diff options
-rw-r--r-- | multiload/Makefile.am | 25 | ||||
-rw-r--r-- | multiload/cpuload.c | 242 | ||||
-rw-r--r-- | multiload/cpuload.h | 16 | ||||
-rw-r--r-- | multiload/global.h | 38 | ||||
-rw-r--r-- | multiload/linux-proc.c | 149 | ||||
-rw-r--r-- | multiload/linux-proc.h | 6 | ||||
-rw-r--r-- | multiload/load-graph.c | 354 | ||||
-rw-r--r-- | multiload/load-graph.h | 41 | ||||
-rw-r--r-- | multiload/main.c | 141 | ||||
-rw-r--r-- | multiload/memload.c | 263 | ||||
-rw-r--r-- | multiload/memload.h | 17 | ||||
-rw-r--r-- | multiload/properties-cpu.c | 244 | ||||
-rw-r--r-- | multiload/properties-cpu.h | 18 | ||||
-rw-r--r-- | multiload/properties-mem.c | 296 | ||||
-rw-r--r-- | multiload/properties-mem.h | 20 | ||||
-rw-r--r-- | multiload/properties-swap.c | 246 | ||||
-rw-r--r-- | multiload/properties-swap.h | 18 | ||||
-rw-r--r-- | multiload/properties.c | 84 | ||||
-rw-r--r-- | multiload/properties.h | 37 | ||||
-rw-r--r-- | multiload/property-entries.c | 135 | ||||
-rw-r--r-- | multiload/property-entries.h | 41 | ||||
-rw-r--r-- | multiload/swapload.c | 224 | ||||
-rw-r--r-- | multiload/swapload.h | 16 |
23 files changed, 1025 insertions, 1646 deletions
diff --git a/multiload/Makefile.am b/multiload/Makefile.am index 00cf008fd..7aef5c7d7 100644 --- a/multiload/Makefile.am +++ b/multiload/Makefile.am @@ -1,26 +1,23 @@ INCLUDES = -I. -I$(srcdir) \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ - -I$(top_builddir)/panel \ - -I$(srcdir)/../../panel \ + -I$(top_builddir)/panel -I$(srcdir)/../../panel \ -I$(includedir) $(GNOME_INCLUDEDIR) $(LIBGTOP_INCS) bin_PROGRAMS = multiload_applet -multiload_applet_SOURCES = cpuload.c \ - cpuload.h \ - memload.c \ - memload.h \ - swapload.c \ - swapload.h \ +multiload_applet_SOURCES = cpuload.c \ + memload.c \ + swapload.c \ main.c \ + global.h \ + properties.c \ + properties.h \ + property-entries.c \ + property-entries.h \ linux-proc.h \ linux-proc.c \ - properties-cpu.c \ - properties-cpu.h \ - properties-mem.c \ - properties-mem.h \ - properties-swap.c \ - properties-swap.h + load-graph.c \ + load-graph.h multiload_applet_LDADD = ../../panel/libpanel_applet.la \ $(GNOME_LIBDIR) \ diff --git a/multiload/cpuload.c b/multiload/cpuload.c index 616cbdcd5..37a9096fa 100644 --- a/multiload/cpuload.c +++ b/multiload/cpuload.c @@ -21,185 +21,15 @@ #include <gdk/gdkx.h> #include <applet-widget.h> -#include "linux-proc.h" -#include "properties-cpu.h" -#include "cpuload.h" - -cpuload_properties cpu_props; - -static guchar udata [128]; -static guchar oudata [128]; -static guchar sdata [128]; -static guchar osdata [128]; - -static int -draw (gpointer data_ptr) -{ - int usr=0, sys=0, nice=0, free=0, i; - Cpuload *c = (Cpuload *) data_ptr; - - GetLoad (cpu_props.height, &usr, &nice, &sys, &free ); - - for (i=0; i < cpu_props.width-1; i++) { - udata [i+1] = oudata [i]; - sdata [i+1] = osdata [i]; - } - udata [0] = usr; - sdata [0] = sys; - - /* Erase Rectangle */ - gdk_draw_rectangle (c->pixmap, - c->disp->style->black_gc, - TRUE, 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - - gdk_gc_set_foreground (c->gc, &c->ucolor); - for (i=0; i < cpu_props.width; i++) { - if (udata[i]) - gdk_draw_line (c->pixmap, - c->gc, - i, cpu_props.height, - i, (cpu_props.height - udata[i])); - } - - gdk_gc_set_foreground (c->gc, &c->scolor); - for (i=0; i < cpu_props.width; i++) { - if (sdata[i]) - gdk_draw_line (c->pixmap, - c->gc, - i, (cpu_props.height - udata[i]), - i, ((cpu_props.height - udata[i]) - - sdata[i])); - } - - gdk_draw_pixmap (c->disp->window, - c->disp->style->fg_gc [GTK_WIDGET_STATE(c->disp)], - c->pixmap, - 0, 0, - 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - - for (i=0; i < cpu_props.width; i++) { - oudata[i] = udata[i]; - osdata[i] = sdata[i]; - } - return TRUE; -} - -static gint -cpuload_configure (GtkWidget *widget, GdkEventConfigure *event, - gpointer data_ptr) -{ - Cpuload *c = (Cpuload *) data_ptr; - - c->pixmap = gdk_pixmap_new (widget->window, - widget->allocation.width, - widget->allocation.height, - gtk_widget_get_visual (c->disp)->depth); - gdk_draw_rectangle (c->pixmap, - widget->style->black_gc, - TRUE, 0,0, - widget->allocation.width, - widget->allocation.height); - gdk_draw_pixmap (widget->window, - c->disp->style->fg_gc [GTK_WIDGET_STATE(widget)], - c->pixmap, - 0, 0, - 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - return TRUE; -} - -static gint -cpuload_expose (GtkWidget *widget, GdkEventExpose *event, - gpointer data_ptr) -{ - Cpuload *c = (Cpuload *) data_ptr; - - gdk_draw_pixmap (widget->window, - widget->style->fg_gc [GTK_WIDGET_STATE(widget)], - c->pixmap, - event->area.x, event->area.y, - event->area.x, event->area.y, - event->area.width, event->area.height); - return FALSE; -} - -static Cpuload * -cpuload_new (void) -{ - GtkWidget *box; - Cpuload *c; - - c = g_malloc (sizeof (Cpuload)); - memset (c, 0, sizeof (Cpuload)); - - c->timer_index = -1; - - box = gtk_vbox_new (FALSE, FALSE); - gtk_widget_show (box); - - c->frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (c->frame), - cpu_props.look?GTK_SHADOW_OUT:GTK_SHADOW_IN); - - c->disp = gtk_drawing_area_new (); - gtk_signal_connect (GTK_OBJECT (c->disp), "expose_event", - (GtkSignalFunc)cpuload_expose, c); - gtk_signal_connect (GTK_OBJECT(c->disp), "configure_event", - (GtkSignalFunc)cpuload_configure, c); - gtk_widget_set_events (c->disp, GDK_EXPOSURE_MASK); - - gtk_box_pack_start_defaults (GTK_BOX (box), c->disp); - gtk_container_add (GTK_CONTAINER (c->frame), box); - - gtk_widget_set_usize (c->disp, cpu_props.width, cpu_props.height); - - cpuload_start_timer (c); - - gtk_widget_show_all (c->frame); - return c; -} - -void -cpuload_start_timer (Cpuload *c) -{ - if (c->timer_index != -1) - gtk_timeout_remove (c->timer_index); - - c->timer_index = - gtk_timeout_add (cpu_props.speed, (GtkFunction)draw, c); -} - -void -cpuload_setup_colors (Cpuload *c) -{ - GdkColormap *colormap; - - colormap = gtk_widget_get_colormap (c->disp); - - gdk_color_parse (cpu_props.ucolor, &c->ucolor); - gdk_color_alloc (colormap, &c->ucolor); - - gdk_color_parse (cpu_props.scolor, &c->scolor); - gdk_color_alloc (colormap, &c->scolor); -} - -static void -create_gc (Cpuload *c) -{ - c->gc = gdk_gc_new (c->disp->window); - gdk_gc_copy (c->gc, c->disp->style->white_gc); -} +#include "global.h" static gint applet_save_session (GtkWidget *widget, char *privcfgpath, char *globcfgpath, gpointer data) { +#if 0 save_cpu_properties (privcfgpath, &cpu_props); +#endif return FALSE; } @@ -207,36 +37,38 @@ applet_save_session (GtkWidget *widget, char *privcfgpath, GtkWidget * make_cpuload_applet (const gchar *goad_id) { - GtkWidget *applet; - GtkWidget *label; - Cpuload *cpuload; - - /* create a new applet_widget */ - applet = applet_widget_new(goad_id); - /* in the rare case that the communication with the panel - failed, error out */ - if (!applet) - g_error ("Can't create applet!\n"); - - load_cpu_properties (APPLET_WIDGET(applet)->privcfgpath, &cpu_props); - - cpuload = cpuload_new (); - applet_widget_add (APPLET_WIDGET(applet), cpuload->frame); - gtk_widget_show (applet); - - create_gc (cpuload); - cpuload_setup_colors (cpuload); - - gtk_signal_connect (GTK_OBJECT(applet),"save_session", - GTK_SIGNAL_FUNC(applet_save_session), - NULL); - - applet_widget_register_stock_callback (APPLET_WIDGET(applet), - "properties", - GNOME_STOCK_MENU_PROP, - _("Properties..."), - cpu_properties, - cpuload); - - return applet; + GtkWidget *applet; + LoadGraph *g; + + /* create a new applet_widget */ + applet = applet_widget_new(goad_id); + /* in the rare case that the communication with the panel + failed, error out */ + if (!applet) + g_error ("Can't create applet!\n"); + +#if 0 + load_cpu_properties (APPLET_WIDGET(applet)->privcfgpath, &cpu_props); +#endif + + g = load_graph_new (4, N_("CPU Load"), &multiload_properties.cpuload, + 500, 40, 40, GetLoad); + + applet_widget_add (APPLET_WIDGET(applet), g->frame); + gtk_widget_show (applet); + + load_graph_start (g); + + gtk_signal_connect (GTK_OBJECT(applet),"save_session", + GTK_SIGNAL_FUNC(applet_save_session), + NULL); + + applet_widget_register_stock_callback (APPLET_WIDGET(applet), + "properties", + GNOME_STOCK_MENU_PROP, + _("Properties..."), + multiload_properties_cb, + g); + + return applet; } diff --git a/multiload/cpuload.h b/multiload/cpuload.h deleted file mode 100644 index 3b6adde7b..000000000 --- a/multiload/cpuload.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef CPULOAD_H__ -#define CPULOAD_H__ - -typedef struct _Cpuload Cpuload; -struct _Cpuload { - GtkWidget *frame, *disp; - GdkPixmap *pixmap; - GdkGC *gc; - GdkColor ucolor, scolor; - int timer_index; -}; - -void cpuload_setup_colors (Cpuload *cpuload); -void cpuload_start_timer (Cpuload *cpuload); - -#endif diff --git a/multiload/global.h b/multiload/global.h new file mode 100644 index 000000000..acf906a67 --- /dev/null +++ b/multiload/global.h @@ -0,0 +1,38 @@ +#ifndef __GLOBAL_H__ +#define __GLOBAL_H__ + +#include <config.h> +#include <gnome.h> +#include <applet-widget.h> + +#include <linux-proc.h> +#include <properties.h> +#include <load-graph.h> + +BEGIN_GNOME_DECLS + +/* start a new instance of the cpuload applet */ +GtkWidget * +make_cpuload_applet (const gchar *goad_id); + +/* start a new instance of the memload applet */ +GtkWidget * +make_memload_applet (const gchar *goad_id); + +/* start a new instance of the swapload applet */ +GtkWidget * +make_swapload_applet (const gchar *goad_id); + +/* show properties dialog. */ +void +multiload_properties_cb (AppletWidget *widget, gpointer data); + +/* Logfile. */ +extern FILE *logfile; + +/* Load graph properties descriptor. */ +extern GnomePropertyDescriptor LoadGraphProperty_Descriptor; + +END_GNOME_DECLS + +#endif diff --git a/multiload/linux-proc.c b/multiload/linux-proc.c index 04a641ca4..f0ae1909b 100644 --- a/multiload/linux-proc.c +++ b/multiload/linux-proc.c @@ -31,98 +31,99 @@ static unsigned needed_mem_flags = static unsigned needed_swap_flags = 0; void -GetLoad (int Maximum, int *usr, int *nice, int *sys, int *free) +GetLoad (int Maximum, int data [4]) { - glibtop_cpu cpu; - int total; - - glibtop_get_cpu (&cpu); - - assert ((cpu.flags & needed_cpu_flags) == needed_cpu_flags); - - cp_time [0] = cpu.user; - cp_time [1] = cpu.nice; - cp_time [2] = cpu.sys; - cp_time [3] = cpu.idle; - - *usr = cp_time [0] - last [0]; - *nice = cp_time [1] - last [1]; - *sys = cp_time [2] - last [2]; - *free = cp_time [3] - last [3]; + static int init = 0; + int usr, nice, sys, free; + int total; - total = *usr + *nice + *sys + *free; + glibtop_cpu cpu; - last [0] = cp_time [0]; - last [1] = cp_time [1]; - last [2] = cp_time [2]; - last [3] = cp_time [3]; + glibtop_get_cpu (&cpu); - *usr = rint (Maximum * (float)(*usr) / total); - *nice = rint (Maximum * (float)(*nice) / total); - *sys = rint (Maximum * (float)(*sys) / total); - *free = rint (Maximum * (float)(*free) / total); - -#ifdef DEBUG - fprintf (stderr, "CPU: %d - %d - (%d, %d, %d, %d)\n", - Maximum, total, *usr, *sys, *nice, *free); -#endif + assert ((cpu.flags & needed_cpu_flags) == needed_cpu_flags); + + cp_time [0] = cpu.user; + cp_time [1] = cpu.nice; + cp_time [2] = cpu.sys; + cp_time [3] = cpu.idle; + + if (!init) { + memcpy (last, cp_time, sizeof (last)); + init = 1; + } + + usr = cp_time [0] - last [0]; + nice = cp_time [1] - last [1]; + sys = cp_time [2] - last [2]; + free = cp_time [3] - last [3]; + + total = usr + nice + sys + free; + + last [0] = cp_time [0]; + last [1] = cp_time [1]; + last [2] = cp_time [2]; + last [3] = cp_time [3]; + + if (!total) total = Maximum; + + usr = rint (Maximum * (float)(usr) / total); + nice = rint (Maximum * (float)(nice) / total); + sys = rint (Maximum * (float)(sys) / total); + free = rint (Maximum * (float)(free) / total); + + data [0] = usr; + data [1] = sys; + data [2] = nice; + data [3] = free; } void -GetMemory (int Maximum, int *used, int *shared, int *buffer, int *cached) +GetMemory (int Maximum, int data [4]) { - glibtop_mem mem; + int used, shared, buffer, cached; + + glibtop_mem mem; - glibtop_get_mem (&mem); + glibtop_get_mem (&mem); - assert ((mem.flags & needed_mem_flags) == needed_mem_flags); - -#ifdef DEBUG - fprintf (stderr, "Memory: %Lu - %Lu - %Lu - (%Lu, %Lu, %Lu)\n", - mem.total, mem.free, mem.used, mem.shared, mem.buffer, - mem.cached); -#endif - - mem.total = mem.free + mem.used + mem.shared + - mem.buffer + mem.cached; - - *used = rint (Maximum * (float)mem.used / mem.total); - *shared = rint (Maximum * (float)mem.shared / mem.total); - *buffer = rint (Maximum * (float)mem.buffer / mem.total); - *cached = rint (Maximum * (float)mem.cached / mem.total); - -#ifdef DEBUG - fprintf (stderr, "MEM: %d - %Lu - (%d, %d, %d, %d)\n", - Maximum, mem.total, *used, *shared, *buffer, *cached); -#endif + assert ((mem.flags & needed_mem_flags) == needed_mem_flags); + + mem.total = mem.free + mem.used + mem.shared + + mem.buffer + mem.cached; + + used = rint (Maximum * (float)mem.used / mem.total); + shared = rint (Maximum * (float)mem.shared / mem.total); + buffer = rint (Maximum * (float)mem.buffer / mem.total); + cached = rint (Maximum * (float)mem.cached / mem.total); + + data [0] = used; + data [1] = shared; + data [2] = buffer; + data [3] = cached; } void -GetSwap (int Maximum, int *used, int *free) +GetSwap (int Maximum, int data [2]) { - glibtop_swap swap; + int used, free; + + glibtop_swap swap; - glibtop_get_swap (&swap); + glibtop_get_swap (&swap); - assert ((swap.flags & needed_swap_flags) == needed_swap_flags); - -#ifdef DEBUG - fprintf (stderr, "Swap: %Lu - %Lu - %Lu\n", - swap.total, swap.free, swap.used); -#endif + assert ((swap.flags & needed_swap_flags) == needed_swap_flags); - swap.total = swap.free + swap.used; + swap.total = swap.free + swap.used; - if (swap.total == 0) { /* Avoid division by zero */ - *used = *free = 0; - return; - } + if (swap.total == 0) { /* Avoid division by zero */ + used = free = 0; + return; + } - *used = rint (Maximum * (float)swap.used / swap.total); - *free = rint (Maximum * (float)swap.free / swap.total); + used = rint (Maximum * (float)swap.used / swap.total); + free = rint (Maximum * (float)swap.free / swap.total); -#ifdef DEBUG - fprintf (stderr, "SWAP: %d - %Lu - (%d, %d)\n", - Maximum, swap.total, *used, *free); -#endif + data [0] = used; + data [1] = free; } diff --git a/multiload/linux-proc.h b/multiload/linux-proc.h index 84690a552..db75c566f 100644 --- a/multiload/linux-proc.h +++ b/multiload/linux-proc.h @@ -1,8 +1,8 @@ #ifndef LINUX_PROC_H__ #define LINUX_PROC_H__ -void GetLoad(int Maximum, int *usr, int *nice, int *sys, int *free); -void GetMemory(int Maximum, int *used, int *shared, int *buffer, int *cached); -void GetSwap (int Maximum, int *used, int *free); +void GetLoad (int Maximum, int data [4]); +void GetMemory (int Maximum, int data [4]); +void GetSwap (int Maximum, int data [2]); #endif diff --git a/multiload/load-graph.c b/multiload/load-graph.c new file mode 100644 index 000000000..831d4bc0b --- /dev/null +++ b/multiload/load-graph.c @@ -0,0 +1,354 @@ +#include <stdio.h> +#include <config.h> +#include <sys/stat.h> +#include <unistd.h> +#include <signal.h> +#include <dirent.h> +#include <string.h> +#include <time.h> +#include <config.h> +#include <gnome.h> +#include <gdk/gdkx.h> +#include <applet-widget.h> + +#include "global.h" + +static GtkWidget *load_graph_properties_init (GnomePropertyObject *object); +static void load_graph_properties_changed (GnomePropertyObject *object); +static void load_graph_properties_update (GnomePropertyObject *object); +static void load_graph_properties_load (GnomePropertyObject *object); +static void load_graph_properties_save (GnomePropertyObject *object); + +static GList *object_list = NULL; + +GnomePropertyDescriptor LoadGraphProperty_Descriptor = { + sizeof (LoadGraphProperties), + N_("Load Graph"), + load_graph_properties_init, + NULL, + load_graph_properties_update, + load_graph_properties_load, + load_graph_properties_save, + NULL, NULL, NULL, + load_graph_properties_changed, + NULL +}; + +static int +load_graph_draw (LoadGraph *g) +{ + gint i, j; + + g->get_data (g->width, g->data [0]); + + for (i=0; i < g->width-1; i++) + for (j=0; j < g->n; j++) + g->data [i+1][j] = g->odata [i][j]; + + /* Create GC if necessary. */ + if (!g->gc) { + g->gc = gdk_gc_new (g->disp->window); + gdk_gc_copy (g->gc, g->disp->style->white_gc); + } + + /* Allocate colors. */ + if (!g->colors_allocated) { + GdkColormap *colormap; + + colormap = gdk_window_get_colormap (g->disp->window); + for (i = 0; i < g->n; i++) { + g->colors [i] = g->prop_data->colors [i]; + gdk_color_alloc (colormap, &(g->colors [i])); + } + + g->colors_allocated = 1; + } + + /* Erase Rectangle */ + gdk_draw_rectangle (g->pixmap, + g->disp->style->black_gc, + TRUE, 0, 0, + g->disp->allocation.width, + g->disp->allocation.height); + + for (i = 0; i < g->width; i++) + g->pos [i] = g->height; + + for (j = 0; j < g->n; j++) { + gdk_gc_set_foreground (g->gc, &(g->colors [j])); + + for (i = 0; i < g->width; i++) { + gdk_draw_line (g->pixmap, g->gc, + g->width - i, g->pos[i], + g->width - i, g->pos[i] - g->data[i][j]); + + g->pos [i] -= g->data [i][j]; + } + } + + gdk_draw_pixmap (g->disp->window, + g->disp->style->fg_gc [GTK_WIDGET_STATE(g->disp)], + g->pixmap, + 0, 0, + 0, 0, + g->disp->allocation.width, + g->disp->allocation.height); + + for (i = 0; i < g->width; i++) + memcpy (g->odata [i], g->data [i], g->data_size); + + return TRUE; +} + +static gint +load_graph_configure (GtkWidget *widget, GdkEventConfigure *event, + gpointer data_ptr) +{ + LoadGraph *c = (LoadGraph *) data_ptr; + + c->pixmap = gdk_pixmap_new (widget->window, + widget->allocation.width, + widget->allocation.height, + gtk_widget_get_visual (c->disp)->depth); + gdk_draw_rectangle (c->pixmap, + widget->style->black_gc, + TRUE, 0,0, + widget->allocation.width, + widget->allocation.height); + gdk_draw_pixmap (widget->window, + c->disp->style->fg_gc [GTK_WIDGET_STATE(widget)], + c->pixmap, + 0, 0, + 0, 0, + c->disp->allocation.width, + c->disp->allocation.height); + return TRUE; +} + +static gint +load_graph_expose (GtkWidget *widget, GdkEventExpose *event, + gpointer data_ptr) +{ + LoadGraph *g = (LoadGraph *) data_ptr; + + gdk_draw_pixmap (widget->window, + widget->style->fg_gc [GTK_WIDGET_STATE(widget)], + g->pixmap, + event->area.x, event->area.y, + event->area.x, event->area.y, + event->area.width, event->area.height); + return FALSE; +} + +static GtkWidget * +load_graph_properties_init (GnomePropertyObject *object) +{ + GtkWidget *vb, *frame, *label, *entry, *button, *table, *spin; + LoadGraphProperties *prop_data = object->prop_data; + guint i; + + static const gchar *adj_data_texts [3] = { + N_("Speed:"), N_("Width:"), N_("Height:") + }; + + static glong adj_data_descr [3*8] = { + 1, 0, 0, 0, INT_MAX, 1, 256, 256, + 1, 0, 0, 0, INT_MAX, 1, 256, 256, + 1, 0, 0, 0, INT_MAX, 1, 256, 256 + }; + + vb = gtk_vbox_new (FALSE, 0); + gtk_container_border_width (GTK_CONTAINER (vb), GNOME_PAD_SMALL); + + frame = gnome_property_entry_colors (object, _("Colors"), prop_data->n, + prop_data->n, NULL, prop_data->colors, + prop_data->texts); + + gtk_container_add (GTK_CONTAINER (vb), frame); + + frame = gnome_property_entry_adjustments + (object, NULL, 3, 3, 2, NULL, adj_data_texts, + adj_data_descr, prop_data->adj_data); + + gtk_container_add (GTK_CONTAINER (vb), frame); + + return vb; +} + +static void +load_graph_properties_load (GnomePropertyObject *object) +{ + LoadGraphProperties *prop_data = object->prop_data; + gchar name [BUFSIZ], *temp; + guint i; + + if (!prop_data->colors) + prop_data->colors = g_new0 (GdkColor, prop_data->n); + + for (i=0; i < prop_data->n; i++) { + GdkColor *color = &(prop_data->colors [i]); + + sprintf (name, "multiload/%s/color%d=%s", + prop_data->name, i, prop_data->color_defs [i]); + + temp = gnome_config_get_string (name); + gdk_color_parse (temp, color); + g_free (temp); + } + + sprintf (name, "multiload/%s/speed=%ld", + prop_data->name, prop_data->adj_data [0]); + prop_data->adj_data [0] = gnome_config_get_int (name); + + sprintf (name, "multiload/%s/width=%ld", + prop_data->name, prop_data->adj_data [1]); + prop_data->adj_data [1] = gnome_config_get_int (name); + + sprintf (name, "multiload/%s/height=%ld", + prop_data->name, prop_data->adj_data [2]); + prop_data->adj_data [2] = gnome_config_get_int (name); + +} + +static void +load_graph_properties_save (GnomePropertyObject *object) +{ + LoadGraphProperties *prop_data = object->prop_data; + gchar name [BUFSIZ], temp [BUFSIZ]; + guint i; + + for (i=0; i < prop_data->n; i++) { + GdkColor *color = &(prop_data->colors [i]); + + sprintf (temp, "#%04x%04x%04x", + color->red, color->green, color->blue); + + sprintf (name, "multiload/%s/color%d", prop_data->name, i); + gnome_config_set_string (name, temp); + } + + sprintf (name, "multiload/%s/speed", prop_data->name); + gnome_config_set_int (name, prop_data->adj_data [0]); + + sprintf (name, "multiload/%s/width", prop_data->name); + gnome_config_set_int (name, prop_data->adj_data [1]); + + sprintf (name, "multiload/%s/height", prop_data->name); + gnome_config_set_int (name, prop_data->adj_data [2]); +} + +static void +load_graph_properties_changed (GnomePropertyObject *object) +{ + multiload_properties_changed (); +} + +static void +load_graph_properties_update (GnomePropertyObject *object) +{ + LoadGraphProperties *prop_data = object->prop_data; + GList *c; + + for (c = object_list; c; c = c->next) { + LoadGraph *g = (LoadGraph *) c->data; + + if (g->colors_allocated) { + GdkColormap *colormap; + + colormap = gdk_window_get_colormap (g->disp->window); + gdk_colormap_free_colors (colormap, g->colors, g->n); + + g->colors_allocated = 0; + } + + if (g->timer_index != -1) { + load_graph_stop (g); + + load_graph_start (g); + } + } +} + +LoadGraph * +load_graph_new (guint n, gchar *label, LoadGraphProperties *prop_data, + guint speed, guint width, guint height, + LoadGraphDataFunc get_data) +{ + GtkWidget *box; + LoadGraph *g; + guint i; + + g = g_new0 (LoadGraph, 1); + + g->n = n; + g->prop_data = prop_data; + + g->speed = speed; + g->width = width; + g->height = height; + + g->get_data = get_data; + + g->data = g_new0 (guint *, g->width); + g->odata = g_new0 (guint *, g->width); + + g->data_size = sizeof (guint) * g->n; + + g->colors = g_new0 (GdkColor, g->n); + + for (i = 0; i < g->width; i++) { + g->data [i] = g_malloc0 (g->data_size); + g->odata [i] = g_malloc0 (g->data_size); + } + + g->pos = g_new0 (guint, g->width); + + g->timer_index = -1; + + box = gtk_vbox_new (FALSE, FALSE); + gtk_widget_show (box); + + g->frame = gtk_frame_new (NULL); +#if 0 + gtk_frame_set_shadow_type (GTK_FRAME (g->frame), + cpu_props.look?GTK_SHADOW_OUT:GTK_SHADOW_IN); +#endif + + g->disp = gtk_drawing_area_new (); + gtk_signal_connect (GTK_OBJECT (g->disp), "expose_event", + (GtkSignalFunc)load_graph_expose, g); + gtk_signal_connect (GTK_OBJECT(g->disp), "configure_event", + (GtkSignalFunc)load_graph_configure, g); + gtk_widget_set_events (g->disp, GDK_EXPOSURE_MASK); + + gtk_box_pack_start_defaults (GTK_BOX (box), g->disp); + gtk_container_add (GTK_CONTAINER (g->frame), box); + + gtk_widget_set_usize (g->disp, g->width, g->height); + + object_list = g_list_append (object_list, g); + + gtk_widget_show_all (g->frame); + return g; +} + +void +load_graph_start (LoadGraph *g) +{ + if (g->timer_index != -1) + gtk_timeout_remove (g->timer_index); + + fprintf (stderr, "load_graph_start: %ld\n", g->prop_data->adj_data [0]); + + g->timer_index = gtk_timeout_add (g->prop_data->adj_data [0], + (GtkFunction)load_graph_draw, g); +} + +void +load_graph_stop (LoadGraph *g) +{ + if (g->timer_index != -1) + gtk_timeout_remove (g->timer_index); + + g->timer_index = -1; +} diff --git a/multiload/load-graph.h b/multiload/load-graph.h new file mode 100644 index 000000000..62d508b55 --- /dev/null +++ b/multiload/load-graph.h @@ -0,0 +1,41 @@ +#ifndef LOAD_GRAPH_H__ +#define LOAD_GRAPH_H__ + +typedef struct _LoadGraph LoadGraph; + +typedef void (*LoadGraphDataFunc) (int, int []); + +struct _LoadGraph { + guint n; + guint speed, width, height; + LoadGraphDataFunc get_data; + + LoadGraphProperties *prop_data; + + GdkColor *colors; + guint **data, **odata; + guint data_size; + guint *pos; + + gint colors_allocated; + GtkWidget *frame, *disp; + GdkPixmap *pixmap; + GdkGC *gc; + int timer_index; +}; + +/* Create new load graph. */ +LoadGraph * +load_graph_new (guint n, gchar *label, LoadGraphProperties *prop_data, + guint speed, guint width, guint height, + LoadGraphDataFunc get_data); + +/* Start load graph. */ +void +load_graph_start (LoadGraph *g); + +/* Stop load graph. */ +void +load_graph_stop (LoadGraph *g); + +#endif diff --git a/multiload/main.c b/multiload/main.c index 5e406ae47..ddb87c3e2 100644 --- a/multiload/main.c +++ b/multiload/main.c @@ -21,44 +21,137 @@ #include <gdk/gdkx.h> #include <applet-widget.h> -extern GtkWidget* make_cpuload_applet (const gchar *); -extern GtkWidget* make_memload_applet (const gchar *); -extern GtkWidget* make_swapload_applet (const gchar *); +#include "global.h" +FILE *logfile; +static const gchar *cpu_texts [4] = { + N_("User"), N_("Nice"), N_("System"), N_("Idle") +}; + +static const gchar *mem_texts [4] = { + N_("Other"), N_("Shared"), N_("Buffers"), N_("Free") +}; + +static const gchar *swap_texts [2] = { + N_("Used"), N_("Free") +}; + +static const gchar *cpu_color_defs [4] = { + "#ffffffff4fff", "#dfffdfffdfff", + "#afffafffafff", "#000000000000" +}; + +static const gchar *mem_color_defs [4] = { + "#bfffbfff4fff", "#efffefff4fff", + "#afffafffafff", "#00008fff0000" +}; + +static const gchar *swap_color_defs [4] = { + "#cfff5fff5fff", "#00008fff0000" +}; + + +#define ADD_PROPERTIES(x,y) multiload_property_object_list = g_list_append (multiload_property_object_list, gnome_property_object_new (& ## x ## Property_Descriptor, &multiload_properties. ## y ##)) + static GtkWidget * make_new_applet (const gchar *goad_id) { - if (!strcmp (goad_id, "multiload_memload_applet")) - return make_memload_applet (goad_id); - else if (!strcmp (goad_id, "multiload_swapload_applet")) - return make_swapload_applet (goad_id); - else if(!strcmp(goad_id, "multiload_cpuload_applet")) - return make_cpuload_applet (goad_id); + if (strstr (goad_id, "multiload_memload_applet")) + return make_memload_applet (goad_id); + else if (strstr (goad_id, "multiload_swapload_applet")) + return make_swapload_applet (goad_id); + else + return make_cpuload_applet (goad_id); +} + +/*when we get a command to start a new widget*/ +static GtkWidget * +applet_start_new_applet (const gchar *goad_id, const char **params, int nparams) +{ + return make_new_applet (goad_id); } int main (int argc, char **argv) { - const char *goad_id; + GList *list = NULL, *c; + const char *goad_id; + + /* Initialize the i18n stuff */ + bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE); - /* Initialize the i18n stuff */ - bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE); + logfile = fopen ("/var/tmp/test", "a"); + if (!logfile) + g_error ("Can't open logfile"); - applet_widget_init ("multiload_applet", VERSION, argc, argv, NULL, 0, - NULL); + list = g_list_prepend(list,"multiload_cpuload_applet"); + list = g_list_prepend(list,"multiload_memload_applet"); + list = g_list_prepend(list,"multiload_swapload_applet"); + applet_widget_init ("multiload_applet", VERSION, argc, argv, NULL, 0, NULL); + applet_factory_new("multiload_applet", NULL, applet_start_new_applet); + g_list_free(list); - applet_factory_new("multiload_applet", NULL, - (AppletFactoryActivator)make_cpuload_applet); + goad_id = goad_server_activation_id(); + if(!goad_id) + return 0; - goad_id = goad_server_activation_id(); - if(!goad_id) - make_new_applet("multiload_cpuload_applet"); - else - make_new_applet(goad_id); + /* Setup properties. */ - applet_widget_gtk_main (); + multiload_properties.cpuload.n = 4; + multiload_properties.cpuload.name = "cpuload"; + multiload_properties.cpuload.texts = cpu_texts; + multiload_properties.cpuload.color_defs = cpu_color_defs; + multiload_properties.cpuload.adj_data [0] = 500; + multiload_properties.cpuload.adj_data [1] = 40; + multiload_properties.cpuload.adj_data [2] = 40; + + multiload_properties.memload.n = 4; + multiload_properties.memload.name = "memload"; + multiload_properties.memload.texts = mem_texts; + multiload_properties.memload.color_defs = mem_color_defs; + multiload_properties.memload.adj_data [0] = 500; + multiload_properties.memload.adj_data [1] = 40; + multiload_properties.memload.adj_data [2] = 40; + + multiload_properties.swapload.n = 2; + multiload_properties.swapload.name = "swapload"; + multiload_properties.swapload.texts = swap_texts; + multiload_properties.swapload.color_defs = swap_color_defs; + multiload_properties.swapload.adj_data [0] = 500; + multiload_properties.swapload.adj_data [1] = 40; + multiload_properties.swapload.adj_data [2] = 40; + + /* Add property objects. */ + + ADD_PROPERTIES (LoadGraph, cpuload); + ADD_PROPERTIES (LoadGraph, memload); + ADD_PROPERTIES (LoadGraph, swapload); + + /* This looks really ugly, but libgnomeui is already freezed so I can't + * add new function there ... */ + + c = g_list_nth (multiload_property_object_list, 0); + ((GnomePropertyObject *) c->data)->label = gtk_label_new (_("CPU Load")); + gtk_widget_ref (((GnomePropertyObject *) c->data)->label); + + c = g_list_nth (multiload_property_object_list, 1); + ((GnomePropertyObject *) c->data)->label = gtk_label_new (_("Memory Load")); + gtk_widget_ref (((GnomePropertyObject *) c->data)->label); + + c = g_list_nth (multiload_property_object_list, 2); + ((GnomePropertyObject *) c->data)->label = gtk_label_new (_("Swap Load")); + gtk_widget_ref (((GnomePropertyObject *) c->data)->label); + + /* Read properties. */ + multiload_init_properties (); + + /* Only do if factory wasn't requested. */ + if(strcmp(goad_id, "multiload_applet")) + make_new_applet(goad_id); + + applet_widget_gtk_main (); - return 0; + return 0; } diff --git a/multiload/memload.c b/multiload/memload.c index 93298bf1d..e3e135de1 100644 --- a/multiload/memload.c +++ b/multiload/memload.c @@ -21,224 +21,15 @@ #include <gdk/gdkx.h> #include <applet-widget.h> -#include "linux-proc.h" -#include "properties-mem.h" -#include "memload.h" - -memload_properties mem_props; - -static guchar udata [128]; -static guchar oudata [128]; -static guchar sdata [128]; -static guchar osdata [128]; -static guchar bdata [128]; -static guchar obdata [128]; -static guchar cdata [128]; -static guchar ocdata [128]; - -static int -draw (gpointer data_ptr) -{ - int used=0, shared=0, buffer=0, cached=0, i; - Memload *c = (Memload *) data_ptr; - - GetMemory (mem_props.height, &used, &shared, &buffer, &cached); - - for (i=0; i < mem_props.width-1; i++) { - udata [i+1] = oudata [i]; - sdata [i+1] = osdata [i]; - bdata [i+1] = obdata [i]; - cdata [i+1] = ocdata [i]; - } - udata [0] = used; - sdata [0] = shared; - bdata [0] = buffer; - cdata [0] = cached; - - /* Erase Rectangle */ - gdk_draw_rectangle (c->pixmap, - c->disp->style->black_gc, - TRUE, 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - - gdk_gc_set_foreground (c->gc, &c->ucolor); - for (i=0; i < mem_props.width; i++) { - if (udata[i]) - gdk_draw_line (c->pixmap, - c->gc, - i, mem_props.height, - i, mem_props.height - udata[i]); - } - - gdk_gc_set_foreground (c->gc, &c->scolor); - for (i=0; i < mem_props.width; i++) { - if (sdata[i]) - gdk_draw_line (c->pixmap, - c->gc, - i, (mem_props.height - udata[i]), - i, ((mem_props.height - - (udata[i] + sdata[i])))); - } - - gdk_gc_set_foreground (c->gc, &c->bcolor); - for (i=0; i < mem_props.width; i++) { - if (bdata[i]) - gdk_draw_line (c->pixmap, - c->gc, - i, (mem_props.height - - (udata[i] + sdata[i])), - i, (mem_props.height - - (udata[i] + sdata[i] + bdata[i]))); - } - - gdk_gc_set_foreground (c->gc, &c->ccolor); - for (i=0; i < mem_props.width; i++) { - if (cdata[i]) - gdk_draw_line (c->pixmap, - c->gc, - i, (mem_props.height - - (udata[i] + sdata[i] + bdata[i])), - i, (mem_props.height - - (udata [i] + sdata[i] + - bdata [i] + cdata[i]))); - } - - gdk_draw_pixmap (c->disp->window, - c->disp->style->fg_gc [GTK_WIDGET_STATE(c->disp)], - c->pixmap, - 0, 0, - 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - - for (i=0; i < mem_props.width; i++) { - oudata[i] = udata[i]; - osdata[i] = sdata[i]; - obdata[i] = bdata[i]; - ocdata[i] = cdata[i]; - } - return TRUE; -} - -static gint -memload_configure (GtkWidget *widget, GdkEventConfigure *event, - gpointer data_ptr) -{ - Memload *c = (Memload *) data_ptr; - - c->pixmap = gdk_pixmap_new (widget->window, - widget->allocation.width, - widget->allocation.height, - gtk_widget_get_visual (c->disp)->depth); - gdk_draw_rectangle (c->pixmap, - widget->style->black_gc, - TRUE, 0,0, - widget->allocation.width, - widget->allocation.height); - gdk_draw_pixmap (widget->window, - c->disp->style->fg_gc [GTK_WIDGET_STATE(widget)], - c->pixmap, - 0, 0, - 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - return TRUE; -} - -static gint -memload_expose (GtkWidget *widget, GdkEventExpose *event, - gpointer data_ptr) -{ - Memload *c = (Memload *) data_ptr; - - gdk_draw_pixmap (widget->window, - widget->style->fg_gc [GTK_WIDGET_STATE(widget)], - c->pixmap, - event->area.x, event->area.y, - event->area.x, event->area.y, - event->area.width, event->area.height); - return FALSE; -} - -static Memload * -memload_new (void) -{ - GtkWidget *box; - Memload *c; - - c = g_malloc (sizeof (Memload)); - memset (c, 0, sizeof (Memload)); - - c->timer_index = -1; - - box = gtk_vbox_new (FALSE, FALSE); - gtk_widget_show (box); - - c->frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (c->frame), - mem_props.look?GTK_SHADOW_OUT:GTK_SHADOW_IN); - - c->disp = gtk_drawing_area_new (); - gtk_signal_connect (GTK_OBJECT (c->disp), "expose_event", - (GtkSignalFunc)memload_expose, c); - gtk_signal_connect (GTK_OBJECT(c->disp), "configure_event", - (GtkSignalFunc)memload_configure, c); - gtk_widget_set_events (c->disp, GDK_EXPOSURE_MASK); - - gtk_box_pack_start_defaults (GTK_BOX (box), c->disp); - gtk_container_add (GTK_CONTAINER (c->frame), box); - - gtk_widget_set_usize (c->disp, mem_props.width, mem_props.height); - - memload_start_timer (c); - - gtk_widget_show_all (c->frame); - return c; -} - -void -memload_start_timer (Memload *c) -{ - if (c->timer_index != -1) - gtk_timeout_remove (c->timer_index); - - c->timer_index = - gtk_timeout_add (mem_props.speed, (GtkFunction)draw, c); -} - -void -memload_setup_colors (Memload *c) -{ - GdkColormap *colormap; - - colormap = gtk_widget_get_colormap (c->disp); - - gdk_color_parse (mem_props.ucolor, &c->ucolor); - gdk_color_alloc (colormap, &c->ucolor); - - gdk_color_parse (mem_props.scolor, &c->scolor); - gdk_color_alloc (colormap, &c->scolor); - - gdk_color_parse (mem_props.bcolor, &c->bcolor); - gdk_color_alloc (colormap, &c->bcolor); - - gdk_color_parse (mem_props.ccolor, &c->ccolor); - gdk_color_alloc (colormap, &c->ccolor); -} - -static void -create_gc (Memload *c) -{ - c->gc = gdk_gc_new (c->disp->window); - gdk_gc_copy (c->gc, c->disp->style->white_gc); -} +#include "global.h" static gint applet_save_session (GtkWidget *widget, char *privcfgpath, char *globcfgpath, gpointer data) { +#if 0 save_mem_properties (privcfgpath, &mem_props); +#endif return FALSE; } @@ -246,36 +37,34 @@ applet_save_session (GtkWidget *widget, char *privcfgpath, GtkWidget * make_memload_applet (const gchar *goad_id) { - GtkWidget *applet; - GtkWidget *label; - Memload *memload; + GtkWidget *applet; + LoadGraph *g; - /* create a new applet_widget */ - applet = applet_widget_new(goad_id); - /* in the rare case that the communication with the panel - failed, error out */ - if (!applet) - g_error ("Can't create applet!\n"); + /* create a new applet_widget */ + applet = applet_widget_new(goad_id); + /* in the rare case that the communication with the panel + failed, error out */ + if (!applet) + g_error ("Can't create applet!\n"); - load_mem_properties (APPLET_WIDGET(applet)->privcfgpath, &mem_props); +#if 0 + load_mem_properties (APPLET_WIDGET(applet)->privcfgpath, &mem_props); +#endif - memload = memload_new (); - applet_widget_add (APPLET_WIDGET(applet), memload->frame); - gtk_widget_show (applet); + g = load_graph_new (4, N_("Memory Load"), &multiload_properties.memload, + 500, 40, 40, GetMemory); - create_gc (memload); - memload_setup_colors (memload); + applet_widget_add (APPLET_WIDGET(applet), g->frame); + gtk_widget_show (applet); - gtk_signal_connect (GTK_OBJECT(applet),"save_session", - GTK_SIGNAL_FUNC(applet_save_session), - NULL); + load_graph_start (g); - applet_widget_register_stock_callback (APPLET_WIDGET(applet), - "properties", - GNOME_STOCK_MENU_PROP, - _("Properties..."), - mem_properties, - memload); + applet_widget_register_stock_callback (APPLET_WIDGET(applet), + "properties", + GNOME_STOCK_MENU_PROP, + _("Properties..."), + multiload_properties_cb, + g); - return applet; + return applet; } diff --git a/multiload/memload.h b/multiload/memload.h deleted file mode 100644 index 2c3d6c989..000000000 --- a/multiload/memload.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef MEMLOAD_H__ -#define MEMLOAD_H__ - -typedef struct _Memload Memload; -struct _Memload { - GtkWidget *frame, *disp; - GdkPixmap *pixmap; - GdkGC *gc; - GdkColor ucolor, scolor; - GdkColor bcolor, ccolor; - int timer_index; -}; - -void memload_setup_colors (Memload *memload); -void memload_start_timer (Memload *memload); - -#endif diff --git a/multiload/properties-cpu.c b/multiload/properties-cpu.c deleted file mode 100644 index 8c0cc500b..000000000 --- a/multiload/properties-cpu.c +++ /dev/null @@ -1,244 +0,0 @@ -/* GNOME cpuload/memload panel applet - properties dialog - * (C) 1997 The Free Software Foundation - * - * Authors: Tim P. Gerla - * Martin Baulig - * - */ - -#include <stdio.h> -#include <string.h> -#include <config.h> -#include <gnome.h> - -#include <assert.h> - -#include "cpuload.h" -#include "properties-cpu.h" - -static GtkWidget *propbox=NULL; -static cpuload_properties temp_props; - -extern cpuload_properties cpu_props; - -void -load_cpu_properties (char *path, cpuload_properties *prop) -{ - gnome_config_push_prefix (path); - prop->ucolor = gnome_config_get_string ("cpu/ucolor=#20b2aa"); - prop->scolor = gnome_config_get_string ("cpu/scolor=#188982"); - prop->speed = gnome_config_get_int ("cpu/speed=2000"); - prop->height = gnome_config_get_int ("cpu/height=40"); - prop->width = gnome_config_get_int ("cpu/width=40"); - prop->look = gnome_config_get_bool ("cpu/look=1"); - gnome_config_pop_prefix (); -} - -void -save_cpu_properties (char *path, cpuload_properties *prop) -{ - gnome_config_push_prefix (path); - gnome_config_set_string ("cpu/ucolor", prop->ucolor); - gnome_config_set_string ("cpu/scolor", prop->scolor); - gnome_config_set_int ("cpu/speed", prop->speed); - gnome_config_set_int ("cpu/height", prop->height); - gnome_config_set_int ("cpu/width", prop->width); - gnome_config_set_bool ("cpu/look", prop->look); - gnome_config_pop_prefix (); - gnome_config_sync (); - gnome_config_drop_all (); -} - -static void -ucolor_changed_cb (GnomeColorPicker *widget) -{ - guint8 r,g,b; - - gnome_color_picker_get_i8 - (widget, &r, &g, &b, NULL); - - sprintf (temp_props.ucolor, "#%02x%02x%02x", r, g, b); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -scolor_changed_cb (GnomeColorPicker *widget) -{ - guint8 r,g,b; - - gnome_color_picker_get_i8 - (widget, &r, &g, &b, NULL); - - sprintf (temp_props.scolor, "#%02x%02x%02x", r, g, b); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -height_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.height = - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin)); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -width_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.width = - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin)); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -freq_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.speed = gtk_spin_button_get_value_as_float - (GTK_SPIN_BUTTON(spin)) * 1000; - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static GtkWidget * -create_frame (void) -{ - GtkWidget *label; - GtkWidget *box, *color, *size, *speed; - GtkWidget *height, *width, *freq; - GtkObject *height_a, *width_a, *freq_a; - - GtkWidget *ucolor_gcs, *scolor_gcs; - int ur,ug,ub, sr,sg,sb; - - sscanf (temp_props.ucolor, "#%02x%02x%02x", &ur, &ug, &ub); - sscanf (temp_props.scolor, "#%02x%02x%02x", &sr, &sg, &sb); - - box = gtk_vbox_new (5, TRUE); - color = gtk_hbox_new (5, TRUE); - size = gtk_hbox_new (5, TRUE); - speed = gtk_hbox_new (5, TRUE); - gtk_container_set_border_width (GTK_CONTAINER(box), 5); - - - ucolor_gcs = gnome_color_picker_new (); - scolor_gcs = gnome_color_picker_new (); - - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (ucolor_gcs), - ur, ug, ub, 255); - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (scolor_gcs), - sr, sg, sb, 255); - gtk_signal_connect (GTK_OBJECT (ucolor_gcs), "color_set", - GTK_SIGNAL_FUNC (ucolor_changed_cb), NULL); - gtk_signal_connect (GTK_OBJECT (scolor_gcs), "color_set", - GTK_SIGNAL_FUNC (scolor_changed_cb), NULL); - - label = gtk_label_new (_("User Load")); - gtk_box_pack_start_defaults (GTK_BOX (color), label); - gtk_box_pack_start_defaults (GTK_BOX (color), ucolor_gcs); - - label = gtk_label_new (_("System Load")); - gtk_box_pack_start_defaults (GTK_BOX(color), label); - gtk_box_pack_start_defaults (GTK_BOX(color), scolor_gcs); - - label = gtk_label_new (_("Applet Height")); - height_a = gtk_adjustment_new - (temp_props.height, 0.5, 128, 1, 8, 8); - height = gtk_spin_button_new - (GTK_ADJUSTMENT (height_a), 1, 0); - gtk_box_pack_start_defaults (GTK_BOX (size), label); - gtk_box_pack_start_defaults (GTK_BOX (size), height); - - label = gtk_label_new (_("Width")); - width_a = gtk_adjustment_new - (temp_props.width, 0.5, 128, 1, 8, 8); - width = gtk_spin_button_new (GTK_ADJUSTMENT (width_a), 1, 0); - gtk_box_pack_start_defaults (GTK_BOX (size), label); - gtk_box_pack_start_defaults (GTK_BOX (size), width); - - gtk_signal_connect (GTK_OBJECT (height_a), "value_changed", - GTK_SIGNAL_FUNC (height_cb), height); - gtk_signal_connect (GTK_OBJECT (height), "changed", - GTK_SIGNAL_FUNC (height_cb), height); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (height), - GTK_UPDATE_ALWAYS); - gtk_signal_connect (GTK_OBJECT (width_a), "value_changed", - GTK_SIGNAL_FUNC (width_cb), width); - gtk_signal_connect (GTK_OBJECT (width), "changed", - GTK_SIGNAL_FUNC (width_cb), width); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (width), - GTK_UPDATE_ALWAYS); - - label = gtk_label_new (_("Update Frequency")); - g_print ("%d %d\n", temp_props.speed, temp_props.speed/1000); - freq_a = gtk_adjustment_new - ((float)temp_props.speed/1000, 0.1, 60, 0.1, 5, 5); - freq = gtk_spin_button_new (GTK_ADJUSTMENT (freq_a), 0.1, 1); - gtk_box_pack_start (GTK_BOX (speed), label, TRUE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (speed), freq, TRUE, TRUE, 0); - - gtk_signal_connect (GTK_OBJECT (freq_a), "value_changed", - GTK_SIGNAL_FUNC (freq_cb), freq); - gtk_signal_connect (GTK_OBJECT (freq), "changed", - GTK_SIGNAL_FUNC (freq_cb), freq); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (freq), - GTK_UPDATE_ALWAYS); - - gtk_box_pack_start_defaults (GTK_BOX (box), color); - gtk_box_pack_start_defaults (GTK_BOX (box), size); - gtk_box_pack_start_defaults (GTK_BOX (box), speed); - - gtk_widget_show_all (box); - return box; -} - -static void -apply_cb (GtkWidget *widget, gint dummy, gpointer data) -{ - Cpuload *c = (Cpuload *) data; - - memcpy (&cpu_props, &temp_props, sizeof (cpuload_properties)); - - cpuload_setup_colors (c); - cpuload_start_timer (c); - - /*FIXME: this won't make the window smaller*/ - gtk_widget_set_usize (c->disp, cpu_props.width, cpu_props.height); -} - -static gint -destroy_cb (GtkWidget *widget, gpointer data) -{ - propbox = NULL; - return FALSE; -} - -void -cpu_properties (AppletWidget *applet, gpointer data) -{ - GtkWidget *frame, *label; - - if (propbox) { - gdk_window_raise (propbox->window); - return; - } - - memcpy (&temp_props, &cpu_props, sizeof (cpuload_properties)); - - propbox = gnome_property_box_new (); - gtk_window_set_title - (GTK_WINDOW(&GNOME_PROPERTY_BOX(propbox)->dialog.window), - _("CPULoad Settings")); - - frame = create_frame (); - label = gtk_label_new (_("General")); - gtk_widget_show (frame); - gtk_notebook_append_page - (GTK_NOTEBOOK(GNOME_PROPERTY_BOX(propbox)->notebook), - frame, label); - - gtk_signal_connect (GTK_OBJECT (propbox), "apply", - GTK_SIGNAL_FUNC (apply_cb), data); - - gtk_signal_connect (GTK_OBJECT (propbox), "destroy", - GTK_SIGNAL_FUNC (destroy_cb), data); - - gtk_widget_show_all (propbox); -} diff --git a/multiload/properties-cpu.h b/multiload/properties-cpu.h deleted file mode 100644 index 2aaa8cead..000000000 --- a/multiload/properties-cpu.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PROPERTIES_CPU_H__ -#define PROPERTIES_CPU_H__ - -#include <applet-widget.h> - -typedef struct -{ - gchar *ucolor; - gchar *scolor; - guint speed, height, width; - gboolean look; -} cpuload_properties; - -void cpu_properties (AppletWidget *applet, gpointer data); -void load_cpu_properties (char *path, cpuload_properties *prop); -void save_cpu_properties (char *path, cpuload_properties *prop); - -#endif diff --git a/multiload/properties-mem.c b/multiload/properties-mem.c deleted file mode 100644 index dcc07bdd5..000000000 --- a/multiload/properties-mem.c +++ /dev/null @@ -1,296 +0,0 @@ -/* GNOME cpuload/memload panel applet - properties dialog - * (C) 1997 The Free Software Foundation - * - * Authors: Tim P. Gerla - * Martin Baulig - * - */ - -#include <stdio.h> -#include <string.h> -#include <config.h> -#include <gnome.h> - -#include <assert.h> - -#include "memload.h" -#include "properties-mem.h" - -static GtkWidget *propbox=NULL; -static memload_properties temp_props; - -/* extern GtkWidget *disp; */ -extern memload_properties mem_props; - -void -load_mem_properties (char *path, memload_properties *prop) -{ - gnome_config_push_prefix (path); - prop->ucolor = gnome_config_get_string ("mem/ucolor=#20b2aa"); - prop->scolor = gnome_config_get_string ("mem/scolor=#188982"); - prop->bcolor = gnome_config_get_string ("mem/bcolor=#ff0000"); - prop->ccolor = gnome_config_get_string ("mem/ccolor=#00ff00"); - prop->speed = gnome_config_get_int ("mem/speed=2000"); - prop->height = gnome_config_get_int ("mem/height=40"); - prop->width = gnome_config_get_int ("mem/width=40"); - prop->look = gnome_config_get_bool ("mem/look=1"); - gnome_config_pop_prefix (); -} - -void -save_mem_properties (char *path, memload_properties *prop) -{ - gnome_config_push_prefix (path); - gnome_config_set_string ("mem/ucolor", prop->ucolor); - gnome_config_set_string ("mem/scolor", prop->scolor); - gnome_config_set_string ("mem/bcolor", prop->bcolor); - gnome_config_set_string ("mem/ccolor", prop->ccolor); - gnome_config_set_int ("mem/speed", prop->speed); - gnome_config_set_int ("mem/height", prop->height); - gnome_config_set_int ("mem/width", prop->width); - gnome_config_set_bool ("mem/look", prop->look); - gnome_config_pop_prefix (); - gnome_config_sync (); - gnome_config_drop_all (); -} - -static void -ucolor_changed_cb (GnomeColorPicker *widget) -{ - guint8 r,g,b; - - gnome_color_picker_get_i8 - (widget, &r, &g, &b, NULL); - - sprintf (temp_props.ucolor, "#%02x%02x%02x", r, g, b); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -scolor_changed_cb (GnomeColorPicker *widget) -{ - guint8 r,g,b; - - gnome_color_picker_get_i8 - (widget, &r, &g, &b, NULL); - - sprintf (temp_props.scolor, "#%02x%02x%02x", r, g, b); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} -static void -bcolor_changed_cb (GnomeColorPicker *widget) -{ - guint8 r,g,b; - - gnome_color_picker_get_i8 - (widget, &r, &g, &b, NULL); - - sprintf (temp_props.bcolor, "#%02x%02x%02x", r, g, b); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -ccolor_changed_cb (GnomeColorPicker *widget) -{ - guint8 r,g,b; - - gnome_color_picker_get_i8 - (widget, &r, &g, &b, NULL); - - sprintf (temp_props.ccolor, "#%02x%02x%02x", r, g, b); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -height_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.height = - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin)); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -width_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.width = - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin)); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -freq_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.speed = gtk_spin_button_get_value_as_float - (GTK_SPIN_BUTTON(spin)) * 1000; - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static GtkWidget * -create_frame (void) -{ - GtkWidget *label; - GtkWidget *box, *color_a, *color_b, *size, *speed; - GtkWidget *height, *width, *freq; - GtkObject *height_a, *width_a, *freq_a; - - GtkWidget *ucolor_gcs, *scolor_gcs; - GtkWidget *bcolor_gcs, *ccolor_gcs; - int ur,ug,ub, sr,sg,sb, br,bg,bb, cr,cg,cb; - - sscanf (temp_props.ucolor, "#%02x%02x%02x", &ur, &ug, &ub); - sscanf (temp_props.scolor, "#%02x%02x%02x", &sr, &sg, &sb); - sscanf (temp_props.bcolor, "#%02x%02x%02x", &br, &bg, &bb); - sscanf (temp_props.ccolor, "#%02x%02x%02x", &cr, &cg, &cb); - - box = gtk_vbox_new (5, TRUE); - color_a = gtk_hbox_new (5, TRUE); - color_b = gtk_hbox_new (5, TRUE); - size = gtk_hbox_new (5, TRUE); - speed = gtk_hbox_new (5, TRUE); - gtk_container_set_border_width (GTK_CONTAINER(box), 5); - - ucolor_gcs = gnome_color_picker_new (); - scolor_gcs = gnome_color_picker_new (); - bcolor_gcs = gnome_color_picker_new (); - ccolor_gcs = gnome_color_picker_new (); - - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (ucolor_gcs), - ur, ug, ub, 255); - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (scolor_gcs), - sr, sg, sb, 255); - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (bcolor_gcs), - br, bg, bb, 255); - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (ccolor_gcs), - cr, cg, cb, 255); - - - label = gtk_label_new (_("Used Memory")); - gtk_box_pack_start_defaults (GTK_BOX (color_a), label); - gtk_box_pack_start_defaults (GTK_BOX (color_a), ucolor_gcs); - - label = gtk_label_new (_("Shared Memory")); - gtk_box_pack_start_defaults (GTK_BOX (color_a), label); - gtk_box_pack_start_defaults (GTK_BOX (color_a), scolor_gcs); - - label = gtk_label_new (_("Buffered Memory")); - gtk_box_pack_start_defaults (GTK_BOX (color_b), label); - gtk_box_pack_start_defaults (GTK_BOX (color_b), bcolor_gcs); - - label = gtk_label_new (_("Cached Memory")); - gtk_box_pack_start_defaults (GTK_BOX (color_b), label); - gtk_box_pack_start_defaults (GTK_BOX (color_b), ccolor_gcs); - - gtk_signal_connect (GTK_OBJECT (ucolor_gcs), "color_set", - GTK_SIGNAL_FUNC (ucolor_changed_cb), NULL); - gtk_signal_connect (GTK_OBJECT (scolor_gcs), "color_set", - GTK_SIGNAL_FUNC (scolor_changed_cb), NULL); - gtk_signal_connect (GTK_OBJECT (bcolor_gcs), "color_set", - GTK_SIGNAL_FUNC (bcolor_changed_cb), NULL); - gtk_signal_connect (GTK_OBJECT (ccolor_gcs), "color_set", - GTK_SIGNAL_FUNC (ccolor_changed_cb), NULL); - - label = gtk_label_new (_("Applet Height")); - height_a = gtk_adjustment_new - (temp_props.height, 0.5, 128, 1, 8, 8); - height = gtk_spin_button_new - (GTK_ADJUSTMENT (height_a), 1, 0); - gtk_box_pack_start_defaults (GTK_BOX (size), label); - gtk_box_pack_start_defaults (GTK_BOX (size), height); - - label = gtk_label_new (_("Width")); - width_a = gtk_adjustment_new - (temp_props.width, 0.5, 128, 1, 8, 8); - width = gtk_spin_button_new (GTK_ADJUSTMENT (width_a), 1, 0); - gtk_box_pack_start_defaults (GTK_BOX (size), label); - gtk_box_pack_start_defaults (GTK_BOX (size), width); - - gtk_signal_connect (GTK_OBJECT (height_a), "value_changed", - GTK_SIGNAL_FUNC (height_cb), height); - gtk_signal_connect (GTK_OBJECT (height), "changed", - GTK_SIGNAL_FUNC (height_cb), height); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (height), - GTK_UPDATE_ALWAYS); - gtk_signal_connect (GTK_OBJECT (width_a), "value_changed", - GTK_SIGNAL_FUNC (width_cb), width); - gtk_signal_connect (GTK_OBJECT (width), "changed", - GTK_SIGNAL_FUNC (width_cb), width); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (width), - GTK_UPDATE_ALWAYS); - - label = gtk_label_new (_("Update Frequency")); - g_print ("%d %d\n", temp_props.speed, temp_props.speed/1000); - freq_a = gtk_adjustment_new - ((float)temp_props.speed/1000, 0.1, 60, 0.1, 5, 5); - freq = gtk_spin_button_new (GTK_ADJUSTMENT (freq_a), 0.1, 1); - gtk_box_pack_start (GTK_BOX (speed), label, TRUE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (speed), freq, TRUE, TRUE, 0); - - gtk_signal_connect (GTK_OBJECT (freq_a), "value_changed", - GTK_SIGNAL_FUNC (freq_cb), freq); - gtk_signal_connect (GTK_OBJECT (freq), "changed", - GTK_SIGNAL_FUNC (freq_cb), freq); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (freq), - GTK_UPDATE_ALWAYS); - - gtk_box_pack_start_defaults (GTK_BOX (box), color_a); - gtk_box_pack_start_defaults (GTK_BOX (box), color_b); - gtk_box_pack_start_defaults (GTK_BOX (box), size); - gtk_box_pack_start_defaults (GTK_BOX (box), speed); - - gtk_widget_show_all (box); - return box; -} - -static void -apply_cb (GtkWidget *widget, gint dummy, gpointer data) -{ - Memload *c = (Memload *) data; - - memcpy (&mem_props, &temp_props, sizeof (memload_properties)); - - memload_setup_colors (c); - memload_start_timer (c); - - /*FIXME: this won't make the window smaller*/ - gtk_widget_set_usize (c->disp, mem_props.width, mem_props.height); -} - -static gint -destroy_cb (GtkWidget *widget, gpointer data) -{ - propbox = NULL; - return FALSE; -} - -void -mem_properties (AppletWidget *applet, gpointer data) -{ - GtkWidget *frame, *label; - - if (propbox) { - gdk_window_raise (propbox->window); - return; - } - - memcpy (&temp_props, &mem_props, sizeof (memload_properties)); - - propbox = gnome_property_box_new (); - gtk_window_set_title - (GTK_WINDOW(&GNOME_PROPERTY_BOX(propbox)->dialog.window), - _("MemLoad Settings")); - - frame = create_frame (); - label = gtk_label_new (_("General")); - gtk_widget_show (frame); - gtk_notebook_append_page - (GTK_NOTEBOOK(GNOME_PROPERTY_BOX(propbox)->notebook), - frame, label); - - gtk_signal_connect (GTK_OBJECT (propbox), "apply", - GTK_SIGNAL_FUNC (apply_cb), data); - - gtk_signal_connect (GTK_OBJECT (propbox), "destroy", - GTK_SIGNAL_FUNC (destroy_cb), data); - - gtk_widget_show_all (propbox); -} diff --git a/multiload/properties-mem.h b/multiload/properties-mem.h deleted file mode 100644 index b0a2fa133..000000000 --- a/multiload/properties-mem.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef PROPERTIES_MEM_H__ -#define PROPERTIES_MEM_H__ - -#include <applet-widget.h> - -typedef struct -{ - gchar *ucolor; - gchar *scolor; - gchar *bcolor; - gchar *ccolor; - guint speed, height, width; - gboolean look; -} memload_properties; - -void mem_properties (AppletWidget *applet, gpointer data); -void load_mem_properties (char *path, memload_properties *prop); -void save_mem_properties (char *path, memload_properties *prop); - -#endif diff --git a/multiload/properties-swap.c b/multiload/properties-swap.c deleted file mode 100644 index ff6456dc7..000000000 --- a/multiload/properties-swap.c +++ /dev/null @@ -1,246 +0,0 @@ -/* GNOME cpuload/memload panel applet - properties dialog - * (C) 1997 The Free Software Foundation - * - * Authors: Tim P. Gerla - * Martin Baulig - * - */ - -#include <stdio.h> -#include <string.h> -#include <config.h> -#include <gnome.h> - -#include <assert.h> - -#include "swapload.h" -#include "properties-swap.h" - -static GtkWidget *propbox=NULL; -static swapload_properties temp_props; - -extern swapload_properties swap_props; - -void -load_swap_properties (char *path, swapload_properties *prop) -{ - gnome_config_push_prefix (path); - prop->ucolor = gnome_config_get_string ("swap/ucolor=#ff0000"); - prop->fcolor = gnome_config_get_string ("swap/fcolor=#000000"); - prop->speed = gnome_config_get_int ("swap/speed=2000"); - prop->height = gnome_config_get_int ("swap/height=40"); - prop->width = gnome_config_get_int ("swap/width=40"); - prop->look = gnome_config_get_bool ("swap/look=1"); - gnome_config_pop_prefix (); -} - -void -save_swap_properties (char *path, swapload_properties *prop) -{ - gnome_config_push_prefix (path); - gnome_config_set_string ("swap/ucolor", prop->ucolor); - gnome_config_set_string ("swap/fcolor", prop->fcolor); - gnome_config_set_int ("swap/speed", prop->speed); - gnome_config_set_int ("swap/height", prop->height); - gnome_config_set_int ("swap/width", prop->width); - gnome_config_set_bool ("swap/look", prop->look); - gnome_config_pop_prefix (); - gnome_config_sync (); - gnome_config_drop_all (); -} - -static void -ucolor_changed_cb (GnomeColorPicker *widget) -{ - guint8 r,g,b; - - gnome_color_picker_get_i8 - (widget, &r, &g, &b, NULL); - - sprintf (temp_props.ucolor, "#%02x%02x%02x", r, g, b); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -fcolor_changed_cb (GnomeColorPicker *widget) -{ - guint8 r,g,b; - - gnome_color_picker_get_i8 - (widget, &r, &g, &b, NULL); - - sprintf (temp_props.fcolor, "#%02x%02x%02x", r, g, b); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -height_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.height = - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin)); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -width_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.width = - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin)); - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static void -freq_cb (GtkWidget *widget, GtkWidget *spin) -{ - temp_props.speed = gtk_spin_button_get_value_as_float - (GTK_SPIN_BUTTON(spin)) * 1000; - gnome_property_box_changed (GNOME_PROPERTY_BOX(propbox)); -} - -static GtkWidget * -create_frame (void) -{ - GtkWidget *label; - GtkWidget *box, *color, *size, *speed; - GtkWidget *height, *width, *freq; - GtkObject *height_a, *width_a, *freq_a; - - GtkWidget *ucolor_gcs, *fcolor_gcs; - int ur,ug,ub, sr,sg,sb; - - sscanf (temp_props.ucolor, "#%02x%02x%02x", &ur, &ug, &ub); - sscanf (temp_props.fcolor, "#%02x%02x%02x", &sr, &sg, &sb); - - box = gtk_vbox_new (5, TRUE); - color = gtk_hbox_new (5, TRUE); - size = gtk_hbox_new (5, TRUE); - speed = gtk_hbox_new (5, TRUE); - gtk_container_set_border_width (GTK_CONTAINER(box), 5); - - - ucolor_gcs = gnome_color_picker_new (); - fcolor_gcs = gnome_color_picker_new (); - - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (ucolor_gcs), - ur, ug, ub, 255); - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (fcolor_gcs), - sr, sg, sb, 255); - - - label = gtk_label_new (_("Used Swap")); - gtk_box_pack_start_defaults (GTK_BOX (color), label); - gtk_box_pack_start_defaults (GTK_BOX (color), ucolor_gcs); - - label = gtk_label_new (_("Free Swap")); - gtk_box_pack_start_defaults (GTK_BOX(color), label); - gtk_box_pack_start_defaults (GTK_BOX(color), fcolor_gcs); - - gtk_signal_connect (GTK_OBJECT (ucolor_gcs), "color_set", - GTK_SIGNAL_FUNC (ucolor_changed_cb), NULL); - gtk_signal_connect (GTK_OBJECT (fcolor_gcs), "color_set", - GTK_SIGNAL_FUNC (fcolor_changed_cb), NULL); - - label = gtk_label_new (_("Applet Height")); - height_a = gtk_adjustment_new - (temp_props.height, 0.5, 128, 1, 8, 8); - height = gtk_spin_button_new - (GTK_ADJUSTMENT (height_a), 1, 0); - gtk_box_pack_start_defaults (GTK_BOX (size), label); - gtk_box_pack_start_defaults (GTK_BOX (size), height); - - label = gtk_label_new (_("Width")); - width_a = gtk_adjustment_new - (temp_props.width, 0.5, 128, 1, 8, 8); - width = gtk_spin_button_new (GTK_ADJUSTMENT (width_a), 1, 0); - gtk_box_pack_start_defaults (GTK_BOX (size), label); - gtk_box_pack_start_defaults (GTK_BOX (size), width); - - gtk_signal_connect (GTK_OBJECT (height_a), "value_changed", - GTK_SIGNAL_FUNC (height_cb), height); - gtk_signal_connect (GTK_OBJECT (height), "changed", - GTK_SIGNAL_FUNC (height_cb), height); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (height), - GTK_UPDATE_ALWAYS); - gtk_signal_connect (GTK_OBJECT (width_a), "value_changed", - GTK_SIGNAL_FUNC (width_cb), width); - gtk_signal_connect (GTK_OBJECT (width), "changed", - GTK_SIGNAL_FUNC (width_cb), width); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (width), - GTK_UPDATE_ALWAYS); - - label = gtk_label_new (_("Update Frequency")); - g_print ("%d %d\n", temp_props.speed, temp_props.speed/1000); - freq_a = gtk_adjustment_new - ((float)temp_props.speed/1000, 0.1, 60, 0.1, 5, 5); - freq = gtk_spin_button_new (GTK_ADJUSTMENT (freq_a), 0.1, 1); - gtk_box_pack_start (GTK_BOX (speed), label, TRUE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (speed), freq, TRUE, TRUE, 0); - - gtk_signal_connect (GTK_OBJECT (freq_a), "value_changed", - GTK_SIGNAL_FUNC (freq_cb), freq); - gtk_signal_connect (GTK_OBJECT (freq), "changed", - GTK_SIGNAL_FUNC (freq_cb), freq); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (freq), - GTK_UPDATE_ALWAYS); - - gtk_box_pack_start_defaults (GTK_BOX (box), color); - gtk_box_pack_start_defaults (GTK_BOX (box), size); - gtk_box_pack_start_defaults (GTK_BOX (box), speed); - - gtk_widget_show_all (box); - return box; -} - -static void -apply_cb (GtkWidget *widget, gint dummy, gpointer data) -{ - Swapload *c = (Swapload *) data; - - memcpy (&swap_props, &temp_props, sizeof (swapload_properties)); - - swapload_setup_colors (c); - swapload_start_timer (c); - - /*FIXME: this won't make the window smaller*/ - gtk_widget_set_usize (c->disp, swap_props.width, swap_props.height); -} - -static gint -destroy_cb (GtkWidget *widget, gpointer data) -{ - propbox = NULL; - return FALSE; -} - -void -swap_properties (AppletWidget *applet, gpointer data) -{ - GtkWidget *frame, *label; - - if (propbox) { - gdk_window_raise (propbox->window); - return; - } - - memcpy (&temp_props, &swap_props, sizeof (swapload_properties)); - - propbox = gnome_property_box_new (); - gtk_window_set_title - (GTK_WINDOW(&GNOME_PROPERTY_BOX(propbox)->dialog.window), - _("SwapLoad Settings")); - - frame = create_frame (); - label = gtk_label_new (_("General")); - gtk_widget_show (frame); - gtk_notebook_append_page - (GTK_NOTEBOOK(GNOME_PROPERTY_BOX(propbox)->notebook), - frame, label); - - gtk_signal_connect (GTK_OBJECT (propbox), "apply", - GTK_SIGNAL_FUNC (apply_cb), data); - - gtk_signal_connect (GTK_OBJECT (propbox), "destroy", - GTK_SIGNAL_FUNC (destroy_cb), data); - - gtk_widget_show_all (propbox); -} diff --git a/multiload/properties-swap.h b/multiload/properties-swap.h deleted file mode 100644 index ca4778919..000000000 --- a/multiload/properties-swap.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PROPERTIES_SWAP_H__ -#define PROPERTIES_SWAP_H__ - -#include <applet-widget.h> - -typedef struct -{ - gchar *ucolor; - gchar *fcolor; - guint speed, height, width; - gboolean look; -} swapload_properties; - -void swap_properties (AppletWidget *applet, gpointer data); -void load_swap_properties (char *path, swapload_properties *prop); -void save_swap_properties (char *path, swapload_properties *prop); - -#endif diff --git a/multiload/properties.c b/multiload/properties.c new file mode 100644 index 000000000..c9ce29245 --- /dev/null +++ b/multiload/properties.c @@ -0,0 +1,84 @@ +#include "global.h" + +GList *multiload_property_object_list = NULL; + +MultiLoadProperties multiload_properties; + +static GtkWidget *win = NULL; + +void +multiload_properties_cb (AppletWidget *widget, gpointer data) +{ + multiload_show_properties (); +} + +void +multiload_properties_close (void) +{ + gnome_property_object_list_walk (multiload_property_object_list, + GNOME_PROPERTY_ACTION_DISCARD_TEMP); + + win = NULL; +} + +void +multiload_properties_apply (void) +{ + gnome_property_object_list_walk (multiload_property_object_list, + GNOME_PROPERTY_ACTION_APPLY); + + gnome_property_object_list_walk (multiload_property_object_list, + GNOME_PROPERTY_ACTION_SAVE_TEMP); + + gnome_property_object_list_walk (multiload_property_object_list, + GNOME_PROPERTY_ACTION_SAVE); + + gnome_property_object_list_walk (multiload_property_object_list, + GNOME_PROPERTY_ACTION_UPDATE); + + gnome_property_object_list_walk (multiload_property_object_list, + GNOME_PROPERTY_ACTION_LOAD_TEMP); +} + +void +multiload_properties_changed (void) +{ + gnome_property_box_changed (GNOME_PROPERTY_BOX (win)); +} + +void +multiload_show_properties (void) +{ + GList *c; + + if (win) { + gdk_window_raise (win->window); + + return; + } + + win = gnome_property_box_new (); + + for (c = multiload_property_object_list; c; c = c->next) { + GnomePropertyObject *object = c->data; + + gnome_property_object_register + (GNOME_PROPERTY_BOX (win), object); + } + + gnome_property_object_list_walk (multiload_property_object_list, + GNOME_PROPERTY_ACTION_LOAD_TEMP); + + gtk_signal_connect (GTK_OBJECT (win), "apply", + GTK_SIGNAL_FUNC(multiload_properties_apply), NULL); + + gtk_signal_connect (GTK_OBJECT (win), "destroy", + GTK_SIGNAL_FUNC(multiload_properties_close), NULL); + + gtk_widget_show_all (win); +} + +void +multiload_init_properties (void) +{ +} diff --git a/multiload/properties.h b/multiload/properties.h new file mode 100644 index 000000000..7c9189c96 --- /dev/null +++ b/multiload/properties.h @@ -0,0 +1,37 @@ +#ifndef __PROPERTIES_H__ +#define __PROPERTIES_H__ + +#include <property-entries.h> + +BEGIN_GNOME_DECLS + +typedef struct _MultiLoadProperties MultiLoadProperties; + +typedef struct _LoadGraphProperties LoadGraphProperties; + +struct _LoadGraphProperties { + guint n; + const gchar *name; + const gchar **texts; + const gchar **color_defs; + GdkColor *colors; + glong adj_data [3]; +}; + +struct _MultiLoadProperties { + LoadGraphProperties cpuload, memload, swapload; +}; + +extern GList *multiload_property_object_list; + +extern MultiLoadProperties multiload_properties; + +void multiload_properties_apply (void); +void multiload_properties_close (void); +void multiload_properties_changed (void); +void multiload_show_properties (void); +void multiload_init_properties (void); + +END_GNOME_DECLS + +#endif diff --git a/multiload/property-entries.c b/multiload/property-entries.c new file mode 100644 index 000000000..95c1c9cbd --- /dev/null +++ b/multiload/property-entries.c @@ -0,0 +1,135 @@ +#include <global.h> + +/* ======================================================================= + * Multiple adjustments. + * ======================================================================= + */ + +typedef struct +{ + gint num_items, total_size; + glong *values, *temp_values; +} AdjustmentBlockProperties; + +typedef struct +{ + glong *value; + GtkAdjustment *adjustment; + GnomePropertyObject *object; +} AdjustmentCbData; + +static void +_property_entry_adjustments_load_temp (GnomePropertyObject *object) +{ + AdjustmentBlockProperties *prop_ptr = object->prop_data; + + memcpy (prop_ptr->temp_values, prop_ptr->values, prop_ptr->total_size); +} + +static gint +_property_entry_adjustments_save_temp (GnomePropertyObject *object) +{ + AdjustmentBlockProperties *prop_ptr = object->prop_data; + + memcpy (prop_ptr->values, prop_ptr->temp_values, prop_ptr->total_size); + + return FALSE; +} + +static void +_property_entry_adjustment_changed_cb (GtkWidget *widget, + AdjustmentCbData *cb_data) +{ + *(cb_data->value) = cb_data->adjustment->value; + + gnome_property_object_changed (cb_data->object); +} + +GtkWidget * +gnome_property_entry_adjustments (GnomePropertyObject *object, + const gchar *label, gint num_items, + gint columns, gint internal_columns, + gint *table_pos, const gchar *texts [], + glong *data_ptr, glong *values) +{ + GtkWidget *frame, *table; + GnomePropertyDescriptor *descriptor; + GnomePropertyObject *entry_object; + AdjustmentBlockProperties *prop_ptr; + glong *temp_values; + gint rows, i; + + frame = gtk_frame_new (_(label)); + + rows = (num_items < columns) ? 1 : (num_items+columns-1) / columns; + + temp_values = g_memdup (values, num_items * sizeof (glong)); + + table = gtk_table_new (rows, columns * internal_columns, TRUE); + gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD << 2); + gtk_container_border_width (GTK_CONTAINER (table), GNOME_PAD_SMALL); + + for (i = 0; i < num_items; i++) { + glong *data = &(data_ptr [i*8]); + AdjustmentCbData *cb_data; + GtkObject *adjustment; + GtkWidget *spin, *lb; + gint row, col; + + spin = gtk_spin_button_new (NULL, data [0], data [1]); + adjustment = gtk_adjustment_new (data [2], data[3], data [4], + data [5], data[6], data [7]); + gtk_spin_button_set_adjustment + (GTK_SPIN_BUTTON (spin), GTK_ADJUSTMENT (adjustment)); + gtk_spin_button_set_value + (GTK_SPIN_BUTTON (spin), values [i]); + + cb_data = g_new0 (AdjustmentCbData, 1); + cb_data->adjustment = GTK_ADJUSTMENT (adjustment); + cb_data->value = &(temp_values [i]); + cb_data->object = object; + + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + _property_entry_adjustment_changed_cb, + cb_data); + + col = table_pos ? table_pos [i] : i; + row = col / columns; + col %= columns; + col *= internal_columns; + + lb = gtk_label_new (_(texts [i])); + gtk_misc_set_alignment (GTK_MISC (lb), 0.0, 0.5); + + gtk_table_attach_defaults + (GTK_TABLE (table), lb, col, col+internal_columns-1, + row, row+1); + + gtk_table_attach_defaults + (GTK_TABLE (table), spin, col+internal_columns-1, + col+internal_columns, row, row+1); + } + + gtk_container_add (GTK_CONTAINER (frame), table); + + descriptor = g_new0 (GnomePropertyDescriptor, 1); + descriptor->size = sizeof (AdjustmentBlockProperties); + + descriptor->load_temp_func = _property_entry_adjustments_load_temp; + descriptor->save_temp_func = _property_entry_adjustments_save_temp; + + prop_ptr = g_new0 (AdjustmentBlockProperties, 1); + prop_ptr->total_size = num_items * sizeof (glong); + prop_ptr->num_items = num_items; + prop_ptr->temp_values = temp_values; + prop_ptr->values = values; + + entry_object = gnome_property_object_new (descriptor, prop_ptr); + entry_object->user_data = object; + + object->object_list = g_list_append (object->object_list, entry_object); + + g_free (descriptor); + + return frame; +} diff --git a/multiload/property-entries.h b/multiload/property-entries.h new file mode 100644 index 000000000..8e89e19b6 --- /dev/null +++ b/multiload/property-entries.h @@ -0,0 +1,41 @@ +/* WARNING ____ IMMATURE API ____ liable to change */ + +/* property-entries.h - Property entries. + + Copyright (C) 1998 Martin Baulig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#ifndef __PROPERTY_ENTRIES_H__ +#define __PROPERTY_ENTRIES_H__ + +#include <config.h> +#include <gnome.h> + +BEGIN_GNOME_DECLS + +/* Adjustment block. */ +GtkWidget * +gnome_property_entry_adjustments (GnomePropertyObject *object, + const gchar *label, gint num_items, + gint columns, gint internal_columns, + gint *table_pos, const gchar *texts [], + glong *data_ptr, glong *values); + +END_GNOME_DECLS + +#endif diff --git a/multiload/swapload.c b/multiload/swapload.c index 1fdf67d53..72ce935e7 100644 --- a/multiload/swapload.c +++ b/multiload/swapload.c @@ -21,185 +21,15 @@ #include <gdk/gdkx.h> #include <applet-widget.h> -#include "linux-proc.h" -#include "properties-swap.h" -#include "swapload.h" - -swapload_properties swap_props; - -static guchar udata [128]; -static guchar oudata [128]; -static guchar fdata [128]; -static guchar ofdata [128]; - -static int -draw (gpointer data_ptr) -{ - int used=0, free=0, i; - Swapload *c = (Swapload *) data_ptr; - - GetSwap (swap_props.height, &used, &free ); - - for (i=0; i < swap_props.width-1; i++) { - udata [i+1] = oudata [i]; - fdata [i+1] = ofdata [i]; - } - udata [0] = used; - fdata [0] = free; - - /* Erase Rectangle */ - gdk_draw_rectangle (c->pixmap, - c->disp->style->black_gc, - TRUE, 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - - gdk_gc_set_foreground (c->gc, &c->ucolor); - for (i=0; i < swap_props.width; i++) { - if (udata[i]) - gdk_draw_line (c->pixmap, - c->gc, - i, swap_props.height, - i, (swap_props.height - udata[i])); - } - - gdk_gc_set_foreground (c->gc, &c->fcolor); - for (i=0; i < swap_props.width; i++) { - if (fdata[i]) - gdk_draw_line (c->pixmap, - c->gc, - i, (swap_props.height - udata[i]), - i, ((swap_props.height - udata[i]) - - fdata[i])); - } - - gdk_draw_pixmap (c->disp->window, - c->disp->style->fg_gc [GTK_WIDGET_STATE(c->disp)], - c->pixmap, - 0, 0, - 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - - for (i=0; i < swap_props.width; i++) { - oudata[i] = udata[i]; - ofdata[i] = fdata[i]; - } - return TRUE; -} - -static gint -swapload_configure (GtkWidget *widget, GdkEventConfigure *event, - gpointer data_ptr) -{ - Swapload *c = (Swapload *) data_ptr; - - c->pixmap = gdk_pixmap_new (widget->window, - widget->allocation.width, - widget->allocation.height, - gtk_widget_get_visual (c->disp)->depth); - gdk_draw_rectangle (c->pixmap, - widget->style->black_gc, - TRUE, 0,0, - widget->allocation.width, - widget->allocation.height); - gdk_draw_pixmap (widget->window, - c->disp->style->fg_gc [GTK_WIDGET_STATE(widget)], - c->pixmap, - 0, 0, - 0, 0, - c->disp->allocation.width, - c->disp->allocation.height); - return TRUE; -} - -static gint -swapload_expose (GtkWidget *widget, GdkEventExpose *event, - gpointer data_ptr) -{ - Swapload *c = (Swapload *) data_ptr; - - gdk_draw_pixmap (widget->window, - widget->style->fg_gc [GTK_WIDGET_STATE(widget)], - c->pixmap, - event->area.x, event->area.y, - event->area.x, event->area.y, - event->area.width, event->area.height); - return FALSE; -} - -static Swapload * -swapload_new (void) -{ - GtkWidget *box; - Swapload *c; - - c = g_malloc (sizeof (Swapload)); - memset (c, 0, sizeof (Swapload)); - - c->timer_index = -1; - - box = gtk_vbox_new (FALSE, FALSE); - gtk_widget_show (box); - - c->frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (c->frame), - swap_props.look?GTK_SHADOW_OUT:GTK_SHADOW_IN); - - c->disp = gtk_drawing_area_new (); - gtk_signal_connect (GTK_OBJECT (c->disp), "expose_event", - (GtkSignalFunc)swapload_expose, c); - gtk_signal_connect (GTK_OBJECT(c->disp), "configure_event", - (GtkSignalFunc)swapload_configure, c); - gtk_widget_set_events (c->disp, GDK_EXPOSURE_MASK); - - gtk_box_pack_start_defaults (GTK_BOX (box), c->disp); - gtk_container_add (GTK_CONTAINER (c->frame), box); - - gtk_widget_set_usize (c->disp, swap_props.width, swap_props.height); - - swapload_start_timer (c); - - gtk_widget_show_all (c->frame); - return c; -} - -void -swapload_start_timer (Swapload *c) -{ - if (c->timer_index != -1) - gtk_timeout_remove (c->timer_index); - - c->timer_index = - gtk_timeout_add (swap_props.speed, (GtkFunction)draw, c); -} - -void -swapload_setup_colors (Swapload *c) -{ - GdkColormap *colormap; - - colormap = gtk_widget_get_colormap (c->disp); - - gdk_color_parse (swap_props.ucolor, &c->ucolor); - gdk_color_alloc (colormap, &c->ucolor); - - gdk_color_parse (swap_props.fcolor, &c->fcolor); - gdk_color_alloc (colormap, &c->fcolor); -} - -static void -create_gc (Swapload *c) -{ - c->gc = gdk_gc_new (c->disp->window); - gdk_gc_copy (c->gc, c->disp->style->white_gc); -} +#include "global.h" static gint applet_save_session (GtkWidget *widget, char *privcfgpath, char *globcfgpath, gpointer data) { +#if 0 save_swap_properties (privcfgpath, &swap_props); +#endif return FALSE; } @@ -207,36 +37,34 @@ applet_save_session (GtkWidget *widget, char *privcfgpath, GtkWidget * make_swapload_applet (const gchar *goad_id) { - GtkWidget *applet; - GtkWidget *label; - Swapload *swapload; + GtkWidget *applet; + LoadGraph *g; - /* create a new applet_widget */ - applet = applet_widget_new (goad_id); - /* in the rare case that the communication with the panel - failed, error out */ - if (!applet) - g_error ("Can't create applet!\n"); + /* create a new applet_widget */ + applet = applet_widget_new (goad_id); + /* in the rare case that the communication with the panel + failed, error out */ + if (!applet) + g_error ("Can't create applet!\n"); - load_swap_properties (APPLET_WIDGET(applet)->privcfgpath, &swap_props); +#if 0 + load_swap_properties (APPLET_WIDGET(applet)->privcfgpath, &swap_props); +#endif - swapload = swapload_new (); - applet_widget_add (APPLET_WIDGET(applet), swapload->frame); - gtk_widget_show (applet); + g = load_graph_new (2, N_("Swap Load"), &multiload_properties.swapload, + 500, 40, 40, GetSwap); - create_gc (swapload); - swapload_setup_colors (swapload); + applet_widget_add (APPLET_WIDGET(applet), g->frame); + gtk_widget_show (applet); - gtk_signal_connect (GTK_OBJECT(applet),"save_session", - GTK_SIGNAL_FUNC(applet_save_session), - NULL); + load_graph_start (g); - applet_widget_register_stock_callback (APPLET_WIDGET(applet), - "properties", - GNOME_STOCK_MENU_PROP, - _("Properties..."), - swap_properties, - swapload); + applet_widget_register_stock_callback (APPLET_WIDGET(applet), + "properties", + GNOME_STOCK_MENU_PROP, + _("Properties..."), + multiload_properties_cb, + g); - return applet; + return applet; } diff --git a/multiload/swapload.h b/multiload/swapload.h deleted file mode 100644 index 2cd80e800..000000000 --- a/multiload/swapload.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SWAPLOAD_H__ -#define SWAPLOAD_H__ - -typedef struct _Swapload Swapload; -struct _Swapload { - GtkWidget *frame, *disp; - GdkPixmap *pixmap; - GdkGC *gc; - GdkColor ucolor, fcolor; - int timer_index; -}; - -void swapload_setup_colors (Swapload *swapload); -void swapload_start_timer (Swapload *swapload); - -#endif |