]>
cloud.milkyroute.net Git - dolphin.git/blob - src/statusbarspaceinfo.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
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. *
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. *
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 ***************************************************************************/
21 #include "statusbarspaceinfo.h"
23 #include <kdiskfreespace.h>
24 #include <kmountpoint.h>
31 StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget
* parent
) :
34 m_foundMountPoint(false),
42 // Update the space information each 10 seconds. Polling is useful
43 // here, as files can be deleted/added outside the scope of Dolphin.
44 QTimer
* timer
= new QTimer(this);
45 connect(timer
, SIGNAL(timeout()), this, SLOT(refresh()));
49 StatusBarSpaceInfo::~StatusBarSpaceInfo()
53 void StatusBarSpaceInfo::setUrl(const KUrl
& url
)
59 QString
StatusBarSpaceInfo::text() const
64 void StatusBarSpaceInfo::slotFoundMountPoint(const QString
& mountPoint
,
72 m_gettingSize
= false;
73 m_foundMountPoint
= true;
74 const bool valuesChanged
= (kBUsed
!= static_cast<quint64
>(value())) ||
75 (kBAvailable
!= static_cast<quint64
>(maximum()));
77 m_text
= i18nc("@info:status Free disk space", "%1 free", KIO::convertSize(kBAvailable
* 1024));
83 void StatusBarSpaceInfo::slotDiskFreeSpaceDone()
85 if (m_foundMountPoint
) {
89 m_gettingSize
= false;
90 m_text
= i18nc("@info:status", "Unknown size");
96 void StatusBarSpaceInfo::refresh()
98 // KDiskFreeSpace is for local paths only
99 if (!m_url
.isLocalFile()) {
100 m_text
= i18nc("@info:status", "Unknown size");
105 KMountPoint::Ptr mp
= KMountPoint::currentMountPoints().findByPath(m_url
.path());
110 m_gettingSize
= true;
111 m_foundMountPoint
= false;
112 KDiskFreeSpace
* job
= new KDiskFreeSpace(this);
113 connect(job
, SIGNAL(foundMountPoint(const QString
&,
117 this, SLOT(slotFoundMountPoint(const QString
&,
121 connect(job
, SIGNAL(done()), this, SLOT(slotDiskFreeSpaceDone()));
123 job
->readDF(mp
->mountPoint());
125 // refresh() is invoked for each directory change. Usually getting
126 // the size information can be done very fast, so to prevent any
127 // flickering the "Getting size..." indication is only shown if
128 // at least 300 ms have been passed.
129 QTimer::singleShot(300, this, SLOT(showGettingSizeInfo()));
132 void StatusBarSpaceInfo::showGettingSizeInfo()
135 m_text
= i18nc("@info:status", "Getting size...");
142 #include "statusbarspaceinfo.moc"