diff options
Diffstat (limited to 'sowatchui')
-rw-r--r-- | sowatchui/daemonproxy.cpp | 26 | ||||
-rw-r--r-- | sowatchui/daemonproxy.h | 63 | ||||
-rw-r--r-- | sowatchui/main.cpp | 2 | ||||
-rw-r--r-- | sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp | 5 | ||||
-rw-r--r-- | sowatchui/qmlapplicationviewer/qmlapplicationviewer.h | 2 | ||||
-rw-r--r-- | sowatchui/scannerproxy.cpp (renamed from sowatchui/scannerproxy.cc) | 0 | ||||
-rw-r--r-- | sowatchui/scanwatchesmodel.cpp (renamed from sowatchui/scanwatchesmodel.cc) | 0 | ||||
-rw-r--r-- | sowatchui/sowatchui.pro | 9 | ||||
-rw-r--r-- | sowatchui/watchesmodel.cpp (renamed from sowatchui/watchesmodel.cc) | 38 | ||||
-rw-r--r-- | sowatchui/watchesmodel.h | 6 |
10 files changed, 144 insertions, 7 deletions
diff --git a/sowatchui/daemonproxy.cpp b/sowatchui/daemonproxy.cpp new file mode 100644 index 0000000..6a4aee2 --- /dev/null +++ b/sowatchui/daemonproxy.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -c DaemonProxy -p daemonproxy ../sowatchd/daemon.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "daemonproxy.h" + +/* + * Implementation of interface class DaemonProxy + */ + +DaemonProxy::DaemonProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +DaemonProxy::~DaemonProxy() +{ +} + diff --git a/sowatchui/daemonproxy.h b/sowatchui/daemonproxy.h new file mode 100644 index 0000000..5083cf3 --- /dev/null +++ b/sowatchui/daemonproxy.h @@ -0,0 +1,63 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -c DaemonProxy -p daemonproxy ../sowatchd/daemon.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef DAEMONPROXY_H_1344472584 +#define DAEMONPROXY_H_1344472584 + +#include <QtCore/QObject> +#include <QtCore/QByteArray> +#include <QtCore/QList> +#include <QtCore/QMap> +#include <QtCore/QString> +#include <QtCore/QStringList> +#include <QtCore/QVariant> +#include <QtDBus/QtDBus> + +/* + * Proxy class for interface com.javispedro.sowatch.Daemon + */ +class DaemonProxy: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "com.javispedro.sowatch.Daemon"; } + +public: + DaemonProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~DaemonProxy(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<QString> GetWatchStatus(const QString &watch) + { + QList<QVariant> argumentList; + argumentList << qVariantFromValue(watch); + return asyncCallWithArgumentList(QLatin1String("GetWatchStatus"), argumentList); + } + + inline QDBusPendingReply<> Terminate() + { + QList<QVariant> argumentList; + return asyncCallWithArgumentList(QLatin1String("Terminate"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void WatchStatusChanged(const QString &watch, const QString &status); +}; + +namespace com { + namespace javispedro { + namespace sowatch { + typedef ::DaemonProxy Daemon; + } + } +} +#endif diff --git a/sowatchui/main.cpp b/sowatchui/main.cpp index f306fa9..ea4a172 100644 --- a/sowatchui/main.cpp +++ b/sowatchui/main.cpp @@ -19,6 +19,8 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) watches = new WatchesModel(app.data()); watchScanner = new ScanWatchesModel(app.data()); + qDebug() << "Starting" << watches << endl; + viewer->rootContext()->setContextProperty("watches", watches); viewer->rootContext()->setContextProperty("watchScanner", watchScanner); diff --git a/sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp b/sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp index 8ba6e88..672abd8 100644 --- a/sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp +++ b/sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -125,6 +125,11 @@ QmlApplicationViewer *QmlApplicationViewer::create() #endif } +QDeclarativeContext * QmlApplicationViewer::rootContext() +{ + return d->view->rootContext(); +} + void QmlApplicationViewer::setMainQmlFile(const QString &file) { d->mainQmlFile = d->adjustPath(file); diff --git a/sowatchui/qmlapplicationviewer/qmlapplicationviewer.h b/sowatchui/qmlapplicationviewer/qmlapplicationviewer.h index f8008f5..84fa3db 100644 --- a/sowatchui/qmlapplicationviewer/qmlapplicationviewer.h +++ b/sowatchui/qmlapplicationviewer/qmlapplicationviewer.h @@ -29,6 +29,8 @@ public: static QmlApplicationViewer *create(); + QDeclarativeContext *rootContext(); + void setMainQmlFile(const QString &file); void addImportPath(const QString &path); diff --git a/sowatchui/scannerproxy.cc b/sowatchui/scannerproxy.cpp index cfa4365..cfa4365 100644 --- a/sowatchui/scannerproxy.cc +++ b/sowatchui/scannerproxy.cpp diff --git a/sowatchui/scanwatchesmodel.cc b/sowatchui/scanwatchesmodel.cpp index 5b7c331..5b7c331 100644 --- a/sowatchui/scanwatchesmodel.cc +++ b/sowatchui/scanwatchesmodel.cpp diff --git a/sowatchui/sowatchui.pro b/sowatchui/sowatchui.pro index e02afcc..53abe73 100644 --- a/sowatchui/sowatchui.pro +++ b/sowatchui/sowatchui.pro @@ -21,14 +21,17 @@ CONFIG += qdeclarative-boostable LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch INCLUDEPATH += $$PWD/../libsowatch DEPENDPATH += $$PWD/../libsowatch +!isEmpty(MEEGO_VERSION_MAJOR)|maemo5 { + QMAKE_RPATHDIR += /opt/sowatch/lib +} # Source files SOURCES += main.cpp \ - watchesmodel.cc \ - scanwatchesmodel.cc scannerproxy.cc + watchesmodel.cpp daemonproxy.cpp \ + scanwatchesmodel.cpp scannerproxy.cpp HEADERS += \ - watchesmodel.h \ + watchesmodel.h daemonproxy.h \ scanwatchesmodel.h scannerproxy.h OTHER_FILES += qml/main.qml \ diff --git a/sowatchui/watchesmodel.cc b/sowatchui/watchesmodel.cpp index d12e7db..4531544 100644 --- a/sowatchui/watchesmodel.cc +++ b/sowatchui/watchesmodel.cpp @@ -7,7 +7,8 @@ using namespace sowatch; WatchesModel::WatchesModel(QObject *parent) : QAbstractListModel(parent), _config(new GConfKey("/apps/sowatch", this)), - _active_watches(_config->getSubkey("active-watches", this)) + _active_watches(_config->getSubkey("active-watches", this)), + _daemon(new DaemonProxy("com.javispedro.sowatchd", "/com/javispedro/sowatch/daemon", QDBusConnection::sessionBus())) { QHash<int, QByteArray> roles = roleNames(); roles[Qt::DisplayRole] = QByteArray("title"); @@ -19,7 +20,8 @@ WatchesModel::WatchesModel(QObject *parent) : this, SLOT(handleConfigChanged())); connect(_config, SIGNAL(subkeyChanged(QString)), this, SLOT(handleSubkeyChanged(QString))); - qDebug() << "connects"; + connect(_daemon, SIGNAL(WatchStatusChanged(QString,QString)), + this, SLOT(handleWatchStatusChanged(QString,QString))); reload(); } @@ -37,18 +39,31 @@ QVariant WatchesModel::data(const QModelIndex &index, int role) const { qDebug() << "Asked for data" << index.row() << index.column() << role; ConfigKey *config = _list[index.row()]; + QString key = config->key(); + QString id = key.mid(key.lastIndexOf('/') + 1); switch (role) { case Qt::DisplayRole: return config->value("name"); case Qt::StatusTipRole: - return QVariant(tr("Configured")); + if (isWatchIdActive(id)) { + QString status = _status[id]; + if (status == "connected") { + return QVariant(tr("Connected")); + } else if (status == "enabled") { + return QVariant(tr("Searching...")); + } else { + return QVariant(tr("Enabled")); + } + } else { + return QVariant(tr("Disabled")); + } } return QVariant(); } bool WatchesModel::removeRows(int row, int count, const QModelIndex &parent) { - + return false; // TODO } void WatchesModel::addFoundWatch(const QVariantMap &info) @@ -124,6 +139,15 @@ void WatchesModel::handleSubkeyChanged(const QString &subkey) } } +void WatchesModel::handleWatchStatusChanged(const QString &watch, const QString &status) +{ + _status[watch] = status; + int i = findRowByWatchId(watch); + if (i != -1) { + emit dataChanged(createIndex(i, 0), createIndex(i, 0)); + } +} + int WatchesModel::findRowByWatchId(const QString &id) { QString pattern(_config->key() + "/" + id); @@ -134,3 +158,9 @@ int WatchesModel::findRowByWatchId(const QString &id) } return -1; } + +bool WatchesModel::isWatchIdActive(const QString &id) const +{ + QStringList active = _active_watches->value().toStringList(); + return active.contains(id); +} diff --git a/sowatchui/watchesmodel.h b/sowatchui/watchesmodel.h index cc6c9af..4962725 100644 --- a/sowatchui/watchesmodel.h +++ b/sowatchui/watchesmodel.h @@ -5,6 +5,8 @@ #include <sowatch.h> +#include "daemonproxy.h" + class WatchesModel : public QAbstractListModel { Q_OBJECT @@ -27,14 +29,18 @@ private slots: void reload(); void handleConfigChanged(); void handleSubkeyChanged(const QString& subkey); + void handleWatchStatusChanged(const QString& watch, const QString& status); private: int findRowByWatchId(const QString& id); + bool isWatchIdActive(const QString& id) const; private: sowatch::ConfigKey *_config; sowatch::ConfigKey *_active_watches; + DaemonProxy *_daemon; QList<sowatch::ConfigKey*> _list; + QMap<QString, QString> _status; }; #endif // WATCHESMODEL_H |