1/*
2 * kdiskfreespaceinfo.h
3 *
4 * Copyright 2008 Sebastian Trug <trueg@kde.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License version 2 as published by the Free Software Foundation.
9 *
10 * This library 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 GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef _KDISK_FREE_SPACE_INFO_H_
22#define _KDISK_FREE_SPACE_INFO_H_
23
24#include <QtCore/QSharedDataPointer>
25#include <QtCore/QString>
26
27#include <kio/kio_export.h>
28#include <kio/global.h>
29
30/**
31 * \class KDiskFreeSpaceInfo kdiskfreespaceinfo.h KDiskFreeSpaceInfo
32 *
33 * \brief Determine the space left on an arbitrary partition.
34 *
35 * This class determines the free space left on the partition that holds a given
36 * path. This path can be the mount point or any file or directory on the
37 * partition.
38 *
39 * To find how much space is available on the partition containing @p path,
40 * simply do the following:
41 *
42 * \code
43 * KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( path );
44 * if( info.isValid() )
45 * doSomething( info.available() );
46 * \code
47 *
48 * \author Sebastian Trueg <trueg@kde.org>
49 *
50 * \since 4.2
51 */
52class KIO_EXPORT KDiskFreeSpaceInfo
53{
54public:
55 /**
56 * Copy constructor
57 */
58 KDiskFreeSpaceInfo( const KDiskFreeSpaceInfo& );
59
60 /**
61 * Destructor
62 */
63 ~KDiskFreeSpaceInfo();
64
65 /**
66 * Assignment operator
67 */
68 KDiskFreeSpaceInfo& operator=( const KDiskFreeSpaceInfo& );
69
70 /**
71 * \return \p true if the available disk space was successfully
72 * determined and the values from mountPoint(), size(), available(),
73 * and used() are valid. \p false otherwise.
74 */
75 bool isValid() const;
76
77 /**
78 * The mount point of the partition the requested path points to
79 *
80 * Only valid if isValid() returns \p true.
81 */
82 QString mountPoint() const;
83
84 /**
85 * The total size of the partition mounted at mountPoint()
86 *
87 * Only valid if isValid() returns \p true.
88 *
89 * \return Total size of the requested partition in bytes.
90 */
91 KIO::filesize_t size() const;
92
93 /**
94 * The available space in the partition mounted at mountPoint()
95 *
96 * Only valid if isValid() returns \p true.
97 *
98 * \return Available space left on the requested partition in bytes.
99 */
100 KIO::filesize_t available() const;
101
102 /**
103 * The used space in the partition mounted at mountPoint()
104 *
105 * Only valid if isValid() returns \p true.
106 *
107 * \return Used space on the requested partition in bytes.
108 */
109 KIO::filesize_t used() const;
110
111 /**
112 * Static method used to determine the free disk space.
113 *
114 * \param path An arbitrary path. The available space will be
115 * determined for the partition containing path.
116 *
117 * Check isValid() to see if the process was successful. Then
118 * use mountPoint(), size(), available(), and used() to access
119 * the requested values.
120 */
121 static KDiskFreeSpaceInfo freeSpaceInfo( const QString& path );
122
123private:
124 KDiskFreeSpaceInfo();
125
126 class Private;
127 QSharedDataPointer<Private> d;
128};
129
130#endif
131
132