1 /*
2 * kdiskfreespace.cpp
3 *
4 * Copyright 2007 David Faure <faure@kde.org>
5 * Copyright 2008 Dirk Mueller <mueller@kde.org>
6 * Copyright 2008 Sebastian Trug <trueg@kde.org>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License version 2 as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #include "kdiskfreespace.h"
24 #include "kdiskfreespaceinfo.h"
25 #include <QTimer>
26
27 #include <kdebug.h>
28
29 class Q_DECL_HIDDEN KDiskFreeSpace::Private
30 {
31 public:
Private(KDiskFreeSpace * parent)32 Private(KDiskFreeSpace *parent)
33 : m_parent(parent)
34 {}
35
36 bool _k_calculateFreeSpace();
37
38 KDiskFreeSpace *m_parent;
39 QString m_path;
40 };
41
KDiskFreeSpace(QObject * parent)42 KDiskFreeSpace::KDiskFreeSpace(QObject *parent)
43 : QObject(parent), d(new Private(this))
44 {
45 }
46
~KDiskFreeSpace()47 KDiskFreeSpace::~KDiskFreeSpace()
48 {
49 delete d;
50 }
51
readDF(const QString & mountPoint)52 bool KDiskFreeSpace::readDF(const QString &mountPoint)
53 {
54 d->m_path = mountPoint;
55 return d->_k_calculateFreeSpace();
56 }
57
_k_calculateFreeSpace()58 bool KDiskFreeSpace::Private::_k_calculateFreeSpace()
59 {
60 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_path);
61 if (info.isValid()) {
62 quint64 sizeKiB = info.size() / 1024;
63 quint64 availKiB = info.available() / 1024;
64 emit m_parent->foundMountPoint(info.mountPoint(), sizeKiB, sizeKiB - availKiB, availKiB);
65 }
66
67 emit m_parent->done();
68
69 m_parent->deleteLater();
70
71 return info.isValid();
72 }
73
findUsageInfo(const QString & path)74 KDiskFreeSpace *KDiskFreeSpace::findUsageInfo(const QString &path)
75 {
76 KDiskFreeSpace *job = new KDiskFreeSpace;
77 job->d->m_path = path;
78 QTimer::singleShot(0, job, SLOT(_k_calculateFreeSpace()));
79 return job;
80 }
81
82 #include "moc_kdiskfreespace.cpp"
83
84