2004-11-08 [colin] 0.9.12cvs141
[claws.git] / src / action.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 Hiroyuki Yamamoto & The Sylpheed Claws Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <gdk/gdkx.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <sys/types.h>
35 #include <sys/wait.h>
36 #include <signal.h>
37 #include <unistd.h>
38
39 #include "intl.h"
40 #include "utils.h"
41 #include "gtkutils.h"
42 #include "manage_window.h"
43 #include "mainwindow.h"
44 #include "prefs_common.h"
45 #include "alertpanel.h"
46 #include "inputdialog.h"
47 #include "action.h"
48 #include "compose.h"
49 #include "procmsg.h"
50 #include "gtkstext.h"
51 #include "textview.h"
52 #include "matcher_parser.h" /* CLAWS */
53 #include "filtering.h"
54
55 typedef struct _Children                Children;
56 typedef struct _ChildInfo               ChildInfo;
57 typedef struct _UserStringDialog        UserStringDialog;
58
59 struct _Children
60 {
61         GtkWidget       *dialog;
62         GtkWidget       *text;
63         GtkWidget       *input_entry;
64         GtkWidget       *input_hbox;
65         GtkWidget       *progress_bar;
66         GtkWidget       *abort_btn;
67         GtkWidget       *close_btn;
68         GtkWidget       *scrolledwin;
69
70         gchar           *action;
71         ActionType       action_type;
72         GSList          *list;
73         gint             nb;
74         gint             initial_nb;
75         gint             open_in;
76         gboolean         output;
77
78         GtkWidget       *msg_text;
79         GdkFont         *msgfont;
80 };
81
82 struct _ChildInfo
83 {
84         Children        *children;
85         gchar           *cmd;
86         pid_t            pid;
87         gint             chld_in;
88         gint             chld_out;
89         gint             chld_err;
90         gint             chld_status;
91         gint             tag_in;
92         gint             tag_out;
93         gint             tag_err;
94         gint             tag_status;
95         gint             new_out;
96
97         GString         *output;
98 };
99
100 static void action_update_menu          (GtkItemFactory *ifactory,
101                                          gchar          *branch_path,
102                                          gpointer        callback,
103                                          gpointer        data);
104 static void compose_actions_execute_cb  (Compose        *compose,
105                                          guint           action_nb,
106                                          GtkWidget      *widget);
107 static void mainwin_actions_execute_cb  (MainWindow     *mainwin,
108                                          guint           action_nb,
109                                          GtkWidget      *widget);
110 static void msgview_actions_execute_cb  (MessageView    *msgview,
111                                          guint           action_nb,
112                                          GtkWidget      *widget);
113 static void message_actions_execute     (MessageView    *msgview,
114                                          guint           action_nb,
115                                          GSList         *msg_list);
116
117 static gboolean execute_filtering_actions(gchar         *action, 
118                                           GSList        *msglist);
119
120 static gboolean execute_actions         (gchar          *action, 
121                                          GSList         *msg_list, 
122                                          GtkWidget      *text,
123                                          GdkFont        *msgfont,
124                                          gint            body_pos,
125                                          MimeInfo       *partinfo);
126
127 static gchar *parse_action_cmd          (gchar          *action,
128                                          MsgInfo        *msginfo,
129                                          GSList         *msg_list,
130                                          MimeInfo       *partinfo,
131                                          const gchar    *user_str,
132                                          const gchar    *user_hidden_str,
133                                          const gchar    *sel_str);
134 static gboolean parse_append_filename   (GString        *cmd,
135                                          MsgInfo        *msginfo);
136
137 static gboolean parse_append_msgpart    (GString        *cmd,
138                                          MsgInfo        *msginfo,
139                                          MimeInfo       *partinfo);
140
141 static ChildInfo *fork_child            (gchar          *cmd,
142                                          const gchar    *msg_str,
143                                          Children       *children);
144
145 static gint wait_for_children           (Children       *children);
146
147 static void free_children               (Children       *children);
148
149 static void childinfo_close_pipes       (ChildInfo      *child_info);
150
151 static void create_io_dialog            (Children       *children);
152 static void update_io_dialog            (Children       *children);
153
154 static void hide_io_dialog_cb           (GtkWidget      *widget,
155                                          gpointer        data);
156 static gint io_dialog_key_pressed_cb    (GtkWidget      *widget,
157                                          GdkEventKey    *event,
158                                          gpointer        data);
159
160 static void catch_output                (gpointer                data,
161                                          gint                    source,
162                                          GdkInputCondition       cond);
163 static void catch_input                 (gpointer                data, 
164                                          gint                    source,
165                                          GdkInputCondition       cond);
166 static void catch_status                (gpointer                data,
167                                          gint                    source,
168                                          GdkInputCondition       cond);
169
170 static gchar *get_user_string           (const gchar    *action,
171                                          ActionType      type);
172
173
174 ActionType action_get_type(const gchar *action_str)
175 {
176         const gchar *p;
177         ActionType action_type = ACTION_NONE;
178
179         g_return_val_if_fail(action_str,  ACTION_ERROR);
180         g_return_val_if_fail(*action_str, ACTION_ERROR);
181
182         p = action_str;
183
184         if (p[0] == '|') {
185                 action_type |= ACTION_PIPE_IN;
186                 p++;
187         } else if (p[0] == '>') {
188                 action_type |= ACTION_USER_IN;
189                 p++;
190         } else if (p[0] == '*') {
191                 action_type |= ACTION_USER_HIDDEN_IN;
192                 p++;
193         }
194
195         if (p[0] == '\0')
196                 return ACTION_ERROR;
197
198         while (*p && action_type != ACTION_ERROR) {
199                 if (p[0] == '%' && p[1]) {
200                         switch (p[1]) {
201                         case 'a':
202                                 /* CLAWS: filtering action is a mutually exclusive
203                                  * action. we can enable others if needed later. we
204                                  * add ACTION_SINGLE | ACTION_MULTIPLE so it will
205                                  * only be executed from the main window toolbar */
206                                 if (p[2] == 's')  /* source messages */
207                                         action_type = ACTION_FILTERING_ACTION 
208                                                     | ACTION_SINGLE 
209                                                     | ACTION_MULTIPLE;
210                                 break;
211                         case 'f':
212                                 action_type |= ACTION_SINGLE;
213                                 break;
214                         case 'F':
215                                 action_type |= ACTION_MULTIPLE;
216                                 break;
217                         case 'p':
218                                 action_type |= ACTION_SINGLE;
219                                 break;
220                         case 's':
221                                 action_type |= ACTION_SELECTION_STR;
222                                 break;
223                         case 'u':
224                                 action_type |= ACTION_USER_STR;
225                                 break;
226                         case 'h':
227                                 action_type |= ACTION_USER_HIDDEN_STR;
228                                 break;
229                         default:
230                                 action_type = ACTION_ERROR;
231                                 break;
232                         }
233                 } else if (p[0] == '|') {
234                         if (p[1] == '\0')
235                                 action_type |= ACTION_PIPE_OUT;
236                 } else if (p[0] == '>') {
237                         if (p[1] == '\0')
238                                 action_type |= ACTION_INSERT;
239                 } else if (p[0] == '&') {
240                         if (p[1] == '\0')
241                                 action_type |= ACTION_ASYNC;
242                 }
243                 p++;
244         }
245
246         return action_type;
247 }
248
249 static gchar *parse_action_cmd(gchar *action, MsgInfo *msginfo,
250                                GSList *msg_list, MimeInfo *partinfo,
251                                const gchar *user_str,
252                                const gchar *user_hidden_str,
253                                const gchar *sel_str)
254 {
255         GString *cmd;
256         gchar *p;
257         GSList *cur;
258         
259         p = action;
260         
261         if (p[0] == '|' || p[0] == '>' || p[0] == '*')
262                 p++;
263
264         cmd = g_string_sized_new(strlen(action));
265
266         while (p[0] &&
267                !((p[0] == '|' || p[0] == '>' || p[0] == '&') && !p[1])) {
268                 if (p[0] == '%' && p[1]) {
269                         switch (p[1]) {
270                         case 'f':
271                                 if (!parse_append_filename(cmd, msginfo)) {
272                                         g_string_free(cmd, TRUE);
273                                         return NULL;
274                                 }
275                                 p++;
276                                 break;
277                         case 'F':
278                                 for (cur = msg_list; cur != NULL;
279                                      cur = cur->next) {
280                                         MsgInfo *msg = (MsgInfo *)cur->data;
281
282                                         if (!parse_append_filename(cmd, msg)) {
283                                                 g_string_free(cmd, TRUE);
284                                                 return NULL;
285                                         }
286                                         if (cur->next)
287                                                 g_string_append_c(cmd, ' ');
288                                 }
289                                 p++;
290                                 break;
291                         case 'p':
292                                 if (!parse_append_msgpart(cmd, msginfo,
293                                                           partinfo)) {
294                                         g_string_free(cmd, TRUE);
295                                         return NULL;
296                                 }
297                                 p++;
298                                 break;
299                         case 's':
300                                 if (sel_str)
301                                         g_string_append(cmd, sel_str);
302                                 p++;
303                                 break;
304                         case 'u':
305                                 if (user_str)
306                                         g_string_append(cmd, user_str);
307                                 p++;
308                                 break;
309                         case 'h':
310                                 if (user_hidden_str)
311                                         g_string_append(cmd, user_hidden_str);
312                                 p++;
313                                 break;
314                         default:
315                                 g_string_append_c(cmd, p[0]);
316                                 g_string_append_c(cmd, p[1]);
317                                 p++;
318                         }
319                 } else {
320                         g_string_append_c(cmd, p[0]);
321                 }
322                 p++;
323         }
324         if (cmd->len == 0) {
325                 g_string_free(cmd, TRUE);
326                 return NULL;
327         }
328
329         p = cmd->str;
330         g_string_free(cmd, FALSE);
331         return p;
332 }
333
334 static gboolean parse_append_filename(GString *cmd, MsgInfo *msginfo)
335 {
336         gchar *filename;
337
338         g_return_val_if_fail(msginfo, FALSE);
339
340         filename = procmsg_get_message_file(msginfo);
341
342         if (filename) {
343                 g_string_append(cmd, filename);
344                 g_free(filename);
345         } else {
346                 alertpanel_error(_("Could not get message file %d"),
347                                  msginfo->msgnum);
348                 return FALSE;
349         }
350
351         return TRUE;
352 }
353
354 static gboolean parse_append_msgpart(GString *cmd, MsgInfo *msginfo,
355                                      MimeInfo *partinfo)
356 {
357         gboolean single_part = FALSE;
358         gchar *filename;
359         gchar *part_filename;
360         gint ret;
361
362         if (!partinfo) {
363                 partinfo = procmime_scan_message(msginfo);
364                 if (!partinfo) {
365                         alertpanel_error(_("Could not get message part."));
366                         return FALSE;
367                 }
368
369                 single_part = TRUE;
370         }
371
372         filename = procmsg_get_message_file_path(msginfo);
373         part_filename = procmime_get_tmp_file_name(partinfo);
374
375         ret = procmime_get_part(part_filename, partinfo);
376
377         if (single_part)
378                 procmime_mimeinfo_free_all(partinfo);
379         g_free(filename);
380
381         if (ret < 0) {
382                 alertpanel_error(_("Can't get part of multipart message"));
383                 g_free(part_filename);
384                 return FALSE;
385         }
386
387         g_string_append(cmd, part_filename);
388
389         g_free(part_filename);
390
391         return TRUE;
392 }
393
394 void actions_execute(gpointer data, 
395                      guint action_nb,
396                      GtkWidget *widget,
397                      gint source)
398 {
399         if (source == TOOLBAR_MAIN) 
400                 mainwin_actions_execute_cb((MainWindow*)data, action_nb, widget);
401         else if (source == TOOLBAR_COMPOSE)
402                 compose_actions_execute_cb((Compose*)data, action_nb, widget);
403         else if (source == TOOLBAR_MSGVIEW)
404                 msgview_actions_execute_cb((MessageView*)data, action_nb, widget);      
405 }
406
407 void action_update_mainwin_menu(GtkItemFactory *ifactory,
408                                 gchar *branch_path,
409                                 MainWindow *mainwin)
410 {
411         action_update_menu(ifactory, branch_path,
412                            mainwin_actions_execute_cb, mainwin);
413 }
414
415 void action_update_msgview_menu(GtkItemFactory *ifactory,
416                                 gchar *branch_path,
417                                 MessageView *msgview)
418 {
419         action_update_menu(ifactory, branch_path,
420                            msgview_actions_execute_cb, msgview);
421 }
422
423 void action_update_compose_menu(GtkItemFactory *ifactory, 
424                                 gchar *branch_path,
425                                 Compose *compose)
426 {
427         action_update_menu(ifactory, branch_path,
428                            compose_actions_execute_cb, compose);
429 }
430
431 static void action_update_menu(GtkItemFactory *ifactory, 
432                                gchar *branch_path,
433                                gpointer callback, gpointer data)
434 {
435         GtkWidget *menuitem;
436         gchar *menu_path;
437         GSList *cur;
438         gchar *action, *action_p;
439         GList *amenu;
440         GtkItemFactoryEntry ifentry = {NULL, NULL, NULL, 0, "<Branch>"};
441
442         ifentry.path = branch_path;
443         menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
444         g_return_if_fail(menuitem != NULL);
445
446         amenu = GTK_MENU_SHELL(menuitem)->children;
447         while (amenu != NULL) {
448                 GList *alist = amenu->next;
449                 gtk_widget_destroy(GTK_WIDGET(amenu->data));
450                 amenu = alist;
451         }
452
453         ifentry.accelerator     = NULL;
454         ifentry.callback_action = 0;
455         ifentry.callback        = callback;
456         ifentry.item_type       = NULL;
457
458         for (cur = prefs_common.actions_list; cur; cur = cur->next) {
459                 action   = g_strdup((gchar *)cur->data);
460                 action_p = strstr(action, ": ");
461                 if (action_p && action_p[2] &&
462                     action_get_type(&action_p[2]) != ACTION_ERROR) {
463                         action_p[0] = 0x00;
464                         menu_path = g_strdup_printf("%s/%s", branch_path,
465                                                     action);
466                         ifentry.path = menu_path;
467                         gtk_item_factory_create_item(ifactory, &ifentry, data,
468                                                      1);
469                         g_free(menu_path);
470                 }
471                 g_free(action);
472                 ifentry.callback_action++;
473         }
474 }
475
476 static void compose_actions_execute_cb(Compose *compose, guint action_nb,
477                                        GtkWidget *widget)
478 {
479         gchar *buf, *action;
480         ActionType action_type;
481
482         g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
483
484         buf = (gchar *)g_slist_nth_data(prefs_common.actions_list, action_nb);
485         g_return_if_fail(buf != NULL);
486         action = strstr(buf, ": ");
487         g_return_if_fail(action != NULL);
488
489         /* Point to the beginning of the command-line */
490         action += 2;
491
492         action_type = action_get_type(action);
493         if (action_type & (ACTION_SINGLE | ACTION_MULTIPLE)) {
494                 alertpanel_warning
495                         (_("The selected action cannot be used in the compose window\n"
496                            "because it contains %%f, %%F, %%as or %%p."));
497                 return;
498         }
499
500         execute_actions(action, NULL, compose->text, NULL, 0, NULL);
501 }
502
503 static void mainwin_actions_execute_cb(MainWindow *mainwin, guint action_nb,
504                                        GtkWidget *widget)
505 {
506         GSList *msg_list;
507
508         msg_list = summary_get_selected_msg_list(mainwin->summaryview);
509         message_actions_execute(mainwin->messageview, action_nb, msg_list);
510         g_slist_free(msg_list);
511 }
512
513 static void msgview_actions_execute_cb(MessageView *msgview, guint action_nb,
514                                        GtkWidget *widget)
515 {
516         GSList *msg_list = NULL;
517
518         if (msgview->msginfo)
519                 msg_list = g_slist_append(msg_list, msgview->msginfo);
520         message_actions_execute(msgview, action_nb, msg_list);
521         g_slist_free(msg_list);
522 }
523
524 static void message_actions_execute(MessageView *msgview, guint action_nb,
525                                     GSList *msg_list)
526 {
527         TextView *textview;
528         MimeInfo *partinfo;
529         gchar *buf;
530         gchar *action;
531         GtkWidget *text = NULL;
532         GdkFont *msgfont = NULL;
533         guint body_pos = 0;
534         ActionType action_type;
535         
536         g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
537
538         buf = (gchar *)g_slist_nth_data(prefs_common.actions_list, action_nb);
539
540         g_return_if_fail(buf);
541         g_return_if_fail(action = strstr(buf, ": "));
542
543         /* Point to the beginning of the command-line */
544         action += 2;
545
546         textview = messageview_get_current_textview(msgview);
547         if (textview) {
548                 text     = textview->text;
549                 msgfont  = textview->msgfont;
550                 body_pos = textview->body_pos;
551         }
552         partinfo = messageview_get_selected_mime_part(msgview);
553
554         /* this command will alter the message text */
555         action_type = action_get_type(action);
556         if (action_type & (ACTION_PIPE_OUT | ACTION_INSERT))
557                 msgview->filtered = TRUE;
558
559         if (action_type & ACTION_FILTERING_ACTION) 
560                 /* CLAWS: most of the above code is not necessary for applying
561                  * filtering */
562                 execute_filtering_actions(action, msg_list);
563         else
564                 execute_actions(action, msg_list, text, msgfont, body_pos, partinfo);
565 }
566
567 static gboolean execute_filtering_actions(gchar *action, GSList *msglist)
568 {
569         GSList *action_list, *p;
570         const gchar *sbegin, *send;
571         gchar *action_string;
572         
573         if (NULL == (sbegin = strstr2(action, "%as{")))
574                 return FALSE;
575         sbegin += sizeof "%as{" - 1;
576         if (NULL == (send = strrchr(sbegin, '}')))
577                 return FALSE;
578         action_string = g_strndup(sbegin, send - sbegin);
579         
580         action_list = matcher_parser_get_action_list(action_string);
581         g_free(action_string);
582         if (action_list == NULL) return FALSE;
583         
584         /* apply actions on each message info */
585         for (p = msglist; p && p->data; p = g_slist_next(p))
586                 filteringaction_apply_action_list(action_list, (MsgInfo *) p->data);
587                 
588         for (p = action_list; p; p = g_slist_next(p))
589                 if (p->data) filteringaction_free(p->data);     
590         g_slist_free(action_list);              
591         return TRUE;    
592 }
593
594 static gboolean execute_actions(gchar *action, GSList *msg_list,
595                                 GtkWidget *text, GdkFont *msgfont,
596                                 gint body_pos, MimeInfo *partinfo)
597 {
598         GSList *children_list = NULL;
599         gint is_ok  = TRUE;
600         gint msg_list_len;
601         Children *children;
602         ChildInfo *child_info;
603         ActionType action_type;
604         MsgInfo *msginfo;
605         gchar *cmd;
606         guint start = 0, end = 0;
607         gchar *sel_str = NULL;
608         gchar *msg_str = NULL;
609         gchar *user_str = NULL;
610         gchar *user_hidden_str = NULL;
611
612         g_return_val_if_fail(action && *action, FALSE);
613
614         action_type = action_get_type(action);
615
616         if (action_type == ACTION_ERROR)
617                 return FALSE;         /* ERR: syntax error */
618
619         if (action_type & (ACTION_SINGLE | ACTION_MULTIPLE) && !msg_list)
620                 return FALSE;         /* ERR: file command without selection */
621
622         msg_list_len = g_slist_length(msg_list);
623
624         if (action_type & (ACTION_PIPE_OUT | ACTION_PIPE_IN | ACTION_INSERT)) {
625                 if (msg_list_len > 1)
626                         return FALSE; /* ERR: pipe + multiple selection */
627                 if (!text)
628                         return FALSE; /* ERR: pipe and no displayed text */
629         }
630
631         if (action_type & ACTION_SELECTION_STR) {
632                 if (!text)
633                         return FALSE; /* ERR: selection string but no text */
634         }
635
636         if (text) {
637                 if (GTK_EDITABLE(text)->has_selection) {
638                         start = GTK_EDITABLE(text)->selection_start_pos;
639                         end   = GTK_EDITABLE(text)->selection_end_pos;
640                         if (start > end) {
641                                 guint tmp;
642                                 tmp = start;
643                                 start = end;
644                                 end = tmp;
645                         }
646
647                         if (start == end) {
648                                 start = body_pos;
649                                 end = gtk_stext_get_length(GTK_STEXT(text));
650                                 msg_str = gtk_editable_get_chars
651                                         (GTK_EDITABLE(text), start, end);
652                         } else {
653                                 sel_str = gtk_editable_get_chars
654                                         (GTK_EDITABLE(text), start, end);
655                                 msg_str = g_strdup(sel_str);
656                         }
657                 } else {
658                         start = body_pos;
659                         end = gtk_stext_get_length(GTK_STEXT(text));
660                         msg_str = gtk_editable_get_chars(GTK_EDITABLE(text),
661                                                          start, end);
662                 }
663         }
664
665         if (action_type & ACTION_USER_STR) {
666                 if (!(user_str = get_user_string(action, ACTION_USER_STR))) {
667                         g_free(msg_str);
668                         g_free(sel_str);
669                         return FALSE;
670                 }
671         }
672
673         if (action_type & ACTION_USER_HIDDEN_STR) {
674                 if (!(user_hidden_str =
675                         get_user_string(action, ACTION_USER_HIDDEN_STR))) {
676                         g_free(msg_str);
677                         g_free(sel_str);
678                         g_free(user_str);
679                         return FALSE;
680                 }
681         }
682
683         if (action_type & ACTION_PIPE_OUT) {
684                 gtk_stext_freeze(GTK_STEXT(text));
685                 gtk_stext_set_point(GTK_STEXT(text), start);
686                 gtk_stext_forward_delete(GTK_STEXT(text), end - start);
687                 gtk_stext_thaw(GTK_STEXT(text));
688         }
689
690         children = g_new0(Children, 1);
691
692         children->action      = g_strdup(action);
693         children->action_type = action_type;
694         children->msg_text    = text;
695         children->msgfont     = msgfont;
696
697         if ((action_type & (ACTION_USER_IN | ACTION_USER_HIDDEN_IN)) &&
698             ((action_type & ACTION_SINGLE) == 0 || msg_list_len == 1))
699                 children->open_in = 1;
700
701         if (action_type & ACTION_SINGLE) {
702                 GSList *cur;
703
704                 for (cur = msg_list; cur && is_ok == TRUE; cur = cur->next) {
705                         msginfo = (MsgInfo *)cur->data;
706                         if (!msginfo) {
707                                 is_ok  = FALSE; /* ERR: msginfo missing */
708                                 break;
709                         }
710                         cmd = parse_action_cmd(action, msginfo, msg_list,
711                                                partinfo, user_str,
712                                                user_hidden_str, sel_str);
713                         if (!cmd) {
714                                 debug_print("Action command error\n");
715                                 is_ok  = FALSE; /* ERR: incorrect command */
716                                 break;
717                         }
718                         if ((child_info = fork_child(cmd, msg_str, children))) {
719                                 children_list = g_slist_append(children_list,
720                                                                child_info);
721                         }
722                         g_free(cmd);
723                 }
724         } else {
725                 cmd = parse_action_cmd(action, NULL, msg_list, partinfo,
726                                        user_str, user_hidden_str, sel_str);
727                 if (cmd) {
728                         if ((child_info = fork_child(cmd, msg_str, children))) {
729                                 children_list = g_slist_append(children_list,
730                                                                child_info);
731                         }
732                         g_free(cmd);
733                 } else
734                         is_ok  = FALSE;         /* ERR: incorrect command */
735         }
736
737         g_free(msg_str);
738         g_free(sel_str);
739         g_free(user_str);
740         g_free(user_hidden_str);
741
742         if (!children_list) {
743                  /* If not waiting for children, return */
744                 free_children(children);
745         } else {
746                 GSList *cur;
747
748                 children->list        = children_list;
749                 children->nb          = g_slist_length(children_list);
750                 children->initial_nb  = children->nb;
751
752                 for (cur = children_list; cur; cur = cur->next) {
753                         child_info = (ChildInfo *) cur->data;
754                         child_info->tag_status = 
755                                 gdk_input_add(child_info->chld_status,
756                                               GDK_INPUT_READ,
757                                               catch_status, child_info);
758                 }
759
760                 create_io_dialog(children);
761         }
762
763         return is_ok;
764 }
765
766 static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
767                              Children *children)
768 {
769         gint chld_in[2], chld_out[2], chld_err[2], chld_status[2];
770         gchar *cmdline[4];
771         pid_t pid, gch_pid;
772         ChildInfo *child_info;
773         gint sync;
774
775         sync = !(children->action_type & ACTION_ASYNC);
776
777         chld_in[0] = chld_in[1] = chld_out[0] = chld_out[1] = chld_err[0]
778                 = chld_err[1] = chld_status[0] = chld_status[1] = -1;
779
780         if (sync) {
781                 if (pipe(chld_status) || pipe(chld_in) || pipe(chld_out) ||
782                     pipe(chld_err)) {
783                         alertpanel_error(_("Command could not be started. "
784                                            "Pipe creation failed.\n%s"),
785                                         g_strerror(errno));
786                         /* Closing fd = -1 fails silently */
787                         close(chld_in[0]);
788                         close(chld_in[1]);
789                         close(chld_out[0]);
790                         close(chld_out[1]);
791                         close(chld_err[0]);
792                         close(chld_err[1]);
793                         close(chld_status[0]);
794                         close(chld_status[1]);
795                         return NULL; /* Pipe error */
796                 }
797         }
798
799         debug_print("Forking child and grandchild.\n");
800
801         pid = fork();
802         if (pid == 0) { /* Child */
803                 if (setpgid(0, 0))
804                         perror("setpgid");
805
806                 close(ConnectionNumber(gdk_display));
807
808                 gch_pid = fork();
809
810                 if (gch_pid == 0) {
811                         if (setpgid(0, getppid()))
812                                 perror("setpgid");
813
814                         if (sync) {
815                                 if (children->action_type &
816                                     (ACTION_PIPE_IN |
817                                      ACTION_USER_IN |
818                                      ACTION_USER_HIDDEN_IN)) {
819                                         close(fileno(stdin));
820                                         dup  (chld_in[0]);
821                                 }
822                                 close(chld_in[0]);
823                                 close(chld_in[1]);
824
825                                 close(fileno(stdout));
826                                 dup  (chld_out[1]);
827                                 close(chld_out[0]);
828                                 close(chld_out[1]);
829
830                                 close(fileno(stderr));
831                                 dup  (chld_err[1]);
832                                 close(chld_err[0]);
833                                 close(chld_err[1]);
834                         }
835
836                         cmdline[0] = "sh";
837                         cmdline[1] = "-c";
838                         cmdline[2] = cmd;
839                         cmdline[3] = 0;
840                         execvp("/bin/sh", cmdline);
841
842                         perror("execvp");
843                         _exit(1);
844                 } else if (gch_pid < (pid_t) 0) { /* Fork error */
845                         if (sync)
846                                 write(chld_status[1], "1\n", 2);
847                         perror("fork");
848                         _exit(1);
849                 } else { /* Child */
850                         if (sync) {
851                                 close(chld_in[0]);
852                                 close(chld_in[1]);
853                                 close(chld_out[0]);
854                                 close(chld_out[1]);
855                                 close(chld_err[0]);
856                                 close(chld_err[1]);
857                                 close(chld_status[0]);
858
859                                 debug_print("Child: Waiting for grandchild\n");
860                                 waitpid(gch_pid, NULL, 0);
861                                 debug_print("Child: grandchild ended\n");
862                                 write(chld_status[1], "0\n", 2);
863                                 close(chld_status[1]);
864                         }
865                         _exit(0);
866                 }
867         } else if (pid < 0) { /* Fork error */
868                 alertpanel_error(_("Could not fork to execute the following "
869                                    "command:\n%s\n%s"),
870                                  cmd, g_strerror(errno));
871                 return NULL; 
872         }
873
874         /* Parent */
875
876         if (!sync) {
877                 waitpid(pid, NULL, 0);
878                 return NULL;
879         }
880
881         close(chld_in[0]);
882         if (!(children->action_type &
883               (ACTION_PIPE_IN | ACTION_USER_IN | ACTION_USER_HIDDEN_IN)))
884                 close(chld_in[1]);
885         close(chld_out[1]);
886         close(chld_err[1]);
887         close(chld_status[1]);
888
889         child_info = g_new0(ChildInfo, 1);
890
891         child_info->children    = children;
892
893         child_info->pid         = pid;
894         child_info->cmd         = g_strdup(cmd);
895         child_info->new_out     = FALSE;
896         child_info->output      = g_string_new(NULL);
897         child_info->chld_in     =
898                 (children->action_type &
899                  (ACTION_PIPE_IN | ACTION_USER_IN | ACTION_USER_HIDDEN_IN))
900                         ? chld_in [1] : -1;
901         child_info->chld_out    = chld_out[0];
902         child_info->chld_err    = chld_err[0];
903         child_info->chld_status = chld_status[0];
904         child_info->tag_in      = -1;
905         child_info->tag_out     = gdk_input_add(chld_out[0], GDK_INPUT_READ,
906                                                 catch_output, child_info);
907         child_info->tag_err     = gdk_input_add(chld_err[0], GDK_INPUT_READ,
908                                                 catch_output, child_info);
909
910         if (!(children->action_type &
911               (ACTION_PIPE_IN | ACTION_PIPE_OUT | ACTION_INSERT)))
912                 return child_info;
913
914         if ((children->action_type & ACTION_PIPE_IN) && msg_str) {
915                 write(chld_in[1], msg_str, strlen(msg_str));
916                 if (!(children->action_type &
917                       (ACTION_USER_IN | ACTION_USER_HIDDEN_IN)))
918                         close(chld_in[1]);
919                 child_info->chld_in = -1; /* No more input */
920         }
921
922         return child_info;
923 }
924
925 static void kill_children_cb(GtkWidget *widget, gpointer data)
926 {
927         GSList *cur;
928         Children *children = (Children *) data;
929         ChildInfo *child_info;
930
931         for (cur = children->list; cur; cur = cur->next) {
932                 child_info = (ChildInfo *)(cur->data);
933                 debug_print("Killing child group id %d\n", child_info->pid);
934                 if (child_info->pid && kill(-child_info->pid, SIGTERM) < 0)
935                         perror("kill");
936         }
937 }
938
939 static gint wait_for_children(Children *children)
940 {
941         gboolean new_output;
942         ChildInfo *child_info;
943         GSList *cur;
944         gint nb = children->nb;
945
946         children->nb = 0;
947
948         cur = children->list;
949         new_output = FALSE;
950         while (cur) {
951                 child_info = (ChildInfo *)cur->data;
952                 if (child_info->pid)
953                         children->nb++;
954                 new_output |= child_info->new_out;
955                 cur = cur->next;
956         }
957
958         children->output |= new_output;
959
960         if (new_output || (children->dialog && (nb != children->nb)))
961                 update_io_dialog(children);
962
963         if (children->nb)
964                 return FALSE;
965
966         if (!children->dialog) {
967                 free_children(children);
968         } else if (!children->output) {
969                 gtk_widget_destroy(children->dialog);
970         }
971
972         return FALSE;
973 }
974
975 static void send_input(GtkWidget *w, gpointer data)
976 {
977         Children *children = (Children *) data;
978         ChildInfo *child_info = (ChildInfo *) children->list->data;
979
980         child_info->tag_in = gdk_input_add(child_info->chld_in,
981                                            GDK_INPUT_WRITE,
982                                            catch_input, children);
983         gtk_widget_set_sensitive(children->input_hbox, FALSE);
984 }
985
986 static gint delete_io_dialog_cb(GtkWidget *w, GdkEvent *e, gpointer data)
987 {
988         hide_io_dialog_cb(w, data);
989         return TRUE;
990 }
991
992 static void hide_io_dialog_cb(GtkWidget *w, gpointer data)
993 {
994
995         Children *children = (Children *)data;
996
997         if (!children->nb) {
998                 gtk_signal_disconnect_by_data(GTK_OBJECT(children->dialog),
999                                               children);
1000                 gtk_widget_destroy(children->dialog);
1001                 free_children(children);
1002         }
1003 }
1004
1005 static gint io_dialog_key_pressed_cb(GtkWidget *widget, GdkEventKey *event,
1006                                      gpointer data)
1007 {
1008         if (event && event->keyval == GDK_Escape)
1009                 hide_io_dialog_cb(widget, data);
1010         return TRUE;
1011 }
1012
1013 static void childinfo_close_pipes(ChildInfo *child_info)
1014 {
1015         /* stdout and stderr pipes are guaranteed to be removed by
1016          * their handler, but in case where we receive child exit notification
1017          * before grand-child's pipes closing signals, we check them and close
1018          * them if necessary
1019          */
1020         if (child_info->tag_in > 0)
1021                 gdk_input_remove(child_info->tag_in);
1022         if (child_info->tag_out > 0)
1023                 gdk_input_remove(child_info->tag_out);
1024         if (child_info->tag_err > 0)
1025                 gdk_input_remove(child_info->tag_err);
1026
1027         if (child_info->chld_in >= 0)
1028                 close(child_info->chld_in);
1029         if (child_info->chld_out >= 0)
1030                 close(child_info->chld_out);
1031         if (child_info->chld_err >= 0)
1032                 close(child_info->chld_err);
1033
1034         close(child_info->chld_status);
1035 }
1036
1037 static void free_children(Children *children)
1038 {
1039         ChildInfo *child_info;
1040
1041         debug_print("Freeing children data %p\n", children);
1042
1043         g_free(children->action);
1044         while (children->list != NULL) {
1045                 child_info = (ChildInfo *)children->list->data;
1046                 g_free(child_info->cmd);
1047                 g_string_free(child_info->output, TRUE);
1048                 children->list = g_slist_remove(children->list, child_info);
1049                 g_free(child_info);
1050         }
1051         g_free(children);
1052 }
1053
1054 static void update_io_dialog(Children *children)
1055 {
1056         GSList *cur;
1057
1058         debug_print("Updating actions input/output dialog.\n");
1059
1060         if (children->progress_bar) {
1061                 gtk_progress_configure(GTK_PROGRESS(children->progress_bar),
1062                                 children->initial_nb -children->nb,
1063                                 0.0, children->initial_nb);
1064         }
1065
1066         if (!children->nb) {
1067                 gtk_widget_set_sensitive(children->abort_btn, FALSE);
1068                 gtk_widget_set_sensitive(children->close_btn, TRUE);
1069                 if (children->input_hbox)
1070                         gtk_widget_set_sensitive(children->input_hbox, FALSE);
1071                 gtk_widget_grab_focus(children->close_btn);
1072                 gtk_signal_connect(GTK_OBJECT(children->dialog),
1073                                    "key_press_event",
1074                                    GTK_SIGNAL_FUNC(io_dialog_key_pressed_cb),
1075                                    children);
1076         }
1077
1078         if (children->output) {
1079                 GtkWidget *text = children->text;
1080                 gchar *caption;
1081                 ChildInfo *child_info;
1082                 GdkFont *font;
1083
1084                 font = gtk_object_get_data(GTK_OBJECT(children->dialog), 
1085                                            "s_txtfont");
1086                 gtk_widget_show(children->scrolledwin);
1087                 gtk_text_freeze(GTK_TEXT(text));
1088                 gtk_text_set_point(GTK_TEXT(text), 0);
1089                 gtk_text_forward_delete(GTK_TEXT(text), 
1090                                         gtk_text_get_length(GTK_TEXT(text)));
1091                 for (cur = children->list; cur; cur = cur->next) {
1092                         child_info = (ChildInfo *)cur->data;
1093                         if (child_info->pid)
1094                                 caption = g_strdup_printf
1095                                         (_("--- Running: %s\n"),
1096                                          child_info->cmd);
1097                         else
1098                                 caption = g_strdup_printf
1099                                         (_("--- Ended: %s\n"),
1100                                          child_info->cmd);
1101
1102                         gtk_text_insert(GTK_TEXT(text), font, NULL, NULL,
1103                                         caption, -1);
1104                         gtk_text_insert(GTK_TEXT(text), font, NULL, NULL,
1105                                         child_info->output->str, -1);
1106                         g_free(caption);
1107                         child_info->new_out = FALSE;
1108                 }
1109                 gtk_text_thaw(GTK_TEXT(text));
1110         }
1111 }
1112
1113 static void create_io_dialog(Children *children)
1114 {
1115         GtkWidget *dialog;
1116         GtkWidget *vbox;
1117         GtkWidget *entry = NULL;
1118         GtkWidget *input_hbox = NULL;
1119         GtkWidget *send_button;
1120         GtkWidget *label;
1121         GtkWidget *text;
1122         GtkWidget *scrolledwin;
1123         GtkWidget *hbox;
1124         GtkWidget *progress_bar = NULL;
1125         GtkWidget *abort_button;
1126         GtkWidget *close_button;
1127         GdkFont   *output_font;
1128
1129         debug_print("Creating action IO dialog\n");
1130
1131         dialog = gtk_dialog_new();
1132         gtk_container_set_border_width
1133                 (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 5);
1134         gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
1135         gtk_window_set_title(GTK_WINDOW(dialog), _("Action's input/output"));
1136         gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
1137         manage_window_set_transient(GTK_WINDOW(dialog));
1138         gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
1139                         GTK_SIGNAL_FUNC(delete_io_dialog_cb), children);
1140         gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
1141                         GTK_SIGNAL_FUNC(hide_io_dialog_cb),
1142                         children);
1143
1144         vbox = gtk_vbox_new(FALSE, 8);
1145         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox);
1146         gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
1147         gtk_widget_show(vbox);
1148
1149         label = gtk_label_new(children->action);
1150         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
1151         gtk_widget_show(label);
1152
1153         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
1154         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
1155                                        GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
1156         gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
1157         gtk_widget_set_usize(scrolledwin, 480, 200);
1158         gtk_widget_hide(scrolledwin);
1159
1160         text = gtk_text_new(gtk_scrolled_window_get_hadjustment
1161                             (GTK_SCROLLED_WINDOW(scrolledwin)),
1162                             gtk_scrolled_window_get_vadjustment
1163                             (GTK_SCROLLED_WINDOW(scrolledwin)));
1164         gtk_text_set_editable(GTK_TEXT(text), FALSE);
1165         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
1166         gtk_widget_show(text);
1167
1168         if (children->open_in) {
1169                 input_hbox = gtk_hbox_new(FALSE, 8);
1170                 gtk_widget_show(input_hbox);
1171
1172                 entry = gtk_entry_new();
1173                 gtk_widget_set_usize(entry, 320, -1);
1174                 gtk_signal_connect(GTK_OBJECT(entry), "activate",
1175                                    GTK_SIGNAL_FUNC(send_input), children);
1176                 gtk_box_pack_start(GTK_BOX(input_hbox), entry, TRUE, TRUE, 0);
1177                 if (children->action_type & ACTION_USER_HIDDEN_IN)
1178                         gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
1179                 gtk_widget_show(entry);
1180
1181                 send_button = gtk_button_new_with_label(_(" Send "));
1182                 gtk_signal_connect(GTK_OBJECT(send_button), "clicked",
1183                                    GTK_SIGNAL_FUNC(send_input), children);
1184                 gtk_box_pack_start(GTK_BOX(input_hbox), send_button, FALSE,
1185                                    FALSE, 0);
1186                 gtk_widget_show(send_button);
1187
1188                 gtk_box_pack_start(GTK_BOX(vbox), input_hbox, FALSE, FALSE, 0);
1189                 gtk_widget_grab_focus(entry);
1190         }
1191
1192         if (children->initial_nb > 1) {
1193                 progress_bar = gtk_progress_bar_new();
1194                 gtk_progress_bar_set_bar_style(GTK_PROGRESS_BAR(progress_bar),
1195                                 GTK_PROGRESS_CONTINUOUS);
1196                 gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(progress_bar),
1197                                 GTK_PROGRESS_LEFT_TO_RIGHT);
1198                 gtk_progress_set_activity_mode(GTK_PROGRESS(progress_bar), 
1199                                 FALSE);
1200                 gtk_progress_set_format_string(GTK_PROGRESS(progress_bar),
1201                                 _("Completed %v/%u"));
1202                 gtk_progress_set_show_text(GTK_PROGRESS(progress_bar), TRUE);
1203                 gtk_progress_configure(GTK_PROGRESS(progress_bar),
1204                                 children->initial_nb -children->nb,
1205                                 0.0, children->initial_nb);
1206
1207                 gtk_box_pack_start(GTK_BOX(vbox), progress_bar, FALSE, FALSE, 0);
1208                 gtk_widget_show(progress_bar);
1209         }
1210
1211         gtkut_button_set_create(&hbox, &abort_button, _("Abort"),
1212                                 &close_button, _("Close"), NULL, NULL);
1213         gtk_signal_connect(GTK_OBJECT(abort_button), "clicked",
1214                         GTK_SIGNAL_FUNC(kill_children_cb), children);
1215         gtk_signal_connect(GTK_OBJECT(close_button), "clicked",
1216                         GTK_SIGNAL_FUNC(hide_io_dialog_cb), children);
1217         gtk_widget_show(hbox);
1218
1219         if (children->nb)
1220                 gtk_widget_set_sensitive(close_button, FALSE);
1221
1222         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), hbox);
1223
1224         children->dialog       = dialog;
1225         children->scrolledwin  = scrolledwin;
1226         children->text         = text;
1227         children->input_hbox   = children->open_in ? input_hbox : NULL;
1228         children->input_entry  = children->open_in ? entry : NULL;
1229         children->progress_bar = progress_bar;
1230         children->abort_btn    = abort_button;
1231         children->close_btn    = close_button;
1232
1233         output_font = gtkut_font_load_from_fontset(prefs_common.textfont);
1234         gtk_object_set_data_full(GTK_OBJECT(dialog), "s_txtfont",
1235                                  output_font, 
1236                                  (GtkDestroyNotify)gdk_font_unref); 
1237         gtk_widget_show(dialog);
1238 }
1239
1240 static void catch_status(gpointer data, gint source, GdkInputCondition cond)
1241 {
1242         ChildInfo *child_info = (ChildInfo *)data;
1243         gchar buf;
1244         gint c;
1245
1246         gdk_input_remove(child_info->tag_status);
1247
1248         c = read(source, &buf, 1);
1249         debug_print("Child returned %c\n", buf);
1250
1251         waitpid(-child_info->pid, NULL, 0);
1252         childinfo_close_pipes(child_info);
1253         child_info->pid = 0;
1254
1255         wait_for_children(child_info->children);
1256 }
1257         
1258 static void catch_input(gpointer data, gint source, GdkInputCondition cond)
1259 {
1260         Children *children = (Children *)data;
1261         ChildInfo *child_info = (ChildInfo *)children->list->data;
1262         gchar *input;
1263         gint c, count, len;
1264
1265         debug_print("Sending input to grand child.\n");
1266         if (!(cond && GDK_INPUT_WRITE))
1267                 return;
1268
1269         gdk_input_remove(child_info->tag_in);
1270         child_info->tag_in = -1;
1271
1272         input = gtk_editable_get_chars(GTK_EDITABLE(children->input_entry),
1273                                        0, -1);
1274         len = strlen(input);
1275         count = 0;
1276
1277         do {
1278                 c = write(child_info->chld_in, input + count, len - count);
1279                 if (c >= 0)
1280                         count += c;
1281         } while (c >= 0 && count < len);
1282
1283         if (c >= 0)
1284                 write(child_info->chld_in, "\n", 2);
1285
1286         g_free(input);
1287
1288         gtk_entry_set_text(GTK_ENTRY(children->input_entry), "");
1289         gtk_widget_set_sensitive(children->input_hbox, TRUE);
1290         close(child_info->chld_in);
1291         child_info->chld_in = -1;
1292         debug_print("Input to grand child sent.\n");
1293 }
1294
1295 static void catch_output(gpointer data, gint source, GdkInputCondition cond)
1296 {
1297         ChildInfo *child_info = (ChildInfo *)data;
1298         gint c, i;
1299         gchar buf[BUFFSIZE];
1300
1301         debug_print("Catching grand child's output.\n");
1302         if (child_info->children->action_type &
1303             (ACTION_PIPE_OUT | ACTION_INSERT)
1304             && source == child_info->chld_out) {
1305                 gboolean is_selection = FALSE;
1306                 GtkWidget *text = child_info->children->msg_text;
1307
1308                 if (GTK_EDITABLE(text)->has_selection)
1309                         is_selection = TRUE;
1310                 gtk_stext_freeze(GTK_STEXT(text));
1311                 while (TRUE) {
1312                         c = read(source, buf, sizeof(buf) - 1);
1313                         if (c == 0)
1314                                 break;
1315                         gtk_stext_insert(GTK_STEXT(text),
1316                                          child_info->children->msgfont,
1317                                          NULL, NULL, buf, c);
1318                 }
1319                 if (is_selection) {
1320                         /* Using the select_region draws things. Should not.
1321                          * so we just change selection position and 
1322                          * defere drawing when thawing. Hack?
1323                          */
1324                         GTK_EDITABLE(text)->selection_end_pos =
1325                                         gtk_stext_get_point(GTK_STEXT(text));
1326                 }
1327                 gtk_stext_thaw(GTK_STEXT(text));
1328         } else {
1329                 c = read(source, buf, sizeof(buf) - 1);
1330                 for (i = 0; i < c; i++)
1331                         g_string_append_c(child_info->output, buf[i]);
1332                 if (c > 0)
1333                         child_info->new_out = TRUE;
1334         }
1335         if (c == 0) {
1336                 if (source == child_info->chld_out) {
1337                         gdk_input_remove(child_info->tag_out);
1338                         child_info->tag_out = -1;
1339                         close(child_info->chld_out);
1340                         child_info->chld_out = -1;
1341                 } else {
1342                         gdk_input_remove(child_info->tag_err);
1343                         child_info->tag_err = -1;
1344                         close(child_info->chld_err);
1345                         child_info->chld_err = -1;
1346                 }
1347         }
1348         
1349         wait_for_children(child_info->children);
1350 }
1351
1352 static gchar *get_user_string(const gchar *action, ActionType type)
1353 {
1354         gchar *message;
1355         gchar *user_str = NULL;
1356
1357         switch (type) {
1358         case ACTION_USER_HIDDEN_STR:
1359                 message = g_strdup_printf
1360                         (_("Enter the argument for the following action:\n"
1361                            "(`%%h' will be replaced with the argument)\n"
1362                            "  %s"),
1363                          action);
1364                 user_str = input_dialog_with_invisible
1365                         (_("Action's hidden user argument"), message, NULL);
1366                 break;
1367         case ACTION_USER_STR:
1368                 message = g_strdup_printf
1369                         (_("Enter the argument for the following action:\n"
1370                            "(`%%u' will be replaced with the argument)\n"
1371                            "  %s"),
1372                          action);
1373                 user_str = input_dialog
1374                         (_("Action's user argument"), message, NULL);
1375                 break;
1376         default:
1377                 g_warning("Unsupported action type %d", type);
1378         }
1379
1380         return user_str;
1381 }