From 3b137c03261ed1d4c9bbe3c54eb0de27aea5517a Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Wed, 18 Apr 2012 17:26:05 +0200 Subject: [PATCH] Load class TellStick for TellStick controllers --- telldus-gui/Plugins/Controllers/controllerlist.cpp | 12 ++++++++++-- telldus-gui/Plugins/Controllers/controllerlist.h | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/telldus-gui/Plugins/Controllers/controllerlist.cpp b/telldus-gui/Plugins/Controllers/controllerlist.cpp index 76f0f347..99c8f039 100644 --- a/telldus-gui/Plugins/Controllers/controllerlist.cpp +++ b/telldus-gui/Plugins/Controllers/controllerlist.cpp @@ -1,5 +1,6 @@ #include "controllerlist.h" #include "controller.h" +#include "tellstick.h" #include @@ -25,7 +26,7 @@ ControllerList::ControllerList(QObject *parent) : char name[DATA_LENGTH]; int available, controllerId, type; while(tdController(&controllerId, &type, name, DATA_LENGTH, &available) == TELLSTICK_SUCCESS) { - Controller *controller = new Controller(controllerId, type, QString::fromUtf8(name), this); + Controller *controller = loadController(controllerId, type, QString::fromUtf8(name), this); controller->setAvailable(available); connect(controller, SIGNAL(nameChanged()), this, SIGNAL(changed())); d->list.append(controller); @@ -72,7 +73,7 @@ void ControllerList::controllerEventSlot(int controllerId, int changeEvent, int if (changeEvent == TELLSTICK_DEVICE_ADDED) { beginInsertRows( QModelIndex(), d->list.size(), d->list.size() ); - Controller *controller = new Controller(controllerId, changeType, "", this); + Controller *controller = loadController(controllerId, changeType, "", this); controller->setAvailable(true); connect(controller, SIGNAL(nameChanged()), this, SIGNAL(changed())); d->list.append(controller); @@ -93,6 +94,13 @@ void ControllerList::controllerEventSlot(int controllerId, int changeEvent, int } } +Controller *ControllerList::loadController(int id, int type, const QString &name, QObject *parent) { + if (type == 1) { + return new TellStick(id, type, "", parent); + } + return new Controller(id, type, "", parent); +} + void WINAPI ControllerList::controllerEvent( int controllerId, int changeEvent, int changeType, const char *newValue, int callbackId, void *context) { ControllerList *controllerList = reinterpret_cast(context); if (!controllerList) { diff --git a/telldus-gui/Plugins/Controllers/controllerlist.h b/telldus-gui/Plugins/Controllers/controllerlist.h index c325868c..be16af6f 100644 --- a/telldus-gui/Plugins/Controllers/controllerlist.h +++ b/telldus-gui/Plugins/Controllers/controllerlist.h @@ -5,6 +5,8 @@ #include #include +class Controller; + class ControllerList : public QAbstractListModel { Q_OBJECT @@ -27,6 +29,7 @@ private slots: void controllerEventSlot(int controllerId, int changeEvent, int changeType, const QString &newValue); private: + static Controller *loadController(int id, int type, const QString &name, QObject *parent); static void WINAPI controllerEvent( int controllerId, int changeEvent, int changeType, const char *newValue, int callbackId, void *context); class PrivateData; PrivateData *d;