Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rainemak committed Sep 26, 2018
1 parent ec94f5b commit 6b51155
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/partitionmanager.cpp
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion src/partitionmanager_p.h
Expand Up @@ -70,7 +70,7 @@ class PartitionManagerPrivate : public QObject, public QSharedData
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;

Expand Down
26 changes: 23 additions & 3 deletions src/partitionmodel.cpp
Expand Up @@ -37,6 +37,7 @@

#include <QDir>
#include <QFileInfo>
#include <QtQml/qqmlinfo.h>

PartitionModel::PartitionModel(QObject *parent)
: QAbstractListModel(parent)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/partitionmodel.h
Expand Up @@ -131,7 +131,7 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel
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;

Expand Down
13 changes: 2 additions & 11 deletions src/udisks2monitor.cpp
Expand Up @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/udisks2monitor_p.h
Expand Up @@ -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)
Expand All @@ -66,7 +66,7 @@ struct Operation
QString devicePath;
QString dbusObjectPath;
QString type;
QVariantHash arguments;
QVariantMap arguments;
};

class Monitor : public QObject
Expand All @@ -84,7 +84,7 @@ class Monitor : public QObject
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;

Expand Down Expand Up @@ -114,7 +114,7 @@ private slots:
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:
Expand Down

0 comments on commit 6b51155

Please sign in to comment.