1
# Description: Show alert boxes for important situations (“Battery may
2
# be recalled”, “Battery may be broken”, etc., and do not use
3
# actions in notifications if the notification-daemon does not
5
# Ubuntu: https://bugs.launchpad.net/bugs/329296
6
=== modified file 'src/gpm-notify.c'
7
--- a/src/gpm-notify.c 2008-11-06 07:20:46 +0000
8
+++ b/src/gpm-notify.c 2009-02-14 06:29:39 +0000
10
#define GPM_NOTIFY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_NOTIFY, GpmNotifyPrivate))
11
#define QUIRK_WEBSITE "http://people.freedesktop.org/~hughsient/quirk/"
15
+ NotifyActionCallback cb;
16
+ GFreeFunc free_func;
21
struct GpmNotifyPrivate
23
GpmAcAdapter *ac_adapter;
26
NotifyNotification *libnotify;
35
G_DEFINE_TYPE (GpmNotify, gpm_notify, G_TYPE_OBJECT)
38
+destroy_alert (NotifyAlert *alert)
40
+ if (alert->user_data != NULL && alert->free_func != NULL)
41
+ alert->free_func (alert->user_data);
43
+ g_free (alert->label);
49
+add_alert_action (GpmNotify *notify,
52
+ NotifyActionCallback callback,
54
+ GFreeFunc free_func)
56
+ NotifyAlert *alert = g_new0 (NotifyAlert, 1);
57
+ alert->cb = callback;
58
+ alert->user_data = user_data;
59
+ alert->free_func = free_func;
60
+ alert->label = g_strdup (label);
62
+ if (notify->priv->alerts == NULL) {
63
+ notify->priv->alerts = g_hash_table_new_full (g_str_hash,
66
+ (GFreeFunc)destroy_alert);
69
+ g_hash_table_insert (notify->priv->alerts,
75
+alert_action_button_clicked (GtkWidget *widget, gpointer data)
77
+ GpmNotify *notify = (GpmNotify*)g_object_get_data (G_OBJECT (widget), "notify");
78
+ gchar *action = (gchar*)data;
81
+ if (notify->priv->alerts != NULL) {
82
+ alert = (NotifyAlert*)g_hash_table_lookup (notify->priv->alerts,
84
+ if (alert != NULL && alert->cb != NULL) {
85
+ alert->cb (notify->priv->libnotify,
91
+ g_hash_table_remove (notify->priv->alerts, action);
95
+gpm_notify_display_alert (GpmNotify *notify,
97
+ const gchar *content,
98
+ GpmNotifyTimeout timeout,
99
+ const gchar *msgicon,
100
+ GpmNotifyUrgency urgency)
102
+ GtkMessageType msg_type;
104
+ if (urgency == GPM_NOTIFY_URGENCY_CRITICAL) {
105
+ msg_type = GTK_MESSAGE_WARNING;
107
+ msg_type = GTK_MESSAGE_INFO;
110
+ notify->priv->dialog = gtk_message_dialog_new_with_markup (NULL,
111
+ GTK_DIALOG_DESTROY_WITH_PARENT,
114
+ "<span size='larger'><b>%s</b></span>",
117
+ gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (notify->priv->dialog), "%s", content);
119
+ g_signal_connect_swapped (notify->priv->dialog,
121
+ G_CALLBACK (gtk_widget_destroy),
122
+ notify->priv->dialog);
127
#ifdef HAVE_LIBNOTIFY
134
-gpm_notify_create (GpmNotify *notify,
135
- const gchar *title,
136
- const gchar *content,
137
- GpmNotifyTimeout timeout,
138
- const gchar *msgicon,
139
- GpmNotifyUrgency urgency)
140
+gpm_notify_create (GpmNotify *notify,
141
+ const gchar *title,
142
+ const gchar *content,
143
+ GpmNotifyTimeout timeout,
144
+ const gchar *msgicon,
145
+ GpmNotifyUrgency urgency,
149
+ gpm_notify_display_alert (notify, title,
155
if (notify->priv->libnotify != NULL) {
156
// notify_notification_close (notify->priv->libnotify, NULL);
157
// notify->priv->libnotify = NULL;
158
@@ -130,15 +238,50 @@
163
+add_action_buttons (gpointer key,
165
+ gpointer user_data)
169
+ NotifyAlert *alert;
173
+ action = (gchar*)key;
174
+ alert = (NotifyAlert*)value;
175
+ notify = (GpmNotify*)user_data;
177
+ button = gtk_button_new_with_label (alert->label);
178
+ g_signal_connect (G_OBJECT (button), "clicked",
179
+ G_CALLBACK (alert_action_button_clicked), action);
180
+ g_object_set_data (G_OBJECT (button), "notify", notify);
182
+ hbox = gtk_hbox_new (FALSE, 12);
183
+ gtk_box_pack_end (GTK_BOX (hbox), button, TRUE, FALSE, 0);
185
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (notify->priv->dialog)->vbox),
186
+ hbox, FALSE, FALSE, 0);
187
+ gtk_widget_show_all (hbox);
191
gpm_notify_show (GpmNotify *notify)
194
- ret = notify_notification_show (notify->priv->libnotify, NULL);
196
- egg_warning ("failed to send notification");
198
+ if (notify->priv->dialog != NULL) {
199
+ g_hash_table_foreach (notify->priv->alerts, add_action_buttons, notify);
200
+ gtk_window_present (GTK_WINDOW (notify->priv->dialog));
203
+ ret = notify_notification_show (notify->priv->libnotify, NULL);
205
+ egg_warning ("failed to send notification");
213
@@ -161,13 +304,74 @@
214
const gchar *msgicon,
215
GpmNotifyUrgency urgency)
217
- gpm_notify_create (notify, title, content, timeout, msgicon, urgency);
218
+ gpm_notify_create (notify, title, content, timeout, msgicon, urgency, FALSE);
219
gpm_notify_show (notify);
224
+gpm_notify_add_action (GpmNotify *notify,
225
+ const char *action,
227
+ NotifyActionCallback callback,
228
+ gpointer user_data,
229
+ GFreeFunc free_func)
231
+ if (notify->priv->dialog != NULL) {
232
+ add_alert_action (notify,
239
+ gboolean supports_actions = FALSE;
240
+ GList *caps = NULL;
243
+ caps = notify_get_server_caps ();
244
+ if (caps != NULL) {
245
+ for (c = caps; c != NULL; c = c->next) {
246
+ if (strcmp ((char*)c->data, "actions") == 0) {
247
+ supports_actions = TRUE;
252
+ g_list_foreach (caps, (GFunc)g_free, NULL);
253
+ g_list_free (caps);
256
+ if (supports_actions) {
257
+ notify_notification_add_action (notify->priv->libnotify,
271
+gpm_notify_add_action (GpmNotify *notify,
272
+ const char *action,
274
+ NotifyActionCallback callback,
275
+ gpointer user_data,
276
+ GFreeFunc free_func)
278
+ add_alert_action (notify,
291
gpm_notify_show (GpmNotify *notify)
293
+ g_hash_table_foreach (notify->priv->alerts, add_action_buttons, notify);
294
+ gtk_window_present (GTK_WINDOW (notify->priv->dialog));
300
const gchar *content,
301
GpmNotifyTimeout timeout,
302
const gchar *msgicon,
303
- GpmNotifyUrgency urgency)
304
+ GpmNotifyUrgency urgency,
307
gpm_notify_display (notify, title, content, timeout, msgicon, urgency);
309
@@ -216,32 +424,12 @@
310
const gchar *msgicon,
311
GpmNotifyUrgency urgency)
314
- GtkMessageType msg_type;
316
- if (urgency == GPM_NOTIFY_URGENCY_CRITICAL) {
317
- msg_type = GTK_MESSAGE_WARNING;
319
- msg_type = GTK_MESSAGE_INFO;
322
- dialog = gtk_message_dialog_new_with_markup (NULL,
323
- GTK_DIALOG_DESTROY_WITH_PARENT,
326
- "<span size='larger'><b>%s</b></span>",
329
- gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), "%s", content);
331
- g_signal_connect_swapped (dialog,
333
- G_CALLBACK (gtk_widget_destroy),
336
- gtk_window_present (GTK_WINDOW (dialog));
339
+ return gpm_notify_display_alert (notify,
348
@@ -376,22 +564,23 @@
350
gpm_notify_create (notify, title, msg, 0,
351
GTK_STOCK_DIALOG_WARNING,
352
- GPM_NOTIFY_URGENCY_CRITICAL);
353
+ GPM_NOTIFY_URGENCY_CRITICAL,
356
/* add extra stuff */
357
#ifdef HAVE_LIBNOTIFY
358
notify->priv->internet_url = g_strdup (website);
359
- notify_notification_add_action (notify->priv->libnotify,
361
- _("Visit recall website"),
362
- (NotifyActionCallback) notify_general_clicked_cb,
364
+ gpm_notify_add_action (notify,
366
+ _("Visit recall website"),
367
+ (NotifyActionCallback) notify_general_clicked_cb,
369
notify->priv->do_not_show_gconf = GPM_CONF_NOTIFY_PERHAPS_RECALL;
370
- notify_notification_add_action (notify->priv->libnotify,
372
- _("Do not show me this again"),
373
- (NotifyActionCallback) notify_general_clicked_cb,
375
+ gpm_notify_add_action (notify,
377
+ _("Do not show me this again"),
378
+ (NotifyActionCallback) notify_general_clicked_cb,
382
gpm_notify_show (notify);
383
@@ -422,16 +611,17 @@
385
gpm_notify_create (notify, title, msg, GPM_NOTIFY_TIMEOUT_LONG,
386
GTK_STOCK_DIALOG_WARNING,
387
- GPM_NOTIFY_URGENCY_CRITICAL);
388
+ GPM_NOTIFY_URGENCY_CRITICAL,
391
/* add extra stuff */
392
#ifdef HAVE_LIBNOTIFY
393
notify->priv->do_not_show_gconf = GPM_CONF_NOTIFY_LOW_CAPACITY;
394
- notify_notification_add_action (notify->priv->libnotify,
396
- _("Do not show me this again"),
397
- (NotifyActionCallback) notify_general_clicked_cb,
399
+ gpm_notify_add_action (notify,
401
+ _("Do not show me this again"),
402
+ (NotifyActionCallback) notify_general_clicked_cb,
406
gpm_notify_show (notify);
409
gpm_notify_inhibit_lid (GpmNotify *notify)
412
- const gchar *title;
414
- /* don't show when running under GDM */
415
- if (g_getenv ("RUNNING_UNDER_GDM") != NULL) {
416
- egg_debug ("running under gdm, so no notification");
420
- title = _("Sleep warning");
421
- msg = g_strdup (_("Your laptop will not sleep if you shut the "
422
- "lid as a running program has prevented this.\n"
423
- "Some laptops can overheat if they do not sleep "
424
- "when the lid is closed."));
426
- gpm_notify_create (notify, title, msg, GPM_NOTIFY_TIMEOUT_LONG,
428
- GPM_NOTIFY_URGENCY_CRITICAL);
430
- /* add extra stuff */
431
-#ifdef HAVE_LIBNOTIFY
432
- notify->priv->do_not_show_gconf = GPM_CONF_NOTIFY_INHIBIT_LID;
433
- notify_notification_add_action (notify->priv->libnotify,
435
- _("Do not show me this again"),
436
- (NotifyActionCallback) notify_general_clicked_cb,
440
- gpm_notify_show (notify);
447
gpm_notify_fully_charged_primary (GpmNotify *notify)
450
- const gchar *title;
452
- title = _("Battery Charged");
453
- msg = _("Your laptop battery is now fully charged");
455
- gpm_notify_create (notify, title, msg, GPM_NOTIFY_TIMEOUT_SHORT,
456
- GTK_STOCK_DIALOG_WARNING,
457
- GPM_NOTIFY_URGENCY_CRITICAL);
459
- /* add extra stuff */
460
-#ifdef HAVE_LIBNOTIFY
461
- notify->priv->do_not_show_gconf = GPM_CONF_NOTIFY_FULLY_CHARGED;
462
- notify_notification_add_action (notify->priv->libnotify,
464
- _("Do not show me this again"),
465
- (NotifyActionCallback) notify_general_clicked_cb,
469
- gpm_notify_show (notify);
473
@@ -523,16 +661,17 @@
475
gpm_notify_create (notify, title, msg, GPM_NOTIFY_TIMEOUT_SHORT,
476
GTK_STOCK_DIALOG_WARNING,
477
- GPM_NOTIFY_URGENCY_CRITICAL);
478
+ GPM_NOTIFY_URGENCY_CRITICAL,
481
/* add extra stuff */
482
#ifdef HAVE_LIBNOTIFY
483
notify->priv->do_not_show_gconf = GPM_CONF_NOTIFY_DISCHARGING;
484
- notify_notification_add_action (notify->priv->libnotify,
486
- _("Do not show me this again"),
487
- (NotifyActionCallback) notify_general_clicked_cb,
489
+ gpm_notify_add_action (notify,
491
+ _("Do not show me this again"),
492
+ (NotifyActionCallback) notify_general_clicked_cb,
496
gpm_notify_show (notify);
497
@@ -553,16 +692,17 @@
499
gpm_notify_create (notify, title, msg, GPM_NOTIFY_TIMEOUT_SHORT,
500
GTK_STOCK_DIALOG_WARNING,
501
- GPM_NOTIFY_URGENCY_CRITICAL);
502
+ GPM_NOTIFY_URGENCY_CRITICAL,
505
/* add extra stuff */
506
#ifdef HAVE_LIBNOTIFY
507
notify->priv->do_not_show_gconf = GPM_CONF_NOTIFY_DISCHARGING;
508
- notify_notification_add_action (notify->priv->libnotify,
510
- _("Do not show me this again"),
511
- (NotifyActionCallback) notify_general_clicked_cb,
513
+ gpm_notify_add_action (notify,
515
+ _("Do not show me this again"),
516
+ (NotifyActionCallback) notify_general_clicked_cb,
520
gpm_notify_show (notify);
521
@@ -589,16 +729,17 @@
524
gpm_notify_create (notify, title, msg, GPM_NOTIFY_TIMEOUT_NEVER, icon,
525
- GPM_NOTIFY_URGENCY_CRITICAL);
526
+ GPM_NOTIFY_URGENCY_CRITICAL,
529
/* add extra stuff */
530
#ifdef HAVE_LIBNOTIFY
531
notify->priv->do_not_show_gconf = GPM_CONF_NOTIFY_SLEEP_FAILED;
532
- notify_notification_add_action (notify->priv->libnotify,
534
- _("Do not show me this again"),
535
- (NotifyActionCallback) notify_general_clicked_cb,
537
+ gpm_notify_add_action (notify,
539
+ _("Do not show me this again"),
540
+ (NotifyActionCallback) notify_general_clicked_cb,
543
notify->priv->internet_url = g_strdup (QUIRK_WEBSITE);
544
/* Translator: Quirks refer to strange/weird/undocumented behaviour of
545
@@ -607,11 +748,11 @@
546
* supply the info by following the procedures outlined in the "Quirks
547
* website" at http://people.freedesktop.org/~hughsient/quirk/.
549
- notify_notification_add_action (notify->priv->libnotify,
551
- _("Visit quirk website"),
552
- (NotifyActionCallback) notify_general_clicked_cb,
554
+ gpm_notify_add_action (notify,
556
+ _("Visit quirk website"),
557
+ (NotifyActionCallback) notify_general_clicked_cb,
561
gpm_notify_show (notify);