]> git.llucax.com Git - software/sadba.git/blob - src/lib-display-blanking-status-menu-widget.c
Persist selected timeout using gconf
[software/sadba.git] / src / lib-display-blanking-status-menu-widget.c
1  /***********************************************************************************
2  *  Display blanking status area plugin
3  *  Copyright (C) 2012 Leandro Lucarella
4  *  Based on status-area-orientationlock-applet by Mohammad Abu-Garbeyyeh.
5  *
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 2 of the License, or
9  *  (at your option) any later version.
10  *
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.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  ***********************************************************************************/
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <libintl.h>
26 #include <gtk/gtk.h>
27 #include <hildon/hildon.h>
28 #include <libhildondesktop/libhildondesktop.h>
29 #include <gconf/gconf-client.h>
30 #include <dbus/dbus.h>
31 #include <mce/dbus-names.h>
32
33
34 #define TYPE_DISPLAY_BLANKING_STATUS_PLUGIN (display_blanking_status_plugin_get_type ())
35
36 #define DISPLAY_BLANKING_STATUS_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
37                                     TYPE_DISPLAY_BLANKING_STATUS_PLUGIN, DisplayBlankingStatusPlugin))
38
39 #define DISPLAY_BLANKING_STATUS_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), \
40                                 TYPE_DISPLAY_BLANKING_STATUS_PLUGIN, DisplayBlankingStatusPluginClass))
41
42 #define IS_DISPLAY_BLANKING_STATUS_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
43                                                     TYPE_DISPLAY_BLANKING_STATUS_PLUGIN))
44
45 #define IS_DISPLAY_BLANKING_STATUS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \
46                                                     TYPE_DISPLAY_BLANKING_STATUS_PLUGIN))
47
48 #define DISPLAY_BLANKING_STATUS_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
49                             TYPE_DISPLAY_BLANKING_STATUS_PLUGIN, DisplayBlankingStatusPluginClass))
50
51 #define STATUS_AREA_DISPLAY_BLANKING_ICON_SIZE 18
52
53 typedef struct _DisplayBlankingStatusPlugin        DisplayBlankingStatusPlugin;
54 typedef struct _DisplayBlankingStatusPluginClass   DisplayBlankingStatusPluginClass;
55 typedef struct _DisplayBlankingStatusPluginPrivate DisplayBlankingStatusPluginPrivate;
56
57 struct _DisplayBlankingStatusPlugin
58 {
59     HDStatusMenuItem parent;
60
61     DisplayBlankingStatusPluginPrivate *priv;
62 };
63
64 struct _DisplayBlankingStatusPluginClass
65 {
66     HDStatusMenuItemClass parent;
67 };
68
69 GType display_blanking_status_plugin_get_type (void);
70
71 #define DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE(obj) \
72         (G_TYPE_INSTANCE_GET_PRIVATE (obj, \
73                 TYPE_DISPLAY_BLANKING_STATUS_PLUGIN, \
74                 DisplayBlankingStatusPluginPrivate))
75
76 #define MODE_GCONF_ROOT "/system/osso/dsm/display"
77 #define MODE_GCONF_KEY  MODE_GCONF_ROOT "/inhibit_blank_mode"
78
79 #define HOURS_GCONF_KEY   "/apps/Maemo/sadba/timed_inhibit_hours"
80 #define MINUTES_GCONF_KEY "/apps/Maemo/sadba/timed_inhibit_minutes"
81
82 #define INHIBIT_MSG_INTERVAL 30 // in seconds
83
84 #define GETTEXT_DOM "status-area-displayblanking-applet"
85 #define gettext_noop(str) (str)
86
87 // Undocumented blanking modes as reported by David Weinehall from Nokia:
88 // http://www.gossamer-threads.com/lists/maemo/developers/61201#61201
89 #define BLANKING_MODES 5
90 static const char *_DisplayBlankingDescription[BLANKING_MODES] =
91 {
92     gettext_noop ("Both enabled"),
93     gettext_noop ("Both only on battery"),
94     gettext_noop ("Blanking only on battery"),
95     gettext_noop ("Both disabled"),
96     gettext_noop ("Only dimming")
97 };
98 static const char *mode_icon_name[BLANKING_MODES] =
99 {
100     "display-blanking-icon.0",
101     "display-blanking-icon.1",
102     "display-blanking-icon.2",
103     "display-blanking-icon.3",
104     "display-blanking-icon.4",
105 };
106 #define INHIBIT_ICON_NAME       "display-blanking-inhibit-icon"
107 #define TIMED_INHIBIT_ICON_NAME "display-blanking-inhibit-icon.timed"
108
109 struct _DisplayBlankingStatusPluginPrivate
110 {
111     GConfClient *gconf_client;
112     DBusConnection* dbus_conn;
113     DBusMessage* dbus_msg;
114     GtkWidget *mode_button;
115     GtkWidget *mode_dialog;
116     GtkWidget *inhibit_button;
117     GtkWidget *timed_inhibit_button;
118     GtkWidget *timed_inhibit_dialog;
119     gint inhibit_timer_id;       // if == 0
120     gint timed_inhibit_timer_id; //     no timer is set
121     // gtk_toggle_button_set_active () triggers the "clicked" signal on the
122     // affected button, since we don't want to process the signal while
123     // changing the "pressed" state (we want just the GUI to change, we use
124     // this flag to ignore the "clicke" signal handler when is TRUE
125     gboolean inhibit_in_signal;
126     gpointer data;
127 };
128
129 HD_DEFINE_PLUGIN_MODULE (DisplayBlankingStatusPlugin,
130         display_blanking_status_plugin, HD_TYPE_STATUS_MENU_ITEM)
131
132 static void
133 display_blanking_status_plugin_class_finalize (
134         DisplayBlankingStatusPluginClass *klass)
135 {
136 }
137
138 static void
139 display_blanking_status_plugin_class_init (DisplayBlankingStatusPluginClass *c)
140 {
141     g_type_class_add_private (c, sizeof (DisplayBlankingStatusPluginPrivate));
142 }
143
144 static void
145 update_mode_gui (gint mode, DisplayBlankingStatusPluginPrivate *priv)
146 {
147     GtkWidget *icon = gtk_image_new_from_icon_name (mode_icon_name[mode],
148             GTK_ICON_SIZE_DIALOG);
149     gtk_button_set_image (GTK_BUTTON (priv->mode_button), icon);
150 }
151
152 static void
153 disable_timer (gint *timer_id)
154 {
155     g_assert (*timer_id != 0);
156     gboolean ok = g_source_remove (*timer_id);
157     g_assert (ok == TRUE);
158     *timer_id = 0;
159 }
160
161 static gboolean
162 on_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
163 {
164     dbus_bool_t ok = dbus_connection_send (priv->dbus_conn, priv->dbus_msg,
165             NULL);
166     g_assert (ok == TRUE);
167
168     return TRUE;
169 }
170
171 static gboolean
172 on_timed_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
173 {
174     disable_timer (&(priv->inhibit_timer_id));
175     disable_timer (&(priv->timed_inhibit_timer_id));
176
177     priv->inhibit_in_signal = TRUE;
178     gtk_toggle_button_set_active (
179             GTK_TOGGLE_BUTTON (priv->timed_inhibit_button), FALSE);
180     priv->inhibit_in_signal = FALSE;
181
182     GtkWidget *banner = hildon_banner_show_information (
183             priv->timed_inhibit_button, NULL,
184             dgettext (GETTEXT_DOM, "Display blanking inhibition disabled"));
185     hildon_banner_set_timeout (HILDON_BANNER (banner), 5000);
186
187     return FALSE;
188 }
189
190 static void
191 enable_inhibit_timer (DisplayBlankingStatusPluginPrivate *priv)
192 {
193     g_assert (priv->inhibit_timer_id == 0);
194     priv->inhibit_timer_id = g_timeout_add_seconds (INHIBIT_MSG_INTERVAL,
195             (GSourceFunc) on_inhibit_timeout, priv);
196     g_assert (priv->inhibit_timer_id > 0);
197 }
198
199 static void
200 on_inhibit_button_clicked (GtkWidget *button,
201         DisplayBlankingStatusPluginPrivate *priv)
202 {
203     if (priv->inhibit_in_signal)
204         return;
205
206     GtkWidget *parent = gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW);
207     gtk_widget_hide (parent);
208
209     gboolean self_pressed = gtk_toggle_button_get_active (
210             GTK_TOGGLE_BUTTON (button));
211     gboolean other_pressed = gtk_toggle_button_get_active (
212             GTK_TOGGLE_BUTTON (priv->timed_inhibit_button));
213
214     if (self_pressed && other_pressed) {
215         g_assert (priv->inhibit_timer_id != 0);
216
217         disable_timer (&(priv->timed_inhibit_timer_id));
218
219         priv->inhibit_in_signal = TRUE;
220         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
221                 priv->timed_inhibit_button), FALSE);
222         priv->inhibit_in_signal = FALSE;
223     }
224     else if (self_pressed && !other_pressed) {
225         g_assert (priv->timed_inhibit_timer_id == 0);
226
227         enable_inhibit_timer (priv);
228     }
229     else if (!self_pressed) {
230         g_assert (!other_pressed);
231         g_assert (priv->timed_inhibit_timer_id == 0);
232
233         disable_timer (&(priv->inhibit_timer_id));
234     }
235     else
236         g_assert (FALSE);
237 }
238
239 static GtkWidget *
240 timed_inhibit_picker_new (const gchar* title, gsize current, guint max,
241         guint step)
242 {
243     g_assert (max < 100);
244     static gchar buffer[3]; // 2 for the number + 1 for \0
245
246     GtkWidget *selector = hildon_touch_selector_entry_new_text ();
247     gint selected = -1;
248     for (int i = 0; i*step <= max; i++) {
249         if (i*step == current)
250             selected = i;
251         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
252                 g_ascii_formatd (buffer, 3, "%.0f", i*step));
253     }
254     hildon_gtk_entry_set_input_mode (GTK_ENTRY (
255                 hildon_touch_selector_entry_get_entry (
256                     HILDON_TOUCH_SELECTOR_ENTRY (selector))),
257             HILDON_GTK_INPUT_MODE_NUMERIC);
258
259     GtkWidget *picker = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT,
260             HILDON_BUTTON_ARRANGEMENT_VERTICAL);
261     hildon_button_set_title (HILDON_BUTTON (picker), title);
262     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker),
263             HILDON_TOUCH_SELECTOR (selector));
264     hildon_picker_button_set_active (HILDON_PICKER_BUTTON (picker),
265             selected);
266     hildon_button_set_value (HILDON_BUTTON (picker),
267                 g_ascii_formatd (buffer, 3, "%.0f", current));
268
269     g_object_set_data (G_OBJECT (picker), "max", GUINT_TO_POINTER (max));
270
271     return picker;
272 }
273
274 static guint
275 timed_inhibit_picker_get_value (GtkWidget *picker)
276 {
277     guint max = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (picker), "max"));
278
279     return CLAMP (g_ascii_strtod (hildon_button_get_value (
280                     HILDON_BUTTON (picker)), NULL), 0, max);
281 }
282
283 static guint
284 timed_inhibit_get_input (DisplayBlankingStatusPluginPrivate *priv)
285 {
286     g_assert (priv->timed_inhibit_dialog == NULL);
287     priv->timed_inhibit_dialog = gtk_dialog_new_with_buttons (
288             dgettext (GETTEXT_DOM, "Inhibit display blanking for..."), NULL,
289             GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
290             GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
291
292     GtkWidget *h_picker = timed_inhibit_picker_new (
293             dgettext (GETTEXT_DOM, "Hours"),
294             gconf_client_get_int (priv->gconf_client, HOURS_GCONF_KEY, NULL),
295             24, 1);
296     GtkWidget *m_picker = timed_inhibit_picker_new (
297             dgettext (GETTEXT_DOM, "Minutes"),
298             gconf_client_get_int (priv->gconf_client, MINUTES_GCONF_KEY, NULL),
299             60, 10);
300
301     GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
302     g_assert (hbox != NULL);
303
304     gtk_container_add (GTK_CONTAINER (hbox), h_picker);
305     gtk_container_add (GTK_CONTAINER (hbox), m_picker);
306
307     GtkWidget *content_area = gtk_dialog_get_content_area (
308             GTK_DIALOG (priv->timed_inhibit_dialog));
309     gtk_container_add (GTK_CONTAINER (content_area), hbox);
310
311     gtk_widget_show_all (priv->timed_inhibit_dialog);
312
313     gint result = gtk_dialog_run (GTK_DIALOG (priv->timed_inhibit_dialog));
314
315     guint timeout = 0;
316     if (result == GTK_RESPONSE_ACCEPT) {
317         gint hours = timed_inhibit_picker_get_value (h_picker);
318         gint mins = timed_inhibit_picker_get_value (m_picker);
319
320         GError *e = NULL;
321         gconf_client_set_int (priv->gconf_client, HOURS_GCONF_KEY, hours, &e);
322         g_assert (e == NULL);
323         gconf_client_set_int (priv->gconf_client, MINUTES_GCONF_KEY, mins, &e);
324         g_assert (e == NULL);
325
326         timeout = hours*3600 + mins*60;
327     }
328
329     gtk_widget_destroy (priv->timed_inhibit_dialog);
330     priv->timed_inhibit_dialog = NULL;
331
332     return timeout;
333 }
334
335 static void
336 on_timed_inhibit_button_clicked (GtkWidget *button,
337         DisplayBlankingStatusPluginPrivate *priv)
338 {
339     if (priv->inhibit_in_signal)
340         return;
341
342     GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button),
343             GTK_TYPE_WINDOW);
344     gtk_widget_hide (parent);
345
346     gboolean self_pressed = gtk_toggle_button_get_active (
347             GTK_TOGGLE_BUTTON (button));
348     gboolean other_pressed = gtk_toggle_button_get_active (
349             GTK_TOGGLE_BUTTON (priv->inhibit_button));
350
351     if (self_pressed) {
352         g_assert (priv->timed_inhibit_timer_id == 0);
353         if (other_pressed)
354             g_assert (priv->inhibit_timer_id != 0);
355
356         guint timeout = timed_inhibit_get_input (priv);
357         if (timeout) {
358             if (other_pressed) {
359                 priv->inhibit_in_signal = TRUE;
360                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
361                             priv->inhibit_button), FALSE);
362                 priv->inhibit_in_signal = FALSE;
363             }
364             else
365                 enable_inhibit_timer (priv);
366
367             priv->timed_inhibit_timer_id = g_timeout_add_seconds (timeout,
368                     (GSourceFunc) on_timed_inhibit_timeout, priv);
369             g_assert (priv->timed_inhibit_timer_id > 0);
370         }
371         else {
372             priv->inhibit_in_signal = TRUE;
373             gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
374                         priv->timed_inhibit_button), FALSE);
375             priv->inhibit_in_signal = FALSE;
376         }
377     }
378     else { // !self_pressed
379         g_assert (!other_pressed);
380
381         disable_timer (&(priv->inhibit_timer_id));
382         disable_timer (&(priv->timed_inhibit_timer_id));
383     }
384 }
385
386 static void
387 on_mode_dialog_button_clicked (GtkWidget *button, GtkDialog *dialog)
388 {
389     const gchar *title = hildon_button_get_title (HILDON_BUTTON (button));
390
391     gint *mode = (gint *) g_object_get_data (G_OBJECT(dialog), "mode");
392     g_assert (mode != NULL);
393
394     for (*mode = 0; *mode < BLANKING_MODES; (*mode)++) {
395         if (strcmp (title, _DisplayBlankingDescription[*mode]) == 0)
396             break;
397     }
398     g_assert (*mode < BLANKING_MODES);
399
400     gtk_dialog_response (dialog, GTK_RESPONSE_OK);
401 }
402
403 static gint
404 mode_get_input (DisplayBlankingStatusPluginPrivate *priv)
405 {
406     g_assert (priv->mode_dialog == NULL);
407     priv->mode_dialog = gtk_dialog_new ();
408     gtk_window_set_modal (GTK_WINDOW (priv->mode_dialog), TRUE);
409     gtk_window_set_title (GTK_WINDOW (priv->mode_dialog),
410             dgettext (GETTEXT_DOM, "Select display blanking mode"));
411
412     GtkWidget *pan_area = hildon_pannable_area_new ();
413     g_assert (pan_area != NULL);
414
415     GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
416     g_assert (vbox != NULL);
417
418     hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pan_area),
419             vbox);
420     GtkWidget *content_area = gtk_dialog_get_content_area (
421             GTK_DIALOG (priv->mode_dialog));
422     gtk_box_pack_start (GTK_BOX (content_area), pan_area, TRUE, TRUE, 0);
423
424     gtk_widget_set_size_request (pan_area, -1, MIN (350, BLANKING_MODES * 70));
425
426     gint mode = BLANKING_MODES;
427     for (int i = 0; i < BLANKING_MODES; i++) {
428         GtkWidget *button =
429                 hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,
430                     HILDON_BUTTON_ARRANGEMENT_VERTICAL,
431                     dgettext (GETTEXT_DOM, (_DisplayBlankingDescription[i])),
432                     NULL);
433         hildon_button_set_style (HILDON_BUTTON (button),
434             HILDON_BUTTON_STYLE_PICKER);
435         GtkWidget *icon = gtk_image_new_from_icon_name (mode_icon_name[i],
436                 GTK_ICON_SIZE_DIALOG);
437         hildon_button_set_image (HILDON_BUTTON (button), icon);
438         gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
439         gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
440         g_signal_connect (button, "clicked",
441                 G_CALLBACK (on_mode_dialog_button_clicked), priv->mode_dialog);
442     }
443
444     g_object_set_data (G_OBJECT (priv->mode_dialog), "mode", &mode);
445     gtk_widget_show_all (priv->mode_dialog);
446     gtk_dialog_run (GTK_DIALOG (priv->mode_dialog));
447
448     gtk_widget_destroy (priv->mode_dialog);
449     priv->mode_dialog = NULL;
450
451     return mode;
452 }
453
454 static void
455 on_mode_button_clicked (GtkWidget *button,
456         DisplayBlankingStatusPluginPrivate *priv)
457 {
458     GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button),
459             GTK_TYPE_WINDOW);
460     gtk_widget_hide (parent);
461
462     gint mode = mode_get_input (priv);
463
464     if (mode != BLANKING_MODES) {
465         // will trigger the gconf notify signal
466         GError *error = NULL;
467         gconf_client_set_int (priv->gconf_client, MODE_GCONF_KEY, mode, &error);
468         g_assert (error == NULL);
469     }
470 }
471
472 static void
473 on_gconf_notify (GConfClient* client, guint cnxn_id, GConfEntry* entry,
474         DisplayBlankingStatusPluginPrivate* priv)
475 {
476     const gchar* key = gconf_entry_get_key (entry);
477     g_assert (key != NULL);
478
479     // Ignore notification about keys we don't care about
480     if (strcmp (key, MODE_GCONF_KEY) != 0)
481         return;
482
483     const GConfValue* value = gconf_entry_get_value (entry);
484     g_assert (value != NULL);
485     g_assert (GCONF_VALUE_TYPE_VALID (value->type));
486     g_assert (value->type == GCONF_VALUE_INT);
487
488     gint mode = gconf_value_get_int (value);
489     update_mode_gui (mode, priv);
490 }
491
492 static void
493 init_gconf (DisplayBlankingStatusPluginPrivate *priv)
494 {
495     GError* error = NULL;
496
497     priv->gconf_client = gconf_client_get_default ();
498     g_assert (GCONF_IS_CLIENT (priv->gconf_client));
499
500     gconf_client_add_dir (priv->gconf_client, MODE_GCONF_ROOT,
501             GCONF_CLIENT_PRELOAD_NONE, &error);
502     g_assert (error == NULL);
503
504     gconf_client_notify_add (priv->gconf_client, MODE_GCONF_KEY,
505             (GConfClientNotifyFunc) &on_gconf_notify, priv, NULL, &error);
506     g_assert (error == NULL);
507 }
508
509 static void
510 init_dbus (DisplayBlankingStatusPluginPrivate *priv)
511 {
512     DBusError error;
513     dbus_error_init (&error);
514
515     priv->dbus_conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
516     g_assert (!dbus_error_is_set (&error));
517     g_assert (priv->dbus_conn != NULL);
518
519     priv->dbus_msg = dbus_message_new_method_call (MCE_SERVICE,
520             MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_PREVENT_BLANK_REQ);
521     g_assert (priv->dbus_msg != NULL);
522     dbus_message_set_no_reply (priv->dbus_msg, TRUE);
523 }
524
525 static void
526 init_mode_gui (DisplayBlankingStatusPluginPrivate *priv)
527 {
528     priv->mode_dialog = NULL;
529     priv->mode_button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT |
530                 HILDON_SIZE_AUTO_WIDTH);
531
532     GError* error = NULL;
533     gint mode = gconf_client_get_int (priv->gconf_client, MODE_GCONF_KEY,
534             &error);
535     g_assert (error == NULL);
536     update_mode_gui (mode, priv);
537
538     g_signal_connect (priv->mode_button, "clicked",
539             G_CALLBACK (on_mode_button_clicked), priv);
540 }
541
542 static GtkWidget *
543 inhibit_button_new (const gchar *icon_name,
544         void (*cb) (GtkWidget *, DisplayBlankingStatusPluginPrivate *),
545         gpointer cb_data)
546 {
547
548     GtkWidget *b = hildon_gtk_toggle_button_new (HILDON_SIZE_FINGER_HEIGHT |
549             HILDON_SIZE_AUTO_WIDTH);
550     gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(b), FALSE);
551     GtkWidget *icon = gtk_image_new_from_icon_name (icon_name,
552             GTK_ICON_SIZE_DIALOG);
553     gtk_button_set_image (GTK_BUTTON (b), icon);
554     g_signal_connect (b, "clicked", G_CALLBACK (cb), cb_data);
555
556     return b;
557 }
558
559 static void
560 init_inhibit_gui (DisplayBlankingStatusPluginPrivate *priv)
561 {
562     priv->inhibit_in_signal = FALSE;
563
564     priv->inhibit_timer_id = 0;
565     priv->timed_inhibit_timer_id = 0;
566
567     priv->inhibit_button = inhibit_button_new (INHIBIT_ICON_NAME,
568             on_inhibit_button_clicked, priv);
569
570     priv->timed_inhibit_button = inhibit_button_new (
571             TIMED_INHIBIT_ICON_NAME, on_timed_inhibit_button_clicked, priv);
572 }
573
574 static void
575 display_blanking_status_plugin_init (DisplayBlankingStatusPlugin *plugin)
576 {
577     DisplayBlankingStatusPluginPrivate *priv;
578
579     priv = DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE (plugin);
580     plugin->priv = priv;
581
582     init_gconf (priv);
583     init_dbus (priv);
584     init_mode_gui (priv);
585     init_inhibit_gui (priv);
586
587     GtkWidget *hbbox = gtk_hbutton_box_new ();
588     g_assert (hbbox != NULL);
589
590     gtk_container_add (GTK_CONTAINER (hbbox), priv->mode_button);
591     gtk_container_add (GTK_CONTAINER (hbbox), priv->inhibit_button);
592     gtk_container_add (GTK_CONTAINER (hbbox), priv->timed_inhibit_button);
593
594     gtk_container_add (GTK_CONTAINER (plugin), hbbox);
595
596     gtk_widget_show_all (GTK_WIDGET (plugin));
597 }
598