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 200 Lines • ▼ Show 20 Line(s) | 223 | if (d->dbusServiceExists) { | |||
235 | } | 234 | } | ||
236 | return; | 235 | return; | ||
237 | } | 236 | } | ||
238 | 237 | | |||
239 | // Persistent => 0 == infinite timeout | 238 | // Persistent => 0 == infinite timeout | ||
240 | // CloseOnTimeout => -1 == let the server decide | 239 | // CloseOnTimeout => -1 == let the server decide | ||
241 | int timeout = (notification->flags() & KNotification::Persistent) ? 0 : -1; | 240 | int timeout = (notification->flags() & KNotification::Persistent) ? 0 : -1; | ||
242 | 241 | | |||
243 | // if Growl can display our popups, use that instead | | |||
244 | if (NotifyByPopupGrowl::canPopup()) { | | |||
245 | | ||||
246 | QString appCaption, iconName; | | |||
247 | d->getAppCaptionAndIconName(notifyConfig, &appCaption, &iconName); | | |||
248 | appCaption = d->stripHtml(appCaption); | | |||
249 | | ||||
250 | //did the user override the icon name? | | |||
251 | if (!notification->iconName().isEmpty()) { | | |||
252 | iconName = notification->iconName(); | | |||
253 | } | | |||
254 | | ||||
255 | // Our growl implementation does not support html stuff | | |||
256 | // so strip it off right away | | |||
257 | QString text = notification->text(); | | |||
258 | text = d->stripHtml(text); | | |||
259 | | ||||
260 | // The first arg is QPixmap*, however that pixmap is not used | | |||
261 | // at all (it has Q_UNUSED) so just set it to 0 | | |||
262 | NotifyByPopupGrowl::popup(nullptr, timeout, appCaption, text); | | |||
263 | | ||||
264 | // Finish immediately, because current NotifyByPopupGrowl can't callback | | |||
265 | finish(notification); | | |||
266 | return; | | |||
267 | } | | |||
268 | | ||||
269 | // Check if this object lives in the GUI thread and return if it doesn't | 242 | // Check if this object lives in the GUI thread and return if it doesn't | ||
270 | // as Qt cannot create/handle widgets in non-GUI threads | 243 | // as Qt cannot create/handle widgets in non-GUI threads | ||
271 | if (QThread::currentThread() != qApp->thread()) { | 244 | if (QThread::currentThread() != qApp->thread()) { | ||
272 | qCWarning(LOG_KNOTIFICATIONS) << "KNotification did not detect any running org.freedesktop.Notifications server and fallback notifications cannot be used from non-GUI thread!"; | 245 | qCWarning(LOG_KNOTIFICATIONS) << "KNotification did not detect any running org.freedesktop.Notifications server and fallback notifications cannot be used from non-GUI thread!"; | ||
273 | return; | 246 | return; | ||
274 | } | 247 | } | ||
275 | 248 | | |||
276 | if (!qobject_cast<QApplication *>(QCoreApplication::instance())) { | 249 | if (!qobject_cast<QApplication *>(QCoreApplication::instance())) { | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 364 | { | |||
396 | } | 369 | } | ||
397 | 370 | | |||
398 | // if Notifications DBus service exists on bus, | 371 | // if Notifications DBus service exists on bus, | ||
399 | // it'll be used instead | 372 | // it'll be used instead | ||
400 | if (d->dbusServiceExists) { | 373 | if (d->dbusServiceExists) { | ||
401 | d->sendNotificationToGalagoServer(notification, notifyConfig, true); | 374 | d->sendNotificationToGalagoServer(notification, notifyConfig, true); | ||
402 | return; | 375 | return; | ||
403 | } | 376 | } | ||
404 | | ||||
405 | // otherwise, just display a new Growl notification | | |||
406 | if (NotifyByPopupGrowl::canPopup()) { | | |||
407 | notify(notification, notifyConfig); | | |||
408 | } | | |||
409 | } | 377 | } | ||
410 | 378 | | |||
411 | void NotifyByPopup::onServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) | 379 | void NotifyByPopup::onServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) | ||
412 | { | 380 | { | ||
413 | Q_UNUSED(serviceName); | 381 | Q_UNUSED(serviceName); | ||
414 | // close all notifications we currently hold reference to | 382 | // close all notifications we currently hold reference to | ||
415 | for (KNotification *n : qAsConst(d->galagoNotifications)) { | 383 | for (KNotification *n : qAsConst(d->galagoNotifications)) { | ||
416 | if (n) { | 384 | if (n) { | ||
▲ Show 20 Lines • Show All 379 Lines • ▼ Show 20 Line(s) | 747 | { | |||
796 | if (!queued) { | 764 | if (!queued) { | ||
797 | qCWarning(LOG_KNOTIFICATIONS) << "Failed to queue dbus message for closing a notification"; | 765 | qCWarning(LOG_KNOTIFICATIONS) << "Failed to queue dbus message for closing a notification"; | ||
798 | } | 766 | } | ||
799 | } | 767 | } | ||
800 | 768 | | |||
801 | void NotifyByPopupPrivate::queryPopupServerCapabilities() | 769 | void NotifyByPopupPrivate::queryPopupServerCapabilities() | ||
802 | { | 770 | { | ||
803 | if (!dbusServiceExists) { | 771 | if (!dbusServiceExists) { | ||
804 | if (NotifyByPopupGrowl::canPopup()) { | | |||
805 | popupServerCapabilities = NotifyByPopupGrowl::capabilities(); | | |||
806 | } else { | | |||
807 | // Return capabilities of the KPassivePopup implementation | 772 | // Return capabilities of the KPassivePopup implementation | ||
808 | popupServerCapabilities = QStringList() << QStringLiteral("actions") << QStringLiteral("body") << QStringLiteral("body-hyperlinks") | 773 | popupServerCapabilities = QStringList() << QStringLiteral("actions") << QStringLiteral("body") << QStringLiteral("body-hyperlinks") | ||
809 | << QStringLiteral("body-markup") << QStringLiteral("icon-static"); | 774 | << QStringLiteral("body-markup") << QStringLiteral("icon-static"); | ||
810 | } | 775 | } | ||
811 | } | | |||
812 | 776 | | |||
813 | if (dbusServiceCapCacheDirty) { | 777 | if (dbusServiceCapCacheDirty) { | ||
814 | QDBusMessage m = QDBusMessage::createMethodCall(QString::fromLatin1(dbusServiceName), | 778 | QDBusMessage m = QDBusMessage::createMethodCall(QString::fromLatin1(dbusServiceName), | ||
815 | QString::fromLatin1(dbusPath), | 779 | QString::fromLatin1(dbusPath), | ||
816 | QString::fromLatin1(dbusInterfaceName), | 780 | QString::fromLatin1(dbusInterfaceName), | ||
817 | QStringLiteral("GetCapabilities")); | 781 | QStringLiteral("GetCapabilities")); | ||
818 | 782 | | |||
819 | QDBusConnection::sessionBus().callWithCallback(m, | 783 | QDBusConnection::sessionBus().callWithCallback(m, | ||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |