]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Bug 196035 - middle clicking on archive files in dolphin does not open them in a...
authorEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Tue, 28 May 2013 15:31:14 +0000 (17:31 +0200)
committerEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Tue, 4 Jun 2013 13:27:45 +0000 (15:27 +0200)
When 'browse through archives' is enabled, open archive files
like folders on middle clicking, context menu -> new tab action
and context menu -> new window action.

BUG: 196035
REVIEW: 110487

src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinviewcontainer.cpp
src/views/dolphinview.cpp
src/views/dolphinview.h

index 4371bcdfd4d41436d289ac239c08a41a7ca873fd..f66847334621f0d0deab3776ccb0c779ca3cabb9 100644 (file)
@@ -235,12 +235,19 @@ void DolphinContextMenu::openItemContextMenu()
                                                    this);
             addAction(openParentInNewTabAction);
 
+            addSeparator();
+        } else if (!DolphinView::openItemAsFolderUrl(m_fileInfo).isEmpty()) {
+            // insert 'Open in new window' and 'Open in new tab' entries
+            addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
+            addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
+
             addSeparator();
         }
     } else {
         bool selectionHasOnlyDirs = true;
         foreach (const KFileItem& item, m_selectedItems) {
-            if (!item.isDir()) {
+            const KUrl& url = DolphinView::openItemAsFolderUrl(item);
+            if (url.isEmpty()) {
                 selectionHasOnlyDirs = false;
                 break;
             }
index 3b169a57dab9a531f581b19b4fa8d96b5e411c54..73001bf54e957c967b8203fc06af7556005f8d12 100644 (file)
@@ -525,8 +525,9 @@ void DolphinMainWindow::openInNewTab()
         openNewTab(m_activeViewContainer->url());
     } else {
         foreach (const KFileItem& item, list) {
-            if (item.isDir()) {
-                openNewTab(item.url());
+            const KUrl& url = DolphinView::openItemAsFolderUrl(item);
+            if (!url.isEmpty()) {
+                openNewTab(url);
             }
         }
     }
@@ -539,8 +540,9 @@ void DolphinMainWindow::openInNewWindow()
     const KFileItemList list = m_activeViewContainer->view()->selectedItems();
     if (list.isEmpty()) {
         newWindowUrl = m_activeViewContainer->url();
-    } else if ((list.count() == 1) && list[0].isDir()) {
-        newWindowUrl = list[0].url();
+    } else if (list.count() == 1) {
+        const KFileItem& item = list.first();
+        newWindowUrl = DolphinView::openItemAsFolderUrl(item);
     }
 
     if (!newWindowUrl.isEmpty()) {
index 44d4ee36fcd4faf58e69e4743abedfdbb76202da..71dc5fd7b50808731992cf1f0d7a3679497ea863 100644 (file)
@@ -482,37 +482,12 @@ void DolphinViewContainer::slotItemActivated(const KFileItem& item)
     // results in an active view.
     m_view->setActive(true);
 
-    KUrl url = item.targetUrl();
-
-    if (item.isDir()) {
+    const KUrl& url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
+    if (!url.isEmpty()) {
         m_view->setUrl(url);
         return;
     }
 
-    if (GeneralSettings::browseThroughArchives() && item.isFile() && url.isLocalFile()) {
-        // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
-        // zip:/<path>/ when clicking on a zip file, etc.
-        // The .protocol file specifies the mimetype that the kioslave handles.
-        // Note that we don't use mimetype inheritance since we don't want to
-        // open OpenDocument files as zip folders...
-        const QString protocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype());
-        if (!protocol.isEmpty()) {
-            url.setProtocol(protocol);
-            m_view->setUrl(url);
-            return;
-        }
-    }
-
-    if (item.mimetype() == QLatin1String("application/x-desktop")) {
-        // Redirect to the URL in Type=Link desktop files
-        KDesktopFile desktopFile(url.toLocalFile());
-        if (desktopFile.hasLinkType()) {
-            url = desktopFile.readUrl();
-            m_view->setUrl(url);
-            return;
-        }
-    }
-
     item.run();
 }
 
index abf572fec8f873e8262010d39d72f42e23590d69..6fadaa85c58f7777d19f64f2beebfcb77826875e 100644 (file)
@@ -33,6 +33,8 @@
 #include <QTimer>
 #include <QScrollBar>
 
+#include <KDesktopFile>
+#include <KProtocolManager>
 #include <KActionCollection>
 #include <KColorScheme>
 #include <KDirModel>
@@ -810,9 +812,10 @@ void DolphinView::slotItemsActivated(const QSet<int>& indexes)
     while (it.hasNext()) {
         const int index = it.next();
         KFileItem item = m_model->fileItem(index);
+        const KUrl& url = openItemAsFolderUrl(item);
 
-        if (item.isDir()) { // Open folders in new tabs
-            emit tabRequested(item.url());
+        if (!url.isEmpty()) { // Open folders in new tabs
+            emit tabRequested(url);
         } else {
             items.append(item);
         }
@@ -827,8 +830,11 @@ void DolphinView::slotItemsActivated(const QSet<int>& indexes)
 
 void DolphinView::slotItemMiddleClicked(int index)
 {
-    const KFileItem item = m_model->fileItem(index);
-    if (item.isDir() || isTabsForFilesEnabled()) {
+    const KFileItem& item = m_model->fileItem(index);
+    const KUrl& url = openItemAsFolderUrl(item);
+    if (!url.isEmpty()) {
+        emit tabRequested(url);
+    } else if (isTabsForFilesEnabled()) {
         emit tabRequested(item.url());
     }
 }
@@ -1202,6 +1208,46 @@ QString DolphinView::viewPropertiesContext() const
     return m_viewPropertiesContext;
 }
 
+KUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseThroughArchives)
+{
+    if (item.isNull()) {
+        return KUrl();
+    }
+
+    KUrl url = item.targetUrl();
+
+    if (item.isDir()) {
+        return url;
+    }
+
+    if (item.isMimeTypeKnown()) {
+        const QString& mimetype = item.mimetype();
+
+        if (browseThroughArchives && item.isFile() && url.isLocalFile()) {
+            // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
+            // zip:/<path>/ when clicking on a zip file, etc.
+            // The .protocol file specifies the mimetype that the kioslave handles.
+            // Note that we don't use mimetype inheritance since we don't want to
+            // open OpenDocument files as zip folders...
+            const QString& protocol = KProtocolManager::protocolForArchiveMimetype(mimetype);
+            if (!protocol.isEmpty()) {
+                url.setProtocol(protocol);
+                return url;
+            }
+        }
+
+        if (mimetype == QLatin1String("application/x-desktop")) {
+            // Redirect to the URL in Type=Link desktop files
+            KDesktopFile desktopFile(url.toLocalFile());
+            if (desktopFile.hasLinkType()) {
+                return desktopFile.readUrl();
+            }
+        }
+    }
+
+    return KUrl();
+}
+
 void DolphinView::observeCreatedItem(const KUrl& url)
 {
     if (m_active) {
index e50dffcd8146c1ccae10314e41ed5916916260fa..5a70c550224196fa772e32cea591153f83e5d666 100644 (file)
@@ -304,6 +304,14 @@ public:
     void setViewPropertiesContext(const QString& context);
     QString viewPropertiesContext() const;
 
+    /**
+     * Checks if the given \a item can be opened as folder (e.g. archives).
+     * This function will also adjust the \a url (e.g. change the protocol).
+     * @return a valid and adjusted url if the item can be opened as folder,
+     * otherwise return an empty url.
+     */
+    static KUrl openItemAsFolderUrl(const KFileItem& item, const bool browseThroughArchives = true);
+
 public slots:
     /**
      * Changes the directory to \a url. If the current directory is equal to