[Goodies-commits] r5603 - xfce4-power-manager/trunk/src
Ali Abdallah
aliov at xfce.org
Mon Oct 13 16:32:25 CEST 2008
Author: aliov
Date: 2008-10-13 14:32:25 +0000 (Mon, 13 Oct 2008)
New Revision: 5603
Modified:
xfce4-power-manager/trunk/src/xfpm-ac-adapter.c
xfce4-power-manager/trunk/src/xfpm-battery.c
xfce4-power-manager/trunk/src/xfpm-button.c
xfce4-power-manager/trunk/src/xfpm-cpu.c
xfce4-power-manager/trunk/src/xfpm-driver.c
xfce4-power-manager/trunk/src/xfpm-hal.c
xfce4-power-manager/trunk/src/xfpm-hal.h
xfce4-power-manager/trunk/src/xfpm-lcd-brightness.c
xfce4-power-manager/trunk/src/xfpm-settings.c
xfce4-power-manager/trunk/src/xfpm-spin-button.c
Log:
Optimization and fixes
Modified: xfce4-power-manager/trunk/src/xfpm-ac-adapter.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-ac-adapter.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-ac-adapter.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -150,6 +150,7 @@
{
XFPM_DEBUG("%s: \n",error->message);
g_error_free(error);
+ error = NULL;
}
priv->can_suspend = xfpm_hal_get_bool_info(priv->hal,
Modified: xfce4-power-manager/trunk/src/xfpm-battery.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-battery.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-battery.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -238,6 +238,7 @@
{
XFPM_DEBUG("%s: \n",error->message);
g_error_free(error);
+ error = NULL;
}
battery->can_suspend = xfpm_hal_get_bool_info(priv->hal,
@@ -603,7 +604,6 @@
if ( g_hash_table_size(priv->batteries) == 0 )
{
- XFPM_DEBUG("No battery device in the hash table\n");
return;
}
@@ -1086,7 +1086,8 @@
XfpmBatteryType type =
xfpm_battery_get_battery_type(battery_type);
- libhal_free_string(battery_type);
+ if ( battery_type )
+ libhal_free_string(battery_type);
GtkStatusIcon *batt_icon;
batt_icon = xfpm_battery_icon_new(last_full,
Modified: xfce4-power-manager/trunk/src/xfpm-button.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-button.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-button.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -565,7 +565,7 @@
xfpm_hal_device_have_key(priv->hal,udi[i],"button.has_state") )
{
GError *error = NULL;
- const gchar *button_type =
+ gchar *button_type =
xfpm_hal_get_string_info(priv->hal,udi[i],"button.type",&error);
if ( error )
{
@@ -573,8 +573,11 @@
g_error_free(error);
continue;
}
-
- _check_button(priv,button_type,udi[i]);
+ if ( button_type)
+ {
+ _check_button(priv,button_type,udi[i]);
+ libhal_free_string(button_type);
+ }
}
}
#ifdef DEBUG
Modified: xfce4-power-manager/trunk/src/xfpm-cpu.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-cpu.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-cpu.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -295,8 +295,15 @@
priv = XFPM_CPU_GET_PRIVATE(cpu);
gchar *current_governor;
- current_governor = xfpm_hal_get_current_cpu_governor(priv->hal);
+ 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 =
@@ -313,7 +320,13 @@
if ( 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);
+ xfpm_hal_set_cpu_governor(priv->hal,config_gov,&error);
+ if ( error )
+ {
+ XFPM_DEBUG("%s:\n",error->message);
+ g_error_free(error);
+ return;
+ }
}
else
{
Modified: xfce4-power-manager/trunk/src/xfpm-driver.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-driver.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-driver.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -419,10 +419,12 @@
GtkWidget *dialog;
GError *g_error = NULL;
+ gboolean with_dpms;
if ( !xfconf_init(&g_error) )
{
g_critical("Unable to xfconf init failed: %s\n",g_error->message);
g_error_free(g_error);
+ g_error = NULL;
}
channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
@@ -431,10 +433,17 @@
G_CALLBACK(xfpm_driver_property_changed_cb),drv);
gchar **govs;
- govs = xfpm_hal_get_available_cpu_governors(priv->hal);
int i = 0;
gint8 gov[5] = { 0, };
+ govs = xfpm_hal_get_available_cpu_governors(priv->hal,&g_error);
+ if ( g_error )
+ {
+ XFPM_DEBUG("%s :\n",g_error->message);
+ g_error_free(g_error);
+ goto no_gov;
+ }
+
if ( govs )
{
for ( i = 0 ; govs[i] ; i++ )
@@ -447,7 +456,9 @@
}
libhal_free_string_array(govs);
}
- gboolean with_dpms;
+
+ no_gov:
+
#ifdef HAVE_DPMS
with_dpms = xfpm_dpms_capable(priv->dpms);
#else
@@ -565,6 +576,7 @@
{
priv->formfactor = SYSTEM_UNKNOWN;
}
+ libhal_free_string(factor);
}
@@ -606,6 +618,7 @@
{
XFPM_DEBUG("%s: \n",g_error->message);
g_error_free(g_error);
+ g_error = NULL;
}
priv->can_hibernate = xfpm_hal_get_bool_info(priv->hal,
Modified: xfce4-power-manager/trunk/src/xfpm-hal.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-hal.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-hal.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -561,19 +561,18 @@
mess,
SLEEP_TIMEOUT,
&error);
-
+
+ dbus_message_unref(mess);
+
if ( dbus_error_is_set(&error) )
{
XFPM_DEBUG("error=%s\n",error.message);
dbus_set_g_error(gerror,&error);
dbus_error_free(&error);
- dbus_message_unref(mess);
*critical = 0;
return FALSE;
}
- dbus_message_unref(mess);
-
if ( !reply )
{
critical = 0;
@@ -644,19 +643,17 @@
mess,
SLEEP_TIMEOUT,
&error);
-
+ dbus_message_unref(mess);
+
if ( dbus_error_is_set(&error) )
{
XFPM_DEBUG("error=%s\n",error.message);
dbus_set_g_error(gerror,&error);
dbus_error_free(&error);
- dbus_message_unref(mess);
*critical = 0;
return FALSE;
}
- dbus_message_unref(mess);
-
if ( !reply )
{
g_set_error(gerror,0,0,_("Message suspend didn't get a reply"));
@@ -727,19 +724,18 @@
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);
- dbus_message_unref(mess);
return;
}
if ( !reply )
{
- g_set_error(gerror,0,0,_("No reply from HAL daemon"));
- dbus_message_unref(mess);
+ g_set_error(gerror,0,0,_("No reply from HAL daemon set brightness message"));
return;
}
@@ -773,19 +769,18 @@
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);
- dbus_message_unref(mess);
return -1;
}
if ( !reply )
{
- g_set_error(gerror,0,0,_("No reply from HAL daemon"));
- dbus_message_unref(mess);
+ g_set_error(gerror,0,0,_("No reply from HAL daemon to get brightness message"));
return -1;
}
@@ -796,14 +791,14 @@
}
gchar
-**xfpm_hal_get_available_cpu_governors(XfpmHal *xfpm_hal)
+**xfpm_hal_get_available_cpu_governors(XfpmHal *xfpm_hal,GError **gerror)
{
XfpmHalPrivate *priv;
priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
DBusMessage *mess;
- DBusPendingCall *pend;
DBusMessage *reply;
+ DBusError error;
gchar **govs = NULL;
int dummy;
@@ -811,68 +806,89 @@
HAL_ROOT_COMPUTER,
HAL_DBUS_INTERFACE_CPU,
"GetCPUFreqAvailableGovernors");
-
- dbus_connection_send_with_reply(priv->connection,mess,&pend,-1);
+ if (!mess)
+ {
+ g_set_error(gerror,0,0,_("Out of memmory"));
+ return NULL;
+ }
+
+ dbus_error_init(&error);
+ reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
+
dbus_message_unref(mess);
-
- g_return_val_if_fail(pend != NULL,NULL);
-
- dbus_pending_call_block(pend);
- reply = dbus_pending_call_steal_reply(pend);
- dbus_pending_call_unref(pend);
-
- if ( reply !=NULL )
+
+ if ( dbus_error_is_set(&error) )
{
- 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;
+ dbus_set_g_error(gerror,&error);
+ dbus_error_free(&error);
+ return NULL;
}
+
+ if ( !reply )
+ {
+ g_set_error(gerror,0,0,_("No reply from HAL daemon to get available cpu governors message"));
+ return NULL;
+ }
- 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)
+*xfpm_hal_get_current_cpu_governor(XfpmHal *xfpm_hal,GError **gerror)
{
XfpmHalPrivate *priv;
priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
DBusMessage *mess;
- DBusPendingCall *pend;
DBusMessage *reply;
- char *gov;
+ DBusError error;
+ gchar *gov = NULL;
mess = xfpm_dbus_new_message(HAL_DBUS_SERVICE,
HAL_ROOT_COMPUTER,
HAL_DBUS_INTERFACE_CPU,
"GetCPUFreqGovernor");
- dbus_connection_send_with_reply(priv->connection,mess,&pend,-1);
+ if (!mess)
+ {
+ g_set_error(gerror,0,0,_("Out of memmory"));
+ return NULL;
+ }
+
+ dbus_error_init(&error);
+
+ reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
dbus_message_unref(mess);
- g_return_val_if_fail(pend != NULL,NULL);
+ if ( dbus_error_is_set(&error) )
+ {
+ dbus_set_g_error(gerror,&error);
+ dbus_error_free(&error);
+ return NULL;
+ }
- dbus_pending_call_block(pend);
- reply = dbus_pending_call_steal_reply(pend);
- dbus_pending_call_unref(pend);
-
- if ( reply !=NULL )
+ if ( !reply )
{
- 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;
+ g_set_error(gerror,0,0,_("No reply from HAL daemon to get current cpu governor message"));
+ return NULL;
}
- 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)
+ const gchar *governor,
+ GError **gerror)
{
XfpmHalPrivate *priv;
priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
@@ -880,14 +896,65 @@
XFPM_DEBUG("Setting CPU gov %s\n",governor);
DBusMessage *mess;
+ DBusMessage *reply;
+ DBusError error;
mess = xfpm_dbus_new_message(HAL_DBUS_SERVICE,
HAL_ROOT_COMPUTER,
HAL_DBUS_INTERFACE_CPU,
"SetCPUFreqGovernor");
-
+ if (!mess)
+ {
+ g_set_error(gerror,0,0,_("Out of memmory"));
+ return;
+ }
+
dbus_message_append_args(mess,DBUS_TYPE_STRING,&governor,DBUS_TYPE_INVALID);
- dbus_connection_send(priv->connection,mess,NULL);
+ dbus_error_init(&error);
+ reply = dbus_connection_send_with_reply_and_block(priv->connection,mess,-1,&error);
+ dbus_message_unref(mess);
+
+ if ( !reply )
+ {
+ g_set_error(gerror,0,0,_("No reply from HAL daemon to set cpu governor message"));
+ 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);
+
+ DBusMessage *mess;
+ DBusMessage *reply;
+ DBusError error;
+ mess = xfpm_dbus_new_message(HAL_DBUS_SERVICE,
+ HAL_ROOT_COMPUTER,
+ HAL_DBUS_INTERFACE_POWER,
+ "SetPowerSave");
+ if (!mess)
+ {
+ g_set_error(gerror,0,0,_("Out of memmory"));
+ 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 ( !reply )
+ {
+ g_set_error(gerror,0,0,_("No reply from HAL daemon to set cpu governor message"));
+ return;
+ }
+ dbus_message_unref(reply);
+}
Modified: xfce4-power-manager/trunk/src/xfpm-hal.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-hal.h 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-hal.h 2008-10-13 14:32:25 UTC (rev 5603)
@@ -130,11 +130,16 @@
const gchar *interface,
GError **gerror);
-gchar **xfpm_hal_get_available_cpu_governors (XfpmHal *xfpm_hal);
-gchar *xfpm_hal_get_current_cpu_governor (XfpmHal *xfpm_hal);
+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);
-
+ 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 */
Modified: xfce4-power-manager/trunk/src/xfpm-lcd-brightness.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-lcd-brightness.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-lcd-brightness.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -246,6 +246,7 @@
if ( error )
{
XFPM_DEBUG("Error setting brigthness level: %s\n",error->message);
+ g_error_free(error);
return;
}
}
@@ -256,6 +257,7 @@
if ( error )
{
XFPM_DEBUG("Error setting brigthness level: %s\n",error->message);
+ g_error_free(error);
return;
}
}
@@ -301,7 +303,7 @@
return;
}
- if ( !udi )
+ if ( !udi || num == 0 )
{
XFPM_DEBUG("No device with laptop_panel capability\n");
return;
Modified: xfce4-power-manager/trunk/src/xfpm-settings.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-settings.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-settings.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -56,6 +56,7 @@
/// Global Variable ///
static GtkWidget *nt;
+static GtkWidget *cpu_gov;
static GtkWidget *performance_on_ac;
static GtkWidget *ondemand_on_ac;
static GtkWidget *powersave_on_ac;
@@ -572,7 +573,6 @@
conservative_on_batt = gtk_radio_button_new_with_label(list,_("Conservative"));
gtk_box_pack_start (GTK_BOX (vbox), conservative_on_batt, FALSE, FALSE, 0);
- /* FIXME: Ugly, and also support for other OS to be added */
if ( govs[0] == 1 )
{
gtk_widget_set_sensitive(powersave_on_batt,enable);
@@ -623,6 +623,7 @@
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(userspace_on_batt),TRUE);
}
}
+
return frame;
}
@@ -634,19 +635,37 @@
hbox = gtk_hbox_new(FALSE,2);
gtk_widget_show(hbox);
- GtkWidget *frame;
- frame = xfpm_settings_cpu_on_ac_adapter(channel,
- govs,
- laptop ? _("Cpu freq settings on AC power") : _("Cpu freq settings"));
- gtk_box_pack_start(GTK_BOX(hbox),frame,FALSE,FALSE,0);
+ GtkWidget *vbox;
+ vbox = gtk_vbox_new(FALSE,0);
+ gtk_widget_show(vbox);
+
+ gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,0);
- if ( laptop )
+ gboolean found_governor = govs[0] || govs[1] || govs[2] || govs[3] || govs[4];
+ if (!found_governor)
{
- frame = xfpm_settings_cpu_on_battery_power(channel,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);
+ }
+ else
+ {
+ GtkWidget *frame;
+ frame = xfpm_settings_cpu_on_ac_adapter(channel,
+ govs,
+ laptop ? _("Cpu freq settings on AC power") : _("Cpu freq settings"));
gtk_box_pack_start(GTK_BOX(hbox),frame,FALSE,FALSE,0);
- }
+
+ if ( laptop )
+ {
+ frame = xfpm_settings_cpu_on_battery_power(channel,govs);
+ gtk_box_pack_start(GTK_BOX(hbox),frame,FALSE,FALSE,0);
+ }
+ }
- return hbox;
+ return vbox;
}
static GtkWidget *
@@ -713,8 +732,8 @@
return frame;
}
-#endif
+
static GtkWidget *
xfpm_settings_dpms_on_ac_adapter(XfconfChannel *channel,const gchar *label)
{
@@ -752,6 +771,7 @@
return frame;
}
+#endif
static GtkWidget *
xfpm_settings_dpms(XfconfChannel *channel,gboolean laptop,gboolean dpms_capable)
@@ -809,7 +829,6 @@
gtk_widget_show(frame);
table = gtk_table_new(3,2,TRUE);
gtk_widget_show(table);
- gtk_container_add(GTK_CONTAINER(align),table);
guint default_config;
/// Power Button
@@ -871,6 +890,7 @@
g_signal_connect(lid_button,"changed",G_CALLBACK(set_lid_button_action_cb),channel);
}
+ gtk_container_add(GTK_CONTAINER(align),table);
return frame;
}
@@ -915,7 +935,6 @@
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,0,1,GTK_SHRINK,GTK_SHRINK,0,0);
- GtkWidget *cpu_gov;
gboolean cpu_gov_enabled;
label = gtk_label_new(_("Enable CPU freq scaling control"));
gtk_widget_show(label);
Modified: xfce4-power-manager/trunk/src/xfpm-spin-button.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-spin-button.c 2008-10-13 09:53:03 UTC (rev 5602)
+++ xfce4-power-manager/trunk/src/xfpm-spin-button.c 2008-10-13 14:32:25 UTC (rev 5603)
@@ -69,6 +69,7 @@
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
More information about the Goodies-commits
mailing list