First runnable version
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <iostream>
|
||||
|
||||
#include "GrisbiImportEngine.hpp"
|
||||
|
||||
@@ -25,23 +26,23 @@ static GrisbiImportEngine grisbiImportEngine;
|
||||
|
||||
void GrisbiImportEngine::LoadAccount(GrisbiImportEngine* _this, const char** attrs)
|
||||
{
|
||||
int i;
|
||||
wxString account_number, name, id, key;
|
||||
int i, id;
|
||||
QString account_number, name, key;
|
||||
Account ac;
|
||||
|
||||
for (i=0; attrs[i]; i+=2)
|
||||
{
|
||||
if (!strcmp(attrs[i], "Name"))
|
||||
name = wxString(attrs[i+1], wxConvUTF8);
|
||||
name = attrs[i+1];
|
||||
|
||||
else if (!strcmp(attrs[i], "Number"))
|
||||
id = wxString(attrs[i+1], wxConvUTF8);
|
||||
id = QString(attrs[i+1]).toInt();
|
||||
|
||||
else if (!strcmp(attrs[i], "Bank_account_number"))
|
||||
account_number = wxString(attrs[i+1], wxConvUTF8);
|
||||
account_number = attrs[i+1];
|
||||
|
||||
else if (!strcmp(attrs[i], "Key"))
|
||||
key = wxString(attrs[i+1], wxConvUTF8);
|
||||
key = attrs[i+1];
|
||||
}
|
||||
|
||||
account_number += key;
|
||||
@@ -58,7 +59,7 @@ void GrisbiImportEngine::LoadAccount(GrisbiImportEngine* _this, const char** att
|
||||
}
|
||||
}
|
||||
|
||||
_this->_accounts[id] = wxT("unknown-") + account_number;
|
||||
_this->_accounts[id] = 0;
|
||||
ac.number = account_number;
|
||||
ac.name = name;
|
||||
ac.shared = false;
|
||||
@@ -71,17 +72,17 @@ void GrisbiImportEngine::LoadAccount(GrisbiImportEngine* _this, const char** att
|
||||
|
||||
void GrisbiImportEngine::LoadCategory(GrisbiImportEngine* _this, const char** attrs)
|
||||
{
|
||||
wxString name, id;
|
||||
int i;
|
||||
QString name;
|
||||
int i, id;
|
||||
Category cat;
|
||||
|
||||
for (i=0; attrs[i]; i+=2)
|
||||
{
|
||||
if (!strcmp(attrs[i], "Na"))
|
||||
name = wxString(attrs[i+1], wxConvUTF8);
|
||||
name = attrs[i+1];
|
||||
|
||||
else if (!strcmp(attrs[i], "Nb"))
|
||||
id = wxString(attrs[i+1], wxConvUTF8);
|
||||
id = QString(attrs[i+1]).toInt();
|
||||
}
|
||||
|
||||
UNESCAPE_CHARS(name);
|
||||
@@ -95,12 +96,12 @@ void GrisbiImportEngine::LoadCategory(GrisbiImportEngine* _this, const char** at
|
||||
}
|
||||
}
|
||||
|
||||
_this->_categories[id] = wxT("unknown-") + name;
|
||||
_this->_categories[id] = 0;
|
||||
cat.id = id;
|
||||
cat.name = name;
|
||||
cat.parent = wxT("0");
|
||||
cat.parent = 0;
|
||||
cat.backcolor = view::OWN_GREEN ;
|
||||
cat.forecolor = *wxBLACK;
|
||||
cat.forecolor = Qt::black;
|
||||
cat.fix_cost = false;
|
||||
_this->_unresolvedCategories.push_back(cat);
|
||||
}
|
||||
@@ -110,44 +111,42 @@ void GrisbiImportEngine::LoadOperation(GrisbiImportEngine* _this, const char** a
|
||||
int i;
|
||||
static int id=0;
|
||||
Operation op;
|
||||
wxString amount;
|
||||
wxDateTime date;
|
||||
QDate date;
|
||||
|
||||
op.id = wxString::Format(wxT("%d"), ++id);
|
||||
op.parent = wxT("");
|
||||
op.account = wxT("unknwon-0");
|
||||
op.category = wxT("unknwon-0");
|
||||
op.id = ++id;
|
||||
op.parent = 0;
|
||||
op.account = 0;
|
||||
op.category = 0;
|
||||
op.fix_cost = false;
|
||||
op.checked = false;
|
||||
op.transfert = wxT("");
|
||||
op.formula = wxT("");
|
||||
op.transfert = 0;
|
||||
op.formula = "";
|
||||
op.meta = false;
|
||||
op._virtual = false;
|
||||
|
||||
for (i=0; attrs[i]; i+=2)
|
||||
{
|
||||
if (!strcmp(attrs[i], "Ac"))
|
||||
op.account = _this->_accounts[wxString(attrs[i+1], wxConvUTF8)];
|
||||
op.account = _this->_accounts[QString(attrs[i+1]).toInt()];
|
||||
|
||||
else if (!strcmp(attrs[i], "Dt"))
|
||||
{
|
||||
date.ParseFormat(wxString(attrs[i+1], wxConvUTF8), wxT("%m/%d/%Y"));
|
||||
op.day = date.GetDay();
|
||||
op.month = date.GetMonth();
|
||||
op.year = date.GetYear();
|
||||
date.fromString(attrs[i+1], "MM/%dd/%yyyy");
|
||||
op.day = date.day();
|
||||
op.month = date.month();
|
||||
op.year = date.year();
|
||||
}
|
||||
|
||||
else if (!strcmp(attrs[i], "Am"))
|
||||
{
|
||||
amount = wxString(attrs[i+1], wxConvUTF8);
|
||||
amount.ToDouble(&op.amount);
|
||||
op.amount = QString(attrs[i+1]).toDouble();
|
||||
}
|
||||
|
||||
else if (!strcmp(attrs[i], "Ca"))
|
||||
op.category = _this->_categories[wxString(attrs[i+1], wxConvUTF8)];
|
||||
op.category = _this->_categories[QString(attrs[i+1]).toInt()];
|
||||
|
||||
else if (!strcmp(attrs[i], "No"))
|
||||
op.description = wxString(attrs[i+1], wxConvUTF8);
|
||||
op.description = attrs[i+1];
|
||||
}
|
||||
|
||||
UNESCAPE_CHARS(op.description);
|
||||
@@ -199,7 +198,7 @@ GrisbiImportEngine::GrisbiImportEngine()
|
||||
{
|
||||
KissCount::RegisterImportEngine(this);
|
||||
|
||||
_shortExt = wxT("gsb");
|
||||
_shortExt = "gsb";
|
||||
_longExt = _("Grisbi files (*.gsb)|*.gsb");
|
||||
|
||||
_sax.startElement = GrisbiStartElement ;
|
||||
@@ -209,7 +208,7 @@ GrisbiImportEngine::~GrisbiImportEngine()
|
||||
{
|
||||
}
|
||||
|
||||
bool GrisbiImportEngine::HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)
|
||||
bool GrisbiImportEngine::HandleFile(const QString& path, User* user, Database* db, KissCount* kiss)
|
||||
{
|
||||
int res = -1;
|
||||
|
||||
@@ -217,7 +216,7 @@ bool GrisbiImportEngine::HandleFile(const wxString& path, User* user, Database*
|
||||
|
||||
try
|
||||
{
|
||||
res = xmlSAXUserParseFile(&_sax, this, path.mb_str());
|
||||
res = xmlSAXUserParseFile(&_sax, this, path.toStdString().c_str());
|
||||
}
|
||||
catch (const char* s)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
GrisbiImportEngine();
|
||||
~GrisbiImportEngine();
|
||||
|
||||
virtual bool HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss);
|
||||
virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss);
|
||||
|
||||
private:
|
||||
xmlSAXHandler _sax;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "ImportEngine.hpp"
|
||||
|
||||
wxString ImportEngine::NULL_IMPORT_PATTERN = wxT("(nil)");
|
||||
QString ImportEngine::NULL_IMPORT_PATTERN = "(nil)";
|
||||
|
||||
ImportEngine::ImportEngine()
|
||||
{
|
||||
@@ -31,7 +31,7 @@ ImportEngine::~ImportEngine()
|
||||
{
|
||||
}
|
||||
|
||||
bool ImportEngine::HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)
|
||||
bool ImportEngine::HandleFile(const QString& path, User* user, Database* db, KissCount* kiss)
|
||||
{
|
||||
_path = path;
|
||||
_user = user;
|
||||
@@ -44,39 +44,39 @@ bool ImportEngine::HandleFile(const wxString& path, User* user, Database* db, Ki
|
||||
_descriptions.clear();
|
||||
_accountAmounts.clear();
|
||||
|
||||
return path.EndsWith(_shortExt) || path.EndsWith(_shortExt.Upper());
|
||||
return path.endsWith(_shortExt) || path.endsWith(_shortExt.toUpper());
|
||||
}
|
||||
|
||||
wxString ImportEngine::GetFileExt()
|
||||
QString ImportEngine::GetFileExt()
|
||||
{
|
||||
return wxGetTranslation(_longExt);
|
||||
return _(_longExt.toStdString().c_str());
|
||||
}
|
||||
|
||||
std::vector<wxString> ExplodeString(wxString& s)
|
||||
std::vector<QString> ExplodeString(QString& s)
|
||||
{
|
||||
wxString tmp = s, cur = wxT("");
|
||||
std::vector<wxString> res;
|
||||
QString tmp = s, cur = "";
|
||||
std::vector<QString> res;
|
||||
|
||||
while (tmp.Len())
|
||||
while (tmp.size())
|
||||
{
|
||||
if (tmp.StartsWith(wxT(" ")) ||
|
||||
tmp.StartsWith(wxT("\t")) ||
|
||||
tmp.StartsWith(wxT("\n")) ||
|
||||
tmp.StartsWith(wxT("\r")))
|
||||
if (tmp.startsWith(" " ) ||
|
||||
tmp.startsWith("\t") ||
|
||||
tmp.startsWith("\n") ||
|
||||
tmp.startsWith("\r"))
|
||||
{
|
||||
if (cur.Len())
|
||||
if (cur.size())
|
||||
{
|
||||
res.push_back(cur);
|
||||
cur = wxT("");
|
||||
cur = "";
|
||||
}
|
||||
tmp = tmp.Mid(1);
|
||||
tmp = tmp.right(tmp.size()-1);
|
||||
continue;
|
||||
}
|
||||
cur += tmp.SubString(0, 0);
|
||||
tmp = tmp.Mid(1);
|
||||
cur += tmp.left(1);
|
||||
tmp = tmp.right(tmp.size()-1);
|
||||
}
|
||||
|
||||
if (cur.Len())
|
||||
if (cur.size())
|
||||
res.push_back(cur);
|
||||
|
||||
return res;
|
||||
@@ -88,30 +88,31 @@ std::vector<wxString> ExplodeString(wxString& s)
|
||||
- tail spaces
|
||||
- every word starting by a number
|
||||
*/
|
||||
wxString ImportEngine::RemoveUnused(const wxString& s)
|
||||
QString ImportEngine::RemoveUnused(const QString& s)
|
||||
{
|
||||
wxString tmp = s, tmp2;
|
||||
wxString res;
|
||||
QString tmp = s, tmp2;
|
||||
QString res;
|
||||
bool number;
|
||||
|
||||
tmp = tmp.Trim(true);
|
||||
tmp = tmp.Trim(false);
|
||||
tmp = tmp.trimmed();
|
||||
|
||||
while (tmp.Len())
|
||||
while (tmp.size())
|
||||
{
|
||||
tmp2 = tmp.SubString(0, 0);
|
||||
if (tmp2.IsNumber())
|
||||
tmp2 = tmp.left(1);
|
||||
tmp2.toInt(&number);
|
||||
if (number)
|
||||
{
|
||||
do
|
||||
{
|
||||
tmp = tmp.Mid(1);
|
||||
tmp2 = tmp.SubString(0, 0);
|
||||
} while (tmp.Len() && tmp2 != wxT(" ") &&
|
||||
tmp2 != wxT("\t") &&
|
||||
tmp2 != wxT("\r") &&
|
||||
tmp2 != wxT("\n"));
|
||||
tmp = tmp.right(tmp.size()-1);
|
||||
tmp2 = tmp.left(1);
|
||||
} while (tmp.size() && tmp2 != " " &&
|
||||
tmp2 != "\t" &&
|
||||
tmp2 != "\r" &&
|
||||
tmp2 != "\n");
|
||||
}
|
||||
res += tmp2;
|
||||
tmp = tmp.Mid(1);
|
||||
tmp = tmp.right(tmp.size()-1);
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -125,12 +126,12 @@ wxString ImportEngine::RemoveUnused(const wxString& s)
|
||||
%wX : word orig[X]
|
||||
other : constants
|
||||
*/
|
||||
wxString ImportEngine::FindPattern(wxString& orig, wxString& dest)
|
||||
QString ImportEngine::FindPattern(QString& orig, QString& dest)
|
||||
{
|
||||
wxString pattern, cur_pat;
|
||||
QString pattern, cur_pat;
|
||||
int i, a;
|
||||
std::vector<wxString> tok1;
|
||||
std::vector<wxString> tok2;
|
||||
std::vector<QString> tok1;
|
||||
std::vector<QString> tok2;
|
||||
int size1, size2;
|
||||
|
||||
if (orig == dest) return NULL_IMPORT_PATTERN;
|
||||
@@ -142,49 +143,49 @@ wxString ImportEngine::FindPattern(wxString& orig, wxString& dest)
|
||||
|
||||
for(i=0; i<size2; i++)
|
||||
{
|
||||
cur_pat = wxT("");
|
||||
cur_pat = "";
|
||||
|
||||
for (a=0; a<size1; a++)
|
||||
{
|
||||
if (tok2[i] == tok1[a])
|
||||
{
|
||||
cur_pat = wxT("%w");
|
||||
cur_pat = "%w";
|
||||
break;
|
||||
}
|
||||
else if (tok2[i] == tok1[a].Lower())
|
||||
else if (tok2[i] == tok1[a].toLower())
|
||||
{
|
||||
cur_pat = wxT("%m");
|
||||
cur_pat = "%m";
|
||||
break;
|
||||
}
|
||||
else if (tok2[i] == tok1[a].Upper())
|
||||
else if (tok2[i] == tok1[a].toUpper())
|
||||
{
|
||||
cur_pat = wxT("%m");
|
||||
cur_pat = "%m";
|
||||
break;
|
||||
}
|
||||
else if (tok2[i].Lower() == tok1[a].Lower() && tok2[i][0] == tok1[a][0])
|
||||
else if (tok2[i].toLower() == tok1[a].toLower() && tok2[i][0] == tok1[a][0])
|
||||
{
|
||||
cur_pat = wxT("%f");
|
||||
cur_pat = "%f";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cur_pat.Len())
|
||||
pattern += cur_pat + wxString::Format(wxT("%d"), a);
|
||||
if (cur_pat.size())
|
||||
pattern += cur_pat + QString::number(a);
|
||||
else
|
||||
pattern += tok2[i];
|
||||
|
||||
pattern += wxT(" ");
|
||||
pattern += " ";
|
||||
}
|
||||
|
||||
pattern = pattern.Trim();
|
||||
pattern = pattern.trimmed();
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
void ImportEngine::ApplyPattern(ImportPattern& pattern, Operation& op)
|
||||
{
|
||||
std::vector<wxString> tok1;
|
||||
std::vector<wxString> tok2;
|
||||
std::vector<QString> tok1;
|
||||
std::vector<QString> tok2;
|
||||
int size1, i;
|
||||
long pos;
|
||||
|
||||
@@ -197,38 +198,38 @@ void ImportEngine::ApplyPattern(ImportPattern& pattern, Operation& op)
|
||||
tok2 = ExplodeString(op.description);
|
||||
size1 = tok1.size();
|
||||
|
||||
op.description = wxT("");
|
||||
op.description = "";
|
||||
|
||||
for(i=0; i<size1; i++)
|
||||
{
|
||||
pos = -1;
|
||||
if (tok1[i].StartsWith(wxT("%")))
|
||||
if (tok1[i].startsWith("%"))
|
||||
{
|
||||
tok1[i].Mid(3).ToLong(&pos);
|
||||
pos = tok1[i].right(tok1[i].size()-3).toInt();
|
||||
}
|
||||
|
||||
if (pos != -1)
|
||||
{
|
||||
if (tok1[i].SubString(1, 1) == wxT("w"))
|
||||
if (tok1[i].left(2).right(1) == "w")
|
||||
op.description += tok2[pos];
|
||||
else if (tok1[i].SubString(1, 1) == wxT("m"))
|
||||
op.description += tok2[pos].Lower();
|
||||
else if (tok1[i].SubString(1, 1) == wxT("M"))
|
||||
op.description += tok2[pos].Upper();
|
||||
else if (tok1[i].SubString(1, 1) == wxT("f"))
|
||||
op.description += tok2[pos].SubString(0, 0).Upper() + tok2[pos].Mid(1).Lower();
|
||||
else if (tok1[i].left(2).right(1) == "m")
|
||||
op.description += tok2[pos].toLower();
|
||||
else if (tok1[i].left(2).right(1) == "M")
|
||||
op.description += tok2[pos].toUpper();
|
||||
else if (tok1[i].left(2).right(1) == "f")
|
||||
op.description += tok2[pos].left(1).toUpper() + tok2[pos].right(tok2[pos].size()-1).toLower();
|
||||
}
|
||||
else
|
||||
op.description += tok1[i];
|
||||
op.description += wxT(" ");
|
||||
op.description += " ";
|
||||
}
|
||||
|
||||
op.description.Trim();
|
||||
op.description = op.description.trimmed();
|
||||
}
|
||||
|
||||
int ImportEngine::UpdatePattern(int pos)
|
||||
{
|
||||
wxString key1, key2;
|
||||
QString key1, key2;
|
||||
ImportPattern pattern;
|
||||
Operation op;
|
||||
int i, nbOpUpdated = 0;
|
||||
@@ -261,9 +262,9 @@ int ImportEngine::UpdatePattern(int pos)
|
||||
return nbOpUpdated;
|
||||
}
|
||||
|
||||
void ImportEngine::MatchPattern(wxString& originalKey, Operation& op)
|
||||
void ImportEngine::MatchPattern(QString& originalKey, Operation& op)
|
||||
{
|
||||
wxString key1;
|
||||
QString key1;
|
||||
ImportPattern pattern;
|
||||
|
||||
if (!_user) return;
|
||||
@@ -293,19 +294,19 @@ void ImportEngine::ParseFile(std::vector<Account>& accounts, std::vector<Categor
|
||||
categories = _unresolvedCategories;
|
||||
}
|
||||
|
||||
std::vector<Operation>* ImportEngine::GetOperations(std::map<wxString, wxString>& accounts, std::map<wxString, wxString>& categories)
|
||||
std::vector<Operation>* ImportEngine::GetOperations(std::map<int, int>& accounts, std::map<int, int>& categories)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0; i<(int)_operations.size(); i++)
|
||||
{
|
||||
if (_operations[i].account.StartsWith(wxT("unknown-")))
|
||||
_operations[i].account = accounts[_operations[i].account.Mid(8)];
|
||||
if (_operations[i].category.StartsWith(wxT("unknown-")))
|
||||
_operations[i].category = categories[_operations[i].category.Mid(8)];
|
||||
if (_operations[i].account < 0)
|
||||
_operations[i].account = accounts[_operations[i].account];
|
||||
if (_operations[i].category < 0)
|
||||
_operations[i].category = categories[_operations[i].category];
|
||||
}
|
||||
|
||||
if (_kiss->GetOperationOrder() == wxT("ASC"))
|
||||
if (_kiss->GetOperationOrder() == "ASC")
|
||||
std::sort(_operations.begin(), _operations.end(), sortOperations);
|
||||
else
|
||||
std::sort(_operations.begin(), _operations.end(), reverseSortOperations);
|
||||
|
||||
@@ -28,24 +28,24 @@ class KissCount;
|
||||
|
||||
class ImportPattern {
|
||||
public:
|
||||
std::string pattern;
|
||||
QString pattern;
|
||||
int account;
|
||||
int category;
|
||||
} ;
|
||||
|
||||
class ImportEngine {
|
||||
public:
|
||||
static std::string NULL_IMPORT_PATTERN;
|
||||
static QString NULL_IMPORT_PATTERN;
|
||||
|
||||
ImportEngine();
|
||||
~ImportEngine();
|
||||
|
||||
// Get supported file extension. Example :
|
||||
// "OFX files (*.ofx)|*.ofx"
|
||||
virtual std::string GetFileExt();
|
||||
virtual QString GetFileExt();
|
||||
|
||||
// Handle the file
|
||||
virtual bool HandleFile(const std::string& path, User* user, Database* db, KissCount* kiss)=0;
|
||||
virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss)=0;
|
||||
|
||||
// Parse the file and return accounts that doesn't match
|
||||
virtual void ParseFile(std::vector<Account>& accounts, std::vector<Category>& categories);
|
||||
@@ -55,30 +55,30 @@ public:
|
||||
|
||||
const std::map<AccountAmount, double, AccountAmount>& GetAccountAmounts();
|
||||
|
||||
void MatchPattern(std::string& key, Operation& op);
|
||||
void MatchPattern(QString& key, Operation& op);
|
||||
int UpdatePattern(int pos);
|
||||
|
||||
static std::string RemoveUnused(const std::string& s);
|
||||
static QString RemoveUnused(const QString& s);
|
||||
|
||||
protected:
|
||||
Database* _db;
|
||||
User* _user;
|
||||
std::string _path;
|
||||
QString _path;
|
||||
KissCount* _kiss;
|
||||
|
||||
std::string _shortExt;
|
||||
std::string _longExt;
|
||||
QString _shortExt;
|
||||
QString _longExt;
|
||||
|
||||
std::map<int, int> _accounts;
|
||||
std::map<int, int> _categories;
|
||||
std::vector<Account> _unresolvedAccounts;
|
||||
std::vector<Category> _unresolvedCategories;
|
||||
std::vector<Operation> _operations;
|
||||
std::map<std::string, std::string> _descriptions;
|
||||
std::map<int, QString> _descriptions;
|
||||
std::map<AccountAmount, double, AccountAmount> _accountAmounts;
|
||||
|
||||
void ApplyPattern(ImportPattern& pattern, Operation& op);
|
||||
std::string FindPattern(std::string& s1, std::string& s2);
|
||||
QString FindPattern(QString& s1, QString& s2);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "../Database.hpp"
|
||||
|
||||
#include "OFXImportEngine.hpp"
|
||||
|
||||
@@ -23,20 +24,23 @@ static OFXImportEngine ofxImportEngine;
|
||||
|
||||
int OFXImportEngine::account_cb(const struct OfxAccountData data, void * account_data)
|
||||
{
|
||||
int i;
|
||||
int i, id;
|
||||
OFXImportEngine* _this = (OFXImportEngine*) account_data;
|
||||
wxString account_number = wxString(data.account_number, wxConvUTF8);
|
||||
QString account_number = QString(data.account_number);
|
||||
Account ac;
|
||||
static int unknownAccount = 0;
|
||||
|
||||
_this->_curAccount = wxT("");
|
||||
_this->_curAccount = 0;
|
||||
|
||||
UNESCAPE_CHARS(account_number);
|
||||
|
||||
id = Database::HashPassword(data.account_id).toInt(0, 16);
|
||||
|
||||
for (i=0; i<(int)_this->_user->_accounts.size(); i++)
|
||||
{
|
||||
if (_this->_user->_accounts[i].number == account_number)
|
||||
{
|
||||
_this->_accounts[account_number] = _this->_user->_accounts[i].id;
|
||||
_this->_accounts[id] = _this->_user->_accounts[i].id;
|
||||
_this->_curAccount = _this->_user->_accounts[i].id;
|
||||
// std::cout << "Account " << data.account_number << " is " << i << std::endl;
|
||||
//_this->_unresolvedAccounts.push_back(account_number);
|
||||
@@ -44,9 +48,9 @@ int OFXImportEngine::account_cb(const struct OfxAccountData data, void * account
|
||||
}
|
||||
}
|
||||
|
||||
if (!_this->_curAccount.Len())
|
||||
if (!_this->_curAccount)
|
||||
{
|
||||
_this->_curAccount = _this->_accounts[account_number] = wxT("unknown-") + account_number;
|
||||
_this->_curAccount = _this->_accounts[id] = --unknownAccount;
|
||||
ac.number = account_number;
|
||||
ac.shared = false;
|
||||
ac.blocked = false;
|
||||
@@ -69,14 +73,14 @@ int OFXImportEngine::transaction_cb(const struct OfxTransactionData data, void *
|
||||
if (!data.amount_valid ||
|
||||
(!data.date_posted_valid && !data.date_initiated_valid)) return 1;
|
||||
|
||||
op.id = wxString::Format(wxT("%d"), ++id);
|
||||
op.parent = wxT("");
|
||||
op.category = wxT("0");
|
||||
op.id = ++id;
|
||||
op.parent = 0;
|
||||
op.category = 0;
|
||||
op.fix_cost = false;
|
||||
op.account = _this->_curAccount;
|
||||
op.checked = false;
|
||||
op.transfert = wxT("");
|
||||
op.formula = wxT("");
|
||||
op.transfert = 0;
|
||||
op.formula = "";
|
||||
op.meta = false;
|
||||
op._virtual = false;
|
||||
|
||||
@@ -92,13 +96,13 @@ int OFXImportEngine::transaction_cb(const struct OfxTransactionData data, void *
|
||||
op.year = t.tm_year+1900;
|
||||
|
||||
if (data.name_valid)
|
||||
op.description = wxString(data.name, wxConvUTF8);
|
||||
op.description = data.name;
|
||||
|
||||
if (data.memo_valid)
|
||||
{
|
||||
if (op.description.Len())
|
||||
op.description += wxT(" ");
|
||||
op.description += wxString(data.memo, wxConvUTF8);
|
||||
if (op.description.size())
|
||||
op.description += " ";
|
||||
op.description += data.memo;
|
||||
}
|
||||
|
||||
UNESCAPE_CHARS(op.description);
|
||||
@@ -131,7 +135,7 @@ OFXImportEngine::OFXImportEngine()
|
||||
ofx_set_transaction_cb(_ctx, transaction_cb, this);
|
||||
ofx_set_statement_cb(_ctx, account_balance_cb, this);
|
||||
|
||||
_shortExt = wxT("ofx");
|
||||
_shortExt = "ofx";
|
||||
_longExt = _("OFX files (*.ofx)|*.ofx");
|
||||
}
|
||||
|
||||
@@ -141,9 +145,9 @@ OFXImportEngine::~OFXImportEngine()
|
||||
libofx_free_context(_ctx);
|
||||
}
|
||||
|
||||
bool OFXImportEngine::HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)
|
||||
bool OFXImportEngine::HandleFile(const QString& path, User* user, Database* db, KissCount* kiss)
|
||||
{
|
||||
if (!ImportEngine::HandleFile(path, user, db, kiss)) return false;
|
||||
|
||||
return !libofx_proc_file(_ctx, path.mb_str(), AUTODETECT);
|
||||
return !libofx_proc_file(_ctx, path.toStdString().c_str(), AUTODETECT);
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ public:
|
||||
OFXImportEngine();
|
||||
~OFXImportEngine();
|
||||
|
||||
virtual bool HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss);
|
||||
virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss);
|
||||
/* virtual std::vector<wxString> ParseFile(); */
|
||||
/* virtual std::vector<Operation>* GetOperations(std::map<wxString, wxString>& accounts); */
|
||||
|
||||
private:
|
||||
LibofxContextPtr _ctx;
|
||||
wxString _curAccount;
|
||||
int _curAccount;
|
||||
|
||||
static int account_cb(const struct OfxAccountData data, void * account_data);
|
||||
static int transaction_cb(const struct OfxTransactionData data, void * transaction_data);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
XMLImportEngine();
|
||||
~XMLImportEngine();
|
||||
|
||||
virtual bool HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss);
|
||||
virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss);
|
||||
|
||||
private:
|
||||
xmlSAXHandler _sax;
|
||||
|
||||
Reference in New Issue
Block a user