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 <KDiskFreeSpaceInfo>
24 #include <kmountpoint.h>
31 StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget
* parent
) :
32 KCapacityBar(KCapacityBar::DrawTextInline
, parent
),
37 setMinimumWidth(200); // something to fix on kcapacitybar (ereslibre)
39 // Use a timer to update the space information. Polling is useful
40 // here, as files can be deleted/added outside the scope of Dolphin.
41 m_timer
= new QTimer(this);
42 connect(m_timer
, SIGNAL(timeout()), this, SLOT(refresh()));
45 StatusBarSpaceInfo::~StatusBarSpaceInfo()
49 void StatusBarSpaceInfo::setUrl(const KUrl
& url
)
55 void StatusBarSpaceInfo::showEvent(QShowEvent
* event
)
57 KCapacityBar::showEvent(event
);
58 if (!event
->spontaneous()) {
60 m_timer
->start(10000);
64 void StatusBarSpaceInfo::hideEvent(QHideEvent
* event
)
67 KCapacityBar::hideEvent(event
);
70 void StatusBarSpaceInfo::refresh()
76 // KDiskFreeSpace is for local paths only
77 if (!m_url
.isLocalFile()) {
78 setText(i18nc("@info:status", "Unknown size"));
84 KMountPoint::Ptr mp
= KMountPoint::currentMountPoints().findByPath(m_url
.path());
89 KDiskFreeSpaceInfo job
= KDiskFreeSpaceInfo::freeSpaceInfo(mp
->mountPoint());
91 setText(i18nc("@info:status", "Unknown size"));
97 KIO::filesize_t kBSize
= job
.size() / 1024;
98 KIO::filesize_t kBUsed
= job
.used() / 1024;
100 const bool valuesChanged
= (kBUsed
!= static_cast<quint64
>(value())) || (kBSize
!= m_kBSize
);
102 setText(i18nc("@info:status Free disk space", "%1 free",
103 KIO::convertSize(job
.available())));
105 setUpdatesEnabled(false);
107 setValue(kBSize
> 0 ? (kBUsed
* 100) / kBSize
: 0);
108 setUpdatesEnabled(true);
113 #include "statusbarspaceinfo.moc"