]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbarspaceinfo.cpp
9bc091b7a03ba80cf33028ed8a8e821634c76e36
[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_text()
34 {
35 setMaximumWidth(200);
36
37 // Update the space information each 10 seconds. Polling is useful
38 // here, as files can be deleted/added outside the scope of Dolphin.
39 QTimer* timer = new QTimer(this);
40 connect(timer, SIGNAL(timeout()), this, SLOT(refresh()));
41 timer->start(10000);
42 }
43
44 StatusBarSpaceInfo::~StatusBarSpaceInfo()
45 {
46 }
47
48 void StatusBarSpaceInfo::setUrl(const KUrl& url)
49 {
50 m_url = url;
51 refresh();
52 QTimer::singleShot(300, this, SLOT(update()));
53 }
54
55 QString StatusBarSpaceInfo::text() const
56 {
57 return m_text;
58 }
59
60 void StatusBarSpaceInfo::slotFoundMountPoint(const QString& mountPoint,
61 quint64 kBSize,
62 quint64 kBUsed,
63 quint64 kBAvailable)
64 {
65 Q_UNUSED(kBUsed);
66 Q_UNUSED(mountPoint);
67
68 m_text = i18nc("@info:status", "%1 free", KIO::convertSizeFromKiB(kBAvailable));
69
70 setMinimum(0);
71 setMaximum(kBAvailable);
72 setValue(kBUsed);
73 }
74
75 void StatusBarSpaceInfo::refresh()
76 {
77 // KDiskFreeSpace is for local paths only
78 if (!m_url.isLocalFile()) {
79 return;
80 }
81
82 m_text = i18nc("@info:status", "Getting size...");
83 setMinimum(0);
84 setMaximum(0);
85
86 KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(m_url.path());
87 if (!mp) {
88 return;
89 }
90
91 KDiskFreeSpace* job = new KDiskFreeSpace(this);
92 connect(job, SIGNAL(foundMountPoint(const QString&,
93 quint64,
94 quint64,
95 quint64)),
96 this, SLOT(slotFoundMountPoint(const QString&,
97 quint64,
98 quint64,
99 quint64)));
100
101 job->readDF(mp->mountPoint());
102 }
103
104 #include "statusbarspaceinfo.moc"