summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
m---------libwatchfish0
-rw-r--r--notificationconn.cc24
-rw-r--r--notificationconn.h14
-rw-r--r--sailfish/notificationmonitor.cpp79
-rw-r--r--sailfish/notificationmonitor.h28
-rw-r--r--sailfish/org.freedesktop.Notifications.xml17
-rw-r--r--sapd.pro9
8 files changed, 37 insertions, 137 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..166ca1b
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "libwatchfish"]
+ path = libwatchfish
+ url = https://git.javispedro.com/libwatchfish.git
diff --git a/libwatchfish b/libwatchfish
new file mode 160000
+Subproject 7ee859f6a5e6a334a172015fce744baeff53905
diff --git a/notificationconn.cc b/notificationconn.cc
index 231427e..9d596ea 100644
--- a/notificationconn.cc
+++ b/notificationconn.cc
@@ -7,7 +7,10 @@
#include "notificationconn.h"
#if SAILFISH
-#include "sailfish/notificationmonitor.h"
+#include "libwatchfish/notificationmonitor.h"
+#include "libwatchfish/notification.h"
+
+static watchfish::NotificationMonitor *monitor = 0;
#endif
NotificationConn::Notification::Notification()
@@ -113,9 +116,11 @@ void NotificationConn::handleConnected()
qDebug() << "NotificationManager socket now connected!";
#if SAILFISH
- NotificationMonitor *monitor = NotificationMonitor::instance();
- connect(monitor, SIGNAL(incomingNotification(QString,QIcon,QString,int,QString,QDateTime)),
- this, SLOT(handleIncomingNotification(QString,QIcon,QString,int,QString,QDateTime)));
+ if (!monitor) {
+ monitor = new watchfish::NotificationMonitor;
+ }
+ connect(monitor, &watchfish::NotificationMonitor::notification,
+ this, &NotificationConn::handleNotification);
#else
QTimer::singleShot(2000, this, SLOT(performTest()));
#endif
@@ -131,8 +136,10 @@ void NotificationConn::handleMessageReceived()
// TODO Seems that we receive the notification ID that we should act upon.
}
-void NotificationConn::handleIncomingNotification(const QString &sender, const QIcon &icon, const QString &summary, int count, const QString &body, const QDateTime &dateTime)
+#if SAILFISH
+void NotificationConn::handleNotification(watchfish::Notification *wfn)
{
+ QString sender = wfn->sender();
short applicationId = _knownSenders.value(sender, 0);
if (!applicationId) {
applicationId = _knownSenders.size() + 1;
@@ -142,11 +149,11 @@ void NotificationConn::handleIncomingNotification(const QString &sender, const Q
Notification n;
n.sequenceNumber = ++_lastSeqNumber;
n.type = NotificationPopup;
- n.time = dateTime;
- n.title = summary;
+ n.time = wfn->timestamp();
+ n.title = wfn->summary();
n.packageName = sender;
n.applicationName = sender;
- n.body = body;
+ n.body = wfn->body();
n.sender = 0;
n.count = 0; // TODO figure this out
n.category = 0;
@@ -155,6 +162,7 @@ void NotificationConn::handleIncomingNotification(const QString &sender, const Q
sendNotification(n);
}
+#endif
void NotificationConn::performTest()
{
diff --git a/notificationconn.h b/notificationconn.h
index da3e3c3..69f2244 100644
--- a/notificationconn.h
+++ b/notificationconn.h
@@ -6,6 +6,14 @@
#include "sapconnection.h"
#include "sapsocket.h"
+#if SAILFISH
+namespace watchfish
+{
+class Notification;
+class NotificationMonitor;
+}
+#endif
+
class NotificationConn : public QObject
{
Q_OBJECT
@@ -59,7 +67,11 @@ protected:
private slots:
void handleConnected();
void handleMessageReceived();
- void handleIncomingNotification(const QString &sender, const QIcon &icon, const QString &summary, int count, const QString &body, const QDateTime &dateTime);
+
+#if SAILFISH
+ void handleNotification(watchfish::Notification *n);
+#endif
+
void performTest();
private:
diff --git a/sailfish/notificationmonitor.cpp b/sailfish/notificationmonitor.cpp
deleted file mode 100644
index f22ce02..0000000
--- a/sailfish/notificationmonitor.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include <QtCore/QDebug>
-#include <QtGui/QIcon>
-#include <QtDBus/QDBusConnection>
-#include <QtDBus/QDBusConnectionInterface>
-
-#include "notificationmonitor.h"
-#include "notifications_adaptor.h"
-
-static NotificationMonitor *global_monitor = 0;
-
-NotificationMonitor::NotificationMonitor(QObject *parent) :
- QObject(parent)
-{
- QDBusConnection bus = QDBusConnection::sessionBus();
- QDBusConnectionInterface *dbus = bus.interface();
- dbus->call("AddMatch",
- "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'");
- new NotificationsAdaptor(this);
- bus.registerObject("/org/freedesktop/Notifications", this);
-}
-
-NotificationMonitor::~NotificationMonitor()
-{
- QDBusConnection bus = QDBusConnection::sessionBus();
- QDBusConnectionInterface *dbus = bus.interface();
- dbus->call("RemoveMatch",
- "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'");
-}
-
-NotificationMonitor *NotificationMonitor::instance()
-{
- if (!global_monitor) {
- global_monitor = new NotificationMonitor;
- }
- return global_monitor;
-}
-
-uint NotificationMonitor::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout)
-{
- QIcon icon;
-
- qDebug() << "Got notification" << app_name << app_icon << summary << body;
-
- // Avoid sending a reply for this method call, since we've received it
- // because we're eavesdropping.
- // The actual target of the method call will send the proper reply, not us.
- Q_ASSERT(calledFromDBus());
- setDelayedReply(true);
-
- // If the notification mentions a specific icon, then use it.
- // But otherwise let's prefer our builtin icons.
- if (app_icon.startsWith("/")) {
- icon = QIcon(app_icon);
- } else if (app_icon.startsWith("file:")) {
- QUrl url(app_icon);
- icon = QIcon(url.toLocalFile());
- } else {
- QString category = hints.value("category").toString();
- // Let's hardcode a few categories for now..
- if (!category.isEmpty()) {
- qDebug() << "TODO: Category icons";
- }
- }
-
- int count = hints.value("x-nemo-item-count").toInt();
- QDateTime dateTime = hints.value("x-nemo-timestamp").toDateTime();
- if (!dateTime.isValid()) {
- dateTime = QDateTime::currentDateTime();
- }
-
- if (summary.isEmpty() && body.isEmpty()) {
- // Avoid sending empty notifications to watch.
- return 0;
- }
-
- emit incomingNotification(app_name, icon, summary, count, body, dateTime);
-
- return 0;
-}
diff --git a/sailfish/notificationmonitor.h b/sailfish/notificationmonitor.h
deleted file mode 100644
index c0f7691..0000000
--- a/sailfish/notificationmonitor.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef NOTIFICATIONMONITOR_H
-#define NOTIFICATIONMONITOR_H
-
-#include <QtCore/QObject>
-#include <QtCore/QDateTime>
-#include <QtDBus/QDBusContext>
-
-class NotificationMonitor : public QObject, protected QDBusContext
-{
- Q_OBJECT
-
-public:
- ~NotificationMonitor();
-
- static NotificationMonitor *instance();
-
-signals:
- void incomingNotification(const QString &sender, const QIcon &icon, const QString &summary, int count, const QString &body, const QDateTime &dateTime);
-
-private:
- explicit NotificationMonitor(QObject *parent = 0);
-
-private slots:
- friend class NotificationsAdaptor;
- uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout);
-};
-
-#endif // NOTIFICATIONMONITOR_H
diff --git a/sailfish/org.freedesktop.Notifications.xml b/sailfish/org.freedesktop.Notifications.xml
deleted file mode 100644
index d3f8bef..0000000
--- a/sailfish/org.freedesktop.Notifications.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
-<node>
- <interface name="org.freedesktop.Notifications">
- <!-- (Partial) Desktop Notification Specification interface -->
- <method name="Notify">
- <arg name="app_name" type="s" direction="in"/>
- <arg name="replaces_id" type="u" direction="in"/>
- <arg name="app_icon" type="s" direction="in"/>
- <arg name="summary" type="s" direction="in"/>
- <arg name="body" type="s" direction="in"/>
- <arg name="actions" type="as" direction="in"/>
- <arg name="hints" type="a{sv}" direction="in"/>
- <arg name="expire_timeout" type="i" direction="in"/>
- <arg name="id" type="u" direction="out"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.In6" value="QVariantHash"/>
- </method>
-</node>
diff --git a/sapd.pro b/sapd.pro
index f2157d4..051c2c7 100644
--- a/sapd.pro
+++ b/sapd.pro
@@ -7,12 +7,13 @@ CONFIG += link_pkgconfig
PKGCONFIG += openssl
exists(/usr/lib/libsailfishapp.so) {
- # Building for Jolla Sailfish, Qt5, Bluez5
+ # Building for Jolla Sailfish, Qt5, Bluez4
QT += bluetooth
DEFINES += SAILFISH
- DBUS_ADAPTORS += sailfish/org.freedesktop.Notifications.xml
- SOURCES += sailfish/notificationmonitor.cpp
- HEADERS += sailfish/notificationmonitor.h
+ PKGCONFIG += dbus-1
+ CONFIG += c++11
+ SOURCES += libwatchfish/notificationmonitor.cpp libwatchfish/notification.cpp
+ HEADERS += libwatchfish/notificationmonitor.h libwatchfish/notification.h
} else:greaterThan(QT_MAJOR_VERSION, 4) {
# Building for desktop, Qt5, Bluez5
QT += bluetooth