41 #include <glib/gi18n.h> 47 constexpr
auto group_prefix =
"Import csv,price - ";
49 #define CSV_COL_TYPES "ColumnTypes" 51 #define CSV_TO_CURR "PriceToCurrency" 52 #define CSV_FROM_COMM "PriceFromCommodity" 54 G_GNUC_UNUSED
static QofLogModule log_module = GNC_MOD_IMPORT;
56 preset_vec_price presets_price;
58 static std::shared_ptr<CsvPriceImpSettings> create_int_no_preset(
void)
60 auto preset = std::make_shared<CsvPriceImpSettings>();
61 preset->m_name = get_no_settings();
75 auto preset_names = std::vector<std::string>();
78 gchar **groups = g_key_file_get_groups (keyfile, &grouplength);
81 for (gsize i=0; i < grouplength; i++)
83 auto group = std::string(groups[i]);
84 auto gp = std::string {group_prefix};
85 auto pos = group.find(gp);
86 if (pos == std::string::npos)
89 preset_names.push_back(group.substr(gp.size()));
95 std::sort(preset_names.begin(), preset_names.end());
98 presets_price.clear();
101 presets_price.push_back(create_int_no_preset());
105 for (
auto preset_name : preset_names)
107 auto preset = std::make_shared<CsvPriceImpSettings>();
108 preset->m_name = preset_name;
110 presets_price.push_back(preset);
112 return presets_price;
126 GError *key_error =
nullptr;
127 m_load_error =
false;
129 auto group = get_group_prefix() + m_name;
134 gchar *key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_TO_CURR, &key_error);
135 if (key_char && *key_char !=
'\0')
136 m_to_currency = parse_commodity_price_comm (key_char,
"");
137 m_load_error |= handle_load_error (&key_error, group);
141 key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_FROM_COMM, &key_error);
142 if (key_char && *key_char !=
'\0')
143 m_from_commodity = parse_commodity_price_comm (key_char,
"");
144 m_load_error |= handle_load_error (&key_error, group);
149 m_column_types_price.clear();
150 gchar** col_types_str_price = g_key_file_get_string_list (keyfile, group.c_str(), CSV_COL_TYPES,
151 &list_len, &key_error);
152 for (uint32_t i = 0; i < list_len; i++)
154 auto col_types_it = std::find_if (gnc_price_col_type_strs.begin(),
156 auto prop = GncPricePropType::NONE;
157 if (col_types_it != gnc_price_col_type_strs.end())
159 prop = col_types_it->first;
161 PWARN(
"Found invalid column type '%s' in group '%s'. Inserting column type 'NONE' instead'.",
162 col_types_str_price[i], group.c_str());
163 m_column_types_price.push_back(prop);
165 if (col_types_str_price)
166 g_strfreev (col_types_str_price);
181 PWARN (
"Ignoring attempt to save to reserved name '%s'", m_name.c_str());
185 if ((m_name.find(
'[') != std::string::npos))
187 PWARN (
"Name '%s' contains invalid characters '[]'. Refusing to save", m_name.c_str());
192 auto group = get_group_prefix() + m_name;
195 g_key_file_remove_group (keyfile, group.c_str(),
nullptr);
207 g_key_file_set_string (keyfile, group.c_str(), CSV_TO_CURR, unique_name);
208 g_free (unique_name);
211 if (m_from_commodity)
215 g_key_file_set_string (keyfile, group.c_str(), CSV_FROM_COMM, unique_name);
216 g_free (unique_name);
219 std::vector<const char*> col_types_str_price;
220 for (
auto col_type : m_column_types_price)
221 col_types_str_price.push_back(gnc_price_col_type_strs[col_type]);
223 if (!col_types_str_price.empty())
224 g_key_file_set_string_list (keyfile, group.c_str(), CSV_COL_TYPES,
225 col_types_str_price.data(), col_types_str_price.size());
240 CsvPriceImpSettings::get_group_prefix (
void)
Functions to load, save and get gui state.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
utility functions for the GnuCash UI
bool load(void)
Load the widget properties from a key File.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
void remove(void)
Remove the preset from the state file.
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
const preset_vec_price & get_import_presets_price(void)
Creates a vector of CsvPriceImpSettings which combines.
#define PWARN(format, args...)
Log a warning.
Account handling public routines.
bool preset_is_reserved_name(const std::string &name)
Check whether name can be used as a preset name.
bool load(void)
Load the widget properties from a key File.
void remove(void)
Remove the preset from the state file.
bool save(void)
Save the gathered widget properties to a key File.
Functor to check if the above map has an element of which the value equals name.
bool save(void)
Save the gathered widget properties to a key File.