Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qstorageinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// Copyright (C) 2015 Ivan Komissarov <ABBAPOH@gmail.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "qstorageinfo.h"
6#include "qstorageinfo_p.h"
7
8#include "qdebug.h"
9
11
13
14
42QStorageInfo::QStorageInfo(QStorageInfoPrivate &dd)
43 : d(&dd)
44{
45}
46
56 : d(new QStorageInfoPrivate)
57{
58}
59
76 : d(new QStorageInfoPrivate)
77{
79}
80
86 : d(new QStorageInfoPrivate)
87{
88 setPath(dir.absolutePath());
89}
90
98
105
110{
111 d = other.d;
112 return *this;
113}
114
137{
138 if (d->rootPath == path)
139 return;
140 d.detach();
141 d->rootPath = path;
142 d->doStat();
143}
144
160{
161 return d->rootPath;
162}
163
176{
177 return d->bytesAvailable;
178}
179
190{
191 return d->bytesFree;
192}
193
202{
203 return d->bytesTotal;
204}
205
214{
215 return d->blockSize;
216}
217
228{
229 return d->fileSystemType;
230}
231
242{
243 return d->device;
244}
245
263{
264 return d->subvolume;
265}
266
280{
281 return d->name;
282}
283
288{
289 if (!d->name.isEmpty())
290 return d->name;
291 return d->rootPath;
292}
293
311{
312 return d->readOnly;
313}
314
325{
326 return d->ready;
327}
328
336{
337 return d->valid;
338}
339
349{
350 d.detach();
351 d->doStat();
352}
353
370QList<QStorageInfo> QStorageInfo::mountedVolumes()
371{
372 return QStorageInfoPrivate::mountedVolumes();
373}
374
375Q_GLOBAL_STATIC(QStorageInfo, getRoot, QStorageInfoPrivate::root())
376
377
386{
387 return *getRoot();
388}
389
407bool comparesEqual(const QStorageInfo &lhs, const QStorageInfo &rhs)
408{
409 if (lhs.d == rhs.d)
410 return true;
411 return lhs.device() == rhs.device() && lhs.rootPath() == rhs.rootPath();
412}
413
414#ifndef QT_NO_DEBUG_STREAM
416{
417 QDebugStateSaver saver(debug);
418 debug.nospace();
419 debug.noquote();
420 debug << "QStorageInfo(";
421 if (s.isValid()) {
422 const QStorageInfoPrivate *d = s.d.constData();
423 debug << '"' << d->rootPath << '"';
424 if (!d->fileSystemType.isEmpty())
425 debug << ", type=" << d->fileSystemType;
426 if (!d->name.isEmpty())
427 debug << ", name=\"" << d->name << '"';
428 if (!d->device.isEmpty())
429 debug << ", device=\"" << d->device << '"';
430 if (!d->subvolume.isEmpty())
431 debug << ", subvolume=\"" << d->subvolume << '"';
432 if (d->readOnly)
433 debug << " [read only]";
434 debug << (d->ready ? " [ready]" : " [not ready]");
435 if (d->bytesTotal > 0) {
436 debug << ", bytesTotal=" << d->bytesTotal << ", bytesFree=" << d->bytesFree
437 << ", bytesAvailable=" << d->bytesAvailable;
438 }
439 } else {
440 debug << "invalid";
441 }
442 debug << ')';
443 return debug;
444}
445#endif // !QT_NO_DEBUG_STREAM
446
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qdir.h:20
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
\inmodule QtCore
static QList< QStorageInfo > mountedVolumes()
Returns the list of QStorageInfo objects that corresponds to the list of currently mounted filesystem...
~QStorageInfo()
Destroys the QStorageInfo object and frees its resources.
QString name() const
Returns the human-readable name of a filesystem, usually called label.
void refresh()
Resets QStorageInfo's internal cache.
qint64 bytesTotal() const
Returns the total volume size in bytes.
qint64 bytesFree() const
Returns the number of free bytes in a volume.
bool isValid() const
Returns true if the QStorageInfo specified by rootPath exists and is mounted correctly.
qint64 bytesAvailable() const
Returns the size (in bytes) available for the current user.
QString displayName() const
Returns the volume's name, if available, or the root path if not.
bool isReady() const
Returns true if the current filesystem is ready to work; false otherwise.
int blockSize() const
QByteArray device() const
Returns the device for this volume.
QString rootPath() const
Returns the mount point of the filesystem this QStorageInfo object represents.
QStorageInfo & operator=(const QStorageInfo &other)
Makes a copy of the QStorageInfo object other and assigns it to this QStorageInfo object.
QByteArray subvolume() const
QByteArray fileSystemType() const
Returns the type name of the filesystem.
bool isReadOnly() const
Returns true if the current filesystem is protected from writing; false otherwise.
void setPath(const QString &path)
Sets this QStorageInfo object to the filesystem mounted where path is located.
QStorageInfo()
Constructs an empty QStorageInfo object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define QT_IMPL_METATYPE_EXTERN(TYPE)
Definition qmetatype.h:1390
GLdouble s
[6]
Definition qopenglext.h:235
GLsizei const GLchar *const * path
QDebug operator<<(QDebug debug, const QStorageInfo &s)
bool comparesEqual(const QStorageInfo &lhs, const QStorageInfo &rhs)
long long qint64
Definition qtypes.h:60
QSharedPointer< T > other(t)
[5]
QString dir
[11]