diff options
Diffstat (limited to 'report.c')
-rw-r--r-- | report.c | 183 |
1 files changed, 158 insertions, 25 deletions
@@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * Copyright (C) 2003-2008 Leandro A. F. Pereira <leandro@hardinfo.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,8 +64,31 @@ void report_key_value(ReportContext * ctx, gchar * key, gchar * value) ctx->keyvalue(ctx, key, value); } +gint report_get_visible_columns(ReportContext *ctx) +{ + gint columns; + + /* Column count starts at two, since we always have at least + two columns visible. */ + columns = 2; + + /* Either the Progress column or the Value column is available at + the same time. So we don't count them. */ + + if (ctx->columns & REPORT_COL_EXTRA1) + columns++; + + if (ctx->columns & REPORT_COL_EXTRA2) + columns++; + + return columns; +} + void report_context_configure(ReportContext * ctx, GKeyFile * keyfile) { + gchar **keys; + const gchar *group = "$ShellParam$"; + /* FIXME: sometime in the future we'll save images in the report. this flag will be set if we should support that. @@ -73,10 +96,50 @@ void report_context_configure(ReportContext * ctx, GKeyFile * keyfile) http://en.wikipedia.org/wiki/Data:_URI_scheme */ ctx->is_image_enabled = (g_key_file_get_boolean(keyfile, - "$ShellParam$", + group, "ViewType", - NULL) == - SHELL_VIEW_PROGRESS); + NULL) == SHELL_VIEW_PROGRESS); + + + keys = g_key_file_get_keys(keyfile, group, NULL, NULL); + if (keys) { + gint i = 0; + + for (; keys[i]; i++) { + gchar *key = keys[i]; + + if (g_str_equal(key, "ShowColumnHeaders")) { + ctx->show_column_headers = g_key_file_get_boolean(keyfile, group, key, NULL); + } else if (g_str_has_prefix(key, "ColumnTitle")) { + gchar *value, *title = strchr(key, '$') + 1; + + value = g_key_file_get_value(keyfile, group, key, NULL); + if (g_str_equal(title, "Extra1")) { + ctx->columns |= REPORT_COL_EXTRA1; + } else if (g_str_equal(title, "Extra2")) { + ctx->columns |= REPORT_COL_EXTRA2; + } else if (g_str_equal(title, "Value")) { + ctx->columns |= REPORT_COL_VALUE; + } else if (g_str_equal(title, "TextValue")) { + ctx->columns |= REPORT_COL_TEXTVALUE; + } else if (g_str_equal(title, "Progress")) { + ctx->columns |= REPORT_COL_PROGRESS; + } + + g_hash_table_replace(ctx->column_titles, title, g_strdup(value)); + + g_free(value); + } else if (g_str_equal(key, "ViewType")) { + if (g_key_file_get_integer(keyfile, group, "ViewType", NULL) == SHELL_VIEW_PROGRESS) { + ctx->columns &= ~REPORT_COL_VALUE; + ctx->columns |= REPORT_COL_PROGRESS; + } + } + } + + g_strfreev(keys); + } + } void report_table(ReportContext * ctx, gchar * text) @@ -85,8 +148,20 @@ void report_table(ReportContext * ctx, gchar * text) gchar **groups; gint i; + /* make only "Value" column visible ("Key" column is always visible) */ + ctx->columns = REPORT_COL_VALUE; + ctx->show_column_headers = FALSE; + + /**/ g_key_file_load_from_data(key_file, text, strlen(text), 0, NULL); groups = g_key_file_get_groups(key_file, NULL); + + for (i = 0; groups[i]; i++) { + if (groups[i][0] == '$') { + report_context_configure(ctx, key_file); + break; + } + } for (i = 0; groups[i]; i++) { gchar *group, *tmpgroup; @@ -94,7 +169,6 @@ void report_table(ReportContext * ctx, gchar * text) gint j; if (groups[i][0] == '$') { - report_context_configure(ctx, key_file); continue; } @@ -115,11 +189,9 @@ void report_table(ReportContext * ctx, gchar * text) gchar *key = keys[j]; gchar *value; - value = - g_key_file_get_value(key_file, tmpgroup, key, NULL); + value = g_key_file_get_value(key_file, tmpgroup, key, NULL); - if (g_utf8_validate(key, -1, NULL) - && g_utf8_validate(value, -1, NULL)) { + if (g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) { strend(key, '#'); if (g_str_equal(value, "...")) { @@ -128,7 +200,7 @@ void report_table(ReportContext * ctx, gchar * text) value = g_strdup("..."); } } - + if (*key == '$') { report_key_value(ctx, strchr(key + 1, '$') + 1, value); @@ -168,45 +240,80 @@ static void report_html_header(ReportContext * ctx) " .sstitle{ font: bold 80%% serif; color: #000000; background: #efefef }\n" " .field { font: 80%% sans-serif; color: #000000; padding: 2px; padding-left: 50px }\n" " .value { font: 80%% sans-serif; color: #505050 }\n" - "</style>\n" "</head><body>\n" "<table width=\"100%%\"><tbody>", + "</style>\n" "</head><body>\n", VERSION); } static void report_html_footer(ReportContext * ctx) { ctx->output = h_strconcat(ctx->output, - "</tbody></table></body></html>", NULL); + "</table></html>", NULL); } static void report_html_title(ReportContext * ctx, gchar * text) { - ctx->output = h_strdup_cprintf("<tr><td colspan=\"2\" class=\"titl" - "e\">%s</td></tr>\n", ctx->output, text); + if (!ctx->first_table) { + ctx->output = h_strdup_cprintf("</table>", ctx->output); + } + + ctx->output = h_strdup_cprintf("<h1 class=\"title\">%s</h1>", ctx->output, text); } static void report_html_subtitle(ReportContext * ctx, gchar * text) { - ctx->output = h_strdup_cprintf("<tr><td colspan=\"2\" class=\"stit" + gint columns = report_get_visible_columns(ctx); + + if (!ctx->first_table) { + ctx->output = h_strdup_cprintf("</table>", ctx->output); + } else { + ctx->first_table = FALSE; + } + + ctx->output = h_strdup_cprintf("<table><tr><td colspan=\"%d\" class=\"stit" "le\">%s</td></tr>\n", ctx->output, + columns, text); } static void report_html_subsubtitle(ReportContext * ctx, gchar * text) { - ctx->output = h_strdup_cprintf("<tr><td colspan=\"2\" class=\"ssti" + gint columns = report_get_visible_columns(ctx); + + ctx->output = h_strdup_cprintf("<tr><td colspan=\"%d\" class=\"ssti" "tle\">%s</td></tr>\n", ctx->output, + columns, text); } static void report_html_key_value(ReportContext * ctx, gchar * key, gchar * value) { - ctx->output = h_strdup_cprintf("<tr><td class=\"field\">%s</td>" - "<td class=\"value\">%s</td></tr>\n", - ctx->output, - key, value); + gint columns = report_get_visible_columns(ctx); + gchar **values; + gint i; + + if (columns == 2) { + ctx->output = h_strdup_cprintf("<tr><td class=\"field\">%s</td>" + "<td class=\"value\">%s</td></tr>\n", + ctx->output, + key, value); + } else { + values = g_strsplit(value, "|", columns); + + ctx->output = h_strdup_cprintf("\n<tr>\n<td class=\"field\">%s</td>", ctx->output, key); + + for (i = columns - 2; i >= 0; i--) { + ctx->output = h_strdup_cprintf("<td class=\"value\">%s</td>", + ctx->output, + values[i]); + } + + ctx->output = h_strdup_cprintf("</tr>\n", ctx->output); + + g_strfreev(values); + } } static void report_text_header(ReportContext * ctx) @@ -255,11 +362,30 @@ static void report_text_subsubtitle(ReportContext * ctx, gchar * text) static void report_text_key_value(ReportContext * ctx, gchar * key, gchar * value) { - if (strlen(value)) - ctx->output = - h_strdup_cprintf("%s\t\t: %s\n", ctx->output, key, value); - else - ctx->output = h_strdup_cprintf("%s\n", ctx->output, key); + gint columns = report_get_visible_columns(ctx); + gchar **values; + gint i; + + if (columns == 2) { + if (strlen(value)) + ctx->output = h_strdup_cprintf("%s\t\t: %s\n", ctx->output, key, value); + else + ctx->output = h_strdup_cprintf("%s\n", ctx->output, key); + } else { + values = g_strsplit(value, "|", columns); + + ctx->output = h_strdup_cprintf("%s\t", ctx->output, key); + + for (i = columns - 2; i >= 0; i--) { + ctx->output = h_strdup_cprintf("%s\t", + ctx->output, + values[i]); + } + + ctx->output = h_strdup_cprintf("\n", ctx->output); + + g_strfreev(values); + } } static GSList *report_create_module_list_from_dialog(ReportDialog * rd) @@ -394,6 +520,9 @@ ReportContext *report_context_html_new() ctx->output = g_strdup(""); ctx->format = REPORT_FORMAT_HTML; + ctx->column_titles = g_hash_table_new(g_str_hash, g_str_equal); + ctx->first_table = TRUE; + return ctx; } @@ -411,12 +540,16 @@ ReportContext *report_context_text_new() ctx->output = g_strdup(""); ctx->format = REPORT_FORMAT_TEXT; + + ctx->column_titles = g_hash_table_new(g_str_hash, g_str_equal); + ctx->first_table = TRUE; return ctx; } void report_context_free(ReportContext * ctx) { + g_hash_table_destroy(ctx->column_titles); g_free(ctx->output); g_free(ctx); } |