]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/informationpanel.cpp
The &-shortcut from another action is not set until the action has been shown at...
[dolphin.git] / src / panels / information / informationpanel.cpp
index 2d6810c88acd80f456f7ad2526d56c66c3f11779..86a7bb9990d7565433a26e2ab0925ecf296be38c 100644 (file)
  ***************************************************************************/
 
 #include "informationpanel.h"
+
+#include "informationpanelcontent.h"
+#include <kio/job.h>
 #include <kdirnotify.h>
+#include <QApplication>
 #include <QShowEvent>
 #include <QVBoxLayout>
-#include "informationpanelcontent.h"
-
-#include <kio/job.h>
 
 InformationPanel::InformationPanel(QWidget* parent) :
     Panel(parent),
@@ -52,24 +53,6 @@ QSize InformationPanel::sizeHint() const
     return size;
 }
 
-void InformationPanel::setUrl(const KUrl& url)
-{
-    Panel::setUrl(url);
-    if (url.isValid() && !isEqualToShownUrl(url)) {
-        if (isVisible()) {
-            cancelRequest();
-            m_shownUrl = url;
-            // Update the content with a delay. This gives
-            // the directory lister the chance to show the content
-            // before expensive operations are done to show
-            // meta information.
-            m_urlChangedTimer->start();
-        } else {
-            m_shownUrl = url;
-        }
-    }
-}
-
 void InformationPanel::setSelection(const KFileItemList& selection)
 {
     if (!isVisible()) {
@@ -103,29 +86,61 @@ void InformationPanel::setSelection(const KFileItemList& selection)
 
 void InformationPanel::requestDelayedItemInfo(const KFileItem& item)
 {
-    if (!isVisible()) {
+    if (!isVisible() || (item.isNull() && m_fileItem.isNull())) {
         return;
     }
 
-    cancelRequest();
+    if (QApplication::mouseButtons() & Qt::LeftButton) {
+        // Ignore the request of an item information when a rubberband
+        // selection is ongoing.
+        return;
+    }
 
-    m_fileItem = KFileItem();
     if (item.isNull()) {
         // The cursor is above the viewport. If files are selected,
         // show information regarding the selection.
         if (m_selection.size() > 0) {
+            cancelRequest();
+            m_fileItem = KFileItem();
             m_infoTimer->start();
         }
-    } else {
-        const KUrl url = item.url();
-        if (url.isValid() && !isEqualToShownUrl(url)) {
-            m_urlCandidate = item.url();
-            m_fileItem = item;
-            m_infoTimer->start();
-        }
+    } else if (item.url().isValid() && !isEqualToShownUrl(item.url())) {
+        // The cursor is above an item that is not shown currently
+        cancelRequest();
+
+        m_urlCandidate = item.url();
+        m_fileItem = item;
+        m_infoTimer->start();
     }
 }
 
+bool InformationPanel::urlChanged()
+{
+    if (!url().isValid()) {
+        return false;
+    }
+
+    if (!isVisible()) {
+        return true;
+    }
+
+    cancelRequest();
+    m_selection.clear();
+
+    if (!isEqualToShownUrl(url())) {
+        m_shownUrl = url();
+        m_fileItem = KFileItem();
+
+        // Update the content with a delay. This gives
+        // the directory lister the chance to show the content
+        // before expensive operations are done to show
+        // meta information.
+        m_urlChangedTimer->start();
+    }
+
+    return true;
+}
+
 void InformationPanel::showEvent(QShowEvent* event)
 {
     Panel::showEvent(event);
@@ -136,6 +151,8 @@ void InformationPanel::showEvent(QShowEvent* event)
             // Information Panel
             init();
         }
+
+        m_shownUrl = url();
         showItemInfo();
     }
 }
@@ -163,10 +180,11 @@ void InformationPanel::showItemInfo()
 
     cancelRequest();
 
-    if (showMultipleSelectionInfo()) {
+    if (m_fileItem.isNull() && (m_selection.count() > 1)) {
+        // The information for a selection of items should be shown
         m_content->showItems(m_selection);
-        m_shownUrl = KUrl();
     } else {
+        // The information for exactly one item should be shown
         KFileItem item;
         if (!m_fileItem.isNull()) {
             item = m_fileItem;
@@ -175,14 +193,13 @@ void InformationPanel::showItemInfo()
             item = m_selection.first();
         }
 
-        if ( item.isNull() ) {
-            // no item is hovered and no selection has been done: provide
-            // an item for the directory represented by m_shownUrl
-            m_folderStatJob = KIO::stat(m_shownUrl, KIO::HideProgressInfo);
+        if (item.isNull()) {
+            // No item is hovered and no selection has been done: provide
+            // an item for the currently shown directory.
+            m_folderStatJob = KIO::stat(url(), KIO::HideProgressInfo);
             connect(m_folderStatJob, SIGNAL(result(KJob*)),
                     this, SLOT(slotFolderStatFinished(KJob*)));
-        }
-        else {
+        } else {
             m_content->showItem(item);
         }
     }
@@ -198,6 +215,7 @@ void InformationPanel::slotFolderStatFinished(KJob* job)
 void InformationPanel::slotInfoTimeout()
 {
     m_shownUrl = m_urlCandidate;
+    m_urlCandidate.clear();
     showItemInfo();
 }
 
@@ -288,12 +306,13 @@ void InformationPanel::cancelRequest()
 {
     delete m_folderStatJob;
     m_folderStatJob = 0;
+
     m_infoTimer->stop();
-}
+    m_urlChangedTimer->stop();
+    m_resetUrlTimer->stop();
 
-bool InformationPanel::showMultipleSelectionInfo() const
-{
-    return m_fileItem.isNull() && (m_selection.count() > 1);
+    m_invalidUrlCandidate.clear();
+    m_urlCandidate.clear();
 }
 
 bool InformationPanel::isEqualToShownUrl(const KUrl& url) const