From 9e3eff1c3a2b7105fecf6d0d7f052eb9943fbada Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 14 May 2013 01:57:34 +0200 Subject: perform only one bluetooth discovery for all watches --- libsowatch/allwatchscanner.cpp | 2 ++ libsowatch/watchserver.h | 4 ---- libsowatchbt/bluetoothwatchscanner.cpp | 41 +++++++++++++++++++++++----------- libsowatchbt/bluetoothwatchscanner.h | 7 +++--- liveview/liveviewscanner.cpp | 1 - metawatch/metawatchscanner.cpp | 1 - qmafwwatchlet/qmafwwatchlet.cpp | 4 ++-- qmafwwatchlet/qmafwwatchletplugin.cpp | 10 +++++---- qmafwwatchlet/qmafwwatchletplugin.h | 2 +- qmapwatchlet/mapview.cpp | 10 +++++++++ qmapwatchlet/mapview.h | 2 +- qtc_packaging/debian_harmattan/rules | 2 +- 12 files changed, 54 insertions(+), 32 deletions(-) diff --git a/libsowatch/allwatchscanner.cpp b/libsowatch/allwatchscanner.cpp index 97f8454..b01ad05 100644 --- a/libsowatch/allwatchscanner.cpp +++ b/libsowatch/allwatchscanner.cpp @@ -23,6 +23,7 @@ AllWatchScanner::AllWatchScanner(QObject *parent) : void AllWatchScanner::start() { + _finishedCount = 0; if (_scanners.empty()) { emit finished(); } else { @@ -40,5 +41,6 @@ void AllWatchScanner::handleFinished() if (_finishedCount >= _scanners.length()) { qDebug() << "all finished"; emit finished(); + _finishedCount = 0; } } diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h index 06f4e4b..2abeb1b 100644 --- a/libsowatch/watchserver.h +++ b/libsowatch/watchserver.h @@ -23,7 +23,6 @@ class SOWATCH_EXPORT WatchServer : public QObject { Q_OBJECT Q_PROPERTY(Watch* watch READ watch CONSTANT) - Q_PROPERTY(QString nextWatchletButton READ nextWatchletButton WRITE setNextWatchletButton) Q_PROPERTY(Watchlet* idleWatchlet READ idleWatchlet WRITE setIdleWatchlet) Q_PROPERTY(Watchlet* notificationWatchlet READ notificationWatchlet WRITE setNotificationWatchlet) @@ -33,9 +32,6 @@ public: Watch* watch(); const Watch* watch() const; - QString nextWatchletButton() const; - void setNextWatchletButton(const QString& value); - Watchlet *idleWatchlet(); void setIdleWatchlet(Watchlet *watchlet); diff --git a/libsowatchbt/bluetoothwatchscanner.cpp b/libsowatchbt/bluetoothwatchscanner.cpp index eeae5f7..192da0d 100644 --- a/libsowatchbt/bluetoothwatchscanner.cpp +++ b/libsowatchbt/bluetoothwatchscanner.cpp @@ -6,26 +6,41 @@ QTM_USE_NAMESPACE using namespace sowatch; + +int BluetoothWatchScanner::_instances = 0; +QBluetoothServiceDiscoveryAgent *BluetoothWatchScanner::_agent = 0; + BluetoothWatchScanner::BluetoothWatchScanner(QObject *parent) : - WatchScanner(parent), - _agent(new QBluetoothServiceDiscoveryAgent(this)) + WatchScanner(parent) { - connect(_agent, SIGNAL(finished()), this, SIGNAL(finished())); - connect(_agent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), - this, SLOT(handleDiscoveredService(QBluetoothServiceInfo))); + if (_instances == 0) { + Q_ASSERT(!_agent); + _agent = new QBluetoothServiceDiscoveryAgent; + } + _instances++; + Q_ASSERT(_agent); } -void BluetoothWatchScanner::start() +BluetoothWatchScanner::~BluetoothWatchScanner() { - if (_agent->isActive()) { - _agent->stop(); + _instances--; + if (_instances == 0) { + delete _agent; + _agent = 0; } - _agent->start(); - qDebug() << "started bluetooth scan"; - emit started(); } -void BluetoothWatchScanner::setUuidFilter(const QBluetoothUuid & uuid) +void BluetoothWatchScanner::start() { - _agent->setUuidFilter(uuid); + Q_ASSERT(_agent); + connect(_agent, SIGNAL(finished()), this, SIGNAL(finished())); + connect(_agent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), + this, SLOT(handleDiscoveredService(QBluetoothServiceInfo))); + + if (!_agent->isActive()) { + qDebug() << "started bluetooth scan"; + _agent->start(); + } + + emit started(); } diff --git a/libsowatchbt/bluetoothwatchscanner.h b/libsowatchbt/bluetoothwatchscanner.h index 1ab974a..e2d78ef 100644 --- a/libsowatchbt/bluetoothwatchscanner.h +++ b/libsowatchbt/bluetoothwatchscanner.h @@ -19,17 +19,16 @@ class SOWATCHBT_EXPORT BluetoothWatchScanner : public WatchScanner public: BluetoothWatchScanner(QObject *parent); + ~BluetoothWatchScanner(); void start(); -protected: - void setUuidFilter(const QBluetoothUuid & uuid); - protected slots: virtual void handleDiscoveredService(const QBluetoothServiceInfo& info) = 0; private: - QBluetoothServiceDiscoveryAgent *_agent; + static int _instances; + static QBluetoothServiceDiscoveryAgent *_agent; }; } diff --git a/liveview/liveviewscanner.cpp b/liveview/liveviewscanner.cpp index 3aee19d..dbb47f3 100644 --- a/liveview/liveviewscanner.cpp +++ b/liveview/liveviewscanner.cpp @@ -9,7 +9,6 @@ using namespace sowatch; LiveViewScanner::LiveViewScanner(QObject *parent) : BluetoothWatchScanner(parent) { - setUuidFilter(QBluetoothUuid::SerialPort); } void LiveViewScanner::handleDiscoveredService(const QBluetoothServiceInfo &info) diff --git a/metawatch/metawatchscanner.cpp b/metawatch/metawatchscanner.cpp index 822f41e..49c4095 100644 --- a/metawatch/metawatchscanner.cpp +++ b/metawatch/metawatchscanner.cpp @@ -9,7 +9,6 @@ using namespace sowatch; MetaWatchScanner::MetaWatchScanner(QObject *parent) : BluetoothWatchScanner(parent) { - setUuidFilter(QBluetoothUuid::SerialPort); } void MetaWatchScanner::handleDiscoveredService(const QBluetoothServiceInfo &info) diff --git a/qmafwwatchlet/qmafwwatchlet.cpp b/qmafwwatchlet/qmafwwatchlet.cpp index 41cea2a..05d707b 100644 --- a/qmafwwatchlet/qmafwwatchlet.cpp +++ b/qmafwwatchlet/qmafwwatchlet.cpp @@ -7,7 +7,7 @@ using namespace sowatch; QMafwWatchlet::QMafwWatchlet(Watch* watch) : - DeclarativeWatchlet(server, "com.javispedro.sowatch.qmafw"), + DeclarativeWatchlet(watch, "com.javispedro.sowatch.qmafw"), _registry(MafwRegistry::instance()), _player(new QMafwWatchletPlayer(this)), _volumeControl(new QMafwWatchletVolumeControl(this)) @@ -24,7 +24,7 @@ QMafwWatchlet::QMafwWatchlet(Watch* watch) : context()->setContextProperty("player", _player); context()->setContextProperty("volumeControl", _volumeControl); - setSource(QUrl(SOWATCH_QML_DIR "/qmafwwatchlet/" + server->watch()->model() + ".qml")); + setSource(QUrl(SOWATCH_QML_DIR "/qmafwwatchlet/" + watch->model() + ".qml")); } void QMafwWatchlet::handleRendererAdded(const QString &uuid) diff --git a/qmafwwatchlet/qmafwwatchletplugin.cpp b/qmafwwatchlet/qmafwwatchletplugin.cpp index f2ec355..a2d7a1f 100644 --- a/qmafwwatchlet/qmafwwatchletplugin.cpp +++ b/qmafwwatchlet/qmafwwatchletplugin.cpp @@ -15,20 +15,22 @@ QStringList QMafwWatchletPlugin::watchlets() return l; } -WatchletPluginInterface::WatchletInfo QMafwWatchletPlugin::describeWatchlet(const QString &id) +WatchletPluginInterface::WatchletInfo QMafwWatchletPlugin::describeWatchlet(const QString &id, const QString &watchModel) { WatchletInfo info; if (id != "com.javispedro.sowatch.qmafw") return info; info.name = tr("Music player"); - info.icon = QUrl::fromLocalFile(SOWATCH_QML_DIR "/qmafwwatchlet/icon.png"); + info.phoneIcon = QUrl::fromLocalFile(SOWATCH_QML_DIR "/qmafwwatchlet/icon.png"); + info.icon = QUrl::fromLocalFile(SOWATCH_QML_DIR "/qmafwwatchlet/" + watchModel + "-icon.png"); + info.visible = true; return info; } -Watchlet* QMafwWatchletPlugin::getWatchlet(const QString &id, ConfigKey *config, WatchServer *server) +Watchlet* QMafwWatchletPlugin::getWatchlet(const QString &id, ConfigKey *config, Watch *watch) { Q_UNUSED(config); if (id != "com.javispedro.sowatch.qmafw") return 0; - return new QMafwWatchlet(server); + return new QMafwWatchlet(watch); } Q_EXPORT_PLUGIN2(qmafwwatchlet, QMafwWatchletPlugin) diff --git a/qmafwwatchlet/qmafwwatchletplugin.h b/qmafwwatchlet/qmafwwatchletplugin.h index b24dcff..7e99cf5 100644 --- a/qmafwwatchlet/qmafwwatchletplugin.h +++ b/qmafwwatchlet/qmafwwatchletplugin.h @@ -17,7 +17,7 @@ public: QStringList watchlets(); WatchletInfo describeWatchlet(const QString &id, const QString &watchModel); - Watchlet* getWatchlet(const QString &id, ConfigKey *config, WatchServer *server); + Watchlet* getWatchlet(const QString &id, ConfigKey *config, Watch *watch); }; } diff --git a/qmapwatchlet/mapview.cpp b/qmapwatchlet/mapview.cpp index 7e78d15..ce0e2b4 100644 --- a/qmapwatchlet/mapview.cpp +++ b/qmapwatchlet/mapview.cpp @@ -95,6 +95,16 @@ void MapView::setUpdateInterval(int msec) } } +bool MapView::decolor() const +{ + return _decolor; +} + +void MapView::setDecolor(bool decolor) +{ + _decolor = decolor; +} + qreal MapView::zoomLevel() const { if (_mapData) { diff --git a/qmapwatchlet/mapview.h b/qmapwatchlet/mapview.h index caa2730..93d8691 100644 --- a/qmapwatchlet/mapview.h +++ b/qmapwatchlet/mapview.h @@ -36,7 +36,7 @@ public: void setUpdateInterval(int msec); bool decolor() const; - void setDecolor(bool decolor) const; + void setDecolor(bool decolor); qreal zoomLevel() const; void setZoomLevel(qreal level); diff --git a/qtc_packaging/debian_harmattan/rules b/qtc_packaging/debian_harmattan/rules index 2460fe9..e6286ce 100755 --- a/qtc_packaging/debian_harmattan/rules +++ b/qtc_packaging/debian_harmattan/rules @@ -69,7 +69,7 @@ binary-arch: build install dh_fixperms # dh_makeshlibs # Uncomment this line for use without Qt Creator dh_installdeb - # dh_shlibdeps # Uncomment this line for use without Qt Creator + # dh_shlibdeps -l/opt/sowatch/lib # Uncomment this line for use without Qt Creator dh_gencontrol dh_md5sums dh_builddeb -- cgit v1.2.3