diff --git a/src/dolphinapplication.cpp b/src/dolphinapplication.cpp index f61bf795a1..c418f4540d 100644 --- a/src/dolphinapplication.cpp +++ b/src/dolphinapplication.cpp @@ -72,57 +72,36 @@ void DolphinApplication::refreshMainWindows() int DolphinApplication::newInstance() { KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); - static bool first = true; - switch (args->count()) { - case 0: - if( !first || !isSessionRestored()) { - openWindow(KUrl()); - } - break; - - case 1: - openWindow(args->url(0)); - break; - - case 2: - openSplitWindow(args->url(0),args->url(1)); - break; - - default: - for (int i = 0; i < args->count(); ++i) { - openWindow(args->url(i)); - } + QList urls; + const int argsCount = args->count(); + for (int i = 0; i < argsCount; ++i) { + urls.append(args->url(i)); } - first = false; + DolphinMainWindow* win = createMainWindow(); + if (urls.count() > 0) { + if (args->isSet("select")) { + win->openFiles(urls); + } else { + win->openDirectories(urls); + } + } + win->show(); + args->clear(); return 0; } -int DolphinApplication::openWindow(const KUrl& url) +int DolphinApplication::openWindow(const QString& urlString) { DolphinMainWindow* win = createMainWindow(); - if ((win->activeViewContainer() != 0) && url.isValid()) { - win->activeViewContainer()->setUrl(url); + const KUrl url(urlString); + if (!url.isEmpty()) { + win->openDirectories(QList() << url); } win->show(); return win->getId(); } -int DolphinApplication::openSplitWindow(const KUrl& leftUrl, const KUrl& rightUrl) -{ - DolphinMainWindow* win = createMainWindow(); - if ((win->activeViewContainer() != 0) && leftUrl.isValid()) { - win->activeViewContainer()->setUrl(leftUrl); - } - win->toggleSplitView(); - if ((win->activeViewContainer() != 0) && rightUrl.isValid()){ - win->activeViewContainer()->setUrl(rightUrl); - } - win->show(); - return win->getId(); -} - - #include "dolphinapplication.moc" diff --git a/src/dolphinapplication.h b/src/dolphinapplication.h index af2006e7dc..ff4aa390c4 100644 --- a/src/dolphinapplication.h +++ b/src/dolphinapplication.h @@ -23,7 +23,6 @@ #define _DOLPHIN_APPLICATION_H #include -#include class DolphinMainWindow; class KUrl; @@ -56,11 +55,10 @@ public: /** @see KUniqueApplication::newInstance(). */ virtual int newInstance(); -public slots: - int openWindow(const KUrl& url); - int openSplitWindow(const KUrl& leftUrl,const KUrl& rightUrl); + /** Interface implementation for D-Bus Interface. */ + int openWindow(const QString& urlString); -protected: +private: /** Called by the DolphinMainWindow to deregister. */ void removeMainWindow(DolphinMainWindow* mainWindow); diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 5e08a9e2e5..7fcbe498fb 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -151,6 +151,64 @@ DolphinMainWindow::~DolphinMainWindow() DolphinApplication::app()->removeMainWindow(this); } +void DolphinMainWindow::openDirectories(const QList& dirs) +{ + if (dirs.isEmpty()) { + return; + } + + const int oldOpenTabsCount = m_viewTab.count(); + + const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings(); + const bool hasSplitView = generalSettings->splitView(); + + // 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.begin(); + while (it != dirs.end()) { + openNewTab(*it); + ++it; + + if (hasSplitView && (it != dirs.end())) { + const int tabIndex = m_viewTab.count() - 1; + m_viewTab[tabIndex].secondaryView->setUrl(*it); + ++it; + } + } + + // remove the previously opened tabs + for (int i = 0; i < oldOpenTabsCount; ++i) { + closeTab(0); + } +} + +void DolphinMainWindow::openFiles(const QList& files) +{ + // Get all distinct directories from 'files' and open a tab + // for each directory. If the "split view" option is enabled, two + // directories are shown inside one tab (see openDirectories()). + QList dirs; + foreach (const KUrl& url, files) { + const KUrl dir(url.directory()); + if (!dirs.contains(dir)) { + dirs.append(dir); + } + } + + openDirectories(dirs); + + // Select the files. Although the files can be split between several + // tabs, there is no need to split 'files' accordingly, as + // the DolphinView will just ignore invalid selections. + const int tabCount = m_viewTab.count(); + for (int i = 0; i < tabCount; ++i) { + m_viewTab[i].primaryView->view()->markUrlsAsSelected(files); + if (m_viewTab[i].secondaryView != 0) { + m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files); + } + } +} + void DolphinMainWindow::toggleViews() { if (m_viewTab[m_tabIndex].primaryView == 0) { @@ -251,11 +309,6 @@ void DolphinMainWindow::changeUrl(const KUrl& url) } } -void DolphinMainWindow::changeSelection(const KFileItemList& selection) -{ - activeViewContainer()->view()->changeSelection(selection); -} - void DolphinMainWindow::slotEditableStateChanged(bool editable) { KToggleAction* editableLocationAction = @@ -1406,8 +1459,6 @@ void DolphinMainWindow::setupDockWidgets() foldersPanel, SLOT(setUrl(KUrl))); connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)), this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons))); - connect(foldersPanel, SIGNAL(changeSelection(KFileItemList)), - this, SLOT(changeSelection(KFileItemList))); // setup "Terminal" #ifndef Q_OS_WIN diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 0b4f90d19f..cfdc21618d 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -73,6 +73,19 @@ public: */ DolphinViewContainer* activeViewContainer() const; + /** + * Opens each directory \p in a separate tab. If the "split view" + * option is enabled, 2 directories are collected within one tab. + */ + void openDirectories(const QList& dirs); + + /** + * Opens the directory which contains the files \p files + * and selects all files (implements the --select option + * of Dolphin). + */ + void openFiles(const QList& files); + /** * Returns true, if the main window contains two instances * of a view container. The active view constainer can be @@ -123,17 +136,12 @@ public slots: int getId() const; /** + * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface. * Inform all affected dolphin components (panels, views) of an URL * change. */ void changeUrl(const KUrl& url); - /** - * Inform all affected dolphin components that a selection change is - * requested. - */ - void changeSelection(const KFileItemList& selection); - /** Stores all settings and quits Dolphin. */ void quit(); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 54294161df..6f36d1655a 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -291,6 +291,14 @@ bool DolphinView::hasSelection() const return view && view->selectionModel()->hasSelection(); } +void DolphinView::markUrlsAsSelected(const QList& urls) +{ + foreach (const KUrl& url, urls) { + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); + m_selectedItems.append(item); + } +} + KFileItemList DolphinView::selectedItems() const { const QAbstractItemView* view = m_viewAccessor.itemView(); @@ -441,7 +449,7 @@ void DolphinView::reload() QByteArray viewState; QDataStream saveStream(&viewState, QIODevice::WriteOnly); saveState(saveStream); - m_selectedItems = selectedItems(); + m_selectedItems= selectedItems(); setUrl(url()); loadDirectory(url(), true); @@ -598,27 +606,6 @@ void DolphinView::clearSelection() m_viewAccessor.itemView()->clearSelection(); } -void DolphinView::changeSelection(const KFileItemList& selection) -{ - clearSelection(); - if (selection.isEmpty()) { - return; - } - const KUrl& baseUrl = url(); - KUrl url; - QItemSelection newSelection; - foreach(const KFileItem& item, selection) { - url = item.url().upUrl(); - if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) { - QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item)); - newSelection.select(index, index); - } - } - m_viewAccessor.itemView()->selectionModel()->select(newSelection, - QItemSelectionModel::ClearAndSelect - | QItemSelectionModel::Current); -} - void DolphinView::renameSelectedItems() { KFileItemList items = selectedItems(); @@ -1227,7 +1214,19 @@ void DolphinView::slotLoadingCompleted() } if (!m_selectedItems.isEmpty()) { - changeSelection(m_selectedItems); + const KUrl& baseUrl = url(); + KUrl url; + QItemSelection newSelection; + foreach(const KFileItem& item, m_selectedItems) { + url = item.url().upUrl(); + if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) { + QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item)); + newSelection.select(index, index); + } + } + m_viewAccessor.itemView()->selectionModel()->select(newSelection, + QItemSelectionModel::ClearAndSelect + | QItemSelectionModel::Current); m_selectedItems.clear(); } diff --git a/src/dolphinview.h b/src/dolphinview.h index f9cf39d7f1..2120e1ee01 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -179,6 +179,14 @@ public: */ bool supportsCategorizedSorting() const; + /** + * Marks the items indicated by \p urls to get selected after the + * directory DolphinView::url() has been loaded. Note that nothing + * gets selected if no loading of a directory has been triggered + * by DolphinView::setUrl() or DolphinView::reload(). + */ + void markUrlsAsSelected(const QList& urls); + /** * Returns the selected items. The list is empty if no item has been * selected. @@ -381,14 +389,6 @@ public slots: void clearSelection(); - /** - * Request of a selection change. The view will do its best to accommodate - * the request, but it is not guaranteed that all items in \a selection - * will actually get selected. The view will e.g. not select items which - * are not in the currently displayed folder. - */ - void changeSelection(const KFileItemList& selection); - /** * Triggers the renaming of the currently selected items, where * the user must input a new name for the items. diff --git a/src/main.cpp b/src/main.cpp index 6786048974..215ec92ec7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,7 +68,14 @@ int main(int argc, char **argv) KCmdLineArgs::init(argc, argv, &about); KCmdLineOptions options; - options.add("+[Url]", ki18nc("@info:shell", "Document to open")); + + // TODO KDE SC 4.5: The string freeze is valid and no new localized strings are allowed. + // To get in the --select option that was available in Konqueror 3, an already existing + // string ("Document to open") is used as workaround (the --select option will most probably + // anyhow used by applications and not by users). + const KLocalizedString& documentToOpen = ki18nc("@info:shell", "Document to open"); + options.add("select", documentToOpen); + options.add("+[Url]", documentToOpen); KCmdLineArgs::addCmdLineOptions(options); if (!DolphinApplication::start()) { diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 1e3bdb8a67..0542665d5b 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -185,7 +185,6 @@ void FoldersPanel::contextMenuEvent(QContextMenuEvent* event) if (index.isValid()) { const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); item = m_dolphinModel->itemForIndex(dolphinModelIndex); - emit changeSelection(KFileItemList()); } TreeViewContextMenu contextMenu(this, item); diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h index 1822d17e0a..438a9ee686 100644 --- a/src/panels/folders/folderspanel.h +++ b/src/panels/folders/folderspanel.h @@ -59,15 +59,6 @@ signals: */ void changeUrl(const KUrl& url, Qt::MouseButtons buttons); - /** - * This signal is emitted when the panel requests a change in the - * current selection. The file-management view recieving this signal is - * not required to select all listed files, limiting the selection to - * e.g. the current folder. The new selection will be reported via the - * setSelection slot. - */ - void changeSelection(const KFileItemList& selection); - public slots: /** * Changes the current selection inside the tree to \a url.