X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fhomebank.c;h=60e87c88650dbc4ccc7bc0329cec3e07db271bf4;hb=35b9973e4de7d69ad8841ead996a2e6cf1d85f08;hp=421d0eff7a45fe62367dad4fc9493503a1e43af9;hpb=59c5e08a64798d4303ae7eb3a2713bc93d98fa7b;p=chaz%2Fhomebank diff --git a/src/homebank.c b/src/homebank.c index 421d0ef..60e87c8 100644 --- a/src/homebank.c +++ b/src/homebank.c @@ -1,5 +1,5 @@ /* HomeBank -- Free, easy, personal accounting for everyone. - * Copyright (C) 1995-2016 Maxime DOYEN + * Copyright (C) 1995-2018 Maxime DOYEN * * This file is part of HomeBank. * @@ -17,20 +17,22 @@ * along with this program. If not, see . */ + #include "homebank.h" +#include "ext.h" #include "dsp_mainwindow.h" #include "hb-preferences.h" #include "language.h" - #ifdef G_OS_WIN32 #include #endif #define APPLICATION_NAME "HomeBank" + /****************************************************************************/ /* Debug macros */ /****************************************************************************/ @@ -54,6 +56,7 @@ static gchar *pixmaps_dir = NULL; static gchar *locale_dir = NULL; static gchar *help_dir = NULL; static gchar *datas_dir = NULL; +static gchar *pkglib_dir = NULL; //#define MARKUP_STRING "%s" @@ -106,7 +109,7 @@ static gint csvtype[7] = { { g_io_channel_set_encoding(io, NULL, NULL); /* set to binary mode */ - for(i=0;i<4;i++) + for(i=0;i<25;i++) { if( retval != FILETYPE_UNKNOW ) break; @@ -140,7 +143,7 @@ static gint csvtype[7] = { g_str_has_prefix(tmpstr, "!option") || g_str_has_prefix(tmpstr, "!Account") || g_str_has_prefix(tmpstr, "!account") - ) + ) { DB( g_print(" type is QIF\n") ); retval = FILETYPE_QIF; @@ -148,7 +151,10 @@ static gint csvtype[7] = { else /* is it OFX ? */ - if( g_strstr_len(tmpstr, 10, "OFX") != NULL) + if( g_strstr_len(tmpstr, -1, "") != NULL + || g_strstr_len(tmpstr, -1, "") != NULL + /*|| strcasestr(tmpstr, "") != NULL*/ + ) { DB( g_print(" type is OFX\n") ); retval = FILETYPE_OFX; @@ -199,7 +205,7 @@ void homebank_file_ensure_xhb(gchar *filename) { gchar *newfilename; - newfilename = hb_util_filename_new_with_extension(filename, "xhb"); + newfilename = hb_filename_new_with_extension(filename, "xhb"); hbfile_change_filepath(newfilename); DB( g_print(" - changed to: '%s'\n", GLOBALS->xhb_filepath) ); } @@ -211,13 +217,15 @@ void homebank_file_ensure_xhb(gchar *filename) } -static gboolean homebank_copy_file(gchar *srcfile, gchar *dstfile) +static gboolean homebank_file_copy(gchar *srcfile, gchar *dstfile) { gchar *buffer; gsize length; //GError *error = NULL; gboolean retval = FALSE; + DB( g_print("\n[homebank] file copy\n") ); + if (g_file_get_contents (srcfile, &buffer, &length, NULL)) { if(g_file_set_contents(dstfile, buffer, length, NULL)) @@ -226,32 +234,46 @@ gboolean retval = FALSE; } g_free(buffer); } + + DB( g_print(" - copied '%s' => '%s' :: %d\n", srcfile, dstfile, retval) ); return retval; } -void homebank_backup_current_file(void) +static gboolean homebank_file_delete_existing(gchar *filepath) { -gchar *bakfilename; +gboolean retval = FALSE; - DB( g_print("\n[homebank] backup_current_file\n") ); + DB( g_print("\n[homebank] file delete existing\n") ); - bakfilename = hb_util_filename_new_with_extension (GLOBALS->xhb_filepath, "xhb~"); - if( g_file_test(bakfilename, G_FILE_TEST_EXISTS) ) + if( g_file_test(filepath, G_FILE_TEST_EXISTS) ) { - DB( g_print(" - delete existing: '%s'\n", bakfilename) ); - g_remove(bakfilename); + g_remove(filepath); + retval = TRUE; } - DB( g_print(" - copy '%s' => '%s'\n", GLOBALS->xhb_filepath, bakfilename) ); + DB( g_print(" - deleted: '%s' :: %d\n", filepath, retval) ); + return retval; +} + + +void homebank_backup_current_file(void) +{ +gchar *bakfilename; + + DB( g_print("\n[homebank] backup_current_file\n") ); + //do normal linux backup file + DB( g_print(" normal backup with ~\n") ); + bakfilename = hb_filename_new_with_extension (GLOBALS->xhb_filepath, "xhb~"); + homebank_file_delete_existing(bakfilename); //#512046 copy file not to broke potential links //retval = g_rename(pathname, newname); - homebank_copy_file (GLOBALS->xhb_filepath, bakfilename); - + homebank_file_copy (GLOBALS->xhb_filepath, bakfilename); g_free(bakfilename); } + /* = = = = = = = = = = = = = = = = = = = = */ /* url open */ @@ -330,43 +352,29 @@ homebank_util_url_show (const gchar *url) /* ** load lastopenedfiles from homedir/.homebank */ -gboolean homebank_lastopenedfiles_load(void) +gchar *homebank_lastopenedfiles_load(void) { GKeyFile *keyfile; -gboolean retval = FALSE; -gchar *group, *filename, *lastfilename; +gchar *group, *filename, *tmpfilename; +gchar *lastfilename = NULL; DB( g_print("\n[homebank] lastopenedfiles load\n") ); keyfile = g_key_file_new(); if(keyfile) { - filename = g_build_filename(homebank_app_get_config_dir(), "lastopenedfiles", NULL ); - - DB( g_print(" - filename: %s\n", filename) ); - if(g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL)) { group = "HomeBank"; - DB( g_print(" - load keyfile ok\n") ); - if(g_key_file_has_key(keyfile, group, "LastOpenedFile", NULL)) { - DB( g_print(" - keyfile has key ok\n") ); - - lastfilename = g_key_file_get_string (keyfile, group, "LastOpenedFile", NULL); - - DB( g_print(" - lastfile loaded: %s\n", lastfilename ) ); + tmpfilename = g_key_file_get_string (keyfile, group, "LastOpenedFile", NULL); // #593082 - if (g_file_test (lastfilename, G_FILE_TEST_EXISTS) != FALSE) + if (g_file_test (tmpfilename, G_FILE_TEST_EXISTS) != FALSE) { - DB( g_print(" - file exists\n") ); - - hbfile_change_filepath(lastfilename); - - retval = TRUE; + lastfilename = tmpfilename; } } } @@ -374,9 +382,7 @@ gchar *group, *filename, *lastfilename; g_key_file_free (keyfile); } - DB( g_print(" - return: %d\n", retval) ); - - return retval; + return lastfilename; } @@ -559,6 +565,12 @@ homebank_app_get_datas_dir (void) return datas_dir; } +const gchar * +homebank_app_get_pkglib_dir (void) +{ + return pkglib_dir; +} + /* build package paths at runtime */ static void @@ -575,6 +587,7 @@ build_package_paths (void) pixmaps_dir = g_build_filename (prefix, "share", PACKAGE, "icons", NULL); help_dir = g_build_filename (prefix, "share", PACKAGE, "help", NULL); datas_dir = g_build_filename (prefix, "share", PACKAGE, "datas", NULL); + pkglib_dir = g_build_filename (prefix, "lib", PACKAGE, NULL); #ifdef PORTABLE_APP DB( g_print(" - app is portable under windows\n") ); config_dir = g_build_filename(prefix, "config", NULL); @@ -588,6 +601,7 @@ build_package_paths (void) pixmaps_dir = g_build_filename (DATA_DIR, PACKAGE, "icons", NULL); help_dir = g_build_filename (DATA_DIR, PACKAGE, "help", NULL); datas_dir = g_build_filename (DATA_DIR, PACKAGE, "datas", NULL); + pkglib_dir = g_build_filename (PKGLIB_DIR, NULL); config_dir = g_build_filename(g_get_user_config_dir(), HB_DATA_PATH, NULL); //#870023 Ubuntu packages the help files in "/usr/share/doc/homebank-data/help/" for some strange reason @@ -604,6 +618,7 @@ build_package_paths (void) DB( g_print(" - locale_dir : %s\n", locale_dir) ); DB( g_print(" - help_dir : %s\n", help_dir) ); DB( g_print(" - datas_dir : %s\n", datas_dir) ); + DB( g_print(" - pkglib_dir : %s\n", pkglib_dir) ); } @@ -745,6 +760,7 @@ static void homebank_cleanup() g_free (pixmaps_dir); g_free (locale_dir); g_free (help_dir); + g_free (pkglib_dir); } @@ -875,7 +891,7 @@ homebank_init_i18n (void) int -main (int argc, char *argv[]) +main (int argc, char *argv[], char *env[]) { GOptionContext *option_context; GOptionGroup *option_group; @@ -947,6 +963,22 @@ gboolean openlast; /* change the locale if a language is specified */ language_init (PREFS->language); + DB( g_print(" - loading plugins\n") ); + ext_init(&argc, &argv, &env); + + GList* it; + for (it = PREFS->ext_whitelist; it; it = g_list_next(it)) { + ext_load_plugin(it->data); + } + + gchar** plugins = ext_list_plugins(); + gchar** plugins_it; + for (plugins_it = plugins; *plugins_it; ++plugins_it) { + gboolean loaded = ext_is_plugin_loaded(*plugins_it); + g_print("found plugin: %s, loaded: %d\n", *plugins_it, loaded); + } + g_strfreev(plugins); + if( PREFS->showsplash == TRUE ) { splash = homebank_construct_splash(); @@ -965,6 +997,9 @@ gboolean openlast; mainwin = (GtkWidget *)create_hbfile_window (NULL); + GValue mainwin_val = G_VALUE_INIT; + ext_hook("create_main_window", EXT_OBJECT(&mainwin_val, mainwin), NULL); + if(mainwin) { @@ -1038,21 +1073,51 @@ gboolean openlast; if( openlast ) { - if( homebank_lastopenedfiles_load() == TRUE ) + gchar *lastfilepath; + + lastfilepath = homebank_lastopenedfiles_load(); + if( lastfilepath != NULL ) + { + //#1710955 test for backup open + if( hbfile_file_isbackup(lastfilepath) ) + { + if( ui_mainwindow_open_backup_check_confirm(lastfilepath) == TRUE ) + { + GLOBALS->hbfile_is_bak = TRUE; + } + else + { + g_free(lastfilepath); + goto nobak; + } + } + + hbfile_change_filepath(lastfilepath); ui_mainwindow_open_internal(mainwin, NULL); + + } } /* -- hack to generate a big file -- */ - +nobak: /* update the mainwin display */ ui_mainwindow_update(mainwin, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE+UF_VISUAL)); - DB( g_print(" - gtk_main()\n" ) ); + ext_hook("enter_main_loop", NULL); + DB( g_print(" - gtk_main()\n" ) ); gtk_main (); + + ext_hook("exit_main_loop", NULL); + + DB( g_print(" - call destroy mainwin\n" ) ); + gtk_widget_destroy(mainwin); } + DB( g_print(" - unloading plugins\n") ); + ext_term(); + }