[Goodies-commits] r2123 - in xfce4-cpufreq-plugin/trunk: . panel-plugin

Thomas Schreck shrek at xfce.org
Mon Oct 23 10:45:20 CEST 2006


Author: shrek
Date: 2006-10-23 08:45:16 +0000 (Mon, 23 Oct 2006)
New Revision: 2123

Modified:
   xfce4-cpufreq-plugin/trunk/ChangeLog
   xfce4-cpufreq-plugin/trunk/configure.ac
   xfce4-cpufreq-plugin/trunk/panel-plugin/Makefile.am
   xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-configure.c
   xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-configure.h
   xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.c
   xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.h
   xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-overview.c
   xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.c
   xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.h
Log:
2006-10-23 10:30  Thomas Schreck <shrek at xfce.org>

        * Dropped libgksu and libgksuui
        * removed support for changing frequency and governor
        * Linux 2.4 support


Modified: xfce4-cpufreq-plugin/trunk/ChangeLog
===================================================================
--- xfce4-cpufreq-plugin/trunk/ChangeLog	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/ChangeLog	2006-10-23 08:45:16 UTC (rev 2123)
@@ -1,3 +1,9 @@
+2006-10-23 10:30  Thomas Schreck <shrek at xfce.org>
+
+	* Dropped libgksu and libgksuui
+	* removed support for changing frequency and governor
+	* Linux 2.4 support
+
 2006-08-24 17:45  Thomas Schreck <shrek at xfce.org>
 
 	* Fix typo

Modified: xfce4-cpufreq-plugin/trunk/configure.ac
===================================================================
--- xfce4-cpufreq-plugin/trunk/configure.ac	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/configure.ac	2006-10-23 08:45:16 UTC (rev 2123)
@@ -32,8 +32,6 @@
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.3.90])
 XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.3.90])
 XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.3.90])
-XDT_CHECK_PACKAGE([LIBGKSU], [libgksu1.2], [1.3.8])
-XDT_CHECK_PACKAGE([LIBGKSUUI], [libgksuui1.0], [1.0.7])
 
 AC_OUTPUT([
 Makefile

Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/Makefile.am	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/Makefile.am	2006-10-23 08:45:16 UTC (rev 2123)
@@ -6,16 +6,12 @@
 	@LIBXFCE4PANEL_CFLAGS@					\
 	@LIBXFCE4UTIL_CFLAGS@					\
 	@LIBXFCEGUI4_CFLAGS@					\
-	@LIBGKSU_CFLAGS@					\
-	@LIBGKSUUI_CFLAGS@					\
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"
 
 xfce4_cpufreq_plugin_LDFLAGS =					\
 	@LIBXFCE4PANEL_LIBS@					\
 	@LIBXFCE4UTIL_LIBS@					\
-	@LIBXFCEGUI4_LIBS@					\
-	@LIBGKSU_LIBS@						\
-	@LIBGKSUUI_LIBS@
+	@LIBXFCEGUI4_LIBS@
 
 xfce4_cpufreq_plugin_SOURCES =					\
 	xfce4-cpufreq-plugin.h					\

Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-configure.c
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-configure.c	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-configure.c	2006-10-23 08:45:16 UTC (rev 2123)
@@ -16,18 +16,16 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #define BORDER 		1
 #define TIMEOUT_MIN	0.5
 #define TIMEOUT_MAX	3
 #define TIMEOUT_STEP	0.5
 
-#include <libxfcegui4/libxfcegui4.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
+#include <libxfcegui4/libxfcegui4.h>
 #include "xfce4-cpufreq-plugin.h"
 #include "xfce4-cpufreq-configure.h"
 
@@ -94,6 +92,7 @@
 cpufreq_configure (XfcePanelPlugin *plugin)
 {
 	gint i;
+	gchar *cpu_name;
 	GtkWidget *dialog, *dialog_vbox, *header;
 	GtkWidget *frame, *align, *label, *vbox, *hbox;
 	GtkWidget *combo, *spinner, *button;
@@ -179,7 +178,7 @@
 
 	for (i = 0; i < cpuFreq->cpus->len; ++i)
 	{
-		gchar *cpu_name = g_strdup_printf ("%d", i);
+		cpu_name = g_strdup_printf ("%d", i);
 		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), cpu_name);
 		g_free (cpu_name);
 	}

Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-configure.h
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-configure.h	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-configure.h	2006-10-23 08:45:16 UTC (rev 2123)
@@ -22,7 +22,7 @@
 
 typedef struct
 {
-	GtkWidget *main, *display_icon, *display_freq, *display_governor;
+	GtkWidget *display_icon, *display_freq, *display_governor;
 	GtkWidget *display_cpu, *display_frame, *monitor_timeout;
 	GtkWidget *combo_cpu, *spinner_timeout;
 } CpuFreqPluginConfigure;

Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.c
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.c	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.c	2006-10-23 08:45:16 UTC (rev 2123)
@@ -22,12 +22,10 @@
 #endif
 
 #include <dirent.h>
-#include <gksuui.h>
-
 #include "xfce4-cpufreq-plugin.h"
 #include "xfce4-cpufreq-linux.h"
 
-gboolean
+static gboolean
 cpufreq_cpu_parse_sysfs_init (gint cpu_number)
 {
 	CpuInfo *cpu;
@@ -177,7 +175,7 @@
 	return FALSE;
 }
 
-gboolean
+static gboolean
 cpufreq_cpu_read_sysfs_current (gint cpu_number)
 {
 	CpuInfo *cpu;
@@ -221,115 +219,140 @@
 	return FALSE;
 }
 
-gboolean
-cpufreq_cpu_read_sysfs ()
+static gboolean
+cpufreq_cpu_read_procfs_cpuinfo ()
 {
-	gint j, i = -2;
-	DIR *dir;
-	struct dirent *dir_entry;
+	CpuInfo	*cpu;
+	FILE	*file;
+	gchar	*freq, *filePath, *fileContent;
 
-	if ((dir = opendir ("/sys/devices/system/cpu")) != NULL)
+	filePath = g_strdup ("/proc/cpuinfo");
+	if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
 	{
-		while ((dir_entry = readdir (dir)) != NULL)
-			i++;
+		g_free (filePath);
+		return FALSE;
 	}
-	else
-		return FALSE;
-	closedir (dir);
+	file = fopen (filePath, "r");
+	if (file)
+	{
+		fileContent = g_new (gchar,255);
+		while (fgets (fileContent, 255, file) != NULL)
+		{
+			if (g_ascii_strncasecmp (fileContent, "cpu MHz", 7) == 0)
+			{
+				cpu = g_new0 (CpuInfo, 1);
+				cpu->max_freq = 0;
+				cpu->min_freq = 0;
+				cpu->cur_governor = NULL;
+				cpu->available_freqs = NULL;
+				cpu->available_governors = NULL;
 
-	for (j = 0; j < i; j++)
-	{
-		cpufreq_cpu_parse_sysfs_init (j);
+				freq = g_strrstr (fileContent, ":");
+				if (freq != NULL)
+				{
+					sscanf (++freq, "%d.", &cpu->cur_freq);
+					cpu->cur_freq *= 1000;
+				}
+				else
+					break;
+
+				g_ptr_array_add (cpuFreq->cpus, cpu);
+			}
+		}
+		fclose (file);
+		g_free (fileContent);
 	}
 
+	g_free (filePath);
 	return TRUE;
 }
 
-gboolean
-cpufreq_cpu_set_freq (guint cpu_number, guint *freq)
+static gboolean
+cpufreq_cpu_read_procfs ()
 {
-	gchar     *cmd, *cpu_num, *cpu_freq;
-	GtkWidget *gksuui_dialog;
-	GError    *error = NULL;
+	CpuInfo *cpu;
+	FILE	*file;
+	gint	i;
+	gchar	*filePath, *fileContent;
 
-	// TODO check if freq is different
-	
-	cpu_freq = g_new (gchar, 30);
-	cpu_num  = g_new (gchar, 3);
-	sprintf (cpu_num, "%d", cpu_number);
-	sprintf (cpu_freq, "%d", freq);
-	cmd = g_strconcat ("/bin/echo ",
-			cpu_freq,
-			" > /sys/devices/system/cpu/cpu",
-			cpu_num,
-			"/cpufreq/scaling_setspeed",
-			NULL);
-
-	if (gksu_context_try_need_password (cpuFreq->gksu_ctx))
+	filePath = g_strdup ("/proc/cpufreq");
+	if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
 	{
-		gksuui_dialog = gksuui_dialog_new ();
-		gksuui_dialog_set_message (GKSUUI_DIALOG (gksuui_dialog),
-				_("Please enter root password to change CPU frequency !"));
-		gtk_widget_show_all (gksuui_dialog);
-		if (gtk_dialog_run (GTK_DIALOG (gksuui_dialog)))
-			gksu_context_set_password (cpuFreq->gksu_ctx,
-					gksuui_dialog_get_password (GKSUUI_DIALOG (gksuui_dialog)));
+		g_free (filePath);
+		return FALSE;
+	}
+	file = fopen (filePath, "r");
+	if (file)
+	{
+		fileContent = g_new (gchar, 255);
+		while (fgets (fileContent, 255, file) != NULL)
+		{
+			if (g_ascii_strncasecmp (fileContent, "CPU", 3) == 0)
+			{
+				cpu = g_new0 (CpuInfo, 1);
+				cpu->max_freq = 0;
+				cpu->min_freq = 0;
+				cpu->cur_governor = g_new (gchar, 20);
+				cpu->available_freqs = NULL;
+				cpu->available_governors = NULL;
 
-		gtk_widget_hide (gksuui_dialog);
+				sscanf (fileContent, 
+					"CPU %d %d kHz (%d %%) - %d kHz (%d %%) - %20s",
+					NULL, &cpu->min_freq,
+					NULL, &cpu->max_freq,
+					NULL, cpu->cur_governor);
+				cpu->min_freq *= 1000;
+				cpu->max_freq *= 1000;
+
+				g_ptr_array_add (cpuFreq->cpus, cpu);
+			}
+		}
+		fclose (file);
+		g_free (fileContent);
 	}
+	g_free (filePath);
 
-	gksu_context_set_command (cpuFreq->gksu_ctx, cmd);
-	gksu_context_run (cpuFreq->gksu_ctx, &error);
-
-	g_free (cpu_num);
-	g_free (cpu_freq);
-	g_free (cmd);
-	
-	if (error)
-		return FALSE;
+	for (i = 0; i < cpuFreq->cpus->len; i++)
+	{
+		cpu = g_ptr_array_index (cpuFreq->cpus, i);
+		filePath = g_strdup_printf ("/proc/sys/cpu/%d/speed", i);
+		if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
+		{
+			g_free (filePath);
+			return FALSE;
+		}
+		file = fopen (filePath, "r");
+		if (file)
+		{
+			fscanf (file, "%d", &cpu->cur_freq);
+			fclose (file);
+		}
+		g_free (filePath);
+	}
 	return TRUE;
 }
 
-gboolean
-cpufreq_cpu_set_governor (guint cpu_number, gchar *governor)
+static gboolean
+cpufreq_cpu_read_sysfs ()
 {
-	gchar	  *cmd, *cpu_num;
-	GtkWidget *gksuui_dialog;
-	GError	  *error = NULL;
+	gint j, i = -2;
+	DIR *dir;
+	struct dirent *dir_entry;
 
-	if (governor == NULL) //TODO && governor in list
+	if ((dir = opendir ("/sys/devices/system/cpu")) != NULL)
+	{
+		while ((dir_entry = readdir (dir)) != NULL)
+			i++;
+	}
+	else
 		return FALSE;
+	closedir (dir);
 
-	cpu_num = g_new (gchar, 3);
-	sprintf (cpu_num, "%d", cpu_number);
-	cmd = g_strconcat ("/bin/echo ", 
-			governor, 
-			" > /sys/devices/system/cpu/cpu", 
-			cpu_num, 
-			"/cpufreq/scaling_governor", 
-			NULL);
-
-	if (gksu_context_try_need_password (cpuFreq->gksu_ctx))
+	for (j = 0; j < i; j++)
 	{
-		gksuui_dialog = gksuui_dialog_new ();
-		gksuui_dialog_set_message (GKSUUI_DIALOG (gksuui_dialog),
-				_("Please enter root password to change CPU governor !"));
-		gtk_widget_show_all (gksuui_dialog);
-		if (gtk_dialog_run (GTK_DIALOG (gksuui_dialog)))
-			gksu_context_set_password (cpuFreq->gksu_ctx,
-				gksuui_dialog_get_password (GKSUUI_DIALOG (gksuui_dialog)));
-		
-		gtk_widget_hide (gksuui_dialog);
+		cpufreq_cpu_parse_sysfs_init (j);
 	}
 
-	gksu_context_set_command (cpuFreq->gksu_ctx, cmd);
-	gksu_context_run (cpuFreq->gksu_ctx, &error);
-
-	g_free (cpu_num);
-	g_free (cmd);
-
-	if (error)
-		return FALSE;
 	return TRUE;
 }
 
@@ -338,8 +361,28 @@
 {
 	gint i;
 
-	for (i = 0; i < cpuFreq->cpus->len; i++)
-		cpufreq_cpu_read_sysfs_current (i);
+	if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS))
+	{
+		for (i = 0; i < cpuFreq->cpus->len; i++)
+			cpufreq_cpu_read_sysfs_current (i);
+	}
+	else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS))
+	{
+		/* First we delete the cpus and then read the /proc/cpufreq file again */
+		for (i = 0; i < cpuFreq->cpus->len; i++)
+		{
+			CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
+			g_ptr_array_remove_fast (cpuFreq->cpus, cpu);
+			g_free (cpu->cur_governor);
+			g_free (cpu);
+		}
+		cpufreq_cpu_read_procfs ();
+	}
+	else
+	{
+		/* We do not need to update, because no scaling available */
+		return FALSE;
+	}
 
 	return cpufreq_update_plugin ();
 }
