Implemented communication wizard -> kcm

Renamed androidshine -> kdeconnect
This commit is contained in:
Albert Vaca 2013-07-02 01:50:32 +02:00
parent 5027b7ee8e
commit 5fbd33e8c5
16 changed files with 177 additions and 57 deletions

View file

@ -1,4 +1,4 @@
project(androidshine)
project(kdeconnect)
cmake_minimum_required(VERSION 2.6)
find_package(KDE4 REQUIRED)

View file

@ -1,4 +1,4 @@
set(kded_androidshine_SRCS
set(kded_kdeconnect_SRCS
announcers/announcer.cpp
announcers/fakeannouncer.cpp
@ -19,9 +19,9 @@ set(kded_androidshine_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.xml
)
kde4_add_plugin(kded_androidshine ${kded_androidshine_SRCS})
kde4_add_plugin(kded_kdeconnect ${kded_kdeconnect_SRCS})
target_link_libraries(kded_androidshine
target_link_libraries(kded_kdeconnect
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
kdnssd
@ -37,6 +37,6 @@ qt4_generate_dbus_interface(
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR})
install(TARGETS kded_androidshine DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES androidshine.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded)
install(FILES androidshine.notifyrc DESTINATION ${DATA_INSTALL_DIR}/androidshine)
install(TARGETS kded_kdeconnect DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kdeconnect.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded)
install(FILES kdeconnect.notifyrc DESTINATION ${DATA_INSTALL_DIR}/kdeconnect)

View file

@ -36,8 +36,8 @@
#include <iomanip>
#include <iostream>
K_PLUGIN_FACTORY(AndroidShineFactory, registerPlugin<Daemon>();)
K_EXPORT_PLUGIN(AndroidShineFactory("androidshine", "androidshine"))
K_PLUGIN_FACTORY(KdeConnectFactory, registerPlugin<Daemon>();)
K_EXPORT_PLUGIN(KdeConnectFactory("kdeconnect", "kdeconnect"))
void Daemon::linkTo(DeviceLink* dl)
{
@ -58,13 +58,17 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
qDebug() << "GO GO GO!";
//TODO: Do not hardcode the load of the package receivers
//use: https://techbase.kde.org/Development/Tutorials/Services/Plugins
packageReceivers.push_back(new NotificationPackageReceiver());
packageReceivers.push_back(new PauseMusicPackageReceiver());
//TODO: Do not hardcode the load of the device locators
//use: https://techbase.kde.org/Development/Tutorials/Services/Plugins
announcers.insert(new AvahiAnnouncer());
announcers.insert(new FakeAnnouncer());
//TODO: Add package emitters
//TODO: Read paired devices from config
//pairedDevices.push_back(new Device("MyAndroid","MyAndroid"));
@ -77,7 +81,6 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
this,SLOT(deviceConnection(DeviceLink*)));
}
}
QString Daemon::listVisibleDevices()

View file

@ -3,6 +3,6 @@
Device::Device(const QString& id, const QString& name) {
mDeviceId = id;
mDeviceName = name;
QDBusConnection::sessionBus().registerObject("module/androidshine/Devices/"+id, this);
QDBusConnection::sessionBus().registerObject("module/kdeconnect/Devices/"+id, this);
}

View file

@ -2,12 +2,12 @@
Type=Service
Icon=preferences-system-power-management
X-KDE-ServiceTypes=KDEDModule
X-KDE-Library=androidshine
X-KDE-DBus-ModuleName=androidshine
X-KDE-Library=kdeconnect
X-KDE-DBus-ModuleName=kdeconnect
X-KDE-Kded-autoload=true
X-KDE-Kded-load-on-demand=false
X-KDE-Kded-phase=1
Name=Android shine
Name=KDE Connect
Comment=Android shiny backend
Comment=Connect KDE with your smartphone

View file

@ -62,7 +62,7 @@ KNotification* NotificationPackageReceiver::createNotification(const NetworkPack
KNotification* notification = new KNotification(type); //KNotification::Persistent
notification->setPixmap(KIcon(icon).pixmap(48, 48));
notification->setComponentData(KComponentData("androidshine", "androidshine"));
notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
notification->setTitle(title);
notification->setText(np.body());

View file

@ -21,7 +21,7 @@
#include "daemondbusinterface.h"
DaemonDbusInterface::DaemonDbusInterface(QObject* parent)
: OrgKdeKdeconnectInterface("org.kde.kdeconnect", "/modules/androidshine", QDBusConnection::sessionBus(), parent)
: OrgKdeKdeconnectInterface("org.kde.kdeconnect", "/modules/kdeconnect", QDBusConnection::sessionBus(), parent)
{
}

View file

@ -21,22 +21,63 @@
*/
#include "devicesmodel.h"
#include <ksharedconfig.h>
#include <QDebug>
#include <KConfigGroup>
DevicesModel::DevicesModel(QObject *parent)
: QAbstractItemModel(parent)
{
}
DevicesModel::~DevicesModel()
{
}
void DevicesModel::loadPaired()
{
//TODO: Load from daemon, so we can know if they are currently connected or not
removeRows(0,rowCount());
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
const KConfigGroup& known = config->group("devices").group("paired");
const QStringList& list = known.groupList();
const QString defaultName("unnamed");
Q_FOREACH(QString id, list) {
const KConfigGroup& data = known.group(id);
const QString& name = data.readEntry<QString>("name",defaultName);
//qDebug() << id << name;
addDevice(id,name,Visible);
}
}
void DevicesModel::addDevice(QString id, QString name, DevicesModel::DeviceStatus status)
{
int rown = rowCount();
insertRows(rown,1);
setData(index(rown,0),QVariant(id),IdModelRole);
setData(index(rown,0),QVariant(name),NameModelRole);
setData(index(rown,0),QVariant(PairedConnected),StatusModelRole);
emit dataChanged(index(rown,0),index(rown,0));
}
int DevicesModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
return 1; //We are not using the second dimension at all
}
QVariant DevicesModel::data(const QModelIndex &index, int role) const
@ -46,15 +87,13 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
}
switch (role) {
case IconModelRole:
//return m_deviceList[index.row()].m_icon;
return QPixmap(); //TODO: Return a pixmap to represent the status
case IdModelRole:
return m_deviceList[index.row()].id;
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);
return m_deviceList[index.row()].name;
case StatusModelRole:
return m_deviceList[index.row()].status;
default:
break;
}
@ -68,16 +107,16 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int
}
switch (role) {
case IconModelRole:
//m_deviceList[index.row()].m_icon = value.value<QPixmap>();
qDebug() << "Icon can not be assigned to, change status instead";
break;
case DeviceTypeModelRole:
//m_deviceList[index.row()].m_deviceType = value.toString();
case IdModelRole:
m_deviceList[index.row()].id = 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()));
}
case NameModelRole:
m_deviceList[index.row()].name = value.toString();
break;
case StatusModelRole:
m_deviceList[index.row()].status = (DeviceStatus)value.toInt();
break;
default:
return false;

