[evolution] Bug 271124 - Allow filter dialog to specify incoming vs outgoing
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 271124 - Allow filter dialog to specify incoming vs outgoing
- Date: Mon, 11 Sep 2017 14:55:38 +0000 (UTC)
commit 177846eee311df3d4e948c916303d60780acbc3c
Author: Milan Crha <mcrha redhat com>
Date: Mon Sep 11 16:56:10 2017 +0200
Bug 271124 - Allow filter dialog to specify incoming vs outgoing
src/e-util/e-rule-editor.c | 95 +++++++++++++++++++++++++++-----------------
src/mail/em-filter-rule.c | 37 +++++++++++++++++
2 files changed, 95 insertions(+), 37 deletions(-)
---
diff --git a/src/e-util/e-rule-editor.c b/src/e-util/e-rule-editor.c
index 2120fc1..a87da78 100644
--- a/src/e-util/e-rule-editor.c
+++ b/src/e-util/e-rule-editor.c
@@ -57,6 +57,22 @@ G_DEFINE_TYPE (
e_rule_editor,
GTK_TYPE_DIALOG)
+static gboolean
+update_selected_rule (ERuleEditor *editor)
+{
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ selection = gtk_tree_view_get_selection (editor->list);
+ if (selection && gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ gtk_tree_model_get (GTK_TREE_MODEL (editor->model), &iter, 1, &editor->current, -1);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
dialog_rule_changed (EFilterRule *fr,
GtkWidget *dialog)
@@ -75,6 +91,8 @@ add_editor_response (GtkWidget *dialog,
GtkTreePath *path;
GtkTreeIter iter;
+ g_signal_handlers_disconnect_by_func (editor->edit, G_CALLBACK (dialog_rule_changed), editor->dialog);
+
if (button == GTK_RESPONSE_OK) {
EAlert *alert = NULL;
if (!e_filter_rule_validate (editor->edit, &alert)) {
@@ -93,24 +111,30 @@ add_editor_response (GtkWidget *dialog,
g_object_ref (editor->edit);
- gtk_list_store_append (editor->model, &iter);
- gtk_list_store_set (
- editor->model, &iter,
- 0, editor->edit->name,
- 1, editor->edit,
- 2, editor->edit->enabled, -1);
- selection = gtk_tree_view_get_selection (editor->list);
- gtk_tree_selection_select_iter (selection, &iter);
-
- /* scroll to the newly added row */
- path = gtk_tree_model_get_path (
- GTK_TREE_MODEL (editor->model), &iter);
- gtk_tree_view_scroll_to_cell (
- editor->list, path, NULL, TRUE, 1.0, 0.0);
- gtk_tree_path_free (path);
+ e_rule_context_add_rule (editor->context, editor->edit);
+
+ if (g_strcmp0 (editor->source, editor->edit->source) == 0) {
+ gtk_list_store_append (editor->model, &iter);
+ gtk_list_store_set (
+ editor->model, &iter,
+ 0, editor->edit->name,
+ 1, editor->edit,
+ 2, editor->edit->enabled, -1);
+ selection = gtk_tree_view_get_selection (editor->list);
+ gtk_tree_selection_select_iter (selection, &iter);
+
+ /* scroll to the newly added row */
+ path = gtk_tree_model_get_path (
+ GTK_TREE_MODEL (editor->model), &iter);
+ gtk_tree_view_scroll_to_cell (
+ editor->list, path, NULL, TRUE, 1.0, 0.0);
+ gtk_tree_path_free (path);
- editor->current = editor->edit;
- e_rule_context_add_rule (editor->context, editor->current);
+ editor->current = editor->edit;
+ } else {
+ editor->current = NULL;
+ update_selected_rule (editor);
+ }
}
gtk_widget_destroy (dialog);
@@ -131,22 +155,6 @@ editor_destroy (ERuleEditor *editor,
e_rule_editor_set_sensitive (editor);
}
-static gboolean
-update_selected_rule (ERuleEditor *editor)
-{
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- selection = gtk_tree_view_get_selection (editor->list);
- if (selection && gtk_tree_selection_get_selected (selection, &model, &iter)) {
- gtk_tree_model_get (GTK_TREE_MODEL (editor->model), &iter, 1, &editor->current, -1);
- return TRUE;
- }
-
- return FALSE;
-}
-
static void
cursor_changed (GtkTreeView *treeview,
ERuleEditor *editor)
@@ -213,6 +221,8 @@ edit_editor_response (GtkWidget *dialog,
GtkTreeIter iter;
gint pos;
+ g_signal_handlers_disconnect_by_func (editor->edit, G_CALLBACK (dialog_rule_changed), editor->dialog);
+
if (button == GTK_RESPONSE_OK) {
EAlert *alert = NULL;
if (!e_filter_rule_validate (editor->edit, &alert)) {
@@ -246,12 +256,19 @@ edit_editor_response (GtkWidget *dialog,
GTK_TREE_MODEL (editor->model), &iter, path);
gtk_tree_path_free (path);
- gtk_list_store_set (
- editor->model, &iter,
- 0, editor->edit->name, -1);
-
/* replace the old rule with the new rule */
e_filter_rule_copy (editor->current, editor->edit);
+
+ if (g_strcmp0 (editor->source, editor->edit->source) == 0) {
+ gtk_list_store_set (
+ editor->model, &iter,
+ 0, editor->edit->name, -1);
+ } else {
+ gtk_list_store_remove (editor->model, &iter);
+ editor->current = NULL;
+
+ update_selected_rule (editor);
+ }
}
}
@@ -497,6 +514,8 @@ rule_editor_finalize (GObject *object)
g_object_unref (editor->context);
+ g_clear_pointer (&editor->source, g_free);
+
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_rule_editor_parent_class)->finalize (object);
}
@@ -760,6 +779,8 @@ e_rule_editor_construct (ERuleEditor *editor,
renderer = GTK_CELL_RENDERER (list->data);
g_warn_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (renderer));
+ g_list_free (list);
+
g_signal_connect (
renderer, "toggled",
G_CALLBACK (rule_able_toggled), editor->list);
diff --git a/src/mail/em-filter-rule.c b/src/mail/em-filter-rule.c
index 75df5a1..051126b 100644
--- a/src/mail/em-filter-rule.c
+++ b/src/mail/em-filter-rule.c
@@ -572,6 +572,20 @@ ensure_scrolled_height_cb (GtkAdjustment *adj,
ensure_scrolled_height (scrolled_window);
}
+static void
+filter_type_changed_cb (GtkComboBox *combobox,
+ EFilterRule *fr)
+{
+ const gchar *id;
+
+ g_return_if_fail (GTK_IS_COMBO_BOX (combobox));
+ g_return_if_fail (E_IS_FILTER_RULE (fr));
+
+ id = gtk_combo_box_get_active_id (combobox);
+ if (id && *id)
+ e_filter_rule_set_source (fr, id);
+}
+
static GtkWidget *
get_widget (EFilterRule *fr,
ERuleContext *rc)
@@ -591,6 +605,29 @@ get_widget (EFilterRule *fr,
widget = E_FILTER_RULE_CLASS (em_filter_rule_parent_class)->
get_widget (fr, rc);
+ g_warn_if_fail (GTK_IS_GRID (widget));
+
+ label = gtk_label_new_with_mnemonic (_("Rul_e type:"));
+ w = gtk_combo_box_text_new ();
+
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), w);
+
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (w), E_FILTER_SOURCE_INCOMING, _("Incoming"));
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (w), E_FILTER_SOURCE_OUTGOING, _("Outgoing"));
+
+ gtk_combo_box_set_active_id (GTK_COMBO_BOX (w), fr->source);
+
+ g_signal_connect (w, "changed", G_CALLBACK (filter_type_changed_cb), fr);
+
+ hgrid = GTK_GRID (gtk_grid_new ());
+ gtk_grid_set_column_spacing (hgrid, 12);
+
+ gtk_grid_attach (hgrid, label, 0, 0, 1, 1);
+ gtk_grid_attach_next_to (hgrid, w, label, GTK_POS_RIGHT, 1, 1);
+
+ gtk_grid_insert_row (GTK_GRID (widget), 1);
+ gtk_grid_attach (GTK_GRID (widget), GTK_WIDGET (hgrid), 0, 1, 1, 1);
+
/* and now for the action area */
msg = g_strdup_printf ("<b>%s</b>", _("Then"));
label = gtk_label_new (msg);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]