]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinstatusbar.cpp
Use KNewMenu instead of custom implementation of Dolphin. TODO: currently errors...
[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 const QSize size(m_progressBar->sizeHint());
55 m_progressBar->setMaximumWidth(200);
56 setMinimumHeight(size.height());
57 m_messageLabel->setMinimumTextHeight(size.height());
58
59 connect(parent, SIGNAL(urlChanged(const KUrl&)),
60 this, SLOT(updateSpaceInfo(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 m_messageLabel->setType(type);
73
74 if (type == Error) {
75 // assure that enough space is available for the error message and
76 // hide the space information and progress information
77 m_spaceInfo->hide();
78 m_progressBar->hide();
79 m_progressText->hide();
80 }
81 else if (!m_progressBar->isVisible()) {
82 m_spaceInfo->show();
83 }
84 }
85
86 DolphinStatusBar::Type DolphinStatusBar::type() const
87 {
88 return m_messageLabel->type();
89 }
90
91 QString DolphinStatusBar::message() const
92 {
93 return m_messageLabel->text();
94 }
95
96 void DolphinStatusBar::setProgressText(const QString& text)
97 {
98 m_progressText->setText(text);
99 }
100
101 QString DolphinStatusBar::progressText() const
102 {
103 return m_progressText->text();
104 }
105
106 void DolphinStatusBar::setProgress(int percent)
107 {
108 if (percent < 0) {
109 percent = 0;
110 }
111 else if (percent > 100) {
112 percent = 100;
113 }
114
115 m_progress = percent;
116 if (m_messageLabel->type() == Error) {
117 // don't update any widget or status bar text if an
118 // error message is shown
119 return;
120 }
121
122 m_progressBar->setValue(m_progress);
123 if (!m_progressBar->isVisible() || (percent == 100)) {
124 QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
125 }
126
127 const QString msg(m_messageLabel->text());
128 if ((percent == 0) && !msg.isEmpty()) {
129 setMessage(QString::null, Default);
130 }
131 else if ((percent == 100) && (msg != m_defaultText)) {
132 setMessage(m_defaultText, Default);
133 }
134 }
135
136 void DolphinStatusBar::clear()
137 {
138 // TODO: check for timeout, so that it's prevented that
139 // a message is cleared too early.
140 setMessage(m_defaultText, Default);
141 }
142
143 void DolphinStatusBar::setDefaultText(const QString& text)
144 {
145 m_defaultText = text;
146 }
147
148 void DolphinStatusBar::updateProgressInfo()
149 {
150 const bool isErrorShown = (m_messageLabel->type() == Error);
151 if (m_progress < 100) {
152 // show the progress information and hide the space information
153 m_spaceInfo->hide();
154 if (!isErrorShown) {
155 m_progressText->show();
156 m_progressBar->show();
157 }
158 }
159 else {
160 // hide the progress information and show the space information
161 m_progressText->hide();
162 m_progressBar->hide();
163 if (m_messageLabel->type() != Error) {
164 m_spaceInfo->show();
165 }
166 }
167 }
168
169 void DolphinStatusBar::updateSpaceInfo(const KUrl& url)
170 {
171 m_spaceInfo->setUrl(url);
172 }
173
174 #include "dolphinstatusbar.moc"