]>
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::convertSizeFromKiB(kBAvailable
));
83 void StatusBarSpaceInfo::slotKDFSDone()
85 if( m_foundMountPoint
)
87 m_gettingSize
= false;
88 m_text
= i18n("Free disk space could not be determined");
94 void StatusBarSpaceInfo::refresh()
96 // KDiskFreeSpace is for local paths only
97 if (!m_url
.isLocalFile()) {
98 m_text
= i18nc("@info:status", "Unknown size");
103 KMountPoint::Ptr mp
= KMountPoint::currentMountPoints().findByPath(m_url
.path());
108 m_gettingSize
= true;
109 m_foundMountPoint
= false;
110 KDiskFreeSpace
* job
= new KDiskFreeSpace(this);
111 connect(job
, SIGNAL(foundMountPoint(const QString
&,
115 this, SLOT(slotFoundMountPoint(const QString
&,
119 connect(job
, SIGNAL(done()), this, SLOT(slotKDFSDone()));
121 job
->readDF(mp
->mountPoint());
123 // refresh() is invoked for each directory change. Usually getting
124 // the size information can be done very fast, so to prevent any
125 // flickering the "Getting size..." indication is only shown if
126 // at least 300 ms have been passed.
127 QTimer::singleShot(300, this, SLOT(showGettingSizeInfo()));
130 void StatusBarSpaceInfo::showGettingSizeInfo()
133 m_text
= i18nc("@info:status", "Getting size...");
140 #include "statusbarspaceinfo.moc"