Basic communication between daemon and wizard
This commit is contained in:
parent
1f536de7e9
commit
1bdd3eb97b
4 changed files with 45 additions and 24 deletions
|
@ -65,18 +65,19 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
|
||||||
announcers.insert(new AvahiAnnouncer());
|
announcers.insert(new AvahiAnnouncer());
|
||||||
announcers.insert(new FakeAnnouncer());
|
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
|
//TODO: Read paired devices from config
|
||||||
//pairedDevices.push_back(new Device("MyAndroid","MyAndroid"));
|
//pairedDevices.push_back(new Device("MyAndroid","MyAndroid"));
|
||||||
|
|
||||||
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
|
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()
|
QString Daemon::listVisibleDevices()
|
||||||
|
@ -88,9 +89,9 @@ QString Daemon::listVisibleDevices()
|
||||||
ret << std::setw(20) << "Name";
|
ret << std::setw(20) << "Name";
|
||||||
ret << std::endl;
|
ret << std::endl;
|
||||||
|
|
||||||
Q_FOREACH (Device* d, visibleDevices) {
|
Q_FOREACH (DeviceLink* d, visibleDevices) {
|
||||||
ret << std::setw(20) << d->id().toStdString();
|
ret << std::setw(20) << d->device()->id().toStdString();
|
||||||
ret << std::setw(20) << d->name().toStdString();
|
ret << std::setw(20) << d->device()->name().toStdString();
|
||||||
ret << std::endl;
|
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)
|
bool Daemon::pairDevice(QString id)
|
||||||
{
|
{
|
||||||
//TODO
|
if (!visibleDevices.contains(id)) return false;
|
||||||
linkedDevices.append(new EchoDeviceLink(new Device(id,"fake-to-the-max")));
|
|
||||||
|
linkTo(visibleDevices[id]);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Daemon::listLinkedDevices()
|
QString Daemon::listLinkedDevices()
|
||||||
|
@ -132,7 +145,7 @@ void Daemon::deviceConnection(DeviceLink* dl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visibleDevices.append(dl->device());
|
visibleDevices[dl->device()->id()] = dl;
|
||||||
|
|
||||||
if (paired) {
|
if (paired) {
|
||||||
qDebug() << "Known device connected" + dl->device()->name();
|
qDebug() << "Known device connected" + dl->device()->name();
|
||||||
|
@ -140,8 +153,10 @@ void Daemon::deviceConnection(DeviceLink* dl)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "Unknown device connected" + dl->device()->name();
|
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:
|
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 QString listVisibleDevices();
|
||||||
|
|
||||||
Q_SCRIPTABLE bool pairDevice(QString id);
|
Q_SCRIPTABLE bool pairDevice(QString id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Q_SCRIPTABLE QString listPairedDevices(QString id);
|
Q_SCRIPTABLE QString listPairedDevices(QString id);
|
||||||
|
|
||||||
|
@ -72,15 +77,15 @@ public Q_SLOTS:
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|
||||||
Q_SCRIPTABLE void deviceAdded(QString id, QString name);
|
Q_SCRIPTABLE void deviceDiscovered(QString id, QString name);
|
||||||
Q_SCRIPTABLE void deviceRemoved(QString id);
|
//Q_SCRIPTABLE void deviceLost(QString id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void linkTo(DeviceLink* dl);
|
void linkTo(DeviceLink* dl);
|
||||||
|
|
||||||
//Non paired visible devices
|
//(Non paired?) visible devices
|
||||||
QList<Device*> visibleDevices;
|
QMap<QString, DeviceLink*> visibleDevices;
|
||||||
|
|
||||||
//All paired devices (should be stored and read from disk)
|
//All paired devices (should be stored and read from disk)
|
||||||
QVector<Device*> pairedDevices;
|
QVector<Device*> pairedDevices;
|
||||||
|
|
|
@ -38,8 +38,8 @@ AddDeviceWizard::AddDeviceWizard(QWidget* parent)
|
||||||
|
|
||||||
connect(this,SIGNAL(currentIdChanged(int)),this,SLOT(pageChanged(int)));
|
connect(this,SIGNAL(currentIdChanged(int)),this,SLOT(pageChanged(int)));
|
||||||
|
|
||||||
connect(dbusInterface, SIGNAL(deviceAdded(QString, QString)), this, SLOT(deviceDiscovered(QString,QString)));
|
connect(dbusInterface, SIGNAL(deviceDiscovered(QString, QString)), this, SLOT(deviceDiscovered(QString,QString)));
|
||||||
connect(dbusInterface, SIGNAL(deviceRemoved(QString)), this, SLOT(deviceLost(QString)));
|
//connect(dbusInterface, SIGNAL(deviceLost(QString)), this, SLOT(deviceLost(QString)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ void AddDeviceWizard::pageChanged(int id)
|
||||||
qDebug() << id;
|
qDebug() << id;
|
||||||
//QWizardPage* p = page(id);
|
//QWizardPage* p = page(id);
|
||||||
if (id == 1) {
|
if (id == 1) {
|
||||||
|
dbusInterface->startDiscovery(10);
|
||||||
//Show "scanning"
|
//Show "scanning"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,12 +60,12 @@ void AddDeviceWizard::deviceDiscovered(QString id, QString name)
|
||||||
|
|
||||||
discoveredDevicesList->appendRow(item);
|
discoveredDevicesList->appendRow(item);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void AddDeviceWizard::deviceLost(QString id)
|
void AddDeviceWizard::deviceLost(QString id)
|
||||||
{
|
{
|
||||||
//discoveredDevicesList->removeRow();
|
//discoveredDevicesList->removeRow();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void AddDeviceWizard::discoveryFinished(bool success)
|
void AddDeviceWizard::discoveryFinished(bool success)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ private Q_SLOTS:
|
||||||
void pageChanged(int id);
|
void pageChanged(int id);
|
||||||
|
|
||||||
void deviceDiscovered(QString id, QString name);
|
void deviceDiscovered(QString id, QString name);
|
||||||
void deviceLost(QString id);
|
//void deviceLost(QString id);
|
||||||
void discoveryFinished(bool success);
|
void discoveryFinished(bool success);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue