+ 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);
+ GtkWidget *icon = gtk_image_new_from_icon_name (icon_name,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_button_set_image (GTK_BUTTON (b), icon);
+ g_signal_connect (b, "clicked", G_CALLBACK (cb), cb_data);
+
+ return b;
+}
+
+static void
+init_inhibit_gui (DisplayBlankingStatusPluginPrivate *priv)
+{
+ priv->inhibit_in_signal = FALSE;
+
+ priv->inhibit_timer_id = 0;
+ priv->timed_inhibit_timer_id = 0;
+
+ priv->inhibit_button = inhibit_button_new (INHIBIT_ICON_NAME,
+ on_inhibit_button_clicked, priv);
+
+ priv->timed_inhibit_button = inhibit_button_new (
+ TIMED_INHIBIT_ICON_NAME, on_timed_inhibit_button_clicked, priv);
+}
+
+static void
+display_blanking_status_plugin_init (DisplayBlankingStatusPlugin *plugin)
+{
+ DisplayBlankingStatusPluginPrivate *priv;
+
+ priv = DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE (plugin);
+ plugin->priv = priv;
+ priv->plugin = plugin;