diff options
Diffstat (limited to 'libsowatch')
-rw-r--r-- | libsowatch/libsowatch.pro | 8 | ||||
-rw-r--r-- | libsowatch/sowatch.h | 1 | ||||
-rw-r--r-- | libsowatch/watch.h | 33 | ||||
-rw-r--r-- | libsowatch/watchletplugininterface.cpp | 7 | ||||
-rw-r--r-- | libsowatch/watchletplugininterface.h | 28 | ||||
-rw-r--r-- | libsowatch/watchserver.cpp | 81 | ||||
-rw-r--r-- | libsowatch/watchserver.h | 11 |
7 files changed, 149 insertions, 20 deletions
diff --git a/libsowatch/libsowatch.pro b/libsowatch/libsowatch.pro index aefdadd..44458c2 100644 --- a/libsowatch/libsowatch.pro +++ b/libsowatch/libsowatch.pro @@ -27,7 +27,8 @@ SOURCES += \ watchplugininterface.cpp \ notification.cpp \ notificationplugininterface.cpp \ - notificationprovider.cpp + notificationprovider.cpp \ + watchletplugininterface.cpp HEADERS +=\ watchsimulator.h \ @@ -45,7 +46,8 @@ HEADERS +=\ watchplugininterface.h \ notification.h \ notificationplugininterface.h \ - notificationprovider.h + notificationprovider.h \ + watchletplugininterface.h install_headers.files = $$HEADERS @@ -89,3 +91,5 @@ unix:!symbian { + + diff --git a/libsowatch/sowatch.h b/libsowatch/sowatch.h index e294ece..d8844bc 100644 --- a/libsowatch/sowatch.h +++ b/libsowatch/sowatch.h @@ -15,5 +15,6 @@ #include "watchlet.h" #include "graphicswatchlet.h" #include "declarativewatchlet.h" +#include "watchletplugininterface.h" #endif // SOWATCH_H diff --git a/libsowatch/watch.h b/libsowatch/watch.h index eabfa06..ee9bde7 100644 --- a/libsowatch/watch.h +++ b/libsowatch/watch.h @@ -3,6 +3,7 @@ #include <QtCore/QObject> #include <QtCore/QDateTime> +#include <QtCore/QStringList> #include <QtGui/QPaintDevice> #include <QtGui/QImage> #include "notification.h" @@ -21,18 +22,34 @@ public: explicit Watch(QObject* parent = 0); ~Watch(); - /** Return a string identiyfying this watch's model. */ + /** Return a string identifying this watch's model. */ virtual QString model() const = 0; + + /** Names for all the buttons this watch has. Order is important. */ + virtual QStringList buttons() const = 0; + /** Should return true if the watch is connected. */ virtual bool isConnected() const = 0; - /** Indicates if watch is too busy atm and we should limit frame rate. */ virtual bool busy() const = 0; - /** Changes the current date/time on the watch. */ + /** Gets the current date/time on the watch. */ virtual QDateTime dateTime() = 0; + /** Sets the current date/time on the watch. */ virtual void setDateTime(const QDateTime& dateTime) = 0; + /** Go back to the idle screen. */ + virtual void displayIdleScreen() = 0; + /** A standard notification; it's up to the watch when to stop showing it. */ + virtual void displayNotification(Notification* n) = 0; + /** Enter application mode. */ + virtual void displayApplication() = 0; + + /** Grabs a button from whatever is default function is for the current mode. */ + virtual void grabButton(int button) = 0; + /** Restores a button to its default function. */ + virtual void ungrabButton(int button) = 0; + /** Tells the watch to update the unread notifications count, if visible. */ virtual void updateNotificationCount(Notification::Type type, int count) = 0; @@ -43,16 +60,10 @@ signals: void disconnected(); /** The watch has returned to the idle screen by either inactivity or notification cleared/timeout. */ void idling(); + /** A button has been pressed. */ void buttonPressed(int button); + /** A button has been pressed and then released. */ void buttonReleased(int button); - -public slots: - /** Go back to the idle screen. */ - virtual void displayIdleScreen() = 0; - /** A standard notification; it's up to the watch when to stop showing it. */ - virtual void displayNotification(Notification* n) = 0; - /** Enter application mode. */ - virtual void displayApplication() = 0; }; } diff --git a/libsowatch/watchletplugininterface.cpp b/libsowatch/watchletplugininterface.cpp new file mode 100644 index 0000000..c575236 --- /dev/null +++ b/libsowatch/watchletplugininterface.cpp @@ -0,0 +1,7 @@ +#include "watchletplugininterface.h" + +using namespace sowatch; + +WatchletPluginInterface::~WatchletPluginInterface() +{ +} diff --git a/libsowatch/watchletplugininterface.h b/libsowatch/watchletplugininterface.h new file mode 100644 index 0000000..ad83dd4 --- /dev/null +++ b/libsowatch/watchletplugininterface.h @@ -0,0 +1,28 @@ +#ifndef SOWATCH_WATCHLETPLUGININTERFACE_H +#define SOWATCH_WATCHLETPLUGININTERFACE_H + +#include <QtPlugin> +#include <QtCore/QSettings> +#include <QtCore/QStringList> +#include "sowatch_global.h" + +namespace sowatch +{ + +class Watchlet; +class WatchServer; + +class SOWATCH_EXPORT WatchletPluginInterface +{ +public: + virtual ~WatchletPluginInterface(); + + virtual QStringList watchlets() = 0; + virtual Watchlet* getProvider(const QString& id, QSettings& settings, WatchServer *server) = 0; +}; + +} + +Q_DECLARE_INTERFACE(sowatch::WatchletPluginInterface, "com.javispedro.sowatch.WatchletPluginInterface") + +#endif // SOWATCH_WATCHLETPLUGININTERFACE_H diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index d95d4fb..39802f9 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -9,11 +9,14 @@ using namespace sowatch; WatchServer::WatchServer(Watch* watch, QObject* parent) : - QObject(parent), _watch(watch), _currentWatchlet(0) + QObject(parent), _watch(watch), + _nextWatchletButton(-1), + _currentWatchlet(0), _currentWatchletIndex(-1) { connect(_watch, SIGNAL(connected()), SLOT(watchConnected())); connect(_watch, SIGNAL(disconnected()), SLOT(watchDisconnected())); connect(_watch, SIGNAL(idling()), SLOT(watchIdling())); + connect(_watch, SIGNAL(buttonPressed(int)), SLOT(watchButtonPress(int))); } Watch* WatchServer::watch() @@ -21,6 +24,27 @@ Watch* WatchServer::watch() return _watch; } +QString WatchServer::nextWatchletButton() const +{ + if (_nextWatchletButton >= 0) { + return _watch->buttons().at(_nextWatchletButton); + } else { + return QString(); + } +} + +void WatchServer::setNextWatchletButton(const QString& value) +{ + if (value.isEmpty()) { + _nextWatchletButton = -1; + return; + } + _nextWatchletButton = _watch->buttons().indexOf(value); + if (_nextWatchletButton < 0) { + qWarning() << "Invalid watch button" << value; + } +} + void WatchServer::addProvider(NotificationProvider *provider) { provider->setParent(this); @@ -33,6 +57,7 @@ void WatchServer::runWatchlet(const QString& id) if (_currentWatchlet) { closeWatchlet(); } + qDebug() << "activating watchlet" << id; _currentWatchlet = _watchlets[id]; if (_watch->isConnected()) { reactivateCurrentWatchlet(); @@ -41,11 +66,15 @@ void WatchServer::runWatchlet(const QString& id) void WatchServer::closeWatchlet() { - Q_ASSERT(_currentWatchlet != 0); - if (_watch->isConnected()) { - _currentWatchlet->deactivate(); + if (_currentWatchlet) { + if (_watch->isConnected()) { + _currentWatchlet->deactivate(); + } + _currentWatchlet = 0; + if (_pendingNotifications.empty()) { + goToIdle(); + } } - _currentWatchlet = 0; } void WatchServer::registerWatchlet(Watchlet *watchlet) @@ -61,6 +90,20 @@ void WatchServer::reactivateCurrentWatchlet() _currentWatchlet->activate(); } +void WatchServer::nextWatchlet() +{ + QStringList watchlets = _watchlets.keys(); + _currentWatchletIndex++; + qDebug() << "next watchlet" << _currentWatchletIndex; + if (_currentWatchletIndex >= watchlets.size()) { + _currentWatchletIndex = -1; + closeWatchlet(); + } else { + QString watchlet = watchlets.at(_currentWatchletIndex); + runWatchlet(watchlet); + } +} + void WatchServer::nextNotification() { if (!_watch->isConnected()) return; @@ -70,7 +113,7 @@ void WatchServer::nextNotification() } else if (_currentWatchlet) { reactivateCurrentWatchlet(); } else { - _watch->displayIdleScreen(); + goToIdle(); } } @@ -83,12 +126,22 @@ uint WatchServer::getNotificationCount(Notification::Type type) return count; } +void WatchServer::goToIdle() +{ + _watch->displayIdleScreen(); + if (_nextWatchletButton >= 0) { + _watch->grabButton(_nextWatchletButton); + } +} + void WatchServer::watchConnected() { if (!_pendingNotifications.isEmpty()) { nextNotification(); } else if (_currentWatchlet) { reactivateCurrentWatchlet(); + } else { + goToIdle(); } } @@ -102,13 +155,27 @@ void WatchServer::watchDisconnected() void WatchServer::watchIdling() { - qDebug() << "Watch idling"; + qDebug() << "watch idling"; if (!_pendingNotifications.empty()) { _pendingNotifications.dequeue(); nextNotification(); } } +void WatchServer::watchButtonPress(int button) +{ + if (button == _nextWatchletButton) { + if (_pendingNotifications.empty()) { + // No notifications: either app or idle mode. + nextWatchlet(); + } else { + // Skip to next notification if any + _pendingNotifications.dequeue(); + nextNotification(); + } + } +} + void WatchServer::notificationReceived(Notification *notification) { const Notification::Type type = notification->type(); diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h index 1ece104..681c758 100644 --- a/libsowatch/watchserver.h +++ b/libsowatch/watchserver.h @@ -19,12 +19,16 @@ class SOWATCH_EXPORT WatchServer : public QObject { Q_OBJECT Q_PROPERTY(Watch* watch READ watch CONSTANT) + Q_PROPERTY(QString nextWatchletButton READ nextWatchletButton WRITE setNextWatchletButton) public: explicit WatchServer(Watch* watch, QObject* parent = 0); Watch* watch(); + QString nextWatchletButton() const; + void setNextWatchletButton(const QString& value); + void addProvider(NotificationProvider* provider); void runWatchlet(const QString& id); @@ -33,6 +37,8 @@ public: protected: Watch* _watch; + char _nextWatchletButton; + QMap<QString, Watchlet*> _watchlets; /** Stores current notifications, classified by type. */ @@ -40,17 +46,22 @@ protected: QQueue<Notification*> _pendingNotifications; Watchlet* _currentWatchlet; + char _currentWatchletIndex; void registerWatchlet(Watchlet *watchlet); void reactivateCurrentWatchlet(); + void nextWatchlet(); void nextNotification(); uint getNotificationCount(Notification::Type type); + void goToIdle(); + protected slots: void watchConnected(); void watchDisconnected(); void watchIdling(); + void watchButtonPress(int button); void notificationReceived(Notification* notification); void notificationChanged(); void notificationCleared(); |