diff --git a/src/lib/notifications/desktopnotificationsfactory.cpp b/src/lib/notifications/desktopnotificationsfactory.cpp index f1511d0d1..d3a5588ae 100644 --- a/src/lib/notifications/desktopnotificationsfactory.cpp +++ b/src/lib/notifications/desktopnotificationsfactory.cpp @@ -22,11 +22,13 @@ #include "mainapplication.h" #include "browserwindow.h" #include "../config.h" +#include "qztools.h" #include #include #include +#include #if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS) #include @@ -68,7 +70,7 @@ void DesktopNotificationsFactory::showNotification(const QString &heading, const showNotification(QPixmap(), heading, text); } -void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QString &heading, const QString &text) +void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QString &heading, const QString &text, const DesktopNotificationsFactory::EventType notificationType) { if (!m_enabled) { return; @@ -86,16 +88,30 @@ void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QS m_desktopNotif.data()->move(m_position); m_desktopNotif.data()->show(); break; - case DesktopNative: - KNotification *notification = new KNotification(QSL("contactOnline")); + case DesktopNative: { +#if 1 + if (!KNotificationEvents.contains(notificationType)) { + qWarning() << "Invalid notification type"; + } + + QPixmap image = icon.copy(); /* Workaround for corrupted image */ + KNotification *notification = new KNotification(KNotificationEvents[notificationType]); + notification->setPixmap(image); notification->setTitle(heading); notification->setText(text); - notification->setPixmap(icon); - // notification->setActions({tr("Open chat")}); + notification->setComponentName(QSL("falkon")); - // connect(notification, QOverload::of(&KNotification::activated), contact, &Contact::slotOpenChat); + KNotificationAction *actionOpenFile = notification->addAction(tr("Open File")); + connect(actionOpenFile, &KNotificationAction::activated, this, [=]() { + QDesktopServices::openUrl(QUrl(QSL("file:///home/juraj"))); + }); + KNotificationAction *actionOpenFolder = notification->addAction(tr("Open Folder")); + connect(actionOpenFolder, &KNotificationAction::activated, this, [=]() { + QzTools::openFolder({QUrl(QSL("/home/juraj"))}); + }); notification->sendEvent(); +#else #if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS) QFile tmp(DataPaths::path(DataPaths::Temp) + QLatin1String("/falkon_notif.png")); tmp.open(QFile::WriteOnly); @@ -116,9 +132,11 @@ void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QS args.append(hints); args.append(m_timeout); dbus.callWithCallback(QSL("Notify"), args, this, SLOT(updateLastId(QDBusMessage)), SLOT(error(QDBusError))); +#endif #endif break; } + } } void DesktopNotificationsFactory::nativeNotificationPreview() diff --git a/src/lib/notifications/desktopnotificationsfactory.h b/src/lib/notifications/desktopnotificationsfactory.h index c002fe8c0..1ed9ce920 100644 --- a/src/lib/notifications/desktopnotificationsfactory.h +++ b/src/lib/notifications/desktopnotificationsfactory.h @@ -57,7 +57,7 @@ public: bool supportsNativeNotifications() const; void showNotification(const QString &heading, const QString &text); - void showNotification(const QPixmap &icon, const QString &heading, const QString &text); + void showNotification(const QPixmap &icon, const QString &heading, const QString &text, const DesktopNotificationsFactory::EventType notificationType = General); void nativeNotificationPreview(); private Q_SLOTS: