[Xfce4-commits] <xfce4-cpugraph-plugin:master> Reorganize code

Florian noreply at xfce.org
Sat Apr 17 16:16:35 CEST 2010


Updating branch refs/heads/master
         to 85a30ad7d54438ada913826f5cd6bde6f721420a (commit)
       from 8432c0feedb6990942b200fa93f235666ec55882 (commit)

commit 85a30ad7d54438ada913826f5cd6bde6f721420a
Author: Florian <frivoal at gmail.com>
Date:   Tue Mar 9 10:20:45 2010 +0900

    Reorganize code
    
    Change a little which files contain what part of the code, and improve
    consistency in naming.

 panel-plugin/Makefile.am  |   16 ++--
 panel-plugin/actions.c    |   86 ----------------
 panel-plugin/actions.h    |   16 ---
 panel-plugin/cpu.c        |  244 +++++++++++++++++++++++----------------------
 panel-plugin/cpu.h        |   57 ++++-------
 panel-plugin/mode.c       |   38 ++++----
 panel-plugin/mode.h       |   14 ++--
 panel-plugin/os.c         |   65 +++++++++---
 panel-plugin/os.h         |   47 ++--------
 panel-plugin/properties.c |  205 ++++++++++++++++++++++++++++----------
 panel-plugin/properties.h |    8 ++
 panel-plugin/settings.c   |   20 ++--
 panel-plugin/settings.h   |    9 ++
 13 files changed, 414 insertions(+), 411 deletions(-)

diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 8568206..b3f5484 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -8,17 +8,17 @@ xfce4_cpugraph_plugin_CFLAGS =					\
 xfce4_cpugraph_plugin_LDADD =					\
 	@LIBXFCE4PANEL_LIBS@
 
-xfce4_cpugraph_plugin_SOURCES =					\
-	mode.c						\
-	mode.h						\
-	cpu.c							\
-	cpu.h							\
-	os.c							\
+xfce4_cpugraph_plugin_SOURCES =                                 \
+	mode.c                                                  \
+	mode.h                                                  \
+	cpu.c                                                   \
+	cpu.h                                                   \
+	os.c                                                    \
 	os.h                                                    \
 	properties.c                                            \
+	properties.h                                            \
 	settings.c                                              \
-	actions.c                                               \
-	actions.h
+	settings.h
 
 # .desktop file
 #
diff --git a/panel-plugin/actions.c b/panel-plugin/actions.c
deleted file mode 100644
index ed72b96..0000000
--- a/panel-plugin/actions.c
+++ /dev/null
@@ -1,86 +0,0 @@
-#include <actions.h>
-
-void AssociateCommandChange( GtkEntry *entry, CPUGraph * base )
-{
-	set_command( base, gtk_entry_get_text( entry ) );
-}
-
-void ChangeColor( GtkColorButton * button, CPUGraph * base, int number)
-{
-	GdkColor color;
-	gtk_color_button_get_color( button, &color );
-	set_color( base, number, color );
-}
-
-void ChangeColor1( GtkColorButton * button, CPUGraph * base )
-{
-	ChangeColor( button, base, 1);
-}
-
-void ChangeColor2( GtkColorButton * button, CPUGraph * base )
-{
-	ChangeColor( button, base, 2);
-}
-
-void ChangeColor3( GtkColorButton * button, CPUGraph * base )
-{
-	ChangeColor( button, base, 3);
-}
-
-void ChangeColor0( GtkColorButton * button, CPUGraph * base )
-{
-	ChangeColor( button, base, 0);
-}
-
-void select_active_colors( CPUGraph * base )
-{
-	if( base->m_ColorMode != 0 || base->m_Mode == 1 || base->m_Mode == 3 )
-		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[2] ), TRUE );
-	else
-		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[2] ), FALSE );
-
-	if( base->m_ColorMode != 0 && base->m_Mode == 1 )
-		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[3] ), TRUE );
-	else
-		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[3] ), FALSE );
-}
-
-void ModeChange( GtkOptionMenu * om, CPUGraph * base )
-{
-	set_mode( base, gtk_option_menu_get_history( om ) );
-	select_active_colors( base );
-}
-
-void ColorModeChange( GtkOptionMenu * om, CPUGraph * base )
-{
-	set_color_mode( base, gtk_option_menu_get_history( om ) );
-	select_active_colors( base );
-}
-
-void DialogResponse( GtkWidget *dlg, int response, CPUGraph *base )
-{
-	gtk_widget_destroy( dlg );
-	xfce_panel_plugin_unblock_menu( base->plugin );
-	WriteSettings( base->plugin, base );
-}
-
-void FrameChange( GtkToggleButton * button, CPUGraph * base )
-{
-	set_frame( base, gtk_toggle_button_get_active( button ) );
-}
-
-void SizeChange( GtkSpinButton * sb, CPUGraph *base)
-{
-	set_size( base, gtk_spin_button_get_value_as_int( sb ) );
-}
-
-void TimeScaleChange( GtkToggleButton * button, CPUGraph * base )
-{
-	set_nonlinear_time( base, gtk_toggle_button_get_active( button ) );
-}
-
-void UpdateChange( GtkOptionMenu * om, CPUGraph * base )
-{
-	set_update_rate( base, gtk_option_menu_get_history( om ) );
-}
-
diff --git a/panel-plugin/actions.h b/panel-plugin/actions.h
deleted file mode 100644
index 1e731ac..0000000
--- a/panel-plugin/actions.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <cpu.h>
-
-void AssociateCommandChange( GtkEntry *entry, CPUGraph *base );
-void ChangeColor0( GtkColorButton *button, CPUGraph *base );
-void ChangeColor1( GtkColorButton * button, CPUGraph * base );
-void ChangeColor2( GtkColorButton *button, CPUGraph *base );
-void ChangeColor3( GtkColorButton *button, CPUGraph *base );
-void select_active_colors( CPUGraph * base );
-void ColorModeChange( GtkOptionMenu *om, CPUGraph *base );
-void DialogResponse( GtkWidget *dlg, int response, CPUGraph *base );
-void ApplyChanges( CPUGraph *base );
-void FrameChange( GtkToggleButton *button, CPUGraph *base );
-void ModeChange( GtkOptionMenu *om, CPUGraph *base );
-void SizeChange( GtkSpinButton *sb, CPUGraph *base );
-void TimeScaleChange( GtkToggleButton *button, CPUGraph *base );
-void UpdateChange( GtkOptionMenu *om, CPUGraph *base );
diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c
index bdb8027..3c951c4 100644
--- a/panel-plugin/cpu.c
+++ b/panel-plugin/cpu.c
@@ -1,5 +1,20 @@
 #include "cpu.h"
+#include "settings.h"
 #include "mode.h"
+#include "properties.h"
+
+static void cpugraph_construct( XfcePanelPlugin *plugin );
+static CPUGraph *create_gui( XfcePanelPlugin *plugin );
+static void shutdown( XfcePanelPlugin *plugin, CPUGraph *base );
+static gboolean size_cb( XfcePanelPlugin *plugin, int size, CPUGraph *base );
+static void orientation_cb( XfcePanelPlugin *plugin, GtkOrientation orientation, CPUGraph *base );
+static gboolean update_cb( CPUGraph *base );
+static void update_tooltip( CPUGraph *base );
+static void draw_area_cb( GtkWidget *da, GdkEventExpose *event, gpointer data );
+static void draw_graph( CPUGraph *base );
+static gboolean command_cb( GtkWidget *w, GdkEventButton *event, CPUGraph *base );
+
+XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL( cpugraph_construct );
 
 static void cpugraph_construct( XfcePanelPlugin *plugin )
 {
@@ -7,49 +22,18 @@ static void cpugraph_construct( XfcePanelPlugin *plugin )
 
 	xfce_textdomain( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8" );
 
-	base = CreateControl( plugin );
-
-	ReadSettings( plugin, base );
-
-	g_signal_connect( plugin, "free-data", G_CALLBACK( Kill ), base );
-
-	g_signal_connect( plugin, "save", G_CALLBACK( WriteSettings ), base );
-
+	base = create_gui( plugin );
+	read_settings( plugin, base );
 	xfce_panel_plugin_menu_show_configure( plugin );
 
-	g_signal_connect( plugin, "configure-plugin", G_CALLBACK( CreateOptions ), base );
-
-	g_signal_connect( plugin, "size-changed", G_CALLBACK( SetSize ), base );
-
-	g_signal_connect( plugin, "orientation-changed", G_CALLBACK( SetOrientation ), base );
-}
-
-/* register the plugin */
-XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL( cpugraph_construct );
-
-void Kill( XfcePanelPlugin * plugin, CPUGraph * base )
-{
-	gint i;
-	cpuData_free();
-	base->m_CpuData = NULL;
-
-	for(i=0; i<base->nrCores-1; i++)
-		gtk_widget_destroy(base->m_pBar[i]);
-	g_free( base->m_pBar );
-
-	gtk_widget_destroy(base->m_Box);
-
-	if( base->m_TimeoutID )
-		g_source_remove( base->m_TimeoutID );
-
-	g_free( base->m_History );
-
-	g_free( base->m_AssociateCommand );
-	g_free( base );
+	g_signal_connect( plugin, "free-data", G_CALLBACK( shutdown ), base );
+	g_signal_connect( plugin, "save", G_CALLBACK( write_settings ), base );
+	g_signal_connect( plugin, "configure-plugin", G_CALLBACK( create_options ), base );
+	g_signal_connect( plugin, "size-changed", G_CALLBACK( size_cb ), base );
+	g_signal_connect( plugin, "orientation-changed", G_CALLBACK( orientation_cb ), base );
 }
 
-
-CPUGraph * CreateControl( XfcePanelPlugin * plugin )
+static CPUGraph * create_gui( XfcePanelPlugin * plugin )
 {
 	gint i;
 	GtkWidget *frame, *ebox;
@@ -57,7 +41,7 @@ CPUGraph * CreateControl( XfcePanelPlugin * plugin )
 	CPUGraph *base = g_new0( CPUGraph, 1 );
 
 	orientation = xfce_panel_plugin_get_orientation(plugin);
-	if((base->nrCores = cpuData_init() - 1) < 0)
+	if((base->nr_cores = init_cpu_data() - 1) < 0)
 		fprintf(stderr,"Cannot init cpu data !\n");
 
 	base->plugin = plugin;
@@ -65,14 +49,14 @@ CPUGraph * CreateControl( XfcePanelPlugin * plugin )
 	ebox = gtk_event_box_new();
 	gtk_container_add( GTK_CONTAINER( plugin ), ebox );
 	xfce_panel_plugin_add_action_widget( plugin, ebox );
-	g_signal_connect( ebox, "button-press-event", G_CALLBACK( LaunchCommand ), base );
+	g_signal_connect( ebox, "button-press-event", G_CALLBACK( command_cb ), base );
 
 	base->m_Box = xfce_hvbox_new(orientation, FALSE, 0);
 	gtk_container_add(GTK_CONTAINER(ebox), base->m_Box);
 
-	base->m_pBar = (GtkWidget **) g_malloc( sizeof( GtkWidget * ) * base->nrCores );
+	base->m_pBar = (GtkWidget **) g_malloc( sizeof( GtkWidget * ) * base->nr_cores );
 
-	for(i=0; i<base->nrCores; i++) {
+	for(i=0; i<base->nr_cores; i++) {
 		base->m_pBar[i] = GTK_WIDGET(gtk_progress_bar_new());
 		gtk_box_pack_start( GTK_BOX(base->m_Box), base->m_pBar[i], FALSE, FALSE, 0);
 	}
@@ -82,43 +66,37 @@ CPUGraph * CreateControl( XfcePanelPlugin * plugin )
 
 	base->m_DrawArea = gtk_drawing_area_new();
 	gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( base->m_DrawArea ) );
-	g_signal_connect_after( base->m_DrawArea, "expose-event", G_CALLBACK( DrawAreaExposeEvent ), base );
+	g_signal_connect_after( base->m_DrawArea, "expose-event", G_CALLBACK( draw_area_cb ), base );
 
-	SetOrientation(plugin, orientation, base);
+	orientation_cb(plugin, orientation, base);
 
 	gtk_widget_show_all(ebox);
 
 	return base;
 }
 
-void SetOrientation( XfcePanelPlugin * plugin, GtkOrientation orientation, CPUGraph *base )
+static void shutdown( XfcePanelPlugin * plugin, CPUGraph * base )
 {
-	GtkProgressBarOrientation barOrientation;
-	gpointer p_pBar[base->nrCores];
-	gint i; 
+	gint i;
+	free_cpu_data();
+	base->cpu_data = NULL;
 
-	xfce_hvbox_set_orientation( XFCE_HVBOX( base->m_Box ), orientation );
+	for(i=0; i<base->nr_cores-1; i++)
+		gtk_widget_destroy(base->m_pBar[i]);
+	g_free( base->m_pBar );
 
-	if( orientation == GTK_ORIENTATION_HORIZONTAL )
-		barOrientation = GTK_PROGRESS_BOTTOM_TO_TOP;
-	else
-		barOrientation = GTK_PROGRESS_LEFT_TO_RIGHT;
+	gtk_widget_destroy(base->m_Box);
 
-	for( i=0; i<base->nrCores; i++ )
-	{
-		gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR( base->m_pBar[i] ), barOrientation );	
-	}
+	if( base->timeout_id )
+		g_source_remove( base->timeout_id );
 
-}
+	g_free( base->history );
 
-void UpdateTooltip( CPUGraph * base )
-{
-	gchar tooltip[32];
-	int pos = g_snprintf( tooltip, 32, "Usage: %d%%", (int)base->m_CpuData[0].load*100/CPU_SCALE );
-	gtk_widget_set_tooltip_text( base->m_FrameWidget, tooltip );
+	g_free( base->command );
+	g_free( base );
 }
 
-gboolean SetSize( XfcePanelPlugin *plugin, int size, CPUGraph *base )
+static gboolean size_cb( XfcePanelPlugin *plugin, int size, CPUGraph *base )
 {
 	gint i;
 	gint frame_h, frame_v, bar_h, bar_v, history;
@@ -144,53 +122,87 @@ gboolean SetSize( XfcePanelPlugin *plugin, int size, CPUGraph *base )
 
 	gtk_widget_set_size_request( GTK_WIDGET( base->m_FrameWidget ), frame_h, frame_v );
 
-	for( i=0; i<base->nrCores; i++ )
+	for( i=0; i<base->nr_cores; i++ )
 		gtk_widget_set_size_request( GTK_WIDGET(base->m_pBar[i]), bar_h, bar_v );
 
-	base->m_History = (long *) g_realloc( base->m_History, history * sizeof( long ) );
-	if( history > base->m_Values )
-		memset( base->m_History + base->m_Values, 0, (history - base->m_Values) * sizeof( long ) );
-	base->m_Values = history;
+	base->history = (long *) g_realloc( base->history, history * sizeof( long ) );
+	if( history > base->history_size )
+		memset( base->history + base->history_size, 0, (history - base->history_size) * sizeof( long ) );
+	base->history_size = history;
 
 	return TRUE;
 }
 
