summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAli Abdallah <ali.slackware@gmail.com>2009-04-04 11:58:11 +0000
committerAli Abdallah <ali.slackware@gmail.com>2009-04-04 11:58:11 +0000
commit4ad9706e22ade75ced65bde4e4c9a639c0d268f5 (patch)
tree5b8041ce84ed01b9ceeedd89bd5d64a45d3cce2f /src
parent8928587625138a0287f256eb4bf59348e1cc6ad0 (diff)
downloadixfce4-power-manager-4ad9706e22ade75ced65bde4e4c9a639c0d268f5.tar.gz
Alpha2 release0.8.0alpha2
(Old svn revision: 7108)
Diffstat (limited to 'src')
-rw-r--r--src/xfpm-battery.c28
-rw-r--r--src/xfpm-cpu.c7
-rw-r--r--src/xfpm-dpms.c13
-rw-r--r--src/xfpm-manager.c4
-rw-r--r--src/xfpm-supply.c33
-rw-r--r--src/xfpm-xfconf.c9
6 files changed, 55 insertions, 39 deletions
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 49778bd1..5a7e016c 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -202,22 +202,28 @@ static void
xfpm_battery_refresh_state (XfpmBattery *battery, XfpmBatteryState state)
{
const gchar *message;
+ gboolean notify;
+
+ notify = xfpm_xfconf_get_property_bool (battery->priv->conf, GENERAL_NOTIFICATION_CFG);
if ( battery->priv->state != state)
{
battery->priv->state = state;
- message = xfpm_battery_get_message_from_battery_state (state, battery->priv->adapter_present );
- if ( !message )
- goto signal;
- xfpm_notify_show_notification (battery->priv->notify,
- _("Xfce power manager"),
- message,
- xfpm_tray_icon_get_icon_name (battery->priv->icon),
- 10000,
- battery->priv->type == HAL_DEVICE_TYPE_PRIMARY ? FALSE : TRUE,
- XFPM_NOTIFY_NORMAL,
- xfpm_tray_icon_get_tray_icon(battery->priv->icon));
+ if ( notify )
+ {
+ message = xfpm_battery_get_message_from_battery_state (state, battery->priv->adapter_present );
+ if ( !message )
+ goto signal;
+ xfpm_notify_show_notification (battery->priv->notify,
+ _("Xfce power manager"),
+ message,
+ xfpm_tray_icon_get_icon_name (battery->priv->icon),
+ 8000,
+ battery->priv->type == HAL_DEVICE_TYPE_PRIMARY ? FALSE : TRUE,
+ XFPM_NOTIFY_NORMAL,
+ xfpm_tray_icon_get_tray_icon(battery->priv->icon));
+ }
signal:
g_signal_emit (G_OBJECT(battery), signals[BATTERY_STATE_CHANGED], 0, state);
TRACE("Emitting signal battery state changed");
diff --git a/src/xfpm-cpu.c b/src/xfpm-cpu.c
index cfd01afb..4ea00047 100644
--- a/src/xfpm-cpu.c
+++ b/src/xfpm-cpu.c
@@ -362,6 +362,7 @@ xfpm_cpu_init(XfpmCpu *cpu)
G_CALLBACK(xfpm_cpu_power_save_settings_changed_cb), cpu);
cpu->priv->on_battery = !xfpm_adapter_get_present (cpu->priv->adapter);
+ xfpm_cpu_refresh (cpu);
}
out:
@@ -375,11 +376,9 @@ xfpm_cpu_finalize(GObject *object)
cpu = XFPM_CPU(object);
- if ( cpu->priv->conf )
- g_object_unref (cpu->priv->conf);
+ g_object_unref (cpu->priv->conf);
- if ( cpu->priv->adapter)
- g_object_unref (cpu->priv->adapter);
+ g_object_unref (cpu->priv->adapter);
if ( cpu->priv->bus )
dbus_g_connection_unref (cpu->priv->bus);
diff --git a/src/xfpm-dpms.c b/src/xfpm-dpms.c
index 89bdd212..70cae8f3 100644
--- a/src/xfpm-dpms.c
+++ b/src/xfpm-dpms.c
@@ -24,18 +24,8 @@
#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 <gdk/gdk.h>
#include <gdk/gdkx.h>
@@ -248,6 +238,9 @@ xfpm_dpms_init(XfpmDpms *dpms)
g_signal_connect (dpms->priv->conf, "dpms-settings-changed",
G_CALLBACK (xfpm_dpms_settings_changed_cb), dpms);
+
+ dpms->priv->on_battery = !xfpm_adapter_get_present (dpms->priv->adapter);
+ xfpm_dpms_refresh (dpms);
}
else
{
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index d06b81d8..d84a8ed8 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -35,6 +35,8 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
+#include <libnotify/notify.h>
+
#include "libxfpm/hal-monitor.h"
#include "libxfpm/xfpm-string.h"
#include "libxfpm/xfpm-dbus.h"
@@ -104,6 +106,8 @@ xfpm_manager_init(XfpmManager *manager)
manager->priv->session_bus = NULL;
manager->priv->engine = NULL;
manager->priv->monitor = NULL;
+
+ notify_init ("xfce4-power-manager");
}
static void
diff --git a/src/xfpm-supply.c b/src/xfpm-supply.c
index 62cb9895..b06ac5da 100644
--- a/src/xfpm-supply.c
+++ b/src/xfpm-supply.c
@@ -66,6 +66,7 @@ struct XfpmSupplyPrivate
HalPower *power;
GHashTable *hash;
+ gboolean low_power;
gboolean adapter_present;
gboolean inhibited;
guint8 power_management;
@@ -105,7 +106,7 @@ xfpm_supply_class_init(XfpmSupplyClass *klass)
object_class->finalize = xfpm_supply_finalize;
- g_type_class_add_private(klass,sizeof(XfpmSupplyPrivate));
+ g_type_class_add_private (klass, sizeof (XfpmSupplyPrivate));
}
static void
@@ -121,6 +122,7 @@ xfpm_supply_init (XfpmSupply *supply)
supply->priv->tray = xfpm_tray_icon_new ();
supply->priv->inhibit = xfpm_inhibit_new ();
supply->priv->inhibited = FALSE;
+ supply->priv->low_power = FALSE;
xfpm_tray_icon_set_visible (supply->priv->tray, FALSE);
xfpm_tray_icon_set_icon (supply->priv->tray, "gpm-ac-adapter");
@@ -283,7 +285,7 @@ xfpm_supply_show_critical_action_inhibited (XfpmSupply *supply, XfpmBattery *bat
xfpm_supply_add_actions_to_notification (supply, battery, n);
- xfpm_notify_present_notification (supply->priv->notify, n, FALSE);
+ xfpm_notify_critical (supply->priv->notify, n);
}
static void
@@ -300,13 +302,12 @@ xfpm_supply_show_critical_action (XfpmSupply *supply, XfpmBattery *battery)
_("Xfce power manager"),
message,
xfpm_battery_get_icon_name (battery),
- 15000,
+ 20000,
XFPM_NOTIFY_CRITICAL,
xfpm_battery_get_status_icon (battery));
xfpm_supply_add_actions_to_notification (supply, battery, n);
-
- xfpm_notify_present_notification (supply->priv->notify, n, FALSE);
+ xfpm_notify_critical (supply->priv->notify, n);
}
static void
@@ -318,6 +319,7 @@ xfpm_supply_handle_primary_critical (XfpmSupply *supply, XfpmBattery *battery)
if ( xfpm_supply_on_low_power (supply) )
{
TRACE ("System is running on low power");
+ supply->priv->low_power = TRUE;
if ( supply->priv->inhibited )
{
xfpm_supply_show_critical_action_inhibited (supply, battery);
@@ -334,21 +336,24 @@ xfpm_supply_handle_primary_critical (XfpmSupply *supply, XfpmBattery *battery)
}
static void
-xfpm_supply_primary_critical (XfpmSupply *supply, XfpmBattery *battery, XfpmBatteryState state)
+xfpm_supply_battery_state_changed_cb (XfpmBattery *battery, XfpmBatteryState state, XfpmSupply *supply)
{
if ( state == BATTERY_CHARGE_CRITICAL )
- {
xfpm_supply_handle_primary_critical (supply, battery);
+ else if ( supply->priv->low_power == TRUE )
+ {
+ if ( xfpm_supply_on_low_power (supply) )
+ {
+ xfpm_supply_handle_primary_critical (supply, battery);
+ }
+ else
+ {
+ supply->priv->low_power = FALSE;
+ xfpm_notify_close_critical (supply->priv->notify);
+ }
}
}
-static void
-xfpm_supply_battery_state_changed_cb (XfpmBattery *battery, XfpmBatteryState state, XfpmSupply *supply)
-{
- if ( state == BATTERY_CHARGE_CRITICAL )
- xfpm_supply_primary_critical (supply, battery, state);
-}
-
static XfpmBattery *
xfpm_supply_get_battery (XfpmSupply *supply, const gchar *udi)
{
diff --git a/src/xfpm-xfconf.c b/src/xfpm-xfconf.c
index 9a030851..b0c44c24 100644
--- a/src/xfpm-xfconf.c
+++ b/src/xfpm-xfconf.c
@@ -75,6 +75,7 @@ struct XfpmXfconfPrivate
XfpmShowIcon show_icon;
guint critical_level;
+ gboolean general_notification;
};
enum
@@ -115,6 +116,10 @@ xfpm_xfconf_property_changed_cb (XfconfChannel *channel, gchar *property,
else
conf->priv->sleep_button = val;
}
+ else if ( xfpm_strequal (property, GENERAL_NOTIFICATION_CFG) )
+ {
+ conf->priv->general_notification = g_value_get_boolean (value);
+ }
else if ( xfpm_strequal (property, POWER_SWITCH_CFG ) )
{
str = g_value_get_string (value);
@@ -289,6 +294,8 @@ xfpm_xfconf_load_configuration (XfpmXfconf *conf)
g_free (str);
+ conf->priv->general_notification = xfconf_channel_get_bool (conf->priv->channel, GENERAL_NOTIFICATION_CFG, TRUE);
+
str = xfconf_channel_get_string (conf->priv->channel, LID_SWITCH_ON_AC_CFG, "Nothing");
val = xfpm_shutdown_string_to_int (str);
@@ -499,6 +506,8 @@ gboolean xfpm_xfconf_get_property_bool (XfpmXfconf *conf, const gchar *property)
return conf->priv->lock_screen;
else if ( xfpm_strequal (property, POWER_SAVE_ON_BATTERY ) )
return conf->priv->power_save_on_battery;
+ else if ( xfpm_strequal (property, GENERAL_NOTIFICATION_CFG ) )
+ return conf->priv->general_notification;
#ifdef HAVE_DPMS
else if ( xfpm_strequal (property, DPMS_SLEEP_MODE ))
return conf->priv->sleep_dpms_mode;