From f94610632119de26f0f25859b77ebd7d1c805904 Mon Sep 17 00:00:00 2001
From: Ivailo Monev
Date: Sat, 26 Aug 2023 22:06:45 +0300
Subject: [PATCH] kget: adjust to KNotification changes
Signed-off-by: Ivailo Monev
---
kget/core/kget.cpp | 172 +++++++++++++++-----
kget/core/urlchecker.cpp | 28 +++-
kget/extensions/webinterface/httpserver.cpp | 24 ++-
3 files changed, 168 insertions(+), 56 deletions(-)
diff --git a/kget/core/kget.cpp b/kget/core/kget.cpp
index 2f5dbd55..b4cc2def 100644
--- a/kget/core/kget.cpp
+++ b/kget/core/kget.cpp
@@ -244,9 +244,14 @@ TransferHandler * KGet::addTransfer(KUrl srcUrl, QString destDir, QString sugges
TransferHandler *transfer = createTransfer(srcUrl, destUrl, groupName, start);
if (transfer) {
- KGet::showNotification(m_mainWindow, "kget/added",
- i18n("The following transfer has been added to the download list:
%1
", transfer->source().pathOrUrl()),
- "kget", i18n("Download added"));
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow,
+ "kget/added",
+ i18n("The following transfer has been added to the download list:
%1
", transfer->source().pathOrUrl()),
+ "kget",
+ i18n("Download added")
+ );
+ notification->send();
}
return transfer;
@@ -343,7 +348,14 @@ const QList KGet::addTransfer(KUrl::List srcUrls, QString des
message = i18n("The following transfers have been added to the download list:
");
}
const QString content = QString("%1
").arg(urls);
- KGet::showNotification(m_mainWindow, "kget/added", message + content, "kget", i18n("Download added"));
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow,
+ "kget/added",
+ message + content,
+ "kget",
+ i18n("Download added")
+ );
+ notification->send();
}
return transfers;
@@ -569,8 +581,11 @@ void KGet::save( QString filename, bool plain ) // krazy:exclude=passbyvalue
if ( !file.open( QIODevice::WriteOnly ) )
{
// kWarning() << "Unable to open output file when saving";
- KGet::showNotification(m_mainWindow, "kget/error",
- i18n("Unable to save to: %1", filename));
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow, "kget/error",
+ i18n("Unable to save to: %1", filename)
+ );
+ notification->send();
return;
}
@@ -881,7 +896,14 @@ QList KGet::createTransfers(const QList &dataIte
}
content = QString("%1
").arg(content);
- KGet::showNotification(m_mainWindow, "kget/error", message + content, "dialog-error", i18n("Protocol unsupported"));
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow,
+ "kget/error",
+ message + content,
+ "dialog-error",
+ i18n("Protocol unsupported")
+ );
+ notification->send();
}
//add the created transfers to the model and start them if specified
@@ -982,16 +1004,20 @@ bool KGet::isValidSource(const KUrl &source)
{
// Check if the URL is well formed
if (!source.isValid()) {
- KGet::showNotification(m_mainWindow, "kget/error",
- i18n("Malformed URL:\n%1", source.prettyUrl()));
-
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow, "kget/error",
+ i18n("Malformed URL:\n%1", source.prettyUrl())
+ );
+ notification->send();
return false;
}
// Check if the URL contains the protocol
if (source.protocol().isEmpty()){
- KGet::showNotification(m_mainWindow, "kget/error",
- i18n("Malformed URL, protocol missing:\n%1", source.prettyUrl()));
-
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow, "kget/error",
+ i18n("Malformed URL, protocol missing:\n%1", source.prettyUrl())
+ );
+ notification->send();
return false;
}
// Check if a transfer with the same url already exists
@@ -1193,16 +1219,23 @@ void KGet::setHasNetworkConnection(bool hasConnection)
const bool finalState = m_scheduler->hasRunningJobs();
if (initialState != finalState) {
+ KNotification *notification = nullptr;
if (hasConnection) {
- KGet::showNotification(m_mainWindow, "kget/notification",
- i18n("Internet connection established, resuming transfers."),
- "dialog-info");
+ notification = KGet::showNotification(
+ m_mainWindow, "kget/notification",
+ i18n("Internet connection established, resuming transfers."),
+ "dialog-info"
+ );
} else {
- KGet::showNotification(m_mainWindow, "kget/notification",
- i18n("No internet connection, stopping transfers."),
- "dialog-info");
+ notification = KGet::showNotification(
+ m_mainWindow,
+ "kget/notification",
+ i18n("No internet connection, stopping transfers."),
+ "dialog-info"
+ );
}
+ notification->send();
}
}
@@ -1214,9 +1247,13 @@ KGetPlugin * KGet::createPluginFromService( const KService::Ptr &service )
if (!factory)
{
- KGet::showNotification(m_mainWindow, "kget/error",
- i18n("Plugin loader could not load the plugin: %1.", service->library()),
- "dialog-info");
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow,
+ "kget/error",
+ i18n("Plugin loader could not load the plugin: %1.", service->library()),
+ "dialog-info"
+ );
+ notification->send();
kError() << "KPluginFactory could not load the plugin:" << service->library() << loader.errorString();
return 0;
}
@@ -1227,31 +1264,41 @@ KGetPlugin * KGet::createPluginFromService( const KService::Ptr &service )
bool KGet::safeDeleteFile( const KUrl& url )
{
- if ( url.isLocalFile() )
- {
+ if ( url.isLocalFile() ) {
QFileInfo info( url.toLocalFile() );
- if ( info.isDir() )
- {
- KGet::showNotification(m_mainWindow, "kget/notification",
- i18n("Not deleting\n%1\nas it is a directory.", url.prettyUrl()),
- "dialog-info");
+ if (info.isDir()) {
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow, "kget/notification",
+ i18n("Not deleting\n%1\nas it is a directory.", url.prettyUrl()),
+ "dialog-info"
+ );
+ notification->send();
return false;
}
KIO::NetAccess::del( url, 0L );
return true;
}
-
- else
- KGet::showNotification(m_mainWindow, "kget/notification",
- i18n("Not deleting\n%1\nas it is not a local file.", url.prettyUrl()),
- "dialog-info");
+ KNotification *notification = KGet::showNotification(
+ m_mainWindow,
+ "kget/notification",
+ i18n("Not deleting\n%1\nas it is not a local file.", url.prettyUrl()),
+ "dialog-info"
+ );
+ notification->send();
return false;
}
KNotification *KGet::showNotification(QWidget *parent, const QString &eventType,
const QString &text, const QString &icon, const QString &title, const KNotification::NotificationFlags &flags)
{
- return KNotification::event(eventType, title, text, icon, parent, flags);
+ KNotification *notification = new KNotification(parent);
+ notification->setEventID(eventType);
+ notification->setText(text);
+ notification->setIcon(icon);
+ notification->setTitle(title);
+ notification->setWidget(parent);
+ notification->setFlags(flags);
+ return notification;
}
GenericObserver::GenericObserver(QObject *parent)
@@ -1353,17 +1400,19 @@ void GenericObserver::transfersChangedEvent(QMapstatus() == Job::Finished) && (transfer->startStatus() != Job::Finished)) {
- KGet::showNotification(
+ KNotification* notification = KGet::showNotification(
KGet::m_mainWindow, "kget/finished",
i18n("The following file has finished downloading:
%1
", transfer->dest().fileName()),
"kget", i18n("Download completed")
);
+ notification->send();
} else if (transfer->status() == Job::Running) {
- KGet::showNotification(
+ KNotification* notification = KGet::showNotification(
KGet::m_mainWindow, "kget/started",
i18n("The following transfer has been started:
%1
", transfer->source().pathOrUrl()),
"kget", i18n("Download started")
);
+ notification->send();
} else if (transfer->status() == Job::Aborted && transfer->error().type != Job::AutomaticRetry) {
KNotification* notification = new KNotification(this);
notification->setEventID("kget/error");
@@ -1420,7 +1469,7 @@ void GenericObserver::transfersChangedEvent(QMapAll transfers have been finished.
"),
- "kget", i18n("Downloads completed"));
+ KNotification *notification = KGet::showNotification(
+ KGet::m_mainWindow,
+ "kget/finishedall",
+ i18n("All transfers have been finished.
"),
+ "kget",
+ i18n("Downloads completed")
+ );
+ notification->send();
}
}
diff --git a/kget/core/urlchecker.cpp b/kget/core/urlchecker.cpp
index c7a592d4..48beff71 100644
--- a/kget/core/urlchecker.cpp
+++ b/kget/core/urlchecker.cpp
@@ -166,7 +166,12 @@ UrlChecker::UrlError UrlChecker::checkSource(const KUrl &src, bool showNotificat
if (showNotification && (error != NoError)) {
kDebug() << "Source:" << src << "has error:" << error;
- KGet::showNotification(KGet::m_mainWindow, "kget/error", message(src, Source, error));
+ KNotification* notification = KGet::showNotification(
+ KGet::m_mainWindow,
+ "kget/error",
+ message(src, Source, error)
+ );
+ notification->send();
}
return error;
@@ -194,7 +199,12 @@ UrlChecker::UrlError UrlChecker::checkDestination(const KUrl &destination, bool
if (showNotification && (error != NoError)) {
kDebug() << "Destination:" << destination << "has error:" << error;
- KGet::showNotification(KGet::m_mainWindow, "kget/error", message(destination, Destination, error));
+ KNotification* notification = KGet::showNotification(
+ KGet::m_mainWindow,
+ "kget/error",
+ message(destination, Destination, error)
+ );
+ notification->send();
}
return error;
@@ -225,7 +235,12 @@ UrlChecker::UrlError UrlChecker::checkFolder(const KUrl &folder, bool showNotifi
if (showNotification && (error != NoError)) {
kDebug() << "Folder:" << folder << "has error:" << error;
- KGet::showNotification(KGet::m_mainWindow, "kget/error", message(folder, Folder, error));
+ KNotification* notification = KGet::showNotification(
+ KGet::m_mainWindow,
+ "kget/error",
+ message(folder, Folder, error)
+ );
+ notification->send();
}
return error;
@@ -847,7 +862,12 @@ void UrlChecker::displayErrorMessages()
}
if (!m.isEmpty()) {
- KGet::showNotification(KGet::m_mainWindow, "kget/error", m);
+ KNotification* notification = KGet::showNotification(
+ KGet::m_mainWindow,
+ "kget/error",
+ m
+ );
+ notification->send();
}
}
}
diff --git a/kget/extensions/webinterface/httpserver.cpp b/kget/extensions/webinterface/httpserver.cpp
index 4dbdb835..ea314a46 100644
--- a/kget/extensions/webinterface/httpserver.cpp
+++ b/kget/extensions/webinterface/httpserver.cpp
@@ -39,21 +39,27 @@ HttpServer::HttpServer(QWidget *parent)
const QString usr = Settings::webinterfaceUser();
const QString pwd = m_passwdstore->getPasswd("Webinterface", parent->winId());
if (!setAuthenticate(usr.toUtf8(), pwd.toUtf8())) {
- KGet::showNotification(parent,
+ KNotification* notification = KGet::showNotification(
+ parent,
"kget/error", i18nc("@info", "Unable to set the WebInterface authorization: %1", errorString())
);
+ notification->send();
return;
}
if (!start(QHostAddress::Any, Settings::webinterfacePort())) {
- KGet::showNotification(parent,
+ KNotification* notification = KGet::showNotification(
+ parent,
"kget/error", i18nc("@info", "Unable to start WebInterface: %1", errorString())
);
+ notification->send();
return;
}
} else {
- KGet::showNotification(parent,
+ KNotification* notification = KGet::showNotification(
+ parent,
"kget/error", i18n("Unable to start WebInterface: Could not open KPasswdStore")
);
+ notification->send();
}
}
@@ -69,17 +75,21 @@ void HttpServer::settingsChanged()
const QString pwd = m_passwdstore->getPasswd("Webinterface");
stop();
if (!setAuthenticate(usr.toUtf8(), pwd.toUtf8())) {
- KGet::showNotification(
+ KNotification* notification = KGet::showNotification(
parentwidget,
- "kget/error", i18nc("@info", "Unable to set the WebInterface authorization: %1", errorString())
+ "kget/error",
+ i18nc("@info", "Unable to set the WebInterface authorization: %1", errorString())
);
+ notification->send();
return;
}
if (!start(QHostAddress::Any, Settings::webinterfacePort())) {
- KGet::showNotification(
+ KNotification* notification = KGet::showNotification(
parentwidget,
- "kget/error", i18nc("@info", "Unable to restart WebInterface: %1", errorString())
+ "kget/error",
+ i18nc("@info", "Unable to restart WebInterface: %1", errorString())
);
+ notification->send();
return;
}
}