summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'daemon')
-rw-r--r--daemon/daemon.cpp3
-rw-r--r--daemon/daemon.pro6
-rw-r--r--daemon/manager.cpp58
-rw-r--r--daemon/manager.h14
-rw-r--r--daemon/notificationmanager.cpp124
-rw-r--r--daemon/notificationmanager.h41
-rw-r--r--daemon/watchconnector.cpp5
7 files changed, 203 insertions, 48 deletions
diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp
index eba9afa..cd5e781 100644
--- a/daemon/daemon.cpp
+++ b/daemon/daemon.cpp
@@ -125,8 +125,9 @@ int main(int argc, char *argv[])
watch::WatchConnector watch;
DBusConnector dbus;
VoiceCallManager voice;
+ NotificationManager notifications;
- Manager manager(&watch, &dbus, &voice);
+ Manager manager(&watch, &dbus, &voice, &notifications);
signal(SIGINT, signalhandler);
signal(SIGTERM, signalhandler);
diff --git a/daemon/daemon.pro b/daemon/daemon.pro
index 9d1a441..e52e8e8 100644
--- a/daemon/daemon.pro
+++ b/daemon/daemon.pro
@@ -19,7 +19,8 @@ SOURCES += \
voicecallhandler.cpp \
watchconnector.cpp \
dbusconnector.cpp \
- dbusadaptor.cpp
+ dbusadaptor.cpp \
+ notificationmanager.cpp
HEADERS += \
manager.h \
@@ -27,7 +28,8 @@ HEADERS += \
voicecallhandler.h \
watchconnector.h \
dbusconnector.h \
- dbusadaptor.h
+ dbusadaptor.h \
+ notificationmanager.h
OTHER_FILES += \
org.pebbled.xml \
diff --git a/daemon/manager.cpp b/daemon/manager.cpp
index 8ff6785..0a5d722 100644
--- a/daemon/manager.cpp
+++ b/daemon/manager.cpp
@@ -5,8 +5,8 @@
#include <QtContacts/QContact>
#include <QtContacts/QContactPhoneNumber>
-Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice) :
- QObject(0), watch(watch), dbus(dbus), voice(voice),
+Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, NotificationManager *notifications) :
+ QObject(0), watch(watch), dbus(dbus), voice(voice), notifications(notifications),
notification(MNotification::DeviceEvent)
{
// We don't need to handle presence changes, so report them separately and ignore them
@@ -17,13 +17,13 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan
numberFilter.setDetailType(QContactDetail::TypePhoneNumber, QContactPhoneNumber::FieldNumber);
numberFilter.setMatchFlags(QContactFilter::MatchPhoneNumber);
- conversations = new GroupManager(this);
- connect(conversations, SIGNAL(groupAdded(GroupObject*)), SLOT(onConversationGroupAdded(GroupObject*)));
- conversations->getGroups();
-
connect(voice, SIGNAL(activeVoiceCallChanged()), SLOT(onActiveVoiceCallChanged()));
connect(voice, SIGNAL(error(const QString &)), SLOT(onVoiceError(const QString &)));
+ connect(notifications, SIGNAL(error(const QString &)), SLOT(onNotifyError(const QString &)));
+ connect(notifications, SIGNAL(emailNotify(const QString &,const QString &,const QString &)), SLOT(onEmailNotify(const QString &,const QString &,const QString &)));
+ connect(notifications, SIGNAL(smsNotify(const QString &,const QString &)), SLOT(onSmsNotify(const QString &,const QString &)));
+
connect(watch, SIGNAL(hangup()), SLOT(hangupAll()));
connect(watch, SIGNAL(connectedChanged()), SLOT(onConnectedChanged()));
@@ -144,44 +144,32 @@ void Manager::onVoiceError(const QString &message)
logger()->error() << "Error: " << message;
}
-void Manager::hangupAll()
+
+void Manager::onNotifyError(const QString &message)
{
- foreach (VoiceCallHandler* handler, voice->voiceCalls()) {
- handler->hangup();
- }
+ qWarning() << "Error: " << message;
}
-void Manager::onConversationGroupAdded(GroupObject *group)
+void Manager::onSmsNotify(const QString &sender, const QString &data)
{
- if (!group) {
- logger()->debug() << "Got null conversation group";
- return;
- }
-
- connect(group, SIGNAL(unreadMessagesChanged()), SLOT(onUnreadMessagesChanged()));
- if (group->unreadMessages()) processUnreadMessages(group);
+ logger()->debug() << "SMS:";
+ logger()->debug() << sender;
+ logger()->debug() << data;
+ watch->sendSMSNotification(sender, data);
}
-
-void Manager::onUnreadMessagesChanged()
+void Manager::onEmailNotify(const QString &sender, const QString &data,const QString &subject)
{
- GroupObject *group = qobject_cast<GroupObject*>(sender());
- if (!group) {
- logger()->debug() << "Got unreadMessagesChanged for null group";
- return;
- }
- processUnreadMessages(group);
+ logger()->debug() << "Email:";
+ logger()->debug() << sender;
+ logger()->debug() << data;
+ logger()->debug() << subject;
+ watch->sendEmailNotification(sender, data, subject);
}
-void Manager::processUnreadMessages(GroupObject *group)
+void Manager::hangupAll()
{
- if (group->unreadMessages()) {
- QString name = group->contactName();
- QString message = group->lastMessageText();
- logger()->debug() << "Msg:" << message;
- logger()->debug() << "From:" << name;
- watch->sendSMSNotification(name.isEmpty()?"Unknown":name, message);
- } else {
- logger()->debug() << "Got processUnreadMessages for group with no new messages";
+ foreach (VoiceCallHandler* handler, voice->voiceCalls()) {
+ handler->hangup();
}
}
diff --git a/daemon/manager.h b/daemon/manager.h
index db0d0d3..45ba50a 100644
--- a/daemon/manager.h
+++ b/daemon/manager.h
@@ -4,17 +4,16 @@
#include "watchconnector.h"
#include "dbusconnector.h"
#include "voicecallmanager.h"
+#include "notificationmanager.h"
#include <QObject>
#include <QBluetoothLocalDevice>
#include <QtContacts/QContactManager>
#include <QtContacts/QContactDetailFilter>
-#include <CommHistory/GroupModel>
#include <MNotification>
#include "Logger"
using namespace QtContacts;
-using namespace CommHistory;
class Manager : public QObject
{
@@ -28,18 +27,17 @@ class Manager : public QObject
watch::WatchConnector *watch;
DBusConnector *dbus;
VoiceCallManager *voice;
+ NotificationManager *notifications;
MNotification notification;
QContactManager *contacts;
QContactDetailFilter numberFilter;
- GroupManager *conversations;
public:
- explicit Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice);
+ explicit Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, NotificationManager *notifications);
Q_INVOKABLE QString findPersonByNumber(QString number);
- Q_INVOKABLE void processUnreadMessages(GroupObject *group);
signals:
@@ -52,9 +50,9 @@ protected slots:
void onActiveVoiceCallChanged();
void onVoiceError(const QString &message);
void onActiveVoiceCallStatusChanged();
- void onConversationGroupAdded(GroupObject *group);
- void onUnreadMessagesChanged();
-
+ void onNotifyError(const QString &message);
+ void onSmsNotify(const QString &sender, const QString &data);
+ void onEmailNotify(const QString &sender, const QString &data,const QString &subject);
};
class PebbledProxy : public QObject
diff --git a/daemon/notificationmanager.cpp b/daemon/notificationmanager.cpp
new file mode 100644
index 0000000..8a2129e
--- /dev/null
+++ b/daemon/notificationmanager.cpp
@@ -0,0 +1,124 @@
+#include "notificationmanager.h"
+
+#include <QDebug>
+#include <QTimer>
+#include <QFile>
+#include <QSettings>
+#include <QDBusInterface>
+#include <QDBusPendingReply>
+
+class NotificationManagerPrivate
+{
+ Q_DECLARE_PUBLIC(NotificationManager)
+
+public:
+ NotificationManagerPrivate(NotificationManager *q)
+ : q_ptr(q),
+ interface(NULL),
+ connected(false)
+ { /*...*/ }
+
+ NotificationManager *q_ptr;
+
+ QDBusInterface *interface;
+
+ bool connected;
+};
+
+NotificationManager::NotificationManager(QObject *parent)
+ : QObject(parent), d_ptr(new NotificationManagerPrivate(this))
+{
+ Q_D(NotificationManager);
+ QDBusConnection::sessionBus().registerObject("/org/freedesktop/Notifications", this, QDBusConnection::ExportAllSlots);
+
+ d->interface = new QDBusInterface("org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus");
+
+ d->interface->call("AddMatch", "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'");
+
+ this->initialize();
+}
+
+NotificationManager::~NotificationManager()
+{
+ Q_D(NotificationManager);
+ delete d;
+}
+
+
+void NotificationManager::initialize(bool notifyError)
+{
+ Q_D(NotificationManager);
+ bool success = false;
+
+ if(d->interface->isValid())
+ {
+ success = true;
+ }
+
+ if(!(d->connected = success))
+ {
+ QTimer::singleShot(2000, this, SLOT(initialize()));
+ if(notifyError) emit this->error("Failed to connect to Notifications D-Bus service.");
+ }
+}
+
+QDBusInterface* NotificationManager::interface() const
+{
+ Q_D(const NotificationManager);
+ return d->interface;
+}
+
+QString NotificationManager::detectCleanAppname(QString app_name)
+{
+ QString desktopFile = "/usr/share/applications/" + app_name + ".desktop";
+ QFile testFile(desktopFile);
+ if (testFile.exists()) {
+ QSettings settings(desktopFile, QSettings::IniFormat);
+ settings.beginGroup("Desktop Entry");
+ QString cleanName = settings.value("Name").toString();
+ settings.endGroup();
+ if (!cleanName.isEmpty()) {
+ return cleanName;
+ }
+ }
+ return app_name;
+}
+
+void NotificationManager::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) {
+
+ //Ignore notifcations from myself
+ if (app_name == "pebbled") {
+ return;
+ }
+
+ qDebug() << "Got notification via dbus from" << detectCleanAppname(app_name);
+
+ if (app_name == "messageserver5") {
+ emit this->emailNotify(hints.value("x-nemo-preview-summary", detectCleanAppname(app_name)).toString(),
+ hints.value("x-nemo-preview-body", "").toString(),
+ ""
+ );
+ } else if (app_name == "commhistoryd") {
+ if (summary == "" && body == "") {
+ emit this->smsNotify(hints.value("x-nemo-preview-summary", "default").toString(),
+ hints.value("x-nemo-preview-body", "default").toString()
+ );
+ }
+ } else {
+ QString data = summary;
+ QString subject = body;
+ if (data.isEmpty()) {
+ data = hints.value("x-nemo-preview-summary", "").toString();
+ }
+ if (subject.isEmpty()) {
+ subject = hints.value("x-nemo-preview-body", "").toString();
+ }
+ if (data.isEmpty() && !subject.isEmpty()) {
+ data = subject;
+ subject = "";
+ }
+ emit this->emailNotify(detectCleanAppname(app_name), data, subject);
+ }
+}
diff --git a/daemon/notificationmanager.h b/daemon/notificationmanager.h
new file mode 100644
index 0000000..dd3f8bb
--- /dev/null
+++ b/daemon/notificationmanager.h
@@ -0,0 +1,41 @@
+#ifndef NOTIFICATIONMANAGER_H
+#define NOTIFICATIONMANAGER_H
+
+#include <QObject>
+
+#include <QDBusInterface>
+#include <QDBusPendingCallWatcher>
+
+class NotificationManager : public QObject
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications")
+
+ Q_PROPERTY(QDBusInterface* interface READ interface)
+public:
+ explicit NotificationManager(QObject *parent = 0);
+ ~NotificationManager();
+
+ QDBusInterface* interface() const;
+
+Q_SIGNALS:
+ void error(const QString &message);
+ void smsNotify(const QString &sender, const QString &data);
+ void emailNotify(const QString &sender, const QString &data,const QString &subject);
+
+public Q_SLOTS:
+ void 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);
+
+protected Q_SLOTS:
+ void initialize(bool notifyError = false);
+
+private:
+ class NotificationManagerPrivate *d_ptr;
+
+ QString detectCleanAppname(QString app_name);
+
+ Q_DISABLE_COPY(NotificationManager)
+ Q_DECLARE_PRIVATE(NotificationManager)
+};
+
+#endif // NOTIFICATIONMANAGER_H
diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp
index 088384d..48fd52f 100644
--- a/daemon/watchconnector.cpp
+++ b/daemon/watchconnector.cpp
@@ -222,9 +222,10 @@ void WatchConnector::buildData(QByteArray &res, QStringList data)
{
for (QString d : data)
{
- QByteArray tmp = d.left(0xF0).toUtf8();
- res.append(tmp.length() & 0xFF);
+ QByteArray tmp = d.left(0xEF).toUtf8();
+ res.append((tmp.length() + 1) & 0xFF);
res.append(tmp);
+ res.append('\0');
}
}