Started wizzard implementation

This commit is contained in:
Albert Vaca 2013-06-27 02:13:16 +02:00
parent 800de8836f
commit 1f536de7e9
9 changed files with 340 additions and 41 deletions

View file

@ -1,13 +1,14 @@
set(kcm_SRCS
set(kcm_SRCS devicesmodel.cpp
kcm.cpp
wizard.cpp
daemondbusinterface.cpp
)
qt4_add_dbus_interface(
kcm_SRCS
${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.xml
daemoninterface
org_kde_kdeconnect_interface
)
kde4_add_ui_files(kcm_SRCS kcm.ui wizard.ui)

View file

@ -0,0 +1,27 @@
/*
* 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)
{
}

33
kcm/daemondbusinterface.h Normal file
View file

@ -0,0 +1,33 @@
/*
* 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

138
kcm/devicesmodel.cpp Normal file
View file

@ -0,0 +1,138 @@
/*
* <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;
}

64
kcm/devicesmodel.h Normal file
View file

@ -0,0 +1,64 @@
/*
* <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

View file

@ -40,24 +40,19 @@ K_EXPORT_PLUGIN(KdeConnectKcmFactory("kdeconnect-kcm", "kdeconnect-kcm"))
KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
: KCModule(KdeConnectKcmFactory::componentData(), parent)
, dbusInterface("org.kde.kdeconnect", "/modules/androidshine", QDBusConnection::sessionBus(), this)
, wizard(this)
, kcmUi(new Ui::KdeConnectKcmUi())
, dbusInterface(this)
, pairedDevicesList(this)
, addDeviceWizard(this)
{
m_ui = new Ui::KdeConnectKcmUi();
m_ui->setupUi(this);
kcmUi->setupUi(this);
m_model = new QStandardItemModel(this);
m_ui->deviceList->setIconSize(QSize(32,32));
m_ui->deviceList->setModel(m_model);
kcmUi->deviceList->setIconSize(QSize(32,32));
kcmUi->deviceList->setModel(&pairedDevicesList);
// dbusInterface.pairDevice("holalala");
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()));
connect(kcmUi->addButton, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked()));
connect(kcmUi->removeButton, SIGNAL(clicked(bool)), this, SLOT(removeButtonClicked()));
}
@ -68,7 +63,7 @@ KdeConnectKcm::~KdeConnectKcm()
void KdeConnectKcm::addButtonClicked()
{
addDeviceWizard.show();
}
void KdeConnectKcm::removeButtonClicked()
@ -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"

View file

@ -27,7 +27,6 @@
#include <kcmodule.h>
#include "wizard.h"
#include "daemoninterface.h"
class Create;
class QModelIndex;
@ -43,7 +42,7 @@ namespace Ui {
class KdeConnectKcm : public KCModule
{
Q_OBJECT
Q_OBJECT
public:
KdeConnectKcm(QWidget *parent, const QVariantList&);
virtual ~KdeConnectKcm();
@ -53,14 +52,12 @@ private Q_SLOTS:
void removeButtonClicked();
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
void deviceAdded(QString id, QString name);
void deviceRemoved(QString id);
private:
OrgKdeKdeconnectInterface dbusInterface;
Ui::KdeConnectKcmUi* m_ui;
QStandardItemModel* m_model;
AddDeviceWizard wizard;
Ui::KdeConnectKcmUi* kcmUi;
DaemonDbusInterface dbusInterface;
QStandardItemModel pairedDevicesList;
AddDeviceWizard addDeviceWizard;
};

View file

@ -21,20 +21,58 @@
#include "wizard.h"
#include <QDebug>
#include <QStandardItemModel>
#include "ui_wizard.h"
AddDeviceWizard::AddDeviceWizard(QWidget* parent)
: QWizard(parent)
, wizardUi(new Ui::Wizard())
, dbusInterface(new DaemonDbusInterface(this))
, discoveredDevicesList(new QStandardItemModel(this))
{
qDebug() << "HA";
m_wizard = new Ui::Wizard();
m_wizard->setupUi(this);
wizardUi->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()
{
delete m_wizard;
delete wizardUi;
delete dbusInterface;
delete discoveredDevicesList;
}

View file

@ -22,18 +22,35 @@
#define WIZARD_H
#include <QWizard>
#include <QObject>
#include "daemondbusinterface.h"
namespace Ui {
class Wizard;
}
class QStandardItemModel;
class AddDeviceWizard : public QWizard
{
Q_OBJECT
public:
AddDeviceWizard(QWidget* parent);
~AddDeviceWizard();
private Q_SLOTS:
void pageChanged(int id);
void deviceDiscovered(QString id, QString name);
void deviceLost(QString id);
void discoveryFinished(bool success);
private:
Ui::Wizard* m_wizard;
Ui::Wizard* wizardUi;
DaemonDbusInterface* dbusInterface;
QStandardItemModel* discoveredDevicesList;
};
#endif // WIZARD_H