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_AUTOMOC ( ${telldus-gui_SRCS} )
QT4_ADD_RESOURCES (telldus-gui_RSRCS telldusgui.qrc ) QT4_ADD_RESOURCES (telldus-gui_RSRCS telldusgui.qrc )
FIND_LIBRARY( TELLDUSCORE_LIBRARY telldus-core )
SET( telldus-gui_LIBRARIES SET( telldus-gui_LIBRARIES
${QT_LIBRARIES} ${QT_LIBRARIES}
${TELLDUSCORE_LIBRARY}
) )
######## Configurable options for the platform ######## ######## Configurable options for the platform ########
@ -106,7 +109,7 @@ ADD_LIBRARY(${telldus-gui_TARGET} SHARED
TARGET_LINK_LIBRARIES( ${telldus-gui_TARGET} ${telldus-gui_LIBRARIES} ) TARGET_LINK_LIBRARIES( ${telldus-gui_TARGET} ${telldus-gui_LIBRARIES} )
SET_PROPERTY(TARGET ${telldus-gui_TARGET} SET_PROPERTY(TARGET ${telldus-gui_TARGET}
PROPERTY FRAMEWORK TRUE PROPERTY FRAMEWORK TRUE
) )
SET_PROPERTY(TARGET ${telldus-gui_TARGET} SET_PROPERTY(TARGET ${telldus-gui_TARGET}
PROPERTY PUBLIC_HEADER ${telldus-gui_HDRS} PROPERTY PUBLIC_HEADER ${telldus-gui_HDRS}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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