]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/statusbarspaceinfo.cpp
Improve the performance of the code part which checks which items are visible. Althou...
[dolphin.git] / src / statusbarspaceinfo.cpp
index 8da3dc9472c3f0a283b0be17109cc228419bee99..c674a387a5c1a96d0bae3e850e9e871286c83016 100644 (file)
@@ -31,6 +31,7 @@
 StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget* parent) :
     QProgressBar(parent),
     m_gettingSize(false),
+    m_foundMountPoint(false),
     m_text()
 {
     setMinimum(0);
@@ -65,17 +66,32 @@ void StatusBarSpaceInfo::slotFoundMountPoint(const QString& mountPoint,
                                              quint64 kBUsed,
                                              quint64 kBAvailable)
 {
-    Q_UNUSED(kBSize);
     Q_UNUSED(mountPoint);
 
     m_gettingSize = false;
+    m_foundMountPoint = true;
     const bool valuesChanged = (kBUsed != static_cast<quint64>(value())) ||
-                               (kBAvailable != static_cast<quint64>(maximum()));
+                               (kBSize != static_cast<quint64>(maximum()));
     if (valuesChanged) {
-        m_text = i18nc("@info:status Free disk space", "%1 free", KIO::convertSizeFromKiB(kBAvailable));
+        m_text = i18nc("@info:status Free disk space", "%1 free", KIO::convertSize(kBAvailable * 1024));
+        setUpdatesEnabled(false);
         setMaximum(kBSize);
         setValue(kBUsed);
+        setUpdatesEnabled(true);
+        update();
+    }
+}
+
+void StatusBarSpaceInfo::slotDiskFreeSpaceDone()
+{
+    if (m_foundMountPoint) {
+        return;
     }
+
+    m_gettingSize = false;
+    m_text = i18nc("@info:status", "Unknown size");
+    setValue(0);
+    update();
 }
 
 void StatusBarSpaceInfo::refresh()
@@ -83,6 +99,7 @@ void StatusBarSpaceInfo::refresh()
     // KDiskFreeSpace is for local paths only
     if (!m_url.isLocalFile()) {
         m_text = i18nc("@info:status", "Unknown size");
+        setValue(0);
         update();
         return;
     }
@@ -93,6 +110,7 @@ void StatusBarSpaceInfo::refresh()
     }
 
     m_gettingSize = true;
+    m_foundMountPoint = false;
     KDiskFreeSpace* job = new KDiskFreeSpace(this);
     connect(job, SIGNAL(foundMountPoint(const QString&,
                                         quint64,
@@ -102,6 +120,7 @@ void StatusBarSpaceInfo::refresh()
                                            quint64,
                                            quint64,
                                            quint64)));
+    connect(job, SIGNAL(done()), this, SLOT(slotDiskFreeSpaceDone()));
 
     job->readDF(mp->mountPoint());
 
@@ -116,9 +135,8 @@ void StatusBarSpaceInfo::showGettingSizeInfo()
 {
     if (m_gettingSize) {
         m_text = i18nc("@info:status", "Getting size...");
-        update();
-        setMinimum(0);
         setMaximum(0);
+        update();
     }
 }