/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
#ifdef HAVE_CONFIG_H
#include "folder.h"
#include "filtering.h"
#include "addr_compl.h"
-#include "colorlabel.h"
#include "manual.h"
+#include "combobox.h"
#include "matcher_parser.h"
#include "matcher.h"
enum {
PREFS_FILTERING_ENABLED,
PREFS_FILTERING_NAME,
+ PREFS_FILTERING_ACCOUNT_ID,
+ PREFS_FILTERING_ACCOUNT_NAME,
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;
+
+ GtkTreeViewColumn *account_name_column;
+};
+
+typedef struct _Filtering Filtering;
+
+static Filtering filtering;
static GSList ** p_processing_list = NULL;
static gint prefs_filtering_list_view_set_row (gint row, FilteringProp * prop);
static void prefs_filtering_reset_dialog (void);
+static gboolean prefs_filtering_rename_tag_func(GNode *node, gpointer data);
static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data);
static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data);
static gint prefs_filtering_list_view_insert_rule (GtkListStore *list_store,
gint row,
gboolean enabled,
- const gchar *name,
+ const gchar *name,
+ gint account_id,
+ const gchar *account_name,
const gchar *rule,
gboolean prop);
static gchar *prefs_filtering_list_view_get_rule (GtkWidget *list,
gint row);
-static void prefs_filtering_list_view_get_rule_name (GtkWidget *list,
+static void prefs_filtering_list_view_get_rule_info (GtkWidget *list,
gint row,
gboolean *enabled,
- gchar **name);
+ gchar **name,
+ gint *account_id);
static GtkWidget *prefs_filtering_list_view_create (void);
static void prefs_filtering_create_list_view_columns (GtkWidget *list_view);
-static gint prefs_filtering_get_selected_row (GtkWidget *list_view);
-static gboolean prefs_filtering_list_view_select_row (GtkWidget *list, gint row);
static gboolean prefs_filtering_selected (GtkTreeSelection *selector,
GtkTreeModel *model,
gboolean currently_selected,
gpointer data);
+static void prefs_filtering_account_option_menu_populate(void);
+
static gulong signal_id = 0; /* filtering.help_btn clicked signal */
+static int modified = FALSE;
+
void prefs_filtering_open(GSList ** p_processing,
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();
}
+ gtk_tree_view_column_set_visible(filtering.account_name_column,
+ per_account_filtering);
+
manage_window_set_transient(GTK_WINDOW(filtering.window));
gtk_widget_grab_focus(filtering.ok_btn);
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_if_fail(accounts != NULL);
+
+ COMBOBOX_ADD(filtering.account_combobox_list, Q_("Filtering Account Menu|All"), 0);
+ for (; accounts != NULL; accounts = accounts->next) {
+ PrefsAccount *ac = (PrefsAccount *)accounts->data;
+
+ COMBOBOX_ADD_ESCAPED(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 *name_label;
GtkWidget *name_entry;
+ GtkWidget *account_label;
+ GtkWidget *account_opt_menu;
GtkWidget *cond_label;
GtkWidget *cond_entry;
GtkWidget *cond_btn;
debug_print("Creating filtering configuration window...\n");
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering");
gtk_container_set_border_width (GTK_CONTAINER (window), 8);
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
gtk_window_set_modal (GTK_WINDOW (window), TRUE);
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(4, 3, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_widget_show(table);
gtk_box_pack_start (GTK_BOX (vbox1), table, TRUE, TRUE, 0);
-
- name_label = gtk_label_new (_("Name: "));
+ name_label = gtk_label_new (_("Name"));
gtk_widget_show (name_label);
gtk_misc_set_alignment (GTK_MISC (name_label), 1, 0.5);
gtk_table_attach (GTK_TABLE (table), name_label, 0, 1, 0, 1,
(GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
(GtkAttachOptions) (0), 0, 0);
- cond_label = gtk_label_new (_("Condition: "));
+ 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... "));
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",
G_CALLBACK(prefs_filtering_condition_define),
NULL);
- action_label = gtk_label_new (_("Action: "));
+ 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... "));
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",
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_tag(GSList * filters,
+ const gchar * old_tag, const gchar * new_tag);
+
+void prefs_filtering_rename_tag(const gchar *old_tag, const gchar *new_tag)
+{
+ GList * cur;
+ const gchar *tags[2] = {NULL, NULL};
+ tags[0] = old_tag;
+ tags[1] = new_tag;
+ for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
+ Folder *folder;
+ folder = (Folder *) cur->data;
+ g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+ prefs_filtering_rename_tag_func, tags);
+ }
+
+ rename_tag(pre_global_processing, old_tag, new_tag);
+ rename_tag(post_global_processing, old_tag, new_tag);
+ rename_tag(filtering_rules, old_tag, new_tag);
+
+ prefs_matcher_write_config();
+}
+
+
static void rename_path(GSList * filters,
const gchar * old_path, const gchar * new_path);
FilteringAction *action = action_cur->data;
- if (!action->destination) continue;
+ if (action->type == MATCHACTION_SET_TAG ||
+ action->type == MATCHACTION_UNSET_TAG)
+ continue;
+ if (!action->destination)
+ continue;
destlen = strlen(action->destination);
return FALSE;
}
+static void rename_tag(GSList * filters,
+ const gchar * old_tag, const gchar * new_tag)
+{
+ GSList * action_cur;
+ GSList * cur;
+
+ for (cur = filters; cur != NULL; cur = cur->next) {
+ FilteringProp *filtering = (FilteringProp *)cur->data;
+
+ for(action_cur = filtering->action_list ; action_cur != NULL ;
+ action_cur = action_cur->next) {
+
+ FilteringAction *action = action_cur->data;
+
+ if (action->type != MATCHACTION_SET_TAG &&
+ action->type != MATCHACTION_UNSET_TAG)
+ continue;
+ if (!action->destination)
+ continue;
+ if (!strcmp(action->destination, old_tag)) {
+ g_free(action->destination);
+ action->destination = g_strdup(new_tag);
+ }
+ }
+ }
+}
+
+static gboolean prefs_filtering_rename_tag_func(GNode *node, gpointer data)
+{
+ GSList *filters;
+ const gchar * old_tag;
+ const gchar * new_tag;
+ const gchar ** tags;
+ FolderItem *item;
+
+ tags = data;
+ old_tag = tags[0];
+ new_tag = tags[1];
+
+ g_return_val_if_fail(old_tag != NULL, FALSE);
+ g_return_val_if_fail(new_tag != NULL, FALSE);
+ g_return_val_if_fail(node != NULL, FALSE);
+
+ item = node->data;
+ if (!item || !item->prefs)
+ return FALSE;
+ filters = item->prefs->processing;
+
+ rename_tag(filters, old_tag, new_tag);
+
+ return FALSE;
+}
+
void prefs_filtering_delete_path(const gchar *path)
{
GList * cur;
action = action_cur->data;
- if (!action->destination) continue;
+ if (action->type == MATCHACTION_SET_TAG ||
+ action->type == MATCHACTION_UNSET_TAG)
+ continue;
+ if (!action->destination)
+ continue;
destlen = strlen(action->destination);
/* add the place holder (New) at row 0 */
prefs_filtering_list_view_insert_rule(list_store, -1,
FALSE,
+ _("(New)"),
+ 0,
_("(New)"),
_("(New)"),
FALSE);
for(cur = prefs_filtering ; cur != NULL ; cur = g_slist_next(cur)) {
FilteringProp * prop = (FilteringProp *) cur->data;
+ gchar *account_name = NULL;
+
+ if (prop->account_id > 0) {
+ PrefsAccount *ac_prefs = account_find_from_id(prop->account_id);
+
+ if (ac_prefs)
+ account_name = ac_prefs->account_name;
+ }
+ if (account_name == NULL)
+ account_name = (gchar *)Q_("Filtering Account Menu|All");
cond_str = filteringprop_to_string(prop);
subst_char(cond_str, '\t', ':');
prefs_filtering_list_view_insert_rule(list_store, -1,
prop->enabled,
prop->name,
+ prop->account_id,
+ account_name,
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), "");
}
if (strcmp(filtering_str, _("(New)")) != 0) {
gboolean enabled;
gchar *name;
+ gint account_id = 0;
- prefs_filtering_list_view_get_rule_name(
+ prefs_filtering_list_view_get_rule_info(
filtering.cond_list_view, row,
- &enabled, &name);
+ &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;
+ gchar *account_name = (gchar *)Q_("Filtering Account Menu|All");
gboolean enabled = TRUE;
str = filteringprop_to_string(prop);
if (prop) {
if (prop->name)
name = prop->name;
+ account_id = prop->account_id;
+ if (account_id > 0)
+ account_name = account_find_from_id(account_id)->account_name;
enabled = prop->enabled;
}
row = prefs_filtering_list_view_insert_rule(list_store, row,
enabled,
name,
+ account_id,
+ account_name,
str,
prop != NULL);
cond_str = gtk_editable_get_chars(GTK_EDITABLE(filtering.cond_entry), 0, -1);
if (*cond_str != '\0') {
- matchers = matcher_parser_get_cond(cond_str);
+ matchers = matcher_parser_get_cond(cond_str, NULL);
if (matchers == NULL)
alertpanel_error(_("Condition string is not valid."));
}
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;
}
- cond = matcher_parser_get_cond(cond_str);
+ cond = matcher_parser_get_cond(cond_str, NULL);
if (cond == NULL) {
if(alert == TRUE) alertpanel_error(_("Condition string is not valid."));
goto fail;
}
- prop = filteringprop_new(enabled, name, cond, action_list);
+ prop = filteringprop_new(enabled, name, account_id, cond, action_list);
fail:
g_free(name);
filteringprop_free(prop);
prefs_filtering_reset_dialog();
+ modified = TRUE;
}
static void prefs_filtering_substitute_cb(void)
{
- gint selected_row = prefs_filtering_get_selected_row
+ gint selected_row = gtkut_list_view_get_selected_row
(filtering.cond_list_view);
FilteringProp *prop;
+ gboolean enabled;
+ gchar *name;
+ gint account_id;
if (selected_row <= 0)
return;
prop = prefs_filtering_dialog_to_filtering(TRUE);
+
if (prop == NULL)
return;
+
+ /* prop->emabled is always TRUE here, re-use the value from the selected row
+ as we don't substitute this value from dialog */
+ prefs_filtering_list_view_get_rule_info(
+ filtering.cond_list_view, selected_row,
+ &enabled, &name, &account_id);
+ prop->enabled = enabled;
+
prefs_filtering_list_view_set_row(selected_row, prop);
filteringprop_free(prop);
prefs_filtering_reset_dialog();
+ modified = TRUE;
}
static void prefs_filtering_delete_cb(void)
GtkTreeIter iter;
gint row;
- row = prefs_filtering_get_selected_row(filtering.cond_list_view);
+ row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
if (row <= 0)
return;
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
prefs_filtering_reset_dialog();
+ modified = TRUE;
}
static void prefs_filtering_top(void)
GtkTreeIter top, sel;
GtkTreeModel *model;
- row = prefs_filtering_get_selected_row(filtering.cond_list_view);
+ row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
if (row <= 1)
return;
return;
gtk_list_store_move_after(GTK_LIST_STORE(model), &sel, &top);
- prefs_filtering_list_view_select_row(filtering.cond_list_view, 1);
+ gtkut_list_view_select_row(filtering.cond_list_view, 1);
+ modified = TRUE;
}
static void prefs_filtering_up(void)
GtkTreeIter top, sel;
GtkTreeModel *model;
- row = prefs_filtering_get_selected_row(filtering.cond_list_view);
+ row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
if (row <= 1)
return;
return;
gtk_list_store_swap(GTK_LIST_STORE(model), &top, &sel);
- prefs_filtering_list_view_select_row(filtering.cond_list_view, row - 1);
+ gtkut_list_view_select_row(filtering.cond_list_view, row - 1);
+ modified = TRUE;
}
static void prefs_filtering_down(void)
model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
n_rows = gtk_tree_model_iter_n_children(model, NULL);
- row = prefs_filtering_get_selected_row(filtering.cond_list_view);
+ row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
if (row < 1 || row >= n_rows - 1)
return;
return;
gtk_list_store_swap(GTK_LIST_STORE(model), &top, &sel);
- prefs_filtering_list_view_select_row(filtering.cond_list_view, row + 1);
+ gtkut_list_view_select_row(filtering.cond_list_view, row + 1);
+ modified = TRUE;
}
static void prefs_filtering_bottom(void)
model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
n_rows = gtk_tree_model_iter_n_children(model, NULL);
- row = prefs_filtering_get_selected_row(filtering.cond_list_view);
+ row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
if (row < 1 || row >= n_rows - 1)
return;
return;
gtk_list_store_move_after(GTK_LIST_STORE(model), &top, &sel);
- prefs_filtering_list_view_select_row(filtering.cond_list_view, n_rows - 1);
+ gtkut_list_view_select_row(filtering.cond_list_view, n_rows - 1);
+ modified = TRUE;
}
static void prefs_filtering_select_set(FilteringProp *prop)
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);
return FALSE;
}
-static void prefs_filtering_ok(void)
+static gboolean prefs_filtering_check_mod(gboolean check_changed_list)
{
FilteringProp * prop;
gchar * str;
AlertValue val;
prop = prefs_filtering_dialog_to_filtering(FALSE);
+
+ if (check_changed_list) {
+ if (modified && alertpanel(_("Filtering rules not saved"),
+ _("The list of filtering rules have been modified. Close anyway?"),
+ GTK_STOCK_CLOSE, _("+_Continue editing"),
+ NULL) != G_ALERTDEFAULT) {
+ return TRUE;
+ }
+ }
+
+ /* check if a rule is being edited */
if (prop != NULL) {
str = filteringprop_to_string(prop);
g_free(filtering_str);
g_free(str); /* fixed two leaks: huzzah! */
filteringprop_free(prop);
- return;
+ return TRUE;
}
}
g_free(name);
g_free(condition);
g_free(action);
- return;
+ return TRUE;
}
}
g_free(name);
g_free(condition);
g_free(action);
}
+ return FALSE;
+}
+
+static void prefs_filtering_ok(void)
+{
+ if (prefs_filtering_check_mod(FALSE))
+ return;
+ modified = FALSE;
prefs_filtering_set_list();
prefs_matcher_write_config();
prefs_filtering_close();
static void prefs_filtering_cancel(void)
{
+ if (prefs_filtering_check_mod(TRUE))
+ return;
+ modified = FALSE;
prefs_matcher_read_config();
prefs_filtering_close();
}
return gtk_list_store_new(N_PREFS_FILTERING_COLUMNS,
G_TYPE_BOOLEAN,
G_TYPE_STRING,
+ G_TYPE_INT,
+ G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_BOOLEAN,
-1);
* row
*\param enabled TRUE if rule is enabled
*\param name The Name of rule
+ *\param account_id The account ID
+ *\param account_name The account name or All or (New)
*\param rule String representation of rule
*\param prop TRUE if valid filtering rule; if FALSE it's the first
* entry in the store ("(New)").
gint row,
gboolean enabled,
const gchar *name,
+ gint account_id,
+ const gchar *account_name,
const gchar *rule,
gboolean prop)
{
gtk_list_store_set(list_store, &iter,
PREFS_FILTERING_ENABLED, enabled,
PREFS_FILTERING_NAME, name,
+ PREFS_FILTERING_ACCOUNT_ID, account_id,
+ PREFS_FILTERING_ACCOUNT_NAME, account_name,
PREFS_FILTERING_RULE, rule,
PREFS_FILTERING_PROP, prop,
-1);
gtk_list_store_set(list_store, &iter,
PREFS_FILTERING_ENABLED, enabled,
PREFS_FILTERING_NAME, name,
+ PREFS_FILTERING_ACCOUNT_ID, account_id,
+ PREFS_FILTERING_ACCOUNT_NAME, account_name,
PREFS_FILTERING_RULE, rule,
-1);
return row;
return result;
}
-static void prefs_filtering_list_view_get_rule_name(GtkWidget *list, gint row, gboolean *enabled, gchar **name)
+static void prefs_filtering_list_view_get_rule_info(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);
gtk_tree_model_get(model, &iter,
PREFS_FILTERING_ENABLED, enabled,
PREFS_FILTERING_NAME, name,
+ PREFS_FILTERING_ACCOUNT_ID, account_id,
-1);
}
}
list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL
(prefs_filtering_create_data_store())));
- gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
+ gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
gtk_tree_view_set_reorderable(list_view, TRUE);
selector = gtk_tree_view_get_selection(list_view);
renderer,
"active", PREFS_FILTERING_ENABLED,
NULL);
+ gtk_tree_view_column_set_alignment (column, 0.5);
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
g_signal_connect(G_OBJECT(renderer), "toggled",
G_CALLBACK(prefs_filtering_enable_toggled),
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
gtk_tree_view_column_set_resizable(column, TRUE);
+
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Account"),
+ renderer,
+ "text", PREFS_FILTERING_ACCOUNT_NAME,
+ NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
+ gtk_tree_view_column_set_resizable(column, TRUE);
+
+ filtering.account_name_column = column;
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
}
-static gboolean gtkut_tree_iter_comp(GtkTreeModel *model,
- GtkTreeIter *iter1,
- GtkTreeIter *iter2)
-{
- GtkTreePath *path1 = gtk_tree_model_get_path(model, iter1);
- GtkTreePath *path2 = gtk_tree_model_get_path(model, iter2);
- gboolean result;
-
- result = gtk_tree_path_compare(path1, path2) == 0;
-
- gtk_tree_path_free(path1);
- gtk_tree_path_free(path2);
-
- return result;
-}
-
-/*!
- *\brief Get selected row number.
- */
-static gint prefs_filtering_get_selected_row(GtkWidget *list_view)
-{
- GtkTreeView *view = GTK_TREE_VIEW(list_view);
- GtkTreeModel *model = gtk_tree_view_get_model(view);
- int n_rows = gtk_tree_model_iter_n_children(model, NULL);
- GtkTreeSelection *selection;
- GtkTreeIter iter;
- int row;
-
- if (n_rows == 0)
- return -1;
-
- selection = gtk_tree_view_get_selection(view);
- if (!gtk_tree_selection_get_selected(selection, &model, &iter))
- return -1;
-
- /* get all iterators and compare them... */
- for (row = 0; row < n_rows; row++) {
- GtkTreeIter itern;
-
- gtk_tree_model_iter_nth_child(model, &itern, NULL, row);
- if (gtkut_tree_iter_comp(model, &iter, &itern))
- return row;
- }
-
- return -1;
-}
-
-static gboolean prefs_filtering_list_view_select_row(GtkWidget *list, gint row)
-{
- GtkTreeView *list_view = GTK_TREE_VIEW(list);
- GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
- GtkTreeModel *model = gtk_tree_view_get_model(list_view);
- GtkTreeIter iter;
- GtkTreePath *path;
-
- if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
- return FALSE;
-
- gtk_tree_selection_select_iter(selection, &iter);
-
- path = gtk_tree_model_get_path(model, &iter);
- gtk_tree_view_set_cursor(list_view, path, NULL, FALSE);
- gtk_tree_path_free(path);
-
- return TRUE;
-}
-
/*!
*\brief Triggered when a row is selected
*/
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_ID, &account_id,
+ -1);
prop = matcher_parser_get_filtering(filtering_str);
- if (prop) {
+ if (prop) {
prop->name = g_strdup(name);
+ prop->account_id = account_id;
prefs_filtering_select_set(prop);
filteringprop_free(prop);
}