-gboolean UpdateCPU( CPUGraph * base )
+static void orientation_cb( XfcePanelPlugin * plugin, GtkOrientation orientation, CPUGraph *base )
+{
+	GtkProgressBarOrientation barOrientation;
+	gpointer p_pBar[base->nr_cores];
+	gint i; 
+
+	xfce_hvbox_set_orientation( XFCE_HVBOX( base->m_Box ), orientation );
+
+	if( orientation == GTK_ORIENTATION_HORIZONTAL )
+		barOrientation = GTK_PROGRESS_BOTTOM_TO_TOP;
+	else
+		barOrientation = GTK_PROGRESS_LEFT_TO_RIGHT;
+
+	for( i=0; i<base->nr_cores; i++ )
+	{
+		gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR( base->m_pBar[i] ), barOrientation );	
+	}
+
+}
+
+static gboolean update_cb( CPUGraph * base )
 {
 	gint i;
-	base->m_CpuData = cpuData_read();
-	for( i=0; i<base->nrCores; i++ )
+	base->cpu_data = read_cpu_data();
+	for( i=0; i<base->nr_cores; i++ )
 	{
-		gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(base->m_pBar[i]), (gdouble)base->m_CpuData[i+1].load / CPU_SCALE );
+		gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(base->m_pBar[i]), (gdouble)base->cpu_data[i+1].load / CPU_SCALE );
 	}
 
-	if( base->m_TimeScale )
+	if( base->non_linear )
 	{
-		int i = base->m_Values - 1;
-		int j = i + base->m_Values;
+		int i = base->history_size - 1;
+		int j = i + base->history_size;
 		while( i > 0 )
 		{
 			int a, b;
 
-			a = base->m_History[i], b = base->m_History[i-1];
+			a = base->history[i], b = base->history[i-1];
 			if( a < b ) a++;
 			int factor = (i*2);
-			base->m_History[i--] = (a * (factor-1) + b) / factor;
+			base->history[i--] = (a * (factor-1) + b) / factor;
 		}
 	} else {
-		memmove( base->m_History + 1 , base->m_History , (base->m_Values - 1) * sizeof( long ) );
+		memmove( base->history + 1 , base->history , (base->history_size - 1) * sizeof( long ) );
 	}
-	base->m_History[0] = (long)base->m_CpuData[0].load;
+	base->history[0] = (long)base->cpu_data[0].load;
 
 	/* Tooltip */
-	UpdateTooltip( base );
+	update_tooltip( base );
 
 	/* Draw the graph. */
 	gtk_widget_queue_draw( base->m_DrawArea );
 	return TRUE;
 }
 
-void DrawGraph( CPUGraph * base )
+static void update_tooltip( CPUGraph * base )
+{
+	gchar tooltip[32];
+	int pos = g_snprintf( tooltip, 32, "Usage: %d%%", (int)base->cpu_data[0].load*100/CPU_SCALE );
+	gtk_widget_set_tooltip_text( base->m_FrameWidget, tooltip );
+}
+
+static void draw_area_cb( GtkWidget * da, GdkEventExpose * event, gpointer data )
+{
+	CPUGraph *base = (CPUGraph *) data;
+
+	draw_graph( base );
+}
+
+static void draw_graph( CPUGraph * base )
 {
 	GtkWidget *da = base->m_DrawArea;
 	int w, h;
@@ -198,41 +210,33 @@ void DrawGraph( CPUGraph * base )
 	w = da->allocation.width;
 	h = da->allocation.height;
 
-	if( base->m_Mode == 0 )
-	{
-		drawGraphModeNormal( base, da, w, h );
-	}
-	else if( base->m_Mode == 1 )
+	switch( base->mode )
 	{
-		drawGraphModeLED( base, da, w, h );
-	}
-	else if( base->m_Mode == 2 )
-	{
-		drawGraphModeNoHistory( base, da, w, h );
-	}
-	else if( base->m_Mode == 3 )
-	{
-		drawGraphGrid(base, da, w, h);
+		case 0:
+			draw_graph_normal( base, da, w, h );
+			break;
+		case 1:
+			draw_graph_LED( base, da, w, h );
+			break;
+		case 2:
+			draw_graph_no_history( base, da, w, h );
+			break;
+		case 3:
+			draw_graph_grid(base, da, w, h);
+			break;
 	}
 }
 
-void DrawAreaExposeEvent( GtkWidget * da, GdkEventExpose * event, gpointer data )
-{
-	CPUGraph *base = (CPUGraph *) data;
-
-	DrawGraph( base );
-}
-
-gboolean LaunchCommand( GtkWidget*w,GdkEventButton *event, CPUGraph *base )
+static gboolean command_cb( GtkWidget *w,GdkEventButton *event, CPUGraph *base )
 {
 	if( event->button == 1 )
 	{
 		GString *cmd;
-		if( strlen(base->m_AssociateCommand) == 0 )
+		if( strlen(base->command) == 0 )
 		{
 			return FALSE;
 		}
-		cmd = g_string_new( base->m_AssociateCommand );
+		cmd = g_string_new( base->command );
 		xfce_exec( cmd->str, FALSE, FALSE, NULL );
 		g_string_free( cmd, TRUE );
 	}
@@ -241,30 +245,30 @@ gboolean LaunchCommand( GtkWidget*w,GdkEventButton *event, CPUGraph *base )
 
 void set_command( CPUGraph *base, const gchar *command )
 {
-	g_free (base->m_AssociateCommand );
-	base->m_AssociateCommand = g_strdup( command );
+	g_free( base->command );
+	base->command = g_strdup( command );
 }
 
 void set_frame( CPUGraph *base, gboolean frame )
 {
-	base->m_Frame = frame;
-	gtk_frame_set_shadow_type( GTK_FRAME( base->m_FrameWidget ), base->m_Frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE );
+	base->frame = frame;
+	gtk_frame_set_shadow_type( GTK_FRAME( base->m_FrameWidget ), base->frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE );
 }
 
 void set_nonlinear_time( CPUGraph *base, gboolean nonlinear )
 {
-	base->m_TimeScale = nonlinear;
+	base->non_linear = nonlinear;
 }
 
 void set_update_rate( CPUGraph *base, int rate )
 {
 	int update;
 
-	base->m_UpdateInterval = rate;
+	base->update_interval = rate;
 
-	if( base->m_TimeoutID )
-		g_source_remove( base->m_TimeoutID );
-	switch( base->m_UpdateInterval )
+	if( base->timeout_id )
+		g_source_remove( base->timeout_id );
+	switch( base->update_interval )
 	{
 		case 0:
 			update = 250;
@@ -278,23 +282,23 @@ void set_update_rate( CPUGraph *base, int rate )
 		default:
 			update = 1000;
 	}
-	base->m_TimeoutID = g_timeout_add( update, (GtkFunction) UpdateCPU, base );
+	base->timeout_id = g_timeout_add( update, (GtkFunction) update_cb, base );
 }
 
 void set_size( CPUGraph *base, int size )
 {
 	base->size = size;
-	SetSize( base->plugin, xfce_panel_plugin_get_size( base->plugin ), base );
+	size_cb( base->plugin, xfce_panel_plugin_get_size( base->plugin ), base );
 }
 
 void set_color_mode( CPUGraph *base, int color_mode )
 {
-	base->m_ColorMode = color_mode;
+	base->color_mode = color_mode;
 }
 
 void set_mode( CPUGraph *base, int mode )
 {
-	base->m_Mode = mode;
+	base->mode = mode;
 }
 
 void set_color( CPUGraph *base, int number, GdkColor color )
diff --git a/panel-plugin/cpu.h b/panel-plugin/cpu.h
index 6a8a2f3..7edf78d 100644
--- a/panel-plugin/cpu.h
+++ b/panel-plugin/cpu.h
@@ -1,8 +1,8 @@
-#ifndef __XFCE_CPU_H__
-#define __XFCE_CPU_H__
+#ifndef _XFCE_CPU_H_
+#define _XFCE_CPU_H_
 
 #if HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <gtk/gtk.h>
@@ -16,18 +16,16 @@
 #include <libxfce4panel/xfce-panel-plugin.h>
 #include <libxfce4panel/xfce-hvbox.h>
 
-#include "os.h"
 
-#define DEFAULT_COMMAND "exo-open --launch TerminalEmulator top"
 
-#define BORDER  8
+#include "os.h"
 
-#define MAX_WIDTH 64
+#define BORDER  8
 
 typedef struct
 {
+	/* GUI components */
 	XfcePanelPlugin *plugin;
-
 	GtkWidget *m_FrameWidget;
 	GtkWidget *m_DrawArea;
 	GtkWidget *m_OptionsDialog;
@@ -35,39 +33,26 @@ typedef struct
 	GtkWidget **m_pBar;
 	GtkWidget *color_buttons[4];
 
-	int m_UpdateInterval; // Number of ms between updates.
-	gboolean m_TimeScale; // Wether to use non-linear time scale.
+	/* Settings */
+	int update_interval; /* Number of ms between updates. */
+	gboolean non_linear;
 	int size;
-	int m_Mode; // Eventual mode of the plugin.
-	int m_ColorMode;
-	gboolean m_Frame;
-	gchar  *m_AssociateCommand;
-	guint nrCores; // Number of cores (not including total cpu)
-
+	int mode;
+	int color_mode;
+	gboolean frame;
+	gchar  *command;
 	GdkColor colors[4];
 
-	guint m_TimeoutID; // Timeout ID for the tooltip;
-	long *m_History;
-	int m_Values;
-	int m_Orientation;
-	CpuData *m_CpuData;
+	/* Runtime data */
+	guint nr_cores;
+	guint timeout_id;
+	long *history;
+	gssize history_size;
+	int orientation;
+	CpuData *cpu_data;
 
 } CPUGraph;
 
-CPUGraph *CreateControl( XfcePanelPlugin *plugin );
-void Kill( XfcePanelPlugin *plugin, CPUGraph *base );
-void ReadSettings( XfcePanelPlugin *plugin, CPUGraph *base );
-void WriteSettings( XfcePanelPlugin *plugin, CPUGraph *base );
-gboolean SetSize( XfcePanelPlugin *plugin, int size, CPUGraph *base );
-gboolean UpdateCPU( CPUGraph *base );
-void UpdateTooltip( CPUGraph *base );
-void DrawGraph( CPUGraph *base );
-void DrawAreaExposeEvent( GtkWidget *da, GdkEventExpose *event, gpointer data );
-void CreateOptions( XfcePanelPlugin *plugin, CPUGraph *base );
-void SetOrientation( XfcePanelPlugin *plugin, GtkOrientation orientation, CPUGraph *base );
-
-gboolean LaunchCommand( GtkWidget *w, GdkEventButton *event, CPUGraph *base );
-
 void set_command( CPUGraph *base, const gchar *command );
 void set_frame( CPUGraph *base, gboolean frame );
 void set_nonlinear_time( CPUGraph *base, gboolean nonlinear );
@@ -76,4 +61,4 @@ void set_size( CPUGraph *base, int width );
 void set_color_mode( CPUGraph *base, int color_mode );
 void set_mode( CPUGraph *base, int mode );
 void set_color( CPUGraph *base, int number, GdkColor color );
-#endif
+#endif /* !_XFCE_CPU_H_ */
diff --git a/panel-plugin/mode.c b/panel-plugin/mode.c
index 3e1c6cf..67edc2a 100644
--- a/panel-plugin/mode.c
+++ b/panel-plugin/mode.c
@@ -28,7 +28,7 @@ static guint16 _lerp( double t, guint16 a, guint16 b )
 	return (guint16) (a + t * (b - a));
 }
 
