[gnome-power-manager] Add policy to show icon when low, rather than critically low. Fixes #589125
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-power-manager] Add policy to show icon when low, rather than critically low. Fixes #589125
- Date: Mon, 20 Jul 2009 15:04:41 +0000 (UTC)
commit 16627b5651898940f280913c29e71e50c3931675
Author: Richard Hughes <richard hughsie com>
Date: Mon Jul 20 16:02:48 2009 +0100
Add policy to show icon when low, rather than critically low. Fixes #589125
data/gnome-power-manager.schemas.in | 2 +-
data/gpm-prefs.ui | 4 ++--
src/gpm-common.c | 35 +++++++++++++++++------------------
src/gpm-common.h | 1 +
src/gpm-engine.c | 28 ++++++++++++++++++++++++----
src/gpm-prefs-core.c | 20 ++++++++++----------
6 files changed, 55 insertions(+), 35 deletions(-)
---
diff --git a/data/gnome-power-manager.schemas.in b/data/gnome-power-manager.schemas.in
index f464f40..486ae0a 100644
--- a/data/gnome-power-manager.schemas.in
+++ b/data/gnome-power-manager.schemas.in
@@ -793,7 +793,7 @@
<default>present</default>
<locale name="C">
<short>When to show the notification icon</short>
- <long>Display options for the notification icon. Valid options are "never", "critical", "charge", "present" and "always".</long>
+ <long>Display options for the notification icon. Valid options are "never", "low", "critical", "charge", "present" and "always".</long>
</locale>
</schema>
diff --git a/data/gpm-prefs.ui b/data/gpm-prefs.ui
index ecab266..7a70903 100644
--- a/data/gpm-prefs.ui
+++ b/data/gpm-prefs.ui
@@ -946,8 +946,8 @@
</packing>
</child>
<child>
- <object class="GtkRadioButton" id="radiobutton_notification_critical">
- <property name="label" translatable="yes">_Only display an icon when battery power is critically low</property>
+ <object class="GtkRadioButton" id="radiobutton_notification_low">
+ <property name="label" translatable="yes">_Only display an icon when battery power is low</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
diff --git a/src/gpm-common.c b/src/gpm-common.c
index 7d613be..9ff0dac 100644
--- a/src/gpm-common.c
+++ b/src/gpm-common.c
@@ -81,41 +81,40 @@ gpm_get_timestring (guint time_secs)
GpmIconPolicy
gpm_tray_icon_mode_from_string (const gchar *str)
{
- if (str == NULL) {
+ if (str == NULL)
return GPM_ICON_POLICY_NEVER;
- }
- if (strcmp (str, "always") == 0) {
+ if (strcmp (str, "always") == 0)
return GPM_ICON_POLICY_ALWAYS;
- } else if (strcmp (str, "present") == 0) {
+ if (strcmp (str, "present") == 0)
return GPM_ICON_POLICY_PRESENT;
- } else if (strcmp (str, "charge") == 0) {
+ if (strcmp (str, "charge") == 0)
return GPM_ICON_POLICY_CHARGE;
- } else if (strcmp (str, "critical") == 0) {
+ if (strcmp (str, "low") == 0)
+ return GPM_ICON_POLICY_LOW;
+ if (strcmp (str, "critical") == 0)
return GPM_ICON_POLICY_CRITICAL;
- } else if (strcmp (str, "never") == 0) {
- return GPM_ICON_POLICY_NEVER;
- } else {
+ if (strcmp (str, "never") == 0)
return GPM_ICON_POLICY_NEVER;
- }
+ return GPM_ICON_POLICY_NEVER;
}
const gchar *
gpm_tray_icon_mode_to_string (GpmIconPolicy mode)
{
- if (mode == GPM_ICON_POLICY_ALWAYS) {
+ if (mode == GPM_ICON_POLICY_ALWAYS)
return "always";
- } else if (mode == GPM_ICON_POLICY_PRESENT) {
+ if (mode == GPM_ICON_POLICY_PRESENT)
return "present";
- } else if (mode == GPM_ICON_POLICY_CHARGE) {
+ if (mode == GPM_ICON_POLICY_CHARGE)
return "charge";
- } else if (mode == GPM_ICON_POLICY_CRITICAL) {
+ if (mode == GPM_ICON_POLICY_LOW)
+ return "low";
+ if (mode == GPM_ICON_POLICY_CRITICAL)
return "critical";
- } else if (mode == GPM_ICON_POLICY_NEVER) {
+ if (mode == GPM_ICON_POLICY_NEVER)
return "never";
- } else {
- return "never";
- }
+ return "never";
}
/**
diff --git a/src/gpm-common.h b/src/gpm-common.h
index 0c5567e..2a0de77 100644
--- a/src/gpm-common.h
+++ b/src/gpm-common.h
@@ -174,6 +174,7 @@ typedef enum {
GPM_ICON_POLICY_ALWAYS,
GPM_ICON_POLICY_PRESENT,
GPM_ICON_POLICY_CHARGE,
+ GPM_ICON_POLICY_LOW,
GPM_ICON_POLICY_CRITICAL,
GPM_ICON_POLICY_NEVER
} GpmIconPolicy;
diff --git a/src/gpm-engine.c b/src/gpm-engine.c
index adc3d6e..ef47c67 100644
--- a/src/gpm-engine.c
+++ b/src/gpm-engine.c
@@ -130,9 +130,9 @@ gpm_engine_get_warning_percentage (GpmEngine *engine, DkpDevice *device)
}
if (percentage <= engine->priv->action_percentage)
return GPM_ENGINE_WARNING_ACTION;
- else if (percentage <= engine->priv->critical_percentage)
+ if (percentage <= engine->priv->critical_percentage)
return GPM_ENGINE_WARNING_CRITICAL;
- else if (percentage <= engine->priv->low_percentage)
+ if (percentage <= engine->priv->low_percentage)
return GPM_ENGINE_WARNING_LOW;
return GPM_ENGINE_WARNING_NONE;
}
@@ -160,9 +160,9 @@ gpm_engine_get_warning_time (GpmEngine *engine, DkpDevice *device)
if (time_to_empty <= engine->priv->action_time)
return GPM_ENGINE_WARNING_ACTION;
- else if (time_to_empty <= engine->priv->critical_time)
+ if (time_to_empty <= engine->priv->critical_time)
return GPM_ENGINE_WARNING_CRITICAL;
- else if (time_to_empty <= engine->priv->low_time)
+ if (time_to_empty <= engine->priv->low_time)
return GPM_ENGINE_WARNING_LOW;
return GPM_ENGINE_WARNING_NONE;
}
@@ -348,6 +348,26 @@ gpm_engine_get_icon (GpmEngine *engine)
return NULL;
}
+ /* we try CRITICAL: BATTERY, UPS, MOUSE, KEYBOARD */
+ icon = gpm_engine_get_icon_priv (engine, DKP_DEVICE_TYPE_BATTERY, GPM_ENGINE_WARNING_LOW, FALSE);
+ if (icon != NULL)
+ return icon;
+ icon = gpm_engine_get_icon_priv (engine, DKP_DEVICE_TYPE_UPS, GPM_ENGINE_WARNING_LOW, FALSE);
+ if (icon != NULL)
+ return icon;
+ icon = gpm_engine_get_icon_priv (engine, DKP_DEVICE_TYPE_MOUSE, GPM_ENGINE_WARNING_LOW, FALSE);
+ if (icon != NULL)
+ return icon;
+ icon = gpm_engine_get_icon_priv (engine, DKP_DEVICE_TYPE_KEYBOARD, GPM_ENGINE_WARNING_LOW, FALSE);
+ if (icon != NULL)
+ return icon;
+
+ /* policy */
+ if (engine->priv->icon_policy == GPM_ICON_POLICY_LOW) {
+ egg_debug ("no devices low, so no icon will be displayed.");
+ return NULL;
+ }
+
/* we try (DIS)CHARGING: BATTERY, UPS */
icon = gpm_engine_get_icon_priv (engine, DKP_DEVICE_TYPE_BATTERY, GPM_ENGINE_WARNING_NONE, TRUE);
if (icon != NULL)
diff --git a/src/gpm-prefs-core.c b/src/gpm-prefs-core.c
index c8f4067..4512466 100644
--- a/src/gpm-prefs-core.c
+++ b/src/gpm-prefs-core.c
@@ -581,7 +581,7 @@ prefs_setup_notification (GpmPrefs *prefs)
GtkWidget *radiobutton_icon_always;
GtkWidget *radiobutton_icon_present;
GtkWidget *radiobutton_icon_charge;
- GtkWidget *radiobutton_icon_critical;
+ GtkWidget *radiobutton_icon_low;
GtkWidget *radiobutton_icon_never;
gboolean is_writable;
@@ -595,8 +595,8 @@ prefs_setup_notification (GpmPrefs *prefs)
"radiobutton_notification_present"));
radiobutton_icon_charge = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder,
"radiobutton_notification_charge"));
- radiobutton_icon_critical = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder,
- "radiobutton_notification_critical"));
+ radiobutton_icon_low = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder,
+ "radiobutton_notification_low"));
radiobutton_icon_never = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder,
"radiobutton_notification_never"));
@@ -604,7 +604,7 @@ prefs_setup_notification (GpmPrefs *prefs)
gtk_widget_set_sensitive (radiobutton_icon_always, is_writable);
gtk_widget_set_sensitive (radiobutton_icon_present, is_writable);
gtk_widget_set_sensitive (radiobutton_icon_charge, is_writable);
- gtk_widget_set_sensitive (radiobutton_icon_critical, is_writable);
+ gtk_widget_set_sensitive (radiobutton_icon_low, is_writable);
gtk_widget_set_sensitive (radiobutton_icon_never, is_writable);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_always),
@@ -613,8 +613,8 @@ prefs_setup_notification (GpmPrefs *prefs)
icon_policy == GPM_ICON_POLICY_PRESENT);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_charge),
icon_policy == GPM_ICON_POLICY_CHARGE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_critical),
- icon_policy == GPM_ICON_POLICY_CRITICAL);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_low),
+ icon_policy == GPM_ICON_POLICY_LOW);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_icon_never),
icon_policy == GPM_ICON_POLICY_NEVER);
@@ -624,8 +624,8 @@ prefs_setup_notification (GpmPrefs *prefs)
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_critical), "policy",
- GINT_TO_POINTER (GPM_ICON_POLICY_CRITICAL));
+ 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));
@@ -637,7 +637,7 @@ prefs_setup_notification (GpmPrefs *prefs)
G_CALLBACK (gpm_prefs_icon_radio_cb), prefs);
g_signal_connect (radiobutton_icon_charge, "clicked",
G_CALLBACK (gpm_prefs_icon_radio_cb), prefs);
- g_signal_connect (radiobutton_icon_critical, "clicked",
+ g_signal_connect (radiobutton_icon_low, "clicked",
G_CALLBACK (gpm_prefs_icon_radio_cb), prefs);
g_signal_connect (radiobutton_icon_never, "clicked",
G_CALLBACK (gpm_prefs_icon_radio_cb), prefs);
@@ -649,7 +649,7 @@ prefs_setup_notification (GpmPrefs *prefs)
if (prefs->priv->has_batteries == FALSE) {
/* Hide battery radio options if we have no batteries */
gtk_widget_hide_all (radiobutton_icon_charge);
- gtk_widget_hide_all (radiobutton_icon_critical);
+ gtk_widget_hide_all (radiobutton_icon_low);
}
if (prefs->priv->has_batteries == FALSE && prefs->priv->has_ups == FALSE) {
/* Hide battery present option if no ups or primary */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]