gnome-power-manager r3030 - in trunk: . src



Author: rhughes
Date: Wed Oct 22 10:04:19 2008
New Revision: 3030
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=3030&view=rev

Log:
2008-10-22  Richard Hughes  <richard hughsie com>

* src/Makefile.am:
* src/gpm-brightness-kbd.c: (gpm_brightness_kbd_set_dim),
(gpm_brightness_kbd_set_std), (gpm_brightness_kbd_dim),
(gpm_brightness_kbd_undim), (gpm_brightness_kbd_get),
(gpm_brightness_kbd_up), (gpm_brightness_kbd_down),
(gpm_brightness_kbd_class_init), (gpm_brightness_kbd_toggle),
(gpm_brightness_kbd_init), (gpm_brightness_kbd_new):
* src/gpm-brightness-kbd.h:
* src/gpm-manager.c: (idle_changed_cb), (button_pressed_cb),
(ac_adapter_changed_cb), (gpm_conf_gconf_key_changed_cb),
(brightness_kbd_changed_cb), (gpm_manager_init),
(gpm_manager_finalize):
* src/gpm-srv-brightness-kbd.c:
* src/gpm-srv-brightness-kbd.h:
* src/gpm-warnings.c: (gpm_warnings_get_state_percentage),
(gpm_warnings_get_state), (gconf_key_changed_cb),
(gpm_warnings_init):
Remove the state setting parts of GpmBrightnessKbd into GpmManager.


Removed:
   trunk/src/gpm-srv-brightness-kbd.c
   trunk/src/gpm-srv-brightness-kbd.h
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/gpm-brightness-kbd.c
   trunk/src/gpm-brightness-kbd.h
   trunk/src/gpm-manager.c
   trunk/src/gpm-warnings.c

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Wed Oct 22 10:04:19 2008
@@ -163,8 +163,6 @@
 	gpm-backlight.c					\
 	gpm-prefs-server.h				\
 	gpm-prefs-server.c				\
-	gpm-srv-brightness-kbd.h			\
-	gpm-srv-brightness-kbd.c			\
 	gpm-srv-screensaver.h				\
 	gpm-srv-screensaver.c				\
 	gpm-idle.h					\

Modified: trunk/src/gpm-brightness-kbd.c
==============================================================================
--- trunk/src/gpm-brightness-kbd.c	(original)
+++ trunk/src/gpm-brightness-kbd.c	Wed Oct 22 10:04:19 2008
@@ -42,8 +42,8 @@
 
 #include <hal-device.h>
 #include <hal-manager.h>
-#include "egg-dbus-proxy.h"
 
+#include "egg-dbus-proxy.h"
 #include "egg-debug.h"
 #include "egg-discrete.h"
 
@@ -58,6 +58,7 @@
 
 struct GpmBrightnessKbdPrivate
 {
+	gboolean		 has_hw;
 	gboolean		 does_own_updates;	/* keys are hardwired */
 	gboolean		 does_own_dimming;	/* hardware auto-fades */
 	gboolean		 is_dimmed;
@@ -67,7 +68,7 @@
 	guint			 level_std_hw;
 	guint			 levels;
 	gchar			*udi;
-	GConfClient			*conf;
+	GConfClient		*conf;
 	GpmLightSensor		*sensor;
 	EggDbusProxy		*gproxy;
 };
@@ -285,6 +286,11 @@
 	g_return_val_if_fail (brightness != NULL, FALSE);
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
 