-static void MixAndApplyColors( double ratio, GdkColor *color1, GdkColor *color2, GdkGC *target )
+static void mix_colors( double ratio, GdkColor *color1, GdkColor *color2, GdkGC *target )
 {
 	GdkColor color;
 	color.red = _lerp (ratio, color1->red, color2->red);
@@ -37,7 +37,7 @@ static void MixAndApplyColors( double ratio, GdkColor *color1, GdkColor *color2,
 	gdk_gc_set_rgb_fg_color( target, &color );
 }
 
-void drawGraphModeNormal( CPUGraph *base, GtkWidget *da, int w, int h )
+void draw_graph_normal( CPUGraph *base, GtkWidget *da, int w, int h )
 {
 	int x, y;
 	long usage;
@@ -45,16 +45,16 @@ void drawGraphModeNormal( CPUGraph *base, GtkWidget *da, int w, int h )
 	int tmp;
 	GdkGC *fg1 = gdk_gc_new( da->window );
 
-	if( base->m_ColorMode == 0 )
+	if( base->color_mode == 0 )
 		gdk_gc_set_rgb_fg_color( fg1, &base->colors[1] );
 
 	for( x = 0; x < w; x++ )
 	{
-		usage = h * base->m_History[w - 1- x] / CPU_SCALE;
+		usage = h * base->history[w - 1- x] / CPU_SCALE;
 
 		if( usage == 0 ) continue;
 
-		if( base->m_ColorMode == 0 )
+		if( base->color_mode == 0 )
 		{
 			gdk_draw_line( da->window, fg1, x, h-usage, x, h-1 );
 		}
@@ -63,10 +63,10 @@ void drawGraphModeNormal( CPUGraph *base, GtkWidget *da, int w, int h )
 			tmp = 0;
 			for( y = h-1; y >= h - usage; y--, tmp++ )
 			{
-				t = (base->m_ColorMode == 1) ?
+				t = (base->color_mode == 1) ?
 					(tmp / (double) (h)) :
 					(tmp / (double) (usage));
-				MixAndApplyColors( t, &base->colors[1], &base->colors[2], fg1);
+				mix_colors( t, &base->colors[1], &base->colors[2], fg1);
 				gdk_draw_point( da->window, fg1, x, y );
 			}
 		}
@@ -74,7 +74,7 @@ void drawGraphModeNormal( CPUGraph *base, GtkWidget *da, int w, int h )
 	g_object_unref( fg1 );
 }
 
-void drawGraphModeLED( CPUGraph *base, GtkWidget *da, int w, int h )
+void draw_graph_LED( CPUGraph *base, GtkWidget *da, int w, int h )
 {
 	int nrx = (w + 1) / 3;
 	int nry = (h + 1) / 2;
@@ -88,15 +88,15 @@ void drawGraphModeLED( CPUGraph *base, GtkWidget *da, int w, int h )
 	for( x = 0; x * 3 < w; x++ )
 	{
 		int idx = nrx-x;
-		int limit = nry - nry * base->m_History[idx]/CPU_SCALE;
+		int limit = nry - nry * base->history[idx]/CPU_SCALE;
 		for( y = 0; y * 2 < h; y++ )
 		{
-			if( base->m_ColorMode != 0 && y < limit )
+			if( base->color_mode != 0 && y < limit )
 			{
-				double t = (base->m_ColorMode == 1) ?
+				double t = (base->color_mode == 1) ?
 				           (y / (double)nry) :
 				           (y / (double)limit);
-				MixAndApplyColors( t, &base->colors[3], &base->colors[2], fg2);
+				mix_colors( t, &base->colors[3], &base->colors[2], fg2);
 			}
 			gdk_draw_rectangle (da->window, y >= limit ? fg1 : fg2, TRUE, x * 3, y * 2, 2, 1);
 		}
@@ -105,15 +105,15 @@ void drawGraphModeLED( CPUGraph *base, GtkWidget *da, int w, int h )
 	g_object_unref( fg2 );
 }
 
-void drawGraphModeNoHistory( CPUGraph *base, GtkWidget *da, int w, int h )
+void draw_graph_no_history( CPUGraph *base, GtkWidget *da, int w, int h )
 {
 	int y;
-	long usage = h * base->m_History[0] / CPU_SCALE;
+	long usage = h * base->history[0] / CPU_SCALE;
 	int tmp = 0;
 	double t;
 	GdkGC *fg1 = gdk_gc_new( da->window );
 
-	if( base->m_ColorMode == 0 )
+	if( base->color_mode == 0 )
 	{
 		gdk_gc_set_rgb_fg_color( fg1, &base->colors[1] );
 		gdk_draw_rectangle( da->window, fg1, TRUE, 0, h-usage, w, usage );
@@ -122,10 +122,10 @@ void drawGraphModeNoHistory( CPUGraph *base, GtkWidget *da, int w, int h )
 	{
 		for( y = h-1; y > h - 1 - usage; y-- )
 		{
-			t = (base->m_ColorMode == 1) ?
+			t = (base->color_mode == 1) ?
 				(tmp / (double) (h)) :
 				(tmp / (double) (usage));
-			MixAndApplyColors( t, &base->colors[1], &base->colors[2], fg1 );
+			mix_colors( t, &base->colors[1], &base->colors[2], fg1 );
 			tmp++;
 			gdk_draw_line( da->window, fg1, 0, y, w-1, y );
 		}
@@ -139,7 +139,7 @@ typedef struct
 	long y;
 } point;
 
-void drawGraphGrid( CPUGraph *base, GtkWidget *da, int w, int h )
+void draw_graph_grid( CPUGraph *base, GtkWidget *da, int w, int h )
 {
 	int x, y;
 	long usage;
@@ -161,7 +161,7 @@ void drawGraphGrid( CPUGraph *base, GtkWidget *da, int w, int h )
 	gdk_gc_set_rgb_fg_color( fg1, &base->colors[2] );
 	for( x = 0; x < w; x++ )
 	{
-		usage = h * base->m_History[w - 1- x] / CPU_SCALE;
+		usage = h * base->history[w - 1- x] / CPU_SCALE;
 		current.x = x;
 		current.y = h - usage;
 		gdk_draw_line( da->window, fg1, current.x, current.y, last.x, last.y );
diff --git a/panel-plugin/mode.h b/panel-plugin/mode.h
index 8807fe1..3108097 100644
--- a/panel-plugin/mode.h
+++ b/panel-plugin/mode.h
@@ -1,11 +1,11 @@
-#ifndef __XFCE_MODE_H__
-#define __XFCE_MODE_H__
+#ifndef _XFCE_MODE_H_
+#define _XFCE_MODE_H_
 
 #include "cpu.h"
 
-void drawGraphModeNormal( CPUGraph *base, GtkWidget *da, int w, int h );
-void drawGraphModeLED( CPUGraph *base, GtkWidget *da, int w, int h );
-void drawGraphModeNoHistory( CPUGraph *base, GtkWidget *da, int w, int h );
-void drawGraphGrid( CPUGraph *base, GtkWidget *da, int w, int h );
+void draw_graph_normal( CPUGraph *base, GtkWidget *da, int w, int h );
+void draw_graph_LED( CPUGraph *base, GtkWidget *da, int w, int h );
+void draw_graph_no_history( CPUGraph *base, GtkWidget *da, int w, int h );
+void draw_graph_grid( CPUGraph *base, GtkWidget *da, int w, int h );
 
-#endif
+#endif /* !_XFCE_MODE_H_ */
diff --git a/panel-plugin/os.c b/panel-plugin/os.c
index 36dbbc0..69894b6 100644
--- a/panel-plugin/os.c
+++ b/panel-plugin/os.c
@@ -2,30 +2,61 @@
 #include <config.h>
 #endif
 
-#include "cpu.h"
+#include "os.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
 
 #if defined (__linux__)
 #define PROC_STAT "/proc/stat"
-#define SYS_DEVICE "/sys/devices/system/cpu/cpu"
-#define SCAL_CUR_FREQ "/cpufreq/scaling_cur_freq"
-#define SCAL_MIN_FREQ "/cpufreq/scaling_min_freq"
-#define SCAL_MAX_FREQ "/cpufreq/scaling_max_freq"
 #define PROCMAXLNLEN 256 /* should make it */
 #endif
 
+#if defined (__FreeBSD__)
+#include <osreldate.h>
+#include <sys/types.h>
+#if __FreeBSD_version < 500101
+#include <sys/dkstat.h>
+#else
+#include <sys/resource.h>
+#endif
+#include <sys/sysctl.h>
+#include <devstat.h>
+#include <fcntl.h>
+#include <nlist.h>
+#endif
+
+#if defined (__NetBSD__)
+#include <sys/param.h>
+#include <sys/sched.h>
+#include <sys/sysctl.h>
+#include <fcntl.h>
+#include <nlist.h>
+#endif
+
+#if defined (__OpenBSD__)
+#include <sys/param.h>
+#include <sys/sched.h>
+#include <sys/sysctl.h>
+#include <sys/dkstat.h>
+#include <fcntl.h>
+#include <nlist.h>
+#endif
+
 CpuData *cpudata = NULL;
 int nrCpus = 0;
 
-static int DetectCPUNumber();
+static int detect_cpu_number();
 
-void cpuData_free()
+void free_cpu_data()
 {
 	g_free( cpudata );
 	cpudata = NULL;
 	nrCpus = 0;
 }
 
-int cpuData_init()
+int init_cpu_data()
 {
 	int i, cpuNr = -1;
 
@@ -33,7 +64,7 @@ int cpuData_init()
 	if( cpudata != NULL )
 		return -2;
 
-	cpuNr = DetectCPUNumber();
+	cpuNr = detect_cpu_number();
 	if( cpuNr < 1 )
 		return -1;
 
@@ -44,7 +75,7 @@ int cpuData_init()
 }
 
 #if defined (__linux__)
-static int DetectCPUNumber()
+static int detect_cpu_number()
 {
 	int cpuNr= -1;
 	FILE *fstat = NULL;
@@ -64,7 +95,7 @@ static int DetectCPUNumber()
 	return cpuNr;
 }
 
-CpuData *cpuData_read()
+CpuData *read_cpu_data()
 {
 	FILE *fStat = NULL;
 	char cpuStr[PROCMAXLNLEN];
@@ -110,12 +141,12 @@ CpuData *cpuData_read()
 }
 
 #elif defined (__FreeBSD__)
-static int DetectCPUNumber()
+static int detect_cpu_number()
 {
 	return 1;
 }
 
-CpuData *cpuData_read()
+CpuData *read_cpu_data()
 {
 	unsigned long user, nice, sys, bsdidle, idle;
 	unsigned long used, total;
@@ -150,12 +181,12 @@ CpuData *cpuData_read()
 }
 
 #elif defined (__NetBSD__)
-static int DetectCPUNumber()
+static int detect_cpu_number()
 {
 	return 1;
 }
 
-CpuData *cpuData_read()
+CpuData *read_cpu_data()
 {
 	long user, nice, sys, bsdidle, idle;
 	long used, total, usage;
@@ -190,12 +221,12 @@ CpuData *cpuData_read()
 }
 
 #elif defined (__OpenBSD__)
-static int DetectCPUNumber()
+static int detect_cpu_number()
 {
 	return 1;
 }
 
-CpuData *cpuData_read()
+CpuData *read_cpu_data()
 {
 	unsigned long user, nice, sys, bsdidle, idle;
 	unsigned long used, total, usage;
diff --git a/panel-plugin/os.h b/panel-plugin/os.h
index b2ebac6..3924419 100644
--- a/panel-plugin/os.h
+++ b/panel-plugin/os.h
@@ -1,42 +1,9 @@
-#ifndef __OS_H__
-#define __OS_H__
-
-#include <stdio.h>
-
-#if defined (__FreeBSD__)
-#include <osreldate.h>
-#include <sys/types.h>
-#if __FreeBSD_version < 500101
-#include <sys/dkstat.h>
-#else
-#include <sys/resource.h>
-#endif
-#include <sys/sysctl.h>
-#include <devstat.h>
-#include <fcntl.h>
-#include <nlist.h>
-#endif
-
-#if defined (__NetBSD__)
-#include <sys/param.h>
-#include <sys/sched.h>
-#include <sys/sysctl.h>
-#include <fcntl.h>
-#include <nlist.h>
-#endif
-
-#if defined (__OpenBSD__)
-#include <sys/param.h>
-#include <sys/sched.h>
-#include <sys/sysctl.h>
-#include <sys/dkstat.h>
-#include <fcntl.h>
-#include <nlist.h>
-#endif
+#ifndef _XFCE_OS_H_
+#define _XFCE_OS_H_
 
 #define CPU_SCALE 100000
 
-typedef struct s_cpuData
+typedef struct
 {
 	float load; /* cpu utilization */
 	unsigned long pUsed; /* Previous value of used cpu time */
@@ -44,8 +11,8 @@ typedef struct s_cpuData
 } CpuData;
 
 
-int cpuData_init();
-void cpuData_free();
-CpuData *cpuData_read();
+int init_cpu_data();
+void free_cpu_data();
+CpuData *read_cpu_data();
 
-#endif
+#endif /* !_XFCE_OS_H */
diff --git a/panel-plugin/properties.c b/panel-plugin/properties.c
index 63ec061..cd00b74 100644
--- a/panel-plugin/properties.c
+++ b/panel-plugin/properties.c
@@ -1,19 +1,34 @@
-#include <actions.h>
-
-static GtkBox *CreateTab();
-static GtkBox *CreateOptionLine( GtkBox *tab, GtkSizeGroup *sg, const char *name );
-static void CreateCheckBox( GtkBox *tab, GtkSizeGroup *sg, const char *name, int init, void (callback)( GtkToggleButton *, CPUGraph *), void *cb_data );
-static void CreateDropDown( GtkBox *tab, GtkSizeGroup *sg, const char * name, const char **items, size_t nb_items, int init, void (callback)( GtkOptionMenu *, CPUGraph * ), void * cb_data);
-
-static void SetupUpdateIntervalOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base );
-static void SetupWidthOption( GtkBox *vbox, GtkSizeGroup *sg, XfcePanelPlugin *plugin, CPUGraph *base );
-static void SetupAssociateCommandOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base );
-static void SetupColorOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base, int number, const gchar *name, GCallback cb );
-static void SetupModesOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base );
-static void SetupColormodeOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base );
-
-
-void CreateOptions( XfcePanelPlugin *plugin, CPUGraph *base )
+#include "cpu.h"
+#include "properties.h"
+#include "settings.h"
+
+static GtkBox *create_tab();
+static GtkBox *create_option_line( GtkBox *tab, GtkSizeGroup *sg, const char *name );
+static void create_check_box( GtkBox *tab, GtkSizeGroup *sg, const char *name, int init, void (callback)( GtkToggleButton *, CPUGraph *), void *cb_data );
+static void create_drop_down( GtkBox *tab, GtkSizeGroup *sg, const char * name, const char **items, size_t nb_items, int init, void (callback)( GtkOptionMenu *, CPUGraph * ), void * cb_data);
+
+static void setup_update_interval_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base );
+static void setup_size_option( GtkBox *vbox, GtkSizeGroup *sg, XfcePanelPlugin *plugin, CPUGraph *base );
+static void setup_command_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base );
+static void setup_color_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base, int number, const gchar *name, GCallback cb );
+static void setup_mode_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base );
+static void setup_color_mode_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base );
+
+static void change_command( GtkEntry *entry, CPUGraph *base );
+static void change_color_0( GtkColorButton *button, CPUGraph *base );
+static void change_color_1( GtkColorButton * button, CPUGraph * base );
+static void change_color_2( GtkColorButton *button, CPUGraph *base );
+static void change_color_3( GtkColorButton *button, CPUGraph *base );
+static void select_active_colors( CPUGraph * base );
+static void change_mode( GtkOptionMenu *om, CPUGraph *base );
+static void change_color_mode( GtkOptionMenu *om, CPUGraph *base );
+static void response_cb( GtkWidget *dlg, int response, CPUGraph *base );
+static void change_frame( GtkToggleButton *button, CPUGraph *base );
+static void change_size( GtkSpinButton *sb, CPUGraph *base );
+static void change_time_scale( GtkToggleButton *button, CPUGraph *base );
+static void change_update( GtkOptionMenu *om, CPUGraph *base );
+
+void create_options( XfcePanelPlugin *plugin, CPUGraph *base )
 {
 	GtkWidget *dlg, *header;
 	GtkBox *vbox, *vbox2;
@@ -33,7 +48,7 @@ void CreateOptions( XfcePanelPlugin *plugin, CPUGraph *base )
 
 	base->m_OptionsDialog = dlg;
 
-	g_signal_connect( dlg, "response", G_CALLBACK( DialogResponse ), base );
+	g_signal_connect( dlg, "response", G_CALLBACK( response_cb ), base );
 
 	gtk_container_set_border_width( GTK_CONTAINER( dlg ), 2 );
 
@@ -45,21 +60,21 @@ void CreateOptions( XfcePanelPlugin *plugin, CPUGraph *base )
 
 	sg = gtk_size_group_new( GTK_SIZE_GROUP_HORIZONTAL );
 
-	vbox = CreateTab();
-	SetupUpdateIntervalOption( vbox, sg, base );
-	SetupWidthOption( vbox, sg, plugin, base );
-	CreateCheckBox( vbox, sg, _("Non-linear time-scale"), base->m_TimeScale, TimeScaleChange, base );
-	CreateCheckBox( vbox, sg, _("Show frame"), base->m_Frame, FrameChange, base );
-	SetupAssociateCommandOption( vbox, sg, base );
-
-	vbox2 = CreateTab();
-	SetupColorOption( vbox2, sg, base, 1, _("Color 1:"), G_CALLBACK( ChangeColor1 ) );
-	SetupColorOption( vbox2, sg, base, 2, _("Color 2:"), G_CALLBACK( ChangeColor2 ) );
-	SetupColorOption( vbox2, sg, base, 3, _("Color 3:"), G_CALLBACK( ChangeColor3 ) );
-	SetupColorOption( vbox2, sg, base, 0, _("Background:"), G_CALLBACK( ChangeColor0 ) );
+	vbox = create_tab();
+	setup_update_interval_option( vbox, sg, base );
+	setup_size_option( vbox, sg, plugin, base );
+	create_check_box( vbox, sg, _("Non-linear time-scale"), base->non_linear, change_time_scale, base );
+	create_check_box( vbox, sg, _("Show frame"), base->frame, change_frame, base );
+	setup_command_option( vbox, sg, base );
+
+	vbox2 = create_tab();
+	setup_color_option( vbox2, sg, base, 1, _("Color 1:"), G_CALLBACK( change_color_1 ) );
+	setup_color_option( vbox2, sg, base, 2, _("Color 2:"), G_CALLBACK( change_color_2 ) );
+	setup_color_option( vbox2, sg, base, 3, _("Color 3:"), G_CALLBACK( change_color_3 ) );
+	setup_color_option( vbox2, sg, base, 0, _("Background:"), G_CALLBACK( change_color_0 ) );
 	select_active_colors( base );
-	SetupModesOption( vbox2, sg, base );
-	SetupColormodeOption( vbox2, sg, base );
+	setup_mode_option( vbox2, sg, base );
+	setup_color_mode_option( vbox2, sg, base );
 
 	Notebook = gtk_notebook_new();
 	gtk_container_set_border_width( GTK_CONTAINER( Notebook ), BORDER - 2 );
@@ -74,7 +89,7 @@ void CreateOptions( XfcePanelPlugin *plugin, CPUGraph *base )
 	gtk_widget_show( dlg );
 }
 
