From 2c56271e1b9220a2121ff350ee1cb7a001b2ceba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 13 Mar 2011 19:15:21 +0100 Subject: [PATCH] Temp commit --- Makefile | 35 ++++++++++++++++---------- src/controller/KissCount.cpp | 47 ++++++++++++++++++++++++++++++++++- src/controller/KissCount.h | 9 +++++++ src/model/Database.h | 2 +- src/model/model.h | 8 +++--- src/view/grid/GridAccount.cpp | 18 +++++++++++--- src/view/grid/GridAccount.h | 8 ++++-- src/view/wxUI.cpp | 1 + src/view/wxUI.h | 3 +++ 9 files changed, 106 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 314290c..333d0e7 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ CXXFLAGS+=-DRESSOURCES_ROOT="\"$(SHARE_DIR)\"" #CXXFLAGS+=-DRESSOURCES_ROOT="\"./ressources/\"" LDFLAGS+=`wx-config --libs` +LDFLAGS+=-lofx + 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 @@ -21,25 +23,32 @@ endif CXX=$(PREFIX)g++ -SOURCES=$(wildcard src/model/*.cpp) -SOURCES+=$(wildcard src/view/*.cpp) -SOURCES+=$(wildcard src/view/grid/*.cpp) -SOURCES+=$(wildcard src/controller/*.cpp) -SOURCES+=src/main.cpp src/sha1.cpp src/ParseExp.cpp -HEADERS=$(wildcard src/model/*.h) -HEADERS+=$(wildcard src/view/*.h) -HEADERS+=$(wildcard src/view/grid/*.h) -HEADERS+=$(wildcard src/controller/*.h) -HEADERS+=src/main.h src/sha1.h +# SOURCES=$(wildcard src/model/*.cpp) +# SOURCES+=$(wildcard src/model/import/*.cpp) +# SOURCES+=$(wildcard src/model/export/*.cpp) +# SOURCES+=$(wildcard src/view/*.cpp) +# SOURCES+=$(wildcard src/view/grid/*.cpp) +# SOURCES+=$(wildcard src/controller/*.cpp) +# SOURCES+=$(wildcard src/*.cpp) +SOURCES=$(shell find src -name '*.cpp' -type f | tr '\n' ' ') +# HEADERS=$(wildcard src/model/*.h) +# HEADERS+=$(wildcard src/model/import/*.h) +# HEADERS+=$(wildcard src/model/export/*.h) +# HEADERS+=$(wildcard src/view/*.h) +# HEADERS+=$(wildcard src/view/grid/*.h) +# HEADERS+=$(wildcard src/controller/*.h) +# HEADERS+=$(wildcard src/*.h) +HEADERS=$(shell find src -name '*.h' -type f) OBJS=$(SOURCES:.cpp=.o) all: check kc clean: - rm -f *~ src/*~ src/*.o src/model/*.o src/model/*~ src/view/*.o src/view/grid/*.o src/view/grid/*~ src/view/*~ src/controller/*.o src/controller/*~ kc + find src -type f -name '*.[o~]' -exec rm -f \{\} \; + rm -f kc -%.o : src/model/%.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 + $(CXX) $(CXXFLAGS) -c $< check: if ! test -d lib ; then echo lib directory not found, please see INSTALL ; return 1 ; fi diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 75648dc..f2a0449 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -19,6 +19,8 @@ #include "KissCount.h" +std::vector KissCount::_importEngines; + KissCount::KissCount(const char* bdd_filename) : _user(NULL) { wxRect rect = wxDisplay().GetGeometry(); @@ -40,7 +42,7 @@ KissCount::KissCount(const char* bdd_filename) : _user(NULL) _wxUI->Close(true); throw s; } - + _wxUI->ChangeUser(); _wxUI->Enable(); } @@ -561,3 +563,46 @@ wxString KissCount::CompactFont(const wxFont& font) return res; } + +void KissCount::UnRegisterImportEngine(ImportEngine* engine) +{ + std::vector::iterator it; + + for(it=_importEngines.begin(); it!=_importEngines.end(); it++) + if (*it == engine) + { + _importEngines.erase(it); + break; + } +} + +void KissCount::RegisterImportEngine(ImportEngine* engine) +{ + _importEngines.push_back(engine); +} + +wxString KissCount::GetImportEngineExtensions() +{ + wxString res; + std::vector::iterator it; + int i; + + for(i=0; i<(int)_importEngines.size()-1; i++) + res = res + _importEngines[i]->GetFileExt() + wxT("|") ; + + if (_importEngines.size()) + res = res + _importEngines[i]->GetFileExt(); + + return res; +} + +ImportEngine* KissCount::GetImportEngine(wxString path) +{ + std::vector::iterator it; + + for(it=_importEngines.begin(); it!=_importEngines.end(); it++) + if ((*it)->HandleFile(path, _user, _db)) + return *it; + + return NULL; +} diff --git a/src/controller/KissCount.h b/src/controller/KissCount.h index 9614bd7..5c8b241 100644 --- a/src/controller/KissCount.h +++ b/src/controller/KissCount.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -33,6 +34,7 @@ class wxUI; class Database; +class ImportEngine; class KissCount { @@ -102,10 +104,17 @@ public: static wxFont ExtractFont(wxString strFont); static wxString CompactFont(const wxFont& font); + static void RegisterImportEngine(ImportEngine* engine); + static void UnRegisterImportEngine(ImportEngine* engine); + + wxString GetImportEngineExtensions(); + ImportEngine* GetImportEngine(wxString path); + private: wxUI* _wxUI; Database* _db; User* _user; + static std::vector _importEngines; }; #endif diff --git a/src/model/Database.h b/src/model/Database.h index 2126190..0d64f1f 100644 --- a/src/model/Database.h +++ b/src/model/Database.h @@ -30,8 +30,8 @@ #include #include -#include "model.h" #include "../controller/KissCount.h" +#include "model.h" #define DATABASE_VERSION 2 diff --git a/src/model/model.h b/src/model/model.h index e3dcf33..4d11dc9 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -25,9 +25,9 @@ class Database; class Account; class Operation; -#include "User.h" -#include "Database.h" -#include "Account.h" -#include "Operation.h" +#include +#include +#include +#include #endif diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 558b597..b3a79a7 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -43,10 +43,13 @@ enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, C enum {GRID_ID}; -GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxGrid(parent, id), _fixCosts(0), _week1(0), - _week2(0), _week3(0), _week4(0), _parent(parent), _kiss(kiss), - _loadOperations(false), - _curMonth(0), _curYear(0) +GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id, + bool canAddOperation, bool setWeek, bool synchronizeWithDatabase) + : wxGrid(parent, id), _fixCosts(0), _week1(0), + _week2(0), _week3(0), _week4(0), _parent(parent), _kiss(kiss), + _canAddOperation(canAddOperation), _setWeek(setWeek), + _databaseSynchronization(synchronizeWithDatabase), _loadOperations(false), + _curMonth(0), _curYear(0) { wxBitmap deleteBitmap(wxT(DELETE_ICON), wxBITMAP_TYPE_PNG); wxBitmap checkedBitmap(wxT(CHECKED_ICON), wxBITMAP_TYPE_PNG); @@ -174,6 +177,13 @@ int GridAccount::GetDisplayedRow(const wxString& id) return -1; } +void GridAccount::ClearGrid() +{ + std::vector operations; + + LoadOperations(&operations, false, false, 0, 0); +} + void GridAccount::LoadOperations(std::vector* operations, bool canAddOperation, bool setWeek, int month, int year) { std::vector::iterator it; diff --git a/src/view/grid/GridAccount.h b/src/view/grid/GridAccount.h index 6130d51..1533290 100644 --- a/src/view/grid/GridAccount.h +++ b/src/view/grid/GridAccount.h @@ -41,13 +41,15 @@ typedef void (*updateOperationFunc)(Operation* op, void** params); class GridAccount : public wxGrid { public: - GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id); + GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id, + bool canAddOperation, bool setWeek, bool synchronizeWithDatabase); ~GridAccount(); wxPen GetColGridLinePen (int col); wxPen GetRowGridLinePen (int row); - void LoadOperations(std::vector* operations, bool canAddOperation, bool setWeek, int month, int year); + virtual void ClearGrid(); + void LoadOperations(std::vector* 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) ; @@ -69,6 +71,8 @@ private: wxWindow* _parent; KissCount* _kiss; bool _displayLines; + bool _canAddOperation, setWeek; + bool _databaseSynchronization; wxString* _categories, *_accounts; std::vector* _operations; bool _canAddOperation, _loadOperations; diff --git a/src/view/wxUI.cpp b/src/view/wxUI.cpp index 59c78ee..b6b2663 100644 --- a/src/view/wxUI.cpp +++ b/src/view/wxUI.cpp @@ -154,6 +154,7 @@ void wxUI::InitPanels() ADD_PANEL(StatsPanel, 1); ADD_PANEL(SearchPanel, 2); ADD_PANEL(PreferencesPanel, 3); + ADD_PANEL(ImportPanel, 4); } void wxUI::LoadPanels() diff --git a/src/view/wxUI.h b/src/view/wxUI.h index 8c3376f..e7c8c52 100644 --- a/src/view/wxUI.h +++ b/src/view/wxUI.h @@ -20,6 +20,8 @@ #ifndef WXUI_H #define WXUI_H +class ImportEngine; + #include #include "AccountPanel.h" #include "PreferencesPanel.h" @@ -27,6 +29,7 @@ #include "GenerateDialog.h" #include "SearchPanel.h" #include "StatsPanel.h" +#include "ImportPanel.h" #include #include "grid/wxMyGrid.h" #include "grid/wxGridCellFastBoolEditor.h"