1 /***************************************************************************
2                           mymoneyqifprofile.h  -  description
3                              -------------------
4     begin                : Tue Dec 24 2002
5     copyright            : (C) 2002 by Thomas Baumgart
6     email                : thb@net-bembel.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef MYMONEYQIFPROFILE_H
19 #define MYMONEYQIFPROFILE_H
20 
21 // ----------------------------------------------------------------------------
22 // QT Includes
23 
24 #include <QMap>
25 #include <QObject>
26 #include <QString>
27 class QDate;
28 
29 // ----------------------------------------------------------------------------
30 // KDE Includes
31 
32 // ----------------------------------------------------------------------------
33 // Project Includes
34 
35 class MyMoneyMoney;
36 
37 /**
38   * @author Thomas Baumgart
39   */
40 
41 class MyMoneyQifProfile : public QObject
42 {
43   Q_OBJECT
44 
45 public:
46   MyMoneyQifProfile();
47   explicit MyMoneyQifProfile(const QString& name);
48   ~MyMoneyQifProfile();
49 
profileName()50   inline const QString& profileName() const {
51     return m_profileName;
52   }
53   void setProfileName(const QString& name);
54 
55   void loadProfile(const QString& name);
56   void saveProfile();
57 
58   const QDate date(const QString& datein) const;
59   const QString date(const QDate& datein) const;
60 
61   const MyMoneyMoney value(const QChar& def, const QString& valuein) const;
62   const QString value(const QChar& def, const MyMoneyMoney& valuein) const;
63 
outputDateFormat()64   inline const QString& outputDateFormat() const {
65     return m_dateFormat;
66   }
67   const QString inputDateFormat() const;
apostropheFormat()68   inline const QString& apostropheFormat() const {
69     return m_apostropheFormat;
70   }
71   const QChar amountDecimal(const QChar& def) const;
72   const QChar amountThousands(const QChar& def) const;
profileDescription()73   inline const QString& profileDescription() const {
74     return m_profileDescription;
75   }
profileType()76   inline const QString& profileType() const {
77     return m_profileType;
78   }
openingBalanceText()79   inline const QString& openingBalanceText() const {
80     return m_openingBalanceText;
81   }
82   const QString accountDelimiter() const;
voidMark()83   inline const QString& voidMark() const {
84     return m_voidMark;
85   }
filterScriptImport()86   inline const QString& filterScriptImport() const {
87     return m_filterScriptImport;
88   }
filterScriptExport()89   inline const QString& filterScriptExport() const {
90     return m_filterScriptExport;
91   }
filterFileType()92   inline const QString& filterFileType() const {
93     return m_filterFileType;
94   }
attemptMatchDuplicates()95   inline bool attemptMatchDuplicates() const {
96     return m_attemptMatchDuplicates;
97   }
98 
99   /**
100    * This method scans all strings contained in @a lines and tries to figure
101    * out the settings for m_decimal, m_thousands and m_dateFormat
102    */
103   void autoDetect(const QStringList& lines);
104 
105   /**
106    * This method returns a list of possible date formats the user
107    * can choose from. If autoDetect() has not been run, the @a list
108    * contains all possible date formats, in the other case, the @a list
109    * is adjusted to those that will match the data scanned.
110    */
111   void possibleDateFormats(QStringList& list) const;
112 
113   /**
114     * This method presets the member variables with the default values.
115     */
116   void clear();
117 
118   /**
119     * This method is used to determine, if a profile has been changed or not
120     */
isDirty()121   inline bool isDirty() const {
122     return m_isDirty;
123   };
124 
125 public Q_SLOTS:
126   void setProfileDescription(const QString& desc);
127   void setProfileType(const QString& type);
128   void setOutputDateFormat(const QString& dateFormat);
129   void setInputDateFormat(const QString& dateFormat);
130   void setApostropheFormat(const QString& apostropheFormat);
131   void setAmountDecimal(const QChar& def, const QChar& chr);
132   void setAmountThousands(const QChar& def, const QChar& chr);
133   void setAccountDelimiter(const QString& delim);
134   void setOpeningBalanceText(const QString& text);
135   void setVoidMark(const QString& txt);
136   void setFilterScriptImport(const QString& txt);
137   void setFilterScriptExport(const QString& txt);
138   void setFilterFileType(const QString& txt);
139   void setAttemptMatchDuplicates(bool);
140 
141 private:
142   const QString twoDigitYear(const QChar& delim, int yr) const;
143   void scanNumeric(const QString& txt, QChar& decimal, QChar& thousands) const;
144   void scanDate(const QString& txt) const;
145 
146 private:
147   /// \internal d-pointer class.
148   class Private;
149   /// \internal d-pointer instance.
150   Private* const d;
151   bool      m_isDirty;
152   QString   m_profileName;
153   QString   m_profileDescription;
154   QString   m_dateFormat;
155   QString   m_apostropheFormat;
156   QString   m_valueMode;
157   QString   m_profileType;
158   QString   m_openingBalanceText;
159   QString   m_voidMark;
160   QString   m_accountDelimiter;
161   QString   m_filterScriptImport;
162   QString   m_filterScriptExport;
163   QString   m_filterFileType;  /*< The kind of input files the filter will expect, e.g. "*.qif" */
164   QMap<QChar, QChar> m_decimal;
165   QMap<QChar, QChar> m_thousands;
166   bool      m_attemptMatchDuplicates;
167 };
168 
169 #endif
170