[gnome-power-manager: 2/3] Use the GSetting enum functionality



commit 6273ede3210f1e67e82f419f3dfe4556384c03bf
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jun 19 23:37:56 2010 +0100

    Use the GSetting enum functionality

 data/org.gnome.power-manager.gschema.xml |   72 +++++++++++++++++----------
 src/cc-power-panel.c                     |   23 ++-------
 src/gpm-backlight.c                      |   12 +---
 src/gpm-common.c                         |   81 ------------------------------
 src/gpm-common.h                         |    4 --
 src/gpm-engine.c                         |   11 +---
 src/gpm-manager.c                        |   33 +++---------
 7 files changed, 63 insertions(+), 173 deletions(-)
---
diff --git a/data/org.gnome.power-manager.gschema.xml b/data/org.gnome.power-manager.gschema.xml
index b001e61..60882ed 100644
--- a/data/org.gnome.power-manager.gschema.xml
+++ b/data/org.gnome.power-manager.gschema.xml
@@ -1,34 +1,54 @@
 <schemalist>
+  <enum id="org.gnome.power-manager.ActionType">
+    <value nick="blank" value="0"/>
+    <value nick="suspend" value="1"/>
+    <value nick="shutdown" value="2"/>
+    <value nick="hibernate" value="3"/>
+    <value nick="interactive" value="4"/>
+    <value nick="nothing" value="5"/>
+  </enum>
+  <enum id="org.gnome.power-manager.IconPolicy">
+    <value nick="present" value="0"/>
+    <value nick="charge" value="1"/>
+    <value nick="low" value="2"/>
+    <value nick="critical" value="3"/>
+    <value nick="never" value="4"/>
+  </enum>
+  <enum id="org.gnome.power-manager.DpmsMethod">
+    <value nick="standby" value="1"/>
+    <value nick="suspend" value="2"/>
+    <value nick="off" value="3"/>
+  </enum>
   <schema id="org.gnome.power-manager" path="/apps/gnome-power-manager/">
-    <key name="action-sleep-type-battery" type="s">
+    <key name="action-sleep-type-battery" enum="org.gnome.power-manager.ActionType">
       <default>'hibernate'</default>
       <summary>Whether to hibernate, suspend or do nothing when inactive</summary>
-      <description>The type of sleeping that should be performed when the computer is inactive. Possible values are "hibernate", "suspend" and "nothing".</description>
+      <description>The type of sleeping that should be performed when the computer is inactive.</description>
     </key>
-    <key name="action-critical-battery" type="s">
+    <key name="action-critical-battery" enum="org.gnome.power-manager.ActionType">
       <default>'hibernate'</default>
       <summary>Battery critical low action</summary>
-      <description>The action to take when the battery is critically low. Possible values are "hibernate", "suspend", "shutdown" and "nothing".</description>
+      <description>The action to take when the battery is critically low.</description>
     </key>
     <key name="event-when-closed-battery" type="b">
       <default>true</default>
       <summary>If the battery event should occur when the lid is shut and the power disconnected</summary>
       <description>If the battery lid close event should occur (for example 'Suspend when lid closed on battery') when the lid is previously shut and the AC power disconnected at a later time.</description>
     </key>
-    <key name="action-sleep-type-ac" type="s">
+    <key name="action-sleep-type-ac" enum="org.gnome.power-manager.ActionType">
       <default>'suspend'</default>
       <summary>Whether to hibernate, suspend or do nothing when inactive</summary>
-      <description>The type of sleeping that should be performed when the computer is inactive. Possible values are "hibernate", "suspend" and "nothing".</description>
+      <description>The type of sleeping that should be performed when the computer is inactive.</description>
     </key>
-    <key name="action-critical-ups" type="s">
+    <key name="action-critical-ups" enum="org.gnome.power-manager.ActionType">
       <default>'shutdown'</default>
       <summary>UPS critical low action</summary>
