Skip to content

Commit

Permalink
Some cleanups in import-acount-matcher.c
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
gjanssens committed Feb 4, 2023
1 parent 99506d3 commit 56d16f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
36 changes: 6 additions & 30 deletions gnucash/import-export/import-account-matcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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))
Expand All @@ -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);
}
Expand Down
17 changes: 5 additions & 12 deletions gnucash/import-export/import-account-matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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,
Expand Down

0 comments on commit 56d16f4

Please sign in to comment.