]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbarspaceinfo.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / statusbarspaceinfo.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
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 "statusbarspaceinfo.h"
22
23 #include <kdiskfreespace.h>
24 #include <kmountpoint.h>
25 #include <klocale.h>
26 #include <kio/job.h>
27
28 #include <QTimer>
29 #include <QKeyEvent>
30
31 StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget* parent) :
32 QProgressBar(parent),
33 m_gettingSize(false),
34 m_text()
35 {
36 setMinimum(0);
37 setMaximum(0);
38
39 setMaximumWidth(200);
40
41 // Update the space information each 10 seconds. Polling is useful
42 // here, as files can be deleted/added outside the scope of Dolphin.
43 QTimer* timer = new QTimer(this);
44 connect(timer, SIGNAL(timeout()), this, SLOT(refresh()));
45 timer->start(10000);
46 }
47
48 StatusBarSpaceInfo::~StatusBarSpaceInfo()
49 {
50 }
51
52 void StatusBarSpaceInfo::setUrl(const KUrl& url)
53 {
54 m_url = url;
55 refresh();
56 }
57
58 QString StatusBarSpaceInfo::text() const
59 {
60 return m_text;
61 }
62
63 void StatusBarSpaceInfo::slotFoundMountPoint(const QString& mountPoint,
64 quint64 kBSize,
65 quint64 kBUsed,
66 quint64 kBAvailable)
67 {
68 Q_UNUSED(kBSize);
69 Q_UNUSED(mountPoint);
70
71 m_gettingSize = false;
72 const bool valuesChanged = (kBUsed != static_cast<quint64>(value())) ||
73 (kBAvailable != static_cast<quint64>(maximum()));
74 if (valuesChanged) {
75 m_text = i18nc("@info:status", "%1 free", KIO::convertSizeFromKiB(kBAvailable));
76 setMaximum(kBAvailable);
77 setValue(kBUsed);
78 }
79 }
80
81 void StatusBarSpaceInfo::refresh()
82 {
83 // KDiskFreeSpace is for local paths only
84 if (!m_url.isLocalFile()) {
85 return;
86 }
87
88 KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(m_url.path());
89 if (!mp) {
90 return;
91 }
92
93 m_gettingSize = true;
94 KDiskFreeSpace* job = new KDiskFreeSpace(this);
95 connect(job, SIGNAL(foundMountPoint(const QString&,
96 quint64,
97 quint64,
98 quint64)),
99 this, SLOT(slotFoundMountPoint(const QString&,
100 quint64,
101 quint64,
102 quint64)));
103
104 job->readDF(mp->mountPoint());
105
106 // refresh() is invoked for each directory change. Usually getting
107 // the size information can be done very fast, so to prevent any
108 // flickering the "Getting size..." indication is only shown if
109 // at least 300 ms have been passed.
110 QTimer::singleShot(300, this, SLOT(showGettingSizeInfo()));
111 }
112
113 void StatusBarSpaceInfo::showGettingSizeInfo()
114 {
115 if (m_gettingSize) {
116 m_text = i18nc("@info:status", "Getting size...");
117 setMinimum(0);
118 setMaximum(0);
119 }
120 }
121
122 #include "statusbarspaceinfo.moc"