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

[Download Plugin] Register downloaded files as recent documents

Makes them more easily accessible throughout the shell.

Differential Revision: https://phabricator.kde.org/D26378
parent 182edeac
......@@ -72,6 +72,10 @@
"description": "Title for Downloads plugin",
"message": "Show downloads in notification area"
},
"options_plugin_downloads_addToRecentDocuments": {
"description": "Option for adding downloaded files to recent documents",
"message": "Add downloaded files to recent documents"
},
"options_plugin_downloads_saveOriginUrl": {
"description": "Option for saving download source URL in file metadata",
"message": "Save URL a file was downloaded from in the file's attributes"
......
......@@ -29,6 +29,7 @@ DEFAULT_EXTENSION_SETTINGS = {
},
downloads: {
enabled: true,
addToRecentDocuments: true,
saveOriginUrl: false
},
tabsrunner: {
......
......@@ -65,6 +65,12 @@
</label>
<p></p>
</li>
<li class="dependent" data-requires-extension="downloads" data-requires-extension-version-minimum="3">
<label>
<input type="checkbox" data-extension="downloads" data-settings-key="addToRecentDocuments" data-depends-extension="downloads" data-depends-settings-key="enabled" data-depends-settings-value="TRUE"> <span data-i18n="options_plugin_downloads_addToRecentDocuments">I18N</span>
</label>
<p></p>
</li>
<li class="dependent" data-requires-extension="downloads" data-requires-extension-version-minimum="2">
<label>
<input type="checkbox" data-extension="downloads" data-settings-key="saveOriginUrl" data-depends-extension="downloads" data-depends-settings-key="enabled" data-depends-settings-value="TRUE"> <span data-i18n="options_plugin_downloads_saveOriginUrl">I18N</span>
......
......@@ -27,6 +27,7 @@ target_link_libraries(
Qt5::DBus
Qt5::Gui
Qt5::Widgets
KF5::Activities
KF5::Crash
KF5::I18n
KF5::KIOCore
......
......@@ -25,8 +25,10 @@
#include "settings.h"
#include <QDateTime>
#include <QGuiApplication>
#include <QJsonObject>
#include <KActivities/ResourceInstance>
#include <KFileMetaData/UserMetaData>
#include <KLocalizedString>
......@@ -237,6 +239,9 @@ void DownloadJob::update(const QJsonObject &payload)
setError(KJob::NoError);
setProcessedAmount(KJob::Files, 1);
// Add to recent document
addToRecentDocuments();
// Write origin url into extended file attributes
saveOriginUrl();
......@@ -254,6 +259,22 @@ void DownloadJob::updateDescription()
);
}
void DownloadJob::addToRecentDocuments()
{
if (m_incognito || m_fileName.isEmpty()) {
return;
}
const QJsonObject settings = Settings::self().settingsForPlugin(QStringLiteral("downloads"));
const bool enabled = settings.value(QStringLiteral("addToRecentDocuments")).toBool();
if (!enabled) {
return;
}
KActivities::ResourceInstance::notifyAccessed(QUrl::fromLocalFile(m_fileName), qApp->desktopFileName());
}
void DownloadJob::saveOriginUrl()
{
if (m_incognito
......
......@@ -60,6 +60,7 @@ protected:
private:
void updateDescription();
void addToRecentDocuments();
void saveOriginUrl();
int m_id = -1;
......
......@@ -30,7 +30,7 @@
#include <KJobTrackerInterface>
DownloadPlugin::DownloadPlugin(QObject* parent) :
AbstractBrowserPlugin(QStringLiteral("downloads"), 2, parent)
AbstractBrowserPlugin(QStringLiteral("downloads"), 3, parent)
{
}
......
Markdown is supported
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