diff --git a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-price.cpp b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-price.cpp index d3d5e03c57..a49c7f0eda 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-price.cpp +++ b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-price.cpp @@ -42,7 +42,7 @@ extern "C" #include "gnc-ui-util.h" } -const std::string settings_type{"PRICE"}; +constexpr auto group_prefix = "Import csv,price - "; #define CSV_COL_TYPES "ColumnTypes" @@ -57,7 +57,6 @@ static std::shared_ptr create_int_no_preset(void) { auto preset = std::make_shared(); preset->m_name = get_no_settings(); - preset->m_settings_type = settings_type; return preset; } @@ -101,7 +100,7 @@ const preset_vec_price& get_import_presets_price (void) for (gsize i=0; i < grouplength; i++) { auto group = std::string(groups[i]); - auto gp = get_prefix() + settings_type + " - "; + auto gp = std::string {group_prefix}; auto pos = group.find(gp); if (pos == std::string::npos) continue; @@ -125,7 +124,6 @@ const preset_vec_price& get_import_presets_price (void) for (auto preset_name : preset_names) { auto preset = std::make_shared(); - preset->m_settings_type = settings_type; preset->m_name = preset_name; preset->load(); presets_price.push_back(preset); @@ -147,7 +145,7 @@ CsvPriceImpSettings::load (void) GError *key_error = nullptr; m_load_error = false; auto keyfile = gnc_state_get_current (); - auto group = get_prefix() + m_settings_type + " - " + m_name; + auto group = get_group_prefix() + m_name; // Start Loading the settings m_load_error = CsvImportSettings::load(); // load the common settings @@ -210,7 +208,7 @@ CsvPriceImpSettings::save (void) } auto keyfile = gnc_state_get_current (); - auto group = get_prefix() + m_settings_type + " - " + m_name; + auto group = get_group_prefix() + m_name; // Drop previous saved settings with this name g_key_file_remove_group (keyfile, group.c_str(), nullptr); @@ -256,3 +254,9 @@ CsvPriceImpSettings::remove (void) CsvImportSettings::remove(); } + +const char* +CsvPriceImpSettings::get_group_prefix (void) +{ + return group_prefix; +} diff --git a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-price.hpp b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-price.hpp index f1833e5d50..ef15cdd29d 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-price.hpp +++ b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-price.hpp @@ -64,6 +64,9 @@ void remove (void); gnc_commodity *m_from_commodity; // Price From Commodity gnc_commodity *m_to_currency; // Price To Currency std::vector m_column_types_price; // The Price Column types in order + +protected: + const char* get_group_prefix (void) override; }; using preset_vec_price = std::vector>; diff --git a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.cpp b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.cpp index ccac10b0b3..a0a679a067 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.cpp +++ b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.cpp @@ -42,7 +42,7 @@ extern "C" #include "gnc-ui-util.h" } -const std::string settings_type{"TRANS"}; +constexpr auto group_prefix = "Import csv,transaction - "; #define CSV_COL_TYPES "ColumnTypes" @@ -57,7 +57,6 @@ static std::shared_ptr create_int_no_preset(void) { auto preset = std::make_shared(); preset->m_name = get_no_settings(); - preset->m_settings_type = settings_type; return preset; } @@ -114,7 +113,7 @@ const preset_vec_trans& get_import_presets_trans (void) for (gsize i=0; i < grouplength; i++) { auto group = std::string(groups[i]); - auto gp = get_prefix() + settings_type + " - "; + auto gp = std::string {group_prefix}; auto pos = group.find(gp); if (pos == std::string::npos) continue; @@ -138,7 +137,6 @@ const preset_vec_trans& get_import_presets_trans (void) for (auto preset_name : preset_names) { auto preset = std::make_shared(); - preset->m_settings_type = settings_type; preset->m_name = preset_name; preset->load(); presets_trans.push_back(preset); @@ -160,7 +158,7 @@ CsvTransImpSettings::load (void) GError *key_error = nullptr; m_load_error = false; auto keyfile = gnc_state_get_current (); - auto group = get_prefix() + m_settings_type + " - " + m_name; + auto group = get_group_prefix() + m_name; // Start Loading the settings m_load_error = CsvImportSettings::load(); // load the common settings @@ -225,7 +223,7 @@ CsvTransImpSettings::save (void) } auto keyfile = gnc_state_get_current (); - auto group = get_prefix() + m_settings_type + " - " + m_name; + auto group = get_group_prefix() + m_name; // Drop previous saved settings with this name g_key_file_remove_group (keyfile, group.c_str(), nullptr); @@ -260,3 +258,9 @@ CsvTransImpSettings::remove (void) CsvImportSettings::remove(); } + +const char* +CsvTransImpSettings::get_group_prefix (void) +{ + return group_prefix; +} diff --git a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.hpp b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.hpp index 254a41d64f..8d798f7f19 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.hpp +++ b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.hpp @@ -64,6 +64,9 @@ void remove (void); Account *m_base_account; // Base account bool m_multi_split; // Assume multiple lines per transaction std::vector m_column_types; // The Column types in order + +protected: + const char* get_group_prefix (void) override; }; using preset_vec_trans = std::vector>; diff --git a/gnucash/import-export/csv-imp/gnc-imp-settings-csv.cpp b/gnucash/import-export/csv-imp/gnc-imp-settings-csv.cpp index 27b430aa6c..29c28f350a 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-settings-csv.cpp +++ b/gnucash/import-export/csv-imp/gnc-imp-settings-csv.cpp @@ -106,11 +106,6 @@ std::string get_gnc_exp (void) return gnc_exp; } -std::string get_prefix (void) -{ - return csv_group_prefix; -} - /************************************************** * load_common * @@ -121,7 +116,7 @@ CsvImportSettings::load (void) { GError *key_error = nullptr; m_load_error = false; - auto group = csv_group_prefix + m_settings_type + " - " + m_name; + auto group = get_group_prefix() + m_name; auto keyfile = gnc_state_get_current (); m_skip_start_lines = g_key_file_get_integer (keyfile, group.c_str(), CSV_SKIP_START, &key_error); @@ -189,7 +184,7 @@ bool CsvImportSettings::save (void) { auto keyfile = gnc_state_get_current (); - auto group = csv_group_prefix + m_settings_type + " - " + m_name; + auto group = get_group_prefix() + m_name; // Start Saving the Common settings g_key_file_set_string (keyfile, group.c_str(), CSV_NAME, m_name.c_str()); @@ -243,6 +238,6 @@ void CsvImportSettings::remove (void) { auto keyfile = gnc_state_get_current (); - auto group = csv_group_prefix + m_settings_type + " - " + m_name; + auto group = get_group_prefix() + m_name; g_key_file_remove_group (keyfile, group.c_str(), nullptr); } diff --git a/gnucash/import-export/csv-imp/gnc-imp-settings-csv.hpp b/gnucash/import-export/csv-imp/gnc-imp-settings-csv.hpp index d226a70814..b7daed0c37 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-settings-csv.hpp +++ b/gnucash/import-export/csv-imp/gnc-imp-settings-csv.hpp @@ -72,8 +72,6 @@ bool load (void); */ void remove (void); -std::string m_settings_type; // Settings Type, TRANS, PRICE etc. - // Common Settings std::string m_name; // Name given to this preset by the user GncImpFileFormat m_file_format; // CSV import Format @@ -86,11 +84,13 @@ bool m_skip_alt_lines; // Skip alternate rows std::string m_separators; // Separators for csv format bool m_load_error; // Was there an error while parsing the state file ? std::vector m_column_widths; // The Column widths + +protected: + virtual const char* get_group_prefix (void) = 0; }; std::string get_no_settings (void); std::string get_gnc_exp (void); -std::string get_prefix (void); /** Check whether name can be used as a preset name. * The names of the internal presets are considered reserved.