diff --git a/telldus-gui/Plugins/CMakeLists.txt b/telldus-gui/Plugins/CMakeLists.txt index 366d2f0d..4b29d679 100644 --- a/telldus-gui/Plugins/CMakeLists.txt +++ b/telldus-gui/Plugins/CMakeLists.txt @@ -8,11 +8,12 @@ IF (BUILD_LIBTELLDUS-GUI) SET(BUILD_PLUGIN_SYSTRAY TRUE CACHE BOOL "Build plugin 'Systray'") ENDIF (BUILD_LIBTELLDUS-GUI) +SET(BUILD_PLUGIN_CONTROLLERS FALSE CACHE BOOL "Build plugin 'Controllers admin plugin'") SET(BUILD_PLUGIN_DBUS FALSE CACHE BOOL "Build plugin 'DBus'") SET(BUILD_PLUGIN_LIVE FALSE CACHE BOOL "Build plugin 'Telldus Live!'") -SET(BUILD_PLUGIN_XPL FALSE CACHE BOOL "Build plugin 'xPL'") SET(BUILD_PLUGIN_SCHEDULERGUISIMPLE FALSE CACHE BOOL "Build plugin 'Simple Scheduler GUI'") SET(BUILD_PLUGIN_SENSORS TRUE CACHE BOOL "Build plugin 'Sensors'") +SET(BUILD_PLUGIN_XPL FALSE CACHE BOOL "Build plugin 'xPL'") ADD_SUBDIRECTORY(telldus) @@ -28,6 +29,10 @@ IF(BUILD_PLUGIN_SYSTRAY) ADD_SUBDIRECTORY(Systray) ENDIF(BUILD_PLUGIN_SYSTRAY) +IF(BUILD_PLUGIN_CONTROLLERS) + ADD_SUBDIRECTORY(Controllers) +ENDIF() + IF(BUILD_PLUGIN_DBUS) ADD_SUBDIRECTORY(DBus) ENDIF(BUILD_PLUGIN_DBUS) diff --git a/telldus-gui/Plugins/Controllers/CMakeLists.txt b/telldus-gui/Plugins/Controllers/CMakeLists.txt new file mode 100644 index 00000000..71825541 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/CMakeLists.txt @@ -0,0 +1,41 @@ +SET(REQUIRE_PLUGIN_QML TRUE PARENT_SCOPE) +#SET(REQUIRE_PLUGIN_SETTINGS TRUE PARENT_SCOPE) + +SET(QT_USE_QTDECLARATIVE TRUE) + +SET( Plugin_NAME "Controllers" ) + + +SET( Plugin_SRCS + controller.cpp + controllerlist.cpp + controllersplugin.cpp +) + +SET( Plugin_HDRS + controllersplugin.h +) + +SET( Plugin_MOC_HDRS + controller.h + controllerlist.h +) + +SET( Plugin_PATH "com.telldus.controllers" ) + +SET( Plugin_EXTRA + btn_action_remove.png + ControllerView.qml + header_bg.png + HeaderTitle.qml + icon.png + main.qml + row_bg.png + tellstick.png + tellstick_duo.png +) + +FIND_PACKAGE(TelldusCore REQUIRED) +SET( Plugin_LIBRARIES ${TELLDUSCORE_LIBRARY} ) + +INCLUDE( ../TelldusCenterPlugin.cmake NO_POLICY_SCOPE ) diff --git a/telldus-gui/Plugins/Controllers/ControllerView.qml b/telldus-gui/Plugins/Controllers/ControllerView.qml new file mode 100644 index 00000000..00989020 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/ControllerView.qml @@ -0,0 +1,92 @@ +import QtQuick 1.1 +import QtDesktop 0.1 + +BorderImage { + source: "row_bg.png" + border.left: 5; border.top: 5 + border.right: 5; border.bottom: 5 + width: parent.width + height: content.height + content.anchors.margins*2 + + Item { + id: content + anchors.top: parent.top + anchors.left: parent.left + anchors.margins: 5 + height: childrenRect.height + width: childrenRect.width + + Row { + spacing: 10 + Image { + source: icon(controller.type) + width: 50 + smooth: true + fillMode: Image.PreserveAspectFit + opacity: controller.available ? 1 : 0.5 + } + + Column { + Text { + color: "#004275" + text: productName(controller.type) + font.pixelSize: 15 + } + TextField { + //id: nameEdit + text: controller.name; + placeholderText: 'Enter a name for this controller' + onTextChanged: controller.name = text + } + } + Loader { + sourceComponent: tellstick + } + Image { + source: "btn_action_remove.png" + visible: !controller.available + } + } + } + + Component { + id: tellstick + Grid { + spacing: 3 + columns: 2 + Text { + color: "#004275" + text: "Serial:" + } + Text { + color: "#004275" + text: controller.serial + } + Text { + color: "#004275" + text: "Firmware version:" + } + Text { + color: "#004275" + text: controller.firmware + } + } + } + + function icon(type) { + if (type == 1) { + return "tellstick.png"; + } else if (type == 2) { + return "tellstick_duo.png"; + } + return "tellstick.png"; + } + function productName(type) { + if (type == 1) { + return "TellStick"; + } else if (type == 2) { + return "TellStick Duo"; + } + return ""; + } +} diff --git a/telldus-gui/Plugins/Controllers/HeaderTitle.qml b/telldus-gui/Plugins/Controllers/HeaderTitle.qml new file mode 100644 index 00000000..0d7ae213 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/HeaderTitle.qml @@ -0,0 +1,10 @@ +import Qt 4.7 + +Text { + id: headerTitle + text: "Name" + color: "white" + font.weight: Font.Bold + height: parent.height + verticalAlignment: Text.AlignVCenter +} diff --git a/telldus-gui/Plugins/Controllers/__init__.js b/telldus-gui/Plugins/Controllers/__init__.js new file mode 100644 index 00000000..b06ea8c4 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/__init__.js @@ -0,0 +1,25 @@ +/** Sensors **/ +__setupPackage__( __extension__ ); + +__postInit__ = function() { + application.allDoneLoading.connect( com.telldus.controllers.init ); +} + +com.telldus.controllers = function() { + var view = null; + + function init() { + view = new com.telldus.qml.view({}); + view.setProperty('controllerModel', com.telldus.controllers.list); + view.load("main.qml"); + view.sizeRootObjectToView(true); + application.configuration.addPage('Controllers', view, 'icon.png'); + com.telldus.controllers.list.changed.connect(application.configuration.valueChanged) + application.configuration.save.connect(com.telldus.controllers.list.save) + } + + return { //Public functions + init:init + } + +}(); diff --git a/telldus-gui/Plugins/Controllers/btn_action_remove.png b/telldus-gui/Plugins/Controllers/btn_action_remove.png new file mode 100644 index 00000000..d9e5bf75 Binary files /dev/null and b/telldus-gui/Plugins/Controllers/btn_action_remove.png differ diff --git a/telldus-gui/Plugins/Controllers/controller.cpp b/telldus-gui/Plugins/Controllers/controller.cpp new file mode 100644 index 00000000..d1966c11 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/controller.cpp @@ -0,0 +1,84 @@ +#include "controller.h" +#include +#include + +class Controller::PrivateData { +public: + bool available, nameChanged; + int id, type; + QString name, serial, firmware; +}; + +Controller::Controller(int id, int type, const QString &name, QObject *parent) : + QObject(parent) +{ + d = new PrivateData; + d->id = id; + d->type = type; + d->available = false; + d->nameChanged = false; + d->name = name; + + const int DATA_LENGTH = 255; + char buff[DATA_LENGTH]; + if (tdControllerValue(id, "serial", buff, DATA_LENGTH) == TELLSTICK_SUCCESS) { + d->serial = QString::fromUtf8(buff); + } + if (tdControllerValue(id, "firmware", buff, DATA_LENGTH) == TELLSTICK_SUCCESS) { + d->firmware = QString::fromUtf8(buff); + } +} + +Controller::~Controller() { + delete d; +} + +bool Controller::available() const { + return d->available; +} + +void Controller::setAvailable(bool available) { + d->available = available; + emit availableChanged(); + emit firmwareChanged(); +} + +QString Controller::firmware() const { + if (!d->available) { + return "?"; + } + return d->firmware; +} + +int Controller::id() const { + return d->id; +} + +QString Controller::name() const { + return d->name; +} + +void Controller::setName(const QString &name) { + if (name == d->name) { + return; + } + d->nameChanged = true; + d->name = name; + emit nameChanged(); +} + +void Controller::save() { + if (d->nameChanged) { + tdSetControllerValue(d->id, "name", d->name.toUtf8()); + d->nameChanged = false; + } +} + +QString Controller::serial() const { + return d->serial; +} + +int Controller::type() const { + return d->type; +} + diff --git a/telldus-gui/Plugins/Controllers/controller.h b/telldus-gui/Plugins/Controllers/controller.h new file mode 100644 index 00000000..07740c63 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/controller.h @@ -0,0 +1,52 @@ +#ifndef CONTROLLER_H +#define CONTROLLER_H + +#include +#include + +class Controller : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool available READ available NOTIFY availableChanged) + Q_PROPERTY(QString firmware READ firmware NOTIFY firmwareChanged) + Q_PROPERTY(int id READ id NOTIFY idChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString serial READ serial NOTIFY serialChanged) + Q_PROPERTY(int type READ type NOTIFY typeChanged()) + +public: + explicit Controller(int id = 0, int type = 1, const QString &name = "", QObject *parent = 0); + ~Controller(); + + bool available() const; + void setAvailable(bool available); + + QString firmware() const; + + int id() const; + + QString name() const; + void setName(const QString &name); + + void save(); + + QString serial() const; + + int type() const; + +signals: + void availableChanged(); + void firmwareChanged(); + void idChanged(); + void nameChanged(); + void serialChanged(); + void typeChanged(); + +private: + class PrivateData; + PrivateData *d; +}; + +Q_DECLARE_METATYPE(Controller*) + +#endif // CONTROLLER_H diff --git a/telldus-gui/Plugins/Controllers/controllerlist.cpp b/telldus-gui/Plugins/Controllers/controllerlist.cpp new file mode 100644 index 00000000..849999d0 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/controllerlist.cpp @@ -0,0 +1,48 @@ +#include "controllerlist.h" +#include "controller.h" +#include + +#include + +class ControllerList::PrivateData { +public: + QList list; +}; + +ControllerList::ControllerList(QObject *parent) : + QAbstractListModel(parent) +{ + d = new PrivateData; + + QHash roles; + roles[Qt::UserRole+1] = "controller"; + setRoleNames(roles); + + const int DATA_LENGTH = 255; + 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->setAvailable(available); + connect(controller, SIGNAL(nameChanged()), this, SIGNAL(changed())); + d->list.append(controller); + } +} + +ControllerList::~ControllerList() { + delete d; +} + +QVariant ControllerList::data(const QModelIndex &index, int role) const { + return QVariant::fromValue(d->list.at(index.row())); +} + +int ControllerList::rowCount(const QModelIndex &parent) const { + return d->list.size(); +} + +void ControllerList::save() { + for(int i = 0; i < d->list.size(); ++i) { + d->list.at(i)->save(); + } +} diff --git a/telldus-gui/Plugins/Controllers/controllerlist.h b/telldus-gui/Plugins/Controllers/controllerlist.h new file mode 100644 index 00000000..d5884feb --- /dev/null +++ b/telldus-gui/Plugins/Controllers/controllerlist.h @@ -0,0 +1,30 @@ +#ifndef CONTROLLERLIST_H +#define CONTROLLERLIST_H + +#include +#include + +class ControllerList : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(int length READ rowCount) +public: + explicit ControllerList(QObject *parent = 0); + ~ControllerList(); + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + +signals: + void changed(); + +public slots: + void save(); + +private: + class PrivateData; + PrivateData *d; + +}; + +#endif // CONTROLLERLIST_H diff --git a/telldus-gui/Plugins/Controllers/controllersplugin.cpp b/telldus-gui/Plugins/Controllers/controllersplugin.cpp new file mode 100644 index 00000000..681ccca2 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/controllersplugin.cpp @@ -0,0 +1,30 @@ +#include "controllersplugin.h" +#include "controllerlist.h" +#include "controller.h" +#include +#include + + +ControllersPlugin::ControllersPlugin ( QObject * parent ) + :QScriptExtensionPlugin( parent ) +{ +} + +ControllersPlugin::~ControllersPlugin() { +} + +void ControllersPlugin::initialize ( const QString & key, QScriptEngine * engine ) { + if (key == "com.telldus.controllers") { + qmlRegisterType("Telldus", 1, 0, "Controller"); + + QScriptValue qml = engine->globalObject().property("com").property("telldus").property("controllers"); + QScriptValue list = engine->newQObject(new ControllerList(), QScriptEngine::ScriptOwnership); + qml.setProperty("list", list); + } +} + +QStringList ControllersPlugin::keys () const { + return QStringList() << "com.telldus.controllers"; +} + +Q_EXPORT_PLUGIN2(ControllersInterface, ControllersPlugin) diff --git a/telldus-gui/Plugins/Controllers/controllersplugin.h b/telldus-gui/Plugins/Controllers/controllersplugin.h new file mode 100644 index 00000000..57cbe1d2 --- /dev/null +++ b/telldus-gui/Plugins/Controllers/controllersplugin.h @@ -0,0 +1,16 @@ +#ifndef CONTROLLERSPLUGIN_H +#define CONTROLLERSPLUGIN_H + +#include + +class ControllersPlugin : public QScriptExtensionPlugin { +public: + ControllersPlugin ( QObject * parent = 0 ); + ~ControllersPlugin (); + + virtual void initialize ( const QString & key, QScriptEngine * engine ); + virtual QStringList keys () const; +}; + + +#endif // CONTROLLERSPLUGIN_H diff --git a/telldus-gui/Plugins/Controllers/header_bg.png b/telldus-gui/Plugins/Controllers/header_bg.png new file mode 100644 index 00000000..564a158b Binary files /dev/null and b/telldus-gui/Plugins/Controllers/header_bg.png differ diff --git a/telldus-gui/Plugins/Controllers/icon.png b/telldus-gui/Plugins/Controllers/icon.png new file mode 100644 index 00000000..4badd42f Binary files /dev/null and b/telldus-gui/Plugins/Controllers/icon.png differ diff --git a/telldus-gui/Plugins/Controllers/main.qml b/telldus-gui/Plugins/Controllers/main.qml new file mode 100644 index 00000000..fb8f164b --- /dev/null +++ b/telldus-gui/Plugins/Controllers/main.qml @@ -0,0 +1,30 @@ +import QtQuick 1.1 + +//import QtDesktop 0.1 + +Item { + width: 500 //Minimum width + + Column { + spacing: 1 + anchors.fill: parent + + BorderImage { + id: header + source: "header_bg.png" + width: parent.width; height: 40 + border.left: 5; border.top: 5 + border.right: 5; border.bottom: 5 + + HeaderTitle { + text: "Controllers" + anchors.left: parent.left + anchors.leftMargin: 15 + } + } + Repeater { + model: controllerModel + delegate: ControllerView {} + } + } +} diff --git a/telldus-gui/Plugins/Controllers/row_bg.png b/telldus-gui/Plugins/Controllers/row_bg.png new file mode 100644 index 00000000..06f9d82d Binary files /dev/null and b/telldus-gui/Plugins/Controllers/row_bg.png differ diff --git a/telldus-gui/Plugins/Controllers/tellstick.png b/telldus-gui/Plugins/Controllers/tellstick.png new file mode 100644 index 00000000..b437a369 Binary files /dev/null and b/telldus-gui/Plugins/Controllers/tellstick.png differ diff --git a/telldus-gui/Plugins/Controllers/tellstick_duo.png b/telldus-gui/Plugins/Controllers/tellstick_duo.png new file mode 100644 index 00000000..c3a4513a Binary files /dev/null and b/telldus-gui/Plugins/Controllers/tellstick_duo.png differ