-
Notifications
You must be signed in to change notification settings - Fork 0
/
aussackler.cpp
150 lines (132 loc) · 4.2 KB
/
aussackler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 2013 Georg Lippitsch
*
* This file is part of Aussackler.
*
* Aussackler is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Aussackler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Aussackler. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
#include <QTextCodec>
#include <QDate>
#include <QFile>
#include <stdio.h>
#include "aussackler.h"
#include "entry.h"
#include "mainwindow.h"
#include "transaction.h"
Aussackler::Aussackler()
{
ASTransaction::TTypeInit();
ASMainWindow * mw = new ASMainWindow(&m_transactions);
connect(mw, SIGNAL(signalLoad(const QString)),
this, SLOT(slotLoadFile(const QString)));
connect(mw, SIGNAL(signalSave(const QString)),
this, SLOT(slotSaveFile(const QString)));
mw->show();
}
Aussackler::~Aussackler()
{
}
void Aussackler::slotLoadFile(const QString fileName)
{
QDomDocument doc("aussackler");
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
return;
if (!doc.setContent(&file)) {
file.close();
return;
}
file.close();
for (int i = m_transactions.size() - 1; i >= 0; --i)
{
delete m_transactions.at(i);
}
m_transactions.clear();
QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
while(!n.isNull())
{
QDomElement e = n.toElement();
if(!e.isNull() && e.tagName() == "transaction")
{
if (!e.hasAttribute("type"))
continue;
ASTransaction::TransactionType type =
(ASTransaction::TransactionType)
ASTransaction::TransactionTypeStrings.
indexOf(e.attribute("type"));
ASTransaction * a = NULL;
switch(type)
{
case ASTransaction::TRANSACTION_TYPE_BASE:
a = new ASTransaction(&m_transactions);
break;
case ASTransaction::TRANSACTION_TYPE_CATEGORY:
a = new ASCategory(&m_transactions);
break;
case ASTransaction::TRANSACTION_TYPE_ACCOUNT:
a = new ASAccount(&m_transactions);
break;
case ASTransaction::TRANSACTION_TYPE_ACCOUNTENTRY:
a = new ASAccountEntry(&m_transactions);
break;
case ASTransaction::TRANSACTION_TYPE_INVESTMENT:
a = new ASInvestEntry(&m_transactions);
break;
case ASTransaction::TRANSACTION_TYPE_DOCUMENT:
a = new ASDocument(&m_transactions);
break;
case ASTransaction::TRANSACTION_TYPE_VATCATEGORY:
a = new ASVatCategory(&m_transactions);
break;
}
if (a)
{
a->readFromXml(&e);
a->commit();
}
}
n = n.nextSibling();
}
}
void Aussackler::slotSaveFile(const QString fileName)
{
QDomDocument doc("aussackler");
QDomElement root = doc.createElement("aussackler");
doc.appendChild(root);
ASTransactionList::const_iterator it = m_transactions.constBegin();
for(; it != m_transactions.constEnd(); ++it)
{
QDomElement de = doc.createElement("transaction");
(*it)->writeToXml(&doc, &de);
root.appendChild(de);
}
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
return;
file.write(doc.toByteArray(4));
file.close();
}
/********************************************************************/
int main(int argc, char * argv[])
{
QLocale::setDefault(QLocale(QLocale::German, QLocale::Austria));
QApplication app(argc, argv);
Aussackler as;
if (argc > 1)
as.slotLoadFile(argv[1]);
app.exec();
return 0;
}