From 5acfb27760f3da1d4f794e820008f8a4c8ff7533 Mon Sep 17 00:00:00 2001 From: Emmanuel Pescosta Date: Mon, 27 Apr 2015 12:55:53 +0200 Subject: [PATCH] Simplify startup split view handling * 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 | 13 ++++--------- src/dolphinmainwindow.h | 20 ++++++++------------ src/dolphintabwidget.cpp | 17 ++++++----------- src/dolphintabwidget.h | 15 ++++++++------- src/main.cpp | 38 ++++++++++++-------------------------- 5 files changed, 38 insertions(+), 65 deletions(-) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index da6c5319d..f7a761307 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -169,14 +169,14 @@ DolphinMainWindow::~DolphinMainWindow() { } -void DolphinMainWindow::openDirectories(const QList& dirs) +void DolphinMainWindow::openDirectories(const QList& dirs, bool splitView) { - m_tabWidget->openDirectories(dirs); + m_tabWidget->openDirectories(dirs, splitView); } -void DolphinMainWindow::openFiles(const QList& files) +void DolphinMainWindow::openFiles(const QList& 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(); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 5066657ef..7003e9474 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -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 &dirs); + void openDirectories(const QList &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& files); + void openFiles(const QList& 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 diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index 5b26359e6..ca626d47a 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -22,7 +22,6 @@ #include "dolphintabbar.h" #include "dolphintabpage.h" #include "dolphinviewcontainer.h" -#include "dolphin_generalsettings.h" #include #include @@ -154,16 +153,14 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU } } -void DolphinTabWidget::openDirectories(const QList& dirs) +void DolphinTabWidget::openDirectories(const QList& 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::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& dirs) } } -void DolphinTabWidget::openFiles(const QList& files) +void DolphinTabWidget::openFiles(const QList& 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& 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 diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h index a84b7facb..7b3a18814 100644 --- a/src/dolphintabwidget.h +++ b/src/dolphintabwidget.h @@ -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& dirs); + void openDirectories(const QList& 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 &files); + void openFiles(const QList &files, bool splitView); /** * Closes the currently active tab. diff --git a/src/main.cpp b/src/main.cpp index 105330059..cbfc6b72f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -113,36 +113,22 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv) const QStringList args = parser.positionalArguments(); QList 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(); -- 2.47.3