[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:26:40 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=7ef29fd

The following commit has been merged in the master branch:
commit 7ef29fdd698b33b2082f0c325b2e90969ca551ac
Author: Albert Vaca <albertvaka at gmail.com>
Date:   Tue Jul 23 16:11:54 2013 +0200

    Implemented bi-directional communication using tcp.
---
 daemon/CMakeLists.txt                              |   4 +-
 daemon/announcers/announcer.h                      |  19 ++--
 daemon/announcers/avahiannouncer.cpp               |  41 +++++---
 daemon/announcers/avahiannouncer.h                 |   7 +-
 daemon/announcers/avahitcpannouncer.cpp            | 114 +++++++++++++++++++++
 .../{avahiannouncer.h => avahitcpannouncer.h}      |  26 ++---
 daemon/announcers/fakeannouncer.cpp                |  12 ++-
 daemon/announcers/fakeannouncer.h                  |  16 +--
 daemon/daemon.cpp                                  |  30 ++++--
 daemon/daemon.h                                    |   2 +-
 daemon/device.cpp                                  |  22 +++-
 daemon/device.h                                    |   1 +
 daemon/devicelinks/echodevicelink.cpp              |   2 +-
 daemon/devicelinks/echodevicelink.h                |   4 +-
 .../{echodevicelink.cpp => tcpdevicelink.cpp}      |  23 ++++-
 .../{udpdevicelink.h => tcpdevicelink.h}           |  26 +++--
 daemon/devicelinks/udpdevicelink.cpp               |  13 ++-
 daemon/devicelinks/udpdevicelink.h                 |  11 +-
 daemon/networkpackage.cpp                          |  20 +++-
 daemon/networkpackage.h                            |   2 +
 .../notificationpackagereceiver.cpp                |   2 -
 .../packagereceivers/pausemusicpackagereceiver.cpp |   2 +-
 daemon/packagereceivers/pingpackagereceiver.cpp    |   5 +-
 kcmodule.sh                                        |   7 --
 24 files changed, 299 insertions(+), 112 deletions(-)

diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt
index a5fadd1..135a9a4 100644
--- a/daemon/CMakeLists.txt
+++ b/daemon/CMakeLists.txt
@@ -3,10 +3,12 @@ set(kded_kdeconnect_SRCS
     announcers/announcer.cpp
     announcers/fakeannouncer.cpp
     announcers/avahiannouncer.cpp
+    announcers/avahitcpannouncer.cpp
 
+    devicelinks/devicelink.cpp
     devicelinks/echodevicelink.cpp
     devicelinks/udpdevicelink.cpp
-    devicelinks/devicelink.cpp
+    devicelinks/tcpdevicelink.cpp
 
     packagereceivers/packagereceiver.cpp
     packagereceivers/pingpackagereceiver.cpp
diff --git a/daemon/announcers/announcer.h b/daemon/announcers/announcer.h
index f080140..d99fd74 100644
--- a/daemon/announcers/announcer.h
+++ b/daemon/announcers/announcer.h
@@ -34,24 +34,23 @@ class Announcer : public QObject
     Q_OBJECT
 
 public:
+
+    const int PRIORITY_LOW = 0;      //ie: 3g
+    const int PRIORITY_MEDIUM = 50;  //ie: internet
+    const int PRIORITY_HIGH = 100;   //ie: lan
+
     Announcer();
     virtual ~Announcer() { }
 
-    enum Priority {
-        PRIORITY_LOW = 0,      //ie: 3g
-        PRIORITY_MEDIUM = 50,  //ie: internet
-        PRIORITY_HIGH = 100    //ie: lan
-    };
-
     virtual QString name() = 0;
-    virtual Priority priority() = 0;
+    virtual int priority() = 0;
 
     virtual void setDiscoverable(bool b) = 0;
 
 signals:
-    //NOTE: The announcer has to destroy the DeviceLink when it's no longer accessible,
-    //      and every user should listen to the destroy signal to remove its references.
-    void onNewDeviceLink(const QString& id, const QString& name, DeviceLink*);
+    //NOTE: The announcer will to destroy the DeviceLink when it's no longer accessible,
+    //      and every user should listen to the destroyed signal to remove its references.
+    void onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*);
 
 signals:
 
diff --git a/daemon/announcers/avahiannouncer.cpp b/daemon/announcers/avahiannouncer.cpp
index f3d6f4b..4aa1611 100644
--- a/daemon/announcers/avahiannouncer.cpp
+++ b/daemon/announcers/avahiannouncer.cpp
@@ -36,23 +36,23 @@ AvahiAnnouncer::AvahiAnnouncer()
     mUdpSocket = new QUdpSocket();
     mUdpSocket->bind(port);
 
-    connect(mUdpSocket, SIGNAL(readyRead()), this, SLOT(readPendingNotifications()));
+    connect(mUdpSocket, SIGNAL(readyRead()), this, SLOT(newConnection()));
 
     qDebug() << "Listening to udp messages";
 
 }
 
