gnome-power-manager r3028 - in trunk: . src
- From: rhughes svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-power-manager r3028 - in trunk: . src
- Date: Wed, 22 Oct 2008 08:51:28 +0000 (UTC)
Author: rhughes
Date: Wed Oct 22 08:51:27 2008
New Revision: 3028
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=3028&view=rev
Log:
2008-10-22 Richard Hughes <richard hughsie com>
* src/gpm-info.c: (gpm_statistics_add_data_type),
(gpm_statistics_add_event_type), (gpm_info_event_log),
(gpm_info_set_collection_data), (gpm_info_log_do_poll),
(dpms_mode_changed_cb), (control_resume_cb), (gpm_info_init),
(gpm_info_finalize):
* src/gpm-manager.c: (idle_changed_cb), (button_pressed_cb),
(ac_adapter_changed_cb), (control_sleep_failure_cb):
Move some of the GpmInfo logic down into GpmManager.
Modified:
trunk/ChangeLog
trunk/src/gpm-info.c
trunk/src/gpm-manager.c
Modified: trunk/src/gpm-info.c
==============================================================================
--- trunk/src/gpm-info.c (original)
+++ trunk/src/gpm-info.c Wed Oct 22 08:51:27 2008
@@ -28,12 +28,9 @@
#include <string.h>
#include <dbus/dbus-gtype-specialized.h>
#include <gconf/gconf-client.h>
-
#include <hal-manager.h>
#include "egg-color.h"
-#include "gpm-ac-adapter.h"
-#include "gpm-button.h"
#include "gpm-control.h"
#include "gpm-common.h"
#include "egg-debug.h"
@@ -43,7 +40,6 @@
#include "gpm-array.h"
#include "gpm-engine.h"
#include "gpm-stock-icons.h"
-#include "gpm-idle.h"
#include "gpm-graph-widget.h"
static void gpm_info_class_init (GpmInfoClass *klass);
@@ -68,11 +64,8 @@
struct GpmInfoPrivate
{
- GpmAcAdapter *ac_adapter;
- GpmButton *button;
GpmControl *control;
GpmDpms *dpms;
- GpmIdle *idle;
GpmProfile *profile;
GpmEngineCollection *collection;
@@ -112,10 +105,10 @@
* Helper function
**/
void
-gpm_info_explain_reason (GpmInfo *info,
+gpm_info_explain_reason (GpmInfo *info,
GpmGraphWidgetEvent event,
- const gchar *pre,
- const gchar *post)
+ const gchar *pre,
+ const gchar *post)
{
gchar *message;
if (post) {
@@ -156,9 +149,7 @@
* gpm_statistics_add_data_type:
**/
static void
-gpm_statistics_add_data_type (GPtrArray *array,
- guint colour,
- const gchar *description)
+gpm_statistics_add_data_type (GPtrArray *array, guint colour, const gchar *description)
{
GValue *value;
@@ -174,11 +165,7 @@
* gpm_statistics_add_event_type:
**/
static void
-gpm_statistics_add_event_type (GPtrArray *array,
- guint id,
- guint colour,
- guint shape,
- const gchar *description)
+gpm_statistics_add_event_type (GPtrArray *array, guint id, guint colour, guint shape, const gchar *description)
{
GValue *value;
@@ -198,7 +185,7 @@
{
/* add the general key items, TODO specify which ones make sense */
gpm_statistics_add_event_type (array, GPM_EVENT_ON_AC,
- EGG_COLOR_BLUE,
+ EGG_COLOR_BLUE,
GPM_GRAPH_WIDGET_SHAPE_CIRCLE,
_("On AC"));
gpm_statistics_add_event_type (array, GPM_EVENT_ON_BATTERY,
@@ -570,9 +557,7 @@
* Adds an point to the event log
**/
void
-gpm_info_event_log (GpmInfo *info,
- GpmGraphWidgetEvent event,
- const gchar *desc)
+gpm_info_event_log (GpmInfo *info, GpmGraphWidgetEvent event, const gchar *desc)
{
g_return_if_fail (info != NULL);
g_return_if_fail (GPM_IS_INFO (info));
@@ -586,8 +571,7 @@
* gpm_info_set_collection_data:
**/
gboolean
-gpm_info_set_collection_data (GpmInfo *info,
- GpmEngineCollection *collection)
+gpm_info_set_collection_data (GpmInfo *info, GpmEngineCollection *collection)
{
g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (GPM_IS_INFO (info), FALSE);
@@ -622,102 +606,24 @@
value_x = g_timer_elapsed (info->priv->timer, NULL) - GPM_INFO_DATA_POLL;
/* set the correct colours */
- if (unit->is_discharging) {
+ if (unit->is_discharging)
colour = EGG_COLOR_DISCHARGING;
- } else if (unit->is_charging) {
+ else if (unit->is_charging)
colour = EGG_COLOR_CHARGING;
- } else {
+ else
colour = EGG_COLOR_CHARGED;
- }
- if (unit->percentage > 0) {
- gpm_array_add (info->priv->percentage_data, value_x,
- unit->percentage, colour);
- }
- if (unit->rate > 0) {
- gpm_array_add (info->priv->rate_data, value_x,
- unit->rate, colour);
- }
- if (unit->voltage > 0) {
- gpm_array_add (info->priv->voltage_data, value_x,
- unit->voltage, colour);
- }
+ if (unit->percentage > 0)
+ gpm_array_add (info->priv->percentage_data, value_x, unit->percentage, colour);
+ if (unit->rate > 0)
+ gpm_array_add (info->priv->rate_data, value_x, unit->rate, colour);
+ if (unit->voltage > 0)
+ gpm_array_add (info->priv->voltage_data, value_x, unit->voltage, colour);
}
return TRUE;
}
/**
- * ac_adapter_changed_cb:
- *
- * Does the actions when the ac source is inserted/removed.
- **/
-static void
-ac_adapter_changed_cb (GpmAcAdapter *ac_adapter,
- gboolean on_ac,
- GpmInfo *info)
-{
- if (on_ac) {
- gpm_info_event_log (info, GPM_EVENT_ON_AC,
- _("AC adapter inserted"));
- } else {
- gpm_info_event_log (info, GPM_EVENT_ON_BATTERY,
- _("AC adapter removed"));
- }
-}
-
-/**
- * button_pressed_cb:
- * @type: The button type, e.g. "power"
- * @state: The state, where TRUE is depressed or closed
- * @brightness: This class instance
- **/
-static void
-button_pressed_cb (GpmButton *button,
- const gchar *type,
- GpmInfo *info)
-{
- egg_debug ("Button press event type=%s", type);
-
- if (strcmp (type, GPM_BUTTON_LID_CLOSED) == 0) {
- gpm_info_event_log (info,
- GPM_EVENT_LID_CLOSED,
- _("The laptop lid has been closed"));
- egg_debug ("lid button CLOSED");
-
- } else if (strcmp (type, GPM_BUTTON_LID_OPEN) == 0) {
- gpm_info_event_log (info,
- GPM_EVENT_LID_OPENED,
- _("The laptop lid has been re-opened"));
- egg_debug ("lid button OPENED");
- }
-}
-
-/**
- * idle_changed_cb:
- * @idle: The idle class instance
- * @mode: The idle mode, e.g. GPM_IDLE_MODE_SESSION
- * @manager: This class instance
- *
- * This callback is called when gnome-screensaver detects that the idle state
- * has changed. GPM_IDLE_MODE_SESSION is when the session has become inactive,
- * and GPM_IDLE_MODE_SYSTEM is where the session has become inactive, AND the
- * session timeout has elapsed for the idle action.
- **/
-static void
-idle_changed_cb (GpmIdle *idle,
- GpmIdleMode mode,
- GpmInfo *info)
-{
- if (mode == GPM_IDLE_MODE_NORMAL) {
- gpm_info_event_log (info, GPM_EVENT_SESSION_ACTIVE, _("idle mode ended"));
- } else if (mode == GPM_IDLE_MODE_SESSION) {
- gpm_info_event_log (info, GPM_EVENT_SESSION_IDLE, _("idle mode started"));
- } else if (mode == GPM_IDLE_MODE_POWERSAVE) {
- gpm_info_event_log (info, GPM_EVENT_SESSION_POWERSAVE, _("powersave mode started"));
- }
-}
-
-/**
* dpms_mode_changed_cb:
* @mode: The DPMS mode, e.g. GPM_DPMS_MODE_OFF
* @info: This class instance
@@ -725,21 +631,18 @@
* Log when the DPMS mode is changed.
**/
static void
-dpms_mode_changed_cb (GpmDpms *dpms,
- GpmDpmsMode mode,
- GpmInfo *info)
+dpms_mode_changed_cb (GpmDpms *dpms, GpmDpmsMode mode, GpmInfo *info)
{
egg_debug ("DPMS mode changed: %d", mode);
- if (mode == GPM_DPMS_MODE_ON) {
+ if (mode == GPM_DPMS_MODE_ON)
gpm_info_event_log (info, GPM_EVENT_DPMS_ON, _("dpms on"));
- } else if (mode == GPM_DPMS_MODE_STANDBY) {
+ else if (mode == GPM_DPMS_MODE_STANDBY)
gpm_info_event_log (info, GPM_EVENT_DPMS_STANDBY, _("dpms standby"));
- } else if (mode == GPM_DPMS_MODE_SUSPEND) {
+ else if (mode == GPM_DPMS_MODE_SUSPEND)
gpm_info_event_log (info, GPM_EVENT_DPMS_SUSPEND, _("dpms suspend"));
- } else if (mode == GPM_DPMS_MODE_OFF) {
+ else if (mode == GPM_DPMS_MODE_OFF)
gpm_info_event_log (info, GPM_EVENT_DPMS_OFF, _("dpms off"));
- }
}
/**
@@ -750,30 +653,9 @@
* We have to update the caches on resume
**/
static void
-control_resume_cb (GpmControl *control,
- GpmControlAction action,
- GpmInfo *info)
+control_resume_cb (GpmControl *control, GpmControlAction action, GpmInfo *info)
{
- gpm_info_explain_reason (info, GPM_EVENT_RESUME,
- _("Resuming computer"), NULL);
-}
-
-/**
- * control_sleep_failure_cb:
- * @control: The control class instance
- * @info: This class instance
- *
- * We have to log if suspend failed
- **/
-static void
-control_sleep_failure_cb (GpmControl *control,
- GpmControlAction action,
- GpmInfo *info)
-{
- if (action == GPM_CONTROL_ACTION_HIBERNATE)
- gpm_info_event_log (info, GPM_EVENT_NOTIFICATION, _("Hibernate Problem"));
- else
- gpm_info_event_log (info, GPM_EVENT_NOTIFICATION, _("Suspend Problem"));
+ gpm_info_explain_reason (info, GPM_EVENT_RESUME, _("Resuming computer"), NULL);
}
/**
@@ -802,10 +684,7 @@
info->priv->timer = g_timer_new ();
info->priv->control = gpm_control_new ();
- g_signal_connect (info->priv->control, "resume",
- G_CALLBACK (control_resume_cb), info);
- g_signal_connect (info->priv->control, "sleep-failure",
- G_CALLBACK (control_sleep_failure_cb), info);
+ g_signal_connect (info->priv->control, "resume", G_CALLBACK (control_resume_cb), info);
/* find out if we should log and display the extra graphs */
hal_manager = hal_manager_new ();
@@ -815,25 +694,9 @@
/* set default, we have to set these from the manager */
info->priv->profile = gpm_profile_new ();
- /* we use ac_adapter so we can log the event */
- info->priv->ac_adapter = gpm_ac_adapter_new ();
- g_signal_connect (info->priv->ac_adapter, "ac-adapter-changed",
- G_CALLBACK (ac_adapter_changed_cb), info);
-
- /* watch for lid open/close */
- info->priv->button = gpm_button_new ();
- g_signal_connect (info->priv->button, "button-pressed",
- G_CALLBACK (button_pressed_cb), info);
-
- /* watch for idle mode changes */
- info->priv->idle = gpm_idle_new ();
- g_signal_connect (info->priv->idle, "idle-changed",
- G_CALLBACK (idle_changed_cb), info);
-
/* watch for dpms mode changes */
info->priv->dpms = gpm_dpms_new ();
- g_signal_connect (info->priv->dpms, "mode-changed",
- G_CALLBACK (dpms_mode_changed_cb), info);
+ g_signal_connect (info->priv->dpms, "mode-changed", G_CALLBACK (dpms_mode_changed_cb), info);
/* set to a blank list */
info->priv->events = gpm_array_new ();
@@ -882,26 +745,18 @@
info = GPM_INFO (object);
info->priv = GPM_INFO_GET_PRIVATE (info);
- if (info->priv->rate_data) {
+ if (info->priv->rate_data)
g_object_unref (info->priv->rate_data);
- }
- if (info->priv->percentage_data) {
+ if (info->priv->percentage_data)
g_object_unref (info->priv->percentage_data);
- }
- if (info->priv->time_data) {
+ if (info->priv->time_data)
g_object_unref (info->priv->time_data);
- }
- if (info->priv->voltage_data) {
+ if (info->priv->voltage_data)
g_object_unref (info->priv->voltage_data);
- }
- if (info->priv->dpms != NULL) {
+ if (info->priv->dpms != NULL)
g_object_unref (info->priv->dpms);
- }
- if (info->priv->control != NULL) {
+ if (info->priv->control != NULL)
g_object_unref (info->priv->control);
- }
- g_object_unref (info->priv->ac_adapter);
- g_object_unref (info->priv->idle);
g_object_unref (info->priv->events);
g_object_unref (info->priv->profile);
Modified: trunk/src/gpm-manager.c
==============================================================================
--- trunk/src/gpm-manager.c (original)
+++ trunk/src/gpm-manager.c Wed Oct 22 08:51:27 2008
@@ -878,10 +878,15 @@
* session timeout has elapsed for the idle action.
**/
static void
-idle_changed_cb (GpmIdle *idle,
- GpmIdleMode mode,
- GpmManager *manager)
+idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmManager *manager)
{
+ if (mode == GPM_IDLE_MODE_NORMAL)
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_SESSION_ACTIVE, _("idle mode ended"));
+ else if (mode == GPM_IDLE_MODE_SESSION)
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_SESSION_IDLE, _("idle mode started"));
+ else if (mode == GPM_IDLE_MODE_POWERSAVE)
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_SESSION_POWERSAVE, _("powersave mode started"));
+
/* Ignore timeout events when the lid is closed, as the DPMS is
* already off, and we don't want to perform policy actions or re-enable
* the screen when the user moves the mouse on systems that do not
@@ -1043,6 +1048,11 @@
{
egg_debug ("Button press event type=%s", type);
+ if (strcmp (type, GPM_BUTTON_LID_CLOSED) == 0)
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_LID_CLOSED, _("The laptop lid has been closed"));
+ else if (strcmp (type, GPM_BUTTON_LID_OPEN) == 0)
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_LID_OPENED, _("The laptop lid has been re-opened"));
+
if (strcmp (type, GPM_BUTTON_POWER) == 0) {
power_button_pressed (manager);
@@ -1075,26 +1085,27 @@
* Does the actions when the ac power source is inserted/removed.
**/
static void
-ac_adapter_changed_cb (GpmAcAdapter *ac_adapter,
- gboolean on_ac,
- GpmManager *manager)
+ac_adapter_changed_cb (GpmAcAdapter *ac_adapter, gboolean on_ac, GpmManager *manager)
{
gboolean event_when_closed;
gboolean power_save;
egg_debug ("Setting on-ac: %d", on_ac);
+ if (on_ac)
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_ON_AC, _("AC adapter inserted"));
+ else
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_ON_BATTERY, _("AC adapter removed"));
+
gpm_manager_sync_policy_sleep (manager);
- if (on_ac == FALSE)
+ if (on_ac)
+ gpm_manager_play (manager, GPM_MANAGER_SOUND_POWER_PLUG, FALSE);
+ else
gpm_manager_play (manager, GPM_MANAGER_SOUND_POWER_UNPLUG, FALSE);
egg_debug ("emitting on-ac-changed : %i", on_ac);
- if (on_ac) {
- g_signal_emit (manager, signals [ON_BATTERY_CHANGED], 0, FALSE);
- } else {
- g_signal_emit (manager, signals [ON_BATTERY_CHANGED], 0, TRUE);
- }
+ g_signal_emit (manager, signals [ON_BATTERY_CHANGED], 0, !on_ac);
on_ac = gpm_ac_adapter_is_present (manager->priv->ac_adapter);
if (on_ac)
@@ -1112,8 +1123,7 @@
/* We keep track of the lid state so we can do the
lid close on battery action if the ac_adapter is removed when the laptop
is closed. Fixes #331655 */
- if (event_when_closed &&
- on_ac == FALSE &&
+ if (event_when_closed && on_ac == FALSE &&
gpm_button_is_lid_closed (manager->priv->button)) {
manager_policy_do (manager, GPM_CONF_BUTTON_LID_BATT,
_("The lid has been closed, and the ac adapter "
@@ -1421,6 +1431,11 @@
{
gboolean show_sleep_failed;
+ if (action == GPM_CONTROL_ACTION_HIBERNATE)
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_NOTIFICATION, _("Hibernate Problem"));
+ else
+ gpm_info_event_log (manager->priv->info, GPM_EVENT_NOTIFICATION, _("Suspend Problem"));
+
/* only show this if specified in gconf */
show_sleep_failed = gconf_client_get_bool (manager->priv->conf, GPM_CONF_NOTIFY_SLEEP_FAILED, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]