View file

@ -33,12 +33,19 @@ class DevicesModel
{
public:
enum ModelRoles {
IconModelRole = 0,
NameModelRole,
AliasModelRole,
DeviceTypeModelRole,
DeviceModelRole,
LastModelRole
NameModelRole = Qt::DisplayRole,
IconModelRole = Qt::DecorationRole,
IdModelRole = Qt::UserRole,
StatusModelRole
};
enum DeviceStatus {
Missing = 0,
Visible,
Connected,
PairedMissing = 10,
PairedVisible,
PairedConnected,
};
DevicesModel(QObject *parent = 0);
@ -53,10 +60,15 @@ public:
virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
void loadPaired();
void addDevice(QString id, QString name, DeviceStatus status);
private:
struct Device {
QString id;
QString name;
DeviceStatus status;
};
QList<Device> m_deviceList;
};

View file

@ -44,16 +44,24 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
, dbusInterface(this)
, pairedDevicesList(this)
, addDeviceWizard(this)
, config(KSharedConfig::openConfig("kdeconnectrc"))
{
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);
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)));
}
KdeConnectKcm::~KdeConnectKcm()
@ -71,6 +79,12 @@ void KdeConnectKcm::removeButtonClicked()
}
void KdeConnectKcm::deviceAdded(QString id,QString name)
{
qDebug() << "Succesfully paired: " + id;
pairedDevicesList.addDevice(id,name,DevicesModel::PairedConnected);
}
void KdeConnectKcm::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{

View file

@ -25,8 +25,10 @@
#include <QDBusConnection>
#include <kcmodule.h>
#include <ksharedconfig.h>
#include "wizard.h"
#include "devicesmodel.h"
class Create;
class QModelIndex;
@ -51,12 +53,14 @@ private Q_SLOTS:
void addButtonClicked();
void removeButtonClicked();
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
void deviceAdded(QString id, QString name);
private:
Ui::KdeConnectKcmUi* kcmUi;
DaemonDbusInterface dbusInterface;
QStandardItemModel pairedDevicesList;
DevicesModel pairedDevicesList;
AddDeviceWizard addDeviceWizard;
KSharedConfigPtr config;
};

View file

