+ if (index.isValid()) {
+ const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
+ KFileItem item = m_dirModel->itemForIndex(dirIndex);
+ Q_ASSERT(!item.isNull());
+ if (item.isDir()) {
+ emit urlsDropped(urls, item.url());
+ }
+ }
+}
+
+void TreeViewSidebarPage::triggerExpanding(const QModelIndex& index)
+{
+ Q_UNUSED(index);
+ // the expanding of the folders may not be done in the context
+ // of this slot
+ QMetaObject::invokeMethod(this, "expandToLeafDir", Qt::QueuedConnection);
+}
+
+void TreeViewSidebarPage::expandToLeafDir()
+{
+ // expand all directories until the parent directory of m_leafDir
+ const KUrl parentUrl = m_leafDir.upUrl();
+ QModelIndex dirIndex = m_dirModel->indexForUrl(parentUrl);
+ QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+ m_treeView->setExpanded(proxyIndex, true);
+
+ // assure that m_leafDir gets selected
+ dirIndex = m_dirModel->indexForUrl(m_leafDir);
+ proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+ m_treeView->scrollTo(proxyIndex);
+
+ QItemSelectionModel* selModel = m_treeView->selectionModel();
+ selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::Select);
+}
+
+void TreeViewSidebarPage::loadSubTree()
+{
+ disconnect(m_dirLister, SIGNAL(completed()),
+ this, SLOT(loadSubTree()));
+
+ QItemSelectionModel* selModel = m_treeView->selectionModel();
+ selModel->clearSelection();
+
+ if (m_leafDir.isParentOf(m_dirLister->url())) {
+ // The leaf directory is not a child of the base URL, hence
+ // no sub directory must be loaded or selected.