/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto and the Sylpheed-Claws team
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and 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
#include "filtering.h"
#include "addr_compl.h"
#include "colorlabel.h"
+#include "manual.h"
+#include "combobox.h"
#include "matcher_parser.h"
#include "matcher.h"
#include "prefs_filtering_action.h"
enum {
+ PREFS_FILTERING_ENABLED,
PREFS_FILTERING_NAME,
+ PREFS_FILTERING_ACCOUNT,
PREFS_FILTERING_RULE,
PREFS_FILTERING_PROP,
N_PREFS_FILTERING_COLUMNS
};
-static struct Filtering {
+struct _Filtering {
GtkWidget *window;
+ GtkWidget *help_btn;
GtkWidget *ok_btn;
GtkWidget *name_entry;
+ GtkWidget *account_label;
+ GtkWidget *account_combobox;
+ GtkListStore *account_combobox_list;
GtkWidget *cond_entry;
GtkWidget *action_entry;
GtkWidget *cond_list_view;
-} filtering;
+};
+
+typedef struct _Filtering Filtering;
+
+static Filtering filtering;
static GSList ** p_processing_list = NULL;
static GtkListStore* prefs_filtering_create_data_store (void);
static gint prefs_filtering_list_view_insert_rule (GtkListStore *list_store,
gint row,
+ gboolean enabled,
const gchar *name,
+ gint account_id,
const gchar *rule,
gboolean prop);
static gchar *prefs_filtering_list_view_get_rule (GtkWidget *list,
gint row);
-static gchar *prefs_filtering_list_view_get_rule_name (GtkWidget *list,
- gint row);
+static void prefs_filtering_list_view_get_rule_name (GtkWidget *list,
+ gint row,
+ gboolean *enabled,
+ gchar **name,
+ gint *account_id);
static GtkWidget *prefs_filtering_list_view_create (void);
static void prefs_filtering_create_list_view_columns (GtkWidget *list_view);
gboolean currently_selected,
gpointer data);
+static void prefs_filtering_account_option_menu_populate(void);
+
+static gulong signal_id = 0; /* filtering.help_btn clicked signal */
+
void prefs_filtering_open(GSList ** p_processing,
- const gchar * title,
+ const gchar *title,
+ const gchar *help_url_anchor,
const gchar *header,
- const gchar *key)
+ const gchar *key,
+ gboolean per_account_filtering)
{
if (prefs_rc_is_readonly(FILTERING_RC))
return;
if (!filtering.window) {
prefs_filtering_create();
+ } else {
+ gtk_list_store_clear(filtering.account_combobox_list);
+ prefs_filtering_account_option_menu_populate();
}
manage_window_set_transient(GTK_WINDOW(filtering.window));
else
gtk_window_set_title (GTK_WINDOW(filtering.window),
_("Filtering/Processing configuration"));
-
+
+ if (help_url_anchor != NULL) {
+ if (signal_id != 0) {
+ g_signal_handler_disconnect(
+ G_OBJECT(filtering.help_btn),
+ signal_id);
+ }
+
+ signal_id = g_signal_connect(G_OBJECT(filtering.help_btn),
+ "clicked",
+ G_CALLBACK(manual_open_with_anchor_cb),
+ (gchar*)help_url_anchor);
+ }
+ else {
+ gtk_widget_set_sensitive(filtering.help_btn, FALSE);
+ }
+
p_processing_list = p_processing;
prefs_filtering_set_dialog(header, key);
+ if (per_account_filtering) {
+ gtk_widget_show(filtering.account_label);
+ gtk_widget_show(filtering.account_combobox);
+ } else {
+ gtk_widget_hide(filtering.account_label);
+ gtk_widget_hide(filtering.account_combobox);
+ combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), 0);
+ }
gtk_widget_show(filtering.window);
- start_address_completion();
+ start_address_completion(NULL);
}
static void prefs_filtering_size_allocate_cb(GtkWidget *widget,
inc_unlock();
}
+static void prefs_filtering_account_option_menu_populate(void)
+{
+ GList *accounts = NULL;
+ GtkTreeIter iter;
+
+ accounts = account_get_list();
+
+ g_return_val_if_fail(accounts != NULL, NULL);
+
+ COMBOBOX_ADD(filtering.account_combobox_list, _("All"), 0);
+ for (; accounts != NULL; accounts = accounts->next) {
+ PrefsAccount *ac = (PrefsAccount *)accounts->data;
+
+ COMBOBOX_ADD(filtering.account_combobox_list, ac->account_name, ac->account_id);
+ }
+}
+
+static GtkWidget *prefs_filtering_account_option_menu(Filtering *filtering)
+{
+ GtkWidget *optmenu = NULL;
+ GtkWidget *optmenubox = NULL;
+ GtkListStore *menu = NULL;
+
+ optmenubox = gtk_event_box_new();
+ optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
+ menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
+
+ filtering->account_combobox = optmenu;
+ filtering->account_combobox_list = menu;
+
+ prefs_filtering_account_option_menu_populate();
+
+ return optmenubox;
+}
+
static void prefs_filtering_create(void)
{
GtkWidget *window;
GtkWidget *vbox;
- GtkWidget *ok_btn;
+ GtkWidget *help_btn;
GtkWidget *cancel_btn;
+ GtkWidget *ok_btn;
GtkWidget *confirm_area;
GtkWidget *vbox1;
GtkWidget *name_label;
GtkWidget *name_entry;
+ GtkWidget *account_label;
+ GtkWidget *account_opt_menu;
GtkWidget *cond_label;
GtkWidget *cond_entry;
GtkWidget *cond_btn;
gtk_widget_show (vbox);
gtk_container_add (GTK_CONTAINER (window), vbox);
- gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK,
- &cancel_btn, GTK_STOCK_CANCEL, NULL, NULL);
+ gtkut_stock_button_set_create_with_help(&confirm_area, &help_btn,
+ &cancel_btn, GTK_STOCK_CANCEL,
+ &ok_btn, GTK_STOCK_OK,
+ NULL, NULL);
gtk_widget_show (confirm_area);
gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
gtk_widget_grab_default (ok_btn);
gtk_box_pack_start (GTK_BOX (vbox), vbox1, FALSE, TRUE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
- table = gtk_table_new(3, 3, FALSE);
+ table = gtk_table_new(3, 4, FALSE);
gtk_widget_show(table);
gtk_box_pack_start (GTK_BOX (vbox1), table, TRUE, TRUE, 0);
(GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
(GtkAttachOptions) (0), 0, 0);
+ account_label = gtk_label_new (_("Account:"));
+ gtk_widget_show (account_label);
+ gtk_misc_set_alignment (GTK_MISC (account_label), 1, 0.5);
+ gtk_table_attach (GTK_TABLE (table), account_label, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ account_opt_menu = prefs_filtering_account_option_menu(&filtering);
+ gtk_widget_show (account_opt_menu);
+ gtk_table_attach (GTK_TABLE (table), account_opt_menu, 1, 2, 1, 2,
+ (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
+ (GtkAttachOptions) (0), 0, 0);
+ combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), 0);
+
cond_label = gtk_label_new (_("Condition: "));
gtk_widget_show (cond_label);
gtk_misc_set_alignment (GTK_MISC (cond_label), 1, 0.5);
- gtk_table_attach (GTK_TABLE (table), cond_label, 0, 1, 1, 2,
+ gtk_table_attach (GTK_TABLE (table), cond_label, 0, 1, 2, 3,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
cond_entry = gtk_entry_new ();
gtk_widget_show (cond_entry);
- gtk_table_attach (GTK_TABLE (table), cond_entry, 1, 2, 1, 2,
+ gtk_table_attach (GTK_TABLE (table), cond_entry, 1, 2, 2, 3,
(GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
(GtkAttachOptions) (0), 0, 0);
- cond_btn = gtk_button_new_with_label (_("Define ..."));
+ cond_btn = gtk_button_new_with_label (_(" Define... "));
gtk_widget_show (cond_btn);
- gtk_table_attach (GTK_TABLE (table), cond_btn, 2, 3, 1, 2,
+ gtk_table_attach (GTK_TABLE (table), cond_btn, 2, 3, 2, 3,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 2, 2);
g_signal_connect(G_OBJECT (cond_btn), "clicked",
action_label = gtk_label_new (_("Action: "));
gtk_widget_show (action_label);
gtk_misc_set_alignment (GTK_MISC (action_label), 1, 0.5);
- gtk_table_attach (GTK_TABLE (table), action_label, 0, 1, 2, 3,
+ gtk_table_attach (GTK_TABLE (table), action_label, 0, 1, 3, 4,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
action_entry = gtk_entry_new ();
gtk_widget_show (action_entry);
- gtk_table_attach (GTK_TABLE (table), action_entry, 1, 2, 2, 3,
+ gtk_table_attach (GTK_TABLE (table), action_entry, 1, 2, 3, 4,
(GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
(GtkAttachOptions) (0), 0, 0);
- action_btn = gtk_button_new_with_label (_("Define ..."));
+ action_btn = gtk_button_new_with_label (_(" Define... "));
gtk_widget_show (action_btn);
- gtk_table_attach (GTK_TABLE (table), action_btn, 2, 3, 2, 3,
+ gtk_table_attach (GTK_TABLE (table), action_btn, 2, 3, 3, 4,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 2, 2);
g_signal_connect(G_OBJECT (action_btn), "clicked",
g_signal_connect(G_OBJECT (reg_btn), "clicked",
G_CALLBACK(prefs_filtering_register_cb), NULL);
- subst_btn = gtk_button_new_with_label (_(" Replace "));
+ subst_btn = gtkut_get_replace_btn (_("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",
gtk_widget_show_all(window);
filtering.window = window;
+ filtering.help_btn = help_btn;
filtering.ok_btn = ok_btn;
filtering.name_entry = name_entry;
filtering.cond_entry = cond_entry;
filtering.action_entry = action_entry;
filtering.cond_list_view = cond_list_view;
+ filtering.account_label = account_label;
}
static void rename_path(GSList * filters,
/* add the place holder (New) at row 0 */
prefs_filtering_list_view_insert_rule(list_store, -1,
+ FALSE,
_("(New)"),
+ 0,
_("(New)"),
FALSE);
subst_char(cond_str, '\t', ':');
prefs_filtering_list_view_insert_rule(list_store, -1,
+ prop->enabled,
prop->name,
+ prop->account_id,
cond_str, TRUE);
g_free(cond_str);
static void prefs_filtering_reset_dialog(void)
{
gtk_entry_set_text(GTK_ENTRY(filtering.name_entry), "");
+ combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), 0);
gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), "");
gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), "");
}
/* FIXME: this strcmp() is bogus: "(New)" should never
* be inserted in the storage */
if (strcmp(filtering_str, _("(New)")) != 0) {
- gchar *name = prefs_filtering_list_view_get_rule_name(filtering.cond_list_view, row);
+ gboolean enabled;
+ gchar *name;
+ gint account_id = 0;
+
+ prefs_filtering_list_view_get_rule_name(
+ filtering.cond_list_view, row,
+ &enabled, &name, &account_id);
prop = matcher_parser_get_filtering(filtering_str);
g_free(filtering_str);
if (prop) {
+ prop->enabled = enabled;
prop->name = name;
+ prop->account_id = account_id;
prefs_filtering =
g_slist_append(prefs_filtering, prop);
}
gchar *str;
GtkListStore *list_store;
gchar *name = NULL;
-
+ gint account_id = 0;
+ gboolean enabled = TRUE;
+
str = filteringprop_to_string(prop);
if (str == NULL)
return -1;
-
- if (prop && prop->name)
- name = prop->name;
+
+ if (prop) {
+ if (prop->name)
+ name = prop->name;
+ account_id = prop->account_id;
+ enabled = prop->enabled;
+ }
list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
- row = prefs_filtering_list_view_insert_rule(list_store, row, name, str, prop != NULL);
+ row = prefs_filtering_list_view_insert_rule(list_store, row,
+ enabled,
+ name,
+ account_id,
+ str,
+ prop != NULL);
g_free(str);
static FilteringProp * prefs_filtering_dialog_to_filtering(gboolean alert)
{
MatcherList * cond;
+ gboolean enabled = TRUE;
gchar * name = NULL;
+ gint account_id = 0;
gchar * cond_str = NULL;
gchar * action_str = NULL;
FilteringProp * prop = NULL;
name = gtk_editable_get_chars(GTK_EDITABLE(filtering.name_entry), 0, -1);
+ account_id = combobox_get_active_data(GTK_COMBO_BOX(filtering.account_combobox));
+
cond_str = gtk_editable_get_chars(GTK_EDITABLE(filtering.cond_entry), 0, -1);
if (*cond_str == '\0') {
if(alert == TRUE) alertpanel_error(_("Condition string is empty."));
goto fail;
}
- prop = filteringprop_new(name, cond, action_list);
+ prop = filteringprop_new(enabled, name, account_id, cond, action_list);
fail:
g_free(name);
if (alertpanel(_("Delete rule"),
_("Do you really want to delete this rule?"),
- GTK_STOCK_YES, GTK_STOCK_NO, NULL) == G_ALERTALTERNATE)
+ GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL) == G_ALERTDEFAULT)
return;
model = gtk_tree_view_get_model(list_view);
if (prop->name != NULL)
gtk_entry_set_text(GTK_ENTRY(filtering.name_entry), prop->name);
+ combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), prop->account_id);
+
gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), matcher_str);
action_str = filteringaction_list_to_string(prop->action_list);
if (!filtering_str) {
val = alertpanel(_("Entry not saved"),
_("The entry was not saved. Close anyway?"),
- GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+ GTK_STOCK_CLOSE, _("+_Continue editing"), NULL);
if (G_ALERTDEFAULT != val) {
g_free(filtering_str);
g_free(str); /* fixed two leaks: huzzah! */
strlen(action)) {
val = alertpanel(_("Entry not saved"),
_("The entry was not saved. Close anyway?"),
- GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+ GTK_STOCK_CLOSE, _("+_Continue editing"), NULL);
if (G_ALERTDEFAULT != val) {
g_free(name);
g_free(condition);
static GtkListStore* prefs_filtering_create_data_store(void)
{
return gtk_list_store_new(N_PREFS_FILTERING_COLUMNS,
+ G_TYPE_BOOLEAN,
G_TYPE_STRING,
+ G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_BOOLEAN,
-1);
*\param list_store Store to operate on
*\param row -1 to add a new rule to store, else change an existing
* row
+ *\param enabled TRUE if rule is enabled
+ *\param name The Name of rule
+ *\param account_id The account ID
*\param rule String representation of rule
*\param prop TRUE if valid filtering rule; if FALSE it's the first
* entry in the store ("(New)").
*/
static gint prefs_filtering_list_view_insert_rule(GtkListStore *list_store,
gint row,
+ gboolean enabled,
const gchar *name,
+ gint account_id,
const gchar *rule,
gboolean prop)
{
/* append new */
gtk_list_store_append(list_store, &iter);
gtk_list_store_set(list_store, &iter,
+ PREFS_FILTERING_ENABLED, enabled,
PREFS_FILTERING_NAME, name,
+ PREFS_FILTERING_ACCOUNT, account_id,
PREFS_FILTERING_RULE, rule,
PREFS_FILTERING_PROP, prop,
-1);
} else {
/* change existing */
gtk_list_store_set(list_store, &iter,
+ PREFS_FILTERING_ENABLED, enabled,
PREFS_FILTERING_NAME, name,
+ PREFS_FILTERING_ACCOUNT, account_id,
PREFS_FILTERING_RULE, rule,
-1);
return row;
return result;
}
-static gchar *prefs_filtering_list_view_get_rule_name(GtkWidget *list, gint row)
+static void prefs_filtering_list_view_get_rule_name(GtkWidget *list, gint row,
+ gboolean *enabled, gchar **name, gint *account_id)
{
GtkTreeView *list_view = GTK_TREE_VIEW(list);
GtkTreeModel *model = gtk_tree_view_get_model(list_view);
GtkTreeIter iter;
- gchar *result = NULL;
- if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
- return NULL;
-
- gtk_tree_model_get(model, &iter,
- PREFS_FILTERING_NAME, &result,
- -1);
-
- return result;
+ *enabled = TRUE;
+ *name = NULL;
+
+ if (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
+ gtk_tree_model_get(model, &iter,
+ PREFS_FILTERING_ENABLED, enabled,
+ PREFS_FILTERING_NAME, name,
+ PREFS_FILTERING_ACCOUNT, account_id,
+ -1);
+ }
}
/*!
return GTK_WIDGET(list_view);
}
+static void prefs_filtering_enable_toggled(GtkCellRendererToggle *widget,
+ gchar *path,
+ GtkWidget *list_view)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
+ gboolean enabled = TRUE;
+
+ if (!gtk_tree_model_get_iter_from_string(model, &iter, path))
+ return;
+
+ gtk_tree_model_get(model, &iter,
+ PREFS_FILTERING_ENABLED, &enabled,
+ -1);
+
+ gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+ PREFS_FILTERING_ENABLED, !enabled,
+ -1);
+}
+
static void prefs_filtering_create_list_view_columns(GtkWidget *list_view)
{
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
+ renderer = gtk_cell_renderer_toggle_new();
+ g_object_set(renderer,
+ "radio", FALSE,
+ "activatable", TRUE,
+ NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Enable"), /* FIXME : Enable, Enabled, or 'E' ? */
+ renderer,
+ "active", PREFS_FILTERING_ENABLED,
+ NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
+ g_signal_connect(G_OBJECT(renderer), "toggled",
+ G_CALLBACK(prefs_filtering_enable_toggled),
+ list_view);
+
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
(_("Name"),
FilteringProp *prop;
gchar *filtering_str = NULL;
gchar *name = NULL;
+ gint account_id = 0;
gtk_tree_model_get(model, &iter,
PREFS_FILTERING_RULE, &filtering_str,
gtk_tree_model_get(model, &iter,
PREFS_FILTERING_NAME, &name,
-1);
+ gtk_tree_model_get(model, &iter,
+ PREFS_FILTERING_ACCOUNT, &account_id,
+ -1);
+ gtk_tree_model_get(model, &iter,
+ PREFS_FILTERING_ACCOUNT, &account_id,
+ -1);
prop = matcher_parser_get_filtering(filtering_str);
if (prop) {
prop->name = g_strdup(name);
+ prop->account_id = account_id;
prefs_filtering_select_set(prop);
filteringprop_free(prop);
}