]> Dogcows Code - chaz/homebank/blob - src/dsp_mainwindow.c
Merge branch 'upstream'
[chaz/homebank] / src / dsp_mainwindow.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2016 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 #include "list_upcoming.h"
27 #include "list_topspending.h"
28
29 #include "dsp_account.h"
30 #include "ui-assist-import.h"
31 #include "ui-assist-start.h"
32 #include "ui-account.h"
33 #include "ui-currency.h"
34 #include "ui-payee.h"
35 #include "ui-category.h"
36 #include "ui-archive.h"
37 #include "ui-assign.h"
38 #include "ui-budget.h"
39 #include "ui-pref.h"
40 #include "ui-hbfile.h"
41 #include "ui-transaction.h"
42
43 #include "rep_balance.h"
44 #include "rep_budget.h"
45 #include "rep_stats.h"
46 #include "rep_time.h"
47 #include "rep_vehicle.h"
48
49 #include "gtk-chart.h"
50
51 //#define HOMEBANK_URL_HELP "http://homebank.free.fr/help/"
52 #define HOMEBANK_URL_HELP "index.html"
53 #define HOMEBANK_URL_HELP_ONLINE "https://launchpad.net/homebank/+addquestion"
54 #define HOMEBANK_URL_HELP_TRANSLATE "https://launchpad.net/homebank/+translations"
55 #define HOMEBANK_URL_HELP_PROBLEM "https://launchpad.net/homebank/+filebug"
56
57
58 /****************************************************************************/
59 /* Debug macros */
60 /****************************************************************************/
61 #define MYDEBUG 0
62
63 #if MYDEBUG
64 #define DB(x) (x);
65 #else
66 #define DB(x);
67 #endif
68
69 /* our global datas */
70 extern struct HomeBank *GLOBALS;
71 extern struct Preferences *PREFS;
72 extern gchar *homebank_pixmaps_dir;
73
74
75 /* our functions prototype */
76 static void ui_mainwindow_action_new(void);
77 static void ui_mainwindow_action_open(void);
78 static void ui_mainwindow_action_save(void);
79 static void ui_mainwindow_action_saveas(void);
80 static void ui_mainwindow_action_revert(void);
81 static void ui_mainwindow_action_properties(void);
82 static void ui_mainwindow_action_close(void);
83 static void ui_mainwindow_action_quit(void);
84
85 static void ui_mainwindow_action_defcurrency(void);
86 static void ui_mainwindow_action_defaccount(void);
87 static void ui_mainwindow_action_defpayee(void);
88 static void ui_mainwindow_action_defcategory(void);
89 static void ui_mainwindow_action_defarchive(void);
90 static void ui_mainwindow_action_defbudget(void);
91 static void ui_mainwindow_action_defassign(void);
92 static void ui_mainwindow_action_preferences(void);
93
94 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction *action);
95 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction *action);
96 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction *action);
97 static void ui_mainwindow_action_toggle_minor(GtkToggleAction *action);
98
99 static void ui_mainwindow_action_showtransactions(void);
100 static void ui_mainwindow_action_addtransactions(void);
101 static void ui_mainwindow_action_checkscheduled(void);
102
103 static void ui_mainwindow_action_statistic(void);
104 static void ui_mainwindow_action_trendtime(void);
105 static void ui_mainwindow_action_budget(void);
106 static void ui_mainwindow_action_balance(void);
107 static void ui_mainwindow_action_vehiclecost(void);
108
109 static void ui_mainwindow_action_import(GtkAction *action);
110 static void ui_mainwindow_action_export(void);
111 static void ui_mainwindow_action_anonymize(void);
112 static void ui_mainwindow_action_file_statistics(void);
113
114 static void ui_mainwindow_action_help(void);
115 void ui_mainwindow_action_help_welcome(void);
116 static void ui_mainwindow_action_help_online(void);
117 static void ui_mainwindow_action_help_translate(void);
118 static void ui_mainwindow_action_help_problem(void);
119 static void ui_mainwindow_action_about(void);
120
121
122 static GtkWidget *ui_mainwindow_create_recent_chooser_menu (GtkRecentManager *manager);
123
124 static void ui_mainwindow_populate_topspending(GtkWidget *widget, gpointer user_data);
125
126 void ui_mainwindow_open(GtkWidget *widget, gpointer user_data);
127
128 void ui_mainwindow_save(GtkWidget *widget, gpointer user_data);
129 void ui_mainwindow_revert(GtkWidget *widget, gpointer user_data);
130 void ui_mainwindow_action(GtkWidget *widget, gpointer user_data);
131 void ui_mainwindow_toggle_minor(GtkWidget *widget, gpointer user_data);
132 void ui_mainwindow_clear(GtkWidget *widget, gpointer user_data);
133
134 gboolean ui_dialog_msg_savechanges(GtkWidget *widget, gpointer user_data);
135
136 void ui_mainwindow_update(GtkWidget *widget, gpointer user_data);
137 void ui_mainwindow_addtransactions(GtkWidget *widget, gpointer user_data);
138 void ui_mainwindow_recent_add (struct hbfile_data *data, const gchar *path);
139
140 static void ui_mainwindow_scheduled_populate(GtkWidget *widget, gpointer user_data);
141 void ui_mainwindow_scheduled_postall(GtkWidget *widget, gpointer user_data);
142
143 void ui_mainwindow_recent_add (struct hbfile_data *data, const gchar *path);
144
145 extern gchar *CYA_ACC_TYPE[];
146
147 gchar *CYA_CATSUBCAT[] = {
148 N_("Category"),
149 N_("Subcategory"),
150 NULL
151 };
152
153
154 static GtkActionEntry entries[] = {
155
156 /* name, icon-name, label */
157
158 { "FileMenu" , NULL, N_("_File"), NULL, NULL, NULL },
159 { "ImportMenu" , NULL, N_("_Import"), NULL, NULL, NULL },
160 { "EditMenu" , NULL, N_("_Edit"), NULL, NULL, NULL },
161 { "ViewMenu" , NULL, N_("_View"), NULL, NULL, NULL },
162 { "ManageMenu" , NULL, N_("_Manage"), NULL, NULL, NULL },
163 { "TxnMenu" , NULL, N_("_Transactions"), NULL, NULL, NULL },
164 { "ReportMenu" , NULL, N_("_Reports"), NULL, NULL, NULL },
165 { "ToolsMenu" , NULL, N_("_Tools"), NULL, NULL, NULL },
166 { "HelpMenu" , NULL, N_("_Help"), NULL, NULL, NULL },
167
168 // { "Import" , NULL, N_("Import") },
169 // { "Export" , NULL, N_("Export to") },
170 /* name, icon-name, label, accelerator, tooltip */
171
172 /* FileMenu */
173 { "New" , ICONNAME_NEW , N_("_New") , "<control>N", N_("Create a new file"), G_CALLBACK (ui_mainwindow_action_new) },
174 { "Open" , ICONNAME_OPEN , N_("_Open...") , "<control>O", N_("Open a file"), G_CALLBACK (ui_mainwindow_action_open) },
175 { "Save" , ICONNAME_SAVE , N_("_Save") , "<control>S", N_("Save the current file"), G_CALLBACK (ui_mainwindow_action_save) },
176 { "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) },
177 { "Revert" , ICONNAME_REVERT , N_("Revert") , NULL, N_("Revert to a saved version of this file"), G_CALLBACK (ui_mainwindow_action_revert) },
178
179 { "Properties" , ICONNAME_PROPERTIES , N_("Properties..."), NULL, N_("Configure the file"), G_CALLBACK (ui_mainwindow_action_properties) },
180 { "Close" , ICONNAME_CLOSE , N_("_Close") , "<control>W", N_("Close the current file"), G_CALLBACK (ui_mainwindow_action_close) },
181 { "Quit" , ICONNAME_QUIT , N_("_Quit") , "<control>Q", N_("Quit HomeBank"), G_CALLBACK (ui_mainwindow_action_quit) },
182
183 /* Exchange */
184 { "ImportQIF" , ICONNAME_HB_FILE_IMPORT , N_("QIF file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
185 { "ImportOFX" , ICONNAME_HB_FILE_IMPORT , N_("OFX/QFX file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
186 { "ImportCSV" , ICONNAME_HB_FILE_IMPORT , N_("CSV file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
187
188 { "ExportQIF" , ICONNAME_HB_FILE_EXPORT , N_("Export QIF file...") , NULL, N_("Export all account in a QIF file"), G_CALLBACK (ui_mainwindow_action_export) },
189
190 /* EditMenu */
191 { "Preferences", ICONNAME_PREFERENCES , N_("Preferences..."), NULL, N_("Configure HomeBank"), G_CALLBACK (ui_mainwindow_action_preferences) },
192
193 /* ManageMenu */
194 { "Currency" , ICONNAME_HB_CURRENCY , N_("Currencies...") , NULL, N_("Configure the currencies"), G_CALLBACK (ui_mainwindow_action_defcurrency) },
195 { "Account" , ICONNAME_HB_ACCOUNT , N_("Acc_ounts...") , NULL, N_("Configure the accounts"), G_CALLBACK (ui_mainwindow_action_defaccount) },
196 { "Payee" , ICONNAME_HB_PAYEE , N_("_Payees...") , NULL, N_("Configure the payees"), G_CALLBACK (ui_mainwindow_action_defpayee) },
197 { "Category" , ICONNAME_HB_CATEGORY , N_("Categories...") , NULL, N_("Configure the categories"), G_CALLBACK (ui_mainwindow_action_defcategory) },
198 { "Archive" , ICONNAME_HB_ARCHIVE , N_("Scheduled/Template...") , NULL, N_("Configure the scheduled/template transactions"), G_CALLBACK (ui_mainwindow_action_defarchive) },
199 { "Budget" , ICONNAME_HB_BUDGET , N_("Budget...") , NULL, N_("Configure the budget"), G_CALLBACK (ui_mainwindow_action_defbudget) },
200 { "Assign" , ICONNAME_HB_ASSIGN , N_("Assignments..."), NULL, N_("Configure the automatic assignments"), G_CALLBACK (ui_mainwindow_action_defassign) },
201
202 /* TxnMenu */
203 { "ShowOpe" , ICONNAME_HB_OPE_SHOW , N_("Show...") , NULL, N_("Shows selected account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions) },
204 { "AddOpe" , ICONNAME_HB_OPE_ADD , N_("Add...") , NULL, N_("Add transactions"), G_CALLBACK (ui_mainwindow_action_addtransactions) },
205 { "Scheduler" , NULL , N_("Set scheduler...") , NULL, N_("Configure the transaction scheduler"), G_CALLBACK (ui_mainwindow_action_properties) },
206 { "AddScheduled", NULL , N_("Post scheduled"), NULL, N_("Post pending scheduled transactions"), G_CALLBACK (ui_mainwindow_action_checkscheduled) },
207
208 /* ReportMenu */
209 { "RStatistics" , ICONNAME_HB_REP_STATS , N_("_Statistics...") , NULL, N_("Open the Statistics report"), G_CALLBACK (ui_mainwindow_action_statistic) },
210 { "RTrendTime" , ICONNAME_HB_REP_TIME , N_("_Trend Time...") , NULL, N_("Open the Trend Time report"), G_CALLBACK (ui_mainwindow_action_trendtime) },
211 { "RBudget" , ICONNAME_HB_REP_BUDGET , N_("B_udget...") , NULL, N_("Open the Budget report"), G_CALLBACK (ui_mainwindow_action_budget) },
212 { "RBalance" , ICONNAME_HB_REP_BALANCE, N_("Balance...") , NULL, N_("Open the Balance report"), G_CALLBACK (ui_mainwindow_action_balance) },
213 { "RVehiculeCost", ICONNAME_HB_REP_CAR , N_("_Vehicle cost...") , NULL, N_("Open the Vehicle cost report"), G_CALLBACK (ui_mainwindow_action_vehiclecost) },
214
215 /* Tools */
216 { "Welcome" , NULL , N_("Show welcome dialog...") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_help_welcome) },
217 { "FileStats" , NULL , N_("File statistics...") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_file_statistics) },
218 { "Anonymize" , NULL , N_("Anonymize...") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_anonymize) },
219
220 /* HelpMenu */
221 { "Contents" , ICONNAME_HELP , N_("_Contents") , "F1", N_("Documentation about HomeBank"), G_CALLBACK (ui_mainwindow_action_help) },
222 { "Online" , "lpi-help" , N_("Get Help Online...") , NULL, N_("Connect to the LaunchPad website for online help"), G_CALLBACK (ui_mainwindow_action_help_online) },
223 { "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) },
224 { "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) },
225
226 { "About" , ICONNAME_ABOUT , N_("_About") , NULL, N_("About HomeBank") ,G_CALLBACK (ui_mainwindow_action_about) },
227
228 };
229 static guint n_entries = G_N_ELEMENTS (entries);
230
231
232 static GtkToggleActionEntry toggle_entries[] = {
233 /* name , icon-name, label, accelerator, tooltip, callback, is_active */
234 { "Toolbar" , NULL , N_("_Toolbar") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_toggle_toolbar), TRUE },
235 { "Spending" , NULL , N_("_Top spending") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_toggle_topspending), TRUE },
236 { "Upcoming" , NULL , N_("_Scheduled list") , NULL, NULL, G_CALLBACK (ui_mainwindow_action_toggle_upcoming), TRUE },
237 { "AsMinor" , NULL , N_("Euro minor"), "<control>M", NULL, G_CALLBACK (ui_mainwindow_action_toggle_minor), FALSE },
238 };
239
240 static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
241
242
243 static const gchar *ui_info =
244 "<ui>"
245
246 " <menubar name='MenuBar'>"
247 " <menu action='FileMenu'>"
248 " <menuitem action='New'/>"
249 " <menuitem action='Open'/>"
250 " <separator/>"
251 " <menuitem action='Save'/>"
252 " <menuitem action='SaveAs'/>"
253 " <menuitem action='Revert'/>"
254 " <separator/>"
255 " <menuitem action='Properties'/>"
256 " <separator/>"
257 " <menu action='ImportMenu'>"
258 " <menuitem action='ImportQIF'/>"
259 " <menuitem action='ImportOFX'/>"
260 " <menuitem action='ImportCSV'/>"
261 " </menu>"
262 " <menuitem action='ExportQIF'/>"
263 //" <separator/>"
264 // print to come here
265 " <separator/>"
266 " <menuitem action='Close'/>"
267 " <menuitem action='Quit'/>"
268 " </menu>"
269 " <menu action='EditMenu'>"
270 " <menuitem action='Preferences'/>"
271 " </menu>"
272 " <menu action='ViewMenu'>"
273 " <menuitem action='Toolbar'/>"
274 " <separator/>"
275 " <menuitem action='Spending'/>"
276 " <menuitem action='Upcoming'/>"
277 " <separator/>"
278 " <menuitem action='AsMinor'/>"
279 " </menu>"
280 " <menu action='ManageMenu'>"
281 " <menuitem action='Account'/>"
282 " <menuitem action='Payee'/>"
283 " <menuitem action='Category'/>"
284 " <menuitem action='Archive'/>"
285 " <menuitem action='Budget'/>"
286 " <menuitem action='Assign'/>"
287 " <menuitem action='Currency'/>"
288 " </menu>"
289 " <menu action='TxnMenu'>"
290 " <menuitem action='ShowOpe'/>"
291 " <menuitem action='AddOpe'/>"
292 " <separator/>"
293 " <menuitem action='Scheduler'/>"
294 " <menuitem action='AddScheduled'/>"
295 " </menu>"
296 " <menu action='ReportMenu'>"
297 " <menuitem action='RStatistics'/>"
298 " <menuitem action='RTrendTime'/>"
299 " <menuitem action='RBalance'/>"
300 " <menuitem action='RBudget'/>"
301 " <menuitem action='RVehiculeCost'/>"
302 " </menu>"
303 " <menu action='ToolsMenu'>"
304 " <menuitem action='Welcome'/>"
305 " <menuitem action='FileStats'/>"
306 " <separator/>"
307 " <menuitem action='Anonymize'/>"
308 " </menu>"
309 " <menu action='HelpMenu'>"
310 " <menuitem action='Contents'/>"
311 " <separator/>"
312 " <menuitem action='Online'/>"
313 " <menuitem action='Translate'/>"
314 " <menuitem action='Problem'/>"
315 " <separator/>"
316 " <menuitem action='About'/>"
317 " </menu>"
318 " </menubar>"
319
320 " <toolbar name='ToolBar'>"
321 " <toolitem action='New'/>"
322 // here Open + recent is coded
323 " <toolitem action='Save'/>"
324 " <separator/>"
325 " <toolitem action='Account'/>"
326 " <toolitem action='Payee'/>"
327 " <toolitem action='Category'/>"
328 " <toolitem action='Archive'/>"
329 " <toolitem action='Budget'/>"
330 " <toolitem action='Assign'/>"
331 " <toolitem action='Currency'/>"
332 " <separator/>"
333 " <toolitem action='ShowOpe'/>"
334 " <toolitem action='AddOpe'/>"
335 " <separator/>"
336 " <toolitem action='RStatistics'/>"
337 " <toolitem action='RTrendTime'/>"
338 " <toolitem action='RBalance'/>"
339 " <toolitem action='RBudget'/>"
340 " <toolitem action='RVehiculeCost'/>"
341 " </toolbar>"
342
343 "</ui>";
344
345
346
347 /* TODO: a bouger */
348
349
350 /*
351 **
352 */
353 void ui_mainwindow_revert(GtkWidget *widget, gpointer user_data)
354 {
355 //struct hbfile_data *data;
356 gchar *basename;
357 gchar *title;
358 gchar *secondtext;
359 gint result;
360
361 DB( g_print("\n[ui-mainwindow] revert\n") );
362
363 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
364
365 basename = g_path_get_basename(GLOBALS->xhb_filepath);
366 title = g_strdup_printf (
367 _("Revert unsaved changes to file '%s'?"), basename);
368
369 secondtext =
370 _("- Changes made to the file will be permanently lost\n"
371 "- File will be reloaded from the last save (.xhb~)");
372
373 result = ui_dialog_msg_confirm_alert(
374 GTK_WINDOW(GLOBALS->mainwindow),
375 title,
376 secondtext,
377 _("_Revert")
378 );
379
380 g_free(title);
381 g_free(basename);
382
383 if( result == GTK_RESPONSE_OK )
384 {
385 DB( g_print(" - should revert\n") );
386
387 hbfile_change_filepath(hb_util_filename_new_with_extension(GLOBALS->xhb_filepath, "xhb~"));
388 ui_mainwindow_open_internal(widget, NULL);
389 hbfile_change_filepath(hb_util_filename_new_with_extension(GLOBALS->xhb_filepath, "xhb"));
390 }
391
392 }
393
394
395 static void
396 activate_url (GtkAboutDialog *about,
397 const gchar *link,
398 gpointer data)
399 {
400 DB( g_print("activate url %s\n", link) );
401
402 homebank_util_url_show (link);
403 }
404
405 static void hbfile_about(void)
406 {
407 GtkWidget *dialog;
408 GdkPixbuf *pixbuf;
409 gchar *pathfilename;
410 gchar *version;
411
412 static const gchar *artists[] = {
413 "Maxime DOYEN",
414 NULL
415 };
416
417 static const gchar *authors[] = {
418 "Lead developer:\n" \
419 "Maxime DOYEN",
420 "\nContributor:\n" \
421 "Ga\xc3\xabtan LORIDANT (Maths formulas for charts)\n",
422 NULL
423 };
424
425 /*
426 const gchar *documenters[] = {
427 "Maxime DOYEN",
428 NULL
429 };
430 */
431
432 static const gchar *copyright = "Copyright \xc2\xa9 1995-2016 - Maxime DOYEN";
433
434
435
436 version = g_strdup_printf (PACKAGE_VERSION "\n<small>Running against GTK+ %d.%d.%d</small>",
437 gtk_get_major_version (),
438 gtk_get_minor_version (),
439 gtk_get_micro_version ());
440
441 dialog = gtk_about_dialog_new();
442
443 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(GLOBALS->mainwindow));
444 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
445
446 gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog), g_get_application_name ());
447 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), version);
448 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright);
449 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), _("Free, easy, personal accounting for everyone"));
450 gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG(dialog), GTK_LICENSE_GPL_2_0);
451
452 //gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(dialog), );
453 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), "http://homebank.free.fr");
454 gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(dialog), "Visit the HomeBank website");
455
456 gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(dialog), "homebank");
457
458 pathfilename = g_build_filename(homebank_app_get_images_dir(), "splash.png", NULL);
459 pixbuf = gdk_pixbuf_new_from_file(pathfilename, NULL);
460 g_free(pathfilename);
461
462 if( pixbuf )
463 {
464 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pixbuf);
465 g_object_unref (pixbuf);
466 }
467
468 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog), authors);
469 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog), artists);
470 //gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(dialog), );
471 //gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog), );
472
473 g_signal_connect (dialog, "activate-link", G_CALLBACK (activate_url), NULL);
474
475 gtk_dialog_run (GTK_DIALOG (dialog));
476
477 gtk_widget_destroy (dialog);
478
479 g_free(version);
480
481 }
482
483
484 /* hbfile action functions -------------------- */
485 static void ui_mainwindow_action_new(void)
486 {
487 GtkWidget *widget = GLOBALS->mainwindow;
488
489 if( ui_dialog_msg_savechanges(widget,NULL) == TRUE )
490 {
491 //clear all, and init GLOBALS->xhb_filepath to default
492 ui_mainwindow_clear(widget, GINT_TO_POINTER(TRUE)); // GPOINTER_TO_INT(
493 ui_mainwindow_update(widget, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
494
495 ui_start_assistant();
496 ui_mainwindow_populate_accounts(GLOBALS->mainwindow, NULL);
497 ui_mainwindow_scheduled_populate(GLOBALS->mainwindow, NULL);
498 ui_mainwindow_populate_topspending(GLOBALS->mainwindow, NULL);
499 }
500 }
501
502 static void ui_mainwindow_action_open(void)
503 {
504 ui_mainwindow_open(GLOBALS->mainwindow, NULL);
505 }
506
507 static void ui_mainwindow_action_save(void)
508 {
509 ui_mainwindow_save(GLOBALS->mainwindow, GINT_TO_POINTER(FALSE));
510 }
511
512 static void ui_mainwindow_action_saveas(void)
513 {
514 ui_mainwindow_save(GLOBALS->mainwindow, GINT_TO_POINTER(TRUE));
515 }
516
517 static void ui_mainwindow_action_revert(void)
518 {
519 ui_mainwindow_revert(GLOBALS->mainwindow, NULL);
520 }
521
522 static void ui_mainwindow_action_close(void)
523 {
524 GtkWidget *widget = GLOBALS->mainwindow;
525
526 if( ui_dialog_msg_savechanges(widget,NULL) == TRUE )
527 {
528 //clear all, and init GLOBALS->xhb_filepath to default
529 ui_mainwindow_clear(widget, GINT_TO_POINTER(TRUE));
530 ui_mainwindow_update(widget, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE+UF_REFRESHALL));
531 }
532
533 }
534
535
536 static void ui_mainwindow_action_quit(void)
537 {
538 gboolean result;
539
540 //gtk_widget_destroy(GLOBALS->mainwindow);
541
542 g_signal_emit_by_name(GLOBALS->mainwindow, "delete-event", NULL, &result);
543
544 //gtk_main_quit();
545 }
546
547 static void ui_mainwindow_action_file_statistics(void)
548 {
549 ui_dialog_file_statistics();
550 }
551
552
553 static void ui_mainwindow_action_properties(void)
554 {
555 create_defhbfile_dialog();
556 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
557 }
558
559 static void ui_mainwindow_action_anonymize(void)
560 {
561 gint result;
562 gchar *title;
563 gchar *secondtext;
564
565 title = _("Are you sure you want to anonymize the file?");
566
567 secondtext =
568 _("Proceeding will anonymize any text, \n"
569 "like 'account x', 'payee y', 'memo z', ...");
570
571 result = ui_dialog_msg_confirm_alert(
572 GTK_WINDOW(GLOBALS->mainwindow),
573 title,
574 secondtext,
575 _("_Anonymize")
576 );
577
578 if( result == GTK_RESPONSE_CANCEL )
579 return;
580
581 hbfile_anonymize();
582 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
583 }
584
585
586 static void ui_mainwindow_action_defcurrency(void)
587 {
588 ui_cur_manage_dialog();
589 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_REFRESHALL));
590 }
591
592
593 static void ui_mainwindow_action_defaccount(void)
594 {
595 ui_acc_manage_dialog();
596
597 //our global list has changed, so update the treeview
598 //todo: optimize this, should not call compute balance here
599 account_compute_balances ();
600 ui_mainwindow_populate_accounts(GLOBALS->mainwindow, NULL);
601
602 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE));
603 }
604
605 static void ui_mainwindow_action_defpayee(void)
606 {
607 ui_pay_manage_dialog();
608 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
609 }
610
611 static void ui_mainwindow_action_defcategory(void)
612 {
613 ui_cat_manage_dialog();
614 //todo:why refresh upcoming here??
615 //ui_mainwindow_populate_upcoming(GLOBALS->mainwindow, NULL);
616 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
617 }
618
619
620 static void ui_mainwindow_defarchive(Archive *arc)
621 {
622 struct hbfile_data *data;
623 GtkTreeModel *model;
624
625 data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
626
627 // upcoming list have direct pointer to the arc (which may have changed)
628 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_upc));
629 gtk_list_store_clear (GTK_LIST_STORE(model));
630
631 ui_arc_manage_dialog(arc);
632
633 ui_mainwindow_scheduled_populate(GLOBALS->mainwindow, NULL);
634
635 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
636 }
637
638
639 static void ui_mainwindow_action_defarchive(void)
640 {
641 ui_mainwindow_defarchive(NULL);
642 }
643
644
645 static void ui_mainwindow_action_defbudget(void)
646 {
647 ui_bud_manage_dialog();
648 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
649 }
650
651
652 static void ui_mainwindow_action_defassign(void)
653 {
654
655 ui_asg_manage_dialog();
656
657 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
658 }
659
660
661 static void ui_mainwindow_action_preferences(void)
662 {
663 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
664
665 defpref_dialog_new();
666 if(!PREFS->euro_active)
667 {
668 GtkToggleAction *action = (GtkToggleAction *)gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/AsMinor");
669
670 gtk_toggle_action_set_active(action, FALSE);
671 ui_mainwindow_action_toggle_minor(action);
672 }
673 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_VISUAL+UF_REFRESHALL));
674 }
675
676 /* display action */
677
678 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction *action)
679 {
680 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
681
682 PREFS->wal_toolbar = gtk_toggle_action_get_active(action);
683 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_VISUAL));
684 }
685
686 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction *action)
687 {
688 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
689
690 PREFS->wal_upcoming = gtk_toggle_action_get_active(action);
691 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_VISUAL));
692 }
693
694 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction *action)
695 {
696 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
697
698 PREFS->wal_spending = gtk_toggle_action_get_active(action);
699 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_VISUAL));
700 }
701
702 static void ui_mainwindow_action_toggle_minor(GtkToggleAction *action)
703 {
704 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
705
706 GLOBALS->minor = gtk_toggle_action_get_active(action);
707
708 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_acc));
709 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_upc));
710
711 // top spending
712 gtk_chart_show_minor(GTK_CHART(data->RE_pie), GLOBALS->minor);
713 hb_label_set_amount(GTK_LABEL(data->TX_topamount), data->toptotal, GLOBALS->kcur, GLOBALS->minor);
714
715 }
716
717 static void ui_mainwindow_action_showtransactions(void)
718 {
719 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
720 GtkWidget *window;
721
722 //todo:change this
723 if( data->acc )
724 {
725 if( data->acc->window == NULL )
726 {
727 window = register_panel_window_new(data->acc->key, data->acc);
728 register_panel_window_init(window, NULL);
729 }
730 else
731 {
732 if(GTK_IS_WINDOW(data->acc->window))
733 gtk_window_present(data->acc->window);
734
735 }
736 }
737 }
738
739
740 static void ui_mainwindow_action_addtransactions(void)
741 {
742 ui_mainwindow_addtransactions(GLOBALS->mainwindow, NULL);
743 }
744
745 static void ui_mainwindow_action_checkscheduled(void)
746 {
747 ui_mainwindow_scheduled_postall(GLOBALS->mainwindow, GINT_TO_POINTER(TRUE));
748 }
749
750 static void ui_mainwindow_action_statistic(void)
751 {
752 ui_repdist_window_new();
753 }
754
755 static void ui_mainwindow_action_trendtime(void)
756 {
757 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
758
759 ui_reptime_window_new(data->acc != NULL ? data->acc->key : 0);
760 }
761
762 static void ui_mainwindow_action_budget(void)
763 {
764 repbudget_window_new();
765 }
766
767 static void ui_mainwindow_action_balance(void)
768 {
769 struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
770
771 repbalance_window_new(data->acc != NULL ? data->acc->key : 0);
772 }
773
774 static void ui_mainwindow_action_vehiclecost(void)
775 {
776 repcost_window_new();
777 }
778
779 static void ui_mainwindow_action_import(GtkAction *action)
780 {
781 const gchar *name;
782 gint filetype = FILETYPE_UNKNOW;
783
784 name = gtk_action_get_name(action);
785
786 if( g_str_has_suffix (name, "QIF"))
787 filetype= FILETYPE_QIF;
788 else
789 if( g_str_has_suffix (name, "OFX"))
790 filetype= FILETYPE_OFX;
791 else
792 if( g_str_has_suffix (name, "CSV"))
793 filetype= FILETYPE_CSV_HB;
794
795 DB( g_print("action %s type=%d\n", name, filetype) );
796
797 ui_import_assistant_new(filetype);
798
799 }
800
801
802 static void ui_mainwindow_action_about(void)
803 {
804 hbfile_about();
805
806
807 }
808
809 static void ui_mainwindow_action_export(void)
810 {
811 gchar *filename;
812
813 if( ui_file_chooser_qif(NULL, &filename) == TRUE )
814 {
815 hb_export_qif_account_all(filename);
816 g_free( filename );
817 }
818 }
819
820 static void ui_mainwindow_action_help(void)
821 {
822 gchar *link;
823
824 link = g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP, NULL );
825 homebank_util_url_show (link);
826
827 g_free(link);
828 }
829
830
831 //todo: move this to a ui-assist-welcome.c
832
833 static void ui_mainwindow_action_help_welcome1 (GtkButton *button, gpointer user_data)
834 {
835 gtk_dialog_response (GTK_DIALOG(user_data), 1);
836 }
837
838 static void ui_mainwindow_action_help_welcome2 (GtkButton *button, gpointer user_data)
839 {
840 gtk_dialog_response (GTK_DIALOG(user_data), 2);
841 }
842
843 static void ui_mainwindow_action_help_welcome3 (GtkButton *button, gpointer user_data)
844 {
845 gtk_dialog_response (GTK_DIALOG(user_data), 3);
846 }
847
848 static void ui_mainwindow_action_help_welcome4 (GtkButton *button, gpointer user_data)
849 {
850 gtk_dialog_response (GTK_DIALOG(user_data), 4);
851 }
852
853 static void ui_mainwindow_action_help_welcome5 (GtkButton *button, gpointer user_data)
854 {
855 gtk_dialog_response (GTK_DIALOG(user_data), 5);
856 }
857
858 void ui_mainwindow_action_help_welcome(void)
859 {
860 GtkWidget *dialog, *content_area;
861 GtkWidget *mainvbox, *widget, *label;
862
863 dialog = gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
864 GTK_WINDOW(GLOBALS->mainwindow),
865 0,
866 _("_Close"),
867 GTK_RESPONSE_ACCEPT,
868 NULL);
869
870 content_area = gtk_dialog_get_content_area(GTK_DIALOG (dialog));
871
872 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
873 gtk_box_pack_start (GTK_BOX (content_area), mainvbox, FALSE, FALSE, 0);
874 gtk_container_set_border_width (GTK_CONTAINER(mainvbox), SPACING_MEDIUM);
875
876 label = make_label (_("HomeBank"), 0, 0);
877 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
878 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, 0);
879
880 label = make_label (_("Free, easy, personal accounting for everyone"), 0, 0);
881 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, 0);
882
883 widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
884 gtk_box_pack_start (GTK_BOX (content_area), widget, FALSE, FALSE, 0);
885
886 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_MEDIUM);
887 gtk_box_pack_start (GTK_BOX (content_area), mainvbox, TRUE, TRUE, 0);
888 gtk_container_set_border_width (GTK_CONTAINER(mainvbox), SPACING_MEDIUM);
889
890 label = make_label (_("What do you want to do:"), 0, 0);
891 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
892 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, 0);
893
894 widget = gtk_button_new_with_mnemonic(_("Read HomeBank _Manual"));
895 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
896 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome1), dialog);
897
898 widget = gtk_button_new_with_mnemonic(_("Configure _preferences"));
899 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
900 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome2), dialog);
901
902 widget = gtk_button_new_with_mnemonic(_("Create a _new file"));
903 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
904 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome3), dialog);
905
906 widget = gtk_button_new_with_mnemonic(_("_Open an existing file"));
907 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
908 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome4), dialog);
909
910 widget = gtk_button_new_with_mnemonic(_("Open the _example file"));
911 gtk_box_pack_start (GTK_BOX (mainvbox), widget, FALSE, FALSE, 0);
912 g_signal_connect (widget, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome5), dialog);
913
914 //connect all our signals
915 g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &dialog);
916
917 gtk_widget_show_all (dialog);
918
919 //wait for the user
920 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
921
922 // cleanup and destroy
923 gtk_widget_destroy (dialog);
924
925 // do appropriate action
926 switch(result)
927 {
928 case 1:
929 ui_mainwindow_action_help();
930 break;
931 case 2:
932 ui_mainwindow_action_preferences();
933 break;
934 case 3:
935 ui_mainwindow_action_new();
936 break;
937 case 4:
938 ui_mainwindow_action_open();
939 break;
940 case 5:
941 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL));
942 ui_mainwindow_open_internal(GLOBALS->mainwindow, NULL);
943 break;
944 }
945
946 }
947
948
949
950 static void ui_mainwindow_action_help_online(void)
951 {
952 const gchar *link = HOMEBANK_URL_HELP_ONLINE;
953
954 homebank_util_url_show (link);
955
956 }
957
958 static void ui_mainwindow_action_help_translate(void)
959 {
960 const gchar *link = HOMEBANK_URL_HELP_TRANSLATE;
961
962 homebank_util_url_show (link);
963
964 }
965
966 static void ui_mainwindow_action_help_problem(void)
967 {
968 const gchar *link = HOMEBANK_URL_HELP_PROBLEM;
969
970 homebank_util_url_show (link);
971
972 }
973
974
975
976
977 /* hbfile functions -------------------- */
978
979
980
981
982 /*
983 **
984 */
985 static void ui_mainwindow_selection(GtkTreeSelection *treeselection, gpointer user_data)
986 {
987 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection)), GINT_TO_POINTER(UF_SENSITIVE));
988 }
989
990
991 static void ui_mainwindow_close_openbooks(void)
992 {
993 GList *lacc, *elt;
994
995 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
996
997 lacc = elt = g_hash_table_get_values(GLOBALS->h_acc);
998 while (elt != NULL)
999 {
1000 Account *item = elt->data;
1001
1002 if(item->window)
1003 {
1004 gtk_widget_destroy(GTK_WIDGET(item->window));
1005 item->window = NULL;
1006 }
1007
1008 elt = g_list_next(elt);
1009 }
1010 g_list_free(lacc);
1011
1012 }
1013
1014
1015
1016 /*
1017 **
1018 */
1019 void ui_mainwindow_clear(GtkWidget *widget, gpointer user_data)
1020 {
1021 struct hbfile_data *data;
1022 gboolean file_clear = GPOINTER_TO_INT(user_data);
1023
1024 DB( g_print("\n[ui-mainwindow] clear\n") );
1025
1026 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1027
1028 // Close opened account window
1029 // Clear TreeView
1030 ui_mainwindow_close_openbooks();
1031 gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_acc))));
1032 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_upc))));
1033 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_top))));
1034
1035 hbfile_cleanup(file_clear);
1036 hbfile_setup(file_clear);
1037
1038 }
1039
1040
1041 /*
1042 ** add some transactions directly
1043 */
1044 void ui_mainwindow_addtransactions(GtkWidget *widget, gpointer user_data)
1045 {
1046 struct hbfile_data *data;
1047 GtkWidget *window;
1048 gint result = 1;
1049 guint32 date;
1050 gint account, count;
1051
1052 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1053
1054 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1055
1056 /* init the transaction */
1057 date = homebank_app_date_get_julian();
1058 //todo: maybe think about set a default account here
1059 account = 1;
1060 if(data->acc != NULL)
1061 account = data->acc->key;
1062
1063 window = create_deftransaction_window(GTK_WINDOW(data->window), TRANSACTION_EDIT_ADD, FALSE);
1064 count = 0;
1065 while(result == GTK_RESPONSE_ADD || result == GTK_RESPONSE_ADDKEEP)
1066 {
1067 Transaction *ope;
1068
1069 /* fill in the transaction */
1070 if( result == GTK_RESPONSE_ADD )
1071 {
1072 ope = da_transaction_malloc();
1073 ope->date = date;
1074 ope->kacc = account;
1075
1076 if( PREFS->heritdate == FALSE ) //fix: 318733
1077 ope->date = GLOBALS->today;
1078 }
1079
1080 // normally we can't be in addkeep without initialized ope with add
1081
1082 deftransaction_set_transaction(window, ope);
1083
1084 result = gtk_dialog_run (GTK_DIALOG (window));
1085
1086 DB( g_print(" - dialog result is %d\n", result) );
1087
1088 if(result == GTK_RESPONSE_ADD || result == GTK_RESPONSE_ADDKEEP || result == GTK_RESPONSE_ACCEPT)
1089 {
1090 deftransaction_get(window, NULL);
1091 transaction_add(ope, NULL, ope->kacc);
1092
1093 DB( g_print(" - added 1 transaction to %d\n", ope->kacc) );
1094
1095 ui_mainwindow_populate_accounts(GLOBALS->mainwindow, NULL);
1096
1097 count++;
1098 //todo: still usefull ? store last date
1099 date = ope->date;
1100 }
1101
1102 if( result == GTK_RESPONSE_ADD )
1103 {
1104 da_transaction_free(ope);
1105 ope = NULL;
1106 }
1107
1108 }
1109
1110
1111 deftransaction_dispose(window, NULL);
1112 gtk_widget_destroy (window);
1113
1114 /* todo optimize this */
1115 if(count > 0)
1116 {
1117 GLOBALS->changes_count += count;
1118 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE+UF_REFRESHALL));
1119 }
1120 }
1121
1122 struct tmptop
1123 {
1124 guint32 key;
1125 gdouble value;
1126 };
1127
1128 static gint tmptop_compare_func(struct tmptop *tt1, struct tmptop *tt2)
1129 {
1130 return tt1->value > tt2->value ? 1 : -1;
1131 }
1132
1133
1134 static void ui_mainwindow_populate_topspending(GtkWidget *widget, gpointer user_data)
1135 {
1136 struct hbfile_data *data;
1137 GtkTreeModel *model;
1138 GtkTreeIter iter;
1139 GList *list;
1140 gint type, range;
1141 guint n_result, i, n_items;
1142 GArray *garray;
1143 gdouble total, other;
1144 Account *acc;
1145
1146 #define MAX_TOPSPENDING 5
1147
1148 DB( g_print("\n[ui-mainwindow] populate_topspending\n") );
1149
1150 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1151
1152 type = radio_get_active(GTK_CONTAINER(data->RA_type));
1153 range = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_range));
1154
1155 DB( g_print(" - type=%d, range=%d\n", type, range) );
1156 DB( g_print(" - pref range=%d\n", PREFS->date_range_wal) );
1157
1158 if(range == FLT_RANGE_OTHER)
1159 return;
1160
1161 filter_preset_daterange_set(data->filter, range, 0);
1162
1163
1164 n_result = da_cat_get_max_key() + 1;
1165 total = 0.0;
1166
1167 DB( g_print(" - max key is %d\n", n_result) );
1168
1169 /* allocate some memory */
1170 garray = g_array_sized_new(FALSE, FALSE, sizeof(struct tmptop), n_result);
1171
1172 if(garray)
1173 {
1174 struct tmptop zero = { .key=0, .value=0.0 };
1175 GQueue *txn_queue;
1176
1177 //DB( g_print(" - array length=%d\n", garray->len) );
1178
1179 for(i=0 ; i<n_result ; i++)
1180 {
1181 g_array_append_vals(garray, &zero, 1);
1182 //g_array_insert_vals(garray, i, &zero, 1);
1183
1184 //struct tmptop *tt = &g_array_index (garray, struct tmptop, i);
1185 //DB( g_print("%4d, %4d %f\n", i, tt->key, tt->value) );
1186 }
1187
1188 //DB( g_print("\n - end array length=%d\n", garray->len) );
1189
1190 //todo: not ideal, has ot force to get_acc for each txn below
1191 txn_queue = hbfile_transaction_get_partial(data->filter->mindate, data->filter->maxdate);
1192
1193 /* compute the results */
1194 list = g_queue_peek_head_link(txn_queue);
1195 while (list != NULL)
1196 {
1197 Transaction *ope = list->data;
1198
1199 //DB( g_print(" - eval txn: '%s', cat=%d ==> flt-test=%d\n", ope->wording, ope->kcat, filter_test(data->filter, ope)) );
1200
1201 if( !(ope->paymode == PAYMODE_INTXFER) )
1202 {
1203 guint32 pos = 0;
1204 gdouble trn_amount;
1205
1206 //todo: optimize here
1207 trn_amount = ope->amount;
1208 acc = da_acc_get(ope->kacc);
1209 if(acc)
1210 trn_amount = hb_amount_base(ope->amount, acc->kcur);
1211
1212 if( ope->flags & OF_SPLIT )
1213 {
1214 guint nbsplit = da_splits_count(ope->splits);
1215 Split *split;
1216 struct tmptop *item;
1217
1218 for(i=0;i<nbsplit;i++)
1219 {
1220 split = ope->splits[i];
1221 pos = category_report_id(split->kcat, type);
1222
1223 trn_amount = hb_amount_base(split->amount, acc->kcur);
1224 //trn_amount = split->amount;
1225 //#1297054 if( trn_amount < 0 ) {
1226 item = &g_array_index (garray, struct tmptop, pos);
1227 item->key = pos;
1228 item->value += trn_amount;
1229 //DB( g_print(" - stored %.2f to item %d\n", trn_amount, pos) );
1230 //}
1231 }
1232 }
1233 else
1234 {
1235 struct tmptop *item;
1236
1237 pos = category_report_id(ope->kcat, type);
1238
1239 //#1297054 if( trn_amount < 0 ) {
1240 item = &g_array_index (garray, struct tmptop, pos);
1241 item->key = pos;
1242 item->value += trn_amount;
1243 //DB( g_print(" - stored %.2f to item %d\n", trn_amount, pos) );
1244 //}
1245 }
1246
1247
1248 }
1249
1250 list = g_list_next(list);
1251 }
1252
1253 g_queue_free (txn_queue);
1254
1255 // we need to sort this and limit before
1256 g_array_sort(garray, (GCompareFunc)tmptop_compare_func);
1257
1258 n_items = MIN(garray->len,MAX_TOPSPENDING);
1259 other = 0;
1260 for(i=0 ; i<garray->len ; i++)
1261 {
1262 struct tmptop *item;
1263
1264 item = &g_array_index (garray, struct tmptop, i);
1265 if(item->value < 0)
1266 {
1267 total += item->value;
1268
1269 if(i >= n_items)
1270 other += item->value;
1271
1272 DB( g_print(" - %d : k='%d' v='%f' t='%f'\n", i, item->key, item->value, total) );
1273
1274 }
1275 }
1276
1277 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_top));
1278 gtk_list_store_clear (GTK_LIST_STORE(model));
1279 g_object_ref(model); /* Make sure the model stays with us after the tree view unrefs it */
1280 gtk_tree_view_set_model(GTK_TREE_VIEW(data->LV_top), NULL); /* Detach model from view */
1281
1282 /* insert into the treeview */
1283 for(i=0 ; i<MIN(garray->len,MAX_TOPSPENDING) ; i++)
1284 {
1285 gchar *name;
1286 Category *entry;
1287 struct tmptop *item;
1288 gdouble value;
1289
1290 item = &g_array_index (garray, struct tmptop, i);
1291
1292 if(!item->value) continue;
1293
1294 value = hb_amount_round(item->value, 2);
1295 entry = da_cat_get(item->key);
1296 if(entry == NULL) continue;
1297
1298 name = entry->key == 0 ? _("(no category)") : da_cat_get_fullname(entry);
1299
1300 // append test
1301 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
1302 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
1303 LST_TOPSPEND_ID, i,
1304 LST_TOPSPEND_KEY, 0,
1305 LST_TOPSPEND_NAME, name,
1306 LST_TOPSPEND_AMOUNT, value,
1307 //LST_TOPSPEND_RATE, (gint)(((ABS(value)*100)/ABS(total)) + 0.5),
1308 -1);
1309
1310 }
1311
1312 // append test
1313 if(ABS(other) > 0)
1314 {
1315 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
1316 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
1317 LST_TOPSPEND_ID, n_items,
1318 LST_TOPSPEND_KEY, 0,
1319 LST_TOPSPEND_NAME, _("Other"),
1320 LST_TOPSPEND_AMOUNT, other,
1321 //LST_TOPSPEND_RATE, (gint)(((ABS(other)*100)/ABS(total)) + 0.5),
1322 -1);
1323 }
1324
1325 /* Re-attach model to view */
1326 gtk_tree_view_set_model(GTK_TREE_VIEW(data->LV_top), model);
1327 g_object_unref(model);
1328
1329 data->toptotal = total;
1330 hb_label_set_amount(GTK_LABEL(data->TX_topamount), total, GLOBALS->kcur, GLOBALS->minor);
1331
1332 gtk_chart_set_color_scheme(GTK_CHART(data->RE_pie), PREFS->report_color_scheme);
1333 gtk_chart_set_currency(GTK_CHART(data->RE_pie), GLOBALS->kcur);
1334 gtk_chart_set_datas(GTK_CHART(data->RE_pie), model, LST_TOPSPEND_AMOUNT, NULL, NULL);
1335 //gtk_chart_show_legend(GTK_CHART(data->RE_pie), FALSE);
1336
1337 /* update info range text */
1338 {
1339 gchar *daterange;
1340
1341 daterange = filter_daterange_text_get(data->filter);
1342 gtk_widget_set_tooltip_markup(GTK_WIDGET(data->CY_range), daterange);
1343 g_free(daterange);
1344 }
1345 }
1346
1347 /* free our memory */
1348 g_array_free (garray, TRUE);
1349
1350 }
1351
1352
1353 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1354 /* scheduled */
1355 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1356 static Archive *
1357 ui_mainwindow_scheduled_get_selected_item(GtkTreeView *treeview)
1358 {
1359 GtkTreeSelection *treeselection;
1360 GtkTreeModel *model;
1361 GtkTreeIter iter;
1362
1363 treeselection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
1364 if( gtk_tree_selection_get_selected(treeselection, &model, &iter) )
1365 {
1366 Archive *arc;
1367
1368 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, LST_DSPUPC_DATAS, &arc, -1);
1369 return arc;
1370 }
1371
1372 return NULL;
1373 }
1374
1375
1376 static void ui_mainwindow_scheduled_onRowActivated (GtkTreeView *treeview,
1377 GtkTreePath *path,
1378 GtkTreeViewColumn *col,
1379 gpointer userdata)
1380 {
1381 //struct hbfile_data *data;
1382 Archive *arc;
1383
1384 DB( g_print ("\n[ui-mainwindow] A scheduled row has been double-clicked!\n") );
1385
1386 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(treeview, GTK_TYPE_WINDOW)), "inst_data");
1387
1388 arc = ui_mainwindow_scheduled_get_selected_item(treeview);
1389 ui_mainwindow_defarchive(arc);
1390 }
1391
1392
1393 static void ui_mainwindow_scheduled_do_post(Archive *arc, gboolean doedit, gpointer user_data)
1394 {
1395 struct hbfile_data *data = user_data;
1396 GtkWidget *window;
1397 gint result;
1398 Transaction *txn;
1399
1400 window = create_deftransaction_window(GTK_WINDOW(data->window), TRANSACTION_EDIT_ADD, TRUE);
1401
1402 /* fill in the transaction */
1403 txn = da_transaction_malloc();
1404 da_transaction_init_from_template(txn, arc);
1405 txn->date = scheduled_get_postdate(arc, arc->nextdate);
1406
1407 deftransaction_set_transaction(window, txn);
1408
1409 result = gtk_dialog_run (GTK_DIALOG (window));
1410
1411 DB( g_print(" - dialog result is %d\n", result) );
1412
1413 if(result == GTK_RESPONSE_ADD || result == GTK_RESPONSE_ACCEPT)
1414 {
1415 deftransaction_get(window, NULL);
1416 transaction_add(txn, NULL, txn->kacc);
1417 GLOBALS->changes_count++;
1418
1419 scheduled_date_advance(arc);
1420
1421 DB( g_print(" - added 1 transaction to %d\n", txn->kacc) );
1422 }
1423
1424 da_transaction_free(txn);
1425
1426 deftransaction_dispose(window, NULL);
1427 gtk_widget_destroy (window);
1428
1429 }
1430
1431
1432 static void ui_mainwindow_scheduled_editpost_cb(GtkWidget *widget, gpointer user_data)
1433 {
1434 struct hbfile_data *data = user_data;
1435
1436 Archive *arc = ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data->LV_upc));
1437
1438 if( (arc != NULL) )
1439 {
1440 ui_mainwindow_scheduled_do_post(arc, TRUE, data);
1441 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_SENSITIVE|UF_REFRESHALL));
1442 }
1443 }
1444
1445
1446 static void ui_mainwindow_scheduled_post_cb(GtkWidget *widget, gpointer user_data)
1447 {
1448 struct hbfile_data *data = user_data;
1449
1450 Archive *arc = ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data->LV_upc));
1451
1452 if( (arc != NULL) )
1453 {
1454 if( scheduled_is_postable(arc) )
1455 {
1456 Transaction *txn = da_transaction_malloc ();
1457
1458 da_transaction_init_from_template(txn, arc);
1459 txn->date = scheduled_get_postdate(arc, arc->nextdate);
1460 transaction_add(txn, NULL, 0);
1461
1462 GLOBALS->changes_count++;
1463 scheduled_date_advance(arc);
1464
1465 da_transaction_free (txn);
1466 }
1467 else
1468 {
1469 ui_mainwindow_scheduled_do_post(arc, FALSE, data);
1470 }
1471
1472 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_SENSITIVE|UF_REFRESHALL));
1473 }
1474 }
1475
1476
1477 static void ui_mainwindow_scheduled_skip_cb(GtkWidget *widget, gpointer user_data)
1478 {
1479 struct hbfile_data *data = user_data;
1480
1481 Archive *arc = ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data->LV_upc));
1482 if( (arc != NULL) && (arc->flags & OF_AUTO) )
1483 {
1484 GLOBALS->changes_count++;
1485 scheduled_date_advance(arc);
1486
1487 ui_mainwindow_scheduled_populate(GLOBALS->mainwindow, NULL);
1488 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_SENSITIVE));
1489 }
1490 }
1491
1492
1493
1494 static void ui_mainwindow_scheduled_update(GtkWidget *widget, gpointer user_data)
1495 {
1496 struct hbfile_data *data;
1497 //gint filter;
1498
1499 DB( g_print("\n[ui-mainwindow] scheduled update\n") );
1500
1501 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1502
1503 //filter = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_sched_filter));
1504
1505 Archive *arc = ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data->LV_upc));
1506
1507 if(arc)
1508 {
1509 DB( g_print("archive is %s\n", arc->wording) );
1510
1511 gtk_widget_set_sensitive(GTK_WIDGET(data->BT_sched_skip), TRUE);
1512 gtk_widget_set_sensitive(GTK_WIDGET(data->BT_sched_post), TRUE);
1513 gtk_widget_set_sensitive(GTK_WIDGET(data->BT_sched_editpost), TRUE);
1514 }
1515 else
1516 {
1517 gtk_widget_set_sensitive(GTK_WIDGET(data->BT_sched_skip), FALSE);
1518 gtk_widget_set_sensitive(GTK_WIDGET(data->BT_sched_post), FALSE);
1519 gtk_widget_set_sensitive(GTK_WIDGET(data->BT_sched_editpost), FALSE);
1520 }
1521
1522 }
1523
1524
1525
1526 static void ui_mainwindow_scheduled_selection_cb(GtkTreeSelection *treeselection, gpointer user_data)
1527 {
1528
1529
1530 ui_mainwindow_scheduled_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection)), GINT_TO_POINTER(UF_SENSITIVE));
1531 }
1532
1533
1534
1535 /*
1536 ** called after load, importamiga, on demand
1537 */
1538 void ui_mainwindow_scheduled_postall(GtkWidget *widget, gpointer user_data)
1539 {
1540 //struct hbfile_data *data;
1541 gint count;
1542 gint usermode = GPOINTER_TO_INT(user_data);
1543
1544 DB( g_print("\n[ui-mainwindow] check scheduled\n") );
1545
1546 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1547
1548 count = scheduled_post_all_pending();
1549
1550 //inform the user
1551 if(usermode == TRUE)
1552 {
1553 gchar *txt;
1554
1555 //#125534
1556 if( count > 0 )
1557 {
1558 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_REFRESHALL));
1559 }
1560
1561 if(count == 0)
1562 txt = _("No transaction to add");
1563 else
1564 txt = _("transaction added: %d");
1565
1566 ui_dialog_msg_infoerror(GTK_WINDOW(GLOBALS->mainwindow), GTK_MESSAGE_INFO,
1567 _("Check scheduled transactions result"),
1568 txt,
1569 count);
1570 }
1571
1572 }
1573
1574
1575 static void ui_mainwindow_scheduled_populate(GtkWidget *widget, gpointer user_data)
1576 {
1577 struct hbfile_data *data;
1578 GtkTreeModel *model;
1579 GtkTreeIter iter;
1580 GList *list;
1581 gdouble totexp = 0;
1582 gdouble totinc = 0;
1583 gint count = 0;
1584 gchar buffer[256];
1585 guint32 maxpostdate;
1586 GDate *date;
1587 //Account *acc;
1588
1589 DB( g_print("\n[ui-mainwindow] scheduled populate list\n") );
1590
1591 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1592
1593 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_upc));
1594 gtk_list_store_clear (GTK_LIST_STORE(model));
1595
1596 homebank_app_date_get_julian();
1597
1598 maxpostdate = scheduled_date_get_post_max();
1599
1600 date = g_date_new_julian (maxpostdate);
1601 g_date_strftime (buffer, 256-1, PREFS->date_format, date);
1602 g_date_free(date);
1603
1604 gtk_label_set_text(GTK_LABEL(data->LB_maxpostdate), buffer);
1605
1606
1607 list = g_list_first(GLOBALS->arc_list);
1608 while (list != NULL)
1609 {
1610 Archive *arc = list->data;
1611 Account *acc;
1612 gdouble inc, exp;
1613 guint nbdays, nblate;
1614
1615 if((arc->flags & OF_AUTO) ) //&& arc->kacc > 0)
1616 {
1617 count++;
1618 nbdays = arc->nextdate - maxpostdate;
1619 nblate = scheduled_get_latepost_count(arc, GLOBALS->today);
1620
1621 DB( g_print(" - append '%s' : %d\n", arc->wording, nbdays) );
1622
1623 if(arc->flags & OF_INCOME)
1624 {
1625 inc = arc->amount;
1626 exp = 0.0;
1627 }
1628 else
1629 {
1630 exp = arc->amount;
1631 inc = 0.0;
1632 }
1633
1634 /* insert normal txn */
1635 acc = da_acc_get(arc->kacc);
1636 if( acc)
1637 {
1638 totinc += hb_amount_base(inc, acc->kcur);
1639 totexp += hb_amount_base(exp, acc->kcur);
1640 }
1641 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
1642 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
1643 LST_DSPUPC_DATAS, arc,
1644 LST_DSPUPC_ACCOUNT, acc,
1645 LST_DSPUPC_WORDING, arc->wording,
1646 LST_DSPUPC_EXPENSE, exp,
1647 LST_DSPUPC_INCOME, inc,
1648 LST_DSPUPC_REMAINING, nbdays,
1649 LST_DSPUPC_NB_LATE, nblate,
1650 -1);
1651
1652 /* insert internal xfer txn : 1378836 */
1653 if(arc->paymode == PAYMODE_INTXFER)
1654 {
1655 acc = da_acc_get(arc->kxferacc);
1656 if( acc)
1657 {
1658 totinc += hb_amount_base(-inc, acc->kcur);
1659 totexp += hb_amount_base(-exp, acc->kcur);
1660 }
1661 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
1662 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
1663 LST_DSPUPC_DATAS, arc,
1664 LST_DSPUPC_ACCOUNT, acc,
1665 LST_DSPUPC_WORDING, arc->wording,
1666 LST_DSPUPC_EXPENSE, -inc,
1667 LST_DSPUPC_INCOME, -exp,
1668 LST_DSPUPC_REMAINING, nbdays,
1669 LST_DSPUPC_NB_LATE, nblate,
1670 -1);
1671 }
1672
1673 }
1674 list = g_list_next(list);
1675 }
1676
1677 // insert total
1678 if(count > 0 )
1679 {
1680 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
1681 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
1682 LST_DSPUPC_DATAS, NULL,
1683 LST_DSPUPC_ACCOUNT, NULL,
1684 LST_DSPUPC_WORDING, _("Total"),
1685 LST_DSPUPC_EXPENSE, totexp,
1686 LST_DSPUPC_INCOME, totinc,
1687 -1);
1688 }
1689
1690
1691 ui_mainwindow_scheduled_update(widget, NULL);
1692
1693 }
1694
1695
1696
1697
1698 /*
1699 **
1700 */
1701 void ui_mainwindow_open(GtkWidget *widget, gpointer user_data)
1702 {
1703 //struct hbfile_data *data;
1704 gchar *filename = NULL;
1705
1706 DB( g_print("\n[ui-mainwindow] open\n") );
1707
1708 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1709
1710 if( ui_dialog_msg_savechanges(widget,NULL) == TRUE )
1711 {
1712 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN, &filename) == TRUE)
1713 {
1714 hbfile_change_filepath(filename);
1715
1716 ui_mainwindow_open_internal(widget, NULL);
1717
1718
1719 }
1720 }
1721 }
1722
1723 /*
1724 * open the file stored in GLOBALS->xhb_filepath
1725 */
1726 void ui_mainwindow_open_internal(GtkWidget *widget, gpointer user_data)
1727 {
1728 struct hbfile_data *data;
1729 gint r;
1730
1731 DB( g_print("\n[ui-mainwindow] open internal\n") );
1732
1733 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1734
1735 DB( g_print(" - filename: '%s'\n", GLOBALS->xhb_filepath) );
1736
1737 if( GLOBALS->xhb_filepath != NULL )
1738 {
1739 ui_mainwindow_clear(GLOBALS->mainwindow, GINT_TO_POINTER(FALSE));
1740 GLOBALS->hbfile_is_new = FALSE;
1741
1742 r = homebank_load_xml(GLOBALS->xhb_filepath);
1743 if( r == XML_OK )
1744 {
1745 DB( g_print(" - file loaded ok : rcode=%d\n", r) );
1746
1747 hbfile_file_hasbackup(GLOBALS->xhb_filepath);
1748
1749 if(PREFS->appendscheduled)
1750 scheduled_post_all_pending();
1751
1752 if(PREFS->do_update_currency)
1753 ui_cur_manage_dialog_update_currencies(GTK_WINDOW(GLOBALS->mainwindow));
1754
1755 homebank_lastopenedfiles_save();
1756
1757 //todo: delete this after computing done at xml read
1758 account_compute_balances();
1759
1760 ui_mainwindow_recent_add(data, GLOBALS->xhb_filepath);
1761 }
1762 else
1763 {
1764 gchar *msg = _("Unknow error");
1765
1766 switch(r)
1767 {
1768 case XML_IO_ERROR:
1769 msg = _("I/O error for file '%s'.");
1770 break;
1771 case XML_FILE_ERROR:
1772 msg = _("The file '%s' is not a valid HomeBank file.");
1773 break;
1774 case XML_VERSION_ERROR:
1775 msg = _("The file '%s' was saved with a higher version of HomeBank\nand cannot be loaded by the current version.");
1776 break;
1777 }
1778
1779 ui_dialog_msg_infoerror(GTK_WINDOW(data->window), GTK_MESSAGE_ERROR,
1780 _("File error"),
1781 msg,
1782 GLOBALS->xhb_filepath
1783 );
1784
1785 ui_mainwindow_clear(GLOBALS->mainwindow, GINT_TO_POINTER(TRUE));
1786
1787 }
1788
1789 ui_mainwindow_populate_accounts(GLOBALS->mainwindow, NULL);
1790 ui_mainwindow_scheduled_populate(GLOBALS->mainwindow, NULL);
1791 ui_mainwindow_populate_topspending(GLOBALS->mainwindow, NULL);
1792 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_VISUAL));
1793 }
1794
1795
1796 }
1797
1798 /*
1799 **
1800 */
1801 void ui_mainwindow_save(GtkWidget *widget, gpointer user_data)
1802 {
1803 struct hbfile_data *data;
1804 gboolean saveas = GPOINTER_TO_INT(user_data);
1805 gchar *filename = NULL;
1806 gint r = XML_UNSET;
1807
1808 DB( g_print("\n[ui-mainwindow] save\n") );
1809
1810 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1811
1812 if( GLOBALS->hbfile_is_new == TRUE )
1813 saveas = 1;
1814
1815 if(saveas == 1)
1816 {
1817 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE, &filename) == TRUE)
1818 {
1819 DB( g_print(" + should save as '%s'\n", filename) );
1820 homebank_file_ensure_xhb(filename);
1821 homebank_backup_current_file();
1822 r = homebank_save_xml(GLOBALS->xhb_filepath);
1823 GLOBALS->hbfile_is_new = FALSE;
1824 }
1825 else
1826 return;
1827 }
1828 else
1829 {
1830 DB( g_print(" + should quick save %s\n", GLOBALS->xhb_filepath) );
1831 homebank_file_ensure_xhb(NULL);
1832 homebank_backup_current_file();
1833 r = homebank_save_xml(GLOBALS->xhb_filepath);
1834 }
1835
1836
1837 if(r == XML_OK)
1838 {
1839 GLOBALS->changes_count = 0;
1840 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_VISUAL));
1841 }
1842 else
1843 {
1844 gchar *msg = _("I/O error for file '%s'.");
1845
1846 ui_dialog_msg_infoerror(GTK_WINDOW(data->window), GTK_MESSAGE_ERROR,
1847 _("File error"),
1848 msg,
1849 GLOBALS->xhb_filepath
1850 );
1851
1852 }
1853
1854
1855 }
1856
1857
1858 void ui_mainwindow_populate_accounts(GtkWidget *widget, gpointer user_data)
1859 {
1860 struct hbfile_data *data;
1861 GtkTreeModel *model;
1862 GtkTreeIter iter1, child_iter;
1863 GList *lacc, *elt;
1864 Account *acc;
1865 guint i, j, nbtype;
1866 gdouble gtbank, gttoday, gtfuture;
1867
1868 DB( g_print("\n[ui-mainwindow] populate accounts\n") );
1869
1870 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1871
1872 /* here we create a count and a list of every account pointer by type */
1873
1874 GPtrArray *typeacc[ACC_TYPE_MAXVALUE] = {0};
1875 lacc = elt = g_hash_table_get_values(GLOBALS->h_acc);
1876 while (elt != NULL)
1877 {
1878 acc = elt->data;
1879 //#1339572
1880 if( !(acc->flags & (AF_CLOSED|AF_NOSUMMARY)) )
1881 {
1882 DB( g_print(" - insert %d:%s\n", acc->key, acc->name) );
1883
1884 if(typeacc[acc->type] == NULL)
1885 typeacc[acc->type] = g_ptr_array_sized_new(da_acc_length ());
1886
1887 g_ptr_array_add(typeacc[acc->type], (gpointer)acc);
1888 }
1889 elt = g_list_next(elt);
1890 }
1891 g_list_free(lacc);
1892
1893 gtbank = gttoday = gtfuture = 0;
1894
1895 DB( g_print(" - populate listview\n") );
1896
1897
1898 /* then populate the listview */
1899 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_acc));
1900 gtk_tree_store_clear (GTK_TREE_STORE(model));
1901
1902 nbtype = 0;
1903 for(i=0;i<ACC_TYPE_MAXVALUE;i++)
1904 {
1905 GPtrArray *gpa = typeacc[i];
1906 gdouble tbank, ttoday, tfuture;
1907
1908 if(gpa != NULL)
1909 {
1910 nbtype++;
1911 //1: Header: Bank, Cash, ...
1912 DB( g_print(" - append type '%s'\n", CYA_ACC_TYPE[i]) );
1913
1914 gtk_tree_store_append (GTK_TREE_STORE(model), &iter1, NULL);
1915 gtk_tree_store_set (GTK_TREE_STORE(model), &iter1,
1916 LST_DSPACC_DATATYPE, DSPACC_TYPE_HEADER,
1917 LST_DSPACC_NAME, _(CYA_ACC_TYPE[i]),
1918 -1);
1919
1920 tbank = ttoday = tfuture = 0;
1921
1922 //2: Accounts for real
1923 for(j=0;j<gpa->len;j++)
1924 {
1925 acc = g_ptr_array_index(gpa, j);
1926
1927 //tbank += acc->bal_bank;
1928 //ttoday += acc->bal_today;
1929 //tfuture += acc->bal_future;
1930 tbank += hb_amount_base(acc->bal_bank, acc->kcur);
1931 ttoday += hb_amount_base(acc->bal_today, acc->kcur);
1932 tfuture += hb_amount_base(acc->bal_future, acc->kcur);
1933
1934 DB( g_print(" - insert '%s' :: %.2f %.2f %.2f\n", acc->name, acc->bal_bank, acc->bal_today, acc->bal_future) );
1935
1936 gtk_tree_store_append (GTK_TREE_STORE(model), &child_iter, &iter1);
1937 gtk_tree_store_set (GTK_TREE_STORE(model), &child_iter,
1938 LST_DSPACC_DATAS, acc,
1939 LST_DSPACC_DATATYPE, DSPACC_TYPE_NORMAL,
1940 LST_DSPACC_BANK, acc->bal_bank,
1941 LST_DSPACC_TODAY, acc->bal_today,
1942 LST_DSPACC_FUTURE, acc->bal_future,
1943 -1);
1944 }
1945
1946 if(gpa->len > 1)
1947 {
1948 DB( g_print(" - type totals :: %.2f %.2f %.2f\n", tbank, ttoday, tfuture) );
1949
1950 // insert the total line
1951 gtk_tree_store_append (GTK_TREE_STORE(model), &child_iter, &iter1);
1952 gtk_tree_store_set (GTK_TREE_STORE(model), &child_iter,
1953 LST_DSPACC_DATATYPE, DSPACC_TYPE_SUBTOTAL,
1954 LST_DSPACC_NAME, _("Total"),
1955 LST_DSPACC_BANK, tbank,
1956 LST_DSPACC_TODAY, ttoday,
1957 LST_DSPACC_FUTURE, tfuture,
1958 -1);
1959 }
1960
1961 /* set balance to header to display when collasped */
1962 gtk_tree_store_set (GTK_TREE_STORE(model), &iter1,
1963 LST_DSPACC_BANK, tbank,
1964 LST_DSPACC_TODAY, ttoday,
1965 LST_DSPACC_FUTURE, tfuture,
1966 -1);
1967
1968 /* add to grand total */
1969 gtbank += tbank;
1970 gttoday += ttoday;
1971 gtfuture += tfuture;
1972
1973 }
1974
1975 }
1976
1977 DB( g_print(" - grand totals :: %.2f %.2f %.2f\n", gtbank, gttoday, gtfuture) );
1978
1979 // Grand total
1980 if( nbtype > 1 )
1981 {
1982 gtk_tree_store_append (GTK_TREE_STORE(model), &iter1, NULL);
1983 gtk_tree_store_set (GTK_TREE_STORE(model), &iter1,
1984 LST_DSPACC_DATATYPE, DSPACC_TYPE_SUBTOTAL,
1985 LST_DSPACC_NAME, _("Grand total"),
1986 LST_DSPACC_BANK, gtbank,
1987 LST_DSPACC_TODAY, gttoday,
1988 LST_DSPACC_FUTURE, gtfuture,
1989 -1);
1990 }
1991
1992
1993 gtk_tree_view_expand_all(GTK_TREE_VIEW(data->LV_acc));
1994
1995 DB( g_print(" - free ressources\n") );
1996
1997
1998 /* free all temp stuff */
1999 for(i=0;i<ACC_TYPE_MAXVALUE;i++)
2000 {
2001 GPtrArray *gpa = typeacc[i];
2002
2003 if(gpa != NULL)
2004 g_ptr_array_free (gpa, TRUE);
2005 }
2006
2007
2008 }
2009
2010
2011 void ui_mainwindow_update(GtkWidget *widget, gpointer user_data)
2012 {
2013 struct hbfile_data *data;
2014 gint flags;
2015
2016 DB( g_print("\n[ui-mainwindow] refresh_display\n") );
2017
2018 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
2019 //data = INST_DATA(widget);
2020
2021 flags = GPOINTER_TO_INT(user_data);
2022
2023 /* set window title */
2024 if(flags & UF_TITLE)
2025 {
2026 gchar *basename;
2027 gchar *changed;
2028
2029 DB( g_print(" + 1: wintitle %x\n", (gint)data->wintitle) );
2030
2031 basename = g_path_get_basename(GLOBALS->xhb_filepath);
2032
2033 DB( g_print(" global changes: %d\n", GLOBALS->changes_count) );
2034
2035 g_free(data->wintitle);
2036
2037 changed = (GLOBALS->changes_count > 0) ? "*" : "";
2038
2039 data->wintitle = g_strdup_printf("%s%s - %s - " PROGNAME, changed, basename, GLOBALS->owner);
2040
2041 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), data->wintitle);
2042
2043 g_free(basename);
2044 }
2045
2046 /* update disabled things */
2047 if(flags & UF_SENSITIVE)
2048 {
2049 GtkTreeSelection *selection;
2050 GtkTreeModel *model;
2051 GtkTreeIter iter;
2052 GtkTreePath *path;
2053 gboolean active,sensitive;
2054
2055 DB( g_print(" + 2: disabled, opelist count\n") );
2056
2057 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_acc));
2058
2059 active = gtk_tree_selection_get_selected(selection, &model, &iter);
2060 if(active)
2061 {
2062 Account *acc;
2063 gint depth;
2064
2065 path = gtk_tree_model_get_path(model, &iter);
2066 depth = gtk_tree_path_get_depth(path);
2067
2068 if( depth > 1 )
2069 {
2070 DB( g_print(" depth is %d\n", depth) );
2071
2072 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, LST_DSPACC_DATAS, &acc, -1);
2073 data->acc = acc;
2074
2075 }
2076 else
2077 active = FALSE;
2078 }
2079 else
2080 {
2081 //ensure data->acc will not be null
2082 data->acc = da_acc_get(1);
2083 }
2084
2085
2086 // no change: disable save
2087 DB( g_print(" changes %d - new %d\n", GLOBALS->changes_count, GLOBALS->hbfile_is_new) );
2088
2089
2090 sensitive = (GLOBALS->changes_count != 0 ) ? TRUE : FALSE;
2091 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/SaveAs"), sensitive);
2092 //if(sensitive == TRUE && GLOBALS->hbfile_is_new == TRUE) sensitive = FALSE;
2093 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/Save"), sensitive);
2094 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/Revert"), GLOBALS->xhb_hasbak);
2095
2096
2097 // define off ?
2098 sensitive = GLOBALS->define_off == 0 ? TRUE : FALSE;
2099
2100 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Account"), sensitive);
2101 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Payee"), sensitive);
2102 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Category"), sensitive);
2103 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Budget"), sensitive);
2104 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/EditMenu/Preferences"), sensitive);
2105
2106 // empty account list: disable Import, Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
2107 sensitive = da_acc_length() > 0 ? TRUE : FALSE;
2108
2109 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data-data->manager, "/MenuBar/FileMenu/Import"), sensitive);
2110
2111 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/Close"), sensitive);
2112 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Archive"), sensitive);
2113 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/AddOpe"), sensitive);
2114 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/ShowOpe"), sensitive);
2115 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RStatistics"), sensitive);
2116 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RTrendTime"), sensitive);
2117 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RBudget"), sensitive);
2118 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RBalance"), sensitive);
2119 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ReportMenu/RVehiculeCost"), sensitive);
2120
2121 // empty category list: disable Budget
2122 sensitive = da_cat_length() > 1 ? TRUE : FALSE;
2123 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Budget"), sensitive);
2124
2125 //#1501129 no need to disable, P & C can be created from assign dialog
2126 //sensitive = ((da_cat_length() > 1) || (da_pay_length() > 1)) ? TRUE : FALSE;
2127 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Assign"), sensitive);
2128
2129 // empty archive list: disable scheduled check
2130 sensitive = g_list_length(GLOBALS->arc_list) > 0 ? TRUE : FALSE;
2131
2132 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/AddScheduled"), sensitive);
2133
2134 // no active account: disable Edit, Over
2135 sensitive = (active == TRUE ) ? TRUE : FALSE;
2136 if(data->acc && data->acc->window != NULL)
2137 sensitive = FALSE;
2138
2139 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/ShowOpe"), sensitive);
2140
2141 }
2142
2143 /* update toolbar, list */
2144 if(flags & UF_VISUAL)
2145 {
2146 DB( g_print(" + 8: visual\n") );
2147
2148 if(PREFS->toolbar_style == 0)
2149 gtk_toolbar_unset_style(GTK_TOOLBAR(data->toolbar));
2150 else
2151 gtk_toolbar_set_style(GTK_TOOLBAR(data->toolbar), PREFS->toolbar_style-1);
2152
2153 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data->LV_acc), PREFS->grid_lines);
2154 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_acc));
2155
2156 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data->LV_upc), PREFS->grid_lines);
2157 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_upc));
2158
2159 DB( g_print(" - show toolbar=%d\n", PREFS->wal_toolbar) );
2160 if(PREFS->wal_toolbar)
2161 gtk_widget_show(GTK_WIDGET(data->toolbar));
2162 else
2163 gtk_widget_hide(GTK_WIDGET(data->toolbar));
2164
2165
2166 DB( g_print(" - show top_spending=%d\n", PREFS->wal_spending) );
2167
2168 gtk_combo_box_set_active(GTK_COMBO_BOX(data->CY_range), PREFS->date_range_wal);
2169
2170 if(PREFS->wal_spending)
2171 gtk_widget_show(GTK_WIDGET(data->GR_top));
2172 else
2173 gtk_widget_hide(GTK_WIDGET(data->GR_top));
2174
2175
2176
2177 DB( g_print(" - show upcoming=%d\n", PREFS->wal_upcoming) );
2178 if(PREFS->wal_upcoming)
2179 gtk_widget_show(GTK_WIDGET(data->GR_upc));
2180 else
2181 gtk_widget_hide(GTK_WIDGET(data->GR_upc));
2182
2183 DB( g_print(" minor %d\n", PREFS->euro_active) );
2184 gtk_action_set_visible(gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/AsMinor"), PREFS->euro_active);
2185 }
2186
2187 /* update balances */
2188 if(flags & UF_BALANCE)
2189 {
2190
2191 DB( g_print(" + 4: balances\n") );
2192
2193 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_acc));
2194
2195 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
2196
2197 /*
2198 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[0]), data->bank, minor);
2199 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[1]), data->today, minor);
2200 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[2]), data->future, minor);
2201 */
2202 }
2203
2204 if(flags & UF_REFRESHALL)
2205 {
2206 DB( g_print(" + 8: refreshall\n") );
2207
2208 ui_mainwindow_populate_accounts(GLOBALS->mainwindow, NULL);
2209 ui_mainwindow_populate_topspending(GLOBALS->mainwindow, NULL);
2210 ui_mainwindow_scheduled_populate(GLOBALS->mainwindow, NULL);
2211 }
2212
2213
2214 }
2215
2216
2217
2218 static void
2219 ui_mainwindow_onRowActivated (GtkTreeView *treeview,
2220 GtkTreePath *path,
2221 GtkTreeViewColumn *col,
2222 gpointer userdata)
2223 {
2224 GtkTreeModel *model;
2225 GtkTreeIter iter;
2226
2227 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
2228
2229 model = gtk_tree_view_get_model(treeview);
2230
2231 if (gtk_tree_model_get_iter(model, &iter, path))
2232 {
2233 Account *acc;
2234
2235 gtk_tree_model_get(model, &iter, LST_DSPACC_DATAS, &acc, -1);
2236
2237 if( acc != NULL )
2238 {
2239
2240 DB( g_print ("Double-clicked row contains name %s\n", acc->name) );
2241
2242 ui_mainwindow_action_showtransactions();
2243
2244 //g_free(name);
2245 }
2246 }
2247 }
2248
2249 /*
2250 **
2251 */
2252 static gboolean ui_mainwindow_dispose(GtkWidget *widget, GdkEvent *event, gpointer user_data)
2253 {
2254 struct hbfile_data *data = user_data;
2255 struct WinGeometry *wg;
2256 gboolean retval = FALSE;
2257
2258 DB( g_print("\n[ui-mainwindow] dispose\n") );
2259
2260 //store position and size
2261 wg = &PREFS->wal_wg;
2262 gtk_window_get_position(GTK_WINDOW(widget), &wg->l, &wg->t);
2263 gtk_window_get_size(GTK_WINDOW(widget), &wg->w, &wg->h);
2264 GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(widget));
2265 GdkWindowState state = gdk_window_get_state(gdk_window);
2266 wg->s = (state & GDK_WINDOW_STATE_MAXIMIZED) ? 1 : 0;
2267
2268 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) );
2269
2270 PREFS->wal_vpaned = gtk_paned_get_position(GTK_PANED(data->vpaned));
2271 PREFS->wal_hpaned = gtk_paned_get_position(GTK_PANED(data->hpaned));
2272
2273 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS->wal_vpaned, PREFS->wal_hpaned) );
2274
2275 //todo
2276 if(ui_dialog_msg_savechanges(widget, NULL) == FALSE)
2277 {
2278 retval = TRUE;
2279 }
2280 else
2281 {
2282 DB( g_print(" free wintitle %x\n", (gint)data->wintitle) );
2283
2284 gtk_widget_destroy(data->LV_top);
2285
2286 g_free(data->wintitle);
2287 da_filter_free(data->filter);
2288 g_free(user_data);
2289 gtk_main_quit();
2290 }
2291
2292
2293
2294 //delete-event TRUE abort/FALSE destroy
2295 return retval;
2296 }
2297
2298
2299 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser *chooser, struct hbfile_data *data)
2300 {
2301 gchar *uri, *path;
2302 GError *error = NULL;
2303
2304 uri = gtk_recent_chooser_get_current_uri (chooser);
2305
2306 path = g_filename_from_uri (uri, NULL, NULL);
2307 if (error)
2308 {
2309 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri, error->message);
2310 g_error_free (error);
2311 return;
2312 }
2313
2314 if( ui_dialog_msg_savechanges(data->window, NULL) == TRUE )
2315 {
2316
2317 //todo: FixMe
2318 /*
2319 if (! load)
2320 {
2321 gpw_recent_remove (gpw, path);
2322 }
2323 */
2324
2325 hbfile_change_filepath(path);
2326 ui_mainwindow_open_internal(data->window, NULL);
2327 }
2328 else
2329 {
2330 g_free (path);
2331 }
2332 g_free (uri);
2333 }
2334
2335
2336 static void ui_mainwindow_window_screen_changed_cb (GtkWidget *widget,
2337 GdkScreen *old_screen,
2338 struct hbfile_data *data)
2339 {
2340
2341 DB( g_print("\n[ui-mainwindow] screen_changed_cb\n") );
2342
2343
2344 data->recent_manager = gtk_recent_manager_get_default ();
2345
2346 gtk_menu_detach (GTK_MENU (data->recent_menu));
2347 g_object_unref (G_OBJECT (data->recent_menu));
2348
2349 data->recent_menu = ui_mainwindow_create_recent_chooser_menu (data->recent_manager);
2350
2351 g_signal_connect (data->recent_menu,
2352 "item-activated",
2353 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb),
2354 data);
2355
2356 //menu_item = gtk_ui_manager_get_widget (data->manager, "/MenuBar/FileMenu/OpenRecent");
2357 //gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), data->recent_menu);
2358 }
2359
2360
2361 void ui_mainwindow_recent_add (struct hbfile_data *data, const gchar *path)
2362 {
2363 GtkRecentData *recent_data;
2364 gchar *uri;
2365 GError *error = NULL;
2366
2367 DB( g_print("\n[ui-mainwindow] recent_add\n") );
2368
2369 DB( g_print(" - file has .xhb suffix = %d\n", g_str_has_suffix (path, ".xhb") ) );
2370
2371 if( g_str_has_suffix (path, ".xhb") == FALSE ) //ignore reverted file
2372 return;
2373
2374 uri = g_filename_to_uri (path, NULL, &error);
2375 if (error)
2376 {
2377 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri, error->message);
2378 g_error_free (error);
2379 return;
2380 }
2381
2382 recent_data = g_slice_new (GtkRecentData);
2383
2384 recent_data->display_name = NULL;
2385 recent_data->description = NULL;
2386 recent_data->mime_type = "application/x-homebank";
2387 recent_data->app_name = (gchar *) g_get_application_name ();
2388 recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
2389 recent_data->groups = NULL;
2390 recent_data->is_private = FALSE;
2391
2392 if (!gtk_recent_manager_add_full (data->recent_manager,
2393 uri,
2394 recent_data))
2395 {
2396 g_warning ("Unable to add '%s' to the list of recently used documents", uri);
2397 }
2398
2399 g_free (uri);
2400 g_free (recent_data->app_exec);
2401 g_slice_free (GtkRecentData, recent_data);
2402
2403 }
2404
2405
2406
2407
2408
2409 enum
2410 {
2411 TARGET_URI_LIST
2412 };
2413
2414 static GtkTargetEntry drop_types[] =
2415 {
2416 {"text/uri-list", 0, TARGET_URI_LIST}
2417 };
2418
2419 static void ui_mainwindow_drag_data_received (GtkWidget *widget,
2420 GdkDragContext *context,
2421 gint x, gint y,
2422 GtkSelectionData *selection_data,
2423 guint info, guint time, GtkWindow *window)
2424 {
2425 gchar **uris, **str;
2426 gchar *newseldata;
2427 gint filetype, slen;
2428
2429 if (info != TARGET_URI_LIST)
2430 return;
2431
2432 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
2433
2434 /* On MS-Windows, it looks like `selection_data->data' is not NULL terminated. */
2435 slen = gtk_selection_data_get_length(selection_data);
2436 newseldata = g_new (gchar, slen + 1);
2437 memcpy (newseldata, gtk_selection_data_get_data(selection_data), slen);
2438 newseldata[slen] = 0;
2439
2440 uris = g_uri_list_extract_uris (newseldata);
2441
2442 str = uris;
2443 //for (str = uris; *str; str++)
2444 if( *str )
2445 {
2446 GError *error = NULL;
2447 gchar *path = g_filename_from_uri (*str, NULL, &error);
2448
2449 if (path)
2450 {
2451 filetype = homebank_alienfile_recognize(path);
2452
2453 DB( g_print(" - dragged %s, type is %d\n", path, filetype ) );
2454
2455 if( filetype == FILETYPE_HOMEBANK)
2456 {
2457 hbfile_change_filepath(g_strdup(path));
2458 ui_mainwindow_open_internal(GTK_WIDGET(window), NULL);
2459 }
2460 else
2461 {
2462 //todo: future here to implement import for other filetype
2463
2464 ui_dialog_msg_infoerror(GTK_WINDOW(window), GTK_MESSAGE_ERROR,
2465 _("File error"),
2466 _("The file %s is not a valid HomeBank file."),
2467 path
2468 );
2469
2470
2471 }
2472
2473 }
2474 else
2475 {
2476 g_warning ("Could not convert uri to local path: %s", error->message);
2477
2478 g_error_free (error);
2479 }
2480 g_free (path);
2481 }
2482 g_strfreev (uris);
2483
2484 g_free(newseldata);
2485 }
2486
2487
2488 static GtkWidget *ui_mainwindow_create_recent_chooser_menu (GtkRecentManager *manager)
2489 {
2490 GtkWidget *toolbar_recent_menu;
2491 GtkRecentFilter *filter;
2492
2493 toolbar_recent_menu = gtk_recent_chooser_menu_new_for_manager (manager);
2494
2495 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu),
2496 FALSE);
2497 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu),
2498 GTK_RECENT_SORT_MRU);
2499 //todo: add a user pref for this
2500 gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER (toolbar_recent_menu),
2501 10);
2502
2503
2504 //gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (toolbar_recent_menu), FALSE);
2505
2506 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (toolbar_recent_menu), TRUE);
2507
2508 filter = gtk_recent_filter_new ();
2509 //gtk_recent_filter_add_application (filter, g_get_application_name());
2510 gtk_recent_filter_add_pattern (filter, "*.[Xx][Hh][Bb]");
2511 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (toolbar_recent_menu), filter);
2512
2513 return toolbar_recent_menu;
2514 }
2515
2516
2517 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data *data, GtkWidget *mainvbox)
2518 {
2519 GtkUIManager *manager;
2520 GtkActionGroup *action_group;
2521 GtkAction *action;
2522 GError *error = NULL;
2523
2524 manager = gtk_ui_manager_new ();
2525 data->manager = manager;
2526
2527 gtk_window_add_accel_group (GTK_WINDOW (data->window),
2528 gtk_ui_manager_get_accel_group(manager));
2529
2530 action_group = gtk_action_group_new ("MainWindow");
2531 gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE);
2532
2533 gtk_action_group_add_actions (action_group,
2534 entries,
2535 n_entries,
2536 NULL);
2537
2538 gtk_action_group_add_toggle_actions (action_group,
2539 toggle_entries,
2540 n_toggle_entries,
2541 NULL);
2542
2543 gtk_ui_manager_insert_action_group (data->manager, action_group, 0);
2544 g_object_unref (action_group);
2545 data->actions = action_group;
2546
2547 /* set short labels to use in the toolbar */
2548 action = gtk_action_group_get_action(action_group, "Open");
2549 g_object_set(action, "short_label", _("Open"), NULL);
2550
2551 //action = gtk_action_group_get_action(action_group, "Save");
2552 //g_object_set(action, "is_important", TRUE, NULL);
2553
2554 action = gtk_action_group_get_action(action_group, "Account");
2555 g_object_set(action, "short_label", _("Account"), NULL);
2556
2557 action = gtk_action_group_get_action(action_group, "Payee");
2558 g_object_set(action, "short_label", _("Payee"), NULL);
2559
2560 action = gtk_action_group_get_action(action_group, "Category");
2561 g_object_set(action, "short_label", _("Category"), NULL);
2562
2563 action = gtk_action_group_get_action(action_group, "Archive");
2564 //TRANSLATORS: an archive is stored transaction buffers (kind of bookmark to prefill manual insertion)
2565 g_object_set(action, "short_label", _("Archive"), NULL);
2566
2567 action = gtk_action_group_get_action(action_group, "Budget");
2568 g_object_set(action, "short_label", _("Budget"), NULL);
2569
2570 action = gtk_action_group_get_action(action_group, "ShowOpe");
2571 g_object_set(action, "short_label", _("Show"), NULL);
2572
2573 action = gtk_action_group_get_action(action_group, "AddOpe");
2574 g_object_set(action, "is_important", TRUE, "short_label", _("Add"), NULL);
2575
2576 action = gtk_action_group_get_action(action_group, "RStatistics");
2577 g_object_set(action, "short_label", _("Statistics"), NULL);
2578
2579 action = gtk_action_group_get_action(action_group, "RBudget");
2580 g_object_set(action, "short_label", _("Budget"), NULL);
2581
2582 action = gtk_action_group_get_action(action_group, "RBalance");
2583 g_object_set(action, "short_label", _("Balance"), NULL);
2584
2585 action = gtk_action_group_get_action(action_group, "RVehiculeCost");
2586 g_object_set(action, "short_label", _("Vehicle cost"), NULL);
2587
2588 /* now load the UI definition */
2589 gtk_ui_manager_add_ui_from_string (data->manager, ui_info, -1, &error);
2590 if (error != NULL)
2591 {
2592 g_message ("Building menus failed: %s", error->message);
2593 g_error_free (error);
2594 }
2595
2596 //todo: this generate a warning
2597 data->menubar = gtk_ui_manager_get_widget (manager, "/MenuBar");
2598 gtk_box_pack_start (GTK_BOX (mainvbox),
2599 data->menubar,
2600 FALSE,
2601 FALSE,
2602 0);
2603
2604 data->toolbar = gtk_ui_manager_get_widget (manager, "/ToolBar");
2605 gtk_box_pack_start (GTK_BOX (mainvbox),
2606 data->toolbar,
2607 FALSE,
2608 FALSE,
2609 0);
2610
2611 /* recent files menu */
2612
2613 data->recent_manager = gtk_recent_manager_get_default ();
2614
2615 data->recent_menu = ui_mainwindow_create_recent_chooser_menu (data->recent_manager);
2616
2617 g_signal_connect (data->recent_menu,
2618 "item-activated",
2619 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb),
2620 data);
2621
2622 /*
2623 widget = gtk_ui_manager_get_widget (data->manager, "/MenuBar/FileMenu/OpenRecent");
2624 gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), data->recent_menu);
2625 */
2626
2627 /* test */
2628 /* add the custom Open button to the toolbar */
2629 GtkWidget *image = gtk_image_new_from_icon_name (ICONNAME_OPEN, GTK_ICON_SIZE_BUTTON);
2630
2631 GtkToolItem *open_button = gtk_menu_tool_button_new(image, _("_Open"));
2632 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button), data->recent_menu);
2633
2634 gtk_tool_item_set_tooltip_text (open_button, _("Open a file"));
2635 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button), _("Open a recently used file"));
2636
2637 action = gtk_action_group_get_action (data->actions, "Open");
2638 g_object_set (action, "short_label", _("Open"), NULL);
2639 //gtk_action_connect_proxy (action, GTK_WIDGET (open_button));
2640 gtk_activatable_set_related_action (GTK_ACTIVATABLE (open_button), action);
2641
2642 gtk_toolbar_insert (GTK_TOOLBAR (data->toolbar), open_button, 1);
2643 /* end test */
2644
2645 }
2646
2647 static GtkWidget *ui_mainwindow_create_youraccounts(struct hbfile_data *data)
2648 {
2649 GtkWidget *mainvbox, *label, *widget, *sw;
2650
2651 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2652
2653 label = make_label_group(_("Your accounts"));
2654 gtk_widget_set_margin_top(GTK_WIDGET(label), SPACING_SMALL/2);
2655 gtk_widget_set_margin_bottom(GTK_WIDGET(label), SPACING_SMALL/2);
2656 gtk_widget_set_margin_start(GTK_WIDGET(label), SPACING_SMALL);
2657 gtk_widget_set_margin_end(GTK_WIDGET(label), SPACING_SMALL);
2658 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, 0);
2659
2660 sw = gtk_scrolled_window_new (NULL, NULL);
2661 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
2662 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2663 //gtk_widget_set_margin_top(GTK_WIDGET(sw), 0);
2664 gtk_widget_set_margin_bottom(GTK_WIDGET(sw), SPACING_SMALL);
2665 gtk_widget_set_margin_start(GTK_WIDGET(sw), 2*SPACING_SMALL);
2666 gtk_widget_set_margin_end(GTK_WIDGET(sw), SPACING_SMALL);
2667 gtk_box_pack_start (GTK_BOX (mainvbox), sw, TRUE, TRUE, 0);
2668
2669 widget = (GtkWidget *)create_list_account();
2670 data->LV_acc = widget;
2671 gtk_container_add (GTK_CONTAINER (sw), widget);
2672
2673 return mainvbox;
2674 }
2675
2676
2677 static GtkWidget *ui_mainwindow_create_topspending(struct hbfile_data *data)
2678 {
2679 GtkWidget *mainvbox, *hbox, *vbox;
2680 GtkWidget *label, *widget;
2681
2682 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2683 data->GR_top = mainvbox;
2684
2685 label = make_label_group(_("Where your money goes"));
2686 gtk_widget_set_margin_top(GTK_WIDGET(label), SPACING_SMALL/2);
2687 gtk_widget_set_margin_bottom(GTK_WIDGET(label), SPACING_SMALL/2);
2688 gtk_widget_set_margin_start(GTK_WIDGET(label), SPACING_SMALL);
2689 gtk_widget_set_margin_end(GTK_WIDGET(label), SPACING_SMALL);
2690 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, 0);
2691
2692
2693 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_SMALL);
2694 //gtk_widget_set_margin_top(GTK_WIDGET(vbox), 0);
2695 gtk_widget_set_margin_bottom(GTK_WIDGET(vbox), SPACING_SMALL);
2696 gtk_widget_set_margin_start(GTK_WIDGET(vbox), 2*SPACING_SMALL);
2697 gtk_widget_set_margin_end(GTK_WIDGET(vbox), SPACING_SMALL);
2698 gtk_box_pack_start (GTK_BOX (mainvbox), vbox, TRUE, TRUE, 0);
2699
2700 /* total + date range */
2701 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, SPACING_SMALL);
2702 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
2703
2704 label = make_label(_("Top spending"), 0.0, 0.5);
2705 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2706
2707 label = make_label(NULL, 0.0, 0.5);
2708 data->TX_topamount = label;
2709 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
2710
2711 data->CY_range = make_daterange(label, FALSE);
2712 gtk_box_pack_end (GTK_BOX (hbox), data->CY_range, FALSE, FALSE, 0);
2713
2714 widget = make_radio(CYA_CATSUBCAT, TRUE, GTK_ORIENTATION_HORIZONTAL);
2715 data->RA_type = widget;
2716 gtk_box_pack_end (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
2717
2718 /* pie + listview */
2719 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
2720 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
2721
2722 widget = gtk_chart_new(CHART_TYPE_PIE);
2723 data->RE_pie = widget;
2724 gtk_chart_set_minor_prefs(GTK_CHART(widget), PREFS->euro_value, PREFS->minor_cur.symbol);
2725 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
2726
2727 /*
2728 sw = gtk_scrolled_window_new (NULL, NULL);
2729 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
2730 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2731 gtk_box_pack_start (GTK_BOX (hbox), sw, FALSE, FALSE, 0);
2732 */
2733
2734 widget = (GtkWidget *)create_list_topspending();
2735 data->LV_top = widget;
2736
2737 gtk_chart_show_legend(GTK_CHART(data->RE_pie), TRUE, TRUE);
2738
2739 // gtk_container_add (GTK_CONTAINER (sw), widget);
2740
2741 return mainvbox;
2742 }
2743
2744
2745 static GtkWidget *ui_mainwindow_scheduled_create(struct hbfile_data *data)
2746 {
2747 GtkWidget *mainvbox, *hbox, *vbox, *bbox, *sw, *tbar;
2748 GtkWidget *label, *widget;
2749 GtkToolItem *toolitem;
2750
2751 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2752 data->GR_upc = mainvbox;
2753
2754 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, SPACING_SMALL);
2755 gtk_box_pack_start (GTK_BOX (mainvbox), hbox, FALSE, FALSE, 0);
2756
2757 label = make_label_group(_("Scheduled transactions"));
2758 gtk_widget_set_margin_top(GTK_WIDGET(label), SPACING_SMALL/2);
2759 gtk_widget_set_margin_bottom(GTK_WIDGET(label), SPACING_SMALL/2);
2760 gtk_widget_set_margin_start(GTK_WIDGET(label), SPACING_SMALL);
2761 gtk_widget_set_margin_end(GTK_WIDGET(label), SPACING_SMALL);
2762 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2763
2764 label = make_label(_("maximum post date"), 0.0, 0.7);
2765 gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_SCALE, PANGO_SCALE_SMALL, -1);
2766 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2767
2768 label = make_label(NULL, 0.0, 0.7);
2769 data->LB_maxpostdate = label;
2770 gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_SCALE, PANGO_SCALE_SMALL, -1);
2771 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2772
2773 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2774 //gtk_widget_set_margin_top(GTK_WIDGET(vbox), 0);
2775 gtk_widget_set_margin_bottom(GTK_WIDGET(vbox), SPACING_SMALL);
2776 gtk_widget_set_margin_start(GTK_WIDGET(vbox), 2*SPACING_SMALL);
2777 gtk_widget_set_margin_end(GTK_WIDGET(vbox), SPACING_SMALL);
2778 gtk_box_pack_start (GTK_BOX (mainvbox), vbox, TRUE, TRUE, 0);
2779
2780 sw = gtk_scrolled_window_new (NULL, NULL);
2781 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
2782 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2783 gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
2784
2785 widget = (GtkWidget *)create_list_upcoming();
2786 data->LV_upc = widget;
2787 gtk_container_add (GTK_CONTAINER (sw), widget);
2788
2789 tbar = gtk_toolbar_new();
2790 gtk_toolbar_set_icon_size (GTK_TOOLBAR(tbar), GTK_ICON_SIZE_MENU);
2791 gtk_toolbar_set_style(GTK_TOOLBAR(tbar), GTK_TOOLBAR_ICONS);
2792 gtk_style_context_add_class (gtk_widget_get_style_context (tbar), GTK_STYLE_CLASS_INLINE_TOOLBAR);
2793 gtk_box_pack_start (GTK_BOX (vbox), tbar, FALSE, FALSE, 0);
2794
2795 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
2796 toolitem = gtk_tool_item_new();
2797 gtk_container_add (GTK_CONTAINER(toolitem), bbox);
2798 gtk_toolbar_insert(GTK_TOOLBAR(tbar), GTK_TOOL_ITEM(toolitem), -1);
2799
2800 widget = gtk_button_new_with_label(_("Skip"));
2801 data->BT_sched_skip = widget;
2802 gtk_box_pack_start (GTK_BOX (bbox), widget, FALSE, FALSE, 0);
2803
2804 widget = gtk_button_new_with_label(_("Edit & Post"));
2805 data->BT_sched_editpost = widget;
2806 gtk_box_pack_start (GTK_BOX (bbox), widget, FALSE, FALSE, 0);
2807
2808 //TRANSLATORS: Posting a scheduled transaction is the action to materialize it into its target account.
2809 //TRANSLATORS: Before that action the automated transaction occurrence is pending and not yet really existing.
2810 widget = gtk_button_new_with_label (_("Post"));
2811 data->BT_sched_post = widget;
2812 gtk_box_pack_start (GTK_BOX (bbox), widget, FALSE, FALSE, 0);
2813
2814
2815 /* image = gtk_image_new_from_icon_name (ICONNAME_HB_SCHED_SKIP, GTK_ICON_SIZE_MENU);
2816 toolitem = gtk_tool_button_new(image, NULL);
2817 data->BT_sched_skip = toolitem;
2818 gtk_toolbar_insert(GTK_TOOLBAR(tbar), GTK_TOOL_ITEM(toolitem), -1);
2819 gtk_widget_set_tooltip_text(GTK_WIDGET(toolitem), _("Skip"));
2820
2821 image = gtk_image_new_from_icon_name (ICONNAME_HB_SCHED_POST, GTK_ICON_SIZE_MENU);
2822 toolitem = gtk_tool_button_new(image, NULL);
2823 data->BT_sched_post = toolitem;
2824 gtk_toolbar_insert(GTK_TOOLBAR(tbar), GTK_TOOL_ITEM(toolitem), -1);
2825 gtk_widget_set_tooltip_text(GTK_WIDGET(toolitem), _("Post"));
2826 */
2827
2828
2829 return mainvbox;
2830 }
2831
2832 /*
2833 ** the window creation
2834 */
2835 GtkWidget *create_hbfile_window(GtkWidget *do_widget)
2836 {
2837 struct hbfile_data *data;
2838 struct WinGeometry *wg;
2839 GtkWidget *mainvbox, *vbox, *vpaned, *hpaned;
2840 GtkWidget *widget;
2841 GtkWidget *window;
2842 GtkAction *action;
2843
2844 DB( g_print("\n[ui-mainwindow] create main window\n") );
2845
2846 data = g_malloc0(sizeof(struct hbfile_data));
2847 if(!data) return NULL;
2848
2849 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2850
2851 //store our window private data
2852 g_object_set_data(G_OBJECT(window), "inst_data", (gpointer)data);
2853 DB( g_print(" - new window=%x, inst_data=%0x\n", (gint)window, (gint)data) );
2854
2855 // this is our mainwindow, so store it to GLOBALS data
2856 data->window = window;
2857 GLOBALS->mainwindow = window;
2858
2859 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2860 gtk_container_add (GTK_CONTAINER (window), mainvbox);
2861
2862 ui_mainwindow_create_menu_bar_and_toolbar (data, mainvbox);
2863
2864 #if HB_UNSTABLE == TRUE
2865 GtkWidget *bar, *label;
2866
2867 bar = gtk_info_bar_new ();
2868 gtk_box_pack_start (GTK_BOX (mainvbox), bar, FALSE, FALSE, 0);
2869 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_WARNING);
2870 label = make_label(NULL, 0.5, 0.5);
2871 gtk_label_set_markup (GTK_LABEL(label), "Unstable Development Version");
2872 gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label, FALSE, FALSE, 0);
2873 #endif
2874
2875 /* Add the main area */
2876 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2877 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
2878 gtk_box_pack_start (GTK_BOX (mainvbox), vbox, TRUE, TRUE, 0);
2879
2880 vpaned = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2881 data->vpaned = vpaned;
2882 gtk_box_pack_start (GTK_BOX (vbox), vpaned, TRUE, TRUE, 0);
2883
2884 hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2885 data->hpaned = hpaned;
2886 gtk_paned_pack1 (GTK_PANED(vpaned), hpaned, FALSE, FALSE);
2887
2888 widget = ui_mainwindow_scheduled_create(data);
2889 gtk_paned_pack2 (GTK_PANED(vpaned), widget, FALSE, FALSE);
2890
2891 widget = ui_mainwindow_create_youraccounts(data);
2892 gtk_paned_pack1 (GTK_PANED(hpaned), widget, FALSE, FALSE);
2893
2894 widget = ui_mainwindow_create_topspending(data);
2895 gtk_paned_pack2 (GTK_PANED(hpaned), widget, FALSE, FALSE);
2896
2897
2898 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS->wal_vpaned, PREFS->wal_hpaned) );
2899
2900 if(PREFS->wal_hpaned > 0)
2901 gtk_paned_set_position(GTK_PANED(data->hpaned), PREFS->wal_hpaned);
2902 if(PREFS->wal_vpaned > 0)
2903 gtk_paned_set_position(GTK_PANED(data->vpaned), PREFS->wal_vpaned);
2904
2905 //setup, init and show window
2906 wg = &PREFS->wal_wg;
2907 if(wg->s == 0)
2908 {
2909 gtk_window_move(GTK_WINDOW(window), wg->l, wg->t);
2910 gtk_window_resize(GTK_WINDOW(window), wg->w, wg->h);
2911 }
2912 else
2913 gtk_window_maximize(GTK_WINDOW(window));
2914
2915 gtk_widget_show_all (window);
2916
2917 //todo: move this elsewhere
2918 DB( g_print(" - setup stuff\n") );
2919
2920 data->filter = da_filter_malloc();
2921 filter_default_all_set(data->filter);
2922 gtk_combo_box_set_active(GTK_COMBO_BOX(data->CY_range), PREFS->date_range_wal);
2923
2924
2925
2926 action = gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/Toolbar");
2927 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), PREFS->wal_toolbar);
2928 action = gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/Spending");
2929 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), PREFS->wal_spending);
2930 action = gtk_ui_manager_get_action(data->manager, "/MenuBar/ViewMenu/Upcoming");
2931 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), PREFS->wal_upcoming);
2932
2933 /* Drag and drop support, set targets to NULL because we add the
2934 default uri_targets below */
2935
2936 /* support for opening a file by dragging onto the project window */
2937 gtk_drag_dest_set (GTK_WIDGET (window),
2938 GTK_DEST_DEFAULT_ALL,
2939 drop_types,
2940 G_N_ELEMENTS (drop_types),
2941 GDK_ACTION_COPY);
2942
2943 g_signal_connect (G_OBJECT (window), "drag-data-received",
2944 G_CALLBACK (ui_mainwindow_drag_data_received), window);
2945
2946
2947
2948 //connect all our signals
2949 DB( g_print(" - connect signals\n") );
2950
2951
2952 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_acc)), "changed", G_CALLBACK (ui_mainwindow_selection), NULL);
2953 g_signal_connect (GTK_TREE_VIEW(data->LV_acc), "row-activated", G_CALLBACK (ui_mainwindow_onRowActivated), GINT_TO_POINTER(2));
2954
2955 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_upc)), "changed", G_CALLBACK (ui_mainwindow_scheduled_selection_cb), NULL);
2956 g_signal_connect (GTK_TREE_VIEW(data->LV_upc), "row-activated", G_CALLBACK (ui_mainwindow_scheduled_onRowActivated), NULL);
2957 g_signal_connect (G_OBJECT (data->BT_sched_skip), "clicked", G_CALLBACK (ui_mainwindow_scheduled_skip_cb), data);
2958 g_signal_connect (G_OBJECT (data->BT_sched_editpost), "clicked", G_CALLBACK (ui_mainwindow_scheduled_editpost_cb), data);
2959 g_signal_connect (G_OBJECT (data->BT_sched_post), "clicked", G_CALLBACK (ui_mainwindow_scheduled_post_cb), data);
2960
2961 widget = radio_get_nth_widget(GTK_CONTAINER(data->RA_type), 1);
2962 if(widget)
2963 g_signal_connect (widget, "toggled", G_CALLBACK (ui_mainwindow_populate_topspending), &data);
2964
2965 g_signal_connect (data->CY_range, "changed", G_CALLBACK (ui_mainwindow_populate_topspending), NULL);
2966
2967
2968 /* GtkWindow events */
2969 g_signal_connect (window, "delete-event", G_CALLBACK (ui_mainwindow_dispose), (gpointer)data);
2970
2971
2972 g_signal_connect (window, "screen-changed",
2973 G_CALLBACK (ui_mainwindow_window_screen_changed_cb),
2974 data);
2975
2976
2977 //gtk_action_group_set_sensitive(data->actions, FALSE);
2978
2979
2980 return window;
2981 }
2982
This page took 0.166937 seconds and 5 git commands to generate.