Commit 1bdd3eb9 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Basic communication between daemon and wizard

parent 1f536de7
......@@ -65,17 +65,18 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
announcers.insert(new AvahiAnnouncer());
announcers.insert(new FakeAnnouncer());
//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*)));
a->setDiscoverable(true);
}
//TODO: Read paired devices from config
//pairedDevices.push_back(new Device("MyAndroid","MyAndroid"));
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
}
......@@ -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);
}
}
......
......@@ -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<Device*> visibleDevices;
//(Non paired?) visible devices
QMap<QString, DeviceLink*> visibleDevices;
//All paired devices (should be stored and read from disk)
QVector<Device*> pairedDevices;
......
......@@ -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)
{
......
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment