]> cloud.milkyroute.net Git - dolphin.git/commitdiff
do only a polling of the available space when the widget is visible
authorPeter Penz <peter.penz19@gmail.com>
Sun, 5 Oct 2008 21:13:50 +0000 (21:13 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 5 Oct 2008 21:13:50 +0000 (21:13 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=868270

src/statusbarspaceinfo.cpp
src/statusbarspaceinfo.h

index a311902f77c76c907541581412eda95bde7c3874..ba37a82a585feea13b994146b585c18a55dade26 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,26 @@ void StatusBarSpaceInfo::setUrl(const KUrl& url)
     refresh();
 }
 
+void StatusBarSpaceInfo::showEvent(QShowEvent* event)
+{
+    KCapacityBar::showEvent(event);
+    if (!event->spontaneous()) {
+        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"));
index 839c74e1af8a45de0393778f0732b25c9c74b3c4..7a9fae36d002a6166ba3d4ace8ea6c8ce23a2b99 100644 (file)
@@ -29,6 +29,8 @@
 #include <kcapacitybar.h>
 
 class KDiskFreeSp;
+class QHideEvent;
+class QShowEvent;
 
 /**
  * @short Shows the available space for the volume represented
@@ -45,6 +47,10 @@ public:
     void setUrl(const KUrl& url);
     const KUrl& url() const;
 
+protected:
+    void showEvent(QShowEvent* event);
+    void hideEvent(QHideEvent* event);
+    
 private slots:
     /** Refreshes the space information for the current set URL. */
     void refresh();
@@ -52,6 +58,7 @@ private slots:
 private:
     quint64 m_kBSize;
     KUrl m_url;
+    QTimer* m_timer;
 };
 
 inline const KUrl& StatusBarSpaceInfo::url() const