]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Simplify startup split view handling
authorEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Mon, 27 Apr 2015 10:55:53 +0000 (12:55 +0200)
committerEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Mon, 27 Apr 2015 10:55:53 +0000 (12:55 +0200)
* Instead of setting and resetting GeneralSettings's split view option, just pass it on to openFiles/openDirectories.
* Require at least one url in openFiles/openDirectories

REVIEW: 123395

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphintabwidget.cpp
src/dolphintabwidget.h
src/main.cpp

index da6c5319d6eb52c4a6830f2e02abc7ad84ca67a2..f7a76130786d58900002c11a85cf33dc09da6faa 100644 (file)
@@ -169,14 +169,14 @@ DolphinMainWindow::~DolphinMainWindow()
 {
 }
 
-void DolphinMainWindow::openDirectories(const QList<QUrl>& dirs)
+void DolphinMainWindow::openDirectories(const QList<QUrl>& dirs, bool splitView)
 {
-    m_tabWidget->openDirectories(dirs);
+    m_tabWidget->openDirectories(dirs, splitView);
 }
 
-void DolphinMainWindow::openFiles(const QList<QUrl>& files)
+void DolphinMainWindow::openFiles(const QList<QUrl>& files, bool splitView)
 {
-    m_tabWidget->openFiles(files);
+    m_tabWidget->openFiles(files, splitView);
 }
 
 void DolphinMainWindow::showCommand(CommandType command)
@@ -300,11 +300,6 @@ void DolphinMainWindow::openNewTab(const QUrl& url)
     m_tabWidget->openNewTab(url);
 }
 
