summaryrefslogtreecommitdiffstats
path: root/src/systeminfo/qsystemstorageinfo.cpp
blob: 8aad3c189106825e8e236157e8597ccd8d88655d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qsystemstorageinfo.h"
#include "qsysteminfocommon_p.h"
#include <QMetaType>

QTM_BEGIN_NAMESPACE
#ifndef Q_OS_SYMBIAN
Q_GLOBAL_STATIC(QSystemStorageInfoPrivate, storageInfoPrivateSingleton)
#endif

#ifdef QT_SIMULATOR
QSystemStorageInfoPrivate *getSystemStorageInfoPrivate() { return storageInfoPrivateSingleton(); }
#endif // QT_SIMULATOR

/*!
    \class QSystemStorageInfo
    \ingroup systeminfo
    \inmodule QtSystemInfo
    \brief The QSystemStorageInfo class provides access to disk storage information from the system.
    \since 1.1


    \reentrant

    \note Most functions in this class are reentrant on all platforms. The exceptions are listed below.
    
    \note In Symbian platform this class is not reentrant since Symbian Belle (Qt Mobility version 1.2).

    \warning On Symbian this class does not support QObject::moveToThread().
*/

/*!
    \enum QSystemStorageInfo::DriveType
    This enum describes the type of drive or volume

    \value NoDrive               Drive type undetermined.
    \value InternalDrive         Is internal mass storage drive like a hard drive.
    \value RemovableDrive        Is a removable disk like MMC.
    \value RemoteDrive           Is a network drive.
    \value CdromDrive            Is a cd rom drive.
    \value InternalFlashDrive    Is an internal flash disk, or Phone Memory. Since 1.2
    \value RamDrive              Is a virtual drive made in RAM memory. Since 1.2
*/

/*!
    \enum QSystemStorageInfo::StorageState
    This enum describes the state of the storage level of drive or volume.

    \value UnknownStorageState         Storage level indicates an error, offline or unknown.
    \value NormalStorageState          Storage level indicates normal.
    \value LowStorageState             Storage level indicates below 40%.
    \value VeryLowStorageState         Storage level indicates below 10%.
    \value CriticalStorageState        Storage level indicates below 2%.
*/

/*!
    \fn void QSystemStorageInfo::logicalDriveChanged(bool added, const QString &drive)

    This signal gets emitted when a new \a drive storage has been added or removed. If \a added is true,
    it means a new drive is found, otherwise a drive is removed.
    \since 1.1
*/

/*!
    \fn void QSystemStorageInfo::storageStateChanged(const QString &drive, QSystemStorageInfo::StorageState state)

    This signal gets emitted when the storage state of a \a drive has changed to \a state. Note that the
    polling time may be different for different platforms.
    \since 1.2
*/

/*!
    \qmlclass StorageInfo
    \brief The StorageInfo element provides access to disk storage information from the system.

    \ingroup qml-systeminfo
    \since Mobility 1.2

    This element is part of the \bold{QtMobility.systeminfo 1.2} module.
    It is a convience class to make QML usage easier.

    \sa QSystemStorageInfo
*/

/*!
  \qmlproperty list StorageInfo::logicalDrives
  \since Mobility 1.2

  Returns list of logical drives.
  */

/*!
  \qmlmethod long StorageInfo::totalDiskSpace(string drive)
  \since Mobility 1.2

  Returns the amount of total space on the given drive, in bytes.
  */

/*!
  \qmlmethod long StorageInfo::availableDiskSpace(string drive)
  \since Mobility 1.2

  Returns the available disk space on the given drive, in bytes.
*/

/*!
    \qmlmethod string StorageInfo::uriForDrive(string drive)
    \since Mobility 1.2

    Returns the URI, or unique identifier for the given drive.
*/

/*!
    \qmlmethod StorageState StorageInfo::getStorageState(string drive)
    \since Mobility 1.2

    Returns the storage state of the given drive.

    \sa QSystemStorageInfo::StorageState
*/

/*!
    \qmlmethod DriveType StorageInfo::typeForDrive(string drive)
    \since Mobility 1.2

    Returns the type of the given drive.

    \sa QSystemStorageInfo::DriveType
*/

/*!
    \qmlsignal StorageInfo::logicalDriveChanged(bool added, string drive)
    \since Mobility 1.2

    This signal gets emitted when a new drive storage has been added or removed. If \a bool is true,
    it means a new drive is found, otherwise a drive is removed.
 */

/*!
    \qmlsignal StorageInfo::storageStateChanged(string drive, QSystemStorageInfo::StorageState state)
    \since Mobility 1.2

    This signal gets emitted when the storage state of a drive has changed to state. Note that the
    polling time may be different for different platforms.
 */


/*!
    Constructs a QSystemStorageInfo with the given \a parent.
*/
QSystemStorageInfo::QSystemStorageInfo(QObject *parent)
    : QObject(parent)
{
#ifdef Q_OS_SYMBIAN
    d = new QSystemStorageInfoPrivate();
#else
    d = storageInfoPrivateSingleton();
#endif
    qRegisterMetaType<QSystemStorageInfo::DriveType>("QSystemStorageInfo::DriveType");
    qRegisterMetaType<QSystemStorageInfo::StorageState>("QSystemStorageInfo::StorageState");
}

/*!
    Destroys the QSystemStorageInfo object.
*/
QSystemStorageInfo::~QSystemStorageInfo()
{
#ifdef Q_OS_SYMBIAN
    delete d;
#endif
}

/*!
    Returns the amount of total space on the \a drive, in bytes.
*/
qlonglong QSystemStorageInfo::totalDiskSpace(const QString &drive)
{
    return d->totalDiskSpace(drive);
}

/*!
    Returns the amount of available free space on the \a drive, in bytes.
*/
qlonglong QSystemStorageInfo::availableDiskSpace(const QString &drive)
{
    return d->availableDiskSpace(drive);
}

/*!
    \property QSystemStorageInfo::logicalDrives
    \brief The  list of logical drives.

    Returns a QStringList of drives or volumes, or an empty list if no drives are found.

    \warning On Symbian this function is not reentrant and must be used from main thread only.
*/
QStringList QSystemStorageInfo::logicalDrives()
{
#ifdef Q_OS_SYMBIAN
        QSystemStorageInfoPrivate* storageInfo = QSystemStorageInfoPrivate::storageinfoPrivateInstance();
        QStringList drivelist = storageInfo->logicalDrives();
        delete storageInfo;
        return drivelist;
#else
    return storageInfoPrivateSingleton()->logicalDrives();
#endif
}

/*!
    Returns the type of the give \a drive.
*/
QSystemStorageInfo::DriveType QSystemStorageInfo::typeForDrive(const QString &drive)
{
    return d->typeForDrive(drive);
}

/*!
    Returns the URI, or unique identifier for the given \a drive.
    \since 1.2
*/
QString QSystemStorageInfo::uriForDrive(const QString &drive)
{
    return d->uriForDrive(drive);
}

/*!
    Returns the storage state of the given \a drive.
    \since 1.2
*/
QSystemStorageInfo::StorageState QSystemStorageInfo::getStorageState(const QString &drive)
{
    return d->getStorageState(drive);
}

/*!
    \internal
*/
void QSystemStorageInfo::connectNotify(const char *signal)
{
     if (QLatin1String(signal) ==
        QLatin1String(QMetaObject::normalizedSignature(SIGNAL(logicalDriveChanged(bool, const QString &))))) {
         connect(d, SIGNAL(logicalDriveChanged(bool,QString)),
                 this, SIGNAL(logicalDriveChanged(bool,QString)), Qt::UniqueConnection);
     }
     if (QLatin1String(signal) == SIGNAL(logicalDriveChanged(bool,QString))) {
         connect(d, SIGNAL(storageStateChanged(const QString &,QSystemStorageInfo::StorageState)),
                 this, SIGNAL(storageStateChanged(const QString &,QSystemStorageInfo::StorageState)),Qt::UniqueConnection);
     }
}

#include "moc_qsystemstorageinfo.cpp"

QTM_END_NAMESPACE