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

[nemo-systemsettings] Stay in formatting state until filesystem/encrypted...

[nemo-systemsettings] Stay in formatting state until filesystem/encrypted interface appear. Contributes to JB#42963

This also renames bogus type to filesystemType.
parent 607e6c26
......@@ -317,12 +317,12 @@ void PartitionManagerPrivate::unmount(const Partition &partition)
}
}
void PartitionManagerPrivate::format(const QString &devicePath, const QString &type, const QVariantMap &arguments)
void PartitionManagerPrivate::format(const QString &devicePath, const QString &filesystemType, 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, arguments);
m_udisksMonitor->instance()->format(devicePath, filesystemType, 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 QVariantMap &arguments);
void format(const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments);
QString objectPath(const QString &devicePath) const;
......
......@@ -158,8 +158,8 @@ void PartitionModel::unmount(const QString &devicePath)
void PartitionModel::format(const QString &devicePath, const QVariantMap &arguments)
{
QString type = arguments.value(QLatin1String("filesystemType"), QString()).toString();
if (type.isEmpty()) {
QString filesystemType = arguments.value(QLatin1String("filesystemType"), QString()).toString();
if (filesystemType.isEmpty()) {
qmlInfo(this) << "Missing or empty filesystemType argument, cannot format.";
return;
}
......@@ -177,8 +177,8 @@ void PartitionModel::format(const QString &devicePath, const QVariantMap &argume
args.insert(QLatin1String("encrypt.passphrase"), passphrase);
}
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << type << args << m_partitions.count();
m_manager->format(devicePath, type, args);
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << filesystemType << args << m_partitions.count();
m_manager->format(devicePath, filesystemType, args);
}
QString PartitionModel::objectPath(const QString &devicePath) const
......
......@@ -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.
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).
......@@ -171,16 +175,14 @@ bool UDisks2::Block::isEncrypted() const
return m_encrypted;
}
void UDisks2::Block::setEncrypted(bool encrypted)
bool UDisks2::Block::setEncrypted(bool encrypted)
{
if (m_encrypted != encrypted) {
m_encrypted = encrypted;
blockSignals(true);
setMountable(!m_encrypted);
blockSignals(false);
emit updated();
return true;
}
return false;
}
bool UDisks2::Block::isMountable() const
......@@ -188,23 +190,29 @@ bool UDisks2::Block::isMountable() const
return m_mountable;
}
void UDisks2::Block::setMountable(bool mountable)
bool UDisks2::Block::setMountable(bool mountable)
{
if (m_mountable != mountable) {
m_mountable = mountable;
if (m_mountable && m_formatting) {
m_formatting = false;
emit formatted();
}
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
......@@ -291,17 +299,23 @@ void UDisks2::Block::updateProperties(const QDBusMessage &message)
QString interface = arguments.value(0).toString();
if (interface == UDISKS2_BLOCK_INTERFACE) {
QVariantMap changedProperties = NemoDBus::demarshallArgument<QVariantMap>(arguments.value(1));
qCInfo(lcMemoryCardLog) << "Changed properties:" << changedProperties;
for (QMap<QString, QVariant>::const_iterator i = changedProperties.begin(); i != changedProperties.end(); ++i) {
for (QMap<QString, QVariant>::const_iterator i = changedProperties.constBegin(); i != changedProperties.constEnd(); ++i) {
m_data.insert(i.key(), i.value());
}
emit updated();
if (!clearFormattingState()) {
emit updated();
}
} else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
m_mountable = true;
updateMountPoint(arguments.value(1));
}
}
bool UDisks2::Block::isCompleted() const
{
return !m_pendingFileSystem && !m_pendingBlock && !m_pendingEncrypted;
}
void UDisks2::Block::updateMountPoint(const QVariant &mountPoints)
{
QVariantMap mountPointsMap = NemoDBus::demarshallArgument<QVariantMap>(mountPoints);
......@@ -315,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();
}
void UDisks2::Block::complete()
{
if (!m_pendingFileSystem && !m_pendingBlock && !m_pendingEncrypted) {
if (isCompleted()) {
QMetaObject::invokeMethod(this, "completed", Qt::QueuedConnection);
}
}
bool UDisks2::Block::clearFormattingState()
{
if (isCompleted() && isMountable() && isFormatting()) {
return setFormatting(false);
}
return false;
}
void UDisks2::Block::getFileSystemInterface()
{
QDBusInterface dbusPropertyInterface(UDISKS2_SERVICE,
......@@ -338,7 +370,6 @@ void UDisks2::Block::getFileSystemInterface()
if (watcher->isValid() && watcher->isFinished()) {
QDBusPendingReply<> reply = *watcher;
QDBusMessage message = reply.reply();
m_mountable = true;
updateMountPoint(message.arguments().at(0));
} else {
QDBusError error = watcher->error();
......
......@@ -68,13 +68,13 @@ public:
QString cryptoBackingDeviceObjectPath() const;
bool isEncrypted() const;
void setEncrypted(bool encrypted);
bool setEncrypted(bool encrypted);
bool isMountable() const;
void setMountable(bool mountable);
bool setMountable(bool mountable);
bool isFormatting() const;
void setFormatting();
bool setFormatting(bool formatting);
bool isLocking() const;
void setLocking();
......@@ -107,8 +107,11 @@ private slots:
void updateProperties(const QDBusMessage &message);
private:
bool isCompleted() const;
void updateMountPoint(const QVariant &mountPoints);
void complete();
bool clearFormattingState();
void getFileSystemInterface();
void getEncryptedInterface();
......
This diff is collapsed.
......@@ -54,18 +54,18 @@ class Job;
struct Operation
{
Operation(const QString &command, const QString &devicePath, const QString &dbusObjectPath = QString(), const QString &type = QString(), const QVariantMap &arguments = QVariantMap())
Operation(const QString &command, const QString &devicePath, const QString &dbusObjectPath = QString(), const QString &filesystemType = QString(), const QVariantMap &arguments = QVariantMap())
: command(command)
, devicePath(devicePath)
, dbusObjectPath(dbusObjectPath)
, type(type)
, filesystemType(filesystemType)
, arguments(arguments)
{}
QString command;
QString devicePath;
QString dbusObjectPath;
QString type;
QString filesystemType;
QVariantMap arguments;
};
......@@ -84,7 +84,7 @@ public:
void mount(const QString &devicePath);
void unmount(const QString &devicePath);
void format(const QString &devicePath, const QString &type, const QVariantMap &arguments);
void format(const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments);
QString objectPath(const QString &devicePath) const;
......@@ -100,11 +100,12 @@ signals:
private slots:
void interfacesAdded(const QDBusObjectPath &objectPath, const UDisks2::InterfacePropertyMap &interfaces);
void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces);
void doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &filesystemType, const QVariantMap &arguments);
private:
void setPartitionProperties(QExplicitlySharedDataPointer<PartitionPrivate> &partition, const UDisks2::Block *blockDevice);
void updatePartitionProperties(const UDisks2::Block *blockDevice);
void updatePartitionStatus(const UDisks2::Job *job, bool success);
void setPartitionProperties(QExplicitlySharedDataPointer<PartitionPrivate> &partition, const Block *blockDevice);
void updatePartitionProperties(const Block *blockDevice);
void updatePartitionStatus(const Job *job, bool success);
bool externalBlockDevice(const QString &objectPathStr) const;
void startLuksOperation(const QString &devicePath, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments);
......@@ -112,17 +113,18 @@ private:
void lookupPartitions(PartitionManagerPrivate::Partitions &affectedPartitions, const QStringList &objects);
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 QVariantMap &arguments);
void getBlockDevices();
Block *findBlock(const QString &devicePath) const;
private:
static Monitor *sharedInstance;
QExplicitlySharedDataPointer<PartitionManagerPrivate> m_manager;
QMap<QString, UDisks2::Job *> m_jobsToWait;
QMap<QString, UDisks2::Block *> m_blockDevices;
QMap<QString, Job *> m_jobsToWait;
QMap<QString, Block *> m_blockDevices;
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