summaryrefslogtreecommitdiffstats
path: root/tests/manual/qstorageinfo/printvolumes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/qstorageinfo/printvolumes.cpp')
-rw-r--r--tests/manual/qstorageinfo/printvolumes.cpp55
1 files changed, 20 insertions, 35 deletions
diff --git a/tests/manual/qstorageinfo/printvolumes.cpp b/tests/manual/qstorageinfo/printvolumes.cpp
index b56e871109..d6bf9dab52 100644
--- a/tests/manual/qstorageinfo/printvolumes.cpp
+++ b/tests/manual/qstorageinfo/printvolumes.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Intel Corporation
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Intel Corporation
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QStorageInfo>
@@ -37,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()));
}
}