1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2016 Maxime DOYEN
4 * This file is part of HomeBank.
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.
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.
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/>.
23 #include "dsp_mainwindow.h"
25 #include "list_account.h"
26 #include "list_upcoming.h"
27 #include "list_topspending.h"
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"
35 #include "ui-category.h"
36 #include "ui-archive.h"
37 #include "ui-assign.h"
38 #include "ui-budget.h"
40 #include "ui-hbfile.h"
41 #include "ui-transaction.h"
43 #include "rep_balance.h"
44 #include "rep_budget.h"
45 #include "rep_stats.h"
47 #include "rep_vehicle.h"
49 #include "gtk-chart.h"
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"
58 /****************************************************************************/
60 /****************************************************************************/
69 /* our global datas */
70 extern struct HomeBank
*GLOBALS
;
71 extern struct Preferences
*PREFS
;
72 extern gchar
*homebank_pixmaps_dir
;
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);
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);
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
);
99 static void ui_mainwindow_action_showtransactions(void);
100 static void ui_mainwindow_action_addtransactions(void);
101 static void ui_mainwindow_action_checkscheduled(void);
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);
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);
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);
122 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
);
124 static void ui_mainwindow_populate_topspending(GtkWidget
*widget
, gpointer user_data
);
126 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
);
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
);
134 gboolean
ui_dialog_msg_savechanges(GtkWidget
*widget
, gpointer user_data
);
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
);
140 static void ui_mainwindow_scheduled_populate(GtkWidget
*widget
, gpointer user_data
);
141 void ui_mainwindow_scheduled_postall(GtkWidget
*widget
, gpointer user_data
);
143 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
145 extern gchar
*CYA_ACC_TYPE
[];
147 gchar
*CYA_CATSUBCAT
[] = {
154 static GtkActionEntry entries
[] = {
156 /* name, icon-name, label */
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
},
168 // { "Import" , NULL, N_("Import") },
169 // { "Export" , NULL, N_("Export to") },
170 /* name, icon-name, label, accelerator, tooltip */
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
) },
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
) },
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
) },
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
) },
191 { "Preferences", ICONNAME_PREFERENCES
, N_("Preferences..."), NULL
, N_("Configure HomeBank"), G_CALLBACK (ui_mainwindow_action_preferences
) },
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
) },
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
) },
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
) },
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
) },
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
) },
226 { "About" , ICONNAME_ABOUT
, N_("_About") , NULL
, N_("About HomeBank") ,G_CALLBACK (ui_mainwindow_action_about
) },
229 static guint n_entries
= G_N_ELEMENTS (entries
);
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
},
240 static guint n_toggle_entries
= G_N_ELEMENTS (toggle_entries
);
243 static const gchar
*ui_info
=
246 " <menubar name='MenuBar'>"
247 " <menu action='FileMenu'>"
248 " <menuitem action='New'/>"
249 " <menuitem action='Open'/>"
251 " <menuitem action='Save'/>"
252 " <menuitem action='SaveAs'/>"
253 " <menuitem action='Revert'/>"
255 " <menuitem action='Properties'/>"
257 " <menu action='ImportMenu'>"
258 " <menuitem action='ImportQIF'/>"
259 " <menuitem action='ImportOFX'/>"
260 " <menuitem action='ImportCSV'/>"
262 " <menuitem action='ExportQIF'/>"
264 // print to come here
266 " <menuitem action='Close'/>"
267 " <menuitem action='Quit'/>"
269 " <menu action='EditMenu'>"
270 " <menuitem action='Preferences'/>"
272 " <menu action='ViewMenu'>"
273 " <menuitem action='Toolbar'/>"
275 " <menuitem action='Spending'/>"
276 " <menuitem action='Upcoming'/>"
278 " <menuitem action='AsMinor'/>"
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'/>"
289 " <menu action='TxnMenu'>"
290 " <menuitem action='ShowOpe'/>"
291 " <menuitem action='AddOpe'/>"
293 " <menuitem action='Scheduler'/>"
294 " <menuitem action='AddScheduled'/>"
296 " <menu action='ReportMenu'>"
297 " <menuitem action='RStatistics'/>"
298 " <menuitem action='RTrendTime'/>"
299 " <menuitem action='RBalance'/>"
300 " <menuitem action='RBudget'/>"
301 " <menuitem action='RVehiculeCost'/>"
303 " <menu action='ToolsMenu'>"
304 " <menuitem action='Welcome'/>"
305 " <menuitem action='FileStats'/>"
307 " <menuitem action='Anonymize'/>"
309 " <menu action='HelpMenu'>"
310 " <menuitem action='Contents'/>"
312 " <menuitem action='Online'/>"
313 " <menuitem action='Translate'/>"
314 " <menuitem action='Problem'/>"
316 " <menuitem action='About'/>"
320 " <toolbar name='ToolBar'>"
321 " <toolitem action='New'/>"
322 // here Open + recent is coded
323 " <toolitem action='Save'/>"
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'/>"
333 " <toolitem action='ShowOpe'/>"
334 " <toolitem action='AddOpe'/>"
336 " <toolitem action='RStatistics'/>"
337 " <toolitem action='RTrendTime'/>"
338 " <toolitem action='RBalance'/>"
339 " <toolitem action='RBudget'/>"
340 " <toolitem action='RVehiculeCost'/>"
353 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
)
355 //struct hbfile_data *data;
361 DB( g_print("\n[ui-mainwindow] revert\n") );
363 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
365 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
366 title
= g_strdup_printf (
367 _("Revert unsaved changes to file '%s'?"), basename
);
370 _("- Changes made to the file will be permanently lost\n"
371 "- File will be reloaded from the last save (.xhb~)");
373 result
= ui_dialog_msg_confirm_alert(
374 GTK_WINDOW(GLOBALS
->mainwindow
),
383 if( result
== GTK_RESPONSE_OK
)
385 DB( g_print(" - should revert\n") );
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"));
396 activate_url (GtkAboutDialog
*about
,
400 DB( g_print("activate url %s\n", link
) );
402 homebank_util_url_show (link
);
405 static void hbfile_about(void)
412 static const gchar
*artists
[] = {
417 static const gchar
*authors
[] = {
418 "Lead developer:\n" \
421 "Ga\xc3\xabtan LORIDANT (Maths formulas for charts)\n",
426 const gchar *documenters[] = {
432 static const gchar
*copyright
= "Copyright \xc2\xa9 1995-2016 - Maxime DOYEN";
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 ());
441 dialog
= gtk_about_dialog_new();
443 gtk_window_set_transient_for (GTK_WINDOW(dialog
), GTK_WINDOW(GLOBALS
->mainwindow
));
444 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
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
);
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");
456 gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(dialog
), "homebank");
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
);
464 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog
), pixbuf
);
465 g_object_unref (pixbuf
);
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), );
473 g_signal_connect (dialog
, "activate-link", G_CALLBACK (activate_url
), NULL
);
475 gtk_dialog_run (GTK_DIALOG (dialog
));
477 gtk_widget_destroy (dialog
);
484 /* hbfile action functions -------------------- */
485 static void ui_mainwindow_action_new(void)
487 GtkWidget
*widget
= GLOBALS
->mainwindow
;
489 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
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
));
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
);
502 static void ui_mainwindow_action_open(void)
504 ui_mainwindow_open(GLOBALS
->mainwindow
, NULL
);
507 static void ui_mainwindow_action_save(void)
509 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
512 static void ui_mainwindow_action_saveas(void)
514 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
517 static void ui_mainwindow_action_revert(void)
519 ui_mainwindow_revert(GLOBALS
->mainwindow
, NULL
);
522 static void ui_mainwindow_action_close(void)
524 GtkWidget
*widget
= GLOBALS
->mainwindow
;
526 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
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
));
536 static void ui_mainwindow_action_quit(void)
540 //gtk_widget_destroy(GLOBALS->mainwindow);
542 g_signal_emit_by_name(GLOBALS
->mainwindow
, "delete-event", NULL
, &result
);
547 static void ui_mainwindow_action_file_statistics(void)
549 ui_dialog_file_statistics();
553 static void ui_mainwindow_action_properties(void)
555 create_defhbfile_dialog();
556 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
559 static void ui_mainwindow_action_anonymize(void)
565 title
= _("Are you sure you want to anonymize the file?");
568 _("Proceeding will anonymize any text, \n"
569 "like 'account x', 'payee y', 'memo z', ...");
571 result
= ui_dialog_msg_confirm_alert(
572 GTK_WINDOW(GLOBALS
->mainwindow
),
578 if( result
== GTK_RESPONSE_CANCEL
)
582 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
586 static void ui_mainwindow_action_defcurrency(void)
588 ui_cur_manage_dialog();
589 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
593 static void ui_mainwindow_action_defaccount(void)
595 ui_acc_manage_dialog();
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
);
602 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
));
605 static void ui_mainwindow_action_defpayee(void)
607 ui_pay_manage_dialog();
608 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
611 static void ui_mainwindow_action_defcategory(void)
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
));
620 static void ui_mainwindow_defarchive(Archive
*arc
)
622 struct hbfile_data
*data
;
625 data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
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
));
631 ui_arc_manage_dialog(arc
);
633 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
635 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
639 static void ui_mainwindow_action_defarchive(void)
641 ui_mainwindow_defarchive(NULL
);
645 static void ui_mainwindow_action_defbudget(void)
647 ui_bud_manage_dialog();
648 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
652 static void ui_mainwindow_action_defassign(void)
655 ui_asg_manage_dialog();
657 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
661 static void ui_mainwindow_action_preferences(void)
663 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
665 defpref_dialog_new();
666 if(!PREFS
->euro_active
)
668 GtkToggleAction
*action
= (GtkToggleAction
*)gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor");
670 gtk_toggle_action_set_active(action
, FALSE
);
671 ui_mainwindow_action_toggle_minor(action
);
673 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
+UF_REFRESHALL
));
678 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction
*action
)
680 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
682 PREFS
->wal_toolbar
= gtk_toggle_action_get_active(action
);
683 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
686 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction
*action
)
688 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
690 PREFS
->wal_upcoming
= gtk_toggle_action_get_active(action
);
691 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
694 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction
*action
)
696 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
698 PREFS
->wal_spending
= gtk_toggle_action_get_active(action
);
699 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
702 static void ui_mainwindow_action_toggle_minor(GtkToggleAction
*action
)
704 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
706 GLOBALS
->minor
= gtk_toggle_action_get_active(action
);
708 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
709 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
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
);
717 static void ui_mainwindow_action_showtransactions(void)
719 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
725 if( data
->acc
->window
== NULL
)
727 window
= register_panel_window_new(data
->acc
->key
, data
->acc
);
728 register_panel_window_init(window
, NULL
);
732 if(GTK_IS_WINDOW(data
->acc
->window
))
733 gtk_window_present(data
->acc
->window
);
740 static void ui_mainwindow_action_addtransactions(void)
742 ui_mainwindow_addtransactions(GLOBALS
->mainwindow
, NULL
);
745 static void ui_mainwindow_action_checkscheduled(void)
747 ui_mainwindow_scheduled_postall(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
750 static void ui_mainwindow_action_statistic(void)
752 ui_repdist_window_new();
755 static void ui_mainwindow_action_trendtime(void)
757 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
759 ui_reptime_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
762 static void ui_mainwindow_action_budget(void)
764 repbudget_window_new();
767 static void ui_mainwindow_action_balance(void)
769 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
771 repbalance_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
774 static void ui_mainwindow_action_vehiclecost(void)
776 repcost_window_new();
779 static void ui_mainwindow_action_import(GtkAction
*action
)
782 gint filetype
= FILETYPE_UNKNOW
;
784 name
= gtk_action_get_name(action
);
786 if( g_str_has_suffix (name
, "QIF"))
787 filetype
= FILETYPE_QIF
;
789 if( g_str_has_suffix (name
, "OFX"))
790 filetype
= FILETYPE_OFX
;
792 if( g_str_has_suffix (name
, "CSV"))
793 filetype
= FILETYPE_CSV_HB
;
795 DB( g_print("action %s type=%d\n", name
, filetype
) );
797 ui_import_assistant_new(filetype
);
802 static void ui_mainwindow_action_about(void)
809 static void ui_mainwindow_action_export(void)
813 if( ui_file_chooser_qif(NULL
, &filename
) == TRUE
)
815 hb_export_qif_account_all(filename
);
820 static void ui_mainwindow_action_help(void)
824 link
= g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP
, NULL
);
825 homebank_util_url_show (link
);
831 //todo: move this to a ui-assist-welcome.c
833 static void ui_mainwindow_action_help_welcome1 (GtkButton
*button
, gpointer user_data
)
835 gtk_dialog_response (GTK_DIALOG(user_data
), 1);
838 static void ui_mainwindow_action_help_welcome2 (GtkButton
*button
, gpointer user_data
)
840 gtk_dialog_response (GTK_DIALOG(user_data
), 2);
843 static void ui_mainwindow_action_help_welcome3 (GtkButton
*button
, gpointer user_data
)
845 gtk_dialog_response (GTK_DIALOG(user_data
), 3);
848 static void ui_mainwindow_action_help_welcome4 (GtkButton
*button
, gpointer user_data
)
850 gtk_dialog_response (GTK_DIALOG(user_data
), 4);
853 static void ui_mainwindow_action_help_welcome5 (GtkButton
*button
, gpointer user_data
)
855 gtk_dialog_response (GTK_DIALOG(user_data
), 5);
858 void ui_mainwindow_action_help_welcome(void)
860 GtkWidget
*dialog
, *content_area
;
861 GtkWidget
*mainvbox
, *widget
, *label
;
863 dialog
= gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
864 GTK_WINDOW(GLOBALS
->mainwindow
),
870 content_area
= gtk_dialog_get_content_area(GTK_DIALOG (dialog
));
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
);
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);
880 label
= make_label (_("Free, easy, personal accounting for everyone"), 0, 0);
881 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
883 widget
= gtk_separator_new(GTK_ORIENTATION_HORIZONTAL
);
884 gtk_box_pack_start (GTK_BOX (content_area
), widget
, FALSE
, FALSE
, 0);
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
);
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);
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
);
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
);
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
);
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
);
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
);
914 //connect all our signals
915 g_signal_connect (dialog
, "destroy", G_CALLBACK (gtk_widget_destroyed
), &dialog
);
917 gtk_widget_show_all (dialog
);
920 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
922 // cleanup and destroy
923 gtk_widget_destroy (dialog
);
925 // do appropriate action
929 ui_mainwindow_action_help();
932 ui_mainwindow_action_preferences();
935 ui_mainwindow_action_new();
938 ui_mainwindow_action_open();
941 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL
));
942 ui_mainwindow_open_internal(GLOBALS
->mainwindow
, NULL
);
950 static void ui_mainwindow_action_help_online(void)
952 const gchar
*link
= HOMEBANK_URL_HELP_ONLINE
;
954 homebank_util_url_show (link
);
958 static void ui_mainwindow_action_help_translate(void)
960 const gchar
*link
= HOMEBANK_URL_HELP_TRANSLATE
;
962 homebank_util_url_show (link
);
966 static void ui_mainwindow_action_help_problem(void)
968 const gchar
*link
= HOMEBANK_URL_HELP_PROBLEM
;
970 homebank_util_url_show (link
);
977 /* hbfile functions -------------------- */
985 static void ui_mainwindow_selection(GtkTreeSelection
*treeselection
, gpointer user_data
)
987 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
991 static void ui_mainwindow_close_openbooks(void)
995 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
997 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1000 Account
*item
= elt
->data
;
1004 gtk_widget_destroy(GTK_WIDGET(item
->window
));
1005 item
->window
= NULL
;
1008 elt
= g_list_next(elt
);
1019 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
)
1021 struct hbfile_data
*data
;
1022 gboolean file_clear
= GPOINTER_TO_INT(user_data
);
1024 DB( g_print("\n[ui-mainwindow] clear\n") );
1026 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1028 // Close opened account window
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
))));
1035 hbfile_cleanup(file_clear
);
1036 hbfile_setup(file_clear
);
1042 ** add some transactions directly
1044 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
)
1046 struct hbfile_data
*data
;
1050 gint account
, count
;
1052 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1054 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1056 /* init the transaction */
1057 date
= homebank_app_date_get_julian();
1058 //todo: maybe think about set a default account here
1060 if(data
->acc
!= NULL
)
1061 account
= data
->acc
->key
;
1063 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
, FALSE
);
1065 while(result
== GTK_RESPONSE_ADD
|| result
== GTK_RESPONSE_ADDKEEP
)
1069 /* fill in the transaction */
1070 if( result
== GTK_RESPONSE_ADD
)
1072 ope
= da_transaction_malloc();
1074 ope
->kacc
= account
;
1076 if( PREFS
->heritdate
== FALSE
) //fix: 318733
1077 ope
->date
= GLOBALS
->today
;
1080 // normally we can't be in addkeep without initialized ope with add
1082 deftransaction_set_transaction(window
, ope
);
1084 result
= gtk_dialog_run (GTK_DIALOG (window
));
1086 DB( g_print(" - dialog result is %d\n", result
) );
1088 if(result
== GTK_RESPONSE_ADD
|| result
== GTK_RESPONSE_ADDKEEP
|| result
== GTK_RESPONSE_ACCEPT
)
1090 deftransaction_get(window
, NULL
);
1091 transaction_add(ope
, NULL
, ope
->kacc
);
1093 DB( g_print(" - added 1 transaction to %d\n", ope
->kacc
) );
1095 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
1098 //todo: still usefull ? store last date
1102 if( result
== GTK_RESPONSE_ADD
)
1104 da_transaction_free(ope
);
1111 deftransaction_dispose(window
, NULL
);
1112 gtk_widget_destroy (window
);
1114 /* todo optimize this */
1117 GLOBALS
->changes_count
+= count
;
1118 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
1128 static gint
tmptop_compare_func(struct tmptop
*tt1
, struct tmptop
*tt2
)
1130 return tt1
->value
> tt2
->value
? 1 : -1;
1134 static void ui_mainwindow_populate_topspending(GtkWidget
*widget
, gpointer user_data
)
1136 struct hbfile_data
*data
;
1137 GtkTreeModel
*model
;
1141 guint n_result
, i
, n_items
;
1143 gdouble total
, other
;
1146 #define MAX_TOPSPENDING 5
1148 DB( g_print("\n[ui-mainwindow] populate_topspending\n") );
1150 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1152 type
= radio_get_active(GTK_CONTAINER(data
->RA_type
));
1153 range
= gtk_combo_box_get_active(GTK_COMBO_BOX(data
->CY_range
));
1155 DB( g_print(" - type=%d, range=%d\n", type
, range
) );
1156 DB( g_print(" - pref range=%d\n", PREFS
->date_range_wal
) );
1158 if(range
== FLT_RANGE_OTHER
)
1161 filter_preset_daterange_set(data
->filter
, range
, 0);
1164 n_result
= da_cat_get_max_key() + 1;
1167 DB( g_print(" - max key is %d\n", n_result
) );
1169 /* allocate some memory */
1170 garray
= g_array_sized_new(FALSE
, FALSE
, sizeof(struct tmptop
), n_result
);
1174 struct tmptop zero
= { .key
=0, .value
=0.0 };
1177 //DB( g_print(" - array length=%d\n", garray->len) );
1179 for(i
=0 ; i
<n_result
; i
++)
1181 g_array_append_vals(garray
, &zero
, 1);
1182 //g_array_insert_vals(garray, i, &zero, 1);
1184 //struct tmptop *tt = &g_array_index (garray, struct tmptop, i);
1185 //DB( g_print("%4d, %4d %f\n", i, tt->key, tt->value) );
1188 //DB( g_print("\n - end array length=%d\n", garray->len) );
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
);
1193 /* compute the results */
1194 list
= g_queue_peek_head_link(txn_queue
);
1195 while (list
!= NULL
)
1197 Transaction
*ope
= list
->data
;
1199 //DB( g_print(" - eval txn: '%s', cat=%d ==> flt-test=%d\n", ope->wording, ope->kcat, filter_test(data->filter, ope)) );
1201 if( !(ope
->paymode
== PAYMODE_INTXFER
) )
1206 //todo: optimize here
1207 trn_amount
= ope
->amount
;
1208 acc
= da_acc_get(ope
->kacc
);
1210 trn_amount
= hb_amount_base(ope
->amount
, acc
->kcur
);
1212 if( ope
->flags
& OF_SPLIT
)
1214 guint nbsplit
= da_splits_count(ope
->splits
);
1216 struct tmptop
*item
;
1218 for(i
=0;i
<nbsplit
;i
++)
1220 split
= ope
->splits
[i
];
1221 pos
= category_report_id(split
->kcat
, type
);
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
);
1228 item
->value
+= trn_amount
;
1229 //DB( g_print(" - stored %.2f to item %d\n", trn_amount, pos) );
1235 struct tmptop
*item
;
1237 pos
= category_report_id(ope
->kcat
, type
);
1239 //#1297054 if( trn_amount < 0 ) {
1240 item
= &g_array_index (garray
, struct tmptop
, pos
);
1242 item
->value
+= trn_amount
;
1243 //DB( g_print(" - stored %.2f to item %d\n", trn_amount, pos) );
1250 list
= g_list_next(list
);
1253 g_queue_free (txn_queue
);
1255 // we need to sort this and limit before
1256 g_array_sort(garray
, (GCompareFunc
)tmptop_compare_func
);
1258 n_items
= MIN(garray
->len
,MAX_TOPSPENDING
);
1260 for(i
=0 ; i
<garray
->len
; i
++)
1262 struct tmptop
*item
;
1264 item
= &g_array_index (garray
, struct tmptop
, i
);
1267 total
+= item
->value
;
1270 other
+= item
->value
;
1272 DB( g_print(" - %d : k='%d' v='%f' t='%f'\n", i
, item
->key
, item
->value
, total
) );
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 */
1282 /* insert into the treeview */
1283 for(i
=0 ; i
<MIN(garray
->len
,MAX_TOPSPENDING
) ; i
++)
1287 struct tmptop
*item
;
1290 item
= &g_array_index (garray
, struct tmptop
, i
);
1292 if(!item
->value
) continue;
1294 value
= hb_amount_round(item
->value
, 2);
1295 entry
= da_cat_get(item
->key
);
1296 if(entry
== NULL
) continue;
1298 name
= entry
->key
== 0 ? _("(no category)") : da_cat_get_fullname(entry
);
1301 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1302 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
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),
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),
1325 /* Re-attach model to view */
1326 gtk_tree_view_set_model(GTK_TREE_VIEW(data
->LV_top
), model
);
1327 g_object_unref(model
);
1329 data
->toptotal
= total
;
1330 hb_label_set_amount(GTK_LABEL(data
->TX_topamount
), total
, GLOBALS
->kcur
, GLOBALS
->minor
);
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);
1337 /* update info range text */
1341 daterange
= filter_daterange_text_get(data
->filter
);
1342 gtk_widget_set_tooltip_markup(GTK_WIDGET(data
->CY_range
), daterange
);
1347 /* free our memory */
1348 g_array_free (garray
, TRUE
);
1353 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1355 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1357 ui_mainwindow_scheduled_get_selected_item(GtkTreeView
*treeview
)
1359 GtkTreeSelection
*treeselection
;
1360 GtkTreeModel
*model
;
1363 treeselection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
1364 if( gtk_tree_selection_get_selected(treeselection
, &model
, &iter
) )
1368 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPUPC_DATAS
, &arc
, -1);
1376 static void ui_mainwindow_scheduled_onRowActivated (GtkTreeView
*treeview
,
1378 GtkTreeViewColumn
*col
,
1381 //struct hbfile_data *data;
1384 DB( g_print ("\n[ui-mainwindow] A scheduled row has been double-clicked!\n") );
1386 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(treeview, GTK_TYPE_WINDOW)), "inst_data");
1388 arc
= ui_mainwindow_scheduled_get_selected_item(treeview
);
1389 ui_mainwindow_defarchive(arc
);
1393 static void ui_mainwindow_scheduled_do_post(Archive
*arc
, gboolean doedit
, gpointer user_data
)
1395 struct hbfile_data
*data
= user_data
;
1400 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
, TRUE
);
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
);
1407 deftransaction_set_transaction(window
, txn
);
1409 result
= gtk_dialog_run (GTK_DIALOG (window
));
1411 DB( g_print(" - dialog result is %d\n", result
) );
1413 if(result
== GTK_RESPONSE_ADD
|| result
== GTK_RESPONSE_ACCEPT
)
1415 deftransaction_get(window
, NULL
);
1416 transaction_add(txn
, NULL
, txn
->kacc
);
1417 GLOBALS
->changes_count
++;
1419 scheduled_date_advance(arc
);
1421 DB( g_print(" - added 1 transaction to %d\n", txn
->kacc
) );
1424 da_transaction_free(txn
);
1426 deftransaction_dispose(window
, NULL
);
1427 gtk_widget_destroy (window
);
1432 static void ui_mainwindow_scheduled_editpost_cb(GtkWidget
*widget
, gpointer user_data
)
1434 struct hbfile_data
*data
= user_data
;
1436 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1440 ui_mainwindow_scheduled_do_post(arc
, TRUE
, data
);
1441 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_SENSITIVE
|UF_REFRESHALL
));
1446 static void ui_mainwindow_scheduled_post_cb(GtkWidget
*widget
, gpointer user_data
)
1448 struct hbfile_data
*data
= user_data
;
1450 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1454 if( scheduled_is_postable(arc
) )
1456 Transaction
*txn
= da_transaction_malloc ();
1458 da_transaction_init_from_template(txn
, arc
);
1459 txn
->date
= scheduled_get_postdate(arc
, arc
->nextdate
);
1460 transaction_add(txn
, NULL
, 0);
1462 GLOBALS
->changes_count
++;
1463 scheduled_date_advance(arc
);
1465 da_transaction_free (txn
);
1469 ui_mainwindow_scheduled_do_post(arc
, FALSE
, data
);
1472 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_SENSITIVE
|UF_REFRESHALL
));
1477 static void ui_mainwindow_scheduled_skip_cb(GtkWidget
*widget
, gpointer user_data
)
1479 struct hbfile_data
*data
= user_data
;
1481 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1482 if( (arc
!= NULL
) && (arc
->flags
& OF_AUTO
) )
1484 GLOBALS
->changes_count
++;
1485 scheduled_date_advance(arc
);
1487 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1488 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_SENSITIVE
));
1494 static void ui_mainwindow_scheduled_update(GtkWidget
*widget
, gpointer user_data
)
1496 struct hbfile_data
*data
;
1499 DB( g_print("\n[ui-mainwindow] scheduled update\n") );
1501 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1503 //filter = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_sched_filter));
1505 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1509 DB( g_print("archive is %s\n", arc
->wording
) );
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
);
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
);
1526 static void ui_mainwindow_scheduled_selection_cb(GtkTreeSelection
*treeselection
, gpointer user_data
)
1530 ui_mainwindow_scheduled_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
1536 ** called after load, importamiga, on demand
1538 void ui_mainwindow_scheduled_postall(GtkWidget
*widget
, gpointer user_data
)
1540 //struct hbfile_data *data;
1542 gint usermode
= GPOINTER_TO_INT(user_data
);
1544 DB( g_print("\n[ui-mainwindow] check scheduled\n") );
1546 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1548 count
= scheduled_post_all_pending();
1551 if(usermode
== TRUE
)
1558 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_REFRESHALL
));
1562 txt
= _("No transaction to add");
1564 txt
= _("transaction added: %d");
1566 ui_dialog_msg_infoerror(GTK_WINDOW(GLOBALS
->mainwindow
), GTK_MESSAGE_INFO
,
1567 _("Check scheduled transactions result"),
1575 static void ui_mainwindow_scheduled_populate(GtkWidget
*widget
, gpointer user_data
)
1577 struct hbfile_data
*data
;
1578 GtkTreeModel
*model
;
1585 guint32 maxpostdate
;
1589 DB( g_print("\n[ui-mainwindow] scheduled populate list\n") );
1591 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1593 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
));
1594 gtk_list_store_clear (GTK_LIST_STORE(model
));
1596 homebank_app_date_get_julian();
1598 maxpostdate
= scheduled_date_get_post_max();
1600 date
= g_date_new_julian (maxpostdate
);
1601 g_date_strftime (buffer
, 256-1, PREFS
->date_format
, date
);
1604 gtk_label_set_text(GTK_LABEL(data
->LB_maxpostdate
), buffer
);
1607 list
= g_list_first(GLOBALS
->arc_list
);
1608 while (list
!= NULL
)
1610 Archive
*arc
= list
->data
;
1613 guint nbdays
, nblate
;
1615 if((arc
->flags
& OF_AUTO
) ) //&& arc->kacc > 0)
1618 nbdays
= arc
->nextdate
- maxpostdate
;
1619 nblate
= scheduled_get_latepost_count(arc
, GLOBALS
->today
);
1621 DB( g_print(" - append '%s' : %d\n", arc
->wording
, nbdays
) );
1623 if(arc
->flags
& OF_INCOME
)
1634 /* insert normal txn */
1635 acc
= da_acc_get(arc
->kacc
);
1638 totinc
+= hb_amount_base(inc
, acc
->kcur
);
1639 totexp
+= hb_amount_base(exp
, acc
->kcur
);
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
,
1652 /* insert internal xfer txn : 1378836 */
1653 if(arc
->paymode
== PAYMODE_INTXFER
)
1655 acc
= da_acc_get(arc
->kxferacc
);
1658 totinc
+= hb_amount_base(-inc
, acc
->kcur
);
1659 totexp
+= hb_amount_base(-exp
, acc
->kcur
);
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
,
1674 list
= g_list_next(list
);
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
,
1691 ui_mainwindow_scheduled_update(widget
, NULL
);
1701 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
)
1703 //struct hbfile_data *data;
1704 gchar
*filename
= NULL
;
1706 DB( g_print("\n[ui-mainwindow] open\n") );
1708 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1710 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
1712 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN
, &filename
) == TRUE
)
1714 hbfile_change_filepath(filename
);
1716 ui_mainwindow_open_internal(widget
, NULL
);
1724 * open the file stored in GLOBALS->xhb_filepath
1726 void ui_mainwindow_open_internal(GtkWidget
*widget
, gpointer user_data
)
1728 struct hbfile_data
*data
;
1731 DB( g_print("\n[ui-mainwindow] open internal\n") );
1733 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1735 DB( g_print(" - filename: '%s'\n", GLOBALS
->xhb_filepath
) );
1737 if( GLOBALS
->xhb_filepath
!= NULL
)
1739 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
1740 GLOBALS
->hbfile_is_new
= FALSE
;
1742 r
= homebank_load_xml(GLOBALS
->xhb_filepath
);
1745 DB( g_print(" - file loaded ok : rcode=%d\n", r
) );
1747 hbfile_file_hasbackup(GLOBALS
->xhb_filepath
);
1749 if(PREFS
->appendscheduled
)
1750 scheduled_post_all_pending();
1752 if(PREFS
->do_update_currency
)
1753 ui_cur_manage_dialog_update_currencies(GTK_WINDOW(GLOBALS
->mainwindow
));
1755 homebank_lastopenedfiles_save();
1757 //todo: delete this after computing done at xml read
1758 account_compute_balances();
1760 ui_mainwindow_recent_add(data
, GLOBALS
->xhb_filepath
);
1764 gchar
*msg
= _("Unknow error");
1769 msg
= _("I/O error for file '%s'.");
1771 case XML_FILE_ERROR
:
1772 msg
= _("The file '%s' is not a valid HomeBank file.");
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.");
1779 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1782 GLOBALS
->xhb_filepath
1785 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
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
));
1801 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
)
1803 struct hbfile_data
*data
;
1804 gboolean saveas
= GPOINTER_TO_INT(user_data
);
1805 gchar
*filename
= NULL
;
1808 DB( g_print("\n[ui-mainwindow] save\n") );
1810 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1812 if( GLOBALS
->hbfile_is_new
== TRUE
)
1817 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE
, &filename
) == TRUE
)
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
;
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
);
1839 GLOBALS
->changes_count
= 0;
1840 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1844 gchar
*msg
= _("I/O error for file '%s'.");
1846 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1849 GLOBALS
->xhb_filepath
1858 void ui_mainwindow_populate_accounts(GtkWidget
*widget
, gpointer user_data
)
1860 struct hbfile_data
*data
;
1861 GtkTreeModel
*model
;
1862 GtkTreeIter iter1
, child_iter
;
1866 gdouble gtbank
, gttoday
, gtfuture
;
1868 DB( g_print("\n[ui-mainwindow] populate accounts\n") );
1870 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1872 /* here we create a count and a list of every account pointer by type */
1874 GPtrArray
*typeacc
[ACC_TYPE_MAXVALUE
] = {0};
1875 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1880 if( !(acc
->flags
& (AF_CLOSED
|AF_NOSUMMARY
)) )
1882 DB( g_print(" - insert %d:%s\n", acc
->key
, acc
->name
) );
1884 if(typeacc
[acc
->type
] == NULL
)
1885 typeacc
[acc
->type
] = g_ptr_array_sized_new(da_acc_length ());
1887 g_ptr_array_add(typeacc
[acc
->type
], (gpointer
)acc
);
1889 elt
= g_list_next(elt
);
1893 gtbank
= gttoday
= gtfuture
= 0;
1895 DB( g_print(" - populate listview\n") );
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
));
1903 for(i
=0;i
<ACC_TYPE_MAXVALUE
;i
++)
1905 GPtrArray
*gpa
= typeacc
[i
];
1906 gdouble tbank
, ttoday
, tfuture
;
1911 //1: Header: Bank, Cash, ...
1912 DB( g_print(" - append type '%s'\n", CYA_ACC_TYPE
[i
]) );
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
]),
1920 tbank
= ttoday
= tfuture
= 0;
1922 //2: Accounts for real
1923 for(j
=0;j
<gpa
->len
;j
++)
1925 acc
= g_ptr_array_index(gpa
, j
);
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
);
1934 DB( g_print(" - insert '%s' :: %.2f %.2f %.2f\n", acc
->name
, acc
->bal_bank
, acc
->bal_today
, acc
->bal_future
) );
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
,
1948 DB( g_print(" - type totals :: %.2f %.2f %.2f\n", tbank
, ttoday
, tfuture
) );
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
,
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
,
1968 /* add to grand total */
1971 gtfuture
+= tfuture
;
1977 DB( g_print(" - grand totals :: %.2f %.2f %.2f\n", gtbank
, gttoday
, gtfuture
) );
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
,
1993 gtk_tree_view_expand_all(GTK_TREE_VIEW(data
->LV_acc
));
1995 DB( g_print(" - free ressources\n") );
1998 /* free all temp stuff */
1999 for(i
=0;i
<ACC_TYPE_MAXVALUE
;i
++)
2001 GPtrArray
*gpa
= typeacc
[i
];
2004 g_ptr_array_free (gpa
, TRUE
);
2011 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
)
2013 struct hbfile_data
*data
;
2016 DB( g_print("\n[ui-mainwindow] refresh_display\n") );
2018 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
2019 //data = INST_DATA(widget);
2021 flags
= GPOINTER_TO_INT(user_data
);
2023 /* set window title */
2024 if(flags
& UF_TITLE
)
2029 DB( g_print(" + 1: wintitle %x\n", (gint
)data
->wintitle
) );
2031 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
2033 DB( g_print(" global changes: %d\n", GLOBALS
->changes_count
) );
2035 g_free(data
->wintitle
);
2037 changed
= (GLOBALS
->changes_count
> 0) ? "*" : "";
2039 data
->wintitle
= g_strdup_printf("%s%s - %s - " PROGNAME
, changed
, basename
, GLOBALS
->owner
);
2041 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), data
->wintitle
);
2046 /* update disabled things */
2047 if(flags
& UF_SENSITIVE
)
2049 GtkTreeSelection
*selection
;
2050 GtkTreeModel
*model
;
2053 gboolean active
,sensitive
;
2055 DB( g_print(" + 2: disabled, opelist count\n") );
2057 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
));
2059 active
= gtk_tree_selection_get_selected(selection
, &model
, &iter
);
2065 path
= gtk_tree_model_get_path(model
, &iter
);
2066 depth
= gtk_tree_path_get_depth(path
);
2070 DB( g_print(" depth is %d\n", depth
) );
2072 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPACC_DATAS
, &acc
, -1);
2081 //ensure data->acc will not be null
2082 data
->acc
= da_acc_get(1);
2086 // no change: disable save
2087 DB( g_print(" changes %d - new %d\n", GLOBALS
->changes_count
, GLOBALS
->hbfile_is_new
) );
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
);
2098 sensitive
= GLOBALS
->define_off
== 0 ? TRUE
: FALSE
;
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
);
2106 // empty account list: disable Import, Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
2107 sensitive
= da_acc_length() > 0 ? TRUE
: FALSE
;
2109 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data-data->manager, "/MenuBar/FileMenu/Import"), sensitive);
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
);
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
);
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);
2129 // empty archive list: disable scheduled check
2130 sensitive
= g_list_length(GLOBALS
->arc_list
) > 0 ? TRUE
: FALSE
;
2132 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddScheduled"), sensitive
);
2134 // no active account: disable Edit, Over
2135 sensitive
= (active
== TRUE
) ? TRUE
: FALSE
;
2136 if(data
->acc
&& data
->acc
->window
!= NULL
)
2139 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowOpe"), sensitive
);
2143 /* update toolbar, list */
2144 if(flags
& UF_VISUAL
)
2146 DB( g_print(" + 8: visual\n") );
2148 if(PREFS
->toolbar_style
== 0)
2149 gtk_toolbar_unset_style(GTK_TOOLBAR(data
->toolbar
));
2151 gtk_toolbar_set_style(GTK_TOOLBAR(data
->toolbar
), PREFS
->toolbar_style
-1);
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
));
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
));
2159 DB( g_print(" - show toolbar=%d\n", PREFS
->wal_toolbar
) );
2160 if(PREFS
->wal_toolbar
)
2161 gtk_widget_show(GTK_WIDGET(data
->toolbar
));
2163 gtk_widget_hide(GTK_WIDGET(data
->toolbar
));
2166 DB( g_print(" - show top_spending=%d\n", PREFS
->wal_spending
) );
2168 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
2170 if(PREFS
->wal_spending
)
2171 gtk_widget_show(GTK_WIDGET(data
->GR_top
));
2173 gtk_widget_hide(GTK_WIDGET(data
->GR_top
));
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
));
2181 gtk_widget_hide(GTK_WIDGET(data
->GR_upc
));
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
);
2187 /* update balances */
2188 if(flags
& UF_BALANCE
)
2191 DB( g_print(" + 4: balances\n") );
2193 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
2195 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
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);
2204 if(flags
& UF_REFRESHALL
)
2206 DB( g_print(" + 8: refreshall\n") );
2208 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
2209 ui_mainwindow_populate_topspending(GLOBALS
->mainwindow
, NULL
);
2210 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
2219 ui_mainwindow_onRowActivated (GtkTreeView
*treeview
,
2221 GtkTreeViewColumn
*col
,
2224 GtkTreeModel
*model
;
2227 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
2229 model
= gtk_tree_view_get_model(treeview
);
2231 if (gtk_tree_model_get_iter(model
, &iter
, path
))
2235 gtk_tree_model_get(model
, &iter
, LST_DSPACC_DATAS
, &acc
, -1);
2240 DB( g_print ("Double-clicked row contains name %s\n", acc
->name
) );
2242 ui_mainwindow_action_showtransactions();
2252 static gboolean
ui_mainwindow_dispose(GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
2254 struct hbfile_data
*data
= user_data
;
2255 struct WinGeometry
*wg
;
2256 gboolean retval
= FALSE
;
2258 DB( g_print("\n[ui-mainwindow] dispose\n") );
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;
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
) );
2270 PREFS
->wal_vpaned
= gtk_paned_get_position(GTK_PANED(data
->vpaned
));
2271 PREFS
->wal_hpaned
= gtk_paned_get_position(GTK_PANED(data
->hpaned
));
2273 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
2276 if(ui_dialog_msg_savechanges(widget
, NULL
) == FALSE
)
2282 DB( g_print(" free wintitle %x\n", (gint
)data
->wintitle
) );
2284 gtk_widget_destroy(data
->LV_top
);
2286 g_free(data
->wintitle
);
2287 da_filter_free(data
->filter
);
2294 //delete-event TRUE abort/FALSE destroy
2299 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser
*chooser
, struct hbfile_data
*data
)
2302 GError
*error
= NULL
;
2304 uri
= gtk_recent_chooser_get_current_uri (chooser
);
2306 path
= g_filename_from_uri (uri
, NULL
, NULL
);
2309 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
2310 g_error_free (error
);
2314 if( ui_dialog_msg_savechanges(data
->window
, NULL
) == TRUE
)
2321 gpw_recent_remove (gpw, path);
2325 hbfile_change_filepath(path
);
2326 ui_mainwindow_open_internal(data
->window
, NULL
);
2336 static void ui_mainwindow_window_screen_changed_cb (GtkWidget
*widget
,
2337 GdkScreen
*old_screen
,
2338 struct hbfile_data
*data
)
2341 DB( g_print("\n[ui-mainwindow] screen_changed_cb\n") );
2344 data
->recent_manager
= gtk_recent_manager_get_default ();
2346 gtk_menu_detach (GTK_MENU (data
->recent_menu
));
2347 g_object_unref (G_OBJECT (data
->recent_menu
));
2349 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2351 g_signal_connect (data
->recent_menu
,
2353 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
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);
2361 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
)
2363 GtkRecentData
*recent_data
;
2365 GError
*error
= NULL
;
2367 DB( g_print("\n[ui-mainwindow] recent_add\n") );
2369 DB( g_print(" - file has .xhb suffix = %d\n", g_str_has_suffix (path
, ".xhb") ) );
2371 if( g_str_has_suffix (path
, ".xhb") == FALSE
) //ignore reverted file
2374 uri
= g_filename_to_uri (path
, NULL
, &error
);
2377 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
2378 g_error_free (error
);
2382 recent_data
= g_slice_new (GtkRecentData
);
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
;
2392 if (!gtk_recent_manager_add_full (data
->recent_manager
,
2396 g_warning ("Unable to add '%s' to the list of recently used documents", uri
);
2400 g_free (recent_data
->app_exec
);
2401 g_slice_free (GtkRecentData
, recent_data
);
2414 static GtkTargetEntry drop_types
[] =
2416 {"text/uri-list", 0, TARGET_URI_LIST
}
2419 static void ui_mainwindow_drag_data_received (GtkWidget
*widget
,
2420 GdkDragContext
*context
,
2422 GtkSelectionData
*selection_data
,
2423 guint info
, guint time
, GtkWindow
*window
)
2425 gchar
**uris
, **str
;
2427 gint filetype
, slen
;
2429 if (info
!= TARGET_URI_LIST
)
2432 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
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;
2440 uris
= g_uri_list_extract_uris (newseldata
);
2443 //for (str = uris; *str; str++)
2446 GError
*error
= NULL
;
2447 gchar
*path
= g_filename_from_uri (*str
, NULL
, &error
);
2451 filetype
= homebank_alienfile_recognize(path
);
2453 DB( g_print(" - dragged %s, type is %d\n", path
, filetype
) );
2455 if( filetype
== FILETYPE_HOMEBANK
)
2457 hbfile_change_filepath(g_strdup(path
));
2458 ui_mainwindow_open_internal(GTK_WIDGET(window
), NULL
);
2462 //todo: future here to implement import for other filetype
2464 ui_dialog_msg_infoerror(GTK_WINDOW(window
), GTK_MESSAGE_ERROR
,
2466 _("The file %s is not a valid HomeBank file."),
2476 g_warning ("Could not convert uri to local path: %s", error
->message
);
2478 g_error_free (error
);
2488 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
)
2490 GtkWidget
*toolbar_recent_menu
;
2491 GtkRecentFilter
*filter
;
2493 toolbar_recent_menu
= gtk_recent_chooser_menu_new_for_manager (manager
);
2495 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu
),
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
),
2504 //gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (toolbar_recent_menu), FALSE);
2506 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (toolbar_recent_menu), TRUE);
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
);
2513 return toolbar_recent_menu
;
2517 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data
*data
, GtkWidget
*mainvbox
)
2519 GtkUIManager
*manager
;
2520 GtkActionGroup
*action_group
;
2522 GError
*error
= NULL
;
2524 manager
= gtk_ui_manager_new ();
2525 data
->manager
= manager
;
2527 gtk_window_add_accel_group (GTK_WINDOW (data
->window
),
2528 gtk_ui_manager_get_accel_group(manager
));
2530 action_group
= gtk_action_group_new ("MainWindow");
2531 gtk_action_group_set_translation_domain(action_group
, GETTEXT_PACKAGE
);
2533 gtk_action_group_add_actions (action_group
,
2538 gtk_action_group_add_toggle_actions (action_group
,
2543 gtk_ui_manager_insert_action_group (data
->manager
, action_group
, 0);
2544 g_object_unref (action_group
);
2545 data
->actions
= action_group
;
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
);
2551 //action = gtk_action_group_get_action(action_group, "Save");
2552 //g_object_set(action, "is_important", TRUE, NULL);
2554 action
= gtk_action_group_get_action(action_group
, "Account");
2555 g_object_set(action
, "short_label", _("Account"), NULL
);
2557 action
= gtk_action_group_get_action(action_group
, "Payee");
2558 g_object_set(action
, "short_label", _("Payee"), NULL
);
2560 action
= gtk_action_group_get_action(action_group
, "Category");
2561 g_object_set(action
, "short_label", _("Category"), NULL
);
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
);
2567 action
= gtk_action_group_get_action(action_group
, "Budget");
2568 g_object_set(action
, "short_label", _("Budget"), NULL
);
2570 action
= gtk_action_group_get_action(action_group
, "ShowOpe");
2571 g_object_set(action
, "short_label", _("Show"), NULL
);
2573 action
= gtk_action_group_get_action(action_group
, "AddOpe");
2574 g_object_set(action
, "is_important", TRUE
, "short_label", _("Add"), NULL
);
2576 action
= gtk_action_group_get_action(action_group
, "RStatistics");
2577 g_object_set(action
, "short_label", _("Statistics"), NULL
);
2579 action
= gtk_action_group_get_action(action_group
, "RBudget");
2580 g_object_set(action
, "short_label", _("Budget"), NULL
);
2582 action
= gtk_action_group_get_action(action_group
, "RBalance");
2583 g_object_set(action
, "short_label", _("Balance"), NULL
);
2585 action
= gtk_action_group_get_action(action_group
, "RVehiculeCost");
2586 g_object_set(action
, "short_label", _("Vehicle cost"), NULL
);
2588 /* now load the UI definition */
2589 gtk_ui_manager_add_ui_from_string (data
->manager
, ui_info
, -1, &error
);
2592 g_message ("Building menus failed: %s", error
->message
);
2593 g_error_free (error
);
2596 //todo: this generate a warning
2597 data
->menubar
= gtk_ui_manager_get_widget (manager
, "/MenuBar");
2598 gtk_box_pack_start (GTK_BOX (mainvbox
),
2604 data
->toolbar
= gtk_ui_manager_get_widget (manager
, "/ToolBar");
2605 gtk_box_pack_start (GTK_BOX (mainvbox
),
2611 /* recent files menu */
2613 data
->recent_manager
= gtk_recent_manager_get_default ();
2615 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2617 g_signal_connect (data
->recent_menu
,
2619 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
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);
2628 /* add the custom Open button to the toolbar */
2629 GtkWidget
*image
= gtk_image_new_from_icon_name (ICONNAME_OPEN
, GTK_ICON_SIZE_BUTTON
);
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
);
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"));
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
);
2642 gtk_toolbar_insert (GTK_TOOLBAR (data
->toolbar
), open_button
, 1);
2647 static GtkWidget
*ui_mainwindow_create_youraccounts(struct hbfile_data
*data
)
2649 GtkWidget
*mainvbox
, *label
, *widget
, *sw
;
2651 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
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);
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);
2669 widget
= (GtkWidget
*)create_list_account();
2670 data
->LV_acc
= widget
;
2671 gtk_container_add (GTK_CONTAINER (sw
), widget
);
2677 static GtkWidget
*ui_mainwindow_create_topspending(struct hbfile_data
*data
)
2679 GtkWidget
*mainvbox
, *hbox
, *vbox
;
2680 GtkWidget
*label
, *widget
;
2682 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2683 data
->GR_top
= mainvbox
;
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);
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);
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);
2704 label
= make_label(_("Top spending"), 0.0, 0.5);
2705 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
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);
2711 data
->CY_range
= make_daterange(label
, FALSE
);
2712 gtk_box_pack_end (GTK_BOX (hbox
), data
->CY_range
, FALSE
, FALSE
, 0);
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);
2718 /* pie + listview */
2719 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
2720 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, TRUE
, TRUE
, 0);
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);
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);
2734 widget
= (GtkWidget
*)create_list_topspending();
2735 data
->LV_top
= widget
;
2737 gtk_chart_show_legend(GTK_CHART(data
->RE_pie
), TRUE
, TRUE
);
2739 // gtk_container_add (GTK_CONTAINER (sw), widget);
2745 static GtkWidget
*ui_mainwindow_scheduled_create(struct hbfile_data
*data
)
2747 GtkWidget
*mainvbox
, *hbox
, *vbox
, *bbox
, *sw
, *tbar
;
2748 GtkWidget
*label
, *widget
;
2749 GtkToolItem
*toolitem
;
2751 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2752 data
->GR_upc
= mainvbox
;
2754 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, SPACING_SMALL
);
2755 gtk_box_pack_start (GTK_BOX (mainvbox
), hbox
, FALSE
, FALSE
, 0);
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);
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);
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);
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);
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);
2785 widget
= (GtkWidget
*)create_list_upcoming();
2786 data
->LV_upc
= widget
;
2787 gtk_container_add (GTK_CONTAINER (sw
), widget
);
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);
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);
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);
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);
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);
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"));
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"));
2833 ** the window creation
2835 GtkWidget
*create_hbfile_window(GtkWidget
*do_widget
)
2837 struct hbfile_data
*data
;
2838 struct WinGeometry
*wg
;
2839 GtkWidget
*mainvbox
, *vbox
, *vpaned
, *hpaned
;
2844 DB( g_print("\n[ui-mainwindow] create main window\n") );
2846 data
= g_malloc0(sizeof(struct hbfile_data
));
2847 if(!data
) return NULL
;
2849 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
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
) );
2855 // this is our mainwindow, so store it to GLOBALS data
2856 data
->window
= window
;
2857 GLOBALS
->mainwindow
= window
;
2859 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2860 gtk_container_add (GTK_CONTAINER (window
), mainvbox
);
2862 ui_mainwindow_create_menu_bar_and_toolbar (data
, mainvbox
);
2864 #if HB_UNSTABLE == TRUE
2865 GtkWidget
*bar
, *label
;
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);
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);
2880 vpaned
= gtk_paned_new(GTK_ORIENTATION_VERTICAL
);
2881 data
->vpaned
= vpaned
;
2882 gtk_box_pack_start (GTK_BOX (vbox
), vpaned
, TRUE
, TRUE
, 0);
2884 hpaned
= gtk_paned_new(GTK_ORIENTATION_HORIZONTAL
);
2885 data
->hpaned
= hpaned
;
2886 gtk_paned_pack1 (GTK_PANED(vpaned
), hpaned
, FALSE
, FALSE
);
2888 widget
= ui_mainwindow_scheduled_create(data
);
2889 gtk_paned_pack2 (GTK_PANED(vpaned
), widget
, FALSE
, FALSE
);
2891 widget
= ui_mainwindow_create_youraccounts(data
);
2892 gtk_paned_pack1 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
2894 widget
= ui_mainwindow_create_topspending(data
);
2895 gtk_paned_pack2 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
2898 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
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
);
2905 //setup, init and show window
2906 wg
= &PREFS
->wal_wg
;
2909 gtk_window_move(GTK_WINDOW(window
), wg
->l
, wg
->t
);
2910 gtk_window_resize(GTK_WINDOW(window
), wg
->w
, wg
->h
);
2913 gtk_window_maximize(GTK_WINDOW(window
));
2915 gtk_widget_show_all (window
);
2917 //todo: move this elsewhere
2918 DB( g_print(" - setup stuff\n") );
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
);
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
);
2933 /* Drag and drop support, set targets to NULL because we add the
2934 default uri_targets below */
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
,
2940 G_N_ELEMENTS (drop_types
),
2943 g_signal_connect (G_OBJECT (window
), "drag-data-received",
2944 G_CALLBACK (ui_mainwindow_drag_data_received
), window
);
2948 //connect all our signals
2949 DB( g_print(" - connect signals\n") );
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));
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
);
2961 widget
= radio_get_nth_widget(GTK_CONTAINER(data
->RA_type
), 1);
2963 g_signal_connect (widget
, "toggled", G_CALLBACK (ui_mainwindow_populate_topspending
), &data
);
2965 g_signal_connect (data
->CY_range
, "changed", G_CALLBACK (ui_mainwindow_populate_topspending
), NULL
);
2968 /* GtkWindow events */
2969 g_signal_connect (window
, "delete-event", G_CALLBACK (ui_mainwindow_dispose
), (gpointer
)data
);
2972 g_signal_connect (window
, "screen-changed",
2973 G_CALLBACK (ui_mainwindow_window_screen_changed_cb
),
2977 //gtk_action_group_set_sensitive(data->actions, FALSE);