Skip to content

Commit

Permalink
Merge branch 'jb46110' into 'master'
Browse files Browse the repository at this point in the history
[settings-storage] Expose externalStoragesPopulated property. Contributes to JB#46110

See merge request mer-core/nemo-qml-plugin-systemsettings!115
  • Loading branch information
rainemak committed Aug 23, 2019
2 parents 9b5b458 + 021e8b2 commit 6014bfe
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 20 deletions.
10 changes: 1 addition & 9 deletions src/aboutsettings.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -258,7 +253,6 @@ void AboutSettings::partitionCountChanged()
void AboutSettings::reloadStorageLists()
{
m_internalStorage.clear();
m_externalStorage.clear();

for (auto partition : m_partitionManager.partitions()) {
QVariantMap row;
Expand All @@ -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);
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/aboutsettings.h
Expand Up @@ -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();
Expand All @@ -75,7 +72,6 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
* - total: total bytes on the storage
**/
Q_INVOKABLE QVariant diskUsageModel() const;
QVariant externalStorageUsageModel() const;
Q_INVOKABLE void refreshStorageModels();

QString wlanMacAddress() const;
Expand All @@ -101,7 +97,6 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
QDeviceInfo *m_devinfo;

QVariantList m_internalStorage;
QVariantList m_externalStorage;
PartitionManager m_partitionManager;

mutable QMap<QString, QString> m_osRelease;
Expand Down
9 changes: 9 additions & 0 deletions src/partitionmanager.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -371,13 +373,20 @@ QStringList PartitionManagerPrivate::supportedFileSystems() const
return supportedFs;
}

bool PartitionManagerPrivate::externalStoragesPopulated() const
{
return UDisks2::BlockDevices::instance()->populated();
}

PartitionManager::PartitionManager(QObject *parent)
: QObject(parent)
, d(PartitionManagerPrivate::instance())
{
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()
Expand Down
1 change: 1 addition & 0 deletions src/partitionmanager.h
Expand Up @@ -54,6 +54,7 @@ class SYSTEMSETTINGS_EXPORT PartitionManager : public QObject
void partitionChanged(const Partition &partition);
void partitionAdded(const Partition &partition);
void partitionRemoved(const Partition &partition);
void externalStoragesPopulated();

private:
QExplicitlySharedDataPointer<PartitionManagerPrivate> d;
Expand Down
2 changes: 2 additions & 0 deletions src/partitionmanager_p.h
Expand Up @@ -75,11 +75,13 @@ class PartitionManagerPrivate : public QObject, public QSharedData
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);
Expand Down
8 changes: 7 additions & 1 deletion src/partitionmodel.cpp
Expand Up @@ -32,7 +32,6 @@
#include "partitionmodel.h"
#include "partitionmanager_p.h"

#include "udisks2monitor_p.h"
#include "logging_p.h"

#include <QDir>
Expand All @@ -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);

Expand Down Expand Up @@ -108,6 +109,11 @@ QStringList PartitionModel::supportedFormatTypes() const
return types;
}

bool PartitionModel::externalStoragesPopulated() const
{
return m_manager->externalStoragesPopulated();
}

void PartitionModel::refresh()
{
m_manager->refresh();
Expand Down
3 changes: 3 additions & 0 deletions src/partitionmodel.h
Expand Up @@ -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 {
Expand Down Expand Up @@ -132,6 +133,7 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel
void setStorageTypes(StorageTypes storageTypes);

QStringList supportedFormatTypes() const;
bool externalStoragesPopulated() const;

Q_INVOKABLE void refresh();
Q_INVOKABLE void refresh(int index);
Expand All @@ -152,6 +154,7 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel
signals:
void countChanged();
void storageTypesChanged();
void externalStoragesPopulatedChanged();

void errorMessage(const QString &objectPath, const QString &errorName);
void lockError(Error error);
Expand Down
2 changes: 0 additions & 2 deletions src/plugin/plugins.qmltypes
Expand Up @@ -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" }
Expand Down
36 changes: 36 additions & 0 deletions src/udisks2blockdevices.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand All @@ -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);

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/udisks2blockdevices_p.h
Expand Up @@ -35,6 +35,7 @@
#include <QMap>
#include <QPointer>
#include <functional>
#include <QDBusObjectPath>

#include "udisks2block_p.h"

Expand Down Expand Up @@ -63,19 +64,22 @@ class BlockDevices : public QObject
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;

static bool isExternal(const QString &dbusObjectPath);

signals:
void newBlock(Block *block);
void externalStoragesPopulated();

private slots:
void blockCompleted();
Expand All @@ -97,9 +101,12 @@ private slots:
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;
};
Expand Down
4 changes: 1 addition & 3 deletions src/udisks2monitor.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit 6014bfe

Please sign in to comment.