]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Minor adjustments and cleanups in the statusbar:
authorPeter Penz <peter.penz19@gmail.com>
Tue, 23 Jan 2007 18:33:43 +0000 (18:33 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 23 Jan 2007 18:33:43 +0000 (18:33 +0000)
- prevent a flickering of the space information if a folder has been changed
- assure that no progress bar and space information is shown if an error is displayed currently

svn path=/trunk/playground/utils/dolphin/; revision=626571

src/dolphinstatusbar.cpp
src/dolphinstatusbar.h
src/statusbarspaceinfo.cpp
src/statusbarspaceinfo.h

index 82cb09e110b20d104d7c5eda572364618c2726fc..a112a1f64625f37f33aec525b002834f2fc1702b 100644 (file)
@@ -51,17 +51,13 @@ DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
     m_progressBar = new QProgressBar(this);
     m_progressBar->hide();
 
-    m_progressTimer = new QTimer(this);
-    connect(m_progressTimer, SIGNAL(timeout()),
-            this, SLOT(slotProgressTimer()));
-
     const QSize size(m_progressBar->sizeHint());
     m_progressBar->setMaximumWidth(200);
     setMinimumHeight(size.height());
     m_messageLabel->setMinimumTextHeight(size.height());
 
     connect(parent, SIGNAL(urlChanged(const KUrl&)),
-            this, SLOT(slotUrlChanged(const KUrl&)));
+            this, SLOT(updateSpaceInfo(const KUrl&)));
 }
 
 
@@ -73,18 +69,17 @@ void DolphinStatusBar::setMessage(const QString& msg,
                                   Type type)
 {
     m_messageLabel->setText(msg);
-    if (msg.isEmpty() || (msg == m_defaultText)) {
-        type = Default;
-    }
     m_messageLabel->setType(type);
 
-    if ((type == Error) && (m_progress < 100)) {
-        // If an error message is shown during a progress is ongoing,
-        // the (never finishing) progress information should be hidden immediately
-        // (invoking 'setProgress(100)' only leads to a delayed hiding).
+    if (type == Error) {
+        // assure that enough space is available for the error message and
+        // hide the space information and progress information
+        m_spaceInfo->hide();
         m_progressBar->hide();
         m_progressText->hide();
-        setProgress(100);
+    }
+    else if (!m_progressBar->isVisible()) {
+        m_spaceInfo->show();
     }
 }
 
@@ -118,19 +113,23 @@ void DolphinStatusBar::setProgress(int percent)
     }
 
     m_progress = percent;
+    if (m_messageLabel->type() == Error) {
+        // don't update any widget or status bar text if an
+        // error message is shown
+        return;
+    }
+
     m_progressBar->setValue(m_progress);
-    m_progressTimer->setSingleShot(true);
-    m_progressTimer->start(300);
+    if (!m_progressBar->isVisible() || (percent == 100)) {
+        QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
+    }
 
     const QString msg(m_messageLabel->text());
-    if (msg.isEmpty() || (msg == m_defaultText)) {
-        if (percent == 0) {
-            m_messageLabel->setText(QString::null);
-            m_messageLabel->setType(Default);
-        }
-        else if (percent == 100) {
-            m_messageLabel->setText(m_defaultText);
-        }
+    if ((percent == 0) && !msg.isEmpty()) {
+        setMessage(QString::null, Default);
+    }
+    else if ((percent == 100) && (msg != m_defaultText)) {
+        setMessage(m_defaultText, Default);
     }
 }
 
@@ -138,8 +137,7 @@ void DolphinStatusBar::clear()
 {
     // TODO: check for timeout, so that it's prevented that
     // a message is cleared too early.
-    m_messageLabel->setText(m_defaultText);
-    m_messageLabel->setType(Default);
+    setMessage(m_defaultText, Default);
 }
 
 void DolphinStatusBar::setDefaultText(const QString& text)
@@ -147,23 +145,28 @@ void DolphinStatusBar::setDefaultText(const QString& text)
     m_defaultText = text;
 }
 
