2011-05-25 [colin] 3.7.9cvs24
[claws.git] / src / action.c
index 28e8a58e415e5bd571c689620a0f4a943c19f115..3e6de2c6abf89b96a890b66de1c22bc1c53db116 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 1999-2011 Hiroyuki Yamamoto & The Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -89,6 +89,7 @@ struct _ChildInfo
        Children        *children;
        gchar           *cmd;
        pid_t            pid;
+       gint             next_sig;
        gint             chld_in;
        gint             chld_out;
        gint             chld_err;
@@ -106,8 +107,7 @@ struct _ChildInfo
        GSList          *msginfo_list;
 };
 
-static void action_update_menu         (GtkItemFactory *ifactory,
-                                        GtkUIManager   *ui_manager,
+static void action_update_menu         (GtkUIManager   *ui_manager,
                                         const gchar    *accel_group,
                                         gchar          *branch_path,
                                         gpointer        callback,
@@ -118,7 +118,9 @@ static void compose_actions_execute         (Compose        *compose,
                                         guint           action_nb,
                                         GtkWidget      *widget);
 
-static void mainwin_actions_execute_cb         (MainWindow     *mainwin,
+static void mainwin_actions_execute_cb (GtkWidget      *widget, 
+                                        gpointer        data);
+static void mainwin_actions_execute    (MainWindow     *mainwin,
                                         guint           action_nb,
                                         GtkWidget      *widget);
 
@@ -193,10 +195,11 @@ static gchar *get_user_string             (const gchar    *action,
 ActionType action_get_type(const gchar *action_str)
 {
        const gchar *p;
+       gboolean in_filtering_action = FALSE;
        ActionType action_type = ACTION_NONE;
 
-       g_return_val_if_fail(action_str,  ACTION_ERROR);
-       g_return_val_if_fail(*action_str, ACTION_ERROR);
+       cm_return_val_if_fail(action_str,  ACTION_ERROR);
+       cm_return_val_if_fail(*action_str, ACTION_ERROR);
 
        p = action_str;
 
@@ -215,55 +218,60 @@ ActionType action_get_type(const gchar *action_str)
                return ACTION_ERROR;
 
        while (*p && action_type != ACTION_ERROR) {
-               if (p[0] == '%' && p[1]) {
-                       switch (p[1]) {
-                       case 'a':
-                               /* CLAWS: filtering action is a mutually exclusive
-                                * action. we can enable others if needed later. we
-                                * add ACTION_SINGLE | ACTION_MULTIPLE so it will
-                                * only be executed from the main window toolbar */
-                               if (p[2] == 's')  /* source messages */
-                                       action_type = ACTION_FILTERING_ACTION 
-                                                   | ACTION_SINGLE 
-                                                   | ACTION_MULTIPLE;
-                               break;
-                       case 'f':
-                               action_type |= ACTION_SINGLE;
-                               break;
-                       case 'F':
-                               action_type |= ACTION_MULTIPLE;
-                               break;
-                       case 'p':
-                               action_type |= ACTION_SINGLE;
-                               break;
-                       case 's':
-                               action_type |= ACTION_SELECTION_STR;
-                               break;
-                       case 'u':
-                               action_type |= ACTION_USER_STR;
-                               break;
-                       case 'h':
-                               action_type |= ACTION_USER_HIDDEN_STR;
-                               break;
-                       case '%':
-                               /* literal '%' */
-                               break;
-                       default:
-                               action_type = ACTION_ERROR;
-                               break;
+               if (!in_filtering_action) {
+                       if (p[0] == '%' && p[1]) {
+                               switch (p[1]) {
+                               case 'a':
+                                       /* CLAWS: filtering action is a mutually exclusive
+                                       * action. we can enable others if needed later. we
+                                       * add ACTION_SINGLE | ACTION_MULTIPLE so it will
+                                       * only be executed from the main window toolbar */
+                                       if (p[2] == 's')  /* source messages */
+                                               action_type = ACTION_FILTERING_ACTION 
+                                                               | ACTION_SINGLE 
+                                                               | ACTION_MULTIPLE;
+                                       in_filtering_action = TRUE;
+                                       break;
+                               case 'f':
+                                       action_type |= ACTION_SINGLE;
+                                       break;
+                               case 'F':
+                                       action_type |= ACTION_MULTIPLE;
+                                       break;
+                               case 'p':
+                                       action_type |= ACTION_SINGLE;
+                                       break;
+                               case 's':
+                                       action_type |= ACTION_SELECTION_STR;
+                                       break;
+                               case 'u':
+                                       action_type |= ACTION_USER_STR;
+                                       break;
+                               case 'h':
+                                       action_type |= ACTION_USER_HIDDEN_STR;
+                                       break;
+                               case '%':
+                                       /* literal '%' */
+                                       break;
+                               default:
+                                       action_type = ACTION_ERROR;
+                                       break;
+                               }
+                               p++;
+                       } else if (p[0] == '|') {
+                               if (p[1] == '\0')
+                                       action_type |= ACTION_PIPE_OUT;
+                       } else if (p[0] == '>') {
+                               if (p[1] == '\0')
+                                       action_type |= ACTION_INSERT;
+                       } else if (p[0] == '&') {
+                               if (p[1] == '\0')
+                                       action_type |= ACTION_ASYNC;
+                       } else if (p[0] == '}') {
+                               in_filtering_action = FALSE;
                        }
-                       p++;
-               } else if (p[0] == '|') {
-                       if (p[1] == '\0')
-                               action_type |= ACTION_PIPE_OUT;
-               } else if (p[0] == '>') {
-                       if (p[1] == '\0')
-                               action_type |= ACTION_INSERT;
-               } else if (p[0] == '&') {
-                       if (p[1] == '\0')
-                               action_type |= ACTION_ASYNC;
                }
-               p++;
+                       p++;
        }
 
        return action_type;
@@ -364,7 +372,7 @@ static gboolean parse_append_filename(GString *cmd, MsgInfo *msginfo)
        gchar *p, *q;
        gchar escape_ch[] = "\\ ";
 
-       g_return_val_if_fail(msginfo, FALSE);
+       cm_return_val_if_fail(msginfo, FALSE);
 
        filename = procmsg_get_message_file(msginfo);
 
@@ -435,18 +443,18 @@ void actions_execute(gpointer data,
                     gint source)
 {
        if (source == TOOLBAR_MAIN) 
-               mainwin_actions_execute_cb((MainWindow*)data, action_nb, widget);
+               mainwin_actions_execute((MainWindow*)data, action_nb, widget);
        else if (source == TOOLBAR_COMPOSE)
                compose_actions_execute((Compose*)data, action_nb, widget);
        else if (source == TOOLBAR_MSGVIEW)
                msgview_actions_execute((MessageView*)data, action_nb, widget); 
 }
 
-void action_update_mainwin_menu(GtkItemFactory *ifactory,
+void action_update_mainwin_menu(GtkUIManager *ui_manager,
                                gchar *branch_path,
                                MainWindow *mainwin)
 {
-       action_update_menu(ifactory, NULL, "<MainwinActions>", branch_path,
+       action_update_menu(ui_manager, "<MainwinActions>", branch_path,
                           mainwin_actions_execute_cb, mainwin);
 }
 
@@ -454,7 +462,7 @@ void action_update_msgview_menu(GtkUIManager        *ui_manager,
                                gchar *branch_path,
                                MessageView *msgview)
 {
-       action_update_menu(NULL, ui_manager, "<MsgviewActions>", branch_path,
+       action_update_menu(ui_manager, "<MsgviewActions>", branch_path,
                           msgview_actions_execute_cb, msgview);
 }
 
@@ -462,7 +470,7 @@ void action_update_compose_menu(GtkUIManager *ui_manager,
                                gchar *branch_path,
                                Compose *compose)
 {
-       action_update_menu(NULL, ui_manager, "<ComposeActions>", branch_path,
+       action_update_menu(ui_manager, "<ComposeActions>", branch_path,
                           compose_actions_execute_cb, compose);
 }
 
@@ -508,93 +516,53 @@ static GtkWidget *create_submenus(GtkWidget *menu, const gchar *action)
        return new_menu ? new_menu : menu;
 }
 
-static void action_update_menu(GtkItemFactory *ifactory,
-                              GtkUIManager *ui_manager,
+static void action_update_menu(GtkUIManager *ui_manager,
                               const gchar *accel_group,
                               gchar *branch_path,
                               gpointer callback, gpointer data)
 {
-       GtkWidget *menuitem;
-       gchar *menu_path;
        GSList *cur;
        gchar *action, *action_p;
-       GList *amenu;
-       GtkItemFactoryEntry ifentry = {NULL, NULL, NULL, 0, "<Branch>"};
        int callback_action = 0;
-
-       if (ifactory) {
-               ifentry.path = branch_path;
-               menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
-               ifentry.accelerator     = NULL;
-               ifentry.callback_action = 0;
-               ifentry.callback        = callback;
-               ifentry.item_type       = NULL;
-               g_return_if_fail(menuitem != NULL);
-               amenu = GTK_MENU_SHELL(menuitem)->children;
-               while (amenu != NULL) {
-                       GList *alist = amenu->next;
-                       gtk_widget_destroy(GTK_WIDGET(amenu->data));
-                       amenu = alist;
-               }
-
-               for (cur = prefs_common.actions_list; cur; cur = cur->next) {
-                       action   = g_strdup((gchar *)cur->data);
-                       action_p = strstr(action, ": ");
-                       if (action_p && action_p[2] &&
-                           (action_get_type(&action_p[2]) != ACTION_ERROR) &&
-                           (action[0] != '/')) {
-                               action_p[0] = '\0';
-                               menu_path = g_strdup_printf("%s/%s", branch_path,
-                                                           action);
-                               ifentry.path = menu_path;
-                               gtk_item_factory_create_item(ifactory, &ifentry, data,
-                                                            1);
-                               g_free(menu_path);
+       GtkWidget *menu = gtk_menu_new();
+       GtkWidget *item;
+
+       for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
+               GtkWidget *cur_menu = menu;
+               const gchar *action_name = NULL;
+               action   = g_strdup((gchar *)cur->data);
+               action_p = strstr(action, ": ");
+               if (action_p && action_p[2] &&
+                   (action_get_type(&action_p[2]) != ACTION_ERROR) &&
+                   (action[0] != '/')) {
+                       gchar *accel_path = NULL;
+
+                       action_p[0] = '\0';
+                       if (strchr(action, '/')) {
+                               cur_menu = create_submenus(cur_menu, action);
+                               action_name = strrchr(action, '/')+1;
+                       } else {
+                               action_name = action;
                        }
-                       g_free(action);
-                       ifentry.callback_action++;
-               }
-       } else {
-               GtkWidget *menu = gtk_menu_new();
-               GtkWidget *item;
-               for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
-                       GtkWidget *cur_menu = menu;
-                       const gchar *action_name = NULL;
-                       action   = g_strdup((gchar *)cur->data);
-                       action_p = strstr(action, ": ");
-                       if (action_p && action_p[2] &&
-                           (action_get_type(&action_p[2]) != ACTION_ERROR) &&
-                           (action[0] != '/')) {
-                               gchar *accel_path = NULL;
-
-                               action_p[0] = '\0';
-                               if (strchr(action, '/')) {
-                                       cur_menu = create_submenus(cur_menu, action);
-                                       action_name = strrchr(action, '/')+1;
-                               } else {
-                                       action_name = action;
-                               }
-                               gtk_menu_set_accel_group (GTK_MENU (cur_menu), 
-                                       gtk_ui_manager_get_accel_group(ui_manager));
-                               item = gtk_menu_item_new_with_label(action_name);
-                               gtk_menu_shell_append(GTK_MENU_SHELL(cur_menu), item);
-                               g_signal_connect(G_OBJECT(item), "activate",
-                                                G_CALLBACK(callback), data);
-                               g_object_set_data(G_OBJECT(item), "action_num", GINT_TO_POINTER(callback_action));
-                               gtk_widget_show(item);
-                               accel_path = g_strconcat(accel_group,branch_path, "/", action, NULL);
-                               gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
-                               g_free(accel_path);
+                       gtk_menu_set_accel_group (GTK_MENU (cur_menu), 
+                               gtk_ui_manager_get_accel_group(ui_manager));
+                       item = gtk_menu_item_new_with_label(action_name);
+                       gtk_menu_shell_append(GTK_MENU_SHELL(cur_menu), item);
+                       g_signal_connect(G_OBJECT(item), "activate",
+                                        G_CALLBACK(callback), data);
+                       g_object_set_data(G_OBJECT(item), "action_num", GINT_TO_POINTER(callback_action));
+                       gtk_widget_show(item);
+                       accel_path = g_strconcat(accel_group,branch_path, "/", action, NULL);
+                       gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
+                       g_free(accel_path);
 
-                       }
-                       g_free(action);
-                       callback_action++;
                }
-
-               gtk_widget_show(menu);
-               gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtk_ui_manager_get_widget(ui_manager, branch_path)), menu);
-
+               g_free(action);
+               callback_action++;
        }
+
+       gtk_widget_show(menu);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtk_ui_manager_get_widget(ui_manager, branch_path)), menu);
 }
 
 static void compose_actions_execute_cb(GtkWidget *widget, gpointer data)
@@ -609,12 +577,12 @@ static void compose_actions_execute(Compose *compose, guint action_nb, GtkWidget
        gchar *buf, *action;
        ActionType action_type;
 
-       g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
+       cm_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
 
        buf = (gchar *)g_slist_nth_data(prefs_common.actions_list, action_nb);
-       g_return_if_fail(buf != NULL);
+       cm_return_if_fail(buf != NULL);
        action = strstr(buf, ": ");
-       g_return_if_fail(action != NULL);
+       cm_return_if_fail(action != NULL);
 
        /* Point to the beginning of the command-line */
        action += 2;
@@ -631,7 +599,14 @@ static void compose_actions_execute(Compose *compose, guint action_nb, GtkWidget
                compose_action_cb, compose);
 }
 
-static void mainwin_actions_execute_cb(MainWindow *mainwin, guint action_nb,
+static void mainwin_actions_execute_cb(GtkWidget *widget, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+       gint action_nb = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "action_num"));
+       mainwin_actions_execute(mainwin, action_nb, NULL);
+}
+
+static void mainwin_actions_execute(MainWindow *mainwin, guint action_nb,
                                       GtkWidget *widget)
 {
        GSList *msg_list;
@@ -670,12 +645,12 @@ static void message_actions_execute(MessageView *msgview, guint action_nb,
        guint body_pos = 0;
        ActionType action_type;
        
-       g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
+       cm_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
 
        buf = (gchar *)g_slist_nth_data(prefs_common.actions_list, action_nb);
 
-       g_return_if_fail(buf);
-       g_return_if_fail((action = strstr(buf, ": ")));
+       cm_return_if_fail(buf);
+       cm_return_if_fail((action = strstr(buf, ": ")));
 
        /* Point to the beginning of the command-line */
        action += 2;
@@ -783,7 +758,7 @@ static gboolean execute_actions(gchar *action, GSList *msg_list,
        GtkTextIter start_iter, end_iter;
        gboolean is_selection = FALSE;
 
-       g_return_val_if_fail(action && *action, FALSE);
+       cm_return_val_if_fail(action && *action, FALSE);
 
        action_type = action_get_type(action);
 
@@ -922,9 +897,10 @@ static gboolean execute_actions(gchar *action, GSList *msg_list,
                        child_info->callback = callback;
                        child_info->data = data;
                        child_info->tag_status = 
-                               gdk_input_add(child_info->chld_status,
+                               claws_input_add(child_info->chld_status,
                                              GDK_INPUT_READ,
-                                             catch_status, child_info);
+                                             catch_status, child_info,
+                                             FALSE);
                }
 
                create_io_dialog(children);
@@ -972,13 +948,10 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
 
        pid = fork();
        if (pid == 0) { /* Child */
+               int r = 0;
                if (setpgid(0, 0))
                        perror("setpgid");
 
-#ifdef GDK_WINDOWING_X11
-               (void)close(ConnectionNumber(gdk_display));
-#endif /* GDK_WINDOWING_X11 */
-
                gch_pid = fork();
 
                if (gch_pid == 0) {
@@ -990,21 +963,24 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                                    (ACTION_PIPE_IN |
                                     ACTION_USER_IN |
                                     ACTION_USER_HIDDEN_IN)) {
-                                       (void)close(fileno(stdin));
-                                       (void)dup  (chld_in[0]);
+                                       r |= close(fileno(stdin));
+                                       (void) dup  (chld_in[0]);
                                }
-                               (void)close(chld_in[0]);
-                               (void)close(chld_in[1]);
-
-                               (void)close(fileno(stdout));
-                               (void)dup  (chld_out[1]);
-                               (void)close(chld_out[0]);
-                               (void)close(chld_out[1]);
-
-                               (void)close(fileno(stderr));
-                               (void)dup  (chld_err[1]);
-                               (void)close(chld_err[0]);
-                               (void)close(chld_err[1]);
+                               r |= close(chld_in[0]);
+                               r |= close(chld_in[1]);
+
+                               r |= close(fileno(stdout));
+                               (void) dup  (chld_out[1]);
+                               r |= close(chld_out[0]);
+                               r |= close(chld_out[1]);
+
+                               r |= close(fileno(stderr));
+                               (void) dup  (chld_err[1]);
+                               r |= close(chld_err[0]);
+                               r |= close(chld_err[1]);
+
+                               if (r != 0)
+                                       debug_print("%s(%d)", strerror(errno), errno);
                        }
 
                        cmdline[0] = "sh";
@@ -1024,24 +1000,29 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                        _exit(1);
                } else if (gch_pid < (pid_t) 0) { /* Fork error */
                        if (sync)
-                               (void)write(chld_status[1], "1\n", 2);
+                               r = write(chld_status[1], "1\n", 2);
+                       if (r != 0)
+                               debug_print("%s(%d)", strerror(errno), errno);
                        perror("fork");
                        _exit(1);
                } else { /* Child */
                        if (sync) {
-                               (void)close(chld_in[0]);
-                               (void)close(chld_in[1]);
-                               (void)close(chld_out[0]);
-                               (void)close(chld_out[1]);
-                               (void)close(chld_err[0]);
-                               (void)close(chld_err[1]);
-                               (void)close(chld_status[0]);
+                               r |= close(chld_in[0]);
+                               r |= close(chld_in[1]);
+                               r |= close(chld_out[0]);
+                               r |= close(chld_out[1]);
+                               r |= close(chld_err[0]);
+                               r |= close(chld_err[1]);
+                               r |= close(chld_status[0]);
 
                                debug_print("Child: waiting for grandchild\n");
-                               waitpid(gch_pid, NULL, 0);
+                               r |= waitpid(gch_pid, NULL, 0);
                                debug_print("Child: grandchild ended\n");
-                               (void)write(chld_status[1], "0\n", 2);
-                               (void)close(chld_status[1]);
+                               r |= write(chld_status[1], "0\n", 2);
+                               r |= close(chld_status[1]);
+
+                               if (r != 0)
+                                       debug_print("%s(%d)", strerror(errno), errno);
                        }
                        _exit(0);
                }
@@ -1072,6 +1053,7 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
        child_info->children    = children;
 
        child_info->pid         = pid;
+       child_info->next_sig    = SIGTERM;
        child_info->cmd         = g_strdup(cmd);
        child_info->new_out     = FALSE;
        child_info->output      = g_string_new(NULL);
@@ -1083,27 +1065,30 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
        child_info->chld_err    = chld_err[0];
        child_info->chld_status = chld_status[0];
        child_info->tag_in      = -1;
-       child_info->tag_out     = gdk_input_add(chld_out[0], GDK_INPUT_READ,
-                                               catch_output, child_info);
-       child_info->tag_err     = gdk_input_add(chld_err[0], GDK_INPUT_READ,
-                                               catch_output, child_info);
+       child_info->tag_out     = claws_input_add(chld_out[0], GDK_INPUT_READ,
+                                               catch_output, child_info, FALSE);
+       child_info->tag_err     = claws_input_add(chld_err[0], GDK_INPUT_READ,
+                                               catch_output, child_info, FALSE);
 
        if (!(children->action_type &
              (ACTION_PIPE_IN | ACTION_PIPE_OUT | ACTION_INSERT)))
                return child_info;
 
        if ((children->action_type & ACTION_PIPE_IN) && msg_str) {
+               int r;
                ret_str = g_locale_from_utf8(msg_str, strlen(msg_str),
                                             &by_read, &by_written, NULL);
                if (ret_str && by_written) {
-                       (void)write(chld_in[1], ret_str, strlen(ret_str));
+                       r = write(chld_in[1], ret_str, strlen(ret_str));
                        g_free(ret_str);
                } else
-                       (void)write(chld_in[1], msg_str, strlen(msg_str));
+                       r = write(chld_in[1], msg_str, strlen(msg_str));
                if (!(children->action_type &
                      (ACTION_USER_IN | ACTION_USER_HIDDEN_IN)))
-                       (void)close(chld_in[1]);
+                       r = close(chld_in[1]);
                child_info->chld_in = -1; /* No more input */
+               if (r != 0)
+                       debug_print("%s(%d)", strerror(errno), errno);
        }
 
        return child_info;
@@ -1122,8 +1107,9 @@ static void kill_children_cb(GtkWidget *widget, gpointer data)
        for (cur = children->list; cur; cur = cur->next) {
                child_info = (ChildInfo *)(cur->data);
                debug_print("Killing child group id %d\n", child_info->pid);
-               if (child_info->pid && kill(-child_info->pid, SIGTERM) < 0)
+               if (child_info->pid && kill(-child_info->pid, child_info->next_sig) < 0)
                        perror("kill");
+               child_info->next_sig = SIGKILL;
        }
 #endif /* G_OS_UNIX */
 }
@@ -1133,23 +1119,18 @@ static gint wait_for_children(Children *children)
        gboolean new_output;
        ChildInfo *child_info;
        GSList *cur;
-       gint nb = children->nb;
-
-       children->nb = 0;
 
        cur = children->list;
        new_output = FALSE;
        while (cur) {
                child_info = (ChildInfo *)cur->data;
-               if (child_info->pid)
-                       children->nb++;
                new_output |= child_info->new_out;
                cur = cur->next;
        }
 
        children->output |= new_output;
 
-       if (new_output || (children->dialog && (nb != children->nb)))
+       if (new_output || (children->dialog && (children->initial_nb != children->nb)))
                update_io_dialog(children);
 
        if (children->nb)
@@ -1169,9 +1150,9 @@ static void send_input(GtkWidget *w, gpointer data)
        Children *children = (Children *) data;
        ChildInfo *child_info = (ChildInfo *) children->list->data;
 
-       child_info->tag_in = gdk_input_add(child_info->chld_in,
+       child_info->tag_in = claws_input_add(child_info->chld_in,
                                           GDK_INPUT_WRITE,
-                                          catch_input, children);
+                                          catch_input, children, FALSE);
 }
 
 static gint delete_io_dialog_cb(GtkWidget *w, GdkEvent *e, gpointer data)
@@ -1212,11 +1193,11 @@ static void childinfo_close_pipes(ChildInfo *child_info)
         * them if necessary
         */
        if (child_info->tag_in > 0)
-               gdk_input_remove(child_info->tag_in);
+               g_source_remove(child_info->tag_in);
        if (child_info->tag_out > 0)
-               gdk_input_remove(child_info->tag_out);
+               g_source_remove(child_info->tag_out);
        if (child_info->tag_err > 0)
-               gdk_input_remove(child_info->tag_err);
+               g_source_remove(child_info->tag_err);
 
        if (child_info->chld_in >= 0)
                (void)close(child_info->chld_in);
@@ -1261,17 +1242,23 @@ static void update_io_dialog(Children *children)
 
        if (children->progress_bar) {
                gchar *text;
+#ifdef GENERIC_UMPC
+               /* use a more compact format */
+               const gchar *format = "%s %d/%d";
+#else
+               const gchar *format = "%s %d / %d";
+#endif
                
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(children->progress_bar),
                                                  (children->initial_nb == 0) ? 0 :
                                              (gdouble) (children->initial_nb - children->nb) /
                                              (gdouble) children->initial_nb);
-               text = g_strdup_printf("%s %d/%d", _("Completed"), 
+               text = g_strdup_printf(format, _("Completed"), 
                                       children->initial_nb - children->nb,
                                       children->initial_nb);
                gtk_progress_bar_set_text(GTK_PROGRESS_BAR(children->progress_bar), text);
                g_free(text);
-       }                                             
+       }
 
        if (!children->nb) {
                gtk_widget_set_sensitive(children->abort_btn, FALSE);
@@ -1417,12 +1404,18 @@ static void create_io_dialog(Children *children)
        }
 
        if (children->initial_nb > 1) {
-               gchar * text;
+               gchar *text;
+#ifdef GENERIC_UMPC
+               /* use a more compact format */
+               const gchar *format = "%s 0/%d\n";
+#else
+               const gchar *format = "%s 0 / %d\n";
+#endif
                
                progress_bar = gtk_progress_bar_new();
                gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(progress_bar),
                                GTK_PROGRESS_LEFT_TO_RIGHT);
-               text = g_strdup_printf("%s 0/%d\n", _("Completed"), 
+               text = g_strdup_printf(format, _("Completed"), 
                                       children->initial_nb);
                gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar),
                                          text);
@@ -1462,7 +1455,7 @@ static void catch_status(gpointer data, gint source, GdkInputCondition cond)
        gchar buf;
        gint c;
 
-       gdk_input_remove(child_info->tag_status);
+       g_source_remove(child_info->tag_status);
 
        c = read(source, &buf, 1);
        debug_print("Child returned %c\n", buf);
@@ -1518,6 +1511,9 @@ static void catch_status(gpointer data, gint source, GdkInputCondition cond)
                child_info->msginfo_list = NULL;
        }
 
+       if (!child_info->pid)
+               child_info->children->nb--;
+
        wait_for_children(child_info->children);
 }
        
@@ -1526,17 +1522,17 @@ static void catch_input(gpointer data, gint source, GdkInputCondition cond)
        Children *children = (Children *)data;
        ChildInfo *child_info = (ChildInfo *)children->list->data;
        gchar *input, *ret_str;
-       gint c, count, len;
+       gint c, count, len, r;
        gssize by_read = 0, by_written = 0;
 
        debug_print("Sending input to grand child.\n");
-       if (!(cond && GDK_INPUT_WRITE))
+       if (!(cond & GDK_INPUT_WRITE))
                return;
 
        gtk_widget_set_sensitive(children->input_hbox, FALSE);
        gtk_widget_grab_focus(children->abort_btn);
 
-       gdk_input_remove(child_info->tag_in);
+       g_source_remove(child_info->tag_in);
        child_info->tag_in = -1;
 
        input = gtk_editable_get_chars(GTK_EDITABLE(children->input_entry),
@@ -1558,11 +1554,13 @@ static void catch_input(gpointer data, gint source, GdkInputCondition cond)
        } while (c >= 0 && count < len);
 
        if (c >= 0)
-               (void)write(child_info->chld_in, "\n", 2);
+               r = write(child_info->chld_in, "\n", 2);
 
        g_free(input);
 
-       (void)close(child_info->chld_in);
+       r = close(child_info->chld_in);
+       if (r != 0)
+               debug_print("%s(%d)", strerror(errno), errno);
        child_info->chld_in = -1;
        debug_print("Input to grand child sent.\n");
 }
@@ -1635,12 +1633,12 @@ static void catch_output(gpointer data, gint source, GdkInputCondition cond)
        }
        if (c == 0) {
                if (source == child_info->chld_out) {
-                       gdk_input_remove(child_info->tag_out);
+                       g_source_remove(child_info->tag_out);
                        child_info->tag_out = -1;
                        (void)close(child_info->chld_out);
                        child_info->chld_out = -1;
                } else {
-                       gdk_input_remove(child_info->tag_err);
+                       g_source_remove(child_info->tag_err);
                        child_info->tag_err = -1;
                        (void)close(child_info->chld_err);
                        child_info->chld_err = -1;