• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIO

kdiskfreespace.cpp

Go to the documentation of this file.
00001 /*
00002  * kdiskfreespace.cpp
00003  *
00004  * Copyright 2007 David Faure <faure@kde.org>
00005  * Copyright 2008 Dirk Mueller <mueller@kde.org>
00006  *
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Library General Public
00009  *  License version 2 as published by the Free Software Foundation.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #include "kdiskfreespace.h"
00023 #include <QtCore/QFile>
00024 #include <QtCore/QTextIStream>
00025 #include <QtCore/QTimer>
00026 
00027 #include <kdebug.h>
00028 #include <kprocess.h>
00029 #include <kmountpoint.h>
00030 #include <kio/global.h>
00031 #include <config-kfile.h>
00032 
00033 class KDiskFreeSpace::Private
00034 {
00035 public:
00036     Private(KDiskFreeSpace *parent)
00037         : m_parent(parent)
00038     {}
00039 
00040     bool _k_calculateFreeSpace();
00041 
00042     KDiskFreeSpace   *m_parent;
00043     QString           m_path;
00044 };
00045 
00046 KDiskFreeSpace::KDiskFreeSpace(QObject *parent)
00047     : QObject(parent), d(new Private(this))
00048 {
00049 }
00050 
00051 
00052 KDiskFreeSpace::~KDiskFreeSpace()
00053 {
00054     delete d;
00055 }
00056 
00057 bool KDiskFreeSpace::readDF( const QString & mountPoint )
00058 {
00059     d->m_path = mountPoint;
00060     return d->_k_calculateFreeSpace();
00061 }
00062 
00063 #ifdef Q_OS_WIN
00064 #include <QtCore/QDir>
00065 #include <windows.h>
00066 #else
00067 #include <sys/statvfs.h>
00068 #endif
00069 
00070 bool KDiskFreeSpace::Private::_k_calculateFreeSpace()
00071 {
00072     // determine the mount point
00073     QString mountPoint;
00074 
00075     KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath( m_path );
00076     if (mp)
00077         mountPoint = mp->mountPoint();
00078 
00079     quint64 availUser, total, avail;
00080     bool bRet = false;
00081 #ifdef Q_OS_WIN
00082     QFileInfo fi(mountPoint);
00083     QString dir = QDir::toNativeSeparators(fi.absoluteDir().canonicalPath());
00084 
00085     if(GetDiskFreeSpaceExW((LPCWSTR)dir.utf16(),
00086                            (PULARGE_INTEGER)&availUser,
00087                            (PULARGE_INTEGER)&total,
00088                            (PULARGE_INTEGER)&avail) != 0) {
00089         availUser = availUser / 1024;
00090         total = total / 1024;
00091         avail = avail / 1024;
00092         emit m_parent->foundMountPoint( mountPoint, total, total-avail, avail );
00093         bRet = true;
00094     }
00095 #else
00096     struct statvfs statvfs_buf;
00097 
00098     if (!statvfs(QFile::encodeName(m_path).constData(), &statvfs_buf)) {
00099         avail = statvfs_buf.f_bavail * statvfs_buf.f_frsize / 1024;
00100         total = statvfs_buf.f_blocks * statvfs_buf.f_frsize / 1024;
00101         emit m_parent->foundMountPoint( mountPoint, total, total-avail, avail );
00102         bRet = true;
00103     }
00104 #endif
00105 
00106     emit m_parent->done();
00107     m_parent->deleteLater();
00108 
00109     return bRet;
00110 }
00111 
00112 KDiskFreeSpace * KDiskFreeSpace::findUsageInfo( const QString & path )
00113 {
00114     KDiskFreeSpace * job = new KDiskFreeSpace;
00115     job->d->m_path = path;
00116     QTimer::singleShot(0, job, SLOT(_k_calculateFreeSpace()));
00117     return job;
00118 }
00119 
00120 #include "kdiskfreespace.moc"
00121 

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal