Changeset View
Changeset View
Standalone View
Standalone View
plugins/notifications/notification.cpp
Context not available. | |||||
33 | Notification::Notification(const NetworkPackage& np, QObject* parent) | 33 | Notification::Notification(const NetworkPackage& np, QObject* parent) | ||
---|---|---|---|---|---|
34 | : QObject(parent) | 34 | : QObject(parent) | ||
35 | { | 35 | { | ||
36 | mImagesDir = QDir::temp().absoluteFilePath(QStringLiteral("kdeconnect")); | 36 | m_imagesDir = QDir::temp().absoluteFilePath(QStringLiteral("kdeconnect")); | ||
37 | mImagesDir.mkpath(mImagesDir.absolutePath()); | 37 | m_imagesDir.mkpath(m_imagesDir.absolutePath()); | ||
38 | mClosed = false; | 38 | m_closed = false; | ||
39 | 39 | | |||
40 | parseNetworkPackage(np); | 40 | parseNetworkPackage(np); | ||
41 | createKNotification(false, np); | 41 | createKNotification(false, np); | ||
Context not available. | |||||
48 | 48 | | |||
49 | void Notification::dismiss() | 49 | void Notification::dismiss() | ||
50 | { | 50 | { | ||
51 | if (mDismissable) { | 51 | if (m_dismissable) { | ||
52 | Q_EMIT dismissRequested(mInternalId); | 52 | Q_EMIT dismissRequested(m_internalId); | ||
53 | } | 53 | } | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | void Notification::show() | 56 | void Notification::show() | ||
57 | { | 57 | { | ||
58 | Q_EMIT ready(); | 58 | if (!m_silent) { | ||
59 | if (!mSilent) { | 59 | m_closed = false; | ||
60 | mClosed = false; | 60 | m_notification->sendEvent(); | ||
61 | mNotification->sendEvent(); | | |||
62 | } | 61 | } | ||
63 | } | 62 | } | ||
64 | 63 | | |||
65 | void Notification::applyIconAndShow() | 64 | void Notification::applyIconAndShow() | ||
66 | { | 65 | { | ||
67 | if (!mSilent) { | 66 | if (!m_silent) { | ||
68 | QPixmap icon(mIconPath, "PNG"); | 67 | QPixmap icon(m_iconPath, "PNG"); | ||
69 | mNotification->setPixmap(icon); | 68 | m_notification->setPixmap(icon); | ||
70 | show(); | 69 | show(); | ||
71 | } | 70 | } | ||
72 | } | 71 | } | ||
73 | 72 | | |||
74 | void Notification::update(const NetworkPackage &np) | 73 | void Notification::update(const NetworkPackage& np) | ||
75 | { | 74 | { | ||
76 | parseNetworkPackage(np); | 75 | parseNetworkPackage(np); | ||
77 | createKNotification(!mClosed, np); | 76 | createKNotification(!m_closed, np); | ||
78 | } | 77 | } | ||
79 | 78 | | |||
80 | KNotification* Notification::createKNotification(bool update, const NetworkPackage &np) | 79 | KNotification* Notification::createKNotification(bool update, const NetworkPackage& np) | ||
81 | { | 80 | { | ||
82 | if (!update) { | 81 | if (!update) { | ||
83 | mNotification = new KNotification(QStringLiteral("notification"), KNotification::CloseOnTimeout, this); | 82 | m_notification = new KNotification(QStringLiteral("notification"), KNotification::CloseOnTimeout, this); | ||
84 | mNotification->setComponentName(QStringLiteral("kdeconnect")); | 83 | m_notification->setComponentName(QStringLiteral("kdeconnect")); | ||
85 | } | 84 | } | ||
86 | 85 | | |||
87 | QString escapedTitle = mTitle.toHtmlEscaped(); | 86 | QString escapedTitle = m_title.toHtmlEscaped(); | ||
88 | QString escapedText = mText.toHtmlEscaped(); | 87 | QString escapedText = m_text.toHtmlEscaped(); | ||
89 | QString escapedTicker = mTicker.toHtmlEscaped(); | 88 | QString escapedTicker = m_ticker.toHtmlEscaped(); | ||
90 | 89 | | |||
91 | mNotification->setTitle(mAppName.toHtmlEscaped()); | 90 | m_notification->setTitle(m_appName.toHtmlEscaped()); | ||
92 | 91 | | |||
93 | if (mTitle.isEmpty() && mText.isEmpty()) { | 92 | if (m_title.isEmpty() && m_text.isEmpty()) { | ||
94 | mNotification->setText(escapedTicker); | 93 | m_notification->setText(escapedTicker); | ||
95 | } else if (mAppName==mTitle) { | 94 | } else if (m_appName==m_title) { | ||
96 | mNotification->setText(escapedText); | 95 | m_notification->setText(escapedText); | ||
97 | } else if (mTitle.isEmpty()){ | 96 | } else if (m_title.isEmpty()){ | ||
98 | mNotification->setText(escapedText); | 97 | m_notification->setText(escapedText); | ||
99 | } else if (mText.isEmpty()){ | 98 | } else if (m_text.isEmpty()){ | ||
100 | mNotification->setText(escapedTitle); | 99 | m_notification->setText(escapedTitle); | ||
101 | } else { | 100 | } else { | ||
102 | mNotification->setText(escapedTitle+": "+escapedText); | 101 | m_notification->setText(escapedTitle+": "+escapedText); | ||
103 | } | 102 | } | ||
104 | 103 | | |||
105 | if (!mHasIcon) { | 104 | if (!m_hasIcon) { | ||
106 | //HACK The only way to display no icon at all is trying to load a non-existant icon | 105 | //HACK The only way to display no icon at all is trying to load a non-existant icon | ||
107 | mNotification->setIconName(QString("not_a_real_icon")); | 106 | m_notification->setIconName(QString("not_a_real_icon")); | ||
108 | show(); | 107 | show(); | ||
109 | } else { | 108 | } else { | ||
110 | QString filename = mPayloadHash; | 109 | QString filename = m_payloadHash; | ||
111 | 110 | | |||
112 | if (filename.isEmpty()) { | 111 | if (filename.isEmpty()) { | ||
113 | mHasIcon = false; | 112 | m_hasIcon = false; | ||
114 | } else { | 113 | } else { | ||
115 | mIconPath = mImagesDir.absoluteFilePath(filename); | 114 | m_iconPath = m_imagesDir.absoluteFilePath(filename); | ||
116 | QUrl destinationUrl(mIconPath); | 115 | QUrl destinationUrl(m_iconPath); | ||
117 | FileTransferJob* job = np.createPayloadTransferJob(destinationUrl); | 116 | FileTransferJob* job = np.createPayloadTransferJob(destinationUrl); | ||
118 | job->start(); | 117 | job->start(); | ||
119 | connect(job, &FileTransferJob::result, this, &Notification::applyIconAndShow); | 118 | connect(job, &FileTransferJob::result, this, &Notification::applyIconAndShow); | ||
120 | } | 119 | } | ||
121 | } | 120 | } | ||
122 | 121 | | |||
123 | if(!mRequestReplyId.isEmpty()) { | 122 | if(!m_requestReplyId.isEmpty()) { | ||
124 | mNotification->setActions( QStringList(i18n("Reply")) ); | 123 | m_notification->setActions( QStringList(i18n("Reply")) ); | ||
125 | connect(mNotification, &KNotification::action1Activated, this, &Notification::reply); | 124 | connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); | ||
126 | } | 125 | } | ||
127 | 126 | | |||
128 | connect(mNotification, &KNotification::closed, this, &Notification::closed); | 127 | connect(m_notification, &KNotification::closed, this, &Notification::closed); | ||
129 | 128 | | |||
130 | return mNotification; | 129 | return m_notification; | ||
131 | } | 130 | } | ||
132 | 131 | | |||
133 | void Notification::reply() | 132 | void Notification::reply() | ||
Context not available. | |||||
137 | 136 | | |||
138 | void Notification::closed() | 137 | void Notification::closed() | ||
139 | { | 138 | { | ||
140 | mClosed = true; | 139 | m_closed = true; | ||
141 | } | 140 | } | ||
142 | 141 | | |||
143 | void Notification::parseNetworkPackage(const NetworkPackage &np) | 142 | void Notification::parseNetworkPackage(const NetworkPackage& np) | ||
144 | { | 143 | { | ||
145 | mInternalId = np.get<QString>(QStringLiteral("id")); | 144 | m_internalId = np.get<QString>(QStringLiteral("id")); | ||
146 | mAppName = np.get<QString>(QStringLiteral("appName")); | 145 | m_appName = np.get<QString>(QStringLiteral("appName")); | ||
147 | mTicker = np.get<QString>(QStringLiteral("ticker")); | 146 | m_ticker = np.get<QString>(QStringLiteral("ticker")); | ||
148 | mTitle = np.get<QString>(QStringLiteral("title")); | 147 | m_title = np.get<QString>(QStringLiteral("title")); | ||
149 | mText = np.get<QString>(QStringLiteral("text")); | 148 | m_text = np.get<QString>(QStringLiteral("text")); | ||
150 | mDismissable = np.get<bool>(QStringLiteral("isClearable")); | 149 | m_dismissable = np.get<bool>(QStringLiteral("isClearable")); | ||
151 | mHasIcon = np.hasPayload(); | 150 | m_hasIcon = np.hasPayload(); | ||
152 | mSilent = np.get<bool>(QStringLiteral("silent")); | 151 | m_silent = np.get<bool>(QStringLiteral("silent")); | ||
153 | mPayloadHash = np.get<QString>(QStringLiteral("payloadHash")); | 152 | m_payloadHash = np.get<QString>(QStringLiteral("payloadHash")); | ||
154 | mRequestReplyId = np.get<QString>(QStringLiteral("requestReplyId"), QString()); | 153 | m_requestReplyId = np.get<QString>(QStringLiteral("requestReplyId"), QString()); | ||
155 | } | 154 | } | ||
Context not available. |