]> cloud.milkyroute.net Git - dolphin.git/commitdiff
prevent flickering of status bar when changing between directories
authorPeter Penz <peter.penz19@gmail.com>
Mon, 15 Oct 2007 16:51:23 +0000 (16:51 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 15 Oct 2007 16:51:23 +0000 (16:51 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=725546

src/statusbarspaceinfo.cpp
src/statusbarspaceinfo.h

index 9bc091b7a03ba80cf33028ed8a8e821634c76e36..fcf51cd65c1725ee76456171dc5c30e7b120a21a 100644 (file)
 
 StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget* parent) :
     QProgressBar(parent),
+    m_gettingSize(false),
     m_text()
 {
+    setMinimum(0);
+    setMaximum(0);
+
     setMaximumWidth(200);
 
     // Update the space information each 10 seconds. Polling is useful
@@ -49,7 +53,6 @@ void StatusBarSpaceInfo::setUrl(const KUrl& url)
 {
     m_url = url;
     refresh();
-    QTimer::singleShot(300, this, SLOT(update()));
 }
 
 QString StatusBarSpaceInfo::text() const
@@ -62,14 +65,17 @@ void StatusBarSpaceInfo::slotFoundMountPoint(const QString& mountPoint,
                                              quint64 kBUsed,
                                              quint64 kBAvailable)
 {
-    Q_UNUSED(kBUsed);
+    Q_UNUSED(kBSize);
     Q_UNUSED(mountPoint);
 
-    m_text = i18nc("@info:status", "%1 free", KIO::convertSizeFromKiB(kBAvailable));
-
-    setMinimum(0);
-    setMaximum(kBAvailable);
-    setValue(kBUsed);
+    m_gettingSize = false;
+    const bool valuesChanged = (kBUsed != static_cast<quint64>(value())) ||
+                               (kBAvailable != static_cast<quint64>(maximum()));
+    if (valuesChanged) {
+        setMaximum(kBAvailable);
+        setValue(kBUsed);
+        m_text = i18nc("@info:status", "%1 free", KIO::convertSizeFromKiB(kBAvailable));
+    }
 }
 
 void StatusBarSpaceInfo::refresh()
@@ -79,15 +85,12 @@ void StatusBarSpaceInfo::refresh()
         return;
     }
 
-    m_text = i18nc("@info:status", "Getting size...");
-    setMinimum(0);
-    setMaximum(0);
-
     KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(m_url.path());
     if (!mp) {
         return;
     }
 
+    m_gettingSize = true;
     KDiskFreeSpace* job = new KDiskFreeSpace(this);
     connect(job, SIGNAL(foundMountPoint(const QString&,
                                         quint64,
@@ -99,6 +102,21 @@ void StatusBarSpaceInfo::refresh()
                                            quint64)));
 
     job->readDF(mp->mountPoint());
+
+    // refresh() is invoked for each directory change. Usually getting
+    // the size information can be done very fast, so to prevent any
+    // flickering the "Getting size..." indication is only shown if
+    // at least 300 ms have been passed.
+    QTimer::singleShot(300, this, SLOT(showGettingSizeInfo()));
+}
+
+void StatusBarSpaceInfo::showGettingSizeInfo()
+{
+    if (m_gettingSize) {
+        m_text = i18nc("@info:status", "Getting size...");
+        setMinimum(0);
+        setMaximum(0);
+    }
 }
 
 #include "statusbarspaceinfo.moc"
index 02e36698b640b4f26eb370eef2b4fcd6d0265d0b..b50d14c4dd715f3a2f1f8581d29b99565c1ac965 100644 (file)
@@ -56,7 +56,10 @@ private slots:
     /** Refreshes the space information for the current set URL. */
     void refresh();
 
+    void showGettingSizeInfo();
+
 private:
+    bool m_gettingSize;
     KUrl m_url;
     QString m_text;
 };