claws-mail/src/prefs_matcher.c

1758 lines
48 KiB
C
Raw Normal View History

2001-05-08 16:29:47 +02:00
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (C) 1999-2001 Hiroyuki Yamamoto
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "defs.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "intl.h"
#include "main.h"
#include "prefs_gtk.h"
2001-05-08 16:29:47 +02:00
#include "prefs_matcher.h"
#include "prefs_common.h"
#include "mainwindow.h"
#include "foldersel.h"
#include "manage_window.h"
#include "inc.h"
#include "matcher.h"
#include "utils.h"
#include "gtkutils.h"
#include "alertpanel.h"
#include "folder.h"
#include "description_window.h"
2001-05-08 16:29:47 +02:00
#include "matcher_parser.h"
#include "colorlabel.h"
/*!
*\brief UI data for matcher dialog
*/
2001-05-08 16:29:47 +02:00
static struct Matcher {
GtkWidget *window;
GtkWidget *ok_btn;
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
GtkWidget *predicate_combo;
2001-05-11 01:00:27 +02:00
GtkWidget *predicate_flag_combo;
2001-05-09 15:30:45 +02:00
GtkWidget *header_combo;
GtkWidget *criteria_list;
2001-05-11 01:00:27 +02:00
2001-05-09 15:30:45 +02:00
GtkWidget *predicate_list;
2001-05-11 01:00:27 +02:00
GtkWidget *predicate_label;
GtkWidget *predicate_flag_list;
2001-05-09 15:30:45 +02:00
GtkWidget *bool_op_list;
2001-05-08 16:29:47 +02:00
GtkWidget *header_entry;
GtkWidget *header_label;
GtkWidget *value_entry;
GtkWidget *value_label;
GtkWidget *case_chkbtn;
GtkWidget *regexp_chkbtn;
GtkWidget *color_optmenu;
2001-05-08 16:29:47 +02:00
2004-01-12 22:28:31 +01:00
GtkWidget *test_btn;
2001-05-08 16:29:47 +02:00
GtkWidget *cond_clist;
GtkWidget *criteria_table;
gint selected_criteria; /*!< selected criteria in combobox */
2001-05-08 16:29:47 +02:00
} matcher;
/*!
*\brief Conditions with a negate counterpart (like unread and ~unread)
* have the same CRITERIA_XXX id). I.e. both unread and ~unread
* have criteria id CRITERIA_UNREAD. This id is passed as the
* first parameter to #matcherprop_new and #matcherprop_unquote_new.
*
*\warning Currently the enum constants should have the same order as the
* #criteria_text
*/
2001-05-08 16:29:47 +02:00
enum {
CRITERIA_ALL = 0,
2001-05-11 01:00:27 +02:00
2001-05-08 16:29:47 +02:00
CRITERIA_SUBJECT = 1,
CRITERIA_FROM = 2,
CRITERIA_TO = 3,
CRITERIA_CC = 4,
CRITERIA_TO_OR_CC = 5,
CRITERIA_NEWSGROUPS = 6,
CRITERIA_INREPLYTO = 7,
2001-05-13 04:57:01 +02:00
CRITERIA_REFERENCES = 8,
CRITERIA_AGE_GREATER = 9,
CRITERIA_AGE_LOWER = 10,
CRITERIA_HEADER = 11,
CRITERIA_HEADERS_PART = 12,
CRITERIA_BODY_PART = 13,
CRITERIA_MESSAGE = 14,
CRITERIA_UNREAD = 15,
CRITERIA_NEW = 16,
CRITERIA_MARKED = 17,
CRITERIA_DELETED = 18,
CRITERIA_REPLIED = 19,
CRITERIA_FORWARDED = 20,
CRITERIA_LOCKED = 21,
CRITERIA_COLORLABEL = 22,
CRITERIA_IGNORE_THREAD = 23,
2001-05-13 04:57:01 +02:00
CRITERIA_SCORE_GREATER = 24,
CRITERIA_SCORE_LOWER = 25,
CRITERIA_SCORE_EQUAL = 26,
2004-01-12 22:28:31 +01:00
CRITERIA_TEST = 27,
CRITERIA_SIZE_GREATER = 28,
CRITERIA_SIZE_SMALLER = 29,
CRITERIA_SIZE_EQUAL = 30,
CRITERIA_PARTIAL = 31
2001-05-11 01:00:27 +02:00
};
/*!
*\brief Descriptive text for conditions
*/
static const gchar *criteria_text [] = {
N_("All messages"), N_("Subject"),
N_("From"), N_("To"), N_("Cc"), N_("To or Cc"),
N_("Newsgroups"), N_("In reply to"), N_("References"),
N_("Age greater than"), N_("Age lower than"),
N_("Header"), N_("Headers part"),
N_("Body part"), N_("Whole message"),
N_("Unread flag"), N_("New flag"),
N_("Marked flag"), N_("Deleted flag"),
N_("Replied flag"), N_("Forwarded flag"),
N_("Locked flag"),
N_("Color label"),
N_("Ignore thread"),
N_("Score greater than"), N_("Score lower than"),
N_("Score equal to"),
2004-01-12 22:28:31 +01:00
N_("Test"),
N_("Size greater than"),
N_("Size smaller than"),
N_("Size exactly")
};
/*!
*\brief Boolean / predicate constants
*
*\warning Same order as #bool_op_text!
*/
2001-05-11 01:00:27 +02:00
enum {
BOOL_OP_OR = 0,
BOOL_OP_AND = 1
2001-05-08 16:29:47 +02:00
};
/*!
*\brief Descriptive text in UI
*/
static const gchar *bool_op_text [] = {
2001-07-22 14:35:04 +02:00
N_("or"), N_("and")
2001-05-08 16:29:47 +02:00
};
/*!
*\brief Contains predicate
*
*\warning Same order as in #predicate_text
*/
2001-05-11 01:00:27 +02:00
enum {
PREDICATE_CONTAINS = 0,
PREDICATE_DOES_NOT_CONTAIN = 1
};
/*!
*\brief Descriptive text in UI for predicate
*/
static const gchar *predicate_text [] = {
2001-07-22 14:35:04 +02:00
N_("contains"), N_("does not contain")
2001-05-08 16:29:47 +02:00
};
/*!
*\brief Enabled predicate
*
*\warning Same order as in #predicate_flag_text
*/
2001-05-11 01:00:27 +02:00
enum {
PREDICATE_FLAG_ENABLED = 0,
PREDICATE_FLAG_DISABLED = 1
};
/*!
*\brief Descriptive text in UI for enabled flag
*/
static const gchar *predicate_flag_text [] = {
2001-07-22 14:35:04 +02:00
N_("yes"), N_("no")
2001-05-11 01:00:27 +02:00
};
/*!
*\brief Hooks
*/
static PrefsMatcherSignal *matchers_callback;
2001-05-08 16:29:47 +02:00
/* widget creating functions */
static void prefs_matcher_create (void);
static void prefs_matcher_set_dialog (MatcherList *matchers);
static gint prefs_matcher_clist_set_row (gint row, MatcherProp *prop);
2001-05-08 16:29:47 +02:00
/* callback functions */
static void prefs_matcher_register_cb (void);
static void prefs_matcher_substitute_cb (void);
static void prefs_matcher_delete_cb (void);
static void prefs_matcher_up (void);
static void prefs_matcher_down (void);
2001-05-09 15:30:45 +02:00
static void prefs_matcher_select (GtkCList *clist,
2001-05-08 16:29:47 +02:00
gint row,
gint column,
GdkEvent *event);
2004-01-12 22:28:31 +01:00
static gboolean prefs_matcher_key_pressed(GtkWidget *widget,
2001-05-08 16:29:47 +02:00
GdkEventKey *event,
gpointer data);
static void prefs_matcher_ok (void);
2002-12-27 01:21:23 +01:00
static void prefs_matcher_cancel (void);
static gint prefs_matcher_deleted (GtkWidget *widget, GdkEventAny *event,
gpointer data);
static void prefs_matcher_criteria_select (GtkList *list,
GtkWidget *widget,
gpointer user_data);
static MatcherList *prefs_matcher_get_list (void);
2002-12-27 01:21:23 +01:00
/*!
*\brief Find index of list selection
*
*\param list GTK list widget
*
*\return gint Selection index
*/
static gint get_sel_from_list(GtkList *list)
2002-12-27 01:21:23 +01:00
{
gint row = 0;
void * sel;
GList * child;
sel = list->selection->data;
for (child = list->children; child != NULL; child = g_list_next(child)) {
if (child->data == sel)
return row;
row ++;
}
return row;
}
2001-05-08 16:29:47 +02:00
/*!
*\brief Opens the matcher dialog with a list of conditions
*
*\param matchers List of conditions
*\param cb Callback
*
*/
2002-12-27 01:21:23 +01:00
void prefs_matcher_open(MatcherList *matchers, PrefsMatcherSignal *cb)
2001-05-08 16:29:47 +02:00
{
inc_lock();
2001-05-08 16:29:47 +02:00
if (!matcher.window) {
prefs_matcher_create();
}
manage_window_set_transient(GTK_WINDOW(matcher.window));
gtk_widget_grab_focus(matcher.ok_btn);
2001-05-08 16:29:47 +02:00
2001-05-11 01:00:27 +02:00
matchers_callback = cb;
prefs_matcher_set_dialog(matchers);
2001-05-08 16:29:47 +02:00
gtk_widget_show(matcher.window);
}
/*!
*\brief Create the matcher dialog
*/
2001-05-08 16:29:47 +02:00
static void prefs_matcher_create(void)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *ok_btn;
GtkWidget *cancel_btn;
2001-05-08 16:29:47 +02:00
GtkWidget *confirm_area;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *vbox3;
GtkWidget *criteria_table;
2001-05-08 16:29:47 +02:00
GtkWidget *hbox1;
GtkWidget *header_combo;
GtkWidget *header_entry;
GtkWidget *header_label;
GtkWidget *criteria_combo;
2001-05-09 15:30:45 +02:00
GtkWidget *criteria_list;
2001-05-08 16:29:47 +02:00
GtkWidget *criteria_label;
GtkWidget *value_label;
GtkWidget *value_entry;
GtkWidget *predicate_combo;
2001-05-09 15:30:45 +02:00
GtkWidget *predicate_list;
2001-05-11 01:00:27 +02:00
GtkWidget *predicate_flag_combo;
GtkWidget *predicate_flag_list;
2001-05-08 16:29:47 +02:00
GtkWidget *predicate_label;
GtkWidget *bool_op_combo;
2001-05-09 15:30:45 +02:00
GtkWidget *bool_op_list;
2001-05-08 16:29:47 +02:00
GtkWidget *bool_op_label;
GtkWidget *regexp_chkbtn;
GtkWidget *case_chkbtn;
GtkWidget *reg_hbox;
GtkWidget *btn_hbox;
GtkWidget *arrow;
GtkWidget *reg_btn;
GtkWidget *subst_btn;
GtkWidget *del_btn;
GtkWidget *cond_hbox;
GtkWidget *cond_scrolledwin;
GtkWidget *cond_clist;
GtkWidget *btn_vbox;
GtkWidget *up_btn;
GtkWidget *down_btn;
2004-01-12 22:28:31 +01:00
GtkWidget *test_btn;
GtkWidget *color_optmenu;
2001-05-08 16:29:47 +02:00
GList *combo_items;
gint i;
2002-02-08 11:07:11 +01:00
gchar *title[1];
2001-05-08 16:29:47 +02:00
2002-11-27 18:41:38 +01:00
debug_print("Creating matcher configuration window...\n");
2001-05-08 16:29:47 +02:00
2003-10-05 12:10:30 +02:00
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2002-12-27 01:21:23 +01:00
gtk_container_set_border_width(GTK_CONTAINER(window), 8);
gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
vbox = gtk_vbox_new(FALSE, 6);
gtk_widget_show(vbox);
gtk_container_add(GTK_CONTAINER(window), vbox);
2001-05-08 16:29:47 +02:00
gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
&cancel_btn, _("Cancel"), NULL, NULL);
2002-12-27 01:21:23 +01:00
gtk_widget_show(confirm_area);
gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
gtk_widget_grab_default(ok_btn);
gtk_window_set_title(GTK_WINDOW(window),
_("Condition configuration"));
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(prefs_matcher_deleted), NULL);
g_signal_connect(G_OBJECT(window), "key_press_event",
G_CALLBACK(prefs_matcher_key_pressed), NULL);
2002-12-27 01:21:23 +01:00
MANAGE_WINDOW_SIGNALS_CONNECT(window);
g_signal_connect(G_OBJECT(ok_btn), "clicked",
G_CALLBACK(prefs_matcher_ok), NULL);
g_signal_connect(G_OBJECT(cancel_btn), "clicked",
G_CALLBACK(prefs_matcher_cancel), NULL);
2002-12-27 01:21:23 +01:00
vbox1 = gtk_vbox_new(FALSE, VSPACING);
gtk_widget_show(vbox1);
gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
criteria_table = gtk_table_new(2, 4, FALSE);
gtk_widget_show(criteria_table);
gtk_box_pack_start(GTK_BOX(vbox1), criteria_table, FALSE, FALSE, 0);
gtk_table_set_row_spacings(GTK_TABLE(criteria_table), 8);
gtk_table_set_col_spacings(GTK_TABLE(criteria_table), 8);
2001-05-08 16:29:47 +02:00
/* criteria combo box */
2002-12-27 01:21:23 +01:00
criteria_label = gtk_label_new(_("Match type"));
gtk_widget_show(criteria_label);
gtk_misc_set_alignment(GTK_MISC(criteria_label), 0, 0.5);
gtk_table_attach(GTK_TABLE(criteria_table), criteria_label, 0, 1, 0, 1,
GTK_FILL, 0, 0, 0);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
criteria_combo = gtk_combo_new();
gtk_widget_show(criteria_combo);
2001-05-08 16:29:47 +02:00
combo_items = NULL;
2002-12-27 01:21:23 +01:00
for (i = 0; i < (gint) (sizeof(criteria_text) / sizeof(gchar *)); i++) {
2001-05-08 16:29:47 +02:00
combo_items = g_list_append(combo_items,
(gpointer) _(criteria_text[i]));
}
gtk_combo_set_popdown_strings(GTK_COMBO(criteria_combo), combo_items);
g_list_free(combo_items);
2002-12-27 01:21:23 +01:00
gtk_widget_set_usize(criteria_combo, 120, -1);
gtk_table_attach(GTK_TABLE(criteria_table), criteria_combo, 0, 1, 1, 2,
2001-05-08 16:29:47 +02:00
0, 0, 0, 0);
2001-05-09 15:30:45 +02:00
criteria_list = GTK_COMBO(criteria_combo)->list;
g_signal_connect(G_OBJECT(criteria_list), "select-child",
G_CALLBACK(prefs_matcher_criteria_select),
NULL);
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(criteria_combo)->entry),
FALSE);
2001-05-08 16:29:47 +02:00
/* header name */
2002-12-27 01:21:23 +01:00
header_label = gtk_label_new(_("Header name"));
gtk_widget_show(header_label);
gtk_misc_set_alignment(GTK_MISC(header_label), 0, 0.5);
gtk_table_attach(GTK_TABLE(criteria_table), header_label, 1, 2, 0, 1,
GTK_FILL, 0, 0, 0);
header_combo = gtk_combo_new();
gtk_widget_show(header_combo);
gtk_widget_set_usize(header_combo, 96, -1);
gtkut_combo_set_items(GTK_COMBO (header_combo),
"Subject", "From", "To", "Cc", "Reply-To",
"Sender", "X-ML-Name", "X-List", "X-Sequence",
"X-Mailer","X-BeenThere",
NULL);
gtk_table_attach(GTK_TABLE(criteria_table), header_combo, 1, 2, 1, 2,
0, 0, 0, 0);
header_entry = GTK_COMBO(header_combo)->entry;
gtk_entry_set_editable(GTK_ENTRY(header_entry), TRUE);
2001-05-08 16:29:47 +02:00
/* value */
2002-12-27 01:21:23 +01:00
value_label = gtk_label_new(_("Value"));
gtk_widget_show(value_label);
gtk_misc_set_alignment(GTK_MISC (value_label), 0, 0.5);
gtk_table_attach(GTK_TABLE(criteria_table), value_label, 2, 3, 0, 1,
GTK_FILL | GTK_SHRINK | GTK_EXPAND, 0, 0, 0);
value_entry = gtk_entry_new();
gtk_widget_show(value_entry);
gtk_widget_set_usize(value_entry, 200, -1);
gtk_table_attach(GTK_TABLE(criteria_table), value_entry, 2, 3, 1, 2,
GTK_FILL | GTK_SHRINK | GTK_EXPAND, 0, 0, 0);
2004-01-12 22:28:31 +01:00
test_btn = gtk_button_new_with_label(_("Info ..."));
gtk_widget_show(test_btn);
gtk_table_attach(GTK_TABLE (criteria_table), test_btn, 3, 4, 1, 2,
2002-12-27 01:21:23 +01:00
GTK_FILL | GTK_SHRINK | GTK_EXPAND, 0, 0, 0);
g_signal_connect(G_OBJECT (test_btn), "clicked",
G_CALLBACK(prefs_matcher_test_info),
NULL);
2001-05-08 16:29:47 +02:00
color_optmenu = gtk_option_menu_new();
gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu),
colorlabel_create_color_menu());
2001-05-08 16:29:47 +02:00
/* predicate */
2002-12-27 01:21:23 +01:00
vbox2 = gtk_vbox_new(FALSE, VSPACING);
gtk_widget_show(vbox2);
gtk_box_pack_start(GTK_BOX(vbox1), vbox2, FALSE, FALSE, 0);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
hbox1 = gtk_hbox_new(FALSE, 8);
gtk_widget_show(hbox1);
gtk_box_pack_start(GTK_BOX(vbox2), hbox1, FALSE, FALSE, 0);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
predicate_label = gtk_label_new(_("Predicate"));
gtk_widget_show(predicate_label);
gtk_box_pack_start(GTK_BOX(hbox1), predicate_label,
FALSE, FALSE, 0);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
predicate_combo = gtk_combo_new();
gtk_widget_show(predicate_combo);
gtk_widget_set_usize(predicate_combo, 120, -1);
2001-05-09 15:30:45 +02:00
predicate_list = GTK_COMBO(predicate_combo)->list;
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(predicate_combo)->entry),
FALSE);
2001-05-08 16:29:47 +02:00
combo_items = NULL;
2002-12-27 01:21:23 +01:00
for (i = 0; i < (gint) (sizeof(predicate_text) / sizeof(gchar *)); i++) {
2001-05-08 16:29:47 +02:00
combo_items = g_list_append(combo_items,
(gpointer) _(predicate_text[i]));
}
gtk_combo_set_popdown_strings(GTK_COMBO(predicate_combo), combo_items);
g_list_free(combo_items);
2002-12-27 01:21:23 +01:00
gtk_box_pack_start(GTK_BOX(hbox1), predicate_combo,
FALSE, FALSE, 0);
2001-05-08 16:29:47 +02:00
2001-05-11 01:00:27 +02:00
/* predicate flag */
2002-12-27 01:21:23 +01:00
predicate_flag_combo = gtk_combo_new();
gtk_widget_hide(predicate_flag_combo);
gtk_widget_set_usize(predicate_flag_combo, 120, -1);
2001-05-11 01:00:27 +02:00
predicate_flag_list = GTK_COMBO(predicate_flag_combo)->list;
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(predicate_flag_combo)->entry), FALSE);
combo_items = NULL;
2002-12-27 01:21:23 +01:00
for (i = 0; i < (gint) (sizeof(predicate_text) / sizeof(gchar *)); i++) {
2001-05-11 01:00:27 +02:00
combo_items = g_list_append(combo_items, (gpointer) _(predicate_flag_text[i]));
}
gtk_combo_set_popdown_strings(GTK_COMBO(predicate_flag_combo),
combo_items);
g_list_free(combo_items);
2002-12-27 01:21:23 +01:00
gtk_box_pack_start(GTK_BOX(hbox1), predicate_flag_combo,
FALSE, FALSE, 0);
2001-05-11 01:00:27 +02:00
2002-12-27 01:21:23 +01:00
vbox3 = gtk_vbox_new(FALSE, 0);
2001-05-08 16:29:47 +02:00
gtk_widget_show (vbox3);
2002-12-27 01:21:23 +01:00
gtk_box_pack_start(GTK_BOX(hbox1), vbox3, FALSE, FALSE, 0);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
PACK_CHECK_BUTTON(vbox3, case_chkbtn, _("Case sensitive"));
PACK_CHECK_BUTTON(vbox3, regexp_chkbtn, _("Use regexp"));
2001-05-08 16:29:47 +02:00
/* register / substitute / delete */
2002-12-27 01:21:23 +01:00
reg_hbox = gtk_hbox_new(FALSE, 4);
gtk_widget_show(reg_hbox);
gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
gtk_widget_show(arrow);
gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
gtk_widget_set_usize(arrow, -1, 16);
btn_hbox = gtk_hbox_new(TRUE, 4);
gtk_widget_show(btn_hbox);
gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
reg_btn = gtk_button_new_with_label(_("Add"));
gtk_widget_show(reg_btn);
gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
g_signal_connect(G_OBJECT(reg_btn), "clicked",
G_CALLBACK(prefs_matcher_register_cb), NULL);
2002-12-27 01:21:23 +01:00
subst_btn = gtk_button_new_with_label(_(" Replace "));
gtk_widget_show(subst_btn);
gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
g_signal_connect(G_OBJECT(subst_btn), "clicked",
G_CALLBACK(prefs_matcher_substitute_cb),
NULL);
2002-12-27 01:21:23 +01:00
del_btn = gtk_button_new_with_label(_("Delete"));
gtk_widget_show(del_btn);
gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
g_signal_connect(G_OBJECT(del_btn), "clicked",
G_CALLBACK(prefs_matcher_delete_cb), NULL);
2001-05-08 16:29:47 +02:00
/* boolean operation */
2002-12-27 01:21:23 +01:00
bool_op_label = gtk_label_new(_("Boolean Op"));
gtk_misc_set_alignment(GTK_MISC(value_label), 0, 0.5);
gtk_widget_show(bool_op_label);
gtk_box_pack_start(GTK_BOX(btn_hbox), bool_op_label,
FALSE, FALSE, 0);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
bool_op_combo = gtk_combo_new();
gtk_widget_show(bool_op_combo);
gtk_widget_set_usize(bool_op_combo, 50, -1);
2001-05-09 15:30:45 +02:00
bool_op_list = GTK_COMBO(bool_op_combo)->list;
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(bool_op_combo)->entry),
FALSE);
2001-05-08 16:29:47 +02:00
combo_items = NULL;
2002-12-27 01:21:23 +01:00
for (i = 0; i < (gint) (sizeof(bool_op_text) / sizeof(gchar *)); i++) {
2001-05-08 16:29:47 +02:00
combo_items = g_list_append(combo_items,
(gpointer) _(bool_op_text[i]));
}
gtk_combo_set_popdown_strings(GTK_COMBO(bool_op_combo), combo_items);
g_list_free(combo_items);
2002-12-27 01:21:23 +01:00
gtk_box_pack_start(GTK_BOX(btn_hbox), bool_op_combo,
FALSE, FALSE, 0);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
cond_hbox = gtk_hbox_new(FALSE, 8);
gtk_widget_show(cond_hbox);
gtk_box_pack_start(GTK_BOX(vbox1), cond_hbox, TRUE, TRUE, 0);
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
cond_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_show(cond_scrolledwin);
gtk_widget_set_usize(cond_scrolledwin, -1, 150);
gtk_box_pack_start(GTK_BOX(cond_hbox), cond_scrolledwin,
TRUE, TRUE, 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(cond_scrolledwin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
2001-05-08 16:29:47 +02:00
2002-11-27 18:41:38 +01:00
title[0] = _("Current condition rules");
2001-05-08 16:29:47 +02:00
cond_clist = gtk_clist_new_with_titles(1, title);
2002-12-27 01:21:23 +01:00
gtk_widget_show(cond_clist);
gtk_container_add(GTK_CONTAINER(cond_scrolledwin), cond_clist);
gtk_clist_set_column_width(GTK_CLIST(cond_clist), 0, 80);
gtk_clist_set_selection_mode(GTK_CLIST(cond_clist),
GTK_SELECTION_BROWSE);
GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(cond_clist)->column[0].button,
GTK_CAN_FOCUS);
g_signal_connect(G_OBJECT(cond_clist), "select_row",
G_CALLBACK(prefs_matcher_select), NULL);
2002-12-27 01:21:23 +01:00
btn_vbox = gtk_vbox_new(FALSE, 8);
gtk_widget_show(btn_vbox);
gtk_box_pack_start(GTK_BOX(cond_hbox), btn_vbox, FALSE, FALSE, 0);
up_btn = gtk_button_new_with_label(_("Up"));
gtk_widget_show(up_btn);
gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(up_btn), "clicked",
G_CALLBACK(prefs_matcher_up), NULL);
2002-12-27 01:21:23 +01:00
down_btn = gtk_button_new_with_label(_("Down"));
gtk_widget_show(down_btn);
gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(down_btn), "clicked",
G_CALLBACK(prefs_matcher_down), NULL);
2001-05-08 16:29:47 +02:00
gtk_widget_show_all(window);
matcher.window = window;
matcher.ok_btn = ok_btn;
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
matcher.criteria_list = criteria_list;
matcher.header_combo = header_combo;
2001-05-08 16:29:47 +02:00
matcher.header_entry = header_entry;
matcher.header_label = header_label;
matcher.value_entry = value_entry;
matcher.value_label = value_label;
matcher.predicate_label = predicate_label;
2001-05-09 15:30:45 +02:00
matcher.predicate_list = predicate_list;
matcher.predicate_combo = predicate_combo;
2001-05-11 01:00:27 +02:00
matcher.predicate_flag_list = predicate_flag_list;
matcher.predicate_flag_combo = predicate_flag_combo;
2001-05-08 16:29:47 +02:00
matcher.case_chkbtn = case_chkbtn;
matcher.regexp_chkbtn = regexp_chkbtn;
2001-05-09 15:30:45 +02:00
matcher.bool_op_list = bool_op_list;
2004-01-12 22:28:31 +01:00
matcher.test_btn = test_btn;
matcher.color_optmenu = color_optmenu;
matcher.criteria_table = criteria_table;
2001-05-08 16:29:47 +02:00
2002-12-27 01:21:23 +01:00
matcher.cond_clist = cond_clist;
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Set the contents of a row
*
*\param row Index of row to set
*\param prop Condition to set
*
*\return gint Row index \a prop has been added
*/
2002-12-27 01:21:23 +01:00
static gint prefs_matcher_clist_set_row(gint row, MatcherProp *prop)
2001-05-08 16:29:47 +02:00
{
2001-05-09 15:30:45 +02:00
GtkCList *clist = GTK_CLIST(matcher.cond_clist);
2002-12-27 01:21:23 +01:00
gchar *cond_str[1];
gchar *matcher_str;
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
if (prop == NULL) {
cond_str[0] = _("(New)");
return gtk_clist_append(clist, cond_str);
2001-05-08 16:29:47 +02:00
}
2001-05-09 15:30:45 +02:00
matcher_str = matcherprop_to_string(prop);
cond_str[0] = matcher_str;
if (row < 0)
row = gtk_clist_append(clist, cond_str);
else
gtk_clist_set_text(clist, row, 0, cond_str[0]);
g_free(matcher_str);
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
return row;
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Clears a condition in the list widget
*/
2001-05-09 15:30:45 +02:00
static void prefs_matcher_reset_condition(void)
2001-05-08 16:29:47 +02:00
{
2001-05-09 15:30:45 +02:00
gtk_list_select_item(GTK_LIST(matcher.criteria_list), 0);
gtk_list_select_item(GTK_LIST(matcher.predicate_list), 0);
gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), "");
gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), "");
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Update scrollbar
*/
static void prefs_matcher_update_hscrollbar(void)
{
gint optwidth = gtk_clist_optimal_column_width(GTK_CLIST(matcher.cond_clist), 0);
gtk_clist_set_column_width(GTK_CLIST(matcher.cond_clist), 0, optwidth);
}
/*!
*\brief Initializes dialog with a set of conditions
*
*\param matchers List of conditions
*/
2002-12-27 01:21:23 +01:00
static void prefs_matcher_set_dialog(MatcherList *matchers)
2001-05-08 16:29:47 +02:00
{
2001-05-09 15:30:45 +02:00
GtkCList *clist = GTK_CLIST(matcher.cond_clist);
2002-12-27 01:21:23 +01:00
GSList *cur;
gboolean bool_op = 1;
2001-05-08 16:29:47 +02:00
gtk_clist_freeze(clist);
gtk_clist_clear(clist);
2001-05-09 15:30:45 +02:00
prefs_matcher_clist_set_row(-1, NULL);
2001-05-11 01:00:27 +02:00
if (matchers != NULL) {
2002-12-27 01:21:23 +01:00
for (cur = matchers->matchers; cur != NULL;
2001-05-09 15:30:45 +02:00
cur = g_slist_next(cur)) {
2002-12-27 01:21:23 +01:00
MatcherProp *prop;
2001-05-09 15:30:45 +02:00
prop = (MatcherProp *) cur->data;
prefs_matcher_clist_set_row(-1, prop);
}
2001-05-08 16:29:47 +02:00
2001-05-11 01:00:27 +02:00
bool_op = matchers->bool_and;
2001-05-08 16:29:47 +02:00
}
prefs_matcher_update_hscrollbar();
2001-05-11 01:00:27 +02:00
2001-05-08 16:29:47 +02:00
gtk_clist_thaw(clist);
2001-05-09 15:30:45 +02:00
gtk_list_select_item(GTK_LIST(matcher.bool_op_list), bool_op);
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
prefs_matcher_reset_condition();
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Converts current conditions in list box in
* a matcher list used by the matcher.
*
*\return MatcherList * List of conditions.
*/
2002-12-27 01:21:23 +01:00
static MatcherList *prefs_matcher_get_list(void)
2001-05-08 16:29:47 +02:00
{
2002-12-27 01:21:23 +01:00
gchar *matcher_str;
MatcherProp *prop;
2001-05-09 15:30:45 +02:00
gint row = 1;
2001-05-11 01:00:27 +02:00
gboolean bool_and;
2002-12-27 01:21:23 +01:00
GSList *matcher_list;
MatcherList *matchers;
2001-05-08 16:29:47 +02:00
2001-05-11 01:00:27 +02:00
matcher_list = NULL;
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
while (gtk_clist_get_text(GTK_CLIST(matcher.cond_clist),
row, 0, &matcher_str)) {
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
if (strcmp(matcher_str, _("(New)")) != 0) {
/* tmp = matcher_str; */
prop = matcher_parser_get_prop(matcher_str);
2001-05-09 15:30:45 +02:00
if (prop == NULL)
2001-05-09 15:30:45 +02:00
break;
2001-05-11 01:00:27 +02:00
matcher_list = g_slist_append(matcher_list, prop);
2001-05-09 15:30:45 +02:00
}
row ++;
2001-05-08 16:29:47 +02:00
}
2001-05-11 01:00:27 +02:00
bool_and = get_sel_from_list(GTK_LIST(matcher.bool_op_list));
2001-05-08 16:29:47 +02:00
2001-05-11 01:00:27 +02:00
matchers = matcherlist_new(matcher_list, bool_and);
return matchers;
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Maps a keyword id (see #get_matchparser_tab_id) to a
* criteria type (see first parameter of #matcherprop_new
* or #matcherprop_unquote_new)
*
*\param matching_id Id returned by the matcher parser.
*
*\return gint One of the CRITERIA_xxx constants.
*/
2001-05-17 12:57:37 +02:00
static gint prefs_matcher_get_criteria_from_matching(gint matching_id)
{
switch(matching_id) {
case MATCHCRITERIA_ALL:
2001-05-17 12:57:37 +02:00
return CRITERIA_ALL;
case MATCHCRITERIA_NOT_UNREAD:
case MATCHCRITERIA_UNREAD:
2001-05-17 12:57:37 +02:00
return CRITERIA_UNREAD;
case MATCHCRITERIA_NOT_NEW:
case MATCHCRITERIA_NEW:
2001-05-17 12:57:37 +02:00
return CRITERIA_NEW;
case MATCHCRITERIA_NOT_MARKED:
case MATCHCRITERIA_MARKED:
2001-05-17 12:57:37 +02:00
return CRITERIA_MARKED;
case MATCHCRITERIA_NOT_DELETED:
case MATCHCRITERIA_DELETED:
2001-05-17 12:57:37 +02:00
return CRITERIA_DELETED;
case MATCHCRITERIA_NOT_REPLIED:
case MATCHCRITERIA_REPLIED:
2001-05-17 12:57:37 +02:00
return CRITERIA_REPLIED;
case MATCHCRITERIA_NOT_FORWARDED:
case MATCHCRITERIA_FORWARDED:
2001-05-17 12:57:37 +02:00
return CRITERIA_FORWARDED;
case MATCHCRITERIA_LOCKED:
case MATCHCRITERIA_NOT_LOCKED:
return CRITERIA_LOCKED;
case MATCHCRITERIA_PARTIAL:
case MATCHCRITERIA_NOT_PARTIAL:
return CRITERIA_PARTIAL;
case MATCHCRITERIA_COLORLABEL:
case MATCHCRITERIA_NOT_COLORLABEL:
return CRITERIA_COLORLABEL;
case MATCHCRITERIA_IGNORE_THREAD:
case MATCHCRITERIA_NOT_IGNORE_THREAD:
return CRITERIA_IGNORE_THREAD;
case MATCHCRITERIA_NOT_SUBJECT:
case MATCHCRITERIA_SUBJECT:
2001-05-17 12:57:37 +02:00
return CRITERIA_SUBJECT;
case MATCHCRITERIA_NOT_FROM:
case MATCHCRITERIA_FROM:
2001-05-17 12:57:37 +02:00
return CRITERIA_FROM;
case MATCHCRITERIA_NOT_TO:
case MATCHCRITERIA_TO:
2001-05-17 12:57:37 +02:00
return CRITERIA_TO;
case MATCHCRITERIA_NOT_CC:
case MATCHCRITERIA_CC:
2001-05-17 12:57:37 +02:00
return CRITERIA_CC;
case MATCHCRITERIA_NOT_NEWSGROUPS:
case MATCHCRITERIA_NEWSGROUPS:
2001-05-17 12:57:37 +02:00
return CRITERIA_NEWSGROUPS;
case MATCHCRITERIA_NOT_INREPLYTO:
case MATCHCRITERIA_INREPLYTO:
2001-05-17 12:57:37 +02:00
return CRITERIA_INREPLYTO;
case MATCHCRITERIA_NOT_REFERENCES:
case MATCHCRITERIA_REFERENCES:
2001-05-17 12:57:37 +02:00
return CRITERIA_REFERENCES;
case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
case MATCHCRITERIA_TO_OR_CC:
2001-05-17 12:57:37 +02:00
return CRITERIA_TO_OR_CC;
case MATCHCRITERIA_NOT_BODY_PART:
case MATCHCRITERIA_BODY_PART:
2001-05-17 12:57:37 +02:00
return CRITERIA_BODY_PART;
case MATCHCRITERIA_NOT_MESSAGE:
case MATCHCRITERIA_MESSAGE:
2001-05-17 12:57:37 +02:00
return CRITERIA_MESSAGE;
break;
case MATCHCRITERIA_NOT_HEADERS_PART:
case MATCHCRITERIA_HEADERS_PART:
2001-05-17 12:57:37 +02:00
return CRITERIA_HEADERS_PART;
case MATCHCRITERIA_NOT_HEADER:
case MATCHCRITERIA_HEADER:
2001-05-17 12:57:37 +02:00
return CRITERIA_HEADER;
case MATCHCRITERIA_AGE_GREATER:
2001-05-17 12:57:37 +02:00
return CRITERIA_AGE_GREATER;
case MATCHCRITERIA_AGE_LOWER:
2001-05-17 12:57:37 +02:00
return CRITERIA_AGE_LOWER;
case MATCHCRITERIA_SCORE_GREATER:
2001-05-17 12:57:37 +02:00
return CRITERIA_SCORE_GREATER;
case MATCHCRITERIA_SCORE_LOWER:
2001-05-17 12:57:37 +02:00
return CRITERIA_SCORE_LOWER;
case MATCHCRITERIA_SCORE_EQUAL:
2001-09-18 13:02:34 +02:00
return CRITERIA_SCORE_EQUAL;
2004-01-12 22:28:31 +01:00
case MATCHCRITERIA_NOT_TEST:
case MATCHCRITERIA_TEST:
return CRITERIA_TEST;
case MATCHCRITERIA_SIZE_GREATER:
return CRITERIA_SIZE_GREATER;
case MATCHCRITERIA_SIZE_SMALLER:
return CRITERIA_SIZE_SMALLER;
case MATCHCRITERIA_SIZE_EQUAL:
return CRITERIA_SIZE_EQUAL;
2001-05-17 12:57:37 +02:00
default:
return -1;
}
}
/*!
*\brief Returns the matcher keyword id from a criteria id
*
*\param criteria_id Criteria id (should not be the negate
* one)
*
*\return gint A matcher keyword id. See #get_matchparser_tab_id.
*/
2001-05-09 15:30:45 +02:00
static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
2001-05-08 16:29:47 +02:00
{
switch (criteria_id) {
case CRITERIA_ALL:
return MATCHCRITERIA_ALL;
2001-05-11 01:00:27 +02:00
case CRITERIA_UNREAD:
return MATCHCRITERIA_UNREAD;
2001-05-11 01:00:27 +02:00
case CRITERIA_NEW:
return MATCHCRITERIA_NEW;
2001-05-11 01:00:27 +02:00
case CRITERIA_MARKED:
return MATCHCRITERIA_MARKED;
2001-05-11 01:00:27 +02:00
case CRITERIA_DELETED:
return MATCHCRITERIA_DELETED;
2001-05-11 01:00:27 +02:00
case CRITERIA_REPLIED:
return MATCHCRITERIA_REPLIED;
2001-05-11 01:00:27 +02:00
case CRITERIA_FORWARDED:
return MATCHCRITERIA_FORWARDED;
case CRITERIA_LOCKED:
return MATCHCRITERIA_LOCKED;
case CRITERIA_PARTIAL:
return MATCHCRITERIA_PARTIAL;
case CRITERIA_COLORLABEL:
return MATCHCRITERIA_COLORLABEL;
case CRITERIA_IGNORE_THREAD:
return MATCHCRITERIA_IGNORE_THREAD;
2001-05-08 16:29:47 +02:00
case CRITERIA_SUBJECT:
return MATCHCRITERIA_SUBJECT;
2001-05-08 16:29:47 +02:00
case CRITERIA_FROM:
return MATCHCRITERIA_FROM;
2001-05-08 16:29:47 +02:00
case CRITERIA_TO:
return MATCHCRITERIA_TO;
2001-05-08 16:29:47 +02:00
case CRITERIA_CC:
return MATCHCRITERIA_CC;
2001-05-08 16:29:47 +02:00
case CRITERIA_TO_OR_CC:
return MATCHCRITERIA_TO_OR_CC;
2001-05-08 16:29:47 +02:00
case CRITERIA_NEWSGROUPS:
return MATCHCRITERIA_NEWSGROUPS;
case CRITERIA_INREPLYTO:
return MATCHCRITERIA_INREPLYTO;
2001-05-13 04:57:01 +02:00
case CRITERIA_REFERENCES:
return MATCHCRITERIA_REFERENCES;
2001-05-08 16:29:47 +02:00
case CRITERIA_AGE_GREATER:
return MATCHCRITERIA_AGE_GREATER;
2001-05-08 16:29:47 +02:00
case CRITERIA_AGE_LOWER:
return MATCHCRITERIA_AGE_LOWER;
2001-05-13 04:57:01 +02:00
case CRITERIA_SCORE_GREATER:
return MATCHCRITERIA_SCORE_GREATER;
2001-05-13 04:57:01 +02:00
case CRITERIA_SCORE_LOWER:
return MATCHCRITERIA_SCORE_LOWER;
2001-09-18 13:02:34 +02:00
case CRITERIA_SCORE_EQUAL:
return MATCHCRITERIA_SCORE_EQUAL;
2001-05-08 16:29:47 +02:00
case CRITERIA_HEADER:
return MATCHCRITERIA_HEADER;
2001-05-08 16:29:47 +02:00
case CRITERIA_HEADERS_PART:
return MATCHCRITERIA_HEADERS_PART;
2001-05-08 16:29:47 +02:00
case CRITERIA_BODY_PART:
return MATCHCRITERIA_BODY_PART;
2001-05-08 16:29:47 +02:00
case CRITERIA_MESSAGE:
return MATCHCRITERIA_MESSAGE;
2004-01-12 22:28:31 +01:00
case CRITERIA_TEST:
return MATCHCRITERIA_TEST;
case CRITERIA_SIZE_GREATER:
return MATCHCRITERIA_SIZE_GREATER;
case CRITERIA_SIZE_SMALLER:
return MATCHCRITERIA_SIZE_SMALLER;
case CRITERIA_SIZE_EQUAL:
return MATCHCRITERIA_SIZE_EQUAL;
2001-05-08 16:29:47 +02:00
default:
return -1;
}
}
/*!
*\brief Returns the negate matcher keyword id from a matcher keyword
* id.
*
*\param matcher_criteria Matcher keyword id.
*
*\return gint A matcher keyword id. See #get_matchparser_tab_id.
*/
2001-05-08 16:29:47 +02:00
static gint prefs_matcher_not_criteria(gint matcher_criteria)
{
switch(matcher_criteria) {
case MATCHCRITERIA_UNREAD:
return MATCHCRITERIA_NOT_UNREAD;
case MATCHCRITERIA_NEW:
return MATCHCRITERIA_NOT_NEW;
case MATCHCRITERIA_MARKED:
return MATCHCRITERIA_NOT_MARKED;
case MATCHCRITERIA_DELETED:
return MATCHCRITERIA_NOT_DELETED;
case MATCHCRITERIA_REPLIED:
return MATCHCRITERIA_NOT_REPLIED;
case MATCHCRITERIA_FORWARDED:
return MATCHCRITERIA_NOT_FORWARDED;
case MATCHCRITERIA_LOCKED:
return MATCHCRITERIA_NOT_LOCKED;
case MATCHCRITERIA_PARTIAL:
return MATCHCRITERIA_NOT_PARTIAL;
case MATCHCRITERIA_COLORLABEL:
return MATCHCRITERIA_NOT_COLORLABEL;
case MATCHCRITERIA_IGNORE_THREAD:
return MATCHCRITERIA_NOT_IGNORE_THREAD;
case MATCHCRITERIA_SUBJECT:
return MATCHCRITERIA_NOT_SUBJECT;
case MATCHCRITERIA_FROM:
return MATCHCRITERIA_NOT_FROM;
case MATCHCRITERIA_TO:
return MATCHCRITERIA_NOT_TO;
case MATCHCRITERIA_CC:
return MATCHCRITERIA_NOT_CC;
case MATCHCRITERIA_TO_OR_CC:
return MATCHCRITERIA_NOT_TO_AND_NOT_CC;
case MATCHCRITERIA_NEWSGROUPS:
return MATCHCRITERIA_NOT_NEWSGROUPS;
case MATCHCRITERIA_INREPLYTO:
return MATCHCRITERIA_NOT_INREPLYTO;
case MATCHCRITERIA_REFERENCES:
return MATCHCRITERIA_NOT_REFERENCES;
case MATCHCRITERIA_HEADER:
return MATCHCRITERIA_NOT_HEADER;
case MATCHCRITERIA_HEADERS_PART:
return MATCHCRITERIA_NOT_HEADERS_PART;
case MATCHCRITERIA_MESSAGE:
return MATCHCRITERIA_NOT_MESSAGE;
2004-01-12 22:28:31 +01:00
case MATCHCRITERIA_TEST:
return MATCHCRITERIA_NOT_TEST;
case MATCHCRITERIA_BODY_PART:
return MATCHCRITERIA_NOT_BODY_PART;
2001-05-08 16:29:47 +02:00
default:
return matcher_criteria;
}
}
/*!
*\brief Converts the text in the selected row to a
* matcher structure
*
*\return MatcherProp * Newly allocated matcher structure.
*/
static MatcherProp *prefs_matcher_dialog_to_matcher(void)
2001-05-08 16:29:47 +02:00
{
MatcherProp *matcherprop;
2001-05-08 16:29:47 +02:00
gint criteria;
gint matchtype;
gint value_pred;
2001-05-11 01:00:27 +02:00
gint value_pred_flag;
2001-05-08 16:29:47 +02:00
gint value_criteria;
gboolean use_regexp;
gboolean case_sensitive;
2003-10-05 12:10:30 +02:00
const gchar *header;
const gchar *expr;
2001-05-13 04:57:01 +02:00
gint value;
2003-10-05 12:10:30 +02:00
const gchar *value_str;
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
value_criteria = get_sel_from_list(GTK_LIST(matcher.criteria_list));
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
criteria = prefs_matcher_get_matching_from_criteria(value_criteria);
value_pred = get_sel_from_list(GTK_LIST(matcher.predicate_list));
2001-05-11 01:00:27 +02:00
value_pred_flag = get_sel_from_list(GTK_LIST(matcher.predicate_flag_list));
2001-05-08 16:29:47 +02:00
use_regexp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn));
case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn));
2001-05-11 01:00:27 +02:00
switch (value_criteria) {
case CRITERIA_UNREAD:
case CRITERIA_NEW:
case CRITERIA_MARKED:
case CRITERIA_DELETED:
case CRITERIA_REPLIED:
case CRITERIA_FORWARDED:
case CRITERIA_LOCKED:
case CRITERIA_PARTIAL:
2004-01-12 22:28:31 +01:00
case CRITERIA_TEST:
case CRITERIA_COLORLABEL:
case CRITERIA_IGNORE_THREAD:
2001-05-11 01:00:27 +02:00
if (value_pred_flag == PREDICATE_FLAG_DISABLED)
criteria = prefs_matcher_not_criteria(criteria);
break;
case CRITERIA_SUBJECT:
case CRITERIA_FROM:
case CRITERIA_TO:
case CRITERIA_CC:
case CRITERIA_TO_OR_CC:
case CRITERIA_NEWSGROUPS:
case CRITERIA_INREPLYTO:
2001-05-13 04:57:01 +02:00
case CRITERIA_REFERENCES:
2001-05-11 01:00:27 +02:00
case CRITERIA_HEADERS_PART:
case CRITERIA_BODY_PART:
case CRITERIA_MESSAGE:
case CRITERIA_AGE_GREATER:
case CRITERIA_AGE_LOWER:
case CRITERIA_HEADER:
if (value_pred == PREDICATE_DOES_NOT_CONTAIN)
criteria = prefs_matcher_not_criteria(criteria);
break;
}
2001-05-08 16:29:47 +02:00
if (use_regexp) {
if (case_sensitive)
matchtype = MATCHTYPE_REGEXP;
2001-05-08 16:29:47 +02:00
else
matchtype = MATCHTYPE_REGEXPCASE;
2001-05-08 16:29:47 +02:00
}
else {
if (case_sensitive)
matchtype = MATCHTYPE_MATCH;
2001-05-08 16:29:47 +02:00
else
matchtype = MATCHTYPE_MATCHCASE;
2001-05-08 16:29:47 +02:00
}
header = NULL;
expr = NULL;
2001-05-13 04:57:01 +02:00
value = 0;
2001-05-08 16:29:47 +02:00
switch (value_criteria) {
case CRITERIA_ALL:
2001-05-11 01:00:27 +02:00
case CRITERIA_UNREAD:
case CRITERIA_NEW:
case CRITERIA_MARKED:
case CRITERIA_DELETED:
case CRITERIA_REPLIED:
case CRITERIA_FORWARDED:
case CRITERIA_LOCKED:
case CRITERIA_PARTIAL:
case CRITERIA_IGNORE_THREAD:
2001-05-08 16:29:47 +02:00
break;
case CRITERIA_SUBJECT:
case CRITERIA_FROM:
case CRITERIA_TO:
case CRITERIA_CC:
case CRITERIA_TO_OR_CC:
case CRITERIA_NEWSGROUPS:
case CRITERIA_INREPLYTO:
2001-05-13 04:57:01 +02:00
case CRITERIA_REFERENCES:
2001-05-08 16:29:47 +02:00
case CRITERIA_HEADERS_PART:
case CRITERIA_BODY_PART:
case CRITERIA_MESSAGE:
2004-01-12 22:28:31 +01:00
case CRITERIA_TEST:
2001-05-08 16:29:47 +02:00
expr = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
break;
case CRITERIA_AGE_GREATER:
case CRITERIA_AGE_LOWER:
2001-05-13 04:57:01 +02:00
case CRITERIA_SCORE_GREATER:
case CRITERIA_SCORE_LOWER:
2001-09-18 13:02:34 +02:00
case CRITERIA_SCORE_EQUAL:
case CRITERIA_SIZE_GREATER:
case CRITERIA_SIZE_SMALLER:
case CRITERIA_SIZE_EQUAL:
2001-05-13 04:57:01 +02:00
value_str = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
2001-05-09 15:30:45 +02:00
2001-05-13 04:57:01 +02:00
if (*value_str == '\0') {
alertpanel_error(_("Value is not set."));
2001-05-09 15:30:45 +02:00
return NULL;
}
2001-05-13 04:57:01 +02:00
value = atoi(value_str);
2001-05-09 15:30:45 +02:00
2001-05-08 16:29:47 +02:00
break;
case CRITERIA_COLORLABEL:
value = colorlabel_get_color_menu_active_item
(gtk_option_menu_get_menu(GTK_OPTION_MENU
(matcher.color_optmenu)));
break;
2001-05-08 16:29:47 +02:00
case CRITERIA_HEADER:
2001-05-09 15:30:45 +02:00
2001-05-08 16:29:47 +02:00
header = gtk_entry_get_text(GTK_ENTRY(matcher.header_entry));
expr = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
2001-05-09 15:30:45 +02:00
if (*header == '\0') {
alertpanel_error(_("Header name is not set."));
return NULL;
}
2001-05-08 16:29:47 +02:00
break;
}
matcherprop = matcherprop_new(criteria, header, matchtype,
expr, value);
2001-05-11 01:00:27 +02:00
2001-05-08 16:29:47 +02:00
return matcherprop;
}
/*!
*\brief Signal handler for register button
*/
2001-05-08 16:29:47 +02:00
static void prefs_matcher_register_cb(void)
{
MatcherProp *matcherprop;
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
matcherprop = prefs_matcher_dialog_to_matcher();
if (matcherprop == NULL)
return;
prefs_matcher_clist_set_row(-1, matcherprop);
2001-05-08 16:29:47 +02:00
matcherprop_free(matcherprop);
2001-05-09 15:30:45 +02:00
prefs_matcher_reset_condition();
prefs_matcher_update_hscrollbar();
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Signal handler for substitute button
*/
2001-05-08 16:29:47 +02:00
static void prefs_matcher_substitute_cb(void)
{
2001-05-09 15:30:45 +02:00
GtkCList *clist = GTK_CLIST(matcher.cond_clist);
2001-05-08 16:29:47 +02:00
gint row;
MatcherProp *matcherprop;
2001-05-08 16:29:47 +02:00
if (!clist->selection) return;
2001-05-08 16:29:47 +02:00
row = GPOINTER_TO_INT(clist->selection->data);
2001-05-09 15:30:45 +02:00
if (row == 0)
return;
matcherprop = prefs_matcher_dialog_to_matcher();
if (matcherprop == NULL)
return;
prefs_matcher_clist_set_row(row, matcherprop);
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
matcherprop_free(matcherprop);
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
prefs_matcher_reset_condition();
prefs_matcher_update_hscrollbar();
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Signal handler for delete button
*/
2001-05-08 16:29:47 +02:00
static void prefs_matcher_delete_cb(void)
{
2001-05-09 15:30:45 +02:00
GtkCList *clist = GTK_CLIST(matcher.cond_clist);
2001-05-08 16:29:47 +02:00
gint row;
if (!clist->selection) return;
row = GPOINTER_TO_INT(clist->selection->data);
2001-05-09 15:30:45 +02:00
if (row == 0)
2001-05-08 16:29:47 +02:00
return;
gtk_clist_remove(clist, row);
2003-02-27 21:43:39 +01:00
prefs_matcher_reset_condition();
prefs_matcher_update_hscrollbar();
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Signal handler for 'move up' button
*/
2001-05-08 16:29:47 +02:00
static void prefs_matcher_up(void)
{
2001-05-09 15:30:45 +02:00
GtkCList *clist = GTK_CLIST(matcher.cond_clist);
2001-05-08 16:29:47 +02:00
gint row;
if (!clist->selection) return;
row = GPOINTER_TO_INT(clist->selection->data);
if (row > 1) {
2001-05-08 16:29:47 +02:00
gtk_clist_row_move(clist, row, row - 1);
if (gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL)
gtk_clist_moveto(clist, row - 1, 0, 0, 0);
}
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Signal handler for 'move down' button
*/
2001-05-08 16:29:47 +02:00
static void prefs_matcher_down(void)
{
2001-05-09 15:30:45 +02:00
GtkCList *clist = GTK_CLIST(matcher.cond_clist);
2001-05-08 16:29:47 +02:00
gint row;
if (!clist->selection) return;
row = GPOINTER_TO_INT(clist->selection->data);
if (row >= 1 && row < clist->rows - 1) {
2001-05-08 16:29:47 +02:00
gtk_clist_row_move(clist, row, row + 1);
if (gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL)
gtk_clist_moveto(clist, row + 1, 0, 1, 0);
}
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Signal handler for select row.
*
*\param clist List widget
*\param row Selected row
*\param column Selected column
*\param event Event information
*/
2001-05-09 15:30:45 +02:00
static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
GdkEvent *event)
2001-05-08 16:29:47 +02:00
{
2002-12-27 01:21:23 +01:00
gchar *matcher_str;
MatcherProp *prop;
2001-05-09 15:30:45 +02:00
gboolean negative_cond;
2001-05-17 12:57:37 +02:00
gint criteria;
2001-05-09 15:30:45 +02:00
if (!gtk_clist_get_text(GTK_CLIST(matcher.cond_clist),
row, 0, &matcher_str))
return;
negative_cond = FALSE;
if (row == 0) {
prefs_matcher_reset_condition();
return;
}
prop = matcher_parser_get_prop(matcher_str);
if (prop == NULL)
2001-05-09 15:30:45 +02:00
return;
2001-05-17 12:57:37 +02:00
criteria = prefs_matcher_get_criteria_from_matching(prop->criteria);
if (criteria != -1)
2001-05-09 15:30:45 +02:00
gtk_list_select_item(GTK_LIST(matcher.criteria_list),
2001-05-17 12:57:37 +02:00
criteria);
2001-05-09 15:30:45 +02:00
2001-05-17 12:57:37 +02:00
switch(prop->criteria) {
case MATCHCRITERIA_NOT_UNREAD:
case MATCHCRITERIA_NOT_NEW:
case MATCHCRITERIA_NOT_MARKED:
case MATCHCRITERIA_NOT_DELETED:
case MATCHCRITERIA_NOT_REPLIED:
case MATCHCRITERIA_NOT_FORWARDED:
case MATCHCRITERIA_NOT_LOCKED:
case MATCHCRITERIA_NOT_PARTIAL:
case MATCHCRITERIA_NOT_COLORLABEL:
case MATCHCRITERIA_NOT_IGNORE_THREAD:
case MATCHCRITERIA_NOT_SUBJECT:
case MATCHCRITERIA_NOT_FROM:
case MATCHCRITERIA_NOT_TO:
case MATCHCRITERIA_NOT_CC:
case MATCHCRITERIA_NOT_NEWSGROUPS:
case MATCHCRITERIA_NOT_INREPLYTO:
case MATCHCRITERIA_NOT_REFERENCES:
case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
case MATCHCRITERIA_NOT_BODY_PART:
case MATCHCRITERIA_NOT_MESSAGE:
case MATCHCRITERIA_NOT_HEADERS_PART:
case MATCHCRITERIA_NOT_HEADER:
2001-05-09 15:30:45 +02:00
negative_cond = TRUE;
2001-05-13 04:57:01 +02:00
break;
2001-05-09 15:30:45 +02:00
}
switch(prop->criteria) {
case MATCHCRITERIA_ALL:
2001-05-09 15:30:45 +02:00
break;
case MATCHCRITERIA_NOT_SUBJECT:
case MATCHCRITERIA_NOT_FROM:
case MATCHCRITERIA_NOT_TO:
case MATCHCRITERIA_NOT_CC:
case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
case MATCHCRITERIA_NOT_NEWSGROUPS:
case MATCHCRITERIA_NOT_INREPLYTO:
case MATCHCRITERIA_NOT_REFERENCES:
case MATCHCRITERIA_NOT_HEADERS_PART:
case MATCHCRITERIA_NOT_BODY_PART:
case MATCHCRITERIA_NOT_MESSAGE:
case MATCHCRITERIA_SUBJECT:
case MATCHCRITERIA_FROM:
case MATCHCRITERIA_TO:
case MATCHCRITERIA_CC:
case MATCHCRITERIA_TO_OR_CC:
case MATCHCRITERIA_NEWSGROUPS:
case MATCHCRITERIA_INREPLYTO:
case MATCHCRITERIA_REFERENCES:
case MATCHCRITERIA_HEADERS_PART:
case MATCHCRITERIA_BODY_PART:
case MATCHCRITERIA_MESSAGE:
2004-01-12 22:28:31 +01:00
case MATCHCRITERIA_TEST:
2001-05-09 15:30:45 +02:00
gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), prop->expr);
break;
case MATCHCRITERIA_AGE_GREATER:
case MATCHCRITERIA_AGE_LOWER:
case MATCHCRITERIA_SCORE_GREATER:
case MATCHCRITERIA_SCORE_LOWER:
case MATCHCRITERIA_SCORE_EQUAL:
case MATCHCRITERIA_SIZE_GREATER:
case MATCHCRITERIA_SIZE_SMALLER:
case MATCHCRITERIA_SIZE_EQUAL:
2001-05-13 04:57:01 +02:00
gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), itos(prop->value));
2001-05-09 15:30:45 +02:00
break;
case MATCHCRITERIA_NOT_COLORLABEL:
case MATCHCRITERIA_COLORLABEL:
gtk_option_menu_set_history(GTK_OPTION_MENU(matcher.color_optmenu),
prop->value);
break;
case MATCHCRITERIA_NOT_HEADER:
case MATCHCRITERIA_HEADER:
2001-05-09 15:30:45 +02:00
gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), prop->header);
gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), prop->expr);
break;
}
if (negative_cond)
gtk_list_select_item(GTK_LIST(matcher.predicate_list), 1);
2001-05-08 16:29:47 +02:00
else
2001-05-09 15:30:45 +02:00
gtk_list_select_item(GTK_LIST(matcher.predicate_list), 0);
2001-05-08 16:29:47 +02:00
2001-05-09 15:30:45 +02:00
switch(prop->matchtype) {
case MATCHTYPE_MATCH:
2001-05-09 15:30:45 +02:00
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn), FALSE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn), TRUE);
break;
2001-05-08 16:29:47 +02:00
case MATCHTYPE_MATCHCASE:
2001-05-09 15:30:45 +02:00
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn), FALSE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn), FALSE);
break;
case MATCHTYPE_REGEXP:
2001-05-09 15:30:45 +02:00
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn), TRUE);
break;
2001-05-08 16:29:47 +02:00
case MATCHTYPE_REGEXPCASE:
2001-05-09 15:30:45 +02:00
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn), FALSE);
break;
}
}
2001-05-08 16:29:47 +02:00
/*!
*\brief Helper function that allows us to replace the 'Value' entry box
* by another widget.
*
*\param old_widget Widget that needs to be removed.
*\param new_widget Replacement widget
*/
static void prefs_matcher_set_value_widget(GtkWidget *old_widget,
GtkWidget *new_widget)
{
/* TODO: find out why the following spews harmless "parent errors" */
/* NOTE: we first need to bump up the refcount of the old_widget,
* because the gtkut_container_remove() will otherwise destroy it */
gtk_widget_ref(old_widget);
gtkut_container_remove(GTK_CONTAINER(matcher.criteria_table), old_widget);
gtk_widget_show(new_widget);
gtk_widget_set_usize(new_widget, 200, -1);
gtk_table_attach(GTK_TABLE(matcher.criteria_table), new_widget,
2, 3, 1, 2,
GTK_FILL | GTK_SHRINK | GTK_EXPAND,
0, 0, 0);
}
/*!
*\brief Change widgets depending on the selected condition
*
*\param list List widget
*\param widget Not used
*\param user_data Not used
*/
2001-05-09 15:30:45 +02:00
static void prefs_matcher_criteria_select(GtkList *list,
GtkWidget *widget,
2001-05-08 16:29:47 +02:00
gpointer user_data)
{
gint value, old_value;
2001-05-08 16:29:47 +02:00
old_value = matcher.selected_criteria;
matcher.selected_criteria = value = get_sel_from_list
(GTK_LIST(matcher.criteria_list));
/* CLAWS: the value widget is currently either the color label combo box,
* or a GtkEntry, so kiss for now */
if (matcher.selected_criteria == CRITERIA_COLORLABEL) {
prefs_matcher_set_value_widget(matcher.value_entry,
matcher.color_optmenu);
} else if (old_value == CRITERIA_COLORLABEL) {
prefs_matcher_set_value_widget(matcher.color_optmenu,
matcher.value_entry);
}
2001-05-08 16:29:47 +02:00
switch (value) {
case CRITERIA_ALL:
2001-05-09 15:30:45 +02:00
gtk_widget_set_sensitive(matcher.header_combo, FALSE);
2001-05-08 16:29:47 +02:00
gtk_widget_set_sensitive(matcher.header_label, FALSE);
gtk_widget_set_sensitive(matcher.value_label, FALSE);
gtk_widget_set_sensitive(matcher.value_entry, FALSE);
gtk_widget_set_sensitive(matcher.predicate_label, FALSE);
2001-05-09 15:30:45 +02:00
gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
2001-05-11 01:00:27 +02:00
gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
gtk_widget_hide(matcher.predicate_combo);
gtk_widget_show(matcher.predicate_flag_combo);
gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
2004-01-12 22:28:31 +01:00
gtk_widget_set_sensitive(matcher.test_btn, FALSE);
2001-05-11 01:00:27 +02:00
break;
case CRITERIA_UNREAD:
case CRITERIA_NEW:
case CRITERIA_MARKED:
case CRITERIA_DELETED:
case CRITERIA_REPLIED:
case CRITERIA_FORWARDED:
case CRITERIA_LOCKED:
case CRITERIA_PARTIAL:
case CRITERIA_IGNORE_THREAD:
2001-05-11 01:00:27 +02:00
gtk_widget_set_sensitive(matcher.header_combo, FALSE);
gtk_widget_set_sensitive(matcher.header_label, FALSE);
gtk_widget_set_sensitive(matcher.value_label, FALSE);
gtk_widget_set_sensitive(matcher.value_entry, FALSE);
gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
gtk_widget_set_sensitive(matcher.predicate_flag_combo, TRUE);
gtk_widget_hide(matcher.predicate_combo);
gtk_widget_show(matcher.predicate_flag_combo);
gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
2004-01-12 22:28:31 +01:00
gtk_widget_set_sensitive(matcher.test_btn, FALSE);
break;
case CRITERIA_COLORLABEL:
gtk_widget_set_sensitive(matcher.header_combo, FALSE);
gtk_widget_set_sensitive(matcher.header_label, FALSE);
gtk_widget_set_sensitive(matcher.value_label, TRUE);
gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
gtk_widget_set_sensitive(matcher.predicate_flag_combo, TRUE);
gtk_widget_hide(matcher.predicate_combo);
2001-05-11 01:00:27 +02:00
gtk_widget_show(matcher.predicate_flag_combo);
2001-05-08 16:29:47 +02:00
gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
2004-01-12 22:28:31 +01:00
gtk_widget_set_sensitive(matcher.test_btn, FALSE);
2001-05-08 16:29:47 +02:00
break;
case CRITERIA_SUBJECT:
case CRITERIA_FROM:
case CRITERIA_TO:
case CRITERIA_CC:
case CRITERIA_TO_OR_CC:
case CRITERIA_NEWSGROUPS:
case CRITERIA_INREPLYTO:
2001-05-13 04:57:01 +02:00
case CRITERIA_REFERENCES:
2001-05-08 16:29:47 +02:00
case CRITERIA_HEADERS_PART:
case CRITERIA_BODY_PART:
case CRITERIA_MESSAGE:
2001-05-09 15:30:45 +02:00
gtk_widget_set_sensitive(matcher.header_combo, FALSE);
2001-05-08 16:29:47 +02:00
gtk_widget_set_sensitive(matcher.header_label, FALSE);
gtk_widget_set_sensitive(matcher.value_label, TRUE);
gtk_widget_set_sensitive(matcher.value_entry, TRUE);
gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
2001-05-09 15:30:45 +02:00
gtk_widget_set_sensitive(matcher.predicate_combo, TRUE);
2001-05-11 01:00:27 +02:00
gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
gtk_widget_show(matcher.predicate_combo);
gtk_widget_hide(matcher.predicate_flag_combo);
2001-05-08 16:29:47 +02:00
gtk_widget_set_sensitive(matcher.case_chkbtn, TRUE);
gtk_widget_set_sensitive(matcher.regexp_chkbtn, TRUE);
2004-01-12 22:28:31 +01:00
gtk_widget_set_sensitive(matcher.test_btn, FALSE);
break;
2004-01-12 22:28:31 +01:00
case CRITERIA_TEST:
gtk_widget_set_sensitive(matcher.header_combo, FALSE);
gtk_widget_set_sensitive(matcher.header_label, FALSE);
gtk_widget_set_sensitive(matcher.value_label, TRUE);
gtk_widget_set_sensitive(matcher.value_entry, TRUE);
gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
gtk_widget_set_sensitive(matcher.predicate_flag_combo, TRUE);
gtk_widget_hide(matcher.predicate_combo);
gtk_widget_show(matcher.predicate_flag_combo);
gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
2004-01-12 22:28:31 +01:00
gtk_widget_set_sensitive(matcher.test_btn, TRUE);
2001-05-08 16:29:47 +02:00
break;
case CRITERIA_AGE_GREATER:
case CRITERIA_AGE_LOWER:
2001-05-13 04:57:01 +02:00
case CRITERIA_SCORE_GREATER:
case CRITERIA_SCORE_LOWER:
2001-09-18 13:02:34 +02:00
case CRITERIA_SCORE_EQUAL:
case CRITERIA_SIZE_GREATER:
case CRITERIA_SIZE_SMALLER:
case CRITERIA_SIZE_EQUAL:
2001-05-09 15:30:45 +02:00
gtk_widget_set_sensitive(matcher.header_combo, FALSE);
2001-05-08 16:29:47 +02:00
gtk_widget_set_sensitive(matcher.header_label, FALSE);
gtk_widget_set_sensitive(matcher.value_label, TRUE);
gtk_widget_set_sensitive(matcher.value_entry, TRUE);
gtk_widget_set_sensitive(matcher.predicate_label, FALSE);
2001-05-09 15:30:45 +02:00
gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
2001-05-11 01:00:27 +02:00
gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
gtk_widget_show(matcher.predicate_combo);
gtk_widget_hide(matcher.predicate_flag_combo);
2001-05-08 16:29:47 +02:00
gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
2004-01-12 22:28:31 +01:00
gtk_widget_set_sensitive(matcher.test_btn, FALSE);
2001-05-08 16:29:47 +02:00
break;
case CRITERIA_HEADER:
2001-05-09 15:30:45 +02:00
gtk_widget_set_sensitive(matcher.header_combo, TRUE);
2001-05-08 16:29:47 +02:00
gtk_widget_set_sensitive(matcher.header_label, TRUE);
gtk_widget_set_sensitive(matcher.value_label, TRUE);
gtk_widget_set_sensitive(matcher.value_entry, TRUE);
gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
2001-05-09 15:30:45 +02:00
gtk_widget_set_sensitive(matcher.predicate_combo, TRUE);
2001-05-11 01:00:27 +02:00
gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
gtk_widget_show(matcher.predicate_combo);
gtk_widget_hide(matcher.predicate_flag_combo);
2001-05-08 16:29:47 +02:00
gtk_widget_set_sensitive(matcher.case_chkbtn, TRUE);
gtk_widget_set_sensitive(matcher.regexp_chkbtn, TRUE);
2004-01-12 22:28:31 +01:00
gtk_widget_set_sensitive(matcher.test_btn, FALSE);
2001-05-08 16:29:47 +02:00
break;
}
}
/*!
*\brief Handle key press
*
*\param widget Widget receiving key press
*\param event Key event
*\param data User data
*/
2003-10-05 12:13:26 +02:00
static gboolean prefs_matcher_key_pressed(GtkWidget *widget, GdkEventKey *event,
2001-05-08 16:29:47 +02:00
gpointer data)
{
2004-02-28 11:10:15 +01:00
if (event && event->keyval == GDK_Escape) {
prefs_matcher_cancel();
2004-02-28 11:10:15 +01:00
return TRUE;
}
return FALSE;
}
/*!
*\brief Cancel matcher dialog
*/
static void prefs_matcher_cancel(void)
{
gtk_widget_hide(matcher.window);
inc_unlock();
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Accept current matchers
*/
static void prefs_matcher_ok(void)
2001-05-08 16:29:47 +02:00
{
2002-12-27 01:21:23 +01:00
MatcherList *matchers;
MatcherProp *matcherprop;
AlertValue val;
2002-12-27 01:21:23 +01:00
gchar *matcher_str;
gchar *str;
gint row = 1;
2001-05-11 01:00:27 +02:00
matchers = prefs_matcher_get_list();
2001-05-11 01:00:27 +02:00
if (matchers != NULL) {
matcherprop = prefs_matcher_dialog_to_matcher();
if (matcherprop != NULL) {
str = matcherprop_to_string(matcherprop);
if(strcmp(str, "all") != 0) {
while (gtk_clist_get_text(GTK_CLIST(matcher.cond_clist),
row, 0, &matcher_str)) {
if (strcmp(matcher_str, str) == 0) break;
row++;
}
2003-02-27 21:43:39 +01:00
if (strcmp(matcher_str, str) != 0) {
2003-02-27 21:43:39 +01:00
val = alertpanel(_("Entry not saved"),
_("The entry was not saved\nHave you really finished?"),
_("Yes"), _("No"), NULL);
if (G_ALERTDEFAULT != val) {
g_free(str);
2003-02-27 21:43:39 +01:00
return;
}
}
}
}
g_free(str);
gtk_widget_hide(matcher.window);
inc_unlock();
2001-05-11 01:00:27 +02:00
if (matchers_callback != NULL)
matchers_callback(matchers);
matcherlist_free(matchers);
}
2001-05-08 16:29:47 +02:00
}
/*!
*\brief Called when closing dialog box
*
*\param widget Dialog widget
*\param event Event info
*\param data User data
*
*\return gint TRUE
*/
2001-05-08 16:29:47 +02:00
static gint prefs_matcher_deleted(GtkWidget *widget, GdkEventAny *event,
gpointer data)
{
prefs_matcher_cancel();
2001-05-08 16:29:47 +02:00
return TRUE;
}
/*
2004-01-12 22:28:31 +01:00
* Strings describing test format strings
*
* When adding new lines, remember to put 2 strings for each line
*/
2004-01-12 22:28:31 +01:00
static gchar *test_desc_strings[] = {
N_("'Test' allows you to test a message or message element"), NULL,
N_("using an external program or script. The program will"), NULL,
N_("return either 0 or 1"), NULL,
N_("The following symbols can be used:"), NULL,
"%%", "%",
"%s", N_("Subject"),
"%f", N_("From"),
"%t", N_("To"),
"%c", N_("Cc"),
"%d", N_("Date"),
"%i", N_("Message-ID"),
"%n", N_("Newsgroups"),
"%r", N_("References"),
"%F", N_("Filename - should not be modified"),
"\\n", N_("new line"),
"\\", N_("escape character for quotes"),
2004-01-12 22:28:31 +01:00
"\\\"", N_("quote character"),
NULL, NULL
};
2004-01-12 22:28:31 +01:00
static DescriptionWindow test_desc_win = {
NULL,
2,
2004-01-12 22:28:31 +01:00
N_("Match Type: 'Test'"),
test_desc_strings
};
/*!
2004-01-12 22:28:31 +01:00
*\brief Show Test action's info
*/
2004-01-12 22:28:31 +01:00
void prefs_matcher_test_info(void)
{
2004-01-12 22:28:31 +01:00
description_window_create(&test_desc_win);
}