Changeset View
Changeset View
Standalone View
Standalone View
src/notifybysnore.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | Copyright (C) 2019 Piyush Aggarwal <piyushaggarwal002@gmail.com> | 2 | Copyright (C) 2019 Piyush Aggarwal <piyushaggarwal002@gmail.com> | ||
broulik: Did you even compile this?
Also, this is the same in both branches, move it above the `if` and… | |||||
3 | 3 | | |||
4 | This program is free software; you can redistribute it and/or modify it | 4 | This program is free software; you can redistribute it and/or modify it | ||
broulik: Check for `isNull()` | |||||
5 | under the terms of the GNU Library General Public License as published by | 5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | 6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
broulik: The explicit call to `actualSize` shouldn't be neccessary | |||||
just to be sure :) but if there's a check implemented already somewhere within QIcon, I'd happily remove it from here! brute4s99: just to be sure :)
but if there's a check implemented already somewhere within QIcon, I'd… | |||||
7 | option) any later version. | 7 | option) any later version. | ||
8 | 8 | | |||
broulik: Whitespace | |||||
9 | This program is distributed in the hope that it will be useful, but WITHOUT | 9 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | 11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | 12 | License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 142 | { | |||
145 | 145 | | |||
146 | arguments << QStringLiteral("-t"); | 146 | arguments << QStringLiteral("-t"); | ||
147 | if (!notification->title().isEmpty()) { | 147 | if (!notification->title().isEmpty()) { | ||
148 | arguments << notification->title(); | 148 | arguments << notification->title(); | ||
149 | } else { | 149 | } else { | ||
150 | arguments << qApp->applicationDisplayName(); | 150 | arguments << qApp->applicationDisplayName(); | ||
151 | } | 151 | } | ||
152 | arguments << QStringLiteral("-m") << notification->text(); | 152 | arguments << QStringLiteral("-m") << notification->text(); | ||
153 | const QString iconPath = m_iconDir.path() + QLatin1Char('/') | ||||
154 | + QString::number(notification->id()) + QStringLiteral(".png"); | ||||
153 | if (!notification->pixmap().isNull()) { | 155 | if (!notification->pixmap().isNull()) { | ||
154 | auto iconPath = QString(m_iconDir.path() + QLatin1Char('/') | | |||
155 | + QString::number(notification->id()) + QStringLiteral(".png")); | | |||
156 | notification->pixmap().save(iconPath, "PNG"); | 156 | notification->pixmap().save(iconPath, "PNG"); | ||
157 | arguments << QStringLiteral("-p") << iconPath; | 157 | arguments << QStringLiteral("-p") << iconPath; | ||
sredman: Whitespace | |||||
158 | } else if (!qApp->windowIcon().isNull()) { | ||||
159 | QIcon app_icon = qApp->windowIcon(); | ||||
160 | // We limit the icon size to 1024x1024 as it is the highest supported by Windows | ||||
sredman: Indentation | |||||
161 | QPixmap pixmap = app_icon.pixmap(app_icon.actualSize(QSize(1024, 1024))); | ||||
162 | pixmap.save(iconPath, "PNG"); | ||||
163 | arguments << QStringLiteral("-p") << iconPath; | ||||
158 | } | 164 | } | ||
159 | arguments << QStringLiteral("-appID") << qApp->applicationName() | 165 | arguments << QStringLiteral("-appID") << qApp->applicationName() | ||
160 | << QStringLiteral("-id") << QString::number(notification->id()) | 166 | << QStringLiteral("-id") << QString::number(notification->id()) | ||
161 | << QStringLiteral("-pipename") << m_server.fullServerName(); | 167 | << QStringLiteral("-pipename") << m_server.fullServerName(); | ||
162 | 168 | | |||
163 | if (!notification->actions().isEmpty()) { | 169 | if (!notification->actions().isEmpty()) { | ||
164 | arguments << QStringLiteral("-b") << notification->actions().join(QLatin1Char(';')); | 170 | arguments << QStringLiteral("-b") << notification->actions().join(QLatin1Char(';')); | ||
165 | } | 171 | } | ||
166 | qCDebug(LOG_KNOTIFICATIONS) << arguments; | 172 | qCDebug(LOG_KNOTIFICATIONS) << arguments; | ||
167 | proc->start(m_program, arguments); | 173 | proc->start(m_program, arguments); | ||
168 | m_notifications.insert(notification->id(), notification); | 174 | m_notifications.insert(notification->id(), notification); | ||
169 | connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), | 175 | connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), | ||
170 | [=](int exitCode, QProcess::ExitStatus exitStatus){ | 176 | [=](int exitCode, QProcess::ExitStatus exitStatus){ | ||
171 | proc->deleteLater(); | 177 | proc->deleteLater(); | ||
172 | if (exitStatus != QProcess::NormalExit) { | 178 | if (exitStatus != QProcess::NormalExit) { | ||
173 | qCDebug(LOG_KNOTIFICATIONS) << "SnoreToast crashed while trying to show a notification."; | 179 | qCDebug(LOG_KNOTIFICATIONS) << "SnoreToast crashed while trying to show a notification."; | ||
174 | close(notification); | 180 | close(notification); | ||
175 | } | 181 | } | ||
176 | QFile::remove(QString(m_iconDir.path() + QLatin1Char('/') | 182 | QFile::remove(iconPath); | ||
177 | + QString::number(notification->id()) + QStringLiteral(".png"))); | | |||
178 | }); | 183 | }); | ||
179 | } | 184 | } | ||
180 | 185 | | |||
181 | void NotifyBySnore::close(KNotification *notification) | 186 | void NotifyBySnore::close(KNotification *notification) | ||
182 | { | 187 | { | ||
183 | if (m_notifications.constFind(notification->id()) == m_notifications.constEnd()) { | 188 | if (m_notifications.constFind(notification->id()) == m_notifications.constEnd()) { | ||
184 | return; | 189 | return; | ||
185 | } | 190 | } | ||
Show All 16 Lines |
Did you even compile this?
Also, this is the same in both branches, move it above the if and also make it const