Commit 213e8ea9 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Fixed android app bug

parent 669edf8e
...@@ -50,6 +50,12 @@ void Daemon::linkTo(DeviceLink* dl) ...@@ -50,6 +50,12 @@ void Daemon::linkTo(DeviceLink* dl)
pr,SLOT(receivePackage(const NetworkPackage&))); 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<QVariant>&) Daemon::Daemon(QObject *parent, const QList<QVariant>&)
...@@ -124,15 +130,28 @@ void Daemon::startDiscovery(int timeOut) ...@@ -124,15 +130,28 @@ void Daemon::startDiscovery(int timeOut)
bool Daemon::pairDevice(QString id) 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()); config->group("devices").group("paired").group(id).writeEntry("name",visibleDevices[id]->device()->name());
linkTo(visibleDevices[id]); linkTo(visibleDevices[id]);
return true; 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 Daemon::listLinkedDevices()
{ {
QString ret; QString ret;
......
...@@ -66,6 +66,7 @@ public Q_SLOTS: ...@@ -66,6 +66,7 @@ public Q_SLOTS:
Q_SCRIPTABLE QString listVisibleDevices(); Q_SCRIPTABLE QString listVisibleDevices();
Q_SCRIPTABLE bool pairDevice(QString id); Q_SCRIPTABLE bool pairDevice(QString id);
Q_SCRIPTABLE bool unpairDevice(QString id);
/* /*
Q_SCRIPTABLE QString listPairedDevices(QString id); Q_SCRIPTABLE QString listPairedDevices(QString id);
......
...@@ -33,6 +33,7 @@ class DeviceLink ...@@ -33,6 +33,7 @@ class DeviceLink
Q_OBJECT Q_OBJECT
public: public:
//TODO: Add QObject* parent
DeviceLink(Device* d); DeviceLink(Device* d);
Device* device() { return mDevice; } Device* device() { return mDevice; }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <KConfigGroup> #include <KConfigGroup>
DevicesModel::DevicesModel(QObject *parent) DevicesModel::DevicesModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractListModel(parent)
{ {
} }
......
...@@ -25,11 +25,12 @@ ...@@ -25,11 +25,12 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QAbstractListModel>
#include <QPixmap> #include <QPixmap>
#include <QList> #include <QList>
class DevicesModel class DevicesModel
: public QAbstractItemModel : public QAbstractListModel
{ {
public: public:
enum ModelRoles { enum ModelRoles {
......
...@@ -41,27 +41,27 @@ K_EXPORT_PLUGIN(KdeConnectKcmFactory("kdeconnect-kcm", "kdeconnect-kcm")) ...@@ -41,27 +41,27 @@ K_EXPORT_PLUGIN(KdeConnectKcmFactory("kdeconnect-kcm", "kdeconnect-kcm"))
KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&) KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
: KCModule(KdeConnectKcmFactory::componentData(), parent) : KCModule(KdeConnectKcmFactory::componentData(), parent)
, kcmUi(new Ui::KdeConnectKcmUi()) , kcmUi(new Ui::KdeConnectKcmUi())
, dbusInterface(this) , m_dbusInterface(new DaemonDbusInterface(this))
, pairedDevicesList(this) , pairedDevicesList(new DevicesModel(this))
, addDeviceWizard(this) , addDeviceWizard(new AddDeviceWizard(this))
, config(KSharedConfig::openConfig("kdeconnectrc")) , 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); 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->setIconSize(QSize(32,32));
kcmUi->deviceList->setModel(&pairedDevicesList); kcmUi->deviceList->setModel(pairedDevicesList);
connect(kcmUi->addButton, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked())); connect(kcmUi->addButton, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked()));
connect(kcmUi->removeButton, SIGNAL(clicked(bool)), this, SLOT(removeButtonClicked())); 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() KdeConnectKcm::~KdeConnectKcm()
...@@ -71,28 +71,34 @@ KdeConnectKcm::~KdeConnectKcm() ...@@ -71,28 +71,34 @@ KdeConnectKcm::~KdeConnectKcm()
void KdeConnectKcm::addButtonClicked() void KdeConnectKcm::addButtonClicked()
{ {
addDeviceWizard.show(); addDeviceWizard->show();
} }
void KdeConnectKcm::removeButtonClicked() 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) 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"
...@@ -52,14 +52,14 @@ public: ...@@ -52,14 +52,14 @@ public:
private Q_SLOTS: private Q_SLOTS:
void addButtonClicked(); void addButtonClicked();
void removeButtonClicked(); void removeButtonClicked();
void currentChanged(const QModelIndex& current, const QModelIndex& previous); void deviceSelected(const QModelIndex& current);
void deviceAdded(QString id, QString name); void deviceAdded(QString id, QString name);
private: private:
Ui::KdeConnectKcmUi* kcmUi; Ui::KdeConnectKcmUi* kcmUi;
DaemonDbusInterface dbusInterface; DaemonDbusInterface* m_dbusInterface;
DevicesModel pairedDevicesList; DevicesModel* pairedDevicesList;
AddDeviceWizard addDeviceWizard; AddDeviceWizard* addDeviceWizard;
KSharedConfigPtr config; KSharedConfigPtr config;
}; };
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
<item> <item>
<widget class="QPushButton" name="addButton"> <widget class="QPushButton" name="addButton">
<property name="text"> <property name="text">
<string/> <string>Add</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="list-add"> <iconset theme="list-add">
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string/> <string>Remove</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="list-remove"> <iconset theme="list-remove">
......
...@@ -54,7 +54,6 @@ AddDeviceWizard::AddDeviceWizard(QWidget* parent) ...@@ -54,7 +54,6 @@ AddDeviceWizard::AddDeviceWizard(QWidget* parent)
void AddDeviceWizard::wizardFinished() void AddDeviceWizard::wizardFinished()
{ {
if (selectedIndex.isValid() && 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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment