A better way to get a widget from a GnomeDialog pointer???



Hi, check this callback:


void
on_add_magazine_button_clicked(GtkButton *button, gpointer user_data)
{
  GtkWidget *dialog = create_add_magazine_dialog();
  GtkWidget *entry;
  struct _GtkBoxChild *child;
  int result;

  GList *dialog_children =
GTK_BOX(GNOME_DIALOG(dialog)->vbox)->children;

  result = gnome_dialog_run(GNOME_DIALOG(dialog));

  if ( result == 0 ) {
    child = ((struct _GtkBoxChild *)(g_list_nth_data(dialog_children,
3)));
    entry = child->widget;
    g_print("%s\n", gtk_entry_get_text(GTK_ENTRY(entry)));
    
    child = ((struct _GtkBoxChild *)(g_list_nth_data(dialog_children,
5)));
    entry = child->widget;
    g_print("%s\n", gtk_entry_get_text(GTK_ENTRY(entry)));
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));
}

In short, this callback runs a gnome dialog and gets the data inside the
two GtkEntry included on that dialog. Inside this function I only have
access to the dialog widget.

As you can see, I have harcoded the positions of the GtkEntry widgets
inside the GList. If I modify the dialog, adding another widget, then
this function will break because the entries won't be at the index 3 and
5.

What can I do to have a more elegant, not harcoded way, to reference the
GtkEntry widgets??

ALSO:

Is it a good idea to mess around directly with struct _GtkBoxChild???

Thanks for your help.




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