Commit bc5da22a authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb42943' into 'master'

Make block devices without partition/partitiontable visible in model

See merge request mer-core/nemo-qml-plugin-systemsettings!91
parents e1d9073b 7b6a8ed9
......@@ -101,9 +101,9 @@ Partition::StorageType Partition::storageType() const
return d ? d->storageType : Invalid;
}
Partition::ConnectionBus Partition::connectionBus() const
QVariantMap Partition::drive() const
{
return d ? d->connectionBus : UnknownBus;
return d ? d->drive : QVariantMap();
}
QString Partition::devicePath() const
......
......@@ -115,7 +115,7 @@ public:
QString cryptoBackingDevicePath() const;
StorageType storageType() const;
ConnectionBus connectionBus() const;
QVariantMap drive() const;
QString devicePath() const;
QString deviceName() const;
......
......@@ -34,6 +34,8 @@
#include "partition.h"
#include <QVariantMap>
class PartitionManagerPrivate;
class PartitionPrivate : public QSharedData
......@@ -45,7 +47,6 @@ public:
, bytesTotal(0)
, bytesFree(0)
, storageType(Partition::Invalid)
, connectionBus(Partition::UnknownBus)
, status(Partition::Unmounted)
, readOnly(true)
, canMount(false)
......@@ -76,8 +77,8 @@ public:
qint64 bytesTotal;
qint64 bytesFree;
Partition::StorageType storageType;
Partition::ConnectionBus connectionBus;
Partition::Status status;
QVariantMap drive;
bool readOnly;
bool canMount;
bool isEncrypted;
......
......@@ -31,6 +31,7 @@
#include "partitionmanager_p.h"
#include "udisks2monitor_p.h"
#include "udisks2blockdevices_p.h"
#include "logging_p.h"
#include <QFile>
......@@ -62,17 +63,22 @@ PartitionManagerPrivate::PartitionManagerPrivate()
connect(m_udisksMonitor.data(), &UDisks2::Monitor::unmountError, this, &PartitionManagerPrivate::unmountError);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::formatError, this, &PartitionManagerPrivate::formatError);
QVariantMap defaultDrive;
defaultDrive.insert(QLatin1String("model"), QString());
defaultDrive.insert(QLatin1String("vendor"), QString());
defaultDrive.insert(QLatin1String("connectionBus"), Partition::SDIO);
QExplicitlySharedDataPointer<PartitionPrivate> root(new PartitionPrivate(this));
root->storageType = Partition::System;
root->connectionBus = Partition::SDIO;
root->mountPath = QStringLiteral("/");
root->drive = defaultDrive;
m_partitions.append(root);
QExplicitlySharedDataPointer<PartitionPrivate> home(new PartitionPrivate(this));
home->storageType = Partition::User;
home->connectionBus = Partition::SDIO;
home->mountPath = QStringLiteral("/home");
home->drive = defaultDrive;
m_partitions.append(home);
refresh(m_partitions, m_partitions);
......@@ -152,7 +158,8 @@ void PartitionManagerPrivate::add(QExplicitlySharedDataPointer<PartitionPrivate>
{
int insertIndex = 0;
for (const auto existingPartition : m_partitions) {
if (existingPartition->connectionBus <= partition->connectionBus)
if (existingPartition->drive.value(QLatin1String("connectionBus")).toInt()
<= partition->drive.value(QLatin1String("connectionBus")).toInt())
++insertIndex;
else
break;
......@@ -299,7 +306,7 @@ void PartitionManagerPrivate::unlock(const Partition &partition, const QString &
{
qCInfo(lcMemoryCardLog) << "Can unlock:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.devicePath();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->instance()->unlock(partition.devicePath(), passphrase);
m_udisksMonitor->unlock(partition.devicePath(), passphrase);
} else {
qCWarning(lcMemoryCardLog) << "Unlock allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
......@@ -309,7 +316,7 @@ void PartitionManagerPrivate::mount(const Partition &partition)
{
qCInfo(lcMemoryCardLog) << "Can mount:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.devicePath();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->instance()->mount(partition.devicePath());
m_udisksMonitor->mount(partition.devicePath());
} else {
qCWarning(lcMemoryCardLog) << "Mount allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
......@@ -319,7 +326,7 @@ void PartitionManagerPrivate::unmount(const Partition &partition)
{
qCInfo(lcMemoryCardLog) << "Can unmount:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.devicePath();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->instance()->unmount(partition.devicePath());
m_udisksMonitor->unmount(partition.devicePath());
} else {
qCWarning(lcMemoryCardLog) << "Unmount allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
......@@ -330,7 +337,7 @@ void PartitionManagerPrivate::format(const QString &devicePath, const QString &f
QString deviceName = devicePath.section(QChar('/'), 2);
qCInfo(lcMemoryCardLog) << "Can format:" << externalMedia.match(deviceName).hasMatch() << devicePath;
if (externalMedia.match(deviceName).hasMatch()) {
m_udisksMonitor->instance()->format(devicePath, filesystemType, arguments);
m_udisksMonitor->format(devicePath, filesystemType, arguments);
} else {
qCWarning(lcMemoryCardLog) << "Formatting allowed only for external memory cards," << devicePath << "is not allowed";
}
......@@ -340,7 +347,7 @@ QString PartitionManagerPrivate::objectPath(const QString &devicePath) const
{
QString deviceName = devicePath.section(QChar('/'), 2);
if (externalMedia.match(deviceName).hasMatch()) {
return m_udisksMonitor->instance()->objectPath(devicePath);
return UDisks2::BlockDevices::instance()->objectPath(devicePath);
} else {
qCWarning(lcMemoryCardLog) << "Object path existing only for external memory cards:" << devicePath;
return QString();
......
......@@ -90,6 +90,7 @@ signals:
void formatError(Partition::Error error);
private:
// TODO: This is leaking (Disks2::Monitor is never free'ed).
static PartitionManagerPrivate *sharedInstance;
Partitions m_partitions;
......
......@@ -261,7 +261,7 @@ QHash<int, QByteArray> PartitionModel::roleNames() const
{ IsSupportedFileSystemType, "isSupportedFileSystemType"},
{ IsEncryptedRoles, "isEncrypted"},
{ CryptoBackingDevicePath, "cryptoBackingDevicePath"},
{ ConnectionBusRole, "connectionBus"},
{ DriveRole, "drive"},
};
return roleNames;
......@@ -316,8 +316,8 @@ QVariant PartitionModel::data(const QModelIndex &index, int role) const
return partition.isEncrypted();
case CryptoBackingDevicePath:
return partition.cryptoBackingDevicePath();
case ConnectionBusRole:
return partition.connectionBus();
case DriveRole:
return partition.drive();
default:
return QVariant();
}
......
......@@ -66,7 +66,7 @@ public:
IsSupportedFileSystemType,
IsEncryptedRoles,
CryptoBackingDevicePath,
ConnectionBusRole,
DriveRole,
};
// For Status role
......
......@@ -39,6 +39,7 @@ SOURCES += \
locationsettings.cpp \
timezoneinfo.cpp \
udisks2block.cpp \
udisks2blockdevices.cpp \
udisks2job.cpp \
udisks2monitor.cpp
......@@ -78,6 +79,7 @@ HEADERS += \
partition_p.h \
partitionmanager_p.h \
udisks2block_p.h \
udisks2blockdevices_p.h \
udisks2job_p.h \
udisks2monitor_p.h
......
This diff is collapsed.
......@@ -35,6 +35,7 @@
#include <QObject>
#include <QVariantMap>
#include <QDBusConnection>
#include <QPointer>
#include "udisks2defines.h"
......@@ -42,14 +43,13 @@ class QDBusPendingCallWatcher;
namespace UDisks2 {
class Block : public QObject
{
Q_OBJECT
Q_PROPERTY(QString connectionBus READ connectionBus NOTIFY updated)
public:
Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
virtual ~Block();
QString path() const;
......@@ -57,8 +57,14 @@ public:
QString device() const;
QString preferredDevice() const;
QString drive() const;
QString driveModel() const;
QString driveVendor() const;
QString connectionBus() const;
QString partitionTable() const;
bool isPartition() const;
bool isPartitionTable() const;
qint64 deviceNumber() const;
QString id() const;
......@@ -99,34 +105,38 @@ public:
static QString cryptoBackingDevicePath(const QString &objectPath);
void addInterface(const QString &interface, QVariantMap propertyMap);
void removeInterface(const QString &interface);
void morph(const Block& other);
signals:
void completed();
void completed(QPrivateSignal);
void updated();
void formatted();
void mountPathChanged();
private slots:
void updateProperties(const QDBusMessage &message);
void complete();
private:
Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
Block& operator=(const Block& other);
bool setEncrypted(bool encrypted);
bool setMountable(bool mountable);
void addInterface(const QString &interface, QVariantMap propertyMap);
void removeInterface(const QString &interface);
int interfaceCount() const;
bool hasInterface(const QString &interface) const;
bool isCompleted() const;
void updateMountPoint(const QVariant &mountPoints);
void complete();
void updateFileSystemInterface(const QVariant &mountPoints);
bool clearFormattingState();
void getFileSystemInterface();
void getEncryptedInterface();
void getDriveProperties();
void getProperties(const QString &path, const QString &interface,
QPointer<QDBusPendingCallWatcher> &watcherPointer,
std::function<void (const QVariantMap &)> success);
void rescan(const QString &dbusObjectPath);
......@@ -141,10 +151,14 @@ private:
bool m_formatting;
bool m_locking;
QDBusPendingCallWatcher *m_pendingFileSystem;
QDBusPendingCallWatcher *m_pendingBlock;
QDBusPendingCallWatcher *m_pendingEncrypted;
QDBusPendingCallWatcher *m_pendingDrive;
QPointer<QDBusPendingCallWatcher> m_pendingFileSystem;
QPointer<QDBusPendingCallWatcher> m_pendingBlock;
QPointer<QDBusPendingCallWatcher> m_pendingEncrypted;
QPointer<QDBusPendingCallWatcher> m_pendingDrive;
QPointer<QDBusPendingCallWatcher> m_pendingPartition;
QPointer<QDBusPendingCallWatcher> m_pendingPartitionTable;
friend class BlockDevices;
};
}
......
This diff is collapsed.
/*
* Copyright (C) 2018 Jolla Ltd. <raine.makelainen@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#ifndef UDISKS2_BLOCK_DEVICES_H
#define UDISKS2_BLOCK_DEVICES_H
#include <QMap>
#include <QPointer>
#include "udisks2block_p.h"
class QTimerEvent;
namespace UDisks2 {
class BlockDevices : public QObject
{
Q_OBJECT
public:
static BlockDevices* instance();
virtual ~BlockDevices() override;
bool contains(const QString &dbusObjectPath) const;
void remove(const QString &dbusObjectPath);
Block *device(const QString &dbusObjectPath) const;
Block *replace(const QString &dbusObjectPath, Block *block);
void insert(const QString &dbusObjectPath, Block *block);
Block *find(std::function<bool (const Block *block)> condition);
Block *find(const QString &devicePath);
QString objectPath(const QString &devicePath) const;
QStringList devicePaths(const QStringList &dbusObjectPaths) const;
bool createBlockDevice(const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap);
void lock(const QString &dbusObjectPath);
void waitPartition(Block *block);
void clearPartitionWait(const QString &dbusObjectPath, bool destroyBlock);
void removeInterfaces(const QString &dbusObjectPath, const QStringList &interfaces);
void dumpBlocks() const;
static bool isExternal(const QString &dbusObjectPath);
signals:
void newBlock(Block *block);
private slots:
void blockCompleted();
private:
struct PartitionWaiter {
PartitionWaiter(int timer, Block *block);
~PartitionWaiter();
int timer;
Block *block;
};
BlockDevices(QObject *parent = nullptr);
Block *doCreateBlockDevice(const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap);
void updateFormattingState(Block *block);
void complete(Block *block, bool forceAccept = false);
void timerEvent(QTimerEvent *e) override;
QMap<QString, Block *> m_blockDevices;
QMap<QString, PartitionWaiter*> m_partitionWaits;
static QPointer<BlockDevices> sharedInstance;
};
}
#endif
......@@ -54,13 +54,14 @@ Q_DECLARE_METATYPE(UDisks2::InterfacePropertyMap)
#define UDISKS2_MANAGER_PATH QLatin1String("/org/freedesktop/UDisks2/Manager")
// 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")
#define UDISKS2_JOB_INTERFACE QLatin1String("org.freedesktop.UDisks2.Job")
#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")
#define UDISKS2_PARTITION_TABLE_INTERFACE QLatin1String("org.freedesktop.UDisks2.PartitionTable")
#define UDISKS2_JOB_INTERFACE QLatin1String("org.freedesktop.UDisks2.Job")
// Jobs
#define UDISKS2_JOB_OP_ENC_LOCK QLatin1String("encrypted-lock")
......
......@@ -137,17 +137,16 @@ UDisks2::Job::Operation UDisks2::Job::operation() const
}
}
void UDisks2::Job::dumpInfo() const
{
qCInfo(lcMemoryCardLog) << "Job" << path() << ((status() == Added) ? "added" : "completed");
for (const QString &key : m_data.keys()) {
qCInfo(lcMemoryCardLog) << "- " << qPrintable(key) << value(key);
}
}
void UDisks2::Job::updateCompleted(bool success, const QString &message)
{
complete(success);
m_message = message;
QDBusConnection systemBus = QDBusConnection::systemBus();
systemBus.disconnect(
UDISKS2_SERVICE,
m_path,
UDISKS2_JOB_INTERFACE,
QStringLiteral("Completed"),
this,
SLOT(updateJobStatus(bool, QString)));
complete(success);
}
......@@ -76,6 +76,8 @@ public:
Status status() const;
Operation operation() const;
void dumpInfo() const;
signals:
void completed(bool success);
......
This diff is collapsed.
......@@ -50,6 +50,7 @@ static const QRegularExpression deviceRoot(QStringLiteral("^mmcblk\\d+$"));
namespace UDisks2 {
class Block;
class BlockDevices;
class Job;
struct Operation
......@@ -86,8 +87,6 @@ public:
void format(const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments);
QString objectPath(const QString &devicePath) const;
signals:
void status(const QString &devicePath, Partition::Status);
void errorMessage(const QString &objectPath, const QString &errorName);
......@@ -101,33 +100,30 @@ private slots:
void interfacesAdded(const QDBusObjectPath &objectPath, const UDisks2::InterfacePropertyMap &interfaces);
void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces);
void doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &filesystemType, const QVariantMap &arguments);
void handleNewBlock(UDisks2::Block *block);
private:
void setPartitionProperties(QExplicitlySharedDataPointer<PartitionPrivate> &partition, const Block *blockDevice);
void updatePartitionProperties(const Block *blockDevice);
void updatePartitionStatus(const Job *job, bool success);
bool externalBlockDevice(const QString &objectPathStr) const;
void startLuksOperation(const QString &devicePath, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments);
void startMountOperation(const QString &devicePath, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments);
void lookupPartitions(PartitionManagerPrivate::Partitions &affectedPartitions, const QStringList &objects);
void createPartition(const Block *block);
Block *createBlockDevice(const QString &dbusObjectPath, const UDisks2::InterfacePropertyMap &interfacePropertyMap);
void getBlockDevices();
Block *findBlock(const QString &devicePath) const;
void updateFormattingState(UDisks2::Block *block);
void connectSignals(UDisks2::Block *block);
private:
static Monitor *sharedInstance;
QExplicitlySharedDataPointer<PartitionManagerPrivate> m_manager;
QMap<QString, Job *> m_jobsToWait;
QMap<QString, Block *> m_blockDevices;
QQueue<Operation> m_operationQueue;
BlockDevices *m_blockDevices;
};
}
......
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