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