[kde-doc-english] [ark] /: Introduce new Extract actions

Elvis Angelaccio elvis.angelaccio at kdemail.net
Wed Feb 24 18:39:41 UTC 2016


Git commit 2cd1d594b7b26b6fa4fc236acadf92f02c8bfd03 by Elvis Angelaccio.
Committed on 24/02/2016 at 18:33.
Pushed by elvisangelaccio into branch 'master'.

Introduce new Extract actions

Now that we have introduced the new Archive and File menus, it makes sense to introduce
different Extract actions as well, one for each menu:

1. The Extract action in the Archive menu, which always extracts the whole
   archive (even if the user selected some file).
2. The Extract action in the File menu, which is only enabled if some file
   has been selected, and extracts only those files.

The Extract action in the toolbar is the very same Extract
action that Ark currently provides: it allows to extract the whole
archive, or only the selected files (if any).

Differential Revision: D795

GUI:

M  +3    -1    app/arkui.rc
M  +5    -4    part/ark_part.rc
M  +66   -15   part/part.cpp
M  +5    -1    part/part.h

http://commits.kde.org/ark/2cd1d594b7b26b6fa4fc236acadf92f02c8bfd03

diff --git a/app/arkui.rc b/app/arkui.rc
index 4949c36..94b7a88 100644
--- a/app/arkui.rc
+++ b/app/arkui.rc
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="ark" version="14">
+<kpartgui name="ark" version="15">
 <MenuBar>
 	<Menu name="archive">
 		<text>&Archive</text>
@@ -9,6 +9,8 @@
 		<Separator/>
 		<DefineGroup name="file_save" append="save_merge"/>
 		<Separator/>
+		<DefineGroup name="archive_extract" append="save_merge"/>
+		<Separator/>
 		<DefineGroup name="archive_edit" append="save_merge"/>
 		<Separator/>
 		<Action name="ark_quit"/>
diff --git a/part/ark_part.rc b/part/ark_part.rc
index af29944..cb20024 100644
--- a/part/ark_part.rc
+++ b/part/ark_part.rc
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="ark_part" version="5">
+<kpartgui name="ark_part" version="6">
 <MenuBar>
 	<Menu name="archive">
 		<text>&Archive</text>
@@ -7,6 +7,7 @@
 		<Action name="add" group="archive_edit"/>
 		<Action name="add-dir" group="archive_edit"/>
 		<Action name="delete" group="archive_edit"/>
+		<Action name="extract" group="archive_extract"/>
 	</Menu>
 	<Menu name="ark_file">
 		<text>&File</text>
@@ -14,7 +15,7 @@
 		<Action name="openfile"/>
 		<Action name="openfilewith"/>
 		<Separator/>
-		<Action name="extract"/>
+		<Action name="extract_files"/>
 	</Menu>
 	<Menu name="settings">
 		<text>&Settings</text>
@@ -25,7 +26,7 @@
 	<Action name="add"/>
 	<Action name="add-dir"/>
 	<Action name="delete"/>
-	<Action name="extract"/>
+	<Action name="toolbar_extract"/>
 	<Action name="preview"/>
 </ToolBar>
 <Menu name="context_menu">
@@ -34,6 +35,6 @@
 	<Action name="openfilewith"/>
 	<Separator/>
 	<Action name="delete"/>
-	<Action name="extract"/>
+	<Action name="extract_files"/>
 </Menu>
 </kpartgui>
diff --git a/part/part.cpp b/part/part.cpp
index 2331289..a387e4d 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -174,7 +174,9 @@ Part::~Part()
     ArkSettings::setShowInfoPanel(m_showInfoPanelAction->isChecked());
     ArkSettings::self()->save();
 
+    m_extractArchiveAction->menu()->deleteLater();
     m_extractFilesAction->menu()->deleteLater();
+    m_toolbarExtractAction->menu()->deleteLater();
 }
 
 KAboutData *Part::createAboutData()
