summaryrefslogtreecommitdiff
path: root/libsowatch
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-10-02 16:39:40 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-10-02 16:39:40 +0200
commit0a656b75f3fc80f13424db0e7ec403dff28a366e (patch)
tree23f72a2fde3f718048b49d9806ded3d315d50a80 /libsowatch
parentd9f132f3d5bf41ee4f30e7ea2bd1b61120fa29b7 (diff)
downloadsowatch-0a656b75f3fc80f13424db0e7ec403dff28a366e.tar.gz
sowatch-0a656b75f3fc80f13424db0e7ec403dff28a366e.zip
new notifications list, time syncing
Diffstat (limited to 'libsowatch')
-rw-r--r--libsowatch/declarativewatchlet.cpp2
-rw-r--r--libsowatch/declarativewatchwrapper.cpp23
-rw-r--r--libsowatch/declarativewatchwrapper.h18
-rw-r--r--libsowatch/libsowatch.pro28
-rw-r--r--libsowatch/notification.cpp2
-rw-r--r--libsowatch/notification.h34
-rw-r--r--libsowatch/notificationprovider.h3
-rw-r--r--libsowatch/watch.h3
-rw-r--r--libsowatch/watchpaintengine.h3
-rw-r--r--libsowatch/watchserver.cpp53
-rw-r--r--libsowatch/watchserver.h14
-rw-r--r--libsowatch/watchsimulator.h5
12 files changed, 122 insertions, 66 deletions
diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp
index dbd4759..34a1d2a 100644
--- a/libsowatch/declarativewatchlet.cpp
+++ b/libsowatch/declarativewatchlet.cpp
@@ -24,7 +24,7 @@ DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id)
}
_engine = new QDeclarativeEngine(this);
- _wrapper = new DeclarativeWatchWrapper(server->watch(), this);
+ _wrapper = new DeclarativeWatchWrapper(server, server->watch(), this);
_engine->rootContext()->setContextProperty("watch", _wrapper);
}
diff --git a/libsowatch/declarativewatchwrapper.cpp b/libsowatch/declarativewatchwrapper.cpp
index f7914f8..d972d86 100644
--- a/libsowatch/declarativewatchwrapper.cpp
+++ b/libsowatch/declarativewatchwrapper.cpp
@@ -1,11 +1,14 @@
#include <QtCore/QDebug>
+#include "watchserver.h"
#include "watch.h"
+#include "notification.h"
#include "declarativewatchwrapper.h"
using namespace sowatch;
-DeclarativeWatchWrapper::DeclarativeWatchWrapper(Watch* watch, QObject *parent) :
- QObject(parent), _watch(watch), _active(false)
+DeclarativeWatchWrapper::DeclarativeWatchWrapper(WatchServer* server, Watch* watch, QObject* parent) :
+ QObject(parent), _server(server), _watch(watch),
+ _active(false)
{
}
@@ -20,6 +23,19 @@ bool DeclarativeWatchWrapper::active() const
return _active;
}
+QList<QObject*> DeclarativeWatchWrapper::notifications() const
+{
+ // TODO: Figure a better way for this; QAbstractListModel, etc.
+ QList<Notification*> nl = _server->liveNotifications();
+ QList<QObject*> ol;
+ foreach (Notification* n, nl) {
+ QObject * o = n;
+ ol.append(o);
+ }
+ qDebug() << "notifications declarative: " << ol;
+ return ol;
+}
+
void DeclarativeWatchWrapper::vibrate(int msecs)
{
if (_active) {
@@ -34,6 +50,9 @@ void DeclarativeWatchWrapper::activate()
connect(_watch, SIGNAL(buttonReleased(int)), this, SIGNAL(buttonReleased(int)));
_active = true;
emit activeChanged();
+ // Since a notification currently causes the active watchlet to be deactivated,
+ // we can assume notifications only change when we are deactivated.
+ emit notificationsChanged();
}
}
diff --git a/libsowatch/declarativewatchwrapper.h b/libsowatch/declarativewatchwrapper.h
index 583b2d2..8d4fd7d 100644
--- a/libsowatch/declarativewatchwrapper.h
+++ b/libsowatch/declarativewatchwrapper.h
@@ -2,24 +2,30 @@
#define SOWATCH_DECLARATIVEWATCHWRAPPER_H
#include <QtDeclarative/QtDeclarative>
+#include "sowatch_global.h"
namespace sowatch
{
+class WatchServer;
class Watch;
class DeclarativeWatchlet;
+class Notification;
-class DeclarativeWatchWrapper : public QObject
+class SOWATCH_EXPORT DeclarativeWatchWrapper : public QObject
{
Q_OBJECT
Q_PROPERTY(QString model READ model CONSTANT)
Q_PROPERTY(bool active READ active NOTIFY activeChanged)
+ Q_PROPERTY(QList<QObject*> notifications READ notifications NOTIFY notificationsChanged)
public:
- explicit DeclarativeWatchWrapper(Watch *watch, QObject *parent = 0);
+ explicit DeclarativeWatchWrapper(WatchServer *server, Watch *watch, QObject *parent = 0);
- Q_INVOKABLE QString model() const;
- Q_INVOKABLE bool active() const;
+ QString model() const;
+ bool active() const;
+
+ QList<QObject*> notifications() const;
public slots:
void vibrate(int msecs);
@@ -29,8 +35,10 @@ signals:
void buttonReleased(int button);
void activeChanged();
+ void notificationsChanged();
-protected:
+private:
+ WatchServer *_server;
Watch* _watch;
bool _active;
diff --git a/libsowatch/libsowatch.pro b/libsowatch/libsowatch.pro
index 4c0d7dc..574e1a4 100644
--- a/libsowatch/libsowatch.pro
+++ b/libsowatch/libsowatch.pro
@@ -5,7 +5,6 @@
#-------------------------------------------------
QT += gui declarative
-CONFIG += mobility
TARGET = sowatch
TEMPLATE = lib
@@ -66,30 +65,3 @@ unix:!symbian {
}
INSTALLS += install_headers target
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libsowatch/notification.cpp b/libsowatch/notification.cpp
index e321b58..62a9b7d 100644
--- a/libsowatch/notification.cpp
+++ b/libsowatch/notification.cpp
@@ -15,7 +15,7 @@ QString Notification::displayTime() const
{
QDateTime dt = dateTime();
int secsDiff = dt.secsTo(QDateTime::currentDateTime());
- if (secsDiff < 1) {
+ if (secsDiff < 20) {
return "";
} else if (secsDiff < 60) {
return tr("%n second(s) ago", "", secsDiff);
diff --git a/libsowatch/notification.h b/libsowatch/notification.h
index 1af0264..758a8b7 100644
--- a/libsowatch/notification.h
+++ b/libsowatch/notification.h
@@ -4,6 +4,7 @@
#include <QtCore/QString>
#include <QtCore/QDateTime>
#include <QtGui/QImage>
+#include <QtDeclarative/QtDeclarative>
#include "sowatch_global.h"
namespace sowatch
@@ -13,12 +14,13 @@ class SOWATCH_EXPORT Notification : public QObject
{
Q_OBJECT
Q_ENUMS(Type)
- Q_PROPERTY(Type type READ type)
- Q_PROPERTY(uint count READ count)
- Q_PROPERTY(QDateTime dateTime READ dateTime)
- Q_PROPERTY(QString title READ title)
- Q_PROPERTY(QString body READ body)
- Q_PROPERTY(QImage image READ image)
+ Q_PROPERTY(Type type READ type CONSTANT)
+ 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)
+ Q_PROPERTY(QString title READ title NOTIFY titleChanged)
+ Q_PROPERTY(QString body READ body NOTIFY bodyChanged)
+ Q_PROPERTY(QImage image READ image NOTIFY imageChanged)
public:
enum Type {
@@ -45,14 +47,30 @@ public:
virtual QImage image() const;
public slots:
+ /** Do something on this notification; open the application that caused it, answer, etc. */
virtual void activate() = 0;
- virtual void clear() = 0;
+ /** Dismiss this notification. */
+ virtual void dismiss() = 0;
signals:
+ /* For the convenience of QML users */
+ void countChanged();
+ void dateTimeChanged();
+ void displayTimeChanged();
+ void titleChanged();
+ void bodyChanged();
+ void imageChanged();
+
+ /** Generic "changed" signal if any of the properties changes; can be batched. */
void changed();
- void cleared();
+
+ /** The notification has been dismissed by the user or via dismiss(). */
+ void dismissed();
+ /* Provider of this notification object should delete it after dismissal. */
};
}
+QML_DECLARE_TYPE(sowatch::Notification)
+
#endif // SOWATCH_NOTIFICATION_H
diff --git a/libsowatch/notificationprovider.h b/libsowatch/notificationprovider.h
index 31182f1..d5449f8 100644
--- a/libsowatch/notificationprovider.h
+++ b/libsowatch/notificationprovider.h
@@ -3,11 +3,12 @@
#include <QtCore/QObject>
#include "notification.h"
+#include "sowatch_global.h"
namespace sowatch
{
-class NotificationProvider : public QObject
+class SOWATCH_EXPORT NotificationProvider : public QObject
{
Q_OBJECT
diff --git a/libsowatch/watch.h b/libsowatch/watch.h
index bb4376c..f18ed9a 100644
--- a/libsowatch/watch.h
+++ b/libsowatch/watch.h
@@ -7,11 +7,12 @@
#include <QtGui/QPaintDevice>
#include <QtGui/QImage>
#include "notification.h"
+#include "sowatch_global.h"
namespace sowatch
{
-class Watch : public QObject, public QPaintDevice
+class SOWATCH_EXPORT Watch : public QObject, public QPaintDevice
{
Q_OBJECT
Q_PROPERTY(QString model READ model CONSTANT)
diff --git a/libsowatch/watchpaintengine.h b/libsowatch/watchpaintengine.h
index 7a97ad7..07e3868 100644
--- a/libsowatch/watchpaintengine.h
+++ b/libsowatch/watchpaintengine.h
@@ -2,11 +2,12 @@
#define SOWATCH_WATCHPAINTENGINE_H
#include <QtGui/QPaintEngine>
+#include "sowatch_global.h"
namespace sowatch
{
-class WatchPaintEngine : public QPaintEngine
+class SOWATCH_EXPORT WatchPaintEngine : public QPaintEngine
{
public:
~WatchPaintEngine();
diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp
index 9f11795..60c410d 100644
--- a/libsowatch/watchserver.cpp
+++ b/libsowatch/watchserver.cpp
@@ -12,12 +12,17 @@ WatchServer::WatchServer(Watch* watch, QObject* parent) :
QObject(parent), _watch(watch),
_nextWatchletButton(-1),
_oldNotificationThreshold(300),
- _currentWatchlet(0), _currentWatchletIndex(-1)
+ _currentWatchlet(0), _currentWatchletIndex(-1),
+ _syncTimeTimer(new QTimer(this))
{
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)));
+ connect(_syncTimeTimer, SIGNAL(timeout()), SLOT(syncTime()));
+
+ _syncTimeTimer->setSingleShot(true);
+ _syncTimeTimer->setInterval(24 * 3600 * 1000); // Once a day
}
Watch* WatchServer::watch()
@@ -53,6 +58,17 @@ void WatchServer::addProvider(NotificationProvider *provider)
// And that's it, really.
}
+QList<Notification*> WatchServer::liveNotifications()
+{
+ QList<Notification*> notifications;
+
+ for (int i = 0; i < Notification::TypeCount; i++) {
+ notifications.append(_notifications[i]);
+ }
+
+ return notifications;
+}
+
void WatchServer::runWatchlet(const QString& id)
{
if (_currentWatchlet) {
@@ -105,16 +121,12 @@ void WatchServer::nextWatchlet()
}
}
-void WatchServer::nextNotification()
+void WatchServer::syncTime()
{
- if (!_watch->isConnected()) return;
- if (!_pendingNotifications.empty()) {
- Notification *n = _pendingNotifications.head();
- _watch->displayNotification(n);
- } else if (_currentWatchlet) {
- reactivateCurrentWatchlet();
- } else {
- goToIdle();
+ if (_watch->isConnected()) {
+ qDebug() << "syncing watch time";
+ _watch->setDateTime(QDateTime::currentDateTime());
+ _syncTimeTimer->start();
}
}
@@ -137,6 +149,7 @@ void WatchServer::goToIdle()
void WatchServer::watchConnected()
{
+ syncTime();
if (!_pendingNotifications.isEmpty()) {
nextNotification();
} else if (_currentWatchlet) {
@@ -148,6 +161,7 @@ void WatchServer::watchConnected()
void WatchServer::watchDisconnected()
{
+ _syncTimeTimer->stop();
if (_currentWatchlet) {
_currentWatchlet->deactivate();
}
@@ -184,7 +198,7 @@ void WatchServer::postNotification(Notification *notification)
_notifications[type].append(notification);
connect(notification, SIGNAL(changed()), SLOT(notificationChanged()));
- connect(notification, SIGNAL(cleared()), SLOT(notificationCleared()));
+ connect(notification, SIGNAL(dismissed()), SLOT(notificationDismissed()));
qDebug() << "notification received" << notification->title() << "(" << notification->count() << ")";
@@ -207,6 +221,19 @@ void WatchServer::postNotification(Notification *notification)
}
}
+void WatchServer::nextNotification()
+{
+ if (!_watch->isConnected()) return;
+ if (!_pendingNotifications.empty()) {
+ Notification *n = _pendingNotifications.head();
+ _watch->displayNotification(n);
+ } else if (_currentWatchlet) {
+ reactivateCurrentWatchlet();
+ } else {
+ goToIdle();
+ }
+}
+
void WatchServer::notificationChanged()
{
QObject *obj = sender();
@@ -223,7 +250,7 @@ void WatchServer::notificationChanged()
}
}
-void WatchServer::notificationCleared()
+void WatchServer::notificationDismissed()
{
QObject *obj = sender();
if (obj) {
@@ -231,7 +258,7 @@ void WatchServer::notificationCleared()
const Notification::Type type = n->type();
_notifications[type].removeOne(n);
- qDebug() << "notification deleted" << n->title() << "(" << n->count() << ")";
+ qDebug() << "notification dismissed" << n->title() << "(" << n->count() << ")";
_watch->updateNotificationCount(type, getNotificationCount(type));
diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h
index 66c941a..a773749 100644
--- a/libsowatch/watchserver.h
+++ b/libsowatch/watchserver.h
@@ -5,6 +5,7 @@
#include <QtCore/QStringList>
#include <QtCore/QMap>
#include <QtCore/QQueue>
+#include <QtCore/QTimer>
#include "sowatch_global.h"
#include "notification.h"
@@ -32,12 +33,19 @@ public:
void addProvider(NotificationProvider* provider);
+ /** Get a list of all current live notifications. */
+ QList<Notification*> liveNotifications();
+
public slots:
void postNotification(Notification *notification);
+ void nextNotification();
+
void runWatchlet(const QString& id);
void closeWatchlet();
void nextWatchlet();
+ void syncTime();
+
private:
Watch* _watch;
@@ -61,10 +69,12 @@ private:
/** The current watchlet index if any, for use by nextWatchlet() */
int _currentWatchletIndex;
+ /** Used for periodic time syncing. */
+ QTimer* _syncTimeTimer;
+
void registerWatchlet(Watchlet *watchlet);
void reactivateCurrentWatchlet();
- void nextNotification();
uint getNotificationCount(Notification::Type type);
void goToIdle();
@@ -76,7 +86,7 @@ private slots:
void watchButtonPress(int button);
void notificationChanged();
- void notificationCleared();
+ void notificationDismissed();
friend class Watchlet;
};
diff --git a/libsowatch/watchsimulator.h b/libsowatch/watchsimulator.h
index c9d69ba..8189dfe 100644
--- a/libsowatch/watchsimulator.h
+++ b/libsowatch/watchsimulator.h
@@ -1,14 +1,13 @@
#ifndef SOWATCH_WATCHSIMULATOR_H
#define SOWATCH_WATCHSIMULATOR_H
-#include <QtGui/QImage>
-
#include "watch.h"
+#include "sowatch_global.h"
namespace sowatch
{
-class WatchSimulator : public Watch
+class SOWATCH_EXPORT WatchSimulator : public Watch
{
Q_OBJECT
public: