Hello,
I need a standard "Sending File" type of a dialog. It should provide a mean to cancel network transmission at any point and then destroy itself (i.e. without user inteaction) upon task completion. All networking part is done as a child process controlled by SIGALRM.
Below is a piece of code that correctly treats "Cancelling" task, but stays in the gtk_dialog_run loop until killed manually in a case of "Success".
Code:
volatile sig_atomic_t child_running_flag=1;
static GtkWidget *dialog;
void sigchld_received (int sig)
{
child_running_flag=0;
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_DELETE_EVENT);
}
int show_dialog (GtkWidget *mainwindow, pid_t pid)
{
int result;
dialog=gtk_dialog_new_with_buttons(
"transmission in progess",
GTK_WINDOW (mainwindow),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
signal (SIGCHLD, sigchld_received);
result=gtk_dialog_run (GTK_DIALOG (dialog));
if (result==GTK_RESPONSE_CANCEL)
{
fprintf (stderr, "cancelling transmission\n");
kill (pid, SIGALRM);
}
gtk_widget_destroy (dialog);
return result;
}
Connecting a "response" signal to the widget_destroy function
g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
hangs up the gtk_dialog_run () with a failing assertion `gtk_widget_get_visible ()'.
Setting sigchld_received() to call gtk_widget_destroy (dialog) directly, certainly also screws the performance, but in a different way.
Basically the question is : if emission of a "delete-event" signal
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_DELETE_EVENT);
sets up a correct value for the `result' variable, invocation of which instances would fall me out of the gtk_dialog_run loop?
Thanks.
-alex