From a21f0533c5e1fbeacb3d6bd79ebfa4af2e1f7ea5 Mon Sep 17 00:00:00 2001 From: Jaroslav Barton Date: Wed, 18 Mar 2009 21:23:22 +0100 Subject: [PATCH] getDevices creates data model for combo box (created from device path and device name) --- src/FMDbusConn.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++---------- src/FMDbusConn.h | 15 +++++++-- 2 files changed, 92 insertions(+), 20 deletions(-) diff --git a/src/FMDbusConn.cpp b/src/FMDbusConn.cpp index f8a2e83..be3dd6c 100644 --- a/src/FMDbusConn.cpp +++ b/src/FMDbusConn.cpp @@ -4,28 +4,46 @@ #include #include #include + #include "FMDbusConn.h" +#include "FingerManagerDevicesModel.h" + +FMDbusConn::FMDbusConn() : managerIface(0) { + if (!QDBusConnection::systemBus().isConnected()) { + qDebug("Cannot connect to D-Bus system bus."); + return; + } + deviceResultsWatcher = new QFutureWatcher(this); + connect(deviceResultsWatcher, SIGNAL(resultReadyAt(int)), SLOT(emitDiscovered(int))); +}; + +FMDbusConn::~FMDbusConn() { + delete managerIface; +} +/** + * Start D-Bus daemon (requires some retries) + */ QDBusInterface* FMDbusConn::getManagerIface(int retr = INTERFACE_ACQUIRE_RETRY) { if (!retr) { qDebug("Manager interface doesn't found!"); return(0); } - + if (managerIface && managerIface->isValid()) { qDebug("Returning existing manager interface"); return managerIface; } qDebug("getManagerConnection try: %d", retr); - + // Connect to Fprint manager on system bus QDBusConnection bus = QDBusConnection::systemBus(); QDBusInterface *iface = new QDBusInterface("net.reactivated.Fprint", "/net/reactivated/Fprint/Manager", "net.reactivated.Fprint.Manager", bus, this); - + // Wait while D-Bus Fprintd daemon starts if (iface->isValid()) { managerIface = iface; @@ -35,38 +53,81 @@ QDBusInterface* FMDbusConn::getManagerIface(int retr = INTERFACE_ACQUIRE_RETRY) return(managerIface); } -FMDbusConn::FMDbusConn() : managerIface(0) { - if (!QDBusConnection::systemBus().isConnected()) { - qDebug("Cannot connect to D-Bus system bus."); - return; +/** + * QFutureWatcher signal handler + */ +void FMDbusConn::emitDiscovered(int idx) { + emit devicesDiscovered(idx); +} + +/** + * Returns FingerManagerDevicesModel created by getDevices + */ +FingerManagerDevicesModel* FMDbusConn::getModel(int idx) { + return(deviceResultsWatcher->resultAt(idx)); +} + +/** + * Get device communication interface + */ +QDBusInterface* getDeviceInterface(QString device) { + QDBusInterface* i = new QDBusInterface("net.reactivated.Fprint", + device, + "net.reactivated.Fprint.Device", + QDBusConnection::systemBus()); + return(i); +} + +/** + * Returns name associated with device + */ +QString getDeviceName(QString device) { + QString name; + QDBusInterface *i = getDeviceInterface(device); + if (i->isValid()) { + name = i->property("name").toString(); + } else { + name = device; } - -}; + delete(i); + return(name); +} -void FMDbusConn::getDevices() { - QDBusInterface *iface = getManagerIface(); +/** + * Real function which do all the work + */ +FingerManagerDevicesModel* getDevicesReal(QDBusInterface *iface) { + FingerManagerDevicesModel *model = new FingerManagerDevicesModel(); if (iface && iface->isValid()) { + qDebug("D-Bus interface acquired! :-)"); QDBusReply > devices = iface->call("GetDevices"); if (devices.isValid()) { foreach (QDBusObjectPath device, devices.value()) { - qDebug() << "Found device: " << device.path(); + model->addDevice(device.path(), getDeviceName(device.path())); } } QDBusReply defaultDevice = iface->call("GetDefaultDevice"); if (defaultDevice.isValid()) { - qDebug() << "Default device: " << defaultDevice.value().path(); + model->setDefault(defaultDevice.value().path()); } - - emit devicesDiscovered(); } else { qDebug("D-Bus interface cannot be acquired! :-("); - return; } + + return(model); } -FMDbusConn::~FMDbusConn() { - delete managerIface; +/** + * Starts thread + */ +void FMDbusConn::getDevices() { + QDBusInterface *iface = getManagerIface(); + deviceResultsWatcher->setFuture(QtConcurrent::run(getDevicesReal, iface)); +} + +void FMDbusConn::getEnrolledFingers(QDBusObjectPath device) { + Q_UNUSED(device); } diff --git a/src/FMDbusConn.h b/src/FMDbusConn.h index 2710f18..82f33e4 100644 --- a/src/FMDbusConn.h +++ b/src/FMDbusConn.h @@ -4,23 +4,34 @@ #include #include #include +#include +#include + +#include "FingerManagerDevicesModel.h" #define INTERFACE_ACQUIRE_RETRY 3 +void getDevicesReal(); + class FMDbusConn : public QObject { Q_OBJECT signals: - void devicesDiscovered(); - + void devicesDiscovered(int idx); + void enrolledFingersDiscovered(); + private slots: + void emitDiscovered(int idx); private: QDBusInterface *managerIface; QDBusInterface* getManagerIface(int retr); + QFutureWatcher *deviceResultsWatcher; public: FMDbusConn(); ~FMDbusConn(); void getDevices(); + void getEnrolledFingers(QDBusObjectPath device); + FingerManagerDevicesModel* getModel(int idx); }; #endif /*FMDBUSCONN_H_*/ -- 2.11.4.GIT