From 918cf2ffa494ca0667a43774b0661c73d6498cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 29 Jul 2016 14:17:36 +0100 Subject: [PATCH] Use more compact syntax for passing and returning kauth helper arguments. --- src/fs/ext2.cpp | 2 +- src/plugins/libparted/helpers/scan.cpp | 75 ++++++++------------ src/plugins/libparted/libpartedbackend.cpp | 17 ++--- src/plugins/libparted/libparteddevice.cpp | 4 +- src/plugins/libparted/libparteddevice.h | 2 +- src/plugins/libparted/libpartedpartition.cpp | 1 - src/plugins/libparted/libpartedpartition.h | 1 - 7 files changed, 42 insertions(+), 60 deletions(-) diff --git a/src/fs/ext2.cpp b/src/fs/ext2.cpp index 533b92d..429cfc7 100644 --- a/src/fs/ext2.cpp +++ b/src/fs/ext2.cpp @@ -1,6 +1,6 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * - * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * diff --git a/src/plugins/libparted/helpers/scan.cpp b/src/plugins/libparted/helpers/scan.cpp index e2d6349..dd65dbb 100644 --- a/src/plugins/libparted/helpers/scan.cpp +++ b/src/plugins/libparted/helpers/scan.cpp @@ -25,28 +25,24 @@ ActionReply Scan::scandevice(const QVariantMap& args) { ActionReply reply; - QString deviceNode = args[QLatin1String("deviceNode")].toString(); - PedDevice* pedDevice = ped_device_get(deviceNode.toLocal8Bit().constData()); + PedDevice* pedDevice = ped_device_get(args[QStringLiteral("deviceNode")].toString().toLocal8Bit().constData()); - QVariantMap returnArgs; if (!pedDevice) { - returnArgs[QLatin1String("pedDeviceError")] = true; - reply.setData(returnArgs); + reply.addData(QStringLiteral("pedDeviceError"), true); return reply; } - returnArgs[QLatin1String("model")] = QString::fromUtf8(pedDevice->model); - returnArgs[QLatin1String("path")] = QString::fromUtf8(pedDevice->path); - returnArgs[QLatin1String("heads")] = pedDevice->bios_geom.heads; - returnArgs[QLatin1String("sectors")] = pedDevice->bios_geom.sectors; - returnArgs[QLatin1String("cylinders")] = pedDevice->bios_geom.cylinders; - returnArgs[QLatin1String("sectorSize")] = pedDevice->sector_size; + reply.addData(QStringLiteral("model"), QString::fromUtf8(pedDevice->model)); + reply.addData(QStringLiteral("path"), QString::fromUtf8(pedDevice->path)); + reply.addData(QStringLiteral("heads"), pedDevice->bios_geom.heads); + reply.addData(QStringLiteral("sectors"), pedDevice->bios_geom.sectors); + reply.addData(QStringLiteral("cylinders"), pedDevice->bios_geom.cylinders); + reply.addData(QStringLiteral("sectorSize"), pedDevice->sector_size); PedDisk* pedDisk = ped_disk_new(pedDevice); if (!pedDisk) { - returnArgs[QLatin1String("pedDiskError")] = true; - reply.setData(returnArgs); + reply.addData(QStringLiteral("pedDiskError"), true); return reply; } @@ -77,13 +73,13 @@ ActionReply Scan::scandevice(const QVariantMap& args) lastUsableSector -= 32; } - returnArgs[QLatin1String("pedDeviceError")] = false; - returnArgs[QLatin1String("pedDiskError")] = false; + reply.addData(QStringLiteral("pedDeviceError"), false); + reply.addData(QStringLiteral("pedDiskError"), false); - returnArgs[QLatin1String("typeName")] = QString::fromUtf8(pedDisk->type->name); - returnArgs[QLatin1String("maxPrimaryPartitionCount")] = ped_disk_get_max_primary_partition_count(pedDisk); - returnArgs[QLatin1String("firstUsableSector")] = firstUsableSector; - returnArgs[QLatin1String("lastUsableSector")] = lastUsableSector; + reply.addData(QStringLiteral("typeName"), QString::fromUtf8(pedDisk->type->name)); + reply.addData(QStringLiteral("maxPrimaryPartitionCount"), ped_disk_get_max_primary_partition_count(pedDisk)); + reply.addData(QStringLiteral("firstUsableSector"), firstUsableSector); + reply.addData(QStringLiteral("lastUsableSector"), lastUsableSector); PedPartition* pedPartition = nullptr; QList partitionPath; @@ -98,7 +94,7 @@ ActionReply Scan::scandevice(const QVariantMap& args) if (pedPartition->num < 1) continue; - partitionPath.append(QLatin1String(ped_partition_get_path(pedPartition))); + partitionPath.append(QString::fromLatin1(ped_partition_get_path(pedPartition))); partitionType.append(pedPartition->type); partitionStart.append(pedPartition->geom.start); partitionEnd.append(pedPartition->geom.end); @@ -134,45 +130,37 @@ ActionReply Scan::scandevice(const QVariantMap& args) // -------------------------------------------------------------------------- } - returnArgs[QLatin1String("availableFlags")] = availableFlags; - returnArgs[QLatin1String("activeFlags")] = activeFlags; - returnArgs[QLatin1String("partitionPath")] = partitionPath; - returnArgs[QLatin1String("partitionType")] = partitionType; - returnArgs[QLatin1String("partitionStart")] = partitionStart; - returnArgs[QLatin1String("partitionEnd")] = partitionEnd; - returnArgs[QLatin1String("partitionBusy")] = partitionBusy; + reply.addData(QStringLiteral("availableFlags"), availableFlags); + reply.addData(QStringLiteral("activeFlags"), activeFlags); + reply.addData(QStringLiteral("partitionPath"), partitionPath); + reply.addData(QStringLiteral("partitionType"), partitionType); + reply.addData(QStringLiteral("partitionStart"), partitionStart); + reply.addData(QStringLiteral("partitionEnd"), partitionEnd); + reply.addData(QStringLiteral("partitionBusy"), partitionBusy); - reply.setData(returnArgs); return reply; } ActionReply Scan::readsectorsused(const QVariantMap& args) { - ActionReply reply; - - QString deviceNode = args[QLatin1String("deviceNode")].toString(); - qint64 firstSector = args[QLatin1String("firstSector")].toLongLong(); qint64 rval = -1; - if (PedDevice* pedDevice = ped_device_get(deviceNode.toLocal8Bit().constData())) + if (PedDevice* pedDevice = ped_device_get(args[QStringLiteral("deviceNode")].toString().toLocal8Bit().constData())) if (PedDisk* pedDisk = ped_disk_new(pedDevice)) - if (PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk, firstSector)) + if (PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk, args[QStringLiteral("firstSector")].toLongLong())) if (PedFileSystem* pedFileSystem = ped_file_system_open(&pedPartition->geom)) if (PedConstraint* pedConstraint = ped_file_system_get_resize_constraint(pedFileSystem)) rval = pedConstraint->min_size; - QVariantMap returnArgs; - returnArgs[QLatin1String("sectorsUsed")] = rval; - - reply.setData(returnArgs); + ActionReply reply; + reply.addData(QStringLiteral("sectorsUsed"), rval); return reply; } ActionReply Scan::detectfilesystem(const QVariantMap& args) { ActionReply reply; - QVariantMap returnArgs; - QString deviceNode = args[QLatin1String("deviceNode")].toString(); + QString deviceNode = args[QStringLiteral("deviceNode")].toString(); blkid_cache cache; if (blkid_get_cache(&cache, nullptr) == 0) { @@ -189,17 +177,16 @@ ActionReply Scan::detectfilesystem(const QVariantMap& args) QString st = QString::fromUtf8(string); free(string); if (st == QStringLiteral("msdos")) - returnArgs[QLatin1String("fileSystem")] = QStringLiteral("fat16"); + reply.addData(QStringLiteral("fileSystem"), QStringLiteral("fat16")); else - returnArgs[QLatin1String("fileSystem")] = QStringLiteral("fat32"); + reply.addData(QStringLiteral("fileSystem"), QStringLiteral("fat32")); } else - returnArgs[QLatin1String("fileSystem")] = s; + reply.addData(QStringLiteral("fileSystem"), s); } blkid_put_cache(cache); } - reply.setData(returnArgs); return reply; } diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 0c9155f..5b87bf3 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -75,12 +75,12 @@ static PedExceptionOption pedExceptionHandler(PedException* e) #if defined LIBPARTED_FS_RESIZE_LIBRARY_SUPPORT static qint64 readSectorsUsedLibParted(const Partition& p) { - QVariantMap args; - args[QLatin1String("deviceNode")] = p.deviceNode(); - args[QLatin1String("firstSector")] = p.firstSector(); - KAuth::Action action = QStringLiteral("org.kde.kpmcore.scan.readsectorsused"); action.setHelperId(QStringLiteral("org.kde.kpmcore.scan")); + QVariantMap args = { + { QStringLiteral("deviceNode"), p.deviceNode() }, + { QStringLiteral("firstSector"), p.firstSector() } + }; action.setArguments(args); KAuth::ExecuteJob *job = action.execute(); if (!job->exec()) { @@ -146,11 +146,9 @@ void LibPartedBackend::initFSSupport() */ Device* LibPartedBackend::scanDevice(const QString& deviceNode) { - QVariantMap args; - args[QLatin1String("deviceNode")] = deviceNode; - KAuth::Action scanAction = QStringLiteral("org.kde.kpmcore.scan.scandevice"); scanAction.setHelperId(QStringLiteral("org.kde.kpmcore.scan")); + QVariantMap args = {{ QStringLiteral("deviceNode"), deviceNode }}; scanAction.setArguments(args); KAuth::ExecuteJob *job = scanAction.execute(); if (!job->exec()) { @@ -354,12 +352,11 @@ FileSystem::Type LibPartedBackend::detectFileSystem(const QString& deviceNode) { FileSystem::Type rval = FileSystem::Unknown; - QVariantMap args; - args[QLatin1String("deviceNode")] = deviceNode; - KAuth::Action action = QStringLiteral("org.kde.kpmcore.scan.detectfilesystem"); action.setHelperId(QStringLiteral("org.kde.kpmcore.scan")); + QVariantMap args = {{ QStringLiteral("deviceNode"), deviceNode }}; action.setArguments(args); + KAuth::ExecuteJob *job = action.execute(); if (!job->exec()) { qWarning() << "KAuth returned an error code: " << job->errorString(); diff --git a/src/plugins/libparted/libparteddevice.cpp b/src/plugins/libparted/libparteddevice.cpp index 0c26540..5a4b33b 100644 --- a/src/plugins/libparted/libparteddevice.cpp +++ b/src/plugins/libparted/libparteddevice.cpp @@ -28,8 +28,8 @@ #include -LibPartedDevice::LibPartedDevice(const QString& device_node) : - CoreBackendDevice(device_node), +LibPartedDevice::LibPartedDevice(const QString& deviceNode) : + CoreBackendDevice(deviceNode), m_PedDevice(nullptr) { } diff --git a/src/plugins/libparted/libparteddevice.h b/src/plugins/libparted/libparteddevice.h index 022fed5..c7737a3 100644 --- a/src/plugins/libparted/libparteddevice.h +++ b/src/plugins/libparted/libparteddevice.h @@ -35,7 +35,7 @@ class LibPartedDevice : public CoreBackendDevice Q_DISABLE_COPY(LibPartedDevice); public: - LibPartedDevice(const QString& device_node); + LibPartedDevice(const QString& deviceNode); ~LibPartedDevice(); public: diff --git a/src/plugins/libparted/libpartedpartition.cpp b/src/plugins/libparted/libpartedpartition.cpp index 1b24f40..f82a8d7 100644 --- a/src/plugins/libparted/libpartedpartition.cpp +++ b/src/plugins/libparted/libpartedpartition.cpp @@ -51,4 +51,3 @@ bool LibPartedPartition::setFlag(Report& report, PartitionTable::Flag partitionM return true; } - diff --git a/src/plugins/libparted/libpartedpartition.h b/src/plugins/libparted/libpartedpartition.h index 0aef94a..1582e2e 100644 --- a/src/plugins/libparted/libpartedpartition.h +++ b/src/plugins/libparted/libpartedpartition.h @@ -46,5 +46,4 @@ private: PedPartition* m_PedPartition; }; - #endif