174 lines
5.8 KiB
C++
174 lines
5.8 KiB
C++
/*
|
|
Copyright 2010-2016 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 KISSCOUNT_H
|
|
#define KISSCOUNT_H
|
|
|
|
#include <list>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <model/import/ImportEngine.hpp>
|
|
#include <model/export/ExportEngine.hpp>
|
|
#include <model/model.hpp>
|
|
|
|
#include <view/wxUI.hpp>
|
|
|
|
#define APP_VERSION "0.8"
|
|
|
|
#define ESCAPE_CHARS(s) s = s.replace("\"", " ");
|
|
// #define ESCAPE_CHARS(s) s = s.replace("\"", "\\\""); s = s.replace("\'", "\\\'");
|
|
/*{ \
|
|
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) s = s.replace("\\\"", " ");
|
|
// #define UNESCAPE_CHARS(s) s = s.replace("\\\"", "\""); s = s.replace("\\\'", "\'");
|
|
/*{ \
|
|
s.Replace(wxT("\\\""), wxT("\""), true); \
|
|
s.Replace(wxT("\\\'"), wxT("\'"), true); \
|
|
}
|
|
*/
|
|
class wxUI;
|
|
class Database;
|
|
class ImportEngine;
|
|
class ExportEngine;
|
|
|
|
class KissCount : public QApplication
|
|
{
|
|
public:
|
|
KissCount(int& argc, char** argv);
|
|
~KissCount();
|
|
|
|
std::list<QString> GetUsers();
|
|
bool IsValidUser(const QString& user, const QString& password);
|
|
void LoadUser(const QString& user);
|
|
User* GetUser();
|
|
void ChangePassword(const QString& password);
|
|
bool UserExists(const QString& name);
|
|
void ChangeName(const QString& name);
|
|
void NewUser(const QString& name);
|
|
|
|
void LoadYear(int year, bool force=false);
|
|
|
|
int AddOperation(Operation& op, bool checkTransfert=true);
|
|
void UpdateOperation(Operation& op, bool checkTransfert=true);
|
|
void DeleteOperation(Operation& op);
|
|
void DeleteOperations(int month, int year);
|
|
int MetaAmount(int id);
|
|
int MetaPositiveAmount(int id);
|
|
|
|
int GetAccountAmount(int id, int month, int year, bool* had_values=0, bool create_if_not_exsits=true);
|
|
void SetAccountAmount(int accountId, int month, int year, int value);
|
|
int CalcAccountAmount(int id, int month, int year, bool* had_values);
|
|
|
|
int AddAccount(Account& ac);
|
|
void UpdateAccount(Account& ac);
|
|
void DeleteAccount(Account& ac, int replacement);
|
|
void AddSharedAccount(Account& ac, const QString& granted);
|
|
void RemoveSharedAccount(Account& ac, int granted);
|
|
std::map<QString, QString> getSharedAccountOwners(int account);
|
|
QString getSharedAccountOwner(int account);
|
|
|
|
int AddCategory(Category& category);
|
|
void UpdateCategory(Category& category);
|
|
void DeleteCategory(Category& category, int replacement);
|
|
|
|
int AddTag(Tag& tag);
|
|
void UpdateTag(Tag& tag);
|
|
void DeleteTag(Tag& tag, int replacement);
|
|
|
|
std::map<int, std::vector<int> > GetAllOperations();
|
|
|
|
int GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
|
|
void KillMe();
|
|
|
|
void SetLanguage(QString language);
|
|
QString GetLanguage(void);
|
|
void SetAccountLimitValue(int limit);
|
|
void SetAccountLimitColor(QColor& color);
|
|
int GetAccountLimitValue(void);
|
|
QColor GetAccountLimitColor(void);
|
|
void SetOperationOrder(const QString& order);
|
|
const QString& GetOperationOrder();
|
|
|
|
std::vector<Operation>* Search(QString* description, QDate* dateFrom, QDate* dateTo,
|
|
int* amountFrom, int* amountTo,
|
|
std::vector<int> categories,
|
|
int types, std::vector<int> accounts, std::vector<int> tags);
|
|
|
|
bool SearchPreviousOperation(Operation* res, Operation& op, int month, int year, bool limitToType, int index);
|
|
|
|
void GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo,
|
|
std::map<int, std::map<int, std::map<int, int> > >* accountAmounts,
|
|
std::map<int, int>* categories, std::map<int, int>* tags);
|
|
|
|
void GetMonthStats(int month, int year, int nbDays,
|
|
std::map<int, std::vector<int> >* operations,
|
|
std::map<int, int>* categories, std::map<int, int>* tags);
|
|
void UpdateStats();
|
|
|
|
std::map<int, int>* GetNotChecked(int month, int year);
|
|
std::map<int, int>* GetVirtualAmount(int month, int year);
|
|
|
|
static QFont ExtractFont(QString);
|
|
static QString CompactFont(const QFont& font);
|
|
|
|
static void RegisterImportEngine(ImportEngine* engine);
|
|
static void UnRegisterImportEngine(ImportEngine* engine);
|
|
|
|
QString GetImportEngineExtensions();
|
|
ImportEngine* GetImportEngine(QString path);
|
|
|
|
static void RegisterExportEngine(ExportEngine* engine);
|
|
static void UnRegisterExportEngine(ExportEngine* engine);
|
|
|
|
QString GetExportEngineExtensions();
|
|
ExportEngine* GetExportEngine(QString path, QString filter);
|
|
|
|
void UpdateImportPattern();
|
|
|
|
void GetHistory(int month, int year, QStringList& list);
|
|
|
|
bool ChangeDatabase(QString filename);
|
|
|
|
QLocale* GetLocale();
|
|
QString GetDateLocalFormat();
|
|
QString FormatDate(int day, int month, int year);
|
|
|
|
private:
|
|
wxUI* _wxUI;
|
|
Database* _db;
|
|
User* _user;
|
|
|
|
static std::vector<ImportEngine*> *GetImportEngines();
|
|
static std::vector<ExportEngine*> *GetExportEngines();
|
|
|
|
static std::vector<ImportEngine*> *_importEngines;
|
|
static std::vector<ExportEngine*> *_exportEngines;
|
|
|
|
int CopyGeneratedOperation(int monthTo, int yearTo, Operation& opOrig, Operation& opDest,
|
|
std::map<int, int> &meta, QRegularExpression *regexp);
|
|
};
|
|
|
|
#endif
|