File indexing completed on 2024-05-05 16:08:24

0001 /*
0002  * kdiskfreespace.cpp
0003  *
0004  * Copyright 2007 David Faure <faure@kde.org>
0005  * Copyright 2008 Dirk Mueller <mueller@kde.org>
0006  * Copyright 2008 Sebastian Trug <trueg@kde.org>
0007  *
0008  *  This library is free software; you can redistribute it and/or
0009  *  modify it under the terms of the GNU Library General Public
0010  *  License version 2 as published by the Free Software Foundation.
0011  *
0012  *  This library is distributed in the hope that it will be useful,
0013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  *  Library General Public License for more details.
0016  *
0017  *  You should have received a copy of the GNU Library General Public License
0018  *  along with this library; see the file COPYING.LIB.  If not, write to
0019  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  *  Boston, MA 02110-1301, USA.
0021  */
0022 
0023 #include "kdiskfreespace.h"
0024 #include "kdiskfreespaceinfo.h"
0025 #include <QTimer>
0026 
0027 #include <kdebug.h>
0028 
0029 class Q_DECL_HIDDEN KDiskFreeSpace::Private
0030 {
0031 public:
0032     Private(KDiskFreeSpace *parent)
0033         : m_parent(parent)
0034     {}
0035 
0036     bool _k_calculateFreeSpace();
0037 
0038     KDiskFreeSpace   *m_parent;
0039     QString           m_path;
0040 };
0041 
0042 KDiskFreeSpace::KDiskFreeSpace(QObject *parent)
0043     : QObject(parent), d(new Private(this))
0044 {
0045 }
0046 
0047 KDiskFreeSpace::~KDiskFreeSpace()
0048 {
0049     delete d;
0050 }
0051 
0052 bool KDiskFreeSpace::readDF(const QString &mountPoint)
0053 {
0054     d->m_path = mountPoint;
0055     return d->_k_calculateFreeSpace();
0056 }
0057 
0058 bool KDiskFreeSpace::Private::_k_calculateFreeSpace()
0059 {
0060     KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_path);
0061     if (info.isValid()) {
0062         quint64 sizeKiB = info.size() / 1024;
0063         quint64 availKiB = info.available() / 1024;
0064         emit m_parent->foundMountPoint(info.mountPoint(), sizeKiB, sizeKiB - availKiB, availKiB);
0065     }
0066 
0067     emit m_parent->done();
0068 
0069     m_parent->deleteLater();
0070 
0071     return info.isValid();
0072 }
0073 
0074 KDiskFreeSpace *KDiskFreeSpace::findUsageInfo(const QString &path)
0075 {
0076     KDiskFreeSpace *job = new KDiskFreeSpace;
0077     job->d->m_path = path;
0078     QTimer::singleShot(0, job, SLOT(_k_calculateFreeSpace()));
0079     return job;
0080 }
0081 
0082 #include "moc_kdiskfreespace.cpp"
0083