@@ -310,13 +312,27 @@ void Part::setupActions()
     connect(m_previewAction, SIGNAL(triggered(bool)), m_signalMapper, SLOT(map()));
     m_signalMapper->setMapping(m_previewAction, Preview);
 
-    m_extractFilesAction = actionCollection()->addAction(QStringLiteral("extract"));
-    m_extractFilesAction->setText(i18n("E&xtract"));
+    m_extractArchiveAction = actionCollection()->addAction(QStringLiteral("extract"));
+    m_extractArchiveAction->setText(i18nc("@action:inmenu", "E&xtract"));
+    m_extractArchiveAction->setIcon(QIcon::fromTheme(QStringLiteral("archive-extract")));
+    m_extractArchiveAction->setToolTip(i18n("Click to open an extraction dialog, where you can choose how to extract all the files in the archive"));
+    connect(m_extractArchiveAction, &QAction::triggered,
+            this, &Part::slotExtractArchive);
+
+    m_extractFilesAction = actionCollection()->addAction(QStringLiteral("extract_files"));
+    m_extractFilesAction->setText(i18nc("@action:inmenu", "E&xtract"));
     m_extractFilesAction->setIcon(QIcon::fromTheme(QStringLiteral("archive-extract")));
-    m_extractFilesAction->setStatusTip(i18n("Click to open an extraction dialog, where you can choose to extract either all files or just the selected ones"));
-    actionCollection()->setDefaultShortcut(m_extractFilesAction, Qt::CTRL + Qt::Key_E);
+    m_extractFilesAction->setToolTip(i18n("Click to open an extraction dialog, where you can choose how to extract the selected files"));
     connect(m_extractFilesAction, &QAction::triggered,
-            this, &Part::slotExtractFiles);
+            this, &Part::slotShowExtractionDialog);
+
+    m_toolbarExtractAction = actionCollection()->addAction(QStringLiteral("toolbar_extract"));
+    m_toolbarExtractAction->setText(i18nc("@action:intoolbar", "E&xtract"));
+    m_toolbarExtractAction->setIcon(QIcon::fromTheme(QStringLiteral("archive-extract")));
+    m_toolbarExtractAction->setToolTip(i18n("Click to open an extraction dialog, where you can choose to extract either all files or just the selected ones"));
+    actionCollection()->setDefaultShortcut(m_toolbarExtractAction, Qt::CTRL + Qt::Key_E);
+    connect(m_toolbarExtractAction, &QAction::triggered,
+            this, &Part::slotShowExtractionDialog);
 
     m_addFilesAction = actionCollection()->addAction(QStringLiteral("add"));
     m_addFilesAction->setIcon(QIcon::fromTheme(QStringLiteral("archive-insert")));
@@ -361,8 +377,13 @@ void Part::updateActions()
                                 isPreviewable &&
                                 !isDirectory &&
                                 (selectedEntriesCount == 1));
+    m_extractArchiveAction->setEnabled(!isBusy() &&
+                                       (m_model->rowCount() > 0));
     m_extractFilesAction->setEnabled(!isBusy() &&
-                                     (m_model->rowCount() > 0));
+                                     (m_model->rowCount() > 0) &&
+                                     (selectedEntriesCount > 0));
+    m_toolbarExtractAction->setEnabled(!isBusy() &&
+                                       (m_model->rowCount() > 0));
     m_saveAsAction->setEnabled(!isBusy() &&
                                m_model->rowCount() > 0);
     m_addFilesAction->setEnabled(!isBusy() &&
@@ -381,20 +402,41 @@ void Part::updateActions()
                                      !isDirectory &&
                                      (selectedEntriesCount == 1));
 
