2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 the Claws Mail Team and Hiroyuki Yamamoto
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "claws-features.h"
27 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
30 #ifdef GDK_WINDOWING_X11
31 # include <gdk/gdkx.h>
32 #endif /* GDK_WINDOWING_X11 */
33 #ifdef GDK_WINDOWING_QUARTZ
34 # include <gdk/gdkquartz.h>
35 #endif /* GDK_WINDOWING_QUARTZ */
40 #include <sys/types.h>
42 # include <sys/wait.h>
49 #include "manage_window.h"
50 #include "mainwindow.h"
51 #include "prefs_common.h"
52 #include "alertpanel.h"
53 #include "inputdialog.h"
59 #include "matcher_parser.h" /* CLAWS */
60 #include "filtering.h"
61 #include "procheader.h"
67 typedef struct _Children Children
;
68 typedef struct _ChildInfo ChildInfo
;
69 typedef struct _UserStringDialog UserStringDialog
;
75 GtkWidget
*input_entry
;
76 GtkWidget
*input_hbox
;
77 GtkWidget
*progress_bar
;
80 GtkWidget
*scrolledwin
;
83 ActionType action_type
;
92 gboolean is_selection
;
111 void (*callback
)(void *data
);
114 GSList
*msginfo_list
;
117 static void action_update_menu (GtkUIManager
*ui_manager
,
118 const gchar
*accel_group
,
122 static void compose_actions_execute_cb (GtkWidget
*widget
,
124 static void compose_actions_execute (Compose
*compose
,
128 static void mainwin_actions_execute_cb (GtkWidget
*widget
,
130 static void mainwin_actions_execute (MainWindow
*mainwin
,
134 static void msgview_actions_execute_cb (GtkWidget
*widget
,
136 static void msgview_actions_execute (MessageView
*msgview
,
140 static void message_actions_execute (MessageView
*msgview
,
144 static gboolean
execute_filtering_actions(gchar
*action
,
147 static gboolean
execute_actions (gchar
*action
,
152 void (*callback
)(void *data
),
155 static gchar
*parse_action_cmd (gchar
*action
,
159 const gchar
*user_str
,
160 const gchar
*user_hidden_str
,
161 const gchar
*sel_str
);
162 static gboolean
parse_append_filename (GString
*cmd
,
165 static gboolean
parse_append_msgpart (GString
*cmd
,
169 static ChildInfo
*fork_child (gchar
*cmd
,
170 const gchar
*msg_str
,
173 static gint
wait_for_children (Children
*children
);
175 static void free_children (Children
*children
);
177 static void childinfo_close_pipes (ChildInfo
*child_info
);
179 static void create_io_dialog (Children
*children
);
180 static void update_io_dialog (Children
*children
);
182 static void hide_io_dialog_cb (GtkWidget
*widget
,
184 static gint
io_dialog_key_pressed_cb (GtkWidget
*widget
,
188 static void catch_output (gpointer data
,
191 static void catch_input (gpointer data
,
194 static void catch_status (GPid pid
, gint status
, gpointer data
);
196 static gchar
*get_user_string (const gchar
*action
,
200 ActionType
action_get_type(const gchar
*action_str
)
203 gboolean in_filtering_action
= FALSE
;
204 ActionType action_type
= ACTION_NONE
;
206 cm_return_val_if_fail(action_str
, ACTION_ERROR
);
207 cm_return_val_if_fail(*action_str
, ACTION_ERROR
);
212 action_type
|= ACTION_PIPE_IN
;
214 } else if (p
[0] == '>') {
215 action_type
|= ACTION_USER_IN
;
217 } else if (p
[0] == '*') {
218 action_type
|= ACTION_USER_HIDDEN_IN
;
225 while (*p
&& action_type
!= ACTION_ERROR
) {
226 if (!in_filtering_action
) {
227 if (p
[0] == '%' && p
[1]) {
230 /* CLAWS: filtering action is a mutually exclusive
231 * action. we can enable others if needed later. we
232 * add ACTION_SINGLE | ACTION_MULTIPLE so it will
233 * only be executed from the main window toolbar */
234 if (p
[2] == 's') /* source messages */
235 action_type
= ACTION_FILTERING_ACTION
238 in_filtering_action
= TRUE
;
241 action_type
|= ACTION_SINGLE
;
244 action_type
|= ACTION_MULTIPLE
;
247 action_type
|= ACTION_SINGLE
;
250 action_type
|= ACTION_SELECTION_STR
;
253 action_type
|= ACTION_USER_STR
;
256 action_type
|= ACTION_USER_HIDDEN_STR
;
262 action_type
= ACTION_ERROR
;
266 } else if (p
[0] == '|') {
268 action_type
|= ACTION_PIPE_OUT
;
269 } else if (p
[0] == '>') {
271 action_type
|= ACTION_INSERT
;
272 } else if (p
[0] == '&') {
274 action_type
|= ACTION_ASYNC
;
275 } else if (p
[0] == '}') {
276 in_filtering_action
= FALSE
;
285 static gchar
*parse_action_cmd(gchar
*action
, MsgInfo
*msginfo
,
286 GSList
*msg_list
, MimeInfo
*partinfo
,
287 const gchar
*user_str
,
288 const gchar
*user_hidden_str
,
289 const gchar
*sel_str
)
297 if (p
[0] == '|' || p
[0] == '>' || p
[0] == '*')
300 cmd
= g_string_sized_new(strlen(action
));
303 !((p
[0] == '|' || p
[0] == '>' || p
[0] == '&') && !p
[1])) {
304 if (p
[0] == '%' && p
[1]) {
307 if (!parse_append_filename(cmd
, msginfo
)) {
308 g_string_free(cmd
, TRUE
);
314 for (cur
= msg_list
; cur
!= NULL
;
316 MsgInfo
*msg
= (MsgInfo
*)cur
->data
;
318 if (!parse_append_filename(cmd
, msg
)) {
319 g_string_free(cmd
, TRUE
);
323 g_string_append_c(cmd
, ' ');
328 if (!parse_append_msgpart(cmd
, msginfo
,
330 g_string_free(cmd
, TRUE
);
337 g_string_append(cmd
, sel_str
);
342 g_string_append(cmd
, user_str
);
347 g_string_append(cmd
, user_hidden_str
);
351 g_string_append_c(cmd
, p
[1]);
355 g_string_append_c(cmd
, p
[0]);
356 g_string_append_c(cmd
, p
[1]);
360 g_string_append_c(cmd
, p
[0]);
365 g_string_free(cmd
, TRUE
);
369 return g_string_free(cmd
, FALSE
);
372 static gboolean
parse_append_filename(GString
*cmd
, MsgInfo
*msginfo
)
376 cm_return_val_if_fail(msginfo
, FALSE
);
378 filename
= procmsg_get_message_file(msginfo
);
381 alertpanel_error(_("Could not get message file %d"),
386 g_string_append(cmd
, "\"");
388 gchar
*p
= filename
, *q
;
389 gchar escape_ch
[] = "\\ ";
390 while ((q
= strpbrk(p
, "$\"`\\~")) != NULL
) {
393 g_string_append(cmd
, p
);
394 g_string_append(cmd
, escape_ch
);
398 g_string_append(cmd
, p
);
400 g_string_append(cmd
, filename
);
402 g_string_append(cmd
, "\"");
408 static gboolean
parse_append_msgpart(GString
*cmd
, MsgInfo
*msginfo
,
411 gboolean single_part
= FALSE
;
413 gchar
*part_filename
;
417 partinfo
= procmime_scan_message(msginfo
);
419 alertpanel_error(_("Could not get message part."));
426 filename
= procmsg_get_message_file_path(msginfo
);
427 part_filename
= procmime_get_tmp_file_name(partinfo
);
429 ret
= procmime_get_part(part_filename
, partinfo
);
432 procmime_mimeinfo_free_all(&partinfo
);
436 alertpanel_error(_("Can't get part of multipart message: %s"), g_strerror(-ret
));
437 g_free(part_filename
);
441 g_string_append(cmd
, part_filename
);
443 g_free(part_filename
);
448 void actions_execute(gpointer data
,
453 if (source
== TOOLBAR_MAIN
)
454 mainwin_actions_execute((MainWindow
*)data
, action_nb
, widget
);
455 else if (source
== TOOLBAR_COMPOSE
)
456 compose_actions_execute((Compose
*)data
, action_nb
, widget
);
457 else if (source
== TOOLBAR_MSGVIEW
)
458 msgview_actions_execute((MessageView
*)data
, action_nb
, widget
);
461 void action_update_mainwin_menu(GtkUIManager
*ui_manager
,
465 action_update_menu(ui_manager
, "<MainwinActions>", branch_path
,
466 mainwin_actions_execute_cb
, mainwin
);
469 void action_update_msgview_menu(GtkUIManager
*ui_manager
,
471 MessageView
*msgview
)
473 action_update_menu(ui_manager
, "<MsgviewActions>", branch_path
,
474 msgview_actions_execute_cb
, msgview
);
477 void action_update_compose_menu(GtkUIManager
*ui_manager
,
481 action_update_menu(ui_manager
, "<ComposeActions>", branch_path
,
482 compose_actions_execute_cb
, compose
);
485 static GtkWidget
*find_item_in_menu(GtkWidget
*menu
, gchar
*name
)
487 GList
*children
= gtk_container_get_children(GTK_CONTAINER(GTK_MENU_SHELL(menu
)));
488 GList
*amenu
= children
;
489 const gchar
*existing_name
;
491 GtkWidget
*item
= GTK_WIDGET(amenu
->data
);
492 if ((existing_name
= g_object_get_data(G_OBJECT(item
), "s_name")) != NULL
&&
493 !g_strcmp0(name
, existing_name
))
495 g_list_free(children
);
501 g_list_free(children
);
506 static GtkWidget
*create_submenus(GtkWidget
*menu
, const gchar
*action
)
508 gchar
*submenu
= g_strdup(action
);
509 GtkWidget
*new_menu
= NULL
;
511 if (strchr(submenu
, '/')) {
512 const gchar
*end
= (strchr(submenu
, '/')+1);
513 GtkWidget
*menu_item
= NULL
;
515 *strchr(submenu
, '/') = '\0';
516 if ((menu_item
= find_item_in_menu(menu
, submenu
)) == NULL
) {
517 menu_item
= gtk_menu_item_new_with_mnemonic(submenu
);
518 g_object_set_data_full(G_OBJECT(menu_item
), "s_name", g_strdup(submenu
), g_free
);
519 gtk_widget_show(menu_item
);
520 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menu_item
);
521 new_menu
= gtk_menu_new();
522 gtk_widget_show(new_menu
);
523 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item
), new_menu
);
525 new_menu
= gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_item
));
527 new_menu
= create_submenus(new_menu
, end
);
531 return new_menu
? new_menu
: menu
;
534 static void action_update_menu(GtkUIManager
*ui_manager
,
535 const gchar
*accel_group
,
537 gpointer callback
, gpointer data
)
540 gchar
*action
, *action_p
;
541 int callback_action
= 0;
542 GtkWidget
*menu
= gtk_menu_new();
545 for (cur
= prefs_common
.actions_list
; cur
!= NULL
; cur
= cur
->next
) {
546 GtkWidget
*cur_menu
= menu
;
547 const gchar
*action_name
= NULL
;
548 action
= g_strdup((gchar
*)cur
->data
);
549 action_p
= strstr(action
, ": ");
550 if (action_p
&& action_p
[2] &&
551 (action_get_type(&action_p
[2]) != ACTION_ERROR
) &&
552 (action
[0] != '/')) {
553 gchar
*accel_path
= NULL
;
556 if (strchr(action
, '/')) {
557 cur_menu
= create_submenus(cur_menu
, action
);
558 action_name
= strrchr(action
, '/')+1;
560 action_name
= action
;
562 gtk_menu_set_accel_group (GTK_MENU (cur_menu
),
563 gtk_ui_manager_get_accel_group(ui_manager
));
564 item
= gtk_menu_item_new_with_label(action_name
);
565 gtk_menu_shell_append(GTK_MENU_SHELL(cur_menu
), item
);
566 g_signal_connect(G_OBJECT(item
), "activate",
567 G_CALLBACK(callback
), data
);
568 g_object_set_data(G_OBJECT(item
), "action_num", GINT_TO_POINTER(callback_action
));
569 gtk_widget_show(item
);
570 accel_path
= g_strconcat(accel_group
,branch_path
, "/", action
, NULL
);
571 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item
), accel_path
);
579 gtk_widget_show(menu
);
580 gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtk_ui_manager_get_widget(ui_manager
, branch_path
)), menu
);
583 static void compose_actions_execute_cb(GtkWidget
*widget
, gpointer data
)
585 Compose
*compose
= (Compose
*)data
;
586 gint action_nb
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget
), "action_num"));
587 compose_actions_execute(compose
, action_nb
, NULL
);
590 static void compose_actions_execute(Compose
*compose
, guint action_nb
, GtkWidget
*widget
)
593 ActionType action_type
;
595 cm_return_if_fail(action_nb
< g_slist_length(prefs_common
.actions_list
));
597 buf
= (gchar
*)g_slist_nth_data(prefs_common
.actions_list
, action_nb
);
598 cm_return_if_fail(buf
!= NULL
);
599 action
= strstr(buf
, ": ");
600 cm_return_if_fail(action
!= NULL
);
602 /* Point to the beginning of the command-line */
605 action_type
= action_get_type(action
);
606 if (action_type
& (ACTION_SINGLE
| ACTION_MULTIPLE
)) {
608 (_("The selected action cannot be used in the compose window\n"
609 "because it contains %%f, %%F, %%as or %%p."));
613 execute_actions(action
, NULL
, compose
->text
, 0, NULL
,
614 compose_action_cb
, compose
);
617 static void mainwin_actions_execute_cb(GtkWidget
*widget
, gpointer data
)
619 MainWindow
*mainwin
= (MainWindow
*)data
;
620 gint action_nb
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget
), "action_num"));
621 mainwin_actions_execute(mainwin
, action_nb
, NULL
);
624 static void _free_msginfos(gpointer data
, gpointer user_data
)
626 MsgInfo
*msginfo
= (MsgInfo
*)data
;
628 procmsg_msginfo_free(&msginfo
);
631 static void mainwin_actions_execute(MainWindow
*mainwin
, guint action_nb
,
636 msg_list
= summary_get_selected_msg_list(mainwin
->summaryview
);
637 message_actions_execute(mainwin
->messageview
, action_nb
, msg_list
);
638 summary_select_by_msg_list(mainwin
->summaryview
, msg_list
);
639 g_slist_foreach(msg_list
, _free_msginfos
, NULL
);
640 g_slist_free(msg_list
);
643 static void msgview_actions_execute_cb(GtkWidget
*widget
, gpointer data
)
645 MessageView
*msgview
= (MessageView
*)data
;
646 gint action_nb
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget
), "action_num"));
647 msgview_actions_execute(msgview
, action_nb
, NULL
);
650 static void msgview_actions_execute(MessageView
*msgview
, guint action_nb
,
653 GSList
*msg_list
= NULL
;
655 if (msgview
->msginfo
)
656 msg_list
= g_slist_append(msg_list
, msgview
->msginfo
);
657 message_actions_execute(msgview
, action_nb
, msg_list
);
658 g_slist_free(msg_list
);
661 static void message_actions_execute(MessageView
*msgview
, guint action_nb
,
668 GtkWidget
*text
= NULL
;
670 ActionType action_type
;
672 cm_return_if_fail(action_nb
< g_slist_length(prefs_common
.actions_list
));
674 buf
= (gchar
*)g_slist_nth_data(prefs_common
.actions_list
, action_nb
);
676 cm_return_if_fail(buf
);
677 cm_return_if_fail((action
= strstr(buf
, ": ")));
679 /* Point to the beginning of the command-line */
682 textview
= messageview_get_current_textview(msgview
);
684 text
= textview
->text
;
685 body_pos
= textview
->body_pos
;
687 partinfo
= messageview_get_selected_mime_part(msgview
);
689 /* this command will alter the message text */
690 action_type
= action_get_type(action
);
691 if (action_type
& (ACTION_PIPE_OUT
| ACTION_INSERT
))
692 msgview
->filtered
= TRUE
;
694 if (action_type
& ACTION_FILTERING_ACTION
)
695 /* CLAWS: most of the above code is not necessary for applying
697 execute_filtering_actions(action
, msg_list
);
699 execute_actions(action
, msg_list
, text
, body_pos
, partinfo
,
703 static gboolean
execute_filtering_actions(gchar
*action
, GSList
*msglist
)
705 GSList
*action_list
, *p
;
706 const gchar
*sbegin
, *send
;
707 gchar
*action_string
;
708 SummaryView
*summaryview
= NULL
;
709 MainWindow
*mainwin
= NULL
;
711 if (mainwindow_get_mainwindow()) {
712 summaryview
= mainwindow_get_mainwindow()->summaryview
;
713 mainwin
= mainwindow_get_mainwindow();
716 if (NULL
== (sbegin
= g_strstr_len(action
, -1, "%as{")))
718 sbegin
+= sizeof "%as{" - 1;
719 if (NULL
== (send
= strrchr(sbegin
, '}')))
721 action_string
= g_strndup(sbegin
, send
- sbegin
);
723 action_list
= matcher_parser_get_action_list(action_string
);
724 if (action_list
== NULL
) {
725 gchar
*tmp
= g_strdup(action_string
);
729 alertpanel_error(_("There is no filtering action set"));
731 alertpanel_error(_("Invalid filtering action(s):\n%s"), tmp
);
732 g_free(action_string
);
736 g_free(action_string
);
738 /* apply actions on each message info */
739 for (p
= msglist
; p
&& p
->data
; p
= g_slist_next(p
)) {
740 filteringaction_apply_action_list(action_list
, (MsgInfo
*) p
->data
);
744 summary_lock(summaryview
);
745 main_window_cursor_wait(mainwin
);
746 summary_freeze(summaryview
);
747 folder_item_update_freeze();
750 filtering_move_and_copy_msgs(msglist
);
753 folder_item_update_thaw();
754 summary_thaw(summaryview
);
755 main_window_cursor_normal(mainwin
);
756 summary_unlock(summaryview
);
757 summary_show(summaryview
, summaryview
->folder_item
, FALSE
);
759 for (p
= action_list
; p
; p
= g_slist_next(p
))
760 if (p
->data
) filteringaction_free(p
->data
);
761 g_slist_free(action_list
);
765 static gboolean
execute_actions(gchar
*action
, GSList
*msg_list
,
767 gint body_pos
, MimeInfo
*partinfo
,
768 void (*callback
)(void *data
), void *data
)
770 GSList
*children_list
= NULL
, *cur
= NULL
;
774 ChildInfo
*child_info
;
775 ActionType action_type
;
778 gchar
*sel_str
= NULL
;
779 gchar
*msg_str
= NULL
;
780 gchar
*user_str
= NULL
;
781 gchar
*user_hidden_str
= NULL
;
782 GtkTextIter start_iter
, end_iter
;
783 gboolean is_selection
= FALSE
;
785 cm_return_val_if_fail(action
&& *action
, FALSE
);
787 action_type
= action_get_type(action
);
789 if (action_type
== ACTION_ERROR
)
790 return FALSE
; /* ERR: syntax error */
792 if (action_type
& (ACTION_SINGLE
| ACTION_MULTIPLE
) && !msg_list
)
793 return FALSE
; /* ERR: file command without selection */
795 msg_list_len
= g_slist_length(msg_list
);
797 if (action_type
& (ACTION_PIPE_OUT
| ACTION_PIPE_IN
| ACTION_INSERT
)) {
798 if (msg_list_len
> 1)
799 return FALSE
; /* ERR: pipe + multiple selection */
801 return FALSE
; /* ERR: pipe and no displayed text */
804 if (action_type
& ACTION_SELECTION_STR
) {
806 return FALSE
; /* ERR: selection string but no text */
810 GtkTextBuffer
*textbuf
;
812 textbuf
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(text
));
813 is_selection
= gtk_text_buffer_get_selection_bounds
814 (textbuf
, &start_iter
, &end_iter
);
816 gtk_text_buffer_get_iter_at_offset
817 (textbuf
, &start_iter
, body_pos
);
818 gtk_text_buffer_get_end_iter(textbuf
, &end_iter
);
820 msg_str
= gtk_text_buffer_get_text
821 (textbuf
, &start_iter
, &end_iter
, FALSE
);
823 sel_str
= g_strdup(msg_str
);
826 if (action_type
& ACTION_USER_STR
) {
827 if (!(user_str
= get_user_string(action
, ACTION_USER_STR
))) {
834 if (action_type
& ACTION_USER_HIDDEN_STR
) {
835 if (!(user_hidden_str
=
836 get_user_string(action
, ACTION_USER_HIDDEN_STR
))) {
844 if (text
&& (action_type
& ACTION_PIPE_OUT
)) {
845 GtkTextBuffer
*textbuf
;
846 textbuf
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(text
));
847 gtk_text_buffer_delete(textbuf
, &start_iter
, &end_iter
);
850 children
= g_new0(Children
, 1);
853 children
->action
= g_strdup(action
);
854 children
->action_type
= action_type
;
855 children
->msg_text
= text
;
856 children
->is_selection
= is_selection
;
858 if ((action_type
& (ACTION_USER_IN
| ACTION_USER_HIDDEN_IN
)) &&
859 ((action_type
& ACTION_SINGLE
) == 0 || msg_list_len
== 1))
860 children
->open_in
= 1;
862 /* Pre-fetch bodies, makes it easier on IMAP (see bug #3011) */
863 for (cur
= msg_list
; cur
; cur
= cur
->next
) {
865 msginfo
= (MsgInfo
*)cur
->data
;
867 dummy
= procmsg_get_message_file((MsgInfo
*)cur
->data
);
874 if (is_ok
&& (action_type
& ACTION_SINGLE
)) {
875 for (cur
= msg_list
; cur
&& is_ok
== TRUE
; cur
= cur
->next
) {
876 msginfo
= (MsgInfo
*)cur
->data
;
878 is_ok
= FALSE
; /* ERR: msginfo missing */
881 cmd
= parse_action_cmd(action
, msginfo
, msg_list
,
883 user_hidden_str
, sel_str
);
885 debug_print("Action command error\n");
886 is_ok
= FALSE
; /* ERR: incorrect command */
889 if ((child_info
= fork_child(cmd
, msg_str
, children
))) {
890 /* Pass msginfo to catch_status () */
891 if (!(action_type
& (ACTION_PIPE_OUT
| ACTION_INSERT
)))
892 child_info
->msginfo_list
=
893 g_slist_append (NULL
, msginfo
);
894 children_list
= g_slist_append(children_list
,
901 cmd
= parse_action_cmd(action
, NULL
, msg_list
, partinfo
,
902 user_str
, user_hidden_str
, sel_str
);
904 if ((child_info
= fork_child(cmd
, msg_str
, children
))) {
905 if (!(action_type
& (ACTION_PIPE_OUT
| ACTION_INSERT
)))
906 child_info
->msginfo_list
=
907 g_slist_copy (msg_list
);
908 children_list
= g_slist_append(children_list
,
914 is_ok
= FALSE
; /* ERR: incorrect command */
920 g_free(user_hidden_str
);
922 if (!children_list
) {
923 /* If not waiting for children, return */
924 free_children(children
);
928 children
->list
= children_list
;
929 children
->initial_nb
= children
->nb
;
931 for (cur
= children_list
; cur
; cur
= cur
->next
) {
932 child_info
= (ChildInfo
*) cur
->data
;
933 child_info
->callback
= callback
;
934 child_info
->data
= data
;
935 child_info
->tag_status
=
936 g_child_watch_add(child_info
->pid
, catch_status
, child_info
);
939 create_io_dialog(children
);
944 static ChildInfo
*fork_child(gchar
*cmd
, const gchar
*msg_str
,
947 gint chld_in
, chld_out
, chld_err
;
948 gchar
**argv
, *ret_str
, *trim_cmd
;
950 ChildInfo
*child_info
;
952 gssize by_written
= 0, by_read
= 0;
953 gboolean result
= FALSE
;
954 GError
*error
= NULL
;
956 follow_child
= !(children
->action_type
& ACTION_ASYNC
);
958 chld_in
= chld_out
= chld_err
= -1;
960 ret_str
= g_locale_from_utf8(cmd
, strlen(cmd
),
961 &by_read
, &by_written
,
963 if (!ret_str
|| !by_written
) {
966 ret_str
= g_strdup(cmd
);
971 while (g_ascii_isspace(trim_cmd
[0]))
975 argv
= g_new0(gchar
*, 4);
976 argv
[0] = g_strdup("/bin/sh");
977 argv
[1] = g_strdup("-c");
978 argv
[2] = g_strdup(trim_cmd
);
981 argv
= strsplit_with_quote(trim_cmd
, " ", 0);
986 result
= g_spawn_async_with_pipes(NULL
, argv
, NULL
,
987 G_SPAWN_DO_NOT_REAP_CHILD
| G_SPAWN_SEARCH_PATH
,
988 NULL
, NULL
, &pid
, &chld_in
, &chld_out
,
991 result
= g_spawn_async(NULL
, argv
, NULL
,
992 G_SPAWN_DO_NOT_REAP_CHILD
| G_SPAWN_SEARCH_PATH
, NULL
, NULL
,
996 debug_print("spawning %s: %d\n", cmd
, result
);
1001 alertpanel_error(_("Could not fork to execute the following "
1002 "command:\n%s\n%s"),
1003 cmd
, error
? error
->message
: _("Unknown error"));
1005 g_error_free(error
);
1009 if (!(children
->action_type
&
1010 (ACTION_PIPE_IN
| ACTION_USER_IN
| ACTION_USER_HIDDEN_IN
)))
1011 (void)close(chld_in
);
1013 if (!follow_child
) {
1014 g_spawn_close_pid(pid
);
1017 child_info
= g_new0(ChildInfo
, 1);
1019 child_info
->children
= children
;
1021 child_info
->pid
= pid
;
1023 child_info
->next_sig
= SIGTERM
;
1025 child_info
->cmd
= g_strdup(cmd
);
1026 child_info
->new_out
= FALSE
;
1027 child_info
->output
= g_string_new(NULL
);
1028 child_info
->chld_in
=
1029 (children
->action_type
&
1030 (ACTION_PIPE_IN
| ACTION_USER_IN
| ACTION_USER_HIDDEN_IN
))
1032 child_info
->chld_out
= chld_out
;
1033 child_info
->chld_err
= chld_err
;
1034 child_info
->tag_status
= -1;
1035 child_info
->tag_in
= -1;
1036 child_info
->tag_out
= claws_input_add(chld_out
, G_IO_IN
| G_IO_HUP
| G_IO_ERR
,
1037 catch_output
, child_info
, FALSE
);
1038 child_info
->tag_err
= claws_input_add(chld_err
, G_IO_IN
| G_IO_HUP
| G_IO_ERR
,
1039 catch_output
, child_info
, FALSE
);
1041 if (!(children
->action_type
&
1042 (ACTION_PIPE_IN
| ACTION_PIPE_OUT
| ACTION_INSERT
)))
1045 if ((children
->action_type
& ACTION_PIPE_IN
) && msg_str
) {
1047 ret_str
= g_locale_from_utf8(msg_str
, strlen(msg_str
),
1048 &by_read
, &by_written
, NULL
);
1049 if (ret_str
&& by_written
)
1050 r
= write(chld_in
, ret_str
, strlen(ret_str
));
1052 r
= write(chld_in
, msg_str
, strlen(msg_str
));
1056 if (!(children
->action_type
&
1057 (ACTION_USER_IN
| ACTION_USER_HIDDEN_IN
)))
1059 child_info
->chld_in
= -1; /* No more input */
1061 debug_print("piping to child process: %s (%d)\n", g_strerror(errno
), errno
);
1067 static void kill_children_cb(GtkWidget
*widget
, gpointer data
)
1070 Children
*children
= (Children
*) data
;
1071 ChildInfo
*child_info
;
1073 for (cur
= children
->list
; cur
; cur
= cur
->next
) {
1074 child_info
= (ChildInfo
*)(cur
->data
);
1076 debug_print("Killing child group HANDLE %p\n", child_info
->pid
);
1077 TerminateProcess(child_info
->pid
, 0);
1079 debug_print("Killing child group id %d\n", child_info
->pid
);
1080 if (child_info
->pid
&& kill(child_info
->pid
, child_info
->next_sig
) < 0)
1082 child_info
->next_sig
= SIGKILL
;
1087 static gint
wait_for_children(Children
*children
)
1089 gboolean new_output
;
1090 ChildInfo
*child_info
;
1093 cur
= children
->list
;
1096 child_info
= (ChildInfo
*)cur
->data
;
1097 new_output
|= child_info
->new_out
;
1101 children
->output
|= new_output
;
1103 if (new_output
|| (children
->dialog
&& (children
->initial_nb
!= children
->nb
)))
1104 update_io_dialog(children
);
1109 if (!children
->dialog
) {
1110 free_children(children
);
1111 } else if (!children
->output
) {
1112 gtk_widget_destroy(children
->dialog
);
1118 static void send_input(GtkWidget
*w
, gpointer data
)
1120 Children
*children
= (Children
*) data
;
1121 ChildInfo
*child_info
= (ChildInfo
*) children
->list
->data
;
1123 child_info
->tag_in
= claws_input_add(child_info
->chld_in
,
1124 G_IO_OUT
| G_IO_ERR
,
1125 catch_input
, children
, FALSE
);
1128 static gint
delete_io_dialog_cb(GtkWidget
*w
, GdkEvent
*e
, gpointer data
)
1130 hide_io_dialog_cb(w
, data
);
1134 static void hide_io_dialog_cb(GtkWidget
*w
, gpointer data
)
1137 Children
*children
= (Children
*)data
;
1139 if (!children
->nb
) {
1140 g_signal_handlers_disconnect_matched
1141 (G_OBJECT(children
->dialog
), G_SIGNAL_MATCH_DATA
,
1142 0, 0, NULL
, NULL
, children
);
1143 gtk_widget_destroy(children
->dialog
);
1144 free_children(children
);
1148 static gint
io_dialog_key_pressed_cb(GtkWidget
*widget
, GdkEventKey
*event
,
1151 if (event
&& (event
->keyval
== GDK_KEY_Escape
||
1152 event
->keyval
== GDK_KEY_Return
||
1153 event
->keyval
== GDK_KEY_KP_Enter
))
1154 hide_io_dialog_cb(widget
, data
);
1158 static void childinfo_close_pipes(ChildInfo
*child_info
)
1160 /* stdout and stderr pipes are guaranteed to be removed by
1161 * their handler, but in case where we receive child exit notification
1162 * before grand-child's pipes closing signals, we check them and close
1165 if (child_info
->tag_in
> 0)
1166 g_source_remove(child_info
->tag_in
);
1167 if (child_info
->tag_out
> 0)
1168 g_source_remove(child_info
->tag_out
);
1169 if (child_info
->tag_err
> 0)
1170 g_source_remove(child_info
->tag_err
);
1172 if (child_info
->chld_in
>= 0)
1173 (void)close(child_info
->chld_in
);
1174 if (child_info
->chld_out
>= 0)
1175 (void)close(child_info
->chld_out
);
1176 if (child_info
->chld_err
>= 0)
1177 (void)close(child_info
->chld_err
);
1180 static void free_children(Children
*children
)
1182 ChildInfo
*child_info
;
1183 void (*callback
)(void *data
) = NULL
;
1186 debug_print("Freeing children data %p\n", children
);
1188 g_free(children
->action
);
1189 while (children
->list
!= NULL
) {
1190 child_info
= (ChildInfo
*)children
->list
->data
;
1191 g_free(child_info
->cmd
);
1192 g_string_free(child_info
->output
, TRUE
);
1193 children
->list
= g_slist_remove(children
->list
, child_info
);
1194 callback
= child_info
->callback
;
1195 data
= child_info
->data
;
1205 static void update_io_dialog(Children
*children
)
1209 debug_print("Updating actions input/output dialog.\n");
1211 if (children
->progress_bar
) {
1214 /* use a more compact format */
1215 const gchar
*format
= "%s %d/%d";
1217 const gchar
*format
= "%s %d / %d";
1220 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(children
->progress_bar
),
1221 (children
->initial_nb
== 0) ? 0 :
1222 (gdouble
) (children
->initial_nb
- children
->nb
) /
1223 (gdouble
) children
->initial_nb
);
1224 text
= g_strdup_printf(format
, _("Completed"),
1225 children
->initial_nb
- children
->nb
,
1226 children
->initial_nb
);
1227 gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(children
->progress_bar
), TRUE
);
1228 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(children
->progress_bar
), text
);
1232 if (!children
->nb
) {
1233 gtk_widget_set_sensitive(children
->abort_btn
, FALSE
);
1234 gtk_widget_set_sensitive(children
->close_btn
, TRUE
);
1235 if (children
->input_hbox
)
1236 gtk_widget_set_sensitive(children
->input_hbox
, FALSE
);
1237 gtk_widget_grab_focus(children
->close_btn
);
1238 g_signal_connect(G_OBJECT(children
->dialog
),
1240 G_CALLBACK(io_dialog_key_pressed_cb
),
1244 if (children
->output
) {
1245 GtkWidget
*text
= children
->text
;
1246 GtkTextBuffer
*textbuf
;
1247 GtkTextIter iter
, start_iter
, end_iter
;
1249 ChildInfo
*child_info
;
1251 gtk_widget_show(children
->scrolledwin
);
1252 textbuf
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(text
));
1253 gtk_text_buffer_get_bounds(textbuf
, &start_iter
, &end_iter
);
1254 gtk_text_buffer_delete(textbuf
, &start_iter
, &end_iter
);
1255 gtk_text_buffer_get_start_iter(textbuf
, &iter
);
1257 for (cur
= children
->list
; cur
; cur
= cur
->next
) {
1258 child_info
= (ChildInfo
*)cur
->data
;
1259 if (child_info
->pid
)
1260 caption
= g_strdup_printf
1261 (_("--- Running: %s\n"),
1264 caption
= g_strdup_printf
1265 (_("--- Ended: %s\n"),
1268 gtk_text_buffer_insert(textbuf
, &iter
, caption
, -1);
1269 gtk_text_buffer_insert(textbuf
, &iter
,
1270 child_info
->output
->str
, -1);
1272 child_info
->new_out
= FALSE
;
1278 *\brief Save Gtk object size to prefs dataset
1280 static void actions_io_size_allocate_cb(GtkWidget
*widget
,
1281 GtkAllocation
*allocation
)
1283 cm_return_if_fail(allocation
!= NULL
);
1285 gtk_window_get_size(GTK_WINDOW(widget
),
1286 &prefs_common
.actionsiodialog_width
, &prefs_common
.actionsiodialog_height
);
1289 static void create_io_dialog(Children
*children
)
1293 GtkWidget
*entry
= NULL
;
1294 GtkWidget
*input_hbox
= NULL
;
1295 GtkWidget
*send_button
;
1298 GtkWidget
*scrolledwin
;
1299 GtkWidget
*progress_bar
= NULL
;
1300 GtkWidget
*abort_button
;
1301 GtkWidget
*close_button
;
1302 static GdkGeometry geometry
;
1304 debug_print("Creating action IO dialog\n");
1306 dialog
= gtk_dialog_new();
1307 gtk_window_set_position(GTK_WINDOW(dialog
), GTK_WIN_POS_CENTER
);
1308 gtk_window_set_title(GTK_WINDOW(dialog
), _("Action's input/output"));
1309 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
1310 manage_window_set_transient(GTK_WINDOW(dialog
));
1311 g_signal_connect(G_OBJECT(dialog
), "delete_event",
1312 G_CALLBACK(delete_io_dialog_cb
), children
);
1313 g_signal_connect(G_OBJECT(dialog
), "destroy",
1314 G_CALLBACK(hide_io_dialog_cb
),
1316 g_signal_connect(G_OBJECT(dialog
), "size_allocate",
1317 G_CALLBACK(actions_io_size_allocate_cb
), NULL
);
1319 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 8);
1320 gtk_container_add(GTK_CONTAINER(
1321 gtk_dialog_get_content_area(GTK_DIALOG(dialog
))), vbox
);
1322 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 8);
1323 gtk_widget_show(vbox
);
1325 label
= gtk_label_new(children
->action
);
1326 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
1327 gtk_widget_show(label
);
1329 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
1330 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
1331 GTK_POLICY_AUTOMATIC
,
1332 GTK_POLICY_AUTOMATIC
);
1333 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin
),
1335 gtk_scrolled_window_set_propagate_natural_height(GTK_SCROLLED_WINDOW(scrolledwin
), TRUE
);
1336 gtk_box_pack_start(GTK_BOX(vbox
), scrolledwin
, TRUE
, TRUE
, 0);
1337 gtk_widget_hide(scrolledwin
);
1339 text
= gtk_text_view_new();
1341 if (prefs_common
.textfont
) {
1342 PangoFontDescription
*font_desc
;
1343 font_desc
= pango_font_description_from_string
1344 (prefs_common
.textfont
);
1346 gtk_widget_override_font(text
, font_desc
);
1347 pango_font_description_free(font_desc
);
1351 gtk_text_view_set_editable(GTK_TEXT_VIEW(text
), FALSE
);
1352 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text
), GTK_WRAP_WORD
);
1353 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text
), 6);
1354 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text
), 6);
1355 gtk_container_add(GTK_CONTAINER(scrolledwin
), text
);
1356 gtk_widget_show(text
);
1358 if (children
->open_in
) {
1359 input_hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
1360 gtk_widget_show(input_hbox
);
1362 entry
= gtk_entry_new();
1363 gtk_widget_set_size_request(entry
, 320, -1);
1364 g_signal_connect(G_OBJECT(entry
), "activate",
1365 G_CALLBACK(send_input
), children
);
1366 gtk_box_pack_start(GTK_BOX(input_hbox
), entry
, TRUE
, TRUE
, 0);
1367 if (children
->action_type
& ACTION_USER_HIDDEN_IN
) {
1368 gtk_entry_set_visibility(GTK_ENTRY(entry
), FALSE
);
1370 gtk_widget_show(entry
);
1372 send_button
= gtkut_stock_button("system-run", _("_Execute"));
1373 g_signal_connect(G_OBJECT(send_button
), "clicked",
1374 G_CALLBACK(send_input
), children
);
1375 gtk_box_pack_start(GTK_BOX(input_hbox
), send_button
, FALSE
,
1377 gtk_widget_show(send_button
);
1379 gtk_box_pack_start(GTK_BOX(vbox
), input_hbox
, FALSE
, FALSE
, 0);
1380 gtk_widget_grab_focus(entry
);
1383 if (children
->initial_nb
> 1) {
1386 /* use a more compact format */
1387 const gchar
*format
= "%s 0/%d\n";
1389 const gchar
*format
= "%s 0 / %d\n";
1392 progress_bar
= gtk_progress_bar_new();
1393 gtk_orientable_set_orientation(GTK_ORIENTABLE(progress_bar
),
1394 GTK_ORIENTATION_HORIZONTAL
);
1395 gtk_progress_bar_set_inverted(GTK_PROGRESS_BAR(progress_bar
),
1398 text
= g_strdup_printf(format
, _("Completed"),
1399 children
->initial_nb
);
1400 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar
),
1403 gtk_box_pack_start(GTK_BOX(vbox
), progress_bar
, FALSE
, FALSE
, 0);
1404 gtk_widget_show(progress_bar
);
1407 abort_button
= gtk_dialog_add_button(GTK_DIALOG(dialog
), _("_Stop"),
1409 close_button
= gtk_dialog_add_button(GTK_DIALOG(dialog
),_("_Close"),
1411 gtk_widget_grab_default(close_button
);
1412 g_signal_connect(G_OBJECT(abort_button
), "clicked",
1413 G_CALLBACK(kill_children_cb
), children
);
1414 g_signal_connect(G_OBJECT(close_button
), "clicked",
1415 G_CALLBACK(hide_io_dialog_cb
), children
);
1418 gtk_widget_set_sensitive(close_button
, FALSE
);
1420 if (!geometry
.min_height
) {
1421 geometry
.min_width
= 582;
1422 geometry
.min_height
= 310;
1425 gtk_window_set_geometry_hints(GTK_WINDOW(dialog
), NULL
, &geometry
,
1427 gtk_window_set_default_size(GTK_WINDOW(dialog
), prefs_common
.actionsiodialog_width
,
1428 prefs_common
.actionsiodialog_height
);
1430 gtk_widget_show(dialog
);
1432 children
->dialog
= dialog
;
1433 children
->scrolledwin
= scrolledwin
;
1434 children
->text
= text
;
1435 children
->input_hbox
= children
->open_in
? input_hbox
: NULL
;
1436 children
->input_entry
= children
->open_in
? entry
: NULL
;
1437 children
->progress_bar
= progress_bar
;
1438 children
->abort_btn
= abort_button
;
1439 children
->close_btn
= close_button
;
1442 static void catch_status(GPid pid
, gint status
, gpointer data
)
1444 ChildInfo
*child_info
= (ChildInfo
*)data
;
1446 debug_print("Child returned %d\n", status
);
1448 childinfo_close_pipes(child_info
);
1449 g_spawn_close_pid(child_info
->pid
);
1450 child_info
->pid
= 0;
1452 if (child_info
->children
->action_type
& (ACTION_SINGLE
| ACTION_MULTIPLE
)
1453 && child_info
->msginfo_list
) {
1454 /* Actions on message *files* might change size and
1455 * time stamp, and thus invalidate the cache */
1456 SummaryView
*summaryview
= NULL
;
1458 MsgInfo
*msginfo
, *nmi
; /* newmsginfo */
1460 gboolean modified_something
= FALSE
;
1461 FolderItem
*last_item
= NULL
;
1462 if (mainwindow_get_mainwindow ())
1463 summaryview
= mainwindow_get_mainwindow ()->summaryview
;
1464 for (cur
= child_info
->msginfo_list
; cur
; cur
= cur
->next
) {
1465 msginfo
= (MsgInfo
*)cur
->data
;
1466 if (!(msginfo
&& /* Stuff used valid? */
1467 msginfo
->folder
&& msginfo
->folder
->cache
))
1469 file
= procmsg_get_message_file_path (msginfo
);
1472 nmi
= procheader_parse_file (file
, msginfo
->flags
, TRUE
, FALSE
);
1474 continue; /* Deleted? */
1475 if (msginfo
->mtime
!= nmi
->mtime
|| msginfo
->size
!= nmi
->size
) {
1476 nmi
->folder
= msginfo
->folder
;
1477 nmi
->msgnum
= msginfo
->msgnum
;
1478 msgcache_update_msg (msginfo
->folder
->cache
, nmi
);
1479 modified_something
= TRUE
;
1480 last_item
= nmi
->folder
;
1482 procmsg_msginfo_free (&nmi
);
1483 if (summaryview
&& summaryview
->displayed
&&
1484 summaryview
->folder_item
== msginfo
->folder
&&
1485 summary_get_msgnum(summaryview
, summaryview
->displayed
) == msginfo
->msgnum
)
1486 summary_redisplay_msg(summaryview
);
1489 if (modified_something
&& last_item
&&
1490 summaryview
&& summaryview
->folder_item
== last_item
) {
1491 summary_show (summaryview
, summaryview
->folder_item
, FALSE
);
1493 g_slist_free (child_info
->msginfo_list
);
1494 child_info
->msginfo_list
= NULL
;
1497 if (!child_info
->pid
)
1498 child_info
->children
->nb
--;
1500 wait_for_children(child_info
->children
);
1503 static void catch_input(gpointer data
, gint source
, GIOCondition cond
)
1505 Children
*children
= (Children
*)data
;
1506 ChildInfo
*child_info
= (ChildInfo
*)children
->list
->data
;
1507 gchar
*input
, *ret_str
;
1508 gint c
, count
, len
, r
;
1509 gssize by_read
= 0, by_written
= 0;
1511 debug_print("Sending input to grand child.\n");
1512 if (!(cond
& (G_IO_OUT
| G_IO_ERR
)))
1515 gtk_widget_set_sensitive(children
->input_hbox
, FALSE
);
1516 gtk_widget_grab_focus(children
->abort_btn
);
1518 g_source_remove(child_info
->tag_in
);
1519 child_info
->tag_in
= -1;
1521 input
= gtk_editable_get_chars(GTK_EDITABLE(children
->input_entry
),
1523 ret_str
= g_locale_from_utf8(input
, strlen(input
), &by_read
,
1533 len
= strlen(input
);
1537 c
= write(child_info
->chld_in
, input
+ count
, len
- count
);
1540 } while (c
>= 0 && count
< len
);
1543 r
= write(child_info
->chld_in
, "\n", 2);
1547 r
= close(child_info
->chld_in
);
1548 child_info
->chld_in
= -1;
1550 debug_print("closing child input fd: %s (%d)\n", g_strerror(errno
), errno
);
1551 child_info
->chld_in
= -1;
1552 debug_print("Input to grand child sent.\n");
1555 static void catch_output(gpointer data
, gint source
, GIOCondition cond
)
1557 ChildInfo
*child_info
= (ChildInfo
*)data
;
1559 gchar buf
[BUFFSIZE
];
1561 debug_print("Catching grand child's output.\n");
1562 if (child_info
->children
->action_type
&
1563 (ACTION_PIPE_OUT
| ACTION_INSERT
)
1564 && source
== child_info
->chld_out
) {
1566 GTK_TEXT_VIEW(child_info
->children
->msg_text
);
1567 GtkTextBuffer
*textbuf
= gtk_text_view_get_buffer(text
);
1572 mark
= gtk_text_buffer_get_insert(textbuf
);
1573 gtk_text_buffer_get_iter_at_mark(textbuf
, &iter
, mark
);
1574 ins_pos
= gtk_text_iter_get_offset(&iter
);
1577 gsize bytes_read
= 0, bytes_written
= 0;
1580 c
= read(source
, buf
, sizeof(buf
) - 1);
1585 ret_str
= g_locale_to_utf8
1586 (buf
, c
, &bytes_read
, &bytes_written
, NULL
);
1587 if (ret_str
&& bytes_written
> 0)
1588 gtk_text_buffer_insert(textbuf
, &iter
, ret_str
, -1);
1590 gtk_text_buffer_insert(textbuf
, &iter
, buf
, c
);
1595 if (child_info
->children
->is_selection
) {
1598 gtk_text_buffer_get_iter_at_offset
1599 (textbuf
, &ins
, ins_pos
);
1600 gtk_text_buffer_select_range(textbuf
, &ins
, &iter
);
1603 c
= read(source
, buf
, sizeof(buf
) - 1);
1605 gsize bytes_read
= 0, bytes_written
= 0;
1609 ret_str
= g_locale_to_utf8
1610 (buf
, c
, &bytes_read
, &bytes_written
, NULL
);
1612 if (bytes_written
) {
1614 (child_info
->output
, ret_str
,
1619 g_string_append_len(child_info
->output
, buf
, c
);
1621 child_info
->new_out
= TRUE
;
1625 if (source
== child_info
->chld_out
) {
1626 g_source_remove(child_info
->tag_out
);
1627 child_info
->tag_out
= -1;
1628 (void)close(child_info
->chld_out
);
1629 child_info
->chld_out
= -1;
1631 g_source_remove(child_info
->tag_err
);
1632 child_info
->tag_err
= -1;
1633 (void)close(child_info
->chld_err
);
1634 child_info
->chld_err
= -1;
1638 wait_for_children(child_info
->children
);
1641 static gchar
*get_user_string(const gchar
*action
, ActionType type
)
1644 gchar
*user_str
= NULL
;
1647 case ACTION_USER_HIDDEN_STR
:
1648 message
= g_strdup_printf
1649 (_("Enter the argument for the following action:\n"
1650 "('%%h' will be replaced with the argument)\n"
1653 user_str
= input_dialog_with_invisible
1654 (_("Action's hidden user argument"), message
, NULL
);
1656 case ACTION_USER_STR
:
1657 message
= g_strdup_printf
1658 (_("Enter the argument for the following action:\n"
1659 "('%%u' will be replaced with the argument)\n"
1662 user_str
= input_dialog
1663 (_("Action's user argument"), message
, NULL
);
1666 g_warning("unsupported action type %d", type
);