14345N/A--- ./libhal-glib/Makefile.am.orig 2008-09-16 10:41:55.539506000 +0800
14345N/A+++ ./libhal-glib/Makefile.am 2008-09-16 10:45:00.053008000 +0800
14345N/A@@ -11,11 +11,27 @@
14345N/A $(top_builddir)/libdbus-glib/libdbus-proxy.la
14345N/A
14345N/A noinst_LTLIBRARIES = \
14345N/A+ libhal-gcpufreq.la \
14345N/A libhal-gmanager.la \
14345N/A libhal-gdevice.la \
14345N/A libhal-gdevicestore.la \
14345N/A libhal-gpower.la
14345N/A
14345N/A+libhal_gcpufreq_la_SOURCES = \
14345N/A+ libhal-marshal.h \
14345N/A+ libhal-marshal.c \
14345N/A+ libhal-gdevice.c \
14345N/A+ libhal-gdevice.h \
14345N/A+ libhal-gcpufreq.c \
14345N/A+ libhal-gcpufreq.h \
14345N/A+ libhal-gmanager.c \
14345N/A+ libhal-gmanager.h
14345N/A+libhal_gcpufreq_la_LIBADD = \
14345N/A+ $(LOCAL_LIBDBUS_LIBS) \
14345N/A+ $(DBUS_LIBS) \
14345N/A+ $(INTLLIBS) \
14345N/A+ $(GLIB_LIBS)
14345N/A+
14345N/A libhal_gmanager_la_SOURCES = \
14345N/A libhal-marshal.h \
14345N/A libhal-marshal.c \
14345N/A--- ./libhal-glib/libhal-gcpufreq.h.orig 1970-01-01 08:00:00.000000000 +0800
14345N/A+++ ./libhal-glib/libhal-gcpufreq.h 2008-09-16 10:34:25.096229000 +0800
14345N/A@@ -0,0 +1,93 @@
14345N/A+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
14345N/A+ *
14345N/A+ * Copyright (C) 2006-2007 Richard Hughes <richard@hughsie.com>
14345N/A+ *
14345N/A+ * Licensed under the GNU General Public License Version 2
14345N/A+ *
14345N/A+ * This program is free software; you can redistribute it and/or modify
14345N/A+ * it under the terms of the GNU General Public License as published by
14345N/A+ * the Free Software Foundation; either version 2 of the License, or
14345N/A+ * (at your option) any later version.
14345N/A+ *
14345N/A+ * This program is distributed in the hope that it will be useful,
14345N/A+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14345N/A+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14345N/A+ * GNU General Public License for more details.
14345N/A+ *
14345N/A+ * You should have received a copy of the GNU General Public License
14345N/A+ * along with this program; if not, write to the Free Software
14345N/A+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14345N/A+ */
14345N/A+
14345N/A+#ifndef __LIBHAL_GCPUFREQ_H
14345N/A+#define __LIBHAL_GCPUFREQ_H
14345N/A+
14345N/A+#include <glib-object.h>
14345N/A+
14345N/A+G_BEGIN_DECLS
14345N/A+
14345N/A+#define LIBHAL_TYPE_CPUFREQ (hal_gcpufreq_get_type ())
14345N/A+#define LIBHAL_CPUFREQ(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), LIBHAL_TYPE_CPUFREQ, HalGCpufreq))
14345N/A+#define LIBHAL_CPUFREQ_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), LIBHAL_TYPE_CPUFREQ, HalGCpufreqClass))
14345N/A+#define LIBHAL_IS_CPUFREQ(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), LIBHAL_TYPE_CPUFREQ))
14345N/A+#define LIBHAL_IS_CPUFREQ_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), LIBHAL_TYPE_CPUFREQ))
14345N/A+#define LIBHAL_CPUFREQ_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), LIBHAL_TYPE_CPUFREQ, HalGCpufreqClass))
14345N/A+
14345N/A+typedef struct HalGCpufreqPrivate HalGCpufreqPrivate;
14345N/A+
14345N/A+typedef struct
14345N/A+{
14345N/A+ GObject parent;
14345N/A+ HalGCpufreqPrivate *priv;
14345N/A+} HalGCpufreq;
14345N/A+
14345N/A+
14345N/A+typedef struct
14345N/A+{
14345N/A+ GObjectClass parent_class;
14345N/A+} HalGCpufreqClass;
14345N/A+
14345N/A+/* types of governor */
14345N/A+typedef enum {
14345N/A+ LIBHAL_CPUFREQ_UNKNOWN = 0,
14345N/A+ LIBHAL_CPUFREQ_ONDEMAND = 1,
14345N/A+ LIBHAL_CPUFREQ_CONSERVATIVE = 2,
14345N/A+ LIBHAL_CPUFREQ_POWERSAVE = 4,
14345N/A+ LIBHAL_CPUFREQ_USERSPACE = 8,
14345N/A+ LIBHAL_CPUFREQ_PERFORMANCE = 16,
14345N/A+ LIBHAL_CPUFREQ_NOTHING = 32,
14345N/A+} HalGCpufreqType;
14345N/A+
14345N/A+#define CODE_CPUFREQ_ONDEMAND "ondemand"
14345N/A+#define CODE_CPUFREQ_CONSERVATIVE "conservative"
14345N/A+#define CODE_CPUFREQ_POWERSAVE "powersave"
14345N/A+#define CODE_CPUFREQ_USERSPACE "userspace"
14345N/A+#define CODE_CPUFREQ_PERFORMANCE "performance"
14345N/A+#define CODE_CPUFREQ_NOTHING "nothing"
14345N/A+
14345N/A+GType hal_gcpufreq_get_type (void);
14345N/A+HalGCpufreq *hal_gcpufreq_new (void);
14345N/A+gboolean hal_gcpufreq_has_hw (void);
14345N/A+
14345N/A+const gchar *hal_gcpufreq_enum_to_string (HalGCpufreqType cpufreq_type);
14345N/A+HalGCpufreqType hal_gcpufreq_string_to_enum (const gchar *governor);
14345N/A+gboolean hal_gcpufreq_get_governors (HalGCpufreq *cpufreq,
14345N/A+ HalGCpufreqType *cpufreq_type);
14345N/A+gboolean hal_gcpufreq_get_governor (HalGCpufreq *cpufreq,
14345N/A+ HalGCpufreqType *cpufreq_type);
14345N/A+gboolean hal_gcpufreq_set_governor (HalGCpufreq *cpufreq,
14345N/A+ HalGCpufreqType governor_enum);
14345N/A+gboolean hal_gcpufreq_get_consider_nice (HalGCpufreq *cpufreq,
14345N/A+ gboolean *consider_nice);
14345N/A+gboolean hal_gcpufreq_set_consider_nice (HalGCpufreq *cpufreq,
14345N/A+ gboolean consider_nice);
14345N/A+gboolean hal_gcpufreq_get_performance (HalGCpufreq *cpufreq,
14345N/A+ guint *performance);
14345N/A+gboolean hal_gcpufreq_set_performance (HalGCpufreq *cpufreq,
14345N/A+ guint performance);
14345N/A+guint hal_gcpufreq_get_number_governors (HalGCpufreq *cpufreq,
14345N/A+ gboolean use_cache);
14345N/A+
14345N/A+G_END_DECLS
14345N/A+
14345N/A+#endif /* __LIBHAL_GCPUFREQ_H */
14345N/A--- ./libhal-glib/libhal-gcpufreq.c.orig 1970-01-01 08:00:00.000000000 +0800
14345N/A+++ ./libhal-glib/libhal-gcpufreq.c 2008-09-16 10:34:25.096051000 +0800
14345N/A@@ -0,0 +1,608 @@
14345N/A+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
14345N/A+ *
14345N/A+ * Copyright (C) 2006-2007 Richard Hughes <richard@hughsie.com>
14345N/A+ *
14345N/A+ * Licensed under the GNU General Public License Version 2
14345N/A+ *
14345N/A+ * This program is free software; you can redistribute it and/or modify
14345N/A+ * it under the terms of the GNU General Public License as published by
14345N/A+ * the Free Software Foundation; either version 2 of the License, or
14345N/A+ * (at your option) any later version.
14345N/A+ *
14345N/A+ * This program is distributed in the hope that it will be useful,
14345N/A+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14345N/A+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14345N/A+ * GNU General Public License for more details.
14345N/A+ *
14345N/A+ * You should have received a copy of the GNU General Public License
14345N/A+ * along with this program; if not, write to the Free Software
14345N/A+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14345N/A+ */
14345N/A+
14345N/A+#ifdef HAVE_CONFIG_H
14345N/A+# include <config.h>
14345N/A+#endif
14345N/A+
14345N/A+#include <string.h>
14345N/A+#include <glib.h>
14345N/A+#include <dbus/dbus-glib.h>
14345N/A+#include <glib/gi18n.h>
14345N/A+#include <libdbus-proxy.h>
14345N/A+
14345N/A+#include "libhal-marshal.h"
14345N/A+#include "libhal-gpower.h"
14345N/A+#include "libhal-gdevice.h"
14345N/A+#include "libhal-gcpufreq.h"
14345N/A+#include "libhal-gmanager.h"
14345N/A+
14345N/A+static void hal_gcpufreq_class_init (HalGCpufreqClass *klass);
14345N/A+static void hal_gcpufreq_init (HalGCpufreq *hal);
14345N/A+static void hal_gcpufreq_finalize (GObject *object);
14345N/A+
14345N/A+#define LIBHAL_CPUFREQ_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LIBHAL_TYPE_CPUFREQ, HalGCpufreqPrivate))
14345N/A+
14345N/A+struct HalGCpufreqPrivate
14345N/A+{
14345N/A+ DbusProxy *gproxy;
14345N/A+ guint available_governors;
14345N/A+ HalGCpufreqType current_governor;
14345N/A+};
14345N/A+
14345N/A+G_DEFINE_TYPE (HalGCpufreq, hal_gcpufreq, G_TYPE_OBJECT)
14345N/A+
14345N/A+static gpointer hal_gcpufreq_object = NULL;
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_string_to_enum:
14345N/A+ * @governor: The cpufreq kernel governor, e.g. "powersave"
14345N/A+ * Return value: The HalGCpufreqType value, e.g. LIBHAL_CPUFREQ_POWERSAVE
14345N/A+ **/
14345N/A+HalGCpufreqType
14345N/A+hal_gcpufreq_string_to_enum (const gchar *governor)
14345N/A+{
14345N/A+ HalGCpufreqType cpufreq_type = LIBHAL_CPUFREQ_UNKNOWN;
14345N/A+ if (governor == NULL) {
14345N/A+ cpufreq_type = LIBHAL_CPUFREQ_NOTHING;
14345N/A+ } else if (strcmp (governor, CODE_CPUFREQ_ONDEMAND) == 0) {
14345N/A+ cpufreq_type = LIBHAL_CPUFREQ_ONDEMAND;
14345N/A+ } else if (strcmp (governor, CODE_CPUFREQ_CONSERVATIVE) == 0) {
14345N/A+ cpufreq_type = LIBHAL_CPUFREQ_CONSERVATIVE;
14345N/A+ } else if (strcmp (governor, CODE_CPUFREQ_POWERSAVE) == 0) {
14345N/A+ cpufreq_type = LIBHAL_CPUFREQ_POWERSAVE;
14345N/A+ } else if (strcmp (governor, CODE_CPUFREQ_USERSPACE) == 0) {
14345N/A+ cpufreq_type = LIBHAL_CPUFREQ_USERSPACE;
14345N/A+ } else if (strcmp (governor, CODE_CPUFREQ_PERFORMANCE) == 0) {
14345N/A+ cpufreq_type = LIBHAL_CPUFREQ_PERFORMANCE;
14345N/A+ } else if (strcmp (governor, CODE_CPUFREQ_NOTHING) == 0) {
14345N/A+ cpufreq_type = LIBHAL_CPUFREQ_NOTHING;
14345N/A+ }
14345N/A+ return cpufreq_type;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_string_to_enum:
14345N/A+ * @cpufreq_type: The HalGCpufreqType value, e.g. LIBHAL_CPUFREQ_POWERSAVE
14345N/A+ * Return value: The cpufreq kernel governor, e.g. "powersave"
14345N/A+ **/
14345N/A+const gchar *
14345N/A+hal_gcpufreq_enum_to_string (HalGCpufreqType cpufreq_type)
14345N/A+{
14345N/A+ const char *governor;
14345N/A+ if (cpufreq_type == LIBHAL_CPUFREQ_ONDEMAND) {
14345N/A+ governor = CODE_CPUFREQ_ONDEMAND;
14345N/A+ } else if (cpufreq_type == LIBHAL_CPUFREQ_CONSERVATIVE) {
14345N/A+ governor = CODE_CPUFREQ_CONSERVATIVE;
14345N/A+ } else if (cpufreq_type == LIBHAL_CPUFREQ_POWERSAVE) {
14345N/A+ governor = CODE_CPUFREQ_POWERSAVE;
14345N/A+ } else if (cpufreq_type == LIBHAL_CPUFREQ_USERSPACE) {
14345N/A+ governor = CODE_CPUFREQ_USERSPACE;
14345N/A+ } else if (cpufreq_type == LIBHAL_CPUFREQ_PERFORMANCE) {
14345N/A+ governor = CODE_CPUFREQ_PERFORMANCE;
14345N/A+ } else if (cpufreq_type == LIBHAL_CPUFREQ_NOTHING) {
14345N/A+ governor = CODE_CPUFREQ_NOTHING;
14345N/A+ } else {
14345N/A+ governor = "unknown";
14345N/A+ }
14345N/A+ return governor;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_set_performance:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @performance: The percentage perfomance figure
14345N/A+ * Return value: If the method succeeded
14345N/A+ **/
14345N/A+gboolean
14345N/A+hal_gcpufreq_set_performance (HalGCpufreq *cpufreq, guint performance)
14345N/A+{
14345N/A+ GError *error = NULL;
14345N/A+ gboolean ret;
14345N/A+ HalGCpufreqType cpufreq_type;
14345N/A+ DBusGProxy *proxy;
14345N/A+
14345N/A+ g_return_val_if_fail (cpufreq != NULL, FALSE);
14345N/A+ g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
14345N/A+ g_return_val_if_fail (performance >= 0, FALSE);
14345N/A+ g_return_val_if_fail (performance <= 100, FALSE);
14345N/A+
14345N/A+ /* we need to find the current governor to see if it's sane */
14345N/A+ if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_UNKNOWN) {
14345N/A+ hal_gcpufreq_get_governor (cpufreq, &cpufreq_type);
14345N/A+ }
14345N/A+
14345N/A+ /* only applies to some governors */
14345N/A+ if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_PERFORMANCE ||
14345N/A+ cpufreq->priv->current_governor == LIBHAL_CPUFREQ_POWERSAVE) {
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
14345N/A+ if (proxy == NULL) {
14345N/A+ g_warning ("not connected");
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ ret = dbus_g_proxy_call (proxy, "SetCPUFreqPerformance", &error,
14345N/A+ G_TYPE_INT, performance,
14345N/A+ G_TYPE_INVALID,
14345N/A+ G_TYPE_INVALID);
14345N/A+ if (error) {
14345N/A+ g_warning ("ERROR: %s", error->message);
14345N/A+ g_error_free (error);
14345N/A+ }
14345N/A+ if (ret == FALSE) {
14345N/A+ /* abort as the DBUS method failed */
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+ return TRUE;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_set_governor:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @cpufreq_type: The CPU governor type, e.g. LIBHAL_CPUFREQ_CONSERVATIVE
14345N/A+ * Return value: If the method succeeded
14345N/A+ **/
14345N/A+gboolean
14345N/A+hal_gcpufreq_set_governor (HalGCpufreq *cpufreq,
14345N/A+ HalGCpufreqType cpufreq_type)
14345N/A+{
14345N/A+ GError *error = NULL;
14345N/A+ gboolean ret;
14345N/A+ const gchar *governor;
14345N/A+ DBusGProxy *proxy;
14345N/A+
14345N/A+ g_return_val_if_fail (cpufreq != NULL, FALSE);
14345N/A+ g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
14345N/A+ g_return_val_if_fail (cpufreq_type != LIBHAL_CPUFREQ_UNKNOWN, FALSE);
14345N/A+
14345N/A+ governor = hal_gcpufreq_enum_to_string (cpufreq_type);
14345N/A+ g_return_val_if_fail (governor != NULL, FALSE);
14345N/A+
14345N/A+ proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
14345N/A+ if (proxy == NULL) {
14345N/A+ g_warning ("not connected");
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ ret = dbus_g_proxy_call (proxy, "SetCPUFreqGovernor", &error,
14345N/A+ G_TYPE_STRING, governor,
14345N/A+ G_TYPE_INVALID,
14345N/A+ G_TYPE_INVALID);
14345N/A+ if (error) {
14345N/A+ g_warning ("ERROR: %s", error->message);
14345N/A+ g_error_free (error);
14345N/A+ }
14345N/A+ if (ret == FALSE) {
14345N/A+ /* abort as the DBUS method failed */
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ /* save the cache */
14345N/A+ cpufreq->priv->current_governor = cpufreq_type;
14345N/A+ return TRUE;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_get_governors:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @cpufreq_type: Return variable, The CPU governor type as an combined bitwise type
14345N/A+ * Return value: If the method succeeded
14345N/A+ **/
14345N/A+gboolean
14345N/A+hal_gcpufreq_get_governors (HalGCpufreq *cpufreq,
14345N/A+ HalGCpufreqType *cpufreq_type)
14345N/A+{
14345N/A+ GError *error = NULL;
14345N/A+ gboolean ret;
14345N/A+ char **strlist;
14345N/A+ int i = 0;
14345N/A+ DBusGProxy *proxy;
14345N/A+ HalGCpufreqType types = LIBHAL_CPUFREQ_UNKNOWN;
14345N/A+
14345N/A+ g_return_val_if_fail (cpufreq != NULL, FALSE);
14345N/A+ g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
14345N/A+ g_return_val_if_fail (cpufreq_type != NULL, FALSE);
14345N/A+
14345N/A+ proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
14345N/A+ if (proxy == NULL) {
14345N/A+ g_warning ("not connected");
14345N/A+ *cpufreq_type = LIBHAL_CPUFREQ_UNKNOWN;
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ ret = dbus_g_proxy_call (proxy, "GetCPUFreqAvailableGovernors", &error,
14345N/A+ G_TYPE_INVALID,
14345N/A+ G_TYPE_STRV, &strlist,
14345N/A+ G_TYPE_INVALID);
14345N/A+ if (error) {
14345N/A+ g_warning ("ERROR: %s", error->message);
14345N/A+ g_error_free (error);
14345N/A+ }
14345N/A+ if (ret == FALSE) {
14345N/A+ /* abort as the DBUS method failed */
14345N/A+ *cpufreq_type = LIBHAL_CPUFREQ_UNKNOWN;
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ /* treat as binary flags */
14345N/A+ while (strlist && strlist[i]) {
14345N/A+ types += hal_gcpufreq_string_to_enum (strlist[i]);
14345N/A+ ++i;
14345N/A+ }
14345N/A+
14345N/A+ /* when we have conservative and ondemand available, only expose
14345N/A+ ondemand in the UI. They are too similar and ondemand is better. */
14345N/A+ if (types & LIBHAL_CPUFREQ_ONDEMAND && types & LIBHAL_CPUFREQ_CONSERVATIVE) {
14345N/A+ types -= LIBHAL_CPUFREQ_CONSERVATIVE;
14345N/A+ }
14345N/A+
14345N/A+ /* We never allow the user to use userspace. */
14345N/A+ if (types & LIBHAL_CPUFREQ_USERSPACE) {
14345N/A+ types -= LIBHAL_CPUFREQ_USERSPACE;
14345N/A+ }
14345N/A+
14345N/A+ *cpufreq_type = types;
14345N/A+ cpufreq->priv->available_governors = i;
14345N/A+ return TRUE;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_get_number_governors:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @use_cache: if we should force a cache update
14345N/A+ * Return value: the number of available governors
14345N/A+ **/
14345N/A+guint
14345N/A+hal_gcpufreq_get_number_governors (HalGCpufreq *cpufreq,
14345N/A+ gboolean use_cache)
14345N/A+{
14345N/A+ HalGCpufreqType cpufreq_type;
14345N/A+
14345N/A+ g_return_val_if_fail (cpufreq != NULL, FALSE);
14345N/A+ g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
14345N/A+
14345N/A+ if (use_cache == FALSE || cpufreq->priv->available_governors == -1) {
14345N/A+ hal_gcpufreq_get_governors (cpufreq, &cpufreq_type);
14345N/A+ }
14345N/A+ return cpufreq->priv->available_governors;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_get_consider_nice:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @consider_nice: Return variable, if consider niced processes
14345N/A+ * Return value: If the method succeeded
14345N/A+ **/
14345N/A+gboolean
14345N/A+hal_gcpufreq_get_consider_nice (HalGCpufreq *cpufreq,
14345N/A+ gboolean *consider_nice)
14345N/A+{
14345N/A+ GError *error = NULL;
14345N/A+ gboolean ret;
14345N/A+ HalGCpufreqType cpufreq_type;
14345N/A+ DBusGProxy *proxy;
14345N/A+
14345N/A+ g_return_val_if_fail (cpufreq != NULL, FALSE);
14345N/A+ g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
14345N/A+ g_return_val_if_fail (consider_nice != NULL, FALSE);
14345N/A+
14345N/A+ /* we need to find the current governor to see if it's sane */
14345N/A+ if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_UNKNOWN) {
14345N/A+ hal_gcpufreq_get_governor (cpufreq, &cpufreq_type);
14345N/A+ }
14345N/A+
14345N/A+ /* only applies to some governors */
14345N/A+ if (cpufreq->priv->current_governor != LIBHAL_CPUFREQ_ONDEMAND &&
14345N/A+ cpufreq->priv->current_governor != LIBHAL_CPUFREQ_CONSERVATIVE) {
14345N/A+ *consider_nice = FALSE;
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
14345N/A+ if (proxy == NULL) {
14345N/A+ g_warning ("not connected");
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ ret = dbus_g_proxy_call (proxy, "GetCPUFreqConsiderNice", &error,
14345N/A+ G_TYPE_INVALID,
14345N/A+ G_TYPE_BOOLEAN, consider_nice,
14345N/A+ G_TYPE_INVALID);
14345N/A+ if (error) {
14345N/A+ g_warning ("ERROR: %s", error->message);
14345N/A+ g_error_free (error);
14345N/A+ }
14345N/A+ if (ret == FALSE) {
14345N/A+ /* abort as the DBUS method failed */
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+ return TRUE;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_get_performance:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @performance: Return variable, the percentage performance
14345N/A+ * Return value: If the method succeeded
14345N/A+ **/
14345N/A+gboolean
14345N/A+hal_gcpufreq_get_performance (HalGCpufreq *cpufreq,
14345N/A+ guint *performance)
14345N/A+{
14345N/A+ GError *error = NULL;
14345N/A+ gboolean ret;
14345N/A+ HalGCpufreqType cpufreq_type;
14345N/A+ DBusGProxy *proxy;
14345N/A+
14345N/A+ g_return_val_if_fail (cpufreq != NULL, FALSE);
14345N/A+ g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
14345N/A+ g_return_val_if_fail (performance != NULL, FALSE);
14345N/A+
14345N/A+ /* we need to find the current governor to see if it's sane */
14345N/A+ if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_UNKNOWN) {
14345N/A+ hal_gcpufreq_get_governor (cpufreq, &cpufreq_type);
14345N/A+ }
14345N/A+
14345N/A+ /* only applies to some governors */
14345N/A+ if (cpufreq->priv->current_governor != LIBHAL_CPUFREQ_USERSPACE) {
14345N/A+ *performance = -1;
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
14345N/A+ if (proxy == NULL) {
14345N/A+ g_warning ("not connected");
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ ret = dbus_g_proxy_call (proxy, "GetCPUFreqPerformance", &error,
14345N/A+ G_TYPE_INVALID,
14345N/A+ G_TYPE_INT, performance,
14345N/A+ G_TYPE_INVALID);
14345N/A+ if (error) {
14345N/A+ g_warning ("ERROR: %s", error->message);
14345N/A+ g_error_free (error);
14345N/A+ }
14345N/A+ if (ret == FALSE) {
14345N/A+ /* abort as the DBUS method failed */
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+ return TRUE;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_get_governor:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @cpufreq_type: Return variable, the governor type, e.g. LIBHAL_CPUFREQ_POWERSAVE
14345N/A+ * Return value: If the method succeeded
14345N/A+ **/
14345N/A+gboolean
14345N/A+hal_gcpufreq_get_governor (HalGCpufreq *cpufreq,
14345N/A+ HalGCpufreqType *cpufreq_type)
14345N/A+{
14345N/A+ GError *error = NULL;
14345N/A+ gboolean ret;
14345N/A+ gchar *governor;
14345N/A+ DBusGProxy *proxy;
14345N/A+
14345N/A+ g_return_val_if_fail (cpufreq != NULL, FALSE);
14345N/A+ g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
14345N/A+ g_return_val_if_fail (cpufreq_type, FALSE);
14345N/A+
14345N/A+ *cpufreq_type = LIBHAL_CPUFREQ_UNKNOWN;
14345N/A+
14345N/A+ /* use the cache */
14345N/A+ if (cpufreq->priv->current_governor != LIBHAL_CPUFREQ_UNKNOWN) {
14345N/A+ return cpufreq->priv->current_governor;
14345N/A+ }
14345N/A+
14345N/A+ proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
14345N/A+ if (proxy == NULL) {
14345N/A+ g_warning ("not connected");
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ ret = dbus_g_proxy_call (proxy, "GetCPUFreqGovernor", &error,
14345N/A+ G_TYPE_INVALID,
14345N/A+ G_TYPE_STRING, &governor,
14345N/A+ G_TYPE_INVALID);
14345N/A+ if (error) {
14345N/A+ g_warning ("ERROR: %s", error->message);
14345N/A+ g_error_free (error);
14345N/A+ }
14345N/A+ if (ret == FALSE) {
14345N/A+ /* abort as the DBUS method failed */
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ /* convert to enumerated type */
14345N/A+ if (governor != NULL) {
14345N/A+ *cpufreq_type = hal_gcpufreq_string_to_enum (governor);
14345N/A+ cpufreq->priv->current_governor = *cpufreq_type;
14345N/A+ g_free (governor);
14345N/A+ }
14345N/A+
14345N/A+ return TRUE;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_set_consider_nice:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @enable: True to consider nice processes
14345N/A+ * Return value: If the method succeeded
14345N/A+ **/
14345N/A+gboolean
14345N/A+hal_gcpufreq_set_consider_nice (HalGCpufreq *cpufreq,
14345N/A+ gboolean consider_nice)
14345N/A+{
14345N/A+ GError *error = NULL;
14345N/A+ gboolean ret;
14345N/A+ HalGCpufreqType cpufreq_type;
14345N/A+ DBusGProxy *proxy;
14345N/A+
14345N/A+ g_return_val_if_fail (cpufreq != NULL, FALSE);
14345N/A+ g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
14345N/A+
14345N/A+ /* we need to find the current governor to see if it's sane */
14345N/A+ if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_UNKNOWN) {
14345N/A+ hal_gcpufreq_get_governor (cpufreq, &cpufreq_type);
14345N/A+ }
14345N/A+
14345N/A+ /* only applies to some governors */
14345N/A+ if (cpufreq->priv->current_governor != LIBHAL_CPUFREQ_ONDEMAND &&
14345N/A+ cpufreq->priv->current_governor != LIBHAL_CPUFREQ_CONSERVATIVE) {
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
14345N/A+ if (proxy == NULL) {
14345N/A+ g_warning ("not connected");
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+
14345N/A+ ret = dbus_g_proxy_call (proxy, "SetCPUFreqConsiderNice", &error,
14345N/A+ G_TYPE_BOOLEAN, consider_nice,
14345N/A+ G_TYPE_INVALID,
14345N/A+ G_TYPE_INVALID);
14345N/A+ if (error) {
14345N/A+ g_warning ("ERROR: %s", error->message);
14345N/A+ g_error_free (error);
14345N/A+ }
14345N/A+ if (ret == FALSE) {
14345N/A+ /* abort as the DBUS method failed */
14345N/A+ return FALSE;
14345N/A+ }
14345N/A+ return TRUE;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_class_init:
14345N/A+ * @klass: This class instance
14345N/A+ **/
14345N/A+static void
14345N/A+hal_gcpufreq_class_init (HalGCpufreqClass *klass)
14345N/A+{
14345N/A+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
14345N/A+ object_class->finalize = hal_gcpufreq_finalize;
14345N/A+ g_type_class_add_private (klass, sizeof (HalGCpufreqPrivate));
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_init:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ **/
14345N/A+static void
14345N/A+hal_gcpufreq_init (HalGCpufreq *cpufreq)
14345N/A+{
14345N/A+ cpufreq->priv = LIBHAL_CPUFREQ_GET_PRIVATE (cpufreq);
14345N/A+
14345N/A+ cpufreq->priv->gproxy = dbus_proxy_new ();
14345N/A+ dbus_proxy_assign (cpufreq->priv->gproxy,
14345N/A+ DBUS_PROXY_SYSTEM,
14345N/A+ HAL_DBUS_SERVICE,
14345N/A+ HAL_ROOT_COMPUTER,
14345N/A+ HAL_DBUS_INTERFACE_CPUFREQ);
14345N/A+
14345N/A+ /* set defaults */
14345N/A+ cpufreq->priv->available_governors = -1;
14345N/A+ cpufreq->priv->current_governor = LIBHAL_CPUFREQ_UNKNOWN;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_finalize:
14345N/A+ * @object: This class instance
14345N/A+ **/
14345N/A+static void
14345N/A+hal_gcpufreq_finalize (GObject *object)
14345N/A+{
14345N/A+ HalGCpufreq *cpufreq;
14345N/A+ g_return_if_fail (object != NULL);
14345N/A+ g_return_if_fail (LIBHAL_IS_CPUFREQ (object));
14345N/A+
14345N/A+ cpufreq = LIBHAL_CPUFREQ (object);
14345N/A+ cpufreq->priv = LIBHAL_CPUFREQ_GET_PRIVATE (cpufreq);
14345N/A+
14345N/A+ if (cpufreq->priv->gproxy != NULL) {
14345N/A+ g_object_unref (cpufreq->priv->gproxy);
14345N/A+ }
14345N/A+
14345N/A+ G_OBJECT_CLASS (hal_gcpufreq_parent_class)->finalize (object);
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_has_hw:
14345N/A+ *
14345N/A+ * Self contained function that works out if we have the hardware.
14345N/A+ * If not, we return FALSE and the module is unloaded.
14345N/A+ **/
14345N/A+gboolean
14345N/A+hal_gcpufreq_has_hw (void)
14345N/A+{
14345N/A+ HalGManager *hal_manager;
14345N/A+ gchar **names;
14345N/A+ gboolean ret = TRUE;
14345N/A+
14345N/A+ /* okay, as singleton */
14345N/A+ hal_manager = hal_gmanager_new ();
14345N/A+ ret = hal_gmanager_find_capability (hal_manager, "cpufreq_control", &names, NULL);
14345N/A+
14345N/A+ /* nothing found */
14345N/A+ if (names == NULL || names[0] == NULL) {
14345N/A+ ret = FALSE;
14345N/A+ }
14345N/A+ hal_gmanager_free_capability (names);
14345N/A+ g_object_unref (hal_manager);
14345N/A+
14345N/A+ return ret;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * hal_gcpufreq_new:
14345N/A+ * Return value: new HalGCpufreq instance.
14345N/A+ **/
14345N/A+HalGCpufreq *
14345N/A+hal_gcpufreq_new (void)
14345N/A+{
14345N/A+ if (hal_gcpufreq_object != NULL) {
14345N/A+ g_object_ref (hal_gcpufreq_object);
14345N/A+ } else {
14345N/A+ /* only load an instance of this module if we have the hardware */
14345N/A+ if (hal_gcpufreq_has_hw () == FALSE) {
14345N/A+ return NULL;
14345N/A+ }
14345N/A+ hal_gcpufreq_object = g_object_new (LIBHAL_TYPE_CPUFREQ, NULL);
14345N/A+ g_object_add_weak_pointer (hal_gcpufreq_object, &hal_gcpufreq_object);
14345N/A+ }
14345N/A+ return LIBHAL_CPUFREQ (hal_gcpufreq_object);
14345N/A+}
14345N/A+
14345N/A--- data/gnome-power-manager.schemas.in.orig 2008-09-16 13:26:20.971533000 +0800
14345N/A+++ data/gnome-power-manager.schemas.in 2008-09-16 13:27:40.434145000 +0800
14345N/A@@ -300,6 +300,66 @@
14345N/A </schema>
14345N/A
14345N/A <schema>
14345N/A+ <key>/schemas/apps/gnome-power-manager/cpufreq/consider_nice</key>
14345N/A+ <applyto>/apps/gnome-power-manager/cpufreq/consider_nice</applyto>
14345N/A+ <owner>gnome-power-manager</owner>
14345N/A+ <type>bool</type>
14345N/A+ <default>false</default>
14345N/A+ <locale name="C">
14345N/A+ <short>Whether or not niced processes should be considered on processor load calculation</short>
14345N/A+ <long>If niced processes are considered, they can cause a frequency increment even though their absolute load percentage wouldn't trigger the scaling mechanism to switch up the frequency.</long>
14345N/A+ </locale>
14345N/A+ </schema>
14345N/A+
14345N/A+ <schema>
14345N/A+ <key>/schemas/apps/gnome-power-manager/cpufreq/policy_ac</key>
14345N/A+ <applyto>/apps/gnome-power-manager/cpufreq/policy_ac</applyto>
14345N/A+ <owner>gnome-power-manager</owner>
14345N/A+ <type>string</type>
14345N/A+ <default>nothing</default>
14345N/A+ <locale name="C">
14345N/A+ <short>The cpufreq policy to use when on AC power</short>
14345N/A+ <long>The cpufreq policy used to scale the processor when on AC power. Possible values are ondemand, conservative, powersave, userspace, performance, nothing.</long>
14345N/A+ </locale>
14345N/A+ </schema>
14345N/A+
14345N/A+ <schema>
14345N/A+ <key>/schemas/apps/gnome-power-manager/cpufreq/performance_ac</key>
14345N/A+ <applyto>/apps/gnome-power-manager/cpufreq/performance_ac</applyto>
14345N/A+ <owner>gnome-power-manager</owner>
14345N/A+ <type>int</type>
14345N/A+ <default>85</default>
14345N/A+ <locale name="C">
14345N/A+ <short>The cpufreq performance value to use when on AC power</short>
14345N/A+ <long>The cpufreq performance value used to scale the processor when on AC power.</long>
14345N/A+ </locale>
14345N/A+ </schema>
14345N/A+
14345N/A+ <schema>
14345N/A+ <key>/schemas/apps/gnome-power-manager/cpufreq/policy_battery</key>
14345N/A+ <applyto>/apps/gnome-power-manager/cpufreq/policy_battery</applyto>
14345N/A+ <owner>gnome-power-manager</owner>
14345N/A+ <type>string</type>
14345N/A+ <default>nothing</default>
14345N/A+ <locale name="C">
14345N/A+ <short>The cpufreq policy to use when on battery power</short>
14345N/A+ <long>The cpufreq policy used to scale the processor when on battery power. Possible values are ondemand, conservative, powersave, userspace, performance, nothing.</long>
14345N/A+ </locale>
14345N/A+ </schema>
14345N/A+
14345N/A+ <schema>
14345N/A+ <key>/schemas/apps/gnome-power-manager/cpufreq/performance_battery</key>
14345N/A+ <applyto>/apps/gnome-power-manager/cpufreq/performance_battery</applyto>
14345N/A+ <owner>gnome-power-manager</owner>
14345N/A+ <type>int</type>
14345N/A+ <default>25</default>
14345N/A+ <locale name="C">
14345N/A+ <short>The cpufreq performance value to use when on battery power</short>
14345N/A+ <long>The cpufreq performance value used to scale the processor when on battery power.</long>
14345N/A+ </locale>
14345N/A+ </schema>
14345N/A+
14345N/A+ <schema>
14345N/A <key>/schemas/apps/gnome-power-manager/general/installed_schema</key>
14345N/A <applyto>/apps/gnome-power-manager/general/installed_schema</applyto>
14345N/A <owner>gnome-power-manager</owner>
14345N/A--- data/gpm-prefs.glade.orig 2008-09-16 12:10:25.562141000 +0800
14345N/A+++ data/gpm-prefs.glade 2008-09-16 12:20:00.554400000 +0800
14345N/A@@ -111,6 +111,58 @@
14345N/A <property name="position">1</property>
14345N/A </packing>
14345N/A </child>
14345N/A+
14345N/A+ <child>
14345N/A+ <widget class="GtkHBox" id="hbox_ac_cpu">
14345N/A+ <property name="visible">True</property>
14345N/A+ <property name="homogeneous">True</property>
14345N/A+ <property name="spacing">12</property>
14345N/A+
14345N/A+ <child>
14345N/A+ <widget class="GtkLabel" id="label_ac_cpu">
14345N/A+ <property name="visible">True</property>
15932N/A+ <property name="label" translatable="yes" comments="SUN_BRANDING">Computer sp_eed policy:</property>
14345N/A+ <property name="use_underline">True</property>
14345N/A+ <property name="use_markup">False</property>
14345N/A+ <property name="justify">GTK_JUSTIFY_LEFT</property>
14345N/A+ <property name="wrap">False</property>
14345N/A+ <property name="selectable">False</property>
14345N/A+ <property name="xalign">0</property>
14345N/A+ <property name="yalign">0.5</property>
14345N/A+ <property name="xpad">0</property>
14345N/A+ <property name="ypad">0</property>
14345N/A+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
14345N/A+ <property name="width_chars">-1</property>
14345N/A+ <property name="single_line_mode">False</property>
14345N/A+ <property name="angle">0</property>
14345N/A+ </widget>
14345N/A+ <packing>
14345N/A+ <property name="padding">0</property>
14345N/A+ <property name="expand">False</property>
14345N/A+ <property name="fill">True</property>
14345N/A+ </packing>
14345N/A+ </child>
14345N/A+
14345N/A+ <child>
14345N/A+ <widget class="GtkComboBox" id="combobox_ac_cpu">
14345N/A+ <property name="visible">True</property>
14345N/A+ <property name="items" translatable="yes"></property>
14345N/A+ <property name="add_tearoffs">False</property>
14345N/A+ <property name="focus_on_click">True</property>
14345N/A+ </widget>
14345N/A+ <packing>
14345N/A+ <property name="padding">0</property>
14345N/A+ <property name="expand">True</property>
14345N/A+ <property name="fill">True</property>
14345N/A+ </packing>
14345N/A+ </child>
14345N/A+ </widget>
14345N/A+ <packing>
14345N/A+ <property name="padding">0</property>
14345N/A+ <property name="expand">True</property>
14345N/A+ <property name="fill">True</property>
14345N/A+ </packing>
14345N/A+ </child>
14345N/A </widget>
14345N/A </child>
14345N/A </widget>
14345N/A@@ -378,6 +430,58 @@
14345N/A <property name="position">2</property>
14345N/A </packing>
14345N/A </child>
14345N/A+
14345N/A+ <child>
14345N/A+ <widget class="GtkHBox" id="hbox_battery_cpu">
14345N/A+ <property name="visible">True</property>
14345N/A+ <property name="homogeneous">True</property>
14345N/A+ <property name="spacing">12</property>
14345N/A+
14345N/A+ <child>
14345N/A+ <widget class="GtkLabel" id="label_battery_cpu">
14345N/A+ <property name="visible">True</property>
15932N/A+ <property name="label" translatable="yes" comments="SUN_BRANDING">Computer sp_eed policy:</property>
14345N/A+ <property name="use_underline">True</property>
14345N/A+ <property name="use_markup">False</property>
14345N/A+ <property name="justify">GTK_JUSTIFY_LEFT</property>
14345N/A+ <property name="wrap">False</property>
14345N/A+ <property name="selectable">False</property>
14345N/A+ <property name="xalign">0</property>
14345N/A+ <property name="yalign">0.5</property>
14345N/A+ <property name="xpad">0</property>
14345N/A+ <property name="ypad">0</property>
14345N/A+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
14345N/A+ <property name="width_chars">-1</property>
14345N/A+ <property name="single_line_mode">False</property>
14345N/A+ <property name="angle">0</property>
14345N/A+ </widget>
14345N/A+ <packing>
14345N/A+ <property name="padding">0</property>
14345N/A+ <property name="expand">False</property>
14345N/A+ <property name="fill">True</property>
14345N/A+ </packing>
14345N/A+ </child>
14345N/A+
14345N/A+ <child>
14345N/A+ <widget class="GtkComboBox" id="combobox_battery_cpu">
14345N/A+ <property name="visible">True</property>
14345N/A+ <property name="items" translatable="yes"></property>
14345N/A+ <property name="add_tearoffs">False</property>
14345N/A+ <property name="focus_on_click">True</property>
14345N/A+ </widget>
14345N/A+ <packing>
14345N/A+ <property name="padding">0</property>
14345N/A+ <property name="expand">True</property>
14345N/A+ <property name="fill">True</property>
14345N/A+ </packing>
14345N/A+ </child>
14345N/A+ </widget>
14345N/A+ <packing>
14345N/A+ <property name="padding">0</property>
14345N/A+ <property name="expand">True</property>
14345N/A+ <property name="fill">True</property>
14345N/A+ </packing>
14345N/A+ </child>
14345N/A </widget>
14345N/A </child>
14345N/A </widget>
14345N/A--- src/Makefile.am.orig 2008-09-16 10:37:34.789458000 +0800
14345N/A+++ src/Makefile.am 2008-09-16 10:41:39.623511000 +0800
14345N/A@@ -38,6 +38,7 @@
14345N/A $(top_builddir)/libhal-glib/libhal-gdevice.la \
14345N/A $(top_builddir)/libhal-glib/libhal-gdevicestore.la \
14345N/A $(top_builddir)/libhal-glib/libhal-gmanager.la \
14345N/A+ $(top_builddir)/libhal-glib/libhal-gcpufreq.la \
14345N/A $(top_builddir)/libhal-glib/libhal-gpower.la
14345N/A
14345N/A LOCAL_LIBDBUS_LIBS = \
14345N/A@@ -164,6 +165,8 @@
14345N/A gpm-srv-brightness-kbd.c \
14345N/A gpm-srv-screensaver.h \
14345N/A gpm-srv-screensaver.c \
14345N/A+ gpm-cpufreq.c \
14345N/A+ gpm-cpufreq.h \
14345N/A gpm-conf.h \
14345N/A gpm-conf.c \
14345N/A gpm-idle.h \
14345N/A--- src/gpm-cpufreq.h.orig 1970-01-01 08:00:00.000000000 +0800
14345N/A+++ src/gpm-cpufreq.h 2008-09-16 10:54:00.762524000 +0800
14345N/A@@ -0,0 +1,55 @@
14345N/A+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
14345N/A+ *
14345N/A+ * Copyright (C) 2006-2007 Richard Hughes <richard@hughsie.com>
14345N/A+ *
14345N/A+ * Licensed under the GNU General Public License Version 2
14345N/A+ *
14345N/A+ * This program is free software; you can redistribute it and/or modify
14345N/A+ * it under the terms of the GNU General Public License as published by
14345N/A+ * the Free Software Foundation; either version 2 of the License, or
14345N/A+ * (at your option) any later version.
14345N/A+ *
14345N/A+ * This program is distributed in the hope that it will be useful,
14345N/A+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14345N/A+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14345N/A+ * GNU General Public License for more details.
14345N/A+ *
14345N/A+ * You should have received a copy of the GNU General Public License
14345N/A+ * along with this program; if not, write to the Free Software
14345N/A+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14345N/A+ */
14345N/A+
14345N/A+#ifndef __GPMCPUFREQ_H
14345N/A+#define __GPMCPUFREQ_H
14345N/A+
14345N/A+#include <glib-object.h>
14345N/A+
14345N/A+G_BEGIN_DECLS
14345N/A+
14345N/A+#define GPM_TYPE_CPUFREQ (gpm_cpufreq_get_type ())
14345N/A+#define GPM_CPUFREQ(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_CPUFREQ, GpmCpufreq))
14345N/A+#define GPM_CPUFREQ_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_CPUFREQ, GpmCpufreqClass))
14345N/A+#define GPM_IS_CPUFREQ(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_CPUFREQ))
14345N/A+#define GPM_IS_CPUFREQ_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_CPUFREQ))
14345N/A+#define GPM_CPUFREQ_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_CPUFREQ, GpmCpufreqClass))
14345N/A+
14345N/A+typedef struct GpmCpufreqPrivate GpmCpufreqPrivate;
14345N/A+
14345N/A+typedef struct
14345N/A+{
14345N/A+ GObject parent;
14345N/A+ GpmCpufreqPrivate *priv;
14345N/A+} GpmCpufreq;
14345N/A+
14345N/A+typedef struct
14345N/A+{
14345N/A+ GObjectClass parent_class;
14345N/A+} GpmCpufreqClass;
14345N/A+
14345N/A+GType gpm_cpufreq_get_type (void);
14345N/A+GpmCpufreq *gpm_cpufreq_new (void);
14345N/A+
14345N/A+G_END_DECLS
14345N/A+
14345N/A+#endif /* __GPMCPUFREQ_H */
14345N/A+
14345N/A--- src/gpm-cpufreq.c.orig 1970-01-01 08:00:00.000000000 +0800
14345N/A+++ src/gpm-cpufreq.c 2008-09-16 13:18:02.206211000 +0800
14345N/A@@ -0,0 +1,250 @@
14345N/A+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
14345N/A+ *
14345N/A+ * Copyright (C) 2006-2007 Richard Hughes <richard@hughsie.com>
14345N/A+ *
14345N/A+ * Licensed under the GNU General Public License Version 2
14345N/A+ *
14345N/A+ * This program is free software; you can redistribute it and/or modify
14345N/A+ * it under the terms of the GNU General Public License as published by
14345N/A+ * the Free Software Foundation; either version 2 of the License, or
14345N/A+ * (at your option) any later version.
14345N/A+ *
14345N/A+ * This program is distributed in the hope that it will be useful,
14345N/A+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14345N/A+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14345N/A+ * GNU General Public License for more details.
14345N/A+ *
14345N/A+ * You should have received a copy of the GNU General Public License
14345N/A+ * along with this program; if not, write to the Free Software
14345N/A+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14345N/A+ */
14345N/A+
14345N/A+#ifdef HAVE_CONFIG_H
14345N/A+# include <config.h>
14345N/A+#endif
14345N/A+
14345N/A+#include <string.h>
14345N/A+#include <glib.h>
14345N/A+#include <dbus/dbus-glib.h>
14345N/A+#include <glib/gi18n.h>
14345N/A+
14345N/A+#include <libhal-gcpufreq.h>
14345N/A+
14345N/A+#include "gpm-ac-adapter.h"
14345N/A+#include "gpm-conf.h"
14471N/A+#include "egg-debug.h"
14345N/A+#include "gpm-cpufreq.h"
14345N/A+
14345N/A+static void gpm_cpufreq_class_init (GpmCpufreqClass *klass);
14345N/A+static void gpm_cpufreq_init (GpmCpufreq *hal);
14345N/A+static void gpm_cpufreq_finalize (GObject *object);
14345N/A+
14345N/A+#define GPM_CPUFREQ_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_CPUFREQ, GpmCpufreqPrivate))
14345N/A+
14345N/A+struct GpmCpufreqPrivate
14345N/A+{
14345N/A+ HalGCpufreq *hal_cpufreq;
14345N/A+ GpmConf *conf;
14345N/A+ GpmAcAdapter *ac_adapter;
14345N/A+};
14345N/A+
14345N/A+G_DEFINE_TYPE (GpmCpufreq, gpm_cpufreq, G_TYPE_OBJECT)
14345N/A+
14345N/A+#if defined(sun) && defined(__SVR4)
14345N/A+/**
14345N/A+ * gpm_cpufreq_sync_policy_from_system_to_gconf:
14345N/A+ * @cpufreq: This class instance
14345N/A+ *
14345N/A+ * Changes the cpufreq policy if AC gconf isn't identical to current system setting.
14345N/A+ * Note: Because Solaris considers server user apart from laptop user, AC gconf key
14345N/A+ * isn't per user preference any more. In other words, AC gconf key always
14345N/A+ * identical to current kernel/system configuration. Therefore, we need to
14345N/A+ * read setting from kernel/system and store in AC gconf key.
14345N/A+ **/
14345N/A+static gboolean
14345N/A+gpm_cpufreq_sync_policy_from_system_to_gconf (GpmCpufreq *cpufreq)
14345N/A+{
14345N/A+ gboolean on_ac;
14345N/A+ guint cpufreq_performance;
14345N/A+ gchar *cpufreq_policy;
14345N/A+ HalGCpufreqType cpufreq_type;
14345N/A+
14345N/A+ on_ac = gpm_ac_adapter_is_present (cpufreq->priv->ac_adapter);
14345N/A+ if (on_ac == TRUE) {
14345N/A+ /* Store current system governor and performance setting into AC gconf key.
14345N/A+ * Solaris CPUfreq don't support nice, do nothing for that.
14345N/A+ */
14345N/A+ hal_gcpufreq_get_governor (cpufreq->priv->hal_cpufreq, &cpufreq_type);
14345N/A+ cpufreq_policy = hal_gcpufreq_enum_to_string (cpufreq_type);
14345N/A+ gpm_conf_set_string (cpufreq->priv->conf, GPM_CONF_CPUFREQ_POLICY_AC, cpufreq_policy);
14345N/A+ if (hal_gcpufreq_get_performance (cpufreq->priv->hal_cpufreq, &cpufreq_performance)) {
14345N/A+ gpm_conf_set_uint (cpufreq->priv->conf, GPM_CONF_CPUFREQ_PERFORMANCE_AC, cpufreq_performance);
14345N/A+ }
14345N/A+ }
14345N/A+
14345N/A+ return TRUE;
14345N/A+}
14345N/A+#endif
14345N/A+
14345N/A+/**
14345N/A+ * gpm_cpufreq_sync_policy:
14345N/A+ * @cpufreq: This class instance
14345N/A+ * @on_ac: If we are on AC power
14345N/A+ *
14345N/A+ * Changes the cpufreq policy if required
14345N/A+ **/
14345N/A+static gboolean
14345N/A+gpm_cpufreq_sync_policy (GpmCpufreq *cpufreq)
14345N/A+{
14345N/A+ gboolean cpufreq_consider_nice;
14345N/A+ gboolean on_ac;
14345N/A+ guint cpufreq_performance;
14345N/A+ gchar *cpufreq_policy;
14345N/A+ HalGCpufreqType cpufreq_type;
14345N/A+
14345N/A+ on_ac = gpm_ac_adapter_is_present (cpufreq->priv->ac_adapter);
14345N/A+
14345N/A+ if (on_ac == TRUE) {
14345N/A+ gpm_conf_get_bool (cpufreq->priv->conf, GPM_CONF_CPUFREQ_USE_NICE, &cpufreq_consider_nice);
14345N/A+ gpm_conf_get_string (cpufreq->priv->conf, GPM_CONF_CPUFREQ_POLICY_AC, &cpufreq_policy);
14345N/A+ gpm_conf_get_uint (cpufreq->priv->conf, GPM_CONF_CPUFREQ_PERFORMANCE_AC, &cpufreq_performance);
14345N/A+ } else {
14345N/A+ gpm_conf_get_bool (cpufreq->priv->conf, GPM_CONF_CPUFREQ_USE_NICE, &cpufreq_consider_nice);
14345N/A+ gpm_conf_get_string (cpufreq->priv->conf, GPM_CONF_CPUFREQ_POLICY_BATT, &cpufreq_policy);
14345N/A+ gpm_conf_get_uint (cpufreq->priv->conf, GPM_CONF_CPUFREQ_PERFORMANCE_BATT, &cpufreq_performance);
14345N/A+ }
14345N/A+
14345N/A+ /* use enumerated value */
14345N/A+ cpufreq_type = hal_gcpufreq_string_to_enum (cpufreq_policy);
14345N/A+ g_free (cpufreq_policy);
14345N/A+
14345N/A+ /* change to the right governer and settings */
14345N/A+ hal_gcpufreq_set_governor (cpufreq->priv->hal_cpufreq, cpufreq_type);
14345N/A+ hal_gcpufreq_set_consider_nice (cpufreq->priv->hal_cpufreq, cpufreq_consider_nice);
14345N/A+ // Fix for bugster #6727770. hal_gcpufreq_set_performance (cpufreq->priv->hal_cpufreq, cpufreq_performance);
14345N/A+ return TRUE;
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * conf_key_changed_cb:
14345N/A+ *
14345N/A+ * We might have to do things when the gconf keys change; do them here.
14345N/A+ **/
14345N/A+static void
14345N/A+conf_key_changed_cb (GpmConf *conf,
14345N/A+ const gchar *key,
14345N/A+ GpmCpufreq *cpufreq)
14345N/A+{
14345N/A+ /* if any change, just resync the whole lot */
14345N/A+ if (strcmp (key, GPM_CONF_CPUFREQ_POLICY_AC) == 0 ||
14345N/A+ strcmp (key, GPM_CONF_CPUFREQ_PERFORMANCE_AC) == 0 ||
14345N/A+ strcmp (key, GPM_CONF_CPUFREQ_POLICY_BATT) == 0 ||
14345N/A+ strcmp (key, GPM_CONF_CPUFREQ_PERFORMANCE_BATT) == 0 ||
14345N/A+ strcmp (key, GPM_CONF_CPUFREQ_USE_NICE) == 0) {
14345N/A+
14345N/A+ gpm_cpufreq_sync_policy (cpufreq);
14345N/A+ }
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * ac_adapter_changed_cb:
14345N/A+ * @ac_adapter: The ac_adapter class instance
14345N/A+ * @on_ac: if we are on AC power
14345N/A+ * @cpufreq: This class instance
14345N/A+ *
14345N/A+ * Does the actions when the ac power source is inserted/removed.
14345N/A+ **/
14345N/A+static void
14345N/A+ac_adapter_changed_cb (GpmAcAdapter *ac_adapter,
14345N/A+ gboolean on_ac,
14345N/A+ GpmCpufreq *cpufreq)
14345N/A+{
14345N/A+ gpm_cpufreq_sync_policy (cpufreq);
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * gpm_cpufreq_class_init:
14345N/A+ * @klass: This class instance
14345N/A+ **/
14345N/A+static void
14345N/A+gpm_cpufreq_class_init (GpmCpufreqClass *klass)
14345N/A+{
14345N/A+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
14345N/A+ object_class->finalize = gpm_cpufreq_finalize;
14345N/A+ g_type_class_add_private (klass, sizeof (GpmCpufreqPrivate));
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * gpm_cpufreq_init:
14345N/A+ *
14345N/A+ * @cpufreq: This class instance
14345N/A+ **/
14345N/A+static void
14345N/A+gpm_cpufreq_init (GpmCpufreq *cpufreq)
14345N/A+{
14345N/A+ cpufreq->priv = GPM_CPUFREQ_GET_PRIVATE (cpufreq);
14345N/A+
14345N/A+ /* we use cpufreq as the master class */
14345N/A+ cpufreq->priv->hal_cpufreq = hal_gcpufreq_new ();
14345N/A+
14345N/A+ /* get changes from gconf */
14345N/A+ cpufreq->priv->conf = gpm_conf_new ();
14345N/A+ g_signal_connect (cpufreq->priv->conf, "value-changed",
14345N/A+ G_CALLBACK (conf_key_changed_cb), cpufreq);
14345N/A+
14345N/A+ /* we use ac_adapter for the ac-adapter-changed signal */
14345N/A+ cpufreq->priv->ac_adapter = gpm_ac_adapter_new ();
14345N/A+ g_signal_connect (cpufreq->priv->ac_adapter, "ac-adapter-changed",
14345N/A+ G_CALLBACK (ac_adapter_changed_cb), cpufreq);
14345N/A+
14345N/A+ /* sync policy */
14345N/A+#if defined(sun) && defined(__SVR4)
14345N/A+ gpm_cpufreq_sync_policy_from_system_to_gconf (cpufreq);
14345N/A+#else
14345N/A+ gpm_cpufreq_sync_policy (cpufreq);
14345N/A+#endif
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * gpm_cpufreq_finalize:
14345N/A+ * @object: This class instance
14345N/A+ **/
14345N/A+static void
14345N/A+gpm_cpufreq_finalize (GObject *object)
14345N/A+{
14345N/A+ GpmCpufreq *cpufreq;
14345N/A+ g_return_if_fail (object != NULL);
14345N/A+ g_return_if_fail (GPM_IS_CPUFREQ (object));
14345N/A+
14345N/A+ cpufreq = GPM_CPUFREQ (object);
14345N/A+ cpufreq->priv = GPM_CPUFREQ_GET_PRIVATE (cpufreq);
14345N/A+
14345N/A+ if (cpufreq->priv->hal_cpufreq != NULL) {
14345N/A+ g_object_unref (cpufreq->priv->hal_cpufreq);
14345N/A+ }
14345N/A+ if (cpufreq->priv->conf != NULL) {
14345N/A+ g_object_unref (cpufreq->priv->conf);
14345N/A+ }
14345N/A+ if (cpufreq->priv->ac_adapter != NULL) {
14345N/A+ g_object_unref (cpufreq->priv->ac_adapter);
14345N/A+ }
14345N/A+ G_OBJECT_CLASS (gpm_cpufreq_parent_class)->finalize (object);
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * gpm_cpufreq_new:
14345N/A+ * Return value: new GpmCpufreq instance.
14345N/A+ **/
14345N/A+GpmCpufreq *
14345N/A+gpm_cpufreq_new (void)
14345N/A+{
14345N/A+ GpmCpufreq *cpufreq = NULL;
14345N/A+
14345N/A+ /* only load if we have the hardware */
14345N/A+ if (hal_gcpufreq_has_hw() == TRUE) {
14345N/A+ cpufreq = g_object_new (GPM_TYPE_CPUFREQ, NULL);
14345N/A+ }
14345N/A+
14345N/A+ return cpufreq;
14345N/A+}
14345N/A+
14345N/A--- src/gpm-conf.h.orig 2008-09-16 10:56:10.738304000 +0800
14345N/A+++ src/gpm-conf.h 2008-09-16 10:56:30.989120000 +0800
14345N/A@@ -72,6 +72,13 @@
14345N/A #define GPM_CONF_BUTTON_HIBERNATE GPM_CONF_DIR "/buttons/hibernate"
14345N/A #define GPM_CONF_BUTTON_POWER GPM_CONF_DIR "/buttons/power"
14345N/A
14345N/A+/* cpufreq */
14345N/A+#define GPM_CONF_CPUFREQ_POLICY_AC GPM_CONF_DIR "/cpufreq/policy_ac"
14345N/A+#define GPM_CONF_CPUFREQ_POLICY_BATT GPM_CONF_DIR "/cpufreq/policy_battery"
14345N/A+#define GPM_CONF_CPUFREQ_PERFORMANCE_AC GPM_CONF_DIR "/cpufreq/performance_ac"
14345N/A+#define GPM_CONF_CPUFREQ_PERFORMANCE_BATT GPM_CONF_DIR "/cpufreq/performance_battery"
14345N/A+#define GPM_CONF_CPUFREQ_USE_NICE GPM_CONF_DIR "/cpufreq/consider_nice"
14345N/A+
14345N/A /* general */
14345N/A #define GPM_CONF_DEBUG GPM_CONF_DIR "/general/debug"
14345N/A #define GPM_CONF_SCHEMA_VERSION GPM_CONF_DIR "/general/installed_schema"
14345N/A--- src/gpm-prefs-core.c.orig 2008-09-16 11:14:29.546125000 +0800
14345N/A+++ src/gpm-prefs-core.c 2008-09-16 13:08:23.567034000 +0800
14345N/A@@ -34,6 +34,7 @@
14345N/A #include <gconf/gconf-client.h>
14345N/A
14345N/A #include <libhal-gmanager.h>
14345N/A+#include <libhal-gcpufreq.h>
14345N/A
14345N/A #include "gpm-tray-icon.h"
14345N/A #include "gpm-common.h"
14345N/A@@ -79,6 +80,8 @@
14345N/A #ifdef HAVE_GCONF_DEFAULTS
14345N/A PolKitGnomeAction *default_action;
14345N/A #endif
14345N/A+ HalGCpufreq *hal_cpufreq;
14345N/A+ HalGCpufreqType cpufreq_types;
14345N/A };
14345N/A
14345N/A enum {
15932N/A@@ -99,6 +102,17 @@
14345N/A #define ACTION_BLANK_TEXT _("Blank screen")
14345N/A #define ACTION_NOTHING_TEXT _("Do nothing")
14345N/A
14345N/A+/* The text that should appear in the processor combo box */
14345N/A+#define CPUFREQ_NOTHING_TEXT _("Do nothing")
15932N/A+/* SUN_BRANDING */
14345N/A+#define CPUFREQ_ONDEMAND_TEXT _("Based on processor load")
15932N/A+/* SUN_BRANDING */
14345N/A+#define CPUFREQ_CONSERVATIVE_TEXT _("Automatic power saving")
15932N/A+/* SUN_BRANDING */
14345N/A+#define CPUFREQ_POWERSAVE_TEXT _("Maximum power saving")
15932N/A+/* SUN_BRANDING */
14345N/A+#define CPUFREQ_PERFORMANCE_TEXT _("Always maximum speed")
14345N/A+
14345N/A /* If sleep time in a slider is set to 61 it is considered as never */
14345N/A const int NEVER_TIME_ON_SLIDER = 61;
14345N/A
15932N/A@@ -704,6 +718,134 @@
14345N/A }
14345N/A }
14345N/A
14345N/A+/**
14345N/A+ * gpm_prefs_processor_combo_changed_cb:
14345N/A+ * @widget: The GtkWidget object
14345N/A+ * @gpm_pref_key: The GConf key for this preference setting.
14345N/A+ **/
14345N/A+static void
14345N/A+gpm_prefs_processor_combo_changed_cb (GtkWidget *widget,
14345N/A+ GpmPrefs *prefs)
14345N/A+{
14345N/A+ gchar *value;
14345N/A+ const gchar *policy;
14345N/A+ gchar *gpm_pref_key;
14345N/A+
14345N/A+ value = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget));
14345N/A+ if (value == NULL) {
14471N/A+ egg_warning ("active text failed");
14345N/A+ return;
14345N/A+ }
14345N/A+ if (strcmp (value, CPUFREQ_ONDEMAND_TEXT) == 0) {
14345N/A+ policy = CODE_CPUFREQ_ONDEMAND;
14345N/A+ } else if (strcmp (value, CPUFREQ_CONSERVATIVE_TEXT) == 0) {
14345N/A+ policy = CODE_CPUFREQ_CONSERVATIVE;
14345N/A+ } else if (strcmp (value, CPUFREQ_POWERSAVE_TEXT) == 0) {
14345N/A+ policy = CODE_CPUFREQ_POWERSAVE;
14345N/A+ } else if (strcmp (value, CPUFREQ_PERFORMANCE_TEXT) == 0) {
14345N/A+ policy = CODE_CPUFREQ_PERFORMANCE;
14345N/A+ } else if (strcmp (value, CPUFREQ_NOTHING_TEXT) == 0) {
14345N/A+ policy = CODE_CPUFREQ_NOTHING;
14345N/A+ } else {
14345N/A+ g_assert (FALSE);
14345N/A+ }
14345N/A+
14345N/A+ g_free (value);
14345N/A+ gpm_pref_key = (char *) g_object_get_data (G_OBJECT (widget), "conf_key");
14471N/A+ egg_debug ("Changing %s to %s", gpm_pref_key, policy);
14345N/A+ gpm_conf_set_string (prefs->priv->conf, gpm_pref_key, policy);
14345N/A+}
14345N/A+
14345N/A+/**
14345N/A+ * gpm_prefs_setup_action_combo:
14345N/A+ * @prefs: This prefs class instance
14345N/A+ * @widget_name: The GtkWidget name
14345N/A+ * @gpm_pref_key: The GConf key for this preference setting.
14345N/A+ * @actions: The actions to associate in an array.
14345N/A+ **/
14345N/A+static void
14345N/A+gpm_prefs_setup_processor_combo (GpmPrefs *prefs,
14345N/A+ const gchar *widget_name,
14345N/A+ const gchar *gpm_pref_key,
14345N/A+ HalGCpufreqType cpufreq_types)
14345N/A+{
14345N/A+ gchar *value;
14345N/A+ guint n_added = 0;
14345N/A+ gboolean has_option = FALSE;
14345N/A+ gboolean is_writable;
14345N/A+ GtkWidget *widget;
14345N/A+ HalGCpufreqType cpufreq_type;
14345N/A+
14345N/A+ widget = glade_xml_get_widget (prefs->priv->glade_xml, widget_name);
14345N/A+ gpm_conf_get_string (prefs->priv->conf, gpm_pref_key, &value);
14345N/A+ gpm_conf_is_writable (prefs->priv->conf, gpm_pref_key, &is_writable);
14345N/A+
14345N/A+ gtk_widget_set_sensitive (widget, is_writable);
14345N/A+
14345N/A+ if (value == NULL) {
14471N/A+ egg_warning ("invalid schema, please re-install");
14345N/A+ value = g_strdup ("nothing");
14345N/A+ }
14345N/A+
14345N/A+ g_object_set_data (G_OBJECT (widget), "conf_key", (gpointer) gpm_pref_key);
14345N/A+ g_signal_connect (G_OBJECT (widget), "changed",
14345N/A+ G_CALLBACK (gpm_prefs_processor_combo_changed_cb),
14345N/A+ prefs);
14345N/A+
14345N/A+ cpufreq_type = hal_gcpufreq_string_to_enum (value);
14345N/A+
14345N/A+ if (cpufreq_types & LIBHAL_CPUFREQ_ONDEMAND) {
14345N/A+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
14345N/A+ CPUFREQ_ONDEMAND_TEXT);
14345N/A+ if (cpufreq_type == LIBHAL_CPUFREQ_ONDEMAND) {
14345N/A+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), n_added);
14345N/A+ has_option = TRUE;
14345N/A+ }
14345N/A+ n_added++;
14345N/A+ }
14345N/A+ if (cpufreq_types & LIBHAL_CPUFREQ_NOTHING) {
14345N/A+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
14345N/A+ CPUFREQ_NOTHING_TEXT);
14345N/A+ if (cpufreq_type == LIBHAL_CPUFREQ_ONDEMAND) {
14345N/A+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), n_added);
14345N/A+ has_option = TRUE;
14345N/A+ }
14345N/A+ n_added++;
14345N/A+ }
14345N/A+ if (cpufreq_types & LIBHAL_CPUFREQ_CONSERVATIVE) {
14345N/A+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
14345N/A+ CPUFREQ_CONSERVATIVE_TEXT);
14345N/A+ if (cpufreq_type == LIBHAL_CPUFREQ_CONSERVATIVE) {
14345N/A+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), n_added);
14345N/A+ has_option = TRUE;
14345N/A+ }
14345N/A+ n_added++;
14345N/A+ }
14345N/A+ if (cpufreq_types & LIBHAL_CPUFREQ_POWERSAVE) {
14345N/A+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
14345N/A+ CPUFREQ_POWERSAVE_TEXT);
14345N/A+ if (cpufreq_type == LIBHAL_CPUFREQ_POWERSAVE) {
14345N/A+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), n_added);
14345N/A+ has_option = TRUE;
14345N/A+ }
14345N/A+ n_added++;
14345N/A+ }
14345N/A+ if (cpufreq_types & LIBHAL_CPUFREQ_PERFORMANCE) {
14345N/A+ gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
14345N/A+ CPUFREQ_PERFORMANCE_TEXT);
14345N/A+ if (cpufreq_type == LIBHAL_CPUFREQ_PERFORMANCE) {
14345N/A+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), n_added);
14345N/A+ has_option = TRUE;
14345N/A+ }
14345N/A+ n_added++;
14345N/A+ }
14345N/A+
14345N/A+ if (has_option == FALSE || cpufreq_type == LIBHAL_CPUFREQ_NOTHING) {
14345N/A+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), n_added);
14345N/A+ }
14345N/A+ g_free (value);
14345N/A+}
14345N/A+
14345N/A /** setup the notification page */
14345N/A static void
14345N/A prefs_setup_notification (GpmPrefs *prefs)
15932N/A@@ -815,6 +957,7 @@
14345N/A gint page;
14345N/A
14345N/A if ((prefs->priv->has_button_lid == FALSE)
14345N/A+ && (prefs->priv->hal_cpufreq == FALSE)
14345N/A && (prefs->priv->has_lcd == FALSE)) {
14345N/A notebook = glade_xml_get_widget (prefs->priv->glade_xml, "notebook_preferences");
14345N/A widget = glade_xml_get_widget (prefs->priv->glade_xml, "vbox_ac");
15932N/A@@ -827,6 +970,8 @@
14345N/A gpm_prefs_setup_action_combo (prefs, "combobox_ac_lid",
14345N/A GPM_CONF_BUTTON_LID_AC,
14345N/A button_lid_actions);
14345N/A+ gpm_prefs_setup_processor_combo (prefs, "combobox_ac_cpu",
14345N/A+ GPM_CONF_CPUFREQ_POLICY_AC, prefs->priv->cpufreq_types);
14345N/A gpm_prefs_setup_sleep_slider (prefs, "hscale_ac_computer",
14345N/A GPM_CONF_TIMEOUT_SLEEP_COMPUTER_AC);
14345N/A gpm_prefs_setup_sleep_slider (prefs, "hscale_ac_display",
15932N/A@@ -845,6 +990,16 @@
14345N/A widget = glade_xml_get_widget (prefs->priv->glade_xml, "hbox_ac_lid");
14345N/A gtk_widget_hide_all (widget);
14345N/A }
14345N/A+
14345N/A+#if defined(sun) && defined(__SVR4)
14345N/A+ if (prefs->priv->hal_cpufreq == NULL || prefs->priv->can_cpufreq == FALSE ) {
14345N/A+#else
14345N/A+ if (prefs->priv->hal_cpufreq == NULL) {
14345N/A+#endif
14345N/A+ widget = glade_xml_get_widget (prefs->priv->glade_xml, "hbox_ac_cpu");
14345N/A+ gtk_widget_hide_all (widget);
14345N/A+ }
14345N/A+
14345N/A #if defined(sun) && defined(__SVR4)
14345N/A if (prefs->priv->has_lcd == FALSE || prefs->priv->can_brightness == FALSE) {
14345N/A #else
15932N/A@@ -1060,6 +1064,8 @@
14441N/A gpm_prefs_setup_action_combo (prefs, "combobox_battery_critical",
14441N/A GPM_CONF_ACTIONS_CRITICAL_BATT,
14441N/A battery_critical_actions);
14441N/A+ gpm_prefs_setup_processor_combo (prefs, "combobox_battery_cpu",
14441N/A+ GPM_CONF_CPUFREQ_POLICY_BATT, prefs->priv->cpufreq_types);
14441N/A gpm_prefs_setup_sleep_slider (prefs, "hscale_battery_computer",
14441N/A GPM_CONF_TIMEOUT_SLEEP_COMPUTER_BATT);
14441N/A gpm_prefs_setup_sleep_slider (prefs, "hscale_battery_display",
15932N/A@@ -1133,6 +1288,8 @@
14345N/A
14345N/A prefs->priv = GPM_PREFS_GET_PRIVATE (prefs);
14345N/A
14345N/A+ prefs->priv->hal_cpufreq = hal_gcpufreq_new ();
14345N/A+
14345N/A prefs->priv->screensaver = gpm_screensaver_new ();
14345N/A g_signal_connect (prefs->priv->screensaver, "gs-delay-changed",
14345N/A G_CALLBACK (gs_delay_changed_cb), prefs);
15932N/A@@ -1161,6 +1318,7 @@
14345N/A GpmControl *control = gpm_control_new ();
14345N/A if (control) {
14345N/A prefs->priv->can_cpufreq = gpm_control_is_user_privileged (control, "hal-power-cpu");
14345N/A+ prefs->priv->can_cpufreq = 1;
14345N/A prefs->priv->can_brightness = gpm_control_is_user_privileged (control, "hal-power-brightness");
14345N/A g_object_unref (control);
14345N/A } else {
15932N/A@@ -1178,6 +1336,14 @@
14345N/A gpk_prefs_setup_policykit (prefs);
14345N/A #endif
14345N/A
14345N/A+ /* only enable cpufreq stuff if we have the hardware */
14345N/A+ if (prefs->priv->hal_cpufreq) {
14345N/A+ hal_gcpufreq_get_governors (prefs->priv->hal_cpufreq,
14345N/A+ &prefs->priv->cpufreq_types);
14345N/A+ } else {
14345N/A+ prefs->priv->cpufreq_types = LIBHAL_CPUFREQ_NOTHING;
14345N/A+ }
14345N/A+
14345N/A prefs->priv->glade_xml = glade_xml_new (GPM_DATA "/gpm-prefs.glade", NULL, NULL);
14345N/A if (prefs->priv->glade_xml == NULL) {
14345N/A g_error ("Cannot find 'gpm-prefs.glade'");
15932N/A@@ -1235,6 +1401,10 @@
14345N/A g_object_unref (prefs->priv->screensaver);
14345N/A }
14345N/A
14345N/A+ if (prefs->priv->hal_cpufreq) {
14345N/A+ g_object_unref (prefs->priv->hal_cpufreq);
14345N/A+ }
14345N/A+
14345N/A G_OBJECT_CLASS (gpm_prefs_parent_class)->finalize (object);
14345N/A }
14345N/A
14345N/A--- src/gpm-manager.c.orig 2008-09-16 14:48:55.069459000 +0800
14345N/A+++ src/gpm-manager.c 2008-09-16 14:58:21.514052000 +0800
14345N/A@@ -48,6 +48,7 @@
14345N/A #include "gpm-conf.h"
14345N/A #include "gpm-control.h"
14345N/A #include "gpm-common.h"
14345N/A+#include "gpm-cpufreq.h"
14471N/A #include "egg-debug.h"
14345N/A #include "gpm-dpms.h"
14345N/A #include "gpm-idle.h"
14345N/A@@ -99,6 +100,7 @@
14345N/A GpmBacklight *backlight;
15445N/A EggConsoleKit *console;
14345N/A GpmSrvBrightnessKbd *srv_brightness_kbd;
14345N/A+ GpmCpufreq *cpufreq;
14345N/A GpmSrvScreensaver *srv_screensaver;
14345N/A };
14345N/A
14345N/A@@ -1742,6 +1744,8 @@
14345N/A manager->priv->sound = gpm_sound_new ();
14345N/A
14345N/A /* try and start an interactive service */
14345N/A+ manager->priv->cpufreq = gpm_cpufreq_new ();
14345N/A+
14345N/A manager->priv->screensaver = gpm_screensaver_new ();
14345N/A g_signal_connect (manager->priv->screensaver, "auth-request",
14345N/A G_CALLBACK (screensaver_auth_request_cb), manager);