1 /***************************************************************************
2                           mymoneytemplate.h  -  description
3                              -------------------
4     begin                : Sat Aug 14 2004
5     copyright            : (C) 2004 by Thomas Baumgart
6     email                : ipwizard@users.sourceforge.net
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 MYMONEYTEMPLATE_H
19 #define MYMONEYTEMPLATE_H
20 
21 // ----------------------------------------------------------------------------
22 // QT Includes
23 
24 #include <QDomDocument>
25 #include <QDomNode>
26 #include <QUrl>
27 #include <QMap>
28 
29 class QTreeWidgetItem;
30 class QSaveFile;
31 
32 // ----------------------------------------------------------------------------
33 // KDE Includes
34 
35 // ----------------------------------------------------------------------------
36 // Project Includes
37 
38 /**
39   * @author Thomas Baumgart
40   */
41 
42 /**
43   * This class represents an account template handler. It is capable
44   * to read an XML formatted account template file and import it into
45   * the current engine. Also, it can save the current account structure
46   * of the engine to an XML formatted template file.
47   */
48 class MyMoneyAccount;
49 class MyMoneyTemplate
50 {
51 public:
52   MyMoneyTemplate();
53   explicit MyMoneyTemplate(const QUrl &url);
54   ~MyMoneyTemplate();
55 
56   bool loadTemplate(const QUrl &url);
57   bool saveTemplate(const QUrl &url);
58   bool importTemplate(void(*callback)(int, int, const QString&));
59   bool exportTemplate(void(*callback)(int, int, const QString&));
60 
61   const QString& title() const;
62   const QString& shortDescription() const;
63   const QString& longDescription() const;
64 
65   void setTitle(const QString &s);
66   void setShortDescription(const QString &s);
67   void setLongDescription(const QString &s);
68 
69   void hierarchy(QMap<QString, QTreeWidgetItem*>& list);
70 
71 protected:
72   bool loadDescription();
73   bool createAccounts(MyMoneyAccount& parent, QDomNode account);
74   bool setFlags(MyMoneyAccount& acc, QDomNode flags);
75   bool saveToLocalFile(QSaveFile* qfile);
76   bool addAccountStructure(QDomElement& parent, const MyMoneyAccount& acc);
77   bool hierarchy(QMap<QString, QTreeWidgetItem*>& list, const QString& parent, QDomNode account);
78 
79   /**
80     * This method is used to update the progress information. It
81     * checks if an appropriate function is known and calls it.
82     *
83     * For a parameter description see KMyMoneyView::progressCallback().
84     */
85   void signalProgress(int current, int total, const QString& = "");
86 
87 private:
88   QDomDocument    m_doc;
89   QDomNode        m_accounts;
90   QString         m_title;
91   QString         m_shortDesc;
92   QString         m_longDesc;
93   QUrl            m_source;
94   void (*m_progressCallback)(int, int, const QString&);
95   int             m_accountsRead;
96   QMap<QString,QString> m_vatAccountMap;
97 };
98 
99 #endif
100