file selection bombs



Hi,

I'm suffering from a problem within the file selection box. Nearly every time
I select a file, then OK, the app bombs with SIGABRT:

--snip--
nils@rhpc60:~/boomerang/src> boom

** ERROR **: BadWindow (invalid Window parameter)
IOT trap/Abort
nils@rhpc60:~/boomerang/src> 
--snap--

As far as I can see, It bombs at gtk_widget_destroy(), where the
fileselectorbox should be unmapped (and the memory should be released of
course)

The relevant source pieces are the following:

--snip--
void
file_upload_cmd_callback (GtkWidget * widget, gpointer data)
{
  GtkWidget *filew;
[...]
  filew = gtk_file_selection_new (PROGNAME " - Upload File");
[...]
  gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
			"clicked", (GtkSignalFunc) file_upload_ok_sel, GTK_WIDGET(filew));
[...]
}

gint
file_upload_del_callback (GtkWidget *widget, GdkEvent *event, GtkWidget *dlg)
{
  file_upload_cancel_sel(widget, dlg);
  return FALSE;
}

void
file_upload_cancel_sel (GtkWidget *widget, GtkWidget *dlg)
{
  gtk_widget_hide(dlg);
  gtk_widget_destroy(dlg);
  UploadDlg=0;
  do_menus();
}

void
file_upload_ok_sel (GtkWidget *widget, GtkWidget *dlg)
{
  char newfilename[1025];
  FILE *fd;
  strncpy(newfilename,gtk_file_selection_get_filename (GTK_FILE_SELECTION (dlg)),1024);
  gtk_widget_hide(GTK_WIDGET(dlg));
  gtk_widget_destroy(GTK_WIDGET(dlg));
  if((fd=fopen(newfilename, "r"))==(FILE *) NULL) {
    fclose(fd);
    file_upload_fileerror();
  } else {
    fclose(fd);
    strcpy(filename, newfilename);
  }
  UploadDlg=0;
  do_menus();
}
--snip--

I've attached the complete source file so ou can check if I've included
everything interesting :-)

Regards Nils

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Nils Philippsen                      @college: nils@rhlx01.rz.fht-esslingen.de
Vogelsangstrasse 115                @home: nils@wombat.dialup.fht-esslingen.de
D 70197 Stuttgart                     Do not meddle in the affairs of wizards,
+49-711-6599405                     for you are crunchy and good with ketchup.
#include <gtk/gtk.h>
#include <string.h>

#include "boomerang.h"
#include "globals.h"
#include "menus.h"
#include "updownload.h"

void
file_upload_cmd_callback (GtkWidget * widget, gpointer data)
{
  GtkWidget *filew;
  UploadDlg=1;
  do_menus();
  filew = gtk_file_selection_new (PROGNAME " - Upload File");
  gtk_signal_connect (GTK_OBJECT (filew), "delete_event", 
			(GtkSignalFunc) file_upload_del_callback, GTK_WIDGET(filew));
  gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
			"clicked", (GtkSignalFunc) file_upload_ok_sel, GTK_WIDGET(filew));
  gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
			"clicked", (GtkSignalFunc) file_upload_cancel_sel, GTK_WIDGET(filew));
  gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), filename);
  gtk_widget_show(filew);
}

gint
file_upload_del_callback (GtkWidget *widget, GdkEvent *event, GtkWidget *dlg)
{
  file_upload_cancel_sel(widget, dlg);
  return FALSE;
}

void
file_upload_cancel_sel (GtkWidget *widget, GtkWidget *dlg)
{
  gtk_widget_hide(dlg);
  gtk_widget_destroy(dlg);
  UploadDlg=0;
  do_menus();
}

void
file_upload_ok_sel (GtkWidget *widget, GtkWidget *dlg)
{
  char newfilename[1025];
  FILE *fd;
  strncpy(newfilename,gtk_file_selection_get_filename (GTK_FILE_SELECTION (dlg)),1024);
  gtk_widget_hide(GTK_WIDGET(dlg));
  gtk_widget_destroy(GTK_WIDGET(dlg));
  if((fd=fopen(newfilename, "r"))==(FILE *) NULL) {
    fclose(fd);
    file_upload_fileerror();
  } else {
    fclose(fd);
    strcpy(filename, newfilename);
  }
  UploadDlg=0;
  do_menus();
}

void
file_upload_fileerror(void)
{
  GtkWidget *window;
  GtkWidget *label;
  GtkWidget *button;

  window=gtk_dialog_new();

  gtk_grab_add(window);

  gtk_container_border_width(GTK_CONTAINER(window),10);

  gtk_grab_add(window);

  gtk_window_set_title (GTK_WINDOW (window), PROGNAME " - Error");

  label=gtk_label_new("File could not be accessed");

  gtk_container_add(GTK_CONTAINER(GTK_DIALOG(window)->vbox), label);

  gtk_widget_show(label);

  button=gtk_button_new_with_label("  OK  ");

  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);

  gtk_container_add(GTK_CONTAINER(GTK_DIALOG(window)->action_area), button);

  gtk_widget_grab_default (button);

  gtk_signal_connect (GTK_OBJECT(button), "delete_event", (GtkSignalFunc) file_upload_fileerror_del, window);

  gtk_signal_connect (GTK_OBJECT(button), "clicked", (GtkSignalFunc) file_upload_fileerror_ok, window);

  gtk_widget_show(button);

  gtk_widget_show(window);

}

gint
file_upload_fileerror_del(GtkWidget *widget, GdkEvent *event, GtkWidget *dlg)
{
  file_upload_fileerror_ok(widget, dlg);
  return FALSE;
}

void
file_upload_fileerror_ok(GtkWidget *widget, GtkWidget *dlg)
{
  gtk_grab_remove(dlg);
  gtk_widget_hide(dlg);
  gtk_widget_destroy(dlg);
}


void
file_download_cmd_callback (GtkWidget * widget, gpointer data)
{
  return;
}


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