]> git.llucax.com Git - software/sadba.git/blob - src/lib-display-blanking-status-menu-widget.c
Add (empty) upgrade description to package info
[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 #define INHIBIT_STATUS_ICON_NAME "display-blanking-status"
109
110 struct _DisplayBlankingStatusPluginPrivate
111 {
112     DisplayBlankingStatusPlugin* plugin;
113     GConfClient *gconf_client;
114     DBusConnection* dbus_conn;
115     DBusMessage* dbus_msg;
116     GtkWidget *mode_button;
117     GtkWidget *mode_dialog;
118     GtkWidget *inhibit_button;
119     GtkWidget *timed_inhibit_button;
120     GtkWidget *timed_inhibit_dialog;
121     gint inhibit_timer_id;       // if == 0
122     gint timed_inhibit_timer_id; //     no timer is set
123     // gtk_toggle_button_set_active () triggers the "clicked" signal on the
124     // affected button, since we don't want to process the signal while
125     // changing the "pressed" state (we want just the GUI to change, we use
126     // this flag to ignore the "clicke" signal handler when is TRUE
127     gboolean inhibit_in_signal;
128     gpointer data;
129 };
130
131 HD_DEFINE_PLUGIN_MODULE (DisplayBlankingStatusPlugin,
132         display_blanking_status_plugin, HD_TYPE_STATUS_MENU_ITEM)
133
134 static void
135 display_blanking_status_plugin_class_finalize (
136         DisplayBlankingStatusPluginClass *klass)
137 {
138 }
139
140 static void
141 display_blanking_status_plugin_class_init (DisplayBlankingStatusPluginClass *c)
142 {
143     g_type_class_add_private (c, sizeof (DisplayBlankingStatusPluginPrivate));
144 }
145
146 static void
147 update_mode_gui (gint mode, DisplayBlankingStatusPluginPrivate *priv)
148 {
149     GtkWidget *icon = gtk_image_new_from_icon_name (mode_icon_name[mode],
150             GTK_ICON_SIZE_DIALOG);
151     gtk_button_set_image (GTK_BUTTON (priv->mode_button), icon);
152 }
153
154 static void
155 disable_timer (gint *timer_id)
156 {
157     g_assert (*timer_id != 0);
158     gboolean ok = g_source_remove (*timer_id);
159     g_assert (ok == TRUE);
160     *timer_id = 0;
161 }
162
163 static void
164 disable_inhibition (DisplayBlankingStatusPluginPrivate *priv)
165 {
166     disable_timer (&(priv->inhibit_timer_id));
167     hd_status_plugin_item_set_status_area_icon (
168             HD_STATUS_PLUGIN_ITEM (priv->plugin), NULL);
169 }
170
171 static gboolean
172 on_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
173 {
174     dbus_bool_t ok = dbus_connection_send (priv->dbus_conn, priv->dbus_msg,
175             NULL);
176     g_assert (ok == TRUE);
177
178     return TRUE;
179 }
180
181 static gboolean
182 on_timed_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
183 {
184     disable_inhibition (priv);
185     disable_timer (&(priv->timed_inhibit_timer_id));
186
187     priv->inhibit_in_signal = TRUE;
188     gtk_toggle_button_set_active (
189             GTK_TOGGLE_BUTTON (priv->timed_inhibit_button), FALSE);
190     priv->inhibit_in_signal = FALSE;
191
192     GtkWidget *banner = hildon_banner_show_information (
193             priv->timed_inhibit_button, NULL,
194             dgettext (GETTEXT_DOM, "Display blanking inhibition disabled"));
195     hildon_banner_set_timeout (HILDON_BANNER (banner), 5000);
196
197     return FALSE;
198 }
199
200 static void
201 enable_inhibition (DisplayBlankingStatusPluginPrivate *priv)
202 {
203     g_assert (priv->inhibit_timer_id == 0);
204     priv->inhibit_timer_id = g_timeout_add_seconds (INHIBIT_MSG_INTERVAL,
205             (GSourceFunc) on_inhibit_timeout, priv);
206     g_assert (priv->inhibit_timer_id > 0);
207
208     GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
209     GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (icon_theme,
210             INHIBIT_STATUS_ICON_NAME, 18, GTK_ICON_LOOKUP_NO_SVG, NULL);
211     hd_status_plugin_item_set_status_area_icon (
212             HD_STATUS_PLUGIN_ITEM (priv->plugin), pixbuf);
213 }
214
215 static void
216 on_inhibit_button_clicked (GtkWidget *button,
217         DisplayBlankingStatusPluginPrivate *priv)
218 {
219     if (priv->inhibit_in_signal)
220         return;
221
222     GtkWidget *parent = gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW);
223     gtk_widget_hide (parent);
224
225     gboolean self_pressed = gtk_toggle_button_get_active (
226             GTK_TOGGLE_BUTTON (button));
227     gboolean other_pressed = gtk_toggle_button_get_active (
228             GTK_TOGGLE_BUTTON (priv->timed_inhibit_button));
229
230     if (self_pressed && other_pressed) {
231         g_assert (priv->inhibit_timer_id != 0);
232
233         disable_timer (&(priv->timed_inhibit_timer_id));
234
235         priv->inhibit_in_signal = TRUE;
236         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
237                 priv->timed_inhibit_button), FALSE);
238         priv->inhibit_in_signal = FALSE;
239     }
240     else if (self_pressed && !other_pressed) {
241         g_assert (priv->timed_inhibit_timer_id == 0);
242
243         enable_inhibition (priv);
244     }
245     else if (!self_pressed) {
246         g_assert (!other_pressed);
247         g_assert (priv->timed_inhibit_timer_id == 0);
248
249         disable_inhibition (priv);
250     }
251     else
252         g_assert (FALSE);
253 }
254
255 static GtkWidget *
256 timed_inhibit_picker_new (const gchar* title, gsize current, guint max,
257         guint step)
258 {
259     g_assert (max < 100);
260     static gchar buffer[3]; // 2 for the number + 1 for \0
261
262     GtkWidget *selector = hildon_touch_selector_entry_new_text ();
263     gint selected = -1;
264     for (int i = 0; i*step <= max; i++) {
265         if (i*step == current)
266             selected = i;
267         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
268                 g_ascii_formatd (buffer, 3, "%.0f", i*step));
269     }
270     hildon_gtk_entry_set_input_mode (GTK_ENTRY (
271                 hildon_touch_selector_entry_get_entry (
272                     HILDON_TOUCH_SELECTOR_ENTRY (selector))),
273             HILDON_GTK_INPUT_MODE_NUMERIC);
274
275     GtkWidget *picker = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT,
276             HILDON_BUTTON_ARRANGEMENT_VERTICAL);
277     hildon_button_set_title (HILDON_BUTTON (picker), title);
278     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker),
279             HILDON_TOUCH_SELECTOR (selector));
280     hildon_picker_button_set_active (HILDON_PICKER_BUTTON (picker),
281             selected);
282     hildon_button_set_value (HILDON_BUTTON (picker),
283                 g_ascii_formatd (buffer, 3, "%.0f", current));
284
285     g_object_set_data (G_OBJECT (picker), "max", GUINT_TO_POINTER (max));
286
287     return picker;
288 }
289
290 static guint
291 timed_inhibit_picker_get_value (GtkWidget *picker)
292 {
293     guint max = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (picker), "max"));
294
295     return CLAMP (g_ascii_strtod (hildon_button_get_value (
296                     HILDON_BUTTON (picker)), NULL), 0, max);
297 }
298
299 static guint
300 timed_inhibit_get_input (DisplayBlankingStatusPluginPrivate *priv)
301 {
302     g_assert (priv->timed_inhibit_dialog == NULL);
303     priv->timed_inhibit_dialog = gtk_dialog_new_with_buttons (
304             dgettext (GETTEXT_DOM, "Inhibit display blanking for..."), NULL,
305             GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
306             GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
307
308     GtkWidget *h_picker = timed_inhibit_picker_new (
309             dgettext (GETTEXT_DOM, "Hours"),
310             gconf_client_get_int (priv->gconf_client, HOURS_GCONF_KEY, NULL),
311             24, 1);
312     GtkWidget *m_picker = timed_inhibit_picker_new (
313             dgettext (GETTEXT_DOM, "Minutes"),
314             gconf_client_get_int (priv->gconf_client, MINUTES_GCONF_KEY, NULL),
315             60, 10);
316
317     GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
318     g_assert (hbox != NULL);
319
320     gtk_container_add (GTK_CONTAINER (hbox), h_picker);
321     gtk_container_add (GTK_CONTAINER (hbox), m_picker);
322
323     GtkWidget *content_area = gtk_dialog_get_content_area (
324             GTK_DIALOG (priv->timed_inhibit_dialog));
325     gtk_container_add (GTK_CONTAINER (content_area), hbox);
326
327     gtk_widget_show_all (priv->timed_inhibit_dialog);
328
329     gint result = gtk_dialog_run (GTK_DIALOG (priv->timed_inhibit_dialog));
330
331     guint timeout = 0;
332     if (result == GTK_RESPONSE_ACCEPT) {
333         gint hours = timed_inhibit_picker_get_value (h_picker);
334         gint mins = timed_inhibit_picker_get_value (m_picker);
335
336         GError *e = NULL;
337         gconf_client_set_int (priv->gconf_client, HOURS_GCONF_KEY, hours, &e);
338         g_assert (e == NULL);
339         gconf_client_set_int (priv->gconf_client, MINUTES_GCONF_KEY, mins, &e);
340         g_assert (e == NULL);
341
342         timeout = hours*3600 + mins*60;
343     }
344
345     gtk_widget_destroy (priv->timed_inhibit_dialog);
346     priv->timed_inhibit_dialog = NULL;
347
348     return timeout;
349 }
350
351 static void
352 on_timed_inhibit_button_clicked (GtkWidget *button,
353         DisplayBlankingStatusPluginPrivate *priv)
354 {
355     if (priv->inhibit_in_signal)
356         return;
357
358     GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button),
359             GTK_TYPE_WINDOW);
360     gtk_widget_hide (parent);
361
362     gboolean self_pressed = gtk_toggle_button_get_active (
363             GTK_TOGGLE_BUTTON (button));
364     gboolean other_pressed = gtk_toggle_button_get_active (
365             GTK_TOGGLE_BUTTON (priv->inhibit_button));
366
367     if (self_pressed) {
368         g_assert (priv->timed_inhibit_timer_id == 0);
369         if (other_pressed)
370             g_assert (priv->inhibit_timer_id != 0);
371
372         guint timeout = timed_inhibit_get_input (priv);
373         if (timeout) {
374             if (other_pressed) {
375                 priv->inhibit_in_signal = TRUE;
376                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
377                             priv->inhibit_button), FALSE);
378                 priv->inhibit_in_signal = FALSE;
379             }
380             else
381                 enable_inhibition (priv);
382
383             priv->timed_inhibit_timer_id = g_timeout_add_seconds (timeout,
384                     (GSourceFunc) on_timed_inhibit_timeout, priv);
385             g_assert (priv->timed_inhibit_timer_id > 0);
386         }
387         else {
388             priv->inhibit_in_signal = TRUE;
389             gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
390                         priv->timed_inhibit_button), FALSE);
391             priv->inhibit_in_signal = FALSE;
392         }
393     }
394     else { // !self_pressed
395         g_assert (!other_pressed);
396
397         disable_inhibition (priv);
398         disable_timer (&(priv->timed_inhibit_timer_id));
399     }
400 }
401
402 static void
403 on_mode_dialog_button_clicked (GtkWidget *button, GtkDialog *dialog)
404 {
405     const gchar *title = hildon_button_get_title (HILDON_BUTTON (button));
406
407     gint *mode = (gint *) g_object_get_data (G_OBJECT(dialog), "mode");
408     g_assert (mode != NULL);
409
410     for (*mode = 0; *mode < BLANKING_MODES; (*mode)++) {
411         if (strcmp (title, _DisplayBlankingDescription[*mode]) == 0)
412             break;
413     }
414     g_assert (*mode < BLANKING_MODES);
415
416     gtk_dialog_response (dialog, GTK_RESPONSE_OK);
417 }
418
419 static gint
420 mode_get_input (DisplayBlankingStatusPluginPrivate *priv)
421 {
422     g_assert (priv->mode_dialog == NULL);
423     priv->mode_dialog = gtk_dialog_new ();
424     gtk_window_set_modal (GTK_WINDOW (priv->mode_dialog), TRUE);
425     gtk_window_set_title (GTK_WINDOW (priv->mode_dialog),
426             dgettext (GETTEXT_DOM, "Select display blanking mode"));
427
428     GtkWidget *pan_area = hildon_pannable_area_new ();
429     g_assert (pan_area != NULL);
430
431     GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
432     g_assert (vbox != NULL);
433
434     hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pan_area),
435             vbox);
436     GtkWidget *content_area = gtk_dialog_get_content_area (
437             GTK_DIALOG (priv->mode_dialog));
438     gtk_box_pack_start (GTK_BOX (content_area), pan_area, TRUE, TRUE, 0);
439
440     gtk_widget_set_size_request (pan_area, -1, MIN (350, BLANKING_MODES * 70));
441
442     gint mode = BLANKING_MODES;
443     for (int i = 0; i < BLANKING_MODES; i++) {
444         GtkWidget *button =
445                 hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,
446                     HILDON_BUTTON_ARRANGEMENT_VERTICAL,
447                     dgettext (GETTEXT_DOM, (_DisplayBlankingDescription[i])),
448                     NULL);
449         hildon_button_set_style (HILDON_BUTTON (button),
450             HILDON_BUTTON_STYLE_PICKER);
451         GtkWidget *icon = gtk_image_new_from_icon_name (mode_icon_name[i],
452                 GTK_ICON_SIZE_DIALOG);
453         hildon_button_set_image (HILDON_BUTTON (button), icon);
454         gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
455         gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
456         g_signal_connect (button, "clicked",
457                 G_CALLBACK (on_mode_dialog_button_clicked), priv->mode_dialog);
458     }
459
460     g_object_set_data (G_OBJECT (priv->mode_dialog), "mode", &mode);
461     gtk_widget_show_all (priv->mode_dialog);
462     gtk_dialog_run (GTK_DIALOG (priv->mode_dialog));
463
464     gtk_widget_destroy (priv->mode_dialog);
465     priv->mode_dialog = NULL;
466
467     return mode;
468 }
469
470 static void
471 on_mode_button_clicked (GtkWidget *button,
472         DisplayBlankingStatusPluginPrivate *priv)
473 {
474     GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button),
475             GTK_TYPE_WINDOW);
476     gtk_widget_hide (parent);
477
478     gint mode = mode_get_input (priv);
479
480     if (mode != BLANKING_MODES) {
481         // will trigger the gconf notify signal
482         GError *error = NULL;
483         gconf_client_set_int (priv->gconf_client, MODE_GCONF_KEY, mode, &error);
484         g_assert (error == NULL);
485     }
486 }
487
488 static void
489 on_gconf_notify (GConfClient* client, guint cnxn_id, GConfEntry* entry,
490         DisplayBlankingStatusPluginPrivate* priv)
491 {
492     const gchar* key = gconf_entry_get_key (entry);
493     g_assert (key != NULL);
494
495     // Ignore notification about keys we don't care about
496     if (strcmp (key, MODE_GCONF_KEY) != 0)
497         return;
498
499     const GConfValue* value = gconf_entry_get_value (entry);
500     g_assert (value != NULL);
501     g_assert (GCONF_VALUE_TYPE_VALID (value->type));
502     g_assert (value->type == GCONF_VALUE_INT);
503
504     gint mode = gconf_value_get_int (value);
505     update_mode_gui (mode, priv);
506 }
507
508 static void
509 init_gconf (DisplayBlankingStatusPluginPrivate *priv)
510 {
511     GError* error = NULL;
512
513     priv->gconf_client = gconf_client_get_default ();
514     g_assert (GCONF_IS_CLIENT (priv->gconf_client));
515
516     gconf_client_add_dir (priv->gconf_client, MODE_GCONF_ROOT,
517             GCONF_CLIENT_PRELOAD_NONE, &error);
518     g_assert (error == NULL);
519
520     gconf_client_notify_add (priv->gconf_client, MODE_GCONF_KEY,
521             (GConfClientNotifyFunc) &on_gconf_notify, priv, NULL, &error);
522     g_assert (error == NULL);
523 }
524
525 static void
526 init_dbus (DisplayBlankingStatusPluginPrivate *priv)
527 {
528     DBusError error;
529     dbus_error_init (&error);
530
531     priv->dbus_conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
532     g_assert (!dbus_error_is_set (&error));
533     g_assert (priv->dbus_conn != NULL);
534
535     priv->dbus_msg = dbus_message_new_method_call (MCE_SERVICE,
536             MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_PREVENT_BLANK_REQ);
537     g_assert (priv->dbus_msg != NULL);
538     dbus_message_set_no_reply (priv->dbus_msg, TRUE);
539 }
540
541 static void
542 init_mode_gui (DisplayBlankingStatusPluginPrivate *priv)
543 {
544     priv->mode_dialog = NULL;
545     priv->mode_button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT |
546                 HILDON_SIZE_AUTO_WIDTH);
547
548     GError* error = NULL;
549     gint mode = gconf_client_get_int (priv->gconf_client, MODE_GCONF_KEY,
550             &error);
551     g_assert (error == NULL);
552     update_mode_gui (mode, priv);
553
554     g_signal_connect (priv->mode_button, "clicked",
555             G_CALLBACK (on_mode_button_clicked), priv);
556 }
557
558 static GtkWidget *
559 inhibit_button_new (const gchar *icon_name,
560         void (*cb) (GtkWidget *, DisplayBlankingStatusPluginPrivate *),
561         gpointer cb_data)
562 {
563
564     GtkWidget *b = hildon_gtk_toggle_button_new (HILDON_SIZE_FINGER_HEIGHT |
565             HILDON_SIZE_AUTO_WIDTH);
566     gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(b), FALSE);
567     GtkWidget *icon = gtk_image_new_from_icon_name (icon_name,
568             GTK_ICON_SIZE_DIALOG);
569     gtk_button_set_image (GTK_BUTTON (b), icon);
570     g_signal_connect (b, "clicked", G_CALLBACK (cb), cb_data);
571
572     return b;
573 }
574
575 static void
576 init_inhibit_gui (DisplayBlankingStatusPluginPrivate *priv)
577 {
578     priv->inhibit_in_signal = FALSE;
579
580     priv->inhibit_timer_id = 0;
581     priv->timed_inhibit_timer_id = 0;
582
583     priv->inhibit_button = inhibit_button_new (INHIBIT_ICON_NAME,
584             on_inhibit_button_clicked, priv);
585
586     priv->timed_inhibit_button = inhibit_button_new (
587             TIMED_INHIBIT_ICON_NAME, on_timed_inhibit_button_clicked, priv);
588 }
589
590 static void
591 display_blanking_status_plugin_init (DisplayBlankingStatusPlugin *plugin)
592 {
593     DisplayBlankingStatusPluginPrivate *priv;
594
595     priv = DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE (plugin);
596     plugin->priv = priv;
597     priv->plugin = plugin;
598
599     init_gconf (priv);
600     init_dbus (priv);
601     init_mode_gui (priv);
602     init_inhibit_gui (priv);
603
604     GtkWidget *hbbox = gtk_hbutton_box_new ();
605     g_assert (hbbox != NULL);
606
607     gtk_container_add (GTK_CONTAINER (hbbox), priv->mode_button);
608     gtk_container_add (GTK_CONTAINER (hbbox), priv->inhibit_button);
609     gtk_container_add (GTK_CONTAINER (hbbox), priv->timed_inhibit_button);
610
611     gtk_container_add (GTK_CONTAINER (plugin), hbbox);
612
613     gtk_widget_show_all (GTK_WIDGET (plugin));
614 }
615