diff options
-rw-r--r-- | hardinfo2/callbacks.c | 91 | ||||
-rw-r--r-- | hardinfo2/callbacks.h | 1 | ||||
-rwxr-xr-x | hardinfo2/configure | 1 | ||||
-rw-r--r-- | hardinfo2/hardinfo.c | 4 | ||||
-rw-r--r-- | hardinfo2/menu.c | 5 | ||||
-rw-r--r-- | hardinfo2/shell.c | 11 | ||||
-rw-r--r-- | hardinfo2/uidefs.xml | 2 |
7 files changed, 110 insertions, 5 deletions
diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index d7982075..526ac1fb 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -28,6 +28,97 @@ #include <config.h> +void cb_save_graphic() +{ + /* this is ridiculously complicated :/ why in the hell gtk+ makes this kind of thing so difficult? + FIXME: it still don't save the image with the right size; we should do this sometime soon (tm) */ + 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; + gchar *filename = NULL; + + /* */ + shell_status_update("Creating image..."); + + /* initialize stuff */ + gc = gdk_gc_new(widget->window); + context = gtk_widget_get_pango_context (widget); + layout = pango_layout_new(context); + + /* draw the title */ + pango_layout_set_markup(layout, shell->selected->name, -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 = widget->allocation.height + rect.height; + + pm = gdk_pixmap_new(widget->window, w, h, -1); + 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, widget->allocation.height, + widget->allocation.width, rect.height); + + /* save the pixbuf to a png file */ + dialog = gtk_file_chooser_dialog_new("Save Image", + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + + filename = g_strconcat(shell->selected->name, ".png", NULL); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename); + g_free(filename); + + if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + + shell_status_update("Saving image..."); + gdk_pixbuf_save(pb, filename, "png", NULL, + "compression", "9", + "tEXt::hardinfo::version", VERSION, + "tEXt::hardinfo::arch", ARCH, + NULL); + + g_free(filename); + } + + /* 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."); +} + void cb_open_web_page() { open_url("http://hardinfo.berlios.de"); diff --git a/hardinfo2/callbacks.h b/hardinfo2/callbacks.h index af553a9a..3cae72cb 100644 --- a/hardinfo2/callbacks.h +++ b/hardinfo2/callbacks.h @@ -21,6 +21,7 @@ void cb_about(); void cb_generate_report(); +void cb_save_graphic(); void cb_quit(); void cb_refresh(); void cb_copy_to_clipboard(); diff --git a/hardinfo2/configure b/hardinfo2/configure index 6d739d44..05e92c0e 100755 --- a/hardinfo2/configure +++ b/hardinfo2/configure @@ -154,6 +154,7 @@ echo "#define VERSION \"$VERSION\"" >> config.h echo "#define LSPCI \"$LSPCI -v\"" >> config.h echo "#define $ARCH" >> config.h +echo "#define ARCH \"$ARCH\"" >> config.h echo "#define PLATFORM \"`uname`\"" >> config.h echo "#define KERNEL \"`uname -r`\"" >> config.h diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index 668f4d31..82f53f79 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -42,13 +42,13 @@ main(int argc, char **argv) g_print("Copyright (C) 2003-2006 Leandro A. F. Pereira. See COPYING for details.\n\n"); g_print("Compile-time options:\n" - " Release version: %s\n" + " Release version: %s (%s)\n" " BinReloc enabled: %s\n" " Data prefix: %s\n" " Library prefix: %s\n" " Compiled on: %s %s (%s)\n" " Debugging enabled: %s\n\n", - RELEASE ? "Yes" : "No (" VERSION ")", + RELEASE ? "Yes" : "No (" VERSION ")", ARCH, ENABLE_BINRELOC ? "Yes" : "No", PREFIX, LIBPREFIX, diff --git a/hardinfo2/menu.c b/hardinfo2/menu.c index 9dff3502..344c1386 100644 --- a/hardinfo2/menu.c +++ b/hardinfo2/menu.c @@ -45,6 +45,11 @@ static GtkActionEntry entries[] = NULL, G_CALLBACK(cb_copy_to_clipboard) }, + { "SaveGraphAction", GTK_STOCK_SAVE, + "_Save Graphic", "<control>S", + NULL, + G_CALLBACK(cb_save_graphic) }, + { "RefreshAction", GTK_STOCK_REFRESH, "_Refresh", "F5", NULL, diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index e39cee40..b776cbfb 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -511,6 +511,7 @@ void shell_init(GSList * modules) 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); } @@ -632,6 +633,9 @@ static void set_view_type(ShellViewType viewtype) /* turn off the rules hint */ gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(shell->info->view), FALSE); + /* turn off the save graphic action */ + shell_action_set_enabled("SaveGraphAction", FALSE); + if (viewtype == shell->view_type) return; @@ -659,6 +663,7 @@ static void set_view_type(ShellViewType viewtype) shell->loadgraph->height - 16); break; case SHELL_VIEW_PROGRESS: + shell_action_set_enabled("SaveGraphAction", TRUE); gtk_tree_view_column_set_visible(shell->info->col_progress, TRUE); gtk_tree_view_column_set_visible(shell->info->col_value, FALSE); gtk_widget_hide(shell->notebook); @@ -903,15 +908,15 @@ module_selected_show_info(ShellModuleEntry * entry, gboolean reload) gint i; gsize ngroups; + /* reset the view type to normal */ + set_view_type(SHELL_VIEW_NORMAL); + if (entry->func) { key_data = entry->func(entry->number); } else { key_data = g_strdup("[Error]\n" "Invalid module="); } - /* reset the view type to normal */ - set_view_type(SHELL_VIEW_NORMAL); - /* recreate the iter hash table only if we're not reloading the module section */ if (!reload) { if (update_tbl != NULL) { diff --git a/hardinfo2/uidefs.xml b/hardinfo2/uidefs.xml index 779479c1..3eff07e4 100644 --- a/hardinfo2/uidefs.xml +++ b/hardinfo2/uidefs.xml @@ -2,6 +2,8 @@ <menubar> <menu name="InformationMenu" action="InformationMenuAction"> <menuitem name="Copy" action="CopyAction" /> + <menuitem name="SaveGraph" action="SaveGraphAction" /> + <separator/> <menuitem name="Report" action="ReportAction" /> <separator/> <menuitem name="Quit" action="QuitAction" /> |