]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Queue error messages so that a currently shown error message is not replaced until...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 31 Jan 2007 22:03:35 +0000 (22:03 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 31 Jan 2007 22:03:35 +0000 (22:03 +0000)
svn path=/trunk/playground/utils/dolphin/; revision=628905

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

index 4cdffec944e0baa511d914ef3c540c8267938bfd..26a373875ebb82f34d5a73b4ee2aacd3c8752ead 100644 (file)
@@ -71,8 +71,7 @@ DolphinStatusBar::~DolphinStatusBar()
 void DolphinStatusBar::setMessage(const QString& msg,
                                   Type type)
 {
 void DolphinStatusBar::setMessage(const QString& msg,
                                   Type type)
 {
-    m_messageLabel->setText(msg);
-    m_messageLabel->setType(type);
+    m_messageLabel->setMessage(msg, type);
 
     const int widthGap = m_messageLabel->widthGap();
     if (widthGap > 0) {
 
     const int widthGap = m_messageLabel->widthGap();
     if (widthGap > 0) {
@@ -123,25 +122,29 @@ void DolphinStatusBar::setProgress(int percent)
         QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
     }
 
         QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
     }
 
+    const QString& defaultText = m_messageLabel->defaultText();
     const QString msg(m_messageLabel->text());
     if ((percent == 0) && !msg.isEmpty()) {
         setMessage(QString::null, Default);
     }
     const QString msg(m_messageLabel->text());
     if ((percent == 0) && !msg.isEmpty()) {
         setMessage(QString::null, Default);
     }
-    else if ((percent == 100) && (msg != m_defaultText)) {
-        setMessage(m_defaultText, Default);
+    else if ((percent == 100) && (msg != defaultText)) {
+        setMessage(defaultText, Default);
     }
 }
 
 void DolphinStatusBar::clear()
 {
     }
 }
 
 void DolphinStatusBar::clear()
 {
-    // TODO: check for timeout, so that it's prevented that
-    // a message is cleared too early.
-    setMessage(m_defaultText, Default);
+    setMessage(m_messageLabel->defaultText(), Default);
 }
 
 void DolphinStatusBar::setDefaultText(const QString& text)
 {
 }
 
 void DolphinStatusBar::setDefaultText(const QString& text)
 {
-    m_defaultText = text;
+    m_messageLabel->setDefaultText(text);
+}
+
+const QString& DolphinStatusBar::defaultText() const
+{
+    return m_messageLabel->defaultText();
 }
 
 void DolphinStatusBar::resizeEvent(QResizeEvent* event)
 }
 
 void DolphinStatusBar::resizeEvent(QResizeEvent* event)
index e98e9e5126c2b4aa61ab6611e7574a6cbb05a42f..5a04b21cb8f570a8b2980251e9aedd39f90d00f5 100644 (file)
@@ -108,7 +108,7 @@ public:
      * is cleared by DolphinStatusBar::clear().
      */
     void setDefaultText(const QString& text);
      * is cleared by DolphinStatusBar::clear().
      */
     void setDefaultText(const QString& text);
-    const QString& defaultText() const { return m_defaultText; }
+    const QString& defaultText() const;
 
 protected:
     /** @see QWidget::resizeEvent() */
 
 protected:
     /** @see QWidget::resizeEvent() */
@@ -138,8 +138,6 @@ private:
     QLabel* m_progressText;
     QProgressBar* m_progressBar;
     int m_progress;
     QLabel* m_progressText;
     QProgressBar* m_progressBar;
     int m_progress;
-
-    QString m_defaultText;
 };
 
 #endif
 };
 
 #endif
index f355189fc0578c13b7d2e832e00acee9d1334622..2efcd2e7df40fa98a6b8e2dcc7fb387fbe2913eb 100644 (file)
@@ -48,69 +48,73 @@ StatusBarMessageLabel::StatusBarMessageLabel(QWidget* parent) :
     connect(m_timer, SIGNAL(timeout()),
             this, SLOT(timerDone()));
 
     connect(m_timer, SIGNAL(timeout()),
             this, SLOT(timerDone()));
 
-    m_closeButton = new QPushButton(KIcon("close"), QString::null, this);
+    m_closeButton = new QPushButton(i18n("Close"), this);
     m_closeButton->hide();
     m_closeButton->hide();
+    connect(m_closeButton, SIGNAL(clicked()),
+            this, SLOT(closeErrorMessage()));
 }
 
 StatusBarMessageLabel::~StatusBarMessageLabel()
 {
 }
 
 }
 
 StatusBarMessageLabel::~StatusBarMessageLabel()
 {
 }
 
-void StatusBarMessageLabel::setType(DolphinStatusBar::Type type)
+void StatusBarMessageLabel::setMessage(const QString& text,
+                                       DolphinStatusBar::Type type)
 {
 {
-    if ((type != m_type) || (type == DolphinStatusBar::Error)) {
-        m_type = type;
-
-        m_timer->stop();
-        m_illumination = 0;
-        m_state = Default;
-
-        const char* iconName = 0;
-        QPixmap pixmap;
-        switch (type) {
-            case DolphinStatusBar::OperationCompleted:
-                iconName = "ok";
-                m_closeButton->hide();
-                break;
-
-            case DolphinStatusBar::Information:
-                iconName = "info";
-                m_closeButton->hide();
-                break;
-
-            case DolphinStatusBar::Error:
-                iconName = "error";
-                m_timer->start(100);
-                m_state = Illuminate;
-
-                updateCloseButtonPosition();
-                m_closeButton->show();
-                break;
-
-            case DolphinStatusBar::Default:
-            default:
-                m_closeButton->hide();
-                break;
+    if (m_type == DolphinStatusBar::Error) {
+        // If an error is shown currently, other error messages get queued.
+        // Non-error messages are ignored if there are pending error messages.
+        if (type == DolphinStatusBar::Error) {
+            m_pendingMessages.append(text);
+            return;
         }
         }
+        if ((m_state != Default) || !m_pendingMessages.isEmpty()) {
+            return;
+        }
+    }
 
 
-        m_pixmap = (iconName == 0) ? QPixmap() : SmallIcon(iconName);
-        QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
-        update();
+    if ((text == m_text) && (type == m_type)) {
+        return;
     }
     }
-}
 
 
-void StatusBarMessageLabel::setText(const QString& text)
-{
-    if (text != m_text) {
-        if (m_type == DolphinStatusBar::Error) {
+    m_text = text;
+    m_type = type;
+
+    m_timer->stop();
+    m_illumination = 0;
+    m_state = Default;
+
+    const char* iconName = 0;
+    QPixmap pixmap;
+    switch (type) {
+        case DolphinStatusBar::OperationCompleted:
+            iconName = "ok";
+            m_closeButton->hide();
+            break;
+
+        case DolphinStatusBar::Information:
+            iconName = "info";
+            m_closeButton->hide();
+            break;
+
+        case DolphinStatusBar::Error:
+            iconName = "error";
             m_timer->start(100);
             m_timer->start(100);
-            m_illumination = 0;
             m_state = Illuminate;
             m_state = Illuminate;
-        }
-        m_text = text;
-        QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
-        update();
+
+            updateCloseButtonPosition();
+            m_closeButton->show();
+            break;
+
+        case DolphinStatusBar::Default:
+        default:
+            m_closeButton->hide();
+            break;
     }
     }
+
+    m_pixmap = (iconName == 0) ? QPixmap() : SmallIcon(iconName);
+    QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
+    update();
 }
 
 void StatusBarMessageLabel::setMinimumTextHeight(int min)
 }
 
 void StatusBarMessageLabel::setMinimumTextHeight(int min)
@@ -118,6 +122,7 @@ void StatusBarMessageLabel::setMinimumTextHeight(int min)
     if (min != m_minTextHeight) {
         m_minTextHeight = min;
         setMinimumHeight(min);
     if (min != m_minTextHeight) {
         m_minTextHeight = min;
         setMinimumHeight(min);
+        m_closeButton->setFixedHeight(min - borderGap() * 2);
     }
 }
 
     }
 }
 
@@ -165,6 +170,7 @@ void StatusBarMessageLabel::paintEvent(QPaintEvent* /* event */)
 void StatusBarMessageLabel::resizeEvent(QResizeEvent* event)
 {
     QWidget::resizeEvent(event);
 void StatusBarMessageLabel::resizeEvent(QResizeEvent* event)
 {
     QWidget::resizeEvent(event);
+    updateCloseButtonPosition();
     QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
 }
 
     QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
 }
 
@@ -256,7 +262,7 @@ int StatusBarMessageLabel::availableTextWidth() const
 {
     const int buttonWidth = (m_type == DolphinStatusBar::Error) ?
                             m_closeButton->width() + borderGap() : 0;
 {
     const int buttonWidth = (m_type == DolphinStatusBar::Error) ?
                             m_closeButton->width() + borderGap() : 0;
-    return width() - m_pixmap.width() - (borderGap() * 3) - buttonWidth;
+    return width() - m_pixmap.width() - (borderGap() * 4) - buttonWidth;
 }
 
 QColor StatusBarMessageLabel::mixColors(const QColor& c1,
 }
 
 QColor StatusBarMessageLabel::mixColors(const QColor& c1,
@@ -272,9 +278,33 @@ QColor StatusBarMessageLabel::mixColors(const QColor& c1,
 
 void StatusBarMessageLabel::updateCloseButtonPosition()
 {
 
 void StatusBarMessageLabel::updateCloseButtonPosition()
 {
-    const int x = width() - m_closeButton->width();
-    const int y = 2;
+    const int x = width() - m_closeButton->width() - borderGap();
+    const int y = height() - m_closeButton->height() - borderGap();
     m_closeButton->move(x, y);
 }
 
     m_closeButton->move(x, y);
 }
 
+void StatusBarMessageLabel::closeErrorMessage()
+{
+    if (!showPendingMessage()) {
+        reset();
+        setMessage(m_defaultText, DolphinStatusBar::Default);
+    }
+}
+
+bool StatusBarMessageLabel::showPendingMessage()
+{
+    if (!m_pendingMessages.isEmpty()) {
+        reset();
+        setMessage(m_pendingMessages.takeFirst(), DolphinStatusBar::Error);
+        return true;
+    }
+    return false;
+}
+
+void StatusBarMessageLabel::reset()
+{
+    m_text = QString::null;
+    m_type = DolphinStatusBar::Default;
+}
+
 #include "statusbarmessagelabel.moc"
 #include "statusbarmessagelabel.moc"
index b75e499fbf9cb878b79a86ff5b4a7a4f10b28848..154915e4cc5ebaad5dae7331350c02c83cd92aea 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <dolphinstatusbar.h>
 
 
 #include <dolphinstatusbar.h>
 
+#include <QList>
 #include <QPixmap>
 #include <QString>
 #include <QWidget>
 #include <QPixmap>
 #include <QString>
 #include <QWidget>
@@ -48,12 +49,14 @@ public:
     explicit StatusBarMessageLabel(QWidget* parent);
     virtual ~StatusBarMessageLabel();
 
     explicit StatusBarMessageLabel(QWidget* parent);
     virtual ~StatusBarMessageLabel();
 
-    void setType(DolphinStatusBar::Type type);
-    DolphinStatusBar::Type type() const { return m_type; }
+    void setMessage(const QString& text, DolphinStatusBar::Type type);
 
 
-    void setText(const QString& text);
+    DolphinStatusBar::Type type() const { return m_type; }
     const QString& text() const { return m_text; }
 
     const QString& text() const { return m_text; }
 
+    void setDefaultText(const QString& text) { m_defaultText = text; }
+    const QString& defaultText() const { return m_defaultText; }
+
     // TODO: maybe a better approach is possible with the size hint
     void setMinimumTextHeight(int min);
     int minimumTextHeight() const { return m_minTextHeight; }
     // TODO: maybe a better approach is possible with the size hint
     void setMinimumTextHeight(int min);
     int minimumTextHeight() const { return m_minTextHeight; }
@@ -92,6 +95,26 @@ private slots:
      */
     void updateCloseButtonPosition();
 
      */
     void updateCloseButtonPosition();
 
+    /**
+     * Closes the currently shown error message and replaces it
+     * by the next pending message.
+     */
+    void closeErrorMessage();
+
+private:
+    /**
+     * Shows the next pending error message. If no pending message
+     * was in the queue, false is returned.
+     */
+    bool showPendingMessage();
+
+    /**
+     * Resets the message label properties. This is useful when the
+     * result of invoking StatusBarMessageLabel::setMessage() should
+     * not rely on previous states.
+     */
+    void reset();
+
 private:
     enum State {
         Default,
 private:
     enum State {
         Default,
@@ -108,6 +131,8 @@ private:
     int m_minTextHeight;
     QTimer* m_timer;
     QString m_text;
     int m_minTextHeight;
     QTimer* m_timer;
     QString m_text;
+    QString m_defaultText;
+    QList<QString> m_pendingMessages;
     QPixmap m_pixmap;
     QPushButton* m_closeButton;
 
     QPixmap m_pixmap;
     QPushButton* m_closeButton;
 
@@ -115,7 +140,7 @@ private:
                      const QColor& c2,
                      int percent) const;
 
                      const QColor& c2,
                      int percent) const;
 
-    int borderGap() const { return 3; }
+    int borderGap() const { return 2; }
 };
 
 #endif
 };
 
 #endif
index fca7bdd0beda538f7d457f44c879c01bab5dcf94..b61cf3f45124d8e885fcb782c7a86efc5b621725 100644 (file)
@@ -59,8 +59,8 @@ void StatusBarSpaceInfo::paintEvent(QPaintEvent* /* event */)
 {
     QPainter painter(this);
     const int barWidth = width();
 {
     QPainter painter(this);
     const int barWidth = width();
-    const int barTop = 2;
-    const int barHeight = height() - 4;
+    const int barTop = 1;
+    const int barHeight = height() - 5;
 
     QString text;
 
 
     QString text;
 
@@ -98,7 +98,7 @@ void StatusBarSpaceInfo::paintEvent(QPaintEvent* /* event */)
             text = i18n("Getting size...");
         }
         else {
             text = i18n("Getting size...");
         }
         else {
-            text = "";
+            text = QString::null;
             QTimer::singleShot(0, this, SLOT(hide()));
         }
     }
             QTimer::singleShot(0, this, SLOT(hide()));
         }
     }
index 488465705c4e3c9f490697c7bcbeafc40a62cb09..bfa1156c3f6dd6b10dfc6436af63cc82ded13fa7 100644 (file)
@@ -60,7 +60,7 @@ private slots:
                              const QString& mountPoint);
     void showResult();
 
                              const QString& mountPoint);
     void showResult();
 
-    /** Refreshs the space information for the current set Url. */
+    /** Refreshs the space information for the current set URL. */
     void refresh();
 
 private:
     void refresh();
 
 private: