First pass

This commit is contained in:
2011-08-25 17:45:41 +02:00
parent ed6a7a5fef
commit 991486a042
64 changed files with 1257 additions and 8876 deletions

View File

@@ -4,26 +4,14 @@ SHARE_DIR=$(DESTDIR)$(ROOT_DIR)"/share/kisscount/"
DOC_DIR=$(DESTDIR)$(ROOT_DIR)"/share/doc/kisscount/"
BIN_DIR=$(DESTDIR)$(ROOT_DIR)"/bin/"
CXXFLAGS+=`wx-config --cxxflags` -Wall -Isrc -ggdb
CXXFLAGS+=-I./lib/wxsqlite3-1.9.9/include
CXXFLAGS+=-I./lib/freechart/include
CXXFLAGS+=-I/usr/include/libxml2
CXXFLAGS=`pkg-config --cflags QtCore QtGui QtSql` -Wall -Isrc -ggdb
CXXFLAGS+=-Wl,--rpath,"$(LIB_DIR)"
CXXFLAGS+=-DRESSOURCES_ROOT="\"$(SHARE_DIR)\""
# For developpers
#CXXFLAGS+=-DRESSOURCES_ROOT="\"./ressources/\""
LDFLAGS+=`wx-config --libs`
LDFLAGS=`pkg-config --libs QtCore QtGui QtSql`
LDFLAGS+=-lofx
LDFLAGS+=-lxml2
ifdef WIN32
LDFLAGS+=-L./lib/wxsqlite3-1.9.9/lib/ -lwxcode_msw_wxsqlite3-2.8
LDFLAGS+=-L./lib/freechart/lib -lwxcode_msw_freechart-2.8
else
LDFLAGS+=-L./lib/wxsqlite3-1.9.9/lib/ -lwxcode_gtk2u_wxsqlite3-2.8
LDFLAGS+=-L./lib/freechart/lib -lwxcode_gtk2u_freechart-2.8
endif
CXX=$(HOST)g++
@@ -31,17 +19,16 @@ SOURCES=$(shell find src -name '*.cpp' -type f | tr '\n' ' ')
HEADERS=$(shell find src -name '*.h' -type f)
OBJS=$(SOURCES:.cpp=.o)
all: check kc
all: kc
clean:
find src -type f -name '*.[o~]' -exec rm -f \{\} \;
rm -f kc
%.o : src/model/%.cpp src/model/import/%.cpp src/model/export/%.cpp src/view/%.cpp src/view/grid/%.cpp src/controller/%.cpp src/%.cpp
$(CXX) $(CXXFLAGS) -c $<
# %.o : src/model/%.cpp src/model/import/%.cpp src/model/export/%.cpp src/view/%.cpp src/view/grid/%.cpp src/controller/%.cpp src/%.cpp
check:
if ! test -d lib ; then echo lib directory not found, please see INSTALL ; return 1 ; fi
%.o : src/model/%.cpp src/model/import/%.cpp src/model/export/%.cpp src/view/%.cpp src/controller/%.cpp src/%.cpp src/%.c
$(CXX) $(CXXFLAGS) -c $<
kc: $(OBJS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)

View File

@@ -36,9 +36,9 @@ KissCount::KissCount(const char* bdd_filename) : _user(0)
_wxUI->SetLanguage(wxLocale::GetSystemLanguage());
_wxUI->Show(true);
_wxUI->Centre();
_wxUI->Disable();
_wxUI->show();
// _wxUI->Centre();
// _wxUI->Disable();
try
{
@@ -64,17 +64,17 @@ KissCount::~KissCount()
if (_user) delete _user;
}
std::list<wxString> KissCount::GetUsers()
std::list<std::string> KissCount::GetUsers()
{
return _db->GetUsers();
}
bool KissCount::IsValidUser(const wxString& user, const wxString& password)
bool KissCount::IsValidUser(const std::string& user, const std::string& password)
{
return _db->IsValidUser(user, password) ;
}
void KissCount::LoadUser(const wxString& user)
void KissCount::LoadUser(const std::string& user)
{
if (_user) delete _user;
_user = _db->LoadUser(user) ;
@@ -100,12 +100,12 @@ User* KissCount::GetUser()
return _user;
}
double KissCount::GetAccountAmount(const wxString& id, int month, int year)
double KissCount::GetAccountAmount(int id, int month, int year)
{
return _db->GetAccountAmount(id, month, year);
}
double KissCount::CalcAccountAmount(const wxString& id, int month, int year, bool* had_values)
double KissCount::CalcAccountAmount(int id, int month, int year, bool* had_values)
{
return _db->CalcAccountAmount(id, month, year, had_values);
}
@@ -115,7 +115,7 @@ void KissCount::UpdateOperation(Operation& op, bool checkTransfert)
// Unlink
if (checkTransfert)
{
op.transfert = wxT("");
op.transfert = 0;
_user->LinkOrUnlinkOperation(op);
}
@@ -126,9 +126,9 @@ void KissCount::UpdateOperation(Operation& op, bool checkTransfert)
_user->LinkOrUnlinkOperation(op);
}
wxString KissCount::AddOperation(Operation& op, bool checkTransfert)
int KissCount::AddOperation(Operation& op, bool checkTransfert)
{
wxString ret = _db->AddOperation(_user, op, checkTransfert);
int ret = _db->AddOperation(_user, op, checkTransfert);
if (checkTransfert && op.transfert.Length())
_user->LinkOrUnlinkOperation(op);
@@ -140,7 +140,7 @@ void KissCount::DeleteOperation(Operation& op)
{
if (op.transfert.Length())
{
op.transfert = wxT("");
op.transfert = 0;
_user->LinkOrUnlinkOperation(op);
}
_db->DeleteOperation(_user, op);
@@ -159,22 +159,22 @@ void KissCount::DeleteOperations(int month, int year)
}
}
double KissCount::MetaAmount(const wxString& id)
double KissCount::MetaAmount(int id)
{
return _db->MetaAmount(id);
}
double KissCount::MetaPositiveAmount(const wxString& id)
double KissCount::MetaPositiveAmount(int id)
{
return _db->MetaPositiveAmount(id);
}
void KissCount::SetAccountAmount(const wxString& accountId, int month, int year, double amount)
void KissCount::SetAccountAmount(int accountId, int month, int year, double amount)
{
_db->SetAccountAmount(accountId, month, year, amount);
}
wxString KissCount::AddAccount(Account& ac)
int KissCount::AddAccount(Account& ac)
{
wxDateTime curDate;
@@ -196,7 +196,7 @@ void KissCount::UpdateAccount(Account& ac)
std::sort(_user->_accounts.begin(), _user->_accounts.end(), Account());
}
void KissCount::DeleteAccount(Account& ac, const wxString& replacement)
void KissCount::DeleteAccount(Account& ac, int replacement)
{
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it2;
@@ -209,27 +209,27 @@ void KissCount::DeleteAccount(Account& ac, const wxString& replacement)
LoadYear(it2->first, true);
}
void KissCount::AddSharedAccount(Account& ac, const wxString& granted)
void KissCount::AddSharedAccount(Account& ac, const std::string& granted)
{
_db->AddSharedAccount(ac, granted);
}
void KissCount::RemoveSharedAccount(Account& ac, const wxString& granted)
void KissCount::RemoveSharedAccount(Account& ac, const std::string& granted)
{
_db->RemoveSharedAccount(ac, granted);
}
std::map<wxString, wxString> KissCount::getSharedAccountOwners(const wxString& account)
std::map<int, int> KissCount::getSharedAccountOwners(int account)
{
return _db->getSharedAccountOwners(account);
}
wxString KissCount::getSharedAccountOwner(const wxString& account)
int KissCount::getSharedAccountOwner(int account)
{
return _db->getSharedAccountOwner(account);
}
wxString KissCount::AddCategory(Category& category)
int KissCount::AddCategory(Category& category)
{
category.id = _db->AddCategory(_user, category);
_user->AddCategory(category);
@@ -243,7 +243,7 @@ void KissCount::UpdateCategory(Category& category)
_user->UpdateCategory(category);
}
void KissCount::DeleteCategory(Category& category, const wxString& replacement)
void KissCount::DeleteCategory(Category& category, int replacement)
{
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it;
@@ -264,7 +264,7 @@ std::map<int, std::vector<int> > KissCount::GetAllOperations()
void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo)
{
std::vector<Operation>::iterator it, it2;
std::map<wxString, wxString> meta;
std::map<int, int> meta;
Operation op;
_db->GenerateMonth(_user, monthFrom, yearFrom, monthTo, yearTo);
@@ -317,17 +317,17 @@ void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int year
_wxUI->GenerateMonth(monthTo, yearTo);
}
void KissCount::ChangePassword(const wxString& password)
void KissCount::ChangePassword(const std::string& password)
{
_db->ChangePassword(_user, password);
}
bool KissCount::UserExists(const wxString& name)
bool KissCount::UserExists(const std::string& name)
{
return _db->UserExists(name);
}
void KissCount::ChangeName(const wxString& name)
void KissCount::ChangeName(const std::string& name)
{
_db->ChangeName(_user, name);
_user->_name = name;
@@ -339,13 +339,13 @@ wxString default_cats[] = {
_("Unexpected"), _("Other")
};
void KissCount::NewUser(const wxString& name)
void KissCount::NewUser(const std::string& name)
{
wxDateTime curDate;
Account ac = {
/*.id = */wxT(""),
/*.id = */0,
/*.name = */_("Account 1"),
/*.number = */wxT(""),
/*.number = */0,
/*.shared = */false,
/*.blocked = */false,
/*._default = */true,
@@ -360,20 +360,20 @@ void KissCount::NewUser(const wxString& name)
AddAccount(ac);
cat.parent = wxT("0") ; cat.name = wxT("Fix") ; cat.backcolor = view::OWN_YELLOW ; cat.forecolor = *wxBLACK; cat.fix_cost = true;
cat.parent = 0 ; cat.name = "Fix" ; cat.backcolor = view::OWN_YELLOW ; cat.forecolor = Qt::black; cat.fix_cost = true;
AddCategory(cat);
cat.parent = wxT("0") ; cat.name = wxT("Groceries") ; cat.backcolor = view::OWN_GREEN; cat.forecolor = *wxBLACK; cat.fix_cost = false;
cat.parent = 0 ; cat.name = "Groceries" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
AddCategory(cat);
cat.parent = wxT("0") ; cat.name = wxT("Hobbies") ; cat.backcolor = view::OWN_GREEN; cat.forecolor = *wxBLACK; cat.fix_cost = false;
cat.parent = 0 ; cat.name = "Hobbies" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
AddCategory(cat);
cat.parent = wxT("0") ; cat.name = wxT("Car") ; cat.backcolor = view::OWN_GREEN; cat.forecolor = *wxBLACK; cat.fix_cost = false;
cat.parent = 0 ; cat.name = "Car" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
AddCategory(cat);
cat.parent = wxT("0") ; cat.name = wxT("Unexpected") ; cat.backcolor = view::OWN_GREEN; cat.forecolor = *wxBLACK; cat.fix_cost = false;
cat.parent = 0 ; cat.name = "Unexpected" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
AddCategory(cat);
cat.parent = wxT("0") ; cat.name = wxT("Other") ; cat.backcolor = view::OWN_GREEN; cat.forecolor = *wxBLACK; cat.fix_cost = false;
cat.parent = 0 ; cat.name = "Other" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
AddCategory(cat);
SetOperationOrder(wxT("ASC"));
SetOperationOrder("ASC");
_db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear());
}
@@ -389,27 +389,27 @@ void KissCount::KillMe()
void KissCount::SetLanguage(wxLanguage language)
{
_user->_preferences[wxT("language")] = wxString::Format(wxT("%d"), language) ;
_db->UpdatePreference(_user, wxT("language"));
_user->_preferences["language"] = wxString::Format(wxT("%d"), language) ;
_db->UpdatePreference(_user, "language");
}
/*
ASC (default) or DESC
*/
void KissCount::SetOperationOrder(const wxString& order)
void KissCount::SetOperationOrder(const std::string& order)
{
_user->_preferences[wxT("operation_order")] = order;
_db->UpdatePreference(_user, wxT("operation_order"));
_user->_preferences["operation_order"] = order;
_db->UpdatePreference(_user, "operation_order");
}
const wxString& KissCount::GetOperationOrder()
const std::string& KissCount::GetOperationOrder()
{
return _user->_preferences[wxT("operation_order")] ;
return _user->_preferences["operation_order"] ;
}
std::vector<Operation>* KissCount::Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
wxString* amountFrom, wxString* amountTo,
std::vector<wxString> categories, int types, std::vector<wxString> accounts)
std::vector<Operation>* KissCount::Search(std::string* description, wxDateTime* dateFrom, wxDateTime* dateTo,
int* amountFrom, int* amountTo,
std::vector<int> categories, int types, std::vector<int> accounts)
{
return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, types, accounts, true);
@@ -460,8 +460,8 @@ bool KissCount::SearchPreviousOperation(Operation* res, Operation& op, int month
}
void KissCount::GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo,
std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
std::map<wxString, double>* categories)
std::map<int, std::map<int, std::map<int, double> > >* accountAmounts,
std::map<int, double>* categories)
{
wxString monthF = wxString::Format(wxT("%d"), monthFrom);
wxString monthT = wxString::Format(wxT("%d"), monthTo);
@@ -472,8 +472,8 @@ void KissCount::GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo,
}
void KissCount::GetMonthStats(int month, int year, int nbDays,
std::map<wxString, std::vector<double> >* operations,
std::map<wxString, double>* categories)
std::map<int, std::vector<double> >* operations,
std::map<int, double>* categories)
{
wxString monthS = wxString::Format(wxT("%d"), month);
wxString yearS = wxString::Format(wxT("%d"), year);
@@ -482,70 +482,76 @@ void KissCount::GetMonthStats(int month, int year, int nbDays,
}
std::map<wxString, double>* KissCount::GetNotChecked(int month, int year)
std::map<int, double>* KissCount::GetNotChecked(int month, int year)
{
return _db->GetNotChecked(_user, month, year);
}
std::map<wxString, double>* KissCount::GetVirtualAmount(int month, int year)
std::map<int, double>* KissCount::GetVirtualAmount(int month, int year)
{
return _db->GetVirtualAmount(_user, month, year);
}
wxFont KissCount::ExtractFont(wxString strFont)
QFont KissCount::ExtractFont(std::string strFont)
{
long int pos, pointSize, family, style, weight;
long int pointSize, family, style, weight;
size_t pos;
std::string tmp;
wxString faceName;
if (!strFont.Length())
if (!strFont.size())
{
DEFAULT_FONT(f);
return f;
}
pos = strFont.Find(wxT(";"));
pos = strFont.find(";");
if (pos != -1)
{
strFont.SubString(0, pos).ToLong(&pointSize);
strFont = strFont.SubString(pos+1, strFont.Length());
tmp = substring(strFont, 0, pos);
pointSize = QString(tmp).toInt();
strFont = strFont.substring(pos+1, strFont.size());
}
pos = strFont.find(";");
if (pos != -1)
{
tmp = substring(strFont, 0, pos);
family = QString(tmp).toInt();
strFont = strFont.substring(pos+1, strFont.size());
}
pos = strFont.find(";");
if (pos != -1)
{
tmp = substring(strFont, 0, pos);
style = QString(tmp).toInt();
strFont = strFont.substring(pos+1, strFont.size());
}
pos = strFont.Find(wxT(";"));
if (pos != -1)
{
strFont.SubString(0, pos).ToLong(&family);
strFont = strFont.SubString(pos+1, strFont.Length());
}
pos = strFont.Find(wxT(";"));
if (pos != -1)
{
strFont.SubString(0, pos).ToLong(&style);
strFont = strFont.SubString(pos+1, strFont.Length());
}
pos = strFont.Find(wxT(";"));
if (pos != -1)
{
strFont.SubString(0, pos).ToLong(&weight);
strFont = strFont.SubString(pos+1, strFont.Length());
tmp = substring(strFont, 0, pos);
weight = QString(tmp).toInt();
strFont = strFont.substring(pos+1, strFont.size());
}
faceName = strFont;
return wxFont(pointSize, family, style, weight, false, faceName) ;
return QFont(faceName, pointSize, weight);
}
wxString KissCount::CompactFont(const wxFont& font)
std::string KissCount::CompactFont(const QFont& font)
{
wxString res = wxString::Format(wxT("%d;%d;%d;%d;"), font.GetPointSize(), font.GetFamily(), font.GetStyle(), font.GetWeight());
res += font.GetFaceName();
QString res = QString::sprintf("%d;%d;%d;%d;", font.pointSize(), 0, 0, font.weight());
res += font.family();
return res;
return res.toStdString();
}
void KissCount::UnRegisterImportEngine(ImportEngine* engine)
@@ -580,7 +586,7 @@ wxString KissCount::GetImportEngineExtensions()
return res;
}
ImportEngine* KissCount::GetImportEngine(wxString path)
ImportEngine* KissCount::GetImportEngine(std::string path)
{
std::vector<ImportEngine*>::iterator it;
std::vector<ImportEngine*>* importEngines = KissCount::GetImportEngines();
@@ -615,13 +621,13 @@ void KissCount::RegisterExportEngine(ExportEngine* engine)
wxString KissCount::GetExportEngineExtensions()
{
wxString res;
std::string res;
std::vector<ExportEngine*>::iterator it;
int i;
std::vector<ExportEngine*>* exportEngines = KissCount::GetExportEngines();
for(i=0; i<(int)exportEngines->size()-1; i++)
res = res + (*exportEngines)[i]->GetFileExt() + wxT("|") ;
res = res + (*exportEngines)[i]->GetFileExt() + "|" ;
if (exportEngines->size())
res = res + (*exportEngines)[i]->GetFileExt();
@@ -629,7 +635,7 @@ wxString KissCount::GetExportEngineExtensions()
return res;
}
ExportEngine* KissCount::GetExportEngine(wxString path)
ExportEngine* KissCount::GetExportEngine(std::string path)
{
std::vector<ExportEngine*>::iterator it;
std::vector<ExportEngine*>* exportEngines = KissCount::GetExportEngines();

View File

@@ -22,112 +22,115 @@
#include <list>
#include <QApplication>
#include <model/import/ImportEngine.hpp>
#include <model/export/ExportEngine.hpp>
#include <model/model.hpp>
#include <wx/display.h>
#include <view/wxUI.hpp>
#define APP_VERSION "0.3"
#define ESCAPE_CHARS(s) { \
#define ESCAPE_CHARS(s) s
/*{ \
if (s.Find(wxT("\\\"")) == wxNOT_FOUND) \
s.Replace(wxT("\""), wxT("\\\""), true); \
if (s.Find(wxT("\\\'")) == wxNOT_FOUND) \
s.Replace(wxT("\'"), wxT("\\\'"), true); \
}
#define UNESCAPE_CHARS(s) { \
*/
#define UNESCAPE_CHARS(s) s
/*{ \
s.Replace(wxT("\\\""), wxT("\""), true); \
s.Replace(wxT("\\\'"), wxT("\'"), true); \
}
*/
class wxUI;
class Database;
class ImportEngine;
class ExportEngine;
class KissCount
class KissCount : public QApplication
{
public:
KissCount(const char* bdd_filename);
~KissCount();
std::list<wxString> GetUsers();
bool IsValidUser(const wxString& user, const wxString& password);
void LoadUser(const wxString& user);
std::list<std::string> GetUsers();
bool IsValidUser(const std::string& user, const std::string& password);
void LoadUser(const std::string& user);
User* GetUser();
void ChangePassword(const wxString& password);
bool UserExists(const wxString& name);
void ChangeName(const wxString& name);
void NewUser(const wxString& name);
void ChangePassword(const std::string& password);
bool UserExists(const std::string& name);
void ChangeName(const std::string& name);
void NewUser(const std::string& name);
void LoadYear(int year, bool force=false);
wxString AddOperation(Operation& op, bool checkTransfert=true);
int AddOperation(Operation& op, bool checkTransfert=true);
void UpdateOperation(Operation& op, bool checkTransfert=true);
void DeleteOperation(Operation& op);
void DeleteOperations(int month, int year);
double MetaAmount(const wxString& id);
double MetaPositiveAmount(const wxString& id);
double MetaAmount(int id);
double MetaPositiveAmount(int id);
double GetAccountAmount(const wxString& id, int month, int year);
void SetAccountAmount(const wxString& accountId, int month, int year, double value);
double CalcAccountAmount(const wxString& id, int month, int year, bool* had_values);
double GetAccountAmount(int id, int month, int year);
void SetAccountAmount(int accountId, int month, int year, double value);
double CalcAccountAmount(int id, int month, int year, bool* had_values);
wxString AddAccount(Account& ac);
int AddAccount(Account& ac);
void UpdateAccount(Account& ac);
void DeleteAccount(Account& ac, const wxString& replacement);
void AddSharedAccount(Account& ac, const wxString& granted);
void RemoveSharedAccount(Account& ac, const wxString& granted);
std::map<wxString, wxString> getSharedAccountOwners(const wxString& account);
wxString getSharedAccountOwner(const wxString& account);
void DeleteAccount(Account& ac, int replacement);
void AddSharedAccount(Account& ac, const std::string& granted);
void RemoveSharedAccount(Account& ac, const std::string& granted);
std::map<int, int> getSharedAccountOwners(int account);
int getSharedAccountOwner(int account);
wxString AddCategory(Category& category);
int AddCategory(Category& category);
void UpdateCategory(Category& category);
void DeleteCategory(Category& category, const wxString& replacement);
void DeleteCategory(Category& category, int replacement);
std::map<int, std::vector<int> > GetAllOperations();
void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
void KillMe();
void SetLanguage(wxLanguage language);
void SetOperationOrder(const wxString& order);
const wxString& GetOperationOrder();
std::vector<Operation>* Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
wxString* amountFrom, wxString* amountTo,
std::vector<wxString> categories, int types, std::vector<wxString> accounts);
void SetLanguage(std::string language);
void SetOperationOrder(const std::string& order);
const std::string& GetOperationOrder();
std::vector<Operation>* Search(std::string* description, QDate* dateFrom, QDate* dateTo,
int* amountFrom, int* amountTo,
std::vector<int> categories, int types, std::vector<int> accounts);
bool SearchPreviousOperation(Operation* res, Operation& op, int month, int year, bool limitToType);
void GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo,
std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
std::map<wxString, double>* categories);
std::map<int, std::map<int, std::map<int, double> > >* accountAmounts,
std::map<int, double>* categories);
void GetMonthStats(int month, int year, int nbDays,
std::map<wxString, std::vector<double> >* operations,
std::map<wxString, double>* categories);
std::map<int, std::vector<double> >* operations,
std::map<int, double>* categories);
std::map<wxString, double>* GetNotChecked(int month, int year);
std::map<wxString, double>* GetVirtualAmount(int month, int year);
std::map<int, double>* GetNotChecked(int month, int year);
std::map<int, double>* GetVirtualAmount(int month, int year);
static wxFont ExtractFont(wxString strFont);
static wxString CompactFont(const wxFont& font);
static QFont ExtractFont(std::string);
static std::string CompactFont(const QFont& font);
static void RegisterImportEngine(ImportEngine* engine);
static void UnRegisterImportEngine(ImportEngine* engine);
wxString GetImportEngineExtensions();
ImportEngine* GetImportEngine(wxString path);
std::string GetImportEngineExtensions();
ImportEngine* GetImportEngine(std::string path);
static void RegisterExportEngine(ExportEngine* engine);
static void UnRegisterExportEngine(ExportEngine* engine);
wxString GetExportEngineExtensions();
ExportEngine* GetExportEngine(wxString path);
std::string GetExportEngineExtensions();
ExportEngine* GetExportEngine(std::string path);
void UpdateImportPattern();

