Changeset View
Changeset View
Standalone View
Standalone View
plugins/notifications/notification.cpp
Show All 16 Lines | |||||
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "notification.h" | 21 | #include "notification.h" | ||
22 | #include "notification_debug.h" | 22 | #include "notification_debug.h" | ||
23 | 23 | | |||
24 | #include <KNotification> | 24 | #include <KNotification> | ||
25 | #include <QtGlobal> | ||||
25 | #include <QIcon> | 26 | #include <QIcon> | ||
26 | #include <QString> | 27 | #include <QString> | ||
27 | #include <QUrl> | 28 | #include <QUrl> | ||
28 | #include <QPixmap> | 29 | #include <QPixmap> | ||
29 | #include <KLocalizedString> | 30 | #include <KLocalizedString> | ||
30 | #include <QFile> | 31 | #include <QFile> | ||
31 | 32 | | |||
33 | #include <QJsonArray> | ||||
34 | | ||||
32 | #include <core/filetransferjob.h> | 35 | #include <core/filetransferjob.h> | ||
33 | 36 | | |||
34 | QMap<QString, FileTransferJob*> Notification::s_downloadsInProgress; | 37 | QMap<QString, FileTransferJob*> Notification::s_downloadsInProgress; | ||
35 | 38 | | |||
36 | Notification::Notification(const NetworkPacket& np, QObject* parent) | 39 | Notification::Notification(const NetworkPacket& np, QObject* parent) | ||
37 | : QObject(parent) | 40 | : QObject(parent) | ||
38 | { | 41 | { | ||
39 | //Make a own directory for each user so noone can see each others icons | 42 | //Make a own directory for each user so noone can see each others icons | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 86 | { | |||
99 | } else if (m_title.isEmpty()){ | 102 | } else if (m_title.isEmpty()){ | ||
100 | m_notification->setText(escapedText); | 103 | m_notification->setText(escapedText); | ||
101 | } else if (m_text.isEmpty()){ | 104 | } else if (m_text.isEmpty()){ | ||
102 | m_notification->setText(escapedTitle); | 105 | m_notification->setText(escapedTitle); | ||
103 | } else { | 106 | } else { | ||
104 | m_notification->setText(escapedTitle+": "+escapedText); | 107 | m_notification->setText(escapedTitle+": "+escapedText); | ||
105 | } | 108 | } | ||
106 | 109 | | |||
110 | connect(m_notification, QOverload<unsigned int>::of(&KNotification::activated), this, [this] (unsigned int actionIndex) { | ||||
111 | // Do nothing for our own reply action | ||||
112 | if(!m_requestReplyId.isEmpty() && actionIndex == 1) { | ||||
mtijink: Do we need a check/index change here when we add "Reply" here? | |||||
Not sure if that can happen but it looks like you might clear m_actions at a point where a notifications still shown and then m_actions[actionIndex] would be out of bounds And also, like the previous comment, when "Reply" is added, the index shifts. broulik: Not sure if that can happen but it looks like you might clear `m_actions` at a point where a… | |||||
113 | return; | ||||
114 | } | ||||
115 | // Notification action idices start at 1 | ||||
116 | Q_EMIT actionTriggered(m_internalId, m_actions[actionIndex - 1]); | ||||
117 | }); | ||||
118 | | ||||
107 | m_hasIcon = m_hasIcon && !m_payloadHash.isEmpty(); | 119 | m_hasIcon = m_hasIcon && !m_payloadHash.isEmpty(); | ||
108 | 120 | | |||
109 | if (!m_hasIcon) { | 121 | if (!m_hasIcon) { | ||
110 | applyNoIcon(); | 122 | applyNoIcon(); | ||
111 | show(); | 123 | show(); | ||
112 | } else { | 124 | } else { | ||
113 | m_iconPath = m_imagesDir.absoluteFilePath(m_payloadHash); | 125 | m_iconPath = m_imagesDir.absoluteFilePath(m_payloadHash); | ||
114 | loadIcon(np); | 126 | loadIcon(np); | ||
115 | } | 127 | } | ||
116 | 128 | | |||
117 | if (!m_requestReplyId.isEmpty()) { | 129 | if (!m_requestReplyId.isEmpty()) { | ||
118 | m_notification->setActions(QStringList(i18n("Reply"))); | 130 | m_actions.prepend(i18n("Reply")); | ||
broulik: You change `m_actions` after having called `setActions()` above | |||||
119 | connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); | 131 | connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); | ||
120 | } | 132 | } | ||
133 | m_notification->setActions(m_actions); | ||||
121 | 134 | | |||
122 | return m_notification; | 135 | return m_notification; | ||
broulik: Whitespace | |||||
123 | } | 136 | } | ||
124 | 137 | | |||
125 | void Notification::loadIcon(const NetworkPacket& np) | 138 | void Notification::loadIcon(const NetworkPacket& np) | ||
126 | { | 139 | { | ||
127 | m_ready = false; | 140 | m_ready = false; | ||
128 | 141 | | |||
129 | if (QFileInfo::exists(m_iconPath)) { | 142 | if (QFileInfo::exists(m_iconPath)) { | ||
130 | applyIcon(); | 143 | applyIcon(); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 184 | { | |||
174 | m_ticker = np.get<QString>(QStringLiteral("ticker")); | 187 | m_ticker = np.get<QString>(QStringLiteral("ticker")); | ||
175 | m_title = np.get<QString>(QStringLiteral("title")); | 188 | m_title = np.get<QString>(QStringLiteral("title")); | ||
176 | m_text = np.get<QString>(QStringLiteral("text")); | 189 | m_text = np.get<QString>(QStringLiteral("text")); | ||
177 | m_dismissable = np.get<bool>(QStringLiteral("isClearable")); | 190 | m_dismissable = np.get<bool>(QStringLiteral("isClearable")); | ||
178 | m_hasIcon = np.hasPayload(); | 191 | m_hasIcon = np.hasPayload(); | ||
179 | m_silent = np.get<bool>(QStringLiteral("silent")); | 192 | m_silent = np.get<bool>(QStringLiteral("silent")); | ||
180 | m_payloadHash = np.get<QString>(QStringLiteral("payloadHash")); | 193 | m_payloadHash = np.get<QString>(QStringLiteral("payloadHash")); | ||
181 | m_requestReplyId = np.get<QString>(QStringLiteral("requestReplyId"), QString()); | 194 | m_requestReplyId = np.get<QString>(QStringLiteral("requestReplyId"), QString()); | ||
195 | | ||||
196 | m_actions.clear(); | ||||
197 | | ||||
198 | for (QJsonValue value : np.get<QJsonArray>(QStringLiteral("actions"))) { | ||||
mtijink: Leftover debug? | |||||
199 | m_actions.append(value.toString()); | ||||
200 | } | ||||
201 | | ||||
182 | } | 202 | } |
Do we need a check/index change here when we add "Reply" here?