Commit 6b51155e authored by Raine Makelainen's avatar Raine Makelainen

Change format method to take QVariantMap

This makes usage clearer on QML side. The only supported values
are "label" and "encrypt-passphrase".

This introduces "auto-mount" variable as well but that's not yet
in use.
parent ec94f5bf
......@@ -317,12 +317,12 @@ void PartitionManagerPrivate::unmount(const Partition &partition)
}
}
void PartitionManagerPrivate::format(const QString &devicePath, const QString &type, const QString &label, const QString &passphrase)
void PartitionManagerPrivate::format(const QString &devicePath, const QString &type, const QVariantMap &arguments)
{
QString deviceName = devicePath.section(QChar('/'), 2);
qCInfo(lcMemoryCardLog) << "Can format:" << externalMedia.match(deviceName).hasMatch() << devicePath;
if (externalMedia.match(deviceName).hasMatch()) {
m_udisksMonitor->instance()->format(devicePath, type, label, passphrase);
m_udisksMonitor->instance()->format(devicePath, type, arguments);
} else {
qCWarning(lcMemoryCardLog) << "Formatting allowed only for external memory cards," << devicePath << "is not allowed";
}
......
......@@ -70,7 +70,7 @@ public:
void unlock(const Partition &partition, const QString &passphrase);
void mount(const Partition &partition);
void unmount(const Partition &partition);
void format(const QString &devicePath, const QString &type, const QString &label, const QString &passphrase);
void format(const QString &devicePath, const QString &type, const QVariantMap &arguments);
QString objectPath(const QString &devicePath) const;
......
......@@ -37,6 +37,7 @@
#include <QDir>
#include <QFileInfo>
#include <QtQml/qqmlinfo.h>
PartitionModel::PartitionModel(QObject *parent)
: QAbstractListModel(parent)
......@@ -155,10 +156,29 @@ void PartitionModel::unmount(const QString &devicePath)
}
}
void PartitionModel::format(const QString &devicePath, const QString &type, const QString &label, const QString &passphrase)
void PartitionModel::format(const QString &devicePath, const QVariantMap &arguments)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << type << label << m_partitions.count();
m_manager->format(devicePath, type, label, passphrase);
QString type = arguments.value(QLatin1String("filesystemType"), QString()).toString();
if (type.isEmpty()) {
qmlInfo(this) << "Missing or empty filesystemType argument, cannot format.";
return;
}
// Only fixing invalid args would be enough. Udisks don't care if key is unknown like auto-mount.
QVariantMap args;
args.insert(QLatin1String("label"), arguments.value(QLatin1String("label"), QString()).toString());
args.insert(QLatin1String("no-block"), true);
args.insert(QLatin1String("take-ownership"), true);
args.insert(QLatin1String("update-partition-type"), true);
args.insert(QLatin1String("auto-mount"), arguments.value(QLatin1String("auto-mount"), false).toBool());
QString passphrase = arguments.value(QLatin1String("encrypt-passphrase"), QString()).toString();
if (!passphrase.isEmpty()) {
args.insert(QLatin1String("encrypt.passphrase"), passphrase);
}
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << type << args << m_partitions.count();
m_manager->format(devicePath, type, args);
}
QString PartitionModel::objectPath(const QString &devicePath) const
......
......@@ -131,7 +131,7 @@ public:
Q_INVOKABLE void unlock(const QString &devicePath, const QString &passphrase);
Q_INVOKABLE void mount(const QString &devicePath);
Q_INVOKABLE void unmount(const QString &devicePath);
Q_INVOKABLE void format(const QString &devicePath, const QString &type, const QString &label, const QString &passphrase = QString());
Q_INVOKABLE void format(const QString &devicePath, const QVariantMap &arguments);
Q_INVOKABLE QString objectPath(const QString &devicePath) const;
......
......@@ -182,7 +182,7 @@ void UDisks2::Monitor::unmount(const QString &devicePath)
startMountOperation(devicePath, UDISKS2_FILESYSTEM_UNMOUNT, objectPath(devicePath), arguments);
}
void UDisks2::Monitor::format(const QString &devicePath, const QString &type, const QString &label, const QString &passphrase)
void UDisks2::Monitor::format(const QString &devicePath, const QString &type, const QVariantMap &arguments)
{
if (devicePath.isEmpty()) {
qCCritical(lcMemoryCardLog) << "Cannot format without device name";
......@@ -195,15 +195,6 @@ void UDisks2::Monitor::format(const QString &devicePath, const QString &type, co
return;
}
QVariantHash arguments;
arguments.insert(QStringLiteral("label"), QString(label));
arguments.insert(QStringLiteral("no-block"), true);
arguments.insert(QStringLiteral("take-ownership"), true);
arguments.insert(QStringLiteral("update-partition-type"), true);
if (!passphrase.isEmpty()) {
arguments.insert(QStringLiteral("encrypt.passphrase"), passphrase);
}
const QString objectPath = this->objectPath(devicePath);
PartitionManagerPrivate::Partitions affectedPartitions;
lookupPartitions(affectedPartitions, QStringList() << objectPath);
......@@ -695,7 +686,7 @@ void UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPath, const UD
}
}
void UDisks2::Monitor::doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &type, const QVariantHash &arguments)
void UDisks2::Monitor::doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &type, const QVariantMap &arguments)
{
QDBusInterface blockDeviceInterface(UDISKS2_SERVICE,
dbusObjectPath,
......
......@@ -54,7 +54,7 @@ class Job;
struct Operation
{
Operation(const QString &command, const QString &devicePath, const QString &dbusObjectPath = QString(), const QString &type = QString(), const QVariantHash &arguments = QVariantHash())
Operation(const QString &command, const QString &devicePath, const QString &dbusObjectPath = QString(), const QString &type = QString(), const QVariantMap &arguments = QVariantMap())
: command(command)
, devicePath(devicePath)
, dbusObjectPath(dbusObjectPath)
......@@ -66,7 +66,7 @@ struct Operation
QString devicePath;
QString dbusObjectPath;
QString type;
QVariantHash arguments;
QVariantMap arguments;
};
class Monitor : public QObject
......@@ -84,7 +84,7 @@ public:
void mount(const QString &devicePath);
void unmount(const QString &devicePath);
void format(const QString &devicePath, const QString &type, const QString &label, const QString &passphrase);
void format(const QString &devicePath, const QString &type, const QVariantMap &arguments);
QString objectPath(const QString &devicePath) const;
......@@ -114,7 +114,7 @@ private:
void createPartition(const Block *block);
void createBlockDevice(const QString &dbusObjectPath, const UDisks2::InterfacePropertyMap &interfacePropertyMap);
void doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &type, const QVariantHash &arguments);
void doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &type, const QVariantMap &arguments);
void getBlockDevices();
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment