]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinstatusbar.cpp
commited initial version of Dolphin
[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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "dolphinstatusbar.h"
22 #include <qprogressbar.h>
23 #include <qlabel.h>
24 #include <qtimer.h>
25 #include <kiconloader.h>
26
27 #include "dolphinview.h"
28 #include "statusbarmessagelabel.h"
29 #include "statusbarspaceinfo.h"
30
31 DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
32 Q3HBox(parent),
33 m_messageLabel(0),
34 m_spaceInfo(0),
35 m_progressBar(0),
36 m_progress(100)
37 {
38 m_messageLabel = new StatusBarMessageLabel(this);
39 m_messageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
40
41 m_spaceInfo = new StatusBarSpaceInfo(this);
42 m_spaceInfo->setURL(parent->url());
43
44 m_progressText = new QLabel(this);
45 m_progressText->hide();
46
47 m_progressBar = new QProgressBar(this);
48 m_progressBar->hide();
49
50 m_progressTimer = new QTimer(this);
51 connect(m_progressTimer, SIGNAL(timeout()),
52 this, SLOT(slotProgressTimer()));
53
54 const QSize size(m_progressBar->sizeHint());
55 m_progressBar->setMaximumWidth(size.width());
56 setMinimumHeight(size.height());
57 m_messageLabel->setMinimumTextHeight(size.height());
58
59 connect(parent, SIGNAL(signalURLChanged(const KUrl&)),
60 this, SLOT(slotURLChanged(const KUrl&)));
61 }
62
63
64 DolphinStatusBar::~DolphinStatusBar()
65 {
66 }
67
68 void DolphinStatusBar::setMessage(const QString& msg,
69 Type type)
70 {
71 m_messageLabel->setText(msg);
72 if (msg.isEmpty() || (msg == m_defaultText)) {
73 type = Default;
74 }
75 m_messageLabel->setType(type);
76
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();
83 setProgress(100);
84 }
85 }
86
87 DolphinStatusBar::Type DolphinStatusBar::type() const
88 {
89 return m_messageLabel->type();
90 }
91
92 QString DolphinStatusBar::message() const
93 {
94 return m_messageLabel->text();
95 }
96
97 void DolphinStatusBar::setProgressText(const QString& text)
98 {
99 m_progressText->setText(text);
100 }
101
102 QString DolphinStatusBar::progressText() const
103 {
104 return m_progressText->text();
105 }
106
107 void DolphinStatusBar::setProgress(int percent)
108 {
109 if (percent < 0) {
110 percent = 0;
111 }
112 else if (percent > 100) {
113 percent = 100;
114 }
115
116 m_progress = percent;
117 m_progressBar->setValue(m_progress);
118 m_progressTimer->start(300, true);
119
120 const QString msg(m_messageLabel->text());
121 if (msg.isEmpty() || (msg == m_defaultText)) {
122 if (percent == 0) {
123 m_messageLabel->setText(QString::null);
124 m_messageLabel->setType(Default);
125 }
126 else if (percent == 100) {
127 m_messageLabel->setText(m_defaultText);
128 }
129 }
130 }
131
132 void DolphinStatusBar::clear()
133 {
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);
138 }
139
140 void DolphinStatusBar::setDefaultText(const QString& text)
141 {
142 m_defaultText = text;
143 }
144
145 void DolphinStatusBar::slotProgressTimer()
146 {
147 if (m_progress < 100) {
148 // progress should be shown
149 m_progressBar->show();
150 m_progressText->show();
151 m_spaceInfo->hide();
152 }
153 else {
154 // progress should not be shown anymore
155 m_progressBar->hide();
156 m_progressText->hide();
157 m_spaceInfo->show();
158 }
159 }
160
161 void DolphinStatusBar::slotURLChanged(const KUrl& url)
162 {
163 m_spaceInfo->setURL(url);
164 }
165
166 #include "dolphinstatusbar.moc"