Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[partitionmodel] Change lock, unlock, mount, unmount to devicePath ba…
…sed. Contributes to JB#42996
  • Loading branch information
rainemak committed Sep 19, 2018
1 parent 3006733 commit 1796c15
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 103 deletions.
22 changes: 11 additions & 11 deletions src/partitionmanager.cpp
Expand Up @@ -278,50 +278,50 @@ void PartitionManagerPrivate::refresh(const Partitions &partitions, Partitions &

void PartitionManagerPrivate::lock(const Partition &partition)
{
qCInfo(lcMemoryCardLog) << "Can lock:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.deviceName();
qCInfo(lcMemoryCardLog) << "Can lock:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.devicePath();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->lock(partition.deviceName());
m_udisksMonitor->lock(partition.devicePath());
} else {
qCWarning(lcMemoryCardLog) << "Lock allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
}

void PartitionManagerPrivate::unlock(const Partition &partition, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << "Can unlock:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.deviceName();
qCInfo(lcMemoryCardLog) << "Can unlock:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.devicePath();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->instance()->unlock(partition.deviceName(), passphrase);
m_udisksMonitor->instance()->unlock(partition.devicePath(), passphrase);
} else {
qCWarning(lcMemoryCardLog) << "Unlock allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
}

void PartitionManagerPrivate::mount(const Partition &partition)
{
qCInfo(lcMemoryCardLog) << "Can mount:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.deviceName();
qCInfo(lcMemoryCardLog) << "Can mount:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.devicePath();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->instance()->mount(partition.deviceName());
m_udisksMonitor->instance()->mount(partition.devicePath());
} else {
qCWarning(lcMemoryCardLog) << "Mount allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
}

void PartitionManagerPrivate::unmount(const Partition &partition)
{
qCInfo(lcMemoryCardLog) << "Can unmount:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.deviceName();
qCInfo(lcMemoryCardLog) << "Can unmount:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.devicePath();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->instance()->unmount(partition.deviceName());
m_udisksMonitor->instance()->unmount(partition.devicePath());
} else {
qCWarning(lcMemoryCardLog) << "Unmount allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
}

void PartitionManagerPrivate::format(const Partition &partition, const QString &type, const QString &label, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << "Can format:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.deviceName();
qCInfo(lcMemoryCardLog) << "Can format:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.devicePath();

if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->instance()->format(partition.deviceName(), type, label, passphrase);
m_udisksMonitor->instance()->format(partition.devicePath(), type, label, passphrase);
} else {
qCWarning(lcMemoryCardLog) << "Formatting allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
Expand All @@ -330,7 +330,7 @@ void PartitionManagerPrivate::format(const Partition &partition, const QString &
QString PartitionManagerPrivate::objectPath(const Partition &partition) const
{
if (externalMedia.match(partition.deviceName()).hasMatch()) {
return m_udisksMonitor->instance()->objectPath(partition.deviceName());
return m_udisksMonitor->instance()->objectPath(partition.devicePath());
} else {
qCWarning(lcMemoryCardLog) << "Object path existing only for external memory cards:" << partition.devicePath();
return QString();
Expand Down
52 changes: 26 additions & 26 deletions src/partitionmodel.cpp
Expand Up @@ -119,63 +119,63 @@ void PartitionModel::refresh(int index)
}
}

void PartitionModel::lock(const QString &deviceName)
void PartitionModel::lock(const QString &devicePath)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
if (const Partition *partition = getPartition(deviceName)) {
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << m_partitions.count();
if (const Partition *partition = getPartition(devicePath)) {
m_manager->lock(*partition);
} else {
qCWarning(lcMemoryCardLog) << "Unable to lock unknown device:" << deviceName;
qCWarning(lcMemoryCardLog) << "Unable to lock unknown device:" << devicePath;
}
}

void PartitionModel::unlock(const QString &deviceName, const QString &passphrase)
void PartitionModel::unlock(const QString &devicePath, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
if (const Partition *partition = getPartition(deviceName)) {
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << m_partitions.count();
if (const Partition *partition = getPartition(devicePath)) {
m_manager->unlock(*partition, passphrase);
} else {
qCWarning(lcMemoryCardLog) << "Unable to unlock unknown device:" << deviceName;
qCWarning(lcMemoryCardLog) << "Unable to unlock unknown device:" << devicePath;
}
}

void PartitionModel::mount(const QString &deviceName)
void PartitionModel::mount(const QString &devicePath)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
if (const Partition *partition = getPartition(deviceName)) {
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << m_partitions.count();
if (const Partition *partition = getPartition(devicePath)) {
m_manager->mount(*partition);
} else {
qCWarning(lcMemoryCardLog) << "Unable to mount unknown device:" << deviceName;
qCWarning(lcMemoryCardLog) << "Unable to mount unknown device:" << devicePath;
}
}

void PartitionModel::unmount(const QString &deviceName)
void PartitionModel::unmount(const QString &devicePath)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
if (const Partition *partition = getPartition(deviceName)) {
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << m_partitions.count();
if (const Partition *partition = getPartition(devicePath)) {
m_manager->unmount(*partition);
} else {
qCWarning(lcMemoryCardLog) << "Unable to unmount unknown device:" << deviceName;
qCWarning(lcMemoryCardLog) << "Unable to unmount unknown device:" << devicePath;
}
}

void PartitionModel::format(const QString &deviceName, const QString &type, const QString &label, const QString &passphrase)
void PartitionModel::format(const QString &devicePath, const QString &type, const QString &label, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << type << label << m_partitions.count();
if (const Partition *partition = getPartition(deviceName)) {
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath << type << label << m_partitions.count();
if (const Partition *partition = getPartition(devicePath)) {
m_manager->format(*partition, type, label, passphrase);
} else {
qCWarning(lcMemoryCardLog) << "Unable to format unknown device:" << deviceName;
qCWarning(lcMemoryCardLog) << "Unable to format unknown device:" << devicePath;
}
}

QString PartitionModel::objectPath(const QString &deviceName) const
QString PartitionModel::objectPath(const QString &devicePath) const
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName;
if (const Partition *partition = getPartition(deviceName)) {
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << devicePath;
if (const Partition *partition = getPartition(devicePath)) {
return m_manager->objectPath(*partition);
} else {
qCWarning(lcMemoryCardLog) << "Unable to get object path for unknown device:" << deviceName;
qCWarning(lcMemoryCardLog) << "Unable to get object path for unknown device:" << devicePath;
return QString();
}
}
Expand Down Expand Up @@ -222,10 +222,10 @@ void PartitionModel::update()
}
}

const Partition *PartitionModel::getPartition(const QString &deviceName) const
const Partition *PartitionModel::getPartition(const QString &devicePath) const
{
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
if (devicePath == partition.devicePath()) {
return &partition;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/partitionmodel.h
Expand Up @@ -127,13 +127,13 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel
Q_INVOKABLE void refresh();
Q_INVOKABLE void refresh(int index);

Q_INVOKABLE void lock(const QString &deviceName);
Q_INVOKABLE void unlock(const QString &deviceName, const QString &passphrase);
Q_INVOKABLE void mount(const QString &deviceName);
Q_INVOKABLE void unmount(const QString &deviceName);
Q_INVOKABLE void format(const QString &deviceName, const QString &type, const QString &label, const QString &passphrase = QString());
Q_INVOKABLE void lock(const QString &devicePath);
Q_INVOKABLE void unlock(const QString &devicePath, const QString &passphrase);
Q_INVOKABLE void mount(const QString &devicePath);
Q_INVOKABLE void unmount(const QString &devicePath);
Q_INVOKABLE void format(const QString &devicePath, const QString &type, const QString &label, const QString &passphrase = QString());

Q_INVOKABLE QString objectPath(const QString &deviceName) const;
Q_INVOKABLE QString objectPath(const QString &devicePath) const;

QHash<int, QByteArray> roleNames() const;

Expand All @@ -154,7 +154,7 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel
private:
void update();

const Partition *getPartition(const QString &deviceName) const;
const Partition *getPartition(const QString &devicePath) const;

void partitionChanged(const Partition &partition);
void partitionAdded(const Partition &partition);
Expand Down

0 comments on commit 1796c15

Please sign in to comment.