@@ -351,9 +394,11 @@
 		return FALSE;
 
 	if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS))
-	{
 		return cpufreq_cpu_read_sysfs ();
+	else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS))
+		return cpufreq_cpu_read_procfs ();
+	else
+	{	xfce_warn (_("Your system does not support cpufreq.\nThe applet only shows the current cpu frequency"));
+		return cpufreq_cpu_read_procfs_cpuinfo ();
 	}
-	else
-		return FALSE;
 }

Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.h
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.h	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.h	2006-10-23 08:45:16 UTC (rev 2123)
@@ -23,12 +23,6 @@
 G_BEGIN_DECLS
 
 gboolean
-cpufreq_cpu_set_freq (guint cpu_number, guint *freq);
-
-gboolean
-cpufreq_cpu_set_governor (guint cpu_number, gchar *governor);
-
-gboolean
 cpufreq_update_cpus (gpointer data);
 
 gboolean

Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-overview.c
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-overview.c	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-overview.c	2006-10-23 08:45:16 UTC (rev 2123)
@@ -16,69 +16,20 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
+#define BORDER 1
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-#define BORDER 1
-
 #include <libxfcegui4/libxfcegui4.h>
-
 #include "xfce4-cpufreq-plugin.h"
+#ifdef __linux__
 #include "xfce4-cpufreq-linux.h"
