mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-19 10:16:34 +01:00
Use KNotifications events
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
2e4478b6f6
commit
2f108f0f8f
@ -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
|
||||
|
@ -307,7 +307,7 @@ MainApplication::MainApplication(int &argc, char** argv)
|
||||
m_webProfile->setNotificationPresenter([&] (std::unique_ptr<QWebEngineNotification> notification) {
|
||||
auto notifications = desktopNotifications();
|
||||
notifications->showNotification(
|
||||
QPixmap::fromImage(notification->icon()), notification->title(), notification->message()
|
||||
QPixmap::fromImage(notification->icon()), notification->title(), notification->message(), DesktopNotificationsFactory::Web
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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<DesktopNotificationsFactory::EventData, QVariant> 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<DesktopNotificationsFactory::EventData, QVariant> 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;
|
||||
}
|
||||
|
||||
|
@ -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<DesktopNotificationsFactory::EventData, QVariant> data = {});
|
||||
void showNotification(const QPixmap &icon, const QString &heading, const QString &text,
|
||||
const DesktopNotificationsFactory::EventType notificationType = General,
|
||||
const QHash<DesktopNotificationsFactory::EventData, QVariant> data = {});
|
||||
void nativeNotificationPreview();
|
||||
|
||||
private Q_SLOTS:
|
||||
@ -76,14 +81,11 @@ private:
|
||||
QHash<EventType, QString> 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")}
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user