/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto & The Sylpheed Claws Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
GtkWidget *text;
GtkWidget *input_entry;
GtkWidget *input_hbox;
+ GtkWidget *progress_bar;
GtkWidget *abort_btn;
GtkWidget *close_btn;
GtkWidget *scrolledwin;
gchar *action;
+ ActionType action_type;
GSList *list;
gint nb;
+ gint initial_nb;
gint open_in;
gboolean output;
{
Children *children;
gchar *cmd;
- guint type;
pid_t pid;
gint chld_in;
gint chld_out;
MimeInfo *partinfo);
static ChildInfo *fork_child (gchar *cmd,
- gint action_type,
const gchar *msg_str,
Children *children);
gint ret;
if (!partinfo) {
- FILE *fp;
-#if USE_GPGME
- if ((fp = procmsg_open_message_decrypted(msginfo, &partinfo))
- == NULL) {
- alertpanel_error(_("Could not get message file."));
- return FALSE;
- }
-#else
- if ((fp = procmsg_open_message(msginfo)) == NULL) {
- alertpanel_error(_("Could not get message file."));
- return FALSE;
- }
- partinfo = procmime_scan_mime_header(fp);
-#endif
- fclose(fp);
+ partinfo = procmime_scan_message(msginfo);
if (!partinfo) {
- procmime_mimeinfo_free_all(partinfo);
alertpanel_error(_("Could not get message part."));
return FALSE;
}
GtkWidget *widget)
{
gchar *buf, *action;
- guint action_type;
+ ActionType action_type;
g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
GtkWidget *text = NULL;
GdkFont *msgfont = NULL;
guint body_pos = 0;
-
+ ActionType action_type;
+
g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
buf = (gchar *)g_slist_nth_data(prefs_common.actions_list, action_nb);
}
partinfo = messageview_get_selected_mime_part(msgview);
+ /* this command will alter the message text */
+ action_type = action_get_type(action);
+ if (action_type & (ACTION_PIPE_OUT | ACTION_INSERT))
+ msgview->filtered = TRUE;
+
execute_actions(action, msg_list, text, msgfont, body_pos, partinfo);
}
gint msg_list_len;
Children *children;
ChildInfo *child_info;
- gint action_type;
+ ActionType action_type;
MsgInfo *msginfo;
gchar *cmd;
guint start = 0, end = 0;
return FALSE; /* ERR: selection string but no text */
}
- if (GTK_EDITABLE(text)->has_selection) {
- start = GTK_EDITABLE(text)->selection_start_pos;
- end = GTK_EDITABLE(text)->selection_end_pos;
- if (start > end) {
- guint tmp;
- tmp = start;
- start = end;
- end = tmp;
- }
+ if (text) {
+ if (GTK_EDITABLE(text)->has_selection) {
+ start = GTK_EDITABLE(text)->selection_start_pos;
+ end = GTK_EDITABLE(text)->selection_end_pos;
+ if (start > end) {
+ guint tmp;
+ tmp = start;
+ start = end;
+ end = tmp;
+ }
- if (start == end) {
+ if (start == end) {
+ start = body_pos;
+ end = gtk_stext_get_length(GTK_STEXT(text));
+ msg_str = gtk_editable_get_chars
+ (GTK_EDITABLE(text), start, end);
+ } else {
+ sel_str = gtk_editable_get_chars
+ (GTK_EDITABLE(text), start, end);
+ msg_str = g_strdup(sel_str);
+ }
+ } else {
start = body_pos;
end = gtk_stext_get_length(GTK_STEXT(text));
msg_str = gtk_editable_get_chars(GTK_EDITABLE(text),
start, end);
- } else {
- sel_str = gtk_editable_get_chars(GTK_EDITABLE(text),
- start, end);
- msg_str = g_strdup(sel_str);
}
- } else {
- start = body_pos;
- end = gtk_stext_get_length(GTK_STEXT(text));
- msg_str = gtk_editable_get_chars(GTK_EDITABLE(text),
- start, end);
}
if (action_type & ACTION_USER_STR) {
children = g_new0(Children, 1);
- children->msg_text = text;
- children->msgfont = msgfont;
+ children->action = g_strdup(action);
+ children->action_type = action_type;
+ children->msg_text = text;
+ children->msgfont = msgfont;
if ((action_type & (ACTION_USER_IN | ACTION_USER_HIDDEN_IN)) &&
((action_type & ACTION_SINGLE) == 0 || msg_list_len == 1))
is_ok = FALSE; /* ERR: incorrect command */
break;
}
- if ((child_info = fork_child(cmd, action_type, msg_str,
- children))) {
+ if ((child_info = fork_child(cmd, msg_str, children))) {
children_list = g_slist_append(children_list,
child_info);
}
cmd = parse_action_cmd(action, NULL, msg_list, partinfo,
user_str, user_hidden_str, sel_str);
if (cmd) {
- if ((child_info = fork_child(cmd, action_type, msg_str,
- children))) {
+ if ((child_info = fork_child(cmd, msg_str, children))) {
children_list = g_slist_append(children_list,
child_info);
}
if (!children_list) {
/* If not waiting for children, return */
- g_free(children);
+ free_children(children);
} else {
GSList *cur;
- children->action = g_strdup(action);
- children->dialog = NULL;
- children->list = children_list;
- children->nb = g_slist_length(children_list);
+ children->list = children_list;
+ children->nb = g_slist_length(children_list);
+ children->initial_nb = children->nb;
for (cur = children_list; cur; cur = cur->next) {
child_info = (ChildInfo *) cur->data;
return is_ok;
}
-static ChildInfo *fork_child(gchar *cmd, gint action_type,
- const gchar *msg_str, Children *children)
+static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
+ Children *children)
{
gint chld_in[2], chld_out[2], chld_err[2], chld_status[2];
gchar *cmdline[4];
ChildInfo *child_info;
gint sync;
- sync = !(action_type & ACTION_ASYNC);
+ sync = !(children->action_type & ACTION_ASYNC);
chld_in[0] = chld_in[1] = chld_out[0] = chld_out[1] = chld_err[0]
= chld_err[1] = chld_status[0] = chld_status[1] = -1;
perror("setpgid");
if (sync) {
- if (action_type &
+ if (children->action_type &
(ACTION_PIPE_IN |
ACTION_USER_IN |
ACTION_USER_HIDDEN_IN)) {
}
close(chld_in[0]);
- if (!(action_type &
+ if (!(children->action_type &
(ACTION_PIPE_IN | ACTION_USER_IN | ACTION_USER_HIDDEN_IN)))
close(chld_in[1]);
close(chld_out[1]);
child_info->pid = pid;
child_info->cmd = g_strdup(cmd);
- child_info->type = action_type;
child_info->new_out = FALSE;
child_info->output = g_string_new(NULL);
child_info->chld_in =
- (action_type &
+ (children->action_type &
(ACTION_PIPE_IN | ACTION_USER_IN | ACTION_USER_HIDDEN_IN))
? chld_in [1] : -1;
child_info->chld_out = chld_out[0];
child_info->tag_err = gdk_input_add(chld_err[0], GDK_INPUT_READ,
catch_output, child_info);
- if (!(action_type & (ACTION_PIPE_IN | ACTION_PIPE_OUT | ACTION_INSERT)))
+ if (!(children->action_type &
+ (ACTION_PIPE_IN | ACTION_PIPE_OUT | ACTION_INSERT)))
return child_info;
- if ((action_type & ACTION_PIPE_IN) && msg_str) {
+ if ((children->action_type & ACTION_PIPE_IN) && msg_str) {
write(chld_in[1], msg_str, strlen(msg_str));
- if (!(action_type & (ACTION_USER_IN | ACTION_USER_HIDDEN_IN)))
+ if (!(children->action_type &
+ (ACTION_USER_IN | ACTION_USER_HIDDEN_IN)))
close(chld_in[1]);
child_info->chld_in = -1; /* No more input */
}
static void childinfo_close_pipes(ChildInfo *child_info)
{
+ /* stdout and stderr pipes are guaranteed to be removed by
+ * their handler, but in case where we receive child exit notification
+ * before grand-child's pipes closing signals, we check them and close
+ * them if necessary
+ */
if (child_info->tag_in > 0)
gdk_input_remove(child_info->tag_in);
- gdk_input_remove(child_info->tag_out);
- gdk_input_remove(child_info->tag_err);
+ if (child_info->tag_out > 0)
+ gdk_input_remove(child_info->tag_out);
+ if (child_info->tag_err > 0)
+ gdk_input_remove(child_info->tag_err);
if (child_info->chld_in >= 0)
close(child_info->chld_in);
- close(child_info->chld_out);
- close(child_info->chld_err);
+ if (child_info->chld_out >= 0)
+ close(child_info->chld_out);
+ if (child_info->chld_err >= 0)
+ close(child_info->chld_err);
+
close(child_info->chld_status);
}
static void free_children(Children *children)
{
- GSList *cur;
ChildInfo *child_info;
debug_print("Freeing children data %p\n", children);
g_free(children->action);
- for (cur = children->list; cur;) {
- child_info = (ChildInfo *)cur->data;
+ while (children->list != NULL) {
+ child_info = (ChildInfo *)children->list->data;
g_free(child_info->cmd);
g_string_free(child_info->output, TRUE);
children->list = g_slist_remove(children->list, child_info);
g_free(child_info);
- cur = children->list;
}
g_free(children);
}
debug_print("Updating actions input/output dialog.\n");
+ if (children->progress_bar) {
+ gtk_progress_configure(GTK_PROGRESS(children->progress_bar),
+ children->initial_nb -children->nb,
+ 0.0, children->initial_nb);
+ }
+
if (!children->nb) {
gtk_widget_set_sensitive(children->abort_btn, FALSE);
gtk_widget_set_sensitive(children->close_btn, TRUE);
GtkWidget *text;
GtkWidget *scrolledwin;
GtkWidget *hbox;
+ GtkWidget *progress_bar = NULL;
GtkWidget *abort_button;
GtkWidget *close_button;
gtk_signal_connect(GTK_OBJECT(entry), "activate",
GTK_SIGNAL_FUNC(send_input), children);
gtk_box_pack_start(GTK_BOX(input_hbox), entry, TRUE, TRUE, 0);
- if (children->open_in & ACTION_USER_HIDDEN_IN)
+ if (children->action_type & ACTION_USER_HIDDEN_IN)
gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
gtk_widget_show(entry);
gtk_widget_grab_focus(entry);
}
+ if (children->initial_nb > 1) {
+ progress_bar = gtk_progress_bar_new();
+ gtk_progress_bar_set_bar_style(GTK_PROGRESS_BAR(progress_bar),
+ GTK_PROGRESS_CONTINUOUS);
+ gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(progress_bar),
+ GTK_PROGRESS_LEFT_TO_RIGHT);
+ gtk_progress_set_activity_mode(GTK_PROGRESS(progress_bar),
+ FALSE);
+ gtk_progress_set_format_string(GTK_PROGRESS(progress_bar),
+ _("Completed %v/%u"));
+ gtk_progress_set_show_text(GTK_PROGRESS(progress_bar), TRUE);
+ gtk_progress_configure(GTK_PROGRESS(progress_bar),
+ children->initial_nb -children->nb,
+ 0.0, children->initial_nb);
+
+ gtk_box_pack_start(GTK_BOX(vbox), progress_bar, TRUE, TRUE, 0);
+ gtk_widget_show(progress_bar);
+ }
+
gtkut_button_set_create(&hbox, &abort_button, _("Abort"),
&close_button, _("Close"), NULL, NULL);
gtk_signal_connect(GTK_OBJECT(abort_button), "clicked",
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), hbox);
- children->dialog = dialog;
- children->scrolledwin = scrolledwin;
- children->text = text;
- children->input_hbox = children->open_in ? input_hbox : NULL;
- children->input_entry = children->open_in ? entry : NULL;
- children->abort_btn = abort_button;
- children->close_btn = close_button;
+ children->dialog = dialog;
+ children->scrolledwin = scrolledwin;
+ children->text = text;
+ children->input_hbox = children->open_in ? input_hbox : NULL;
+ children->input_entry = children->open_in ? entry : NULL;
+ children->progress_bar = progress_bar;
+ children->abort_btn = abort_button;
+ children->close_btn = close_button;
gtk_widget_show(dialog);
}
gchar buf[BUFFSIZE];
debug_print("Catching grand child's output.\n");
- if (child_info->type & (ACTION_PIPE_OUT | ACTION_INSERT)
+ if (child_info->children->action_type &
+ (ACTION_PIPE_OUT | ACTION_INSERT)
&& source == child_info->chld_out) {
gboolean is_selection = FALSE;
GtkWidget *text = child_info->children->msg_text;
if (c > 0)
child_info->new_out = TRUE;
}
+ if (c == 0) {
+ if (source == child_info->chld_out) {
+ gdk_input_remove(child_info->tag_out);
+ child_info->tag_out = -1;
+ close(child_info->chld_out);
+ child_info->chld_out = -1;
+ } else {
+ gdk_input_remove(child_info->tag_err);
+ child_info->tag_err = -1;
+ close(child_info->chld_err);
+ child_info->chld_err = -1;
+ }
+ }
+
wait_for_children(child_info->children);
}