Initial commit

A good base to start working
This commit is contained in:
2010-05-14 15:04:01 +02:00
commit ee8d4c0c8f
25 changed files with 1003 additions and 0 deletions

28
model/Account.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <list>
#include <map>
struct operation {
unsigned int day;
unsigned int month;
unsigned int year;
unsigned int amount;
std::string description;
std::string category;
bool fix_cost;
} ;
class Account
{
private:
std::string _name;
std::string _number;
std::map<unsigned int, std::map<unsigned int, std::list<operation> > > _operations;
bool _shared;
bool _default;
};
#endif

115
model/Database.cpp Normal file
View File

@@ -0,0 +1,115 @@
#include "Database.h"
Database::Database()
{
std::ifstream bdd_file;
bdd_file.open(BDD_FILE);
if (!bdd_file)
{
CreateDatabase();
}
else
_db.Open(_(BDD_FILE));
bdd_file.close();
}
void Database::CreateDatabase()
{
std::ifstream init_script;
std::string line;
wxMessageBox(_("No database found, creating a new one"), _("KissCount"), wxICON_EXCLAMATION | wxOK );
init_script.open(INIT_SCRIPT);
if (!init_script)
{
wxMessageBox(_(INIT_SCRIPT " not found, aborting"), _("Error"), wxICON_ERROR | wxOK );
throw "init.sql not found, aborting";
}
_db.Open(_(BDD_FILE));
do
{
getline(init_script, line);
if (!_db.CheckSyntax(line.data()))
{
std::cout << line << " is invalid !\n" ;
continue;
}
try
{
_db.ExecuteUpdate(line.data());
}
catch (...)
{
wxMessageBox(_("Error creating original database"), _("Error"), wxICON_ERROR | wxOK );
throw line;
}
} while (init_script);
init_script.close();
}
std::list<wxString> Database::GetUsers()
{
std::list<wxString> res;
// Check whether value exists in table
wxSQLite3ResultSet set ;
try
{
set = _db.ExecuteQuery(wxT("SELECT name FROM user"));
}
catch (wxSQLite3Exception e)
{
std::cerr << e.GetMessage().mb_str() << "\n" ;
return res;
}
while (set.NextRow())
{
res.push_front(set.GetAsString(0));
}
set.Finalize();
return res;
}
bool Database::IsValidUser(wxString user, wxString password)
{
bool res;
blk_SHA_CTX sha_ctx;
unsigned char sha[20];
wxString req, wxSHA;
wxSQLite3ResultSet set;
blk_SHA1_Init(&sha_ctx);
blk_SHA1_Update(&sha_ctx, password.c_str(), password.Length());
blk_SHA1_Final(sha, &sha_ctx);
for(int i=0; i<20; i++)
wxSHA += wxString::Format(wxT("%02F"), (int)sha[i]);
req = _("SELECT name FROM user WHERE name='") + user + _("' AND password='") + wxSHA + _("'");
// Check whether value exists in table
try
{
set = _db.ExecuteQuery(req);
}
catch (wxSQLite3Exception e)
{
std::cerr << e.GetMessage().mb_str() << "\n" ;
return false;
}
res = set.NextRow() ;
set.Finalize();
return res;
}

26
model/Database.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef DATABASE_H
#define DATABASE_H
#include <fstream>
#include <list>
#include <wx/wxsqlite3.h>
#include <wx/wx.h>
#include <sha1.h>
#define BDD_FILE "kc.bdd"
#define INIT_SCRIPT "init.sql"
class Database
{
public:
Database();
std::list<wxString> GetUsers();
bool IsValidUser(wxString user, wxString password);
private:
wxSQLite3Database _db;
void CreateDatabase();
};
#endif

13
model/Preferences.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef PREFERENCES_H
#define PREFERENCES_H
#include <wx/colour.h>
#include <map>
class Preferences
{
private:
std::map<std::string, wxColour> _colors;
};
#endif

17
model/User.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef USER_H
#define USER_H
#include <list>
#include "Account.h"
class User
{
private:
unsigned int _id;
wxString _name;
wxString _password;
std::list<Account> _accounts;
};
#endif