+	if (!brightness->priv->has_hw) {
+		egg_debug ("no hardware");
+		return FALSE;
+	}
+
 	level_hw = egg_discrete_from_percent (brightness_level, brightness->priv->levels);
 
 	/* If the current brightness_kbd is less than the dim brightness_kbd then just
@@ -318,6 +324,11 @@
 	g_return_val_if_fail (brightness != NULL, FALSE);
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
 
+	if (!brightness->priv->has_hw) {
+		egg_debug ("no hardware");
+		return FALSE;
+	}
+
 	level_hw = egg_discrete_from_percent (brightness_level,
 						 brightness->priv->levels);
 	brightness->priv->level_std_hw = level_hw;
@@ -341,6 +352,11 @@
 	g_return_val_if_fail (brightness != NULL, FALSE);
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
 
+	if (!brightness->priv->has_hw) {
+		egg_debug ("no hardware");
+		return FALSE;
+	}
+
 	/* check to see if we are already dimmed */
 	if (brightness->priv->is_dimmed) {
 		egg_warning ("already dim'ed");
@@ -363,6 +379,11 @@
 	g_return_val_if_fail (brightness != NULL, FALSE);
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
 
+	if (!brightness->priv->has_hw) {
+		egg_debug ("no hardware");
+		return FALSE;
+	}
+
 	/* check to see if we are already dimmed */
 	if (brightness->priv->is_dimmed == FALSE) {
 		egg_warning ("already undim'ed");
@@ -387,6 +408,11 @@
 {
 	guint percentage;
 
+	if (!brightness->priv->has_hw) {
+		egg_debug ("no hardware");
+		return FALSE;
+	}
+
 	g_return_val_if_fail (brightness != NULL, FALSE);
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
 
@@ -411,6 +437,11 @@
 	g_return_val_if_fail (brightness != NULL, FALSE);
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
 
+	if (!brightness->priv->has_hw) {
+		egg_debug ("no hardware");
+		return FALSE;
+	}
+
 	/* Do we find the new value, or set the new value */
 	if (brightness->priv->does_own_updates) {
 		gpm_brightness_kbd_get_hw (brightness, &brightness->priv->current_hw);
@@ -447,6 +478,11 @@
 	g_return_val_if_fail (brightness != NULL, FALSE);
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
 
+	if (!brightness->priv->has_hw) {
+		egg_debug ("no hardware");
+		return FALSE;
+	}
+
 	/* Do we find the new value, or set the new value */
 	if (brightness->priv->does_own_updates) {
 		gpm_brightness_kbd_get_hw (brightness, &brightness->priv->current_hw);
@@ -497,19 +533,16 @@
 gpm_brightness_kbd_class_init (GpmBrightnessKbdClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
-	object_class->finalize	   = gpm_brightness_kbd_finalize;
+	object_class->finalize = gpm_brightness_kbd_finalize;
 
 	signals [BRIGHTNESS_CHANGED] =
 		g_signal_new ("brightness-changed",
 			      G_TYPE_FROM_CLASS (object_class),
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (GpmBrightnessKbdClass, brightness_changed),
-			      NULL,
-			      NULL,
+			      NULL, NULL,
 			      g_cclosure_marshal_VOID__UINT,
-			      G_TYPE_NONE,
-			      1,
-			      G_TYPE_UINT);
+			      G_TYPE_NONE, 1, G_TYPE_UINT);
 
 	g_type_class_add_private (klass, sizeof (GpmBrightnessKbdPrivate));
 }
@@ -644,6 +677,11 @@
 	g_return_val_if_fail (brightness != NULL, FALSE);
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
 
+	if (!brightness->priv->has_hw) {
+		egg_debug ("no hardware");
+		return FALSE;
+	}
+
 	if (brightness->priv->is_disabled == FALSE) {
 		/* go dark, that's what the user wants */
 		gpm_brightness_kbd_set_std (brightness, 0);
@@ -675,29 +713,29 @@
 
 	brightness->priv = GPM_BRIGHTNESS_KBD_GET_PRIVATE (brightness);
 
-	/* listen for ambient light changes.. if we have an ambient light sensor */
-	brightness->priv->sensor = gpm_light_sensor_new ();
-	if (brightness->priv->sensor != NULL) {
-		g_signal_connect (brightness->priv->sensor, "brightness-changed",
-				  G_CALLBACK (sensor_changed_cb), brightness);
-	}
+	manager = hal_manager_new ();
 
 	/* save udi of kbd adapter */
-	manager = hal_manager_new ();
 	hal_manager_find_capability (manager, "keyboard_backlight", &names, NULL);
-	g_object_unref (manager);
 	if (names == NULL || names[0] == NULL) {
 		egg_warning ("No devices of capability keyboard_backlight");
-		return;
+		brightness->priv->has_hw = FALSE;
+		goto out;
+	}
+
+	/* listen for ambient light changes.. if we have an ambient light sensor */
+	brightness->priv->sensor = gpm_light_sensor_new ();
+	if (brightness->priv->sensor != NULL) {
+		g_signal_connect (brightness->priv->sensor, "brightness-changed",
+				  G_CALLBACK (sensor_changed_cb), brightness);
 	}
 
 	/* We only want first keyboard_backlight object (should only be one) */
 	brightness->priv->udi = g_strdup (names[0]);
-	hal_manager_free_capability (names);
-
 	brightness->priv->does_own_dimming = FALSE;
 	brightness->priv->does_own_updates = FALSE;
 	brightness->priv->is_disabled = FALSE;
+	brightness->priv->has_hw = TRUE;
 
 	/* get a managed proxy */
 	brightness->priv->gproxy = egg_dbus_proxy_new ();
@@ -725,33 +763,9 @@
 
 	/* choose a start value */
 	adjust_kbd_brightness_according_to_ambient_light (brightness, TRUE);
-}
-
-/**
- * gpm_brightness_kbd_has_hw:
- *
- * Self contained function that works out if we have the hardware.
- * If not, we return FALSE and the module is unloaded.
- **/
-gboolean
-gpm_brightness_kbd_has_hw (void)
-{
-	HalManager *manager;
-	gchar **names;
-	gboolean ret = TRUE;
-
-	/* okay, as singleton - so we don't allocate more memory */
-	manager = hal_manager_new ();
-	hal_manager_find_capability (manager, "keyboard_backlight", &names, NULL);
-	g_object_unref (manager);
-
-	/* nothing found */
-	if (names == NULL || names[0] == NULL) {
-		ret = FALSE;
-	}
-
+out:
 	hal_manager_free_capability (names);
-	return ret;
+	g_object_unref (manager);
 }
 
 /**
@@ -762,12 +776,6 @@
 gpm_brightness_kbd_new (void)
 {
 	GpmBrightnessKbd *brightness;
-
-	/* only load an instance of this module if we have the hardware */
-	if (gpm_brightness_kbd_has_hw () == FALSE) {
-		return NULL;
-	}
-
 	brightness = g_object_new (GPM_TYPE_BRIGHTNESS_KBD, NULL);
 	return GPM_BRIGHTNESS_KBD (brightness);
 }

Modified: trunk/src/gpm-brightness-kbd.h
==============================================================================
--- trunk/src/gpm-brightness-kbd.h	(original)
+++ trunk/src/gpm-brightness-kbd.h	Wed Oct 22 10:04:19 2008
@@ -52,7 +52,6 @@
 
 GType		 gpm_brightness_kbd_get_type	(void);
 GpmBrightnessKbd *gpm_brightness_kbd_new	(void);
-gboolean	 gpm_brightness_kbd_has_hw	(void);
 
 gboolean	 gpm_brightness_kbd_up		(GpmBrightnessKbd	*brightness);
 gboolean	 gpm_brightness_kbd_down	(GpmBrightnessKbd	*brightness);

Modified: trunk/src/gpm-manager.c
==============================================================================
--- trunk/src/gpm-manager.c	(original)
+++ trunk/src/gpm-manager.c	Wed Oct 22 10:04:19 2008
@@ -59,12 +59,13 @@
 #include "gpm-prefs.h"
 #include "gpm-screensaver.h"
 #include "gpm-backlight.h"
-#include "gpm-srv-brightness-kbd.h"
+#include "gpm-brightness-kbd.h"
 #include "gpm-srv-screensaver.h"
 #include "gpm-stock-icons.h"
 #include "gpm-prefs-server.h"
 #include "gpm-tray-icon.h"
 #include "gpm-engine.h"
+#include "gpm-feedback-widget.h"
 
 #include "dbus/xdg-power-management-stats.h"
 #include "dbus/xdg-power-management-inhibit.h"
@@ -94,10 +95,11 @@
 	GpmEngine		*engine;
 	HalDevicePower		*hal_device_power;
 	gboolean		 low_power;
+	GpmBrightnessKbd	*brightness_kbd;
+	GpmFeedback		*feedback_kbd;
 
 	/* interactive services */
 	GpmBacklight		*backlight;
-	GpmSrvBrightnessKbd	*srv_brightness_kbd;
 	GpmSrvScreensaver 	*srv_screensaver;
 };
 
@@ -874,16 +876,13 @@
 	}
 
 	if (mode == GPM_IDLE_MODE_NORMAL) {
-
 		egg_debug ("Idle state changed: NORMAL");
-
+		gpm_brightness_kbd_undim (manager->priv->brightness_kbd);
 	} else if (mode == GPM_IDLE_MODE_SESSION) {
-
 		egg_debug ("Idle state changed: SESSION");
-
+		gpm_brightness_kbd_dim (manager->priv->brightness_kbd);
 	} else if (mode == GPM_IDLE_MODE_SYSTEM) {
 		egg_debug ("Idle state changed: SYSTEM");
-
 		if (gpm_manager_is_inhibit_valid (manager, FALSE, "timeout action") == FALSE)
 			return;
 		idle_do_sleep (manager);
@@ -1043,6 +1042,13 @@
 		lid_button_pressed (manager, TRUE);
 	else if (strcmp (type, GPM_BUTTON_BATTERY) == 0)
 		battery_button_pressed (manager);
+
+	if ((strcmp (type, GPM_BUTTON_KBD_BRIGHT_UP) == 0))
+		gpm_brightness_kbd_up (manager->priv->brightness_kbd);
+	else if ((strcmp (type, GPM_BUTTON_KBD_BRIGHT_DOWN) == 0))
+		gpm_brightness_kbd_down (manager->priv->brightness_kbd);
+	else if (strcmp (type, GPM_BUTTON_KBD_BRIGHT_TOGGLE) == 0)
+		gpm_brightness_kbd_toggle (manager->priv->brightness_kbd);
 }
 
 /**
@@ -1058,6 +1064,7 @@
 {
 	gboolean event_when_closed;
 	gboolean power_save;
+	guint brightness;
 
 	egg_debug ("Setting on-ac: %d", on_ac);
 
@@ -1066,6 +1073,12 @@
 	else
 		gpm_info_event_log (manager->priv->info, GPM_EVENT_ON_BATTERY, _("AC adapter removed"));
 
+	if (on_ac)
+		brightness = gconf_client_get_int (manager->priv->conf, GPM_CONF_KEYBOARD_BRIGHTNESS_AC, NULL);
+	else
+		brightness = gconf_client_get_int (manager->priv->conf, GPM_CONF_KEYBOARD_BRIGHTNESS_BATT, NULL);
+	gpm_brightness_kbd_set_std (manager->priv->brightness_kbd, brightness);
+
 	gpm_manager_sync_policy_sleep (manager);
 
 	if (on_ac)
@@ -1183,6 +1196,8 @@
 gpm_conf_gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, GpmManager *manager)
 {
 	GConfValue *value;
+	gint brightness;
+	gboolean on_ac;
 
 	value = gconf_entry_get_value (entry);
 	if (value == NULL)
@@ -1191,6 +1206,22 @@
 	if (strcmp (entry->key, GPM_CONF_TIMEOUT_SLEEP_COMPUTER_BATT) == 0 ||
 	    strcmp (entry->key, GPM_CONF_TIMEOUT_SLEEP_COMPUTER_AC) == 0)
 		gpm_manager_sync_policy_sleep (manager);
+
+	/* set keyboard brightness */
+	on_ac = gpm_ac_adapter_is_present (manager->priv->ac_adapter);
+	if (strcmp (entry->key, GPM_CONF_KEYBOARD_BRIGHTNESS_AC) == 0) {
+
+		brightness = gconf_value_get_int (value);
+		if (on_ac)
+			gpm_brightness_kbd_set_std (manager->priv->brightness_kbd, brightness);
+
+	} else if (strcmp (entry->key, GPM_CONF_KEYBOARD_BRIGHTNESS_BATT) == 0) {
+
+		brightness = gconf_client_get_int (manager->priv->conf, GPM_CONF_KEYBOARD_BRIGHTNESS_AC, NULL);
+		if (on_ac == FALSE)
+			gpm_brightness_kbd_set_std (manager->priv->brightness_kbd, brightness);
+
+	}
 }
 
 /**
@@ -1696,6 +1727,21 @@
 }
 
 /**
+ * brightness_kbd_changed_cb:
+ * @brightness: The GpmBrightnessKbd class instance
+ * @percentage: The new percentage brightness
+ * @brightness: This class instance
+ *
+ * This callback is called when the brightness value changes.
+ **/
+static void
+brightness_kbd_changed_cb (GpmBrightnessKbd *brightness, gint percentage, GpmManager *manager)
+{
+	egg_debug ("Need to display backlight feedback value %i", percentage);
+	gpm_feedback_display_value (manager->priv->feedback_kbd, (float) percentage / 100.0f);
+}
+
+/**
  * gpm_manager_init:
  * @manager: This class instance
  **/
