scan for devices in the backend, not the device scanner thread

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1098235
This commit is contained in:
Volker Lanz 2010-03-03 09:51:53 +00:00
parent 23d78e20b4
commit dd9d20345d
8 changed files with 77 additions and 44 deletions

4
TODO
View File

@ -27,10 +27,6 @@ Random plans and ideas for 1.1 and beyond:
* let the user specify extern command locations and options in the settings
* move device scanning to backend plugin (call it from the device scanner
thread though)
Bugs:
* solid and its object-created-with-parent-in-wrong-thread problem

View File

@ -56,6 +56,11 @@ void CoreBackend::emitProgress(int i)
emit progress(i);
}
void CoreBackend::emitScanProgress(const QString& device_node, int i)
{
emit scanProgress(device_node, i);
}
void CoreBackend::setPartitionTableForDevice(Device& d, PartitionTable* p)
{
d.setPartitionTable(p);

View File

@ -24,6 +24,7 @@
#include "util/libpartitionmanagerexport.h"
#include <QObject>
#include <QList>
class CoreBackendDevice;
class Device;
@ -42,16 +43,19 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackend : public QObject
signals:
void progress(int);
void scanProgress(const QString&,int);
public:
static CoreBackend* self();
virtual QString about() const = 0;
virtual QList<Device*> scanDevices() = 0;
virtual Device* scanDevice(const QString& device_node) = 0;
virtual CoreBackendDevice* openDevice(const QString& device_node) = 0;
virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node) = 0;
virtual bool closeDevice(CoreBackendDevice* core_device) = 0;
virtual void emitProgress(int i);
virtual void emitScanProgress(const QString& device_node, int i);
protected:
static void setPartitionTableForDevice(Device& d, PartitionTable* p);

View File

@ -24,10 +24,8 @@
#include "core/operationstack.h"
#include "core/device.h"
#include <solid/device.h>
#include <solid/deviceinterface.h>
#include <solid/block.h>
#include <solid/storagedrive.h>
#include <klocale.h>
#include <kdebug.h>
/** Constructs a DeviceScanner
@param ostack the OperationStack where the devices will be created
@ -36,6 +34,7 @@ DeviceScanner::DeviceScanner(QObject* parent, OperationStack& ostack) :
QThread(parent),
m_OperationStack(ostack)
{
connect(CoreBackend::self(), SIGNAL(scanProgress(QString,int)), SIGNAL(progress(QString,int)));
}
void DeviceScanner::clear()
@ -44,47 +43,16 @@ void DeviceScanner::clear()
operationStack().clearDevices();
}
static quint32 countDevices(const QList<Solid::Device>& driveList)
{
quint32 rval = 0;
foreach(const Solid::Device& solidDevice, driveList)
{
const Solid::StorageDrive* solidDrive = solidDevice.as<Solid::StorageDrive>();
if (solidDrive->driveType() == Solid::StorageDrive::HardDisk)
rval++;
}
return rval;
}
void DeviceScanner::run()
{
emit progress(QString(), 0);
clear();
const QList<Solid::Device> driveList = Solid::Device::listFromType(Solid::DeviceInterface::StorageDrive, QString());
const quint32 totalDevices = countDevices(driveList);
quint32 count = 0;
QList<Device*> deviceList = CoreBackend::self()->scanDevices();
foreach(const Solid::Device& solidDevice, driveList)
{
const Solid::StorageDrive* solidDrive = solidDevice.as<Solid::StorageDrive>();
if (solidDrive->driveType() != Solid::StorageDrive::HardDisk)
continue;
const Solid::Block* solidBlock = solidDevice.as<Solid::Block>();
Device* d = CoreBackend::self()->scanDevice(solidBlock->device());
if (d != NULL)
{
d->setIconName(solidDevice.icon());
operationStack().addDevice(d);
}
emit progress(solidBlock->device(), (++count) * 100 / totalDevices);
}
foreach(Device* d, deviceList)
operationStack().addDevice(d);
operationStack().sortDevices();
}

View File

@ -50,6 +50,13 @@ QString DummyBackend::about() const
return QString("DummyBackend");
}
QList<Device*> DummyBackend::scanDevices()
{
QList<Device*> result;
result.append(scanDevice("/dev/sda"));
return result;
}
Device* DummyBackend::scanDevice(const QString& device_node)
{
Device* d = new Device("Dummy Device", QString("/tmp" + device_node), 255, 0xffff, 63, 512);

View File

@ -46,6 +46,7 @@ class DummyBackend : public CoreBackend
public:
virtual QString about() const;
virtual QList<Device*> scanDevices();
virtual CoreBackendDevice* openDevice(const QString& device_node);
virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node);
virtual bool closeDevice(CoreBackendDevice* core_device);

View File

@ -41,6 +41,11 @@
#include <kdiskfreespaceinfo.h>
#include <kpluginfactory.h>
#include <solid/device.h>
#include <solid/deviceinterface.h>
#include <solid/block.h>
#include <solid/storagedrive.h>
#include <parted/parted.h>
#include <unistd.h>
#include <blkid/blkid.h>
@ -375,6 +380,51 @@ Device* LibPartedBackend::scanDevice(const QString& device_node)
return d;
}
static quint32 countDevices(const QList<Solid::Device>& driveList)
{
quint32 rval = 0;
foreach(const Solid::Device& solidDevice, driveList)
{
const Solid::StorageDrive* solidDrive = solidDevice.as<Solid::StorageDrive>();
if (solidDrive->driveType() == Solid::StorageDrive::HardDisk)
rval++;
}
return rval;
}
QList<Device*> LibPartedBackend::scanDevices()
{
QList<Device*> result;
const QList<Solid::Device> driveList = Solid::Device::listFromType(Solid::DeviceInterface::StorageDrive, QString());
const quint32 totalDevices = countDevices(driveList);
quint32 count = 0;
foreach(const Solid::Device& solidDevice, driveList)
{
const Solid::StorageDrive* solidDrive = solidDevice.as<Solid::StorageDrive>();
if (solidDrive->driveType() != Solid::StorageDrive::HardDisk)
continue;
const Solid::Block* solidBlock = solidDevice.as<Solid::Block>();
Device* d = CoreBackend::self()->scanDevice(solidBlock->device());
if (d != NULL)
{
d->setIconName(solidDevice.icon());
result.append(d);
}
emitScanProgress(solidBlock->device(), (++count) * 100 / totalDevices);
}
return result;
}
CoreBackendDevice* LibPartedBackend::openDevice(const QString& device_node)
{
LibPartedDevice* device = new LibPartedDevice(device_node);

View File

@ -36,6 +36,7 @@
class LibPartedDevice;
class LibPartedPartitionTable;
class LibPartedPartition;
class OperationStack;
class Device;
class KPluginFactory;
@ -64,6 +65,7 @@ class LibPartedBackend : public CoreBackend
virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node);
virtual bool closeDevice(CoreBackendDevice* core_device);
virtual Device* scanDevice(const QString& device_node);
virtual QList<Device*> scanDevices();
private:
static FileSystem::Type detectFileSystem(PedDevice* pedDevice, PedPartition* pedPartition);