Skip to content

Commit

Permalink
Merge branch 'jb42527-defines' into 'master'
Browse files Browse the repository at this point in the history
Expose defines through devel package and expose crypto device role

See merge request mer-core/nemo-qml-plugin-systemsettings!71
  • Loading branch information
rainemak committed Aug 31, 2018
2 parents 43908cd + a306fa4 commit daedc48
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/partition.cpp
Expand Up @@ -86,6 +86,11 @@ bool Partition::mountFailed() const
return d && d->mountFailed;
}

bool Partition::isCryptoDevice() const
{
return d ? d->isCryptoDevice : false;
}

Partition::StorageType Partition::storageType() const
{
return d ? d->storageType : Invalid;
Expand Down
1 change: 1 addition & 0 deletions src/partition.h
Expand Up @@ -103,6 +103,7 @@ class SYSTEMSETTINGS_EXPORT Partition

bool canMount() const;
bool mountFailed() const;
bool isCryptoDevice() const;

StorageType storageType() const;

Expand Down
2 changes: 2 additions & 0 deletions src/partition_p.h
Expand Up @@ -48,6 +48,7 @@ class PartitionPrivate : public QSharedData
, status(Partition::Unmounted)
, readOnly(true)
, canMount(false)
, isCryptoDevice(false)
, mountFailed(false)
, deviceRoot(false)
, valid(false)
Expand All @@ -74,6 +75,7 @@ class PartitionPrivate : public QSharedData
Partition::Status status;
bool readOnly;
bool canMount;
bool isCryptoDevice;
bool mountFailed;
bool deviceRoot;
// If valid, only mount status and available bytes will be checked
Expand Down
5 changes: 4 additions & 1 deletion src/partitionmodel.cpp
Expand Up @@ -267,7 +267,8 @@ QHash<int, QByteArray> PartitionModel::roleNames() const
{ BytesAvailableRole, "bytesAvailable" },
{ BytesTotalRole, "bytesTotal" },
{ BytesFreeRole, "bytesFree" },
{ PartitionModelRole, "partitionModel" }
{ PartitionModelRole, "partitionModel" },
{ IsCryptoDeviceRoles, "isCryptoDevice"},
};

return roleNames;
Expand Down Expand Up @@ -314,6 +315,8 @@ QVariant PartitionModel::data(const QModelIndex &index, int role) const
return partition.bytesFree();
case PartitionModelRole:
return QVariant::fromValue(static_cast<QObject*>(const_cast<PartitionModel*>((this))));
case IsCryptoDeviceRoles:
return partition.isCryptoDevice();
default:
return QVariant();
}
Expand Down
3 changes: 2 additions & 1 deletion src/partitionmodel.h
Expand Up @@ -61,7 +61,8 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel
BytesAvailableRole,
BytesTotalRole,
BytesFreeRole,
PartitionModelRole
PartitionModelRole,
IsCryptoDeviceRoles,
};

// For Status role
Expand Down
2 changes: 1 addition & 1 deletion src/src.pro
Expand Up @@ -57,6 +57,7 @@ PUBLIC_HEADERS = \
connmanvpnconnectionproxy.h \
developermodesettings.h \
batterystatus.h \
udisks2defines.h \
diskusage.h \
partition.h \
partitionmanager.h \
Expand All @@ -77,7 +78,6 @@ HEADERS += \
partition_p.h \
partitionmanager_p.h \
udisks2block_p.h \
udisks2defines.h \
udisks2job_p.h \
udisks2monitor_p.h

Expand Down
2 changes: 1 addition & 1 deletion src/udisks2block.cpp
Expand Up @@ -7,7 +7,7 @@
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>

UDisks2::Block::Block(const QString &path, const InterfacePropertyMap &interfacePropertyMap, QObject *parent)
UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent)
: QObject(parent)
, m_path(path)
, m_interfacePropertyMap(interfacePropertyMap)
Expand Down
8 changes: 3 additions & 5 deletions src/udisks2block_p.h
Expand Up @@ -36,9 +36,7 @@
#include <QVariantMap>
#include <QDBusConnection>