@@ -1775,7 +1821,13 @@
 						     G_OBJECT (manager->priv->backlight));
 	}
 
-	manager->priv->srv_brightness_kbd = gpm_srv_brightness_kbd_new ();
+	/* use a visual widget */
+	manager->priv->feedback_kbd = gpm_feedback_new ();
+	gpm_feedback_set_icon_name (manager->priv->feedback_kbd, GPM_STOCK_BRIGHTNESS_KBD);
+
+	manager->priv->brightness_kbd = gpm_brightness_kbd_new ();
+	g_signal_connect (manager->priv->brightness_kbd, "brightness-changed",
+			  G_CALLBACK (brightness_kbd_changed_cb), manager);
 
 	manager->priv->idle = gpm_idle_new ();
 	g_signal_connect (manager->priv->idle, "idle-changed",
@@ -1884,14 +1936,13 @@
 	g_object_unref (manager->priv->srv_screensaver);
 	g_object_unref (manager->priv->prefs_server);
 	g_object_unref (manager->priv->control);
+	g_object_unref (manager->priv->feedback_kbd);
+	g_object_unref (manager->priv->button);
+	g_object_unref (manager->priv->brightness_kbd);
 
 	/* optional gobjects */
-	if (manager->priv->button)
-		g_object_unref (manager->priv->button);
 	if (manager->priv->backlight)
 		g_object_unref (manager->priv->backlight);
-	if (manager->priv->srv_brightness_kbd)
-		g_object_unref (manager->priv->srv_brightness_kbd);
 
 	G_OBJECT_CLASS (gpm_manager_parent_class)->finalize (object);
 }

