]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/statusbarspaceinfo.cpp
The feature freeze is near: Add video support to the Information Panel. Phonon is...
[dolphin.git] / src / statusbarspaceinfo.cpp
index a311902f77c76c907541581412eda95bde7c3874..c9173b8f9ef2feee26d18ca34c8ed2dbda5cbe7b 100644 (file)
 
 StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget* parent) :
     KCapacityBar(KCapacityBar::DrawTextInline, parent),
-    m_kBSize(0)
+    m_kBSize(0),
+    m_timer(0)
 {
     setMaximumWidth(200);
     setMinimumWidth(200); // something to fix on kcapacitybar (ereslibre)
 
-    // Update the space information each 10 seconds. Polling is useful
+    // Use a timer to update the space information. Polling is useful
     // here, as files can be deleted/added outside the scope of Dolphin.
-    QTimer* timer = new QTimer(this);
-    connect(timer, SIGNAL(timeout()), this, SLOT(refresh()));
-    timer->start(10000);
+    m_timer = new QTimer(this);
+    connect(m_timer, SIGNAL(timeout()), this, SLOT(refresh()));
 }
 
 StatusBarSpaceInfo::~StatusBarSpaceInfo()
@@ -52,8 +52,27 @@ void StatusBarSpaceInfo::setUrl(const KUrl& url)
     refresh();
 }
 
+void StatusBarSpaceInfo::showEvent(QShowEvent* event)
+{
+    KCapacityBar::showEvent(event);
+    if (!event->spontaneous()) {
+        refresh();
+        m_timer->start(10000);
+    }
+}
+
+void StatusBarSpaceInfo::hideEvent(QHideEvent* event)
+{
+    m_timer->stop();
+    KCapacityBar::hideEvent(event);
+}
+
 void StatusBarSpaceInfo::refresh()
 {
+    if (!isVisible()) {
+        return;
+    }
+
     // KDiskFreeSpace is for local paths only
     if (!m_url.isLocalFile()) {
         setText(i18nc("@info:status", "Unknown size"));
@@ -62,7 +81,7 @@ void StatusBarSpaceInfo::refresh()
         return;
     }
 
-    KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(m_url.path());
+    KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(m_url.toLocalFile());
     if (!mp) {
         return;
     }
@@ -82,7 +101,7 @@ void StatusBarSpaceInfo::refresh()
     if (valuesChanged) {
         setText(i18nc("@info:status Free disk space", "%1 free",
                 KIO::convertSize(job.available())));
-        
+
         setUpdatesEnabled(false);
         m_kBSize = kBSize;
         setValue(kBSize > 0 ? (kBUsed * 100) / kBSize : 0);