From 1bdd3eb97b2170830b62cfebee6972fbccc0a834 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Thu, 27 Jun 2013 02:26:06 +0200 Subject: [PATCH] Basic communication between daemon and wizard --- daemon/daemon.cpp | 45 ++++++++++++++++++++++++++++++--------------- daemon/daemon.h | 13 +++++++++---- kcm/wizard.cpp | 9 +++++---- kcm/wizard.h | 2 +- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp index f443f6e1b..4139344bf 100644 --- a/daemon/daemon.cpp +++ b/daemon/daemon.cpp @@ -65,18 +65,19 @@ Daemon::Daemon(QObject *parent, const QList&) announcers.insert(new AvahiAnnouncer()); announcers.insert(new FakeAnnouncer()); - //Listen to incomming connections - Q_FOREACH (Announcer* a, announcers) { - QObject::connect(a,SIGNAL(deviceConnection(DeviceLink*)), - this,SLOT(deviceConnection(DeviceLink*))); - a->setDiscoverable(true); - } - //TODO: Read paired devices from config //pairedDevices.push_back(new Device("MyAndroid","MyAndroid")); QDBusConnection::sessionBus().registerService("org.kde.kdeconnect"); + + //Listen to incomming connections + Q_FOREACH (Announcer* a, announcers) { + QObject::connect(a,SIGNAL(deviceConnection(DeviceLink*)), + this,SLOT(deviceConnection(DeviceLink*))); + } + + } QString Daemon::listVisibleDevices() @@ -88,9 +89,9 @@ QString Daemon::listVisibleDevices() ret << std::setw(20) << "Name"; ret << std::endl; - Q_FOREACH (Device* d, visibleDevices) { - ret << std::setw(20) << d->id().toStdString(); - ret << std::setw(20) << d->name().toStdString(); + Q_FOREACH (DeviceLink* d, visibleDevices) { + ret << std::setw(20) << d->device()->id().toStdString(); + ret << std::setw(20) << d->device()->name().toStdString(); ret << std::endl; } @@ -98,11 +99,23 @@ QString Daemon::listVisibleDevices() } +void Daemon::startDiscovery(int timeOut) +{ + + //Listen to incomming connections + Q_FOREACH (Announcer* a, announcers) { + a->setDiscoverable(true); + } + +} + bool Daemon::pairDevice(QString id) { - //TODO - linkedDevices.append(new EchoDeviceLink(new Device(id,"fake-to-the-max"))); + if (!visibleDevices.contains(id)) return false; + + linkTo(visibleDevices[id]); return true; + } QString Daemon::listLinkedDevices() @@ -132,7 +145,7 @@ void Daemon::deviceConnection(DeviceLink* dl) } } - visibleDevices.append(dl->device()); + visibleDevices[dl->device()->id()] = dl; if (paired) { qDebug() << "Known device connected" + dl->device()->name(); @@ -140,8 +153,10 @@ void Daemon::deviceConnection(DeviceLink* dl) } else { qDebug() << "Unknown device connected" + dl->device()->name(); - //TODO: Not connect immediately - linkTo(dl); + + emit deviceDiscovered(dl->device()->id(), dl->device()->name()); + + //linkTo(dl); } } diff --git a/daemon/daemon.h b/daemon/daemon.h index 9ca8bdd19..47ccfceed 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -58,10 +58,15 @@ private Q_SLOTS: public Q_SLOTS: + //After calling this, signal deviceDiscovered will be triggered for each device + Q_SCRIPTABLE void startDiscovery(int timeOut); + Q_SCRIPTABLE QString listVisibleDevices(); Q_SCRIPTABLE bool pairDevice(QString id); + + /* Q_SCRIPTABLE QString listPairedDevices(QString id); @@ -72,15 +77,15 @@ public Q_SLOTS: Q_SIGNALS: - Q_SCRIPTABLE void deviceAdded(QString id, QString name); - Q_SCRIPTABLE void deviceRemoved(QString id); + Q_SCRIPTABLE void deviceDiscovered(QString id, QString name); + //Q_SCRIPTABLE void deviceLost(QString id); private: void linkTo(DeviceLink* dl); - //Non paired visible devices - QList visibleDevices; + //(Non paired?) visible devices + QMap visibleDevices; //All paired devices (should be stored and read from disk) QVector pairedDevices; diff --git a/kcm/wizard.cpp b/kcm/wizard.cpp index f4c530c64..639fd107d 100644 --- a/kcm/wizard.cpp +++ b/kcm/wizard.cpp @@ -38,8 +38,8 @@ AddDeviceWizard::AddDeviceWizard(QWidget* parent) connect(this,SIGNAL(currentIdChanged(int)),this,SLOT(pageChanged(int))); - connect(dbusInterface, SIGNAL(deviceAdded(QString, QString)), this, SLOT(deviceDiscovered(QString,QString))); - connect(dbusInterface, SIGNAL(deviceRemoved(QString)), this, SLOT(deviceLost(QString))); + connect(dbusInterface, SIGNAL(deviceDiscovered(QString, QString)), this, SLOT(deviceDiscovered(QString,QString))); + //connect(dbusInterface, SIGNAL(deviceLost(QString)), this, SLOT(deviceLost(QString))); } @@ -48,6 +48,7 @@ void AddDeviceWizard::pageChanged(int id) qDebug() << id; //QWizardPage* p = page(id); if (id == 1) { + dbusInterface->startDiscovery(10); //Show "scanning" } } @@ -59,12 +60,12 @@ void AddDeviceWizard::deviceDiscovered(QString id, QString name) discoveredDevicesList->appendRow(item); } - +/* void AddDeviceWizard::deviceLost(QString id) { //discoveredDevicesList->removeRow(); } - +*/ void AddDeviceWizard::discoveryFinished(bool success) { diff --git a/kcm/wizard.h b/kcm/wizard.h index 741a051e0..40ce755a0 100644 --- a/kcm/wizard.h +++ b/kcm/wizard.h @@ -44,7 +44,7 @@ private Q_SLOTS: void pageChanged(int id); void deviceDiscovered(QString id, QString name); - void deviceLost(QString id); + //void deviceLost(QString id); void discoveryFinished(bool success); private: