diff --git a/libnotificationmanager/jobsmodel.h b/libnotificationmanager/jobsmodel.h --- a/libnotificationmanager/jobsmodel.h +++ b/libnotificationmanager/jobsmodel.h @@ -57,6 +57,7 @@ QVariant data(const QModelIndex &index, int role) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; + QHash roleNames() const override; /** * @brief Close a job diff --git a/libnotificationmanager/jobsmodel.cpp b/libnotificationmanager/jobsmodel.cpp --- a/libnotificationmanager/jobsmodel.cpp +++ b/libnotificationmanager/jobsmodel.cpp @@ -22,6 +22,7 @@ #include "jobsmodel_p.h" #include "notifications.h" +#include "utils_p.h" #include #include @@ -176,6 +177,11 @@ return d->m_jobViews.count(); } +QHash JobsModel::roleNames() const +{ + return Utils::roleNames(); +} + void JobsModel::close(const QModelIndex &idx) { if (checkIndex(idx)) { diff --git a/libnotificationmanager/notifications.cpp b/libnotificationmanager/notifications.cpp --- a/libnotificationmanager/notifications.cpp +++ b/libnotificationmanager/notifications.cpp @@ -843,26 +843,5 @@ QHash Notifications::roleNames() const { - static QHash s_roles; - - if (s_roles.isEmpty()) { - s_roles = QSortFilterProxyModel::roleNames(); - - // This generates role names from the Roles enum in the form of: FooRole -> foo - const QMetaEnum e = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("Roles")); - - for (int i = 0; i < e.keyCount(); ++i) { - const int value = e.value(i); - - QByteArray key(e.key(i)); - key[0] = key[0] + 32; // lower case first letter - key.chop(4); // strip "Role" suffix - - s_roles.insert(value, key); - } - - s_roles.insert(IdRole, QByteArrayLiteral("notificationId")); // id is QML-reserved - } - - return s_roles; + return Utils::roleNames(); } diff --git a/libnotificationmanager/notificationsmodel.h b/libnotificationmanager/notificationsmodel.h --- a/libnotificationmanager/notificationsmodel.h +++ b/libnotificationmanager/notificationsmodel.h @@ -45,6 +45,7 @@ QVariant data(const QModelIndex &index, int role) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; + QHash roleNames() const override; void expire(uint notificationId); void close(uint notificationId); diff --git a/libnotificationmanager/notificationsmodel.cpp b/libnotificationmanager/notificationsmodel.cpp --- a/libnotificationmanager/notificationsmodel.cpp +++ b/libnotificationmanager/notificationsmodel.cpp @@ -23,6 +23,7 @@ #include "debug.h" #include "server.h" +#include "utils_p.h" #include "notifications.h" @@ -350,6 +351,11 @@ return d->notifications.count(); } +QHash NotificationsModel::roleNames() const +{ + return Utils::roleNames(); +} + void NotificationsModel::expire(uint notificationId) { if (d->rowOfNotification(notificationId) > -1) { diff --git a/libnotificationmanager/utils.cpp b/libnotificationmanager/utils.cpp --- a/libnotificationmanager/utils.cpp +++ b/libnotificationmanager/utils.cpp @@ -20,20 +20,51 @@ #include "utils_p.h" +#include "notifications.h" + #include #include #include #include #include #include +#include #include #include #include using namespace NotificationManager; +QHash Utils::roleNames() +{ + static QHash s_roles; + + if (s_roles.isEmpty()) { + // This generates role names from the Roles enum in the form of: FooRole -> foo + const QMetaEnum e = QMetaEnum::fromType(); + + // Qt built-in roles we use + s_roles.insert(Qt::DisplayRole, QByteArrayLiteral("display")); + s_roles.insert(Qt::DecorationRole, QByteArrayLiteral("decoration")); + + for (int i = 0; i < e.keyCount(); ++i) { + const int value = e.value(i); + + QByteArray key(e.key(i)); + key[0] = key[0] + 32; // lower case first letter + key.chop(4); // strip "Role" suffix + + s_roles.insert(value, key); + } + + s_roles.insert(Notifications::IdRole, QByteArrayLiteral("notificationId")); // id is QML-reserved + } + + return s_roles; +} + QString Utils::processNameFromPid(uint pid) { auto processInfo = KProcessList::processInfo(pid); diff --git a/libnotificationmanager/utils_p.h b/libnotificationmanager/utils_p.h --- a/libnotificationmanager/utils_p.h +++ b/libnotificationmanager/utils_p.h @@ -32,6 +32,8 @@ namespace Utils { +QHash roleNames(); + QString processNameFromPid(uint pid); QString desktopEntryFromPid(uint pid);