/*
* 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
#include "folder.h"
#include "filtering.h"
#include "addr_compl.h"
-#include "colorlabel.h"
#include "manual.h"
#include "combobox.h"
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,
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,
for (; accounts != NULL; accounts = accounts->next) {
PrefsAccount *ac = (PrefsAccount *)accounts->data;
- COMBOBOX_ADD(filtering.account_combobox_list, ac->account_name, ac->account_id);
+ COMBOBOX_ADD_ESCAPED(filtering.account_combobox_list, ac->account_name, ac->account_id);
}
}
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, 4, 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);
- account_label = gtk_label_new (_("Account:"));
+ 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) (0), 0, 0);
combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), 0);
- cond_label = gtk_label_new (_("Condition: "));
+ 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, 2, 3,
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, 3, 4,
for(cur = prefs_filtering ; cur != NULL ; cur = g_slist_next(cur)) {
FilteringProp * prop = (FilteringProp *) cur->data;
- gchar *account_name;
+ gchar *account_name = NULL;
if (prop->account_id > 0) {
- account_name = account_find_from_id(prop->account_id)->account_name;
- } else {
- account_name = (gchar *)Q_("Filtering Account Menu|All");
+ 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', ':');
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, &account_id);
prop = matcher_parser_get_filtering(filtering_str);
if (prop->name)
name = prop->name;
account_id = prop->account_id;
- if (account_id > 0) {
+ if (account_id > 0)
account_name = account_find_from_id(account_id)->account_name;
- } else {
- account_name = (gchar *)Q_("Filtering Account Menu|All");
- }
enabled = prop->enabled;
}
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."));
}
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."));
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);
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;
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);
}
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);
}
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);
}
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);
}
static void prefs_filtering_select_set(FilteringProp *prop)
return result;
}
-static void prefs_filtering_list_view_get_rule_name(GtkWidget *list, gint row,
+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);
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),
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
*/
-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);