diff --git a/telldus-gui/TelldusGui/CMakeLists.txt b/telldus-gui/TelldusGui/CMakeLists.txt index 093a5f1b..420dbaf3 100644 --- a/telldus-gui/TelldusGui/CMakeLists.txt +++ b/telldus-gui/TelldusGui/CMakeLists.txt @@ -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} diff --git a/telldus-gui/TelldusGui/device.cpp b/telldus-gui/TelldusGui/device.cpp index 955d4aba..5e2954f8 100644 --- a/telldus-gui/TelldusGui/device.cpp +++ b/telldus-gui/TelldusGui/device.cpp @@ -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 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; } diff --git a/telldus-gui/TelldusGui/device.h b/telldus-gui/TelldusGui/device.h index c3e8fe47..afcab9a5 100644 --- a/telldus-gui/TelldusGui/device.h +++ b/telldus-gui/TelldusGui/device.h @@ -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; diff --git a/telldus-gui/TelldusGui/telldusgui.qrc b/telldus-gui/TelldusGui/telldusgui.qrc index ef760761..f286aaa2 100644 --- a/telldus-gui/TelldusGui/telldusgui.qrc +++ b/telldus-gui/TelldusGui/telldusgui.qrc @@ -1,36 +1,37 @@ - - - data/devices.xml - images/bell.png - images/devices/143011.png - images/devices/14323.png - images/devices/14327.png - images/devices/145041.png - images/devices/145071.png - images/devices/145091.png - images/devices/17-356.png - images/devices/51340.png - images/devices/el2005.png - images/devices/el2019.png - images/devices/hdr.png - images/devices/koppla.png - images/devices/ml.png - images/devices/sycr.png - images/devices/RSL366R.png - images/devices/projectorscreen.png - images/list-add.png - images/list-edit.png - images/list-remove.png - images/vendors/ikea.png - images/vendors/intertechno.jpg - images/vendors/kjelloco.png - images/vendors/nexa.png - images/vendors/proove.png - images/vendors/roxcore.png - images/vendors/sartano.png - images/vendors/telldus.jpg - images/vendors/waveman.png - images/state_1.png - images/state_2.png - - + + + data/devices.xml + images/bell.png + images/devices/143011.png + images/devices/14323.png + images/devices/14327.png + images/devices/145041.png + images/devices/145071.png + images/devices/145091.png + images/devices/17-356.png + images/devices/51340.png + images/devices/el2005.png + images/devices/el2019.png + images/devices/hdr.png + images/devices/koppla.png + images/devices/ml.png + images/devices/sycr.png + images/devices/RSL366R.png + images/devices/projectorscreen.png + images/list-add.png + images/list-edit.png + images/list-remove.png + images/vendors/ikea.png + images/vendors/intertechno.jpg + images/vendors/kjelloco.png + images/vendors/nexa.png + images/vendors/proove.png + images/vendors/roxcore.png + images/vendors/sartano.png + images/vendors/telldus.jpg + images/vendors/waveman.png + images/state_1.png + images/state_2.png + images/devices/bell.png + + diff --git a/telldus-gui/TelldusGui/vendordevicemodel.cpp b/telldus-gui/TelldusGui/vendordevicemodel.cpp index cea28538..a61d6713 100644 --- a/telldus-gui/TelldusGui/vendordevicemodel.cpp +++ b/telldus-gui/TelldusGui/vendordevicemodel.cpp @@ -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(); } diff --git a/telldus-gui/TelldusGui/vendordevicetreeitem.cpp b/telldus-gui/TelldusGui/vendordevicetreeitem.cpp index 4a07d089..4ef33514 100644 --- a/telldus-gui/TelldusGui/vendordevicetreeitem.cpp +++ b/telldus-gui/TelldusGui/vendordevicetreeitem.cpp @@ -1,13 +1,13 @@ #include "vendordevicetreeitem.h" +#include "device.h" #include #include #include #include -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(); diff --git a/telldus-gui/TelldusGui/vendordevicetreeitem.h b/telldus-gui/TelldusGui/vendordevicetreeitem.h index 276cef9d..74e3bc92 100644 --- a/telldus-gui/TelldusGui/vendordevicetreeitem.h +++ b/telldus-gui/TelldusGui/vendordevicetreeitem.h @@ -3,12 +3,13 @@ #include #include +#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 childItems; - int deviceId, settingsWidget; - QString deviceName, protocol; + int settingsWidget; + QString deviceName, protocol, model; QString img; VendorDeviceTreeItem *parentItem; };