]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Group classes into folders, Dolphin is too big in the meantime for having a flat...
[dolphin.git] / src / dolphinviewcontainer.cpp
index cccce3fadbfb1ea0a4934ded79c129905733aca8..f09d3d1c926895573bf4fc55602c31ebe250f7f7 100644 (file)
@@ -42,6 +42,7 @@
 #include <konq_fileitemcapabilities.h>
 #include <konq_operations.h>
 #include <kurl.h>
+#include <krun.h>
 
 #include "dolphinmodel.h"
 #include "dolphincolumnview.h"
 #include "dolphindetailsview.h"
 #include "dolphiniconsview.h"
 #include "dolphincontextmenu.h"
+#include "draganddrophelper.h"
 #include "filterbar.h"
 #include "kurlnavigator.h"
 #include "viewproperties.h"
-#include "dolphinsettings.h"
+#include "settings/dolphinsettings.h"
 #include "dolphin_generalsettings.h"
 
 DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
@@ -80,8 +82,8 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
     m_topLayout->setMargin(0);
 
     m_urlNavigator = new KUrlNavigator(DolphinSettings::instance().placesModel(), url, this);
-    connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)),
-            m_mainWindow, SLOT(dropUrls(const KUrl::List&, const KUrl&)));
+    connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl&, QDropEvent*)),
+            this, SLOT(dropUrls(const KUrl&, QDropEvent*)));
     connect(m_urlNavigator, SIGNAL(activated()),
             this, SLOT(activate()));
 
@@ -115,6 +117,8 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
             this, SLOT(showInfoMessage(const QString&)));
     connect(m_dirLister, SIGNAL(errorMessage(const QString&)),
             this, SLOT(showErrorMessage(const QString&)));
+    connect(m_dirLister, SIGNAL(urlIsFileError(const KUrl&)),
+            this, SLOT(openFile(const KUrl&)));
 
     m_view = new DolphinView(this,
                              url,
@@ -139,13 +143,13 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
             this, SLOT(slotItemTriggered(KFileItem)));
     connect(m_view, SIGNAL(startedPathLoading(const KUrl&)),
             this, SLOT(saveRootUrl(const KUrl&)));
+    connect(m_view, SIGNAL(redirection(KUrl, KUrl)),
+            this, SLOT(redirect(KUrl, KUrl)));
 
     connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
             this, SLOT(restoreView(const KUrl&)));
 
-    m_statusBar = new DolphinStatusBar(this, url);
-    connect(m_view, SIGNAL(urlChanged(const KUrl&)),
-            m_statusBar, SLOT(updateSpaceInfoContent(const KUrl&)));
+    m_statusBar = new DolphinStatusBar(this, m_view);
 
     m_filterBar = new FilterBar(this);
     m_filterBar->setVisible(settings->filterBar());
@@ -174,11 +178,12 @@ DolphinViewContainer::~DolphinViewContainer()
 void DolphinViewContainer::setUrl(const KUrl& newUrl)
 {
     m_urlNavigator->setUrl(newUrl);
-
-    // Temporary disable the 'File'->'Create New...' menu until
-    // the write permissions can be checked in a fast way at
-    // DolphinViewContainer::slotDirListerCompleted().
-    m_mainWindow->newMenu()->menu()->setEnabled(false);
+    if (newUrl != m_urlNavigator->url()) {
+        // Temporary disable the 'File'->'Create New...' menu until
+        // the write permissions can be checked in a fast way at
+        // DolphinViewContainer::slotDirListerCompleted().
+        m_mainWindow->newMenu()->menu()->setEnabled(false);
+    }
 }
 
 const KUrl& DolphinViewContainer::url() const
@@ -198,11 +203,27 @@ bool DolphinViewContainer::isActive() const
     return m_view->isActive();
 }
 
+void DolphinViewContainer::refresh()
+{
+    m_view->refresh();
+    m_statusBar->refresh();
+}
+
 bool DolphinViewContainer::isFilterBarVisible() const
 {
     return m_filterBar->isVisible();
 }
 
+void DolphinViewContainer::showFilterBar(bool show)
+{
+    Q_ASSERT(m_filterBar != 0);
+    if (show) {
+        m_filterBar->show();
+    } else {
+        closeFilterBar();
+    }
+}
+
 bool DolphinViewContainer::isUrlEditable() const
 {
     return m_urlNavigator->isUrlEditable();
@@ -237,7 +258,7 @@ void DolphinViewContainer::slotDirListerCompleted()
     }
 
     updateStatusBar();
-    QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
+    QMetaObject::invokeMethod(this, "restoreContentsPos", Qt::QueuedConnection);
 
     // Enable the 'File'->'Create New...' menu only if the directory
     // supports writing.
@@ -280,67 +301,10 @@ void DolphinViewContainer::closeFilterBar()
 {
     m_filterBar->hide();
     m_filterBar->clear();
+    m_view->setFocus();
     emit showFilterBarChanged(false);
 }
 
-QString DolphinViewContainer::defaultStatusBarText() const
-{
-    int folderCount = 0;
-    int fileCount = 0;
-    m_view->calculateItemCount(fileCount, folderCount);
-    return KIO::itemsSummaryString(fileCount + folderCount,
-                                   fileCount,
-                                   folderCount,
-                                   0, false);
-}
-
-QString DolphinViewContainer::selectionStatusBarText() const
-{
-    QString text;
-    const KFileItemList list = m_view->selectedItems();
-    if (list.isEmpty()) {
-        // when an item is triggered, it is temporary selected but selectedItems()
-        // will return an empty list
-        return QString();
-    }
-
-    int fileCount = 0;
-    int folderCount = 0;
-    KIO::filesize_t byteSize = 0;
-    KFileItemList::const_iterator it = list.begin();
-    const KFileItemList::const_iterator end = list.end();
-    while (it != end) {
-        const KFileItem& item = *it;
-        if (item.isDir()) {
-            ++folderCount;
-        } else {
-            ++fileCount;
-            byteSize += item.size();
-        }
-        ++it;
-    }
-
-    if (folderCount > 0) {
-        text = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
-        if (fileCount > 0) {
-            text += ", ";
-        }
-    }
-
-    if (fileCount > 0) {
-        const QString sizeText(KIO::convertSize(byteSize));
-        text += i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText);
-    }
-
-    return text;
-}
-
-void DolphinViewContainer::showFilterBar(bool show)
-{
-    Q_ASSERT(m_filterBar != 0);
-    m_filterBar->setVisible(show);
-}
-
 void DolphinViewContainer::updateStatusBar()
 {
     // As the item count information is less important
@@ -356,7 +320,7 @@ void DolphinViewContainer::updateStatusBar()
                                      (m_statusBar->type() == DolphinStatusBar::Information)) &&
                                     (m_statusBar->progress() == 100);
 
-    const QString text(m_view->hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
+    const QString text(m_view->statusBarText());
     m_statusBar->setDefaultText(text);
 
     if (updateStatusBarMsg) {
@@ -397,7 +361,37 @@ void DolphinViewContainer::activate()
 
 void DolphinViewContainer::restoreView(const KUrl& url)
 {
-    m_view->updateView(url, m_urlNavigator->savedRootUrl());
+    if (KProtocolManager::supportsListing(url)) {
+        m_view->updateView(url, m_urlNavigator->savedRootUrl());
+        if (isActive()) {
+            // When an URL has been entered, the view should get the focus.
+            // The focus must be requested asynchronously, as changing the URL might create
+            // a new view widget. Using QTimer::singleShow() works reliable, however
+            // QMetaObject::invokeMethod() with a queued connection does not work, which might
+            // indicate that we should pass a hint to DolphinView::updateView()
+            // regarding the focus instead. To test: Enter an URL and press CTRL+Enter.
+            // Expected result: The view should get the focus.
+            QTimer::singleShot(0, this, SLOT(requestFocus()));
+        }
+    } else if (KProtocolManager::isSourceProtocol(url)) {
+        QString app = "konqueror";
+        if (url.protocol().startsWith(QLatin1String("http"))) {
+            showErrorMessage(i18nc("@info:status",
+                                   "Dolphin does not support web pages, the web browser has been launched"));
+            const KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
+            const QString browser = config.readEntry("BrowserApplication");
+            if (!browser.isEmpty()) {
+                app = browser;
+            }
+        } else {
+            showErrorMessage(i18nc("@info:status",
+                                   "Protocol not supported by Dolphin, Konqueror has been launched"));
+        }
+        const QString command = app + ' ' + url.pathOrUrl();
+        KRun::runCommand(command, app, app, this);
+    } else {
+        showErrorMessage(i18nc("@info:status", "Invalid protocol"));
+    }
 }
 
 void DolphinViewContainer::saveRootUrl(const KUrl& url)
@@ -406,6 +400,25 @@ void DolphinViewContainer::saveRootUrl(const KUrl& url)
     m_urlNavigator->saveRootUrl(m_view->rootUrl());
 }
 
+void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
+{
+    DragAndDropHelper::instance().dropUrls(KFileItem(), destination, event, this);
+}
+
+void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
+{
+    Q_UNUSED(oldUrl);
+    const bool block = m_urlNavigator->signalsBlocked();
+    m_urlNavigator->blockSignals(true);
+    m_urlNavigator->setUrl(newUrl);
+    m_urlNavigator->blockSignals(block);
+}
+
+void DolphinViewContainer::requestFocus()
+{
+    m_view->setFocus();
+}
+
 void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
 {
     KUrl url = item.targetUrl();
@@ -434,4 +447,13 @@ void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
     item.run();
 }
 
+void DolphinViewContainer::openFile(const KUrl& url)
+{
+    // Using m_dolphinModel for getting the file item instance is not possible
+    // here: openFile() is triggered by an error of the directory lister
+    // job, so the file item must be received "manually".
+    const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+    slotItemTriggered(item);
+}
+
 #include "dolphinviewcontainer.moc"