26 #include <libnotify/notify.h> 39 #if NOTIFY_CHECK_VERSION (0, 7, 0) 40 #define NOTIFICATION_NEW(summary, body, icon) \ 41 notify_notification_new(summary, body, icon) 42 #define NOTIFICATION_SET_HINT_STRING(notification, key, value) \ 43 notify_notification_set_hint(notification, key, g_variant_new_string(value)) 44 #define NOTIFICATION_SET_HINT_INT32(notification, key, value) \ 45 notify_notification_set_hint(notification, key, g_variant_new_int32(value)) 47 #define NOTIFICATION_NEW(summary, body, icon) \ 48 notify_notification_new(summary, body, icon, NULL) 49 #define NOTIFICATION_SET_HINT_STRING(notification, key, value) \ 50 notify_notification_set_hint_string(notification, key, value) 51 #define NOTIFICATION_SET_HINT_INT32(notification, key, value) \ 52 notify_notification_set_hint_int32(notification, key, value) 58 show_volume_notif(NotifyNotification *notification,
59 const gchar *card,
const gchar *channel,
60 gboolean muted, gdouble volume)
63 gchar *icon, *summary;
66 icon =
"audio-volume-muted";
68 icon =
"audio-volume-off";
70 icon =
"audio-volume-low";
72 icon =
"audio-volume-medium";
74 icon =
"audio-volume-high";
77 summary = g_strdup(
_(
"Volume muted"));
79 summary = g_strdup_printf(
"%s (%s)\n" 82 _(
"Volume"), lround(volume));
84 notify_notification_update(notification, summary, NULL, icon);
85 NOTIFICATION_SET_HINT_INT32(notification,
"value", lround(volume));
87 if (!notify_notification_show(notification, &error)) {
88 ERROR(
"Could not send notification: %s", error->message);
96 show_text_notif(NotifyNotification *notification,
97 const gchar *summary,
const gchar *body)
101 notify_notification_update(notification, summary, body, NULL);
103 if (!notify_notification_show(notification, &error)) {
104 ERROR(
"Could not send notification: %s", error->message);
121 NotifyNotification *volume_notif;
122 NotifyNotification *text_notif;
134 show_text_notif(notif->text_notif,
136 _(
"No playable soundcard found"));
140 show_text_notif(notif->text_notif,
141 _(
"Soundcard disconnected"),
142 _(
"Soundcard has been disconnected, reloading sound system..."));
149 switch (event->
user) {
151 if (!notif->external)
167 WARN(
"Unhandled audio user");
171 show_volume_notif(notif->volume_notif,
191 NotifyNotification *notification;
202 notification = NOTIFICATION_NEW(
"", NULL, NULL);
203 notify_notification_set_timeout(notification, timeout);
204 NOTIFICATION_SET_HINT_STRING(notification,
"x-canonical-private-synchronous",
"");
205 if (notif->volume_notif)
206 g_object_unref(notif->volume_notif);
207 notif->volume_notif = notification;
210 notification = NOTIFICATION_NEW(
"", NULL, NULL);
211 notify_notification_set_timeout(notification, timeout * 2);
212 NOTIFICATION_SET_HINT_STRING(notification,
"x-canonical-private-synchronous",
"");
213 if (notif->text_notif)
214 g_object_unref(notif->text_notif);
215 notif->text_notif = notification;
231 if (notif->volume_notif)
232 g_object_unref(notif->volume_notif);
233 if (notif->text_notif)
234 g_object_unref(notif->text_notif);
240 g_assert(notify_is_initted() == TRUE);
258 notif = g_new0(
Notif, 1);
261 g_assert(notify_is_initted() == FALSE);
262 if (!notify_init(PACKAGE))
264 "Notifications won't be sent.");
267 notif->audio =
audio;
294 #endif // WITH_LIBNOTIFY
Internationalization support.
void notif_reload(G_GNUC_UNUSED Notif *notif)
void audio_signals_disconnect(Audio *audio, AudioCallback callback, gpointer data)
void audio_signals_connect(Audio *audio, AudioCallback callback, gpointer data)
gboolean prefs_get_boolean(const gchar *key, gboolean def)
static void on_audio_changed(Audio *audio, AudioEvent *event, G_GNUC_UNUSED gpointer data)
Notif * notif_new(G_GNUC_UNUSED Audio *audio)
void run_error_dialog(const char *fmt,...)
gint prefs_get_integer(const gchar *key, gint def)
void notif_free(G_GNUC_UNUSED Notif *notif)