Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/utils.cpp
Show All 14 Lines | |||||
15 | * Lesser General Public License for more details. | 15 | * Lesser General Public License for more details. | ||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | 17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "utils_p.h" | 21 | #include "utils_p.h" | ||
22 | 22 | | |||
23 | #include "notifications.h" | ||||
24 | | ||||
23 | #include <QAbstractItemModel> | 25 | #include <QAbstractItemModel> | ||
24 | #include <QAbstractProxyModel> | 26 | #include <QAbstractProxyModel> | ||
25 | #include <QCoreApplication> | 27 | #include <QCoreApplication> | ||
26 | #include <QDBusConnection> | 28 | #include <QDBusConnection> | ||
27 | #include <QDBusConnectionInterface> | 29 | #include <QDBusConnectionInterface> | ||
28 | #include <QFile> | 30 | #include <QFile> | ||
31 | #include <QMetaEnum> | ||||
29 | #include <QTextStream> | 32 | #include <QTextStream> | ||
30 | 33 | | |||
31 | #include <KConcatenateRowsProxyModel> | 34 | #include <KConcatenateRowsProxyModel> | ||
32 | 35 | | |||
33 | #include <KProcessList> | 36 | #include <KProcessList> | ||
34 | 37 | | |||
35 | using namespace NotificationManager; | 38 | using namespace NotificationManager; | ||
36 | 39 | | |||
40 | QHash<int, QByteArray> Utils::roleNames() | ||||
41 | { | ||||
42 | static QHash<int, QByteArray> s_roles; | ||||
43 | | ||||
44 | if (s_roles.isEmpty()) { | ||||
45 | // This generates role names from the Roles enum in the form of: FooRole -> foo | ||||
46 | const QMetaEnum e = QMetaEnum::fromType<Notifications::Roles>(); | ||||
47 | | ||||
48 | // Qt built-in roles we use | ||||
49 | s_roles.insert(Qt::DisplayRole, QByteArrayLiteral("display")); | ||||
50 | s_roles.insert(Qt::DecorationRole, QByteArrayLiteral("decoration")); | ||||
51 | | ||||
52 | for (int i = 0; i < e.keyCount(); ++i) { | ||||
53 | const int value = e.value(i); | ||||
54 | | ||||
55 | QByteArray key(e.key(i)); | ||||
56 | key[0] = key[0] + 32; // lower case first letter | ||||
57 | key.chop(4); // strip "Role" suffix | ||||
58 | | ||||
59 | s_roles.insert(value, key); | ||||
60 | } | ||||
61 | | ||||
62 | s_roles.insert(Notifications::IdRole, QByteArrayLiteral("notificationId")); // id is QML-reserved | ||||
63 | } | ||||
64 | | ||||
65 | return s_roles; | ||||
66 | } | ||||
67 | | ||||
37 | QString Utils::processNameFromPid(uint pid) | 68 | QString Utils::processNameFromPid(uint pid) | ||
38 | { | 69 | { | ||
39 | auto processInfo = KProcessList::processInfo(pid); | 70 | auto processInfo = KProcessList::processInfo(pid); | ||
40 | 71 | | |||
41 | if (!processInfo.isValid()) { | 72 | if (!processInfo.isValid()) { | ||
42 | return QString(); | 73 | return QString(); | ||
43 | } | 74 | } | ||
44 | 75 | | |||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |