[utilities/ark] /: Add "Extract here and delete archive" menu action
Severin von Wnuck
null at kde.org
Tue Nov 28 16:57:28 GMT 2023
Git commit 1878e8de27a31922d55dae93ceec2bbbac51fed8 by Severin von Wnuck.
Committed on 27/11/2023 at 20:51.
Pushed by ngraham into branch 'master'.
Add "Extract here and delete archive" menu action
Introduce a new menu option to delete archives after extraction.
Change default "extract here" behavior to autodetect subfolders.
M +16 -12 app/extractfileitemaction.cpp
M +1 -1 app/extractfileitemaction.h
M +4 -3 doc/index.docbook
https://invent.kde.org/utilities/ark/-/commit/1878e8de27a31922d55dae93ceec2bbbac51fed8
diff --git a/app/extractfileitemaction.cpp b/app/extractfileitemaction.cpp
index e6f5b3350..173029e3b 100644
--- a/app/extractfileitemaction.cpp
+++ b/app/extractfileitemaction.cpp
@@ -10,6 +10,8 @@
#include <QFileInfo>
#include <QMenu>
+#include <KIO/CopyJob>
+#include <KIO/JobUiDelegate>
#include <KIO/OpenFileManagerWindowJob>
#include <KLocalizedString>
#include <KPluginFactory>
@@ -60,7 +62,7 @@ QList<QAction*> ExtractFileItemAction::actions(const KFileItemListProperties& fi
}
QAction *extractToAction = createAction(icon,
- i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract archive to..."),
+ i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract to…"),
parentWidget,
supportedUrls,
AdditionalJobOptions::ShowDialog);
@@ -72,19 +74,18 @@ QList<QAction*> ExtractFileItemAction::actions(const KFileItemListProperties& fi
QMenu *extractMenu = new QMenu(parentWidget);
extractMenu->addAction(createAction(icon,
- i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract archive here"),
+ i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract here"),
parentWidget,
supportedUrls,
AdditionalJobOptions::None));
- extractMenu->addAction(extractToAction);
-
- extractMenu->addAction(createAction(icon,
- i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract archive here, autodetect subfolder"),
+ extractMenu->addAction(createAction(QIcon::fromTheme(QStringLiteral("archive-remove")),
+ i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract here and delete archive"),
parentWidget,
supportedUrls,
- AdditionalJobOptions::AutoSubfolder));
+ AdditionalJobOptions::AutoDelete));
+ extractMenu->addAction(extractToAction);
QAction *extractMenuAction = new QAction(i18nc("@action:inmenu Extract submenu in Dolphin context menu", "Extract"), parentWidget);
extractMenuAction->setMenu(extractMenu);
@@ -104,21 +105,24 @@ QAction *ExtractFileItemAction::createAction(const QIcon& icon, const QString& n
auto *batchExtractJob = new BatchExtract(nullptr);
batchExtractJob->setDestinationFolder(QFileInfo(urls.first().toLocalFile()).path());
batchExtractJob->setOpenDestinationAfterExtraction(ArkSettings::openDestinationFolderAfterExtraction());
- if (option == AutoSubfolder) {
- batchExtractJob->setAutoSubfolder(true);
- } else if (option == ShowDialog) {
+ if (option == ShowDialog) {
if (!batchExtractJob->showExtractDialog()) {
delete batchExtractJob;
return;
}
+ } else {
+ batchExtractJob->setAutoSubfolder(true);
}
for (const QUrl &url : urls) {
batchExtractJob->addInput(url);
}
batchExtractJob->start();
- connect(batchExtractJob, &KJob::finished, this, [this, batchExtractJob](){
- if (!batchExtractJob->errorString().isEmpty()) {
+ connect(batchExtractJob, &KJob::finished, this, [this, batchExtractJob, option, urls]() {
+ if (batchExtractJob->error()) {
Q_EMIT error(batchExtractJob->errorString());
+ } else if (option == AutoDelete) {
+ KIO::Job *job = KIO::trash(urls);
+ job->uiDelegate()->setAutoErrorHandlingEnabled(true);
}
batchExtractJob->deleteLater();
});
diff --git a/app/extractfileitemaction.h b/app/extractfileitemaction.h
index 1e6880ed3..1b6dc23bc 100644
--- a/app/extractfileitemaction.h
+++ b/app/extractfileitemaction.h
@@ -34,7 +34,7 @@ private:
enum AdditionalJobOptions {
None,
ShowDialog,
- AutoSubfolder,
+ AutoDelete,
};
QAction *createAction(const QIcon& icon, const QString& name, QWidget *parent, const QList<QUrl>& urls, AdditionalJobOptions option);
diff --git a/doc/index.docbook b/doc/index.docbook
index 32d6bfca4..a63c249fd 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -392,14 +392,15 @@ The menu has these additional items to extract an archive using &ark;:
<itemizedlist>
<listitem>
-<para><guimenuitem>Extract archive here, autodetect subfolder</guimenuitem> creates a
+<para><guimenuitem>Extract here</guimenuitem> creates a
subfolder in the folder with the archive and extracts the folders and files into it.</para>
</listitem>
<listitem>
-<para><guimenuitem>Extract archive to...</guimenuitem> opens the Extract dialog where you can choose the destination folder and various extraction options.</para>
+<para><guimenuitem>Extract here and delete archive</guimenuitem> creates a
+subfolder in the folder with the archive, extracts the folders and files into it and deletes the archive.</para>
</listitem>
<listitem>
-<para><guimenuitem>Extract archive here</guimenuitem> extracts the content of the archive into the same folder.</para>
+<para><guimenuitem>Extract to…</guimenuitem> opens the Extract dialog where you can choose the destination folder and various extraction options.</para>
</listitem>
</itemizedlist>
More information about the kde-doc-english
mailing list