Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nemo-systemsettings] Stay in formatting state until filesystem/encry…
…pted interface appear. Contributes to JB#42963

This also renames bogus type to filesystemType.
  • Loading branch information
rainemak committed Sep 27, 2018
1 parent 607e6c2 commit 6e841e0
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 88 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 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";
}
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 QVariantMap &arguments);
void format(const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments);

QString objectPath(const QString &devicePath) const;

Expand Down
8 changes: 4 additions & 4 deletions src/partitionmodel.cpp
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
73 changes: 52 additions & 21 deletions src/udisks2block.cpp
Expand Up @@ -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).
Expand Down Expand Up @@ -171,40 +175,44 @@ 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
{
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
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions src/udisks2block_p.h
Expand Up @@ -68,13 +68,13 @@ class Block : public QObject
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();
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 6e841e0

Please sign in to comment.