GtkFileChooser with preview image problems



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?

This warning is printed if starting the sample:
(GtkFileChooser:7424): GLib-GObject-WARNING **: gsignal.c:2267: 
signal name `finished-loading' is invalid for instance `0x815ece0

If I try to debug the sample no windows are opened and gdb prints:
(gdb) run
Starting program: /home/andreas/src/gtk/beispiele/GtkFileChooser/GtkFileChooser 
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.

Program received signal SIG32, Real-time event 32.
0x40c50984 in ?? ()
(gdb) bt
#0  0x40c50984 in ?? ()
#1  0xbfffe478 in ?? ()
#2  0x40c507c9 in ?? ()
#3  0xbfffe3e0 in ?? ()
#4  0x00000020 in ?? ()
#5  0xbfffe3e0 in ?? ()
#6  0x404f9e7d in vfprintf () from /lib/libc.so.6
Previous frame inner to this frame (corrupt stack?)

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;
}

Sorry that I write to this devel-list, but no one answered on the app-devel-list
and I wasn't able to find a working GtkFileChooser with preview image sample code.

So if this isn't a gtk bug (I don't think so), could you help mo to get this 
example working?

regards
Andreas



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]