From 8058585d4914275fd36a009e15d6fd9f58f5ca3e Mon Sep 17 00:00:00 2001 From: Volker Lanz Date: Fri, 15 Jan 2010 01:46:45 +0000 Subject: [PATCH] Improved device discovery via Solid. Use the Solid-provided icon name for devices. svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1074953 --- src/core/device.cpp | 5 +++-- src/core/device.h | 4 +++- src/core/libparted.cpp | 26 ++++++++------------------ src/gui/listdevices.cpp | 2 +- src/gui/partitionmanagerwidget.cpp | 2 +- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/core/device.cpp b/src/core/device.cpp index 8ed2563..9bc31bb 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -32,7 +32,7 @@ @param cylinders the number of cylinders in CHS notation @param sectorSize the size of a sector in bytes */ -Device::Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize) : +Device::Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, const QString& iconname) : QObject(), m_Name(name), m_DeviceNode(devicenode), @@ -40,7 +40,8 @@ Device::Device(const QString& name, const QString& devicenode, qint32 heads, qin m_Heads(heads), m_SectorsPerTrack(numSectors), m_Cylinders(cylinders), - m_SectorSize(sectorSize) + m_SectorSize(sectorSize), + m_IconName(iconname.isEmpty() ? "drive-hardisk" : iconname) { } diff --git a/src/core/device.h b/src/core/device.h index 70be842..286ebd6 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -47,7 +47,7 @@ class Device : public QObject friend class LibParted; public: - Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize); + Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, const QString& iconname = QString()); ~Device(); public: @@ -62,6 +62,7 @@ class Device : public QObject qint64 totalSectors() const { return static_cast(heads()) * cylinders() * sectorsPerTrack(); } /**< @return the total number of sectors on the device */ qint64 capacity() const { return totalSectors() * sectorSize(); } /**< @return the Device's capacity in bytes */ qint64 cylinderSize() const { return static_cast(heads()) * sectorsPerTrack(); } /**< @return the size of a cylinder on this Device in sectors */ + const QString& iconName() const { return m_IconName; } /**< @return suggested icon name for this Device */ protected: void setPartitionTable(PartitionTable* ptable) { m_PartitionTable = ptable; } @@ -74,6 +75,7 @@ class Device : public QObject qint32 m_SectorsPerTrack; qint32 m_Cylinders; qint32 m_SectorSize; + QString m_IconName; }; #endif diff --git a/src/core/libparted.cpp b/src/core/libparted.cpp index b8c556a..2e830ff 100644 --- a/src/core/libparted.cpp +++ b/src/core/libparted.cpp @@ -279,24 +279,19 @@ void LibParted::scanDevices(OperationStack& ostack) // For that reason we scan devices on our own using Solid now. QList driveList = Solid::Device::listFromType(Solid::DeviceInterface::StorageDrive, QString()); - foreach(const Solid::Device& d, driveList) + foreach(const Solid::Device& solidDevice, driveList) { - const Solid::StorageDrive* drv = d.as(); + const Solid::StorageDrive* solidDrive = solidDevice.as(); - if (drv->driveType() == Solid::StorageDrive::HardDisk) - { - const Solid::Block* b = d.as(); - ped_device_get(b->device().toLocal8Bit()); - } - } + if (solidDrive->driveType() != Solid::StorageDrive::HardDisk) + continue; - PedDevice* pedDevice = ped_device_get_next(NULL); + const Solid::Block* solidBlock = solidDevice.as(); + PedDevice* pedDevice = ped_device_get(solidBlock->device().toLocal8Bit()); - while (pedDevice) - { log(log::information) << i18nc("@info/plain", "Device found: %1", pedDevice->model); - Device* d = new Device(pedDevice->model, pedDevice->path, pedDevice->bios_geom.heads, pedDevice->bios_geom.sectors, pedDevice->bios_geom.cylinders, pedDevice->sector_size); + Device* d = new Device(pedDevice->model, pedDevice->path, pedDevice->bios_geom.heads, pedDevice->bios_geom.sectors, pedDevice->bios_geom.cylinders, pedDevice->sector_size, solidDevice.icon()); PedDisk* pedDisk = ped_disk_new(pedDevice); @@ -309,12 +304,7 @@ void LibParted::scanDevices(OperationStack& ostack) scanDevicePartitions(pedDevice, *d, pedDisk, mountInfo); } - // add this device if either there is a valid partition table or it's not - // read only (read only devices without partition table are CD/DVD readers, writers etc) - if (pedDisk || !pedDevice->read_only) - ostack.addDevice(d); - - pedDevice = ped_device_get_next(pedDevice); + ostack.addDevice(d); } ostack.sortDevices(); diff --git a/src/gui/listdevices.cpp b/src/gui/listdevices.cpp index 978efd0..2bae0f2 100644 --- a/src/gui/listdevices.cpp +++ b/src/gui/listdevices.cpp @@ -51,7 +51,7 @@ void ListDevices::updateDevices() { const QString shortText = d->deviceNode() + " (" + Capacity(*d).toString() + ')'; const QString longText = d->deviceNode() + " (" + Capacity(*d).toString() + ", " + d->name() + ')'; - QListWidgetItem* item = new QListWidgetItem(DesktopIcon("drive-harddisk"), shortText); + QListWidgetItem* item = new QListWidgetItem(DesktopIcon(d->iconName()), shortText); item->setToolTip(longText); item->setSizeHint(QSize(0, 32)); listDevices().addItem(item); diff --git a/src/gui/partitionmanagerwidget.cpp b/src/gui/partitionmanagerwidget.cpp index 14c3445..b14c12a 100644 --- a/src/gui/partitionmanagerwidget.cpp +++ b/src/gui/partitionmanagerwidget.cpp @@ -379,7 +379,7 @@ void PartitionManagerWidget::updatePartitions() QTreeWidgetItem* deviceItem = new QTreeWidgetItem(); deviceItem->setText(0, selectedDevice()->name()); - deviceItem->setIcon(0, DesktopIcon("drive-harddisk")); + deviceItem->setIcon(0, DesktopIcon(selectedDevice()->iconName())); deviceItem->setSizeHint(0, QSize(0, 32)); treePartitions().addTopLevelItem(deviceItem);