From 669edf8ea5cf3709544dbfc6a45612d0a47b8d89 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Tue, 2 Jul 2013 02:46:41 +0200 Subject: [PATCH] It even works now --- daemon/announcers/avahiannouncer.cpp | 10 +++++++--- daemon/daemon.cpp | 29 +++++++++++++++++++--------- daemon/daemon.h | 11 +++++++---- daemon/devicelinks/udpdevicelink.cpp | 2 ++ daemon/networkpackage.cpp | 4 +++- kcm/devicesmodel.cpp | 1 + kcm/kcm.cpp | 6 +++++- kcm/wizard.cpp | 8 +++++--- 8 files changed, 50 insertions(+), 21 deletions(-) diff --git a/daemon/announcers/avahiannouncer.cpp b/daemon/announcers/avahiannouncer.cpp index a78e3b0cb..6c94d6eff 100644 --- a/daemon/announcers/avahiannouncer.cpp +++ b/daemon/announcers/avahiannouncer.cpp @@ -35,14 +35,14 @@ AvahiAnnouncer::AvahiAnnouncer() connect(mUdpSocket, SIGNAL(readyRead()), this, SLOT(readPendingNotifications())); - qDebug() << "listening to udp messages"; + qDebug() << "Listening to udp messages"; } void AvahiAnnouncer::readPendingNotifications() { - qDebug() << "readPendingNotifications"; + qDebug() << "AvahiAnnouncer readPendingNotifications"; while (mUdpSocket->hasPendingDatagrams()) { @@ -53,17 +53,21 @@ void AvahiAnnouncer::readPendingNotifications() mUdpSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort); //log.write(datagram); - qDebug() << ("AvahiAnnouncer incomming udp datagram: " + datagram); + qDebug() << "AvahiAnnouncer incomming udp datagram: " << datagram; NetworkPackage np = NetworkPackage::fromString(datagram); QString id = np.deviceId(); QString name = np.body(); + qDebug() << "AvahiAnnouncer creating link to device" << name; + Device* device = new Device(id, name); DeviceLink* dl = new UdpDeviceLink(device, sender, 10600); links.append(dl); + qDebug() << "Emitting link" << name; + emit deviceConnection(dl); } diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp index d98841528..91485250e 100644 --- a/daemon/daemon.cpp +++ b/daemon/daemon.cpp @@ -28,9 +28,10 @@ #include #include - #include -#include + +#include +#include #include #include @@ -53,6 +54,7 @@ void Daemon::linkTo(DeviceLink* dl) Daemon::Daemon(QObject *parent, const QList&) : KDEDModule(parent) + , config(KSharedConfig::openConfig("kdeconnectrc")) { qDebug() << "GO GO GO!"; @@ -69,8 +71,16 @@ Daemon::Daemon(QObject *parent, const QList&) //TODO: Add package emitters - //TODO: Read paired devices from config - //pairedDevices.push_back(new Device("MyAndroid","MyAndroid")); + //Read remebered paired devices + const KConfigGroup& known = config->group("devices").group("paired"); + const QStringList& list = known.groupList(); + const QString defaultName("unnamed"); + Q_FOREACH(QString id, list) { + const KConfigGroup& data = known.group(id); + const QString& name = data.readEntry("name",defaultName); + pairedDevices.push_back(new Device(id,name)); + } + QDBusConnection::sessionBus().registerService("org.kde.kdeconnect"); @@ -116,6 +126,8 @@ bool Daemon::pairDevice(QString id) { if (!visibleDevices.contains(id)) return false; + config->group("devices").group("paired").group(id).writeEntry("name",visibleDevices[id]->device()->name()); + linkTo(visibleDevices[id]); return true; @@ -139,6 +151,8 @@ QString Daemon::listLinkedDevices() void Daemon::deviceConnection(DeviceLink* dl) { + qDebug() << "deviceConnection"; + QString id = dl->device()->id(); bool paired = false; Q_FOREACH (Device* d, pairedDevices) { @@ -151,15 +165,12 @@ void Daemon::deviceConnection(DeviceLink* dl) visibleDevices[dl->device()->id()] = dl; if (paired) { - qDebug() << "Known device connected" + dl->device()->name(); + qDebug() << "Known device connected" << dl->device()->name(); linkTo(dl); } else { - qDebug() << "Unknown device connected" + dl->device()->name(); - + qDebug() << "Unknown device connected" << dl->device()->name(); emit deviceDiscovered(dl->device()->id(), dl->device()->name()); - - //linkTo(dl); } } diff --git a/daemon/daemon.h b/daemon/daemon.h index 47ccfceed..37c4dc0ae 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -26,8 +26,8 @@ #include #include -#include -#include +#include +#include #include "networkpackage.h" #include @@ -36,6 +36,8 @@ #include +#include + #include "device.h" #include "packagereceivers/packagereceiver.h" #include "devicelinks/devicelink.h" @@ -65,8 +67,6 @@ public Q_SLOTS: Q_SCRIPTABLE bool pairDevice(QString id); - - /* Q_SCRIPTABLE QString listPairedDevices(QString id); @@ -82,8 +82,11 @@ Q_SIGNALS: private: + void linkTo(DeviceLink* dl); + KSharedConfigPtr config; + //(Non paired?) visible devices QMap visibleDevices; diff --git a/daemon/devicelinks/udpdevicelink.cpp b/daemon/devicelinks/udpdevicelink.cpp index 68931aa67..c32caab85 100644 --- a/daemon/devicelinks/udpdevicelink.cpp +++ b/daemon/devicelinks/udpdevicelink.cpp @@ -37,6 +37,8 @@ UdpDeviceLink::UdpDeviceLink(Device* d, QHostAddress ip, quint16 port) void UdpDeviceLink::readPendingNotifications() { + qDebug() << "UdpDeviceLink readPendingNotifications"; + while (mUdpSocket->hasPendingDatagrams()) { QByteArray datagram; diff --git a/daemon/networkpackage.cpp b/daemon/networkpackage.cpp index 574f850c7..f3e964959 100644 --- a/daemon/networkpackage.cpp +++ b/daemon/networkpackage.cpp @@ -36,7 +36,7 @@ NetworkPackage NetworkPackage::fromString(QByteArray s) long id; ss >> id; - qDebug() << "Receiving package with id: " << id; + //qDebug() << "Decoding package with id:" << id; NetworkPackage pp(id); @@ -59,6 +59,8 @@ NetworkPackage NetworkPackage::fromString(QByteArray s) ss >> pp.mIsCancel; + qDebug() << "Decoded package with id:" << id; + return pp; } diff --git a/kcm/devicesmodel.cpp b/kcm/devicesmodel.cpp index 9f47c12ef..c18650192 100644 --- a/kcm/devicesmodel.cpp +++ b/kcm/devicesmodel.cpp @@ -69,6 +69,7 @@ void DevicesModel::addDevice(QString id, QString name, DevicesModel::DeviceStatu setData(index(rown,0),QVariant(id),IdModelRole); setData(index(rown,0),QVariant(name),NameModelRole); setData(index(rown,0),QVariant(PairedConnected),StatusModelRole); + qDebug() << "Add device" << name; emit dataChanged(index(rown,0),index(rown,0)); } diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index c3cdf74e5..8f7c7ceea 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -82,7 +82,11 @@ void KdeConnectKcm::removeButtonClicked() void KdeConnectKcm::deviceAdded(QString id,QString name) { qDebug() << "Succesfully paired: " + id; - pairedDevicesList.addDevice(id,name,DevicesModel::PairedConnected); + + //TODO: Do not use kconf directly but talk to daemon + dbusInterface.pairDevice(id); + + pairedDevicesList.loadPaired(); } void KdeConnectKcm::currentChanged(const QModelIndex& current, const QModelIndex& previous) diff --git a/kcm/wizard.cpp b/kcm/wizard.cpp index 90012c914..4707d305b 100644 --- a/kcm/wizard.cpp +++ b/kcm/wizard.cpp @@ -54,10 +54,11 @@ AddDeviceWizard::AddDeviceWizard(QWidget* parent) void AddDeviceWizard::wizardFinished() { - if (selectedIndex.row() > 0 && selectedIndex.row() < discoveredDevicesList->rowCount()) { + + if (selectedIndex.isValid() && selectedIndex.row() >= 0 && selectedIndex.row() < discoveredDevicesList->rowCount()) { QString name = discoveredDevicesList->data(selectedIndex,DevicesModel::NameModelRole).toString(); QString id = discoveredDevicesList->data(selectedIndex,DevicesModel::IdModelRole).toString(); - emit deviceAdded(name,id); + emit deviceAdded(id,name); } } @@ -72,6 +73,7 @@ void AddDeviceWizard::pageChanged(int id) void AddDeviceWizard::deviceDiscovered(QString id, QString name) { + qDebug() << "Discovered"<addDevice(id,name,DevicesModel::Visible); } /* @@ -100,7 +102,7 @@ void AddDeviceWizard::show() void AddDeviceWizard::deviceSelected(const QModelIndex& index) { - qDebug() << "Selected: " + index.row(); + qDebug() << "Selected:" << index.row(); selectedIndex = index; next(); }