]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinstatusbar.cpp
Adapt to new konsole api
[dolphin.git] / src / dolphinstatusbar.cpp
index 6d7df45111d9185c4424889e8f33c3b5d4aaa206..e2b4e68bab0c13849d5b71fbafecf23500bfa687 100644 (file)
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
 #include "dolphinstatusbar.h"
-#include <qprogressbar.h>
-#include <qlabel.h>
-#include <qtimer.h>
-#include <kiconloader.h>
-#include <kvbox.h>
-
 #include "dolphinview.h"
 #include "statusbarmessagelabel.h"
 #include "statusbarspaceinfo.h"
 
+#include <QLabel>
+#include <QProgressBar>
+#include <QTimer>
+
+#include <kiconloader.h>
+#include <kvbox.h>
+
 DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
     KHBox(parent),
     m_messageLabel(0),
@@ -36,8 +37,10 @@ DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
     m_progressBar(0),
     m_progress(100)
 {
+    setSpacing(4);
+
     m_messageLabel = new StatusBarMessageLabel(this);
-    m_messageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
+    m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
     m_spaceInfo = new StatusBarSpaceInfo(this);
     m_spaceInfo->setUrl(parent->url());
@@ -48,41 +51,33 @@ 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(size.width());
-    setMinimumHeight(size.height());
-    m_messageLabel->setMinimumTextHeight(size.height());
+    const int barHeight = size.height();
 
-    connect(parent, SIGNAL(signalUrlChanged(const KUrl&)),
-            this, SLOT(slotUrlChanged(const KUrl&)));
+    m_progressBar->setMaximumWidth(200);
+    setMinimumHeight(barHeight);
+    m_messageLabel->setMinimumTextHeight(barHeight);
+    m_spaceInfo->setFixedHeight(barHeight);
+
+    connect(parent, SIGNAL(urlChanged(const KUrl&)),
+            this, SLOT(updateSpaceInfoContent(const KUrl&)));
 }
 
 
 DolphinStatusBar::~DolphinStatusBar()
-{
-}
+{}
 
 void DolphinStatusBar::setMessage(const QString& msg,
                                   Type type)
 {
-    m_messageLabel->setText(msg);
-    if (msg.isEmpty() || (msg == m_defaultText)) {
-        type = Default;
-    }
-    m_messageLabel->setType(type);
+    m_messageLabel->setMessage(msg, 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).
+    const int widthGap = m_messageLabel->widthGap();
+    if (widthGap > 0) {
         m_progressBar->hide();
         m_progressText->hide();
-        setProgress(100);
     }
+    showSpaceInfo();
 }
 
 DolphinStatusBar::Type DolphinStatusBar::type() const
@@ -109,60 +104,92 @@ void DolphinStatusBar::setProgress(int percent)
 {
     if (percent < 0) {
         percent = 0;
-    }
-    else if (percent > 100) {
+    } else if (percent > 100) {
         percent = 100;
     }
 
     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& defaultText = m_messageLabel->defaultText();
     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(), Default);
+    } else if ((percent == 100) && (msg != defaultText)) {
+        setMessage(defaultText, Default);
     }
 }
 
 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_messageLabel->defaultText(), Default);
 }
 
 void DolphinStatusBar::setDefaultText(const QString& text)
 {
-    m_defaultText = text;
+    m_messageLabel->setDefaultText(text);
 }
 
-void DolphinStatusBar::slotProgressTimer()
+const QString& DolphinStatusBar::defaultText() const
 {
+    return m_messageLabel->defaultText();
+}
+
+void DolphinStatusBar::resizeEvent(QResizeEvent* event)
+{
+    QWidget::resizeEvent(event);
+    QTimer::singleShot(0, this, SLOT(showSpaceInfo()));
+}
+
+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();
-    }
-    else {
-        // progress should not be shown anymore
-        m_progressBar->hide();
+        if (!isErrorShown) {
+            m_progressText->show();
+            m_progressBar->show();
+        }
+    } else {
+        // hide the progress information and show the space information
         m_progressText->hide();
-        m_spaceInfo->show();
+        m_progressBar->hide();
+        showSpaceInfo();
     }
 }
 
-void DolphinStatusBar::slotUrlChanged(const KUrl& url)
+void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url)
 {
     m_spaceInfo->setUrl(url);
+    showSpaceInfo();
+}
+
+void DolphinStatusBar::showSpaceInfo()
+{
+    const int widthGap = m_messageLabel->widthGap();
+    const bool isProgressBarVisible = m_progressBar->isVisible();
+
+    if (m_spaceInfo->isVisible()) {
+        // The space information is shown currently. Hide it
+        // if the progress bar is visible or if the status bar
+        // text does not fit into the available width.
+        const QSize size(m_progressBar->sizeHint());
+        if (isProgressBarVisible || (widthGap > 0)) {
+            m_spaceInfo->hide();
+        }
+    } else if (widthGap + m_spaceInfo->width() <= 0) {
+        m_spaceInfo->show();
+    }
 }
 
 #include "dolphinstatusbar.moc"