1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 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"
27 #include "hub-account.h"
28 #include "hub-scheduled.h"
29 #include "hub-spending.h"
30 #include "hub-transaction.h"
32 #include "dsp-account.h"
33 #include "ui-assist-import.h"
34 #include "ui-assist-start.h"
35 #include "ui-account.h"
36 #include "ui-currency.h"
38 #include "ui-category.h"
39 #include "ui-archive.h"
40 #include "ui-assign.h"
41 #include "ui-budget.h"
43 #include "ui-hbfile.h"
44 #include "ui-transaction.h"
47 #include "rep-balance.h"
48 #include "rep-budget.h"
49 #include "rep-stats.h"
51 #include "rep-vehicle.h"
53 #include "gtk-chart.h"
56 //#define HOMEBANK_URL_HELP "http://homebank.free.fr/help/"
57 //#define HOMEBANK_URL_HELP_ONLINE "https://launchpad.net/homebank/+addquestion"
58 //#define HOMEBANK_URL_HELP_PROBLEM "https://launchpad.net/homebank/+filebug"
59 //#define HOMEBANK_URL_HELP_TRANSLATE "https://launchpad.net/homebank/+translations"
61 #define HOMEBANK_URL_HELP "index.html"
62 #define HOMEBANK_URL_HELP_ONLINE "http://homebank.free.fr/support.php"
63 #define HOMEBANK_URL_HELP_UPDATES "http://homebank.free.fr/downloads.php"
64 #define HOMEBANK_URL_HELP_PROBLEM "http://homebank.free.fr/development.php#bug"
65 #define HOMEBANK_URL_HELP_TRANSLATE "http://homebank.free.fr/development.php#translate"
68 /****************************************************************************/
70 /****************************************************************************/
79 /* our global datas */
80 extern struct HomeBank
*GLOBALS
;
81 extern struct Preferences
*PREFS
;
82 extern gchar
*homebank_pixmaps_dir
;
85 /* our functions prototype */
86 static void ui_mainwindow_action_new(void);
87 static void ui_mainwindow_action_open(void);
88 static void ui_mainwindow_action_save(void);
89 static void ui_mainwindow_action_saveas(void);
90 static void ui_mainwindow_action_revert(void);
91 static void ui_mainwindow_action_openbak(void);
92 static void ui_mainwindow_action_properties(void);
93 static void ui_mainwindow_action_close(void);
94 static void ui_mainwindow_action_quit(void);
96 static void ui_mainwindow_action_defcurrency(void);
97 static void ui_mainwindow_action_defaccount(void);
98 static void ui_mainwindow_action_defpayee(void);
99 static void ui_mainwindow_action_defcategory(void);
100 static void ui_mainwindow_action_defarchive(void);
101 static void ui_mainwindow_action_defbudget(void);
102 static void ui_mainwindow_action_defassign(void);
103 static void ui_mainwindow_action_deftag(void);
104 static void ui_mainwindow_action_preferences(void);
106 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction
*action
);
107 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction
*action
);
108 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction
*action
);
109 static void ui_mainwindow_action_toggle_minor(GtkToggleAction
*action
);
111 static void ui_mainwindow_action_showtransactions(GtkAction
*action
);
113 static void ui_mainwindow_action_addtransactions(void);
114 static void ui_mainwindow_action_checkscheduled(void);
116 static void ui_mainwindow_action_statistic(void);
117 static void ui_mainwindow_action_trendtime(void);
118 static void ui_mainwindow_action_budget(void);
119 static void ui_mainwindow_action_balance(void);
120 static void ui_mainwindow_action_vehiclecost(void);
122 static void ui_mainwindow_action_import(GtkAction
*action
);
123 static void ui_mainwindow_action_export(void);
124 static void ui_mainwindow_action_anonymize(void);
125 static void ui_mainwindow_action_file_statistics(void);
127 static void ui_mainwindow_action_help(void);
128 void ui_mainwindow_action_help_welcome(void);
129 static void ui_mainwindow_action_help_online(void);
130 static void ui_mainwindow_action_help_updates(void);
131 static void ui_mainwindow_action_help_releasenotes(void);
132 static void ui_mainwindow_action_help_translate(void);
133 static void ui_mainwindow_action_help_problem(void);
134 static void ui_mainwindow_action_about(void);
137 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
);
139 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
);
141 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
);
142 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
);
143 void ui_mainwindow_action(GtkWidget
*widget
, gpointer user_data
);
144 void ui_mainwindow_toggle_minor(GtkWidget
*widget
, gpointer user_data
);
145 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
);
147 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
);
148 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
);
149 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
151 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
154 static GtkActionEntry entries
[] = {
156 /* name, icon-name, label */
158 { "FileMenu" , NULL
, N_("_File"), NULL
, NULL
, NULL
},
159 //{ "ImportMenu" , NULL, N_("_Import"), NULL, NULL, NULL },
160 { "RecentMenu" , NULL
, N_("Open _Recent"), NULL
, NULL
, NULL
},
161 { "EditMenu" , NULL
, N_("_Edit"), NULL
, NULL
, NULL
},
162 { "ViewMenu" , NULL
, N_("_View"), NULL
, NULL
, NULL
},
163 { "ManageMenu" , NULL
, N_("_Manage"), NULL
, NULL
, NULL
},
164 { "TxnMenu" , NULL
, N_("_Transactions"), NULL
, NULL
, NULL
},
165 { "ReportMenu" , NULL
, N_("_Reports"), NULL
, NULL
, NULL
},
166 { "ToolsMenu" , NULL
, N_("_Tools"), NULL
, NULL
, NULL
},
167 { "HelpMenu" , NULL
, N_("_Help"), NULL
, NULL
, NULL
},
169 // { "Import" , NULL, N_("Import") },
170 // { "Export" , NULL, N_("Export to") },
171 /* name, icon-name, label, accelerator, tooltip */
174 { "New" , ICONNAME_HB_FILE_NEW
, N_("_New") , "<control>N", N_("Create a new file"), G_CALLBACK (ui_mainwindow_action_new
) },
175 { "Open" , ICONNAME_HB_FILE_OPEN
, N_("_Open...") , "<control>O", N_("Open a file"), G_CALLBACK (ui_mainwindow_action_open
) },
176 { "Save" , ICONNAME_HB_FILE_SAVE
, N_("_Save") , "<control>S", N_("Save the current file"), G_CALLBACK (ui_mainwindow_action_save
) },
177 { "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
) },
180 { "OpenBak" , NULL
, N_("Restore backup") , NULL
, N_("Restore from a backup file"), G_CALLBACK (ui_mainwindow_action_openbak
) },
182 { "Properties" , ICONNAME_PROPERTIES
, N_("Properties..."), NULL
, N_("Configure the file"), G_CALLBACK (ui_mainwindow_action_properties
) },
183 { "Close" , ICONNAME_CLOSE
, N_("_Close") , "<control>W", N_("Close the current file"), G_CALLBACK (ui_mainwindow_action_close
) },
184 { "Quit" , ICONNAME_QUIT
, N_("_Quit") , "<control>Q", N_("Quit HomeBank"), G_CALLBACK (ui_mainwindow_action_quit
) },
187 { "Import" , ICONNAME_HB_FILE_IMPORT
, N_("Import...") , NULL
, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import
) },
188 //{ "ImportQIF" , ICONNAME_HB_FILE_IMPORT , N_("QIF file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
189 //{ "ImportOFX" , ICONNAME_HB_FILE_IMPORT , N_("OFX/QFX file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
190 //{ "ImportCSV" , ICONNAME_HB_FILE_IMPORT , N_("CSV file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
192 { "ExportQIF" , ICONNAME_HB_FILE_EXPORT
, N_("Export as QIF...") , NULL
, N_("Export all account in a QIF file"), G_CALLBACK (ui_mainwindow_action_export
) },
195 { "Preferences", ICONNAME_PREFERENCES
, N_("Preferences..."), NULL
, N_("Configure HomeBank"), G_CALLBACK (ui_mainwindow_action_preferences
) },
198 { "Currency" , ICONNAME_HB_CURRENCY
, N_("Currencies...") , NULL
, N_("Configure the currencies"), G_CALLBACK (ui_mainwindow_action_defcurrency
) },
199 { "Account" , ICONNAME_HB_ACCOUNT
, N_("Acc_ounts...") , NULL
, N_("Configure the accounts"), G_CALLBACK (ui_mainwindow_action_defaccount
) },
200 { "Payee" , ICONNAME_HB_PAYEE
, N_("_Payees...") , NULL
, N_("Configure the payees"), G_CALLBACK (ui_mainwindow_action_defpayee
) },
201 { "Category" , ICONNAME_HB_CATEGORY
, N_("Categories...") , NULL
, N_("Configure the categories"), G_CALLBACK (ui_mainwindow_action_defcategory
) },
202 { "Archive" , ICONNAME_HB_ARCHIVE
, N_("Scheduled/Template...") , NULL
, N_("Configure the scheduled/template transactions"), G_CALLBACK (ui_mainwindow_action_defarchive
) },
203 { "Budget" , ICONNAME_HB_BUDGET
, N_("Budget...") , NULL
, N_("Configure the budget"), G_CALLBACK (ui_mainwindow_action_defbudget
) },
204 { "Assign" , ICONNAME_HB_ASSIGN
, N_("Assignments..."), NULL
, N_("Configure the automatic assignments"), G_CALLBACK (ui_mainwindow_action_defassign
) },
205 { "Tag" , NULL
, N_("Tags..."), NULL
, N_("Configure the tags"), G_CALLBACK (ui_mainwindow_action_deftag
) },
208 { "AddTxn" , ICONNAME_HB_OPE_ADD
, N_("Add...") , NULL
, N_("Add transactions"), G_CALLBACK (ui_mainwindow_action_addtransactions
) },
209 { "ShowTxn" , ICONNAME_HB_OPE_SHOW
, N_("Show...") , NULL
, N_("Shows selected account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions
) },
210 //beware ShowAllTxn is used to detect showall
211 { "ShowAllTxn" , ICONNAME_HB_OPE_SHOW
, N_("Show all...") , NULL
, N_("Shows all account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions
) },
212 { "Scheduler" , NULL
, N_("Set scheduler...") , NULL
, N_("Configure the transaction scheduler"), G_CALLBACK (ui_mainwindow_action_properties
) },
213 { "AddScheduled", NULL
, N_("Post scheduled"), NULL
, N_("Post pending scheduled transactions"), G_CALLBACK (ui_mainwindow_action_checkscheduled
) },
216 { "RStatistics" , ICONNAME_HB_REP_STATS
, N_("_Statistics...") , NULL
, N_("Open the Statistics report"), G_CALLBACK (ui_mainwindow_action_statistic
) },
217 { "RTrendTime" , ICONNAME_HB_REP_TIME
, N_("_Trend Time...") , NULL
, N_("Open the Trend Time report"), G_CALLBACK (ui_mainwindow_action_trendtime
) },
218 { "RBudget" , ICONNAME_HB_REP_BUDGET
, N_("B_udget...") , NULL
, N_("Open the Budget report"), G_CALLBACK (ui_mainwindow_action_budget
) },
219 { "RBalance" , ICONNAME_HB_REP_BALANCE
, N_("Balance...") , NULL
, N_("Open the Balance report"), G_CALLBACK (ui_mainwindow_action_balance
) },
220 { "RVehiculeCost", ICONNAME_HB_REP_CAR
, N_("_Vehicle cost...") , NULL
, N_("Open the Vehicle cost report"), G_CALLBACK (ui_mainwindow_action_vehiclecost
) },
223 { "Welcome" , NULL
, N_("Show welcome dialog...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_help_welcome
) },
224 { "FileStats" , NULL
, N_("File statistics...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_file_statistics
) },
225 { "Anonymize" , NULL
, N_("Anonymize...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_anonymize
) },
228 { "Contents" , ICONNAME_HELP
, N_("_Contents") , "F1", N_("Documentation about HomeBank"), G_CALLBACK (ui_mainwindow_action_help
) },
229 { "Online" , "lpi-help" , N_("Get Help Online...") , NULL
, N_("Connect to the LaunchPad website for online help"), G_CALLBACK (ui_mainwindow_action_help_online
) },
231 { "Updates" , NULL
, N_("Check for updates...") , NULL
, N_("Visit HomeBank website to check for update"), G_CALLBACK (ui_mainwindow_action_help_updates
) },
232 { "ReleaseNotes", NULL
, N_("Release Notes") , NULL
, N_("Display the release notes"), G_CALLBACK (ui_mainwindow_action_help_releasenotes
) },
233 { "Problem" , "lpi-bug" , N_("Report a Problem...") , NULL
, N_("Connect to the LaunchPad website to help fix problems"), G_CALLBACK (ui_mainwindow_action_help_problem
) },
234 { "Translate" , "lpi-translate" , N_("Translate this Application..."), NULL
, N_("Connect to the LaunchPad website to help translate this application"), G_CALLBACK (ui_mainwindow_action_help_translate
) },
236 { "About" , ICONNAME_ABOUT
, N_("_About") , NULL
, N_("About HomeBank") ,G_CALLBACK (ui_mainwindow_action_about
) },
239 static guint n_entries
= G_N_ELEMENTS (entries
);
242 static GtkToggleActionEntry toggle_entries
[] = {
243 /* name , icon-name, label, accelerator, tooltip, callback, is_active */
244 { "Toolbar" , NULL
, N_("_Toolbar") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_toolbar
), TRUE
},
245 { "Spending" , NULL
, N_("_Top spending") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_topspending
), TRUE
},
246 { "BottomLists", NULL
, N_("_Bottom Lists") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_upcoming
), TRUE
},
247 { "AsMinor" , NULL
, N_("Euro minor"), "<control>M", NULL
, G_CALLBACK (ui_mainwindow_action_toggle_minor
), FALSE
},
250 static guint n_toggle_entries
= G_N_ELEMENTS (toggle_entries
);
253 static const gchar
*ui_info
=
256 " <menubar name='MenuBar'>"
257 " <menu action='FileMenu'>"
258 " <menuitem action='New'/>"
259 " <menuitem action='Open'/>"
260 " <menuitem action='RecentMenu'/>"
262 " <menuitem action='Save'/>"
263 " <menuitem action='SaveAs'/>"
265 " <menuitem action='Import'/>"
266 /*" <menu action='ImportMenu'>"
267 " <menuitem action='ImportQIF'/>"
268 " <menuitem action='ImportOFX'/>"
269 " <menuitem action='ImportCSV'/>"
271 " <menuitem action='ExportQIF'/>"
272 // future: print to come here
274 " <menuitem action='Revert'/>"
275 " <menuitem action='OpenBak'/>"
277 " <menuitem action='Properties'/>"
279 " <menuitem action='Close'/>"
280 " <menuitem action='Quit'/>"
282 " <menu action='EditMenu'>"
283 " <menuitem action='Preferences'/>"
285 " <menu action='ViewMenu'>"
286 " <menuitem action='Toolbar'/>"
288 " <menuitem action='Spending'/>"
289 " <menuitem action='BottomLists'/>"
291 " <menuitem action='AsMinor'/>"
293 " <menu action='ManageMenu'>"
294 " <menuitem action='Account'/>"
295 " <menuitem action='Payee'/>"
296 " <menuitem action='Category'/>"
297 " <menuitem action='Archive'/>"
298 " <menuitem action='Budget'/>"
299 " <menuitem action='Assign'/>"
300 " <menuitem action='Currency'/>"
301 " <menuitem action='Tag'/>"
303 " <menu action='TxnMenu'>"
304 " <menuitem action='AddTxn'/>"
305 " <menuitem action='ShowTxn'/>"
306 " <menuitem action='ShowAllTxn'/>"
308 " <menuitem action='Scheduler'/>"
309 " <menuitem action='AddScheduled'/>"
311 " <menu action='ReportMenu'>"
312 " <menuitem action='RStatistics'/>"
313 " <menuitem action='RTrendTime'/>"
314 " <menuitem action='RBalance'/>"
315 " <menuitem action='RBudget'/>"
316 " <menuitem action='RVehiculeCost'/>"
318 " <menu action='ToolsMenu'>"
319 " <menuitem action='Welcome'/>"
320 " <menuitem action='FileStats'/>"
322 " <menuitem action='Anonymize'/>"
324 " <menu action='HelpMenu'>"
325 " <menuitem action='Contents'/>"
326 " <menuitem action='Online'/>"
328 " <menuitem action='Updates'/>"
329 " <menuitem action='ReleaseNotes'/>"
330 " <menuitem action='Problem'/>"
331 " <menuitem action='Translate'/>"
333 " <menuitem action='About'/>"
337 " <toolbar name='ToolBar'>"
338 " <toolitem action='New'/>"
339 // here Open + recent is coded
340 " <toolitem action='Save'/>"
342 " <toolitem action='Account'/>"
343 " <toolitem action='Payee'/>"
344 " <toolitem action='Category'/>"
345 " <toolitem action='Archive'/>"
346 " <toolitem action='Budget'/>"
347 " <toolitem action='Assign'/>"
348 " <toolitem action='Currency'/>"
350 " <toolitem action='ShowTxn'/>"
351 " <toolitem action='AddTxn'/>"
353 " <toolitem action='RStatistics'/>"
354 " <toolitem action='RTrendTime'/>"
355 " <toolitem action='RBalance'/>"
356 " <toolitem action='RBudget'/>"
357 " <toolitem action='RVehiculeCost'/>"
370 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
)
372 //struct hbfile_data *data;
378 DB( g_print("\n[ui-mainwindow] revert\n") );
380 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
382 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
383 title
= g_strdup_printf (
384 _("Revert unsaved changes to file '%s'?"), basename
);
387 _("- Changes made to the file will be permanently lost\n"
388 "- File will be reloaded from the last save (.xhb~)");
390 result
= ui_dialog_msg_confirm_alert(
391 GTK_WINDOW(GLOBALS
->mainwindow
),
400 if( result
== GTK_RESPONSE_OK
)
402 DB( g_print(" - should revert\n") );
404 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb~"));
405 ui_mainwindow_open_internal(widget
, NULL
);
406 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb"));
413 activate_url (GtkAboutDialog
*about
,
417 DB( g_print("activate url %s\n", link
) );
419 homebank_util_url_show (link
);
422 static void hbfile_about(void)
429 static const gchar
*artists
[] = {
434 static const gchar
*authors
[] = {
435 "Lead developer:\n" \
438 "Ga\xc3\xabtan LORIDANT (Maths formulas for charts)\n",
443 const gchar *documenters[] = {
449 static const gchar
*copyright
= "Copyright \xc2\xa9 1995-2019 - Maxime DOYEN";
453 version
= g_strdup_printf (PACKAGE_VERSION
"\n<small>Running against GTK+ %d.%d.%d</small>",
454 gtk_get_major_version (),
455 gtk_get_minor_version (),
456 gtk_get_micro_version ());
458 dialog
= gtk_about_dialog_new();
460 gtk_window_set_transient_for (GTK_WINDOW(dialog
), GTK_WINDOW(GLOBALS
->mainwindow
));
461 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
463 gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog
), g_get_application_name ());
464 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog
), version
);
465 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog
), copyright
);
466 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog
), _("Free, easy, personal accounting for everyone"));
467 gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG(dialog
), GTK_LICENSE_GPL_2_0
);
469 //gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(dialog), );
470 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog
), "http://homebank.free.fr");
471 gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(dialog
), "Visit the HomeBank website");
473 gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(dialog
), "homebank");
475 pathfilename
= g_build_filename(homebank_app_get_images_dir(), "splash.png", NULL
);
476 pixbuf
= gdk_pixbuf_new_from_file(pathfilename
, NULL
);
477 g_free(pathfilename
);
481 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog
), pixbuf
);
482 g_object_unref (pixbuf
);
485 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog
), authors
);
486 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog
), artists
);
487 //gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(dialog), );
488 //gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog), );
490 g_signal_connect (dialog
, "activate-link", G_CALLBACK (activate_url
), NULL
);
492 gtk_dialog_run (GTK_DIALOG (dialog
));
494 gtk_widget_destroy (dialog
);
501 /* hbfile action functions -------------------- */
502 static void ui_mainwindow_action_new(void)
504 GtkWidget
*widget
= GLOBALS
->mainwindow
;
506 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
508 //clear all, and init GLOBALS->xhb_filepath to default
509 ui_mainwindow_clear(widget
, GINT_TO_POINTER(TRUE
)); // GPOINTER_TO_INT(
510 ui_mainwindow_update(widget
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
512 ui_start_assistant();
513 //ui_hub_account_populate(GLOBALS->mainwindow, NULL);
514 //ui_hub_scheduled_populate(GLOBALS->mainwindow, NULL);
515 //ui_hub_spending_populate(GLOBALS->mainwindow, NULL);
519 static void ui_mainwindow_action_open(void)
521 ui_mainwindow_open(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
524 static void ui_mainwindow_action_openbak(void)
526 ui_mainwindow_open(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
529 static void ui_mainwindow_action_save(void)
531 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
534 static void ui_mainwindow_action_saveas(void)
536 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
539 static void ui_mainwindow_action_revert(void)
541 ui_mainwindow_revert(GLOBALS
->mainwindow
, NULL
);
544 static void ui_mainwindow_action_close(void)
546 GtkWidget
*widget
= GLOBALS
->mainwindow
;
548 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
550 //clear all, and init GLOBALS->xhb_filepath to default
551 ui_mainwindow_clear(widget
, GINT_TO_POINTER(TRUE
));
552 ui_mainwindow_update(widget
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
558 static void ui_mainwindow_action_quit(void)
562 //emulate the wm close button
563 g_signal_emit_by_name(GLOBALS
->mainwindow
, "delete-event", NULL
, &result
);
567 static void ui_mainwindow_action_file_statistics(void)
569 ui_dialog_file_statistics();
573 static void ui_mainwindow_action_properties(void)
575 create_defhbfile_dialog();
576 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
579 static void ui_mainwindow_action_anonymize(void)
585 title
= _("Are you sure you want to anonymize the file?");
588 _("Proceeding will anonymize any text, \n"
589 "like 'account x', 'payee y', 'memo z', ...");
591 result
= ui_dialog_msg_confirm_alert(
592 GTK_WINDOW(GLOBALS
->mainwindow
),
599 //if( result == GTK_RESPONSE_CANCEL )
601 if( result
== GTK_RESPONSE_OK
)
604 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
609 static void ui_mainwindow_action_defcurrency(void)
611 ui_cur_manage_dialog();
612 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
616 static void ui_mainwindow_action_defaccount(void)
618 ui_acc_manage_dialog();
620 //our global list has changed, so update the treeview
621 //todo: optimize this, should not call compute balance here
622 account_compute_balances ();
623 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
625 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
));
628 static void ui_mainwindow_action_defpayee(void)
630 ui_pay_manage_dialog();
631 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
634 static void ui_mainwindow_action_defcategory(void)
636 ui_cat_manage_dialog();
637 //todo:why refresh upcoming here??
638 //ui_mainwindow_populate_upcoming(GLOBALS->mainwindow, NULL);
639 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
643 //TODO: not ideal to do this
644 void ui_mainwindow_defarchive(Archive
*arc
)
646 struct hbfile_data
*data
;
649 data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
651 // upcoming list have direct pointer to the arc (which may change during edit)
652 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
));
653 gtk_list_store_clear (GTK_LIST_STORE(model
));
655 ui_arc_manage_dialog(arc
);
657 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
659 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
663 static void ui_mainwindow_action_defarchive(void)
665 ui_mainwindow_defarchive(NULL
);
669 static void ui_mainwindow_action_defbudget(void)
671 ui_bud_manage_dialog();
672 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
676 static void ui_mainwindow_action_defassign(void)
679 ui_asg_manage_dialog();
681 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
685 static void ui_mainwindow_action_deftag(void)
688 ui_tag_manage_dialog();
690 //ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
694 static void ui_mainwindow_action_preferences(void)
696 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
698 defpref_dialog_new();
699 if(!PREFS
->euro_active
)
701 GtkToggleAction
*action
= (GtkToggleAction
*)gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor");
703 gtk_toggle_action_set_active(action
, FALSE
);
704 ui_mainwindow_action_toggle_minor(action
);
706 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
+UF_REFRESHALL
));
711 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction
*action
)
713 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
715 PREFS
->wal_toolbar
= gtk_toggle_action_get_active(action
);
716 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
719 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction
*action
)
721 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
723 PREFS
->wal_upcoming
= gtk_toggle_action_get_active(action
);
724 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
727 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction
*action
)
729 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
731 PREFS
->wal_spending
= gtk_toggle_action_get_active(action
);
732 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
735 static void ui_mainwindow_action_toggle_minor(GtkToggleAction
*action
)
737 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
739 GLOBALS
->minor
= gtk_toggle_action_get_active(action
);
741 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
742 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
745 gtk_chart_show_minor(GTK_CHART(data
->RE_pie
), GLOBALS
->minor
);
747 ui_hub_spending_update(data
->window
, data
);
751 static void ui_mainwindow_action_showtransactions(GtkAction
*action
)
753 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
755 gboolean showall
= FALSE
;
759 DB( g_print(" actioname=%s\n", gtk_action_get_name(action
)) );
760 if( hb_string_compare((gchar
*)gtk_action_get_name(action
), "ShowAllTxn" ) == 0 )
765 if( data
->acc
&& showall
== FALSE
)
767 if( data
->acc
->window
== NULL
)
769 window
= register_panel_window_new(data
->acc
);
770 register_panel_window_init(window
, NULL
);
774 if(GTK_IS_WINDOW(data
->acc
->window
))
775 gtk_window_present(GTK_WINDOW(data
->acc
->window
));
780 if( GLOBALS
->alltxnwindow
== NULL
)
782 window
= register_panel_window_new(NULL
);
783 register_panel_window_init(window
, NULL
);
787 if(GTK_IS_WINDOW(GLOBALS
->alltxnwindow
))
788 gtk_window_present(GTK_WINDOW(GLOBALS
->alltxnwindow
));
794 static void ui_mainwindow_action_addtransactions(void)
796 ui_mainwindow_addtransactions(GLOBALS
->mainwindow
, NULL
);
799 static void ui_mainwindow_action_checkscheduled(void)
801 ui_hub_scheduled_postall(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
804 static void ui_mainwindow_action_statistic(void)
806 ui_repdist_window_new();
809 static void ui_mainwindow_action_trendtime(void)
811 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
813 ui_reptime_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
816 static void ui_mainwindow_action_budget(void)
818 repbudget_window_new();
821 static void ui_mainwindow_action_balance(void)
823 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
825 repbalance_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
828 static void ui_mainwindow_action_vehiclecost(void)
830 repcost_window_new();
833 static void ui_mainwindow_action_import(GtkAction
*action
)
836 gint filetype = FILETYPE_UNKNOWN;
838 name = gtk_action_get_name(action);
840 if( g_str_has_suffix (name, "QIF"))
841 filetype= FILETYPE_QIF;
843 if( g_str_has_suffix (name, "OFX"))
844 filetype= FILETYPE_OFX;
846 if( g_str_has_suffix (name, "CSV"))
847 filetype= FILETYPE_CSV_HB;*/
849 //DB( g_print("action %s type=%d\n", name, filetype) );
851 ui_import_assistant_new(NULL
);
856 static void ui_mainwindow_action_about(void)
864 static void ui_mainwindow_action_export(void)
868 if( ui_file_chooser_qif(NULL
, &filename
) == TRUE
)
870 hb_export_qif_account_all(filename
);
876 static void ui_mainwindow_action_help(void)
880 link
= g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP
, NULL
);
881 homebank_util_url_show (link
);
886 static void ui_mainwindow_action_help_releasenotes(void)
891 link
= g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog.txt", NULL
);
893 link
= g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog", NULL
);
895 homebank_util_url_show (link
);
900 //todo: move this to a ui-assist-welcome.c
902 static void ui_mainwindow_action_help_welcome1 (GtkButton
*button
, gpointer user_data
)
904 gtk_dialog_response (GTK_DIALOG(user_data
), 1);
907 static void ui_mainwindow_action_help_welcome2 (GtkButton
*button
, gpointer user_data
)
909 gtk_dialog_response (GTK_DIALOG(user_data
), 2);
912 static void ui_mainwindow_action_help_welcome3 (GtkButton
*button
, gpointer user_data
)
914 gtk_dialog_response (GTK_DIALOG(user_data
), 3);
917 static void ui_mainwindow_action_help_welcome4 (GtkButton
*button
, gpointer user_data
)
919 gtk_dialog_response (GTK_DIALOG(user_data
), 4);
922 static void ui_mainwindow_action_help_welcome5 (GtkButton
*button
, gpointer user_data
)
924 gtk_dialog_response (GTK_DIALOG(user_data
), 5);
927 void ui_mainwindow_action_help_welcome(void)
929 GtkWidget
*dialog
, *content_area
;
930 GtkWidget
*mainvbox
, *widget
, *label
;
932 dialog
= gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
933 GTK_WINDOW(GLOBALS
->mainwindow
),
939 content_area
= gtk_dialog_get_content_area(GTK_DIALOG (dialog
));
941 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
942 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, FALSE
, FALSE
, 0);
943 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
945 label
= make_label (_("HomeBank"), 0, 0);
946 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
947 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
949 label
= make_label (_("Free, easy, personal accounting for everyone"), 0, 0);
950 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
952 widget
= gtk_separator_new(GTK_ORIENTATION_HORIZONTAL
);
953 gtk_box_pack_start (GTK_BOX (content_area
), widget
, FALSE
, FALSE
, 0);
955 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, SPACING_MEDIUM
);
956 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, TRUE
, TRUE
, 0);
957 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
959 label
= make_label (_("What do you want to do:"), 0, 0);
960 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
961 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
963 widget
= gtk_button_new_with_mnemonic(_("Read HomeBank _Manual"));
964 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
965 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome1
), dialog
);
967 widget
= gtk_button_new_with_mnemonic(_("Configure _preferences"));
968 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
969 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome2
), dialog
);
971 widget
= gtk_button_new_with_mnemonic(_("Create a _new file"));
972 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
973 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome3
), dialog
);
975 widget
= gtk_button_new_with_mnemonic(_("_Open an existing file"));
976 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
977 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome4
), dialog
);
979 widget
= gtk_button_new_with_mnemonic(_("Open the _example file"));
980 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
981 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome5
), dialog
);
983 //connect all our signals
984 g_signal_connect (dialog
, "destroy", G_CALLBACK (gtk_widget_destroyed
), &dialog
);
986 gtk_widget_show_all (dialog
);
989 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
991 // cleanup and destroy
992 gtk_widget_destroy (dialog
);
994 // do appropriate action
998 ui_mainwindow_action_help();
1001 ui_mainwindow_action_preferences();
1004 ui_mainwindow_action_new();
1007 ui_mainwindow_action_open();
1010 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL
));
1011 ui_mainwindow_open_internal(GLOBALS
->mainwindow
, NULL
);
1018 static void ui_mainwindow_action_help_updates(void)
1020 const gchar
*link
= HOMEBANK_URL_HELP_UPDATES
;
1022 homebank_util_url_show (link
);
1026 static void ui_mainwindow_action_help_online(void)
1028 const gchar
*link
= HOMEBANK_URL_HELP_ONLINE
;
1030 homebank_util_url_show (link
);
1034 static void ui_mainwindow_action_help_translate(void)
1036 const gchar
*link
= HOMEBANK_URL_HELP_TRANSLATE
;
1038 homebank_util_url_show (link
);
1042 static void ui_mainwindow_action_help_problem(void)
1044 const gchar
*link
= HOMEBANK_URL_HELP_PROBLEM
;
1046 homebank_util_url_show (link
);
1050 /* hbfile functions -------------------- */
1056 static void ui_mainwindow_selection(GtkTreeSelection
*treeselection
, gpointer user_data
)
1058 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
1062 static void ui_mainwindow_close_openbooks(void)
1066 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
1068 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1071 Account
*item
= elt
->data
;
1075 gtk_widget_destroy(GTK_WIDGET(item
->window
));
1076 item
->window
= NULL
;
1079 elt
= g_list_next(elt
);
1090 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
)
1092 struct hbfile_data
*data
;
1093 gboolean file_clear
= GPOINTER_TO_INT(user_data
);
1095 DB( g_print("\n[ui-mainwindow] clear\n") );
1097 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1099 // Close opened account window
1101 ui_mainwindow_close_openbooks();
1102 gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_acc
))));
1103 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
))));
1104 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_top
))));
1106 data
->showall
= FALSE
;
1107 ui_hub_account_setup(data
);
1109 hbfile_cleanup(file_clear
);
1110 hbfile_setup(file_clear
);
1116 ** add some transactions directly
1118 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
)
1120 struct hbfile_data
*data
;
1124 gint account
, count
;
1126 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1128 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1130 /* init the transaction */
1131 date
= homebank_app_date_get_julian();
1135 if(data
->acc
!= NULL
)
1136 account
= data
->acc
->key
;
1138 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
, FALSE
, account
);
1140 while(result
== HB_RESPONSE_ADD
|| result
== HB_RESPONSE_ADDKEEP
)
1144 /* fill in the transaction */
1145 if( result
== HB_RESPONSE_ADD
)
1147 ope
= da_transaction_malloc();
1149 ope
->kacc
= account
;
1151 if( PREFS
->heritdate
== FALSE
) //fix: 318733
1152 ope
->date
= GLOBALS
->today
;
1154 da_transaction_set_default_template(ope
);
1157 // normally we can't be in addkeep without initialized ope with add
1159 deftransaction_set_transaction(window
, ope
);
1161 result
= gtk_dialog_run (GTK_DIALOG (window
));
1163 DB( g_print(" - dialog result is %d\n", result
) );
1165 if(result
== HB_RESPONSE_ADD
|| result
== HB_RESPONSE_ADDKEEP
|| result
== GTK_RESPONSE_ACCEPT
)
1167 deftransaction_get(window
, NULL
);
1168 transaction_add(GTK_WINDOW(GLOBALS
->mainwindow
), ope
);
1170 DB( g_print(" - added 1 transaction to %d\n", ope
->kacc
) );
1172 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1175 //todo: still usefull ? store last date
1179 if( result
== HB_RESPONSE_ADD
)
1181 da_transaction_free(ope
);
1188 deftransaction_dispose(window
, NULL
);
1189 gtk_widget_destroy (window
);
1191 /* todo optimize this */
1194 GLOBALS
->changes_count
+= count
;
1195 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
1200 gboolean
ui_mainwindow_open_backup_check_confirm(gchar
*filepath
)
1202 gboolean retval
= FALSE
;
1203 gchar
*basename
, *secondtext
;
1206 basename
= g_path_get_basename(filepath
);
1207 secondtext
= g_strdup_printf (
1208 _("Your are about to open the backup file '%s'.\n\nAre you sure you want to do this ?"), basename
);
1210 result
= ui_dialog_msg_confirm_alert(
1211 GTK_WINDOW(GLOBALS
->mainwindow
),
1212 _("Open the backup file ?"),
1220 if( result
== GTK_RESPONSE_OK
)
1230 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
)
1232 //struct hbfile_data *data;
1233 gboolean bakmode
= GPOINTER_TO_INT(user_data
);;
1234 gboolean doopen
= TRUE
;
1235 gchar
*filename
= NULL
;
1237 DB( g_print("\n[ui-mainwindow] open\n") );
1239 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1241 //#1791554 do ask for save confirm
1242 if( bakmode
!= TRUE
)
1243 doopen
= ui_dialog_msg_savechanges(widget
,NULL
);
1245 if( doopen
== TRUE
)
1247 if( ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN
, &filename
, bakmode
) == TRUE
)
1249 //#1710955 test for backup open
1250 if( hbfile_file_isbackup(filename
) )
1252 if( ui_mainwindow_open_backup_check_confirm(filename
) == TRUE
)
1254 GLOBALS
->hbfile_is_bak
= TRUE
;
1263 hbfile_change_filepath(filename
);
1264 ui_mainwindow_open_internal(widget
, NULL
);
1271 * open the file stored in GLOBALS->xhb_filepath
1273 void ui_mainwindow_open_internal(GtkWidget
*widget
, gpointer user_data
)
1275 struct hbfile_data
*data
;
1278 DB( g_print("\n[ui-mainwindow] open internal\n") );
1280 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1282 if( GLOBALS
->xhb_filepath
!= NULL
)
1284 DB( g_print(" - filename: '%s'\n", GLOBALS
->xhb_filepath
) );
1286 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
1287 GLOBALS
->hbfile_is_new
= FALSE
;
1289 r
= homebank_load_xml(GLOBALS
->xhb_filepath
);
1292 DB( g_print(" - file loaded ok : rcode=%d\n", r
) );
1294 GLOBALS
->xhb_timemodified
= hbfile_file_get_time_modified(GLOBALS
->xhb_filepath
);
1295 hbfile_file_hasrevert(GLOBALS
->xhb_filepath
);
1297 if(PREFS
->appendscheduled
)
1298 scheduled_post_all_pending();
1300 if(PREFS
->do_update_currency
)
1301 ui_cur_manage_dialog_update_currencies(GTK_WINDOW(GLOBALS
->mainwindow
));
1303 homebank_lastopenedfiles_save();
1305 //todo: delete this after computing done at xml read
1306 account_compute_balances();
1308 ui_mainwindow_recent_add(data
, GLOBALS
->xhb_filepath
);
1312 gchar
*msg
= _("Unknown error");
1317 msg
= _("I/O error for file '%s'.");
1319 case XML_FILE_ERROR
:
1320 msg
= _("The file '%s' is not a valid HomeBank file.");
1322 case XML_VERSION_ERROR
:
1323 msg
= _("The file '%s' was saved with a higher version of HomeBank\nand cannot be loaded by the current version.");
1327 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1330 GLOBALS
->xhb_filepath
1333 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
1337 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1338 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1339 ui_hub_spending_populate(GLOBALS
->mainwindow
, NULL
);
1340 ui_hub_transaction_populate(data
);
1342 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1352 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
)
1354 struct hbfile_data
*data
;
1355 gboolean saveas
= GPOINTER_TO_INT(user_data
);
1356 gchar
*filename
= NULL
;
1359 DB( g_print("\n[ui-mainwindow] save\n") );
1361 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1363 if( GLOBALS
->hbfile_is_new
== TRUE
)
1366 //#1710955 test for backup open
1367 if( GLOBALS
->hbfile_is_bak
== TRUE
)
1369 //todo: later for backup, should also remove datetime and .bak
1370 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb"));
1376 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE
, &filename
, FALSE
) == TRUE
)
1378 DB( g_print(" + should save as '%s'\n", filename
) );
1379 homebank_file_ensure_xhb(filename
);
1380 homebank_backup_current_file();
1381 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1382 GLOBALS
->hbfile_is_new
= FALSE
;
1383 GLOBALS
->hbfile_is_bak
= FALSE
;
1390 guint64 time_modified
= hbfile_file_get_time_modified (GLOBALS
->xhb_filepath
);
1391 gint result
= GTK_RESPONSE_OK
;
1393 DB( g_print(" + should quick save '%s'\n + time: open=%lu :: now=%lu\n", GLOBALS
->xhb_filepath
, GLOBALS
->xhb_timemodified
, time_modified
) );
1395 if( GLOBALS
->xhb_timemodified
!= time_modified
)
1397 result
= ui_dialog_msg_confirm_alert(
1398 GTK_WINDOW(GLOBALS
->mainwindow
),
1399 _("The file has been modified since reading it."),
1400 _("If you save it, all the external changes could be lost. Save it anyway?"),
1404 if( result
!= GTK_RESPONSE_OK
)
1408 DB( g_print(" + saving...\n") );
1409 homebank_file_ensure_xhb(NULL
);
1410 homebank_backup_current_file();
1411 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1416 DB( g_print(" + OK...\n") );
1417 GLOBALS
->changes_count
= 0;
1418 GLOBALS
->xhb_timemodified
= hbfile_file_get_time_modified (GLOBALS
->xhb_filepath
);
1419 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1423 gchar
*msg
= _("I/O error for file '%s'.");
1425 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1428 GLOBALS
->xhb_filepath
1434 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
)
1436 struct hbfile_data
*data
;
1439 DB( g_print("\n[ui-mainwindow] update %p\n", user_data
) );
1441 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1442 //data = INST_DATA(widget);
1444 flags
= GPOINTER_TO_INT(user_data
);
1446 /* set window title */
1447 if(flags
& UF_TITLE
)
1452 DB( g_print(" 1: wintitle %p\n", data
->wintitle
) );
1454 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
1456 DB( g_print(" global changes: %d\n", GLOBALS
->changes_count
) );
1458 g_free(data
->wintitle
);
1460 changed
= (GLOBALS
->changes_count
> 0) ? "*" : "";
1463 data
->wintitle
= g_strdup_printf("%s%s (%d)- %s - " PROGNAME
, changed
, basename
, GLOBALS
->changes_count
, GLOBALS
->owner
);
1465 data
->wintitle
= g_strdup_printf("%s%s - %s - " PROGNAME
, changed
, basename
, GLOBALS
->owner
);
1468 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), data
->wintitle
);
1473 /* update disabled things */
1474 if(flags
& UF_SENSITIVE
)
1476 GtkTreeSelection
*selection
;
1477 GtkTreeModel
*model
;
1480 gboolean active
,sensitive
;
1482 DB( g_print(" 2: disabled, opelist count\n") );
1487 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
));
1488 active
= gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1494 path
= gtk_tree_model_get_path(model
, &iter
);
1495 depth
= gtk_tree_path_get_depth(path
);
1499 DB( g_print(" depth is %d\n", depth
) );
1501 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1508 DB( g_print(" changes %d - new %d\n", GLOBALS
->changes_count
, GLOBALS
->hbfile_is_new
) );
1511 sensitive
= (GLOBALS
->changes_count
!= 0 ) ? TRUE
: FALSE
;
1512 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Save"), sensitive
);
1515 sensitive
= ( (GLOBALS
->changes_count
!= 0) && GLOBALS
->xhb_hasrevert
) ? TRUE
: FALSE
;
1516 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Revert"), sensitive
);
1517 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/OpenBak"), sensitive
);
1520 sensitive
= GLOBALS
->define_off
== 0 ? TRUE
: FALSE
;
1521 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Account"), sensitive
);
1522 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Payee"), sensitive
);
1523 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Category"), sensitive
);
1524 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1525 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/EditMenu/Preferences"), sensitive
);
1527 // empty account list: disable Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
1528 sensitive
= da_acc_length() > 0 ? TRUE
: FALSE
;
1529 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Close"), sensitive
);
1530 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Archive"), sensitive
);
1531 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddTxn"), sensitive
);
1532 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowTxn"), sensitive
);
1533 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RStatistics"), sensitive
);
1534 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RTrendTime"), sensitive
);
1535 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBudget"), sensitive
);
1536 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBalance"), sensitive
);
1537 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RVehiculeCost"), sensitive
);
1539 // empty category list: disable Budget
1540 sensitive
= da_cat_length() > 1 ? TRUE
: FALSE
;
1541 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1543 //#1501129 no need to disable, P & C can be created from assign dialog
1544 //sensitive = ((da_cat_length() > 1) || (da_pay_length() > 1)) ? TRUE : FALSE;
1545 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Assign"), sensitive);
1547 // empty archive list: disable scheduled check
1548 sensitive
= g_list_length(GLOBALS
->arc_list
) > 0 ? TRUE
: FALSE
;
1549 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddScheduled"), sensitive
);
1551 // no active account: disable Edit, Over
1553 /* sensitive = (active == TRUE ) ? TRUE : FALSE;
1554 if(data->acc && data->acc->window != NULL)
1556 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/ShowTxn"), sensitive);
1560 /* update toolbar, list */
1561 if(flags
& UF_VISUAL
)
1563 DB( g_print(" 8: visual\n") );
1565 if(PREFS
->toolbar_style
== 0)
1566 gtk_toolbar_unset_style(GTK_TOOLBAR(data
->toolbar
));
1568 gtk_toolbar_set_style(GTK_TOOLBAR(data
->toolbar
), PREFS
->toolbar_style
-1);
1570 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_acc
), PREFS
->grid_lines
);
1571 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
1573 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_upc
), PREFS
->grid_lines
);
1574 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
1576 DB( g_print(" - show toolbar=%d\n", PREFS
->wal_toolbar
) );
1577 if(PREFS
->wal_toolbar
)
1578 gtk_widget_show(GTK_WIDGET(data
->toolbar
));
1580 gtk_widget_hide(GTK_WIDGET(data
->toolbar
));
1583 DB( g_print(" - show top_spending=%d\n", PREFS
->wal_spending
) );
1585 hbtk_combo_box_set_active_id(GTK_COMBO_BOX_TEXT(data
->CY_range
), PREFS
->date_range_wal
);
1587 if(PREFS
->wal_spending
)
1588 gtk_widget_show(GTK_WIDGET(data
->GR_top
));
1590 gtk_widget_hide(GTK_WIDGET(data
->GR_top
));
1594 DB( g_print(" - show upcoming=%d\n", PREFS
->wal_upcoming
) );
1595 if(PREFS
->wal_upcoming
)
1596 gtk_widget_show(GTK_WIDGET(data
->GR_upc
));
1598 gtk_widget_hide(GTK_WIDGET(data
->GR_upc
));
1600 DB( g_print(" minor %d\n", PREFS
->euro_active
) );
1601 gtk_action_set_visible(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor"), PREFS
->euro_active
);
1604 /* update balances */
1605 if(flags
& UF_BALANCE
)
1608 DB( g_print(" 4: balances\n") );
1610 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
1612 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
1615 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[0]), data->bank, minor);
1616 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[1]), data->today, minor);
1617 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[2]), data->future, minor);
1621 if(flags
& UF_REFRESHALL
)
1623 DB( g_print(" 16: refreshall\n") );
1625 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1626 ui_hub_spending_populate(GLOBALS
->mainwindow
, NULL
);
1627 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1628 ui_hub_transaction_populate(data
);
1637 ui_mainwindow_onRowActivated (GtkTreeView
*treeview
,
1639 GtkTreeViewColumn
*col
,
1642 GtkTreeModel
*model
;
1645 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
1647 model
= gtk_tree_view_get_model(treeview
);
1649 if (gtk_tree_model_get_iter(model
, &iter
, path
))
1653 gtk_tree_model_get(model
, &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1658 DB( g_print ("Double-clicked row contains name %s\n", acc
->name
) );
1660 ui_mainwindow_action_showtransactions(NULL
);
1668 static void ui_mainwindow_destroy(GtkTreeView
*treeview
, gpointer user_data
)
1670 DB( g_print("\n[ui-mainwindow] destroy\n") );
1678 static gboolean
ui_mainwindow_dispose(GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
1680 struct hbfile_data
*data
= user_data
;
1681 struct WinGeometry
*wg
;
1682 gboolean retval
= FALSE
;
1684 DB( g_print("\n[ui-mainwindow] delete-event\n") );
1686 //store position and size
1687 wg
= &PREFS
->wal_wg
;
1688 gtk_window_get_position(GTK_WINDOW(widget
), &wg
->l
, &wg
->t
);
1689 gtk_window_get_size(GTK_WINDOW(widget
), &wg
->w
, &wg
->h
);
1690 GdkWindow
*gdk_window
= gtk_widget_get_window(GTK_WIDGET(widget
));
1691 GdkWindowState state
= gdk_window_get_state(gdk_window
);
1692 wg
->s
= (state
& GDK_WINDOW_STATE_MAXIMIZED
) ? 1 : 0;
1693 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
) );
1695 PREFS
->wal_vpaned
= gtk_paned_get_position(GTK_PANED(data
->vpaned
));
1696 PREFS
->wal_hpaned
= gtk_paned_get_position(GTK_PANED(data
->hpaned
));
1697 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
1699 if(PREFS
->pnl_list_tab
)
1700 g_free(PREFS
->pnl_list_tab
);
1701 PREFS
->pnl_list_tab
= g_strdup(gtk_stack_get_visible_child_name(GTK_STACK(data
->stack
)));
1704 if(ui_dialog_msg_savechanges(widget
, NULL
) == FALSE
)
1710 //todo: retval is useless and below should move to destroy
1712 gtk_widget_destroy(data
->LV_top
);
1714 g_free(data
->wintitle
);
1715 da_flt_free(data
->filter
);
1721 //TRUE:stop other handlers from being invoked for the event | FALSE: propagate
1726 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser
*chooser
, struct hbfile_data
*data
)
1729 GError
*error
= NULL
;
1731 uri
= gtk_recent_chooser_get_current_uri (chooser
);
1733 path
= g_filename_from_uri (uri
, NULL
, NULL
);
1736 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
1737 g_error_free (error
);
1741 if( ui_dialog_msg_savechanges(data
->window
, NULL
) == TRUE
)
1748 gpw_recent_remove (gpw, path);
1752 hbfile_change_filepath(path
);
1753 ui_mainwindow_open_internal(data
->window
, NULL
);
1763 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
)
1765 GtkRecentData
*recent_data
;
1767 GError
*error
= NULL
;
1769 DB( g_print("\n[ui-mainwindow] recent_add\n") );
1771 DB( g_print(" - file has .xhb suffix = %d\n", g_str_has_suffix (path
, ".xhb") ) );
1773 if( g_str_has_suffix (path
, ".xhb") == FALSE
) //ignore reverted file
1776 uri
= g_filename_to_uri (path
, NULL
, &error
);
1779 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
1780 g_error_free (error
);
1784 recent_data
= g_slice_new (GtkRecentData
);
1786 recent_data
->display_name
= NULL
;
1787 recent_data
->description
= NULL
;
1788 recent_data
->mime_type
= "application/x-homebank";
1789 recent_data
->app_name
= (gchar
*) g_get_application_name ();
1790 recent_data
->app_exec
= g_strjoin (" ", g_get_prgname (), "%u", NULL
);
1791 recent_data
->groups
= NULL
;
1792 recent_data
->is_private
= FALSE
;
1794 if (!gtk_recent_manager_add_full (data
->recent_manager
,
1798 g_warning ("Unable to add '%s' to the list of recently used documents", uri
);
1802 g_free (recent_data
->app_exec
);
1803 g_slice_free (GtkRecentData
, recent_data
);
1816 static GtkTargetEntry drop_types
[] =
1818 {"text/uri-list", 0, TARGET_URI_LIST
}
1821 static void ui_mainwindow_drag_data_received (GtkWidget
*widget
,
1822 GdkDragContext
*context
,
1824 GtkSelectionData
*selection_data
,
1825 guint info
, guint time
, GtkWindow
*window
)
1827 gchar
**uris
, **str
;
1829 gint n_uris
, filetype
, slen
;
1830 GError
*error
= NULL
;
1832 if (info
!= TARGET_URI_LIST
)
1835 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
1837 /* On MS-Windows, it looks like `selection_data->data' is not NULL terminated. */
1838 slen
= gtk_selection_data_get_length(selection_data
);
1839 newseldata
= g_new (gchar
, slen
+ 1);
1840 memcpy (newseldata
, gtk_selection_data_get_data(selection_data
), slen
);
1841 newseldata
[slen
] = 0;
1842 //DB( g_print(" - seldata ='%s'\n", gtk_selection_data_get_data(selection_data) ) );
1843 //DB( g_print(" - newseldata ='%s'\n", newseldata ) );
1845 uris
= g_uri_list_extract_uris (newseldata
);
1846 n_uris
= g_strv_length(uris
);
1847 DB( g_print(" - dragged %d files (len=%d)\n", n_uris
, slen
) );
1851 //single file: check for xhb
1854 filetype
= hb_filename_type_get_by_extension(*uris
);
1856 DB( g_print(" - filetype is homebank (%d)\n", filetype
) );
1858 if( filetype
== FILETYPE_HOMEBANK
)
1860 gchar
*path
= g_filename_from_uri (*uris
, NULL
, &error
);
1864 DB( g_print(" - path is '%s'\n", path
) );
1865 hbfile_change_filepath(g_strdup(path
));
1866 ui_mainwindow_open_internal(GTK_WIDGET(window
), NULL
);
1871 g_warning ("Could not convert uri to local path: %s", error
->message
);
1872 g_error_free (error
);
1876 /* we no more manage error here
1877 ui_dialog_msg_infoerror(GTK_WINDOW(window), GTK_MESSAGE_ERROR,
1879 _("The file %s is not a valid HomeBank file."),
1884 //collect known filetype to import
1885 DB( g_print(" - collect %d files\n", n_uris
) );
1887 gchar
**paths
= g_new (gchar
*, n_uris
+ 1);
1889 for (str
= uris
; *str
; str
++)
1891 filetype
= hb_filename_type_get_by_extension(*str
);
1892 if( filetype
!= FILETYPE_HOMEBANK
&& filetype
!= FILETYPE_UNKNOWN
)
1894 gchar
*path
= g_filename_from_uri (*str
, NULL
, NULL
);
1898 DB( g_print(" - append %d '%s'\n", slen
, path
) );
1899 paths
[slen
++] = path
;
1907 ui_import_assistant_new( paths
);
1916 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
)
1918 GtkWidget
*recent_menu
;
1919 GtkRecentFilter
*filter
;
1921 recent_menu
= gtk_recent_chooser_menu_new_for_manager (manager
);
1922 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu
), FALSE
);
1923 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu
), GTK_RECENT_SORT_MRU
);
1924 //todo: add a user pref for this
1925 gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER (recent_menu
), 10);
1926 gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu
), FALSE
);
1927 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_menu), TRUE);
1929 filter
= gtk_recent_filter_new ();
1930 //gtk_recent_filter_add_application (filter, g_get_application_name());
1931 gtk_recent_filter_add_pattern (filter
, "*.[Xx][Hh][Bb]");
1932 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu
), filter
);
1938 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data
*data
, GtkWidget
*mainvbox
)
1940 GtkUIManager
*manager
;
1941 GtkActionGroup
*actions
;
1943 GError
*error
= NULL
;
1945 manager
= gtk_ui_manager_new ();
1946 data
->manager
= manager
;
1948 gtk_window_add_accel_group (GTK_WINDOW (data
->window
),
1949 gtk_ui_manager_get_accel_group(manager
));
1951 actions
= gtk_action_group_new ("MainWindow");
1952 gtk_action_group_set_translation_domain(actions
, GETTEXT_PACKAGE
);
1954 gtk_action_group_add_actions (actions
,
1959 gtk_action_group_add_toggle_actions (actions
,
1964 gtk_ui_manager_insert_action_group (data
->manager
, actions
, 0);
1965 g_object_unref (actions
);
1966 data
->actions
= actions
;
1968 /* set short labels to use in the toolbar */
1969 action
= gtk_action_group_get_action(actions
, "Open");
1970 g_object_set(action
, "short_label", _("Open"), NULL
);
1972 //action = gtk_action_group_get_action(action_group, "Save");
1973 //g_object_set(action, "is_important", TRUE, NULL);
1975 action
= gtk_action_group_get_action(actions
, "Account");
1976 g_object_set(action
, "short_label", _("Account"), NULL
);
1978 action
= gtk_action_group_get_action(actions
, "Payee");
1979 g_object_set(action
, "short_label", _("Payee"), NULL
);
1981 action
= gtk_action_group_get_action(actions
, "Category");
1982 g_object_set(action
, "short_label", _("Category"), NULL
);
1984 action
= gtk_action_group_get_action(actions
, "Archive");
1985 //TRANSLATORS: an archive is stored transaction buffers (kind of bookmark to prefill manual insertion)
1986 g_object_set(action
, "short_label", _("Archive"), NULL
);
1988 action
= gtk_action_group_get_action(actions
, "Budget");
1989 g_object_set(action
, "short_label", _("Budget"), NULL
);
1991 action
= gtk_action_group_get_action(actions
, "ShowTxn");
1992 g_object_set(action
, "short_label", _("Show"), NULL
);
1994 action
= gtk_action_group_get_action(actions
, "AddTxn");
1995 g_object_set(action
, "is_important", TRUE
, "short_label", _("Add"), NULL
);
1997 action
= gtk_action_group_get_action(actions
, "RStatistics");
1998 g_object_set(action
, "short_label", _("Statistics"), NULL
);
2000 action
= gtk_action_group_get_action(actions
, "RBudget");
2001 g_object_set(action
, "short_label", _("Budget"), NULL
);
2003 action
= gtk_action_group_get_action(actions
, "RBalance");
2004 g_object_set(action
, "short_label", _("Balance"), NULL
);
2006 action
= gtk_action_group_get_action(actions
, "RVehiculeCost");
2007 g_object_set(action
, "short_label", _("Vehicle cost"), NULL
);
2009 /* now load the UI definition */
2010 gtk_ui_manager_add_ui_from_string (data
->manager
, ui_info
, -1, &error
);
2013 g_message ("Building menus failed: %s", error
->message
);
2014 g_error_free (error
);
2018 data
->recent_manager
= gtk_recent_manager_get_default ();
2020 data
->menubar
= gtk_ui_manager_get_widget (manager
, "/MenuBar");
2021 gtk_box_pack_start (GTK_BOX (mainvbox
),
2027 /* recent files menu */
2028 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2030 g_signal_connect (data
->recent_menu
,
2032 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2035 GtkWidget
*widget
= gtk_ui_manager_get_widget (data
->manager
, "/MenuBar/FileMenu/RecentMenu");
2036 gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget
), data
->recent_menu
);
2039 data
->toolbar
= gtk_ui_manager_get_widget (manager
, "/ToolBar");
2040 gtk_box_pack_start (GTK_BOX (mainvbox
),
2046 /* add the custom Open button to the toolbar */
2047 GtkWidget
*image
= gtk_image_new_from_icon_name (ICONNAME_HB_FILE_OPEN
, GTK_ICON_SIZE_BUTTON
);
2048 GtkToolItem
*open_button
= gtk_menu_tool_button_new(image
, _("_Open"));
2049 gtk_tool_item_set_tooltip_text (open_button
, _("Open a file"));
2051 GtkWidget
*recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2052 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button
), recent_menu
);
2053 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button
), _("Open a recently used file"));
2055 g_signal_connect (recent_menu
,
2057 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2060 action
= gtk_action_group_get_action (data
->actions
, "Open");
2061 g_object_set (action
, "short_label", _("Open"), NULL
);
2062 //gtk_action_connect_proxy (action, GTK_WIDGET (open_button));
2063 gtk_activatable_set_related_action (GTK_ACTIVATABLE (open_button
), action
);
2065 gtk_toolbar_insert (GTK_TOOLBAR (data
->toolbar
), open_button
, 1);
2071 ** the window creation
2073 GtkWidget
*create_hbfile_window(GtkWidget
*do_widget
)
2075 struct hbfile_data
*data
;
2076 struct WinGeometry
*wg
;
2077 GtkWidget
*mainvbox
, *vbox
, *box
, *vpaned
, *hpaned
, *sidebar
, *stack
;
2078 GtkWidget
*widget
, *page
;
2082 DB( g_print("\n[ui-mainwindow] create main window\n") );
2084 data
= g_malloc0(sizeof(struct hbfile_data
));
2085 if(!data
) return NULL
;
2087 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
2089 //store our window private data
2090 g_object_set_data(G_OBJECT(window
), "inst_data", (gpointer
)data
);
2091 DB( g_print(" - new window=%p, inst_data=%p\n", window
, data
) );
2093 // this is our mainwindow, so store it to GLOBALS data
2094 data
->window
= window
;
2095 GLOBALS
->mainwindow
= window
;
2097 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2098 gtk_container_add (GTK_CONTAINER (window
), mainvbox
);
2100 ui_mainwindow_create_menu_bar_and_toolbar (data
, mainvbox
);
2102 #if HB_UNSTABLE_SHOW == TRUE
2103 GtkWidget
*bar
, *label
;
2105 bar
= gtk_info_bar_new ();
2106 gtk_box_pack_start (GTK_BOX (mainvbox
), bar
, FALSE
, FALSE
, 0);
2107 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar
), GTK_MESSAGE_WARNING
);
2108 label
= make_label(NULL
, 0.5, 0.5);
2109 gtk_label_set_markup (GTK_LABEL(label
), "Unstable Development Version");
2110 gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar
))), label
, FALSE
, FALSE
, 0);
2113 /* Add the main area */
2114 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2115 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
2116 gtk_box_pack_start (GTK_BOX (mainvbox
), vbox
, TRUE
, TRUE
, 0);
2118 vpaned
= gtk_paned_new(GTK_ORIENTATION_VERTICAL
);
2119 data
->vpaned
= vpaned
;
2120 gtk_box_pack_start (GTK_BOX (vbox
), vpaned
, TRUE
, TRUE
, 0);
2122 hpaned
= gtk_paned_new(GTK_ORIENTATION_HORIZONTAL
);
2123 data
->hpaned
= hpaned
;
2124 gtk_paned_pack1 (GTK_PANED(vpaned
), hpaned
, FALSE
, FALSE
);
2126 widget
= ui_hub_account_create(data
);
2127 //gtk_widget_set_size_request (widget, 100, -1);
2128 gtk_paned_pack1 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
2130 widget
= ui_hub_spending_create(data
);
2131 //gtk_widget_set_size_request (widget, -1, 100);
2132 gtk_paned_pack2 (GTK_PANED(hpaned
), widget
, TRUE
, FALSE
);
2134 box
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
2136 gtk_paned_pack2 (GTK_PANED(vpaned
), box
, TRUE
, FALSE
);
2138 sidebar
= gtk_stack_sidebar_new ();
2139 gtk_box_pack_start (GTK_BOX (box
), sidebar
, FALSE
, FALSE
, 0);
2141 stack
= gtk_stack_new ();
2142 //gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN);
2143 gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar
), GTK_STACK (stack
));
2144 data
->stack
= stack
;
2145 gtk_box_pack_start (GTK_BOX (box
), stack
, TRUE
, TRUE
, 0);
2147 page
= ui_hub_scheduled_create(data
);
2148 gtk_stack_add_titled (GTK_STACK (stack
), page
, "sched", _("Scheduled"));
2149 //gtk_paned_pack2 (GTK_PANED(vpaned), widget, TRUE, FALSE);
2151 page
= ui_hub_transaction_create(data
, HUB_TXN_TYPE_FUTURE
);
2152 gtk_stack_add_titled (GTK_STACK (stack
), page
, "futur", _("Future"));
2154 page
= ui_hub_transaction_create(data
, HUB_TXN_TYPE_REMIND
);
2155 gtk_stack_add_titled (GTK_STACK (stack
), page
, "remin", _("Remind"));
2158 //setup, init and show window
2159 wg
= &PREFS
->wal_wg
;
2162 gtk_window_move(GTK_WINDOW(window
), wg
->l
, wg
->t
);
2163 gtk_window_resize(GTK_WINDOW(window
), wg
->w
, wg
->h
);
2166 gtk_window_maximize(GTK_WINDOW(window
));
2168 gtk_widget_show_all (window
);
2170 //#1662197/1660910 moved after resize/show
2171 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
2173 if(PREFS
->wal_hpaned
> 0)
2174 gtk_paned_set_position(GTK_PANED(data
->hpaned
), PREFS
->wal_hpaned
);
2175 if(PREFS
->wal_vpaned
> 0)
2176 gtk_paned_set_position(GTK_PANED(data
->vpaned
), PREFS
->wal_vpaned
);
2178 if( PREFS
->pnl_list_tab
!= NULL
)
2179 gtk_stack_set_visible_child_name (GTK_STACK(data
->stack
), PREFS
->pnl_list_tab
);
2182 //todo: move this elsewhere
2183 DB( g_print(" - setup stuff\n") );
2185 data
->filter
= da_flt_malloc();
2186 filter_reset(data
->filter
);
2187 hbtk_combo_box_set_active_id(GTK_COMBO_BOX_TEXT(data
->CY_range
), PREFS
->date_range_wal
);
2189 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Toolbar");
2190 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_toolbar
);
2191 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Spending");
2192 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_spending
);
2193 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/BottomLists");
2194 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_upcoming
);
2196 /* Drag and drop support, set targets to NULL because we add the
2197 default uri_targets below */
2199 /* support for opening a file by dragging onto the project window */
2200 gtk_drag_dest_set (GTK_WIDGET (window
),
2201 GTK_DEST_DEFAULT_ALL
,
2203 G_N_ELEMENTS (drop_types
),
2206 g_signal_connect (G_OBJECT (window
), "drag-data-received",
2207 G_CALLBACK (ui_mainwindow_drag_data_received
), window
);
2209 //connect all our signals
2210 DB( g_print(" - connect signals\n") );
2212 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
)), "changed", G_CALLBACK (ui_mainwindow_selection
), NULL
);
2213 g_signal_connect (GTK_TREE_VIEW(data
->LV_acc
), "row-activated", G_CALLBACK (ui_mainwindow_onRowActivated
), GINT_TO_POINTER(2));
2215 /* GtkWindow events */
2216 g_signal_connect (window
, "delete-event", G_CALLBACK (ui_mainwindow_dispose
), (gpointer
)data
);
2217 g_signal_connect (window
, "destroy", G_CALLBACK (ui_mainwindow_destroy
), NULL
);
2219 //gtk_action_group_set_sensitive(data->actions, FALSE);