Some cleanups in import-acount-matcher.c

- Remove unused member variables from AccountPickerDialog struct
- Rename boolean function parameter to better describe what it represents
- Simplify a few constructs and condidionals
- remove unused constructor

Kept separate from actual logic changes
This commit is contained in:
Geert Janssens 2023-02-04 15:56:37 +01:00
parent 99506d331a
commit 56d16f4f0f
2 changed files with 11 additions and 42 deletions

View File

@ -72,26 +72,6 @@ partial_match_if_valid (AccountOnlineMatch *match)
* Functions needed by gnc_import_select_account
*
\********************************************************************/
/** Constructor for AccountPickerDialog.
* @return Pointer to a new AccountPickerDialog
*/
static AccountPickerDialog* gnc_import_new_account_picker(void)
{
AccountPickerDialog* picker = g_new(AccountPickerDialog, 1);
picker->dialog = NULL;
picker->account_tree = NULL;
picker->account_tree_sw = NULL;
picker->auto_create = TRUE;
picker->account_human_description = NULL;
picker->account_online_id_value = NULL;
picker->account_online_id_label = NULL;
picker->new_account_default_commodity = NULL;
picker->new_account_default_type = 0;
picker->default_account = NULL;
picker->retAccount = NULL;
return picker;
}
/**************************************************
* test_acct_online_id_match
@ -402,7 +382,7 @@ account_tree_row_activated_cb(GtkTreeView *view, GtkTreePath *path,
*******************************************************/
Account * gnc_import_select_account(GtkWidget *parent,
const gchar * account_online_id_value,
gboolean auto_create,
gboolean prompt_on_no_match,
const gchar * account_human_description,
const gnc_commodity * new_account_default_commodity,
GNCAccountType new_account_default_type,
@ -424,7 +404,6 @@ Account * gnc_import_select_account(GtkWidget *parent,
DEBUG("Default account type received: %s", xaccAccountGetTypeStr( new_account_default_type));
picker = g_new0(AccountPickerDialog, 1);
picker->account_online_id_value = account_online_id_value;
picker->account_human_description = account_human_description;
picker->new_account_default_commodity = new_account_default_commodity;
picker->new_account_default_type = new_account_default_type;
@ -441,7 +420,7 @@ Account * gnc_import_select_account(GtkWidget *parent,
new_account_default_type == ACCT_TYPE_NONE)
retval = match.partial_match;
}
if (retval == NULL && auto_create != 0)
if (!retval && prompt_on_no_match)
{
/* load the interface */
builder = gtk_builder_new();
@ -517,16 +496,13 @@ Account * gnc_import_select_account(GtkWidget *parent,
case GTK_RESPONSE_OK:
retval = gnc_tree_view_account_get_selected_account(picker->account_tree);
if (retval == NULL)
if (!retval)
{
response = GNC_RESPONSE_NEW;
break;
}
if (retval)
retval_name = xaccAccountGetName(retval);
if (!retval_name)
retval_name = "(null)";
DEBUG("Selected account %p, %s", retval, retval_name);
retval_name = xaccAccountGetName(retval);
DEBUG("Selected account %p, %s", retval, retval_name ? retval_name : "(null)");
/* See if the selected account is a placeholder. */
if (retval && xaccAccountGetPlaceholder (retval))
@ -544,7 +520,7 @@ Account * gnc_import_select_account(GtkWidget *parent,
break;
}
if ( account_online_id_value != NULL)
if (account_online_id_value)
{
gnc_import_set_acc_online_id(retval, account_online_id_value);
}

View File

@ -42,18 +42,12 @@ extern "C" {
typedef struct
{
GtkWidget *dialog; /* Dialog Widget */
GtkWidget *new_button; /* new account button Widget */
GtkWidget *ok_button; /* ok button Widget */
GncTreeViewAccount *account_tree; /* Account tree */
GtkWidget *account_tree_sw; /* Scroll Window for Account tree */
gboolean auto_create; /* Auto create retAccount, can be used to step over this stage */
const gchar *account_human_description; /* description for on line id, incoming */
const gchar *account_online_id_value; /* On line id value, incoming */
GtkWidget *account_online_id_label; /* the label Widget for the on line id, incoming */
const gnc_commodity *new_account_default_commodity; /* new account default commodity, incoming */
GNCAccountType new_account_default_type; /* new account default type, incoming */
Account *default_account; /* default account for selection, incoming */
Account *retAccount; /* Account value returned to caller */
GtkWidget *whbox; /* Warning HBox */
GtkWidget *warning; /* Warning Label */
} AccountPickerDialog;
@ -78,7 +72,7 @@ typedef struct
remembered elsewhere. You would fill account_human_description to tell
the user what he is looking for. In this mode, the online_id
field of the found account will not be touched. To use this mode,
auto_create must NOT be set to 0.
prompt_on_no_match must NOT be set to 0.
@param account_human_description
A human-readable description of
@ -100,11 +94,10 @@ typedef struct
ACCT_TYPE_NONE, the function will also warn the user if the found
or created account's commodity doesn't match.
@param auto_create
Only active if no account with the
@param prompt_on_no_match Only active if no account with the
account_online_id_value could be found in gnucash, or if online-id
was NULL. In that case, if auto_create is TRUE (nonzero), the user
will be asked to create a new account. If auto_create is FALSE
was NULL. In that case, if prompt_on_no_match is TRUE (nonzero), the user
will be asked to create a new account. If prompt_on_no_match is FALSE
(zero), this function will simply return NULL but will neither
select nor create any account.
@ -121,7 +114,7 @@ typedef struct
*/
Account * gnc_import_select_account(GtkWidget *parent,
const gchar * account_online_id_value,
gboolean auto_create,
gboolean prompt_on_no_match,
const gchar * account_human_description,
const gnc_commodity * new_account_default_commodity,
GNCAccountType new_account_default_type,