mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-19 18:26: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
|
Comment=Notifications from web sites
|
||||||
Action=Popup
|
Action=Popup
|
||||||
|
|
||||||
[Event/DownloadFinished]
|
[Event/AllDownloadsFinished]
|
||||||
Name=Download Finished
|
Name=All Downloads Finished
|
||||||
Comment=All downloads are finished
|
Comment=All downloads finished downloading
|
||||||
Action=Sound|Popup
|
Action=Popup
|
||||||
|
|
||||||
[Event/UpdateAvailable]
|
[Event/UpdateAvailable]
|
||||||
Name=Update Available
|
Name=Update Available
|
||||||
@ -27,7 +27,7 @@ Action=Popup
|
|||||||
[Event/OcsSupport]
|
[Event/OcsSupport]
|
||||||
Name=Plugin installer
|
Name=Plugin installer
|
||||||
Comment=Information from online plugin installer
|
Comment=Information from online plugin installer
|
||||||
Action=Sound|Popup
|
Action=Popup
|
||||||
|
|
||||||
[Event/Plugins]
|
[Event/Plugins]
|
||||||
Name=Plugins
|
Name=Plugins
|
||||||
|
@ -307,7 +307,7 @@ MainApplication::MainApplication(int &argc, char** argv)
|
|||||||
m_webProfile->setNotificationPresenter([&] (std::unique_ptr<QWebEngineNotification> notification) {
|
m_webProfile->setNotificationPresenter([&] (std::unique_ptr<QWebEngineNotification> notification) {
|
||||||
auto notifications = desktopNotifications();
|
auto notifications = desktopNotifications();
|
||||||
notifications->showNotification(
|
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 (downloadingAllFilesFinished) {
|
||||||
if (success && qApp->activeWindow() != this) {
|
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) {
|
if (!m_closeOnFinish) {
|
||||||
raise();
|
raise();
|
||||||
activateWindow();
|
activateWindow();
|
||||||
|
@ -65,12 +65,16 @@ bool DesktopNotificationsFactory::supportsNativeNotifications() const
|
|||||||
#endif
|
#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) {
|
if (!m_enabled) {
|
||||||
return;
|
return;
|
||||||
@ -99,16 +103,19 @@ void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QS
|
|||||||
notification->setPixmap(image);
|
notification->setPixmap(image);
|
||||||
notification->setTitle(heading);
|
notification->setTitle(heading);
|
||||||
notification->setText(text);
|
notification->setText(text);
|
||||||
notification->setComponentName(QSL("falkon"));
|
|
||||||
|
|
||||||
KNotificationAction *actionOpenFile = notification->addAction(tr("Open File"));
|
if (data.contains(DesktopNotificationsFactory::FilePath)) {
|
||||||
connect(actionOpenFile, &KNotificationAction::activated, this, [=]() {
|
QUrl path = data[DesktopNotificationsFactory::FilePath].toUrl();
|
||||||
QDesktopServices::openUrl(QUrl(QSL("file:///home/juraj")));
|
|
||||||
});
|
KNotificationAction *actionOpenFile = notification->addAction(tr("Open File"));
|
||||||
KNotificationAction *actionOpenFolder = notification->addAction(tr("Open Folder"));
|
connect(actionOpenFile, &KNotificationAction::activated, this, [=]() {
|
||||||
connect(actionOpenFolder, &KNotificationAction::activated, this, [=]() {
|
QDesktopServices::openUrl(path);
|
||||||
QzTools::openFolder({QUrl(QSL("/home/juraj"))});
|
});
|
||||||
});
|
KNotificationAction *actionOpenFolder = notification->addAction(tr("Open Folder"));
|
||||||
|
connect(actionOpenFolder, &KNotificationAction::activated, this, [=]() {
|
||||||
|
QzTools::openFolder({path});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
#else
|
#else
|
||||||
@ -145,7 +152,7 @@ void DesktopNotificationsFactory::nativeNotificationPreview()
|
|||||||
|
|
||||||
m_notifType = DesktopNative;
|
m_notifType = DesktopNative;
|
||||||
const QPixmap icon = mApp->getWindow()->windowIcon().pixmap(64);
|
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;
|
m_notifType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,15 +40,16 @@ public:
|
|||||||
enum EventType {
|
enum EventType {
|
||||||
General,
|
General,
|
||||||
Web,
|
Web,
|
||||||
DownloadFinished,
|
AllDownloadsFinished,
|
||||||
UpdateAvailable,
|
UpdateAvailable,
|
||||||
OcsSupport,
|
OcsSupport,
|
||||||
Plugins,
|
Plugins,
|
||||||
Preview,
|
Preview,
|
||||||
GreaseMonkeyInstall,
|
|
||||||
GreaseMonkeyScrips,
|
|
||||||
KWalletDisabled
|
KWalletDisabled
|
||||||
};
|
};
|
||||||
|
enum EventData {
|
||||||
|
FilePath
|
||||||
|
};
|
||||||
|
|
||||||
explicit DesktopNotificationsFactory(QObject* parent = nullptr);
|
explicit DesktopNotificationsFactory(QObject* parent = nullptr);
|
||||||
|
|
||||||
@ -56,8 +57,12 @@ public:
|
|||||||
|
|
||||||
bool supportsNativeNotifications() const;
|
bool supportsNativeNotifications() const;
|
||||||
|
|
||||||
void showNotification(const QString &heading, const QString &text);
|
void showNotification(const QString &heading, const QString &text,
|
||||||
void showNotification(const QPixmap &icon, const QString &heading, const QString &text, const DesktopNotificationsFactory::EventType notificationType = General);
|
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();
|
void nativeNotificationPreview();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
@ -76,14 +81,11 @@ private:
|
|||||||
QHash<EventType, QString> KNotificationEvents = {
|
QHash<EventType, QString> KNotificationEvents = {
|
||||||
{General, QSL("General")},
|
{General, QSL("General")},
|
||||||
{Web, QSL("Web")},
|
{Web, QSL("Web")},
|
||||||
{DownloadFinished, QSL("DownloadFinished")},
|
{AllDownloadsFinished, QSL("AllDownloadsFinished")},
|
||||||
{UpdateAvailable, QSL("UpdateAvailable")},
|
{UpdateAvailable, QSL("UpdateAvailable")},
|
||||||
{OcsSupport, QSL("OcsSupport")},
|
{OcsSupport, QSL("OcsSupport")},
|
||||||
{Plugins, QSL("Plugins")},
|
{Plugins, QSL("Plugins")},
|
||||||
{Preview, QSL("Preview")},
|
{Preview, QSL("Preview")}
|
||||||
{GreaseMonkeyInstall, QSL("GreaseMonkeyInstall")},
|
|
||||||
{GreaseMonkeyScrips, QSL("GreaseMonkeyScrips")},
|
|
||||||
{KWalletDisabled, QSL("KWalletDisabled")}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -148,7 +148,12 @@ void Updater::downCompleted()
|
|||||||
Version updated(html);
|
Version updated(html);
|
||||||
|
|
||||||
if (current.isValid && updated.isValid && current < updated) {
|
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)
|
void OcsSupport::installTheme(const KArchiveDirectory *directory)
|
||||||
{
|
{
|
||||||
auto showError = []() {
|
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) {
|
if (directory->entries().size() != 1) {
|
||||||
@ -144,7 +144,7 @@ void OcsSupport::installTheme(const KArchiveDirectory *directory)
|
|||||||
|
|
||||||
if (QFileInfo::exists(targetDir + QL1C('/') + name)) {
|
if (QFileInfo::exists(targetDir + QL1C('/') + name)) {
|
||||||
qWarning() << "Theme" << name << "already exists";
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,13 +156,13 @@ void OcsSupport::installTheme(const KArchiveDirectory *directory)
|
|||||||
|
|
||||||
qInfo() << "Theme installed to" << targetDir;
|
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)
|
void OcsSupport::installExtension(const KArchiveDirectory *directory)
|
||||||
{
|
{
|
||||||
auto showError = []() {
|
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) {
|
if (directory->entries().size() != 1) {
|
||||||
@ -200,7 +200,7 @@ void OcsSupport::installExtension(const KArchiveDirectory *directory)
|
|||||||
|
|
||||||
if (QFileInfo::exists(targetDir + QL1S("/") + name)) {
|
if (QFileInfo::exists(targetDir + QL1S("/") + name)) {
|
||||||
qWarning() << "Extension" << name << "already exists";
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,5 +219,5 @@ void OcsSupport::installExtension(const KArchiveDirectory *directory)
|
|||||||
return;
|
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 QPixmap icon = QPixmap(iconPath);
|
||||||
const QString heading = map.value(QSL("heading")).toString();
|
const QString heading = map.value(QSL("heading")).toString();
|
||||||
const QString message = map.value(QSL("message")).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)
|
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"));
|
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()
|
void GM_Manager::load()
|
||||||
|
@ -194,7 +194,11 @@ void KWalletPasswordBackend::showErrorNotification()
|
|||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialized = true;
|
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