]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinstatusbar.cpp
Use a QLinkedList instead of Q3PtrList
[dolphin.git] / src / dolphinstatusbar.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
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. *
9 * *
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. *
14 * *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "dolphinstatusbar.h"
22 #include "dolphinview.h"
23 #include "statusbarmessagelabel.h"
24 #include "statusbarspaceinfo.h"
25
26 #include <QLabel>
27 #include <QProgressBar>
28 #include <QTimer>
29
30 #include <kiconloader.h>
31 #include <kvbox.h>
32
33 DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
34 KHBox(parent),
35 m_messageLabel(0),
36 m_spaceInfo(0),
37 m_progressBar(0),
38 m_progress(100)
39 {
40 setSpacing(4);
41
42 m_messageLabel = new StatusBarMessageLabel(this);
43 m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
44
45 m_spaceInfo = new StatusBarSpaceInfo(this);
46 m_spaceInfo->setUrl(parent->url());
47
48 m_progressText = new QLabel(this);
49 m_progressText->hide();
50
51 m_progressBar = new QProgressBar(this);
52 m_progressBar->hide();
53
54 m_progressTimer = new QTimer(this);
55 connect(m_progressTimer, SIGNAL(timeout()),
56 this, SLOT(slotProgressTimer()));
57
58 const QSize size(m_progressBar->sizeHint());
59 m_progressBar->setMaximumWidth(200);
60 setMinimumHeight(size.height());
61 m_messageLabel->setMinimumTextHeight(size.height());
62
63 connect(parent, SIGNAL(signalUrlChanged(const KUrl&)),
64 this, SLOT(slotUrlChanged(const KUrl&)));
65 }
66
67
68 DolphinStatusBar::~DolphinStatusBar()
69 {
70 }
71
72 void DolphinStatusBar::setMessage(const QString& msg,
73 Type type)
74 {
75 m_messageLabel->setText(msg);
76 if (msg.isEmpty() || (msg == m_defaultText)) {
77 type = Default;
78 }
79 m_messageLabel->setType(type);
80
81 if ((type == Error) && (m_progress < 100)) {
82 // If an error message is shown during a progress is ongoing,
83 // the (never finishing) progress information should be hidden immediately
84 // (invoking 'setProgress(100)' only leads to a delayed hiding).
85 m_progressBar->hide();
86 m_progressText->hide();
87 setProgress(100);
88 }
89 }
90
91 DolphinStatusBar::Type DolphinStatusBar::type() const
92 {
93 return m_messageLabel->type();
94 }
95
96 QString DolphinStatusBar::message() const
97 {
98 return m_messageLabel->text();
99 }
100
101 void DolphinStatusBar::setProgressText(const QString& text)
102 {
103 m_progressText->setText(text);
104 }
105
106 QString DolphinStatusBar::progressText() const
107 {
108 return m_progressText->text();
109 }
110
111 void DolphinStatusBar::setProgress(int percent)
112 {
113 if (percent < 0) {
114 percent = 0;
115 }
116 else if (percent > 100) {
117 percent = 100;
118 }
119
120 m_progress = percent;
121 m_progressBar->setValue(m_progress);
122 m_progressTimer->setSingleShot(true);
123 m_progressTimer->start(300);
124
125 const QString msg(m_messageLabel->text());
126 if (msg.isEmpty() || (msg == m_defaultText)) {
127 if (percent == 0) {
128 m_messageLabel->setText(QString::null);
129 m_messageLabel->setType(Default);
130 }
131 else if (percent == 100) {
132 m_messageLabel->setText(m_defaultText);
133 }
134 }
135 }
136
137 void DolphinStatusBar::clear()
138 {
139 // TODO: check for timeout, so that it's prevented that
140 // a message is cleared too early.
141 m_messageLabel->setText(m_defaultText);
142 m_messageLabel->setType(Default);
143 }
144
145 void DolphinStatusBar::setDefaultText(const QString& text)
146 {
147 m_defaultText = text;
148 }
149
150 void DolphinStatusBar::slotProgressTimer()
151 {
152 if (m_progress < 100) {
153 // progress should be shown
154 m_progressBar->show();
155 m_progressText->show();
156 m_spaceInfo->hide();
157 }
158 else {
159 // progress should not be shown anymore
160 m_progressBar->hide();
161 m_progressText->hide();
162 m_spaceInfo->show();
163 }
164 }
165
166 void DolphinStatusBar::slotUrlChanged(const KUrl& url)
167 {
168 m_spaceInfo->setUrl(url);
169 }
170
171 #include "dolphinstatusbar.moc"