]> cloud.milkyroute.net Git - dolphin.git/commitdiff
* respect the --select startup option
authorPeter Penz <peter.penz19@gmail.com>
Thu, 17 Dec 2009 21:07:18 +0000 (21:07 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 17 Dec 2009 21:07:18 +0000 (21:07 +0000)
* minor cleanups related to selecting items in general

svn path=/trunk/KDE/kdebase/apps/; revision=1063329

src/dolphinapplication.cpp
src/dolphinapplication.h
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinview.cpp
src/dolphinview.h
src/main.cpp
src/panels/folders/folderspanel.cpp
src/panels/folders/folderspanel.h

index f61bf795a1a5ebcde2609f3bb62478072ac0b43c..c418f4540d086a4ae45536625c18301215bb0925 100644 (file)
@@ -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;
+    QList<KUrl> urls;
+    const int argsCount = args->count();
+    for (int i = 0; i < argsCount; ++i) {
+        urls.append(args->url(i));
+    }
 
-    default:
-        for (int i = 0; i < args->count(); ++i) {
-            openWindow(args->url(i));
+    DolphinMainWindow* win = createMainWindow();
+    if (urls.count() > 0) {
+        if (args->isSet("select")) {
+            win->openFiles(urls);
+        } else {
+            win->openDirectories(urls);
         }
     }
+    win->show();
 
-    first = false;
     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<KUrl>() << 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"
index af2006e7dc4a59c52874b0f2a3a0e4d2fb8922ed..ff4aa390c44bfa85f22c917ae244f45d51e81354 100644 (file)
@@ -23,7 +23,6 @@
 #define _DOLPHIN_APPLICATION_H
 
 #include <kuniqueapplication.h>
-#include <kurl.h>
 
 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);
 
index 5e08a9e2e5d292c922dac15b64ca2fed6d5f8f81..7fcbe498fb7cd067aa9096e3c460813a1a19588d 100644 (file)
@@ -151,6 +151,64 @@ DolphinMainWindow::~DolphinMainWindow()
     DolphinApplication::app()->removeMainWindow(this);
 }
 
+void DolphinMainWindow::openDirectories(const QList<KUrl>& 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<KUrl>::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<KUrl>& 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<KUrl> 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
index 0b4f90d19fe806755e82cde6cb413d7d454d0277..cfdc21618d76725783de87f2815cd982798ed1d0 100644 (file)
@@ -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<KUrl>& dirs);
+    
+    /**
+     * Opens the directory which contains the files \p files
+     * and selects all files (implements the --select option
+     * of Dolphin).
+     */
+    void openFiles(const QList<KUrl>& 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();
 
index 54294161df6382ec40e689e87a5e2cde35d40fa6..6f36d1655a66192e5c24a8d48eb5006981baffcd 100644 (file)
@@ -291,6 +291,14 @@ bool DolphinView::hasSelection() const
     return view && view->selectionModel()->hasSelection();
 }
 
+void DolphinView::markUrlsAsSelected(const QList<KUrl>& 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();
     }
 
index f9cf39d7f18c312a681bf675b2feb44a9f5e5431..2120e1ee01759df4a9e0cf3961201f5205885949 100644 (file)
@@ -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<KUrl>& 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.
index 67860489748f5439d07ee755847b7fac52c1397c..215ec92ec73ea1e9480dc7205fa397dfa70d93e3 100644 (file)
@@ -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()) {
index 1e3bdb8a67371951c73dd7a823ac6684d6fa04f1..0542665d5bb0b9ee38dba917ff5358ea51b49df7 100644 (file)
@@ -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);
index 1822d17e0a86cc8378bb9bfd9467b6ca20507979..438a9ee686c382ee5c7d242dd92598c591620502 100644 (file)
@@ -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.