From 19cf719782152bba59cd8e4442dcfdeaa3daf75a Mon Sep 17 00:00:00 2001 From: raveit65 Date: Sun, 30 Aug 2020 18:04:32 +0200 Subject: multiload: improve code-style - tab to spaces - fix some indents --- multiload/autoscaler.c | 58 +- multiload/autoscaler.h | 14 +- multiload/load-graph.c | 26 +- multiload/load-graph.h | 6 +- multiload/main.c | 817 +++++++++++++------------- multiload/netspeed.c | 60 +- multiload/properties.c | 1481 ++++++++++++++++++++++++------------------------ 7 files changed, 1233 insertions(+), 1229 deletions(-) diff --git a/multiload/autoscaler.c b/multiload/autoscaler.c index 39eab7db..735b2713 100644 --- a/multiload/autoscaler.c +++ b/multiload/autoscaler.c @@ -6,46 +6,46 @@ /* i wish i could have used C99 initializers instead of writing this function */ void autoscaler_init(AutoScaler *that, unsigned interval, unsigned floor) { - that->update_interval = interval; - that->floor = floor; - that->max = 0; - that->count = 0; - that->last_update = 0; - that->sum = 0.0f; - that->last_average = 0.0f; + that->update_interval = interval; + that->floor = floor; + that->max = 0; + that->count = 0; + that->last_update = 0; + that->sum = 0.0f; + that->last_average = 0.0f; } unsigned autoscaler_get_max(AutoScaler *that, unsigned current) { - time_t now; + time_t now; - that->sum += current; - that->count++; - time(&now); + that->sum += current; + that->count++; + time(&now); - if((float)difftime(now, that->last_update) > that->update_interval) - { - float new_average = that->sum / that->count; - float average; + if((float)difftime(now, that->last_update) > that->update_interval) + { + float new_average = that->sum / that->count; + float average; - if(new_average < that->last_average) - average = ((that->last_average * 0.5f) + new_average) / 1.5f; - else - average = new_average; + if(new_average < that->last_average) + average = ((that->last_average * 0.5f) + new_average) / 1.5f; + else + average = new_average; - that->max = average * 1.2f; + that->max = average * 1.2f; - that->sum = 0.0f; - that->count = 0; - that->last_update = now; - that->last_average = average; - } + that->sum = 0.0f; + that->count = 0; + that->last_update = now; + that->last_average = average; + } - that->max = MAX(that->max, current); - that->max = MAX(that->max, that->floor); + that->max = MAX(that->max, current); + that->max = MAX(that->max, that->floor); #if 0 - printf("%p max = %u, current = %u, last_average = %f\n", that, that->max, current, that->last_average); + printf("%p max = %u, current = %u, last_average = %f\n", that, that->max, current, that->last_average); #endif - return that->max; + return that->max; } diff --git a/multiload/autoscaler.h b/multiload/autoscaler.h index 11ca588b..d0ae4cd6 100644 --- a/multiload/autoscaler.h +++ b/multiload/autoscaler.h @@ -8,13 +8,13 @@ typedef struct _AutoScaler AutoScaler; struct _AutoScaler { - /* const */ unsigned update_interval; - /* const */ unsigned floor; - unsigned max; - unsigned count; - time_t last_update; - float sum; - float last_average; + /* const */ unsigned update_interval; + /* const */ unsigned floor; + unsigned max; + unsigned count; + time_t last_update; + float sum; + float last_average; }; diff --git a/multiload/load-graph.c b/multiload/load-graph.c index 07a425f4..953dc5b2 100644 --- a/multiload/load-graph.c +++ b/multiload/load-graph.c @@ -30,17 +30,17 @@ static void shift_right(LoadGraph *g) { - unsigned i; - int* last_data; + unsigned i; + int* last_data; - /* data[g->draw_width - 1] becomes data[0] */ - last_data = g->data[g->draw_width - 1]; + /* data[g->draw_width - 1] becomes data[0] */ + last_data = g->data[g->draw_width - 1]; - /* data[i+1] = data[i] */ - for(i = g->draw_width - 1; i != 0; --i) - g->data[i] = g->data[i - 1]; + /* data[i+1] = data[i] */ + for(i = g->draw_width - 1; i != 0; --i) + g->data[i] = g->data[i - 1]; - g->data[0] = last_data; + g->data[0] = last_data; } @@ -179,7 +179,7 @@ load_graph_draw (LoadGraph *g) /* this is Load graph */ else { - guint maxload = 1; + guint maxload = 1; for (i = 0; i < g->draw_width; i++) { g->pos [i] = g->draw_height - 1; @@ -219,7 +219,7 @@ load_graph_draw (LoadGraph *g) spacing = ((double) g->draw_height/load) * (k+1); cairo_move_to (cr, 0.5, spacing); cairo_line_to (cr, g->draw_width-0.5, spacing); - } + } cairo_stroke (cr); } @@ -233,12 +233,12 @@ static gboolean load_graph_update (LoadGraph *g) { if (g->data == NULL) - return TRUE; + return TRUE; shift_right(g); if (g->tooltip_update) - multiload_applet_tooltip_update(g); + multiload_applet_tooltip_update(g); g->get_data (g->draw_height, g->data [0], g); @@ -252,7 +252,7 @@ load_graph_unalloc (LoadGraph *g) guint i; if (!g->allocated) - return; + return; for (i = 0; i < g->draw_width; i++) { diff --git a/multiload/load-graph.h b/multiload/load-graph.h index a45542c1..76effcd6 100644 --- a/multiload/load-graph.h +++ b/multiload/load-graph.h @@ -6,8 +6,8 @@ /* Create new load graph. */ G_GNUC_INTERNAL LoadGraph * load_graph_new (MultiloadApplet *multiload, guint n, const gchar *label, - guint id, guint speed, guint size, gboolean visible, - const gchar *name, LoadGraphDataFunc get_data); + guint id, guint speed, guint size, gboolean visible, + const gchar *name, LoadGraphDataFunc get_data); /* Start load graph. */ G_GNUC_INTERNAL void @@ -20,5 +20,5 @@ load_graph_stop (LoadGraph *g); /* free load graph */ G_GNUC_INTERNAL void load_graph_unalloc (LoadGraph *g); - + #endif diff --git a/multiload/main.c b/multiload/main.c index e0d50a31..259bf0b5 100644 --- a/multiload/main.c +++ b/multiload/main.c @@ -31,23 +31,23 @@ static void about_cb (GtkAction *action, - MultiloadApplet *ma) + MultiloadApplet *ma) { const gchar * const authors[] = { - "Martin Baulig ", - "Todd Kulesza ", - "Benoît Dejean ", - "Davyd Madeley ", - NULL + "Martin Baulig ", + "Todd Kulesza ", + "Benoît Dejean ", + "Davyd Madeley ", + NULL }; const gchar* documenters[] = { - "Chee Bin HOH ", - N_("Sun GNOME Documentation Team "), - N_("MATE Documentation Team"), - NULL + "Chee Bin HOH ", + N_("Sun GNOME Documentation Team "), + N_("MATE Documentation Team"), + NULL }; #ifdef ENABLE_NLS @@ -57,39 +57,36 @@ about_cb (GtkAction *action, #endif gtk_show_about_dialog (NULL, - "title", _("About System Monitor"), - "version", VERSION, - "copyright", _("Copyright \xc2\xa9 1999-2005 Free Software Foundation and others\n" - "Copyright \xc2\xa9 2012-2020 MATE developers"), - "comments", _("A system load monitor capable of displaying graphs " - "for CPU, ram, and swap space use, plus network " - "traffic."), - "authors", authors, - "documenters", documenters, - "translator-credits", _("translator-credits"), - "logo-icon-name", "utilities-system-monitor", - NULL); + "title", _("About System Monitor"), + "version", VERSION, + "copyright", _("Copyright \xc2\xa9 1999-2005 Free Software Foundation and others\n" + "Copyright \xc2\xa9 2012-2020 MATE developers"), + "comments", _("A system load monitor capable of displaying graphs " + "for CPU, ram, and swap space use, plus network " + "traffic."), + "authors", authors, + "documenters", documenters, + "translator-credits", _("translator-credits"), + "logo-icon-name", "utilities-system-monitor", + NULL); } static void help_cb (GtkAction *action, - MultiloadApplet *ma) + MultiloadApplet *ma) { - - GError *error = NULL; - - gtk_show_uri_on_window (NULL, - "help:mate-multiload", - gtk_get_current_event_time (), - &error); - - if (error) { /* FIXME: the user needs to see this */ - g_warning ("help error: %s\n", error->message); - g_error_free (error); - error = NULL; - } - - + GError *error = NULL; + + gtk_show_uri_on_window (NULL, + "help:mate-multiload", + gtk_get_current_event_time (), + &error); + + if (error) { /* FIXME: the user needs to see this */ + g_warning ("help error: %s\n", error->message); + g_error_free (error); + error = NULL; + } } /* run the full-scale system process monitor */ @@ -97,483 +94,483 @@ help_cb (GtkAction *action, static void start_procman (MultiloadApplet *ma) { - GError *error = NULL; - GDesktopAppInfo *appinfo; - gchar *monitor; - GdkAppLaunchContext *launch_context; - GdkDisplay *display; - GAppInfo *app_info; - GdkScreen *screen; - - g_return_if_fail (ma != NULL); - - monitor = g_settings_get_string (ma->settings, "system-monitor"); - if (monitor == NULL) - monitor = g_strdup ("mate-system-monitor.desktop"); - - screen = gtk_widget_get_screen (GTK_WIDGET (ma->applet)); - appinfo = g_desktop_app_info_new (monitor); - if (appinfo) { - GdkAppLaunchContext *context; - display = gdk_screen_get_display (screen); - context = gdk_display_get_app_launch_context (display); - gdk_app_launch_context_set_screen (context, screen); - g_app_info_launch (G_APP_INFO (appinfo), NULL, G_APP_LAUNCH_CONTEXT (context), &error); - g_object_unref (context); - g_object_unref (appinfo); - } - else { - app_info = g_app_info_create_from_commandline ("mate-system-monitor", - _("Start system-monitor"), - G_APP_INFO_CREATE_NONE, - &error); - - if (!error) { - display = gdk_screen_get_display (screen); - launch_context = gdk_display_get_app_launch_context (display); - gdk_app_launch_context_set_screen (launch_context, screen); - g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error); - - g_object_unref (launch_context); - } - } - g_free (monitor); - - if (error) { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _("There was an error executing '%s': %s"), - "mate-system-monitor", - error->message); - - g_signal_connect (dialog, "response", - G_CALLBACK (gtk_widget_destroy), - NULL); - - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_window_set_screen (GTK_WINDOW (dialog), screen); - - gtk_widget_show (dialog); - - g_error_free (error); - } + GError *error = NULL; + GDesktopAppInfo *appinfo; + gchar *monitor; + GdkAppLaunchContext *launch_context; + GdkDisplay *display; + GAppInfo *app_info; + GdkScreen *screen; + + g_return_if_fail (ma != NULL); + + monitor = g_settings_get_string (ma->settings, "system-monitor"); + if (monitor == NULL) + monitor = g_strdup ("mate-system-monitor.desktop"); + + screen = gtk_widget_get_screen (GTK_WIDGET (ma->applet)); + appinfo = g_desktop_app_info_new (monitor); + if (appinfo) { + GdkAppLaunchContext *context; + display = gdk_screen_get_display (screen); + context = gdk_display_get_app_launch_context (display); + gdk_app_launch_context_set_screen (context, screen); + g_app_info_launch (G_APP_INFO (appinfo), NULL, G_APP_LAUNCH_CONTEXT (context), &error); + g_object_unref (context); + g_object_unref (appinfo); + } + else { + app_info = g_app_info_create_from_commandline ("mate-system-monitor", + _("Start system-monitor"), + G_APP_INFO_CREATE_NONE, + &error); + + if (!error) { + display = gdk_screen_get_display (screen); + launch_context = gdk_display_get_app_launch_context (display); + gdk_app_launch_context_set_screen (launch_context, screen); + g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error); + + g_object_unref (launch_context); + } + } + g_free (monitor); + + if (error) { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _("There was an error executing '%s': %s"), + "mate-system-monitor", + error->message); + + g_signal_connect (dialog, "response", + G_CALLBACK (gtk_widget_destroy), + NULL); + + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_window_set_screen (GTK_WINDOW (dialog), screen); + + gtk_widget_show (dialog); + + g_error_free (error); + } } static void start_procman_cb (GtkAction *action, - MultiloadApplet *ma) + MultiloadApplet *ma) { - start_procman (ma); + start_procman (ma); } static void multiload_change_size_cb(MatePanelApplet *applet, gint size, gpointer data) { - MultiloadApplet *ma = (MultiloadApplet *)data; + MultiloadApplet *ma = (MultiloadApplet *)data; - multiload_applet_refresh(ma); + multiload_applet_refresh(ma); - return; + return; } static void multiload_change_orient_cb(MatePanelApplet *applet, gint arg1, gpointer data) { - MultiloadApplet *ma = data; - multiload_applet_refresh((MultiloadApplet *)data); - gtk_widget_show (GTK_WIDGET (ma->applet)); - return; + MultiloadApplet *ma = data; + multiload_applet_refresh((MultiloadApplet *)data); + gtk_widget_show (GTK_WIDGET (ma->applet)); + return; } static void multiload_destroy_cb(GtkWidget *widget, gpointer data) { - gint i; - MultiloadApplet *ma = data; + gint i; + MultiloadApplet *ma = data; - for (i = 0; i < graph_n; i++) - { - load_graph_stop(ma->graphs[i]); - if (ma->graphs[i]->colors) - { - g_free (ma->graphs[i]->colors); - ma->graphs[i]->colors = NULL; - } - gtk_widget_destroy(ma->graphs[i]->main_widget); + for (i = 0; i < graph_n; i++) + { + load_graph_stop(ma->graphs[i]); + if (ma->graphs[i]->colors) + { + g_free (ma->graphs[i]->colors); + ma->graphs[i]->colors = NULL; + } + gtk_widget_destroy(ma->graphs[i]->main_widget); - load_graph_unalloc(ma->graphs[i]); - g_free(ma->graphs[i]); - } + load_graph_unalloc(ma->graphs[i]); + g_free(ma->graphs[i]); + } - netspeed_delete (ma->netspeed_in); - netspeed_delete (ma->netspeed_out); + netspeed_delete (ma->netspeed_in); + netspeed_delete (ma->netspeed_out); - if (ma->about_dialog) - gtk_widget_destroy (ma->about_dialog); + if (ma->about_dialog) + gtk_widget_destroy (ma->about_dialog); - if (ma->prop_dialog) - gtk_widget_destroy (ma->prop_dialog); + if (ma->prop_dialog) + gtk_widget_destroy (ma->prop_dialog); - gtk_widget_destroy(GTK_WIDGET(ma->applet)); + gtk_widget_destroy(GTK_WIDGET(ma->applet)); - g_free (ma); + g_free (ma); - return; + return; } static gboolean multiload_button_press_event_cb (GtkWidget *widget, GdkEventButton *event, MultiloadApplet *ma) { - g_return_val_if_fail (event != NULL, FALSE); - g_return_val_if_fail (ma != NULL, FALSE); - - if (event->button == 1 && event->type == GDK_BUTTON_PRESS) { - start_procman (ma); - return TRUE; - } - return FALSE; + g_return_val_if_fail (event != NULL, FALSE); + g_return_val_if_fail (ma != NULL, FALSE); + + if (event->button == 1 && event->type == GDK_BUTTON_PRESS) { + start_procman (ma); + return TRUE; + } + return FALSE; } static gboolean multiload_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, MultiloadApplet *ma) { - g_return_val_if_fail (event != NULL, FALSE); - g_return_val_if_fail (ma != NULL, FALSE); - - switch (event->keyval) { - /* this list of keyvals taken from mixer applet, which seemed to have - a good list of keys to use */ - case GDK_KEY_KP_Enter: - case GDK_KEY_ISO_Enter: - case GDK_KEY_3270_Enter: - case GDK_KEY_Return: - case GDK_KEY_space: - case GDK_KEY_KP_Space: - /* activate */ - start_procman (ma); - return TRUE; - - default: - break; - } - - return FALSE; + g_return_val_if_fail (event != NULL, FALSE); + g_return_val_if_fail (ma != NULL, FALSE); + + switch (event->keyval) { + /* this list of keyvals taken from mixer applet, which seemed to have + a good list of keys to use */ + case GDK_KEY_KP_Enter: + case GDK_KEY_ISO_Enter: + case GDK_KEY_3270_Enter: + case GDK_KEY_Return: + case GDK_KEY_space: + case GDK_KEY_KP_Space: + /* activate */ + start_procman (ma); + return TRUE; + + default: + break; + } + + return FALSE; } /* update the tooltip to the graph's current "used" percentage */ void multiload_applet_tooltip_update(LoadGraph *g) { - gchar *tooltip_text; - MultiloadApplet *multiload; - const char *tooltip_label [graph_n] = { - [graph_cpuload] = N_("Processor"), - [graph_memload] = N_("Memory"), - [graph_netload2] = N_("Network"), - [graph_swapload] = N_("Swap Space"), - [graph_loadavg] = N_("Load Average"), - [graph_diskload] = N_("Disk") - }; - const char *name; - - g_assert(g); - - multiload = g->multiload; - - /* label the tooltip intuitively */ - name = gettext (tooltip_label [g->id]); - - switch (g->id) { - case graph_memload: { - float user_percent, cache_percent; - - user_percent = MIN ((float)(100 * multiload->memload_user) / (float)(multiload->memload_total), 100.0f); - cache_percent = MIN ((float)(100 * multiload->memload_cache) / (float)(multiload->memload_total), 100.0f); - tooltip_text = g_strdup_printf (_("%s:\n" - "%.01f%% in use by programs\n" - "%.01f%% in use as cache"), - name, - user_percent, - cache_percent); - break; - } - case graph_loadavg: { - tooltip_text = g_strdup_printf (_("The system load average is %0.02f"), - multiload->loadavg1); - break; - } - case graph_netload2: { - char *tx_in, *tx_out; - - tx_in = netspeed_get(multiload->netspeed_in); - tx_out = netspeed_get(multiload->netspeed_out); - /* xgettext: same as in graphic tab of g-s-m */ - tooltip_text = g_strdup_printf(_("%s:\n" - "Receiving %s\n" - "Sending %s"), - name, tx_in, tx_out); - g_free(tx_in); - g_free(tx_out); - break; - } - default: { - float ratio; - float percent; - - if (g->id == graph_cpuload) - ratio = multiload->cpu_used_ratio; - else if (g->id == graph_swapload) - ratio = multiload->swapload_used_ratio; - else if (g->id == graph_diskload) - ratio = multiload->diskload_used_ratio; - else - g_assert_not_reached (); - - percent = CLAMP (ratio * 100.0f, 0.0f, 100.0f); - tooltip_text = g_strdup_printf(_("%s:\n" - "%.01f%% in use"), - name, - percent); - } - } - - gtk_widget_set_tooltip_text(g->disp, tooltip_text); - - g_free(tooltip_text); + gchar *tooltip_text; + MultiloadApplet *multiload; + const char *tooltip_label [graph_n] = { + [graph_cpuload] = N_("Processor"), + [graph_memload] = N_("Memory"), + [graph_netload2] = N_("Network"), + [graph_swapload] = N_("Swap Space"), + [graph_loadavg] = N_("Load Average"), + [graph_diskload] = N_("Disk") + }; + const char *name; + + g_assert(g); + + multiload = g->multiload; + + /* label the tooltip intuitively */ + name = gettext (tooltip_label [g->id]); + + switch (g->id) { + case graph_memload: { + float user_percent, cache_percent; + + user_percent = MIN ((float)(100 * multiload->memload_user) / (float)(multiload->memload_total), 100.0f); + cache_percent = MIN ((float)(100 * multiload->memload_cache) / (float)(multiload->memload_total), 100.0f); + tooltip_text = g_strdup_printf (_("%s:\n" + "%.01f%% in use by programs\n" + "%.01f%% in use as cache"), + name, + user_percent, + cache_percent); + break; + } + case graph_loadavg: { + tooltip_text = g_strdup_printf (_("The system load average is %0.02f"), + multiload->loadavg1); + break; + } + case graph_netload2: { + char *tx_in, *tx_out; + + tx_in = netspeed_get(multiload->netspeed_in); + tx_out = netspeed_get(multiload->netspeed_out); + /* xgettext: same as in graphic tab of g-s-m */ + tooltip_text = g_strdup_printf(_("%s:\n" + "Receiving %s\n" + "Sending %s"), + name, tx_in, tx_out); + g_free(tx_in); + g_free(tx_out); + break; + } + default: { + float ratio; + float percent; + + if (g->id == graph_cpuload) + ratio = multiload->cpu_used_ratio; + else if (g->id == graph_swapload) + ratio = multiload->swapload_used_ratio; + else if (g->id == graph_diskload) + ratio = multiload->diskload_used_ratio; + else + g_assert_not_reached (); + + percent = CLAMP (ratio * 100.0f, 0.0f, 100.0f); + tooltip_text = g_strdup_printf(_("%s:\n" + "%.01f%% in use"), + name, + percent); + } + } + + gtk_widget_set_tooltip_text(g->disp, tooltip_text); + + g_free(tooltip_text); } static void multiload_create_graphs(MultiloadApplet *ma) { - struct { const char *label; - const char *visibility_key; - const char *name; - int num_colours; - LoadGraphDataFunc callback; - } graph_types [graph_n] = { - [graph_cpuload] = { _("CPU Load"), VIEW_CPULOAD_KEY, "cpuload", cpuload_n, GetLoad }, - [graph_memload] = { _("Memory Load"), VIEW_MEMLOAD_KEY, "memload", memload_n, GetMemory }, - [graph_netload2] = { _("Net Load"), VIEW_NETLOAD_KEY, "netload2", 6, GetNet }, - [graph_swapload] = { _("Swap Load"), VIEW_SWAPLOAD_KEY, "swapload", swapload_n, GetSwap }, - [graph_loadavg] = { _("Load Average"), VIEW_LOADAVG_KEY, "loadavg", 3, GetLoadAvg }, - [graph_diskload] = { _("Disk Load"), VIEW_DISKLOAD_KEY, "diskload", diskload_n, GetDiskLoad } - }; - - gint speed, size; - guint net_threshold1; - guint net_threshold2; - guint net_threshold3; - gint i; - - speed = g_settings_get_int (ma->settings, "speed"); - size = g_settings_get_int (ma->settings, "size"); - net_threshold1 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold1"), MIN_NET_THRESHOLD1, MAX_NET_THRESHOLD1); - net_threshold2 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold2"), MIN_NET_THRESHOLD2, MAX_NET_THRESHOLD2); - net_threshold3 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold3"), MIN_NET_THRESHOLD3, MAX_NET_THRESHOLD3); - if (net_threshold1 >= net_threshold2) - { - net_threshold1 = net_threshold2 - 1; - } - if (net_threshold2 >= net_threshold3) - { - net_threshold3 = net_threshold2 + 1; - } - speed = MAX (speed, 50); - size = CLAMP (size, 10, 400); - - for (i = 0; i < graph_n; i++) - { - ma->graphs[i] = load_graph_new (ma, - graph_types[i].num_colours, - graph_types[i].label, - i, - speed, - size, - g_settings_get_boolean (ma->settings, graph_types[i].visibility_key), - graph_types[i].name, - graph_types[i].callback); - } - ma->nvme_diskstats = g_settings_get_boolean (ma->settings, "diskload-nvme-diskstats"); - /* for Network graph, colors[4] is grid line color, it should not be used in loop in load-graph.c */ - /* for Network graph, colors[5] is indicator color, it should not be used in loop in load-graph.c */ - ma->graphs[graph_netload2]->n = 4; - ma->net_threshold1 = net_threshold1; - ma->net_threshold2 = net_threshold2; - ma->net_threshold3 = net_threshold3; - ma->netspeed_in = netspeed_new (ma->graphs [graph_netload2]); - ma->netspeed_out = netspeed_new (ma->graphs [graph_netload2]); - /* for Load graph, colors[2] is grid line color, it should not be used in loop in load-graph.c */ - ma->graphs[graph_loadavg]->n = 2; + struct { const char *label; + const char *visibility_key; + const char *name; + int num_colours; + LoadGraphDataFunc callback; + } graph_types [graph_n] = { + [graph_cpuload] = { _("CPU Load"), VIEW_CPULOAD_KEY, "cpuload", cpuload_n, GetLoad }, + [graph_memload] = { _("Memory Load"), VIEW_MEMLOAD_KEY, "memload", memload_n, GetMemory }, + [graph_netload2] = { _("Net Load"), VIEW_NETLOAD_KEY, "netload2", 6, GetNet }, + [graph_swapload] = { _("Swap Load"), VIEW_SWAPLOAD_KEY, "swapload", swapload_n, GetSwap }, + [graph_loadavg] = { _("Load Average"), VIEW_LOADAVG_KEY, "loadavg", 3, GetLoadAvg }, + [graph_diskload] = { _("Disk Load"), VIEW_DISKLOAD_KEY, "diskload", diskload_n, GetDiskLoad } + }; + + gint speed, size; + guint net_threshold1; + guint net_threshold2; + guint net_threshold3; + gint i; + + speed = g_settings_get_int (ma->settings, "speed"); + size = g_settings_get_int (ma->settings, "size"); + net_threshold1 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold1"), MIN_NET_THRESHOLD1, MAX_NET_THRESHOLD1); + net_threshold2 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold2"), MIN_NET_THRESHOLD2, MAX_NET_THRESHOLD2); + net_threshold3 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold3"), MIN_NET_THRESHOLD3, MAX_NET_THRESHOLD3); + if (net_threshold1 >= net_threshold2) + { + net_threshold1 = net_threshold2 - 1; + } + if (net_threshold2 >= net_threshold3) + { + net_threshold3 = net_threshold2 + 1; + } + speed = MAX (speed, 50); + size = CLAMP (size, 10, 400); + + for (i = 0; i < graph_n; i++) + { + ma->graphs[i] = load_graph_new (ma, + graph_types[i].num_colours, + graph_types[i].label, + i, + speed, + size, + g_settings_get_boolean (ma->settings, graph_types[i].visibility_key), + graph_types[i].name, + graph_types[i].callback); + } + ma->nvme_diskstats = g_settings_get_boolean (ma->settings, "diskload-nvme-diskstats"); + /* for Network graph, colors[4] is grid line color, it should not be used in loop in load-graph.c */ + /* for Network graph, colors[5] is indicator color, it should not be used in loop in load-graph.c */ + ma->graphs[graph_netload2]->n = 4; + ma->net_threshold1 = net_threshold1; + ma->net_threshold2 = net_threshold2; + ma->net_threshold3 = net_threshold3; + ma->netspeed_in = netspeed_new (ma->graphs [graph_netload2]); + ma->netspeed_out = netspeed_new (ma->graphs [graph_netload2]); + /* for Load graph, colors[2] is grid line color, it should not be used in loop in load-graph.c */ + ma->graphs[graph_loadavg]->n = 2; } /* remove the old graphs and rebuild them */ void multiload_applet_refresh(MultiloadApplet *ma) { - gint i; - MatePanelAppletOrient orientation; + gint i; + MatePanelAppletOrient orientation; - /* stop and free the old graphs */ - for (i = 0; i < graph_n; i++) - { - if (!ma->graphs[i]) - continue; + /* stop and free the old graphs */ + for (i = 0; i < graph_n; i++) + { + if (!ma->graphs[i]) + continue; - load_graph_stop(ma->graphs[i]); - gtk_widget_destroy(ma->graphs[i]->main_widget); + load_graph_stop(ma->graphs[i]); + gtk_widget_destroy(ma->graphs[i]->main_widget); - load_graph_unalloc(ma->graphs[i]); - g_free(ma->graphs[i]); - } + load_graph_unalloc(ma->graphs[i]); + g_free(ma->graphs[i]); + } - if (ma->box) - gtk_widget_destroy(ma->box); + if (ma->box) + gtk_widget_destroy(ma->box); - orientation = mate_panel_applet_get_orient(ma->applet); + orientation = mate_panel_applet_get_orient(ma->applet); - if ( (orientation == MATE_PANEL_APPLET_ORIENT_UP) || - (orientation == MATE_PANEL_APPLET_ORIENT_DOWN) ) { - ma->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - } - else - ma->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + if ( (orientation == MATE_PANEL_APPLET_ORIENT_UP) || + (orientation == MATE_PANEL_APPLET_ORIENT_DOWN) ) { + ma->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + } + else + ma->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_container_add(GTK_CONTAINER(ma->applet), ma->box); + gtk_container_add(GTK_CONTAINER(ma->applet), ma->box); - /* create the N graphs, passing in their user-configurable properties with gsettings. */ - multiload_create_graphs (ma); + /* create the N graphs, passing in their user-configurable properties with gsettings. */ + multiload_create_graphs (ma); - /* only start and display the graphs the user has turned on */ + /* only start and display the graphs the user has turned on */ - for (i = 0; i < graph_n; i++) { - gtk_box_pack_start(GTK_BOX(ma->box), - ma->graphs[i]->main_widget, - TRUE, TRUE, 1); - if (ma->graphs[i]->visible) { - gtk_widget_show_all (ma->graphs[i]->main_widget); - load_graph_start(ma->graphs[i]); - } - } - gtk_widget_show (ma->box); + for (i = 0; i < graph_n; i++) { + gtk_box_pack_start(GTK_BOX(ma->box), + ma->graphs[i]->main_widget, + TRUE, TRUE, 1); + if (ma->graphs[i]->visible) { + gtk_widget_show_all (ma->graphs[i]->main_widget); + load_graph_start(ma->graphs[i]); + } + } + gtk_widget_show (ma->box); - return; + return; } static const GtkActionEntry multiload_menu_actions [] = { - { "MultiLoadProperties", "document-properties", N_("_Preferences"), - NULL, NULL, - G_CALLBACK (multiload_properties_cb) }, - { "MultiLoadRunProcman", "system-run", N_("_Open System Monitor"), - NULL, NULL, - G_CALLBACK (start_procman_cb) }, - { "MultiLoadHelp", "help-browser", N_("_Help"), - NULL, NULL, - G_CALLBACK (help_cb) }, - { "MultiLoadAbout", "help-about", N_("_About"), - NULL, NULL, - G_CALLBACK (about_cb) } + { "MultiLoadProperties", "document-properties", N_("_Preferences"), + NULL, NULL, + G_CALLBACK (multiload_properties_cb) }, + { "MultiLoadRunProcman", "system-run", N_("_Open System Monitor"), + NULL, NULL, + G_CALLBACK (start_procman_cb) }, + { "MultiLoadHelp", "help-browser", N_("_Help"), + NULL, NULL, + G_CALLBACK (help_cb) }, + { "MultiLoadAbout", "help-about", N_("_About"), + NULL, NULL, + G_CALLBACK (about_cb) } }; /* create a box and stuff the load graphs inside of it */ static gboolean multiload_applet_new(MatePanelApplet *applet, const gchar *iid, gpointer data) { - GtkStyleContext *context; - MultiloadApplet *ma; - GSettings *lockdown_settings; - GtkActionGroup *action_group; - gchar *ui_path; + GtkStyleContext *context; + MultiloadApplet *ma; + GSettings *lockdown_settings; + GtkActionGroup *action_group; + gchar *ui_path; - context = gtk_widget_get_style_context (GTK_WIDGET (applet)); - gtk_style_context_add_class (context, "multiload-applet"); + context = gtk_widget_get_style_context (GTK_WIDGET (applet)); + gtk_style_context_add_class (context, "multiload-applet"); - ma = g_new0(MultiloadApplet, 1); + ma = g_new0(MultiloadApplet, 1); - ma->applet = applet; + ma->applet = applet; - ma->about_dialog = NULL; - ma->prop_dialog = NULL; + ma->about_dialog = NULL; + ma->prop_dialog = NULL; ma->last_clicked = 0; - g_set_application_name (_("System Monitor")); + g_set_application_name (_("System Monitor")); - gtk_window_set_default_icon_name ("utilities-system-monitor"); - mate_panel_applet_set_background_widget (applet, GTK_WIDGET(applet)); + gtk_window_set_default_icon_name ("utilities-system-monitor"); + mate_panel_applet_set_background_widget (applet, GTK_WIDGET(applet)); - ma->settings = mate_panel_applet_settings_new (applet, "org.mate.panel.applet.multiload"); - mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR); + ma->settings = mate_panel_applet_settings_new (applet, "org.mate.panel.applet.multiload"); + mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR); - action_group = gtk_action_group_new ("Multiload Applet Actions"); - gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions (action_group, - multiload_menu_actions, - G_N_ELEMENTS (multiload_menu_actions), - ma); - ui_path = g_build_filename (MULTILOAD_MENU_UI_DIR, "multiload-applet-menu.xml", NULL); - mate_panel_applet_setup_menu_from_file (applet, ui_path, action_group); - g_free (ui_path); + action_group = gtk_action_group_new ("Multiload Applet Actions"); + gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (action_group, + multiload_menu_actions, + G_N_ELEMENTS (multiload_menu_actions), + ma); + ui_path = g_build_filename (MULTILOAD_MENU_UI_DIR, "multiload-applet-menu.xml", NULL); + mate_panel_applet_setup_menu_from_file (applet, ui_path, action_group); + g_free (ui_path); - if (mate_panel_applet_get_locked_down (applet)) { - GtkAction *action; + if (mate_panel_applet_get_locked_down (applet)) { + GtkAction *action; - action = gtk_action_group_get_action (action_group, "MultiLoadProperties"); - gtk_action_set_visible (action, FALSE); - } + action = gtk_action_group_get_action (action_group, "MultiLoadProperties"); + gtk_action_set_visible (action, FALSE); + } - lockdown_settings = g_settings_new ("org.mate.lockdown"); - if (g_settings_get_boolean (lockdown_settings, "disable-command-line") || - mate_panel_applet_get_locked_down (applet)) { - GtkAction *action; + lockdown_settings = g_settings_new ("org.mate.lockdown"); + if (g_settings_get_boolean (lockdown_settings, "disable-command-line") || + mate_panel_applet_get_locked_down (applet)) { + GtkAction *action; - /* When the panel is locked down or when the command line is inhibited, - it seems very likely that running the procman would be at least harmful */ - action = gtk_action_group_get_action (action_group, "MultiLoadRunProcman"); - gtk_action_set_visible (action, FALSE); - } - g_object_unref (lockdown_settings); + /* When the panel is locked down or when the command line is inhibited, + it seems very likely that running the procman would be at least harmful */ + action = gtk_action_group_get_action (action_group, "MultiLoadRunProcman"); + gtk_action_set_visible (action, FALSE); + } + g_object_unref (lockdown_settings); - g_object_unref (action_group); + g_object_unref (action_group); - g_signal_connect(G_OBJECT(applet), "change_size", - G_CALLBACK(multiload_change_size_cb), ma); - g_signal_connect(G_OBJECT(applet), "change_orient", - G_CALLBACK(multiload_change_orient_cb), ma); - g_signal_connect(G_OBJECT(applet), "destroy", - G_CALLBACK(multiload_destroy_cb), ma); - g_signal_connect(G_OBJECT(applet), "button_press_event", - G_CALLBACK(multiload_button_press_event_cb), ma); - g_signal_connect(G_OBJECT(applet), "key_press_event", - G_CALLBACK(multiload_key_press_event_cb), ma); + g_signal_connect(G_OBJECT(applet), "change_size", + G_CALLBACK(multiload_change_size_cb), ma); + g_signal_connect(G_OBJECT(applet), "change_orient", + G_CALLBACK(multiload_change_orient_cb), ma); + g_signal_connect(G_OBJECT(applet), "destroy", + G_CALLBACK(multiload_destroy_cb), ma); + g_signal_connect(G_OBJECT(applet), "button_press_event", + G_CALLBACK(multiload_button_press_event_cb), ma); + g_signal_connect(G_OBJECT(applet), "key_press_event", + G_CALLBACK(multiload_key_press_event_cb), ma); - multiload_applet_refresh (ma); + multiload_applet_refresh (ma); - gtk_widget_show(GTK_WIDGET(applet)); + gtk_widget_show(GTK_WIDGET(applet)); - return TRUE; + return TRUE; } static gboolean multiload_factory (MatePanelApplet *applet, - const gchar *iid, - gpointer data) + const gchar *iid, + gpointer data) { - gboolean retval = FALSE; + gboolean retval = FALSE; - glibtop_init(); + glibtop_init(); - retval = multiload_applet_new(applet, iid, data); + retval = multiload_applet_new(applet, iid, data); - return retval; + return retval; } MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("MultiLoadAppletFactory", - PANEL_TYPE_APPLET, - "multiload", - multiload_factory, - NULL) + PANEL_TYPE_APPLET, + "multiload", + multiload_factory, + NULL) diff --git a/multiload/netspeed.c b/multiload/netspeed.c index 21747881..3e889c8f 100644 --- a/multiload/netspeed.c +++ b/multiload/netspeed.c @@ -8,27 +8,27 @@ enum { N_STATES = 4 }; struct _NetSpeed { - LoadGraph *graph; - gulong states[N_STATES]; - size_t cur; + LoadGraph *graph; + gulong states[N_STATES]; + size_t cur; }; NetSpeed* netspeed_new(LoadGraph *g) { - NetSpeed *ns = g_new0(NetSpeed, 1); - ns->graph = g; - return ns; + NetSpeed *ns = g_new0(NetSpeed, 1); + ns->graph = g; + return ns; } void netspeed_delete(NetSpeed *ns) { - g_free(ns); + g_free(ns); } void netspeed_add(NetSpeed *ns, gulong tx) { - ns->cur = (ns->cur + 1) % N_STATES; - ns->states[ns->cur] = tx; + ns->cur = (ns->cur + 1) % N_STATES; + ns->states[ns->cur] = tx; } /* Something very similar to g_format_size() but for rates. @@ -36,35 +36,35 @@ void netspeed_add(NetSpeed *ns, gulong tx) static char* format_rate_for_display(guint rate) { - char *bytes; - char *text; + char *bytes; + char *text; - bytes = g_format_size (rate); - text = g_strdup_printf (_("%s/s"), bytes); - g_free (bytes); + bytes = g_format_size (rate); + text = g_strdup_printf (_("%s/s"), bytes); + g_free (bytes); - return text; + return text; } char* netspeed_get(NetSpeed *ns) { - gulong older, newer; - guint rate; + gulong older, newer; + guint rate; - newer = ns->states[ns->cur]; - older = ns->states[(ns->cur + 1) % N_STATES]; + newer = ns->states[ns->cur]; + older = ns->states[(ns->cur + 1) % N_STATES]; - if ((older != 0) && (newer > older)) - rate = (newer - older) * 1000 / ((N_STATES - 1) * ns->graph->speed); - else - /* We end up here if we haven't got enough data yet or the - network interface has jumped back (or there has never - been any activity on any interface). A value of 0 is - likely to be accurate, but if it is wrong it will be - clearly wrong. In any event, it should fix itself in a - few seconds. */ - rate = 0; + if ((older != 0) && (newer > older)) + rate = (newer - older) * 1000 / ((N_STATES - 1) * ns->graph->speed); + else + /* We end up here if we haven't got enough data yet or the + network interface has jumped back (or there has never + been any activity on any interface). A value of 0 is + likely to be accurate, but if it is wrong it will be + clearly wrong. In any event, it should fix itself in a + few seconds. */ + rate = 0; - return format_rate_for_display(rate); + return format_rate_for_display(rate); } diff --git a/multiload/properties.c b/multiload/properties.c index 214ce27f..c1ee09b6 100644 --- a/multiload/properties.c +++ b/multiload/properties.c @@ -2,7 +2,7 @@ * (C) 2002 The Free Software Foundation * * Authors: - * Todd Kulesza + * Todd Kulesza * * */ @@ -21,28 +21,28 @@ #include "global.h" -#define PROP_CPU 0 -#define PROP_MEM 1 -#define PROP_NET 2 -#define PROP_SWAP 3 -#define PROP_AVG 4 -#define PROP_DISK 5 +#define PROP_CPU 0 +#define PROP_MEM 1 +#define PROP_NET 2 +#define PROP_SWAP 3 +#define PROP_AVG 4 +#define PROP_DISK 5 -#define PROP_SPEED 6 -#define PROP_SIZE 7 +#define PROP_SPEED 6 +#define PROP_SIZE 7 #define PROP_NET_THRESHOLD1 8 #define PROP_NET_THRESHOLD2 9 #define PROP_NET_THRESHOLD3 10 -#define HIG_IDENTATION " " -#define NEVER_SENSITIVE "never_sensitive" +#define HIG_IDENTATION " " +#define NEVER_SENSITIVE "never_sensitive" /* set sensitive and setup NEVER_SENSITIVE appropriately */ static void hard_set_sensitive (GtkWidget *w, gboolean sensitivity) { - gtk_widget_set_sensitive (w, sensitivity); - g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE, - GINT_TO_POINTER ( ! sensitivity)); + gtk_widget_set_sensitive (w, sensitivity); + g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE, + GINT_TO_POINTER ( ! sensitivity)); } @@ -50,278 +50,285 @@ hard_set_sensitive (GtkWidget *w, gboolean sensitivity) static void soft_set_sensitive (GtkWidget *w, gboolean sensitivity) { - if (g_object_get_data (G_OBJECT (w), NEVER_SENSITIVE)) - gtk_widget_set_sensitive (w, FALSE); - else - gtk_widget_set_sensitive (w, sensitivity); + if (g_object_get_data (G_OBJECT (w), NEVER_SENSITIVE)) + gtk_widget_set_sensitive (w, FALSE); + else + gtk_widget_set_sensitive (w, sensitivity); } static void properties_set_insensitive(MultiloadApplet *ma) { - gint i, total_graphs, last_graph; + gint i, total_graphs, last_graph; - total_graphs = 0; - last_graph = 0; + total_graphs = 0; + last_graph = 0; - for (i = 0; i < graph_n; i++) - if (ma->graphs[i]->visible) - { - last_graph = i; - total_graphs++; - } + for (i = 0; i < graph_n; i++) + if (ma->graphs[i]->visible) + { + last_graph = i; + total_graphs++; + } - if (total_graphs < 2) - soft_set_sensitive(ma->check_boxes[last_graph], FALSE); + if (total_graphs < 2) + soft_set_sensitive(ma->check_boxes[last_graph], FALSE); - return; + return; } static void properties_close_cb (GtkWidget *widget, gint arg, MultiloadApplet *ma) { - GError *error = NULL; - - switch (arg) - { - case GTK_RESPONSE_HELP: - - gtk_show_uri_on_window (NULL, - "help:mate-multiload/multiload-prefs", - gtk_get_current_event_time (), - &error); - - if (error) { /* FIXME: the user needs to see this */ - g_warning ("help error: %s\n", error->message); - g_error_free (error); - error = NULL; - } - break; - - case GTK_RESPONSE_CLOSE: - default: - gtk_widget_destroy (widget); - ma->prop_dialog = NULL; - } + GError *error = NULL; + + switch (arg) + { + case GTK_RESPONSE_HELP: + + gtk_show_uri_on_window (NULL, + "help:mate-multiload/multiload-prefs", + gtk_get_current_event_time (), + &error); + + if (error) { /* FIXME: the user needs to see this */ + g_warning ("help error: %s\n", error->message); + g_error_free (error); + error = NULL; + } + break; + + case GTK_RESPONSE_CLOSE: + default: + gtk_widget_destroy (widget); + ma->prop_dialog = NULL; + } } static void property_toggled_cb(GtkWidget *widget, gpointer name) { - MultiloadApplet *ma; - gint prop_type, i; - gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - - ma = g_object_get_data(G_OBJECT(widget), "MultiloadApplet"); - prop_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "prop_type")); - - /* FIXME: the first toggle button to be checked/dechecked does not work, but after that everything is cool. what gives? */ - /* FIXME: check if this is still valid for gsettings */ - g_settings_set_boolean (ma->settings, (gchar *)name, active); - g_settings_set_boolean (ma->settings, (gchar *)name, active); - - if (active) - { - for (i = 0; i < graph_n; i++) - soft_set_sensitive(ma->check_boxes[i], TRUE); - gtk_widget_show_all (ma->graphs[prop_type]->main_widget); - ma->graphs[prop_type]->visible = TRUE; - load_graph_start(ma->graphs[prop_type]); - } - else - { - load_graph_stop(ma->graphs[prop_type]); - gtk_widget_hide (ma->graphs[prop_type]->main_widget); - ma->graphs[prop_type]->visible = FALSE; - properties_set_insensitive(ma); - } - - return; + MultiloadApplet *ma; + gint prop_type, i; + gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + + ma = g_object_get_data(G_OBJECT(widget), "MultiloadApplet"); + prop_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "prop_type")); + + /* FIXME: the first toggle button to be checked/dechecked does not work, but after that everything is cool. what gives? */ + /* FIXME: check if this is still valid for gsettings */ + g_settings_set_boolean (ma->settings, (gchar *)name, active); + g_settings_set_boolean (ma->settings, (gchar *)name, active); + + if (active) + { + for (i = 0; i < graph_n; i++) + soft_set_sensitive(ma->check_boxes[i], TRUE); + gtk_widget_show_all (ma->graphs[prop_type]->main_widget); + ma->graphs[prop_type]->visible = TRUE; + load_graph_start(ma->graphs[prop_type]); + } + else + { + load_graph_stop(ma->graphs[prop_type]); + gtk_widget_hide (ma->graphs[prop_type]->main_widget); + ma->graphs[prop_type]->visible = FALSE; + properties_set_insensitive(ma); + } + + return; } static void spin_button_changed_cb(GtkWidget *widget, gpointer name) { - MultiloadApplet *ma; - gint value; - gint prop_type, i; - - ma = g_object_get_data(G_OBJECT(widget), "MultiloadApplet"); - prop_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "prop_type")); - value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); - - switch(prop_type) - { - case PROP_SPEED: - g_settings_set_int (ma->settings, (gchar *)name, value); - for (i = 0; i < graph_n; i++) - { - load_graph_stop(ma->graphs[i]); - ma->graphs[i]->speed = value; - if (ma->graphs[i]->visible) - load_graph_start(ma->graphs[i]); - } - - break; - - case PROP_SIZE: - for (i = 0; i < graph_n; i++) - { - g_settings_set_int (ma->settings, (gchar *)name, value); - ma->graphs[i]->size = value ; - - if (ma->graphs[i]->orient) - gtk_widget_set_size_request ( - ma->graphs[i]->main_widget, - ma->graphs[i]->pixel_size, - ma->graphs[i]->size); - else - gtk_widget_set_size_request ( - ma->graphs[i]->main_widget, - ma->graphs[i]->size, - ma->graphs[i]->pixel_size); - } - break; - - case PROP_NET_THRESHOLD1: - g_settings_set_uint (ma->settings, (gchar *)name, value); - if (value >= ma->net_threshold2) - { - gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), - (gdouble)g_settings_get_uint (ma->settings, "netthreshold2") - 1); - ma->net_threshold1 = g_settings_get_uint (ma->settings, "netthreshold2") - 1; - } - else - ma->net_threshold1 = value; - break; - - case PROP_NET_THRESHOLD2: - g_settings_set_uint (ma->settings, (gchar *)name, value); - if (value >= ma->net_threshold3) - { - gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), - (gdouble)g_settings_get_uint (ma->settings, "netthreshold3") - 1); - ma->net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold3") - 1; - } - else if (value <= ma->net_threshold1) - { - gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), - (gdouble)g_settings_get_uint (ma->settings, "netthreshold1") + 1); - ma->net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold1") + 1; - } - else - ma->net_threshold2 = value; - - break; - - case PROP_NET_THRESHOLD3: - g_settings_set_uint (ma->settings, (gchar *)name, value); - if (value <= ma->net_threshold2) - { - gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), - (gdouble)g_settings_get_uint (ma->settings, "netthreshold2") + 1); - ma->net_threshold3 = g_settings_get_uint (ma->settings, "netthreshold2") + 1; - } - else - ma->net_threshold3 = value; - break; - default: - g_assert_not_reached(); - } - - return; + MultiloadApplet *ma; + gint value; + gint prop_type, i; + + ma = g_object_get_data(G_OBJECT(widget), "MultiloadApplet"); + prop_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "prop_type")); + value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + + switch(prop_type) + { + case PROP_SPEED: + g_settings_set_int (ma->settings, (gchar *)name, value); + for (i = 0; i < graph_n; i++) + { + load_graph_stop(ma->graphs[i]); + ma->graphs[i]->speed = value; + if (ma->graphs[i]->visible) + load_graph_start(ma->graphs[i]); + } + + break; + + case PROP_SIZE: + for (i = 0; i < graph_n; i++) + { + g_settings_set_int (ma->settings, (gchar *)name, value); + ma->graphs[i]->size = value ; + + if (ma->graphs[i]->orient) + gtk_widget_set_size_request ( + ma->graphs[i]->main_widget, + ma->graphs[i]->pixel_size, + ma->graphs[i]->size); + else + gtk_widget_set_size_request ( + ma->graphs[i]->main_widget, + ma->graphs[i]->size, + ma->graphs[i]->pixel_size); + } + break; + + case PROP_NET_THRESHOLD1: + g_settings_set_uint (ma->settings, (gchar *)name, value); + if (value >= ma->net_threshold2) + { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), + (gdouble)g_settings_get_uint (ma->settings, + "netthreshold2") - 1); + ma->net_threshold1 = g_settings_get_uint (ma->settings, + "netthreshold2") - 1; + } + else + ma->net_threshold1 = value; + break; + + case PROP_NET_THRESHOLD2: + g_settings_set_uint (ma->settings, (gchar *)name, value); + if (value >= ma->net_threshold3) + { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), + (gdouble)g_settings_get_uint (ma->settings, + "netthreshold3") - 1); + ma->net_threshold2 = g_settings_get_uint (ma->settings, + "netthreshold3") - 1; + } + else if (value <= ma->net_threshold1) + { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), + (gdouble)g_settings_get_uint (ma->settings, + "netthreshold1") + 1); + ma->net_threshold2 = g_settings_get_uint (ma->settings, + "netthreshold1") + 1; + } + else + ma->net_threshold2 = value; + break; + + case PROP_NET_THRESHOLD3: + g_settings_set_uint (ma->settings, (gchar *)name, value); + if (value <= ma->net_threshold2) + { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), + (gdouble)g_settings_get_uint (ma->settings, + "netthreshold2") + 1); + ma->net_threshold3 = g_settings_get_uint (ma->settings, + "netthreshold2") + 1; + } + else + ma->net_threshold3 = value; + break; + default: + g_assert_not_reached(); + } + + return; } /* create a new page in the notebook widget, add it, and return a pointer to it */ static GtkWidget * add_page(GtkWidget *notebook, gchar *label) { - GtkWidget *page; - GtkWidget *page_label; + GtkWidget *page; + GtkWidget *page_label; - page = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_set_homogeneous (GTK_BOX (page), TRUE); - page_label = gtk_label_new(label); - gtk_container_set_border_width(GTK_CONTAINER(page), 6); + page = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_set_homogeneous (GTK_BOX (page), TRUE); + page_label = gtk_label_new(label); + gtk_container_set_border_width(GTK_CONTAINER(page), 6); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, page_label); + gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, page_label); - return page; + return page; } /* save the selected color to gsettings and apply it on the applet */ static void color_picker_set_cb(GtkColorChooser *color_picker, gchar *key) { - gchar *color_string; - guint8 prop_type; - GdkRGBA color; - MultiloadApplet *ma; - - ma = g_object_get_data (G_OBJECT (color_picker), "MultiloadApplet"); - - if (strstr(key, "cpuload")) - prop_type = PROP_CPU; - else if (strstr(key, "memload")) - prop_type = PROP_MEM; - else if (strstr(key, "netload2")) - prop_type = PROP_NET; - else if (strstr(key, "swapload")) - prop_type = PROP_SWAP; - else if (strstr(key, "loadavg")) - prop_type = PROP_AVG; - else if (strstr(key, "diskload")) - prop_type = PROP_DISK; - else - g_assert_not_reached(); - - gtk_color_chooser_get_rgba(color_picker, &color); - - color_string = gdk_rgba_to_string (&color); - g_settings_set_string(ma->settings, key, color_string); - - gdk_rgba_parse(&(ma->graphs[prop_type]->colors[g_ascii_digit_value(key[strlen(key) - 1]) ]), - color_string); - - return; + gchar *color_string; + guint8 prop_type; + GdkRGBA color; + MultiloadApplet *ma; + + ma = g_object_get_data (G_OBJECT (color_picker), "MultiloadApplet"); + + if (strstr(key, "cpuload")) + prop_type = PROP_CPU; + else if (strstr(key, "memload")) + prop_type = PROP_MEM; + else if (strstr(key, "netload2")) + prop_type = PROP_NET; + else if (strstr(key, "swapload")) + prop_type = PROP_SWAP; + else if (strstr(key, "loadavg")) + prop_type = PROP_AVG; + else if (strstr(key, "diskload")) + prop_type = PROP_DISK; + else + g_assert_not_reached(); + + gtk_color_chooser_get_rgba(color_picker, &color); + + color_string = gdk_rgba_to_string (&color); + g_settings_set_string(ma->settings, key, color_string); + + gdk_rgba_parse(&(ma->graphs[prop_type]->colors[g_ascii_digit_value(key[strlen(key) - 1]) ]), + color_string); + + return; } /* create a color selector */ static void add_color_selector(GtkWidget *page, gchar *name, gchar *key, MultiloadApplet *ma) { - GtkWidget *vbox; - GtkWidget *label; - GtkWidget *color_picker; - GdkRGBA color; - gchar *color_string; + GtkWidget *vbox; + GtkWidget *label; + GtkWidget *color_picker; + GdkRGBA color; + gchar *color_string; - color_string = g_settings_get_string (ma->settings, key); - if (!color_string) - color_string = g_strdup ("#000000"); - gdk_rgba_parse (&color, color_string); - g_free (color_string); + color_string = g_settings_get_string (ma->settings, key); + if (!color_string) + color_string = g_strdup ("#000000"); + gdk_rgba_parse (&color, color_string); + g_free (color_string); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - label = gtk_label_new_with_mnemonic(name); - color_picker = gtk_color_button_new(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), color_picker); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + label = gtk_label_new_with_mnemonic(name); + color_picker = gtk_color_button_new(); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), color_picker); - gtk_box_pack_start(GTK_BOX(vbox), color_picker, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), color_picker, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(page), vbox, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(page), vbox, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (color_picker), "MultiloadApplet", ma); + g_object_set_data (G_OBJECT (color_picker), "MultiloadApplet", ma); - gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color_picker), &color); + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color_picker), &color); - g_signal_connect(G_OBJECT(color_picker), "color_set", G_CALLBACK(color_picker_set_cb), key); + g_signal_connect(G_OBJECT(color_picker), "color_set", G_CALLBACK(color_picker_set_cb), key); - if ( ! g_settings_is_writable (ma->settings, key)) - hard_set_sensitive (vbox, FALSE); + if ( ! g_settings_is_writable (ma->settings, key)) + hard_set_sensitive (vbox, FALSE); - return; + return; } /* save the checkbox option to gsettings and apply it on the applet */ @@ -329,533 +336,533 @@ static void nvme_checkbox_toggled_cb (GtkCheckButton *checkbox, MultiloadApplet *ma) { - gboolean option; + gboolean option; - option = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)); - ma->nvme_diskstats = option; - g_settings_set_boolean (ma->settings, "diskload-nvme-diskstats", option); + option = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)); + ma->nvme_diskstats = option; + g_settings_set_boolean (ma->settings, "diskload-nvme-diskstats", option); - return; + return; } /* creates the properties dialog using up-to-the-minute info from gsettings */ static void fill_properties(GtkWidget *dialog, MultiloadApplet *ma) { - GtkWidget *page; - GtkWidget *hbox, *vbox; - GtkWidget *categories_vbox; - GtkWidget *category_vbox; - GtkWidget *control_vbox; - GtkWidget *control_hbox; - GtkWidget *check_box; - GtkWidget *indent; - GtkWidget *spin_button; - GtkWidget *label; - MatePanelAppletOrient orient; - GtkSizeGroup *label_size; - GtkSizeGroup *spin_size; - gchar *label_text; - gchar *title; - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); - gtk_widget_show (vbox); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox, - TRUE, TRUE, 0); - - categories_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18); - gtk_box_pack_start (GTK_BOX (vbox), categories_vbox, TRUE, TRUE, 0); - gtk_widget_show (categories_vbox); - - category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); - gtk_widget_show (category_vbox); - - title = g_strconcat ("", _("Monitored Resources"), "", NULL); - label = gtk_label_new_with_mnemonic (_(title)); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - gtk_label_set_xalign (GTK_LABEL (label), 0.0); - gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); - g_free (title); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - indent = gtk_label_new (HIG_IDENTATION); - gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); - gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); - gtk_widget_show (indent); - - control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); - gtk_widget_show (control_vbox); - - control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); - gtk_widget_show (control_hbox); - - check_box = gtk_check_button_new_with_mnemonic(_("_Processor")); - ma->check_boxes[0] = check_box; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), - g_settings_get_boolean (ma->settings, VIEW_CPULOAD_KEY)); - g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_CPU)); - g_signal_connect(G_OBJECT(check_box), "toggled", - G_CALLBACK(property_toggled_cb), VIEW_CPULOAD_KEY); - gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, VIEW_CPULOAD_KEY)) - hard_set_sensitive (check_box, FALSE); - - check_box = gtk_check_button_new_with_mnemonic(_("_Memory")); - ma->check_boxes[1] = check_box; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), - g_settings_get_boolean (ma->settings, VIEW_MEMLOAD_KEY)); - g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_MEM)); - g_signal_connect(G_OBJECT(check_box), "toggled", - G_CALLBACK(property_toggled_cb), VIEW_MEMLOAD_KEY); - gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, VIEW_MEMLOAD_KEY)) - hard_set_sensitive (check_box, FALSE); - - check_box = gtk_check_button_new_with_mnemonic(_("_Network")); - ma->check_boxes[2] = check_box; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), - g_settings_get_boolean (ma->settings, VIEW_NETLOAD_KEY)); - g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_NET)); - g_signal_connect(G_OBJECT(check_box), "toggled", - G_CALLBACK(property_toggled_cb), VIEW_NETLOAD_KEY); - gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, VIEW_NETLOAD_KEY)) - hard_set_sensitive (check_box, FALSE); - - check_box = gtk_check_button_new_with_mnemonic (_("S_wap Space")); - ma->check_boxes[3] = check_box; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), - g_settings_get_boolean (ma->settings, VIEW_SWAPLOAD_KEY)); - g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_SWAP)); - g_signal_connect(G_OBJECT(check_box), "toggled", - G_CALLBACK(property_toggled_cb), VIEW_SWAPLOAD_KEY); - gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, VIEW_SWAPLOAD_KEY)) - hard_set_sensitive (check_box, FALSE); - - check_box = gtk_check_button_new_with_mnemonic(_("_Load")); - ma->check_boxes[4] = check_box; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), - g_settings_get_boolean (ma->settings, VIEW_LOADAVG_KEY)); - g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_AVG)); - g_signal_connect(G_OBJECT(check_box), "toggled", - G_CALLBACK(property_toggled_cb), VIEW_LOADAVG_KEY); - gtk_box_pack_start(GTK_BOX(control_hbox), check_box, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, VIEW_LOADAVG_KEY)) - hard_set_sensitive (check_box, FALSE); - - check_box = gtk_check_button_new_with_mnemonic(_("_Harddisk")); - ma->check_boxes[5] = check_box; - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_box), - g_settings_get_boolean (ma->settings, VIEW_DISKLOAD_KEY)); - g_object_set_data (G_OBJECT (check_box), "MultiloadApplet", ma); - g_object_set_data (G_OBJECT (check_box), "prop_type", - GINT_TO_POINTER (PROP_DISK)); - g_signal_connect (G_OBJECT (check_box), "toggled", - G_CALLBACK (property_toggled_cb), VIEW_DISKLOAD_KEY); - gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, VIEW_DISKLOAD_KEY)) - hard_set_sensitive (check_box, FALSE); - - category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); - gtk_widget_show (category_vbox); - - title = g_strconcat ("", _("Options"), "", NULL); - label = gtk_label_new (title); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - gtk_label_set_xalign (GTK_LABEL (label), 0.0); - gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); - gtk_widget_show (label); - g_free (title); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - indent = gtk_label_new (HIG_IDENTATION); - gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); - gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); - gtk_widget_show (indent); - - control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); - gtk_widget_show (control_vbox); - - control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); - gtk_widget_show (control_hbox); - - label_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - orient = mate_panel_applet_get_orient(ma->applet); - if ( (orient == MATE_PANEL_APPLET_ORIENT_UP) || (orient == MATE_PANEL_APPLET_ORIENT_DOWN) ) - label_text = g_strdup(_("System m_onitor width: ")); - else - label_text = g_strdup(_("System m_onitor height: ")); - - label = gtk_label_new_with_mnemonic(label_text); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_size_group_add_widget (label_size, label); - gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - spin_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - spin_button = gtk_spin_button_new_with_range(10, 1000, 5); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); - g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(spin_button), "prop_type", - GINT_TO_POINTER(PROP_SIZE)); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), - (gdouble)g_settings_get_int(ma->settings, "size")); - g_signal_connect(G_OBJECT(spin_button), "value_changed", - G_CALLBACK(spin_button_changed_cb), "size"); - - if ( ! g_settings_is_writable (ma->settings, "size")) { - hard_set_sensitive (label, FALSE); - hard_set_sensitive (hbox, FALSE); - } - - gtk_size_group_add_widget (spin_size, spin_button); - gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); - - label = gtk_label_new (_("pixels")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); - gtk_widget_show (control_hbox); - - label = gtk_label_new_with_mnemonic(_("Sys_tem monitor update interval: ")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_size_group_add_widget (label_size, label); - gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - spin_button = gtk_spin_button_new_with_range(50, 10000, 50); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); - g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(spin_button), "prop_type", - GINT_TO_POINTER(PROP_SPEED)); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), - (gdouble)g_settings_get_int (ma->settings, "speed")); - g_signal_connect(G_OBJECT(spin_button), "value_changed", - G_CALLBACK(spin_button_changed_cb), "speed"); - gtk_size_group_add_widget (spin_size, spin_button); - gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, "speed")) { - hard_set_sensitive (label, FALSE); - hard_set_sensitive (hbox, FALSE); - } - - label = gtk_label_new(_("milliseconds")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - g_free(label_text); - - - category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); - gtk_widget_show (category_vbox); - - title = g_strconcat ("", _("Colors"), "", NULL); - label = gtk_label_new (title); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - gtk_label_set_xalign (GTK_LABEL (label), 0.0); - gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); - gtk_widget_show (label); - g_free (title); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - indent = gtk_label_new (HIG_IDENTATION); - gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); - gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); - gtk_widget_show (indent); - - control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); - gtk_widget_show (control_vbox); - - ma->notebook = gtk_notebook_new(); - gtk_container_add (GTK_CONTAINER (control_vbox), ma->notebook); - - page = add_page(ma->notebook, _("Processor")); - gtk_container_set_border_width (GTK_CONTAINER (page), 12); - add_color_selector(page, _("_User"), "cpuload-color0", ma); - add_color_selector(page, _("S_ystem"), "cpuload-color1", ma); - add_color_selector(page, _("N_ice"), "cpuload-color2", ma); - add_color_selector(page, _("I_OWait"), "cpuload-color3", ma); - add_color_selector(page, _("I_dle"), "cpuload-color4", ma); - - page = add_page(ma->notebook, _("Memory")); - gtk_container_set_border_width (GTK_CONTAINER (page), 12); - add_color_selector(page, _("_User"), "memload-color0", ma); - add_color_selector(page, _("Sh_ared"), "memload-color1", ma); - add_color_selector(page, _("_Buffers"), "memload-color2", ma); - add_color_selector (page, _("Cach_ed"), "memload-color3", ma); - add_color_selector(page, _("F_ree"), "memload-color4", ma); - - page = add_page(ma->notebook, _("Network")); - gtk_container_set_border_width (GTK_CONTAINER (page), 12); - add_color_selector (page, _("_In"), "netload2-color0", ma); - add_color_selector(page, _("_Out"), "netload2-color1", ma); - add_color_selector (page, _("_Local"), "netload2-color2", ma); - add_color_selector(page, _("_Background"), "netload2-color3", ma); - add_color_selector(page, _("_Gridline"), "netload2-color4", ma); - add_color_selector(page, _("_Indicator"), "netload2-color5", ma); - - page = add_page(ma->notebook, _("Swap Space")); - gtk_container_set_border_width (GTK_CONTAINER (page), 12); - add_color_selector(page, _("_Used"), "swapload-color0", ma); - add_color_selector(page, _("_Free"), "swapload-color1", ma); - - page = add_page(ma->notebook, _("Load")); - gtk_container_set_border_width (GTK_CONTAINER (page), 12); - add_color_selector(page, _("_Average"), "loadavg-color0", ma); - add_color_selector(page, _("_Background"), "loadavg-color1", ma); - add_color_selector(page, _("_Gridline"), "loadavg-color2", ma); - - page = add_page (ma->notebook, _("Harddisk")); - gtk_container_set_border_width (GTK_CONTAINER (page), 12); - add_color_selector (page, _("_Read"), "diskload-color0", ma); - add_color_selector (page, _("_Write"), "diskload-color1", ma); - add_color_selector (page, _("_Background"), "diskload-color2", ma); - GtkWidget *nvme_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - GtkWidget *nvme_checkbox = gtk_check_button_new_with_mnemonic (_("Use diskstats for NVMe")); - ma->nvme_diskstats = g_settings_get_boolean (ma->settings, "diskload-nvme-diskstats"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (nvme_checkbox), - ma->nvme_diskstats); - g_signal_connect (G_OBJECT (nvme_checkbox), "toggled", - G_CALLBACK (nvme_checkbox_toggled_cb), ma); - gtk_box_pack_start (GTK_BOX(nvme_box), nvme_checkbox, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(page), nvme_box, FALSE, FALSE, 0); - gtk_widget_show (nvme_box); - - title = g_strconcat ("", _("Network speed thresholds"), "", NULL); - label = gtk_label_new (title); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - gtk_label_set_xalign (GTK_LABEL (label), 0.0); - gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); - gtk_widget_show (label); - g_free (title); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - indent = gtk_label_new (HIG_IDENTATION); - gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); - gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); - gtk_widget_show (indent); - - control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); - gtk_widget_show (control_vbox); - - control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); - gtk_widget_show (control_hbox); - - label_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - label_text = g_strdup(_("Threshold 1: ")); - label = gtk_label_new_with_mnemonic(label_text); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_size_group_add_widget (label_size, label); - gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - spin_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD1, MAX_NET_THRESHOLD1, 5); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); - g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(spin_button), "prop_type", - GUINT_TO_POINTER(PROP_NET_THRESHOLD1)); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), - (gdouble)g_settings_get_uint(ma->settings, "netthreshold1")); - g_signal_connect(G_OBJECT(spin_button), "value_changed", - G_CALLBACK(spin_button_changed_cb), "netthreshold1"); - - if ( ! g_settings_is_writable (ma->settings, "netthreshold1")) - { - hard_set_sensitive (label, FALSE); - hard_set_sensitive (hbox, FALSE); - } - - gtk_size_group_add_widget (spin_size, spin_button); - gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); - - label = gtk_label_new (_("bytes")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); - gtk_widget_show (control_hbox); - - label = gtk_label_new_with_mnemonic(_("Threshold 2: ")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_size_group_add_widget (label_size, label); - gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD2, MAX_NET_THRESHOLD2, 5); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); - g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(spin_button), "prop_type", - GINT_TO_POINTER(PROP_NET_THRESHOLD2)); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), - (gdouble)g_settings_get_uint (ma->settings, "netthreshold2")); - g_signal_connect(G_OBJECT(spin_button), "value_changed", - G_CALLBACK(spin_button_changed_cb), "netthreshold2"); - gtk_size_group_add_widget (spin_size, spin_button); - gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, "netthreshold2")) - { - hard_set_sensitive (label, FALSE); - hard_set_sensitive (hbox, FALSE); - } - - label = gtk_label_new(_("bytes")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); - gtk_widget_show (control_hbox); - - label = gtk_label_new_with_mnemonic(_("Threshold 3: ")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_size_group_add_widget (label_size, label); - gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD3, MAX_NET_THRESHOLD3, 5); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); - g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); - g_object_set_data(G_OBJECT(spin_button), "prop_type", - GINT_TO_POINTER(PROP_NET_THRESHOLD3)); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), - (gdouble)g_settings_get_uint (ma->settings, "netthreshold3")); - g_signal_connect(G_OBJECT(spin_button), "value_changed", - G_CALLBACK(spin_button_changed_cb), "netthreshold3"); - gtk_size_group_add_widget (spin_size, spin_button); - gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); - - if ( ! g_settings_is_writable (ma->settings, "netthreshold3")) - { - hard_set_sensitive (label, FALSE); - hard_set_sensitive (hbox, FALSE); - } - - label = gtk_label_new(_("bytes")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0f); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - g_free(label_text); - - category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); - - control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); - gtk_widget_show (control_hbox); - - gtk_widget_show (category_vbox); - - - return; + GtkWidget *page; + GtkWidget *hbox, *vbox; + GtkWidget *categories_vbox; + GtkWidget *category_vbox; + GtkWidget *control_vbox; + GtkWidget *control_hbox; + GtkWidget *check_box; + GtkWidget *indent; + GtkWidget *spin_button; + GtkWidget *label; + MatePanelAppletOrient orient; + GtkSizeGroup *label_size; + GtkSizeGroup *spin_size; + gchar *label_text; + gchar *title; + + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); + gtk_widget_show (vbox); + + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), + vbox, TRUE, TRUE, 0); + + categories_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18); + gtk_box_pack_start (GTK_BOX (vbox), categories_vbox, TRUE, TRUE, 0); + gtk_widget_show (categories_vbox); + + category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); + gtk_widget_show (category_vbox); + + title = g_strconcat ("", _("Monitored Resources"), "", NULL); + label = gtk_label_new_with_mnemonic (_(title)); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); + g_free (title); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + indent = gtk_label_new (HIG_IDENTATION); + gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); + gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); + gtk_widget_show (indent); + + control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); + gtk_widget_show (control_vbox); + + control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); + gtk_widget_show (control_hbox); + + check_box = gtk_check_button_new_with_mnemonic(_("_Processor")); + ma->check_boxes[0] = check_box; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), + g_settings_get_boolean (ma->settings, + VIEW_CPULOAD_KEY)); + g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_CPU)); + g_signal_connect(G_OBJECT(check_box), "toggled", + G_CALLBACK(property_toggled_cb), VIEW_CPULOAD_KEY); + gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, VIEW_CPULOAD_KEY)) + hard_set_sensitive (check_box, FALSE); + + check_box = gtk_check_button_new_with_mnemonic(_("_Memory")); + ma->check_boxes[1] = check_box; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), + g_settings_get_boolean (ma->settings, VIEW_MEMLOAD_KEY)); + g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_MEM)); + g_signal_connect(G_OBJECT(check_box), "toggled", + G_CALLBACK(property_toggled_cb), VIEW_MEMLOAD_KEY); + gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, VIEW_MEMLOAD_KEY)) + hard_set_sensitive (check_box, FALSE); + + check_box = gtk_check_button_new_with_mnemonic(_("_Network")); + ma->check_boxes[2] = check_box; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), + g_settings_get_boolean (ma->settings, VIEW_NETLOAD_KEY)); + g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_NET)); + g_signal_connect(G_OBJECT(check_box), "toggled", + G_CALLBACK(property_toggled_cb), VIEW_NETLOAD_KEY); + gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, VIEW_NETLOAD_KEY)) + hard_set_sensitive (check_box, FALSE); + + check_box = gtk_check_button_new_with_mnemonic (_("S_wap Space")); + ma->check_boxes[3] = check_box; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), + g_settings_get_boolean (ma->settings, VIEW_SWAPLOAD_KEY)); + g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_SWAP)); + g_signal_connect(G_OBJECT(check_box), "toggled", + G_CALLBACK(property_toggled_cb), VIEW_SWAPLOAD_KEY); + gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, VIEW_SWAPLOAD_KEY)) + hard_set_sensitive (check_box, FALSE); + + check_box = gtk_check_button_new_with_mnemonic(_("_Load")); + ma->check_boxes[4] = check_box; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), + g_settings_get_boolean (ma->settings, VIEW_LOADAVG_KEY)); + g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_AVG)); + g_signal_connect(G_OBJECT(check_box), "toggled", + G_CALLBACK(property_toggled_cb), VIEW_LOADAVG_KEY); + gtk_box_pack_start(GTK_BOX(control_hbox), check_box, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, VIEW_LOADAVG_KEY)) + hard_set_sensitive (check_box, FALSE); + + check_box = gtk_check_button_new_with_mnemonic(_("_Harddisk")); + ma->check_boxes[5] = check_box; + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_box), + g_settings_get_boolean (ma->settings, VIEW_DISKLOAD_KEY)); + g_object_set_data (G_OBJECT (check_box), "MultiloadApplet", ma); + g_object_set_data (G_OBJECT (check_box), "prop_type", + GINT_TO_POINTER (PROP_DISK)); + g_signal_connect (G_OBJECT (check_box), "toggled", + G_CALLBACK (property_toggled_cb), VIEW_DISKLOAD_KEY); + gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, VIEW_DISKLOAD_KEY)) + hard_set_sensitive (check_box, FALSE); + + category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); + gtk_widget_show (category_vbox); + + title = g_strconcat ("", _("Options"), "", NULL); + label = gtk_label_new (title); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + g_free (title); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + indent = gtk_label_new (HIG_IDENTATION); + gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); + gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); + gtk_widget_show (indent); + + control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); + gtk_widget_show (control_vbox); + + control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); + gtk_widget_show (control_hbox); + + label_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + orient = mate_panel_applet_get_orient(ma->applet); + if ( (orient == MATE_PANEL_APPLET_ORIENT_UP) || (orient == MATE_PANEL_APPLET_ORIENT_DOWN) ) + label_text = g_strdup(_("System m_onitor width: ")); + else + label_text = g_strdup(_("System m_onitor height: ")); + + label = gtk_label_new_with_mnemonic(label_text); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_size_group_add_widget (label_size, label); + gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + spin_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + spin_button = gtk_spin_button_new_with_range(10, 1000, 5); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); + g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(spin_button), "prop_type", + GINT_TO_POINTER(PROP_SIZE)); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), + (gdouble)g_settings_get_int(ma->settings, "size")); + g_signal_connect(G_OBJECT(spin_button), "value_changed", + G_CALLBACK(spin_button_changed_cb), "size"); + + if ( ! g_settings_is_writable (ma->settings, "size")) { + hard_set_sensitive (label, FALSE); + hard_set_sensitive (hbox, FALSE); + } + + gtk_size_group_add_widget (spin_size, spin_button); + gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); + + label = gtk_label_new (_("pixels")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); + gtk_widget_show (control_hbox); + + label = gtk_label_new_with_mnemonic(_("Sys_tem monitor update interval: ")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_size_group_add_widget (label_size, label); + gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + spin_button = gtk_spin_button_new_with_range(50, 10000, 50); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); + g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(spin_button), "prop_type", + GINT_TO_POINTER(PROP_SPEED)); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), + (gdouble)g_settings_get_int (ma->settings, "speed")); + g_signal_connect(G_OBJECT(spin_button), "value_changed", + G_CALLBACK(spin_button_changed_cb), "speed"); + gtk_size_group_add_widget (spin_size, spin_button); + gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, "speed")) { + hard_set_sensitive (label, FALSE); + hard_set_sensitive (hbox, FALSE); + } + + label = gtk_label_new(_("milliseconds")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + g_free(label_text); + + + category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); + gtk_widget_show (category_vbox); + + title = g_strconcat ("", _("Colors"), "", NULL); + label = gtk_label_new (title); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + g_free (title); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + indent = gtk_label_new (HIG_IDENTATION); + gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); + gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); + gtk_widget_show (indent); + + control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); + gtk_widget_show (control_vbox); + + ma->notebook = gtk_notebook_new(); + gtk_container_add (GTK_CONTAINER (control_vbox), ma->notebook); + + page = add_page(ma->notebook, _("Processor")); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + add_color_selector(page, _("_User"), "cpuload-color0", ma); + add_color_selector(page, _("S_ystem"), "cpuload-color1", ma); + add_color_selector(page, _("N_ice"), "cpuload-color2", ma); + add_color_selector(page, _("I_OWait"), "cpuload-color3", ma); + add_color_selector(page, _("I_dle"), "cpuload-color4", ma); + + page = add_page(ma->notebook, _("Memory")); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + add_color_selector(page, _("_User"), "memload-color0", ma); + add_color_selector(page, _("Sh_ared"), "memload-color1", ma); + add_color_selector(page, _("_Buffers"), "memload-color2", ma); + add_color_selector (page, _("Cach_ed"), "memload-color3", ma); + add_color_selector(page, _("F_ree"), "memload-color4", ma); + + page = add_page(ma->notebook, _("Network")); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + add_color_selector (page, _("_In"), "netload2-color0", ma); + add_color_selector(page, _("_Out"), "netload2-color1", ma); + add_color_selector (page, _("_Local"), "netload2-color2", ma); + add_color_selector(page, _("_Background"), "netload2-color3", ma); + add_color_selector(page, _("_Gridline"), "netload2-color4", ma); + add_color_selector(page, _("_Indicator"), "netload2-color5", ma); + + page = add_page(ma->notebook, _("Swap Space")); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + add_color_selector(page, _("_Used"), "swapload-color0", ma); + add_color_selector(page, _("_Free"), "swapload-color1", ma); + + page = add_page(ma->notebook, _("Load")); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + add_color_selector(page, _("_Average"), "loadavg-color0", ma); + add_color_selector(page, _("_Background"), "loadavg-color1", ma); + add_color_selector(page, _("_Gridline"), "loadavg-color2", ma); + + page = add_page (ma->notebook, _("Harddisk")); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + add_color_selector (page, _("_Read"), "diskload-color0", ma); + add_color_selector (page, _("_Write"), "diskload-color1", ma); + add_color_selector (page, _("_Background"), "diskload-color2", ma); + GtkWidget *nvme_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + GtkWidget *nvme_checkbox = gtk_check_button_new_with_mnemonic (_("Use diskstats for NVMe")); + ma->nvme_diskstats = g_settings_get_boolean (ma->settings, "diskload-nvme-diskstats"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (nvme_checkbox), + ma->nvme_diskstats); + g_signal_connect (G_OBJECT (nvme_checkbox), "toggled", + G_CALLBACK (nvme_checkbox_toggled_cb), ma); + gtk_box_pack_start (GTK_BOX(nvme_box), nvme_checkbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(page), nvme_box, FALSE, FALSE, 0); + gtk_widget_show (nvme_box); + + title = g_strconcat ("", _("Network speed thresholds"), "", NULL); + label = gtk_label_new (title); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + g_free (title); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + indent = gtk_label_new (HIG_IDENTATION); + gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); + gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); + gtk_widget_show (indent); + + control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); + gtk_widget_show (control_vbox); + + control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); + gtk_widget_show (control_hbox); + + label_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + label_text = g_strdup(_("Threshold 1: ")); + label = gtk_label_new_with_mnemonic(label_text); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_size_group_add_widget (label_size, label); + gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + spin_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD1, MAX_NET_THRESHOLD1, 5); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); + g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(spin_button), "prop_type", + GUINT_TO_POINTER(PROP_NET_THRESHOLD1)); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), + (gdouble)g_settings_get_uint(ma->settings, "netthreshold1")); + g_signal_connect(G_OBJECT(spin_button), "value_changed", + G_CALLBACK(spin_button_changed_cb), "netthreshold1"); + + if ( ! g_settings_is_writable (ma->settings, "netthreshold1")) + { + hard_set_sensitive (label, FALSE); + hard_set_sensitive (hbox, FALSE); + } + + gtk_size_group_add_widget (spin_size, spin_button); + gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); + + label = gtk_label_new (_("bytes")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); + gtk_widget_show (control_hbox); + + label = gtk_label_new_with_mnemonic(_("Threshold 2: ")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_size_group_add_widget (label_size, label); + gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD2, MAX_NET_THRESHOLD2, 5); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); + g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(spin_button), "prop_type", + GINT_TO_POINTER(PROP_NET_THRESHOLD2)); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), + (gdouble)g_settings_get_uint (ma->settings, "netthreshold2")); + g_signal_connect(G_OBJECT(spin_button), "value_changed", + G_CALLBACK(spin_button_changed_cb), "netthreshold2"); + gtk_size_group_add_widget (spin_size, spin_button); + gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, "netthreshold2")) + { + hard_set_sensitive (label, FALSE); + hard_set_sensitive (hbox, FALSE); + } + + label = gtk_label_new(_("bytes")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); + gtk_widget_show (control_hbox); + + label = gtk_label_new_with_mnemonic(_("Threshold 3: ")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_size_group_add_widget (label_size, label); + gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD3, MAX_NET_THRESHOLD3, 5); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); + g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); + g_object_set_data(G_OBJECT(spin_button), "prop_type", + GINT_TO_POINTER(PROP_NET_THRESHOLD3)); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), + (gdouble)g_settings_get_uint (ma->settings, "netthreshold3")); + g_signal_connect(G_OBJECT(spin_button), "value_changed", + G_CALLBACK(spin_button_changed_cb), "netthreshold3"); + gtk_size_group_add_widget (spin_size, spin_button); + gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); + + if ( ! g_settings_is_writable (ma->settings, "netthreshold3")) + { + hard_set_sensitive (label, FALSE); + hard_set_sensitive (hbox, FALSE); + } + + label = gtk_label_new(_("bytes")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + g_free(label_text); + + category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); + + control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); + gtk_widget_show (control_hbox); + + gtk_widget_show (category_vbox); + + return; } /* show properties dialog */ void multiload_properties_cb (GtkAction *action, - MultiloadApplet *ma) + MultiloadApplet *ma) { - GtkWidget *dialog = NULL; + GtkWidget *dialog = NULL; - if (ma->prop_dialog) { - dialog = ma->prop_dialog; + if (ma->prop_dialog) { + dialog = ma->prop_dialog; - gtk_window_set_screen (GTK_WINDOW (dialog), - gtk_widget_get_screen (GTK_WIDGET (ma->applet))); + gtk_window_set_screen (GTK_WINDOW (dialog), + gtk_widget_get_screen (GTK_WIDGET (ma->applet))); - gtk_notebook_set_current_page (GTK_NOTEBOOK (ma->notebook), - ma->last_clicked); - gtk_window_present (GTK_WINDOW (dialog)); - return; - } + gtk_notebook_set_current_page (GTK_NOTEBOOK (ma->notebook), + ma->last_clicked); + gtk_window_present (GTK_WINDOW (dialog)); + return; + } - dialog = gtk_dialog_new_with_buttons (_("System Monitor Preferences"), - NULL, 0, - "gtk-help", GTK_RESPONSE_HELP, - "gtk-close", GTK_RESPONSE_CLOSE, - NULL); - gtk_window_set_screen (GTK_WINDOW (dialog), - gtk_widget_get_screen (GTK_WIDGET (ma->applet))); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2); + dialog = gtk_dialog_new_with_buttons (_("System Monitor Preferences"), + NULL, 0, + "gtk-help", GTK_RESPONSE_HELP, + "gtk-close", GTK_RESPONSE_CLOSE, + NULL); + gtk_window_set_screen (GTK_WINDOW (dialog), + gtk_widget_get_screen (GTK_WIDGET (ma->applet))); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2); - fill_properties(dialog, ma); + fill_properties(dialog, ma); - properties_set_insensitive(ma); + properties_set_insensitive(ma); - g_signal_connect(G_OBJECT(dialog), "response", - G_CALLBACK(properties_close_cb), ma); + g_signal_connect(G_OBJECT(dialog), "response", + G_CALLBACK(properties_close_cb), ma); - ma->prop_dialog = dialog; + ma->prop_dialog = dialog; - gtk_widget_show_all(dialog); + gtk_widget_show_all(dialog); - gtk_notebook_set_current_page (GTK_NOTEBOOK (ma->notebook), - ma->last_clicked); + gtk_notebook_set_current_page (GTK_NOTEBOOK (ma->notebook), + ma->last_clicked); } -- cgit v1.2.1