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