Issues in writing a wrapper around GTK File Chooser Dialog...



Hi,

I am using gtk+2.3.2 (slightly older one for now, but I don't have a
reason to believe that things should not work in this).

While writing a wrapper over gtk_file_chooser_dialog, I am facing the
following issues:

1. The example in documentation
(http://developer.gnome.org/doc/API/2.2/gtk/GtkFileChooser.html) says
that preview widget is to be attached with "update-preview" event. I
copied and pasted this example in my app, but was unable to get the
control to update_preview_cb (handler for this event). From the
documentation its not clear when this event will be emitted.

2. As a workaround, I used the event "selection-changed" instead of
"update-preview", and I am getting the control in the handler. But now
if I try to get the filename from
gtk_file_chooser_get_preview_filename(file_chooser); it returns NULL.

I even tried emitting "update-preview" from selection_changed_cb, and
calling gtk_file_chooser_get_preview_filename (file_chooser); from
within update_preview_cb, still I get NULL as filename.

I suspect that I am doing something wrong and there's nothing wrong with
gtk.

Part of the code is also pasted below for your reference...

// this is a static method
void MyWrapper::selection_changed (GtkFileChooser *file_chooser,
gpointer data)
{
  // get current selected file/folder
  char* filename = gtk_file_chooser_get_filename(file_chooser);
  if (!g_file_test(filename, G_FILE_TEST_IS_DIR))
    // if its not a folder, launch update-preview signal
    g_signal_emit_by_name(file_chooser, "update-preview", data);
}

// this is a static method
void MyWrapper::update_preview_cb (GtkFileChooser *file_chooser,
gpointer data)
{
  printf("MyWrapper::update_preview_cb\n");
  GtkWidget *preview;
  char *filename;
  GdkPixbuf *pixbuf;
  gboolean have_preview = false;

  printf("MyWrapper::update_preview_cb file_chooser != NULL %d\n",
(file_chooser != NULL));
  printf("MyWrapper::update_preview_cb data != NULL %d\n", (data !=
NULL));

  preview = GTK_WIDGET (data);
  //  filename = gtk_file_chooser_get_preview_filename (file_chooser);
  filename = gtk_file_chooser_get_filename(file_chooser);
  printf("MyWrapper::update_preview_cb filename = %s\n", filename);
  if (NULL != filename)
  {
    pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128,
NULL);
    have_preview = (pixbuf != NULL);
  printf("MyWrapper::update_preview_cb pixbuf != NULL %d\n", (pixbuf
!= NULL));

    gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
    if (pixbuf)
      gdk_pixbuf_unref (pixbuf);
  }
  g_free (filename);

  gtk_file_chooser_set_preview_widget_active (file_chooser,
have_preview);
}

void MyWrapper::DummyEnableForPreview()
{
  printf("MyWrapper::DummyEnableForPreview\n");
  GtkImage* preview;
  preview = GTK_IMAGE(gtk_image_new());

  gtk_file_chooser_set_preview_widget ( GTK_FILE_CHOOSER(mFSWidget),
GTK_WIDGET(preview) );
  g_signal_connect (  GTK_FILE_CHOOSER(mFSWidget), "selection-changed",
G_CALLBACK (selection_changed), preview);
  g_signal_connect (  GTK_FILE_CHOOSER(mFSWidget), "update-preview",
G_CALLBACK (update_preview_cb), preview);
}

Thanks in advance.
Regards
-Anil





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