[gnome-power-manager] Use enumerated values for the policy actions, and hide 'Do nothing' unless specified in GConf
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-power-manager] Use enumerated values for the policy actions, and hide 'Do nothing' unless specified in GConf
- Date: Wed, 22 Jul 2009 13:23:15 +0000 (UTC)
commit 8bf6879f00e17d7feb39cecb820ad0ad33e2e827
Author: Richard Hughes <richard hughsie com>
Date: Wed Jul 22 14:22:04 2009 +0100
Use enumerated values for the policy actions, and hide 'Do nothing' unless specified in GConf
data/gnome-power-manager.schemas.in | 2 +-
src/Makefile.am | 1 -
src/gpm-common.c | 77 +++++++++++---
src/gpm-common.h | 15 +++-
src/gpm-engine.c | 4 +-
src/gpm-load.c | 1 -
src/gpm-manager.c | 116 ++++++++++-----------
src/gpm-prefs-core.c | 198 +++++++++++++++--------------------
src/gpm-prefs.c | 1 -
src/gpm-prefs.h | 38 -------
10 files changed, 217 insertions(+), 236 deletions(-)
---
diff --git a/data/gnome-power-manager.schemas.in b/data/gnome-power-manager.schemas.in
index db202ae..e8336bb 100644
--- a/data/gnome-power-manager.schemas.in
+++ b/data/gnome-power-manager.schemas.in
@@ -61,7 +61,7 @@
<key>/schemas/apps/gnome-power-manager/actions/low_ups</key>
<applyto>/apps/gnome-power-manager/actions/low_ups</applyto>
<type>string</type>
- <default>nothing</default>
+ <default>hibernate</default>
<locale name="C">
<short>UPS low power action</short>
<long>The action to take when the UPS is low. Possible values are "hibernate", "suspend", "shutdown" and "nothing".</long>
diff --git a/src/Makefile.am b/src/Makefile.am
index f62afff..1cecd9a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -105,7 +105,6 @@ gnome_power_preferences_SOURCES = \
gpm-session.c \
gpm-load.h \
gpm-load.c \
- gpm-prefs.h \
gpm-prefs.c \
gpm-prefs-core.h \
gpm-prefs-core.c \
diff --git a/src/gpm-common.c b/src/gpm-common.c
index 9ff0dac..b3da7b3 100644
--- a/src/gpm-common.c
+++ b/src/gpm-common.c
@@ -78,46 +78,91 @@ gpm_get_timestring (guint time_secs)
return timestring;
}
+/**
+ * gpm_icon_policy_from_string:
+ **/
GpmIconPolicy
-gpm_tray_icon_mode_from_string (const gchar *str)
+gpm_icon_policy_from_string (const gchar *policy)
{
- if (str == NULL)
+ if (policy == NULL)
return GPM_ICON_POLICY_NEVER;
-
- if (strcmp (str, "always") == 0)
+ if (g_strcmp0 (policy, "always") == 0)
return GPM_ICON_POLICY_ALWAYS;
- if (strcmp (str, "present") == 0)
+ if (g_strcmp0 (policy, "present") == 0)
return GPM_ICON_POLICY_PRESENT;
- if (strcmp (str, "charge") == 0)
+ if (g_strcmp0 (policy, "charge") == 0)
return GPM_ICON_POLICY_CHARGE;
- if (strcmp (str, "low") == 0)
+ if (g_strcmp0 (policy, "low") == 0)
return GPM_ICON_POLICY_LOW;
- if (strcmp (str, "critical") == 0)
+ if (g_strcmp0 (policy, "critical") == 0)
return GPM_ICON_POLICY_CRITICAL;
- if (strcmp (str, "never") == 0)
+ if (g_strcmp0 (policy, "never") == 0)
return GPM_ICON_POLICY_NEVER;
return GPM_ICON_POLICY_NEVER;
}
+/**
+ * gpm_icon_policy_to_string:
+ **/
const gchar *
-gpm_tray_icon_mode_to_string (GpmIconPolicy mode)
+gpm_icon_policy_to_string (GpmIconPolicy policy)
{
- if (mode == GPM_ICON_POLICY_ALWAYS)
+ if (policy == GPM_ICON_POLICY_ALWAYS)
return "always";
- if (mode == GPM_ICON_POLICY_PRESENT)
+ if (policy == GPM_ICON_POLICY_PRESENT)
return "present";
- if (mode == GPM_ICON_POLICY_CHARGE)
+ if (policy == GPM_ICON_POLICY_CHARGE)
return "charge";
- if (mode == GPM_ICON_POLICY_LOW)
+ if (policy == GPM_ICON_POLICY_LOW)
return "low";
- if (mode == GPM_ICON_POLICY_CRITICAL)
+ if (policy == GPM_ICON_POLICY_CRITICAL)
return "critical";
- if (mode == GPM_ICON_POLICY_NEVER)
+ 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 2a0de77..98c8646 100644
--- a/src/gpm-common.h
+++ b/src/gpm-common.h
@@ -179,9 +179,20 @@ typedef enum {
GPM_ICON_POLICY_NEVER
} GpmIconPolicy;
+typedef enum {
+ GPM_ACTION_POLICY_BLANK,
+ GPM_ACTION_POLICY_SUSPEND,
+ GPM_ACTION_POLICY_SHUTDOWN,
+ GPM_ACTION_POLICY_HIBERNATE,
+ GPM_ACTION_POLICY_INTERACTIVE,
+ GPM_ACTION_POLICY_NOTHING
+} GpmActionPolicy;
+
gchar *gpm_get_timestring (guint time);
-GpmIconPolicy gpm_tray_icon_mode_from_string (const gchar *mode);
-const gchar *gpm_tray_icon_mode_to_string (GpmIconPolicy mode);
+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 ef47c67..415b2d4 100644
--- a/src/gpm-engine.c
+++ b/src/gpm-engine.c
@@ -516,7 +516,7 @@ gpm_engine_conf_key_changed_cb (GConfClient *conf, guint cnxn_id, GConfEntry *en
/* do we want to display the icon in the tray */
icon_policy = gconf_client_get_string (conf, GPM_CONF_UI_ICON_POLICY, NULL);
- engine->priv->icon_policy = gpm_tray_icon_mode_from_string (icon_policy);
+ engine->priv->icon_policy = gpm_icon_policy_from_string (icon_policy);
g_free (icon_policy);
/* perhaps change icon */
@@ -1060,7 +1060,7 @@ gpm_engine_init (GpmEngine *engine)
/* do we want to display the icon in the tray */
icon_policy = gconf_client_get_string (engine->priv->conf, GPM_CONF_UI_ICON_POLICY, NULL);
- engine->priv->icon_policy = gpm_tray_icon_mode_from_string (icon_policy);
+ engine->priv->icon_policy = gpm_icon_policy_from_string (icon_policy);
g_free (icon_policy);
/* get percentage policy */
diff --git a/src/gpm-load.c b/src/gpm-load.c
index d5bbd57..f625842 100644
--- a/src/gpm-load.c
+++ b/src/gpm-load.c
@@ -40,7 +40,6 @@
#include <glib/gi18n.h>
#include "gpm-common.h"
-#include "gpm-prefs.h"
#include "gpm-marshal.h"
#include "egg-debug.h"
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index 6030fa0..207184e 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -52,7 +52,6 @@
#include "gpm-dpms.h"
#include "gpm-idle.h"
#include "gpm-manager.h"
-#include "gpm-prefs.h"
#include "gpm-screensaver.h"
#include "gpm-backlight.h"
#include "gpm-screensaver.h"
@@ -484,7 +483,7 @@ gpm_manager_action_hibernate (GpmManager *manager, const gchar *reason)
}
/**
- * manager_policy_do:
+ * gpm_manager_perform_policy:
* @manager: This class instance
* @policy: The policy that we should do, e.g. "suspend"
* @reason: The reason we are performing the policy action, e.g. "battery critical"
@@ -492,35 +491,35 @@ gpm_manager_action_hibernate (GpmManager *manager, const gchar *reason)
* Does one of the policy actions specified in gconf.
**/
static gboolean
-manager_policy_do (GpmManager *manager, const gchar *policy, const gchar *reason)
+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;
- egg_debug ("policy: %s", policy);
- action = gconf_client_get_string (manager->priv->conf, policy, NULL);
- if (action == NULL)
- return FALSE;
+ action = gconf_client_get_string (manager->priv->conf, policy_key, NULL);
+ egg_debug ("action: %s set to %s (%s)", policy_key, action, reason);
+ policy = gpm_action_policy_from_string (action);
- if (strcmp (action, ACTION_NOTHING) == 0) {
+ if (policy == GPM_ACTION_POLICY_NOTHING) {
egg_debug ("doing nothing, reason: %s", reason);
- } else if (strcmp (action, ACTION_SUSPEND) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_SUSPEND) {
gpm_manager_action_suspend (manager, reason);
- } else if (strcmp (action, ACTION_HIBERNATE) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_HIBERNATE) {
gpm_manager_action_hibernate (manager, reason);
- } else if (strcmp (action, ACTION_BLANK) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_BLANK) {
gpm_manager_blank_screen (manager, NULL);
- } else if (strcmp (action, ACTION_SHUTDOWN) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_SHUTDOWN) {
egg_debug ("shutting down, reason: %s", reason);
gpm_control_shutdown (manager->priv->control, NULL);
- } else if (strcmp (action, ACTION_INTERACTIVE) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_INTERACTIVE) {
GpmSession *session;
egg_debug ("logout, reason: %s", reason);
session = gpm_session_new ();
@@ -638,21 +637,18 @@ idle_do_sleep (GpmManager *manager)
gchar *action = NULL;
gboolean ret;
GError *error = NULL;
+ GpmActionPolicy policy;
if (!manager->priv->on_battery)
action = gconf_client_get_string (manager->priv->conf, GPM_CONF_ACTIONS_SLEEP_TYPE_AC, NULL);
else
action = gconf_client_get_string (manager->priv->conf, GPM_CONF_ACTIONS_SLEEP_TYPE_BATT, NULL);
+ policy = gpm_action_policy_from_string (action);
- if (action == NULL) {
- egg_warning ("action NULL, gconf error");
- return;
- }
-
- if (strcmp (action, ACTION_NOTHING) == 0) {
+ if (policy == GPM_ACTION_POLICY_NOTHING) {
egg_debug ("doing nothing as system idle action");
- } else if (strcmp (action, ACTION_SUSPEND) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_SUSPEND) {
egg_debug ("suspending, reason: System idle");
ret = gpm_control_suspend (manager->priv->control, &error);
if (!ret) {
@@ -666,7 +662,7 @@ idle_do_sleep (GpmManager *manager)
}
}
- } else if (strcmp (action, ACTION_HIBERNATE) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_HIBERNATE) {
egg_debug ("hibernating, reason: System idle");
ret = gpm_control_hibernate (manager->priv->control, &error);
if (!ret) {
@@ -744,13 +740,13 @@ lid_button_pressed (GpmManager *manager, gboolean pressed)
if (!manager->priv->on_battery) {
egg_debug ("Performing AC policy");
- manager_policy_do (manager, GPM_CONF_BUTTON_LID_AC,
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_LID_AC,
_("The lid has been closed on ac power."));
return;
}
egg_debug ("Performing battery policy");
- manager_policy_do (manager, GPM_CONF_BUTTON_LID_BATT,
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_LID_BATT,
_("The lid has been closed on battery power."));
}
@@ -830,19 +826,19 @@ button_pressed_cb (GpmButton *button, const gchar *type, GpmManager *manager)
return;
}
- if (strcmp (type, GPM_BUTTON_POWER) == 0)
- manager_policy_do (manager, GPM_CONF_BUTTON_POWER, _("The power button has been pressed."));
- else if (strcmp (type, GPM_BUTTON_SLEEP) == 0)
- manager_policy_do (manager, GPM_CONF_BUTTON_SUSPEND, _("The suspend button has been pressed."));
- else if (strcmp (type, GPM_BUTTON_SUSPEND) == 0)
- manager_policy_do (manager, GPM_CONF_BUTTON_SUSPEND, _("The suspend button has been pressed."));
- else if (strcmp (type, GPM_BUTTON_HIBERNATE) == 0)
- manager_policy_do (manager, GPM_CONF_BUTTON_HIBERNATE, _("The hibernate button has been pressed."));
- else if (strcmp (type, GPM_BUTTON_LID_OPEN) == 0)
+ if (g_strcmp0 (type, GPM_BUTTON_POWER) == 0)
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_POWER, _("The power button has been pressed."));
+ else if (g_strcmp0 (type, GPM_BUTTON_SLEEP) == 0)
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_SUSPEND, _("The suspend button has been pressed."));
+ else if (g_strcmp0 (type, GPM_BUTTON_SUSPEND) == 0)
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_SUSPEND, _("The suspend button has been pressed."));
+ else if (g_strcmp0 (type, GPM_BUTTON_HIBERNATE) == 0)
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_HIBERNATE, _("The hibernate button has been pressed."));
+ else if (g_strcmp0 (type, GPM_BUTTON_LID_OPEN) == 0)
lid_button_pressed (manager, FALSE);
- else if (strcmp (type, GPM_BUTTON_LID_CLOSED) == 0)
+ else if (g_strcmp0 (type, GPM_BUTTON_LID_CLOSED) == 0)
lid_button_pressed (manager, TRUE);
- else if (strcmp (type, GPM_BUTTON_BATTERY) == 0) {
+ else if (g_strcmp0 (type, GPM_BUTTON_BATTERY) == 0) {
message = gpm_engine_get_summary (manager->priv->engine);
gpm_manager_notify (manager, &manager->priv->notification,
_("Power Information"),
@@ -854,13 +850,13 @@ button_pressed_cb (GpmButton *button, const gchar *type, GpmManager *manager)
}
/* really belongs in gnome-manager */
- if (strcmp (type, GPM_BUTTON_LOCK) == 0)
+ if (g_strcmp0 (type, GPM_BUTTON_LOCK) == 0)
gpm_screensaver_lock (manager->priv->screensaver);
/* Disable or enable the fancy manager, as we don't want
* this starting when the lid is shut */
- if (strcmp (type, GPM_BUTTON_LID_CLOSED) == 0)
+ if (g_strcmp0 (type, GPM_BUTTON_LID_CLOSED) == 0)
update_lid_throttle (manager, TRUE);
- else if (strcmp (type, GPM_BUTTON_LID_OPEN) == 0)
+ else if (g_strcmp0 (type, GPM_BUTTON_LID_OPEN) == 0)
update_lid_throttle (manager, FALSE);
}
@@ -947,7 +943,7 @@ gpm_manager_client_changed_cb (DkpClient *client, GpmManager *manager)
lid close on battery action if the ac adapter is removed when the laptop
is closed. Fixes #331655 */
if (event_when_closed && on_battery && gpm_button_is_lid_closed (manager->priv->button)) {
- manager_policy_do (manager, GPM_CONF_BUTTON_LID_BATT,
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_LID_BATT,
_("The lid has been closed, and the ac adapter "
"removed (and gconf is okay)."));
}
@@ -965,7 +961,7 @@ gpm_manager_client_changed_cb (DkpClient *client, GpmManager *manager)
static gboolean
manager_critical_action_do (GpmManager *manager)
{
- manager_policy_do (manager, GPM_CONF_ACTIONS_CRITICAL_BATT, _("Battery is critically low."));
+ gpm_manager_perform_policy (manager, GPM_CONF_ACTIONS_CRITICAL_BATT, _("Battery is critically low."));
return FALSE;
}
@@ -995,10 +991,10 @@ gpm_conf_gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *e
if (value == NULL)
return;
- if (strcmp (entry->key, GPM_CONF_TIMEOUT_SLEEP_COMPUTER_BATT) == 0 ||
- strcmp (entry->key, GPM_CONF_TIMEOUT_SLEEP_COMPUTER_AC) == 0 ||
- strcmp (entry->key, GPM_CONF_TIMEOUT_SLEEP_DISPLAY_BATT) == 0 ||
- strcmp (entry->key, GPM_CONF_TIMEOUT_SLEEP_DISPLAY_AC) == 0)
+ if (g_strcmp0 (entry->key, GPM_CONF_TIMEOUT_SLEEP_COMPUTER_BATT) == 0 ||
+ g_strcmp0 (entry->key, GPM_CONF_TIMEOUT_SLEEP_COMPUTER_AC) == 0 ||
+ g_strcmp0 (entry->key, GPM_CONF_TIMEOUT_SLEEP_DISPLAY_BATT) == 0 ||
+ g_strcmp0 (entry->key, GPM_CONF_TIMEOUT_SLEEP_DISPLAY_AC) == 0)
gpm_manager_sync_policy_sleep (manager);
}
@@ -1433,6 +1429,7 @@ gpm_engine_charge_critical_cb (GpmEngine *engine, DkpDevice *device, GpmManager
DkpDeviceType type;
gdouble percentage;
gint64 time_to_empty;
+ GpmActionPolicy policy;
/* get device properties */
g_object_get (device,
@@ -1456,19 +1453,16 @@ gpm_engine_charge_critical_cb (GpmEngine *engine, DkpDevice *device, GpmManager
/* we have to do different warnings depending on the policy */
action = gconf_client_get_string (manager->priv->conf, GPM_CONF_ACTIONS_CRITICAL_BATT, NULL);
- if (action == NULL) {
- egg_warning ("schema invalid!");
- action = g_strdup (ACTION_NOTHING);
- }
+ policy = gpm_action_policy_from_string (action);
/* use different text for different actions */
- if (strcmp (action, ACTION_NOTHING) == 0)
+ if (policy == GPM_ACTION_POLICY_NOTHING)
action_text = g_strdup (_("Plug in your AC adapter to avoid losing data."));
- else if (strcmp (action, ACTION_SUSPEND) == 0)
+ else if (policy == GPM_ACTION_POLICY_SUSPEND)
action_text = g_strdup_printf (_("This computer will suspend in %s if the AC is not connected."), time_text);
- else if (strcmp (action, ACTION_HIBERNATE) == 0)
+ else if (policy == GPM_ACTION_POLICY_HIBERNATE)
action_text = g_strdup_printf (_("This computer will hibernate in %s if the AC is not connected."), time_text);
- else if (strcmp (action, ACTION_SHUTDOWN) == 0)
+ else if (policy == GPM_ACTION_POLICY_SHUTDOWN)
action_text = g_strdup_printf (_("This computer will shutdown in %s if the AC is not connected."), time_text);
message = g_strdup_printf (_("You have approximately <b>%s</b> of remaining battery life (%.1f%%). %s"),
@@ -1527,6 +1521,7 @@ gpm_engine_charge_action_cb (GpmEngine *engine, DkpDevice *device, GpmManager *m
gchar *message = NULL;
gchar *icon = NULL;
DkpDeviceType type;
+ GpmActionPolicy policy;
/* get device properties */
g_object_get (device,
@@ -1546,24 +1541,25 @@ gpm_engine_charge_action_cb (GpmEngine *engine, DkpDevice *device, GpmManager *m
/* we have to do different warnings depending on the policy */
action = gconf_client_get_string (manager->priv->conf, GPM_CONF_ACTIONS_CRITICAL_BATT, NULL);
+ policy = gpm_action_policy_from_string (action);
/* use different text for different actions */
- if (strcmp (action, ACTION_NOTHING) == 0) {
+ if (policy == GPM_ACTION_POLICY_NOTHING) {
message = g_strdup (_("The battery is below the critical level and "
"this computer will <b>power-off</b> when the "
"battery becomes completely empty."));
- } else if (strcmp (action, ACTION_SUSPEND) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_SUSPEND) {
message = g_strdup (_("The battery is below the critical level and "
"this computer is about to suspend.<br>"
"<b>NOTE:</b> A small amount of power is required "
"to keep your computer in a suspended state."));
- } else if (strcmp (action, ACTION_HIBERNATE) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_HIBERNATE) {
message = g_strdup (_("The battery is below the critical level and "
"this computer is about to hibernate."));
- } else if (strcmp (action, ACTION_SHUTDOWN) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_SHUTDOWN) {
message = g_strdup (_("The battery is below the critical level and "
"this computer is about to shutdown."));
}
@@ -1580,16 +1576,16 @@ gpm_engine_charge_action_cb (GpmEngine *engine, DkpDevice *device, GpmManager *m
action = gconf_client_get_string (manager->priv->conf, GPM_CONF_ACTIONS_CRITICAL_UPS, NULL);
/* use different text for different actions */
- if (strcmp (action, ACTION_NOTHING) == 0) {
+ if (policy == GPM_ACTION_POLICY_NOTHING) {
message = g_strdup (_("The UPS is below the critical level and "
"this computer will <b>power-off</b> when the "
"UPS becomes completely empty."));
- } else if (strcmp (action, ACTION_HIBERNATE) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_HIBERNATE) {
message = g_strdup (_("The UPS is below the critical level and "
"this computer is about to hibernate."));
- } else if (strcmp (action, ACTION_SHUTDOWN) == 0) {
+ } else if (policy == GPM_ACTION_POLICY_SHUTDOWN) {
message = g_strdup (_("The UPS is below the critical level and "
"this computer is about to shutdown."));
}
@@ -1658,13 +1654,13 @@ gpm_manager_console_kit_active_changed_cb (EggConsoleKit *console, gboolean acti
/* get ac state */
if (!manager->priv->on_battery) {
egg_debug ("Performing AC policy as become active when lid down");
- manager_policy_do (manager, GPM_CONF_BUTTON_LID_AC,
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_LID_AC,
_("The lid has been found closed on ac power."));
return;
}
egg_debug ("Performing battery policy as become active when lid down");
- manager_policy_do (manager, GPM_CONF_BUTTON_LID_BATT,
+ gpm_manager_perform_policy (manager, GPM_CONF_BUTTON_LID_BATT,
_("The lid has been found closed on battery power."));
}
diff --git a/src/gpm-prefs-core.c b/src/gpm-prefs-core.c
index 4512466..abe070b 100644
--- a/src/gpm-prefs-core.c
+++ b/src/gpm-prefs-core.c
@@ -2,7 +2,7 @@
*
* Copyright (C) 2005 Jaap Haitsma <jaap haitsma org>
* Copyright (C) 2005 William Jon McCann <mccann jhu edu>
- * Copyright (C) 2005-2007 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2005-2009 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -35,7 +35,6 @@
#include "gpm-tray-icon.h"
#include "gpm-common.h"
-#include "gpm-prefs.h"
#include "gpm-prefs-core.h"
#include "egg-debug.h"
#include "gpm-stock-icons.h"
@@ -71,14 +70,6 @@ static guint signals [LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GpmPrefs, gpm_prefs, G_TYPE_OBJECT)
-/* The text that should appear in the action combo boxes */
-#define ACTION_INTERACTIVE_TEXT _("Ask me")
-#define ACTION_SUSPEND_TEXT _("Suspend")
-#define ACTION_SHUTDOWN_TEXT _("Shutdown")
-#define ACTION_HIBERNATE_TEXT _("Hibernate")
-#define ACTION_BLANK_TEXT _("Blank screen")
-#define ACTION_NOTHING_TEXT _("Do nothing")
-
/**
* gpm_prefs_class_init:
* @klass: This prefs class instance
@@ -187,7 +178,7 @@ gpm_prefs_icon_radio_cb (GtkWidget *widget, GpmPrefs *prefs)
gint policy;
policy = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "policy"));
- str = gpm_tray_icon_mode_to_string (policy);
+ str = gpm_icon_policy_to_string (policy);
egg_debug ("Changing %s to %s", GPM_CONF_UI_ICON_POLICY, str);
gconf_client_set_string (prefs->priv->conf, GPM_CONF_UI_ICON_POLICY, str, NULL);
}
@@ -261,35 +252,18 @@ gpm_prefs_setup_brightness_slider (GpmPrefs *prefs, const gchar *widget_name, co
static void
gpm_prefs_action_combo_changed_cb (GtkWidget *widget, GpmPrefs *prefs)
{
- gchar *value;
- const gchar *action = NULL;
- gchar *gpm_pref_key;
-
- value = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget));
-
- if (strcmp (value, ACTION_SUSPEND_TEXT) == 0) {
- action = ACTION_SUSPEND;
- } else if (strcmp (value, ACTION_HIBERNATE_TEXT) == 0) {
- action = ACTION_HIBERNATE;
- } else if (strcmp (value, ACTION_SHUTDOWN_TEXT) == 0) {
- action = ACTION_SHUTDOWN;
- } else if (strcmp (value, ACTION_BLANK_TEXT) == 0) {
- action = ACTION_BLANK;
- } else if (strcmp (value, ACTION_NOTHING_TEXT) == 0) {
- action = ACTION_NOTHING;
- } else if (strcmp (value, ACTION_INTERACTIVE_TEXT) == 0) {
- action = ACTION_INTERACTIVE;
- }
-
- g_free (value);
+ GpmActionPolicy policy;
+ const GpmActionPolicy *actions;
+ const gchar *gpm_pref_key;
+ const gchar *action;
+ guint active;
- /* nothing matched */
- if (action == NULL) {
- egg_warning ("could not match %s", value);
- return;
- }
+ actions = (const GpmActionPolicy *) g_object_get_data (G_OBJECT (widget), "actions");
+ gpm_pref_key = (const gchar *) g_object_get_data (G_OBJECT (widget), "conf_key");
- gpm_pref_key = (char *) g_object_get_data (G_OBJECT (widget), "conf_key");
+ 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);
gconf_client_set_string (prefs->priv->conf, gpm_pref_key, action, NULL);
}
@@ -344,72 +318,68 @@ gpm_prefs_set_combo_simple_text (GtkWidget *combo_box)
**/
static void
gpm_prefs_setup_action_combo (GpmPrefs *prefs, const gchar *widget_name,
- const gchar *gpm_pref_key, const gchar **actions)
+ const gchar *gpm_pref_key, const GpmActionPolicy *actions)
{
- gchar *value;
- gint i = 0;
+ gchar *value_txt;
+ gint i;
gint n_added = 0;
gboolean is_writable;
GtkWidget *widget;
+ GpmActionPolicy policy;
+ GpmActionPolicy value;
widget = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder, widget_name));
gpm_prefs_set_combo_simple_text (widget);
- value = gconf_client_get_string (prefs->priv->conf, gpm_pref_key, NULL);
+ value_txt = gconf_client_get_string (prefs->priv->conf, gpm_pref_key, NULL);
is_writable = gconf_client_key_is_writable (prefs->priv->conf, gpm_pref_key, NULL);
+ value = gpm_action_policy_from_string (value_txt);
gtk_widget_set_sensitive (widget, is_writable);
g_object_set_data (G_OBJECT (widget), "conf_key", (gpointer) gpm_pref_key);
+ g_object_set_data (G_OBJECT (widget), "actions", (gpointer) actions);
g_signal_connect (G_OBJECT (widget), "changed",
G_CALLBACK (gpm_prefs_action_combo_changed_cb), prefs);
- if (value == NULL) {
- egg_warning ("invalid schema, please re-install");
- value = g_strdup ("nothing");
- }
-
- while (actions[i] != NULL) {
- if ((strcmp (actions[i], ACTION_SHUTDOWN) == 0) && !prefs->priv->can_shutdown) {
+ for (i=0; actions[i] != -1; i++) {
+ policy = actions[i];
+ if (policy == GPM_ACTION_POLICY_SHUTDOWN && !prefs->priv->can_shutdown) {
egg_debug ("Cannot add option, as cannot shutdown.");
- } else if (strcmp (actions[i], ACTION_SHUTDOWN) == 0 && prefs->priv->can_shutdown) {
- gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
- ACTION_SHUTDOWN_TEXT);
+ } else if (policy == GPM_ACTION_POLICY_SHUTDOWN && prefs->priv->can_shutdown) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget), _("Shutdown"));
n_added++;
- } else if ((strcmp (actions[i], ACTION_SUSPEND) == 0) && !prefs->priv->can_suspend) {
+ } else if (policy == GPM_ACTION_POLICY_SUSPEND && !prefs->priv->can_suspend) {
egg_debug ("Cannot add option, as cannot suspend.");
- } else if ((strcmp (actions[i], ACTION_HIBERNATE) == 0) && !prefs->priv->can_hibernate) {
+ } else if (policy == GPM_ACTION_POLICY_HIBERNATE && !prefs->priv->can_hibernate) {
egg_debug ("Cannot add option, as cannot hibernate.");
- } else if ((strcmp (actions[i], ACTION_SUSPEND) == 0) && prefs->priv->can_suspend) {
- gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
- ACTION_SUSPEND_TEXT);
- n_added++;
- } else if ((strcmp (actions[i], ACTION_HIBERNATE) == 0) && prefs->priv->can_hibernate) {
- gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
- ACTION_HIBERNATE_TEXT);
+ } else if (policy == GPM_ACTION_POLICY_SUSPEND && prefs->priv->can_suspend) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget), _("Suspend"));
n_added++;
- } else if (strcmp (actions[i], ACTION_BLANK) == 0) {
- gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
- ACTION_BLANK_TEXT);
+ } else if (policy == GPM_ACTION_POLICY_HIBERNATE && prefs->priv->can_hibernate) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget), _("Hibernate"));
n_added++;
- } else if (strcmp (actions[i], ACTION_INTERACTIVE) == 0) {
- gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
- ACTION_INTERACTIVE_TEXT);
+ } else if (policy == GPM_ACTION_POLICY_BLANK) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget), _("Blank screen"));
n_added++;
- } else if (strcmp (actions[i], ACTION_NOTHING) == 0) {
- gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
- ACTION_NOTHING_TEXT);
+ } else if (policy == GPM_ACTION_POLICY_INTERACTIVE) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget), _("Ask me"));
n_added++;
+ } else if (policy == GPM_ACTION_POLICY_NOTHING) {
+ /* we only add do nothing in the GUI if the user has explicitly specified this in GConf */
+ if (value == GPM_ACTION_POLICY_NOTHING) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget), _("Do nothing"));
+ n_added++;
+ }
} else {
- egg_error ("Unknown action read from conf: %s", actions[i]);
+ egg_warning ("Unknown action read from conf: %i", policy);
}
- if (strcmp (value, actions[i]) == 0)
+ if (value == policy)
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), n_added - 1);
- i++;
}
- g_free (value);
+ g_free (value_txt);
}
/**
@@ -554,18 +524,18 @@ gpm_conf_gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *e
if (value == NULL)
return;
- if (strcmp (entry->key, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC) == 0) {
+ if (g_strcmp0 (entry->key, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC) == 0) {
widget = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder, "hscale_ac_brightness"));
brightness = gconf_value_get_int (value);
gtk_range_set_value (GTK_RANGE (widget), brightness);
}
- if (strcmp (entry->key, GPM_CONF_DISKS_SPINDOWN_ENABLE_AC) == 0) {
+ if (g_strcmp0 (entry->key, GPM_CONF_DISKS_SPINDOWN_ENABLE_AC) == 0) {
widget = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder, "checkbutton_ac_spindown"));
enabled = gconf_value_get_bool (value);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), enabled);
- } else if (strcmp (entry->key, GPM_CONF_DISKS_SPINDOWN_ENABLE_BATT) == 0) {
+ } else if (g_strcmp0 (entry->key, GPM_CONF_DISKS_SPINDOWN_ENABLE_BATT) == 0) {
widget = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder, "checkbutton_battery_spindown"));
enabled = gconf_value_get_bool (value);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), enabled);
@@ -586,7 +556,7 @@ prefs_setup_notification (GpmPrefs *prefs)
gboolean is_writable;
icon_policy_str = gconf_client_get_string (prefs->priv->conf, GPM_CONF_UI_ICON_POLICY, NULL);
- icon_policy = gpm_tray_icon_mode_from_string (icon_policy_str);
+ icon_policy = gpm_icon_policy_from_string (icon_policy_str);
g_free (icon_policy_str);
radiobutton_icon_always = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder,
@@ -661,13 +631,13 @@ static void
prefs_setup_ac (GpmPrefs *prefs)
{
GtkWidget *widget;
- const gchar *button_lid_actions[] =
- {ACTION_NOTHING,
- ACTION_BLANK,
- ACTION_SUSPEND,
- ACTION_HIBERNATE,
- ACTION_SHUTDOWN,
- NULL};
+ static 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,
@@ -723,19 +693,19 @@ prefs_setup_battery (GpmPrefs *prefs)
GtkNotebook *notebook;
gint page;
- const gchar *button_lid_actions[] =
- {ACTION_NOTHING,
- ACTION_BLANK,
- ACTION_SUSPEND,
- ACTION_HIBERNATE,
- ACTION_SHUTDOWN,
- NULL};
- const gchar *battery_critical_actions[] =
- {ACTION_NOTHING,
- ACTION_SUSPEND,
- ACTION_HIBERNATE,
- ACTION_SHUTDOWN,
- NULL};
+ static 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 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,
@@ -800,11 +770,11 @@ prefs_setup_ups (GpmPrefs *prefs)
GtkNotebook *notebook;
gint page;
- const gchar *ups_low_actions[] =
- {ACTION_NOTHING,
- ACTION_HIBERNATE,
- ACTION_SHUTDOWN,
- NULL};
+ static 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,
@@ -849,17 +819,17 @@ static void
prefs_setup_general (GpmPrefs *prefs)
{
GtkWidget *widget;
- const gchar *power_button_actions[] =
- {ACTION_INTERACTIVE,
- ACTION_SUSPEND,
- ACTION_HIBERNATE,
- ACTION_SHUTDOWN,
- NULL};
- const gchar *suspend_button_actions[] =
- {ACTION_NOTHING,
- ACTION_SUSPEND,
- ACTION_HIBERNATE,
- NULL};
+ static const GpmActionPolicy power_button_actions[] =
+ {GPM_ACTION_POLICY_INTERACTIVE,
+ GPM_ACTION_POLICY_SUSPEND,
+ GPM_ACTION_POLICY_HIBERNATE,
+ GPM_ACTION_POLICY_SHUTDOWN,
+ -1};
+ static 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_CONF_BUTTON_POWER,
diff --git a/src/gpm-prefs.c b/src/gpm-prefs.c
index 46a2f0a..a057295 100644
--- a/src/gpm-prefs.c
+++ b/src/gpm-prefs.c
@@ -34,7 +34,6 @@
#include <egg-unique.h>
#include "gpm-common.h"
-#include "gpm-prefs.h"
#include "egg-debug.h"
#include "gpm-prefs-core.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]