+static void
+on_mode_dialog_button_clicked (GtkWidget *button, GtkDialog *dialog)
+{
+ const gchar *title = hildon_button_get_title (HILDON_BUTTON (button));
+
+ gint *mode = (gint *) g_object_get_data (G_OBJECT(dialog), "mode");
+ g_assert (mode != NULL);
+
+ for (*mode = 0; *mode < BLANKING_MODES; (*mode)++) {
+ if (strcmp (title, _DisplayBlankingDescription[*mode]) == 0)
+ break;
+ }
+ g_assert (*mode < BLANKING_MODES);
+
+ gtk_dialog_response (dialog, GTK_RESPONSE_OK);
+}
+
+static gint
+mode_get_input (DisplayBlankingStatusPluginPrivate *priv)
+{
+ g_assert (priv->mode_dialog == NULL);
+ priv->mode_dialog = gtk_dialog_new ();
+ gtk_window_set_modal (GTK_WINDOW (priv->mode_dialog), TRUE);
+ gtk_window_set_title (GTK_WINDOW (priv->mode_dialog),
+ dgettext (GETTEXT_DOM, "Select display blanking mode"));
+
+ GtkWidget *pan_area = hildon_pannable_area_new ();
+ g_assert (pan_area != NULL);
+
+ GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
+ g_assert (vbox != NULL);
+
+ hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pan_area),
+ vbox);
+ GtkWidget *content_area = gtk_dialog_get_content_area (
+ GTK_DIALOG (priv->mode_dialog));
+ gtk_box_pack_start (GTK_BOX (content_area), pan_area, TRUE, TRUE, 0);
+
+ gtk_widget_set_size_request (pan_area, -1, MIN (350, BLANKING_MODES * 70));
+
+ gint mode = BLANKING_MODES;
+ for (int i = 0; i < BLANKING_MODES; i++) {
+ GtkWidget *button =
+ hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,
+ HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+ dgettext (GETTEXT_DOM, (_DisplayBlankingDescription[i])),
+ NULL);
+ hildon_button_set_style (HILDON_BUTTON (button),
+ HILDON_BUTTON_STYLE_PICKER);
+ GtkWidget *icon = gtk_image_new_from_icon_name (mode_icon_name[i],
+ GTK_ICON_SIZE_DIALOG);
+ hildon_button_set_image (HILDON_BUTTON (button), icon);
+ gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (on_mode_dialog_button_clicked), priv->mode_dialog);
+ }
+
+ g_object_set_data (G_OBJECT (priv->mode_dialog), "mode", &mode);
+ gtk_widget_show_all (priv->mode_dialog);
+ gtk_dialog_run (GTK_DIALOG (priv->mode_dialog));
+
+ gtk_widget_destroy (priv->mode_dialog);
+ priv->mode_dialog = NULL;
+
+ return mode;
+}
+
+static void
+on_mode_button_clicked (GtkWidget *button,
+ DisplayBlankingStatusPluginPrivate *priv)
+{
+ GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button),
+ GTK_TYPE_WINDOW);
+ gtk_widget_hide (parent);
+
+ gint mode = mode_get_input (priv);
+
+ if (mode != BLANKING_MODES) {
+ // will trigger the gconf notify signal
+ GError *error = NULL;
+ gconf_client_set_int (priv->gconf_client, MODE_GCONF_KEY, mode, &error);
+ g_assert (error == NULL);
+ }
+}
+
+static void
+on_gconf_notify (GConfClient* client, guint cnxn_id, GConfEntry* entry,
+ DisplayBlankingStatusPluginPrivate* priv)
+{
+ const gchar* key = gconf_entry_get_key (entry);
+ g_assert (key != NULL);
+
+ // Ignore notification about keys we don't care about
+ if (strcmp (key, MODE_GCONF_KEY) != 0)
+ return;
+
+ const GConfValue* value = gconf_entry_get_value (entry);
+ g_assert (value != NULL);
+ g_assert (GCONF_VALUE_TYPE_VALID (value->type));
+ g_assert (value->type == GCONF_VALUE_INT);
+
+ gint mode = gconf_value_get_int (value);
+ update_mode_gui (mode, priv);
+}
+
+static void
+init_gconf (DisplayBlankingStatusPluginPrivate *priv)
+{
+ GError* error = NULL;
+
+ priv->gconf_client = gconf_client_get_default ();
+ g_assert (GCONF_IS_CLIENT (priv->gconf_client));
+
+ gconf_client_add_dir (priv->gconf_client, MODE_GCONF_ROOT,
+ GCONF_CLIENT_PRELOAD_NONE, &error);
+ g_assert (error == NULL);
+
+ gconf_client_notify_add (priv->gconf_client, MODE_GCONF_KEY,
+ (GConfClientNotifyFunc) &on_gconf_notify, priv, NULL, &error);
+ g_assert (error == NULL);
+}
+
+static void
+init_dbus (DisplayBlankingStatusPluginPrivate *priv)
+{
+ DBusError error;
+ dbus_error_init (&error);
+
+ priv->dbus_conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ g_assert (!dbus_error_is_set (&error));
+ g_assert (priv->dbus_conn != NULL);
+
+ priv->dbus_msg = dbus_message_new_method_call (MCE_SERVICE,
+ MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_PREVENT_BLANK_REQ);
+ g_assert (priv->dbus_msg != NULL);
+ dbus_message_set_no_reply (priv->dbus_msg, TRUE);
+}
+
+static void
+init_mode_gui (DisplayBlankingStatusPluginPrivate *priv)
+{
+ priv->mode_dialog = NULL;
+ priv->mode_button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT |
+ HILDON_SIZE_AUTO_WIDTH);
+
+ GError* error = NULL;
+ gint mode = gconf_client_get_int (priv->gconf_client, MODE_GCONF_KEY,
+ &error);
+ g_assert (error == NULL);
+ update_mode_gui (mode, priv);
+
+ g_signal_connect (priv->mode_button, "clicked",
+ G_CALLBACK (on_mode_button_clicked), priv);
+}
+
+static GtkWidget *
+inhibit_button_new (const gchar *icon_name,
+ void (*cb) (GtkWidget *, DisplayBlankingStatusPluginPrivate *),
+ gpointer cb_data)
+{
+
+ GtkWidget *b = hildon_gtk_toggle_button_new (HILDON_SIZE_FINGER_HEIGHT |
+ HILDON_SIZE_AUTO_WIDTH);
+ gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(b), FALSE);