Changeset View
Changeset View
Standalone View
Standalone View
plugins/notifications/notification.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 41 | #ifdef Q_OS_WIN | |||
---|---|---|---|---|---|
42 | username = qgetenv("USERNAME"); | 42 | username = qgetenv("USERNAME"); | ||
43 | #else | 43 | #else | ||
44 | username = qgetenv("USER"); | 44 | username = qgetenv("USER"); | ||
45 | #endif | 45 | #endif | ||
46 | 46 | | |||
47 | m_imagesDir = QDir::temp().absoluteFilePath(QStringLiteral("kdeconnect_") + username); | 47 | m_imagesDir = QDir::temp().absoluteFilePath(QStringLiteral("kdeconnect_") + username); | ||
48 | m_imagesDir.mkpath(m_imagesDir.absolutePath()); | 48 | m_imagesDir.mkpath(m_imagesDir.absolutePath()); | ||
49 | QFile(m_imagesDir.absolutePath()).setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner); | 49 | QFile(m_imagesDir.absolutePath()).setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner); | ||
50 | m_closed = false; | | |||
51 | m_ready = false; | 50 | m_ready = false; | ||
52 | 51 | | |||
53 | parseNetworkPacket(np); | 52 | parseNetworkPacket(np); | ||
54 | createKNotification(false, np); | 53 | createKNotification(np); | ||
55 | } | 54 | } | ||
56 | 55 | | |||
57 | Notification::~Notification() | 56 | Notification::~Notification() | ||
58 | { | 57 | { | ||
59 | } | 58 | } | ||
60 | 59 | | |||
61 | void Notification::dismiss() | 60 | void Notification::dismiss() | ||
62 | { | 61 | { | ||
63 | if (m_dismissable) { | 62 | if (m_dismissable) { | ||
64 | Q_EMIT dismissRequested(m_internalId); | 63 | Q_EMIT dismissRequested(m_internalId); | ||
65 | } | 64 | } | ||
66 | } | 65 | } | ||
67 | 66 | | |||
68 | void Notification::show() | 67 | void Notification::show() | ||
69 | { | 68 | { | ||
70 | m_ready = true; | 69 | m_ready = true; | ||
71 | Q_EMIT ready(); | 70 | Q_EMIT ready(); | ||
72 | if (!m_silent) { | 71 | if (!m_silent) { | ||
73 | m_closed = false; | | |||
74 | m_notification->sendEvent(); | 72 | m_notification->sendEvent(); | ||
75 | } | 73 | } | ||
76 | } | 74 | } | ||
77 | 75 | | |||
78 | void Notification::update(const NetworkPacket& np) | 76 | void Notification::update(const NetworkPacket& np) | ||
79 | { | 77 | { | ||
80 | parseNetworkPacket(np); | 78 | parseNetworkPacket(np); | ||
81 | createKNotification(!m_closed, np); | 79 | createKNotification(np); | ||
82 | } | 80 | } | ||
83 | 81 | | |||
84 | KNotification* Notification::createKNotification(bool update, const NetworkPacket& np) | 82 | KNotification* Notification::createKNotification(const NetworkPacket& np) | ||
85 | { | 83 | { | ||
86 | if (!update) { | 84 | if (!m_notification) { | ||
broulik: Can't this be simplified to drop the `update` argument and just check for `m_notification`? | |||||
broulik: Looks like it's "public API", so maybe not? | |||||
nicolasfella: Good point. I actually think I can simplify things much more | |||||
broulik: Indeed, I think the `m_closed` stuff also isn't neccessary anymore | |||||
87 | m_notification = new KNotification(QStringLiteral("notification"), KNotification::CloseOnTimeout, this); | 85 | m_notification = new KNotification(QStringLiteral("notification"), KNotification::CloseOnTimeout, this); | ||
88 | m_notification->setComponentName(QStringLiteral("kdeconnect")); | 86 | m_notification->setComponentName(QStringLiteral("kdeconnect")); | ||
89 | } | 87 | } | ||
90 | 88 | | |||
91 | QString escapedTitle = m_title.toHtmlEscaped(); | 89 | QString escapedTitle = m_title.toHtmlEscaped(); | ||
92 | QString escapedText = m_text.toHtmlEscaped(); | 90 | QString escapedText = m_text.toHtmlEscaped(); | ||
93 | QString escapedTicker = m_ticker.toHtmlEscaped(); | 91 | QString escapedTicker = m_ticker.toHtmlEscaped(); | ||
94 | 92 | | |||
Show All 21 Lines | 112 | } else { | |||
116 | loadIcon(np); | 114 | loadIcon(np); | ||
117 | } | 115 | } | ||
118 | 116 | | |||
119 | if (!m_requestReplyId.isEmpty()) { | 117 | if (!m_requestReplyId.isEmpty()) { | ||
120 | m_notification->setActions(QStringList(i18n("Reply"))); | 118 | m_notification->setActions(QStringList(i18n("Reply"))); | ||
121 | connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); | 119 | connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); | ||
122 | } | 120 | } | ||
123 | 121 | | |||
124 | connect(m_notification, &KNotification::closed, this, &Notification::closed); | | |||
125 | | ||||
126 | return m_notification; | 122 | return m_notification; | ||
127 | } | 123 | } | ||
128 | 124 | | |||
129 | void Notification::loadIcon(const NetworkPacket& np) | 125 | void Notification::loadIcon(const NetworkPacket& np) | ||
130 | { | 126 | { | ||
131 | m_ready = false; | 127 | m_ready = false; | ||
132 | 128 | | |||
133 | if (QFileInfo::exists(m_iconPath)) { | 129 | if (QFileInfo::exists(m_iconPath)) { | ||
Show All 32 Lines | 160 | { | |||
166 | m_notification->setIconName(QStringLiteral("not_a_real_icon")); | 162 | m_notification->setIconName(QStringLiteral("not_a_real_icon")); | ||
167 | } | 163 | } | ||
168 | 164 | | |||
169 | void Notification::reply() | 165 | void Notification::reply() | ||
170 | { | 166 | { | ||
171 | Q_EMIT replyRequested(); | 167 | Q_EMIT replyRequested(); | ||
172 | } | 168 | } | ||
173 | 169 | | |||
174 | void Notification::closed() | | |||
175 | { | | |||
176 | m_closed = true; | | |||
177 | } | | |||
178 | | ||||
179 | void Notification::parseNetworkPacket(const NetworkPacket& np) | 170 | void Notification::parseNetworkPacket(const NetworkPacket& np) | ||
180 | { | 171 | { | ||
181 | m_internalId = np.get<QString>(QStringLiteral("id")); | 172 | m_internalId = np.get<QString>(QStringLiteral("id")); | ||
182 | m_appName = np.get<QString>(QStringLiteral("appName")); | 173 | m_appName = np.get<QString>(QStringLiteral("appName")); | ||
183 | m_ticker = np.get<QString>(QStringLiteral("ticker")); | 174 | m_ticker = np.get<QString>(QStringLiteral("ticker")); | ||
184 | m_title = np.get<QString>(QStringLiteral("title")); | 175 | m_title = np.get<QString>(QStringLiteral("title")); | ||
185 | m_text = np.get<QString>(QStringLiteral("text")); | 176 | m_text = np.get<QString>(QStringLiteral("text")); | ||
186 | m_dismissable = np.get<bool>(QStringLiteral("isClearable")); | 177 | m_dismissable = np.get<bool>(QStringLiteral("isClearable")); | ||
187 | m_hasIcon = np.hasPayload(); | 178 | m_hasIcon = np.hasPayload(); | ||
188 | m_silent = np.get<bool>(QStringLiteral("silent")); | 179 | m_silent = np.get<bool>(QStringLiteral("silent")); | ||
189 | m_payloadHash = np.get<QString>(QStringLiteral("payloadHash")); | 180 | m_payloadHash = np.get<QString>(QStringLiteral("payloadHash")); | ||
190 | m_requestReplyId = np.get<QString>(QStringLiteral("requestReplyId"), QString()); | 181 | m_requestReplyId = np.get<QString>(QStringLiteral("requestReplyId"), QString()); | ||
191 | } | 182 | } |
Can't this be simplified to drop the update argument and just check for m_notification?
This method is only used in the constructor where m_notification is null anyway, and in update where you check for m_notification