]>
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>
28 #include "dolphinview.h"
29 #include "statusbarmessagelabel.h"
30 #include "statusbarspaceinfo.h"
32 DolphinStatusBar::DolphinStatusBar(DolphinView
* parent
) :
39 m_messageLabel
= new StatusBarMessageLabel(this);
40 m_messageLabel
->setSizePolicy(QSizePolicy::Ignored
, QSizePolicy::Fixed
);
42 m_spaceInfo
= new StatusBarSpaceInfo(this);
43 m_spaceInfo
->setUrl(parent
->url());
45 m_progressText
= new QLabel(this);
46 m_progressText
->hide();
48 m_progressBar
= new QProgressBar(this);
49 m_progressBar
->hide();
51 m_progressTimer
= new QTimer(this);
52 connect(m_progressTimer
, SIGNAL(timeout()),
53 this, SLOT(slotProgressTimer()));
55 const QSize
size(m_progressBar
->sizeHint());
56 m_progressBar
->setMaximumWidth(size
.width());
57 setMinimumHeight(size
.height());
58 m_messageLabel
->setMinimumTextHeight(size
.height());
60 connect(parent
, SIGNAL(signalUrlChanged(const KUrl
&)),
61 this, SLOT(slotUrlChanged(const KUrl
&)));
65 DolphinStatusBar::~DolphinStatusBar()
69 void DolphinStatusBar::setMessage(const QString
& msg
,
72 m_messageLabel
->setText(msg
);
73 if (msg
.isEmpty() || (msg
== m_defaultText
)) {
76 m_messageLabel
->setType(type
);
78 if ((type
== Error
) && (m_progress
< 100)) {
79 // If an error message is shown during a progress is ongoing,
80 // the (never finishing) progress information should be hidden immediately
81 // (invoking 'setProgress(100)' only leads to a delayed hiding).
82 m_progressBar
->hide();
83 m_progressText
->hide();
88 DolphinStatusBar::Type
DolphinStatusBar::type() const
90 return m_messageLabel
->type();
93 QString
DolphinStatusBar::message() const
95 return m_messageLabel
->text();
98 void DolphinStatusBar::setProgressText(const QString
& text
)
100 m_progressText
->setText(text
);
103 QString
DolphinStatusBar::progressText() const
105 return m_progressText
->text();
108 void DolphinStatusBar::setProgress(int percent
)
113 else if (percent
> 100) {
117 m_progress
= percent
;
118 m_progressBar
->setValue(m_progress
);
119 m_progressTimer
->start(300, true);
121 const QString
msg(m_messageLabel
->text());
122 if (msg
.isEmpty() || (msg
== m_defaultText
)) {
124 m_messageLabel
->setText(QString::null
);
125 m_messageLabel
->setType(Default
);
127 else if (percent
== 100) {
128 m_messageLabel
->setText(m_defaultText
);
133 void DolphinStatusBar::clear()
135 // TODO: check for timeout, so that it's prevented that
136 // a message is cleared too early.
137 m_messageLabel
->setText(m_defaultText
);
138 m_messageLabel
->setType(Default
);
141 void DolphinStatusBar::setDefaultText(const QString
& text
)
143 m_defaultText
= text
;
146 void DolphinStatusBar::slotProgressTimer()
148 if (m_progress
< 100) {
149 // progress should be shown
150 m_progressBar
->show();
151 m_progressText
->show();
155 // progress should not be shown anymore
156 m_progressBar
->hide();
157 m_progressText
->hide();
162 void DolphinStatusBar::slotUrlChanged(const KUrl
& url
)
164 m_spaceInfo
->setUrl(url
);
167 #include "dolphinstatusbar.moc"