First runnable version

This commit is contained in:
2011-08-27 18:35:36 +02:00
parent 991486a042
commit 658ec606ed
28 changed files with 657 additions and 646 deletions

View File

@@ -17,32 +17,36 @@
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "XMLImportEngine.hpp"
static XMLImportEngine xmlImportEngine;
void XMLImportEngine::LoadAccount(XMLImportEngine* _this, const char** attrs)
{
int i;
wxString account_number, name, id;
int i, id;
QString account_number, name;
Account ac;
static int unknownAccount = 0;
ac.id = 0;
for (i=0; attrs[i]; i+=2)
{
if (!strcmp(attrs[i], "name"))
ac.name = wxString(attrs[i+1], wxConvUTF8);
ac.name = attrs[i+1];
else if (!strcmp(attrs[i], "id"))
ac.id = id = wxString(attrs[i+1], wxConvUTF8);
ac.id = id = QString(attrs[i+1]).toInt();
else if (!strcmp(attrs[i], "number"))
ac.number = account_number = wxString(attrs[i+1], wxConvUTF8);
ac.number = account_number = attrs[i+1];
else if (!strcmp(attrs[i], "blocked"))
ac.blocked = (wxString(attrs[i+1], wxConvUTF8) == wxT("1"));
ac.blocked = (QString(attrs[i+1]) == "1");
else if (!strcmp(attrs[i], "virtual"))
ac._virtual = (wxString(attrs[i+1], wxConvUTF8) == wxT("1"));
ac._virtual = (QString(attrs[i+1]) == "1");
}
UNESCAPE_CHARS(ac.name);
@@ -52,11 +56,10 @@ void XMLImportEngine::LoadAccount(XMLImportEngine* _this, const char** attrs)
ac.shared = false;
ac.is_owner = true;
if (account_number.Length())
if (account_number.size())
{
try {
Account ac = _this->_user->GetAccount(account_number);
_this->_accounts[id] = ac.id;
_this->_accounts[ac.id] = _this->_user->GetAccountIdFromAccountNumber(account_number);
return;
}
catch (User::AccountNotFound)
@@ -64,7 +67,7 @@ void XMLImportEngine::LoadAccount(XMLImportEngine* _this, const char** attrs)
}
}
_this->_accounts[id] = wxT("unknown-") + account_number;
_this->_accounts[id] = --unknownAccount;
_this->_unresolvedAccounts.push_back(ac);
}
@@ -72,28 +75,25 @@ void XMLImportEngine::LoadAccountAmount(XMLImportEngine* _this, const char** att
{
AccountAmount accountAmount;
int i;
long v;
double amount;
for (i=0; attrs[i]; i+=2)
{
if (!strcmp(attrs[i], "account"))
accountAmount.account = wxString(attrs[i+1], wxConvUTF8);
accountAmount.account = QString(attrs[i+1]).toInt();
else if (!strcmp(attrs[i], "month"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&v);
accountAmount.month = v;
accountAmount.month = QString(attrs[i+1]).toInt();
}
else if (!strcmp(attrs[i], "year"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&v);
accountAmount.year = v;
accountAmount.year = QString(attrs[i+1]).toInt();
}
else if (!strcmp(attrs[i], "amount"))
wxString(attrs[i+1], wxConvUTF8).ToDouble(&amount);
amount = QString(attrs[i+1]).toDouble();
}
_this->_accountAmounts[accountAmount] = amount;
@@ -101,49 +101,50 @@ void XMLImportEngine::LoadAccountAmount(XMLImportEngine* _this, const char** att
void XMLImportEngine::LoadCategory(XMLImportEngine* _this, const char** attrs)
{
wxString name, id;
int i;
QString name;
int i, id;
long rgb;
Category cat;
static int unknownCategory = 0;
for (i=0; attrs[i]; i+=2)
{
if (!strcmp(attrs[i], "name"))
cat.name = name = wxString(attrs[i+1], wxConvUTF8);
cat.name = name = QString(attrs[i+1]);
else if (!strcmp(attrs[i], "id"))
cat.id = id = wxString(attrs[i+1], wxConvUTF8);
cat.id = id = QString(attrs[i+1]).toInt();
else if (!strcmp(attrs[i], "font"))
cat.font = wxString(attrs[i+1], wxConvUTF8);
cat.font = QString(attrs[i+1]);
else if (!strcmp(attrs[i], "backcolor"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&rgb, 16);
cat.backcolor = wxColour((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF);
rgb = QString(attrs[i+1]).toInt(0, 16);
cat.backcolor = QColor((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF);
}
else if (!strcmp(attrs[i], "forecolor"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&rgb, 16);
cat.forecolor = wxColour((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF);
rgb = QString(attrs[i+1]).toInt(0, 16);
cat.forecolor = QColor((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF);
}
else if (!strcmp(attrs[i], "fix_cost"))
cat.fix_cost = (wxString(attrs[i+1], wxConvUTF8) == wxT("1"));
cat.fix_cost = (QString(attrs[i+1]) == "1");
}
UNESCAPE_CHARS(cat.name);
wxString catId = _this->_user->GetCategoryId(name);
int catId = _this->_user->GetCategoryId(name);
if (catId != wxT("0"))
if (catId)
{
_this->_categories[id] = catId;
return;
}
_this->_categories[id] = wxT("unknown-") + name;
_this->_categories[id] = --unknownCategory;
_this->_unresolvedCategories.push_back(cat);
}
@@ -151,68 +152,61 @@ void XMLImportEngine::LoadOperation(XMLImportEngine* _this, const char** attrs)
{
int i;
Operation op;
long v;
double amount;
wxString id;
for (i=0; attrs[i]; i+=2)
{
if (!strcmp(attrs[i], "id"))
op.id = wxString(attrs[i+1], wxConvUTF8);
op.id = QString(attrs[i+1]).toInt();
else if (!strcmp(attrs[i], "parent"))
op.parent = wxString(attrs[i+1], wxConvUTF8);
op.parent = QString(attrs[i+1]).toInt();
else if (!strcmp(attrs[i], "day"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&v);
op.day = v;
op.day = QString(attrs[i+1]).toInt();
}
else if (!strcmp(attrs[i], "month"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&v);
op.month = v;
op.month = QString(attrs[i+1]).toInt();
}
else if (!strcmp(attrs[i], "year"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&v);
op.year = v;
op.year = QString(attrs[i+1]).toInt();
}
else if (!strcmp(attrs[i], "amount"))
{
wxString(attrs[i+1], wxConvUTF8).ToDouble(&amount);
op.amount = amount;
op.amount = QString(attrs[i+1]).toDouble();
}
else if (!strcmp(attrs[i], "description"))
op.description = wxString(attrs[i+1], wxConvUTF8);
op.description = QString(attrs[i+1]);
else if (!strcmp(attrs[i], "category"))
op.category = _this->_categories[wxString(attrs[i+1], wxConvUTF8)];
op.category = _this->_categories[QString(attrs[i+1]).toInt()];
else if (!strcmp(attrs[i], "fix_cost"))
op.fix_cost = (wxString(attrs[i+1], wxConvUTF8) == wxT("1"));
op.fix_cost = (QString(attrs[i+1]) == "1");
else if (!strcmp(attrs[i], "account"))
op.account = _this->_accounts[wxString(attrs[i+1], wxConvUTF8)];
op.account = _this->_accounts[QString(attrs[i+1]).toInt()];
else if (!strcmp(attrs[i], "checked"))
op.checked = (wxString(attrs[i+1], wxConvUTF8) == wxT("1"));
op.checked = (QString(attrs[i+1]) == "1");
else if (!strcmp(attrs[i], "transfert"))
op.transfert = wxString(attrs[i+1], wxConvUTF8);
op.transfert = QString(attrs[i+1]).toInt();
else if (!strcmp(attrs[i], "formula"))
op.formula = wxString(attrs[i+1], wxConvUTF8);
op.formula = QString(attrs[i+1]);
else if (!strcmp(attrs[i], "meta"))
op.meta = (wxString(attrs[i+1], wxConvUTF8) == wxT("1"));
op.meta = (QString(attrs[i+1]) == "1");
else if (!strcmp(attrs[i], "virtual"))
op._virtual = (wxString(attrs[i+1], wxConvUTF8) == wxT("1"));
op._virtual = (QString(attrs[i+1]) == "1");
}
UNESCAPE_CHARS(op.description);
@@ -263,7 +257,7 @@ XMLImportEngine::XMLImportEngine()
{
KissCount::RegisterImportEngine(this);
_shortExt = wxT("xml");
_shortExt = "xml";
_longExt = _("KissCount xml files (*.xml)|*.xml");
_sax.startElement = XmlStartElement ;
@@ -273,7 +267,7 @@ XMLImportEngine::~XMLImportEngine()
{
}
bool XMLImportEngine::HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)
bool XMLImportEngine::HandleFile(const QString& path, User* user, Database* db, KissCount* kiss)
{
int res = -1 ;
@@ -281,7 +275,7 @@ bool XMLImportEngine::HandleFile(const wxString& path, User* user, Database* db,
try
{
res = xmlSAXUserParseFile(&_sax, this, path.mb_str()) >= 0;
res = xmlSAXUserParseFile(&_sax, this, path.toStdString().c_str()) >= 0;
}
catch (const char* s)
{