]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/treeviewsidebarpage.cpp
Port dolphin to the KFileItemDelegate API changes.
[dolphin.git] / src / treeviewsidebarpage.cpp
index eac1e6cf43273d94f7b7742d464b04e90748e442..680b2d3791c8853eb9e4deb6d77d83ebd3e6d5ec 100644 (file)
@@ -38,6 +38,7 @@
 
 TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
     SidebarPage(parent),
+    m_dirListerCompleted(false),
     m_dirLister(0),
     m_dolphinModel(0),
     m_proxyModel(0),
@@ -89,6 +90,12 @@ void TreeViewSidebarPage::showEvent(QShowEvent* event)
         m_dirLister->setDelayedMimeTypes(true);
         m_dirLister->setAutoErrorHandlingEnabled(false, this);
 
+        m_dirListerCompleted = true;
+        connect(m_dirLister, SIGNAL(started(const KUrl&)),
+                this, SLOT(slotDirListerStarted(const KUrl&)));
+        connect(m_dirLister, SIGNAL(completed()),
+                this, SLOT(slotDirListerCompleted()));
+
         Q_ASSERT(m_dolphinModel == 0);
         m_dolphinModel = new DolphinModel(this);
         m_dolphinModel->setDirLister(m_dirLister);
@@ -138,34 +145,6 @@ void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
     contextMenu.open();
 }
 
-void TreeViewSidebarPage::expandSelectionParent()
-{
-    disconnect(m_dirLister, SIGNAL(completed()),
-               this, SLOT(expandSelectionParent()));
-
-    // expand the parent folder of the selected item
-    KUrl parentUrl = url().upUrl();
-    if (!m_dirLister->url().isParentOf(parentUrl)) {
-        return;
-    }
-
-    QModelIndex index = m_dolphinModel->indexForUrl(parentUrl);
-    if (index.isValid()) {
-        QModelIndex proxyIndex = m_proxyModel->mapFromSource(index);
-        m_treeView->setExpanded(proxyIndex, true);
-
-        // select the item and assure that the item is visible
-        index = m_dolphinModel->indexForUrl(url());
-        if (index.isValid()) {
-            proxyIndex = m_proxyModel->mapFromSource(index);
-            m_treeView->scrollTo(proxyIndex);
-
-            QItemSelectionModel* selModel = m_treeView->selectionModel();
-            selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::Select);
-        }
-    }
-}
-
 void TreeViewSidebarPage::updateActiveView(const QModelIndex& index)
 {
     const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
@@ -215,9 +194,6 @@ void TreeViewSidebarPage::expandToLeafDir()
 
 void TreeViewSidebarPage::loadSubTree()
 {
-    disconnect(m_dirLister, SIGNAL(completed()),
-               this, SLOT(loadSubTree()));
-
     QItemSelectionModel* selModel = m_treeView->selectionModel();
     selModel->clearSelection();
 
@@ -233,7 +209,7 @@ void TreeViewSidebarPage::loadSubTree()
         const QModelIndex proxyIndex = m_proxyModel->mapFromSource(index);
         m_treeView->scrollTo(proxyIndex);
         selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::Select);
-    } else {
+    } else if (m_dirListerCompleted) {
         // Load all sub directories that need to get expanded for making
         // the leaf directory visible. The slot triggerExpanding() will
         // get invoked if the expanding has been finished.
@@ -241,6 +217,18 @@ void TreeViewSidebarPage::loadSubTree()
     }
 }
 
+void TreeViewSidebarPage::slotDirListerStarted(const KUrl& url)
+{
+    Q_UNUSED(url);
+    m_dirListerCompleted = false;
+}
+
+void TreeViewSidebarPage::slotDirListerCompleted()
+{
+    m_dirListerCompleted = true;
+    QMetaObject::invokeMethod(this, "loadSubTree", Qt::QueuedConnection);
+}
+
 void TreeViewSidebarPage::loadTree(const KUrl& url)
 {
     Q_ASSERT(m_dirLister != 0);
@@ -255,11 +243,9 @@ void TreeViewSidebarPage::loadTree(const KUrl& url)
         baseUrl = url;
     }
 
-    connect(m_dirLister, SIGNAL(completed()),
-            this, SLOT(loadSubTree()));
     if (m_dirLister->url() != baseUrl) {
         m_dirLister->stop();
-        m_dirLister->openUrl(baseUrl);
+        m_dirLister->openUrl(baseUrl, false, true);
     } else {
         loadSubTree();
     }