Projekt

Allgemein

Profil

Herunterladen (4,37 KB) Statistiken
| Zweig: | Markierung: | Revision:
/****************************************************************************
* This file is part of the project AqFinance.
* AqFinance (c) by 2009 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif



#include "ff_app.hpp"
#include "ff_modulemanager.hpp"
#include "bankaccounts/fm_bankaccounts.hpp"
#include "transfers/fm_transfers.hpp"
#include "outbox/fm_outbox.hpp"
#include "accounts/fm_accounts.hpp"
#include "partners/fm_partners.hpp"
#include "business/fm_business.hpp"
#include "mainwindow.hpp"

#include <aqbanking/abgui.h>

#include <gwen-gui-fox16/fox16_gui.hpp>

#include <gwenhywfar/configmgr.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/directory.h>
#include <gwenhywfar/gwenhywfarapi.h>
#include <gwenhywfar/debug.h>


#define AQFINANCE_USERDATADIR ".aqfinance"



#include <aqbanking/dlg_importer.h>


static FXString g_dataFolder;



static void _determineDataFolder(const char *dname) {
char home[256];

if (GWEN_Directory_GetHomeDirectory(home, sizeof(home))) {
DBG_ERROR(0,
"Could not determine home directory, aborting.");
abort();
}

if (dname) {
/* setup data dir */
g_dataFolder=FXString(dname);
}
else {
const char *s;
GWEN_BUFFER *buf;

buf=GWEN_Buffer_new(0, 256, 0, 1);
s=getenv("AQFINANCE_HOME");
if (s && !*s)
s=0;
if (s)
GWEN_Buffer_AppendString(buf, s);
else {
/* use default */
GWEN_Buffer_AppendString(buf, home);
GWEN_Buffer_AppendString(buf, GWEN_DIR_SEPARATOR_S AQFINANCE_USERDATADIR);
}

/* as we are at it: store default data dir */
g_dataFolder=FXString(GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
}
}



static GWEN_CONFIGMGR *_getConfigManager() {
GWEN_BUFFER *buf;
GWEN_CONFIGMGR *cm;

buf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendString(buf, "dir://");
GWEN_Buffer_AppendString(buf, g_dataFolder.text());
GWEN_Buffer_AppendString(buf, GWEN_DIR_SEPARATOR_S "settings");

cm=GWEN_ConfigMgr_Factory(GWEN_Buffer_GetStart(buf));
if (cm==NULL) {
DBG_ERROR(0,
"Could not create ConfigMgr[%s]. "
"Maybe the gwenhywfar plugins are not installed?",
GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return NULL;
}

/* done */
GWEN_Buffer_free(buf);
return cm;
}



int main(int argc, char **argv) {
FF_App app("AqFinance", "Martin Preuss");
FOX16_Gui *gui;
GWEN_CONFIGMGR *cm;
MainWindow *mw;
FF_Module *m;
FXString lf;
AB_BANKING *ab;
int rv;

AE_Init();
app.init(argc, argv);

_determineDataFolder(NULL);
cm=_getConfigManager();
if (cm==NULL)
return 2;
app.setConfigMgr(cm);

ab=AB_Banking_new("AqFinance", NULL, 0);
app.setBanking(ab);

mw=new MainWindow(&app, "AqFinance", NULL, NULL, DECOR_ALL);
app.create();

/* create GUI */
gui=new FOX16_Gui(&app);
/* add handling of certificate cache using AqBanking shared data */
AB_Gui_Extend(gui->getCInterface(), ab);
GWEN_Gui_SetGui(gui->getCInterface());

rv=AB_Banking_Init(ab);
if (rv<0) {
DBG_ERROR(0, "Error initializing AqBanking (%d)", rv);
}
else {
rv=AB_Banking_OnlineInit(ab, 0);
if (rv<0) {
DBG_ERROR(0, "Error initializing online-part of AqBanking (%d)", rv);
app.setBanking(NULL);
}
}

mw->openConfig();

/* add modules */
m=new FM_BankAccounts(app.getModuleManager());
app.getModuleManager()->addModule(m);

m=new FM_Accounts(app.getModuleManager());
app.getModuleManager()->addModule(m);

m=new FM_Partners(app.getModuleManager());
app.getModuleManager()->addModule(m);

m=new FM_Transfers(app.getModuleManager());
app.getModuleManager()->addModule(m);

m=new FM_Business(app.getModuleManager());
app.getModuleManager()->addModule(m);

m=new FM_Outbox(app.getModuleManager());
app.getModuleManager()->addModule(m);

mw->show();

lf=mw->getLastOpened();
if (!lf.empty())
mw->openDb(lf);

app.run();
app.fini();

rv=AB_Banking_OnlineFini(ab, 0);
if (rv<0) {
DBG_ERROR(0, "Error deinitializing online-part of AqBanking (%d)", rv);
}
rv=AB_Banking_Fini(ab);
if (rv<0) {
DBG_ERROR(0, "Error deinitializing AqBanking (%d)", rv);
}
AB_Banking_free(ab);

return 0;
}

(4-4/6)