]> Dogcows Code - chaz/homebank/blob - src/dsp-mainwindow.c
Merge branch 'master' into ext-perl
[chaz/homebank] / src / dsp-mainwindow.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 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
21 #include "homebank.h"
22
23 #include "dsp-mainwindow.h"
24
25 #include "ext.h"
26
27 #include "list-account.h"
28
29 #include "hub-account.h"
30 #include "hub-scheduled.h"
31 #include "hub-spending.h"
32 #include "hub-transaction.h"
33
34 #include "dsp-account.h"
35 #include "ui-assist-import.h"
36 #include "ui-assist-start.h"
37 #include "ui-account.h"
38 #include "ui-currency.h"
39 #include "ui-payee.h"
40 #include "ui-category.h"
41 #include "ui-archive.h"
42 #include "ui-assign.h"
43 #include "ui-budget.h"
44 #include "ui-pref.h"
45 #include "ui-hbfile.h"
46 #include "ui-transaction.h"
47 #include "ui-tag.h"
48
49 #include "rep-balance.h"
50 #include "rep-budget.h"
51 #include "rep-stats.h"
52 #include "rep-time.h"
53 #include "rep-vehicle.h"
54
55 #include "gtk-chart.h"
56
57 //old url prior 2019
58 //#define HOMEBANK_URL_HELP "http://homebank.free.fr/help/"
59 //#define HOMEBANK_URL_HELP_ONLINE "https://launchpad.net/homebank/+addquestion"
60 //#define HOMEBANK_URL_HELP_PROBLEM "https://launchpad.net/homebank/+filebug"
61 //#define HOMEBANK_URL_HELP_TRANSLATE "https://launchpad.net/homebank/+translations"
62
63 #define HOMEBANK_URL_HELP "index.html"
64 #define HOMEBANK_URL_HELP_ONLINE "http://homebank.free.fr/support.php"
65 #define HOMEBANK_URL_HELP_UPDATES "http://homebank.free.fr/downloads.php"
66 #define HOMEBANK_URL_HELP_PROBLEM "http://homebank.free.fr/development.php#bug"
67 #define HOMEBANK_URL_HELP_TRANSLATE "http://homebank.free.fr/development.php#translate"
68
69
70 /****************************************************************************/
71 /* Debug macros */
72 /****************************************************************************/
73 #define MYDEBUG 0
74
75 #if MYDEBUG
76 #define DB(x) (x);
77 #else
78 #define DB(x);
79 #endif
80
81 /* our global datas */
82 extern struct HomeBank *GLOBALS;
83 extern struct Preferences *PREFS;
84 extern gchar *homebank_pixmaps_dir;
85
86
87 /* our functions prototype */
88 static void ui_mainwindow_action_new(void);
89 static void ui_mainwindow_action_open(void);
90 static void ui_mainwindow_action_save(void);
91 static void ui_mainwindow_action_saveas(void);
92 static void ui_mainwindow_action_revert(void);
93 static void ui_mainwindow_action_openbak(void);
94 static void ui_mainwindow_action_properties(void);
95 static void ui_mainwindow_action_close(void);
96 static void ui_mainwindow_action_quit(void);
97
98 static void ui_mainwindow_action_defcurrency(void);
99 static void ui_mainwindow_action_defaccount(void);
100 static void ui_mainwindow_action_defpayee(void);
101 static void ui_mainwindow_action_defcategory(void);
102 static void ui_mainwindow_action_defarchive(void);
103 static void ui_mainwindow_action_defbudget(void);
104 static void ui_mainwindow_action_defassign(void);
105 static void ui_mainwindow_action_deftag(void);
106 static void ui_mainwindow_action_preferences(void);
107
108 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction *action);
109 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction *action);
110 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction *action);
111 static void ui_mainwindow_action_toggle_minor(GtkToggleAction *action);
112
113 static void ui_mainwindow_action_showtransactions(void);
114 static void ui_mainwindow_action_showalltransactions(void);
115
116 static void ui_mainwindow_action_addtransactions(void);
117 static void ui_mainwindow_action_checkscheduled(void);
118
119 static void ui_mainwindow_action_statistic(void);
120 static void ui_mainwindow_action_trendtime(void);
121 static void ui_mainwindow_action_budget(void);
122 static void ui_mainwindow_action_balance(void);
123 static void ui_mainwindow_action_vehiclecost(void);
124
125 static void ui_mainwindow_action_import(GtkAction *action);
126 static void ui_mainwindow_action_export(void);
127 static void ui_mainwindow_action_anonymize(void);
128 static void ui_mainwindow_action_file_statistics(void);
129
130 static void ui_mainwindow_action_pluginprefs(void);
131
132 static void ui_mainwindow_action_help(void);
133 void ui_mainwindow_action_help_welcome(void);
134 static void ui_mainwindow_action_help_online(void);
135 static void ui_mainwindow_action_help_updates(void);
136 static void ui_mainwindow_action_help_releasenotes(void);
137 static void ui_mainwindow_action_help_translate(void);
138 static void ui_mainwindow_action_help_problem(void);
139 static void ui_mainwindow_action_about(void);
140
141
142 static GtkWidget *ui_mainwindow_create_recent_chooser_menu (GtkRecentManager *manager);
143
144 void ui_mainwindow_open(GtkWidget *widget, gpointer user_data);
145
146 void ui_mainwindow_save(GtkWidget *widget, gpointer user_data);
147 void ui_mainwindow_revert(GtkWidget *widget, gpointer user_data);
148 void ui_mainwindow_action(GtkWidget *widget, gpointer user_data);
149 void ui_mainwindow_toggle_minor(GtkWidget *widget, gpointer user_data);
150 void ui_mainwindow_clear(GtkWidget *widget, gpointer user_data);
151
152 void ui_mainwindow_update(GtkWidget *widget, gpointer user_data);
153 void ui_mainwindow_addtransactions(GtkWidget *widget, gpointer user_data);
154 void ui_mainwindow_recent_add (struct hbfile_data *data, const gchar *path);
155
156 void ui_mainwindow_recent_add (struct hbfile_data *data, const gchar *path);
157
158 static void ui_mainwindow_showprefs(gint page);
159
160 static GtkActionEntry entries[] = {
161
162 /* name, icon-name, label */
163
164 { "FileMenu" , NULL, N_("_File"), NULL, NULL, NULL },
165 //{ "ImportMenu" , NULL, N_("_Import"), NULL, NULL, NULL },
166 { "RecentMenu" , NULL, N_("Open _Recent"), NULL, NULL, NULL },
167 { "EditMenu" , NULL, N_("_Edit"), NULL, NULL, NULL },
168 { "ViewMenu" , NULL, N_("_View"), NULL, NULL, NULL },
169 { "ManageMenu" , NULL, N_("_Manage"), NULL, NULL, NULL },
170 { "TxnMenu" , NULL, N_("_Transactions"), NULL, NULL, NULL },
171 { "ReportMenu" , NULL, N_("_Reports"), NULL, NULL, NULL },
172 { "ToolsMenu" , NULL, N_("_Tools"), NULL, NULL, NULL },
173 { "PluginMenu" , NULL, N_("_Plugins"), NULL, NULL, NULL },
174 { "HelpMenu" , NULL, N_("_Help"), NULL, NULL, NULL },
175
176 // { "Import" , NULL, N_("Import") },
177 // { "Export" , NULL, N_("Export to") },
178 /* name, icon-name, label, accelerator, tooltip */
179
180 /* FileMenu */
181 { "New" , ICONNAME_HB_FILE_NEW , N_("_New") , "<control>N", N_("Create a new file"), G_CALLBACK (ui_mainwindow_action_new) },
182 { "Open" , ICONNAME_HB_FILE_OPEN , N_("_Open...") , "<control>O", N_("Open a file"), G_CALLBACK (ui_mainwindow_action_open) },
183 { "Save" , ICONNAME_HB_FILE_SAVE , N_("_Save") , "<control>S", N_("Save the current file"), G_CALLBACK (ui_mainwindow_action_save) },
184 { "SaveAs" , ICONNAME_SAVE_AS , N_("Save _As...") , "<shift><control>S", N_("Save the current file with a different name"), G_CALLBACK (ui_mainwindow_action_saveas) },
185
186 { "Revert" , ICONNAME_REVERT , N_("Revert") , NULL, N_("Revert to a saved version of this file"), G_CALLBACK (ui_mainwindow_action_revert) },
187 { "OpenBak" , NULL , N_("Restore backup") , NULL, N_("Restore from a backup file"), G_CALLBACK (ui_mainwindow_action_openbak) },
188
189 { "Properties" , ICONNAME_PROPERTIES , N_("Properties..."), NULL, N_("Configure the file"), G_CALLBACK (ui_mainwindow_action_properties) },
190 { "Close" , ICONNAME_CLOSE , N_("_Close") , "<control>W", N_("Close the current file"), G_CALLBACK (ui_mainwindow_action_close) },
191 { "Quit" , ICONNAME_QUIT , N_("_Quit") , "<control>Q", N_("Quit HomeBank"), G_CALLBACK (ui_mainwindow_action_quit) },
192
193 /* Exchange */
194 { "Import" , ICONNAME_HB_FILE_IMPORT , N_("Import...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
195 //{ "ImportQIF" , ICONNAME_HB_FILE_IMPORT , N_("QIF file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
196 //{ "ImportOFX" , ICONNAME_HB_FILE_IMPORT , N_("OFX/QFX file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
197 //{ "ImportCSV" , ICONNAME_HB_FILE_IMPORT , N_("CSV file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
198
199 { "ExportQIF" , ICONNAME_HB_FILE_EXPORT , N_("Export as QIF...") , NULL, N_("Export all account in a QIF file"), G_CALLBACK (ui_mainwindow_action_export) },
200
201 /* EditMenu */
202 { "Preferences", ICONNAME_PREFERENCES , N_("Preferences..."), NULL, N_("Configure HomeBank"), G_CALLBACK (ui_mainwindow_action_preferences) },
203
204 /* ManageMenu */
205 { "Currency" , ICONNAME_HB_CURRENCY , N_("Currencies...") , NULL, N_("Configure the currencies"), G_CALLBACK (ui_mainwindow_action_defcurrency) },
206 { "Account" , ICONNAME_HB_ACCOUNT , N_("Acc_ounts...") , NULL, N_("Configure the accounts"), G_CALLBACK (ui_mainwindow_action_defaccount) },
207 { "Payee" , ICONNAME_HB_PAYEE , N_("_Payees...") , NULL, N_("Configure the payees"), G_CALLBACK (ui_mainwindow_action_defpayee) },
208 { "Category" , ICONNAME_HB_CATEGORY , N_("Categories...") , NULL, N_("Configure the categories"), G_CALLBACK (ui_mainwindow_action_defcategory) },
209 { "Archive" , ICONNAME_HB_ARCHIVE , N_("Scheduled/Template...") , NULL, N_("Configure the scheduled/template transactions"), G_CALLBACK (ui_mainwindow_action_defarchive) },
210 { "Budget" , ICONNAME_HB_BUDGET , N_("Budget...") , NULL, N_("Configure the budget"), G_CALLBACK (ui_mainwindow_action_defbudget) },
211 { "Assign" , ICONNAME_HB_ASSIGN , N_("Assignments..."), NULL, N_("Configure the automatic assignments"), G_CALLBACK (ui_mainwindow_action_defassign) },
212 { "Tag" , NULL , N_("Tags..."), NULL, N_("Configure the tags"), G_CALLBACK (ui_mainwindow_action_deftag) },
213
214 /* TxnMenu */
215 { "AddTxn" , ICONNAME_HB_OPE_ADD , N_("Add...") , NULL, N_("Add transactions"), G_CALLBACK (ui_mainwindow_action_addtransactions) },
216 { "ShowTxn" , ICONNAME_HB_OPE_SHOW , N_("Show...") , NULL, N_("Shows selected account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions) },
217 { "ShowAllTxn" , ICONNAME_HB_OPE_SHOW , N_("Show all...") , NULL, N_("Shows all account transactions"), G_CALLBACK (ui_mainwindow_action_showalltransactions) },
218 { "Scheduler" , NULL , N_("Set scheduler...") , NULL, N_("Configure the transaction scheduler"), G_CALLBACK (ui_mainwindow_action_properties) },
219 { "AddScheduled", NULL , N_("Post scheduled"), NULL, N_("Post pending scheduled transactions"), G_CALLBACK (ui_mainwindow_action_checkscheduled) },
220
221 /* ReportMenu */
222 { "RStatistics" , ICONNAME_HB_REP_STATS , N_("_Statistics...") , NULL, N_("Open the Statistics report"), G_CALLBACK (ui_mainwindow_action_statistic) },
223 { "RTrendTime" , ICONNAME_HB_REP_TIME , N_("_Trend Time...") , NULL, N_("Open the Trend Time report"), G_CALLBACK (ui_mainwindow_action_trendtime) },
224 { "RBudget" , ICONNAME_HB_REP_BUDGET , N_("B_udget...") , NULL, N_("Open the Budget report"), G_CALLBACK (ui_mainwindow_action_budget) },
225 { "RBalance" , ICONNAME_HB_REP_BALANCE, N_("Balance...") , NULL, N_("Open the Balance report"), G_CALLBACK (ui_mainwindow_action_balance) },
226 { "RVehiculeCost", ICONNAME_HB_REP_CAR , N_("_Vehicle cost...") , NULL, N_("Open the Vehicle cost report"), G_CALLBACK (ui_mainwindow_action_vehiclecost) },
227
228 /* Tools */
229 { "Welcome" , NULL , N_("Show welcome dialog...") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_help_welcome) },
230 { "FileStats" , NULL , N_("File statistics...") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_file_statistics) },
231 { "Anonymize" , NULL , N_("Anonymize...") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_anonymize) },
232
233 /* Plugins */
234 { "PluginPreferences", "prf-plugins", N_("_Plugins..."), "<control>U", N_("Configure plugin preferences"), G_CALLBACK(ui_mainwindow_action_pluginprefs) },
235
236 /* HelpMenu */
237 { "Contents" , ICONNAME_HELP , N_("_Contents") , "F1", N_("Documentation about HomeBank"), G_CALLBACK (ui_mainwindow_action_help) },
238 { "Online" , "lpi-help" , N_("Get Help Online...") , NULL, N_("Connect to the LaunchPad website for online help"), G_CALLBACK (ui_mainwindow_action_help_online) },
239
240 { "Updates" , NULL , N_("Check for updates...") , NULL, N_("Visit HomeBank website to check for update"), G_CALLBACK (ui_mainwindow_action_help_updates) },
241 { "ReleaseNotes", NULL , N_("Release Notes") , NULL, N_("Display the release notes"), G_CALLBACK (ui_mainwindow_action_help_releasenotes) },
242 { "Problem" , "lpi-bug" , N_("Report a Problem...") , NULL, N_("Connect to the LaunchPad website to help fix problems"), G_CALLBACK (ui_mainwindow_action_help_problem) },
243 { "Translate" , "lpi-translate" , N_("Translate this Application..."), NULL, N_("Connect to the LaunchPad website to help translate this application"), G_CALLBACK (ui_mainwindow_action_help_translate) },
244
245 { "About" , ICONNAME_ABOUT , N_("_About") , NULL, N_("About HomeBank") ,G_CALLBACK (ui_mainwindow_action_about) },
246
247 };
248 static guint n_entries = G_N_ELEMENTS (entries);
249
250
251 static GtkToggleActionEntry toggle_entries[] = {
252 /* name , icon-name, label, accelerator, tooltip, callback, is_active */
253 { "Toolbar" , NULL , N_("_Toolbar") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_toggle_toolbar), TRUE },
254 { "Spending" , NULL , N_("_Top spending") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_toggle_topspending), TRUE },
255 { "BottomLists", NULL , N_("_Bottom Lists") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_toggle_upcoming), TRUE },
256 { "AsMinor" , NULL , N_("Euro minor"), "<control>M", NULL, G_CALLBACK (ui_mainwindow_action_toggle_minor), FALSE },
257 };
258
259 static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
260
261
262 static const gchar *ui_info =
263 "<ui>"
264
265 " <menubar name='MenuBar'>"
266 " <menu action='FileMenu'>"
267 " <menuitem action='New'/>"
268 " <menuitem action='Open'/>"
269 " <menuitem action='RecentMenu'/>"
270 " <separator/>"
271 " <menuitem action='Save'/>"
272 " <menuitem action='SaveAs'/>"
273 " <separator/>"
274 " <menuitem action='Import'/>"
275 /*" <menu action='ImportMenu'>"
276 " <menuitem action='ImportQIF'/>"
277 " <menuitem action='ImportOFX'/>"
278 " <menuitem action='ImportCSV'/>"
279 " </menu>"*/
280 " <menuitem action='ExportQIF'/>"
281 // future: print to come here
282 " <separator/>"
283 " <menuitem action='Revert'/>"
284 " <menuitem action='OpenBak'/>"
285 " <separator/>"
286 " <menuitem action='Properties'/>"
287 " <separator/>"
288 " <menuitem action='Close'/>"
289 " <menuitem action='Quit'/>"
290 " </menu>"
291 " <menu action='EditMenu'>"
292 " <menuitem action='Preferences'/>"
293 " </menu>"
294 " <menu action='ViewMenu'>"
295 " <menuitem action='Toolbar'/>"
296 " <separator/>"
297 " <menuitem action='Spending'/>"
298 " <menuitem action='BottomLists'/>"
299 " <separator/>"
300 " <menuitem action='AsMinor'/>"
301 " </menu>"
302 " <menu action='ManageMenu'>"
303 " <menuitem action='Account'/>"
304 " <menuitem action='Payee'/>"
305 " <menuitem action='Category'/>"
306 " <menuitem action='Archive'/>"
307 " <menuitem action='Budget'/>"
308 " <menuitem action='Assign'/>"
309 " <menuitem action='Currency'/>"
310 " <menuitem action='Tag'/>"
311 " </menu>"
312 " <menu action='TxnMenu'>"
313 " <menuitem action='AddTxn'/>"
314 " <menuitem action='ShowTxn'/>"
315 " <menuitem action='ShowAllTxn'/>"
316 " <separator/>"
317 " <menuitem action='Scheduler'/>"
318 " <menuitem action='AddScheduled'/>"
319 " </menu>"
320 " <menu action='ReportMenu'>"
321 " <menuitem action='RStatistics'/>"
322 " <menuitem action='RTrendTime'/>"
323 " <menuitem action='RBalance'/>"
324 " <menuitem action='RBudget'/>"
325 " <menuitem action='RVehiculeCost'/>"
326 " </menu>"
327 " <menu action='ToolsMenu'>"
328 " <menuitem action='Welcome'/>"
329 " <menuitem action='FileStats'/>"
330 " <separator/>"
331 " <menuitem action='Anonymize'/>"
332 " </menu>"
333 " <menu action='PluginMenu'>"
334 " <separator/>"
335 " <menuitem action='PluginPreferences'/>"
336 " <separator/>"
337 " </menu>"
338 " <menu action='HelpMenu'>"
339 " <menuitem action='Contents'/>"
340 " <menuitem action='Online'/>"
341 " <separator/>"
342 " <menuitem action='Updates'/>"
343 " <menuitem action='ReleaseNotes'/>"
344 " <menuitem action='Problem'/>"
345 " <menuitem action='Translate'/>"
346 " <separator/>"
347 " <menuitem action='About'/>"
348 " </menu>"
349 " </menubar>"
350
351 " <toolbar name='ToolBar'>"
352 " <toolitem action='New'/>"
353 // here Open + recent is coded
354 " <toolitem action='Save'/>"
355 " <separator/>"
356 " <toolitem action='Account'/>"
357 " <toolitem action='Payee'/>"
358 " <toolitem action='Category'/>"
359 " <toolitem action='Archive'/>"
360 " <toolitem action='Budget'/>"
361 " <toolitem action='Assign'/>"
362 " <toolitem action='Currency'/>"
363 " <separator/>"
364 " <toolitem action='ShowTxn'/>"
365 " <toolitem action='AddTxn'/>"
366 " <separator/>"
367 " <toolitem action='RStatistics'/>"
368 " <toolitem action='RTrendTime'/>"
369 " <toolitem action='RBalance'/>"
370 " <toolitem action='RBudget'/>"
371 " <toolitem action='RVehiculeCost'/>"
372 " <separator/>"
373 " </toolbar>"
374
375 "</ui>";
376
377
378
379 /* TODO: a bouger */
380
381
382 /*
383 **
384 */
385 void ui_mainwindow_revert(GtkWidget *widget, gpointer user_data)
386 {
387 //struct hbfile_data *data;
388 gchar *basename;
389 gchar *title;
390 gchar *secondtext;
391 gint result;
392
393 DB( g_print("\n[ui-mainwindow] revert\n") );
394
395 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
396
397 basename = g_path_get_basename(GLOBALS->xhb_filepath);
398 title = g_strdup_printf (
399 _("Revert unsaved changes to file '%s'?"), basename);
400
401 secondtext =
402 _("- Changes made to the file will be permanently lost\n"
403 "- File will be reloaded from the last save (.xhb~)");
404
405 result = ui_dialog_msg_confirm_alert(
406 GTK_WINDOW(GLOBALS->mainwindow),
407 title,
408 secondtext,
409 _("_Revert")
410 );
411
412 g_free(title);
413 g_free(basename);
414
415 if( result == GTK_RESPONSE_OK )
416 {
417 DB( g_print(" - should revert\n") );
418
419 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS->xhb_filepath, "xhb~"));
420 ui_mainwindow_open_internal(widget, NULL);
421 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS->xhb_filepath, "xhb"));
422 }
423
424 }
425
426
427 static void
428 activate_url (GtkAboutDialog *about,
429 const gchar *link,
430 gpointer data)
431 {
432 DB( g_print("activate url %s\n", link) );
433
434 homebank_util_url_show (link);
435 }
436
437 static void hbfile_about(void)
438 {
439 GtkWidget *dialog;
440 GdkPixbuf *pixbuf;
441 gchar *pathfilename;
442 gchar *version;
443
444 static const gchar *artists[] = {
445 "Maxime DOYEN",
446 NULL
447 };
448
449 static const gchar *authors[] = {
450 "Lead developer:\n" \
451 "Maxime DOYEN",
452 "\nContributors:\n" \
453 "Charles MCGARVEY (Plugin system, Perl support)\n" \
454 "Ga\xc3\xabtan LORIDANT (Maths formulas for charts)\n",
455 NULL
456 };
457
458 /*
459 const gchar *documenters[] = {
460 "Maxime DOYEN",
461 NULL
462 };
463 */
464
465 static const gchar *copyright = "Copyright \xc2\xa9 1995-2019 - Maxime DOYEN";
466
467
468
469 version = g_strdup_printf (PACKAGE_VERSION "\n<small>Running against GTK+ %d.%d.%d</small>",
470 gtk_get_major_version (),
471 gtk_get_minor_version (),
472 gtk_get_micro_version ());
473
474 dialog = gtk_about_dialog_new();
475
476 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(GLOBALS->mainwindow));
477 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
478
479 gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog), g_get_application_name ());
480 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), version);
481 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright);
482 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), _("Free, easy, personal accounting for everyone"));
483 gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG(dialog), GTK_LICENSE_GPL_2_0);
484
485 //gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(dialog), );
486 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), "http://homebank.free.fr");
487 gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(dialog), "Visit the HomeBank website");
488
489 gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(dialog), "homebank");
490
491 pathfilename = g_build_filename(homebank_app_get_images_dir(), "splash.png", NULL);
492 pixbuf = gdk_pixbuf_new_from_file(pathfilename, NULL);
493 g_free(pathfilename);
494
495 if( pixbuf )
496 {
497 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pixbuf);
498 g_object_unref (pixbuf);
499 }
500
501 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog), authors);
502 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog), artists);
503 //gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(dialog), );
504 //gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog), );
505
506 g_signal_connect (dialog, "activate-link", G_CALLBACK (activate_url), NULL);
507
508 gtk_dialog_run (GTK_DIALOG (dialog));
509
510 gtk_widget_destroy (dialog);
511
512 g_free(version);
513
514 }
515
516
517 /* hbfile action functions -------------------- */
518 static void ui_mainwindow_action_new(void)
519 {
520 GtkWidget *widget = GLOBALS->mainwindow;
521
522 if( ui_dialog_msg_savechanges(widget,NULL) == TRUE )
523 {
524 //clear all, and init GLOBALS->xhb_filepath to default
525 ui_mainwindow_clear(widget, GINT_TO_POINTER(TRUE)); // GPOINTER_TO_INT(
526 ui_mainwindow_update(widget, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
527
528 ui_start_assistant();
529 //ui_hub_account_populate(GLOBALS->mainwindow, NULL);
530 //ui_hub_scheduled_populate(GLOBALS->mainwindow, NULL);
531 //ui_hub_spending_populate(GLOBALS->mainwindow, NULL);
532 }
533 }
534
535 static void ui_mainwindow_action_open(void)
536 {
537 ui_mainwindow_open(GLOBALS->mainwindow, GINT_TO_POINTER(FALSE));
538 }
539
540 static void ui_mainwindow_action_openbak(void)
541 {
542 ui_mainwindow_open(GLOBALS->mainwindow, GINT_TO_POINTER(TRUE));
543 }
544
545 static void ui_mainwindow_action_save(void)
546 {
547 ui_mainwindow_save(GLOBALS->mainwindow, GINT_TO_POINTER(FALSE));
548 }
549
550 static void ui_mainwindow_action_saveas(void)
551 {
552 ui_mainwindow_save(GLOBALS->mainwindow, GINT_TO_POINTER(TRUE));
553 }
554
555 static void ui_mainwindow_action_revert(void)
556 {
557 ui_mainwindow_revert(GLOBALS->mainwindow, NULL);
558 }
559
560 static void ui_mainwindow_action_close(void)
561 {
562 GtkWidget *widget = GLOBALS->mainwindow;
563
564 if( ui_dialog_msg_savechanges(widget,NULL) == TRUE )
565 {
566 //clear all, and init GLOBALS->xhb_filepath to default
567 ui_mainwindow_clear(widget, GINT_TO_POINTER(TRUE));
568 ui_mainwindow_update(widget, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE+UF_REFRESHALL));
569 }
570
571 }
572
573
574 static void ui_mainwindow_action_quit(void)
575 {
576 gboolean result;
577
578 //emulate the wm close button
579 g_signal_emit_by_name(GLOBALS->mainwindow, "delete-event", NULL, &result);
580 }
581
582
583 static void ui_mainwindow_action_file_statistics(void)
584 {
585 ui_dialog_file_statistics();
586 }
587
588
589 static void ui_mainwindow_action_pluginprefs(void)
590 {
591 ui_mainwindow_showprefs(PREF_PLUGINS);
592 }
593
594
595 static void ui_mainwindow_action_properties(void)
596 {
597 create_defhbfile_dialog();
598 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
599 }
600
601 static void ui_mainwindow_action_anonymize(void)
602 {
603 gint result;
604 gchar *title;
605 gchar *secondtext;
606
607 title = _("Are you sure you want to anonymize the file?");
608
609 secondtext =
610 _("Proceeding will anonymize any text, \n"
611 "like 'account x', 'payee y', 'memo z', ...");
612
613 result = ui_dialog_msg_confirm_alert(
614 GTK_WINDOW(GLOBALS->mainwindow),
615 title,
616 secondtext,
617 _("_Anonymize")
618 );
619
620 //#1707201
621 //if( result == GTK_RESPONSE_CANCEL )
622 // return;
623 if( result == GTK_RESPONSE_OK )
624 {
625 hbfile_anonymize();
626 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
627 }
628 }
629
630
631 static void ui_mainwindow_action_defcurrency(void)
632 {
633 ui_cur_manage_dialog();
634 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
635 }
636
637
638 static void ui_mainwindow_action_defaccount(void)
639 {
640 ui_acc_manage_dialog();
641
642 //our global list has changed, so update the treeview
643 //todo: optimize this, should not call compute balance here
644 account_compute_balances ();
645 ui_hub_account_populate(GLOBALS->mainwindow, NULL);
646
647 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE));
648 }
649
650 static void ui_mainwindow_action_defpayee(void)
651 {
652 ui_pay_manage_dialog();
653 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
654 }
655
656 static void ui_mainwindow_action_defcategory(void)
657 {
658 ui_cat_manage_dialog();
659 //todo:why refresh upcoming here??
660 //ui_mainwindow_populate_upcoming(GLOBALS->mainwindow, NULL);
661 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
662 }
663
664
665 //TODO: not ideal to do this
666 void ui_mainwindow_defarchive(Archive *arc)
667 {
668 struct hbfile_data *data;
669 GtkTreeModel *model;
670
671 data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
672
673 // upcoming list have direct pointer to the arc (which may change during edit)
674 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_upc));
675 gtk_list_store_clear (GTK_LIST_STORE(model));
676
677 ui_arc_manage_dialog(arc);
678
679 ui_hub_scheduled_populate(GLOBALS->mainwindow, NULL);
680
681 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
682 }
683
684
685 static void ui_mainwindow_action_defarchive(void)
686 {
687 ui_mainwindow_defarchive(NULL);
688 }
689
690
691 static void ui_mainwindow_action_defbudget(void)
692 {
693 ui_bud_manage_dialog();
694 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
695 }
696
697
698 static void ui_mainwindow_action_defassign(void)
699 {
700
701 ui_asg_manage_dialog();
702
703 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
704 }
705
706
707 static void ui_mainwindow_action_deftag(void)
708 {
709
710 ui_tag_manage_dialog();
711
712 //ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
713 }
714
715
716 static void ui_mainwindow_action_preferences(void)
717 {
718 ui_mainwindow_showprefs(PREF_GENERAL);
719 }
720
721 static void ui_mainwindow_showprefs(gint page)
722 {
723 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
724
725 defpref_dialog_new(page);
726 if(!PREFS->euro_active)
727 {
728 GtkToggleAction *action = (GtkToggleAction *)gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/AsMinor");
729
730 gtk_toggle_action_set_active(action, FALSE);
731 ui_mainwindow_action_toggle_minor(action);
732 }
733 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_VISUAL+UF_REFRESHALL));
734 }
735
736 /* display action */
737
738 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction *action)
739 {
740 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
741
742 PREFS->wal_toolbar = gtk_toggle_action_get_active(action);
743 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_VISUAL));
744 }
745
746 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction *action)
747 {
748 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
749
750 PREFS->wal_upcoming = gtk_toggle_action_get_active(action);
751 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_VISUAL));
752 }
753
754 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction *action)
755 {
756 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
757
758 PREFS->wal_spending = gtk_toggle_action_get_active(action);
759 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_VISUAL));
760 }
761
762 static void ui_mainwindow_action_toggle_minor(GtkToggleAction *action)
763 {
764 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
765
766 GLOBALS->minor = gtk_toggle_action_get_active(action);
767
768 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_acc));
769 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_upc));
770
771 // top spending
772 gtk_chart_show_minor(GTK_CHART(data->RE_pie), GLOBALS->minor);
773
774 ui_hub_spending_update(data->window, data);
775
776 }
777
778 static void ui_mainwindow_action_showtransactions(void)
779 {
780 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
781 GtkWidget *window;
782
783 //todo:change this
784 if( data->acc )
785 {
786 if( data->acc->window == NULL )
787 {
788 window = register_panel_window_new(data->acc);
789 register_panel_window_init(window, NULL);
790 }
791 else
792 {
793 if(GTK_IS_WINDOW(data->acc->window))
794 gtk_window_present(GTK_WINDOW(data->acc->window));
795
796 }
797 }
798 }
799
800
801 static void ui_mainwindow_action_showalltransactions(void)
802 {
803 GtkWidget *window;
804
805 if( GLOBALS->alltxnwindow == NULL )
806 {
807 window = register_panel_window_new(NULL);
808 register_panel_window_init(window, NULL);
809 }
810 else
811 {
812 if(GTK_IS_WINDOW(GLOBALS->alltxnwindow))
813 gtk_window_present(GTK_WINDOW(GLOBALS->alltxnwindow));
814 }
815
816 }
817
818
819 static void ui_mainwindow_action_addtransactions(void)
820 {
821 ui_mainwindow_addtransactions(GLOBALS->mainwindow, NULL);
822 }
823
824 static void ui_mainwindow_action_checkscheduled(void)
825 {
826 ui_hub_scheduled_postall(GLOBALS->mainwindow, GINT_TO_POINTER(TRUE));
827 }
828
829 static void ui_mainwindow_action_statistic(void)
830 {
831 ui_repdist_window_new();
832 }
833
834 static void ui_mainwindow_action_trendtime(void)
835 {
836 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
837
838 ui_reptime_window_new(data->acc != NULL ? data->acc->key : 0);
839 }
840
841 static void ui_mainwindow_action_budget(void)
842 {
843 repbudget_window_new();
844 }
845
846 static void ui_mainwindow_action_balance(void)
847 {
848 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
849
850 repbalance_window_new(data->acc != NULL ? data->acc->key : 0);
851 }
852
853 static void ui_mainwindow_action_vehiclecost(void)
854 {
855 repcost_window_new();
856 }
857
858 static void ui_mainwindow_action_import(GtkAction *action)
859 {
860 /*const gchar *name;
861 gint filetype = FILETYPE_UNKNOWN;
862
863 name = gtk_action_get_name(action);
864
865 if( g_str_has_suffix (name, "QIF"))
866 filetype= FILETYPE_QIF;
867 else
868 if( g_str_has_suffix (name, "OFX"))
869 filetype= FILETYPE_OFX;
870 else
871 if( g_str_has_suffix (name, "CSV"))
872 filetype= FILETYPE_CSV_HB;*/
873
874 //DB( g_print("action %s type=%d\n", name, filetype) );
875
876 ui_import_assistant_new(NULL);
877
878 }
879
880
881 static void ui_mainwindow_action_about(void)
882 {
883 hbfile_about();
884
885
886 }
887
888
889 static void ui_mainwindow_action_export(void)
890 {
891 gchar *filename;
892
893 if( ui_file_chooser_qif(NULL, &filename) == TRUE )
894 {
895 hb_export_qif_account_all(filename);
896 g_free( filename );
897 }
898 }
899
900
901 static void ui_mainwindow_action_help(void)
902 {
903 gchar *link;
904
905 link = g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP, NULL );
906 homebank_util_url_show (link);
907 g_free(link);
908 }
909
910
911 static void ui_mainwindow_action_help_releasenotes(void)
912 {
913 gchar *link;
914
915 #ifdef G_OS_WIN32
916 link = g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog.txt", NULL );
917 #else
918 link = g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog", NULL );
919 #endif
920 homebank_util_url_show (link);
921 g_free(link);
922 }
923
924
925 //todo: move this to a ui-assist-welcome.c
926
927 static void ui_mainwindow_action_help_welcome1 (GtkButton *button, gpointer user_data)
928 {
929 gtk_dialog_response (GTK_DIALOG(user_data), 1);
930 }
931
932 static void ui_mainwindow_action_help_welcome2 (GtkButton *button, gpointer user_data)
933 {
934 gtk_dialog_response (GTK_DIALOG(user_data), 2);
935 }
936
937 static void ui_mainwindow_action_help_welcome3 (GtkButton *button, gpointer user_data)
938 {
939 gtk_dialog_response (GTK_DIALOG(user_data), 3);
940 }
941
942 static void ui_mainwindow_action_help_welcome4 (GtkButton *button, gpointer user_data)
943 {
944 gtk_dialog_response (GTK_DIALOG(user_data), 4);
945 }
946
947 static void ui_mainwindow_action_help_welcome5 (GtkButton *button, gpointer user_data)
948 {
949 gtk_dialog_response (GTK_DIALOG(user_data), 5);
950 }
951
952 void ui_mainwindow_action_help_welcome(void)
953 {
954 GtkWidget *dialog, *content_area;
955 GtkWidget *mainvbox, *widget, *label;
956
957 dialog = gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
958 GTK_WINDOW(GLOBALS->mainwindow),
959 0,
960 _("_Close"),
961 GTK_RESPONSE_ACCEPT,
962 NULL);
963
964 content_area = gtk_dialog_get_content_area(GTK_DIALOG (dialog));
965
966 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
967 gtk_box_pack_start (GTK_BOX (content_area), mainvbox, FALSE, FALSE, 0);
968 gtk_container_set_border_width (GTK_CONTAINER(mainvbox), SPACING_MEDIUM);
969
970 label = make_label (_("HomeBank"), 0, 0);
971 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
972 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, 0);
973
974 label = make_label (_("Free, easy, personal accounting for everyone"), 0, 0);
975 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, 0);
976
977 widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
978 gtk_box_pack_start (GTK_BOX (content_area), widget, FALSE, FALSE, 0);
979
980 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_MEDIUM);
981 gtk_box_pack_start (GTK_BOX (content_area), mainvbox, TRUE, TRUE, 0);
982 gtk_container_set_border_width (GTK_CONTAINER(mainvbox), SPACING_MEDIUM);
983
984 label = make_label (_("What do you want to do:"), 0, 0);
985 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
986 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, 0);
987
988 widget = gtk_button_new_with_mnemonic(_("Read HomeBank _Manual"));
989 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
990 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome1), dialog);
991
992 widget = gtk_button_new_with_mnemonic(_("Configure _preferences"));
993 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
994 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome2), dialog);
995
996 widget = gtk_button_new_with_mnemonic(_("Create a _new file"));
997 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
998 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome3), dialog);
999
1000 widget = gtk_button_new_with_mnemonic(_("_Open an existing file"));
1001 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
1002 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome4), dialog);
1003
1004 widget = gtk_button_new_with_mnemonic(_("Open the _example file"));
1005 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
1006 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome5), dialog);
1007
1008 //connect all our signals
1009 g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &dialog);
1010
1011 gtk_widget_show_all (dialog);
1012
1013 //wait for the user
1014 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
1015
1016 // cleanup and destroy
1017 gtk_widget_destroy (dialog);
1018
1019 // do appropriate action
1020 switch(result)
1021 {
1022 case 1:
1023 ui_mainwindow_action_help();
1024 break;
1025 case 2:
1026 ui_mainwindow_action_preferences();
1027 break;
1028 case 3:
1029 ui_mainwindow_action_new();
1030 break;
1031 case 4:
1032 ui_mainwindow_action_open();
1033 break;
1034 case 5:
1035 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL));
1036 ui_mainwindow_open_internal(GLOBALS->mainwindow, NULL);
1037 break;
1038 }
1039
1040 }
1041
1042
1043 static void ui_mainwindow_action_help_updates(void)
1044 {
1045 const gchar *link = HOMEBANK_URL_HELP_UPDATES;
1046
1047 homebank_util_url_show (link);
1048 }
1049
1050
1051 static void ui_mainwindow_action_help_online(void)
1052 {
1053 const gchar *link = HOMEBANK_URL_HELP_ONLINE;
1054
1055 homebank_util_url_show (link);
1056 }
1057
1058
1059 static void ui_mainwindow_action_help_translate(void)
1060 {
1061 const gchar *link = HOMEBANK_URL_HELP_TRANSLATE;
1062
1063 homebank_util_url_show (link);
1064 }
1065
1066
1067 static void ui_mainwindow_action_help_problem(void)
1068 {
1069 const gchar *link = HOMEBANK_URL_HELP_PROBLEM;
1070
1071 homebank_util_url_show (link);
1072 }
1073
1074
1075 /* hbfile functions -------------------- */
1076
1077
1078 /*
1079 **
1080 */
1081 static void ui_mainwindow_selection(GtkTreeSelection *treeselection, gpointer user_data)
1082 {
1083 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection)), GINT_TO_POINTER(UF_SENSITIVE));
1084 }
1085
1086
1087 static void ui_mainwindow_close_openbooks(void)
1088 {
1089 GList *lacc, *elt;
1090
1091 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
1092
1093 lacc = elt = g_hash_table_get_values(GLOBALS->h_acc);
1094 while (elt != NULL)
1095 {
1096 Account *item = elt->data;
1097
1098 if(item->window)
1099 {
1100 gtk_widget_destroy(GTK_WIDGET(item->window));
1101 item->window = NULL;
1102 }
1103
1104 elt = g_list_next(elt);
1105 }
1106 g_list_free(lacc);
1107
1108 }
1109
1110
1111
1112 /*
1113 **
1114 */
1115 void ui_mainwindow_clear(GtkWidget *widget, gpointer user_data)
1116 {
1117 struct hbfile_data *data;
1118 gboolean file_clear = GPOINTER_TO_INT(user_data);
1119
1120 DB( g_print("\n[ui-mainwindow] clear\n") );
1121
1122 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1123
1124 // Close opened account window
1125 // Clear TreeView
1126 ui_mainwindow_close_openbooks();
1127 gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_acc))));
1128 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_upc))));
1129 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_top))));
1130
1131 data->showall = FALSE;
1132 ui_hub_account_setup(data);
1133
1134 hbfile_cleanup(file_clear);
1135 hbfile_setup(file_clear);
1136
1137 }
1138
1139
1140 /*
1141 ** add some transactions directly
1142 */
1143 void ui_mainwindow_addtransactions(GtkWidget *widget, gpointer user_data)
1144 {
1145 struct hbfile_data *data;
1146 GtkWidget *window;
1147 gint result = 1;
1148 guint32 date;
1149 gint account, count;
1150
1151 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1152
1153 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1154
1155 /* init the transaction */
1156 date = homebank_app_date_get_julian();
1157
1158 //#1656531
1159 account = 0;
1160 if(data->acc != NULL)
1161 account = data->acc->key;
1162
1163 window = create_deftransaction_window(GTK_WINDOW(data->window), TRANSACTION_EDIT_ADD, FALSE, account);
1164 count = 0;
1165 while(result == HB_RESPONSE_ADD || result == HB_RESPONSE_ADDKEEP)
1166 {
1167 Transaction *ope;
1168
1169 /* fill in the transaction */
1170 if( result == HB_RESPONSE_ADD )
1171 {
1172 ope = da_transaction_malloc();
1173 ope->date = date;
1174 ope->kacc = account;
1175
1176 if( PREFS->heritdate == FALSE ) //fix: 318733
1177 ope->date = GLOBALS->today;
1178
1179 da_transaction_set_default_template(ope);
1180 }
1181
1182 // normally we can't be in addkeep without initialized ope with add
1183
1184 deftransaction_set_transaction(window, ope);
1185
1186 result = gtk_dialog_run (GTK_DIALOG (window));
1187
1188 DB( g_print(" - dialog result is %d\n", result) );
1189
1190 if(result == HB_RESPONSE_ADD || result == HB_RESPONSE_ADDKEEP || result == GTK_RESPONSE_ACCEPT)
1191 {
1192 deftransaction_get(window, NULL);
1193 transaction_add(GTK_WINDOW(GLOBALS->mainwindow), ope);
1194
1195 DB( g_print(" - added 1 transaction to %d\n", ope->kacc) );
1196
1197 ui_hub_account_populate(GLOBALS->mainwindow, NULL);
1198
1199 count++;
1200 //todo: still usefull ? store last date
1201 date = ope->date;
1202 }
1203
1204 if( result == HB_RESPONSE_ADD )
1205 {
1206 da_transaction_free(ope);
1207 ope = NULL;
1208 }
1209
1210 }
1211
1212
1213 deftransaction_dispose(window, NULL);
1214 gtk_widget_destroy (window);
1215
1216 /* todo optimize this */
1217 if(count > 0)
1218 {
1219 GLOBALS->changes_count += count;
1220 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE+UF_REFRESHALL));
1221 }
1222 }
1223
1224
1225 gboolean ui_mainwindow_open_backup_check_confirm(gchar *filepath)
1226 {
1227 gboolean retval = FALSE;
1228 gchar *basename, *secondtext;
1229 gboolean result;
1230
1231 basename = g_path_get_basename(filepath);
1232 secondtext = g_strdup_printf (
1233 _("Your are about to open the backup file '%s'.\n\nAre you sure you want to do this ?"), basename);
1234
1235 result = ui_dialog_msg_confirm_alert(
1236 GTK_WINDOW(GLOBALS->mainwindow),
1237 _("Open the backup file ?"),
1238 secondtext,
1239 _("_Open backup")
1240 );
1241
1242 g_free(secondtext);
1243 g_free(basename);
1244
1245 if( result == GTK_RESPONSE_OK )
1246 retval = TRUE;
1247
1248 return retval;
1249 }
1250
1251
1252 /*
1253 **
1254 */
1255 void ui_mainwindow_open(GtkWidget *widget, gpointer user_data)
1256 {
1257 //struct hbfile_data *data;
1258 gboolean bakmode = GPOINTER_TO_INT(user_data);;
1259 gboolean doopen = TRUE;
1260 gchar *filename = NULL;
1261
1262 DB( g_print("\n[ui-mainwindow] open\n") );
1263
1264 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1265
1266 //#1791554 do ask for save confirm
1267 if( bakmode != TRUE )
1268 doopen = ui_dialog_msg_savechanges(widget,NULL);
1269
1270 if( doopen == TRUE )
1271 {
1272 if( ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN, &filename, bakmode) == TRUE )
1273 {
1274 //#1710955 test for backup open
1275 if( hbfile_file_isbackup(filename) )
1276 {
1277 if( ui_mainwindow_open_backup_check_confirm(filename) == TRUE )
1278 {
1279 GLOBALS->hbfile_is_bak = TRUE;
1280 }
1281 else
1282 {
1283 g_free(filename);
1284 return;
1285 }
1286 }
1287
1288 hbfile_change_filepath(filename);
1289 ui_mainwindow_open_internal(widget, NULL);
1290 }
1291 }
1292 }
1293
1294
1295 /*
1296 * open the file stored in GLOBALS->xhb_filepath
1297 */
1298 void ui_mainwindow_open_internal(GtkWidget *widget, gpointer user_data)
1299 {
1300 struct hbfile_data *data;
1301 gint r;
1302
1303 DB( g_print("\n[ui-mainwindow] open internal\n") );
1304
1305 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1306
1307 if( GLOBALS->xhb_filepath != NULL )
1308 {
1309 DB( g_print(" - filename: '%s'\n", GLOBALS->xhb_filepath) );
1310
1311 ui_mainwindow_clear(GLOBALS->mainwindow, GINT_TO_POINTER(FALSE));
1312 GLOBALS->hbfile_is_new = FALSE;
1313
1314 r = homebank_load_xml(GLOBALS->xhb_filepath);
1315 if( r == XML_OK )
1316 {
1317 DB( g_print(" - file loaded ok : rcode=%d\n", r) );
1318
1319 GLOBALS->xhb_timemodified = hbfile_file_get_time_modified(GLOBALS->xhb_filepath);
1320 hbfile_file_hasrevert(GLOBALS->xhb_filepath);
1321
1322 if(PREFS->appendscheduled)
1323 scheduled_post_all_pending();
1324
1325 if(PREFS->do_update_currency)
1326 ui_cur_manage_dialog_update_currencies(GTK_WINDOW(GLOBALS->mainwindow));
1327
1328 homebank_lastopenedfiles_save();
1329
1330 //todo: delete this after computing done at xml read
1331 account_compute_balances();
1332
1333 ui_mainwindow_recent_add(data, GLOBALS->xhb_filepath);
1334 }
1335 else
1336 {
1337 gchar *msg = _("Unknown error");
1338
1339 switch(r)
1340 {
1341 case XML_IO_ERROR:
1342 msg = _("I/O error for file '%s'.");
1343 break;
1344 case XML_FILE_ERROR:
1345 msg = _("The file '%s' is not a valid HomeBank file.");
1346 break;
1347 case XML_VERSION_ERROR:
1348 msg = _("The file '%s' was saved with a higher version of HomeBank\nand cannot be loaded by the current version.");
1349 break;
1350 }
1351
1352 ui_dialog_msg_infoerror(GTK_WINDOW(data->window), GTK_MESSAGE_ERROR,
1353 _("File error"),
1354 msg,
1355 GLOBALS->xhb_filepath
1356 );
1357
1358 ui_mainwindow_clear(GLOBALS->mainwindow, GINT_TO_POINTER(TRUE));
1359
1360 }
1361
1362 ui_hub_account_populate(GLOBALS->mainwindow, NULL);
1363 ui_hub_scheduled_populate(GLOBALS->mainwindow, NULL);
1364 ui_hub_spending_populate(GLOBALS->mainwindow, NULL);
1365 ui_hub_transaction_populate(data);
1366
1367 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_VISUAL));
1368 }
1369
1370
1371 }
1372
1373
1374 /*
1375 **
1376 */
1377 void ui_mainwindow_save(GtkWidget *widget, gpointer user_data)
1378 {
1379 struct hbfile_data *data;
1380 gboolean saveas = GPOINTER_TO_INT(user_data);
1381 gchar *filename = NULL;
1382 gint r = XML_UNSET;
1383
1384 DB( g_print("\n[ui-mainwindow] save\n") );
1385
1386 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1387
1388 if( GLOBALS->hbfile_is_new == TRUE )
1389 saveas = 1;
1390
1391 //#1710955 test for backup open
1392 if( GLOBALS->hbfile_is_bak == TRUE )
1393 {
1394 //todo: later for backup, should also remove datetime and .bak
1395 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS->xhb_filepath, "xhb"));
1396 saveas = 1;
1397 }
1398
1399 if(saveas == 1)
1400 {
1401 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE, &filename, FALSE) == TRUE)
1402 {
1403 DB( g_print(" + should save as '%s'\n", filename) );
1404 homebank_file_ensure_xhb(filename);
1405 homebank_backup_current_file();
1406 r = homebank_save_xml(GLOBALS->xhb_filepath);
1407 GLOBALS->hbfile_is_new = FALSE;
1408 GLOBALS->hbfile_is_bak = FALSE;
1409 }
1410 else
1411 return;
1412 }
1413 else
1414 {
1415 guint64 time_modified = hbfile_file_get_time_modified (GLOBALS->xhb_filepath);
1416 gint result = GTK_RESPONSE_OK;
1417
1418 DB( g_print(" + should quick save '%s'\n + time: open=%lu :: now=%lu\n", GLOBALS->xhb_filepath, GLOBALS->xhb_timemodified, time_modified) );
1419
1420 if( GLOBALS->xhb_timemodified != time_modified )
1421 {
1422 result = ui_dialog_msg_confirm_alert(
1423 GTK_WINDOW(GLOBALS->mainwindow),
1424 _("The file has been modified since reading it."),
1425 _("If you save it, all the external changes could be lost. Save it anyway?"),
1426 _("S_ave Anyway")
1427 );
1428
1429 if( result != GTK_RESPONSE_OK )
1430 return;
1431 }
1432
1433 DB( g_print(" + saving...\n") );
1434 homebank_file_ensure_xhb(NULL);
1435 homebank_backup_current_file();
1436 r = homebank_save_xml(GLOBALS->xhb_filepath);
1437 }
1438
1439 if(r == XML_OK)
1440 {
1441 DB( g_print(" + OK...\n") );
1442 GLOBALS->changes_count = 0;
1443 GLOBALS->xhb_timemodified = hbfile_file_get_time_modified (GLOBALS->xhb_filepath);
1444 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_VISUAL));
1445 }
1446 else
1447 {
1448 gchar *msg = _("I/O error for file '%s'.");
1449
1450 ui_dialog_msg_infoerror(GTK_WINDOW(data->window), GTK_MESSAGE_ERROR,
1451 _("File error"),
1452 msg,
1453 GLOBALS->xhb_filepath
1454 );
1455 }
1456 }
1457
1458
1459 void ui_mainwindow_update(GtkWidget *widget, gpointer user_data)
1460 {
1461 struct hbfile_data *data;
1462 gint flags;
1463
1464 DB( g_print("\n[ui-mainwindow] update %p\n", user_data) );
1465
1466 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1467 //data = INST_DATA(widget);
1468
1469 flags = GPOINTER_TO_INT(user_data);
1470
1471 /* set window title */
1472 if(flags & UF_TITLE)
1473 {
1474 gchar *basename;
1475 gchar *changed;
1476
1477 DB( g_print(" 1: wintitle %p\n", data->wintitle) );
1478
1479 basename = g_path_get_basename(GLOBALS->xhb_filepath);
1480
1481 DB( g_print(" global changes: %d\n", GLOBALS->changes_count) );
1482
1483 g_free(data->wintitle);
1484
1485 changed = (GLOBALS->changes_count > 0) ? "*" : "";
1486
1487 #if MYDEBUG == 1
1488 data->wintitle = g_strdup_printf("%s%s (%d)- %s - " PROGNAME, changed, basename, GLOBALS->changes_count, GLOBALS->owner);
1489 #else
1490 data->wintitle = g_strdup_printf("%s%s - %s - " PROGNAME, changed, basename, GLOBALS->owner);
1491 #endif
1492
1493 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), data->wintitle);
1494
1495 g_free(basename);
1496 }
1497
1498 /* update disabled things */
1499 if(flags & UF_SENSITIVE)
1500 {
1501 GtkTreeSelection *selection;
1502 GtkTreeModel *model;
1503 GtkTreeIter iter;
1504 GtkTreePath *path;
1505 gboolean active,sensitive;
1506
1507 DB( g_print(" 2: disabled, opelist count\n") );
1508
1509 //#1656531
1510 data->acc = NULL;
1511
1512 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_acc));
1513 active = gtk_tree_selection_get_selected(selection, &model, &iter);
1514 if(active)
1515 {
1516 Account *acc;
1517 gint depth;
1518
1519 path = gtk_tree_model_get_path(model, &iter);
1520 depth = gtk_tree_path_get_depth(path);
1521
1522 if( depth > 1 )
1523 {
1524 DB( g_print(" depth is %d\n", depth) );
1525
1526 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, LST_DSPACC_DATAS, &acc, -1);
1527 data->acc = acc;
1528 }
1529 else
1530 active = FALSE;
1531 }
1532
1533 DB( g_print(" changes %d - new %d\n", GLOBALS->changes_count, GLOBALS->hbfile_is_new) );
1534
1535 // save
1536 sensitive = (GLOBALS->changes_count != 0 ) ? TRUE : FALSE;
1537 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/Save"), sensitive);
1538
1539 // backup
1540 sensitive = ( (GLOBALS->changes_count != 0) && GLOBALS->xhb_hasrevert ) ? TRUE : FALSE;
1541 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/Revert"), sensitive);
1542 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/OpenBak"), sensitive);
1543
1544 // define off ?
1545 sensitive = GLOBALS->define_off == 0 ? TRUE : FALSE;
1546 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Account"), sensitive);
1547 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Payee"), sensitive);
1548 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Category"), sensitive);
1549 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Budget"), sensitive);
1550 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/EditMenu/Preferences"), sensitive);
1551
1552 // empty account list: disable Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
1553 sensitive = da_acc_length() > 0 ? TRUE : FALSE;
1554 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/Close"), sensitive);
1555 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Archive"), sensitive);
1556 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/AddTxn"), sensitive);
1557 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/ShowTxn"), sensitive);
1558 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RStatistics"), sensitive);
1559 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RTrendTime"), sensitive);
1560 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RBudget"), sensitive);
1561 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RBalance"), sensitive);
1562 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RVehiculeCost"), sensitive);
1563
1564 // empty category list: disable Budget
1565 sensitive = da_cat_length() > 1 ? TRUE : FALSE;
1566 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Budget"), sensitive);
1567
1568 //#1501129 no need to disable, P & C can be created from assign dialog
1569 //sensitive = ((da_cat_length() > 1) || (da_pay_length() > 1)) ? TRUE : FALSE;
1570 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Assign"), sensitive);
1571
1572 // empty archive list: disable scheduled check
1573 sensitive = g_list_length(GLOBALS->arc_list) > 0 ? TRUE : FALSE;
1574 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/AddScheduled"), sensitive);
1575
1576 // no active account: disable Edit, Over
1577 sensitive = (active == TRUE ) ? TRUE : FALSE;
1578 if(data->acc && data->acc->window != NULL)
1579 sensitive = FALSE;
1580 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/ShowTxn"), sensitive);
1581 }
1582
1583 /* update toolbar, list */
1584 if(flags & UF_VISUAL)
1585 {
1586 DB( g_print(" 8: visual\n") );
1587
1588 if(PREFS->toolbar_style == 0)
1589 gtk_toolbar_unset_style(GTK_TOOLBAR(data->toolbar));
1590 else
1591 gtk_toolbar_set_style(GTK_TOOLBAR(data->toolbar), PREFS->toolbar_style-1);
1592
1593 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data->LV_acc), PREFS->grid_lines);
1594 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_acc));
1595
1596 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data->LV_upc), PREFS->grid_lines);
1597 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_upc));
1598
1599 DB( g_print(" - show toolbar=%d\n", PREFS->wal_toolbar) );
1600 if(PREFS->wal_toolbar)
1601 gtk_widget_show(GTK_WIDGET(data->toolbar));
1602 else
1603 gtk_widget_hide(GTK_WIDGET(data->toolbar));
1604
1605
1606 DB( g_print(" - show top_spending=%d\n", PREFS->wal_spending) );
1607
1608 gtk_combo_box_set_active(GTK_COMBO_BOX(data->CY_range), PREFS->date_range_wal);
1609
1610 if(PREFS->wal_spending)
1611 gtk_widget_show(GTK_WIDGET(data->GR_top));
1612 else
1613 gtk_widget_hide(GTK_WIDGET(data->GR_top));
1614
1615
1616
1617 DB( g_print(" - show upcoming=%d\n", PREFS->wal_upcoming) );
1618 if(PREFS->wal_upcoming)
1619 gtk_widget_show(GTK_WIDGET(data->GR_upc));
1620 else
1621 gtk_widget_hide(GTK_WIDGET(data->GR_upc));
1622
1623 DB( g_print(" minor %d\n", PREFS->euro_active) );
1624 gtk_action_set_visible(gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/AsMinor"), PREFS->euro_active);
1625 }
1626
1627 /* update balances */
1628 if(flags & UF_BALANCE)
1629 {
1630
1631 DB( g_print(" 4: balances\n") );
1632
1633 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_acc));
1634
1635 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
1636
1637 /*
1638 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[0]), data->bank, minor);
1639 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[1]), data->today, minor);
1640 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[2]), data->future, minor);
1641 */
1642 }
1643
1644 if(flags & UF_REFRESHALL)
1645 {
1646 DB( g_print(" 16: refreshall\n") );
1647
1648 ui_hub_account_populate(GLOBALS->mainwindow, NULL);
1649 ui_hub_spending_populate(GLOBALS->mainwindow, NULL);
1650 ui_hub_scheduled_populate(GLOBALS->mainwindow, NULL);
1651 ui_hub_transaction_populate(data);
1652 }
1653
1654
1655 }
1656
1657
1658
1659 static void
1660 ui_mainwindow_onRowActivated (GtkTreeView *treeview,
1661 GtkTreePath *path,
1662 GtkTreeViewColumn *col,
1663 gpointer userdata)
1664 {
1665 GtkTreeModel *model;
1666 GtkTreeIter iter;
1667
1668 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
1669
1670 model = gtk_tree_view_get_model(treeview);
1671
1672 if (gtk_tree_model_get_iter(model, &iter, path))
1673 {
1674 Account *acc;
1675
1676 gtk_tree_model_get(model, &iter, LST_DSPACC_DATAS, &acc, -1);
1677
1678 if( acc != NULL )
1679 {
1680
1681 DB( g_print ("Double-clicked row contains name %s\n", acc->name) );
1682
1683 ui_mainwindow_action_showtransactions();
1684
1685 //g_free(name);
1686 }
1687 }
1688 }
1689
1690
1691 static void ui_mainwindow_destroy(GtkTreeView *treeview, gpointer user_data)
1692 {
1693 DB( g_print("\n[ui-mainwindow] destroy\n") );
1694
1695 }
1696
1697
1698 /*
1699 **
1700 */
1701 static gboolean ui_mainwindow_dispose(GtkWidget *widget, GdkEvent *event, gpointer user_data)
1702 {
1703 struct hbfile_data *data = user_data;
1704 struct WinGeometry *wg;
1705 gboolean retval = FALSE;
1706
1707 GValue widget_value = G_VALUE_INIT;
1708 ext_hook("main_window_disposal", EXT_OBJECT(&widget_value, widget), NULL);
1709
1710 DB( g_print("\n[ui-mainwindow] delete-event\n") );
1711
1712 //store position and size
1713 wg = &PREFS->wal_wg;
1714 gtk_window_get_position(GTK_WINDOW(widget), &wg->l, &wg->t);
1715 gtk_window_get_size(GTK_WINDOW(widget), &wg->w, &wg->h);
1716 GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(widget));
1717 GdkWindowState state = gdk_window_get_state(gdk_window);
1718 wg->s = (state & GDK_WINDOW_STATE_MAXIMIZED) ? 1 : 0;
1719 DB( g_print(" window: l=%d, t=%d, w=%d, h=%d s=%d, state=%d\n", wg->l, wg->t, wg->w, wg->h, wg->s, state & GDK_WINDOW_STATE_MAXIMIZED) );
1720
1721 PREFS->wal_vpaned = gtk_paned_get_position(GTK_PANED(data->vpaned));
1722 PREFS->wal_hpaned = gtk_paned_get_position(GTK_PANED(data->hpaned));
1723 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS->wal_vpaned, PREFS->wal_hpaned) );
1724
1725 if(PREFS->pnl_list_tab)
1726 g_free(PREFS->pnl_list_tab);
1727 PREFS->pnl_list_tab = g_strdup(gtk_stack_get_visible_child_name(GTK_STACK(data->stack)));
1728
1729 //todo
1730 if(ui_dialog_msg_savechanges(widget, NULL) == FALSE)
1731 {
1732 retval = TRUE;
1733 }
1734 else
1735 {
1736 //todo: retval is useless and below should move to destroy
1737 retval = TRUE;
1738 gtk_widget_destroy(data->LV_top);
1739
1740 g_free(data->wintitle);
1741 da_flt_free(data->filter);
1742 g_free(user_data);
1743
1744 gtk_main_quit();
1745 }
1746
1747 //TRUE:stop other handlers from being invoked for the event | FALSE: propagate
1748 return retval;
1749 }
1750
1751
1752 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser *chooser, struct hbfile_data *data)
1753 {
1754 gchar *uri, *path;
1755 GError *error = NULL;
1756
1757 uri = gtk_recent_chooser_get_current_uri (chooser);
1758
1759 path = g_filename_from_uri (uri, NULL, NULL);
1760 if (error)
1761 {
1762 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri, error->message);
1763 g_error_free (error);
1764 return;
1765 }
1766
1767 if( ui_dialog_msg_savechanges(data->window, NULL) == TRUE )
1768 {
1769
1770 //todo: FixMe
1771 /*
1772 if (! load)
1773 {
1774 gpw_recent_remove (gpw, path);
1775 }
1776 */
1777
1778 hbfile_change_filepath(path);
1779 ui_mainwindow_open_internal(data->window, NULL);
1780 }
1781 else
1782 {
1783 g_free (path);
1784 }
1785 g_free (uri);
1786 }
1787
1788
1789 void ui_mainwindow_recent_add (struct hbfile_data *data, const gchar *path)
1790 {
1791 GtkRecentData *recent_data;
1792 gchar *uri;
1793 GError *error = NULL;
1794
1795 DB( g_print("\n[ui-mainwindow] recent_add\n") );
1796
1797 DB( g_print(" - file has .xhb suffix = %d\n", g_str_has_suffix (path, ".xhb") ) );
1798
1799 if( g_str_has_suffix (path, ".xhb") == FALSE ) //ignore reverted file
1800 return;
1801
1802 uri = g_filename_to_uri (path, NULL, &error);
1803 if (error)
1804 {
1805 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri, error->message);
1806 g_error_free (error);
1807 return;
1808 }
1809
1810 recent_data = g_slice_new (GtkRecentData);
1811
1812 recent_data->display_name = NULL;
1813 recent_data->description = NULL;
1814 recent_data->mime_type = "application/x-homebank";
1815 recent_data->app_name = (gchar *) g_get_application_name ();
1816 recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
1817 recent_data->groups = NULL;
1818 recent_data->is_private = FALSE;
1819
1820 if (!gtk_recent_manager_add_full (data->recent_manager,
1821 uri,
1822 recent_data))
1823 {
1824 g_warning ("Unable to add '%s' to the list of recently used documents", uri);
1825 }
1826
1827 g_free (uri);
1828 g_free (recent_data->app_exec);
1829 g_slice_free (GtkRecentData, recent_data);
1830
1831 }
1832
1833
1834
1835
1836
1837 enum
1838 {
1839 TARGET_URI_LIST
1840 };
1841
1842 static GtkTargetEntry drop_types[] =
1843 {
1844 {"text/uri-list", 0, TARGET_URI_LIST}
1845 };
1846
1847 static void ui_mainwindow_drag_data_received (GtkWidget *widget,
1848 GdkDragContext *context,
1849 gint x, gint y,
1850 GtkSelectionData *selection_data,
1851 guint info, guint time, GtkWindow *window)
1852 {
1853 gchar **uris, **str;
1854 gchar *newseldata;
1855 gint n_uris, filetype, slen;
1856 GError *error = NULL;
1857
1858 if (info != TARGET_URI_LIST)
1859 return;
1860
1861 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
1862
1863 /* On MS-Windows, it looks like `selection_data->data' is not NULL terminated. */
1864 slen = gtk_selection_data_get_length(selection_data);
1865 newseldata = g_new (gchar, slen + 1);
1866 memcpy (newseldata, gtk_selection_data_get_data(selection_data), slen);
1867 newseldata[slen] = 0;
1868 //DB( g_print(" - seldata ='%s'\n", gtk_selection_data_get_data(selection_data) ) );
1869 //DB( g_print(" - newseldata ='%s'\n", newseldata ) );
1870
1871 uris = g_uri_list_extract_uris (newseldata);
1872 n_uris = g_strv_length(uris);
1873 DB( g_print(" - dragged %d files (len=%d)\n", n_uris, slen ) );
1874
1875 g_free(newseldata);
1876
1877 //single file: check for xhb
1878 if(n_uris == 1)
1879 {
1880 filetype = hb_filename_type_get_by_extension(*uris);
1881
1882 DB( g_print(" - filetype is homebank (%d)\n", filetype) );
1883
1884 if( filetype == FILETYPE_HOMEBANK )
1885 {
1886 gchar *path = g_filename_from_uri (*uris, NULL, &error);
1887
1888 if( path != NULL )
1889 {
1890 DB( g_print(" - path is '%s'\n", path) );
1891 hbfile_change_filepath(g_strdup(path));
1892 ui_mainwindow_open_internal(GTK_WIDGET(window), NULL);
1893 goto end_drop;
1894 }
1895 else
1896 {
1897 g_warning ("Could not convert uri to local path: %s", error->message);
1898 g_error_free (error);
1899 }
1900 g_free (path);
1901 }
1902 /* we no more manage error here
1903 ui_dialog_msg_infoerror(GTK_WINDOW(window), GTK_MESSAGE_ERROR,
1904 _("File error"),
1905 _("The file %s is not a valid HomeBank file."),
1906 path);
1907 */
1908 }
1909
1910 //collect known filetype to import
1911 DB( g_print(" - collect %d files\n", n_uris) );
1912
1913 gchar **paths = g_new (gchar *, n_uris + 1);
1914 slen = 0;
1915 for (str = uris; *str; str++)
1916 {
1917 filetype = hb_filename_type_get_by_extension(*str);
1918 if( filetype != FILETYPE_HOMEBANK && filetype != FILETYPE_UNKNOWN )
1919 {
1920 gchar *path = g_filename_from_uri (*str, NULL, NULL);
1921
1922 if( path != NULL )
1923 {
1924 DB( g_print(" - append %d '%s'\n", slen, path ) );
1925 paths[slen++] = path;
1926 }
1927 }
1928 }
1929 paths[slen] = NULL;
1930
1931 if( slen > 0 )
1932 {
1933 ui_import_assistant_new( paths );
1934 }
1935
1936
1937 end_drop:
1938 g_strfreev (uris);
1939 }
1940
1941
1942 static GtkWidget *ui_mainwindow_create_recent_chooser_menu (GtkRecentManager *manager)
1943 {
1944 GtkWidget *recent_menu;
1945 GtkRecentFilter *filter;
1946
1947 recent_menu = gtk_recent_chooser_menu_new_for_manager (manager);
1948 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu), FALSE);
1949 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu), GTK_RECENT_SORT_MRU);
1950 //todo: add a user pref for this
1951 gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER (recent_menu), 10);
1952 gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu), FALSE);
1953 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_menu), TRUE);
1954
1955 filter = gtk_recent_filter_new ();
1956 //gtk_recent_filter_add_application (filter, g_get_application_name());
1957 gtk_recent_filter_add_pattern (filter, "*.[Xx][Hh][Bb]");
1958 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu), filter);
1959
1960 return recent_menu;
1961 }
1962
1963
1964 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data *data, GtkWidget *mainvbox)
1965 {
1966 GtkUIManager *manager;
1967 GtkActionGroup *actions;
1968 GtkAction *action;
1969 GError *error = NULL;
1970
1971 manager = gtk_ui_manager_new ();
1972 data->manager = manager;
1973
1974 gtk_window_add_accel_group (GTK_WINDOW (data->window),
1975 gtk_ui_manager_get_accel_group(manager));
1976
1977 actions = gtk_action_group_new ("MainWindow");
1978 gtk_action_group_set_translation_domain(actions, GETTEXT_PACKAGE);
1979
1980 gtk_action_group_add_actions (actions,
1981 entries,
1982 n_entries,
1983 NULL);
1984
1985 gtk_action_group_add_toggle_actions (actions,
1986 toggle_entries,
1987 n_toggle_entries,
1988 NULL);
1989
1990 gtk_ui_manager_insert_action_group (data->manager, actions, 0);
1991 g_object_unref (actions);
1992 data->actions = actions;
1993
1994 /* set short labels to use in the toolbar */
1995 action = gtk_action_group_get_action(actions, "Open");
1996 g_object_set(action, "short_label", _("Open"), NULL);
1997
1998 //action = gtk_action_group_get_action(action_group, "Save");
1999 //g_object_set(action, "is_important", TRUE, NULL);
2000
2001 action = gtk_action_group_get_action(actions, "Account");
2002 g_object_set(action, "short_label", _("Account"), NULL);
2003
2004 action = gtk_action_group_get_action(actions, "Payee");
2005 g_object_set(action, "short_label", _("Payee"), NULL);
2006
2007 action = gtk_action_group_get_action(actions, "Category");
2008 g_object_set(action, "short_label", _("Category"), NULL);
2009
2010 action = gtk_action_group_get_action(actions, "Archive");
2011 //TRANSLATORS: an archive is stored transaction buffers (kind of bookmark to prefill manual insertion)
2012 g_object_set(action, "short_label", _("Archive"), NULL);
2013
2014 action = gtk_action_group_get_action(actions, "Budget");
2015 g_object_set(action, "short_label", _("Budget"), NULL);
2016
2017 action = gtk_action_group_get_action(actions, "ShowTxn");
2018 g_object_set(action, "short_label", _("Show"), NULL);
2019
2020 action = gtk_action_group_get_action(actions, "AddTxn");
2021 g_object_set(action, "is_important", TRUE, "short_label", _("Add"), NULL);
2022
2023 action = gtk_action_group_get_action(actions, "RStatistics");
2024 g_object_set(action, "short_label", _("Statistics"), NULL);
2025
2026 action = gtk_action_group_get_action(actions, "RBudget");
2027 g_object_set(action, "short_label", _("Budget"), NULL);
2028
2029 action = gtk_action_group_get_action(actions, "RBalance");
2030 g_object_set(action, "short_label", _("Balance"), NULL);
2031
2032 action = gtk_action_group_get_action(actions, "RVehiculeCost");
2033 g_object_set(action, "short_label", _("Vehicle cost"), NULL);
2034
2035 /* now load the UI definition */
2036 gtk_ui_manager_add_ui_from_string (data->manager, ui_info, -1, &error);
2037 if (error != NULL)
2038 {
2039 g_message ("Building menus failed: %s", error->message);
2040 g_error_free (error);
2041 }
2042
2043
2044 data->recent_manager = gtk_recent_manager_get_default ();
2045
2046 data->menubar = gtk_ui_manager_get_widget (manager, "/MenuBar");
2047 gtk_box_pack_start (GTK_BOX (mainvbox),
2048 data->menubar,
2049 FALSE,
2050 FALSE,
2051 0);
2052
2053 /* recent files menu */
2054 data->recent_menu = ui_mainwindow_create_recent_chooser_menu (data->recent_manager);
2055
2056 g_signal_connect (data->recent_menu,
2057 "item-activated",
2058 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb),
2059 data);
2060
2061 GtkWidget *widget = gtk_ui_manager_get_widget (data->manager, "/MenuBar/FileMenu/RecentMenu");
2062 gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), data->recent_menu);
2063
2064
2065 data->toolbar = gtk_ui_manager_get_widget (manager, "/ToolBar");
2066 gtk_box_pack_start (GTK_BOX (mainvbox),
2067 data->toolbar,
2068 FALSE,
2069 FALSE,
2070 0);
2071
2072 /* add the custom Open button to the toolbar */
2073 GtkWidget *image = gtk_image_new_from_icon_name (ICONNAME_HB_FILE_OPEN, GTK_ICON_SIZE_BUTTON);
2074 GtkToolItem *open_button = gtk_menu_tool_button_new(image, _("_Open"));
2075 gtk_tool_item_set_tooltip_text (open_button, _("Open a file"));
2076
2077 GtkWidget *recent_menu = ui_mainwindow_create_recent_chooser_menu (data->recent_manager);
2078 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button), recent_menu);
2079 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button), _("Open a recently used file"));
2080
2081 g_signal_connect (recent_menu,
2082 "item-activated",
2083 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb),
2084 data);
2085
2086 action = gtk_action_group_get_action (data->actions, "Open");
2087 g_object_set (action, "short_label", _("Open"), NULL);
2088 //gtk_action_connect_proxy (action, GTK_WIDGET (open_button));
2089 gtk_activatable_set_related_action (GTK_ACTIVATABLE (open_button), action);
2090
2091 gtk_toolbar_insert (GTK_TOOLBAR (data->toolbar), open_button, 1);
2092
2093 }
2094
2095
2096 /*
2097 ** the window creation
2098 */
2099 GtkWidget *create_hbfile_window(GtkWidget *do_widget)
2100 {
2101 struct hbfile_data *data;
2102 struct WinGeometry *wg;
2103 GtkWidget *mainvbox, *vbox, *box, *vpaned, *hpaned, *sidebar, *stack;
2104 GtkWidget *widget, *page;
2105 GtkWidget *window;
2106 GtkAction *action;
2107
2108 DB( g_print("\n[ui-mainwindow] create main window\n") );
2109
2110 data = g_malloc0(sizeof(struct hbfile_data));
2111 if(!data) return NULL;
2112
2113 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2114
2115 //store our window private data
2116 g_object_set_data(G_OBJECT(window), "inst_data", (gpointer)data);
2117 DB( g_print(" - new window=%p, inst_data=%p\n", window, data) );
2118
2119 // this is our mainwindow, so store it to GLOBALS data
2120 data->window = window;
2121 GLOBALS->mainwindow = window;
2122
2123 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2124 gtk_container_add (GTK_CONTAINER (window), mainvbox);
2125
2126 ui_mainwindow_create_menu_bar_and_toolbar (data, mainvbox);
2127
2128 #if HB_UNSTABLE_SHOW == TRUE
2129 GtkWidget *bar, *label;
2130
2131 bar = gtk_info_bar_new ();
2132 gtk_box_pack_start (GTK_BOX (mainvbox), bar, FALSE, FALSE, 0);
2133 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_WARNING);
2134 label = make_label(NULL, 0.5, 0.5);
2135 gtk_label_set_markup (GTK_LABEL(label), "Unstable Development Version");
2136 gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label, FALSE, FALSE, 0);
2137 #endif
2138
2139 /* Add the main area */
2140 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2141 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
2142 gtk_box_pack_start (GTK_BOX (mainvbox), vbox, TRUE, TRUE, 0);
2143
2144 vpaned = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2145 data->vpaned = vpaned;
2146 gtk_box_pack_start (GTK_BOX (vbox), vpaned, TRUE, TRUE, 0);
2147
2148 hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2149 data->hpaned = hpaned;
2150 gtk_paned_pack1 (GTK_PANED(vpaned), hpaned, FALSE, FALSE);
2151
2152 widget = ui_hub_account_create(data);
2153 //gtk_widget_set_size_request (widget, 100, -1);
2154 gtk_paned_pack1 (GTK_PANED(hpaned), widget, FALSE, FALSE);
2155
2156 widget = ui_hub_spending_create(data);
2157 //gtk_widget_set_size_request (widget, -1, 100);
2158 gtk_paned_pack2 (GTK_PANED(hpaned), widget, TRUE, FALSE);
2159
2160 box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
2161 data->GR_upc = box;
2162 gtk_paned_pack2 (GTK_PANED(vpaned), box, TRUE, FALSE);
2163
2164 sidebar = gtk_stack_sidebar_new ();
2165 gtk_box_pack_start (GTK_BOX (box), sidebar, FALSE, FALSE, 0);
2166
2167 stack = gtk_stack_new ();
2168 //gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN);
2169 gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar), GTK_STACK (stack));
2170 data->stack = stack;
2171 gtk_box_pack_start (GTK_BOX (box), stack, TRUE, TRUE, 0);
2172
2173 page = ui_hub_scheduled_create(data);
2174 gtk_stack_add_titled (GTK_STACK (stack), page, "sched", _("Scheduled"));
2175 //gtk_paned_pack2 (GTK_PANED(vpaned), widget, TRUE, FALSE);
2176
2177 page = ui_hub_transaction_create(data, HUB_TXN_TYPE_FUTURE);
2178 gtk_stack_add_titled (GTK_STACK (stack), page, "futur", _("Future"));
2179
2180 page = ui_hub_transaction_create(data, HUB_TXN_TYPE_REMIND);
2181 gtk_stack_add_titled (GTK_STACK (stack), page, "remin", _("Remind"));
2182
2183
2184 //setup, init and show window
2185 wg = &PREFS->wal_wg;
2186 if(wg->s == 0)
2187 {
2188 gtk_window_move(GTK_WINDOW(window), wg->l, wg->t);
2189 gtk_window_resize(GTK_WINDOW(window), wg->w, wg->h);
2190 }
2191 else
2192 gtk_window_maximize(GTK_WINDOW(window));
2193
2194 gtk_widget_show_all (window);
2195
2196 //#1662197/1660910 moved after resize/show
2197 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS->wal_vpaned, PREFS->wal_hpaned) );
2198
2199 if(PREFS->wal_hpaned > 0)
2200 gtk_paned_set_position(GTK_PANED(data->hpaned), PREFS->wal_hpaned);
2201 if(PREFS->wal_vpaned > 0)
2202 gtk_paned_set_position(GTK_PANED(data->vpaned), PREFS->wal_vpaned);
2203
2204 if( PREFS->pnl_list_tab != NULL )
2205 gtk_stack_set_visible_child_name (GTK_STACK(data->stack), PREFS->pnl_list_tab);
2206
2207
2208 //todo: move this elsewhere
2209 DB( g_print(" - setup stuff\n") );
2210
2211 data->filter = da_flt_malloc();
2212 filter_reset(data->filter);
2213 gtk_combo_box_set_active(GTK_COMBO_BOX(data->CY_range), PREFS->date_range_wal);
2214
2215 action = gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/Toolbar");
2216 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), PREFS->wal_toolbar);
2217 action = gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/Spending");
2218 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), PREFS->wal_spending);
2219 action = gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/BottomLists");
2220 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), PREFS->wal_upcoming);
2221
2222 /* Drag and drop support, set targets to NULL because we add the
2223 default uri_targets below */
2224
2225 /* support for opening a file by dragging onto the project window */
2226 gtk_drag_dest_set (GTK_WIDGET (window),
2227 GTK_DEST_DEFAULT_ALL,
2228 drop_types,
2229 G_N_ELEMENTS (drop_types),
2230 GDK_ACTION_COPY);
2231
2232 g_signal_connect (G_OBJECT (window), "drag-data-received",
2233 G_CALLBACK (ui_mainwindow_drag_data_received), window);
2234
2235 //connect all our signals
2236 DB( g_print(" - connect signals\n") );
2237
2238 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_acc)), "changed", G_CALLBACK (ui_mainwindow_selection), NULL);
2239 g_signal_connect (GTK_TREE_VIEW(data->LV_acc ), "row-activated", G_CALLBACK (ui_mainwindow_onRowActivated), GINT_TO_POINTER(2));
2240
2241 /* GtkWindow events */
2242 g_signal_connect (window, "delete-event", G_CALLBACK (ui_mainwindow_dispose), (gpointer)data);
2243 g_signal_connect (window, "destroy", G_CALLBACK (ui_mainwindow_destroy), NULL);
2244
2245 //gtk_action_group_set_sensitive(data->actions, FALSE);
2246
2247 return window;
2248 }
2249
This page took 0.147647 seconds and 4 git commands to generate.