diff options
Diffstat (limited to 'tests/manual/qstorageinfo')
-rw-r--r-- | tests/manual/qstorageinfo/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/manual/qstorageinfo/main.cpp | 4 | ||||
-rw-r--r-- | tests/manual/qstorageinfo/printvolumes.cpp | 28 |
3 files changed, 21 insertions, 13 deletions
diff --git a/tests/manual/qstorageinfo/CMakeLists.txt b/tests/manual/qstorageinfo/CMakeLists.txt index 12437d4b41..a72cc2d92c 100644 --- a/tests/manual/qstorageinfo/CMakeLists.txt +++ b/tests/manual/qstorageinfo/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qstorageinfo.pro. - ##################################################################### ## qstorageinfo Binary: ##################################################################### diff --git a/tests/manual/qstorageinfo/main.cpp b/tests/manual/qstorageinfo/main.cpp index a2fd95129c..f6890b0c3b 100644 --- a/tests/manual/qstorageinfo/main.cpp +++ b/tests/manual/qstorageinfo/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 Intel Corporation -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QCoreApplication> @@ -15,7 +15,7 @@ int main(int argc, char *argv[]) QStringList args = a.arguments(); args.takeFirst(); // skip application name - foreach (const QString &path, args) { + for (const QString &path : std::as_const(args)) { QStorageInfo info(path); if (!info.isValid()) { // no error string... diff --git a/tests/manual/qstorageinfo/printvolumes.cpp b/tests/manual/qstorageinfo/printvolumes.cpp index 5e4fdd4863..d6bf9dab52 100644 --- a/tests/manual/qstorageinfo/printvolumes.cpp +++ b/tests/manual/qstorageinfo/printvolumes.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 Intel Corporation -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QStorageInfo> @@ -12,21 +12,31 @@ void printVolumes(const QList<QStorageInfo> &volumes, int (*printer)(const char // 214958080 39088272 4096 / // /dev/disk1s2 (hfs) RW 488050672 419909696 4096 Macintosh HD2 /Volumes/Macintosh HD2 - printer("Filesystem (Type) Size Available BSize Label Mounted on\n"); - foreach (const QStorageInfo &info, volumes) { + int fsColumnWidth = 25; + int labelColumnWidth = 20; + for (const QStorageInfo &info : volumes) { + int len = 3 + info.device().size() + info.fileSystemType().size(); + fsColumnWidth = qMax(fsColumnWidth, len); + if (QString subvol = info.subvolume(); !subvol.isEmpty()) + labelColumnWidth = qMax(labelColumnWidth, int(subvol.size() + strlen("subvol="))); + else + labelColumnWidth = qMax(labelColumnWidth, int(info.name().size())); + } + + printer("%*s Size Available BSize %*s Mounted on\n", + -fsColumnWidth, "Filesystem (Type)", + -labelColumnWidth, "Label"); + for (const QStorageInfo &info : volumes) { QByteArray fsAndType = info.device(); if (info.fileSystemType() != fsAndType) fsAndType += " (" + info.fileSystemType() + ')'; - printer("%-19s R%c ", fsAndType.constData(), info.isReadOnly() ? 'O' : 'W'); - if (fsAndType.size() > 19) - printer("\n%23s", ""); - + printer("%*s R%c ", -fsColumnWidth, fsAndType.constData(), info.isReadOnly() ? 'O' : 'W'); printer("%10llu %10llu %5u ", info.bytesTotal() / 1024, info.bytesFree() / 1024, info.blockSize()); if (!info.subvolume().isEmpty()) - printer("subvol=%-18s ", qPrintable(info.subvolume())); + printer("subvol=%*s ", -labelColumnWidth + int(strlen("subvol=")), qPrintable(info.subvolume())); else - printer("%-25s ", qPrintable(info.name())); + printer("%*s ", -labelColumnWidth, qPrintable(info.name())); printer("%s\n", qPrintable(info.rootPath())); } } |