/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2005 Jaap Haitsma * Copyright (C) 2005 William Jon McCann * Copyright (C) 2005-2009 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include #include #define UPOWER_ENABLE_DEPRECATED #include #include "egg-console-kit.h" #include "gpm-tray-icon.h" #include "gpm-common.h" #include "gpm-prefs-core.h" #include "gpm-icon-names.h" #include "gpm-brightness.h" #define GET_WIDGET(x) (GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder, (x)))) #define GET_NOTEBOOK(x) (GTK_NOTEBOOK (gtk_builder_get_object (prefs->priv->builder, (x)))) #define GET_WINDOW(x) (GTK_WINDOW (gtk_builder_get_object (prefs->priv->builder, (x)))) static void gpm_prefs_finalize (GObject *object); struct GpmPrefsPrivate { UpClient *client; GtkBuilder *builder; gboolean has_batteries; gboolean has_lcd; gboolean has_ups; gboolean has_button_lid; gboolean has_button_suspend; gboolean can_shutdown; gboolean can_suspend; gboolean can_hibernate; GSettings *settings; EggConsoleKit *console; }; enum { ACTION_HELP, ACTION_CLOSE, LAST_SIGNAL }; static guint signals [LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE_WITH_PRIVATE (GpmPrefs, gpm_prefs, G_TYPE_OBJECT) /** * gpm_prefs_class_init: * @klass: This prefs class instance **/ static void gpm_prefs_class_init (GpmPrefsClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gpm_prefs_finalize; signals [ACTION_HELP] = g_signal_new ("action-help", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GpmPrefsClass, action_help), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals [ACTION_CLOSE] = g_signal_new ("action-close", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GpmPrefsClass, action_close), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } /** * gpm_prefs_activate_window: * @prefs: This prefs class instance * * Activates (shows) the window. **/ void gpm_prefs_activate_window (GtkApplication *app, GpmPrefs *prefs) { GtkWindow *window; window = GET_WINDOW ("dialog_preferences"); gtk_application_add_window (GTK_APPLICATION (app), window); gtk_window_present (window); } /** * gpm_prefs_help_cb: * @widget: The GtkWidget object * @prefs: This prefs class instance **/ static void gpm_prefs_help_cb (GtkWidget *widget, GpmPrefs *prefs) { g_debug ("emitting action-help"); g_signal_emit (prefs, signals [ACTION_HELP], 0); } /** * gpm_prefs_icon_radio_cb: * @widget: The GtkWidget object **/ static void gpm_prefs_icon_radio_cb (GtkWidget *widget, GpmPrefs *prefs) { gint policy; policy = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "policy")); g_settings_set_enum (prefs->priv->settings, GPM_SETTINGS_ICON_POLICY, policy); } /** * gpm_prefs_format_percentage_cb: * @scale: The GtkScale object * @value: The value in %. **/ static gchar * gpm_prefs_format_percentage_cb (GtkScale *scale, gdouble value) { return g_strdup_printf ("%.0f%%", value); } /** * gpm_prefs_action_combo_changed_cb: **/ static void gpm_prefs_action_combo_changed_cb (GtkWidget *widget, GpmPrefs *prefs) { GpmActionPolicy policy; const GpmActionPolicy *actions; const gchar *gpm_pref_key; guint active; actions = (const GpmActionPolicy *) g_object_get_data (G_OBJECT (widget), "actions"); gpm_pref_key = (const gchar *) g_object_get_data (G_OBJECT (widget), "settings_key"); active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); policy = actions[active]; g_settings_set_enum (prefs->priv->settings, gpm_pref_key, policy); } /** * gpm_prefs_action_time_changed_cb: **/ static void gpm_prefs_action_time_changed_cb (GtkWidget *widget, GpmPrefs *prefs) { guint value; const gint *values; const gchar *gpm_pref_key; guint active; values = (const gint *) g_object_get_data (G_OBJECT (widget), "values"); gpm_pref_key = (const gchar *) g_object_get_data (G_OBJECT (widget), "settings_key"); active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); value = values[active]; g_debug ("Changing %s to %i", gpm_pref_key, value); g_settings_set_int (prefs->priv->settings, gpm_pref_key, value); } /** * gpm_prefs_actions_destroy_cb: **/ static void gpm_prefs_actions_destroy_cb (GpmActionPolicy *array) { g_free (array); } /** * gpm_prefs_setup_action_combo: * @prefs: This prefs class instance * @widget_name: The GtkWidget name * @gpm_pref_key: The settings key for this preference setting. * @actions: The actions to associate in an array. **/ static void gpm_prefs_setup_action_combo (GpmPrefs *prefs, const gchar *widget_name, const gchar *gpm_pref_key, const GpmActionPolicy *actions) { gint i; gboolean is_writable; GtkWidget *widget; GpmActionPolicy policy; GpmActionPolicy value; GPtrArray *array; GpmActionPolicy *actions_added; widget = GET_WIDGET (widget_name); value = g_settings_get_enum (prefs->priv->settings, gpm_pref_key); is_writable = g_settings_is_writable (prefs->priv->settings, gpm_pref_key); gtk_widget_set_sensitive (widget, is_writable); array = g_ptr_array_new (); g_object_set_data (G_OBJECT (widget), "settings_key", (gpointer) gpm_pref_key); g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (gpm_prefs_action_combo_changed_cb), prefs); for (i=0; actions[i] != -1; i++) { policy = actions[i]; if (policy == GPM_ACTION_POLICY_SHUTDOWN && !prefs->priv->can_shutdown) { g_debug ("Cannot add option, as cannot shutdown."); } else if (policy == GPM_ACTION_POLICY_SHUTDOWN && prefs->priv->can_shutdown) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (widget), _("Shutdown")); g_ptr_array_add(array, GINT_TO_POINTER (policy)); } else if (policy == GPM_ACTION_POLICY_SUSPEND && !prefs->priv->can_suspend) { g_debug ("Cannot add option, as cannot suspend."); } else if (policy == GPM_ACTION_POLICY_HIBERNATE && !prefs->priv->can_hibernate) { g_debug ("Cannot add option, as cannot hibernate."); } else if (policy == GPM_ACTION_POLICY_SUSPEND && prefs->priv->can_suspend) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (widget), _("Suspend")); g_ptr_array_add (array, GINT_TO_POINTER (policy)); } else if (policy == GPM_ACTION_POLICY_HIBERNATE && prefs->priv->can_hibernate) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (widget), _("Hibernate")); g_ptr_array_add(array, GINT_TO_POINTER (policy)); } else if (policy == GPM_ACTION_POLICY_BLANK) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (widget), _("Blank screen")); g_ptr_array_add (array, GINT_TO_POINTER (policy)); } else if (policy == GPM_ACTION_POLICY_INTERACTIVE) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (widget), _("Ask me")); g_ptr_array_add(array, GINT_TO_POINTER (policy)); } else if (policy == GPM_ACTION_POLICY_NOTHING) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (widget), _("Do nothing")); g_ptr_array_add(array, GINT_TO_POINTER (policy)); } else { g_warning ("Unknown action read from settings: %i", policy); } } /* save as array _only_ the actions we could add */ actions_added = g_new0 (GpmActionPolicy, array->len+1); for (i=0; ilen; i++) actions_added[i] = GPOINTER_TO_INT (g_ptr_array_index (array, i)); actions_added[i] = -1; g_object_set_data_full (G_OBJECT (widget), "actions", (gpointer) actions_added, (GDestroyNotify) gpm_prefs_actions_destroy_cb); /* set what we have in the settings */ for (i=0; actions_added[i] != -1; i++) { policy = actions_added[i]; if (value == policy) gtk_combo_box_set_active (GTK_COMBO_BOX (widget), i); } g_ptr_array_unref (array); } /** * gpm_prefs_setup_time_combo: * @prefs: This prefs class instance * @widget_name: The GtkWidget name * @gpm_pref_key: The settings key for this preference setting. * @actions: The actions to associate in an array. **/ static void gpm_prefs_setup_time_combo (GpmPrefs *prefs, const gchar *widget_name, const gchar *gpm_pref_key, const gint *values) { guint value; gchar *text; guint i; gboolean is_writable; GtkWidget *widget; widget = GET_WIDGET (widget_name); value = g_settings_get_int (prefs->priv->settings, gpm_pref_key); is_writable = g_settings_is_writable (prefs->priv->settings, gpm_pref_key); gtk_widget_set_sensitive (widget, is_writable); g_object_set_data (G_OBJECT (widget), "settings_key", (gpointer) gpm_pref_key); g_object_set_data (G_OBJECT (widget), "values", (gpointer) values); /* add each time */ for (i=0; values[i] != -1; i++) { /* get translation for number of seconds */ if (values[i] != 0) { text = gpm_get_timestring (values[i]); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (widget), text); g_free (text); } else { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (widget), _("Never")); } /* matches, so set default */ if (value == values[i]) gtk_combo_box_set_active (GTK_COMBO_BOX (widget), i); } /* connect after set */ g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (gpm_prefs_action_time_changed_cb), prefs); } /** * gpm_prefs_close_cb: * @widget: The GtkWidget object * @prefs: This prefs class instance **/ static void gpm_prefs_close_cb (GtkWidget *widget, GpmPrefs *prefs) { g_debug ("emitting action-close"); g_signal_emit (prefs, signals [ACTION_CLOSE], 0); } /** * gpm_prefs_delete_event_cb: * @widget: The GtkWidget object * @event: The event type, unused. * @prefs: This prefs class instance **/ static gboolean gpm_prefs_delete_event_cb (GtkWidget *widget, GdkEvent *event, GpmPrefs *prefs) { gpm_prefs_close_cb (widget, prefs); return FALSE; } static void prefs_setup_ac (GpmPrefs *prefs) { GtkWidget *widget; const GpmActionPolicy button_lid_actions[] = {GPM_ACTION_POLICY_NOTHING, GPM_ACTION_POLICY_BLANK, GPM_ACTION_POLICY_SUSPEND, GPM_ACTION_POLICY_HIBERNATE, GPM_ACTION_POLICY_SHUTDOWN, -1}; static const gint computer_times[] = {10*60, 30*60, 1*60*60, 2*60*60, 0, /* never */ -1}; static const gint display_times[] = {1*60, 5*60, 10*60, 30*60, 1*60*60, 0, /* never */ -1}; gpm_prefs_setup_time_combo (prefs, "combobox_ac_computer", GPM_SETTINGS_SLEEP_COMPUTER_AC, computer_times); gpm_prefs_setup_time_combo (prefs, "combobox_ac_display", GPM_SETTINGS_SLEEP_DISPLAY_AC, display_times); gpm_prefs_setup_action_combo (prefs, "combobox_ac_lid", GPM_SETTINGS_BUTTON_LID_AC, button_lid_actions); /* setup brightness slider */ widget = GET_WIDGET ("hscale_ac_brightness"); g_settings_bind (prefs->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC, gtk_range_get_adjustment (GTK_RANGE (widget)), "value", G_SETTINGS_BIND_DEFAULT); g_signal_connect (G_OBJECT (widget), "format-value", G_CALLBACK (gpm_prefs_format_percentage_cb), NULL); /* set up the checkboxes */ g_settings_bind (prefs->priv->settings, GPM_SETTINGS_IDLE_DIM_AC, GET_WIDGET ("checkbutton_ac_display_dim"), "active", G_SETTINGS_BIND_DEFAULT); if (prefs->priv->has_button_lid == FALSE) { gtk_widget_hide (GET_WIDGET ("box_ac_lid")); } if (prefs->priv->has_lcd == FALSE) { gtk_widget_hide (GET_WIDGET ("box_ac_brightness")); gtk_widget_hide (GET_WIDGET ("checkbutton_ac_display_dim")); } } static void prefs_setup_battery (GpmPrefs *prefs) { GtkNotebook *notebook; gint page; const GpmActionPolicy button_lid_actions[] = {GPM_ACTION_POLICY_NOTHING, GPM_ACTION_POLICY_BLANK, GPM_ACTION_POLICY_SUSPEND, GPM_ACTION_POLICY_HIBERNATE, GPM_ACTION_POLICY_SHUTDOWN, -1}; const GpmActionPolicy battery_critical_actions[] = {GPM_ACTION_POLICY_NOTHING, GPM_ACTION_POLICY_SUSPEND, GPM_ACTION_POLICY_HIBERNATE, GPM_ACTION_POLICY_SHUTDOWN, -1}; static const gint computer_times[] = {10*60, 30*60, 1*60*60, 2*60*60, 0, /* never */ -1}; static const gint display_times[] = {1*60, 5*60, 10*60, 30*60, 1*60*60, 0, /* never */ -1}; gpm_prefs_setup_time_combo (prefs, "combobox_battery_computer", GPM_SETTINGS_SLEEP_COMPUTER_BATT, computer_times); gpm_prefs_setup_time_combo (prefs, "combobox_battery_display", GPM_SETTINGS_SLEEP_DISPLAY_BATT, display_times); if (prefs->priv->has_batteries == FALSE) { notebook = GET_NOTEBOOK ("notebook_preferences"); page = gtk_notebook_page_num (notebook, GET_WIDGET ("box_battery")); gtk_notebook_remove_page (notebook, page); return; } gpm_prefs_setup_action_combo (prefs, "combobox_battery_lid", GPM_SETTINGS_BUTTON_LID_BATT, button_lid_actions); gpm_prefs_setup_action_combo (prefs, "combobox_battery_critical", GPM_SETTINGS_ACTION_CRITICAL_BATT, battery_critical_actions); /* set up the checkboxes */ g_settings_bind (prefs->priv->settings, GPM_SETTINGS_BACKLIGHT_BATTERY_REDUCE, GET_WIDGET ("checkbutton_battery_display_reduce"), "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (prefs->priv->settings, GPM_SETTINGS_IDLE_DIM_BATT, GET_WIDGET ("checkbutton_battery_display_dim"), "active", G_SETTINGS_BIND_DEFAULT); if (prefs->priv->has_button_lid == FALSE) gtk_widget_hide (GET_WIDGET ("box_battery_lid")); if (prefs->priv->has_lcd == FALSE) gtk_widget_hide (GET_WIDGET ("checkbutton_battery_display_dim")); } static void prefs_setup_ups (GpmPrefs *prefs) { GtkWidget *notebook; GtkWidget *window; gint page; const GpmActionPolicy ups_low_actions[] = {GPM_ACTION_POLICY_NOTHING, GPM_ACTION_POLICY_HIBERNATE, GPM_ACTION_POLICY_SHUTDOWN, -1}; static const gint computer_times[] = {10*60, 30*60, 1*60*60, 2*60*60, 0, /* never */ -1}; static const gint display_times[] = {1*60, 5*60, 10*60, 30*60, 1*60*60, 0, /* never */ -1}; gpm_prefs_setup_time_combo (prefs, "combobox_ups_computer", GPM_SETTINGS_SLEEP_COMPUTER_UPS, computer_times); gpm_prefs_setup_time_combo (prefs, "combobox_ups_display", GPM_SETTINGS_SLEEP_DISPLAY_UPS, display_times); window = gpm_window (prefs); notebook = GET_WIDGET ("notebook_preferences"); gtk_widget_add_events (notebook, GDK_SCROLL_MASK); g_signal_connect (GTK_NOTEBOOK (notebook), "scroll-event", G_CALLBACK (gpm_dialog_page_scroll_event_cb), window); if (prefs->priv->has_ups == FALSE) { page = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), GET_WIDGET ("box_ups")); gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page); return; } gpm_prefs_setup_action_combo (prefs, "combobox_ups_low", GPM_SETTINGS_ACTION_LOW_UPS, ups_low_actions); gpm_prefs_setup_action_combo (prefs, "combobox_ups_critical", GPM_SETTINGS_ACTION_CRITICAL_UPS, ups_low_actions); } static void prefs_setup_general (GpmPrefs *prefs) { const GpmActionPolicy power_button_actions[] = {GPM_ACTION_POLICY_INTERACTIVE, GPM_ACTION_POLICY_SUSPEND, GPM_ACTION_POLICY_HIBERNATE, GPM_ACTION_POLICY_SHUTDOWN, GPM_ACTION_POLICY_NOTHING, -1}; const GpmActionPolicy suspend_button_actions[] = {GPM_ACTION_POLICY_NOTHING, GPM_ACTION_POLICY_SUSPEND, GPM_ACTION_POLICY_HIBERNATE, -1}; gpm_prefs_setup_action_combo (prefs, "combobox_general_power", GPM_SETTINGS_BUTTON_POWER, power_button_actions); gpm_prefs_setup_action_combo (prefs, "combobox_general_suspend", GPM_SETTINGS_BUTTON_SUSPEND, suspend_button_actions); if (prefs->priv->has_button_suspend == FALSE) gtk_widget_hide (GET_WIDGET ("box_general_suspend")); } /** * gpm_prefs_init: * @prefs: This prefs class instance **/ static void gpm_prefs_init (GpmPrefs *prefs) { GError *error = NULL; GPtrArray *devices = NULL; UpDevice *device; UpDeviceKind kind; GpmBrightness *brightness; guint i; GDBusProxy *proxy; GVariant *res, *inner; gchar * r; prefs->priv = gpm_prefs_get_instance_private (prefs); prefs->priv->client = up_client_new (); prefs->priv->console = egg_console_kit_new (); prefs->priv->settings = g_settings_new (GPM_SETTINGS_SCHEMA); prefs->priv->can_shutdown = FALSE; prefs->priv->can_suspend = FALSE; prefs->priv->can_hibernate = FALSE; if (LOGIND_RUNNING()) { /* get values from logind */ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", NULL, &error ); if (proxy == NULL) { g_error ("Error connecting to dbus - %s", error->message); g_error_free (error); return; } res = g_dbus_proxy_call_sync (proxy, "CanPowerOff", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error ); if (error == NULL && res != NULL) { g_variant_get(res,"(&s)", &r); prefs->priv->can_shutdown = g_strcmp0(r,"yes")==0?TRUE:FALSE; g_variant_unref (res); } else if (error != NULL ) { g_error ("Error in dbus - %s", error->message); g_error_free (error); } res = g_dbus_proxy_call_sync (proxy, "CanSuspend", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error ); if (error == NULL && res != NULL) { g_variant_get(res,"(&s)", &r); prefs->priv->can_suspend = g_strcmp0(r,"yes")==0?TRUE:FALSE; g_variant_unref (res); } else if (error != NULL ) { g_error ("Error in dbus - %s", error->message); g_error_free (error); } res = g_dbus_proxy_call_sync (proxy, "CanHibernate", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error ); if (error == NULL && res != NULL) { g_variant_get(res,"(&s)", &r); prefs->priv->can_hibernate = g_strcmp0(r,"yes")==0?TRUE:FALSE; g_variant_unref (res); } else if (error != NULL ) { g_error ("Error in dbus - %s", error->message); g_error_free (error); } g_object_unref(proxy); } else { /* Get values from ConsoleKit */ egg_console_kit_can_stop (prefs->priv->console, &prefs->priv->can_shutdown, NULL); egg_console_kit_can_suspend (prefs->priv->console, &prefs->priv->can_suspend, NULL); egg_console_kit_can_hibernate (prefs->priv->console, &prefs->priv->can_hibernate, NULL); } if (LOGIND_RUNNING()) { proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, "org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", NULL, &error ); if (proxy == NULL) { g_error ("Error connecting to dbus - %s", error->message); g_error_free (error); return; } res = g_dbus_proxy_call_sync (proxy, "Get", g_variant_new( "(ss)", "org.freedesktop.UPower", "LidIsPresent"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error ); if (error == NULL && res != NULL) { g_variant_get(res, "(v)", &inner ); prefs->priv->has_button_lid = g_variant_get_boolean(inner); g_variant_unref (inner); g_variant_unref (res); } else if (error != NULL ) { g_error ("Error in dbus - %s", error->message); g_error_free (error); } g_object_unref(proxy); } else { prefs->priv->has_button_lid = up_client_get_lid_is_present (prefs->priv->client); } prefs->priv->has_button_suspend = TRUE; /* find if we have brightness hardware */ brightness = gpm_brightness_new (); prefs->priv->has_lcd = gpm_brightness_has_hw (brightness); g_object_unref (brightness); devices = up_client_get_devices2 (prefs->priv->client); for (i=0; ilen; i++) { device = g_ptr_array_index (devices, i); g_object_get (device, "kind", &kind, NULL); if (kind == UP_DEVICE_KIND_BATTERY) prefs->priv->has_batteries = TRUE; if (kind == UP_DEVICE_KIND_UPS) prefs->priv->has_ups = TRUE; } g_ptr_array_unref (devices); error = NULL; prefs->priv->builder = gtk_builder_new (); (void) gtk_builder_add_from_resource (prefs->priv->builder, "/org/mate/powermanager/preferences/gpm-prefs.ui", &error); if (error) { g_error ("failed to load ui: %s", error->message); } /* Hide window first so that the dialogue resizes itself without redrawing */ gtk_widget_hide (GET_WIDGET ("dialog_preferences")); gtk_widget_hide (GET_WIDGET ("button_defaults")); /** setup the notification page */ gint icon_policy; GtkWidget *radiobutton_icon_always; GtkWidget *radiobutton_icon_present; GtkWidget *radiobutton_icon_charge; GtkWidget *radiobutton_icon_low; GtkWidget *radiobutton_icon_never; icon_policy = g_settings_get_enum (prefs->priv->settings, GPM_SETTINGS_ICON_POLICY); radiobutton_icon_always = GET_WIDGET ("radiobutton_notification_always"); radiobutton_icon_present = GET_WIDGET ("radiobutton_notification_present"); radiobutton_icon_charge = GET_WIDGET ("radiobutton_notification_charge"); radiobutton_icon_low = GET_WIDGET ("radiobutton_notification_low"); radiobutton_icon_never = GET_WIDGET ("radiobutton_notification_never"); gtk_widget_set_sensitive (GET_WIDGET ("box_general_notification"), g_settings_is_writable (prefs->priv->settings, GPM_SETTINGS_ICON_POLICY)); switch (icon_policy) { case GPM_ICON_POLICY_ALWAYS: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_always), TRUE); break; case GPM_ICON_POLICY_PRESENT: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_present), TRUE); break; case GPM_ICON_POLICY_CHARGE: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_charge), TRUE); break; case GPM_ICON_POLICY_LOW: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_low), TRUE); break; case GPM_ICON_POLICY_NEVER: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_never), TRUE); break; } g_object_set_data (G_OBJECT (radiobutton_icon_always), "policy", GINT_TO_POINTER (GPM_ICON_POLICY_ALWAYS)); g_object_set_data (G_OBJECT (radiobutton_icon_present), "policy", GINT_TO_POINTER (GPM_ICON_POLICY_PRESENT)); g_object_set_data (G_OBJECT (radiobutton_icon_charge), "policy", GINT_TO_POINTER (GPM_ICON_POLICY_CHARGE)); g_object_set_data (G_OBJECT (radiobutton_icon_low), "policy", GINT_TO_POINTER (GPM_ICON_POLICY_LOW)); g_object_set_data (G_OBJECT (radiobutton_icon_never), "policy", GINT_TO_POINTER (GPM_ICON_POLICY_NEVER)); gtk_builder_add_callback_symbols (prefs->priv->builder, "on_dialog_preferences_delete_event", G_CALLBACK (gpm_prefs_delete_event_cb), "on_button_help_clicked", G_CALLBACK (gpm_prefs_help_cb), "on_button_close_clicked", G_CALLBACK (gpm_prefs_close_cb), "on_radiobutton_notification_never_clicked", G_CALLBACK (gpm_prefs_icon_radio_cb), "on_radiobutton_notification_low_clicked", G_CALLBACK (gpm_prefs_icon_radio_cb), "on_radiobutton_notification_charge_clicked", G_CALLBACK (gpm_prefs_icon_radio_cb), "on_radiobutton_notification_present_clicked", G_CALLBACK (gpm_prefs_icon_radio_cb), "on_radiobutton_notification_always_clicked", G_CALLBACK (gpm_prefs_icon_radio_cb), NULL); gtk_builder_connect_signals (prefs->priv->builder, prefs); prefs_setup_ac (prefs); prefs_setup_battery (prefs); prefs_setup_ups (prefs); prefs_setup_general (prefs); } /** * gpm_prefs_finalize: * @object: This prefs class instance **/ static void gpm_prefs_finalize (GObject *object) { GpmPrefs *prefs; g_return_if_fail (object != NULL); g_return_if_fail (GPM_IS_PREFS (object)); prefs = GPM_PREFS (object); prefs->priv = gpm_prefs_get_instance_private (prefs); g_object_unref (prefs->priv->settings); g_object_unref (prefs->priv->client); g_object_unref (prefs->priv->console); g_object_unref (prefs->priv->builder); G_OBJECT_CLASS (gpm_prefs_parent_class)->finalize (object); } /** * gpm_prefs_new: * Return value: new GpmPrefs instance. **/ GpmPrefs * gpm_prefs_new (void) { GpmPrefs *prefs; prefs = g_object_new (GPM_TYPE_PREFS, NULL); return GPM_PREFS (prefs); } /** * gpm_window: * Return value: Prefs window widget. **/ GtkWidget * gpm_window (GpmPrefs *prefs) { return GET_WIDGET ("dialog_preferences"); }