-      <description>The action to take when the UPS is critically low. Possible values are "hibernate", "suspend", "shutdown" and "nothing".</description>
+      <description>The action to take when the UPS is critically low.</description>
     </key>
-    <key name="action-low-ups" type="s">
+    <key name="action-low-ups" enum="org.gnome.power-manager.ActionType">
       <default>'hibernate'</default>
       <summary>UPS low power action</summary>
-      <description>The action to take when the UPS is low. Possible values are "hibernate", "suspend", "shutdown" and "nothing".</description>
+      <description>The action to take when the UPS is low.</description>
     </key>
     <key name="backlight-enable" type="b">
       <default>true</default>
@@ -65,45 +85,45 @@
       <summary>Dim the screen after a period of inactivity when on AC power</summary>
       <description>If the screen should be dimmed to save power when the computer is idle when on AC power.</description>
     </key>
-    <key name="dpms-method-ac" type="s">
+    <key name="dpms-method-ac" enum="org.gnome.power-manager.DpmsMethod">
       <default>'off'</default>
       <summary>Method used to blank screen on AC</summary>
-      <description>The DPMS method used to blank the screen when on AC power. Possible values are "standby", "suspend" and "off".</description>
+      <description>The DPMS method used to blank the screen when on AC power.</description>
     </key>
-    <key name="dpms-method-battery" type="s">
+    <key name="dpms-method-battery" enum="org.gnome.power-manager.DpmsMethod">
       <default>'off'</default>
       <summary>Method used to blank screen on battery</summary>
-      <description>The DPMS method used to blank the screen when on battery power. Possible values are "standby", "suspend" and "off".</description>
+      <description>The DPMS method used to blank the screen when on battery power.</description>
     </key>
     <key name="brightness-ac" type="d">
       <default>1.0</default>
       <summary>LCD brightness when on AC</summary>
       <description>The brightness of the display when on AC power. Possible values are between 0.0 and 1.0.</description>
     </key>
-    <key name="button-suspend" type="s">
+    <key name="button-suspend" enum="org.gnome.power-manager.ActionType">
       <default>'suspend'</default>
       <summary>Suspend button action</summary>
-      <description>The action to take when the system suspend button is pressed. Possible values are "suspend", "hibernate", "interactive", "shutdown" and "nothing".</description>
+      <description>The action to take when the system suspend button is pressed.</description>
     </key>
-    <key name="button-hibernate" type="s">
+    <key name="button-hibernate" enum="org.gnome.power-manager.ActionType">
       <default>'hibernate'</default>
       <summary>Hibernate button action</summary>
-      <description>The action to take when the system hibernate button is pressed. Possible values are "suspend", "hibernate", "interactive", "shutdown" and "nothing".</description>
+      <description>The action to take when the system hibernate button is pressed.</description>
     </key>
-    <key name="button-power" type="s">
+    <key name="button-power" enum="org.gnome.power-manager.ActionType">
       <default>'interactive'</default>
       <summary>Power button action</summary>
-      <description>The action to take when the system power button is pressed. Possible values are "suspend", "hibernate", "interactive", "shutdown" and "nothing".</description>
+      <description>The action to take when the system power button is pressed.</description>
     </key>
-    <key name="button-lid-battery" type="s">
+    <key name="button-lid-battery" enum="org.gnome.power-manager.ActionType">
       <default>'suspend'</default>
       <summary>Laptop lid close action on battery</summary>
-      <description>The action to take when the laptop lid is closed and the laptop is on battery power. Possible values are "suspend", "hibernate", "blank", and "nothing".</description>
+      <description>The action to take when the laptop lid is closed and the laptop is on battery power.</description>
     </key>
-    <key name="button-lid-ac" type="s">
+    <key name="button-lid-ac" enum="org.gnome.power-manager.ActionType">
       <default>'suspend'</default>
       <summary>Laptop lid close action when on AC</summary>
