Skip to content

Commit

Permalink
Merge branch 'jb42527-regression-fix' into 'master'
Browse files Browse the repository at this point in the history
[systemsettings] Fix initial FileSystem interface reading. Contributes to JB#42527

See merge request mer-core/nemo-qml-plugin-systemsettings!69
  • Loading branch information
rainemak committed Aug 29, 2018
2 parents 05f989b + 1549450 commit beee054
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
50 changes: 31 additions & 19 deletions src/udisks2block.cpp
Expand Up @@ -31,25 +31,12 @@ UDisks2::Block::Block(const QString &path, const QVariantMap &data, QObject *par
m_path,
DBUS_OBJECT_PROPERTIES_INTERFACE,
m_connection);
QDBusPendingCall pendingCall = dbusPropertyInterface.asyncCall(DBUS_GET_ALL, UDISKS2_FILESYSTEM_INTERFACE);
m_pendingFileSystem = new QDBusPendingCallWatcher(pendingCall, this);
connect(m_pendingFileSystem, &QDBusPendingCallWatcher::finished, this, [this, path](QDBusPendingCallWatcher *watcher) {
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();
qCWarning(lcMemoryCardLog) << "Error reading filesystem properties:" << error.name() << error.message() << path;
}
watcher->deleteLater();
m_pendingFileSystem = nullptr;
complete();
});

if (data.isEmpty()) {
pendingCall = dbusPropertyInterface.asyncCall(DBUS_GET_ALL, UDISKS2_BLOCK_INTERFACE);
qCInfo(lcMemoryCardLog) << "Creating a new block. Mountable:" << m_mountable << ", object path:" << m_path << ", data is empty:" << m_data.isEmpty();
getFileSystemInterface();

if (m_data.isEmpty()) {
QDBusPendingCall pendingCall = dbusPropertyInterface.asyncCall(DBUS_GET_ALL, UDISKS2_BLOCK_INTERFACE);
m_pendingBlock = new QDBusPendingCallWatcher(pendingCall, this);
connect(m_pendingBlock, &QDBusPendingCallWatcher::finished, this, [this, path](QDBusPendingCallWatcher *watcher) {
if (watcher->isValid() && watcher->isFinished()) {
Expand All @@ -62,7 +49,7 @@ UDisks2::Block::Block(const QString &path, const QVariantMap &data, QObject *par
QDBusError error = watcher->error();
qCWarning(lcMemoryCardLog) << "Error reading block properties:" << error.name() << error.message();
}
watcher->deleteLater();
m_pendingBlock->deleteLater();
m_pendingBlock = nullptr;
complete();
});
Expand Down Expand Up @@ -216,3 +203,28 @@ void UDisks2::Block::complete()
QMetaObject::invokeMethod(this, "completed", Qt::QueuedConnection);
}
}

void UDisks2::Block::getFileSystemInterface()
{
QDBusInterface dbusPropertyInterface(UDISKS2_SERVICE,
m_path,
DBUS_OBJECT_PROPERTIES_INTERFACE,
m_connection);
QDBusPendingCall pendingCall = dbusPropertyInterface.asyncCall(DBUS_GET_ALL, UDISKS2_FILESYSTEM_INTERFACE);
m_pendingFileSystem = new QDBusPendingCallWatcher(pendingCall, this);
connect(m_pendingFileSystem, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
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();
qCWarning(lcMemoryCardLog) << "Error reading filesystem properties:" << error.name() << error.message() << m_path;
m_mountable = false;
}
m_pendingFileSystem->deleteLater();
m_pendingFileSystem = nullptr;
complete();
});
}
1 change: 1 addition & 0 deletions src/udisks2block_p.h
Expand Up @@ -90,6 +90,7 @@ private slots:
private:
void updateMountPoint(const QVariant &mountPoints);
void complete();
void getFileSystemInterface();

QString m_path;
QVariantMap m_data;
Expand Down
9 changes: 5 additions & 4 deletions src/udisks2monitor.cpp
Expand Up @@ -447,9 +447,7 @@ void UDisks2::Monitor::createBlockDevice(const QString &path, const QVariantMap
return;
}

QString deviceName = path.section(QChar('/'), 5);

if (externalBlockDevice(deviceName)) {
if (externalBlockDevice(path)) {
UDisks2::Block *block = new UDisks2::Block(path, dict);
if (block->hasData()) {
m_blockDevices.insert(path, block);
Expand Down Expand Up @@ -602,7 +600,10 @@ void UDisks2::Monitor::getBlockDevices()
QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
const QList<QDBusObjectPath> blockDevicePaths = reply.argumentAt<0>();
for (const QDBusObjectPath &dbusObjectPath : blockDevicePaths) {
createBlockDevice(dbusObjectPath.path(), QVariantMap());
QString path = dbusObjectPath.path();
if (externalBlockDevice(path)) {
createBlockDevice(path, QVariantMap());
}
}
} else if (watcher->isError()) {
QDBusError error = watcher->error();
Expand Down

0 comments on commit beee054

Please sign in to comment.