Modified: trunk/src/gpm-warnings.c
==============================================================================
--- trunk/src/gpm-warnings.c	(original)
+++ trunk/src/gpm-warnings.c	Wed Oct 22 10:04:19 2008
@@ -112,8 +112,7 @@
 }
 
 static GpmWarningsState
-gpm_warnings_get_state_percentage (GpmWarnings  *warnings,
-		                  GpmCellUnit *unit)
+gpm_warnings_get_state_percentage (GpmWarnings *warnings, GpmCellUnit *unit)
 {
 	if (unit->percentage == 0) {
 		/* this is probably an error condition */
@@ -142,8 +141,7 @@
  * Return value: A GpmWarnings state, e.g. GPM_WARNINGS_VERY_LOW
  **/
 GpmWarningsState
-gpm_warnings_get_state (GpmWarnings  *warnings,
-		       GpmCellUnit *unit)
+gpm_warnings_get_state (GpmWarnings  *warnings, GpmCellUnit *unit)
 {
 	GpmWarningsState type;
 
@@ -202,19 +200,20 @@
 
 /**
  * gconf_key_changed_cb:
+ *
+ * We might have to do things when the gconf keys change; do them here.
  **/
 static void
-gconf_key_changed_cb (GConfClient     *conf,
-		      const gchar *key,
-		      GpmWarnings  *warnings)
-{
-	g_return_if_fail (GPM_IS_WARNINGS (warnings));
-
-	if (strcmp (key, GPM_CONF_USE_TIME_POLICY) == 0) {
-		warnings->priv->use_time_primary =
-			gconf_client_get_bool (warnings->priv->conf,
-					       GPM_CONF_USE_TIME_POLICY, NULL);
-	}
+gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, GpmWarnings *warnings)
+{
+	GConfValue *value;
+
+	value = gconf_entry_get_value (entry);
+	if (value == NULL)
+		return;
+
+	if (strcmp (entry->key, GPM_CONF_USE_TIME_POLICY) == 0)
+		warnings->priv->use_time_primary = gconf_value_get_bool (value);
 }
 
 /**
@@ -244,8 +243,11 @@
 
 	warnings->priv->time_is_accurate = TRUE;
 	warnings->priv->conf = gconf_client_get_default ();
-	g_signal_connect (warnings->priv->conf, "value-changed",
-			  G_CALLBACK (gconf_key_changed_cb), warnings);
+	gconf_client_add_dir (warnings->priv->conf, GPM_CONF_DIR,
+			      GCONF_CLIENT_PRELOAD_NONE, NULL);
+	gconf_client_notify_add (warnings->priv->conf, GPM_CONF_DIR,
+				 (GConfClientNotifyFunc) gconf_key_changed_cb,
+				 warnings, NULL, NULL);
 
 	/* get percentage policy */
 	warnings->priv->low_percentage = gconf_client_get_int (warnings->priv->conf, GPM_CONF_THRESH_PERCENTAGE_LOW, NULL);
@@ -260,11 +262,10 @@
 	/* We can disable this if the ACPI BIOS is broken, and the
 	   time_remaining is therefore inaccurate or just plain wrong. */
 	warnings->priv->use_time_primary = gconf_client_get_bool (warnings->priv->conf, GPM_CONF_USE_TIME_POLICY, NULL);
-	if (warnings->priv->use_time_primary) {
+	if (warnings->priv->use_time_primary)
 		egg_debug ("Using per-time notification policy");
-	} else {
+	else
 		egg_debug ("Using percentage notification policy");
-	}
 }
 
 /**



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