View File

@@ -17,28 +17,22 @@
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/wx.h>
#include <controller/KissCount.hpp>
class MyApp: public wxApp
int main(int argc, char *argv[])
{
virtual bool OnInit()
try
{
try
{
if (argc == 2)
new KissCount(wxString(argv[1]).mb_str());
else
new KissCount(0);
}
catch (std::string s)
{
std::cerr << "Error " << s << "\n";
return false;
}
return true;
}
};
if (argc == 2)
KissCount(wxString(argv[1]).mb_str());
else
KissCount(0);
IMPLEMENT_APP(MyApp);
return KissCount.exec();
}
catch (std::string s)
{
std::cerr << "Error " << s << "\n";
throw;
}
}

View File

@@ -20,12 +20,10 @@
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <wx/wx.h>
struct Account {
wxString id;
wxString name;
wxString number;
int id;
std::string name;
std::string number;
bool shared;
bool blocked;
bool _default;
@@ -43,10 +41,10 @@ struct Account {
if (!ac1._virtual && ac2._virtual) return true;
if (ac1._virtual && !ac2._virtual) return false;
return (ac1.name.Cmp(ac2.name) < 0);
return ac1.name < ac2.name;
}
bool operator == (const wxString& accountId)
bool operator == (int accountId)
{
return id == accountId;
}

View File

@@ -21,21 +21,14 @@
#define ACCOUNTAMOUNT_H
struct AccountAmount {
wxString account;
int account;
int month;
int year;
bool operator()(const AccountAmount& x, const AccountAmount& y) const
{
long x1, y1;
if (x.account != y.account)
{
x.account.ToLong(&x1);
y.account.ToLong(&y1);
return x1 < y1;
}
return x.account < y.account;
return (x.year < y.year || ((x.year == y.year) && x.month < y.month));
}

View File

@@ -20,19 +20,20 @@
#ifndef CATEGORY_H
#define CATEGORY_H
#include <wx/wx.h>
#include <string>
#include <QColor>
struct Category
{
wxString id;
wxString parent;
wxString name;
wxColour backcolor;
wxColour forecolor;
wxString font;
int id;
int parent;
std::string name;
QColor backcolor;
QColor forecolor;
std::string font;
bool fix_cost;
bool operator == (const wxString& catId)
bool operator == (int catId)
{
return id == catId;
}

File diff suppressed because it is too large Load Diff

View File

@@ -21,8 +21,9 @@
#define DATABASE_H
#include <list>
#include <wx/wxsqlite3.h>
#include <wx/wx.h>
#include <QSqlDatabase>
#include <QDate>
#include <controller/KissCount.hpp>
#include "model.hpp"
@@ -40,40 +41,31 @@
// }
#define EXECUTE_SQL_UPDATE_WITH_CODE(req, return_value, code_if_fail, code_if_syntax_fail) \
do{ \
try \
{ \
_db.ExecuteUpdate(req); \
} \
catch (wxSQLite3Exception e) \
{ \
wxMessageBox(_("Update failed !\n") + req, _("Error"), wxICON_ERROR | wxOK); \
std::cerr << __FUNCTION__ << "\n" ; \
std::cerr << req.mb_str() << "\n" ; \
std::cerr << e.GetMessage().mb_str() << "\n" ; \
code_if_fail; \
return return_value; \
} \
do { \
QSqlQuery query; \
if (!query.exec(req)) \
{ \
QMessageBox::critical(0, _("Error"), _("Update failed !\n") + req); \
std::cerr << __FUNCTION__ << "\n" ; \
std::cerr << req.toStdString() << "\n" ; \
std::cerr << query.lastError().text().toStdString() << "\n" ; \
code_if_fail; \
return return_value; \
} \
} while(0);
#define EXECUTE_SQL_QUERY_WITH_CODE(req, res, return_value, code_if_fail, code_if_syntax_fail) \
do{ \
try \
{ \
res = _db.ExecuteQuery(req); \
} \
catch (wxSQLite3Exception e) \
{ \
wxMessageBox(_("Query failed !\n") + req, _("Error"), wxICON_ERROR | wxOK); \
std::cerr << __FUNCTION__ << "\n" ; \
std::cerr << req.mb_str() << "\n" ; \
std::cerr << e.GetMessage().mb_str() << "\n" ; \
code_if_fail; \
return return_value; \
} \
} while(0);
#define EXECUTE_SQL_QUERY_WITH_CODE(req, return_value, code_if_fail, code_if_syntax_fail) \
if (!query.exec(req)) \
{ \
QMessageBox::critical(0, _("Error"), _("Query failed !\n") + req); \
std::cerr << __FUNCTION__ << "\n" ; \
std::cerr << req.toStdString() << "\n" ; \
std::cerr << query.lastError().text().toStdString() << "\n" ; \
code_if_fail; \
return return_value; \
} \
#define EXECUTE_SQL_QUERY(req, res, return_value) EXECUTE_SQL_QUERY_WITH_CODE(req, res, return_value, {}, {})
#define EXECUTE_SQL_QUERY(req, return_value) EXECUTE_SQL_QUERY_WITH_CODE(req, return_value, {}, {})
#define EXECUTE_SQL_UPDATE(req, return_value) EXECUTE_SQL_UPDATE_WITH_CODE(req, return_value, {}, {})
@@ -83,8 +75,8 @@ class User;
class Database
{
public:
static const int FIX_OP = 1;//(1 << 0);
static const int NON_FIX_OP = 2;//(1 << 1);
static const int FIX_OP = (1 << 0);
static const int NON_FIX_OP = (1 << 1);
static const int CHECKED_OP = (1 << 2);
static const int NOT_CHECKED_OP = (1 << 3);
static const int ALL_OP = (~0);
@@ -93,64 +85,64 @@ public:
Database(const char* filename, KissCount* kiss);
std::list<wxString> GetUsers();
bool IsValidUser(const wxString& user, const wxString& password);
std::list<std::string> GetUsers();
bool IsValidUser(const QString& user, const QString& password);
User* LoadUser(const wxString& name);
User* LoadUser(const std::string& name);
void LoadYear(User* user, int year);
void UpdateOperation(User* user, Operation& op, bool checkTransfert=true);
wxString AddOperation(User* user, Operation& op, bool checkTransfert=true);
int AddOperation(User* user, Operation& op, bool checkTransfert=true);
void DeleteOperation(User* user, Operation& op);
void DeleteOperations(User* user, int month, int year);
bool LoadOperation(User* user, const wxString& id);
double MetaAmount(const wxString& id);
double MetaPositiveAmount(const wxString& id);
bool LoadOperation(User* user, int id);
double MetaAmount(int id);
double MetaPositiveAmount(int id);
double GetAccountAmount(const wxString& id, int month, int year);
void SetAccountAmount(const wxString& accountId, int month, int year, double amount);
double CalcAccountAmount(const wxString& id, int month, int year, bool* had_values);
double GetAccountAmount(int id, int month, int year);
void SetAccountAmount(int accountId, int month, int year, double amount);
double CalcAccountAmount(int id, int month, int year, bool* had_values);
wxString AddAccount(User* user, Account& ac);
int AddAccount(User* user, Account& ac);
void UpdateAccount(Account& ac);
void DeleteAccount(User* user, Account& ac, const wxString& replacement);
void AddSharedAccount(Account& ac, const wxString& granted);
void RemoveSharedAccount(Account& ac, const wxString& granted);
void DeleteAccount(User* user, Account& ac, int replacement);
void AddSharedAccount(Account& ac, const std::string& granted);
void RemoveSharedAccount(Account& ac, const std::string& granted);
wxString AddCategory(User* user, Category& category);
int AddCategory(User* user, Category& category);
void UpdateCategory(Category& category);
void DeleteCategory(User* user, Category& category, const wxString& replacement);
bool LoadCategory(const wxString& id, const wxString& name, Category& category);
void DeleteCategory(User* user, Category& category, int replacement);
bool LoadCategory(int id, const std::string& name, Category& category);
std::map<int, std::vector<int> > GetAllOperations(User* user);
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
void ChangePassword(User* user, const wxString& password);
bool UserExists(const wxString& name);
void ChangeName(User* user, const wxString& name);
void NewUser(const wxString& name);
void ChangePassword(User* user, const std::string& password);
bool UserExists(const std::string& name);
void ChangeName(User* user, const std::string& name);
void NewUser(const std::string& name);
void UpdatePreference(User* user, const wxString& preference);
void UpdatePreference(User* user, const std::string& preference);
std::vector<Operation>* Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
wxString* amountFrom, wxString* amountTo,
std::vector<wxString> categories, int types, std::vector<wxString> accounts, bool wildcards);
std::vector<Operation>* Search(User* user, std::string* description, QDate* dateFrom, QDate* dateTo,
int* amountFrom, int* amountTo,
std::vector<int> categories, int types, std::vector<int> accounts, bool wildcards);
void GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo,
const wxString& yearTo, std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
std::map<wxString, double>* categories);
void GetStats(User* user, int monthFrom, int yearFrom, int monthTo,
int yearTo, std::map<int, std::map<int, std::map<int, double> > >* accountAmounts,
std::map<int, double>* categories);
void GetMonthStats(User* user, const wxString& month, const wxString& year, int nbDays,
std::map<wxString, std::vector<double> >* operations,
std::map<wxString, double>* categories);
void GetMonthStats(User* user, int month, int year, int nbDays,
std::map<int, std::vector<double> >* operations,
std::map<int, double>* categories);
void KillMe(User* user);
bool GetOperation(const wxString& id, Operation* op);
std::map<wxString, wxString> getSharedAccountOwners(const wxString& account);
wxString getSharedAccountOwner(const wxString& account);
bool GetOperation(int id, Operation* op);
std::map<std::string, std::string> getSharedAccountOwners(int account);
int getSharedAccountOwner(int account);
std::map<wxString, double>* GetNotChecked(User* user, int month, int year);
std::map<wxString, double>* GetVirtualAmount(User* user, int month, int year);
std::map<int, int>* GetNotChecked(User* user, int month, int year);
std::map<int, int>* GetVirtualAmount(User* user, int month, int year);
void UpdateImportPattern(User* user);
@@ -160,10 +152,10 @@ public:
private:
KissCount* _kiss;
wxSQLite3Database _db;
QSqlDatabase _db;
void CreateDatabase();
wxString HashPassword(const wxString& password);
QString HashPassword(const QString& password);
void LinkOrUnlinkOperation(User* user, Operation& op);
};

View File

@@ -35,7 +35,7 @@ bool sortOperations(const Operation& op1, const Operation& op2)
if (op1.day < op2.day)
return true;
else if (op1.day == op2.day)
return (op1.description.Cmp(op2.description) < 0);
return (op1.description < op2.description);
}
}

View File

@@ -20,28 +20,27 @@
#ifndef OPERATION_H
#define OPERATION_H
#include <wx/wx.h>
#include <vector>
struct Operation {
wxString id;
wxString parent;
int id;
int parent;
unsigned int day;
unsigned int month;
unsigned int year;
double amount;
wxString description;
wxString category;
std::string description;
int category;
bool fix_cost;
wxString account;
int account;
bool checked;
wxString transfert;
wxString formula;
int transfert;
std::string formula;
bool meta;
bool _virtual;
std::vector<wxString> childs;
std::vector<int> childs;
bool operator == (const wxString& opId)
bool operator == (int opId)
{
return id == opId;
}

View File

@@ -44,64 +44,64 @@ void User::InvalidateOperations()
_operations.clear();
}
Category User::GetCategory(const wxString& catId)
Category User::GetCategory(int catId)
{
Category cat;
std::vector<Category>::iterator it = std::find(_categories.begin(), _categories.end(), catId);
if (it !=_categories.end()) return *it;
if (_db->LoadCategory(catId, wxT(""), cat))
if (_db->LoadCategory(catId, "", cat))
return cat;
cat.id = wxT("0");
cat.parent = wxT("0");
cat.id = 0;
cat.parent = 0;
cat.name = _("Unknown");
cat.font = wxT("");
cat.font = "";
cat.backcolor = view::OWN_GREEN;
cat.forecolor = wxColour(0x00, 0x00, 0x00);
return cat;
}
wxString User::GetCategoryName(const wxString& catId)
std::string User::GetCategoryName(int catId)
{
Category cat;
std::vector<Category>::iterator it = std::find(_categories.begin(), _categories.end(), catId);
if (it !=_categories.end()) return it->name;
if (_db->LoadCategory(catId, wxT(""), cat))
if (_db->LoadCategory(catId, "", cat))
return cat.name;
return _("Unknown") ;
}
wxString User::GetCategoryId(const wxString& catName)
int User::GetCategoryId(const std::string& catName)
{
std::vector<Category>::iterator it;
Category cat;
for (it=_categories.begin(); it !=_categories.end(); it++)
if (wxGetTranslation(it->name) == catName)
if (_(it->name) == catName)
return it->id;
if ( _db->LoadCategory(wxT(""), catName, cat))
if ( _db->LoadCategory("", catName, cat))
return cat.id;
return wxT("0") ;
return 0 ;
}
const wxFont User::GetCategoryFont(const wxString& catId)
const QFont User::GetCategoryFont(int catId)
{
wxFont f;
QFont f;
Category cat;
for (unsigned int i=0; i<_categories.size(); i++)
if (_categories[i].id == catId)
return _categoriesFonts[i];
if (_db->LoadCategory(catId, wxT(""), cat))
if (_db->LoadCategory(catId, "", cat))
return KissCount::ExtractFont(cat.font);
return f;
@@ -110,7 +110,7 @@ const wxFont User::GetCategoryFont(const wxString& catId)
void User::AddCategory(const Category& cat)
{
_categories.push_back(cat);
_categoriesFonts.push_back(KissCount::ExtractFont(wxT("")));
_categoriesFonts.push_back(KissCount::ExtractFont(""));
}
void User::UpdateCategory(const Category& cat)
@@ -136,7 +136,7 @@ void User::DeleteCategory(const Category& cat)
}
}
Account User::GetAccount(const wxString& accountId) throw (AccountNotFound)
Account User::GetAccount(int accountId) throw (AccountNotFound)
{
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), accountId);
@@ -146,7 +146,7 @@ Account User::GetAccount(const wxString& accountId) throw (AccountNotFound)
throw AccountNotFound();
}
wxString User::GetAccountName(const wxString& accountId)
std::string User::GetAccountName(int accountId)
{
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), accountId);
@@ -155,14 +155,14 @@ wxString User::GetAccountName(const wxString& accountId)
return _("Unknown") ;
}
wxString User::GetAccountId(const wxString& accountName)
int User::GetAccountId(const std::string& accountName)
{
std::vector<Account>::iterator it;
for (it=_accounts.begin(); it !=_accounts.end(); it++)
if (it->name == accountName)
return it->id;
return wxT("0") ;
return 0 ;
}
void User::AddAccount(Account& ac)
@@ -201,17 +201,17 @@ int User::GetOperationsNumber(int month, int year)
return (*_operations[year])[month].size();
}
wxLanguage User::GetLanguage()
std::string User::GetLanguage()
{
wxString res = _preferences[wxT("language")];
long val;
return _preferences["language"];
// long val;
if (!res.Length())
return wxLANGUAGE_ENGLISH ;
// if (!res.Length())
// return wxLANGUAGE_ENGLISH ;
res.ToLong(&val);
// res.ToLong(&val);
return (wxLanguage)val;
// return (wxLanguage)val;
}
void User::LinkOrUnlinkOperation(Operation& op)
@@ -226,13 +226,13 @@ void User::LinkOrUnlinkOperation(Operation& op)
return;
// Not Linked
if (!op.transfert.Length())
if (!op.transfert)
{
for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++)
{
if (it->id != op.id && it->transfert == op.id)
{
it->transfert = wxT("");
it->transfert = 0;
it->_virtual = false;
return;
}
@@ -253,7 +253,7 @@ void User::LinkOrUnlinkOperation(Operation& op)
return;
}
}
op.transfert = wxT("");
op.transfert = 0;
op._virtual = false;
}
}
@@ -261,7 +261,7 @@ void User::LinkOrUnlinkOperation(Operation& op)
bool User::Group(std::vector<Operation>* ops, const Operation& op)
{
std::vector<Operation>::iterator it;
std::vector<wxString>::iterator it2;
std::vector<int>::iterator it2;
for (it = ops->begin(); it != ops->end(); it++)
{
@@ -280,9 +280,6 @@ bool User::Group(std::vector<Operation>* ops, const Operation& op)
void User::Group(const Operation& op)
{
std::vector<Operation>::iterator it;
std::vector<wxString>::iterator it2;
if (!Group(&(*_operations[op.year])[op.month], op)
&& _db->LoadOperation(this, op.parent))
{
@@ -293,7 +290,7 @@ void User::Group(const Operation& op)
void User::UnGroup(const Operation& op)
{
std::vector<Operation>::iterator it;
std::vector<wxString>::iterator it2;
std::vector<int>::iterator it2;
for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++)
{

View File

@@ -22,7 +22,8 @@
#include <map>
#include <vector>
#include <wx/wx.h>
#include <QFont>
#include "Category.hpp"
#include "Account.hpp"
@@ -40,30 +41,30 @@ public:
~User();
void InvalidateOperations();
wxString _id;
wxString _name;
wxString _password;
int _id;
std::string _name;
std::string _password;
std::vector<Account> _accounts;
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* > _operations;
std::vector<Category> _categories;
std::vector<wxFont> _categoriesFonts;
std::map<wxString, wxString> _preferences;
std::map<wxString, ImportPattern> _importPatterns;
std::vector<QFont> _categoriesFonts;
std::map<std::string, std::string> _preferences;
std::map<std::string, ImportPattern> _importPatterns;
class AccountNotFound {};
Category GetCategory(const wxString& catId);
wxString GetCategoryName(const wxString& catId);
wxString GetCategoryId(const wxString& catName);
const wxFont GetCategoryFont(const wxString& catId);
Category GetCategory(int catId);
std::string GetCategoryName(int catId);
int GetCategoryId(const std::string& catName);
const QFont GetCategoryFont(int catId);
void AddCategory(const Category& cat);
void UpdateCategory(const Category& cat);
void DeleteCategory(const Category& cat);
Account GetAccount(const wxString& accountId) throw (AccountNotFound);
wxString GetAccountName(const wxString& accountId);
wxString GetAccountId(const wxString& accountName);
Account GetAccount(int accountId) throw (AccountNotFound);
std::string GetAccountName(int accountId);
int GetAccountId(const std::string& accountName);
void AddAccount(Account& ac);
void UpdateAccount(Account& ac);
void DeleteAccount(Account& ac);
@@ -73,7 +74,7 @@ public:
int GetAccountsNumber();
int GetOperationsNumber(int month, int year);
wxLanguage GetLanguage();
std::string GetLanguage();
void LinkOrUnlinkOperation(Operation& op);

View File

@@ -33,25 +33,25 @@ public:
// Get supported file extension. Example :
// "OFX files (*.ofx)|*.ofx"
virtual wxString GetFileExt();
virtual std::string GetFileExt();
// Handle the file
virtual bool HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)=0;
virtual bool HandleFile(const std::string& path, User* user, Database* db, KissCount* kiss)=0;
// Save operations (ExportEngin pre fill _accounts, _categories and _accountAmounts)
virtual bool SaveFile(std::vector<Operation>* operations)=0;
protected:
wxString _path;
std::string _path;
Database* _db;
User* _user;
KissCount* _kiss;
wxString _shortExt;
wxString _longExt;
std::string _shortExt;
std::string _longExt;
std::map<wxString, int> _accounts;
std::map<wxString, int> _categories;
std::map<int, int> _accounts;
std::map<int, int> _categories;
std::map<AccountAmount, double, AccountAmount> _accountAmounts;
};

View File

@@ -76,7 +76,7 @@ bool XMLExportEngine::SaveAccountAmounts()
{
xmlTextWriterStartElement(_writer, (const xmlChar*) "account_amount");
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "account", (const xmlChar*) it->first.account.utf8_str().data());
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "monthpp", "%d", it->first.month);
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "month", "%d", it->first.month);
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "year", "%d", it->first.year);
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "amount", "%.2lf", it->second);
xmlTextWriterEndElement(_writer);
@@ -128,7 +128,7 @@ bool XMLExportEngine::SaveOperations(std::vector<Operation>* operations)
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "id", (const xmlChar*) it->id.utf8_str().data());
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "parent", (const xmlChar*) it->parent.utf8_str().data());
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "day", "%d", it->day);
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "monthpp", "%d", it->month);
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "month", "%d", it->month);
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "year", "%d", it->year);
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "amount", "%.2lf", it->amount);
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "description", (const xmlChar*) it->description.utf8_str().data());

View File

@@ -28,57 +28,57 @@ class KissCount;
class ImportPattern {
public:
wxString pattern;
wxString account;
wxString category;
std::string pattern;
int account;
int category;
} ;
class ImportEngine {
public:
static wxString NULL_IMPORT_PATTERN;
static std::string NULL_IMPORT_PATTERN;
ImportEngine();
~ImportEngine();
// Get supported file extension. Example :
// "OFX files (*.ofx)|*.ofx"
virtual wxString GetFileExt();
virtual std::string GetFileExt();
// Handle the file
virtual bool HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)=0;
virtual bool HandleFile(const std::string& 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);
// Final Step
virtual std::vector<Operation>* GetOperations(std::map<wxString, wxString>& accounts, std::map<wxString, wxString>& categories);
virtual std::vector<Operation>* GetOperations(std::map<int, int>& accounts, std::map<int, int>& categories);
const std::map<AccountAmount, double, AccountAmount>& GetAccountAmounts();
void MatchPattern(wxString& key, Operation& op);
void MatchPattern(std::string& key, Operation& op);
int UpdatePattern(int pos);
static wxString RemoveUnused(const wxString& s);
static std::string RemoveUnused(const std::string& s);
protected:
Database* _db;
User* _user;
wxString _path;
std::string _path;
KissCount* _kiss;
wxString _shortExt;
wxString _longExt;
std::string _shortExt;
std::string _longExt;
std::map<wxString, wxString> _accounts;
std::map<wxString, wxString> _categories;
std::map<int, int> _accounts;
std::map<int, int> _categories;
std::vector<Account> _unresolvedAccounts;
std::vector<Category> _unresolvedCategories;
std::vector<Operation> _operations;
std::map<wxString, wxString> _descriptions;
std::map<std::string, std::string> _descriptions;
std::map<AccountAmount, double, AccountAmount> _accountAmounts;
void ApplyPattern(ImportPattern& pattern, Operation& op);
wxString FindPattern(wxString& s1, wxString& s2);
std::string FindPattern(std::string& s1, std::string& s2);
};
#endif

