Fixed android app bug

This commit is contained in:
Albert Vaca 2013-07-02 15:22:05 +02:00
parent 669edf8ea5
commit 213e8ea9ad
9 changed files with 59 additions and 32 deletions

View file

@ -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<QVariant>&)
@ -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;

View file

@ -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);

View file

@ -33,6 +33,7 @@ class DeviceLink
Q_OBJECT
public:
//TODO: Add QObject* parent
DeviceLink(Device* d);
Device* device() { return mDevice; }

View file

@ -27,7 +27,7 @@
#include <KConfigGroup>
DevicesModel::DevicesModel(QObject *parent)
: QAbstractItemModel(parent)
: QAbstractListModel(parent)
{
}

View file

@ -25,11 +25,12 @@
#include <QAbstractItemModel>
#include <QAbstractListModel>
#include <QPixmap>
#include <QList>
class DevicesModel
: public QAbstractItemModel
: public QAbstractListModel
{
public:
enum ModelRoles {

View file

@ -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"

View file

@ -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;
};

View file

@ -62,7 +62,7 @@
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string/>
<string>Add</string>
</property>
<property name="icon">
<iconset theme="list-add">
@ -77,7 +77,7 @@
<bool>false</bool>
</property>
<property name="text">
<string/>
<string>Remove</string>
</property>
<property name="icon">
<iconset theme="list-remove">

View file

@ -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();