]> 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 c75553c4bab4874f1e3074a5722d8b5dc413b93b..f09d3d1c926895573bf4fc55602c31ebe250f7f7 100644 (file)
@@ -58,7 +58,7 @@
 #include "filterbar.h"
 #include "kurlnavigator.h"
 #include "viewproperties.h"
-#include "dolphinsettings.h"
+#include "settings/dolphinsettings.h"
 #include "dolphin_generalsettings.h"
 
 DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
@@ -117,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,
@@ -212,6 +214,16 @@ 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();
@@ -246,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.
@@ -289,15 +301,10 @@ void DolphinViewContainer::closeFilterBar()
 {
     m_filterBar->hide();
     m_filterBar->clear();
+    m_view->setFocus();
     emit showFilterBarChanged(false);
 }
 
-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,6 +363,16 @@ void DolphinViewContainer::restoreView(const KUrl& url)
 {
     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"))) {
@@ -397,6 +414,11 @@ void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
     m_urlNavigator->blockSignals(block);
 }
 
+void DolphinViewContainer::requestFocus()
+{
+    m_view->setFocus();
+}
+
 void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
 {
     KUrl url = item.targetUrl();
@@ -425,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"