GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 23, 2014 8:21 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GtkDialog + fork()
PostPosted: Mon Oct 08, 2012 11:20 pm 
Offline

Joined: Mon Oct 08, 2012 2:06 pm
Posts: 1
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


Top
 Profile  
 
 Post subject: Re: GtkDialog + fork()
PostPosted: Tue Oct 09, 2012 6:12 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Don't use gtk_dialog_run. This effectively makes the dialog modal and freezes up other gtk activity from being processed.
Instead you should set up signals and let the function end and return to the gtk_main loop where all the signals (for IO, the dialog, etc) can be handled properly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group