gnome-power-manager r2922 - in trunk: . src
- From: rhughes svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-power-manager r2922 - in trunk: . src
- Date: Thu, 4 Sep 2008 17:05:42 +0000 (UTC)
Author: rhughes
Date: Thu Sep 4 17:05:42 2008
New Revision: 2922
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=2922&view=rev
Log:
2008-09-04 Richard Hughes <richard hughsie com>
* src/Makefile.am:
* src/egg-color.c: (egg_color_test):
* src/egg-color.h:
* src/egg-discrete.c: (egg_discrete_from_percent),
(egg_discrete_to_percent), (egg_discrete_to_fraction),
(egg_discrete_test):
* src/egg-discrete.h:
* src/egg-precision.c: (egg_precision_round_up),
(egg_precision_round_down), (egg_precision_test):
* src/egg-precision.h:
* src/egg-test.c: (egg_test_start):
* src/gpm-brightness-hal.c: (gpm_brightness_hal_set),
(gpm_brightness_hal_get):
* src/gpm-brightness-kbd.c: (gpm_brightness_kbd_set_dim),
(gpm_brightness_kbd_set_std), (gpm_brightness_kbd_get),
(gpm_brightness_kbd_up), (gpm_brightness_kbd_down):
* src/gpm-brightness-xrandr.c:
(gpm_brightness_xrandr_output_get_percentage),
(gpm_brightness_xrandr_output_set):
* src/gpm-cell-array.c: (gpm_cell_array_get_description):
* src/gpm-common.c: (gpm_common_test):
* src/gpm-common.h:
* src/gpm-graph-widget.c: (gpm_graph_widget_auto_range):
* src/gpm-light-sensor.c: (gpm_light_sensor_get_absolute),
(gpm_light_sensor_calibrate), (gpm_light_sensor_get_relative):
* src/gpm-self-test.c: (main):
Use and generate more egg code.
Added:
trunk/src/egg-discrete.c
trunk/src/egg-discrete.h
trunk/src/egg-precision.c
trunk/src/egg-precision.h
Modified:
trunk/ChangeLog
trunk/src/Makefile.am
trunk/src/egg-color.c
trunk/src/egg-color.h
trunk/src/egg-test.c
trunk/src/gpm-brightness-hal.c
trunk/src/gpm-brightness-kbd.c
trunk/src/gpm-brightness-xrandr.c
trunk/src/gpm-cell-array.c
trunk/src/gpm-common.c
trunk/src/gpm-common.h
trunk/src/gpm-graph-widget.c
trunk/src/gpm-light-sensor.c
trunk/src/gpm-self-test.c
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Thu Sep 4 17:05:42 2008
@@ -60,6 +60,10 @@
egg-debug.c \
egg-unique.h \
egg-unique.c \
+ egg-precision.h \
+ egg-precision.c \
+ egg-discrete.h \
+ egg-discrete.c \
gpm-statistics.c \
gpm-statistics-core.h \
gpm-statistics-core.c \
@@ -137,6 +141,10 @@
egg-debug.c \
egg-dbus-monitor.h \
egg-dbus-monitor.c \
+ egg-precision.h \
+ egg-precision.c \
+ egg-discrete.h \
+ egg-discrete.c \
gpm-dpms.h \
gpm-dpms.c \
gpm-notify.h \
@@ -245,6 +253,10 @@
egg-debug.c \
egg-dbus-monitor.h \
egg-dbus-monitor.c \
+ egg-precision.h \
+ egg-precision.c \
+ egg-discrete.h \
+ egg-discrete.c \
gpm-ac-adapter.h \
gpm-ac-adapter.c \
gpm-prefs-server.h \
Modified: trunk/src/egg-color.c
==============================================================================
--- trunk/src/egg-color.c (original)
+++ trunk/src/egg-color.c Thu Sep 4 17:05:42 2008
@@ -54,99 +54,101 @@
/***************************************************************************
*** MAKE CHECK TESTS ***
***************************************************************************/
-#ifdef EGG_BUILD_TESTS
-#include "egg-self-test.h"
+#ifdef EGG_TEST
+#include "egg-test.h"
void
-egg_st_color (EggSelfTest *test)
+egg_color_test (EggTest *test)
{
guint8 r, g, b;
guint32 colour;
- if (egg_st_start (test, "EggColor") == FALSE) {
+ if (egg_test_start (test, "EggColor") == FALSE) {
return;
}
/************************************************************/
- egg_st_title (test, "get red");
+ egg_test_title (test, "get red");
egg_color_to_rgb (0xff0000, &r, &g, &b);
if (r == 255 && g == 0 && b == 0) {
- egg_st_success (test, "got red");
+ egg_test_success (test, "got red");
} else {
- egg_st_failed (test, "could not get red (%i, %i, %i)", r, g, b);
+ egg_test_failed (test, "could not get red (%i, %i, %i)", r, g, b);
}
/************************************************************/
- egg_st_title (test, "get green");
+ egg_test_title (test, "get green");
egg_color_to_rgb (0x00ff00, &r, &g, &b);
if (r == 0 && g == 255 && b == 0) {
- egg_st_success (test, "got green");
+ egg_test_success (test, "got green");
} else {
- egg_st_failed (test, "could not get green (%i, %i, %i)", r, g, b);
+ egg_test_failed (test, "could not get green (%i, %i, %i)", r, g, b);
}
/************************************************************/
- egg_st_title (test, "get blue");
+ egg_test_title (test, "get blue");
egg_color_to_rgb (0x0000ff, &r, &g, &b);
if (r == 0 && g == 0 && b == 255) {
- egg_st_success (test, "got blue");
+ egg_test_success (test, "got blue");
} else {
- egg_st_failed (test, "could not get blue (%i, %i, %i)", r, g, b);
+ egg_test_failed (test, "could not get blue (%i, %i, %i)", r, g, b);
}
/************************************************************/
- egg_st_title (test, "get black");
+ egg_test_title (test, "get black");
egg_color_to_rgb (0x000000, &r, &g, &b);
if (r == 0 && g == 0 && b == 0) {
- egg_st_success (test, "got black");
+ egg_test_success (test, "got black");
} else {
- egg_st_failed (test, "could not get black (%i, %i, %i)", r, g, b);
+ egg_test_failed (test, "could not get black (%i, %i, %i)", r, g, b);
}
/************************************************************/
- egg_st_title (test, "get white");
+ egg_test_title (test, "get white");
egg_color_to_rgb (0xffffff, &r, &g, &b);
if (r == 255 && g == 255 && b == 255) {
- egg_st_success (test, "got white");
+ egg_test_success (test, "got white");
} else {
- egg_st_failed (test, "could not get white (%i, %i, %i)", r, g, b);
+ egg_test_failed (test, "could not get white (%i, %i, %i)", r, g, b);
}
/************************************************************/
- egg_st_title (test, "set red");
+ egg_test_title (test, "set red");
colour = egg_color_from_rgb (0xff, 0x00, 0x00);
if (colour == 0xff0000) {
- egg_st_success (test, "set red");
+ egg_test_success (test, "set red");
} else {
- egg_st_failed (test, "could not set red (%i)", colour);
+ egg_test_failed (test, "could not set red (%i)", colour);
}
/************************************************************/
- egg_st_title (test, "set green");
+ egg_test_title (test, "set green");
colour = egg_color_from_rgb (0x00, 0xff, 0x00);
if (colour == 0x00ff00) {
- egg_st_success (test, "set green");
+ egg_test_success (test, "set green");
} else {
- egg_st_failed (test, "could not set green (%i)", colour);
+ egg_test_failed (test, "could not set green (%i)", colour);
}
/************************************************************/
- egg_st_title (test, "set blue");
+ egg_test_title (test, "set blue");
colour = egg_color_from_rgb (0x00, 0x00, 0xff);
if (colour == 0x0000ff) {
- egg_st_success (test, "set blue");
+ egg_test_success (test, "set blue");
} else {
- egg_st_failed (test, "could not set blue (%i)", colour);
+ egg_test_failed (test, "could not set blue (%i)", colour);
}
/************************************************************/
- egg_st_title (test, "set white");
+ egg_test_title (test, "set white");
colour = egg_color_from_rgb (0xff, 0xff, 0xff);
if (colour == 0xffffff) {
- egg_st_success (test, "set white");
+ egg_test_success (test, "set white");
} else {
- egg_st_failed (test, "could not set white (%i)", colour);
+ egg_test_failed (test, "could not set white (%i)", colour);
}
+
+ egg_test_end (test);
}
#endif
Modified: trunk/src/egg-color.h
==============================================================================
--- trunk/src/egg-color.h (original)
+++ trunk/src/egg-color.h Thu Sep 4 17:05:42 2008
@@ -24,6 +24,7 @@
#include <glib.h>
+G_BEGIN_DECLS
#define EGG_COLOR_WHITE 0xffffff
#define EGG_COLOR_BLACK 0x000000
@@ -42,8 +43,6 @@
#define EGG_COLOR_DARK_YELLOW 0x606000
#define EGG_COLOR_DARK_GREY 0x606060
-G_BEGIN_DECLS
-
guint32 egg_color_from_rgb (guint8 red,
guint8 green,
guint8 blue);
Added: trunk/src/egg-discrete.c
==============================================================================
--- (empty file)
+++ trunk/src/egg-discrete.c Thu Sep 4 17:05:42 2008
@@ -0,0 +1,161 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2008 Richard Hughes <richard hughsie 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.
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include "egg-debug.h"
+#include "egg-discrete.h"
+
+/**
+ * egg_discrete_from_percent:
+ * @percentage: The percentage to convert
+ * @levels: The number of discrete levels
+ *
+ * We have to be carefull when converting from %->discrete as precision is very
+ * important if we want the highest value.
+ *
+ * Return value: The discrete value for this percentage.
+ **/
+guint
+egg_discrete_from_percent (guint percentage, guint levels)
+{
+ /* check we are in range */
+ if (percentage > 100)
+ return levels;
+ if (levels == 0) {
+ egg_warning ("levels is 0!");
+ return 0;
+ }
+ return ((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f;
+}
+
+/**
+ * egg_discrete_to_percent:
+ * @hw: The discrete level
+ * @levels: The number of discrete levels
+ *
+ * We have to be carefull when converting from discrete->%.
+ *
+ * Return value: The percentage for this discrete value.
+ **/
+guint
+egg_discrete_to_percent (guint discrete, guint levels)
+{
+ /* check we are in range */
+ if (discrete > levels)
+ return 100;
+ if (levels == 0) {
+ egg_warning ("levels is 0!");
+ return 0;
+ }
+ return (guint) ((gfloat) discrete * (100.0f / (gfloat) (levels - 1)));
+}
+
+/**
+ * egg_discrete_to_fraction:
+ * @hw: The discrete level
+ * @levels: The number of discrete levels
+ *
+ * We have to be careful when converting from discrete->fractions.
+ *
+ * Return value: The floating point fraction (0..1) for this discrete value.
+ **/
+gfloat
+egg_discrete_to_fraction (guint discrete, guint levels)
+{
+ /* check we are in range */
+ if (discrete > levels)
+ return 1.0;
+ if (levels == 0) {
+ egg_warning ("levels is 0!");
+ return 0.0;
+ }
+ return (guint) ((gfloat) discrete / ((gfloat) (levels - 1)));
+}
+
+/***************************************************************************
+ *** MAKE CHECK TESTS ***
+ ***************************************************************************/
+#ifdef EGG_TEST
+#include "egg-test.h"
+
+void
+egg_discrete_test (EggTest *test)
+{
+ guint value;
+ gfloat fvalue;
+
+ if (!egg_test_start (test, "EggDiscrete"))
+ return;
+
+ /************************************************************/
+ egg_test_title (test, "convert discrete 0/10 levels");
+ value = egg_discrete_to_percent (0, 10);
+ if (value == 0) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "conversion incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "convert discrete 9/10 levels");
+ value = egg_discrete_to_percent (9, 10);
+ if (value == 100) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "conversion incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "convert discrete 20/10 levels");
+ value = egg_discrete_to_percent (20, 10);
+ if (value == 100) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "conversion incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "convert discrete 0/10 levels");
+ fvalue = egg_discrete_to_fraction (0, 10);
+ if (fvalue > -0.01 && fvalue < 0.01) {
+ egg_test_success (test, "got %f", fvalue);
+ } else {
+ egg_test_failed (test, "conversion incorrect (%f)", fvalue);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "convert discrete 9/10 levels");
+ fvalue = egg_discrete_to_fraction (9, 10);
+ if (fvalue > -1.01 && fvalue < 1.01) {
+ egg_test_success (test, "got %f", fvalue);
+ } else {
+ egg_test_failed (test, "conversion incorrect (%f)", fvalue);
+ }
+
+ egg_test_end (test);
+}
+
+#endif
+
Added: trunk/src/egg-discrete.h
==============================================================================
--- (empty file)
+++ trunk/src/egg-discrete.h Thu Sep 4 17:05:42 2008
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2008 Richard Hughes <richard hughsie 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 __EGG_DISCRETE_H
+#define __EGG_DISCRETE_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+guint egg_discrete_from_percent (guint percentage,
+ guint levels);
+guint egg_discrete_to_percent (guint discrete,
+ guint levels);
+gfloat egg_discrete_to_fraction (guint discrete,
+ guint levels);
+
+G_END_DECLS
+
+#endif /* __EGG_DISCRETE_H */
Added: trunk/src/egg-precision.c
==============================================================================
--- (empty file)
+++ trunk/src/egg-precision.c Thu Sep 4 17:05:42 2008
@@ -0,0 +1,190 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2008 Richard Hughes <richard hughsie 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.
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include "egg-debug.h"
+
+/**
+ * egg_precision_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
+ **/
+gint
+egg_precision_round_up (gfloat value, gint smallest)
+{
+ gfloat division;
+ if (fabs (value) < 0.01)
+ return 0;
+ if (smallest == 0) {
+ egg_warning ("divisor zero");
+ return 0;
+ }
+ division = (gfloat) value / (gfloat) smallest;
+ division = ceilf (division);
+ division *= smallest;
+ return (gint) division;
+}
+
+/**
+ * egg_precision_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
+ **/
+gint
+egg_precision_round_down (gfloat value, gint smallest)
+{
+ gfloat division;
+ if (fabs (value) < 0.01)
+ return 0;
+ if (smallest == 0) {
+ egg_warning ("divisor zero");
+ return 0;
+ }
+ division = (gfloat) value / (gfloat) smallest;
+ division = floorf (division);
+ division *= smallest;
+ return (gint) division;
+}
+
+/***************************************************************************
+ *** MAKE CHECK TESTS ***
+ ***************************************************************************/
+#ifdef EGG_TEST
+#include "egg-test.h"
+
+void
+egg_precision_test (EggTest *test)
+{
+ guint value;
+
+ if (!egg_test_start (test, "EggPrecision"))
+ return;
+
+ /************************************************************/
+ egg_test_title (test, "limit precision down 0,10");
+ value = egg_precision_round_down (0, 10);
+ if (value == 0) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision down 4,10");
+ value = egg_precision_round_down (4, 10);
+ if (value == 0) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision down 11,10");
+ value = egg_precision_round_down (11, 10);
+ if (value == 10) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision down 201,2");
+ value = egg_precision_round_down (201, 2);
+ if (value == 200) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision down 100,10");
+ value = egg_precision_round_down (100, 10);
+ if (value == 100) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision up 0,10");
+ value = egg_precision_round_up (0, 10);
+ if (value == 0) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision up 4,10");
+ value = egg_precision_round_up (4, 10);
+ if (value == 10) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision up 11,10");
+ value = egg_precision_round_up (11, 10);
+ if (value == 20) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision up 201,2");
+ value = egg_precision_round_up (201, 2);
+ if (value == 202) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "limit precision up 100,10");
+ value = egg_precision_round_up (100, 10);
+ if (value == 100) {
+ egg_test_success (test, "got %i", value);
+ } else {
+ egg_test_failed (test, "precision incorrect (%i)", value);
+ }
+
+ egg_test_end (test);
+}
+
+#endif
+
Added: trunk/src/egg-precision.h
==============================================================================
--- (empty file)
+++ trunk/src/egg-precision.h Thu Sep 4 17:05:42 2008
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2008 Richard Hughes <richard hughsie 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 __EGG_PRECISION_H
+#define __EGG_PRECISION_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+guint egg_precision_round_up (gfloat value,
+ gint smallest);
+guint egg_precision_round_down (gfloat value,
+ gint smallest);
+
+G_END_DECLS
+
+#endif /* __EGG_PRECISION_H */
Modified: trunk/src/egg-test.c
==============================================================================
--- trunk/src/egg-test.c (original)
+++ trunk/src/egg-test.c Thu Sep 4 17:05:42 2008
@@ -173,7 +173,6 @@
}
test->type = g_strdup (name);
test->started = TRUE;
- g_print ("%s...", test->type);
return TRUE;
}
Modified: trunk/src/gpm-brightness-hal.c
==============================================================================
--- trunk/src/gpm-brightness-hal.c (original)
+++ trunk/src/gpm-brightness-hal.c Thu Sep 4 17:05:42 2008
@@ -42,10 +42,12 @@
#include <libhal-gmanager.h>
#include <libdbus-proxy.h>
+#include "egg-debug.h"
+#include "egg-discrete.h"
+
#include "gpm-brightness.h"
#include "gpm-brightness-hal.h"
#include "gpm-common.h"
-#include "egg-debug.h"
#include "gpm-marshal.h"
#define GPM_BRIGHTNESS_HAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_BRIGHTNESS_HAL, GpmBrightnessHalPrivate))
@@ -265,7 +267,7 @@
/* reset to not-changed */
brightness->priv->hw_changed = FALSE;
- level_hw = gpm_percent_to_discrete (percentage, brightness->priv->levels);
+ level_hw = egg_discrete_from_percent (percentage, brightness->priv->levels);
brightness->priv->level_std_hw = level_hw;
/* update */
@@ -289,7 +291,7 @@
{
g_return_val_if_fail (GPM_IS_BRIGHTNESS_HAL (brightness), FALSE);
- *percentage = gpm_discrete_to_percent (brightness->priv->last_set_hw,
+ *percentage = egg_discrete_to_percent (brightness->priv->last_set_hw,
brightness->priv->levels);
return TRUE;
}
Modified: trunk/src/gpm-brightness-kbd.c
==============================================================================
--- trunk/src/gpm-brightness-kbd.c (original)
+++ trunk/src/gpm-brightness-kbd.c Thu Sep 4 17:05:42 2008
@@ -43,10 +43,12 @@
#include <libhal-gmanager.h>
#include <libdbus-proxy.h>
+#include "egg-debug.h"
+#include "egg-discrete.h"
+
#include "gpm-brightness-kbd.h"
#include "gpm-conf.h"
#include "gpm-common.h"
-#include "egg-debug.h"
#include "gpm-light-sensor.h"
#include "gpm-marshal.h"
@@ -283,7 +285,7 @@
g_return_val_if_fail (brightness != NULL, FALSE);
g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
- level_hw = gpm_percent_to_discrete (brightness_level, brightness->priv->levels);
+ level_hw = egg_discrete_from_percent (brightness_level, brightness->priv->levels);
/* If the current brightness_kbd is less than the dim brightness_kbd then just
* use the current brightness_kbd so that we don't *increase* in brightness_kbd
@@ -316,7 +318,7 @@
g_return_val_if_fail (brightness != NULL, FALSE);
g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
- level_hw = gpm_percent_to_discrete (brightness_level,
+ level_hw = egg_discrete_from_percent (brightness_level,
brightness->priv->levels);
brightness->priv->level_std_hw = level_hw;
@@ -388,7 +390,7 @@
g_return_val_if_fail (brightness != NULL, FALSE);
g_return_val_if_fail (GPM_IS_BRIGHTNESS_KBD (brightness), FALSE);
- percentage = gpm_discrete_to_percent (brightness->priv->current_hw,
+ percentage = egg_discrete_to_percent (brightness->priv->current_hw,
brightness->priv->levels);
*brightness_level = percentage;
return TRUE;
@@ -422,7 +424,7 @@
gpm_brightness_kbd_set_hw (brightness, brightness->priv->current_hw + step);
}
- percentage = gpm_discrete_to_percent (brightness->priv->current_hw,
+ percentage = egg_discrete_to_percent (brightness->priv->current_hw,
brightness->priv->levels);
egg_debug ("emitting brightness-changed (%i)", percentage);
g_signal_emit (brightness, signals [BRIGHTNESS_CHANGED], 0, percentage);
@@ -458,7 +460,7 @@
gpm_brightness_kbd_set_hw (brightness, brightness->priv->current_hw - step);
}
- percentage = gpm_discrete_to_percent (brightness->priv->current_hw,
+ percentage = egg_discrete_to_percent (brightness->priv->current_hw,
brightness->priv->levels);
egg_debug ("emitting brightness-changed (%i)", percentage);
g_signal_emit (brightness, signals [BRIGHTNESS_CHANGED], 0, percentage);
Modified: trunk/src/gpm-brightness-xrandr.c
==============================================================================
--- trunk/src/gpm-brightness-xrandr.c (original)
+++ trunk/src/gpm-brightness-xrandr.c Thu Sep 4 17:05:42 2008
@@ -43,10 +43,12 @@
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
+#include "egg-debug.h"
+#include "egg-discrete.h"
+
#include "gpm-brightness.h"
#include "gpm-brightness-xrandr.h"
#include "gpm-common.h"
-#include "egg-debug.h"
#include "gpm-marshal.h"
#define GPM_BRIGHTNESS_XRANDR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_BRIGHTNESS_XRANDR, GpmBrightnessXRandRPrivate))
@@ -221,7 +223,7 @@
return FALSE;
}
egg_debug ("hard value=%i, min=%i, max=%i", cur, min, max);
- percentage = gpm_discrete_to_percent (cur, (max-min)+1);
+ percentage = egg_discrete_to_percent (cur, (max-min)+1);
egg_debug ("percentage %i", percentage);
brightness->priv->shared_value = percentage;
return TRUE;
@@ -318,7 +320,7 @@
return FALSE;
}
- shared_value_abs = gpm_percent_to_discrete (brightness->priv->shared_value, (max-min)+1);
+ shared_value_abs = egg_discrete_from_percent (brightness->priv->shared_value, (max-min)+1);
egg_debug ("percent=%i, absolute=%i", brightness->priv->shared_value, shared_value_abs);
egg_debug ("hard value=%i, min=%i, max=%i", cur, min, max);
Modified: trunk/src/gpm-cell-array.c
==============================================================================
--- trunk/src/gpm-cell-array.c (original)
+++ trunk/src/gpm-cell-array.c Thu Sep 4 17:05:42 2008
@@ -29,6 +29,9 @@
#include <libhal-gdevice.h>
#include <libhal-gmanager.h>
+#include "egg-debug.h"
+#include "egg-precision.h"
+
#include "gpm-marshal.h"
#include "gpm-ac-adapter.h"
#include "gpm-common.h"
@@ -38,7 +41,6 @@
#include "gpm-cell.h"
#include "gpm-phone.h"
#include "gpm-control.h"
-#include "egg-debug.h"
#include "gpm-warnings.h"
#include "gpm-profile.h"
@@ -998,8 +1000,8 @@
egg_debug ("accuracy = %i", accuracy);
/* precalculate so we don't get Unknown time remaining */
- charge_time_round = gpm_precision_round_down (unit->time_charge, GPM_UI_TIME_PRECISION);
- discharge_time_round = gpm_precision_round_down (unit->time_discharge, GPM_UI_TIME_PRECISION);
+ charge_time_round = egg_precision_round_down (unit->time_charge, GPM_UI_TIME_PRECISION);
+ discharge_time_round = egg_precision_round_down (unit->time_discharge, GPM_UI_TIME_PRECISION);
/* We always display "Laptop battery 16 minutes remaining" as we need
to clarify what device we are refering to. For details see :
@@ -1009,7 +1011,7 @@
if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY &&
accuracy > GPM_CELL_ARRAY_TEXT_MIN_ACCURACY) {
time = gpm_profile_get_time (cell_array->priv->profile, (guint) unit->percentage, TRUE);
- discharge_time_round = gpm_precision_round_down (time, GPM_UI_TIME_PRECISION);
+ discharge_time_round = egg_precision_round_down (time, GPM_UI_TIME_PRECISION);
discharge_timestring = gpm_get_timestring (discharge_time_round);
description = g_strdup_printf (_("%s fully charged (%.1f%%)\nProvides %s battery runtime\n"),
type_desc, unit->percentage, discharge_timestring);
Modified: trunk/src/gpm-common.c
==============================================================================
--- trunk/src/gpm-common.c (original)
+++ trunk/src/gpm-common.c Thu Sep 4 17:05:42 2008
@@ -31,64 +31,6 @@
#include "gpm-common.h"
/**
- * gpm_precision_round_up:
- * @value: The input value
- * @smallest: The smallest increment allowed
- *
- * 101, 10 110
- * 95, 10 100
- * 0, 10 10
- * 112, 10 120
- * 100, 10 100
- **/
-guint
-gpm_precision_round_up (guint value, guint smallest)
-{
- guint division;
- if (value == 0) {
- return smallest;
- }
- if (smallest == 0) {
- egg_warning ("divisor zero");
- return 0;
- }
- division = value / smallest;
- /* add one unit to scale if we can't contain */
- if (value % smallest != 0) {
- division++;
- }
- division *= smallest;
- return division;
-}
-
-/**
- * gpm_precision_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
- **/
-guint
-gpm_precision_round_down (guint value, guint smallest)
-{
- guint division;
- if (value == 0) {
- return 0;
- }
- if (smallest == 0) {
- egg_warning ("divisor zero");
- return 0;
- }
- division = value / smallest;
- division *= smallest;
- return division;
-}
-
-/**
* gpm_exponential_average:
* @previous: The old value
* @new: The new value
@@ -117,77 +59,6 @@
}
/**
- * gpm_percent_to_discrete:
- * @percentage: The percentage to convert
- * @levels: The number of discrete levels
- *
- * We have to be carefull when converting from %->discrete as precision is very
- * important if we want the highest value.
- *
- * Return value: The discrete value for this percentage.
- **/
-guint
-gpm_percent_to_discrete (guint percentage, guint levels)
-{
- /* check we are in range */
- if (percentage > 100) {
- return levels;
- }
- if (levels == 0) {
- egg_warning ("levels is 0!");
- return 0;
- }
- return ((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f;
-}
-
-/**
- * gpm_discrete_to_percent:
- * @hw: The discrete level
- * @levels: The number of discrete levels
- *
- * We have to be carefull when converting from discrete->%.
- *
- * Return value: The percentage for this discrete value.
- **/
-guint
-gpm_discrete_to_percent (guint discrete, guint levels)
-{
- /* check we are in range */
- if (discrete > levels) {
- return 100;
- }
- if (levels == 0) {
- egg_warning ("levels is 0!");
- return 0;
- }
- return (guint) ((gfloat) discrete * (100.0f / (gfloat) (levels - 1)));
-}
-
-/**
- * gpm_discrete_to_fraction:
- * @hw: The discrete level
- * @levels: The number of discrete levels
- *
- * We have to be careful when converting from discrete->fractions.
- *
- * Return value: The floating point fraction (0..1) for this discrete value.
- **/
-gfloat
-gpm_discrete_to_fraction (guint discrete,
- guint levels)
-{
- /* check we are in range */
- if (discrete > levels) {
- return 1.0;
- }
- if (levels == 0) {
- egg_warning ("levels is 0!");
- return 0.0;
- }
- return (guint) ((gfloat) discrete / ((gfloat) (levels - 1)));
-}
-
-/**
* gpm_get_timestring:
* @time_secs: The time value to convert in seconds
* @cookie: The cookie we are looking for
@@ -342,148 +213,10 @@
void
gpm_common_test (EggTest *test)
{
- guint value;
- gfloat fvalue;
-
if (egg_test_start (test, "GpmCommon") == FALSE) {
return;
}
- /************************************************************/
- egg_test_title (test, "limit precision down 0,10");
- value = gpm_precision_round_down (0, 10);
- if (value == 0) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision down 4,10");
- value = gpm_precision_round_down (4, 10);
- if (value == 0) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision down 11,10");
- value = gpm_precision_round_down (11, 10);
- if (value == 10) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision down 201,2");
- value = gpm_precision_round_down (201, 2);
- if (value == 200) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision down 100,10");
- value = gpm_precision_round_down (100, 10);
- if (value == 100) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision up 0,10");
- value = gpm_precision_round_up (0, 10);
- if (value == 10) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision up 4,10");
- value = gpm_precision_round_up (4, 10);
- if (value == 10) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision up 11,10");
- value = gpm_precision_round_up (11, 10);
- if (value == 20) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision up 201,2");
- value = gpm_precision_round_up (201, 2);
- if (value == 202) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "limit precision up 100,10");
- value = gpm_precision_round_up (100, 10);
- if (value == 100) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "precision incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "convert discrete 0/10 levels");
- value = gpm_discrete_to_percent (0, 10);
- if (value == 0) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "conversion incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "convert discrete 9/10 levels");
- value = gpm_discrete_to_percent (9, 10);
- if (value == 100) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "conversion incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "convert discrete 20/10 levels");
- value = gpm_discrete_to_percent (20, 10);
- if (value == 100) {
- egg_test_success (test, "got %i", value);
- } else {
- egg_test_failed (test, "conversion incorrect (%i)", value);
- }
-
- /************************************************************/
- egg_test_title (test, "convert discrete 0/10 levels");
- fvalue = gpm_discrete_to_fraction (0, 10);
- if (fvalue > -0.01 && fvalue < 0.01) {
- egg_test_success (test, "got %f", fvalue);
- } else {
- egg_test_failed (test, "conversion incorrect (%f)", fvalue);
- }
-
- /************************************************************/
- egg_test_title (test, "convert discrete 9/10 levels");
- fvalue = gpm_discrete_to_fraction (9, 10);
- if (fvalue > -1.01 && fvalue < 1.01) {
- egg_test_success (test, "got %f", fvalue);
- } else {
- egg_test_failed (test, "conversion incorrect (%f)", fvalue);
- }
-
egg_test_end (test);
}
Modified: trunk/src/gpm-common.h
==============================================================================
--- trunk/src/gpm-common.h (original)
+++ trunk/src/gpm-common.h Thu Sep 4 17:05:42 2008
@@ -57,19 +57,9 @@
} GpmIconPolicy;
gchar *gpm_get_timestring (guint time);
-guint gpm_precision_round_up (guint value,
- guint smallest);
-guint gpm_precision_round_down (guint value,
- guint smallest);
-guint gpm_percent_to_discrete (guint percentage,
- guint levels);
gint gpm_exponential_average (gint previous,
gint new,
guint slew);
-guint gpm_discrete_to_percent (guint discrete,
- guint levels);
-gfloat gpm_discrete_to_fraction (guint discrete,
- guint levels);
GpmIconPolicy gpm_tray_icon_mode_from_string (const gchar *mode);
const gchar *gpm_tray_icon_mode_to_string (GpmIconPolicy mode);
void gpm_help_display (char *link_id);
Modified: trunk/src/gpm-graph-widget.c
==============================================================================
--- trunk/src/gpm-graph-widget.c (original)
+++ trunk/src/gpm-graph-widget.c Thu Sep 4 17:05:42 2008
@@ -27,11 +27,14 @@
#include <stdlib.h>
#include <string.h>
+#include "egg-debug.h"
+#include "egg-precision.h"
#include "egg-color.h"
+#include "egg-debug.h"
+
#include "gpm-common.h"
#include "gpm-graph-widget.h"
#include "gpm-array.h"
-#include "egg-debug.h"
G_DEFINE_TYPE (GpmGraphWidget, gpm_graph_widget, GTK_TYPE_DRAWING_AREA);
#define GPM_GRAPH_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_GRAPH_WIDGET, GpmGraphWidgetPrivate))
@@ -748,10 +751,10 @@
}
}
- graph->priv->start_x = gpm_precision_round_down (smallest_x, rounding_x);
- graph->priv->start_y = gpm_precision_round_down (smallest_y, rounding_y);
- graph->priv->stop_x = gpm_precision_round_up (biggest_x, rounding_x);
- graph->priv->stop_y = gpm_precision_round_up (biggest_y, rounding_y);
+ graph->priv->start_x = egg_precision_round_down (smallest_x, rounding_x);
+ graph->priv->start_y = egg_precision_round_down (smallest_y, rounding_y);
+ graph->priv->stop_x = egg_precision_round_up (biggest_x, rounding_x);
+ graph->priv->stop_y = egg_precision_round_up (biggest_y, rounding_y);
/* if percentage, and close to the end points, then extend */
if (graph->priv->axis_type_x == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
Modified: trunk/src/gpm-light-sensor.c
==============================================================================
--- trunk/src/gpm-light-sensor.c (original)
+++ trunk/src/gpm-light-sensor.c Thu Sep 4 17:05:42 2008
@@ -42,8 +42,10 @@
#include <libhal-gmanager.h>
#include <libdbus-proxy.h>
-#include "gpm-common.h"
#include "egg-debug.h"
+#include "egg-discrete.h"
+
+#include "gpm-common.h"
#include "gpm-light-sensor.h"
#include "gpm-conf.h"
#include "gpm-marshal.h"
@@ -147,7 +149,7 @@
return FALSE;
}
- *sensor_level = gpm_discrete_to_percent (sensor->priv->current_hw,
+ *sensor_level = egg_discrete_to_percent (sensor->priv->current_hw,
sensor->priv->levels);
return TRUE;
}
@@ -171,7 +173,7 @@
return FALSE;
}
- fraction = gpm_discrete_to_fraction (sensor->priv->current_hw,
+ fraction = egg_discrete_to_fraction (sensor->priv->current_hw,
sensor->priv->levels);
sensor->priv->calibration_abs = fraction;
egg_debug ("calibrating to %f", fraction);
@@ -201,7 +203,7 @@
return FALSE;
}
- absolute = gpm_discrete_to_percent (sensor->priv->current_hw,
+ absolute = egg_discrete_to_percent (sensor->priv->current_hw,
sensor->priv->levels);
*difference = (absolute - sensor->priv->calibration_abs) + 1.0;
return TRUE;
Modified: trunk/src/gpm-self-test.c
==============================================================================
--- trunk/src/gpm-self-test.c (original)
+++ trunk/src/gpm-self-test.c Thu Sep 4 17:05:42 2008
@@ -28,6 +28,10 @@
#include "egg-debug.h"
/* prototypes */
+void egg_precision_test (EggTest *test);
+void egg_discrete_test (EggTest *test);
+void egg_color_test (EggTest *test);
+
void gpm_common_test (EggTest *test);
void gpm_array_float_test (EggTest *test);
void gpm_array_test (EggTest *test);
@@ -58,6 +62,10 @@
gtk_init (&argc, &argv);
/* tests go here */
+ egg_precision_test (test);
+ egg_discrete_test (test);
+ egg_color_test (test);
+
gpm_common_test (test);
gpm_array_float_test (test);
gpm_array_test (test);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]