From 12cf6df3f1c90c6ccbab398f0ae03c946e4af638 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 5 May 2013 03:18:46 +0200 Subject: continue working on qml watchface support --- libsowatch/watchletplugininterface.h | 6 ++ libsowatch/watchserver.cpp | 126 +++++++++++++++++++++++------------ libsowatch/watchserver.h | 11 +-- 3 files changed, 97 insertions(+), 46 deletions(-) (limited to 'libsowatch') diff --git a/libsowatch/watchletplugininterface.h b/libsowatch/watchletplugininterface.h index 5e99605..ed90467 100644 --- a/libsowatch/watchletplugininterface.h +++ b/libsowatch/watchletplugininterface.h @@ -22,7 +22,13 @@ public: struct WatchletInfo { QString name; QUrl icon; + bool hidden; QUrl configQmlUrl; + + inline WatchletInfo() : + hidden(false) + { + } }; virtual QStringList watchlets() = 0; diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index d3328df..6448508 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -8,12 +8,12 @@ using namespace sowatch; WatchServer::WatchServer(Watch* watch, QObject* parent) : - QObject(parent), _watch(watch), - _nextWatchletButton(-1), - _oldNotificationThreshold(300), + QObject(parent), _watch(watch), + _nextWatchletButton(-1), _idleWatchlet(0), _notificationWatchlet(0), + _oldNotificationThreshold(300), _notifications(new NotificationsModel(this)), - _currentWatchlet(0), _currentWatchletActive(false), _currentWatchletIndex(-1), - _syncTimeTimer(new QTimer(this)) + _activeWatchlet(0), _currentWatchlet(0), _currentWatchletIndex(-1), + _syncTimeTimer(new QTimer(this)) { connect(_watch, SIGNAL(connected()), SLOT(handleWatchConnected())); connect(_watch, SIGNAL(disconnected()), SLOT(handleWatchDisconnected())); @@ -56,6 +56,39 @@ void WatchServer::setNextWatchletButton(const QString& value) } } +Watchlet * WatchServer::idleWatchlet() +{ + return _idleWatchlet; +} + +void WatchServer::setIdleWatchlet(Watchlet *watchlet) +{ + if (_idleWatchlet) { + removeWatchlet(_idleWatchlet); + } + _idleWatchlet = watchlet; + if (watchlet) { + _watchletIds[watchlet->id()] = watchlet; + } +} + +Watchlet * WatchServer::notificationWatchlet() +{ + return _notificationWatchlet; +} + +void WatchServer::setNotificationWatchlet(Watchlet *watchlet) +{ + if (_notificationWatchlet) { + removeWatchlet(_notificationWatchlet); + } + _notificationWatchlet = watchlet; + if (watchlet) { + _watchletIds[watchlet->id()] = watchlet; + // TODO Possibly activate this watchlet now if we are on the idle screen. + } +} + void WatchServer::addWatchlet(Watchlet *watchlet) { Q_ASSERT(watchlet); @@ -168,12 +201,12 @@ void WatchServer::nextNotification() if (!_watch->isConnected()) return; if (!_pendingNotifications.empty()) { Notification *n = _pendingNotifications.head(); - if (_currentWatchlet && _currentWatchletActive) { - deactivateCurrentWatchlet(); + if (_activeWatchlet) { + deactivateActiveWatchlet(); } _watch->displayNotification(n); } else if (_currentWatchlet) { - reactivateCurrentWatchlet(); + activateCurrentWatchlet(); } else { goToIdle(); } @@ -182,12 +215,12 @@ void WatchServer::nextNotification() void WatchServer::runWatchlet(Watchlet *watchlet) { Q_ASSERT(watchlet->watch() == _watch); - if (_currentWatchlet && _currentWatchletActive) { - deactivateCurrentWatchlet(); + if (_activeWatchlet) { + deactivateActiveWatchlet(); } _currentWatchlet = watchlet; if (_watch->isConnected()) { - reactivateCurrentWatchlet(); + activateCurrentWatchlet(); } } @@ -200,8 +233,8 @@ void WatchServer::runWatchlet(const QString& id) void WatchServer::closeWatchlet() { if (_currentWatchlet) { - if (_currentWatchletActive) { - deactivateCurrentWatchlet(); + if (_currentWatchlet == _activeWatchlet) { + deactivateActiveWatchlet(); } _currentWatchlet = 0; if (_watch->isConnected() && _pendingNotifications.empty()) { @@ -210,23 +243,43 @@ void WatchServer::closeWatchlet() } } -void WatchServer::deactivateCurrentWatchlet() +void WatchServer::setWatchletProperties(Watchlet *watchlet) { - Q_ASSERT(_currentWatchlet != 0); - Q_ASSERT(_currentWatchletActive); - qDebug() << "deactivating watchlet" << _currentWatchlet->id(); - _currentWatchlet->deactivate(); - _currentWatchletActive = false; + Q_ASSERT(watchlet->watch() == _watch); + watchlet->setNotificationsModel(_notifications); } -void WatchServer::reactivateCurrentWatchlet() +void WatchServer::unsetWatchletProperties(Watchlet *watchlet) { - Q_ASSERT(_currentWatchlet != 0); - Q_ASSERT(!_currentWatchletActive); - qDebug() << "activating watchlet" << _currentWatchlet->id(); + Q_ASSERT(watchlet->watch() == _watch); + watchlet->setNotificationsModel(0); +} + +void WatchServer::activateWatchlet(Watchlet *watchlet) +{ + Q_ASSERT(!_activeWatchlet); + + qDebug() << "activating watchlet" << watchlet->id(); + _activeWatchlet = watchlet; + _activeWatchlet->activate(); +} + +void WatchServer::deactivateActiveWatchlet() +{ + Q_ASSERT(_activeWatchlet); + + qDebug() << "deactivating watchlet" << _activeWatchlet->id(); + _activeWatchlet->deactivate(); + _activeWatchlet = 0; +} + +void WatchServer::activateCurrentWatchlet() +{ + Q_ASSERT(_currentWatchlet); + Q_ASSERT(!_activeWatchlet); + _watch->displayApplication(); - _currentWatchlet->activate(); - _currentWatchletActive = true; + activateWatchlet(_currentWatchlet); } void WatchServer::nextWatchlet() @@ -282,22 +335,13 @@ void WatchServer::removeNotification(Notification::Type type, Notification *n) disconnect(n, 0, this, 0); } -void WatchServer::setWatchletProperties(Watchlet *watchlet) -{ - Q_ASSERT(watchlet->watch() == _watch); - watchlet->setNotificationsModel(_notifications); -} - -void WatchServer::unsetWatchletProperties(Watchlet *watchlet) -{ - Q_ASSERT(watchlet->watch() == _watch); - watchlet->setNotificationsModel(0); -} - void WatchServer::goToIdle() { - Q_ASSERT(!_currentWatchletActive); + Q_ASSERT(!_currentWatchlet && !_activeWatchlet); _watch->displayIdleScreen(); + if (_idleWatchlet) { + activateWatchlet(_idleWatchlet); + } } void WatchServer::handleWatchConnected() @@ -306,7 +350,7 @@ void WatchServer::handleWatchConnected() if (!_pendingNotifications.isEmpty()) { nextNotification(); } else if (_currentWatchlet) { - reactivateCurrentWatchlet(); + activateCurrentWatchlet(); } else { goToIdle(); } @@ -316,8 +360,8 @@ void WatchServer::handleWatchConnected() void WatchServer::handleWatchDisconnected() { _syncTimeTimer->stop(); - if (_currentWatchlet && _currentWatchletActive) { - deactivateCurrentWatchlet(); + if (_activeWatchlet) { + deactivateActiveWatchlet(); } _pendingNotifications.clear(); emit watchDisconnected(); diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h index 30f39c6..eafee7a 100644 --- a/libsowatch/watchserver.h +++ b/libsowatch/watchserver.h @@ -94,10 +94,10 @@ private: /** We store a currently live weather forecast. */ WeatherNotification* _weather; - /** Current watchlet. */ + /** Active watchlet is the one that has "focus" right now. */ + Watchlet* _activeWatchlet; + /** Current watchlet is the app watchlet (not idle, not notification) that is current in the carrousel. */ Watchlet* _currentWatchlet; - /** Is the current watchlet active? */ - bool _currentWatchletActive; /** The current watchlet index if any, for use by nextWatchlet() */ int _currentWatchletIndex; @@ -111,8 +111,9 @@ private: void setWatchletProperties(Watchlet *watchlet); void unsetWatchletProperties(Watchlet *watchlet); - void deactivateCurrentWatchlet(); - void reactivateCurrentWatchlet(); + void activateWatchlet(Watchlet *watchlet); + void deactivateActiveWatchlet(); + void activateCurrentWatchlet(); void goToIdle(); private slots: -- cgit v1.2.3