mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Use consistent name for importer class and its filename
The class was still called after the original struct in c and the file had an almost ok name from when I started the conversion. Add some usage information to the class as well.
This commit is contained in:
committed by
Geert Janssens
parent
a6aa76fc76
commit
9525d9b84b
@@ -12,12 +12,12 @@ SET(csv_import_SOURCES
|
||||
gnc-csv-account-map.c
|
||||
gnc-csv-model.c
|
||||
gnc-csv-gnumeric-popup.c
|
||||
gnc-csv-imp-trans.cpp
|
||||
gnc-csv-tokenizer.cpp
|
||||
gnc-csv-trans-settings.c
|
||||
gnc-dummy-tokenizer.cpp
|
||||
gnc-fw-tokenizer.cpp
|
||||
gnc-tokenizer.cpp
|
||||
gnc-tx-import.cpp
|
||||
${CMAKE_SOURCE_DIR}/lib/stf/stf-parse.c
|
||||
${CMAKE_SOURCE_DIR}/lib/goffice/go-charmap-sel.c
|
||||
${CMAKE_SOURCE_DIR}/lib/goffice/go-optionmenu.c
|
||||
@@ -37,12 +37,12 @@ SET(csv_import_noinst_HEADERS
|
||||
gnc-csv-account-map.h
|
||||
gnc-csv-model.h
|
||||
gnc-csv-gnumeric-popup.h
|
||||
gnc-csv-imp-trans.hpp
|
||||
gnc-csv-tokenizer.hpp
|
||||
gnc-csv-trans-settings.h
|
||||
gnc-dummy-tokenizer.hpp
|
||||
gnc-fw-tokenizer.hpp
|
||||
gnc-tokenizer.hpp
|
||||
gnc-tx-import.hpp
|
||||
${CMAKE_SOURCE_DIR}/lib/stf/stf-parse.h
|
||||
${CMAKE_SOURCE_DIR}/lib/goffice/go-charmap-sel.h
|
||||
${CMAKE_SOURCE_DIR}/lib/goffice/go-optionmenu.h
|
||||
|
||||
@@ -12,12 +12,12 @@ libgncmod_csv_import_la_SOURCES = \
|
||||
csv-fixed-trans-import.c \
|
||||
gnc-csv-account-map.c \
|
||||
gnc-csv-model.c \
|
||||
gnc-csv-imp-trans.cpp \
|
||||
gnc-csv-tokenizer.cpp \
|
||||
gnc-csv-gnumeric-popup.c \
|
||||
gnc-dummy-tokenizer.cpp \
|
||||
gnc-fw-tokenizer.cpp \
|
||||
gnc-tokenizer.cpp \
|
||||
gnc-tx-import.cpp \
|
||||
gnc-csv-trans-settings.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
@@ -29,12 +29,12 @@ noinst_HEADERS = \
|
||||
csv-fixed-trans-import.h \
|
||||
gnc-csv-account-map.h \
|
||||
gnc-csv-model.h \
|
||||
gnc-csv-imp-trans.hpp \
|
||||
gnc-csv-tokenizer.hpp \
|
||||
gnc-csv-gnumeric-popup.h \
|
||||
gnc-dummy-tokenizer.hpp \
|
||||
gnc-fw-tokenizer.hpp \
|
||||
gnc-tokenizer.hpp \
|
||||
gnc-tx-import.hpp \
|
||||
gnc-csv-trans-settings.h
|
||||
|
||||
libgncmod_csv_import_la_LDFLAGS = -avoid-version
|
||||
|
||||
@@ -57,7 +57,7 @@ extern "C"
|
||||
#include <goffice/go-charmap-sel.h>
|
||||
}
|
||||
|
||||
#include "gnc-csv-imp-trans.hpp"
|
||||
#include "gnc-tx-import.hpp"
|
||||
#include "gnc-fw-tokenizer.hpp"
|
||||
#include "gnc-csv-tokenizer.hpp"
|
||||
|
||||
@@ -95,7 +95,7 @@ typedef struct
|
||||
int end_row; /**< The liststore end row, max number of rows -1 */
|
||||
int home_account_number; /**< The number of unique home account strings */
|
||||
|
||||
GncCsvParseData *parse_data; /**< The actual data we are previewing */
|
||||
GncTxImport *parse_data; /**< The actual data we are previewing */
|
||||
CsvSettings *settings_data; /**< The settings to be saved and loaded */
|
||||
GOCharmapSel *encselector; /**< The widget for selecting the encoding */
|
||||
GtkCheckButton *sep_buttons[SEP_NUM_OF_TYPES]; /**< Checkbuttons for common separators */
|
||||
@@ -691,7 +691,7 @@ csv_import_trans_file_chooser_confirm_cb (GtkWidget *button, CsvImportTrans *inf
|
||||
DEBUG("starting directory is %s", info->starting_dir.c_str());
|
||||
|
||||
/* Load the file into parse_data. */
|
||||
auto parse_data = new GncCsvParseData;
|
||||
auto parse_data = new GncTxImport;
|
||||
/* Assume data is CSV. User can later override to Fixed Width if needed */
|
||||
parse_data->file_format (GncImpFileFormat::CSV, &error);
|
||||
if (parse_data->load_file (info->file_name, &error))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/********************************************************************\
|
||||
* gnc-csv-imp-trans.cpp - import transactions from csv files *
|
||||
* gnc-tx-import.cpp - import transactions from csv or fixed-width *
|
||||
* files *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@@ -48,14 +49,14 @@ extern "C" {
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/regex/icu.hpp>
|
||||
|
||||
#include "gnc-csv-imp-trans.hpp"
|
||||
#include "gnc-tx-import.hpp"
|
||||
#include "gnc-csv-tokenizer.hpp"
|
||||
#include "gnc-fw-tokenizer.hpp"
|
||||
|
||||
GQuark
|
||||
gnc_csv_imp_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string ("g-csv-imp-error-quark");
|
||||
return g_quark_from_static_string ("g-tx-import-error-quark");
|
||||
}
|
||||
|
||||
G_GNUC_UNUSED static QofLogModule log_module = GNC_MOD_IMPORT;
|
||||
@@ -218,10 +219,10 @@ time64 parse_date (const std::string &date_str, int format)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Constructor for GncCsvParseData.
|
||||
/** Constructor for GncTxImport.
|
||||
* @return Pointer to a new GncCSvParseData
|
||||
*/
|
||||
GncCsvParseData::GncCsvParseData(GncImpFileFormat format)
|
||||
GncTxImport::GncTxImport(GncImpFileFormat format)
|
||||
{
|
||||
/* All of the data pointers are initially NULL. This is so that, if
|
||||
* gnc_csv_parse_data_free is called before all of the data is
|
||||
@@ -237,13 +238,13 @@ GncCsvParseData::GncCsvParseData(GncImpFileFormat format)
|
||||
tokenizer = GncTokenizerFactory(file_fmt);
|
||||
}
|
||||
|
||||
/** Destructor for GncCsvParseData.
|
||||
/** Destructor for GncTxImport.
|
||||
*/
|
||||
GncCsvParseData::~GncCsvParseData()
|
||||
GncTxImport::~GncTxImport()
|
||||
{
|
||||
}
|
||||
|
||||
int GncCsvParseData::file_format(GncImpFileFormat format,
|
||||
int GncTxImport::file_format(GncImpFileFormat format,
|
||||
GError** error)
|
||||
{
|
||||
if (file_fmt == format)
|
||||
@@ -267,7 +268,7 @@ int GncCsvParseData::file_format(GncImpFileFormat format,
|
||||
tokenizer->encoding(new_encoding);
|
||||
return load_file(new_imp_file, error);
|
||||
}
|
||||
GncImpFileFormat GncCsvParseData::file_format()
|
||||
GncImpFileFormat GncTxImport::file_format()
|
||||
{
|
||||
return file_fmt;
|
||||
}
|
||||
@@ -280,15 +281,15 @@ GncImpFileFormat GncCsvParseData::file_format()
|
||||
* @param error Will point to an error on failure
|
||||
* @return 0 on success, 1 on failure
|
||||
*/
|
||||
void GncCsvParseData::convert_encoding (const std::string& encoding)
|
||||
void GncTxImport::convert_encoding (const std::string& encoding)
|
||||
{
|
||||
// TODO investigate if we can catch conversion errors and report them
|
||||
if (tokenizer)
|
||||
tokenizer->encoding(encoding);
|
||||
}
|
||||
|
||||
/** Loads a file into a GncCsvParseData. This is the first function
|
||||
* that must be called after creating a new GncCsvParseData. If this
|
||||
/** Loads a file into a GncTxImport. This is the first function
|
||||
* that must be called after creating a new GncTxImport. If this
|
||||
* fails because the file couldn't be opened, no more functions can be
|
||||
* called on the parse data until this succeeds (or until it fails
|
||||
* because of an encoding guess error). If it fails because the
|
||||
@@ -299,7 +300,7 @@ void GncCsvParseData::convert_encoding (const std::string& encoding)
|
||||
* @param error Will contain an error if there is a failure
|
||||
* @return 0 on success, 1 on failure
|
||||
*/
|
||||
int GncCsvParseData::load_file (const std::string& filename,
|
||||
int GncTxImport::load_file (const std::string& filename,
|
||||
GError** error)
|
||||
{
|
||||
|
||||
@@ -331,7 +332,7 @@ int GncCsvParseData::load_file (const std::string& filename,
|
||||
* @param error Will contain an error if there is a failure
|
||||
* @return 0 on success, 1 on failure
|
||||
*/
|
||||
int GncCsvParseData::parse (bool guessColTypes, GError** error)
|
||||
int GncTxImport::parse (bool guessColTypes, GError** error)
|
||||
{
|
||||
uint max_cols = 0;
|
||||
tokenizer->tokenize();
|
||||
@@ -747,7 +748,7 @@ static GncCsvTransLine* trans_properties_to_trans (prop_map_t& trans_props, gcha
|
||||
* @param redo_errors TRUE to convert only error data, FALSE for all data
|
||||
* @return 0 on success, 1 on failure
|
||||
*/
|
||||
int GncCsvParseData::parse_to_trans (Account* account,
|
||||
int GncTxImport::parse_to_trans (Account* account,
|
||||
bool redo_errors)
|
||||
{
|
||||
/* Free error_lines and transactions if they
|
||||
@@ -953,7 +954,7 @@ int GncCsvParseData::parse_to_trans (Account* account,
|
||||
|
||||
|
||||
bool
|
||||
GncCsvParseData::check_for_column_type (GncTransPropType type)
|
||||
GncTxImport::check_for_column_type (GncTransPropType type)
|
||||
{
|
||||
return (std::find (column_types.begin(), column_types.end(), type) != column_types.end());
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/********************************************************************\
|
||||
* gnc-csv-imp-trans.hpp - import transactions from csv files *
|
||||
* gnc-tx-import.hpp - import transactions from csv files *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@@ -20,14 +20,14 @@
|
||||
\********************************************************************/
|
||||
|
||||
/** @file
|
||||
@brief Class to import transactions from CSV files
|
||||
@brief Class to import transactions from CSV or fixed width files
|
||||
*
|
||||
gnc-csv-imp-trans.hpp
|
||||
gnc-tx-import.hpp
|
||||
@author Copyright (c) 2015 Geert Janssens <geert@kobaltwit.be>
|
||||
*/
|
||||
|
||||
#ifndef GNC_CSV_IMP_TRANS_HPP
|
||||
#define GNC_CSV_IMP_TRANS_HPP
|
||||
#ifndef GNC_TX_IMPORT_HPP
|
||||
#define GNC_TX_IMPORT_HPP
|
||||
|
||||
extern "C" {
|
||||
#include "config.h"
|
||||
@@ -63,7 +63,7 @@ enum class GncTransPropType {
|
||||
};
|
||||
|
||||
/** Maps all column types to a string representation.
|
||||
* The actual definition is in gnc-csv-imp-trans.cpp.
|
||||
* The actual definition is in gnc-tx-import.cpp.
|
||||
* Attention: that definition should be adjusted for any
|
||||
* changes to enum class GncTransPropType ! */
|
||||
extern std::map<GncTransPropType, const char*> gnc_csv_col_type_strs;
|
||||
@@ -110,13 +110,22 @@ extern const gchar* date_format_user[];
|
||||
/** Pair to hold a tokenized line of input and an optional error string */
|
||||
using parse_line_t = std::pair<str_vec, std::string>;
|
||||
|
||||
/** Struct containing data for parsing a CSV/Fixed-Width file. */
|
||||
class GncCsvParseData
|
||||
/* The actual TxImport class
|
||||
* It's intended to use in the following sequence of actions:
|
||||
* - set a file format
|
||||
* - load a file
|
||||
* - optionally convert it's encoding
|
||||
* - parse the file into lines, which in turn are split up in columns
|
||||
* the result of this step can be queried from tokenizer
|
||||
* - the user should now map the columns to types, which is stored in column_types
|
||||
* - last step is convert the mapped columns into a list of transactions
|
||||
* - this list will then be passed on the the generic importer for further processing */
|
||||
class GncTxImport
|
||||
{
|
||||
public:
|
||||
// Constructor - Destructor
|
||||
GncCsvParseData(GncImpFileFormat format = GncImpFileFormat::UNKNOWN);
|
||||
~GncCsvParseData();
|
||||
GncTxImport(GncImpFileFormat format = GncImpFileFormat::UNKNOWN);
|
||||
~GncTxImport();
|
||||
|
||||
int file_format(GncImpFileFormat format, GError** error);
|
||||
GncImpFileFormat file_format();
|
||||
Reference in New Issue
Block a user