added notification via libnotify and QMaemo5InformationBox.
authorIonutz Borcoman <iborco@gmail.com>
Sun, 6 Mar 2011 09:01:46 +0000 (11:01 +0200)
committerIonutz Borcoman <iborco@gmail.com>
Thu, 10 Mar 2011 08:10:13 +0000 (10:10 +0200)
src/constants.h
src/genericnotify.cpp [new file with mode: 0644]
src/genericnotify.h [new file with mode: 0644]
src/main.cpp
src/xbmc.cpp
src/xbmcnetmoviesremote.pro

index 2adece1..d5f8db2 100644 (file)
@@ -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 (file)
index 0000000..bdefdb7
--- /dev/null
@@ -0,0 +1,44 @@
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5InformationBox>
+#else
+#include <libnotify/notify.h>
+#endif
+
+#include "genericnotify.h"
+#include "constants.h"
+#include <QSettings>
+
+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 (file)
index 0000000..8a3143c
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef GENERIC_NOTIFY_H
+#define GENERIC_NOTIFY_H
+
+#include <QString>
+
+namespace notify
+{
+    void init();
+    void notify(const QString& msg);
+}
+
+#endif // GENERIC_NOTIFY_H
index bb6450d..06cf469 100644 (file)
@@ -1,10 +1,13 @@
 #include "mainwindow.h"
 #include "constants.h"
+#include "genericnotify.h"
 
 #include <QtGui/QApplication>
 
 int main(int argc, char *argv[])
 {
+    notify::init();
+
     QApplication app(argc, argv);
     app.setOrganizationName(APPLICATION_NAME);
     app.setApplicationName(ORGANIZATION_NAME);
index e318d99..f2e9252 100644 (file)
@@ -1,5 +1,6 @@
 #include "xbmc.h"
 #include "constants.h"
+#include "genericnotify.h"
 
 #include <QSettings>
 #include <QTextStream>
@@ -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();
     }
index 8b2baf4..1f2aabc 100644 (file)
@@ -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