-      <description>The action to take when the laptop lid is closed and the laptop is on AC power. Possible values are "suspend", "hibernate", "blank" and "nothing".</description>
+      <description>The action to take when the laptop lid is closed and the laptop is on AC power.</description>
     </key>
     <key name="schema-version" type="i">
       <default>3</default>
@@ -329,10 +349,10 @@
       <default>true</default>
       <summary>If preferences and statistics items should be shown in the context menu</summary>
     </key>
-    <key name="icon-policy" type="s">
+    <key name="icon-policy" enum="org.gnome.power-manager.IconPolicy">
       <default>'present'</default>
       <summary>When to show the notification icon</summary>
-      <description>Display options for the notification icon. Valid options are "never", "low", "critical", "charge", and "present".</description>
+      <description>Display options for the notification icon.</description>
     </key>
   </schema>
 </schemalist>
diff --git a/src/cc-power-panel.c b/src/cc-power-panel.c
index 6e832d8..45f74e4 100644
--- a/src/cc-power-panel.c
+++ b/src/cc-power-panel.c
@@ -71,13 +71,9 @@ cc_power_panel_help_cb (GtkWidget *widget, CcPowerPanel *panel)
 static void
 cc_power_panel_icon_radio_cb (GtkWidget *widget, CcPowerPanel *panel)
 {
-	const gchar *str;
 	gint policy;
-
 	policy = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "policy"));
-	str = gpm_icon_policy_to_string (policy);
-	g_debug ("Changing %s to %s", GPM_SETTINGS_ICON_POLICY, str);
-	g_settings_set_string (panel->priv->settings, GPM_SETTINGS_ICON_POLICY, str);
+	g_settings_set_enum (panel->priv->settings, GPM_SETTINGS_ICON_POLICY, policy);
 }
 
 /**
@@ -98,7 +94,6 @@ cc_power_panel_action_combo_changed_cb (GtkWidget *widget, CcPowerPanel *panel)
 	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");
@@ -106,9 +101,7 @@ cc_power_panel_action_combo_changed_cb (GtkWidget *widget, CcPowerPanel *panel)
 
 	active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
 	policy = actions[active];
-	action = gpm_action_policy_to_string (policy);
-	g_debug ("Changing %s to %s", gpm_pref_key, action);
-	g_settings_set_string (panel->priv->settings, gpm_pref_key, action);
+	g_settings_set_enum (panel->priv->settings, gpm_pref_key, policy);
 }
 
 /**
@@ -168,7 +161,6 @@ static void
 cc_power_panel_setup_action_combo (CcPowerPanel *panel, const gchar *widget_name,
 			      const gchar *gpm_pref_key, const GpmActionPolicy *actions)
 {
-	gchar *value_txt;
 	gint i;
 	gboolean is_writable;
 	GtkWidget *widget;
@@ -180,9 +172,8 @@ cc_power_panel_setup_action_combo (CcPowerPanel *panel, const gchar *widget_name
 	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, widget_name));
 	cc_power_panel_set_combo_simple_text (widget);
 
-	value_txt = g_settings_get_string (panel->priv->settings, gpm_pref_key);
+	value = g_settings_get_enum (panel->priv->settings, gpm_pref_key);
 	is_writable = g_settings_is_writable (panel->priv->settings, gpm_pref_key);
-	value = gpm_action_policy_from_string (value_txt);
 
 	gtk_widget_set_sensitive (widget, is_writable);
 
@@ -236,13 +227,11 @@ cc_power_panel_setup_action_combo (CcPowerPanel *panel, const gchar *widget_name
 	/* set what we have in GConf */
 	for (i=0; actions_added[i] != -1; i++) {
 		policy = actions_added[i];
-		g_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);
 }
 
 /**
@@ -294,7 +283,6 @@ cc_power_panel_setup_time_combo (CcPowerPanel *panel, const gchar *widget_name,
 static void
 cc_power_panel_setup_notification (CcPowerPanel *panel)
 {
-	gchar *icon_policy_str;
 	gint icon_policy;
 	GtkWidget *radiobutton_icon_present;
 	GtkWidget *radiobutton_icon_charge;
@@ -302,10 +290,7 @@ cc_power_panel_setup_notification (CcPowerPanel *panel)
 	GtkWidget *radiobutton_icon_never;
 	gboolean is_writable;
 
-	icon_policy_str = g_settings_get_string (panel->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 (panel->priv->settings, GPM_SETTINGS_ICON_POLICY);
 	radiobutton_icon_present = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
 					       "radiobutton_notification_present"));
 	radiobutton_icon_charge = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
diff --git a/src/gpm-backlight.c b/src/gpm-backlight.c
index 1a88981..e7fa3bd 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 %s unknown. Using OFF.", gpm_dpms_mode_to_string (dpms_mode));
 			dpms_mode = GPM_DPMS_MODE_OFF;
 		}
 
@@ -613,8 +609,6 @@ idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight)
 			egg_warning ("failed to change DPMS: %s", error->message);
 			g_error_free (error);
 		}
-
-		g_free (dpms_method);
 	}
 }
 
diff --git a/src/gpm-common.c b/src/gpm-common.c
index f2640cd..038bb5b 100644
--- a/src/gpm-common.c
+++ b/src/gpm-common.c
@@ -79,87 +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 ||
-	    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_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 gnome-power-manager help section
  **/
diff --git a/src/gpm-common.h b/src/gpm-common.h
index f891037..a86e1f4 100644
--- a/src/gpm-common.h
+++ b/src/gpm-common.h
@@ -175,10 +175,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-engine.c b/src/gpm-engine.c
index fa237fd..1ecd435 100644
--- a/src/gpm-engine.c
+++ b/src/gpm-engine.c
@@ -513,17 +513,13 @@ 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);
 
 	} 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);
@@ -1101,7 +1097,6 @@ phone_device_refresh_cb (GpmPhone *phone, guint idx, GpmEngine *engine)
 static void
 gpm_engine_init (GpmEngine *engine)
 {
-	gchar *icon_policy;
 	guint idle_id;
 
 	engine->priv = GPM_ENGINE_GET_PRIVATE (engine);
@@ -1141,9 +1136,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 858093a..6781ec4 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -687,17 +687,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);
 	} else if (policy == GPM_ACTION_POLICY_SUSPEND) {
@@ -720,10 +717,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;
 }
 
@@ -737,16 +733,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");
@@ -779,7 +773,6 @@ gpm_manager_idle_do_sleep (GpmManager *manager)
 			}
 		}
 	}
-	g_free (action);
 }
 
 /**
@@ -1581,7 +1574,6 @@ gpm_manager_engine_charge_critical_cb (GpmEngine *engine, UpDevice *device, GpmM
 {
 	const gchar *title = NULL;
 	gchar *message = NULL;
-	gchar *action;
 	GIcon *icon = NULL;
 	UpDeviceKind kind;
 	gdouble percentage;
@@ -1617,8 +1609,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) {
@@ -1638,7 +1629,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;
 
@@ -1750,7 +1740,6 @@ static void
 gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmManager *manager)
 {
 	const gchar *title = NULL;
-	gchar *action;
 	gchar *message = NULL;
 	GIcon *icon = NULL;
 	UpDeviceKind kind;
@@ -1776,8 +1765,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) {
@@ -1804,8 +1792,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 */
 		timer_id = g_timeout_add_seconds (20, (GSourceFunc) manager_critical_action_do, manager);
 #if GLIB_CHECK_VERSION(2,25,8)
@@ -1817,8 +1803,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) {
@@ -1843,8 +1828,6 @@ gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmMan
 #if GLIB_CHECK_VERSION(2,25,8)
 		g_source_set_name_by_id (timer_id, "[GpmManager] ups critical-action");
 #endif
-
-		g_free (action);
 	}
 
 	/* not all types have actions */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]