Add new 'Controllers' plugin to admin controllers, see #108

This commit is contained in:
Micke Prag 2012-02-17 15:36:36 +01:00
parent 345ff62a93
commit 3de0a98f89
18 changed files with 464 additions and 1 deletions

View file

@ -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)

View file

@ -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 )

View file

@ -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 "";
}
}

View file

@ -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
}

View file

@ -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
}
}();

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,84 @@
#include "controller.h"
#include <telldus-core.h>
#include <QDebug>
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;
}

View file

@ -0,0 +1,52 @@
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <QObject>
#include <QMetaType>
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

View file

@ -0,0 +1,48 @@
#include "controllerlist.h"
#include "controller.h"
#include <telldus-core.h>
#include <QDebug>
class ControllerList::PrivateData {
public:
QList<Controller *> list;
};
ControllerList::ControllerList(QObject *parent) :
QAbstractListModel(parent)
{
d = new PrivateData;
QHash<int, QByteArray> 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();
}
}

View file

@ -0,0 +1,30 @@
#ifndef CONTROLLERLIST_H
#define CONTROLLERLIST_H
#include <QAbstractListModel>
#include <QScriptValue>
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

View file

@ -0,0 +1,30 @@
#include "controllersplugin.h"
#include "controllerlist.h"
#include "controller.h"
#include <QScriptEngine>
#include <QtDeclarative>
ControllersPlugin::ControllersPlugin ( QObject * parent )
:QScriptExtensionPlugin( parent )
{
}
ControllersPlugin::~ControllersPlugin() {
}
void ControllersPlugin::initialize ( const QString & key, QScriptEngine * engine ) {
if (key == "com.telldus.controllers") {
qmlRegisterType<Controller>("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)

View file

@ -0,0 +1,16 @@
#ifndef CONTROLLERSPLUGIN_H
#define CONTROLLERSPLUGIN_H
#include <QScriptExtensionPlugin>
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 754 B

View file

@ -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 {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB