Load class TellStick for TellStick controllers

This commit is contained in:
Micke Prag 2012-04-18 17:26:05 +02:00
parent a2f8d08511
commit 3b137c0326
2 changed files with 13 additions and 2 deletions

View file

@ -1,5 +1,6 @@
#include "controllerlist.h"
#include "controller.h"
#include "tellstick.h"
#include <QDebug>
@ -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<ControllerList *>(context);
if (!controllerList) {

View file

@ -5,6 +5,8 @@
#include <QScriptValue>
#include <telldus-core.h>
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;