Commit 3babd32f authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Downloads] Port to KUIServerV2JobTracker and enable instant reporting

We probably don't want the KIO Widgets job tracker as fallback as
that won't be any more useful than what the browser has buit-in.

Furthermore, set immediate progress reporting, so that the job is shown
right away and always, i.e. even when downloading a small file will show
a "Finished" notification with useful "Open" action.

Finally, while at it get rid of "id" in `DownloadJob` as it was never used.
parent f1c48155
......@@ -5,7 +5,7 @@ set(PROJECT_VERSION "5.21.80")
set(PROJECT_VERSION_MAJOR 5)
set(QT_MIN_VERSION "5.9.0")
set(KF5_MIN_VERSION "5.72.0")
set(KF5_MIN_VERSION "5.81.0")
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} )
......@@ -34,6 +34,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Activities
Purpose
FileMetaData
JobWidgets
)
find_package(LibTaskManager ${PROJECT_VERSION} CONFIG REQUIRED)
......
......@@ -32,6 +32,7 @@ target_link_libraries(
KF5::CoreAddons
KF5::Crash
KF5::I18n
KF5::JobWidgets
KF5::KIOCore
KF5::PurposeWidgets
KF5::Runner
......
......@@ -15,13 +15,17 @@
#include <KActivities/ResourceInstance>
#include <KFileMetaData/UserMetaData>
#include <KLocalizedString>
#include <KUiServerV2JobTracker>
#include <KIO/Global>
DownloadJob::DownloadJob(int id)
DownloadJob::DownloadJob()
: KJob()
, m_id(id)
{
// Tell KJobTracker to show the job right away so that we get a "finished"
// notification even for tiny downloads
setProperty("immediateProgressReporting", true);
// the thing with "canResume" in chrome downloads is that it just means
// "this download can be resumed right now because it is paused",
// it's not a general thing. I think we can always pause/resume downloads
......
......@@ -17,7 +17,7 @@ class DownloadJob : public KJob
Q_OBJECT
public:
DownloadJob(int id);
DownloadJob();
enum class State {
None,
......@@ -50,8 +50,6 @@ private:
QUrl originUrl() const;
int m_id = -1;
QUrl m_url;
QUrl m_finalUrl;
QUrl m_referrer;
......
......@@ -9,11 +9,11 @@
#include "connection.h"
#include <KIO/JobTracker>
#include <KJobTrackerInterface>
#include <KUiServerV2JobTracker>
DownloadPlugin::DownloadPlugin(QObject* parent) :
AbstractBrowserPlugin(QStringLiteral("downloads"), 3, parent)
AbstractBrowserPlugin(QStringLiteral("downloads"), 3, parent),
m_tracker(new KUiServerV2JobTracker(this))
{
}
......@@ -50,10 +50,10 @@ void DownloadPlugin::handleData(const QString& event, const QJsonObject& payload
return;
}
job = new DownloadJob(id);
job = new DownloadJob();
// first register and then update, otherwise we miss the initial population..
KIO::getJobTracker()->registerJob(job);
// first register and then update, otherwise it will miss the initial description() emission
m_tracker->registerJob(job);
job->update(download);
......
......@@ -12,6 +12,8 @@
#include <QHash>
#include "downloadjob.h"
class KUiServerV2JobTracker;
class DownloadPlugin : public AbstractBrowserPlugin
{
Q_OBJECT
......@@ -22,5 +24,6 @@ public:
using AbstractBrowserPlugin::handleData;
void handleData(const QString &event, const QJsonObject &data) override;
private:
KUiServerV2JobTracker *m_tracker;
QHash<int, DownloadJob *> m_jobs;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment