Qt 6.x
The Qt SDK
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
49 : d(new QStorageInfoPrivate)
50{
51}
52
69 : d(new QStorageInfoPrivate)
70{
73
79 : d(new QStorageInfoPrivate)
80{
81 setPath(dir.absolutePath());
82}
83
88 : d(other.d)
89{
90}
91
96{
97}
98
103{
104 d = other.d;
105 return *this;
106}
107
130{
131 if (d->rootPath == path)
132 return;
133 d.detach();
134 d->rootPath = path;
135 d->doStat();
136}
137
153{
154 return d->rootPath;
155}
156
169{
170 return d->bytesAvailable;
171}
172
183{
184 return d->bytesFree;
185}
186
195{
196 return d->bytesTotal;
197}
198
207{
208 return d->blockSize;
209}
210
221{
222 return d->fileSystemType;
223}
224
235{
236 return d->device;
237}
238
256{
257 return d->subvolume;
258}
259
273{
274 return d->name;
275}
276
281{
282 if (!d->name.isEmpty())
283 return d->name;
284 return d->rootPath;
285}
286
304{
305 return d->readOnly;
306}
307
318{
319 return d->ready;
320}
321
329{
330 return d->valid;
331}
332
342{
343 d.detach();
344 d->doStat();
345}
346
364{
365 return QStorageInfoPrivate::mountedVolumes();
366}
367
368Q_GLOBAL_STATIC(QStorageInfo, getRoot, QStorageInfoPrivate::root())
369
370
379{
380 return *getRoot();
381}
382
400#ifndef QT_NO_DEBUG_STREAM
402{
403 QDebugStateSaver saver(debug);
404 debug.nospace();
405 debug.noquote();
406 debug << "QStorageInfo(";
407 if (s.isValid()) {
408 const QStorageInfoPrivate *d = s.d.constData();
409 debug << '"' << d->rootPath << '"';
410 if (!d->fileSystemType.isEmpty())
411 debug << ", type=" << d->fileSystemType;
412 if (!d->name.isEmpty())
413 debug << ", name=\"" << d->name << '"';
414 if (!d->device.isEmpty())
415 debug << ", device=\"" << d->device << '"';
416 if (!d->subvolume.isEmpty())
417 debug << ", subvolume=\"" << d->subvolume << '"';
418 if (d->readOnly)
419 debug << " [read only]";
420 debug << (d->ready ? " [ready]" : " [not ready]");
421 if (d->bytesTotal > 0) {
422 debug << ", bytesTotal=" << d->bytesTotal << ", bytesFree=" << d->bytesFree
423 << ", bytesAvailable=" << d->bytesAvailable;
424 }
425 } else {
426 debug << "invalid";
427 }
428 debug << ')';
429 return debug;
430}
431#endif // !QT_NO_DEBUG_STREAM
432
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qdir.h:19
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
Definition qlist.h:74
\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:127
Combined button and popup list for selecting options.
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define QT_IMPL_METATYPE_EXTERN(TYPE)
Definition qmetatype.h:1369
GLsizei const GLchar *const * path
GLdouble s
[6]
Definition qopenglext.h:235
QDebug operator<<(QDebug debug, const QStorageInfo &s)
long long qint64
Definition qtypes.h:55
QSharedPointer< T > other(t)
[5]
QString dir
[11]