diff options
Diffstat (limited to 'libsowatch')
-rw-r--r-- | libsowatch/notification.cpp | 5 | ||||
-rw-r--r-- | libsowatch/notification.h | 13 | ||||
-rw-r--r-- | libsowatch/watch.h | 6 | ||||
-rw-r--r-- | libsowatch/watchserver.cpp | 47 | ||||
-rw-r--r-- | libsowatch/watchserver.h | 4 | ||||
-rw-r--r-- | libsowatch/weathernotification.cpp | 5 | ||||
-rw-r--r-- | libsowatch/weathernotification.h | 27 |
7 files changed, 48 insertions, 59 deletions
diff --git a/libsowatch/notification.cpp b/libsowatch/notification.cpp index 62a9b7d..8f346c0 100644 --- a/libsowatch/notification.cpp +++ b/libsowatch/notification.cpp @@ -11,6 +11,11 @@ Notification::~Notification() { } +Notification::Priority Notification::priority() const +{ + return Normal; +} + QString Notification::displayTime() const { QDateTime dt = dateTime(); diff --git a/libsowatch/notification.h b/libsowatch/notification.h index 7080f7f..e20f897 100644 --- a/libsowatch/notification.h +++ b/libsowatch/notification.h @@ -13,8 +13,9 @@ namespace sowatch class SOWATCH_EXPORT Notification : public QObject { Q_OBJECT - Q_ENUMS(Type) + Q_ENUMS(Type Priority) Q_PROPERTY(Type type READ type CONSTANT) + Q_PROPERTY(Priority priority READ priority NOTIFY priorityChanged) Q_PROPERTY(uint count READ count NOTIFY countChanged) Q_PROPERTY(QDateTime dateTime READ dateTime NOTIFY dateTimeChanged) Q_PROPERTY(QString displayTime READ displayTime NOTIFY displayTimeChanged STORED false) @@ -36,10 +37,17 @@ public: TypeCount }; + enum Priority { + Silent, + Normal, + Urgent + }; + explicit Notification(QObject *parent = 0); virtual ~Notification(); virtual Type type() const = 0; + virtual Priority priority() const; virtual uint count() const = 0; virtual QDateTime dateTime() const = 0; virtual QString displayTime() const; @@ -54,7 +62,7 @@ public slots: virtual void dismiss() = 0; signals: - /* For the convenience of QML users */ + void priorityChanged(); void countChanged(); void dateTimeChanged(); void displayTimeChanged(); @@ -74,5 +82,6 @@ signals: QML_DECLARE_TYPE(sowatch::Notification) QML_DECLARE_TYPE(sowatch::Notification::Type) +QML_DECLARE_TYPE(sowatch::Notification::Priority) #endif // SOWATCH_NOTIFICATION_H diff --git a/libsowatch/watch.h b/libsowatch/watch.h index 5e0233b..938071b 100644 --- a/libsowatch/watch.h +++ b/libsowatch/watch.h @@ -57,12 +57,6 @@ public: virtual void queryCharging() = 0; virtual bool charging() const = 0; - /** Tells the watch to update the unread notifications count, if visible. */ - virtual void updateNotificationCount(Notification::Type type, int count) = 0; - - /** Tells the watch to update the current weather forecast, if visible. */ - virtual void updateWeather(WeatherNotification* weather) = 0; - public slots: /** Go back to the idle screen. */ virtual void displayIdleScreen() = 0; diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index 41dc78e..0b7b60f 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -162,6 +162,7 @@ const NotificationsModel * WatchServer::notifications() const void WatchServer::postNotification(Notification *notification) { const Notification::Type type = notification->type(); + const Notification::Priority priority = notification->priority(); // Add notification to model _notifications->add(notification); @@ -173,14 +174,8 @@ void WatchServer::postNotification(Notification *notification) qDebug() << "notification received" << notification->title() << "(" << notification->count() << ")"; - _watch->updateNotificationCount(type, getNotificationCount(type)); - - if (type == Notification::WeatherNotification) { - // Weather notifications, we handle differently. - WeatherNotification* weather = static_cast<WeatherNotification*>(notification); - _weather = weather; - _watch->updateWeather(weather); - return; // And do not display it the usual way + if (priority == Notification::Silent) { + return; // Do not display notification in the usual way } QDateTime oldThreshold = QDateTime::currentDateTime().addSecs(-_oldNotificationThreshold); @@ -191,8 +186,9 @@ void WatchServer::postNotification(Notification *notification) if (_pendingNotifications.isEmpty()) { _pendingNotifications.enqueue(notification); nextNotification(); - } else if (type == Notification::CallNotification) { - // Oops, priority!!!! + } else if (priority == Notification::Urgent) { + // Notification has priority, so we switch to it even if there is + // an active notification. _pendingNotifications.prepend(notification); nextNotification(); } else { @@ -319,21 +315,12 @@ void WatchServer::syncTime() } } -uint WatchServer::getNotificationCount(Notification::Type type) -{ - // TODO: deprecate - return 0; - //return _notifications->fullCountByType(type); -} - void WatchServer::removeNotification(Notification::Type type, Notification *n) { // Warning: This function might be called with n being deleted. _notifications->remove(type, n); _notificationCounts.remove(n); - _watch->updateNotificationCount(type, getNotificationCount(type)); - if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) { qDebug() << "removing top notification"; _pendingNotifications.removeAll(n); @@ -341,12 +328,6 @@ void WatchServer::removeNotification(Notification::Type type, Notification *n) } else { _pendingNotifications.removeAll(n); } - if (type == Notification::WeatherNotification) { - WeatherNotification* w = static_cast<WeatherNotification*>(n); - if (_weather == w) { - _weather = 0; - } - } // No longer interested in this notification disconnect(n, 0, this, 0); @@ -419,22 +400,6 @@ void WatchServer::handleNotificationChanged() qDebug() << "notification changed" << n->title() << "(" << n->count() << ")"; - _watch->updateNotificationCount(type, getNotificationCount(type)); - - if (type == Notification::WeatherNotification) { - WeatherNotification* w = static_cast<WeatherNotification*>(n); - if (!_weather || _weather->dateTime() < w->dateTime()) { - // Prefer showing the most recent data - _weather = w; - } - if (_weather == w) { - // This is the weather notification we are currently displaying on the watch - // Therefore, update the displayed information - _watch->updateWeather(w); - } - return; // Do not display it the usual way - } - if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) { // This is the notification that is being currently signaled on the watch // Therefore, show it again no matter what. diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h index cc6c548..43bb7d4 100644 --- a/libsowatch/watchserver.h +++ b/libsowatch/watchserver.h @@ -97,8 +97,6 @@ private: QQueue<Notification*> _pendingNotifications; /** Stores the count of notifications hidden between each notification object. */ QMap<Notification*, uint> _notificationCounts; - /** We store a currently live weather forecast. */ - WeatherNotification* _weather; /** Active watchlet is the one that has "focus" right now. */ Watchlet* _activeWatchlet; @@ -110,8 +108,6 @@ private: /** Used for periodic watch time syncing. */ QTimer* _syncTimeTimer; - /** Counts all notifications from a given type. */ - uint getNotificationCount(Notification::Type type); /** Remove a notification of a certain type. */ void removeNotification(Notification::Type type, Notification* n); diff --git a/libsowatch/weathernotification.cpp b/libsowatch/weathernotification.cpp index 6d693b2..9c9c2e8 100644 --- a/libsowatch/weathernotification.cpp +++ b/libsowatch/weathernotification.cpp @@ -7,6 +7,11 @@ WeatherNotification::WeatherNotification(QObject *parent) : { } +Notification::Priority WeatherNotification::priority() const +{ + return Silent; +} + qreal WeatherNotification::convertTemperature(qreal temp, Unit from, Unit to) { if (from == to) { diff --git a/libsowatch/weathernotification.h b/libsowatch/weathernotification.h index 843a844..5fe4697 100644 --- a/libsowatch/weathernotification.h +++ b/libsowatch/weathernotification.h @@ -9,6 +9,11 @@ namespace sowatch class WeatherNotification : public Notification { Q_OBJECT + Q_ENUMS(WeatherType Unit) + Q_PROPERTY(WeatherType forecast READ forecast NOTIFY forecastChanged) + Q_PROPERTY(int temperature READ temperature NOTIFY temperatureChanged) + Q_PROPERTY(Unit temperatureUnits READ temperatureUnits NOTIFY temperatureUnitsChanged) + public: explicit WeatherNotification(QObject *parent = 0); @@ -29,17 +34,27 @@ public: Fahrenheit }; - virtual WeatherType forecast() = 0; - virtual int temperature() = 0; - virtual Unit temperatureUnits() = 0; + Priority priority() const; + + virtual WeatherType forecast() const = 0; + virtual int temperature() const = 0; + virtual Unit temperatureUnits() const = 0; + +signals: + void forecastChanged(); + void temperatureChanged(); + void temperatureUnitsChanged(); - /** Quite useful helper function. */ +protected: + /** Useful helper functions. */ static qreal convertTemperature(qreal temp, Unit from, Unit to); static int convertTemperature(int temp, Unit from, Unit to); }; - - } +QML_DECLARE_TYPE(sowatch::WeatherNotification) +QML_DECLARE_TYPE(sowatch::WeatherNotification::WeatherType) +QML_DECLARE_TYPE(sowatch::WeatherNotification::Unit) + #endif // WEATHERNOTIFICATION_H |