gnucash master: Multiple changes pushed

Robert Fewell bobit at code.gnucash.org
Thu Mar 12 09:16:11 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/41af84b9 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9fed4b46 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3556182a (commit)
	from  https://github.com/Gnucash/gnucash/commit/fee1bf00 (commit)



commit 41af84b93751087366f82f2d0d5da24970b5a673
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Mar 1 12:34:19 2020 +0000

    Only show invalid mappings dialog once
    
    When you select the type of information to display, the invalid mapping
    dialog is shown if necessary on each occasion so this commit changes
    that to show it once and then you can use the added button.

diff --git a/gnucash/gnome/dialog-imap-editor.c b/gnucash/gnome/dialog-imap-editor.c
index 76a7f351a..4dc512127 100644
--- a/gnucash/gnome/dialog-imap-editor.c
+++ b/gnucash/gnome/dialog-imap-editor.c
@@ -56,6 +56,13 @@ typedef enum
     ONLINE
 }GncListType;
 
+typedef struct
+{
+    guint inv_dialog_shown_bayes : 1;
+    guint inv_dialog_shown_nbayes : 1;
+    guint inv_dialog_shown_online : 1;
+}GncInvFlags;
+
 typedef struct
 {
     GtkWidget    *dialog;
@@ -80,6 +87,7 @@ typedef struct
     GtkWidget    *expand_button;
     GtkWidget    *collapse_button;
     GtkWidget    *remove_button;
+    GncInvFlags   inv_dialog_shown;
 }ImapDialog;
 
 
@@ -371,6 +379,13 @@ gnc_imap_invalid_maps_dialog (ImapDialog *imap_dialog)
         else
         {
             gtk_widget_show (imap_dialog->remove_button);
+
+            if (imap_dialog->type == BAYES)
+                imap_dialog->inv_dialog_shown.inv_dialog_shown_bayes = TRUE;
+            if (imap_dialog->type == NBAYES)
+                imap_dialog->inv_dialog_shown.inv_dialog_shown_nbayes = TRUE;
+            if (imap_dialog->type == ONLINE)
+                imap_dialog->inv_dialog_shown.inv_dialog_shown_online = TRUE;
         }
         g_free (message);
         g_free (message2);
@@ -378,6 +393,24 @@ gnc_imap_invalid_maps_dialog (ImapDialog *imap_dialog)
     }
 }
 
+static void
+gnc_imap_invalid_maps (ImapDialog *imap_dialog)
+{
+    gboolean inv_dialog_shown = FALSE;
+
+    if ((imap_dialog->type == BAYES) && (imap_dialog->inv_dialog_shown.inv_dialog_shown_bayes))
+        inv_dialog_shown = TRUE;
+
+    if ((imap_dialog->type == NBAYES) && (imap_dialog->inv_dialog_shown.inv_dialog_shown_nbayes))
+        inv_dialog_shown = TRUE;
+
+    if ((imap_dialog->type == ONLINE) && (imap_dialog->inv_dialog_shown.inv_dialog_shown_online))
+        inv_dialog_shown = TRUE;
+
+    if (!inv_dialog_shown)
+        gnc_imap_invalid_maps_dialog (imap_dialog);
+}
+
 void
 gnc_imap_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
 {
@@ -519,9 +552,22 @@ list_type_selected_cb (GtkToggleButton* button, ImapDialog *imap_dialog)
     // Lets do this only on change of list type
     if (type != imap_dialog->type)
     {
+        gboolean inv_dialog_shown = FALSE;
+
         imap_dialog->type = type;
         get_account_info (imap_dialog);
-        gnc_imap_invalid_maps_dialog (imap_dialog);
+
+        if ((imap_dialog->type == BAYES) && (imap_dialog->inv_dialog_shown.inv_dialog_shown_bayes))
+            inv_dialog_shown = TRUE;
+
+        if ((imap_dialog->type == NBAYES) && (imap_dialog->inv_dialog_shown.inv_dialog_shown_nbayes))
+            inv_dialog_shown = TRUE;
+
+        if ((imap_dialog->type == ONLINE) && (imap_dialog->inv_dialog_shown.inv_dialog_shown_online))
+            inv_dialog_shown = TRUE;
+
+        if (!inv_dialog_shown)
+            gnc_imap_invalid_maps_dialog (imap_dialog);
     }
 }
 

commit 9fed4b464fe259be31d97e97452524ba18a54cc7
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Mar 1 11:59:04 2020 +0000

    Bug 797612 - Add a dialog to the imap_dialog to show invalid maps
    
    When imap_dialog is opened, check the tot_invalid_maps value to see if
    there were any invalid maps and present a dialog to allow the user to
    remove them now, if not add a button to imap_dialog so it can be done
    later.

