4
* Copyright 2013 Alex <alex@linuxonly.ru>
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
#include "notifications.h"
27
#include "resources.h"
30
mmgui_notifications_t mmgui_notifications_new(mmgui_libpaths_cache_t libcache)
32
mmgui_notifications_t notifications;
34
GtkSettings *gtksettings;
37
notifications = g_new0(struct _mmgui_notifications, 1);
40
notifications->notifymodule = NULL;
43
notifications->notifymodule = g_module_open(mmgui_libpaths_cache_get_library_name(libcache, "libnotify"), G_MODULE_BIND_LAZY);
45
if (notifications->notifymodule != NULL) {
47
libopened = libopened && g_module_symbol(notifications->notifymodule, "notify_init", (gpointer *)&(notifications->notify_init));
48
libopened = libopened && g_module_symbol(notifications->notifymodule, "notify_notification_new", (gpointer *)&(notifications->notify_notification_new));
49
libopened = libopened && g_module_symbol(notifications->notifymodule, "notify_notification_set_timeout", (gpointer *)&(notifications->notify_notification_set_timeout));
50
libopened = libopened && g_module_symbol(notifications->notifymodule, "notify_notification_set_hint", (gpointer *)&(notifications->notify_notification_set_hint));
51
libopened = libopened && g_module_symbol(notifications->notifymodule, "notify_notification_set_image_from_pixbuf", (gpointer *)&(notifications->notify_notification_set_image_from_pixbuf));
52
libopened = libopened && g_module_symbol(notifications->notifymodule, "notify_notification_set_category", (gpointer *)&(notifications->notify_notification_set_category));
53
libopened = libopened && g_module_symbol(notifications->notifymodule, "notify_notification_set_urgency", (gpointer *)&(notifications->notify_notification_set_urgency));
54
libopened = libopened && g_module_symbol(notifications->notifymodule, "notify_notification_show", (gpointer *)&(notifications->notify_notification_show));
55
//If some functions not exported, close library
57
notifications->notify_init = NULL;
58
notifications->notify_notification_new = NULL;
59
notifications->notify_notification_set_timeout = NULL;
60
notifications->notify_notification_set_hint = NULL;
61
notifications->notify_notification_set_image_from_pixbuf = NULL;
62
notifications->notify_notification_set_category = NULL;
63
notifications->notify_notification_set_urgency = NULL;
64
notifications->notify_notification_show = NULL;
66
g_module_close(notifications->notifymodule);
67
notifications->notifymodule = NULL;
69
//Initialize libnotify
70
(notifications->notify_init)("Modem Manager GUI");
75
notifications->canberramodule = NULL;
76
notifications->cacontext = NULL;
79
notifications->canberramodule = g_module_open(mmgui_libpaths_cache_get_library_name(libcache, "libcanberra"), G_MODULE_BIND_LAZY);
81
if (notifications->canberramodule != NULL) {
83
libopened = libopened && g_module_symbol(notifications->canberramodule, "ca_context_create", (gpointer *)&(notifications->ca_context_create));
84
libopened = libopened && g_module_symbol(notifications->canberramodule, "ca_context_destroy", (gpointer *)&(notifications->ca_context_destroy));
85
libopened = libopened && g_module_symbol(notifications->canberramodule, "ca_context_play", (gpointer *)&(notifications->ca_context_play));
86
libopened = libopened && g_module_symbol(notifications->canberramodule, "ca_context_change_props", (gpointer *)&(notifications->ca_context_change_props));
87
libopened = libopened && g_module_symbol(notifications->canberramodule, "ca_proplist_create", (gpointer *)&(notifications->ca_proplist_create));
88
libopened = libopened && g_module_symbol(notifications->canberramodule, "ca_proplist_destroy", (gpointer *)&(notifications->ca_proplist_destroy));
89
libopened = libopened && g_module_symbol(notifications->canberramodule, "ca_proplist_sets", (gpointer *)&(notifications->ca_proplist_sets));
90
libopened = libopened && g_module_symbol(notifications->canberramodule, "ca_context_play_full", (gpointer *)&(notifications->ca_context_play_full));
91
//If some functions not exported, close library
93
notifications->ca_context_create = NULL;
94
notifications->ca_context_destroy = NULL;
95
notifications->ca_context_play = NULL;
96
notifications->ca_context_change_props = NULL;
97
notifications->ca_proplist_create = NULL;
98
notifications->ca_proplist_destroy = NULL;
99
notifications->ca_proplist_sets = NULL;
100
notifications->ca_context_play_full = NULL;
102
g_module_close(notifications->canberramodule);
103
notifications->canberramodule = NULL;
104
notifications->cacontext = NULL;
106
//Initialize libnotify
107
(notifications->ca_context_create)(&(notifications->cacontext));
108
gtksettings = gtk_settings_get_default();
109
gtksoundtheme = NULL;
110
g_object_get(gtksettings, "gtk-sound-theme-name", >ksoundtheme, NULL);
111
if (gtksoundtheme != NULL) {
112
(notifications->ca_context_change_props)(notifications->cacontext, "canberra.xdg-theme.name", gtksoundtheme, NULL);
113
g_free(gtksoundtheme);
118
return notifications;
121
gboolean mmgui_notifications_show(mmgui_notifications_t notifications, gchar *caption, gchar *text, enum _mmgui_notifications_sound sound)
123
gpointer notification;
125
ca_proplist *caproplist;
127
if (notifications == NULL) return FALSE;
129
if ((caption != NULL) && (text != NULL) && (notifications->notifymodule != NULL)) {
130
notification = (notifications->notify_notification_new)(caption, text, NULL);
131
if (notification != NULL) {
132
(notifications->notify_notification_set_timeout)(notification, 3000);
133
(notifications->notify_notification_show)(notification, NULL);
137
if ((sound != MMGUI_NOTIFICATIONS_SOUND_NONE) && (notifications->canberramodule != NULL) && (notifications->cacontext != NULL)) {
138
(notifications->ca_proplist_create)(&caproplist);
140
case MMGUI_NOTIFICATIONS_SOUND_MESSAGE:
141
(notifications->ca_proplist_sets)(caproplist, "media.filename", RESOURCE_SOUND_MESSAGE);
142
(notifications->ca_proplist_sets)(caproplist, "media.role", "event");
144
case MMGUI_NOTIFICATIONS_SOUND_INFO:
145
(notifications->ca_proplist_sets)(caproplist, "event.id", "dialog-info");
146
(notifications->ca_proplist_sets)(caproplist, "media.role", "event");
148
case MMGUI_NOTIFICATIONS_SOUND_NONE:
151
(notifications->ca_proplist_sets)(caproplist, "event.id", "dialog-error");
152
(notifications->ca_proplist_sets)(caproplist, "media.role", "event");
155
caresult = (notifications->ca_context_play_full)(notifications->cacontext, 0, caproplist, NULL, NULL);
156
(notifications->ca_proplist_destroy)(caproplist);
162
void mmgui_notifications_close(mmgui_notifications_t notifications)
164
if (notifications == NULL) return;
166
if (notifications->notifymodule != NULL) {
167
//First close context
168
if (notifications->cacontext != NULL) {
169
(notifications->ca_context_destroy)(notifications->cacontext);
172
g_module_close(notifications->notifymodule);
173
notifications->notifymodule = NULL;
176
if (notifications->canberramodule != NULL) {
177
//Only module unload needed
178
g_module_close(notifications->canberramodule);
179
notifications->canberramodule = NULL;
182
g_free(notifications);