shift-shell/containments/homescreens/folio/applicationusagemodel.h
Marco Allegretti 1702027f7e Add convergence launcher app lists
Record app launches from window creation so recent and most-used
lists survive after windows close.

Use those models in the convergence launcher and keep the hover
surface in the unified chrome.
2026-05-26 17:27:44 +02:00

80 lines
No EOL
1.7 KiB
C++

// SPDX-FileCopyrightText: 2026 Marco Allegretti
// SPDX-License-Identifier: EUPL-1.2
#pragma once
#include <QAbstractListModel>
#include <QDateTime>
#include <QHash>
#include <QList>
#include <QObject>
#include <QString>
#include <QtQmlIntegration/qqmlintegration.h>
#include <memory>
class FolioDelegate;
class HomeScreen;
struct ApplicationUsageEntry {
QString storageId;
int launchCount = 0;
QDateTime lastUsed;
};
class ApplicationUsageStore : public QObject
{
Q_OBJECT
public:
explicit ApplicationUsageStore(HomeScreen *parent = nullptr);
QList<ApplicationUsageEntry> entries() const;
void recordUsage(const QString &storageId);
Q_SIGNALS:
void usageChanged();
private:
void load();
void save();
HomeScreen *m_homeScreen{nullptr};
QHash<QString, ApplicationUsageEntry> m_entries;
};
class ApplicationUsageModel : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
public:
enum Mode {
RecentUsage,
MostUsed,
};
enum Roles {
DelegateRole = Qt::UserRole + 1,
LaunchCountRole,
LastUsedRole,
};
ApplicationUsageModel(HomeScreen *homeScreen = nullptr, ApplicationUsageStore *store = nullptr, Mode mode = RecentUsage);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
public Q_SLOTS:
void rebuild();
private:
HomeScreen *m_homeScreen{nullptr};
ApplicationUsageStore *m_store{nullptr};
Mode m_mode{RecentUsage};
QList<ApplicationUsageEntry> m_entries;
QList<std::shared_ptr<FolioDelegate>> m_delegates;
};