diff --git a/gnucash/gnome/dialog-imap-editor.c b/gnucash/gnome/dialog-imap-editor.c
index d88b31886..76a7f351a 100644
--- a/gnucash/gnome/dialog-imap-editor.c
+++ b/gnucash/gnome/dialog-imap-editor.c
@@ -31,6 +31,7 @@
 #include "gnc-component-manager.h"
 #include "gnc-session.h"
 
+#include "gnc-ui.h"
 #include "gnc-ui-util.h"
 #include "Account.h"
 
@@ -72,9 +73,13 @@ typedef struct
     GtkWidget    *filter_label;
     gboolean      apply_selection_filter;
 
+    GtkWidget    *total_entries_label;
+    gint          tot_entries;
+    gint          tot_invalid_maps;
 
     GtkWidget    *expand_button;
     GtkWidget    *collapse_button;
+    GtkWidget    *remove_button;
 }ImapDialog;
 
 
@@ -146,6 +151,12 @@ delete_selected_row (ImapDialog *imap_dialog, GtkTreeIter *iter)
     gchar       *head;
     gchar       *category;
     gchar       *match_string;
+    gint         num = 0;
+    GtkTreeIter  parent;
+
+    // get the parent iter and see how many children it has, if 1 we will remove
+    if (gtk_tree_model_iter_parent (imap_dialog->model, &parent, iter))
+        num = gtk_tree_model_iter_n_children (imap_dialog->model, &parent);
 
     gtk_tree_model_get (imap_dialog->model, iter, SOURCE_ACCOUNT, &source_account,
                                                   SOURCE_FULL_ACC, &full_source_account,
@@ -174,7 +185,15 @@ delete_selected_row (ImapDialog *imap_dialog, GtkTreeIter *iter)
 
         if (imap_dialog->type == NBAYES)
             delete_info_nbayes (source_account, head, category, match_string, depth);
+
+        gtk_tree_store_remove (GTK_TREE_STORE(imap_dialog->model), iter);
+
+        if (num == 1 && (imap_dialog->type != ONLINE))
+            gtk_tree_store_remove (GTK_TREE_STORE(imap_dialog->model), &parent);
     }
+    // Clear the total
+    gtk_label_set_text (GTK_LABEL(imap_dialog->total_entries_label), " ");
+
     if (head)
         g_free (head);
     if (category)
@@ -185,6 +204,30 @@ delete_selected_row (ImapDialog *imap_dialog, GtkTreeIter *iter)
         g_free (full_source_account);
 }
 
+static gboolean
+find_invalid_mappings_total (GtkTreeModel *model, GtkTreePath *path,
+                             GtkTreeIter *iter, ImapDialog *imap_dialog)
+{
+    Account *source_account = NULL;
+    Account *map_account = NULL;
+    gchar   *head;
+    gint     depth;
+
+    gtk_tree_model_get (model, iter, SOURCE_ACCOUNT, &source_account,
+                                     MAP_ACCOUNT, &map_account,
+                                     HEAD, &head, -1);
+
+    depth = gtk_tree_path_get_depth (path);
+
+    if ((source_account != NULL) && (map_account == NULL))
+    {
+        if (((g_strcmp0 (head, "online_id") == 0) && (depth == 1)) || (depth == 2))
+            imap_dialog->tot_invalid_maps ++;
+    }
+    g_free (head);
+    return FALSE;
+}
+
 static void
 gnc_imap_dialog_delete (ImapDialog *imap_dialog)
 {
@@ -203,6 +246,9 @@ gnc_imap_dialog_delete (ImapDialog *imap_dialog)
     if (g_list_length (list) == 0)
         return;
 
+    // reset the invalid map total
+    imap_dialog->tot_invalid_maps = 0;
+
     // reverse list
     list = g_list_reverse (list);
 
@@ -221,10 +267,115 @@ gnc_imap_dialog_delete (ImapDialog *imap_dialog)
     g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
     g_list_free (list);
 
-    get_account_info (imap_dialog);
+    // Enable GUI refresh again
+    gnc_resume_gui_refresh();
+
+    // recount the number of invalid maps
+    gtk_tree_model_foreach (imap_dialog->model,
+                            (GtkTreeModelForeachFunc)find_invalid_mappings_total,
+                            imap_dialog);
+
+    if (imap_dialog->tot_invalid_maps == 0)
+        gtk_widget_hide (imap_dialog->remove_button);
+
+}
+
+static gboolean
+find_invalid_mappings (GtkTreeModel *model, GtkTreePath *path,
+                         GtkTreeIter *iter, GList **rowref_list)
+{
+    Account *source_account = NULL;
+    Account *map_account = NULL;
+    gchar   *head;
+    gint     depth;
+
+    gtk_tree_model_get (model, iter, SOURCE_ACCOUNT, &source_account,
+                                     MAP_ACCOUNT, &map_account,
+                                     HEAD, &head, -1);
+
+    depth = gtk_tree_path_get_depth (path);
+
+    if ((source_account != NULL) && (map_account == NULL))
+    {
+        if (((g_strcmp0 (head, "online_id") == 0) && (depth == 1)) || (depth == 2))
+        {
+             GtkTreeRowReference *rowref = gtk_tree_row_reference_new (model, path);
+             *rowref_list = g_list_append (*rowref_list, rowref);
+        }
+    }
+    g_free (head);
+    return FALSE;
+}
+
+static void
+gnc_imap_remove_invalid_maps (ImapDialog *imap_dialog)
+{
+    GList *rr_list = NULL;
+    GList *node;
+
+    gtk_tree_model_foreach (imap_dialog->model,
+                            (GtkTreeModelForeachFunc)find_invalid_mappings,
+                            &rr_list);
+
+    // reverse the reference list
+    rr_list = g_list_reverse (rr_list);
+
+    // Suspend GUI refreshing
+    gnc_suspend_gui_refresh();
+
+    // Walk the list
+    for (node = rr_list; node != NULL; node = node->next)
+    {
+        GtkTreePath *path = gtk_tree_row_reference_get_path ((GtkTreeRowReference*)node->data);
+
+        if (path)
+        {
+            GtkTreeIter iter;
+
+            if (gtk_tree_model_get_iter (GTK_TREE_MODEL(imap_dialog->model), &iter, path))
+                delete_selected_row (imap_dialog, &iter);
+
+            gtk_tree_path_free (path);
+        }
+    }
 
     // Enable GUI refresh again
     gnc_resume_gui_refresh();
+
+    g_list_foreach (rr_list, (GFunc)gtk_tree_row_reference_free, NULL);
+    g_list_free (rr_list);
+}
+
+static void
+gnc_imap_invalid_maps_dialog (ImapDialog *imap_dialog)
+{
+    gtk_widget_hide (imap_dialog->remove_button);
+
+    if (imap_dialog->tot_invalid_maps > 0)
+    {
+        /* Translators: This is a ngettext(3) message, %d is the number of maps missing */
+        gchar *message = g_strdup_printf (ngettext ("There is %d invalid mapping,\n\nWould you like to remove it now?",
+                                                    "There are %d invalid mappings,\n\nWould you like to remove them now?",
+                                                    imap_dialog->tot_invalid_maps),
+                                                    imap_dialog->tot_invalid_maps);
+
+        gchar *message2 = g_strdup_printf (gettext ("To see the invalid mappings, use a filter of '%s'"), _("Map Account NOT found"));
+
+        gchar *text = g_strdup_printf ("%s\n\n%s\n\n%s", message, message2, _("(Note, if there is a large number, it may take a while)"));
+
+        if (gnc_verify_dialog (GTK_WINDOW (imap_dialog->dialog), FALSE, "%s", text))
+        {
+            gnc_imap_remove_invalid_maps (imap_dialog);
+            gtk_widget_hide (imap_dialog->remove_button);
+        }
+        else
+        {
+            gtk_widget_show (imap_dialog->remove_button);
+        }
+        g_free (message);
+        g_free (message2);
+        g_free (text);
+    }
 }
 
 void
@@ -238,6 +389,10 @@ gnc_imap_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_
         gnc_imap_dialog_delete (imap_dialog);
         return;
 
+    case GTK_RESPONSE_REJECT:
+        gnc_imap_invalid_maps_dialog (imap_dialog);
+        return;
+
     case GTK_RESPONSE_CLOSE:
     default:
         gnc_close_gui_component_by_data (DIALOG_IMAP_CM_CLASS, imap_dialog);
@@ -366,6 +521,7 @@ list_type_selected_cb (GtkToggleButton* button, ImapDialog *imap_dialog)
     {
         imap_dialog->type = type;
         get_account_info (imap_dialog);
+        gnc_imap_invalid_maps_dialog (imap_dialog);
     }
 }
 
