GtkFileChooser with preview image problems
- From: Andreas Volz <lists brachttal net>
- To: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: GtkFileChooser with preview image problems
- Date: Tue, 13 Jul 2004 11:52:33 +0200
Hi,
I try to change my application from GtkFileSelection to GtkFileChooser
with preview image. So I took the example code from the API docs and
build an simple example. The Chooser works, but if I try to preview a
picture the example froze. Perhaps someone has a better example or knows
where's the problem in my example?
Here is my broken example code:
#include <gtk/gtk.h>
static void
update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
{
GtkWidget *preview;
char *filename;
GdkPixbuf *pixbuf;
gboolean have_preview;
preview = GTK_WIDGET (data);
filename = gtk_file_chooser_get_preview_filename (file_chooser);
pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
have_preview = (pixbuf != NULL);
g_free (filename);
gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
if (pixbuf)
gdk_pixbuf_unref (pixbuf);
gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
}
int
main (int argc, char *argv[])
{
GtkWidget *dialog;
GtkWidget *window;
GtkWidget *preview;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
dialog = gtk_file_chooser_dialog_new ("Open File",
GTK_WINDOW (window),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
preview = gtk_image_new ();
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview);
g_signal_connect (GTK_FILE_CHOOSER (dialog), "update-preview",
G_CALLBACK (update_preview_cb), preview);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
//open_file (filename);
g_free (filename);
}
gtk_widget_destroy (dialog);
gtk_main ();
return 0;
}
regards
Andreas
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]