Changeset View
Changeset View
Standalone View
Standalone View
plugins/notifications/notification.cpp
Show All 26 Lines | |||||
27 | #include <QUrl> | 27 | #include <QUrl> | ||
28 | #include <QPixmap> | 28 | #include <QPixmap> | ||
29 | #include <KLocalizedString> | 29 | #include <KLocalizedString> | ||
30 | #include <QFile> | 30 | #include <QFile> | ||
31 | 31 | | |||
32 | #include <core/filetransferjob.h> | 32 | #include <core/filetransferjob.h> | ||
33 | 33 | | |||
34 | 34 | | |||
35 | Notification::Notification(const NetworkPackage& np, QObject* parent) | 35 | Notification::Notification(const NetworkPacket& np, QObject* parent) | ||
36 | : QObject(parent) | 36 | : QObject(parent) | ||
37 | { | 37 | { | ||
38 | //Make a own directory for each user so noone can see each others icons | 38 | //Make a own directory for each user so noone can see each others icons | ||
39 | QString username; | 39 | QString username; | ||
40 | #ifdef Q_OS_WIN | 40 | #ifdef Q_OS_WIN | ||
41 | username = qgetenv("USERNAME"); | 41 | username = qgetenv("USERNAME"); | ||
42 | #else | 42 | #else | ||
43 | username = qgetenv("USER"); | 43 | username = qgetenv("USER"); | ||
44 | #endif | 44 | #endif | ||
45 | 45 | | |||
46 | m_imagesDir = QDir::temp().absoluteFilePath(QStringLiteral("kdeconnect_") + username); | 46 | m_imagesDir = QDir::temp().absoluteFilePath(QStringLiteral("kdeconnect_") + username); | ||
47 | m_imagesDir.mkpath(m_imagesDir.absolutePath()); | 47 | m_imagesDir.mkpath(m_imagesDir.absolutePath()); | ||
48 | QFile(m_imagesDir.absolutePath()).setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner); | 48 | QFile(m_imagesDir.absolutePath()).setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner); | ||
49 | m_closed = false; | 49 | m_closed = false; | ||
50 | m_ready = false; | 50 | m_ready = false; | ||
51 | 51 | | |||
52 | parseNetworkPackage(np); | 52 | parseNetworkPacket(np); | ||
53 | createKNotification(false, np); | 53 | createKNotification(false, np); | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | Notification::~Notification() | 56 | Notification::~Notification() | ||
57 | { | 57 | { | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | void Notification::dismiss() | 60 | void Notification::dismiss() | ||
61 | { | 61 | { | ||
62 | if (m_dismissable) { | 62 | if (m_dismissable) { | ||
63 | Q_EMIT dismissRequested(m_internalId); | 63 | Q_EMIT dismissRequested(m_internalId); | ||
64 | } | 64 | } | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | void Notification::show() | 67 | void Notification::show() | ||
68 | { | 68 | { | ||
69 | m_ready = true; | 69 | m_ready = true; | ||
70 | Q_EMIT ready(); | 70 | Q_EMIT ready(); | ||
71 | if (!m_silent) { | 71 | if (!m_silent) { | ||
72 | m_closed = false; | 72 | m_closed = false; | ||
73 | m_notification->sendEvent(); | 73 | m_notification->sendEvent(); | ||
74 | } | 74 | } | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | void Notification::update(const NetworkPackage& np) | 77 | void Notification::update(const NetworkPacket& np) | ||
78 | { | 78 | { | ||
79 | parseNetworkPackage(np); | 79 | parseNetworkPacket(np); | ||
80 | createKNotification(!m_closed, np); | 80 | createKNotification(!m_closed, np); | ||
81 | } | 81 | } | ||
82 | 82 | | |||
83 | KNotification* Notification::createKNotification(bool update, const NetworkPackage& np) | 83 | KNotification* Notification::createKNotification(bool update, const NetworkPacket& np) | ||
84 | { | 84 | { | ||
85 | if (!update) { | 85 | if (!update) { | ||
86 | m_notification = new KNotification(QStringLiteral("notification"), KNotification::CloseOnTimeout, this); | 86 | m_notification = new KNotification(QStringLiteral("notification"), KNotification::CloseOnTimeout, this); | ||
87 | m_notification->setComponentName(QStringLiteral("kdeconnect")); | 87 | m_notification->setComponentName(QStringLiteral("kdeconnect")); | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | QString escapedTitle = m_title.toHtmlEscaped(); | 90 | QString escapedTitle = m_title.toHtmlEscaped(); | ||
91 | QString escapedText = m_text.toHtmlEscaped(); | 91 | QString escapedText = m_text.toHtmlEscaped(); | ||
Show All 35 Lines | 125 | if (!m_requestReplyId.isEmpty()) { | |||
127 | connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); | 127 | connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); | ||
128 | } | 128 | } | ||
129 | 129 | | |||
130 | connect(m_notification, &KNotification::closed, this, &Notification::closed); | 130 | connect(m_notification, &KNotification::closed, this, &Notification::closed); | ||
131 | 131 | | |||
132 | return m_notification; | 132 | return m_notification; | ||
133 | } | 133 | } | ||
134 | 134 | | |||
135 | void Notification::loadIcon(const NetworkPackage& np) | 135 | void Notification::loadIcon(const NetworkPacket& np) | ||
136 | { | 136 | { | ||
137 | m_ready = false; | 137 | m_ready = false; | ||
138 | FileTransferJob* job = np.createPayloadTransferJob(QUrl::fromLocalFile(m_iconPath)); | 138 | FileTransferJob* job = np.createPayloadTransferJob(QUrl::fromLocalFile(m_iconPath)); | ||
139 | job->start(); | 139 | job->start(); | ||
140 | 140 | | |||
141 | connect(job, &FileTransferJob::result, this, [this, job]{ | 141 | connect(job, &FileTransferJob::result, this, [this, job]{ | ||
142 | 142 | | |||
143 | if (job->error()) { | 143 | if (job->error()) { | ||
Show All 23 Lines | 166 | { | |||
167 | Q_EMIT replyRequested(); | 167 | Q_EMIT replyRequested(); | ||
168 | } | 168 | } | ||
169 | 169 | | |||
170 | void Notification::closed() | 170 | void Notification::closed() | ||
171 | { | 171 | { | ||
172 | m_closed = true; | 172 | m_closed = true; | ||
173 | } | 173 | } | ||
174 | 174 | | |||
175 | void Notification::parseNetworkPackage(const NetworkPackage& np) | 175 | void Notification::parseNetworkPacket(const NetworkPacket& np) | ||
176 | { | 176 | { | ||
177 | m_internalId = np.get<QString>(QStringLiteral("id")); | 177 | m_internalId = np.get<QString>(QStringLiteral("id")); | ||
178 | m_appName = np.get<QString>(QStringLiteral("appName")); | 178 | m_appName = np.get<QString>(QStringLiteral("appName")); | ||
179 | m_ticker = np.get<QString>(QStringLiteral("ticker")); | 179 | m_ticker = np.get<QString>(QStringLiteral("ticker")); | ||
180 | m_title = np.get<QString>(QStringLiteral("title")); | 180 | m_title = np.get<QString>(QStringLiteral("title")); | ||
181 | m_text = np.get<QString>(QStringLiteral("text")); | 181 | m_text = np.get<QString>(QStringLiteral("text")); | ||
182 | m_dismissable = np.get<bool>(QStringLiteral("isClearable")); | 182 | m_dismissable = np.get<bool>(QStringLiteral("isClearable")); | ||
183 | m_hasIcon = np.hasPayload(); | 183 | m_hasIcon = np.hasPayload(); | ||
184 | m_silent = np.get<bool>(QStringLiteral("silent")); | 184 | m_silent = np.get<bool>(QStringLiteral("silent")); | ||
185 | m_payloadHash = np.get<QString>(QStringLiteral("payloadHash")); | 185 | m_payloadHash = np.get<QString>(QStringLiteral("payloadHash")); | ||
186 | m_requestReplyId = np.get<QString>(QStringLiteral("requestReplyId"), QString()); | 186 | m_requestReplyId = np.get<QString>(QStringLiteral("requestReplyId"), QString()); | ||
187 | } | 187 | } |