@@ -395,10 +551,18 @@ add_to_store (ImapDialog *imap_dialog, GtkTreeIter *iter, const gchar *text, Gnc
 
     // Do we have a valid map account
     if (imapInfo->map_account == NULL)
+    {
+        // count the total invalid maps
+        imap_dialog->tot_invalid_maps ++;
+
         map_fullname = g_strdup (_("Map Account NOT found"));
+    }
     else
         map_fullname = gnc_account_get_full_name (imapInfo->map_account);
 
+    // count the total entries
+    imap_dialog->tot_entries ++;
+
     PINFO("Add to Store: Source Acc '%s', Head is '%s', Category is '%s', Match '%s', Map Acc '%s', Count is %s",
           fullname, imapInfo->head, imapInfo->category, imapInfo->match_string, map_fullname, imapInfo->count);
 
@@ -581,11 +745,15 @@ get_account_info (ImapDialog *imap_dialog)
     Account      *root;
     GList        *accts;
     GtkTreeModel *fmodel;
+    gchar        *total;
 
     /* Get list of Accounts */
     root = gnc_book_get_root_account (gnc_get_current_book());
     accts = gnc_account_get_descendants_sorted (root);
 
+    imap_dialog->tot_entries = 0;
+    imap_dialog->tot_invalid_maps = 0;
+
     fmodel = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
 
     imap_dialog->model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(fmodel));
@@ -633,6 +801,17 @@ get_account_info (ImapDialog *imap_dialog)
     // if there are any entries, show first row
     show_first_row (imap_dialog);
 
+    // add the totals
+    total = g_strdup_printf ("%s %d", _("Total Entries"), imap_dialog->tot_entries);
+    gtk_label_set_text (GTK_LABEL(imap_dialog->total_entries_label), total);
+    gtk_widget_show (imap_dialog->total_entries_label);
+    g_free (total);
+
+    if (imap_dialog->tot_invalid_maps > 0)
+        gtk_widget_show (imap_dialog->remove_button);
+    else
+        gtk_widget_hide (imap_dialog->remove_button);
+
     g_list_free (accts);
 }
 
@@ -681,8 +860,8 @@ gnc_imap_dialog_create (GtkWidget *parent, ImapDialog *imap_dialog)
     dialog = GTK_WIDGET(gtk_builder_get_object (builder, "import_map_dialog"));
     imap_dialog->dialog = dialog;
 
-    // Set the style context for this dialog so it can be easily manipulated with css
-    gnc_widget_set_style_context (GTK_WIDGET(dialog), "GncImapDialog");
+    // Set the name for this dialog so it can be easily manipulated with css
+    gtk_widget_set_name (GTK_WIDGET(dialog), "gnc-id-import-map");
 
     imap_dialog->session = gnc_get_current_session();
     imap_dialog->type = BAYES;
@@ -700,6 +879,7 @@ gnc_imap_dialog_create (GtkWidget *parent, ImapDialog *imap_dialog)
     g_signal_connect (imap_dialog->radio_nbayes, "toggled",
                       G_CALLBACK(list_type_selected_cb), (gpointer)imap_dialog);
 
+    imap_dialog->total_entries_label = GTK_WIDGET(gtk_builder_get_object (builder, "total_entries_label"));
     imap_dialog->filter_text_entry = GTK_WIDGET(gtk_builder_get_object (builder, "filter-text-entry"));
     imap_dialog->filter_label = GTK_WIDGET(gtk_builder_get_object (builder, "filter-label"));
     imap_dialog->filter_button = GTK_WIDGET(gtk_builder_get_object (builder, "filter-button"));
@@ -716,6 +896,8 @@ gnc_imap_dialog_create (GtkWidget *parent, ImapDialog *imap_dialog)
 
     imap_dialog->view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));
 
+    imap_dialog->remove_button = GTK_WIDGET(gtk_builder_get_object (builder, "remove_button"));
+
     // Set filter column
     filter = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
     gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER(filter), FILTER);
@@ -810,5 +992,7 @@ gnc_imap_dialog (GtkWidget *parent)
     gnc_gui_component_set_session (component_id, imap_dialog->session);
 
     gtk_widget_show (imap_dialog->dialog);
+    gtk_widget_hide (imap_dialog->remove_button);
+    gnc_imap_invalid_maps_dialog (imap_dialog);
     LEAVE(" ");
 }
diff --git a/gnucash/gtkbuilder/dialog-imap-editor.glade b/gnucash/gtkbuilder/dialog-imap-editor.glade
index e4fd3dba9..c1e61c8cc 100644
--- a/gnucash/gtkbuilder/dialog-imap-editor.glade
+++ b/gnucash/gtkbuilder/dialog-imap-editor.glade
@@ -50,6 +50,20 @@
           <object class="GtkButtonBox" id="dialog-action_area1">
             <property name="can_focus">False</property>
             <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="remove_button">
+                <property name="label" translatable="yes">_Remove Invalid Mappings</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="no_show_all">True</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkButton" id="delete_button">
                 <property name="label" translatable="yes">_Delete</property>
@@ -61,7 +75,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">0</property>
+                <property name="position">1</property>
               </packing>
             </child>
             <child>
@@ -77,7 +91,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </object>
@@ -85,7 +99,7 @@
             <property name="expand">False</property>
             <property name="fill">False</property>
             <property name="pack_type">end</property>
