From 9525d9b84badd15d90b079a1135e0177070deecb Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 16 Sep 2016 23:17:26 +0200 Subject: [PATCH] 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. --- src/import-export/csv-imp/CMakeLists.txt | 4 +-- src/import-export/csv-imp/Makefile.am | 4 +-- .../csv-imp/assistant-csv-trans-import.cpp | 6 ++-- ...nc-csv-imp-trans.cpp => gnc-tx-import.cpp} | 33 ++++++++++--------- ...nc-csv-imp-trans.hpp => gnc-tx-import.hpp} | 29 ++++++++++------ 5 files changed, 43 insertions(+), 33 deletions(-) rename src/import-export/csv-imp/{gnc-csv-imp-trans.cpp => gnc-tx-import.cpp} (97%) rename src/import-export/csv-imp/{gnc-csv-imp-trans.hpp => gnc-tx-import.hpp} (85%) diff --git a/src/import-export/csv-imp/CMakeLists.txt b/src/import-export/csv-imp/CMakeLists.txt index 789ec1bcf2..72143a2b40 100644 --- a/src/import-export/csv-imp/CMakeLists.txt +++ b/src/import-export/csv-imp/CMakeLists.txt @@ -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 diff --git a/src/import-export/csv-imp/Makefile.am b/src/import-export/csv-imp/Makefile.am index 0c4920a441..e3c4775b58 100644 --- a/src/import-export/csv-imp/Makefile.am +++ b/src/import-export/csv-imp/Makefile.am @@ -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 diff --git a/src/import-export/csv-imp/assistant-csv-trans-import.cpp b/src/import-export/csv-imp/assistant-csv-trans-import.cpp index bbfe500976..8b4a48c232 100644 --- a/src/import-export/csv-imp/assistant-csv-trans-import.cpp +++ b/src/import-export/csv-imp/assistant-csv-trans-import.cpp @@ -57,7 +57,7 @@ extern "C" #include } -#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)) diff --git a/src/import-export/csv-imp/gnc-csv-imp-trans.cpp b/src/import-export/csv-imp/gnc-tx-import.cpp similarity index 97% rename from src/import-export/csv-imp/gnc-csv-imp-trans.cpp rename to src/import-export/csv-imp/gnc-tx-import.cpp index b2982846c3..0c12a113db 100644 --- a/src/import-export/csv-imp/gnc-csv-imp-trans.cpp +++ b/src/import-export/csv-imp/gnc-tx-import.cpp @@ -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 #include -#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()); } diff --git a/src/import-export/csv-imp/gnc-csv-imp-trans.hpp b/src/import-export/csv-imp/gnc-tx-import.hpp similarity index 85% rename from src/import-export/csv-imp/gnc-csv-imp-trans.hpp rename to src/import-export/csv-imp/gnc-tx-import.hpp index 6aee870814..f22ef8c633 100644 --- a/src/import-export/csv-imp/gnc-csv-imp-trans.hpp +++ b/src/import-export/csv-imp/gnc-tx-import.hpp @@ -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 */ -#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 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; -/** 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();