-    QMenu *menu = m_extractFilesAction->menu();
+    // TODO: why do we even update these menus here?
+    // It should be enough to update them when a new dir is appended to the history.
+    updateQuickExtractMenu(m_extractArchiveAction);
+    updateQuickExtractMenu(m_extractFilesAction);
+    updateQuickExtractMenu(m_toolbarExtractAction);
+}
+
+void Part::updateQuickExtractMenu(QAction *extractAction)
+{
+    if (!extractAction) {
+        return;
+    }
+
+    QMenu *menu = extractAction->menu();
+
     if (!menu) {
-        menu = new QMenu;
-        m_extractFilesAction->setMenu(menu);
+        menu = new QMenu();
+        extractAction->setMenu(menu);
         connect(menu, &QMenu::triggered,
                 this, &Part::slotQuickExtractFiles);
 
         // Remember to keep this action's properties as similar to
-        // m_extractFilesAction's as possible (except where it does not make
+        // extractAction's as possible (except where it does not make
         // sense, such as the text or the shortcut).
         QAction *extractTo = menu->addAction(i18n("Extract To..."));
-        extractTo->setIcon(m_extractFilesAction->icon());
-        extractTo->setStatusTip(m_extractFilesAction->statusTip());
-        connect(extractTo, &QAction::triggered, this, &Part::slotExtractFiles);
+        extractTo->setIcon(extractAction->icon());
+        extractTo->setToolTip(extractAction->toolTip());
+
+        if (extractAction == m_extractArchiveAction) {
+            connect(extractTo, &QAction::triggered,
+                    this, &Part::slotExtractArchive);
+        } else {
+            connect(extractTo, &QAction::triggered,
+                    this, &Part::slotShowExtractionDialog);
+        }
 
         menu->addSeparator();
 
@@ -526,7 +568,7 @@ bool Part::openFile()
     m_infoPanel->setIndex(QModelIndex());
 
     if (arguments().metaData()[QStringLiteral("showExtractDialog")] == QLatin1String("true")) {
-        QTimer::singleShot(0, this, &Part::slotExtractFiles);
+        QTimer::singleShot(0, this, &Part::slotShowExtractionDialog);
     }
 
     const QString password = arguments().metaData()[QStringLiteral("encryptionPassword")];
@@ -818,7 +860,16 @@ QString Part::detectSubfolder() const
     return m_model->archive()->subfolderName();
 }
 
-void Part::slotExtractFiles()
+void Part::slotExtractArchive()
+{
+    if (m_view->selectionModel()->selectedRows().count() > 0) {
+        m_view->selectionModel()->clear();
+    }
+
+    slotShowExtractionDialog();
+}
+
+void Part::slotShowExtractionDialog()
 {
     if (!m_model) {
         return;
diff --git a/part/part.h b/part/part.h
index 1253038..0e0882a 100644
--- a/part/part.h
+++ b/part/part.h
@@ -85,7 +85,8 @@ private slots:
     void slotOpenExtractedEntry(KJob*);
     void slotOpenEntry(int mode);
     void slotError(const QString& errorMessage, const QString& details);
-    void slotExtractFiles();
+    void slotExtractArchive();
+    void slotShowExtractionDialog();
     void slotExtractionDone(KJob*);
     void slotQuickExtractFiles(QAction*);
     void slotAddFiles();
@@ -99,6 +100,7 @@ private slots:
     void slotToggleInfoPanel(bool);
     void slotSaveAs();
     void updateActions();
+    void updateQuickExtractMenu(QAction *extractAction);
     void selectionChanged();
     void adjustColumns();
     void setBusyGui();
@@ -127,7 +129,9 @@ private:
     QAction *m_previewAction;
     QAction *m_openFileAction;
     QAction *m_openFileWithAction;
+    QAction *m_extractArchiveAction;
     QAction *m_extractFilesAction;
+    QAction *m_toolbarExtractAction;
     QAction *m_addFilesAction;
     QAction *m_addDirAction;
     QAction *m_deleteFilesAction;


More information about the kde-doc-english mailing list