@ -19,43 +19,60 @@
*/
#include "wizard.h"
#include "devicesmodel.h"
#include <QDebug>
#include <QStandardItemModel>
#include <kdebug.h>
#include "ui_wizard.h"
AddDeviceWizard::AddDeviceWizard(QWidget* parent)
: QWizard(parent)
, wizardUi(new Ui::Wizard())
, dbusInterface(new DaemonDbusInterface(this))
, discoveredDevicesList(new QStandardItemModel(this))
, discoveredDevicesList(new DevicesModel(this))
{
wizardUi->setupUi(this);
connect(wizardUi->listView,SIGNAL(activated(QModelIndex)),this,SLOT(deviceSelected(QModelIndex)));
wizardUi->listView->setModel(discoveredDevicesList);
dbusInterface->startDiscovery(123456789);
connect(this,SIGNAL(currentIdChanged(int)),this,SLOT(pageChanged(int)));
connect(this,SIGNAL(accepted()),this,SLOT(wizardFinished()));
connect(dbusInterface, SIGNAL(deviceDiscovered(QString, QString)), this, SLOT(deviceDiscovered(QString,QString)));
//connect(dbusInterface, SIGNAL(deviceLost(QString)), this, SLOT(deviceLost(QString)));
dbusInterface->startDiscovery(123456789);
}
void AddDeviceWizard::wizardFinished()
{
if (selectedIndex.row() > 0 && selectedIndex.row() < discoveredDevicesList->rowCount()) {
QString name = discoveredDevicesList->data(selectedIndex,DevicesModel::NameModelRole).toString();
QString id = discoveredDevicesList->data(selectedIndex,DevicesModel::IdModelRole).toString();
emit deviceAdded(name,id);
}
}
void AddDeviceWizard::pageChanged(int id)
{
qDebug() << id;
if (id == 2) {
//TODO: Do the actual pairing in this page
}
}
void AddDeviceWizard::deviceDiscovered(QString id, QString name)
{
QStandardItem* item = new QStandardItem(name);
item->setData(id);
discoveredDevicesList->appendRow(item);
discoveredDevicesList->addDevice(id,name,DevicesModel::Visible);
}
/*
void AddDeviceWizard::deviceLost(QString id)
@ -68,6 +85,26 @@ void AddDeviceWizard::discoveryFinished(bool success)
}
void AddDeviceWizard::restart()
{
selectedIndex = QModelIndex();
QWizard::restart();
}
void AddDeviceWizard::show()
{
restart();
QWizard::show();
}
void AddDeviceWizard::deviceSelected(const QModelIndex& index)
{
qDebug() << "Selected: " + index.row();
selectedIndex = index;
next();
}
AddDeviceWizard::~AddDeviceWizard()
{
delete wizardUi;

View file

@ -25,6 +25,7 @@
#include <QObject>
#include "daemondbusinterface.h"
#include "devicesmodel.h"
namespace Ui {
class Wizard;
@ -39,6 +40,8 @@ class AddDeviceWizard : public QWizard
public:
AddDeviceWizard(QWidget* parent);
~AddDeviceWizard();
void show();
void restart();
private Q_SLOTS:
void pageChanged(int id);
@ -47,10 +50,18 @@ private Q_SLOTS:
//void deviceLost(QString id);
void discoveryFinished(bool success);
void deviceSelected(const QModelIndex& index);
void wizardFinished();
Q_SIGNALS:
void deviceAdded(QString id, QString name);
private:
Ui::Wizard* wizardUi;
DaemonDbusInterface* dbusInterface;
QStandardItemModel* discoveredDevicesList;
DevicesModel* discoveredDevicesList;
QModelIndex selectedIndex;
};
#endif // WIZARD_H

View file

@ -14,14 +14,14 @@ if kdebuild; then
true
done
#qdbus org.kde.kded /kded unloadModule androidshine
#qdbus org.kde.kded /kded loadModule androidshine
#qdbus org.kde.kded /kded unloadModule kdeconnect
#qdbus org.kde.kded /kded loadModule kdeconnect
if [ ""$1 == "--nodaemon" ]; then
echo "nodaemon"
kded4 --nofork
else
kded4 2>&1 | grep -v "^kded(" &
kded4 --nofork # 2>&1 | grep -v "^kded(" &
fi
fi

View file

@ -1,10 +1,10 @@
set(kded_androidshine_tests_SRCS
set(kded_kdeconnect_tests_SRCS
backendtests.cpp
)
kde4_add_unit_test(kded_androidshine_tests ${kded_androidshine_tests_SRCS})
kde4_add_unit_test(kded_kdeconnect_tests ${kded_kdeconnect_tests_SRCS})
target_link_libraries(kded_androidshine_tests
target_link_libraries(kded_kdeconnect_tests
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
kdnssd
@ -12,5 +12,5 @@ target_link_libraries(kded_androidshine_tests
${QT_QTNETWORK_LIBRARY}
)
add_test(kded_androidshine_tests ${CMAKE_CURRENT_BINARY_DIR}/kded_androidshine_tests)
add_test(kded_kdeconnect_tests ${CMAKE_CURRENT_BINARY_DIR}/kded_kdeconnect_tests)