GnuCash  5.6-150-g038405b370+
Macros | Functions | Variables
gnc-imp-settings-csv-price.cpp File Reference

CSV Import Settings. More...

#include "gnc-imp-settings-csv.hpp"
#include "gnc-imp-settings-csv-price.hpp"
#include <algorithm>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include <cstdint>
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "Account.h"
#include "gnc-state.h"
#include "gnc-ui-util.h"

Go to the source code of this file.

Macros

#define CSV_COL_TYPES   "ColumnTypes"
 
#define CSV_TO_CURR   "PriceToCurrency"
 
#define CSV_FROM_COMM   "PriceFromCommodity"
 

Functions

const preset_vec_price & get_import_presets_price (void)
 Creates a vector of CsvPriceImpSettings which combines. More...
 

Variables

constexpr auto group_prefix = "Import csv,price - "
 
preset_vec_price presets_price
 

Detailed Description

CSV Import Settings.

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

Definition in file gnc-imp-settings-csv-price.cpp.

Function Documentation

◆ get_import_presets_price()

const preset_vec_price& get_import_presets_price ( void  )

Creates a vector of CsvPriceImpSettings 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 72 of file gnc-imp-settings-csv-price.cpp.

73 {
74  // Search all Groups in the state key file for ones starting with prefix
75  auto preset_names = std::vector<std::string>();
76  auto keyfile = gnc_state_get_current ();
77  gsize grouplength;
78  gchar **groups = g_key_file_get_groups (keyfile, &grouplength);
79 
80  /* Start by building a sorted list of candidate presets as found in the state file */
81  for (gsize i=0; i < grouplength; i++)
82  {
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)
87  continue;
88 
89  preset_names.push_back(group.substr(gp.size()));
90  }
91  // string array from the state file is no longer needed now.
92  g_strfreev (groups);
93 
94  /* We want our settings to appear sorted alphabetically to the user */
95  std::sort(preset_names.begin(), preset_names.end());
96 
97  /* Now add each preset to our global list */
98  presets_price.clear();
99 
100  /* Start with the internally generated ones */
101  presets_price.push_back(create_int_no_preset());
102  //presets_price.push_back(create_int_gnc_exp_preset()); // Not Required
103 
104  /* Then add all the ones we found in the state file */
105  for (auto preset_name : preset_names)
106  {
107  auto preset = std::make_shared<CsvPriceImpSettings>();
108  preset->m_name = preset_name;
109  preset->load();
110  presets_price.push_back(preset);
111  }
112  return presets_price;
113 }
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248