+#endif /* __linux__ */
 #include "xfce4-cpufreq-overview.h"
 
 static void
-freq_combo_changed (GtkWidget *combo, guint cpu_number)
-{
-	guint	freq;
-	gchar   *new_freq;
-	CpuInfo *cpu;
-
-	cpu      = g_ptr_array_index (cpuFreq->cpus, cpu_number);
-	new_freq = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
-	freq     = cpufreq_get_normal_freq (new_freq);
-
-	if (g_ascii_strcasecmp (cpu->cur_governor, "userspace") != 0)
-	{
-		xfce_warn ("You could only change CPU frequency, if you use the \"userspace\" governor");
-		g_free (new_freq);
-		return;
-	}
-
-	if (xfce_confirm (_("Are you sure to change the frequency !"), GTK_STOCK_YES, NULL) == FALSE)
-	{
-		g_free (new_freq);
-		return;
-	}
-
-	if (cpufreq_cpu_set_freq (cpu_number, freq) == FALSE)
-		xfce_err (_("It was not possible to change the frequency"));
-
-	g_free (new_freq);
-}
-
-static void
-governor_combo_changed (GtkWidget *combo, guint cpu_number)
-{
-	gchar *new_governor;
-
-	new_governor = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
-
-	if (xfce_confirm (_("Are you sure to change the governor !"), GTK_STOCK_YES, NULL) == FALSE)
-	{
-		g_free (new_governor);
-		return;
-	}
-
-	if (cpufreq_cpu_set_governor (cpu_number, new_governor) == FALSE)
-		xfce_err (_("It was not possible to change the governor"));
-
-	g_free (new_governor);
-}
-
-static void
 cpufreq_overview_add (CpuInfo *cpu, guint cpu_number, GtkWidget *dialog_hbox)
 {
 	gint	  i, j;
@@ -107,7 +58,11 @@
 	label = gtk_label_new (_("Scaling driver:"));
 	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
-	text = g_strdup_printf ("<b>%s</b>", cpu->scaling_driver);
+	if (cpu->scaling_driver != NULL)
+		text = g_strdup_printf ("<b>%s</b>", cpu->scaling_driver);
+	else
+		text = g_strdup_printf (_("No scaling driver available"));
+
 	label = gtk_label_new (text);
 	gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
 	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
@@ -120,52 +75,98 @@
 	label = gtk_label_new (_("Available frequencies:"));
 	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
-	combo = gtk_combo_box_new_text ();
-	gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
-	list = g_list_first (cpu->available_freqs);
-	j = 0;
-	while (list)
+	if (cpu->available_freqs != NULL) /* Linux 2.6 with scaling support */
 	{
-		text = cpufreq_get_human_readable_freq (GPOINTER_TO_INT (list->data));
-		if (GPOINTER_TO_INT (list->data) == cpu->cur_freq)
-			i = j;
-		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), text);
+		combo = gtk_combo_box_new_text ();
+		gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
+		list = g_list_first (cpu->available_freqs);
+		j = 0;
+		while (list)
+		{
+			text = cpufreq_get_human_readable_freq (GPOINTER_TO_INT (list->data));
+			if (GPOINTER_TO_INT (list->data) == cpu->cur_freq)
+				i = j;
+			gtk_combo_box_append_text (GTK_COMBO_BOX (combo), text);
+			g_free (text);
+			list = g_list_next (list);
+			j++;
+		}
+		gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
+	}
+	else if (cpu->cur_freq && cpu->min_freq && cpu->max_freq) /* Linux 2.4 with scaling support */
+	{
+		combo = gtk_combo_box_new_text ();
+		gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
+
+                text = cpufreq_get_human_readable_freq (cpu->cur_freq);
+                gtk_combo_box_append_text (GTK_COMBO_BOX (combo), text);
+                g_free (text);
+		text = cpufreq_get_human_readable_freq (cpu->max_freq);
+                gtk_combo_box_append_text (GTK_COMBO_BOX (combo), text);
+                g_free (text);
+		text = cpufreq_get_human_readable_freq (cpu->min_freq);
+                gtk_combo_box_append_text (GTK_COMBO_BOX (combo), text);
+                g_free (text);
+
+                gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+	}
+	else /* If there is no scaling support only show the cpu freq */
+	{
+		text = cpufreq_get_human_readable_freq (cpu->cur_freq);
+		text = g_strdup_printf ("<b>%s</b> (current frequency)", text);
+		label = gtk_label_new (text);
+		gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+		gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
 		g_free (text);
-		list = g_list_next (list);
-		j++;
 	}
