Refactored telldus-gui to handle device-model as string instead of integer

This commit is contained in:
Micke Prag 2009-05-06 15:13:11 +00:00
parent 52f663e29e
commit 1fc3474605
7 changed files with 75 additions and 68 deletions

View file

@ -55,8 +55,11 @@ QT4_WRAP_CPP( telldus-gui_MOC_SRCS ${telldus-gui_MOC_HDRS} )
QT4_AUTOMOC ( ${telldus-gui_SRCS} )
QT4_ADD_RESOURCES (telldus-gui_RSRCS telldusgui.qrc )
FIND_LIBRARY( TELLDUSCORE_LIBRARY telldus-core )
SET( telldus-gui_LIBRARIES
${QT_LIBRARIES}
${TELLDUSCORE_LIBRARY}
)
######## Configurable options for the platform ########
@ -106,7 +109,7 @@ ADD_LIBRARY(${telldus-gui_TARGET} SHARED
TARGET_LINK_LIBRARIES( ${telldus-gui_TARGET} ${telldus-gui_LIBRARIES} )
SET_PROPERTY(TARGET ${telldus-gui_TARGET}
PROPERTY FRAMEWORK TRUE
PROPERTY FRAMEWORK TRUE
)
SET_PROPERTY(TARGET ${telldus-gui_TARGET}
PROPERTY PUBLIC_HEADER ${telldus-gui_HDRS}

View file

@ -6,8 +6,8 @@ int Device::callbackId = tdRegisterDeviceEvent( &Device::deviceEvent, 0);
class DevicePrivate {
public:
int id, model, state;
QString name, protocol;
int id, state;
QString name, protocol, model;
bool modelChanged, nameChanged, protocolChanged;
mutable int methods;
mutable QHash<QString, QString> settings;
@ -17,7 +17,7 @@ Device::Device(int id)
{
d = new DevicePrivate;
d->id = id;
d->model = 0;
d->model = "";
d->state = 0;
d->name = "";
d->protocol = "";
@ -45,12 +45,12 @@ Device::~Device() {
delete d;
}
void Device::setModel( int model ) {
void Device::setModel( const QString &model ) {
d->model = model;
d->modelChanged = true;
}
int Device::model() {
QString Device::model() const {
return d->model;
}
@ -62,7 +62,7 @@ void Device::setName( const QString & name ) {
d->nameChanged = true;
}
const QString &Device::name() {
QString &Device::name() const {
return d->name;
}
@ -87,7 +87,7 @@ void Device::setProtocol( const QString & protocol ) {
d->protocolChanged = true;
}
const QString &Device::protocol() {
QString &Device::protocol() const {
return d->protocol;
}
@ -133,7 +133,7 @@ void Device::save() {
}
if (d->modelChanged || deviceIsAdded) {
tdSetModel(d->id, d->model);
tdSetModel(d->id, d->model.toLocal8Bit());
methodsChanged = true;
d->modelChanged = false;
}

View file

@ -21,17 +21,17 @@ public:
static Device *newDevice( );
static bool deviceLoaded( int id );
void setModel( int model );
int model();
void setModel( const QString &model );
QString model() const;
void setName( const QString & name );
const QString &name();
QString &name() const;
void setParameter( const QString &name, const QString &value );
QString parameter( const QString &name, const QString &defaultValue ) const;
void setProtocol( const QString & protocol );
const QString &protocol();
QString &protocol() const;
int deviceType() const;
int lastSentCommand() const;

View file

@ -1,36 +1,37 @@
<RCC>
<qresource prefix="/" >
<file>data/devices.xml</file>
<file>images/bell.png</file>
<file>images/devices/143011.png</file>
<file>images/devices/14323.png</file>
<file>images/devices/14327.png</file>
<file>images/devices/145041.png</file>
<file>images/devices/145071.png</file>
<file>images/devices/145091.png</file>
<file>images/devices/17-356.png</file>
<file>images/devices/51340.png</file>
<file>images/devices/el2005.png</file>
<file>images/devices/el2019.png</file>
<file>images/devices/hdr.png</file>
<file>images/devices/koppla.png</file>
<file>images/devices/ml.png</file>
<file>images/devices/sycr.png</file>
<file>images/devices/RSL366R.png</file>
<file>images/devices/projectorscreen.png</file>
<file>images/list-add.png</file>
<file>images/list-edit.png</file>
<file>images/list-remove.png</file>
<file>images/vendors/ikea.png</file>
<file>images/vendors/intertechno.jpg</file>
<file>images/vendors/kjelloco.png</file>
<file>images/vendors/nexa.png</file>
<file>images/vendors/proove.png</file>
<file>images/vendors/roxcore.png</file>
<file>images/vendors/sartano.png</file>
<file>images/vendors/telldus.jpg</file>
<file>images/vendors/waveman.png</file>
<file>images/state_1.png</file>
<file>images/state_2.png</file>
</qresource>
</RCC>
<RCC>
<qresource prefix="/" >
<file>data/devices.xml</file>
<file>images/bell.png</file>
<file>images/devices/143011.png</file>
<file>images/devices/14323.png</file>
<file>images/devices/14327.png</file>
<file>images/devices/145041.png</file>
<file>images/devices/145071.png</file>
<file>images/devices/145091.png</file>
<file>images/devices/17-356.png</file>
<file>images/devices/51340.png</file>
<file>images/devices/el2005.png</file>
<file>images/devices/el2019.png</file>
<file>images/devices/hdr.png</file>
<file>images/devices/koppla.png</file>
<file>images/devices/ml.png</file>
<file>images/devices/sycr.png</file>
<file>images/devices/RSL366R.png</file>
<file>images/devices/projectorscreen.png</file>
<file>images/list-add.png</file>
<file>images/list-edit.png</file>
<file>images/list-remove.png</file>
<file>images/vendors/ikea.png</file>
<file>images/vendors/intertechno.jpg</file>
<file>images/vendors/kjelloco.png</file>
<file>images/vendors/nexa.png</file>
<file>images/vendors/proove.png</file>
<file>images/vendors/roxcore.png</file>
<file>images/vendors/sartano.png</file>
<file>images/vendors/telldus.jpg</file>
<file>images/vendors/waveman.png</file>
<file>images/state_1.png</file>
<file>images/state_2.png</file>
<file>images/devices/bell.png</file>
</qresource>
</RCC>

View file

@ -76,7 +76,7 @@ QModelIndex VendorDeviceModel::index(int row, int column, const QModelIndex &par
}
QModelIndex VendorDeviceModel::index(Device *device) const {
VendorDeviceTreeItem *item = rootItem->findByDeviceId( device->model() );
VendorDeviceTreeItem *item = rootItem->findByDevice( *device );
if (!item) {
return QModelIndex();
}

View file

@ -1,13 +1,13 @@
#include "vendordevicetreeitem.h"
#include "device.h"
#include <QFile>
#include <QPixmap>
#include <QDebug>
#include <iostream>
VendorDeviceTreeItem::VendorDeviceTreeItem(int id, VendorDeviceTreeItem *parent)
:deviceId(id),
settingsWidget(0),
VendorDeviceTreeItem::VendorDeviceTreeItem(VendorDeviceTreeItem *parent)
:settingsWidget(0),
parentItem(parent)
{
}
@ -53,7 +53,7 @@ int VendorDeviceTreeItem::row() const {
QPixmap VendorDeviceTreeItem::image() const {
QString filename;
if (deviceId == 0) {
if (model == "") {
filename = ":/images/vendors/" + img + ".png";
} else {
filename = ":/images/devices/" + img + ".png";
@ -71,23 +71,24 @@ int VendorDeviceTreeItem::widget() const {
}
bool VendorDeviceTreeItem::isDevice() const {
return deviceId > 0;
return model.length() > 0;
}
int VendorDeviceTreeItem::deviceModel() const {
return deviceId;
QString VendorDeviceTreeItem::deviceModel() const {
return model;
}
const QString &VendorDeviceTreeItem::deviceProtocol() const {
return protocol;
}
VendorDeviceTreeItem * VendorDeviceTreeItem::findByDeviceId( int deviceId ) const {
VendorDeviceTreeItem * VendorDeviceTreeItem::findByDevice( const Device &device ) const {
foreach( VendorDeviceTreeItem *item, childItems ) {
if (item->deviceId == deviceId) {
if (item->deviceProtocol() == device.protocol() &&
item->deviceModel() == device.model()) {
return item;
}
VendorDeviceTreeItem *i = item->findByDeviceId( deviceId );
VendorDeviceTreeItem *i = item->findByDevice( device );
if (i) {
return i;
}
@ -139,7 +140,7 @@ bool VendorDeviceTreeItem::parseXml( const QString &filename ) {
}
void VendorDeviceTreeItem::parseType( QXmlStreamReader *reader ) {
VendorDeviceTreeItem *item = new VendorDeviceTreeItem(0, this);
VendorDeviceTreeItem *item = new VendorDeviceTreeItem(this);
item->deviceName = reader->attributes().value("name").toString();
appendChild(item);
@ -163,7 +164,7 @@ void VendorDeviceTreeItem::parseType( QXmlStreamReader *reader ) {
}
void VendorDeviceTreeItem::parseVendor( QXmlStreamReader *reader, VendorDeviceTreeItem *parent ) {
VendorDeviceTreeItem *item = new VendorDeviceTreeItem(0, parent);
VendorDeviceTreeItem *item = new VendorDeviceTreeItem(parent);
item->deviceName = reader->attributes().value("name").toString();
item->img = reader->attributes().value("image").toString();
parent->appendChild(item);
@ -189,7 +190,8 @@ void VendorDeviceTreeItem::parseVendor( QXmlStreamReader *reader, VendorDeviceTr
void VendorDeviceTreeItem::parseDevice( QXmlStreamReader *reader, VendorDeviceTreeItem *parent ) {
QXmlStreamAttributes attributes = reader->attributes();
VendorDeviceTreeItem *item = new VendorDeviceTreeItem(attributes.value("id").toString().toInt(), parent);
VendorDeviceTreeItem *item = new VendorDeviceTreeItem(parent);
item->model = attributes.value("model").toString();
item->img = attributes.value("image").toString();
item->settingsWidget = attributes.value("widget").toString().toInt();
item->protocol = attributes.value("protocol").toString();

View file

@ -3,12 +3,13 @@
#include <QVariant>
#include <QXmlStreamReader>
#include "device.h"
class VendorDeviceTreeItem
{
Q_DISABLE_COPY(VendorDeviceTreeItem)
public:
VendorDeviceTreeItem(int id = 0, VendorDeviceTreeItem *parent = 0);
VendorDeviceTreeItem(VendorDeviceTreeItem *parent = 0);
~VendorDeviceTreeItem();
void appendChild(VendorDeviceTreeItem *child);
@ -25,10 +26,10 @@ public:
QPixmap image() const;
int widget() const;
bool isDevice() const;
int deviceModel() const;
QString deviceModel() const;
const QString &deviceProtocol() const;
VendorDeviceTreeItem *findByDeviceId( int deviceId ) const;
VendorDeviceTreeItem *findByDevice( const Device &device ) const;
private:
void parseType( QXmlStreamReader *reader );
@ -38,8 +39,8 @@ private:
QList<VendorDeviceTreeItem *> childItems;
int deviceId, settingsWidget;
QString deviceName, protocol;
int settingsWidget;
QString deviceName, protocol, model;
QString img;
VendorDeviceTreeItem *parentItem;
};