typedef QMap<QString, QVariantMap> InterfacePropertyMap;

Q_DECLARE_METATYPE(InterfacePropertyMap)
#include "udisks2defines.h"

class QDBusPendingCallWatcher;

Expand All @@ -49,7 +47,7 @@ class Block : public QObject
Q_OBJECT

public:
Block(const QString &path, const InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
Block& operator=(const Block& other);

~Block();
Expand Down Expand Up @@ -112,7 +110,7 @@ private slots:
void getEncryptedInterface();

QString m_path;
InterfacePropertyMap m_interfacePropertyMap;
UDisks2::InterfacePropertyMap m_interfacePropertyMap;
QVariantMap m_data;
QDBusConnection m_connection;
QString m_mountPath;
Expand Down
10 changes: 9 additions & 1 deletion src/udisks2defines.h
Expand Up @@ -32,11 +32,18 @@
#ifndef UDISKS2_DEFINES
#define UDISKS2_DEFINES

#include <QVariantMap>

namespace UDisks2 {
static const auto propertiesChangedSignal = QStringLiteral("PropertiesChanged");
static const auto cryptoBackingDeviceKey = QStringLiteral("CryptoBackingDevice");
static const auto interfacesAddedSignal = QStringLiteral("InterfacesAdded");
static const auto interfacesRemovedSignal = QStringLiteral("InterfacesRemoved");
static const auto cryptoBackingDeviceKey = QStringLiteral("CryptoBackingDevice");

typedef QMap<QString, QVariantMap> InterfacePropertyMap;
}

Q_DECLARE_METATYPE(UDisks2::InterfacePropertyMap)

#define DBUS_OBJECT_MANAGER_INTERFACE QLatin1String("org.freedesktop.DBus.ObjectManager")
#define DBUS_OBJECT_PROPERTIES_INTERFACE QLatin1String("org.freedesktop.DBus.Properties")
Expand All @@ -49,6 +56,7 @@ namespace UDisks2 {
// Interfaces
#define UDISKS2_MANAGER_INTERFACE QLatin1String("org.freedesktop.UDisks2.Manager")
#define UDISKS2_ENCRYPTED_INTERFACE QLatin1String("org.freedesktop.UDisks2.Encrypted")
#define UDISKS2_DRIVE_INTERFACE QLatin1String("org.freedesktop.UDisks2.Drive")
#define UDISKS2_BLOCK_INTERFACE QLatin1String("org.freedesktop.UDisks2.Block")
#define UDISKS2_FILESYSTEM_INTERFACE QLatin1String("org.freedesktop.UDisks2.Filesystem")
#define UDISKS2_PARTITION_INTERFACE QLatin1String("org.freedesktop.UDisks2.Partition")
Expand Down
15 changes: 8 additions & 7 deletions src/udisks2monitor.cpp
Expand Up @@ -85,7 +85,7 @@ UDisks2::Monitor::Monitor(PartitionManagerPrivate *manager, QObject *parent)
Q_ASSERT(!sharedInstance);
sharedInstance = this;

qDBusRegisterMetaType<InterfacePropertyMap>();
qDBusRegisterMetaType<UDisks2::InterfacePropertyMap>();
QDBusConnection systemBus = QDBusConnection::systemBus();

connect(systemBus.interface(), &QDBusConnectionInterface::callWithCallbackFailed, this, [this](const QDBusError &error, const QDBusMessage &call) {
Expand All @@ -104,17 +104,17 @@ UDisks2::Monitor::Monitor(PartitionManagerPrivate *manager, QObject *parent)
UDISKS2_SERVICE,
UDISKS2_PATH,
DBUS_OBJECT_MANAGER_INTERFACE,
QStringLiteral("InterfacesAdded"),
interfacesAddedSignal,
this,
SLOT(interfacesAdded(QDBusObjectPath, InterfacePropertyMap)))) {
SLOT(interfacesAdded(QDBusObjectPath, UDisks2::InterfacePropertyMap)))) {
qCWarning(lcMemoryCardLog) << "Failed to connect to interfaces added signal:" << qPrintable(systemBus.lastError().message());
}

if (!systemBus.connect(
UDISKS2_SERVICE,
UDISKS2_PATH,
DBUS_OBJECT_MANAGER_INTERFACE,
QStringLiteral("InterfacesRemoved"),
interfacesRemovedSignal,
this,
SLOT(interfacesRemoved(QDBusObjectPath, QStringList)))) {
qCWarning(lcMemoryCardLog) << "Failed to connect to interfaces removed signal:" << qPrintable(systemBus.lastError().message());
Expand Down Expand Up @@ -202,7 +202,7 @@ void UDisks2::Monitor::format(const QString &deviceName, const QString &type, co
doFormat(deviceName, objectPath, type, arguments);
}

void UDisks2::Monitor::interfacesAdded(const QDBusObjectPath &objectPath, const InterfacePropertyMap &interfaces)
void UDisks2::Monitor::interfacesAdded(const QDBusObjectPath &objectPath, const UDisks2::InterfacePropertyMap &interfaces)
{
QString path = objectPath.path();
qCInfo(lcMemoryCardLog) << "UDisks interface added:" << path << interfaces << externalBlockDevice(path);
Expand Down Expand Up @@ -291,6 +291,7 @@ void UDisks2::Monitor::setPartitionProperties(QExplicitlySharedDataPointer<Parti
partition->canMount = blockDevice->isMountable() && m_manager->supportedFileSystems().contains(partition->filesystemType);
partition->status = blockDevice->isEncrypted() ? Partition::Locked
: blockDevice->mountPath().isEmpty() ? Partition::Unmounted : Partition::Mounted;
partition->isCryptoDevice = blockDevice->isEncrypted() || blockDevice->hasCryptoBackingDevice();
}

void UDisks2::Monitor::updatePartitionProperties(const UDisks2::Block *blockDevice)
Expand Down Expand Up @@ -561,7 +562,7 @@ void UDisks2::Monitor::createPartition(const UDisks2::Block *block)
m_manager->add(addedPartitions);
}

void UDisks2::Monitor::createBlockDevice(const QString &path, const InterfacePropertyMap &interfacePropertyMap)
void UDisks2::Monitor::createBlockDevice(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap)
{
if (m_blockDevices.contains(path)) {
return;
Expand Down Expand Up @@ -698,7 +699,7 @@ void UDisks2::Monitor::getBlockDevices()
for (const QDBusObjectPath &dbusObjectPath : blockDevicePaths) {
QString path = dbusObjectPath.path();
if (externalBlockDevice(path)) {
createBlockDevice(path, InterfacePropertyMap());
createBlockDevice(path, UDisks2::InterfacePropertyMap());
}
}
} else if (watcher->isError()) {
Expand Down
6 changes: 3 additions & 3 deletions src/udisks2monitor_p.h
Expand Up @@ -41,7 +41,7 @@

#include "partitionmodel.h"
#include "partitionmanager_p.h"
#include "udisks2block_p.h"
#include "udisks2defines.h"

class PartitionManagerPrivate;

Expand Down Expand Up @@ -96,7 +96,7 @@ class Monitor : public QObject
void formatError(Partition::Error error);

private slots:
void interfacesAdded(const QDBusObjectPath &objectPath, const InterfacePropertyMap &interfaces);
void interfacesAdded(const QDBusObjectPath &objectPath, const UDisks2::InterfacePropertyMap &interfaces);
void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces);

private:
Expand All @@ -110,7 +110,7 @@ private slots:
void lookupPartitions(PartitionManagerPrivate::Partitions &affectedPartitions, const QStringList &objects);

void createPartition(const Block *block);
void createBlockDevice(const QString &path, const InterfacePropertyMap &interfacePropertyMap);
void createBlockDevice(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap);

void doFormat(const QString &deviceName, const QString &dbusObjectPath, const QString &type, const QVariantHash &arguments);
void getBlockDevices();
Expand Down

0 comments on commit daedc48

Please sign in to comment.