]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Stat URLs before opening them to make sure they are actually dirs we can list. Otherw...
[dolphin.git] / src / dolphinmainwindow.cpp
index e68fab99768a02a4bb92a3e2335e950013abe583..da4cab597fc475fc510aef0038d23a39703d233e 100644 (file)
@@ -121,7 +121,8 @@ DolphinMainWindow::DolphinMainWindow(int id) :
     m_actionHandler(0),
     m_remoteEncoding(0),
     m_settingsDialog(0),
-    m_captionStatJob(0)
+    m_captionStatJob(0),
+    m_lastHandleUrlStatJob(0)
 {
     setObjectName("Dolphin#");
 
@@ -1132,13 +1133,44 @@ void DolphinMainWindow::showSearchOptions()
 
 void DolphinMainWindow::handleUrl(const KUrl& url)
 {
-    if (KProtocolManager::supportsListing(url)) {
+    delete m_lastHandleUrlStatJob;
+    m_lastHandleUrlStatJob = 0;
+
+    if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
+        activeViewContainer()->setUrl(url);
+    } else if (KProtocolManager::supportsListing(url)) {
+        // stat the URL to see if it is a dir or not
+        m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
+        connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
+                this, SLOT(slotHandleUrlStatFinished(KJob*)));
+
+    } else {
+        new KRun(url, this);
+    }
+}
+
+void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
+{
+    m_lastHandleUrlStatJob = 0;
+    const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
+    const KUrl url = static_cast<KIO::StatJob*>(job)->url();
+    if ( entry.isDir() ) {
         activeViewContainer()->setUrl(url);
     } else {
         new KRun(url, this);
     }
 }
 
+void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
+{
+    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+    if (!urls.isEmpty() && tab != -1) {
+        const ViewTab& viewTab = m_viewTab[tab];
+        const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
+        DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
+    }
+}
+
 void DolphinMainWindow::slotCaptionStatFinished(KJob* job)
 {
     m_captionStatJob = 0;
@@ -1227,6 +1259,8 @@ void DolphinMainWindow::init()
             this, SLOT(closeTab(int)));
     connect(m_tabBar, SIGNAL(tabMoved(int, int)),
             this, SLOT(slotTabMoved(int, int)));
+    connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
+            this, SLOT(tabDropEvent(int, QDropEvent*)));
 
     m_tabBar->blockSignals(true);  // signals get unblocked after at least 2 tabs are open