View File

@@ -80,7 +80,7 @@ void XMLImportEngine::LoadAccountAmount(XMLImportEngine* _this, const char** att
if (!strcmp(attrs[i], "account"))
accountAmount.account = wxString(attrs[i+1], wxConvUTF8);
else if (!strcmp(attrs[i], "monthpp"))
else if (!strcmp(attrs[i], "month"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&v);
accountAmount.month = v;
@@ -169,7 +169,7 @@ void XMLImportEngine::LoadOperation(XMLImportEngine* _this, const char** attrs)
op.day = v;
}
else if (!strcmp(attrs[i], "monthpp"))
else if (!strcmp(attrs[i], "month"))
{
wxString(attrs[i+1], wxConvUTF8).ToLong(&v);
op.month = v;

File diff suppressed because it is too large Load Diff

View File

@@ -1,93 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ACCOUNTPANEL_H
#define ACCOUNTPANEL_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/treectrl.h>
#include <wx/pie/pieplot.h>
#include <wx/chartpanel.h>
#include <wx/radiobox.h>
#include "view.hpp"
#include <model/model.hpp>
#include "grid/GridAccount.hpp"
#include "grid/CalendarEditor.hpp"
#include <wx/category/categorysimpledataset.h>
class GridAccount;
class AccountPanel: public KissPanel
{
public:
AccountPanel(KissCount* kiss, wxUI *parent);
~AccountPanel();
KissPanel* CreatePanel();
wxBitmapButton* GetButton(int id);
wxString GetToolTip();
void OnShow(wxShowEvent& event);
void ChangeUser();
void LoadYear(int year, bool showMonth=true);
void ShowMonth(int month, int year);
void GenerateMonth(int month, int year);
void OnOperationModified(wxGridEvent& event);
void OnAccountModified(wxGridEvent& event);
void OnTreeRightClick(wxTreeEvent& event);
void OnTreeChange(wxTreeEvent& event);
void OnMenuGenerate(wxCommandEvent& event);
void OnMenuDelete(wxCommandEvent& event);
void OnCalendarChange(wxCalendarEvent& event);
void OnModeChange(wxCommandEvent& event);
void OnGroup(wxCommandEvent& event);
void OnUnGroup(wxCommandEvent& event);
void OnUpdateNextMonths(wxCommandEvent& event);
int _curMonth, _curYear;
private:
wxTreeCtrl _tree;
wxCalendarCtrl* _calendar;
GridAccount* _grid;
wxGrid *_statsGrid, *_accountsGrid;
PiePlot* _pie;
double *_categoriesValues;
wxRadioBox *_radioMode;
std::map<wxString, int> _categoriesIndexes;
std::vector<Operation>* _curOperations;
wxString* _categories, *_accounts;
std::map<wxString, double> _accountsInitValues;
CategorySimpleDataset* _dataset;
int _fixCosts;
void InitStatsGrid(User* user);
void InitAccountsGrid(User* user, int month, int year);
void UpdateStats();
void InsertOperation(User* user, Operation* op, int line, bool fix);
void GetTreeSelection(int* month, int* year);
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,155 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "grid/CalendarEditor.hpp"
#include "grid/wxGridCellBitmapRenderer.hpp"
#include "ExportPanel.hpp"
enum {EXPORT_ID=1, SEARCH_ID, GRID_ID};
BEGIN_EVENT_TABLE(ExportPanel, wxPanel)
EVT_BUTTON(EXPORT_ID, ExportPanel::OnButtonExport)
EVT_BUTTON(SEARCH_ID, ExportPanel::OnButtonSearch)
EVT_SHOW(ExportPanel::OnShow)
END_EVENT_TABLE()
ExportPanel::ExportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _operations(0)
{
DEFAULT_FONT(font);
std::vector<Account>::iterator accountIt;
std::vector<Category>::iterator categoryIt;
wxDateTime firstOfMonth;
wxRect rect = wxDisplay().GetGeometry();
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
SetSizer(vbox);
_searchButton = new wxButton(this, SEARCH_ID, _("Searchpp"));
_banner = new SearchBanner(kiss, this, this, OnEnter);
vbox->Add(_banner, 0, wxGROW|wxALL, 5);
vbox->Add(_searchButton, 0, wxALL, 5);
_grid = new GridAccount(_kiss, this, GRID_ID, false, false, false);
hbox->Add(_grid, 0, wxGROW|wxALL, 5);
_exportButton = new wxButton(this, EXPORT_ID, _("Export"));
vbox2->Add(_exportButton, wxALL, 15);
hbox->Add(vbox2, 0, wxALL, 15);
vbox->Add(hbox, 0, wxGROW|wxALL, 5);
Fit();
SetMinSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
SetMaxSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
SetScrollbars(10, 10, 100/10, 100/10);
}
ExportPanel::~ExportPanel()
{
}
KissPanel* ExportPanel::CreatePanel()
{
return new ExportPanel(_kiss, _wxUI);
}
wxBitmapButton* ExportPanel::GetButton(int id)
{
if (!_KissButton)
_KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(EXPORT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128));
return _KissButton;
}
wxString ExportPanel::GetToolTip()
{
return _("Export");
}
void ExportPanel::OnEnter(void* caller, wxCommandEvent& event)
{
ExportPanel* _this = (ExportPanel*) caller;
_this->OnButtonExport(event);
}
void ExportPanel::OnButtonSearch(wxCommandEvent& event)
{
_operations = _banner->Search();
if (!_operations) return;
if (_operations->size() > 1)
wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
else if (_operations->size() == 1)
wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
else
{
wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
return;
}
_grid->LoadOperations(_operations, 0, 0);
_wxUI->Layout();
}
void ExportPanel::OnButtonExport(wxCommandEvent& event)
{
if (!_operations || !_operations->size())
{
wxMessageBox(_("No operation to save"), wxT("Error"), wxICON_ERROR | wxOK);
return;
}
wxFileDialog saveFileDialog(this, _("Save as"), wxT(""), wxT(""),
_kiss->GetExportEngineExtensions(), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (saveFileDialog.ShowModal() == wxID_CANCEL)
return;
_exportEngine = _kiss->GetExportEngine(saveFileDialog.GetPath());
if (!_exportEngine)
{
wxMessageBox(_("Any engine can process this file !"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
return ;
}
if (_exportEngine->SaveFile(_operations))
wxMessageBox(_("Operations successfuly saved"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
else
wxMessageBox(_("Failed to save operations"), wxT("Error"), wxICON_ERROR | wxOK);
}
void ExportPanel::OnShow(wxShowEvent& event)
{
_wxUI->SetTitle(_("KissCount - Export"));
}

View File

@@ -1,63 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EXPORTPANEL_H
#define EXPORTPANEL_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/treectrl.h>
#include <wx/scrolwin.h>
#include "view.hpp"
#include "grid/GridAccount.hpp"
#include "SearchBanner.hpp"
#include <model/model.hpp>
#include <model/export/ExportEngine.hpp>
class GridAccount;
class SearchBanner;
class ExportEngine;
class ExportPanel: public KissPanel
{
public:
ExportPanel(KissCount* kiss, wxUI *parent);
~ExportPanel();
KissPanel* CreatePanel();
wxBitmapButton* GetButton(int id);
wxString GetToolTip();
void OnShow(wxShowEvent& event);
void OnButtonSearch(wxCommandEvent& event);
void OnButtonExport(wxCommandEvent& event);
private:
std::vector<Operation> *_operations;
SearchBanner* _banner;
GridAccount *_grid;
wxButton* _searchButton, *_exportButton;
ExportEngine* _exportEngine;
static void OnEnter(void* caller, wxCommandEvent& event);
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,238 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/choice.h>
#include <wx/textctrl.h>
#include <wx/gbsizer.h>
#include "GenerateDialog.hpp"
enum {BUTTON_OK_ID=1, BUTTON_CANCEL_ID, YEAR_FROM_ID, MONTH_FROM_ID, YEAR_TO_ID, MONTH_TO_ID};
BEGIN_EVENT_TABLE(GenerateDialog, wxDialog)
EVT_BUTTON(BUTTON_OK_ID, GenerateDialog::OnOK)
EVT_BUTTON(BUTTON_CANCEL_ID, GenerateDialog::OnCancel)
EVT_CHOICE(YEAR_FROM_ID, GenerateDialog::OnYearFromChange)
EVT_CHOICE(YEAR_TO_ID, GenerateDialog::OnYearToChange)
END_EVENT_TABLE()
GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year) : wxDialog(&(*parent), wxID_ANY, _("Generate monthpp")), _kiss(kiss), _wxUI(parent)
{
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
std::map<int, std::vector<int> >::iterator it;
int i, a, toSelect=-1;
wxDateTime curDate;
wxCommandEvent event;
std::vector<int>::iterator monthIt;
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
gridBagSizer = new wxGridBagSizer(4, 5);
curDate.SetToCurrent();
label = new wxStaticText(this, wxID_ANY, _("From "));
gridBagSizer->Add(label, wxGBPosition(0, 0));
_yearFrom = new wxChoice(this, YEAR_FROM_ID);
gridBagSizer->Add(_yearFrom, wxGBPosition(0, 1));
_monthFrom = new wxChoice(this, MONTH_FROM_ID);
gridBagSizer->Add(_monthFrom, wxGBPosition(0, 2));
label = new wxStaticText(this, wxID_ANY, _("To "));
gridBagSizer->Add(label, wxGBPosition(1, 0));
_yearTo = new wxChoice(this, YEAR_TO_ID);
gridBagSizer->Add(_yearTo, wxGBPosition(1, 1));
_monthTo = new wxChoice(this, MONTH_TO_ID);
gridBagSizer->Add(_monthTo, wxGBPosition(1, 2));
wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK"));
wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel"));
gridBagSizer->Add(ok, wxGBPosition(3, 3));
gridBagSizer->Add(cancel, wxGBPosition(3, 4));
_ops = _kiss->GetAllOperations();
_yearFrom->Append(wxT(""));
_monthFrom->Append(wxT(""));
for(i=1, it = _ops.begin(); it != _ops.end(); it++, i++)
{
_yearFrom->Append(wxString::Format(wxT("%d"), it->first));
if (year == it->first)
toSelect = i;
}
if (toSelect != -1)
{
_yearFrom->Select(toSelect);
OnYearFromChange(event);
toSelect=0;
if (month != -1)
{
for(i=0; i<(int)_monthFrom->GetCount(); i++)
{
if (_monthFrom->GetString(i) == wxUI::months[month])
{
toSelect = i;
break;
}
}
}
_monthFrom->Select(toSelect);
}
else
{
_yearFrom->Select(0);
OnYearFromChange(event);
}
for(i=2000; i<=2050; i++)
_yearTo->Append(wxString::Format(wxT("%d"), i));
if (year == -1)
{
_yearTo->Select(curDate.GetYear()-2000);
OnYearToChange(event);
_monthTo->Select(curDate.GetMonth()-1);
}
else
{
if (month == 11)
year++;
_yearTo->Select(year-2000);
OnYearToChange(event);
if (month == -1)
_monthTo->Select(0);
else
{
for(a=0, i=0, monthIt=_ops[year].begin(); monthIt!=_ops[year].end() && i<12; i++)
{
if (i != *monthIt)
{
a++;
continue;
}
if (*monthIt > month)
break;
monthIt++;
}
_monthTo->Select(a);
}
}
hbox->Add(gridBagSizer, 0, wxGROW|wxALL, 10);
SetSizer(hbox);
Fit();
Center();
}
void GenerateDialog::OnYearFromChange(wxCommandEvent& event)
{
wxString years = _yearFrom->GetString(_yearFrom->GetCurrentSelection());
int year;
std::vector<int>::iterator it;
_monthFrom->Clear();
if (!years.Length())
{
_monthFrom->Append(wxT(""));
return;
}
year = wxAtoi(years);
for(it=_ops[year].begin(); it!=_ops[year].end(); it++)
_monthFrom->Append(wxUI::months[*it]);
_monthFrom->Select(0);
Layout();
}
void GenerateDialog::OnYearToChange(wxCommandEvent& event)
{
int year, i, ok;
std::vector<int>::iterator it;
_monthTo->Clear();
year = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection()));
for (i=0; i<12; i++)
{
ok = 1;
for(it=_ops[year].begin(); it!=_ops[year].end(); it++)
{
if (*it == i)
{
ok=0; break;
}
}
if (ok)
_monthTo->Append(wxUI::months[i]);
}
_monthTo->Select(0);
Layout();
}
void GenerateDialog::OnOK(wxCommandEvent& event)
{
int monthFrom, yearFrom, monthTo, yearTo, i;
if (!_yearFrom->GetString(_yearFrom->GetCurrentSelection()).Length())
{
monthFrom = -1;
yearFrom = -1;
}
else
{
for (i=0; i<12; i++)
{
if (wxUI::months[i] == _monthFrom->GetString(_monthFrom->GetCurrentSelection()))
{
monthFrom = i;
break;
}
}
yearFrom = wxAtoi(_yearFrom->GetString(_yearFrom->GetCurrentSelection()));
}
for (i=0; i<12; i++)
{
if (wxUI::months[i] == _monthTo->GetString(_monthTo->GetCurrentSelection()))
{
monthTo = i;
break;
}
}
yearTo = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection()));
Close();
_kiss->GenerateMonth(monthFrom, yearFrom, monthTo, yearTo);
}
void GenerateDialog::OnCancel(wxCommandEvent& event)
{
Close();
}

View File

@@ -1,53 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GENERATEDIALOG_H
#define GENERATEDIALOG_H
#include <map>
#include <wx/wx.h>
#include <controller/KissCount.hpp>
#include <model/model.hpp>
#include "wxUI.hpp"
class wxUI;
class KissCount;
class GenerateDialog : public wxDialog
{
public:
GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year);
void OnYearFromChange(wxCommandEvent& event);
void OnYearToChange(wxCommandEvent& event);
void OnOK(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
private:
KissCount* _kiss;
wxUI* _wxUI;
wxChoice* _yearFrom, *_monthFrom, *_yearTo, *_monthTo;
std::map<int, std::vector<int> > _ops;
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,458 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/colordlg.h>
#include <wx/fontdlg.h>
#include <wx/treectrl.h>
#include <wx/statbox.h>
#include <wx/gbsizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/bmpcbox.h>
#include <wx/grid.h>
#include "ImportPanel.hpp"
enum {OPEN_FILE_ID=1, BUTTON_OPEN_ID, NAME_ID, BUTTON_LOAD_ID, BUTTON_INTEGRATE_ID, CHECK_SAVE_ID, OPS_GRID_ID};
BEGIN_EVENT_TABLE(ImportPanel, wxPanel)
EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, ImportPanel::OnOperationModified)
EVT_BUTTON(BUTTON_OPEN_ID, ImportPanel::OnFile)
EVT_BUTTON(BUTTON_INTEGRATE_ID, ImportPanel::OnIntegrate)
EVT_TEXT_ENTER(OPEN_FILE_ID, ImportPanel::OnFileEnter)
EVT_BUTTON(BUTTON_LOAD_ID, ImportPanel::OnLoadOperations)
EVT_SHOW(ImportPanel::OnShow)
END_EVENT_TABLE()
ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent)
{
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
_hbox = new wxBoxSizer(wxHORIZONTAL);
wxButton* buttonOpen;
wxRect rect = wxDisplay().GetGeometry();
int w, h;
wxStaticBox* staticAccount = new wxStaticBox(this, wxID_ANY, _("Unresolved accounts"));
wxStaticBox* staticCategory = new wxStaticBox(this, wxID_ANY, _("Unresolved categories"));
SetSizer(vbox);
_fileTxt = new wxTextCtrl(this, OPEN_FILE_ID);
_fileTxt->SetWindowStyle(_fileTxt->GetWindowStyle() | wxTE_PROCESS_ENTER);
_fileTxt->GetSize(&w, &h);
wxSize size(rect.width/3, h);
_fileTxt->SetMinSize(size);
buttonOpen = new wxButton(this, BUTTON_OPEN_ID, wxT("..."));
_buttonLoadOperations = new wxButton(this, BUTTON_LOAD_ID, _("Load operations"));
_buttonLoadOperations->Disable();
_buttonIntegrate = new wxButton(this, BUTTON_INTEGRATE_ID, _("Integrate operations"));
_buttonIntegrate->Disable();
_checkSaveImportPatterns = new wxCheckBox(this, CHECK_SAVE_ID, _("Save import patterns"));
hbox->Add(_fileTxt, 0, wxGROW|wxALL, 5);
hbox->Add(buttonOpen, 0, wxALL, 5);
hbox->Add(_buttonLoadOperations, 0, wxALL, 5);
hbox->Add(_buttonIntegrate, 0, wxALL, 5);
hbox->Add(_checkSaveImportPatterns, 0, wxALL, 5);
vbox->Add(hbox, 0);
_accountsGrid = new wxGrid(this, wxID_ANY);
_accountsGrid->CreateGrid(0, 3);
_accountsGrid->SetRowLabelSize(0);
_accountsGrid->SetColLabelValue(0, _("File account"));
_accountsGrid->SetColLabelValue(1, _("Account name"));
_accountsGrid->SetColLabelValue(2, _("Internal account"));
_accountsGrid->Fit();
_categoriesGrid = new wxGrid(this, wxID_ANY);
_categoriesGrid->CreateGrid(0, 3);
_categoriesGrid->SetRowLabelSize(0);
_categoriesGrid->SetColLabelValue(0, _("File category"));
_categoriesGrid->SetColLabelValue(1, _("Category name"));
_categoriesGrid->SetColLabelValue(2, _("Internal category"));
_categoriesGrid->Fit();
wxStaticBoxSizer* staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL);
staticBoxSizer->Add(_accountsGrid, 0, wxGROW|wxALL, 2);
vbox2->Add(staticBoxSizer, wxGROW|wxALL);
staticBoxSizer = new wxStaticBoxSizer (staticCategory, wxVERTICAL);
staticBoxSizer->Add(_categoriesGrid, 0, wxGROW|wxALL, 2);
vbox2->Add(staticBoxSizer, wxGROW|wxALL);
_operationsGrid = new GridAccount(kiss, this, OPS_GRID_ID, false, false, false);
_hbox->Add(vbox2, 0, wxGROW|wxALL, 15);
_hbox->Add(_operationsGrid, 0, wxGROW|wxALL, 15);
vbox->Add(_hbox, wxGROW);
Fit();
SetMinSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
SetMaxSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
SetScrollbars(10, 10, 100/10, 100/10);
}
KissPanel* ImportPanel::CreatePanel()
{
return new ImportPanel(_kiss, _wxUI);
}
wxBitmapButton* ImportPanel::GetButton(int id)
{
if (!_KissButton)
_KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(IMPORT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128));
return _KissButton;
}
wxString ImportPanel::GetToolTip()
{
return _("Import");
}
void ImportPanel::OnShow(wxShowEvent& event)
{
_wxUI->SetTitle(_("KissCount - Import"));
}
void ImportPanel::OnFile(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog openFileDialog(this, _("Choose a database to open"), wxT(""), wxT(""),
_kiss->GetImportEngineExtensions(), wxFD_OPEN|wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() == wxID_CANCEL)
return;
_fileTxt->Clear();
*_fileTxt << openFileDialog.GetPath();
ProcessFile();
}
void ImportPanel::OnFileEnter(wxCommandEvent& WXUNUSED(event))
{
ProcessFile();
}
void ImportPanel::ProcessFile()
{
User* user = _kiss->GetUser();
int i;
wxGridCellChoiceEditor* accountEditor;
wxString* userAccounts;
std::map<wxString, wxString> resolvedAccounts;
wxGridCellChoiceEditor* categoryEditor;
wxString* userCategories;
std::map<wxString, wxString> resolvedCategories;
wxCommandEvent event;
wxString path = _fileTxt->GetLineText(0);
_buttonLoadOperations->Disable();
_buttonIntegrate->Disable();
_accountsGrid->ClearGrid();
_categoriesGrid->ClearGrid();
_operationsGrid->ClearGrid();
_importEngine = _kiss->GetImportEngine(path);
if (!_importEngine)
{
wxMessageBox(_("Any engine can process this file !"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
return ;
}
_importEngine->ParseFile(_unresolvedAccounts, _unresolvedCategories);
if (_unresolvedAccounts.size())
{
int nb_accounts = user->GetAccountsNumber();
userAccounts = new wxString[nb_accounts+1];
userAccounts[0] = _("Create one");
for(i=0; i<nb_accounts; i++)
userAccounts[i+1] = user->_accounts[i].name;
accountEditor = new wxGridCellChoiceEditor(nb_accounts+1, userAccounts, false);
_buttonLoadOperations->Enable();
_accountsGrid->AppendRows(_unresolvedAccounts.size());
for (i=0; i<(int)_unresolvedAccounts.size(); i++)
{
_accountsGrid->SetCellValue(i, 0, _unresolvedAccounts[i].number);
_accountsGrid->SetReadOnly(i, 0);
_accountsGrid->SetCellValue(i, 1, _unresolvedAccounts[i].name);
_accountsGrid->SetCellValue(i, 2, userAccounts[0]);
_accountsGrid->SetCellEditor(i, 2, accountEditor);
}
_accountsGrid->AutoSize();
_accountsGrid->Layout();
}
if (_unresolvedCategories.size())
{
int nb_categories = user->GetCategoriesNumber();
userCategories = new wxString[nb_categories+1];
userCategories[0] = _("Create one");
for(i=0; i<nb_categories; i++)
userCategories[i+1] = user->_categories[i].name;
categoryEditor = new wxGridCellChoiceEditor(nb_categories+1, userCategories, false);
_buttonLoadOperations->Enable();
_categoriesGrid->AppendRows(_unresolvedCategories.size());
for (i=0; i<(int)_unresolvedCategories.size(); i++)
{
_categoriesGrid->SetCellValue(i, 0, _unresolvedCategories[i].name);
_categoriesGrid->SetReadOnly(i, 0);
_categoriesGrid->SetCellValue(i, 2, userCategories[0]);
_categoriesGrid->SetCellEditor(i, 2, categoryEditor);
}
_categoriesGrid->AutoSize();
_categoriesGrid->Layout();
}
if (!_unresolvedAccounts.size() && !_unresolvedCategories.size())
{
OnLoadOperations(event);
}
Layout();
}
void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
{
int i, nbAccounts=0, nbCategories=0;
User* user = _kiss->GetUser();
Account account;
Category category;
std::map<wxString, wxString> accounts;
std::map<wxString, wxString> categories;
wxString oldid;
for(i=0; i<_accountsGrid->GetNumberRows(); i++)
{
if (_accountsGrid->GetCellValue(i, 2) == _("Create one"))
nbAccounts++;
else
accounts[_accountsGrid->GetCellValue(i, 0)] =
user->GetAccountId(_accountsGrid->GetCellValue(i, 1));
}
for(i=0; i<_categoriesGrid->GetNumberRows(); i++)
{
if (_categoriesGrid->GetCellValue(i, 2) == _("Create one"))
nbCategories++;
else
categories[_categoriesGrid->GetCellValue(i, 0)] =
user->GetAccountId(_categoriesGrid->GetCellValue(i, 1));
}
if (nbAccounts || nbCategories)
{
wxString message;
if (nbAccounts)
{
message += wxString::Format(_("%d accounts"), nbAccounts);
if (nbCategories) message += _(" and ");
}
if (nbCategories)
message += wxString::Format(_("%d categories"), nbCategories);
message += _(" will be created, is it ok ?");
wxMessageDialog dialog(_wxUI, message, wxT("KissCount"), wxYES_NO);
if (dialog.ShowModal() == wxID_NO)
return;
for(i=0; i<_accountsGrid->GetNumberRows(); i++)
{
if (_accountsGrid->GetCellValue(i, 2) == _("Create one"))
{
account = _unresolvedAccounts[i] ;
if (_accountsGrid->GetCellValue(i, 1).Length())
account.name = _accountsGrid->GetCellValue(i, 1);
else
account.name = _accountsGrid->GetCellValue(i, 0);
account.number = _accountsGrid->GetCellValue(i, 0);
oldid = account.id;
_resolvedAccounts[oldid] = accounts[_accountsGrid->GetCellValue(i, 0)] = _kiss->AddAccount(account);
}
}
_accountsGrid->DeleteRows(0, _accountsGrid->GetNumberRows ());
for(i=0; i<_categoriesGrid->GetNumberRows(); i++)
{
if (_categoriesGrid->GetCellValue(i, 2) == _("Create one"))
{
category = _unresolvedCategories[i] ;
if (_categoriesGrid->GetCellValue(i, 1).Length())
category.name = _categoriesGrid->GetCellValue(i, 1);
else
category.name = _categoriesGrid->GetCellValue(i, 0);
oldid = category.id;
_resolvedCategories[oldid] = categories[_categoriesGrid->GetCellValue(i, 0)] = category.id = _kiss->AddCategory(category);
}
}
_categoriesGrid->DeleteRows(0, _categoriesGrid->GetNumberRows ());
_wxUI->NeedReload();
}
_operations = _importEngine->GetOperations(accounts, categories);
if (_operations->size())
{
_hbox->Detach(_operationsGrid);
delete _operationsGrid;
_operationsGrid = new GridAccount(_kiss, this, OPS_GRID_ID, false, false, false);
_hbox->Add(_operationsGrid, 0, wxGROW|wxALL, 15);
_operationsGrid->LoadOperations(_operations, 0, 0);
_buttonIntegrate->Enable();
_buttonLoadOperations->Disable();
Fit();
}
else
{
wxMessageBox(_("No operation found into this file"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
}
}
void ImportPanel::OnIntegrate(wxCommandEvent& WXUNUSED(event))
{
int i;
std::map<wxString, wxString> mapid;
wxString oldid, account;
bool update;
std::map<AccountAmount, double, AccountAmount> accountAmounts;
std::map<AccountAmount, double, AccountAmount>::iterator it;
double amount;
if (!_operations->size()) return;
wxMessageDialog dialog(_wxUI, _("Are you sure want to integrate these operations ?"), wxT("KissCount"), wxYES_NO);
if (dialog.ShowModal() == wxID_NO)
return;
_buttonIntegrate->Disable();
for(i=0; i<(int)_operations->size(); i++)
{
oldid = (*_operations)[i].id;
_kiss->AddOperation((*_operations)[i], false);
mapid[oldid] = (*_operations)[i].id;
}
for(i=0; i<(int)_operations->size(); i++)
{
update = false;
if ((*_operations)[i].parent.Length())
{
(*_operations)[i].parent = mapid[(*_operations)[i].parent];
update = true;
}
if ((*_operations)[i].transfert.Length())
{
(*_operations)[i].transfert = mapid[(*_operations)[i].transfert];
update = true;
}
if (update)
_kiss->UpdateOperation((*_operations)[i], false);
}
accountAmounts = _importEngine->GetAccountAmounts();
for(it=accountAmounts.begin(); it!=accountAmounts.end(); it++)
{
account = it->first.account;
if (_resolvedAccounts.count(account))
account = _resolvedAccounts[account];
amount = _kiss->GetAccountAmount(account, it->first.month, it->first.year);
if (!amount)
_kiss->SetAccountAmount(account, it->first.month, it->first.year, it->second);
}
if (_checkSaveImportPatterns->IsChecked())
_kiss->UpdateImportPattern();
_operations->clear();
_operationsGrid->ClearGrid();
wxMessageBox(_("Operations successfully imported"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
_wxUI->NeedReload();
}
void ImportPanel::OnOperationModified(wxGridEvent& event)
{
int col = event.GetCol();
int row;
static bool update = false;
if (col != DESCRIPTION && col != CATEGORY && col != ACCOUNT) return ;
if (update) return;
update = true;
row = event.GetRow();
_operationsGrid->ClearGrid();
if (_importEngine->UpdatePattern(row-1) > 1)
_operationsGrid->LoadOperations(_operations, 0, 0);
Fit();
update = false;
}

View File

@@ -1,67 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef IMPORTPANEL_H
#define IMPORTPANEL_H
#include <wx/wx.h>
#include "view.hpp"
#include <model/model.hpp>
#include <model/import/ImportEngine.hpp>
#include "grid/GridAccount.hpp"
class ImportPanel: public KissPanel
{
public:
ImportPanel(KissCount* kiss, wxUI *parent);
KissPanel* CreatePanel();
wxBitmapButton* GetButton(int id);
wxString GetToolTip();
void OnShow(wxShowEvent& event);
void OnFile(wxCommandEvent& WXUNUSED(event));
void OnFileEnter(wxCommandEvent& WXUNUSED(event));
void OnLoadOperations(wxCommandEvent& WXUNUSED(event));
void OnIntegrate(wxCommandEvent& WXUNUSED(event));
void OnOperationModified(wxGridEvent& event);
private:
wxBoxSizer *_hbox;
wxGrid* _accountsGrid, *_categoriesGrid;
wxTextCtrl* _fileTxt;
GridAccount* _operationsGrid;
ImportEngine* _importEngine;
wxButton* _buttonLoadOperations, *_buttonIntegrate;
wxCheckBox *_checkSaveImportPatterns;
std::vector<Operation>* _operations;
std::vector<Account> _unresolvedAccounts;
std::vector<Category> _unresolvedCategories;
std::map<wxString, wxString> _resolvedAccounts;
std::map<wxString, wxString> _resolvedCategories;
void ProcessFile();
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -20,34 +20,5 @@
#ifndef KISSPANEL_H
#define KISSPANEL_H
#include <wx/wx.h>
#include <wx/scrolwin.h>
#include <wx/bmpbuttn.h>
#include "wxUI.hpp"
class wxUI;
class KissCount;
class KissPanel: public wxScrolledWindow
{
public:
KissPanel(KissCount* kiss, wxUI* parent) :
wxScrolledWindow((wxFrame*)parent),
_kiss(kiss),
_wxUI(parent),
_KissButton(0)
{Hide();}
virtual void OnShow(wxShowEvent& event)=0;
virtual KissPanel* CreatePanel()=0;
virtual wxBitmapButton* GetButton(int id) {return 0;}
virtual wxString GetToolTip() {return wxT("");}
protected:
KissCount* _kiss;
wxUI* _wxUI;
wxBitmapButton* _KissButton;
};
#endif

View File

@@ -1,95 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/choice.h>
#include <wx/textctrl.h>
#include <wx/gbsizer.h>
#include "PasswordDialog.hpp"
enum {BUTTON_OK_ID=1, BUTTON_CANCEL_ID, OLD_PASSWORD_ID, NEW_PASSWORD_ID, CONFIRM_PASSWORD_ID};
BEGIN_EVENT_TABLE(PasswordDialog, wxDialog)
EVT_BUTTON(BUTTON_OK_ID, PasswordDialog::OnOK)
EVT_BUTTON(BUTTON_CANCEL_ID, PasswordDialog::OnCancel)
END_EVENT_TABLE()
PasswordDialog::PasswordDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), wxID_ANY, _("Change password")), _kiss(kiss), _wxUI(parent)
{
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
gridBagSizer = new wxGridBagSizer(5, 3);
label = new wxStaticText(this, wxID_ANY, _("Old password "));
gridBagSizer->Add(label, wxGBPosition(0, 0));
_oldPassword = new wxTextCtrl(this, OLD_PASSWORD_ID);
gridBagSizer->Add(_oldPassword, wxGBPosition(0, 1));
label = new wxStaticText(this, wxID_ANY, _("New password "));
gridBagSizer->Add(label, wxGBPosition(1, 0));
_newPassword = new wxTextCtrl(this, NEW_PASSWORD_ID);
gridBagSizer->Add(_newPassword, wxGBPosition(1, 1));
label = new wxStaticText(this, wxID_ANY, _("Confirm password "));
gridBagSizer->Add(label, wxGBPosition(2, 0));
_confirmPassword = new wxTextCtrl(this, CONFIRM_PASSWORD_ID);
gridBagSizer->Add(_confirmPassword, wxGBPosition(2, 1));
_oldPassword->SetWindowStyle(wxTE_PASSWORD);
_newPassword->SetWindowStyle(wxTE_PASSWORD);
_confirmPassword->SetWindowStyle(wxTE_PASSWORD);
wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK"));
wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel"));
gridBagSizer->Add(ok, wxGBPosition(4, 1));
gridBagSizer->Add(cancel, wxGBPosition(4, 2));
SetSizer(gridBagSizer);
Layout();
Center();
}
void PasswordDialog::OnOK(wxCommandEvent& event)
{
User* user = _kiss->GetUser();
if (!_kiss->IsValidUser(user->_name, _oldPassword->GetLineText(0)))
{
wxMessageBox(_("Invalid old password"), _("Error"), wxICON_ERROR | wxOK);
return;
}
if (_newPassword->GetLineText(0) != _confirmPassword->GetLineText(0))
{
wxMessageBox(_("Please retype new password"), _("Error"), wxICON_ERROR | wxOK);
return;
}
_kiss->ChangePassword(_newPassword->GetLineText(0));
wxMessageBox(_("Password changed"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
Close();
}
void PasswordDialog::OnCancel(wxCommandEvent& event)
{
Close();
}

View File

@@ -1,45 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PASSWORDDIALOG_H
#define PASSWORDDIALOG_H
#include <wx/wx.h>
#include "wxUI.hpp"
#include <model/model.hpp>
class wxUI;
class KissCount;
class PasswordDialog : public wxDialog
{
public:
PasswordDialog(KissCount* kiss, wxUI *parent);
void OnOK(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
private:
KissCount* _kiss;
wxUI* _wxUI;
wxTextCtrl* _oldPassword, *_newPassword, *_confirmPassword;
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,863 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/grid.h>
#include <wx/treectrl.h>
#include <wx/statbox.h>
#include <wx/gbsizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/bmpcbox.h>
#include <wx/colordlg.h>
#include <wx/fontdlg.h>
#include "grid/wxMyGrid.hpp"
#include "grid/wxGridCellStarEditor.hpp"
#include "grid/wxGridCellFastBoolEditor.hpp"
#include "grid/wxGridCellButtonRenderer.hpp"
#include "grid/wxGridCellButtonEditor.hpp"
#include "PasswordDialog.hpp"
#include "PreferencesPanel.hpp"
enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_VIRTUAL, ACCOUNT_BLOCKED, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT};
enum {CATEGORY_NAME, CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY};
enum {CATEGORIES_GRID_ID=1, ACCOUNTS_GRID_ID, NAME_ID, CHANGE_NAME_ID, CHANGE_PASSWORD_ID, KILL_ME_ID, LANGUAGE_ID,
OPERATION_ORDER_ID, SHARED_WITH_ID};
BEGIN_EVENT_TABLE(PreferencesPanel, wxPanel)
EVT_BUTTON(CHANGE_NAME_ID, PreferencesPanel::OnChangeName)
EVT_BUTTON(CHANGE_PASSWORD_ID, PreferencesPanel::OnChangePassword)
EVT_BUTTON(KILL_ME_ID, PreferencesPanel::OnKillMe)
EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified)
EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified)
EVT_GRID_CMD_SELECT_CELL(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountCellChanged)
EVT_COMBOBOX(OPERATION_ORDER_ID, PreferencesPanel::OnOperationOrderChange)
EVT_COMBOBOX(LANGUAGE_ID, PreferencesPanel::OnLanguageChange)
EVT_CHECKLISTBOX(SHARED_WITH_ID, PreferencesPanel::OnSharedChange)
EVT_SHOW(PreferencesPanel::OnShow)
END_EVENT_TABLE()
PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _sharedWith(0), _curAccountRow(-1)
{
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL);
//wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxStaticBox* staticUser, *staticAccount, *staticCategories, *staticLanguage, *staticOperationOrder, *staticSharedWith;
User* user = _kiss->GetUser();
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
wxButton* buttonChangeName, *buttonChangePassword, *killMe;
wxStaticBoxSizer * staticBoxSizer;
std::list<wxString> users;
std::list<wxString>::iterator it;
wxRect rect = wxDisplay().GetGeometry();
SetSizer(vbox);
staticUser = new wxStaticBox(this, wxID_ANY, _("User"));
staticAccount = new wxStaticBox(this, wxID_ANY, _("Accounts"));
staticCategories = new wxStaticBox(this, wxID_ANY, _("Categories"));
staticLanguage = new wxStaticBox(this, wxID_ANY, _("Language"));
staticOperationOrder = new wxStaticBox(this, wxID_ANY, _("Operation order"));
staticSharedWith = new wxStaticBox(this, wxID_ANY, _("Shared withpp"));
// User
staticBoxSizer = new wxStaticBoxSizer (staticUser, wxVERTICAL);
gridBagSizer = new wxGridBagSizer(2, 3);
staticBoxSizer->Add(gridBagSizer, 0, wxGROW|wxALL, 2);
label = new wxStaticText(this, wxID_ANY, _("Name"));
gridBagSizer->Add(label, wxGBPosition(0, 0));
_name = new wxTextCtrl(this, NAME_ID, user->_name);
gridBagSizer->Add(_name, wxGBPosition(0, 1));
buttonChangeName = new wxButton(this, CHANGE_NAME_ID, _("Change Name"));
buttonChangePassword = new wxButton(this, CHANGE_PASSWORD_ID, _("Change Password"));
killMe = new wxButton(this, KILL_ME_ID, _("Kill me"));
gridBagSizer->Add(buttonChangeName, wxGBPosition(1, 0));
gridBagSizer->Add(buttonChangePassword, wxGBPosition(1, 1));
gridBagSizer->Add(killMe, wxGBPosition(1, 2));
vbox->Add(staticBoxSizer, 0, wxALL, 10);
// Account
staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL);
{
int clicks[] = {ACCOUNT_DEFAULT, ACCOUNT_DELETE};
_accountsGrid = new wxMyGrid(this, ACCOUNTS_GRID_ID, clicks, 2);
}
InitAccounts(user);
staticBoxSizer->Add(_accountsGrid, 0, wxGROW|wxALL, 2);
hbox1->Add(staticBoxSizer, 0, wxALL);
staticBoxSizer = new wxStaticBoxSizer (staticSharedWith, wxVERTICAL);
_sharedWith = new wxCheckListBox(this, SHARED_WITH_ID);
staticBoxSizer->Add(_sharedWith, 0, wxGROW);
users = _kiss->GetUsers();
for(it=users.begin(); it!=users.end(); it++)
if (*it != user->_name)
_sharedWith->Append(*it);
_sharedWith->Enable(false);
hbox1->Add(staticBoxSizer, 0, wxLEFT, 5);
vbox->Add(hbox1, 0, wxGROW|wxALL, 10);
// Categories
staticBoxSizer = new wxStaticBoxSizer (staticCategories, wxVERTICAL);
{
int clicks[] = {CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE};
_categoriesGrid = new wxMyGrid(this, CATEGORIES_GRID_ID, clicks, 4);
}
staticBoxSizer->Add(_categoriesGrid, 0, wxGROW|wxALL, 2);
InitCategories(user);
vbox->Add(staticBoxSizer, 0, wxALL, 10);
// Operation Order
staticBoxSizer = new wxStaticBoxSizer (staticOperationOrder, wxVERTICAL);
_operationOrder = new wxComboBox(this, OPERATION_ORDER_ID);
_operationOrder->SetWindowStyle(wxCB_READONLY);
staticBoxSizer->Add(_operationOrder, 0, wxGROW|wxALL, 2);
hbox2->Add(staticBoxSizer, 0);
InitOperationOrder(user);
// Language
staticBoxSizer = new wxStaticBoxSizer (staticLanguage, wxVERTICAL);
_language = new wxBitmapComboBox(this, LANGUAGE_ID);
_language->SetWindowStyle(wxCB_READONLY);
staticBoxSizer->Add(_language, 0, wxGROW|wxALL, 2);
hbox2->Add(staticBoxSizer, 0, wxLEFT, 10);
InitLanguage(user);
_language->Fit();
vbox->Add(hbox2, 0, wxALL, 10);
Fit();
SetMinSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
SetMaxSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
SetScrollbars(10, 10, 100/10, 100/10);
}
KissPanel* PreferencesPanel::CreatePanel()
{
return new PreferencesPanel(_kiss, _wxUI);
}
wxBitmapButton* PreferencesPanel::GetButton(int id)
{
if (!_KissButton)
_KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(PREFS_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128));
return _KissButton;
}
wxString PreferencesPanel::GetToolTip()
{
return _("Preferences");
}
void PreferencesPanel::InitAccounts(User* user)
{
std::vector<Account>::iterator it;
int curLine = 0;
Account account ;
DEFAULT_FONT(font);
_accountsGrid->CreateGrid(0, NUMBER_COLS_ACCOUNT);
_accountsGrid->SetRowLabelSize(0);
_accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Name"));
_accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Number"));
_accountsGrid->SetColLabelValue(ACCOUNT_DEFAULT, _("Default"));
_accountsGrid->SetColLabelValue(ACCOUNT_VIRTUAL, _("Virtual"));
_accountsGrid->SetColLabelValue(ACCOUNT_BLOCKED, _("Blocked"));
_accountsGrid->SetColLabelValue(ACCOUNT_DELETE, _("Delete"));
_accountsGrid->SetDefaultCellFont(font);
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++)
{
_accountsGrid->AppendRows();
AddAccount(curLine, *it);
}
_accountsGrid->AppendRows();
account.id = wxT("0");
AddAccount(curLine, account);
}
void PreferencesPanel::AddAccount(int line, Account ac)
{
if (ac.id != wxT("0"))
{
_accountsGrid->SetCellValue(line, ACCOUNT_NAME, ac.name);
if (ac.shared)
_accountsGrid->SetCellValue(line, ACCOUNT_NUMBER, ac.number + wxT("*"));
else
_accountsGrid->SetCellValue(line, ACCOUNT_NUMBER, ac.number);
_accountsGrid->SetCellEditor(line, ACCOUNT_NUMBER, new wxGridCellStarEditor ());
_accountsGrid->SetCellRenderer(line, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(line, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(line, ACCOUNT_VIRTUAL, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(line, ACCOUNT_VIRTUAL, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(line, ACCOUNT_BLOCKED, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(line, ACCOUNT_BLOCKED, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(line, ACCOUNT_DELETE, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(line, ACCOUNT_DELETE, new wxGridCellBoolEditor ());
_accountsGrid->SetCellValue(line, ACCOUNT_DEFAULT, (ac._default)?wxT("1"):wxT("0"));
_accountsGrid->SetCellValue(line, ACCOUNT_VIRTUAL, (ac._virtual)?wxT("1"):wxT("0"));
_accountsGrid->SetCellValue(line, ACCOUNT_BLOCKED, (ac.blocked)?wxT("1"):wxT("0"));
_accountsGrid->SetCellAlignment(line, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(line, ACCOUNT_VIRTUAL, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(line, ACCOUNT_BLOCKED, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(line, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
if (!ac.is_owner)
{
_accountsGrid->SetReadOnly(line, ACCOUNT_NAME, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_NUMBER, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true);
}
else
{
_accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, false);
_accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, false);
_accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, false);
_accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, false);
}
}
else
{
_accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, true);
_accountsGrid->AutoSizeColumns(true);
}
}
#define SET_ROW_COLOR(row, backcolor, forecolor) for(int i=0; i<NUMBER_COLS_CATEGORY; i++) \
{ \
_categoriesGrid->SetCellBackgroundColour(row, i, backcolor); \
_categoriesGrid->SetCellTextColour(row, i, forecolor); \
}
#define SET_ROW_FONT(row, font) for(int i=0; i<NUMBER_COLS_CATEGORY; i++) \
{ \
_categoriesGrid->SetCellFont(row, i, font); \
}
void PreferencesPanel::InitCategories(User* user)
{
std::vector<Category>::iterator it;
int curLine = 0;
DEFAULT_FONT(font);
Category cat;
_categoriesGrid->CreateGrid(0, NUMBER_COLS_CATEGORY);
_categoriesGrid->SetRowLabelSize(0);
_categoriesGrid->SetDefaultCellFont(font);
_categoriesGrid->SetColLabelValue(CATEGORY_NAME, _("Name"));
_categoriesGrid->SetColLabelValue(CATEGORY_BACKGROUND_COLOR, _("Background color"));
_categoriesGrid->SetColLabelValue(CATEGORY_FOREGROUND_COLOR, _("Foreground color"));
_categoriesGrid->SetColLabelValue(CATEGORY_FONT, _("Font"));
_categoriesGrid->SetColLabelValue(CATEGORY_DELETE, _("Delete"));
for (it=user->_categories.begin(); it!=user->_categories.end(); it++, curLine++)
{
_categoriesGrid->AppendRows();
AddCategory(curLine, *it);
}
_categoriesGrid->SetReadOnly(0, CATEGORY_NAME, true);
_categoriesGrid->SetReadOnly(0, CATEGORY_DELETE, true);
cat.id = wxT("0");
_categoriesGrid->AppendRows();
AddCategory(curLine, cat);
}
void PreferencesPanel::AddCategory(int line, Category cat)
{
User* user = _kiss->GetUser();
if (cat.id != wxT("0"))
{
_categoriesGrid->SetCellValue(line, CATEGORY_NAME, wxGetTranslation(cat.name));
SET_ROW_COLOR(line, cat.backcolor, cat.forecolor);
if (line)
{
_categoriesGrid->SetCellRenderer(line, CATEGORY_DELETE, new wxGridCellBoolRenderer ());
_categoriesGrid->SetCellEditor(line, CATEGORY_DELETE, new wxGridCellBoolEditor ());
}
_categoriesGrid->SetCellRenderer(line, CATEGORY_BACKGROUND_COLOR, new wxGridCellButtonRenderer (wxT("...")));
_categoriesGrid->SetCellRenderer(line, CATEGORY_FOREGROUND_COLOR, new wxGridCellButtonRenderer (wxT("...")));
_categoriesGrid->SetCellRenderer(line, CATEGORY_FONT, new wxGridCellButtonRenderer (wxT("...")));
_categoriesGrid->SetCellEditor(line, CATEGORY_BACKGROUND_COLOR, new wxGridCellButtonEditor (wxT("...")));
_categoriesGrid->SetCellEditor(line, CATEGORY_FOREGROUND_COLOR, new wxGridCellButtonEditor (wxT("...")));
_categoriesGrid->SetCellEditor(line, CATEGORY_FONT, new wxGridCellButtonEditor (wxT("...")));
if (cat.font.Length())
{
wxFont font = user->GetCategoryFont(cat.id);
SET_ROW_FONT(line, font);
}
_categoriesGrid->SetCellAlignment(line, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
}
else
{
_categoriesGrid->SetReadOnly(line, CATEGORY_BACKGROUND_COLOR, true);
_categoriesGrid->SetReadOnly(line, CATEGORY_FOREGROUND_COLOR, true);
_categoriesGrid->SetReadOnly(line, CATEGORY_FONT, true);
_categoriesGrid->SetReadOnly(line, CATEGORY_DELETE, true);
SET_ROW_COLOR(line, view::OWN_GREEN, *wxBLACK);
_categoriesGrid->AutoSizeColumns(true);
}
}
void PreferencesPanel::InitLanguage(User* user)
{
int i, select=0;
for (i=0; i<SupportedLanguages::NB_SUPPORTED_LANGUAGES; i++)
{
_language->Append(SupportedLanguages::languages[i].name, wxBitmap(SupportedLanguages::languages[i].icon, wxBITMAP_TYPE_PNG));
if (SupportedLanguages::languages[i].language == _wxUI->_language)
select = i;
}
_language->Select(select);
}
void PreferencesPanel::InitOperationOrder(User* user)
{
_operationOrder->Append(_("Ascending"));
_operationOrder->Append(_("Descending"));
if (user->_preferences[wxT("operation_order")] == wxT("ASC"))
_operationOrder->Select(0);
else
_operationOrder->Select(1);
}
void PreferencesPanel::OnAccountModified(wxGridEvent& event)
{
int op_complete = 1;
wxString value ;
Account new_account, account;
User* user = _kiss->GetUser();
int row = event.GetRow();
int col = event.GetCol();
static bool inModification = false ;
int i, a;
if (inModification) return;
inModification = true;
value = _accountsGrid->GetCellValue(row, ACCOUNT_NAME);
if (value.Length())
{
new_account.name = value;
op_complete--;
}
value = _accountsGrid->GetCellValue(row, ACCOUNT_NUMBER);
if (value.Length())
{
new_account.number = value;
op_complete--;
}
value = _accountsGrid->GetCellValue(row, ACCOUNT_DEFAULT);
if (value.Length() && value != wxT("0"))
new_account._default = true;
else
new_account._default = false;
value = _accountsGrid->GetCellValue(row, ACCOUNT_VIRTUAL);
if (value.Length() && value != wxT("0"))
new_account._virtual = true;
else
new_account._virtual = false;
value = _accountsGrid->GetCellValue(row, ACCOUNT_BLOCKED);
if (value.Length() && value != wxT("0"))
new_account.blocked = true;
else
new_account.blocked = false;
// Account modification
if (user->GetAccountsNumber() && row < user->GetAccountsNumber())
{
new_account.id = user->_accounts[row].id;
new_account.shared = user->_accounts[row].shared;
new_account.is_owner = user->_accounts[row].is_owner;
if (col == ACCOUNT_DELETE)
{
if (user->_accounts.size() == 1)
{
wxMessageBox(_("It must be at least one account !"), _("Error"), wxICON_ERROR | wxOK);
_accountsGrid->SetCellValue(row, col, wxT("0"));
return;
}
wxString *accounts = new wxString[user->GetAccountsNumber()];
accounts[0] = _("None");
a = 0;
for(i=0; i < user->GetAccountsNumber(); i++)
if (user->_accounts[i].id != new_account.id)
accounts[++a] = user->_accounts[i].name;
wxSingleChoiceDialog dialog(_wxUI, _("Wich account will replace this one ?"), wxT("KissCount"), user->GetAccountsNumber(), accounts);
if (dialog.ShowModal() == wxID_CANCEL)
{
_accountsGrid->SetCellValue(row, col, wxT("0"));
}
else
{
_accountsGrid->DeleteRows(row, 1);
i = dialog.GetSelection();
_kiss->DeleteAccount(new_account, (!i) ? wxT("0") : user->GetAccountId(accounts[i]));
}
if (user->_accounts.size() == 1)
{
user->_accounts[0]._default = true;
_kiss->UpdateAccount(user->_accounts[0]);
_accountsGrid->SetCellValue(0, ACCOUNT_DEFAULT, wxT("1"));
}
Fit();
inModification = false;
_wxUI->NeedReload();
return;
}
if (col == ACCOUNT_DEFAULT)
{
for (i=0; i<user->GetAccountsNumber(); i++)
{
if (i != row)
{
account = user->_accounts[i];
if (account._default)
{
account._default = false;
_kiss->UpdateAccount(account);
_accountsGrid->SetCellValue(i, ACCOUNT_DEFAULT, wxT(""));
break;
}
}
}
}
if (col == ACCOUNT_NAME)
{
value = user->GetAccountId(new_account.name);
if (value != wxT("0") && value != new_account.id)
{
wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK );
_accountsGrid->SetCellValue(row, ACCOUNT_NAME, user->_accounts[row].name);
inModification = false;
return ;
}
}
_kiss->UpdateAccount(new_account);
}
// New account
else
{
if (op_complete)
{
inModification = false;
return ;
}
if (user->GetAccountId(new_account.name) != wxT("0"))
{
wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK );
inModification = false;
return ;
}
new_account.shared = false;
new_account.blocked = false;
new_account.is_owner = true;
new_account._virtual = false;
AddAccount(row, new_account);
_kiss->AddAccount(new_account);
_accountsGrid->AppendRows();
new_account.id = wxT("0");
AddAccount(row+1, new_account);
}
Fit();
_wxUI->NeedReload();
inModification = false;
}
void PreferencesPanel::OnAccountCellChanged(wxGridEvent& event)
{
User* user = _kiss->GetUser();
int row = event.GetRow();
std::map<wxString, wxString>::iterator it;
int i;
bool own;
wxString owner;
if (!_sharedWith || _curAccountRow == row)
{
event.Skip();
return ;
}
_curAccountRow = row ;
if (row >= (int) user->_accounts.size())
{
for(i=0; i<(int)_sharedWith->GetCount(); i++)
_sharedWith->Check(i, false);
own = false;
}
else
{
_sharedOwners = _kiss->getSharedAccountOwners(user->_accounts[row].id);
owner = _kiss->getSharedAccountOwner(user->_accounts[row].id);
for(i=0; i<(int)_sharedWith->GetCount(); i++)
{
_sharedWith->Check(i, _sharedOwners[_sharedWith->GetString(i)].Length() > 0 ||
_sharedWith->GetString(i) == owner);
}
own = user->_accounts[row].is_owner;
}
_sharedWith->Enable(own);
event.Skip();
}
void PreferencesPanel::OnSharedChange(wxCommandEvent& event)
{
User* user = _kiss->GetUser();
// Event is fired before change
if (_sharedWith->IsChecked(event.GetSelection()))
{
if (!user->_accounts[_curAccountRow].shared)
_accountsGrid->SetCellValue(_curAccountRow, ACCOUNT_NUMBER,
user->_accounts[_curAccountRow].number + wxT("*"));
_kiss->AddSharedAccount(user->_accounts[_curAccountRow],
_sharedWith->GetString(event.GetSelection()));
}
else
{
_kiss->RemoveSharedAccount(user->_accounts[_curAccountRow],
_sharedOwners[_sharedWith->GetString(
event.GetSelection())]);
if (!user->_accounts[_curAccountRow].shared)
_accountsGrid->SetCellValue(_curAccountRow, ACCOUNT_NUMBER, user->_accounts[_curAccountRow].number);
}
_wxUI->NeedReload();
event.Skip();
}
void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
{
int op_complete = 1;
wxString value;
User* user = _kiss->GetUser();
int row = event.GetRow();
int col = event.GetCol();
static bool inModification = false ;
Category new_cat, cat_tmp;
int i, a;
if (inModification) return;
inModification = true;
if (event.GetCol() == CATEGORY_BACKGROUND_COLOR)
{
wxColourData color;
color.SetColour(wxColor(user->_categories[row].backcolor));
wxColourDialog dial(this, &color);
if (dial.ShowModal() == wxID_OK)
{
user->_categories[row].backcolor = dial.GetColourData().GetColour();
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor);
_wxUI->NeedReload();
}
inModification = false ;
return ;
}
if (event.GetCol() == CATEGORY_FOREGROUND_COLOR)
{
wxColourData color;
color.SetColour(wxColor(user->_categories[row].forecolor));
wxColourDialog dial(this, &color);
if (dial.ShowModal() == wxID_OK)
{
user->_categories[row].forecolor = dial.GetColourData().GetColour();
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor);
_wxUI->NeedReload();
}
inModification = false ;
return ;
}
if (event.GetCol() == CATEGORY_FONT)
{
wxFontData font;
font.SetInitialFont(_kiss->ExtractFont(user->_categories[row].font));
wxFontDialog dial(this, font);
if (dial.ShowModal() == wxID_OK)
{
font = dial.GetFontData();
user->_categories[row].font = _kiss->CompactFont(font.GetChosenFont());
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_FONT(row, font.GetChosenFont());
_wxUI->NeedReload();
}
inModification = false ;
return ;
}
value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME);
if (value.Length())
{
new_cat.name = value;
op_complete--;
}
new_cat.backcolor = _categoriesGrid->GetCellBackgroundColour(row, col);
new_cat.forecolor = _categoriesGrid->GetCellTextColour(row, col);
new_cat.font = wxT("");
new_cat.parent = wxT("0");
// Categories modification
if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber())
{
new_cat.id = user->_categories[row].id;
new_cat.fix_cost = user->_categories[row].fix_cost;
if (col == CATEGORY_DELETE)
{
wxString *categories = new wxString[user->GetCategoriesNumber()];
categories[0] = _("None");
a = 0;
for(i=0; i < user->GetCategoriesNumber(); i++)
if (user->_categories[i].id != new_cat.id)
categories[++a] = wxGetTranslation(user->_categories[i].name);
wxSingleChoiceDialog dialog(_wxUI, _("Wich category will replace this one ?"), wxT("KissCount"), user->GetCategoriesNumber(), categories);
if (dialog.ShowModal() == wxID_CANCEL)
{
_categoriesGrid->SetCellValue(row, col, wxT("0"));
}
else
{
_categoriesGrid->DeleteRows(row, 1);
i = dialog.GetSelection();
_kiss->DeleteCategory(user->_categories[row], (!i) ? wxT("0") : user->GetCategoryId(categories[i]));
Fit();
_wxUI->NeedReload();
}
inModification = false;
return;
}
value = user->GetCategoryId(new_cat.name);
if (value != wxT("0") && value != new_cat.id)
{
wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK );
_categoriesGrid->SetCellValue(row, CATEGORY_NAME, user->_categories[row].name);
inModification = false;
return ;
}
_kiss->UpdateCategory(new_cat);
}
// New category
else
{
if (op_complete)
{
inModification = false;
return ;
}
if (user->GetCategoryId(new_cat.name) != wxT("0"))
{
wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK );
inModification = false;
return ;
}
new_cat.fix_cost = false;
_kiss->AddCategory(new_cat);
AddCategory(row, new_cat);
_categoriesGrid->SetReadOnly(row, CATEGORY_BACKGROUND_COLOR, false);
_categoriesGrid->SetReadOnly(row, CATEGORY_FOREGROUND_COLOR, false);
_categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false);
_categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false);
new_cat.id = wxT("0");
_categoriesGrid->AppendRows();
AddCategory(++row, new_cat);
}
Fit();
_wxUI->NeedReload();
inModification = false;
return;
}
void PreferencesPanel::OnChangeName(wxCommandEvent& event)
{
User* user = _kiss->GetUser();
wxString name = _name->GetLineText(0);
if (name == user->_name)
return;
if (!name.size())
{
wxMessageBox(_("Invalid name"), _("Error"), wxICON_ERROR | wxOK);
return;
}
if (_kiss->UserExists(name))
{
wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK);
return;
}
_kiss->ChangeName(name);
wxMessageBox(_("Name changed"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
_wxUI->NeedReload();
_wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") +_("Preferences"));
}
void PreferencesPanel::OnChangePassword(wxCommandEvent& event)
{
PasswordDialog p(_kiss, _wxUI);
p.ShowModal();
}
void PreferencesPanel::OnOperationOrderChange(wxCommandEvent& event)
{
if (_operationOrder->GetCurrentSelection() == 0)
_kiss->SetOperationOrder(wxT("ASC"));
else
_kiss->SetOperationOrder(wxT("DESC"));
_wxUI->NeedReload();
}
void PreferencesPanel::OnLanguageChange(wxCommandEvent& event)
{
wxLanguage language = SupportedLanguages::languages[_language->GetSelection()].language;
if (_wxUI->SetLanguage(language) || language == wxLANGUAGE_ENGLISH)
{
_wxUI->NeedReload();
_kiss->SetLanguage(language);
wxMessageBox(_("Language successfully changed, please go to another panel"), _("KissCount"), wxICON_INFORMATION | wxOK);
}
else
wxMessageBox(_("Language not changed"), _("KissCount"), wxICON_ERROR | wxOK);
}
void PreferencesPanel::OnShow(wxShowEvent& event)
{
_wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + _("Preferences"));
}
void PreferencesPanel::OnKillMe(wxCommandEvent& event)
{
User* user = _kiss->GetUser();
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete ")+user->_name+_(" profil ?"), wxT("KissCount"), wxYES_NO);
if (dialog.ShowModal() == wxID_NO)
{
return;
}
_kiss->KillMe();
}

