From: Peter Penz Date: Mon, 24 Sep 2007 13:50:31 +0000 (+0000) Subject: Restore the root URL when navigating through the history (this is important for views... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/772a55aafc2e558302d042eb65026b9b50302ccc Restore the root URL when navigating through the history (this is important for views like the column view where the root URL might differ from the current URL). svn path=/trunk/KDE/kdebase/apps/; revision=716310 --- diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 7a1e41331..a89ab1848 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -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(); diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 2f10a9be8..2b393e466 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -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 diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 0b6c32811..ab413f765 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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) diff --git a/src/dolphinview.h b/src/dolphinview.h index 6799215e0..3f5b9f596 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -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 m_cutItemsCache; + + KUrl m_rootUrl; }; #endif // DOLPHINVIEW_H diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index c30b2d0bc..9a358b2ff 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -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. diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index f73fb8a26..b7cb4ca5b 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -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