diff --git a/src/main.c b/src/main.c index 1244bd6..e877c6c 100644 --- a/src/main.c +++ b/src/main.c @@ -22,12 +22,14 @@ #include "process-window.h" #include "task-manager.h" +#include "network.h" + static XtmSettings *settings; static GtkWidget *window; static GtkStatusIcon *status_icon; static XtmTaskManager *task_manager; static gboolean timeout = 0; - +static NetworkUsage oldNetworkUsage; static void status_icon_activated (void) { @@ -88,15 +90,18 @@ init_timeout (void) guint num_processes; gfloat cpu, memory_percent, swap_percent; guint64 swap_used, swap_free, swap_total, memory_used, memory_total; - gchar *used, *total, tooltip[1024], memory_info[64], swap_info[64]; + gchar *used, *total, tooltip[1024], memory_info[64], swap_info[64],network_down_info[64],network_up_info[64]; gboolean show_memory_in_xbytes; - + guint refresh_rate; + xtm_task_manager_get_system_info (task_manager, &num_processes, &cpu, &memory_used, &memory_total, &swap_used, &swap_total); memory_percent = (memory_total != 0) ? memory_used * 100 / (gdouble)memory_total : 0; swap_percent = (swap_total != 0) ? swap_used * 100 / (gdouble)swap_total : 0; g_object_get (settings, "show-memory-in-xbytes", &show_memory_in_xbytes, NULL); + g_object_get (settings, "refresh-rate", &refresh_rate, NULL); + if (show_memory_in_xbytes) { used = g_format_size_full(memory_used, G_FORMAT_SIZE_IEC_UNITS); total = g_format_size_full(memory_total, G_FORMAT_SIZE_IEC_UNITS); @@ -114,7 +119,18 @@ init_timeout (void) g_snprintf (swap_info, 64, "%.0f%%", swap_percent); } - xtm_process_window_set_system_info (XTM_PROCESS_WINDOW (window), num_processes, cpu, memory_percent, memory_info, swap_percent, swap_info); + NetworkUsage network_usage; + readNetworkUsageFromSys(&network_usage); + double network_down_info_value = 0; + double network_up_info_value = 0; + if (timeout != 0) { + network_down_info_value=(network_usage.download-oldNetworkUsage.download)/(1024.0*(refresh_rate/1000.0)); + network_up_info_value=(network_usage.upload-oldNetworkUsage.upload)/(1024.0*(refresh_rate/1000.0)); + } + oldNetworkUsage = network_usage; + g_snprintf (network_down_info, 64 ,"%.2f KB",(network_down_info_value)); + g_snprintf (network_up_info, 64 ,"%.2f KB",(network_up_info_value)); + xtm_process_window_set_system_info (XTM_PROCESS_WINDOW (window), num_processes, cpu, memory_percent, memory_info, swap_percent, swap_info,network_down_info,network_up_info); xtm_task_manager_get_swap_usage (task_manager, &swap_free, &swap_total); xtm_process_window_show_swap_usage (XTM_PROCESS_WINDOW (window), (swap_total > 0)); @@ -144,8 +160,6 @@ init_timeout (void) if (timeout == 0) { - guint refresh_rate; - g_object_get (settings, "refresh-rate", &refresh_rate, NULL); timeout = g_timeout_add (refresh_rate, (GSourceFunc)init_timeout, NULL); } diff --git a/src/process-statusbar.c b/src/process-statusbar.c index 3bb7e34..ac754cf 100644 --- a/src/process-statusbar.c +++ b/src/process-statusbar.c @@ -25,6 +25,8 @@ enum PROP_CPU = 1, PROP_MEMORY, PROP_SWAP, + PROP_NETWORK_UP, + PROP_NETWORK_DOWN, PROP_SHOW_SWAP, PROP_NUM_PROCESSES, }; @@ -43,10 +45,14 @@ struct _XtmProcessStatusbar GtkWidget * label_cpu; GtkWidget * label_memory; GtkWidget * label_swap; + GtkWidget * label_up_network; + GtkWidget * label_down_network; gfloat cpu; gchar memory[64]; gchar swap[64]; + gchar network_down[64]; + gchar network_up[64]; guint num_processes; }; G_DEFINE_TYPE (XtmProcessStatusbar, xtm_process_statusbar, GTK_TYPE_BOX) @@ -69,6 +75,10 @@ xtm_process_statusbar_class_init (XtmProcessStatusbarClass *klass) g_param_spec_string ("memory", "Memory", "Memory usage", "", G_PARAM_CONSTRUCT|G_PARAM_WRITABLE)); g_object_class_install_property (class, PROP_SWAP, g_param_spec_string ("swap", "Swap", "Swap usage", "", G_PARAM_CONSTRUCT|G_PARAM_WRITABLE)); + g_object_class_install_property (class, PROP_NETWORK_DOWN, + g_param_spec_string ("network_down", "Network Download", "Network Download usage", "", G_PARAM_CONSTRUCT|G_PARAM_WRITABLE)); + g_object_class_install_property (class, PROP_NETWORK_UP, + g_param_spec_string ("network_up", "Network Upload", "Network Upload usage", "", G_PARAM_CONSTRUCT|G_PARAM_WRITABLE)); g_object_class_install_property (class, PROP_SHOW_SWAP, g_param_spec_boolean ("show-swap", "ShowSwap", "Show or hide swap usage", TRUE, G_PARAM_WRITABLE)); g_object_class_install_property (class, PROP_NUM_PROCESSES, @@ -78,17 +88,19 @@ xtm_process_statusbar_class_init (XtmProcessStatusbarClass *klass) static void xtm_process_statusbar_init (XtmProcessStatusbar *statusbar) { - GtkWidget *hbox, *hbox_cpu, *hbox_mem; + GtkWidget *hbox, *hbox_cpu, *hbox_mem,*hbox_network; statusbar->settings = xtm_settings_get_default (); #if GTK_CHECK_VERSION(3, 0, 0) hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 16); hbox_cpu = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 16); hbox_mem = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 16); + hbox_network = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 16); #else hbox = gtk_hbox_new (FALSE, 16); hbox_cpu = gtk_hbox_new (FALSE, 16); hbox_mem = gtk_hbox_new (FALSE, 16); + hbox_network = gtk_hbox_new (FALSE, 16); #endif statusbar->label_cpu = gtk_label_new (NULL); @@ -103,8 +115,15 @@ xtm_process_statusbar_init (XtmProcessStatusbar *statusbar) statusbar->label_swap = gtk_label_new (NULL); gtk_box_pack_start (GTK_BOX (hbox_mem), statusbar->label_swap, TRUE, FALSE, 0); + statusbar->label_down_network = gtk_label_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox_network), statusbar->label_down_network, TRUE, FALSE, 0); + + statusbar->label_up_network = gtk_label_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox_network), statusbar->label_up_network, TRUE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), hbox_cpu, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), hbox_mem, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), hbox_network, TRUE, TRUE, 0); gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE); gtk_box_pack_start (GTK_BOX (statusbar), hbox, TRUE, TRUE, 0); @@ -178,6 +197,20 @@ xtm_process_statusbar_set_property (GObject *object, guint property_id, const GV g_free (text); break; + case PROP_NETWORK_DOWN: + g_strlcpy(statusbar->network_down, g_value_get_string (value), 64); + text = g_strdup_printf (_("Down: %s"), statusbar->network_down); + gtk_label_set_text (GTK_LABEL (statusbar->label_down_network), text); + g_free (text); + break; + + case PROP_NETWORK_UP: + g_strlcpy(statusbar->network_up, g_value_get_string (value), 64); + text = g_strdup_printf (_("Up: %s"), statusbar->network_up); + gtk_label_set_text (GTK_LABEL (statusbar->label_up_network), text); + g_free (text); + break; + case PROP_SHOW_SWAP: if (g_value_get_boolean (value)) gtk_widget_show (statusbar->label_swap); diff --git a/src/process-window.c b/src/process-window.c index 86f84db..26b042f 100644 --- a/src/process-window.c +++ b/src/process-window.c @@ -32,6 +32,7 @@ #include "process-statusbar.h" #include "exec-tool-button.h" #include "settings-tool-button.h" +#include "network.h" @@ -443,7 +444,7 @@ xtm_process_window_get_model (XtmProcessWindow *window) } void -xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str) +xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str,gchar* network_down_usage,gchar* network_up_usage) { gchar text[100]; gchar value[4]; @@ -451,7 +452,8 @@ xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processe g_return_if_fail (XTM_IS_PROCESS_WINDOW (window)); g_return_if_fail (GTK_IS_BOX (window->statusbar)); - g_object_set (window->statusbar, "num-processes", num_processes, "cpu", cpu, "memory", memory_str, "swap", swap_str, NULL); + g_object_set (window->statusbar, "num-processes", num_processes, "cpu", cpu, "memory", memory_str, "swap", swap_str, "network_down",network_down_usage, "network_up",network_up_usage,NULL); + // g_object_set (window->statusbar, "num-processes", num_processes, "cpu", cpu, "memory", memory_str, "swap", swap_str,NULL); xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->cpu_monitor), cpu / 100.0); g_snprintf (value, 4, "%.0f", cpu); diff --git a/src/process-window.h b/src/process-window.h index 1203186..91d7b4e 100644 --- a/src/process-window.h +++ b/src/process-window.h @@ -30,7 +30,7 @@ GType xtm_process_window_get_type (void); GtkWidget * xtm_process_window_new (void); void xtm_process_window_show (GtkWidget *widget); GtkTreeModel * xtm_process_window_get_model (XtmProcessWindow *window); -void xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str); +void xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str,gchar* network_down_usage,gchar* network_up_usage); void xtm_process_window_show_swap_usage (XtmProcessWindow *window, gboolean show_swap_usage); #endif /* !PROCESS_WINDOW_H */