View File

@@ -1,73 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PREFERENCESPANEL_H
#define PREFERENCESPANEL_H
#include <wx/wx.h>
#include <wx/bmpcbox.h>
#include "view.hpp"
#include <model/model.hpp>
#include "SupportedLanguages.hpp"
class PreferencesPanel: public KissPanel
{
public:
PreferencesPanel(KissCount* kiss, wxUI *parent);
KissPanel* CreatePanel();
wxBitmapButton* GetButton(int id);
wxString GetToolTip();
void OnShow(wxShowEvent& event);
void ChangeUser();
void OnAccountModified(wxGridEvent& event);
void OnAccountCellChanged(wxGridEvent& event);
void OnSharedChange(wxCommandEvent& event);
void OnCategoryModified(wxGridEvent& event);
void OnChangeName(wxCommandEvent& event);
void OnChangePassword(wxCommandEvent& event);
void OnOperationOrderChange(wxCommandEvent& event);
void OnLanguageChange(wxCommandEvent& event);
void OnKillMe(wxCommandEvent& event);
private:
wxGrid* _accountsGrid;
wxGrid* _categoriesGrid;
wxTextCtrl* _name;
wxBitmapComboBox* _language;
wxComboBox* _operationOrder;
wxCheckListBox* _sharedWith;
int _curAccountRow;
std::map<wxString, wxString> _sharedOwners;
void InitAccounts(User* user);
void InitCategories(User* user);
void InitLanguage(User* user);
void InitOperationOrder(User* user);
void AddAccount(int line, Account ac);
void AddCategory(int line, Category cat);
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,220 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SearchBanner.hpp"
enum {DESCRIPTION_ID=1, CALENDAR_FROM_ID, CALENDAR_TO_ID};
BEGIN_EVENT_TABLE(SearchBanner, wxPanel)
EVT_CALENDAR_SEL_CHANGED(CALENDAR_TO_ID, SearchBanner::OnCalendarToChange)
EVT_TEXT_ENTER(DESCRIPTION_ID, SearchBanner::OnEnter)
END_EVENT_TABLE()
SearchBanner::SearchBanner(KissCount* kiss, wxPanel *parent, void* caller, OnButtonEnter enterCallback) : wxPanel(parent), _kiss(kiss), _caller(caller), _enterCallback(enterCallback), _operations(0)
{
DEFAULT_FONT(font);
User* user = _kiss->GetUser();
std::vector<Account>::iterator accountIt;
std::vector<Category>::iterator categoryIt;
wxDateTime firstOfMonth;
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
SetSizer(vbox);
_checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from"));
_checkDateTo = new wxCheckBox(this, wxID_ANY, _("Date to"));
_checkDateFrom->SetValue(wxT("1"));
_checkDateTo->SetValue(wxT("1"));
wxGridBagSizer *gridBagSizer = new wxGridBagSizer(3, 10);
firstOfMonth.SetToCurrent();
firstOfMonth.SetDay(1);
_calendarFrom = new wxCalendarCtrl(this, CALENDAR_FROM_ID, firstOfMonth, wxDefaultPosition, wxDefaultSize,
wxCAL_MONDAY_FIRST);
_calendarTo = new wxCalendarCtrl(this, CALENDAR_TO_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize,
wxCAL_MONDAY_FIRST);
_description = new wxTextCtrl(this, DESCRIPTION_ID);
_description->SetWindowStyle(_description->GetWindowStyle() | wxTE_PROCESS_ENTER);
wxSize size = _description->GetSize();
size.SetWidth(size.GetWidth()*2);
_description->SetMinSize(size);
_amountFrom = new wxTextCtrl(this, wxID_ANY);
_amountTo = new wxTextCtrl(this, wxID_ANY);
_category = new wxCheckListBox(this, wxID_ANY);
_category->Append(_("Unknown"));
for(categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
_category->Append(wxGetTranslation(categoryIt->name));
wxString stypes[] = {_("Fix"), _("Non fix"), _("Checked"), _("Not checked")};
_optype = new wxCheckListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, stypes);
_account = new wxCheckListBox(this, wxID_ANY);
_account->Append(_("Unknown"));
for(accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++)
_account->Append(accountIt->name);
wxStaticText* labelDescription = new wxStaticText(this, wxID_ANY, _("Description"));
wxStaticText* labelAmountFrom = new wxStaticText(this, wxID_ANY, _("Amount from"));
wxStaticText* labelAmountTo = new wxStaticText(this, wxID_ANY, _("Amount to"));
wxStaticText* labelCategory = new wxStaticText(this, wxID_ANY, _("Category"));
wxStaticText* labelOperations = new wxStaticText(this, wxID_ANY, _("Operations"));
wxStaticText* labelAccount = new wxStaticText(this, wxID_ANY, _("Account"));
gridBagSizer->Add(labelDescription, wxGBPosition(0, 0));
gridBagSizer->Add(_description, wxGBPosition(1, 0));
gridBagSizer->Add(_checkDateFrom, wxGBPosition(0, 1));
gridBagSizer->Add(_calendarFrom, wxGBPosition(1, 1));
gridBagSizer->Add(_checkDateTo, wxGBPosition(0, 2));
gridBagSizer->Add(_calendarTo, wxGBPosition(1, 2));
gridBagSizer->Add(labelAmountFrom, wxGBPosition(0, 3));
gridBagSizer->Add(_amountFrom, wxGBPosition(1, 3));
gridBagSizer->Add(labelAmountTo, wxGBPosition(0, 4));
gridBagSizer->Add(_amountTo, wxGBPosition(1, 4));
gridBagSizer->Add(labelCategory, wxGBPosition(0, 5));
gridBagSizer->Add(_category, wxGBPosition(1, 5));
gridBagSizer->Add(labelOperations, wxGBPosition(0, 6));
gridBagSizer->Add(_optype, wxGBPosition(1, 6));
gridBagSizer->Add(labelAccount, wxGBPosition(0, 7));
gridBagSizer->Add(_account, wxGBPosition(1, 7));
vbox->Add(gridBagSizer, 0, wxGROW|wxALL, 5);
}
SearchBanner::~SearchBanner()
{
if (_operations) delete _operations;
}
std::vector<Operation> * SearchBanner::Search()
{
wxString *description=0, *amountFrom=0, *amountTo=0;
std::vector<wxString> categories, accounts;
wxDateTime *dateFrom=0, *dateTo=0;
User* user= _kiss->GetUser();
int i, types=0;
std::vector<Operation>::iterator it;
double af, at;
if (_operations)
{
delete _operations;
_operations = 0;
}
if (_checkDateFrom->IsChecked())
{
dateFrom = new wxDateTime;
*dateFrom = _calendarFrom->GetDate();
}
if (_checkDateTo->IsChecked())
{
dateTo = new wxDateTime;
*dateTo = _calendarTo->GetDate();
}
if (dateFrom && dateTo && *dateFrom > *dateTo)
{
wxMessageBox(_("Invalid date range"), _("Error"), wxICON_ERROR | wxOK);
goto end;
}
if (_amountFrom->GetLineText(0).Length())
{
amountFrom = new wxString;
*amountFrom = _amountFrom->GetLineText(0);
if (!amountFrom->ToDouble(&af))
{
wxMessageBox(_("Invalid amount from"), _("Error"), wxICON_ERROR | wxOK);
goto end;
}
if (af < 0) af *= -1;
}
if (_amountTo->GetLineText(0).Length())
{
amountTo = new wxString;
*amountTo = _amountTo->GetLineText(0);
if (!amountTo->ToDouble(&at))
{
wxMessageBox(_("Invalid amount to"), _("Error"), wxICON_ERROR | wxOK);
goto end;
}
if (at < 0) at *= -1;
}
if (amountFrom && amountTo && af > at)
{
wxMessageBox(_("Invalid amount range"), _("Error"), wxICON_ERROR | wxOK);
goto end;
}
if (_description->GetLineText(0).Length())
{
description = new wxString;
*description = _description->GetLineText(0);
}
for(i=0; i<user->GetCategoriesNumber()+1; i++)
if (_category->IsChecked(i))
categories.push_back((i) ? user->_categories[i-1].id : wxT("0"));
types |= (_optype->IsChecked(0)) ? Database::FIX_OP : 0;
types |= (_optype->IsChecked(1)) ? Database::NON_FIX_OP : 0;
types |= (_optype->IsChecked(2)) ? Database::CHECKED_OP : 0;
types |= (_optype->IsChecked(3)) ? Database::NOT_CHECKED_OP : 0;
for(i=0; i<user->GetAccountsNumber()+1; i++)
if (_account->IsChecked(i))
accounts.push_back((i) ? user->_accounts[i-1].id : wxT("0"));
_operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories,types, accounts);
end:
delete dateFrom;
delete dateTo;
delete amountFrom;
delete amountTo;
return _operations;
}
void SearchBanner::OnEnter(wxCommandEvent& event)
{
if (_enterCallback)
_enterCallback(_caller, event);
}
void SearchBanner::OnCalendarFromChange(wxCalendarEvent& event)
{
_checkDateFrom->SetValue(true);
}
void SearchBanner::OnCalendarToChange(wxCalendarEvent& event)
{
_checkDateTo->SetValue(true);
}