-static GtkBox *CreateTab()
+static GtkBox *create_tab()
 {
 	GtkBox *tab;
 	tab = GTK_BOX( gtk_vbox_new( FALSE, BORDER ) );
@@ -83,7 +98,7 @@ static GtkBox *CreateTab()
 	return tab;
 }
 
-static GtkBox *CreateOptionLine( GtkBox *tab, GtkSizeGroup *sg, const char *name )
+static GtkBox *create_option_line( GtkBox *tab, GtkSizeGroup *sg, const char *name )
 {
 	GtkBox *line;
 	GtkWidget *label;
@@ -104,12 +119,12 @@ static GtkBox *CreateOptionLine( GtkBox *tab, GtkSizeGroup *sg, const char *name
 	return line;
 }
 
-static void CreateCheckBox( GtkBox *tab, GtkSizeGroup *sg, const char *name, int init, void (callback)( GtkToggleButton *, CPUGraph *), void *cb_data )
+static void create_check_box( GtkBox *tab, GtkSizeGroup *sg, const char *name, int init, void (callback)( GtkToggleButton *, CPUGraph *), void *cb_data )
 {
 	GtkBox *hbox;
 	GtkWidget * checkBox;
 
-	hbox = CreateOptionLine( tab, sg, NULL );
+	hbox = create_option_line( tab, sg, NULL );
 
 	checkBox = gtk_check_button_new_with_mnemonic( name );
 	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( checkBox ), init );
@@ -119,7 +134,7 @@ static void CreateCheckBox( GtkBox *tab, GtkSizeGroup *sg, const char *name, int
 	gtk_size_group_add_widget( sg, checkBox );
 }
 
-static void CreateDropDown( GtkBox *tab, GtkSizeGroup *sg, const char * name, const char ** items, size_t nb_items, int init, void (callback)( GtkOptionMenu *, CPUGraph * ), void * cb_data)
+static void create_drop_down( GtkBox *tab, GtkSizeGroup *sg, const char * name, const char ** items, size_t nb_items, int init, void (callback)( GtkOptionMenu *, CPUGraph * ), void * cb_data)
 {
 	GtkBox *hbox;
 	GtkWidget *Option;
@@ -127,7 +142,7 @@ static void CreateDropDown( GtkBox *tab, GtkSizeGroup *sg, const char * name, co
 	GtkWidget *MenuItem;
 	int i;
 
-	hbox = CreateOptionLine( tab, sg, name );
+	hbox = create_option_line( tab, sg, name );
 
 	Option = gtk_option_menu_new();
 	gtk_widget_show( Option );
@@ -148,7 +163,7 @@ static void CreateDropDown( GtkBox *tab, GtkSizeGroup *sg, const char * name, co
 	g_signal_connect( Option, "changed", G_CALLBACK( callback ), cb_data );
 }
 
-static void SetupUpdateIntervalOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
+static void setup_update_interval_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
 {
 	const char *items[] = { _("Fastest (~250ms)"),
 	                        _("Fast (~500ms)"),
@@ -157,45 +172,45 @@ static void SetupUpdateIntervalOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph
 	                      };
 	size_t nb_items = sizeof( items ) / sizeof( char* );
 
-	CreateDropDown( vbox, sg, _("Update Interval: "), items, nb_items, base->m_UpdateInterval, UpdateChange, base);
+	create_drop_down( vbox, sg, _("Update Interval: "), items, nb_items, base->update_interval, change_update, base);
 }
 
-static void SetupWidthOption( GtkBox *vbox, GtkSizeGroup *sg, XfcePanelPlugin *plugin, CPUGraph *base )
+static void setup_size_option( GtkBox *vbox, GtkSizeGroup *sg, XfcePanelPlugin *plugin, CPUGraph *base )
 {
 	GtkBox *hbox;
 	GtkWidget *Size;
 
 	if( xfce_panel_plugin_get_orientation( plugin ) == GTK_ORIENTATION_HORIZONTAL )
-		hbox = CreateOptionLine( vbox, sg, _("Width:") );
+		hbox = create_option_line( vbox, sg, _("Width:") );
 	else
-		hbox = CreateOptionLine( vbox, sg, _("Height:") );
+		hbox = create_option_line( vbox, sg, _("Height:") );
 
 	Size = gtk_spin_button_new_with_range( 10, 128, 1 );
 	gtk_spin_button_set_value( GTK_SPIN_BUTTON( Size ), base->size );
 	gtk_widget_show( Size );
 	gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( Size ), FALSE, FALSE, 0 );
-	g_signal_connect( Size, "value-changed", G_CALLBACK( SizeChange ), base );
+	g_signal_connect( Size, "value-changed", G_CALLBACK( change_size ), base );
 }
 
-static void SetupAssociateCommandOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
+static void setup_command_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
 {
 	GtkBox *hbox;
 	GtkWidget *AssociateCommand;
 
-	hbox = CreateOptionLine( vbox, sg, _("Associated command :") );
+	hbox = create_option_line( vbox, sg, _("Associated command :") );
 
 	AssociateCommand = gtk_entry_new();
-	gtk_entry_set_text( GTK_ENTRY(AssociateCommand), base->m_AssociateCommand );
+	gtk_entry_set_text( GTK_ENTRY(AssociateCommand), base->command );
 	gtk_widget_show( AssociateCommand );
 	gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( AssociateCommand ), FALSE, FALSE, 0 );
-	g_signal_connect( AssociateCommand, "changed", G_CALLBACK( AssociateCommandChange ), base );
+	g_signal_connect( AssociateCommand, "changed", G_CALLBACK( change_command ), base );
 }
 
-static void SetupColorOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base, int number, const gchar * name, GCallback cb )
+static void setup_color_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base, int number, const gchar * name, GCallback cb )
 {
 	GtkBox *hbox;
 
-	hbox = CreateOptionLine( vbox, sg, name );
+	hbox = create_option_line( vbox, sg, name );
 
 	base->color_buttons[number] = gtk_color_button_new_with_color( &base->colors[number] );
 	gtk_widget_show( GTK_WIDGET( base->color_buttons[number] ) );
@@ -204,7 +219,7 @@ static void SetupColorOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base, in
 	g_signal_connect( base->color_buttons[number], "color-set", cb, base );
 }
 
