1 #include <KApplication>
3 #include <QDBusConnectionInterface>
8 #include "FMDbusConn.h"
9 #include "FingerManagerDevicesModel.h"
11 FMDbusConn::FMDbusConn() : managerIface(0) {
12 if (!QDBusConnection::systemBus().isConnected()) {
13 qDebug("Cannot connect to D-Bus system bus.");
16 deviceResultsWatcher
= new QFutureWatcher
<FingerManagerDevicesModel
*>(this);
17 connect(deviceResultsWatcher
, SIGNAL(resultReadyAt(int)), SLOT(emitDiscovered(int)));
20 FMDbusConn::~FMDbusConn() {
25 * Start D-Bus daemon (requires some retries)
27 QDBusInterface
* FMDbusConn::getManagerIface(int retr
= INTERFACE_ACQUIRE_RETRY
) {
29 qDebug("Manager interface doesn't found!");
33 if (managerIface
&& managerIface
->isValid()) {
34 qDebug("Returning existing manager interface");
38 qDebug("getManagerConnection try: %d", retr
);
40 // Connect to Fprint manager on system bus
41 QDBusConnection bus
= QDBusConnection::systemBus();
42 QDBusInterface
*iface
= new QDBusInterface("net.reactivated.Fprint",
43 "/net/reactivated/Fprint/Manager",
44 "net.reactivated.Fprint.Manager",
47 // Wait while D-Bus Fprintd daemon starts
48 if (iface
->isValid()) {
51 managerIface
= getManagerIface(--retr
);
57 * QFutureWatcher signal handler
59 void FMDbusConn::emitDiscovered(int idx
) {
60 emit
devicesDiscovered(idx
);
64 * Returns FingerManagerDevicesModel created by getDevices
66 FingerManagerDevicesModel
* FMDbusConn::getModel(int idx
) {
67 return(deviceResultsWatcher
->resultAt(idx
));
71 * Get device communication interface
73 QDBusInterface
* getDeviceInterface(QString device
) {
74 QDBusInterface
* i
= new QDBusInterface("net.reactivated.Fprint",
76 "net.reactivated.Fprint.Device",
77 QDBusConnection::systemBus());
82 * Returns name associated with device
84 QString
getDeviceName(QString device
) {
86 QDBusInterface
*i
= getDeviceInterface(device
);
88 name
= i
->property("name").toString();
97 * Real function which do all the work
99 FingerManagerDevicesModel
* getDevicesReal(QDBusInterface
*iface
) {
100 FingerManagerDevicesModel
*model
= new FingerManagerDevicesModel();
102 if (iface
&& iface
->isValid()) {
104 qDebug("D-Bus interface acquired! :-)");
105 QDBusReply
<QList
<QDBusObjectPath
> > devices
= iface
->call("GetDevices");
106 if (devices
.isValid()) {
107 foreach (QDBusObjectPath device
, devices
.value()) {
108 model
->addDevice(device
.path(), getDeviceName(device
.path()));
112 QDBusReply
<QDBusObjectPath
> defaultDevice
= iface
->call("GetDefaultDevice");
113 if (defaultDevice
.isValid()) {
114 model
->setDefault(defaultDevice
.value().path());
117 qDebug("D-Bus interface cannot be acquired! :-(");
126 void FMDbusConn::getDevices() {
127 QDBusInterface
*iface
= getManagerIface();
128 deviceResultsWatcher
->setFuture(QtConcurrent::run(getDevicesReal
, iface
));
131 void FMDbusConn::getEnrolledFingers(QDBusObjectPath device
) {