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
This commit is contained in:
Emmanuel Pescosta 2015-04-27 12:55:53 +02:00
parent 06776451a7
commit 5acfb27760
5 changed files with 39 additions and 66 deletions

View 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();

View 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

View 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

View 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.

View 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()) {
if (parser.isSet("select")) {
m_mainWindow->openFiles(urls);
} else {
m_mainWindow->openDirectories(urls);
}
} else {
if (urls.isEmpty()) {
// We need at least one URL to open Dolphin
const QUrl homeUrl(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
m_mainWindow->openNewActivatedTab(homeUrl);
urls.append(homeUrl);
}
if (resetSplitSettings) {
GeneralSettings::setSplitView(false);
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 (parser.isSet("select")) {
m_mainWindow->openFiles(urls, splitView);
} else {
m_mainWindow->openDirectories(urls, splitView);
}
m_mainWindow->show();