Commit 6014bfe7 authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb46110' into 'master'

[settings-storage] Expose externalStoragesPopulated property. Contributes to JB#46110

See merge request mer-core/nemo-qml-plugin-systemsettings!115
parents 9b5b458e 021e8b24
...@@ -153,11 +153,6 @@ QVariant AboutSettings::diskUsageModel() const ...@@ -153,11 +153,6 @@ QVariant AboutSettings::diskUsageModel() const
return m_internalStorage; return m_internalStorage;
} }
QVariant AboutSettings::externalStorageUsageModel() const
{
return m_externalStorage;
}
QString AboutSettings::wlanMacAddress() const QString AboutSettings::wlanMacAddress() const
{ {
return m_netinfo->macAddress(QNetworkInfo::WlanMode, 0); return m_netinfo->macAddress(QNetworkInfo::WlanMode, 0);
...@@ -258,7 +253,6 @@ void AboutSettings::partitionCountChanged() ...@@ -258,7 +253,6 @@ void AboutSettings::partitionCountChanged()
void AboutSettings::reloadStorageLists() void AboutSettings::reloadStorageLists()
{ {
m_internalStorage.clear(); m_internalStorage.clear();
m_externalStorage.clear();
for (auto partition : m_partitionManager.partitions()) { for (auto partition : m_partitionManager.partitions()) {
QVariantMap row; QVariantMap row;
...@@ -283,9 +277,7 @@ void AboutSettings::reloadStorageLists() ...@@ -283,9 +277,7 @@ void AboutSettings::reloadStorageLists()
} }
}(); }();
if (partition.storageType() == Partition::External) { if (partition.storageType() != Partition::External) {
m_externalStorage << QVariant(row);
} else {
m_internalStorage << QVariant(row); m_internalStorage << QVariant(row);
} }
} }
......
...@@ -55,9 +55,6 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject ...@@ -55,9 +55,6 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
Q_PROPERTY(QString vendorName READ vendorName CONSTANT) Q_PROPERTY(QString vendorName READ vendorName CONSTANT)
Q_PROPERTY(QString vendorVersion READ vendorVersion CONSTANT) Q_PROPERTY(QString vendorVersion READ vendorVersion CONSTANT)
Q_PROPERTY(QVariant internalStorageUsageModel READ diskUsageModel NOTIFY storageChanged)
Q_PROPERTY(QVariant externalStorageUsageModel READ externalStorageUsageModel NOTIFY storageChanged)
public: public:
explicit AboutSettings(QObject *parent = 0); explicit AboutSettings(QObject *parent = 0);
virtual ~AboutSettings(); virtual ~AboutSettings();
...@@ -75,7 +72,6 @@ public: ...@@ -75,7 +72,6 @@ public:
* - total: total bytes on the storage * - total: total bytes on the storage
**/ **/
Q_INVOKABLE QVariant diskUsageModel() const; Q_INVOKABLE QVariant diskUsageModel() const;
QVariant externalStorageUsageModel() const;
Q_INVOKABLE void refreshStorageModels(); Q_INVOKABLE void refreshStorageModels();
QString wlanMacAddress() const; QString wlanMacAddress() const;
...@@ -101,7 +97,6 @@ private: ...@@ -101,7 +97,6 @@ private:
QDeviceInfo *m_devinfo; QDeviceInfo *m_devinfo;
QVariantList m_internalStorage; QVariantList m_internalStorage;
QVariantList m_externalStorage;
PartitionManager m_partitionManager; PartitionManager m_partitionManager;
mutable QMap<QString, QString> m_osRelease; mutable QMap<QString, QString> m_osRelease;
......
...@@ -62,6 +62,8 @@ PartitionManagerPrivate::PartitionManagerPrivate() ...@@ -62,6 +62,8 @@ PartitionManagerPrivate::PartitionManagerPrivate()
connect(m_udisksMonitor.data(), &UDisks2::Monitor::mountError, this, &PartitionManagerPrivate::mountError); connect(m_udisksMonitor.data(), &UDisks2::Monitor::mountError, this, &PartitionManagerPrivate::mountError);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::unmountError, this, &PartitionManagerPrivate::unmountError); connect(m_udisksMonitor.data(), &UDisks2::Monitor::unmountError, this, &PartitionManagerPrivate::unmountError);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::formatError, this, &PartitionManagerPrivate::formatError); connect(m_udisksMonitor.data(), &UDisks2::Monitor::formatError, this, &PartitionManagerPrivate::formatError);
connect(UDisks2::BlockDevices::instance(), &UDisks2::BlockDevices::externalStoragesPopulated,
this, &PartitionManagerPrivate::externalStoragesPopulatedChanged);
QVariantMap defaultDrive; QVariantMap defaultDrive;
defaultDrive.insert(QLatin1String("model"), QString()); defaultDrive.insert(QLatin1String("model"), QString());
...@@ -371,6 +373,11 @@ QStringList PartitionManagerPrivate::supportedFileSystems() const ...@@ -371,6 +373,11 @@ QStringList PartitionManagerPrivate::supportedFileSystems() const
return supportedFs; return supportedFs;
} }
bool PartitionManagerPrivate::externalStoragesPopulated() const
{
return UDisks2::BlockDevices::instance()->populated();
}
PartitionManager::PartitionManager(QObject *parent) PartitionManager::PartitionManager(QObject *parent)
: QObject(parent) : QObject(parent)
, d(PartitionManagerPrivate::instance()) , d(PartitionManagerPrivate::instance())
...@@ -378,6 +385,8 @@ PartitionManager::PartitionManager(QObject *parent) ...@@ -378,6 +385,8 @@ PartitionManager::PartitionManager(QObject *parent)
connect(d.data(), &PartitionManagerPrivate::partitionChanged, this, &PartitionManager::partitionChanged); connect(d.data(), &PartitionManagerPrivate::partitionChanged, this, &PartitionManager::partitionChanged);
connect(d.data(), &PartitionManagerPrivate::partitionAdded, this, &PartitionManager::partitionAdded); connect(d.data(), &PartitionManagerPrivate::partitionAdded, this, &PartitionManager::partitionAdded);
connect(d.data(), &PartitionManagerPrivate::partitionRemoved, this, &PartitionManager::partitionRemoved); connect(d.data(), &PartitionManagerPrivate::partitionRemoved, this, &PartitionManager::partitionRemoved);
connect(d.data(), &PartitionManagerPrivate::externalStoragesPopulatedChanged,
this, &PartitionManager::externalStoragesPopulated);
} }
PartitionManager::~PartitionManager() PartitionManager::~PartitionManager()
......
...@@ -54,6 +54,7 @@ signals: ...@@ -54,6 +54,7 @@ signals:
void partitionChanged(const Partition &partition); void partitionChanged(const Partition &partition);
void partitionAdded(const Partition &partition); void partitionAdded(const Partition &partition);
void partitionRemoved(const Partition &partition); void partitionRemoved(const Partition &partition);
void externalStoragesPopulated();
private: private:
QExplicitlySharedDataPointer<PartitionManagerPrivate> d; QExplicitlySharedDataPointer<PartitionManagerPrivate> d;
......
...@@ -75,11 +75,13 @@ public: ...@@ -75,11 +75,13 @@ public:
QString objectPath(const QString &devicePath) const; QString objectPath(const QString &devicePath) const;
QStringList supportedFileSystems() const; QStringList supportedFileSystems() const;
bool externalStoragesPopulated() const;
signals: signals:
void partitionChanged(const Partition &partition); void partitionChanged(const Partition &partition);
void partitionAdded(const Partition &partition); void partitionAdded(const Partition &partition);
void partitionRemoved(const Partition &partition); void partitionRemoved(const Partition &partition);
void externalStoragesPopulatedChanged();
void status(const QString &deviceName, Partition::Status); void status(const QString &deviceName, Partition::Status);
void errorMessage(const QString &objectPath, const QString &errorName); void errorMessage(const QString &objectPath, const QString &errorName);
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "partitionmodel.h" #include "partitionmodel.h"
#include "partitionmanager_p.h" #include "partitionmanager_p.h"
#include "udisks2monitor_p.h"
#include "logging_p.h" #include "logging_p.h"
#include <QDir> #include <QDir>
...@@ -49,6 +48,8 @@ PartitionModel::PartitionModel(QObject *parent) ...@@ -49,6 +48,8 @@ PartitionModel::PartitionModel(QObject *parent)
connect(m_manager.data(), &PartitionManagerPrivate::partitionChanged, this, &PartitionModel::partitionChanged); connect(m_manager.data(), &PartitionManagerPrivate::partitionChanged, this, &PartitionModel::partitionChanged);
connect(m_manager.data(), &PartitionManagerPrivate::partitionAdded, this, &PartitionModel::partitionAdded); connect(m_manager.data(), &PartitionManagerPrivate::partitionAdded, this, &PartitionModel::partitionAdded);
connect(m_manager.data(), &PartitionManagerPrivate::partitionRemoved, this, &PartitionModel::partitionRemoved); connect(m_manager.data(), &PartitionManagerPrivate::partitionRemoved, this, &PartitionModel::partitionRemoved);
connect(m_manager.data(), &PartitionManagerPrivate::externalStoragesPopulatedChanged,
this, &PartitionModel::externalStoragesPopulatedChanged);
connect(m_manager.data(), &PartitionManagerPrivate::errorMessage, this, &PartitionModel::errorMessage); connect(m_manager.data(), &PartitionManagerPrivate::errorMessage, this, &PartitionModel::errorMessage);
...@@ -108,6 +109,11 @@ QStringList PartitionModel::supportedFormatTypes() const ...@@ -108,6 +109,11 @@ QStringList PartitionModel::supportedFormatTypes() const
return types; return types;
} }
bool PartitionModel::externalStoragesPopulated() const
{
return m_manager->externalStoragesPopulated();
}
void PartitionModel::refresh() void PartitionModel::refresh()
{ {
m_manager->refresh(); m_manager->refresh();
......
...@@ -45,6 +45,7 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel ...@@ -45,6 +45,7 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel
Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(StorageTypes storageTypes READ storageTypes WRITE setStorageTypes NOTIFY storageTypesChanged) Q_PROPERTY(StorageTypes storageTypes READ storageTypes WRITE setStorageTypes NOTIFY storageTypesChanged)
Q_PROPERTY(QStringList supportedFormatTypes READ supportedFormatTypes CONSTANT) Q_PROPERTY(QStringList supportedFormatTypes READ supportedFormatTypes CONSTANT)
Q_PROPERTY(bool externalStoragesPopulated READ externalStoragesPopulated NOTIFY externalStoragesPopulatedChanged)
public: public:
enum { enum {
...@@ -132,6 +133,7 @@ public: ...@@ -132,6 +133,7 @@ public:
void setStorageTypes(StorageTypes storageTypes); void setStorageTypes(StorageTypes storageTypes);
QStringList supportedFormatTypes() const; QStringList supportedFormatTypes() const;
bool externalStoragesPopulated() const;
Q_INVOKABLE void refresh(); Q_INVOKABLE void refresh();
Q_INVOKABLE void refresh(int index); Q_INVOKABLE void refresh(int index);
...@@ -152,6 +154,7 @@ public: ...@@ -152,6 +154,7 @@ public:
signals: signals:
void countChanged(); void countChanged();
void storageTypesChanged(); void storageTypesChanged();
void externalStoragesPopulatedChanged();
void errorMessage(const QString &objectPath, const QString &errorName); void errorMessage(const QString &objectPath, const QString &errorName);
void lockError(Error error); void lockError(Error error);
......
...@@ -23,8 +23,6 @@ Module { ...@@ -23,8 +23,6 @@ Module {
Property { name: "adaptationVersion"; type: "string"; isReadonly: true } Property { name: "adaptationVersion"; type: "string"; isReadonly: true }
Property { name: "vendorName"; type: "string"; isReadonly: true } Property { name: "vendorName"; type: "string"; isReadonly: true }
Property { name: "vendorVersion"; type: "string"; isReadonly: true } Property { name: "vendorVersion"; type: "string"; isReadonly: true }
Property { name: "internalStorageUsageModel"; type: "QVariant"; isReadonly: true }
Property { name: "externalStorageUsageModel"; type: "QVariant"; isReadonly: true }
Signal { name: "storageChanged" } Signal { name: "storageChanged" }
Method { name: "totalDiskSpace"; type: "qlonglong" } Method { name: "totalDiskSpace"; type: "qlonglong" }
Method { name: "availableDiskSpace"; type: "qlonglong" } Method { name: "availableDiskSpace"; type: "qlonglong" }
......
...@@ -148,12 +148,26 @@ QStringList BlockDevices::devicePaths(const QStringList &dbusObjectPaths) const ...@@ -148,12 +148,26 @@ QStringList BlockDevices::devicePaths(const QStringList &dbusObjectPaths) const
bool BlockDevices::createBlockDevice(const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap) bool BlockDevices::createBlockDevice(const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap)
{ {
if (!BlockDevices::isExternal(dbusObjectPath)) { if (!BlockDevices::isExternal(dbusObjectPath)) {
updatePopulatedCheck();
return false; return false;
} }
return doCreateBlockDevice(dbusObjectPath, interfacePropertyMap); return doCreateBlockDevice(dbusObjectPath, interfacePropertyMap);
} }
void BlockDevices::createBlockDevices(const QList<QDBusObjectPath> &devices)
{
m_blockCount = devices.count();
if (m_blockCount == 0) {
m_populated = true;
emit externalStoragesPopulated();
}
for (const QDBusObjectPath &dbusObjectPath : devices) {
createBlockDevice(dbusObjectPath.path(), UDisks2::InterfacePropertyMap());
}
}
void BlockDevices::lock(const QString &dbusObjectPath) void BlockDevices::lock(const QString &dbusObjectPath)
{ {
Block *deviceMapped = find([dbusObjectPath](const Block *block) { Block *deviceMapped = find([dbusObjectPath](const Block *block) {
...@@ -210,6 +224,11 @@ void BlockDevices::removeInterfaces(const QString &dbusObjectPath, const QString ...@@ -210,6 +224,11 @@ void BlockDevices::removeInterfaces(const QString &dbusObjectPath, const QString
} }
} }
bool BlockDevices::populated() const
{
return m_populated;
}
bool BlockDevices::isExternal(const QString &dbusObjectPath) bool BlockDevices::isExternal(const QString &dbusObjectPath)
{ {
static const QRegularExpression externalBlockDevice(QStringLiteral("^/org/freedesktop/UDisks2/block_devices/%1$").arg(externalDevice)); static const QRegularExpression externalBlockDevice(QStringLiteral("^/org/freedesktop/UDisks2/block_devices/%1$").arg(externalDevice));
...@@ -223,15 +242,21 @@ void BlockDevices::blockCompleted() ...@@ -223,15 +242,21 @@ void BlockDevices::blockCompleted()
(completedBlock->hasInterface(UDISKS2_BLOCK_INTERFACE) && completedBlock->interfaceCount() == 1)) ){ (completedBlock->hasInterface(UDISKS2_BLOCK_INTERFACE) && completedBlock->interfaceCount() == 1)) ){
qCInfo(lcMemoryCardLog) << "Start waiting for block" << completedBlock->device(); qCInfo(lcMemoryCardLog) << "Start waiting for block" << completedBlock->device();
waitPartition(completedBlock); waitPartition(completedBlock);
updatePopulatedCheck();
return; return;
} }
clearPartitionWait(completedBlock->partitionTable(), true); clearPartitionWait(completedBlock->partitionTable(), true);
complete(completedBlock); complete(completedBlock);
// Check only after complete has been called.
updatePopulatedCheck();
} }
BlockDevices::BlockDevices(QObject *parent) BlockDevices::BlockDevices(QObject *parent)
: QObject(parent) : QObject(parent)
, m_blockCount(0)
, m_populated(false)
{ {
Q_ASSERT(!sharedInstance); Q_ASSERT(!sharedInstance);
...@@ -333,6 +358,17 @@ void BlockDevices::timerEvent(QTimerEvent *e) ...@@ -333,6 +358,17 @@ void BlockDevices::timerEvent(QTimerEvent *e)
} }
} }
void BlockDevices::updatePopulatedCheck()
{
if (!m_populated) {
--m_blockCount;
if (m_blockCount == 0) {
m_populated = true;
emit externalStoragesPopulated();
}
}
}
BlockDevices::PartitionWaiter::PartitionWaiter(int timer, Block *block) BlockDevices::PartitionWaiter::PartitionWaiter(int timer, Block *block)
: timer(timer) : timer(timer)
, block(block) , block(block)
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <QMap> #include <QMap>
#include <QPointer> #include <QPointer>
#include <functional> #include <functional>
#include <QDBusObjectPath>
#include "udisks2block_p.h" #include "udisks2block_p.h"
...@@ -63,12 +64,14 @@ public: ...@@ -63,12 +64,14 @@ public:
QStringList devicePaths(const QStringList &dbusObjectPaths) const; QStringList devicePaths(const QStringList &dbusObjectPaths) const;
bool createBlockDevice(const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap); bool createBlockDevice(const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap);
void createBlockDevices(const QList<QDBusObjectPath> &devices);
void lock(const QString &dbusObjectPath); void lock(const QString &dbusObjectPath);
void waitPartition(Block *block); void waitPartition(Block *block);
void clearPartitionWait(const QString &dbusObjectPath, bool destroyBlock); void clearPartitionWait(const QString &dbusObjectPath, bool destroyBlock);
void removeInterfaces(const QString &dbusObjectPath, const QStringList &interfaces); void removeInterfaces(const QString &dbusObjectPath, const QStringList &interfaces);
bool populated() const;
void dumpBlocks() const; void dumpBlocks() const;
...@@ -76,6 +79,7 @@ public: ...@@ -76,6 +79,7 @@ public:
signals: signals:
void newBlock(Block *block); void newBlock(Block *block);
void externalStoragesPopulated();
private slots: private slots:
void blockCompleted(); void blockCompleted();
...@@ -97,9 +101,12 @@ private: ...@@ -97,9 +101,12 @@ private:
void complete(Block *block, bool forceAccept = false); void complete(Block *block, bool forceAccept = false);
void timerEvent(QTimerEvent *e) override; void timerEvent(QTimerEvent *e) override;
void updatePopulatedCheck();
QMap<QString, Block *> m_blockDevices; QMap<QString, Block *> m_blockDevices;
QMap<QString, PartitionWaiter*> m_partitionWaits; QMap<QString, PartitionWaiter*> m_partitionWaits;
int m_blockCount;
bool m_populated;
static QPointer<BlockDevices> sharedInstance; static QPointer<BlockDevices> sharedInstance;
}; };
......
...@@ -665,9 +665,7 @@ void UDisks2::Monitor::getBlockDevices() ...@@ -665,9 +665,7 @@ void UDisks2::Monitor::getBlockDevices()
if (watcher->isValid() && watcher->isFinished()) { if (watcher->isValid() && watcher->isFinished()) {
QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher; QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
const QList<QDBusObjectPath> blockDevicePaths = reply.argumentAt<0>(); const QList<QDBusObjectPath> blockDevicePaths = reply.argumentAt<0>();
for (const QDBusObjectPath &dbusObjectPath : blockDevicePaths) { m_blockDevices->createBlockDevices(blockDevicePaths);
m_blockDevices->createBlockDevice(dbusObjectPath.path(), UDisks2::InterfacePropertyMap());
}
} else if (watcher->isError()) { } else if (watcher->isError()) {
QDBusError error = watcher->error(); QDBusError error = watcher->error();
qCWarning(lcMemoryCardLog) << "Unable to enumerate block devices:" << error.name() << error.message(); qCWarning(lcMemoryCardLog) << "Unable to enumerate block devices:" << error.name() << error.message();
......
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