summaryrefslogtreecommitdiff
path: root/libsowatch
diff options
context:
space:
mode:
Diffstat (limited to 'libsowatch')
-rw-r--r--libsowatch/declarativewatchlet.cpp10
-rw-r--r--libsowatch/declarativewatchlet.h4
-rw-r--r--libsowatch/notification.cpp19
-rw-r--r--libsowatch/notification.h1
-rw-r--r--libsowatch/watchletplugininterface.h2
-rw-r--r--libsowatch/watchserver.cpp20
-rw-r--r--libsowatch/watchserver.h5
7 files changed, 51 insertions, 10 deletions
diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp
index 7e6768e..60538f8 100644
--- a/libsowatch/declarativewatchlet.cpp
+++ b/libsowatch/declarativewatchlet.cpp
@@ -54,6 +54,16 @@ void DeclarativeWatchlet::setSource(const QUrl &url)
}
}
+QDeclarativeEngine* DeclarativeWatchlet::engine()
+{
+ return _engine;
+}
+
+QDeclarativeContext* DeclarativeWatchlet::rootContext()
+{
+ return _engine->rootContext();
+}
+
void DeclarativeWatchlet::activate()
{
Watchlet::activate();
diff --git a/libsowatch/declarativewatchlet.h b/libsowatch/declarativewatchlet.h
index 2cc4655..0dd7e23 100644
--- a/libsowatch/declarativewatchlet.h
+++ b/libsowatch/declarativewatchlet.h
@@ -2,6 +2,7 @@
#define SOWATCH_DECLARATIVEWATCHLET_H
#include <QtDeclarative/QDeclarativeEngine>
+#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeComponent>
#include <QtDeclarative/QDeclarativeItem>
#include "graphicswatchlet.h"
@@ -20,6 +21,9 @@ public:
void setSource(const QUrl& url);
+ QDeclarativeEngine* engine();
+ QDeclarativeContext* rootContext();
+
protected slots:
void handleComponentStatus(QDeclarativeComponent::Status status);
diff --git a/libsowatch/notification.cpp b/libsowatch/notification.cpp
index b4c97b2..e321b58 100644
--- a/libsowatch/notification.cpp
+++ b/libsowatch/notification.cpp
@@ -11,6 +11,25 @@ Notification::~Notification()
{
}
+QString Notification::displayTime() const
+{
+ QDateTime dt = dateTime();
+ int secsDiff = dt.secsTo(QDateTime::currentDateTime());
+ if (secsDiff < 1) {
+ return "";
+ } else if (secsDiff < 60) {
+ return tr("%n second(s) ago", "", secsDiff);
+ } else if (secsDiff < 60*60) {
+ int n = secsDiff / 60;
+ return tr("%n minute(s) ago", "", n);
+ } else if (secsDiff < 60*60*24) {
+ int n = secsDiff / 3600;
+ return tr("%n hour(s) ago", "", n);
+ } else {
+ return dt.toString(Qt::SystemLocaleShortDate);
+ }
+}
+
QImage Notification::image() const
{
return QImage();
diff --git a/libsowatch/notification.h b/libsowatch/notification.h
index 8e58653..3505c44 100644
--- a/libsowatch/notification.h
+++ b/libsowatch/notification.h
@@ -33,6 +33,7 @@ public:
virtual Type type() const = 0;
virtual uint count() const = 0;
virtual QDateTime dateTime() const = 0;
+ virtual QString displayTime() const;
virtual QString title() const = 0;
virtual QString body() const = 0;
virtual QImage image() const;
diff --git a/libsowatch/watchletplugininterface.h b/libsowatch/watchletplugininterface.h
index ad83dd4..4f525f2 100644
--- a/libsowatch/watchletplugininterface.h
+++ b/libsowatch/watchletplugininterface.h
@@ -18,7 +18,7 @@ public:
virtual ~WatchletPluginInterface();
virtual QStringList watchlets() = 0;
- virtual Watchlet* getProvider(const QString& id, QSettings& settings, WatchServer *server) = 0;
+ virtual Watchlet* getWatchlet(const QString& id, QSettings& settings, WatchServer *server) = 0;
};
}
diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp
index 39802f9..07e4609 100644
--- a/libsowatch/watchserver.cpp
+++ b/libsowatch/watchserver.cpp
@@ -11,6 +11,7 @@ using namespace sowatch;
WatchServer::WatchServer(Watch* watch, QObject* parent) :
QObject(parent), _watch(watch),
_nextWatchletButton(-1),
+ _oldNotificationThreshold(300),
_currentWatchlet(0), _currentWatchletIndex(-1)
{
connect(_watch, SIGNAL(connected()), SLOT(watchConnected()));
@@ -55,7 +56,7 @@ void WatchServer::addProvider(NotificationProvider *provider)
void WatchServer::runWatchlet(const QString& id)
{
if (_currentWatchlet) {
- closeWatchlet();
+ _currentWatchlet->deactivate();
}
qDebug() << "activating watchlet" << id;
_currentWatchlet = _watchlets[id];
@@ -67,11 +68,9 @@ void WatchServer::runWatchlet(const QString& id)
void WatchServer::closeWatchlet()
{
if (_currentWatchlet) {
- if (_watch->isConnected()) {
- _currentWatchlet->deactivate();
- }
+ _currentWatchlet->deactivate();
_currentWatchlet = 0;
- if (_pendingNotifications.empty()) {
+ if (_watch->isConnected() && _pendingNotifications.empty()) {
goToIdle();
}
}
@@ -94,7 +93,6 @@ void WatchServer::nextWatchlet()
{
QStringList watchlets = _watchlets.keys();
_currentWatchletIndex++;
- qDebug() << "next watchlet" << _currentWatchletIndex;
if (_currentWatchletIndex >= watchlets.size()) {
_currentWatchletIndex = -1;
closeWatchlet();
@@ -165,6 +163,7 @@ void WatchServer::watchIdling()
void WatchServer::watchButtonPress(int button)
{
if (button == _nextWatchletButton) {
+ qDebug() << "next watchlet button pressed";
if (_pendingNotifications.empty()) {
// No notifications: either app or idle mode.
nextWatchlet();
@@ -187,6 +186,12 @@ void WatchServer::notificationReceived(Notification *notification)
qDebug() << "notification received" << notification->title() << notification->count();
_watch->updateNotificationCount(type, getNotificationCount(type));
+
+ QDateTime oldThreshold = QDateTime::currentDateTime().addSecs(-_oldNotificationThreshold);
+ if (notification->dateTime() < oldThreshold) {
+ return; // Do not care about that old notifications...
+ }
+
if (_pendingNotifications.isEmpty()) {
_pendingNotifications.enqueue(notification);
nextNotification();
@@ -226,7 +231,8 @@ void WatchServer::notificationCleared()
qDebug() << "notification deleted" << n->title() << n->count();
_watch->updateNotificationCount(type, getNotificationCount(type));
- if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) {
+
+ if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) {qDebug() << "removing top notification";
_pendingNotifications.removeAll(n);
nextNotification();
} else {
diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h
index 681c758..a3e0593 100644
--- a/libsowatch/watchserver.h
+++ b/libsowatch/watchserver.h
@@ -37,7 +37,8 @@ public:
protected:
Watch* _watch;
- char _nextWatchletButton;
+ int _nextWatchletButton;
+ int _oldNotificationThreshold;
QMap<QString, Watchlet*> _watchlets;
@@ -46,7 +47,7 @@ protected:
QQueue<Notification*> _pendingNotifications;
Watchlet* _currentWatchlet;
- char _currentWatchletIndex;
+ unsigned char _currentWatchletIndex;
void registerWatchlet(Watchlet *watchlet);
void reactivateCurrentWatchlet();