Bug 642824 - Check for Placeholder Accounts in Qif Import

Placeholder accounts do not allow transactions so when the account
picker dialog is presented, add an error dialog for placeholder
selection and a column to display that the account is a placeholder.
This commit is contained in:
Robert Fewell
2019-05-07 15:47:04 +01:00
parent ac0eb00141
commit bca3bd379e
2 changed files with 118 additions and 4 deletions

View File

@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkWindow" id="preferences_window">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Preferences</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkGrid" id="prefs_table">
<property name="visible">True</property>
@@ -141,6 +144,9 @@
<property name="default_width">300</property>
<property name="default_height">400</property>
<property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="visible">True</property>
@@ -248,6 +254,44 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="placeholder_warning_hbox">
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="margin_top">6</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="placeholder_warning_image">
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="stock">gtk-dialog-warning</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="placeholder_warning_label">
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>

View File

@@ -45,6 +45,7 @@ enum account_cols
{
ACCOUNT_COL_NAME = 0,
ACCOUNT_COL_FULLNAME,
ACCOUNT_COL_PLACEHOLDER,
ACCOUNT_COL_CHECK,
NUM_ACCOUNT_COLS
};
@@ -53,8 +54,11 @@ struct _accountpickerdialog
{
GtkWidget * dialog;
GtkTreeView * treeview;
GtkWidget * pwhbox;
GtkWidget * pwarning;
GtkWidget * ok_button;
QIFImportWindow * qif_wind;
SCM map_entry;
SCM map_entry;
gchar * selected_name;
};
@@ -83,9 +87,11 @@ acct_tree_add_accts(SCM accts,
gboolean leafnode;
SCM current;
gboolean checked;
Account * account;
while (!scm_is_null(accts))
{
gboolean placeholder = FALSE;
current = SCM_CAR(accts);
if (scm_is_null(current))
@@ -122,10 +128,15 @@ acct_tree_add_accts(SCM accts,
checked = (SCM_CADR(current) == SCM_BOOL_T);
account = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), acctname);
if (account)
placeholder = xaccAccountGetPlaceholder (account);
gtk_tree_store_append(store, &iter, parent);
gtk_tree_store_set(store, &iter,
ACCOUNT_COL_NAME, compname,
ACCOUNT_COL_FULLNAME, acctname,
ACCOUNT_COL_PLACEHOLDER, placeholder,
ACCOUNT_COL_CHECK, checked,
-1);
@@ -267,15 +278,34 @@ gnc_ui_qif_account_picker_changed_cb(GtkTreeSelection *selection,
SCM name_setter = scm_c_eval_string("qif-map-entry:set-gnc-name!");
GtkTreeModel *model;
GtkTreeIter iter;
gboolean placeholder;
gtk_widget_set_sensitive (wind->ok_button, TRUE); // enable OK button
g_free(wind->selected_name);
if (gtk_tree_selection_get_selected(selection, &model, &iter))
{
gtk_tree_model_get(model, &iter,
ACCOUNT_COL_PLACEHOLDER, &placeholder,
ACCOUNT_COL_FULLNAME, &wind->selected_name,
-1);
scm_call_2(name_setter, wind->map_entry,
wind->selected_name ? scm_from_utf8_string(wind->selected_name) : SCM_BOOL_F);
if (placeholder)
{
gchar *text = g_strdup_printf (_("The account %s is a placeholder account and does not allow "
"transactions. Please choose a different account."), wind->selected_name);
gtk_label_set_text (GTK_LABEL(wind->pwarning), text);
gnc_label_set_alignment (wind->pwarning, 0.0, 0.5);
gtk_widget_show_all (GTK_WIDGET(wind->pwhbox));
g_free (text);
gtk_widget_set_sensitive (wind->ok_button, FALSE); // disable OK button
}
else
gtk_widget_hide (GTK_WIDGET(wind->pwhbox)); // hide the placeholder warning
}
else
{
@@ -318,6 +348,31 @@ gnc_ui_qif_account_picker_map_cb(GtkWidget * w, gpointer user_data)
}
/****************************************************************
* dialog_response_cb
*
****************************************************************/
static void
dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
{
QIFAccountPickerDialog * wind = user_data;
GtkTreeModel *model;
GtkTreeIter iter;
gboolean placeholder;
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection
(wind->treeview), &model, &iter))
gtk_tree_model_get (model, &iter,
ACCOUNT_COL_PLACEHOLDER, &placeholder, -1);
if (response_id == GTK_RESPONSE_OK)
{
if (placeholder)
g_signal_stop_emission_by_name (dialog, "response");
}
}
/****************************************************************
* qif_account_picker_dialog
*
@@ -354,18 +409,21 @@ qif_account_picker_dialog(GtkWindow *parent, QIFImportWindow * qif_wind, SCM map
wind->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "qif_import_account_picker_dialog"));
wind->treeview = GTK_TREE_VIEW(gtk_builder_get_object (builder, "account_tree"));
wind->pwhbox = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_warning_hbox"));
wind->pwarning = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_warning_label"));
wind->ok_button = GTK_WIDGET(gtk_builder_get_object (builder, "okbutton"));
wind->qif_wind = qif_wind;
gtk_window_set_transient_for (GTK_WINDOW (wind->dialog), parent);
{
GtkTreeSelection *selection;
GtkTreeStore *store;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
store = gtk_tree_store_new(NUM_ACCOUNT_COLS, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_BOOLEAN);
G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
gtk_tree_view_set_model(wind->treeview, GTK_TREE_MODEL(store));
g_object_unref(store);
@@ -378,6 +436,15 @@ qif_account_picker_dialog(GtkWindow *parent, QIFImportWindow * qif_wind, SCM map
g_object_set(column, "expand", TRUE, NULL);
gtk_tree_view_append_column(wind->treeview, column);
renderer = gtk_cell_renderer_toggle_new();
g_object_set(renderer, "activatable", FALSE, NULL);
column = gtk_tree_view_column_new_with_attributes(_("Placeholder?"),
renderer,
"active",
ACCOUNT_COL_PLACEHOLDER,
NULL);
gtk_tree_view_append_column(wind->treeview, column);
renderer = gtk_cell_renderer_toggle_new();
g_object_set(renderer, "activatable", FALSE, NULL);
column = gtk_tree_view_column_new_with_attributes(_("New?"),
@@ -406,6 +473,9 @@ qif_account_picker_dialog(GtkWindow *parent, QIFImportWindow * qif_wind, SCM map
* again after the window is mapped. */
build_acct_tree(wind, wind->qif_wind);
g_signal_connect (wind->dialog, "response",
G_CALLBACK (dialog_response_cb), wind);
do
{
response = gtk_dialog_run(GTK_DIALOG(wind->dialog));