[Glade-users] Update progressbar from forked child



Hi there,

This is my first attempt to Gtk Programming in Glade. Although I know
php and a little VB, It's been a long time since I used ansi C and maybe
I'm doing stupid things.  Please feel free to point them out :-)

I'm trying to make a front-end to ufraw-batch, a CLI program to convert
RAW images to a standard format.
I've built a nice interface to select the files and some options, and
ofcourse a start-button :-)
When I press start, I want the following to happen:
- All selected RAW images will be converted one by one
- Application window can't freeze while converting, I want to be able to
show a progress bar and status info
- After each image converted, I want to update the progress bar

The code I've writte to do that is pasted below...
(It works, the window isn't freezing until after the converts of all
files, but the progressbar is not updated)
(watch the use of 'fork' and 'vfork'. If I don't do it that way, the app
freezes until after convertion or the execve-statement isn't executed)
(To get rid of the first child after termination, I've created a signal
handler for SIGCHLD which executes "wait(NULL);")

If there are other, more standard ways, to do what I'm doing, please
tell me :-)  I'm not familiar with programming a GUI, but I know php
quiet well and I want to learn... 


Thx in advance
Steven


============== CODE ==============

    char *argv[] = {"", ...}

    int pid=fork();
    if (pid == 0)
    {
        while (files)
        {
            pid=vfork ();
            if (pid == 0)
            {
                GtkWidget *progressbar =
lookup_widget(GTK_WIDGET(button), "progressbar1");
printf("Set fraction from %f to %f\n",
gtk_progress_bar_get_fraction(progressbar), counter*PBfraction+PBfraction);
                gtk_progress_bar_set_fraction(progressbar,
(counter*PBfraction+PBfraction));
                execve("/usr/bin/ufraw-batch", argv, envp);
                _exit(0);
            }
            else
            {
                wait(NULL);
            }
            counter++;
        }
        _exit(0)
    }

============== /CODE ==============




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