From cf5d24b94d96b722c6d76c2225293a56a50d3c2b Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 25 Sep 2011 04:53:46 +0200 Subject: watchlets working! --- sysinfowatchlet/metawatch-digital.qml | 46 +++++++++++++++++++++++++++++++++++ sysinfowatchlet/sysinfoplugin.cpp | 29 ++++++++++++++++++++++ sysinfowatchlet/sysinfoplugin.h | 24 ++++++++++++++++++ sysinfowatchlet/sysinfowatchlet.cpp | 26 ++++++++++++++++++++ sysinfowatchlet/sysinfowatchlet.h | 29 ++++++++++++++++++++++ sysinfowatchlet/sysinfowatchlet.pro | 44 +++++++++++++++++++++++++++++++++ sysinfowatchlet/sysinfowatchlet.qrc | 5 ++++ 7 files changed, 203 insertions(+) create mode 100644 sysinfowatchlet/metawatch-digital.qml create mode 100644 sysinfowatchlet/sysinfoplugin.cpp create mode 100644 sysinfowatchlet/sysinfoplugin.h create mode 100644 sysinfowatchlet/sysinfowatchlet.cpp create mode 100644 sysinfowatchlet/sysinfowatchlet.h create mode 100644 sysinfowatchlet/sysinfowatchlet.pro create mode 100644 sysinfowatchlet/sysinfowatchlet.qrc (limited to 'sysinfowatchlet') diff --git a/sysinfowatchlet/metawatch-digital.qml b/sysinfowatchlet/metawatch-digital.qml new file mode 100644 index 0000000..65e9a7d --- /dev/null +++ b/sysinfowatchlet/metawatch-digital.qml @@ -0,0 +1,46 @@ +import QtQuick 1.0 + +Rectangle { + width: 96 + height: 96 + + color: "white" + + Column { + anchors.fill: parent + spacing: 4 + + Text { + text: "Battery: " + batteryLevel + "%" + } + + Rectangle { + id: battery + x: 12 + width: 72 + height: 16 + + border.color: "black" + border.width: 1 + + Rectangle { + width: (batteryLevel / 100) * parent.width + height: parent.height + + color: "black" + } + } + + Text { + width: parent.width + text: "Connected to:" + } + + Text { + width: parent.width + text: networkName + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.Wrap + } + } +} diff --git a/sysinfowatchlet/sysinfoplugin.cpp b/sysinfowatchlet/sysinfoplugin.cpp new file mode 100644 index 0000000..fc862c0 --- /dev/null +++ b/sysinfowatchlet/sysinfoplugin.cpp @@ -0,0 +1,29 @@ +#include "sysinfowatchlet.h" +#include "sysinfoplugin.h" + +using namespace sowatch; + +SysInfoPlugin::SysInfoPlugin(QObject *parent) : + QObject(parent) +{ +} + +SysInfoPlugin::~SysInfoPlugin() +{ +} + +QStringList SysInfoPlugin::watchlets() +{ + QStringList l; + l << "com.javispedro.sowatch.sysinfo"; + return l; +} + +Watchlet* SysInfoPlugin::getWatchlet(const QString& driver, QSettings& settings, WatchServer *server) +{ + Q_UNUSED(driver); + Q_UNUSED(settings); + return new SysInfoWatchlet(server); +} + +Q_EXPORT_PLUGIN2(sysinfowatchlet, SysInfoPlugin) diff --git a/sysinfowatchlet/sysinfoplugin.h b/sysinfowatchlet/sysinfoplugin.h new file mode 100644 index 0000000..4e24b9e --- /dev/null +++ b/sysinfowatchlet/sysinfoplugin.h @@ -0,0 +1,24 @@ +#ifndef CKITCALLPLUGIN_H +#define CKITCALLPLUGIN_H + +#include + +namespace sowatch +{ + +class SysInfoPlugin : public QObject, public WatchletPluginInterface +{ + Q_OBJECT + Q_INTERFACES(sowatch::WatchletPluginInterface) + +public: + SysInfoPlugin(QObject *parent = 0); + ~SysInfoPlugin(); + + QStringList watchlets(); + Watchlet* getWatchlet(const QString& driver, QSettings& settings, WatchServer* server); +}; + +} + +#endif // CKITCALLPLUGIN_H diff --git a/sysinfowatchlet/sysinfowatchlet.cpp b/sysinfowatchlet/sysinfowatchlet.cpp new file mode 100644 index 0000000..c9f44c2 --- /dev/null +++ b/sysinfowatchlet/sysinfowatchlet.cpp @@ -0,0 +1,26 @@ +#include "sysinfowatchlet.h" + +using namespace sowatch; +QTM_USE_NAMESPACE + +SysInfoWatchlet::SysInfoWatchlet(WatchServer* server) : + DeclarativeWatchlet(server, "com.javispedro.sowatch.sysinfo"), + _devInfo(new QSystemDeviceInfo(this)), + _netMgr(new QNetworkConfigurationManager(this)) +{ + rootContext()->setContextProperty("batteryLevel", 0); + rootContext()->setContextProperty("networkName", ""); + setSource(QUrl("qrc:/sysinfowatchlet/" + server->watch()->model() + ".qml")); + connect(this, SIGNAL(activated()), SLOT(handleActivated())); +} + +void SysInfoWatchlet::handleActivated() +{ + QList cfgs = _netMgr->allConfigurations(QNetworkConfiguration::Active); + rootContext()->setContextProperty("batteryLevel", _devInfo->batteryLevel()); + if (cfgs.size() > 0) { + rootContext()->setContextProperty("networkName", cfgs[0].name()); + } else { + rootContext()->setContextProperty("networkName", ""); + } +} diff --git a/sysinfowatchlet/sysinfowatchlet.h b/sysinfowatchlet/sysinfowatchlet.h new file mode 100644 index 0000000..25d8f57 --- /dev/null +++ b/sysinfowatchlet/sysinfowatchlet.h @@ -0,0 +1,29 @@ +#ifndef SOWATCH_TESTDECLARATIVEWATCHLET_H +#define SOWATCH_TESTDECLARATIVEWATCHLET_H + +#include +#include +#include + +using QTM_PREPEND_NAMESPACE(QSystemDeviceInfo); + +namespace sowatch +{ + +class SysInfoWatchlet : public DeclarativeWatchlet +{ + Q_OBJECT +public: + explicit SysInfoWatchlet(WatchServer* server); + +private slots: + void handleActivated(); + +private: + QSystemDeviceInfo *_devInfo; + QNetworkConfigurationManager *_netMgr; +}; + +} + +#endif // SOWATCH_TESTDECLARATIVEWATCHLET_H diff --git a/sysinfowatchlet/sysinfowatchlet.pro b/sysinfowatchlet/sysinfowatchlet.pro new file mode 100644 index 0000000..8c87ad8 --- /dev/null +++ b/sysinfowatchlet/sysinfowatchlet.pro @@ -0,0 +1,44 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-09-24T00:00:03 +# +#------------------------------------------------- + +TARGET = sysinfowatchlet +TEMPLATE = lib +# CONFIG += plugin # Stupid Qt creator doesn't want to deploy plugins +QT += network +CONFIG += mobility +MOBILITY += systeminfo + +SOURCES += sysinfoplugin.cpp sysinfowatchlet.cpp + +HEADERS += sysinfoplugin.h sysinfowatchlet.h + +unix: LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch + +INCLUDEPATH += $$PWD/../libsowatch +DEPENDPATH += $$PWD/../libsowatch + +unix:!symbian { + maemo5 { + target.path = /opt/sowatch/watchlets + } else { + target.path = /usr/lib/sowatch/watchlets + } + INSTALLS += target +} + +OTHER_FILES += \ + metawatch-digital.qml + +RESOURCES += \ + sysinfowatchlet.qrc + + + + + + + + diff --git a/sysinfowatchlet/sysinfowatchlet.qrc b/sysinfowatchlet/sysinfowatchlet.qrc new file mode 100644 index 0000000..62142b0 --- /dev/null +++ b/sysinfowatchlet/sysinfowatchlet.qrc @@ -0,0 +1,5 @@ + + + metawatch-digital.qml + + -- cgit v1.2.3