summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'daemon')
-rw-r--r--daemon/daemon.cpp4
-rw-r--r--daemon/daemon.pro5
-rw-r--r--daemon/manager.cpp64
-rw-r--r--daemon/manager.h16
-rw-r--r--daemon/notificationmanager.cpp222
-rw-r--r--daemon/notificationmanager.h51
-rw-r--r--daemon/settings.h24
-rw-r--r--daemon/watchconnector.cpp15
-rw-r--r--daemon/watchconnector.h4
9 files changed, 357 insertions, 48 deletions
diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp
index 6fa634c..e075c0c 100644
--- a/daemon/daemon.cpp
+++ b/daemon/daemon.cpp
@@ -85,10 +85,10 @@ int main(int argc, char *argv[])
watch::WatchConnector watch;
DBusConnector dbus;
VoiceCallManager voice;
-
+ NotificationManager notifications;
Settings settings;
- Manager manager(&watch, &dbus, &voice, &settings);
+ Manager manager(&watch, &dbus, &voice, &notifications, &settings);
signal(SIGINT, signalhandler);
signal(SIGTERM, signalhandler);
diff --git a/daemon/daemon.pro b/daemon/daemon.pro
index d77be1a..df7b887 100644
--- a/daemon/daemon.pro
+++ b/daemon/daemon.pro
@@ -5,7 +5,7 @@ CONFIG += link_pkgconfig
QT -= gui
QT += bluetooth dbus contacts
-PKGCONFIG += commhistory-qt5 mlite5
+PKGCONFIG += mlite5
QMAKE_CXXFLAGS += -std=c++0x
LIBS += -L$$OUT_PWD/../ext/Log4Qt/ -llog4qt
@@ -19,6 +19,7 @@ SOURCES += \
manager.cpp \
voicecallmanager.cpp \
voicecallhandler.cpp \
+ notificationmanager.cpp \
watchconnector.cpp \
dbusconnector.cpp \
dbusadaptor.cpp \
@@ -28,6 +29,7 @@ HEADERS += \
manager.h \
voicecallmanager.h \
voicecallhandler.h \
+ notificationmanager.h \
watchconnector.h \
dbusconnector.h \
dbusadaptor.h \
@@ -62,5 +64,4 @@ lib.files += $$OUT_PWD/../ext/Log4Qt/*.s*
lib.path = /usr/share/pebble/lib
# unnecesary includes, just so QtCreator could find headers... :-(
-INCLUDEPATH += $$[QT_HOST_PREFIX]/include/commhistory-qt5
INCLUDEPATH += $$[QT_HOST_PREFIX]/include/mlite5
diff --git a/daemon/manager.cpp b/daemon/manager.cpp
index e97da41..bdda77b 100644
--- a/daemon/manager.cpp
+++ b/daemon/manager.cpp
@@ -5,10 +5,12 @@
#include <QtContacts/QContact>
#include <QtContacts/QContactPhoneNumber>
-Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, Settings *settings) :
- QObject(0), watch(watch), dbus(dbus), voice(voice), commands(new WatchCommands(watch, this)),
+Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, NotificationManager *notifications, Settings *settings) :
+ QObject(0), watch(watch), dbus(dbus), voice(voice), notifications(notifications), commands(new WatchCommands(watch, this)),
settings(settings), notification(MNotification::DeviceEvent)
{
+ notifications->setSettings(settings);;
+
connect(settings, SIGNAL(valueChanged(QString)), SLOT(onSettingChanged(const QString&)));
connect(settings, SIGNAL(valuesChanged()), SLOT(onSettingsChanged()));
//connect(settings, SIGNAL(silentWhenConnectedChanged(bool)), SLOT(onSilentWhenConnectedChanged(bool)));
@@ -21,14 +23,16 @@ 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(watch, SIGNAL(connectedChanged()), SLOT(onConnectedChanged()));
connect(voice, SIGNAL(activeVoiceCallChanged()), SLOT(onActiveVoiceCallChanged()));
connect(voice, SIGNAL(error(const QString &)), SLOT(onVoiceError(const QString &)));
- connect(watch, SIGNAL(connectedChanged()), SLOT(onConnectedChanged()));
+ 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(notifications, SIGNAL(twitterNotify(const QString &,const QString &)), SLOT(onTwitterNotify(const QString &,const QString &)));
+ connect(notifications, SIGNAL(facebookNotify(const QString &,const QString &)), SLOT(onFacebookNotify(const QString &,const QString &)));
connect(watch, SIGNAL(messageDecoded(uint,QByteArray)), commands, SLOT(processMessage(uint,QByteArray)));
connect(commands, SIGNAL(hangup()), SLOT(hangupAll()));
@@ -65,7 +69,6 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan
void Manager::onSettingChanged(const QString &key)
{
logger()->debug() << __FUNCTION__ << key << ":" << settings->property(qPrintable(key));
- if (key == "silentWhenConnected") applyProfile();
}
void Manager::onSettingsChanged()
@@ -188,45 +191,38 @@ 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;
- }
+ watch->sendSMSNotification(sender, data);
+}
- connect(group, SIGNAL(unreadMessagesChanged()), SLOT(onUnreadMessagesChanged()));
- if (group->unreadMessages()) processUnreadMessages(group);
+void Manager::onTwitterNotify(const QString &sender, const QString &data)
+{
+ watch->sendTwitterNotification(sender, data);
}
-void Manager::onUnreadMessagesChanged()
+void Manager::onFacebookNotify(const QString &sender, const QString &data)
{
- GroupObject *group = qobject_cast<GroupObject*>(sender());
- if (!group) {
- logger()->debug() << "Got unreadMessagesChanged for null group";
- return;
- }
- processUnreadMessages(group);
+ watch->sendFacebookNotification(sender, data);
}
-void Manager::processUnreadMessages(GroupObject *group)
+
+void Manager::onEmailNotify(const QString &sender, const QString &data,const QString &subject)
{
- 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";
+ watch->sendEmailNotification(sender, data, subject);
+}
+
+void Manager::hangupAll()
+{
+ foreach (VoiceCallHandler* handler, voice->voiceCalls()) {
+ handler->hangup();
}
}
diff --git a/daemon/manager.h b/daemon/manager.h
index 26a0fd8..4a55256 100644
--- a/daemon/manager.h
+++ b/daemon/manager.h
@@ -4,6 +4,7 @@
#include "watchconnector.h"
#include "dbusconnector.h"
#include "voicecallmanager.h"
+#include "notificationmanager.h"
#include "watchcommands.h"
#include "settings.h"
@@ -12,12 +13,10 @@
#include <QDBusContext>
#include <QtContacts/QContactManager>
#include <QtContacts/QContactDetailFilter>
-#include <CommHistory/GroupModel>
#include <MNotification>
#include "Logger"
using namespace QtContacts;
-using namespace CommHistory;
class Manager :
public QObject,
@@ -36,6 +35,7 @@ class Manager :
watch::WatchConnector *watch;
DBusConnector *dbus;
VoiceCallManager *voice;
+ NotificationManager *notifications;
WatchCommands *commands;
@@ -45,17 +45,15 @@ class Manager :
QContactManager *contacts;
QContactDetailFilter numberFilter;
- GroupManager *conversations;
QString defaultProfile;
QString lastSeenMpris;
public:
- explicit Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, Settings *settings);
+ explicit Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, NotificationManager *notifications, Settings *settings);
Q_INVOKABLE QString findPersonByNumber(QString number);
- Q_INVOKABLE void processUnreadMessages(GroupObject *group);
Q_INVOKABLE QString getCurrentProfile();
Q_INVOKABLE QString mpris();
QVariantMap mprisMetadata;
@@ -76,12 +74,14 @@ 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 onTwitterNotify(const QString &sender, const QString &data);
+ void onFacebookNotify(const QString &sender, const QString &data);
+ void onEmailNotify(const QString &sender, const QString &data,const QString &subject);
void onMprisPropertiesChanged(QString,QMap<QString,QVariant>,QStringList);
void setMprisMetadata(QDBusArgument metadata);
void setMprisMetadata(QVariantMap metadata);
-
};
class PebbledProxy : public QObject
diff --git a/daemon/notificationmanager.cpp b/daemon/notificationmanager.cpp
new file mode 100644
index 0000000..ad2c98f
--- /dev/null
+++ b/daemon/notificationmanager.cpp
@@ -0,0 +1,222 @@
+#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::getCleanAppName(QString app_name)
+{
+ QString desktopFile = QString("/usr/share/applications/%1.desktop").arg(app_name);
+ 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;
+}
+
+QStringHash NotificationManager::getCategoryParams(QString category)
+{
+ if (!category.isEmpty()) {
+ QString categoryConfigFile = QString("/usr/share/lipstick/notificationcategories/%1.conf").arg(category);
+ QFile testFile(categoryConfigFile);
+ if (testFile.exists()) {
+ QStringHash categories;
+ QSettings settings(categoryConfigFile, QSettings::IniFormat);
+ const QStringList settingKeys = settings.allKeys();
+ foreach (const QString &settingKey, settingKeys) {
+ categories[settingKey] = settings.value(settingKey).toString();
+ }
+ return categories;
+ }
+ }
+ return QStringHash();
+}
+
+void NotificationManager::setSettings(Settings *settings)
+{
+ this->settings = settings;
+}
+
+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)
+{
+ Q_UNUSED(replaces_id);
+ Q_UNUSED(app_icon);
+ Q_UNUSED(actions);
+ Q_UNUSED(expire_timeout);
+
+ //Ignore notifcations from myself
+ if (app_name == "pebbled") {
+ return;
+ }
+
+ logger()->debug() << Q_FUNC_INFO << "Got notification via dbus from" << this->getCleanAppName(app_name);
+ logger()->debug() << hints;
+
+ if (app_name == "messageserver5") {
+
+ if (!settings->property("notificationsEmails").toBool()) {
+ logger()->debug() << "Ignoring email notification because of setting!";
+ return;
+ }
+
+ QString subject = hints.value("x-nemo-preview-summary", "").toString();
+ QString data = hints.value("x-nemo-preview-body", "").toString();
+ if (!data.isEmpty() && !subject.isEmpty()) {
+ emit this->emailNotify(subject, data, "");
+ }
+ } else if (app_name == "commhistoryd") {
+ if (summary == "" && body == "") {
+ QString category = hints.value("category", "").toString();
+
+ if (category == "x-nemo.call.missed") {
+ if (!settings->property("notificationsMissedCall").toBool()) {
+ logger()->debug() << "Ignoring MissedCall notification because of setting!";
+ return;
+ }
+ } else {
+ if (!settings->property("notificationsCommhistoryd").toBool()) {
+ logger()->debug() << "Ignoring commhistoryd notification because of setting!";
+ return;
+ }
+ }
+ emit this->smsNotify(hints.value("x-nemo-preview-summary", "default").toString(),
+ hints.value("x-nemo-preview-body", "default").toString()
+ );
+ }
+ } else if (app_name == "harbour-mitakuuluu2-server") {
+
+ if (!settings->property("notificationsMitakuuluu").toBool()) {
+ logger()->debug() << "Ignoring mitakuuluu notification because of setting!";
+ return;
+ }
+
+ emit this->smsNotify(hints.value("x-nemo-preview-body", "default").toString(),
+ hints.value("x-nemo-preview-summary", "default").toString()
+ );
+
+ } else if (app_name == "twitter-notifications-client") {
+
+ if (!settings->property("notificationsTwitter").toBool()) {
+ logger()->debug() << "Ignoring twitter notification because of setting!";
+ return;
+ }
+
+ emit this->twitterNotify(hints.value("x-nemo-preview-body", body).toString(),
+ hints.value("x-nemo-preview-summary", summary).toString()
+ );
+
+ } else {
+ //Prioritize x-nemo-preview* over dbus direct summary and body
+ QString subject = hints.value("x-nemo-preview-summary", "").toString();
+ QString data = hints.value("x-nemo-preview-body", "").toString();
+ QString category = hints.value("category", "").toString();
+ QStringHash categoryParams = this->getCategoryParams(category);
+ int prio = categoryParams.value("x-nemo-priority", "0").toInt();
+
+ logger()->debug() << "MSG Prio:" << prio;
+
+ if (!settings->property("notificationsAll").toBool() && prio <= 10) {
+ logger()->debug() << "Ignoring notification because of setting! (all)";
+ return;
+ }
+
+ if (!settings->property("notificationsOther").toBool() && prio < 90) {
+ logger()->debug() << "Ignoring notification because of setting! (other)";
+ return;
+ }
+
+ if (subject.isEmpty()) {
+ subject = summary;
+ }
+ if (data.isEmpty()) {
+ data = body;
+ }
+
+ //Prioritize data over subject
+ if (data.isEmpty() && !subject.isEmpty()) {
+ data = subject;
+ subject = "";
+ }
+
+ //Never send empty data and subject
+ if (data.isEmpty() && subject.isEmpty()) {
+ logger()->warn() << Q_FUNC_INFO << "Empty subject and data in dbus app " << app_name;
+ return;
+ }
+
+ emit this->emailNotify(this->getCleanAppName(app_name), data, subject);
+ }
+}
diff --git a/daemon/notificationmanager.h b/daemon/notificationmanager.h
new file mode 100644
index 0000000..4695db9
--- /dev/null
+++ b/daemon/notificationmanager.h
@@ -0,0 +1,51 @@
+#ifndef NOTIFICATIONMANAGER_H
+#define NOTIFICATIONMANAGER_H
+
+#include <QObject>
+#include "Logger"
+#include "settings.h"
+
+#include <QDBusInterface>
+#include <QDBusPendingCallWatcher>
+
+typedef QHash<QString, QString> QStringHash;
+
+class NotificationManager : public QObject
+{
+ Q_OBJECT
+ LOG4QT_DECLARE_QCLASS_LOGGER
+ 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 twitterNotify(const QString &sender, const QString &data);
+ void facebookNotify(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);
+ void setSettings(Settings *settings);
+
+protected Q_SLOTS:
+ void initialize(bool notifyError = false);
+
+private:
+ class NotificationManagerPrivate *d_ptr;
+
+ QString getCleanAppName(QString app_name);
+ QStringHash getCategoryParams(QString category);
+ Settings *settings;
+
+ Q_DISABLE_COPY(NotificationManager)
+ Q_DECLARE_PRIVATE(NotificationManager)
+};
+
+#endif // NOTIFICATIONMANAGER_H
diff --git a/daemon/settings.h b/daemon/settings.h
index 50ffd86..1f2e2e5 100644
--- a/daemon/settings.h
+++ b/daemon/settings.h
@@ -8,7 +8,23 @@ class Settings : public MDConfGroup
Q_OBJECT
Q_PROPERTY(bool silentWhenConnected MEMBER silentWhenConnected NOTIFY silentWhenConnectedChanged)
+ Q_PROPERTY(bool notificationsCommhistoryd MEMBER notificationsCommhistoryd NOTIFY notificationsCommhistorydChanged)
+ Q_PROPERTY(bool notificationsMissedCall MEMBER notificationsMissedCall NOTIFY notificationsMissedCallChanged)
+ Q_PROPERTY(bool notificationsEmails MEMBER notificationsEmails NOTIFY notificationsEmailsChanged)
+ Q_PROPERTY(bool notificationsMitakuuluu MEMBER notificationsMitakuuluu NOTIFY notificationsMitakuuluuChanged)
+ Q_PROPERTY(bool notificationsTwitter MEMBER notificationsTwitter NOTIFY notificationsTwitterChanged)
+ Q_PROPERTY(bool notificationsFacebook MEMBER notificationsFacebook NOTIFY notificationsFacebookChanged)
+ Q_PROPERTY(bool notificationsOther MEMBER notificationsOther NOTIFY notificationsOtherChanged)
+ Q_PROPERTY(bool notificationsAll MEMBER notificationsAll NOTIFY notificationsAllChanged)
bool silentWhenConnected;
+ bool notificationsCommhistoryd;
+ bool notificationsMissedCall;
+ bool notificationsEmails;
+ bool notificationsMitakuuluu;
+ bool notificationsTwitter;
+ bool notificationsFacebook;
+ bool notificationsOther;
+ bool notificationsAll;
public:
explicit Settings(QObject *parent = 0) :
@@ -17,6 +33,14 @@ public:
signals:
void silentWhenConnectedChanged(bool);
+ void notificationsCommhistorydChanged(bool);
+ void notificationsMissedCallChanged(bool);
+ void notificationsEmailsChanged(bool);
+ void notificationsMitakuuluuChanged(bool);
+ void notificationsTwitterChanged(bool);
+ void notificationsFacebookChanged(bool);
+ void notificationsOtherChanged(bool);
+ void notificationsAllChanged(bool);
public slots:
diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp
index 70b8e6f..e9066ce 100644
--- a/daemon/watchconnector.cpp
+++ b/daemon/watchconnector.cpp
@@ -178,9 +178,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');
}
}
@@ -282,6 +283,16 @@ void WatchConnector::sendSMSNotification(QString sender, QString data)
sendNotification(leadSMS, sender, data, "");
}
+void WatchConnector::sendFacebookNotification(QString sender, QString data)
+{
+ sendNotification(leadFACEBOOK, sender, data, "");
+}
+
+void WatchConnector::sendTwitterNotification(QString sender, QString data)
+{
+ sendNotification(leadTWITTER, sender, data, "");
+}
+
void WatchConnector::sendEmailNotification(QString sender, QString data, QString subject)
{
sendNotification(leadEMAIL, sender, data, subject);
diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h
index cdaf059..deb4894 100644
--- a/daemon/watchconnector.h
+++ b/daemon/watchconnector.h
@@ -102,6 +102,8 @@ public:
enum {
leadEMAIL = 0,
leadSMS = 1,
+ leadFACEBOOK = 2,
+ leadTWITTER = 3,
leadNOW_PLAYING_DATA = 16
};
enum {
@@ -149,6 +151,8 @@ public slots:
void sendNotification(uint lead, QString sender, QString data, QString subject);
void sendSMSNotification(QString sender, QString data);
void sendEmailNotification(QString sender, QString data, QString subject);
+ void sendFacebookNotification(QString sender, QString data);
+ void sendTwitterNotification(QString sender, QString data);
void sendMusicNowPlaying(QString track, QString album, QString artist);
void sendPhoneVersion();