-	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
-	g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (freq_combo_changed), cpu_number);
 
+#ifdef __linux__
 	/* display list of available governors */
-	hbox = gtk_hbox_new (FALSE, BORDER);
-	gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
+	if (cpu->available_governors != NULL) /* Linux 2.6 and cpu scaling support */
+	{
+		hbox = gtk_hbox_new (FALSE, BORDER);
+		gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
 
-	label = gtk_label_new (_("Available governors:"));\
-	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+		label = gtk_label_new (_("Available governors:"));\
+		gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
-	combo = gtk_combo_box_new_text ();
-	gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
-	list = g_list_first (cpu->available_governors);
-	j = 0;
-	while (list)
+		combo = gtk_combo_box_new_text ();
+		gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
+		list = g_list_first (cpu->available_governors);
+		j = 0;
+		while (list)
+		{
+			gtk_combo_box_append_text (GTK_COMBO_BOX (combo), list->data);
+			if (g_ascii_strcasecmp (list->data, cpu->cur_governor) == 0)
+				i = j;
+			list = g_list_next (list);
+			j++;
+		}
+
+		gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
+	}
+	else if (cpu->cur_governor != NULL) /* Linux 2.4 and cpu scaling support */
 	{
-		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), list->data);
-		if (g_ascii_strcasecmp (list->data, cpu->cur_governor) == 0)
-			i = j;
-		list = g_list_next (list);
-		j++;
+		hbox = gtk_hbox_new (FALSE, BORDER);
+		gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
+
+		label = gtk_label_new (_("Current governor:"));
+		gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+		text = g_strdup_printf ("<b>%s</b>", cpu->cur_governor);
+		label = gtk_label_new (text);
+		gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+		gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+		g_free (text);
 	}
-
-	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
-	g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (governor_combo_changed), cpu_number);
+	/* If there is no scaling support, do not display governor combo */
+#endif /* __linux__ */
 }
 
 static void
-cpufreq_overview_response (GtkWidget *dialog, gint response, CpuFreqPlugin *cpuFreq)
+cpufreq_overview_response (GtkWidget *dialog, gint response, gpointer data)
 {
 	g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", NULL);
-
 	gtk_widget_destroy (dialog);
 }
 
@@ -216,7 +217,7 @@
 		}
 	}
 
-	g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (cpufreq_overview_response), cpuFreq);
+	g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (cpufreq_overview_response), NULL);
 
 	gtk_widget_show_all (dialog);
 

Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.c
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.c	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.c	2006-10-23 08:45:16 UTC (rev 2123)
@@ -27,9 +27,10 @@
 
 #include <libxfce4util/libxfce4util.h>
 #include <libxfcegui4/libxfcegui4.h>
-
 #include "xfce4-cpufreq-plugin.h"
+#ifdef __linux__
 #include "xfce4-cpufreq-linux.h"
+#endif /* __linux__ */
 #include "xfce4-cpufreq-configure.h"
 #include "xfce4-cpufreq-overview.h"
 #include "xfce4-cpufreq-utils.h"
