1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2017 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_panel_topspending_update(GtkWidget
*widget
, gpointer user_data
);
142 static void ui_mainwindow_scheduled_populate(GtkWidget
*widget
, gpointer user_data
);
143 void ui_mainwindow_scheduled_postall(GtkWidget
*widget
, gpointer user_data
);
145 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
147 extern gchar
*CYA_ACC_TYPE
[];
149 gchar
*CYA_CATSUBCAT
[] = {
156 static GtkActionEntry entries
[] = {
158 /* name, icon-name, label */
160 { "FileMenu" , NULL
, N_("_File"), NULL
, NULL
, NULL
},
161 { "ImportMenu" , NULL
, N_("_Import"), NULL
, NULL
, NULL
},
162 { "EditMenu" , NULL
, N_("_Edit"), NULL
, NULL
, NULL
},
163 { "ViewMenu" , NULL
, N_("_View"), NULL
, NULL
, NULL
},
164 { "ManageMenu" , NULL
, N_("_Manage"), NULL
, NULL
, NULL
},
165 { "TxnMenu" , NULL
, N_("_Transactions"), NULL
, NULL
, NULL
},
166 { "ReportMenu" , NULL
, N_("_Reports"), NULL
, NULL
, NULL
},
167 { "ToolsMenu" , NULL
, N_("_Tools"), NULL
, NULL
, NULL
},
168 { "HelpMenu" , NULL
, N_("_Help"), NULL
, NULL
, NULL
},
170 // { "Import" , NULL, N_("Import") },
171 // { "Export" , NULL, N_("Export to") },
172 /* name, icon-name, label, accelerator, tooltip */
175 { "New" , ICONNAME_NEW
, N_("_New") , "<control>N", N_("Create a new file"), G_CALLBACK (ui_mainwindow_action_new
) },
176 { "Open" , ICONNAME_OPEN
, N_("_Open...") , "<control>O", N_("Open a file"), G_CALLBACK (ui_mainwindow_action_open
) },
177 { "Save" , ICONNAME_SAVE
, N_("_Save") , "<control>S", N_("Save the current file"), G_CALLBACK (ui_mainwindow_action_save
) },
178 { "SaveAs" , ICONNAME_SAVE_AS
, N_("Save _As...") , "<shift><control>S", N_("Save the current file with a different name"), G_CALLBACK (ui_mainwindow_action_saveas
) },
179 { "Revert" , ICONNAME_REVERT
, N_("Revert") , NULL
, N_("Revert to a saved version of this file"), G_CALLBACK (ui_mainwindow_action_revert
) },
181 { "Properties" , ICONNAME_PROPERTIES
, N_("Properties..."), NULL
, N_("Configure the file"), G_CALLBACK (ui_mainwindow_action_properties
) },
182 { "Close" , ICONNAME_CLOSE
, N_("_Close") , "<control>W", N_("Close the current file"), G_CALLBACK (ui_mainwindow_action_close
) },
183 { "Quit" , ICONNAME_QUIT
, N_("_Quit") , "<control>Q", N_("Quit HomeBank"), G_CALLBACK (ui_mainwindow_action_quit
) },
186 { "ImportQIF" , ICONNAME_HB_FILE_IMPORT
, N_("QIF file...") , NULL
, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import
) },
187 { "ImportOFX" , ICONNAME_HB_FILE_IMPORT
, N_("OFX/QFX file...") , NULL
, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import
) },
188 { "ImportCSV" , ICONNAME_HB_FILE_IMPORT
, N_("CSV file...") , NULL
, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import
) },
190 { "ExportQIF" , ICONNAME_HB_FILE_EXPORT
, N_("Export QIF file...") , NULL
, N_("Export all account in a QIF file"), G_CALLBACK (ui_mainwindow_action_export
) },
193 { "Preferences", ICONNAME_PREFERENCES
, N_("Preferences..."), NULL
, N_("Configure HomeBank"), G_CALLBACK (ui_mainwindow_action_preferences
) },
196 { "Currency" , ICONNAME_HB_CURRENCY
, N_("Currencies...") , NULL
, N_("Configure the currencies"), G_CALLBACK (ui_mainwindow_action_defcurrency
) },
197 { "Account" , ICONNAME_HB_ACCOUNT
, N_("Acc_ounts...") , NULL
, N_("Configure the accounts"), G_CALLBACK (ui_mainwindow_action_defaccount
) },
198 { "Payee" , ICONNAME_HB_PAYEE
, N_("_Payees...") , NULL
, N_("Configure the payees"), G_CALLBACK (ui_mainwindow_action_defpayee
) },
199 { "Category" , ICONNAME_HB_CATEGORY
, N_("Categories...") , NULL
, N_("Configure the categories"), G_CALLBACK (ui_mainwindow_action_defcategory
) },
200 { "Archive" , ICONNAME_HB_ARCHIVE
, N_("Scheduled/Template...") , NULL
, N_("Configure the scheduled/template transactions"), G_CALLBACK (ui_mainwindow_action_defarchive
) },
201 { "Budget" , ICONNAME_HB_BUDGET
, N_("Budget...") , NULL
, N_("Configure the budget"), G_CALLBACK (ui_mainwindow_action_defbudget
) },
202 { "Assign" , ICONNAME_HB_ASSIGN
, N_("Assignments..."), NULL
, N_("Configure the automatic assignments"), G_CALLBACK (ui_mainwindow_action_defassign
) },
205 { "ShowOpe" , ICONNAME_HB_OPE_SHOW
, N_("Show...") , NULL
, N_("Shows selected account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions
) },
206 { "AddOpe" , ICONNAME_HB_OPE_ADD
, N_("Add...") , NULL
, N_("Add transactions"), G_CALLBACK (ui_mainwindow_action_addtransactions
) },
207 { "Scheduler" , NULL
, N_("Set scheduler...") , NULL
, N_("Configure the transaction scheduler"), G_CALLBACK (ui_mainwindow_action_properties
) },
208 { "AddScheduled", NULL
, N_("Post scheduled"), NULL
, N_("Post pending scheduled transactions"), G_CALLBACK (ui_mainwindow_action_checkscheduled
) },
211 { "RStatistics" , ICONNAME_HB_REP_STATS
, N_("_Statistics...") , NULL
, N_("Open the Statistics report"), G_CALLBACK (ui_mainwindow_action_statistic
) },
212 { "RTrendTime" , ICONNAME_HB_REP_TIME
, N_("_Trend Time...") , NULL
, N_("Open the Trend Time report"), G_CALLBACK (ui_mainwindow_action_trendtime
) },
213 { "RBudget" , ICONNAME_HB_REP_BUDGET
, N_("B_udget...") , NULL
, N_("Open the Budget report"), G_CALLBACK (ui_mainwindow_action_budget
) },
214 { "RBalance" , ICONNAME_HB_REP_BALANCE
, N_("Balance...") , NULL
, N_("Open the Balance report"), G_CALLBACK (ui_mainwindow_action_balance
) },
215 { "RVehiculeCost", ICONNAME_HB_REP_CAR
, N_("_Vehicle cost...") , NULL
, N_("Open the Vehicle cost report"), G_CALLBACK (ui_mainwindow_action_vehiclecost
) },
218 { "Welcome" , NULL
, N_("Show welcome dialog...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_help_welcome
) },
219 { "FileStats" , NULL
, N_("File statistics...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_file_statistics
) },
220 { "Anonymize" , NULL
, N_("Anonymize...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_anonymize
) },
223 { "Contents" , ICONNAME_HELP
, N_("_Contents") , "F1", N_("Documentation about HomeBank"), G_CALLBACK (ui_mainwindow_action_help
) },
224 { "Online" , "lpi-help" , N_("Get Help Online...") , NULL
, N_("Connect to the LaunchPad website for online help"), G_CALLBACK (ui_mainwindow_action_help_online
) },
225 { "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
) },
226 { "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
) },
228 { "About" , ICONNAME_ABOUT
, N_("_About") , NULL
, N_("About HomeBank") ,G_CALLBACK (ui_mainwindow_action_about
) },
231 static guint n_entries
= G_N_ELEMENTS (entries
);
234 static GtkToggleActionEntry toggle_entries
[] = {
235 /* name , icon-name, label, accelerator, tooltip, callback, is_active */
236 { "Toolbar" , NULL
, N_("_Toolbar") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_toolbar
), TRUE
},
237 { "Spending" , NULL
, N_("_Top spending") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_topspending
), TRUE
},
238 { "Upcoming" , NULL
, N_("_Scheduled list") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_upcoming
), TRUE
},
239 { "AsMinor" , NULL
, N_("Euro minor"), "<control>M", NULL
, G_CALLBACK (ui_mainwindow_action_toggle_minor
), FALSE
},
242 static guint n_toggle_entries
= G_N_ELEMENTS (toggle_entries
);
245 static const gchar
*ui_info
=
248 " <menubar name='MenuBar'>"
249 " <menu action='FileMenu'>"
250 " <menuitem action='New'/>"
251 " <menuitem action='Open'/>"
253 " <menuitem action='Save'/>"
254 " <menuitem action='SaveAs'/>"
255 " <menuitem action='Revert'/>"
257 " <menuitem action='Properties'/>"
259 " <menu action='ImportMenu'>"
260 " <menuitem action='ImportQIF'/>"
261 " <menuitem action='ImportOFX'/>"
262 " <menuitem action='ImportCSV'/>"
264 " <menuitem action='ExportQIF'/>"
266 // print to come here
268 " <menuitem action='Close'/>"
269 " <menuitem action='Quit'/>"
271 " <menu action='EditMenu'>"
272 " <menuitem action='Preferences'/>"
274 " <menu action='ViewMenu'>"
275 " <menuitem action='Toolbar'/>"
277 " <menuitem action='Spending'/>"
278 " <menuitem action='Upcoming'/>"
280 " <menuitem action='AsMinor'/>"
282 " <menu action='ManageMenu'>"
283 " <menuitem action='Account'/>"
284 " <menuitem action='Payee'/>"
285 " <menuitem action='Category'/>"
286 " <menuitem action='Archive'/>"
287 " <menuitem action='Budget'/>"
288 " <menuitem action='Assign'/>"
289 " <menuitem action='Currency'/>"
291 " <menu action='TxnMenu'>"
292 " <menuitem action='ShowOpe'/>"
293 " <menuitem action='AddOpe'/>"
295 " <menuitem action='Scheduler'/>"
296 " <menuitem action='AddScheduled'/>"
298 " <menu action='ReportMenu'>"
299 " <menuitem action='RStatistics'/>"
300 " <menuitem action='RTrendTime'/>"
301 " <menuitem action='RBalance'/>"
302 " <menuitem action='RBudget'/>"
303 " <menuitem action='RVehiculeCost'/>"
305 " <menu action='ToolsMenu'>"
306 " <menuitem action='Welcome'/>"
307 " <menuitem action='FileStats'/>"
309 " <menuitem action='Anonymize'/>"
311 " <menu action='HelpMenu'>"
312 " <menuitem action='Contents'/>"
314 " <menuitem action='Online'/>"
315 " <menuitem action='Translate'/>"
316 " <menuitem action='Problem'/>"
318 " <menuitem action='About'/>"
322 " <toolbar name='ToolBar'>"
323 " <toolitem action='New'/>"
324 // here Open + recent is coded
325 " <toolitem action='Save'/>"
327 " <toolitem action='Account'/>"
328 " <toolitem action='Payee'/>"
329 " <toolitem action='Category'/>"
330 " <toolitem action='Archive'/>"
331 " <toolitem action='Budget'/>"
332 " <toolitem action='Assign'/>"
333 " <toolitem action='Currency'/>"
335 " <toolitem action='ShowOpe'/>"
336 " <toolitem action='AddOpe'/>"
338 " <toolitem action='RStatistics'/>"
339 " <toolitem action='RTrendTime'/>"
340 " <toolitem action='RBalance'/>"
341 " <toolitem action='RBudget'/>"
342 " <toolitem action='RVehiculeCost'/>"
355 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
)
357 //struct hbfile_data *data;
363 DB( g_print("\n[ui-mainwindow] revert\n") );
365 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
367 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
368 title
= g_strdup_printf (
369 _("Revert unsaved changes to file '%s'?"), basename
);
372 _("- Changes made to the file will be permanently lost\n"
373 "- File will be reloaded from the last save (.xhb~)");
375 result
= ui_dialog_msg_confirm_alert(
376 GTK_WINDOW(GLOBALS
->mainwindow
),
385 if( result
== GTK_RESPONSE_OK
)
387 DB( g_print(" - should revert\n") );
389 hbfile_change_filepath(hb_util_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb~"));
390 ui_mainwindow_open_internal(widget
, NULL
);
391 hbfile_change_filepath(hb_util_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb"));
398 activate_url (GtkAboutDialog
*about
,
402 DB( g_print("activate url %s\n", link
) );
404 homebank_util_url_show (link
);
407 static void hbfile_about(void)
414 static const gchar
*artists
[] = {
419 static const gchar
*authors
[] = {
420 "Lead developer:\n" \
423 "Ga\xc3\xabtan LORIDANT (Maths formulas for charts)\n",
428 const gchar *documenters[] = {
434 static const gchar
*copyright
= "Copyright \xc2\xa9 1995-2017 - Maxime DOYEN";
438 version
= g_strdup_printf (PACKAGE_VERSION
"\n<small>Running against GTK+ %d.%d.%d</small>",
439 gtk_get_major_version (),
440 gtk_get_minor_version (),
441 gtk_get_micro_version ());
443 dialog
= gtk_about_dialog_new();
445 gtk_window_set_transient_for (GTK_WINDOW(dialog
), GTK_WINDOW(GLOBALS
->mainwindow
));
446 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
448 gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog
), g_get_application_name ());
449 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog
), version
);
450 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog
), copyright
);
451 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog
), _("Free, easy, personal accounting for everyone"));
452 gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG(dialog
), GTK_LICENSE_GPL_2_0
);
454 //gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(dialog), );
455 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog
), "http://homebank.free.fr");
456 gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(dialog
), "Visit the HomeBank website");
458 gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(dialog
), "homebank");
460 pathfilename
= g_build_filename(homebank_app_get_images_dir(), "splash.png", NULL
);
461 pixbuf
= gdk_pixbuf_new_from_file(pathfilename
, NULL
);
462 g_free(pathfilename
);
466 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog
), pixbuf
);
467 g_object_unref (pixbuf
);
470 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog
), authors
);
471 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog
), artists
);
472 //gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(dialog), );
473 //gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog), );
475 g_signal_connect (dialog
, "activate-link", G_CALLBACK (activate_url
), NULL
);
477 gtk_dialog_run (GTK_DIALOG (dialog
));
479 gtk_widget_destroy (dialog
);
486 /* hbfile action functions -------------------- */
487 static void ui_mainwindow_action_new(void)
489 GtkWidget
*widget
= GLOBALS
->mainwindow
;
491 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
493 //clear all, and init GLOBALS->xhb_filepath to default
494 ui_mainwindow_clear(widget
, GINT_TO_POINTER(TRUE
)); // GPOINTER_TO_INT(
495 ui_mainwindow_update(widget
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
497 ui_start_assistant();
498 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
499 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
500 ui_mainwindow_populate_topspending(GLOBALS
->mainwindow
, NULL
);
504 static void ui_mainwindow_action_open(void)
506 ui_mainwindow_open(GLOBALS
->mainwindow
, NULL
);
509 static void ui_mainwindow_action_save(void)
511 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
514 static void ui_mainwindow_action_saveas(void)
516 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
519 static void ui_mainwindow_action_revert(void)
521 ui_mainwindow_revert(GLOBALS
->mainwindow
, NULL
);
524 static void ui_mainwindow_action_close(void)
526 GtkWidget
*widget
= GLOBALS
->mainwindow
;
528 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
530 //clear all, and init GLOBALS->xhb_filepath to default
531 ui_mainwindow_clear(widget
, GINT_TO_POINTER(TRUE
));
532 ui_mainwindow_update(widget
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
538 static void ui_mainwindow_action_quit(void)
542 //gtk_widget_destroy(GLOBALS->mainwindow);
544 g_signal_emit_by_name(GLOBALS
->mainwindow
, "delete-event", NULL
, &result
);
549 static void ui_mainwindow_action_file_statistics(void)
551 ui_dialog_file_statistics();
555 static void ui_mainwindow_action_properties(void)
557 create_defhbfile_dialog();
558 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
561 static void ui_mainwindow_action_anonymize(void)
567 title
= _("Are you sure you want to anonymize the file?");
570 _("Proceeding will anonymize any text, \n"
571 "like 'account x', 'payee y', 'memo z', ...");
573 result
= ui_dialog_msg_confirm_alert(
574 GTK_WINDOW(GLOBALS
->mainwindow
),
580 if( result
== GTK_RESPONSE_CANCEL
)
584 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
588 static void ui_mainwindow_action_defcurrency(void)
590 ui_cur_manage_dialog();
591 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
595 static void ui_mainwindow_action_defaccount(void)
597 ui_acc_manage_dialog();
599 //our global list has changed, so update the treeview
600 //todo: optimize this, should not call compute balance here
601 account_compute_balances ();
602 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
604 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
));
607 static void ui_mainwindow_action_defpayee(void)
609 ui_pay_manage_dialog();
610 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
613 static void ui_mainwindow_action_defcategory(void)
615 ui_cat_manage_dialog();
616 //todo:why refresh upcoming here??
617 //ui_mainwindow_populate_upcoming(GLOBALS->mainwindow, NULL);
618 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
622 static void ui_mainwindow_defarchive(Archive
*arc
)
624 struct hbfile_data
*data
;
627 data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
629 // upcoming list have direct pointer to the arc (which may have changed)
630 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
));
631 gtk_list_store_clear (GTK_LIST_STORE(model
));
633 ui_arc_manage_dialog(arc
);
635 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
637 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
641 static void ui_mainwindow_action_defarchive(void)
643 ui_mainwindow_defarchive(NULL
);
647 static void ui_mainwindow_action_defbudget(void)
649 ui_bud_manage_dialog();
650 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
654 static void ui_mainwindow_action_defassign(void)
657 ui_asg_manage_dialog();
659 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
663 static void ui_mainwindow_action_preferences(void)
665 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
667 defpref_dialog_new();
668 if(!PREFS
->euro_active
)
670 GtkToggleAction
*action
= (GtkToggleAction
*)gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor");
672 gtk_toggle_action_set_active(action
, FALSE
);
673 ui_mainwindow_action_toggle_minor(action
);
675 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
+UF_REFRESHALL
));
680 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction
*action
)
682 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
684 PREFS
->wal_toolbar
= gtk_toggle_action_get_active(action
);
685 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
688 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction
*action
)
690 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
692 PREFS
->wal_upcoming
= gtk_toggle_action_get_active(action
);
693 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
696 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction
*action
)
698 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
700 PREFS
->wal_spending
= gtk_toggle_action_get_active(action
);
701 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
704 static void ui_mainwindow_action_toggle_minor(GtkToggleAction
*action
)
706 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
708 GLOBALS
->minor
= gtk_toggle_action_get_active(action
);
710 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
711 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
714 gtk_chart_show_minor(GTK_CHART(data
->RE_pie
), GLOBALS
->minor
);
716 ui_panel_topspending_update(data
->window
, data
);
720 static void ui_mainwindow_action_showtransactions(void)
722 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
728 if( data
->acc
->window
== NULL
)
730 window
= register_panel_window_new(data
->acc
->key
, data
->acc
);
731 register_panel_window_init(window
, NULL
);
735 if(GTK_IS_WINDOW(data
->acc
->window
))
736 gtk_window_present(data
->acc
->window
);
743 static void ui_mainwindow_action_addtransactions(void)
745 ui_mainwindow_addtransactions(GLOBALS
->mainwindow
, NULL
);
748 static void ui_mainwindow_action_checkscheduled(void)
750 ui_mainwindow_scheduled_postall(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
753 static void ui_mainwindow_action_statistic(void)
755 ui_repdist_window_new();
758 static void ui_mainwindow_action_trendtime(void)
760 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
762 ui_reptime_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
765 static void ui_mainwindow_action_budget(void)
767 repbudget_window_new();
770 static void ui_mainwindow_action_balance(void)
772 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
774 repbalance_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
777 static void ui_mainwindow_action_vehiclecost(void)
779 repcost_window_new();
782 static void ui_mainwindow_action_import(GtkAction
*action
)
785 gint filetype
= FILETYPE_UNKNOW
;
787 name
= gtk_action_get_name(action
);
789 if( g_str_has_suffix (name
, "QIF"))
790 filetype
= FILETYPE_QIF
;
792 if( g_str_has_suffix (name
, "OFX"))
793 filetype
= FILETYPE_OFX
;
795 if( g_str_has_suffix (name
, "CSV"))
796 filetype
= FILETYPE_CSV_HB
;
798 DB( g_print("action %s type=%d\n", name
, filetype
) );
800 ui_import_assistant_new(filetype
);
805 static void ui_mainwindow_action_about(void)
812 static void ui_mainwindow_action_export(void)
816 if( ui_file_chooser_qif(NULL
, &filename
) == TRUE
)
818 hb_export_qif_account_all(filename
);
823 static void ui_mainwindow_action_help(void)
827 link
= g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP
, NULL
);
828 homebank_util_url_show (link
);
834 //todo: move this to a ui-assist-welcome.c
836 static void ui_mainwindow_action_help_welcome1 (GtkButton
*button
, gpointer user_data
)
838 gtk_dialog_response (GTK_DIALOG(user_data
), 1);
841 static void ui_mainwindow_action_help_welcome2 (GtkButton
*button
, gpointer user_data
)
843 gtk_dialog_response (GTK_DIALOG(user_data
), 2);
846 static void ui_mainwindow_action_help_welcome3 (GtkButton
*button
, gpointer user_data
)
848 gtk_dialog_response (GTK_DIALOG(user_data
), 3);
851 static void ui_mainwindow_action_help_welcome4 (GtkButton
*button
, gpointer user_data
)
853 gtk_dialog_response (GTK_DIALOG(user_data
), 4);
856 static void ui_mainwindow_action_help_welcome5 (GtkButton
*button
, gpointer user_data
)
858 gtk_dialog_response (GTK_DIALOG(user_data
), 5);
861 void ui_mainwindow_action_help_welcome(void)
863 GtkWidget
*dialog
, *content_area
;
864 GtkWidget
*mainvbox
, *widget
, *label
;
866 dialog
= gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
867 GTK_WINDOW(GLOBALS
->mainwindow
),
873 content_area
= gtk_dialog_get_content_area(GTK_DIALOG (dialog
));
875 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
876 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, FALSE
, FALSE
, 0);
877 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
879 label
= make_label (_("HomeBank"), 0, 0);
880 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
881 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
883 label
= make_label (_("Free, easy, personal accounting for everyone"), 0, 0);
884 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
886 widget
= gtk_separator_new(GTK_ORIENTATION_HORIZONTAL
);
887 gtk_box_pack_start (GTK_BOX (content_area
), widget
, FALSE
, FALSE
, 0);
889 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, SPACING_MEDIUM
);
890 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, TRUE
, TRUE
, 0);
891 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
893 label
= make_label (_("What do you want to do:"), 0, 0);
894 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
895 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
897 widget
= gtk_button_new_with_mnemonic(_("Read HomeBank _Manual"));
898 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
899 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome1
), dialog
);
901 widget
= gtk_button_new_with_mnemonic(_("Configure _preferences"));
902 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
903 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome2
), dialog
);
905 widget
= gtk_button_new_with_mnemonic(_("Create a _new file"));
906 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
907 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome3
), dialog
);
909 widget
= gtk_button_new_with_mnemonic(_("_Open an existing file"));
910 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
911 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome4
), dialog
);
913 widget
= gtk_button_new_with_mnemonic(_("Open the _example file"));
914 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
915 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome5
), dialog
);
917 //connect all our signals
918 g_signal_connect (dialog
, "destroy", G_CALLBACK (gtk_widget_destroyed
), &dialog
);
920 gtk_widget_show_all (dialog
);
923 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
925 // cleanup and destroy
926 gtk_widget_destroy (dialog
);
928 // do appropriate action
932 ui_mainwindow_action_help();
935 ui_mainwindow_action_preferences();
938 ui_mainwindow_action_new();
941 ui_mainwindow_action_open();
944 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL
));
945 ui_mainwindow_open_internal(GLOBALS
->mainwindow
, NULL
);
953 static void ui_mainwindow_action_help_online(void)
955 const gchar
*link
= HOMEBANK_URL_HELP_ONLINE
;
957 homebank_util_url_show (link
);
961 static void ui_mainwindow_action_help_translate(void)
963 const gchar
*link
= HOMEBANK_URL_HELP_TRANSLATE
;
965 homebank_util_url_show (link
);
969 static void ui_mainwindow_action_help_problem(void)
971 const gchar
*link
= HOMEBANK_URL_HELP_PROBLEM
;
973 homebank_util_url_show (link
);
980 /* hbfile functions -------------------- */
988 static void ui_mainwindow_selection(GtkTreeSelection
*treeselection
, gpointer user_data
)
990 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
994 static void ui_mainwindow_close_openbooks(void)
998 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
1000 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1003 Account
*item
= elt
->data
;
1007 gtk_widget_destroy(GTK_WIDGET(item
->window
));
1008 item
->window
= NULL
;
1011 elt
= g_list_next(elt
);
1022 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
)
1024 struct hbfile_data
*data
;
1025 gboolean file_clear
= GPOINTER_TO_INT(user_data
);
1027 DB( g_print("\n[ui-mainwindow] clear\n") );
1029 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1031 // Close opened account window
1033 ui_mainwindow_close_openbooks();
1034 gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_acc
))));
1035 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
))));
1036 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_top
))));
1038 data
->showall
= FALSE
;
1040 hbfile_cleanup(file_clear
);
1041 hbfile_setup(file_clear
);
1047 ** add some transactions directly
1049 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
)
1051 struct hbfile_data
*data
;
1055 gint account
, count
;
1057 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1059 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1061 /* init the transaction */
1062 date
= homebank_app_date_get_julian();
1066 if(data
->acc
!= NULL
)
1067 account
= data
->acc
->key
;
1069 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
, FALSE
);
1071 while(result
== GTK_RESPONSE_ADD
|| result
== GTK_RESPONSE_ADDKEEP
)
1075 /* fill in the transaction */
1076 if( result
== GTK_RESPONSE_ADD
)
1078 ope
= da_transaction_malloc();
1080 ope
->kacc
= account
;
1082 if( PREFS
->heritdate
== FALSE
) //fix: 318733
1083 ope
->date
= GLOBALS
->today
;
1086 // normally we can't be in addkeep without initialized ope with add
1088 deftransaction_set_transaction(window
, ope
);
1090 result
= gtk_dialog_run (GTK_DIALOG (window
));
1092 DB( g_print(" - dialog result is %d\n", result
) );
1094 if(result
== GTK_RESPONSE_ADD
|| result
== GTK_RESPONSE_ADDKEEP
|| result
== GTK_RESPONSE_ACCEPT
)
1096 deftransaction_get(window
, NULL
);
1097 transaction_add(ope
, NULL
, ope
->kacc
);
1099 DB( g_print(" - added 1 transaction to %d\n", ope
->kacc
) );
1101 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
1104 //todo: still usefull ? store last date
1108 if( result
== GTK_RESPONSE_ADD
)
1110 da_transaction_free(ope
);
1117 deftransaction_dispose(window
, NULL
);
1118 gtk_widget_destroy (window
);
1120 /* todo optimize this */
1123 GLOBALS
->changes_count
+= count
;
1124 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
1135 #define MAX_TOPSPENDING 5
1138 static gint
tmptop_compare_func(struct tmptop
*tt1
, struct tmptop
*tt2
)
1140 return tt1
->value
> tt2
->value
? 1 : -1;
1144 static void ui_panel_topspending_update(GtkWidget
*widget
, gpointer user_data
)
1146 struct hbfile_data
*data
;
1147 GtkTreeModel
*model
;
1149 gchar strbuffer
[G_ASCII_DTOSTR_BUF_SIZE
];
1151 DB( g_print("\n[ui-mainwindow] topspending_update\n") );
1153 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1155 hb_strfmon(strbuffer
, G_ASCII_DTOSTR_BUF_SIZE
-1, data
->toptotal
, GLOBALS
->kcur
, GLOBALS
->minor
);
1156 //hb_label_set_amount(GTK_LABEL(data->TX_topamount), total, GLOBALS->kcur, GLOBALS->minor);
1157 title
= g_strdup_printf("%s %s", _("Top spending"), strbuffer
);
1159 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_top
));
1161 gtk_chart_set_color_scheme(GTK_CHART(data
->RE_pie
), PREFS
->report_color_scheme
);
1162 gtk_chart_set_currency(GTK_CHART(data
->RE_pie
), GLOBALS
->kcur
);
1163 gtk_chart_set_datas(GTK_CHART(data
->RE_pie
), model
, LST_TOPSPEND_AMOUNT
, title
, NULL
);
1168 gchar
*fu
= _("Top %d spending"); title
= fu
;
1172 static void ui_mainwindow_populate_topspending(GtkWidget
*widget
, gpointer user_data
)
1174 struct hbfile_data
*data
;
1175 GtkTreeModel
*model
;
1179 guint n_result
, i
, n_items
;
1181 gdouble total
, other
;
1185 DB( g_print("\n[ui-mainwindow] populate_topspending\n") );
1187 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1189 type
= radio_get_active(GTK_CONTAINER(data
->RA_type
));
1190 range
= gtk_combo_box_get_active(GTK_COMBO_BOX(data
->CY_range
));
1192 DB( g_print(" - type=%d, range=%d\n", type
, range
) );
1193 DB( g_print(" - pref range=%d\n", PREFS
->date_range_wal
) );
1195 if(range
== FLT_RANGE_OTHER
)
1198 filter_preset_daterange_set(data
->filter
, range
, 0);
1201 n_result
= da_cat_get_max_key() + 1;
1204 DB( g_print(" - max key is %d\n", n_result
) );
1206 /* allocate some memory */
1207 garray
= g_array_sized_new(FALSE
, FALSE
, sizeof(struct tmptop
), n_result
);
1211 struct tmptop zero
= { .key
=0, .value
=0.0 };
1214 //DB( g_print(" - array length=%d\n", garray->len) );
1216 for(i
=0 ; i
<n_result
; i
++)
1218 g_array_append_vals(garray
, &zero
, 1);
1219 //g_array_insert_vals(garray, i, &zero, 1);
1221 //struct tmptop *tt = &g_array_index (garray, struct tmptop, i);
1222 //DB( g_print("%4d, %4d %f\n", i, tt->key, tt->value) );
1225 //DB( g_print("\n - end array length=%d\n", garray->len) );
1227 //todo: not ideal, has ot force to get_acc for each txn below
1228 txn_queue
= hbfile_transaction_get_partial(data
->filter
->mindate
, data
->filter
->maxdate
);
1230 /* compute the results */
1231 list
= g_queue_peek_head_link(txn_queue
);
1232 while (list
!= NULL
)
1234 Transaction
*ope
= list
->data
;
1236 //DB( g_print(" - eval txn: '%s', cat=%d ==> flt-test=%d\n", ope->wording, ope->kcat, filter_test(data->filter, ope)) );
1238 if( !(ope
->paymode
== PAYMODE_INTXFER
) )
1243 //todo: optimize here
1244 trn_amount
= ope
->amount
;
1245 acc
= da_acc_get(ope
->kacc
);
1247 trn_amount
= hb_amount_base(ope
->amount
, acc
->kcur
);
1249 if( ope
->flags
& OF_SPLIT
)
1251 guint nbsplit
= da_splits_count(ope
->splits
);
1253 struct tmptop
*item
;
1255 for(i
=0;i
<nbsplit
;i
++)
1257 split
= ope
->splits
[i
];
1258 pos
= category_report_id(split
->kcat
, type
);
1260 trn_amount
= hb_amount_base(split
->amount
, acc
->kcur
);
1261 //trn_amount = split->amount;
1262 //#1297054 if( trn_amount < 0 ) {
1263 item
= &g_array_index (garray
, struct tmptop
, pos
);
1265 item
->value
+= trn_amount
;
1266 //DB( g_print(" - stored %.2f to item %d\n", trn_amount, pos) );
1272 struct tmptop
*item
;
1274 pos
= category_report_id(ope
->kcat
, type
);
1276 //#1297054 if( trn_amount < 0 ) {
1277 item
= &g_array_index (garray
, struct tmptop
, pos
);
1279 item
->value
+= trn_amount
;
1280 //DB( g_print(" - stored %.2f to item %d\n", trn_amount, pos) );
1287 list
= g_list_next(list
);
1290 g_queue_free (txn_queue
);
1292 // we need to sort this and limit before
1293 g_array_sort(garray
, (GCompareFunc
)tmptop_compare_func
);
1295 n_items
= MIN(garray
->len
,MAX_TOPSPENDING
);
1297 for(i
=0 ; i
<garray
->len
; i
++)
1299 struct tmptop
*item
;
1301 item
= &g_array_index (garray
, struct tmptop
, i
);
1304 total
+= item
->value
;
1307 other
+= item
->value
;
1309 DB( g_print(" - %d : k='%d' v='%f' t='%f'\n", i
, item
->key
, item
->value
, total
) );
1314 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_top
));
1315 gtk_list_store_clear (GTK_LIST_STORE(model
));
1316 g_object_ref(model
); /* Make sure the model stays with us after the tree view unrefs it */
1317 gtk_tree_view_set_model(GTK_TREE_VIEW(data
->LV_top
), NULL
); /* Detach model from view */
1319 /* insert into the treeview */
1320 for(i
=0 ; i
<MIN(garray
->len
,MAX_TOPSPENDING
) ; i
++)
1324 struct tmptop
*item
;
1327 item
= &g_array_index (garray
, struct tmptop
, i
);
1329 if(!item
->value
) continue;
1331 value
= hb_amount_round(item
->value
, 2);
1332 entry
= da_cat_get(item
->key
);
1333 if(entry
== NULL
) continue;
1335 name
= entry
->key
== 0 ? _("(no category)") : da_cat_get_fullname(entry
);
1338 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1339 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1341 LST_TOPSPEND_KEY
, 0,
1342 LST_TOPSPEND_NAME
, name
,
1343 LST_TOPSPEND_AMOUNT
, value
,
1344 //LST_TOPSPEND_RATE, (gint)(((ABS(value)*100)/ABS(total)) + 0.5),
1352 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1353 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1354 LST_TOPSPEND_ID
, n_items
,
1355 LST_TOPSPEND_KEY
, 0,
1356 LST_TOPSPEND_NAME
, _("Other"),
1357 LST_TOPSPEND_AMOUNT
, other
,
1358 //LST_TOPSPEND_RATE, (gint)(((ABS(other)*100)/ABS(total)) + 0.5),
1362 /* Re-attach model to view */
1363 gtk_tree_view_set_model(GTK_TREE_VIEW(data
->LV_top
), model
);
1364 g_object_unref(model
);
1367 // update chart and widgets
1371 data
->toptotal
= total
;
1372 ui_panel_topspending_update(widget
, data
);
1374 daterange
= filter_daterange_text_get(data
->filter
);
1375 gtk_widget_set_tooltip_markup(GTK_WIDGET(data
->CY_range
), daterange
);
1380 /* free our memory */
1381 g_array_free (garray
, TRUE
);
1386 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1388 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1390 ui_mainwindow_scheduled_get_selected_item(GtkTreeView
*treeview
)
1392 GtkTreeSelection
*treeselection
;
1393 GtkTreeModel
*model
;
1396 treeselection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
1397 if( gtk_tree_selection_get_selected(treeselection
, &model
, &iter
) )
1401 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPUPC_DATAS
, &arc
, -1);
1409 static void ui_mainwindow_scheduled_onRowActivated (GtkTreeView
*treeview
,
1411 GtkTreeViewColumn
*col
,
1414 //struct hbfile_data *data;
1417 DB( g_print ("\n[ui-mainwindow] A scheduled row has been double-clicked!\n") );
1419 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(treeview, GTK_TYPE_WINDOW)), "inst_data");
1421 arc
= ui_mainwindow_scheduled_get_selected_item(treeview
);
1422 ui_mainwindow_defarchive(arc
);
1426 static void ui_mainwindow_scheduled_do_post(Archive
*arc
, gboolean doedit
, gpointer user_data
)
1428 struct hbfile_data
*data
= user_data
;
1433 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
, TRUE
);
1435 /* fill in the transaction */
1436 txn
= da_transaction_malloc();
1437 da_transaction_init_from_template(txn
, arc
);
1438 txn
->date
= scheduled_get_postdate(arc
, arc
->nextdate
);
1440 deftransaction_set_transaction(window
, txn
);
1442 result
= gtk_dialog_run (GTK_DIALOG (window
));
1444 DB( g_print(" - dialog result is %d\n", result
) );
1446 if(result
== GTK_RESPONSE_ADD
|| result
== GTK_RESPONSE_ACCEPT
)
1448 deftransaction_get(window
, NULL
);
1449 transaction_add(txn
, NULL
, txn
->kacc
);
1450 GLOBALS
->changes_count
++;
1452 scheduled_date_advance(arc
);
1454 DB( g_print(" - added 1 transaction to %d\n", txn
->kacc
) );
1457 da_transaction_free(txn
);
1459 deftransaction_dispose(window
, NULL
);
1460 gtk_widget_destroy (window
);
1465 static void ui_mainwindow_scheduled_editpost_cb(GtkWidget
*widget
, gpointer user_data
)
1467 struct hbfile_data
*data
= user_data
;
1469 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1473 ui_mainwindow_scheduled_do_post(arc
, TRUE
, data
);
1474 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_SENSITIVE
|UF_REFRESHALL
));
1479 static void ui_mainwindow_scheduled_post_cb(GtkWidget
*widget
, gpointer user_data
)
1481 struct hbfile_data
*data
= user_data
;
1483 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1487 if( scheduled_is_postable(arc
) )
1489 Transaction
*txn
= da_transaction_malloc ();
1491 da_transaction_init_from_template(txn
, arc
);
1492 txn
->date
= scheduled_get_postdate(arc
, arc
->nextdate
);
1493 transaction_add(txn
, NULL
, 0);
1495 GLOBALS
->changes_count
++;
1496 scheduled_date_advance(arc
);
1498 da_transaction_free (txn
);
1502 ui_mainwindow_scheduled_do_post(arc
, FALSE
, data
);
1505 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_SENSITIVE
|UF_REFRESHALL
));
1510 static void ui_mainwindow_scheduled_skip_cb(GtkWidget
*widget
, gpointer user_data
)
1512 struct hbfile_data
*data
= user_data
;
1514 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1515 if( (arc
!= NULL
) && (arc
->flags
& OF_AUTO
) )
1517 GLOBALS
->changes_count
++;
1518 scheduled_date_advance(arc
);
1520 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1521 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_SENSITIVE
));
1527 static void ui_mainwindow_scheduled_update(GtkWidget
*widget
, gpointer user_data
)
1529 struct hbfile_data
*data
;
1532 DB( g_print("\n[ui-mainwindow] scheduled update\n") );
1534 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1536 //filter = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_sched_filter));
1538 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1542 DB( g_print("archive is %s\n", arc
->wording
) );
1544 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_skip
), TRUE
);
1545 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_post
), TRUE
);
1546 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_editpost
), TRUE
);
1550 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_skip
), FALSE
);
1551 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_post
), FALSE
);
1552 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_editpost
), FALSE
);
1559 static void ui_mainwindow_scheduled_selection_cb(GtkTreeSelection
*treeselection
, gpointer user_data
)
1563 ui_mainwindow_scheduled_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
1569 ** called after load, importamiga, on demand
1571 void ui_mainwindow_scheduled_postall(GtkWidget
*widget
, gpointer user_data
)
1573 //struct hbfile_data *data;
1575 gint usermode
= GPOINTER_TO_INT(user_data
);
1577 DB( g_print("\n[ui-mainwindow] check scheduled\n") );
1579 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1581 count
= scheduled_post_all_pending();
1584 if(usermode
== TRUE
)
1591 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_REFRESHALL
));
1595 txt
= _("No transaction to add");
1597 txt
= _("transaction added: %d");
1599 ui_dialog_msg_infoerror(GTK_WINDOW(GLOBALS
->mainwindow
), GTK_MESSAGE_INFO
,
1600 _("Check scheduled transactions result"),
1608 static void ui_mainwindow_scheduled_populate(GtkWidget
*widget
, gpointer user_data
)
1610 struct hbfile_data
*data
;
1611 GtkTreeModel
*model
;
1618 guint32 maxpostdate
;
1622 DB( g_print("\n[ui-mainwindow] scheduled populate list\n") );
1624 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1626 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
));
1627 gtk_list_store_clear (GTK_LIST_STORE(model
));
1629 homebank_app_date_get_julian();
1631 maxpostdate
= scheduled_date_get_post_max();
1633 date
= g_date_new_julian (maxpostdate
);
1634 g_date_strftime (buffer
, 256-1, PREFS
->date_format
, date
);
1637 gtk_label_set_text(GTK_LABEL(data
->LB_maxpostdate
), buffer
);
1640 list
= g_list_first(GLOBALS
->arc_list
);
1641 while (list
!= NULL
)
1643 Archive
*arc
= list
->data
;
1646 guint nbdays
, nblate
;
1648 if((arc
->flags
& OF_AUTO
) ) //&& arc->kacc > 0)
1651 nbdays
= arc
->nextdate
- maxpostdate
;
1652 nblate
= scheduled_get_latepost_count(arc
, GLOBALS
->today
);
1654 DB( g_print(" - append '%s' : %d\n", arc
->wording
, nbdays
) );
1656 if(arc
->flags
& OF_INCOME
)
1667 /* insert normal txn */
1668 acc
= da_acc_get(arc
->kacc
);
1671 totinc
+= hb_amount_base(inc
, acc
->kcur
);
1672 totexp
+= hb_amount_base(exp
, acc
->kcur
);
1674 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1675 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1676 LST_DSPUPC_DATAS
, arc
,
1677 LST_DSPUPC_ACCOUNT
, acc
,
1678 LST_DSPUPC_WORDING
, arc
->wording
,
1679 LST_DSPUPC_EXPENSE
, exp
,
1680 LST_DSPUPC_INCOME
, inc
,
1681 LST_DSPUPC_REMAINING
, nbdays
,
1682 LST_DSPUPC_NB_LATE
, nblate
,
1685 /* insert internal xfer txn : 1378836 */
1686 if(arc
->paymode
== PAYMODE_INTXFER
)
1688 acc
= da_acc_get(arc
->kxferacc
);
1691 totinc
+= hb_amount_base(-inc
, acc
->kcur
);
1692 totexp
+= hb_amount_base(-exp
, acc
->kcur
);
1694 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1695 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1696 LST_DSPUPC_DATAS
, arc
,
1697 LST_DSPUPC_ACCOUNT
, acc
,
1698 LST_DSPUPC_WORDING
, arc
->wording
,
1699 LST_DSPUPC_EXPENSE
, -inc
,
1700 LST_DSPUPC_INCOME
, -exp
,
1701 LST_DSPUPC_REMAINING
, nbdays
,
1702 LST_DSPUPC_NB_LATE
, nblate
,
1707 list
= g_list_next(list
);
1713 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1714 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1715 LST_DSPUPC_DATAS
, NULL
,
1716 LST_DSPUPC_ACCOUNT
, NULL
,
1717 LST_DSPUPC_WORDING
, _("Total"),
1718 LST_DSPUPC_EXPENSE
, totexp
,
1719 LST_DSPUPC_INCOME
, totinc
,
1724 ui_mainwindow_scheduled_update(widget
, NULL
);
1734 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
)
1736 //struct hbfile_data *data;
1737 gchar
*filename
= NULL
;
1739 DB( g_print("\n[ui-mainwindow] open\n") );
1741 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1743 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
1745 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN
, &filename
) == TRUE
)
1747 hbfile_change_filepath(filename
);
1749 ui_mainwindow_open_internal(widget
, NULL
);
1757 * open the file stored in GLOBALS->xhb_filepath
1759 void ui_mainwindow_open_internal(GtkWidget
*widget
, gpointer user_data
)
1761 struct hbfile_data
*data
;
1764 DB( g_print("\n[ui-mainwindow] open internal\n") );
1766 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1768 DB( g_print(" - filename: '%s'\n", GLOBALS
->xhb_filepath
) );
1770 if( GLOBALS
->xhb_filepath
!= NULL
)
1772 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
1773 GLOBALS
->hbfile_is_new
= FALSE
;
1775 r
= homebank_load_xml(GLOBALS
->xhb_filepath
);
1778 DB( g_print(" - file loaded ok : rcode=%d\n", r
) );
1780 hbfile_file_hasbackup(GLOBALS
->xhb_filepath
);
1782 if(PREFS
->appendscheduled
)
1783 scheduled_post_all_pending();
1785 if(PREFS
->do_update_currency
)
1786 ui_cur_manage_dialog_update_currencies(GTK_WINDOW(GLOBALS
->mainwindow
));
1788 homebank_lastopenedfiles_save();
1790 //todo: delete this after computing done at xml read
1791 account_compute_balances();
1793 ui_mainwindow_recent_add(data
, GLOBALS
->xhb_filepath
);
1797 gchar
*msg
= _("Unknow error");
1802 msg
= _("I/O error for file '%s'.");
1804 case XML_FILE_ERROR
:
1805 msg
= _("The file '%s' is not a valid HomeBank file.");
1807 case XML_VERSION_ERROR
:
1808 msg
= _("The file '%s' was saved with a higher version of HomeBank\nand cannot be loaded by the current version.");
1812 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1815 GLOBALS
->xhb_filepath
1818 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
1822 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
1823 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1824 ui_mainwindow_populate_topspending(GLOBALS
->mainwindow
, NULL
);
1825 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1834 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
)
1836 struct hbfile_data
*data
;
1837 gboolean saveas
= GPOINTER_TO_INT(user_data
);
1838 gchar
*filename
= NULL
;
1841 DB( g_print("\n[ui-mainwindow] save\n") );
1843 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1845 if( GLOBALS
->hbfile_is_new
== TRUE
)
1850 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE
, &filename
) == TRUE
)
1852 DB( g_print(" + should save as '%s'\n", filename
) );
1853 homebank_file_ensure_xhb(filename
);
1854 homebank_backup_current_file();
1855 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1856 GLOBALS
->hbfile_is_new
= FALSE
;
1863 DB( g_print(" + should quick save %s\n", GLOBALS
->xhb_filepath
) );
1864 homebank_file_ensure_xhb(NULL
);
1865 homebank_backup_current_file();
1866 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1872 GLOBALS
->changes_count
= 0;
1873 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1877 gchar
*msg
= _("I/O error for file '%s'.");
1879 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1882 GLOBALS
->xhb_filepath
1891 static void ui_panel_accounts_expand_all(GtkWidget
*widget
, gpointer user_data
)
1893 struct hbfile_data
*data
;
1895 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1896 gtk_tree_view_expand_all(GTK_TREE_VIEW(data
->LV_acc
));
1900 static void ui_panel_accounts_collapse_all(GtkWidget
*widget
, gpointer user_data
)
1902 struct hbfile_data
*data
;
1904 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1905 gtk_tree_view_collapse_all(GTK_TREE_VIEW(data
->LV_acc
));
1910 static GHashTable
*ui_panel_accounts_groups_get(GList
*lacc
, gint groupby
, gboolean showall
)
1917 nballoc
= da_acc_length ();
1918 hash
= g_hash_table_new_full(g_str_hash
, g_str_equal
, (GDestroyNotify
)g_free
, NULL
);
1919 elt
= g_list_first(lacc
);
1922 Account
*acc
= elt
->data
;
1925 if( showall
|| !(acc
->flags
& (AF_CLOSED
|AF_NOSUMMARY
)) )
1927 if( groupby
== DSPACC_GROUP_BY_BANK
)
1929 groupname
= _("(no institution)");
1930 if( (acc
->bankname
!= NULL
) && strlen(acc
->bankname
) > 0 )
1931 groupname
= acc
->bankname
;
1935 //pre 5.1.3 historical by type display
1936 groupname
= _(CYA_ACC_TYPE
[acc
->type
]);
1939 if( g_hash_table_contains(hash
, groupname
) == FALSE
)
1941 g_hash_table_insert(hash
, g_strdup(groupname
), g_ptr_array_sized_new(nballoc
) );
1942 //DB( g_print(" - type hash insert '%s' = %d\n", groupname, inserted) );
1945 group
= g_hash_table_lookup(hash
, groupname
);
1948 g_ptr_array_add(group
, (gpointer
)acc
);
1949 DB( g_print(" -- add '%s' to group '%s'\n", acc
->name
, groupname
) );
1952 elt
= g_list_next(elt
);
1963 void ui_mainwindow_populate_accounts(GtkWidget
*widget
, gpointer user_data
)
1965 struct hbfile_data
*data
;
1966 GtkTreeModel
*model
;
1967 GtkTreeIter iter1
, child_iter
;
1971 gdouble gtbank
, gttoday
, gtfuture
;
1973 GHashTable
*h_group
;
1974 GHashTableIter grp_iter
;
1975 gpointer key
, value
;
1977 DB( g_print("\n[ui-mainwindow] populate accounts\n") );
1979 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1981 /* here we create a count and a list of every account pointer by type */
1982 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1984 h_group
= ui_panel_accounts_groups_get(lacc
, PREFS
->pnl_acc_show_by
, data
->showall
);
1988 gtbank
= gttoday
= gtfuture
= 0;
1990 DB( g_print(" populate listview\n") );
1992 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_acc
));
1993 gtk_tree_store_clear (GTK_TREE_STORE(model
));
1996 g_hash_table_iter_init (&grp_iter
, h_group
);
1997 while (g_hash_table_iter_next (&grp_iter
, &key
, &value
))
1999 GPtrArray
*gpa
= value
;
2000 gdouble tbank
, ttoday
, tfuture
;
2005 //1: Header: Bank, Cash, ...
2006 //DB( g_print(" - append type '%s'\n", CYA_ACC_TYPE[i]) );
2007 DB( g_print("\n - append type '%d'\n", key
) );
2009 gtk_tree_store_append (GTK_TREE_STORE(model
), &iter1
, NULL
);
2010 gtk_tree_store_set (GTK_TREE_STORE(model
), &iter1
,
2011 LST_DSPACC_DATATYPE
, DSPACC_TYPE_HEADER
,
2012 LST_DSPACC_NAME
, key
,
2015 tbank
= ttoday
= tfuture
= 0;
2017 //2: Accounts for real
2018 for(j
=0;j
<gpa
->len
;j
++)
2020 acc
= g_ptr_array_index(gpa
, j
);
2022 //tbank += acc->bal_bank;
2023 //ttoday += acc->bal_today;
2024 //tfuture += acc->bal_future;
2025 tbank
+= hb_amount_base(acc
->bal_bank
, acc
->kcur
);
2026 ttoday
+= hb_amount_base(acc
->bal_today
, acc
->kcur
);
2027 tfuture
+= hb_amount_base(acc
->bal_future
, acc
->kcur
);
2029 DB( g_print(" - insert '%s' :: %.2f %.2f %.2f\n", acc
->name
, acc
->bal_bank
, acc
->bal_today
, acc
->bal_future
) );
2031 gtk_tree_store_append (GTK_TREE_STORE(model
), &child_iter
, &iter1
);
2032 gtk_tree_store_set (GTK_TREE_STORE(model
), &child_iter
,
2033 LST_DSPACC_DATAS
, acc
,
2034 LST_DSPACC_DATATYPE
, DSPACC_TYPE_NORMAL
,
2035 LST_DSPACC_BANK
, acc
->bal_bank
,
2036 LST_DSPACC_TODAY
, acc
->bal_today
,
2037 LST_DSPACC_FUTURE
, acc
->bal_future
,
2043 DB( g_print(" - type totals :: %.2f %.2f %.2f\n", tbank
, ttoday
, tfuture
) );
2045 // insert the total line
2046 gtk_tree_store_append (GTK_TREE_STORE(model
), &child_iter
, &iter1
);
2047 gtk_tree_store_set (GTK_TREE_STORE(model
), &child_iter
,
2048 LST_DSPACC_DATATYPE
, DSPACC_TYPE_SUBTOTAL
,
2049 LST_DSPACC_NAME
, _("Total"),
2050 LST_DSPACC_BANK
, tbank
,
2051 LST_DSPACC_TODAY
, ttoday
,
2052 LST_DSPACC_FUTURE
, tfuture
,
2056 /* set balance to header to display when collasped */
2057 DB( g_print(" - enrich totals to header :: %.2f %.2f %.2f\n", tbank
, ttoday
, tfuture
) );
2058 gtk_tree_store_set (GTK_TREE_STORE(model
), &iter1
,
2059 LST_DSPACC_BANK
, tbank
,
2060 LST_DSPACC_TODAY
, ttoday
,
2061 LST_DSPACC_FUTURE
, tfuture
,
2064 /* add to grand total */
2067 gtfuture
+= tfuture
;
2073 DB( g_print(" - grand totals :: %.2f %.2f %.2f\n", gtbank
, gttoday
, gtfuture
) );
2078 gtk_tree_store_append (GTK_TREE_STORE(model
), &iter1
, NULL
);
2079 gtk_tree_store_set (GTK_TREE_STORE(model
), &iter1
,
2080 LST_DSPACC_DATATYPE
, DSPACC_TYPE_SUBTOTAL
,
2081 LST_DSPACC_NAME
, _("Grand total"),
2082 LST_DSPACC_BANK
, gtbank
,
2083 LST_DSPACC_TODAY
, gttoday
,
2084 LST_DSPACC_FUTURE
, gtfuture
,
2089 gtk_tree_view_expand_all(GTK_TREE_VIEW(data
->LV_acc
));
2091 DB( g_print(" - free ressources\n") );
2093 g_hash_table_iter_init (&grp_iter
, h_group
);
2094 while (g_hash_table_iter_next (&grp_iter
, &key
, &value
))
2096 g_ptr_array_free (value
, TRUE
);
2098 g_hash_table_destroy (h_group
);
2103 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
)
2105 struct hbfile_data
*data
;
2108 DB( g_print("\n[ui-mainwindow] refresh_display\n") );
2110 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
2111 //data = INST_DATA(widget);
2113 flags
= GPOINTER_TO_INT(user_data
);
2115 /* set window title */
2116 if(flags
& UF_TITLE
)
2121 DB( g_print(" + 1: wintitle %x\n", data
->wintitle
) );
2123 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
2125 DB( g_print(" global changes: %d\n", GLOBALS
->changes_count
) );
2127 g_free(data
->wintitle
);
2129 changed
= (GLOBALS
->changes_count
> 0) ? "*" : "";
2131 data
->wintitle
= g_strdup_printf("%s%s - %s - " PROGNAME
, changed
, basename
, GLOBALS
->owner
);
2133 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), data
->wintitle
);
2138 /* update disabled things */
2139 if(flags
& UF_SENSITIVE
)
2141 GtkTreeSelection
*selection
;
2142 GtkTreeModel
*model
;
2145 gboolean active
,sensitive
;
2147 DB( g_print(" + 2: disabled, opelist count\n") );
2152 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
));
2153 active
= gtk_tree_selection_get_selected(selection
, &model
, &iter
);
2159 path
= gtk_tree_model_get_path(model
, &iter
);
2160 depth
= gtk_tree_path_get_depth(path
);
2164 DB( g_print(" depth is %d\n", depth
) );
2166 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPACC_DATAS
, &acc
, -1);
2174 // no change: disable save
2175 DB( g_print(" changes %d - new %d\n", GLOBALS
->changes_count
, GLOBALS
->hbfile_is_new
) );
2178 sensitive
= (GLOBALS
->changes_count
!= 0 ) ? TRUE
: FALSE
;
2179 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/SaveAs"), sensitive);
2180 //if(sensitive == TRUE && GLOBALS->hbfile_is_new == TRUE) sensitive = FALSE;
2181 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Save"), sensitive
);
2182 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Revert"), GLOBALS
->xhb_hasbak
);
2186 sensitive
= GLOBALS
->define_off
== 0 ? TRUE
: FALSE
;
2188 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Account"), sensitive
);
2189 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Payee"), sensitive
);
2190 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Category"), sensitive
);
2191 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
2192 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/EditMenu/Preferences"), sensitive
);
2194 // empty account list: disable Import, Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
2195 sensitive
= da_acc_length() > 0 ? TRUE
: FALSE
;
2197 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data-data->manager, "/MenuBar/FileMenu/Import"), sensitive);
2199 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Close"), sensitive
);
2200 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Archive"), sensitive
);
2201 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddOpe"), sensitive
);
2202 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowOpe"), sensitive
);
2203 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RStatistics"), sensitive
);
2204 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RTrendTime"), sensitive
);
2205 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBudget"), sensitive
);
2206 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBalance"), sensitive
);
2207 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RVehiculeCost"), sensitive
);
2209 // empty category list: disable Budget
2210 sensitive
= da_cat_length() > 1 ? TRUE
: FALSE
;
2211 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
2213 //#1501129 no need to disable, P & C can be created from assign dialog
2214 //sensitive = ((da_cat_length() > 1) || (da_pay_length() > 1)) ? TRUE : FALSE;
2215 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Assign"), sensitive);
2217 // empty archive list: disable scheduled check
2218 sensitive
= g_list_length(GLOBALS
->arc_list
) > 0 ? TRUE
: FALSE
;
2220 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddScheduled"), sensitive
);
2222 // no active account: disable Edit, Over
2223 sensitive
= (active
== TRUE
) ? TRUE
: FALSE
;
2224 if(data
->acc
&& data
->acc
->window
!= NULL
)
2227 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowOpe"), sensitive
);
2231 /* update toolbar, list */
2232 if(flags
& UF_VISUAL
)
2234 DB( g_print(" + 8: visual\n") );
2236 if(PREFS
->toolbar_style
== 0)
2237 gtk_toolbar_unset_style(GTK_TOOLBAR(data
->toolbar
));
2239 gtk_toolbar_set_style(GTK_TOOLBAR(data
->toolbar
), PREFS
->toolbar_style
-1);
2241 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_acc
), PREFS
->grid_lines
);
2242 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
2244 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_upc
), PREFS
->grid_lines
);
2245 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
2247 DB( g_print(" - show toolbar=%d\n", PREFS
->wal_toolbar
) );
2248 if(PREFS
->wal_toolbar
)
2249 gtk_widget_show(GTK_WIDGET(data
->toolbar
));
2251 gtk_widget_hide(GTK_WIDGET(data
->toolbar
));
2254 DB( g_print(" - show top_spending=%d\n", PREFS
->wal_spending
) );
2256 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
2258 if(PREFS
->wal_spending
)
2259 gtk_widget_show(GTK_WIDGET(data
->GR_top
));
2261 gtk_widget_hide(GTK_WIDGET(data
->GR_top
));
2265 DB( g_print(" - show upcoming=%d\n", PREFS
->wal_upcoming
) );
2266 if(PREFS
->wal_upcoming
)
2267 gtk_widget_show(GTK_WIDGET(data
->GR_upc
));
2269 gtk_widget_hide(GTK_WIDGET(data
->GR_upc
));
2271 DB( g_print(" minor %d\n", PREFS
->euro_active
) );
2272 gtk_action_set_visible(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor"), PREFS
->euro_active
);
2275 /* update balances */
2276 if(flags
& UF_BALANCE
)
2279 DB( g_print(" + 4: balances\n") );
2281 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
2283 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
2286 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[0]), data->bank, minor);
2287 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[1]), data->today, minor);
2288 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[2]), data->future, minor);
2292 if(flags
& UF_REFRESHALL
)
2294 DB( g_print(" + 8: refreshall\n") );
2296 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
2297 ui_mainwindow_populate_topspending(GLOBALS
->mainwindow
, NULL
);
2298 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
2307 ui_mainwindow_onRowActivated (GtkTreeView
*treeview
,
2309 GtkTreeViewColumn
*col
,
2312 GtkTreeModel
*model
;
2315 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
2317 model
= gtk_tree_view_get_model(treeview
);
2319 if (gtk_tree_model_get_iter(model
, &iter
, path
))
2323 gtk_tree_model_get(model
, &iter
, LST_DSPACC_DATAS
, &acc
, -1);
2328 DB( g_print ("Double-clicked row contains name %s\n", acc
->name
) );
2330 ui_mainwindow_action_showtransactions();
2340 static gboolean
ui_mainwindow_dispose(GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
2342 struct hbfile_data
*data
= user_data
;
2343 struct WinGeometry
*wg
;
2344 gboolean retval
= FALSE
;
2346 DB( g_print("\n[ui-mainwindow] dispose\n") );
2348 //store position and size
2349 wg
= &PREFS
->wal_wg
;
2350 gtk_window_get_position(GTK_WINDOW(widget
), &wg
->l
, &wg
->t
);
2351 gtk_window_get_size(GTK_WINDOW(widget
), &wg
->w
, &wg
->h
);
2352 GdkWindow
*gdk_window
= gtk_widget_get_window(GTK_WIDGET(widget
));
2353 GdkWindowState state
= gdk_window_get_state(gdk_window
);
2354 wg
->s
= (state
& GDK_WINDOW_STATE_MAXIMIZED
) ? 1 : 0;
2356 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
) );
2358 PREFS
->wal_vpaned
= gtk_paned_get_position(GTK_PANED(data
->vpaned
));
2359 PREFS
->wal_hpaned
= gtk_paned_get_position(GTK_PANED(data
->hpaned
));
2361 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
2364 if(ui_dialog_msg_savechanges(widget
, NULL
) == FALSE
)
2370 DB( g_print(" free wintitle %x\n", data
->wintitle
) );
2372 gtk_widget_destroy(data
->LV_top
);
2374 g_free(data
->wintitle
);
2375 da_filter_free(data
->filter
);
2382 //delete-event TRUE abort/FALSE destroy
2387 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser
*chooser
, struct hbfile_data
*data
)
2390 GError
*error
= NULL
;
2392 uri
= gtk_recent_chooser_get_current_uri (chooser
);
2394 path
= g_filename_from_uri (uri
, NULL
, NULL
);
2397 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
2398 g_error_free (error
);
2402 if( ui_dialog_msg_savechanges(data
->window
, NULL
) == TRUE
)
2409 gpw_recent_remove (gpw, path);
2413 hbfile_change_filepath(path
);
2414 ui_mainwindow_open_internal(data
->window
, NULL
);
2424 static void ui_mainwindow_window_screen_changed_cb (GtkWidget
*widget
,
2425 GdkScreen
*old_screen
,
2426 struct hbfile_data
*data
)
2429 DB( g_print("\n[ui-mainwindow] screen_changed_cb\n") );
2432 data
->recent_manager
= gtk_recent_manager_get_default ();
2434 gtk_menu_detach (GTK_MENU (data
->recent_menu
));
2435 g_object_unref (G_OBJECT (data
->recent_menu
));
2437 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2439 g_signal_connect (data
->recent_menu
,
2441 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2444 //menu_item = gtk_ui_manager_get_widget (data->manager, "/MenuBar/FileMenu/OpenRecent");
2445 //gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), data->recent_menu);
2449 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
)
2451 GtkRecentData
*recent_data
;
2453 GError
*error
= NULL
;
2455 DB( g_print("\n[ui-mainwindow] recent_add\n") );
2457 DB( g_print(" - file has .xhb suffix = %d\n", g_str_has_suffix (path
, ".xhb") ) );
2459 if( g_str_has_suffix (path
, ".xhb") == FALSE
) //ignore reverted file
2462 uri
= g_filename_to_uri (path
, NULL
, &error
);
2465 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
2466 g_error_free (error
);
2470 recent_data
= g_slice_new (GtkRecentData
);
2472 recent_data
->display_name
= NULL
;
2473 recent_data
->description
= NULL
;
2474 recent_data
->mime_type
= "application/x-homebank";
2475 recent_data
->app_name
= (gchar
*) g_get_application_name ();
2476 recent_data
->app_exec
= g_strjoin (" ", g_get_prgname (), "%u", NULL
);
2477 recent_data
->groups
= NULL
;
2478 recent_data
->is_private
= FALSE
;
2480 if (!gtk_recent_manager_add_full (data
->recent_manager
,
2484 g_warning ("Unable to add '%s' to the list of recently used documents", uri
);
2488 g_free (recent_data
->app_exec
);
2489 g_slice_free (GtkRecentData
, recent_data
);
2502 static GtkTargetEntry drop_types
[] =
2504 {"text/uri-list", 0, TARGET_URI_LIST
}
2507 static void ui_mainwindow_drag_data_received (GtkWidget
*widget
,
2508 GdkDragContext
*context
,
2510 GtkSelectionData
*selection_data
,
2511 guint info
, guint time
, GtkWindow
*window
)
2513 gchar
**uris
, **str
;
2515 gint filetype
, slen
;
2517 if (info
!= TARGET_URI_LIST
)
2520 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
2522 /* On MS-Windows, it looks like `selection_data->data' is not NULL terminated. */
2523 slen
= gtk_selection_data_get_length(selection_data
);
2524 newseldata
= g_new (gchar
, slen
+ 1);
2525 memcpy (newseldata
, gtk_selection_data_get_data(selection_data
), slen
);
2526 newseldata
[slen
] = 0;
2528 uris
= g_uri_list_extract_uris (newseldata
);
2530 DB( g_print(" - dragged %d %d files\n", slen
, g_strv_length(uris
) ) );
2533 //for (str = uris; *str; str++)
2536 GError
*error
= NULL
;
2537 gchar
*path
= g_filename_from_uri (*str
, NULL
, &error
);
2541 filetype
= homebank_alienfile_recognize(path
);
2543 DB( g_print(" - dragged %s, type is %d\n", path
, filetype
) );
2545 if( filetype
== FILETYPE_HOMEBANK
)
2547 hbfile_change_filepath(g_strdup(path
));
2548 ui_mainwindow_open_internal(GTK_WIDGET(window
), NULL
);
2552 //todo: future here to implement import for other filetype
2553 // ui_import_assistant_new();
2554 // + write a method into assistant to catch other filename
2557 ui_dialog_msg_infoerror(GTK_WINDOW(window
), GTK_MESSAGE_ERROR
,
2559 _("The file %s is not a valid HomeBank file."),
2569 g_warning ("Could not convert uri to local path: %s", error
->message
);
2571 g_error_free (error
);
2581 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
)
2583 GtkWidget
*toolbar_recent_menu
;
2584 GtkRecentFilter
*filter
;
2586 toolbar_recent_menu
= gtk_recent_chooser_menu_new_for_manager (manager
);
2588 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu
),
2590 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu
),
2591 GTK_RECENT_SORT_MRU
);
2592 //todo: add a user pref for this
2593 gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER (toolbar_recent_menu
),
2597 //gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (toolbar_recent_menu), FALSE);
2599 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (toolbar_recent_menu), TRUE);
2601 filter
= gtk_recent_filter_new ();
2602 //gtk_recent_filter_add_application (filter, g_get_application_name());
2603 gtk_recent_filter_add_pattern (filter
, "*.[Xx][Hh][Bb]");
2604 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (toolbar_recent_menu
), filter
);
2606 return toolbar_recent_menu
;
2610 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data
*data
, GtkWidget
*mainvbox
)
2612 GtkUIManager
*manager
;
2613 GtkActionGroup
*actions
;
2615 GError
*error
= NULL
;
2617 manager
= gtk_ui_manager_new ();
2618 data
->manager
= manager
;
2620 gtk_window_add_accel_group (GTK_WINDOW (data
->window
),
2621 gtk_ui_manager_get_accel_group(manager
));
2623 actions
= gtk_action_group_new ("MainWindow");
2624 gtk_action_group_set_translation_domain(actions
, GETTEXT_PACKAGE
);
2626 gtk_action_group_add_actions (actions
,
2631 gtk_action_group_add_toggle_actions (actions
,
2636 gtk_ui_manager_insert_action_group (data
->manager
, actions
, 0);
2637 g_object_unref (actions
);
2638 data
->actions
= actions
;
2640 /* set short labels to use in the toolbar */
2641 action
= gtk_action_group_get_action(actions
, "Open");
2642 g_object_set(action
, "short_label", _("Open"), NULL
);
2644 //action = gtk_action_group_get_action(action_group, "Save");
2645 //g_object_set(action, "is_important", TRUE, NULL);
2647 action
= gtk_action_group_get_action(actions
, "Account");
2648 g_object_set(action
, "short_label", _("Account"), NULL
);
2650 action
= gtk_action_group_get_action(actions
, "Payee");
2651 g_object_set(action
, "short_label", _("Payee"), NULL
);
2653 action
= gtk_action_group_get_action(actions
, "Category");
2654 g_object_set(action
, "short_label", _("Category"), NULL
);
2656 action
= gtk_action_group_get_action(actions
, "Archive");
2657 //TRANSLATORS: an archive is stored transaction buffers (kind of bookmark to prefill manual insertion)
2658 g_object_set(action
, "short_label", _("Archive"), NULL
);
2660 action
= gtk_action_group_get_action(actions
, "Budget");
2661 g_object_set(action
, "short_label", _("Budget"), NULL
);
2663 action
= gtk_action_group_get_action(actions
, "ShowOpe");
2664 g_object_set(action
, "short_label", _("Show"), NULL
);
2666 action
= gtk_action_group_get_action(actions
, "AddOpe");
2667 g_object_set(action
, "is_important", TRUE
, "short_label", _("Add"), NULL
);
2669 action
= gtk_action_group_get_action(actions
, "RStatistics");
2670 g_object_set(action
, "short_label", _("Statistics"), NULL
);
2672 action
= gtk_action_group_get_action(actions
, "RBudget");
2673 g_object_set(action
, "short_label", _("Budget"), NULL
);
2675 action
= gtk_action_group_get_action(actions
, "RBalance");
2676 g_object_set(action
, "short_label", _("Balance"), NULL
);
2678 action
= gtk_action_group_get_action(actions
, "RVehiculeCost");
2679 g_object_set(action
, "short_label", _("Vehicle cost"), NULL
);
2681 /* now load the UI definition */
2682 gtk_ui_manager_add_ui_from_string (data
->manager
, ui_info
, -1, &error
);
2685 g_message ("Building menus failed: %s", error
->message
);
2686 g_error_free (error
);
2689 //todo: this generate a warning
2690 data
->menubar
= gtk_ui_manager_get_widget (manager
, "/MenuBar");
2691 gtk_box_pack_start (GTK_BOX (mainvbox
),
2697 data
->toolbar
= gtk_ui_manager_get_widget (manager
, "/ToolBar");
2698 gtk_box_pack_start (GTK_BOX (mainvbox
),
2704 /* recent files menu */
2706 data
->recent_manager
= gtk_recent_manager_get_default ();
2708 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2710 g_signal_connect (data
->recent_menu
,
2712 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2716 widget = gtk_ui_manager_get_widget (data->manager, "/MenuBar/FileMenu/OpenRecent");
2717 gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), data->recent_menu);
2721 /* add the custom Open button to the toolbar */
2722 GtkWidget
*image
= gtk_image_new_from_icon_name (ICONNAME_OPEN
, GTK_ICON_SIZE_BUTTON
);
2724 GtkToolItem
*open_button
= gtk_menu_tool_button_new(image
, _("_Open"));
2725 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button
), data
->recent_menu
);
2727 gtk_tool_item_set_tooltip_text (open_button
, _("Open a file"));
2728 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button
), _("Open a recently used file"));
2730 action
= gtk_action_group_get_action (data
->actions
, "Open");
2731 g_object_set (action
, "short_label", _("Open"), NULL
);
2732 //gtk_action_connect_proxy (action, GTK_WIDGET (open_button));
2733 gtk_activatable_set_related_action (GTK_ACTIVATABLE (open_button
), action
);
2735 gtk_toolbar_insert (GTK_TOOLBAR (data
->toolbar
), open_button
, 1);
2740 /* Callback function for the undo action */
2742 activate_action (GSimpleAction *action, GVariant *parameter, gpointer user_data)
2744 g_print ("Action %s activated\n", g_action_get_name (G_ACTION (action)));
2748 activate_toggle (GSimpleAction
*action
, GVariant
*parameter
, gpointer user_data
)
2750 struct hbfile_data
*data
= user_data
;
2751 GVariant
*old_state
, *new_state
;
2753 old_state
= g_action_get_state (G_ACTION (action
));
2754 new_state
= g_variant_new_boolean (!g_variant_get_boolean (old_state
));
2756 DB( g_print ("Toggle action %s activated, state changes from %d to %d\n",
2757 g_action_get_name (G_ACTION (action
)),
2758 g_variant_get_boolean (old_state
),
2759 g_variant_get_boolean (new_state
)) );
2761 data
->showall
= g_variant_get_boolean (new_state
);
2762 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
2764 g_simple_action_set_state (action
, new_state
);
2765 g_variant_unref (old_state
);
2769 activate_radio (GSimpleAction
*action
, GVariant
*parameter
, gpointer user_data
)
2771 //struct hbfile_data *data = user_data;
2772 GVariant
*old_state
, *new_state
;
2774 old_state
= g_action_get_state (G_ACTION (action
));
2775 new_state
= g_variant_new_string (g_variant_get_string (parameter
, NULL
));
2777 DB( g_print ("Radio action %s activated, state changes from %s to %s\n",
2778 g_action_get_name (G_ACTION (action
)),
2779 g_variant_get_string (old_state
, NULL
),
2780 g_variant_get_string (new_state
, NULL
)) );
2782 PREFS
->pnl_acc_show_by
= DSPACC_GROUP_BY_TYPE
;
2783 if( !strcmp("bank", g_variant_get_string(new_state
, NULL
)) )
2784 PREFS
->pnl_acc_show_by
= DSPACC_GROUP_BY_BANK
;
2786 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
2788 g_simple_action_set_state (action
, new_state
);
2789 g_variant_unref (old_state
);
2793 static const GActionEntry actions
[] = {
2794 // { "paste", activate_action, NULL, NULL, NULL, {0,0,0} },
2795 { "showall" , activate_toggle
, NULL
, "false", NULL
, {0,0,0} },
2796 { "groupby", activate_radio
, "s", "'type'", NULL
, {0,0,0} }
2800 static GtkWidget
*ui_mainwindow_create_youraccounts(struct hbfile_data
*data
)
2802 GtkWidget
*panel
, *label
, *widget
, *sw
, *tbar
, *hbox
, *image
;
2803 GtkToolItem
*toolitem
;
2805 panel
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2806 gtk_container_set_border_width(GTK_CONTAINER(panel
), SPACING_SMALL
);
2808 sw
= gtk_scrolled_window_new (NULL
, NULL
);
2809 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw
), GTK_SHADOW_ETCHED_IN
);
2810 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw
), GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2811 gtk_box_pack_start (GTK_BOX (panel
), sw
, TRUE
, TRUE
, 0);
2812 widget
= (GtkWidget
*)create_list_account();
2813 data
->LV_acc
= widget
;
2814 gtk_container_add (GTK_CONTAINER (sw
), widget
);
2817 tbar
= gtk_toolbar_new();
2818 gtk_toolbar_set_icon_size (GTK_TOOLBAR(tbar
), GTK_ICON_SIZE_MENU
);
2819 gtk_toolbar_set_style(GTK_TOOLBAR(tbar
), GTK_TOOLBAR_ICONS
);
2820 gtk_style_context_add_class (gtk_widget_get_style_context (tbar
), GTK_STYLE_CLASS_INLINE_TOOLBAR
);
2821 gtk_box_pack_start (GTK_BOX (panel
), tbar
, FALSE
, FALSE
, 0);
2823 label
= make_label_group(_("Your accounts"));
2824 toolitem
= gtk_tool_item_new();
2825 gtk_container_add (GTK_CONTAINER(toolitem
), label
);
2826 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2828 toolitem
= gtk_separator_tool_item_new ();
2829 gtk_tool_item_set_expand (toolitem
, TRUE
);
2830 gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(toolitem
), FALSE
);
2831 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2833 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
2834 toolitem
= gtk_tool_item_new();
2835 gtk_container_add (GTK_CONTAINER(toolitem
), hbox
);
2836 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2838 widget
= make_image_button(ICONNAME_HB_BUTTON_EXPAND
, _("Expand all"));
2839 data
->BT_expandall
= widget
;
2840 gtk_box_pack_start (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
2842 widget
= make_image_button(ICONNAME_HB_BUTTON_COLLAPSE
, _("Collapse all"));
2843 data
->BT_collapseall
= widget
;
2844 gtk_box_pack_start (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
2846 toolitem
= gtk_separator_tool_item_new ();
2847 gtk_tool_item_set_expand (toolitem
, FALSE
);
2848 gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(toolitem
), FALSE
);
2849 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2852 //gmenu test (see test folder into gtk)
2853 widget
= gtk_menu_button_new();
2854 gtk_menu_button_set_direction (GTK_MENU_BUTTON(widget
), GTK_ARROW_UP
);
2855 gtk_widget_set_halign (widget
, GTK_ALIGN_END
);
2856 image
= gtk_image_new_from_icon_name (ICONNAME_EMBLEM_SYSTEM
, GTK_ICON_SIZE_MENU
);
2857 g_object_set (widget
, "image", image
, NULL
);
2859 toolitem
= gtk_tool_item_new();
2860 gtk_container_add (GTK_CONTAINER(toolitem
), widget
);
2861 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2863 GMenu
*menu
, *section
;
2865 menu
= g_menu_new ();
2866 //g_menu_append (menumodel, "About", "actions.undo");
2867 //g_menu_append (menumodel, "Test", "actions.redo");
2868 section
= g_menu_new ();
2869 g_menu_append (section
, _("Show all"), "actions.showall");
2870 g_menu_append_section(menu
, NULL
, G_MENU_MODEL(section
));
2871 g_object_unref (section
);
2873 section
= g_menu_new ();
2874 g_menu_append (section
, _("By type"), "actions.groupby::type");
2875 g_menu_append (section
, _("By institition"), "actions.groupby::bank");
2876 g_menu_append_section(menu
, NULL
, G_MENU_MODEL(section
));
2877 g_object_unref (section
);
2880 GSimpleActionGroup
*group
= g_simple_action_group_new ();
2881 g_action_map_add_action_entries (G_ACTION_MAP (group
), actions
, G_N_ELEMENTS (actions
), data
);
2884 GAction
*action
= g_action_map_lookup_action (G_ACTION_MAP (group
), "groupby");
2885 const gchar
*value
= (PREFS
->pnl_acc_show_by
== DSPACC_GROUP_BY_TYPE
) ? "type" : "bank";
2886 g_simple_action_set_state (G_SIMPLE_ACTION (action
), g_variant_new_string (value
));
2888 gtk_widget_insert_action_group (widget
, "actions", G_ACTION_GROUP(group
));
2890 gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (widget
), G_MENU_MODEL (menu
));
2896 static GtkWidget
*ui_mainwindow_create_topspending(struct hbfile_data
*data
)
2898 GtkWidget
*panel
, *hbox
, *tbar
;
2899 GtkWidget
*label
, *widget
;
2900 GtkToolItem
*toolitem
;
2902 widget
= (GtkWidget
*)create_list_topspending();
2903 data
->LV_top
= widget
;
2905 panel
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2906 gtk_container_set_border_width(GTK_CONTAINER(panel
), SPACING_SMALL
);
2907 data
->GR_top
= panel
;
2909 /* chart + listview */
2910 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
2911 gtk_box_pack_start (GTK_BOX (panel
), hbox
, TRUE
, TRUE
, 0);
2913 widget
= gtk_chart_new(CHART_TYPE_PIE
);
2914 data
->RE_pie
= widget
;
2915 gtk_chart_set_minor_prefs(GTK_CHART(widget
), PREFS
->euro_value
, PREFS
->minor_cur
.symbol
);
2916 gtk_chart_show_legend(GTK_CHART(data
->RE_pie
), TRUE
, TRUE
);
2917 gtk_box_pack_start (GTK_BOX (hbox
), widget
, TRUE
, TRUE
, 0);
2920 tbar
= gtk_toolbar_new();
2921 gtk_toolbar_set_icon_size (GTK_TOOLBAR(tbar
), GTK_ICON_SIZE_MENU
);
2922 gtk_toolbar_set_style(GTK_TOOLBAR(tbar
), GTK_TOOLBAR_ICONS
);
2923 gtk_style_context_add_class (gtk_widget_get_style_context (tbar
), GTK_STYLE_CLASS_INLINE_TOOLBAR
);
2924 gtk_box_pack_start (GTK_BOX (panel
), tbar
, FALSE
, FALSE
, 0);
2926 label
= make_label_group(_("Where your money goes"));
2927 toolitem
= gtk_tool_item_new();
2928 gtk_container_add (GTK_CONTAINER(toolitem
), label
);
2929 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2931 toolitem
= gtk_separator_tool_item_new ();
2932 gtk_tool_item_set_expand (toolitem
, TRUE
);
2933 gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(toolitem
), FALSE
);
2934 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2936 /* total + date range */
2937 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, SPACING_SMALL
);
2938 toolitem
= gtk_tool_item_new();
2939 gtk_container_add (GTK_CONTAINER(toolitem
), hbox
);
2940 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2942 data
->CY_range
= make_daterange(label
, FALSE
);
2943 gtk_box_pack_end (GTK_BOX (hbox
), data
->CY_range
, FALSE
, FALSE
, 0);
2945 widget
= make_radio(CYA_CATSUBCAT
, TRUE
, GTK_ORIENTATION_HORIZONTAL
);
2946 data
->RA_type
= widget
;
2947 gtk_box_pack_end (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
2953 static GtkWidget
*ui_mainwindow_scheduled_create(struct hbfile_data
*data
)
2955 GtkWidget
*panel
, *hbox
, *vbox
, *bbox
, *sw
, *tbar
;
2956 GtkWidget
*label
, *widget
;
2957 GtkToolItem
*toolitem
;
2959 panel
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2960 gtk_container_set_border_width(GTK_CONTAINER(panel
), SPACING_SMALL
);
2961 data
->GR_upc
= panel
;
2963 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2964 //gtk_widget_set_margin_top(GTK_WIDGET(vbox), 0);
2965 //gtk_widget_set_margin_bottom(GTK_WIDGET(vbox), SPACING_SMALL);
2966 //gtk_widget_set_margin_start(GTK_WIDGET(vbox), 2*SPACING_SMALL);
2967 //gtk_widget_set_margin_end(GTK_WIDGET(vbox), SPACING_SMALL);
2968 gtk_box_pack_start (GTK_BOX (panel
), vbox
, TRUE
, TRUE
, 0);
2970 sw
= gtk_scrolled_window_new (NULL
, NULL
);
2971 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw
), GTK_SHADOW_ETCHED_IN
);
2972 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw
), GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2973 gtk_box_pack_start (GTK_BOX (vbox
), sw
, TRUE
, TRUE
, 0);
2975 widget
= (GtkWidget
*)create_list_upcoming();
2976 data
->LV_upc
= widget
;
2977 gtk_container_add (GTK_CONTAINER (sw
), widget
);
2979 tbar
= gtk_toolbar_new();
2980 gtk_toolbar_set_icon_size (GTK_TOOLBAR(tbar
), GTK_ICON_SIZE_MENU
);
2981 gtk_toolbar_set_style(GTK_TOOLBAR(tbar
), GTK_TOOLBAR_ICONS
);
2982 gtk_style_context_add_class (gtk_widget_get_style_context (tbar
), GTK_STYLE_CLASS_INLINE_TOOLBAR
);
2983 gtk_box_pack_start (GTK_BOX (vbox
), tbar
, FALSE
, FALSE
, 0);
2985 label
= make_label_group(_("Scheduled transactions"));
2986 toolitem
= gtk_tool_item_new();
2987 gtk_container_add (GTK_CONTAINER(toolitem
), label
);
2988 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2990 toolitem
= gtk_separator_tool_item_new ();
2991 gtk_tool_item_set_expand (toolitem
, FALSE
);
2992 gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(toolitem
), FALSE
);
2993 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2996 bbox
= gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL
);
2997 toolitem
= gtk_tool_item_new();
2998 gtk_container_add (GTK_CONTAINER(toolitem
), bbox
);
2999 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
3001 widget
= gtk_button_new_with_label(_("Skip"));
3002 data
->BT_sched_skip
= widget
;
3003 gtk_box_pack_start (GTK_BOX (bbox
), widget
, FALSE
, FALSE
, 0);
3005 widget
= gtk_button_new_with_label(_("Edit & Post"));
3006 data
->BT_sched_editpost
= widget
;
3007 gtk_box_pack_start (GTK_BOX (bbox
), widget
, FALSE
, FALSE
, 0);
3009 //TRANSLATORS: Posting a scheduled transaction is the action to materialize it into its target account.
3010 //TRANSLATORS: Before that action the automated transaction occurrence is pending and not yet really existing.
3011 widget
= gtk_button_new_with_label (_("Post"));
3012 data
->BT_sched_post
= widget
;
3013 gtk_box_pack_start (GTK_BOX (bbox
), widget
, FALSE
, FALSE
, 0);
3015 toolitem
= gtk_separator_tool_item_new ();
3016 gtk_tool_item_set_expand (toolitem
, FALSE
);
3017 gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(toolitem
), FALSE
);
3018 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
3020 hbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
3021 gtk_widget_set_valign (hbox
, GTK_ALIGN_CENTER
);
3022 toolitem
= gtk_tool_item_new();
3023 gtk_container_add (GTK_CONTAINER(toolitem
), hbox
);
3024 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
3026 label
= make_label(_("maximum post date"), 0.0, 0.7);
3027 gtk_widget_set_halign (label
, GTK_ALIGN_CENTER
);
3028 gimp_label_set_attributes (GTK_LABEL (label
), PANGO_ATTR_SCALE
, PANGO_SCALE_SMALL
, -1);
3029 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
3031 label
= make_label(NULL
, 0.0, 0.7);
3032 data
->LB_maxpostdate
= label
;
3033 gtk_widget_set_halign (label
, GTK_ALIGN_CENTER
);
3034 gimp_label_set_attributes (GTK_LABEL (label
), PANGO_ATTR_SCALE
, PANGO_SCALE_SMALL
, -1);
3035 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
3042 ** the window creation
3044 GtkWidget
*create_hbfile_window(GtkWidget
*do_widget
)
3046 struct hbfile_data
*data
;
3047 struct WinGeometry
*wg
;
3048 GtkWidget
*mainvbox
, *vbox
, *vpaned
, *hpaned
;
3053 DB( g_print("\n[ui-mainwindow] create main window\n") );
3055 data
= g_malloc0(sizeof(struct hbfile_data
));
3056 if(!data
) return NULL
;
3058 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
3060 //store our window private data
3061 g_object_set_data(G_OBJECT(window
), "inst_data", (gpointer
)data
);
3062 DB( g_print(" - new window=%x, inst_data=%0x\n", window
, data
) );
3064 // this is our mainwindow, so store it to GLOBALS data
3065 data
->window
= window
;
3066 GLOBALS
->mainwindow
= window
;
3068 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
3069 gtk_container_add (GTK_CONTAINER (window
), mainvbox
);
3071 ui_mainwindow_create_menu_bar_and_toolbar (data
, mainvbox
);
3073 #if HB_UNSTABLE_SHOW == TRUE
3074 GtkWidget
*bar
, *label
;
3076 bar
= gtk_info_bar_new ();
3077 gtk_box_pack_start (GTK_BOX (mainvbox
), bar
, FALSE
, FALSE
, 0);
3078 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar
), GTK_MESSAGE_WARNING
);
3079 label
= make_label(NULL
, 0.5, 0.5);
3080 gtk_label_set_markup (GTK_LABEL(label
), "Unstable Development Version");
3081 gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar
))), label
, FALSE
, FALSE
, 0);
3084 /* Add the main area */
3085 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
3086 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
3087 gtk_box_pack_start (GTK_BOX (mainvbox
), vbox
, TRUE
, TRUE
, 0);
3089 vpaned
= gtk_paned_new(GTK_ORIENTATION_VERTICAL
);
3090 data
->vpaned
= vpaned
;
3091 gtk_box_pack_start (GTK_BOX (vbox
), vpaned
, TRUE
, TRUE
, 0);
3093 hpaned
= gtk_paned_new(GTK_ORIENTATION_HORIZONTAL
);
3094 data
->hpaned
= hpaned
;
3095 gtk_paned_pack1 (GTK_PANED(vpaned
), hpaned
, FALSE
, FALSE
);
3097 widget
= ui_mainwindow_scheduled_create(data
);
3098 gtk_paned_pack2 (GTK_PANED(vpaned
), widget
, FALSE
, FALSE
);
3100 widget
= ui_mainwindow_create_youraccounts(data
);
3101 gtk_paned_pack1 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
3103 widget
= ui_mainwindow_create_topspending(data
);
3104 gtk_paned_pack2 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
3107 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
3109 if(PREFS
->wal_hpaned
> 0)
3110 gtk_paned_set_position(GTK_PANED(data
->hpaned
), PREFS
->wal_hpaned
);
3111 if(PREFS
->wal_vpaned
> 0)
3112 gtk_paned_set_position(GTK_PANED(data
->vpaned
), PREFS
->wal_vpaned
);
3114 //setup, init and show window
3115 wg
= &PREFS
->wal_wg
;
3118 gtk_window_move(GTK_WINDOW(window
), wg
->l
, wg
->t
);
3119 gtk_window_resize(GTK_WINDOW(window
), wg
->w
, wg
->h
);
3122 gtk_window_maximize(GTK_WINDOW(window
));
3124 gtk_widget_show_all (window
);
3126 //todo: move this elsewhere
3127 DB( g_print(" - setup stuff\n") );
3129 data
->filter
= da_filter_malloc();
3130 filter_default_all_set(data
->filter
);
3131 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
3133 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Toolbar");
3134 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_toolbar
);
3135 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Spending");
3136 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_spending
);
3137 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Upcoming");
3138 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_upcoming
);
3140 /* Drag and drop support, set targets to NULL because we add the
3141 default uri_targets below */
3143 /* support for opening a file by dragging onto the project window */
3144 gtk_drag_dest_set (GTK_WIDGET (window
),
3145 GTK_DEST_DEFAULT_ALL
,
3147 G_N_ELEMENTS (drop_types
),
3150 g_signal_connect (G_OBJECT (window
), "drag-data-received",
3151 G_CALLBACK (ui_mainwindow_drag_data_received
), window
);
3155 //connect all our signals
3156 DB( g_print(" - connect signals\n") );
3159 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
)), "changed", G_CALLBACK (ui_mainwindow_selection
), NULL
);
3160 g_signal_connect (GTK_TREE_VIEW(data
->LV_acc
), "row-activated", G_CALLBACK (ui_mainwindow_onRowActivated
), GINT_TO_POINTER(2));
3161 g_signal_connect (G_OBJECT (data
->BT_expandall
), "clicked" , G_CALLBACK (ui_panel_accounts_expand_all
), NULL
);
3162 g_signal_connect (G_OBJECT (data
->BT_collapseall
), "clicked" , G_CALLBACK (ui_panel_accounts_collapse_all
), NULL
);
3164 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_upc
)), "changed", G_CALLBACK (ui_mainwindow_scheduled_selection_cb
), NULL
);
3165 g_signal_connect (GTK_TREE_VIEW(data
->LV_upc
), "row-activated", G_CALLBACK (ui_mainwindow_scheduled_onRowActivated
), NULL
);
3166 g_signal_connect (G_OBJECT (data
->BT_sched_skip
), "clicked", G_CALLBACK (ui_mainwindow_scheduled_skip_cb
), data
);
3167 g_signal_connect (G_OBJECT (data
->BT_sched_editpost
), "clicked", G_CALLBACK (ui_mainwindow_scheduled_editpost_cb
), data
);
3168 g_signal_connect (G_OBJECT (data
->BT_sched_post
), "clicked", G_CALLBACK (ui_mainwindow_scheduled_post_cb
), data
);
3170 widget
= radio_get_nth_widget(GTK_CONTAINER(data
->RA_type
), 1);
3172 g_signal_connect (widget
, "toggled", G_CALLBACK (ui_mainwindow_populate_topspending
), &data
);
3174 g_signal_connect (data
->CY_range
, "changed", G_CALLBACK (ui_mainwindow_populate_topspending
), NULL
);
3177 /* GtkWindow events */
3178 g_signal_connect (window
, "delete-event", G_CALLBACK (ui_mainwindow_dispose
), (gpointer
)data
);
3181 g_signal_connect (window
, "screen-changed",
3182 G_CALLBACK (ui_mainwindow_window_screen_changed_cb
),
3186 //gtk_action_group_set_sensitive(data->actions, FALSE);