From 1635e0d39902bb05ed5b67618cce2c04a689e67b Mon Sep 17 00:00:00 2001
From: Ali Abdallah <ali.slackware@gmail.com>
Date: Sun, 8 Mar 2009 19:49:10 +0000
Subject: [PATCH] Import of changes for what will be in time version 0.8

(Old svn revision: 6871)
---
 ChangeLog                                     |    5 +-
 Makefile.am                                   |   15 +-
 configure.ac.in                               |   39 +-
 libxfpm/Makefile.am                           |   44 +
 libxfpm/dbus-hal.c                            |  498 ++++++
 libxfpm/dbus-hal.h                            |   71 +
 libxfpm/hal-ctx.c                             |  377 ++++
 libxfpm/hal-ctx.h                             |   96 ++
 libxfpm/hal-device.c                          |  620 +++++++
 libxfpm/hal-device.h                          |   55 +
 libxfpm/hal-enum.h                            |   38 +
 libxfpm/hal-power.c                           |  305 ++++
 libxfpm/hal-power.h                           |   60 +
 libxfpm/xfpm-common.c                         |  138 ++
 libxfpm/xfpm-common.h                         |   42 +
 libxfpm/xfpm-dbus.c                           |   89 +
 .../xfpm-dbus.h                               |   30 +-
 {src => libxfpm}/xfpm-popups.c                |    0
 {src => libxfpm}/xfpm-popups.h                |    0
 {src => libxfpm}/xfpm-string.c                |    0
 {src => libxfpm}/xfpm-string.h                |    0
 panel-plugins/Makefile.am                     |    1 +
 panel-plugins/brightness/Makefile.am          |   39 +
 panel-plugins/brightness/main.c               |   41 +
 .../xfce4-brightness-plugin.desktop.in.in     |    5 +
 settings/Makefile.am                          |   68 +
 .../xfce4-power-manager.desktop.in            |    0
 {src => settings}/xfpm-settings-main.c        |   79 +-
 settings/xfpm-settings.c                      |  655 +++++++
 settings/xfpm-settings.glade                  |  774 +++++++++
 {src => settings}/xfpm-settings.h             |   18 +-
 src/Makefile.am                               |  144 +-
 src/org.xfce.Power.Manager.xml                |    6 +-
 src/xfpm-ac-adapter.c                         |  496 ------
 src/xfpm-ac-adapter.h                         |   61 -
 src/xfpm-adapter.c                            |  167 ++
 src/xfpm-adapter.h                            |   62 +
 src/xfpm-battery-icon.c                       |  626 -------
 src/xfpm-battery-icon.h                       |   88 -
 src/xfpm-battery-info.c                       |  217 +++
 src/xfpm-battery-info.h                       |   35 +
 src/xfpm-battery.c                            | 1512 ++++-------------
 src/xfpm-battery.h                            |   71 +-
 src/xfpm-brightness-hal.c                     |   90 +
 src/xfpm-brightness-hal.h                     |   52 +
 src/xfpm-button-xf86.c                        |  241 +++
 src/xfpm-button-xf86.h                        |   57 +
 src/xfpm-button.c                             |  658 -------
 src/xfpm-button.h                             |   66 -
 src/xfpm-common.c                             |  152 --
 src/{xfpm-common.h => xfpm-config.h}          |   65 +-
 src/xfpm-cpu.c                                |  471 ++---
 src/xfpm-cpu.h                                |   40 +-
 src/xfpm-dbus-messages.c                      |  162 --
 src/xfpm-debug.h                              |   37 -
 src/xfpm-dpms-spins.c                         |  385 -----
 src/xfpm-dpms-spins.h                         |   70 -
 src/xfpm-dpms.c                               |  413 ++---
 src/xfpm-dpms.h                               |   49 +-
 src/xfpm-driver.c                             | 1208 -------------
 src/xfpm-driver.h                             |   68 -
 src/xfpm-engine.c                             |  389 +++++
 src/xfpm-engine.h                             |   52 +
 src/xfpm-enum-glib.h                          |   70 +
 src/xfpm-enum.h                               |   59 +
 src/xfpm-enums.h                              |   59 -
 src/xfpm-hal.c                                | 1128 ------------
 src/xfpm-hal.h                                |  146 --
 src/xfpm-lcd-brightness.c                     |  510 ------
 src/xfpm-lcd-brightness.h                     |   56 -
 src/xfpm-lid-hal.c                            |  206 +++
 src/xfpm-lid-hal.h                            |   55 +
 src/xfpm-main.c                               |  241 ++-
 src/xfpm-manager.c                            |  209 +++
 src/xfpm-manager.h                            |   55 +
 src/xfpm-marshal.list                         |    9 +-
 src/xfpm-network-manager.c                    |   62 +
 src/xfpm-network-manager.h                    |   30 +
 src/xfpm-notify.c                             |  195 ++-
 src/xfpm-notify.h                             |   77 +-
 src/xfpm-settings.c                           | 1324 ---------------
 src/xfpm-spin-button.c                        |  312 ----
 src/xfpm-spin-button.h                        |   61 -
 src/xfpm-supply.c                             |  605 +++++++
 src/xfpm-supply.h                             |   63 +
 src/xfpm-tray-icon.c                          |  178 ++
 src/xfpm-tray-icon.h                          |   62 +
 87 files changed, 8138 insertions(+), 10046 deletions(-)
 create mode 100644 libxfpm/Makefile.am
 create mode 100644 libxfpm/dbus-hal.c
 create mode 100644 libxfpm/dbus-hal.h
 create mode 100644 libxfpm/hal-ctx.c
 create mode 100644 libxfpm/hal-ctx.h
 create mode 100644 libxfpm/hal-device.c
 create mode 100644 libxfpm/hal-device.h
 create mode 100644 libxfpm/hal-enum.h
 create mode 100644 libxfpm/hal-power.c
 create mode 100644 libxfpm/hal-power.h
 create mode 100644 libxfpm/xfpm-common.c
 create mode 100644 libxfpm/xfpm-common.h
 create mode 100644 libxfpm/xfpm-dbus.c
 rename src/xfpm-dbus-messages.h => libxfpm/xfpm-dbus.h (50%)
 rename {src => libxfpm}/xfpm-popups.c (100%)
 rename {src => libxfpm}/xfpm-popups.h (100%)
 rename {src => libxfpm}/xfpm-string.c (100%)
 rename {src => libxfpm}/xfpm-string.h (100%)
 create mode 100644 panel-plugins/Makefile.am
 create mode 100644 panel-plugins/brightness/Makefile.am
 create mode 100644 panel-plugins/brightness/main.c
 create mode 100644 panel-plugins/brightness/xfce4-brightness-plugin.desktop.in.in
 create mode 100644 settings/Makefile.am
 rename {src => settings}/xfce4-power-manager.desktop.in (100%)
 rename {src => settings}/xfpm-settings-main.c (62%)
 create mode 100644 settings/xfpm-settings.c
 create mode 100644 settings/xfpm-settings.glade
 rename {src => settings}/xfpm-settings.h (56%)
 delete mode 100644 src/xfpm-ac-adapter.c
 delete mode 100644 src/xfpm-ac-adapter.h
 create mode 100644 src/xfpm-adapter.c
 create mode 100644 src/xfpm-adapter.h
 delete mode 100644 src/xfpm-battery-icon.c
 delete mode 100644 src/xfpm-battery-icon.h
 create mode 100644 src/xfpm-battery-info.c
 create mode 100644 src/xfpm-battery-info.h
 create mode 100644 src/xfpm-brightness-hal.c
 create mode 100644 src/xfpm-brightness-hal.h
 create mode 100644 src/xfpm-button-xf86.c
 create mode 100644 src/xfpm-button-xf86.h
 delete mode 100644 src/xfpm-button.c
 delete mode 100644 src/xfpm-button.h
 delete mode 100644 src/xfpm-common.c
 rename src/{xfpm-common.h => xfpm-config.h} (54%)
 delete mode 100644 src/xfpm-dbus-messages.c
 delete mode 100644 src/xfpm-debug.h
 delete mode 100644 src/xfpm-dpms-spins.c
 delete mode 100644 src/xfpm-dpms-spins.h
 delete mode 100644 src/xfpm-driver.c
 delete mode 100644 src/xfpm-driver.h
 create mode 100644 src/xfpm-engine.c
 create mode 100644 src/xfpm-engine.h
 create mode 100644 src/xfpm-enum-glib.h
 create mode 100644 src/xfpm-enum.h
 delete mode 100644 src/xfpm-enums.h
 delete mode 100644 src/xfpm-hal.c
 delete mode 100644 src/xfpm-hal.h
 delete mode 100644 src/xfpm-lcd-brightness.c
 delete mode 100644 src/xfpm-lcd-brightness.h
 create mode 100644 src/xfpm-lid-hal.c
 create mode 100644 src/xfpm-lid-hal.h
 create mode 100644 src/xfpm-manager.c
 create mode 100644 src/xfpm-manager.h
 create mode 100644 src/xfpm-network-manager.c
 create mode 100644 src/xfpm-network-manager.h
 delete mode 100644 src/xfpm-settings.c
 delete mode 100644 src/xfpm-spin-button.c
 delete mode 100644 src/xfpm-spin-button.h
 create mode 100644 src/xfpm-supply.c
 create mode 100644 src/xfpm-supply.h
 create mode 100644 src/xfpm-tray-icon.c
 create mode 100644 src/xfpm-tray-icon.h

diff --git a/ChangeLog b/ChangeLog
index 802923f4..11fea524 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,6 @@
-2009-03-02 14:30 Ali
-	
-	*: Tag 0.6.4, removed the panel plugin for now
 
+2009-03-08 20:48 Ali aliov@xfce.org 
+	 * : Import of changes for what will be in time version 0.8
 2009-02-18 11:00 Ali
 
 	*: Added a panel brightness plugin directory,
diff --git a/Makefile.am b/Makefile.am
index 57bc5ec4..acd4bec7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,9 +1,16 @@
 @SET_MAKE@
 
-SUBDIRS =        \
-	src 	     \
-	data         \
-	po           \
+if BUILD_PANEL_PLUGINS
+plugins_dir = panel-plugins
+endif
+
+SUBDIRS =        	\
+	libxfpm		\
+	src		\
+	settings	\
+	$(plugins_dir)	\
+	data         	\
+	po           	\
 	doc
 
 EXTRA_DIST = \
diff --git a/configure.ac.in b/configure.ac.in
index 4e4ff5c2..084d8a3c 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -1,9 +1,9 @@
 m4_define([intltool_minimum_version], [0.31])
 m4_define([xfpm_version_major],  [0])
-m4_define([xfpm_version_minor],  [6])
-m4_define([xfpm_version_micro],  [4])
+m4_define([xfpm_version_minor],  [8])
+m4_define([xfpm_version_micro],  [0])
 m4_define([xfpm_version_build],  [r@REVISION@])
-m4_define([xfpm_version_tag],[])
+m4_define([xfpm_version_tag],[svn])
 m4_define([xfpm_version], [xfpm_version_major().xfpm_version_minor().xfpm_version_micro()ifelse(xfpm_version_tag(), [svn], [xfpm_version_tag().xfpm_version_build()], [xfpm_version_tag()])])
 
 AC_INIT([xfce4-power-manager], [xfpm_version], [http://bugzilla.xfce.org/])
@@ -25,9 +25,16 @@ AC_MINIX
 # ===================================================== #
 AC_PROG_CC
 AM_PROG_CC_C_O
+AC_PROG_LD
 AC_PROG_INSTALL
 AC_PROG_INTLTOOL([intltool_minimum_version], [no-xml])
 
+# ===================================================== #
+#               Initialize libtool                      #
+# ===================================================== #
+AC_DISABLE_STATIC
+AC_PROG_LIBTOOL
+
 # ==================================================== #
 #   Check for headers needed for standard interfaces   #
 # ==================================================== #
@@ -52,6 +59,8 @@ m4_define([hal_minimum_version], [0.5.6])
 m4_define([xfconf_minimum_version], [4.5.90])
 m4_define([libxfcegui4_minimum_version],[4.4.1])
 m4_define([libxfce4util_minimum_version],[4.4.1])
+m4_define([libxfce4panel_minimum_version],[4.4.0])
+m4_define([glade_minimum_version], [2.0.0])
 m4_define([dbus_glib_minimum_version], [0.70])
 m4_define([libnotify_minimum_version], [0.4.1])
 
@@ -64,6 +73,7 @@ XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [dbus_glib_minimum_version])
 XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0],[xfconf_minimum_version])
 XDT_CHECK_PACKAGE([LIBXFCE4GUI], [libxfcegui4-1.0],[libxfcegui4_minimum_version])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0],[libxfce4util_minimum_version])
+XDT_CHECK_PACKAGE([LIBGLADE], [libglade-2.0],[glade_minimum_version])
 
 #=======================================================#
 #           Check for DPMS support                      #
@@ -92,6 +102,24 @@ XDT_CHECK_OPTIONAL_PACKAGE([LIBNOTIFY],
                        [libnotify], 
                        [libnotify library], [yes])
 
+#=======================================================#
+#                 Panel plugins ?                       #
+#=======================================================#
+AC_ARG_ENABLE([panel_plugins],
+	[AC_HELP_STRING([--disable-panel-plugins],
+		[Do not build panel plugins (default=enabled)])],
+	[ac_cv_enable_panel_plugins=$enableval],
+	[ac_cv_enable_panel_plugins=yes])
+if test "x$ac_cv_enable_panel_plugins" = "xno"; then
+	build_panel_plugins="no"
+else
+	build_panel_plugins="yes"
+	XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0],
+		[libxfce4panel_minimum_version])
+fi
+AM_CONDITIONAL([BUILD_PANEL_PLUGINS], [test "x$build_panel_plugins" = "xyes"])
+
+
 #=======================================================#
 #              Check for debugging support              #
 #=======================================================#
@@ -100,7 +128,11 @@ XDT_FEATURE_DEBUG
 
 AC_OUTPUT([
 Makefile
+libxfpm/Makefile
 src/Makefile
+settings/Makefile
+panel-plugins/Makefile
+panel-plugins/brightness/Makefile
 data/Makefile
 data/icons/Makefile
 data/icons/scalable/Makefile
@@ -118,6 +150,7 @@ echo 	 "   Build Configuration"
 echo 
 echo "   DPMS         support    $have_dpms      "
 echo "   Notification support    $LIBNOTIFY_FOUND"
+echo "   Build panel  plugins    $build_panel_plugins"
 echo "   Debug        support    $enable_debug   "
 echo
 echo "----------------------------------------"  
diff --git a/libxfpm/Makefile.am b/libxfpm/Makefile.am
new file mode 100644
index 00000000..f4fc3069
--- /dev/null
+++ b/libxfpm/Makefile.am
@@ -0,0 +1,44 @@
+noinst_LTLIBRARIES = 			\
+	libxfpmhal.la			\
+	libxfpmdbus.la			\
+	libxfpmcommon.la
+
+libxfpmhal_la_SOURCES =			\
+	hal-ctx.c			\
+	hal-ctx.h			\
+	hal-power.c			\
+	hal-power.h			\
+	hal-device.c			\
+	hal-device.h
+
+libxfpmhal_la_CFLAGS =			\
+	$(HAL_CFLAGS)			\
+	$(GLIB_CFLAGS)			\
+	$(DBUS_GLIB_CFLAGS)
+
+libxfpmdbus_la_SOURCES =		\
+	dbus-hal.c			\
+	dbus-hal.h
+
+
+libxfpmdbus_la_CFLAGS =			\
+	$(GLIB_CFLAGS)			\
+	$(DBUS_CFLAGS)			\
+	$(DBUS_GLIB_CFLAGS)
+
+
+libxfpmcommon_la_SOURCES =      	\
+        xfpm-string.c           	\
+        xfpm-string.h           	\
+        xfpm-dbus.c             	\
+        xfpm-dbus.h             	\
+        xfpm-popups.c           	\
+        xfpm-popups.h           	\
+        xfpm-common.c           	\
+        xfpm-common.h
+
+libxfpmcommon_la_CFLAGS =       	\
+        $(GTK_CFLAGS)           	\
+        $(GLIB_CFLAGS)          	\
+        $(DBUS_CFLAGS)			\
+	$(LIBXFCE4UTIL_CFLAGS)
\ No newline at end of file
diff --git a/libxfpm/dbus-hal.c b/libxfpm/dbus-hal.c
new file mode 100644
index 00000000..d8cb2d4c
--- /dev/null
+++ b/libxfpm/dbus-hal.c
@@ -0,0 +1,498 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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
+ */
+
+#include <stdio.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <malloc.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include <glib.h>
+
+#include "dbus-hal.h"
+#include "xfpm-string.h"
+
+/* Init */
+static void dbus_hal_class_init (DbusHalClass *klass);
+static void dbus_hal_init       (DbusHal *bus);
+static void dbus_hal_finalize   (GObject *object);
+
+static void dbus_hal_get_property(GObject *object,
+                                         guint prop_id,
+                                         GValue *value,
+                                         GParamSpec *pspec);
+
+#define DBUS_HAL_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), DBUS_TYPE_HAL, DbusHalPrivate))
+
+struct DbusHalPrivate
+{
+    DBusGConnection *system_bus;
+    
+    gboolean         connected;
+    
+    gboolean         can_suspend;
+    gboolean         can_hibernate;
+    gboolean         power_management;
+    
+    gboolean         cpu_freq_can_be_used;
+    
+    guint            power_management_info;
+};
+
+enum
+{
+    PROP_0,
+    PROP_POWER_MANAGEMENT_INFO,
+};
+
+G_DEFINE_TYPE(DbusHal, dbus_hal, G_TYPE_OBJECT)
+
+static void
+dbus_hal_class_init(DbusHalClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->get_property = dbus_hal_get_property;
+
+    g_object_class_install_property(object_class,
+                                    PROP_POWER_MANAGEMENT_INFO,
+                                    g_param_spec_uint("power-management-info",
+                                                      NULL, NULL,
+                                                      0,
+						      2,
+						      0,
+                                                      G_PARAM_READABLE));
+
+    object_class->finalize = dbus_hal_finalize;
+
+    g_type_class_add_private(klass,sizeof(DbusHalPrivate));
+}
+
+static void
+dbus_hal_init(DbusHal *bus)
+{
+    bus->priv = DBUS_HAL_GET_PRIVATE(bus);
+    
+    bus->priv->system_bus    = NULL;
+     
+    bus->priv->can_suspend      = FALSE;
+    bus->priv->can_hibernate    = FALSE;
+    bus->priv->power_management = FALSE;
+    
+    bus->priv->power_management_info = 0;
+}
+
+static void dbus_hal_get_property (GObject *object,
+                                          guint prop_id,
+                                          GValue *value,
+                                          GParamSpec *pspec)
+{
+    DbusHal *bus;
+    bus = DBUS_HAL (object);
+    
+    switch (prop_id)
+    {
+    	case PROP_POWER_MANAGEMENT_INFO:
+                g_value_set_uint (value, bus->priv->power_management_info);
+                break;	
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
+    }
+    
+}
+
+static void
+dbus_hal_finalize(GObject *object)
+{
+    DbusHal *bus;
+
+    bus = DBUS_HAL(object);
+    
+    if ( bus->priv->system_bus )
+    	dbus_g_connection_unref (bus->priv->system_bus);
+	
+    G_OBJECT_CLASS(dbus_hal_parent_class)->finalize(object);
+}
+
+static gboolean
+dbus_hal_check_interface (DbusHal *bus, 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(bus->priv->system_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
+dbus_hal_get_bool_property (DbusHal *bus, const gchar *property)
+{
+    DBusMessage *message, *reply = NULL;
+    DBusError error;
+    
+    gboolean property_value;
+    
+    message = dbus_message_new_method_call ("org.freedesktop.Hal",
+					    "/org/freedesktop/Hal/devices/computer",
+					    "org.freedesktop.Hal.Device",
+					    "GetPropertyBoolean");
+    if (!message)
+	return FALSE;
+	    
+    dbus_error_init (&error);
+    
+    dbus_message_append_args (message, 
+			      DBUS_TYPE_STRING, &property, 
+			      DBUS_TYPE_INVALID);
+    
+    reply = 
+    	dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection(bus->priv->system_bus),
+						   message, 2000, &error);
+    dbus_message_unref (message);
+    
+     if ( dbus_error_is_set(&error) )
+    {
+	g_critical("%s", error.message);
+	dbus_error_free (&error);
+	return FALSE;
+    }    
+    
+    if ( !reply ) return FALSE;
+    
+    dbus_message_get_args (reply, NULL,
+    			   DBUS_TYPE_BOOLEAN, &property_value,
+			   DBUS_TYPE_INVALID);
+    
+   return property_value;
+}
+
+static void
+dbus_hal_check (DbusHal *bus)
+{
+    bus->priv->can_suspend = dbus_hal_get_bool_property (bus, "power_management.can_suspend");
+    bus->priv->can_hibernate = dbus_hal_get_bool_property (bus, "power_management.can_hibernate");
+    
+    bus->priv->power_management = 
+    	dbus_hal_check_interface (bus, "org.freedesktop.Hal.Device.SystemPowerManagement");
+    
+    bus->priv->cpu_freq_can_be_used =
+    	dbus_hal_check_interface (bus, "org.freedesktop.Hal.Device.CPUFreq");
+	
+}
+
+DbusHal *
+dbus_hal_new(void)
+{
+    DbusHal *bus = NULL;
+    bus = g_object_new (DBUS_TYPE_HAL, NULL);
+    
+    GError *error = NULL;
+    bus->priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+    
+    if ( error )
+    {
+    	g_critical("Unable to connect to the system dbus: %s", error->message);
+	bus->priv->connected = FALSE;
+	goto out;
+    }
+    bus->priv->connected = TRUE;
+    
+    dbus_hal_check (bus);
+    
+    if ( bus->priv->power_management && bus->priv->can_hibernate )
+    	 bus->priv->power_management_info |= SYSTEM_CAN_HIBERNATE;
+	
+    if ( bus->priv->power_management && bus->priv->can_suspend )
+    	 bus->priv->power_management_info |= SYSTEM_CAN_SUSPEND;
+    
+out:
+    return bus;
+}
+
+gboolean dbus_hal_shutdown (DbusHal *bus, const gchar *shutdown, GError **gerror)
+{
+    g_return_val_if_fail (DBUS_IS_HAL(bus), FALSE);
+    g_return_val_if_fail (bus->priv->connected, 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(bus->priv->system_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 **dbus_hal_get_cpu_available_governors (DbusHal *bus, GError **gerror)
+{
+    g_return_val_if_fail (DBUS_IS_HAL(bus), NULL);
+    g_return_val_if_fail (bus->priv->connected, NULL);
+    g_return_val_if_fail (bus->priv->cpu_freq_can_be_used == TRUE, NULL);
+    
+    DBusMessage *message, *reply = NULL;
+    DBusError error;
+    char **govs = NULL;
+    gint dummy = 0;
+    
+    message = dbus_message_new_method_call ("org.freedesktop.Hal",
+					    "/org/freedesktop/Hal/devices/computer",
+					    "org.freedesktop.Hal.Device.CPUFreq",
+					    "GetCPUFreqAvailableGovernors");
+					    
+    if ( !message )
+    {
+	g_set_error ( gerror, 0, 0, "Out of memory");
+	return NULL;
+    }
+    
+    dbus_error_init(&error);
+    reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection(bus->priv->system_bus) ,
+						       message,
+						       -1,
+						       &error);
+    dbus_message_unref (message);
+    
+    if ( dbus_error_is_set (&error) )
+    {
+         dbus_set_g_error (gerror, &error);
+         dbus_error_free (&error);
+         return FALSE;
+    }
+    
+    if ( !reply ) 
+    {
+        g_critical("No reply from HAL daemon to get available cpu governors\n");
+	
+        return NULL;
+    }
+    
+    dbus_message_get_args(reply,NULL,
+                          DBUS_TYPE_ARRAY,
+			  DBUS_TYPE_STRING,
+                          &govs,&dummy,
+			  DBUS_TYPE_INVALID,
+                          DBUS_TYPE_INVALID);
+			  
+    dbus_message_unref(reply);
+    
+    return govs;
+}
+
+gchar* dbus_hal_get_cpu_current_governor (DbusHal *bus, GError **gerror)
+{
+    g_return_val_if_fail (DBUS_IS_HAL(bus), FALSE);
+    g_return_val_if_fail (bus->priv->connected, FALSE);
+    g_return_val_if_fail (bus->priv->cpu_freq_can_be_used == TRUE, FALSE);
+    
+    DBusMessage *message, *reply = NULL;
+    DBusError error;
+    gchar *gov = NULL;
+    
+    message = dbus_message_new_method_call ("org.freedesktop.Hal",
+					    "/org/freedesktop/Hal/devices/computer",
+					    "org.freedesktop.Hal.Device.CPUFreq",
+					    "GetCPUFreqGovernor");
+    
+    if ( !message )
+    {
+    	g_set_error ( gerror, 0, 0, "Out of memory");
+	return NULL;
+    }
+    
+    dbus_error_init(&error);
+    reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection(bus->priv->system_bus) ,
+						       message,
+						       -1,
+						       &error);
+    dbus_message_unref (message);
+    
+    if ( dbus_error_is_set (&error) )
+    {
+         dbus_set_g_error (gerror, &error);
+         dbus_error_free (&error);
+         return NULL;
+    }
+    
+    if ( !reply ) 
+    {
+        g_critical("No reply from HAL daemon to get available cpu governors\n");
+        return NULL;
+    }
+    
+    dbus_message_get_args (reply, NULL, 
+    			   DBUS_TYPE_STRING,
+			   &gov,
+			   DBUS_TYPE_INVALID);
+			   
+    dbus_message_unref (reply);
+    
+    return gov;
+}
+
+gboolean dbus_hal_set_cpu_governor (DbusHal *bus, const gchar *governor, GError **gerror)
+{
+    g_return_val_if_fail (DBUS_IS_HAL(bus), FALSE);
+    g_return_val_if_fail (bus->priv->connected, FALSE);
+    g_return_val_if_fail (bus->priv->cpu_freq_can_be_used == TRUE, FALSE);
+    
+    DBusMessage *message, *reply = NULL;
+    DBusError error;
+    
+    message = dbus_message_new_method_call ("org.freedesktop.Hal",
+					    "/org/freedesktop/Hal/devices/computer",
+					    "org.freedesktop.Hal.Device.CPUFreq",
+					    "SetCPUFreqGovernor");
+    
+    if ( !message )
+    {
+    	g_set_error ( gerror, 0, 0, "Out of memory");
+	return FALSE;
+    }
+    
+    dbus_message_append_args (message, DBUS_TYPE_STRING, &governor, DBUS_TYPE_INVALID);
+    
+    dbus_error_init(&error);
+    
+    reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (bus->priv->system_bus), 
+						       message, 
+						       -1, 
+						       &error);
+    
+    dbus_message_unref(message);
+    
+    if ( dbus_error_is_set(&error) )
+    {
+        dbus_set_g_error(gerror,&error);
+        dbus_error_free(&error);
+        return FALSE;
+    }
+
+    if ( !reply ) 
+    {
+        g_critical("No reply from HAL daemon to set cpu governor");
+        return FALSE;
+    }
+    
+    dbus_message_unref(reply);
+    
+    return TRUE;
+}
+
+void dbus_hal_free_string_array (char **array)
+{
+    if ( !array )
+    	return;
+	
+    dbus_free_string_array (array);
+}
diff --git a/libxfpm/dbus-hal.h b/libxfpm/dbus-hal.h
new file mode 100644
index 00000000..f9aaa7aa
--- /dev/null
+++ b/libxfpm/dbus-hal.h
@@ -0,0 +1,71 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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 __DBUS_HAL_H
+#define __DBUS_HAL_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define DBUS_TYPE_HAL        	    (dbus_hal_get_type () )
+#define DBUS_HAL(o)          	    (G_TYPE_CHECK_INSTANCE_CAST((o), DBUS_TYPE_HAL, DbusHal))
+#define DBUS_IS_HAL(o)              (G_TYPE_CHECK_INSTANCE_TYPE((o), DBUS_TYPE_HAL))
+
+typedef enum
+{
+    SYSTEM_CAN_HIBERNATE         =  (1<<0),
+    SYSTEM_CAN_SUSPEND           =  (1<<1),
+    
+} SystemPowerManagement;
+
+typedef struct DbusHalPrivate DbusHalPrivate;
+
+typedef struct
+{
+    GObject		  parent;
+    DbusHalPrivate	 *priv;
+    
+} DbusHal;
+
+typedef struct
+{
+    GObjectClass          parent_class;
+	
+} DbusHalClass;
+
+GType                     dbus_hal_get_type        	  	(void) G_GNUC_CONST;
+DbusHal       		 *dbus_hal_new             	  	(void);
+gboolean             	  dbus_hal_shutdown        	  	(DbusHal *bus,
+						      	   	 const gchar *shutdown,
+							   	 GError **error);
+gchar   	   	**dbus_hal_get_cpu_available_governors  (DbusHal *bus, 
+							       	 GError **gerror);
+
+gchar       	         *dbus_hal_get_cpu_current_governor 	(DbusHal *bus, 
+							   	 GError **gerror);
+
+gboolean 	          dbus_hal_set_cpu_governor 	  	(DbusHal *bus,
+								 const gchar *governor,
+							   	 GError **gerror);
+void                      dbus_hal_free_string_array            (char **array);
+G_END_DECLS
+
+#endif /* __DBUS_HAL_H */
diff --git a/libxfpm/hal-ctx.c b/libxfpm/hal-ctx.c
new file mode 100644
index 00000000..de47f276
--- /dev/null
+++ b/libxfpm/hal-ctx.c
@@ -0,0 +1,377 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "hal-ctx.h"
+
+/* Init */
+static void hal_ctx_class_init (HalCtxClass *klass);
+static void hal_ctx_init       (HalCtx *ctx);
+static void hal_ctx_finalize   (GObject *object);
+
+#define HAL_CTX_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), HAL_TYPE_CTX, HalCtxPrivate))
+
+struct HalCtxPrivate
+{
+    DBusGConnection *bus;
+    LibHalContext   *context;
+    
+    gboolean         connected;
+};
+
+G_DEFINE_TYPE(HalCtx, hal_ctx, G_TYPE_OBJECT)
+
+static void
+hal_ctx_class_init(HalCtxClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->finalize = hal_ctx_finalize;
+
+    g_type_class_add_private(klass,sizeof(HalCtxPrivate));
+}
+
+static void
+hal_ctx_init(HalCtx *ctx)
+{
+    ctx->priv = HAL_CTX_GET_PRIVATE(ctx);
+    
+    ctx->priv->bus       = NULL;
+    ctx->priv->context   = NULL;
+    ctx->priv->connected = FALSE;
+}
+
+static void
+hal_ctx_finalize(GObject *object)
+{
+    HalCtx *ctx;
+
+    ctx = HAL_CTX(object);
+    
+    if ( ctx->priv->context )
+    	libhal_ctx_free(ctx->priv->context);
+	
+    if ( ctx->priv->bus)
+    	dbus_g_connection_unref(ctx->priv->bus);
+
+    G_OBJECT_CLASS(hal_ctx_parent_class)->finalize(object);
+}
+
+HalCtx *
+hal_ctx_new(void)
+{
+    HalCtx *ctx = NULL;
+    ctx = g_object_new(HAL_TYPE_CTX,NULL);
+    return ctx;
+}
+
+/*
+ * Set HAL context assosiated with a DBus connection
+ */
+gboolean hal_ctx_connect (HalCtx *ctx)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), FALSE);
+
+    GError *gerror = NULL;
+    DBusError error;
+    
+    ctx->priv->bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &gerror);
+
+    if ( gerror )
+    {
+	g_critical("Error connecting to the system bus: %s\n", gerror->message);
+	g_error_free(gerror);
+	return FALSE;
+    }
+    
+    ctx->priv->context = libhal_ctx_new();
+    libhal_ctx_set_dbus_connection(ctx->priv->context, 
+				   dbus_g_connection_get_connection(ctx->priv->bus));
+    
+    dbus_error_init(&error);
+    libhal_ctx_init(ctx->priv->context, &error);
+    
+    if ( dbus_error_is_set(&error) )
+    {
+	g_critical("Hal initialization failed: %s", error.message);
+	dbus_error_free(&error);
+	return FALSE;
+    }
+    
+    ctx->priv->connected = TRUE;
+    
+    return TRUE;
+}
+
+/*
+ * 
+ */
+void hal_ctx_set_user_data (HalCtx *ctx, void *data)
+{
+    g_return_if_fail(HAL_IS_CTX(ctx));
+    g_return_if_fail(ctx->priv->connected == TRUE);
+    
+    libhal_ctx_set_user_data(ctx->priv->context, data);
+}
+
+/*
+ * Add a device-added callback
+ */
+void hal_ctx_set_device_added_callback (HalCtx *ctx, LibHalDeviceAdded callback)
+{
+    g_return_if_fail(HAL_IS_CTX(ctx));
+    g_return_if_fail(ctx->priv->connected == TRUE);
+    
+    libhal_ctx_set_device_added(ctx->priv->context, callback);
+}
+
+/*
+ * Add a device-removed callback
+ */
+void hal_ctx_set_device_removed_callback (HalCtx *ctx, LibHalDeviceRemoved callback)
+{
+    g_return_if_fail(HAL_IS_CTX(ctx));
+    g_return_if_fail(ctx->priv->connected == TRUE);
+    
+    libhal_ctx_set_device_removed(ctx->priv->context, callback);
+}
+
+/*
+ * Add a property-changed callback
+ */
+void hal_ctx_set_device_property_callback (HalCtx *ctx, LibHalDevicePropertyModified callback)
+{
+    g_return_if_fail(HAL_IS_CTX(ctx));
+    g_return_if_fail(ctx->priv->connected == TRUE);
+    
+    libhal_ctx_set_device_property_modified(ctx->priv->context, callback);
+}
+
+gboolean hal_ctx_watch_all (HalCtx *ctx)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), FALSE);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, FALSE);
+    
+    DBusError error;
+    dbus_error_init(&error);
+    
+    libhal_device_property_watch_all(ctx->priv->context, &error);
+    
+    return TRUE;
+}
+
+gboolean hal_ctx_watch_device (HalCtx *ctx, const gchar *udi)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), FALSE);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, FALSE);
+    
+    DBusError error;
+    dbus_error_init(&error);
+    
+    libhal_device_add_property_watch(ctx->priv->context,
+				     udi,
+				     &error);
+				     
+    HAL_CTX_CHECK_DBUS_ERROR(error)
+    
+    return TRUE;
+}
+
+/*
+ * Get All the devices found by HAL
+ */
+gchar **hal_ctx_get_all_devices (HalCtx *ctx)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), NULL);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, NULL);
+    
+    gchar **udis = NULL;
+    DBusError error;
+    gint number;
+    
+    dbus_error_init(&error);
+    
+    udis = libhal_get_all_devices (ctx->priv->context,
+				   &number,
+				   &error);
+				   
+    HAL_CTX_CHECK_DBUS_ERROR(error)
+    
+    return udis;
+}
+
+/*
+ * Get devices udi's from HAL by capability
+ */
+gchar **hal_ctx_get_device_by_capability (HalCtx *ctx, const gchar *capability, gint *number)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), NULL);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, NULL);
+    
+    gchar **udis = NULL;
+    DBusError error;
+    
+    dbus_error_init(&error);
+    
+    udis = libhal_find_device_by_capability (ctx->priv->context,
+					     capability,
+					     number,
+					     &error);
+    
+    HAL_CTX_CHECK_DBUS_ERROR(error)
+    
+    return udis;
+}
+
+gboolean hal_ctx_device_has_capability (HalCtx *ctx, const gchar *udi, const gchar *capability)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), FALSE);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, FALSE);
+    
+    DBusError error;
+    gboolean ret;
+    
+    dbus_error_init(&error);
+    
+    ret = libhal_device_property_exists(ctx->priv->context,
+					udi,
+					"info.capabilities",
+					&error);
+    if ( dbus_error_is_set (&error) )
+    {
+	dbus_error_free (&error);
+	return FALSE;
+    }
+    
+    if ( !ret )
+    	return FALSE;
+    
+    ret = libhal_device_query_capability(ctx->priv->context,
+					 udi,
+					 capability,
+					 &error);
+    HAL_CTX_CHECK_DBUS_ERROR (error)
+    
+    return ret;
+    
+}
+
+gint32 hal_ctx_get_property_int (HalCtx *ctx, const gchar *udi, const gchar *key)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), 0);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, 0);
+    
+    DBusError error;
+    
+    dbus_error_init(&error);
+    
+    gint32 ret = libhal_device_get_property_int(ctx->priv->context,
+						udi,
+						key,
+						&error);
+    HAL_CTX_CHECK_DBUS_ERROR(error)
+    
+    return ret;
+}
+
+gboolean hal_ctx_get_property_bool (HalCtx *ctx, const gchar *udi, const gchar *key)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), FALSE);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, FALSE);
+    
+    DBusError error;
+    
+    dbus_error_init(&error);
+    
+    gboolean ret = libhal_device_get_property_bool(ctx->priv->context,
+		   				   udi,
+						   key,
+						   &error);
+    HAL_CTX_CHECK_DBUS_ERROR(error)
+    
+    return ret;
+}
+
+gchar *hal_ctx_get_property_string (HalCtx *ctx, const gchar *udi, const gchar *key)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), NULL);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, NULL);
+    
+    DBusError error;
+    
+    gchar *ret     = NULL;
+    gchar *ret_str = NULL;
+    
+    dbus_error_init(&error);
+    
+    ret = libhal_device_get_property_string(ctx->priv->context,
+				  	    udi,
+					    key,
+					    &error);
+    
+    HAL_CTX_CHECK_DBUS_ERROR(error)
+    
+    if ( ret )
+    {
+	ret_str = g_strdup(ret);
+	libhal_free_string(ret);
+    }
+    
+    return ret_str;
+}
+
+gboolean hal_ctx_device_has_key (HalCtx *ctx, const gchar *udi, const gchar *key)
+{
+    g_return_val_if_fail(HAL_IS_CTX(ctx), FALSE);
+    g_return_val_if_fail(ctx->priv->connected == TRUE, FALSE);
+    
+      
+    DBusError error;
+    dbus_error_init(&error);
+    gboolean ret;
+    
+    ret = libhal_device_property_exists(ctx->priv->context,
+					udi,
+					key,
+					&error);
+    HAL_CTX_CHECK_DBUS_ERROR(error)
+					
+    return ret;
+}
diff --git a/libxfpm/hal-ctx.h b/libxfpm/hal-ctx.h
new file mode 100644
index 00000000..3530b2c8
--- /dev/null
+++ b/libxfpm/hal-ctx.h
@@ -0,0 +1,96 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_CTX_H
+#define __HAL_CTX_H
+
+#include <glib-object.h>
+
+#include <hal/libhal.h>
+#include <dbus/dbus-glib.h>
+
+G_BEGIN_DECLS
+
+#define HAL_TYPE_CTX        (hal_ctx_get_type () )
+#define HAL_CTX(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), HAL_TYPE_CTX, HalCtx))
+#define HAL_IS_CTX(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), HAL_TYPE_CTX))
+
+#define HAL_CTX_CHECK_DBUS_ERROR(_dbus_error_)		\
+    if ( dbus_error_is_set(&_dbus_error_) )		\
+    {							\
+	g_critical("%s", _dbus_error_.message);		\
+	dbus_error_free(&_dbus_error_);			\
+    }
+
+typedef struct HalCtxPrivate HalCtxPrivate;
+
+typedef struct
+{
+    GObject		parent;
+    HalCtxPrivate      *priv;
+    
+} HalCtx;
+
+typedef struct
+{
+    GObjectClass 	parent_class;
+    
+} HalCtxClass;
+
+GType         hal_ctx_get_type        			(void) G_GNUC_CONST;
+HalCtx       *hal_ctx_new             			(void);
+gboolean      hal_ctx_connect         			(HalCtx *ctx);
+
+void          hal_ctx_set_user_data			(HalCtx *ctx,
+							 void *data);
+void          hal_ctx_set_device_added_callback		(HalCtx *ctx,
+							 LibHalDeviceAdded callback);
+void          hal_ctx_set_device_removed_callback	(HalCtx *ctx,
+							 LibHalDeviceRemoved callback);
+							 
+void          hal_ctx_set_device_property_callback	(HalCtx *ctx,
+							 LibHalDevicePropertyModified callback);
+							 
+gboolean      hal_ctx_watch_all 			(HalCtx *ctx);
+gboolean      hal_ctx_watch_device 			(HalCtx *ctx,
+							 const gchar *udi);
+
+gchar       **hal_ctx_get_all_devices                   (HalCtx *ctx);
+gchar       **hal_ctx_get_device_by_capability		(HalCtx *ctx,
+							 const gchar *capability,
+							 gint *number);
+gboolean      hal_ctx_device_has_capability		(HalCtx *ctx,
+							 const gchar *udi,
+							 const gchar *capability);
+gint32        hal_ctx_get_property_int			(HalCtx *ctx,
+							 const gchar *udi,
+							 const gchar *key);
+gboolean      hal_ctx_get_property_bool			(HalCtx *ctx,
+							 const gchar *udi,
+							 const gchar *key);
+gchar        *hal_ctx_get_property_string               (HalCtx *ctx,
+							 const gchar *udi,
+							 const gchar *key);
+gboolean      hal_ctx_device_has_key			(HalCtx *ctx,
+							 const gchar *udi,
+							 const gchar *key);
+G_END_DECLS
+
+#endif /* __HAL_CTX_H */
diff --git a/libxfpm/hal-device.c b/libxfpm/hal-device.c
new file mode 100644
index 00000000..06702c2e
--- /dev/null
+++ b/libxfpm/hal-device.c
@@ -0,0 +1,620 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "hal-device.h"
+#include "hal-ctx.h"
+#include "xfpm-string.h"
+#include "hal-enum.h"
+
+/* Init */
+static void hal_device_class_init (HalDeviceClass *klass);
+static void hal_device_init       (HalDevice *device);
+static void hal_device_finalize   (GObject *object);
+
+static void hal_device_get_property(GObject *object,
+				    guint prop_id,
+				    GValue *value,
+				    GParamSpec *pspec);
+
+#define HAL_DEVICE_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), HAL_TYPE_DEVICE, HalDevicePrivate))
+
+struct HalDevicePrivate
+{
+    HalCtx *ctx;
+    
+    /* Properties read-only */
+    HalDeviceType type;
+    
+    gboolean  is_present;
+    gboolean  is_charging;
+    gboolean  is_discharging;
+    
+    gchar    *unit;
+    gchar    *technology;
+    gchar    *udi;
+    gchar    *vendor;
+    gchar    *model;
+    guint     percentage;
+
+    guint32   current_charge;
+    guint32   last_full;
+    
+    guint32   reporting_design;
+    guint32   reporting_last_full;
+    
+    gint      time;
+    
+};
+
+enum
+{
+    PROP_0,
+    PROP_TYPE,
+    PROP_IS_PRESENT,
+    PROP_IS_CHARGING,
+    PROP_IS_DISCHARGING,
+    PROP_UDI,
+    PROP_CURRENT_CHARGE,
+    PROP_PERCENTAGE,
+    PROP_REPORTING_DESIGN,
+    PROP_LAST_FULL,
+    PROP_REPORTING_LAST_FULL,
+    PROP_TIME,
+    PROP_TECHNOLOGY,
+    PROP_VENDOR,
+    PROP_MODEL,
+    PROP_UNIT
+};
+
+enum
+{
+    DEVICE_CHANGED,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE(HalDevice, hal_device, G_TYPE_OBJECT)
+
+static void
+hal_device_class_init(HalDeviceClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->get_property = hal_device_get_property;
+    object_class->finalize = hal_device_finalize;
+
+    signals[DEVICE_CHANGED] =
+    	g_signal_new("device-changed",
+		     HAL_TYPE_DEVICE,
+		     G_SIGNAL_RUN_LAST,
+		     G_STRUCT_OFFSET(HalDeviceClass, device_changed),
+		     NULL, NULL,
+		     g_cclosure_marshal_VOID__VOID,
+		     G_TYPE_NONE, 0, G_TYPE_NONE);
+    
+    g_object_class_install_property(object_class,
+				    PROP_IS_PRESENT,
+				    g_param_spec_boolean("is-present",
+				    			 NULL, NULL,
+							 FALSE,
+							 G_PARAM_READABLE));
+
+    g_object_class_install_property(object_class,
+				    PROP_IS_CHARGING,
+				    g_param_spec_boolean("is-charging",
+							 NULL, NULL,
+							 FALSE,
+							 G_PARAM_READABLE));
+							 
+    g_object_class_install_property(object_class,
+				    PROP_IS_DISCHARGING,
+				    g_param_spec_boolean("is-discharging",
+							 NULL, NULL,
+							 FALSE,
+							 G_PARAM_READABLE));
+    g_object_class_install_property(object_class,
+				    PROP_CURRENT_CHARGE,
+				    g_param_spec_uint("current-charge",
+						      NULL, NULL,
+						      0,
+						      G_MAXUINT32,
+						      0,
+						      G_PARAM_READABLE));
+						      
+    g_object_class_install_property(object_class,
+				    PROP_LAST_FULL,
+				    g_param_spec_uint("last-full",
+						      NULL, NULL,
+						      0,
+						      G_MAXUINT32,
+						      0,
+						      G_PARAM_READABLE));
+						      
+     g_object_class_install_property(object_class,
+				    PROP_REPORTING_DESIGN,
+				    g_param_spec_uint("reporting-design",
+						      NULL, NULL,
+						      0,
+						      G_MAXUINT32,
+						      0,
+						      G_PARAM_READABLE));
+    g_object_class_install_property(object_class,
+				    PROP_REPORTING_LAST_FULL,
+				    g_param_spec_uint("reporting-last-full",
+						      NULL, NULL,
+						      0,
+						      G_MAXUINT32,
+						      0,
+						      G_PARAM_READABLE));
+    g_object_class_install_property(object_class,
+				    PROP_TIME,
+				    g_param_spec_uint("time",
+						      NULL, NULL,
+						      0,
+						      G_MAXINT,
+						      0,
+						      G_PARAM_READABLE));
+    g_object_class_install_property(object_class,
+				    PROP_TYPE,
+				    g_param_spec_uint("type",
+						      NULL, NULL,
+						      0,
+						      HAL_DEVICE_TYPE_UNKNOWN,
+						      HAL_DEVICE_TYPE_UNKNOWN,
+						      G_PARAM_READABLE));
+    g_object_class_install_property(object_class,
+				    PROP_PERCENTAGE,
+				    g_param_spec_uint("percentage",
+						      NULL, NULL,
+						      0,
+						      G_MAXINT,
+						      0,
+						      G_PARAM_READABLE));
+						      
+    g_object_class_install_property(object_class,
+				    PROP_UDI,
+				    g_param_spec_string("udi",
+							NULL, NULL,
+						        NULL,
+						        G_PARAM_READABLE));
+		
+    g_object_class_install_property(object_class,
+				    PROP_TECHNOLOGY,
+				    g_param_spec_string("technology",
+							NULL, NULL,
+						        NULL,
+						        G_PARAM_READABLE));
+     g_object_class_install_property(object_class,
+				    PROP_VENDOR,
+				    g_param_spec_string("vendor",
+							NULL, NULL,
+						        NULL,
+						        G_PARAM_READABLE));
+    g_object_class_install_property(object_class,
+				    PROP_MODEL,
+				    g_param_spec_string("model",
+							NULL, NULL,
+						        NULL,
+						        G_PARAM_READABLE));
+    g_object_class_install_property(object_class,
+				    PROP_UNIT,
+				    g_param_spec_string("unit",
+							 NULL, NULL,
+							 FALSE,
+							 G_PARAM_READABLE));
+							 
+    g_type_class_add_private(klass,sizeof(HalDevicePrivate));
+}
+
+static void
+hal_device_init(HalDevice *device)
+{
+    device->priv = HAL_DEVICE_GET_PRIVATE(device);
+    
+    device->priv->ctx = hal_ctx_new();
+    
+    device->priv->is_present      = FALSE;
+    device->priv->is_charging     = FALSE;
+    device->priv->is_discharging  = FALSE;
+
+    device->priv->unit            = NULL;
+    device->priv->vendor          = NULL;
+    device->priv->technology      = NULL;
+    device->priv->udi             = NULL;
+    device->priv->model           = NULL;
+    device->priv->type            = HAL_DEVICE_TYPE_UNKNOWN;
+    
+    device->priv->percentage      = 0;
+    device->priv->current_charge  = 0;
+    device->priv->last_full       = 0;
+    device->priv->time            = 0;
+    device->priv->reporting_design = 0;
+    device->priv->reporting_last_full = 0;
+}
+
+static void hal_device_get_property(GObject *object,
+				    guint prop_id,
+				    GValue *value,
+				    GParamSpec *pspec)
+{
+    HalDevice *device;
+    device = HAL_DEVICE(object);
+
+    switch (prop_id)
+    {
+	case PROP_TYPE:
+		g_value_set_uint (value, device->priv->type);
+		break;
+	case PROP_IS_PRESENT:
+		g_value_set_boolean (value, device->priv->is_present);
+		break;
+	case PROP_IS_CHARGING:
+		g_value_set_boolean (value, device->priv->is_charging);
+		break;
+	case PROP_IS_DISCHARGING:
+		g_value_set_boolean (value, device->priv->is_discharging);
+		break;
+	case PROP_UNIT:
+		g_value_set_string (value, device->priv->unit);
+		break;
+ 	case PROP_UDI:
+		g_value_set_string (value, device->priv->udi);
+		break;
+	case PROP_TECHNOLOGY:
+		g_value_set_string (value, device->priv->technology);
+		break;
+	case PROP_VENDOR:
+		g_value_set_string (value, device->priv->vendor);
+		break;
+	case PROP_MODEL:
+		g_value_set_string (value, device->priv->model);
+		break;
+	case PROP_PERCENTAGE:
+		g_value_set_uint (value, device->priv->percentage);
+		break;
+	case PROP_CURRENT_CHARGE:
+		g_value_set_uint (value, device->priv->current_charge);
+		break;
+	case PROP_LAST_FULL:
+		g_value_set_uint (value, device->priv->last_full);
+		break;
+	case PROP_REPORTING_DESIGN:
+		g_value_set_uint (value, device->priv->reporting_design);
+		break;
+	case PROP_REPORTING_LAST_FULL:
+		g_value_set_uint (value, device->priv->reporting_last_full);
+		break;	
+	case PROP_TIME:
+		g_value_set_int (value, device->priv->time);
+		break;
+	default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
+            break;
+    }
+}
+
+static void
+hal_device_finalize(GObject *object)
+{
+    HalDevice *device;
+
+    device = HAL_DEVICE(object);
+    
+    if ( device->priv->ctx )
+    	g_object_unref(device->priv->ctx);
+	
+    if ( device->priv->udi)
+    	g_free(device->priv->udi);
+	
+    if ( device->priv->technology )
+    	g_free (device->priv->technology);
+	
+    if ( device->priv->vendor )
+    	g_free (device->priv->vendor);
+	
+    if ( device->priv->model )
+    	g_free (device->priv->model);
+	
+    if ( device->priv->unit )
+    	g_free (device->priv->unit);
+
+    G_OBJECT_CLASS(hal_device_parent_class)->finalize(object);
+}
+
+static HalDeviceType
+hal_device_type_enum_from_string(const gchar *string)
+{
+    if ( xfpm_strequal (string, "primary") )
+    {
+	return HAL_DEVICE_TYPE_PRIMARY;
+    }
+    else if ( xfpm_strequal (string, "ups") )
+    {
+	return HAL_DEVICE_TYPE_UPS;
+    }
+    else if ( xfpm_strequal (string, "mouse") )
+    {
+	return HAL_DEVICE_TYPE_MOUSE;
+    }
+    else if ( xfpm_strequal (string, "keyboard") )
+    {
+	return HAL_DEVICE_TYPE_KEYBOARD;
+    }
+    else if ( xfpm_strequal (string, "camera") )
+    {
+	return HAL_DEVICE_TYPE_CAMERA;
+    }
+    else if ( xfpm_strequal (string, "keyboard_mouse") )
+    {
+	return HAL_DEVICE_TYPE_KEYBOARD_MOUSE;
+    }
+    
+    return HAL_DEVICE_TYPE_UNKNOWN;
+}
+
+static HalDeviceType
+hal_device_get_device_type(HalDevice *device)
+{
+    if ( hal_ctx_device_has_capability(device->priv->ctx, device->priv->udi, "battery") )
+    {
+	gchar *type = hal_ctx_get_property_string(device->priv->ctx, device->priv->udi, "battery.type");
+	if ( type )
+	{
+	    HalDeviceType type_enum  = hal_device_type_enum_from_string(type);
+	    g_free(type);
+	    return type_enum;
+	}
+	else 
+		goto out;
+    }
+    else if ( hal_ctx_device_has_capability(device->priv->ctx, device->priv->udi, "ac_adapter") )
+    {
+	return HAL_DEVICE_TYPE_ADAPTER;
+    }
+    
+out:
+    return HAL_DEVICE_TYPE_UNKNOWN;
+}
+
+static void
+hal_device_refresh_all_adapter (HalDevice *device)
+{
+    device->priv->is_present =
+    	hal_ctx_get_property_bool(device->priv->ctx, device->priv->udi, "ac_adapter.present");
+    
+}
+
+static void
+hal_device_refresh_all_battery (HalDevice *device)
+{
+    device->priv->is_present = 
+    	hal_ctx_get_property_bool(device->priv->ctx, device->priv->udi, "battery.present");
+	
+    device->priv->is_charging = 
+    	hal_ctx_get_property_bool(device->priv->ctx, device->priv->udi, "battery.rechargeable.is_charging");
+    
+    device->priv->is_discharging = 
+    	hal_ctx_get_property_bool(device->priv->ctx, device->priv->udi, "battery.rechargeable.is_discharging");
+    
+    device->priv->current_charge = 
+    	hal_ctx_get_property_int(device->priv->ctx, device->priv->udi, "battery.charge_level.current");
+	
+    device->priv->last_full = 
+    	hal_ctx_get_property_int(device->priv->ctx, device->priv->udi, "battery.charge_level.last_full");
+    
+    if ( hal_ctx_device_has_key(device->priv->ctx, device->priv->udi, "battery.remaining_time") )
+    	device->priv->time = 
+    		hal_ctx_get_property_int(device->priv->ctx, device->priv->udi, "battery.remaining_time");
+    else
+    	device->priv->time = 0;
+    
+    //FIXME: calculate the percentage if it is not found on HAL
+    if ( hal_ctx_device_has_key(device->priv->ctx, device->priv->udi, "battery.charge_level.percentage") )
+     	device->priv->percentage = 
+    		hal_ctx_get_property_int(device->priv->ctx, device->priv->udi, "battery.charge_level.percentage");
+    else device->priv->percentage = 0;
+    
+    if ( hal_ctx_device_has_key(device->priv->ctx, device->priv->udi, "battery.reporting.last_full") )
+     	device->priv->reporting_last_full = 
+    		hal_ctx_get_property_int(device->priv->ctx, device->priv->udi, "battery.reporting.last_full");
+		
+}
+
+static const gchar *
+_translate_technology (const gchar *tech)
+{
+    if ( xfpm_strequal (tech, "lithium-ion") )
+    {
+	return _("Lithium ion");
+    }
+    else if ( xfpm_strequal (tech, "lead-acid") )
+    {
+	return _("Lead acid");
+    }
+    else if ( xfpm_strequal (tech, "lithium-polymer") )
+    {
+	return _("Lithium polymer");
+    }
+    else if ( xfpm_strequal (tech, "nickel-metal-hydride") )
+    {
+	return _("Nickel metal hydride");
+    }
+    
+    return _("Unknown");
+}
+
+static const gchar *
+_translate_unit (const gchar *unit)
+{
+    if ( xfpm_strequal (unit, "mWh") )
+    {
+	return _("mWh");
+    }
+    else if ( xfpm_strequal (unit, "mAh") )
+    {
+	return _("mAh");
+    }
+    
+    return _("Unknown unit");
+}
+
+static void
+hal_device_get_battery_info (HalDevice *device)
+{
+    if ( hal_ctx_device_has_key (device->priv->ctx, device->priv->udi, "battery.technology") )
+    {
+	gchar *tech = hal_ctx_get_property_string (device->priv->ctx, device->priv->udi, "battery.technology");
+	if ( tech )
+	{
+	    device->priv->technology = g_strdup (_translate_technology (tech));
+	    g_free (tech);
+	}
+    }
+    
+    if ( hal_ctx_device_has_key (device->priv->ctx, device->priv->udi, "battery.vendor") )
+    {
+	gchar *vendor = hal_ctx_get_property_string (device->priv->ctx, device->priv->udi, "battery.vendor");
+	if ( vendor )
+	{
+	    device->priv->vendor = g_strdup ( vendor);
+	    g_free (vendor);
+	}
+    }
+    
+    if ( hal_ctx_device_has_key (device->priv->ctx, device->priv->udi, "battery.model") )
+    {
+	gchar *model = hal_ctx_get_property_string (device->priv->ctx, device->priv->udi, "battery.model");
+	if ( model )
+	{
+	    device->priv->model = g_strdup (model);
+	    g_free (model);
+	}
+    }
+    
+    device->priv->reporting_design = hal_ctx_get_property_int (device->priv->ctx, 
+							      device->priv->udi, 
+							      "battery.reporting.design");
+							      
+    if ( hal_ctx_device_has_key (device->priv->ctx, device->priv->udi, "battery.reporting.unit") )
+    {
+	gchar *unit = hal_ctx_get_property_string (device->priv->ctx, device->priv->udi, "battery.reporting.unit");
+	
+	if ( unit )
+	{
+	    device->priv->unit = g_strdup(_translate_unit(unit));
+	    g_free(unit);	    
+	}
+    }
+}
+
+static void
+hal_device_adapter_changed_cb (HalDevice *device, const gchar *key)
+{
+    if ( xfpm_strequal (key, "ac_adapter.present") )
+    {
+    	hal_device_refresh_all_adapter(device);
+    	g_signal_emit(G_OBJECT(device), signals[DEVICE_CHANGED], 0);
+    }
+    
+}
+
+static void
+hal_device_battery_changed_cb (HalDevice *device, const gchar *key)
+{
+    if ( xfpm_strequal (key, "battery.present") ||
+    	 xfpm_strequal (key, "battery.rechargeable.is_charging") ||
+	 xfpm_strequal (key, "battery.rechargeable.is_discharging") ||
+	 xfpm_strequal (key, "battery.charge_level.current")    ||
+	 xfpm_strequal (key, "battery.remaining_time") ||
+	 xfpm_strequal (key, "battery.charge_level.percentage") )
+    {
+	hal_device_refresh_all_battery(device);
+    	g_signal_emit(G_OBJECT(device), signals[DEVICE_CHANGED], 0);
+    }
+    
+}
+
+
+static void
+hal_device_property_modified(LibHalContext *ctx, 
+			     const gchar *udi,
+			     const gchar *key, 
+			     dbus_bool_t is_removed,
+			     dbus_bool_t is_added)
+{
+    HalDevice *device = libhal_ctx_get_user_data(ctx);
+    
+    if ( device->priv->type == HAL_DEVICE_TYPE_ADAPTER )
+    	hal_device_adapter_changed_cb (device, key);
+    else
+    	hal_device_battery_changed_cb (device, key);
+}
+
+HalDevice *
+hal_device_new(const gchar *udi)
+{
+    HalDevice *device = NULL;
+    device = g_object_new(HAL_TYPE_DEVICE,NULL);
+    
+    device->priv->udi = g_strdup(udi);
+    
+    if ( !hal_ctx_connect(device->priv->ctx)) goto out;
+    
+    device->priv->type = hal_device_get_device_type(device);
+   
+    if ( device->priv->type == HAL_DEVICE_TYPE_ADAPTER )
+    	hal_device_refresh_all_adapter(device);
+    else
+    {
+    	hal_device_refresh_all_battery (device);
+	hal_device_get_battery_info    (device);
+    }
+	
+    hal_ctx_set_user_data(device->priv->ctx, device);
+    hal_ctx_set_device_property_callback(device->priv->ctx, 
+    					 hal_device_property_modified);
+    hal_ctx_watch_device(device->priv->ctx, device->priv->udi);
+    
+out:
+    return device;
+}
diff --git a/libxfpm/hal-device.h b/libxfpm/hal-device.h
new file mode 100644
index 00000000..bfba604a
--- /dev/null
+++ b/libxfpm/hal-device.h
@@ -0,0 +1,55 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_DEVICE_H
+#define __HAL_DEVICE_H
+
+#include <glib-object.h>
+
+#include "hal-enum.h"
+
+G_BEGIN_DECLS
+
+#define HAL_TYPE_DEVICE        (hal_device_get_type () )
+#define HAL_DEVICE(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), HAL_TYPE_DEVICE, HalDevice))
+#define HAL_IS_DEVICE(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), HAL_TYPE_DEVICE))
+
+typedef struct HalDevicePrivate HalDevicePrivate;
+
+typedef struct
+{
+    GObject		  parent;
+    HalDevicePrivate	 *priv;
+    
+} HalDevice;
+
+typedef struct
+{
+    GObjectClass          parent_class;
+    void                 (*device_changed) (HalDevice *device);
+    
+} HalDeviceClass;
+
+GType        	 hal_device_get_type        (void) G_GNUC_CONST;
+HalDevice       *hal_device_new             (const gchar *udi);
+
+G_END_DECLS
+
+#endif /* __HAL_DEVICE_H */
diff --git a/libxfpm/hal-enum.h b/libxfpm/hal-enum.h
new file mode 100644
index 00000000..3dac6527
--- /dev/null
+++ b/libxfpm/hal-enum.h
@@ -0,0 +1,38 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_ENUM_H
+#define __HAL_ENUM_H
+
+typedef enum
+{
+    HAL_DEVICE_TYPE_ADAPTER,
+    HAL_DEVICE_TYPE_PRIMARY,
+    HAL_DEVICE_TYPE_UPS,
+    HAL_DEVICE_TYPE_MOUSE,
+    HAL_DEVICE_TYPE_KEYBOARD,
+    HAL_DEVICE_TYPE_KEYBOARD_MOUSE,
+    HAL_DEVICE_TYPE_CAMERA,
+    HAL_DEVICE_TYPE_PDA,
+    HAL_DEVICE_TYPE_UNKNOWN
+    
+} HalDeviceType;
+
+#endif /*__HAL_ENUM_H */
diff --git a/libxfpm/hal-power.c b/libxfpm/hal-power.c
new file mode 100644
index 00000000..3a4f8087
--- /dev/null
+++ b/libxfpm/hal-power.c
@@ -0,0 +1,305 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <glib.h>
+
+#include "hal-ctx.h"
+#include "hal-power.h"
+
+/* Init */
+static void hal_power_class_init (HalPowerClass *klass);
+static void hal_power_init       (HalPower *power);
+static void hal_power_finalize   (GObject *object);
+
+#define HAL_POWER_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), HAL_TYPE_POWER, HalPowerPrivate))
+
+struct HalPowerPrivate
+{
+    GHashTable *hash  ;
+    HalCtx     *ctx   ;
+};
+
+enum
+{
+    DEVICE_ADDED,
+    DEVICE_REMOVED,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE(HalPower, hal_power, G_TYPE_OBJECT)
+
+/*
+ * Sanity check of the keys present of a battery device
+ */
+static gboolean
+hal_power_chech_battery (HalPower *power, const gchar *udi)
+{
+    if ( hal_ctx_device_has_key(power->priv->ctx, udi, "battery.present") &&
+	 hal_ctx_device_has_key(power->priv->ctx, udi, "battery.rechargeable.is_charging") &&
+         hal_ctx_device_has_key(power->priv->ctx, udi, "battery.rechargeable.is_discharging") &&
+         hal_ctx_device_has_key(power->priv->ctx, udi, "battery.charge_level.current") &&
+	 hal_ctx_device_has_key(power->priv->ctx, udi, "battery.charge_level.last_full") )
+		 return TRUE;
+    
+    return FALSE;
+}
+
+static gboolean
+hal_power_is_power_device(HalPower *power, const gchar *udi)
+{
+    if ( hal_ctx_device_has_capability(power->priv->ctx, udi, "battery") ||
+    	 hal_ctx_device_has_capability(power->priv->ctx, udi, "ac_adapter") )
+	return TRUE;
+    
+    return FALSE;
+}
+
+static HalDevice *
+hal_power_add_device(HalPower *power, const gchar *udi)
+{
+    HalDevice *device;
+    device = hal_device_new (udi);
+    
+    g_hash_table_insert (power->priv->hash, g_strdup(udi), device);
+    
+    return device;
+}
+
+static void
+hal_power_remove_device(HalPower *power, HalDevice *device, const gchar *udi)
+{
+    g_object_unref(device);
+    if (!g_hash_table_remove(power->priv->hash, udi))
+    	g_warning ("Unable to removed object from hash\n");
+}
+
+static HalDevice *
+hal_power_get_device(HalPower *power, const gchar *udi)
+{
+    HalDevice *device = NULL;
+    device = g_hash_table_lookup(power->priv->hash, udi);
+    return device;
+}
+
+static void
+hal_power_device_added_cb (LibHalContext *context, const gchar *udi)
+{
+    HalPower *power = libhal_ctx_get_user_data(context);
+    if ( !hal_power_is_power_device(power, udi) ) return;
+    
+    HalDevice *device = hal_power_add_device(power, udi);
+    
+    g_signal_emit(G_OBJECT(power), signals[DEVICE_ADDED], 0, device);
+}
+
+static void
+hal_power_device_removed_cb (LibHalContext *context, const gchar *udi)
+{
+    HalPower *power = libhal_ctx_get_user_data (context);
+    
+    HalDevice *device = hal_power_get_device (power, udi);
+    
+    if (device)
+    {
+    	g_signal_emit(power, signals[DEVICE_REMOVED], 0, device);
+	hal_power_remove_device(power, device, udi);
+    }
+}
+
+static void
+hal_power_class_init(HalPowerClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    signals[DEVICE_ADDED] =
+    	g_signal_new("device-added",
+		     HAL_TYPE_POWER,
+		     G_SIGNAL_RUN_LAST,
+		     G_STRUCT_OFFSET(HalPowerClass, device_added),
+		     NULL, NULL,
+		     g_cclosure_marshal_VOID__POINTER,
+		     G_TYPE_NONE, 1, G_TYPE_POINTER);
+		     
+    signals[DEVICE_REMOVED] =
+    	g_signal_new("device-removed",
+		     HAL_TYPE_POWER,
+		     G_SIGNAL_RUN_LAST,
+		     G_STRUCT_OFFSET(HalPowerClass, device_removed),
+		     NULL, NULL,
+		     g_cclosure_marshal_VOID__POINTER,
+		     G_TYPE_NONE, 1, G_TYPE_POINTER);
+		     
+    object_class->finalize = hal_power_finalize;
+
+    g_type_class_add_private(klass,sizeof(HalPowerPrivate));
+}
+
+static void
+hal_power_get_batteries(HalPower *power)
+{
+    gint number = 0;
+    gchar **batteries = NULL;
+    gint i;
+    
+    batteries = hal_ctx_get_device_by_capability(power->priv->ctx, "battery", &number);
+    
+    if ( !batteries || number == 0 ) 
+    	goto out;
+    
+    for ( i = 0; batteries[i]; i++ )
+    {
+	if (!hal_power_chech_battery(power, batteries[i]))
+		continue;
+		
+    	hal_power_add_device(power, batteries[i]);
+    }
+	
+    libhal_free_string_array(batteries);
+    
+out:
+    	;
+    
+}
+
+static void
+hal_power_get_adapter(HalPower *power)
+{
+    gint number = 0;
+    gchar **adapter = NULL;
+    gint i = 0;
+    
+    adapter = hal_ctx_get_device_by_capability(power->priv->ctx, "ac_adapter", &number);
+    
+    if ( !adapter || number == 0 ) 
+    	goto out;
+    
+    if ( number > 1) 
+    	g_warning("More than one adapter were found on the system");
+    
+    hal_power_add_device (power, adapter[i]);
+    
+    libhal_free_string_array(adapter);
+    
+out:
+    	;
+    
+}
+
+static void
+hal_power_init(HalPower *power)
+{
+    power->priv = HAL_POWER_GET_PRIVATE(power);
+    
+    power->priv->ctx   = hal_ctx_new();
+    power->priv->hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+    
+    if ( !hal_ctx_connect(power->priv->ctx) )
+    {
+    	g_critical("Unable to connect to HAL");
+	goto out;
+    }
+    
+    hal_ctx_set_user_data (power->priv->ctx, power);
+    hal_ctx_set_device_added_callback (power->priv->ctx, hal_power_device_added_cb);
+    hal_ctx_set_device_removed_callback (power->priv->ctx, hal_power_device_removed_cb);
+   
+    hal_power_get_batteries (power);
+    hal_power_get_adapter (power);
+    
+out:
+	;
+}
+
+static void
+hal_power_finalize(GObject *object)
+{
+    HalPower *power;
+    
+    power = HAL_POWER(object);
+    
+    if (power->priv->hash)
+    	g_hash_table_unref(power->priv->hash);
+    
+    if ( power->priv->ctx )
+    	g_object_unref(power->priv->ctx);
+    
+    G_OBJECT_CLASS(hal_power_parent_class)->finalize(object);
+}
+
+HalPower *
+hal_power_new(void)
+{
+    HalPower *power = NULL;
+    power = g_object_new(HAL_TYPE_POWER,NULL);
+    return power;
+}
+
+/*
+ * Return an array of power devices, the array should be freed by the caller
+ */
+GPtrArray *
+hal_power_get_devices (HalPower *power)
+{
+    guint i;
+    GPtrArray *array;
+    HalDevice *device;
+   
+    array = g_ptr_array_new ();
+   
+    GList *list = NULL;
+    list = g_hash_table_get_values (power->priv->hash);
+   
+    if (!list)
+   	goto out;
+	
+    for ( i=0; i < g_list_length (list); i++)
+    {
+       device = g_list_nth_data (list, i);
+       g_object_ref (device);
+       g_ptr_array_add (array, device);
+    }
+   
+    g_list_free (list);
+
+out:
+
+   return array;
+}
diff --git a/libxfpm/hal-power.h b/libxfpm/hal-power.h
new file mode 100644
index 00000000..f71c33e1
--- /dev/null
+++ b/libxfpm/hal-power.h
@@ -0,0 +1,60 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_POWER_H
+#define __HAL_POWER_H
+
+#include <glib-object.h>
+
+#include "hal-device.h"
+
+G_BEGIN_DECLS
+
+#define HAL_TYPE_POWER        (hal_power_get_type () )
+#define HAL_POWER(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), HAL_TYPE_POWER, HalPower))
+#define HAL_IS_POWER(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), HAL_TYPE_POWER))
+
+typedef struct HalPowerPrivate HalPowerPrivate;
+
+typedef struct
+{
+    GObject		  parent;
+    HalPowerPrivate	 *priv;
+    
+} HalPower;
+
+typedef struct
+{
+    GObjectClass parent_class;
+    
+    void 	(*device_added)	       (HalPower *power,
+					const HalDevice *device);
+    void        (*device_removed)      (HalPower *power,
+    					const HalDevice *device);
+    
+} HalPowerClass;
+
+GType        hal_power_get_type        (void) G_GNUC_CONST;
+HalPower    *hal_power_new             (void);
+GPtrArray   *hal_power_get_devices     (HalPower *power);
+
+G_END_DECLS
+
+#endif /* __HAL_POWER_H */
diff --git a/libxfpm/xfpm-common.c b/libxfpm/xfpm-common.c
new file mode 100644
index 00000000..ea108ed4
--- /dev/null
+++ b/libxfpm/xfpm-common.c
@@ -0,0 +1,138 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "xfpm-common.h"
+
+static void
+xfpm_link_browser(GtkAboutDialog *about,const gchar *link,gpointer data)
+{
+    gchar *cmd = g_strdup_printf("%s %s","xfbrowser4",link);
+    g_spawn_command_line_async (cmd, NULL);
+    g_free(cmd);
+	
+}
+
+static void
+xfpm_link_mailto(GtkAboutDialog *about,const gchar *link,gpointer data)
+{
+    gchar *cmd = g_strdup_printf("%s %s","xdg-email",link);
+
+    g_spawn_command_line_async (cmd, NULL);
+    
+    g_free (cmd);
+}
+	
+
+GdkPixbuf *
+xfpm_load_icon(const char *icon_name,gint size)
+{
+    GdkPixbuf *icon;
+    GError *error = NULL;
+    
+    icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default (),
+                                   icon_name,
+                                   size,
+                                   GTK_ICON_LOOKUP_FORCE_SVG,
+                                   &error);
+    if ( error )
+    {
+        g_warning("Error occured while loading icon %s: %s\n", icon_name, error->message);
+        g_error_free(error);
+    }
+    return icon;                               
+}
+
+void       
+xfpm_lock_screen(void)
+{
+    gboolean ret = g_spawn_command_line_async ("xflock4", NULL);
+    
+    if ( !ret )
+    {
+        g_spawn_command_line_async ("gnome-screensaver-command -l", NULL);
+    }
+    
+    if ( !ret )
+    {
+        /* this should be the default*/
+        ret = g_spawn_command_line_async ("xdg-screensaver lock", NULL);
+    }
+    
+    if ( !ret )
+    {
+        ret = g_spawn_command_line_async ("xscreensaver-command -lock", NULL);
+    }
+    
+    if ( !ret )
+    {
+        g_critical ("Connot lock screen\n");
+    }
+    
+    g_usleep (2000000);
+}
+
+void       
+xfpm_preferences(void) 
+{
+    g_spawn_command_line_async ("xfce4-power-manager-settings", NULL);
+}
+
+void       
+xfpm_help(void)
+{
+    g_spawn_command_line_async ("xfhelp4 xfce4-power-manager.html", NULL);
+}
+
+void       
+xfpm_about(GtkWidget *widget,gpointer data)
+{
+    const gchar* authors[3] = 
+    {
+	"Ali Abdallah <aliov@xfce.org>", 
+	 NULL
+    };
+							    
+    static const gchar *documenters[] =
+    {
+	"Ali Abdallah <aliov@xfce.org>",
+	NULL,
+    };
+
+    gtk_about_dialog_set_url_hook (xfpm_link_browser, NULL, NULL);
+    gtk_about_dialog_set_email_hook (xfpm_link_mailto, NULL, NULL);
+    
+    gtk_show_about_dialog (NULL,
+		     "authors", authors,
+		     "copyright", "Copyright \302\251 2008 Ali Abdallah",
+		     "destroy-with-parent", TRUE,
+		     "documenters", documenters,
+		     "license", XFCE_LICENSE_GPL,
+		     "name", _("Xfce4 Power Manager"),
+		     "translator-credits", _("translator-credits"),
+		     "version", PACKAGE_VERSION,
+		     "website", "http://goodies.xfce.org",
+		     NULL);
+						 
+}
diff --git a/libxfpm/xfpm-common.h b/libxfpm/xfpm-common.h
new file mode 100644
index 00000000..12597501
--- /dev/null
+++ b/libxfpm/xfpm-common.h
@@ -0,0 +1,42 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __XFPM_COMMON_H
+#define __XFPM_COMMON_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GdkPixbuf* 	xfpm_load_icon    	(const gchar *icon_name,
+					 gint size);
+void       	xfpm_lock_screen  	(void);
+void       	xfpm_preferences	(void);
+void       	xfpm_help		(void);
+void       	xfpm_about		(GtkWidget *widget, 
+					 gpointer data);
+
+G_END_DECLS
+
+#endif /* XFPM_COMMON_H */
diff --git a/libxfpm/xfpm-dbus.c b/libxfpm/xfpm-dbus.c
new file mode 100644
index 00000000..35d8b362
--- /dev/null
+++ b/libxfpm/xfpm-dbus.c
@@ -0,0 +1,89 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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
+ */
+
+#include "xfpm-dbus.h"
+
+gboolean
+xfpm_dbus_name_has_owner(DBusConnection *connection, const gchar *name)
+{
+    DBusError error;
+    dbus_error_init(&error);
+    
+    gboolean ret = dbus_bus_name_has_owner(connection, name, &error);
+    
+    if ( dbus_error_is_set(&error) )
+    {
+        g_warning("Failed to get name owner: %s\n",error.message);
+        dbus_error_free(&error);
+        return FALSE;
+    }
+    
+    return ret;
+}
+
+gboolean xfpm_dbus_register_name(DBusConnection *connection, const gchar *name)
+{
+    DBusError error;
+    
+    dbus_error_init(&error);
+    
+    int ret =
+	dbus_bus_request_name(connection,
+			      name,
+			      DBUS_NAME_FLAG_DO_NOT_QUEUE,
+			      &error);
+	
+    if ( dbus_error_is_set(&error) )
+    {
+	g_warning("Error: %s\n",error.message);
+	dbus_error_free(&error);
+	return FALSE;
+    }
+    
+    if ( ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
+    {
+	return TRUE;
+    }
+    
+    return FALSE;
+}
+
+gboolean xfpm_dbus_release_name(DBusConnection *connection, const gchar *name)
+{
+    DBusError error;
+    
+    dbus_error_init(&error);
+    
+    int ret =
+	dbus_bus_release_name(connection,
+			      name,
+			      &error);
+    
+    if ( dbus_error_is_set(&error) )
+    {
+        g_warning("Error: %s\n",error.message);
+        dbus_error_free(&error);
+        return FALSE;
+    }
+    
+    if ( ret == -1 ) return FALSE;
+    
+    return TRUE;
+}
diff --git a/src/xfpm-dbus-messages.h b/libxfpm/xfpm-dbus.h
similarity index 50%
rename from src/xfpm-dbus-messages.h
rename to libxfpm/xfpm-dbus.h
index bf1a2c90..11ca3722 100644
--- a/src/xfpm-dbus-messages.h
+++ b/libxfpm/xfpm-dbus.h
@@ -1,5 +1,4 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
+/*
  * * Copyright (C) 2008 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
@@ -16,27 +15,20 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef __XFPM_DBUS_MESSAGES
-#define __XFPM_DBUS_MESSAGES
-
-#define NM_SERVICE	 "org.freedesktop.NetworkManager"
-#define NM_PATH	        "/org/freedesktop/NetworkManager"
-#define NM_INTERFACE	"org.freedesktop.NetworkManager"
+#ifndef __XFPM_DBUS_H
+#define __XFPM_DBUS_H
 
 #include <glib.h>
 #include <dbus/dbus.h>
 
-gboolean xfpm_dbus_name_has_owner(DBusConnection *connection,
-                                  const gchar *service);
-				  
-void     xfpm_dbus_send_nm_message         (const gchar *signal);
-
-gboolean xfpm_dbus_register_name	   (DBusConnection *connection,
-					    const gchar *name);
-gboolean xfpm_dbus_release_name		   (DBusConnection *connection,
-					    const gchar *name);
+gboolean	xfpm_dbus_name_has_owner (DBusConnection *bus,
+					  const gchar *name);
+gboolean        xfpm_dbus_register_name  (DBusConnection *bus,
+					  const gchar *name);
+gboolean        xfpm_dbus_release_name   (DBusConnection *bus,
+					  const gchar *name);
 
-#endif /* __XFPM_DBUS_MESSAGES */
+#endif /* __XFPM_DBUS_H */
diff --git a/src/xfpm-popups.c b/libxfpm/xfpm-popups.c
similarity index 100%
rename from src/xfpm-popups.c
rename to libxfpm/xfpm-popups.c
diff --git a/src/xfpm-popups.h b/libxfpm/xfpm-popups.h
similarity index 100%
rename from src/xfpm-popups.h
rename to libxfpm/xfpm-popups.h
diff --git a/src/xfpm-string.c b/libxfpm/xfpm-string.c
similarity index 100%
rename from src/xfpm-string.c
rename to libxfpm/xfpm-string.c
diff --git a/src/xfpm-string.h b/libxfpm/xfpm-string.h
similarity index 100%
rename from src/xfpm-string.h
rename to libxfpm/xfpm-string.h
diff --git a/panel-plugins/Makefile.am b/panel-plugins/Makefile.am
new file mode 100644
index 00000000..3e438125
--- /dev/null
+++ b/panel-plugins/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = brightness
diff --git a/panel-plugins/brightness/Makefile.am b/panel-plugins/brightness/Makefile.am
new file mode 100644
index 00000000..8993e51b
--- /dev/null
+++ b/panel-plugins/brightness/Makefile.am
@@ -0,0 +1,39 @@
+plugindir = $(libexecdir)/xfce4/panel-plugins
+plugin_PROGRAMS = xfce4-brightness-plugin
+
+xfce4_brightness_plugin_SOURCES =		\
+	main.c
+
+xfce4_brightness_plugin_CFLAGS =		\
+	-DLOCALEDIR=\"$(localedir)\"  		\
+	$(LIBXFCE4PANEL_CFLAGS)       		\
+	$(LIBXFCE4UTIL_CFLAGS)        		\
+	$(GTK_CFLAGS)			      	\
+	$(GLIB_CFLAGS)			      	\
+	$(HAL_CFLAGS)
+
+xfce4_brightness_plugin_LDADD =			\
+	$(LIBXFCE4PANEL_LIBS)   		\
+	$(LIBXFCE4UTIL_LIBS)			\
+	$(GTK_LIBS)   				\
+	$(GLIB_LIBS)				\
+	$(HAL_LIBS)
+
+#
+# Desktop file
+#
+desktopdir = $(datadir)/xfce4/panel-plugins
+desktop_in_in_files = xfce4-brightness-plugin.desktop.in.in
+desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in)
+desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
+@INTLTOOL_DESKTOP_RULE@
+
+EXTRA_DIST =                                                            \
+        $(desktop_in_in_files)
+
+CLEANFILES =                                                            \
+        $(desktop_in_files)                                             \
+        $(desktop_DATA)
+
+%.desktop.in: %.desktop.in.in
+	sed -e "s,\@libexecdir\@,$(libexecdir),g" < $< > $@
diff --git a/panel-plugins/brightness/main.c b/panel-plugins/brightness/main.c
new file mode 100644
index 00000000..2cf81d5f
--- /dev/null
+++ b/panel-plugins/brightness/main.c
@@ -0,0 +1,41 @@
+/*
+ *
+ * * Copyright (C) 2008 Ali <aliov@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
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <gtk/gtk.h>
+#include <glib.h>
+
+#include <libxfce4panel/xfce-panel-plugin.h>
+#include <libxfce4util/libxfce4util.h>
+
+#include <hal/libhal.h>
+
+static void
+register_plugin(XfcePanelPlugin *plugin)
+{
+    
+}
+
+
+XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(register_plugin);
diff --git a/panel-plugins/brightness/xfce4-brightness-plugin.desktop.in.in b/panel-plugins/brightness/xfce4-brightness-plugin.desktop.in.in
new file mode 100644
index 00000000..3d71dced
--- /dev/null
+++ b/panel-plugins/brightness/xfce4-brightness-plugin.desktop.in.in
@@ -0,0 +1,5 @@
+[Xfce Panel]
+Type=X-XFCE-PanelPlugin
+_Name=Brightness plugin
+X-XFCE-Exec=@libexecdir@/xfce4/panel-plugins/xfce4-brightness-plugin
+X-XFCE-Unique=TRUE
diff --git a/settings/Makefile.am b/settings/Makefile.am
new file mode 100644
index 00000000..ef8c302f
--- /dev/null
+++ b/settings/Makefile.am
@@ -0,0 +1,68 @@
+bin_PROGRAMS = xfce4-power-manager-settings
+
+xfce4_power_manager_settings_SOURCES = 				\
+	xfce-power-manager-dbus-client.h			\
+	xfpm-settings_glade.h					\
+	xfpm-settings-main.c					\
+	xfpm-settings.c						\
+	xfpm-settings.h						\
+	$(top_srcdir)/src/xfpm-config.h
+
+
+xfce4_power_manager_settings_CFLAGS =				\
+	-I$(top_srcdir)						\
+	-I$(top_srcdir)/src					\
+	-DLOCALEDIR=\"$(localedir)\"				\
+	-DG_LOG_DOMAIN=\"xfce4-power-manager-settings\" 	\
+	$(GTK_CFLAGS)						\
+	$(GLIB_CFLAGS)						\
+	$(DBUS_CFLAGS)						\
+	$(DBUS_GLIB_CFLAGS)					\
+	$(LIBXFCE4GUI_CFLAGS)					\
+	$(LIBXFCE4UTIL_CFLAGS)					\
+	$(LIBGLADE_CFLAGS)					\
+	$(XFCONF_CFLAGS)
+
+xfce4_power_manager_settings_LDADD   =				\
+	$(GTK_LIBS)						\
+	$(GLIB_LIBS)						\
+	$(DBUS_LIBS)						\
+	$(DBUS_GLIB_LIBS)					\
+	$(LIBXFCE4GUI_LIBS)					\
+	$(LIBXFCE4UTIL_LIBS)					\
+	$(LIBGLADE_LIBS)					\
+	$(XFCONF_LIBS)						\
+	$(top_builddir)/libxfpm/libxfpmcommon.la
+
+
+if MAINTAINER_MODE
+
+BUILT_SOURCES = 				\
+	xfce-power-manager-dbus-client.h	\
+	xfpm-settings_glade.h
+
+xfce-power-manager-dbus-client.h: $(top_srcdir)/src/org.xfce.Power.Manager.xml
+	dbus-binding-tool --mode=glib-client --prefix=xfpm_manager $< >$@
+
+xfpm-settings_glade.h: $(srcdir)/xfpm-settings.glade
+	exo-csource --static --name=xfpm_settings_glade $< >$@
+
+endif
+
+#
+# .desktop file
+#
+desktop_in_files = xfce4-power-manager.desktop.in
+desktopdir = $(datadir)/applications
+desktop_DATA =	$(desktop_in_files:.desktop.in=.desktop)
+
+@INTLTOOL_DESKTOP_RULE@
+
+EXTRA_DIST = 					\
+	xfce-power-manaher-dbus-client.h	\
+	xfpm-settings_glade.h			\
+	$(desktop_in_files)
+
+DISTCLEANFILES =				\
+	$(BUILT_SOURCES)			\
+	$(desktop_DATA)
\ No newline at end of file
diff --git a/src/xfce4-power-manager.desktop.in b/settings/xfce4-power-manager.desktop.in
similarity index 100%
rename from src/xfce4-power-manager.desktop.in
rename to settings/xfce4-power-manager.desktop.in
diff --git a/src/xfpm-settings-main.c b/settings/xfpm-settings-main.c
similarity index 62%
rename from src/xfpm-settings-main.c
rename to settings/xfpm-settings-main.c
index b06880a6..054b0687 100644
--- a/src/xfpm-settings-main.c
+++ b/settings/xfpm-settings-main.c
@@ -37,19 +37,18 @@
 
 #include <xfconf/xfconf.h>
 
-#include "xfce-power-manager-dbus-client.h"
-
-#include "xfpm-string.h"
-#include "xfpm-dbus-messages.h"
+#include "libxfpm/xfpm-popups.h"
+#include "libxfpm/xfpm-string.h"
+#include "libxfpm/xfpm-common.h"
+#include "libxfpm/xfpm-dbus.h"
 
+#include "xfce-power-manager-dbus-client.h"
 #include "xfpm-settings.h"
-#include "xfpm-common.h"
-#include "xfpm-popups.h"
+#include "xfpm-config.h"
 
-static void dialog_response_cb(GtkDialog *dialog, gint response, gpointer data)
+static void dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
 {
-    XfconfChannel   *channel = (XfconfChannel *)g_object_get_data(G_OBJECT(data), "channel");
-    DBusGConnection *bus     = (DBusGConnection *)g_object_get_data(G_OBJECT(data), "bus");    
+    DBusGConnection *bus     = (DBusGConnection *) data;    
     
     switch(response)
     {
@@ -57,27 +56,24 @@ static void dialog_response_cb(GtkDialog *dialog, gint response, gpointer data)
 	    xfpm_help();
 	    break;
 	default:
-	    g_object_unref(G_OBJECT(channel));
 	    xfpm_dbus_release_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
 	    dbus_g_connection_unref(bus);
+	    
 	    xfconf_shutdown();
-	    g_object_unref(G_OBJECT(data));
 	    gtk_widget_destroy(GTK_WIDGET(dialog));
 	    gtk_main_quit();
 	    break;
     }
-    
-    
 }
 
 int main(int argc, char **argv)
 {
     xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
-    
+
+    //FIXME: Help argument
     gtk_init(&argc, &argv);
     
     GError *error = NULL;
-    
     DBusGConnection *bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
     
     if ( error )
@@ -89,11 +85,11 @@ int main(int argc, char **argv)
 
     if ( xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager") ) 
     {
-	g_print("Xfce power manager is running\n");
+	TRACE("Xfce power manager is running\n");
 	
 	if ( xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config") )
 	{
-	    g_warning("Settings dialog already open\n");
+	    TRACE("Settings dialog already open\n");
 	    dbus_g_connection_unref(bus);
 	    return EXIT_SUCCESS;
 	}
@@ -103,59 +99,24 @@ int main(int argc, char **argv)
 	if ( !xfconf_init(&error) )
     	{
 	    g_critical("xfconf init failed: %s using default settings\n",error->message);
-	    xfpm_popup_message(_("Xfce4 Power Manager"),_("Failed to load power manager configuration, "\
-				"using defaults"),GTK_MESSAGE_WARNING);
+	    
+	    xfpm_popup_message(_("Xfce Power Manager"),_("Failed to load power manager configuration, "\
+	    			"using defaults"), GTK_MESSAGE_WARNING);
 	    g_error_free(error);
 	    error = NULL;
     	}
 	
 	XfconfChannel *channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-	
 	DBusGProxy *proxy;
-    
+    	GtkWidget *dialog;
+	
    	proxy = dbus_g_proxy_new_for_name(bus,
 				           "org.xfce.PowerManager",
 				           "/org/xfce/PowerManager",
 				           "org.xfce.Power.Manager");
-	gboolean   system_laptop;
-	gint       power_management;
-	gboolean   with_dpms;
-	gint       governor;
-	gint       switch_buttons;
-	gboolean   brightness_control;
-	gboolean   ups_found;
-	
-	xfpm_driver_dbus_client_get_conf(proxy, &system_laptop, &power_management
-					 ,&with_dpms, &governor, &switch_buttons,
-					 &brightness_control, &ups_found, &error);
-					 
-	if ( error ) g_error("%s \n", error->message);
-	
-	g_print("laptop=%d pm=%d dpms=%d gov=%d bt=%d br=%d ups=%d",
-	 system_laptop, power_management,with_dpms, governor,
-	switch_buttons, brightness_control, ups_found);
-	
-	GtkWidget *dialog = xfpm_settings_new(channel, 
-					      system_laptop,
-					      power_management,
-					      with_dpms,
-					      governor,
-					      switch_buttons,
-					      brightness_control,
-					      ups_found);
-	
-	xfce_gtk_window_center_on_monitor_with_pointer(GTK_WINDOW(dialog));
-	gtk_window_set_modal(GTK_WINDOW(dialog), FALSE);
-	
-	gdk_x11_window_set_user_time(dialog->window, gdk_x11_get_server_time (dialog->window));
-	
-	gpointer data;
-	data = g_object_new(G_TYPE_OBJECT, NULL);
-	
-	g_object_set_data(G_OBJECT(data), "bus", bus);
-	g_object_set_data(G_OBJECT(data), "channel", channel);
 	
-	g_signal_connect(dialog, "response", G_CALLBACK(dialog_response_cb), data);
+	dialog = xfpm_settings_dialog_new (channel);	
+	g_signal_connect(dialog, "response", G_CALLBACK(dialog_response_cb), bus);
 	
 	gtk_widget_show(dialog);
 	
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
new file mode 100644
index 00000000..3dda53ed
--- /dev/null
+++ b/settings/xfpm-settings.c
@@ -0,0 +1,655 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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 <gtk/gtk.h>
+#include <glib.h>
+#include <glade/glade.h>
+
+#include <xfconf/xfconf.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+
+#include "libxfpm/xfpm-common.h"
+#include "libxfpm/xfpm-string.h"
+
+#include "xfpm-settings_glade.h"
+
+#include "xfpm-config.h"
+
+static 	GladeXML *xml 				= NULL;
+#ifdef HAVE_DPMS
+static  GtkWidget *on_battery_dpms_sleep 	= NULL;
+static  GtkWidget *on_battery_dpms_off  	= NULL;
+static  GtkWidget *on_ac_dpms_sleep 		= NULL;
+static  GtkWidget *on_ac_dpms_off 		= NULL;
+#endif
+/*
+ * Callback settings 
+ */
+static void
+battery_critical_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    guint value = gtk_combo_box_get_active ( GTK_COMBO_BOX (w));
+    
+    if (!xfconf_channel_set_uint (channel, CRITICAL_BATT_ACTION_CFG, value) )
+    {
+	g_critical ("Cannot set value for property %s\n", CRITICAL_BATT_ACTION_CFG);
+    }
+}
+
+static void
+set_show_tray_icon_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    guint value = gtk_combo_box_get_active ( GTK_COMBO_BOX (w));
+    
+    if (!xfconf_channel_set_uint (channel, SHOW_TRAY_ICON_CFG, value) )
+    {
+	g_critical ("Cannot set value for property %s\n", SHOW_TRAY_ICON_CFG);
+    }
+}
+
+static void
+set_sleep_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    guint value = gtk_combo_box_get_active ( GTK_COMBO_BOX (w));
+    
+    if (!xfconf_channel_set_uint (channel, SLEEP_SWITCH_CFG, value) )
+    {
+	g_critical ("Cannot set value for property %s\n", SLEEP_SWITCH_CFG);
+    }
+}
+
+static void
+power_save_toggled_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    gboolean val = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
+    
+    if (!xfconf_channel_set_bool (channel, POWER_SAVE_ON_BATTERY, val) )
+    {
+	g_critical ("Cannot set value for property %s\n", POWER_SAVE_ON_BATTERY);
+    }
+}
+
+static void
+notify_toggled_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    gboolean val = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
+    
+    if (!xfconf_channel_set_bool (channel, GENERAL_NOTIFICATION_CFG, val) )
+    {
+	g_critical ("Cannot set value for property %s\n", GENERAL_NOTIFICATION_CFG);
+    }
+}
+
+#ifdef HAVE_DPMS
+static void
+dpms_toggled_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    gboolean val = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
+    
+    xfconf_channel_set_bool (channel, DPMS_ENABLED_CFG, val);
+    
+    gtk_widget_set_sensitive (on_ac_dpms_off, val);
+    gtk_widget_set_sensitive (on_ac_dpms_sleep, val);
+    
+    if ( GTK_IS_WIDGET (on_battery_dpms_off ) )
+    {
+	gtk_widget_set_sensitive (on_battery_dpms_off, val);
+    	gtk_widget_set_sensitive (on_battery_dpms_sleep, val);
+    }
+}
+
+static void
+sleep_on_battery_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    gint off_value    = (gint)gtk_range_get_value (GTK_RANGE(on_battery_dpms_off));
+    gint sleep_value  = (gint)gtk_range_get_value (GTK_RANGE(w));
+    
+    //g_print("SLEEP off_value=%d sleep_value =%d\n", off_value, sleep_value);
+    if ( off_value != 0 )
+    {
+	if ( sleep_value >= off_value )
+	{
+	    gtk_range_set_value (GTK_RANGE(on_battery_dpms_off), sleep_value + 1 );
+	}
+    }
+    
+    if (!xfconf_channel_set_uint (channel, ON_BATT_DPMS_SLEEP, sleep_value))
+    {
+	g_critical ("Cannot set value for property %s\n", ON_BATT_DPMS_SLEEP);
+    }
+    
+}
+
+static void
+off_on_battery_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    gint off_value    = (gint)gtk_range_get_value (GTK_RANGE(w));
+    gint sleep_value  = (gint)gtk_range_get_value (GTK_RANGE(on_battery_dpms_sleep));
+    
+    //g_print("OFF off_value=%d sleep_value =%d\n", off_value, sleep_value);
+    if ( sleep_value != 0 )
+    {
+	if ( off_value <= sleep_value )
+	{
+	    gtk_range_set_value (GTK_RANGE(on_battery_dpms_sleep), off_value -1 );
+	}
+    }
+    
+    if (!xfconf_channel_set_uint (channel, ON_BATT_DPMS_OFF, off_value))
+    {
+	g_critical ("Cannot set value for property %s\n", ON_BATT_DPMS_OFF);
+    }
+    
+}
+
+static void
+sleep_on_ac_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    gint off_value    = (gint)gtk_range_get_value (GTK_RANGE(on_ac_dpms_off));
+    gint sleep_value  = (gint)gtk_range_get_value (GTK_RANGE(w));
+    
+    if ( off_value > 60 || sleep_value > 60 )
+    	return;
+	
+    g_print("SLEEP off_value=%d sleep_value =%d\n", off_value, sleep_value);
+    
+    if ( off_value != 0 )
+    {
+	if ( sleep_value >= off_value )
+	{
+	    gtk_range_set_value (GTK_RANGE(on_ac_dpms_off), sleep_value + 1 );
+	}
+    }
+    
+    if (!xfconf_channel_set_uint (channel, ON_AC_DPMS_SLEEP, sleep_value))
+    {
+	g_critical ("Cannot set value for property %s\n", ON_AC_DPMS_SLEEP);
+    }
+}
+
+static void
+off_on_ac_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    gint off_value    = (gint)gtk_range_get_value (GTK_RANGE(w));
+    gint sleep_value  = (gint)gtk_range_get_value (GTK_RANGE(on_ac_dpms_sleep));
+    
+    g_print("OFF off_value=%d sleep_value =%d\n", off_value, sleep_value);
+    
+    if ( off_value > 60 || sleep_value > 60 )
+    	return;
+    
+    if ( sleep_value != 0 )
+    {
+	if ( off_value <= sleep_value )
+	{
+	    gtk_range_set_value (GTK_RANGE(on_ac_dpms_sleep), off_value -1 );
+	}
+    }
+    
+    if (!xfconf_channel_set_uint (channel, ON_AC_DPMS_OFF, off_value))
+    {
+	g_critical ("Cannot set value for property %s\n", ON_AC_DPMS_OFF);
+    }
+    
+}
+
+/*
+ * Format value of GtkRange used with DPMS
+ */
+static gchar *
+format_dpms_value_cb (GtkScale *scale, gdouble value)
+{
+    if ( (int)value == 0 )
+    	return g_strdup _("Never");
+        
+    return g_strdup_printf ("%d %s", (int)value, _("Minutes"));
+}
+#endif
+
+static void
+on_battery_lid_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    guint val = gtk_combo_box_get_active (GTK_COMBO_BOX(w));
+    
+    if (!xfconf_channel_set_uint (channel, LID_SWITCH_ON_BATTERY_CFG, val) )
+    {
+	g_critical ("Cannot set value for property %s\n", LID_SWITCH_ON_BATTERY_CFG);
+    }
+}
+
+static void
+on_ac_lid_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    guint val = gtk_combo_box_get_active (GTK_COMBO_BOX(w));
+    
+    if (!xfconf_channel_set_uint (channel, LID_SWITCH_ON_AC_CFG, val) )
+    {
+	g_critical ("Cannot set value for property %s\n", LID_SWITCH_ON_AC_CFG);
+    }
+} 
+
+static void
+xfpm_settings_on_battery (XfconfChannel *channel)
+{
+    guint val;
+    GtkWidget *battery_critical = glade_xml_get_widget (xml, "battery-critical-combox");
+    
+    gtk_combo_box_append_text (GTK_COMBO_BOX(battery_critical), _("Shutdown"));
+    gtk_combo_box_append_text (GTK_COMBO_BOX(battery_critical), _("Hibernate"));
+    
+    guint critical_action = xfconf_channel_get_uint (channel, CRITICAL_BATT_ACTION_CFG, 0);
+    gtk_combo_box_set_active (GTK_COMBO_BOX(battery_critical), critical_action);
+    
+    g_signal_connect (battery_critical, "changed", 
+		      G_CALLBACK(battery_critical_changed_cb), channel);
+    GtkWidget *power_save = glade_xml_get_widget (xml, "power-save");
+    gboolean save_power = xfconf_channel_get_bool (channel, POWER_SAVE_ON_BATTERY, TRUE);
+    
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(power_save), save_power);
+    g_signal_connect (power_save, "toggled",
+		      G_CALLBACK(power_save_toggled_cb), channel);
+    
+    /*
+     * DPMS settings when running on battery power
+     */
+#ifdef HAVE_DPMS
+    GtkWidget *dpms_frame_on_battery = glade_xml_get_widget (xml, "dpms-on-battery-frame");
+    gtk_widget_show (GTK_WIDGET(dpms_frame_on_battery));
+    
+    on_battery_dpms_sleep = glade_xml_get_widget (xml, "sleep-dpms-on-battery");
+  
+    val = xfconf_channel_get_uint (channel, ON_BATT_DPMS_SLEEP, 3);
+    gtk_range_set_value (GTK_RANGE(on_battery_dpms_sleep), val);
+    
+    g_signal_connect (on_battery_dpms_sleep, "value-changed",
+		      G_CALLBACK(sleep_on_battery_value_changed_cb), channel);
+		      
+    g_signal_connect (on_battery_dpms_sleep, "format-value", 
+		      G_CALLBACK(format_dpms_value_cb), NULL);
+		      
+    on_battery_dpms_off = glade_xml_get_widget (xml, "off-dpms-on-battery");
+    
+    val = xfconf_channel_get_uint (channel, ON_BATT_DPMS_OFF, 5);
+    gtk_range_set_value (GTK_RANGE(on_battery_dpms_off), val);
+    
+    g_signal_connect (on_battery_dpms_off, "value-changed",
+		      G_CALLBACK(off_on_battery_value_changed_cb), channel);
+    g_signal_connect (on_battery_dpms_off, "format-value", 
+		      G_CALLBACK(format_dpms_value_cb), NULL);
+#endif
+
+     /*
+     * Lid switch settings on battery
+     */
+    GtkWidget *lid = glade_xml_get_widget (xml, "on-battery-lid");
+    val = xfconf_channel_get_uint (channel, LID_SWITCH_ON_BATTERY_CFG, 0);
+    
+    gtk_combo_box_append_text (GTK_COMBO_BOX(lid), _("Suspend"));
+    gtk_combo_box_append_text (GTK_COMBO_BOX(lid), _("Hibernate"));
+    
+    gtk_combo_box_set_active (GTK_COMBO_BOX(lid), val);
+    
+    g_signal_connect (lid, "changed", 
+		      G_CALLBACK(on_battery_lid_changed_cb), channel);
+}
+
+static void
+xfpm_settings_on_ac (XfconfChannel *channel)
+{
+    guint val;
+#ifdef HAVE_DPMS
+    /*
+     * DPMS settings when running on AC power 
+     */
+    GtkWidget *dpms_frame_on_ac = glade_xml_get_widget (xml, "dpms-on-ac-frame");
+    gtk_widget_show (GTK_WIDGET(dpms_frame_on_ac));
+    
+    on_ac_dpms_sleep = glade_xml_get_widget (xml, "sleep-dpms-on-ac");
+  
+    val = xfconf_channel_get_uint (channel, ON_AC_DPMS_SLEEP, 10);
+    gtk_range_set_value (GTK_RANGE(on_ac_dpms_sleep), val);
+    
+    g_signal_connect (on_ac_dpms_sleep, "value-changed",
+		      G_CALLBACK(sleep_on_ac_value_changed_cb), channel);
+		      
+    g_signal_connect (on_ac_dpms_sleep, "format-value", 
+		      G_CALLBACK(format_dpms_value_cb), NULL);
+		      
+    on_ac_dpms_off = glade_xml_get_widget (xml, "off-dpms-on-ac");
+    
+    val = xfconf_channel_get_uint (channel, ON_AC_DPMS_OFF, 15);
+    gtk_range_set_value (GTK_RANGE(on_ac_dpms_off), val);
+    
+    g_signal_connect (on_ac_dpms_off, "value-changed",
+		      G_CALLBACK(off_on_ac_value_changed_cb), channel);
+    g_signal_connect (on_ac_dpms_off, "format-value", 
+		      G_CALLBACK(format_dpms_value_cb), NULL);
+#endif
+
+    /*
+     * Lid switch settings on battery
+     */
+    GtkWidget *lid = glade_xml_get_widget (xml, "on-ac-lid");
+    val = xfconf_channel_get_uint (channel, LID_SWITCH_ON_AC_CFG, 0);
+    
+    gtk_combo_box_append_text (GTK_COMBO_BOX(lid), _("Suspend"));
+    gtk_combo_box_append_text (GTK_COMBO_BOX(lid), _("Hibernate"));
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX(lid), val);
+    g_signal_connect (lid, "changed", 
+		      G_CALLBACK(on_ac_lid_changed_cb), channel);
+    
+}
+
+static void
+xfpm_settings_general (XfconfChannel *channel)
+{
+    /*
+     *  Tray icon settings
+     */
+    GtkWidget *tray = glade_xml_get_widget (xml, "tray-combox");
+    
+    gtk_combo_box_append_text (GTK_COMBO_BOX(tray), _("When battery is present"));
+    gtk_combo_box_append_text (GTK_COMBO_BOX(tray), _("When battery is charging or discharging"));
+    
+    guint show_tray = xfconf_channel_get_uint (channel, SHOW_TRAY_ICON_CFG, 0);
+    
+    gtk_combo_box_set_active (GTK_COMBO_BOX(tray), show_tray);
+    
+    g_signal_connect (tray, "changed",
+		      G_CALLBACK(set_show_tray_icon_cb), channel);
+    gboolean val;
+#ifdef HAVE_DPMS
+    /*
+     * Global dpms settings (enable/disable)
+     */
+    GtkWidget *dpms = glade_xml_get_widget (xml, "enable-dpms");
+   
+    g_signal_connect (dpms, "toggled",
+		      G_CALLBACK(dpms_toggled_cb), channel);
+		      
+    val = xfconf_channel_get_bool (channel, DPMS_ENABLED_CFG, TRUE);
+    
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dpms), val);
+#endif
+
+    /*
+     * Sleep button 
+     */
+    GtkWidget *sleep = glade_xml_get_widget (xml, "sleep-combox");
+
+    gtk_combo_box_append_text (GTK_COMBO_BOX(sleep), _("Suspend"));
+    gtk_combo_box_append_text (GTK_COMBO_BOX(sleep), _("Hibernate"));
+    gtk_combo_box_append_text (GTK_COMBO_BOX(sleep), _("Shutdown"));
+    
+    guint sleep_val = xfconf_channel_get_uint (channel, SLEEP_SWITCH_CFG, 0);
+    
+    gtk_combo_box_set_active (GTK_COMBO_BOX(sleep), sleep_val);
+    
+    g_signal_connect (sleep, "changed",
+		      G_CALLBACK(set_sleep_changed_cb), channel);
+    
+    /*
+     * Enable/Disable Notification
+     */
+    
+    GtkWidget *notify = glade_xml_get_widget (xml, "notification");
+    val = xfconf_channel_get_bool (channel, GENERAL_NOTIFICATION_CFG, TRUE);
+    
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(notify), val);
+    
+    g_signal_connect (notify, "toggled",
+		      G_CALLBACK(notify_toggled_cb), channel);
+}
+
+static void
+_cursor_changed_cb(GtkIconView *view,gpointer data)
+{
+    GtkTreeSelection *sel;
+    GtkTreeModel     *model;
+    GtkTreeIter       selected_row;
+    gint int_data = 0;
+
+    sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
+
+    gtk_tree_selection_get_selected (sel, &model, &selected_row);
+
+    gtk_tree_model_get(model,
+                       &selected_row,
+                       2,
+                       &int_data,
+                       -1);
+
+    if ( int_data >= 0 && int_data <= 3 )
+    {
+	GtkWidget *nt = glade_xml_get_widget (xml, "main-notebook");
+        gtk_notebook_set_current_page(GTK_NOTEBOOK(nt), int_data);
+    }
+}
+
+static void
+xfpm_settings_tree_view (XfconfChannel *channel)
+{
+    GtkWidget *view = glade_xml_get_widget (xml, "treeview");
+    GdkPixbuf *pix;
+    GtkListStore *list_store;
+    GtkTreeIter iter;
+    GtkTreeViewColumn *col;
+    GtkCellRenderer *renderer;
+    gint i = 0;
+    
+    list_store = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT);
+
+    gtk_tree_view_set_model (GTK_TREE_VIEW(view), GTK_TREE_MODEL(list_store));
+    
+    gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view),TRUE);
+    col = gtk_tree_view_column_new();
+    //gtk_tree_view_column_set_spacing(col, 10);
+
+    renderer = gtk_cell_renderer_pixbuf_new();
+    
+    gtk_tree_view_column_pack_start(col, renderer, FALSE);
+    gtk_tree_view_column_set_attributes(col, renderer, "pixbuf", 0, NULL);
+
+    renderer = gtk_cell_renderer_text_new();
+    gtk_tree_view_column_pack_start (col, renderer, FALSE);
+    gtk_tree_view_column_set_attributes (col, renderer, "text", 1, NULL);
+    
+    gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
+    
+    /*General settings */
+    pix = xfpm_load_icon("preferences-system", 48); 
+    
+    gtk_list_store_append(list_store, &iter);
+    
+    if ( pix )
+    {
+	    gtk_list_store_set (list_store, &iter, 0, pix, 1, _("General"), 2, i, -1);
+	    g_object_unref(pix);
+    }
+    else
+    {
+	    gtk_list_store_set (list_store, &iter, 1, _("General"), 2, i, -1);
+    }
+    i++;
+    
+    /* ON ac power */
+    pix = xfpm_load_icon("gpm-ac-adapter", 48); 
+    gtk_list_store_append(list_store, &iter);
+    if ( pix )
+    {
+	    gtk_list_store_set(list_store, &iter, 0, pix, 1, _("ON AC"), 2, i, -1);
+	    g_object_unref(pix);
+    }
+    else
+    {
+	    gtk_list_store_set(list_store, &iter, 1, _("ON AC"), 2, i, -1);
+    }
+    i++;
+    
+    
+    pix = xfpm_load_icon("battery", 48); 
+    gtk_list_store_append(list_store, &iter);
+    if ( pix )
+    {
+	    gtk_list_store_set(list_store, &iter, 0, pix, 1, _("ON Battery"), 2, i, -1);
+	    g_object_unref(pix);
+    }
+    else
+    {
+	    gtk_list_store_set(list_store, &iter, 1, _("ON Battery"), 2, i, -1);
+    }
+    i++;
+    
+    GtkTreeSelection *sel;
+    GtkTreePath *path;
+
+    sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+
+    path = gtk_tree_path_new_from_string("0");
+
+    gtk_tree_selection_select_path(sel, path);
+    gtk_tree_path_free(path);
+
+    g_signal_connect(view,"cursor-changed",G_CALLBACK(_cursor_changed_cb),NULL);
+    
+}
+
+//FIXME: Check the values before updating the dialog
+static void
+update_settings_dialog (XfconfChannel *channel, gchar *property, GValue *value, GladeXML *xml)
+{
+    if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
+    	return;
+
+#ifdef HAVE_DPMS
+
+    if ( xfpm_strequal (property, DPMS_ENABLED_CFG) )
+    {
+	gboolean val = g_value_get_boolean (value );
+	GtkWidget *dpms = glade_xml_get_widget (xml, "enable-dpms");
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dpms), val);
+    }
+    else if ( xfpm_strequal (property, ON_AC_DPMS_SLEEP) )
+    {
+        guint val = g_value_get_uint (value);
+	gtk_range_set_value (GTK_RANGE(on_ac_dpms_sleep), val);
+    }
+    else if ( xfpm_strequal (property, ON_AC_DPMS_OFF) )
+    {
+        guint val = g_value_get_uint (value);
+	gtk_range_set_value (GTK_RANGE(on_ac_dpms_off), val);
+    }
+    else if ( xfpm_strequal (property, ON_BATT_DPMS_SLEEP) )
+    {
+        guint val = g_value_get_uint (value);
+	gtk_range_set_value (GTK_RANGE(on_ac_dpms_sleep), val);
+    }
+    else if ( xfpm_strequal (property, ON_BATT_DPMS_OFF) )
+    {
+        guint val = g_value_get_uint (value);
+	gtk_range_set_value (GTK_RANGE(on_ac_dpms_off), val);
+    }
+#endif /* HAVE_DPMS */
+    else if ( xfpm_strequal (property, POWER_SAVE_ON_BATTERY ) )
+    {
+	GtkWidget *widget = glade_xml_get_widget (xml, "power-save");
+	gboolean val = g_value_get_boolean (value);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), val);
+    }
+    else if ( xfpm_strequal (property, SLEEP_SWITCH_CFG ) )
+    {
+	GtkWidget *widget = glade_xml_get_widget (xml, "sleep-combox");
+	guint val = g_value_get_uint (value);
+	gtk_combo_box_set_active (GTK_COMBO_BOX(widget), val);
+    }
+    else if ( xfpm_strequal (property, LID_SWITCH_ON_AC_CFG ) )
+    {
+	GtkWidget *widget = glade_xml_get_widget (xml, "on-ac-lid");
+	guint val = g_value_get_uint (value);
+	gtk_combo_box_set_active (GTK_COMBO_BOX(widget), val);
+    }
+    else if ( xfpm_strequal (property, LID_SWITCH_ON_BATTERY_CFG ) )
+    {
+	GtkWidget *widget = glade_xml_get_widget (xml, "on-battery-lid");
+	guint val = g_value_get_uint (value);
+	gtk_combo_box_set_active (GTK_COMBO_BOX(widget), val);
+    }
+    if ( xfpm_strequal (property, GENERAL_NOTIFICATION_CFG ) )
+    {
+	GtkWidget *widget = glade_xml_get_widget (xml, "notification");
+	guint val = g_value_get_boolean (value);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), val);
+    }
+    
+}
+
+static void dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
+{
+    XfconfChannel *channel = (XfconfChannel *)data;
+    
+    switch(response)
+    {
+	case GTK_RESPONSE_HELP:
+	    xfpm_help();
+	    break;
+	default:
+	    g_object_unref(G_OBJECT(channel));
+	    break;
+    }
+}
+
+GtkWidget *
+xfpm_settings_dialog_new (XfconfChannel *channel)
+{
+    GtkWidget *dialog;
+    
+    xml = glade_xml_new_from_buffer (xfpm_settings_glade,
+				     xfpm_settings_glade_length,
+				     "xfpm-settings-dialog", NULL);
+    
+    dialog = glade_xml_get_widget (xml, "xfpm-settings-dialog");
+
+    xfpm_settings_tree_view (channel);
+    xfpm_settings_general   (channel);
+    xfpm_settings_on_ac     (channel);
+    xfpm_settings_on_battery (channel);
+
+    /*
+     * Connect property-changed to the channel in case the settings changed
+     * somehow, say with xfconf-query so we can update the settings dialog
+     */
+    g_signal_connect (channel, "property-changed", 
+		      G_CALLBACK (update_settings_dialog), xml);
+		      
+    g_signal_connect (dialog, "response", G_CALLBACK(dialog_response_cb), channel);
+    
+    return dialog;
+}
diff --git a/settings/xfpm-settings.glade b/settings/xfpm-settings.glade
new file mode 100644
index 00000000..81faf219
--- /dev/null
+++ b/settings/xfpm-settings.glade
@@ -0,0 +1,774 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--Generated with glade3 3.4.5 on Sun Mar  8 17:07:51 2009 -->
+<glade-interface>
+  <requires lib="xfce4"/>
+  <widget class="XfceTitledDialog" id="xfpm-settings-dialog">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Xfce Power Manager</property>
+    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+    <property name="icon_name">gpm-ac-adapter</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="has_separator">False</property>
+    <property name="subtitle" translatable="yes">Power manager settings</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkTreeView" id="treeview">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="headers_visible">False</property>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkNotebook" id="main-notebook">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="show_tabs">False</property>
+                    <child>
+                      <widget class="GtkFrame" id="frame4">
+                        <property name="visible">True</property>
+                        <property name="label_xalign">0</property>
+                        <property name="shadow_type">GTK_SHADOW_NONE</property>
+                        <child>
+                          <widget class="GtkAlignment" id="alignment6">
+                            <property name="visible">True</property>
+                            <property name="left_padding">12</property>
+                            <child>
+                              <widget class="GtkVBox" id="vbox13">
+                                <property name="visible">True</property>
+                                <property name="spacing">10</property>
+                                <child>
+                                  <widget class="GtkTable" id="table1">
+                                    <property name="visible">True</property>
+                                    <property name="n_rows">3</property>
+                                    <property name="n_columns">2</property>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox10">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <widget class="GtkComboBox" id="sleep-combox">
+                                            <property name="visible">True</property>
+                                            <property name="items" translatable="yes">Nothing</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">1</property>
+                                        <property name="bottom_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox9">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <widget class="GtkComboBox" id="tray-combox">
+                                            <property name="visible">True</property>
+                                            <property name="items" translatable="yes">Always show icon</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox7">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label4">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">System tray icon: </property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox8">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label2">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">When sleep button is pressed:</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="top_attach">1</property>
+                                        <property name="bottom_attach">2</property>
+                                      </packing>
+                                    </child>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <widget class="GtkCheckButton" id="enable-dpms">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="label" translatable="yes">Enable monitor power management control</property>
+                                    <property name="response_id">0</property>
+                                    <property name="draw_indicator">True</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <widget class="GtkCheckButton" id="notification">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="label" translatable="yes">Enable notification</property>
+                                    <property name="response_id">0</property>
+                                    <property name="draw_indicator">True</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">2</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                            </child>
+                          </widget>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label12">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;b&gt;General Options&lt;/b&gt;</property>
+                            <property name="use_markup">True</property>
+                          </widget>
+                          <packing>
+                            <property name="type">label_item</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="on-ac-tab">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">General Options</property>
+                      </widget>
+                      <packing>
+                        <property name="type">tab</property>
+                        <property name="tab_fill">False</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkVBox" id="vbox2">
+                        <property name="visible">True</property>
+                        <child>
+                          <widget class="GtkFrame" id="frame5">
+                            <property name="visible">True</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">GTK_SHADOW_NONE</property>
+                            <child>
+                              <widget class="GtkAlignment" id="alignment5">
+                                <property name="visible">True</property>
+                                <property name="top_padding">5</property>
+                                <property name="left_padding">15</property>
+                                <child>
+                                  <widget class="GtkVBox" id="vbox4">
+                                    <property name="visible">True</property>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox4">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label14">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">When laptop lid is closed:</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkComboBox" id="on-ac-lid">
+                                            <property name="visible">True</property>
+                                            <property name="items" translatable="yes">Nothing</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                  </widget>
+                                </child>
+                              </widget>
+                            </child>
+                            <child>
+                              <widget class="GtkLabel" id="sleep">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Actions&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </widget>
+                              <packing>
+                                <property name="type">label_item</property>
+                              </packing>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="padding">10</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkFrame" id="dpms-on-ac-frame">
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">GTK_SHADOW_NONE</property>
+                            <child>
+                              <widget class="GtkAlignment" id="alignment7">
+                                <property name="visible">True</property>
+                                <property name="top_padding">5</property>
+                                <property name="left_padding">15</property>
+                                <child>
+                                  <widget class="GtkVBox" id="vbox8">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">20</property>
+                                    <child>
+                                      <widget class="GtkVBox" id="vbox11">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label9">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">Put display to sleep when computer is inactive for:</property>
+                                          </widget>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkHScale" id="sleep-dpms-on-ac">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="adjustment">0 0 100 1 10 10</property>
+                                            <property name="show_fill_level">True</property>
+                                            <property name="digits">0</property>
+                                            <property name="value_pos">GTK_POS_BOTTOM</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkVBox" id="vbox12">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label10">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">Switch off display when computer is inactive for:</property>
+                                          </widget>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkHScale" id="off-dpms-on-ac">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="adjustment">0 0 100 1 10 10</property>
+                                            <property name="show_fill_level">True</property>
+                                            <property name="digits">0</property>
+                                            <property name="value_pos">GTK_POS_BOTTOM</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </widget>
+                                </child>
+                              </widget>
+                            </child>
+                            <child>
+                              <widget class="GtkLabel" id="label11">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Monitor&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </widget>
+                              <packing>
+                                <property name="type">label_item</property>
+                              </packing>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkFrame" id="frame6">
+                            <property name="visible">True</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">GTK_SHADOW_NONE</property>
+                            <child>
+                              <widget class="GtkAlignment" id="alignment8">
+                                <property name="visible">True</property>
+                                <property name="top_padding">5</property>
+                                <property name="left_padding">15</property>
+                                <child>
+                                  <widget class="GtkVBox" id="vbox14">
+                                    <property name="visible">True</property>
+                                    <child>
+                                      <widget class="GtkLabel" id="label15">
+                                        <property name="visible">True</property>
+                                        <property name="label" translatable="yes">Reduce screen brightness when computer is inactive for:</property>
+                                      </widget>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkHScale" id="hscale2">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="adjustment">0 0 100 1 10 10</property>
+                                        <property name="digits">0</property>
+                                        <property name="value_pos">GTK_POS_BOTTOM</property>
+                                      </widget>
+                                      <packing>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                  </widget>
+                                </child>
+                              </widget>
+                            </child>
+                            <child>
+                              <widget class="GtkLabel" id="label16">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Brightness&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </widget>
+                              <packing>
+                                <property name="type">label_item</property>
+                              </packing>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="label7">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Running on AC</property>
+                      </widget>
+                      <packing>
+                        <property name="type">tab</property>
+                        <property name="position">1</property>
+                        <property name="tab_fill">False</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkVBox" id="vbox15">
+                        <property name="visible">True</property>
+                        <child>
+                          <widget class="GtkVBox" id="vbox3">
+                            <property name="visible">True</property>
+                            <child>
+                              <widget class="GtkFrame" id="frame2">
+                                <property name="visible">True</property>
+                                <property name="label_xalign">0</property>
+                                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                                <child>
+                                  <widget class="GtkAlignment" id="alignment3">
+                                    <property name="visible">True</property>
+                                    <property name="top_padding">5</property>
+                                    <property name="left_padding">15</property>
+                                    <child>
+                                      <widget class="GtkVBox" id="vbox6">
+                                        <property name="visible">True</property>
+                                        <property name="spacing">2</property>
+                                        <child>
+                                          <widget class="GtkTable" id="table2">
+                                            <property name="visible">True</property>
+                                            <property name="n_rows">2</property>
+                                            <property name="n_columns">2</property>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox12">
+                                                <property name="visible">True</property>
+                                                <child>
+                                                  <widget class="GtkComboBox" id="on-battery-lid">
+                                                    <property name="visible">True</property>
+                                                    <property name="items" translatable="yes">Nothing</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="left_attach">1</property>
+                                                <property name="right_attach">2</property>
+                                                <property name="top_attach">1</property>
+                                                <property name="bottom_attach">2</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox11">
+                                                <property name="visible">True</property>
+                                                <child>
+                                                  <widget class="GtkComboBox" id="battery-critical-combox">
+                                                    <property name="visible">True</property>
+                                                    <property name="items" translatable="yes">Nothing</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="left_attach">1</property>
+                                                <property name="right_attach">2</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox5">
+                                                <property name="visible">True</property>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label13">
+                                                    <property name="visible">True</property>
+                                                    <property name="label" translatable="yes">When laptop lid is closed:</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="top_attach">1</property>
+                                                <property name="bottom_attach">2</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox2">
+                                                <property name="visible">True</property>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label1">
+                                                    <property name="visible">True</property>
+                                                    <property name="label" translatable="yes">When battery power is critical:</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkCheckButton" id="power-save">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="label" translatable="yes">Prefer power savings over performance</property>
+                                            <property name="response_id">0</property>
+                                            <property name="draw_indicator">True</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                    </child>
+                                  </widget>
+                                </child>
+                                <child>
+                                  <widget class="GtkLabel" id="label6">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">&lt;b&gt;Actions&lt;/b&gt;</property>
+                                    <property name="use_markup">True</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="type">label_item</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="padding">10</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <widget class="GtkFrame" id="dpms-on-battery-frame">
+                                <property name="label_xalign">0</property>
+                                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                                <child>
+                                  <widget class="GtkAlignment" id="alignment2">
+                                    <property name="visible">True</property>
+                                    <property name="top_padding">5</property>
+                                    <property name="left_padding">15</property>
+                                    <child>
+                                      <widget class="GtkVBox" id="vbox5">
+                                        <property name="visible">True</property>
+                                        <property name="spacing">20</property>
+                                        <child>
+                                          <widget class="GtkVBox" id="vbox9">
+                                            <property name="visible">True</property>
+                                            <child>
+                                              <widget class="GtkLabel" id="label17">
+                                                <property name="visible">True</property>
+                                                <property name="label" translatable="yes">Put display to sleep when computer is inactive for:</property>
+                                              </widget>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkHScale" id="sleep-dpms-on-battery">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="adjustment">0 0 60 1 10 10</property>
+                                                <property name="show_fill_level">True</property>
+                                                <property name="digits">0</property>
+                                                <property name="value_pos">GTK_POS_BOTTOM</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkVBox" id="vbox10">
+                                            <property name="visible">True</property>
+                                            <child>
+                                              <widget class="GtkLabel" id="label18">
+                                                <property name="visible">True</property>
+                                                <property name="label" translatable="yes">Switch off display when computer is inactive for:</property>
+                                              </widget>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkHScale" id="off-dpms-on-battery">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="adjustment">0 0 60 1 10 10</property>
+                                                <property name="show_fill_level">True</property>
+                                                <property name="digits">0</property>
+                                                <property name="value_pos">GTK_POS_BOTTOM</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                    </child>
+                                  </widget>
+                                </child>
+                                <child>
+                                  <widget class="GtkLabel" id="label19">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">&lt;b&gt;Monitor&lt;/b&gt;</property>
+                                    <property name="use_markup">True</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="type">label_item</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <widget class="GtkFrame" id="frame3">
+                                <property name="visible">True</property>
+                                <property name="label_xalign">0</property>
+                                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                                <child>
+                                  <widget class="GtkAlignment" id="alignment4">
+                                    <property name="visible">True</property>
+                                    <property name="top_padding">5</property>
+                                    <property name="left_padding">15</property>
+                                    <child>
+                                      <widget class="GtkVBox" id="vbox7">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label20">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">Reduce screen brightness when computer is inactive for:</property>
+                                          </widget>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkHScale" id="hscale1">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="adjustment">0 0 100 1 10 10</property>
+                                            <property name="digits">0</property>
+                                            <property name="value_pos">GTK_POS_BOTTOM</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkHBox" id="hbox3">
+                                            <property name="visible">True</property>
+                                            <child>
+                                              <placeholder/>
+                                            </child>
+                                            <child>
+                                              <placeholder/>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="position">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkHBox" id="hbox6">
+                                            <property name="visible">True</property>
+                                            <child>
+                                              <placeholder/>
+                                            </child>
+                                            <child>
+                                              <placeholder/>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="position">3</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                    </child>
+                                  </widget>
+                                </child>
+                                <child>
+                                  <widget class="GtkLabel" id="label21">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">&lt;b&gt;Brightness&lt;/b&gt;</property>
+                                    <property name="use_markup">True</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="type">label_item</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">2</property>
+                              </packing>
+                            </child>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="label3">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Running on battery</property>
+                      </widget>
+                      <packing>
+                        <property name="type">tab</property>
+                        <property name="position">2</property>
+                        <property name="tab_fill">False</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">GTK_BUTTONBOX_EDGE</property>
+            <child>
+              <widget class="GtkButton" id="button2">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-help</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkButton" id="button1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-close</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">GTK_PACK_END</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>
diff --git a/src/xfpm-settings.h b/settings/xfpm-settings.h
similarity index 56%
rename from src/xfpm-settings.h
rename to settings/xfpm-settings.h
index 5e83939b..4f7bdc07 100644
--- a/src/xfpm-settings.h
+++ b/settings/xfpm-settings.h
@@ -1,6 +1,5 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@xfce.org>
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -16,22 +15,15 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifndef __XFPM_SETTINGS_H
 #define __XFPM_SETTINGS_H
 
-#include <xfconf/xfconf.h>
 
-GtkWidget *xfpm_settings_new(XfconfChannel *channel,
-                             gboolean is_laptop,
-                             guint8 power_management,
-                             gboolean dpms_capable,
-                             guint8 govs,
-                             guint8 switch_buttons,
-                             gboolean lcd,
-                             gboolean ups_found);
+GtkWidget *	xfpm_settings_dialog_new 	(XfconfChannel *channel);
+
 
 
 #endif /* __XFPM_SETTINGS_H */
diff --git a/src/Makefile.am b/src/Makefile.am
index 231eeddb..23020c18 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,52 +1,50 @@
-bin_PROGRAMS = xfce4-power-manager		\
-	       xfce4-power-manager-settings
+bin_PROGRAMS = xfce4-power-manager
 
-generated_files =				\
+xfce4_power_manager_SOURCES = 			\
 	xfpm-enum-types.c			\
 	xfpm-enum-types.h			\
 	xfpm-marshal.c				\
-	xfpm-marshal.h
-
-
-xfce4_power_manager_SOURCES = 			\
-	$(generated_files)			\
+	xfpm-marshal.h				\
 	xfce-power-manager-dbus-server.h	\
 	xfce-power-manager-dbus-client.h	\
 	xfpm-main.c				\
-	xfpm-debug.h				\
-	xfpm-hal.c  		 		\
-	xfpm-hal.h	     			\
-	xfpm-driver.c				\
-	xfpm-driver.h				\
-	xfpm-ac-adapter.c			\
-	xfpm-ac-adapter.h			\
-	xfpm-cpu.c				\
-	xfpm-cpu.h				\
-	xfpm-lcd-brightness.c			\
-	xfpm-lcd-brightness.h			\
-	xfpm-button.c				\
-	xfpm-button.h				\
-	xfpm-dbus-messages.c			\
-	xfpm-dbus-messages.h			\
+	xfpm-manager.c				\
+	xfpm-manager.h				\
+	xfpm-engine.c				\
+	xfpm-engine.h				\
+	xfpm-supply.c				\
+	xfpm-supply.h				\
+	xfpm-adapter.c				\
+	xfpm-adapter.h				\
 	xfpm-battery.c				\
 	xfpm-battery.h				\
-	xfpm-battery-icon.c			\
-	xfpm-battery-icon.h			\
+	xfpm-battery-info.c			\
+	xfpm-battery-info.h			\
 	xfpm-dpms.c				\
 	xfpm-dpms.h				\
-	xfpm-popups.c           		\
-	xfpm-popups.h           		\
+	xfpm-cpu.c				\
+	xfpm-cpu.h				\
+	xfpm-button-xf86.c			\
+	xfpm-button-xf86.h			\
+	xfpm-lid-hal.c				\
+	xfpm-lid-hal.h				\
+	xfpm-brightness-hal.c			\
+	xfpm-brightness-hal.h			\
+	xfpm-tray-icon.c			\
+	xfpm-tray-icon.h			\
 	xfpm-notify.c				\
 	xfpm-notify.h				\
-	xfpm-enums.h				\
-	xfpm-common.c				\
-	xfpm-common.h				\
-	xfpm-string.c				\
-	xfpm-string.h
+	xfpm-network-manager.c			\
+	xfpm-network-manager.h			\
+	xfpm-config.h				\
+	xfpm-enum.h
+
 
 xfce4_power_manager_CFLAGS =			\
+	-I$(top_srcdir)				\
+	-I$(top_srcdir)/libxfpm			\
 	-DLOCALEDIR=\"$(localedir)\"		\
-	-DG_LOG_DOMAIN=\"xfce4-power-manager\" \
+	-DG_LOG_DOMAIN=\"xfce4-power-manager\" 	\
 	$(GTK_CFLAGS)				\
 	$(GLIB_CFLAGS)				\
 	$(DBUS_CFLAGS)				\
@@ -59,6 +57,9 @@ xfce4_power_manager_CFLAGS =			\
 	$(DPMS_CFLAGS)              	
 
 xfce4_power_manager_LDADD   =			\
+	$(top_builddir)/libxfpm/libxfpmhal.la	\
+	$(top_builddir)/libxfpm/libxfpmdbus.la	\
+	$(top_builddir)/libxfpm/libxfpmcommon.la\
 	$(GTK_LIBS)				\
 	$(GLIB_LIBS)				\
 	$(DBUS_LIBS)				\
@@ -70,53 +71,8 @@ xfce4_power_manager_LDADD   =			\
 	$(LIBNOTIFY_LIBS)			\
 	$(DPMS_LIBS)		
 
-
-xfce4_power_manager_settings_SOURCES =		\
-	xfpm-marshal.c				\
-	xfpm-marshal.h				\
-	xfpm-settings-main.c			\
-	xfpm-settings.c				\
-	xfpm-settings.h				\
-	xfpm-common.c				\
-	xfpm-common.h				\
-	xfpm-enums.h				\
-	xfpm-enum-types.c			\
-	xfpm-enum-types.h			\
-	xfpm-string.c				\
-	xfpm-string.h				\
-	xfpm-spin-button.c			\
-	xfpm-spin-button.h			\
-	xfpm-dpms-spins.c			\
-	xfpm-dpms-spins.h			\
-	xfpm-dbus-messages.c			\
-	xfpm-dbus-messages.h			\
-	xfpm-popups.c				\
-	xfpm-popups.h				\
-	xfpm-debug.h
-
-
-xfce4_power_manager_settings_CFLAGS =		\
-	-DLOCALEDIR=\"$(localedir)\"		\
-	-DG_LOG_DOMAIN=\"xfce4-power-manager-settings\"  \
-	$(GTK_CFLAGS)				\
-	$(GLIB_CFLAGS)				\
-	$(DBUS_CFLAGS)				\
-	$(DBUS_GLIB_CFLAGS)			\
-	$(LIBXFCE4GUI_CFLAGS)			\
-	$(LIBXFCE4UTIL_CFLAGS)			\
-	$(XFCONF_CFLAGS)
-
-xfce4_power_manager_settings_LDADD = 		\
-	$(GTK_LIBS)				\
-	$(GLIB_LIBS)				\
-	$(DBUS_LIBS)				\
-	$(DBUS_GLIB_LIBS)			\
-	$(LIBXFCE4GUI_LIBS)			\
-	$(LIBXFCE4UTIL_LIBS)			\
-	$(XFCONF_LIBS)
-
-xfpm_headers = 					\
-	$(srcdir)/xfpm-enums.h			
+xfpm_glib_headers = 				\
+	$(srcdir)/xfpm-enum-glib.h			
 
 if MAINTAINER_MODE
 
@@ -128,25 +84,25 @@ BUILT_SOURCES = 				\
 	xfpm-enum-types.c			\
 	xfpm-enum-types.h
 
-xfpm-enum-types.h: $(xfpm_headers)
+xfpm-enum-types.h: $(xfpm_glib_headers)
 	( cd $(srcdir) && glib-mkenums \
 		--fhead "#ifndef _XFPM_ENUM_TYPES_H\n#define _XFPM_ENUM_TYPES_H\n#include <glib-object.h>\nG_BEGIN_DECLS\n" \
 		--fprod "/* enumerations from \"@filename@\" */\n" \
 		--vhead "GType @enum_name@_get_type (void);\n#define XFPM_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \
 		--ftail "G_END_DECLS\n\n#endif /* _XFPM_ENUM_TYPES_H__ */" \
-		$(xfpm_headers) ) >> xgen \
+		$(xfpm_glib_headers) ) >> xgen \
 	&& (cmp -s xgen xfpm-enum-types.h || cp xgen xfpm-enum-types.h ) \
 	&& rm -f xgen xgen~
 
 xfpm-enum-types.c: xfpm-enum-types.h
 	( cd $(srcdir) && glib-mkenums \
 		--fhead "#include <xfpm-enum-types.h>\n" \
-		--fhead "#include \"xfpm-enums.h\"\n\n" \
+		--fhead "#include \"xfpm-enum-glib.h\"\n\n" \
 		--fprod "\n/* enumerations from \"@filename@\" */\n" \
 		--vhead "GType\n@enum_name@_get_type (void)\n{\n\tstatic GType type = 0;\n\tif (type == 0) {\n\tstatic const G@Type@Value values[] = {"\
 		--vprod "\t{ @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
 		--vtail "\t{ 0, NULL, NULL }\n\t};\n\ttype = g_@type@_register_static (\"@EnumName@\", values);\n  }\n\treturn type;\n}\n" \
-		$(xfpm_headers) ) > xgen \
+		$(xfpm_glib_headers) ) > xgen \
 	&& cp xgen xfpm-enum-types.c  \
 	&& rm -f xgen xgen~
 
@@ -163,26 +119,16 @@ xfpm-marshal.c: xfpm-marshal.h
         rm -f tmp-marshal.c tmp-marshal.c~
 
 xfce-power-manager-dbus-server.h: $(srcdir)/org.xfce.Power.Manager.xml
-	dbus-binding-tool --mode=glib-server --prefix=xfpm_driver $< >$@
+	dbus-binding-tool --mode=glib-server --prefix=xfpm_manager $< >$@
 
-xfce-power-manager-dbus-client.h: $(srcdir)/org.xfce.Power.Manager.xml
-	dbus-binding-tool --mode=glib-client --prefix=xfpm_client $< >$@
+xfce-power-manager-dbus-client.h: $(srdir)org.xfce.Power.Manager.xml
+	dbus-binding-tool --mode=glib-client --prefix=xfpm_manager $< >$@
 
 endif
 
-#
-# .desktop file
-#
-desktop_in_files = xfce4-power-manager.desktop.in
-desktopdir = $(datadir)/applications
-desktop_DATA =	$(desktop_in_files:.desktop.in=.desktop)
-
-@INTLTOOL_DESKTOP_RULE@
 
 EXTRA_DIST = 					\
-	xfpm-marshal.list			\
-	$(desktop_in_files)
+	xfpm-marshal.list
 
 DISTCLEANFILES =				\
-	$(BUILT_SOURCES)			\
-	$(desktop_DATA)
\ No newline at end of file
+	$(BUILT_SOURCES)
\ No newline at end of file
diff --git a/src/org.xfce.Power.Manager.xml b/src/org.xfce.Power.Manager.xml
index 2f40f677..b9334056 100644
--- a/src/org.xfce.Power.Manager.xml
+++ b/src/org.xfce.Power.Manager.xml
@@ -3,14 +3,14 @@
 <node name="/org/xfce/PowerManager">
     <interface name="org.xfce.Power.Manager">
         <annotation name="org.freedesktop.DBus.GLib.CSymbol"
-                    value="xfpm_driver_dbus"/>
+                    value="xfpm_manager_dbus"/>
         <annotation name="org.freedesktop.DBus.GLib.ClientCSymbol"
-                    value="xfpm_driver_dbus_client"/>   
+                    value="xfpm_manager_dbus_client"/>   
      
     <method name="Quit">
     </method>
     
-    <method name="GetConf">
+    <method name="GetAll">
 	<arg direction="out" name="system_laptop" type="b"/>
 	<arg direction="out" name="power_management" type="i"/>
 	<arg direction="out" name="with_dpms" type="b"/>
diff --git a/src/xfpm-ac-adapter.c b/src/xfpm-ac-adapter.c
deleted file mode 100644
index e01d4504..00000000
--- a/src/xfpm-ac-adapter.c
+++ /dev/null
@@ -1,496 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <gtk/gtkstatusicon.h>
-
-#include <libxfcegui4/libxfcegui4.h>
-#include <libxfce4util/libxfce4util.h>
-
-#include "xfpm-common.h"
-
-#include "xfpm-hal.h"
-#include "xfpm-driver.h"
-#include "xfpm-ac-adapter.h"
-#include "xfpm-marshal.h"
-#include "xfpm-enums.h"
-#include "xfpm-enum-types.h"
-#include "xfpm-notify.h"
-#include "xfpm-debug.h"
-
-#ifndef _
-#define _(x) x
-#endif
-
-#define XFPM_AC_ADAPTER_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE(o,XFPM_TYPE_AC_ADAPTER,XfpmAcAdapterPrivate))
-
-static void xfpm_ac_adapter_init(XfpmAcAdapter *adapter);
-static void xfpm_ac_adapter_class_init(XfpmAcAdapterClass *klass);
-static void xfpm_ac_adapter_finalize(GObject *object);
-
-static gboolean xfpm_ac_adapter_size_changed_cb(GtkStatusIcon *adapter,
-                                                gint size,
-                                                gpointer data);
-static void xfpm_ac_adapter_get_adapter(XfpmAcAdapter *adapter);
-                                        
-static void xfpm_ac_adapter_device_added_cb(XfpmHal *hal,
-                                            const gchar *udi,
-                                            XfpmAcAdapter *adapter);
-
-static void xfpm_ac_adapter_device_removed_cb(XfpmHal *hal,
-                                              const gchar *udi,
-                                              XfpmAcAdapter *adapter);
-                                              
-static void xfpm_ac_adapter_property_changed_cb(XfpmHal *hal,
-                                                const gchar *udi,
-                                                const gchar *key,
-                                                gboolean is_removed,
-                                                gboolean is_added,
-                                                XfpmAcAdapter *adapter);
-static void xfpm_ac_adapter_hibernate_callback(GtkWidget *widget,
-                                               XfpmAcAdapter *adapter);
-static void xfpm_ac_adapter_suspend_callback(GtkWidget *widget,
-                                             XfpmAcAdapter *adapter);  
-static void xfpm_ac_adapter_popup_menu(GtkStatusIcon *tray_icon,
-                                       guint button,
-                                       guint activate_time,
-                                       XfpmAcAdapter *adapter);
-
-struct XfpmAcAdapterPrivate
-{
-    XfpmHal *hal;
-    SystemFormFactor factor;
-    
-    GQuark adapter_udi;
-    gboolean present;
-    gboolean adapter_found;
-    
-    guint8 power_management;
-        
-};
-
-enum 
-{
-    XFPM_AC_ADAPTER_CHANGED,
-    XFPM_ACTION_REQUEST,
-    LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0,};    
-
-G_DEFINE_TYPE(XfpmAcAdapter,xfpm_ac_adapter,GTK_TYPE_STATUS_ICON)
-
-static void
-xfpm_ac_adapter_class_init(XfpmAcAdapterClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-    
-    gobject_class->finalize = xfpm_ac_adapter_finalize;
-    
-    signals[XFPM_AC_ADAPTER_CHANGED] = g_signal_new("xfpm-ac-adapter-changed",
-                                                   XFPM_TYPE_AC_ADAPTER,
-                                                   G_SIGNAL_RUN_LAST,
-                                                   G_STRUCT_OFFSET(XfpmAcAdapterClass,ac_adapter_changed),
-                                                   NULL,NULL,
-                                                   _xfpm_marshal_VOID__BOOLEAN_BOOLEAN,
-                                                   G_TYPE_NONE,2,
-                                                   G_TYPE_BOOLEAN,G_TYPE_BOOLEAN);
-    
-    signals[XFPM_ACTION_REQUEST] = g_signal_new("xfpm-action-request",
-                                               XFPM_TYPE_AC_ADAPTER,
-                                               G_SIGNAL_RUN_LAST,
-                                               G_STRUCT_OFFSET(XfpmAcAdapterClass,adapter_action_request),
-                                               NULL,NULL,
-                                               _xfpm_marshal_VOID__ENUM_BOOLEAN ,
-                                               G_TYPE_NONE,2,
-                                               XFPM_TYPE_ACTION_REQUEST,G_TYPE_BOOLEAN);
-                                               
-    g_type_class_add_private(klass,sizeof(XfpmAcAdapterPrivate));
-    
-}
-
-static void
-xfpm_ac_adapter_init(XfpmAcAdapter *adapter)
-{
-    XfpmAcAdapterPrivate *priv;
-    priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-    
-    priv->hal = xfpm_hal_new();
-    priv->adapter_udi = 0 ;
-
-    priv->power_management = 0 ;
-        
-    g_signal_connect(adapter,"size-changed",
-                    G_CALLBACK(xfpm_ac_adapter_size_changed_cb),NULL);
-    g_signal_connect(adapter,"popup-menu",
-                    G_CALLBACK(xfpm_ac_adapter_popup_menu),adapter);
-}
-
-static void
-xfpm_ac_adapter_finalize(GObject *object)
-{
-    XfpmAcAdapter *adapter = XFPM_AC_ADAPTER(object);
-    adapter->priv = XFPM_AC_ADAPTER_GET_PRIVATE(object);
-   
-    if ( adapter->priv->hal )
-    {
-        g_object_unref(adapter->priv->hal);
-    }
-    
-    G_OBJECT_CLASS(xfpm_ac_adapter_parent_class)->finalize(object);
-}
-
-static gboolean
-xfpm_ac_adapter_size_changed_cb(GtkStatusIcon *adapter,gint size,gpointer data)
-{
-    if ( size > 128 )
-    {
-        size = 48;
-    }
-
-    GdkPixbuf *icon;
-    icon = xfpm_load_icon("gpm-ac-adapter",size);
-    
-    if ( icon )
-    {
-        gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(adapter),icon);
-        g_object_unref(G_OBJECT(icon));
-        return TRUE;
-    } 
-    return FALSE;
-}
-
-static void
-_ac_adapter_not_found(XfpmAcAdapter *adapter)
-{
-    XfpmAcAdapterPrivate *priv;
-    priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-    
-    /* then most probably the ac kernel module is not loaded */
-    if ( priv->factor == SYSTEM_LAPTOP )
-    {
-        priv->present = TRUE; /* assuming present */
-        priv->adapter_found = FALSE;
-        gtk_status_icon_set_tooltip(GTK_STATUS_ICON(adapter),
-                                   _("Unable to read adapter status, the power manager will not work properly"));
-    }     
-    else  
-    {
-        priv->present = TRUE; /* just for eveything to function correctly */
-        priv->adapter_found = TRUE;
-    }
-    g_signal_emit(G_OBJECT(adapter),signals[XFPM_AC_ADAPTER_CHANGED],0,
-                  priv->present,priv->adapter_found);
-    
-}
-
-static void
-xfpm_ac_adapter_get_adapter(XfpmAcAdapter *adapter)
-{
-    XfpmAcAdapterPrivate *priv;
-    priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-    
-    priv->adapter_udi = 0 ;
-    
-    gchar **udi = NULL;
-    gint num;
-    GError *error = NULL;
-    
-    udi = xfpm_hal_get_device_udi_by_capability(priv->hal,"ac_adapter",&num,&error);
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    
-    if ( num == 0 )
-    {
-        priv->present = TRUE;
-        XFPM_DEBUG("No ac adapter device found\n");
-        _ac_adapter_not_found(adapter);
-        return;
-    }
-    
-    if ( !udi ) 
-    {
-        _ac_adapter_not_found(adapter);
-        return;
-    }
-    
-    int i;
-    for ( i = 0 ; udi[i]; i++)
-    {
-        if ( xfpm_hal_device_have_key(priv->hal,udi[i],"ac_adapter.present"))
-        {
-            priv->present = xfpm_hal_get_bool_info(priv->hal,
-                                                  udi[i],
-                                                 "ac_adapter.present",
-                                                  &error);
-            if ( error ) 
-            {
-                XFPM_DEBUG("%s:\n",error->message);
-                g_error_free(error);
-                return;
-            }                                                 
-            XFPM_DEBUG("Getting udi %s\n",udi[i]);
-            priv->adapter_udi = g_quark_from_string(udi[i]);
-            priv->adapter_found = TRUE;
-            break;
-        }
-    }
-    
-    gtk_status_icon_set_tooltip(GTK_STATUS_ICON(adapter),
-                priv->present ? _("Adapter is online") : _("Adapter is offline"));   
-    g_signal_emit(G_OBJECT(adapter),signals[XFPM_AC_ADAPTER_CHANGED],0,priv->present,priv->adapter_found);
-    libhal_free_string_array(udi);
-}
-
-static void
-_get_adapter_status(XfpmAcAdapter *adapter,const gchar *udi)
-{
-    XfpmAcAdapterPrivate *priv;
-    priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-    GError *error = NULL;
-    gboolean ac_adapter = 
-    xfpm_hal_get_bool_info(priv->hal,udi,"ac_adapter.present",&error);
-    if ( error )                                        
-    {
-        XFPM_DEBUG("%s\n",error->message);
-        g_error_free(error);
-        return;
-    }       
-    XFPM_DEBUG("Ac adapter changed %d\n",ac_adapter);
-    priv->present = ac_adapter;
-    gtk_status_icon_set_tooltip(GTK_STATUS_ICON(adapter),
-                priv->present ? _("Adapter is online") : _("Adapter is offline"));   
-    g_signal_emit(G_OBJECT(adapter),signals[XFPM_AC_ADAPTER_CHANGED],0,
-                  priv->present,priv->adapter_found);
-}
-
-static void
-xfpm_ac_adapter_device_added_cb(XfpmHal *hal,const gchar *udi,XfpmAcAdapter *adapter)
-{
-    if ( xfpm_hal_device_have_key(hal,udi,"ac_adapter.present"))
-    {
-        XfpmAcAdapterPrivate *priv;
-        priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-        priv->adapter_found = TRUE;
-        priv->adapter_udi = g_quark_from_string(udi);
-    
-        _get_adapter_status(adapter,udi);
-    }
-}
-
-static void
-xfpm_ac_adapter_device_removed_cb(XfpmHal *hal,const gchar *udi,XfpmAcAdapter *adapter)
-{
-    XfpmAcAdapterPrivate *priv;
-    priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-    
-    if ( priv->adapter_udi == g_quark_from_string(udi) ) 
-    {
-        XFPM_DEBUG("Adapter removed\n");
-        xfpm_ac_adapter_get_adapter(adapter);
-    }
-}
-
-static void
-xfpm_ac_adapter_property_changed_cb(XfpmHal *hal,const gchar *udi,
-                                    const gchar *key,gboolean is_removed,
-                                    gboolean is_added,XfpmAcAdapter *adapter)
-{   
-    if ( xfpm_hal_device_have_key(hal,udi,"ac_adapter.present"))
-    {
-        XfpmAcAdapterPrivate *priv;
-        priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-        _get_adapter_status(adapter,udi);
-        
-    }
-}
-
-static void
-xfpm_ac_adapter_hibernate_callback(GtkWidget *widget,XfpmAcAdapter *adapter)
-{
-    gboolean ret = 
-    xfce_confirm(_("Are you sure you want to hibernate the system?"),
-                GTK_STOCK_YES,
-                _("Hibernate"));
-    
-    if ( ret ) 
-    {
-        g_signal_emit(G_OBJECT(adapter),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_HIBERNATE,FALSE);
-	}
-}
-
-static void
-xfpm_ac_adapter_suspend_callback(GtkWidget *widget,XfpmAcAdapter *adapter)
-{
-    gboolean ret = 
-    xfce_confirm(_("Are you sure you want to suspend the system?"),
-                GTK_STOCK_YES,
-                _("Suspend"));
-    
-    if ( ret ) 
-    {
-        g_signal_emit(G_OBJECT(adapter),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_SUSPEND,FALSE);
-    }
-}
-
-static void 
-xfpm_ac_adapter_popup_menu(GtkStatusIcon *tray_icon,
-                           guint button,
-                           guint activate_time,
-                           XfpmAcAdapter *adapter)
-{
-    XfpmAcAdapterPrivate *priv;
-    priv = XFPM_AC_ADAPTER_GET_PRIVATE(XFPM_AC_ADAPTER(tray_icon));
-    
-    GtkWidget *menu,*mi,*img;
-	
-	menu = gtk_menu_new();
-
-	// Hibernate menu option
-	mi = gtk_image_menu_item_new_with_label(_("Hibernate"));
-	img = gtk_image_new_from_icon_name("gpm-hibernate",GTK_ICON_SIZE_MENU);
-	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi),img);
-	gtk_widget_set_sensitive(mi,FALSE);
-	
-	
-	if ( priv->power_management & SYSTEM_CAN_HIBERNATE )
-	{
-		gtk_widget_set_sensitive(mi,TRUE);
-		g_signal_connect(mi,"activate",
-					 	 G_CALLBACK(xfpm_ac_adapter_hibernate_callback),
-					 	 adapter);
-	}
-	gtk_widget_show(mi);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	// Suspend menu option
-	mi = gtk_image_menu_item_new_with_label(_("Suspend"));
-	img = gtk_image_new_from_icon_name("gpm-suspend",GTK_ICON_SIZE_MENU);
-	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi),img);
-	
-	gtk_widget_set_sensitive(mi,FALSE);
-	if ( priv->power_management & SYSTEM_CAN_SUSPEND )
-    {	
-		gtk_widget_set_sensitive(mi,TRUE);
-		g_signal_connect(mi,"activate",
-					     G_CALLBACK(xfpm_ac_adapter_suspend_callback),
-					     adapter);
-	}
-	gtk_widget_show(mi);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	// Separotor
-	mi = gtk_separator_menu_item_new();
-	gtk_widget_show(mi);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-
-	mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP,NULL);
-	gtk_widget_set_sensitive(mi,TRUE);
-	gtk_widget_show(mi);
-	g_signal_connect(mi,"activate",G_CALLBACK(xfpm_help),NULL);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT,NULL);
-	gtk_widget_set_sensitive(mi,TRUE);
-	gtk_widget_show(mi);
-	g_signal_connect(mi,"activate",G_CALLBACK(xfpm_about),NULL);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_PREFERENCES,NULL);
-	gtk_widget_set_sensitive(mi,TRUE);
-	gtk_widget_show(mi);
-	g_signal_connect(mi,"activate",G_CALLBACK(xfpm_preferences),NULL);
-	
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	// Popup the menu
-	gtk_menu_popup(GTK_MENU(menu),NULL,NULL,
-		       gtk_status_icon_position_menu,tray_icon,button,activate_time);
-}                                             
-
-GtkStatusIcon *
-xfpm_ac_adapter_new(gboolean visible)
-{
-    XfpmAcAdapter *adapter = NULL;
-    adapter = g_object_new(XFPM_TYPE_AC_ADAPTER,"visible",visible,NULL);
-    return GTK_STATUS_ICON(adapter);
-}
-
-void
-xfpm_ac_adapter_monitor(XfpmAcAdapter *adapter,SystemFormFactor factor)
-{
-    XfpmAcAdapterPrivate *priv;
-    priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-    priv->factor = factor;
-    xfpm_ac_adapter_get_adapter(adapter);
-    
-    if ( factor == SYSTEM_LAPTOP )
-    {
-        if (xfpm_hal_connect_to_signals(priv->hal,TRUE,TRUE,TRUE,FALSE) )
-        {
-            g_signal_connect(priv->hal,"xfpm-device-added",
-                        G_CALLBACK(xfpm_ac_adapter_device_added_cb),adapter);
-            g_signal_connect(priv->hal,"xfpm-device-removed",
-                        G_CALLBACK(xfpm_ac_adapter_device_removed_cb),adapter); 
-            g_signal_connect(priv->hal,"xfpm-device-property-changed",
-                         G_CALLBACK(xfpm_ac_adapter_property_changed_cb),adapter);            
-        }             
-    }
-}   
-
-
-void           
-xfpm_ac_adapter_set_sleep_info (XfpmAcAdapter *adapter,
-                                guint8 sleep_info)
-{
-    g_return_if_fail(XFPM_IS_AC_ADAPTER(adapter));
-    XfpmAcAdapterPrivate *priv;
-    priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
-
-    priv->power_management = sleep_info;    
-}
diff --git a/src/xfpm-ac-adapter.h b/src/xfpm-ac-adapter.h
deleted file mode 100644
index 3d225dc3..00000000
--- a/src/xfpm-ac-adapter.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __XFPM_AC_ADAPTER_H
-#define __XFPM_AC_ADAPTER_H
-
-#include <glib.h>
-#include <gtk/gtk.h>
-
-#define XFPM_TYPE_AC_ADAPTER    (xfpm_ac_adapter_get_type())
-#define XFPM_AC_ADAPTER(o)      (G_TYPE_CHECK_INSTANCE_CAST(o,XFPM_TYPE_AC_ADAPTER,XfpmAcAdapter))
-#define XFPM_IS_AC_ADAPTER(o)   (G_TYPE_CHECK_INSTANCE_TYPE(o,XFPM_TYPE_AC_ADAPTER))
-
-typedef struct XfpmAcAdapterPrivate XfpmAcAdapterPrivate;
-
-typedef struct
-{
-    GtkStatusIcon parent;
-    XfpmAcAdapterPrivate *priv;
-    
-} XfpmAcAdapter;
-
-typedef struct
-{
-    GtkStatusIconClass parent_class;
-    
-    /* signals */
-    void   (*ac_adapter_changed)  (XfpmAcAdapter *xfpm_adapter,
-                                   gboolean present,
-                                   gboolean state_ok);
-                                   
-    void  (*adapter_action_request) (XfpmAcAdapter *adapter,
-                                     XfpmActionRequest action,
-                                     gboolean critical);                               
-} XfpmAcAdapterClass;
-
-GType          xfpm_ac_adapter_get_type       (void) G_GNUC_CONST;
-GtkStatusIcon *xfpm_ac_adapter_new            (gboolean visible);
-void           xfpm_ac_adapter_monitor        (XfpmAcAdapter *adapter,
-                                               SystemFormFactor factor);
-void           xfpm_ac_adapter_set_sleep_info (XfpmAcAdapter *adapter,
-                                               guint8 sleep_info);
-#endif
diff --git a/src/xfpm-adapter.c b/src/xfpm-adapter.c
new file mode 100644
index 00000000..8469bd4d
--- /dev/null
+++ b/src/xfpm-adapter.c
@@ -0,0 +1,167 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <glib.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "libxfpm/xfpm-string.h"
+
+#include "xfpm-adapter.h"
+#include "xfpm-tray-icon.h"
+
+/* Init */
+static void xfpm_adapter_class_init (XfpmAdapterClass *klass);
+static void xfpm_adapter_init       (XfpmAdapter *adapter);
+static void xfpm_adapter_finalize   (GObject *object);
+
+#define XFPM_ADAPTER_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_ADAPTER, XfpmAdapterPrivate))
+
+struct XfpmAdapterPrivate
+{
+    XfpmTrayIcon *icon;
+    HalDevice    *device;
+};
+
+enum
+{
+    ADAPTER_CHANGED,
+    LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE(XfpmAdapter, xfpm_adapter, G_TYPE_OBJECT)
+
+static void
+xfpm_adapter_class_init(XfpmAdapterClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    signals[ADAPTER_CHANGED] = 
+    	g_signal_new("adapter-changed",
+                      XFPM_TYPE_ADAPTER,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET(XfpmAdapterClass, adapter_changed),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__BOOLEAN,
+                      G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+		      
+    object_class->finalize = xfpm_adapter_finalize;
+
+
+    g_type_class_add_private (klass, sizeof(XfpmAdapterPrivate));
+}
+
+static void
+xfpm_adapter_init(XfpmAdapter *adapter)
+{
+    adapter->priv = XFPM_ADAPTER_GET_PRIVATE(adapter);
+    
+    adapter->priv->device = NULL;
+    
+    adapter->priv->icon = xfpm_tray_icon_new ();
+    xfpm_tray_icon_set_visible (adapter->priv->icon, FALSE);
+    xfpm_tray_icon_set_icon (adapter->priv->icon, "gpm-ac-adapter");
+}
+
+static void
+xfpm_adapter_finalize(GObject *object)
+{
+    XfpmAdapter *adapter;
+
+    adapter = XFPM_ADAPTER(object);
+    
+    if ( adapter->priv->icon )
+    	g_object_unref (adapter->priv->icon);
+	
+    if ( adapter->priv->device)
+    	g_object_unref (adapter->priv->device);
+
+    G_OBJECT_CLASS(xfpm_adapter_parent_class)->finalize(object);
+}
+
+static void
+xfpm_adapter_device_changed_cb (HalDevice *device, XfpmAdapter *adapter)
+{
+    gboolean is_present =
+    	xfpm_adapter_get_presence (adapter);
+    
+    TRACE("Adapter changed is_present =%s", xfpm_bool_to_string(is_present));
+    
+    g_signal_emit (G_OBJECT(adapter), signals[ADAPTER_CHANGED], 0, is_present);
+}
+
+XfpmAdapter *
+xfpm_adapter_new (const HalDevice *device)
+{
+    XfpmAdapter *adapter = NULL;
+    adapter = g_object_new (XFPM_TYPE_ADAPTER, NULL);
+    
+    adapter->priv->device = g_object_ref (G_OBJECT(device));
+    
+    g_signal_connect (adapter->priv->device, "device-changed", 
+		      G_CALLBACK (xfpm_adapter_device_changed_cb),
+		      adapter);
+    
+    return adapter;
+}
+
+gboolean xfpm_adapter_get_presence (XfpmAdapter *adapter)
+{
+    gboolean is_present;
+    g_object_get (G_OBJECT(adapter->priv->device), "is-present", &is_present, NULL);
+    return is_present;
+}
+
+void xfpm_adapter_set_visible (XfpmAdapter *adapter, gboolean visible)
+{
+    g_return_if_fail ( XFPM_IS_ADAPTER (adapter));
+    
+    xfpm_tray_icon_set_visible(adapter->priv->icon, visible);
+    
+}
+
+void xfpm_adapter_set_tooltip (XfpmAdapter *adapter, const gchar *text)
+{
+     g_return_if_fail ( XFPM_IS_ADAPTER (adapter));
+    
+    xfpm_tray_icon_set_tooltip (adapter->priv->icon, text);
+    
+}
diff --git a/src/xfpm-adapter.h b/src/xfpm-adapter.h
new file mode 100644
index 00000000..c04ff7f2
--- /dev/null
+++ b/src/xfpm-adapter.h
@@ -0,0 +1,62 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_ADAPTER_H
+#define __XFPM_ADAPTER_H
+
+#include <glib-object.h>
+
+#include "libxfpm/hal-device.h"
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_ADAPTER        (xfpm_adapter_get_type () )
+#define XFPM_ADAPTER(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_ADAPTER, XfpmAdapter))
+#define XFPM_IS_ADAPTER(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_ADAPTER))
+
+typedef struct XfpmAdapterPrivate XfpmAdapterPrivate;
+
+typedef struct
+{
+    GObject		  parent;
+    XfpmAdapterPrivate	 *priv;
+    
+} XfpmAdapter;
+
+typedef struct
+{
+    GObjectClass 	  parent_class;
+    
+    void                 (*adapter_changed)    (XfpmAdapter *adapter,
+    						gboolean present);
+    
+} XfpmAdapterClass;
+
+GType        	  xfpm_adapter_get_type        (void) G_GNUC_CONST;
+XfpmAdapter      *xfpm_adapter_new             (const HalDevice *device);
+gboolean          xfpm_adapter_get_presence    (XfpmAdapter *adapter);
+
+void              xfpm_adapter_set_visible     (XfpmAdapter *adapter,
+						gboolean visible);
+void              xfpm_adapter_set_tooltip     (XfpmAdapter *adapter,
+						const gchar *text);
+G_END_DECLS
+
+#endif /* __XFPM_ADAPTER_H */
diff --git a/src/xfpm-battery-icon.c b/src/xfpm-battery-icon.c
deleted file mode 100644
index 34f43e15..00000000
--- a/src/xfpm-battery-icon.c
+++ /dev/null
@@ -1,626 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#include <gtk/gtk.h>
-
-#include <glib.h>
-
-#include <libxfce4util/libxfce4util.h>
-
-#include "xfpm-battery-icon.h"
-#include "xfpm-notify.h"
-#include "xfpm-debug.h"
-#include "xfpm-common.h"
-#include "xfpm-enum-types.h"
-
-/* init */
-static void xfpm_battery_icon_init(XfpmBatteryIcon *battery_icon);
-static void xfpm_battery_icon_class_init(XfpmBatteryIconClass *klass);
-static void xfpm_battery_icon_finalize(GObject *object);
-
-static void xfpm_battery_icon_set_property(GObject *object,
-                                           guint prop_id,
-                                           const GValue *value,
-                                           GParamSpec *pspec);
-static void xfpm_battery_icon_get_property(GObject *object,
-                                        guint prop_id,
-                                        GValue *value,
-                                        GParamSpec *pspec);
-
-static gboolean   xfpm_battery_icon_size_change_cb(XfpmBatteryIcon *battery_icon,
-                                                   gint size,
-                                                   gpointer data);
-                                                
-static const gchar *xfpm_battery_icon_get_index(XfpmBatteryType type,
-                                                guint percent);
-
-static gchar *    xfpm_battery_icon_get_icon_prefix (XfpmBatteryType type);
-
-static void       xfpm_battery_icon_update (XfpmBatteryIcon *battery_icon,
-                                            XfpmBatteryState state,
-                                            guint level,
-                                            gboolean adapter_present);
-
-G_DEFINE_TYPE(XfpmBatteryIcon,xfpm_battery_icon,GTK_TYPE_STATUS_ICON)
-
-enum
-{
-    PROP_0,
-    PROP_BATTERY_TYPE,
-    PROP_BATTERY_STATE,
-    PROP_LAST_FULL,
-    PROP_BATT_CRITICAL,
-#ifdef HAVE_LIBNOTIFY
-    PROP_NOTIFY
-#endif        
-};
-
-static void
-xfpm_battery_icon_class_init(XfpmBatteryIconClass *klass) 
-{
-    GObjectClass *object_class = G_OBJECT_CLASS(klass);
-    
-    object_class->get_property = xfpm_battery_icon_get_property;
-    object_class->set_property = xfpm_battery_icon_set_property;
-    object_class->finalize = xfpm_battery_icon_finalize;
-    
-    g_object_class_install_property(object_class,
-                                    PROP_BATTERY_TYPE,
-                                    g_param_spec_enum("battery-type",
-                                                      "Battery type",
-                                                      "Battery typed",
-                                                      XFPM_TYPE_BATTERY_TYPE,
-                                                      PRIMARY, 
-                                                      G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
-    g_object_class_install_property(object_class,
-                                    PROP_BATTERY_STATE,
-                                    g_param_spec_enum("battery-state",
-                                                      "Battery state",
-                                                      "Battery state",
-                                                      XFPM_TYPE_BATTERY_STATE,
-                                                      0, /* Defaul not present */
-                                                      G_PARAM_READWRITE));
-
-    g_object_class_install_property(object_class,
-                                    PROP_LAST_FULL,
-                                    g_param_spec_uint("last-full",
-                                                      "Last full",
-                                                      "Last battery full charge",
-                                                      0,
-                                                      G_MAXUINT32,
-                                                      4000,
-                                                      G_PARAM_READWRITE|G_PARAM_CONSTRUCT ));
-    
-    g_object_class_install_property(object_class,
-                                    PROP_BATT_CRITICAL,
-                                    g_param_spec_uint("batt-critical-level",
-                                                      "Battery critical level",
-                                                      "Low battery level",
-                                                      1,
-                                                      20,
-                                                      10,
-                                                      G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
-    
-#ifdef HAVE_LIBNOTIFY
-    g_object_class_install_property(object_class,
-                                    PROP_NOTIFY,
-                                    g_param_spec_boolean("systray-notify",
-                                                         "systray-notify",
-                                                         "systray notification",
-                                                         FALSE,
-                                                         G_PARAM_READWRITE));
-#endif
-                                                                                                           
-}
-
-static void
-xfpm_battery_icon_init(XfpmBatteryIcon *battery_icon)
-{
-
-    g_signal_connect(battery_icon,"size-changed",
-                     G_CALLBACK(xfpm_battery_icon_size_change_cb),NULL);
-    
-    /* This is only use when the power manager loads, just for the tray icon to take it's 
-     * place in the panel */
-#ifdef HAVE_LIBNOTIFY    
-    battery_icon->discard_notification = TRUE;
-#endif
-    battery_icon->icon    = -1;
-    battery_icon->icon_loaded = FALSE;
-	battery_icon->icon_size   = 1;
-}
-
-static void xfpm_battery_icon_set_property(GObject *object,
-                                        guint prop_id,
-                                        const GValue *value,
-                                        GParamSpec *pspec)
-{
-    XfpmBatteryIcon *icon;
-    icon = XFPM_BATTERY_ICON(object);
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif            
-    switch (prop_id)
-    {
-        case PROP_BATTERY_TYPE:
-            icon->type = g_value_get_enum(value);
-            break;    
-        case PROP_BATTERY_STATE:
-            icon->state = g_value_get_enum(value);
-            break;
-        case PROP_LAST_FULL:
-            icon->last_full = g_value_get_uint(value);
-            break;
-        case PROP_BATT_CRITICAL:
-            icon->critical_level = g_value_get_uint(value);
-            break;      
-#ifdef HAVE_LIBNOTIFY              
-        case PROP_NOTIFY:
-            icon->notify = g_value_get_boolean(value);
-            break;
-#endif            
-        default:
-            G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-            break;
-    }                                    
-}
-
-static void xfpm_battery_icon_get_property(GObject *object,
-                                        guint prop_id,
-                                        GValue *value,
-                                        GParamSpec *pspec)
-{
-    XfpmBatteryIcon *icon;
-    icon = XFPM_BATTERY_ICON(object);
-    
-    switch (prop_id)
-    {
-        case PROP_BATTERY_TYPE:
-            g_value_set_enum(value,icon->type);
-            break;
-        case PROP_BATTERY_STATE:
-            g_value_set_enum(value,icon->state);
-            break;
-        case PROP_LAST_FULL:
-            g_value_set_uint(value,icon->last_full);
-            break;
-        case PROP_BATT_CRITICAL:
-            g_value_set_uint(value,icon->critical_level);
-            break; 
-#ifdef HAVE_LIBNOTIFY              
-        case PROP_NOTIFY:
-            g_value_set_boolean(value,icon->notify);
-            break;
-#endif            
-        default:
-            G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-            break;
-    }                 
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif     
-    
-}
-                                        
-static void
-xfpm_battery_icon_finalize(GObject *object)
-{
-    XfpmBatteryIcon *icon;
-    icon = XFPM_BATTERY_ICON(object);
-    
-    G_OBJECT_CLASS(xfpm_battery_icon_parent_class)->finalize(object);
-}
-
-static gboolean
-xfpm_battery_icon_size_change_cb(XfpmBatteryIcon *battery_icon,gint size,gpointer data)
-{
-    XFPM_DEBUG("size change event %d\n",size);
-	
-	if ( size == 1 )
-	{
-		/*Panel is in hidden mode*/
-		battery_icon->icon_size = 1;
-		return TRUE;
-	}
-    if ( size > 128 )
-    {
-        /* Reduce the size until we get the correct size of the system tray */
-        battery_icon->icon_size = 48;
-    }
-	else
-	{
-		battery_icon->icon_size = size;
-	}
-    
-	if ( battery_icon->icon == -1 )
-	{
-		return FALSE;
-	}
-	else
-	{
-		GdkPixbuf *icon;
-		icon = xfpm_load_icon(g_quark_to_string(battery_icon->icon),battery_icon->icon_size);
-        
-        if ( icon )
-        {
-            battery_icon->icon_loaded = TRUE;
-            gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(battery_icon),icon);
-            g_object_unref(G_OBJECT(icon));
-			return TRUE;
-        }
-		return FALSE;
-	}
-	return FALSE;
-}
-
-static const gchar *
-xfpm_battery_icon_get_index(XfpmBatteryType type,guint percent)
-{
-	if (percent < 10) {
-		return "000";
-	} else if (percent < 30) {
-	    return (type == MOUSE || type == KEYBOARD ? "030" : "020");
-	} else if (percent < 50) {
-	    return (type == MOUSE || type == KEYBOARD ? "030" : "040");
-	} else if (percent < 70) {
-		return "060";
-	} else if (percent < 90) {
-	    return (type == MOUSE || type == KEYBOARD ? "060" : "080");
-	}
-	return "100";
-}
-
-static gchar *
-xfpm_battery_icon_get_icon_prefix(XfpmBatteryType type)
-{
-    if ( type == PRIMARY )
-    {
-        return g_strdup("gpm-primary");
-    }
-    else if ( type == UPS )
-    {
-        return g_strdup("gpm-ups");
-    }
-    else if ( type == KEYBOARD)
-    {
-        return g_strdup("gpm-keyboard");
-    }
-    else if ( type == MOUSE )
-    {
-        return g_strdup("gpm-mouse");
-    }
-    /* we are going to show a primary icon */
-    return g_strdup("gpm-primary");    
-}
-
-#ifdef HAVE_LIBNOTIFY
-static gboolean
-_battery_icon_send_notification(gpointer data)
-{
-	NotifyNotification *n = (NotifyNotification *) data;
-	xfpm_notify_show_notification(n,0); 
-	return FALSE;
-}
-#endif	
-static void
-xfpm_battery_icon_update(XfpmBatteryIcon *battery_icon,XfpmBatteryState state,
-                        guint level,gboolean adapter_present)
-{
-    XFPM_DEBUG(" start\n");
-#ifdef HAVE_LIBNOTIFY    
-    const gchar *message = NULL;
-#endif    
-    gchar *icon_name = NULL;
-    gchar *icon_prefix = NULL;
-    
-    icon_prefix = xfpm_battery_icon_get_icon_prefix(battery_icon->type);
-        
-    switch(state)
-    {
-        case NOT_PRESENT:
-            icon_name = g_strdup_printf("%s-missing",icon_prefix);
-            break;
-        case LOW:
-            icon_name = g_strdup_printf("%s-%s",icon_prefix,
-                            xfpm_battery_icon_get_index(battery_icon->type,level));
-#ifdef HAVE_LIBNOTIFY 
-            message = _("Your battery charge is low");
-#endif
-            break;
-        case CRITICAL:
-            icon_name = g_strdup_printf("%s-%s",icon_prefix,
-                            xfpm_battery_icon_get_index(battery_icon->type,level));
-#ifdef HAVE_LIBNOTIFY 
-            message = _("Your battery is almost empty");
-#endif
-            break;    
-        case DISCHARGING:
-            icon_name = g_strdup_printf("%s-%s",icon_prefix,
-                            xfpm_battery_icon_get_index(battery_icon->type,level));
-#ifdef HAVE_LIBNOTIFY 
-            if ( !adapter_present )
-            {
-                message = battery_icon->type == PRIMARY ? _("You are running on Battery"):_("Battery is discharging");
-            }
-            else
-            {
-                message = _("Your battery is discharging");
-            }
-#endif      
-            break;
-        case CHARGING:
-            icon_name = g_strdup_printf("%s-%s-charging",icon_prefix,
-                            xfpm_battery_icon_get_index(battery_icon->type,level));
-#ifdef HAVE_LIBNOTIFY 
-            message = _("Battery is charging");
-#endif
-        case NOT_FULL:
-             icon_name = g_strdup_printf("%s-%s-charging",icon_prefix,
-                            xfpm_battery_icon_get_index(battery_icon->type,level));
-             break;                   
-        case FULL:    
-             icon_name = g_strdup_printf("%s-charged",icon_prefix);
-#ifdef HAVE_LIBNOTIFY 
-            message = _("Your battery is fully charged");
-#endif
-            break;
-    }
-    XFPM_DEBUG("icon %s\n",icon_name);
-    
-    if ( battery_icon->state != state && state != NOT_FULL ) {
-	g_object_set(G_OBJECT(battery_icon),"battery-state",state,NULL);
-#ifdef HAVE_LIBNOTIFY
-    gboolean visible;
-    g_object_get(G_OBJECT(battery_icon),"visible",&visible,NULL);
-        if ( battery_icon->notify ) 
-        {
-            if ( battery_icon->discard_notification )
-            {
-                battery_icon->discard_notification = FALSE;
-            }
-            else
-            {
-                NotifyNotification *n =
-                xfpm_notify_new(_("Xfce power manager"),message,5000,NOTIFY_URGENCY_LOW,
-                               visible ? GTK_STATUS_ICON(battery_icon):NULL,icon_name);
-                g_idle_add((GSourceFunc)_battery_icon_send_notification,n);             
-            }
-        }
-#endif     
-    }
-
-    if ( icon_prefix && icon_name )
-    {
-        if ( battery_icon->icon == g_quark_from_string(icon_name ) && 
-             battery_icon->icon_loaded )
-        {
-            g_free(icon_prefix);
-            g_free(icon_name);
-            return;
-        }
-        gint size;    
-        GdkPixbuf *icon;
-        g_object_get(G_OBJECT(battery_icon),"size",&size,NULL);
-        icon = xfpm_load_icon(icon_name,size);
-        battery_icon->icon = g_quark_from_string(icon_name);
-        g_free(icon_prefix);
-        g_free(icon_name);
-        
-        if ( icon )
-        {
-            battery_icon->icon_loaded = TRUE;
-            gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(battery_icon),icon);
-            g_object_unref(G_OBJECT(icon));
-        }
-        else
-        {
-            battery_icon->icon_loaded = FALSE;
-        } 
-     }   
-}
-
-GtkStatusIcon *
-xfpm_battery_icon_new(guint32 last_full,XfpmBatteryType battery_type,
-                      guint critical_level,gboolean visible)
-{
-    XfpmBatteryIcon *battery_icon = NULL;
-    battery_icon = g_object_new(XFPM_TYPE_BATTERY_ICON,
-                            "battery-type",
-                            battery_type,
-                            "last-full",
-                            last_full,
-                            "batt-critical-level",
-                            critical_level,
-                            "visible",
-                            visible,
-                            NULL);
-                            
-    return GTK_STATUS_ICON(battery_icon);
-}
-
-void
-xfpm_battery_icon_set_state(XfpmBatteryIcon *battery_icon,guint32 charge,guint per,
-                            guint32 remaining_time,gboolean present,
-                            gboolean is_charging,gboolean is_discharging,
-                            gboolean ac_adapter_present)
-{
-    g_return_if_fail(XFPM_IS_BATTERY_ICON(battery_icon));
-    battery_icon->battery_present = present;
-    guint critical_level = battery_icon->type == PRIMARY || UPS ? battery_icon->critical_level : 5;
-#ifdef DEBUG
-    gchar *content_is_charging;
-    gchar *content_is_discharging;
-    gchar *content_present;
-    
-    GValue value = { 0, };
-    g_value_init(&value,G_TYPE_BOOLEAN);
-    g_value_set_boolean(&value,is_charging);
-    content_is_charging = g_strdup_value_contents(&value);
-    
-    g_value_set_boolean(&value,is_discharging);
-    content_is_discharging = g_strdup_value_contents(&value);
-    
-    g_value_set_boolean(&value,present);
-    content_present = g_strdup_value_contents(&value);
-        
-    XFPM_DEBUG("Setting battery state charge=%d is_charging:%s is_discharging:%s present:%s \n",charge,
-    content_is_charging,content_is_discharging,content_present);
-    g_free(content_is_charging);
-    g_free(content_is_discharging);
-    g_free(content_present);
-#endif    
-    guint remaining_per;
-    if ( per > 0 )
-    {
-        remaining_per =  per;
-    }
-    else
-    {
-        remaining_per = 1;
-    }
-    
-    gchar tip[256];
-    
-    if ( present == FALSE )
-    {
-        xfpm_battery_icon_update(battery_icon,NOT_PRESENT,remaining_per,ac_adapter_present);
-        sprintf(tip,"%s",_("Not present"));
-        gtk_status_icon_set_tooltip(GTK_STATUS_ICON(battery_icon),tip);
-        return;
-    }
-    
-    sprintf(tip,"%i",remaining_per);
-    strcat(tip,_("%"));
-	strcat(tip," ");
-    
-    // battery is full
-    if ( is_charging == FALSE && is_discharging == FALSE && battery_icon->last_full == charge )
-    {
-        strcat(tip,_("Battery fully charged"));
-        xfpm_battery_icon_update(battery_icon,FULL,remaining_per,ac_adapter_present);
-    }
-    
-    // battery is not dis/charging but is not full also
-    if ( is_charging == FALSE && is_discharging == FALSE && battery_icon->last_full != charge )
-    {
-        strcat(tip,_("Battery charge level"));
-        xfpm_battery_icon_update(battery_icon,NOT_FULL,remaining_per,ac_adapter_present);
-    }
-    
-    //battery is charging
-    if ( is_charging == TRUE && is_discharging == FALSE )
-    {
-        strcat(tip,_("Battery is charging"));
-        xfpm_battery_icon_update(battery_icon,CHARGING,remaining_per,ac_adapter_present);
-    }
-    
-    // battery is discharging
-    if ( is_charging == FALSE && is_discharging == TRUE )
-    {
-        if ( remaining_per > ( critical_level + 10 ) )
-        {
-            if ( !ac_adapter_present )
-            {
-                strcat(tip,
-                battery_icon->type == PRIMARY ? _("Running on battery"): _("Battery is discharging"));
-            }
-            else
-            {
-                strcat(tip,_("Battery is discharging"));
-            }
-            xfpm_battery_icon_update(battery_icon,DISCHARGING,remaining_per,ac_adapter_present);
-        } 
-        else if ( remaining_per <= ( critical_level+10 ) && remaining_per > critical_level )
-        {
-            strcat(tip,_("Battery charge is low"));
-            xfpm_battery_icon_update(battery_icon,LOW,20,ac_adapter_present);
-        }
-        else if ( remaining_per <= critical_level )
-        {
-            strcat(tip,_("Battery is almost empty"));
-            xfpm_battery_icon_update(battery_icon,CRITICAL,0,ac_adapter_present);
-        }
-    }
-
-	if ( remaining_time > 28800 && battery_icon->type == PRIMARY ) 
-	{
-		/* 8 hours is the threshold that we accept*/
-		goto end;
-	}
-	
-    if ( remaining_time != 0 )
-    {
-        gchar *time_str;
-        gchar *est_time = NULL;
-        
-        gint minutes,hours,minutes_left;
-       	hours = remaining_time / 3600;
-		minutes = remaining_time / 60;
-		minutes_left = minutes % 60;
-		
-		if ( battery_icon->state == DISCHARGING || 
-		     battery_icon->state == LOW         || 
-		     battery_icon->state == CRITICAL )
-        {
-            est_time = g_strdup(_("\nEstimated time left"));
-           
-        }
-        else if ( battery_icon->state == CHARGING )
-        {
-            est_time = g_strdup(_("\nEstimated time to charge"));
-           
-        }
-        time_str = g_strdup_printf("%s: %d %s %d %s",est_time,
-                                   hours,hours > 1 ? _("hours") : _("hour") ,
-                                   minutes_left, minutes_left > 1 ? _("minutes") : _("minute"));
-                                        
-		strcat(tip,time_str);
-		g_free(time_str);
-		g_free(est_time);
-    }
-    end:
-    gtk_status_icon_set_tooltip(GTK_STATUS_ICON(battery_icon),tip);
-    
-}
diff --git a/src/xfpm-battery-icon.h b/src/xfpm-battery-icon.h
deleted file mode 100644
index 4e70cc16..00000000
--- a/src/xfpm-battery-icon.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __XFPM_BATTERY_ICON_H
-#define __XFPM_BATTERY_ICON_H
-
-#include <glib-object.h>
-#include <gtk/gtkstatusicon.h>
-
-#include "xfpm-enums.h"
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_BATTERY_ICON    (xfpm_battery_icon_get_type())
-#define XFPM_BATTERY_ICON(o)      (G_TYPE_CHECK_INSTANCE_CAST((o),XFPM_TYPE_BATTERY_ICON,XfpmBatteryIcon))
-#define XFPM_IS_BATTERY_ICON(o)   (G_TYPE_CHECK_INSTANCE_TYPE((o),XFPM_TYPE_BATTERY_ICON))
-
-typedef struct XfpmBatteryIconPrivate XfpmBatteryIconPrivate;
-
-typedef struct 
-{
-    GtkStatusIcon parent;
-
-    XfpmBatteryState state;
-    XfpmBatteryType  type;
-    
-    GQuark icon;
-	gint icon_size;
-    gboolean icon_loaded;
-
-    gboolean battery_present;
-        
-    guint last_full;
-    guint critical_level;
-
-#ifdef HAVE_LIBNOTIFY
-    gboolean notify;
-    gboolean discard_notification;
-#endif        
-
-} XfpmBatteryIcon;
-
-typedef struct 
-{
-    
-    GtkStatusIconClass parent_class;
-    
-} XfpmBatteryIconClass;
-
-GType          xfpm_battery_icon_get_type   (void);
-GtkStatusIcon *xfpm_battery_icon_new        (guint32 last_full,
-                                            XfpmBatteryType battery_type,
-                                            guint critical_charge,        
-                                            gboolean visible);
-                                            
-void           xfpm_battery_icon_set_state  (XfpmBatteryIcon *battery_icon,
-                                            guint32 charge,
-                                            guint remaining_per,
-                                            guint32 remaining_time,
-                                            gboolean present,
-                                            gboolean is_charging,
-                                            gboolean is_discharging,
-                                            gboolean ac_adapter_present);
-G_END_DECLS
-
-#endif /* __XFPM_BATTERY_ICON_H */
diff --git a/src/xfpm-battery-info.c b/src/xfpm-battery-info.c
new file mode 100644
index 00000000..08ecc03d
--- /dev/null
+++ b/src/xfpm-battery-info.c
@@ -0,0 +1,217 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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
+ */
+
+#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+
+#include "xfpm-battery-info.h"
+
+static GtkWidget *
+xfpm_battery_info (HalDevice *device)
+{
+    PangoFontDescription *pfd;
+    
+    GtkWidget *table;
+    GtkWidget *label;
+    GtkWidget *align;
+    
+    gint i = 0;
+
+    gchar   *unit = NULL;
+    guint32  last_full = 0;
+    guint32  design_capacity = 0;
+    gchar   *tech = NULL;
+    gchar   *vendor = NULL;
+    gchar   *model = NULL;
+
+    g_object_get (G_OBJECT(device), 
+    		  "unit", &unit,
+		  "reporting-last-full", &last_full, 
+		  "technology", &tech, 
+		  "vendor", &vendor,
+		  "model", &model,
+		  "reporting-design", &design_capacity,
+		  NULL);
+		  
+    pfd = pango_font_description_from_string("bold");
+    
+    table = gtk_table_new (4, 2, FALSE);
+    
+    if (!unit)
+    	unit = g_strdup (_("Unknown unit"));
+    
+    //Technology
+    if ( tech )
+    {
+    	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+    
+    	label = gtk_label_new (_("Technology:"));
+    	gtk_container_add (GTK_CONTAINER(align), label);
+    	gtk_widget_modify_font (label, pfd);
+    
+    	gtk_table_attach(GTK_TABLE(table), align,
+			 0, 1, i, i+1, 
+		     	 GTK_FILL, GTK_FILL,
+		     	 2, 8);
+
+	label = gtk_label_new (tech);
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+	g_free (tech);
+	gtk_table_attach(GTK_TABLE(table), align,
+			 1, 2, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+		     	 2, 8);
+    	i++;
+    }
+
+    /// Capacity design
+    if ( design_capacity != 0 )
+    {
+	label = gtk_label_new (_("Design:"));
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+	
+	gtk_widget_modify_font (label, pfd);
+	
+	gtk_table_attach(GTK_TABLE(table), align,
+			 0, 1, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+			 2, 8);
+			 
+	gchar *str = g_strdup_printf ("%d %s", design_capacity, unit);
+	
+	label = gtk_label_new (str);
+	g_free (str);
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+	
+	gtk_table_attach(GTK_TABLE(table), align,
+			 1, 2, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+			 2, 8);
+	i++;
+    }
+    
+    
+    if ( last_full != 0 )
+    {
+    	label = gtk_label_new (_("Last full:"));
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+    	gtk_widget_modify_font (label, pfd);
+    
+    	gtk_table_attach(GTK_TABLE(table), align,
+			 0, 1, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+		     	 2, 8);
+			 
+	gchar *str = g_strdup_printf ("%d %s", last_full, unit);
+	label = gtk_label_new (str);
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+	g_free (str);
+	gtk_table_attach(GTK_TABLE(table), align,
+			 1, 2, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+		     	 2, 8);
+    	i++;
+    }
+    
+    if ( vendor )
+    {
+    	label = gtk_label_new (_("Vendor:"));
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+	gtk_widget_modify_font (label, pfd);
+	
+	gtk_table_attach(GTK_TABLE(table), align,
+			 0, 1, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+			 2, 8);
+	
+	label = gtk_label_new (vendor);
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+	g_free (vendor);
+	gtk_table_attach(GTK_TABLE(table), align,
+			 1, 2, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+		     	 2, 8);
+	i++;
+    }
+    
+     
+    if ( model )
+    {
+    	label = gtk_label_new (_("Model:"));
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+	gtk_widget_modify_font (label, pfd);
+	
+	gtk_table_attach(GTK_TABLE(table), align,
+			 0, 1, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+			 2, 8);
+	
+	label = gtk_label_new (model);
+	align = gtk_alignment_new (0.0, 0.5, 0, 0);
+	gtk_container_add (GTK_CONTAINER(align), label);
+	g_free (model);
+	gtk_table_attach(GTK_TABLE(table), align,
+			 1, 2, i, i+1, 
+			 GTK_FILL, GTK_FILL,
+		     	 2, 8);
+	i++;
+    }
+    
+    if ( unit )
+    	g_free(unit);
+	
+    return table;
+}
+
+GtkWidget *xfpm_battery_info_new (HalDevice *device, const gchar *icon_name)
+{
+    GtkWidget *info;
+    GtkWidget *mainbox;
+    GtkWidget *allbox;
+    
+    info = xfce_titled_dialog_new_with_buttons(_("Battery information"),
+					       NULL,
+                                               GTK_DIALOG_DESTROY_WITH_PARENT,
+                                               GTK_STOCK_CLOSE,
+                                               GTK_RESPONSE_CANCEL,
+					       NULL);
+					       
+    gtk_window_set_icon_name (GTK_WINDOW(info), icon_name);
+    gtk_dialog_set_default_response (GTK_DIALOG(info), GTK_RESPONSE_CLOSE);
+    
+    mainbox = GTK_DIALOG (info)->vbox;
+    
+    allbox = gtk_vbox_new (FALSE, 0);
+    gtk_box_pack_start (GTK_BOX(mainbox), allbox, TRUE, TRUE, 0);
+    
+    gtk_box_pack_start (GTK_BOX (allbox), xfpm_battery_info(device), FALSE, FALSE, 8);
+    
+    g_signal_connect (info, "response", G_CALLBACK(gtk_widget_destroy), NULL);
+    
+    return info;
+}
diff --git a/src/xfpm-battery-info.h b/src/xfpm-battery-info.h
new file mode 100644
index 00000000..481a6eae
--- /dev/null
+++ b/src/xfpm-battery-info.h
@@ -0,0 +1,35 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_BATTERY_INFO_H
+#define __XFPM_BATTERY_INFO_H
+
+#include <gtk/gtk.h>
+#include <glib.h>
+
+#include "libxfpm/hal-device.h"
+
+G_BEGIN_DECLS
+
+GtkWidget 	*xfpm_battery_info_new 		(HalDevice *device, const gchar *icon_name);
+
+G_END_DECLS
+
+#endif /*__XFPM_BATTERY_INFO_H */
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 88f9175e..bc0d849b 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -1,5 +1,4 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
+/*
  * * Copyright (C) 2008 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
@@ -16,7 +15,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifdef HAVE_CONFIG_H
@@ -24,1365 +23,460 @@
 #endif
 
 #include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
 #include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 
+#include <glib.h>
 #include <gtk/gtk.h>
+
 #include <glib.h>
 
-#include <libxfcegui4/libxfcegui4.h>
 #include <libxfce4util/libxfce4util.h>
-#include <xfconf/xfconf.h>
+
+#include "libxfpm/xfpm-string.h"
 
 #include "xfpm-battery.h"
-#include "xfpm-battery-icon.h"
-#include "xfpm-hal.h"
-#include "xfpm-debug.h"
-#include "xfpm-common.h"
+#include "xfpm-tray-icon.h"
+#include "xfpm-string.h"
+#include "xfpm-marshal.h"
 #include "xfpm-enum-types.h"
+#include "xfpm-battery-info.h"
 #include "xfpm-notify.h"
-#include "xfpm-marshal.h"
-#include "xfpm-string.h"
 
-#define XFPM_BATTERY_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE(o,XFPM_TYPE_BATTERY,XfpmBatteryPrivate))
+/* Init */
+static void xfpm_battery_class_init (XfpmBatteryClass *klass);
+static void xfpm_battery_init       (XfpmBattery *battery);
+static void xfpm_battery_finalize   (GObject *object);
 
-static void xfpm_battery_init(XfpmBattery *battery);
-static void xfpm_battery_class_init(XfpmBatteryClass *klass);
-static void xfpm_battery_finalize(GObject *object);
+#define XFPM_BATTERY_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_BATTERY, XfpmBatteryPrivate))
 
-
-static void xfpm_battery_set_property (GObject *object,
-                                   guint prop_id,
-                                   const GValue *value,
-                                   GParamSpec *pspec);
-static void xfpm_battery_get_property (GObject *object,
-                                   guint prop_id,
-                                   GValue *value,
-                                   GParamSpec *pspec);
-
-static void xfpm_battery_refresh_tray_icon(XfpmBattery *batt);
-#ifdef HAVE_LIBNOTIFY
-static void xfpm_battery_refresh_notification(XfpmBattery *batt);
-#endif
-static void xfpm_battery_refresh_critical_charge(XfpmBattery *batt);
-static void xfpm_battery_refresh(XfpmBattery *batt);
-
-static void xfpm_battery_notify_cb (GObject *object,
-                                    GParamSpec *arg1,
-                                    gpointer data);
-
-static void xfpm_battery_load_config(XfpmBattery *batt);
-
-static void xfpm_battery_handle_device_added(XfpmHal *hal,
-                                             const gchar *udi,
-                                             XfpmBattery *batt);
-                                             
-static void xfpm_battery_handle_device_removed(XfpmHal *hal,
-                                               const gchar *udi,
-                                               XfpmBattery *batt);
-                                               
-static void xfpm_battery_handle_device_property_changed(XfpmHal *hal,const gchar *udi,
-                                                        const gchar *key,gboolean is_removed,
-                                                        gboolean is_added,XfpmBattery *batt);
-                                                        
-static void xfpm_battery_show_critical_options(XfpmBattery *batt,
-											   XfpmBatteryIcon *icon,
-											   XfpmBatteryType battery_type);
-static void xfpm_battery_handle_primary_critical(XfpmBattery *batt,
-                                                XfpmBatteryIcon *icon);
-static void xfpm_battery_handle_critical_charge(XfpmBattery *batt,
-                                                XfpmBatteryIcon *icon);
-                                                
-static void xfpm_battery_state_change_cb(GObject *object,
-                                         GParamSpec *arg1,
-                                         gpointer data);
-
-static XfpmBatteryType xfpm_battery_get_battery_type(const gchar *battery_type);
-
-static gboolean xfpm_battery_check(XfpmBattery *batt,
-                                    const gchar *udi);
-static gboolean xfpm_battery_is_new(XfpmBattery *batt, 
-                                    const gchar *udi, 
-                                    XfpmBatteryType battery_type, 
-                                    guint last_full);
-
-static void xfpm_battery_hibernate_callback(GtkWidget *widget,
-                                            XfpmBattery *batt);
-static void xfpm_battery_suspend_callback(GtkWidget *widget,
-                                          XfpmBattery *batt);
-static void xfpm_battery_popup_tray_icon_menu(GtkStatusIcon *tray_icon,
-                                             guint button,
-                                             guint activate_time,
-                                             XfpmBattery *batt);
-
-static void xfpm_battery_new_device(XfpmBattery *batt,
-                                    const gchar *udi);
-static void xfpm_battery_get_devices(XfpmBattery *batt);
-                                                        
 struct XfpmBatteryPrivate
 {
-    XfpmHal *hal;
-    GHashTable *batteries;
-
-    guint8 power_management;
+    XfpmTrayIcon  *icon;
+    HalDevice     *device;
+    XfpmNotify    *notify;
+    
+    HalDeviceType    type;
+    gchar 	    *icon_prefix;
     
-    gboolean ups_found;
-        
+    gboolean         adapter_present;
+    
+    XfpmShowIcon     show_icon;
+    XfpmBatteryState state;
 };
-                                
-G_DEFINE_TYPE(XfpmBattery,xfpm_battery,G_TYPE_OBJECT)
 
-enum 
+enum
 {
-    XFPM_SHOW_ADAPTER_ICON,
-    XFPM_ACTION_REQUEST,
+    BATTERY_STATE_CHANGED,
+    POPUP_BATTERY_MENU,
     LAST_SIGNAL
 };
 
-static guint signals[LAST_SIGNAL] = { 0,}; 
+static guint signals[LAST_SIGNAL] = { 0 };
 
-enum
-{
-    PROP_0,
-    PROP_AC_ADAPTER,
-    PROP_CRITICAL_CHARGE,
-    PROP_CRITICAL_ACTION,
-#ifdef HAVE_LIBNOTIFY
-    PROP_ENABLE_NOTIFICATION,
-#endif
-    PROP_SHOW_TRAY_ICON    
-};
+G_DEFINE_TYPE(XfpmBattery, xfpm_battery, G_TYPE_OBJECT)
 
 static void
 xfpm_battery_class_init(XfpmBatteryClass *klass)
 {
-    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-    
-    gobject_class->set_property = xfpm_battery_set_property;
-    gobject_class->get_property = xfpm_battery_get_property;
-    
-    gobject_class->finalize = xfpm_battery_finalize;
-    
-    signals[XFPM_SHOW_ADAPTER_ICON] = g_signal_new("xfpm-show-adapter-icon",
-                                                   XFPM_TYPE_BATTERY,
-                                                   G_SIGNAL_RUN_LAST,
-                                                   G_STRUCT_OFFSET(XfpmBatteryClass,show_adapter_icon),
-                                                   NULL,NULL,
-                                                   g_cclosure_marshal_VOID__BOOLEAN,
-                                                   G_TYPE_NONE,1,G_TYPE_BOOLEAN);
-                                                   
-    signals[XFPM_ACTION_REQUEST] = g_signal_new("xfpm-action-request",
-                                               XFPM_TYPE_BATTERY,
-                                               G_SIGNAL_RUN_LAST,
-                                               G_STRUCT_OFFSET(XfpmBatteryClass,battery_action_request),
-                                               NULL,NULL,
-                                               _xfpm_marshal_VOID__ENUM_BOOLEAN ,
-                                               G_TYPE_NONE,2,
-                                               XFPM_TYPE_ACTION_REQUEST,G_TYPE_BOOLEAN);
-                                                   
-    g_object_class_install_property(gobject_class,
-                                    PROP_AC_ADAPTER,
-                                    g_param_spec_boolean("on-ac-adapter",
-                                                         "On ac adapter",
-                                                         "On Ac power",
-                                                         TRUE,
-                                                         G_PARAM_READWRITE));
-    
-    g_object_class_install_property(gobject_class,
-                                    PROP_CRITICAL_CHARGE,
-                                    g_param_spec_uint("critical-charge",
-                                                      "Critical charge",
-                                                      "Critical battery charge",
-                                                      1,
-                                                      20,
-                                                      10,
-                                                      G_PARAM_READWRITE));
-    
-    g_object_class_install_property(gobject_class,
-                                    PROP_CRITICAL_ACTION,
-                                    g_param_spec_enum("critical-action",
-                                                      "Critical action",
-                                                      "Battery critical charge action",
-                                                      XFPM_TYPE_ACTION_REQUEST,
-                                                      XFPM_DO_NOTHING,
-                                                      G_PARAM_READWRITE));
-    
-#ifdef HAVE_LIBNOTIFY    
-    g_object_class_install_property(gobject_class,
-                                    PROP_ENABLE_NOTIFICATION,
-                                    g_param_spec_boolean("enable-notification",
-                                                         "Notify enabled",
-                                                         "Notification",
-                                                         FALSE,
-                                                         G_PARAM_READWRITE));
-
-#endif
-     g_object_class_install_property(gobject_class,
-                                    PROP_SHOW_TRAY_ICON,
-                                    g_param_spec_enum("show-tray-icon",
-                                                     "Show tray icon",
-                                                     "Tray Icon",
-                                                      XFPM_TYPE_SHOW_ICON,
-                                                      0,
-                                                      G_PARAM_READWRITE));
-                                                         
-    g_type_class_add_private(klass,sizeof(XfpmBatteryPrivate));                                                     
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    signals[BATTERY_STATE_CHANGED] = 
+    	g_signal_new("battery-state-changed",
+		      XFPM_TYPE_BATTERY,
+		      G_SIGNAL_RUN_LAST,
+		      G_STRUCT_OFFSET(XfpmBatteryClass, battery_state_changed),
+		      NULL, NULL,
+		      g_cclosure_marshal_VOID__ENUM,
+		      G_TYPE_NONE, 1, XFPM_TYPE_BATTERY_STATE);
+
+    signals[POPUP_BATTERY_MENU] = 
+   	g_signal_new("popup-battery-menu",
+		      XFPM_TYPE_BATTERY,
+		      G_SIGNAL_RUN_LAST,
+		      G_STRUCT_OFFSET(XfpmBatteryClass, popup_battery_menu),
+		      NULL, NULL,
+		      _xfpm_marshal_VOID__POINTER_UINT_UINT_UINT,
+		      G_TYPE_NONE, 4, 
+		      GTK_TYPE_STATUS_ICON, 
+		      G_TYPE_UINT,
+		      G_TYPE_UINT,
+		      G_TYPE_UINT);
+		      
+    object_class->finalize = xfpm_battery_finalize;
+    
+
+    g_type_class_add_private(klass,sizeof(XfpmBatteryPrivate));
 }
 
 static void
 xfpm_battery_init(XfpmBattery *battery)
 {
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(battery);
-    
-    priv->batteries = g_hash_table_new(g_str_hash,g_str_equal);
-    
-    xfpm_battery_load_config(battery);
-    
-    priv->hal = xfpm_hal_new();
+    battery->priv = XFPM_BATTERY_GET_PRIVATE(battery);
     
-    if (xfpm_hal_connect_to_signals(priv->hal,TRUE,TRUE,TRUE,FALSE) )
-    {
-        g_signal_connect(G_OBJECT(priv->hal),"xfpm-device-added",
-                         G_CALLBACK(xfpm_battery_handle_device_added),
-                         battery);
-         
-        g_signal_connect(G_OBJECT(priv->hal),"xfpm-device-removed",
-                         G_CALLBACK(xfpm_battery_handle_device_removed),
-                         battery);
-                                          
-        g_signal_connect(G_OBJECT(priv->hal),"xfpm-device-property-changed",
-                         G_CALLBACK(xfpm_battery_handle_device_property_changed),
-                         battery);                 
-        
-    }
-    g_signal_connect(G_OBJECT(battery),"notify",
-                        G_CALLBACK(xfpm_battery_notify_cb),NULL);
+    battery->priv->icon      = xfpm_tray_icon_new();
+    battery->priv->show_icon = SHOW_ICON_ALWAYS;
+    battery->priv->notify    = xfpm_notify_new ();
 }
 
-static void xfpm_battery_set_property(GObject *object,
-                                      guint prop_id,
-                                      const GValue *value,
-                                      GParamSpec *pspec)
+static void
+xfpm_battery_finalize(GObject *object)
 {
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif      
     XfpmBattery *battery;
     battery = XFPM_BATTERY(object);
     
-    switch (prop_id)
-    {
-    case PROP_AC_ADAPTER:
-        battery->ac_adapter_present = g_value_get_boolean(value);
-        break;   
-    case PROP_CRITICAL_CHARGE:
-        battery->critical_level = g_value_get_uint(value);
-        break;
-    case PROP_CRITICAL_ACTION:
-        battery->critical_action = g_value_get_enum(value);
-        break;
-    case PROP_SHOW_TRAY_ICON:
-        battery->show_tray = g_value_get_enum(value);
-        break;    
-#ifdef HAVE_LIBNOTIFY
-    case PROP_ENABLE_NOTIFICATION:
-        battery->notify_enabled = g_value_get_boolean(value);
-        break;
-#endif                        
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }
-}    
-                               
-static void xfpm_battery_get_property(GObject *object,
-                                      guint prop_id,
-                                      GValue *value,
-                                      GParamSpec *pspec)
-{
-    XfpmBattery *battery;
-    battery = XFPM_BATTERY(object);
-        
-    switch (prop_id)
-    {
-    case PROP_AC_ADAPTER:
-        g_value_set_boolean(value,battery->ac_adapter_present);
-        break;  
-    case PROP_CRITICAL_CHARGE:
-        g_value_set_uint(value,battery->critical_level);
-        break;
-    case PROP_CRITICAL_ACTION:
-        g_value_set_enum(value,battery->critical_action );
-        break;
-    case PROP_SHOW_TRAY_ICON:
-        g_value_set_enum(value, battery->show_tray);
-        break;
-#ifdef HAVE_LIBNOTIFY
-    case PROP_ENABLE_NOTIFICATION:
-        g_value_set_boolean(value, battery->notify_enabled);
-        break;
-#endif                         
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }                         
+    if ( battery->priv->icon )
+    	g_object_unref (battery->priv->icon);
     
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif  
-}
-
-static void
-xfpm_battery_finalize(GObject *object)
-{
-    XfpmBattery *battery = XFPM_BATTERY(object);
-    battery->priv = XFPM_BATTERY_GET_PRIVATE(battery);
+    if ( battery->priv->device )
+    	g_object_unref (battery->priv->device);
+	
+    if ( battery->priv->icon_prefix )
+    	g_free(battery->priv->icon_prefix);
 
-    if ( battery->priv->batteries )
-    {
-        g_hash_table_unref(battery->priv->batteries);
-    }
     G_OBJECT_CLASS(xfpm_battery_parent_class)->finalize(object);
 }
 
-static void
-xfpm_battery_refresh_tray_icon(XfpmBattery *batt)
-{
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    GList *icons_list;
-    int i=0;
-    GtkStatusIcon *icon;
-    
-    if ( batt->show_tray == ALWAYS && g_hash_table_size(priv->batteries) == 0 )
-    {
-        XFPM_DEBUG("batt->show_tray == ALWAYS && g_hash_table_size(priv->batteries) == 0\n");
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_SHOW_ADAPTER_ICON],0,TRUE);
-    }
-    else if ( batt->show_tray == CHARGING_OR_DISCHARGING && g_hash_table_size(priv->batteries) == 0 )
-    {
-        XFPM_DEBUG("batt->show_tray == CHARGING_OR_DISCHARGING && g_hash_table_size(priv->batteries) == 0 \n");
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_SHOW_ADAPTER_ICON],0,FALSE);
-        
-    }
-    else if ( batt->show_tray == ALWAYS && g_hash_table_size(priv->batteries) != 0 )
-    {
-        XFPM_DEBUG("batt->show_tray == ALWAYS && g_hash_table_size(priv->batteries) != 0  \n");
-        icons_list = g_hash_table_get_values(priv->batteries);
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_SHOW_ADAPTER_ICON],0,FALSE);
-        for ( i = 0 ; i < g_list_length(icons_list) ; i++ )
-        {
-            icon = g_list_nth_data(icons_list,i);
-            if ( icon ) 
-            {
-                g_object_set(G_OBJECT(icon),"visible",TRUE,NULL);
-            }
-        }
-    }
-    else if ( batt->show_tray == PRESENT )
-    {
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_SHOW_ADAPTER_ICON],0,FALSE);
-        XFPM_DEBUG("batt->show_tray == PRESENT \n");
-        icons_list = g_hash_table_get_values(priv->batteries);
-        for ( i = 0 ; i < g_list_length(icons_list) ; i++ )
-        {
-            icon = g_list_nth_data(icons_list,i);
-            if ( icon ) 
-            {
-                g_object_set(G_OBJECT(icon),"visible",XFPM_BATTERY_ICON(icon)->battery_present,NULL);
-            }
-        }
-    }
-    else if ( batt->show_tray == CHARGING_OR_DISCHARGING )
-    {
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_SHOW_ADAPTER_ICON],0,FALSE);
-        XFPM_DEBUG("batt->show_tray == CHARGING_OR_DISCHARGING \n");
-        icons_list = g_hash_table_get_values(priv->batteries);
-        for ( i = 0 ; i < g_list_length(icons_list) ; i++ )
-        {
-            icon = g_list_nth_data(icons_list,i);
-            if ( icon )
-            {
-                if (  XFPM_BATTERY_ICON(icon)->state == CHARGING || 
-                      XFPM_BATTERY_ICON(icon)->state == DISCHARGING ||
-                      XFPM_BATTERY_ICON(icon)->state == NOT_FULL   ||
-                      XFPM_BATTERY_ICON(icon)->state == LOW        ||
-                      XFPM_BATTERY_ICON(icon)->state == CRITICAL) 
-                {
-                    g_object_set(G_OBJECT(icon),"visible",TRUE,NULL);
-                }
-                else
-                {
-                    g_object_set(G_OBJECT(icon),"visible",FALSE,NULL);
-                }
-            }
-        }
-    }   
+static const gchar *
+xfpm_battery_get_icon_index (HalDeviceType type, guint percent)
+{
+    if (percent < 10) {
+	return "000";
+    } else if (percent < 30) {
+	return (type == HAL_DEVICE_TYPE_PRIMARY || type == HAL_DEVICE_TYPE_UPS ? "020" : "030");
+    } else if (percent < 50) {
+	return (type == HAL_DEVICE_TYPE_PRIMARY || type == HAL_DEVICE_TYPE_UPS ? "040" : "030");
+    } else if (percent < 70) {
+	return "060";
+    } else if (percent < 90) {
+	return (type == HAL_DEVICE_TYPE_PRIMARY || type == HAL_DEVICE_TYPE_UPS ? "080" : "060");
+    }
+    return "100";
 }
 
-#ifdef HAVE_LIBNOTIFY
 static void
-xfpm_battery_refresh_notification(XfpmBattery *batt)
+xfpm_battery_refresh_visible_icon (XfpmBattery *battery)
 {
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
+    gboolean visible = FALSE, tray_visible = FALSE;
     
-    if ( g_hash_table_size(priv->batteries) == 0 ) 
+    if ( battery->priv->show_icon == SHOW_ICON_ALWAYS )
+    	visible = TRUE;
+    else if ( battery->priv->show_icon == SHOW_ICON_WHEN_BATTERY_PRESENT )
     {
-        return;
+	if ( battery->priv->state == BATTERY_NOT_PRESENT )
+	    visible = FALSE;
+	else visible = TRUE;
     }
-    GList *icons_list;
-    GtkStatusIcon *icon;
-    int i;
-    
-    icons_list = g_hash_table_get_values(priv->batteries);
-    for ( i = 0 ; i < g_list_length(icons_list) ; i++ )
+    else if ( battery->priv->show_icon == SHOW_ICON_WHEN_BATTERY_CHARGING_DISCHARGING )
     {
-        icon = g_list_nth_data(icons_list,i);
-        if ( icon ) 
-        {
-            g_object_set(G_OBJECT(icon),"systray-notify",batt->notify_enabled,NULL);
-        }
+	if ( battery->priv->state == BATTERY_FULLY_CHARGED )
+	    visible = FALSE;
+	else visible = TRUE;
     }
-}
-#endif
-
-static void
-xfpm_battery_refresh_critical_charge(XfpmBattery *batt)
-{
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    
-    if ( g_hash_table_size(priv->batteries) == 0 ) 
-    {
-        return;
-    }
-    GList *icons_list;
-    GtkStatusIcon *icon;
-    int i;
-    
-    icons_list = g_hash_table_get_values(priv->batteries);
-    for ( i = 0 ; i < g_list_length(icons_list) ; i++ )
-    {
-        icon = g_list_nth_data(icons_list,i);
-        if ( icon ) 
-        {
-            g_object_set(G_OBJECT(icon),"batt-critical-level",batt->critical_level,NULL);
-        }
-    }
-}
-
-static void
-xfpm_battery_refresh(XfpmBattery *batt)
-{
-    xfpm_battery_refresh_tray_icon(batt);
-    xfpm_battery_refresh_critical_charge(batt);
-#ifdef HAVE_LIBNOTIFY
-    xfpm_battery_refresh_notification(batt);
-#endif        
-}
 
-static void 
-xfpm_battery_notify_cb (GObject *object,
-                        GParamSpec *arg1,
-                        gpointer data)
-{
-    XFPM_DEBUG("arg1->name=%s\n",arg1->name);
+    tray_visible = xfpm_tray_icon_get_visible (battery->priv->icon);
     
-    if (!xfpm_strcmp(arg1->name,"show-tray-icon"))
-    {
-        xfpm_battery_refresh_tray_icon(XFPM_BATTERY(object));
-    }
-    else if ( !xfpm_strcmp(arg1->name,"critical-charge"))
+    if ( tray_visible != visible )
     {
-        xfpm_battery_refresh_critical_charge(XFPM_BATTERY(object));
+    	TRACE ("Settings battery visibility %s\n", xfpm_bool_to_string(visible));
+    	xfpm_tray_icon_set_visible (battery->priv->icon, visible);
     }
-#ifdef HAVE_LIBNOTIFY
-    else if ( !xfpm_strcmp(arg1->name,"enable-notification"))
-    {
-        xfpm_battery_refresh_notification(XFPM_BATTERY(object));
-    }    
-#endif 
 }
-
-static void
-xfpm_battery_load_config(XfpmBattery *batt)
-{
-    XFPM_DEBUG("loading configuration\n");
     
-    XfconfChannel *channel;
-    channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-    
-    batt->critical_level  =  xfconf_channel_get_uint(channel,CRITICAL_BATT_CFG,10);
-    batt->critical_action = xfconf_channel_get_uint(channel,CRITICAL_BATT_ACTION_CFG,XFPM_DO_NOTHING);
-    batt->show_tray = xfconf_channel_get_uint(channel,SHOW_TRAY_ICON_CFG,ALWAYS);
-#ifdef HAVE_LIBNOTIFY
-     batt->notify_enabled = xfconf_channel_get_bool(channel,BATT_STATE_NOTIFICATION_CFG,TRUE);
-#endif 
-    g_object_unref(channel);
-}
-
 static void
-xfpm_battery_handle_device_added(XfpmHal *hal,const gchar *udi,XfpmBattery *batt)
-{
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    
-    if ( xfpm_hal_device_have_key(priv->hal,udi,"battery.is_rechargeable") ) 
-    {
-        xfpm_battery_new_device(batt,udi);
-        xfpm_battery_refresh(batt);
+xfpm_battery_refresh_icon (XfpmBattery *battery, 
+			   gboolean is_present,
+			   gboolean is_charging, 
+			   gboolean is_discharging,
+			   guint percentage
+			   )
+{
+    if ( !is_present )
+    {
+	xfpm_tray_icon_set_icon (battery->priv->icon, 
+				 battery->priv->type == HAL_DEVICE_TYPE_UPS ? "gpm-ups-missing" : "gpm-primary-missing");
+	return;
+    }
+    /* Battery full */
+    if ( !is_charging && !is_discharging )
+    {
+	if ( battery->priv->type == HAL_DEVICE_TYPE_PRIMARY)
+	    xfpm_tray_icon_set_icon (battery->priv->icon,
+				     "gpm-primary-charged");
+	else
+	{
+	    gchar *icon = g_strdup_printf("%s%s", 
+	    			          battery->priv->icon_prefix, 
+	    			          xfpm_battery_get_icon_index(battery->priv->type, percentage));
+	    xfpm_tray_icon_set_icon (battery->priv->icon, icon);
+	    g_free(icon);
+	}
+	return;
     }
-}
-
-static void
-xfpm_battery_handle_device_removed(XfpmHal *hal,const gchar *udi,XfpmBattery *batt)
-{
-    GtkStatusIcon *icon;
-    XfpmBatteryPrivate *priv;
     
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    icon = g_hash_table_lookup(priv->batteries,udi);
-    if ( !icon )
+    if ( is_charging )
     {
-        return;
+	gchar *icon = g_strdup_printf("%s%s-%s",
+				      battery->priv->icon_prefix, 
+	    			      xfpm_battery_get_icon_index(battery->priv->type, percentage),
+				      "charging");
+	xfpm_tray_icon_set_icon (battery->priv->icon, icon);
+	g_free(icon);
+	return;
     }
-
-    XFPM_DEBUG("Removing battery device %s\n",udi);    
-    XfpmBatteryType battery_type;
-    g_object_get(G_OBJECT(icon),"battery-type",&battery_type,NULL);
-    
-    if ( battery_type == UPS ) priv->ups_found = FALSE;
-
-    g_hash_table_remove(priv->batteries,udi);
-    g_object_unref(icon);
-    xfpm_battery_refresh(batt);
-}
-
-
-static guint 
-_get_battery_percentage(gint32 last_full,gint32 current)
-{
-    guint val = 100;
-    
-    if ( last_full <= current ) return val;
-    
-    float f = (float)current/last_full *100;
-	
-	val = (guint)f;
-    return val;   
-}
     
-static void
-xfpm_battery_handle_device_property_changed(XfpmHal *hal,const gchar *udi,
-                                           const gchar *key,gboolean is_removed,
-                                           gboolean is_added,XfpmBattery *batt)
-{
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    
-    if ( g_hash_table_size(priv->batteries) == 0 )
+    if ( is_discharging )
     {
-        return;
+	gchar *icon = g_strdup_printf("%s%s",
+				      battery->priv->icon_prefix, 
+	    			      xfpm_battery_get_icon_index(battery->priv->type, percentage));
+	xfpm_tray_icon_set_icon (battery->priv->icon, icon);
+	g_free(icon);
+	return;
     }
     
-    /* A device can have a battery key but is useless to monitor unless it's rechargeable*/
-    if ( xfpm_hal_device_have_key(priv->hal,udi,"battery.is_rechargeable") ) 
-    {
-        GtkStatusIcon *icon;
-        icon = g_hash_table_lookup(priv->batteries,udi);
-        if ( !icon )
-        {
-            return;
-        }
-        if ( !xfpm_strcmp(key,"battery.charge_level.last_full") )
-        {
-            GError *error = NULL;
-            guint last_full = xfpm_hal_get_int_info(priv->hal,
-                                                    udi,
-                                                    "battery.charge_level.last_full",
-                                                    &error);
-            if ( error )                                        
-            {
-                XFPM_DEBUG("%s\n",error->message);
-                g_error_free(error);
-            }                                        
-            g_object_set(G_OBJECT(icon),"last-full",last_full,NULL);
-            return;
-        }
-
-        if ( xfpm_strcmp(key,"battery.charge_level.current")           &&
-             xfpm_strcmp(key,"battery.rechargeable.is_charging")       &&
-             xfpm_strcmp(key,"battery.rechargeable.is_discharging") )
-        {
-            return;
-        }
-        XFPM_DEBUG("Drive status change udi=%s key=%s\n",udi,key);
-
-        gint32 current;
-        guint percentage;
-        gboolean is_charging;
-        gboolean is_discharging;
-        gboolean is_present;
-        GError *error = NULL;
-        current = xfpm_hal_get_int_info(priv->hal,
-                                        udi,
-                                        "battery.charge_level.current",
-                                        &error);
-        if ( error )                                        
-        {
-            XFPM_DEBUG("%s\n",error->message);
-            g_error_free(error);
-            return;
-        }                                    
-
-        if (xfpm_hal_device_have_key(priv->hal,udi,"battery.charge_level.persentage"))
-        {
-            if ( error ) 
-            {
-                XFPM_DEBUG("%s:\n",error->message);
-                g_error_free(error);
-                return;
-            }                                      
-            percentage = xfpm_hal_get_int_info(priv->hal,
-                                              udi,
-                                              "battery.charge_level.percentage",
-                                              &error);
-        }
-        else
-        {
-            GError *error = NULL;
-            guint last_full = xfpm_hal_get_int_info(priv->hal,
-                                                    udi,
-                                                    "battery.charge_level.last_full",
-                                                    &error);
-            if ( error )                                        
-            {
-                XFPM_DEBUG("%s\n",error->message);
-                g_error_free(error);
-                return;
-            }                                        
-            percentage = _get_battery_percentage(last_full,current);
-        }
-                                      
-        is_present = xfpm_hal_get_bool_info(priv->hal,
-                                             udi,
-                                            "battery.present",&error);
-        if ( error )                                        
-        {
-            XFPM_DEBUG("%s\n",error->message);
-            g_error_free(error);
-            return;
-        }                                           
-                                                                          
-        is_charging = xfpm_hal_get_bool_info(priv->hal,
-                                             udi,
-                                            "battery.rechargeable.is_charging",
-                                            &error);
-        if ( error )                                        
-        {
-            XFPM_DEBUG("%s\n",error->message);
-            g_error_free(error);
-            return;
-        }                                           
-                                            
-        is_discharging = xfpm_hal_get_bool_info(priv->hal,
-                                               udi,
-                                               "battery.rechargeable.is_discharging",
-                                               &error);
-        if ( error )                                        
-        {
-            XFPM_DEBUG("%s\n",error->message);
-            g_error_free(error);
-            return;
-        }                                               
-        
-        gint32 remaining_time  = 0 ;
-        if (xfpm_hal_device_have_key(priv->hal,udi,"battery.remaining_time"))
-        {
-            if ( error ) 
-            {
-                XFPM_DEBUG("%s:\n",error->message);
-                g_error_free(error);
-                return;
-            }                                      
-            remaining_time = xfpm_hal_get_int_info(priv->hal,
-                                                   udi,
-                                                   "battery.remaining_time",
-                                                   &error);
-        }                                       
-        xfpm_battery_icon_set_state(XFPM_BATTERY_ICON(icon),current,percentage,remaining_time,
-                                    is_present,is_charging,is_discharging,batt->ac_adapter_present);
-    }
+    
 }
 
-#ifdef HAVE_LIBNOTIFY
 static void
-_do_critical_action(NotifyNotification *n,gchar *action,XfpmBattery *batt)
+xfpm_battery_refresh_state (XfpmBattery *battery, XfpmBatteryState state)
 {
-    if (!xfpm_strcmp(action,"shutdown"))
-    {
-        XFPM_DEBUG("Sending shutdown request\n");
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_SHUTDOWN,TRUE);
-    }
-    else if ( !xfpm_strcmp(action,"hibernate"))
+    if ( battery->priv->state != state)
     {
-        XFPM_DEBUG("Sending hibernate request\n");
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_HIBERNATE,TRUE);
+	battery->priv->state = state;
+	g_signal_emit (G_OBJECT(battery), signals[BATTERY_STATE_CHANGED], 0, state);
+	TRACE("Emitting signal battery state changed");
     }
 }
-#endif
 
 static void
-xfpm_battery_show_critical_options(XfpmBattery *batt,XfpmBatteryIcon *icon,XfpmBatteryType battery_type)
+xfpm_battery_refresh_tooltip (XfpmBattery *battery, 
+			      gboolean is_present, 
+			      gboolean is_charging,
+			      gboolean is_discharging,
+			      guint32 last_full,
+			      guint32 current_charge,
+			      guint percentage)
 {
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
+    gchar tip[256];
+    XfpmBatteryState state = battery->priv->state;
     
-    const gchar *message;
-    message = _("Your battery is almost empty. "\
-              "Save your work to avoid losing data");
-              
-#ifdef HAVE_LIBNOTIFY            
-                                    
-    NotifyNotification *n = xfpm_notify_new(_("Xfce power manager"),
-                                             message,
-                                             20000,
-                                             NOTIFY_URGENCY_CRITICAL,
-                                             GTK_STATUS_ICON(icon),
-                                             battery_type == PRIMARY ? "gpm-primary-000" : "gpm-ups-000");
-    if (priv->power_management & SYSTEM_CAN_SHUTDOWN )
+    if ( !is_present )
     {
-        xfpm_notify_add_action(n,
-                               "shutdown",
-                               _("Shutdown the system"),
-                               (NotifyActionCallback)_do_critical_action,
-                               batt);   
-    }                          
-    if ( priv->power_management & SYSTEM_CAN_HIBERNATE )
-    {
-        xfpm_notify_add_action(n,
-                               "hibernate",
-                               _("Hibernate the system"),
-                               (NotifyActionCallback)_do_critical_action,
-                               batt);      
+	sprintf(tip, "%s",_("Not present"));
+	xfpm_tray_icon_set_tooltip(battery->priv->icon, tip);
+	return;
     }
-    xfpm_notify_show_notification(n,6);      
-#else
-	GtkWidget *dialog;
-	dialog = gtk_message_dialog_new (NULL,
-                                     GTK_DIALOG_MODAL,
-                                     GTK_MESSAGE_WARNING,
-                                     GTK_BUTTONS_CANCEL,
-                                     message,
-                                     NULL);
-     if ( priv->power_management & SYSTEM_CAN_HIBERNATE )
-	 {                                     
-		GtkWidget *hibernate = gtk_button_new_with_label(_("Hibernate"));
-		gtk_widget_show(hibernate);                                     
-		gtk_dialog_add_action_widget(GTK_DIALOG(dialog),hibernate,GTK_RESPONSE_OK); 
-	 }
-	 
-	 if ( priv->power_management & SYSTEM_CAN_SHUTDOWN )
-	 {                                     
-		GtkWidget *shutdown = gtk_button_new_with_label(_("Shutdown"));
-		gtk_widget_show(shutdown);                                     
-		gtk_dialog_add_action_widget(GTK_DIALOG(dialog),shutdown,GTK_RESPONSE_ACCEPT); 
-	 }
-     
-     switch(gtk_dialog_run(GTK_DIALOG(dialog)))
-     {
-     	case GTK_RESPONSE_OK:
-			g_signal_emit(G_OBJECT(batt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_HIBERNATE,TRUE);
-     		break;
-		case GTK_RESPONSE_ACCEPT:
-			g_signal_emit(G_OBJECT(batt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_SHUTDOWN,TRUE);
-			break;
-     	default:
-     		break;
-     }
-	 gtk_widget_destroy(dialog);
-#endif
-}
+    
+    sprintf(tip, "%i", percentage);
+    strcat(tip,_("%"));
+    strcat(tip," ");
 
-static void
-xfpm_battery_handle_primary_critical(XfpmBattery *batt,XfpmBatteryIcon *icon)
-{
-    if ( batt->critical_action == XFPM_DO_HIBERNATE )
+    if ( !is_charging && !is_discharging && last_full == current_charge )
     {
-        XFPM_DEBUG("Sending Hibernate request\n");
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_HIBERNATE,TRUE);
-        return;
+	sprintf(tip, "%s",_("Battery fully charged"));
+	state = BATTERY_FULLY_CHARGED;
+	xfpm_tray_icon_set_tooltip(battery->priv->icon, tip);
     }
-    
-    if ( batt->critical_action == XFPM_DO_SHUTDOWN )
+    else if ( !is_charging && !is_discharging && last_full != current_charge )
     {
-        XFPM_DEBUG("Sending shutdown request\n");
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_SHUTDOWN,TRUE);
-        return;
+        strcat(tip,_("Battery charge level"));
+	state = BATTERY_NOT_FULLY_CHARGED;
+	xfpm_tray_icon_set_tooltip(battery->priv->icon, tip);
     }
-    
-    if ( batt->critical_action == XFPM_DO_NOTHING )
+    else if ( is_charging && !is_discharging )
     {
-        xfpm_battery_show_critical_options(batt,icon,PRIMARY);
+	strcat(tip,_("Battery is charging"));
+	state = BATTERY_IS_CHARGING;
+	xfpm_tray_icon_set_tooltip(battery->priv->icon, tip);
     }
-}
-
-static gboolean
-xfpm_battery_is_critical_charge(XfpmBattery *batt)
-{
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    
-    if ( g_hash_table_size(priv->batteries ) == 1 ) return TRUE;
-    if ( g_hash_table_size(priv->batteries)  == 0 ) return FALSE;
-        
-    GList *icons_list;
-    int i=0;
-    icons_list = g_hash_table_get_values(priv->batteries);
-        
-    gboolean critical = FALSE;
-    
-    for ( i = 0 ; i < g_list_length(icons_list) ; i++ )
+    else if ( !is_charging && is_discharging )
     {
-	XfpmBatteryType type;
-	XfpmBatteryState state;
-	XfpmBatteryIcon *icon;
-        icon = g_list_nth_data(icons_list,i);
-	if ( icon )
+	if ( percentage >= 10 )
 	{
-		g_object_get(G_OBJECT(icon),"battery-type", &type, "battery-state", &state, NULL);
-		if ( type != PRIMARY || type != UPS ) continue;
+	    if ( battery->priv->type == HAL_DEVICE_TYPE_PRIMARY )
+	    	strcat(tip, 
+		       battery->priv->adapter_present ? 
+		       _("Battery is discharging") : 
+		       _("System is running on battery"));
+	    else 
+	    	strcat(tip, _("Battery is discharging") );
 		
-		if ( state == CRITICAL ) critical = TRUE;
-		else                     critical = FALSE;
+	    state = BATTERY_IS_DISCHARGING;
 	}
+	else
+	{
+	    strcat(tip, _("Battery is almost empty"));
+	    state = BATTERY_CRITICALLY_LOW;
+    	}
+	xfpm_tray_icon_set_tooltip(battery->priv->icon, tip);
     }
     
-    return critical;
+    xfpm_battery_refresh_state (battery, state);
 }
 
 static void
-xfpm_battery_handle_critical_charge(XfpmBattery *batt,XfpmBatteryIcon *icon)
-{
-    XfpmBatteryType battery_type;
-    g_object_get(G_OBJECT(icon),"battery-type",&battery_type,NULL);
-    
-    if ( battery_type == PRIMARY || battery_type == UPS )
-    {
-	if ( xfpm_battery_is_critical_charge(batt) )
-        	xfpm_battery_handle_primary_critical(batt,icon);
-    }
+xfpm_battery_refresh (XfpmBattery *battery)
+{
+    gboolean is_present, is_charging, is_discharging = FALSE;
+    guint percentage = 0;
+    guint32 last_full, current_charge = 0;
+    
+    g_object_get (G_OBJECT(battery->priv->device), 
+    		  "is-present", &is_present,
+		  "is-charging", &is_charging,
+		  "is-discharging", &is_discharging, 
+		  "percentage", &percentage,
+		  "last-full", &last_full,
+		  "current-charge", &current_charge,
+		  NULL);
+    
+    xfpm_battery_refresh_icon (battery, is_present, is_charging, is_discharging, percentage);
+    xfpm_battery_refresh_tooltip (battery, is_present, 
+				  is_charging, is_discharging, 
+				  last_full, current_charge,
+				  percentage);
 }
 
 static void
-xfpm_battery_state_change_cb(GObject *object,GParamSpec *arg1,gpointer data)
+xfpm_battery_device_changed_cb (HalDevice *device, XfpmBattery *battery)
 {
-    if ( !xfpm_strcmp(arg1->name,"battery-state") ) 
-    {
-        XfpmBatteryState state;
-        XfpmBattery *batt = XFPM_BATTERY(data);
-        g_object_get(object,"battery-state",&state,NULL);
-        
-        /* refresh here for the tray icon hiding if option
-         * show icon is charging or discharging and battery is fully charged
-         */
-        xfpm_battery_refresh_tray_icon(batt);
-#ifdef DEBUG
-        gchar *content;
-        GValue value = { 0, };
-        g_value_init(&value,XFPM_TYPE_BATTERY_STATE);
-        g_value_set_enum(&value,state);
-        content = g_strdup_value_contents(&value);
-        XFPM_DEBUG("param:%s value:%s\n",arg1->name,content);
-        g_free(content);
-#endif  
-        if ( state == CRITICAL )
-        {
-            xfpm_battery_handle_critical_charge(batt,XFPM_BATTERY_ICON(object));
-        }
-    }
+    TRACE("start");
+    xfpm_battery_refresh (battery);
+    xfpm_battery_refresh_visible_icon (battery);
 }
 
-static void
-xfpm_battery_hibernate_callback(GtkWidget *widget,XfpmBattery *batt)
+static gchar *
+_get_icon_prefix_from_enum_type (HalDeviceType type)
 {
-    gboolean ret = 
-    xfce_confirm(_("Are you sure you want to hibernate the system?"),
-                GTK_STOCK_YES,
-                _("Hibernate"));
-    
-    if ( ret ) 
+    if ( type == HAL_DEVICE_TYPE_PRIMARY )
     {
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_HIBERNATE,FALSE);
-	}
-}
-
-
-static void
-xfpm_battery_suspend_callback(GtkWidget *widget,XfpmBattery *batt)
-{
-    gboolean ret = 
-    xfce_confirm(_("Are you sure you want to suspend the system?"),
-                GTK_STOCK_YES,
-                _("Suspend"));
-    
-    if ( ret ) 
+	return g_strdup("gpm-primary-");
+    }
+    else if ( type == HAL_DEVICE_TYPE_UPS ) 
     {
-        g_signal_emit(G_OBJECT(batt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_SUSPEND,FALSE);
+	return g_strdup("gpm-ups-");
     }
-}
-
-static void xfpm_battery_popup_tray_icon_menu(GtkStatusIcon *tray_icon,
-                                             guint button,
-                                             guint activate_time,
-                                             XfpmBattery *batt)
-{
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    
-    GtkWidget *menu,*mi,*img;
-	
-	menu = gtk_menu_new();
-	// Hibernate menu option
-	mi = gtk_image_menu_item_new_with_label(_("Hibernate"));
-	img = gtk_image_new_from_icon_name("gpm-hibernate",GTK_ICON_SIZE_MENU);
-	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi),img);
-	gtk_widget_set_sensitive(mi,FALSE);
-	if ( priv->power_management & SYSTEM_CAN_HIBERNATE )
-	{
-		gtk_widget_set_sensitive(mi,TRUE);
-		g_signal_connect(mi,"activate",
-					 	 G_CALLBACK(xfpm_battery_hibernate_callback),
-					 	 batt);
-	}
-	gtk_widget_show(mi);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	// Suspend menu option
-	mi = gtk_image_menu_item_new_with_label(_("Suspend"));
-	img = gtk_image_new_from_icon_name("gpm-suspend",GTK_ICON_SIZE_MENU);
-	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi),img);
-	
-	gtk_widget_set_sensitive(mi,FALSE);
-	if ( priv->power_management & SYSTEM_CAN_SUSPEND )
-    {	
-		gtk_widget_set_sensitive(mi,TRUE);
-		g_signal_connect(mi,"activate",
-					     G_CALLBACK(xfpm_battery_suspend_callback),
-					     batt);
-	}
-	gtk_widget_show(mi);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	// Separotor
-	mi = gtk_separator_menu_item_new();
-	gtk_widget_show(mi);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP,NULL);
-	gtk_widget_set_sensitive(mi,TRUE);
-	gtk_widget_show(mi);
-	g_signal_connect(mi,"activate",G_CALLBACK(xfpm_help),NULL);
-	
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT,NULL);
-	gtk_widget_set_sensitive(mi,TRUE);
-	gtk_widget_show(mi);
-	g_signal_connect(mi,"activate",G_CALLBACK(xfpm_about),NULL);
-	
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_PREFERENCES,NULL);
-	gtk_widget_set_sensitive(mi,TRUE);
-	gtk_widget_show(mi);
-	g_signal_connect(mi,"activate",G_CALLBACK(xfpm_preferences),NULL);
-	
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
-	
-	// Popup the menu
-	gtk_menu_popup(GTK_MENU(menu),NULL,NULL,
-		       gtk_status_icon_position_menu,tray_icon,button,activate_time);
-}
-
-static XfpmBatteryType
-xfpm_battery_get_battery_type(const gchar *battery_type)
-{
-    if ( !xfpm_strcmp("primary",battery_type) )
+    else if ( type == HAL_DEVICE_TYPE_MOUSE ) 
+    {
+	return g_strdup("gpm-mouse-");
+    }
+    else if ( type == HAL_DEVICE_TYPE_KEYBOARD ) 
     {
-        return PRIMARY;
+	return g_strdup("gpm-keyboard-");
     }
-    else if ( !xfpm_strcmp("keyboard",battery_type) )
+    else if ( type == HAL_DEVICE_TYPE_CAMERA ) 
     {
-        return KEYBOARD;
+	return g_strdup("gpm-camera-");
     }
-    else if ( !xfpm_strcmp("mouse",battery_type) ) 
+    else if ( type == HAL_DEVICE_TYPE_PDA ) 
     {
-        return MOUSE;
+	return g_strdup("gpm-pda-");
     }
-    else if ( !xfpm_strcmp("ups",battery_type) ) 
+    else if ( type == HAL_DEVICE_TYPE_KEYBOARD_MOUSE ) 
     {
-        return UPS; 
+	return g_strdup("gpm-keyboard-mouse-");
     }
     
-    return UNKNOWN;
+    return g_strdup("gpm-primary-");
 }
 
-
-static gboolean
-xfpm_battery_check(XfpmBattery *batt,const gchar *udi)
+static void
+xfpm_battery_popup_menu_cb (GtkStatusIcon *icon, guint button, guint activate_time, XfpmBattery *battery)
 {
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    
-    // Sanity check
-    // All those keys are flagged as always exist on device battery, except for battery.is_rechargeable
-    if ( !xfpm_hal_device_have_key(priv->hal,udi,"battery.is_rechargeable") ||
-         !xfpm_hal_device_have_key(priv->hal,udi,"battery.charge_level.last_full") ||
-         !xfpm_hal_device_have_key(priv->hal,udi,"battery.charge_level.current")   ||
-         !xfpm_hal_device_have_key(priv->hal,udi,"battery.present")  ||
-         !xfpm_hal_device_have_key(priv->hal,udi,"battery.rechargeable.is_charging") ||
-         !xfpm_hal_device_have_key(priv->hal,udi,"battery.rechargeable.is_discharging") ||
-         !xfpm_hal_device_have_key(priv->hal,udi,"battery.type") )
-    {
-        return FALSE;
-    }
-    
-    return TRUE;
+    g_signal_emit (G_OBJECT(battery), signals[POPUP_BATTERY_MENU], 0,
+    		   icon, button, activate_time, battery->priv->type);
 }
 
-static gboolean
-xfpm_battery_is_new(XfpmBattery *batt, const gchar *udi, 
-                    XfpmBatteryType battery_type, guint last_full)
+XfpmBattery *
+xfpm_battery_new(const HalDevice *device)
 {
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    
-    GList *keys;
+    XfpmBattery *battery = NULL;
     
-    keys = g_hash_table_get_keys(priv->batteries);
+    battery = g_object_new(XFPM_TYPE_BATTERY, NULL);
     
-    if ( !keys ) return TRUE;
+    battery->priv->device = (HalDevice *)g_object_ref(G_OBJECT(device));
     
-    if ( g_list_length(keys) == 0 ) return TRUE;
+    g_object_get(G_OBJECT(battery->priv->device), "type", &battery->priv->type, NULL);
     
-    int i = 0;
+    battery->priv->icon_prefix = _get_icon_prefix_from_enum_type(battery->priv->type);
     
-    for ( i = 0; i < g_list_length(keys); i++)
-    {
-        GError *error = NULL;
-        gchar *udi_b = (gchar *) g_list_nth_data(keys,i);
-        guint last_full_b = xfpm_hal_get_int_info(priv->hal,
-                                            udi_b,
-                                            "battery.charge_level.last_full",
-                                            &error);
-        if ( error )
-        {
-            XFPM_DEBUG("%s:\n",error->message);
-            g_error_free(error);
-            return TRUE;
-        }
-        
-        gchar *batt_type_b = xfpm_hal_get_string_info(priv->hal,
-                                                      udi_b,
-                                                      "battery.type",
-                                                      &error);
-        if ( error ) 
-        {
-            XFPM_DEBUG("%s:\n",error->message);
-            g_error_free(error);
-            return TRUE;
-        } 
-        
-         XfpmBatteryType type_b = 
-            xfpm_battery_get_battery_type(batt_type_b);
-            if ( batt_type_b )
-            libhal_free_string(batt_type_b);
-        
-        if ( type_b == battery_type && last_full_b == last_full ) return FALSE;
-    }       
+    xfpm_battery_refresh (battery);
+    g_signal_connect (G_OBJECT(battery->priv->device), "device-changed",
+		      G_CALLBACK(xfpm_battery_device_changed_cb), battery);
+		      
+    g_signal_connect (G_OBJECT(xfpm_tray_icon_get_tray_icon(battery->priv->icon)), "popup-menu",
+		      G_CALLBACK(xfpm_battery_popup_menu_cb), battery);
     
-    return TRUE;
+    return battery;
 }
 
-static void
-xfpm_battery_new_device(XfpmBattery *batt,const gchar *udi)
+void xfpm_battery_set_adapter_presence (XfpmBattery *battery, gboolean adapter_present)
 {
-    if ( !xfpm_battery_check(batt,udi) )
-    {
-        return;
-    }
-    
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    
-    GError *error = NULL;      
-    guint last_full = xfpm_hal_get_int_info(priv->hal,
-                                          udi,
-                                          "battery.charge_level.last_full",
-                                          &error);
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    gint32 current   = xfpm_hal_get_int_info(priv->hal,
-                                          udi,
-                                          "battery.charge_level.current",
-                                          &error);
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    }                                      
-    gboolean is_present = xfpm_hal_get_bool_info(priv->hal,
-                                                udi,
-                                               "battery.present",
-                                               &error);
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    }                                             
-    gboolean is_charging = xfpm_hal_get_bool_info(priv->hal,
-                                                  udi,
-                                                  "battery.rechargeable.is_charging",
-                                                  &error);
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    }                                              
-    gboolean is_discharging = xfpm_hal_get_bool_info(priv->hal,
-                                                     udi,
-                                                     "battery.rechargeable.is_discharging",
-                                                     &error);
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    }                                                 
-    gchar *battery_type = xfpm_hal_get_string_info(priv->hal,
-                                                  udi,
-                                                  "battery.type",
-                                                  &error);
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    } 
-    
-    guint percentage;            
-    if (xfpm_hal_device_have_key(priv->hal,udi,"battery.charge_level.persentage"))
-    {
-        if ( error ) 
-        {
-            XFPM_DEBUG("%s:\n",error->message);
-            g_error_free(error);
-            return;
-        }                                      
-        percentage = xfpm_hal_get_int_info(priv->hal,
-                                          udi,
-                                          "battery.charge_level.percentage",
-                                          &error);
-    }
-    else
-    {
-        percentage = _get_battery_percentage(last_full,current);
-    }
-   
-    gint32 remaining_time  = 0 ;
-    if (xfpm_hal_device_have_key(priv->hal,udi,"battery.remaining_time"))
-    {
-        if ( error ) 
-        {
-            XFPM_DEBUG("%s:\n",error->message);
-            g_error_free(error);
-            return;
-        }                                      
-        remaining_time = xfpm_hal_get_int_info(priv->hal,
-                                               udi,
-                                               "battery.remaining_time",
-                                               &error);
-    }
-    
-    XfpmBatteryType type = 
-    xfpm_battery_get_battery_type(battery_type);
-    if ( battery_type )
-        libhal_free_string(battery_type);
-    if ( type == UPS ) priv->ups_found = TRUE;    
-    
-    /* Check if this battery is new, udevadm trigger cause hal to make a new udi
-     * for a existing battery */
+    g_return_if_fail ( XFPM_IS_BATTERY(battery));
     
-    if ( !xfpm_battery_is_new(batt, udi, type, last_full) )  
-    {
-        XFPM_DEBUG("Battery with udi=%s already monitored\n",udi);
-        return;
-    } 
-    
-    GtkStatusIcon *batt_icon;
-    batt_icon = xfpm_battery_icon_new(last_full,
-                                      type,
-                                      batt->critical_level,
-                                      TRUE);
-                                      
-#ifdef HAVE_LIBNOTIFY    
-    g_object_set(batt_icon,"systray-notify",batt->notify_enabled,NULL);
-#endif    
-                                                  
-    xfpm_battery_icon_set_state(XFPM_BATTERY_ICON(batt_icon),
-                                current,
-                                percentage,
-                                remaining_time,
-                                is_present,
-                                is_charging,
-                                is_discharging,
-                                batt->ac_adapter_present);
-                                
-    g_signal_connect(batt_icon,"notify",G_CALLBACK(xfpm_battery_state_change_cb),batt);                            
-    g_signal_connect(batt_icon,"popup-menu",G_CALLBACK(xfpm_battery_popup_tray_icon_menu),batt);
-    
-    g_hash_table_insert(priv->batteries,g_strdup(udi),batt_icon);
-    xfpm_battery_refresh(batt);
+    battery->priv->adapter_present = adapter_present;
 }
 
-static void
-xfpm_battery_get_devices(XfpmBattery *batt)
+void xfpm_battery_set_show_icon (XfpmBattery *battery, XfpmShowIcon show_icon)
 {
-    XFPM_DEBUG("Getting batteries\n");
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
+    g_return_if_fail (XFPM_IS_BATTERY(battery));
     
-    int num,i;
-    gchar **udi = NULL;
-    GError *error = NULL;
+    battery->priv->show_icon = show_icon;
     
-    udi = xfpm_hal_get_device_udi_by_capability(priv->hal,"battery",&num,&error);
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    if ( num == 0 ) return;
-    if ( !udi )     return; 
-
-    for ( i = 0 ; udi[i]; i++)
-    {
-        if ( xfpm_hal_device_have_key(priv->hal,udi[i],"battery.is_rechargeable"))
-        {
-            XFPM_DEBUG("found battery %s\n",udi[i]);
-            xfpm_battery_new_device(batt,udi[i]);
-        }
-    }
-    libhal_free_string_array(udi);
+    xfpm_battery_refresh_visible_icon (battery);
 }
 
-XfpmBattery *
-xfpm_battery_new(void)
+const HalDevice	*
+xfpm_battery_get_device (XfpmBattery *battery)
 {
-    XfpmBattery *battery = NULL;
-    battery = g_object_new(XFPM_TYPE_BATTERY,NULL);
-    return battery;
+    g_return_val_if_fail (XFPM_IS_BATTERY(battery), NULL);
+    
+    return battery->priv->device;
 }
 
-void           
-xfpm_battery_monitor(XfpmBattery *batt)
+//FIXME: default g_return value
+XfpmBatteryState xfpm_battery_get_state (XfpmBattery *battery)
 {
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);
-    xfpm_battery_get_devices(batt);
-    xfpm_battery_refresh(batt);
+    g_return_val_if_fail (XFPM_IS_BATTERY(battery), 0);
+    
+    return battery->priv->state;
 }
 
-
-#ifdef HAVE_LIBNOTIFY
-void           xfpm_battery_show_error(XfpmBattery *batt,
-                                       const gchar *icon_name,
-                                       const gchar *error)
+GtkStatusIcon  *xfpm_battery_get_status_icon    (XfpmBattery *battery)
 {
-    g_return_if_fail(XFPM_IS_BATTERY(batt));
-    
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);     
+    g_return_val_if_fail (XFPM_IS_BATTERY(battery), NULL);
     
-    GtkStatusIcon *icon = NULL;
+    return xfpm_tray_icon_get_tray_icon (battery->priv->icon);
     
-    GList *icons_list;
-    int i=0;
-    icons_list = g_hash_table_get_values(priv->batteries);
-    for ( i = 0 ; i < g_list_length(icons_list) ; i++ )
-    {
-        icon = g_list_nth_data(icons_list,i);
-        if ( icon ) 
-        {
-            gboolean visible;
-            XfpmBatteryType type;
-            g_object_get(G_OBJECT(icon),"visible",&visible,"battery-type",&type,NULL);
-            if ( visible && type == PRIMARY )
-            {
-                break;
-            }
-        }
-        icon = NULL;
-    }
-    NotifyNotification *n =
-    xfpm_notify_new(_("Xfce power manager"),
-                    error,
-                    14000,
-                    NOTIFY_URGENCY_CRITICAL,
-                    icon != NULL ? GTK_STATUS_ICON(icon) : NULL,
-                    icon_name);
-    xfpm_notify_show_notification(n,0);                 
-}                                       
-#endif
+}
 
-void           
-xfpm_battery_set_power_info(XfpmBattery *batt,guint8 power_management)
+XfpmNotify *    xfpm_battery_get_notify_obj     (XfpmBattery *battery)
 {
-    g_return_if_fail(XFPM_IS_BATTERY(batt));
+    g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
     
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt);                            
+    return battery->priv->notify;
+}
 
-    priv->power_management = power_management;  
-}                                        
-                                            
-gboolean       
-xfpm_battery_ups_found     (XfpmBattery *batt)
+const gchar *xfpm_battery_get_icon_name (XfpmBattery *battery)
 {
-    g_return_val_if_fail(XFPM_IS_BATTERY(batt),FALSE);
-    XfpmBatteryPrivate *priv;
-    priv = XFPM_BATTERY_GET_PRIVATE(batt); 
+    g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
+    
+    return xfpm_tray_icon_get_icon_name (battery->priv->icon);
+}
+    
+void xfpm_battery_show_info (XfpmBattery *battery)
+{
+    g_return_if_fail (XFPM_IS_BATTERY(battery));
+    
+    gchar *icon = g_strdup_printf("%s%s",
+				  battery->priv->icon_prefix, 
+	    			  xfpm_battery_get_icon_index(battery->priv->type, 100));
+				      
+    GtkWidget *info = xfpm_battery_info_new (battery->priv->device, icon);
+    
+    g_free (icon);
     
-    return priv->ups_found;
+    gtk_widget_show_all (info);
 }
diff --git a/src/xfpm-battery.h b/src/xfpm-battery.h
index 5e85ab8b..63d1b0c8 100644
--- a/src/xfpm-battery.h
+++ b/src/xfpm-battery.h
@@ -1,5 +1,4 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
+/*
  * * Copyright (C) 2008 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
@@ -16,69 +15,59 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifndef __XFPM_BATTERY_H
 #define __XFPM_BATTERY_H
 
 #include <glib-object.h>
+#include <gtk/gtk.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "libxfpm/hal-device.h"
 
-#include "xfpm-enums.h"
+#include "xfpm-enum-glib.h"
+#include "xfpm-notify.h"
 
 G_BEGIN_DECLS
 
-#define XFPM_TYPE_BATTERY    (xfpm_battery_get_type())
-#define XFPM_BATTERY(o)      (G_TYPE_CHECK_INSTANCE_CAST(o,XFPM_TYPE_BATTERY,XfpmBattery))
-#define XFPM_IS_BATTERY(o)   (G_TYPE_CHECK_INSTANCE_TYPE(o,XFPM_TYPE_BATTERY))
+#define XFPM_TYPE_BATTERY        (xfpm_battery_get_type () )
+#define XFPM_BATTERY(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_BATTERY, XfpmBattery))
+#define XFPM_IS_BATTERY(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_BATTERY))
 
 typedef struct XfpmBatteryPrivate XfpmBatteryPrivate;
 
 typedef struct
 {
-    GObject parent;
-    XfpmBatteryPrivate *priv;
-    
-    gboolean ac_adapter_present;
-    guint critical_level;
-    XfpmActionRequest critical_action;
-    XfpmShowIcon show_tray;
-    
-#ifdef HAVE_LIBNOTIFY
-    gboolean notify_enabled;
-#endif        
+    GObject		 parent;
+    XfpmBatteryPrivate	*priv;
     
 } XfpmBattery;
 
 typedef struct
 {
-    GObjectClass parent_class;
+    GObjectClass         parent_class;
     
-    /* signals */
-    void  (*show_adapter_icon)      (XfpmBattery *batt,
-                                     gboolean show);
-    void  (*battery_action_request) (XfpmBattery *batt,
-                                     XfpmActionRequest action,
-                                     gboolean critical);
-                                   
+    void	        (*battery_state_changed)	(XfpmBattery *battery,
+    					            	 XfpmBatteryState state);
+    void                (*popup_battery_menu)		(XfpmBattery *battery,
+						         GtkStatusIcon *icon);
+       
 } XfpmBatteryClass;
 
-GType          xfpm_battery_get_type      (void) G_GNUC_CONST;
-XfpmBattery   *xfpm_battery_new           (void);
-void           xfpm_battery_monitor       (XfpmBattery *batt);
+GType        		 xfpm_battery_get_type           (void) G_GNUC_CONST;
+XfpmBattery    		*xfpm_battery_new                (const HalDevice *device);
+void                     xfpm_battery_set_adapter_presence(XfpmBattery *battery,
+							  gboolean adapter_present);
+void                     xfpm_battery_set_show_icon      (XfpmBattery *battery,
+							  XfpmShowIcon show_icon);
+const HalDevice		*xfpm_battery_get_device         (XfpmBattery *battery);
+XfpmBatteryState         xfpm_battery_get_state          (XfpmBattery *battery);
+GtkStatusIcon  		*xfpm_battery_get_status_icon    (XfpmBattery *battery);
+XfpmNotify     		*xfpm_battery_get_notify_obj     (XfpmBattery *battery);
+const gchar    		*xfpm_battery_get_icon_name      (XfpmBattery *battery);
+void            	 xfpm_battery_show_info          (XfpmBattery *battery);
 
-#ifdef HAVE_LIBNOTIFY
-void           xfpm_battery_show_error    (XfpmBattery *batt,
-                                           const gchar *icon_name,
-                                           const gchar *error);     
-#endif
-void           xfpm_battery_set_power_info(XfpmBattery *batt,
-                                           guint8 power_management);
-gboolean       xfpm_battery_ups_found     (XfpmBattery *batt);                                        
 G_END_DECLS
 
-#endif
+#endif /* __XFPM_BATTERY_H */
diff --git a/src/xfpm-brightness-hal.c b/src/xfpm-brightness-hal.c
new file mode 100644
index 00000000..d5861dd7
--- /dev/null
+++ b/src/xfpm-brightness-hal.c
@@ -0,0 +1,90 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include "xfpm-brightness-hal.h"
+
+/* Init */
+static void xfpm_brightness_hal_class_init (XfpmBrightnessHalClass *klass);
+static void xfpm_brightness_hal_init       (XfpmBrightnessHal *brg);
+static void xfpm_brightness_hal_finalize   (GObject *object);
+
+#define XFPM_BRIGHTNESS_HAL_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_BRIGHTNESS_HAL, XfpmBrightnessHalPrivate))
+
+struct XfpmBrightnessHalPrivate
+{
+    gboolean hw_found;
+};
+
+G_DEFINE_TYPE(XfpmBrightnessHal, xfpm_brightness_hal, G_TYPE_OBJECT)
+
+static void
+xfpm_brightness_hal_class_init(XfpmBrightnessHalClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->finalize = xfpm_brightness_hal_finalize;
+
+
+    g_type_class_add_private(klass,sizeof(XfpmBrightnessHalPrivate));
+}
+
+static void
+xfpm_brightness_hal_init(XfpmBrightnessHal *brg)
+{
+    brg->priv = XFPM_BRIGHTNESS_HAL_GET_PRIVATE(brg);
+}
+
+static void
+xfpm_brightness_hal_finalize(GObject *object)
+{
+    XfpmBrightnessHal *brg;
+
+    brg = XFPM_BRIGHTNESS_HAL(object);
+    
+    G_OBJECT_CLASS(xfpm_brightness_hal_parent_class)->finalize(object);
+}
+
+XfpmBrightnessHal *
+xfpm_brightness_hal_new(void)
+{
+    XfpmBrightnessHal *brg = NULL;
+    brg = g_object_new (XFPM_TYPE_BRIGHTNESS_HAL, NULL);
+    
+    return brg;
+}
diff --git a/src/xfpm-brightness-hal.h b/src/xfpm-brightness-hal.h
new file mode 100644
index 00000000..dd89d7c4
--- /dev/null
+++ b/src/xfpm-brightness-hal.h
@@ -0,0 +1,52 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_BRIGHTNESS_HAL_H
+#define __XFPM_BRIGHTNESS_HAL_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_BRIGHTNESS_HAL        (xfpm_brightness_hal_get_type () )
+#define XFPM_BRIGHTNESS_HAL(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_BRIGHTNESS_HAL, XfpmBrightnessHal))
+#define XFPM_IS_BRIGHTNESS_HAL(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_BRIGHTNESS_HAL))
+
+typedef struct XfpmBrightnessHalPrivate XfpmBrightnessHalPrivate;
+
+typedef struct
+{
+    GObject		 		parent;
+    XfpmBrightnessHalPrivate	       *priv;
+    
+} XfpmBrightnessHal;
+
+typedef struct
+{
+    GObjectClass 			parent_class;
+    
+} XfpmBrightnessHalClass;
+
+GType        				xfpm_brightness_hal_get_type        (void) G_GNUC_CONST;
+XfpmBrightnessHal      		       *xfpm_brightness_hal_new             (void);
+
+G_END_DECLS
+
+#endif /* __XFPM_BRIGHTNESS_HAL_H */
diff --git a/src/xfpm-button-xf86.c b/src/xfpm-button-xf86.c
new file mode 100644
index 00000000..d274fc47
--- /dev/null
+++ b/src/xfpm-button-xf86.c
@@ -0,0 +1,241 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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
+ */
+
+
+/*
+ * Based on code from gpm-button (gnome power manager)
+ * Copyright (C) 2006-2007 Richard Hughes <richard@hughsie.com>
+ * 
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/XF86keysym.h>
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "xfpm-button-xf86.h"
+#include "xfpm-enum-types.h"
+
+/* Init */
+static void xfpm_button_xf86_class_init (XfpmButtonXf86Class *klass);
+static void xfpm_button_xf86_init       (XfpmButtonXf86 *button);
+static void xfpm_button_xf86_finalize   (GObject *object);
+
+#define XFPM_BUTTON_XF86_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_BUTTON_XF86, XfpmButtonXf86Private))
+
+struct XfpmButtonXf86Private
+{
+    GdkScreen	*screen;
+    GdkWindow   *window;
+    GHashTable  *hash;
+};
+
+enum
+{
+    XF86_BUTTON_PRESSED,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE(XfpmButtonXf86, xfpm_button_xf86, G_TYPE_OBJECT)
+
+static void
+xfpm_button_xf86_class_init(XfpmButtonXf86Class *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    signals[XF86_BUTTON_PRESSED] = 
+        g_signal_new("xf86-button-pressed",
+                      XFPM_TYPE_BUTTON_XF86,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET(XfpmButtonXf86Class, xf86_button_pressed),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__ENUM,
+                      G_TYPE_NONE, 1, XFPM_TYPE_XF86_BUTTON);
+
+    object_class->finalize = xfpm_button_xf86_finalize;
+
+    g_type_class_add_private(klass,sizeof(XfpmButtonXf86Private));
+}
+
+static void
+xfpm_button_xf86_init(XfpmButtonXf86 *button)
+{
+    button->priv = XFPM_BUTTON_XF86_GET_PRIVATE(button);
+    
+    button->priv->screen = NULL;
+    button->priv->window = NULL;
+    
+    button->priv->hash = g_hash_table_new (NULL, NULL);
+}
+
+static void
+xfpm_button_xf86_finalize(GObject *object)
+{
+    XfpmButtonXf86 *button;
+
+    button = XFPM_BUTTON_XF86 (object);
+
+    G_OBJECT_CLASS(xfpm_button_xf86_parent_class)->finalize(object);
+}
+
+static GdkFilterReturn
+xfpm_button_xf86_filter_x_events (GdkXEvent *xevent, GdkEvent *ev, gpointer data)
+{
+    XEvent *xev = (XEvent *) xevent;
+    
+    if ( xev->type != KeyPress )
+    	return GDK_FILTER_CONTINUE;
+    
+    XfpmButtonXf86 *button = (XfpmButtonXf86 *) data;
+    
+    gpointer key_hash = g_hash_table_lookup (button->priv->hash, GINT_TO_POINTER(xev->xkey.keycode));
+    
+    if ( !key_hash )
+    {
+	g_print("Key %d not found in hash\n", xev->xkey.keycode);
+	return GDK_FILTER_CONTINUE;
+    }
+    
+    XfpmXF86Button type = GPOINTER_TO_INT (key_hash);
+    
+    TRACE("Found key in hash %d", type);
+    
+    g_signal_emit (G_OBJECT(button), signals[XF86_BUTTON_PRESSED], 0, type);
+    
+    return GDK_FILTER_REMOVE;
+}
+
+static gboolean
+xfpm_button_xf86_grab_keystring (XfpmButtonXf86 *button, guint keycode)
+{
+    Display *display;
+    guint ret;
+    guint modmask = 0;
+    
+    display = GDK_DISPLAY ();
+    
+    gdk_error_trap_push ();
+
+    ret = XGrabKey (display, keycode, modmask,
+		    GDK_WINDOW_XID (button->priv->window), True,
+		    GrabModeAsync, GrabModeAsync);
+		    
+    if ( ret == BadAccess )
+    {
+	g_warning ("Failed to grab modmask=%u, keycode=%li",
+		    modmask, (long int) keycode);
+	return FALSE;
+    }
+	
+    ret = XGrabKey (display, keycode, LockMask | modmask,
+			GDK_WINDOW_XID (button->priv->window), True,
+			GrabModeAsync, GrabModeAsync);
+			
+    if (ret == BadAccess)
+    {
+	g_warning ("Failed to grab modmask=%u, keycode=%li",
+		   LockMask | modmask, (long int) keycode);
+	return FALSE;
+    }
+
+    gdk_flush ();
+    gdk_error_trap_pop ();
+
+    TRACE("Grabbed modmask=%x, keycode=%li", modmask, (long int) keycode);
+    
+    return TRUE;
+    
+}
+
+static gboolean
+xfpm_button_xf86_xevent_key (XfpmButtonXf86 *button, guint keysym , XfpmXF86Button type)
+{
+    guint keycode = XKeysymToKeycode (GDK_DISPLAY(), keysym);
+
+    if ( keycode == 0 )
+    {
+	g_critical ("could not map keysym %x to keycode\n", keysym);
+	return FALSE;
+    }
+    
+    if ( !xfpm_button_xf86_grab_keystring(button, keycode)) 
+    {
+    	g_critical ("Failed to grab %i\n", keycode);
+	return FALSE;
+    }
+	
+    g_hash_table_insert (button->priv->hash, GINT_TO_POINTER(keycode), GINT_TO_POINTER(type));
+    
+    return TRUE;
+}
+
+static void
+xfpm_button_xf86_setup (XfpmButtonXf86 *button)
+{
+    button->priv->screen = gdk_screen_get_default ();
+    button->priv->window = gdk_screen_get_root_window (button->priv->screen);
+    
+    xfpm_button_xf86_xevent_key (button, XF86XK_PowerOff, BUTTON_POWER_OFF);
+    xfpm_button_xf86_xevent_key (button, XF86XK_Sleep, BUTTON_SLEEP);
+    xfpm_button_xf86_xevent_key (button, XF86XK_MonBrightnessUp, BUTTON_MON_BRIGHTNESS_UP);
+    xfpm_button_xf86_xevent_key (button, XF86XK_MonBrightnessDown, BUTTON_MON_BRIGHTNESS_DOWN);
+
+/*    
+    xfpm_button_xf86_xf86_xevent_key (button, XF86XK_KbdBrightnessUp);
+    xfpm_button_xf86_xf86_xevent_key (button, XF86XK_KbdBrightnessDown);
+*/  
+    gdk_window_add_filter (button->priv->window, 
+			   xfpm_button_xf86_filter_x_events, button);
+}
+
+XfpmButtonXf86 *
+xfpm_button_xf86_new(void)
+{
+    XfpmButtonXf86 *button = NULL;
+    button = g_object_new (XFPM_TYPE_BUTTON_XF86, NULL);
+    
+    xfpm_button_xf86_setup (button);
+    
+    return button;
+}
diff --git a/src/xfpm-button-xf86.h b/src/xfpm-button-xf86.h
new file mode 100644
index 00000000..b9463bcd
--- /dev/null
+++ b/src/xfpm-button-xf86.h
@@ -0,0 +1,57 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_BUTTON_XF86_H
+#define __XFPM_BUTTON_XF86_H
+
+#include <glib-object.h>
+
+#include "xfpm-enum-glib.h"
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_BUTTON_XF86   (xfpm_button_xf86_get_type () )
+#define XFPM_BUTTON_XF86(o)     (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_BUTTON_XF86, XfpmButtonXf86))
+#define XFPM_IS_BUTTON_XF86(o)  (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_BUTTON_XF86))
+
+typedef struct XfpmButtonXf86Private XfpmButtonXf86Private;
+
+typedef struct
+{
+    GObject		  	parent;
+    XfpmButtonXf86Private      *priv;
+    
+} XfpmButtonXf86;
+
+typedef struct
+{
+    GObjectClass parent_class;
+     
+    void                 (*xf86_button_pressed)	(XfpmButtonXf86 *button,
+    						 XfpmXF86Button type);
+    
+} XfpmButtonXf86Class;
+
+GType                 xfpm_button_xf86_get_type        (void) G_GNUC_CONST;
+XfpmButtonXf86       *xfpm_button_xf86_new             (void);
+
+G_END_DECLS
+
+#endif /* __XFPM_BUTTON_XF86_H */
diff --git a/src/xfpm-button.c b/src/xfpm-button.c
deleted file mode 100644
index 35d15243..00000000
--- a/src/xfpm-button.c
+++ /dev/null
@@ -1,658 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <xfconf/xfconf.h>
-
-#include "xfpm-button.h"
-#include "xfpm-hal.h"
-#include "xfpm-debug.h"
-#include "xfpm-common.h"
-#include "xfpm-notify.h"
-#include "xfpm-enums.h"
-#include "xfpm-enum-types.h"
-#include "xfpm-marshal.h"
-#include "xfpm-string.h"
-
-#define XFPM_BUTTON_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE(o,XFPM_TYPE_BUTTON,XfpmButtonPrivate))
-
-static void xfpm_button_init(XfpmButton *bt);
-static void xfpm_button_class_init(XfpmButtonClass *klass);
-static void xfpm_button_finalize(GObject *object);
-
-static void xfpm_button_set_property (GObject *object,
-                                           guint prop_id,
-                                           const GValue *value,
-                                           GParamSpec *pspec);
-static void xfpm_button_get_property (GObject *object,
-                                           guint prop_id,
-                                           GValue *value,
-                                           GParamSpec *pspec);
-
-static void xfpm_button_do_suspend(XfpmButton *bt);
-static void xfpm_button_do_hibernate(XfpmButton *bt);
-
-static void xfpm_button_lid_pressed(XfpmButton *bt,const gchar *udi);
-static void xfpm_button_power_pressed(XfpmButton *bt,const gchar *udi);
-static void xfpm_button_sleep_pressed(XfpmButton *bt,const gchar *udi);
-
-static void xfpm_button_handle_device_condition_cb(XfpmHal *hal,
-                                                   const gchar *udi,
-                                                   const gchar *condition_name,
-                                                   const gchar *condition_detail,
-                                                   XfpmButton *bt);
-
-static void xfpm_button_load_config(XfpmButton *bt);
-static void xfpm_button_get_switches(XfpmButton *bt);
-
-struct XfpmButtonPrivate
-{
-    XfpmHal *hal;
-    gulong handler_id;
-    
-    gboolean have_lid_bt;
-    gboolean lid_button_has_state;
-    
-    gboolean have_power_bt;
-    gboolean power_button_has_state;
-    
-    gboolean have_sleep_bt;
-    gboolean sleep_button_has_state;
-    
-    gboolean device_found;
-    
-    guint8 sleep_info;
-    
-};
-
-G_DEFINE_TYPE(XfpmButton,xfpm_button,G_TYPE_OBJECT)
-
-enum 
-{
-    XFPM_ACTION_REQUEST,
-    LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0,}; 
-
-enum
-{
-    PROP_0,
-    PROP_LID_ACTION,
-    PROP_SLEEP_ACTION,
-    PROP_POWER_ACTION
-};
-
-static void xfpm_button_class_init(XfpmButtonClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-    gobject_class->finalize = xfpm_button_finalize;
-    
-    gobject_class->set_property = xfpm_button_set_property;
-    gobject_class->get_property = xfpm_button_get_property;
-
-    signals[XFPM_ACTION_REQUEST] = g_signal_new("xfpm-action-request",
-                                               XFPM_TYPE_BUTTON,
-                                               G_SIGNAL_RUN_LAST,
-                                               G_STRUCT_OFFSET(XfpmButtonClass,button_action_request),
-                                               NULL,NULL,
-                                               _xfpm_marshal_VOID__ENUM_BOOLEAN ,
-                                               G_TYPE_NONE,2,
-                                               XFPM_TYPE_ACTION_REQUEST,G_TYPE_BOOLEAN);
-                                                   
-    g_object_class_install_property(gobject_class,
-                                    PROP_LID_ACTION,
-                                    g_param_spec_enum("lid-switch-action",
-                                                      "lid switch action",
-                                                      "lid switch action",
-                                                      XFPM_TYPE_ACTION_REQUEST,
-                                                      XFPM_DO_NOTHING,
-                                                      G_PARAM_READWRITE));    
-    
-    g_object_class_install_property(gobject_class,
-                                    PROP_SLEEP_ACTION,
-                                    g_param_spec_enum("sleep-switch-action",
-                                                      "sleep switch action",
-                                                      "sleep switch action",
-                                                      XFPM_TYPE_ACTION_REQUEST,
-                                                      XFPM_DO_NOTHING,
-                                                      G_PARAM_READWRITE));    
-    g_object_class_install_property(gobject_class,
-                                    PROP_POWER_ACTION,
-                                    g_param_spec_enum("power-switch-action",
-                                                      "power switch action",
-                                                      "power switch action",
-                                                      XFPM_TYPE_ACTION_REQUEST,
-                                                      XFPM_DO_NOTHING,
-                                                      G_PARAM_READWRITE));                                                      
-    
-    g_type_class_add_private(klass,sizeof(XfpmButtonPrivate));
-
-}
-
-static void xfpm_button_init(XfpmButton *bt)
-{
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    priv->have_lid_bt           = FALSE;
-    priv->lid_button_has_state  = FALSE;
-    
-    priv->have_power_bt         = FALSE;
-    priv->power_button_has_state= FALSE;
-    
-    priv->have_sleep_bt         = FALSE;
-    priv->sleep_button_has_state= FALSE;
-    
-    priv->sleep_info  = 0;
-        
-    priv->hal = xfpm_hal_new();
-    
-    xfpm_button_load_config(bt);
-    xfpm_button_get_switches(bt);
-    
-    if ( priv->have_lid_bt || priv->have_power_bt || priv->have_sleep_bt )
-    {
-        if (xfpm_hal_connect_to_signals(priv->hal,FALSE,FALSE,FALSE,TRUE) )
-        {
-            priv->handler_id =
-            g_signal_connect(priv->hal,"xfpm-device-condition",
-                            G_CALLBACK(xfpm_button_handle_device_condition_cb),bt);
-        }
-    }
-}
-
-static void xfpm_button_set_property (GObject *object,
-                                      guint prop_id,
-                                      const GValue *value,
-                                      GParamSpec *pspec)
-{
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif      
-    XfpmButton *bt;
-    bt = XFPM_BUTTON(object);
-    
-    switch (prop_id)
-    {
-    case PROP_LID_ACTION:
-        bt->lid_action = g_value_get_enum(value);
-        break;   
-    case PROP_SLEEP_ACTION:
-        bt->sleep_action = g_value_get_enum(value);
-        break;   
-     case PROP_POWER_ACTION:
-        bt->power_action = g_value_get_enum(value);
-        break;           
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }
-}
-                                           
-static void xfpm_button_get_property (GObject *object,
-                                      guint prop_id,
-                                      GValue *value,
-                                      GParamSpec *pspec)
-{
-    XfpmButton *bt;
-    bt = XFPM_BUTTON(object);
-        
-    switch (prop_id)
-    {
-    case  PROP_LID_ACTION:
-        g_value_set_enum(value,bt->lid_action);
-        break;   
-     case PROP_SLEEP_ACTION:
-        g_value_set_enum(value,bt->sleep_action);
-        break;   
-     case PROP_POWER_ACTION:
-        g_value_set_enum(value,bt->power_action);
-        break;       
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }                         
-    
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif  
-    
-}
-
-static void xfpm_button_finalize(GObject *object)
-{
-    XfpmButton *bt;
-    bt = XFPM_BUTTON(object);
-    
-    bt->priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    if ( bt->priv->hal ) 
-    {
-        g_object_unref(bt->priv->hal);
-    }
-    
-    G_OBJECT_CLASS(xfpm_button_parent_class)->finalize(object);
-}
-
-static gboolean
-_unblock_handler(XfpmButtonPrivate *priv)
-{
-    g_signal_handler_unblock(priv->hal,priv->handler_id);
-    return FALSE;
-}
-
-static void
-xfpm_button_do_hibernate(XfpmButton *bt)
-{
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    g_signal_handler_block(priv->hal,priv->handler_id);
-    
-    g_signal_emit(G_OBJECT(bt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_HIBERNATE,FALSE);
-    
-    g_timeout_add(10,(GSourceFunc)_unblock_handler,priv);
-    
-}
-
-static void
-xfpm_button_do_suspend(XfpmButton *bt)
-{
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    g_signal_handler_block(priv->hal,priv->handler_id);
-    
-    g_signal_emit(G_OBJECT(bt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_SUSPEND,FALSE);
-    
-    g_timeout_add(10,(GSourceFunc)_unblock_handler,priv);
-}
-
-static void
-_proccess_action(XfpmButton *bt,XfpmActionRequest action)
-{
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    if ( action == XFPM_DO_SUSPEND )
-    {
-        xfpm_button_do_suspend(bt);
-    }
-    else if ( action == XFPM_DO_HIBERNATE )
-    {
-        xfpm_button_do_hibernate(bt);
-    }
-    else if ( action == XFPM_DO_SHUTDOWN )
-    {
-        XfpmButtonPrivate *priv;
-        priv = XFPM_BUTTON_GET_PRIVATE(bt);
-        g_signal_handler_block(priv->hal,priv->handler_id);
-    
-        g_signal_emit(G_OBJECT(bt),signals[XFPM_ACTION_REQUEST],0,XFPM_DO_SHUTDOWN,FALSE);
-        
-        g_timeout_add(10,(GSourceFunc)_unblock_handler,priv);
-        
-    }
-        
-}
-
-static void
-xfpm_button_lid_pressed(XfpmButton *bt,const gchar *udi)
-{
-    if ( bt->lid_action == XFPM_DO_NOTHING )
-    {
-        return;
-    }
-    
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    if ( priv->have_lid_bt )
-    {
-        if ( priv->lid_button_has_state )
-        {
-            GError *error = NULL;
-            gboolean pressed = 
-            xfpm_hal_get_bool_info(priv->hal,udi,"button.state.value",&error);
-            if ( error ) 
-            {
-                XFPM_DEBUG("Error getting lid switch state: %s\n",error->message);
-                g_error_free(error);
-                return;
-            }
-            else if ( pressed == TRUE )
-            {
-                _proccess_action(bt,bt->lid_action);
-            }
-        }
-        else 
-        {
-            _proccess_action(bt,bt->lid_action);
-        }
-    }
-}
-
-static void
-xfpm_button_power_pressed(XfpmButton *bt,const gchar *udi)
-{
-    if ( bt->power_action == XFPM_DO_NOTHING )
-    {
-        XFPM_DEBUG("Power action is do nothing\n");
-        return;
-    }
-    
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    if ( priv->have_power_bt )
-    {
-        if ( priv->power_button_has_state )
-        {
-            GError *error = NULL;
-            gboolean pressed = 
-            xfpm_hal_get_bool_info(priv->hal,udi,"button.state.value",&error);
-            if ( error ) 
-            {
-                XFPM_DEBUG("Error getting lid switch state: %s\n",error->message);
-                g_error_free(error);
-                return;
-            }
-            else if ( pressed == TRUE )
-            {
-                _proccess_action(bt,bt->power_action);
-            }
-        }
-        else 
-        {
-            _proccess_action(bt,bt->power_action);
-        }
-    }
-}
-
-static void
-xfpm_button_sleep_pressed(XfpmButton *bt,const gchar *udi)
-{
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    if ( bt->sleep_action == XFPM_DO_NOTHING )
-    {
-        return;
-    }
-    
-    if ( priv->have_sleep_bt )
-    {
-        if ( priv->sleep_button_has_state )
-        {
-            GError *error = NULL;
-            gboolean pressed = 
-            xfpm_hal_get_bool_info(priv->hal,udi,"button.state.value",&error);
-            if ( error ) 
-            {
-                XFPM_DEBUG("Error getting lid switch state: %s\n",error->message);
-                g_error_free(error);
-                return;
-            }
-            else if ( pressed == TRUE )
-            {
-                _proccess_action(bt,bt->sleep_action);
-            }
-        }
-        else 
-        {
-            _proccess_action(bt,bt->sleep_action);
-        }
-    }
-}
-
-static void
-xfpm_button_handle_device_condition_cb(XfpmHal *hal,
-                                       const gchar *udi,
-                                       const gchar *condition_name,
-                                       const gchar *condition_detail,
-                                       XfpmButton *bt)
-{
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    if ( xfpm_hal_device_have_capability(priv->hal,udi,"button") )
-    {
-        if ( xfpm_strcmp(condition_name,"ButtonPressed") )
-        {
-            XFPM_DEBUG("Not processing event with condition_name=%s\n",condition_name);
-            return;
-        }
-        XFPM_DEBUG("proccessing event: %s %s\n",condition_name,condition_detail);
-        if ( !xfpm_strcmp(condition_detail,"lid") )
-        {
-            xfpm_button_lid_pressed(bt,udi);
-        }
-        else if ( !xfpm_strcmp(condition_detail,"power") )
-        {
-            xfpm_button_power_pressed(bt,udi);
-        }
-        else if ( !xfpm_strcmp(condition_detail,"sleep") )
-        {
-            xfpm_button_sleep_pressed(bt,udi);
-        }
-    }
-}                                       
-
-static void 
-xfpm_button_load_config(XfpmButton *bt)
-{
-    XFPM_DEBUG("Loading configuration\n");
-    
-    XfconfChannel *channel;
-    
-    channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-
-    bt->lid_action   = xfconf_channel_get_uint(channel,LID_SWITCH_CFG,XFPM_DO_NOTHING);
-    bt->sleep_action   = xfconf_channel_get_uint(channel,SLEEP_SWITCH_CFG,XFPM_DO_NOTHING);
-    bt->power_action = xfconf_channel_get_uint(channel,POWER_SWITCH_CFG,XFPM_DO_NOTHING);
-    
-    g_object_unref(channel);
-}
-
-static void
-_check_button(XfpmButtonPrivate *priv,const gchar *button_type,const gchar *udi)
-{
-    if ( !xfpm_strcmp(button_type,"lid"))
-    {
-        priv->have_lid_bt = TRUE;
-        priv->lid_button_has_state = xfpm_hal_get_bool_info(priv->hal,udi,
-                                                            "button.has_state",
-                                                            NULL);
-                                                            
-    }
-    else if ( !xfpm_strcmp(button_type,"power") )
-    {
-        priv->have_power_bt = TRUE;
-        priv->power_button_has_state = xfpm_hal_get_bool_info(priv->hal,udi,
-                                                            "button.has_state",
-                                                            NULL);
-    }
-    else if ( !xfpm_strcmp(button_type,"sleep"))
-    {
-        priv->have_sleep_bt = TRUE;
-        priv->sleep_button_has_state = xfpm_hal_get_bool_info(priv->hal,udi,
-                                                            "button.has_state",
-                                                            NULL);
-    }
-}
-
-static void
-xfpm_button_get_switches(XfpmButton *bt)
-{
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(bt);
-    
-    gchar **udi;
-    gint dummy;
-    GError *error = NULL;
-    
-    udi = xfpm_hal_get_device_udi_by_capability(priv->hal,"button",&dummy,&error);
-    
-    if ( error )
-    {
-        XFPM_DEBUG("Unable to get button switches: %s\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    
-    if ( !udi )
-    {
-        XFPM_DEBUG("No buttons found\n");
-    }
-    int i = 0 ;
-    for ( i = 0 ; udi[i] ; i++)
-    {
-        if ( xfpm_hal_device_have_key(priv->hal,udi[i],"button.type") && 
-            xfpm_hal_device_have_key(priv->hal,udi[i],"button.has_state") )
-        {
-            GError *error = NULL;
-            gchar *button_type = 
-            xfpm_hal_get_string_info(priv->hal,udi[i],"button.type",&error);
-            if ( error )
-            {
-                XFPM_DEBUG(":%s\n",error->message);
-                g_error_free(error);
-                continue;
-            }
-            if ( button_type)
-            {
-                _check_button(priv,button_type,udi[i]);
-                libhal_free_string(button_type);
-            }
-        }
-    }
-#ifdef DEBUG
-    gchar *content1;
-    gchar *content2;
-    
-    GValue value = { 0, };
-    g_value_init(&value,G_TYPE_BOOLEAN);
-    
-    g_value_set_boolean(&value,priv->have_lid_bt);
-    content1 = g_strdup_value_contents(&value);
-    
-    g_value_set_boolean(&value,priv->lid_button_has_state);    
-    content2 = g_strdup_value_contents(&value);
-    
-    XFPM_DEBUG("LID Switch found  = %s has_state = %s\n",content1,content2);
-    g_free(content1);
-    g_free(content2);
-    
-    g_value_set_boolean(&value,priv->have_power_bt);
-    content1 = g_strdup_value_contents(&value);
-    
-    g_value_set_boolean(&value,priv->power_button_has_state);    
-    content2 = g_strdup_value_contents(&value);
-    
-    XFPM_DEBUG("Power Switch found = %s has_state = %s\n",content1,content2);
-    g_free(content1);
-    g_free(content2);
-    
-    g_value_set_boolean(&value,priv->have_sleep_bt);
-    content1 = g_strdup_value_contents(&value);
-    
-    g_value_set_boolean(&value,priv->sleep_button_has_state);    
-    content2 = g_strdup_value_contents(&value);
-    
-    XFPM_DEBUG("Sleep Switch found = %s has_state = %s\n",content1,content2);
-    g_free(content1);
-    g_free(content2);
-#endif    
-    libhal_free_string_array(udi);
-}
-
-XfpmButton *
-xfpm_button_new(void)
-{
-    XfpmButton *bt;
-    bt = g_object_new(XFPM_TYPE_BUTTON,NULL);
-    return bt;
-}
-
-guint8
-xfpm_button_get_available_buttons(XfpmButton *button)
-{
-    g_return_val_if_fail(XFPM_IS_BUTTON(button),0);
-    
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(button);
-    
-    guint8 buttons = 0;
-    
-    if ( priv->have_lid_bt )
-    {
-        buttons |= LID_SWITCH;
-    }
-    if ( priv->have_power_bt )
-    {
-        buttons |= POWER_SWITCH;
-    }
-    if ( priv->have_sleep_bt )
-    {
-        buttons |= SLEEP_SWITCH;
-    }
-    
-    return buttons;
-}
-
-void            
-xfpm_button_set_sleep_info (XfpmButton *button,guint8 sleep_info)
-{
-    g_return_if_fail(XFPM_IS_BUTTON(button));
-    XfpmButtonPrivate *priv;
-    priv = XFPM_BUTTON_GET_PRIVATE(button);
-
-    priv->sleep_info = sleep_info;    
-}
diff --git a/src/xfpm-button.h b/src/xfpm-button.h
deleted file mode 100644
index ead3122d..00000000
--- a/src/xfpm-button.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __XFPM_BUTTON_H
-#define __XFPM_BUTTON_H
-
-#include <glib-object.h>
-
-#include "xfpm-enums.h"
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_BUTTON  (xfpm_button_get_type())
-#define XFPM_BUTTON(o)    (G_TYPE_CHECK_INSTANCE_CAST(o,XFPM_TYPE_BUTTON,XfpmButton)) 
-#define XFPM_IS_BUTTON(o) (G_TYPE_CHECK_INSTANCE_TYPE(o,XFPM_TYPE_BUTTON))
-
-typedef struct XfpmButtonPrivate XfpmButtonPrivate;
-
-typedef struct
-{
-    GObject parent;
-    XfpmButtonPrivate *priv;
-    
-    XfpmActionRequest lid_action;
-    XfpmActionRequest power_action;
-    XfpmActionRequest sleep_action;
-    
-} XfpmButton;
-
-
-typedef struct
-{
-    GObjectClass parent_class;
-    
-    void  (*button_action_request) (XfpmButton *bt,
-                                    XfpmActionRequest action,
-                                    gboolean critical);
-    
-} XfpmButtonClass;
-
-GType           xfpm_button_get_type              (void) G_GNUC_CONST;
-XfpmButton     *xfpm_button_new                   (void);
-guint8          xfpm_button_get_available_buttons (XfpmButton *button);
-void            xfpm_button_set_sleep_info        (XfpmButton *button,
-                                                    guint8 sleep_info);
-G_END_DECLS
-
-#endif
diff --git a/src/xfpm-common.c b/src/xfpm-common.c
deleted file mode 100644
index e2071df2..00000000
--- a/src/xfpm-common.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#include <glib.h>
-#include <libxfcegui4/libxfcegui4.h>
-#include <libxfce4util/libxfce4util.h>
-
-#include "xfpm-common.h"
-#include "xfpm-debug.h"
-
-static void
-xfpm_link_browser(GtkAboutDialog *about,const gchar *link,gpointer data)
-{
-	gchar *cmd = g_strdup_printf("%s %s","xfbrowser4",link);
-	xfce_exec(cmd,FALSE,FALSE,NULL);
-	g_free(cmd);
-	
-}
-
-static void
-xfpm_link_mailto(GtkAboutDialog *about,const gchar *link,gpointer data)
-{
-	gchar *cmd = g_strdup_printf("%s %s","xdg-email",link);
-	xfce_exec(cmd,FALSE,FALSE,NULL);
-	g_free(cmd);
-}
-	
-
-GdkPixbuf *
-xfpm_load_icon(const char *icon_name,gint size)
-{
-    GdkPixbuf *icon;
-    GError *error = NULL;
-    
-    icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default (),
-                                   icon_name,
-                                   size,
-                                   GTK_ICON_LOOKUP_FORCE_SVG,
-                                   &error);
-    if ( error )
-    {
-        XFPM_DEBUG("Error occured while loading icon %s: %s\n",icon_name,error->message);
-        g_error_free(error);
-    }
-    return icon;                               
-}
-
-void       
-xfpm_lock_screen(void)
-{
-    gboolean ret = g_spawn_command_line_async("xflock4",NULL);
-    
-    if ( !ret )
-    {
-        g_spawn_command_line_async("gnome-screensaver-command -l",NULL);
-    }
-    
-    if ( !ret )
-    {
-        /* this should be the default*/
-        ret = g_spawn_command_line_async("xdg-screensaver lock",NULL);
-    }
-    
-    if ( !ret )
-    {
-        ret = g_spawn_command_line_async("xscreensaver-command -lock",NULL);
-    }
-    
-    if ( !ret )
-    {
-        g_critical("Connot lock screen\n");
-    }
-}
-
-void       
-xfpm_preferences(void) 
-{
-    g_spawn_command_line_async("xfce4-power-manager-settings",NULL);
-}
-
-void       
-xfpm_help(void)
-{
-	xfce_exec("xfhelp4 xfce4-power-manager.html", FALSE, FALSE, NULL);
-}
-
-void       
-xfpm_about(GtkWidget *widget,gpointer data)
-{
-	const gchar* authors[3] = 
-	{
-		"Ali Abdallah <aliov@xfce.org>", 
-		NULL
-	};
-								
-	static const gchar *documenters[] =
-	{
-		"Ali Abdallah <aliov@xfce.org>",
-		NULL,
-	};
-
-	gtk_about_dialog_set_url_hook (xfpm_link_browser, NULL, NULL);
-	gtk_about_dialog_set_email_hook(xfpm_link_mailto,NULL,NULL);
-	gtk_show_about_dialog (NULL,
-                         "authors", authors,
-                         "copyright", "Copyright \302\251 2008 Ali Abdallah",
-                         "destroy-with-parent", TRUE,
-                         "documenters", documenters,
-                         "license", XFCE_LICENSE_GPL,
-                         "name", _("Xfce4 Power Manager"),
-                         "translator-credits", _("translator-credits"),
-                         "version", PACKAGE_VERSION,
-                         "website", "http://goodies.xfce.org",
-                         NULL);
-						 
-}
diff --git a/src/xfpm-common.h b/src/xfpm-config.h
similarity index 54%
rename from src/xfpm-common.h
rename to src/xfpm-config.h
index 583dce35..2ff9a535 100644
--- a/src/xfpm-common.h
+++ b/src/xfpm-config.h
@@ -19,77 +19,46 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#ifndef __XFPM_COMMON_H
-#define __XFPM_COMMON_H
+#ifndef __XFPM_CONFIG_H
+#define __XFPM_CONFIG_H
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-#include <gtk/gtk.h>
-
-#define BORDER 8
+G_BEGIN_DECLS
 
 /* Configuration */
 #define XFPM_CHANNEL_CFG            "xfce4-power-manager"
-#define CRITICAL_BATT_CFG           "/xfce4-power-manager/critical-battery-charge"     /* default 10%  */
 #define CRITICAL_BATT_ACTION_CFG    "/xfce4-power-manager/critical-battery-action"     /* default 0 nothing, 1 = shutdown, 2 = hibernate if supported) */
 
-#define CPU_FREQ_SCALING_CFG        "/xfce4-power-manager/cpu-scaling-gov"
-#define ON_AC_CPU_GOV_CFG           "/xfce4-power-manager/on-ac-cpu-gov"
-#define ON_BATT_CPU_GOV_CFG         "/xfce4-power-manager/on-batt-cpu-gov"
+#define POWER_SAVE_ON_BATTERY       "/xfce4-power-manager/power-save-on-battery"
 
-#define POWER_SAVE_CFG              "/xfce4-power-manager/power-save"
-#define CAN_POWER_SAVE              "/xfce4-power-manager/can-power-save"
 #define LCD_BRIGHTNESS_CFG          "/xfce4-power-manager/lcd-brightness"
-#define LID_SWITCH_CFG              "/xfce4-power-manager/lid-switch-action"
+#define LID_SWITCH_ON_AC_CFG        "/xfce4-power-manager/lid-action-on-ac"
+#define LID_SWITCH_ON_BATTERY_CFG   "/xfce4-power-manager/lid-action-on-battery"
 #define SLEEP_SWITCH_CFG            "/xfce4-power-manager/sleep-switch-action"
 #define POWER_SWITCH_CFG            "/xfce4-power-manager/power-switch-action"
 
+#define GENERAL_NOTIFICATION_CFG    "/xfce4-power-manager/general-notification"
+
 #ifdef HAVE_LIBNOTIFY
 #define BATT_STATE_NOTIFICATION_CFG "/xfce4-power-manager/battery-state-notification"  /* default TRUE */
-#define GENERAL_NOTIFICATION_CFG    "/xfce4-power-manager/general-notification"        /* default TRUE not yet used */
+
 #define SHOW_SLEEP_ERRORS_CFG       "/xfce4-power-manager/show-sleep-errors"
 #define SHOW_POWER_MANAGEMENT_ERROR "/xfce4-power-manager/show-power-management-error"
 #endif
+
 #define SHOW_TRAY_ICON_CFG          "/xfce4-power-manager/show-tray-icon"              /* default 0 = always,1 = when charging or discharging, 2 = when battery is present */
 
 #ifdef HAVE_DPMS
-#define DPMS_ENABLE_CFG             "/xfce4-power-manager/dpms-enabled" 
-#define ON_BATT_DPMS_TIMEOUTS_CFG   "/xfce4-power-manager/on-battery-monitor-dpms-timeouts"
-#define ON_AC_DPMS_TIMEOUTS_CFG     "/xfce4-power-manager/on-ac-monitor-dpms-timeouts"
+#define DPMS_ENABLED_CFG             "/xfce4-power-manager/dpms-enabled" 
+#define ON_BATT_DPMS_SLEEP 	     "/xfce4-power-manager/on-battery-dpms-sleep"
+#define ON_BATT_DPMS_OFF	     "/xfce4-power-manager/on-battery-dpms-off"
+#define ON_AC_DPMS_SLEEP 	     "/xfce4-power-manager/on-ac-dpms-sleep"
+#define ON_AC_DPMS_OFF	     	     "/xfce4-power-manager/on-ac-dpms-off"
 #endif
 
-typedef enum
-{
-    SYSTEM_CAN_SHUTDOWN          =  (1<<0),
-    SYSTEM_CAN_HIBERNATE         =  (1<<2),
-    SYSTEM_CAN_SUSPEND           =  (1<<3),
-    SYSTEM_CAN_POWER_SAVE        =  (1<<4)
-    
-} SystemPowerManagement;
-
-typedef enum 
-{
-    SYSTEM_LAPTOP,
-    SYSTEM_DESKTOP,
-    SYSTEM_SERVER,
-    SYSTEM_UNKNOWN
-    
-} SystemFormFactor;
-
-typedef enum
-{
-    LID_SWITCH   = (1<<0),
-    SLEEP_SWITCH = (1<<1),
-    POWER_SWITCH = (1<<2)
-    
-} XfpmSwitchButton;
-
-GdkPixbuf* xfpm_load_icon(const gchar *icon_name,gint size);
-void       xfpm_lock_screen(void);
-void       xfpm_preferences(void);
-void       xfpm_help(void);
-void       xfpm_about(GtkWidget *widget,gpointer data);
+G_END_DECLS
 
-#endif /* XFPM_COMMON_H */
+#endif /* __XFPM_CONFIG_H */
diff --git a/src/xfpm-cpu.c b/src/xfpm-cpu.c
index 285d2a72..25ae9f93 100644
--- a/src/xfpm-cpu.c
+++ b/src/xfpm-cpu.c
@@ -1,6 +1,5 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -16,7 +15,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifdef HAVE_CONFIG_H
@@ -37,408 +36,204 @@
 #include <errno.h>
 #endif
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
+#include <libxfce4util/libxfce4util.h>
 
-#include <xfconf/xfconf.h>
+#include <hal/libhal.h>
+
+#include "libxfpm/dbus-hal.h"
+#include "libxfpm/xfpm-string.h"
 
 #include "xfpm-cpu.h"
-#include "xfpm-hal.h"
-#include "xfpm-debug.h"
-#include "xfpm-common.h"
-#include "xfpm-enum-types.h"
-#include "xfpm-string.h"
-
-#define XFPM_CPU_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE(o,XFPM_TYPE_CPU,XfpmCpuPrivate))
-
-static void xfpm_cpu_init(XfpmCpu *cpu);
-static void xfpm_cpu_class_init(XfpmCpuClass *klass);
-static void xfpm_cpu_finalize(GObject *object);
-
-
-static void xfpm_cpu_set_property (GObject *object,
-                                   guint prop_id,
-                                   const GValue *value,
-                                   GParamSpec *pspec);
-static void xfpm_cpu_get_property (GObject *object,
-                                   guint prop_id,
-                                   GValue *value,
-                                   GParamSpec *pspec);
-
-static void xfpm_cpu_load_config(XfpmCpu *cpu);
-static void xfpm_cpu_check(XfpmCpu *cpu);
-static guint8 xfpm_cpu_get_all_governors(XfpmCpu *cpu);
-static void xfpm_cpu_get_governors(XfpmCpu *cpu);
-static void xfpm_cpu_set_governor(XfpmCpu *cpu,
-                                  gboolean ac_adapter_present);
-
-static void xfpm_cpu_notify_cb (GObject *object,
-                                GParamSpec *arg1,
-                                gpointer data);
-                                
-G_DEFINE_TYPE(XfpmCpu,xfpm_cpu,G_TYPE_OBJECT)
+#include "xfpm-config.h"
+#include "xfpm-enum.h"
+
+/* Init */
+static void xfpm_cpu_class_init (XfpmCpuClass *klass);
+static void xfpm_cpu_init       (XfpmCpu *cpu);
+static void xfpm_cpu_finalize   (GObject *object);
+
+#define XFPM_CPU_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_CPU, XfpmCpuPrivate))
 
 struct XfpmCpuPrivate
 {
-    XfpmHal *hal;
-	guint8 governors;
+    XfconfChannel *channel;
+    DbusHal       *hbus;
+    
+    gboolean 	   on_battery;
+    gboolean 	   power_save;
+    
+    gboolean       interface_ok;
+    guint8         cpu_governors;
 };
 
-enum
-{
-    PROP_0,
-    PROP_AC_ADAPTER,
-    PROP_CPU_FREQ,
-    PROP_ON_AC_CPU_GOV,
-    PROP_ON_BATT_CPU_GOV
-};
+G_DEFINE_TYPE(XfpmCpu, xfpm_cpu, G_TYPE_OBJECT)
 
 static void
 xfpm_cpu_class_init(XfpmCpuClass *klass)
 {
-    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-    
-    gobject_class->set_property = xfpm_cpu_set_property;
-    gobject_class->get_property = xfpm_cpu_get_property;
-    
-    gobject_class->finalize = xfpm_cpu_finalize;
-    
-    g_object_class_install_property(gobject_class,
-                                    PROP_AC_ADAPTER,
-                                    g_param_spec_boolean("on-ac-adapter",
-                                                         "On ac adapter",
-                                                         "On Ac power",
-                                                         TRUE,
-                                                         G_PARAM_READWRITE));
-                                                         
-    g_object_class_install_property(gobject_class,
-                                    PROP_CPU_FREQ,
-                                    g_param_spec_boolean("cpu-freq",
-                                                         "cpu freq",
-                                                         "cpu freq settings",
-                                                         TRUE,
-                                                         G_PARAM_READWRITE));
-    
-    
-    g_object_class_install_property(gobject_class,
-                                    PROP_ON_AC_CPU_GOV,
-                                    g_param_spec_flags("on-ac-cpu-gov",
-                                                      "On ac cpu gov",
-                                                      "Cpu governor on AC power",
-                                                      XFPM_TYPE_CPU_GOVERNOR,
-                                                      ONDEMAND,
-                                                      G_PARAM_READWRITE));
-    g_object_class_install_property(gobject_class,
-                                    PROP_ON_BATT_CPU_GOV,
-                                    g_param_spec_flags("on-batt-cpu-gov",
-                                                      "On battery cpu gov",
-                                                      "Cpu governor on battery power",
-                                                      XFPM_TYPE_CPU_GOVERNOR,
-                                                      POWERSAVE,
-                                                      G_PARAM_READWRITE));
+    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)
 {
-    XfpmCpuPrivate *priv;
-    priv = XFPM_CPU_GET_PRIVATE(cpu);
-    
-    priv->hal = xfpm_hal_new();
-	priv->governors = 0;
-    
-    xfpm_cpu_load_config(cpu);
-	
-	xfpm_cpu_check(cpu);
-	xfpm_cpu_get_governors(cpu);
-    
-    g_signal_connect(G_OBJECT(cpu),"notify",G_CALLBACK(xfpm_cpu_notify_cb),NULL);
-    
+    cpu->priv = XFPM_CPU_GET_PRIVATE(cpu);
+    cpu->priv->cpu_governors = 0;
 }
 
-static void xfpm_cpu_set_property(GObject *object,
-                                  guint prop_id,
-                                  const GValue *value,
-                                  GParamSpec *pspec)
-{
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif      
-    XfpmCpu *cpu;
-    cpu = XFPM_CPU(object);
-    
-    switch (prop_id)
-    {
-    case PROP_AC_ADAPTER:
-        cpu->ac_adapter_present = g_value_get_boolean(value);
-        break;   
-    case PROP_CPU_FREQ:
-        cpu->cpu_freq_enabled = g_value_get_boolean(value);
-        break;    
-    case PROP_ON_AC_CPU_GOV:
-        cpu->on_ac_cpu_gov = g_value_get_flags(value);
-        break;
-    case PROP_ON_BATT_CPU_GOV:
-        cpu->on_batt_cpu_gov = g_value_get_flags(value);
-        break;    
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }
-}    
-                               
-static void xfpm_cpu_get_property(GObject *object,
-                                   guint prop_id,
-                                   GValue *value,
-                                   GParamSpec *pspec)
+static void
+xfpm_cpu_finalize(GObject *object)
 {
     XfpmCpu *cpu;
+
     cpu = XFPM_CPU(object);
-        
-    switch (prop_id)
-    {
-    case PROP_AC_ADAPTER:
-        g_value_set_boolean(value,cpu->ac_adapter_present);
-        break;   
-    case PROP_CPU_FREQ:
-        g_value_set_boolean(value,cpu->cpu_freq_enabled);
-        break;
-    case PROP_ON_AC_CPU_GOV:
-        g_value_set_flags(value,cpu->on_ac_cpu_gov);
-        break;
-    case PROP_ON_BATT_CPU_GOV:
-        g_value_set_flags(value,cpu->on_batt_cpu_gov);
-        break;            
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }                         
-    
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif  
-}
 
-static void
-xfpm_cpu_finalize(GObject *object)
-{
-    XfpmCpu *cpu = XFPM_CPU(object);
-    cpu->priv = XFPM_CPU_GET_PRIVATE(cpu);
-    
-    if ( cpu->priv->hal )
-    {
-        g_object_unref(cpu->priv->hal);
-    }
-    
     G_OBJECT_CLASS(xfpm_cpu_parent_class)->finalize(object);
 }
 
 static void
-xfpm_cpu_load_config(XfpmCpu *cpu)
+xfpm_cpu_set_governor (XfpmCpu *cpu, const gchar *governor)
 {
-    XFPM_DEBUG("loading configuration\n");
-    XfconfChannel *channel;
     
-    channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
+    if (!dbus_hal_set_cpu_governor (cpu->priv->hbus, governor, NULL))
+    	g_critical ("Unable to set CPU governor to %s\n", governor);
     
-    cpu->on_ac_cpu_gov = xfconf_channel_get_uint(channel,ON_AC_CPU_GOV_CFG,ONDEMAND);
-    cpu->on_batt_cpu_gov = xfconf_channel_get_uint(channel,ON_BATT_CPU_GOV_CFG,POWERSAVE);
-    cpu->cpu_freq_enabled = xfconf_channel_get_bool(channel,CPU_FREQ_SCALING_CFG,TRUE);
-    
-    g_object_unref(channel);
 }
 
-
-static
-gchar *_get_governor_from_enum(XfpmCpuGovernor governor)
+static XfpmCpuGovernor 
+_governor_name_to_enum (const gchar *governor)
 {
-    if ( governor == POWERSAVE )
-    {
-        return "powersave";
-    }
-    else if ( governor == ONDEMAND )
-    {
-        return "ondemand";
-    }
-    else if ( governor == PERFORMANCE )
-    {
-        return "performance";
-    }
-    else if ( governor == CONSERVATIVE )
-    {
-        return "conservative";
-    }
-    return NULL;
+    if ( xfpm_strequal(governor, "ondemand") )
+    	return CPU_ONDEMAND;
+    else if ( xfpm_strequal(governor, "powersave") )
+    	return CPU_POWERSAVE;
+    else if ( xfpm_strequal (governor, "performance") )
+    	return CPU_PERFORMANCE;
+    
+    return CPU_UNKNOWN;
 }
 
-static void xfpm_cpu_check(XfpmCpu *cpu)
+static void
+xfpm_cpu_update_governor (XfpmCpu *cpu)
 {
-	XfpmCpuPrivate *priv;
-	priv = XFPM_CPU_GET_PRIVATE(cpu);
+    if ( !cpu->priv->interface_ok )
+    	return;
 	
-	if (!xfpm_hal_cpu_freq_interface_can_be_used(priv->hal))
-    {	
-		priv->governors |= CPU_FREQ_CANNOT_BE_USED;
-	    XFPM_DEBUG("Cpu freq control cannot be used\n");	
+    gchar *current_governor = dbus_hal_get_cpu_current_governor (cpu->priv->hbus, NULL);
+    
+    if ( !current_governor )
+    	return;
+
+    XfpmCpuGovernor current = _governor_name_to_enum (current_governor);
+
+    if ( !cpu->priv->power_save || ( !cpu->priv->on_battery && cpu->priv->power_save) )
+    {
+	if ( cpu->priv->cpu_governors & CPU_ONDEMAND )
+	    xfpm_cpu_set_governor (cpu, "ondemand");
+	else if ( cpu->priv->cpu_governors & CPU_PERFORMANCE )
+	    xfpm_cpu_set_governor (cpu, "performance");
+	else
+	    g_critical ("No conveniant cpu governor found\n");
+	return;
     }
-}
 
-static guint8
-xfpm_cpu_get_all_governors(XfpmCpu *cpu)
-{
-	XfpmCpuPrivate *priv;
-	priv = XFPM_CPU_GET_PRIVATE(cpu);
-		
-	GError *g_error = NULL;
-	gchar **govs = NULL;
-    guint8 governors = 0;
-	    
-	govs = xfpm_hal_get_available_cpu_governors(priv->hal,&g_error);
-	
-	if ( g_error )
+    if ( cpu->priv->on_battery && cpu->priv->power_save )
+    {
+    	if ( current != CPU_POWERSAVE )
 	{
-		XFPM_DEBUG("%s :\n",g_error->message);
-		g_error_free(g_error);
-		return 0;
+	    TRACE ("Settings cpu governor to powersave");
+	    xfpm_cpu_set_governor (cpu, "powersave");
 	}
+	return;
+    }
 
-	int i = 0;    
-	if ( govs ) 
-	{
-		for ( i = 0 ; govs[i] ; i++ )
-		{
-			if ( !xfpm_strcmp(govs[i],"powersave") )    governors |= POWERSAVE;
-			if ( !xfpm_strcmp(govs[i],"ondemand") )     governors |= ONDEMAND;
-			if ( !xfpm_strcmp(govs[i],"performance") )  governors |= PERFORMANCE;
-			if ( !xfpm_strcmp(govs[i],"conservative") ) governors |= CONSERVATIVE;
-		}   
-		libhal_free_string_array(govs);
-	}	
-	
-	return governors;
-	
+    libhal_free_string (current_governor);
 }
 
-static void xfpm_cpu_get_governors(XfpmCpu *cpu)
+static void
+xfpm_cpu_load_configuration (XfpmCpu *cpu)
 {
-	XfpmCpuPrivate *priv;
-	priv = XFPM_CPU_GET_PRIVATE(cpu);
-	
-	if ( priv->governors & CPU_FREQ_CANNOT_BE_USED )
-	{
-		return;
-	}
-	
-	priv->governors = xfpm_cpu_get_all_governors(cpu);
+    cpu->priv->power_save =
+    	xfconf_channel_get_bool (cpu->priv->channel, POWER_SAVE_ON_BATTERY, TRUE);
 }
 
 static void
-xfpm_cpu_set_governor(XfpmCpu *cpu,gboolean ac_adapter_present)
+xfpm_cpu_property_changed_cb (XfconfChannel *channel, gchar *property, GValue *value, XfpmCpu *cpu)
 {
-    XfpmCpuPrivate *priv;
-    priv = XFPM_CPU_GET_PRIVATE(cpu);
-
-    gchar *current_governor;
-    GError *error = NULL;
-    current_governor = xfpm_hal_get_current_cpu_governor(priv->hal,&error);
-    
-    if ( error )
-    {
-        XFPM_DEBUG("%s:\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    if ( !current_governor ) return;
-    
-    gchar *config_gov = 
-           _get_governor_from_enum(ac_adapter_present ? cpu->on_ac_cpu_gov : cpu->on_batt_cpu_gov);
-
-    if ( !config_gov )
-    {
-        XFPM_DEBUG("Unknown cpu governor\n");
+    if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
         return;
-    }
-        
-    XFPM_DEBUG("Configuration governor %s\n",config_gov);
-    
-    if ( xfpm_strcmp(current_governor,config_gov) ) 
-    {
-        XFPM_DEBUG("CPU actuel governor %s, setting=%s\n",current_governor,config_gov);
-        xfpm_hal_set_cpu_governor(priv->hal,config_gov,&error);
-        if ( error )
-        {
-            XFPM_DEBUG("%s:\n",error->message);
-            g_error_free(error);
-            return;
-        }
-    }    
-    else
+	
+    if ( xfpm_strequal(property, POWER_SAVE_ON_BATTERY) )
     {
-        XFPM_DEBUG("No Need to change CPU Governor\n");
+	gboolean val = g_value_get_boolean (value);
+	cpu->priv->power_save = val;
+	xfpm_cpu_update_governor(cpu);
     }
 }
 
-static void 
-xfpm_cpu_notify_cb (GObject *object,
-                    GParamSpec *arg1,
-                    gpointer data)
-{                                
-    XfpmCpu *cpu = XFPM_CPU(object);
-	XfpmCpuPrivate *priv;
-	priv = XFPM_CPU_GET_PRIVATE(cpu);
+static gboolean
+xfpm_cpu_get_available_governors (XfpmCpu *cpu)
+{
+    gchar **governors =
+    	dbus_hal_get_cpu_available_governors (cpu->priv->hbus, NULL);
 	
-	if ( priv->governors & CPU_FREQ_CANNOT_BE_USED )
-	{
-		XFPM_DEBUG("Xfpm cannot use cpu freq control\n");
-		return;
-	}
-    
-    if ( !cpu->cpu_freq_enabled )
+    if ( !governors )
     {
-        XFPM_DEBUG("Cpu freq control is disabled\n");
-		return;
+    	g_critical ("Unable to get CPU governors\n");
+	return FALSE;
     }
     
-    if ( !xfpm_strcmp(arg1->name,"on-ac-adapter") ||
-         !xfpm_strcmp(arg1->name,"on-ac-cpu-gov") ||
-         !xfpm_strcmp(arg1->name,"on-batt-cpu-gov") )
+    int i =0 ;
+    for ( i = 0; governors[i]; i++)
     {
-        xfpm_cpu_set_governor(cpu,cpu->ac_adapter_present);
+    	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;
     }
+
+    libhal_free_string_array (governors);
+    
+    return TRUE;
+    
 }
 
 XfpmCpu *
-xfpm_cpu_new(void)
+xfpm_cpu_new (XfconfChannel *channel, DbusHal *hbus)
 {
     XfpmCpu *cpu = NULL;
-    cpu = g_object_new(XFPM_TYPE_CPU,NULL);
+    cpu = g_object_new (XFPM_TYPE_CPU, NULL);
+    
+    cpu->priv->hbus = hbus;
+    
+    if ( !xfpm_cpu_get_available_governors (cpu))
+    	goto out;
+    
+    cpu->priv->interface_ok = TRUE;
+    cpu->priv->channel = channel;
+    xfpm_cpu_load_configuration (cpu);
+    
+    g_signal_connect (cpu->priv->channel, "property-changed",
+		      G_CALLBACK(xfpm_cpu_property_changed_cb), cpu);
+		      
+out:
     return cpu;
 }
 
-guint8
-xfpm_cpu_get_available_governors(XfpmCpu *cpu)
+void xfpm_cpu_set_on_battery (XfpmCpu *cpu, gboolean on_battery)
 {
-	g_return_val_if_fail(XFPM_IS_CPU(cpu),0);
-	
-	XfpmCpuPrivate *priv;
-	priv = XFPM_CPU_GET_PRIVATE(cpu);
-
-	if ( priv->governors & CPU_FREQ_CANNOT_BE_USED )
-	{
-		return 0;
-	}
-	
-	guint8 govs = xfpm_cpu_get_all_governors(cpu);
-	
-	if ( govs != priv->governors ) priv->governors = govs;
-	
-	return govs;
+    g_return_if_fail (XFPM_IS_CPU(cpu));
+    
+    cpu->priv->on_battery = on_battery;
+    
+    xfpm_cpu_update_governor (cpu);
 }
diff --git a/src/xfpm-cpu.h b/src/xfpm-cpu.h
index a807d6de..fe780ec4 100644
--- a/src/xfpm-cpu.h
+++ b/src/xfpm-cpu.h
@@ -1,6 +1,5 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -16,7 +15,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifndef __XFPM_CPU_H
@@ -24,39 +23,38 @@
 
 #include <glib-object.h>
 
-#include "xfpm-enums.h"
+#include <xfconf/xfconf.h>
+
+#include "libxfpm/dbus-hal.h"
 
 G_BEGIN_DECLS
 
-#define XFPM_TYPE_CPU    (xfpm_cpu_get_type())
-#define XFPM_CPU(o)      (G_TYPE_CHECK_INSTANCE_CAST(o,XFPM_TYPE_CPU,XfpmCpu))
-#define XFPM_IS_CPU(o)   (G_TYPE_CHECK_INSTANCE_TYPE(o,XFPM_TYPE_CPU))
+#define XFPM_TYPE_CPU        (xfpm_cpu_get_type () )
+#define XFPM_CPU(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_CPU, XfpmCpu))
+#define XFPM_IS_CPU(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_CPU))
 
 typedef struct XfpmCpuPrivate XfpmCpuPrivate;
 
 typedef struct
 {
-    GObject parent;
-    XfpmCpuPrivate *priv;
-    
-    gboolean ac_adapter_present;
-    gboolean cpu_freq_enabled;
-    
-    XfpmCpuGovernor    on_ac_cpu_gov;
-    XfpmCpuGovernor    on_batt_cpu_gov;
+    GObject		 parent;
+    XfpmCpuPrivate	 *priv;
     
 } XfpmCpu;
 
 typedef struct
 {
     GObjectClass parent_class;
-
+    
 } XfpmCpuClass;
 
-GType          xfpm_cpu_get_type				(void) G_GNUC_CONST;
-XfpmCpu       *xfpm_cpu_new     				(void);
-guint8         xfpm_cpu_get_available_governors (XfpmCpu *cpu);
+GType          xfpm_cpu_get_type        (void) G_GNUC_CONST;
+XfpmCpu       *xfpm_cpu_new             (XfconfChannel *channel,
+					 DbusHal *bus);
+
+void           xfpm_cpu_set_on_battery  (XfpmCpu *cpu,
+					 gboolean on_battery);
 
 G_END_DECLS
 
-#endif
+#endif /* __XFPM_CPU_H */
diff --git a/src/xfpm-dbus-messages.c b/src/xfpm-dbus-messages.c
deleted file mode 100644
index 270026ad..00000000
--- a/src/xfpm-dbus-messages.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <libxfce4util/libxfce4util.h>
-
-#include "xfpm-dbus-messages.h"
-#include "xfpm-debug.h"
-
-
-gboolean
-xfpm_dbus_name_has_owner(DBusConnection *connection,const gchar *service)
-{
-    DBusError error;
-    dbus_error_init(&error);
-    
-    gboolean ret = dbus_bus_name_has_owner(connection,service,&error);
-    
-    if ( dbus_error_is_set(&error) )
-    {
-        XFPM_DEBUG("Failed to get name owner: %s\n",error.message);
-        dbus_error_free(&error);
-        return FALSE;
-    }
-    
-    if ( ret == FALSE )
-    {
-        XFPM_DEBUG("%s is not running \n",service);
-    }
-    
-    return ret;
-}
-
-static
-DBusConnection *xfpm_dbus_get_connection(DBusBusType type) 
-{
-    DBusError error;
-    DBusConnection *connection;
-
-    dbus_error_init(&error);
-    
-    connection = dbus_bus_get(type,&error);
-    
-    if ( !connection ) 
-    {
-        XFPM_DEBUG("Dbus connection error: %s\n",error.message);
-        dbus_error_free(&error);
-        return NULL; 
-    }
-    else 
-    {
-        return connection;
-    }               
-}    
-
-void
-xfpm_dbus_send_nm_message   (const gchar *signal)
-{
-    DBusConnection *connection;
-    DBusMessage *message;
-    
-    connection = xfpm_dbus_get_connection(DBUS_BUS_SYSTEM);
-    if ( !connection )
-    {
-        return;
-    }
-    
-    if ( !xfpm_dbus_name_has_owner(connection,NM_SERVICE) )
-    {
-        dbus_connection_unref(connection);
-        return;
-    }
-    
-    message = dbus_message_new_method_call(NM_SERVICE,NM_PATH,NM_INTERFACE,signal);
-    
-    if (!message)
-    {
-        return;
-    }
-        
-    gboolean ret =
-    dbus_connection_send(connection,
-                         message,
-                         NULL);
-        
-    dbus_message_unref(message);
-    dbus_connection_unref(connection);
-    if ( ret == FALSE )
-    {
-        XFPM_DEBUG("Failed to send message \n");
-        return;
-    } else
-    {
-        return;
-    }         
-}
-
-gboolean xfpm_dbus_register_name(DBusConnection *connection, const gchar *name)
-{
-    DBusError error;
-    
-    dbus_error_init(&error);
-    
-    int ret =
-	dbus_bus_request_name(connection, name , 0, &error);
-	
-	if ( dbus_error_is_set(&error) )
-	{
-		printf("Error: %s\n",error.message);
-		dbus_error_free(&error);
-		return FALSE;
-	}
-	
-	if ( ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
-	{
-		return TRUE;
-	}
-	
-	return FALSE;
-}
-
-gboolean xfpm_dbus_release_name(DBusConnection *connection, const gchar *name)
-{
-    DBusError error;
-    
-    dbus_error_init(&error);
-    
-    int ret =
-    dbus_bus_release_name(connection, name, &error);
-    
-    if ( dbus_error_is_set(&error) )
-    {
-        printf("Error: %s\n",error.message);
-        dbus_error_free(&error);
-        return FALSE;
-    }
-    
-    if ( ret == -1 ) return FALSE;
-    
-    return TRUE;
-}
diff --git a/src/xfpm-debug.h b/src/xfpm-debug.h
deleted file mode 100644
index 43dbf638..00000000
--- a/src/xfpm-debug.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef __XFPM_DEBUG_H
-#define __XFPM_DEBUG_H
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#include <glib.h>
-
-#ifdef DEBUG 
-
-#define XFPM_DEBUG(...)              G_STMT_START{                          \
-    fprintf(stderr, "TRACE[%s:%d] %s(): ",__FILE__,__LINE__,__func__);      \
-    fprintf(stderr, __VA_ARGS__);                                           \
-}G_STMT_END
-
-#else
-
-#define XFPM_DEBUG(...)
-
-#endif
-
-#endif  /*__XFPM_DEBUG_H */
diff --git a/src/xfpm-dpms-spins.c b/src/xfpm-dpms-spins.c
deleted file mode 100644
index d61994da..00000000
--- a/src/xfpm-dpms-spins.c
+++ /dev/null
@@ -1,385 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <libxfce4util/libxfce4util.h>
-
-#include "xfpm-dpms-spins.h"
-#include "xfpm-spin-button.h"
-#include "xfpm-marshal.h"
-
-#define SUFFIX_NEVER _("never")
-#define SUFFIX_MIN   _("min")
-
-#ifdef HAVE_DPMS
-
-#ifndef BORDER
-#define BORDER 8
-#endif
-
-#ifndef SPACING
-#define SPACING 2
-#endif
-
-/* init */
-static void xfpm_dpms_spins_init      (XfpmDpmsSpins *dpms_spins);
-static void xfpm_dpms_spins_class_init(XfpmDpmsSpinsClass *klass);
-static void xfpm_dpms_spins_finalize  (GObject *object);
-
-static void xfpm_dpms_spins_get_spin1_value_cb(GtkSpinButton *spin_1,
-                                               XfpmDpmsSpins *spins);
-static void xfpm_dpms_spins_get_spin2_value_cb(GtkSpinButton *spin_2,
-                                               XfpmDpmsSpins *spins);
-static void xfpm_dpms_spins_get_spin3_value_cb(GtkSpinButton *spin_3,
-                                               XfpmDpmsSpins *spins);
-
-#define XFPM_DPMS_SPINS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o),XFPM_TYPE_DPMS_SPINS,XfpmDpmsSpinsPrivate))
-
-struct XfpmDpmsSpinsPrivate
-{
-    GtkWidget *spin_1;
-    gint spin_value_1;
-
-    GtkWidget *spin_2;
-    gint spin_value_2;
-
-    GtkWidget *spin_3;
-    gint spin_value_3;
-
-};
-
-G_DEFINE_TYPE(XfpmDpmsSpins,xfpm_dpms_spins,GTK_TYPE_TABLE);
-
-enum {
-
-    DPMS_VALUE_CHANGED,
-    LAST_SIGNAL
-
-};
-
-static guint signals[LAST_SIGNAL] = { 0,};
-
-static void
-xfpm_dpms_spins_class_init(XfpmDpmsSpinsClass *klass)
-{
-    GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
-    signals[DPMS_VALUE_CHANGED] = g_signal_new("dpms-value-changed",
-                                              XFPM_TYPE_DPMS_SPINS,
-                                              G_SIGNAL_RUN_LAST,
-                                              G_STRUCT_OFFSET(XfpmDpmsSpinsClass,dpms_value_changed),
-                                              NULL,NULL,
-                                              _xfpm_marshal_VOID__INT_INT_INT,
-                                              G_TYPE_NONE,3,
-                                              G_TYPE_INT,
-                                              G_TYPE_INT,
-                                              G_TYPE_INT);
-
-    object_class->finalize = xfpm_dpms_spins_finalize;
-
-    g_type_class_add_private(klass,sizeof(XfpmDpmsSpinsClass));
-
-}
-
-static void
-xfpm_dpms_spins_init(XfpmDpmsSpins *dpms_spins)
-{
-    XfpmDpmsSpinsPrivate *priv;
-    priv = XFPM_DPMS_SPINS_GET_PRIVATE(dpms_spins);
-
-    g_object_set(G_OBJECT(dpms_spins),
-                 "homogeneous",FALSE,
-                 "n-columns",2,
-                 "n-rows",3,
-                 NULL);
-
-    gtk_table_set_homogeneous(GTK_TABLE(dpms_spins), FALSE);
-
-    GtkWidget *label;
-    gchar *suffix = g_strdup_printf(" %s",SUFFIX_MIN);
-    GtkWidget *align;
-    label = gtk_label_new(_("Standby after"));
-    align = gtk_alignment_new (0.0, 0.5, 0, 0);
-    gtk_container_add(GTK_CONTAINER(align), label);
-    gtk_table_attach(GTK_TABLE(dpms_spins),align,0,1,0,1,GTK_FILL,GTK_FILL,BORDER,SPACING);
-    priv->spin_1 = xfpm_spin_button_new_with_range(0,298,1);
-    xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_1),suffix);
-    gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_1,1,2,0,1,GTK_FILL,GTK_FILL,BORDER,SPACING);
-
-    label = gtk_label_new(_("Suspend after"));
-    align = gtk_alignment_new (0.0, 0.5, 0, 0);
-    gtk_container_add(GTK_CONTAINER(align), label);
-    gtk_table_attach(GTK_TABLE(dpms_spins),align,0,1,1,2,GTK_FILL,GTK_FILL,BORDER,SPACING);
-    priv->spin_2 = xfpm_spin_button_new_with_range(0,299,1);
-    xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_2),suffix);
-    gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_2,1,2,1,2,GTK_FILL,GTK_FILL,BORDER,SPACING);
-
-    label = gtk_label_new(_("Turn off after"));
-    align = gtk_alignment_new (0.0, 0.5, 0, 0);
-    gtk_container_add(GTK_CONTAINER(align), label);
-    gtk_table_attach(GTK_TABLE(dpms_spins),align,0,1,2,3,GTK_FILL,GTK_FILL,BORDER,SPACING);
-    priv->spin_3 = xfpm_spin_button_new_with_range(0,300,1);
-    xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_3),suffix);
-    gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_3,1,2,2,3,GTK_FILL,GTK_FILL,BORDER,SPACING);
-
-    gtk_widget_show_all(GTK_WIDGET(dpms_spins));
-
-    g_signal_connect(priv->spin_1,"value-changed",G_CALLBACK(xfpm_dpms_spins_get_spin1_value_cb),dpms_spins);
-    g_signal_connect(priv->spin_2,"value-changed",G_CALLBACK(xfpm_dpms_spins_get_spin2_value_cb),dpms_spins);
-    g_signal_connect(priv->spin_3,"value-changed",G_CALLBACK(xfpm_dpms_spins_get_spin3_value_cb),dpms_spins);
-    g_free(suffix);
-}
-
-static void
-xfpm_dpms_spins_finalize(GObject *object)
-{
-    XfpmDpmsSpins *spins;
-    spins = XFPM_DPMS_SPINS(object);
-
-    G_OBJECT_CLASS(xfpm_dpms_spins_parent_class)->finalize(object);
-}
-
-static void
-xfpm_dpms_spins_get_spin1_value_cb(GtkSpinButton *spin_1,XfpmDpmsSpins *spins)
-{
-    XfpmDpmsSpinsPrivate *priv;
-    priv = XFPM_DPMS_SPINS_GET_PRIVATE(spins);
-
-    gint value1,value2,value3;
-    value1 = gtk_spin_button_get_value(spin_1);
-    value2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_2));
-    value3 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_3));
-
-    if ( value1 == 0 )
-    {
-        priv->spin_value_1 = 0;
-        gchar *suffix = g_strdup_printf(" %s",SUFFIX_NEVER);
-        xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_1),suffix);
-        g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,
-                  value1,value2,value3);
-        g_free(suffix);
-        return;
-    }
-
-    if ( priv->spin_value_1 == 0 )
-    {
-        gchar *suffix = g_strdup_printf(" %s",SUFFIX_MIN);
-        xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_1),suffix);
-        priv->spin_value_1 = value1;
-        g_free(suffix);
-    }
-
-    if ( value2 <= value1 && value2 != 0 )
-    {
-        value2 = value1 + 1;
-        /* gtk_spin_button_set_value generate a value-change signal, to avoid receiving
-         * 3 callbacks we block then handler by func and then unblock it again */
-        g_signal_handlers_block_by_func(priv->spin_2,xfpm_dpms_spins_get_spin2_value_cb,spins);
-        gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_2),value2);
-        g_signal_handlers_unblock_by_func(priv->spin_2,xfpm_dpms_spins_get_spin2_value_cb,spins);
-    }
-
-    if ( value3 <= value2 && value3 != 0)
-    {
-        value3 = value2 + 1;
-        g_signal_handlers_block_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-        gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),value3);
-        g_signal_handlers_unblock_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-    }
-
-    if ( value3 <= value1 && value3 != 0)
-    {
-        value3 = value1 + 1;
-        g_signal_handlers_block_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-        gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),value3);
-        g_signal_handlers_unblock_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-    }
-
-    g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,
-                  value1,value2,value3);
-
-}
-
-static void
-xfpm_dpms_spins_get_spin2_value_cb(GtkSpinButton *spin_2,XfpmDpmsSpins *spins)
-{
-    XfpmDpmsSpinsPrivate *priv;
-    priv = XFPM_DPMS_SPINS_GET_PRIVATE(spins);
-
-    gint value1,value2,value3;
-    value2 = gtk_spin_button_get_value(spin_2);
-
-    value1 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_1));
-
-    value3 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_3));
-
-    if ( value2 == 0 )
-    {
-        priv->spin_value_2 = 0;
-        gchar *suffix = g_strdup_printf(" %s",SUFFIX_NEVER);
-        xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_2),suffix);
-        g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,value1,value2,value3);
-        g_free(suffix);
-
-        return;
-    }
-
-    if ( priv->spin_value_2 == 0 )
-    {
-        gchar *suffix = g_strdup_printf(" %s",SUFFIX_MIN);
-        xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_2),suffix);
-        priv->spin_value_2 = value2;
-        g_free(suffix);
-    }
-
-    if ( value2 <= value1 && value2 != 0)
-    {
-        value2 = value1 + 1;
-        g_signal_handlers_block_by_func(priv->spin_2,xfpm_dpms_spins_get_spin2_value_cb,spins);
-        gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_2),value2);
-        g_signal_handlers_unblock_by_func(priv->spin_2,xfpm_dpms_spins_get_spin2_value_cb,spins);
-    }
-
-    if ( value3 <= value2 && value3 != 0)
-    {
-        value3 = value2 + 1;
-        g_signal_handlers_block_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-        gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),value3);
-        g_signal_handlers_unblock_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-    }
-
-    g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,value1,value2,value3);
-
-}
-
-static void
-xfpm_dpms_spins_get_spin3_value_cb(GtkSpinButton *spin_3,XfpmDpmsSpins *spins)
-{
-    XfpmDpmsSpinsPrivate *priv;
-    priv = XFPM_DPMS_SPINS_GET_PRIVATE(spins);
-
-    gint value1,value2,value3;
-    value3 = gtk_spin_button_get_value(spin_3);
-
-    value1 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_1));
-
-    value2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_2));
-
-    if ( value3 == 0 )
-    {
-        priv->spin_value_3 = 0;
-        gchar *suffix = g_strdup_printf(" %s",SUFFIX_NEVER);
-        xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_3),suffix);
-        g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,value1,value2,value3);
-         g_free(suffix);
-        return;
-    }
-
-    if ( priv->spin_value_3 == 0 )
-    {
-        gchar *suffix = g_strdup_printf(" %s",SUFFIX_MIN);
-        xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_3),suffix);
-        priv->spin_value_3 = value3;
-        g_free(suffix);
-    }
-
-    if ( value3 <= value2 && value3 != 0 )
-    {
-        value3 = value2 + 1;
-        g_signal_handlers_block_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-        gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),value3);
-        g_signal_handlers_unblock_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-    }
-
-    if ( value3 <= value1 && value3 != 0 )
-    {
-        value3 = value1 + 1;
-        g_signal_handlers_block_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-        gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),value3);
-        g_signal_handlers_unblock_by_func(priv->spin_3,xfpm_dpms_spins_get_spin3_value_cb,spins);
-    }
-
-    g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,value1,value2,value3);
-}
-
-GtkWidget *
-xfpm_dpms_spins_new(void)
-{
-    return GTK_WIDGET(g_object_new(XFPM_TYPE_DPMS_SPINS,NULL));
-
-}
-
-void  xfpm_dpms_spins_set_default_values(XfpmDpmsSpins *spins,
-                                        guint spin_1,
-                                        guint spin_2,
-                                        guint spin_3)
-{
-    XfpmDpmsSpinsPrivate *priv;
-    priv = XFPM_DPMS_SPINS_GET_PRIVATE(spins);
-    gchar *suffix = g_strdup_printf(" %s",SUFFIX_NEVER);
-
-    if ( spin_1 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_1),suffix);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_1),spin_1);
-
-    if ( spin_2 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_2),suffix);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_2),spin_2);
-
-    if ( spin_3 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_3),suffix);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),spin_3);
-
-    g_free(suffix);
-}
-
-void
-xfpm_dpms_spins_set_active(XfpmDpmsSpins *spins,
-                          gboolean active)
-{
-    XfpmDpmsSpinsPrivate *priv;
-    priv = XFPM_DPMS_SPINS_GET_PRIVATE(spins);
-
-    gtk_widget_set_sensitive(GTK_WIDGET(priv->spin_1),active);
-    gtk_widget_set_sensitive(GTK_WIDGET(priv->spin_2),active);
-    gtk_widget_set_sensitive(GTK_WIDGET(priv->spin_3),active);
-
-}
-
-#endif /* HAVE_DPMS */
diff --git a/src/xfpm-dpms-spins.h b/src/xfpm-dpms-spins.h
deleted file mode 100644
index c5a12225..00000000
--- a/src/xfpm-dpms-spins.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __XFPM_DPMS_SPINS_H
-#define __XFPM_DPMS_SPINS_H
-
-#include <glib-object.h>
-#include <gtk/gtk.h>
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_DPMS
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_DPMS_SPINS    (xfpm_dpms_spins_get_type())
-#define XFPM_DPMS_SPINS(o)      (G_TYPE_CHECK_INSTANCE_CAST((o),XFPM_TYPE_DPMS_SPINS,XfpmDpmsSpins))
-#define XFPM_IS_DPMS_SPINS(o)   (G_TYPE_CHECK_INSTANCE_TYPE((o),XFPM_TYPE_DPMS_SPINS))
-
-typedef struct XfpmDpmsSpinsPrivate XfpmDpmsSpinsPrivate;
-
-typedef struct 
-{
-    GtkTable parent;
-    XfpmDpmsSpinsPrivate *priv;
-
-} XfpmDpmsSpins;
-
-typedef struct 
-{
-    GtkTableClass parent_class;
-    void         (*dpms_value_changed)       (XfpmDpmsSpins *dpms_spins,
-                                              gint spin_1,
-                                              gint spin_2,
-                                              gint spin_3);
-    
-} XfpmDpmsSpinsClass;
-
-GType          xfpm_dpms_spins_get_type           (void);
-GtkWidget     *xfpm_dpms_spins_new                (void);
-void           xfpm_dpms_spins_set_default_values (XfpmDpmsSpins *spins,
-                                                   guint spin_1,
-                                                   guint spin_2,
-                                                   guint spin_3);    
-void           xfpm_dpms_spins_set_active         (XfpmDpmsSpins *spins,
-                                                   gboolean active);    
-G_END_DECLS
-#endif /*HAVE DPMS */
-
-#endif /* __XFPM_DPMS_SPINS_H */
diff --git a/src/xfpm-dpms.c b/src/xfpm-dpms.c
index 7c6d748d..2d6a45ee 100644
--- a/src/xfpm-dpms.c
+++ b/src/xfpm-dpms.c
@@ -1,6 +1,6 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
+/*
  *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
+ * * Copyright (C) 2008 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -16,13 +16,9 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "xfpm-dpms.h"
-
-#ifdef HAVE_DPMS
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -41,10 +37,6 @@
 #include <errno.h>
 #endif
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 
@@ -52,241 +44,127 @@
 #include <X11/extensions/dpms.h>
 #include <X11/extensions/dpmsstr.h>
 
-#include <xfconf/xfconf.h>
+#include <libxfce4util/libxfce4util.h>
 
-#include "xfpm-common.h"
-#include "xfpm-debug.h"
+#include "libxfpm/xfpm-string.h"
 
-#ifndef _
-#define _(x) x
-#endif
-
-#define DPMS_TIMEOUT 120
+#include "xfpm-dpms.h"
+#include "xfpm-config.h"
 
-#define XFPM_DPMS_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE((o),XFPM_TYPE_DPMS,XfpmDpmsPrivate))
+#ifdef HAVE_DPMS
 
-static void xfpm_dpms_init        (XfpmDpms *dpms);
-static void xfpm_dpms_class_init  (XfpmDpmsClass *klass);
-static void xfpm_dpms_finalize    (GObject *object);
+#define CHECK_DPMS_TIMEOUT 120
 
-static void xfpm_dpms_set_property(GObject *object,
-                                   guint prop_id,
-                                   const GValue *value,
-                                   GParamSpec *pspec);
-static void xfpm_dpms_get_property(GObject *object,
-                                   guint prop_id,
-                                   GValue *value,
-                                   GParamSpec *pspec);
-static void xfpm_dpms_load_config (XfpmDpms *dpms);                                   
-static gboolean xfpm_dpms_set_dpms_mode(XfpmDpms *dpms);
+/* Init */
+static void xfpm_dpms_class_init (XfpmDpmsClass *klass);
+static void xfpm_dpms_init       (XfpmDpms *xfpm_dpms);
+static void xfpm_dpms_finalize   (GObject *object);
 
-static void xfpm_dpms_set_timeouts(XfpmDpms *dpms);
+#define XFPM_DPMS_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_DPMS, XfpmDpmsPrivate))
 
-static void xfpm_dpms_notify_cb        (GObject *object,
-                                        GParamSpec *arg1,
-                                        gpointer data);  
 struct XfpmDpmsPrivate
 {
-    gboolean dpms_capable;
+    XfconfChannel *channel;
+    
+    gboolean       dpms_capable;
+    gboolean       dpms_enabled;
+    
+    guint16        sleep_on_battery;
+    guint16        off_on_battery;
+    guint16        sleep_on_ac;
+    guint16        off_on_ac;
+    
+    gboolean       on_battery;
 };
 
-G_DEFINE_TYPE(XfpmDpms,xfpm_dpms,G_TYPE_OBJECT)
-
-enum
-{
-    PROP_0,
-    PROP_AC_ADAPTER,
-    PROP_DPMS
-};
+G_DEFINE_TYPE(XfpmDpms, xfpm_dpms, G_TYPE_OBJECT)
 
-static void xfpm_dpms_class_init(XfpmDpmsClass *klass)
+static void
+xfpm_dpms_class_init(XfpmDpmsClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
     
-    object_class->set_property = xfpm_dpms_set_property;
-    object_class->get_property = xfpm_dpms_get_property;
-    
     object_class->finalize = xfpm_dpms_finalize;
-    
-    g_object_class_install_property(object_class,
-                                    PROP_AC_ADAPTER,
-                                    g_param_spec_boolean("on-ac-adapter",
-                                                         "On ac adapter",
-                                                         "On Ac power",
-                                                         TRUE,
-                                                         G_PARAM_READWRITE));
-                                                         
-    g_object_class_install_property(object_class,
-                                    PROP_DPMS,
-                                    g_param_spec_boolean("dpms",
-                                                         "dpms",
-                                                         "dpms settings",
-                                                         TRUE,
-                                                         G_PARAM_READWRITE));
-                                                         
+
+
     g_type_class_add_private(klass,sizeof(XfpmDpmsPrivate));
-    
 }
 
-static void xfpm_dpms_init(XfpmDpms *dpms)
+static void
+xfpm_dpms_init(XfpmDpms *dpms)
 {
-    XfpmDpmsPrivate *priv;
-    priv = XFPM_DPMS_GET_PRIVATE(dpms);
-    
-    priv->dpms_capable = DPMSCapable(GDK_DISPLAY());
-    
-    xfpm_dpms_load_config(dpms);
+    dpms->priv = XFPM_DPMS_GET_PRIVATE(dpms);
     
-    g_signal_connect(G_OBJECT(dpms),"notify",G_CALLBACK(xfpm_dpms_notify_cb),NULL);
-    g_timeout_add_seconds(DPMS_TIMEOUT,(GSourceFunc)xfpm_dpms_set_dpms_mode,dpms);
+    dpms->priv->dpms_capable = DPMSCapable (GDK_DISPLAY());
     
 }
 
-static void xfpm_dpms_set_property(GObject *object,
-                                   guint prop_id,
-                                   const GValue *value,
-                                   GParamSpec *pspec)
-{
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif      
-    XfpmDpms *dpms;
-    dpms = XFPM_DPMS(object);
-    
-    switch (prop_id)
-    {
-    case PROP_AC_ADAPTER:
-        dpms->ac_adapter_present = g_value_get_boolean(value);
-        break;   
-    case PROP_DPMS:
-        dpms->dpms_enabled = g_value_get_boolean(value);
-        break;    
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }
-}    
-                               
-static void xfpm_dpms_get_property(GObject *object,
-                                   guint prop_id,
-                                   GValue *value,
-                                   GParamSpec *pspec)
+static void
+xfpm_dpms_finalize(GObject *object)
 {
     XfpmDpms *dpms;
-    dpms = XFPM_DPMS(object);
-        
-    switch (prop_id)
-    {
-    case PROP_AC_ADAPTER:
-        g_value_set_boolean(value,dpms->ac_adapter_present);
-        break;   
-    case PROP_DPMS:
-        g_value_set_boolean(value,dpms->dpms_enabled);
-        break;    
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }                         
-    
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif  
-}
 
-static void xfpm_dpms_finalize(GObject *object)
-{
-    XfpmDpms *dpms;
-    dpms = XFPM_DPMS(object);
-    dpms->priv = XFPM_DPMS_GET_PRIVATE(dpms);
-    
+    dpms = XFPM_DPMS (object);
+
     G_OBJECT_CLASS(xfpm_dpms_parent_class)->finalize(object);
-    
 }
 
-static void xfpm_dpms_load_config (XfpmDpms *dpms)
+static void
+xfpm_dpms_timeouts_on_battery (XfpmDpms *dpms)
 {
-    XFPM_DEBUG("loading configuration\n");
-    XfconfChannel *channel;
+    CARD16 x_standby = 0 ,x_suspend = 0,x_off = 0;
     
-    channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
+    DPMSGetTimeouts (GDK_DISPLAY(), &x_standby, &x_suspend, &x_off);
     
-    GPtrArray *arr;
-    GValue *value;
-    arr = xfconf_channel_get_arrayv(channel,ON_AC_DPMS_TIMEOUTS_CFG);
-    if ( arr ) 
-    {
-        value = g_ptr_array_index(arr,0);
-        dpms->on_ac_standby_timeout = g_value_get_uint(value)*60;
-        
-        value = g_ptr_array_index(arr,1);
-        dpms->on_ac_suspend_timeout = g_value_get_uint(value)*60;
-        
-        value = g_ptr_array_index(arr,2);
-        dpms->on_ac_off_timeout = g_value_get_uint(value)*60;
-        xfconf_array_free(arr);
-    } 
-    else
+    if ( x_suspend != dpms->priv->sleep_on_battery ||
+    	 x_off != dpms->priv->off_on_battery )	
     {
-        dpms->on_ac_standby_timeout = 1800;
-        dpms->on_ac_suspend_timeout = 2700;
-        dpms->on_ac_off_timeout = 3600;
+	DPMSSetTimeouts (GDK_DISPLAY(), dpms->priv->sleep_on_battery ,
+					dpms->priv->sleep_on_battery ,
+					dpms->priv->off_on_battery );
+	TRACE("sleep=%d  turn_off=%d\n", dpms->priv->sleep_on_battery, dpms->priv->off_on_battery);
     }
+}
+
+static void
+xfpm_dpms_timeouts_on_adapter (XfpmDpms *dpms)
+{
+    CARD16 x_standby = 0 ,x_suspend = 0,x_off = 0;
     
-    arr = xfconf_channel_get_arrayv(channel,ON_BATT_DPMS_TIMEOUTS_CFG);
-    if ( arr ) 
-    {
-        value = g_ptr_array_index(arr,0);
-        dpms->on_batt_standby_timeout = g_value_get_uint(value)*60;
-        
-        value = g_ptr_array_index(arr,1);
-        dpms->on_batt_suspend_timeout = g_value_get_uint(value)*60;
-        
-        value = g_ptr_array_index(arr,2);
-        dpms->on_batt_off_timeout = g_value_get_uint(value)*60;
-        xfconf_array_free(arr);
-    } 
-    else
+    DPMSGetTimeouts (GDK_DISPLAY(), &x_standby, &x_suspend, &x_off);
+    
+    if ( x_suspend != dpms->priv->sleep_on_ac ||
+    	 x_off != dpms->priv->off_on_ac )	
     {
-        dpms->on_batt_standby_timeout = 180;
-        dpms->on_batt_suspend_timeout = 240;
-        dpms->on_batt_off_timeout = 300;
+	DPMSSetTimeouts (GDK_DISPLAY(), dpms->priv->sleep_on_ac ,
+					dpms->priv->sleep_on_ac ,
+					dpms->priv->off_on_ac );
+					
+	TRACE("sleep=%d  turn_off=%d\n", dpms->priv->sleep_on_ac, dpms->priv->off_on_ac );
     }
-    dpms->dpms_enabled  = xfconf_channel_get_bool(channel,DPMS_ENABLE_CFG,TRUE);
     
-    g_object_unref(channel);
 }
 
 static gboolean
-xfpm_dpms_set_dpms_mode(XfpmDpms *dpms)
+xfpm_dpms_enable_disable (XfpmDpms *dpms)
 {
-    XfpmDpmsPrivate *priv;
-    priv = XFPM_DPMS_GET_PRIVATE(dpms);
-    
-    if ( !priv->dpms_capable )
-    {
-        return FALSE; /* We stop asking for the dpms state*/
-    }
-    
+    if ( !dpms->priv->dpms_capable )
+    	return FALSE;
+	
     BOOL on_off;
-    CARD16 state = 0;    
+    CARD16 state = 0;
     
-    DPMSInfo(GDK_DISPLAY(),&state,&on_off);
-
-    if ( !on_off && dpms->dpms_enabled )
+    DPMSInfo (GDK_DISPLAY(), &state, &on_off);
+    
+    if ( !on_off && dpms->priv->dpms_enabled )
     {
-        XFPM_DEBUG("DPMS is disabled, enabling it: user settings\n");
+        TRACE("DPMS is disabled, enabling it: user settings");
         DPMSEnable(GDK_DISPLAY());
-        g_object_notify(G_OBJECT(dpms),"dpms");
     } 
-    else if ( on_off && !dpms->dpms_enabled )
+    else if ( on_off && !dpms->priv->dpms_enabled )
     {
-        XFPM_DEBUG("DPMS is enabled, disabling it: user settings\n");
+        TRACE("DPMS is enabled, disabling it: user settings");
         DPMSDisable(GDK_DISPLAY());
     }
     
@@ -294,77 +172,118 @@ xfpm_dpms_set_dpms_mode(XfpmDpms *dpms)
 }
 
 static void
-xfpm_dpms_set_timeouts(XfpmDpms *dpms)
+xfpm_dpms_set_timeouts (XfpmDpms *dpms)
 {
-    CARD16 x_standby = 0 ,x_suspend = 0,x_off = 0;
-    DPMSGetTimeouts(GDK_DISPLAY(),&x_standby,&x_suspend,&x_off);
+    xfpm_dpms_enable_disable (dpms);
     
-    if ( dpms->ac_adapter_present )
-    {
-        if ( x_standby != dpms->on_ac_standby_timeout ||
-             x_suspend != dpms->on_ac_suspend_timeout ||
-             x_off != dpms->on_ac_off_timeout )
-        {
-            XFPM_DEBUG("Setting timeout ac-adapter is present,standby=%d suspend=%d off=%d\n",
-                      dpms->on_ac_standby_timeout,dpms->on_ac_suspend_timeout,dpms->on_ac_off_timeout);
-            DPMSSetTimeouts(GDK_DISPLAY(),dpms->on_ac_standby_timeout,dpms->on_ac_suspend_timeout,
-                                   dpms->on_ac_off_timeout);
-        }
-    }
-    else if ( x_standby != dpms->on_batt_standby_timeout ||
-             x_suspend != dpms->on_batt_suspend_timeout  ||
-             x_off != dpms->on_batt_off_timeout )
-    {
-        {
-            XFPM_DEBUG("Setting timeout ac-adapter not present,standby=%d suspend=%d off=%d\n",
-                      dpms->on_batt_standby_timeout,dpms->on_batt_suspend_timeout,dpms->on_batt_off_timeout);
-            DPMSSetTimeouts(GDK_DISPLAY(),dpms->on_batt_standby_timeout,dpms->on_batt_suspend_timeout,
-                                   dpms->on_batt_off_timeout);
-        }
-    }
+    if ( !dpms->priv->on_battery )
+    	xfpm_dpms_timeouts_on_adapter (dpms);
+    else 
+    	xfpm_dpms_timeouts_on_battery (dpms);
 }
 
 static void
-xfpm_dpms_notify_cb(GObject *object,GParamSpec *arg1,gpointer data)
+xfpm_dpms_value_changed_cb (XfconfChannel *channel, gchar *property,
+			    GValue *value, XfpmDpms *dpms)
 {
-    XfpmDpms *dpms;
-    XfpmDpmsPrivate *priv;
-    
-    dpms = XFPM_DPMS(object);
-    priv = XFPM_DPMS_GET_PRIVATE(dpms);
-    XFPM_DEBUG("dpms callback\n");
+    if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
+    	return;
+	
+    gboolean set = FALSE;
     
-    if ( !priv->dpms_capable ) 
+    if ( xfpm_strequal (property, DPMS_ENABLED_CFG) )
     {
-        XFPM_DEBUG("dpms incapable\n");
-        return;
+	gboolean val = g_value_get_boolean (value);
+	dpms->priv->dpms_enabled = val;
+	set = TRUE;
     }
-    
-    if ( !strcmp(arg1->name,"dpms") )
+    else if ( xfpm_strequal (property, ON_AC_DPMS_SLEEP) )
     {
-        xfpm_dpms_set_dpms_mode(dpms);
+	guint val = g_value_get_uint (value);
+	dpms->priv->sleep_on_ac = MIN(3600, val * 60);
+	set = TRUE;
     }
-    
-    if ( dpms->dpms_enabled )
+    else if ( xfpm_strequal (property, ON_AC_DPMS_OFF) )
     {
-        xfpm_dpms_set_timeouts(dpms);
+	guint val = g_value_get_uint (value);
+	dpms->priv->off_on_ac = MIN(3600, val * 60);
+	set = TRUE;
     }
+    else if ( xfpm_strequal (property, ON_BATT_DPMS_SLEEP) )
+    {
+	guint val = g_value_get_uint (value);
+	dpms->priv->sleep_on_battery = MIN(3600, val * 60);
+	set = TRUE;
+    }
+    else if ( xfpm_strequal (property, ON_BATT_DPMS_OFF) )
+    {
+	guint val = g_value_get_uint (value);
+	dpms->priv->off_on_battery = MIN (3600, val * 60);
+	set = TRUE;
+    }
+    
+    if ( set )
+    	xfpm_dpms_set_timeouts (dpms);
+}
+
+static void
+xfpm_dpms_load_configuration (XfpmDpms *dpms)
+{
+    dpms->priv->dpms_enabled =
+    	xfconf_channel_get_bool (dpms->priv->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);
+
+    dpms->priv->off_on_battery = 
+    	MIN(xfconf_channel_get_uint( dpms->priv->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);
+    
+    dpms->priv->off_on_ac = 
+    	MIN(xfconf_channel_get_uint( dpms->priv->channel, ON_AC_DPMS_OFF, 15) * 60, 3600);
 }
 
 XfpmDpms *
-xfpm_dpms_new(void)
+xfpm_dpms_new (XfconfChannel *channel)
 {
     XfpmDpms *dpms = NULL;
-    dpms = g_object_new(XFPM_TYPE_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;
+    
+    xfpm_dpms_load_configuration (dpms);
+    g_signal_connect (dpms->priv->channel, "property-changed",
+		      G_CALLBACK(xfpm_dpms_value_changed_cb), dpms);
+		      
+    g_timeout_add_seconds ( CHECK_DPMS_TIMEOUT,
+    			    (GSourceFunc) xfpm_dpms_enable_disable, dpms);
+out:
     return dpms;
 }
 
-gboolean   
-xfpm_dpms_capable (XfpmDpms *dpms)
+void xfpm_dpms_set_on_battery  (XfpmDpms *dpms, gboolean on_battery)
 {
-    XfpmDpmsPrivate *priv;
-    priv = XFPM_DPMS_GET_PRIVATE(dpms);
-    return priv->dpms_capable;
+    g_return_if_fail (XFPM_IS_DPMS(dpms));
+    
+    dpms->priv->on_battery = on_battery;
+    
+    xfpm_dpms_set_timeouts (dpms);
 }
 
-#endif
+gboolean xfpm_dpms_capable (XfpmDpms *dpms)
+{
+    g_return_val_if_fail (XFPM_IS_DPMS(dpms), FALSE);
+    
+    return dpms->priv->dpms_capable;
+}
+
+#endif /* HAVE_DPMS */
diff --git a/src/xfpm-dpms.h b/src/xfpm-dpms.h
index 3dcaec94..76528175 100644
--- a/src/xfpm-dpms.h
+++ b/src/xfpm-dpms.h
@@ -1,6 +1,5 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -16,54 +15,50 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifndef __XFPM_DPMS_H
 #define __XFPM_DPMS_H
 
-#include <glib-object.h>
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
+#include <glib-object.h>
+
+#include <xfconf/xfconf.h>
+
 #ifdef HAVE_DPMS
 
 G_BEGIN_DECLS
 
-#define XFPM_TYPE_DPMS      (xfpm_dpms_get_type())
-#define XFPM_DPMS(o)        (G_TYPE_CHECK_INSTANCE_CAST((o),XFPM_TYPE_DPMS,XfpmDpms))
+#define XFPM_TYPE_DPMS        (xfpm_dpms_get_type () )
+#define XFPM_DPMS(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_DPMS, XfpmDpms))
+#define XFPM_IS_DPMS(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_DPMS))
 
 typedef struct XfpmDpmsPrivate XfpmDpmsPrivate;
 
-typedef struct 
+typedef struct
 {
-    GObject parent;
-    XfpmDpmsPrivate *priv;
-    
-    gboolean ac_adapter_present;
-    gboolean force_dpms;
-    gboolean dpms_enabled;
-    
-    guint on_ac_standby_timeout;
-    guint on_ac_suspend_timeout;
-    guint on_ac_off_timeout;
-    guint on_batt_standby_timeout;
-    guint on_batt_suspend_timeout;
-    guint on_batt_off_timeout;
+    GObject		  parent;
+    XfpmDpmsPrivate	 *priv;
     
 } XfpmDpms;
 
 typedef struct
 {
-    GObjectClass parent_class;
-
+    GObjectClass 	  parent_class;
+    
 } XfpmDpmsClass;
 
-GType      xfpm_dpms_get_type    ();
-XfpmDpms  *xfpm_dpms_new         (void);
-gboolean   xfpm_dpms_capable     (XfpmDpms *dpms);
+GType           xfpm_dpms_get_type        (void) G_GNUC_CONST;
+XfpmDpms       *xfpm_dpms_new             (XfconfChannel *channel);
+
+void            xfpm_dpms_set_on_battery  (XfpmDpms *dpms,
+					   gboolean on_battery);
+gboolean        xfpm_dpms_capable         (XfpmDpms *dpms);
+
 
 G_END_DECLS
 
diff --git a/src/xfpm-driver.c b/src/xfpm-driver.c
deleted file mode 100644
index 94671911..00000000
--- a/src/xfpm-driver.c
+++ /dev/null
@@ -1,1208 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <gtk/gtk.h>
-#include <glib.h>
-
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include <hal/libhal.h>
-
-#include <libxfcegui4/libxfcegui4.h>
-#include <libxfce4util/libxfce4util.h>
-
-#include <xfconf/xfconf.h>
-
-#include "xfpm-common.h"
-
-#include "xfpm-driver.h"
-#include "xfpm-debug.h"
-#include "xfpm-battery.h"
-#include "xfpm-cpu.h"
-#include "xfpm-ac-adapter.h"
-#include "xfpm-button.h"
-#include "xfpm-lcd-brightness.h"
-#include "xfpm-popups.h"
-#include "xfpm-enum-types.h"
-#include "xfpm-dbus-messages.h"
-#include "xfpm-string.h"
-
-#ifdef HAVE_LIBNOTIFY
-#include "xfpm-notify.h"
-#endif
-
-#ifdef HAVE_DPMS
-#include "xfpm-dpms.h"
-#include "xfpm-dpms-spins.h"
-#endif
-
-#ifndef _
-#define _(x) x
-#endif
-
-/*init*/
-static void xfpm_driver_init        (XfpmDriver *drv);
-static void xfpm_driver_class_init  (XfpmDriverClass *klass);
-static void xfpm_driver_finalize    (GObject *object);
-
-static void xfpm_driver_dbus_class_init (XfpmDriverClass *klass);
-static void xfpm_driver_dbus_init       (XfpmDriver *manager);
-
-static void xfpm_driver_ac_adapter_state_changed_cb(XfpmAcAdapter *adapter,
-                                                    gboolean present,
-                                                    gboolean state_ok,
-                                                    XfpmDriver *drv);
-                                                    
-static void xfpm_driver_set_power_save(XfpmDriver *drv);
-
-static void xfpm_driver_property_changed_cb(XfconfChannel *channel,
-                                            gchar *property,
-                                            GValue *value,
-                                            XfpmDriver *drv);
-                                            
-/* Function that receives events suspend/hibernate,shutdown for all
- * Xfce power manager components and syncronize them
- */
-#ifdef HAVE_LIBNOTIFY
-static void xfpm_driver_report_sleep_errors(XfpmDriver *driver,
-                                            const gchar *icon_name,
-                                            const gchar *error);
-#endif
-static gboolean xfpm_driver_do_suspend(gpointer data);
-static gboolean xfpm_driver_do_hibernate(gpointer data);
-static gboolean xfpm_driver_do_shutdown(gpointer data);
-
-static void xfpm_driver_suspend(XfpmDriver *drv,gboolean critical);
-static void xfpm_driver_hibernate(XfpmDriver *drv,gboolean critical);
-static void xfpm_driver_shutdown(XfpmDriver *drv,gboolean critical);
-
-static void xfpm_driver_handle_action_request(GObject *object,
-                                              guint action,
-                                              gboolean critical,
-                                              XfpmDriver *drv);
-static void xfpm_driver_load_config(XfpmDriver *drv);
-
-static void xfpm_driver_check_nm(XfpmDriver *drv);
-static void xfpm_driver_check_power_management(XfpmDriver *drv);
-static void xfpm_driver_check_power_save(XfpmDriver *drv);
-static void xfpm_driver_check(XfpmDriver *drv);
-
-static void xfpm_driver_load_all(XfpmDriver *drv);
-
-#define XFPM_DRIVER_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE((o),XFPM_TYPE_DRIVER,XfpmDriverPrivate))
-
-struct XfpmDriverPrivate 
-{
-    DBusGConnection *bus;
-    GMainLoop *loop;
-    XfconfChannel *channel;
-    
-    SystemFormFactor formfactor;
-    
-    guint8 power_management;
-
-#ifdef HAVE_LIBNOTIFY    
-    gboolean show_power_management_error;
-#endif
-    gboolean enable_power_save;
-    
-    gboolean accept_sleep_request;
-    
-    gboolean cpufreq_control;
-    gboolean buttons_control;
-    gboolean lcd_brightness_control;
-    gboolean nm_responding;
-    
-    XfpmHal     *hal;
-    XfpmCpu     *cpu;
-    XfpmBattery *batt;
-    XfpmButton  *bt;
-    XfpmLcdBrightness *lcd;
-    
-#ifdef HAVE_DPMS    
-    XfpmDpms *dpms;
-#endif    
-    GtkStatusIcon *adapter;
-    gboolean ac_adapter_present;
-};
-
-G_DEFINE_TYPE(XfpmDriver,xfpm_driver,G_TYPE_OBJECT)
-
-static void
-xfpm_driver_class_init(XfpmDriverClass *klass)
-{
-    GObjectClass *object_class = G_OBJECT_CLASS(klass);
-    
-    object_class->finalize = xfpm_driver_finalize;
-    
-    g_type_class_add_private(klass,sizeof(XfpmDriverPrivate));
-    
-}
-
-static void
-xfpm_driver_init(XfpmDriver *drv)
-{
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-
-    priv->power_management = 0;
-        
-    priv->cpufreq_control = FALSE;
-    priv->buttons_control = FALSE;
-    priv->enable_power_save = FALSE;
-    priv->lcd_brightness_control = FALSE;
-    priv->accept_sleep_request = TRUE;
-    priv->nm_responding = FALSE;
- 
-    priv->loop    = NULL;
-    priv->cpu     = NULL;
-    priv->adapter = NULL;
-    priv->batt    = NULL;
-    priv->bt      = NULL;
-    priv->lcd     = NULL;
-    priv->hal     = NULL;
-#ifdef HAVE_DPMS
-    priv->dpms    = NULL;
-#endif     
-
-#ifdef HAVE_LIBNOTIFY
-    notify_init("xfce4-power-manager");
-#endif    
-}
-
-static void
-xfpm_driver_finalize(GObject *object)
-{
-    XfpmDriver *drv;
-    drv = XFPM_DRIVER(object);
-    drv->priv = XFPM_DRIVER_GET_PRIVATE(drv);
-
-#ifdef HAVE_DPMS
-    if ( drv->priv->dpms )
-    {
-        g_object_unref(drv->priv->dpms);
-    }
-#endif
-    if ( drv->priv->adapter )
-    {
-        g_object_unref(drv->priv->adapter);
-    }
-    if ( drv->priv->batt )
-    {
-        g_object_unref(drv->priv->batt);
-    }
-    if ( drv->priv->cpufreq_control )
-    {
-        g_object_unref(drv->priv->cpu);
-    }
-    if ( drv->priv->buttons_control )
-    {
-        g_object_unref(drv->priv->bt);
-    }
-    if ( drv->priv->lcd_brightness_control )
-    {
-        g_object_unref(drv->priv->lcd);
-    }
-    if ( drv->priv->bus )
-    {
-        dbus_g_connection_unref(drv->priv->bus);
-    }
-    if ( drv->priv->loop )
-    {
-        g_main_loop_unref(drv->priv->loop);
-    }
-    G_OBJECT_CLASS(xfpm_driver_parent_class)->finalize(object);
-}
-
-static void
-xfpm_driver_set_power_save(XfpmDriver *drv)
-{
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    GError *error = NULL;
-    xfpm_hal_set_power_save(priv->hal,priv->ac_adapter_present,&error);
-    
-    if ( error )
-    {
-        XFPM_DEBUG("Set power save failed: %s\n",error->message);
-        g_error_free(error);
-    }
-}
-
-static void xfpm_driver_ac_adapter_state_changed_cb(XfpmAcAdapter *adapter,
-                                                    gboolean present,
-                                                    gboolean state_ok,
-                                                    XfpmDriver *drv)
-{
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-
-    const gchar *error;
-        error =  _("Unable to read AC adapter status, the power manager will not work properly. "\
-                  "Possible reasons: The AC adapter driver is not loaded, "\
-                  "broken connection with the hardware abstract layer or "\
-				  "the message bus daemon is not running");
-    if ( !state_ok && priv->formfactor == SYSTEM_LAPTOP )  
-    {
-#ifdef HAVE_LIBNOTIFY         
-        gboolean visible;
-        g_object_get(G_OBJECT(priv->adapter),"visible",&visible,NULL);
-                             
-        if ( visible ) 
-        {
-            NotifyNotification *n =
-            xfpm_notify_new(_("Xfce power manager"),
-                            error,
-                            12000,
-                            NOTIFY_URGENCY_CRITICAL,
-                            GTK_STATUS_ICON(adapter),
-                            "gpm-ac-adapter");
-            xfpm_notify_show_notification(n,0);                
-        }  
-        else
-        {
-            xfpm_battery_show_error(priv->batt,"gpm-ac-adapter",error);
-        }
-#else
-    xfpm_popup_message(_("Xfce power manager"),error,GTK_MESSAGE_ERROR);
-#endif    
-    }
-   
-    XFPM_DEBUG("start \n");
-    priv->ac_adapter_present = present;
-    
-#ifdef HAVE_DPMS    
-    XFPM_DEBUG("Setting DPMS ac-adapter property\n");
-    g_object_set(G_OBJECT(priv->dpms),"on-ac-adapter",priv->ac_adapter_present,NULL);
-#endif
-    if ( priv->cpufreq_control )    
-    {
-        g_object_set(G_OBJECT(priv->cpu),"on-ac-adapter",priv->ac_adapter_present,NULL);
-    }
-    g_object_set(G_OBJECT(priv->batt),"on-ac-adapter",priv->ac_adapter_present,NULL);
-    if ( priv->lcd_brightness_control )
-    {
-        g_object_set(G_OBJECT(priv->lcd),"on-ac-adapter",priv->ac_adapter_present,NULL);
-    }
-    
-    if ( priv->power_management & SYSTEM_CAN_POWER_SAVE ) 
-    {
-        xfpm_driver_set_power_save(drv);
-    }
-}                                                    
-
-static void
-xfpm_driver_property_changed_cb(XfconfChannel *channel,gchar *property,
-                                GValue *value,XfpmDriver *drv)
-{
-    XFPM_DEBUG("%s \n",property);
-    if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
-    {
-        XFPM_DEBUG(" invalid value type\n");
-        return;
-    }
-    
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    
-    if ( !xfpm_strcmp(property,CRITICAL_BATT_CFG) ) 
-    {
-        guint val = g_value_get_uint(value);
-        g_object_set(G_OBJECT(priv->batt),"critical-charge",val,NULL);
-        return;
-    }
-    
-    if ( !xfpm_strcmp(property,CRITICAL_BATT_ACTION_CFG) ) 
-    {
-        guint val = g_value_get_uint(value);
-        g_object_set(G_OBJECT(priv->batt),"critical-action",val,NULL);
-        return;
-    }
-    
-    if ( !xfpm_strcmp(property,SHOW_TRAY_ICON_CFG) ) 
-    {
-        gboolean val = g_value_get_uint(value);
-        g_object_set(G_OBJECT(priv->batt),"show-tray-icon",val,NULL);
-        return;
-    }
-    
-    if ( priv->cpufreq_control )
-    {
-        if ( !xfpm_strcmp(property,CPU_FREQ_SCALING_CFG) ) 
-        {
-            gboolean val = g_value_get_boolean(value);
-            g_object_set(G_OBJECT(priv->cpu),"cpu-freq",val,NULL);
-            return;
-        }
-        
-        if ( !xfpm_strcmp(property,ON_AC_CPU_GOV_CFG) ) 
-        {
-            guint val = g_value_get_uint(value);
-            g_object_set(G_OBJECT(priv->cpu),"on-ac-cpu-gov",val,NULL);
-            return;
-        }
-        if ( !xfpm_strcmp(property,ON_BATT_CPU_GOV_CFG) ) 
-        {
-            guint val = g_value_get_uint(value);
-            g_object_set(G_OBJECT(priv->cpu),"on-batt-cpu-gov",val,NULL);
-            return;
-        }
-    }
-#ifdef HAVE_LIBNOTIFY    
-    if ( !xfpm_strcmp(property,BATT_STATE_NOTIFICATION_CFG) ) 
-    {
-        gboolean val = g_value_get_boolean(value);
-        g_object_set(G_OBJECT(priv->batt),"enable-notification",val,NULL);
-        return;
-    }
-#endif    
-
-    if ( priv->lcd_brightness_control )
-    {
-        if ( !xfpm_strcmp(property,LCD_BRIGHTNESS_CFG) )
-        {
-            gboolean val = g_value_get_boolean(value);
-            g_object_set(G_OBJECT(priv->lcd),"brightness-enabled",val,NULL);
-            return;
-        }
-    }
-#ifdef HAVE_DPMS
-    if ( !xfpm_strcmp(property,DPMS_ENABLE_CFG) ) 
-    {
-        gboolean val = g_value_get_boolean(value);
-        priv->dpms->dpms_enabled = val;
-        g_object_notify(G_OBJECT(priv->dpms),"dpms");
-        return;
-    }
-
-    if ( !xfpm_strcmp(property,ON_BATT_DPMS_TIMEOUTS_CFG) ) 
-    {
-        GPtrArray *arr;
-        gpointer data;
-        GValue *val;    
-        guint value1 = 180,value2 = 240,value3 = 300;
-        data = g_value_get_boxed(value);
-        arr = (GPtrArray *) data;
-        
-        val = g_ptr_array_index(arr,0);
-        value1 = g_value_get_uint(val);
-        
-        val = g_ptr_array_index(arr,1);
-        value2 = g_value_get_uint(val);
-        
-        val = g_ptr_array_index(arr,2);
-        value3 = g_value_get_uint(val);
-        priv->dpms->on_batt_standby_timeout = value1 * 60;
-        priv->dpms->on_batt_suspend_timeout = value2 * 60;
-        priv->dpms->on_batt_off_timeout     = value3 * 60; 
-        g_object_notify(G_OBJECT(priv->dpms),"dpms");
-        return;
-    }
-    
-    if ( !xfpm_strcmp(property,ON_AC_DPMS_TIMEOUTS_CFG) ) 
-    {
-        GPtrArray *arr;
-        gpointer data;
-        GValue *val;
-        guint value1 = 1800,value2 = 2700,value3 = 3600;
-        data = g_value_get_boxed(value);
-        arr = (GPtrArray *) data;
-        
-        val = g_ptr_array_index(arr,0);
-        value1 = g_value_get_uint(val);
-        
-        val = g_ptr_array_index(arr,1);
-        value2 = g_value_get_uint(val);
-        
-        val = g_ptr_array_index(arr,2);
-        value3 = g_value_get_uint(val);
-        
-        priv->dpms->on_ac_standby_timeout = value1 * 60;
-        priv->dpms->on_ac_suspend_timeout = value2 * 60;
-        priv->dpms->on_ac_off_timeout     = value3 * 60;
-        
-        g_object_notify(G_OBJECT(priv->dpms),"dpms");
-        return;
-    }
-#endif
-
-    if ( priv->buttons_control )
-    {
-        if ( !xfpm_strcmp(property,LID_SWITCH_CFG) ) 
-        {
-            guint val = g_value_get_uint(value);
-            g_object_set(G_OBJECT(priv->bt),"lid-switch-action",val,NULL);
-            return;
-        }
-        
-        if ( !xfpm_strcmp(property,SLEEP_SWITCH_CFG) ) 
-        {
-            guint val = g_value_get_uint(value);
-            g_object_set(G_OBJECT(priv->bt),"sleep-switch-action",val,NULL);
-            return;
-        }
-        
-        if ( !xfpm_strcmp(property,POWER_SWITCH_CFG) ) 
-        {
-            guint val = g_value_get_uint(value);
-            g_object_set(G_OBJECT(priv->bt),"power-switch-action",val,NULL);
-            return;
-        }
-    }
-    
-    if ( !xfpm_strcmp(property,POWER_SAVE_CFG) )
-    {
-        gboolean val = g_value_get_boolean(value);
-        priv->enable_power_save = val;
-        xfpm_driver_set_power_save(drv);
-    }
-    
-} 
-
-#ifdef HAVE_LIBNOTIFY
-static void
-xfpm_driver_report_sleep_errors(XfpmDriver *driver,const gchar *icon_name,const gchar *error)
-{
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(driver);
-    
-    gboolean adapter_visible;
-    g_object_get(G_OBJECT(priv->adapter),"visible",&adapter_visible,NULL);
-    
-    if ( adapter_visible )
-    {
-        NotifyNotification *n =
-        xfpm_notify_new("Xfce power manager",
-                         error,
-                         14000,
-                         NOTIFY_URGENCY_CRITICAL,
-                         GTK_STATUS_ICON(priv->adapter),
-                         icon_name);
-        xfpm_notify_show_notification(n,0);
-    }
-    else  /* the battery object will take care */
-    {
-        xfpm_battery_show_error(priv->batt,icon_name,error);
-    }
-    
-}
-#endif
-
-static gboolean
-xfpm_driver_do_suspend(gpointer data)
-{
-    XfpmDriver *drv = XFPM_DRIVER(data);
-    XfpmDriverPrivate *priv;
-    GError *error = NULL;
-    guint8 critical;
-    
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    xfpm_hal_suspend(priv->hal,&error,&critical);
-    if ( error )
-    {
-        XFPM_DEBUG("error suspend: %s\n",error->message);
-#ifdef HAVE_LIBNOTIFY        
-        if ( critical == 1)
-        xfpm_driver_report_sleep_errors(drv,"gpm-suspend",error->message);
-#endif        
-        g_error_free(error);
-    }
-    
-    priv->accept_sleep_request = TRUE;
-	if ( priv->nm_responding )
-		xfpm_dbus_send_nm_message("wake");
-    
-    return FALSE;
-    
-}
-
-static gboolean
-xfpm_driver_do_hibernate(gpointer data)
-{
-    XfpmDriver *drv = XFPM_DRIVER(data);
-    XfpmDriverPrivate *priv;
-    GError *error = NULL;
-    guint8 critical;
-    
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    xfpm_hal_hibernate(priv->hal,&error,&critical);
-    
-    if ( error )
-    {
-        XFPM_DEBUG("error hibernate: %s\n",error->message);
-#ifdef HAVE_LIBNOTIFY        
-        if ( critical == 1)
-        xfpm_driver_report_sleep_errors(drv,"gpm-hibernate",error->message);
-#endif        
-        g_error_free(error);
-    }
-        
-    priv->accept_sleep_request = TRUE;
-	if ( priv->nm_responding )
-		xfpm_dbus_send_nm_message("wake");
-		
-    return FALSE;
-    
-}
-
-static gboolean
-xfpm_driver_do_shutdown(gpointer data)
-{
-    XfpmDriver *drv = XFPM_DRIVER(data);
-    XfpmDriverPrivate *priv;
-    
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    if (!xfpm_hal_shutdown(priv->hal))
-    {
-#ifdef HAVE_LIBNOTIFY        
-         xfpm_driver_report_sleep_errors(drv,"gpm-ac-adapter",_("System failed to shutdown"));
-#endif         
-    }
-    
-    priv->accept_sleep_request = TRUE;
-    return FALSE;
-}
-
-static void
-xfpm_driver_hibernate(XfpmDriver *drv,gboolean critical)
-{
-	XfpmDriverPrivate *priv;
-	priv = XFPM_DRIVER_GET_PRIVATE(drv);
-	
-    xfpm_lock_screen();
-	if ( priv->nm_responding )
-		xfpm_dbus_send_nm_message("sleep");
-		
-    g_timeout_add_seconds(2,(GSourceFunc)xfpm_driver_do_hibernate,drv);
-}
-
-static void
-xfpm_driver_suspend(XfpmDriver *drv,gboolean critical)
-{
-	XfpmDriverPrivate *priv;
-	priv = XFPM_DRIVER_GET_PRIVATE(drv);
-	
-    xfpm_lock_screen();
-	
-	if ( priv->nm_responding )
-		xfpm_dbus_send_nm_message("sleep");
-
-    g_timeout_add_seconds(2,(GSourceFunc)xfpm_driver_do_suspend,drv);
-}
-
-static void
-xfpm_driver_shutdown(XfpmDriver *drv,gboolean critical)
-{
-    g_timeout_add(100,(GSourceFunc)xfpm_driver_do_shutdown,drv); 
-}
-
-/* Currently the critical argument is ignored */
-static void
-xfpm_driver_handle_action_request(GObject *object,XfpmActionRequest action,
-                                  gboolean critical,XfpmDriver *drv)
-{
-    g_return_if_fail(XFPM_IS_DRIVER(drv));
-    
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-#ifdef DEBUG
-    gchar *content;
-    GValue value = { 0, };
-    g_value_init(&value,XFPM_TYPE_ACTION_REQUEST);
-    g_value_set_enum(&value,action);
-    content = g_strdup_value_contents(&value);
-        
-    if ( XFPM_IS_BATTERY(object) ) XFPM_DEBUG("Action %s request from the Battery object\n",content);
-    if ( XFPM_IS_AC_ADAPTER(object) ) XFPM_DEBUG("Action %s request from the adapter object\n",content);
-    if ( XFPM_IS_BUTTON(object) ) XFPM_DEBUG("Action %s request from the Button object\n",content);
-    
-    g_free(content);
-    
-#endif    
-    if ( priv->power_management == 0 )
-    {
-        XFPM_DEBUG("We cannot use power management interface\n");
-        return;
-    }
-    if ( !priv->accept_sleep_request )
-    {
-        XFPM_DEBUG("Ignoring sleep request\n");
-        return;
-    }
-
-    /* Block any other event here */   
-    priv->accept_sleep_request = FALSE;    
-    
-    switch ( action )
-    {
-        case XFPM_DO_SUSPEND:
-            if (priv->power_management & SYSTEM_CAN_SUSPEND )
-                xfpm_driver_suspend(drv,critical);
-            break;
-        case XFPM_DO_HIBERNATE:
-            if (priv->power_management & SYSTEM_CAN_HIBERNATE )
-                xfpm_driver_hibernate(drv,critical);
-            break;
-        case XFPM_DO_SHUTDOWN:
-            if ( priv->power_management & SYSTEM_CAN_SHUTDOWN ) 
-                xfpm_driver_shutdown(drv,critical);
-            break;    
-        default:
-            break;
-    } 
-}
-
-static void
-_show_adapter_icon(XfpmBattery *batt,gboolean show,XfpmDriver *drv)
-{
-    XFPM_DEBUG("start\n");
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    g_object_set(G_OBJECT(priv->adapter),"visible",show,NULL);
-    
-}
-
-static void
-_get_system_form_factor(XfpmDriverPrivate *priv)
-{
-    priv->formfactor = SYSTEM_UNKNOWN;
-    
-    gchar *factor = xfpm_hal_get_string_info(priv->hal,
-                                            HAL_ROOT_COMPUTER,
-                                            "system.formfactor",
-                                            NULL);
-    if (!factor ) return;
-    
-    if ( !xfpm_strcmp(factor,"laptop") )
-    {
-        priv->formfactor = SYSTEM_LAPTOP;
-    }
-    else if ( !xfpm_strcmp(factor,"desktop") )
-    {
-        priv->formfactor = SYSTEM_DESKTOP;
-    }
-    else if ( !xfpm_strcmp(factor,"server") )
-    {
-        priv->formfactor = SYSTEM_SERVER;
-    }
-    else if ( !xfpm_strcmp(factor,"unknown") )
-    {
-        priv->formfactor = SYSTEM_UNKNOWN;
-    }
-    libhal_free_string(factor);
-}
-
-static void
-xfpm_driver_load_config(XfpmDriver *drv)    
-{
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    XFPM_DEBUG("Loading configuration\n");
-    
-    XfconfChannel *channel;
-    
-    channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-#ifdef HAVE_LIBNOTIFY
-    priv->show_power_management_error
-     = xfconf_channel_get_bool(channel,SHOW_POWER_MANAGEMENT_ERROR,TRUE);
-#endif
-    priv->enable_power_save = xfconf_channel_get_bool(channel,POWER_SAVE_CFG,FALSE);
-    
-    g_object_unref(channel);
-}
-
-#ifdef HAVE_LIBNOTIFY
-static void
-_disable_error(NotifyNotification *n,gchar *action,XfpmDriver *drv)
-{
-    if (xfpm_strcmp(action,"confirmed")) return;
-    
-    XfconfChannel *channel;
-    
-    channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-    xfconf_channel_set_bool(channel,SHOW_POWER_MANAGEMENT_ERROR,FALSE);
-    
-    g_object_unref(channel);
-    g_object_unref(n);
-}
-#endif
-
-#ifdef HAVE_LIBNOTIFY
-static gboolean
-_show_power_management_error_message(XfpmDriver *drv)
-{
-     const gchar *error =
-                 _("Unable to use power management service, functionalities "\
-				  "like hibernate and suspend will not work. "\
-                  "Possible reasons: you don't have enough permission, "\
-                  "broken connection with the hardware abstract layer "\
-				  "or the message bus daemon is not running");
-     NotifyNotification *n = xfpm_notify_new(_("Xfce power manager"),
-                                             error,
-                                             14000,
-                                             NOTIFY_URGENCY_CRITICAL,
-                                             NULL,
-                                             "gpm-ac-adapter");
-     xfpm_notify_add_action(n,
-                            "confirmed",
-                            _("Don't show this message again"),
-                            (NotifyActionCallback)_disable_error,
-                            drv);   
-     xfpm_notify_show_notification(n,10);                        
-     return FALSE;                       
-}
-#endif
-
-static void xfpm_driver_check_nm(XfpmDriver *drv)
-{
-	XFPM_DEBUG("Checking Network Manager interface\n");
-	
-	XfpmDriverPrivate *priv;
-	priv = XFPM_DRIVER_GET_PRIVATE(drv);
-	
-	DBusError error;
-    DBusConnection *connection;
-
-    dbus_error_init(&error);
-    
-    connection = dbus_bus_get(DBUS_BUS_SYSTEM,&error);
-    
-    if ( dbus_error_is_set(&error) )
-    {
-        XFPM_DEBUG("Error getting D-Bus connection: %s\n",error.message);
-        dbus_error_free(&error);
-        priv->nm_responding = FALSE;
-        return;
-    }    
-    
-    if ( !connection )
-    {
-        XFPM_DEBUG("Error, D-Bus connection NULL\n");
-        priv->nm_responding = FALSE;
-        return;
-    }
-    
-	priv->nm_responding = xfpm_dbus_name_has_owner(connection,NM_SERVICE);
-	dbus_connection_unref(connection);
-	
-}
-
-static void
-xfpm_driver_check_power_management(XfpmDriver *drv)
-{
-    XFPM_DEBUG("Checking power management\n");
-    
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    GError *g_error = NULL;
-    
-    gboolean can_use_power_management = xfpm_hal_power_management_can_be_used(priv->hal);
-    if ( !can_use_power_management )
-    {
-#ifdef HAVE_LIBNOTIFY
-    g_timeout_add_seconds(8,(GSourceFunc)_show_power_management_error_message,drv);
-#endif                                       
-        XFPM_DEBUG("Unable to use HAL power management services\n");
-        return;
-    }
-    priv->power_management |= SYSTEM_CAN_SHUTDOWN;
-    
-    gboolean can_suspend = xfpm_hal_get_bool_info(priv->hal,
-                                               HAL_ROOT_COMPUTER,
-                                               "power_management.can_suspend",
-                                               &g_error);
-    if ( g_error )
-    {
-        XFPM_DEBUG("%s: \n",g_error->message);
-        g_error_free(g_error);
-        g_error = NULL;
-    }            
-    
-    if ( can_suspend )  priv->power_management |= SYSTEM_CAN_SUSPEND;
-    
-    gboolean can_hibernate = xfpm_hal_get_bool_info(priv->hal,
-                                                    HAL_ROOT_COMPUTER,
-                                                    "power_management.can_hibernate",
-                                                    &g_error);
-    if ( g_error )
-    {
-        XFPM_DEBUG("%s: \n",g_error->message);
-        g_error_free(g_error);
-    }       
-    
-    if ( can_hibernate )  priv->power_management |= SYSTEM_CAN_HIBERNATE;
-}
-
-static void
-xfpm_driver_check_power_save(XfpmDriver *drv)
-{
-    XFPM_DEBUG("Checking power save availability\n");
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    GError *error = NULL;
-    gboolean ret = xfpm_hal_get_bool_info(priv->hal,
-                                          HAL_ROOT_COMPUTER,
-                                          "power_management.is_powersave_set",
-                                          &error);
-    if ( error )
-    {
-        XFPM_DEBUG("error getting powersave_set %s\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    
-    xfpm_hal_set_power_save(priv->hal,ret,&error);
-    
-    if ( error )
-    {
-        XFPM_DEBUG("System doesn't support power save: %s\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    
-    if ( ret ) priv->power_management |= SYSTEM_CAN_POWER_SAVE;
-    
-}
-
-static void
-xfpm_driver_check(XfpmDriver *drv)
-{
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    xfpm_driver_check_power_management(drv);
-    
-    if ( priv->power_management != 0 )
-    {
-        xfpm_driver_check_power_save(drv);
-		/* We only check nm if we can use power management*/
-		xfpm_driver_check_nm(drv);
-    }
-}
-
-static void
-xfpm_driver_load_all(XfpmDriver *drv)
-{
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    GError *g_error = NULL;
-    
-#ifdef HAVE_DPMS    
-    priv->dpms = xfpm_dpms_new();
-#endif  
-
-    // Load Cpu only if device exists
-    gchar **cpu_udi = NULL;
-    gint cpu_udi_num;
-    cpu_udi = xfpm_hal_get_device_udi_by_capability(priv->hal,
-                                                    "cpufreq_control",
-                                                    &cpu_udi_num,
-                                                    &g_error);
-    if ( g_error )
-    {
-        XFPM_DEBUG("%s: \n",g_error->message);
-        g_error_free(g_error);
-        priv->cpufreq_control = FALSE;
-    }
-    
-    if ( !cpu_udi || cpu_udi_num == 0 )
-    {
-        XFPM_DEBUG("Cpu control not found\n");
-    }
-    else 
-    {
-        priv->cpu = xfpm_cpu_new();
-        priv->cpufreq_control = TRUE;
-        libhal_free_string_array(cpu_udi);
-    }
-    
-    priv->bt  = xfpm_button_new();
-    // if no device found free the allocated memory
-    guint8 buttons = xfpm_button_get_available_buttons(priv->bt);
-    if ( buttons == 0 )
-    {
-        g_object_unref(priv->bt);
-        priv->buttons_control = FALSE;
-    }
-    else
-    {
-        priv->buttons_control = TRUE;
-        xfpm_button_set_sleep_info(priv->bt,priv->power_management);
-        g_signal_connect(priv->bt,"xfpm-action-request",
-                        G_CALLBACK(xfpm_driver_handle_action_request),drv);
-    }
-    
-    priv->lcd = xfpm_lcd_brightness_new();
-    priv->lcd_brightness_control = xfpm_lcd_brightness_device_exists(priv->lcd);
-    
-    if ( !priv->lcd_brightness_control )
-    {
-        g_object_unref(priv->lcd);
-        
-    }
-    
-    /*We call the battery object to start monitoring after loading the Ac adapter*/
-    priv->batt = xfpm_battery_new(); 
-    xfpm_battery_set_power_info(priv->batt,priv->power_management);
-    
-    g_signal_connect(priv->batt,"xfpm-action-request",
-                        G_CALLBACK(xfpm_driver_handle_action_request),drv);
-    g_signal_connect(priv->batt,"xfpm-show-adapter-icon",G_CALLBACK(_show_adapter_icon),drv);
-                        
-    priv->adapter = xfpm_ac_adapter_new(FALSE);
-    xfpm_ac_adapter_set_sleep_info(XFPM_AC_ADAPTER(priv->adapter),priv->power_management);
-    
-    g_signal_connect(priv->adapter,"xfpm-ac-adapter-changed",
-                    G_CALLBACK(xfpm_driver_ac_adapter_state_changed_cb),drv);
-    g_signal_connect(priv->adapter,"xfpm-action-request",
-                        G_CALLBACK(xfpm_driver_handle_action_request),drv);
-                        
-    /* This will give a signal concerning the AC adapter presence,
-     * so we get the callback and then we set up the ac adapter
-     * status for dpms and cpu lcd,...
-     */                    
-    xfpm_ac_adapter_monitor(XFPM_AC_ADAPTER(priv->adapter),priv->formfactor);
-
-    xfpm_battery_monitor(priv->batt);
-}
-
-static void
-xfpm_driver_quit(XfpmDriver *drv)
-{
-    XfpmDriverPrivate *priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    xfpm_dbus_release_name(dbus_g_connection_get_connection(priv->bus), "org.xfce.PowerManager");
-    
-    g_main_loop_quit(priv->loop);
-    g_object_unref(drv);
-}
-
-XfpmDriver *
-xfpm_driver_new(DBusGConnection *bus)
-{
-    XfpmDriver *driver = NULL;
-    driver =  g_object_new(XFPM_TYPE_DRIVER,NULL);
-    
-    XfpmDriverPrivate *priv = XFPM_DRIVER_GET_PRIVATE(driver);
-    priv->bus = bus;
-    
-    xfpm_driver_dbus_class_init(XFPM_DRIVER_GET_CLASS(driver));
-    xfpm_driver_dbus_init(driver);
-    
-    return driver;
-}
-
-gboolean
-xfpm_driver_monitor (XfpmDriver *drv)
-{
-    g_return_val_if_fail (XFPM_IS_DRIVER(drv),FALSE);
-    XFPM_DEBUG("starting xfpm manager\n");
-    
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(drv);
-    
-    priv->loop = g_main_loop_new(NULL,FALSE);
-    
-    priv->hal = xfpm_hal_new();
-    if ( !xfpm_hal_is_connected(priv->hal) )  
-    {
-        return FALSE;
-    }
-    
-    GError *g_error = NULL;
-    if ( !xfconf_init(&g_error) )
-    {
-        g_critical("xfconf init failed: %s using default settings\n",g_error->message);
-        xfpm_popup_message(_("Xfce4 Power Manager"),_("Failed to load power manager configuration, "\
-                            "using defaults"),GTK_MESSAGE_WARNING);
-        g_error_free(g_error);
-        
-    }
-    else
-    {
-	priv->channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-	g_signal_connect(G_OBJECT(priv->channel), "property-changed",
-			 G_CALLBACK(xfpm_driver_property_changed_cb), drv);
-    }
-    
-    xfpm_dbus_register_name(dbus_g_connection_get_connection(priv->bus), "org.xfce.PowerManager");
-    
-    xfpm_driver_load_config(drv);    
-    _get_system_form_factor(priv);
-    
-    xfpm_driver_check(drv);
-
-    xfpm_driver_load_all(drv);
-    
-    g_main_loop_run(priv->loop);
-
-    xfconf_shutdown();
-    
-    return TRUE;
-}
-
-
-/*
- * 
- * DBus server implementation
- * 
- */
-
-static gboolean xfpm_driver_dbus_quit     (XfpmDriver *driver,
-					    GError **error);
-static gboolean xfpm_driver_dbus_get_conf(XfpmDriver *driver,
-					  gboolean   *OUT_system_laptop,
-					  gint       *OUT_power_management,
-					  gboolean   *OUT_with_dpms,
-					  gint       *OUT_governor,
-					  gint       *OUT_switch_buttons,
-					  gboolean   *OUT_brightness_control,
-					  gboolean   *OUT_ups_found,
-					  GError **error);
-static gboolean xfpm_driver_dbus_get_info (XfpmDriver *driver,
-					    gchar **OUT_name,
-					    gchar **OUT_version,
-					    gchar **OUT_vendor,
-					    GError **error);
-
-#include "xfce-power-manager-dbus-server.h"
-
-static void
-xfpm_driver_dbus_class_init(XfpmDriverClass *klass)
-{
-     dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(klass),
-				    &dbus_glib_xfpm_driver_object_info);
-}
-
-static void
-xfpm_driver_dbus_init(XfpmDriver *driver)
-{
-    XfpmDriverPrivate *priv;
-    priv = XFPM_DRIVER_GET_PRIVATE(driver);
-    dbus_g_connection_register_g_object(priv->bus,
-					"/org/xfce/PowerManager",
-					G_OBJECT(driver));
-}
-
-static gboolean
-xfpm_driver_dbus_quit(XfpmDriver *driver, GError **error)
-{
-    XFPM_DEBUG("Quit message received\n");
-    
-    xfpm_driver_quit(driver);
-    
-    return TRUE;
-}
-
-static gboolean
-xfpm_driver_dbus_get_conf(XfpmDriver *driver,
-			  gboolean   *OUT_system_laptop,
-			  gint       *OUT_power_management,
-			  gboolean   *OUT_with_dpms,
-			  gint       *OUT_governor,
-			  gint       *OUT_switch_buttons,
-			  gboolean   *OUT_brightness_control,
-			  gboolean   *OUT_ups_found,
-			  GError **error)
-{
-    XFPM_DEBUG("Get info message received\n");
-    XfpmDriverPrivate *priv = XFPM_DRIVER_GET_PRIVATE(driver);
-    
-    gboolean with_dpms;
-    
-    guint8 governors = 0;
-    if ( priv->cpufreq_control )
-    {    
-       governors = xfpm_cpu_get_available_governors(priv->cpu);
-    }
-
-#ifdef HAVE_DPMS
-    with_dpms = xfpm_dpms_capable(priv->dpms);
-#else
-    with_dpms = FALSE;
-#endif
-
-    guint8 switch_buttons = 0;
-    if ( priv->buttons_control )
-    {
-        switch_buttons = xfpm_button_get_available_buttons(priv->bt);
-    }
-    gboolean ups_found = xfpm_battery_ups_found(priv->batt);
-    
-    *OUT_system_laptop      = priv->formfactor == SYSTEM_LAPTOP ? TRUE : FALSE;
-    *OUT_power_management   = priv->power_management;
-    *OUT_with_dpms          = with_dpms;
-    *OUT_governor           = governors;
-    *OUT_switch_buttons     = switch_buttons;
-    *OUT_brightness_control = priv->lcd_brightness_control;
-    *OUT_ups_found          = ups_found;
-			       
-    return TRUE;
-}
-
-static gboolean 
-xfpm_driver_dbus_get_info (XfpmDriver *driver,
-			    gchar **OUT_name,
-			    gchar **OUT_version,
-			    gchar **OUT_vendor,
-			    GError **error)
-{
-    
-    *OUT_name    = g_strdup(PACKAGE);
-    *OUT_version = g_strdup(VERSION);
-    *OUT_vendor  = g_strdup("Xfce-goodies");
-    
-    return TRUE;
-}
diff --git a/src/xfpm-driver.h b/src/xfpm-driver.h
deleted file mode 100644
index 431fca98..00000000
--- a/src/xfpm-driver.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __XFPM_DRIVER_H
-#define __XFPM_DRIVER_H
-
-#include <glib-object.h>
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include "xfpm-hal.h"
-#include "xfpm-enums.h"
-
-#ifdef HAVE_DPMS
-#include "xfpm-dpms.h"
-#endif
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_DRIVER   (xfpm_driver_get_type())
-#define XFPM_DRIVER(o)     (G_TYPE_CHECK_INSTANCE_CAST((o),XFPM_TYPE_DRIVER,XfpmDriver))
-#define XFPM_IS_DRIVER(o)  (G_TYPE_CHECK_INSTANCE_TYPE((o),XFPM_TYPE_DRIVER))
-#define XFPM_DRIVER_GET_CLASS(k) (G_TYPE_INSTANCE_GET_CLASS((k), XFPM_TYPE_DRIVER, XfpmDriverClass))
-
-typedef struct XfpmDriverPrivate XfpmDriverPrivate;
-
-typedef struct 
-{
-    GObject parent;
-    XfpmDriverPrivate *priv;
-    
-} XfpmDriver;
-
-typedef struct 
-{
-    GObjectClass parent_class;
-    
-} XfpmDriverClass;
-
-GType         xfpm_driver_get_type              (void);
-XfpmDriver   *xfpm_driver_new                   (DBusGConnection *bus);
-gboolean      xfpm_driver_monitor               (XfpmDriver *drv);
-
-G_END_DECLS
-
-#endif /* __XFPM_DRIVER_H */
diff --git a/src/xfpm-engine.c b/src/xfpm-engine.c
new file mode 100644
index 00000000..f006f80b
--- /dev/null
+++ b/src/xfpm-engine.c
@@ -0,0 +1,389 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <glib.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <xfconf/xfconf.h>
+
+#include "libxfpm/dbus-hal.h"
+#include "libxfpm/xfpm-string.h"
+#include "libxfpm/xfpm-common.h"
+
+#ifdef HAVE_DPMS
+#include "xfpm-dpms.h"
+#endif
+
+#include "xfpm-engine.h"
+#include "xfpm-supply.h"
+#include "xfpm-cpu.h"
+#include "xfpm-button-xf86.h"
+#include "xfpm-lid-hal.h"
+#include "xfpm-brightness-hal.h"
+#include "xfpm-config.h"
+
+#define DUPLICATE_SHUTDOWN_TIMEOUT 4.0f
+
+/* Init */
+static void xfpm_engine_class_init (XfpmEngineClass *klass);
+static void xfpm_engine_init       (XfpmEngine *engine);
+static void xfpm_engine_finalize   (GObject *object);
+
+#define XFPM_ENGINE_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_ENGINE, XfpmEnginePrivate))
+
+struct XfpmEnginePrivate
+{
+    DbusHal   	      *hbus;
+    XfconfChannel     *channel;
+    XfpmSupply        *supply;
+    XfpmCpu           *cpu;
+    XfpmButtonXf86    *xf86_button;
+    XfpmLidHal        *lid;
+    XfpmBrightnessHal *brg_hal;
+    
+#ifdef HAVE_DPMS
+    XfpmDpms          *dpms;
+#endif
+
+    GTimer            *button_timer;
+    
+    guint8             power_management;
+    gboolean           on_battery;
+    
+    gboolean           block_shutdown;
+    
+    /*Configuration */
+    XfpmShutdownRequest sleep_button;
+    XfpmShutdownRequest lid_button_ac;
+    XfpmShutdownRequest lid_button_battery;
+    
+};
+
+G_DEFINE_TYPE(XfpmEngine, xfpm_engine, G_TYPE_OBJECT)
+
+static void
+xfpm_engine_class_init(XfpmEngineClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->finalize = xfpm_engine_finalize;
+
+    g_type_class_add_private(klass,sizeof(XfpmEnginePrivate));
+}
+
+static void
+xfpm_engine_init (XfpmEngine *engine)
+{
+    engine->priv = XFPM_ENGINE_GET_PRIVATE(engine);
+    
+    engine->priv->hbus = dbus_hal_new ();
+
+    engine->priv->button_timer= g_timer_new ();
+
+    engine->priv->channel     = NULL;
+    engine->priv->supply      = NULL;
+#ifdef HAVE_DPMS
+    engine->priv->dpms        = NULL;
+#endif    
+    engine->priv->cpu         = NULL;
+    engine->priv->xf86_button = NULL;
+    engine->priv->lid         = NULL;
+    engine->priv->brg_hal     = NULL;
+}
+
+static void
+xfpm_engine_finalize (GObject *object)
+{
+    XfpmEngine *engine;
+
+    engine = XFPM_ENGINE(object);
+    
+    if ( engine->priv->channel )
+    	g_object_unref (engine->priv->channel);
+	
+    if ( engine->priv->supply )
+    	g_object_unref (engine->priv->supply);
+#ifdef HAVE_DPMS
+    if ( engine->priv->dpms )
+    	g_object_unref (engine->priv->dpms);
+#endif
+
+    if ( engine->priv->cpu )
+    	g_object_unref (engine->priv->cpu);
+
+    if ( engine->priv->lid)
+    	g_object_unref(engine->priv->lid);
+    
+    if ( engine->priv->hbus)
+    	g_object_unref(engine->priv->hbus);
+
+    if ( engine->priv->button_timer)
+    	g_timer_destroy (engine->priv->button_timer);
+	
+    G_OBJECT_CLASS(xfpm_engine_parent_class)->finalize(object);
+}
+
+static void
+xfpm_engine_block_shutdown_cb (XfpmSupply *supply, gboolean block, XfpmEngine *engine)
+{
+    engine->priv->block_shutdown = block;
+}
+
+static void
+xfpm_engine_on_battery_cb (XfpmSupply *supply, gboolean on_battery, XfpmEngine *engine)
+{
+    engine->priv->on_battery = on_battery;
+#ifdef HAVE_DPMS
+    xfpm_dpms_set_on_battery (engine->priv->dpms, on_battery);
+#endif
+    xfpm_cpu_set_on_battery (engine->priv->cpu, on_battery);
+}
+
+const gchar *
+_shutdown_string_from_enum (XfpmShutdownRequest shutdown)
+{
+    if ( shutdown == XFPM_DO_HIBERNATE )
+	return "Hibernate";
+    else if ( shutdown == XFPM_DO_SUSPEND )
+    	return "Suspend";
+    else if ( shutdown == XFPM_DO_SHUTDOWN)
+    	return "Shutdown";
+	
+    return "Nothing";
+}
+	
+
+static void
+xfpm_engine_shutdown_request (XfpmEngine *engine, XfpmShutdownRequest shutdown)
+{
+    const gchar *action =
+    	_shutdown_string_from_enum (shutdown);
+	
+    if ( xfpm_strequal(action, "Nothing") )
+    {
+	TRACE("Sleep button disabled in configuration");
+	return;
+    }
+    else
+    {
+	xfpm_lock_screen ();
+	dbus_hal_shutdown (engine->priv->hbus, action, NULL);
+    }
+}
+
+static void
+xfpm_engine_xf86_button_pressed_cb (XfpmButtonXf86 *button, XfpmXF86Button type, XfpmEngine *engine)
+{
+    TRACE("Received button press event type %d", type);
+    
+    if ( type == BUTTON_POWER_OFF || type == BUTTON_SLEEP )
+    {
+	if ( engine->priv->block_shutdown )
+	    return;
+	    
+	if ( g_timer_elapsed (engine->priv->button_timer, NULL ) < DUPLICATE_SHUTDOWN_TIMEOUT )
+	{
+	    TRACE ("Not accepting shutdown request");
+	    return;
+	}
+    	else
+	{
+	    TRACE("Accepting shutdown request");
+	    xfpm_engine_shutdown_request (engine, engine->priv->sleep_button);
+	}
+	    
+    }
+    g_timer_reset (engine->priv->button_timer);
+}
+
+static void
+xfpm_engine_lid_closed_cb (XfpmLidHal *lid, XfpmEngine *engine)
+{
+    g_return_if_fail (engine->priv->lid_button_ac != XFPM_DO_SHUTDOWN );
+    g_return_if_fail (engine->priv->lid_button_battery != XFPM_DO_SHUTDOWN );
+    
+    if ( engine->priv->on_battery && engine->priv->lid_button_battery == XFPM_DO_NOTHING )
+    {
+	TRACE("System on battery, doing nothing: user settings\n");
+    	return;
+    }
+	
+    if ( !engine->priv->on_battery && engine->priv->lid_button_ac == XFPM_DO_NOTHING )
+    {
+	TRACE("System on AC, doing nothing: user settings\n");
+    	return;
+    }
+    
+    if ( engine->priv->block_shutdown )
+    	return;
+	
+    if ( g_timer_elapsed (engine->priv->button_timer, NULL ) < DUPLICATE_SHUTDOWN_TIMEOUT )
+    {
+	TRACE ("Not accepting shutdown request");
+	return;
+    }
+	
+    TRACE("Accepting shutdown request");
+    
+    xfpm_engine_shutdown_request (engine, engine->priv->on_battery ? 
+					  engine->priv->lid_button_battery :
+					  engine->priv->lid_button_ac);
+    
+    g_timer_reset (engine->priv->button_timer);
+}
+
+static void
+xfpm_engine_load_all (XfpmEngine *engine)
+{
+#ifdef HAVE_DPMS		      
+    engine->priv->dpms = xfpm_dpms_new (engine->priv->channel);
+#endif
+    engine->priv->cpu = xfpm_cpu_new (engine->priv->channel, engine->priv->hbus);
+
+    engine->priv->supply = xfpm_supply_new (engine->priv->hbus, engine->priv->channel);
+
+    g_signal_connect (G_OBJECT(engine->priv->supply), "block-shutdown",
+		      G_CALLBACK (xfpm_engine_block_shutdown_cb), engine);
+
+    g_signal_connect (G_OBJECT(engine->priv->supply), "on-battery",
+		      G_CALLBACK (xfpm_engine_on_battery_cb), engine);
+		      
+    /*
+     * Keys from XF86
+     */
+    engine->priv->xf86_button = xfpm_button_xf86_new ();
+    
+    g_signal_connect (engine->priv->xf86_button, "xf86-button-pressed", 
+		      G_CALLBACK(xfpm_engine_xf86_button_pressed_cb), engine);
+		      
+    /*
+     * Lid from HAL 
+     */
+    engine->priv->lid = xfpm_lid_hal_new ();
+    
+    if ( xfpm_lid_hw_found (engine->priv->lid ))
+    	g_signal_connect (engine->priv->lid, "lid-closed",
+			  G_CALLBACK(xfpm_engine_lid_closed_cb), engine);
+			  
+    /*
+     * Brightness HAL
+     */
+    engine->priv->brg_hal = xfpm_brightness_hal_new ();
+    
+}
+
+static void
+xfpm_engine_load_configuration (XfpmEngine *engine)
+{
+    engine->priv->sleep_button =
+    	xfconf_channel_get_uint (engine->priv->channel, SLEEP_SWITCH_CFG, 0);
+	
+    if ( engine->priv->sleep_button > 3 )
+    {
+    	g_warning ("Configuratuon value for %s is wrong\n", SLEEP_SWITCH_CFG );
+	engine->priv->sleep_button = 0;
+    }
+    
+    engine->priv->lid_button_ac =
+    	xfconf_channel_get_uint (engine->priv->channel, LID_SWITCH_ON_AC_CFG, 0);
+	
+    if ( engine->priv->lid_button_ac > 2 )
+    {
+	g_warning ("Configuratuon value for %s is wrong\n", LID_SWITCH_ON_AC_CFG);
+	engine->priv->lid_button_ac = 0;
+    }
+    
+    engine->priv->lid_button_battery =
+    	xfconf_channel_get_uint (engine->priv->channel, LID_SWITCH_ON_BATTERY_CFG, 0);
+	
+    if ( engine->priv->lid_button_battery > 2 )
+    {
+	g_warning ("Configuratuon value for %s is wrong\n", LID_SWITCH_ON_BATTERY_CFG);
+	engine->priv->lid_button_battery = 0;
+    }
+    
+}
+
+static void
+xfpm_engine_property_changed_cb (XfconfChannel *channel, gchar *property, GValue *value, XfpmEngine *engine)
+{
+    if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
+        return;
+
+    if ( xfpm_strequal (property, SLEEP_SWITCH_CFG) )
+    {
+        guint val = g_value_get_uint (value);
+        engine->priv->sleep_button = val;
+    }
+    else if ( xfpm_strequal (property, LID_SWITCH_ON_AC_CFG) )
+    {
+        guint val = g_value_get_uint (value);
+        engine->priv->lid_button_ac = val;
+    }
+    else if ( xfpm_strequal (property, LID_SWITCH_ON_BATTERY_CFG) )
+    {
+        guint val = g_value_get_uint (value);
+        engine->priv->lid_button_battery = val;
+    }
+    
+}
+
+XfpmEngine *
+xfpm_engine_new(void)
+{
+    XfpmEngine *engine = NULL;
+    engine = g_object_new (XFPM_TYPE_ENGINE, NULL);
+
+    GError *error = NULL;
+    if ( !xfconf_init(&error) )
+    {
+    	g_critical ("xfconf_init failed: %s\n", error->message);
+       	g_error_free (error);
+    }	
+    
+    engine->priv->channel   = xfconf_channel_new ("xfce4-power-manager");
+    
+    g_signal_connect (engine->priv->channel, "property-changed",
+		      G_CALLBACK(xfpm_engine_property_changed_cb), engine);
+    
+    xfpm_engine_load_configuration (engine);
+    xfpm_engine_load_all (engine);
+    
+    return engine;
+}
diff --git a/src/xfpm-engine.h b/src/xfpm-engine.h
new file mode 100644
index 00000000..194d3f9d
--- /dev/null
+++ b/src/xfpm-engine.h
@@ -0,0 +1,52 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_ENGINE_H
+#define __XFPM_ENGINE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_ENGINE        (xfpm_engine_get_type () )
+#define XFPM_ENGINE(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_ENGINE, XfpmEngine))
+#define XFPM_IS_ENGINE(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_ENGINE))
+
+typedef struct XfpmEnginePrivate XfpmEnginePrivate;
+
+typedef struct
+{
+    GObject		  parent;
+    XfpmEnginePrivate	 *priv;
+    
+} XfpmEngine;
+
+typedef struct
+{
+    GObjectClass parent_class;
+    
+} XfpmEngineClass;
+
+GType        	  xfpm_engine_get_type        (void) G_GNUC_CONST;
+XfpmEngine       *xfpm_engine_new             (void);
+
+G_END_DECLS
+
+#endif /* __XFPM_ENGINE_H */
diff --git a/src/xfpm-enum-glib.h b/src/xfpm-enum-glib.h
new file mode 100644
index 00000000..42a23087
--- /dev/null
+++ b/src/xfpm-enum-glib.h
@@ -0,0 +1,70 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_ENUM_GLIB_H
+#define __XFPM_ENUM_GLIB_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+    XFPM_DO_NOTHING,
+    XFPM_DO_SUSPEND,
+    XFPM_DO_HIBERNATE,
+    XFPM_DO_SHUTDOWN
+    
+} XfpmShutdownRequest;
+
+typedef enum
+{
+    SHOW_ICON_ALWAYS,
+    SHOW_ICON_WHEN_BATTERY_PRESENT,
+    SHOW_ICON_WHEN_BATTERY_CHARGING_DISCHARGING
+    
+} XfpmShowIcon;
+
+typedef enum
+{
+    BATTERY_FULLY_CHARGED,
+    BATTERY_NOT_FULLY_CHARGED,
+    BATTERY_IS_CHARGING,
+    BATTERY_IS_DISCHARGING,
+    BATTERY_CHARGE_LOW,
+    BATTERY_CRITICALLY_LOW,
+    BATTERY_NOT_PRESENT
+    
+} XfpmBatteryState;
+
+typedef enum
+{
+    BUTTON_POWER_OFF,
+    BUTTON_SLEEP,
+    BUTTON_MON_BRIGHTNESS_UP,
+    BUTTON_MON_BRIGHTNESS_DOWN
+    
+} XfpmXF86Button;
+
+G_END_DECLS
+
+#endif /* __XFPM_ENUM_GLIB_H */
diff --git a/src/xfpm-enum.h b/src/xfpm-enum.h
new file mode 100644
index 00000000..239b50f6
--- /dev/null
+++ b/src/xfpm-enum.h
@@ -0,0 +1,59 @@
+ /*
+ * * Copyright (C) 2008-2009 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __XFPM_ENUM_H
+#define __XFPM_ENUM_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef enum 
+{
+    SYSTEM_LAPTOP,
+    SYSTEM_DESKTOP,
+    SYSTEM_SERVER,
+    SYSTEM_UNKNOWN
+    
+} SystemFormFactor;
+
+typedef enum
+{
+    LID_SWITCH   = (1<<0),
+    SLEEP_SWITCH = (1<<1),
+    POWER_SWITCH = (1<<2)
+    
+} XfpmSwitchButton;
+
+typedef enum
+{
+    CPU_UNKNOWN         = (1<<0),
+    CPU_POWERSAVE	= (1<<1),
+    CPU_ONDEMAND	= (1<<2),
+    CPU_PERFORMANCE	= (1<<3)
+    
+} XfpmCpuGovernor;
+
+
+#endif /*__XFPM_ENUM_H */
diff --git a/src/xfpm-enums.h b/src/xfpm-enums.h
deleted file mode 100644
index 5cd1bfac..00000000
--- a/src/xfpm-enums.h
+++ /dev/null
@@ -1,59 +0,0 @@
-#ifndef __XFPM_ENUMS_H
-#define __XFPM_ENUMS_H
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-typedef enum
-{
-    XFPM_DO_NOTHING,
-    XFPM_DO_SUSPEND,
-    XFPM_DO_HIBERNATE,
-    XFPM_DO_SHUTDOWN
-    
-} XfpmActionRequest;
-
-/* Icon tray */
-typedef enum
-{
-    ALWAYS,
-    PRESENT,
-    CHARGING_OR_DISCHARGING
-} XfpmShowIcon;
-
-/* Battery State */
-typedef enum
-{
-    NOT_PRESENT,
-    LOW,
-    CRITICAL,
-    DISCHARGING,
-    CHARGING,
-    NOT_FULL,
-    FULL
-} XfpmBatteryState;
-
-/* Battery type */
-typedef enum
-{
-    UNKNOWN,
-    PRIMARY,
-    UPS,
-    KEYBOARD,
-    MOUSE
-    
-} XfpmBatteryType;
-
-/* CPU Freq Linux governors */
-typedef enum
-{
-	CPU_FREQ_CANNOT_BE_USED = (1<<0),
-    POWERSAVE               = (1<<1),
-    ONDEMAND                = (1<<2),
-    PERFORMANCE             = (1<<3),
-    CONSERVATIVE            = (1<<4)
-    
-} XfpmCpuGovernor;
-
-#endif
diff --git a/src/xfpm-hal.c b/src/xfpm-hal.c
deleted file mode 100644
index 19f4b0ff..00000000
--- a/src/xfpm-hal.c
+++ /dev/null
@@ -1,1128 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include <libxfce4util/libxfce4util.h>
-
-#include "xfpm-hal.h"
-#include "xfpm-debug.h"
-#include "xfpm-dbus-messages.h"
-
-#include "xfpm-marshal.h"
-#include "xfpm-string.h"
-
-/* Init */
-static void xfpm_hal_class_init(XfpmHalClass *klass);
-static void xfpm_hal_init      (XfpmHal *xfpm_hal);
-static void xfpm_hal_finalize  (GObject *object);
-
-/*functions listner to HAL events*/
-static void xfpm_hal_device_added                 (LibHalContext *ctx,
-                                                 const gchar *udi);
-
-static void xfpm_hal_device_removed               (LibHalContext *ctx,
-                                                 const gchar *udi);
-
-static void xfpm_hal_device_property_modified     (LibHalContext *ctx,
-                                                 const gchar *udi,
-                                                 const gchar *key,
-                                                 dbus_bool_t is_removed,
-                                                 dbus_bool_t is_added);
-static void xfpm_hal_device_condition             (LibHalContext *ctx,
-                                                 const gchar *udi,
-                                                 const gchar *condition_name,
-                                                 const gchar *condition_detail);
-                                                 
-static gboolean   xfpm_hal_monitor               (XfpmHal *xfpm_hal);
-                                                        
-#define XFPM_HAL_GET_PRIVATE(o)   \
-(G_TYPE_INSTANCE_GET_PRIVATE((o),XFPM_TYPE_HAL,XfpmHalPrivate))
-
-GQuark
-xfpm_hal_error_quark (void)
-{
-	static GQuark quark = 0;
-	if (!quark)
-		quark = g_quark_from_static_string ("xfpm_hal_error");
-
-	return quark;
-}
-
-struct XfpmHalPrivate 
-{
-    
-    DBusConnection *connection;
-    LibHalContext *ctx;    
-    gboolean connected;
-    
-};
-
-enum 
-{
-    XFPM_DEVICE_ADDED,
-    XFPM_DEVICE_REMOVED,
-    XFPM_DEVICE_PROPERTY_CHANGED,
-    XFPM_DEVICE_CONDITION,
-    LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0,};    
-
-G_DEFINE_TYPE(XfpmHal,xfpm_hal,G_TYPE_OBJECT)
-
-static void
-xfpm_hal_class_init(XfpmHalClass *klass) {
-    
-    GObjectClass *object_class = G_OBJECT_CLASS(klass);
-    
-    object_class->finalize = xfpm_hal_finalize;
-           
-    g_type_class_add_private(klass,sizeof(XfpmHalPrivate));
-    
-    signals[XFPM_DEVICE_ADDED] = g_signal_new("xfpm-device-added",
-					      					  XFPM_TYPE_HAL,
-    									      G_SIGNAL_RUN_LAST,
-    									      G_STRUCT_OFFSET(XfpmHalClass,device_added),
-    									      NULL,NULL,
-    									      g_cclosure_marshal_VOID__STRING,
-    									      G_TYPE_NONE,1,G_TYPE_STRING);
-    									                                                                               
-    signals[XFPM_DEVICE_REMOVED] = g_signal_new("xfpm-device-removed",
-                                                XFPM_TYPE_HAL,
-    									        G_SIGNAL_RUN_LAST,
-    									        G_STRUCT_OFFSET(XfpmHalClass,device_removed),
-    									        NULL,NULL,
-    									        g_cclosure_marshal_VOID__STRING,
-    									        G_TYPE_NONE,1,G_TYPE_STRING);
-
-	signals[XFPM_DEVICE_PROPERTY_CHANGED] = g_signal_new("xfpm-device-property-changed",
-                                                          XFPM_TYPE_HAL,
-                                                          G_SIGNAL_RUN_LAST,
-                                                          G_STRUCT_OFFSET(XfpmHalClass,device_property_changed),
-                                                          NULL,NULL,
-                                                          _xfpm_marshal_VOID__STRING_STRING_BOOLEAN_BOOLEAN,
-                                                          G_TYPE_NONE,4,
-                                                          G_TYPE_STRING,G_TYPE_STRING,
-                                                          G_TYPE_BOOLEAN,G_TYPE_BOOLEAN);
-                                                          
-    signals[XFPM_DEVICE_CONDITION] = g_signal_new("xfpm-device-condition",
-                                                  XFPM_TYPE_HAL,
-                                                  G_SIGNAL_RUN_LAST,
-                                                  G_STRUCT_OFFSET(XfpmHalClass,device_condition),
-                                                  NULL,NULL,
-                                                  _xfpm_marshal_VOID__STRING_STRING_STRING,
-                                                  G_TYPE_NONE,3,
-                                                  G_TYPE_STRING,G_TYPE_STRING,
-                                                  G_TYPE_STRING);
-      
-}
-    
-static void
-xfpm_hal_init(XfpmHal *xfpm_hal) {
-    
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-        
-    priv->ctx = NULL;
-    
-    // If this happens then nobody cares
-    if ( !xfpm_hal_monitor(xfpm_hal) ) 
-    {
-        g_printerr(_("Error monitoring HAL events"));
-		g_print("\n");
-        priv->connected = FALSE;
-    } 
-    else
-    {
-        priv->connected = TRUE;
-    }
-}
-    
-static void
-xfpm_hal_finalize(GObject *object) {
-    
-    XfpmHal *xfpm_hal;
-    xfpm_hal = XFPM_HAL(object);
-    xfpm_hal->priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    if ( xfpm_hal->priv->ctx ) 
-    {
-        libhal_ctx_shutdown(xfpm_hal->priv->ctx,NULL);
-        libhal_ctx_free(xfpm_hal->priv->ctx);
-    }  
-    
-    if ( xfpm_hal->priv->connection ) 
-    {
-        dbus_connection_unref(xfpm_hal->priv->connection);
-    }  
-    
-    G_OBJECT_CLASS(xfpm_hal_parent_class)->finalize(object);
-}
-        
-XfpmHal *
-xfpm_hal_new(void) {
-    
-    XfpmHal *xfpm_hal = NULL;
-    xfpm_hal = g_object_new (XFPM_TYPE_HAL,NULL);
-    return xfpm_hal;    
-    
-}        
-
-static void
-xfpm_hal_device_added(LibHalContext *ctx,const gchar *udi) {
-    
-    XfpmHal *xfpm_hal = libhal_ctx_get_user_data(ctx);
-    g_signal_emit(G_OBJECT(xfpm_hal),signals[XFPM_DEVICE_ADDED],0,udi);
-    
-}
-    
-static void
-xfpm_hal_device_removed(LibHalContext *ctx,const gchar *udi) {
-    
-    XfpmHal *xfpm_hal = libhal_ctx_get_user_data(ctx);
-    g_signal_emit(G_OBJECT(xfpm_hal),signals[XFPM_DEVICE_REMOVED],0,udi);
-    
-}
-
-static void
-xfpm_hal_device_property_modified(LibHalContext *ctx,const gchar *udi,
-                                 const gchar *key,dbus_bool_t is_removed,
-                                 dbus_bool_t is_added) {
-    
-    XfpmHal *xfpm_hal = libhal_ctx_get_user_data(ctx);
-    g_signal_emit(G_OBJECT(xfpm_hal),signals[XFPM_DEVICE_PROPERTY_CHANGED],0,udi,key,is_removed,is_added);
-    
-}
-
-static void xfpm_hal_device_condition            (LibHalContext *ctx,
-                                                 const gchar *udi,
-                                                 const gchar *condition_name,
-                                                 const gchar *condition_detail) {
-                                                     
-    XfpmHal *xfpm_hal = libhal_ctx_get_user_data(ctx);
-    g_signal_emit(G_OBJECT(xfpm_hal),signals[XFPM_DEVICE_CONDITION],0,udi,condition_name,condition_detail);                                                     
-                                                     
-}
-
-
-static gboolean 
-xfpm_hal_monitor(XfpmHal *xfpm_hal) {
-    
-    XfpmHalPrivate *priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-
-    DBusError error;
-    dbus_error_init(&error);
-    
-    priv->connection = dbus_bus_get(DBUS_BUS_SYSTEM,&error);
-    
-    if ( !priv->connection || dbus_error_is_set(&error) )
-    {
-        g_critical(_("Unable to connect to DBus: %s"),error.message);
-		g_print("\n");
-        return FALSE;
-    }
-    
-    if ( !xfpm_dbus_name_has_owner(priv->connection,HAL_DBUS_SERVICE) )
-    {
-        g_critical(_("HAL is not running or not responding"));
-		g_print("\n");
-        return FALSE;
-    }
-    priv->ctx = libhal_ctx_new();
-    
-    dbus_connection_setup_with_g_main(priv->connection,NULL);
-    
-    libhal_ctx_set_dbus_connection(priv->ctx,priv->connection);
-    libhal_ctx_init(priv->ctx,&error);
-    
-    if ( dbus_error_is_set(&error) ) {
-        g_printerr(_("Unable to connect to DBus: %s"),error.message);
-		g_print("\n");
-        return FALSE;
-    }    
-    
-    libhal_ctx_set_user_data(priv->ctx,xfpm_hal);    
-    return TRUE;
-}    
-
-gboolean xfpm_hal_is_connected(XfpmHal *hal)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(hal),FALSE);
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(hal);
-    
-    return (priv->connected);
-}
-    
-gboolean xfpm_hal_power_management_can_be_used(XfpmHal *hal)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(hal),FALSE);
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-    
-    DBusMessage *message;
-    DBusMessage *reply;
-    DBusError error;
-    
-    message = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                           HAL_ROOT_COMPUTER,
-                                           HAL_DBUS_INTERFACE_POWER,
-                                           "JustToCheck");
-
-    if (!message)
-    {
-        return FALSE;
-    }
-                                           
-    dbus_error_init(&error);                                       
-                                           
-    reply = dbus_connection_send_with_reply_and_block(priv->connection,message,2000,&error);
-    dbus_message_unref(message);
-    
-	if ( reply ) dbus_message_unref(reply);
-	
-    if ( dbus_error_is_set(&error) )
-    {
-        /* This is the only one place in the program we will 
-         * be happy when we seeDBusError is set */
-        if (!xfpm_strcmp(error.name,"org.freedesktop.DBus.Error.UnknownMethod"))
-        {
-            dbus_error_free(&error);
-            return TRUE;
-        }
-    }
-    return FALSE;
-}
-
-gboolean xfpm_hal_cpu_freq_interface_can_be_used(XfpmHal *hal)
-{
-	g_return_val_if_fail(XFPM_IS_HAL(hal),FALSE);
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-    
-    DBusMessage *message;
-    DBusMessage *reply;
-    DBusError error;
-    
-    message = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        HAL_ROOT_COMPUTER,
-                                        HAL_DBUS_INTERFACE_CPU,
-                                        "CpuFreqJustToCheck");
-
-    if (!message)
-    {
-        return FALSE;
-    }
-                                           
-    dbus_error_init(&error);                                       
-                                           
-    reply = dbus_connection_send_with_reply_and_block(priv->connection,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;
-}
-
-gboolean xfpm_hal_connect_to_signals(XfpmHal *hal,
-                                    gboolean device_removed,
-                                    gboolean device_added,
-                                    gboolean device_property_changed,
-                                    gboolean device_condition)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(hal),FALSE);
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-
-    DBusError error;    
-    dbus_error_init(&error);
-    
-    if (device_added ) 
-    {
-        libhal_ctx_set_device_added(priv->ctx,xfpm_hal_device_added);
-    }
-    if ( device_removed )
-    {
-         libhal_ctx_set_device_removed(priv->ctx,xfpm_hal_device_removed);
-    }
-    if ( device_property_changed )
-    {
-        libhal_ctx_set_device_property_modified(priv->ctx,xfpm_hal_device_property_modified);
-    }
-    if ( device_condition )
-    {
-        libhal_ctx_set_device_condition(priv->ctx,xfpm_hal_device_condition);
-    }
-
-    libhal_device_property_watch_all(priv->ctx,&error);        
-
-    if ( dbus_error_is_set(&error) ) {
-        g_printerr(_("Unable to watch device using HAL: %s"),error.message);
-		g_print("\n");
-        return FALSE;
-    }
-    
-    return TRUE;
-}
-
-gchar **
-xfpm_hal_get_device_udi_by_capability(XfpmHal *xfpm_hal,const gchar *capability,
-                                      gint *num,GError **gerror) {
-
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),NULL);
-    XfpmHalPrivate *priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,NULL);
-    
-    gchar **udi_info = NULL;
-    DBusError error;
-        
-    dbus_error_init(&error);
-    udi_info = libhal_find_device_by_capability(priv->ctx, 
-                                                capability,
-                                                num,
-                                                &error);
-    if ( dbus_error_is_set(&error) ) {
-        g_printerr("Cannot get device by capability: %s\n",error.message);
-        dbus_set_g_error(gerror,&error);
-        dbus_error_free(&error);
-        return NULL;
-    } else {
-        return udi_info;
-    }    
-}    
-
-gint32
-xfpm_hal_get_int_info(XfpmHal *xfpm_hal,const gchar *udi,
-                      const gchar *property,GError **gerror)  {
- 
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),-1);
-    XfpmHalPrivate *priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,-1);
-    
-    DBusError error;
-    gint ret;
-    
-    dbus_error_init(&error);
-        
-    ret = libhal_device_get_property_int(priv->ctx,
-                                         udi,
-                                         property,
-                                         &error);
-                                         
-     
-    if ( dbus_error_is_set(&error)) {
-        g_printerr("Cannot get device int info : %s\n",error.message);
-        dbus_set_g_error(gerror,&error);
-        dbus_error_free(&error);
-        return -1;
-    } else {
-        return ret;
-    }    
-    
-}    
-
-gchar *
-xfpm_hal_get_string_info(XfpmHal *xfpm_hal,const gchar *udi,
-                        const gchar *property,GError **gerror)  {
- 
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),NULL);
-    XfpmHalPrivate *priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,NULL);
-    
-    DBusError error;
-    gchar *ret;
-    
-    dbus_error_init(&error);
-        
-    ret = libhal_device_get_property_string(priv->ctx,
-                                            udi,
-                                            property,
-                                            &error);
-                                         
-     
-    if ( dbus_error_is_set(&error) ) {
-        g_printerr("Cannot get device string info : %s\n",error.message);
-        dbus_set_g_error(gerror,&error);
-        dbus_error_free(&error);
-        return NULL;
-    } else {
-        return ret;
-    }    
-    
-}    
-
-gboolean
-xfpm_hal_get_bool_info(XfpmHal *xfpm_hal,const gchar *udi,
-                        const gchar *property,GError **gerror)  {
- 
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
-    XfpmHalPrivate *priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-    
-    DBusError error;
-    gboolean ret;
-    
-    dbus_error_init(&error);
-        
-    ret = libhal_device_get_property_bool(priv->ctx,
-                                          udi,
-                                          property,
-                                          &error);
-                                         
-     
-    if ( dbus_error_is_set(&error)) {
-        g_printerr("Cannot get device bool info : %s\n",error.message);
-        dbus_set_g_error(gerror,&error);
-        dbus_error_free(&error);
-        return FALSE;
-    } else {
-        return ret;
-    }    
-    
-}    
-
-gboolean
-xfpm_hal_device_have_key (XfpmHal *xfpm_hal,const gchar *udi,
-                         const gchar *key)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-    
-    DBusError error;
-    
-    dbus_error_init(&error);
-    
-    gboolean ret = libhal_device_property_exists(priv->ctx,
-                                                udi,
-                                                key,
-                                                &error);
-    if ( dbus_error_is_set(&error) )
-    {
-        g_printerr("Error getting device property %s\n",error.message);
-        dbus_error_free(&error);    
-        return FALSE;
-    }
-    
-    return ret;
-}
-
-gboolean             
-xfpm_hal_device_have_capability(XfpmHal *xfpm_hal,
-                               const gchar *udi,
-                               const gchar *capability)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-    
-    DBusError error;
-    dbus_error_init(&error);
-    
-    gboolean ret = libhal_device_query_capability(priv->ctx,
-                                                  udi,
-                                                  capability,
-                                                  &error);
-                                                  
-     if ( dbus_error_is_set(&error) )
-    {
-        g_printerr("Error query device capability %s\n",error.message);
-        dbus_error_free(&error);    
-        return FALSE;
-    }
-    
-    return ret;
-}
-
-gboolean xfpm_hal_shutdown(XfpmHal *xfpm_hal)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
-     
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-    
-    DBusMessage *mess;
-	
-	mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-					                    HAL_ROOT_COMPUTER,
-					                    HAL_DBUS_INTERFACE_POWER,
-					                    "Shutdown");
-	
-	if (!mess) {
-		return FALSE;
-	}	
-		
-	if(!dbus_connection_send(priv->connection,
-							 mess,
-							 NULL)) {
-		return FALSE;
-	}						 
-    return TRUE;
-}
-
-static const gchar *
-_filter_error_message(const gchar *error)
-{
-    if(!xfpm_strcmp("No back-end for your operating system",error))
-    {
-        return _("No back-end for your operating system");
-    }
-    else if (!xfpm_strcmp("No hibernate script found",error) )
-    {
-        return _("No hibernate script found");
-    }
-	else if (!xfpm_strcmp("No suspend script found",error) )
-	{
-		return _("No suspend script found");
-	}
-    else if (!xfpm_strcmp("No suspend method found",error) )
-    {
-        return _("No suspend method found");
-    }
-    else if (!xfpm_strcmp("No hibernate method found",error))
-    {
-        return _("No hibernate method found");
-    }
-    return NULL;
-}
-
-gboolean   
-xfpm_hal_hibernate(XfpmHal *xfpm_hal,GError **gerror,guint8 *critical) 
-{
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
-
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-    
-	DBusMessage *mess,*reply;
-	DBusError error;
-	gint exit_code;
-    
-	mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        HAL_ROOT_COMPUTER,
-                                        HAL_DBUS_INTERFACE_POWER,
-                                        "Hibernate");
-	if (!mess) 
-	{
-	    *critical = 1;
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Out of memory"));
-		return FALSE;
-	}	
-	
-	dbus_error_init(&error);
-
-	reply = dbus_connection_send_with_reply_and_block(priv->connection,
-                                                    mess,
-                                                    -1,
-                                                    &error);
-    dbus_message_unref(mess);
-             	
-    if ( dbus_error_is_set(&error) )
-    {
-        XFPM_DEBUG("error=%s\n",error.message);
-		const gchar *error_ret =  _filter_error_message(error.message);
-		if ( error_ret )
-        {
-			g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,"%s",error_ret);
-            *critical = 1;
-        }
-        else 
-        {
-            *critical = 0;
-        }
-        dbus_error_free(&error);
-        return FALSE;
-    }
-    
-    if ( !reply ) 
-	{						  		       
-	    critical = 0;
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Message hibernate didn't get a reply"));
-	    return FALSE;
-    }
-
-    *critical = 1;
-    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);
-        XFPM_DEBUG("MESSAGE_TYPE_RETURN exit_code=%d\n",exit_code);
-        dbus_message_unref(reply);
-        if ( exit_code == 0 )
-        {
-            *critical = 0;
-            return TRUE;
-        }
-        if ( exit_code > 1 ) 
-        {
-            g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("System failed to hibernate"));
-            return FALSE;
-        }                 
-        break;
-    case DBUS_MESSAGE_TYPE_ERROR:
-        dbus_message_unref(reply);
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Error occured while trying to suspend"));
-        return FALSE;	
-    default:
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Unknown reply from the message daemon"));
-        dbus_message_unref(reply);
-        return FALSE;	
-    }
-    return TRUE;
-}
-
-gboolean            
-xfpm_hal_suspend(XfpmHal *xfpm_hal,GError **gerror,guint8 *critical) 
-{
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
-     
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,FALSE);
-    
-	DBusMessage *mess,*reply;
-	DBusError error;
-	int seconds = 0;
-	gint exit_code;
-
-	mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        HAL_ROOT_COMPUTER,
-                                        HAL_DBUS_INTERFACE_POWER,
-                                        "Suspend");
-	if (!mess) 
-	{
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Out of memory"));
-	    *critical = 1;
-		return FALSE;
-	}	
-	
-	dbus_message_append_args(mess,DBUS_TYPE_INT32,&seconds,DBUS_TYPE_INVALID);
-
-    dbus_error_init(&error);
-	reply = dbus_connection_send_with_reply_and_block(priv->connection,
-                                                    mess,
-                                                    -1,
-                                                    &error);
-    dbus_message_unref(mess);
-         	
-    if ( dbus_error_is_set(&error) )
-    {
-        XFPM_DEBUG("error=%s\n",error.message);
-		const gchar *error_ret =  _filter_error_message(error.message);
-		if ( error_ret )
-        {
-			g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,"%s",error_ret);
-            *critical = 1;
-        }
-        else 
-        {
-            *critical = 0;
-        }
-        dbus_error_free(&error);
-        return FALSE;
-    }
-    
-    if ( !reply ) 
-	{						  		       
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Message suspend didn't get a reply"));
-	    *critical = 0;
-	    return FALSE;
-    }
-
-    *critical = 1;
-    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);
-        XFPM_DEBUG("MESSAGE_TYPE_RETURN exit_code=%d\n",exit_code);
-        dbus_message_unref(reply);
-        if ( exit_code == 0 ) 
-        {
-            *critical = 0;
-            return TRUE;
-        }
-        if ( exit_code > 1 ) 
-        {
-            g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("System failed to suspend"));
-            return FALSE;
-        }                 
-        break;
-    case DBUS_MESSAGE_TYPE_ERROR:
-        dbus_message_unref(reply);
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Error occured while trying to suspend"));
-        return FALSE;	
-    default:
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Unknown reply from the message daemon"));
-        dbus_message_unref(reply);
-        return FALSE;	
-    }
-    return TRUE;
-}	
-
-void
-xfpm_hal_set_brightness (XfpmHal *xfpm_hal,
-                         const gchar *interface,
-                         gint32 level,
-                         GError **gerror)
-                                                            
-{
-    g_return_if_fail(XFPM_IS_HAL(xfpm_hal));
-    
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_if_fail(priv->connected == TRUE);
-    
-    DBusMessage *mess,*reply;
-	DBusError error;
-
-	mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        interface,
-                                        HAL_DBUS_INTERFACE_LCD,
-                                        "SetBrightness");
-	if (!mess) 
-	{
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Out of memory"));
-		return;
-	}	
-    
-    dbus_message_append_args(mess,DBUS_TYPE_INT32,&level,DBUS_TYPE_INVALID);
-        
-    dbus_error_init(&error);
-    
-    reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
-    dbus_message_unref(mess);
-    
-    if ( dbus_error_is_set(&error) )
-    {
-         dbus_set_g_error(gerror,&error);
-         dbus_error_free(&error);
-         return;
-    }
-        
-    if ( !reply ) 
-    {
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("No reply from HAL daemon to set monitor brightness level"));
-        return;
-    }
-    
-    dbus_message_unref(reply);
-    return;
-}
-
-gint32
-xfpm_hal_get_brightness (XfpmHal *xfpm_hal,
-                        const gchar *interface,
-                        GError **gerror)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),-1);
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,-1);
-    
-    DBusMessage *mess,*reply;
-	DBusError error;
-	gint32 brightness_level = 0;
-
-	mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        interface,
-                                        HAL_DBUS_INTERFACE_LCD,
-                                        "GetBrightness");
-	if (!mess) 
-	{
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Out of memory"));
-		return -1;
-	}	
-    
-    dbus_error_init(&error);
-    
-    reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
-    dbus_message_unref(mess);
-        
-    if ( dbus_error_is_set(&error) )
-    {
-         dbus_set_g_error(gerror,&error);
-         dbus_error_free(&error);
-         return -1;
-    }
-        
-    if ( !reply ) 
-    {
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("No reply from HAL daemon to get monitor brightness level"));
-        return -1;
-    }
-    
-    dbus_message_get_args(reply,NULL,DBUS_TYPE_INT32,&brightness_level);
-    dbus_message_unref(reply);
-    
-    return brightness_level;
-}
-
-gchar               
-**xfpm_hal_get_available_cpu_governors(XfpmHal *xfpm_hal,GError **gerror)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),NULL);
-     
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,NULL);
-    
-    DBusMessage *mess;
-    DBusMessage *reply;
-    DBusError error;
-    gchar **govs = NULL;
-    int dummy;
-    
-    mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        HAL_ROOT_COMPUTER,
-                                        HAL_DBUS_INTERFACE_CPU,
-                                        "GetCPUFreqAvailableGovernors");
-    if (!mess) 
-	{
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Out of memory"));
-		return NULL;
-	}	
-	
-    dbus_error_init(&error);
-    reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
-
-    dbus_message_unref(mess);
-         
-    if ( dbus_error_is_set(&error) )
-    {
-         dbus_set_g_error(gerror,&error);
-         dbus_error_free(&error);
-         return NULL;
-    }
-        
-    if ( !reply ) 
-    {
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("No reply from HAL daemon to get available cpu governors"));
-        return NULL;
-    }
-    
-    dbus_message_get_args(reply,NULL,
-                          DBUS_TYPE_ARRAY,DBUS_TYPE_STRING,
-                          &govs,&dummy,
-                          DBUS_TYPE_INVALID,DBUS_TYPE_INVALID);
-    dbus_message_unref(reply);                      
-    return govs;
-}
-
-gchar                
-*xfpm_hal_get_current_cpu_governor(XfpmHal *xfpm_hal,GError **gerror)
-{
-    g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),NULL);
-     
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_val_if_fail(priv->connected == TRUE,NULL);
-    
-    DBusMessage *mess;
-    DBusMessage *reply;
-    DBusError error;
-    gchar *gov = NULL;
-    
-    mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        HAL_ROOT_COMPUTER,
-                                        HAL_DBUS_INTERFACE_CPU,
-                                        "GetCPUFreqGovernor");
-    
-    if (!mess) 
-	{
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Out of memory"));
-		return NULL;
-	}	
-	
-    dbus_error_init(&error);
-    
-    reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
-    dbus_message_unref(mess);
-    
-    if ( dbus_error_is_set(&error) )
-    {
-         dbus_set_g_error(gerror,&error);
-         dbus_error_free(&error);
-         return NULL;
-    }
-    
-    if ( !reply ) 
-    {
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("No reply from HAL daemon to get current cpu governor"));
-        return NULL;
-    }
-
-    dbus_message_get_args(reply,NULL,DBUS_TYPE_STRING,&gov,DBUS_TYPE_INVALID);
-    XFPM_DEBUG("Got governor %s\n",gov);
-    dbus_message_unref(reply);
-    return gov;
-}
-
-
-void 
-xfpm_hal_set_cpu_governor (XfpmHal *xfpm_hal,
-                           const gchar *governor,
-                           GError **gerror)
-{
-    g_return_if_fail(XFPM_IS_HAL(xfpm_hal));
-     
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_if_fail(priv->connected == TRUE);
-    
-    XFPM_DEBUG("Setting CPU gov %s\n",governor);
-    
-    DBusMessage *mess;
-    DBusMessage *reply;
-    DBusError error;
-    mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        HAL_ROOT_COMPUTER,
-                                        HAL_DBUS_INTERFACE_CPU,
-                                        "SetCPUFreqGovernor");
-    if (!mess) 
-	{
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Out of memory"));
-		return;
-	}	
-	                                                            
-    dbus_message_append_args(mess,DBUS_TYPE_STRING,&governor,DBUS_TYPE_INVALID);
-    
-    dbus_error_init(&error);
-    reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
-    dbus_message_unref(mess);
-    
-    if ( dbus_error_is_set(&error) )
-    {
-        dbus_set_g_error(gerror,&error);
-        dbus_error_free(&error);
-        return;
-    }
-
-    if ( !reply ) 
-    {
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("No reply from HAL daemon to set cpu governor"));
-        return;
-    }
-    dbus_message_unref(reply);
-}
-
-void                 
-xfpm_hal_set_power_save (XfpmHal *xfpm_hal,
-                         gboolean power_save,
-                         GError **gerror)
-{
-    g_return_if_fail(XFPM_IS_HAL(xfpm_hal));
-    
-    XfpmHalPrivate *priv;
-    priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
-    
-    g_return_if_fail(priv->connected == TRUE);
-    
-    DBusMessage *mess;
-    DBusMessage *reply;
-    DBusError error;
-    mess = dbus_message_new_method_call(HAL_DBUS_SERVICE,
-                                        HAL_ROOT_COMPUTER,
-                                        HAL_DBUS_INTERFACE_POWER,
-                                        "SetPowerSave");
-    if (!mess) 
-	{
-	    g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("Out of memory"));
-		return;
-	}	
-	                                                            
-    dbus_message_append_args(mess,DBUS_TYPE_BOOLEAN,&power_save,DBUS_TYPE_INVALID);
-    
-    dbus_error_init(&error);
-    reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
-    dbus_message_unref(mess);
-    
-    if ( dbus_error_is_set(&error) )
-    {
-        dbus_set_g_error(gerror,&error);
-        dbus_error_free(&error);
-        return;
-    }
-
-    if ( !reply ) 
-    {
-        g_set_error(gerror,XFPM_HAL_ERROR,XFPM_HAL_ERROR_GENERAL,_("No reply from HAL daemon to set power save profile"));
-        return;
-    }
-    dbus_message_unref(reply);
-}                                                            
diff --git a/src/xfpm-hal.h b/src/xfpm-hal.h
deleted file mode 100644
index c3ada3d3..00000000
--- a/src/xfpm-hal.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __XFPM_HAL_H
-#define __XFPM_HAL_H
-
-#include <glib.h>
-
-#include <hal/libhal.h>
-
-#define HAL_DBUS_SERVICE             "org.freedesktop.Hal"
-#define HAL_ROOT_COMPUTER	         "/org/freedesktop/Hal/devices/computer"
-#define	HAL_DBUS_INTERFACE_POWER	 "org.freedesktop.Hal.Device.SystemPowerManagement"
-#define HAL_DBUS_INTERFACE_CPU       "org.freedesktop.Hal.Device.CPUFreq"
-#define HAL_DBUS_INTERFACE_LCD       "org.freedesktop.Hal.Device.LaptopPanel"
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_HAL                  (xfpm_hal_get_type ())
-#define XFPM_HAL(o)                    (G_TYPE_CHECK_INSTANCE_CAST((o),XFPM_TYPE_HAL,XfpmHal))
-#define XFPM_HAL_CLASS(k)              (G_TYPE_CHECK_CLASS_CAST((k),XFPM_TYPE_HAL,XfpmHalClass))
-#define XFPM_IS_HAL(o)                 (G_TYPE_CHECK_INSTANCE_TYPE((o),XFPM_TYPE_HAL))
-#define XFPM_IS_HAL_CLASS(k)           (G_TYPE_CHECK_CLASS_TYPE((k),XFPM_TYPE_HAL))
-#define XFPM_HAL_GET_CLASS(k)          (G_TYPE_INSTANCE_GET_CLASS((k),XFPM_TYPE_HAL,XfpmHalClass))
-
-typedef struct XfpmHalPrivate XfpmHalPrivate;
-
-typedef struct {
-    
-    GObject        parent;
-    XfpmHalPrivate *priv;
-    
-} XfpmHal;     
-
-typedef struct {
-    
-    GObjectClass parent_class;
-    
-    /*signals*/
-    void         (*device_added)              (XfpmHal *xfpm_hal,
-                                              const gchar *udi);
-    
-    void         (*device_removed)            (XfpmHal *xfpm_hal,
-                                              const gchar *udi);
-    
-    void         (*device_property_changed)   (XfpmHal *xfpm_hal,
-                                              const gchar *udi,
-                                              const gchar *key,
-                                              gboolean is_removed,
-                                              gboolean is_added);
-                                              
-    void         (*device_condition)          (XfpmHal *xfpm_hal,
-                                              const gchar *udi,
-                                              const gchar *condition_name,
-                                              const gchar *condition_detail);
-                                                                                        
-} XfpmHalClass;    
-
-typedef enum
-{
-	XFPM_HAL_ERROR_GENERAL
-} XfpmHalError;
-
-#define XFPM_HAL_ERROR xfpm_hal_error_quark()
-
-GQuark               xfpm_hal_error_quark                  (void);
-GType                xfpm_hal_get_type                     (void);
-XfpmHal             *xfpm_hal_new                          (void);
-gboolean             xfpm_hal_is_connected                 (XfpmHal *hal);
-gboolean             xfpm_hal_power_management_can_be_used (XfpmHal *hal);
-gboolean 			 xfpm_hal_cpu_freq_interface_can_be_used(XfpmHal *hal);
-gboolean             xfpm_hal_connect_to_signals           (XfpmHal *hal,
-                                                            gboolean device_removed,
-                                                            gboolean device_added,
-                                                            gboolean device_property_changed,
-                                                            gboolean device_condition);
-                                                            
-gchar              **xfpm_hal_get_device_udi_by_capability (XfpmHal *xfpm_hal,
-                                                             const gchar *capability,
-                                                             gint *num,
-                                                             GError **gerror);
-gint32               xfpm_hal_get_int_info                 (XfpmHal *xfpm_hal,
-                                                             const gchar *udi,
-                                                             const gchar *property,
-                                                             GError **gerror);    
-gchar                *xfpm_hal_get_string_info              (XfpmHal *xfpm_hal,
-                                                            const gchar *udi,
-                                                            const gchar *property,
-                                                            GError **gerror); 
-gboolean             xfpm_hal_get_bool_info                (XfpmHal *xfpm_hal,
-                                                            const gchar *udi,
-                                                            const gchar *property,
-                                                            GError **gerror); 
-gboolean             xfpm_hal_device_have_key              (XfpmHal *xfpm_hal,
-                                                            const gchar *udi,
-                                                            const gchar *key);
-gboolean             xfpm_hal_device_have_capability       (XfpmHal *xfpm_hal,
-                                                            const gchar *udi,
-                                                            const gchar *capability);
-                                                            
-gboolean             xfpm_hal_shutdown                     (XfpmHal *xfpm_hal);
-gboolean             xfpm_hal_hibernate                    (XfpmHal *xfpm_hal,
-                                                            GError **gerror,
-                                                            guint8 *critical);
-gboolean             xfpm_hal_suspend                      (XfpmHal *xfpm_hal,
-                                                            GError **gerror,
-                                                            guint8 *critical);
-void                 xfpm_hal_set_brightness               (XfpmHal *xfpm_hal,
-                                                            const gchar *interface,
-                                                            gint level32,
-                                                            GError **gerror);
-gint32               xfpm_hal_get_brightness               (XfpmHal *xfpm_hal,
-                                                            const gchar *interface,
-                                                            GError **gerror);                                                            
-
-gchar              **xfpm_hal_get_available_cpu_governors  (XfpmHal *xfpm_hal,
-                                                            GError **gerror);
-gchar               *xfpm_hal_get_current_cpu_governor     (XfpmHal *xfpm_hal,
-                                                            GError **gerror);
-void                 xfpm_hal_set_cpu_governor             (XfpmHal *xfpm_hal,
-                                                            const gchar *governor,
-                                                            GError **gerror);
-void                 xfpm_hal_set_power_save               (XfpmHal *xfpm_hal,
-                                                            gboolean power_save,
-                                                            GError **gerror);
-G_END_DECLS
-
-#endif /* __XFPM_HAL_H */
diff --git a/src/xfpm-lcd-brightness.c b/src/xfpm-lcd-brightness.c
deleted file mode 100644
index c81a16f3..00000000
--- a/src/xfpm-lcd-brightness.c
+++ /dev/null
@@ -1,510 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <xfconf/xfconf.h>
-
-#include "xfpm-lcd-brightness.h"
-#include "xfpm-hal.h"
-#include "xfpm-debug.h"
-#include "xfpm-common.h"
-#include "xfpm-string.h"
-
-#define XFPM_LCD_BRIGHTNESS_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE(o,XFPM_TYPE_LCD_BRIGHTNESS,XfpmLcdBrightnessPrivate))
-
-static void xfpm_lcd_brightness_init(XfpmLcdBrightness *lcd);
-static void xfpm_lcd_brightness_class_init(XfpmLcdBrightnessClass *klass);
-static void xfpm_lcd_brightness_finalize(GObject *object);
-
-static void xfpm_lcd_brightness_set_property(GObject *object,
-                                             guint prop_id,
-                                             const GValue *value,
-                                             GParamSpec *pspec);
-static void xfpm_lcd_brightness_get_property(GObject *object,
-                                             guint prop_id,
-                                             GValue *value,
-                                             GParamSpec *pspec);
-
-static void xfpm_lcd_brightness_set_level(XfpmLcdBrightness *lcd);
-
-static void xfpm_lcd_brightness_load_config(XfpmLcdBrightness *lcd);
-
-static void xfpm_lcd_brightness_get_device(XfpmLcdBrightness *lcd);
-
-static void xfpm_lcd_brightness_increase(XfpmLcdBrightness *lcd);
-static void xfpm_lcd_brightness_decrease(XfpmLcdBrightness *lcd);
-
-static void xfpm_lcd_brightness_handle_device_condition_cb(XfpmHal *hal,
-                                                           const gchar *udi,
-                                                           const gchar *condition_name,
-                                                           const gchar *condition_detail,
-                                                           XfpmLcdBrightness *lcd);
-static void xfpm_lcd_brightness_notify_cb(GObject *object,
-                                          GParamSpec *arg1,
-                                          gpointer data);
-
-struct XfpmLcdBrightnessPrivate
-{
-    
-    XfpmHal *hal;
-    gboolean device_exists;
-    gboolean brightness_in_hardware;
-    gchar *udi;
-    gint max_brightness;
-    gint step;
-
-};
-
-G_DEFINE_TYPE(XfpmLcdBrightness,xfpm_lcd_brightness,G_TYPE_OBJECT)
-
-enum
-{
-    PROP_0,
-    PROP_AC_ADAPTER,
-    PROP_BRIGHTNESS
-};
-
-static void xfpm_lcd_brightness_class_init(XfpmLcdBrightnessClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
-    gobject_class->finalize = xfpm_lcd_brightness_finalize;
-    gobject_class->set_property = xfpm_lcd_brightness_set_property;
-    gobject_class->get_property = xfpm_lcd_brightness_get_property;
-    
-    g_object_class_install_property(gobject_class,
-                                    PROP_AC_ADAPTER,
-                                    g_param_spec_boolean("on-ac-adapter",
-                                                         "On ac adapter",
-                                                         "On Ac power",
-                                                         TRUE,
-                                                         G_PARAM_READWRITE));
-                                                         
-    g_object_class_install_property(gobject_class,
-                                    PROP_BRIGHTNESS,
-                                    g_param_spec_boolean("brightness-enabled",
-                                                         "brightness enabled",
-                                                         "brightness settings",
-                                                         TRUE,
-                                                         G_PARAM_READWRITE));
-    
-    g_type_class_add_private(klass,sizeof(XfpmLcdBrightnessPrivate));
-
-}
-
-static void xfpm_lcd_brightness_init(XfpmLcdBrightness *lcd)
-{
-    XfpmLcdBrightnessPrivate *priv;
-    priv = XFPM_LCD_BRIGHTNESS_GET_PRIVATE(lcd);
-    
-    priv->hal = xfpm_hal_new();
-    priv->device_exists = FALSE;
-    priv->brightness_in_hardware = TRUE; 
-    priv->udi = NULL;
-    priv->max_brightness = -1;
-    priv->step = 0;
-    
-    xfpm_lcd_brightness_load_config(lcd);
-    xfpm_lcd_brightness_get_device(lcd);
-    
-    if ( priv->device_exists )
-    {
-        g_signal_connect(G_OBJECT(lcd),"notify",
-                         G_CALLBACK(xfpm_lcd_brightness_notify_cb),NULL);
-        if (!priv->brightness_in_hardware )
-        {
-            if (xfpm_hal_connect_to_signals(priv->hal,FALSE,FALSE,FALSE,TRUE) )
-            {
-                g_signal_connect(priv->hal,"xfpm-device-condition",
-                            G_CALLBACK(xfpm_lcd_brightness_handle_device_condition_cb),lcd);
-            }
-        }                 
-    }
-    
-}
-
-static void xfpm_lcd_brightness_finalize(GObject *object)
-{
-    XfpmLcdBrightness *lcd;
-    lcd = XFPM_LCD_BRIGHTNESS(object);
-    lcd->priv = XFPM_LCD_BRIGHTNESS_GET_PRIVATE(lcd);
-    
-    if ( lcd->priv->hal ) 
-    {
-        g_object_unref(lcd->priv->hal);
-    }
-    if ( lcd->priv->udi )
-    {
-        g_free(lcd->priv->udi);
-    }
-    
-    G_OBJECT_CLASS(xfpm_lcd_brightness_parent_class)->finalize(object);
-}
-
-static void 
-xfpm_lcd_brightness_set_property(GObject *object,
-                                 guint prop_id,
-                                 const GValue *value,
-                                 GParamSpec *pspec)
-{
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif      
-    XfpmLcdBrightness *lcd;
-    lcd = XFPM_LCD_BRIGHTNESS(object);
-    
-    switch (prop_id)
-    {
-    case PROP_AC_ADAPTER:
-        lcd->ac_adapter_present = g_value_get_boolean(value);
-        break;   
-    case PROP_BRIGHTNESS:
-        lcd->brightness_control_enabled = g_value_get_boolean(value);
-        break;    
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }
-
-}
-
-static void 
-xfpm_lcd_brightness_get_property(GObject *object,
-                                 guint prop_id,
-                                 GValue *value,
-                                 GParamSpec *pspec)
-{
-    XfpmLcdBrightness *lcd;
-    lcd = XFPM_LCD_BRIGHTNESS(object);
-        
-    switch (prop_id)
-    {
-    case PROP_AC_ADAPTER:
-        g_value_set_boolean(value,lcd->ac_adapter_present);
-        break;   
-    case PROP_BRIGHTNESS:
-        g_value_set_boolean(value,lcd->brightness_control_enabled);
-        break;    
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
-        break;
-    }                         
-    
-#ifdef DEBUG
-    gchar *content;
-    content = g_strdup_value_contents(value);
-    XFPM_DEBUG("param:%s value contents:%s\n",pspec->name,content);
-    g_free(content);
-#endif  
-    
-}                                 
-
-static void
-xfpm_lcd_brightness_set_level(XfpmLcdBrightness *lcd)
-{
-    XfpmLcdBrightnessPrivate *priv;
-    priv = XFPM_LCD_BRIGHTNESS_GET_PRIVATE(lcd);
-    
-    GError *error = NULL;
-    gint32 level =
-        xfpm_hal_get_brightness(priv->hal,priv->udi,&error);
-        
-    if ( error )
-    {
-        XFPM_DEBUG("Get brightness failed: %s\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    
-    if ( lcd->ac_adapter_present )
-    {
-        XFPM_DEBUG("Setting level on ac adapter\n");
-        if ( level != priv->max_brightness -1 )
-        {
-            xfpm_hal_set_brightness(priv->hal,priv->udi,priv->max_brightness -1,&error);
-            if ( error )
-            {
-                XFPM_DEBUG("Error setting brigthness level: %s\n",error->message);
-                g_error_free(error);
-                return;
-            }
-        }
-    }
-    else 
-    {
-        XFPM_DEBUG("Setting level battery power\n");
-        xfpm_hal_set_brightness(priv->hal,priv->udi, 1,&error);
-        if ( error )
-        {
-            XFPM_DEBUG("Error setting brigthness level: %s\n",error->message);
-            g_error_free(error);
-            return;
-        }
-    }
-}
-
-static void xfpm_lcd_brightness_load_config(XfpmLcdBrightness *lcd)
-{
-    XFPM_DEBUG("Loading configuration\n");
-    
-    XfconfChannel *channel;
-    channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-
-    lcd->brightness_control_enabled = xfconf_channel_get_bool(channel,LCD_BRIGHTNESS_CFG,TRUE);
-    
-    g_object_unref(channel);
-}
-
-static void
-_get_steps(XfpmLcdBrightness *lcd)
-{
-    XfpmLcdBrightnessPrivate *priv;
-    priv = XFPM_LCD_BRIGHTNESS_GET_PRIVATE(lcd);
-    
-    if ( priv->max_brightness <= 9 )
-    {
-        priv->step = 1;
-        return;
-    }
-    
-    priv->step = priv->max_brightness/10; /* 77 for example will give 7 step, so that's okay */
-    XFPM_DEBUG("Found approximate lcd brightness steps = %d\n",priv->step);
-}
-
-static void
-xfpm_lcd_brightness_get_device(XfpmLcdBrightness *lcd)
-{
-    XfpmLcdBrightnessPrivate *priv;
-    priv = XFPM_LCD_BRIGHTNESS_GET_PRIVATE(lcd);
-
-    gchar **udi = NULL;
-    gint num;
-    GError *error = NULL;
-    udi = xfpm_hal_get_device_udi_by_capability(priv->hal,"laptop_panel",&num,&error);
-    
-    if ( error ) 
-    {
-        XFPM_DEBUG("%s: \n",error->message);
-        g_error_free(error);
-        return;
-    }
-
-    if ( num == 0 ) return;
-        
-    if ( !udi )
-    {
-        XFPM_DEBUG("No device with laptop_panel capability\n");
-        return;
-    }
-    
-    /* Only one device should be in HAL */
-    g_return_if_fail(num == 1);        
-    
-    priv->udi = g_strdup(udi[0]);
-    XFPM_DEBUG("Found laptop panel device: %s\n",udi[0]);
-    libhal_free_string_array(udi);
-    
-    if ( xfpm_hal_device_have_key(priv->hal,priv->udi,"laptop_panel.num_levels") )
-    {
-        priv->max_brightness = xfpm_hal_get_int_info(priv->hal,priv->udi,"laptop_panel.num_levels",&error);
-        if ( error )
-        {
-            XFPM_DEBUG("error getting max brigthness level: %s\n",error->message);
-            g_error_free(error);
-            return;
-        }
-        XFPM_DEBUG("Max screen luminosity = %d\n",priv->max_brightness);
-        priv->device_exists = TRUE;
-    }
-    
-    if ( xfpm_hal_device_have_key(priv->hal,priv->udi,"laptop_panel.brightness_in_hardware") )
-    {
-        priv->brightness_in_hardware = xfpm_hal_get_bool_info(priv->hal,priv->udi,
-                                            "laptop_panel.brightness_in_hardware",&error);
-        if ( error )
-        {
-            XFPM_DEBUG("error getting max brigthness level: %s\n",error->message);
-            g_error_free(error);
-            priv->brightness_in_hardware = TRUE; /* we always assume that control is in hardware */
-            return;
-        }          
-        if ( !priv->brightness_in_hardware )
-        {
-            _get_steps(lcd);
-        }
-    }
-    
-}
-
-static void
-xfpm_lcd_brightness_increase(XfpmLcdBrightness *lcd)
-{
-    XfpmLcdBrightnessPrivate *priv;
-    priv = XFPM_LCD_BRIGHTNESS_GET_PRIVATE(lcd);
-    GError *error = NULL;
-    gint32 level =
-        xfpm_hal_get_brightness(priv->hal,priv->udi,&error);
-        
-    if ( error )
-    {
-        XFPM_DEBUG("Get brightness failed: %s\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    
-    if ( level != priv->max_brightness -1 )
-    {
-        gint32 set = priv->step + level;
-        if ( set > priv->max_brightness -1 )
-        {
-            set = priv->max_brightness -1;
-        }
-        XFPM_DEBUG("Setting brightness=%d\n",set);
-        xfpm_hal_set_brightness(priv->hal,priv->udi,set,&error);
-        if ( error )
-        {
-            XFPM_DEBUG("Error setting brigthness level: %s\n",error->message);
-            g_error_free(error);
-            return;
-        }
-    }
-}
-
-static void
-xfpm_lcd_brightness_decrease(XfpmLcdBrightness *lcd)
-{
-    XfpmLcdBrightnessPrivate *priv;
-    priv = XFPM_LCD_BRIGHTNESS_GET_PRIVATE(lcd);
-    GError *error = NULL;
-    gint32 level =
-        xfpm_hal_get_brightness(priv->hal,priv->udi,&error);
-        
-    if ( error )
-    {
-        XFPM_DEBUG("Get brightness failed: %s\n",error->message);
-        g_error_free(error);
-        return;
-    }
-    
-    if ( level != 1 )
-    {
-        gint32 set =  level - priv->step;
-        
-        if ( set < 0 )
-        {
-            set = 1;
-        }
-        XFPM_DEBUG("Setting brightness=%d\n",set);
-        xfpm_hal_set_brightness(priv->hal,priv->udi,set,&error);
-        if ( error )
-        {
-            XFPM_DEBUG("Error setting brigthness level: %s\n",error->message);
-            g_error_free(error);
-            return;
-        }
-    }
-}
-
-static void 
-xfpm_lcd_brightness_handle_device_condition_cb(XfpmHal *hal,
-                                               const gchar *udi,
-                                               const gchar *condition_name,
-                                               const gchar *condition_detail,
-                                               XfpmLcdBrightness *lcd)
-{
-    if ( !lcd->brightness_control_enabled ) return;
-        
-    if ( xfpm_hal_device_have_capability(hal,udi,"button") )
-    {
-        if ( !xfpm_strcmp(condition_name,"ButtonPressed") )
-        {
-            if ( !xfpm_strcmp(condition_detail,"brightness-down") )
-            {
-                xfpm_lcd_brightness_decrease(lcd);
-            }
-            else if ( !xfpm_strcmp(condition_name,"brightness-up") )
-            {
-                xfpm_lcd_brightness_increase(lcd);
-            }
-        }
-    }
-}                                                           
-                                                           
-
-static void
-xfpm_lcd_brightness_notify_cb(GObject *object,GParamSpec *arg1,gpointer data)
-{
-    XfpmLcdBrightness *lcd;
-    
-    lcd = XFPM_LCD_BRIGHTNESS(object);
-    
-    XFPM_DEBUG("brightness callback\n");
-    
-    if ( !lcd->brightness_control_enabled )
-    {
-        XFPM_DEBUG("Lcd brightness is disabled\n");
-        return;
-    }
-    
-    xfpm_lcd_brightness_set_level(lcd);    
-}
-
-XfpmLcdBrightness *
-xfpm_lcd_brightness_new(void)
-{
-    XfpmLcdBrightness *lcd;
-    lcd = g_object_new(XFPM_TYPE_LCD_BRIGHTNESS,NULL);
-    return lcd;
-}
-
-gboolean
-xfpm_lcd_brightness_device_exists(XfpmLcdBrightness *lcd)
-{
-    g_return_val_if_fail(XFPM_IS_LCD_BRIGHTNESS(lcd),FALSE);
-    XfpmLcdBrightnessPrivate *priv;
-    priv = XFPM_LCD_BRIGHTNESS_GET_PRIVATE(lcd);
-    return priv->device_exists;
-}
diff --git a/src/xfpm-lcd-brightness.h b/src/xfpm-lcd-brightness.h
deleted file mode 100644
index 9dc57b01..00000000
--- a/src/xfpm-lcd-brightness.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __XFPM_LCD_BRIGHTNESS_H
-#define __XFPM_LCD_BRIGHTNESS_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_LCD_BRIGHTNESS  (xfpm_lcd_brightness_get_type())
-#define XFPM_LCD_BRIGHTNESS(o)    (G_TYPE_CHECK_INSTANCE_CAST(o,XFPM_TYPE_LCD_BRIGHTNESS,XfpmLcdBrightness))
-#define XFPM_IS_LCD_BRIGHTNESS(o) (G_TYPE_CHECK_INSTANCE_TYPE(o,XFPM_TYPE_LCD_BRIGHTNESS))
-
-typedef struct XfpmLcdBrightnessPrivate XfpmLcdBrightnessPrivate;
-
-typedef struct
-{
-    GObject parent;
-    XfpmLcdBrightnessPrivate *priv;
-    
-    gboolean brightness_control_enabled;
-    gboolean ac_adapter_present;
-    
-} XfpmLcdBrightness;
-
-typedef struct
-{
-    GObjectClass parent_class;
-    
-} XfpmLcdBrightnessClass;
-
-GType              xfpm_lcd_brightness_get_type(void) G_GNUC_CONST;
-XfpmLcdBrightness *xfpm_lcd_brightness_new(void);
-gboolean           xfpm_lcd_brightness_device_exists(XfpmLcdBrightness *lcd);
-G_END_DECLS
-
-#endif
diff --git a/src/xfpm-lid-hal.c b/src/xfpm-lid-hal.c
new file mode 100644
index 00000000..5a51a006
--- /dev/null
+++ b/src/xfpm-lid-hal.c
@@ -0,0 +1,206 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "libxfpm/hal-ctx.h"
+#include "libxfpm/xfpm-string.h"
+
+#include "xfpm-lid-hal.h"
+
+/* Init */
+static void xfpm_lid_hal_class_init (XfpmLidHalClass *klass);
+static void xfpm_lid_hal_init       (XfpmLidHal *lid);
+static void xfpm_lid_hal_finalize   (GObject *object);
+
+#define XFPM_LID_HAL_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_LID_HAL, XfpmLidHalPrivate))
+
+struct XfpmLidHalPrivate
+{
+    HalCtx   *ctx;
+    
+    //gchar    *udi;
+    gboolean  hw_found;
+};
+
+enum
+{
+    LID_CLOSED,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE(XfpmLidHal, xfpm_lid_hal, G_TYPE_OBJECT)
+
+static void
+xfpm_lid_hal_class_init(XfpmLidHalClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+
+    signals[LID_CLOSED] = 
+        g_signal_new("lid-closed",
+                      XFPM_TYPE_LID_HAL,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET(XfpmLidHalClass, lid_closed),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__VOID,
+                      G_TYPE_NONE, 0, G_TYPE_NONE);
+		      
+    object_class->finalize = xfpm_lid_hal_finalize;
+
+
+    g_type_class_add_private(klass,sizeof(XfpmLidHalPrivate));
+}
+
+static void
+xfpm_lid_hal_init (XfpmLidHal *lid)
+{
+    lid->priv = XFPM_LID_HAL_GET_PRIVATE(lid);
+    
+    lid->priv->ctx      = NULL;
+    lid->priv->hw_found = FALSE;
+}
+
+static void
+xfpm_lid_hal_finalize(GObject *object)
+{
+    XfpmLidHal *lid;
+
+    lid = XFPM_LID_HAL(object);
+    
+    if ( lid->priv->ctx )
+    	g_object_unref (lid->priv->ctx);
+
+    G_OBJECT_CLASS(xfpm_lid_hal_parent_class)->finalize(object);
+}
+
+static void
+xfpm_lid_property_modified_cb (LibHalContext *ctx,
+			       const gchar *udi,
+                               const gchar *key, 
+                               dbus_bool_t is_removed,
+                               dbus_bool_t is_added)
+{
+    if ( !xfpm_strequal (key, "button.state.value") )
+    	return;
+	
+    TRACE("Property modified key=%s  key=%s\n", key, udi);
+    XfpmLidHal *lid = libhal_ctx_get_user_data (ctx);
+    
+    gboolean pressed = hal_ctx_get_property_bool (lid->priv->ctx, udi, key);
+    
+    if ( pressed )
+    {
+	TRACE("Emitting signal lid closed");
+	g_signal_emit ( G_OBJECT(lid), signals[LID_CLOSED], 0);
+    }
+    
+}
+
+static gboolean
+xfpm_lid_hal_setup (XfpmLidHal *lid)
+{
+    lid->priv->ctx = hal_ctx_new ();
+    
+    if ( !hal_ctx_connect(lid->priv->ctx) )
+    	return FALSE;
+
+    gchar **udi = NULL;
+    gint num = 0;
+    
+    udi = hal_ctx_get_device_by_capability (lid->priv->ctx, "button", &num );
+    
+    if ( !udi )
+    	return FALSE;
+	
+    hal_ctx_set_device_property_callback (lid->priv->ctx, xfpm_lid_property_modified_cb);
+    hal_ctx_set_user_data (lid->priv->ctx, lid);
+    
+    int i;
+    
+    for ( i = 0; udi[i]; i++ )
+    {
+	if ( hal_ctx_device_has_key (lid->priv->ctx, udi[i], "button.type" ) &&
+	     hal_ctx_device_has_key (lid->priv->ctx, udi[i], "button.has_state" ) )
+    	{
+	    gchar *button_type =
+	    	hal_ctx_get_property_string (lid->priv->ctx, udi[i], "button.type");
+		
+	    if ( !button_type )
+	    	continue;
+		
+	    if ( xfpm_strequal (button_type, "lid") )
+	    {
+	    	lid->priv->hw_found = TRUE;
+		hal_ctx_watch_device (lid->priv->ctx, udi[i] );
+		g_free(button_type);
+		TRACE ("Found lid switch on device: %s\n", udi[i]);
+		goto out;
+	    }
+	}
+    }
+        
+out:
+    libhal_free_string_array (udi);
+    return TRUE;
+}
+
+XfpmLidHal *
+xfpm_lid_hal_new(void)
+{
+    XfpmLidHal *lid = NULL;
+    lid = g_object_new (XFPM_TYPE_LID_HAL, NULL);
+    
+    if ( !xfpm_lid_hal_setup (lid) )
+    	goto out;
+	
+	
+out:
+    return lid;
+}
+
+gboolean xfpm_lid_hw_found (XfpmLidHal *lid)
+{
+    g_return_val_if_fail (XFPM_IS_LID_HAL(lid), FALSE);
+    
+    return lid->priv->hw_found;
+    
+}
diff --git a/src/xfpm-lid-hal.h b/src/xfpm-lid-hal.h
new file mode 100644
index 00000000..8e076835
--- /dev/null
+++ b/src/xfpm-lid-hal.h
@@ -0,0 +1,55 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_LID_HAL_H
+#define __XFPM_LID_HAL_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_LID_HAL        (xfpm_lid_hal_get_type () )
+#define XFPM_LID_HAL(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_LID_HAL, XfpmLidHal))
+#define XFPM_IS_LID_HAL(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_LID_HAL))
+
+typedef struct XfpmLidHalPrivate XfpmLidHalPrivate;
+
+typedef struct
+{
+    GObject		  parent;
+    XfpmLidHalPrivate	 *priv;
+    
+} XfpmLidHal;
+
+typedef struct
+{
+    GObjectClass          parent_class;
+    
+    void                 (*lid_closed) 	       (XfpmLidHal *lid);
+    
+} XfpmLidHalClass;
+
+GType        	  xfpm_lid_hal_get_type        (void) G_GNUC_CONST;
+XfpmLidHal       *xfpm_lid_hal_new             (void);
+gboolean          xfpm_lid_hw_found            (XfpmLidHal *lid);
+
+G_END_DECLS
+
+#endif /* __XFPM_LID_HAL_H */
diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index ad411398..5c610f19 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -1,6 +1,5 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@xfce.org>
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -16,7 +15,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifdef HAVE_CONFIG_H
@@ -24,60 +23,33 @@
 #endif
 
 #include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
 #include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <gtk/gtk.h>
-
 #include <glib.h>
-#include <glib/gstdio.h>
 
 #include <libxfce4util/libxfce4util.h>
-#include <libxfcegui4/libxfcegui4.h>
 
+#include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
-#include "xfpm-driver.h"
-#include "xfpm-hal.h"
-#include "xfpm-dbus-messages.h"
-#include "xfpm-popups.h"
-#include "xfpm-debug.h"
+#include "libxfpm/xfpm-dbus.h"
+#include "libxfpm/xfpm-popups.h"
 
 #include "xfce-power-manager-dbus-client.h"
-
-static gboolean run     = FALSE;
-static gboolean quit    = FALSE;
-static gboolean config  = FALSE;
-static gboolean version = FALSE;
-
-static GOptionEntry option_entries[] = {
-    { "run",'r', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,&run,NULL,NULL },
-	{ "customize", 'c', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &config, N_("Show the configuration dialog"), NULL },
-	{ "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &quit, N_("Quit any running xfce power manager"), NULL },
-    { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version, N_("Version information"), NULL },
-    { NULL, },
-};
+#include "xfpm-manager.h"
 
 static void
 show_version()
 {
-	g_print (_("\n"
+    g_print (_("\n"
              "Xfce Power Manager %s\n\n"
              "Part of the Xfce Goodies Project\n"
              "http://goodies.xfce.org\n\n"
              "Licensed under the GNU GPL.\n\n"), VERSION);
-}			 
-	
+}
+
 static void
 autostart()
 {
@@ -93,22 +65,18 @@ autostart()
         return;
     }
     
-    gchar *dir_file;
-    
-    dir_file = g_strdup_printf("%s/.config/autostart", home);
+    gchar *file;
+    file = g_strdup_printf("%s/.config/autostart",home);
     
-    if ( !g_file_test(dir_file,G_FILE_TEST_IS_DIR) )
+    if ( !g_file_test(file,G_FILE_TEST_IS_DIR) )
     {
-        g_mkdir_with_parents(dir_file, 0700);
+        g_mkdir_with_parents(file,0700);
     }
     
-    gchar *file;
-    file = g_strdup_printf("%s/xfce4-power-manager.desktop",dir_file);
-    g_free(dir_file);
+    file = g_strdup_printf("%s/xfce4-power-manager.desktop",file);
     
     if ( g_file_test(file,G_FILE_TEST_EXISTS) )
     {
-        XFPM_DEBUG("xfce4 power manager autostart.desktop file already exists\n");
         g_free(file);
         return;
     }
@@ -153,12 +121,26 @@ autostart()
     g_key_file_free(key);
 }
 
-int main(int argc,char **argv) 
+int main(int argc, char **argv)
 {
     xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
 
-    GError *error = NULL;
+    static gboolean run     = FALSE;
+    static gboolean quit    = FALSE;
+    static gboolean config  = FALSE;
+    static gboolean version = FALSE;
 
+    static GOptionEntry option_entries[] = 
+    {
+	{ "run",'r', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,&run,NULL,NULL },
+	{ "customize", 'c', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &config, N_("Show the configuration dialog"), NULL },
+	{ "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &quit, N_("Quit any running xfce power manager"), NULL },
+	{ "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version, N_("Version information"), NULL },
+	{ NULL, },
+    };
+
+    GError *error = NULL;
+    
     if(!gtk_init_with_args(&argc, &argv, "", option_entries, PACKAGE, &error)) 
     {
         if(G_LIKELY(error)) 
@@ -171,125 +153,106 @@ int main(int argc,char **argv)
         else
         {
             g_error("Unable to open display.");
-		}
+	}
 
         return EXIT_FAILURE;
     }
     
-    if ( version )    {
-		show_version();
+    if ( version )    
+    {
+	show_version();
     	return EXIT_SUCCESS;
-	}
-
-	if ( run + quit + config + version > 1 )
-	{
-		g_printerr(_("Too many arguments"));
-		g_printerr("\n");
-		g_printerr(_("Type '%s --help' for usage."), G_LOG_DOMAIN);
-		g_printerr("\n");
-		return EXIT_FAILURE;
-	}
-	
-	DBusGConnection *bus;
-	
-	bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
-	
-	if ( error )
-	{
-	    xfpm_popup_message(_("Xfce power manager"),
-                                  _("Unable to run Xfce4 power manager, " \
-                                  "make sure the hardware abstract layer and the message bus daemon "\
-                                  "are running"),
-                                  GTK_MESSAGE_ERROR);
-        g_error(_("Unable to load xfce4 power manager"));
-        g_print("\n");
+    }
+    
+    if ( run + quit + config + version > 1 )
+    {
+	g_printerr(_("Too many arguments"));
+	g_printerr("\n");
+	g_printerr(_("Type '%s --help' for usage."), G_LOG_DOMAIN);
+	g_printerr("\n");
+	return EXIT_FAILURE;
+    }
+    
+    DBusGConnection *bus;
+    bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+    
+    if ( error )
+    {
+	gchar *message = g_strdup(_("Unable to connection to the message bus session"));
+	message = g_strdup_printf("%s: ",error->message);
+	xfpm_popup_message(_("Xfce power manager"),
+			   message,
+			   GTK_MESSAGE_ERROR);
+	g_error("%s: \n",message);
+	g_print("\n");
 	g_error_free(error);
-        return EXIT_FAILURE;        
-	}
+	g_free(message);
 	
-	if ( config )
-	{
-	    if (!xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager"))
-	    {
-            	g_print(_("Xfce power manager is not running"));
-			g_print("\n");
-   	         gboolean ret = 
-        	    xfce_confirm(_("Xfce4 Power Manager is not running, do you want to launch it now?"),
-                	        GTK_STOCK_YES,
-                        	_("Run"));
-		if ( ret ) 
-		{
-		    g_spawn_command_line_async("xfce4-power-manager",NULL);
-		}
-		return EXIT_SUCCESS;
-	    }
-	    else
-	    {
-	        g_spawn_command_line_async("xfce4-power-manager-settings", NULL);
-	        return EXIT_SUCCESS;
-	    }
-	}     
-	 
-	if ( quit )
+	return EXIT_FAILURE;
+    }
+    
+    if ( quit )
     {
-        if (!xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus),  "org.xfce.PowerManager"))
+	if (!xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), 
+				      "org.xfce.PowerManager") )
         {
             g_print(_("Xfce power manager is not running"));
 	    g_print("\n");
             return EXIT_SUCCESS;
         }
-        else
-        {
+	else
+	{
 	    GError *error = NULL;
 	    DBusGProxy *proxy = dbus_g_proxy_new_for_name(bus, 
 							  "org.xfce.PowerManager",
 							  "/org/xfce/PowerManager",
 							  "org.xfce.Power.Manager");
-							  
 	    if ( !proxy ) 
 	    {
 		g_critical ("Failed to get proxy");
 		dbus_g_connection_unref(bus);
-            	return EXIT_SUCCESS;
+            	return EXIT_FAILURE;
 	    }
+	    xfpm_manager_dbus_client_quit(proxy , &error);
+	    g_object_unref (proxy);
 	    
-	    xfpm_driver_dbus_client_quit(proxy , &error);
-	    
-	    if ( error )
+	    if ( error)
 	    {
-		g_critical("Failed to sent quit message %s", error->message);
-		g_error_free(error);
+		g_critical ("Failed to send quit message %s:\n", error->message);
+		g_error_free (error);
 	    }
-	    
-	    g_object_unref(proxy);
-	    dbus_g_connection_unref(bus);
-            return EXIT_SUCCESS;
-        }
-    }    
+	}
+	return EXIT_SUCCESS;
+    }
     
-    if (!xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus),  "org.xfce.PowerManager") )
+    if ( config )
     {
-        XfpmDriver *driver = xfpm_driver_new(bus);
-        autostart();
-        if (!xfpm_driver_monitor(driver)) 
-        {
-            xfpm_popup_message(_("Xfce power manager"),
-                              _("Unable to run Xfce4 power manager, " \
-                              "make sure the hardware abstract layer and the message bus daemon "\
-                              "are running"),
-                              GTK_MESSAGE_ERROR);
-            g_error(_("Unable to load xfce4 power manager"));
-            g_print("\n");
-            g_object_unref(driver);
-            return EXIT_FAILURE;
-        }
+	if (!xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), 
+				      "org.xfce.PowerManager"))
+	{
+	    g_print (_("Xfce power manager is not running"));
+	    g_print ("\n");
+	    /* FIXME: dialog to run */
+	}
+	return EXIT_SUCCESS;
     }
-    else
+    
+    
+    if (xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), 
+				      "org.xfce.PowerManager"))
     {
-        g_print(_("Xfce power manager is already running"));
-        g_print("\n");
-        return EXIT_SUCCESS;
+	g_print (_("Xfce power manager is already running"));
+	g_print ("\n");
+    	return EXIT_SUCCESS;
     }
-	    
+    else
+    {	
+	TRACE("Starting the power manager\n");
+	autostart();
+    	XfpmManager *manager;
+    	manager = xfpm_manager_new(bus);
+    	xfpm_manager_start(manager);
+    }
+    
     return EXIT_SUCCESS;
-}    
+}
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
new file mode 100644
index 00000000..a28b83d7
--- /dev/null
+++ b/src/xfpm-manager.c
@@ -0,0 +1,209 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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 <libxfce4util/libxfce4util.h>
+#include <xfconf/xfconf.h>
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "libxfpm/xfpm-string.h"
+#include "libxfpm/xfpm-dbus.h"
+
+#include "xfpm-manager.h"
+#include "xfpm-engine.h"
+
+/* Init */
+static void xfpm_manager_class_init (XfpmManagerClass *klass);
+static void xfpm_manager_init       (XfpmManager *xfpm_manager);
+static void xfpm_manager_finalize   (GObject *object);
+
+static void xfpm_manager_dbus_class_init (XfpmManagerClass *klass);
+static void xfpm_manager_dbus_init	 (XfpmManager *manager);
+
+#define XFPM_MANAGER_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_MANAGER, XfpmManagerPrivate))
+
+struct XfpmManagerPrivate
+{
+    XfpmEngine *engine;
+    
+    DBusGConnection *session_bus;
+    
+    GMainLoop *loop;
+};
+
+G_DEFINE_TYPE(XfpmManager, xfpm_manager, G_TYPE_OBJECT)
+
+static void
+xfpm_manager_class_init (XfpmManagerClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->finalize = xfpm_manager_finalize;
+
+    g_type_class_add_private(klass,sizeof(XfpmManagerPrivate));
+}
+
+static void
+xfpm_manager_init(XfpmManager *manager)
+{
+    manager->priv = XFPM_MANAGER_GET_PRIVATE(manager);
+
+    manager->priv->session_bus   = NULL;
+    manager->priv->loop          = g_main_loop_new(NULL, FALSE);
+}
+
+static void
+xfpm_manager_finalize(GObject *object)
+{
+    XfpmManager *manager;
+
+    manager = XFPM_MANAGER(object);
+
+    if ( manager->priv->session_bus )
+	dbus_g_connection_unref(manager->priv->session_bus);
+	
+    if ( manager->priv->loop ) 
+	g_main_loop_unref(manager->priv->loop);
+	
+    if ( manager->priv->engine )
+    	g_object_unref (manager->priv->engine);
+
+    G_OBJECT_CLASS(xfpm_manager_parent_class)->finalize(object);
+}
+
+static gboolean
+xfpm_manager_quit (XfpmManager *manager)
+{
+    g_main_loop_quit(manager->priv->loop);
+    xfpm_dbus_release_name(dbus_g_connection_get_connection(manager->priv->session_bus),
+			   "org.xfce.PowerManager");
+    
+    g_object_unref(G_OBJECT(manager));
+    return TRUE;
+}
+
+XfpmManager *
+xfpm_manager_new(DBusGConnection *bus)
+{
+    XfpmManager *manager = NULL;
+    manager = g_object_new(XFPM_TYPE_MANAGER,NULL);
+
+    manager->priv->session_bus = bus;
+    
+    xfpm_manager_dbus_class_init(XFPM_MANAGER_GET_CLASS(manager));
+    xfpm_manager_dbus_init(manager);
+    
+    return manager;
+}
+
+void xfpm_manager_start (XfpmManager *manager)
+{
+    if ( !xfpm_dbus_register_name(dbus_g_connection_get_connection(manager->priv->session_bus),
+				  "org.xfce.PowerManager") ) 
+    {
+	g_critical("Unable to reserve bus name\n");
+    }
+    
+    manager->priv->engine = xfpm_engine_new ();
+    
+    g_main_loop_run(manager->priv->loop);
+}
+
+/*
+ * 
+ * DBus server implementation
+ * 
+ */
+static gboolean xfpm_manager_dbus_quit     (XfpmManager *manager,
+					    GError **error);
+static gboolean xfpm_manager_dbus_get_all  (XfpmManager *manager,
+					    GHashTable **OUT_hash,
+					    GError **error);
+static gboolean xfpm_manager_dbus_get_info (XfpmManager *manager,
+					    gchar **OUT_name,
+					    gchar **OUT_version,
+					    gchar **OUT_vendor,
+					    GError **error);
+
+#include "xfce-power-manager-dbus-server.h"
+
+static void
+xfpm_manager_dbus_class_init(XfpmManagerClass *klass)
+{
+     dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(klass),
+				    &dbus_glib_xfpm_manager_object_info);
+}
+
+static void
+xfpm_manager_dbus_init(XfpmManager *manager)
+{
+    dbus_g_connection_register_g_object(manager->priv->session_bus,
+					"/org/xfce/PowerManager",
+					G_OBJECT(manager));
+}
+
+static gboolean
+xfpm_manager_dbus_quit(XfpmManager *manager, GError **error)
+{
+    TRACE("Quit message received\n");
+    
+    xfpm_manager_quit(manager);
+    
+    return TRUE;
+}
+
+static gboolean
+xfpm_manager_dbus_get_all(XfpmManager *manager, 
+			  GHashTable **OUT_hash, 
+			  GError **error)
+{
+    TRACE("Get all message received\n");
+
+   *OUT_hash = g_hash_table_new(g_str_hash, g_str_equal);
+    
+    return TRUE;
+}
+
+static gboolean 
+xfpm_manager_dbus_get_info (XfpmManager *manager,
+			    gchar **OUT_name,
+			    gchar **OUT_version,
+			    gchar **OUT_vendor,
+			    GError **error)
+{
+    
+    *OUT_name    = g_strdup(PACKAGE);
+    *OUT_version = g_strdup(VERSION);
+    *OUT_vendor  = g_strdup("Xfce-goodies");
+    
+    return TRUE;
+}
diff --git a/src/xfpm-manager.h b/src/xfpm-manager.h
new file mode 100644
index 00000000..e1771e69
--- /dev/null
+++ b/src/xfpm-manager.h
@@ -0,0 +1,55 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_MANAGER_H
+#define __XFPM_MANAGER_H
+
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_MANAGER          (xfpm_manager_get_type () )
+#define XFPM_MANAGER(o)            (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_MANAGER, XfpmManager))
+#define XFPM_IS_MANAGER(o)         (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_MANAGER))
+#define XFPM_MANAGER_GET_CLASS(k)  (G_TYPE_INSTANCE_GET_CLASS((k), XFPM_TYPE_MANAGER, XfpmManagerClass))
+
+typedef struct XfpmManagerPrivate XfpmManagerPrivate;
+
+typedef struct
+{
+    GObject		  parent;
+    XfpmManagerPrivate	 *priv;
+    
+} XfpmManager;
+
+typedef struct
+{
+    GObjectClass parent_class;
+    
+} XfpmManagerClass;
+
+GType        	xfpm_manager_get_type        (void) G_GNUC_CONST;
+XfpmManager    *xfpm_manager_new             (DBusGConnection *bus);
+void            xfpm_manager_start           (XfpmManager *manager);
+
+G_END_DECLS
+
+#endif /* __XFPM_MANAGER_H */
diff --git a/src/xfpm-marshal.list b/src/xfpm-marshal.list
index eb366201..596b3c49 100644
--- a/src/xfpm-marshal.list
+++ b/src/xfpm-marshal.list
@@ -1,8 +1 @@
-VOID:INT,INT,INT
-VOID:STRING,STRING
-VOID:STRING,STRING,STRING
-VOID:STRING,STRING,BOOLEAN,BOOLEAN
-VOID:ENUM,BOOLEAN
-VOID:BOOLEAN,BOOLEAN
-
-
+VOID:POINTER,UINT,UINT,UINT
diff --git a/src/xfpm-network-manager.c b/src/xfpm-network-manager.c
new file mode 100644
index 00000000..7c43e9ab
--- /dev/null
+++ b/src/xfpm-network-manager.c
@@ -0,0 +1,62 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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 <glib.h>
+#include <dbus/dbus-glib.h>
+
+/*
+ * Inform the Network Manager when we do suspend/hibernate 
+ * message is either "wake" or "sleep"
+ */
+gboolean 	xfpm_send_message_to_network_manager  	(const gchar *message)
+{
+    DBusGConnection *bus   = NULL;
+    DBusGProxy      *proxy = NULL;
+    GError          *error = NULL;
+    
+    bus = dbus_g_bus_get ( DBUS_BUS_SYSTEM, &error);
+    if ( error )
+    {
+	g_warning("%s", error->message);
+	g_error_free (error);
+	return FALSE;
+    }
+    
+    
+    proxy = dbus_g_proxy_new_for_name (bus,
+				       "org.freedesktop.NetworkManager",
+				       "/org/freedesktop/NetworkManager",
+				       "org.freedesktop.NetworkManager");
+				       
+    if (!proxy)
+    {
+	g_critical ("Failed to create proxy for Network Manager interface");
+	return FALSE;
+    }
+    
+    dbus_g_proxy_call_no_reply (proxy, message, G_TYPE_INVALID);
+    g_object_unref (G_OBJECT(proxy));
+    
+    return TRUE;
+}
diff --git a/src/xfpm-network-manager.h b/src/xfpm-network-manager.h
new file mode 100644
index 00000000..0b680d46
--- /dev/null
+++ b/src/xfpm-network-manager.h
@@ -0,0 +1,30 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_NETWORK_MANAGER_H
+#define __XFPM_NETWORK_MANAGER_H
+
+G_BEGIN_DECLS
+
+gboolean 	xfpm_send_message_to_network_manager 	(const gchar *message);
+
+G_END_DECLS
+
+#endif /*__XFPM_NETWORK_MANAGER_H */
diff --git a/src/xfpm-notify.c b/src/xfpm-notify.c
index 586fe7ed..0b1e51c4 100644
--- a/src/xfpm-notify.c
+++ b/src/xfpm-notify.c
@@ -1,6 +1,5 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -16,82 +15,152 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "xfpm-common.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+
+#include <libnotify/notify.h>
+
+#include "libxfpm/xfpm-common.h"
+
 #include "xfpm-notify.h"
 
-#ifdef HAVE_LIBNOTIFY
+/* Init */
+static void xfpm_notify_class_init (XfpmNotifyClass *klass);
+static void xfpm_notify_init       (XfpmNotify *notify);
+static void xfpm_notify_finalize   (GObject *object);
+
+#define XFPM_NOTIFY_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_NOTIFY, XfpmNotifyPrivate))
+
+struct XfpmNotifyPrivate
+{
+    NotifyNotification *notification;
+};
+
+G_DEFINE_TYPE(XfpmNotify, xfpm_notify, G_TYPE_OBJECT)
+
+static void
+xfpm_notify_class_init(XfpmNotifyClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->finalize = xfpm_notify_finalize;
+
+
+    g_type_class_add_private(klass,sizeof(XfpmNotifyPrivate));
+}
+
+static void
+xfpm_notify_init(XfpmNotify *notify)
+{
+    notify->priv = XFPM_NOTIFY_GET_PRIVATE(notify);
+    
+    notify->priv->notification = NULL;
+        
+    notify_init ("xfce4-power-manager");
+}
+
+static void
+xfpm_notify_finalize(GObject *object)
+{
+    XfpmNotify *notify;
+
+    notify = XFPM_NOTIFY(object);
+    
+    G_OBJECT_CLASS(xfpm_notify_parent_class)->finalize(object);
+}
+
 static NotifyNotification *
-xfpm_notify_create_notification(const char *title,const char *message,
-                                const gchar *icon_name,GtkStatusIcon *icon)
+xfpm_notify_new_notification_internal (XfpmNotify *notify, const gchar *title, const gchar *message)
 {
     NotifyNotification *n;
-    if ( icon != NULL ) 
-	{
-	    n = notify_notification_new_with_status_icon(title,message,NULL,icon);
-	}
-	else
-	{
-	    n = notify_notification_new(title,message,NULL,NULL);
-	}
-    if ( icon_name != NULL ) {
-        GdkPixbuf *pixbuf = xfpm_load_icon(icon_name,48);	
-        if (pixbuf) 
-        {
-            notify_notification_set_icon_from_pixbuf(n,pixbuf);
-            g_object_unref(G_OBJECT(pixbuf));
-        }    
-    }		
-	return n;
+    
+    n = notify_notification_new (title, message, NULL, NULL);
+    
+    return n;
 }
 
-static gboolean
-xfpm_notify_send_notification(gpointer data)
+static void
+xfpm_notify_set_icon (XfpmNotify *notify, NotifyNotification *n, const gchar *icon_name )
 {
-    NotifyNotification *n = data;
-    notify_notification_show(n,NULL);	
-	return FALSE;
+    GdkPixbuf *pix = xfpm_load_icon (icon_name, 48);
+    
+    if ( pix )
+    {
+	notify_notification_set_icon_from_pixbuf (n, 
+						  pix);
+	g_object_unref ( G_OBJECT(pix));
+    }
 }
 
-NotifyNotification * 
-xfpm_notify_new(const gchar *title,const gchar *message,
-                guint timeout,NotifyUrgency urgency,
-                GtkStatusIcon *icon,const gchar *icon_name) 
+static void
+xfpm_notify_closed_cb (NotifyNotification *n, XfpmNotify *notify)
 {
+    notify->priv->notification = NULL;
+    g_object_unref (G_OBJECT(n));
+}
+
+static void
+xfpm_notify_close_notification (XfpmNotify *notify )
+{
+    if ( notify->priv->notification )
+    {
+    	if (!notify_notification_close (notify->priv->notification, NULL))
+	    g_warning ("Failed to close notification\n");
 	
-	NotifyNotification *n;
-	n = xfpm_notify_create_notification(title,message,icon_name,icon);
-	    
-	notify_notification_set_urgency(n,urgency);
-	notify_notification_set_timeout(n,timeout);
-	return n;
-	
-}	
+	g_object_unref (G_OBJECT(notify->priv->notification) );
+	notify->priv->notification  = NULL;
+    }
+}
 
-void xfpm_notify_add_action(NotifyNotification *n,
-                            const gchar *action_id,
-                            const gchar *action_label,
-                            NotifyActionCallback notify_callback,
-                            gpointer user_data) 
+XfpmNotify *
+xfpm_notify_new(void)
 {
-    notify_notification_add_action(n,action_id,action_label,
-								  (NotifyActionCallback)notify_callback,
-								  user_data,NULL);
+    XfpmNotify *notify = NULL;
+    notify = g_object_new (XFPM_TYPE_NOTIFY, NULL);
+    return notify;
 }
-							     
-void xfpm_notify_show_notification(NotifyNotification *n,guint timeout_to_show)
+
+void xfpm_notify_show_notification (XfpmNotify *notify, const gchar *title,
+				    const gchar *text,  const gchar *icon_name,
+				    gint timeout, XfpmNotifyUrgency urgency, 
+				    GtkStatusIcon *icon)
 {
-    if ( timeout_to_show != 0 )
-	{
-	    g_timeout_add_seconds(timeout_to_show,
-                              xfpm_notify_send_notification,
-                              n);
-    }
-    else
-    {
-        xfpm_notify_send_notification(n);
-    }			
+    xfpm_notify_close_notification (notify);
+    
+    notify->priv->notification = 
+    	xfpm_notify_new_notification_internal (notify, title, text);
+    
+    if ( icon_name )
+    	xfpm_notify_set_icon (notify, notify->priv->notification, icon_name);
+	
+    if ( icon )
+    	notify_notification_attach_to_status_icon (notify->priv->notification, icon);
+
+    g_signal_connect (G_OBJECT(notify->priv->notification),"closed",
+		      G_CALLBACK(xfpm_notify_closed_cb), notify);
+		      
+    notify_notification_show (notify->priv->notification, NULL);
+    
 }
-#endif
diff --git a/src/xfpm-notify.h b/src/xfpm-notify.h
index 69d91ca3..e4e65ad2 100644
--- a/src/xfpm-notify.h
+++ b/src/xfpm-notify.h
@@ -1,6 +1,5 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -16,36 +15,56 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifndef __XFPM_NOTIFY_H
 #define __XFPM_NOTIFY_H
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_LIBNOTIFY
-#include <libnotify/notify.h>
+#include <glib-object.h>
 #include <gtk/gtk.h>
 
-NotifyNotification *  xfpm_notify_new(const gchar *title,
-                                      const gchar *message,
-                                      guint timeout,
-                                      NotifyUrgency urgency,
-                                      GtkStatusIcon *icon,
-                                      const gchar *icon_name);
-                                      
-void xfpm_notify_add_action(NotifyNotification *n,
-                            const gchar *action_id,
-                            const gchar *action_label,
-                            NotifyActionCallback notify_callback,
-                            gpointer user_data) ;
-                            
-void xfpm_notify_show_notification(NotifyNotification *n,
-                                   guint timeout_to_show);
-                            
-#endif /* HAVE_LIBNOTIFY */
-
-#endif /*__XFPM_NOTIFY_H */
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_NOTIFY        (xfpm_notify_get_type () )
+#define XFPM_NOTIFY(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_NOTIFY, XfpmNotify))
+#define XFPM_IS_NOTIFY(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_NOTIFY))
+
+typedef enum 
+{
+    XFPM_NOTIFY_CRITICAL,
+    XFPM_NOTIFY_NORMAL,
+    XFPM_NOTIFY_LOW
+    
+} XfpmNotifyUrgency;
+
+typedef struct XfpmNotifyPrivate XfpmNotifyPrivate;
+
+typedef struct
+{
+    GObject		  parent;
+    XfpmNotifyPrivate	 *priv;
+    
+} XfpmNotify;
+
+typedef struct
+{
+    GObjectClass          parent_class;
+    
+} XfpmNotifyClass;
+
+GType        	 xfpm_notify_get_type          (void) G_GNUC_CONST;
+XfpmNotify      *xfpm_notify_new               (void);
+
+void             xfpm_notify_show_notification (XfpmNotify *notify,
+						const gchar *title,
+						const gchar *text,
+						const gchar *icon_name,
+						gint timeout,
+						XfpmNotifyUrgency urgency,
+						GtkStatusIcon *icon);
+
+
+G_END_DECLS
+
+#endif /* __XFPM_NOTIFY_H */
diff --git a/src/xfpm-settings.c b/src/xfpm-settings.c
deleted file mode 100644
index 66f5548d..00000000
--- a/src/xfpm-settings.c
+++ /dev/null
@@ -1,1324 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <aliov@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#include <gtk/gtk.h>
-
-#include <xfconf/xfconf.h>
-#include <libxfce4util/libxfce4util.h>
-#include <libxfcegui4/libxfcegui4.h>
-
-#include "xfpm-settings.h"
-#include "xfpm-enums.h"
-#include "xfpm-common.h"
-#include "xfpm-spin-button.h"
-
-#ifdef HAVE_DPMS
-#include "xfpm-dpms-spins.h"
-#endif
-
-#define BORDER 8
-#define SPACING 2
-
-/// Global Variable ///
-static GtkWidget *nt;
-
-static GtkWidget *cpu_gov;
-static GtkWidget *performance_on_ac;
-static GtkWidget *ondemand_on_ac;
-static GtkWidget *powersave_on_ac;
-static GtkWidget *conservative_on_ac;
-
-static GtkWidget *performance_on_batt;
-static GtkWidget *ondemand_on_batt;
-static GtkWidget *powersave_on_batt;
-static GtkWidget *conservative_on_batt;
-
-#ifdef HAVE_DPMS
-static GtkWidget *dpms_op;
-static GtkWidget *on_batt_dpms;
-static GtkWidget *on_ac_dpms;
-#endif
-
-/// Callback Setting Functions ///
-static void
-set_show_tray_icon_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    gboolean value = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-
-    if(!xfconf_channel_set_uint(channel,SHOW_TRAY_ICON_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",SHOW_TRAY_ICON_CFG);
-    }
-}
-
-static void
-set_battery_critical_charge_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    guint value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
-
-    if(!xfconf_channel_set_uint(channel,CRITICAL_BATT_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",CRITICAL_BATT_CFG);
-    }
-}
-
-static void
-set_critical_action_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    guint value = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-
-    if(!xfconf_channel_set_uint(channel,CRITICAL_BATT_ACTION_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",CRITICAL_BATT_ACTION_CFG);
-    }
-}
-
-static void
-set_power_button_action_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    guint value = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-
-    if(!xfconf_channel_set_uint(channel,POWER_SWITCH_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",POWER_SWITCH_CFG);
-    }
-}
-
-static void
-set_sleep_button_action_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    guint value = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-
-    if(!xfconf_channel_set_uint(channel,SLEEP_SWITCH_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",SLEEP_SWITCH_CFG);
-    }
-}
-
-static void
-set_lid_button_action_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    guint value = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-
-    if(!xfconf_channel_set_uint(channel,LID_SWITCH_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",LID_SWITCH_CFG);
-    }
-}
-
-static void
-set_power_save_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    gboolean value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-
-    if(!xfconf_channel_set_bool(channel,POWER_SAVE_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",POWER_SAVE_CFG);
-    }
-}
-
-#ifdef HAVE_LIBNOTIFY
-static void
-set_battery_state_notification_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    gboolean value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-
-    if(!xfconf_channel_set_bool(channel,BATT_STATE_NOTIFICATION_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",BATT_STATE_NOTIFICATION_CFG);
-    }
-}
-#endif
-
-static void
-set_lcd_brightness_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    gboolean value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-
-    if(!xfconf_channel_set_bool(channel,LCD_BRIGHTNESS_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",LCD_BRIGHTNESS_CFG);
-    }
-}
-
-#ifdef HAVE_DPMS
-static void
-set_dpms_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    gboolean value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-
-    if(!xfconf_channel_set_bool(channel,DPMS_ENABLE_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",DPMS_ENABLE_CFG);
-    }
-
-    xfpm_dpms_spins_set_active(XFPM_DPMS_SPINS(on_ac_dpms),value);
-
-    if ( GTK_IS_WIDGET(on_batt_dpms) )
-    {
-        xfpm_dpms_spins_set_active(XFPM_DPMS_SPINS(on_batt_dpms),value);
-    }
-}
-
-static void
-set_dpms_on_battery_cb(GtkWidget *spin,guint value1,guint value2,
-                      guint value3,XfconfChannel *channel)
-{
-    GPtrArray *arr = g_ptr_array_sized_new(3);
-    GValue *val;
-
-    val = g_new0(GValue, 1);
-    g_value_init(val, G_TYPE_UINT);
-    g_value_set_uint(val, value1);
-    g_ptr_array_add(arr, val);
-
-    val = g_new0(GValue, 1);
-    g_value_init(val, G_TYPE_UINT);
-    g_value_set_uint(val, value2);
-    g_ptr_array_add(arr, val);
-
-    val = g_new0(GValue, 1);
-    g_value_init(val, G_TYPE_UINT);
-    g_value_set_uint(val, value3);
-    g_ptr_array_add(arr, val);
-
-    if (!xfconf_channel_set_arrayv(channel,
-                                  ON_BATT_DPMS_TIMEOUTS_CFG,
-                                  arr) )
-    {
-        g_critical("Cannot set value for %s \n",ON_BATT_DPMS_TIMEOUTS_CFG);
-        xfconf_array_free(arr);
-        return;
-    }
-    xfconf_array_free(arr);
-}
-
-static void
-set_dpms_on_ac_cb(GtkWidget *spin,guint value1,guint value2,
-                  guint value3,XfconfChannel *channel)
-{
-    GPtrArray *arr = g_ptr_array_sized_new(3);
-    GValue *val;
-
-    val = g_new0(GValue, 1);
-    g_value_init(val, G_TYPE_UINT);
-    g_value_set_uint(val, value1);
-    g_ptr_array_add(arr, val);
-
-    val = g_new0(GValue, 1);
-    g_value_init(val, G_TYPE_UINT);
-    g_value_set_uint(val, value2);
-    g_ptr_array_add(arr, val);
-
-    val = g_new0(GValue, 1);
-    g_value_init(val, G_TYPE_UINT);
-    g_value_set_uint(val, value3);
-    g_ptr_array_add(arr, val);
-
-    if (!xfconf_channel_set_arrayv(channel,
-                                  ON_AC_DPMS_TIMEOUTS_CFG,
-                                  arr) )
-    {
-        g_critical("Cannot set value %s \n",ON_AC_DPMS_TIMEOUTS_CFG);
-        xfconf_array_free(arr);
-        return;
-    }
-    xfconf_array_free(arr);
-}
-#endif
-
-static void
-set_cpu_freq_scaling_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    gboolean value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-
-    if(!xfconf_channel_set_bool(channel,CPU_FREQ_SCALING_CFG,value))
-    {
-        g_critical("Cannot set value %s\n",CPU_FREQ_SCALING_CFG);
-    }
-    if ( GTK_IS_WIDGET(ondemand_on_ac) )
-    {
-        gtk_widget_set_sensitive(ondemand_on_ac,value);
-        gtk_widget_set_sensitive(performance_on_ac,value);
-        gtk_widget_set_sensitive(powersave_on_ac,value);
-        gtk_widget_set_sensitive(conservative_on_ac,value);
-    }
-
-    if ( GTK_IS_WIDGET(ondemand_on_batt) )  /* enough to check only one widget */
-    {
-        gtk_widget_set_sensitive(ondemand_on_batt,value);
-        gtk_widget_set_sensitive(performance_on_batt,value);
-        gtk_widget_set_sensitive(powersave_on_batt,value);
-        gtk_widget_set_sensitive(conservative_on_batt,value);
-    }
-}
-
-static void
-set_powersave_on_ac_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    if(!xfconf_channel_set_uint(channel,ON_AC_CPU_GOV_CFG,POWERSAVE))
-    {
-        g_critical("Cannot set value %s\n",ON_AC_CPU_GOV_CFG);
-    }
-
-}
-
-static void
-set_ondemand_on_ac_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    if(!xfconf_channel_set_uint(channel,ON_AC_CPU_GOV_CFG,ONDEMAND))
-    {
-        g_critical("Cannot set value %s\n",ON_AC_CPU_GOV_CFG);
-    }
-
-}
-
-static void
-set_performance_on_ac_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    if(!xfconf_channel_set_uint(channel,ON_AC_CPU_GOV_CFG,PERFORMANCE))
-    {
-        g_critical("Cannot set value %s\n",ON_AC_CPU_GOV_CFG);
-    }
-
-}
-
-static void
-set_conservative_on_ac_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    if(!xfconf_channel_set_uint(channel,ON_AC_CPU_GOV_CFG,CONSERVATIVE))
-    {
-        g_critical("Cannot set value %s\n",ON_AC_CPU_GOV_CFG);
-    }
-
-}
-
-static void
-set_powersave_on_batt_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    if(!xfconf_channel_set_uint(channel,ON_BATT_CPU_GOV_CFG,POWERSAVE))
-    {
-        g_critical("Cannot set value %s\n",ON_BATT_CPU_GOV_CFG);
-    }
-
-}
-
-static void
-set_ondemand_on_batt_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    if(!xfconf_channel_set_uint(channel,ON_BATT_CPU_GOV_CFG,ONDEMAND))
-    {
-        g_critical("Cannot set value %s\n",ON_BATT_CPU_GOV_CFG);
-    }
-
-}
-
-static void
-set_performance_on_batt_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    if(!xfconf_channel_set_uint(channel,ON_BATT_CPU_GOV_CFG,PERFORMANCE))
-    {
-        g_critical("Cannot set value %s\n",ON_BATT_CPU_GOV_CFG);
-    }
-
-}
-
-static void
-set_conservative_on_batt_cb(GtkWidget *widget,XfconfChannel *channel)
-{
-    if(!xfconf_channel_set_uint(channel,ON_BATT_CPU_GOV_CFG,CONSERVATIVE))
-    {
-        g_critical("Cannot set value %s\n",ON_BATT_CPU_GOV_CFG);
-    }
-
-}
-
-/// End of Callback Setting Functions ///
-
-static XfpmActionRequest
-_combo_helper_function(XfconfChannel *channel,const gchar *config,
-                       guint8 power_management,XfpmActionRequest action)
-{
-    if( power_management == 0 && action != XFPM_DO_NOTHING )
-    {
-        xfconf_channel_set_uint(channel,config,XFPM_DO_NOTHING);
-        return XFPM_DO_NOTHING;
-    }
-
-    if( !(power_management & SYSTEM_CAN_SUSPEND)  && action == XFPM_DO_SUSPEND )
-    {
-        xfconf_channel_set_uint(channel,config,XFPM_DO_NOTHING);
-        return XFPM_DO_NOTHING;
-    }
-
-    if( !(power_management & SYSTEM_CAN_HIBERNATE) && action == XFPM_DO_HIBERNATE )
-    {
-        xfconf_channel_set_uint(channel,config,XFPM_DO_NOTHING);
-        return XFPM_DO_NOTHING;
-    }
-
-    if ( action < XFPM_DO_NOTHING || action > XFPM_DO_SHUTDOWN )
-    {
-        xfconf_channel_set_uint(channel,config,XFPM_DO_NOTHING);
-        return XFPM_DO_NOTHING;
-    }
-    return action;
-}
-
-/// Settings frames ///
-static GtkWidget *
-xfpm_settings_battery(XfconfChannel *channel, guint8 power_management,gboolean ups_found)
-{
-    GtkWidget *table;
-    GtkWidget *frame,*align;
-    GtkWidget *label;
-    GtkWidget *critical_spin;
-    GtkWidget *action;
-    GtkWidget *w_align;
-    
-    table = gtk_table_new(4,2,FALSE);
-    gtk_widget_show(table);
-    frame = xfce_create_framebox(ups_found ? _("UPS configuration") :_("Battery configuration"), &align);
-    gtk_widget_show(frame);
-    gtk_container_set_border_width(GTK_CONTAINER(frame),BORDER);
-
-    w_align = gtk_alignment_new (0.0, 0.5, 0, 0);
-    gtk_widget_show(w_align);
-    
-    label = gtk_label_new(ups_found ? _("Consider UPS charge critical"):_("Consider battery charge critical"));
-    gtk_widget_show(label);
-    gtk_container_add(GTK_CONTAINER(w_align), label);
-    gtk_table_attach(GTK_TABLE(table),w_align,0,1,0,1,GTK_FILL,GTK_FILL,BORDER,SPACING);
-
-    critical_spin = xfpm_spin_button_new_with_range(1,20,1);
-    gchar *suffix = g_strdup_printf(" %s",_("percent"));
-    xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(critical_spin),suffix);
-    g_free(suffix);
-    gtk_widget_show(critical_spin);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(critical_spin),
-                              xfconf_channel_get_uint(channel,CRITICAL_BATT_CFG,10));
-    g_signal_connect(critical_spin,"value-changed",
-                    G_CALLBACK(set_battery_critical_charge_cb),channel);
-    gtk_table_attach(GTK_TABLE(table),critical_spin,1,2,0,1,GTK_FILL,GTK_FILL,BORDER,SPACING);
-
-    label = gtk_label_new(_("When battery charge level is critical do"));
-    gtk_widget_show(label);
-    w_align = gtk_alignment_new (0.0, 0.5, 0, 0);
-    gtk_widget_show(w_align);
-    
-    gtk_container_add(GTK_CONTAINER(w_align), label);
-    if ( !ups_found )
-        gtk_table_attach(GTK_TABLE(table),w_align,0,1,1,2,GTK_FILL,GTK_FILL,BORDER,SPACING);
-
-    action = gtk_combo_box_new_text();
-    gtk_combo_box_append_text(GTK_COMBO_BOX(action),_("Nothing"));
-    if ( power_management != 0 )
-    {
-        gtk_combo_box_append_text(GTK_COMBO_BOX(action),_("Shutdown"));
-    }
-    if ( power_management & SYSTEM_CAN_HIBERNATE )
-    {
-        gtk_combo_box_append_text(GTK_COMBO_BOX(action),_("Hibernate"));
-    }
-    guint active = xfconf_channel_get_uint(channel,CRITICAL_BATT_ACTION_CFG,XFPM_DO_NOTHING);
-    active = _combo_helper_function(channel,CRITICAL_BATT_ACTION_CFG,power_management,active);
-
-    gtk_combo_box_set_active(GTK_COMBO_BOX(action),active);
-
-    gtk_widget_show(action);
-    g_signal_connect(action,"changed",G_CALLBACK(set_critical_action_cb),channel);
-
-    !ups_found ? gtk_table_attach(GTK_TABLE(table),action,1,2,1,2,GTK_FILL,GTK_FILL,BORDER,SPACING) : gtk_widget_hide(action);
-
-#ifdef HAVE_LIBNOTIFY
-    GtkWidget *notify_bt;
-    notify_bt = gtk_check_button_new_with_label (ups_found ? _("Enable UPS charge notification") :_("Enable battery state notification") );
-    gtk_widget_show(notify_bt);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(notify_bt),
-                                 xfconf_channel_get_bool(channel,BATT_STATE_NOTIFICATION_CFG,TRUE));
-    g_signal_connect(notify_bt,"toggled",G_CALLBACK(set_battery_state_notification_cb),channel);
-    gtk_table_attach(GTK_TABLE(table),notify_bt,0,2,2,3,GTK_FILL,GTK_FILL,BORDER,SPACING);
-#endif
-    if ( power_management & SYSTEM_CAN_POWER_SAVE )
-    {
-        // Power Save Profile
-        GtkWidget *power_save;
-        power_save = gtk_check_button_new_with_label(ups_found ? _("Enable power save on UPS power") : _("Enable power save on battery power"));
-        gtk_widget_show(power_save);
-
-        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(power_save),
-                                     power_management & SYSTEM_CAN_POWER_SAVE ?
-                                     xfconf_channel_get_bool(channel,POWER_SAVE_CFG,FALSE)
-                                     : FALSE);
-
-        g_signal_connect(power_save,"toggled",G_CALLBACK(set_power_save_cb),channel);
-        gtk_table_attach(GTK_TABLE(table),power_save,0,2,2,3,GTK_SHRINK,GTK_SHRINK,SPACING, SPACING);
-    }
-
-    gtk_container_add(GTK_CONTAINER(align),table); //vbox);
-    return frame;
-
-}
-
-static GtkWidget *
-xfpm_settings_cpu_on_ac_adapter(XfconfChannel *channel,guint8 govs,const gchar *label)
-{
-    GtkWidget *frame;
-    GtkWidget *align;
-    GtkWidget *vbox;
-    
-    GSList *list;
-    guint current_governor = xfconf_channel_get_uint(channel,ON_AC_CPU_GOV_CFG,ONDEMAND);
-    gboolean enable = xfconf_channel_get_bool(channel,CPU_FREQ_SCALING_CFG,TRUE);
-    
-    frame = xfce_create_framebox(label, &align);
-    gtk_container_set_border_width(GTK_CONTAINER(frame),BORDER);
-    gtk_widget_show(frame);
-    
-    vbox = gtk_vbox_new(FALSE,BORDER);
-    gtk_widget_show(vbox);
-    gtk_container_add(GTK_CONTAINER(align),vbox);
-    
-    performance_on_ac = gtk_radio_button_new_with_label(NULL,_("Best performance"));
-	gtk_widget_set_tooltip_text(performance_on_ac,_("Set the CPU to its maximum frequency"));
-    gtk_box_pack_start (GTK_BOX (vbox), performance_on_ac, FALSE, FALSE, 0);
-    
-    list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(performance_on_ac));
-    
-    ondemand_on_ac = gtk_radio_button_new_with_label(list,_("Ondemand performance"));
-	gtk_widget_set_tooltip_text(ondemand_on_ac,_("Set the CPU to its maximum speed when there is any load on it "\
-												"and to its minimum speed when the system is idle"));
-    gtk_box_pack_start (GTK_BOX (vbox), ondemand_on_ac, FALSE, FALSE, 0);
-    list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(ondemand_on_ac));
-    
-    powersave_on_ac = gtk_radio_button_new_with_label(list,_("Best power savings"));
-	gtk_widget_set_tooltip_text(powersave_on_ac,_("Set the CPU to its minimum frequency"));
-    gtk_box_pack_start (GTK_BOX (vbox), powersave_on_ac, FALSE, FALSE, 0); 
-    list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(powersave_on_ac));
-    
-    conservative_on_ac = gtk_radio_button_new_with_label(list,_("Good power savings"));
-	gtk_widget_set_tooltip_text(conservative_on_ac,
-								_("gracefully increases and decreases the CPU speed depending on the current usage"));
-    gtk_box_pack_start (GTK_BOX (vbox), conservative_on_ac, FALSE, FALSE, 0); 
-    
-    if ( govs & POWERSAVE ) 
-    {
-        gtk_widget_set_sensitive(powersave_on_ac,enable);
-        g_signal_connect(powersave_on_ac,"pressed",G_CALLBACK(set_powersave_on_ac_cb),channel);
-        gtk_widget_show(powersave_on_ac);
-        if ( current_governor == POWERSAVE )
-        {
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(powersave_on_ac),TRUE);
-        }
-    }
-    if ( govs & ONDEMAND )
-    {
-        gtk_widget_set_sensitive(ondemand_on_ac,enable);
-        g_signal_connect(ondemand_on_ac,"pressed",G_CALLBACK(set_ondemand_on_ac_cb),channel);
-        gtk_widget_show(ondemand_on_ac);
-        if ( current_governor == ONDEMAND )
-        {
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ondemand_on_ac),TRUE);
-        }
-    }
-    if ( govs & PERFORMANCE )
-    {
-        gtk_widget_set_sensitive(performance_on_ac,enable);
-        g_signal_connect(performance_on_ac,"pressed",G_CALLBACK(set_performance_on_ac_cb),channel);
-        gtk_widget_show(performance_on_ac);
-        if ( current_governor == PERFORMANCE )
-        {
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(performance_on_ac),TRUE);
-        }
-    }
-    if ( govs & CONSERVATIVE )
-    {
-        gtk_widget_set_sensitive(conservative_on_ac,enable);
-        g_signal_connect(conservative_on_ac,"pressed",G_CALLBACK(set_conservative_on_ac_cb),channel);
-        gtk_widget_show(conservative_on_ac);
-        if ( current_governor == CONSERVATIVE )
-        {
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(conservative_on_ac),TRUE);
-        }
-    }
-
-    return frame;
-}
-
-static GtkWidget *
-xfpm_settings_cpu_on_battery_power(XfconfChannel *channel,guint8 govs,gboolean ups)
-{
-    GtkWidget *frame;
-    GtkWidget *align;
-    GtkWidget *vbox;
-    
-    GSList *list;
-    guint current_governor = xfconf_channel_get_uint(channel,ON_BATT_CPU_GOV_CFG,POWERSAVE);
-    gboolean enable = xfconf_channel_get_bool(channel,CPU_FREQ_SCALING_CFG,TRUE);
-    
-    frame = xfce_create_framebox(ups ? _("CPU frequency settings on UPS power") : _("CPU frequency settings on battery power"), &align);
-    gtk_container_set_border_width(GTK_CONTAINER(frame),BORDER);
-    gtk_widget_show(frame);
-    
-    vbox = gtk_vbox_new(FALSE,BORDER);
-    gtk_widget_show(vbox);
-    gtk_container_add(GTK_CONTAINER(align),vbox);
-    
-    performance_on_batt = gtk_radio_button_new_with_label(NULL,_("Best performance"));
-	gtk_widget_set_tooltip_text(performance_on_batt,_("Set the CPU to its maximum frequency"));
-    gtk_box_pack_start (GTK_BOX (vbox), performance_on_batt, FALSE, FALSE, 0);
-    
-    list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(performance_on_batt));
-    
-    ondemand_on_batt = gtk_radio_button_new_with_label(list,_("Ondemand performance"));
-	gtk_widget_set_tooltip_text(ondemand_on_batt,_("Set the CPU to its maximum speed when there is any load on it "\
-												"and to its minimum speed when the system is idle"));
-    gtk_box_pack_start (GTK_BOX (vbox), ondemand_on_batt, FALSE, FALSE, 0);
-    list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(ondemand_on_batt));
-    
-    powersave_on_batt = gtk_radio_button_new_with_label(list,_("Best power savings"));
-	gtk_widget_set_tooltip_text(powersave_on_batt,_("Set the CPU to its minimum frequency"));
-    gtk_box_pack_start (GTK_BOX (vbox), powersave_on_batt, FALSE, FALSE, 0); 
-    list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(powersave_on_batt));
-    
-    conservative_on_batt = gtk_radio_button_new_with_label(list,_("Good power savings"));
-	gtk_widget_set_tooltip_text(conservative_on_batt,
-								_("gracefully increases and decreases the CPU speed depending on the current usage"));
-    gtk_box_pack_start (GTK_BOX (vbox), conservative_on_batt, FALSE, FALSE, 0); 
-    
-    if ( govs & POWERSAVE ) 
-    {
-        gtk_widget_set_sensitive(powersave_on_batt,enable);
-        g_signal_connect(powersave_on_batt,"pressed",G_CALLBACK(set_powersave_on_batt_cb),channel);
-        gtk_widget_show(powersave_on_batt);
-        if ( current_governor == POWERSAVE )
-        {
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(powersave_on_batt),TRUE);
-        }
-    }
-    if ( govs & ONDEMAND )
-    {
-        gtk_widget_set_sensitive(ondemand_on_batt,enable);
-        g_signal_connect(ondemand_on_batt,"pressed",G_CALLBACK(set_ondemand_on_batt_cb),channel);
-        gtk_widget_show(ondemand_on_batt);
-        if ( current_governor == ONDEMAND )
-        {
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ondemand_on_batt),TRUE);
-        }
-    }
-    if ( govs & PERFORMANCE )
-    {
-        gtk_widget_set_sensitive(performance_on_batt,enable);
-        g_signal_connect(performance_on_batt,"pressed",G_CALLBACK(set_performance_on_batt_cb),channel);
-        gtk_widget_show(performance_on_batt);
-        if ( current_governor == PERFORMANCE )
-        {
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(performance_on_batt),TRUE);
-        }
-    }
-    if ( govs & CONSERVATIVE )
-    {
-        gtk_widget_set_sensitive(conservative_on_batt,enable);
-        g_signal_connect(conservative_on_batt,"pressed",G_CALLBACK(set_conservative_on_batt_cb),channel);
-        gtk_widget_show(conservative_on_batt);
-        if ( current_governor == CONSERVATIVE )
-        {
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(conservative_on_batt),TRUE);
-        }
-    }
-    return frame;
-}
-
-static GtkWidget *
-xfpm_settings_cpu_freq(XfconfChannel *channel,guint8 govs,gboolean laptop,gboolean ups)
-{
-    GtkWidget *ntbox;
-	ntbox = gtk_notebook_new();
-	
-    gtk_widget_show(ntbox);
-    
-    GtkWidget *vbox;
-    vbox = gtk_vbox_new(FALSE,0);
-    gtk_widget_show(vbox);
-
-    gtk_box_pack_start(GTK_BOX(vbox),ntbox,TRUE,TRUE,0);
-    
-    if ( !govs ) 
-    {
-        GtkWidget *label;
-        label = gtk_label_new(_("No CPU governor found"));
-        gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
-        gtk_widget_show(label);
-        gtk_widget_set_sensitive(GTK_WIDGET(cpu_gov),FALSE);
-        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cpu_gov),FALSE);
-    }
-	
-	if ( govs & CPU_FREQ_CANNOT_BE_USED )
-	{
-		GtkWidget *label;
-        label = gtk_label_new(_("CPU frequency control cannot be used"));
-        gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
-        gtk_widget_show(label);
-        gtk_widget_set_sensitive(GTK_WIDGET(cpu_gov),FALSE);
-        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cpu_gov),FALSE);
-	}
-	
-    else
-    {
-		GtkWidget *label;
-		label = gtk_label_new(_("On AC power"));
-		gtk_widget_show(label);
-        GtkWidget *frame;
-        frame = xfpm_settings_cpu_on_ac_adapter(channel,
-                                                govs,
-                                                laptop || ups ? _("CPU frequency settings on AC power") : _("CPU frequency settings"));
-        gtk_notebook_append_page(GTK_NOTEBOOK(ntbox),frame,label);
-        
-        if ( laptop || ups )
-        {
-			label = gtk_label_new(_("On battery power"));
-			gtk_widget_show(label);
-            frame = xfpm_settings_cpu_on_battery_power(channel,govs,ups);
-			gtk_notebook_append_page(GTK_NOTEBOOK(ntbox),frame,label);
-        }
-    }    
-    
-    return vbox;
-}
-
-static GtkWidget *
-xfpm_settings_lcd_brightness(XfconfChannel *channel,gboolean laptop,gboolean lcd)
-{
-    GtkWidget *hbox;
-    GtkWidget *brg;
-
-    hbox = gtk_hbox_new(FALSE,SPACING);
-
-    if ( laptop && lcd)
-    {
-        brg = gtk_check_button_new_with_label(_("Enable LCD brightness control"));
-        gtk_box_pack_start(GTK_BOX(hbox),brg,FALSE,FALSE,0);
-        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(brg),
-                                    xfconf_channel_get_bool(channel,LCD_BRIGHTNESS_CFG,TRUE));
-        g_signal_connect(brg,"toggled",G_CALLBACK(set_lcd_brightness_cb),channel);
-    }
-    gtk_widget_show_all(hbox);
-
-    return hbox;
-}
-
-#ifdef HAVE_DPMS
-static GtkWidget *
-xfpm_settings_dpms_on_battery(XfconfChannel *channel,gboolean ups)
-{
-    GtkWidget *frame,*align;
-    frame = xfce_create_framebox(ups ? _("Monitor settings on UPS power") : _("Monitor settings on battery power"), &align);
-    gtk_widget_show(frame);
-
-    gtk_container_set_border_width(GTK_CONTAINER(frame),BORDER);
-
-    on_batt_dpms = xfpm_dpms_spins_new();
-    gtk_widget_show(on_batt_dpms);
-    gtk_container_add(GTK_CONTAINER(align),on_batt_dpms);
-    GPtrArray *arr;
-    GValue *value;
-    guint value1 = 3 ,value2 = 4 ,value3 = 5;
-    arr = xfconf_channel_get_arrayv(channel,ON_BATT_DPMS_TIMEOUTS_CFG);
-    if ( arr )
-    {
-        value = g_ptr_array_index(arr,0);
-        value1 = g_value_get_uint(value);
-
-        value = g_ptr_array_index(arr,1);
-        value2 = g_value_get_uint(value);
-
-        value = g_ptr_array_index(arr,2);
-        value3 = g_value_get_uint(value);
-        xfconf_array_free(arr);
-    }
-    xfpm_dpms_spins_set_default_values(XFPM_DPMS_SPINS(on_batt_dpms),value1,value2,value3);
-    gboolean dpms_enabled = xfconf_channel_get_bool(channel,DPMS_ENABLE_CFG,TRUE);
-    xfpm_dpms_spins_set_active(XFPM_DPMS_SPINS(on_batt_dpms),dpms_enabled);
-    g_signal_connect(on_batt_dpms,"dpms-value-changed",
-                     G_CALLBACK(set_dpms_on_battery_cb),channel);
-
-    return frame;
-
-}
-
-
-static GtkWidget *
-xfpm_settings_dpms_on_ac_adapter(XfconfChannel *channel,const gchar *label)
-{
-    GtkWidget *frame;
-    GtkWidget *align;
-    GtkWidget *vbox;
-
-    frame = xfce_create_framebox(label, &align);
-    gtk_container_set_border_width(GTK_CONTAINER(frame),BORDER);
-    //gtk_widget_show(frame);
-
-    vbox = gtk_vbox_new(FALSE, SPACING);
-    //gtk_widget_show(vbox);
-
-    on_ac_dpms = xfpm_dpms_spins_new();
-    gtk_widget_show(on_ac_dpms);
-    GPtrArray *arr;
-    GValue *value;
-    guint value1 = 30 ,value2 = 45 ,value3 = 60;
-    arr = xfconf_channel_get_arrayv(channel,ON_AC_DPMS_TIMEOUTS_CFG);
-    if ( arr )
-    {
-        value = g_ptr_array_index(arr,0);
-        value1 = g_value_get_uint(value);
-
-        value = g_ptr_array_index(arr,1);
-        value2 = g_value_get_uint(value);
-
-        value = g_ptr_array_index(arr,2);
-        value3 = g_value_get_uint(value);
-        xfconf_array_free(arr);
-    }
-    xfpm_dpms_spins_set_default_values(XFPM_DPMS_SPINS(on_ac_dpms),value1,value2,value3);
-    gboolean dpms_enabled = xfconf_channel_get_bool(channel,DPMS_ENABLE_CFG,TRUE);
-    xfpm_dpms_spins_set_active(XFPM_DPMS_SPINS(on_ac_dpms),dpms_enabled);
-    g_signal_connect(on_ac_dpms,"dpms-value-changed",
-                     G_CALLBACK(set_dpms_on_ac_cb),channel);
-    gtk_container_add(GTK_CONTAINER(align),vbox);
-    gtk_box_pack_start(GTK_BOX(vbox),on_ac_dpms,TRUE,TRUE,0);
-    gtk_widget_show_all(frame);
-
-    return frame;
-}
-#endif
-
-static GtkWidget *
-xfpm_settings_monitor(XfconfChannel *channel,gboolean laptop,
-                      gboolean dpms_capable,gboolean lcd,gboolean ups)
-{
-    GtkWidget *ntbox;
-	ntbox = gtk_notebook_new();
-    gtk_widget_show(ntbox);
-    GtkWidget *vbox;
-    vbox = gtk_vbox_new(FALSE,0);
-    
-    gtk_widget_show(vbox);
-#ifdef HAVE_DPMS
-	GtkWidget *label;
-    GtkWidget *frame;
-    frame = xfpm_settings_dpms_on_ac_adapter(channel,
-                                            laptop || ups ? _("Monitor settings on AC power") : _("Monitor settings"));
-	label = gtk_label_new(_("On AC power"));
-	gtk_widget_show(label);
-	gtk_notebook_append_page(GTK_NOTEBOOK(ntbox),frame,label);										
-    gtk_box_pack_start(GTK_BOX(vbox),ntbox,TRUE,TRUE,0); // or FALSE, FALSE to not stretch window to bottom; would then also not move the brightness control onto the lower end
-
-    if ( laptop || ups )
-    {
-        frame = xfpm_settings_dpms_on_battery(channel,ups);
-		label = gtk_label_new(_("On battery power"));
-		gtk_widget_show(label);
-		gtk_notebook_append_page(GTK_NOTEBOOK(ntbox),frame,label);	
-    }
-
-    if (! dpms_capable ) 
-    {
-        GtkWidget *label;
-        label = gtk_label_new(_("Your monitor doesn't support DPMS control"));
-        gtk_widget_show(label);
-        gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);
-        gtk_widget_set_sensitive(dpms_op,FALSE);
-        xfpm_dpms_spins_set_active(XFPM_DPMS_SPINS(on_ac_dpms),FALSE); 
-    
-        if ( GTK_IS_WIDGET(on_batt_dpms) )
-        {
-            xfpm_dpms_spins_set_active(XFPM_DPMS_SPINS(on_batt_dpms),FALSE); 
-        }
-    }
-#endif    
-    GtkWidget *lcd_box = xfpm_settings_lcd_brightness(channel,laptop,lcd);
-    gtk_box_pack_start(GTK_BOX(vbox),lcd_box,FALSE,FALSE,0);
-    return vbox;
-}
-
-
-static GtkWidget *
-xfpm_settings_keys(XfconfChannel *channel,
-                   gboolean laptop,
-                   guint8 power_management,
-                   guint8 switch_buttons)
-{
-    GtkWidget *table;
-    GtkWidget *label;
-    GtkWidget *frame,*align;
-    GtkWidget *vbox;
-    GtkWidget *w_align;
-    
-    vbox = gtk_vbox_new(FALSE,0);
-    gtk_widget_show(vbox);
-
-    frame = xfce_create_framebox(_("Keyboard shortcuts"), &align);
-    gtk_widget_show(frame);
-    gtk_container_set_border_width(GTK_CONTAINER(frame),BORDER);
-    table = gtk_table_new(3,2,FALSE);
-    gtk_widget_show(table);
-
-    guint active;
-    /// Power Button
-    if (  switch_buttons & POWER_SWITCH )
-    {
-        w_align = gtk_alignment_new (0.0, 0.5, 0, 0);
-        gtk_widget_show(w_align);
-        label = gtk_label_new(_("When power button is pressed do"));
-        gtk_widget_show(label);
-        gtk_container_add(GTK_CONTAINER(w_align), label);
-        gtk_table_attach(GTK_TABLE(table),w_align,0,1,0,1,GTK_FILL,GTK_FILL,BORDER,SPACING);
-        GtkWidget *power_button;
-        power_button = gtk_combo_box_new_text();
-        gtk_combo_box_append_text(GTK_COMBO_BOX(power_button),_("Nothing"));
-        if ( power_management & SYSTEM_CAN_SUSPEND )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(power_button),_("Suspend"));
-        if ( power_management & SYSTEM_CAN_HIBERNATE )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(power_button),_("Hibernate"));
-        if ( power_management & SYSTEM_CAN_SHUTDOWN )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(power_button),_("Shutdown"));
-
-        active = xfconf_channel_get_uint(channel,POWER_SWITCH_CFG,0);
-        active = _combo_helper_function(channel,POWER_SWITCH_CFG,power_management,active);
-
-        gtk_combo_box_set_active(GTK_COMBO_BOX(power_button),active);
-        gtk_table_attach(GTK_TABLE(table),power_button,1,2,0,1,GTK_FILL,GTK_FILL,BORDER,SPACING);
-        g_signal_connect(power_button,"changed",G_CALLBACK(set_power_button_action_cb),channel);
-
-        gtk_widget_show(power_button);
-    }
-
-    /// Sleep Button
-    if ( switch_buttons & SLEEP_SWITCH )
-    {
-        label = gtk_label_new(_("When sleep button is pressed do"));
-        gtk_widget_show(label);
-        w_align = gtk_alignment_new (0.0, 0.5, 0, 0);
-        gtk_widget_show(w_align);
-        gtk_container_add(GTK_CONTAINER(w_align), label);
-        gtk_table_attach(GTK_TABLE(table),w_align,0,1,1,2,GTK_FILL,GTK_FILL,BORDER,SPACING);
-
-        GtkWidget *sleep_button;
-        active = xfconf_channel_get_uint(channel,SLEEP_SWITCH_CFG,0);
-        sleep_button = gtk_combo_box_new_text();
-
-        gtk_combo_box_append_text(GTK_COMBO_BOX(sleep_button),_("Nothing"));
-        if ( power_management & SYSTEM_CAN_SUSPEND )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(sleep_button),_("Suspend"));
-        if ( power_management & SYSTEM_CAN_HIBERNATE )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(sleep_button),_("Hibernate"));
-        if ( power_management & SYSTEM_CAN_SHUTDOWN )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(sleep_button),_("Shutdown"));
-        active = _combo_helper_function(channel,POWER_SWITCH_CFG,power_management,active);
-        gtk_combo_box_set_active(GTK_COMBO_BOX(sleep_button),active);
-        gtk_widget_show(sleep_button);
-        gtk_table_attach(GTK_TABLE(table),sleep_button,1,2,1,2,GTK_FILL,GTK_FILL,BORDER,SPACING);
-        g_signal_connect(sleep_button,"changed",G_CALLBACK(set_sleep_button_action_cb),channel);
-    }
-
-    /// Lid Button
-    if ( laptop && ( switch_buttons & LID_SWITCH ) )
-    {
-        label = gtk_label_new(_("When laptop lid is closed"));
-        gtk_widget_show(label);
-        w_align = gtk_alignment_new (0.0, 0.5, 0, 0);
-        gtk_widget_show(w_align);
-        gtk_container_add(GTK_CONTAINER(w_align), label);
-        gtk_table_attach(GTK_TABLE(table),w_align,0,1,2,3,GTK_FILL,GTK_FILL,BORDER,SPACING);
-        GtkWidget *lid_button;
-        active = xfconf_channel_get_uint(channel,LID_SWITCH_CFG,0);
-        lid_button = gtk_combo_box_new_text();
-        gtk_combo_box_append_text(GTK_COMBO_BOX(lid_button),_("Nothing"));
-        if ( power_management & SYSTEM_CAN_SUSPEND )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(lid_button),_("Suspend"));
-        if ( power_management & SYSTEM_CAN_SUSPEND )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(lid_button),_("Hibernate"));
-        if ( power_management & SYSTEM_CAN_SHUTDOWN )
-            gtk_combo_box_append_text(GTK_COMBO_BOX(lid_button),_("Shutdown"));
-        active = _combo_helper_function(channel,POWER_SWITCH_CFG,power_management,active);
-        gtk_combo_box_set_active(GTK_COMBO_BOX(lid_button),active);
-        gtk_widget_show(lid_button);
-        gtk_table_attach(GTK_TABLE(table),lid_button,1,2,2,3,GTK_FILL,GTK_FILL,BORDER,SPACING);
-        g_signal_connect(lid_button,"changed",G_CALLBACK(set_lid_button_action_cb),channel);
-    }
-
-    gtk_container_add(GTK_CONTAINER(align),vbox);
-    gtk_box_pack_start(GTK_BOX(vbox),table,TRUE,TRUE,0);
-    if ( !switch_buttons )
-    {
-        label = gtk_label_new(_("No available keyboard shortcuts found"));
-        gtk_widget_show(label);
-        gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);
-    }
-    return frame;
-    
-}
-
-static GtkWidget *
-xfpm_settings_general(XfconfChannel *channel,gboolean battery_settings,gboolean ups,guint8 govs)
-{
-    GtkWidget *table;
-    GtkWidget *show_icon;
-    GtkWidget *label;
-    GtkWidget *frame,*align;
-	GtkWidget *hbox;
-	gint i = 0;
-    
-    frame = xfce_create_framebox(_("General Options"), &align);
-    //gtk_widget_show(frame);
-    //table = gtk_table_new(4,2,FALSE);
-	table = gtk_vbox_new (FALSE, SPACING);
-    //gtk_widget_show(table);
-    gtk_container_add(GTK_CONTAINER(align),table);
-    
-	hbox = gtk_hbox_new (FALSE, SPACING);
-	gtk_box_pack_start (GTK_BOX(table), hbox, FALSE, FALSE, SPACING);
-
-    /* Systray icon */
-    label = gtk_label_new(_("System tray icon:"));
-    //gtk_widget_show(label);
-    //gtk_table_attach(GTK_TABLE(table),label,0,1,i,i+1,GTK_SHRINK,GTK_SHRINK,SPACING,SPACING);
-	gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, SPACING);
-    
-    guint icon_cfg = xfconf_channel_get_uint(channel,SHOW_TRAY_ICON_CFG,0);
-    show_icon = gtk_combo_box_new_text();
-    gtk_combo_box_append_text(GTK_COMBO_BOX(show_icon),_("Always Display an icon"));
-    gtk_combo_box_append_text(GTK_COMBO_BOX(show_icon),_("When battery is present"));
-    if ( battery_settings || ups )
-    {
-        gtk_combo_box_append_text(GTK_COMBO_BOX(show_icon),_("When battery is charging or discharging"));
-                            
-    } else if ( icon_cfg == 2 ) /* set to default value then */
-    {
-         if(!xfconf_channel_set_uint(channel,SHOW_TRAY_ICON_CFG,0))
-         {
-            g_critical("Cannot set value %s\n",SHOW_TRAY_ICON_CFG);
-        
-         }
-         icon_cfg = 0;
-    }
-    gtk_combo_box_set_active(GTK_COMBO_BOX(show_icon),icon_cfg);
-    g_signal_connect(show_icon,"changed",G_CALLBACK(set_show_tray_icon_cb),channel);
-    //gtk_widget_show(show_icon);
-    //gtk_table_attach(GTK_TABLE(table),show_icon,1,2,i,i+1,GTK_SHRINK,GTK_SHRINK,0,SPACING);
-	gtk_box_pack_start (GTK_BOX(hbox), show_icon, FALSE, FALSE, SPACING);
-	i++;
-	
-	cpu_gov = gtk_check_button_new_with_label(_("Enable CPU frequency scaling control"));
-	if ( govs )
-	{
-		gboolean cpu_gov_enabled;
-		//label = gtk_label_new(_("Enable CPU frequency scaling control"));
-		//gtk_widget_show(label);
-		//gtk_table_attach(GTK_TABLE(table),label,0,1,i,i+1,GTK_SHRINK,GTK_SHRINK,0,SPACING);
-		//gtk_widget_show(cpu_gov);
-		cpu_gov_enabled = xfconf_channel_get_bool(channel,CPU_FREQ_SCALING_CFG,TRUE);
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cpu_gov),
-									cpu_gov_enabled);                    
-		g_signal_connect(cpu_gov,"toggled",G_CALLBACK(set_cpu_freq_scaling_cb),channel);      
-		//gtk_table_attach(GTK_TABLE(table),cpu_gov,0,2,i,i+1,GTK_SHRINK,GTK_SHRINK,0,SPACING); 
-		gtk_box_pack_start (GTK_BOX(table), cpu_gov, FALSE, FALSE, SPACING);
-		i++;
-	}
-    
-#ifdef HAVE_DPMS
-    gboolean dpms_enabled;
-    //label = gtk_label_new(_("Enable monitor power management control"));
-    //gtk_widget_show(label);
-    //gtk_table_attach(GTK_TABLE(table),label,0,1,i,i+1,GTK_SHRINK,GTK_SHRINK,0,SPACING);	
-    dpms_op = gtk_check_button_new_with_label(_("Enable monitor power management control"));
-    //gtk_widget_show(dpms_op);
-    dpms_enabled = xfconf_channel_get_bool(channel,DPMS_ENABLE_CFG,TRUE);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dpms_op),
-                                 dpms_enabled);                    
-    g_signal_connect(dpms_op,"toggled",G_CALLBACK(set_dpms_cb),channel);      
-    //gtk_table_attach(GTK_TABLE(table),dpms_op,0,2,i,i+1,GTK_SHRINK,GTK_SHRINK,0,SPACING); 
-	gtk_box_pack_start (GTK_BOX(table), dpms_op, FALSE, FALSE, SPACING);
-	
-#endif    
-
-    gtk_widget_show_all (frame);
-    return frame;
-}
-
-
-static void
-_cursor_changed_cb(GtkIconView *view,gpointer data)
-{
-    GtkTreeSelection *sel;
-    GtkTreeModel     *model;
-    GtkTreeIter       selected_row;
-    gint int_data = 0;
-
-    sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
-
-    gtk_tree_selection_get_selected(sel,&model,&selected_row);
-
-    gtk_tree_model_get(model,
-                       &selected_row,
-                       2,
-                       &int_data,
-                       -1);
-
-    if ( int_data >= 0 && int_data <= 3 )
-    {
-        gtk_notebook_set_current_page(GTK_NOTEBOOK(nt),int_data);
-    }
-}
-
-static GtkWidget *
-xfpm_settings_tree_view(gboolean is_laptop,gboolean ups,guint8 govs,gboolean lcd,gboolean switch_buttons)
-{
-    GdkPixbuf *pix;
-    GtkWidget *view;
-    GtkListStore *list_store;
-    GtkTreeIter iter;
-    GtkTreeViewColumn *col;
-    GtkCellRenderer *renderer;
-    gint i = 0;
-
-    list_store = gtk_list_store_new(3,GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_INT);
-
-    view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store));
-    gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view),TRUE);
-    col = gtk_tree_view_column_new();
-    gtk_tree_view_column_set_title(col,_("Advanced settings"));
-
-    renderer = gtk_cell_renderer_pixbuf_new();
-    gtk_tree_view_column_pack_start(col,renderer,FALSE);
-    gtk_tree_view_column_set_attributes(col,renderer,"pixbuf",0,NULL);
-
-    renderer = gtk_cell_renderer_text_new();
-    gtk_tree_view_column_pack_start(col,renderer,FALSE);
-    gtk_tree_view_column_set_attributes(col,renderer,"text",1,NULL);
-    
-    gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
-
-    /// CPU Settings
-	if ( govs )
-	{
-		pix = xfpm_load_icon("xfpm-cpu",38);      
-		gtk_list_store_append(list_store,&iter);
-		if ( pix )
-		{
-			gtk_list_store_set(list_store,&iter,0,pix,1,_("CPU settings"),2,i,-1);
-			g_object_unref(pix);
-		}
-		else
-		{
-			gtk_list_store_set(list_store,&iter,1,_("CPU settings"),2,i,-1);
-		}
-		i++;
-	}
-    
-    /// Battery Settings
-    if ( is_laptop || ups )
-    {
-        pix = xfpm_load_icon(ups ? "gpm-ups-100" : "battery",38);
-        gtk_list_store_append(list_store,&iter);
-        if ( pix )
-        {
-            gtk_list_store_set(list_store,&iter,0,pix,1,_("Battery settings"),2,i,-1);
-            g_object_unref(pix);
-        }
-        else
-        {
-            gtk_list_store_set(list_store,&iter,1,_("Battery settings"),2,i,-1);
-        }
-        i++;
-   }
-
-    /// Keyboard Settings
-    if ( switch_buttons)
-    {
-        pix = xfpm_load_icon("keyboard",38);
-        gtk_list_store_append(list_store,&iter);
-        if ( pix )
-        {
-            gtk_list_store_set(list_store,&iter,0,pix,1,_("Shortcuts"),2,i,-1);
-            g_object_unref(pix);
-        }
-        else
-        {
-            gtk_list_store_set(list_store,&iter,1,_("Shortcuts"),2,i,-1);
-        } 
-        i++;
-    }
-    
-    /// Dpms settings
-    gboolean show_monitor_settings = FALSE;
-#ifdef HAVE_DPMS
-    show_monitor_settings = TRUE;
-#else
-    if ( lcd )
-    show_monitor_settings = TRUE;
-#endif    
-    
-    if ( show_monitor_settings )
-    {
-        pix = xfpm_load_icon("display",38);      
-        gtk_list_store_append(list_store,&iter);
-        if ( pix ) 
-        {
-            gtk_list_store_set(list_store,&iter,0,pix,1,_("Monitor Settings"),2,i,-1);
-            g_object_unref(pix);
-        }
-        else
-        {
-            gtk_list_store_set(list_store,&iter,1,_("Monitor Settings"),2,i,-1);
-        }
-        i++;
-    }
-    GtkTreeSelection *sel;
-    GtkTreePath *path;
-
-    sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
-    path = gtk_tree_path_new_from_string("0");
-    gtk_tree_selection_select_path(sel, path);
-    gtk_tree_path_free(path);
-    g_signal_connect(view,"cursor-changed",G_CALLBACK(_cursor_changed_cb),NULL);
-
-    return view;
-}
-
-GtkWidget *
-xfpm_settings_new(XfconfChannel *channel,
-                  gboolean is_laptop,
-                  guint8 power_management,
-                  gboolean dpms_capable,
-                  guint8 govs,
-                  guint8 switch_buttons,
-                  gboolean lcd,
-                  gboolean ups_found)
-{
-    GtkWidget *Dialog;  /* Main dialog window */
-    GtkWidget *mainbox; /* Box to get (Dialog)->vbox */
-    GtkWidget *box;
-    GtkWidget *table;   
-    GtkWidget *view;
-    GtkWidget *allbox;
-    GtkWidget *frame,*align;
-    
-    Dialog = xfce_titled_dialog_new_with_buttons(_("Power Manager Preferences"),
-                                                    NULL,
-                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                    GTK_STOCK_CLOSE,
-                                                    GTK_RESPONSE_CANCEL,
-                                                    GTK_STOCK_HELP,
-                                                    GTK_RESPONSE_HELP,
-                                                    NULL);
-    
-    gtk_window_set_icon_name(GTK_WINDOW(Dialog),"gpm-ac-adapter");
-    gtk_dialog_set_default_response(GTK_DIALOG(Dialog),GTK_RESPONSE_CLOSE);
-    mainbox = GTK_DIALOG(Dialog)->vbox;
-
-	allbox = gtk_vbox_new(FALSE,0);
-	gtk_widget_show(allbox);
-	gtk_box_pack_start(GTK_BOX(mainbox),allbox,TRUE,TRUE,0);
-	
-    gboolean ups;
-    ups = is_laptop ? FALSE : ups_found;
-        
-    /// General Options Frame
-    box = xfpm_settings_general(channel,is_laptop,ups,govs);
-    gtk_box_pack_start (GTK_BOX (allbox), box, FALSE, FALSE, SPACING);
-    
-    /// Notebook container, comes into big table container
-    nt = gtk_notebook_new();
-    
-    gtk_notebook_set_show_tabs(GTK_NOTEBOOK(nt),FALSE);
-    table = gtk_hbox_new (FALSE, SPACING);
-    gtk_widget_show(table);
-
-    frame = xfce_create_framebox(_("Extended"), &align);
-	gtk_widget_show (frame);
-	gtk_container_add (GTK_CONTAINER(align), table);
-
-    gtk_box_pack_start (GTK_BOX (allbox), frame, TRUE, TRUE, SPACING);
-	
-    view = xfpm_settings_tree_view(is_laptop,ups_found,govs,lcd,switch_buttons);
-
-#ifndef HAVE_DPMS	
-	if ( is_laptop || ups_found || govs || switch_buttons )
-	{
-#endif
-		gtk_box_pack_start (GTK_BOX(table), view, FALSE, FALSE, SPACING);
-		gtk_widget_show(view);  
-		gtk_box_pack_start (GTK_BOX(table), nt, TRUE, TRUE, 0); // spacing ain't nice here // SPACING);
-		gtk_widget_show(nt);
-	
-#ifndef HAVE_DPMS	
-}
-#endif
-    
-    /// Cpu freq settings
-	if ( govs )
-	{
-		box = xfpm_settings_cpu_freq(channel,govs,is_laptop,ups);
-		gtk_notebook_append_page(GTK_NOTEBOOK(nt),box,NULL);
-	}
-
-    /// Battery settings
-    
-	if ( is_laptop || ups )
-	{
-		box = xfpm_settings_battery(channel,power_management,ups);
-		gtk_notebook_append_page(GTK_NOTEBOOK(nt),box,NULL);
-	}
-
-    /// Keyboard buttons settings
-	if ( switch_buttons)
-	{
-		box = xfpm_settings_keys(channel,is_laptop,power_management,switch_buttons);
-		gtk_notebook_append_page(GTK_NOTEBOOK(nt),box,NULL); 
-	}
-    
-    /// Dpms & LCD brightness settings
-	
-    box = xfpm_settings_monitor(channel,is_laptop,dpms_capable,lcd,ups);
-    gtk_notebook_append_page(GTK_NOTEBOOK(nt),box,NULL);
-
-
-    return Dialog;
-}
diff --git a/src/xfpm-spin-button.c b/src/xfpm-spin-button.c
deleted file mode 100644
index 6022c5e2..00000000
--- a/src/xfpm-spin-button.c
+++ /dev/null
@@ -1,312 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#include <math.h>
-
-#include <gtk/gtk.h>
-#include <glib/gi18n.h>
-
-#include "xfpm-spin-button.h"
-#include "xfpm-string.h"
-
-#define MAX_DIGITS 20
-
-/* init */
-static void xfpm_spin_button_init      (XfpmSpinButton *spin_button);
-static void xfpm_spin_button_class_init(XfpmSpinButtonClass *klass);
-static void xfpm_spin_button_finalize  (GObject *object);
-
-static void xfpm_spin_button_editable_init(GtkEditableClass *iface);
-static void xfpm_spin_button_delete_text (GtkEditable *editable,
-                                          gint         start_pos,
-                                          gint         end_pos);
-static void xfpm_spin_button_insert_text (GtkEditable *editable,
-										  const gchar *new_text,
-										  gint         new_text_length,
-										  gint        *position);
-			     
-G_DEFINE_TYPE_WITH_CODE(XfpmSpinButton,xfpm_spin_button,GTK_TYPE_SPIN_BUTTON,
-						G_IMPLEMENT_INTERFACE(GTK_TYPE_EDITABLE,
-											  xfpm_spin_button_editable_init))
-
-static void
-xfpm_spin_button_size_request(GtkWidget *widget,GtkRequisition *req)
-{
-    GtkSpinButton *gtk_spin_button;
-    XfpmSpinButton *xfpm_spin_button;
-    
-    gtk_spin_button = GTK_SPIN_BUTTON(widget);
-    xfpm_spin_button = XFPM_SPIN_BUTTON(widget);
-    
-    GTK_WIDGET_CLASS(xfpm_spin_button_parent_class)->size_request(widget,req);
-    
-    PangoFontMetrics *metrics;
-    PangoContext *context;
-      
-    gtk_widget_ensure_style (GTK_WIDGET(xfpm_spin_button));
-    context = gtk_widget_get_pango_context (GTK_WIDGET(xfpm_spin_button));
-    metrics = pango_context_get_metrics (context,
-                           widget->style->font_desc,
-                           pango_context_get_language (context));	
-
-    gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
-    
-    gint char_pixels = (char_width + PANGO_SCALE - 1) / PANGO_SCALE;
-    
-    req->width += char_pixels * xfpm_spin_button->suffix_length;
-    pango_font_metrics_unref(metrics);
-}
-
-static void
-xfpm_spin_button_class_init(XfpmSpinButtonClass *klass) 
-{
-    GObjectClass *object_class     = (GObjectClass *)klass;
-    GtkWidgetClass *widget_class   = (GtkWidgetClass *) klass;
-    
-    widget_class->size_request = xfpm_spin_button_size_request;
-    
-    object_class->finalize   = xfpm_spin_button_finalize;
-    
-}
-
-static void
-xfpm_spin_button_init(XfpmSpinButton *spin_button)
-{
-    spin_button->suffix_length = 0;
-    spin_button->suffix = NULL;
-}
-
-static void
-xfpm_spin_button_finalize(GObject *object)
-{
-    XfpmSpinButton *spin;
-    spin = XFPM_SPIN_BUTTON(object);
-    
-    if ( spin->suffix )
-    {
-        g_free(spin->suffix);
-    }
-    
-    G_OBJECT_CLASS(xfpm_spin_button_parent_class)->finalize(object);
-}
-
-static void
-xfpm_spin_button_editable_init(GtkEditableClass *iface)
-{
-	iface->insert_text = xfpm_spin_button_insert_text;
-	iface->delete_text = xfpm_spin_button_delete_text;
-}
-
-static void
-_spin_button_update(XfpmSpinButton *spin)
-{
-    GtkWidget *widget;
-    
-    widget = GTK_WIDGET(spin);
-    
-    if ( GTK_WIDGET_DRAWABLE(widget) )
-    {
-        gtk_widget_queue_resize_no_redraw(widget);
-    }
-}
-
-
-static void
-xfpm_spin_button_delete_all_text(GtkEditable *editable)
-{
-    GtkEditableClass *spin_iface = g_type_interface_peek (xfpm_spin_button_parent_class,
-	                                                      GTK_TYPE_EDITABLE);
-    GtkEditableClass *entry_iface = g_type_interface_peek_parent(spin_iface);
-    
-    gint start,end;
-    
-    const gchar *text = gtk_entry_get_text(GTK_ENTRY(editable));
-	start = 0;
-	end = strlen(text);
-	
-    entry_iface->delete_text(editable,start,end);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(editable),gtk_spin_button_get_value(GTK_SPIN_BUTTON(editable)));
-}
-
-static void
-xfpm_spin_button_delete_text (GtkEditable *editable,
-                              gint         start_pos,
-                              gint         end_pos)
-{
-    
-    GtkEditableClass *spin_iface = g_type_interface_peek (xfpm_spin_button_parent_class,
-	                                                      GTK_TYPE_EDITABLE);
-    GtkEditableClass *entry_iface = g_type_interface_peek_parent(spin_iface);
-    
-    XfpmSpinButton *spin = XFPM_SPIN_BUTTON(editable);
-    
-    const gchar *text = gtk_entry_get_text(GTK_ENTRY(editable));
-    gint text_length = strlen(text);
-
-    gint length;
-    
-    if ( spin->suffix )
-    {
-        length = text_length - spin->suffix_length ;
-        if ( start_pos >= ABS(length) ) return;
-        entry_iface->delete_text(editable,start_pos,ABS(length));
-        _spin_button_update(spin);
-    }
-    else
-    {
-        entry_iface->delete_text(editable,start_pos,end_pos);
-        _spin_button_update(spin);
-    }
-}                                   
-
-static gboolean
-_is_digits(const gchar *text,gint length)
-{
-    gint i;
-
-    for ( i = 0 ; i < length ; i++)
-    {
-        if ( text[i] < 0x30 || text[i] > 0x39 )
-        {
-            return FALSE;
-        }
-    }
-    return TRUE;
-}
-
-static void xfpm_spin_button_insert_text (GtkEditable *editable,
-										  const gchar *new_text,
-										  gint         new_text_length,
-										  gint        *position)
-{
-    GtkEditableClass *spin_iface = g_type_interface_peek (xfpm_spin_button_parent_class,
-	                                                      GTK_TYPE_EDITABLE);
-    GtkEditableClass *entry_iface = g_type_interface_peek_parent(spin_iface);
-    
-    XfpmSpinButton *spin = XFPM_SPIN_BUTTON(editable);
-    
-    if ( !_is_digits(new_text,new_text_length) )
-    {
-        if ( spin->suffix && !xfpm_strcmp(new_text,spin->suffix) )
-        {
-            entry_iface->insert_text(editable,spin->suffix,spin->suffix_length,position);
-            _spin_button_update(spin);
-        }
-    }
-    else 
-    {
-        if ( spin->suffix )
-        {
-            const gchar *text = gtk_entry_get_text(GTK_ENTRY(editable));
-            gint text_length = strlen(text);
-            gint length = text_length - spin->suffix_length ;
-            if ( *position > ABS(length) ) return;
-            entry_iface->insert_text(editable,new_text,new_text_length,position);
-            _spin_button_update(spin);
-        }
-        else
-        {
-            entry_iface->insert_text(editable,new_text,new_text_length,position);
-            _spin_button_update(spin);
-        }
-    }
-}										  
-
-/* Constructor for the xfpm-spin button is the same as 
- * gtk_spin_button_new_with_range but slightly modified
- * 
- * GTK - The GIMP Toolkit
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * GtkSpinButton widget for GTK+
- * Copyright (C) 1998 Lars Hamann and Stefan Jeske
- *
- */
-  
-GtkWidget *
-xfpm_spin_button_new_with_range(gdouble min,gdouble max,gdouble step)
-{
-    GtkObject *adj;
-    XfpmSpinButton *spin;
-    
-	spin = g_object_new(XFPM_TYPE_SPIN_BUTTON,NULL);
-
-    gint digits;
-
-    g_return_val_if_fail (min <= max, NULL);
-    g_return_val_if_fail (step != 0.0, NULL);
-
-    adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
-
-    if (fabs (step) >= 1.0 || step == 0.0)
-        digits = 0;
-    else {
-        digits = abs ((gint) floor (log10 (fabs (step))));
-        if (digits > MAX_DIGITS)
-            digits = MAX_DIGITS;
-    }
-
-    gtk_spin_button_configure (GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT (adj), step, digits);
-
-    gtk_spin_button_set_numeric (GTK_SPIN_BUTTON(spin), TRUE);
-    
-	return GTK_WIDGET(spin);
-}
-
-void           
-xfpm_spin_button_set_suffix (XfpmSpinButton *spin,
-							 const gchar *suffix)
-{
-	g_return_if_fail(XFPM_IS_SPIN_BUTTON(spin));
-	g_return_if_fail(suffix != NULL);
-
-    xfpm_spin_button_delete_all_text(GTK_EDITABLE(spin));	
-    
-    if ( spin->suffix ) g_free(spin->suffix);
-    
-    spin->suffix = g_strdup(suffix);
-	spin->suffix_length = strlen(spin->suffix);
-	
-	gint spin_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
-	gint digits_num = 1 ;
-	if ( spin_value != 0 )
-	digits_num = abs ((gint) floor (log10 (fabs (spin_value)))) + 1;
-	
-	xfpm_spin_button_insert_text(GTK_EDITABLE(spin),spin->suffix,spin->suffix_length,&(digits_num));
-}
diff --git a/src/xfpm-spin-button.h b/src/xfpm-spin-button.h
deleted file mode 100644
index 6c951446..00000000
--- a/src/xfpm-spin-button.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
- *
- * * Copyright (C) 2008 Ali <ali.slackware@gmail.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __XFPM_SPIN_BUTTON_H
-#define __XFPM_SPIN_BUTTON_H
-
-#include <glib-object.h>
-#include <gtk/gtk.h>
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_SPIN_BUTTON    (xfpm_spin_button_get_type())
-#define XFPM_SPIN_BUTTON(o)      (G_TYPE_CHECK_INSTANCE_CAST((o),XFPM_TYPE_SPIN_BUTTON,XfpmSpinButton))
-#define XFPM_IS_SPIN_BUTTON(o)   (G_TYPE_CHECK_INSTANCE_TYPE((o),XFPM_TYPE_SPIN_BUTTON))
-
-typedef struct XfpmSpinButtonPrivate XfpmSpinButtonPrivate;
-
-typedef struct 
-{
-    GtkSpinButton parent;
-    
-    gchar *suffix;
-    gint suffix_length;
-    gint suffix_position;
-    gint digits_num;
-    
-} XfpmSpinButton;
-
-typedef struct 
-{
-    GtkSpinButtonClass parent_class;
-    
-} XfpmSpinButtonClass;
-
-GType          xfpm_spin_button_get_type           (void);
-GtkWidget     *xfpm_spin_button_new_with_range     (gdouble min,
-													gdouble max,
-													gdouble step);
-void           xfpm_spin_button_set_suffix         (XfpmSpinButton *spin,
-													const gchar *suffix);
-G_END_DECLS
-
-#endif /* __XFPM_SPIN_BUTTON_H */
diff --git a/src/xfpm-supply.c b/src/xfpm-supply.c
new file mode 100644
index 00000000..bae23757
--- /dev/null
+++ b/src/xfpm-supply.c
@@ -0,0 +1,605 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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 <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+
+#include "libxfpm/hal-power.h"
+#include "libxfpm/xfpm-string.h"
+#include "libxfpm/xfpm-common.h"
+
+#include "xfpm-supply.h"
+#include "xfpm-battery.h"
+#include "xfpm-adapter.h"
+#include "xfpm-notify.h"
+#include "xfpm-network-manager.h"
+#include "xfpm-enum.h"
+#include "xfpm-enum-types.h"
+#include "xfpm-config.h"
+
+/* Init */
+static void xfpm_supply_class_init (XfpmSupplyClass *klass);
+static void xfpm_supply_init       (XfpmSupply *xfpm_supply);
+static void xfpm_supply_finalize   (GObject *object);
+
+#define XFPM_SUPPLY_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_SUPPLY, XfpmSupplyPrivate))
+
+struct XfpmSupplyPrivate
+{
+    DbusHal       *hbus;
+    XfpmNotify    *notify;
+    XfpmAdapter   *adapter;
+    XfconfChannel *channel;
+    
+    HalPower      *power;
+    GHashTable    *hash;
+    
+    XfpmShutdownRequest critical_action;
+    XfpmShowIcon   show_icon;
+    
+    gboolean 	   adapter_found;
+    gboolean       adapter_present;
+    
+    guint8         power_management;
+};
+
+enum
+{
+    BLOCK_SHUTDOWN,
+    ON_BATTERY,
+    ON_LOW_BATTERY,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE(XfpmSupply, xfpm_supply, G_TYPE_OBJECT)
+
+static void
+xfpm_supply_class_init(XfpmSupplyClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    signals[BLOCK_SHUTDOWN] = 
+    	g_signal_new("block-shutdown",
+                      XFPM_TYPE_SUPPLY,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET(XfpmSupplyClass, block_shutdown),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__BOOLEAN,
+                      G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+    
+    signals[ON_BATTERY] = 
+    	g_signal_new("on-battery",
+                      XFPM_TYPE_SUPPLY,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET(XfpmSupplyClass, on_battery),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__BOOLEAN,
+                      G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+		      
+    signals[ON_LOW_BATTERY] = 
+    	g_signal_new("on-low-battery",
+                      XFPM_TYPE_SUPPLY,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET(XfpmSupplyClass, on_low_battery),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__VOID,
+                      G_TYPE_NONE, 0, G_TYPE_NONE);
+		      
+    object_class->finalize = xfpm_supply_finalize;
+
+    g_type_class_add_private(klass,sizeof(XfpmSupplyPrivate));
+}
+
+static void
+xfpm_supply_init (XfpmSupply *supply)
+{
+    supply->priv = XFPM_SUPPLY_GET_PRIVATE (supply);
+  
+    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->channel = NULL;
+    supply->priv->adapter = NULL;
+    supply->priv->adapter_found = FALSE;
+}
+
+static void
+xfpm_supply_finalize (GObject *object)
+{
+    XfpmSupply *supply;
+    supply = XFPM_SUPPLY(object);
+    
+    if ( supply->priv->power )
+    	g_object_unref(supply->priv->power);
+	
+    if ( supply->priv->hash )
+    	g_hash_table_destroy (supply->priv->hash);
+    if ( supply->priv->notify )
+    	g_object_unref (supply->priv->notify);
+    
+    G_OBJECT_CLASS(xfpm_supply_parent_class)->finalize(object);
+}
+
+
+static void
+xfpm_supply_hibernate_cb (GtkWidget *w, XfpmSupply *supply)
+{
+    gboolean ret = 
+    xfce_confirm (_("Are you sure you want to hibernate the system?"),
+                  GTK_STOCK_YES,
+                  _("Hibernate"));
+    
+    if ( ret ) 
+    {
+	g_signal_emit (G_OBJECT(supply ), signals[BLOCK_SHUTDOWN], 0, TRUE);
+	
+	xfpm_send_message_to_network_manager ("sleep");
+	xfpm_lock_screen ();
+	dbus_hal_shutdown (supply->priv->hbus, "Hibernate", NULL);
+	xfpm_send_message_to_network_manager ("wake");
+	
+	g_signal_emit (G_OBJECT(supply ), signals[BLOCK_SHUTDOWN], 0, FALSE);
+    }
+}
+
+static void
+xfpm_supply_suspend_cb (GtkWidget *w, XfpmSupply *supply)
+{
+    gboolean ret = 
+    xfce_confirm (_("Are you sure you want to suspend the system?"),
+                  GTK_STOCK_YES,
+                  _("Suspend"));
+    
+    if ( ret ) 
+    {
+	g_signal_emit (G_OBJECT(supply ), signals[BLOCK_SHUTDOWN], 0, TRUE);
+	
+	xfpm_send_message_to_network_manager ("sleep");
+	xfpm_lock_screen ();
+	dbus_hal_shutdown (supply->priv->hbus, "Suspend", NULL);
+	xfpm_send_message_to_network_manager ("wake");
+	
+	g_signal_emit (G_OBJECT(supply ), signals[BLOCK_SHUTDOWN], 0, FALSE);
+    }
+}
+
+//FIXME: more types
+static const gchar *
+_get_icon_name_from_battery_type (HalDeviceType type)
+{
+    switch (type)
+    {
+	case HAL_DEVICE_TYPE_PRIMARY:
+	    return "gpm-primary-charged";
+	    break;
+	case HAL_DEVICE_TYPE_UPS:
+	    return "gpm-ups-charged";
+	    break;
+	case HAL_DEVICE_TYPE_MOUSE:
+	    return "gpm-mouse-100";
+	    break;
+	case HAL_DEVICE_TYPE_KEYBOARD:
+	    return "gpm-keyboard-100";
+	    break;
+	case HAL_DEVICE_TYPE_PDA:
+	    return "gpm-phone-100";
+	    break;
+	default:
+	    return "gpm-primary-charged";
+	    break;
+    }
+}
+
+static const gchar *
+xfpm_supply_get_message_from_battery_state ( XfpmBatteryState state, HalDeviceType type, gboolean adapter_present)
+{
+    switch ( state )
+    {
+	case BATTERY_FULLY_CHARGED:
+	    return _("Your battery is fully charged");
+	    break;
+	case BATTERY_IS_CHARGING:
+	    return  _("Battery is charging");
+	    break;
+	case BATTERY_IS_DISCHARGING:
+	    if ( type == HAL_DEVICE_TYPE_PRIMARY )
+	    	return adapter_present ? _("Your battery is discharging") : _("System is running on battery");
+	    else
+	    	return _("Your battery is discharging");
+	    break;
+	case BATTERY_CHARGE_LOW:
+	    return _("Your battery charge is low");
+	    break;
+	default:
+	    return  NULL;
+	    break;
+    }
+}
+
+/*
+static gboolean
+xfpm_supply_get_running_on_battery (XfpmSupply *supply)
+{
+    if ( !supply->priv->adapter_found )
+    	return FALSE;
+    else if ( supply->priv->adapter_present )
+	return FALSE;
+    
+    return TRUE;
+}
+*/
+static void
+xfpm_supply_battery_state_changed_cb (XfpmBattery *battery, XfpmBatteryState state, XfpmSupply *supply)
+{
+    HalDeviceType type;
+    const HalDevice *device = xfpm_battery_get_device (battery);
+    
+    if ( device )
+	g_object_get (G_OBJECT(device), "type", &type, NULL);
+    else
+    {
+	g_critical ("Unable to get device object\n");
+	return;
+    }
+	
+    
+    const gchar *message 
+    	= xfpm_supply_get_message_from_battery_state (state,
+						      type,
+						      supply->priv->adapter_found   ? 
+						      supply->priv->adapter_present : 
+						      TRUE);
+    
+    if ( !message )
+    	return;
+    
+    xfpm_notify_show_notification (xfpm_battery_get_notify_obj(battery), 
+				   _("Xfce power manager"), 
+				   message, 
+				   xfpm_battery_get_icon_name (battery),
+				   10000,
+				   XFPM_NOTIFY_NORMAL, 
+				   xfpm_battery_get_status_icon (battery));
+}
+
+static void
+xfpm_supply_show_battery_info (GtkWidget *w, XfpmBattery *battery)
+{
+    xfpm_battery_show_info (battery);
+}
+
+static void
+xfpm_supply_popup_battery_menu_cb (XfpmBattery *battery, GtkStatusIcon *icon, 
+				   guint button, guint activate_time, 
+				   guint battery_type, XfpmSupply *supply)
+{
+    GtkWidget *menu, *mi, *img;
+    
+    menu = gtk_menu_new();
+    
+    // Hibernate menu option
+    mi = gtk_image_menu_item_new_with_label(_("Hibernate"));
+    img = gtk_image_new_from_icon_name("gpm-hibernate",GTK_ICON_SIZE_MENU);
+    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi),img);
+    gtk_widget_set_sensitive(mi,FALSE);
+    
+    if ( supply->priv->power_management & SYSTEM_CAN_HIBERNATE )
+    {
+	gtk_widget_set_sensitive (mi, TRUE);
+	g_signal_connect (G_OBJECT(mi), "activate",
+			  G_CALLBACK(xfpm_supply_hibernate_cb), supply);
+    }
+    gtk_widget_show(mi);
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
+    
+    // Suspend menu option
+    mi = gtk_image_menu_item_new_with_label(_("Suspend"));
+    img = gtk_image_new_from_icon_name("gpm-suspend",GTK_ICON_SIZE_MENU);
+    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi),img);
+    
+    gtk_widget_set_sensitive(mi,FALSE);
+    if ( supply->priv->power_management & SYSTEM_CAN_SUSPEND )
+    {
+	gtk_widget_set_sensitive (mi,TRUE);
+	g_signal_connect(mi,"activate",
+			 G_CALLBACK(xfpm_supply_suspend_cb),
+			 supply);
+    }
+    gtk_widget_show(mi);
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
+    
+    // Separator
+    mi = gtk_separator_menu_item_new();
+    gtk_widget_show(mi);
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
+    
+    // Battery informations
+    mi = gtk_image_menu_item_new_with_label (_("Battery information"));
+    img = gtk_image_new_from_icon_name (_get_icon_name_from_battery_type(battery_type), GTK_ICON_SIZE_MENU);
+    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(mi), img);
+    
+    gtk_widget_set_sensitive(mi,FALSE);
+    gtk_widget_set_sensitive (mi,TRUE);
+    
+    g_signal_connect(mi,"activate",
+		     G_CALLBACK(xfpm_supply_show_battery_info),
+		     battery);
+		     
+    gtk_widget_show(mi);
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
+    
+    // Separator
+    mi = gtk_separator_menu_item_new();
+    gtk_widget_show(mi);
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
+    
+    mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP,NULL);
+    gtk_widget_set_sensitive(mi,TRUE);
+    gtk_widget_show(mi);
+    g_signal_connect(mi,"activate",G_CALLBACK(xfpm_help),NULL);
+    
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
+    
+    mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT,NULL);
+    gtk_widget_set_sensitive(mi,TRUE);
+    gtk_widget_show(mi);
+    g_signal_connect(mi,"activate",G_CALLBACK(xfpm_about),NULL);
+    
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
+    
+    mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_PREFERENCES,NULL);
+    gtk_widget_set_sensitive(mi,TRUE);
+    gtk_widget_show(mi);
+    g_signal_connect(mi,"activate",G_CALLBACK(xfpm_preferences),NULL);
+    
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
+
+    // Popup the menu
+    gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
+		   gtk_status_icon_position_menu, 
+		   icon, button, activate_time);
+}
+
+static void
+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");
+	
+    supply->priv->adapter_present = present;
+    g_signal_emit (G_OBJECT(supply), signals[ON_BATTERY], 0, !supply->priv->adapter_present);
+}
+
+static XfpmBattery *
+xfpm_supply_get_battery (XfpmSupply *supply, const gchar *udi)
+{
+    XfpmBattery *battery;
+    battery = (XfpmBattery *)g_hash_table_lookup (supply->priv->hash, udi);
+    return battery;
+}
+
+static void
+xfpm_supply_add_device (XfpmSupply *supply, const HalDevice *device)
+{
+    HalDeviceType type;
+    gchar *udi = NULL;
+    
+    g_object_get(G_OBJECT(device), "type", &type, "udi", &udi, NULL);
+    
+    if ( type == HAL_DEVICE_TYPE_ADAPTER )
+    {
+	TRACE("Adapter found %s", udi);
+	if ( supply->priv->adapter_found )
+	{
+	    TRACE("System with more than one AC adapter"); /* g_strange */
+	    goto out;
+	}
+	supply->priv->adapter = xfpm_adapter_new (device);
+	g_signal_connect (supply->priv->adapter, "adapter-changed", 
+			  G_CALLBACK (xfpm_supply_adapter_changed_cb), supply);
+			  
+	supply->priv->adapter_found = TRUE;
+	gboolean adapter_present; 
+	g_object_get (G_OBJECT(device), "is-present", &adapter_present, NULL);
+	supply->priv->adapter_present = adapter_present;
+	g_signal_emit (G_OBJECT(supply), signals[ON_BATTERY], 0, supply->priv->adapter_present);
+    }
+    else
+    {
+	TRACE("New battery found %s", udi);
+	XfpmBattery *battery = xfpm_battery_new (device);
+	xfpm_battery_set_show_icon (battery, supply->priv->show_icon);
+	g_hash_table_insert (supply->priv->hash, g_strdup(udi), battery);
+	
+	g_signal_connect (G_OBJECT(battery), "battery-state-changed",
+			  G_CALLBACK(xfpm_supply_battery_state_changed_cb), supply);
+
+	g_signal_connect (G_OBJECT(battery), "popup-battery-menu",
+			  G_CALLBACK(xfpm_supply_popup_battery_menu_cb), supply);
+    }
+out:
+    if (udi)
+    	g_free (udi);
+}
+
+static void
+xfpm_supply_remove_device(XfpmSupply *supply,  const HalDevice *device)
+{
+    HalDeviceType type;
+    gchar *udi = NULL;
+    
+    g_object_get(G_OBJECT(device), "type", &type, "udi", &udi, NULL);
+    
+    if ( type == HAL_DEVICE_TYPE_ADAPTER )
+    {
+	if ( !supply->priv->adapter_found )
+	{
+	    g_warning ("No adapter found in the system to removed from the data\n");
+	    goto out;
+	}
+	TRACE("Adapter removed %s", udi);
+	g_object_unref (supply->priv->adapter);
+	supply->priv->adapter_found = FALSE;
+    }
+    else 
+    {
+	XfpmBattery *battery = xfpm_supply_get_battery(supply, udi);
+	
+	if ( battery )
+	{
+	    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");
+	}
+    }
+    
+out:
+    if (udi)
+    	g_free (udi);
+}
+
+static void
+xfpm_supply_monitor_start (XfpmSupply *supply)
+{
+    GPtrArray *array = hal_power_get_devices (supply->priv->power);
+    
+    int i = 0;
+    for ( i = 0; i<array->len; i++ )
+    {
+	HalDevice *device;
+	device = (HalDevice *)g_ptr_array_index(array, i);
+	xfpm_supply_add_device (supply, device);
+    }
+    
+    g_ptr_array_free(array, TRUE);
+}
+
+static void
+xfpm_supply_device_added_cb (HalPower *power, const HalDevice *device, XfpmSupply *supply)
+{
+    xfpm_supply_add_device (supply, device);
+}
+
+static void
+xfpm_supply_device_removed_cb (HalPower *power, const HalDevice *device, XfpmSupply *supply)
+{
+    xfpm_supply_remove_device (supply, device);
+}
+
+static void
+xfpm_supply_set_battery_show_tray_icon (XfpmSupply *supply)
+{
+    GList *list = NULL;
+    
+    list = g_hash_table_get_values (supply->priv->hash);
+    
+    if ( !list )
+    	return;
+	
+    int i;
+    for ( i = 0; i<g_list_length(list); i++)
+    {
+	XfpmBattery *battery = NULL;
+	battery = (XfpmBattery *) g_list_nth_data(list, i);
+	
+	if ( battery )
+	{
+	    xfpm_battery_set_show_icon (battery, supply->priv->show_icon);
+	}
+    }
+    
+    g_list_free (list);
+    
+}
+
+static void
+xfpm_supply_property_changed_cb (XfconfChannel *channel, gchar *property, GValue *value, XfpmSupply *supply)
+{
+    if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
+    	return;
+	
+    if ( xfpm_strequal (property, CRITICAL_BATT_ACTION_CFG) )
+    {
+	guint val = g_value_get_uint (value);
+	supply->priv->critical_action = val;
+    }
+    else if ( xfpm_strequal (property, SHOW_TRAY_ICON_CFG) )
+    {
+	guint val = g_value_get_uint (value);
+	supply->priv->show_icon = val;
+	xfpm_supply_set_battery_show_tray_icon (supply);
+    }
+    
+}
+
+static void
+xfpm_supply_load_configuration (XfpmSupply *supply)
+{
+    //FIXME: Check if the action specified we can actually do it
+    supply->priv->critical_action =
+    	xfconf_channel_get_uint (supply->priv->channel, CRITICAL_BATT_ACTION_CFG, 0);
+	
+    supply->priv->show_icon =
+    	xfconf_channel_get_uint (supply->priv->channel, SHOW_TRAY_ICON_CFG, 0);
+}
+
+/*
+ * Public functions
+ */ 
+XfpmSupply *
+xfpm_supply_new (DbusHal *bus, XfconfChannel *channel )
+{
+    XfpmSupply *supply = NULL;
+    supply = g_object_new(XFPM_TYPE_SUPPLY,NULL);
+    
+    supply->priv->hbus = bus;
+    supply->priv->channel    = channel;
+    
+    xfpm_supply_load_configuration (supply);
+    
+    g_object_get (G_OBJECT(supply->priv->hbus) , 
+		  "power-management-info", &supply->priv->power_management, NULL);
+    
+    g_signal_connect (channel, "property-changed", 
+		      G_CALLBACK(xfpm_supply_property_changed_cb), supply);
+
+    xfpm_supply_monitor_start(supply);
+    
+    g_signal_connect(supply->priv->power, "device-added",
+		     G_CALLBACK(xfpm_supply_device_added_cb), supply);
+		     
+    g_signal_connect(supply->priv->power, "device-removed",
+		     G_CALLBACK(xfpm_supply_device_removed_cb), supply);
+    return supply;
+}
diff --git a/src/xfpm-supply.h b/src/xfpm-supply.h
new file mode 100644
index 00000000..d7e97f1f
--- /dev/null
+++ b/src/xfpm-supply.h
@@ -0,0 +1,63 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_SUPPLY_H
+#define __XFPM_SUPPLY_H
+
+#include <glib-object.h>
+
+#include <xfconf/xfconf.h>
+
+#include "xfpm-enum.h"
+#include "dbus-hal.h"
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_SUPPLY       (xfpm_supply_get_type () )
+#define XFPM_SUPPLY(o)         (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_SUPPLY, XfpmSupply))
+#define XFPM_IS_SUPPLY(o)      (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_SUPPLY))
+
+typedef struct XfpmSupplyPrivate XfpmSupplyPrivate;
+
+typedef struct
+{
+    GObject		 parent;
+    XfpmSupplyPrivate   *priv;
+	
+} XfpmSupply;
+
+typedef struct
+{
+    GObjectClass         parent_class;
+    
+    void	        (*block_shutdown)	    (XfpmSupply *supply,
+    						     gboolean block);
+    void                (*on_battery    )	    (XfpmSupply *supply,
+						     gboolean on_battery);
+    void                (*on_low_battery)	    (XfpmSupply *supply);
+	
+} XfpmSupplyClass;
+
+GType   	         xfpm_supply_get_type       (void) G_GNUC_CONST;
+XfpmSupply     	        *xfpm_supply_new            (DbusHal *bus,
+						     XfconfChannel *channel);
+G_END_DECLS
+
+#endif /* __XFPM_SUPPLY_H */
diff --git a/src/xfpm-tray-icon.c b/src/xfpm-tray-icon.c
new file mode 100644
index 00000000..f9dbf030
--- /dev/null
+++ b/src/xfpm-tray-icon.c
@@ -0,0 +1,178 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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 <gtk/gtk.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "libxfpm/xfpm-common.h"
+
+#include "xfpm-tray-icon.h"
+
+/* Init */
+static void xfpm_tray_icon_class_init (XfpmTrayIconClass *klass);
+static void xfpm_tray_icon_init       (XfpmTrayIcon *tray);
+static void xfpm_tray_icon_finalize   (GObject *object);
+
+static gboolean xfpm_tray_icon_size_change_cb(GtkStatusIcon *icon, 
+					      gint size,
+					      gpointer data);
+
+#define XFPM_TRAY_ICON_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_TRAY_ICON, XfpmTrayIconPrivate))
+
+struct XfpmTrayIconPrivate
+{
+    GtkStatusIcon *icon;
+    gint icon_size;
+    GQuark icon_quark;
+    
+};
+
+G_DEFINE_TYPE(XfpmTrayIcon, xfpm_tray_icon, G_TYPE_OBJECT)
+
+static void
+xfpm_tray_icon_class_init(XfpmTrayIconClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->finalize = xfpm_tray_icon_finalize;
+
+    g_type_class_add_private(klass,sizeof(XfpmTrayIconPrivate));
+}
+
+static void
+xfpm_tray_icon_init(XfpmTrayIcon *tray)
+{
+    tray->priv = XFPM_TRAY_ICON_GET_PRIVATE(tray);
+    tray->priv->icon = gtk_status_icon_new();
+    tray->priv->icon_size = 0;
+    tray->priv->icon_quark = 0;
+     
+    g_signal_connect(G_OBJECT(tray->priv->icon), "size-changed", 
+		     G_CALLBACK(xfpm_tray_icon_size_change_cb), tray);
+}
+
+static void
+xfpm_tray_icon_finalize(GObject *object)
+{
+    XfpmTrayIcon *icon;
+
+    icon = XFPM_TRAY_ICON(object);
+    
+    if ( icon->priv->icon )
+    	g_object_unref(icon->priv->icon);
+
+    G_OBJECT_CLASS(xfpm_tray_icon_parent_class)->finalize(object);
+}
+
+static gboolean 
+xfpm_tray_icon_size_change_cb(GtkStatusIcon *icon, 
+			      gint size,
+			      gpointer data)
+{
+    XfpmTrayIcon *tray = (XfpmTrayIcon *) data;
+    
+    if ( size > 128 ) return TRUE;
+    if ( tray->priv->icon_quark == 0 ) return TRUE;
+    
+    tray->priv->icon_size = size;
+    
+    xfpm_tray_icon_set_icon (tray, g_quark_to_string(tray->priv->icon_quark));
+    
+    return TRUE;
+}
+
+XfpmTrayIcon *
+xfpm_tray_icon_new(void)
+{
+    XfpmTrayIcon *tray = NULL;
+    tray = g_object_new(XFPM_TYPE_TRAY_ICON,NULL);
+    return tray;
+}
+
+void xfpm_tray_icon_set_icon (XfpmTrayIcon *icon, const gchar *icon_name)
+{
+    g_return_if_fail(XFPM_IS_TRAY_ICON(icon));
+    
+    icon->priv->icon_quark = g_quark_from_string(icon_name);
+        
+    GdkPixbuf *pix;
+    pix = xfpm_load_icon(icon_name, icon->priv->icon_size);
+    
+    if ( pix )
+    {
+	gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(icon->priv->icon), pix);
+	g_object_unref(pix);
+    }
+    
+}
+
+void xfpm_tray_icon_set_tooltip (XfpmTrayIcon *icon, const gchar *tooltip)
+{
+    g_return_if_fail(XFPM_IS_TRAY_ICON(icon));
+
+#if GTK_CHECK_VERSION (2, 16, 0)
+    gtk_status_icon_set_tooltip_text (GTK_STATUS_ICON(icon->priv->icon), tooltip);
+#else
+    gtk_status_icon_set_tooltip (GTK_STATUS_ICON(icon->priv->icon), tooltip);
+#endif
+
+}
+
+void xfpm_tray_icon_set_visible (XfpmTrayIcon *icon, gboolean visible)
+{
+    g_return_if_fail(XFPM_IS_TRAY_ICON(icon));
+    
+    gtk_status_icon_set_visible(GTK_STATUS_ICON(icon->priv->icon), visible);
+    
+}
+
+gboolean xfpm_tray_icon_get_visible (XfpmTrayIcon *icon)
+{
+    g_return_val_if_fail (XFPM_IS_TRAY_ICON(icon), FALSE);
+    
+    return gtk_status_icon_get_visible (GTK_STATUS_ICON(icon->priv->icon));
+}
+
+GtkStatusIcon *xfpm_tray_icon_get_tray_icon (XfpmTrayIcon *icon)
+{
+    g_return_val_if_fail(XFPM_IS_TRAY_ICON(icon), NULL);
+    
+    return icon->priv->icon;
+}
+
+const gchar *xfpm_tray_icon_get_icon_name   (XfpmTrayIcon *icon)
+{
+    g_return_val_if_fail(XFPM_IS_TRAY_ICON(icon), NULL);
+    
+    if ( icon->priv->icon_quark == 0 ) return NULL;
+    
+    return  g_quark_to_string (icon->priv->icon_quark);
+}
diff --git a/src/xfpm-tray-icon.h b/src/xfpm-tray-icon.h
new file mode 100644
index 00000000..af552475
--- /dev/null
+++ b/src/xfpm-tray-icon.h
@@ -0,0 +1,62 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov@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_TRAY_ICON_H
+#define __XFPM_TRAY_ICON_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_TRAY_ICON        (xfpm_tray_icon_get_type () )
+#define XFPM_TRAY_ICON(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_TRAY_ICON, XfpmTrayIcon))
+#define XFPM_IS_TRAY_ICON(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_TRAY_ICON))
+
+typedef struct XfpmTrayIconPrivate XfpmTrayIconPrivate;
+
+typedef struct
+{
+    GObject		    parent;
+    XfpmTrayIconPrivate    *priv;
+	
+} XfpmTrayIcon;
+
+typedef struct
+{
+    GObjectClass            parent_class;
+	
+} XfpmTrayIconClass;
+
+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
+
+#endif /* __XFPM_TRAY_ICON_H */
-- 
GitLab