@@ -45,11 +46,13 @@
 	
 	freq = cpufreq_get_human_readable_freq (cpu->cur_freq);
 	label = g_strconcat (small ? "<span size=\"xx-small\">" : "<span size=\"x-small\">",
-
+		
 		cpuFreq->options->show_label_freq ? freq : "",
 		
+		cpu->cur_governor != NULL &&
 		cpuFreq->options->show_label_freq && cpuFreq->options->show_label_governor ? "\n" : "",
-
+	
+		cpu->cur_governor != NULL &&
 		cpuFreq->options->show_label_governor ? cpu->cur_governor : "",
 		
 		"</span>",
@@ -74,9 +77,12 @@
 		tooltip_msg = g_strconcat (!cpuFreq->options->show_label_freq ? _("Frequency: ") : "",
 			!cpuFreq->options->show_label_freq ? freq : "",
 			
+			cpu->cur_governor != NULL && 
 			!cpuFreq->options->show_label_freq && !cpuFreq->options->show_label_governor ? "\n" : "",
 			
+			cpu->cur_governor != NULL &&
 			!cpuFreq->options->show_label_governor ? _("Governor: ") : "",
+			cpu->cur_governor != NULL &&
 			!cpuFreq->options->show_label_governor ? cpu->cur_governor : "",
 			NULL);
 
@@ -106,7 +112,10 @@
 cpufreq_restart_timeout (void)
 {
 	g_source_remove (cpuFreq->timeoutHandle);
-	cpuFreq->timeoutHandle = g_timeout_add (100, (GSourceFunc)cpufreq_update_cpus, NULL);
+	cpuFreq->timeoutHandle = g_timeout_add (
+			cpuFreq->options->timeout,
+			(GSourceFunc)cpufreq_update_cpus,
+			NULL);
 }
 
 gboolean
@@ -122,7 +131,7 @@
 	if (cpuFreq->ebox)
 		gtk_widget_destroy (cpuFreq->ebox);
 	cpuFreq->ebox = gtk_event_box_new ();
-	
+
 	cpuFreq->frame = gtk_frame_new (NULL);
 	gtk_frame_set_shadow_type (GTK_FRAME (cpuFreq->frame),cpuFreq->options->show_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE);
 	gtk_container_add (GTK_CONTAINER (cpuFreq->ebox), cpuFreq->frame);
@@ -211,7 +220,8 @@
 {
 	gint i;
 
-	g_source_remove (cpuFreq->timeoutHandle);
+	if (cpuFreq->timeoutHandle)
+		g_source_remove (cpuFreq->timeoutHandle);
 
 	for (i = 0; i < cpuFreq->cpus->len; i++)
 	{
@@ -225,8 +235,7 @@
 
 	gtk_tooltips_set_tip (cpuFreq->tooltip, cpuFreq->ebox, NULL, NULL);
 	g_object_unref (cpuFreq->tooltip);
-
-	gksu_context_free (cpuFreq->gksu_ctx);
+	g_ptr_array_free (cpuFreq->cpus, TRUE);
 	cpuFreq->plugin = NULL;
 	g_free (cpuFreq);
 }
@@ -257,26 +266,26 @@
 	cpuFreq 	  = g_new0 (CpuFreqPlugin, 1);
 	cpuFreq->options  = g_new0 (CpuFreqPluginOptions, 1);
 	cpuFreq->plugin   = plugin;
-
-	cpuFreq->gksu_ctx = gksu_context_new ();
-
 	cpuFreq->tooltip = gtk_tooltips_new ();
 	g_object_ref (cpuFreq->tooltip);
-
 	cpuFreq->cpus    = g_ptr_array_new ();
 
 	cpufreq_read_config ();
 
+#ifdef __linux__
 	if (cpufreq_linux_init () == FALSE)
-		xfce_err (_("Could not initialize linux backend !"));
+		xfce_err (_("Your system is not configured correctly to support cpu frequency scaling !"));
 
 	if (cpufreq_widgets () == FALSE)
 		xfce_err (_("Could not create widgets !"));
 
 	cpuFreq->timeoutHandle = g_timeout_add (
-			100,
+			cpuFreq->options->timeout,
 			(GSourceFunc) cpufreq_update_cpus,
 			NULL);
+#else
+	xfce_err (_("Your system is not supported yet !"));
+#endif /* __linux__ */
 
 	g_signal_connect (plugin, "free-data", G_CALLBACK (cpufreq_free),
 			  NULL);

Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.h
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.h	2006-10-22 18:52:46 UTC (rev 2122)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.h	2006-10-23 08:45:16 UTC (rev 2123)
@@ -21,7 +21,6 @@
 #define XFCE4_CPUFREQ_H
 
 #include <gtk/gtk.h>
-#include <gksu.h>
 #include <libxfce4panel/xfce-panel-plugin.h>
 
 typedef struct
@@ -58,7 +57,6 @@
 	GtkTooltips *tooltip;
 
 	CpuFreqPluginOptions  *options;
-	GksuContext	      *gksu_ctx;
 	gint 		      timeoutHandle;
 } CpuFreqPlugin;
 




More information about the Goodies-commits mailing list