-static void SetupModesOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
+static void setup_mode_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
 {
 	const char *items[] = { _("Normal"),
 	                        _("LED"),
@@ -213,10 +228,10 @@ static void SetupModesOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
 	                      };
 	size_t nb_items = sizeof( items ) / sizeof( char* );
 
-	CreateDropDown( vbox, sg, _("Mode:"), items, nb_items, base->m_Mode, ModeChange, base);
+	create_drop_down( vbox, sg, _("Mode:"), items, nb_items, base->mode, change_mode, base);
 }
 
-static void SetupColormodeOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
+static void setup_color_mode_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
 {
 	const char *items[] = { _("None"),
 	                        _("Gradient"),
@@ -224,5 +239,89 @@ static void SetupColormodeOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base
 	                      };
 	size_t nb_items = sizeof( items ) / sizeof( char* );
 
-	CreateDropDown( vbox, sg, _("Color mode: "), items, nb_items, base->m_ColorMode, ColorModeChange, base);
+	create_drop_down( vbox, sg, _("Color mode: "), items, nb_items, base->color_mode, change_color_mode, base);
+}
+
+static void change_command( GtkEntry *entry, CPUGraph * base )
+{
+	set_command( base, gtk_entry_get_text( entry ) );
+}
+
+static void change_color( GtkColorButton * button, CPUGraph * base, int number)
+{
+	GdkColor color;
+	gtk_color_button_get_color( button, &color );
+	set_color( base, number, color );
+}
+
+static void change_color_1( GtkColorButton * button, CPUGraph * base )
+{
+	change_color( button, base, 1);
+}
+
+static void change_color_2( GtkColorButton * button, CPUGraph * base )
+{
+	change_color( button, base, 2);
+}
+
+static void change_color_3( GtkColorButton * button, CPUGraph * base )
+{
+	change_color( button, base, 3);
+}
+
+static void change_color_0( GtkColorButton * button, CPUGraph * base )
+{
+	change_color( button, base, 0);
+}
+
+static void select_active_colors( CPUGraph * base )
+{
+	if( base->color_mode != 0 || base->mode == 1 || base->mode == 3 )
+		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[2] ), TRUE );
+	else
+		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[2] ), FALSE );
+
+	if( base->color_mode != 0 && base->mode == 1 )
+		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[3] ), TRUE );
+	else
+		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[3] ), FALSE );
+}
+
+static void change_mode( GtkOptionMenu * om, CPUGraph * base )
+{
+	set_mode( base, gtk_option_menu_get_history( om ) );
+	select_active_colors( base );
+}
+
+static void change_color_mode( GtkOptionMenu * om, CPUGraph * base )
+{
+	set_color_mode( base, gtk_option_menu_get_history( om ) );
+	select_active_colors( base );
+}
+
+static void response_cb( GtkWidget *dlg, int response, CPUGraph *base )
+{
+	gtk_widget_destroy( dlg );
+	xfce_panel_plugin_unblock_menu( base->plugin );
+	write_settings( base->plugin, base );
+}
+
+static void change_frame( GtkToggleButton * button, CPUGraph * base )
+{
+	set_frame( base, gtk_toggle_button_get_active( button ) );
+}
+
+static void change_size( GtkSpinButton * sb, CPUGraph *base)
+{
+	set_size( base, gtk_spin_button_get_value_as_int( sb ) );
+}
+
+static void change_time_scale( GtkToggleButton * button, CPUGraph * base )
+{
+	set_nonlinear_time( base, gtk_toggle_button_get_active( button ) );
+}
+
+static void change_update( GtkOptionMenu * om, CPUGraph * base )
+{
+	set_update_rate( base, gtk_option_menu_get_history( om ) );
 }