View File

@@ -1,61 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SEARCHBANNER_H
#define SEARCHBANNER_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/gbsizer.h>
#include <wx/treectrl.h>
#include <wx/scrolwin.h>
#include "view.hpp"
#include "grid/CalendarEditor.hpp"
#include <model/model.hpp>
typedef void (*OnButtonEnter)(void* caller, wxCommandEvent& event);
class SearchBanner: public wxPanel
{
public:
SearchBanner(KissCount* kiss, wxPanel* parent, void* caller=0, OnButtonEnter enterCallback=0);
~SearchBanner();
void OnEnter(wxCommandEvent& event);
void OnButtonSearch(wxCommandEvent& event);
void OnCalendarFromChange(wxCalendarEvent& event);
void OnCalendarToChange(wxCalendarEvent& event);
std::vector<Operation> * Search();
private:
KissCount* _kiss;
void* _caller;
OnButtonEnter _enterCallback;
std::vector<Operation> *_operations;
wxCalendarCtrl* _calendarFrom, *_calendarTo;
wxCheckBox *_checkDateFrom, *_checkDateTo;
wxTextCtrl* _description, *_amountFrom, *_amountTo;
wxCheckListBox* _category, *_account, *_optype;
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,265 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/treectrl.h>
#include <wx/scrolwin.h>
#include "grid/CalendarEditor.hpp"
#include "grid/wxGridCellBitmapRenderer.hpp"
#include "SearchPanel.hpp"
enum {SEARCH_ID=1, GRID_ID,
CHANGE_ACCOUNT_ID, CHANGE_CATEGORY_ID, RENAME_ID};
BEGIN_EVENT_TABLE(SearchPanel, wxPanel)
EVT_BUTTON(SEARCH_ID, SearchPanel::OnButtonSearch)
EVT_GRID_CMD_CELL_CHANGE(GRID_ID, SearchPanel::OnOperationModified)
EVT_BUTTON(CHANGE_ACCOUNT_ID, SearchPanel::OnButtonChangeAccount)
EVT_BUTTON(CHANGE_CATEGORY_ID, SearchPanel::OnButtonChangeCategory)
EVT_BUTTON(RENAME_ID, SearchPanel::OnButtonRename)
EVT_SHOW(SearchPanel::OnShow)
END_EVENT_TABLE()
SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _operations(0)
{
DEFAULT_FONT(font);
std::vector<Account>::iterator accountIt;
std::vector<Category>::iterator categoryIt;
wxDateTime firstOfMonth;
wxRect rect = wxDisplay().GetGeometry();
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
SetSizer(vbox);
_searchButton = new wxButton(this, SEARCH_ID, _("Searchpp"));
_banner = new SearchBanner(kiss, this, this, OnEnter);
vbox->Add(_banner, 0, wxGROW|wxALL, 5);
vbox->Add(_searchButton, 0, wxALL, 5);
_grid = new GridAccount(_kiss, this, GRID_ID, false, false, true);
hbox->Add(_grid, 0, wxGROW|wxALL, 5);
_changeAccountButton = new wxButton(this, CHANGE_ACCOUNT_ID, _("Change account"));
_changeCategoryButton = new wxButton(this, CHANGE_CATEGORY_ID, _("Change category"));
_renameButton = new wxButton(this, RENAME_ID, _("Rename"));
vbox2->Add(_changeAccountButton, wxALL, 15);
vbox2->Add(_changeCategoryButton, wxALL, 15);
vbox2->Add(_renameButton, wxALL, 15);
hbox->Add(vbox2, 0, wxALL, 15);
vbox->Add(hbox, 0, wxGROW|wxALL, 5);
Fit();
SetMinSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
SetMaxSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
SetScrollbars(10, 10, 100/10, 100/10);
}
SearchPanel::~SearchPanel()
{
}
KissPanel* SearchPanel::CreatePanel()
{
return new SearchPanel(_kiss, _wxUI);
}
wxBitmapButton* SearchPanel::GetButton(int id)
{
if (!_KissButton)
_KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(SEARCH_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128));
return _KissButton;
}
wxString SearchPanel::GetToolTip()
{
return _("Searchpp");
}
void SearchPanel::OnEnter(void* caller, wxCommandEvent& event)
{
SearchPanel* _this = (SearchPanel*) caller;
_this->OnButtonSearch(event);
}
void SearchPanel::OnButtonSearch(wxCommandEvent& event)
{
_operations = _banner->Search();
if (!_operations) return;
if (_operations->size() > 1)
wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
else if (_operations->size() == 1)
wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
else
{
wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
return;
}
_grid->LoadOperations(_operations, 0, 0);
_wxUI->Layout();
}
static void ChangeAccount(Operation* op, void** params)
{
wxString* account = (wxString*) params[0];
op->account = *account;
}
void SearchPanel::OnButtonChangeAccount(wxCommandEvent& event)
{
int i, a;
std::vector<int> rows;
User* user = _kiss->GetUser();
wxString *accounts = new wxString[user->GetAccountsNumber()+1];
std::vector<Operation>::iterator it;
wxString account;
void * params[] = {&account};
if (!_operations) return;
_grid->GetSelectedOperations(&rows);
accounts[0] = _("None");
a = 0;
for(i=0; i < user->GetAccountsNumber(); i++)
accounts[++a] = user->_accounts[i].name;
wxSingleChoiceDialog dialog(_wxUI, _("Choose a new account"), wxT("KissCount"), user->GetAccountsNumber()+1, accounts);
if (dialog.ShowModal() == wxID_CANCEL)
return;
a = dialog.GetSelection();
account = (a) ? user->_accounts[a-1].id : wxT("0");
_grid->MassUpdate(rows, ChangeAccount, params);
_wxUI->NeedReload();
}
static void ChangeCategory(Operation* op, void** params)
{
wxString* category = (wxString*) params[0];
bool* fix = (bool*) params[1];
op->category = *category;
op->fix_cost = * fix;
}
void SearchPanel::OnButtonChangeCategory(wxCommandEvent& event)
{
int i, a;
std::vector<int> rows;
User* user = _kiss->GetUser();
wxString *categories = new wxString[user->GetCategoriesNumber()+1];
std::vector<Operation>::iterator it;
wxString category;
bool fix;
void * params[] = {&category, &fix};
if (!_operations) return;
_grid->GetSelectedOperations(&rows);
categories[0] = _("None");
a = 0;
for(i=0; i < user->GetCategoriesNumber(); i++)
categories[++a] = wxGetTranslation(user->_categories[i].name);
wxSingleChoiceDialog dialog(_wxUI, _("Choose a new category"), wxT("KissCount"), user->GetCategoriesNumber()+1, categories);
if (dialog.ShowModal() == wxID_CANCEL)
return;
a = dialog.GetSelection();
if (a)
{
category = user->_categories[a-1].id ;
fix = user->_categories[a-1].fix_cost;
}
else
{
category = wxT("0");
fix = false;
}
_grid->MassUpdate(rows, ChangeCategory, params);
_wxUI->NeedReload();
}
static void ChangeName(Operation* op, void** params)
{
wxString* description = (wxString*) params[0];
op->description = *description;
}
void SearchPanel::OnButtonRename(wxCommandEvent& event)
{
std::vector<int> rows;
std::vector<Operation>::iterator it;
wxString category;
wxString description;
void * params[] = {&description};
if (!_operations) return;
_grid->GetSelectedOperations(&rows);
wxTextEntryDialog u(this, wxT(""), _("Enter a new description"));
if (u.ShowModal() == wxID_CANCEL)
return;
description = u.GetValue();
if (!description.size()) return;
_grid->MassUpdate(rows, ChangeName, params);
_wxUI->NeedReload();
}
void SearchPanel::OnShow(wxShowEvent& event)
{
_wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + _("Searchpp"));
}
void SearchPanel::OnOperationModified(wxGridEvent& event)
{
_wxUI->NeedReload();
}

