Commit e091ed13 authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb42963' into 'master'

Stay in formatting state until filesystem/encrypted interface appear

See merge request mer-core/nemo-qml-plugin-systemsettings!82
parents ec94f5bf 035ce6b7
...@@ -317,12 +317,12 @@ void PartitionManagerPrivate::unmount(const Partition &partition) ...@@ -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 &filesystemType, const QVariantMap &arguments)
{ {
QString deviceName = devicePath.section(QChar('/'), 2); QString deviceName = devicePath.section(QChar('/'), 2);
qCInfo(lcMemoryCardLog) << "Can format:" << externalMedia.match(deviceName).hasMatch() << devicePath; qCInfo(lcMemoryCardLog) << "Can format:" << externalMedia.match(deviceName).hasMatch() << devicePath;
if (externalMedia.match(deviceName).hasMatch()) { if (externalMedia.match(deviceName).hasMatch()) {
m_udisksMonitor->instance()->format(devicePath, type, label, passphrase); m_udisksMonitor->instance()->format(devicePath, filesystemType, arguments);
} else { } else {
qCWarning(lcMemoryCardLog) << "Formatting allowed only for external memory cards," << devicePath << "is not allowed"; qCWarning(lcMemoryCardLog) << "Formatting allowed only for external memory cards," << devicePath << "is not allowed";
} }
......
...@@ -70,7 +70,7 @@ public: ...@@ -70,7 +70,7 @@ public:
void unlock(const Partition &partition, const QString &passphrase); void unlock(const Partition &partition, const QString &passphrase);
void mount(const Partition &partition); void mount(const Partition &partition);
void unmount(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 &filesystemType, const QVariantMap &arguments);
QString objectPath(const QString &devicePath) const; QString objectPath(const QString &devicePath) const;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QtQml/qqmlinfo.h>
PartitionModel::PartitionModel(QObject *parent) PartitionModel::PartitionModel(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
...@@ -155,10 +156,29 @@ void PartitionModel::unmount(const QString &devicePath) ...@@ -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(); QString filesystemType = arguments.value(QLatin1String("filesystemType"), QString()).toString();
m_manager->format(devicePath, type, label, passphrase); if (filesystemType.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 << filesystemType << args << m_partitions.count();
m_manager->format(devicePath, filesystemType, args);
} }
QString PartitionModel::objectPath(const QString &devicePath) const QString PartitionModel::objectPath(const QString &devicePath) const
......
...@@ -131,7 +131,7 @@ public: ...@@ -131,7 +131,7 @@ public:
Q_INVOKABLE void unlock(const QString &devicePath, const QString &passphrase); Q_INVOKABLE void unlock(const QString &devicePath, const QString &passphrase);
Q_INVOKABLE void mount(const QString &devicePath); Q_INVOKABLE void mount(const QString &devicePath);
Q_INVOKABLE void unmount(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; Q_INVOKABLE QString objectPath(const QString &devicePath) const;
......
...@@ -67,6 +67,10 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap & ...@@ -67,6 +67,10 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
// We have either org.freedesktop.UDisks2.Filesystem or org.freedesktop.UDisks2.Encrypted interface. // We have either org.freedesktop.UDisks2.Filesystem or org.freedesktop.UDisks2.Encrypted interface.
complete(); complete();
} }
connect(this, &Block::completed, this, [this]() {
clearFormattingState();
});
} }
// Use when morphing a block e.g. updating encrypted block to crypto backing block device (e.i. to a block that implements file system). // Use when morphing a block e.g. updating encrypted block to crypto backing block device (e.i. to a block that implements file system).
...@@ -102,6 +106,8 @@ UDisks2::Block &UDisks2::Block::operator=(const UDisks2::Block &other) ...@@ -102,6 +106,8 @@ UDisks2::Block &UDisks2::Block::operator=(const UDisks2::Block &other)
m_mountable = other.m_mountable; m_mountable = other.m_mountable;
m_mountPath = other.m_mountPath; m_mountPath = other.m_mountPath;
m_encrypted = other.m_encrypted; m_encrypted = other.m_encrypted;
m_formatting = other.m_formatting;
m_locking = other.m_locking;
return *this; return *this;
} }
...@@ -169,16 +175,14 @@ bool UDisks2::Block::isEncrypted() const ...@@ -169,16 +175,14 @@ bool UDisks2::Block::isEncrypted() const
return m_encrypted; return m_encrypted;
} }
void UDisks2::Block::setEncrypted(bool encrypted) bool UDisks2::Block::setEncrypted(bool encrypted)
{ {
if (m_encrypted != encrypted) { if (m_encrypted != encrypted) {
m_encrypted = encrypted; m_encrypted = encrypted;
blockSignals(true);
setMountable(!m_encrypted);
blockSignals(false);
emit updated(); emit updated();
return true;
} }
return false;
} }
bool UDisks2::Block::isMountable() const bool UDisks2::Block::isMountable() const
...@@ -186,23 +190,29 @@ bool UDisks2::Block::isMountable() const ...@@ -186,23 +190,29 @@ bool UDisks2::Block::isMountable() const
return m_mountable; return m_mountable;
} }
void UDisks2::Block::setMountable(bool mountable) bool UDisks2::Block::setMountable(bool mountable)
{ {
if (m_mountable != mountable) { if (m_mountable != mountable) {
m_mountable = mountable; m_mountable = mountable;
if (m_mountable && m_formatting) {
m_formatting = false;
emit formatted();
}
emit updated(); emit updated();
return true;
} }
return false;
} }
void UDisks2::Block::setFormatting() bool UDisks2::Block::isFormatting() const
{ {
m_formatting = true; return m_formatting;
}
bool UDisks2::Block::setFormatting(bool formatting)
{
if (m_formatting != formatting) {
m_formatting = formatting;
emit updated();
return true;
}
return false;
} }
bool UDisks2::Block::isLocking() const bool UDisks2::Block::isLocking() const
...@@ -289,17 +299,23 @@ void UDisks2::Block::updateProperties(const QDBusMessage &message) ...@@ -289,17 +299,23 @@ void UDisks2::Block::updateProperties(const QDBusMessage &message)
QString interface = arguments.value(0).toString(); QString interface = arguments.value(0).toString();
if (interface == UDISKS2_BLOCK_INTERFACE) { if (interface == UDISKS2_BLOCK_INTERFACE) {
QVariantMap changedProperties = NemoDBus::demarshallArgument<QVariantMap>(arguments.value(1)); QVariantMap changedProperties = NemoDBus::demarshallArgument<QVariantMap>(arguments.value(1));
qCInfo(lcMemoryCardLog) << "Changed properties:" << changedProperties; for (QMap<QString, QVariant>::const_iterator i = changedProperties.constBegin(); i != changedProperties.constEnd(); ++i) {
for (QMap<QString, QVariant>::const_iterator i = changedProperties.begin(); i != changedProperties.end(); ++i) {
m_data.insert(i.key(), i.value()); m_data.insert(i.key(), i.value());
} }
if (!clearFormattingState()) {
emit updated(); emit updated();
}
} else if (interface == UDISKS2_FILESYSTEM_INTERFACE) { } else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
m_mountable = true;
updateMountPoint(arguments.value(1)); updateMountPoint(arguments.value(1));
} }
} }
bool UDisks2::Block::isCompleted() const
{
return !m_pendingFileSystem && !m_pendingBlock && !m_pendingEncrypted;
}
void UDisks2::Block::updateMountPoint(const QVariant &mountPoints) void UDisks2::Block::updateMountPoint(const QVariant &mountPoints)
{ {
QVariantMap mountPointsMap = NemoDBus::demarshallArgument<QVariantMap>(mountPoints); QVariantMap mountPointsMap = NemoDBus::demarshallArgument<QVariantMap>(mountPoints);
...@@ -313,17 +329,35 @@ void UDisks2::Block::updateMountPoint(const QVariant &mountPoints) ...@@ -313,17 +329,35 @@ void UDisks2::Block::updateMountPoint(const QVariant &mountPoints)
} }
} }
qCInfo(lcMemoryCardLog) << "New file system mount points:" << mountPoints << "resolved mount path: " << m_mountPath; bool triggerUpdate = false;
blockSignals(true);
triggerUpdate = setMountable(true);
triggerUpdate |= clearFormattingState();
blockSignals(false);
if (triggerUpdate) {
emit updated();
}
qCInfo(lcMemoryCardLog) << "New file system mount points:" << mountPoints << "resolved mount path: " << m_mountPath << "trigger update:" << triggerUpdate;
emit mountPathChanged(); emit mountPathChanged();
} }
void UDisks2::Block::complete() void UDisks2::Block::complete()
{ {
if (!m_pendingFileSystem && !m_pendingBlock && !m_pendingEncrypted) { if (isCompleted()) {
QMetaObject::invokeMethod(this, "completed", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "completed", Qt::QueuedConnection);
} }
} }
bool UDisks2::Block::clearFormattingState()
{
if (isCompleted() && isMountable() && isFormatting()) {
return setFormatting(false);
}
return false;
}
void UDisks2::Block::getFileSystemInterface() void UDisks2::Block::getFileSystemInterface()
{ {
QDBusInterface dbusPropertyInterface(UDISKS2_SERVICE, QDBusInterface dbusPropertyInterface(UDISKS2_SERVICE,
...@@ -336,7 +370,6 @@ void UDisks2::Block::getFileSystemInterface() ...@@ -336,7 +370,6 @@ void UDisks2::Block::getFileSystemInterface()
if (watcher->isValid() && watcher->isFinished()) { if (watcher->isValid() && watcher->isFinished()) {
QDBusPendingReply<> reply = *watcher; QDBusPendingReply<> reply = *watcher;
QDBusMessage message = reply.reply(); QDBusMessage message = reply.reply();
m_mountable = true;
updateMountPoint(message.arguments().at(0)); updateMountPoint(message.arguments().at(0));
} else { } else {
QDBusError error = watcher->error(); QDBusError error = watcher->error();
...@@ -359,8 +392,6 @@ void UDisks2::Block::getEncryptedInterface() ...@@ -359,8 +392,6 @@ void UDisks2::Block::getEncryptedInterface()
m_pendingEncrypted = new QDBusPendingCallWatcher(pendingCall, this); m_pendingEncrypted = new QDBusPendingCallWatcher(pendingCall, this);
connect(m_pendingEncrypted, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { connect(m_pendingEncrypted, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
if (watcher->isValid() && watcher->isFinished()) { if (watcher->isValid() && watcher->isFinished()) {
QDBusPendingReply<> reply = *watcher;
QDBusMessage message = reply.reply();
m_encrypted = true; m_encrypted = true;
} else { } else {
QDBusError error = watcher->error(); QDBusError error = watcher->error();
......
...@@ -68,13 +68,13 @@ public: ...@@ -68,13 +68,13 @@ public:
QString cryptoBackingDeviceObjectPath() const; QString cryptoBackingDeviceObjectPath() const;
bool isEncrypted() const; bool isEncrypted() const;
void setEncrypted(bool encrypted); bool setEncrypted(bool encrypted);
bool isMountable() const; bool isMountable() const;
void setMountable(bool mountable); bool setMountable(bool mountable);
bool isFormatting() const; bool isFormatting() const;
void setFormatting(); bool setFormatting(bool formatting);
bool isLocking() const; bool isLocking() const;
void setLocking(); void setLocking();
...@@ -107,8 +107,11 @@ private slots: ...@@ -107,8 +107,11 @@ private slots:
void updateProperties(const QDBusMessage &message); void updateProperties(const QDBusMessage &message);
private: private:
bool isCompleted() const;
void updateMountPoint(const QVariant &mountPoints); void updateMountPoint(const QVariant &mountPoints);
void complete(); void complete();
bool clearFormattingState();
void getFileSystemInterface(); void getFileSystemInterface();
void getEncryptedInterface(); void getEncryptedInterface();
......
This diff is collapsed.
...@@ -54,19 +54,19 @@ class Job; ...@@ -54,19 +54,19 @@ class Job;
struct Operation 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 &filesystemType = QString(), const QVariantMap &arguments = QVariantMap())
: command(command) : command(command)
, devicePath(devicePath) , devicePath(devicePath)
, dbusObjectPath(dbusObjectPath) , dbusObjectPath(dbusObjectPath)
, type(type) , filesystemType(filesystemType)
, arguments(arguments) , arguments(arguments)
{} {}
QString command; QString command;
QString devicePath; QString devicePath;
QString dbusObjectPath; QString dbusObjectPath;
QString type; QString filesystemType;
QVariantHash arguments; QVariantMap arguments;
}; };
class Monitor : public QObject class Monitor : public QObject
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
void mount(const QString &devicePath); void mount(const QString &devicePath);
void unmount(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 &filesystemType, const QVariantMap &arguments);
QString objectPath(const QString &devicePath) const; QString objectPath(const QString &devicePath) const;
...@@ -100,11 +100,12 @@ signals: ...@@ -100,11 +100,12 @@ signals:
private slots: private slots:
void interfacesAdded(const QDBusObjectPath &objectPath, const UDisks2::InterfacePropertyMap &interfaces); void interfacesAdded(const QDBusObjectPath &objectPath, const UDisks2::InterfacePropertyMap &interfaces);
void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces); void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces);
void doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &filesystemType, const QVariantMap &arguments);
private: private:
void setPartitionProperties(QExplicitlySharedDataPointer<PartitionPrivate> &partition, const UDisks2::Block *blockDevice); void setPartitionProperties(QExplicitlySharedDataPointer<PartitionPrivate> &partition, const Block *blockDevice);
void updatePartitionProperties(const UDisks2::Block *blockDevice); void updatePartitionProperties(const Block *blockDevice);
void updatePartitionStatus(const UDisks2::Job *job, bool success); void updatePartitionStatus(const Job *job, bool success);
bool externalBlockDevice(const QString &objectPathStr) const; bool externalBlockDevice(const QString &objectPathStr) const;
void startLuksOperation(const QString &devicePath, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments); void startLuksOperation(const QString &devicePath, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments);
...@@ -112,17 +113,18 @@ private: ...@@ -112,17 +113,18 @@ private:
void lookupPartitions(PartitionManagerPrivate::Partitions &affectedPartitions, const QStringList &objects); void lookupPartitions(PartitionManagerPrivate::Partitions &affectedPartitions, const QStringList &objects);
void createPartition(const Block *block); void createPartition(const Block *block);
void createBlockDevice(const QString &dbusObjectPath, const UDisks2::InterfacePropertyMap &interfacePropertyMap); Block *createBlockDevice(const QString &dbusObjectPath, const UDisks2::InterfacePropertyMap &interfacePropertyMap);
void doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &type, const QVariantHash &arguments);
void getBlockDevices(); void getBlockDevices();
Block *findBlock(const QString &devicePath) const;
private: private:
static Monitor *sharedInstance; static Monitor *sharedInstance;
QExplicitlySharedDataPointer<PartitionManagerPrivate> m_manager; QExplicitlySharedDataPointer<PartitionManagerPrivate> m_manager;
QMap<QString, UDisks2::Job *> m_jobsToWait; QMap<QString, Job *> m_jobsToWait;
QMap<QString, UDisks2::Block *> m_blockDevices; QMap<QString, Block *> m_blockDevices;
QQueue<Operation> m_operationQueue; QQueue<Operation> m_operationQueue;
}; };
......
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