diff --git a/panel-plugin/properties.h b/panel-plugin/properties.h
new file mode 100644
index 0000000..2b3226f
--- /dev/null
+++ b/panel-plugin/properties.h
@@ -0,0 +1,8 @@
+#ifndef _XFCE_PROPERTIES_H_
+#define _XFCE_PROPERTIES_H_
+
+#include "cpu.h"
+
+void create_options( XfcePanelPlugin *plugin, CPUGraph *base );
+
+#endif /* !_XFCE_PROPERTIES_H_ */
diff --git a/panel-plugin/settings.c b/panel-plugin/settings.c
index 49d0436..6e1e1a3 100644
--- a/panel-plugin/settings.c
+++ b/panel-plugin/settings.c
@@ -1,6 +1,8 @@
-#include <cpu.h>
+#include "settings.h"
 
-void ReadSettings( XfcePanelPlugin * plugin, CPUGraph * base )
+#define DEFAULT_COMMAND "exo-open --launch TerminalEmulator top"
+
+void read_settings( XfcePanelPlugin * plugin, CPUGraph * base )
 {
 	const char *value;
 	char *file;
@@ -76,7 +78,7 @@ void ReadSettings( XfcePanelPlugin * plugin, CPUGraph * base )
 	set_color( base, 0, background );
 }
 
-void WriteSettings( XfcePanelPlugin *plugin, CPUGraph *base )
+void write_settings( XfcePanelPlugin *plugin, CPUGraph *base )
 {
 	char value[10];
 	XfceRc *rc;
@@ -91,19 +93,19 @@ void WriteSettings( XfcePanelPlugin *plugin, CPUGraph *base )
 	if( !rc )
 		return;
 
-	xfce_rc_write_int_entry( rc, "UpdateInterval", base->m_UpdateInterval );
+	xfce_rc_write_int_entry( rc, "UpdateInterval", base->update_interval );
 
-	xfce_rc_write_int_entry( rc, "TimeScale", base->m_TimeScale );
+	xfce_rc_write_int_entry( rc, "TimeScale", base->non_linear );
 
 	xfce_rc_write_int_entry( rc, "Size", base->size );
 
-	xfce_rc_write_int_entry( rc, "Mode", base->m_Mode );
+	xfce_rc_write_int_entry( rc, "Mode", base->mode );
 
-	xfce_rc_write_int_entry( rc, "Frame", base->m_Frame );
+	xfce_rc_write_int_entry( rc, "Frame", base->frame );
 
-	xfce_rc_write_entry( rc, "AssociateCommand", base->m_AssociateCommand ? base->m_AssociateCommand : "" );
+	xfce_rc_write_entry( rc, "AssociateCommand", base->command ? base->command : "" );
 
-	xfce_rc_write_int_entry( rc, "ColorMode", base->m_ColorMode );
+	xfce_rc_write_int_entry( rc, "ColorMode", base->color_mode );
 
 	g_snprintf( value, 8, "#%02X%02X%02X", base->colors[1].red >> 8, base->colors[1].green >> 8, base->colors[1].blue >> 8 );
 	xfce_rc_write_entry( rc, "Foreground1", value );
diff --git a/panel-plugin/settings.h b/panel-plugin/settings.h
new file mode 100644
index 0000000..848debb
--- /dev/null
+++ b/panel-plugin/settings.h
@@ -0,0 +1,9 @@
+#ifndef _XFCE_SETTINGS_H_
+#define _XFCE_SETTINGS_H_
+
+#include "cpu.h"
+
+void read_settings( XfcePanelPlugin *plugin, CPUGraph *base );
+void write_settings( XfcePanelPlugin *plugin, CPUGraph *base );
+
+#endif /* !_XFCE_SETTINGS_H_ */



More information about the Xfce4-commits mailing list