View File

@@ -1,64 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SEARCHPANEL_H
#define SEARCHPANEL_H
#include <wx/wx.h>
#include <wx/grid.h>
#include "view.hpp"
#include "grid/GridAccount.hpp"
#include "AccountPanel.hpp"
#include "SearchBanner.hpp"
#include <model/model.hpp>
class GridAccount;
class SearchPanel: public KissPanel
{
public:
SearchPanel(KissCount* kiss, wxUI *parent);
~SearchPanel();
KissPanel* CreatePanel();
wxBitmapButton* GetButton(int id);
wxString GetToolTip();
void OnShow(wxShowEvent& event);
/* void OnEnter(wxCommandEvent& event); */
void OnButtonSearch(wxCommandEvent& event);
void OnOperationModified(wxGridEvent& event);
void OnButtonChangeAccount(wxCommandEvent& event);
void OnButtonChangeCategory(wxCommandEvent& event);
void OnButtonRename(wxCommandEvent& event);
private:
std::vector<Operation> *_operations;
SearchBanner* _banner;
GridAccount *_grid;
wxButton* _searchButton, *_renameButton, *_changeAccountButton, *_changeCategoryButton;
static void OnEnter(void* caller, wxCommandEvent& event);
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,416 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/xy/xylinerenderer.h>
#include <wx/xy/xysimpledataset.h>
#include "StatsPanel.hpp"
enum {RANGE_ID=1, ACCOUNTS_ID};
BEGIN_EVENT_TABLE(StatsPanel, wxPanel)
EVT_CHOICE(RANGE_ID, StatsPanel::OnRangeChange)
EVT_CHECKLISTBOX(ACCOUNTS_ID, StatsPanel::OnAccountsChange)
END_EVENT_TABLE()
StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _plot(0), _chart(0)
{
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
_hbox2 = new wxBoxSizer(wxHORIZONTAL);
_vbox2 = new wxBoxSizer(wxVERTICAL);
int i;
User* user = _kiss->GetUser();
std::vector<Account>::iterator accountIt;
std::vector<Category>::iterator categoryIt;
std::map<int, std::vector<int> > operations;
std::map<int, std::vector<int> >::iterator it;
int nbCategories;
SetSizer(vbox);
_monthFrom = new wxChoice (this, RANGE_ID, wxDefaultPosition, wxDefaultSize, 12, wxUI::months);
_yearFrom = new wxChoice (this, RANGE_ID);
_monthTo = new wxChoice (this, RANGE_ID, wxDefaultPosition, wxDefaultSize, 12, wxUI::months);
_yearTo = new wxChoice (this, RANGE_ID);
operations = _kiss->GetAllOperations();
for(i=0, it = operations.begin(); it != operations.end(); it++, i++)
{
_yearFrom->Append(wxString::Format(wxT("%d"), it->first));
_yearTo->Append(wxString::Format(wxT("%d"), it->first));
}
if (i) i--;
_yearFrom->Select(i);
_yearTo->Select(i);
_monthFrom->Select(0);
_monthTo->Select(11);
wxStaticText* label = new wxStaticText(this, wxID_ANY, _("From"));
hbox->Add(label, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
hbox->Add(_monthFrom, 0, wxRIGHT, 5);
hbox->Add(_yearFrom, 0, wxRIGHT, 20);
label = new wxStaticText(this, wxID_ANY, _("To"));
hbox->Add(label, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
hbox->Add(_monthTo, 0, wxRIGHT, 5);
hbox->Add(_yearTo);
_account = new wxCheckListBox(this, ACCOUNTS_ID);
for(i=0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++, i++)
{
_account->Append(accountIt->name);
_account->Check(i);
}
_categories = new wxString[user->GetCategoriesNumber()] ;
for(i=0, categoryIt = user->_categories.begin();
categoryIt != user->_categories.end();
categoryIt++, i++)
{
_categoriesIndexes[categoryIt->id] = i;
_categories[i] = wxGetTranslation(categoryIt->name) ;
}
DEFAULT_FONT(font);
_statsGrid = new wxGrid(this, wxID_ANY);
_statsGrid->CreateGrid(user->GetCategoriesNumber()+1, 2);
_statsGrid->SetColLabelSize(0);
_statsGrid->SetRowLabelSize(0);
_statsGrid->EnableEditing(false);
_statsGrid->SetDefaultCellFont(font);
_statsGrid->AutoSizeColumn(0, true);
for(i=0; i<user->GetCategoriesNumber(); i++)
{
if (i)
{
_statsGrid->SetCellValue(i+1, 0, _categories[i]);
_statsGrid->SetCellAlignment(i+1, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
}
else
{
_statsGrid->SetCellValue(i, 0, _categories[i]);
_statsGrid->SetCellAlignment(i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
}
}
_statsGrid->SetCellValue(1, 0, _("Non fix"));
_statsGrid->SetCellAlignment(1, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
_vbox2->Add(_account, 0, wxGROW|wxALL, 5);
_vbox2->Add(_statsGrid, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5);
_pie = new PiePlot();
nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
_dataset = new CategorySimpleDataset(_categories, nbCategories);
ColorScheme* colorScheme = new ColorScheme(wxUI::categoryColors, WXSIZEOF(wxUI::categoryColors));
_categoriesValues = new double[user->GetCategoriesNumber()];
for(i=0; i<user->GetCategoriesNumber(); i++)
_categoriesValues[i] = 0.0;
_dataset->AddSerie(_("Serie 1"), _categoriesValues, nbCategories);
_dataset->SetRenderer(new CategoryRenderer(*colorScheme));
_pie->SetDataset(_dataset);
_pie->SetColorScheme(colorScheme);
_pie->SetLegend(new Legend(wxBOTTOM, wxCENTER));
_chartCategories = new wxChartPanel(this);
_chartCategories->SetChart(new Chart(_pie, _("Cost repartition")));
_chartCategories->Fit();
_chartCategories->Layout();
_chartCategories->SetMinSize(// chart->GetSize()
wxSize(200,250));
vbox->Add(hbox, 0, wxALIGN_CENTER_VERTICAL|wxGROW|wxALL, 5);
vbox->Add(_hbox2, 0, wxGROW|wxALL, 5);
wxCommandEvent event ;
OnRangeChange(event);
Fit();
}
KissPanel* StatsPanel::CreatePanel()
{
return new StatsPanel(_kiss, _wxUI);
}
wxBitmapButton* StatsPanel::GetButton(int id)
{
if (!_KissButton)
_KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(STATS_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128));
return _KissButton;
}
wxString StatsPanel::GetToolTip()
{
return _("Statistics");
}
void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearTo)
{
std::map<wxString, std::map<int, std::map<int, double> > > accountAmounts;
std::map<wxString, double> categories;
std::map<wxString, std::vector<double> > operations;
std::vector<Account>::iterator accountIt;
std::map<wxString, double>::iterator categoriesIt;
std::map<int, std::map<int, double> >::iterator accountYearIt;
double total, non_fix;
int account, size, i, a, b, percents, nbDays;
double *amounts;
wxString value;
User* user = _kiss->GetUser();
wxDateTime date;
bool failed;
if (_chart)
{
_hbox2->Detach(_chart);
_hbox2->Detach(_vbox2);
_hbox2->Detach(_chartCategories);
delete _chart;
}
// first step: create plot
_plot = new XYPlot();
// create dataset
XYSimpleDataset *dataset = new XYSimpleDataset();
if (monthFrom == monthTo && yearFrom == yearTo)
{
nbDays = date.GetLastMonthDay((wxDateTime::Month)monthFrom, yearFrom).GetDay();
_kiss->GetMonthStats(monthFrom, yearFrom, nbDays, &operations, &categories);
// Line on 0 all over the years
amounts = new double[nbDays*2];
for (a=0; a<nbDays; a++)
{
amounts[a*2+0] = a;
amounts[a*2+1] = 0;
}
dataset->AddSerie((double *) amounts, nbDays);
delete[] amounts;
for (account = 0, i = 0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end();
account++, accountIt++, i++)
{
if (!_account->IsChecked(account))
{
i-- ;
continue;
}
amounts = new double[nbDays*2];
size = 0;
for (a=0; a<nbDays; a++)
{
amounts[a*2+0] = a;
amounts[a*2+1] = operations[accountIt->id][a];
}
dataset->AddSerie((double *) amounts, nbDays);
// set serie names to be displayed on legend
dataset->SetSerieName(i+1, user->GetAccountName(accountIt->id));
delete[] amounts;
}
}
else
{
_kiss->GetStats(monthFrom, yearFrom, monthTo, yearTo, &accountAmounts, &categories);
// Line on 0 all over the years
size = ((yearTo - yearFrom) + 1) * 12;
amounts = new double[size*2];
for (a=0; a<(size/12); a++)
{
for(b=0; b<12; b++)
{
amounts[a*12*2+b*2+0] = a*12+b;
amounts[a*12*2+b*2+1] = 0;
}
}
dataset->AddSerie((double *) amounts, size);
delete[] amounts;
for (account = 0, i = 0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end();
account++, accountIt++, i++)
{
if (!_account->IsChecked(account))
{
i-- ;
continue;
}
size = accountAmounts[accountIt->id].size();
amounts = new double[size*13*2];
size = 0;
for(a = 0, accountYearIt = accountAmounts[accountIt->id].begin();
accountYearIt != accountAmounts[accountIt->id].end();
accountYearIt++, a++)
{
for(b = 0; b<=12; b++)
{
amounts[size*2+0] = a*12+b;
if (!accountAmounts[accountIt->id][accountYearIt->first].count(b))
{
/*
If previously afiled, continue to avoid to set
account to 0 (only for display)
*/
if (!b || failed) continue;
/*
Compute cur month value (if there are operations)
as next month value
*/
amounts[size*2+1] =
accountAmounts[accountIt->id][accountYearIt->first][b-1]
+ _kiss->CalcAccountAmount(accountIt->id, b-1, accountYearIt->first, 0);
failed = true;
}
else
{
amounts[size*2+1] = accountAmounts[accountIt->id][accountYearIt->first][b];
failed = false;
}
size++;
}
}
dataset->AddSerie((double *) amounts, size);
// set serie names to be displayed on legend
dataset->SetSerieName(i+1, user->GetAccountName(accountIt->id));
delete[] amounts;
}
}
// create line renderer and set it to dataset
XYLineRenderer *renderer = new XYLineRenderer(true, true);
dataset->SetRenderer(renderer);
// add our dataset to plot
_plot->AddDataset(dataset);
// create left and bottom number axes
NumberAxis *leftAxis = new NumberAxis(AXIS_LEFT);
NumberAxis *bottomAxis = new NumberAxis(AXIS_BOTTOM);
// add axes to plot
_plot->AddAxis(leftAxis);
_plot->AddAxis(bottomAxis);
// link axes and dataset
_plot->LinkDataVerticalAxis(0, 0);
_plot->LinkDataHorizontalAxis(0, 0);
// set legend
_plot->SetLegend(new Legend(wxCENTER, wxRIGHT));
_chart = new wxChartPanel(this);
_chart->SetChart(new Chart(_plot, _("Accounts")));
_chart->Fit();
_chart->Layout();
_chart->SetMinSize(// chart->GetSize()
wxSize(750,550));
_hbox2->Add(_chart, 0, wxGROW|wxALL, 5);
total = 0.0;
for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++)
total += categoriesIt->second;
for(i=0, categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++, i++)
{
_categoriesValues[_categoriesIndexes[categoriesIt->first]] = categoriesIt->second;
if (total)
percents = ((double) (categoriesIt->second*100))/total;
else
percents = 0;
value = wxString::Format(wxT("%0.2lf (%02d%%)"), categoriesIt->second, percents);
if (i)
_statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first]+1, 1, value);
else
_statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first], 1, value);
}
non_fix = total - _categoriesValues[0];
if (total)
percents = ((double) (non_fix*100))/total;
else
percents = 0;
value = wxString::Format(wxT("%0.2lf (%02d%%)"), non_fix, percents);
_statsGrid->SetCellValue(1, 1, value);
_statsGrid->AutoSizeColumn(0, true);
_statsGrid->AutoSizeColumn(1, true);
_pie->DatasetChanged(_dataset);
_hbox2->Add(_vbox2, 0, wxGROW|wxALL, 5);
_hbox2->Add(_chartCategories, 0, wxGROW|wxALL, 10);
Layout();
}
void StatsPanel::OnShow(wxShowEvent& event)
{
_wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + _("Statistics"));
}
void StatsPanel::OnRangeChange(wxCommandEvent& event)
{
long monthFrom, monthTo, yearFrom, yearTo;
if (!_yearFrom->GetStringSelection().Length() ||
!_yearTo->GetStringSelection().Length())
return;
monthFrom = _monthFrom->GetCurrentSelection();
_yearFrom->GetStringSelection().ToLong(&yearFrom);
monthTo = _monthTo->GetCurrentSelection();
_yearTo->GetStringSelection().ToLong(&yearTo);
if (yearTo < yearFrom ||
(yearFrom == yearTo && monthFrom > monthTo))
{
wxMessageBox(_("Invalide date range"), _("KissCount"), wxICON_ERROR | wxOK);
return;
}
UpdateStats(monthFrom, yearFrom, monthTo, yearTo);
}
void StatsPanel::OnAccountsChange(wxCommandEvent& event)
{
OnRangeChange(event);
}

View File

