From c7c6a2c596637fd4942c7fb80341ca2ef7b47808 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Thu, 9 Aug 2012 16:38:56 +0200 Subject: moving scanner logic to ui, new icon --- libsowatch/allwatchscanner.cpp | 40 ++++++++++++++ libsowatch/allwatchscanner.h | 29 ++++++++++ libsowatch/libsowatch.pro | 2 + libsowatch/sowatch.h | 1 + sowatchd/allscanner.cpp | 40 -------------- sowatchd/allscanner.h | 29 ---------- sowatchd/main.cpp | 8 --- sowatchd/scanner.xml | 12 ----- sowatchd/scanneradaptor.cpp | 43 --------------- sowatchd/scanneradaptor.h | 55 ------------------- sowatchd/sowatchd.pro | 4 +- sowatchui/main.cpp | 6 +-- sowatchui/qml/MainPage.qml | 6 +++ sowatchui/qml/WatchPage.qml | 1 + sowatchui/qml/main.qml | 13 ----- sowatchui/scannerproxy.cpp | 26 --------- sowatchui/scannerproxy.h | 58 -------------------- sowatchui/scanwatchesmodel.cpp | 102 ----------------------------------- sowatchui/scanwatchesmodel.h | 49 ----------------- sowatchui/sowatch.svg | 115 ++++++++++------------------------------ sowatchui/sowatch64.png | Bin 3400 -> 3142 bytes sowatchui/sowatch80.png | Bin 4945 -> 3926 bytes sowatchui/sowatch_src.svg | 36 +++++++++++++ sowatchui/sowatchui.pro | 5 +- sowatchui/watchesmodel.cpp | 5 ++ sowatchui/watchscannermodel.cpp | 100 ++++++++++++++++++++++++++++++++++ sowatchui/watchscannermodel.h | 47 ++++++++++++++++ 27 files changed, 303 insertions(+), 529 deletions(-) create mode 100644 libsowatch/allwatchscanner.cpp create mode 100644 libsowatch/allwatchscanner.h delete mode 100644 sowatchd/allscanner.cpp delete mode 100644 sowatchd/allscanner.h delete mode 100644 sowatchd/scanner.xml delete mode 100644 sowatchd/scanneradaptor.cpp delete mode 100644 sowatchd/scanneradaptor.h delete mode 100644 sowatchui/scannerproxy.cpp delete mode 100644 sowatchui/scannerproxy.h delete mode 100644 sowatchui/scanwatchesmodel.cpp delete mode 100644 sowatchui/scanwatchesmodel.h create mode 100644 sowatchui/sowatch_src.svg create mode 100644 sowatchui/watchscannermodel.cpp create mode 100644 sowatchui/watchscannermodel.h diff --git a/libsowatch/allwatchscanner.cpp b/libsowatch/allwatchscanner.cpp new file mode 100644 index 0000000..8a49b86 --- /dev/null +++ b/libsowatch/allwatchscanner.cpp @@ -0,0 +1,40 @@ +#include "allwatchscanner.h" + +using namespace sowatch; + +AllWatchScanner::AllWatchScanner(QObject *parent) : + WatchScanner(parent), _finishedCount(0) +{ + QList plugins = Registry::registry()->getWatchPlugins(); + foreach (WatchPluginInterface* driver, plugins) { + WatchScanner* scanner = driver->getScanner(this); + if (scanner) { + _scanners += scanner; + connect(scanner, SIGNAL(finished()), this, SLOT(handleFinished())); + connect(scanner, SIGNAL(watchFound(QVariantMap)), + this, SIGNAL(watchFound(QVariantMap))); + } + } +} + +void AllWatchScanner::start() +{ + if (_scanners.empty()) { + emit finished(); + } else { + foreach (WatchScanner* scanner, _scanners) { + scanner->start(); + } + emit started(); + } +} + +void AllWatchScanner::handleFinished() +{ + qDebug() << "one finished"; + _finishedCount++; + if (_finishedCount >= _scanners.length()) { + qDebug() << "all finished"; + emit finished(); + } +} diff --git a/libsowatch/allwatchscanner.h b/libsowatch/allwatchscanner.h new file mode 100644 index 0000000..ac0baae --- /dev/null +++ b/libsowatch/allwatchscanner.h @@ -0,0 +1,29 @@ +#ifndef SOWATCH_ALLWATCHSCANNER_H +#define SOWATCH_ALLWATCHSCANNER_H + +#include +#include + +#include + +namespace sowatch +{ + +class AllWatchScanner : public WatchScanner +{ + Q_OBJECT +public: + explicit AllWatchScanner(QObject *parent = 0); + void start(); + +private: + QList _scanners; + int _finishedCount; + +private slots: + void handleFinished(); +}; + +} + +#endif // SOWATCH_ALLWATCHSCANNER_H diff --git a/libsowatch/libsowatch.pro b/libsowatch/libsowatch.pro index 7a5b8eb..1057a87 100644 --- a/libsowatch/libsowatch.pro +++ b/libsowatch/libsowatch.pro @@ -32,6 +32,7 @@ SOURCES += \ watchletplugininterface.cpp \ registry.cpp \ watchscanner.cpp \ + allwatchscanner.cpp \ configkey.cpp \ gconfkey.cpp @@ -54,6 +55,7 @@ HEADERS += \ watchletplugininterface.h \ registry.h \ watchscanner.h \ + allwatchscanner.h \ configkey.h \ gconfkey.h diff --git a/libsowatch/sowatch.h b/libsowatch/sowatch.h index efc5ee8..921e69c 100644 --- a/libsowatch/sowatch.h +++ b/libsowatch/sowatch.h @@ -23,5 +23,6 @@ #include "watchletplugininterface.h" #include "registry.h" +#include "allwatchscanner.h" #endif // SOWATCH_H diff --git a/sowatchd/allscanner.cpp b/sowatchd/allscanner.cpp deleted file mode 100644 index a3e7d33..0000000 --- a/sowatchd/allscanner.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "allscanner.h" - -using namespace sowatch; - -AllScanner::AllScanner(QObject *parent) : - WatchScanner(parent), _finishedCount(0) -{ - QList plugins = Registry::registry()->getWatchPlugins(); - foreach (WatchPluginInterface* driver, plugins) { - WatchScanner* scanner = driver->getScanner(this); - if (scanner) { - _scanners += scanner; - connect(scanner, SIGNAL(finished()), this, SLOT(handleFinished())); - connect(scanner, SIGNAL(watchFound(QVariantMap)), - this, SIGNAL(watchFound(QVariantMap))); - } - } -} - -void AllScanner::start() -{ - if (_scanners.empty()) { - emit finished(); - } else { - foreach (WatchScanner* scanner, _scanners) { - scanner->start(); - } - emit started(); - } -} - -void AllScanner::handleFinished() -{ - qDebug() << "one finished"; - _finishedCount++; - if (_finishedCount >= _scanners.length()) { - qDebug() << "all finished"; - emit finished(); - } -} diff --git a/sowatchd/allscanner.h b/sowatchd/allscanner.h deleted file mode 100644 index 6a7160f..0000000 --- a/sowatchd/allscanner.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef ALLSCANNER_H -#define ALLSCANNER_H - -#include -#include - -#include - -namespace sowatch -{ - -class AllScanner : public WatchScanner -{ - Q_OBJECT -public: - explicit AllScanner(QObject *parent = 0); - void start(); - -private: - QList _scanners; - int _finishedCount; - -private slots: - void handleFinished(); -}; - -} - -#endif // ALLSCANNER_H diff --git a/sowatchd/main.cpp b/sowatchd/main.cpp index 29eee28..2816830 100644 --- a/sowatchd/main.cpp +++ b/sowatchd/main.cpp @@ -4,9 +4,7 @@ #include #include "global.h" -#include "allscanner.h" #include "daemonadaptor.h" -#include "scanneradaptor.h" namespace sowatch { @@ -26,17 +24,11 @@ int main(int argc, char *argv[]) sowatch::daemon = new Daemon(&a); new DaemonAdaptor(sowatch::daemon); - AllScanner *scanner = new AllScanner(&a); - new ScannerAdaptor(scanner); QDBusConnection connection = QDBusConnection::sessionBus(); if (!connection.registerService("com.javispedro.sowatchd")) { qCritical("Could not register D-Bus service"); } - - if (!connection.registerObject("/com/javispedro/sowatch/allscanner", scanner)) { - qCritical("Could not register scanner object"); - } if (!connection.registerObject("/com/javispedro/sowatch/daemon", sowatch::daemon)) { qCritical("Could not register daemon object"); } diff --git a/sowatchd/scanner.xml b/sowatchd/scanner.xml deleted file mode 100644 index 948ce0b..0000000 --- a/sowatchd/scanner.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/sowatchd/scanneradaptor.cpp b/sowatchd/scanneradaptor.cpp deleted file mode 100644 index a3d9ad1..0000000 --- a/sowatchd/scanneradaptor.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -c ScannerAdaptor -a scanneradaptor scanner.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. - */ - -#include "scanneradaptor.h" -#include -#include -#include -#include -#include -#include -#include - -/* - * Implementation of adaptor class ScannerAdaptor - */ - -ScannerAdaptor::ScannerAdaptor(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ - // constructor - connect(parent, SIGNAL(started()), this, SIGNAL(Started())); - connect(parent, SIGNAL(finished()), this, SIGNAL(Finished())); - connect(parent, SIGNAL(watchFound(QVariantMap)), - this, SIGNAL(WatchFound(QVariantMap))); -} - -ScannerAdaptor::~ScannerAdaptor() -{ - // destructor -} - -void ScannerAdaptor::Start() -{ - // handle method call com.javispedro.sowatch.WatchScanner.Start - QMetaObject::invokeMethod(parent(), "start"); -} diff --git a/sowatchd/scanneradaptor.h b/sowatchd/scanneradaptor.h deleted file mode 100644 index 17ffe54..0000000 --- a/sowatchd/scanneradaptor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -c ScannerAdaptor -a scanneradaptor scanner.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. - */ - -#ifndef SCANNERADAPTOR_H_1335303169 -#define SCANNERADAPTOR_H_1335303169 - -#include -#include -class QByteArray; -template class QList; -template class QMap; -class QString; -class QStringList; -class QVariant; - -/* - * Adaptor class for interface com.javispedro.sowatch.WatchScanner - */ -class ScannerAdaptor: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "com.javispedro.sowatch.WatchScanner") - Q_CLASSINFO("D-Bus Introspection", "" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" - "") -public: - ScannerAdaptor(QObject *parent); - virtual ~ScannerAdaptor(); - -public: // PROPERTIES -public Q_SLOTS: // METHODS - void Start(); -Q_SIGNALS: // SIGNALS - void Finished(); - void Started(); - void WatchFound(const QVariantMap &info); -}; - -#endif diff --git a/sowatchd/sowatchd.pro b/sowatchd/sowatchd.pro index 0794c2c..4b1b668 100644 --- a/sowatchd/sowatchd.pro +++ b/sowatchd/sowatchd.pro @@ -5,8 +5,8 @@ TEMPLATE = app QT += core gui dbus CONFIG -= app_bundle -SOURCES += main.cpp daemon.cpp allscanner.cpp scanneradaptor.cpp daemonadaptor.cpp -HEADERS += global.h daemon.h allscanner.h scanneradaptor.h daemonadaptor.h +SOURCES += main.cpp daemon.cpp daemonadaptor.cpp +HEADERS += global.h daemon.h daemonadaptor.h LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch INCLUDEPATH += $$PWD/../libsowatch diff --git a/sowatchui/main.cpp b/sowatchui/main.cpp index ea4a172..f8c58af 100644 --- a/sowatchui/main.cpp +++ b/sowatchui/main.cpp @@ -4,11 +4,11 @@ #include #include "watchesmodel.h" -#include "scanwatchesmodel.h" +#include "watchscannermodel.h" static sowatch::Registry *registry; static WatchesModel *watches; -static ScanWatchesModel *watchScanner; +static WatchScannerModel *watchScanner; Q_DECL_EXPORT int main(int argc, char *argv[]) { @@ -17,7 +17,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) registry = sowatch::Registry::registry(); watches = new WatchesModel(app.data()); - watchScanner = new ScanWatchesModel(app.data()); + watchScanner = new WatchScannerModel(app.data()); qDebug() << "Starting" << watches << endl; diff --git a/sowatchui/qml/MainPage.qml b/sowatchui/qml/MainPage.qml index b660161..d722b3d 100644 --- a/sowatchui/qml/MainPage.qml +++ b/sowatchui/qml/MainPage.qml @@ -6,6 +6,7 @@ Page { id: mainPage anchors.leftMargin: UiConstants.DefaultMargin anchors.rightMargin: UiConstants.DefaultMargin + orientationLock: PageOrientation.LockPortrait tools: ToolBarLayout { ToolIcon { @@ -30,6 +31,11 @@ Page { anchors.right: parent.right; anchors.verticalCenter: parent.verticalCenter } + + onClicked: { + var page = Qt.createComponent("WatchPage.qml"); + pageStack.push(page); + } } } ScrollDecorator { diff --git a/sowatchui/qml/WatchPage.qml b/sowatchui/qml/WatchPage.qml index fb7011c..8159834 100644 --- a/sowatchui/qml/WatchPage.qml +++ b/sowatchui/qml/WatchPage.qml @@ -6,6 +6,7 @@ Page { id: watchPage anchors.leftMargin: UiConstants.DefaultMargin anchors.rightMargin: UiConstants.DefaultMargin + orientationLock: PageOrientation.LockPortrait tools: ToolBarLayout { ToolIcon { diff --git a/sowatchui/qml/main.qml b/sowatchui/qml/main.qml index ca838a2..0fd3ad0 100644 --- a/sowatchui/qml/main.qml +++ b/sowatchui/qml/main.qml @@ -9,17 +9,4 @@ PageStackWindow { MainPage { id: mainPage } - - Menu { - id: myMenu - visualParent: pageStack - MenuLayout { - MenuItem { - text: qsTr("Crap") - onClicked: { - console.log("Crap") - } - } - } - } } diff --git a/sowatchui/scannerproxy.cpp b/sowatchui/scannerproxy.cpp deleted file mode 100644 index cfa4365..0000000 --- a/sowatchui/scannerproxy.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -c ScannerProxy -p scannerproxy ../sowatchd/scanner.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 "scannerproxy.h" - -/* - * Implementation of interface class ScannerProxy - */ - -ScannerProxy::ScannerProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) - : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) -{ -} - -ScannerProxy::~ScannerProxy() -{ -} - diff --git a/sowatchui/scannerproxy.h b/sowatchui/scannerproxy.h deleted file mode 100644 index 3b1b9c8..0000000 --- a/sowatchui/scannerproxy.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -c ScannerProxy -p scannerproxy ../sowatchd/scanner.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 SCANNERPROXY_H_1344446154 -#define SCANNERPROXY_H_1344446154 - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Proxy class for interface com.javispedro.sowatch.WatchScanner - */ -class ScannerProxy: public QDBusAbstractInterface -{ - Q_OBJECT -public: - static inline const char *staticInterfaceName() - { return "com.javispedro.sowatch.WatchScanner"; } - -public: - ScannerProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); - - ~ScannerProxy(); - -public Q_SLOTS: // METHODS - inline QDBusPendingReply<> Start() - { - QList argumentList; - return asyncCallWithArgumentList(QLatin1String("Start"), argumentList); - } - -Q_SIGNALS: // SIGNALS - void Finished(); - void Started(); - void WatchFound(const QVariantMap &info); -}; - -namespace com { - namespace javispedro { - namespace sowatch { - typedef ::ScannerProxy WatchScanner; - } - } -} -#endif diff --git a/sowatchui/scanwatchesmodel.cpp b/sowatchui/scanwatchesmodel.cpp deleted file mode 100644 index 5b7c331..0000000 --- a/sowatchui/scanwatchesmodel.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include - -#include "scanwatchesmodel.h" - -ScanWatchesModel::ScanWatchesModel(QObject *parent) : - QAbstractListModel(parent), - _scanner(new ScannerProxy("com.javispedro.sowatchd", "/com/javispedro/sowatch/allscanner", QDBusConnection::sessionBus())), - _timer(new QTimer(this)), - _enabled(false), _active(false) -{ - QHash roles = roleNames(); - roles[Qt::DisplayRole] = QByteArray("title"); - roles[Qt::StatusTipRole] = QByteArray("subtitle"); - roles[ObjectRole] = QByteArray("object"); - setRoleNames(roles); - - _timer->setSingleShot(true); - _timer->setInterval(3000); - - connect(_scanner, SIGNAL(WatchFound(QVariantMap)), SLOT(handleWatchFound(QVariantMap))); - connect(_scanner, SIGNAL(Started()), SLOT(handleStarted())); - connect(_scanner, SIGNAL(Finished()), SLOT(handleFinished())); - connect(_timer, SIGNAL(timeout()), SLOT(handleTimeout())); -} - -ScanWatchesModel::~ScanWatchesModel() -{ -} - -bool ScanWatchesModel::enabled() const -{ - return _enabled; -} - -void ScanWatchesModel::setEnabled(bool enabled) -{ - _timer->stop(); - - _enabled = enabled; - - if (_enabled && !_active) { - _scanner->Start(); - } -} - -bool ScanWatchesModel::active() const -{ - return _active; -} - -int ScanWatchesModel::rowCount(const QModelIndex &parent) const -{ - return _list.count(); -} - -QVariant ScanWatchesModel::data(const QModelIndex &index, int role) const -{ - qDebug() << "Asked for data" << index.row() << index.column() << role; - const QVariantMap &info = _list.at(index.row()); - switch (role) { - case Qt::DisplayRole: - return info["name"]; - case Qt::StatusTipRole: - return info["address"]; - case ObjectRole: - return QVariant::fromValue(info); - } - return QVariant(); -} - -void ScanWatchesModel::handleWatchFound(const QVariantMap &info) -{ - qDebug() << "Watch found" << info << endl; - if (!_list.contains(info)) { - int count = _list.count(); - beginInsertRows(QModelIndex(), count, count); - _list.append(info); - endInsertRows(); - } -} - -void ScanWatchesModel::handleStarted() -{ - _active = true; - emit activeChanged(); -} - -void ScanWatchesModel::handleFinished() -{ - qDebug() << "Scan finished"; - _active = false; - if (_enabled) { - _timer->start(); - } - emit activeChanged(); -} - -void ScanWatchesModel::handleTimeout() -{ - qDebug() << "Restarting scan"; - _scanner->Start(); -} diff --git a/sowatchui/scanwatchesmodel.h b/sowatchui/scanwatchesmodel.h deleted file mode 100644 index 424ded4..0000000 --- a/sowatchui/scanwatchesmodel.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef SCANWATCHESMODEL_H -#define SCANWATCHESMODEL_H - -#include -#include -#include - -#include "scannerproxy.h" - -class ScanWatchesModel : public QAbstractListModel -{ - Q_OBJECT - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) - Q_PROPERTY(bool active READ active NOTIFY activeChanged) - -public: - explicit ScanWatchesModel(QObject *parent = 0); - ~ScanWatchesModel(); - - enum DataRoles { - ObjectRole = Qt::UserRole - }; - - bool enabled() const; - void setEnabled(bool enabled); - - bool active() const; - - int rowCount(const QModelIndex &parent) const; - QVariant data(const QModelIndex &index, int role) const; - -signals: - void activeChanged(); - -private slots: - void handleWatchFound(const QVariantMap& info); - void handleStarted(); - void handleFinished(); - void handleTimeout(); - -private: - ScannerProxy *_scanner; - QList _list; - QTimer *_timer; - bool _enabled; - bool _active; -}; - -#endif // SCANWATCHESMODEL_H diff --git a/sowatchui/sowatch.svg b/sowatchui/sowatch.svg index 566acfa..f2385c4 100644 --- a/sowatchui/sowatch.svg +++ b/sowatchui/sowatch.svg @@ -1,93 +1,34 @@ - - - + + + + + + + + + + + + + + + + + + + + + + - + image/svg+xml - + + - - - - - - - - - - - - + + - + diff --git a/sowatchui/sowatch64.png b/sowatchui/sowatch64.png index 707d5c4..520e068 100644 Binary files a/sowatchui/sowatch64.png and b/sowatchui/sowatch64.png differ diff --git a/sowatchui/sowatch80.png b/sowatchui/sowatch80.png index 6ad8096..7b38390 100644 Binary files a/sowatchui/sowatch80.png and b/sowatchui/sowatch80.png differ diff --git a/sowatchui/sowatch_src.svg b/sowatchui/sowatch_src.svg new file mode 100644 index 0000000..2975252 --- /dev/null +++ b/sowatchui/sowatch_src.svg @@ -0,0 +1,36 @@ + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sowatchui/sowatchui.pro b/sowatchui/sowatchui.pro index 53abe73..93a2438 100644 --- a/sowatchui/sowatchui.pro +++ b/sowatchui/sowatchui.pro @@ -28,16 +28,17 @@ DEPENDPATH += $$PWD/../libsowatch # Source files SOURCES += main.cpp \ watchesmodel.cpp daemonproxy.cpp \ - scanwatchesmodel.cpp scannerproxy.cpp + watchscannermodel.cpp HEADERS += \ watchesmodel.h daemonproxy.h \ - scanwatchesmodel.h scannerproxy.h + watchscannermodel.h OTHER_FILES += qml/main.qml \ qml/MainPage.qml \ qml/NewWatchSheet.qml \ qml/WatchPage.qml \ + sowatch.svg sowatch_src.svg sowatch64.png sowatch80.png \ sowatch_harmattan.desktop \ sowatch.desktop diff --git a/sowatchui/watchesmodel.cpp b/sowatchui/watchesmodel.cpp index 4531544..5644466 100644 --- a/sowatchui/watchesmodel.cpp +++ b/sowatchui/watchesmodel.cpp @@ -97,9 +97,14 @@ void WatchesModel::reload() foreach (ConfigKey* conf, _list) { conf->deleteLater(); } + _status.clear(); _list.clear(); foreach (const QString& s, dirs) { _list.append(_config->getSubkey(s, this)); + QDBusReply reply = _daemon->GetWatchStatus(s); + if (reply.isValid()) { + _status[s] = reply.value(); + } } endResetModel(); diff --git a/sowatchui/watchscannermodel.cpp b/sowatchui/watchscannermodel.cpp new file mode 100644 index 0000000..2f58523 --- /dev/null +++ b/sowatchui/watchscannermodel.cpp @@ -0,0 +1,100 @@ +#include "watchscannermodel.h" + +WatchScannerModel::WatchScannerModel(QObject *parent) : + QAbstractListModel(parent), + _scanner(new sowatch::AllWatchScanner(this)), + _timer(new QTimer(this)), + _enabled(false), _active(false) +{ + QHash roles = roleNames(); + roles[Qt::DisplayRole] = QByteArray("title"); + roles[Qt::StatusTipRole] = QByteArray("subtitle"); + roles[ObjectRole] = QByteArray("object"); + setRoleNames(roles); + + _timer->setSingleShot(true); + _timer->setInterval(3000); + + connect(_scanner, SIGNAL(watchFound(QVariantMap)), SLOT(handleWatchFound(QVariantMap))); + connect(_scanner, SIGNAL(started()), SLOT(handleStarted())); + connect(_scanner, SIGNAL(finished()), SLOT(handleFinished())); + connect(_timer, SIGNAL(timeout()), SLOT(handleTimeout())); +} + +WatchScannerModel::~WatchScannerModel() +{ +} + +bool WatchScannerModel::enabled() const +{ + return _enabled; +} + +void WatchScannerModel::setEnabled(bool enabled) +{ + _timer->stop(); + + _enabled = enabled; + + if (_enabled && !_active) { + _scanner->start(); + } +} + +bool WatchScannerModel::active() const +{ + return _active; +} + +int WatchScannerModel::rowCount(const QModelIndex &parent) const +{ + return _list.count(); +} + +QVariant WatchScannerModel::data(const QModelIndex &index, int role) const +{ + qDebug() << "Asked for data" << index.row() << index.column() << role; + const QVariantMap &info = _list.at(index.row()); + switch (role) { + case Qt::DisplayRole: + return info["name"]; + case Qt::StatusTipRole: + return info["address"]; + case ObjectRole: + return QVariant::fromValue(info); + } + return QVariant(); +} + +void WatchScannerModel::handleWatchFound(const QVariantMap &info) +{ + qDebug() << "Watch found" << info << endl; + if (!_list.contains(info)) { + int count = _list.count(); + beginInsertRows(QModelIndex(), count, count); + _list.append(info); + endInsertRows(); + } +} + +void WatchScannerModel::handleStarted() +{ + _active = true; + emit activeChanged(); +} + +void WatchScannerModel::handleFinished() +{ + qDebug() << "Scan finished"; + _active = false; + if (_enabled) { + _timer->start(); + } + emit activeChanged(); +} + +void WatchScannerModel::handleTimeout() +{ + qDebug() << "Restarting scan"; + _scanner->start(); +} diff --git a/sowatchui/watchscannermodel.h b/sowatchui/watchscannermodel.h new file mode 100644 index 0000000..32701f7 --- /dev/null +++ b/sowatchui/watchscannermodel.h @@ -0,0 +1,47 @@ +#ifndef WATCHSCANNERMODEL_H +#define WATCHSCANNERMODEL_H + +#include + +#include + +class WatchScannerModel : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) + Q_PROPERTY(bool active READ active NOTIFY activeChanged) + +public: + explicit WatchScannerModel(QObject *parent = 0); + ~WatchScannerModel(); + + enum DataRoles { + ObjectRole = Qt::UserRole + }; + + bool enabled() const; + void setEnabled(bool enabled); + + bool active() const; + + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + +signals: + void activeChanged(); + +private slots: + void handleWatchFound(const QVariantMap& info); + void handleStarted(); + void handleFinished(); + void handleTimeout(); + +private: + sowatch::WatchScanner *_scanner; + QList _list; + QTimer *_timer; + bool _enabled; + bool _active; +}; + +#endif // WATCHSCANNERMODEL_H -- cgit v1.2.3