[gnome-power-manager] trivial: remove 6 files and move the remaining functions to thier point of use
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-power-manager] trivial: remove 6 files and move the remaining functions to thier point of use
- Date: Fri, 5 Aug 2011 10:11:53 +0000 (UTC)
commit 8eef0da9441b7b16854c04245ff4099738ce3ba2
Author: Richard Hughes <richard hughsie com>
Date: Fri Aug 5 09:53:19 2011 +0100
trivial: remove 6 files and move the remaining functions to thier point of use
src/Makefile.am | 8 -
src/gpm-common.c | 260 -------------
src/gpm-common.h | 178 ---------
src/gpm-debug.c | 193 ----------
src/gpm-debug.h | 31 --
src/gpm-graph-widget.c | 80 ++++-
src/gpm-self-test.c | 398 --------------------
src/gpm-statistics.c | 348 +++++++++++++++++-
src/gpm-upower.c | 967 ------------------------------------------------
src/gpm-upower.h | 43 ---
10 files changed, 406 insertions(+), 2100 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 81b669e..ca022c1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,14 +29,8 @@ check_PROGRAMS = \
gnome-power-self-test
gnome_power_statistics_SOURCES = \
- gpm-debug.h \
- gpm-debug.c \
gpm-array-float.c \
gpm-array-float.h \
- gpm-common.h \
- gpm-common.c \
- gpm-upower.c \
- gpm-upower.h \
gpm-statistics.c \
gpm-point-obj.c \
gpm-point-obj.h \
@@ -54,8 +48,6 @@ gnome_power_statistics_CFLAGS = \
$(WARNINGFLAGS)
gnome_power_self_test_SOURCES = \
- gpm-common.h \
- gpm-common.c \
gpm-array-float.h \
gpm-array-float.c \
gpm-self-test.c
diff --git a/src/gpm-graph-widget.c b/src/gpm-graph-widget.c
index 39d881e..884864a 100644
--- a/src/gpm-graph-widget.c
+++ b/src/gpm-graph-widget.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2006-2007 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2006-2011 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -24,8 +24,8 @@
#include <pango/pangocairo.h>
#include <glib/gi18n.h>
#include <stdlib.h>
+#include <math.h>
-#include "gpm-common.h"
#include "gpm-point-obj.h"
#include "gpm-graph-widget.h"
@@ -585,6 +585,20 @@ gpm_graph_widget_draw_labels (GpmGraphWidget *graph, cairo_t *cr)
}
/**
+ * gpm_color_to_rgb:
+ * @red: The red value
+ * @green: The green value
+ * @blue: The blue value
+ **/
+static void
+gpm_color_to_rgb (guint32 color, guint8 *red, guint8 *green, guint8 *blue)
+{
+ *red = (color & 0xff0000) / 0x10000;
+ *green = (color & 0x00ff00) / 0x100;
+ *blue = color & 0x0000ff;
+}
+
+/**
* gpm_graph_widget_get_y_label_max_width:
* @graph: This class instance
* @cr: Cairo drawing context
@@ -615,6 +629,60 @@ gpm_graph_widget_get_y_label_max_width (GpmGraphWidget *graph, cairo_t *cr)
}
/**
+ * gpm_round_up:
+ * @value: The input value
+ * @smallest: The smallest increment allowed
+ *
+ * 101, 10 110
+ * 95, 10 100
+ * 0, 10 0
+ * 112, 10 120
+ * 100, 10 100
+ **/
+static gint
+gpm_round_up (gfloat value, gint smallest)
+{
+ gfloat division;
+ if (fabs (value) < 0.01)
+ return 0;
+ if (smallest == 0) {
+ g_warning ("divisor zero");
+ return 0;
+ }
+ division = (gfloat) value / (gfloat) smallest;
+ division = ceilf (division);
+ division *= smallest;
+ return (gint) division;
+}
+
+/**
+ * gpm_round_down:
+ * @value: The input value
+ * @smallest: The smallest increment allowed
+ *
+ * 101, 10 100
+ * 95, 10 90
+ * 0, 10 0
+ * 112, 10 110
+ * 100, 10 100
+ **/
+static gint
+gpm_round_down (gfloat value, gint smallest)
+{
+ gfloat division;
+ if (fabs (value) < 0.01)
+ return 0;
+ if (smallest == 0) {
+ g_warning ("divisor zero");
+ return 0;
+ }
+ division = (gfloat) value / (gfloat) smallest;
+ division = floorf (division);
+ division *= smallest;
+ return (gint) division;
+}
+
+/**
* gpm_graph_widget_autorange_x:
* @graph: This class instance
*
@@ -687,8 +755,8 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
rounding_x = 10 * 60;
}
- graph->priv->start_x = gpm_precision_round_down (smallest_x, rounding_x);
- graph->priv->stop_x = gpm_precision_round_up (biggest_x, rounding_x);
+ graph->priv->start_x = gpm_round_down (smallest_x, rounding_x);
+ graph->priv->stop_x = gpm_round_up (biggest_x, rounding_x);
g_debug ("Processed(1) range is %i<x<%i",
graph->priv->start_x, graph->priv->stop_x);
@@ -781,8 +849,8 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
rounding_y = 10 * 60;
}
- graph->priv->start_y = gpm_precision_round_down (smallest_y, rounding_y);
- graph->priv->stop_y = gpm_precision_round_up (biggest_y, rounding_y);
+ graph->priv->start_y = gpm_round_down (smallest_y, rounding_y);
+ graph->priv->stop_y = gpm_round_up (biggest_y, rounding_y);
/* a factor graph always is centered around zero */
if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
diff --git a/src/gpm-self-test.c b/src/gpm-self-test.c
index 9e995eb..ea6cee0 100644
--- a/src/gpm-self-test.c
+++ b/src/gpm-self-test.c
@@ -26,260 +26,8 @@
#include <glib-object.h>
#include <gtk/gtk.h>
-#include "gpm-idle.h"
-#include "gpm-common.h"
-#include "gpm-idletime.h"
#include "gpm-array-float.h"
-/** ver:1.0 ***********************************************************/
-static GMainLoop *_test_loop = NULL;
-static guint _test_loop_timeout_id = 0;
-
-static gboolean
-_g_test_hang_check_cb (gpointer user_data)
-{
- guint timeout_ms = *((guint*) user_data);
- g_main_loop_quit (_test_loop);
- g_warning ("loop not completed in %ims", timeout_ms);
- g_assert_not_reached ();
- return FALSE;
-}
-
-/**
- * _g_test_loop_run_with_timeout:
- **/
-static void
-_g_test_loop_run_with_timeout (guint timeout_ms)
-{
- g_assert (_test_loop_timeout_id == 0);
- _test_loop = g_main_loop_new (NULL, FALSE);
- _test_loop_timeout_id = g_timeout_add (timeout_ms, _g_test_hang_check_cb, &timeout_ms);
- g_main_loop_run (_test_loop);
-}
-
-#if 0
-static gboolean
-_g_test_hang_wait_cb (gpointer user_data)
-{
- g_main_loop_quit (_test_loop);
- _test_loop_timeout_id = 0;
- return FALSE;
-}
-
-/**
- * _g_test_loop_wait:
- **/
-static void
-_g_test_loop_wait (guint timeout_ms)
-{
- g_assert (_test_loop_timeout_id == 0);
- _test_loop = g_main_loop_new (NULL, FALSE);
- _test_loop_timeout_id = g_timeout_add (timeout_ms, _g_test_hang_wait_cb, &timeout_ms);
- g_main_loop_run (_test_loop);
-}
-#endif
-
-/**
- * _g_test_loop_quit:
- **/
-static void
-_g_test_loop_quit (void)
-{
- if (_test_loop_timeout_id > 0) {
- g_source_remove (_test_loop_timeout_id);
- _test_loop_timeout_id = 0;
- }
- if (_test_loop != NULL) {
- g_main_loop_quit (_test_loop);
- g_main_loop_unref (_test_loop);
- _test_loop = NULL;
- }
-}
-
-/**********************************************************************/
-
-static GpmIdleMode _mode = 0;
-
-static void
-gpm_test_idle_func_idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, gpointer user_data)
-{
- _mode = mode;
- g_debug ("idle-changed %s", gpm_idle_mode_to_string (mode));
- _g_test_loop_quit ();
-}
-
-static void
-gpm_test_idle_func (void)
-{
- GpmIdle *idle;
-// gboolean ret;
-// GpmDpms *dpms;
-
- idle = gpm_idle_new ();
- g_assert (idle != NULL);
-
- /* set up defaults */
- gpm_idle_set_timeout_dim (idle, 4);
- gpm_idle_set_timeout_blank (idle, 5);
- gpm_idle_set_timeout_sleep (idle, 15);
- g_signal_connect (idle, "idle-changed",
- G_CALLBACK (gpm_test_idle_func_idle_changed_cb), NULL);
-
- /* check normal at startup */
- g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_NORMAL);
-
- g_print ("*****************************\n");
- g_print ("*** DO NOT MOVE THE MOUSE ***\n");
- g_print ("*****************************\n");
- _g_test_loop_run_with_timeout (2000 + 10000);
-
- /* check callback mode */
- g_assert_cmpint (_mode, ==, GPM_IDLE_MODE_DIM);
-
- /* check current mode */
- g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_DIM);
-
- _g_test_loop_run_with_timeout (5000 + 1000);
-
- /* check callback mode */
- g_assert_cmpint (_mode, ==, GPM_IDLE_MODE_BLANK);
-
- /* check current mode */
- g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_BLANK);
-
- g_print ("**********************\n");
- g_print ("*** MOVE THE MOUSE ***\n");
- g_print ("**********************\n");
- _g_test_loop_run_with_timeout (G_MAXUINT);
-
- /* check callback mode */
- g_assert_cmpint (_mode, ==, GPM_IDLE_MODE_NORMAL);
-
- /* check current mode */
- g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_NORMAL);
-
- g_print ("*****************************\n");
- g_print ("*** DO NOT MOVE THE MOUSE ***\n");
- g_print ("*****************************\n");
- _g_test_loop_run_with_timeout (4000 + 1500);
-
- /* check current mode */
- g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_DIM);
-
- _g_test_loop_run_with_timeout (15000);
-
- /* check current mode */
- g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_BLANK);
-
- /* set dpms off */
-// dpms = gpm_dpms_new ();
-// ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_OFF, NULL);
-// g_assert (ret);
-
- /* wait for normal event to be suppressed */
-// g_timeout_add (2000, (GSourceFunc) gpm_test_idle_func_delay_cb, NULL);
- _g_test_loop_run_with_timeout (G_MAXUINT);
-
- /* check current mode */
- g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_BLANK);
-
-// gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, NULL);
-
- g_object_unref (idle);
-// g_object_unref (dpms);
-}
-
-static void
-gpm_test_precision_func (void)
-{
- g_assert_cmpint (gpm_precision_round_down (0, 10), ==, 0);
- g_assert_cmpint (gpm_precision_round_down (4, 10), ==, 0);
- g_assert_cmpint (gpm_precision_round_down (11, 10), ==, 10);
- g_assert_cmpint (gpm_precision_round_down (201, 2), ==, 200);
- g_assert_cmpint (gpm_precision_round_down (100, 10), ==, 100);
- g_assert_cmpint (gpm_precision_round_up (0, 10), ==, 0);
- g_assert_cmpint (gpm_precision_round_up (4, 10), ==, 10);
- g_assert_cmpint (gpm_precision_round_up (11, 10), ==, 20);
- g_assert_cmpint (gpm_precision_round_up (201, 2), ==, 202);
- g_assert_cmpint (gpm_precision_round_up (100, 10), ==, 100);
-}
-
-static void
-gpm_test_discrete_func (void)
-{
- gfloat fvalue;
-
- /* convert discrete levels */
- g_assert_cmpint (gpm_discrete_to_percent (0, 10), ==, 0);
- g_assert_cmpint (gpm_discrete_to_percent (9, 10), ==, 100);
-
- /* convert discrete 20/10 levels */
- g_assert_cmpint (gpm_discrete_to_percent (20, 10), ==, 100);
-
- /* convert discrete 0/10 levels */
- fvalue = gpm_discrete_to_fraction (0, 10);
- g_assert_cmpfloat (fvalue, >, -0.01);
- g_assert_cmpfloat (fvalue, <, 0.01);
-
- /* convert discrete 9/10 levels */
- fvalue = gpm_discrete_to_fraction (9, 10);
- g_assert_cmpfloat (fvalue, >, -1.01);
- g_assert_cmpfloat (fvalue, <, 1.01);
-}
-
-static void
-gpm_test_color_func (void)
-{
- guint8 r, g, b;
- guint32 color;
-
- /* get red */
- gpm_color_to_rgb (0xff0000, &r, &g, &b);
- g_assert_cmpint (r, ==, 255);
- g_assert_cmpint (g, ==, 0);
- g_assert_cmpint (b, ==, 0);
-
- /* get green */
- gpm_color_to_rgb (0x00ff00, &r, &g, &b);
- g_assert_cmpint (r, ==, 0);
- g_assert_cmpint (g, ==, 255);
- g_assert_cmpint (b, ==, 0);
-
- /* get blue */
- gpm_color_to_rgb (0x0000ff, &r, &g, &b);
- g_assert_cmpint (r, ==, 0);
- g_assert_cmpint (g, ==, 0);
- g_assert_cmpint (b, ==, 255);
-
- /* get black */
- gpm_color_to_rgb (0x000000, &r, &g, &b);
- g_assert_cmpint (r, ==, 0);
- g_assert_cmpint (g, ==, 0);
- g_assert_cmpint (b, ==, 0);
-
- /* get white */
- gpm_color_to_rgb (0xffffff, &r, &g, &b);
- g_assert_cmpint (r, ==, 255);
- g_assert_cmpint (g, ==, 255);
- g_assert_cmpint (b, ==, 255);
-
- /* set red */
- color = gpm_color_from_rgb (0xff, 0x00, 0x00);
- g_assert_cmpint (color, ==, 0xff0000);
-
- /* set green */
- color = gpm_color_from_rgb (0x00, 0xff, 0x00);
- g_assert_cmpint (color, ==, 0x00ff00);
-
- /* set blue */
- color = gpm_color_from_rgb (0x00, 0x00, 0xff);
- g_assert_cmpint (color, ==, 0x0000ff);
-
- /* set white */
- color = gpm_color_from_rgb (0xff, 0xff, 0xff);
- g_assert_cmpint (color, ==, 0xffffff);
-}
-
static void
gpm_test_array_float_func (void)
{
@@ -551,147 +299,6 @@ gpm_test_array_float_func (void)
gpm_array_float_free (kernel);
}
-static void
-gpm_test_idletime_wait (guint time_ms)
-{
- GTimer *ltimer = g_timer_new ();
- gfloat goal = time_ms / (gfloat) 1000.0f;
- do {
- g_main_context_iteration (NULL, FALSE);
- } while (g_timer_elapsed (ltimer, NULL) < goal);
- g_timer_destroy (ltimer);
-}
-
-static guint last_alarm = 0;
-static guint event_time;
-GTimer *timer;
-
-static void
-gpm_alarm_expired_cb (GpmIdletime *idletime, guint alarm_id, gpointer data)
-{
- last_alarm = alarm_id;
- event_time = g_timer_elapsed (timer, NULL) * (gfloat) 1000.0f;
-// g_print ("[evt %i in %ims]\n", alarm_id, event_time);
-}
-
-static void
-wait_until_alarm (void)
-{
- g_print ("*****************************\n");
- g_print ("*** DO NOT MOVE THE MOUSE ***\n");
- g_print ("*****************************\n");
- while (last_alarm == 0)
- g_main_context_iteration (NULL, FALSE);
-}
-
-static void
-wait_until_reset (void)
-{
- if (last_alarm == 0)
- return;
- g_print ("*****************************\n");
- g_print ("*** MOVE THE MOUSE ***\n");
- g_print ("*****************************\n");
- while (last_alarm != 0)
- g_main_context_iteration (NULL, FALSE);
- gpm_test_idletime_wait (1000);
-}
-
-static void
-gpm_test_idletime_func (void)
-{
- GpmIdletime *idletime;
- gboolean ret;
- guint i;
-
- timer = g_timer_new ();
- gdk_init (NULL, NULL);
-
- /* warn */
-
- g_timer_start (timer);
- /* check to see if delay works as expected */
- gpm_test_idletime_wait (2000);
- event_time = g_timer_elapsed (timer, NULL) * (gfloat) 1000.0f;
- g_assert_cmpfloat (event_time, >, 1800);
- g_assert_cmpfloat (event_time, <, 2200);
-
- /* make sure we get a non null device */
- idletime = gpm_idletime_new ();
- g_assert (idletime != NULL);
- g_signal_connect (idletime, "alarm-expired",
- G_CALLBACK (gpm_alarm_expired_cb), NULL);
-
- /* check if we are alarm zero with no alarms */
- g_assert_cmpint (last_alarm, ==, 0);
-
- /* check if we can set an reset alarm */
- ret = gpm_idletime_alarm_set (idletime, 0, 100);
- g_assert (!ret);
-
- /* check if we can set an alarm timeout of zero */
- ret = gpm_idletime_alarm_set (idletime, 999, 0);
- g_assert (!ret);
-
- g_timer_start (timer);
- /* check if we can set an alarm */
- ret = gpm_idletime_alarm_set (idletime, 101, 5000);
- g_assert (ret);
-
- gpm_idletime_alarm_set (idletime, 101, 5000);
- wait_until_alarm ();
-
- /* loop this two times */
- for (i=0; i<2; i++) {
- /* just let it time out, and wait for human input */
- wait_until_reset ();
- g_timer_start (timer);
-
- g_timer_start (timer);
- /* check if we can set an alarm */
- ret = gpm_idletime_alarm_set (idletime, 101, 5000);
- g_assert (ret);
-
- /* wait for alarm to go off */
- wait_until_alarm ();
- g_timer_start (timer);
-
- /* check if correct alarm has gone off */
- g_assert_cmpint (last_alarm, ==, 101);
-
- /* check if alarm has gone off in correct time */
- g_assert_cmpint (event_time, >, 3000);
- g_assert_cmpint (event_time, <, 6000);
- }
-
- /* just let it time out, and wait for human input */
- wait_until_reset ();
- g_timer_start (timer);
-
- g_timer_start (timer);
- /* check if we can set an existing alarm */
- ret = gpm_idletime_alarm_set (idletime, 101, 10000);
- g_assert (ret);
-
- /* wait for alarm to go off */
- wait_until_alarm ();
- g_timer_start (timer);
-
- /* check if alarm has gone off in the old time */
- g_assert_cmpint (event_time, >, 5000);
-
- /* check if we can remove an invalid alarm */
- ret = gpm_idletime_alarm_remove (idletime, 202);
- g_assert (!ret);
-
- /* check if we can remove an valid alarm */
- ret = gpm_idletime_alarm_remove (idletime, 101);
- g_assert (ret);
-
- g_timer_destroy (timer);
- g_object_unref (idletime);
-}
-
int
main (int argc, char **argv)
{
@@ -699,12 +306,7 @@ main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
/* tests go here */
- g_test_add_func ("/power/precision", gpm_test_precision_func);
- g_test_add_func ("/power/discrete", gpm_test_discrete_func);
- g_test_add_func ("/power/color", gpm_test_color_func);
g_test_add_func ("/power/array_float", gpm_test_array_float_func);
- g_test_add_func ("/power/idle", gpm_test_idle_func);
- g_test_add_func ("/power/idletime", gpm_test_idletime_func);
return g_test_run ();
}
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index 0d17695..5c9be3a 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2008-2011 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -22,18 +22,24 @@
#include "config.h"
#include <locale.h>
-
#include <glib.h>
#include <glib/gi18n.h>
-
#include <gtk/gtk.h>
#include <libupower-glib/upower.h>
#include "gpm-array-float.h"
-#include "gpm-common.h"
-#include "gpm-upower.h"
#include "gpm-graph-widget.h"
-#include "gpm-debug.h"
+
+#define GPM_SETTINGS_SCHEMA "org.gnome.power-manager"
+#define GPM_SETTINGS_INFO_HISTORY_TIME "info-history-time"
+#define GPM_SETTINGS_INFO_HISTORY_TYPE "info-history-type"
+#define GPM_SETTINGS_INFO_HISTORY_GRAPH_SMOOTH "info-history-graph-smooth"
+#define GPM_SETTINGS_INFO_HISTORY_GRAPH_POINTS "info-history-graph-points"
+#define GPM_SETTINGS_INFO_STATS_TYPE "info-stats-type"
+#define GPM_SETTINGS_INFO_STATS_GRAPH_SMOOTH "info-stats-graph-smooth"
+#define GPM_SETTINGS_INFO_STATS_GRAPH_POINTS "info-stats-graph-points"
+#define GPM_SETTINGS_INFO_PAGE_NUMBER "info-page-number"
+#define GPM_SETTINGS_INFO_LAST_DEVICE "info-last-device"
static GtkBuilder *builder = NULL;
static GtkListStore *list_store_info = NULL;
@@ -105,13 +111,312 @@ enum {
#define GPM_STATS_DISCHARGE_DATA_VALUE "discharge-data"
#define GPM_STATS_DISCHARGE_ACCURACY_VALUE "discharge-accuracy"
+#define GPM_UP_TIME_PRECISION 5*60 /* seconds */
+#define GPM_UP_TEXT_MIN_TIME 120 /* seconds */
+
/**
- * gpm_stats_button_help_cb:
+ * gpm_stats_get_device_icon_index:
+ * @device: The UpDevice
+ *
+ * Return value: The character string for the filename suffix.
**/
-static void
-gpm_stats_button_help_cb (GtkWidget *widget, gpointer user_data)
+static const gchar *
+gpm_stats_get_device_icon_index (UpDevice *device)
{
- gpm_help_display ("statistics");
+ gdouble percentage;
+ /* get device properties */
+ g_object_get (device, "percentage", &percentage, NULL);
+ if (percentage < 10)
+ return "000";
+ else if (percentage < 30)
+ return "020";
+ else if (percentage < 50)
+ return "040";
+ else if (percentage < 70)
+ return "060";
+ else if (percentage < 90)
+ return "080";
+ return "100";
+}
+
+/**
+ * gpm_stats_get_device_icon_suffix:
+ * @device: The UpDevice
+ *
+ * Return value: The character string for the filename suffix.
+ **/
+static const gchar *
+gpm_stats_get_device_icon_suffix (UpDevice *device)
+{
+ gdouble percentage;
+ /* get device properties */
+ g_object_get (device, "percentage", &percentage, NULL);
+ if (percentage < 10)
+ return "caution";
+ else if (percentage < 30)
+ return "low";
+ else if (percentage < 60)
+ return "good";
+ return "full";
+}
+
+/**
+ * gpm_stats_get_device_icon:
+ *
+ * Return value: The device icon, use g_object_unref() when done.
+ **/
+static GIcon *
+gpm_stats_get_device_icon (UpDevice *device, gboolean use_symbolic)
+{
+ GString *filename;
+ gchar **iconnames;
+ const gchar *kind_str;
+ const gchar *suffix_str;
+ const gchar *index_str;
+ UpDeviceKind kind;
+ UpDeviceState state;
+ gboolean is_present;
+ gdouble percentage;
+ GIcon *icon = NULL;
+
+ g_return_val_if_fail (device != NULL, NULL);
+
+ /* get device properties */
+ g_object_get (device,
+ "kind", &kind,
+ "state", &state,
+ "percentage", &percentage,
+ "is-present", &is_present,
+ NULL);
+
+ /* get correct icon prefix */
+ filename = g_string_new (NULL);
+
+ /* get the icon from some simple rules */
+ if (kind == UP_DEVICE_KIND_LINE_POWER) {
+ if (use_symbolic)
+ g_string_append (filename, "ac-adapter-symbolic;");
+ g_string_append (filename, "ac-adapter;");
+
+ } else if (kind == UP_DEVICE_KIND_MONITOR) {
+ if (use_symbolic)
+ g_string_append (filename, "gpm-monitor-symbolic;");
+ g_string_append (filename, "gpm-monitor;");
+
+ } else {
+
+ kind_str = up_device_kind_to_string (kind);
+ if (!is_present) {
+ if (use_symbolic)
+ g_string_append (filename, "battery-missing-symbolic;");
+ g_string_append_printf (filename, "gpm-%s-missing;", kind_str);
+ g_string_append_printf (filename, "gpm-%s-000;", kind_str);
+ g_string_append (filename, "battery-missing;");
+
+ } else {
+ switch (state) {
+ case UP_DEVICE_STATE_EMPTY:
+ if (use_symbolic)
+ g_string_append (filename, "battery-empty-symbolic;");
+ g_string_append_printf (filename, "gpm-%s-empty;", kind_str);
+ g_string_append_printf (filename, "gpm-%s-000;", kind_str);
+ g_string_append (filename, "battery-empty;");
+ break;
+ case UP_DEVICE_STATE_FULLY_CHARGED:
+ if (use_symbolic) {
+ g_string_append (filename, "battery-full-charged-symbolic;");
+ g_string_append (filename, "battery-full-charging-symbolic;");
+ }
+ g_string_append_printf (filename, "gpm-%s-full;", kind_str);
+ g_string_append_printf (filename, "gpm-%s-100;", kind_str);
+ g_string_append (filename, "battery-full-charged;");
+ g_string_append (filename, "battery-full-charging;");
+ break;
+ case UP_DEVICE_STATE_CHARGING:
+ case UP_DEVICE_STATE_PENDING_CHARGE:
+ suffix_str = gpm_stats_get_device_icon_suffix (device);
+ index_str = gpm_stats_get_device_icon_index (device);
+ if (use_symbolic)
+ g_string_append_printf (filename, "battery-%s-charging-symbolic;", suffix_str);
+ g_string_append_printf (filename, "gpm-%s-%s-charging;", kind_str, index_str);
+ g_string_append_printf (filename, "battery-%s-charging;", suffix_str);
+ break;
+ case UP_DEVICE_STATE_DISCHARGING:
+ case UP_DEVICE_STATE_PENDING_DISCHARGE:
+ suffix_str = gpm_stats_get_device_icon_suffix (device);
+ index_str = gpm_stats_get_device_icon_index (device);
+ if (use_symbolic)
+ g_string_append_printf (filename, "battery-%s-symbolic;", suffix_str);
+ g_string_append_printf (filename, "gpm-%s-%s;", kind_str, index_str);
+ g_string_append_printf (filename, "battery-%s;", suffix_str);
+ break;
+ default:
+ if (use_symbolic)
+ g_string_append (filename, "battery-missing-symbolic;");
+ g_string_append (filename, "gpm-battery-missing;");
+ g_string_append (filename, "battery-missing;");
+ }
+ }
+ }
+
+ /* nothing matched */
+ if (filename->len == 0) {
+ g_warning ("nothing matched, falling back to default icon");
+ g_string_append (filename, "dialog-warning;");
+ }
+
+ g_debug ("got filename: %s", filename->str);
+
+ iconnames = g_strsplit (filename->str, ";", -1);
+ icon = g_themed_icon_new_from_names (iconnames, -1);
+
+ g_strfreev (iconnames);
+ g_string_free (filename, TRUE);
+ return icon;
+}
+
+/**
+ * gpm_device_kind_to_localised_string:
+ **/
+static const gchar *
+gpm_device_kind_to_localised_string (UpDeviceKind kind, guint number)
+{
+ const gchar *text = NULL;
+ switch (kind) {
+ case UP_DEVICE_KIND_LINE_POWER:
+ /* TRANSLATORS: system power cord */
+ text = ngettext ("AC adapter", "AC adapters", number);
+ break;
+ case UP_DEVICE_KIND_BATTERY:
+ /* TRANSLATORS: laptop primary battery */
+ text = ngettext ("Laptop battery", "Laptop batteries", number);
+ break;
+ case UP_DEVICE_KIND_UPS:
+ /* TRANSLATORS: battery-backed AC power source */
+ text = ngettext ("UPS", "UPSs", number);
+ break;
+ case UP_DEVICE_KIND_MONITOR:
+ /* TRANSLATORS: a monitor is a device to measure voltage and current */
+ text = ngettext ("Monitor", "Monitors", number);
+ break;
+ case UP_DEVICE_KIND_MOUSE:
+ /* TRANSLATORS: wireless mice with internal batteries */
+ text = ngettext ("Mouse", "Mice", number);
+ break;
+ case UP_DEVICE_KIND_KEYBOARD:
+ /* TRANSLATORS: wireless keyboard with internal battery */
+ text = ngettext ("Keyboard", "Keyboards", number);
+ break;
+ case UP_DEVICE_KIND_PDA:
+ /* TRANSLATORS: portable device */
+ text = ngettext ("PDA", "PDAs", number);
+ break;
+ case UP_DEVICE_KIND_PHONE:
+ /* TRANSLATORS: cell phone (mobile...) */
+ text = ngettext ("Cell phone", "Cell phones", number);
+ break;
+#if UP_CHECK_VERSION(0,9,5)
+ case UP_DEVICE_KIND_MEDIA_PLAYER:
+ /* TRANSLATORS: media player, mp3 etc */
+ text = ngettext ("Media player", "Media players", number);
+ break;
+ case UP_DEVICE_KIND_TABLET:
+ /* TRANSLATORS: tablet device */
+ text = ngettext ("Tablet", "Tablets", number);
+ break;
+ case UP_DEVICE_KIND_COMPUTER:
+ /* TRANSLATORS: tablet device */
+ text = ngettext ("Computer", "Computers", number);
+ break;
+#endif
+ default:
+ g_warning ("enum unrecognised: %i", kind);
+ text = up_device_kind_to_string (kind);
+ }
+ return text;
+}
+
+/**
+ * gpm_device_technology_to_localised_string:
+ **/
+static const gchar *
+gpm_device_technology_to_localised_string (UpDeviceTechnology technology_enum)
+{
+ const gchar *technology = NULL;
+ switch (technology_enum) {
+ case UP_DEVICE_TECHNOLOGY_LITHIUM_ION:
+ /* TRANSLATORS: battery technology */
+ technology = _("Lithium Ion");
+ break;
+ case UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER:
+ /* TRANSLATORS: battery technology */
+ technology = _("Lithium Polymer");
+ break;
+ case UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE:
+ /* TRANSLATORS: battery technology */
+ technology = _("Lithium Iron Phosphate");
+ break;
+ case UP_DEVICE_TECHNOLOGY_LEAD_ACID:
+ /* TRANSLATORS: battery technology */
+ technology = _("Lead acid");
+ break;
+ case UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM:
+ /* TRANSLATORS: battery technology */
+ technology = _("Nickel Cadmium");
+ break;
+ case UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE:
+ /* TRANSLATORS: battery technology */
+ technology = _("Nickel metal hydride");
+ break;
+ case UP_DEVICE_TECHNOLOGY_UNKNOWN:
+ /* TRANSLATORS: battery technology */
+ technology = _("Unknown technology");
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ return technology;
+}
+
+/**
+ * gpm_device_state_to_localised_string:
+ **/
+static const gchar *
+gpm_device_state_to_localised_string (UpDeviceState state)
+{
+ const gchar *state_string = NULL;
+
+ switch (state) {
+ case UP_DEVICE_STATE_CHARGING:
+ /* TRANSLATORS: battery state */
+ state_string = _("Charging");
+ break;
+ case UP_DEVICE_STATE_DISCHARGING:
+ /* TRANSLATORS: battery state */
+ state_string = _("Discharging");
+ break;
+ case UP_DEVICE_STATE_EMPTY:
+ /* TRANSLATORS: battery state */
+ state_string = _("Empty");
+ break;
+ case UP_DEVICE_STATE_FULLY_CHARGED:
+ /* TRANSLATORS: battery state */
+ state_string = _("Charged");
+ break;
+ case UP_DEVICE_STATE_PENDING_CHARGE:
+ /* TRANSLATORS: battery state */
+ state_string = _("Waiting to charge");
+ break;
+ case UP_DEVICE_STATE_PENDING_DISCHARGE:
+ /* TRANSLATORS: battery state */
+ state_string = _("Waiting to discharge");
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ return state_string;
}
/**
@@ -542,6 +847,22 @@ gpm_stats_set_graph_data (GtkWidget *widget, GPtrArray *data, gboolean use_smoot
}
/**
+ * gpm_color_from_rgb:
+ * @red: The red value
+ * @green: The green value
+ * @blue: The blue value
+ **/
+static guint32
+gpm_color_from_rgb (guint8 red, guint8 green, guint8 blue)
+{
+ guint32 color = 0;
+ color += (guint32) red * 0x10000;
+ color += (guint32) green * 0x100;
+ color += (guint32) blue;
+ return color;
+}
+
+/**
* gpm_stats_update_info_page_history:
**/
static void
@@ -1184,7 +1505,7 @@ gpm_stats_add_device (UpDevice *device)
id = up_device_get_object_path (device);
text = gpm_device_kind_to_localised_string (kind, 1);
- icon = gpm_upower_get_device_icon (device, FALSE);
+ icon = gpm_stats_get_device_icon (device, FALSE);
gtk_list_store_append (list_store_devices, &iter);
gtk_list_store_set (list_store_devices, &iter,
@@ -1538,7 +1859,6 @@ gpm_stats_commandline_cb (GApplication *application,
/* TRANSLATORS: the program name */
g_option_context_set_summary (context, _("Power Statistics"));
g_option_context_add_main_entries (context, options, NULL);
- g_option_context_add_group (context, gpm_debug_get_option_group ());
ret = g_option_context_parse (context, &argc, &argv, NULL);
if (!ret)
goto out;
@@ -1624,10 +1944,6 @@ gpm_stats_startup_cb (GApplication *application,
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
gtk_widget_grab_default (widget);
- widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"));
- g_signal_connect (widget, "clicked",
- G_CALLBACK (gpm_stats_button_help_cb), NULL);
-
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_history"));
checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_SMOOTH);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), checked);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]