@@ -1,70 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STATSPANEL_H
#define STATSPANEL_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/choice.h>
#include <wx/chart.h>
#include <wx/grid.h>
#include <wx/pie/pieplot.h>
#include <wx/chartpanel.h>
#include <wx/category/categorysimpledataset.h>
#include <wx/calctrl.h>
#include <wx/xy/xyplot.h>
#include "view.hpp"
#include <model/model.hpp>
class StatsPanel: public KissPanel
{
public:
StatsPanel(KissCount* kiss, wxUI *parent);
KissPanel* CreatePanel();
wxBitmapButton* GetButton(int id);
wxString GetToolTip();
void OnShow(wxShowEvent& event);
private:
wxCalendarCtrl* _calendarFrom, *_calendarTo;
wxChoice* _monthFrom, *_yearFrom, *_monthTo, *_yearTo;
wxGrid *_statsGrid;
PiePlot* _pie;
double *_categoriesValues;
CategorySimpleDataset* _dataset;
XYPlot *_plot ;
wxString* _categories;
std::map<wxString, int> _categoriesIndexes;
wxBoxSizer *_hbox2, *_vbox2;
wxChartPanel* _chart, *_chartCategories;
wxCheckListBox* _account;
void UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearTo);
void OnRangeChange(wxCommandEvent& event);
void OnAccountsChange(wxCommandEvent& event);
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,138 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/choice.h>
#include <wx/textctrl.h>
#include <wx/textdlg.h>
#include <wx/gbsizer.h>
#include "UsersDialog.hpp"
enum {TEXT_PASSWORD_ID=1, BUTTON_OK_ID, BUTTON_CANCEL_ID, BUTTON_NEW_USER_ID};
BEGIN_EVENT_TABLE(UsersDialog, wxDialog)
EVT_BUTTON(BUTTON_OK_ID, UsersDialog::OnOK)
EVT_BUTTON(BUTTON_CANCEL_ID, UsersDialog::OnCancel)
EVT_BUTTON(BUTTON_NEW_USER_ID, UsersDialog::OnNewUser)
EVT_TEXT_ENTER(TEXT_PASSWORD_ID, UsersDialog::OnEnter)
END_EVENT_TABLE()
UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), -1, _("Users")), _kiss(kiss), _wxUI(parent)
{
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
wxCommandEvent event;
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
gridBagSizer = new wxGridBagSizer(4, 4);
label = new wxStaticText(this, wxID_ANY, _("User "));
gridBagSizer->Add(label, wxGBPosition(0, 0));
_users = new wxChoice(this, wxID_ANY);
gridBagSizer->Add(_users, wxGBPosition(0, 1));
label = new wxStaticText(this, wxID_ANY, _("Password "));
gridBagSizer->Add(label, wxGBPosition(1, 0));
_password = new wxTextCtrl(this, TEXT_PASSWORD_ID);
_password->SetWindowStyle(_password->GetWindowStyle() | wxTE_PASSWORD | wxTE_PROCESS_ENTER);
gridBagSizer->Add(_password, wxGBPosition(1, 1));
wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK"));
wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel"));
wxButton* newUser = new wxButton(this, BUTTON_NEW_USER_ID, _("New User"));
gridBagSizer->Add(ok, wxGBPosition(3, 1));
gridBagSizer->Add(cancel, wxGBPosition(3, 2));
gridBagSizer->Add(newUser, wxGBPosition(3, 3));
std::list<wxString> users_list = _kiss->GetUsers();
for(std::list<wxString>::iterator i = users_list.begin(); i != users_list.end(); i++)
{
_users->Append(*i);
}
_users->Select(0);
hbox->Add(gridBagSizer, 0, wxGROW|wxALL, 10);
SetSizer(hbox);
_users->SetFocus();
Fit();
Center();
if (users_list.size() == 0)
OnNewUser(event);
else
ShowModal();
}
void UsersDialog::OnEnter(wxCommandEvent& event)
{
OnOK(event);
}
void UsersDialog::OnOK(wxCommandEvent& event)
{
// No users in database
if (!_users->GetStringSelection().Length())
{
return;
}
if (!_kiss->IsValidUser(_users->GetStringSelection(), _password->GetLineText(0)))
{
wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK);
_password->Clear();
_password->SetFocus();
}
else
{
_kiss->LoadUser(_users->GetStringSelection());
Close();
}
}
void UsersDialog::OnCancel(wxCommandEvent& event)
{
Close();
}
void UsersDialog::OnNewUser(wxCommandEvent& event)
{
wxString name;
wxTextEntryDialog u(this, wxT(""), _("New User"));
if (u.ShowModal() == wxID_CANCEL)
return;
name = u.GetValue();
if (!name.size()) return;
if (_kiss->UserExists(name))
{
wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK);
return;
}
_kiss->NewUser(name);
_kiss->LoadUser(name);
Close();
}

View File

@@ -1,50 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USERSDIALOG_H
#define USERSDIALOG_H
#include <list>
#include <wx/wx.h>
#include "wxUI.hpp"
class wxUI;
class KissCount;
class UsersDialog : public wxDialog
{
public:
UsersDialog(KissCount* kiss, wxUI *parent);
void OnEnter(wxCommandEvent& event);
void OnOK(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
void OnNewUser(wxCommandEvent& event);
private:
KissCount* _kiss;
wxUI* _wxUI;
wxChoice* _users;
wxTextCtrl* _password;
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,111 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CalendarEditor.hpp"
CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(0), _days(0), _editor(0)
{
wxDateTime date;
int i;
_maxDay = date.GetLastMonthDay ((wxDateTime::Month) month, year).GetDay();
_days = new wxString[_maxDay];
for (i=0; i<_maxDay; i++)
_days[i] = wxString::Format(wxT("%d"), i+1) ;
_editor = new wxChoice();
}
CalendarEditor::~CalendarEditor()
{
delete _editor;
delete[] _days;
}
void CalendarEditor::BeginEdit(int row, int col, wxGrid *grid)
{
// wxDateTime date, dateDef;
// if (!grid->GetCellValue(row, col).Len()) return;
// if (date.ParseFormat(grid->GetCellValue(row, col), wxT("%d/%m/%Y"), dateDef))
// _calendar->SetDate(wxDateTime(_day, _month, _year));
}
wxGridCellEditor* CalendarEditor::Clone() const
{
return new CalendarEditor(_day, _month, _year);
}
void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
{
_parent = parent;
_editor->Create(parent, id, wxDefaultPosition, wxDefaultSize, _maxDay, _days);
_editor->Select(_day);
_editor->Connect((int)id, (int)wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(CalendarEditor::OnDateChanged), 0, this);
}
bool CalendarEditor::EndEdit (int row, int col, wxGrid *grid)
{
grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year)) ;
return true;
}
void CalendarEditor::ApplyEdit (int row, int col, wxGrid *grid)
{
grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year)) ;
}
wxString CalendarEditor::GetValue() const
{
return wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year);
}
void CalendarEditor::Reset()
{
_editor->Select(_day);
}
void CalendarEditor::Show (bool show, wxGridCellAttr *attr)
{
_editor->Show(show);
}
void CalendarEditor::SetSize (const wxRect &rect)
{
_editor->SetSize(rect);
}
void CalendarEditor::StartingClick()
{
Show(true, 0);
}
bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event)
{
return true;
}
void CalendarEditor::OnDateChanged(wxCommandEvent& event)
{
_day = _editor->GetSelection();
}

View File

@@ -1,61 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CALENDAREDITOR_H
#define CALENDAREDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/calctrl.h>
#include <wx/datetime.h>
#include <wx/event.h>
#include <wx/choice.h>
class CalendarEditor : public wxGridCellChoiceEditor, public wxEvtHandler
{
public:
CalendarEditor(int day, int month, int year);
~CalendarEditor();
void BeginEdit(int row, int col, wxGrid *grid);
wxGridCellEditor* Clone () const;
void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler);
bool EndEdit(int row, int col, wxGrid *grid);
void ApplyEdit(int row, int col, wxGrid *grid);
wxString GetValue() const;
void Reset();
void Show(bool show, wxGridCellAttr *attr=0);
void SetSize (const wxRect &rect);
/* void OnCalendarChange(wxCommandEvent& event); */
void OnDateChanged(wxCommandEvent& event);
void StartingClick();
bool IsAcceptedKey(wxKeyEvent &event);
private:
int _day;
int _month;
int _year;
wxWindow *_parent;
wxString* _days;
int _maxDay;
wxChoice* _editor;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,102 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRIDACCOUNT_H
#define GRIDACCOUNT_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <list>
#include <vector>
#include <algorithm>
#include <view/AccountPanel.hpp>
#include <model/model.hpp>
#include <controller/KissCount.hpp>
#include "wxGridCellFastBoolEditor.hpp"
#include "wxGridCellTreeButtonRenderer.hpp"
#include "wxGridCellTreeButtonEditor.hpp"
#include "wxGridCellBitmapRenderer.hpp"
#include "wxGridCellFormulaEditor.hpp"
#include "wxGridCellTabStringRenderer.hpp"
class KissCount;
enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS};
typedef void (*updateOperationFunc)(Operation* op, void** params);
class GridAccount : public wxGrid
{
public:
class OperationNotFound {};
GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id,
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
~GridAccount();
wxPen GetColGridLinePen (int col);
wxPen GetRowGridLinePen (int row);
virtual void ClearGrid();
void LoadOperations(std::vector<Operation>* operations, int month, int year);
void InsertOperationWithWeek(User* user, Operation& op, int line, bool fix, int month, int year) ;
void InsertOperation(User* user, Operation& op, int line, bool fix, int month, int year) ;
void GetSelectedOperations(std::vector<int>* rows);
void MassUpdate(std::vector<int>& rows, updateOperationFunc func, void** params);
void Group();
void UnGroup();
void OnCellLeftClick(wxGridEvent& evt);
void OnOperationModified(wxGridEvent& event);
int _fixCosts;
int _week1, _week2, _week3, _week4;
std::vector<Operation> _displayedOperations;
private:
wxWindow* _parent;
KissCount* _kiss;
bool _displayLines;
bool _canAddOperation, _setWeek;
bool _databaseSynchronization;
wxString* _categories, *_accounts;
std::vector<Operation>* _operations;
bool _loadOperations;
int _curMonth, _curYear;
void SetWeek(int week, int line);
void ResetWeeks();
void ComputeWeeks();
void InsertIntoGrid(Operation& op);
void DeleteOperation(const Operation& op);
void UpdateMeta(Operation& op);
int RemoveMeta(Operation op, int line, bool removeRoot, bool deleteOp);
void CheckMeta(Operation& op, int line, bool check);
Operation& GetOperation(const wxString& id) throw(OperationNotFound);
void UpdateOperation(Operation& op);
int GetDisplayedRow(const wxString& id);
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,43 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellBitmapRenderer.hpp"
wxGridCellBitmapRenderer::wxGridCellBitmapRenderer(wxBitmap& bitmap) : _bitmap(bitmap)
{
}
wxGridCellRenderer* wxGridCellBitmapRenderer::Clone () const
{
wxBitmap bitmap(_bitmap);
return new wxGridCellBitmapRenderer(bitmap);
}
void wxGridCellBitmapRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
{
dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col)));
dc.DrawRectangle(rect);
dc.DrawBitmap (_bitmap, rect.x + (rect.width-_bitmap.GetWidth())/2, rect.y + (rect.height-_bitmap.GetHeight())/2, true);
}
wxSize wxGridCellBitmapRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
return wxSize(_bitmap.GetWidth(), _bitmap.GetHeight());
}

View File

@@ -1,40 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLBITMAPRENDERER_H
#define WXGRIDCELLBITMAPRENDERER_H
#include <wx/grid.h>
#include <wx/bitmap.h>
#include <wx/dc.h>
class wxGridCellBitmapRenderer : public wxGridCellRenderer
{
public:
wxGridCellBitmapRenderer(wxBitmap& bitmap);
virtual wxGridCellRenderer* Clone () const;
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col);
private:
wxBitmap _bitmap;
};
#endif

View File

@@ -1,94 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellButtonEditor.hpp"
enum {BUTTON_ID = 1} ;
// BEGIN_EVENT_TABLE(wxGridCellButtonEditor, wxEvtHandler)
// EVT_BUTTON(BUTTON_ID, wxGridCellButtonEditor::OnButton)
// END_EVENT_TABLE()
wxGridCellButtonEditor::wxGridCellButtonEditor(const wxString& text) : _text(text), _button(0)
{}
wxGridCellButtonEditor::~wxGridCellButtonEditor()
{
if (_button) delete _button;
}
wxGridCellEditor* wxGridCellButtonEditor::Clone () const
{
return new wxGridCellButtonEditor(_text);
}
void wxGridCellButtonEditor::BeginEdit (int row, int col, wxGrid *grid)
{
_row = row;
_col = col;
_grid = grid;
if (_grid)
{
wxGridEvent event (_grid->GetId(), wxEVT_GRID_CELL_CHANGE, this, _row, _col);
_grid->GetEventHandler()->AddPendingEvent(event);
}
}
void wxGridCellButtonEditor::Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
{
if (_button) return;
_button = new wxButton(parent, id, _text);
_button->Connect(id, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxGridCellButtonEditor::OnButton), 0, this);
}
bool wxGridCellButtonEditor::EndEdit (int row, int col, /*const*/ wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
return false;
}
void wxGridCellButtonEditor::ApplyEdit (int row, int col, wxGrid *grid)
{}
void wxGridCellButtonEditor::Reset ()
{}
wxString wxGridCellButtonEditor::GetValue() const
{
return wxT("");
}
void wxGridCellButtonEditor::SetSize (const wxRect &rect)
{
if (_button) _button->SetSize(rect);
}
void wxGridCellButtonEditor::Show (bool show, wxGridCellAttr *attr=0)
{
if (_button) _button->Show(show);
}
void wxGridCellButtonEditor::OnButton(wxCommandEvent& evt)
{
if (_grid)
{
wxGridEvent event (_grid->GetId(), wxEVT_GRID_CELL_CHANGE, this, _row, _col);
_grid->GetEventHandler()->AddPendingEvent(event);
}
}

View File

@@ -1,54 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLBUTTONEDITOR_H
#define WXGRIDCELLBUTTONEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellButtonEditor : public wxGridCellEditor, public wxEvtHandler
{
public:
wxGridCellButtonEditor(const wxString& text);
~wxGridCellButtonEditor();
wxGridCellEditor* Clone () const;
void BeginEdit (int row, int col, wxGrid *grid);
void Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler);
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
void ApplyEdit (int row, int col, wxGrid *grid);
void Reset () ;
wxString GetValue() const ;
void SetSize (const wxRect &rect);
void Show (bool show, wxGridCellAttr *attr);
void OnButton(wxCommandEvent& event);
private:
wxString _text;
wxButton* _button;
int _row, _col;
wxGrid* _grid;
/* DECLARE_EVENT_TABLE(); */
};
#endif

View File

@@ -1,96 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellButtonRenderer.hpp"
wxGridCellButtonRenderer::wxGridCellButtonRenderer(const wxString& text) : _text(text)
{
}
wxGridCellRenderer* wxGridCellButtonRenderer::Clone () const
{
return new wxGridCellButtonRenderer(_text);
}
void wxGridCellButtonRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &_rect, int row, int col, bool isSelected)
{
wxRect rect = _rect;
wxCoord w, h, descent, external_leading;
wxBrush originalBrush = dc.GetBrush();
wxPen originalPen = dc.GetPen();
dc.SetPen(wxPen(*wxLIGHT_GREY));
dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col)));
dc.DrawRectangle(rect);
rect.x += 2 ;
rect.y += 2 ;
rect.width -= 6 ;
rect.height -= 6 ;
dc.SetPen(wxPen(*wxWHITE));
dc.DrawLine(rect.x, rect.y, rect.x + rect.width, rect.y);
dc.DrawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
dc.SetPen(wxPen(*wxBLACK));
dc.DrawLine(rect.x, rect.y + rect.height, rect.x + rect.width + 1, rect.y + rect.height);
dc.DrawLine(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height);
dc.SetPen(wxPen(wxColor(0x80, 0x80, 0x80)));
dc.DrawLine(rect.x + 1, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
dc.DrawLine(rect.x + rect.width - 1, rect.y + 1, rect.x + rect.width - 1, rect.y + rect.height);
rect.x += 1 ;
rect.y += 1 ;
rect.width -= 2 ;
rect.height -= 2 ;
dc.SetPen(wxPen(*wxLIGHT_GREY));
dc.SetBrush(wxBrush(*wxLIGHT_GREY));
dc.DrawRectangle(rect);
dc.GetTextExtent(_text, &w, &h, &descent, &external_leading);
if (w < rect.width)
rect.x += (rect.width - w) / 2;
if (h < rect.height)
rect.y += (rect.height - h) / 2;
rect.y -= (external_leading + descent);
dc.SetTextForeground(*wxBLACK);
// dc.SetTextBackground(wxColor(128, 128, 128, 255));
dc.SetTextBackground(*wxLIGHT_GREY);
dc.DrawText(_text, rect.x, rect.y);
dc.SetBrush(originalBrush);
dc.SetPen(originalPen);
}
wxSize wxGridCellButtonRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
wxCoord w, h;
dc.GetTextExtent(_text, &w, &h);
return wxSize(w+14, h+14); // (2 + 2 + 3) * 2
}

View File

@@ -1,39 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLBUTTONRENDERER_H
#define WXGRIDCELLBUTTONRENDERER_H
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellButtonRenderer : public wxGridCellRenderer
{
public:
wxGridCellButtonRenderer(const wxString& text);
virtual wxGridCellRenderer* Clone () const;
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col);
private:
wxString _text;
};
#endif

View File

@@ -1,24 +0,0 @@
#ifndef WXGRIDCELLFASTBOOLEDITOR_H
#define WXGRIDCELLFASTBOOLEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
// From http://wiki.wxwidgets.org/WxGrid
class wxGridCellFastBoolEditor : public wxGridCellBoolEditor
{
public:
void BeginEdit (int row, int col, wxGrid* grid)
{
wxGridCellBoolEditor::BeginEdit(row, col, grid);
wxFocusEvent event (wxEVT_KILL_FOCUS);
if (m_control)
{
m_control->GetEventHandler()->AddPendingEvent(event);
}
}
};
#endif

View File

@@ -1,93 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellFormulaEditor.hpp"
wxGridCellFormulaEditor::wxGridCellFormulaEditor(const wxString& formula) : _formula(formula)
{}
void wxGridCellFormulaEditor::BeginEdit (int row, int col, wxGrid *grid) {
static bool inModification = false;
Operation op;
if (inModification) return ;
inModification = true;
op = ((GridAccount*) grid)->_displayedOperations[row];
if (op.formula.Length())
{
grid->SetCellValue(row, col, op.formula);
_formula = op.formula;
}
wxGridCellTextEditor::BeginEdit(row, col, grid);
inModification = false;
}
bool wxGridCellFormulaEditor::EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
wxString res = GetValue();
Operation op;
char* str, *str2;
struct ParseExp::parse_opt opt, *r;
bool ret;
res = res.Trim();
res.Replace(wxT(","), wxT("."), true);
if (res.StartsWith(wxT("=")))
{
str = (char*) std::string(res.mb_str()).c_str();
str2 = new char[strlen(str)];
strcpy(str2, str+1);
r = &opt;
str = str2;
try {
ParseExp::ParseExp(&str2, r, false);
}
catch(...)
{
wxMessageBox(_("Invalid formula !"), _("Error"), wxICON_ERROR | wxOK);
delete str;
return false;
}
delete str;
_formula = res;
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
grid->SetCellValue(row, col, wxString::Format(wxT("%.2lf"), ParseExp::EvaluateExpr(&opt, true)));
}
else
{
_formula = wxT("");
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
}
return ret;
}
wxString wxGridCellFormulaEditor::GetFormula()
{
return _formula;
}

View File

@@ -1,56 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLFORMULAEDITOR_H
#define WXGRIDCELLFORMULAEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
#include "GridAccount.hpp"
#include "../../ParseExp.hpp"
class wxGridCellFormulaEditor : public wxGridCellTextEditor
{
public:
wxGridCellFormulaEditor(const wxString& formula);
/* ~wxGridCellFormulEeditor(); */
/* wxGridCellEditor* Clone () const; */
void BeginEdit (int row, int col, wxGrid *grid);
/* void Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler); */
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
/* void ApplyEdit (int row, int col, wxGrid *grid); */
/* void Reset () ; */
/* wxString GetValue() const ; */
/* void SetSize (const wxRect &rect); */
/* void Show (bool show, wxGridCellAttr *attr); */
wxString GetFormula();
private:
wxString _formula;
wxButton* _button;
int _row, _col;
wxGrid* _grid;
/* DECLARE_EVENT_TABLE(); */
};
#endif

View File

@@ -1,53 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellStarEditor.hpp"
void wxGridCellStarEditor::BeginEdit (int row, int col, wxGrid *grid) {
static bool inModification = false;
wxString value;
if (inModification) return ;
inModification = true;
value = grid->GetCellValue(row, col);
_has_star = (value[value.Length()-1] == '*');
if (_has_star)
grid->SetCellValue(row, col, value.RemoveLast());
wxGridCellTextEditor::BeginEdit(row, col, grid);
inModification = false;
}
bool wxGridCellStarEditor::EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
wxString res = GetValue();
bool ret;
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
if (_has_star)
grid->SetCellValue(row, col, res + wxT("*"));
return ret;
}

View File

@@ -1,37 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLSTAREDITOR_H
#define WXGRIDCELLSTAREDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellStarEditor : public wxGridCellTextEditor
{
public:
void BeginEdit (int row, int col, wxGrid *grid);
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
private:
bool _has_star;
};
#endif

View File

@@ -1,40 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellTabStringRenderer.hpp"
void wxGridCellTabStringRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
{
wxString d;
wxGridTableBase * table ;
if (!((GridAccount*) &grid)->_displayedOperations[row].parent.Length())
{
wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
return;
}
table = grid.GetTable();
d = table->GetValue(row, col).Trim();
table->SetValue(row, col, wxT(" ") + d);
wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
table->SetValue(row, col, d);
}

View File

@@ -1,35 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLTABSTRINGRENDERER_H
#define WXGRIDCELLTABSTRINGRENDERER_H
#include <wx/grid.h>
#include <wx/bitmap.h>
#include <wx/dc.h>
#include "GridAccount.hpp"
class wxGridCellTabStringRenderer : public wxGridCellStringRenderer
{
public:
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
};
#endif

View File

@@ -1,76 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellTreeButtonEditor.hpp"
wxGridCellEditor* wxGridCellTreeButtonEditor::Clone () const
{
return new wxGridCellTreeButtonEditor();
}
void wxGridCellTreeButtonEditor::BeginEdit (int row, int col, wxGrid *grid)
{
wxGridEvent evt(0, 0, 0, row, col);
_row = row;
_col = col;
_grid = grid;
wxGridCellRenderer* pRenderer = _grid->GetCellRenderer(_row, _col);
((GridAccount*)_grid)->OnCellLeftClick(evt);
((wxGridCellTreeButtonRenderer*) pRenderer)->Invert();
pRenderer->DecRef();
}
void wxGridCellTreeButtonEditor::Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
{
}
bool wxGridCellTreeButtonEditor::EndEdit (int row, int col, /*const*/ wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
return true;
}
void wxGridCellTreeButtonEditor::ApplyEdit (int row, int col, wxGrid *grid)
{}
void wxGridCellTreeButtonEditor::Reset ()
{}
wxString wxGridCellTreeButtonEditor::GetValue() const
{
wxGridCellRenderer* pRenderer = _grid->GetCellRenderer(_row, _col);
wxString res = ((wxGridCellTreeButtonRenderer*) pRenderer)->IsCollapsed() ? wxT("1") : wxT("0");
pRenderer->DecRef();
return res;
}
void wxGridCellTreeButtonEditor::SetSize (const wxRect &rect)
{
}
void wxGridCellTreeButtonEditor::Show (bool show, wxGridCellAttr *attr=0)
{
}

View File

