Changeset View
Changeset View
Standalone View
Standalone View
src/notifybypopup.cpp
Show All 17 Lines | 1 | /* | |||
---|---|---|---|---|---|
18 | 18 | | |||
19 | You should have received a copy of the GNU Lesser General Public | 19 | You should have received a copy of the GNU Lesser General Public | ||
20 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 20 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
21 | 21 | | |||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include "notifybypopup.h" | 24 | #include "notifybypopup.h" | ||
25 | #include "imageconverter.h" | 25 | #include "imageconverter.h" | ||
26 | #include "notifybypopupgrowl.h" | | |||
27 | 26 | | |||
28 | #include "kpassivepopup.h" | 27 | #include "kpassivepopup.h" | ||
29 | #include "knotifyconfig.h" | 28 | #include "knotifyconfig.h" | ||
30 | #include "knotification.h" | 29 | #include "knotification.h" | ||
31 | #include "debug_p.h" | 30 | #include "debug_p.h" | ||
32 | 31 | | |||
33 | #include <QApplication> | 32 | #include <QApplication> | ||
34 | #include <QBuffer> | 33 | #include <QBuffer> | ||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Line(s) | 226 | if (d->dbusServiceExists) { | |||
238 | } | 237 | } | ||
239 | return; | 238 | return; | ||
240 | } | 239 | } | ||
241 | 240 | | |||
242 | // Persistent => 0 == infinite timeout | 241 | // Persistent => 0 == infinite timeout | ||
243 | // CloseOnTimeout => -1 == let the server decide | 242 | // CloseOnTimeout => -1 == let the server decide | ||
244 | int timeout = (notification->flags() & KNotification::Persistent) ? 0 : -1; | 243 | int timeout = (notification->flags() & KNotification::Persistent) ? 0 : -1; | ||
245 | 244 | | |||
246 | // if Growl can display our popups, use that instead | | |||
247 | if (NotifyByPopupGrowl::canPopup()) { | | |||
248 | | ||||
249 | QString appCaption, iconName; | | |||
250 | d->getAppCaptionAndIconName(notifyConfig, &appCaption, &iconName); | | |||
251 | appCaption = d->stripHtml(appCaption); | | |||
252 | | ||||
253 | //did the user override the icon name? | | |||
254 | if (!notification->iconName().isEmpty()) { | | |||
255 | iconName = notification->iconName(); | | |||
256 | } | | |||
257 | | ||||
258 | // Our growl implementation does not support html stuff | | |||
259 | // so strip it off right away | | |||
260 | QString text = notification->text(); | | |||
261 | text = d->stripHtml(text); | | |||
262 | | ||||
263 | // The first arg is QPixmap*, however that pixmap is not used | | |||
264 | // at all (it has Q_UNUSED) so just set it to 0 | | |||
265 | NotifyByPopupGrowl::popup(nullptr, timeout, appCaption, text); | | |||
266 | | ||||
267 | // Finish immediately, because current NotifyByPopupGrowl can't callback | | |||
268 | finish(notification); | | |||
269 | return; | | |||
270 | } | | |||
271 | | ||||
272 | // Check if this object lives in the GUI thread and return if it doesn't | 245 | // Check if this object lives in the GUI thread and return if it doesn't | ||
273 | // as Qt cannot create/handle widgets in non-GUI threads | 246 | // as Qt cannot create/handle widgets in non-GUI threads | ||
274 | if (QThread::currentThread() != qApp->thread()) { | 247 | if (QThread::currentThread() != qApp->thread()) { | ||
275 | qCWarning(LOG_KNOTIFICATIONS) << "KNotification did not detect any running org.freedesktop.Notifications server and fallback notifications cannot be used from non-GUI thread!"; | 248 | qCWarning(LOG_KNOTIFICATIONS) << "KNotification did not detect any running org.freedesktop.Notifications server and fallback notifications cannot be used from non-GUI thread!"; | ||
276 | return; | 249 | return; | ||
277 | } | 250 | } | ||
278 | 251 | | |||
279 | if (!qobject_cast<QApplication *>(QCoreApplication::instance())) { | 252 | if (!qobject_cast<QApplication *>(QCoreApplication::instance())) { | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 367 | { | |||
399 | } | 372 | } | ||
400 | 373 | | |||
401 | // if Notifications DBus service exists on bus, | 374 | // if Notifications DBus service exists on bus, | ||
402 | // it'll be used instead | 375 | // it'll be used instead | ||
403 | if (d->dbusServiceExists) { | 376 | if (d->dbusServiceExists) { | ||
404 | d->sendNotificationToGalagoServer(notification, notifyConfig, true); | 377 | d->sendNotificationToGalagoServer(notification, notifyConfig, true); | ||
405 | return; | 378 | return; | ||
406 | } | 379 | } | ||
407 | | ||||
408 | // otherwise, just display a new Growl notification | | |||
409 | if (NotifyByPopupGrowl::canPopup()) { | | |||
410 | notify(notification, notifyConfig); | | |||
411 | } | | |||
412 | } | 380 | } | ||
413 | 381 | | |||
414 | void NotifyByPopup::onServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) | 382 | void NotifyByPopup::onServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) | ||
415 | { | 383 | { | ||
416 | Q_UNUSED(serviceName); | 384 | Q_UNUSED(serviceName); | ||
417 | // close all notifications we currently hold reference to | 385 | // close all notifications we currently hold reference to | ||
418 | for (KNotification *n : qAsConst(d->galagoNotifications)) { | 386 | for (KNotification *n : qAsConst(d->galagoNotifications)) { | ||
419 | if (n) { | 387 | if (n) { | ||
▲ Show 20 Lines • Show All 379 Lines • ▼ Show 20 Line(s) | 750 | { | |||
799 | if (!queued) { | 767 | if (!queued) { | ||
800 | qCWarning(LOG_KNOTIFICATIONS) << "Failed to queue dbus message for closing a notification"; | 768 | qCWarning(LOG_KNOTIFICATIONS) << "Failed to queue dbus message for closing a notification"; | ||
801 | } | 769 | } | ||
802 | } | 770 | } | ||
803 | 771 | | |||
804 | void NotifyByPopupPrivate::queryPopupServerCapabilities() | 772 | void NotifyByPopupPrivate::queryPopupServerCapabilities() | ||
805 | { | 773 | { | ||
806 | if (!dbusServiceExists) { | 774 | if (!dbusServiceExists) { | ||
807 | if (NotifyByPopupGrowl::canPopup()) { | | |||
808 | popupServerCapabilities = NotifyByPopupGrowl::capabilities(); | | |||
809 | } else { | | |||
810 | // Return capabilities of the KPassivePopup implementation | 775 | // Return capabilities of the KPassivePopup implementation | ||
811 | popupServerCapabilities = QStringList() << QStringLiteral("actions") << QStringLiteral("body") << QStringLiteral("body-hyperlinks") | 776 | popupServerCapabilities = QStringList() << QStringLiteral("actions") << QStringLiteral("body") << QStringLiteral("body-hyperlinks") | ||
812 | << QStringLiteral("body-markup") << QStringLiteral("icon-static"); | 777 | << QStringLiteral("body-markup") << QStringLiteral("icon-static"); | ||
813 | } | 778 | } | ||
814 | } | | |||
815 | 779 | | |||
816 | if (dbusServiceCapCacheDirty) { | 780 | if (dbusServiceCapCacheDirty) { | ||
817 | QDBusMessage m = QDBusMessage::createMethodCall(QString::fromLatin1(dbusServiceName), | 781 | QDBusMessage m = QDBusMessage::createMethodCall(QString::fromLatin1(dbusServiceName), | ||
818 | QString::fromLatin1(dbusPath), | 782 | QString::fromLatin1(dbusPath), | ||
819 | QString::fromLatin1(dbusInterfaceName), | 783 | QString::fromLatin1(dbusInterfaceName), | ||
820 | QStringLiteral("GetCapabilities")); | 784 | QStringLiteral("GetCapabilities")); | ||
821 | 785 | | |||
822 | QDBusConnection::sessionBus().callWithCallback(m, | 786 | QDBusConnection::sessionBus().callWithCallback(m, | ||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |