From 3ca9235ddb93b52730099164a0dc387f7a301280 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 12 May 2013 03:49:38 +0200 Subject: weather rendering in metawatchwatchlets --- testnotification/testnotification.cpp | 2 +- testnotification/testnotification.h | 2 + testnotification/testnotification.pro | 6 ++- testnotification/testnotificationprovider.cpp | 10 ++++- testnotification/testnotificationprovider.h | 1 + testnotification/testweathernotification.cpp | 59 +++++++++++++++++++++++++++ testnotification/testweathernotification.h | 34 +++++++++++++++ 7 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 testnotification/testweathernotification.cpp create mode 100644 testnotification/testweathernotification.h (limited to 'testnotification') diff --git a/testnotification/testnotification.cpp b/testnotification/testnotification.cpp index d5fe985..fe1b30f 100644 --- a/testnotification/testnotification.cpp +++ b/testnotification/testnotification.cpp @@ -8,7 +8,7 @@ TestNotification::TestNotification(Type type, const QString &title, const QStrin _time(QDateTime::currentDateTime()), _title(title), _body(body) { - const int high = 10000, low = 5000; + const int high = 60 * 1000, low = 30 * 1000; int rand = qrand() % ((high + 1) - low) + low; QTimer::singleShot(rand, this, SIGNAL(dismissed())); } diff --git a/testnotification/testnotification.h b/testnotification/testnotification.h index f54623d..ecaacb4 100644 --- a/testnotification/testnotification.h +++ b/testnotification/testnotification.h @@ -31,4 +31,6 @@ private: } +QML_DECLARE_TYPE(sowatch::TestNotification) + #endif // TESTNOTIFICATION_H diff --git a/testnotification/testnotification.pro b/testnotification/testnotification.pro index 525fdac..099c148 100644 --- a/testnotification/testnotification.pro +++ b/testnotification/testnotification.pro @@ -5,10 +5,12 @@ CONFIG += mobility MOBILITY += systeminfo SOURCES += testnotificationplugin.cpp testnotificationprovider.cpp \ - testnotification.cpp + testnotification.cpp \ + testweathernotification.cpp HEADERS += testnotificationplugin.h testnotificationprovider.h \ - testnotification.h + testnotification.h \ + testweathernotification.h unix: LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch INCLUDEPATH += $$PWD/../libsowatch diff --git a/testnotification/testnotificationprovider.cpp b/testnotification/testnotificationprovider.cpp index 687780b..8f1db76 100644 --- a/testnotification/testnotificationprovider.cpp +++ b/testnotification/testnotificationprovider.cpp @@ -1,4 +1,5 @@ #include "testnotification.h" +#include "testweathernotification.h" #include "testnotificationprovider.h" using namespace sowatch; @@ -10,10 +11,11 @@ TestNotificationProvider::TestNotificationProvider(QObject *parent) : _timer(new QTimer(this)) { const int initial_delay = 2000; - const int burst_num = 0; + const int burst_num = 1; const int burst_delay = 500; const int extra_delay = 100 * 1000; QTimer::singleShot(initial_delay, this, SLOT(generateInitialNotification())); + QTimer::singleShot(initial_delay + 100, this, SLOT(generateWeatherNotification())); for (int i = 0; i < burst_num; i++) { QTimer::singleShot(initial_delay + burst_delay * (i+1), this, SLOT(generateNotification())); } @@ -34,6 +36,12 @@ void TestNotificationProvider::generateInitialNotification() emit incomingNotification(n); } +void TestNotificationProvider::generateWeatherNotification() +{ + TestWeatherNotification *n = new TestWeatherNotification; + emit incomingNotification(n); +} + void TestNotificationProvider::generateNotification() { TestNotification *n = new TestNotification(Notification::ImNotification, diff --git a/testnotification/testnotificationprovider.h b/testnotification/testnotificationprovider.h index 7bca1f3..5813a9b 100644 --- a/testnotification/testnotificationprovider.h +++ b/testnotification/testnotificationprovider.h @@ -18,6 +18,7 @@ public: private slots: void generateInitialNotification(); + void generateWeatherNotification(); void generateNotification(); private: diff --git a/testnotification/testweathernotification.cpp b/testnotification/testweathernotification.cpp new file mode 100644 index 0000000..98c0713 --- /dev/null +++ b/testnotification/testweathernotification.cpp @@ -0,0 +1,59 @@ +#include "testweathernotification.h" + +using namespace sowatch; + +TestWeatherNotification::TestWeatherNotification(QObject *parent) + : WeatherNotification(parent) +{ +} + + +Notification::Type TestWeatherNotification::type() const +{ + return Notification::WeatherNotification; +} + +uint TestWeatherNotification::count() const +{ + return 1; +} + +QDateTime TestWeatherNotification::dateTime() const +{ + return QDateTime::currentDateTime(); +} + +QString TestWeatherNotification::title() const +{ + return "My city"; +} + +QString TestWeatherNotification::body() const +{ + return "Mostly sunny"; +} + +WeatherNotification::WeatherType TestWeatherNotification::forecast() const +{ + return Sunny; +} + +int TestWeatherNotification::temperature() const +{ + return 30; +} + +WeatherNotification::Unit TestWeatherNotification::temperatureUnits() const +{ + return Celsius; +} + +void TestWeatherNotification::activate() +{ + // Do nothing +} + +void TestWeatherNotification::dismiss() +{ + deleteLater(); // We do not want to keep those around. +} diff --git a/testnotification/testweathernotification.h b/testnotification/testweathernotification.h new file mode 100644 index 0000000..1236f31 --- /dev/null +++ b/testnotification/testweathernotification.h @@ -0,0 +1,34 @@ +#ifndef TESTWEATHERNOTIFICATION_H +#define TESTWEATHERNOTIFICATION_H + +#include + +namespace sowatch +{ + +class TestWeatherNotification : public WeatherNotification +{ + Q_OBJECT + +public: + explicit TestWeatherNotification(QObject *parent = 0); + + Type type() const; + uint count() const; + QDateTime dateTime() const; + QString title() const; + QString body() const; + + WeatherType forecast() const; + int temperature() const; + Unit temperatureUnits() const; + + void activate(); + void dismiss(); +}; + +} + +QML_DECLARE_TYPE(sowatch::TestWeatherNotification) + +#endif // TESTWEATHERNOTIFICATION_H -- cgit v1.2.3