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