Commit 1f536de7 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Started wizzard implementation

parent 800de883
set(kcm_SRCS set(kcm_SRCS devicesmodel.cpp
kcm.cpp kcm.cpp
wizard.cpp wizard.cpp
daemondbusinterface.cpp
) )
qt4_add_dbus_interface( qt4_add_dbus_interface(
kcm_SRCS kcm_SRCS
${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.xml ${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.xml
daemoninterface org_kde_kdeconnect_interface
) )
kde4_add_ui_files(kcm_SRCS kcm.ui wizard.ui) kde4_add_ui_files(kcm_SRCS kcm.ui wizard.ui)
......
/*
* Copyright 2013 Albert Vaca <albertvaka@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 "daemondbusinterface.h"
DaemonDbusInterface::DaemonDbusInterface(QObject* parent)
: OrgKdeKdeconnectInterface("org.kde.kdeconnect", "/modules/androidshine", QDBusConnection::sessionBus(), parent)
{
}
\ No newline at end of file
/*
* Copyright 2013 Albert Vaca <albertvaka@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 "org_kde_kdeconnect_interface.h"
#ifndef DaemonDbusInterface_H_
#define DaemonDbusInterface_H_
class DaemonDbusInterface : public OrgKdeKdeconnectInterface {
Q_OBJECT
public:
DaemonDbusInterface(QObject* parent);
};
#endif
\ No newline at end of file
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2013 <copyright holder> <email>
*
* 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 "devicesmodel.h"
DevicesModel::DevicesModel(QObject *parent)
: QAbstractItemModel(parent)
{
}
DevicesModel::~DevicesModel()
{
}
int DevicesModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
QVariant DevicesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_deviceList.count()) {
return QVariant();
}
switch (role) {
case IconModelRole:
//return m_deviceList[index.row()].m_icon;
case NameModelRole:
//return m_deviceList[index.row()].m_device->name();
case AliasModelRole:
//return m_deviceList[index.row()].m_device->alias();
case DeviceTypeModelRole:
//return m_deviceList[index.row()].m_deviceType;
case DeviceModelRole:
//return QVariant::fromValue<void*>(m_deviceList[index.row()].m_device);
default:
break;
}
return QVariant();
}
bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_deviceList.count()) {
return false;
}
switch (role) {
case IconModelRole:
//m_deviceList[index.row()].m_icon = value.value<QPixmap>();
break;
case DeviceTypeModelRole:
//m_deviceList[index.row()].m_deviceType = value.toString();
break;
case DeviceModelRole: {
//Device *const device = static_cast<Device*>(value.value<void*>());
//m_deviceList[index.row()].m_device = device;
//connect(device, SIGNAL(propertyChanged(QString,QVariant)),this, SIGNAL(layoutChanged()));
}
break;
default:
return false;
}
emit dataChanged(index, index);
return true;
}
QModelIndex DevicesModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
if (row < 0 || row >= m_deviceList.count() || column != 0) {
return QModelIndex();
}
return createIndex(row, column);
}
QModelIndex DevicesModel::parent(const QModelIndex &index) const
{
Q_UNUSED(index);
return QModelIndex();
}
int DevicesModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_deviceList.count();
}
bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
{
if (row < 0 || row > m_deviceList.count() || count < 1) {
return false;
}
beginInsertRows(parent, row, row + count - 1);
for (int i = row; i < row + count; ++i) {
m_deviceList.insert(i, Device());
}
endInsertRows();
return true;
}
bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (row < 0 || row > m_deviceList.count() || count < 1) {
return false;
}
beginRemoveRows(parent, row, row + count - 1);
for (int i = row; i < row + count; ++i) {
m_deviceList.removeAt(row);
}
endRemoveRows();
return true;
}
\ No newline at end of file
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2013 <copyright holder> <email>
*
* 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/>.
*
*/
#ifndef DEVICESMODEL_H
#define DEVICESMODEL_H
#include <QAbstractItemModel>
#include <QPixmap>
#include <QList>
class DevicesModel
: public QAbstractItemModel
{
public:
enum ModelRoles {
IconModelRole = 0,
NameModelRole,
AliasModelRole,
DeviceTypeModelRole,
DeviceModelRole,
LastModelRole
};
DevicesModel(QObject *parent = 0);
virtual ~DevicesModel();
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex &index) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
private:
struct Device {
QString id;
QString name;
};
QList<Device> m_deviceList;
};
#endif // DEVICESMODEL_H
...@@ -40,24 +40,19 @@ K_EXPORT_PLUGIN(KdeConnectKcmFactory("kdeconnect-kcm", "kdeconnect-kcm")) ...@@ -40,24 +40,19 @@ 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)
, dbusInterface("org.kde.kdeconnect", "/modules/androidshine", QDBusConnection::sessionBus(), this) , kcmUi(new Ui::KdeConnectKcmUi())
, wizard(this) , dbusInterface(this)
, pairedDevicesList(this)
, addDeviceWizard(this)
{ {
m_ui = new Ui::KdeConnectKcmUi(); kcmUi->setupUi(this);
m_ui->setupUi(this);
m_model = new QStandardItemModel(this); kcmUi->deviceList->setIconSize(QSize(32,32));
m_ui->deviceList->setIconSize(QSize(32,32)); kcmUi->deviceList->setModel(&pairedDevicesList);
m_ui->deviceList->setModel(m_model);
// dbusInterface.pairDevice("holalala"); connect(kcmUi->addButton, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked()));
connect(kcmUi->removeButton, SIGNAL(clicked(bool)), this, SLOT(removeButtonClicked()));
connect(&dbusInterface, SIGNAL(deviceAdded(QString, QString)), this, SLOT(deviceAdded(QString, QString)));
connect(&dbusInterface, SIGNAL(deviceRemoved(QString)), this, SLOT(deviceRemoved(QString)));
connect(m_ui->removeButton, SIGNAL(clicked(bool)), this, SLOT(removeButtonClicked()));
connect(m_ui->addButton, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked()));
} }
...@@ -68,7 +63,7 @@ KdeConnectKcm::~KdeConnectKcm() ...@@ -68,7 +63,7 @@ KdeConnectKcm::~KdeConnectKcm()
void KdeConnectKcm::addButtonClicked() void KdeConnectKcm::addButtonClicked()
{ {
addDeviceWizard.show();
} }
void KdeConnectKcm::removeButtonClicked() void KdeConnectKcm::removeButtonClicked()
...@@ -81,16 +76,5 @@ void KdeConnectKcm::currentChanged(const QModelIndex& current, const QModelIndex ...@@ -81,16 +76,5 @@ void KdeConnectKcm::currentChanged(const QModelIndex& current, const QModelIndex
} }
void KdeConnectKcm::deviceAdded(QString id, QString name) //TODO: Rebre mes coses...
{
//m_model->appendRow(new QStandardItem(id));
wizard.show();
}
void KdeConnectKcm::deviceRemoved(QString id)
{
}
#include "kcm.moc" #include "kcm.moc"
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include <kcmodule.h> #include <kcmodule.h>
#include "wizard.h" #include "wizard.h"
#include "daemoninterface.h"
class Create; class Create;
class QModelIndex; class QModelIndex;
...@@ -43,7 +42,7 @@ namespace Ui { ...@@ -43,7 +42,7 @@ namespace Ui {
class KdeConnectKcm : public KCModule class KdeConnectKcm : public KCModule
{ {
Q_OBJECT Q_OBJECT
public: public:
KdeConnectKcm(QWidget *parent, const QVariantList&); KdeConnectKcm(QWidget *parent, const QVariantList&);
virtual ~KdeConnectKcm(); virtual ~KdeConnectKcm();
...@@ -53,14 +52,12 @@ private Q_SLOTS: ...@@ -53,14 +52,12 @@ private Q_SLOTS:
void removeButtonClicked(); void removeButtonClicked();
void currentChanged(const QModelIndex& current, const QModelIndex& previous); void currentChanged(const QModelIndex& current, const QModelIndex& previous);
void deviceAdded(QString id, QString name);
void deviceRemoved(QString id);
private: private:
OrgKdeKdeconnectInterface dbusInterface; Ui::KdeConnectKcmUi* kcmUi;
Ui::KdeConnectKcmUi* m_ui; DaemonDbusInterface dbusInterface;
QStandardItemModel* m_model; QStandardItemModel pairedDevicesList;
AddDeviceWizard wizard; AddDeviceWizard addDeviceWizard;
}; };
......
...@@ -21,20 +21,58 @@ ...@@ -21,20 +21,58 @@
#include "wizard.h" #include "wizard.h"
#include <QDebug> #include <QDebug>
#include <QStandardItemModel>
#include "ui_wizard.h" #include "ui_wizard.h"
AddDeviceWizard::AddDeviceWizard(QWidget* parent) AddDeviceWizard::AddDeviceWizard(QWidget* parent)
: QWizard(parent) : QWizard(parent)
, wizardUi(new Ui::Wizard())
, dbusInterface(new DaemonDbusInterface(this))
, discoveredDevicesList(new QStandardItemModel(this))
{ {
qDebug() << "HA";
m_wizard = new Ui::Wizard(); wizardUi->setupUi(this);
m_wizard->setupUi(this);
wizardUi->listView->setModel(discoveredDevicesList);
connect(this,SIGNAL(currentIdChanged(int)),this,SLOT(pageChanged(int)));
connect(dbusInterface, SIGNAL(deviceAdded(QString, QString)), this, SLOT(deviceDiscovered(QString,QString)));
connect(dbusInterface, SIGNAL(deviceRemoved(QString)), this, SLOT(deviceLost(QString)));
}
void AddDeviceWizard::pageChanged(int id)
{
qDebug() << id;
//QWizardPage* p = page(id);
if (id == 1) {
//Show "scanning"
}
}
void AddDeviceWizard::deviceDiscovered(QString id, QString name)
{
QStandardItem* item = new QStandardItem(name);
item->setData(id);
discoveredDevicesList->appendRow(item);
}
void AddDeviceWizard::deviceLost(QString id)
{
//discoveredDevicesList->removeRow();
}
void AddDeviceWizard::discoveryFinished(bool success)
{
} }
AddDeviceWizard::~AddDeviceWizard() AddDeviceWizard::~AddDeviceWizard()
{ {
delete m_wizard; delete wizardUi;
delete dbusInterface;
delete discoveredDevicesList;
} }
...@@ -22,18 +22,35 @@ ...@@ -22,18 +22,35 @@
#define WIZARD_H #define WIZARD_H
#include <QWizard> #include <QWizard>
#include <QObject>
#include "daemondbusinterface.h"
namespace Ui { namespace Ui {
class Wizard; class Wizard;
} }
class QStandardItemModel;
class AddDeviceWizard : public QWizard class AddDeviceWizard : public QWizard
{ {
Q_OBJECT
public: public:
AddDeviceWizard(QWidget* parent); AddDeviceWizard(QWidget* parent);
~AddDeviceWizard(); ~AddDeviceWizard();
private Q_SLOTS:
void pageChanged(int id);
void deviceDiscovered(QString id, QString name);
void deviceLost(QString id);
void discoveryFinished(bool success);
private: private:
Ui::Wizard* m_wizard; Ui::Wizard* wizardUi;
DaemonDbusInterface* dbusInterface;
QStandardItemModel* discoveredDevicesList;
}; };
#endif // WIZARD_H #endif // WIZARD_H
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