@@ -1,50 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLTREEBUTTONEDITOR_H
#define WXGRIDCELLTREEBUTTONEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
#include "GridAccount.hpp"
#include "wxGridCellTreeButtonRenderer.hpp"
class wxGridCellTreeButtonEditor : public wxGridCellEditor
{
public:
wxGridCellEditor* Clone () const;
void BeginEdit (int row, int col, wxGrid *grid);
void Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler);
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
void ApplyEdit (int row, int col, wxGrid *grid);
void Reset () ;
wxString GetValue() const ;
void SetSize (const wxRect &rect);
void Show (bool show, wxGridCellAttr *attr);
private:
int _row, _col;
wxGrid* _grid;
};
#endif

View File

@@ -1,85 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellTreeButtonRenderer.hpp"
wxGridCellTreeButtonRenderer::wxGridCellTreeButtonRenderer(bool collapsed) : _collapsed(collapsed)
{
}
wxGridCellRenderer* wxGridCellTreeButtonRenderer::Clone () const
{
return new wxGridCellTreeButtonRenderer(_collapsed);
}
bool wxGridCellTreeButtonRenderer::IsCollapsed()
{
return _collapsed;
}
void wxGridCellTreeButtonRenderer::Invert()
{
_collapsed = !_collapsed;
}
void wxGridCellTreeButtonRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &_rect, int row, int col, bool isSelected)
{
wxRect rect = _rect;
wxBrush originalBrush = dc.GetBrush();
wxPen originalPen = dc.GetPen();
dc.SetPen(wxPen(grid.GetCellBackgroundColour(row, col)));
dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col)));
dc.DrawRectangle(rect);
rect.x += 4 ;
rect.y += 4 ;
rect.width -= 8 ;
rect.height -= 8 ;
if (rect.width > rect.height)
rect.width = rect.height;
else if (rect.height > rect.width)
rect.height = rect.width;
dc.SetPen(wxPen(*wxBLACK));
dc.DrawLine(rect.x, rect.y, rect.x + rect.width, rect.y);
dc.DrawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
dc.DrawLine(rect.x, rect.y + rect.height, rect.x + rect.width + 1, rect.y + rect.height);
dc.DrawLine(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height);
rect.x += 2 ;
rect.y += 2 ;
rect.width -= 4 ;
rect.height -= 4 ;
dc.DrawLine(rect.x+1, rect.y + rect.height/2, rect.x + rect.width + 1, rect.y + rect.height/2);
if (!_collapsed)
dc.DrawLine(rect.x + rect.width/2 + 1, rect.y, rect.x + rect.width/2 + 1, rect.y + rect.height);
}
wxSize wxGridCellTreeButtonRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
return wxSize(8, 8);
}

View File

@@ -1,41 +0,0 @@
/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLTREEBUTTONRENDERER_H
#define WXGRIDCELLTREEBUTTONRENDERER_H
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellTreeButtonRenderer : public wxGridCellRenderer
{
public:
wxGridCellTreeButtonRenderer(bool collapsed=false);
virtual wxGridCellRenderer* Clone () const;
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col);
bool IsCollapsed();
void Invert();
private:
bool _collapsed;
};
#endif

View File

@@ -1,48 +0,0 @@
#include "wxMyGrid.hpp"
BEGIN_EVENT_TABLE(wxMyGrid, wxGrid)
EVT_GRID_CELL_LEFT_CLICK(wxMyGrid::OnCellLeftClick )
END_EVENT_TABLE()
wxMyGrid::wxMyGrid(wxWindow* parent, int id, int* clicks, int size) : wxGrid(parent, id)
{
for(int i=0; i<size; i++)
_clicks.push_back(clicks[i]);
}
// From http://nomadsync.cvs.sourceforge.net/nomadsync/nomadsync/src/
void wxMyGrid::OnCellLeftClick(wxGridEvent& evt)
{
std::vector<int>::iterator it;
for(it = _clicks.begin(); it != _clicks.end(); it++)
{
if (*it == evt.GetCol())
{
// This forces the cell to go into edit mode directly
//m_waitForSlowClick = TRUE;
SetGridCursor(evt.GetRow(), evt.GetCol());
// Store the click co-ordinates in the editor if possible
// if an editor has created a ClientData area, we presume it's
// a wxPoint and we store the click co-ordinates
wxGridCellEditor* pEditor = GetCellEditor(evt.GetRow(), evt.GetCol());
wxPoint* pClickPoint = (wxPoint*)pEditor->GetClientData();
if (pClickPoint)
{
*pClickPoint = ClientToScreen(evt.GetPosition());
#ifndef __WINDOWS__
EnableCellEditControl(true);
#endif
}
// hack to prevent selection from being lost when click combobox
if (evt.GetCol() == 0 && IsInSelection(evt.GetRow(), evt.GetCol()))
{
//m_selTemp = m_selection;
m_selection = 0;
}
pEditor->DecRef();
break;
}
}
evt.Skip();
}

View File

@@ -1,22 +0,0 @@
#ifndef WXMYGRID_H
#define WXMYGRID_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <vector>
// From http://wiki.wxwidgets.org/WxGrid
class wxMyGrid : public wxGrid
{
public:
wxMyGrid(wxWindow* parent, int id, int* clicks, int size);
void OnCellLeftClick(wxGridEvent& ev);
private:
std::vector<int> _clicks;
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -20,16 +20,14 @@
#ifndef VIEW_H
#define VIEW_H
#include <wx/colour.h>
namespace view {
const wxColour OWN_CYAN(0x99, 0xCC, 0xFF);
const wxColour OWN_YELLOW(0xFF, 0xFF, 0x99);
const wxColour OWN_GREEN(0x3D, 0xEB, 0x3D);
const wxString DEFAULT_FONT_NAME(wxT("Liberation Sans"));
const QColor OWN_CYAN(0x99, 0xCC, 0xFF);
const QColor OWN_YELLOW(0xFF, 0xFF, 0x99);
const QColor OWN_GREEN(0x3D, 0xEB, 0x3D);
const std::string DEFAULT_FONT_NAME("Liberation Sans");
const int DEFAULT_FONT_SIZE = 12;
#define DEFAULT_FONT(font_name) wxFont font_name(view::DEFAULT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, view::DEFAULT_FONT_NAME);
#define DEFAULT_FONT(font_name) QFont font_name(view::DEFAULT_FONT_NAME, view::DEFAULT_FONT_SIZE);
};
#define DELETE_ICON RESSOURCES_ROOT "icons/process-stop.png"

View File

@@ -17,7 +17,7 @@
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AccountPanel.hpp"
/*#include "AccountPanel.hpp"
#include "PreferencesPanel.hpp"
#include "UsersDialog.hpp"
#include "GenerateDialog.hpp"
@@ -30,121 +30,115 @@
#include "grid/wxGridCellFastBoolEditor.hpp"
#include "grid/wxGridCellButtonRenderer.hpp"
#include "grid/wxGridCellButtonEditor.hpp"
*/
#include "wxUI.hpp"
enum {BUTTON_CHANGE_USER_ID=-4, BUTTON_ABOUT_ID=-5, BUTTON_QUIT_ID=-6};
BEGIN_EVENT_TABLE(wxUI, wxFrame)
EVT_BUTTON(BUTTON_CHANGE_USER_ID, wxUI::OnButtonChangeUser)
EVT_BUTTON(BUTTON_ABOUT_ID, wxUI::OnButtonAbout)
EVT_BUTTON(BUTTON_QUIT_ID, wxUI::OnButtonQuit)
END_EVENT_TABLE()
std::string wxUI::months[12] ;
QColor wxUI::categoryColors[MAX_CATEGORY] = {QColor(0x00, 0x45, 0x86),
QColor(0xFF, 0x3E, 0x0E),
QColor(0xFF, 0xD3, 0x20),
QColor(0x58, 0x9D, 0x1B),
QColor(0x7E, 0x00, 0x21),
QColor(0x83, 0xCC, 0xFF),
QColor(0x31, 0x40, 0x04),
QColor(0xB0, 0xCF, 0x00),
QColor(0x4B, 0x1F, 0x6F),
QColor(0xFF, 0x93, 0x0E),
QColor(0xC5, 0x00, 0x0D),
QColor(0x00, 0x84, 0xD1)};
wxString wxUI::months[12] ;
wxColour wxUI::categoryColors[MAX_CATEGORY] = {wxColour(0x00, 0x45, 0x86),
wxColour(0xFF, 0x3E, 0x0E),
wxColour(0xFF, 0xD3, 0x20),
wxColour(0x58, 0x9D, 0x1B),
wxColour(0x7E, 0x00, 0x21),
wxColour(0x83, 0xCC, 0xFF),
wxColour(0x31, 0x40, 0x04),
wxColour(0xB0, 0xCF, 0x00),
wxColour(0x4B, 0x1F, 0x6F),
wxColour(0xFF, 0x93, 0x0E),
wxColour(0xC5, 0x00, 0x0D),
wxColour(0x00, 0x84, 0xD1)};
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(0, -1, title, pos, size), _kiss(kiss),
wxUI::wxUI(KissCount* kiss, const QString& title)
: QFrame(0), _kiss(kiss),
_curPanel(0), _locale(0), _needReload(false)
{
wxInitAllImageHandlers();
setWindowTitle(title);
_vbox = new wxBoxSizer(wxVERTICAL);
_buttonsBox = new wxBoxSizer(wxHORIZONTAL);
// ButtonPanel* buttons = new ButtonPanel(_kiss, this);
// wxMenu *menuFile = new wxMenu;
// _vbox = new wxBoxSizer(wxVERTICAL);
// _buttonsBox = new wxBoxSizer(wxHORIZONTAL);
// // ButtonPanel* buttons = new ButtonPanel(_kiss, this);
// // wxMenu *menuFile = new wxMenu;
// menuFile->Append( ID_About, wxT("&About...") );
// menuFile->AppendSeparator();
// menuFile->Append( ID_Quit, wxT("E&xit") );
// // menuFile->Append( ID_About, wxT("&About...") );
// // menuFile->AppendSeparator();
// // menuFile->Append( ID_Quit, wxT("E&xit") );
// wxMenuBar *menuBar = new wxMenuBar;
// menuBar->Append( menuFile, wxT("&File") );
// // wxMenuBar *menuBar = new wxMenuBar;
// // menuBar->Append( menuFile, wxT("&File") );
// SetMenuBar( menuBar );
// // SetMenuBar( menuBar );
// CreateStatusBar();
// SetStatusText( wxT("Welcome to wxWidgets!") );
_buttonsBox->Add(new wxBitmapButton(this, BUTTON_CHANGE_USER_ID, wxBitmap(wxT(CHANGE_USER_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
_buttonsBox->Add(new wxBitmapButton(this, BUTTON_ABOUT_ID, wxBitmap(wxT(ABOUT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
_buttonsBox->Add(new wxBitmapButton(this, BUTTON_QUIT_ID, wxBitmap(wxT(QUIT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
// // CreateStatusBar();
// // SetStatusText( wxT("Welcome to wxWidgets!") );
// _buttonsBox->Add(new wxBitmapButton(this, BUTTON_CHANGE_USER_ID, wxBitmap(wxT(CHANGE_USER_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
// _buttonsBox->Add(new wxBitmapButton(this, BUTTON_ABOUT_ID, wxBitmap(wxT(ABOUT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
// _buttonsBox->Add(new wxBitmapButton(this, BUTTON_QUIT_ID, wxBitmap(wxT(QUIT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
SetSizer(_vbox);
// SetSizer(_vbox);
_vbox->Add(_buttonsBox, 0, wxGROW);
// _vbox->Add(_buttonsBox, 0, wxGROW);
}
wxUI::~wxUI()
{
int i;
for (i=0; i<(int)_panels.size(); i++)
Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this);
// for (i=0; i<(int)_panels.size(); i++)
// Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this);
if (_locale) delete _locale;
}
bool wxUI::SetLanguage(long language)
bool wxUI::SetLanguage(std::string language)
{
bool res = true;
if (_locale) delete _locale;
_locale = 0;
// if (_locale) delete _locale;
// _locale = 0;
// load language if possible, fall back to english otherwise
if(wxLocale::IsAvailable(language))
{
_locale = new wxLocale( language, wxLOCALE_CONV_ENCODING );
// // load language if possible, fall back to english otherwise
// if(wxLocale::IsAvailable(language))
// {
// _locale = new wxLocale( language, wxLOCALE_CONV_ENCODING );
#ifdef __WXGTK__
_locale->AddCatalogLookupPathPrefix(wxT(LANG_ROOT));
#endif
// #ifdef __WXGTK__
// _locale->AddCatalogLookupPathPrefix(wxT(LANG_ROOT));
// #endif
_locale->AddCatalog(wxT("frenchpp"));
_locale->AddCatalog(wxT("kisscount"));
// _locale->AddCatalog(wxT("frenchpp"));
// _locale->AddCatalog(wxT("kisscount"));
_language = (wxLanguage) language;
}
// _language = (wxLanguage) language;
// }
if (_locale == 0 || !_locale->IsOk())
{
if (_locale) delete _locale;
_locale = new wxLocale();
// if (_locale == 0 || !_locale->IsOk())
// {
// if (_locale) delete _locale;
// _locale = new wxLocale();
#ifdef __WXGTK__
_locale->AddCatalogLookupPathPrefix(wxT(LANG_ROOT));
#endif
// #ifdef __WXGTK__
// _locale->AddCatalogLookupPathPrefix(wxT(LANG_ROOT));
// #endif
_locale->AddCatalog(wxT("kisscount"));
// _locale->AddCatalog(wxT("kisscount"));
_language = wxLANGUAGE_ENGLISH;
res = false;
}
// _language = wxLANGUAGE_ENGLISH;
// res = false;
// }
months[0] = _("january");
months[1] = _("february");
months[2] = _("marchpp");
months[3] = _("april");
months[4] = _("may");
months[5] = _("june");
months[6] = _("july");
months[7] = _("august");
months[8] = _("september");
months[9] = _("october");
months[10] = _("november");
months[11] = _("december") ;
// months[0] = _("january");
// months[1] = _("february");
// months[2] = _("marchpp");
// months[3] = _("april");
// months[4] = _("may");
// months[5] = _("june");
// months[6] = _("july");
// months[7] = _("august");
// months[8] = _("september");
// months[9] = _("october");
// months[10] = _("november");
// months[11] = _("december") ;
return res;
}
@@ -160,50 +154,50 @@ bool wxUI::SetLanguage(long language)
void wxUI::InitPanels()
{
KissPanel* panel;
wxBitmapButton* button;
_panels.clear();
// KissPanel* panel;
// wxBitmapButton* button;
// _panels.clear();
ADD_PANEL(AccountPanel, 0);
ADD_PANEL(StatsPanel, 1);
ADD_PANEL(SearchPanel, 2);
ADD_PANEL(PreferencesPanel, 3);
ADD_PANEL(ImportPanel, 4);
ADD_PANEL(ExportPanel, 5);
// ADD_PANEL(AccountPanel, 0);
// ADD_PANEL(StatsPanel, 1);
// ADD_PANEL(SearchPanel, 2);
// ADD_PANEL(PreferencesPanel, 3);
// ADD_PANEL(ImportPanel, 4);
// ADD_PANEL(ExportPanel, 5);
}
void wxUI::LoadPanels()
{
std::vector<KissPanel*>::iterator it;
KissPanel* temp;
int i;
// std::vector<KissPanel*>::iterator it;
// KissPanel* temp;
// int i;
if (_curPanel)
{
_vbox->Detach(_curPanel);
_curPanel = 0;
}
// if (_curPanel)
// {
// _vbox->Detach(_curPanel);
// _curPanel = 0;
// }
if (_panels.size())
{
for (i=0; i<(int)_panels.size(); i++)
{
temp = _panels[i]->CreatePanel();
Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this);
_panels[i] = temp;
Connect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), temp, this);
_buttons[i]->SetToolTip(temp->GetToolTip());
}
}
else
InitPanels();
// if (_panels.size())
// {
// for (i=0; i<(int)_panels.size(); i++)
// {
// temp = _panels[i]->CreatePanel();
// Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this);
// _panels[i] = temp;
// Connect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), temp, this);
// _buttons[i]->SetToolTip(temp->GetToolTip());
// }
// }
// else
// InitPanels();
}
void wxUI::LoadUser()
{
User* user = _kiss->GetUser();
if (user->_preferences[wxT("language")] != wxT(""))
if (user->_preferences["language"].size())
SetLanguage(user->GetLanguage());
LoadPanels();
@@ -214,92 +208,92 @@ void wxUI::LoadUser()
void wxUI::ShowPanel(KissPanel* panel)
{
wxShowEvent event;
int i;
User* user = _kiss->GetUser();
// wxShowEvent event;
// int i;
// User* user = _kiss->GetUser();
if (!panel) return;
// if (!panel) return;
if (_curPanel)
{
_vbox->Detach(_curPanel);
_curPanel->Hide();
}
// if (_curPanel)
// {
// _vbox->Detach(_curPanel);
// _curPanel->Hide();
// }
if (_needReload)
{
user->InvalidateOperations();
for(i=0; i<(int)_panels.size(); i++)
if (_panels[i] == panel) break;
LoadPanels();
_needReload = false;
_curPanel = _panels[i];
}
else
_curPanel = panel;
// if (_needReload)
// {
// user->InvalidateOperations();
// for(i=0; i<(int)_panels.size(); i++)
// if (_panels[i] == panel) break;
// LoadPanels();
// _needReload = false;
// _curPanel = _panels[i];
// }
// else
// _curPanel = panel;
_curPanel->OnShow(event);
_vbox->Add(_curPanel);
_curPanel->Show();
Layout();
// _curPanel->OnShow(event);
// _vbox->Add(_curPanel);
// _curPanel->Show();
// Layout();
}
void wxUI::OnButtonClicked(wxCommandEvent& event)
void wxUI::OnButtonClicked(QEvent& event)
{
ShowPanel(_panels[event.GetId()]);
// ShowPanel(_panels[event.GetId()]);
}
void wxUI::OnButtonChangeUser(wxCommandEvent& event)
void wxUI::OnButtonChangeUser(QEvent& event)
{
ChangeUser();
}
void wxUI::ChangeUser()
{
UsersDialog u(_kiss, this);
// UsersDialog u(_kiss, this);
}
void wxUI::OnButtonAbout(wxCommandEvent& event)
void wxUI::OnButtonAbout(QEvent& event)
{
wxMessageBox( _("Personal accounting software\n\nhttp://indefero.soutade.fr/p/kisscount/\n\nLicenced under GNU GPL v3\n\nCopyright (C) 2010-2011 Grégory Soutadé"),
wxT("KissCount " APP_VERSION "\n\n"),
wxOK | wxICON_INFORMATION, this );
// wxMessageBox( _("Personal accounting software\n\nhttp://indefero.soutade.fr/p/kisscount/\n\nLicenced under GNU GPL v3\n\nCopyright (C) 2010-2011 Grégory Soutadé"),
// wxT("KissCount " APP_VERSION "\n\n"),
// wxOK | wxICON_INFORMATION, this );
}
void wxUI::OnButtonQuit(wxCommandEvent& event)
void wxUI::OnButtonQuit(QEvent& event)
{
wxMessageDialog dialog(this, _("Quit KissCount ?"), wxT("KissCount"), wxYES_NO);
if (dialog.ShowModal() == wxID_NO)
{
return;
}
// wxMessageDialog dialog(this, _("Quit KissCount ?"), wxT("KissCount"), wxYES_NO);
// if (dialog.ShowModal() == wxID_NO)
// {
// return;
// }
Close(true);
// Close(true);
}
void wxUI::GenerateMonth(int month, int year)
{
((AccountPanel*)_panels[0])->GenerateMonth(month, year);
// ((AccountPanel*)_panels[0])->GenerateMonth(month, year);
}
void wxUI::KillMe()
{
std::vector<KissPanel*>::iterator it;
// std::vector<KissPanel*>::iterator it;
if (_curPanel)
{
_vbox->Detach(_curPanel);
_curPanel = 0;
}
// if (_curPanel)
// {
// _vbox->Detach(_curPanel);
// _curPanel = 0;
// }
for (it=_panels.begin(); it!= _panels.end(); it++)
{
if (*it) delete *it;
_buttonsBox->Remove(0);
_buttons.erase(_buttons.begin());
}
// for (it=_panels.begin(); it!= _panels.end(); it++)
// {
// if (*it) delete *it;
// _buttonsBox->Remove(0);
// _buttons.erase(_buttons.begin());
// }
_panels.clear();
// _panels.clear();
}
void wxUI::NeedReload()

View File

@@ -22,32 +22,35 @@
class ImportEngine;
#include <wx/wx.h>
#include <QFrame>
#include <QLocale>
#include <QVBoxLayout>
#include <QScrollArea>
#include <QPushButton>
#include <controller/KissCount.hpp>
#include "KissPanel.hpp"
#include <qtranslator.h>
#include <qtextcodec.h>
#ifdef WIN32
#undef _
#define _(s) wxString(wxGetTranslation(s))
#endif
#define _(s) QObject::tr(s)
class KissCount;
class KissPanel;
class AccountPanel;
class PreferencesPanel;
class wxUI: public wxFrame
class wxUI: public QFrame
{
public:
static const int MAX_CATEGORY = 12;
static wxString months[MAX_CATEGORY];
static wxColour categoryColors[MAX_CATEGORY];
static std::string months[MAX_CATEGORY];
static QColor categoryColors[MAX_CATEGORY];
wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size);
wxUI(KissCount* kiss, const QString& title);
~wxUI();
bool SetLanguage(long language);
bool SetLanguage(std::string language);
void ChangeUser();
void LoadUser();
@@ -62,26 +65,45 @@ public:
void ShowPanel(KissPanel* panel);
void NeedReload();
wxLanguage _language;
int _language;
void OnButtonClicked(wxCommandEvent& event);
void OnButtonChangeUser(wxCommandEvent& event);
void OnButtonAbout(wxCommandEvent& event);
void OnButtonQuit(wxCommandEvent& event);
void OnButtonClicked(QEvent& event);
void OnButtonChangeUser(QEvent& event);
void OnButtonAbout(QEvent& event);
void OnButtonQuit(QEvent& event);
private:
KissCount *_kiss;
wxBoxSizer *_vbox, *_buttonsBox;
QVBoxLayout *_vbox, *_buttonsBox;
KissPanel *_curPanel;
std::vector<KissPanel*> _panels;
std::vector<wxBitmapButton*> _buttons;
wxLocale *_locale;
std::vector<QPushButton*> _buttons;
QLocale *_locale;
bool _needReload;
void InitPanels();
void LoadPanels();
};
DECLARE_EVENT_TABLE();
class KissPanel: public QScrollArea
{
public:
KissPanel(KissCount* kiss, wxUI* parent) :
QScrollArea(static_cast<QWidget*>(parent)),
_kiss(kiss),
_wxUI(parent),
_KissButton(0)
{hide();}
virtual void OnShow(QShowEvent * event)=0;
virtual KissPanel* CreatePanel()=0;
virtual QPushButton* GetButton(int id) {return 0;}
virtual std::string GetToolTip() {return "";}
protected:
KissCount* _kiss;
wxUI* _wxUI;
QPushButton* _KissButton;
};
#endif