From 3bf8fa5901f200d26acc2eb527eef88087e6edb9 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Tue, 25 Sep 2007 09:02:29 +0000 Subject: [PATCH] further root URL handling cleanups svn path=/trunk/KDE/kdebase/apps/; revision=716789 --- src/dolphinview.cpp | 31 +++++++++++++------------------ src/dolphinview.h | 23 +++++++++++++++-------- src/dolphinviewcontainer.cpp | 14 +++++++++----- src/dolphinviewcontainer.h | 6 ++++++ 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 9541f5abb..91a41b531 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -71,8 +71,7 @@ DolphinView::DolphinView(QWidget* parent, m_fileItemDelegate(0), m_dolphinModel(dolphinModel), m_dirLister(dirLister), - m_proxyModel(proxyModel), - m_rootUrl(url) + m_proxyModel(proxyModel) { setFocusPolicy(Qt::StrongFocus); m_topLayout = new QVBoxLayout(this); @@ -122,11 +121,6 @@ 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,24 +408,23 @@ void DolphinView::refresh() updateViewportColor(); } -void DolphinView::setUrl(const KUrl& url) +void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl) { if (m_controller->url() == url) { return; } const bool restoreColumnView = !isColumnViewActive() - && !m_rootUrl.isEmpty() - && m_rootUrl.isParentOf(url) - && (m_rootUrl != url); + && !rootUrl.isEmpty() + && !rootUrl.equals(url, KUrl::CompareWithoutTrailingSlash) + && rootUrl.isParentOf(url); - const KUrl oldRootUrl = rootUrl(); m_controller->setUrl(url); // emits urlChanged, which we forward if (restoreColumnView) { - applyViewProperties(m_rootUrl); + applyViewProperties(rootUrl); Q_ASSERT(itemView() == m_columnView); - startDirLister(m_rootUrl); + startDirLister(rootUrl); m_columnView->showColumn(url); } else { applyViewProperties(url); @@ -440,10 +433,12 @@ void DolphinView::setUrl(const KUrl& url) itemView()->setFocus(); - const KUrl newRootUrl = rootUrl(); - if (newRootUrl != oldRootUrl) { - emit rootUrlChanged(newRootUrl); - } + emit startedPathLoading(url); +} + +void DolphinView::setUrl(const KUrl& url) +{ + updateView(url, KUrl()); } void DolphinView::mouseReleaseEvent(QMouseEvent* event) diff --git a/src/dolphinview.h b/src/dolphinview.h index 3f5b9f596..99a5233e9 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -136,11 +136,6 @@ 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 @@ -299,6 +294,16 @@ public: */ void refresh(); + /** + * Changes the directory of the view to \a url. If \a rootUrl is empty, the view + * properties from \a url are used for adjusting the view mode and the other properties. + * If \a rootUrl is not empty, the view properties from the root URL are considered + * instead. Specifying a root URL is only required if a view having a different root URL + * (e. g. the column view) should be restored. Usually using DolphinView::setUrl() + * is enough for changing the current URL. + */ + void updateView(const KUrl& url, const KUrl& rootUrl); + public slots: /** * Changes the directory to \a url. If the current directory is equal to @@ -394,10 +399,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()). + * Is emitted after DolphinView::setUrl() has been invoked and + * the path \a url is currently loaded. If this signal is emitted, + * it is assured that the view contains already the correct root + * URL and property settings. */ - void rootUrlChanged(const KUrl& url); + void startedPathLoading(const KUrl& url); protected: /** @see QWidget::mouseReleaseEvent */ diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index d54ec1e93..5194646f6 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -136,8 +136,8 @@ 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_view, SIGNAL(startedPathLoading(const KUrl&)), + this, SLOT(saveRootUrl(const KUrl&))); connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)), this, SLOT(restoreView(const KUrl&))); @@ -495,8 +495,13 @@ void DolphinViewContainer::activate() void DolphinViewContainer::restoreView(const KUrl& url) { - m_view->setRootUrl(m_urlNavigator->savedRootUrl()); - m_view->setUrl(url); + m_view->updateView(url, m_urlNavigator->savedRootUrl()); +} + +void DolphinViewContainer::saveRootUrl(const KUrl& url) +{ + Q_UNUSED(url); + m_urlNavigator->saveRootUrl(m_view->rootUrl()); } void DolphinViewContainer::slotItemTriggered(const KFileItem& item) @@ -506,7 +511,6 @@ void DolphinViewContainer::slotItemTriggered(const KFileItem& item) KUrl url = item.mostLocalUrl(isLocal); if (item.isDir()) { - m_view->setRootUrl(KUrl()); // the root URL is unknown m_view->setUrl(url); } else if (item.isFile()) { // allow to browse through ZIP and tar files diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index b7cb4ca5b..3cfa907c7 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -207,6 +207,12 @@ private slots: */ void restoreView(const KUrl& url); + /** + * Saves the root URL of the current URL \a url + * into the URL navigator. + */ + void saveRootUrl(const KUrl& url); + private: /** * Returns the default text of the status bar, if no item is -- 2.47.3