diff options
-rw-r--r-- | hardinfo2/arch/common/display.h | 10 | ||||
-rw-r--r-- | hardinfo2/hardinfo.c | 14 | ||||
-rw-r--r-- | hardinfo2/hardinfo.h | 1 | ||||
-rw-r--r-- | hardinfo2/report.c | 157 | ||||
-rw-r--r-- | hardinfo2/report.h | 15 | ||||
-rw-r--r-- | hardinfo2/shell.c | 39 | ||||
-rw-r--r-- | hardinfo2/util.c | 17 |
7 files changed, 188 insertions, 65 deletions
diff --git a/hardinfo2/arch/common/display.h b/hardinfo2/arch/common/display.h index 6731e3e3..b28d34cc 100644 --- a/hardinfo2/arch/common/display.h +++ b/hardinfo2/arch/common/display.h @@ -126,9 +126,13 @@ computer_get_display(void) DisplayInfo *di = g_new0(DisplayInfo, 1); GdkScreen *screen = gdk_screen_get_default(); - - di->width = gdk_screen_get_width(screen); - di->height = gdk_screen_get_height(screen); + + if (screen) { + di->width = gdk_screen_get_width(screen); + di->height = gdk_screen_get_height(screen); + } else { + di->width = di->height = 0; + } get_glx_info(di); get_x11_info(di); diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index ebf65d9f..63609a3c 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -19,6 +19,7 @@ #include <config.h> #include <shell.h> +#include <report.h> #include <hardinfo.h> #include <iconcache.h> #include <stock.h> @@ -64,14 +65,15 @@ main(int argc, char **argv) shell_init(modules); gtk_main(); - - g_return_val_if_reached(0); } else if (params.create_report) { - g_print("creating report...\n"); + gchar *report; + + report = report_create_from_module_list_format(modules, + params.report_format); + g_print("%s", report); - g_return_val_if_reached(0); + g_free(report); } - /* should not be reached */ - g_return_val_if_reached(1); + return 0; } diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index 6d5822cd..68c995c7 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -27,6 +27,7 @@ typedef struct _ProgramParameters ProgramParameters; struct _ProgramParameters { gboolean create_report; + gint report_format; }; struct _FileTypes { diff --git a/hardinfo2/report.c b/hardinfo2/report.c index e3e28705..1c1e991c 100644 --- a/hardinfo2/report.c +++ b/hardinfo2/report.c @@ -250,51 +250,88 @@ report_text_key_value(ReportContext *ctx, gchar *key, gchar *value) ctx->output = g_strdup_printf("%s%s\n", ctx->output, key); } -static void -report_generate_child(ReportContext *ctx, GtkTreeIter *iter) +static GSList * +report_create_module_list_from_dialog(ReportDialog *rd) { - ShellModuleEntry *entry; - gboolean selected; - - gtk_tree_model_get(ctx->rd->model, iter, TREE_COL_SEL, &selected, -1); - if (!selected) - return; - - gtk_tree_model_get(ctx->rd->model, iter, TREE_COL_DATA, &entry, -1); - - ctx->entry = entry; + ShellModule *module; + GSList *modules = NULL; + GtkTreeModel *model = rd->model; + GtkTreeIter iter; - report_subtitle(ctx, entry->name); - report_table(ctx, entry->func(entry->number)); -} + gtk_tree_model_get_iter_first(rd->model, &iter); + do { + gboolean selected; + gchar *name; -static void -report_generate_children(ReportContext *ctx, GtkTreeIter *iter) -{ - GtkTreeModel *model = ctx->rd->model; - gboolean selected; - gchar *name; + gtk_tree_model_get(model, &iter, TREE_COL_SEL, &selected, -1); + if (!selected) + continue; + + module = g_new0(ShellModule, 1); + + gtk_tree_model_get(model, &iter, TREE_COL_NAME, &name, -1); + module->name = name; + module->entries = NULL; - gtk_tree_model_get(model, iter, TREE_COL_SEL, &selected, -1); - if (!selected) - return; + if (gtk_tree_model_iter_has_child(model, &iter)) { + ShellModuleEntry *entry; + + gint children = gtk_tree_model_iter_n_children(model, &iter); + gint i; + + for (i = 0; i < children; i++) { + GtkTreeIter child; + + gtk_tree_model_iter_nth_child(model, &child, &iter, i); + + gtk_tree_model_get(model, &child, TREE_COL_SEL, &selected, -1); + if (!selected) + continue; + + gtk_tree_model_get(model, &child, TREE_COL_DATA, &entry, -1); + + module->entries = g_slist_append(module->entries, entry); + } + } + + modules = g_slist_append(modules, module); + } while (gtk_tree_model_iter_next(rd->model, &iter)); - gtk_tree_model_get(model, iter, TREE_COL_NAME, &name, -1); - report_title(ctx, name); - - if (gtk_tree_model_iter_has_child(model, iter)) { - gint children = gtk_tree_model_iter_n_children(model, iter); - gint i; + return modules; +} - for (i = 0; i < children; i++) { - GtkTreeIter child; +static void +report_create_inner_from_module_list(ReportContext *ctx, GSList *modules) +{ + for (; modules; modules = modules->next) { + ShellModule *module = (ShellModule *) modules->data; + GSList *entries; + + report_title(ctx, module->name); + + for (entries = module->entries; entries; entries = entries->next) { + ShellModuleEntry *entry = (ShellModuleEntry *) entries->data; - gtk_tree_model_iter_nth_child(model, &child, iter, i); - report_generate_child(ctx, &child); + ctx->entry = entry; + report_subtitle(ctx, entry->name); + report_table(ctx, entry->func(entry->number)); } } } +void report_module_list_free(GSList *modules) +{ + GSList *m; + + for (m = modules; m; m = m->next) { + ShellModule *module = (ShellModule *) m->data; + + g_slist_free(module->entries); + } + + g_slist_free(modules); +} + static gchar * report_get_filename(void) { @@ -323,7 +360,7 @@ report_get_filename(void) } ReportContext* -report_context_html_new(ReportDialog *rd) +report_context_html_new() { ReportContext *ctx; @@ -335,14 +372,13 @@ report_context_html_new(ReportDialog *rd) ctx->subsubtitle = report_html_subsubtitle; ctx->keyvalue = report_html_key_value; - ctx->rd = rd; ctx->output = g_strdup(""); return ctx; } ReportContext* -report_context_text_new(ReportDialog *rd) +report_context_text_new() { ReportContext *ctx; @@ -354,7 +390,6 @@ report_context_text_new(ReportDialog *rd) ctx->subsubtitle = report_text_subsubtitle; ctx->keyvalue = report_text_key_value; - ctx->rd = rd; ctx->output = g_strdup(""); return ctx; @@ -367,12 +402,42 @@ report_context_free(ReportContext *ctx) g_free(ctx); } +void +report_create_from_module_list(ReportContext *ctx, GSList *modules) +{ + report_header(ctx); + + report_create_inner_from_module_list(ctx, modules); + report_module_list_free(modules); + + report_footer(ctx); +} + +gchar * +report_create_from_module_list_format(GSList *modules, ReportFormat format) +{ + ReportContext *ctx; + gchar *retval; + + if (format == REPORT_FORMAT_HTML) + ctx = report_context_html_new(); + else + ctx = report_context_text_new(); + + report_create_from_module_list(ctx, modules); + retval = g_strdup(ctx->output); + + report_context_free(ctx); + + return retval; +} + static gboolean report_generate(ReportDialog *rd) { - GtkTreeIter iter; + GSList *modules; ReportContext *ctx; - ReportContext *(*create_context)(ReportDialog *rd); + ReportContext *(*create_context)(); gchar *file; FILE *stream; @@ -392,16 +457,10 @@ report_generate(ReportDialog *rd) return FALSE; } - ctx = create_context(rd); - report_header(ctx); - - gtk_tree_model_get_iter_first(rd->model, &iter); - do { - report_generate_children(ctx, &iter); - } while (gtk_tree_model_iter_next(rd->model, &iter)); - - report_footer(ctx); + ctx = create_context(); + modules = report_create_module_list_from_dialog(rd); + report_create_from_module_list(ctx, modules); fputs(ctx->output, stream); fclose(stream); diff --git a/hardinfo2/report.h b/hardinfo2/report.h index 8762f671..faf04ac5 100644 --- a/hardinfo2/report.h +++ b/hardinfo2/report.h @@ -21,11 +21,15 @@ #include <gtk/gtk.h> #include <shell.h> +typedef enum { + REPORT_FORMAT_TEXT, + REPORT_FORMAT_HTML +} ReportFormat; + typedef struct _ReportDialog ReportDialog; typedef struct _ReportContext ReportContext; struct _ReportContext { - ReportDialog *rd; ShellModuleEntry *entry; gchar *output; @@ -51,6 +55,9 @@ struct _ReportDialog { void report_dialog_show(); +ReportContext *report_context_html_new(); +ReportContext *report_context_text_new(); + void report_header (ReportContext *ctx); void report_footer (ReportContext *ctx); void report_title (ReportContext *ctx, gchar *text); @@ -59,10 +66,10 @@ void report_subsubtitle (ReportContext *ctx, gchar *text); void report_key_value (ReportContext *ctx, gchar *key, gchar *value); void report_table (ReportContext *ctx, gchar *text); -ReportContext *report_context_html_new(ReportDialog *rd); -ReportContext *report_context_text_new(ReportDialog *rd); -ReportContext *report_context_string_new(ReportDialog *rd); +void report_create_from_module_list(ReportContext *ctx, GSList *modules); +gchar *report_create_from_module_list_format(GSList *modules, ReportFormat format); void report_context_free(ReportContext *ctx); +void report_module_list_free(GSList *modules); #endif /* __REPORT_H__ */ diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index d3d55b40..e4d1f194 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -64,6 +64,9 @@ void shell_ui_manager_set_visible(const gchar *path, { GtkWidget *widget; + if (!gui_running) + return; + widget = gtk_ui_manager_get_widget(shell->ui_manager, path); if (!widget) return; @@ -80,6 +83,9 @@ void shell_action_set_property(const gchar *action_name, { GtkAction *action; + if (!gui_running) + return; + action = gtk_action_group_get_action(shell->action_group, action_name); if (action) { GValue value = {0}; @@ -96,6 +102,9 @@ void shell_action_set_property(const gchar *action_name, void shell_action_set_enabled(const gchar *action_name, gboolean setting) { GtkAction *action; + + if (!gui_running) + return; action = gtk_action_group_get_action(shell->action_group, action_name); if (action) { @@ -106,6 +115,9 @@ void shell_action_set_enabled(const gchar *action_name, gboolean setting) gboolean shell_action_get_enabled(const gchar *action_name) { GtkAction *action; + + if (!gui_running) + return FALSE; action = gtk_action_group_get_action(shell->action_group, action_name); if (action) { @@ -117,6 +129,9 @@ gboolean shell_action_get_enabled(const gchar *action_name) void shell_set_side_pane_visible(gboolean setting) { + if (!gui_running) + return; + if (setting) gtk_widget_show(shell->tree->scroll); else @@ -128,7 +143,9 @@ gboolean shell_action_get_active(const gchar *action_name) GtkAction *action; GSList *proxies; - /* FIXME: Ugh. Are you sure there isn't any simpler way? O_o */ + /* FIXME: Ugh. Are you sure there isn't any simpler way? O_o */ + if (!gui_running) + return FALSE; action = gtk_action_group_get_action(shell->action_group, action_name); if (action) { @@ -152,6 +169,8 @@ void shell_action_set_active(const gchar *action_name, gboolean setting) GSList *proxies; /* FIXME: Ugh. Are you sure there isn't any simpler way? O_o */ + if (!gui_running) + return; action = gtk_action_group_get_action(shell->action_group, action_name); if (action) { @@ -171,6 +190,9 @@ void shell_action_set_active(const gchar *action_name, gboolean setting) void shell_status_pulse(void) { + if (!gui_running) + return; + if (shell->_pulses++ == 20) { /* we're pulsing for some time, disable the interface and change the cursor to a hourglass */ @@ -185,6 +207,9 @@ shell_status_pulse(void) void shell_status_set_percentage(gint percentage) { + if (!gui_running) + return; + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(shell->progress), (float)percentage/100.0); while (gtk_events_pending()) @@ -194,6 +219,9 @@ shell_status_set_percentage(gint percentage) void shell_view_set_enabled(gboolean setting) { + if (!gui_running) + return; + if (setting) { shell->_pulses = 0; widget_set_cursor(shell->window, GDK_LEFT_PTR); @@ -211,6 +239,9 @@ shell_view_set_enabled(gboolean setting) void shell_status_set_enabled(gboolean setting) { + if (!gui_running) + return; + if (setting) gtk_widget_show(shell->progress); else { @@ -222,6 +253,9 @@ shell_status_set_enabled(gboolean setting) void shell_do_reload(void) { + if (!gui_running) + return; + shell_action_set_enabled("RefreshAction", FALSE); shell_action_set_enabled("CopyAction", FALSE); shell_action_set_enabled("ReportAction", FALSE); @@ -244,6 +278,9 @@ shell_do_reload(void) void shell_status_update(const gchar *message) { + if (!gui_running) + return; + gtk_label_set_markup(GTK_LABEL(shell->status), message); gtk_progress_bar_pulse(GTK_PROGRESS_BAR(shell->progress)); while (gtk_events_pending()) diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 295fe061..9ed9b8fc 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -17,6 +17,7 @@ */ #include <config.h> +#include <report.h> #include <string.h> #include <shell.h> #include <iconcache.h> @@ -257,16 +258,24 @@ log_handler(const gchar * log_domain, void parameters_init(int *argc, char ***argv, ProgramParameters * param) { - static gboolean create_report = FALSE; + static gboolean create_report = FALSE; + static gchar *report_format = NULL; static GOptionEntry options[] = { { - .long_name = "create-report", + .long_name = "generate-report", .short_name = 'r', .arg = G_OPTION_ARG_NONE, .arg_data = &create_report, .description = "create a report and print to standard output" }, + { + .long_name = "report-format", + .short_name = 'f', + .arg = G_OPTION_ARG_STRING, + .arg_data = &report_format, + .description = "choose a report format (text, html)" + }, { NULL } }; GOptionContext *ctx; @@ -281,6 +290,10 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) g_option_context_free(ctx); param->create_report = create_report; + param->report_format = REPORT_FORMAT_TEXT; + + if (report_format && g_str_equal(report_format, "html")) + param->report_format = REPORT_FORMAT_HTML; } gboolean ui_init(int *argc, char ***argv) |