-            <property name="position">0</property>
+            <property name="position">3</property>
           </packing>
         </child>
         <child>
@@ -98,7 +112,7 @@
           <packing>
             <property name="expand">False</property>
             <property name="fill">False</property>
-            <property name="position">1</property>
+            <property name="position">0</property>
           </packing>
         </child>
         <child>
@@ -161,7 +175,7 @@
           <packing>
             <property name="expand">False</property>
             <property name="fill">False</property>
-            <property name="position">2</property>
+            <property name="position">1</property>
           </packing>
         </child>
         <child>
@@ -251,6 +265,22 @@
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="total_entries_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="margin_left">6</property>
+            <property name="margin_right">6</property>
+            <property name="margin_top">3</property>
+            <property name="margin_bottom">3</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="position">3</property>
           </packing>
         </child>
@@ -261,6 +291,9 @@
             <property name="margin_top">5</property>
             <property name="margin_bottom">5</property>
             <property name="label" translatable="yes">Filter will be applied to 'Match String' and 'Mapped to Account Name' fields, case sensitive.</property>
+            <style>
+              <class name="gnc-class-highlight"/>
+            </style>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -327,7 +360,7 @@
             </child>
             <child>
               <object class="GtkButton" id="collapse-button">
-                <property name="label" translatable="yes">_Collapse All</property>
+                <property name="label" translatable="yes">Collapse _All</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
@@ -374,6 +407,7 @@
       </object>
     </child>
     <action-widgets>
+      <action-widget response="-2">remove_button</action-widget>
       <action-widget response="-10">delete_button</action-widget>
       <action-widget response="-6">close_button</action-widget>
     </action-widgets>

commit 3556182ab5f6e9bf5970beff0e05ae07ebaaf056
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Mar 1 11:32:04 2020 +0000

    Add the model to the imap_dialog structure for convenience

diff --git a/gnucash/gnome/dialog-imap-editor.c b/gnucash/gnome/dialog-imap-editor.c
index 5bc4962c5..d88b31886 100644
--- a/gnucash/gnome/dialog-imap-editor.c
+++ b/gnucash/gnome/dialog-imap-editor.c
@@ -60,6 +60,7 @@ typedef struct
     GtkWidget    *dialog;
     QofSession   *session;
     GtkWidget    *view;
+    GtkTreeModel *model;
     GncListType   type;
 
     GtkWidget    *radio_bayes;
@@ -138,7 +139,7 @@ delete_info_nbayes (Account *source_account, gchar *head,
 }
 
 static void
-delete_selected_row (GtkTreeModel *model, GtkTreeIter *iter, ImapDialog *imap_dialog)
+delete_selected_row (ImapDialog *imap_dialog, GtkTreeIter *iter)
 {
     Account     *source_account = NULL;
     gchar       *full_source_account;
@@ -146,8 +147,11 @@ delete_selected_row (GtkTreeModel *model, GtkTreeIter *iter, ImapDialog *imap_di
     gchar       *category;
     gchar       *match_string;
 
-    gtk_tree_model_get (model, iter, SOURCE_ACCOUNT, &source_account, SOURCE_FULL_ACC, &full_source_account,
-                                     HEAD, &head, CATEGORY, &category, MATCH_STRING, &match_string, -1);
+    gtk_tree_model_get (imap_dialog->model, iter, SOURCE_ACCOUNT, &source_account,
+                                                  SOURCE_FULL_ACC, &full_source_account,
+                                                  HEAD, &head,
+                                                  CATEGORY, &category,
+                                                  MATCH_STRING, &match_string, -1);
 
     PINFO("Account is '%s', Head is '%s', Category is '%s', Match String is '%s'",
            full_source_account, head, category, match_string);
@@ -158,7 +162,7 @@ delete_selected_row (GtkTreeModel *model, GtkTreeIter *iter, ImapDialog *imap_di
         gint         depth;
 
         // Get the level we are at in the tree-model
-        tree_path = gtk_tree_model_get_path (model, iter);
+        tree_path = gtk_tree_model_get_path (imap_dialog->model, iter);
         depth = gtk_tree_path_get_depth (tree_path);
         gtk_tree_path_free (tree_path);
 
@@ -185,14 +189,15 @@ static void
 gnc_imap_dialog_delete (ImapDialog *imap_dialog)
 {
     GList            *list, *row;
-    GtkTreeModel     *model;
+    GtkTreeModel     *fmodel;
+    GtkTreeIter       fiter;
     GtkTreeIter       iter;
     GtkTreeSelection *selection;
 
-    model = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
+    fmodel = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
     selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(imap_dialog->view));
 
-    list = gtk_tree_selection_get_selected_rows (selection, &model);
+    list = gtk_tree_selection_get_selected_rows (selection, &fmodel);
 
     // Make sure we have some rows selected
     if (g_list_length (list) == 0)
@@ -207,8 +212,11 @@ gnc_imap_dialog_delete (ImapDialog *imap_dialog)
     // Walk the list
     for (row = g_list_first (list); row; row = g_list_next (row))
     {
-        if (gtk_tree_model_get_iter (model, &iter, row->data))
-            delete_selected_row (model, &iter, imap_dialog);
+        if (gtk_tree_model_get_iter (fmodel, &fiter, row->data))
+        {
+            gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(fmodel), &iter, &fiter);
+            delete_selected_row (imap_dialog, &iter);
+        }
     }
     g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
     g_list_free (list);
@@ -238,8 +246,8 @@ gnc_imap_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_
 }
 
 static gboolean
-filter_test_and_move_next (GtkTreeModel *model, GtkTreeIter *iter,
-                           const gchar *filter_text, ImapDialog *imap_dialog)
+filter_test_and_move_next (ImapDialog *imap_dialog, GtkTreeIter *iter,
+                           const gchar *filter_text)
 {
     GtkTreePath *tree_path;
     gint         depth;
@@ -248,14 +256,14 @@ filter_test_and_move_next (GtkTreeModel *model, GtkTreeIter *iter,
     const gchar *map_full_acc;
 
     // Read the row
-    gtk_tree_model_get (model, iter, MATCH_STRING, &match_string, MAP_FULL_ACC, &map_full_acc, -1);
+    gtk_tree_model_get (imap_dialog->model, iter, MATCH_STRING, &match_string, MAP_FULL_ACC, &map_full_acc, -1);
 
     // Get the level we are at in the tree-model
-    tree_path = gtk_tree_model_get_path (model, iter);
+    tree_path = gtk_tree_model_get_path (imap_dialog->model, iter);
     depth = gtk_tree_path_get_depth (tree_path);
 
     // Reset filter to TRUE
-    gtk_tree_store_set (GTK_TREE_STORE(model), iter, FILTER, TRUE, -1);
+    gtk_tree_store_set (GTK_TREE_STORE(imap_dialog->model), iter, FILTER, TRUE, -1);
 
     // Check for a filter_text entry
     if (filter_text && *filter_text != '\0')
@@ -264,7 +272,7 @@ filter_test_and_move_next (GtkTreeModel *model, GtkTreeIter *iter,
         {
             if ((g_strrstr (match_string, filter_text) == NULL) &&
                 (g_strrstr (map_full_acc, filter_text) == NULL ))
-                gtk_tree_store_set (GTK_TREE_STORE(model), iter, FILTER, FALSE, -1);
+                gtk_tree_store_set (GTK_TREE_STORE(imap_dialog->model), iter, FILTER, FALSE, -1);
             else
                 gtk_tree_view_expand_to_path (GTK_TREE_VIEW(imap_dialog->view), tree_path);
         }
@@ -275,14 +283,14 @@ filter_test_and_move_next (GtkTreeModel *model, GtkTreeIter *iter,
     else
     {
         gtk_tree_path_next (tree_path);
-        if (!gtk_tree_model_get_iter (model, iter, tree_path))
+        if (!gtk_tree_model_get_iter (imap_dialog->model, iter, tree_path))
         {
             gtk_tree_path_prev (tree_path);
             gtk_tree_path_up (tree_path);
             gtk_tree_path_next (tree_path);
         }
     }
-    valid = gtk_tree_model_get_iter (model, iter, tree_path);
+    valid = gtk_tree_model_get_iter (imap_dialog->model, iter, tree_path);
 
     gtk_tree_path_free (tree_path);
 
@@ -292,14 +300,10 @@ filter_test_and_move_next (GtkTreeModel *model, GtkTreeIter *iter,
 static void
 filter_button_cb (GtkButton *button, ImapDialog *imap_dialog)
 {
-    GtkTreeModel *model, *filter;
     GtkTreeIter   iter;
     gboolean      valid;
     const gchar  *filter_text;
 
-    filter = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
-    model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(filter));
-
     filter_text = gtk_entry_get_text (GTK_ENTRY(imap_dialog->filter_text_entry));
 
     // Collapse all nodes
@@ -314,11 +318,11 @@ filter_button_cb (GtkButton *button, ImapDialog *imap_dialog)
     if (filter_text && *filter_text != '\0')
         imap_dialog->apply_selection_filter = TRUE;
 
-    valid = gtk_tree_model_get_iter_first (model, &iter);
+    valid = gtk_tree_model_get_iter_first (imap_dialog->model, &iter);
 
     while (valid)
     {
-        valid = filter_test_and_move_next (model, &iter, filter_text, imap_dialog);
+        valid = filter_test_and_move_next (imap_dialog, &iter, filter_text);
     }
     gtk_widget_grab_focus (GTK_WIDGET(imap_dialog->view));
 }
@@ -382,7 +386,7 @@ show_count_column (ImapDialog *imap_dialog, gboolean show)
 }
 
 static void
-add_to_store (GtkTreeModel *model, GtkTreeIter *iter, const gchar *text, GncImapInfo *imapInfo)
+add_to_store (ImapDialog *imap_dialog, GtkTreeIter *iter, const gchar *text, GncImapInfo *imapInfo)
 {
     gchar       *fullname = NULL;
     gchar       *map_fullname = NULL;
@@ -398,7 +402,7 @@ add_to_store (GtkTreeModel *model, GtkTreeIter *iter, const gchar *text, GncImap
     PINFO("Add to Store: Source Acc '%s', Head is '%s', Category is '%s', Match '%s', Map Acc '%s', Count is %s",
           fullname, imapInfo->head, imapInfo->category, imapInfo->match_string, map_fullname, imapInfo->count);
 
-    gtk_tree_store_set (GTK_TREE_STORE(model), iter,
+    gtk_tree_store_set (GTK_TREE_STORE(imap_dialog->model), iter,
                         SOURCE_FULL_ACC, fullname, SOURCE_ACCOUNT, imapInfo->source_account,
                         BASED_ON, text,
                         MATCH_STRING, imapInfo->match_string,
@@ -411,7 +415,7 @@ add_to_store (GtkTreeModel *model, GtkTreeIter *iter, const gchar *text, GncImap
 }
 
 static void
-get_imap_info (Account *acc, const gchar *category, GtkTreeModel *model, const gchar *text)
+get_imap_info (ImapDialog *imap_dialog, Account *acc, const gchar *category, const gchar *text)
 {
     GtkTreeIter  toplevel, child;
     GList *imap_list, *node;
@@ -436,8 +440,8 @@ get_imap_info (Account *acc, const gchar *category, GtkTreeModel *model, const g
         PINFO("List length is %d", g_list_length (imap_list));
 
         // Add top level entry of Source full Account and Based on.
-        gtk_tree_store_append (GTK_TREE_STORE(model), &toplevel, NULL);
-        gtk_tree_store_set (GTK_TREE_STORE(model), &toplevel,
+        gtk_tree_store_append (GTK_TREE_STORE(imap_dialog->model), &toplevel, NULL);
+        gtk_tree_store_set (GTK_TREE_STORE(imap_dialog->model), &toplevel,
                         SOURCE_ACCOUNT, acc, SOURCE_FULL_ACC, acc_name,
                         HEAD, head, CATEGORY, category, BASED_ON, text, FILTER, TRUE, -1);
 
@@ -446,8 +450,8 @@ get_imap_info (Account *acc, const gchar *category, GtkTreeModel *model, const g
             GncImapInfo *imapInfo = node->data;
 
             // First add a child entry and pass iter to add_to_store
-            gtk_tree_store_append (GTK_TREE_STORE(model), &child, &toplevel);
-            add_to_store (model, &child, text, imapInfo);
+            gtk_tree_store_append (GTK_TREE_STORE(imap_dialog->model), &child, &toplevel);
+            add_to_store (imap_dialog, &child, text, imapInfo);
 
             // Free the members and structure
             g_free (imapInfo->head);
@@ -464,14 +468,10 @@ get_imap_info (Account *acc, const gchar *category, GtkTreeModel *model, const g
 static void
 show_first_row (ImapDialog *imap_dialog)
 {
-    GtkTreeModel *model, *filter;
     GtkTreeIter   iter;
 
-    filter = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
-    model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(filter));
-
     // See if there are any entries
-    if (gtk_tree_model_get_iter_first (model, &iter))
+    if (gtk_tree_model_get_iter_first (imap_dialog->model, &iter))
     {
         GtkTreePath *path;
         path = gtk_tree_path_new_first (); // Set Path to first entry
@@ -481,7 +481,7 @@ show_first_row (ImapDialog *imap_dialog)
 }
 
 static void
-get_account_info_bayes (GList *accts, GtkTreeModel *model)
+get_account_info_bayes (ImapDialog *imap_dialog, GList *accts)
 {
     GList   *ptr;
 
@@ -490,12 +490,12 @@ get_account_info_bayes (GList *accts, GtkTreeModel *model)
     {
         Account *acc = ptr->data;
 
-        get_imap_info (acc, NULL, model, _("Bayesian"));
+        get_imap_info (imap_dialog, acc, NULL, _("Bayesian"));
     }
 }
 
 static void
-get_account_info_nbayes (GList *accts, GtkTreeModel *model)
+get_account_info_nbayes (ImapDialog *imap_dialog, GList *accts)
 {
     GList   *ptr;
 
@@ -505,18 +505,18 @@ get_account_info_nbayes (GList *accts, GtkTreeModel *model)
         Account *acc = ptr->data;
 
         // Description
-        get_imap_info (acc, IMAP_FRAME_DESC, model, _("Description Field"));
+        get_imap_info (imap_dialog, acc, IMAP_FRAME_DESC, _("Description Field"));
 
         // Memo
-        get_imap_info (acc, IMAP_FRAME_MEMO, model, _("Memo Field"));
+        get_imap_info (imap_dialog, acc, IMAP_FRAME_MEMO, _("Memo Field"));
 
         // CSV Account Map
-        get_imap_info (acc, IMAP_FRAME_CSV, model, _("CSV Account Map"));
+        get_imap_info (imap_dialog, acc, IMAP_FRAME_CSV, _("CSV Account Map"));
     }
 }
 
 static void
-get_account_info_online (GList *accts, GtkTreeModel *model)
+get_account_info_online (ImapDialog *imap_dialog, GList *accts)
 {
     GList       *ptr;
     GtkTreeIter  toplevel;
@@ -547,8 +547,8 @@ get_account_info_online (GList *accts, GtkTreeModel *model)
             imapInfo.count = " ";
 
             // Add top level entry and pass iter to add_to_store
-            gtk_tree_store_append (GTK_TREE_STORE(model), &toplevel, NULL);
-            add_to_store (model, &toplevel, _("Online Id"), &imapInfo);
+            gtk_tree_store_append (GTK_TREE_STORE(imap_dialog->model), &toplevel, NULL);
+            add_to_store (imap_dialog, &toplevel, _("Online Id"), &imapInfo);
         }
         g_free (text);
     }
@@ -580,22 +580,22 @@ get_account_info (ImapDialog *imap_dialog)
 {
     Account      *root;
     GList        *accts;
-    GtkTreeModel *model, *filter;
+    GtkTreeModel *fmodel;
 
     /* Get list of Accounts */
     root = gnc_book_get_root_account (gnc_get_current_book());
     accts = gnc_account_get_descendants_sorted (root);
 
-    filter = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
+    fmodel = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
 
-    model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(filter));
+    imap_dialog->model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(fmodel));
 
     // Disconnect the filter model from the treeview
-    g_object_ref (G_OBJECT(model));
+    g_object_ref (G_OBJECT(imap_dialog->model));
     gtk_tree_view_set_model (GTK_TREE_VIEW(imap_dialog->view), NULL);
 
     // Clear the tree store
-    gtk_tree_store_clear (GTK_TREE_STORE(model));
+    gtk_tree_store_clear (GTK_TREE_STORE(imap_dialog->model));
 
     // Clear the filter
     gtk_entry_set_text (GTK_ENTRY(imap_dialog->filter_text_entry), "");
@@ -609,26 +609,26 @@ get_account_info (ImapDialog *imap_dialog)
 
     if (imap_dialog->type == BAYES)
     {
-        get_account_info_bayes (accts, model);
+        get_account_info_bayes (imap_dialog, accts);
 
         // Show Count Column
         show_count_column (imap_dialog, TRUE);
     }
     else if (imap_dialog->type == NBAYES)
-        get_account_info_nbayes (accts, model);
+        get_account_info_nbayes (imap_dialog, accts);
     else if (imap_dialog->type == ONLINE)
     {
         // Hide Filter Option
         show_filter_option (imap_dialog, FALSE);
-        get_account_info_online (accts, model);
+        get_account_info_online (imap_dialog, accts);
     }
     // create a new filter model and reconnect to treeview
-    filter = gtk_tree_model_filter_new (GTK_TREE_MODEL(model), NULL);
-    gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER(filter), FILTER);
-    g_object_unref (G_OBJECT(model));
+    fmodel = gtk_tree_model_filter_new (GTK_TREE_MODEL(imap_dialog->model), NULL);
+    gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER(fmodel), FILTER);
+    g_object_unref (G_OBJECT(imap_dialog->model));
 
-    gtk_tree_view_set_model (GTK_TREE_VIEW(imap_dialog->view), filter);
-    g_object_unref (G_OBJECT(filter));
+    gtk_tree_view_set_model (GTK_TREE_VIEW(imap_dialog->view), fmodel);
+    g_object_unref (G_OBJECT(fmodel));
 
     // if there are any entries, show first row
     show_first_row (imap_dialog);



Summary of changes:
 gnucash/gnome/dialog-imap-editor.c          | 350 +++++++++++++++++++++++-----
 gnucash/gtkbuilder/dialog-imap-editor.glade |  46 +++-
 2 files changed, 330 insertions(+), 66 deletions(-)



More information about the gnucash-changes mailing list