moved the source back to src
[simple-xmbc-rem] / src / genericnotify.cpp
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));
+}