Commit 52661099 authored by Raine Makelainen's avatar Raine Makelainen

Add common partition lookup method

parent 293ae72d
......@@ -122,17 +122,9 @@ void PartitionModel::refresh(int index)
void PartitionModel::lock(const QString &deviceName)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->lock(partition);
break;
}
}
if (!found) {
if (const Partition *partition = getPartition(deviceName)) {
m_manager->lock(*partition);
} else {
qCWarning(lcMemoryCardLog) << "Unable to lock unknown device:" << deviceName;
}
}
......@@ -140,17 +132,9 @@ void PartitionModel::lock(const QString &deviceName)
void PartitionModel::unlock(const QString &deviceName, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->unlock(partition, passphrase);
break;
}
}
if (!found) {
if (const Partition *partition = getPartition(deviceName)) {
m_manager->unlock(*partition, passphrase);
} else {
qCWarning(lcMemoryCardLog) << "Unable to unlock unknown device:" << deviceName;
}
}
......@@ -158,17 +142,9 @@ void PartitionModel::unlock(const QString &deviceName, const QString &passphrase
void PartitionModel::mount(const QString &deviceName)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->mount(partition);
break;
}
}
if (!found) {
if (const Partition *partition = getPartition(deviceName)) {
m_manager->mount(*partition);
} else {
qCWarning(lcMemoryCardLog) << "Unable to mount unknown device:" << deviceName;
}
}
......@@ -176,17 +152,9 @@ void PartitionModel::mount(const QString &deviceName)
void PartitionModel::unmount(const QString &deviceName)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->unmount(partition);
break;
}
}
if (!found) {
if (const Partition *partition = getPartition(deviceName)) {
m_manager->unmount(*partition);
} else {
qCWarning(lcMemoryCardLog) << "Unable to unmount unknown device:" << deviceName;
}
}
......@@ -194,17 +162,9 @@ void PartitionModel::unmount(const QString &deviceName)
void PartitionModel::format(const QString &deviceName, const QString &type, const QString &label, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << type << label << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->format(partition, type, label, passphrase);
break;
}
}
if (!found) {
if (const Partition *partition = getPartition(deviceName)) {
m_manager->format(*partition, type, label, passphrase);
} else {
qCWarning(lcMemoryCardLog) << "Unable to format unknown device:" << deviceName;
}
}
......@@ -251,6 +211,17 @@ void PartitionModel::update()
}
}
const Partition *PartitionModel::getPartition(const QString &deviceName) const
{
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
return &partition;
}
}
return nullptr;
}
QHash<int, QByteArray> PartitionModel::roleNames() const
{
static const QHash<int, QByteArray> roleNames = {
......
......@@ -150,6 +150,8 @@ signals:
private:
void update();
const Partition *getPartition(const QString &deviceName) const;
void partitionChanged(const Partition &partition);
void partitionAdded(const Partition &partition);
void partitionRemoved(const Partition &partition);
......
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