Skip to content

Commit

Permalink
Aqbanking transfer: Make IBAN and BIC text entry fields filter digits…
Browse files Browse the repository at this point in the history
… or alphas correctly as needed.
  • Loading branch information
cstim committed Sep 1, 2014
1 parent 18666f1 commit 8edb303
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 12 deletions.
93 changes: 83 additions & 10 deletions src/import-export/aqb/dialog-ab-trans.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions src/import-export/aqb/dialog-ab.glade
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 8edb303

Please sign in to comment.