It even works now
This commit is contained in:
parent
5fbd33e8c5
commit
669edf8ea5
8 changed files with 50 additions and 21 deletions
|
@ -35,14 +35,14 @@ AvahiAnnouncer::AvahiAnnouncer()
|
||||||
|
|
||||||
connect(mUdpSocket, SIGNAL(readyRead()), this, SLOT(readPendingNotifications()));
|
connect(mUdpSocket, SIGNAL(readyRead()), this, SLOT(readPendingNotifications()));
|
||||||
|
|
||||||
qDebug() << "listening to udp messages";
|
qDebug() << "Listening to udp messages";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvahiAnnouncer::readPendingNotifications()
|
void AvahiAnnouncer::readPendingNotifications()
|
||||||
{
|
{
|
||||||
|
|
||||||
qDebug() << "readPendingNotifications";
|
qDebug() << "AvahiAnnouncer readPendingNotifications";
|
||||||
|
|
||||||
while (mUdpSocket->hasPendingDatagrams()) {
|
while (mUdpSocket->hasPendingDatagrams()) {
|
||||||
|
|
||||||
|
@ -53,17 +53,21 @@ void AvahiAnnouncer::readPendingNotifications()
|
||||||
mUdpSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
|
mUdpSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
|
||||||
|
|
||||||
//log.write(datagram);
|
//log.write(datagram);
|
||||||
qDebug() << ("AvahiAnnouncer incomming udp datagram: " + datagram);
|
qDebug() << "AvahiAnnouncer incomming udp datagram: " << datagram;
|
||||||
|
|
||||||
NetworkPackage np = NetworkPackage::fromString(datagram);
|
NetworkPackage np = NetworkPackage::fromString(datagram);
|
||||||
|
|
||||||
QString id = np.deviceId();
|
QString id = np.deviceId();
|
||||||
QString name = np.body();
|
QString name = np.body();
|
||||||
|
|
||||||
|
qDebug() << "AvahiAnnouncer creating link to device" << name;
|
||||||
|
|
||||||
Device* device = new Device(id, name);
|
Device* device = new Device(id, name);
|
||||||
DeviceLink* dl = new UdpDeviceLink(device, sender, 10600);
|
DeviceLink* dl = new UdpDeviceLink(device, sender, 10600);
|
||||||
links.append(dl);
|
links.append(dl);
|
||||||
|
|
||||||
|
qDebug() << "Emitting link" << name;
|
||||||
|
|
||||||
emit deviceConnection(dl);
|
emit deviceConnection(dl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,10 @@
|
||||||
|
|
||||||
#include <QtNetwork/QUdpSocket>
|
#include <QtNetwork/QUdpSocket>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <KDE/KIcon>
|
|
||||||
|
#include <KIcon>
|
||||||
|
#include <KConfigGroup>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
@ -53,6 +54,7 @@ void Daemon::linkTo(DeviceLink* dl)
|
||||||
|
|
||||||
Daemon::Daemon(QObject *parent, const QList<QVariant>&)
|
Daemon::Daemon(QObject *parent, const QList<QVariant>&)
|
||||||
: KDEDModule(parent)
|
: KDEDModule(parent)
|
||||||
|
, config(KSharedConfig::openConfig("kdeconnectrc"))
|
||||||
{
|
{
|
||||||
|
|
||||||
qDebug() << "GO GO GO!";
|
qDebug() << "GO GO GO!";
|
||||||
|
@ -69,8 +71,16 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
|
||||||
|
|
||||||
//TODO: Add package emitters
|
//TODO: Add package emitters
|
||||||
|
|
||||||
//TODO: Read paired devices from config
|
//Read remebered paired devices
|
||||||
//pairedDevices.push_back(new Device("MyAndroid","MyAndroid"));
|
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<QString>("name",defaultName);
|
||||||
|
pairedDevices.push_back(new Device(id,name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
|
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
|
||||||
|
|
||||||
|
@ -116,6 +126,8 @@ bool Daemon::pairDevice(QString id)
|
||||||
{
|
{
|
||||||
if (!visibleDevices.contains(id)) return false;
|
if (!visibleDevices.contains(id)) return false;
|
||||||
|
|
||||||
|
config->group("devices").group("paired").group(id).writeEntry("name",visibleDevices[id]->device()->name());
|
||||||
|
|
||||||
linkTo(visibleDevices[id]);
|
linkTo(visibleDevices[id]);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -139,6 +151,8 @@ QString Daemon::listLinkedDevices()
|
||||||
void Daemon::deviceConnection(DeviceLink* dl)
|
void Daemon::deviceConnection(DeviceLink* dl)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
qDebug() << "deviceConnection";
|
||||||
|
|
||||||
QString id = dl->device()->id();
|
QString id = dl->device()->id();
|
||||||
bool paired = false;
|
bool paired = false;
|
||||||
Q_FOREACH (Device* d, pairedDevices) {
|
Q_FOREACH (Device* d, pairedDevices) {
|
||||||
|
@ -151,15 +165,12 @@ void Daemon::deviceConnection(DeviceLink* dl)
|
||||||
visibleDevices[dl->device()->id()] = dl;
|
visibleDevices[dl->device()->id()] = dl;
|
||||||
|
|
||||||
if (paired) {
|
if (paired) {
|
||||||
qDebug() << "Known device connected" + dl->device()->name();
|
qDebug() << "Known device connected" << dl->device()->name();
|
||||||
linkTo(dl);
|
linkTo(dl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "Unknown device connected" + dl->device()->name();
|
qDebug() << "Unknown device connected" << dl->device()->name();
|
||||||
|
|
||||||
emit deviceDiscovered(dl->device()->id(), dl->device()->name());
|
emit deviceDiscovered(dl->device()->id(), dl->device()->name());
|
||||||
|
|
||||||
//linkTo(dl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <KDE/KDEDModule>
|
#include <KDEDModule>
|
||||||
#include <KDE/KNotification>
|
#include <KNotification>
|
||||||
|
|
||||||
#include "networkpackage.h"
|
#include "networkpackage.h"
|
||||||
#include <KDE/KPluginFactory>
|
#include <KDE/KPluginFactory>
|
||||||
|
@ -36,6 +36,8 @@
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
|
#include <KConfig>
|
||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "packagereceivers/packagereceiver.h"
|
#include "packagereceivers/packagereceiver.h"
|
||||||
#include "devicelinks/devicelink.h"
|
#include "devicelinks/devicelink.h"
|
||||||
|
@ -65,8 +67,6 @@ public Q_SLOTS:
|
||||||
|
|
||||||
Q_SCRIPTABLE bool pairDevice(QString id);
|
Q_SCRIPTABLE bool pairDevice(QString id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Q_SCRIPTABLE QString listPairedDevices(QString id);
|
Q_SCRIPTABLE QString listPairedDevices(QString id);
|
||||||
|
|
||||||
|
@ -82,8 +82,11 @@ Q_SIGNALS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
void linkTo(DeviceLink* dl);
|
void linkTo(DeviceLink* dl);
|
||||||
|
|
||||||
|
KSharedConfigPtr config;
|
||||||
|
|
||||||
//(Non paired?) visible devices
|
//(Non paired?) visible devices
|
||||||
QMap<QString, DeviceLink*> visibleDevices;
|
QMap<QString, DeviceLink*> visibleDevices;
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ UdpDeviceLink::UdpDeviceLink(Device* d, QHostAddress ip, quint16 port)
|
||||||
void UdpDeviceLink::readPendingNotifications()
|
void UdpDeviceLink::readPendingNotifications()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
qDebug() << "UdpDeviceLink readPendingNotifications";
|
||||||
|
|
||||||
while (mUdpSocket->hasPendingDatagrams()) {
|
while (mUdpSocket->hasPendingDatagrams()) {
|
||||||
|
|
||||||
QByteArray datagram;
|
QByteArray datagram;
|
||||||
|
|
|
@ -36,7 +36,7 @@ NetworkPackage NetworkPackage::fromString(QByteArray s)
|
||||||
|
|
||||||
long id;
|
long id;
|
||||||
ss >> id;
|
ss >> id;
|
||||||
qDebug() << "Receiving package with id: " << id;
|
//qDebug() << "Decoding package with id:" << id;
|
||||||
|
|
||||||
NetworkPackage pp(id);
|
NetworkPackage pp(id);
|
||||||
|
|
||||||
|
@ -59,6 +59,8 @@ NetworkPackage NetworkPackage::fromString(QByteArray s)
|
||||||
|
|
||||||
ss >> pp.mIsCancel;
|
ss >> pp.mIsCancel;
|
||||||
|
|
||||||
|
qDebug() << "Decoded package with id:" << id;
|
||||||
|
|
||||||
return pp;
|
return pp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(id),IdModelRole);
|
||||||
setData(index(rown,0),QVariant(name),NameModelRole);
|
setData(index(rown,0),QVariant(name),NameModelRole);
|
||||||
setData(index(rown,0),QVariant(PairedConnected),StatusModelRole);
|
setData(index(rown,0),QVariant(PairedConnected),StatusModelRole);
|
||||||
|
qDebug() << "Add device" << name;
|
||||||
emit dataChanged(index(rown,0),index(rown,0));
|
emit dataChanged(index(rown,0),index(rown,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,11 @@ void KdeConnectKcm::removeButtonClicked()
|
||||||
void KdeConnectKcm::deviceAdded(QString id,QString name)
|
void KdeConnectKcm::deviceAdded(QString id,QString name)
|
||||||
{
|
{
|
||||||
qDebug() << "Succesfully paired: " + id;
|
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)
|
void KdeConnectKcm::currentChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||||
|
|
|
@ -54,10 +54,11 @@ AddDeviceWizard::AddDeviceWizard(QWidget* parent)
|
||||||
|
|
||||||
void AddDeviceWizard::wizardFinished()
|
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 name = discoveredDevicesList->data(selectedIndex,DevicesModel::NameModelRole).toString();
|
||||||
QString id = discoveredDevicesList->data(selectedIndex,DevicesModel::IdModelRole).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)
|
void AddDeviceWizard::deviceDiscovered(QString id, QString name)
|
||||||
{
|
{
|
||||||
|
qDebug() << "Discovered"<<name;
|
||||||
discoveredDevicesList->addDevice(id,name,DevicesModel::Visible);
|
discoveredDevicesList->addDevice(id,name,DevicesModel::Visible);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -100,7 +102,7 @@ void AddDeviceWizard::show()
|
||||||
|
|
||||||
void AddDeviceWizard::deviceSelected(const QModelIndex& index)
|
void AddDeviceWizard::deviceSelected(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
qDebug() << "Selected: " + index.row();
|
qDebug() << "Selected:" << index.row();
|
||||||
selectedIndex = index;
|
selectedIndex = index;
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue