Improved device discovery via Solid.
Use the Solid-provided icon name for devices. svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1074953
This commit is contained in:
parent
1051962f62
commit
8058585d49
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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<qint64>(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<qint64>(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
|
||||
|
|
|
@ -279,24 +279,19 @@ void LibParted::scanDevices(OperationStack& ostack)
|
|||
// For that reason we scan devices on our own using Solid now.
|
||||
QList<Solid::Device> 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<Solid::StorageDrive>();
|
||||
const Solid::StorageDrive* solidDrive = solidDevice.as<Solid::StorageDrive>();
|
||||
|
||||
if (drv->driveType() == Solid::StorageDrive::HardDisk)
|
||||
{
|
||||
const Solid::Block* b = d.as<Solid::Block>();
|
||||
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<Solid::Block>();
|
||||
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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue