[Goodies-commits] r6912 - in xfce4-power-manager/trunk: . libxfpm po settings src

Ali Abdallah aliov at xfce.org
Sun Mar 15 11:13:06 CET 2009


Author: aliov
Date: 2009-03-15 10:13:06 +0000 (Sun, 15 Mar 2009)
New Revision: 6912

Added:
   xfce4-power-manager/trunk/libxfpm/hal-iface.c
   xfce4-power-manager/trunk/libxfpm/hal-iface.h
   xfce4-power-manager/trunk/src/xfpm-xfconf.c
   xfce4-power-manager/trunk/src/xfpm-xfconf.h
Removed:
   xfce4-power-manager/trunk/libxfpm/dbus-hal.c
   xfce4-power-manager/trunk/libxfpm/dbus-hal.h
Modified:
   xfce4-power-manager/trunk/ChangeLog
   xfce4-power-manager/trunk/libxfpm/Makefile.am
   xfce4-power-manager/trunk/libxfpm/hal-manager.c
   xfce4-power-manager/trunk/po/POTFILES.in
   xfce4-power-manager/trunk/settings/Makefile.am
   xfce4-power-manager/trunk/src/Makefile.am
   xfce4-power-manager/trunk/src/xfpm-brightness-hal.c
   xfce4-power-manager/trunk/src/xfpm-brightness-hal.h
   xfce4-power-manager/trunk/src/xfpm-cpu.c
   xfce4-power-manager/trunk/src/xfpm-cpu.h
   xfce4-power-manager/trunk/src/xfpm-dpms.c
   xfce4-power-manager/trunk/src/xfpm-dpms.h
   xfce4-power-manager/trunk/src/xfpm-engine.c
   xfce4-power-manager/trunk/src/xfpm-supply.c
   xfce4-power-manager/trunk/src/xfpm-supply.h
   xfce4-power-manager/trunk/src/xfpm-tray-icon.h
Log:
Patched to fix makefile typo and correct the POTFILES.in (Yves Alexis)+Use a weak reference for the common objects

Modified: xfce4-power-manager/trunk/ChangeLog
===================================================================
--- xfce4-power-manager/trunk/ChangeLog	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/ChangeLog	2009-03-15 10:13:06 UTC (rev 6912)
@@ -1,4 +1,7 @@
 
+2009-03-15 11:12 Ali aliov at xfce.org 
+	 * : Patched to fix makefile typo and correct the POTFILES.in (Yves Alexis)+Use a weak reference for the common objects
+
 2009-03-14 19:26 Ali aliov at xfce.org 
 	 * : Added the missing desktop file, Thanks to Mike for pointing out
 

Modified: xfce4-power-manager/trunk/libxfpm/Makefile.am
===================================================================
--- xfce4-power-manager/trunk/libxfpm/Makefile.am	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/libxfpm/Makefile.am	2009-03-15 10:13:06 UTC (rev 6912)
@@ -1,13 +1,13 @@
 noinst_LTLIBRARIES = 			\
 	libxfpmhal.la			\
-	libxfpmdbus.la			\
+	libxfpmhal_iface.la		\
 	libxfpmcommon.la
 
 libxfpmhal_la_SOURCES =			\
 	xfpm-string.c			\
 	xfpm-string.h			\
 	hal-marshal.c			\
-	hal-mardhal.h			\
+	hal-marshal.h			\
 	hal-manager.c			\
 	hal-manager.h			\
 	hal-power.c			\
@@ -15,23 +15,24 @@
 	hal-device.c			\
 	hal-device.h			\
 	hal-battery.c			\
-	hal-battery.h
+	hal-battery.h			\
+	hal-enum.h
 
 libxfpmhal_la_CFLAGS =			\
 	$(GLIB_CFLAGS)			\
 	$(DBUS_GLIB_CFLAGS)
 
-libxfpmdbus_la_SOURCES =		\
-	dbus-hal.c			\
-	dbus-hal.h
+libxfpmhal_iface_la_SOURCES =		\
+	hal-iface.c			\
+	hal-iface.h			\
+	xfpm-string.c			\
+	xfpm-string.h
 
-
-libxfpmdbus_la_CFLAGS =			\
+libxfpmhal_iface_la_CFLAGS =		\
 	$(GLIB_CFLAGS)			\
 	$(DBUS_CFLAGS)			\
 	$(DBUS_GLIB_CFLAGS)
 
-
 libxfpmcommon_la_SOURCES =      	\
         xfpm-string.c           	\
         xfpm-string.h           	\
@@ -66,4 +67,4 @@
         cp tmp-marshal.c $(@F) && \
         rm -f tmp-marshal.c tmp-marshal.c~
 
-endif
\ No newline at end of file
+endif

Added: xfce4-power-manager/trunk/libxfpm/hal-iface.c
===================================================================
--- xfce4-power-manager/trunk/libxfpm/hal-iface.c	                        (rev 0)
+++ xfce4-power-manager/trunk/libxfpm/hal-iface.c	2009-03-15 10:13:06 UTC (rev 6912)
@@ -0,0 +1,456 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <glib.h>
+
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "xfpm-string.h"
+
+#include "hal-iface.h"
+
+/* Init */
+static void hal_iface_class_init (HalIfaceClass *klass);
+static void hal_iface_init       (HalIface *iface);
+static void hal_iface_finalize   (GObject *object);
+
+static void hal_iface_get_property(GObject *object,
+				   guint prop_id,
+				   GValue *value,
+				   GParamSpec *pspec);
+
+static gpointer  hal_iface_object = NULL;
+
+#define HAL_IFACE_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), HAL_TYPE_IFACE, HalIfacePrivate))
+
+struct HalIfacePrivate
+{
+    DBusGConnection 	*bus;
+    
+    gboolean             connected;
+    gboolean             can_suspend;
+    gboolean             can_hibernate;
+    gboolean             cpu_freq_iface_can_be_used;
+    gboolean             caller_privilege;
+    
+};
+
+enum
+{
+    PROP_0,
+    PROP_CALLER_PRIVILEGE,
+    PROP_CAN_SUSPEND,
+    PROP_CAN_HIBERNATE,
+    PROP_CPU_FREQ_IFACE_CAN_BE_USED
+};
+    
+G_DEFINE_TYPE(HalIface, hal_iface, G_TYPE_OBJECT)
+
+static void
+hal_iface_class_init(HalIfaceClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+    
+    object_class->get_property = hal_iface_get_property;
+
+    g_object_class_install_property(object_class,
+				    PROP_CALLER_PRIVILEGE,
+				    g_param_spec_boolean("caller-privilege",
+							 NULL, NULL,
+							 FALSE,
+							 G_PARAM_READABLE));
+							 
+    g_object_class_install_property(object_class,
+				    PROP_CAN_SUSPEND,
+				    g_param_spec_boolean("can-suspend",
+							 NULL, NULL,
+							 FALSE,
+							 G_PARAM_READABLE));
+							 
+    g_object_class_install_property(object_class,
+				    PROP_CAN_HIBERNATE,
+				    g_param_spec_boolean("can-hibernate",
+							 NULL, NULL,
+							 FALSE,
+							 G_PARAM_READABLE));
+							 
+    g_object_class_install_property(object_class,
+				    PROP_CPU_FREQ_IFACE_CAN_BE_USED,
+				    g_param_spec_boolean("cpu-freq-iface",
+							 NULL, NULL,
+							 FALSE,
+							 G_PARAM_READABLE));
+
+    object_class->finalize = hal_iface_finalize;
+
+    g_type_class_add_private(klass,sizeof(HalIfacePrivate));
+}
+
+static void
+hal_iface_init(HalIface *iface)
+{
+    iface->priv = HAL_IFACE_GET_PRIVATE(iface);
+    
+    iface->priv->bus 			= NULL;
+    iface->priv->connected		= FALSE;
+    iface->priv->can_suspend    	= FALSE;
+    iface->priv->can_hibernate  	= FALSE;
+    iface->priv->caller_privilege       = FALSE;
+    iface->priv->cpu_freq_iface_can_be_used = FALSE;
+}
+
+static void hal_iface_get_property(GObject *object,
+				   guint prop_id,
+				   GValue *value,
+				   GParamSpec *pspec)
+{
+    HalIface *iface;
+    iface = HAL_IFACE(object);
+
+    switch(prop_id)
+    {
+	case PROP_CALLER_PRIVILEGE:
+	    g_value_set_boolean (value, iface->priv->caller_privilege );
+	    break;
+	case PROP_CAN_SUSPEND:
+	    g_value_set_boolean (value, iface->priv->can_suspend );
+	    break;
+	case PROP_CAN_HIBERNATE:
+	    g_value_set_boolean (value, iface->priv->can_hibernate);
+	    break;
+	case PROP_CPU_FREQ_IFACE_CAN_BE_USED:
+	    g_value_set_boolean (value, iface->priv->cpu_freq_iface_can_be_used);
+	    break;
+	default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
+	    break;
+    }
+}
+
+static void
+hal_iface_finalize(GObject *object)
+{
+    HalIface *iface;
+
+    iface = HAL_IFACE(object);
+
+    G_OBJECT_CLASS(hal_iface_parent_class)->finalize(object);
+}
+
+HalIface *
+hal_iface_new(void)
+{
+    if ( hal_iface_object != NULL )
+    {
+	g_object_ref (hal_iface_object);
+    }
+    else
+    {
+	hal_iface_object = g_object_new (HAL_TYPE_IFACE, NULL);
+	g_object_add_weak_pointer (hal_iface_object, &hal_iface_object);
+    }
+    
+    return HAL_IFACE (hal_iface_object);
+}
+
+static gboolean
+hal_iface_check_interface (HalIface *iface, const gchar *interface)
+{
+    DBusMessage *message;
+    DBusMessage *reply;
+    DBusError error ;
+    
+    message = dbus_message_new_method_call ("org.freedesktop.Hal",
+					    "/org/freedesktop/Hal",
+					    interface,
+					    "JustToCheck");
+    
+    if (!message)
+    	return FALSE;
+    
+    dbus_error_init (&error);
+    
+    reply = 
+    	dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection(iface->priv->bus),
+						   message, 2000, &error);
+    dbus_message_unref (message);
+    
+    if ( reply ) dbus_message_unref (reply);
+    
+    if ( dbus_error_is_set(&error) )
+    {
+	if (!xfpm_strcmp(error.name,"org.freedesktop.DBus.Error.UnknownMethod"))
+        {
+            dbus_error_free(&error);
+	    return TRUE;
+        }
+    }
+    
+    return FALSE;
+}
+
+static gboolean
+get_property_bool (HalIface *iface, const gchar *property)
+{
+    GError *error = NULL;
+    gboolean ret;
+    DBusGProxy *proxy = dbus_g_proxy_new_for_name (iface->priv->bus, 
+						   "org.freedesktop.Hal",
+					           "/org/freedesktop/Hal/devices/computer",
+					           "org.freedesktop.Hal.Device");
+    dbus_g_proxy_call (proxy, "GetPropertyBoolean", &error,
+		       G_TYPE_STRING, property,
+		       G_TYPE_INVALID,
+		       G_TYPE_BOOLEAN, &ret,
+		       G_TYPE_INVALID);
+		       
+    if ( error )
+    {
+	g_critical ("Unable to get bool property: %s\n", error->message);
+	g_error_free (error);
+    }
+    
+    g_object_unref (proxy);
+    
+    return ret;
+}
+
+static void
+hal_iface_power_management_check (HalIface *iface)
+{
+    iface->priv->caller_privilege =
+	hal_iface_check_interface (iface,  "org.freedesktop.Hal.Device.SystemPowerManagement");
+    
+    iface->priv->can_suspend   = get_property_bool (iface, "power_management.can_suspend");
+    iface->priv->can_hibernate = get_property_bool (iface, "power_management.can_hibernate");
+}
+
+static void
+hal_iface_cpu_check (HalIface *iface)
+{
+    iface->priv->cpu_freq_iface_can_be_used  = 
+	hal_iface_check_interface (iface, "org.freedesktop.Hal.Device.CPUFreq");
+}
+
+gboolean
+hal_iface_connect (HalIface *iface)
+{
+    g_return_val_if_fail (HAL_IS_IFACE (iface), FALSE);
+    
+    GError *error = NULL;
+    
+    iface->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+    
+    if ( error )
+    {
+	g_critical ("Unable to get system bus %s.", error->message);
+	g_error_free (error);
+	return FALSE;
+    }
+    
+    iface->priv->connected = TRUE;
+    hal_iface_power_management_check (iface);
+    hal_iface_cpu_check (iface);
+    
+    return TRUE;
+}
+
+gboolean hal_iface_shutdown (HalIface *iface, const gchar *shutdown, GError **gerror)
+{
+    g_return_val_if_fail (HAL_IS_IFACE(iface), FALSE);
+    g_return_val_if_fail (iface->priv->connected, FALSE);
+    g_return_val_if_fail (iface->priv->caller_privilege, FALSE);
+    
+    DBusMessage *message, *reply = NULL;
+    DBusError error;
+    gint exit_code;
+    
+    message = dbus_message_new_method_call ("org.freedesktop.Hal",
+					    "/org/freedesktop/Hal/devices/computer",
+					    "org.freedesktop.Hal.Device.SystemPowerManagement",
+					    shutdown);
+    if ( !message )
+    {
+	g_set_error ( gerror, 0, 0, "Out of memory");
+	return FALSE;
+    }
+    
+    if ( xfpm_strequal("Suspend", shutdown ) )
+    {
+	gint seconds = 0;
+    	dbus_message_append_args (message, DBUS_TYPE_INT32, &seconds, DBUS_TYPE_INVALID);
+    }
+    
+    dbus_error_init (&error);
+    
+    reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection(iface->priv->bus),
+						       message,
+						       -1,
+						       &error);
+    dbus_message_unref (message);
+
+    if ( dbus_error_is_set(&error) )
+    {
+	dbus_set_g_error (gerror, &error);
+	return FALSE;
+    }
+    
+    switch (dbus_message_get_type(reply) )
+    {
+	case DBUS_MESSAGE_TYPE_METHOD_RETURN:
+	    dbus_message_get_args (reply, NULL,
+				   DBUS_TYPE_INT32,
+				   &exit_code,
+				   DBUS_TYPE_INVALID);
+	    dbus_message_unref (reply);
+	    if ( exit_code == 0) return TRUE;
+	    else
+	    {
+		g_set_error (gerror, 0, 0, "System failed to sleep");
+		return FALSE;
+	    }
+	    break;
+	    
+	case DBUS_MESSAGE_TYPE_ERROR:
+	    dbus_message_unref (reply);
+	    g_set_error ( gerror, 0, 0, "Failed to sleep");
+	    return FALSE;
+	    break;
+	default:
+	    dbus_message_unref ( reply );
+	    g_set_error ( gerror, 0, 0, "Failed to sleep");
+	    return FALSE;
+    }
+    return TRUE;
+}
+
+gchar **hal_iface_get_cpu_governors (HalIface *iface, GError **error)
+{
+    gchar **governors = NULL;
+    
+    g_return_val_if_fail (HAL_IS_IFACE(iface), NULL);
+    g_return_val_if_fail (iface->priv->connected, NULL);
+    g_return_val_if_fail (iface->priv->caller_privilege, NULL);
+    g_return_val_if_fail (iface->priv->cpu_freq_iface_can_be_used, NULL);
+    
+    DBusGProxy *proxy = dbus_g_proxy_new_for_name (iface->priv->bus,
+						   "org.freedesktop.Hal",
+						   "/org/freedesktop/Hal/devices/computer",
+						   "org.freedesktop.Hal.Device.CPUFreq");
+    if ( !proxy )
+    {
+	g_critical ("Failed to create proxy");
+	goto out;
+    }
+    
+    dbus_g_proxy_call (proxy, "GetCPUFreqAvailableGovernors", error,
+		       G_TYPE_INVALID,
+		       G_TYPE_STRV, &governors,
+		       G_TYPE_INVALID);
+    
+    g_object_unref (proxy);
+    
+out:
+    return governors;
+}
+							  
+gchar *hal_iface_get_cpu_current_governor (HalIface *iface, GError **error)
+{
+    gchar *governor;
+    
+    g_return_val_if_fail (HAL_IS_IFACE(iface), NULL);
+    g_return_val_if_fail (iface->priv->connected, NULL);
+    g_return_val_if_fail (iface->priv->caller_privilege, NULL);
+    g_return_val_if_fail (iface->priv->cpu_freq_iface_can_be_used, NULL);
+    
+    DBusGProxy *proxy = dbus_g_proxy_new_for_name (iface->priv->bus,
+						   "org.freedesktop.Hal",
+						   "/org/freedesktop/Hal/devices/computer",
+						   "org.freedesktop.Hal.Device.CPUFreq");
+    if ( !proxy )
+    {
+	g_critical ("Failed to create proxy");
+	goto out;
+    }
+    
+    dbus_g_proxy_call (proxy, "GetCPUFreqGovernor", error,
+		       G_TYPE_INVALID,
+		       G_TYPE_STRING, &governor,
+		       G_TYPE_INVALID);
+    
+    g_object_unref (proxy);
+    
+out:
+    return governor;
+}
+							
+gboolean hal_iface_set_cpu_governor (HalIface *iface, const gchar *governor, GError **error)
+{
+    g_return_val_if_fail (HAL_IS_IFACE(iface), FALSE);
+    g_return_val_if_fail (iface->priv->connected, FALSE);
+    g_return_val_if_fail (iface->priv->caller_privilege, FALSE);
+    g_return_val_if_fail (iface->priv->cpu_freq_iface_can_be_used, FALSE);
+    
+    DBusGProxy *proxy = dbus_g_proxy_new_for_name (iface->priv->bus,
+						   "org.freedesktop.Hal",
+						   "/org/freedesktop/Hal/devices/computer",
+						   "org.freedesktop.Hal.Device.CPUFreq");
+    if ( !proxy )
+    {
+	g_critical ("Failed to create proxy");
+	goto out;
+    }
+    
+    dbus_g_proxy_call (proxy, "SetCPUFreqGovernor", error,
+		       G_TYPE_STRING, &governor,
+		       G_TYPE_INVALID,
+		       G_TYPE_INVALID);
+    
+    g_object_unref (proxy);
+    
+out:
+    
+    return FALSE;
+}
+
+void hal_iface_free_string_array (gchar **array)
+{
+    gint i;
+
+    if (array == NULL)	
+	    return;
+    
+    for (i=0; array[i]; i++) 
+	g_free (array[i]);
+    
+    g_free (array);
+}

Added: xfce4-power-manager/trunk/libxfpm/hal-iface.h
===================================================================
--- xfce4-power-manager/trunk/libxfpm/hal-iface.h	                        (rev 0)
+++ xfce4-power-manager/trunk/libxfpm/hal-iface.h	2009-03-15 10:13:06 UTC (rev 6912)
@@ -0,0 +1,76 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __HAL_IFACE_H
+#define __HAL_IFACE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define HAL_TYPE_IFACE        (hal_iface_get_type () )
+#define HAL_IFACE(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), HAL_TYPE_IFACE, HalIface))
+#define HAL_IS_IFACE(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), HAL_TYPE_IFACE))
+
+typedef enum
+{
+    SYSTEM_CAN_HIBERNATE         =  (1<<0),
+    SYSTEM_CAN_SUSPEND           =  (1<<1),
+    
+} SystemPowerManagement;
+
+typedef struct HalIfacePrivate HalIfacePrivate;
+
+typedef struct
+{
+    GObject		parent;
+    HalIfacePrivate	*priv;
+    
+} HalIface;
+
+typedef struct
+{
+    GObjectClass 	parent_class;
+    
+} HalIfaceClass;
+
+GType        		hal_iface_get_type        	 (void) G_GNUC_CONST;
+HalIface       	       *hal_iface_new             	 (void);
+
+gboolean                hal_iface_connect         	 (HalIface *iface);
+
+gboolean		hal_iface_shutdown	 	 (HalIface *iface,
+							  const gchar *shutdown,
+							  GError **error);
+
+gchar                 **hal_iface_get_cpu_governors 	 (HalIface *iface,
+							  GError **error);
+							  
+gchar 	               *hal_iface_get_cpu_current_governor(HalIface *iface,
+							   GError **error);
+							
+gboolean		hal_iface_set_cpu_governor       (HalIface *iface,
+							  const gchar *governor,
+							  GError **error);
+							   
+void                    hal_iface_free_string_array      (gchar **array);
+G_END_DECLS
+
+#endif /* __HAL_IFACE_H */

Modified: xfce4-power-manager/trunk/libxfpm/hal-manager.c
===================================================================
--- xfce4-power-manager/trunk/libxfpm/hal-manager.c	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/libxfpm/hal-manager.c	2009-03-15 10:13:06 UTC (rev 6912)
@@ -166,7 +166,7 @@
 }
 
 HalManager *
-hal_manager_new(void)
+hal_manager_new (void)
 {
     HalManager *manager = NULL;
     manager = g_object_new (HAL_TYPE_MANAGER, NULL);

Modified: xfce4-power-manager/trunk/po/POTFILES.in
===================================================================
--- xfce4-power-manager/trunk/po/POTFILES.in	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/po/POTFILES.in	2009-03-15 10:13:06 UTC (rev 6912)
@@ -1,12 +1,35 @@
-src/xfpm-ac-adapter.c
+settings/xfpm-settings.c
+settings/xfpm-settings-main.c
+settings/xfce4-power-manager.desktop.in
 src/xfpm-battery.c
-src/xfpm-settings.c
-src/xfpm-battery-icon.c
-src/xfpm-dpms-spins.c
-src/xfpm-common.c
+src/xfpm-battery-info.c
+src/xfpm-button-xf86.c
+src/xfpm-lid-hal.c
+src/xfpm-brightness-hal.c
+src/xfpm-battery.c
+src/xfpm-idle.c
 src/xfpm-main.c
-src/xfpm-driver.c
-src/xfpm-hal.c
-src/xfpm-dbus-messages.c
-src/xfpm-settings-main.c
-src/xfce4-power-manager.desktop.in
+src/xfpm-cpu.c
+src/xfpm-notify.c
+src/xfpm-supply.c
+src/xfpm-network-manager.c
+src/xfpm-dpms.c
+src/xfpm-tray-icon.c
+src/xfpm-engine.c
+src/xfpm-adapter.c
+src/xfpm-manager.c
+libxfpm/xfpm-common.c
+libxfpm/xfpm-string.c
+libxfpm/hal-battery.c
+libxfpm/hal-device.c
+libxfpm/xfpm-dbus.c
+libxfpm/xfpm-popups.c
+libxfpm/hal-marshal.c
+libxfpm/hal-manager.c
+libxfpm/dbus-hal.c
+libxfpm/hal-power.c
+libxfpm/hal-battery.c
+panel-plugins/brightness/main.c
+src/xfce-power-manager.desktop.in
+settings/xfce4-power-manager.desktop.in
+panel-plugins/brightness/xfce4-brightness-plugin.desktop.in.in

Modified: xfce4-power-manager/trunk/settings/Makefile.am
===================================================================
--- xfce4-power-manager/trunk/settings/Makefile.am	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/settings/Makefile.am	2009-03-15 10:13:06 UTC (rev 6912)
@@ -59,10 +59,10 @@
 @INTLTOOL_DESKTOP_RULE@
 
 EXTRA_DIST = 					\
-	xfce-power-manaher-dbus-client.h	\
+	xfce-power-manager-dbus-client.h	\
 	xfpm-settings_glade.h			\
 	$(desktop_in_files)
 
 DISTCLEANFILES =				\
 	$(BUILT_SOURCES)			\
-	$(desktop_DATA)
\ No newline at end of file
+	$(desktop_DATA)

Modified: xfce4-power-manager/trunk/src/Makefile.am
===================================================================
--- xfce4-power-manager/trunk/src/Makefile.am	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/Makefile.am	2009-03-15 10:13:06 UTC (rev 6912)
@@ -12,6 +12,8 @@
 	xfpm-manager.h				\
 	xfpm-engine.c				\
 	xfpm-engine.h				\
+	xfpm-xfconf.c				\
+	xfpm-xfconf.h				\
 	xfpm-supply.c				\
 	xfpm-supply.h				\
 	xfpm-adapter.c				\
@@ -61,6 +63,7 @@
 	$(top_builddir)/libxfpm/libxfpmhal.la	\
 	$(top_builddir)/libxfpm/libxfpmdbus.la	\
 	$(top_builddir)/libxfpm/libxfpmcommon.la\
+	$(top_builddir)/libxfpm/libxfpmhal_iface.la\
 	$(GTK_LIBS)				\
 	$(GLIB_LIBS)				\
 	$(DBUS_LIBS)				\
@@ -132,7 +135,9 @@
 autostart_DATA = $(autostart_in_files:.desktop.in=.desktop)
 
 EXTRA_DIST = 					\
-	xfpm-marshal.list
+	xfpm-marshal.list		\
+	xfpm-enum-glib.h		\
+	$(autostart_in_files)
 
 DISTCLEANFILES =				\
 	$(BUILT_SOURCES)			\

Modified: xfce4-power-manager/trunk/src/xfpm-brightness-hal.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-brightness-hal.c	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-brightness-hal.c	2009-03-15 10:13:06 UTC (rev 6912)
@@ -45,6 +45,7 @@
 #include "libxfpm/hal-device.h"
 #include "libxfpm/xfpm-string.h"
 
+#include "xfpm-xfconf.h"
 #include "xfpm-idle.h"
 #include "xfpm-config.h"
 #include "xfpm-brightness-hal.h"
@@ -63,6 +64,7 @@
     HalDevice    *device;
     DBusGProxy   *proxy;
     
+    XfpmXfconf   *conf;
     XfpmIdle     *idle;
     
     gint          max_level;
@@ -125,6 +127,9 @@
     if ( brg->priv->device )
 	g_object_unref (brg->priv->device);
 	
+    if ( brg->priv->conf )
+	g_object_unref (brg->priv->conf);
+	
     G_OBJECT_CLASS(xfpm_brightness_hal_parent_class)->finalize(object);
 }
 
@@ -290,10 +295,10 @@
 }
 
 static void
-xfpm_brightness_hal_load_config (XfpmBrightnessHal *brg, XfconfChannel *channel)
+xfpm_brightness_hal_load_config (XfpmBrightnessHal *brg)
 {
     brg->priv->on_ac_timeout =
-	xfconf_channel_get_uint (channel, BRIGHTNESS_ON_AC, 9);
+	xfconf_channel_get_uint (brg->priv->conf->channel, BRIGHTNESS_ON_AC, 9);
 	
     if ( brg->priv->on_ac_timeout > 120 || brg->priv->on_ac_timeout < 9)
     {
@@ -302,7 +307,7 @@
     }
     
     brg->priv->on_battery_timeout =
-	xfconf_channel_get_uint (channel, BRIGHTNESS_ON_BATTERY, 10);
+	xfconf_channel_get_uint (brg->priv->conf->channel, BRIGHTNESS_ON_BATTERY, 10);
 	
     if ( brg->priv->on_battery_timeout > 120 || brg->priv->on_battery_timeout < 9)
     {
@@ -360,7 +365,7 @@
 }
 
 XfpmBrightnessHal *
-xfpm_brightness_hal_new (XfconfChannel *channel)
+xfpm_brightness_hal_new ()
 {
     XfpmBrightnessHal *brg = NULL;
     brg = g_object_new (XFPM_TYPE_BRIGHTNESS_HAL, NULL);
@@ -370,6 +375,7 @@
     if ( brg->priv->hw_found || brg->priv->max_level != 0 )
     {
 	brg->priv->idle     = xfpm_idle_new ();
+	brg->priv->conf     = xfpm_xfconf_new ();
 	
 	g_signal_connect (brg->priv->idle, "alarm-timeout",
 			  G_CALLBACK(xfpm_brightness_hal_alarm_timeout_cb), brg);
@@ -377,9 +383,9 @@
 	g_signal_connect (brg->priv->idle, "reset",
 			  G_CALLBACK(xfpm_brightness_hal_reset_cb), brg);
 			  
-	xfpm_brightness_hal_load_config (brg, channel);
+	xfpm_brightness_hal_load_config (brg);
 	
-	g_signal_connect (channel, "property-changed", 
+	g_signal_connect (brg->priv->conf->channel, "property-changed", 
 			  G_CALLBACK(xfpm_brightness_hal_property_changed_cb), brg);
 			  
 	xfpm_brightness_hal_set_timeouts (brg);

Modified: xfce4-power-manager/trunk/src/xfpm-brightness-hal.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-brightness-hal.h	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-brightness-hal.h	2009-03-15 10:13:06 UTC (rev 6912)
@@ -45,7 +45,7 @@
 } XfpmBrightnessHalClass;
 
 GType        				xfpm_brightness_hal_get_type        (void) G_GNUC_CONST;
-XfpmBrightnessHal      		       *xfpm_brightness_hal_new             (XfconfChannel *channel);
+XfpmBrightnessHal      		       *xfpm_brightness_hal_new             (void);
 
 void                                    xfpm_brightness_hal_set_on_battery  (XfpmBrightnessHal *brg,
 									     gboolean on_battery);

Modified: xfce4-power-manager/trunk/src/xfpm-cpu.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-cpu.c	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-cpu.c	2009-03-15 10:13:06 UTC (rev 6912)
@@ -38,10 +38,11 @@
 
 #include <libxfce4util/libxfce4util.h>
 
-#include "libxfpm/dbus-hal.h"
+#include "libxfpm/hal-iface.h"
 #include "libxfpm/xfpm-string.h"
 
 #include "xfpm-cpu.h"
+#include "xfpm-xfconf.h"
 #include "xfpm-config.h"
 #include "xfpm-enum.h"
 
@@ -55,52 +56,28 @@
 
 struct XfpmCpuPrivate
 {
-    XfconfChannel *channel;
-    DbusHal       *hbus;
+    XfpmXfconf    *conf;
+    HalIface      *iface;
     
     gboolean 	   on_battery;
     gboolean 	   power_save;
     
-    gboolean       interface_ok;
     guint8         cpu_governors;
+    
 };
 
 G_DEFINE_TYPE(XfpmCpu, xfpm_cpu, G_TYPE_OBJECT)
 
 static void
-xfpm_cpu_class_init(XfpmCpuClass *klass)
-{
-    GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
-    object_class->finalize = xfpm_cpu_finalize;
-
-    g_type_class_add_private(klass,sizeof(XfpmCpuPrivate));
-}
-
-static void
-xfpm_cpu_init(XfpmCpu *cpu)
-{
-    cpu->priv = XFPM_CPU_GET_PRIVATE(cpu);
-    cpu->priv->cpu_governors = 0;
-}
-
-static void
-xfpm_cpu_finalize(GObject *object)
-{
-    XfpmCpu *cpu;
-
-    cpu = XFPM_CPU(object);
-
-    G_OBJECT_CLASS(xfpm_cpu_parent_class)->finalize(object);
-}
-
-static void
 xfpm_cpu_set_governor (XfpmCpu *cpu, const gchar *governor)
 {
+    GError *error = NULL;
     
-    if (!dbus_hal_set_cpu_governor (cpu->priv->hbus, governor, NULL))
-    	g_critical ("Unable to set CPU governor to %s\n", governor);
-    
+    if (! hal_iface_set_cpu_governor(cpu->priv->iface, governor, &error))
+    {
+    	g_critical ("Unable to set CPU governor to %s: %s\n", governor, error->message);
+	g_error_free (error);
+    }
 }
 
 static XfpmCpuGovernor 
@@ -119,11 +96,25 @@
 static void
 xfpm_cpu_update_governor (XfpmCpu *cpu)
 {
-    if ( !cpu->priv->interface_ok )
-    	return;
-	
-    gchar *current_governor = dbus_hal_get_cpu_current_governor (cpu->priv->hbus, NULL);
+    GError *error = NULL;
+    gboolean cpu_freq_iface;
     
+    g_object_get (G_OBJECT(cpu->priv->iface), 
+		  "cpu-freq-iface", &cpu_freq_iface,
+		  NULL);
+		  
+    if ( !cpu_freq_iface)
+	return;
+    
+    gchar *current_governor = hal_iface_get_cpu_current_governor (cpu->priv->iface, &error);
+    
+    if ( error )
+    {
+	g_warning ("Get cpu governor failed: %s.", error->message);
+	g_error_free (error);
+	return;
+    }
+    
     if ( !current_governor )
     	return;
 
@@ -149,14 +140,52 @@
 	}
 	return;
     }
+    g_free (current_governor);
 
 }
 
+static gboolean
+xfpm_cpu_get_available_governors (XfpmCpu *cpu)
+{
+    GError *error = NULL;
+    gchar **governors =
+    	hal_iface_get_cpu_governors (cpu->priv->iface, &error);
+	
+    if ( error )
+    {
+	g_critical ("Error getting available cpu governors");
+	return FALSE;
+    }
+	
+    if ( !governors )
+    {
+    	g_critical ("Unable to get CPU governors\n");
+	return FALSE;
+    }
+    
+    int i =0 ;
+    for ( i = 0; governors[i]; i++)
+    {
+    	TRACE("found CPU governor %s", governors[i]);
+	
+	if (xfpm_strequal(governors[i], "powersave") )
+	    cpu->priv->cpu_governors |= CPU_POWERSAVE;
+	else if ( xfpm_strequal(governors[i], "ondemand") )
+	    cpu->priv->cpu_governors |= CPU_ONDEMAND;
+	else if ( xfpm_strequal(governors[i], "performance") )
+	    cpu->priv->cpu_governors |= CPU_PERFORMANCE;
+    }
+
+    hal_iface_free_string_array (governors);
+    
+    return TRUE;
+}
+
 static void
 xfpm_cpu_load_configuration (XfpmCpu *cpu)
 {
     cpu->priv->power_save =
-    	xfconf_channel_get_bool (cpu->priv->channel, POWER_SAVE_ON_BATTERY, TRUE);
+    	xfconf_channel_get_bool (cpu->priv->conf->channel, POWER_SAVE_ON_BATTERY, TRUE);
 }
 
 static void
@@ -173,56 +202,85 @@
     }
 }
 
-static gboolean
-xfpm_cpu_get_available_governors (XfpmCpu *cpu)
+static void
+xfpm_cpu_check (XfpmCpu *cpu)
 {
-    gchar **governors =
-    	dbus_hal_get_cpu_available_governors (cpu->priv->hbus, NULL);
-	
-    if ( !governors )
+    gboolean caller_privilege, cpu_freq_iface;
+    
+    g_object_get (G_OBJECT(cpu->priv->iface), 
+		  "caller-privilege", &caller_privilege,
+		  "cpu-freq-iface", &cpu_freq_iface,
+		  NULL);
+		  
+    if ( !caller_privilege )
     {
-    	g_critical ("Unable to get CPU governors\n");
-	return FALSE;
+	g_warning ("Using CPU FREQ interface permission denied");
+	goto out;
     }
     
-    int i =0 ;
-    for ( i = 0; governors[i]; i++)
+    if (!cpu_freq_iface)
     {
-    	TRACE("found CPU governor %s", governors[i]);
-	
-	if (xfpm_strequal(governors[i], "powersave") )
-	    cpu->priv->cpu_governors |= CPU_POWERSAVE;
-	else if ( xfpm_strequal(governors[i], "ondemand") )
-	    cpu->priv->cpu_governors |= CPU_ONDEMAND;
-	else if ( xfpm_strequal(governors[i], "performance") )
-	    cpu->priv->cpu_governors |= CPU_PERFORMANCE;
+	g_warning ("CPU FREQ interface cannot be used");
+	goto out;
     }
-
-    //libhal_free_string_array (governors);
     
-    return TRUE;
-    
+    if ( !xfpm_cpu_get_available_governors (cpu) )
+    {
+	g_critical ("Failed to handle cpu governors");
+	goto out;
+    }
+out:
+	;
 }
 
-XfpmCpu *
-xfpm_cpu_new (XfconfChannel *channel, DbusHal *hbus)
+static void
+xfpm_cpu_class_init(XfpmCpuClass *klass)
 {
-    XfpmCpu *cpu = NULL;
-    cpu = g_object_new (XFPM_TYPE_CPU, NULL);
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->finalize = xfpm_cpu_finalize;
+
+    g_type_class_add_private(klass,sizeof(XfpmCpuPrivate));
+}
+
+static void
+xfpm_cpu_init(XfpmCpu *cpu)
+{
+    cpu->priv = XFPM_CPU_GET_PRIVATE(cpu);
     
-    cpu->priv->hbus = hbus;
+    cpu->priv->cpu_governors = 0;
+    cpu->priv->iface         = hal_iface_new ();
     
-    if ( !xfpm_cpu_get_available_governors (cpu))
-    	goto out;
-    
-    cpu->priv->interface_ok = TRUE;
-    cpu->priv->channel = channel;
+    cpu->priv->conf = xfpm_xfconf_new ();
     xfpm_cpu_load_configuration (cpu);
     
-    g_signal_connect (cpu->priv->channel, "property-changed",
+    g_signal_connect (cpu->priv->conf->channel, "property-changed",
 		      G_CALLBACK(xfpm_cpu_property_changed_cb), cpu);
 		      
-out:
+    xfpm_cpu_check (cpu);
+}
+
+static void
+xfpm_cpu_finalize(GObject *object)
+{
+    XfpmCpu *cpu;
+
+    cpu = XFPM_CPU(object);
+    
+    if ( cpu->priv->conf )
+	g_object_unref (cpu->priv->conf);
+	
+    if ( cpu->priv->iface )
+	g_object_unref (cpu->priv->iface);
+
+    G_OBJECT_CLASS(xfpm_cpu_parent_class)->finalize(object);
+}
+
+XfpmCpu *
+xfpm_cpu_new (void)
+{
+    XfpmCpu *cpu = NULL;
+    cpu = g_object_new (XFPM_TYPE_CPU, NULL);
     return cpu;
 }
 

Modified: xfce4-power-manager/trunk/src/xfpm-cpu.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-cpu.h	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-cpu.h	2009-03-15 10:13:06 UTC (rev 6912)
@@ -23,10 +23,6 @@
 
 #include <glib-object.h>
 
-#include <xfconf/xfconf.h>
-
-#include "libxfpm/dbus-hal.h"
-
 G_BEGIN_DECLS
 
 #define XFPM_TYPE_CPU        (xfpm_cpu_get_type () )
@@ -49,8 +45,7 @@
 } XfpmCpuClass;
 
 GType          xfpm_cpu_get_type        (void) G_GNUC_CONST;
-XfpmCpu       *xfpm_cpu_new             (XfconfChannel *channel,
-					 DbusHal *bus);
+XfpmCpu       *xfpm_cpu_new             (void);
 
 void           xfpm_cpu_set_on_battery  (XfpmCpu *cpu,
 					 gboolean on_battery);

Modified: xfce4-power-manager/trunk/src/xfpm-dpms.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-dpms.c	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-dpms.c	2009-03-15 10:13:06 UTC (rev 6912)
@@ -49,6 +49,7 @@
 #include "libxfpm/xfpm-string.h"
 
 #include "xfpm-dpms.h"
+#include "xfpm-xfconf.h"
 #include "xfpm-config.h"
 
 #ifdef HAVE_DPMS
@@ -65,7 +66,7 @@
 
 struct XfpmDpmsPrivate
 {
-    XfconfChannel *channel;
+    XfpmXfconf    *conf;
     
     gboolean       dpms_capable;
     gboolean       dpms_enabled;
@@ -88,7 +89,6 @@
     
     object_class->finalize = xfpm_dpms_finalize;
 
-
     g_type_class_add_private(klass,sizeof(XfpmDpmsPrivate));
 }
 
@@ -99,6 +99,7 @@
     
     dpms->priv->dpms_capable = DPMSCapable (GDK_DISPLAY());
     
+    dpms->priv->conf = NULL;
 }
 
 static void
@@ -107,6 +108,9 @@
     XfpmDpms *dpms;
 
     dpms = XFPM_DPMS (object);
+    
+    if ( dpms->priv->conf )
+	g_object_unref (dpms->priv->conf);
 
     G_OBJECT_CLASS(xfpm_dpms_parent_class)->finalize(object);
 }
@@ -268,21 +272,21 @@
 xfpm_dpms_load_configuration (XfpmDpms *dpms)
 {
     dpms->priv->dpms_enabled =
-    	xfconf_channel_get_bool (dpms->priv->channel, DPMS_ENABLED_CFG, TRUE);
+    	xfconf_channel_get_bool (dpms->priv->conf->channel, DPMS_ENABLED_CFG, TRUE);
     
     dpms->priv->sleep_on_battery = 
-    	MIN( xfconf_channel_get_uint( dpms->priv->channel, ON_BATT_DPMS_SLEEP, 3) * 60, 3600);
+    	MIN( xfconf_channel_get_uint( dpms->priv->conf->channel, ON_BATT_DPMS_SLEEP, 3) * 60, 3600);
 
     dpms->priv->off_on_battery = 
-    	MIN(xfconf_channel_get_uint( dpms->priv->channel, ON_BATT_DPMS_OFF, 5) * 60, 3600);
+    	MIN(xfconf_channel_get_uint( dpms->priv->conf->channel, ON_BATT_DPMS_OFF, 5) * 60, 3600);
 	
     dpms->priv->sleep_on_ac = 
-    	MIN(xfconf_channel_get_uint( dpms->priv->channel, ON_AC_DPMS_SLEEP, 10) * 60, 3600);
+    	MIN(xfconf_channel_get_uint( dpms->priv->conf->channel, ON_AC_DPMS_SLEEP, 10) * 60, 3600);
     
     dpms->priv->off_on_ac = 
-    	MIN(xfconf_channel_get_uint( dpms->priv->channel, ON_AC_DPMS_OFF, 15) * 60, 3600);
+    	MIN(xfconf_channel_get_uint( dpms->priv->conf->channel, ON_AC_DPMS_OFF, 15) * 60, 3600);
 	
-    gchar *str = xfconf_channel_get_string (dpms->priv->channel, DPMS_SLEEP_MODE, "sleep");
+    gchar *str = xfconf_channel_get_string (dpms->priv->conf->channel, DPMS_SLEEP_MODE, "sleep");
     
     if ( xfpm_strequal (str, "sleep" ) )
     {
@@ -301,22 +305,21 @@
 }
 
 XfpmDpms *
-xfpm_dpms_new (XfconfChannel *channel)
+xfpm_dpms_new (void)
 {
     XfpmDpms *dpms = NULL;
     dpms = g_object_new (XFPM_TYPE_DPMS, NULL);
     
-    
     if ( !dpms->priv->dpms_capable )
     {
     	g_warning ("Display dpms incapable\n");
     	goto out;
     }
 
-    dpms->priv->channel = channel;
+    dpms->priv->conf = xfpm_xfconf_new ();
+    xfpm_dpms_load_configuration (dpms);
     
-    xfpm_dpms_load_configuration (dpms);
-    g_signal_connect (dpms->priv->channel, "property-changed",
+    g_signal_connect (dpms->priv->conf->channel, "property-changed",
 		      G_CALLBACK(xfpm_dpms_value_changed_cb), dpms);
 		      
     g_timeout_add_seconds ( CHECK_DPMS_TIMEOUT,

Modified: xfce4-power-manager/trunk/src/xfpm-dpms.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-dpms.h	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-dpms.h	2009-03-15 10:13:06 UTC (rev 6912)
@@ -53,7 +53,7 @@
 } XfpmDpmsClass;
 
 GType           xfpm_dpms_get_type        (void) G_GNUC_CONST;
-XfpmDpms       *xfpm_dpms_new             (XfconfChannel *channel);
+XfpmDpms       *xfpm_dpms_new             (void);
 
 void            xfpm_dpms_set_on_battery  (XfpmDpms *dpms,
 					   gboolean on_battery);

Modified: xfce4-power-manager/trunk/src/xfpm-engine.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-engine.c	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-engine.c	2009-03-15 10:13:06 UTC (rev 6912)
@@ -41,7 +41,7 @@
 #include <libxfce4util/libxfce4util.h>
 #include <xfconf/xfconf.h>
 
-#include "libxfpm/dbus-hal.h"
+#include "libxfpm/hal-iface.h"
 #include "libxfpm/xfpm-string.h"
 #include "libxfpm/xfpm-common.h"
 
@@ -51,6 +51,7 @@
 
 #include "xfpm-engine.h"
 #include "xfpm-supply.h"
+#include "xfpm-xfconf.h"
 #include "xfpm-cpu.h"
 #include "xfpm-network-manager.h"
 #include "xfpm-button-xf86.h"
@@ -70,14 +71,13 @@
 
 struct XfpmEnginePrivate
 {
-    DbusHal   	      *hbus;
-    XfconfChannel     *channel;
+    XfpmXfconf        *conf;
     XfpmSupply        *supply;
     XfpmCpu           *cpu;
     XfpmButtonXf86    *xf86_button;
     XfpmLidHal        *lid;
     XfpmBrightnessHal *brg_hal;
-    
+    HalIface          *iface;
 #ifdef HAVE_DPMS
     XfpmDpms          *dpms;
 #endif
@@ -94,7 +94,6 @@
     XfpmShutdownRequest lid_button_ac;
     XfpmShutdownRequest lid_button_battery;
     gboolean            lock_screen;
-    
 };
 
 G_DEFINE_TYPE(XfpmEngine, xfpm_engine, G_TYPE_OBJECT)
@@ -114,11 +113,11 @@
 {
     engine->priv = XFPM_ENGINE_GET_PRIVATE(engine);
     
-    engine->priv->hbus = dbus_hal_new ();
+    engine->priv->iface       = hal_iface_new ();
 
     engine->priv->button_timer= g_timer_new ();
 
-    engine->priv->channel     = NULL;
+    engine->priv->conf        = NULL;
     engine->priv->supply      = NULL;
 #ifdef HAVE_DPMS
     engine->priv->dpms        = NULL;
@@ -127,6 +126,8 @@
     engine->priv->xf86_button = NULL;
     engine->priv->lid         = NULL;
     engine->priv->brg_hal     = NULL;
+    
+    engine->priv->power_management = 0;
 }
 
 static void
@@ -136,8 +137,8 @@
 
     engine = XFPM_ENGINE(object);
     
-    if ( engine->priv->channel )
-    	g_object_unref (engine->priv->channel);
+    if ( engine->priv->conf )
+    	g_object_unref (engine->priv->conf);
 	
     if ( engine->priv->supply )
     	g_object_unref (engine->priv->supply);
@@ -152,8 +153,8 @@
     if ( engine->priv->lid)
     	g_object_unref(engine->priv->lid);
     
-    if ( engine->priv->hbus)
-    	g_object_unref(engine->priv->hbus);
+    if ( engine->priv->iface)
+    	g_object_unref(engine->priv->iface);
 
     if ( engine->priv->button_timer)
     	g_timer_destroy (engine->priv->button_timer);
@@ -164,6 +165,7 @@
 static void
 xfpm_engine_shutdown_request (XfpmEngine *engine, XfpmShutdownRequest shutdown)
 {
+    GError *error = NULL;
     const gchar *action = xfpm_int_to_shutdown_string (shutdown);
 	
     if ( xfpm_strequal(action, "Nothing") )
@@ -179,8 +181,13 @@
 	if ( shutdown != XFPM_DO_SHUTDOWN && engine->priv->lock_screen )
 	    xfpm_lock_screen ();
 	    
-	dbus_hal_shutdown (engine->priv->hbus, action, NULL);
+	hal_iface_shutdown (engine->priv->iface, action, &error);
 	xfpm_send_message_to_network_manager ("wake");
+	if ( error )
+	{
+	    g_warning ("%s", error->message);
+	    g_error_free (error);
+	}
     }
 }
 
@@ -262,14 +269,40 @@
 }
 
 static void
+xfpm_engine_check_hal_iface (XfpmEngine *engine)
+{
+    gboolean can_suspend, can_hibernate, caller, cpu;
+    
+    if (!hal_iface_connect (engine->priv->iface))
+	return;
+    
+    g_object_get (G_OBJECT(engine->priv->iface), 
+		  "caller-privilege", &caller,
+		  "can-suspend", &can_suspend,
+		  "can-hibernate", &can_hibernate,
+		  "cpu-freq-iface", &cpu,
+		  NULL);
+		  
+    if ( can_hibernate )
+	engine->priv->power_management |= SYSTEM_CAN_HIBERNATE;
+    if ( can_suspend )
+	engine->priv->power_management |= SYSTEM_CAN_SUSPEND;
+	
+    //FIXME: Show errors here
+   
+}
+
+static void
 xfpm_engine_load_all (XfpmEngine *engine)
 {
+    xfpm_engine_check_hal_iface (engine);
+    
 #ifdef HAVE_DPMS		      
-    engine->priv->dpms = xfpm_dpms_new (engine->priv->channel);
+    engine->priv->dpms = xfpm_dpms_new ();
 #endif
-    engine->priv->cpu = xfpm_cpu_new (engine->priv->channel, engine->priv->hbus);
+    engine->priv->cpu = xfpm_cpu_new ();
 
-    engine->priv->supply = xfpm_supply_new (engine->priv->hbus, engine->priv->channel);
+    engine->priv->supply = xfpm_supply_new (engine->priv->power_management);
 
     g_signal_connect (G_OBJECT(engine->priv->supply), "shutdown-request",
 		      G_CALLBACK (xfpm_engine_shutdown_request_battery_cb), engine);
@@ -297,7 +330,7 @@
     /*
      * Brightness HAL
      */
-    engine->priv->brg_hal = xfpm_brightness_hal_new (engine->priv->channel);
+    engine->priv->brg_hal = xfpm_brightness_hal_new ();
     
 }
 
@@ -307,46 +340,46 @@
     gchar *str;
     gint val;
     
-    str = xfconf_channel_get_string (engine->priv->channel, SLEEP_SWITCH_CFG, "Nothing");
+    str = xfconf_channel_get_string (engine->priv->conf->channel, SLEEP_SWITCH_CFG, "Nothing");
     val = xfpm_shutdown_string_to_int (str);
     
     if ( val == -1 || val == 3)
     {
 	g_warning ("Invalid value %s for property %s, using default\n", str, SLEEP_SWITCH_CFG);
 	engine->priv->sleep_button = XFPM_DO_NOTHING;
-	xfconf_channel_set_string (engine->priv->channel, SLEEP_SWITCH_CFG, "Nothing");
+	xfconf_channel_set_string (engine->priv->conf->channel, SLEEP_SWITCH_CFG, "Nothing");
     }
     else engine->priv->sleep_button = val;
     
     g_free (str);
     
-    str = xfconf_channel_get_string (engine->priv->channel, LID_SWITCH_ON_AC_CFG, "Nothing");
+    str = xfconf_channel_get_string (engine->priv->conf->channel, LID_SWITCH_ON_AC_CFG, "Nothing");
     val = xfpm_shutdown_string_to_int (str);
 
     if ( val == -1 || val == 3)
     {
 	g_warning ("Invalid value %s for property %s, using default\n", str, LID_SWITCH_ON_AC_CFG);
 	engine->priv->lid_button_ac = XFPM_DO_NOTHING;
-	xfconf_channel_set_string (engine->priv->channel, LID_SWITCH_ON_AC_CFG, "Nothing");
+	xfconf_channel_set_string (engine->priv->conf->channel, LID_SWITCH_ON_AC_CFG, "Nothing");
     }
     else engine->priv->lid_button_ac = val;
     
     g_free (str);
     
-    str = xfconf_channel_get_string (engine->priv->channel, LID_SWITCH_ON_BATTERY_CFG, "Nothing");
+    str = xfconf_channel_get_string (engine->priv->conf->channel, LID_SWITCH_ON_BATTERY_CFG, "Nothing");
     val = xfpm_shutdown_string_to_int (str);
     
     if ( val == -1 || val == 3)
     {
 	g_warning ("Invalid value %s for property %s, using default\n", str, LID_SWITCH_ON_BATTERY_CFG);
 	engine->priv->lid_button_battery = XFPM_DO_NOTHING;
-	xfconf_channel_set_string (engine->priv->channel, LID_SWITCH_ON_BATTERY_CFG, "Nothing");
+	xfconf_channel_set_string (engine->priv->conf->channel, LID_SWITCH_ON_BATTERY_CFG, "Nothing");
     }
     else engine->priv->lid_button_battery = val;
     
     g_free (str);
     
-    engine->priv->lock_screen = xfconf_channel_get_bool (engine->priv->channel, LOCK_SCREEN_ON_SLEEP, TRUE);
+    engine->priv->lock_screen = xfconf_channel_get_bool (engine->priv->conf->channel, LOCK_SCREEN_ON_SLEEP, TRUE);
 }
 
 static void
@@ -410,9 +443,9 @@
        	g_error_free (error);
     }	
     
-    engine->priv->channel   = xfconf_channel_new ("xfce4-power-manager");
+    engine->priv->conf   = xfpm_xfconf_new ();
     
-    g_signal_connect (engine->priv->channel, "property-changed",
+    g_signal_connect (engine->priv->conf->channel, "property-changed",
 		      G_CALLBACK(xfpm_engine_property_changed_cb), engine);
     
     xfpm_engine_load_configuration (engine);

Modified: xfce4-power-manager/trunk/src/xfpm-supply.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-supply.c	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-supply.c	2009-03-15 10:13:06 UTC (rev 6912)
@@ -31,6 +31,7 @@
 #include <libxfcegui4/libxfcegui4.h>
 
 #include "libxfpm/hal-power.h"
+#include "libxfpm/hal-iface.h"
 #include "libxfpm/xfpm-string.h"
 #include "libxfpm/xfpm-common.h"
 
@@ -40,6 +41,7 @@
 #include "xfpm-notify.h"
 #include "xfpm-enum.h"
 #include "xfpm-enum-types.h"
+#include "xfpm-xfconf.h"
 #include "xfpm-config.h"
 
 /* Init */
@@ -52,10 +54,9 @@
 
 struct XfpmSupplyPrivate
 {
-    DbusHal       *hbus;
     XfpmNotify    *notify;
     XfpmAdapter   *adapter;
-    XfconfChannel *channel;
+    XfpmXfconf    *conf;
     
     HalPower      *power;
     GHashTable    *hash;
@@ -137,8 +138,8 @@
     supply->priv->power   = hal_power_new ();
     supply->priv->hash    = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
     supply->priv->notify  = xfpm_notify_new ();
+    supply->priv->conf    = xfpm_xfconf_new ();
     
-    supply->priv->channel = NULL;
     supply->priv->adapter = NULL;
     supply->priv->adapter_found = FALSE;
 }
@@ -157,6 +158,9 @@
 	
     if ( supply->priv->notify )
     	g_object_unref (supply->priv->notify);
+	
+    if ( supply->priv->conf )
+    	g_object_unref (supply->priv->conf);
     
     G_OBJECT_CLASS(xfpm_supply_parent_class)->finalize(object);
 }
@@ -416,7 +420,7 @@
 	g_object_get (G_OBJECT(device), "type", &type, NULL);
     else
     {
-	g_critical ("Unable to get device type\n");
+	g_critical ("Unable to get device type");
 	return;
     }
     
@@ -563,14 +567,12 @@
 xfpm_supply_adapter_changed_cb (XfpmAdapter *adapter, gboolean present, XfpmSupply *supply )
 {
     if ( !supply->priv->adapter_found )
-    	g_critical ("Callback from the adapter object but no adapter found in the system\n");
+    	g_warning ("Callback from the adapter object but no adapter found in the system");
 	
-    
     supply->priv->adapter_present = present;
     xfpm_supply_set_adapter_presence (supply);
     
     g_signal_emit (G_OBJECT(supply), signals[ON_BATTERY], 0, !supply->priv->adapter_present);
-    
 }
 
 static XfpmBattery *
@@ -618,7 +620,7 @@
 	TRACE("Removing battery %s", udi);
 	g_object_unref(battery);
 	if (!g_hash_table_remove(supply->priv->hash, udi))
-		g_critical ("Unable to removed battery object from hash\n");
+		g_critical ("Unable to removed battery object from hash");
     }
     
 }
@@ -807,26 +809,26 @@
     gchar *str;
     gint val;
     
-    str = xfconf_channel_get_string (supply->priv->channel, CRITICAL_BATT_ACTION_CFG, "Nothing");
+    str = xfconf_channel_get_string (supply->priv->conf->channel, CRITICAL_BATT_ACTION_CFG, "Nothing");
     val = xfpm_shutdown_string_to_int (str);
     
     if ( val == -1 || val > 3 || val == 1)
     {
 	g_warning ("Invalid value %s for property %s, using default\n", str, CRITICAL_BATT_ACTION_CFG);
 	supply->priv->critical_action = XFPM_DO_NOTHING;
-	xfconf_channel_set_string ( supply->priv->channel, CRITICAL_BATT_ACTION_CFG, "Nothing");
+	xfconf_channel_set_string ( supply->priv->conf->channel, CRITICAL_BATT_ACTION_CFG, "Nothing");
     }
     else supply->priv->critical_action = val;
     
     g_free (str);
     
     supply->priv->show_icon =
-    	xfconf_channel_get_uint (supply->priv->channel, SHOW_TRAY_ICON_CFG, 0);
+    	xfconf_channel_get_uint (supply->priv->conf->channel, SHOW_TRAY_ICON_CFG, 0);
 	
     if ( supply->priv->show_icon < 0 || supply->priv->show_icon > 3 )
     {
 	g_warning ("Invalid value %d for property %s, using default\n", supply->priv->show_icon, SHOW_TRAY_ICON_CFG);
-	xfconf_channel_set_uint (supply->priv->channel, CRITICAL_BATT_ACTION_CFG, 0);
+	xfconf_channel_set_uint (supply->priv->conf->channel, CRITICAL_BATT_ACTION_CFG, 0);
     }
 }
 
@@ -834,20 +836,17 @@
  * Public functions
  */ 
 XfpmSupply *
-xfpm_supply_new (DbusHal *bus, XfconfChannel *channel )
+xfpm_supply_new (guint8 power_management_info)
 {
     XfpmSupply *supply = NULL;
     supply = g_object_new(XFPM_TYPE_SUPPLY,NULL);
     
-    supply->priv->hbus = bus;
-    supply->priv->channel    = channel;
     
-    g_object_get (G_OBJECT(supply->priv->hbus) , 
-		  "power-management-info", &supply->priv->power_management, NULL);
-
+    supply->priv->power_management = power_management_info;
+    
     xfpm_supply_load_configuration (supply);
       
-    g_signal_connect (channel, "property-changed", 
+    g_signal_connect (supply->priv->conf->channel, "property-changed", 
 		      G_CALLBACK(xfpm_supply_property_changed_cb), supply);
 
     xfpm_supply_monitor_start(supply);

Modified: xfce4-power-manager/trunk/src/xfpm-supply.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-supply.h	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-supply.h	2009-03-15 10:13:06 UTC (rev 6912)
@@ -23,11 +23,8 @@
 
 #include <glib-object.h>
 
-#include <xfconf/xfconf.h>
-
 #include "xfpm-enum.h"
 #include "xfpm-enum-glib.h"
-#include "dbus-hal.h"
 
 G_BEGIN_DECLS
 
@@ -63,8 +60,8 @@
 
 GType   	         xfpm_supply_get_type       (void) G_GNUC_CONST;
 
-XfpmSupply     	        *xfpm_supply_new            (DbusHal *bus,
-						     XfconfChannel *channel);
+XfpmSupply     	        *xfpm_supply_new            (guint8 power_management_info);
+						     
 G_END_DECLS
 
 #endif /* __XFPM_SUPPLY_H */

Modified: xfce4-power-manager/trunk/src/xfpm-tray-icon.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-tray-icon.h	2009-03-15 09:27:31 UTC (rev 6911)
+++ xfce4-power-manager/trunk/src/xfpm-tray-icon.h	2009-03-15 10:13:06 UTC (rev 6912)
@@ -47,14 +47,20 @@
 
 GType        	    xfpm_tray_icon_get_type        (void) G_GNUC_CONST;
 XfpmTrayIcon       *xfpm_tray_icon_new             (void);
+
 void                xfpm_tray_icon_set_icon        (XfpmTrayIcon *icon,
 						    const gchar *icon_name);
+						    
 void                xfpm_tray_icon_set_tooltip     (XfpmTrayIcon *icon,
 						    const gchar *tooltip);
+						    
 void                xfpm_tray_icon_set_visible     (XfpmTrayIcon *icon,
 						    gboolean visible);
+						    
 gboolean            xfpm_tray_icon_get_visible     (XfpmTrayIcon *icon);
+
 GtkStatusIcon      *xfpm_tray_icon_get_tray_icon   (XfpmTrayIcon *icon);
+
 const gchar        *xfpm_tray_icon_get_icon_name   (XfpmTrayIcon *icon);  
 
 G_END_DECLS

Added: xfce4-power-manager/trunk/src/xfpm-xfconf.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-xfconf.c	                        (rev 0)
+++ xfce4-power-manager/trunk/src/xfpm-xfconf.c	2009-03-15 10:13:06 UTC (rev 6912)
@@ -0,0 +1,81 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "xfpm-xfconf.h"
+
+/* Init */
+static void xfpm_xfconf_class_init (XfpmXfconfClass *klass);
+static void xfpm_xfconf_init       (XfpmXfconf *xfconf);
+static void xfpm_xfconf_finalize   (GObject *object);
+
+static gpointer xfpm_xfconf_object = NULL;
+
+G_DEFINE_TYPE(XfpmXfconf, xfpm_xfconf, G_TYPE_OBJECT)
+
+static void
+xfpm_xfconf_class_init (XfpmXfconfClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+    
+    object_class->finalize = xfpm_xfconf_finalize;
+}
+
+static void
+xfpm_xfconf_init (XfpmXfconf *xfconf)
+{
+    xfconf->channel = xfconf_channel_new ("xfce4-power-manager");
+}
+
+static void
+xfpm_xfconf_finalize(GObject *object)
+{
+    XfpmXfconf *xfconf;
+
+    xfconf = XFPM_XFCONF(object);
+    
+    if (xfconf->channel )
+	g_object_unref (xfconf->channel);
+    
+    G_OBJECT_CLASS(xfpm_xfconf_parent_class)->finalize(object);
+}
+
+XfpmXfconf *
+xfpm_xfconf_new(void)
+{
+    if ( xfpm_xfconf_object != NULL )
+    {
+	g_object_ref (xfpm_xfconf_object);
+    } 
+    else
+    {
+	xfpm_xfconf_object = g_object_new (XFPM_TYPE_XFCONF, NULL);
+	g_object_add_weak_pointer (xfpm_xfconf_object, &xfpm_xfconf_object);
+    }
+    
+    return XFPM_XFCONF (xfpm_xfconf_object);
+}

Added: xfce4-power-manager/trunk/src/xfpm-xfconf.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-xfconf.h	                        (rev 0)
+++ xfce4-power-manager/trunk/src/xfpm-xfconf.h	2009-03-15 10:13:06 UTC (rev 6912)
@@ -0,0 +1,53 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __XFPM_XFCONF_H
+#define __XFPM_XFCONF_H
+
+#include <glib-object.h>
+
+#include <xfconf/xfconf.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_XFCONF        (xfpm_xfconf_get_type () )
+#define XFPM_XFCONF(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_XFCONF, XfpmXfconf))
+#define XFPM_IS_XFCONF(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_XFCONF))
+
+
+typedef struct
+{
+    GObject		  parent;
+    XfconfChannel        *channel;
+    
+} XfpmXfconf;
+
+typedef struct
+{
+    GObjectClass	  parent_class;
+    
+} XfpmXfconfClass;
+
+GType        		  xfpm_xfconf_get_type        (void) G_GNUC_CONST;
+XfpmXfconf       	 *xfpm_xfconf_new             (void);
+
+G_END_DECLS
+
+#endif /* __XFPM_XFCONF_H */




More information about the Goodies-commits mailing list