X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank;a=blobdiff_plain;f=src%2Fhb-hbfile.c;h=19b5a431ac0413f3d706b3a627767b379ca61b11;hp=adfaa8e5dcf36d14275ef5049e5ab360efbb1c72;hb=HEAD;hpb=996fa4ab9f6b836001f8ad0eecbfd3821687fea7 diff --git a/src/hb-hbfile.c b/src/hb-hbfile.c index adfaa8e..19b5a43 100644 --- a/src/hb-hbfile.c +++ b/src/hb-hbfile.c @@ -1,5 +1,5 @@ /* HomeBank -- Free, easy, personal accounting for everyone. - * Copyright (C) 1995-2016 Maxime DOYEN + * Copyright (C) 1995-2019 Maxime DOYEN * * This file is part of HomeBank. * @@ -22,6 +22,7 @@ #include "hb-archive.h" #include "hb-transaction.h" + /****************************************************************************/ /* Debug macros */ /****************************************************************************/ @@ -41,18 +42,68 @@ extern struct Preferences *PREFS; /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/ -gboolean hbfile_file_hasbackup(gchar *filepath) +gboolean hbfile_file_isbackup(gchar *filepath) +{ +gboolean retval = FALSE; + + if( filepath == NULL ) + return FALSE; + + if( g_str_has_suffix(filepath, "xhb~") || g_str_has_suffix(filepath, "bak") ) + retval = TRUE; + + return retval; +} + + +gboolean hbfile_file_hasrevert(gchar *filepath) { gchar *bakfilepath; - bakfilepath = hb_util_filename_new_with_extension(GLOBALS->xhb_filepath, "xhb~"); - GLOBALS->xhb_hasbak = g_file_test(bakfilepath, G_FILE_TEST_EXISTS); + bakfilepath = hb_filename_new_with_extension(GLOBALS->xhb_filepath, "xhb~"); + GLOBALS->xhb_hasrevert = g_file_test(bakfilepath, G_FILE_TEST_EXISTS); g_free(bakfilepath); //todo check here if need to return something - return GLOBALS->xhb_hasbak; + return GLOBALS->xhb_hasrevert; +} + + +//#1750161 +guint64 hbfile_file_get_time_modified(gchar *filepath) +{ +guint64 retval = 0ULL; +GFile *gfile; +GFileInfo *gfileinfo; + + DB( g_print("\n[hbfile] get time modified\n") ); + + gfile = g_file_new_for_path(filepath); + gfileinfo = g_file_query_info (gfile, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL); + if( gfileinfo ) + { + retval = g_file_info_get_attribute_uint64 (gfileinfo, G_FILE_ATTRIBUTE_TIME_MODIFIED); + DB( g_print("- '%s' last access = %lu\n", filepath, retval) ); + g_object_unref(gfileinfo); + } + g_object_unref(gfile); + + return retval; } +void hbfile_file_default(void) +{ + DB( g_print("\n[hbfile] default\n") ); + + //todo: maybe translate this also + hbfile_change_filepath(g_build_filename(PREFS->path_hbfile, "untitled.xhb", NULL)); + GLOBALS->hbfile_is_new = TRUE; + GLOBALS->hbfile_is_bak = FALSE; + GLOBALS->xhb_timemodified = 0ULL; + + DB( g_print("- path_hbfile is '%s'\n", PREFS->path_hbfile) ); + DB( g_print("- xhb_filepath is '%s'\n", GLOBALS->xhb_filepath) ); +} @@ -82,7 +133,7 @@ void hbfile_replace_basecurrency(Currency4217 *curfmt) Currency *item; guint32 oldkcur; - DB( g_print("\n[hbfile] replace base currency \n") ); + DB( g_print("\n[hbfile] replace base currency\n") ); oldkcur = GLOBALS->kcur; da_cur_remove(oldkcur); @@ -135,7 +186,7 @@ guint32 oldkcur; } -GList *hbfile_transaction_get_all(guint32 kacc) +GList *hbfile_transaction_get_all(void) { GList *lst_acc, *lnk_acc; GList *lnk_txn; @@ -149,9 +200,9 @@ GList *list; { Account *acc = lnk_acc->data; - if( (acc->flags & (AF_CLOSED|AF_NOREPORT)) ) - goto next_acc; - if( (kacc > 0 ) && (acc->key != kacc) ) + //#1674045 ony rely on nosummary + //if( (acc->flags & (AF_CLOSED|AF_NOREPORT)) ) + if( (acc->flags & (AF_NOREPORT)) ) goto next_acc; lnk_txn = g_queue_peek_head_link(acc->txn_queue); @@ -170,7 +221,7 @@ GList *list; } -GQueue *hbfile_transaction_get_partial(guint32 minjulian, guint32 maxjulian) +static GQueue *hbfile_transaction_get_partial_internal(guint32 minjulian, guint32 maxjulian, gushort exclusionflags) { GList *lst_acc, *lnk_acc; GList *lnk_txn; @@ -184,7 +235,7 @@ GQueue *txn_queue; { Account *acc = lnk_acc->data; - if( (acc->flags & (AF_CLOSED|AF_NOREPORT)) ) + if( (acc->flags & exclusionflags) ) goto next_acc; lnk_txn = g_queue_peek_tail_link(acc->txn_queue); @@ -215,6 +266,22 @@ GQueue *txn_queue; } +GQueue *hbfile_transaction_get_partial(guint32 minjulian, guint32 maxjulian) +{ + //#1674045 ony rely on nosummary + //return hbfile_transaction_get_partial_internal(minjulian, maxjulian, (AF_CLOSED|AF_NOREPORT)); + return hbfile_transaction_get_partial_internal(minjulian, maxjulian, (AF_NOREPORT)); +} + + +GQueue *hbfile_transaction_get_partial_budget(guint32 minjulian, guint32 maxjulian) +{ + //#1674045 ony rely on nosummary + //return hbfile_transaction_get_partial_internal(minjulian, maxjulian, (AF_CLOSED|AF_NOREPORT|AF_NOBUDGET)); + return hbfile_transaction_get_partial_internal(minjulian, maxjulian, (AF_NOREPORT|AF_NOBUDGET)); +} + + void hbfile_sanity_check(void) { GList *lst_acc, *lnk_acc; @@ -397,8 +464,8 @@ guint cnt, i; { Archive *item = list->data; - g_free(item->wording); - item->wording = g_strdup_printf("archive %d", cnt++); + g_free(item->memo); + item->memo = g_strdup_printf("archive %d", cnt++); GLOBALS->changes_count++; //later split anonymize also @@ -421,15 +488,16 @@ guint cnt, i; g_free(item->info); item->info = NULL; - g_free(item->wording); - item->wording = g_strdup_printf("memo %d", item->date); + g_free(item->memo); + item->memo = g_strdup_printf("memo %d", item->date); GLOBALS->changes_count++; if(item->flags & OF_SPLIT) { - for(i=0;isplits); + for(i=0;isplits[i]; + split = da_splits_get(item->splits, i); if( split == NULL ) break; if(split->memo != NULL) @@ -518,12 +586,7 @@ void hbfile_setup(gboolean file_clear) if(file_clear == TRUE) { - //todo: maybe translate this also - hbfile_change_filepath(g_build_filename(PREFS->path_hbfile, "untitled.xhb", NULL)); - GLOBALS->hbfile_is_new = TRUE; - - DB( g_print("- path_hbfile is '%s'\n", PREFS->path_hbfile) ); - DB( g_print("- xhb_filepath is '%s'\n", GLOBALS->xhb_filepath) ); + hbfile_file_default(); } else { @@ -542,7 +605,7 @@ void hbfile_setup(gboolean file_clear) GLOBALS->changes_count = 0; - GLOBALS->xhb_hasbak = FALSE; + GLOBALS->xhb_hasrevert = FALSE; }