summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-05-06 23:13:37 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-05-06 23:13:37 +0200
commitae37832316d905889c82706b351b3c037c9e1ab6 (patch)
treed90c4a18729937b782f557e170cf95d4ef38f031
parentd83093df7602aa2896de71292b47948540c22a44 (diff)
downloadsowatch-ae37832316d905889c82706b351b3c037c9e1ab6.tar.gz
sowatch-ae37832316d905889c82706b351b3c037c9e1ab6.zip
prepare for weather qml notifications
-rw-r--r--harmaccuweather/harmaccuweather.cpp6
-rw-r--r--harmaccuweather/harmaccuweather.h6
-rw-r--r--libsowatch/notification.cpp5
-rw-r--r--libsowatch/notification.h13
-rw-r--r--libsowatch/watch.h6
-rw-r--r--libsowatch/watchserver.cpp47
-rw-r--r--libsowatch/watchserver.h4
-rw-r--r--libsowatch/weathernotification.cpp5
-rw-r--r--libsowatch/weathernotification.h27
-rw-r--r--meecastweather/meecastweather.cpp6
-rw-r--r--meecastweather/meecastweather.h6
-rw-r--r--metawatch/metawatch.cpp13
-rw-r--r--metawatch/metawatch.h3
-rw-r--r--metawatch/metawatchdigital.cpp96
-rw-r--r--metawatch/metawatchdigital.h4
15 files changed, 60 insertions, 187 deletions
diff --git a/harmaccuweather/harmaccuweather.cpp b/harmaccuweather/harmaccuweather.cpp
index c4daeb9..e48ee13 100644
--- a/harmaccuweather/harmaccuweather.cpp
+++ b/harmaccuweather/harmaccuweather.cpp
@@ -131,7 +131,7 @@ QString HarmAccuWeather::body() const
}
}
-WeatherNotification::WeatherType HarmAccuWeather::forecast()
+WeatherNotification::WeatherType HarmAccuWeather::forecast() const
{
switch (_lastWxCode) {
case 1:
@@ -198,12 +198,12 @@ WeatherNotification::WeatherType HarmAccuWeather::forecast()
}
}
-int HarmAccuWeather::temperature()
+int HarmAccuWeather::temperature() const
{
return _lastTemp;
}
-WeatherNotification::Unit HarmAccuWeather::temperatureUnits()
+WeatherNotification::Unit HarmAccuWeather::temperatureUnits() const
{
return _metric ? Celsius : Fahrenheit;
}
diff --git a/harmaccuweather/harmaccuweather.h b/harmaccuweather/harmaccuweather.h
index 8b403b9..4fcf2da 100644
--- a/harmaccuweather/harmaccuweather.h
+++ b/harmaccuweather/harmaccuweather.h
@@ -24,9 +24,9 @@ public:
QString title() const;
QString body() const;
- WeatherType forecast();
- int temperature();
- Unit temperatureUnits();
+ WeatherType forecast() const;
+ int temperature() const;
+ Unit temperatureUnits() const;
void activate();
void dismiss();
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
diff --git a/meecastweather/meecastweather.cpp b/meecastweather/meecastweather.cpp
index fa62ab7..47df334 100644
--- a/meecastweather/meecastweather.cpp
+++ b/meecastweather/meecastweather.cpp
@@ -52,7 +52,7 @@ QString MeeCastWeather::body() const
return _lastText;
}
-WeatherNotification::WeatherType MeeCastWeather::forecast()
+WeatherNotification::WeatherType MeeCastWeather::forecast() const
{
switch (_lastCode) {
// Day versions
@@ -125,12 +125,12 @@ WeatherNotification::WeatherType MeeCastWeather::forecast()
}
}
-int MeeCastWeather::temperature()
+int MeeCastWeather::temperature() const
{
return _lastTemp;
}
-WeatherNotification::Unit MeeCastWeather::temperatureUnits()
+WeatherNotification::Unit MeeCastWeather::temperatureUnits() const
{
return _tempUnit;
}
diff --git a/meecastweather/meecastweather.h b/meecastweather/meecastweather.h
index a1ac393..b51a1e4 100644
--- a/meecastweather/meecastweather.h
+++ b/meecastweather/meecastweather.h
@@ -24,9 +24,9 @@ public:
QString title() const;
QString body() const;
- WeatherType forecast();
- int temperature();
- Unit temperatureUnits();
+ WeatherType forecast() const;
+ int temperature() const;
+ Unit temperatureUnits() const;
void activate();
void dismiss();
diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp
index a8eab4d..01dec25 100644
--- a/metawatch/metawatch.cpp
+++ b/metawatch/metawatch.cpp
@@ -228,19 +228,6 @@ bool MetaWatch::charging() const
return _watchCharging;
}
-void MetaWatch::updateNotificationCount(Notification::Type type, int count)
-{
- Q_UNUSED(type);
- Q_UNUSED(count);
- // Default implementation does nothing
-}
-
-void MetaWatch::updateWeather(WeatherNotification *weather)
-{
- Q_UNUSED(weather);
- // Default implementation does nothing
-}
-
void MetaWatch::displayIdleScreen()
{
_currentMode = IdleMode;
diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h
index 2a86f5c..a9cf58b 100644
--- a/metawatch/metawatch.h
+++ b/metawatch/metawatch.h
@@ -112,9 +112,6 @@ public:
void queryCharging();
bool charging() const;
- void updateNotificationCount(Notification::Type type, int count);
- void updateWeather(WeatherNotification *weather);
-
void displayIdleScreen();
void displayNotification(Notification *notification);
void displayApplication();
diff --git a/metawatch/metawatchdigital.cpp b/metawatch/metawatchdigital.cpp
index d2de326..de55db6 100644
--- a/metawatch/metawatchdigital.cpp
+++ b/metawatch/metawatchdigital.cpp
@@ -46,49 +46,6 @@ QString MetaWatchDigital::model() const
return "metawatch-digital";
}
-void MetaWatchDigital::updateNotificationCount(Notification::Type type, int count)
-{
- switch (type) {
- case Notification::MissedCallNotification:
- _nCalls = count;
- break;
- case Notification::EmailNotification:
- _nMails = count;
- break;
- case Notification::ImNotification:
- _nIms = count;
- break;
- case Notification::SmsNotification:
- _nSms = count;
- break;
- case Notification::MmsNotification:
- _nMms = count;
- break;
- default:
- return; // Since this notification won't show up in idle screen, we do not redraw.
- break;
- }
-
- if (isConnected()) {
- renderIdleCounts();
- }
-}
-
-void MetaWatchDigital::updateWeather(WeatherNotification *weather)
-{
- if (weather) {
- _wForecast = weather->forecast();
- _wBody = weather->body();
- _wTemperature = weather->temperature();
- _wMetric = weather->temperatureUnits() == WeatherNotification::Celsius;
- } else {
- _wForecast = WeatherNotification::UnknownWeather;
- }
- if (isConnected()) {
- renderIdleWeather();
- }
-}
-
void MetaWatchDigital::displayIdleScreen()
{
qDebug() << "displaying idle screen";
@@ -146,31 +103,7 @@ void MetaWatchDigital::clear(Mode mode, bool black)
void MetaWatchDigital::renderIdleScreen()
{
-#if 0
- QImage idle_call(QString(SOWATCH_RESOURCES_DIR "/metawatch/graphics/idle_call.bmp"));
- QImage idle_msg(QString(SOWATCH_RESOURCES_DIR "/metawatch/graphics/idle_msg.bmp"));
- QImage idle_mail(QString(SOWATCH_RESOURCES_DIR "/metawatch/graphics/idle_mail.bmp"));
- QPainter p;
-
- _paintMode = IdleMode;
- p.begin(this);
-
- p.fillRect(0, 0, screenWidth, screenHeight, Qt::white);
- p.setPen(QPen(Qt::black, 1.0, Qt::DashLine));
- p.drawLine(1, systemAreaHeight + 2, screenWidth - 2, systemAreaHeight + 2);
- p.drawLine(1, systemAreaHeight * 2 + 4, screenWidth - 2, systemAreaHeight * 2 + 4);
-
- p.drawImage((32 * 0) + 4, systemAreaHeight * 2 + 7, idle_call);
- p.drawImage((32 * 1) + 4, systemAreaHeight * 2 + 7, idle_msg);
- p.drawImage((32 * 2) + 4, systemAreaHeight * 2 + 7, idle_mail);
-
- p.end();
- _paintMode = _currentMode;
-
- renderIdleWeather();
- renderIdleCounts();
-#endif
}
void MetaWatchDigital::renderIdleWeather()
@@ -227,35 +160,6 @@ QImage MetaWatchDigital::iconForWeather(WeatherNotification::WeatherType w)
}
}
-void MetaWatchDigital::renderIdleCounts()
-{
-#if 0
- _paintMode = IdleMode;
- QFont f("MetaWatch Large caps 8pt");
- QString s;
- QPainter p(this);
- QTextOption opt(Qt::AlignCenter);
- const int y = systemAreaHeight * 2 + 26;
- const int w = 24;
- const int h = screenHeight - (y + 1);
- const int mails = _nMails;
- const int calls = _nCalls;
- const int sms = _nSms + _nIms;
-
- qDebug() << "unread counts" << calls << sms << mails;
-
- f.setPixelSize(8); // Seems to be the only way to get the desired size.
-
- p.setFont(f);
- p.fillRect(QRect(0, y, screenWidth, h), Qt::white);
- p.drawText(QRect((32 * 0) + 4, y, w, h), s.sprintf("%d", calls), opt);
- p.drawText(QRect((32 * 1) + 4, y, w, h), s.sprintf("%d", sms), opt);
- p.drawText(QRect((32 * 2) + 4, y, w, h), s.sprintf("%d", mails), opt);
-
- _paintMode = _currentMode;
-#endif
-}
-
void MetaWatchDigital::renderNotification(Notification *n)
{
_paintMode = NotificationMode;
diff --git a/metawatch/metawatchdigital.h b/metawatch/metawatchdigital.h
index 3648160..dde017a 100644
--- a/metawatch/metawatchdigital.h
+++ b/metawatch/metawatchdigital.h
@@ -20,9 +20,6 @@ public:
QString model() const;
- void updateNotificationCount(Notification::Type type, int count);
- void updateWeather(WeatherNotification *weather);
-
void displayIdleScreen();
void displayNotification(Notification *notification);
void displayApplication();
@@ -45,7 +42,6 @@ private:
void renderIdleScreen();
void renderIdleWeather();
QImage iconForWeather(WeatherNotification::WeatherType w);
- void renderIdleCounts();
void renderNotification(Notification *n);
QImage iconForNotification(const Notification *n);