]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Port away from KonqOperations::renameV2.
[dolphin.git] / src / dolphinviewcontainer.cpp
index ae9cd93c0f4087f41ee98a1fabf203c0c2075656..0f3aa97611d4f5e58a1db622db9eaeaa6b4534fc 100644 (file)
@@ -38,7 +38,6 @@
 #include <KIO/PreviewJob>
 #include <KMessageWidget>
 #include <KNewFileMenu>
-#include <konqmimedata.h>
 #include <konq_operations.h>
 #include <KShell>
 #include <KUrl>
@@ -113,6 +112,8 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
             m_urlNavigator, &KUrlNavigator::setUrl);
     connect(m_view, &DolphinView::urlChanged,
             m_messageWidget, &KMessageWidget::hide);
+    connect(m_view, &DolphinView::directoryLoadingCompleted,
+            m_messageWidget, &KMessageWidget::hide);
     connect(m_view, &DolphinView::writeStateChanged,
             this, &DolphinViewContainer::writeStateChanged);
     connect(m_view, &DolphinView::requestItemInfo,
@@ -143,6 +144,8 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
             this, &DolphinViewContainer::showErrorMessage);
     connect(m_view, &DolphinView::urlIsFileError,
             this, &DolphinViewContainer::slotUrlIsFileError);
+    connect(m_view, &DolphinView::activated,
+            this, &DolphinViewContainer::activate);
 
     connect(m_urlNavigator, &KUrlNavigator::urlAboutToBeChanged,
             this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged);
@@ -300,6 +303,9 @@ void DolphinViewContainer::showMessage(const QString& msg, MessageType type)
     const int unwrappedWidth = m_messageWidget->sizeHint().width();
     m_messageWidget->setWordWrap(unwrappedWidth > size().width());
 
+    if (m_messageWidget->isVisible()) {
+        m_messageWidget->hide();
+    }
     m_messageWidget->animatedShow();
 }
 
@@ -338,36 +344,18 @@ void DolphinViewContainer::setSearchModeEnabled(bool enabled)
     m_urlNavigator->setVisible(!enabled);
 
     if (enabled) {
-        KUrl url = m_urlNavigator->locationUrl();
-        m_searchBox->setText(QString());
-        m_searchBox->setReadOnly(isSearchUrl(url), url);
-
-        // Remember the most recent non-search URL as search path
-        // of the search-box, so that it can be restored
-        // when switching back to the URL navigator.
-        int index = m_urlNavigator->historyIndex();
-        const int historySize = m_urlNavigator->historySize();
-        while (isSearchUrl(url) && (index < historySize)) {
-            ++index;
-            url = m_urlNavigator->locationUrl(index);
-        }
-
-        if (!isSearchUrl(url)) {
-            m_searchBox->setSearchPath(url);
-        }
+        const KUrl& locationUrl = m_urlNavigator->locationUrl();
+        m_searchBox->fromSearchUrl(locationUrl);
     } else {
         m_view->setViewPropertiesContext(QString());
 
         // Restore the URL for the URL navigator. If Dolphin has been
         // started with a search-URL, the home URL is used as fallback.
-        const KUrl url = m_searchBox->searchPath();
-        if (url.isValid() && !url.isEmpty()) {
-            if (isSearchUrl(url)) {
-                m_urlNavigator->goHome();
-            } else {
-                m_urlNavigator->setLocationUrl(url);
-            }
+        KUrl url = m_searchBox->searchPath();
+        if (url.isEmpty() || !url.isValid() || isSearchUrl(url)) {
+            url = GeneralSettings::self()->homeUrl();
         }
+        m_urlNavigator->setLocationUrl(url);
     }
 }
 
@@ -500,7 +488,16 @@ void DolphinViewContainer::slotDirectoryLoadingCanceled()
 void DolphinViewContainer::slotUrlIsFileError(const KUrl& url)
 {
     const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
-    slotItemActivated(item);
+
+    // Find out if the file can be opened in the view (for example, this is the
+    // case if the file is an archive). The mime type must be known for that.
+    item.determineMimeType();
+    const KUrl& folderUrl = DolphinView::openItemAsFolderUrl(item, true);
+    if (!folderUrl.isEmpty()) {
+        m_view->setUrl(folderUrl);
+    } else {
+        slotItemActivated(item);
+    }
 }
 
 void DolphinViewContainer::slotItemActivated(const KFileItem& item)
@@ -743,4 +740,3 @@ void DolphinViewContainer::saveViewState()
     m_urlNavigator->saveLocationState(locationState);
 }
 
-#include "dolphinviewcontainer.moc"