1 /*  HomeBank -- Free, easy, personal accounting for everyone.
2  *  Copyright (C) 1995-2021 Maxime DOYEN
3  *
4  *  This file is part of HomeBank.
5  *
6  *  HomeBank is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  HomeBank is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __HOMEBANK_H__
21 #define __HOMEBANK_H__
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 
28 #include <errno.h>
29 #include <math.h>
30 #include <libintl.h>
31 #include <locale.h>
32 #include <stdlib.h>		/* atoi, atof, atol */
33 #include <string.h>		/* memset, memcpy, strcmp, strcpy */
34 //#include <time.h>
35 
36 #include <glib.h>
37 #include <glib/gstdio.h>
38 #include <gtk/gtk.h>
39 
40 #include "enums.h"
41 #include "hb-preferences.h"
42 
43 #include "hb-transaction.h"
44 #include "hb-currency.h"
45 #include "hb-group.h"
46 #include "hb-account.h"
47 #include "hb-archive.h"
48 #include "hb-assign.h"
49 #include "hb-category.h"
50 #include "hb-encoding.h"
51 #include "hb-export.h"
52 #include "hb-filter.h"
53 #include "hb-import.h"
54 #include "hb-misc.h"
55 #include "hb-payee.h"
56 #include "hb-report.h"
57 #include "hb-tag.h"
58 #include "hb-hbfile.h"
59 #include "hb-xml.h"
60 
61 #include "ui-dialogs.h"
62 #include "ui-pref.h"
63 #include "ui-widgets.h"
64 
65 #define _(str) gettext (str)
66 #define gettext_noop(str) (str)
67 #define N_(str) gettext_noop (str)
68 
69 /* = = = = = = = = = = = = = = = = */
70 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
71 
72 #define HB_UNSTABLE			FALSE
73 #define HB_UNSTABLE_SHOW	FALSE
74 
75 
76 #define HOMEBANK_MAJOR	5
77 #define HOMEBANK_MINOR	5
78 #define HOMEBANK_MICRO	1
79 
80 #define HB_VERSION		"5.5.1"
81 #define HB_VERSION_NUM	(HOMEBANK_MAJOR*10000) + (HOMEBANK_MINOR*100) + HOMEBANK_MICRO
82 
83 #define FILE_VERSION		1.4
84 #define PREF_VERSION		551
85 
86 #if HB_UNSTABLE == FALSE
87 	#define	PROGNAME		"HomeBank"
88 	#define HB_DATA_PATH	"homebank"
89 #else
90 	#define	PROGNAME		"HomeBank " HB_VERSION " (unstable)"
91 	#define HB_DATA_PATH	"homebank_unstable"
92 #endif
93 
94 
95 #ifdef G_OS_WIN32
96 	#define GETTEXT_PACKAGE "homebank"
97 	#define LOCALE_DIR      "locale"
98 	#define PIXMAPS_DIR     "images"
99 	#define HELP_DIR        "help"
100 	#define PACKAGE_VERSION HB_VERSION
101 	#define PACKAGE         "homebank"
102 	#define VERSION         HB_VERSION
103 
104 	//#define PORTABLE_APP
105 	//#define NOOFX
106 
107 	#define ENABLE_NLS 1
108 #endif
109 
110 
111 /* container spacing */
112 #define SPACING_TINY		3
113 #define SPACING_SMALL		6
114 #define SPACING_MEDIUM		12
115 #define SPACING_LARGE		18
116 #define SPACING_POPOVER		10
117 
118 
119 #define HB_DATE_MAX_GAP	7
120 
121 // those 2 line are duplicated into dateentry
122 #define HB_MINDATE  693596	  //01/01/1900
123 #define HB_MAXDATE  803533	  //31/12/2200
124 
125 /* widget minimum width */
126 #define HB_MINWIDTH_LIST	161
127 #define HB_MINHEIGHT_LIST	260
128 
129 #define HB_MINWIDTH_SEARCH	240
130 #define HB_MINWIDTH_COLUMN  48
131 
132 
133 /* miscellaneous */
134 #define PHI 1.61803399
135 
136 
137 
138 #define HB_NUMBER_SAMPLE	1234567.89
139 
140 /* hbfile/account/import update flags */
141 enum
142 {
143 	UF_TITLE     	= 1 << 0,	//1
144 	UF_SENSITIVE 	= 1 << 1,	//2
145 	UF_VISUAL   	= 1 << 2,	//4
146 	UF_REFRESHALL   = 1 << 3,	//8
147 //			= 1 << 4	//16
148 };
149 
150 
151 
152 typedef enum
153 {
154 	FILETYPE_UNKNOWN,
155 	FILETYPE_HOMEBANK,
156 	FILETYPE_OFX,
157 	FILETYPE_QIF,
158 	FILETYPE_CSV_HB,
159 //	FILETYPE_AMIGA_HB,
160 	NUM_FILETYPE
161 } HbFileType;
162 
163 
164 /* ---- icon size as defined into gtkiconfactory.c ---- */
165 /* GTK_ICON_SIZE_MENU 16
166  * GTK_ICON_SIZE_BUTTON 20
167  * GTK_ICON_SIZE_SMALL_TOOLBAR 18
168  * GTK_ICON_SIZE_LARGE_TOOLBAR 24 (default for toolbar)
169  * GTK_ICON_SIZE_DND 32
170  * GTK_ICON_SIZE_DIALOG 48
171  */
172 
173 
174 /* -------- named icons (Standard Icon Name) -------- */
175 
176 
177 //obsolete, as since since gtk3.10 : no more icons for dialogs and menu
178 #define ICONNAME_SAVE_AS			"document-save-as"	  //obsolete
179 #define ICONNAME_REVERT		    "document-revert"	  //obsolete
180 #define ICONNAME_PROPERTIES			"document-properties"   //obsolete
181 #define ICONNAME_CLOSE				"window-close"	  //obsolete
182 #define ICONNAME_QUIT				"application-exit"	  //obsolete
183 #define ICONNAME_HELP				"help-browser"	  //obsolete
184 #define ICONNAME_ABOUT				"help-about"	  //obsolete
185 #define ICONNAME_PREFERENCES		"preferences-system"	  //obsolete
186 
187 
188 //#define ICONNAME_FIND				"edit-find"				//unused
189 //#define ICONNAME_CLEAR			"edit-clear"			//unused
190 //#define ICONNAME_HB_SCHED_SKIP		"media-skip-forward"
191 //#define ICONNAME_HB_SCHED_POST		"media-playback-start"
192 
193 //in 5.2 no themeable icon to keep a consistent iconset
194 
195 #define ICONNAME_WARNING			"dialog-warning"
196 #define ICONNAME_ERROR				"dialog-error"
197 #define ICONNAME_INFO				"dialog-information"
198 
199 
200 #define ICONNAME_FOLDER				"folder-symbolic"
201 #define ICONNAME_EMBLEM_OK			"emblem-ok-symbolic"
202 #define ICONNAME_EMBLEM_SYSTEM		"emblem-system-symbolic"
203 #define ICONNAME_WINDOW_CLOSE		"window-close-symbolic"
204 #define ICONNAME_LIST_ADD			"list-add-symbolic"
205 #define ICONNAME_LIST_EDIT			"document-edit-symbolic"
206 #define ICONNAME_LIST_DELETE		"list-remove-symbolic"
207 #define ICONNAME_LIST_DELETE_ALL	"list-remove-all-symbolic"
208 #define ICONNAME_CHANGES_PREVENT	"changes-prevent-symbolic"
209 #define ICONNAME_SYSTEM_SEARCH		"system-search-symbolic"
210 
211 // custom or gnome not found
212 #define ICONNAME_HB_BUTTON_MENU		"open-menu-symbolic"
213 #define ICONNAME_HB_BUTTON_COLLAPSE	"list-collapse-all-symbolic"
214 #define ICONNAME_HB_BUTTON_EXPAND	"list-expand-all-symbolic"
215 #define ICONNAME_HB_BUTTON_SPLIT	"edit-split-symbolic"
216 #define ICONNAME_HB_BUTTON_DELETE	"edit-delete-symbolic"
217 #define ICONNAME_HB_TOGGLE_SIGN		"toggle-sign-symbolic"
218 #define ICONNAME_HB_LIST_MERGE		"list-merge-symbolic"
219 
220 #define ICONNAME_HB_TEXT_CASE		"text-casesensitive-symbolic"
221 #define ICONNAME_HB_TEXT_REGEX		"text-regularexpression-symbolic"
222 
223 
224 /* -------- named icons (Custom to homebank) -------- */
225 
226 
227 #define ICONNAME_HB_CURRENCY		"hb-currency"
228 #define ICONNAME_HB_ACCOUNT         "hb-account"
229 #define ICONNAME_HB_ARCHIVE         "hb-archive"
230 #define ICONNAME_HB_ASSIGN          "hb-assign"
231 #define ICONNAME_HB_BUDGET          "hb-budget"
232 #define ICONNAME_HB_CATEGORY        "hb-category"
233 #define ICONNAME_HB_PAYEE           "hb-payee"
234 #define ICONNAME_HB_OPE_SHOW        "hb-ope-show"   //? "view-register
235 #define ICONNAME_HB_REP_STATS       "hb-rep-stats"
236 #define ICONNAME_HB_REP_TIME        "hb-rep-time"
237 #define ICONNAME_HB_REP_BALANCE     "hb-rep-balance"
238 #define ICONNAME_HB_REP_BUDGET      "hb-rep-budget"
239 #define ICONNAME_HB_REP_CAR         "hb-rep-vehicle"
240 #define ICONNAME_HB_HELP            "hb-help"
241 #define ICONNAME_HB_DONATE          "hb-donate"
242 
243 #define ICONNAME_HB_VIEW_LIST	    "hb-view-list"   //"view-list-text"
244 #define ICONNAME_HB_VIEW_BAR	    "hb-view-bar"    //"view-chart-bar"
245 #define ICONNAME_HB_VIEW_COLUMN	    "hb-view-column" //"view-chart-column"
246 #define ICONNAME_HB_VIEW_LINE	    "hb-view-line"   //"view-chart-line"
247 #define ICONNAME_HB_VIEW_STACK	    "hb-view-stack"  //"view-chart-stack"
248 #define ICONNAME_HB_VIEW_PIE	    "hb-view-pie"    //"view-chart-pie"
249 #define ICONNAME_HB_VIEW_DONUT	    "hb-view-donut"  //"view-chart-donut"
250 #define ICONNAME_HB_SHOW_LEGEND	    "hb-legend"		//"view-legend"
251 #define ICONNAME_HB_SHOW_RATE	    "hb-rate"	    	// obsolete ?
252 #define ICONNAME_HB_REFRESH		    "hb-view-refresh"	//"view-refresh"
253 #define ICONNAME_HB_FILTER		    "hb-filter"		//"edit-filter"
254 
255 #define ICONNAME_HB_FILE_NEW		"hb-document-new"		//document-new
256 #define ICONNAME_HB_FILE_OPEN		"hb-document-open"	//document-open
257 #define ICONNAME_HB_FILE_SAVE		"hb-document-save"	//document-save
258 #define ICONNAME_HB_FILE_IMPORT		"hb-file-import"		//document-import
259 #define ICONNAME_HB_FILE_EXPORT		"hb-file-export"		//document-export
260 #define ICONNAME_HB_FILE_VALID		"hb-file-valid"
261 #define ICONNAME_HB_FILE_INVALID	"hb-file-invalid"
262 
263 #define ICONNAME_HB_PRINT			"hb-document-print"
264 
265 #define ICONNAME_HB_OPE_AUTO        "hb-ope-auto"   //?
266 #define ICONNAME_HB_OPE_BUDGET      "hb-ope-budget" //?
267 #define ICONNAME_HB_OPE_FORCED      "hb-ope-forced" //?
268 #define ICONNAME_HB_OPE_ADD         "hb-ope-add"	//? "edit-add"
269 #define ICONNAME_HB_OPE_HERIT       "hb-ope-herit"  //? "edit-clone"
270 #define ICONNAME_HB_OPE_EDIT        "hb-ope-edit"   //
271 #define ICONNAME_HB_OPE_MULTIEDIT   "hb-ope-multiedit"   //
272 #define ICONNAME_HB_OPE_DELETE      "hb-ope-delete" //? "edit-delete"
273 #define ICONNAME_CONVERT			"hb-ope-convert"	// obsolete ?
274 #define ICONNAME_HB_ASSIGN_RUN      "hb-assign-run"
275 #define ICONNAME_HB_OPE_MOVUP		"hb-go-up"
276 #define ICONNAME_HB_OPE_MOVDW		"hb-go-down"
277 
278 #define ICONNAME_HB_OPE_NEW		     "hb-ope-new"
279 // edit is defined above
280 #define ICONNAME_HB_OPE_VOID        "hb-ope-void"
281 #define ICONNAME_HB_OPE_REMIND      "hb-ope-remind"
282 #define ICONNAME_HB_OPE_SIMILAR     "hb-ope-similar"
283 
284 #define ICONNAME_HB_OPE_CLEARED     "hb-ope-cleared"
285 #define ICONNAME_HB_OPE_RECONCILED  "hb-ope-reconciled"
286 #define ICONNAME_HB_OPE_FUTURE      "hb-ope-future"
287 
288 #define ICONNAME_HB_PM_INTXFER		"pm-intransfer"
289 
290 /*
291 ** Global application datas
292 */
293 struct HomeBank
294 {
295 	// hbfile storage
296 	GHashTable		*h_cur;			//currencies
297 	GHashTable		*h_grp;			//groups
298 
299 	GHashTable		*h_acc;			//accounts
300 	GHashTable		*h_pay;			//payees
301 	GHashTable		*h_cat;			//categories
302 
303 	GHashTable		*h_rul;			//assign rules
304 	GHashTable		*h_tag;			//tags
305 
306 
307 	GHashTable		*h_memo;		//memo/description
308 
309 	GList			*arc_list;		//scheduled/template
310 
311 	//#1419304 we keep the deleted txn to a stack trash
312 	//GTrashStack		*txn_stk;
313 	GSList			*openwindows;	//added 5.5.1
314 	GSList			*deltxn_list;
315 
316 	// hbfile (saved properties)
317 	gchar			*owner;
318 	gshort			auto_smode;
319 	gshort			auto_weekday;
320 	gshort			auto_nbdays;
321 
322 	guint32			vehicle_category;
323 	guint32			kcur;			// base currency
324 
325 	// hbfile (unsaved properties)
326 	guint			changes_count;
327 	gboolean		hbfile_is_new;
328 	gboolean		hbfile_is_bak;
329 	gchar			*xhb_filepath;
330 	gboolean		xhb_hasrevert;		//file has backup (*.xhb~) used for revert menu sensitivity
331 	guint64			xhb_timemodified;
332 
333 	// really global stuffs
334 	gboolean		first_run;
335 	guint32			today;			//today's date
336 	gint			define_off;		//>0 when a stat, account window is opened
337 	gboolean		minor;
338 
339 	GtkWidget		*mainwindow;	//should be global to access attached window data
340 	GtkWidget		*alltxnwindow;	//window to mutex all txn show
341 	GtkIconTheme	*icontheme;
342 	//GdkPixbuf		*lst_pixbuf[NUM_LST_PIXBUF];
343 	//gint			lst_pixbuf_maxwidth;
344 
345 };
346 
347 
348 gchar *homebank_filepath_with_extention(gchar *path, gchar *extension);
349 gchar *homebank_filename_without_extention(gchar *path);
350 void homebank_file_ensure_xhb(gchar *filename);
351 void homebank_backup_current_file(void);
352 gboolean homebank_util_url_show (const gchar *url);
353 gchar *homebank_lastopenedfiles_load(void);
354 gboolean homebank_lastopenedfiles_save(void);
355 
356 
357 void homebank_window_set_icon_from_file(GtkWindow *window, gchar *filename);
358 
359 const gchar *homebank_app_get_config_dir (void);
360 const gchar *homebank_app_get_images_dir (void);
361 const gchar *homebank_app_get_pixmaps_dir (void);
362 const gchar *homebank_app_get_locale_dir (void);
363 const gchar *homebank_app_get_help_dir (void);
364 const gchar *homebank_app_get_datas_dir (void);
365 guint32 homebank_app_date_get_julian(void);
366 
367 /* - - - - obsolete things - - - - */
368 
369 /*
370 typedef struct _budget		Budget;
371 
372 struct _budget
373 {
374 	guint	key;
375 	gushort	flags;
376 	guint	cat_key;
377 	guint	year;
378 	gdouble	value[13];
379 };
380 */
381 
382 /*
383 struct _investment
384 {
385 	guint	date;
386 	gdouble	buy_amount;
387 	gdouble	curr_amount;
388 	gdouble	commission;
389 	guint	number;
390 	guint	account;
391 	gchar	*name;
392 	gchar	*symbol;
393 	gchar	*note;
394 };
395 */
396 
397 #endif
398