]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinstatusbar.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "dolphinstatusbar.h"
22 #include <qprogressbar.h>
25 #include <kiconloader.h>
27 #include "dolphinview.h"
28 #include "statusbarmessagelabel.h"
29 #include "statusbarspaceinfo.h"
31 DolphinStatusBar::DolphinStatusBar(DolphinView
* parent
) :
38 m_messageLabel
= new StatusBarMessageLabel(this);
39 m_messageLabel
->setSizePolicy(QSizePolicy::Ignored
, QSizePolicy::Fixed
);
41 m_spaceInfo
= new StatusBarSpaceInfo(this);
42 m_spaceInfo
->setURL(parent
->url());
44 m_progressText
= new QLabel(this);
45 m_progressText
->hide();
47 m_progressBar
= new QProgressBar(this);
48 m_progressBar
->hide();
50 m_progressTimer
= new QTimer(this);
51 connect(m_progressTimer
, SIGNAL(timeout()),
52 this, SLOT(slotProgressTimer()));
54 const QSize
size(m_progressBar
->sizeHint());
55 m_progressBar
->setMaximumWidth(size
.width());
56 setMinimumHeight(size
.height());
57 m_messageLabel
->setMinimumTextHeight(size
.height());
59 connect(parent
, SIGNAL(signalURLChanged(const KUrl
&)),
60 this, SLOT(slotURLChanged(const KUrl
&)));
64 DolphinStatusBar::~DolphinStatusBar()
68 void DolphinStatusBar::setMessage(const QString
& msg
,
71 m_messageLabel
->setText(msg
);
72 if (msg
.isEmpty() || (msg
== m_defaultText
)) {
75 m_messageLabel
->setType(type
);
77 if ((type
== Error
) && (m_progress
< 100)) {
78 // If an error message is shown during a progress is ongoing,
79 // the (never finishing) progress information should be hidden immediately
80 // (invoking 'setProgress(100)' only leads to a delayed hiding).
81 m_progressBar
->hide();
82 m_progressText
->hide();
87 DolphinStatusBar::Type
DolphinStatusBar::type() const
89 return m_messageLabel
->type();
92 QString
DolphinStatusBar::message() const
94 return m_messageLabel
->text();
97 void DolphinStatusBar::setProgressText(const QString
& text
)
99 m_progressText
->setText(text
);
102 QString
DolphinStatusBar::progressText() const
104 return m_progressText
->text();
107 void DolphinStatusBar::setProgress(int percent
)
112 else if (percent
> 100) {
116 m_progress
= percent
;
117 m_progressBar
->setValue(m_progress
);
118 m_progressTimer
->start(300, true);
120 const QString
msg(m_messageLabel
->text());
121 if (msg
.isEmpty() || (msg
== m_defaultText
)) {
123 m_messageLabel
->setText(QString::null
);
124 m_messageLabel
->setType(Default
);
126 else if (percent
== 100) {
127 m_messageLabel
->setText(m_defaultText
);
132 void DolphinStatusBar::clear()
134 // TODO: check for timeout, so that it's prevented that
135 // a message is cleared too early.
136 m_messageLabel
->setText(m_defaultText
);
137 m_messageLabel
->setType(Default
);
140 void DolphinStatusBar::setDefaultText(const QString
& text
)
142 m_defaultText
= text
;
145 void DolphinStatusBar::slotProgressTimer()
147 if (m_progress
< 100) {
148 // progress should be shown
149 m_progressBar
->show();
150 m_progressText
->show();
154 // progress should not be shown anymore
155 m_progressBar
->hide();
156 m_progressText
->hide();
161 void DolphinStatusBar::slotURLChanged(const KUrl
& url
)
163 m_spaceInfo
->setURL(url
);
166 #include "dolphinstatusbar.moc"