+ return CLAMP (g_ascii_strtod (hildon_button_get_value (
+ HILDON_BUTTON (picker)), NULL), 0, max);
+}
+
+static guint
+timed_inhibit_get_input (DisplayBlankingStatusPluginPrivate *priv)
+{
+ g_assert (priv->timed_inhibit_dialog == NULL);
+ priv->timed_inhibit_dialog = gtk_dialog_new_with_buttons (
+ _ ("Inhibit display blanking for..."), NULL, GTK_DIALOG_MODAL,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
+
+ GtkWidget *h_picker = timed_inhibit_picker_new (_ ("Hours"),
+ gconf_client_get_int (priv->gconf_client, HOURS_GCONF_KEY, NULL),
+ 24, 1);
+ GtkWidget *m_picker = timed_inhibit_picker_new (_ ("Minutes"),
+ gconf_client_get_int (priv->gconf_client, MINUTES_GCONF_KEY, NULL),
+ 60, 10);
+
+ GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
+ g_assert (hbox != NULL);
+
+ gtk_container_add (GTK_CONTAINER (hbox), h_picker);
+ gtk_container_add (GTK_CONTAINER (hbox), m_picker);
+
+ GtkWidget *content_area = gtk_dialog_get_content_area (
+ GTK_DIALOG (priv->timed_inhibit_dialog));
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+
+ gtk_widget_show_all (priv->timed_inhibit_dialog);
+
+ gint result = gtk_dialog_run (GTK_DIALOG (priv->timed_inhibit_dialog));
+
+ guint timeout = 0;
+ if (result == GTK_RESPONSE_ACCEPT) {
+ gint hours = timed_inhibit_picker_get_value (h_picker);
+ gint mins = timed_inhibit_picker_get_value (m_picker);
+
+ GError *e = NULL;
+ gconf_client_set_int (priv->gconf_client, HOURS_GCONF_KEY, hours, &e);
+ g_assert (e == NULL);
+ gconf_client_set_int (priv->gconf_client, MINUTES_GCONF_KEY, mins, &e);
+ g_assert (e == NULL);
+
+ timeout = hours*3600 + mins*60;
+ }
+
+ gtk_widget_destroy (priv->timed_inhibit_dialog);
+ priv->timed_inhibit_dialog = NULL;
+
+ return timeout;
+}
+
+static void
+on_timed_inhibit_button_clicked (GtkWidget *button,
+ DisplayBlankingStatusPluginPrivate *priv)
+{
+ if (priv->inhibit_in_signal)
+ return;
+
+ GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button),
+ GTK_TYPE_WINDOW);
+ gtk_widget_hide (parent);
+
+ gboolean self_pressed = gtk_toggle_button_get_active (
+ GTK_TOGGLE_BUTTON (button));
+ gboolean other_pressed = gtk_toggle_button_get_active (
+ GTK_TOGGLE_BUTTON (priv->inhibit_button));
+
+ if (self_pressed) {
+ g_assert (priv->timed_inhibit_timer_id == 0);
+ if (other_pressed)
+ g_assert (priv->inhibit_timer_id != 0);
+
+ guint timeout = timed_inhibit_get_input (priv);
+ if (timeout) {
+ if (other_pressed) {
+ priv->inhibit_in_signal = TRUE;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
+ priv->inhibit_button), FALSE);
+ priv->inhibit_in_signal = FALSE;
+ }
+ else
+ enable_inhibition (priv);
+
+ priv->timed_inhibit_timer_id = g_timeout_add_seconds (timeout,
+ (GSourceFunc) on_timed_inhibit_timeout, priv);
+ g_assert (priv->timed_inhibit_timer_id > 0);
+ }
+ else {
+ priv->inhibit_in_signal = TRUE;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
+ priv->timed_inhibit_button), FALSE);
+ priv->inhibit_in_signal = FALSE;
+ }
+ }
+ else { // !self_pressed
+ g_assert (!other_pressed);
+
+ disable_inhibition (priv);
+ disable_timer (&(priv->timed_inhibit_timer_id));
+ }
+}
+
+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, mode_title[*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),
+ _ ("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, _ (mode_title[i]),
+ _ (mode_desc[i]));
+ 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);
+ }