Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > d9b360ee2bb591aec74456d859429422 > files > 6

kdelibs4-4.1.2-5mdv2009.0.src.rpm

Index: includes/KDiskFreeSpaceInfo
===================================================================
--- includes/KDiskFreeSpaceInfo	(revision 0)
+++ includes/KDiskFreeSpaceInfo	(revision 837775)
@@ -0,0 +1 @@
+#include "../kdiskfreespaceinfo.h"
Index: includes/CMakeLists.txt
===================================================================
--- includes/CMakeLists.txt	(revision 837774)
+++ includes/CMakeLists.txt	(revision 837775)
@@ -147,6 +147,7 @@
   KDirSelectDialog
   KDirWatch
   KDiskFreeSpace
+  KDiskFreeSpaceInfo
   KDoubleNumInput
   KDoubleSpinBox
   KDoubleValidator
Index: kio/kfile/kdiskfreespaceinfo.h
===================================================================
--- kio/kfile/kdiskfreespaceinfo.h	(revision 0)
+++ kio/kfile/kdiskfreespaceinfo.h	(revision 837775)
@@ -0,0 +1,131 @@
+/*
+ *  kdiskfreespaceinfo.h
+ *
+ *  Copyright 2008 Sebastian Trug <trueg@kde.org>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License version 2 as published by the Free Software Foundation.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _KDISK_FREE_SPACE_INFO_H_
+#define _KDISK_FREE_SPACE_INFO_H_
+
+#include <QtCore/QSharedDataPointer>
+#include <QtCore/QString>
+
+#include <kio/kio_export.h>
+#include <kio/global.h>
+
+/**
+ * \class KDiskFreeSpaceInfo kdiskfreespaceinfo.h KDiskFreeSpaceInfo
+ *
+ * \brief Determine the space left on an arbitrary partition.
+ *
+ * This class determines the free space left on the partition that holds a given 
+ * path.  This path can be the mount point or any file or directory on the 
+ * partition.
+ *
+ * To find how much space is available on the partition containing @p path, 
+ * simply do the following:
+ *
+ * \code
+ * KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( path );
+ * if( info.isValid() )
+ *    doSomething( info.available() );
+ * \code
+ *
+ * \author Sebastian Trueg <trueg@kde.org>
+ *
+ * \since 4.2
+ */
+class KIO_EXPORT KDiskFreeSpaceInfo
+{
+public:
+    /**
+     * Copy constructor
+     */
+    KDiskFreeSpaceInfo( const KDiskFreeSpaceInfo& );
+
+    /**
+     * Destructor
+     */
+    ~KDiskFreeSpaceInfo();
+
+    /**
+     * Assignment operator
+     */
+    KDiskFreeSpaceInfo& operator=( const KDiskFreeSpaceInfo& );
+
+    /**
+     * \return \p true if the available disk space was successfully
+     * determined and the values from mountPoint(), size(), available(),
+     * and used() are valid. \p false otherwise.
+     */
+    bool isValid() const;
+
+    /**
+     * The mount point of the partition the requested path points to
+     *
+     * Only valid if isValid() returns \p true.
+     */
+    QString mountPoint() const;
+
+    /**
+     * The total size of the partition mounted at mountPoint()
+     *
+     * Only valid if isValid() returns \p true.
+     *
+     * \return Total size of the requested partition in bytes.
+     */
+    KIO::filesize_t size() const;
+
+    /**
+     * The available space in the partition mounted at mountPoint()
+     *
+     * Only valid if isValid() returns \p true.
+     *
+     * \return Available space left on the requested partition in bytes.
+     */
+    KIO::filesize_t available() const;
+
+    /**
+     * The used space in the partition mounted at mountPoint()
+     *
+     * Only valid if isValid() returns \p true.
+     *
+     * \return Used space on the requested partition in bytes.
+     */
+    KIO::filesize_t used() const;
+
+    /**
+     * Static method used to determine the free disk space.
+     *
+     * \param path An arbitrary path. The available space will be
+     * determined for the partition containing path.
+     *
+     * Check isValid() to see if the process was successful. Then
+     * use mountPoint(), size(), available(), and used() to access
+     * the requested values.
+     */
+    static KDiskFreeSpaceInfo freeSpaceInfo( const QString& path );
+
+private:
+    KDiskFreeSpaceInfo();
+
+    class Private;
+    QSharedDataPointer<Private> d;
+};
+
+#endif
+
Index: kio/kfile/kdiskfreespaceinfo.cpp
===================================================================
--- kio/kfile/kdiskfreespaceinfo.cpp	(revision 0)
+++ kio/kfile/kdiskfreespaceinfo.cpp	(revision 837775)
@@ -0,0 +1,141 @@
+/*
+ *  kdiskfreespaceinfo.h
+ *
+ *  Copyright 2008 Sebastian Trug <trueg@kde.org>
+ *
+ *  Based on kdiskfreespace.h
+ *  Copyright 2007 David Faure <faure@kde.org>
+ *  Copyright 2008 Dirk Mueller <mueller@kde.org>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License version 2 as published by the Free Software Foundation.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#include "kdiskfreespaceinfo.h"
+
+#include <QtCore/QSharedData>
+#include <QtCore/QFile>
+
+#include <kmountpoint.h>
+
+#ifdef Q_OS_WIN
+#include <QtCore/QDir>
+#include <windows.h>
+#else
+#include <sys/statvfs.h>
+#endif
+
+
+class KDiskFreeSpaceInfo::Private : public QSharedData
+{
+public:
+    Private()
+        : valid(false),
+          size(0),
+          available(0) {
+    }
+
+    bool valid;
+    QString mountPoint;
+    KIO::filesize_t size;
+    KIO::filesize_t available;
+};
+
+
+KDiskFreeSpaceInfo::KDiskFreeSpaceInfo()
+    : d(new Private())
+{
+}
+
+
+KDiskFreeSpaceInfo::KDiskFreeSpaceInfo( const KDiskFreeSpaceInfo& other )
+{
+    d = other.d;
+}
+
+
+KDiskFreeSpaceInfo::~KDiskFreeSpaceInfo()
+{
+}
+
+
+KDiskFreeSpaceInfo& KDiskFreeSpaceInfo::operator=( const KDiskFreeSpaceInfo& other )
+{
+    d = other.d;
+    return *this;
+}
+
+
+bool KDiskFreeSpaceInfo::isValid() const
+{
+    return d->valid;
+}
+
+
+QString KDiskFreeSpaceInfo::mountPoint() const
+{
+    return d->mountPoint;
+}
+
+
+KIO::filesize_t KDiskFreeSpaceInfo::size() const
+{
+    return d->size;
+}
+
+
+KIO::filesize_t KDiskFreeSpaceInfo::available() const
+{
+    return d->available;
+}
+
+
+KIO::filesize_t KDiskFreeSpaceInfo::used() const
+{
+    return d->size - d->available;
+}
+
+
+KDiskFreeSpaceInfo KDiskFreeSpaceInfo::freeSpaceInfo( const QString& path )
+{
+    KDiskFreeSpaceInfo info;
+
+    // determine the mount point
+    KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath( path );
+    if (mp)
+        info.d->mountPoint = mp->mountPoint();
+
+#ifdef Q_OS_WIN
+    quint64 availUser;
+    QFileInfo fi(info.d->mountPoint);
+    QString dir = QDir::toNativeSeparators(fi.absoluteDir().canonicalPath());
+
+    if(GetDiskFreeSpaceExW((LPCWSTR)dir.utf16(),
+                           (PULARGE_INTEGER)&availUser,
+                           (PULARGE_INTEGER)&info.d->size,
+                           (PULARGE_INTEGER)&info.d->available) != 0) {
+        info.d->valid = true;
+    }
+#else
+    struct statvfs statvfs_buf;
+
+    if (!statvfs(QFile::encodeName(path).constData(), &statvfs_buf)) {
+        info.d->available = statvfs_buf.f_bavail * statvfs_buf.f_frsize;
+        info.d->size = statvfs_buf.f_blocks * statvfs_buf.f_frsize;
+        info.d->valid = true;
+    }
+#endif
+
+    return info;
+}
Index: kio/kfile/kpropertiesdialog.cpp
===================================================================
--- kio/kfile/kpropertiesdialog.cpp	(revision 837774)
+++ kio/kfile/kpropertiesdialog.cpp	(revision 837775)
@@ -83,7 +83,7 @@
 #include <kdialog.h>
 #include <kdirwatch.h>
 #include <kdirnotify.h>
-#include <kdiskfreespace.h>
+#include <kdiskfreespaceinfo.h>
 #include <kdebug.h>
 #include <kdesktopfile.h>
 #include <kicondialog.h>
@@ -1102,10 +1102,8 @@
       d->m_capacityBar = new KCapacityBar( KCapacityBar::DrawTextOutline, d->m_frame );
       grid->addWidget( d->m_capacityBar, curRow++, 2);
 
-      KDiskFreeSpace * job = new KDiskFreeSpace;
-      connect(job, SIGNAL(foundMountPoint(QString, quint64, quint64, quint64)),
-              this, SLOT(slotFoundMountPoint(QString, quint64, quint64, quint64)));
-      job->readDF( mp->mountPoint() );
+      KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( mp->mountPoint() );
+      slotFoundMountPoint( info.mountPoint(), info.size()/1024, info.used()/1024, info.available()/1024);
     }
   }
 
@@ -1253,10 +1251,8 @@
     KUrl url = item.mostLocalUrl( isLocal );
     KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath( url.path() );
     if (mp) {
-      KDiskFreeSpace * job = new KDiskFreeSpace;
-      connect(job, SIGNAL(foundMountPoint(QString, quint64, quint64, quint64)),
-              this, SLOT(slotFoundMountPoint(QString, quint64, quint64, quint64)));
-      job->readDF( mp->mountPoint() );
+      KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( mp->mountPoint() );
+      slotFoundMountPoint( info.mountPoint(), info.size()/1024, info.used()/1024, info.available()/1024);
     }
   }
 }
@@ -2859,11 +2855,8 @@
 
   if ( !d->mountpoint->text().isEmpty() )
   {
-    KDiskFreeSpace * job = new KDiskFreeSpace;
-    connect(job, SIGNAL(foundMountPoint(QString, quint64, quint64, quint64)),
-            this, SLOT(slotFoundMountPoint(QString, quint64, quint64, quint64)));
-
-    job->readDF( d->mountpoint->text() );
+      KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( d->mountpoint->text() );
+      slotFoundMountPoint( info.mountPoint(), info.size()/1024, info.used()/1024, info.available()/1024);
   }
 }
 
Index: kio/CMakeLists.txt
===================================================================
--- kio/CMakeLists.txt	(revision 837774)
+++ kio/CMakeLists.txt	(revision 837775)
@@ -157,6 +157,7 @@
   kfile/kdevicelistitem.cpp
   kfile/kdevicelistmodel.cpp
   kfile/kdiskfreespace.cpp
+  kfile/kdiskfreespaceinfo.cpp
   kfile/kencodingfiledialog.cpp
   kfile/kfile.cpp
   kfile/kfiledialog.cpp
@@ -246,7 +247,6 @@
 
 target_link_libraries(kio ${KDE4_KDEUI_LIBS} ${ZLIB_LIBRARY} ${STRIGI_STREAMANALYZER_LIBRARY} ${STRIGI_STREAMS_LIBRARY} ${KDE4_SOLID_LIBS} ${QT_QTNETWORK_LIBRARY} ${QT_QTXML_LIBRARY} ${X11_LIBRARIES})
 
-
 set(SYS_INOTIFY_H_FOUND 0)
 if(SYS_INOTIFY_H_FOUND)
    macro_log_feature(FAM_FOUND "FAM" "File Alteration Monitor" "http://oss.sgi.com/projects/fam" FALSE "" "You have file alteration notification support built into your kernel, however you might consider installing FAM as it also supports NFS.")
@@ -379,6 +379,7 @@
   kfile/kabstractfilewidget.h
   kfile/kdevicelistmodel.h
   kfile/kdiskfreespace.h
+  kfile/kdiskfreespaceinfo.h
   kfile/kencodingfiledialog.h
   kfile/kfile.h
   kfile/kfiledialog.h
--- kio/kfile/kdiskfreespace.h~	2008-05-21 13:08:03.000000000 +0200
+++ kio/kfile/kdiskfreespace.h	2008-08-04 09:37:27.000000000 +0200
@@ -33,6 +33,7 @@
 /**
  * This class parses the output of "df" to find the disk usage
  * information for a given partition (mount point).
+ * \deprecated Use KDiskFreeSpaceInfo
  */
 class KIO_EXPORT KDiskFreeSpace : public QObject
 {
@@ -43,7 +44,7 @@
     /**
      * Constructor
      */
-    explicit KDiskFreeSpace( QObject *parent = 0 );
+    KDE_DEPRECATED explicit KDiskFreeSpace( QObject *parent = 0 );
 
     /**
      * Destructor - this object autodeletes itself when it's done
@@ -63,7 +64,7 @@
      * the request for one mount point and then auto-deletes itself.
      * Suicidal objects are not reusable...
      */
-    bool readDF( const QString & mountPoint );
+    KDE_DEPRECATED bool readDF( const QString & mountPoint );
 
     /**
      * Call this to fire a search on the disk usage information
@@ -72,7 +73,7 @@
      * if this mount point is found, with the info requested.
      * The done() signal is emitted in any case.
      */
-    static KDiskFreeSpace * findUsageInfo( const QString & path );
+    KDE_DEPRECATED static KDiskFreeSpace * findUsageInfo( const QString & path );
 
 Q_SIGNALS:
     /**
--- kio/kfile/kdiskfreespace.cpp~	2008-05-21 13:08:03.000000000 +0200
+++ kio/kfile/kdiskfreespace.cpp	2008-08-04 09:44:14.000000000 +0200
@@ -20,19 +20,13 @@
  */
 
 #include "kdiskfreespace.h"
-#include <QtCore/QFile>
-#include <QtCore/QTextIStream>
+#include "kdiskfreespaceinfo.h"
 #include <QtCore/QTimer>
 
 #include <kdebug.h>
-#include <kprocess.h>
-#include <kmountpoint.h>
-#include <kio/global.h>
-#include <config-kfile.h>
 
-class KDiskFreeSpace::Private
+struct KDiskFreeSpace::Private
 {
-public:
     Private(KDiskFreeSpace *parent)
         : m_parent(parent)
     {}
@@ -60,53 +54,18 @@
     return d->_k_calculateFreeSpace();
 }
 
-#ifdef Q_OS_WIN
-#include <QtCore/QDir>
-#include <windows.h>
-#else
-#include <sys/statvfs.h>
-#endif
-
 bool KDiskFreeSpace::Private::_k_calculateFreeSpace()
 {
-    // determine the mount point
-    QString mountPoint;
-
-    KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath( m_path );
-    if (mp)
-        mountPoint = mp->mountPoint();
-
-    quint64 availUser, total, avail;
-    bool bRet = false;
-#ifdef Q_OS_WIN
-    QFileInfo fi(mountPoint);
-    QString dir = QDir::toNativeSeparators(fi.absoluteDir().canonicalPath());
-
-    if(GetDiskFreeSpaceExW((LPCWSTR)dir.utf16(),
-                           (PULARGE_INTEGER)&availUser,
-                           (PULARGE_INTEGER)&total,
-                           (PULARGE_INTEGER)&avail) != 0) {
-        availUser = availUser / 1024;
-        total = total / 1024;
-        avail = avail / 1024;
-        emit m_parent->foundMountPoint( mountPoint, total, total-avail, avail );
-        bRet = true;
+    KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( m_path );
+    if ( info.isValid() ) {
+        quint64 sizeKiB = info.size() / 1024;
+        quint64 availKiB = info.available() / 1024;
+        emit m_parent->foundMountPoint( info.mountPoint(), sizeKiB, sizeKiB-availKiB, availKiB );	
     }
-#else
-    struct statvfs statvfs_buf;
-
-    if (!statvfs(QFile::encodeName(m_path).constData(), &statvfs_buf)) {
-        avail = statvfs_buf.f_bavail * statvfs_buf.f_frsize / 1024;
-        total = statvfs_buf.f_blocks * statvfs_buf.f_frsize / 1024;
-        emit m_parent->foundMountPoint( mountPoint, total, total-avail, avail );
-        bRet = true;
-    }
-#endif
-
     emit m_parent->done();
     m_parent->deleteLater();
 
-    return bRet;
+	return info.isValid();;
 }
 
 KDiskFreeSpace * KDiskFreeSpace::findUsageInfo( const QString & path )