Changeset View
Changeset View
Standalone View
Standalone View
app/compressfileitemaction.cpp
Show All 22 Lines | |||||
23 | 23 | | |||
24 | #include <QMenu> | 24 | #include <QMenu> | ||
25 | #include <QMimeDatabase> | 25 | #include <QMimeDatabase> | ||
26 | 26 | | |||
27 | #include <KPluginFactory> | 27 | #include <KPluginFactory> | ||
28 | #include <KLocalizedString> | 28 | #include <KLocalizedString> | ||
29 | #include <KRun> | 29 | #include <KRun> | ||
30 | 30 | | |||
31 | #include <algorithm> | ||||
32 | | ||||
31 | #include "pluginmanager.h" | 33 | #include "pluginmanager.h" | ||
32 | 34 | | |||
33 | K_PLUGIN_FACTORY_WITH_JSON(CompressFileItemActionFactory, "compressfileitemaction.json", registerPlugin<CompressFileItemAction>();) | 35 | K_PLUGIN_FACTORY_WITH_JSON(CompressFileItemActionFactory, "compressfileitemaction.json", registerPlugin<CompressFileItemAction>();) | ||
34 | 36 | | |||
35 | using namespace Kerfuffle; | 37 | using namespace Kerfuffle; | ||
36 | 38 | | |||
37 | CompressFileItemAction::CompressFileItemAction(QObject* parent, const QVariantList&) | 39 | CompressFileItemAction::CompressFileItemAction(QObject* parent, const QVariantList&) | ||
38 | : KAbstractFileItemActionPlugin(parent) | 40 | : KAbstractFileItemActionPlugin(parent) | ||
39 | , m_pluginManager(new PluginManager(this)) | 41 | , m_pluginManager(new PluginManager(this)) | ||
40 | {} | 42 | {} | ||
41 | 43 | | |||
42 | QList<QAction*> CompressFileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) | 44 | QList<QAction*> CompressFileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) | ||
43 | { | 45 | { | ||
44 | // #268163: don't offer compression on already compressed archives. | 46 | // #268163: don't offer compression on already compressed archives. | ||
45 | if (m_pluginManager->supportedMimeTypes().contains(fileItemInfos.mimeType())) { | 47 | if (m_pluginManager->supportedMimeTypes().contains(fileItemInfos.mimeType())) { | ||
46 | return {}; | 48 | return {}; | ||
47 | } | 49 | } | ||
48 | 50 | | |||
51 | // KFileItemListProperties::isLocal() doesn't check target URL (e.g. files on the desktop) | ||||
52 | const auto urlList = fileItemInfos.urlList(); | ||||
53 | const bool hasLocalUrl = std::any_of(urlList.begin(), urlList.end(), [](const QUrl &url) { | ||||
elvisangelaccio: `constBegin()` / `constEnd()` | |||||
54 | return url.isLocalFile(); | ||||
55 | }); | ||||
56 | | ||||
57 | if (!hasLocalUrl) { | ||||
58 | return {}; | ||||
59 | } | ||||
60 | | ||||
49 | QList<QAction*> actions; | 61 | QList<QAction*> actions; | ||
50 | const QIcon icon = QIcon::fromTheme(QStringLiteral("ark")); | 62 | const QIcon icon = QIcon::fromTheme(QStringLiteral("ark")); | ||
51 | 63 | | |||
52 | QMenu *compressMenu = new QMenu(parentWidget); | 64 | QMenu *compressMenu = new QMenu(parentWidget); | ||
53 | 65 | | |||
54 | compressMenu->addAction(createAction(icon, | 66 | compressMenu->addAction(createAction(icon, | ||
55 | i18nc("@action:inmenu Part of Compress submenu in Dolphin context menu", "Here (as TAR.GZ)"), | 67 | i18nc("@action:inmenu Part of Compress submenu in Dolphin context menu", "Here (as TAR.GZ)"), | ||
56 | parentWidget, | 68 | parentWidget, | ||
57 | fileItemInfos.urlList(), | 69 | urlList, | ||
58 | QStringLiteral("ark --changetofirstpath --add --autofilename tar.gz %F"))); | 70 | QStringLiteral("ark --changetofirstpath --add --autofilename tar.gz %F"))); | ||
59 | 71 | | |||
60 | const QMimeType zipMime = QMimeDatabase().mimeTypeForName(QStringLiteral("application/zip")); | 72 | const QMimeType zipMime = QMimeDatabase().mimeTypeForName(QStringLiteral("application/zip")); | ||
61 | // Don't offer zip compression if no zip plugin is available. | 73 | // Don't offer zip compression if no zip plugin is available. | ||
62 | if (!m_pluginManager->preferredWritePluginsFor(zipMime).isEmpty()) { | 74 | if (!m_pluginManager->preferredWritePluginsFor(zipMime).isEmpty()) { | ||
63 | compressMenu->addAction(createAction(icon, | 75 | compressMenu->addAction(createAction(icon, | ||
64 | i18nc("@action:inmenu Part of Compress submenu in Dolphin context menu", "Here (as ZIP)"), | 76 | i18nc("@action:inmenu Part of Compress submenu in Dolphin context menu", "Here (as ZIP)"), | ||
65 | parentWidget, | 77 | parentWidget, | ||
66 | fileItemInfos.urlList(), | 78 | urlList, | ||
67 | QStringLiteral("ark --changetofirstpath --add --autofilename zip %F"))); | 79 | QStringLiteral("ark --changetofirstpath --add --autofilename zip %F"))); | ||
68 | } | 80 | } | ||
69 | 81 | | |||
70 | compressMenu->addAction(createAction(icon, | 82 | compressMenu->addAction(createAction(icon, | ||
71 | i18nc("@action:inmenu Part of Compress submenu in Dolphin context menu", "Compress to..."), | 83 | i18nc("@action:inmenu Part of Compress submenu in Dolphin context menu", "Compress to..."), | ||
72 | parentWidget, | 84 | parentWidget, | ||
73 | fileItemInfos.urlList(), | 85 | urlList, | ||
74 | QStringLiteral("ark --add --changetofirstpath --dialog %F"))); | 86 | QStringLiteral("ark --add --changetofirstpath --dialog %F"))); | ||
75 | 87 | | |||
76 | QAction *compressMenuAction = new QAction(i18nc("@action:inmenu Compress submenu in Dolphin context menu", "Compress"), parentWidget); | 88 | QAction *compressMenuAction = new QAction(i18nc("@action:inmenu Compress submenu in Dolphin context menu", "Compress"), parentWidget); | ||
77 | compressMenuAction->setMenu(compressMenu); | 89 | compressMenuAction->setMenu(compressMenu); | ||
78 | compressMenuAction->setEnabled(fileItemInfos.supportsWriting() && !m_pluginManager->availableWritePlugins().isEmpty()); | 90 | compressMenuAction->setEnabled(fileItemInfos.supportsWriting() && !m_pluginManager->availableWritePlugins().isEmpty()); | ||
79 | 91 | | |||
80 | actions << compressMenuAction; | 92 | actions << compressMenuAction; | ||
81 | return actions; | 93 | return actions; | ||
Show All 14 Lines |
constBegin() / constEnd()