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(void);
112 static void ui_mainwindow_action_showalltransactions(void);
114 static void ui_mainwindow_action_addtransactions(void);
115 static void ui_mainwindow_action_checkscheduled(void);
117 static void ui_mainwindow_action_statistic(void);
118 static void ui_mainwindow_action_trendtime(void);
119 static void ui_mainwindow_action_budget(void);
120 static void ui_mainwindow_action_balance(void);
121 static void ui_mainwindow_action_vehiclecost(void);
123 static void ui_mainwindow_action_import(GtkAction
*action
);
124 static void ui_mainwindow_action_export(void);
125 static void ui_mainwindow_action_anonymize(void);
126 static void ui_mainwindow_action_file_statistics(void);
128 static void ui_mainwindow_action_help(void);
129 void ui_mainwindow_action_help_welcome(void);
130 static void ui_mainwindow_action_help_online(void);
131 static void ui_mainwindow_action_help_updates(void);
132 static void ui_mainwindow_action_help_releasenotes(void);
133 static void ui_mainwindow_action_help_translate(void);
134 static void ui_mainwindow_action_help_problem(void);
135 static void ui_mainwindow_action_about(void);
138 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
);
140 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
);
142 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
);
143 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
);
144 void ui_mainwindow_action(GtkWidget
*widget
, gpointer user_data
);
145 void ui_mainwindow_toggle_minor(GtkWidget
*widget
, gpointer user_data
);
146 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
);
148 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
);
149 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
);
150 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
152 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
155 static GtkActionEntry entries
[] = {
157 /* name, icon-name, label */
159 { "FileMenu" , NULL
, N_("_File"), NULL
, NULL
, NULL
},
160 //{ "ImportMenu" , NULL, N_("_Import"), NULL, NULL, NULL },
161 { "RecentMenu" , NULL
, N_("Open _Recent"), NULL
, NULL
, NULL
},
162 { "EditMenu" , NULL
, N_("_Edit"), NULL
, NULL
, NULL
},
163 { "ViewMenu" , NULL
, N_("_View"), NULL
, NULL
, NULL
},
164 { "ManageMenu" , NULL
, N_("_Manage"), NULL
, NULL
, NULL
},
165 { "TxnMenu" , NULL
, N_("_Transactions"), NULL
, NULL
, NULL
},
166 { "ReportMenu" , NULL
, N_("_Reports"), NULL
, NULL
, NULL
},
167 { "ToolsMenu" , NULL
, N_("_Tools"), NULL
, NULL
, NULL
},
168 { "HelpMenu" , NULL
, N_("_Help"), NULL
, NULL
, NULL
},
170 // { "Import" , NULL, N_("Import") },
171 // { "Export" , NULL, N_("Export to") },
172 /* name, icon-name, label, accelerator, tooltip */
175 { "New" , ICONNAME_HB_FILE_NEW
, N_("_New") , "<control>N", N_("Create a new file"), G_CALLBACK (ui_mainwindow_action_new
) },
176 { "Open" , ICONNAME_HB_FILE_OPEN
, N_("_Open...") , "<control>O", N_("Open a file"), G_CALLBACK (ui_mainwindow_action_open
) },
177 { "Save" , ICONNAME_HB_FILE_SAVE
, N_("_Save") , "<control>S", N_("Save the current file"), G_CALLBACK (ui_mainwindow_action_save
) },
178 { "SaveAs" , ICONNAME_SAVE_AS
, N_("Save _As...") , "<shift><control>S", N_("Save the current file with a different name"), G_CALLBACK (ui_mainwindow_action_saveas
) },
180 { "Revert" , ICONNAME_REVERT
, N_("Revert") , NULL
, N_("Revert to a saved version of this file"), G_CALLBACK (ui_mainwindow_action_revert
) },
181 { "OpenBak" , NULL
, N_("Restore backup") , NULL
, N_("Restore from a backup file"), G_CALLBACK (ui_mainwindow_action_openbak
) },
183 { "Properties" , ICONNAME_PROPERTIES
, N_("Properties..."), NULL
, N_("Configure the file"), G_CALLBACK (ui_mainwindow_action_properties
) },
184 { "Close" , ICONNAME_CLOSE
, N_("_Close") , "<control>W", N_("Close the current file"), G_CALLBACK (ui_mainwindow_action_close
) },
185 { "Quit" , ICONNAME_QUIT
, N_("_Quit") , "<control>Q", N_("Quit HomeBank"), G_CALLBACK (ui_mainwindow_action_quit
) },
188 { "Import" , ICONNAME_HB_FILE_IMPORT
, N_("Import...") , NULL
, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import
) },
189 //{ "ImportQIF" , ICONNAME_HB_FILE_IMPORT , N_("QIF file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
190 //{ "ImportOFX" , ICONNAME_HB_FILE_IMPORT , N_("OFX/QFX file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
191 //{ "ImportCSV" , ICONNAME_HB_FILE_IMPORT , N_("CSV file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
193 { "ExportQIF" , ICONNAME_HB_FILE_EXPORT
, N_("Export as QIF...") , NULL
, N_("Export all account in a QIF file"), G_CALLBACK (ui_mainwindow_action_export
) },
196 { "Preferences", ICONNAME_PREFERENCES
, N_("Preferences..."), NULL
, N_("Configure HomeBank"), G_CALLBACK (ui_mainwindow_action_preferences
) },
199 { "Currency" , ICONNAME_HB_CURRENCY
, N_("Currencies...") , NULL
, N_("Configure the currencies"), G_CALLBACK (ui_mainwindow_action_defcurrency
) },
200 { "Account" , ICONNAME_HB_ACCOUNT
, N_("Acc_ounts...") , NULL
, N_("Configure the accounts"), G_CALLBACK (ui_mainwindow_action_defaccount
) },
201 { "Payee" , ICONNAME_HB_PAYEE
, N_("_Payees...") , NULL
, N_("Configure the payees"), G_CALLBACK (ui_mainwindow_action_defpayee
) },
202 { "Category" , ICONNAME_HB_CATEGORY
, N_("Categories...") , NULL
, N_("Configure the categories"), G_CALLBACK (ui_mainwindow_action_defcategory
) },
203 { "Archive" , ICONNAME_HB_ARCHIVE
, N_("Scheduled/Template...") , NULL
, N_("Configure the scheduled/template transactions"), G_CALLBACK (ui_mainwindow_action_defarchive
) },
204 { "Budget" , ICONNAME_HB_BUDGET
, N_("Budget...") , NULL
, N_("Configure the budget"), G_CALLBACK (ui_mainwindow_action_defbudget
) },
205 { "Assign" , ICONNAME_HB_ASSIGN
, N_("Assignments..."), NULL
, N_("Configure the automatic assignments"), G_CALLBACK (ui_mainwindow_action_defassign
) },
206 { "Tag" , NULL
, N_("Tags..."), NULL
, N_("Configure the tags"), G_CALLBACK (ui_mainwindow_action_deftag
) },
209 { "AddTxn" , ICONNAME_HB_OPE_ADD
, N_("Add...") , NULL
, N_("Add transactions"), G_CALLBACK (ui_mainwindow_action_addtransactions
) },
210 { "ShowTxn" , ICONNAME_HB_OPE_SHOW
, N_("Show...") , NULL
, N_("Shows selected account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions
) },
211 { "ShowAllTxn" , ICONNAME_HB_OPE_SHOW
, N_("Show all...") , NULL
, N_("Shows all account transactions"), G_CALLBACK (ui_mainwindow_action_showalltransactions
) },
212 { "Scheduler" , NULL
, N_("Set scheduler...") , NULL
, N_("Configure the transaction scheduler"), G_CALLBACK (ui_mainwindow_action_properties
) },
213 { "AddScheduled", NULL
, N_("Post scheduled"), NULL
, N_("Post pending scheduled transactions"), G_CALLBACK (ui_mainwindow_action_checkscheduled
) },
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(void)
753 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
759 if( data
->acc
->window
== NULL
)
761 window
= register_panel_window_new(data
->acc
);
762 register_panel_window_init(window
, NULL
);
766 if(GTK_IS_WINDOW(data
->acc
->window
))
767 gtk_window_present(GTK_WINDOW(data
->acc
->window
));
774 static void ui_mainwindow_action_showalltransactions(void)
778 if( GLOBALS
->alltxnwindow
== NULL
)
780 window
= register_panel_window_new(NULL
);
781 register_panel_window_init(window
, NULL
);
785 if(GTK_IS_WINDOW(GLOBALS
->alltxnwindow
))
786 gtk_window_present(GTK_WINDOW(GLOBALS
->alltxnwindow
));
792 static void ui_mainwindow_action_addtransactions(void)
794 ui_mainwindow_addtransactions(GLOBALS
->mainwindow
, NULL
);
797 static void ui_mainwindow_action_checkscheduled(void)
799 ui_hub_scheduled_postall(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
802 static void ui_mainwindow_action_statistic(void)
804 ui_repdist_window_new();
807 static void ui_mainwindow_action_trendtime(void)
809 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
811 ui_reptime_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
814 static void ui_mainwindow_action_budget(void)
816 repbudget_window_new();
819 static void ui_mainwindow_action_balance(void)
821 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
823 repbalance_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
826 static void ui_mainwindow_action_vehiclecost(void)
828 repcost_window_new();
831 static void ui_mainwindow_action_import(GtkAction
*action
)
834 gint filetype = FILETYPE_UNKNOWN;
836 name = gtk_action_get_name(action);
838 if( g_str_has_suffix (name, "QIF"))
839 filetype= FILETYPE_QIF;
841 if( g_str_has_suffix (name, "OFX"))
842 filetype= FILETYPE_OFX;
844 if( g_str_has_suffix (name, "CSV"))
845 filetype= FILETYPE_CSV_HB;*/
847 //DB( g_print("action %s type=%d\n", name, filetype) );
849 ui_import_assistant_new(NULL
);
854 static void ui_mainwindow_action_about(void)
862 static void ui_mainwindow_action_export(void)
866 if( ui_file_chooser_qif(NULL
, &filename
) == TRUE
)
868 hb_export_qif_account_all(filename
);
874 static void ui_mainwindow_action_help(void)
878 link
= g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP
, NULL
);
879 homebank_util_url_show (link
);
884 static void ui_mainwindow_action_help_releasenotes(void)
889 link
= g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog.txt", NULL
);
891 link
= g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog", NULL
);
893 homebank_util_url_show (link
);
898 //todo: move this to a ui-assist-welcome.c
900 static void ui_mainwindow_action_help_welcome1 (GtkButton
*button
, gpointer user_data
)
902 gtk_dialog_response (GTK_DIALOG(user_data
), 1);
905 static void ui_mainwindow_action_help_welcome2 (GtkButton
*button
, gpointer user_data
)
907 gtk_dialog_response (GTK_DIALOG(user_data
), 2);
910 static void ui_mainwindow_action_help_welcome3 (GtkButton
*button
, gpointer user_data
)
912 gtk_dialog_response (GTK_DIALOG(user_data
), 3);
915 static void ui_mainwindow_action_help_welcome4 (GtkButton
*button
, gpointer user_data
)
917 gtk_dialog_response (GTK_DIALOG(user_data
), 4);
920 static void ui_mainwindow_action_help_welcome5 (GtkButton
*button
, gpointer user_data
)
922 gtk_dialog_response (GTK_DIALOG(user_data
), 5);
925 void ui_mainwindow_action_help_welcome(void)
927 GtkWidget
*dialog
, *content_area
;
928 GtkWidget
*mainvbox
, *widget
, *label
;
930 dialog
= gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
931 GTK_WINDOW(GLOBALS
->mainwindow
),
937 content_area
= gtk_dialog_get_content_area(GTK_DIALOG (dialog
));
939 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
940 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, FALSE
, FALSE
, 0);
941 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
943 label
= make_label (_("HomeBank"), 0, 0);
944 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
945 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
947 label
= make_label (_("Free, easy, personal accounting for everyone"), 0, 0);
948 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
950 widget
= gtk_separator_new(GTK_ORIENTATION_HORIZONTAL
);
951 gtk_box_pack_start (GTK_BOX (content_area
), widget
, FALSE
, FALSE
, 0);
953 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, SPACING_MEDIUM
);
954 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, TRUE
, TRUE
, 0);
955 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
957 label
= make_label (_("What do you want to do:"), 0, 0);
958 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
959 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
961 widget
= gtk_button_new_with_mnemonic(_("Read HomeBank _Manual"));
962 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
963 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome1
), dialog
);
965 widget
= gtk_button_new_with_mnemonic(_("Configure _preferences"));
966 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
967 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome2
), dialog
);
969 widget
= gtk_button_new_with_mnemonic(_("Create a _new file"));
970 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
971 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome3
), dialog
);
973 widget
= gtk_button_new_with_mnemonic(_("_Open an existing file"));
974 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
975 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome4
), dialog
);
977 widget
= gtk_button_new_with_mnemonic(_("Open the _example file"));
978 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
979 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome5
), dialog
);
981 //connect all our signals
982 g_signal_connect (dialog
, "destroy", G_CALLBACK (gtk_widget_destroyed
), &dialog
);
984 gtk_widget_show_all (dialog
);
987 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
989 // cleanup and destroy
990 gtk_widget_destroy (dialog
);
992 // do appropriate action
996 ui_mainwindow_action_help();
999 ui_mainwindow_action_preferences();
1002 ui_mainwindow_action_new();
1005 ui_mainwindow_action_open();
1008 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL
));
1009 ui_mainwindow_open_internal(GLOBALS
->mainwindow
, NULL
);
1016 static void ui_mainwindow_action_help_updates(void)
1018 const gchar
*link
= HOMEBANK_URL_HELP_UPDATES
;
1020 homebank_util_url_show (link
);
1024 static void ui_mainwindow_action_help_online(void)
1026 const gchar
*link
= HOMEBANK_URL_HELP_ONLINE
;
1028 homebank_util_url_show (link
);
1032 static void ui_mainwindow_action_help_translate(void)
1034 const gchar
*link
= HOMEBANK_URL_HELP_TRANSLATE
;
1036 homebank_util_url_show (link
);
1040 static void ui_mainwindow_action_help_problem(void)
1042 const gchar
*link
= HOMEBANK_URL_HELP_PROBLEM
;
1044 homebank_util_url_show (link
);
1048 /* hbfile functions -------------------- */
1054 static void ui_mainwindow_selection(GtkTreeSelection
*treeselection
, gpointer user_data
)
1056 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
1060 static void ui_mainwindow_close_openbooks(void)
1064 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
1066 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1069 Account
*item
= elt
->data
;
1073 gtk_widget_destroy(GTK_WIDGET(item
->window
));
1074 item
->window
= NULL
;
1077 elt
= g_list_next(elt
);
1088 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
)
1090 struct hbfile_data
*data
;
1091 gboolean file_clear
= GPOINTER_TO_INT(user_data
);
1093 DB( g_print("\n[ui-mainwindow] clear\n") );
1095 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1097 // Close opened account window
1099 ui_mainwindow_close_openbooks();
1100 gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_acc
))));
1101 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
))));
1102 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_top
))));
1104 data
->showall
= FALSE
;
1105 ui_hub_account_setup(data
);
1107 hbfile_cleanup(file_clear
);
1108 hbfile_setup(file_clear
);
1114 ** add some transactions directly
1116 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
)
1118 struct hbfile_data
*data
;
1122 gint account
, count
;
1124 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1126 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1128 /* init the transaction */
1129 date
= homebank_app_date_get_julian();
1133 if(data
->acc
!= NULL
)
1134 account
= data
->acc
->key
;
1136 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
, FALSE
, account
);
1138 while(result
== HB_RESPONSE_ADD
|| result
== HB_RESPONSE_ADDKEEP
)
1142 /* fill in the transaction */
1143 if( result
== HB_RESPONSE_ADD
)
1145 ope
= da_transaction_malloc();
1147 ope
->kacc
= account
;
1149 if( PREFS
->heritdate
== FALSE
) //fix: 318733
1150 ope
->date
= GLOBALS
->today
;
1152 da_transaction_set_default_template(ope
);
1155 // normally we can't be in addkeep without initialized ope with add
1157 deftransaction_set_transaction(window
, ope
);
1159 result
= gtk_dialog_run (GTK_DIALOG (window
));
1161 DB( g_print(" - dialog result is %d\n", result
) );
1163 if(result
== HB_RESPONSE_ADD
|| result
== HB_RESPONSE_ADDKEEP
|| result
== GTK_RESPONSE_ACCEPT
)
1165 deftransaction_get(window
, NULL
);
1166 transaction_add(GTK_WINDOW(GLOBALS
->mainwindow
), ope
);
1168 DB( g_print(" - added 1 transaction to %d\n", ope
->kacc
) );
1170 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1173 //todo: still usefull ? store last date
1177 if( result
== HB_RESPONSE_ADD
)
1179 da_transaction_free(ope
);
1186 deftransaction_dispose(window
, NULL
);
1187 gtk_widget_destroy (window
);
1189 /* todo optimize this */
1192 GLOBALS
->changes_count
+= count
;
1193 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
1198 gboolean
ui_mainwindow_open_backup_check_confirm(gchar
*filepath
)
1200 gboolean retval
= FALSE
;
1201 gchar
*basename
, *secondtext
;
1204 basename
= g_path_get_basename(filepath
);
1205 secondtext
= g_strdup_printf (
1206 _("Your are about to open the backup file '%s'.\n\nAre you sure you want to do this ?"), basename
);
1208 result
= ui_dialog_msg_confirm_alert(
1209 GTK_WINDOW(GLOBALS
->mainwindow
),
1210 _("Open the backup file ?"),
1218 if( result
== GTK_RESPONSE_OK
)
1228 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
)
1230 //struct hbfile_data *data;
1231 gboolean bakmode
= GPOINTER_TO_INT(user_data
);;
1232 gboolean doopen
= TRUE
;
1233 gchar
*filename
= NULL
;
1235 DB( g_print("\n[ui-mainwindow] open\n") );
1237 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1239 //#1791554 do ask for save confirm
1240 if( bakmode
!= TRUE
)
1241 doopen
= ui_dialog_msg_savechanges(widget
,NULL
);
1243 if( doopen
== TRUE
)
1245 if( ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN
, &filename
, bakmode
) == TRUE
)
1247 //#1710955 test for backup open
1248 if( hbfile_file_isbackup(filename
) )
1250 if( ui_mainwindow_open_backup_check_confirm(filename
) == TRUE
)
1252 GLOBALS
->hbfile_is_bak
= TRUE
;
1261 hbfile_change_filepath(filename
);
1262 ui_mainwindow_open_internal(widget
, NULL
);
1269 * open the file stored in GLOBALS->xhb_filepath
1271 void ui_mainwindow_open_internal(GtkWidget
*widget
, gpointer user_data
)
1273 struct hbfile_data
*data
;
1276 DB( g_print("\n[ui-mainwindow] open internal\n") );
1278 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1280 if( GLOBALS
->xhb_filepath
!= NULL
)
1282 DB( g_print(" - filename: '%s'\n", GLOBALS
->xhb_filepath
) );
1284 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
1285 GLOBALS
->hbfile_is_new
= FALSE
;
1287 r
= homebank_load_xml(GLOBALS
->xhb_filepath
);
1290 DB( g_print(" - file loaded ok : rcode=%d\n", r
) );
1292 GLOBALS
->xhb_timemodified
= hbfile_file_get_time_modified(GLOBALS
->xhb_filepath
);
1293 hbfile_file_hasrevert(GLOBALS
->xhb_filepath
);
1295 if(PREFS
->appendscheduled
)
1296 scheduled_post_all_pending();
1298 if(PREFS
->do_update_currency
)
1299 ui_cur_manage_dialog_update_currencies(GTK_WINDOW(GLOBALS
->mainwindow
));
1301 homebank_lastopenedfiles_save();
1303 //todo: delete this after computing done at xml read
1304 account_compute_balances();
1306 ui_mainwindow_recent_add(data
, GLOBALS
->xhb_filepath
);
1310 gchar
*msg
= _("Unknown error");
1315 msg
= _("I/O error for file '%s'.");
1317 case XML_FILE_ERROR
:
1318 msg
= _("The file '%s' is not a valid HomeBank file.");
1320 case XML_VERSION_ERROR
:
1321 msg
= _("The file '%s' was saved with a higher version of HomeBank\nand cannot be loaded by the current version.");
1325 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1328 GLOBALS
->xhb_filepath
1331 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
1335 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1336 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1337 ui_hub_spending_populate(GLOBALS
->mainwindow
, NULL
);
1338 ui_hub_transaction_populate(data
);
1340 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1350 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
)
1352 struct hbfile_data
*data
;
1353 gboolean saveas
= GPOINTER_TO_INT(user_data
);
1354 gchar
*filename
= NULL
;
1357 DB( g_print("\n[ui-mainwindow] save\n") );
1359 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1361 if( GLOBALS
->hbfile_is_new
== TRUE
)
1364 //#1710955 test for backup open
1365 if( GLOBALS
->hbfile_is_bak
== TRUE
)
1367 //todo: later for backup, should also remove datetime and .bak
1368 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb"));
1374 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE
, &filename
, FALSE
) == TRUE
)
1376 DB( g_print(" + should save as '%s'\n", filename
) );
1377 homebank_file_ensure_xhb(filename
);
1378 homebank_backup_current_file();
1379 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1380 GLOBALS
->hbfile_is_new
= FALSE
;
1381 GLOBALS
->hbfile_is_bak
= FALSE
;
1388 guint64 time_modified
= hbfile_file_get_time_modified (GLOBALS
->xhb_filepath
);
1389 gint result
= GTK_RESPONSE_OK
;
1391 DB( g_print(" + should quick save '%s'\n + time: open=%lu :: now=%lu\n", GLOBALS
->xhb_filepath
, GLOBALS
->xhb_timemodified
, time_modified
) );
1393 if( GLOBALS
->xhb_timemodified
!= time_modified
)
1395 result
= ui_dialog_msg_confirm_alert(
1396 GTK_WINDOW(GLOBALS
->mainwindow
),
1397 _("The file has been modified since reading it."),
1398 _("If you save it, all the external changes could be lost. Save it anyway?"),
1402 if( result
!= GTK_RESPONSE_OK
)
1406 DB( g_print(" + saving...\n") );
1407 homebank_file_ensure_xhb(NULL
);
1408 homebank_backup_current_file();
1409 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1414 DB( g_print(" + OK...\n") );
1415 GLOBALS
->changes_count
= 0;
1416 GLOBALS
->xhb_timemodified
= hbfile_file_get_time_modified (GLOBALS
->xhb_filepath
);
1417 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1421 gchar
*msg
= _("I/O error for file '%s'.");
1423 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1426 GLOBALS
->xhb_filepath
1432 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
)
1434 struct hbfile_data
*data
;
1437 DB( g_print("\n[ui-mainwindow] update %p\n", user_data
) );
1439 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1440 //data = INST_DATA(widget);
1442 flags
= GPOINTER_TO_INT(user_data
);
1444 /* set window title */
1445 if(flags
& UF_TITLE
)
1450 DB( g_print(" 1: wintitle %p\n", data
->wintitle
) );
1452 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
1454 DB( g_print(" global changes: %d\n", GLOBALS
->changes_count
) );
1456 g_free(data
->wintitle
);
1458 changed
= (GLOBALS
->changes_count
> 0) ? "*" : "";
1461 data
->wintitle
= g_strdup_printf("%s%s (%d)- %s - " PROGNAME
, changed
, basename
, GLOBALS
->changes_count
, GLOBALS
->owner
);
1463 data
->wintitle
= g_strdup_printf("%s%s - %s - " PROGNAME
, changed
, basename
, GLOBALS
->owner
);
1466 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), data
->wintitle
);
1471 /* update disabled things */
1472 if(flags
& UF_SENSITIVE
)
1474 GtkTreeSelection
*selection
;
1475 GtkTreeModel
*model
;
1478 gboolean active
,sensitive
;
1480 DB( g_print(" 2: disabled, opelist count\n") );
1485 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
));
1486 active
= gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1492 path
= gtk_tree_model_get_path(model
, &iter
);
1493 depth
= gtk_tree_path_get_depth(path
);
1497 DB( g_print(" depth is %d\n", depth
) );
1499 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1506 DB( g_print(" changes %d - new %d\n", GLOBALS
->changes_count
, GLOBALS
->hbfile_is_new
) );
1509 sensitive
= (GLOBALS
->changes_count
!= 0 ) ? TRUE
: FALSE
;
1510 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Save"), sensitive
);
1513 sensitive
= ( (GLOBALS
->changes_count
!= 0) && GLOBALS
->xhb_hasrevert
) ? TRUE
: FALSE
;
1514 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Revert"), sensitive
);
1515 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/OpenBak"), sensitive
);
1518 sensitive
= GLOBALS
->define_off
== 0 ? TRUE
: FALSE
;
1519 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Account"), sensitive
);
1520 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Payee"), sensitive
);
1521 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Category"), sensitive
);
1522 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1523 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/EditMenu/Preferences"), sensitive
);
1525 // empty account list: disable Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
1526 sensitive
= da_acc_length() > 0 ? TRUE
: FALSE
;
1527 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Close"), sensitive
);
1528 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Archive"), sensitive
);
1529 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddTxn"), sensitive
);
1530 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowTxn"), sensitive
);
1531 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RStatistics"), sensitive
);
1532 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RTrendTime"), sensitive
);
1533 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBudget"), sensitive
);
1534 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBalance"), sensitive
);
1535 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RVehiculeCost"), sensitive
);
1537 // empty category list: disable Budget
1538 sensitive
= da_cat_length() > 1 ? TRUE
: FALSE
;
1539 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1541 //#1501129 no need to disable, P & C can be created from assign dialog
1542 //sensitive = ((da_cat_length() > 1) || (da_pay_length() > 1)) ? TRUE : FALSE;
1543 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Assign"), sensitive);
1545 // empty archive list: disable scheduled check
1546 sensitive
= g_list_length(GLOBALS
->arc_list
) > 0 ? TRUE
: FALSE
;
1547 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddScheduled"), sensitive
);
1549 // no active account: disable Edit, Over
1550 sensitive
= (active
== TRUE
) ? TRUE
: FALSE
;
1551 if(data
->acc
&& data
->acc
->window
!= NULL
)
1553 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowTxn"), sensitive
);
1556 /* update toolbar, list */
1557 if(flags
& UF_VISUAL
)
1559 DB( g_print(" 8: visual\n") );
1561 if(PREFS
->toolbar_style
== 0)
1562 gtk_toolbar_unset_style(GTK_TOOLBAR(data
->toolbar
));
1564 gtk_toolbar_set_style(GTK_TOOLBAR(data
->toolbar
), PREFS
->toolbar_style
-1);
1566 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_acc
), PREFS
->grid_lines
);
1567 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
1569 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_upc
), PREFS
->grid_lines
);
1570 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
1572 DB( g_print(" - show toolbar=%d\n", PREFS
->wal_toolbar
) );
1573 if(PREFS
->wal_toolbar
)
1574 gtk_widget_show(GTK_WIDGET(data
->toolbar
));
1576 gtk_widget_hide(GTK_WIDGET(data
->toolbar
));
1579 DB( g_print(" - show top_spending=%d\n", PREFS
->wal_spending
) );
1581 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
1583 if(PREFS
->wal_spending
)
1584 gtk_widget_show(GTK_WIDGET(data
->GR_top
));
1586 gtk_widget_hide(GTK_WIDGET(data
->GR_top
));
1590 DB( g_print(" - show upcoming=%d\n", PREFS
->wal_upcoming
) );
1591 if(PREFS
->wal_upcoming
)
1592 gtk_widget_show(GTK_WIDGET(data
->GR_upc
));
1594 gtk_widget_hide(GTK_WIDGET(data
->GR_upc
));
1596 DB( g_print(" minor %d\n", PREFS
->euro_active
) );
1597 gtk_action_set_visible(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor"), PREFS
->euro_active
);
1600 /* update balances */
1601 if(flags
& UF_BALANCE
)
1604 DB( g_print(" 4: balances\n") );
1606 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
1608 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
1611 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[0]), data->bank, minor);
1612 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[1]), data->today, minor);
1613 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[2]), data->future, minor);
1617 if(flags
& UF_REFRESHALL
)
1619 DB( g_print(" 16: refreshall\n") );
1621 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1622 ui_hub_spending_populate(GLOBALS
->mainwindow
, NULL
);
1623 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1624 ui_hub_transaction_populate(data
);
1633 ui_mainwindow_onRowActivated (GtkTreeView
*treeview
,
1635 GtkTreeViewColumn
*col
,
1638 GtkTreeModel
*model
;
1641 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
1643 model
= gtk_tree_view_get_model(treeview
);
1645 if (gtk_tree_model_get_iter(model
, &iter
, path
))
1649 gtk_tree_model_get(model
, &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1654 DB( g_print ("Double-clicked row contains name %s\n", acc
->name
) );
1656 ui_mainwindow_action_showtransactions();
1664 static void ui_mainwindow_destroy(GtkTreeView
*treeview
, gpointer user_data
)
1666 DB( g_print("\n[ui-mainwindow] destroy\n") );
1674 static gboolean
ui_mainwindow_dispose(GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
1676 struct hbfile_data
*data
= user_data
;
1677 struct WinGeometry
*wg
;
1678 gboolean retval
= FALSE
;
1680 DB( g_print("\n[ui-mainwindow] delete-event\n") );
1682 //store position and size
1683 wg
= &PREFS
->wal_wg
;
1684 gtk_window_get_position(GTK_WINDOW(widget
), &wg
->l
, &wg
->t
);
1685 gtk_window_get_size(GTK_WINDOW(widget
), &wg
->w
, &wg
->h
);
1686 GdkWindow
*gdk_window
= gtk_widget_get_window(GTK_WIDGET(widget
));
1687 GdkWindowState state
= gdk_window_get_state(gdk_window
);
1688 wg
->s
= (state
& GDK_WINDOW_STATE_MAXIMIZED
) ? 1 : 0;
1689 DB( g_print(" window: l=%d, t=%d, w=%d, h=%d s=%d, state=%d\n", wg
->l
, wg
->t
, wg
->w
, wg
->h
, wg
->s
, state
& GDK_WINDOW_STATE_MAXIMIZED
) );
1691 PREFS
->wal_vpaned
= gtk_paned_get_position(GTK_PANED(data
->vpaned
));
1692 PREFS
->wal_hpaned
= gtk_paned_get_position(GTK_PANED(data
->hpaned
));
1693 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
1695 if(PREFS
->pnl_list_tab
)
1696 g_free(PREFS
->pnl_list_tab
);
1697 PREFS
->pnl_list_tab
= g_strdup(gtk_stack_get_visible_child_name(GTK_STACK(data
->stack
)));
1700 if(ui_dialog_msg_savechanges(widget
, NULL
) == FALSE
)
1706 //todo: retval is useless and below should move to destroy
1708 gtk_widget_destroy(data
->LV_top
);
1710 g_free(data
->wintitle
);
1711 da_flt_free(data
->filter
);
1717 //TRUE:stop other handlers from being invoked for the event | FALSE: propagate
1722 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser
*chooser
, struct hbfile_data
*data
)
1725 GError
*error
= NULL
;
1727 uri
= gtk_recent_chooser_get_current_uri (chooser
);
1729 path
= g_filename_from_uri (uri
, NULL
, NULL
);
1732 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
1733 g_error_free (error
);
1737 if( ui_dialog_msg_savechanges(data
->window
, NULL
) == TRUE
)
1744 gpw_recent_remove (gpw, path);
1748 hbfile_change_filepath(path
);
1749 ui_mainwindow_open_internal(data
->window
, NULL
);
1759 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
)
1761 GtkRecentData
*recent_data
;
1763 GError
*error
= NULL
;
1765 DB( g_print("\n[ui-mainwindow] recent_add\n") );
1767 DB( g_print(" - file has .xhb suffix = %d\n", g_str_has_suffix (path
, ".xhb") ) );
1769 if( g_str_has_suffix (path
, ".xhb") == FALSE
) //ignore reverted file
1772 uri
= g_filename_to_uri (path
, NULL
, &error
);
1775 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
1776 g_error_free (error
);
1780 recent_data
= g_slice_new (GtkRecentData
);
1782 recent_data
->display_name
= NULL
;
1783 recent_data
->description
= NULL
;
1784 recent_data
->mime_type
= "application/x-homebank";
1785 recent_data
->app_name
= (gchar
*) g_get_application_name ();
1786 recent_data
->app_exec
= g_strjoin (" ", g_get_prgname (), "%u", NULL
);
1787 recent_data
->groups
= NULL
;
1788 recent_data
->is_private
= FALSE
;
1790 if (!gtk_recent_manager_add_full (data
->recent_manager
,
1794 g_warning ("Unable to add '%s' to the list of recently used documents", uri
);
1798 g_free (recent_data
->app_exec
);
1799 g_slice_free (GtkRecentData
, recent_data
);
1812 static GtkTargetEntry drop_types
[] =
1814 {"text/uri-list", 0, TARGET_URI_LIST
}
1817 static void ui_mainwindow_drag_data_received (GtkWidget
*widget
,
1818 GdkDragContext
*context
,
1820 GtkSelectionData
*selection_data
,
1821 guint info
, guint time
, GtkWindow
*window
)
1823 gchar
**uris
, **str
;
1825 gint n_uris
, filetype
, slen
;
1826 GError
*error
= NULL
;
1828 if (info
!= TARGET_URI_LIST
)
1831 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
1833 /* On MS-Windows, it looks like `selection_data->data' is not NULL terminated. */
1834 slen
= gtk_selection_data_get_length(selection_data
);
1835 newseldata
= g_new (gchar
, slen
+ 1);
1836 memcpy (newseldata
, gtk_selection_data_get_data(selection_data
), slen
);
1837 newseldata
[slen
] = 0;
1838 //DB( g_print(" - seldata ='%s'\n", gtk_selection_data_get_data(selection_data) ) );
1839 //DB( g_print(" - newseldata ='%s'\n", newseldata ) );
1841 uris
= g_uri_list_extract_uris (newseldata
);
1842 n_uris
= g_strv_length(uris
);
1843 DB( g_print(" - dragged %d files (len=%d)\n", n_uris
, slen
) );
1847 //single file: check for xhb
1850 filetype
= hb_filename_type_get_by_extension(*uris
);
1852 DB( g_print(" - filetype is homebank (%d)\n", filetype
) );
1854 if( filetype
== FILETYPE_HOMEBANK
)
1856 gchar
*path
= g_filename_from_uri (*uris
, NULL
, &error
);
1860 DB( g_print(" - path is '%s'\n", path
) );
1861 hbfile_change_filepath(g_strdup(path
));
1862 ui_mainwindow_open_internal(GTK_WIDGET(window
), NULL
);
1867 g_warning ("Could not convert uri to local path: %s", error
->message
);
1868 g_error_free (error
);
1872 /* we no more manage error here
1873 ui_dialog_msg_infoerror(GTK_WINDOW(window), GTK_MESSAGE_ERROR,
1875 _("The file %s is not a valid HomeBank file."),
1880 //collect known filetype to import
1881 DB( g_print(" - collect %d files\n", n_uris
) );
1883 gchar
**paths
= g_new (gchar
*, n_uris
+ 1);
1885 for (str
= uris
; *str
; str
++)
1887 filetype
= hb_filename_type_get_by_extension(*str
);
1888 if( filetype
!= FILETYPE_HOMEBANK
&& filetype
!= FILETYPE_UNKNOWN
)
1890 gchar
*path
= g_filename_from_uri (*str
, NULL
, NULL
);
1894 DB( g_print(" - append %d '%s'\n", slen
, path
) );
1895 paths
[slen
++] = path
;
1903 ui_import_assistant_new( paths
);
1912 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
)
1914 GtkWidget
*recent_menu
;
1915 GtkRecentFilter
*filter
;
1917 recent_menu
= gtk_recent_chooser_menu_new_for_manager (manager
);
1918 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu
), FALSE
);
1919 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu
), GTK_RECENT_SORT_MRU
);
1920 //todo: add a user pref for this
1921 gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER (recent_menu
), 10);
1922 gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu
), FALSE
);
1923 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_menu), TRUE);
1925 filter
= gtk_recent_filter_new ();
1926 //gtk_recent_filter_add_application (filter, g_get_application_name());
1927 gtk_recent_filter_add_pattern (filter
, "*.[Xx][Hh][Bb]");
1928 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu
), filter
);
1934 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data
*data
, GtkWidget
*mainvbox
)
1936 GtkUIManager
*manager
;
1937 GtkActionGroup
*actions
;
1939 GError
*error
= NULL
;
1941 manager
= gtk_ui_manager_new ();
1942 data
->manager
= manager
;
1944 gtk_window_add_accel_group (GTK_WINDOW (data
->window
),
1945 gtk_ui_manager_get_accel_group(manager
));
1947 actions
= gtk_action_group_new ("MainWindow");
1948 gtk_action_group_set_translation_domain(actions
, GETTEXT_PACKAGE
);
1950 gtk_action_group_add_actions (actions
,
1955 gtk_action_group_add_toggle_actions (actions
,
1960 gtk_ui_manager_insert_action_group (data
->manager
, actions
, 0);
1961 g_object_unref (actions
);
1962 data
->actions
= actions
;
1964 /* set short labels to use in the toolbar */
1965 action
= gtk_action_group_get_action(actions
, "Open");
1966 g_object_set(action
, "short_label", _("Open"), NULL
);
1968 //action = gtk_action_group_get_action(action_group, "Save");
1969 //g_object_set(action, "is_important", TRUE, NULL);
1971 action
= gtk_action_group_get_action(actions
, "Account");
1972 g_object_set(action
, "short_label", _("Account"), NULL
);
1974 action
= gtk_action_group_get_action(actions
, "Payee");
1975 g_object_set(action
, "short_label", _("Payee"), NULL
);
1977 action
= gtk_action_group_get_action(actions
, "Category");
1978 g_object_set(action
, "short_label", _("Category"), NULL
);
1980 action
= gtk_action_group_get_action(actions
, "Archive");
1981 //TRANSLATORS: an archive is stored transaction buffers (kind of bookmark to prefill manual insertion)
1982 g_object_set(action
, "short_label", _("Archive"), NULL
);
1984 action
= gtk_action_group_get_action(actions
, "Budget");
1985 g_object_set(action
, "short_label", _("Budget"), NULL
);
1987 action
= gtk_action_group_get_action(actions
, "ShowTxn");
1988 g_object_set(action
, "short_label", _("Show"), NULL
);
1990 action
= gtk_action_group_get_action(actions
, "AddTxn");
1991 g_object_set(action
, "is_important", TRUE
, "short_label", _("Add"), NULL
);
1993 action
= gtk_action_group_get_action(actions
, "RStatistics");
1994 g_object_set(action
, "short_label", _("Statistics"), NULL
);
1996 action
= gtk_action_group_get_action(actions
, "RBudget");
1997 g_object_set(action
, "short_label", _("Budget"), NULL
);
1999 action
= gtk_action_group_get_action(actions
, "RBalance");
2000 g_object_set(action
, "short_label", _("Balance"), NULL
);
2002 action
= gtk_action_group_get_action(actions
, "RVehiculeCost");
2003 g_object_set(action
, "short_label", _("Vehicle cost"), NULL
);
2005 /* now load the UI definition */
2006 gtk_ui_manager_add_ui_from_string (data
->manager
, ui_info
, -1, &error
);
2009 g_message ("Building menus failed: %s", error
->message
);
2010 g_error_free (error
);
2014 data
->recent_manager
= gtk_recent_manager_get_default ();
2016 data
->menubar
= gtk_ui_manager_get_widget (manager
, "/MenuBar");
2017 gtk_box_pack_start (GTK_BOX (mainvbox
),
2023 /* recent files menu */
2024 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2026 g_signal_connect (data
->recent_menu
,
2028 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2031 GtkWidget
*widget
= gtk_ui_manager_get_widget (data
->manager
, "/MenuBar/FileMenu/RecentMenu");
2032 gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget
), data
->recent_menu
);
2035 data
->toolbar
= gtk_ui_manager_get_widget (manager
, "/ToolBar");
2036 gtk_box_pack_start (GTK_BOX (mainvbox
),
2042 /* add the custom Open button to the toolbar */
2043 GtkWidget
*image
= gtk_image_new_from_icon_name (ICONNAME_HB_FILE_OPEN
, GTK_ICON_SIZE_BUTTON
);
2044 GtkToolItem
*open_button
= gtk_menu_tool_button_new(image
, _("_Open"));
2045 gtk_tool_item_set_tooltip_text (open_button
, _("Open a file"));
2047 GtkWidget
*recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2048 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button
), recent_menu
);
2049 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button
), _("Open a recently used file"));
2051 g_signal_connect (recent_menu
,
2053 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2056 action
= gtk_action_group_get_action (data
->actions
, "Open");
2057 g_object_set (action
, "short_label", _("Open"), NULL
);
2058 //gtk_action_connect_proxy (action, GTK_WIDGET (open_button));
2059 gtk_activatable_set_related_action (GTK_ACTIVATABLE (open_button
), action
);
2061 gtk_toolbar_insert (GTK_TOOLBAR (data
->toolbar
), open_button
, 1);
2067 ** the window creation
2069 GtkWidget
*create_hbfile_window(GtkWidget
*do_widget
)
2071 struct hbfile_data
*data
;
2072 struct WinGeometry
*wg
;
2073 GtkWidget
*mainvbox
, *vbox
, *box
, *vpaned
, *hpaned
, *sidebar
, *stack
;
2074 GtkWidget
*widget
, *page
;
2078 DB( g_print("\n[ui-mainwindow] create main window\n") );
2080 data
= g_malloc0(sizeof(struct hbfile_data
));
2081 if(!data
) return NULL
;
2083 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
2085 //store our window private data
2086 g_object_set_data(G_OBJECT(window
), "inst_data", (gpointer
)data
);
2087 DB( g_print(" - new window=%p, inst_data=%p\n", window
, data
) );
2089 // this is our mainwindow, so store it to GLOBALS data
2090 data
->window
= window
;
2091 GLOBALS
->mainwindow
= window
;
2093 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2094 gtk_container_add (GTK_CONTAINER (window
), mainvbox
);
2096 ui_mainwindow_create_menu_bar_and_toolbar (data
, mainvbox
);
2098 #if HB_UNSTABLE_SHOW == TRUE
2099 GtkWidget
*bar
, *label
;
2101 bar
= gtk_info_bar_new ();
2102 gtk_box_pack_start (GTK_BOX (mainvbox
), bar
, FALSE
, FALSE
, 0);
2103 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar
), GTK_MESSAGE_WARNING
);
2104 label
= make_label(NULL
, 0.5, 0.5);
2105 gtk_label_set_markup (GTK_LABEL(label
), "Unstable Development Version");
2106 gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar
))), label
, FALSE
, FALSE
, 0);
2109 /* Add the main area */
2110 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2111 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
2112 gtk_box_pack_start (GTK_BOX (mainvbox
), vbox
, TRUE
, TRUE
, 0);
2114 vpaned
= gtk_paned_new(GTK_ORIENTATION_VERTICAL
);
2115 data
->vpaned
= vpaned
;
2116 gtk_box_pack_start (GTK_BOX (vbox
), vpaned
, TRUE
, TRUE
, 0);
2118 hpaned
= gtk_paned_new(GTK_ORIENTATION_HORIZONTAL
);
2119 data
->hpaned
= hpaned
;
2120 gtk_paned_pack1 (GTK_PANED(vpaned
), hpaned
, FALSE
, FALSE
);
2122 widget
= ui_hub_account_create(data
);
2123 //gtk_widget_set_size_request (widget, 100, -1);
2124 gtk_paned_pack1 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
2126 widget
= ui_hub_spending_create(data
);
2127 //gtk_widget_set_size_request (widget, -1, 100);
2128 gtk_paned_pack2 (GTK_PANED(hpaned
), widget
, TRUE
, FALSE
);
2130 box
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
2132 gtk_paned_pack2 (GTK_PANED(vpaned
), box
, TRUE
, FALSE
);
2134 sidebar
= gtk_stack_sidebar_new ();
2135 gtk_box_pack_start (GTK_BOX (box
), sidebar
, FALSE
, FALSE
, 0);
2137 stack
= gtk_stack_new ();
2138 //gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN);
2139 gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar
), GTK_STACK (stack
));
2140 data
->stack
= stack
;
2141 gtk_box_pack_start (GTK_BOX (box
), stack
, TRUE
, TRUE
, 0);
2143 page
= ui_hub_scheduled_create(data
);
2144 gtk_stack_add_titled (GTK_STACK (stack
), page
, "sched", _("Scheduled"));
2145 //gtk_paned_pack2 (GTK_PANED(vpaned), widget, TRUE, FALSE);
2147 page
= ui_hub_transaction_create(data
, HUB_TXN_TYPE_FUTURE
);
2148 gtk_stack_add_titled (GTK_STACK (stack
), page
, "futur", _("Future"));
2150 page
= ui_hub_transaction_create(data
, HUB_TXN_TYPE_REMIND
);
2151 gtk_stack_add_titled (GTK_STACK (stack
), page
, "remin", _("Remind"));
2154 //setup, init and show window
2155 wg
= &PREFS
->wal_wg
;
2158 gtk_window_move(GTK_WINDOW(window
), wg
->l
, wg
->t
);
2159 gtk_window_resize(GTK_WINDOW(window
), wg
->w
, wg
->h
);
2162 gtk_window_maximize(GTK_WINDOW(window
));
2164 gtk_widget_show_all (window
);
2166 //#1662197/1660910 moved after resize/show
2167 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
2169 if(PREFS
->wal_hpaned
> 0)
2170 gtk_paned_set_position(GTK_PANED(data
->hpaned
), PREFS
->wal_hpaned
);
2171 if(PREFS
->wal_vpaned
> 0)
2172 gtk_paned_set_position(GTK_PANED(data
->vpaned
), PREFS
->wal_vpaned
);
2174 if( PREFS
->pnl_list_tab
!= NULL
)
2175 gtk_stack_set_visible_child_name (GTK_STACK(data
->stack
), PREFS
->pnl_list_tab
);
2178 //todo: move this elsewhere
2179 DB( g_print(" - setup stuff\n") );
2181 data
->filter
= da_flt_malloc();
2182 filter_reset(data
->filter
);
2183 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
2185 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Toolbar");
2186 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_toolbar
);
2187 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Spending");
2188 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_spending
);
2189 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/BottomLists");
2190 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_upcoming
);
2192 /* Drag and drop support, set targets to NULL because we add the
2193 default uri_targets below */
2195 /* support for opening a file by dragging onto the project window */
2196 gtk_drag_dest_set (GTK_WIDGET (window
),
2197 GTK_DEST_DEFAULT_ALL
,
2199 G_N_ELEMENTS (drop_types
),
2202 g_signal_connect (G_OBJECT (window
), "drag-data-received",
2203 G_CALLBACK (ui_mainwindow_drag_data_received
), window
);
2205 //connect all our signals
2206 DB( g_print(" - connect signals\n") );
2208 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
)), "changed", G_CALLBACK (ui_mainwindow_selection
), NULL
);
2209 g_signal_connect (GTK_TREE_VIEW(data
->LV_acc
), "row-activated", G_CALLBACK (ui_mainwindow_onRowActivated
), GINT_TO_POINTER(2));
2211 /* GtkWindow events */
2212 g_signal_connect (window
, "delete-event", G_CALLBACK (ui_mainwindow_dispose
), (gpointer
)data
);
2213 g_signal_connect (window
, "destroy", G_CALLBACK (ui_mainwindow_destroy
), NULL
);
2215 //gtk_action_group_set_sensitive(data->actions, FALSE);