-void DolphinMainWindow::openNewActivatedTab(const QUrl& url)
-{
-    m_tabWidget->openNewActivatedTab(url);
-}
-
 void DolphinMainWindow::openInNewTab()
 {
     const KFileItemList& list = m_activeViewContainer->view()->selectedItems();
index 5066657ef8865137c9483c5c5b8733c9bf63b7cf..7003e94744769450656d3bf3ab84152178059074 100644 (file)
@@ -71,17 +71,18 @@ public:
     DolphinViewContainer* activeViewContainer() const;
 
     /**
-     * Opens each directory in \p dirs in a separate tab. If the "split view"
-     * option is enabled, 2 directories are collected within one tab.
+     * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
+     * 2 directories are collected within one tab.
+     * \pre \a dirs must contain at least one url.
      */
-    void openDirectories(const QList<QUrl> &dirs);
+    void openDirectories(const QList<QUrl> &dirs, bool splitView);
 
     /**
-     * Opens the directory which contains the files \p files
-     * and selects all files (implements the --select option
-     * of Dolphin).
+     * Opens the directories which contain the files \p files and selects all files.
+     * If \a splitView is set, 2 directories are collected within one tab.
+     * \pre \a files must contain at least one url.
      */
-    void openFiles(const QList<QUrl>& files);
+    void openFiles(const QList<QUrl>& files, bool splitView);
 
     /**
      * Returns the 'Create New...' sub menu which also can be shared
@@ -119,11 +120,6 @@ public slots:
     /** Stores all settings and quits Dolphin. */
     void quit();
 
-    /**
-     * Opens a new tab showing the URL \a url and activates the tab.
-     */
-    void openNewActivatedTab(const QUrl& url);
-
 signals:
     /**
      * Is sent if the selection of the currently active view has
index 5b26359e6298f4b4209ddd60d0e1640943dd0586..ca626d47a3b9b83a91267017cea2e29a621312a7 100644 (file)
@@ -22,7 +22,6 @@
 #include "dolphintabbar.h"
 #include "dolphintabpage.h"
 #include "dolphinviewcontainer.h"
-#include "dolphin_generalsettings.h"
 
 #include <QApplication>
 #include <KConfigGroup>
@@ -154,16 +153,14 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU
     }
 }
 
-void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs)
+void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
 {
-    const bool hasSplitView = GeneralSettings::splitView();
+    Q_ASSERT(dirs.size() > 0);
 
-    // Open each directory inside a new tab. If the "split view" option has been enabled,
-    // always show two directories within one tab.
     QList<QUrl>::const_iterator it = dirs.constBegin();
     while (it != dirs.constEnd()) {
         const QUrl& primaryUrl = *(it++);
-        if (hasSplitView && (it != dirs.constEnd())) {
+        if (splitView && (it != dirs.constEnd())) {
             const QUrl& secondaryUrl = *(it++);
             openNewTab(primaryUrl, secondaryUrl);
         } else {
@@ -172,11 +169,9 @@ void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs)
     }
 }
 
-void DolphinTabWidget::openFiles(const QList<QUrl>& files)
+void DolphinTabWidget::openFiles(const QList<QUrl>& files, bool splitView)
 {
-    if (files.isEmpty()) {
-        return;
-    }
+    Q_ASSERT(files.size() > 0);
 
     // Get all distinct directories from 'files' and open a tab
     // for each directory. If the "split view" option is enabled, two
@@ -190,7 +185,7 @@ void DolphinTabWidget::openFiles(const QList<QUrl>& files)
     }
 
     const int oldTabCount = count();
-    openDirectories(dirs);
+    openDirectories(dirs, splitView);
     const int tabCount = count();
 
     // Select the files. Although the files can be split between several
index a84b7facb4233fbeaf2a15ef6091ecb9a01683e6..7b3a18814c59ad8adad380d069ea9595884225c8 100644 (file)
@@ -98,17 +98,18 @@ public slots:
     void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl());
 
     /**
-     * Opens each directory in \p dirs in a separate tab. If the "split view"
-     * option is enabled, 2 directories are collected within one tab.
+     * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
+     * 2 directories are collected within one tab.
+     * \pre \a dirs must contain at least one url.
      */
-    void openDirectories(const QList<QUrl>& dirs);
+    void openDirectories(const QList<QUrl>& dirs, bool splitView);
 
     /**
-     * Opens the directory which contains the files \p files
-     * and selects all files (implements the --select option
-     * of Dolphin).
+     * Opens the directories which contain the files \p files and selects all files.
+     * If \a splitView is set, 2 directories are collected within one tab.
+     * \pre \a files must contain at least one url.
      */
-    void openFiles(const QList<QUrl> &files);
+    void openFiles(const QList<QUrl> &files, bool splitView);
 
     /**
      * Closes the currently active tab.
index 105330059021c96172e85febcbe41985ba05608a..cbfc6b72fd6252c5bab939a0c2344b42a726e864 100644 (file)
@@ -113,36 +113,22 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
     const QStringList args = parser.positionalArguments();
     QList<QUrl> urls = Dolphin::validateUris(args);
 
-    bool resetSplitSettings = false;
-    if (parser.isSet("split") && !GeneralSettings::splitView()) {
-        // Dolphin should be opened with a split view although this is not
-        // set in the GeneralSettings. Temporary adjust the setting until
-        // all passed URLs have been opened.
-        GeneralSettings::setSplitView(true);
-        resetSplitSettings = true;
-
-        // We need 2 URLs to open Dolphin in split view mode
-        if (urls.isEmpty()) { // No URL given - Open home URL in all two views
-            urls.append(GeneralSettings::homeUrl());
-            urls.append(GeneralSettings::homeUrl());
-        } else if (urls.length() == 1) { // Only 1 URL given - Open given URL in all two views
-            urls.append(urls.at(0));
-        }
+    if (urls.isEmpty()) {
+        // We need at least one URL to open Dolphin
+        const QUrl homeUrl(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
+        urls.append(homeUrl);
     }
 
-    if (!urls.isEmpty()) {
-        if (parser.isSet("select")) {
-            m_mainWindow->openFiles(urls);
-        } else {
-            m_mainWindow->openDirectories(urls);
-        }
-    } else {
-        const QUrl homeUrl(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
-        m_mainWindow->openNewActivatedTab(homeUrl);
+    const bool splitView = parser.isSet("split") || GeneralSettings::splitView();
+    if (splitView && urls.size() < 2) {
+        // Split view does only make sense if we have at least 2 URLs
+        urls.append(urls.last());
     }
 
-    if (resetSplitSettings) {
-        GeneralSettings::setSplitView(false);
+    if (parser.isSet("select")) {
+        m_mainWindow->openFiles(urls, splitView);
+    } else {
+        m_mainWindow->openDirectories(urls, splitView);
     }
 
     m_mainWindow->show();