aboutsummaryrefslogtreecommitdiff
path: root/hardinfo2/callbacks.c
diff options
context:
space:
mode:
Diffstat (limited to 'hardinfo2/callbacks.c')
-rw-r--r--hardinfo2/callbacks.c119
1 files changed, 11 insertions, 108 deletions
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()