-void AvahiAnnouncer::readPendingNotifications()
+void AvahiAnnouncer::newConnection()
 {
 
-    qDebug() << "AvahiAnnouncer readPendingNotifications";
+    qDebug() << "AvahiAnnouncer newConnection";
     
     while (mUdpSocket->hasPendingDatagrams()) {
 
         QByteArray datagram;
         datagram.resize(mUdpSocket->pendingDatagramSize());
-        NetAddress sender;
-        mUdpSocket->readDatagram(datagram.data(), datagram.size(), &(sender.ip), &(sender.port));
+        NetAddress client;
+        mUdpSocket->readDatagram(datagram.data(), datagram.size(), &(client.ip), &(client.port));
 
         //log.write(datagram);
         qDebug() << "AvahiAnnouncer incomming udp datagram: " << datagram;
@@ -62,18 +62,27 @@ void AvahiAnnouncer::readPendingNotifications()
 
         if (np.type() == "kdeconnect.identity") {
 
-            QString id = np.get<QString>("deviceId");
-            QString name = np.get<QString>("deviceName");
+            const QString& id = np.get<QString>("deviceId");
+            //const QString& name = np.get<QString>("deviceName");
 
-            qDebug() << "AvahiAnnouncer creating link to device" << id;
+            qDebug() << "AvahiAnnouncer creating link to device" << id << "(" << client.ip << "," << client.port << ")";
 
-            DeviceLink* dl = new UdpDeviceLink(id, this, sender.ip, 10600);
+            DeviceLink* dl = new UdpDeviceLink(id, this, client.ip);
+            connect(dl,SIGNAL(destroyed(QObject*)),this,SLOT(deviceLinkDestroyed(QObject*)));
 
-            if (links.contains(sender)) delete links[sender]; //Delete old link if we already know it, probably it is down if this happens.
+            emit onNewDeviceLink(np, dl);
 
-            links[sender] = dl;
+            NetworkPackage::createIdentityPackage(&np);
+            dl->sendPackage(np);
+
+            if (links.contains(id)) {
+                //Delete old link if we already know it, probably it is down if this happens.
+                qDebug() << "Destroying old link";
+                delete links[id];
+            }
+
+            links[id] = dl;
 
-            emit onNewDeviceLink(id, name, dl);
         } else {
             qDebug() << "Not an identification package (wuh?)";
         }
@@ -81,6 +90,12 @@ void AvahiAnnouncer::readPendingNotifications()
 
 }
 
+void AvahiAnnouncer::deviceLinkDestroyed(QObject* deviceLink)
+{
+    const QString& id = ((DeviceLink*)deviceLink)->deviceId();
+    if (links.contains(id)) links.remove(id);
+}
+
 AvahiAnnouncer::~AvahiAnnouncer()
 {
     delete service;
@@ -88,7 +103,7 @@ AvahiAnnouncer::~AvahiAnnouncer()
 
 void AvahiAnnouncer::setDiscoverable(bool b)
 {
-    qDebug() << "Avahi scanning";
+    qDebug() << "Avahi announcing";
     if (b) service->publishAsync();
 }
 
diff --git a/daemon/announcers/avahiannouncer.h b/daemon/announcers/avahiannouncer.h
index eb3c1db..c7bfc44 100644
--- a/daemon/announcers/avahiannouncer.h
+++ b/daemon/announcers/avahiannouncer.h
@@ -40,18 +40,19 @@ public:
     ~AvahiAnnouncer();
 
     QString name() { return "Avahi"; }
-    Priority priority() { return PRIORITY_HIGH; }
+    int priority() { return PRIORITY_HIGH; }
 
     void setDiscoverable(bool b);
 
 private Q_SLOTS:
-    void readPendingNotifications();
+    void newConnection();
+    void deviceLinkDestroyed(QObject*);
 
 private:
     DNSSD::PublicService* service;
     QUdpSocket* mUdpSocket;
 
-    QMap<NetAddress, DeviceLink*> links;
+    QMap<QString, DeviceLink*> links;
 
 };
 
diff --git a/daemon/announcers/avahitcpannouncer.cpp b/daemon/announcers/avahitcpannouncer.cpp
new file mode 100644
index 0000000..4f329c9
--- /dev/null
+++ b/daemon/announcers/avahitcpannouncer.cpp
@@ -0,0 +1,114 @@
+/**
+ * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "avahitcpannouncer.h"
+
+#include "devicelinks/tcpdevicelink.h"
+
+#include <QHostInfo>
+#include <QTcpServer>
+
+AvahiTcpAnnouncer::AvahiTcpAnnouncer()
+{
+    QString serviceType = "_kdeconnect._tcp";
+    quint16 port = 10602;
+
+    //http://api.kde.org/4.x-api/kdelibs-apidocs/dnssd/html/index.html
+
+    service = new DNSSD::PublicService(QHostInfo::localHostName(), serviceType, port);
+
+    mServer = new QTcpServer();
+    connect(mServer,SIGNAL(newConnection()),this, SLOT(newConnection()));
+    mServer->listen(QHostAddress::Any, port);
+
+}
+
+void AvahiTcpAnnouncer::newConnection()
+{
+    qDebug() << "AvahiTcpAnnouncer newConnection";
+
+    QTcpSocket* socket = mServer->nextPendingConnection();
+
+    connect(socket,SIGNAL(readyRead()),this,SLOT(dataReceived()));
+
+    NetworkPackage np;
+    NetworkPackage::createIdentityPackage(&np);
+    qDebug() << socket->isWritable();
+    qDebug() << socket->isOpen();
+    int written = socket->write(np.serialize());
+
+    qDebug() << np.serialize();
+    qDebug() << "AvahiTcpAnnouncer sent tcp package" << written << " bytes written, waiting for reply";
+}
+
+void AvahiTcpAnnouncer::dataReceived()
+{
+    QTcpSocket* socket = (QTcpSocket*) QObject::sender();
+
+    QByteArray data = socket->readLine();
+
+    qDebug() << "AvahiTcpAnnouncer received reply:" << data;
+
+    NetworkPackage np;
+    NetworkPackage::unserialize(data,&np);
+
+    if (np.version() > 0 && np.type() == PACKAGE_TYPE_IDENTITY) {
+
+        const QString& id = np.get<QString>("deviceId");
+        TcpDeviceLink* dl = new TcpDeviceLink(id, this, socket);
+
+        connect(dl,SIGNAL(destroyed(QObject*)),this,SLOT(deviceLinkDestroyed(QObject*)));
+
+        if (links.contains(id)) {
+            //Delete old link if we already know it, probably it is down if this happens.
+            qDebug() << "Destroying old link";
+            delete links[id];
+        }
+        links[id] = dl;
+
+        qDebug() << "AvahiAnnouncer creating link to device" << id << "(" << socket->peerAddress() << ")";
+
+        emit onNewDeviceLink(np, dl);
+
+        disconnect(socket,SIGNAL(readyRead()),this,SLOT(dataReceived()));
+
+    } else {
+        qDebug() << "AvahiTcpAnnouncer/newConnection: Not an identification package (wuh?)";
+    }
+
+}
+
+void AvahiTcpAnnouncer::deviceLinkDestroyed(QObject* deviceLink)
+{
+    const QString& id = ((DeviceLink*)deviceLink)->deviceId();
+    if (links.contains(id)) links.remove(id);
+}
+
+AvahiTcpAnnouncer::~AvahiTcpAnnouncer()
+{
+    delete service;
+}
+
+void AvahiTcpAnnouncer::setDiscoverable(bool b)
+{
+    qDebug() << "AvahiTcp announcing";
+    if (b) service->publishAsync();
+}
+
diff --git a/daemon/announcers/avahiannouncer.h b/daemon/announcers/avahitcpannouncer.h
similarity index 74%
copy from daemon/announcers/avahiannouncer.h
copy to daemon/announcers/avahitcpannouncer.h
index eb3c1db..84fdcfc 100644
--- a/daemon/announcers/avahiannouncer.h
+++ b/daemon/announcers/avahitcpannouncer.h
@@ -18,40 +18,42 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef AVAHIANNOUNCER_H
-#define AVAHIANNOUNCER_H
+#ifndef AVAHITCPANNOUNCER_H
+#define AVAHITCPANNOUNCER_H
 
 #include <QObject>
-
-#include <QUdpSocket>
+#include <QTcpServer>
 
 #include <KDE/DNSSD/PublicService>
 
 #include "announcer.h"
 #include "netaddress.h"
 
-class AvahiAnnouncer
+
+class AvahiTcpAnnouncer
     : public Announcer
 {
     Q_OBJECT
 
 public:
-    AvahiAnnouncer();
-    ~AvahiAnnouncer();
+    AvahiTcpAnnouncer();
+    ~AvahiTcpAnnouncer();
 
-    QString name() { return "Avahi"; }
-    Priority priority() { return PRIORITY_HIGH; }
+    QString name() { return "AvahiTcpAnnouncer"; }
+    int priority() { return PRIORITY_HIGH + 1; }
 
     void setDiscoverable(bool b);
 
 private Q_SLOTS:
-    void readPendingNotifications();
+    void newConnection();
+    void deviceLinkDestroyed(QObject*);
+    void dataReceived();
 
 private:
     DNSSD::PublicService* service;
-    QUdpSocket* mUdpSocket;
+    QTcpServer* mServer;
 
-    QMap<NetAddress, DeviceLink*> links;
+    QMap<QString, DeviceLink*> links;
 
 };
 
diff --git a/daemon/announcers/fakeannouncer.cpp b/daemon/announcers/fakeannouncer.cpp
index 9749ffc..e045620 100644
--- a/daemon/announcers/fakeannouncer.cpp
+++ b/daemon/announcers/fakeannouncer.cpp
@@ -21,18 +21,22 @@
 #include "fakeannouncer.h"
 #include "devicelinks/echodevicelink.h"
 
-FakeAnnouncer::FakeAnnouncer()
+#include <QDebug>
+
+LoopbackAnnouncer::LoopbackAnnouncer()
 {
     echoDeviceLink = new EchoDeviceLink("fake", this);
+    NetworkPackage::createIdentityPackage(&identityPackage);
 }
 
-FakeAnnouncer::~FakeAnnouncer()
+LoopbackAnnouncer::~LoopbackAnnouncer()
 {
     //delete echoDeviceLink;
 }
 
-void FakeAnnouncer::setDiscoverable(bool b)
+void LoopbackAnnouncer::setDiscoverable(bool b)
 {
-    if (b) emit onNewDeviceLink(echoDeviceLink->deviceId(),"Echo device", echoDeviceLink);
+    qDebug() << "Echo Device discovery emitted";
+    if (b) emit onNewDeviceLink(identityPackage, echoDeviceLink);
 }
 
diff --git a/daemon/announcers/fakeannouncer.h b/daemon/announcers/fakeannouncer.h
index 2f00544..4ca6040 100644
--- a/daemon/announcers/fakeannouncer.h
+++ b/daemon/announcers/fakeannouncer.h
@@ -18,25 +18,27 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef FAKEANNOUNCER_H
-#define FAKEANNOUNCER_H
+#ifndef LOOPBACKANNOUNCER_H
+#define LOOPBACKANNOUNCER_H
 
 #include "announcer.h"
+#include "networkpackage.h"
 
-class FakeAnnouncer : public Announcer
+class LoopbackAnnouncer : public Announcer
 {
     Q_OBJECT
 public:
-    FakeAnnouncer();
-    ~FakeAnnouncer();
+    LoopbackAnnouncer();
+    ~LoopbackAnnouncer();
 
-    QString name() { return "FakeAnnouncer"; }
-    Priority priority() { return PRIORITY_LOW; }
+    QString name() { return "LoopbackAnnouncer"; }
+    int priority() { return PRIORITY_LOW; }
 
     void setDiscoverable(bool b);
 
 private:
     DeviceLink* echoDeviceLink;
+    NetworkPackage identityPackage;
     
 };
 
diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp
index 160ff00..4dacf5d 100644
--- a/daemon/daemon.cpp
+++ b/daemon/daemon.cpp
@@ -24,11 +24,13 @@
 #include "packagereceivers/notificationpackagereceiver.h"
 #include "packagereceivers/pausemusicpackagereceiver.h"
 #include "announcers/avahiannouncer.h"
+#include "announcers/avahitcpannouncer.h"
 #include "announcers/fakeannouncer.h"
 #include "devicelinks/echodevicelink.h"
 
 #include <QtNetwork/QUdpSocket>
 #include <QFile>
+#include <quuid.h>
 #include <QDBusConnection>
 
 #include <KIcon>
@@ -44,9 +46,12 @@ K_EXPORT_PLUGIN(KdeConnectFactory("kdeconnect", "kdeconnect"))
 Daemon::Daemon(QObject *parent, const QList<QVariant>&)
     : KDEDModule(parent)
 {
-
     KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
 
+    if (!config->group("myself").hasKey("id")) {
+        config->group("myself").writeEntry("id",QUuid::createUuid().toString());
+    }
+
     //Debugging
     qDebug() << "GO GO GO!";
     config->group("devices").group("paired").group("fake_unreachable").writeEntry("name","Fake device");
@@ -59,8 +64,9 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
 
     //TODO: Do not hardcode the load of the device locators
     //use: https://techbase.kde.org/Development/Tutorials/Services/Plugins
-    announcers.insert(new AvahiAnnouncer());
-    announcers.insert(new FakeAnnouncer());
+//     announcers.insert(new AvahiAnnouncer());
+    announcers.insert(new AvahiTcpAnnouncer());
+    //announcers.insert(new LoopbackAnnouncer());
 
     //TODO: Add package emitters
 
@@ -81,8 +87,8 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
 
     //Listen to incomming connections
     Q_FOREACH (Announcer* a, announcers) {
-        connect(a,SIGNAL(onNewDeviceLink(QString,QString,DeviceLink*)),
-                this,SLOT(onNewDeviceLink(QString,QString,DeviceLink*)));
+        connect(a,SIGNAL(onNewDeviceLink(NetworkPackage,DeviceLink*)),
+                this,SLOT(onNewDeviceLink(NetworkPackage,DeviceLink*)));
     }
 
     QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
@@ -106,14 +112,16 @@ QStringList Daemon::devices()
 }
 
 
-void Daemon::onNewDeviceLink(const QString& id, const QString& name, DeviceLink* dl)
+void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl)
 {
-    qDebug() << "Device discovered" << dl->deviceId();
+    const QString& id = identityPackage.get<QString>("deviceId");
 
-    if (m_devices.contains(dl->deviceId())) {
+    qDebug() << "Device discovered" << id << "via" << dl->announcer()->name();
+
+    if (m_devices.contains(id)) {
         qDebug() << "It is a known device";
 
-        Device* device = m_devices[dl->deviceId()];
+        Device* device = m_devices[id];
         device->addLink(dl);
 
         KNotification* notification = new KNotification("pingReceived"); //KNotification::Persistent
@@ -127,8 +135,10 @@ void Daemon::onNewDeviceLink(const QString& id, const QString& name, DeviceLink*
     } else {
         qDebug() << "It is a new device";
 
+        const QString& name = identityPackage.get<QString>("deviceName");
+
         Device* device = new Device(id,name,dl);
-        m_devices[dl->deviceId()] = device;
+        m_devices[id] = device;
         Q_FOREACH (PackageReceiver* pr, packageReceivers) {
             connect(device,SIGNAL(receivedPackage(const Device&, const NetworkPackage&)),
                     pr,SLOT(receivePackage(const Device&, const NetworkPackage&)));
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 533da5d..eeef7a9 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -69,7 +69,7 @@ Q_SIGNALS:
 
 
 private Q_SLOTS:
-    void onNewDeviceLink(const QString& id, const QString& name, DeviceLink* dl);
+    void onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl);
 
 private:
 
diff --git a/daemon/device.cpp b/daemon/device.cpp
index adc92ab..8efbeab 100644
--- a/daemon/device.cpp
+++ b/daemon/device.cpp
@@ -2,6 +2,7 @@
 #include <ksharedptr.h>
 #include <ksharedconfig.h>
 #include "devicelinks/devicelink.h"
+#include "announcers/announcer.h"
 
 #include <KConfigGroup>
 #include <QDebug>
@@ -63,7 +64,8 @@ static bool lessThan(DeviceLink* p1, DeviceLink* p2)
 
 void Device::addLink(DeviceLink* link)
 {
-    qDebug() << "AddLink";
+    qDebug() << "Adding link to " << id() << "via" << link->announcer();
+
     connect(link,SIGNAL(destroyed(QObject*)),this,SLOT(linkDestroyed(QObject*)));
 
     m_deviceLinks.append(link);
@@ -74,20 +76,23 @@ void Device::addLink(DeviceLink* link)
 
 void Device::linkDestroyed(QObject* o)
 {
+    qDebug() << "Link destroyed";
     removeLink(static_cast<DeviceLink*>(o));
 }
 
 void Device::removeLink(DeviceLink* link)
 {
     qDebug() << "RemoveLink";
-    disconnect(link, SIGNAL(receivedPackage(NetworkPackage)), this, SLOT(privateReceivedPackage(NetworkPackage)));
+    //disconnect(link, SIGNAL(receivedPackage(NetworkPackage)), this, SLOT(privateReceivedPackage(NetworkPackage)));
     m_deviceLinks.removeOne(link);
 }
 
 bool Device::sendPackage(const NetworkPackage& np)
 {
-    if (m_deviceLinks.empty()) return false;
-    return m_deviceLinks.first()->sendPackage(np);
+    Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
+        if (dl->sendPackage(np)) return true;
+    }
+    return false;
 }
 
 void Device::privateReceivedPackage(const NetworkPackage& np)
@@ -102,6 +107,15 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
     }
 }
 
+QStringList Device::availableLinks() const
+{
+    QStringList sl;
+    Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
+        sl.append(dl->announcer()->name());
+    }
+    return sl;
+}
+
 void Device::sendPing()
 {
     NetworkPackage np("kdeconnect.ping");
diff --git a/daemon/device.h b/daemon/device.h
index 583d3b9..51475c9 100644
--- a/daemon/device.h
+++ b/daemon/device.h
@@ -59,6 +59,7 @@ public Q_SLOTS:
     //Public dbus interface
     Q_SCRIPTABLE QString id() const{ return m_deviceId; }
     Q_SCRIPTABLE QString name() const { return m_deviceName; }
+    Q_SCRIPTABLE QStringList availableLinks() const;
     Q_SCRIPTABLE bool paired() const { return m_paired; }
     Q_SCRIPTABLE bool reachable() const { return !m_deviceLinks.empty(); }
     Q_SCRIPTABLE void setPair(bool b);
diff --git a/daemon/devicelinks/echodevicelink.cpp b/daemon/devicelinks/echodevicelink.cpp
index 004298e..174a36a 100644
--- a/daemon/devicelinks/echodevicelink.cpp
+++ b/daemon/devicelinks/echodevicelink.cpp
@@ -22,7 +22,7 @@
 
 #include "announcers/fakeannouncer.h"
 
-EchoDeviceLink::EchoDeviceLink(const QString& d, FakeAnnouncer* a)
+EchoDeviceLink::EchoDeviceLink(const QString& d, LoopbackAnnouncer* a)
     : DeviceLink(d, a)
 {
 
diff --git a/daemon/devicelinks/echodevicelink.h b/daemon/devicelinks/echodevicelink.h
index f3e5648..26c073f 100644
--- a/daemon/devicelinks/echodevicelink.h
+++ b/daemon/devicelinks/echodevicelink.h
@@ -22,13 +22,13 @@
 #define ECHODEVICELINK_H
 #include "devicelink.h"
 
-class FakeAnnouncer;
+class LoopbackAnnouncer;
 
 class EchoDeviceLink : public DeviceLink
 {
     Q_OBJECT
 public:
-    EchoDeviceLink(const QString& d, FakeAnnouncer* a);
+    EchoDeviceLink(const QString& d, LoopbackAnnouncer* a);
 
     bool sendPackage(const NetworkPackage& np) {
         emit receivedPackage(np);
diff --git a/daemon/devicelinks/echodevicelink.cpp b/daemon/devicelinks/tcpdevicelink.cpp
similarity index 62%
copy from daemon/devicelinks/echodevicelink.cpp
copy to daemon/devicelinks/tcpdevicelink.cpp
index 004298e..c31ecb1 100644
--- a/daemon/devicelinks/echodevicelink.cpp
+++ b/daemon/devicelinks/tcpdevicelink.cpp
@@ -18,12 +18,27 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "echodevicelink.h"
+#include "tcpdevicelink.h"
+#include "announcers/avahitcpannouncer.h"
 
-#include "announcers/fakeannouncer.h"
-
-EchoDeviceLink::EchoDeviceLink(const QString& d, FakeAnnouncer* a)
+TcpDeviceLink::TcpDeviceLink(const QString& d, AvahiTcpAnnouncer* a, QTcpSocket* socket)
     : DeviceLink(d, a)
 {
+    mSocket = socket;
+    connect(mSocket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
+    connect(mSocket, SIGNAL(readyRead()), this, SLOT(dataReceived()));
+}
+
+void TcpDeviceLink::dataReceived()
+{
+    qDebug() << "TcpDeviceLink dataReceived";
+
+    QByteArray a = mSocket->readAll();
+
+    qDebug() << a;
+
+    NetworkPackage np;
+    NetworkPackage::unserialize(a,&np);
 
+    emit receivedPackage(np);
 }
diff --git a/daemon/devicelinks/udpdevicelink.h b/daemon/devicelinks/tcpdevicelink.h
similarity index 73%
copy from daemon/devicelinks/udpdevicelink.h
copy to daemon/devicelinks/tcpdevicelink.h
index 0e9d47f..379b9a0 100644
--- a/daemon/devicelinks/udpdevicelink.h
+++ b/daemon/devicelinks/tcpdevicelink.h
@@ -18,38 +18,36 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef UDPDEVICELINK_H
-#define UDPDEVICELINK_H
+#ifndef TCPDEVICELINK_H
+#define TCPDEVICELINK_H
 
 #include <QObject>
 #include <QString>
+#include <qthread.h>
 
 #include "devicelink.h"
-#include <qudpsocket.h>
-#include <qtcpsocket.h>
+#include <QTcpSocket>
+#include <QTcpServer>
 
-class AvahiAnnouncer;
+class AvahiTcpAnnouncer;
 
-class UdpDeviceLink : public DeviceLink
+class TcpDeviceLink : public DeviceLink
 {
     Q_OBJECT
 
 public:
-    UdpDeviceLink(const QString& d, AvahiAnnouncer* a, QHostAddress ip, quint16 port);
+    TcpDeviceLink(const QString& d, AvahiTcpAnnouncer* a, QTcpSocket* socket);
 
     bool sendPackage(const NetworkPackage& np) {
-        mSocket->writeDatagram(np.serialize(),mIp,mPort);
+        mSocket->write(np.serialize());
         return true;
     }
-    
+
 private Q_SLOTS:
-    void readPendingNotifications();
+    void dataReceived();
 
 private:
-    QUdpSocket* mSocket;
-
-    QHostAddress mIp;
-    quint16 mPort;
+    QTcpSocket* mSocket;
 
 };
 
diff --git a/daemon/devicelinks/udpdevicelink.cpp b/daemon/devicelinks/udpdevicelink.cpp
index e5aabb1..a352757 100644
--- a/daemon/devicelinks/udpdevicelink.cpp
+++ b/daemon/devicelinks/udpdevicelink.cpp
@@ -21,23 +21,22 @@
 #include "udpdevicelink.h"
 #include "announcers/avahiannouncer.h"
 
-UdpDeviceLink::UdpDeviceLink(const QString& d, AvahiAnnouncer* a, QHostAddress ip, quint16 port)
+UdpDeviceLink::UdpDeviceLink(const QString& d, AvahiAnnouncer* a, QHostAddress ip)
     : DeviceLink(d, a)
 {
 
     mIp = ip;
-    mPort = port;
 
     mSocket = new QUdpSocket();
-    mSocket->bind(port);
-    connect(mSocket, SIGNAL(readyRead()), this, SLOT(readPendingNotifications()));
+    mSocket->bind(mPort);
+    connect(mSocket, SIGNAL(readyRead()), this, SLOT(dataReceived()));
 
 }
 
-void UdpDeviceLink::readPendingNotifications()
+void UdpDeviceLink::dataReceived()
 {
 
-    qDebug() << "UdpDeviceLink readPendingNotifications";
+    qDebug() << "UdpDeviceLink dataReceived";
 
     while (mSocket->hasPendingDatagrams()) {
 
@@ -54,7 +53,7 @@ void UdpDeviceLink::readPendingNotifications()
         NetworkPackage::unserialize(datagram,&np);
 
         emit receivedPackage(np);
-        
+
     }
 
 }
diff --git a/daemon/devicelinks/udpdevicelink.h b/daemon/devicelinks/udpdevicelink.h
index 0e9d47f..8735249 100644
--- a/daemon/devicelinks/udpdevicelink.h
+++ b/daemon/devicelinks/udpdevicelink.h
@@ -25,8 +25,7 @@
 #include <QString>
 
 #include "devicelink.h"
-#include <qudpsocket.h>
-#include <qtcpsocket.h>
+#include <QUdpSocket>
 
 class AvahiAnnouncer;
 
@@ -35,21 +34,21 @@ class UdpDeviceLink : public DeviceLink
     Q_OBJECT
 
 public:
-    UdpDeviceLink(const QString& d, AvahiAnnouncer* a, QHostAddress ip, quint16 port);
+    UdpDeviceLink(const QString& d, AvahiAnnouncer* a, QHostAddress ip);
 
     bool sendPackage(const NetworkPackage& np) {
-        mSocket->writeDatagram(np.serialize(),mIp,mPort);
+        mSocket->writeDatagram(np.serialize(),mIp,mPort+1);
         return true;
     }
     
 private Q_SLOTS:
-    void readPendingNotifications();
+    void dataReceived();
 
 private:
     QUdpSocket* mSocket;
 
     QHostAddress mIp;
-    quint16 mPort;
+    const quint16 mPort = 10603;
 
 };
 
diff --git a/daemon/networkpackage.cpp b/daemon/networkpackage.cpp
index 1cb97e3..82ce22d 100644
--- a/daemon/networkpackage.cpp
+++ b/daemon/networkpackage.cpp
@@ -19,9 +19,12 @@
  */
 
 #include "networkpackage.h"
+#include <ksharedconfig.h>
+#include <kconfiggroup.h>
 #include <qbytearray.h>
 #include <qdatastream.h>
-#include <QDebug>
+#include <KDebug>
+#include <QHostInfo>
 #include <sstream>
 #include <string>
 #include <qjson/serializer.h>
@@ -58,6 +61,7 @@ QByteArray NetworkPackage::serialize() const
 
 void NetworkPackage::unserialize(QByteArray a, NetworkPackage* np)
 {
+    kDebug() << a;
     //Json -> QVariant
     QJson::Parser parser;
     bool ok;
@@ -80,3 +84,17 @@ void NetworkPackage::unserialize(QByteArray a, NetworkPackage* np)
     QJson::QObjectHelper::qvariant2qobject(variant,np);
 }
 
+void NetworkPackage::createIdentityPackage(NetworkPackage* np)
+{
+    KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
+    QString id = config->group("myself").readEntry<QString>("id","");
+    np->mId = time(NULL);
+    np->mType = PACKAGE_TYPE_IDENTITY;
+    np->mVersion = CURRENT_PACKAGE_VERSION;
+    np->set("deviceId", id);
+    np->set("deviceName", QHostInfo::localHostName());
+
+    //qDebug() << "createIdentityPackage" << np->serialize();
+}
+
+
diff --git a/daemon/networkpackage.h b/daemon/networkpackage.h
index b2d8179..ce65f4c 100644
--- a/daemon/networkpackage.h
+++ b/daemon/networkpackage.h
@@ -44,6 +44,8 @@ public:
     static void unserialize(QByteArray, NetworkPackage*);
     QByteArray serialize() const;
 
+    static void createIdentityPackage(NetworkPackage*);
+
     long id() const { return mId; }
     const QString& type() const { return mType; }
     QVariantMap& body() { return mBody; }
diff --git a/daemon/packagereceivers/notificationpackagereceiver.cpp b/daemon/packagereceivers/notificationpackagereceiver.cpp
index 221caba..66eb4a6 100644
--- a/daemon/packagereceivers/notificationpackagereceiver.cpp
+++ b/daemon/packagereceivers/notificationpackagereceiver.cpp
@@ -72,8 +72,6 @@ KNotification* NotificationPackageReceiver::createNotification(const QString& de
 
 bool NotificationPackageReceiver::receivePackage(const Device& device, const NetworkPackage& np) {
 
-    qDebug() << "LOLOLO" << np.serialize();
-
     if (np.type() != PACKAGE_TYPE_NOTIFICATION) return false;
 
     if (np.get<bool>("isCancel")) {
diff --git a/daemon/packagereceivers/pausemusicpackagereceiver.cpp b/daemon/packagereceivers/pausemusicpackagereceiver.cpp
index 90fda01..f997372 100644
--- a/daemon/packagereceivers/pausemusicpackagereceiver.cpp
+++ b/daemon/packagereceivers/pausemusicpackagereceiver.cpp
@@ -25,7 +25,7 @@
 PauseMusicPackageReceiver::PauseMusicPackageReceiver()
 {
     //TODO: Be able to change this from settings
-    pauseWhen = PauseWhenTalking;
+    pauseWhen = PauseWhenRinging;
     paused = false;
 
 }
diff --git a/daemon/packagereceivers/pingpackagereceiver.cpp b/daemon/packagereceivers/pingpackagereceiver.cpp
index 993fc39..9b0eea0 100644
--- a/daemon/packagereceivers/pingpackagereceiver.cpp
+++ b/daemon/packagereceivers/pingpackagereceiver.cpp
@@ -20,12 +20,13 @@
 
 #include "pingpackagereceiver.h"
 
-#include <QDebug>
+#include <KDebug>
 #include <kicon.h>
 
 bool PingPackageReceiver::receivePackage(const Device& device, const NetworkPackage& np) {
 
-    qDebug() << np.type();
+
+    kDebug() << np.type();
 
     if (np.type() != PACKAGE_TYPE_PING) return false;
 
diff --git a/kcmodule.sh b/kcmodule.sh
deleted file mode 100755
index 301224c..0000000
--- a/kcmodule.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-#Source bashrc to define environment variables
-#http://techbase.kde.org/Getting_Started/Build/Environment
-. ~/.bashrc
-
-kcmshell4 kcm_kdeconnect &

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list