-void DolphinStatusBar::slotProgressTimer()
+void DolphinStatusBar::updateProgressInfo()
 {
+    const bool isErrorShown = (m_messageLabel->type() == Error);
     if (m_progress < 100) {
-        // progress should be shown
-        m_progressBar->show();
-        m_progressText->show();
+        // show the progress information and hide the space information
         m_spaceInfo->hide();
+        if (!isErrorShown) {
+            m_progressText->show();
+            m_progressBar->show();
+        }
     }
     else {
-        // progress should not be shown anymore
-        m_progressBar->hide();
+        // hide the progress information and show the space information
         m_progressText->hide();
-        m_spaceInfo->show();
+        m_progressBar->hide();
+        if (m_messageLabel->type() != Error) {
+            m_spaceInfo->show();
+        }
     }
 }
 
-void DolphinStatusBar::slotUrlChanged(const KUrl& url)
+void DolphinStatusBar::updateSpaceInfo(const KUrl& url)
 {
     m_spaceInfo->setUrl(url);
 }
index 7dea4c35c44568ba7ce50ff32752205a3a261b9c..445419c3fdc4cece814177b19262714e7b5a6b67 100644 (file)
 #ifndef DOLPHINSTATUSBAR_H
 #define DOLPHINSTATUSBAR_H
 
-
-//Added by qt3to4:
-#include <QLabel>
 #include <khbox.h>
+
+class DolphinView;
+class KUrl;
+class StatusBarMessageLabel;
+class StatusBarSpaceInfo;
 class QProgressBar;
 class QLabel;
 class QTimer;
-class StatusBarMessageLabel;
-class StatusBarSpaceInfo;
-class DolphinView;
-class KUrl;
 
 /**
  * @brief Represents the statusbar of a Dolphin view.
@@ -70,8 +68,8 @@ public:
      * is cleared automatically.
      */
     void setMessage(const QString& msg, Type type);
-
     QString message() const;
+
     Type type() const;
 
     /**
@@ -113,21 +111,23 @@ public:
     const QString& defaultText() const { return m_defaultText; }
 
 private slots:
-    void slotProgressTimer();
+    void updateProgressInfo();
 
     /**
-     * Is invoked, when the Url of the DolphinView, where the
-     * statusbar belongs too, has been changed.
+     * Is invoked, when the URL of the DolphinView, where the
+     * statusbar belongs too, has been changed. The space information
+     * is updated.
      */
-    void slotUrlChanged(const KUrl& url);
+    void updateSpaceInfo(const KUrl& url);
 
 private:
     StatusBarMessageLabel* m_messageLabel;
     StatusBarSpaceInfo* m_spaceInfo;
+
     QLabel* m_progressText;
     QProgressBar* m_progressBar;
-    QTimer* m_progressTimer;
     int m_progress;
+
     QString m_defaultText;
 };
 
index ce8a2519bd39136c4613d45a9d912e09fa950bb9..bccda6e68d7fb6622f9b135a3f146ecc7cece75c 100644 (file)
@@ -52,7 +52,7 @@ void StatusBarSpaceInfo::setUrl(const KUrl& url)
 {
     m_url = url;
     refresh();
-    update();
+    QTimer::singleShot(300, this, SLOT(update()));
 }
 
 void StatusBarSpaceInfo::paintEvent(QPaintEvent* /* event */)
index 1a1b7b26a3f765a92783064d2c5d02e491b84f3b..6db2cc87851249901e147295e50d0139e4df769a 100644 (file)
 #ifndef STATUSBARSPACEINFO_H
 #define STATUSBARSPACEINFO_H
 
-#include <qwidget.h>
-#include <qstring.h>
-//Added by qt3to4:
-#include <QPaintEvent>
 #include <kurl.h>
 #include <qcolor.h>
 
+#include <QPaintEvent>
+#include <QWidget>
+
 class KDiskFreeSp;
+class QTimer;
 
 /**
- * @short Shows the available space for the current volume as part
- *        of the status bar.
+ * @short Shows the available space for the volume represented
+ *        by the given URL as part of the status bar.
  */
 class StatusBarSpaceInfo : public QWidget
 {
@@ -45,7 +45,7 @@ public:
     const KUrl& url() const { return m_url; }
 
 protected:
-    /** @see QWidget::paintEvent */
+    /** @see QWidget::paintEvent() */
     virtual void paintEvent(QPaintEvent* event);
 
 private slots:
@@ -71,11 +71,11 @@ private:
      */
     QColor progressColor(const QColor& bgColor) const;
 
+private:
     KUrl m_url;
     bool m_gettingSize;
     unsigned long m_kBSize;
     unsigned long m_kBAvailable;
-
 };
 
 #endif