CsvTransExp - remove redundant counter num_accounts

Simply use length of account list instead
This commit is contained in:
Geert Janssens 2023-02-14 17:24:11 +01:00
parent 545f27c550
commit 1d971c1578
3 changed files with 19 additions and 25 deletions

View File

@ -378,7 +378,7 @@ show_acct_type_accounts (CsvExportInfo *info)
* *
* update the account tree * update the account tree
*******************************************************/ *******************************************************/
static int static void
update_accounts_tree (CsvExportInfo *info) update_accounts_tree (CsvExportInfo *info)
{ {
GncTreeViewAccount *tree; GncTreeViewAccount *tree;
@ -396,8 +396,6 @@ update_accounts_tree (CsvExportInfo *info)
string = g_strdup_printf ("%d", num_accounts); string = g_strdup_printf ("%d", num_accounts);
gtk_label_set_text (GTK_LABEL (label), string); gtk_label_set_text (GTK_LABEL (label), string);
g_free (string); g_free (string);
return num_accounts;
} }
@ -410,22 +408,22 @@ static void
csv_export_account_changed_cb (GtkTreeSelection *selection, csv_export_account_changed_cb (GtkTreeSelection *selection,
gpointer user_data) gpointer user_data)
{ {
CsvExportInfo *info = user_data;
GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
GncTreeViewAccount *view;
g_return_if_fail(GTK_IS_TREE_SELECTION(selection)); g_return_if_fail(GTK_IS_TREE_SELECTION(selection));
info->csva.num_accounts = update_accounts_tree (info); CsvExportInfo *info = user_data;
GncTreeViewAccount *view = GNC_TREE_VIEW_ACCOUNT(info->csva.account_treeview);
info->csva.account_list = gnc_tree_view_account_get_selected_accounts (view);
/* Enable the "Next" Assistant Button if we have accounts */ /* Enable the "Next" Assistant Button if we have accounts */
if (info->csva.num_accounts > 0) GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
if (g_list_length (info->csva.account_list) > 0)
gtk_assistant_set_page_complete (assistant, info->account_page, TRUE); gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
else else
gtk_assistant_set_page_complete (assistant, info->account_page, FALSE); gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
view = GNC_TREE_VIEW_ACCOUNT(info->csva.account_treeview); update_accounts_tree (info);
info->csva.account_list = gnc_tree_view_account_get_selected_accounts (view);
} }
@ -692,7 +690,7 @@ csv_export_assistant_account_page_prepare (GtkAssistant *assistant,
CsvExportInfo *info = user_data; CsvExportInfo *info = user_data;
/* Enable the "Next" Assistant Button if we have accounts */ /* Enable the "Next" Assistant Button if we have accounts */
if (info->csva.num_accounts > 0) if (g_list_length(info->csva.account_list) > 0)
gtk_assistant_set_page_complete (assistant, info->account_page, TRUE); gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
else else
gtk_assistant_set_page_complete (assistant, info->account_page, FALSE); gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
@ -730,7 +728,9 @@ csv_export_assistant_finish_page_prepare (GtkAssistant *assistant,
if ((info->export_type == XML_EXPORT_REGISTER) && (info->account == NULL)) if ((info->export_type == XML_EXPORT_REGISTER) && (info->account == NULL))
text = g_strdup_printf (gettext (finish_trans_search_gl_string), info->file_name); text = g_strdup_printf (gettext (finish_trans_search_gl_string), info->file_name);
else else
text = g_strdup_printf (gettext (finish_trans_string), info->file_name, info->csva.num_accounts); text = g_strdup_printf (gettext (finish_trans_string),
info->file_name,
g_list_length (info->csva.account_list));
} }
gtk_label_set_text (GTK_LABEL(info->finish_label), text); gtk_label_set_text (GTK_LABEL(info->finish_label), text);
g_free (text); g_free (text);
@ -802,6 +802,7 @@ csv_export_assistant_destroy_cb (GtkWidget *object, gpointer user_data)
{ {
CsvExportInfo *info = user_data; CsvExportInfo *info = user_data;
gnc_unregister_gui_component_by_data (ASSISTANT_CSV_EXPORT_CM_CLASS, info); gnc_unregister_gui_component_by_data (ASSISTANT_CSV_EXPORT_CM_CLASS, info);
g_list_free (info->csva.account_list);
g_free (info); g_free (info);
} }
@ -1013,7 +1014,7 @@ gnc_file_csv_export_internal (CsvExportType export_type, Query *q, Account *acc)
if (acc) if (acc)
info->account = acc; info->account = acc;
if ((export_type == XML_EXPORT_REGISTER) && acc) if ((export_type == XML_EXPORT_REGISTER) && acc)
info->csva.num_accounts = 1; info->csva.account_list = g_list_prepend(info->csva.account_list, acc);
csv_export_assistant_create (info); csv_export_assistant_create (info);
gnc_register_gui_component (ASSISTANT_CSV_EXPORT_CM_CLASS, gnc_register_gui_component (ASSISTANT_CSV_EXPORT_CM_CLASS,

View File

@ -62,7 +62,6 @@ typedef struct
GtkWidget *select_button; GtkWidget *select_button;
GtkWidget *num_acct_label; GtkWidget *num_acct_label;
GList *account_list; GList *account_list;
int num_accounts;
GNCAccountType account_type; GNCAccountType account_type;
} CsvExportAcc; } CsvExportAcc;

View File

@ -578,8 +578,6 @@ void csv_transactions_export (CsvExportInfo *info)
if (info->failed) if (info->failed)
return; return;
if (info->export_type == XML_EXPORT_TRANS)
{
/* Go through list of accounts */ /* Go through list of accounts */
for (GList *ptr = info->csva.account_list; ptr; ptr = g_list_next(ptr)) for (GList *ptr = info->csva.account_list; ptr; ptr = g_list_next(ptr))
{ {
@ -587,10 +585,6 @@ void csv_transactions_export (CsvExportInfo *info)
DEBUG("Account being processed is : %s", xaccAccountGetName (acc)); DEBUG("Account being processed is : %s", xaccAccountGetName (acc));
account_splits (info, acc, fh); account_splits (info, acc, fh);
} }
g_list_free (info->csva.account_list);
}
else
account_splits (info, info->account, fh);
fclose (fh); fclose (fh);
LEAVE(""); LEAVE("");