summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--harmaccuweather/harmaccuplugin.cpp5
-rw-r--r--harmaccuweather/harmaccuprovider.cpp13
-rw-r--r--harmaccuweather/harmaccuprovider.h5
-rw-r--r--harmaccuweather/harmaccuweather.cpp37
-rw-r--r--harmaccuweather/harmaccuweather.h8
5 files changed, 47 insertions, 21 deletions
diff --git a/harmaccuweather/harmaccuplugin.cpp b/harmaccuweather/harmaccuplugin.cpp
index 9ea94bd..25821c4 100644
--- a/harmaccuweather/harmaccuplugin.cpp
+++ b/harmaccuweather/harmaccuplugin.cpp
@@ -21,10 +21,9 @@ QStringList HarmAccuPlugin::providers()
NotificationProvider* HarmAccuPlugin::getProvider(const QString& id, QSettings& settings, QObject *parent)
{
+ Q_UNUSED(settings);
if (id != "harmaccu") return 0;
- int updateTime = settings.value("updateTime").toInt();
- if (updateTime <= 0) updateTime = 2 * 3600; // Two hours by default
- return new HarmAccuProvider(updateTime, parent);
+ return new HarmAccuProvider(parent);
}
Q_EXPORT_PLUGIN2(harmaccuweather, HarmAccuPlugin)
diff --git a/harmaccuweather/harmaccuprovider.cpp b/harmaccuweather/harmaccuprovider.cpp
index af4a8d0..0eedf04 100644
--- a/harmaccuweather/harmaccuprovider.cpp
+++ b/harmaccuweather/harmaccuprovider.cpp
@@ -5,11 +5,10 @@
using namespace sowatch;
-HarmAccuProvider::HarmAccuProvider(int updateTime, QObject *parent) :
- NotificationProvider(parent),
- _updateTime(updateTime)
+HarmAccuProvider::HarmAccuProvider(QObject *parent) :
+ NotificationProvider(parent)
{
- // Give some time to send the notification
+ // Give some time to send the first notification
QTimer::singleShot(2000, this, SLOT(generateNotification()));
}
@@ -22,8 +21,10 @@ void HarmAccuProvider::generateNotification()
{
QSettings* s = HarmAccuWeather::getAccuweatherData();
if (s->contains("LastUpdate")) {
- qDebug() << "generate harmaccuweather notification";
- emit incomingNotification(new HarmAccuWeather(_updateTime, this));
+ qDebug() << "generating harmaccuweather notification";
+ emit incomingNotification(new HarmAccuWeather(this));
+ } else {
+ qWarning() << "Accuweather config file does not seem to exist";
}
delete s;
}
diff --git a/harmaccuweather/harmaccuprovider.h b/harmaccuweather/harmaccuprovider.h
index 44942ad..f7c7ca4 100644
--- a/harmaccuweather/harmaccuprovider.h
+++ b/harmaccuweather/harmaccuprovider.h
@@ -1,7 +1,6 @@
#ifndef CKITCALLPROVIDER_H
#define CKITCALLPROVIDER_H
-#include <QtCore/QTimer>
#include <sowatch.h>
namespace sowatch
@@ -14,14 +13,14 @@ class HarmAccuProvider : public NotificationProvider
Q_OBJECT
public:
- explicit HarmAccuProvider(int updateTime, QObject *parent = 0);
+ explicit HarmAccuProvider(QObject *parent = 0);
~HarmAccuProvider();
public slots:
void generateNotification();
private:
- int _updateTime;
+
};
}
diff --git a/harmaccuweather/harmaccuweather.cpp b/harmaccuweather/harmaccuweather.cpp
index 9d7a00d..1306b6e 100644
--- a/harmaccuweather/harmaccuweather.cpp
+++ b/harmaccuweather/harmaccuweather.cpp
@@ -2,14 +2,22 @@
using namespace sowatch;
-HarmAccuWeather::HarmAccuWeather(int updateTime, QObject *parent) :
+HarmAccuWeather::HarmAccuWeather(QObject *parent) :
WeatherNotification(parent),
- _updateTimer(new QTimer(this)),
+ _watcher(new QFileSystemWatcher(this)),
+ _timer(new QTimer(this)),
_lastUpdate(QDateTime::fromTime_t(0))
{
- connect(_updateTimer, SIGNAL(timeout()), SLOT(update()));
- _updateTimer->setInterval(updateTime * 1000);
- _updateTimer->start();
+ // This only works on Harmattan either way, so I guess
+ // hardcoding the path is OK.
+ _watcher->addPath("/home/user/.config/AccuWeather, Inc./awxapp.conf");
+ connect(_watcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
+
+ _timer->setInterval(2000);
+ _timer->setSingleShot(true);
+ connect(_timer, SIGNAL(timeout()), SLOT(update()));
+
+ // Perform an initial update
update();
}
@@ -41,13 +49,17 @@ QString HarmAccuWeather::title() const
QString HarmAccuWeather::body() const
{
switch (_lastWxCode) {
+ case 2:
+ return tr("Sunny");
+ case 3:
+ return tr("Partly sunny");
case 33:
return tr("Clear");
case 6:
case 38:
return tr("Mostly cloudy");
case 35:
- return tr("Part. cloudy");
+ return tr("Partly cloudy");
case 7:
return tr("Cloudy");
default:
@@ -58,6 +70,8 @@ QString HarmAccuWeather::body() const
WeatherNotification::WeatherType HarmAccuWeather::forecast()
{
switch (_lastWxCode) {
+ case 2:
+ case 3:
case 33:
return Sunny;
case 6:
@@ -90,18 +104,27 @@ void HarmAccuWeather::dismiss()
// Do nothing
}
+void HarmAccuWeather::fileChanged(const QString &path)
+{
+ Q_UNUSED(path);
+ qDebug() << "accuweather config file changed";
+ _timer->start();
+}
+
void HarmAccuWeather::update()
{
QSettings* s = getAccuweatherData();
+ qDebug() << "reading accuweather config file";
+
QDateTime lastUpdate = s->value("LastUpdate").toDateTime();
if (lastUpdate > _lastUpdate) {
- qDebug() << "updated weather info";
_lastUpdate = lastUpdate;
_metric = s->value("useMetric").toBool();
_lastTemp = s->value("LastTemp").toInt();
_lastLocation = s->value("LastLocation").toString();
_lastWxCode = s->value("LastWxCode").toInt();
+ qDebug() << "updated weather info" << _lastUpdate << _lastWxCode;
emit changed();
}
diff --git a/harmaccuweather/harmaccuweather.h b/harmaccuweather/harmaccuweather.h
index bac08e2..8b403b9 100644
--- a/harmaccuweather/harmaccuweather.h
+++ b/harmaccuweather/harmaccuweather.h
@@ -1,6 +1,7 @@
#ifndef HARMACCUWEATHER_H
#define HARMACCUWEATHER_H
+#include <QtCore/QFileSystemWatcher>
#include <QtCore/QTimer>
#include <QtCore/QSettings>
#include <sowatch.h>
@@ -13,7 +14,7 @@ class HarmAccuWeather : public WeatherNotification
Q_OBJECT
public:
- explicit HarmAccuWeather(int updateTime, QObject *parent = 0);
+ explicit HarmAccuWeather(QObject *parent = 0);
static QSettings* getAccuweatherData();
@@ -31,10 +32,13 @@ public:
void dismiss();
private slots:
+ void fileChanged(const QString& path);
void update();
private:
- QTimer* _updateTimer;
+ QFileSystemWatcher* _watcher;
+ QTimer* _timer;
+
bool _metric;
QDateTime _lastUpdate;
QString _lastLocation;