nosignal-shell/plugin/src/Caelestia/appdb.hpp
Bora Gülerman 40a2552830
launcher: add favorite apps (#946)
* launcher: add favorite apps

Favorite apps always appear above non-favorite apps
Accepts regex, same logic as #920
Added the same regex logic to hidden apps
Added util file may need to be relocated

* addressed requested changes

* fix: Renamed newly added util singleton

Also added a null check to favorite icon loader in AppItem.qml

* controlCenter/launcherPane: added favorite apps

added icons to the app list to indicate if they are favorited/hidden
marking as favorite/hidden is desabled if the other is selected

* favouriteApps: renamed from favorite to favourite

Also disabled favorite/hidden switch for entries added as regex

* appDb: added notify and emit to favoriteApps

* controlCentre/Launcher: Fixed bug with favourite switch not enabling itself when no hiddenApps exist

Added a comment to explain the enabled state of the switches
icon loader is now a single loader rather than two, hidden icon has
priority

* spelling mistakes

* fixed warning

* formatting fixes
2026-02-19 21:26:10 +11:00

116 lines
3.7 KiB
C++

#pragma once
#include <qhash.h>
#include <qobject.h>
#include <qqmlintegration.h>
#include <qqmllist.h>
#include <qregularexpression.h>
#include <qtimer.h>
namespace caelestia {
class AppEntry : public QObject {
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("AppEntry instances can only be retrieved from an AppDb")
// The actual DesktopEntry, but we don't have access to the type so it's a QObject
Q_PROPERTY(QObject* entry READ entry CONSTANT)
Q_PROPERTY(quint32 frequency READ frequency NOTIFY frequencyChanged)
Q_PROPERTY(QString id READ id CONSTANT)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString comment READ comment NOTIFY commentChanged)
Q_PROPERTY(QString execString READ execString NOTIFY execStringChanged)
Q_PROPERTY(QString startupClass READ startupClass NOTIFY startupClassChanged)
Q_PROPERTY(QString genericName READ genericName NOTIFY genericNameChanged)
Q_PROPERTY(QString categories READ categories NOTIFY categoriesChanged)
Q_PROPERTY(QString keywords READ keywords NOTIFY keywordsChanged)
public:
explicit AppEntry(QObject* entry, quint32 frequency, QObject* parent = nullptr);
[[nodiscard]] QObject* entry() const;
[[nodiscard]] quint32 frequency() const;
void setFrequency(quint32 frequency);
void incrementFrequency();
[[nodiscard]] QString id() const;
[[nodiscard]] QString name() const;
[[nodiscard]] QString comment() const;
[[nodiscard]] QString execString() const;
[[nodiscard]] QString startupClass() const;
[[nodiscard]] QString genericName() const;
[[nodiscard]] QString categories() const;
[[nodiscard]] QString keywords() const;
signals:
void frequencyChanged();
void nameChanged();
void commentChanged();
void execStringChanged();
void startupClassChanged();
void genericNameChanged();
void categoriesChanged();
void keywordsChanged();
private:
QObject* m_entry;
quint32 m_frequency;
};
class AppDb : public QObject {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QString uuid READ uuid CONSTANT)
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged REQUIRED)
Q_PROPERTY(QObjectList entries READ entries WRITE setEntries NOTIFY entriesChanged REQUIRED)
Q_PROPERTY(QStringList favouriteApps READ favouriteApps WRITE setFavouriteApps NOTIFY favouriteAppsChanged REQUIRED)
Q_PROPERTY(QQmlListProperty<caelestia::AppEntry> apps READ apps NOTIFY appsChanged)
public:
explicit AppDb(QObject* parent = nullptr);
[[nodiscard]] QString uuid() const;
[[nodiscard]] QString path() const;
void setPath(const QString& path);
[[nodiscard]] QObjectList entries() const;
void setEntries(const QObjectList& entries);
[[nodiscard]] QStringList favouriteApps() const;
void setFavouriteApps(const QStringList& favApps);
[[nodiscard]] QQmlListProperty<AppEntry> apps();
Q_INVOKABLE void incrementFrequency(const QString& id);
signals:
void pathChanged();
void entriesChanged();
void favouriteAppsChanged();
void appsChanged();
private:
QTimer* m_timer;
const QString m_uuid;
QString m_path;
QObjectList m_entries;
QStringList m_favouriteApps; // unedited string list from qml
QList<QRegularExpression> m_favouriteAppsRegex; // pre-regexified m_favouriteApps list
QHash<QString, AppEntry*> m_apps;
mutable QList<AppEntry*> m_sortedApps;
QString regexifyString(const QString& original) const;
QList<AppEntry*>& getSortedApps() const;
bool isFavourite(const AppEntry* app) const;
quint32 getFrequency(const QString& id) const;
void updateAppFrequencies();
void updateApps();
};
} // namespace caelestia