GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Protected Member Functions
CsvPriceImpSettings Struct Reference
Inheritance diagram for CsvPriceImpSettings:
CsvImportSettings

Public Member Functions

bool save (void)
 Save the gathered widget properties to a key File.
 
bool load (void)
 Load the widget properties from a key File.
 
void remove (void)
 Remove the preset from the state file.
 
- Public Member Functions inherited from CsvImportSettings
bool save (void)
 Save the gathered widget properties to a key File.
 
bool load (void)
 Load the widget properties from a key File.
 
void remove (void)
 Remove the preset from the state file.
 

Data Fields

gnc_commodity * m_from_commodity
 
gnc_commodity * m_to_currency
 
std::vector< GncPricePropType > m_column_types_price
 
- Data Fields inherited from CsvImportSettings
std::string m_name
 
GncImpFileFormat m_file_format
 
std::string m_encoding
 
int m_date_format
 
int m_currency_format
 
uint32_t m_skip_start_lines
 
uint32_t m_skip_end_lines
 
bool m_skip_alt_lines
 
std::string m_separators
 
bool m_enable_escape
 
bool m_load_error
 
std::vector< uint32_t > m_column_widths
 

Protected Member Functions

const char * get_group_prefix (void) override
 

Detailed Description

Definition at line 41 of file gnc-imp-settings-csv-price.hpp.

Constructor & Destructor Documentation

◆ CsvPriceImpSettings()

CsvPriceImpSettings::CsvPriceImpSettings ( )
inline

Definition at line 43 of file gnc-imp-settings-csv-price.hpp.

43: m_from_commodity {nullptr}, m_to_currency {nullptr} { }

Member Function Documentation

◆ get_group_prefix()

const char * CsvPriceImpSettings::get_group_prefix ( void  )
overrideprotectedvirtual

Implements CsvImportSettings.

Definition at line 240 of file gnc-imp-settings-csv-price.cpp.

241{
242 return group_prefix;
243}

◆ load()

bool CsvPriceImpSettings::load ( void  )

Load the widget properties from a key File.

Returns
true if there was a problem.

Definition at line 121 of file gnc-imp-settings-csv-price.cpp.

122{
123 if (preset_is_reserved_name (m_name))
124 return true;
125
126 GError *key_error = nullptr;
127 m_load_error = false;
128 auto keyfile = gnc_state_get_current ();
129 auto group = get_group_prefix() + m_name;
130
131 // Start Loading the settings
132 m_load_error = CsvImportSettings::load(); // load the common settings
133
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);
138 if (key_char)
139 g_free (key_char);
140
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);
145 if (key_char)
146 g_free (key_char);
147
148 gsize list_len;
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++)
153 {
154 auto col_types_it = std::find_if (gnc_price_col_type_strs.begin(),
155 gnc_price_col_type_strs.end(), test_price_prop_type_str (col_types_str_price[i]));
156 auto prop = GncPricePropType::NONE;
157 if (col_types_it != gnc_price_col_type_strs.end())
158 // Found a valid column type
159 prop = col_types_it->first;
160 else
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);
164 }
165 if (col_types_str_price)
166 g_strfreev (col_types_str_price);
167
168 return m_load_error;
169}
bool preset_is_reserved_name(const std::string &name)
Check whether name can be used as a preset name.
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition gnc-state.c:248
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250
bool load(void)
Load the widget properties from a key File.
Functor to check if the above map has an element of which the value equals name.

◆ remove()

void CsvPriceImpSettings::remove ( void  )

Remove the preset from the state file.

Definition at line 231 of file gnc-imp-settings-csv-price.cpp.

232{
233 if (preset_is_reserved_name (m_name))
234 return;
235
237}
void remove(void)
Remove the preset from the state file.

◆ save()

bool CsvPriceImpSettings::save ( void  )

Save the gathered widget properties to a key File.

Returns
true if there was a problem in saving.

Definition at line 177 of file gnc-imp-settings-csv-price.cpp.

178{
179 if (preset_is_reserved_name (m_name))
180 {
181 PWARN ("Ignoring attempt to save to reserved name '%s'", m_name.c_str());
182 return true;
183 }
184
185 if ((m_name.find('[') != std::string::npos))
186 {
187 PWARN ("Name '%s' contains invalid characters '[]'. Refusing to save", m_name.c_str());
188 return true;
189 }
190
191 auto keyfile = gnc_state_get_current ();
192 auto group = get_group_prefix() + m_name;
193
194 // Drop previous saved settings with this name
195 g_key_file_remove_group (keyfile, group.c_str(), nullptr);
196
197 // Start Saving the settings
198 bool error = CsvImportSettings::save(); // save the common settings
199
200 if (error)
201 return error;
202
203 if (m_to_currency)
204 {
205 auto unique_name = g_strconcat (gnc_commodity_get_namespace (m_to_currency), "::",
206 gnc_commodity_get_mnemonic (m_to_currency), nullptr);
207 g_key_file_set_string (keyfile, group.c_str(), CSV_TO_CURR, unique_name);
208 g_free (unique_name);
209 }
210
211 if (m_from_commodity)
212 {
213 auto unique_name = g_strconcat (gnc_commodity_get_namespace (m_from_commodity), "::",
214 gnc_commodity_get_mnemonic (m_from_commodity), nullptr);
215 g_key_file_set_string (keyfile, group.c_str(), CSV_FROM_COMM, unique_name);
216 g_free (unique_name);
217 }
218
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]);
222
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());
226
227 return error;
228}
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
bool save(void)
Save the gathered widget properties to a key File.

Field Documentation

◆ m_column_types_price

std::vector<GncPricePropType> CsvPriceImpSettings::m_column_types_price

Definition at line 64 of file gnc-imp-settings-csv-price.hpp.

◆ m_from_commodity

gnc_commodity* CsvPriceImpSettings::m_from_commodity

Definition at line 62 of file gnc-imp-settings-csv-price.hpp.

◆ m_to_currency

gnc_commodity* CsvPriceImpSettings::m_to_currency

Definition at line 63 of file gnc-imp-settings-csv-price.hpp.


The documentation for this struct was generated from the following files: