]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinstatusbar.cpp
Use Xesam ontology instead of NIE. Since Strigi uses Xesam and we have no mapping...
[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 <QtGui/QLabel>
27 #include <QtGui/QProgressBar>
28 #include <QtCore/QTimer>
29
30 #include <kiconloader.h>
31 #include <kvbox.h>
32
33 DolphinStatusBar::DolphinStatusBar(QWidget* parent, const KUrl& url) :
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(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 int contentHeight = QFontMetrics(m_messageLabel->font()).height();
55 const int barHeight = contentHeight + 8;
56
57 setMinimumHeight(barHeight);
58 m_messageLabel->setMinimumTextHeight(barHeight);
59 m_spaceInfo->setFixedHeight(contentHeight);
60 m_progressBar->setFixedHeight(contentHeight);
61 m_progressBar->setMaximumWidth(200);
62 }
63
64
65 DolphinStatusBar::~DolphinStatusBar()
66 {
67 }
68
69 void DolphinStatusBar::setMessage(const QString& msg,
70 Type type)
71 {
72 m_messageLabel->setMessage(msg, type);
73
74 const int widthGap = m_messageLabel->widthGap();
75 if (widthGap > 0) {
76 m_progressBar->hide();
77 m_progressText->hide();
78 }
79 showSpaceInfo();
80 }
81
82 DolphinStatusBar::Type DolphinStatusBar::type() const
83 {
84 return m_messageLabel->type();
85 }
86
87 QString DolphinStatusBar::message() const
88 {
89 return m_messageLabel->text();
90 }
91
92 void DolphinStatusBar::setProgressText(const QString& text)
93 {
94 m_progressText->setText(text);
95 }
96
97 QString DolphinStatusBar::progressText() const
98 {
99 return m_progressText->text();
100 }
101
102 void DolphinStatusBar::setProgress(int percent)
103 {
104 if (percent < 0) {
105 percent = 0;
106 } else if (percent > 100) {
107 percent = 100;
108 }
109
110 m_progress = percent;
111 if (m_messageLabel->type() == Error) {
112 // don't update any widget or status bar text if an
113 // error message is shown
114 return;
115 }
116
117 m_progressBar->setValue(m_progress);
118 if (!m_progressBar->isVisible() || (percent == 100)) {
119 QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
120 }
121
122 const QString& defaultText = m_messageLabel->defaultText();
123 const QString msg(m_messageLabel->text());
124 if ((percent == 0) && !msg.isEmpty()) {
125 setMessage(QString(), Default);
126 } else if ((percent == 100) && (msg != defaultText)) {
127 setMessage(defaultText, Default);
128 }
129 }
130
131 void DolphinStatusBar::clear()
132 {
133 setMessage(m_messageLabel->defaultText(), Default);
134 }
135
136 void DolphinStatusBar::setDefaultText(const QString& text)
137 {
138 m_messageLabel->setDefaultText(text);
139 }
140
141 const QString& DolphinStatusBar::defaultText() const
142 {
143 return m_messageLabel->defaultText();
144 }
145
146 void DolphinStatusBar::resizeEvent(QResizeEvent* event)
147 {
148 QWidget::resizeEvent(event);
149 QMetaObject::invokeMethod(this, "showSpaceInfo", Qt::QueuedConnection);
150 }
151
152 void DolphinStatusBar::updateProgressInfo()
153 {
154 const bool isErrorShown = (m_messageLabel->type() == Error);
155 if (m_progress < 100) {
156 // show the progress information and hide the space information
157 m_spaceInfo->hide();
158 if (!isErrorShown) {
159 m_progressText->show();
160 m_progressBar->show();
161 }
162 } else {
163 // hide the progress information and show the space information
164 m_progressText->hide();
165 m_progressBar->hide();
166 showSpaceInfo();
167 }
168 }
169
170 void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url)
171 {
172 m_spaceInfo->setUrl(url);
173 showSpaceInfo();
174 }
175
176 void DolphinStatusBar::showSpaceInfo()
177 {
178 const int widthGap = m_messageLabel->widthGap();
179 const bool isProgressBarVisible = m_progressBar->isVisible();
180
181 if (m_spaceInfo->isVisible()) {
182 // The space information is shown currently. Hide it
183 // if the progress bar is visible or if the status bar
184 // text does not fit into the available width.
185 if (isProgressBarVisible || (widthGap > 0)) {
186 m_spaceInfo->hide();
187 }
188 } else if (widthGap + m_spaceInfo->width() <= 0) {
189 m_spaceInfo->show();
190 }
191 }
192
193 #include "dolphinstatusbar.moc"