aboutsummaryrefslogtreecommitdiff
path: root/hardinfo2
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2007-01-01 17:46:52 +0000
committerLeandro A. F. Pereira <leandro@hardinfo.org>2007-01-01 17:46:52 +0000
commit2ac586a621e9d20667838df367ce5c3b4b428500 (patch)
treed10aea126d631c3bb0675a1c97d333904236f85b /hardinfo2
parentefd445927ac141860f1875c3d4e5272991705593 (diff)
Cleanups.
Diffstat (limited to 'hardinfo2')
-rw-r--r--hardinfo2/arch/common/display.h2
-rw-r--r--hardinfo2/callbacks.c119
-rw-r--r--hardinfo2/computer.c6
-rw-r--r--hardinfo2/computer.h2
-rw-r--r--hardinfo2/hardinfo.h2
-rw-r--r--hardinfo2/report.c106
-rw-r--r--hardinfo2/report.h2
-rw-r--r--hardinfo2/shell.c6
-rw-r--r--hardinfo2/util.c118
9 files changed, 210 insertions, 153 deletions
diff --git a/hardinfo2/arch/common/display.h b/hardinfo2/arch/common/display.h
index 5c1ed849..10ea49e4 100644
--- a/hardinfo2/arch/common/display.h
+++ b/hardinfo2/arch/common/display.h
@@ -37,6 +37,8 @@ get_glx_info(DisplayInfo *di)
get_str("OpenGL version str", di->ogl_version);
g_strfreev(tmp);
+ } else if (strstr(output_lines[i], "direct rendering: Yes")) {
+ di->dri = TRUE;
}
}
diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c
index 7982efe2..e4d0f61d 100644
--- a/hardinfo2/callbacks.c
+++ b/hardinfo2/callbacks.c
@@ -28,102 +28,11 @@
#include <config.h>
-static gint get_tree_view_visible_height(GtkTreeView *tv)
-{
- GtkTreePath *path;
- GdkRectangle rect;
- GtkTreeIter iter;
- GtkTreeModel *model = gtk_tree_view_get_model(tv);
- gint nrows = 1;
-
- path = gtk_tree_path_new_first();
- gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv),
- path, NULL, &rect);
-
- gtk_tree_model_get_iter_first(model, &iter);
- do {
- nrows++;
- } while (gtk_tree_model_iter_next(model, &iter));
-
- gtk_tree_path_free(path);
-
- return nrows * rect.height;
-}
-
void cb_save_graphic()
{
- /* this is ridiculously complicated :/ why in the hell gtk+ makes this kind of thing so difficult? */
- Shell *shell = shell_get_main_shell();
- GtkWidget *widget = shell->info->view;
- GtkWidget *dialog;
-
- PangoLayout *layout;
- PangoContext *context;
- PangoRectangle rect;
-
- GdkPixmap *pm;
- GdkPixbuf *pb;
- GdkGC *gc;
- GdkColor black = { 0, 0, 0, 0 };
- GdkColor white = { 0, 65535, 65535, 65535 };
-
- gint w, h, visible_height;
- gchar *filename = NULL, *tmp;
-
- /* */
- shell_status_update("Creating image...");
-
- /* unselect things in the information treeview */
- gtk_range_set_value(GTK_RANGE
- (GTK_SCROLLED_WINDOW(shell->info->scroll)->
- vscrollbar), 0.0);
- gtk_tree_selection_unselect_all(
- gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)));
- while (gtk_events_pending())
- gtk_main_iteration();
-
- /* initialize stuff */
- gc = gdk_gc_new(widget->window);
- gdk_gc_set_background(gc, &black);
- gdk_gc_set_foreground(gc, &white);
-
- context = gtk_widget_get_pango_context (widget);
- layout = pango_layout_new(context);
-
- visible_height = get_tree_view_visible_height(GTK_TREE_VIEW(widget));
-
- /* draw the title */
- tmp = g_strdup_printf("<b><big>%s</big></b>\n<small>%s</small>",
- shell->selected->name,
- shell->selected->notefunc(shell->selected->number));
- pango_layout_set_markup(layout, tmp, -1);
- pango_layout_set_width(layout, widget->allocation.width * PANGO_SCALE);
- pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
- g_free(tmp);
-
- pango_layout_get_pixel_extents(layout, NULL, &rect);
-
- w = widget->allocation.width;
- h = visible_height + rect.height;
-
- pm = gdk_pixmap_new(widget->window, w, rect.height, -1);
- gdk_draw_rectangle(GDK_DRAWABLE(pm), gc, TRUE, 0, 0, w, rect.height);
- gdk_draw_layout_with_colors (GDK_DRAWABLE(pm), gc, 0, 0, layout,
- &white, &black);
-
- /* copy the pixmap from the treeview and from the title */
- pb = gdk_pixbuf_get_from_drawable(NULL,
- widget->window,
- NULL,
- 0, 0,
- 0, 0,
- w, h);
- pb = gdk_pixbuf_get_from_drawable(pb,
- pm,
- NULL,
- 0, 0,
- 0, visible_height,
- widget->allocation.width, rect.height);
+ Shell *shell = shell_get_main_shell();
+ GtkWidget *dialog;
+ gchar *filename;
/* save the pixbuf to a png file */
dialog = gtk_file_chooser_dialog_new("Save Image",
@@ -139,25 +48,19 @@ void cb_save_graphic()
if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ gtk_widget_destroy(dialog);
shell_status_update("Saving image...");
- gdk_pixbuf_save(pb, filename, "png", NULL,
- "compression", "9",
- "tEXt::hardinfo::version", VERSION,
- "tEXt::hardinfo::arch", ARCH,
- NULL);
-
+
+ tree_view_save_image(filename);
+
+ shell_status_update("Done.");
g_free(filename);
+
+ return;
}
- /* unref */
- gtk_widget_destroy (dialog);
- g_object_unref(pb);
- g_object_unref(layout);
- g_object_unref(pm);
- g_object_unref(gc);
-
- shell_status_update("Done.");
+ gtk_widget_destroy(dialog);
}
void cb_open_web_page()
diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c
index 14284bca..1d8e0b70 100644
--- a/hardinfo2/computer.c
+++ b/hardinfo2/computer.c
@@ -270,7 +270,8 @@ hi_info(gint entry)
"[OpenGL]\n"
"Vendor=%s\n"
"Renderer=%s\n"
- "Version=%s\n",
+ "Version=%s\n"
+ "Direct Rendering=%s\n",
computer->display->width,
computer->display->height,
computer->display->vendor,
@@ -279,7 +280,8 @@ hi_info(gint entry)
computer->display->extensions,
computer->display->ogl_vendor,
computer->display->ogl_renderer,
- computer->display->ogl_version);
+ computer->display->ogl_version,
+ computer->display->dri ? "Yes" : "No");
case COMPUTER_OPERATING_SYSTEM:
return g_strdup_printf("[$ShellParam$]\n"
"UpdateInterval$Uptime=10000\n"
diff --git a/hardinfo2/computer.h b/hardinfo2/computer.h
index a57eb023..4fa771f8 100644
--- a/hardinfo2/computer.h
+++ b/hardinfo2/computer.h
@@ -82,6 +82,8 @@ struct _AlsaInfo {
struct _DisplayInfo {
gchar *ogl_vendor, *ogl_renderer, *ogl_version;
+ gboolean dri;
+
gchar *display_name, *vendor, *version;
gchar *extensions;
gchar *monitors;
diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h
index 17c9719b..1f850cc9 100644
--- a/hardinfo2/hardinfo.h
+++ b/hardinfo2/hardinfo.h
@@ -58,6 +58,8 @@ gchar *strreplace(gchar *string, gchar *replace, gchar new_char);
/* Widget utility functions */
void widget_set_cursor(GtkWidget *widget, GdkCursorType cursor_type);
+gint tree_view_get_visible_height(GtkTreeView *tv);
+void tree_view_save_image(gchar *filename);
/* File Chooser utility functions */
void file_chooser_open_expander(GtkWidget *chooser);
diff --git a/hardinfo2/report.c b/hardinfo2/report.c
index 0e17a852..0a486228 100644
--- a/hardinfo2/report.c
+++ b/hardinfo2/report.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <shell.h>
#include <hardinfo.h>
+#include <config.h>
static ReportDialog *report_dialog_new(GtkTreeModel *model, GtkWidget *parent);
static void set_all_active(ReportDialog *rd, gboolean setting);
@@ -68,6 +69,21 @@ report_key_value(ReportContext *ctx, gchar *key, gchar *value)
}
void
+report_context_configure(ReportContext *ctx, GKeyFile *keyfile)
+{
+ /* FIXME: sometime in the future we'll save images in the report. this
+ flag will be set if we should support that.
+
+ so i don't forget how to encode the images inside the html files:
+ http://en.wikipedia.org/wiki/Data:_URI_scheme */
+
+ ctx->is_image_enabled = (g_key_file_get_boolean(keyfile,
+ "$ShellParam$",
+ "ViewType",
+ NULL) == SHELL_VIEW_PROGRESS);
+}
+
+void
report_table(ReportContext *ctx, gchar *text)
{
GKeyFile *key_file = g_key_file_new();
@@ -82,46 +98,56 @@ report_table(ReportContext *ctx, gchar *text)
gchar **keys;
gint j;
- if (groups[i][0] == '$')
+ if (groups[i][0] == '$') {
+ report_context_configure(ctx, key_file);
continue;
+ }
group = groups[i];
- keys = g_key_file_get_keys(key_file, group, NULL, NULL);
tmpgroup = g_strdup(group);
strend(group, '#');
report_subsubtitle(ctx, group);
- for (j = 0; keys[j]; j++) {
- gchar *key = keys[j];
- gchar *value;
-
- value = g_key_file_get_value(key_file, tmpgroup, key, NULL);
-
- if (g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) {
- strend(key, '#');
-
- if (g_str_equal(value, "...")) {
- g_free(value);
- if (!(value = ctx->entry->fieldfunc(key))) {
- value = g_strdup("...");
+#if 0
+ if (ctx->is_image_enabled) {
+ report_embed_image(ctx, key_file, group);
+ } else {
+#endif
+ keys = g_key_file_get_keys(key_file, tmpgroup, NULL, NULL);
+ for (j = 0; keys[j]; j++) {
+ gchar *key = keys[j];
+ gchar *value;
+
+ value = g_key_file_get_value(key_file, tmpgroup, key, NULL);
+
+ if (g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) {
+ strend(key, '#');
+
+ if (g_str_equal(value, "...")) {
+ g_free(value);
+ if (!(value = ctx->entry->fieldfunc(key))) {
+ value = g_strdup("...");
+ }
}
- }
-
- if (*key == '$') {
- report_key_value(ctx, strchr(key + 1, '$') + 1, value);
- } else {
- report_key_value(ctx, key, value);
- }
-
+
+ if (*key == '$') {
+ report_key_value(ctx, strchr(key + 1, '$') + 1, value);
+ } else {
+ report_key_value(ctx, key, value);
+ }
+
+ }
+
+ g_free(value);
}
- g_free(value);
- }
-
+ g_strfreev(keys);
+#if 0
+ }
+#endif
g_free(tmpgroup);
- g_strfreev(keys);
}
g_strfreev(groups);
@@ -134,19 +160,19 @@ report_html_header(ReportContext *ctx)
if (ctx->output)
g_free(ctx->output);
- ctx->output = g_strdup("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">\n" \
- "<html><head>\n" \
- "<title>HardInfo System Report</title>\n" \
- "<style>\n" \
- "body { background: #fff }\n" \
- ".title { font: bold 130%% serif; color: #0066FF; padding: 30px 0 10px 0 }\n" \
- ".stitle { font: bold 100%% sans-serif; color: #0044DD; padding: 30px 0 10px 0 }\n" \
- ".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>");
+ ctx->output = g_strdup_printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">\n" \
+ "<html><head>\n" \
+ "<title>HardInfo (%s) System Report</title>\n" \
+ "<style>\n" \
+ " body { background: #fff }\n" \
+ " .title { font: bold 130%% serif; color: #0066FF; padding: 30px 0 10px 0 }\n" \
+ " .stitle { font: bold 100%% sans-serif; color: #0044DD; padding: 30px 0 10px 0 }\n" \
+ " .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>", VERSION);
}
static void
diff --git a/hardinfo2/report.h b/hardinfo2/report.h
index e4de9235..6ba18702 100644
--- a/hardinfo2/report.h
+++ b/hardinfo2/report.h
@@ -42,6 +42,8 @@ struct _ReportContext {
void (*keyvalue) (ReportContext *ctx, gchar *key, gchar *value);
ReportFormat format;
+
+ gboolean is_image_enabled;
};
struct _ReportDialog {
diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c
index 4655ec31..5cd0e56d 100644
--- a/hardinfo2/shell.c
+++ b/hardinfo2/shell.c
@@ -509,14 +509,14 @@ void shell_init(GSList * modules)
load_graph_configure_expose(shell->loadgraph);
gtk_widget_hide(shell->notebook);
+ shell_status_update("Done.");
+ shell_status_set_enabled(FALSE);
+
shell_action_set_enabled("RefreshAction", FALSE);
shell_action_set_enabled("CopyAction", FALSE);
shell_action_set_enabled("SaveGraphAction", FALSE);
shell_action_set_active("SidePaneAction", TRUE);
shell_action_set_active("ToolbarAction", TRUE);
-
- shell_status_update("Done.");
- shell_status_set_enabled(FALSE);
}
static gboolean update_field(gpointer data)
diff --git a/hardinfo2/util.c b/hardinfo2/util.c
index ccfc413f..86ba47a3 100644
--- a/hardinfo2/util.c
+++ b/hardinfo2/util.c
@@ -513,3 +513,121 @@ GSList *modules_load_all(void)
{
return modules_load(NULL);
}
+
+gint tree_view_get_visible_height(GtkTreeView *tv)
+{
+ GtkTreePath *path;
+ GdkRectangle rect;
+ GtkTreeIter iter;
+ GtkTreeModel *model = gtk_tree_view_get_model(tv);
+ gint nrows = 1;
+
+ path = gtk_tree_path_new_first();
+ gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv),
+ path, NULL, &rect);
+
+ /* FIXME: isn't there any easier way to tell the number of rows? */
+ gtk_tree_model_get_iter_first(model, &iter);
+ do {
+ nrows++;
+ } while (gtk_tree_model_iter_next(model, &iter));
+
+ gtk_tree_path_free(path);
+
+ return nrows * rect.height;
+}
+
+void tree_view_save_image(gchar *filename)
+{
+ /* this is ridiculously complicated :/ why in the hell gtk+ makes this kind of
+ thing so difficult? */
+ Shell *shell = shell_get_main_shell();
+ GtkWidget *widget = shell->info->view;
+
+ PangoLayout *layout;
+ PangoContext *context;
+ PangoRectangle rect;
+
+ GdkPixmap *pm;
+ GdkPixbuf *pb;
+ GdkGC *gc;
+ GdkColor black = { 0, 0, 0, 0 };
+ GdkColor white = { 0, 65535, 65535, 65535 };
+
+ gint w, h, visible_height;
+ gchar *tmp;
+
+ gboolean tv_enabled;
+
+ /* if the treeview is disabled, we need to enable it so we get the
+ correct colors when saving. we make it insensitive later on if it
+ was this way before entering this function */
+ tv_enabled = GTK_WIDGET_IS_SENSITIVE(widget);
+ gtk_widget_set_sensitive(widget, TRUE);
+
+ /* unselect things in the information treeview */
+ gtk_range_set_value(GTK_RANGE
+ (GTK_SCROLLED_WINDOW(shell->info->scroll)->
+ vscrollbar), 0.0);
+ gtk_tree_selection_unselect_all(
+ gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)));
+ while (gtk_events_pending())
+ gtk_main_iteration();
+
+ /* initialize stuff */
+ gc = gdk_gc_new(widget->window);
+ gdk_gc_set_background(gc, &black);
+ gdk_gc_set_foreground(gc, &white);
+
+ context = gtk_widget_get_pango_context (widget);
+ layout = pango_layout_new(context);
+
+ visible_height = tree_view_get_visible_height(GTK_TREE_VIEW(widget));
+
+ /* draw the title */
+ tmp = g_strdup_printf("<b><big>%s</big></b>\n<small>%s</small>",
+ shell->selected->name,
+ shell->selected->notefunc(shell->selected->number));
+ pango_layout_set_markup(layout, tmp, -1);
+ pango_layout_set_width(layout, widget->allocation.width * PANGO_SCALE);
+ pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
+ pango_layout_get_pixel_extents(layout, NULL, &rect);
+
+ w = widget->allocation.width;
+ h = visible_height + rect.height;
+
+ pm = gdk_pixmap_new(widget->window, w, rect.height, -1);
+ gdk_draw_rectangle(GDK_DRAWABLE(pm), gc, TRUE, 0, 0, w, rect.height);
+ gdk_draw_layout_with_colors (GDK_DRAWABLE(pm), gc, 0, 0, layout,
+ &white, &black);
+
+ /* copy the pixmap from the treeview and from the title */
+ pb = gdk_pixbuf_get_from_drawable(NULL,
+ widget->window,
+ NULL,
+ 0, 0,
+ 0, 0,
+ w, h);
+ pb = gdk_pixbuf_get_from_drawable(pb,
+ pm,
+ NULL,
+ 0, 0,
+ 0, visible_height,
+ w, rect.height);
+
+ /* save the pixbuf to a png file */
+ gdk_pixbuf_save(pb, filename, "png", NULL,
+ "compression", "9",
+ "tEXt::hardinfo::version", VERSION,
+ "tEXt::hardinfo::arch", ARCH,
+ NULL);
+
+ /* unref */
+ g_object_unref(pb);
+ g_object_unref(layout);
+ g_object_unref(pm);
+ g_object_unref(gc);
+ g_free(tmp);
+
+ gtk_widget_set_sensitive(widget, tv_enabled);
+}