-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathnotifyserverapplet.cpp
More file actions
166 lines (127 loc) · 4.06 KB
/
Copy pathnotifyserverapplet.cpp
File metadata and controls
166 lines (127 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "notifyserverapplet.h"
#include "notificationmanager.h"
#include "dbusadaptor.h"
#include "pluginfactory.h"
#include <QCoreApplication>
#include <QEvent>
#include <QThread>
#include <QLoggingCategory>
namespace notification {
Q_DECLARE_LOGGING_CATEGORY(notifyLog)
}
namespace notification {
NotifyServerApplet::NotifyServerApplet(QObject *parent)
: DApplet(parent)
{
}
NotifyServerApplet::~NotifyServerApplet()
{
qDebug(notifyLog) << "Exit notification server.";
constexpr int kWaitTimeoutMs = 3000;
constexpr int kTerminateWaitMs = 1000;
if (m_worker) {
if (m_worker->isRunning()) {
m_worker->quit();
if (!m_worker->wait(kWaitTimeoutMs)) {
qWarning(notifyLog)
<< "Worker thread did not exit in time, terminating.";
m_worker->terminate();
if (!m_worker->wait(kTerminateWaitMs)) {
qCritical(notifyLog)
<< "Worker thread terminate timeout.";
}
}
}
if (m_manager) {
delete m_manager;
m_manager = nullptr;
}
delete m_worker;
m_worker = nullptr;
} else if (m_manager) {
delete m_manager;
m_manager = nullptr;
}
}
bool NotifyServerApplet::load()
{
return DApplet::load();
}
bool NotifyServerApplet::init()
{
// Reentrancy protection
if (m_manager || m_worker) {
qWarning(notifyLog) << "NotifyServerApplet is already initialized.";
return true;
}
DApplet::init();
m_manager = new NotificationManager();
if (!m_manager->registerDbusService()) {
qWarning(notifyLog) << QString("Can't register Notifications to the D-Bus object.");
delete m_manager;
m_manager = nullptr;
return false;
}
new DbusAdaptor(m_manager);
new DDENotificationDbusAdaptor(m_manager);
connect(m_manager, &NotificationManager::NotificationStateChanged, this, &NotifyServerApplet::notificationStateChanged);
removeExpiredNotifications();
m_worker = new QThread();
m_manager->moveToThread(m_worker);
// Register Qt asynchronous cleanup
// connect(m_worker, &QThread::finished, m_manager, &QObject::deleteLater);
// connect(m_worker, &QThread::finished, m_worker, &QObject::deleteLater);
m_worker->start();
return true;
}
void NotifyServerApplet::actionInvoked(qint64 id, uint bubbleId, const QString &actionKey)
{
CHECK_MANAGER();
QMetaObject::invokeMethod(m_manager, "actionInvoked", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(QString, actionKey));
}
void NotifyServerApplet::actionInvoked(qint64 id, const QString &actionKey)
{
CHECK_MANAGER();
QMetaObject::invokeMethod(m_manager, "actionInvoked", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(QString, actionKey));
}
void NotifyServerApplet::notificationClosed(qint64 id, uint bubbleId, uint reason)
{
CHECK_MANAGER();
QMetaObject::invokeMethod(m_manager, "notificationClosed", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(uint, reason));
}
QVariant NotifyServerApplet::appValue(const QString &appId, int configItem)
{
CHECK_MANAGER_RET({});
return m_manager->GetAppInfo(appId, configItem);
}
void NotifyServerApplet::removeNotification(qint64 id)
{
CHECK_MANAGER();
m_manager->removeNotification(id);
}
void NotifyServerApplet::removeNotifications(const QString &appName)
{
CHECK_MANAGER();
m_manager->removeNotifications(appName);
}
void NotifyServerApplet::removeNotifications()
{
CHECK_MANAGER();
m_manager->removeNotifications();
}
void NotifyServerApplet::removeExpiredNotifications()
{
CHECK_MANAGER();
m_manager->removeExpiredNotifications();
}
void NotifyServerApplet::setBlockClosedId(qint64 id)
{
CHECK_MANAGER();
m_manager->setBlockClosedId(id);
}
D_APPLET_CLASS(NotifyServerApplet)
}
#include "notifyserverapplet.moc"