diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp index 91485250e..46c2ac298 100644 --- a/daemon/daemon.cpp +++ b/daemon/daemon.cpp @@ -50,6 +50,12 @@ void Daemon::linkTo(DeviceLink* dl) pr,SLOT(receivePackage(const NetworkPackage&))); } + KNotification* notification = new KNotification("pingReceived"); //KNotification::Persistent + notification->setPixmap(KIcon("dialog-ok").pixmap(48, 48)); + notification->setComponentData(KComponentData("kdeconnect", "kdeconnect")); + notification->setTitle(dl->device()->name()); + notification->setText("Succesfully connected"); + } Daemon::Daemon(QObject *parent, const QList&) @@ -124,15 +130,28 @@ void Daemon::startDiscovery(int timeOut) 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]); return true; - } +bool Daemon::unpairDevice(QString id) +{ + /*qDebug() << "M'han passat" << id; + foreach(QString c, config->group("devices").group("paired").groupList()) { + qDebug() << "Tinc" << c; + }*/ + if (!config->group("devices").group("paired").hasGroup(id)) { + return false; + } + config->group("devices").group("paired").deleteGroup(id); + return true; +} + + QString Daemon::listLinkedDevices() { QString ret; diff --git a/daemon/daemon.h b/daemon/daemon.h index 37c4dc0ae..532f7c315 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -66,6 +66,7 @@ public Q_SLOTS: Q_SCRIPTABLE QString listVisibleDevices(); Q_SCRIPTABLE bool pairDevice(QString id); + Q_SCRIPTABLE bool unpairDevice(QString id); /* Q_SCRIPTABLE QString listPairedDevices(QString id); diff --git a/daemon/devicelinks/devicelink.h b/daemon/devicelinks/devicelink.h index c6959cdbc..670fa0844 100644 --- a/daemon/devicelinks/devicelink.h +++ b/daemon/devicelinks/devicelink.h @@ -33,6 +33,7 @@ class DeviceLink Q_OBJECT public: + //TODO: Add QObject* parent DeviceLink(Device* d); Device* device() { return mDevice; } diff --git a/kcm/devicesmodel.cpp b/kcm/devicesmodel.cpp index c18650192..e7c4bf049 100644 --- a/kcm/devicesmodel.cpp +++ b/kcm/devicesmodel.cpp @@ -27,7 +27,7 @@ #include DevicesModel::DevicesModel(QObject *parent) - : QAbstractItemModel(parent) + : QAbstractListModel(parent) { } diff --git a/kcm/devicesmodel.h b/kcm/devicesmodel.h index 531d02fb5..e153a0f55 100644 --- a/kcm/devicesmodel.h +++ b/kcm/devicesmodel.h @@ -25,11 +25,12 @@ #include +#include #include #include class DevicesModel - : public QAbstractItemModel + : public QAbstractListModel { public: enum ModelRoles { diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 8f7c7ceea..f3715ff49 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -41,27 +41,27 @@ K_EXPORT_PLUGIN(KdeConnectKcmFactory("kdeconnect-kcm", "kdeconnect-kcm")) KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&) : KCModule(KdeConnectKcmFactory::componentData(), parent) , kcmUi(new Ui::KdeConnectKcmUi()) - , dbusInterface(this) - , pairedDevicesList(this) - , addDeviceWizard(this) + , m_dbusInterface(new DaemonDbusInterface(this)) + , pairedDevicesList(new DevicesModel(this)) + , addDeviceWizard(new AddDeviceWizard(this)) , config(KSharedConfig::openConfig("kdeconnectrc")) { + config->group("devices").group("paired").group("123456").writeEntry("name","Ultra-fake device"); + config->group("devices").group("paired").group("987654").writeEntry("name","Ultra-fake device"); - pairedDevicesList.loadPaired(); + pairedDevicesList->loadPaired(); kcmUi->setupUi(this); - //config->group("devices").group("paired").group("123456").writeEntry("name","Ultra-fake device"); - //config->group("devices").group("paired").group("987654").writeEntry("name","Ultra-fake device"); - //pairedDevicesList.updateFromConfig(); - kcmUi->deviceList->setIconSize(QSize(32,32)); - kcmUi->deviceList->setModel(&pairedDevicesList); + kcmUi->deviceList->setModel(pairedDevicesList); connect(kcmUi->addButton, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked())); connect(kcmUi->removeButton, SIGNAL(clicked(bool)), this, SLOT(removeButtonClicked())); - connect(&addDeviceWizard,SIGNAL(deviceAdded(QString,QString)),this, SLOT(deviceAdded(QString,QString))); + connect(kcmUi->deviceList, SIGNAL(pressed(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); + + connect(addDeviceWizard,SIGNAL(deviceAdded(QString,QString)),this, SLOT(deviceAdded(QString,QString))); } KdeConnectKcm::~KdeConnectKcm() @@ -71,28 +71,34 @@ KdeConnectKcm::~KdeConnectKcm() void KdeConnectKcm::addButtonClicked() { - addDeviceWizard.show(); + addDeviceWizard->show(); } void KdeConnectKcm::removeButtonClicked() { + QModelIndex selectedIndex = kcmUi->deviceList->currentIndex(); + if (selectedIndex.isValid() && selectedIndex.row() >= 0 && selectedIndex.row() < pairedDevicesList->rowCount()) { + QString id = pairedDevicesList->data(selectedIndex,DevicesModel::IdModelRole).toString(); + if (m_dbusInterface->unpairDevice(id)) {; + pairedDevicesList->loadPaired(); + } + } } void KdeConnectKcm::deviceAdded(QString id,QString name) { - qDebug() << "Succesfully paired: " + id; + if (m_dbusInterface->pairDevice(id)) { + qDebug() << "Succesfully paired: " + id; + pairedDevicesList->loadPaired(); + } - //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::deviceSelected(const QModelIndex& current) { - + qDebug() << "PENIS"; + kcmUi->removeButton->setEnabled(current.isValid()); } -#include "kcm.moc" diff --git a/kcm/kcm.h b/kcm/kcm.h index 9c66b2df0..3d875cf4a 100644 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -52,14 +52,14 @@ public: private Q_SLOTS: void addButtonClicked(); void removeButtonClicked(); - void currentChanged(const QModelIndex& current, const QModelIndex& previous); + void deviceSelected(const QModelIndex& current); void deviceAdded(QString id, QString name); private: Ui::KdeConnectKcmUi* kcmUi; - DaemonDbusInterface dbusInterface; - DevicesModel pairedDevicesList; - AddDeviceWizard addDeviceWizard; + DaemonDbusInterface* m_dbusInterface; + DevicesModel* pairedDevicesList; + AddDeviceWizard* addDeviceWizard; KSharedConfigPtr config; }; diff --git a/kcm/kcm.ui b/kcm/kcm.ui index e8b0261bc..2d64cd042 100644 --- a/kcm/kcm.ui +++ b/kcm/kcm.ui @@ -62,7 +62,7 @@ - + Add @@ -77,7 +77,7 @@ false - + Remove diff --git a/kcm/wizard.cpp b/kcm/wizard.cpp index 4707d305b..4ef0ad033 100644 --- a/kcm/wizard.cpp +++ b/kcm/wizard.cpp @@ -54,7 +54,6 @@ AddDeviceWizard::AddDeviceWizard(QWidget* parent) void AddDeviceWizard::wizardFinished() { - 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();