gnucash master: Aqbanking transfer: Make IBAN and BIC text entry fields filter digits or alphas correctly as needed.

Christian Stimming cstim at code.gnucash.org
Mon Sep 1 14:58:55 EDT 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/8edb3031 (commit)
	from  https://github.com/Gnucash/gnucash/commit/18666f1e (commit)



commit 8edb3031430de4aaa71e7a7a1cb90993a7082244
Author: Christian Stimming <christian at cstimming.de>
Date:   Mon Sep 1 20:58:15 2014 +0200

    Aqbanking transfer: Make IBAN and BIC text entry fields filter digits or alphas correctly as needed.

diff --git a/src/import-export/aqb/dialog-ab-trans.c b/src/import-export/aqb/dialog-ab-trans.c
index c034fe8..355c0e8 100644
--- a/src/import-export/aqb/dialog-ab-trans.c
+++ b/src/import-export/aqb/dialog-ab-trans.c
@@ -82,7 +82,12 @@ G_MODULE_EXPORT void gnc_ab_trans_dialog_moveup_templ_cb(GtkButton *button, gpoi
 G_MODULE_EXPORT void gnc_ab_trans_dialog_movedown_templ_cb(GtkButton *button, gpointer user_data);
 G_MODULE_EXPORT void gnc_ab_trans_dialog_sort_templ_cb(GtkButton *button, gpointer user_data);
 G_MODULE_EXPORT void gnc_ab_trans_dialog_del_templ_cb(GtkButton *button, gpointer user_data);
-G_MODULE_EXPORT void gnc_ab_trans_dialog_entry_filter_cb (GtkEditable *editable,
+G_MODULE_EXPORT void gnc_ab_trans_dialog_ibanentry_filter_cb (GtkEditable *editable,
+        const gchar *text,
+        gint         length,
+        gint        *position,
+        gpointer     user_data);
+G_MODULE_EXPORT void gnc_ab_trans_dialog_bicentry_filter_cb (GtkEditable *editable,
         const gchar *text,
         gint         length,
         gint        *position,
@@ -1300,7 +1305,60 @@ gnc_ab_trans_dialog_del_templ_cb(GtkButton *button, gpointer user_data)
 }
 
 void
-gnc_ab_trans_dialog_entry_filter_cb (GtkEditable *editable,
+gnc_ab_trans_dialog_ibanentry_filter_cb (GtkEditable *editable,
+                                     const gchar *text,
+                                     gint         length,
+                                     gint        *position,
+                                     gpointer     data)
+{
+    GString* result = g_string_new(NULL);
+    gint i;
+    GncABTransDialog *td = data;
+
+    if (length == -1)
+        length = strlen(text);
+    g_assert(position);
+
+    /* Filter digits / non digits as needed */
+    for (i = 0; i < length; i++)
+    {
+        gchar c = text[i];
+
+        if (gnc_ab_trans_isSEPA(td->trans_type))
+        {
+            // SEPA: Only alphas in the first two places (only upper case, though), then only digits
+            if (*position + i < 2)
+            {
+                if (g_ascii_isalpha(c))
+                    g_string_append_c(result, g_ascii_toupper(c));
+            }
+            else
+            {
+                if (g_ascii_isdigit(c))
+                    g_string_append_c(result, c);
+            }
+        }
+        else
+        {
+            // Non-SEPA: Only accept digits.
+            if (g_ascii_isdigit(c))
+            {
+                g_string_append_c(result, c);
+            }
+        }
+    }
+
+    g_signal_handlers_block_by_func (editable,
+                                     (gpointer) gnc_ab_trans_dialog_ibanentry_filter_cb, data);
+    gtk_editable_insert_text (editable, result->str, result->len, position);
+    g_signal_handlers_unblock_by_func (editable,
+                                       (gpointer) gnc_ab_trans_dialog_ibanentry_filter_cb, data);
+    g_signal_stop_emission_by_name (editable, "insert_text");
+    g_string_free (result, TRUE);
+}
+
+void
+gnc_ab_trans_dialog_bicentry_filter_cb (GtkEditable *editable,
                                      const gchar *text,
                                      gint         length,
                                      gint        *position,
@@ -1312,27 +1370,42 @@ gnc_ab_trans_dialog_entry_filter_cb (GtkEditable *editable,
 
     if (length == -1)
         length = strlen(text);
+    g_assert(position);
 
     /* Filter non digits */
     for (i = 0; i < length; i++)
     {
         gchar c = text[i];
 
-        // Only accept digits. FIXME: In the SEPA dialogs, alphanumerics are
-        // allowed, but we could also verify the input according to actual BIC
-        // and IBAN rules. This is not yet done here.
-        if (g_ascii_isdigit(c)
-                || (gnc_ab_trans_isSEPA(td->trans_type) && g_ascii_isalnum(c)))
+        if (gnc_ab_trans_isSEPA(td->trans_type))
+        {
+            // SEPA: Only alphas in the first 6 places (only upper case, though), then both upper-case alphas and digits
+            if (*position + i < 6)
+            {
+                if (g_ascii_isalpha(c))
+                    g_string_append_c(result, g_ascii_toupper(c));
+            }
+            else
+            {
+                if (g_ascii_isalnum(c))
+                    g_string_append_c(result, g_ascii_toupper(c));
+            }
+        }
+        else
         {
-            g_string_append_c(result, c);
+            // Non-SEPA: Only digits accepted.
+            if (g_ascii_isdigit(c))
+            {
+                g_string_append_c(result, c);
+            }
         }
     }
 
     g_signal_handlers_block_by_func (editable,
-                                     (gpointer) gnc_ab_trans_dialog_entry_filter_cb, data);
+                                     (gpointer) gnc_ab_trans_dialog_bicentry_filter_cb, data);
     gtk_editable_insert_text (editable, result->str, result->len, position);
     g_signal_handlers_unblock_by_func (editable,
-                                       (gpointer) gnc_ab_trans_dialog_entry_filter_cb, data);
+                                       (gpointer) gnc_ab_trans_dialog_bicentry_filter_cb, data);
     g_signal_stop_emission_by_name (editable, "insert_text");
     g_string_free (result, TRUE);
 }
diff --git a/src/import-export/aqb/dialog-ab.glade b/src/import-export/aqb/dialog-ab.glade
index d2bb114..543e06d 100644
--- a/src/import-export/aqb/dialog-ab.glade
+++ b/src/import-export/aqb/dialog-ab.glade
@@ -1023,7 +1023,7 @@
                     <property name="primary_icon_activatable">False</property>
                     <property name="secondary_icon_activatable">False</property>
                     <signal name="changed" handler="gnc_ab_trans_dialog_verify_values" swapped="yes"/>
-                    <signal name="insert-text" handler="gnc_ab_trans_dialog_entry_filter_cb" swapped="no"/>
+                    <signal name="insert-text" handler="gnc_ab_trans_dialog_ibanentry_filter_cb" swapped="no"/>
                   </object>
                   <packing>
                     <property name="top_attach">3</property>
@@ -1055,7 +1055,7 @@
                     <property name="primary_icon_activatable">False</property>
                     <property name="secondary_icon_activatable">False</property>
                     <signal name="changed" handler="gnc_ab_trans_dialog_bankcode_changed_cb" swapped="no"/>
-                    <signal name="insert-text" handler="gnc_ab_trans_dialog_entry_filter_cb" swapped="no"/>
+                    <signal name="insert-text" handler="gnc_ab_trans_dialog_bicentry_filter_cb" swapped="no"/>
                   </object>
                   <packing>
                     <property name="left_attach">2</property>



Summary of changes:
 src/import-export/aqb/dialog-ab-trans.c | 93 +++++++++++++++++++++++++++++----
 src/import-export/aqb/dialog-ab.glade   |  4 +-
 2 files changed, 85 insertions(+), 12 deletions(-)



More information about the gnucash-changes mailing list