diff options
author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-05 02:59:47 +0000 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-05 02:59:47 +0000 |
commit | 5c78971c19a9f941c896b2c818d45319b64651b3 (patch) | |
tree | e5d69148d5d38427f3152ae486f4ce5685adea65 /hardinfo2 | |
parent | a1054182ecd202db45cde1883991d70dbb954763 (diff) |
LoadGraph optimizations, enhancements and cleanups.
Diffstat (limited to 'hardinfo2')
-rw-r--r-- | hardinfo2/arch/linux/common/devmemory.h | 35 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/net.h | 5 | ||||
-rw-r--r-- | hardinfo2/benchmark.c | 2 | ||||
-rw-r--r-- | hardinfo2/callbacks.c | 7 | ||||
-rw-r--r-- | hardinfo2/computer.c | 2 | ||||
-rw-r--r-- | hardinfo2/devices.c | 6 | ||||
-rw-r--r-- | hardinfo2/hardinfo.c | 6 | ||||
-rw-r--r-- | hardinfo2/loadgraph.c | 92 | ||||
-rw-r--r-- | hardinfo2/loadgraph.h | 10 | ||||
-rw-r--r-- | hardinfo2/menu.c | 2 | ||||
-rw-r--r-- | hardinfo2/shell.c | 109 | ||||
-rw-r--r-- | hardinfo2/shell.h | 7 |
12 files changed, 167 insertions, 116 deletions
diff --git a/hardinfo2/arch/linux/common/devmemory.h b/hardinfo2/arch/linux/common/devmemory.h index 0adea960..cc4b1582 100644 --- a/hardinfo2/arch/linux/common/devmemory.h +++ b/hardinfo2/arch/linux/common/devmemory.h @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +static GHashTable *memlabels; + static void __scan_memory() { gchar **keys, *tmp; @@ -41,13 +43,18 @@ static void __scan_memory() g_strstrip(newkeys[1]); + if ((tmp = g_hash_table_lookup(memlabels, newkeys[0]))) { + g_free(newkeys[0]); + newkeys[0] = g_strdup(tmp); + } + g_hash_table_replace(moreinfo, g_strdup(newkeys[0]), g_strdup(newkeys[1])); + tmp = g_strconcat(meminfo, newkeys[0], "=", newkeys[1], "\n", NULL); g_free(meminfo); meminfo = tmp; tmp = g_strconcat(lginterval, - "LoadGraphInterval$", newkeys[0], "=500\n", "UpdateInterval$", newkeys[0], "=1000\n", NULL); g_free(lginterval); lginterval = tmp; @@ -56,3 +63,29 @@ static void __scan_memory() } g_strfreev(keys); } + +static void __init_memory_labels(void) +{ + static struct { + char *proc_label; + char *real_label; + } proc2real[] = { + { "MemTotal", "Total Memory" }, + { "MemFree", "Free Memory" }, + { "SwapCached", "Cached Swap" }, + { "HighTotal", "High Memory" }, + { "HighFree", "Free High Memory" }, + { "LowTotal", "Low Memory" }, + { "LowFree", "Free Low Memory" }, + { "SwapTotal", "Virtual Memory" }, + { "SwapFree", "Free Virtual Memory" }, + { NULL }, + }; + gint i; + + memlabels = g_hash_table_new(g_str_hash, g_str_equal); + + for (i = 0; proc2real[i].proc_label; i++) { + g_hash_table_insert(memlabels, proc2real[i].proc_label, proc2real[i].real_label); + } +} diff --git a/hardinfo2/arch/linux/common/net.h b/hardinfo2/arch/linux/common/net.h index 593baf8f..1d2e20ea 100644 --- a/hardinfo2/arch/linux/common/net.h +++ b/hardinfo2/arch/linux/common/net.h @@ -194,13 +194,14 @@ scan_net_interfaces_24(void) get_net_info(ifacename, &ni); devid = g_strdup_printf("NET%s", ifacename); - network_interfaces = g_strdup_printf("%s$%s$%s=Sent %.2fMiB, received %.2fMiB (%s)\n", + network_interfaces = g_strdup_printf("%s$%s$%s=Sent %.2fMiB, received %.2fMiB%s\n", network_interfaces, devid, ifacename, trans_mb, recv_mb, - ni.ip[0] ? ni.ip : "No IP address"); + ni.ip[0] ? + (gchar*)idle_free(g_strdup_printf(" (%s)", ni.ip)) : ""); detailed = g_strdup_printf("[Network Adapter Properties]\n" "Interface Type=%s\n" diff --git a/hardinfo2/benchmark.c b/hardinfo2/benchmark.c index 5462bccc..601329ce 100644 --- a/hardinfo2/benchmark.c +++ b/hardinfo2/benchmark.c @@ -229,7 +229,7 @@ hi_module_get_about(void) { static ModuleAbout ma[] = { { - .author = "Leandro A. F. Pereira (leandro@linuxmag.com.br)", + .author = "Leandro A. F. Pereira", .version = VERSION, .license = "GNU GPL version 2" } diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index 69201d82..51035e63 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -127,7 +127,7 @@ void cb_about_module(GtkAction *action) GSList *modules = shell->tree->modules; ModuleAbout *ma; gchar *name; - + g_object_get(G_OBJECT(action), "tooltip", &name, NULL); for (; modules; modules = modules->next) { @@ -140,7 +140,8 @@ void cb_about_module(GtkAction *action) GtkWidget *about; about = gtk_about_dialog_new(); - gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), sm->name); + gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), + idle_free(g_strdup_printf("%s Module", sm->name))); gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), ma->version); gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), idle_free(g_strdup_printf("Written by %s", ma->author))); @@ -152,7 +153,7 @@ void cb_about_module(GtkAction *action) gtk_dialog_run(GTK_DIALOG(about)); gtk_widget_destroy(about); } else { - g_warning("No about information is associated with this module."); + g_warning("No about information is associated with the %s module.", name); } break; diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c index a4a53c9a..fe1f594e 100644 --- a/hardinfo2/computer.c +++ b/hardinfo2/computer.c @@ -395,7 +395,7 @@ hi_module_get_about(void) { static ModuleAbout ma[] = { { - .author = "Leandro A. F. Pereira (leandro@linuxmag.com.br)", + .author = "Leandro A. F. Pereira", .version = VERSION, .license = "GNU GPL version 2" } diff --git a/hardinfo2/devices.c b/hardinfo2/devices.c index b5d97f07..9f377f46 100644 --- a/hardinfo2/devices.c +++ b/hardinfo2/devices.c @@ -185,7 +185,7 @@ hi_more_info(gchar * entry) if (info) return g_strdup(info); - return g_strdup("[TSC]"); + return g_strdup("?"); } gchar * @@ -289,6 +289,7 @@ callback_memory() "%s\n" "[$ShellParam$]\n" "ViewType=2\n" + "LoadGraphSuffix= kB\n" "RescanInterval=2000\n" "%s\n", meminfo, @@ -380,6 +381,7 @@ void hi_module_init(void) { moreinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + __init_memory_labels(); } ModuleAbout * @@ -387,7 +389,7 @@ hi_module_get_about(void) { static ModuleAbout ma[] = { { - .author = "Leandro A. F. Pereira (leandro@linuxmag.com.br)", + .author = "Leandro A. F. Pereira", .version = VERSION, .license = "GNU GPL version 2" } diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index 8178d792..fa80dd3e 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -72,13 +72,15 @@ main(int argc, char **argv) /* list all module names */ if (params.list_modules) { g_print("Modules:\n" - "%-20s%s\n", "File Name", "Name"); + "%-20s%-15s%-12s%-20s\n", "File Name", "Name", "Version", "Author"); for (modules = modules_load_all(); modules; modules = modules->next) { ShellModule *module = (ShellModule *) modules->data; + ModuleAbout *ma = module_get_about(module); gchar *name = g_path_get_basename(g_module_name(module->dll)); - g_print("%-20s%s\n", name, module->name); + g_print("%-20s%-15s%-12s%-20s\n", + name, module->name, ma->version, ma->author); g_free(name); } diff --git a/hardinfo2/loadgraph.c b/hardinfo2/loadgraph.c index ac487c78..4600516e 100644 --- a/hardinfo2/loadgraph.c +++ b/hardinfo2/loadgraph.c @@ -33,6 +33,9 @@ LoadGraph *load_graph_new(gint size) lg = g_new0(LoadGraph, 1); + size++; + + lg->suffix = g_strdup(""); lg->area = gtk_drawing_area_new(); lg->size = size; lg->data = g_new0(gint, size); @@ -42,22 +45,26 @@ LoadGraph *load_graph_new(gint size) lg->width = size * 4; lg->height = size * 2; - lg->max_value = -1; + lg->max_value = 1; + lg->remax_count = 0; + lg->layout = pango_layout_new(gtk_widget_get_pango_context (lg->area)); + gtk_widget_set_size_request(lg->area, lg->width, lg->height); gtk_widget_show(lg->area); return lg; } -int load_graph_get_max(LoadGraph *lg) +void load_graph_set_data_suffix(LoadGraph *lg, gchar *suffix) { - return lg->max_value; + g_free(lg->suffix); + lg->suffix = g_strdup(suffix); } -void load_graph_set_max(LoadGraph *lg, gint value) +gchar *load_graph_get_data_suffix(LoadGraph *lg) { - lg->max_value = value; + return lg->suffix; } GtkWidget *load_graph_get_framed(LoadGraph *lg) @@ -85,7 +92,9 @@ void load_graph_clear(LoadGraph *lg) lg->data[i] = 0; lg->scale = 1.0; -// lg->max_value = -1; + lg->max_value = 1; + lg->remax_count = 0; + _draw(lg); } @@ -102,6 +111,7 @@ void load_graph_destroy(LoadGraph *lg) gdk_pixmap_unref(lg->buf); g_object_unref(lg->trace); g_object_unref(lg->grid); + g_object_unref(lg->layout); g_free(lg); } @@ -151,6 +161,27 @@ void load_graph_configure_expose(LoadGraph *lg) } static void +_draw_label_and_line(LoadGraph *lg, gint position, gint value) +{ + gchar *tmp; + + /* draw lines */ + if (position > 0) + gdk_draw_line(GDK_DRAWABLE(lg->buf), lg->grid, 0, position, lg->width, position); + else + position = -1 * position; + + /* draw label */ + tmp = g_strdup_printf("<span size=\"x-small\">%d%s</span>", value, lg->suffix); + + pango_layout_set_markup(lg->layout, tmp, -1); + pango_layout_set_width(lg->layout, lg->area->allocation.width * PANGO_SCALE); + gdk_draw_layout(GDK_DRAWABLE(lg->buf), lg->trace, 2, position, lg->layout); + + g_free(tmp); +} + +static void _draw(LoadGraph *lg) { GdkDrawable *draw = GDK_DRAWABLE(lg->buf); @@ -184,21 +215,13 @@ _draw(LoadGraph *lg) i * 4 + 4, next); } - gtk_widget_queue_draw(lg->area); -} + /* horizontal bars; 25%, 50% and 75% */ + _draw_label_and_line(lg, -1, lg->max_value); + _draw_label_and_line(lg, lg->height / 4, 3 * (lg->max_value / 4)); + _draw_label_and_line(lg, lg->height / 2, lg->max_value / 2); + _draw_label_and_line(lg, 3 * (lg->height / 4), lg->max_value / 4); -static inline int -_max(LoadGraph *lg) -{ - gint i; - gint max = 1.0; - - for (i = 0; i < lg->size; i++) { - if (lg->data[i] > max) - max = lg->data[i]; - } - - return max; + gtk_widget_queue_draw(lg->area); } void @@ -209,14 +232,6 @@ load_graph_update(LoadGraph *lg, gint value) if (value < 0) return; - if (lg->max_value < 0) { - lg->scale = (gfloat)lg->height / (gfloat)_max(lg); - } else { - lg->scale = (gfloat)lg->height / (gfloat)lg->max_value; - - g_print("using max value %d; scale is %f\n", lg->max_value, lg->scale); - } - /* shift-right our data */ for (i = 0; i < lg->size; i++) { lg->data[i] = lg->data[i+1]; @@ -225,6 +240,27 @@ load_graph_update(LoadGraph *lg, gint value) /* insert the updated value */ lg->data[i] = value; + /* calculates the maximum value */ + if (lg->remax_count++ > 20) { + /* only finds the maximum amongst the data every 20 times */ + lg->remax_count = 0; + + gint max = lg->data[0]; + for (i = 1; i < lg->size; i++) { + if (lg->data[i] > max) + max = lg->data[i]; + } + + lg->max_value = max; + } else { + /* otherwise, select the maximum between the current maximum + and the supplied value */ + lg->max_value = MAX(value, lg->max_value); + } + + /* recalculates the scale; always use 90% of it */ + lg->scale = 0.90 * ((gfloat)lg->height / (gfloat)lg->max_value); + /* redraw */ _draw(lg); } diff --git a/hardinfo2/loadgraph.h b/hardinfo2/loadgraph.h index 93185af0..d9d3fa7c 100644 --- a/hardinfo2/loadgraph.h +++ b/hardinfo2/loadgraph.h @@ -47,7 +47,10 @@ struct _LoadGraph { gint width, height; LoadGraphColor color; - gint max_value; + gint max_value, remax_count; + + PangoLayout *layout; + gchar *suffix; }; LoadGraph *load_graph_new(gint size); @@ -56,9 +59,10 @@ void load_graph_configure_expose(LoadGraph *lg); GtkWidget *load_graph_get_framed(LoadGraph *lg); void load_graph_update(LoadGraph *lg, gint value); -void load_graph_set_max(LoadGraph *lg, gint value); -int load_graph_get_max(LoadGraph *lg); void load_graph_set_color(LoadGraph *lg, LoadGraphColor color); void load_graph_clear(LoadGraph *lg); +void load_graph_set_data_suffix(LoadGraph *lg, gchar *suffix); +gchar *load_graph_get_data_suffix(LoadGraph *lg); + #endif /* __LOADGRAPH_H__ */ diff --git a/hardinfo2/menu.c b/hardinfo2/menu.c index c3994dd4..46b4568e 100644 --- a/hardinfo2/menu.c +++ b/hardinfo2/menu.c @@ -33,7 +33,7 @@ static GtkActionEntry entries[] = { "InformationMenuAction", NULL, "_Information" }, /* name, stock id, label */ { "ViewMenuAction", NULL, "_View" }, { "HelpMenuAction", NULL, "_Help" }, - { "HelpMenuModulesAction", NULL, "About _Modules" }, + { "HelpMenuModulesAction", HI_STOCK_ABOUT_MODULES, "About _Modules" }, { "MainMenuBarAction", NULL, "" }, { "ReportAction", HI_STOCK_REPORT, /* name, stock id */ diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index dd2f46ba..1f2e99f1 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -38,7 +38,7 @@ static void create_window(); static ShellTree *tree_new(void); static ShellInfoTree *info_tree_new(gboolean extra); -static void module_selected(GtkTreeSelection * ts, gpointer data); +static void module_selected(gpointer data); static void module_selected_show_info(ShellModuleEntry * entry, gboolean reload); static void info_selected(GtkTreeSelection * ts, gpointer data); @@ -275,13 +275,10 @@ void shell_do_reload(void) shell_action_set_enabled("ReportAction", FALSE); if (shell->selected) { - GtkTreeSelection *ts; - - ts = gtk_tree_view_get_selection(GTK_TREE_VIEW(shell->tree->view)); shell_status_set_enabled(TRUE); module_entry_reload(shell->selected); - module_selected(ts, NULL); + module_selected(NULL); } shell_action_set_enabled("RefreshAction", TRUE); @@ -303,8 +300,7 @@ void shell_status_update(const gchar * message) static void destroy_me(void) { - gtk_main_quit(); - exit(0); + cb_quit(); } static void create_window(void) @@ -360,14 +356,12 @@ static void create_window(void) static void view_menu_select_entry(gpointer data, gpointer data2) { - GtkTreeSelection *ts; GtkTreePath *path; GtkTreeIter *iter = (GtkTreeIter *) data2; - ts = gtk_tree_view_get_selection(GTK_TREE_VIEW(shell->tree->view)); path = gtk_tree_model_get_path(shell->tree->model, iter); - gtk_tree_selection_select_path(ts, path); + gtk_tree_selection_select_path(shell->tree->selection, path); gtk_tree_view_set_cursor(GTK_TREE_VIEW(shell->tree->view), path, NULL, FALSE); gtk_tree_path_free(path); @@ -545,36 +539,28 @@ static gboolean update_field(gpointer data) /* if the entry is still selected, update it */ if (fu->entry->selected && fu->entry->fieldfunc) { - gchar *value = fu->entry->fieldfunc(fu->field_name); - GtkTreeIter *iter = - g_hash_table_lookup(update_tbl, fu->field_name); - - /* this function is also used to feed the load graph when ViewType = - SHELL_VIEW_LOAD_GRAPH */ - if (fu->loadgraph && shell->view_type == SHELL_VIEW_LOAD_GRAPH) { - GtkTreeSelection *ts; - - ts = gtk_tree_view_get_selection(GTK_TREE_VIEW - (shell->info->view)); - - if (iter && gtk_tree_selection_iter_is_selected(ts, iter)) { - load_graph_update(shell->loadgraph, atoi(value)); - } - - g_free(value); - - return TRUE; - } - - if (iter) { - GtkTreeStore *store = GTK_TREE_STORE(shell->info->model); - - gtk_tree_store_set(store, iter, INFO_TREE_COL_VALUE, - value, -1); - g_free(value); - - return TRUE; - } + GtkTreeIter *iter = g_hash_table_lookup(update_tbl, + fu->field_name); + + if (iter) { + GtkTreeStore *store = GTK_TREE_STORE(shell->info->model); + gchar *value = fu->entry->fieldfunc(fu->field_name); + + /* + * this function is also used to feed the load graph when ViewType + * is SHELL_VIEW_LOAD_GRAPH + */ + if (shell->view_type == SHELL_VIEW_LOAD_GRAPH && + gtk_tree_selection_iter_is_selected(shell->info->selection, + iter)) { + load_graph_update(shell->loadgraph, atoi(value)); + } + + gtk_tree_store_set(store, iter, INFO_TREE_COL_VALUE, value, -1); + + g_free(value); + return TRUE; + } } /* otherwise, cleanup and destroy the timeout */ @@ -591,13 +577,11 @@ static gboolean reload_section(gpointer data) /* if the entry is still selected, update it */ if (entry->selected) { GtkTreePath *path = NULL; - GtkTreeSelection *ts; GtkTreeIter iter; /* gets the current selected path */ - ts = gtk_tree_view_get_selection(GTK_TREE_VIEW(shell->info->view)); if (gtk_tree_selection_get_selected - (ts, &shell->info->model, &iter)) + (shell->info->selection, &shell->info->model, &iter)) path = gtk_tree_model_get_path(shell->info->model, &iter); /* update the information, clear the treeview and populate it again */ @@ -607,7 +591,7 @@ static gboolean reload_section(gpointer data) /* if there was a selection, reselect it */ if (path) { - gtk_tree_selection_select_path(ts, path); + gtk_tree_selection_select_path(shell->info->selection, path); gtk_tree_path_free(path); } } @@ -722,26 +706,12 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry, fu->field_name = g_strdup(strchr(key, '$') + 1); fu->entry = entry; - fu->loadgraph = FALSE; g_timeout_add(ms, update_field, fu); - } else if (g_str_has_prefix(key, "LoadGraphInterval")) { - gint ms; - ShellFieldUpdate *fu = g_new0(ShellFieldUpdate, 1); - - ms = g_key_file_get_integer(key_file, group, key, NULL); - - fu->field_name = g_strdup(strchr(key, '$') + 1); - fu->entry = entry; - fu->loadgraph = TRUE; - - g_timeout_add(ms, update_field, fu); - } else if (g_str_equal(key, "LoadGraphMaxValue")) { - gint max_value; - - max_value = - g_key_file_get_integer(key_file, group, key, NULL); - load_graph_set_max(shell->loadgraph, max_value); + } else if (g_str_equal(key, "LoadGraphSuffix")) { + gchar *suffix = g_key_file_get_value(key_file, group, key, NULL); + load_graph_set_data_suffix(shell->loadgraph, suffix); + g_free(suffix); } else if (g_str_equal(key, "ReloadInterval")) { gint ms; @@ -1041,7 +1011,7 @@ static void info_selected_show_extra(gchar * data) } } -static void module_selected(GtkTreeSelection * ts, gpointer data) +static void module_selected(gpointer data) { ShellTree *shelltree = shell->tree; GtkTreeModel *model = GTK_TREE_MODEL(shelltree->model); @@ -1057,7 +1027,7 @@ static void module_selected(GtkTreeSelection * ts, gpointer data) /* Gets the currently selected item on the left-side TreeView; if there is no selection, silently return */ - if (!gtk_tree_selection_get_selected(ts, &model, &parent)) + if (!gtk_tree_selection_get_selected(shelltree->selection, &model, &parent)) return; /* Mark the currently selected module as "unselected"; this is used to kill the @@ -1137,6 +1107,7 @@ static ShellInfoTree *info_tree_new(gboolean extra) GtkTreeStore *store; GtkTreeViewColumn *column; GtkCellRenderer *cr_text, *cr_pbuf, *cr_progress; + GtkTreeSelection *sel; info = g_new0(ShellInfoTree, 1); @@ -1186,19 +1157,18 @@ static ShellInfoTree *info_tree_new(gboolean extra) INFO_TREE_COL_VALUE); gtk_tree_view_column_set_visible(column, FALSE); - if (!extra) { - GtkTreeSelection *sel; + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + if (!extra) g_signal_connect(G_OBJECT(sel), "changed", (GCallback) info_selected, info); - } - + gtk_container_add(GTK_CONTAINER(scroll), treeview); info->scroll = scroll; info->view = treeview; info->model = model; + info->selection = sel; gtk_widget_show_all(scroll); @@ -1253,6 +1223,7 @@ static ShellTree *tree_new() shelltree->view = treeview; shelltree->model = model; shelltree->modules = NULL; + shelltree->selection = sel; gtk_widget_show_all(scroll); diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h index e6134443..ff096e5f 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/shell.h @@ -90,6 +90,7 @@ struct _ShellTree { GtkWidget *scroll; GtkWidget *view; GtkTreeModel *model; + GtkTreeSelection *selection; GSList *modules; }; @@ -97,9 +98,10 @@ struct _ShellTree { struct _ShellInfoTree { GtkWidget *scroll; GtkWidget *view; - GtkTreeModel *model; + GtkTreeModel *model; + GtkTreeSelection *selection; - GtkTreeViewColumn *col_progress, *col_value; + GtkTreeViewColumn *col_progress, *col_value; }; struct _ShellModule { @@ -134,7 +136,6 @@ struct _ShellModuleEntry { struct _ShellFieldUpdate { ShellModuleEntry *entry; gchar *field_name; - gboolean loadgraph; }; void shell_init(GSList *modules); |