]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Restore the root URL when navigating through the history (this is important for views...
authorPeter Penz <peter.penz19@gmail.com>
Mon, 24 Sep 2007 13:50:31 +0000 (13:50 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 24 Sep 2007 13:50:31 +0000 (13:50 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=716310

src/dolphincolumnview.cpp
src/dolphincolumnview.h
src/dolphinview.cpp
src/dolphinview.h
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h

index 7a1e41331ad8d3a992f5b099a328c15bb1a347d0..a89ab184892c5db48431f8fcfa12835d6452bd7d 100644 (file)
@@ -497,6 +497,61 @@ void DolphinColumnView::reload()
     dirLister->openUrl(baseUrl, false, true);
 }
 
+void DolphinColumnView::showColumn(const KUrl& url)
+{
+    if (!m_columns[0]->url().isParentOf(url)) {
+        // the URL is no child URL of the column view, hence do nothing
+        return;
+    }
+
+    int columnIndex = 0;
+    foreach (ColumnWidget* column, m_columns) {
+        if (column->url() == url) {
+            // the column represents already the requested URL, hence activate it
+            requestActivation(column);
+            return;
+        } else if (!column->url().isParentOf(url)) {
+            // the column is no parent of the requested URL, hence
+            // just delete all remaining columns
+            if (columnIndex > 0) {
+                setActiveColumnIndex(columnIndex - 1);
+                deleteInactiveChildColumns();
+                break;
+            }
+        }
+        ++columnIndex;
+    }
+
+    // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
+    // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
+    // "c" will be created.
+    const int lastIndex = m_columns.count() - 1;
+    Q_ASSERT(lastIndex >= 0);
+
+    const KUrl& activeUrl = m_columns[lastIndex]->url();
+    Q_ASSERT(activeUrl.isParentOf(url));
+    Q_ASSERT(activeUrl != url);
+
+    QString path = activeUrl.url(KUrl::AddTrailingSlash);
+    const QString targetPath = url.url(KUrl::AddTrailingSlash);
+    int slashIndex = path.count('/');
+    bool hasSubPath = (slashIndex >= 0);
+    while (hasSubPath) {
+        const QString subPath = targetPath.section('/', slashIndex, slashIndex);
+        if (subPath.isEmpty()) {
+            hasSubPath = false;
+        } else {
+            path += subPath + '/';
+            ++slashIndex;
+
+            const QModelIndex dirIndex = m_dolphinModel->indexForUrl(KUrl(path));
+            if (dirIndex.isValid()) {
+                triggerItem(m_proxyModel->mapFromSource(dirIndex));
+            }
+        }
+    }
+}
+
 bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const
 {
     Q_UNUSED(index);
@@ -647,61 +702,6 @@ void DolphinColumnView::moveContentHorizontally(int x)
     layoutColumns();
 }
 
-void DolphinColumnView::showColumn(const KUrl& url)
-{
-    if (!m_columns[0]->url().isParentOf(url)) {
-        // the URL is no child URL of the column view, hence do nothing
-        return;
-    }
-
-    int columnIndex = 0;
-    foreach (ColumnWidget* column, m_columns) {
-        if (column->url() == url) {
-            // the column represents already the requested URL, hence activate it
-            requestActivation(column);
-            return;
-        } else if (!column->url().isParentOf(url)) {
-            // the column is no parent of the requested URL, hence
-            // just delete all remaining columns
-            if (columnIndex > 0) {
-                setActiveColumnIndex(columnIndex - 1);
-                deleteInactiveChildColumns();
-                break;
-            }
-        }
-        ++columnIndex;
-    }
-
-    // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
-    // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
-    // "c" will be created.
-    const int lastIndex = m_columns.count() - 1;
-    Q_ASSERT(lastIndex >= 0);
-
-    const KUrl& activeUrl = m_columns[lastIndex]->url();
-    Q_ASSERT(activeUrl.isParentOf(url));
-    Q_ASSERT(activeUrl != url);
-
-    QString path = activeUrl.url(KUrl::AddTrailingSlash);
-    const QString targetPath = url.url(KUrl::AddTrailingSlash);
-    int slashIndex = path.count('/');
-    bool hasSubPath = (slashIndex >= 0);
-    while (hasSubPath) {
-        const QString subPath = targetPath.section('/', slashIndex, slashIndex);
-        if (subPath.isEmpty()) {
-            hasSubPath = false;
-        } else {
-            path += subPath + '/';
-            ++slashIndex;
-
-            const QModelIndex dirIndex = m_dolphinModel->indexForUrl(KUrl(path));
-            if (dirIndex.isValid()) {
-                triggerItem(m_proxyModel->mapFromSource(dirIndex));
-            }
-        }
-    }
-}
-
 void DolphinColumnView::updateDecorationSize()
 {
     ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
index 2f10a9be8f29feac8642b8cdd0530da62180f102..2b393e4666c28f9ae4641aa0d5d8f047dacf353f 100644 (file)
@@ -57,6 +57,13 @@ public:
      */
     void reload();
 
+public slots:
+    /**
+     * Shows the column which represents the URL \a url. If the column
+     * is already shown, it gets activated, otherwise it will be created.
+     */
+    void showColumn(const KUrl& url);
+
 protected:
     virtual bool isIndexHidden(const QModelIndex& index) const;
     virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
@@ -79,12 +86,6 @@ private slots:
      */
     void moveContentHorizontally(int x);
 
-    /**
-     * Shows the column which represents the URL \a url. If the column
-     * is already shown, it gets activated, otherwise it will be created.
-     */
-    void showColumn(const KUrl& url);
-
     /**
      * Updates the size of the decoration dependent on the
      * icon size of the ColumnModeSettings. The controller
index 0b6c32811dec3117bf48a21f312961850b6a8987..ab413f765e9a60796610f5a8644e83b8514ce4c4 100644 (file)
@@ -71,7 +71,8 @@ DolphinView::DolphinView(QWidget* parent,
     m_fileItemDelegate(0),
     m_dolphinModel(dolphinModel),
     m_dirLister(dirLister),
-    m_proxyModel(proxyModel)
+    m_proxyModel(proxyModel),
+    m_rootUrl(url)
 {
     setFocusPolicy(Qt::StrongFocus);
     m_topLayout = new QVBoxLayout(this);
@@ -121,6 +122,11 @@ const KUrl& DolphinView::url() const
     return m_controller->url();
 }
 
+void DolphinView::setRootUrl(const KUrl& url)
+{
+    m_rootUrl = url;
+}
+
 KUrl DolphinView::rootUrl() const
 {
     return isColumnViewActive() ? m_dirLister->url() : url();
@@ -414,12 +420,28 @@ void DolphinView::setUrl(const KUrl& url)
         return;
     }
 
+    const KUrl oldRootUrl = rootUrl();
     m_controller->setUrl(url); // emits urlChanged, which we forward
 
-    applyViewProperties(url);
+    const bool restoreColumnView = !isColumnViewActive()
+                                   && m_rootUrl.isParentOf(url)
+                                   && (m_rootUrl != url);
+    if (restoreColumnView) {
+        applyViewProperties(m_rootUrl);
+        startDirLister(m_rootUrl);
+        Q_ASSERT(itemView() == m_columnView);
+        m_columnView->showColumn(url);
+    } else {
+        applyViewProperties(url);
+        startDirLister(url);
+    }
 
-    startDirLister(url);
     itemView()->setFocus();
+
+    const KUrl newRootUrl = rootUrl();
+    if (newRootUrl != oldRootUrl) {
+        emit rootUrlChanged(newRootUrl);
+    }
 }
 
 void DolphinView::mouseReleaseEvent(QMouseEvent* event)
index 6799215e0843fc058372abb0aa4701e489fd694e..3f5b9f596798d445b7f20ac511a406e685d2610b 100644 (file)
@@ -136,6 +136,11 @@ public:
      */
     const KUrl& url() const;
 
+    /**
+     * Sets the root URL of the view (see also DolphinView::rootUrl())
+     */
+    void setRootUrl(const KUrl& url);
+
     /**
      * Returns the root URL of the view, which is defined as the first
      * visible path of DolphinView::url(). Usually the root URL is
@@ -388,6 +393,12 @@ signals:
      */
     void errorMessage(const QString& msg);
 
+    /**
+     * Is emitted if the root URL of the view has been changed
+     * to \a url (see also DolphinView::rootUrl()).
+     */
+    void rootUrlChanged(const KUrl& url);
+
 protected:
     /** @see QWidget::mouseReleaseEvent */
     virtual void mouseReleaseEvent(QMouseEvent* event);
@@ -571,6 +582,8 @@ private:
     DolphinSortFilterProxyModel* m_proxyModel;
 
     QList<CutItem> m_cutItemsCache;
+
+    KUrl m_rootUrl;
 };
 
 #endif // DOLPHINVIEW_H
index c30b2d0bce7ccc4dd75bb6a1c3286e67873de604..9a358b2fffd195a0cd8b9ac10f3195984779ad36 100644 (file)
@@ -136,9 +136,11 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
             this, SLOT(showInfoMessage(const QString&)));
     connect(m_view, SIGNAL(itemTriggered(KFileItem)),
             this, SLOT(slotItemTriggered(KFileItem)));
+    connect(m_view, SIGNAL(rootUrlChanged(const KUrl&)),
+            m_urlNavigator, SLOT(saveRootUrl(const KUrl&)));
 
     connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
-            m_view, SLOT(setUrl(const KUrl&)));
+            this, SLOT(restoreView(const KUrl&)));
 
     m_statusBar = new DolphinStatusBar(this, url);
     connect(m_view, SIGNAL(urlChanged(const KUrl&)),
@@ -491,6 +493,12 @@ void DolphinViewContainer::activate()
     setActive(true);
 }
 
+void DolphinViewContainer::restoreView(const KUrl& url)
+{
+    m_view->setRootUrl(m_urlNavigator->savedRootUrl());
+    m_view->setUrl(url);
+}
+
 void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
 {
     // Prefer the local path over the URL.
index f73fb8a26d6c86a1c4915329b5f519c539643b6d..b7cb4ca5be30787359a034694a57751ce8b40382 100644 (file)
@@ -201,6 +201,12 @@ private slots:
      */
     void activate();
 
+    /**
+     * Restores the current view to show \a url and assures
+     * that the root URL of the view is respected.
+     */
+    void restoreView(const KUrl& url);
+
 private:
     /**
      * Returns the default text of the status bar, if no item is