From f2e25fa2dad53c4a71f78dda14daf7071a627f57 Mon Sep 17 00:00:00 2001 From: Ionutz Borcoman Date: Sun, 6 Mar 2011 11:01:46 +0200 Subject: [PATCH] added notification via libnotify and QMaemo5InformationBox. --- src/constants.h | 3 +++ src/genericnotify.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ src/genericnotify.h | 12 ++++++++++++ src/main.cpp | 3 +++ src/xbmc.cpp | 3 ++- src/xbmcnetmoviesremote.pro | 15 +++++++++++++-- 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/genericnotify.cpp create mode 100644 src/genericnotify.h diff --git a/src/constants.h b/src/constants.h index 2adece1..d5f8db2 100644 --- a/src/constants.h +++ b/src/constants.h @@ -11,4 +11,7 @@ #define SETUP_XBMC_PORT "xbmc/port" #define SETUP_XBMC_PORT_DEFAULT "9090" +#define SETUP_NOTIFICATION_TIMEOUT "notification/timeout" +#define SETUP_NOTIFICATION_TIMEOUT_DEFAULT 3000 + #endif // SETTINGS_H diff --git a/src/genericnotify.cpp b/src/genericnotify.cpp new file mode 100644 index 0000000..bdefdb7 --- /dev/null +++ b/src/genericnotify.cpp @@ -0,0 +1,44 @@ +#ifdef Q_WS_MAEMO_5 +#include +#else +#include +#endif + +#include "genericnotify.h" +#include "constants.h" +#include + +void notify::init() +{ +#ifdef Q_WS_MAEMO_5 +#else + /* Init libnotify library */ + notify_init(APPLICATION_NAME); +#endif +} + +void notify::notify(const QString& msg) +{ +#ifdef Q_WS_MAEMO_5 + QMaemo5InformationBox::information (0, msg); +#else + /* Create notification */ + NotifyNotification *notification = notify_notification_new(APPLICATION_NAME, qPrintable(msg), 0, 0); + if (notification) { + QSettings settings; + int timeout = settings.value(SETUP_NOTIFICATION_TIMEOUT, SETUP_NOTIFICATION_TIMEOUT_DEFAULT).toInt(); + + /* Set timeout */ + notify_notification_set_timeout(notification, timeout); + + /* Schedule notification for showing */ + if (!notify_notification_show(notification, NULL)) { + qDebug("Failed to send notification"); + } + + /* Clean up the memory */ + g_object_unref(notification); + } +#endif + qDebug(qPrintable(msg)); +} diff --git a/src/genericnotify.h b/src/genericnotify.h new file mode 100644 index 0000000..8a3143c --- /dev/null +++ b/src/genericnotify.h @@ -0,0 +1,12 @@ +#ifndef GENERIC_NOTIFY_H +#define GENERIC_NOTIFY_H + +#include + +namespace notify +{ + void init(); + void notify(const QString& msg); +} + +#endif // GENERIC_NOTIFY_H diff --git a/src/main.cpp b/src/main.cpp index bb6450d..06cf469 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,13 @@ #include "mainwindow.h" #include "constants.h" +#include "genericnotify.h" #include int main(int argc, char *argv[]) { + notify::init(); + QApplication app(argc, argv); app.setOrganizationName(APPLICATION_NAME); app.setApplicationName(ORGANIZATION_NAME); diff --git a/src/xbmc.cpp b/src/xbmc.cpp index e318d99..f2e9252 100644 --- a/src/xbmc.cpp +++ b/src/xbmc.cpp @@ -1,5 +1,6 @@ #include "xbmc.h" #include "constants.h" +#include "genericnotify.h" #include #include @@ -82,7 +83,7 @@ void Xbmc::commandActionFinished() QString msg = stream.readAll(); qDebug("Xbmc::commandActionFinished: %s", qPrintable(msg)); } else { - qDebug("Xbmc::commandActionFinished: error: %s", qPrintable(reply->errorString())); + notify::notify(reply->errorString()); } reply->deleteLater(); } diff --git a/src/xbmcnetmoviesremote.pro b/src/xbmcnetmoviesremote.pro index 8b2baf4..1f2aabc 100644 --- a/src/xbmcnetmoviesremote.pro +++ b/src/xbmcnetmoviesremote.pro @@ -7,6 +7,15 @@ DEPLOYMENTFOLDERS = # file1 dir1 # Avoid auto screen rotation #DEFINES += ORIENTATIONLOCK +maemo5 { + message(Compiling for Maemo) + QT += maemo5 + DEFINES += Q_WS_MAEMO_5 +} else { + CONFIG += link_pkgconfig + PKGCONFIG += gtk+-2.0 libnotify +} + # Needs to be defined for Symbian DEFINES += NETWORKACCESS QT += network @@ -23,11 +32,13 @@ TARGET = xbmcnetmoviesremote SOURCES += main.cpp mainwindow.cpp \ setupdialog.cpp \ - xbmc.cpp + xbmc.cpp \ + genericnotify.cpp HEADERS += mainwindow.h \ setupdialog.h \ constants.h \ - xbmc.h + xbmc.h \ + genericnotify.h FORMS += mainwindow.ui \ setupdialog.ui -- 1.7.9.5