]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Further cleanup to prepare the move.
[dolphin.git] / src / dolphinview.cpp
index 88a2cff80ffad1c484ce86e2354c3ff0d5cd8091..1aa7e0ff8055f85fe95f92528fd225d484a90dbf 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <kdirmodel.h>
 #include <kfileitemdelegate.h>
+#include <kfileplacesmodel.h>
 #include <klocale.h>
 #include <kiconeffect.h>
 #include <kio/netaccess.h>
@@ -52,7 +53,7 @@
 #include "dolphincontextmenu.h"
 #include "filterbar.h"
 #include "renamedialog.h"
-#include "urlnavigator.h"
+#include "kurlnavigator.h"
 #include "viewproperties.h"
 #include "dolphinsettings.h"
 #include "dolphin_generalsettings.h"
@@ -96,7 +97,7 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
     connect(clipboard, SIGNAL(dataChanged()),
             this, SLOT(updateCutItems()));
 
-    m_urlNavigator = new UrlNavigator(DolphinSettings::instance().bookmarkManager(), url, this);
+    m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this);
     m_urlNavigator->setUrlEditable(DolphinSettings::instance().generalSettings()->editableUrl());
     m_urlNavigator->setHomeUrl(DolphinSettings::instance().generalSettings()->homeUrl());
     m_urlNavigator->setShowHiddenFiles(showHiddenFiles);
@@ -295,8 +296,8 @@ void DolphinView::renameSelectedItems()
                 name.replace(replaceIndex, 1, number);
 
                 if (oldUrl.fileName() != name) {
-                    KUrl newUrl(oldUrl.upUrl());
-                    newUrl.addPath(name);
+                    KUrl newUrl = oldUrl;
+                    newUrl.setFileName(name);
                     m_mainWindow->rename(oldUrl, newUrl);
                 }
                 ++it;
@@ -323,8 +324,8 @@ void DolphinView::renameSelectedItems()
         }
         else {
             const KUrl& oldUrl = urls.first();
-            KUrl newUrl = oldUrl.upUrl();
-            newUrl.addPath(newName);
+            KUrl newUrl = oldUrl;
+            newUrl.setFileName(newName);
             m_mainWindow->rename(oldUrl, newUrl);
         }
     }
@@ -355,11 +356,6 @@ int DolphinView::contentsY() const
     return itemView()->verticalScrollBar()->value();
 }
 
-void DolphinView::refreshSettings()
-{
-    startDirLister(m_urlNavigator->url());
-}
-
 void DolphinView::emitRequestItemInfo(const KUrl& url)
 {
     emit requestItemInfo(url);
@@ -781,12 +777,13 @@ void DolphinView::showPreview(const KFileItem* item, const QPixmap& pixmap)
 
 void DolphinView::restoreContentsPos()
 {
-    UrlNavigator::HistoryElem historyItem = m_urlNavigator->currentHistoryItem();
-    if (!historyItem.url().isEmpty()) {
+    KUrl currentUrl = m_urlNavigator->url();
+    if (!currentUrl.isEmpty()) {
         QAbstractItemView* view = itemView();
-        // TODO: view->setCurrentItem(historyItem.currentFileName());
-        view->horizontalScrollBar()->setValue(historyItem.contentsX());
-        view->verticalScrollBar()->setValue(historyItem.contentsY());
+        // TODO: view->setCurrentItem(m_urlNavigator->currentFileName());
+        QPoint pos = m_urlNavigator->savedPosition();
+        view->horizontalScrollBar()->setValue(pos.x());
+        view->verticalScrollBar()->setValue(pos.y());
     }
 }
 
@@ -840,14 +837,42 @@ void DolphinView::startDirLister(const KUrl& url, bool reload)
     m_blockContentsMovedSignal = true;
     m_dirLister->stop();
 
+    bool openDir = true;
     bool keepOldDirs = isColumnViewActive();
-    if (keepOldDirs && !m_dirLister->url().isParentOf(url)) {
-        // The current URL is not a child of the dir lister
-        // URL. This may happen when e. g. a bookmark has been selected
-        // and hence the view must be reset.
-        keepOldDirs = false;
+    if (keepOldDirs) {
+        if (reload) {
+            keepOldDirs = false;
+
+            const KUrl& dirListerUrl = m_dirLister->url();
+            if (dirListerUrl.isValid()) {
+                const KUrl::List dirs = m_dirLister->directories();
+                KUrl url;
+                foreach (url, dirs) {
+                    m_dirLister->updateDirectory(url);
+                }
+                openDir = false;
+            }
+        }
+        else if (m_dirLister->directories().contains(url)) {
+            // The dir lister contains the directory already, so
+            // KDirLister::openUrl() may not been invoked twice.
+            m_dirLister->updateDirectory(url);
+            openDir = false;
+        }
+        else {
+            const KUrl& dirListerUrl = m_dirLister->url();
+            if ((dirListerUrl == url) || !m_dirLister->url().isParentOf(url)) {
+                // The current URL is not a child of the dir lister
+                // URL. This may happen when e. g. a bookmark has been selected
+                // and hence the view must be reset.
+                keepOldDirs = false;
+            }
+        }
+    }
+
+    if (openDir) {
+        m_dirLister->openUrl(url, keepOldDirs, reload);
     }
-    m_dirLister->openUrl(url, keepOldDirs, reload);
 }
 
 QString DolphinView::defaultStatusBarText() const