GnuCash  5.6-150-g038405b370+
Data Structures | Typedefs | Functions
gnc-imp-settings-csv-tx.hpp File Reference

CSV Import Settings. More...

#include <config.h>
#include "Account.h"
#include "gnc-commodity.h"
#include <string>
#include <vector>
#include "gnc-imp-props-tx.hpp"
#include "gnc-tokenizer.hpp"
#include "gnc-imp-settings-csv.hpp"

Go to the source code of this file.

Data Structures

struct  CsvTransImpSettings
 

Typedefs

using preset_vec_trans = std::vector< std::shared_ptr< CsvTransImpSettings > >
 

Functions

const preset_vec_trans & get_import_presets_trans (void)
 Creates a vector of CsvTransImpSettings which combines. More...
 

Detailed Description

CSV Import Settings.

Author
Copyright (c) 2014 Robert Fewell
Copyright (c) 2016 Geert Janssens

Definition in file gnc-imp-settings-csv-tx.hpp.

Function Documentation

◆ get_import_presets_trans()

const preset_vec_trans& get_import_presets_trans ( void  )

Creates a vector of CsvTransImpSettings which combines.

  • one or more internally defined presets
  • all preset found in the state key file.
Returns
a reference to the populated vector.

Definition at line 143 of file gnc-imp-settings-csv-tx.cpp.

144 {
145  // Search all Groups in the state key file for ones starting with prefix
146  auto preset_names = std::vector<std::string>();
147  auto keyfile = gnc_state_get_current ();
148  gsize grouplength;
149  gchar **groups = g_key_file_get_groups (keyfile, &grouplength);
150 
151  /* Start by building a sorted list of candidate presets as found in the state file */
152  for (gsize i=0; i < grouplength; i++)
153  {
154  auto group = std::string(groups[i]);
155  auto gp = std::string {group_prefix};
156  auto pos = group.find(gp);
157  if (pos == std::string::npos)
158  continue;
159 
160  preset_names.push_back(group.substr(gp.size()));
161  }
162  // string array from the state file is no longer needed now.
163  g_strfreev (groups);
164 
165  /* We want our settings to appear sorted alphabetically to the user */
166  std::sort(preset_names.begin(), preset_names.end());
167 
168  /* Now add each preset to our global list */
169  presets_trans.clear();
170 
171  /* Start with the internally generated ones */
172  presets_trans.push_back(create_int_no_preset());
173  presets_trans.push_back(create_int_gnc_exp_preset());
174  presets_trans.push_back(create_int_gnc_exp_4_preset());
175 
176  /* Then add all the ones we found in the state file */
177  for (auto preset_name : preset_names)
178  {
179  auto preset = std::make_shared<CsvTransImpSettings>();
180  preset->m_name = preset_name;
181  preset->load();
182  presets_trans.push_back(preset);
183  }
184  return presets_trans;
185 }
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248