diff options
author | Brent Hull <[email protected]> | 2012-10-30 15:55:35 -0400 |
---|---|---|
committer | Brent Hull <[email protected]> | 2012-10-30 15:55:35 -0400 |
commit | 060a4507145425c02c6aa0ef810138c04d38f5a9 (patch) | |
tree | 696262b89d749abf74ccec08260969679ef70d6e /src | |
parent | e58350ab1a00d55e82f7ae97589562e10a77c485 (diff) | |
download | mate-power-manager-060a4507145425c02c6aa0ef810138c04d38f5a9.tar.bz2 mate-power-manager-060a4507145425c02c6aa0ef810138c04d38f5a9.tar.xz |
Use gsettings enums (partially from GNOME)
Diffstat (limited to 'src')
-rw-r--r-- | src/gpm-backlight.c | 11 | ||||
-rw-r--r-- | src/gpm-common.c | 84 | ||||
-rw-r--r-- | src/gpm-common.h | 4 | ||||
-rw-r--r-- | src/gpm-dpms.c | 47 | ||||
-rw-r--r-- | src/gpm-dpms.h | 2 | ||||
-rw-r--r-- | src/gpm-engine.c | 10 | ||||
-rw-r--r-- | src/gpm-manager.c | 31 | ||||
-rw-r--r-- | src/gpm-prefs-core.c | 21 |
8 files changed, 17 insertions, 193 deletions
diff --git a/src/gpm-backlight.c b/src/gpm-backlight.c index 9f6b148..573778a 100644 --- a/src/gpm-backlight.c +++ b/src/gpm-backlight.c @@ -545,7 +545,6 @@ idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight) gboolean ret; GError *error = NULL; gboolean on_battery; - gchar *dpms_method; GpmDpmsMode dpms_mode; /* don't dim or undim the screen when the lid is closed */ @@ -594,16 +593,13 @@ idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight) "on-battery", &on_battery, NULL); if (!on_battery) - dpms_method = g_settings_get_string (backlight->priv->settings, GPM_SETTINGS_DPMS_METHOD_AC); + dpms_mode = g_settings_get_enum (backlight->priv->settings, GPM_SETTINGS_DPMS_METHOD_AC); else - dpms_method = g_settings_get_string (backlight->priv->settings, GPM_SETTINGS_DPMS_METHOD_BATT); - - /* convert the string types to standard types */ - dpms_mode = gpm_dpms_mode_from_string (dpms_method); + dpms_mode = g_settings_get_enum (backlight->priv->settings, GPM_SETTINGS_DPMS_METHOD_BATT); /* check if method is valid */ if (dpms_mode == GPM_DPMS_MODE_UNKNOWN || dpms_mode == GPM_DPMS_MODE_ON) { - egg_warning ("BACKLIGHT method %s unknown. Using OFF.", dpms_method); + egg_warning ("BACKLIGHT method %i unknown. Using OFF.", dpms_mode); dpms_mode = GPM_DPMS_MODE_OFF; } @@ -614,7 +610,6 @@ idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight) g_error_free (error); } - g_free (dpms_method); } } diff --git a/src/gpm-common.c b/src/gpm-common.c index 0d0e536..861837a 100644 --- a/src/gpm-common.c +++ b/src/gpm-common.c @@ -79,90 +79,6 @@ gpm_get_timestring (guint time_secs) } /** - * gpm_icon_policy_from_string: - **/ -GpmIconPolicy -gpm_icon_policy_from_string (const gchar *policy) -{ - if (policy == NULL) - return GPM_ICON_POLICY_NEVER; - if (g_strcmp0 (policy, "always") == 0) - return GPM_ICON_POLICY_ALWAYS; - if (g_strcmp0 (policy, "present") == 0) - return GPM_ICON_POLICY_PRESENT; - if (g_strcmp0 (policy, "charge") == 0) - return GPM_ICON_POLICY_CHARGE; - if (g_strcmp0 (policy, "low") == 0) - return GPM_ICON_POLICY_LOW; - if (g_strcmp0 (policy, "critical") == 0) - return GPM_ICON_POLICY_CRITICAL; - if (g_strcmp0 (policy, "never") == 0) - return GPM_ICON_POLICY_NEVER; - return GPM_ICON_POLICY_NEVER; -} - -/** - * gpm_icon_policy_to_string: - **/ -const gchar * -gpm_icon_policy_to_string (GpmIconPolicy policy) -{ - if (policy == GPM_ICON_POLICY_ALWAYS) - return "always"; - if (policy == GPM_ICON_POLICY_PRESENT) - return "present"; - if (policy == GPM_ICON_POLICY_CHARGE) - return "charge"; - if (policy == GPM_ICON_POLICY_LOW) - return "low"; - if (policy == GPM_ICON_POLICY_CRITICAL) - return "critical"; - if (policy == GPM_ICON_POLICY_NEVER) - return "never"; - return "never"; -} - -/** - * gpm_action_policy_from_string: - **/ -GpmActionPolicy -gpm_action_policy_from_string (const gchar *policy) -{ - if (policy == NULL) - return GPM_ACTION_POLICY_NOTHING; - if (g_strcmp0 (policy, "blank") == 0) - return GPM_ACTION_POLICY_BLANK; - if (g_strcmp0 (policy, "shutdown") == 0) - return GPM_ACTION_POLICY_SHUTDOWN; - if (g_strcmp0 (policy, "suspend") == 0) - return GPM_ACTION_POLICY_SUSPEND; - if (g_strcmp0 (policy, "hibernate") == 0) - return GPM_ACTION_POLICY_HIBERNATE; - if (g_strcmp0 (policy, "interactive") == 0) - return GPM_ACTION_POLICY_INTERACTIVE; - return GPM_ACTION_POLICY_NOTHING; -} - -/** - * gpm_action_policy_to_string: - **/ -const gchar * -gpm_action_policy_to_string (GpmActionPolicy policy) -{ - if (policy == GPM_ACTION_POLICY_BLANK) - return "blank"; - if (policy == GPM_ACTION_POLICY_SHUTDOWN) - return "shutdown"; - if (policy == GPM_ACTION_POLICY_SUSPEND) - return "suspend"; - if (policy == GPM_ACTION_POLICY_HIBERNATE) - return "hibernate"; - if (policy == GPM_ACTION_POLICY_INTERACTIVE) - return "interactive"; - return "nothing"; -} - -/** * gpm_help_display: * @link_id: Subsection of mate-power-manager help section **/ diff --git a/src/gpm-common.h b/src/gpm-common.h index 96a06a4..ee05036 100644 --- a/src/gpm-common.h +++ b/src/gpm-common.h @@ -157,10 +157,6 @@ typedef enum { } GpmActionPolicy; gchar *gpm_get_timestring (guint time); -GpmIconPolicy gpm_icon_policy_from_string (const gchar *policy); -const gchar *gpm_icon_policy_to_string (GpmIconPolicy policy); -GpmActionPolicy gpm_action_policy_from_string (const gchar *policy); -const gchar *gpm_action_policy_to_string (GpmActionPolicy policy); void gpm_help_display (const gchar *link_id); #ifdef EGG_TEST void gpm_common_test (gpointer data); diff --git a/src/gpm-dpms.c b/src/gpm-dpms.c index 13928f9..8eaf704 100644 --- a/src/gpm-dpms.c +++ b/src/gpm-dpms.c @@ -190,53 +190,6 @@ gpm_dpms_x11_set_mode (GpmDpms *dpms, GpmDpmsMode mode, GError **error) } /** - * gpm_dpms_mode_from_string: - **/ -GpmDpmsMode -gpm_dpms_mode_from_string (const gchar *str) -{ - if (str == NULL) - return GPM_DPMS_MODE_UNKNOWN; - if (strcmp (str, "on") == 0) - return GPM_DPMS_MODE_ON; - if (strcmp (str, "standby") == 0) - return GPM_DPMS_MODE_STANDBY; - if (strcmp (str, "suspend") == 0) - return GPM_DPMS_MODE_SUSPEND; - if (strcmp (str, "off") == 0) - return GPM_DPMS_MODE_OFF; - return GPM_DPMS_MODE_UNKNOWN; -} - -/** - * gpm_dpms_mode_to_string: - **/ -const gchar * -gpm_dpms_mode_to_string (GpmDpmsMode mode) -{ - const gchar *str = NULL; - - switch (mode) { - case GPM_DPMS_MODE_ON: - str = "on"; - break; - case GPM_DPMS_MODE_STANDBY: - str = "standby"; - break; - case GPM_DPMS_MODE_SUSPEND: - str = "suspend"; - break; - case GPM_DPMS_MODE_OFF: - str = "off"; - break; - default: - str = NULL; - break; - } - return str; -} - -/** * gpm_dpms_set_mode: **/ gboolean diff --git a/src/gpm-dpms.h b/src/gpm-dpms.h index 95cd226..b6218fc 100644 --- a/src/gpm-dpms.h +++ b/src/gpm-dpms.h @@ -71,8 +71,6 @@ gboolean gpm_dpms_get_mode (GpmDpms *dpms, gboolean gpm_dpms_set_mode (GpmDpms *dpms, GpmDpmsMode mode, GError **error); -const gchar *gpm_dpms_mode_to_string (GpmDpmsMode mode); -GpmDpmsMode gpm_dpms_mode_from_string (const gchar *mode); void gpm_dpms_test (gpointer data); G_END_DECLS diff --git a/src/gpm-engine.c b/src/gpm-engine.c index b006c32..0f9d0c1 100644 --- a/src/gpm-engine.c +++ b/src/gpm-engine.c @@ -513,7 +513,6 @@ gpm_engine_recalculate_state (GpmEngine *engine) static void gpm_engine_settings_key_changed_cb (GSettings *settings, const gchar *key, GpmEngine *engine) { - gchar *icon_policy; if (g_strcmp0 (key, GPM_SETTINGS_USE_TIME_POLICY) == 0) { engine->priv->use_time_primary = g_settings_get_boolean (settings, key); @@ -521,9 +520,7 @@ gpm_engine_settings_key_changed_cb (GSettings *settings, const gchar *key, GpmEn } else if (g_strcmp0 (key, GPM_SETTINGS_ICON_POLICY) == 0) { /* do we want to display the icon in the tray */ - icon_policy = g_settings_get_string (settings, key); - engine->priv->icon_policy = gpm_icon_policy_from_string (icon_policy); - g_free (icon_policy); + engine->priv->icon_policy = g_settings_get_enum (settings, key); /* perhaps change icon */ gpm_engine_recalculate_state_icon (engine); @@ -1045,7 +1042,6 @@ phone_device_refresh_cb (GpmPhone *phone, guint idx, GpmEngine *engine) static void gpm_engine_init (GpmEngine *engine) { - gchar *icon_policy; engine->priv = GPM_ENGINE_GET_PRIVATE (engine); @@ -1084,9 +1080,7 @@ gpm_engine_init (GpmEngine *engine) engine->priv->previous_summary = NULL; /* do we want to display the icon in the tray */ - icon_policy = g_settings_get_string (engine->priv->settings, GPM_SETTINGS_ICON_POLICY); - engine->priv->icon_policy = gpm_icon_policy_from_string (icon_policy); - g_free (icon_policy); + engine->priv->icon_policy = g_settings_get_enum (engine->priv->settings, GPM_SETTINGS_ICON_POLICY); /* get percentage policy */ engine->priv->low_percentage = g_settings_get_int (engine->priv->settings, GPM_SETTINGS_PERCENTAGE_LOW); diff --git a/src/gpm-manager.c b/src/gpm-manager.c index 6014f84..b351b6f 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -667,16 +667,14 @@ gpm_manager_action_hibernate (GpmManager *manager, const gchar *reason) static gboolean gpm_manager_perform_policy (GpmManager *manager, const gchar *policy_key, const gchar *reason) { - gchar *action = NULL; GpmActionPolicy policy; /* are we inhibited? */ if (gpm_manager_is_inhibit_valid (manager, FALSE, "policy action") == FALSE) return FALSE; - action = g_settings_get_string (manager->priv->settings, policy_key); - egg_debug ("action: %s set to %s (%s)", policy_key, action, reason); - policy = gpm_action_policy_from_string (action); + policy = g_settings_get_enum (manager->priv->settings, policy_key); + egg_debug ("action: %s set to %i (%s)", policy_key, policy, reason); if (policy == GPM_ACTION_POLICY_NOTHING) { egg_debug ("doing nothing, reason: %s", reason); @@ -700,10 +698,9 @@ gpm_manager_perform_policy (GpmManager *manager, const gchar *policy_key, const gpm_session_logout (session); g_object_unref (session); } else { - egg_warning ("unknown action %s", action); + egg_warning ("unknown action %i", policy); } - g_free (action); return TRUE; } @@ -717,16 +714,14 @@ gpm_manager_perform_policy (GpmManager *manager, const gchar *policy_key, const static void gpm_manager_idle_do_sleep (GpmManager *manager) { - gchar *action = NULL; gboolean ret; GError *error = NULL; GpmActionPolicy policy; if (!manager->priv->on_battery) - action = g_settings_get_string (manager->priv->settings, GPM_SETTINGS_ACTION_SLEEP_TYPE_AC); + policy = g_settings_get_enum (manager->priv->settings, GPM_SETTINGS_ACTION_SLEEP_TYPE_AC); else - action = g_settings_get_string (manager->priv->settings, GPM_SETTINGS_ACTION_SLEEP_TYPE_BATT); - policy = gpm_action_policy_from_string (action); + policy = g_settings_get_enum (manager->priv->settings, GPM_SETTINGS_ACTION_SLEEP_TYPE_BATT); if (policy == GPM_ACTION_POLICY_NOTHING) { egg_debug ("doing nothing as system idle action"); @@ -759,7 +754,6 @@ gpm_manager_idle_do_sleep (GpmManager *manager) } } } - g_free (action); } /** @@ -1553,7 +1547,6 @@ gpm_manager_engine_charge_critical_cb (GpmEngine *engine, UpDevice *device, GpmM { const gchar *title = NULL; gchar *message = NULL; - gchar *action; gchar *icon = NULL; UpDeviceKind kind; gdouble percentage; @@ -1589,8 +1582,7 @@ gpm_manager_engine_charge_critical_cb (GpmEngine *engine, UpDevice *device, GpmM } /* we have to do different warnings depending on the policy */ - action = g_settings_get_string (manager->priv->settings, GPM_SETTINGS_ACTION_CRITICAL_BATT); - policy = gpm_action_policy_from_string (action); + policy = g_settings_get_enum (manager->priv->settings, GPM_SETTINGS_ACTION_CRITICAL_BATT); /* use different text for different actions */ if (policy == GPM_ACTION_POLICY_NOTHING) { @@ -1610,7 +1602,6 @@ gpm_manager_engine_charge_critical_cb (GpmEngine *engine, UpDevice *device, GpmM message = g_strdup_printf (_("Computer will shutdown very soon unless it is plugged in.")); } - g_free (action); } else if (kind == UP_DEVICE_KIND_UPS) { gchar *remaining_text; @@ -1720,7 +1711,6 @@ static void gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmManager *manager) { const gchar *title = NULL; - gchar *action; gchar *message = NULL; gchar *icon = NULL; UpDeviceKind kind; @@ -1745,8 +1735,7 @@ gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmMan title = _("Laptop battery critically low"); /* we have to do different warnings depending on the policy */ - action = g_settings_get_string (manager->priv->settings, GPM_SETTINGS_ACTION_CRITICAL_BATT); - policy = gpm_action_policy_from_string (action); + policy = g_settings_get_enum (manager->priv->settings, GPM_SETTINGS_ACTION_CRITICAL_BATT); /* use different text for different actions */ if (policy == GPM_ACTION_POLICY_NOTHING) { @@ -1773,8 +1762,6 @@ gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmMan "this computer is about to shutdown.")); } - g_free (action); - /* wait 20 seconds for user-panic */ g_timeout_add_seconds (20, (GSourceFunc) manager_critical_action_do, manager); @@ -1783,8 +1770,7 @@ gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmMan title = _("UPS critically low"); /* we have to do different warnings depending on the policy */ - action = g_settings_get_string (manager->priv->settings, GPM_SETTINGS_ACTION_CRITICAL_UPS); - policy = gpm_action_policy_from_string (action); + policy = g_settings_get_enum (manager->priv->settings, GPM_SETTINGS_ACTION_CRITICAL_UPS); /* use different text for different actions */ if (policy == GPM_ACTION_POLICY_NOTHING) { @@ -1807,7 +1793,6 @@ gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmMan /* wait 20 seconds for user-panic */ g_timeout_add_seconds (20, (GSourceFunc) manager_critical_action_do, manager); - g_free (action); } /* not all types have actions */ diff --git a/src/gpm-prefs-core.c b/src/gpm-prefs-core.c index 3f23c87..790427b 100644 --- a/src/gpm-prefs-core.c +++ b/src/gpm-prefs-core.c @@ -135,13 +135,10 @@ gpm_prefs_help_cb (GtkWidget *widget, GpmPrefs *prefs) static void gpm_prefs_icon_radio_cb (GtkWidget *widget, GpmPrefs *prefs) { - const gchar *str; gint policy; policy = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "policy")); - str = gpm_icon_policy_to_string (policy); - egg_debug ("Changing %s to %s", GPM_SETTINGS_ICON_POLICY, str); - g_settings_set_string (prefs->priv->settings, GPM_SETTINGS_ICON_POLICY, str); + g_settings_set_enum (prefs->priv->settings, GPM_SETTINGS_ICON_POLICY, policy); } /** @@ -164,7 +161,6 @@ gpm_prefs_action_combo_changed_cb (GtkWidget *widget, GpmPrefs *prefs) GpmActionPolicy policy; const GpmActionPolicy *actions; const gchar *gpm_pref_key; - const gchar *action; guint active; actions = (const GpmActionPolicy *) g_object_get_data (G_OBJECT (widget), "actions"); @@ -172,9 +168,7 @@ gpm_prefs_action_combo_changed_cb (GtkWidget *widget, GpmPrefs *prefs) active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); policy = actions[active]; - action = gpm_action_policy_to_string (policy); - egg_debug ("Changing %s to %s", gpm_pref_key, action); - g_settings_set_string (prefs->priv->settings, gpm_pref_key, action); + g_settings_set_enum (prefs->priv->settings, gpm_pref_key, policy); } /** @@ -242,7 +236,6 @@ static void gpm_prefs_setup_action_combo (GpmPrefs *prefs, const gchar *widget_name, const gchar *gpm_pref_key, const GpmActionPolicy *actions) { - gchar *value_txt; gint i; gboolean is_writable; GtkWidget *widget; @@ -254,9 +247,8 @@ gpm_prefs_setup_action_combo (GpmPrefs *prefs, const gchar *widget_name, widget = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder, widget_name)); gpm_prefs_set_combo_simple_text (widget); - value_txt = g_settings_get_string (prefs->priv->settings, gpm_pref_key); + value = g_settings_get_enum (prefs->priv->settings, gpm_pref_key); is_writable = g_settings_is_writable (prefs->priv->settings, gpm_pref_key); - value = gpm_action_policy_from_string (value_txt); gtk_widget_set_sensitive (widget, is_writable); @@ -340,13 +332,11 @@ gpm_prefs_setup_action_combo (GpmPrefs *prefs, const gchar *widget_name, /* set what we have in the settings */ for (i=0; actions_added[i] != -1; i++) { policy = actions_added[i]; - egg_debug ("added: %s", gpm_action_policy_to_string (policy)); if (value == policy) gtk_combo_box_set_active (GTK_COMBO_BOX (widget), i); } g_ptr_array_unref (array); - g_free (value_txt); } /** @@ -435,7 +425,6 @@ gpm_prefs_delete_event_cb (GtkWidget *widget, GdkEvent *event, GpmPrefs *prefs) static void prefs_setup_notification (GpmPrefs *prefs) { - gchar *icon_policy_str; gint icon_policy; GtkWidget *radiobutton_icon_always; GtkWidget *radiobutton_icon_present; @@ -444,9 +433,7 @@ prefs_setup_notification (GpmPrefs *prefs) GtkWidget *radiobutton_icon_never; gboolean is_writable; - icon_policy_str = g_settings_get_string (prefs->priv->settings, GPM_SETTINGS_ICON_POLICY); - icon_policy = gpm_icon_policy_from_string (icon_policy_str); - g_free (icon_policy_str); + icon_policy = g_settings_get_enum (prefs->priv->settings, GPM_SETTINGS_ICON_POLICY); radiobutton_icon_always = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder, "radiobutton_notification_always")); |