File indexing completed on 2024-06-16 04:47:19

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGIMPORTPLUGINCSV_H
0007 #define SKGIMPORTPLUGINCSV_H
0008 /** @file
0009 * This file is Skrooge plugin for CSV import / export.
0010 *
0011 * @author Stephane MANKOWSKI / Guillaume DE BURE
0012 */
0013 #include "skgimportplugin.h"
0014 
0015 /**
0016  * This file is Skrooge plugin for CSV import / export.
0017  */
0018 class SKGImportPluginCsv : public SKGImportPlugin
0019 {
0020     Q_OBJECT
0021     Q_INTERFACES(SKGImportPlugin)
0022 
0023 public:
0024     /**
0025      * Default constructor
0026      * @param iImporter the parent importer
0027      * @param iArg the arguments
0028      */
0029     explicit SKGImportPluginCsv(QObject* iImporter, const QVariantList& iArg);
0030 
0031     /**
0032      * Default Destructor
0033      */
0034     ~SKGImportPluginCsv() override;
0035 
0036     /**
0037      * Set parameters for Import
0038      * @param iParameters the parameters
0039      */
0040     void setImportParameters(const QMap< QString, QString >& iParameters) override;
0041 
0042     /**
0043      * To know if import is possible with this plugin
0044      */
0045     bool isImportPossible() override;
0046 
0047     /**
0048      * Import a file
0049      * @return an object managing the error.
0050      *   @see SKGError
0051      */
0052     SKGError importFile() override;
0053 
0054     /**
0055      * To know if export is possible with this plugin
0056      * @return true or false
0057      */
0058     bool isExportPossible() override;
0059 
0060     /**
0061      * Export a file
0062      * @return an object managing the error.
0063      *   @see SKGError
0064      */
0065     SKGError exportFile() override;
0066 
0067     /**
0068      * Return the mime type filter
0069      * @return the mime type filter. Example: "*.csv|CSV file"
0070      */
0071     QString getMimeTypeFilter() const override;
0072 
0073     /**
0074      * Import units
0075      * @return an object managing the error.
0076      *   @see SKGError
0077      */
0078     virtual SKGError importCSVUnit();
0079 
0080     /**
0081      * Import rules
0082      * @return an object managing the error.
0083      *   @see SKGError
0084      */
0085     virtual SKGError importCSVRule();
0086 
0087 private:
0088     Q_DISABLE_COPY(SKGImportPluginCsv)
0089 
0090     /**
0091      * Set the CSV mapping.
0092      * A mapping is ordered list to described the mapping between the csv file and
0093      * the transaction object.
0094      * List of supported key word:
0095      * date
0096      * number
0097      * mode
0098      * payee
0099      * comment
0100      * status
0101      * bookmarked
0102      * account
0103      * category
0104      * amount
0105      * quantity
0106      * sign
0107      * unit
0108      * This list is a list of transaction attributes.
0109      * @param iCSVMapping the mapping. nullptr to build automatically the CSV mapping.
0110      * @return an object managing the error.
0111      *   @see SKGError
0112      */
0113     virtual SKGError setCSVMapping(const QStringList* iCSVMapping);
0114 
0115     /**
0116      * Set the index of the header in the CSV file.
0117      * @param iIndex the index. -1 to search automatically the index of the header.
0118      * @return an object managing the error.
0119      *   @see SKGError
0120      */
0121     virtual SKGError setCSVHeaderIndex(int iIndex = -1);
0122 
0123     /**
0124      * Get the index of the header in the CSV file.
0125      * @return the index
0126      */
0127     virtual int getCSVHeaderIndex();
0128 
0129     /**
0130      * Get the CSV separator
0131      * @param iLine the line to split to find the separator is not determined yet.
0132      * @return the separator
0133      */
0134     virtual QChar getCSVSeparator(const QString& iLine = QString());
0135 
0136     QStringList getCSVMappingFromLine(const QString& iLine);
0137 
0138     QStringList m_csvMapping;
0139     QChar m_csvSeparator;
0140     int m_csvHeaderIndex;
0141 };
0142 
0143 #endif  // SKGIMPORTPLUGINCSV_H