extended setup dialog
[simple-xmbc-rem] / src / genericnotify.cpp
1 #ifdef Q_WS_MAEMO_5
2 #include <QMaemo5InformationBox>
3 #else
4 #include <libnotify/notify.h>
5 #endif
6
7 #include "genericnotify.h"
8 #include "constants.h"
9 #include <QSettings>
10
11 void notify::init()
12 {
13 #ifdef Q_WS_MAEMO_5
14 #else
15     /* Init libnotify library */
16     notify_init(APPLICATION_NAME);
17 #endif
18 }
19
20 void notify::notify(const QString& msg)
21 {
22     QSettings settings;
23
24     // SETUP_NOTIFICATION_TIMEOUT is in seconds
25     int timeout = 1000 * settings.value(SETUP_NOTIFICATION_TIMEOUT, SETUP_NOTIFICATION_TIMEOUT_DEFAULT).toInt();
26     if (timeout != 0) {
27 #ifdef Q_WS_MAEMO_5
28         QMaemo5InformationBox::information(0, msg, timeout);
29 #else
30         /* Create notification */
31         NotifyNotification *notification = notify_notification_new(APPLICATION_NAME, qPrintable(msg), 0, 0);
32         if (notification) {
33             /* Set timeout */
34             notify_notification_set_timeout(notification, timeout);
35
36             /* Schedule notification for showing */
37             if (!notify_notification_show(notification, NULL)) {
38                 qDebug("Failed to show notification");
39             }
40
41             /* Clean up the memory */
42             g_object_unref(notification);
43         } else {
44             qDebug("Failed to create notification");
45         }
46 #endif
47     }
48     qDebug(qPrintable(msg));
49 }