Bug 798149 - Follow up to CSV saved account settings

The previous commit breaks backwards compatibility so this change adds
a new setting BaseAccountGuid to hold the account Guid, BaseAccount
holds the account full path as before. When a CSV setting is selected,
the Guid is first used to find the account. If unsuccessful, the full
path is then used and if successful the account guid is immediately
saved for future use. If unsuccessfull the account combo is blank with
a error message as before.
When save CSV settings button is used, both the Guid and full paths are
saved so previous versions can still use the full path as before.
This commit is contained in:
Robert Fewell
2021-03-19 10:07:26 +00:00
parent c915fb3039
commit 61e23baf87

View File

@@ -51,6 +51,7 @@ constexpr auto group_prefix = "Import csv,transaction - ";
#define CSV_COL_TYPES "ColumnTypes"
#define CSV_ACCOUNT "BaseAccount"
#define CSV_ACCOUNT_GUID "BaseAccountGuid"
#define CSV_MULTI_SPLIT "MultiSplit"
G_GNUC_UNUSED static QofLogModule log_module = GNC_MOD_IMPORT;
@@ -170,15 +171,22 @@ CsvTransImpSettings::load (void)
m_multi_split = g_key_file_get_boolean (keyfile, group.c_str(), CSV_MULTI_SPLIT, &key_error);
m_load_error |= handle_load_error (&key_error, group);
gchar *key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_ACCOUNT, &key_error);
gchar *key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_ACCOUNT_GUID, &key_error);
if (key_char && *key_char != '\0')
{
QofBook* book = gnc_get_current_book ();
GncGUID guid;
if (string_to_guid (key_char, &guid)) // find account by guid
if (string_to_guid (key_char, &guid)) // find account by guid first
m_base_account = xaccAccountLookup (&guid, book);
}
m_load_error |= handle_load_error (&key_error, group);
if (key_char)
g_free (key_char);
key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_ACCOUNT, &key_error);
if (key_char && *key_char != '\0')
{
if (m_base_account == nullptr)
{
m_base_account = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), key_char);
@@ -187,9 +195,17 @@ CsvTransImpSettings::load (void)
{
gchar acct_guid[GUID_ENCODING_LENGTH + 1];
guid_to_string_buff (xaccAccountGetGUID (m_base_account), acct_guid);
g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT, acct_guid);
g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT_GUID, acct_guid);
}
}
else // check to see if saved full name is the same and save if not
{
gchar *full_name = gnc_account_get_full_name (m_base_account);
if (g_strcmp0 (key_char, full_name) != 0)
g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT, full_name);
g_free (full_name);
}
}
m_load_error |= handle_load_error (&key_error, group);
if (key_char)
@@ -258,11 +274,15 @@ CsvTransImpSettings::save (void)
g_key_file_set_boolean (keyfile, group.c_str(), CSV_MULTI_SPLIT, m_multi_split);
if (m_base_account)
if (m_base_account) // also save account guid introduced in version 4.5
{
gchar acct_guid[GUID_ENCODING_LENGTH + 1];
guid_to_string_buff (xaccAccountGetGUID (m_base_account), acct_guid);
g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT, acct_guid);
g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT_GUID, acct_guid);
gchar *full_name = gnc_account_get_full_name (m_base_account);
g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT, full_name);
g_free (full_name);
}
std::vector<const char*> col_types_str;