diff --git a/common/falkon.notifyrc b/common/falkon.notifyrc index 1089a2359..b1b97d70d 100644 --- a/common/falkon.notifyrc +++ b/common/falkon.notifyrc @@ -14,10 +14,10 @@ Name=Web Comment=Notifications from web sites Action=Popup -[Event/DownloadFinished] -Name=Download Finished -Comment=All downloads are finished -Action=Sound|Popup +[Event/AllDownloadsFinished] +Name=All Downloads Finished +Comment=All downloads finished downloading +Action=Popup [Event/UpdateAvailable] Name=Update Available @@ -27,7 +27,7 @@ Action=Popup [Event/OcsSupport] Name=Plugin installer Comment=Information from online plugin installer -Action=Sound|Popup +Action=Popup [Event/Plugins] Name=Plugins diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index aa9b77327..a4e6499da 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -307,7 +307,7 @@ MainApplication::MainApplication(int &argc, char** argv) m_webProfile->setNotificationPresenter([&] (std::unique_ptr notification) { auto notifications = desktopNotifications(); notifications->showNotification( - QPixmap::fromImage(notification->icon()), notification->title(), notification->message() + QPixmap::fromImage(notification->icon()), notification->title(), notification->message(), DesktopNotificationsFactory::Web ); }); diff --git a/src/lib/downloads/downloadmanager.cpp b/src/lib/downloads/downloadmanager.cpp index 29d4bfd44..015c3ce26 100644 --- a/src/lib/downloads/downloadmanager.cpp +++ b/src/lib/downloads/downloadmanager.cpp @@ -414,7 +414,12 @@ void DownloadManager::downloadFinished(bool success) if (downloadingAllFilesFinished) { if (success && qApp->activeWindow() != this) { - mApp->desktopNotifications()->showNotification(QIcon::fromTheme(QSL("download"), QIcon(QSL(":icons/other/download.svg"))).pixmap(48), tr("Falkon: Download Finished"), tr("All files have been successfully downloaded.")); + mApp->desktopNotifications()->showNotification( + QIcon::fromTheme(QSL("download"),QIcon(QSL(":icons/other/download.svg"))).pixmap(48), + tr("Falkon: Download Finished"), + tr("All files have been successfully downloaded."), + DesktopNotificationsFactory::AllDownloadsFinished + ); if (!m_closeOnFinish) { raise(); activateWindow(); diff --git a/src/lib/notifications/desktopnotificationsfactory.cpp b/src/lib/notifications/desktopnotificationsfactory.cpp index d3a5588ae..da472036d 100644 --- a/src/lib/notifications/desktopnotificationsfactory.cpp +++ b/src/lib/notifications/desktopnotificationsfactory.cpp @@ -65,12 +65,16 @@ bool DesktopNotificationsFactory::supportsNativeNotifications() const #endif } -void DesktopNotificationsFactory::showNotification(const QString &heading, const QString &text) +void DesktopNotificationsFactory::showNotification(const QString &heading, const QString &text, + const DesktopNotificationsFactory::EventType notificationType, + const QHash data) { - showNotification(QPixmap(), heading, text); + showNotification(QPixmap(), heading, text, notificationType, data); } -void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QString &heading, const QString &text, const DesktopNotificationsFactory::EventType notificationType) +void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QString &heading, const QString &text, + const DesktopNotificationsFactory::EventType notificationType, + const QHash data) { if (!m_enabled) { return; @@ -99,16 +103,19 @@ void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QS notification->setPixmap(image); notification->setTitle(heading); notification->setText(text); - notification->setComponentName(QSL("falkon")); - 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"))}); - }); + if (data.contains(DesktopNotificationsFactory::FilePath)) { + QUrl path = data[DesktopNotificationsFactory::FilePath].toUrl(); + + KNotificationAction *actionOpenFile = notification->addAction(tr("Open File")); + connect(actionOpenFile, &KNotificationAction::activated, this, [=]() { + QDesktopServices::openUrl(path); + }); + KNotificationAction *actionOpenFolder = notification->addAction(tr("Open Folder")); + connect(actionOpenFolder, &KNotificationAction::activated, this, [=]() { + QzTools::openFolder({path}); + }); + } notification->sendEvent(); #else @@ -145,7 +152,7 @@ void DesktopNotificationsFactory::nativeNotificationPreview() m_notifType = DesktopNative; const QPixmap icon = mApp->getWindow()->windowIcon().pixmap(64); - showNotification(icon, QObject::tr("Native System Notification"), tr("Preview")); + showNotification(icon, QObject::tr("Native System Notification"), tr("Preview"), DesktopNotificationsFactory::Preview); m_notifType = type; } diff --git a/src/lib/notifications/desktopnotificationsfactory.h b/src/lib/notifications/desktopnotificationsfactory.h index 1ed9ce920..b7ae55226 100644 --- a/src/lib/notifications/desktopnotificationsfactory.h +++ b/src/lib/notifications/desktopnotificationsfactory.h @@ -40,15 +40,16 @@ public: enum EventType { General, Web, - DownloadFinished, + AllDownloadsFinished, UpdateAvailable, OcsSupport, Plugins, Preview, - GreaseMonkeyInstall, - GreaseMonkeyScrips, KWalletDisabled }; + enum EventData { + FilePath + }; explicit DesktopNotificationsFactory(QObject* parent = nullptr); @@ -56,8 +57,12 @@ public: bool supportsNativeNotifications() const; - void showNotification(const QString &heading, const QString &text); - void showNotification(const QPixmap &icon, const QString &heading, const QString &text, const DesktopNotificationsFactory::EventType notificationType = General); + void showNotification(const QString &heading, const QString &text, + const DesktopNotificationsFactory::EventType notificationType = General, + const QHash data = {}); + void showNotification(const QPixmap &icon, const QString &heading, const QString &text, + const DesktopNotificationsFactory::EventType notificationType = General, + const QHash data = {}); void nativeNotificationPreview(); private Q_SLOTS: @@ -76,14 +81,11 @@ private: QHash KNotificationEvents = { {General, QSL("General")}, {Web, QSL("Web")}, - {DownloadFinished, QSL("DownloadFinished")}, + {AllDownloadsFinished, QSL("AllDownloadsFinished")}, {UpdateAvailable, QSL("UpdateAvailable")}, {OcsSupport, QSL("OcsSupport")}, {Plugins, QSL("Plugins")}, - {Preview, QSL("Preview")}, - {GreaseMonkeyInstall, QSL("GreaseMonkeyInstall")}, - {GreaseMonkeyScrips, QSL("GreaseMonkeyScrips")}, - {KWalletDisabled, QSL("KWalletDisabled")} + {Preview, QSL("Preview")} }; }; diff --git a/src/lib/other/updater.cpp b/src/lib/other/updater.cpp index 0a52e9b64..e3c5e216d 100644 --- a/src/lib/other/updater.cpp +++ b/src/lib/other/updater.cpp @@ -148,7 +148,12 @@ void Updater::downCompleted() Version updated(html); if (current.isValid && updated.isValid && current < updated) { - mApp->desktopNotifications()->showNotification(QIcon(QSL(":icons/falkon.svg")).pixmap(48), tr("Update available"), tr("New version of Falkon is ready to download.")); + mApp->desktopNotifications()->showNotification( + QIcon(QSL(":icons/falkon.svg")).pixmap(48), + tr("Update available"), + tr("New version of Falkon is ready to download."), + DesktopNotificationsFactory::UpdateAvailable + ); } } diff --git a/src/lib/plugins/ocssupport.cpp b/src/lib/plugins/ocssupport.cpp index 79919e7cb..1839dd46e 100644 --- a/src/lib/plugins/ocssupport.cpp +++ b/src/lib/plugins/ocssupport.cpp @@ -120,7 +120,7 @@ OcsSupport *OcsSupport::instance() void OcsSupport::installTheme(const KArchiveDirectory *directory) { auto showError = []() { - mApp->desktopNotifications()->showNotification(tr("Installation failed"), tr("Failed to install theme")); + mApp->desktopNotifications()->showNotification(tr("Installation failed"), tr("Failed to install theme"), DesktopNotificationsFactory::OcsSupport); }; if (directory->entries().size() != 1) { @@ -144,7 +144,7 @@ void OcsSupport::installTheme(const KArchiveDirectory *directory) if (QFileInfo::exists(targetDir + QL1C('/') + name)) { qWarning() << "Theme" << name << "already exists"; - mApp->desktopNotifications()->showNotification(tr("Installation failed"), tr("Theme is already installed")); + mApp->desktopNotifications()->showNotification(tr("Installation failed"), tr("Theme is already installed"), DesktopNotificationsFactory::OcsSupport); return; } @@ -156,13 +156,13 @@ void OcsSupport::installTheme(const KArchiveDirectory *directory) qInfo() << "Theme installed to" << targetDir; - mApp->desktopNotifications()->showNotification(tr("Theme installed"), tr("'%1' was successfully installed").arg(metaData.name())); + mApp->desktopNotifications()->showNotification(tr("Theme installed"), tr("'%1' was successfully installed").arg(metaData.name()), DesktopNotificationsFactory::OcsSupport); } void OcsSupport::installExtension(const KArchiveDirectory *directory) { auto showError = []() { - mApp->desktopNotifications()->showNotification(tr("Installation failed"), tr("Failed to install extension")); + mApp->desktopNotifications()->showNotification(tr("Installation failed"), tr("Failed to install extension"), DesktopNotificationsFactory::OcsSupport); }; if (directory->entries().size() != 1) { @@ -200,7 +200,7 @@ void OcsSupport::installExtension(const KArchiveDirectory *directory) if (QFileInfo::exists(targetDir + QL1S("/") + name)) { qWarning() << "Extension" << name << "already exists"; - mApp->desktopNotifications()->showNotification(tr("Installation failed"), tr("Extension is already installed")); + mApp->desktopNotifications()->showNotification(tr("Installation failed"), tr("Extension is already installed"), DesktopNotificationsFactory::OcsSupport); return; } @@ -219,5 +219,5 @@ void OcsSupport::installExtension(const KArchiveDirectory *directory) return; } - mApp->desktopNotifications()->showNotification(tr("Extension installed"), tr("'%1' was successfully installed").arg(metaData.name())); + mApp->desktopNotifications()->showNotification(tr("Extension installed"), tr("'%1' was successfully installed").arg(metaData.name()), DesktopNotificationsFactory::OcsSupport); } diff --git a/src/lib/plugins/qml/api/notifications/qmlnotifications.cpp b/src/lib/plugins/qml/api/notifications/qmlnotifications.cpp index 2b14626f0..d07a16b46 100644 --- a/src/lib/plugins/qml/api/notifications/qmlnotifications.cpp +++ b/src/lib/plugins/qml/api/notifications/qmlnotifications.cpp @@ -34,7 +34,7 @@ void QmlNotifications::create(const QVariantMap &map) const QPixmap icon = QPixmap(iconPath); const QString heading = map.value(QSL("heading")).toString(); const QString message = map.value(QSL("message")).toString(); - mApp->desktopNotifications()->showNotification(icon, heading, message); + mApp->desktopNotifications()->showNotification(icon, heading, message, DesktopNotificationsFactory::Plugins); } void QmlNotifications::setPluginPath(const QString &path) diff --git a/src/plugins/GreaseMonkey/gm_manager.cpp b/src/plugins/GreaseMonkey/gm_manager.cpp index 59dea6644..efd856900 100644 --- a/src/plugins/GreaseMonkey/gm_manager.cpp +++ b/src/plugins/GreaseMonkey/gm_manager.cpp @@ -231,7 +231,7 @@ void GM_Manager::showNotification(const QString &message, const QString &title) { QIcon icon(QSL(":gm/data/icon.svg")); - mApp->desktopNotifications()->showNotification(icon.pixmap(48), title.isEmpty() ? tr("GreaseMonkey") : title, message); + mApp->desktopNotifications()->showNotification(icon.pixmap(48), title.isEmpty() ? tr("GreaseMonkey") : title, message, DesktopNotificationsFactory::Plugins); } void GM_Manager::load() diff --git a/src/plugins/KDEFrameworksIntegration/kwalletpasswordbackend.cpp b/src/plugins/KDEFrameworksIntegration/kwalletpasswordbackend.cpp index 1f1428cfa..851751132 100644 --- a/src/plugins/KDEFrameworksIntegration/kwalletpasswordbackend.cpp +++ b/src/plugins/KDEFrameworksIntegration/kwalletpasswordbackend.cpp @@ -194,7 +194,11 @@ void KWalletPasswordBackend::showErrorNotification() if (!initialized) { initialized = true; - mApp->desktopNotifications()->showNotification(KDEFrameworksIntegrationPlugin::tr("KWallet disabled"), KDEFrameworksIntegrationPlugin::tr("Please enable KWallet to save password.")); + mApp->desktopNotifications()->showNotification( + KDEFrameworksIntegrationPlugin::tr("KWallet disabled"), + KDEFrameworksIntegrationPlugin::tr("Please enable KWallet to save password."), + DesktopNotificationsFactory::Plugins + ); } }