2009-09-24 [iwkse] 3.7.2cvs36
[claws.git] / src / action.c
index d8711eb50fbf75563e64377596f1177004981e35..42b5c5da88936ca116ee316443f130da278b76a5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 1999-2009 Hiroyuki Yamamoto & The Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -194,10 +194,11 @@ static gchar *get_user_string             (const gchar    *action,
 ActionType action_get_type(const gchar *action_str)
 {
        const gchar *p;
+       gboolean in_filtering_action = FALSE;
        ActionType action_type = ACTION_NONE;
 
-       g_return_val_if_fail(action_str,  ACTION_ERROR);
-       g_return_val_if_fail(*action_str, ACTION_ERROR);
+       cm_return_val_if_fail(action_str,  ACTION_ERROR);
+       cm_return_val_if_fail(*action_str, ACTION_ERROR);
 
        p = action_str;
 
@@ -216,55 +217,60 @@ ActionType action_get_type(const gchar *action_str)
                return ACTION_ERROR;
 
        while (*p && action_type != ACTION_ERROR) {
-               if (p[0] == '%' && p[1]) {
-                       switch (p[1]) {
-                       case 'a':
-                               /* CLAWS: filtering action is a mutually exclusive
-                                * action. we can enable others if needed later. we
-                                * add ACTION_SINGLE | ACTION_MULTIPLE so it will
-                                * only be executed from the main window toolbar */
-                               if (p[2] == 's')  /* source messages */
-                                       action_type = ACTION_FILTERING_ACTION 
-                                                   | ACTION_SINGLE 
-                                                   | ACTION_MULTIPLE;
-                               break;
-                       case 'f':
-                               action_type |= ACTION_SINGLE;
-                               break;
-                       case 'F':
-                               action_type |= ACTION_MULTIPLE;
-                               break;
-                       case 'p':
-                               action_type |= ACTION_SINGLE;
-                               break;
-                       case 's':
-                               action_type |= ACTION_SELECTION_STR;
-                               break;
-                       case 'u':
-                               action_type |= ACTION_USER_STR;
-                               break;
-                       case 'h':
-                               action_type |= ACTION_USER_HIDDEN_STR;
-                               break;
-                       case '%':
-                               /* literal '%' */
-                               break;
-                       default:
-                               action_type = ACTION_ERROR;
-                               break;
+               if (!in_filtering_action) {
+                       if (p[0] == '%' && p[1]) {
+                               switch (p[1]) {
+                               case 'a':
+                                       /* CLAWS: filtering action is a mutually exclusive
+                                       * action. we can enable others if needed later. we
+                                       * add ACTION_SINGLE | ACTION_MULTIPLE so it will
+                                       * only be executed from the main window toolbar */
+                                       if (p[2] == 's')  /* source messages */
+                                               action_type = ACTION_FILTERING_ACTION 
+                                                               | ACTION_SINGLE 
+                                                               | ACTION_MULTIPLE;
+                                       in_filtering_action = TRUE;
+                                       break;
+                               case 'f':
+                                       action_type |= ACTION_SINGLE;
+                                       break;
+                               case 'F':
+                                       action_type |= ACTION_MULTIPLE;
+                                       break;
+                               case 'p':
+                                       action_type |= ACTION_SINGLE;
+                                       break;
+                               case 's':
+                                       action_type |= ACTION_SELECTION_STR;
+                                       break;
+                               case 'u':
+                                       action_type |= ACTION_USER_STR;
+                                       break;
+                               case 'h':
+                                       action_type |= ACTION_USER_HIDDEN_STR;
+                                       break;
+                               case '%':
+                                       /* literal '%' */
+                                       break;
+                               default:
+                                       action_type = ACTION_ERROR;
+                                       break;
+                               }
+                               p++;
+                       } else if (p[0] == '|') {
+                               if (p[1] == '\0')
+                                       action_type |= ACTION_PIPE_OUT;
+                       } else if (p[0] == '>') {
+                               if (p[1] == '\0')
+                                       action_type |= ACTION_INSERT;
+                       } else if (p[0] == '&') {
+                               if (p[1] == '\0')
+                                       action_type |= ACTION_ASYNC;
+                       } else if (p[0] == '}') {
+                               in_filtering_action = FALSE;
                        }
-                       p++;
-               } else if (p[0] == '|') {
-                       if (p[1] == '\0')
-                               action_type |= ACTION_PIPE_OUT;
-               } else if (p[0] == '>') {
-                       if (p[1] == '\0')
-                               action_type |= ACTION_INSERT;
-               } else if (p[0] == '&') {
-                       if (p[1] == '\0')
-                               action_type |= ACTION_ASYNC;
                }
-               p++;
+                       p++;
        }
 
        return action_type;
@@ -365,7 +371,7 @@ static gboolean parse_append_filename(GString *cmd, MsgInfo *msginfo)
        gchar *p, *q;
        gchar escape_ch[] = "\\ ";
 
-       g_return_val_if_fail(msginfo, FALSE);
+       cm_return_val_if_fail(msginfo, FALSE);
 
        filename = procmsg_get_message_file(msginfo);
 
@@ -570,12 +576,12 @@ static void compose_actions_execute(Compose *compose, guint action_nb, GtkWidget
        gchar *buf, *action;
        ActionType action_type;
 
-       g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
+       cm_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
 
        buf = (gchar *)g_slist_nth_data(prefs_common.actions_list, action_nb);
-       g_return_if_fail(buf != NULL);
+       cm_return_if_fail(buf != NULL);
        action = strstr(buf, ": ");
-       g_return_if_fail(action != NULL);
+       cm_return_if_fail(action != NULL);
 
        /* Point to the beginning of the command-line */
        action += 2;
@@ -638,12 +644,12 @@ static void message_actions_execute(MessageView *msgview, guint action_nb,
        guint body_pos = 0;
        ActionType action_type;
        
-       g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
+       cm_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
 
        buf = (gchar *)g_slist_nth_data(prefs_common.actions_list, action_nb);
 
-       g_return_if_fail(buf);
-       g_return_if_fail((action = strstr(buf, ": ")));
+       cm_return_if_fail(buf);
+       cm_return_if_fail((action = strstr(buf, ": ")));
 
        /* Point to the beginning of the command-line */
        action += 2;
@@ -751,7 +757,7 @@ static gboolean execute_actions(gchar *action, GSList *msg_list,
        GtkTextIter start_iter, end_iter;
        gboolean is_selection = FALSE;
 
-       g_return_val_if_fail(action && *action, FALSE);
+       cm_return_val_if_fail(action && *action, FALSE);
 
        action_type = action_get_type(action);
 
@@ -890,9 +896,10 @@ static gboolean execute_actions(gchar *action, GSList *msg_list,
                        child_info->callback = callback;
                        child_info->data = data;
                        child_info->tag_status = 
-                               gdk_input_add(child_info->chld_status,
+                               claws_input_add(child_info->chld_status,
                                              GDK_INPUT_READ,
-                                             catch_status, child_info);
+                                             catch_status, child_info,
+                                             FALSE);
                }
 
                create_io_dialog(children);
@@ -1051,10 +1058,10 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
        child_info->chld_err    = chld_err[0];
        child_info->chld_status = chld_status[0];
        child_info->tag_in      = -1;
-       child_info->tag_out     = gdk_input_add(chld_out[0], GDK_INPUT_READ,
-                                               catch_output, child_info);
-       child_info->tag_err     = gdk_input_add(chld_err[0], GDK_INPUT_READ,
-                                               catch_output, child_info);
+       child_info->tag_out     = claws_input_add(chld_out[0], GDK_INPUT_READ,
+                                               catch_output, child_info, FALSE);
+       child_info->tag_err     = claws_input_add(chld_err[0], GDK_INPUT_READ,
+                                               catch_output, child_info, FALSE);
 
        if (!(children->action_type &
              (ACTION_PIPE_IN | ACTION_PIPE_OUT | ACTION_INSERT)))
@@ -1137,9 +1144,9 @@ static void send_input(GtkWidget *w, gpointer data)
        Children *children = (Children *) data;
        ChildInfo *child_info = (ChildInfo *) children->list->data;
 
-       child_info->tag_in = gdk_input_add(child_info->chld_in,
+       child_info->tag_in = claws_input_add(child_info->chld_in,
                                           GDK_INPUT_WRITE,
-                                          catch_input, children);
+                                          catch_input, children, FALSE);
 }
 
 static gint delete_io_dialog_cb(GtkWidget *w, GdkEvent *e, gpointer data)
@@ -1180,11 +1187,11 @@ static void childinfo_close_pipes(ChildInfo *child_info)
         * them if necessary
         */
        if (child_info->tag_in > 0)
-               gdk_input_remove(child_info->tag_in);
+               g_source_remove(child_info->tag_in);
        if (child_info->tag_out > 0)
-               gdk_input_remove(child_info->tag_out);
+               g_source_remove(child_info->tag_out);
        if (child_info->tag_err > 0)
-               gdk_input_remove(child_info->tag_err);
+               g_source_remove(child_info->tag_err);
 
        if (child_info->chld_in >= 0)
                (void)close(child_info->chld_in);
@@ -1430,7 +1437,7 @@ static void catch_status(gpointer data, gint source, GdkInputCondition cond)
        gchar buf;
        gint c;
 
-       gdk_input_remove(child_info->tag_status);
+       g_source_remove(child_info->tag_status);
 
        c = read(source, &buf, 1);
        debug_print("Child returned %c\n", buf);
@@ -1504,7 +1511,7 @@ static void catch_input(gpointer data, gint source, GdkInputCondition cond)
        gtk_widget_set_sensitive(children->input_hbox, FALSE);
        gtk_widget_grab_focus(children->abort_btn);
 
-       gdk_input_remove(child_info->tag_in);
+       g_source_remove(child_info->tag_in);
        child_info->tag_in = -1;
 
        input = gtk_editable_get_chars(GTK_EDITABLE(children->input_entry),
@@ -1603,12 +1610,12 @@ static void catch_output(gpointer data, gint source, GdkInputCondition cond)
        }
        if (c == 0) {
                if (source == child_info->chld_out) {
-                       gdk_input_remove(child_info->tag_out);
+                       g_source_remove(child_info->tag_out);
                        child_info->tag_out = -1;
                        (void)close(child_info->chld_out);
                        child_info->chld_out = -1;
                } else {
-                       gdk_input_remove(child_info->tag_err);
+                       g_source_remove(child_info->tag_err);
                        child_info->tag_err = -1;
                        (void)close(child_info->chld_err);
                        child_info->chld_err = -1;