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"
27 #include "list-account.h"
29 #include "hub-account.h"
30 #include "hub-scheduled.h"
31 #include "hub-spending.h"
32 #include "hub-transaction.h"
34 #include "dsp-account.h"
35 #include "ui-assist-import.h"
36 #include "ui-assist-start.h"
37 #include "ui-account.h"
38 #include "ui-currency.h"
40 #include "ui-category.h"
41 #include "ui-archive.h"
42 #include "ui-assign.h"
43 #include "ui-budget.h"
45 #include "ui-hbfile.h"
46 #include "ui-transaction.h"
49 #include "rep-balance.h"
50 #include "rep-budget.h"
51 #include "rep-stats.h"
53 #include "rep-vehicle.h"
55 #include "gtk-chart.h"
58 //#define HOMEBANK_URL_HELP "http://homebank.free.fr/help/"
59 //#define HOMEBANK_URL_HELP_ONLINE "https://launchpad.net/homebank/+addquestion"
60 //#define HOMEBANK_URL_HELP_PROBLEM "https://launchpad.net/homebank/+filebug"
61 //#define HOMEBANK_URL_HELP_TRANSLATE "https://launchpad.net/homebank/+translations"
63 #define HOMEBANK_URL_HELP "index.html"
64 #define HOMEBANK_URL_HELP_ONLINE "http://homebank.free.fr/support.php"
65 #define HOMEBANK_URL_HELP_UPDATES "http://homebank.free.fr/downloads.php"
66 #define HOMEBANK_URL_HELP_PROBLEM "http://homebank.free.fr/development.php#bug"
67 #define HOMEBANK_URL_HELP_TRANSLATE "http://homebank.free.fr/development.php#translate"
70 /****************************************************************************/
72 /****************************************************************************/
81 /* our global datas */
82 extern struct HomeBank
*GLOBALS
;
83 extern struct Preferences
*PREFS
;
84 extern gchar
*homebank_pixmaps_dir
;
87 /* our functions prototype */
88 static void ui_mainwindow_action_new(void);
89 static void ui_mainwindow_action_open(void);
90 static void ui_mainwindow_action_save(void);
91 static void ui_mainwindow_action_saveas(void);
92 static void ui_mainwindow_action_revert(void);
93 static void ui_mainwindow_action_openbak(void);
94 static void ui_mainwindow_action_properties(void);
95 static void ui_mainwindow_action_close(void);
96 static void ui_mainwindow_action_quit(void);
98 static void ui_mainwindow_action_defcurrency(void);
99 static void ui_mainwindow_action_defaccount(void);
100 static void ui_mainwindow_action_defpayee(void);
101 static void ui_mainwindow_action_defcategory(void);
102 static void ui_mainwindow_action_defarchive(void);
103 static void ui_mainwindow_action_defbudget(void);
104 static void ui_mainwindow_action_defassign(void);
105 static void ui_mainwindow_action_deftag(void);
106 static void ui_mainwindow_action_preferences(void);
108 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction
*action
);
109 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction
*action
);
110 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction
*action
);
111 static void ui_mainwindow_action_toggle_minor(GtkToggleAction
*action
);
113 static void ui_mainwindow_action_showtransactions(GtkAction
*action
);
115 static void ui_mainwindow_action_addtransactions(void);
116 static void ui_mainwindow_action_checkscheduled(void);
118 static void ui_mainwindow_action_statistic(void);
119 static void ui_mainwindow_action_trendtime(void);
120 static void ui_mainwindow_action_budget(void);
121 static void ui_mainwindow_action_balance(void);
122 static void ui_mainwindow_action_vehiclecost(void);
124 static void ui_mainwindow_action_import(GtkAction
*action
);
125 static void ui_mainwindow_action_export(void);
126 static void ui_mainwindow_action_anonymize(void);
127 static void ui_mainwindow_action_file_statistics(void);
129 static void ui_mainwindow_action_pluginprefs(void);
131 static void ui_mainwindow_action_help(void);
132 void ui_mainwindow_action_help_welcome(void);
133 static void ui_mainwindow_action_help_online(void);
134 static void ui_mainwindow_action_help_updates(void);
135 static void ui_mainwindow_action_help_releasenotes(void);
136 static void ui_mainwindow_action_help_translate(void);
137 static void ui_mainwindow_action_help_problem(void);
138 static void ui_mainwindow_action_about(void);
141 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
);
143 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
);
145 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
);
146 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
);
147 void ui_mainwindow_action(GtkWidget
*widget
, gpointer user_data
);
148 void ui_mainwindow_toggle_minor(GtkWidget
*widget
, gpointer user_data
);
149 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
);
151 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
);
152 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
);
153 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
155 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
157 static void ui_mainwindow_showprefs(gint page
);
159 static GtkActionEntry entries
[] = {
161 /* name, icon-name, label */
163 { "FileMenu" , NULL
, N_("_File"), NULL
, NULL
, NULL
},
164 //{ "ImportMenu" , NULL, N_("_Import"), NULL, NULL, NULL },
165 { "RecentMenu" , NULL
, N_("Open _Recent"), NULL
, NULL
, NULL
},
166 { "EditMenu" , NULL
, N_("_Edit"), NULL
, NULL
, NULL
},
167 { "ViewMenu" , NULL
, N_("_View"), NULL
, NULL
, NULL
},
168 { "ManageMenu" , NULL
, N_("_Manage"), NULL
, NULL
, NULL
},
169 { "TxnMenu" , NULL
, N_("_Transactions"), NULL
, NULL
, NULL
},
170 { "ReportMenu" , NULL
, N_("_Reports"), NULL
, NULL
, NULL
},
171 { "ToolsMenu" , NULL
, N_("_Tools"), NULL
, NULL
, NULL
},
172 { "PluginMenu" , NULL
, N_("_Plugins"), NULL
, NULL
, NULL
},
173 { "HelpMenu" , NULL
, N_("_Help"), NULL
, NULL
, NULL
},
175 // { "Import" , NULL, N_("Import") },
176 // { "Export" , NULL, N_("Export to") },
177 /* name, icon-name, label, accelerator, tooltip */
180 { "New" , ICONNAME_HB_FILE_NEW
, N_("_New") , "<control>N", N_("Create a new file"), G_CALLBACK (ui_mainwindow_action_new
) },
181 { "Open" , ICONNAME_HB_FILE_OPEN
, N_("_Open...") , "<control>O", N_("Open a file"), G_CALLBACK (ui_mainwindow_action_open
) },
182 { "Save" , ICONNAME_HB_FILE_SAVE
, N_("_Save") , "<control>S", N_("Save the current file"), G_CALLBACK (ui_mainwindow_action_save
) },
183 { "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
) },
185 { "Revert" , ICONNAME_REVERT
, N_("Revert") , NULL
, N_("Revert to a saved version of this file"), G_CALLBACK (ui_mainwindow_action_revert
) },
186 { "OpenBak" , NULL
, N_("Restore backup") , NULL
, N_("Restore from a backup file"), G_CALLBACK (ui_mainwindow_action_openbak
) },
188 { "Properties" , ICONNAME_PROPERTIES
, N_("Properties..."), NULL
, N_("Configure the file"), G_CALLBACK (ui_mainwindow_action_properties
) },
189 { "Close" , ICONNAME_CLOSE
, N_("_Close") , "<control>W", N_("Close the current file"), G_CALLBACK (ui_mainwindow_action_close
) },
190 { "Quit" , ICONNAME_QUIT
, N_("_Quit") , "<control>Q", N_("Quit HomeBank"), G_CALLBACK (ui_mainwindow_action_quit
) },
193 { "Import" , ICONNAME_HB_FILE_IMPORT
, N_("Import...") , NULL
, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import
) },
194 //{ "ImportQIF" , ICONNAME_HB_FILE_IMPORT , N_("QIF file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
195 //{ "ImportOFX" , ICONNAME_HB_FILE_IMPORT , N_("OFX/QFX file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
196 //{ "ImportCSV" , ICONNAME_HB_FILE_IMPORT , N_("CSV file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
198 { "ExportQIF" , ICONNAME_HB_FILE_EXPORT
, N_("Export as QIF...") , NULL
, N_("Export all account in a QIF file"), G_CALLBACK (ui_mainwindow_action_export
) },
201 { "Preferences", ICONNAME_PREFERENCES
, N_("Preferences..."), NULL
, N_("Configure HomeBank"), G_CALLBACK (ui_mainwindow_action_preferences
) },
204 { "Currency" , ICONNAME_HB_CURRENCY
, N_("Currencies...") , NULL
, N_("Configure the currencies"), G_CALLBACK (ui_mainwindow_action_defcurrency
) },
205 { "Account" , ICONNAME_HB_ACCOUNT
, N_("Acc_ounts...") , NULL
, N_("Configure the accounts"), G_CALLBACK (ui_mainwindow_action_defaccount
) },
206 { "Payee" , ICONNAME_HB_PAYEE
, N_("_Payees...") , NULL
, N_("Configure the payees"), G_CALLBACK (ui_mainwindow_action_defpayee
) },
207 { "Category" , ICONNAME_HB_CATEGORY
, N_("Categories...") , NULL
, N_("Configure the categories"), G_CALLBACK (ui_mainwindow_action_defcategory
) },
208 { "Archive" , ICONNAME_HB_ARCHIVE
, N_("Scheduled/Template...") , NULL
, N_("Configure the scheduled/template transactions"), G_CALLBACK (ui_mainwindow_action_defarchive
) },
209 { "Budget" , ICONNAME_HB_BUDGET
, N_("Budget...") , NULL
, N_("Configure the budget"), G_CALLBACK (ui_mainwindow_action_defbudget
) },
210 { "Assign" , ICONNAME_HB_ASSIGN
, N_("Assignments..."), NULL
, N_("Configure the automatic assignments"), G_CALLBACK (ui_mainwindow_action_defassign
) },
211 { "Tag" , NULL
, N_("Tags..."), NULL
, N_("Configure the tags"), G_CALLBACK (ui_mainwindow_action_deftag
) },
214 { "AddTxn" , ICONNAME_HB_OPE_ADD
, N_("Add...") , NULL
, N_("Add transactions"), G_CALLBACK (ui_mainwindow_action_addtransactions
) },
215 { "ShowTxn" , ICONNAME_HB_OPE_SHOW
, N_("Show...") , NULL
, N_("Shows selected account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions
) },
216 //beware ShowAllTxn is used to detect showall
217 { "ShowAllTxn" , ICONNAME_HB_OPE_SHOW
, N_("Show all...") , NULL
, N_("Shows all account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions
) },
218 { "Scheduler" , NULL
, N_("Set scheduler...") , NULL
, N_("Configure the transaction scheduler"), G_CALLBACK (ui_mainwindow_action_properties
) },
219 { "AddScheduled", NULL
, N_("Post scheduled"), NULL
, N_("Post pending scheduled transactions"), G_CALLBACK (ui_mainwindow_action_checkscheduled
) },
222 { "RStatistics" , ICONNAME_HB_REP_STATS
, N_("_Statistics...") , NULL
, N_("Open the Statistics report"), G_CALLBACK (ui_mainwindow_action_statistic
) },
223 { "RTrendTime" , ICONNAME_HB_REP_TIME
, N_("_Trend Time...") , NULL
, N_("Open the Trend Time report"), G_CALLBACK (ui_mainwindow_action_trendtime
) },
224 { "RBudget" , ICONNAME_HB_REP_BUDGET
, N_("B_udget...") , NULL
, N_("Open the Budget report"), G_CALLBACK (ui_mainwindow_action_budget
) },
225 { "RBalance" , ICONNAME_HB_REP_BALANCE
, N_("Balance...") , NULL
, N_("Open the Balance report"), G_CALLBACK (ui_mainwindow_action_balance
) },
226 { "RVehiculeCost", ICONNAME_HB_REP_CAR
, N_("_Vehicle cost...") , NULL
, N_("Open the Vehicle cost report"), G_CALLBACK (ui_mainwindow_action_vehiclecost
) },
229 { "Welcome" , NULL
, N_("Show welcome dialog...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_help_welcome
) },
230 { "FileStats" , NULL
, N_("File statistics...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_file_statistics
) },
231 { "Anonymize" , NULL
, N_("Anonymize...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_anonymize
) },
234 { "PluginPreferences", "prf-plugins", N_("_Plugins..."), "<control>U", N_("Configure plugin preferences"), G_CALLBACK(ui_mainwindow_action_pluginprefs
) },
237 { "Contents" , ICONNAME_HELP
, N_("_Contents") , "F1", N_("Documentation about HomeBank"), G_CALLBACK (ui_mainwindow_action_help
) },
238 { "Online" , "lpi-help" , N_("Get Help Online...") , NULL
, N_("Connect to the LaunchPad website for online help"), G_CALLBACK (ui_mainwindow_action_help_online
) },
240 { "Updates" , NULL
, N_("Check for updates...") , NULL
, N_("Visit HomeBank website to check for update"), G_CALLBACK (ui_mainwindow_action_help_updates
) },
241 { "ReleaseNotes", NULL
, N_("Release Notes") , NULL
, N_("Display the release notes"), G_CALLBACK (ui_mainwindow_action_help_releasenotes
) },
242 { "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
) },
243 { "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
) },
245 { "About" , ICONNAME_ABOUT
, N_("_About") , NULL
, N_("About HomeBank") ,G_CALLBACK (ui_mainwindow_action_about
) },
248 static guint n_entries
= G_N_ELEMENTS (entries
);
251 static GtkToggleActionEntry toggle_entries
[] = {
252 /* name , icon-name, label, accelerator, tooltip, callback, is_active */
253 { "Toolbar" , NULL
, N_("_Toolbar") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_toolbar
), TRUE
},
254 { "Spending" , NULL
, N_("_Top spending") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_topspending
), TRUE
},
255 { "BottomLists", NULL
, N_("_Bottom Lists") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_upcoming
), TRUE
},
256 { "AsMinor" , NULL
, N_("Euro minor"), "<control>M", NULL
, G_CALLBACK (ui_mainwindow_action_toggle_minor
), FALSE
},
259 static guint n_toggle_entries
= G_N_ELEMENTS (toggle_entries
);
262 static const gchar
*ui_info
=
265 " <menubar name='MenuBar'>"
266 " <menu action='FileMenu'>"
267 " <menuitem action='New'/>"
268 " <menuitem action='Open'/>"
269 " <menuitem action='RecentMenu'/>"
271 " <menuitem action='Save'/>"
272 " <menuitem action='SaveAs'/>"
274 " <menuitem action='Import'/>"
275 /*" <menu action='ImportMenu'>"
276 " <menuitem action='ImportQIF'/>"
277 " <menuitem action='ImportOFX'/>"
278 " <menuitem action='ImportCSV'/>"
280 " <menuitem action='ExportQIF'/>"
281 // future: print to come here
283 " <menuitem action='Revert'/>"
284 " <menuitem action='OpenBak'/>"
286 " <menuitem action='Properties'/>"
288 " <menuitem action='Close'/>"
289 " <menuitem action='Quit'/>"
291 " <menu action='EditMenu'>"
292 " <menuitem action='Preferences'/>"
294 " <menu action='ViewMenu'>"
295 " <menuitem action='Toolbar'/>"
297 " <menuitem action='Spending'/>"
298 " <menuitem action='BottomLists'/>"
300 " <menuitem action='AsMinor'/>"
302 " <menu action='ManageMenu'>"
303 " <menuitem action='Account'/>"
304 " <menuitem action='Payee'/>"
305 " <menuitem action='Category'/>"
306 " <menuitem action='Archive'/>"
307 " <menuitem action='Budget'/>"
308 " <menuitem action='Assign'/>"
309 " <menuitem action='Currency'/>"
310 " <menuitem action='Tag'/>"
312 " <menu action='TxnMenu'>"
313 " <menuitem action='AddTxn'/>"
314 " <menuitem action='ShowTxn'/>"
315 " <menuitem action='ShowAllTxn'/>"
317 " <menuitem action='Scheduler'/>"
318 " <menuitem action='AddScheduled'/>"
320 " <menu action='ReportMenu'>"
321 " <menuitem action='RStatistics'/>"
322 " <menuitem action='RTrendTime'/>"
323 " <menuitem action='RBalance'/>"
324 " <menuitem action='RBudget'/>"
325 " <menuitem action='RVehiculeCost'/>"
327 " <menu action='ToolsMenu'>"
328 " <menuitem action='Welcome'/>"
329 " <menuitem action='FileStats'/>"
331 " <menuitem action='Anonymize'/>"
333 " <menu action='PluginMenu'>"
335 " <menuitem action='PluginPreferences'/>"
338 " <menu action='HelpMenu'>"
339 " <menuitem action='Contents'/>"
340 " <menuitem action='Online'/>"
342 " <menuitem action='Updates'/>"
343 " <menuitem action='ReleaseNotes'/>"
344 " <menuitem action='Problem'/>"
345 " <menuitem action='Translate'/>"
347 " <menuitem action='About'/>"
351 " <toolbar name='ToolBar'>"
352 " <toolitem action='New'/>"
353 // here Open + recent is coded
354 " <toolitem action='Save'/>"
356 " <toolitem action='Account'/>"
357 " <toolitem action='Payee'/>"
358 " <toolitem action='Category'/>"
359 " <toolitem action='Archive'/>"
360 " <toolitem action='Budget'/>"
361 " <toolitem action='Assign'/>"
362 " <toolitem action='Currency'/>"
364 " <toolitem action='ShowTxn'/>"
365 " <toolitem action='AddTxn'/>"
367 " <toolitem action='RStatistics'/>"
368 " <toolitem action='RTrendTime'/>"
369 " <toolitem action='RBalance'/>"
370 " <toolitem action='RBudget'/>"
371 " <toolitem action='RVehiculeCost'/>"
385 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
)
387 //struct hbfile_data *data;
393 DB( g_print("\n[ui-mainwindow] revert\n") );
395 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
397 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
398 title
= g_strdup_printf (
399 _("Revert unsaved changes to file '%s'?"), basename
);
402 _("- Changes made to the file will be permanently lost\n"
403 "- File will be reloaded from the last save (.xhb~)");
405 result
= ui_dialog_msg_confirm_alert(
406 GTK_WINDOW(GLOBALS
->mainwindow
),
415 if( result
== GTK_RESPONSE_OK
)
417 DB( g_print(" - should revert\n") );
419 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb~"));
420 ui_mainwindow_open_internal(widget
, NULL
);
421 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb"));
428 activate_url (GtkAboutDialog
*about
,
432 DB( g_print("activate url %s\n", link
) );
434 homebank_util_url_show (link
);
437 static void hbfile_about(void)
444 static const gchar
*artists
[] = {
449 static const gchar
*authors
[] = {
450 "Lead developer:\n" \
452 "\nContributors:\n" \
453 "Charles MCGARVEY (Plugin system, Perl support)\n" \
454 "Ga\xc3\xabtan LORIDANT (Maths formulas for charts)\n",
459 const gchar *documenters[] = {
465 static const gchar
*copyright
= "Copyright \xc2\xa9 1995-2019 - Maxime DOYEN";
469 version
= g_strdup_printf (PACKAGE_VERSION
"\n<small>Running against GTK+ %d.%d.%d</small>",
470 gtk_get_major_version (),
471 gtk_get_minor_version (),
472 gtk_get_micro_version ());
474 dialog
= gtk_about_dialog_new();
476 gtk_window_set_transient_for (GTK_WINDOW(dialog
), GTK_WINDOW(GLOBALS
->mainwindow
));
477 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
479 gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog
), g_get_application_name ());
480 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog
), version
);
481 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog
), copyright
);
482 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog
), _("Free, easy, personal accounting for everyone"));
483 gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG(dialog
), GTK_LICENSE_GPL_2_0
);
485 //gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(dialog), );
486 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog
), "http://homebank.free.fr");
487 gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(dialog
), "Visit the HomeBank website");
489 gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(dialog
), "homebank");
491 pathfilename
= g_build_filename(homebank_app_get_images_dir(), "splash.png", NULL
);
492 pixbuf
= gdk_pixbuf_new_from_file(pathfilename
, NULL
);
493 g_free(pathfilename
);
497 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog
), pixbuf
);
498 g_object_unref (pixbuf
);
501 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog
), authors
);
502 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog
), artists
);
503 //gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(dialog), );
504 //gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog), );
506 g_signal_connect (dialog
, "activate-link", G_CALLBACK (activate_url
), NULL
);
508 gtk_dialog_run (GTK_DIALOG (dialog
));
510 gtk_widget_destroy (dialog
);
517 /* hbfile action functions -------------------- */
518 static void ui_mainwindow_action_new(void)
520 GtkWidget
*widget
= GLOBALS
->mainwindow
;
522 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
524 //clear all, and init GLOBALS->xhb_filepath to default
525 ui_mainwindow_clear(widget
, GINT_TO_POINTER(TRUE
)); // GPOINTER_TO_INT(
526 ui_mainwindow_update(widget
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
528 ui_start_assistant();
529 //ui_hub_account_populate(GLOBALS->mainwindow, NULL);
530 //ui_hub_scheduled_populate(GLOBALS->mainwindow, NULL);
531 //ui_hub_spending_populate(GLOBALS->mainwindow, NULL);
535 static void ui_mainwindow_action_open(void)
537 ui_mainwindow_open(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
540 static void ui_mainwindow_action_openbak(void)
542 ui_mainwindow_open(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
545 static void ui_mainwindow_action_save(void)
547 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
550 static void ui_mainwindow_action_saveas(void)
552 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
555 static void ui_mainwindow_action_revert(void)
557 ui_mainwindow_revert(GLOBALS
->mainwindow
, NULL
);
560 static void ui_mainwindow_action_close(void)
562 GtkWidget
*widget
= GLOBALS
->mainwindow
;
564 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
566 //clear all, and init GLOBALS->xhb_filepath to default
567 ui_mainwindow_clear(widget
, GINT_TO_POINTER(TRUE
));
568 ui_mainwindow_update(widget
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
574 static void ui_mainwindow_action_quit(void)
578 //emulate the wm close button
579 g_signal_emit_by_name(GLOBALS
->mainwindow
, "delete-event", NULL
, &result
);
583 static void ui_mainwindow_action_file_statistics(void)
585 ui_dialog_file_statistics();
589 static void ui_mainwindow_action_pluginprefs(void)
591 ui_mainwindow_showprefs(PREF_PLUGINS
);
595 static void ui_mainwindow_action_properties(void)
597 create_defhbfile_dialog();
598 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
601 static void ui_mainwindow_action_anonymize(void)
607 title
= _("Are you sure you want to anonymize the file?");
610 _("Proceeding will anonymize any text, \n"
611 "like 'account x', 'payee y', 'memo z', ...");
613 result
= ui_dialog_msg_confirm_alert(
614 GTK_WINDOW(GLOBALS
->mainwindow
),
621 //if( result == GTK_RESPONSE_CANCEL )
623 if( result
== GTK_RESPONSE_OK
)
626 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
631 static void ui_mainwindow_action_defcurrency(void)
633 ui_cur_manage_dialog();
634 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
638 static void ui_mainwindow_action_defaccount(void)
640 ui_acc_manage_dialog();
642 //our global list has changed, so update the treeview
643 //todo: optimize this, should not call compute balance here
644 account_compute_balances ();
645 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
647 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
));
650 static void ui_mainwindow_action_defpayee(void)
652 ui_pay_manage_dialog();
653 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
656 static void ui_mainwindow_action_defcategory(void)
658 ui_cat_manage_dialog();
659 //todo:why refresh upcoming here??
660 //ui_mainwindow_populate_upcoming(GLOBALS->mainwindow, NULL);
661 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
665 //TODO: not ideal to do this
666 void ui_mainwindow_defarchive(Archive
*arc
)
668 struct hbfile_data
*data
;
671 data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
673 // upcoming list have direct pointer to the arc (which may change during edit)
674 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
));
675 gtk_list_store_clear (GTK_LIST_STORE(model
));
677 ui_arc_manage_dialog(arc
);
679 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
681 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
685 static void ui_mainwindow_action_defarchive(void)
687 ui_mainwindow_defarchive(NULL
);
691 static void ui_mainwindow_action_defbudget(void)
693 ui_bud_manage_dialog();
694 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
698 static void ui_mainwindow_action_defassign(void)
701 ui_asg_manage_dialog();
703 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
707 static void ui_mainwindow_action_deftag(void)
710 ui_tag_manage_dialog();
712 //ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
716 static void ui_mainwindow_action_preferences(void)
718 ui_mainwindow_showprefs(PREF_GENERAL
);
721 static void ui_mainwindow_showprefs(gint page
)
723 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
725 defpref_dialog_new(page
);
726 if(!PREFS
->euro_active
)
728 GtkToggleAction
*action
= (GtkToggleAction
*)gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor");
730 gtk_toggle_action_set_active(action
, FALSE
);
731 ui_mainwindow_action_toggle_minor(action
);
733 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
+UF_REFRESHALL
));
738 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction
*action
)
740 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
742 PREFS
->wal_toolbar
= gtk_toggle_action_get_active(action
);
743 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
746 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction
*action
)
748 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
750 PREFS
->wal_upcoming
= gtk_toggle_action_get_active(action
);
751 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
754 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction
*action
)
756 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
758 PREFS
->wal_spending
= gtk_toggle_action_get_active(action
);
759 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
762 static void ui_mainwindow_action_toggle_minor(GtkToggleAction
*action
)
764 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
766 GLOBALS
->minor
= gtk_toggle_action_get_active(action
);
768 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
769 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
772 gtk_chart_show_minor(GTK_CHART(data
->RE_pie
), GLOBALS
->minor
);
774 ui_hub_spending_update(data
->window
, data
);
778 static void ui_mainwindow_action_showtransactions(GtkAction
*action
)
780 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
782 gboolean showall
= FALSE
;
786 DB( g_print(" actioname=%s\n", gtk_action_get_name(action
)) );
787 if( hb_string_compare((gchar
*)gtk_action_get_name(action
), "ShowAllTxn" ) == 0 )
792 if( data
->acc
&& showall
== FALSE
)
794 if( data
->acc
->window
== NULL
)
796 window
= register_panel_window_new(data
->acc
);
797 register_panel_window_init(window
, NULL
);
801 if(GTK_IS_WINDOW(data
->acc
->window
))
802 gtk_window_present(GTK_WINDOW(data
->acc
->window
));
807 if( GLOBALS
->alltxnwindow
== NULL
)
809 window
= register_panel_window_new(NULL
);
810 register_panel_window_init(window
, NULL
);
814 if(GTK_IS_WINDOW(GLOBALS
->alltxnwindow
))
815 gtk_window_present(GTK_WINDOW(GLOBALS
->alltxnwindow
));
821 static void ui_mainwindow_action_addtransactions(void)
823 ui_mainwindow_addtransactions(GLOBALS
->mainwindow
, NULL
);
826 static void ui_mainwindow_action_checkscheduled(void)
828 ui_hub_scheduled_postall(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
831 static void ui_mainwindow_action_statistic(void)
833 ui_repdist_window_new();
836 static void ui_mainwindow_action_trendtime(void)
838 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
840 ui_reptime_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
843 static void ui_mainwindow_action_budget(void)
845 repbudget_window_new();
848 static void ui_mainwindow_action_balance(void)
850 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
852 repbalance_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
855 static void ui_mainwindow_action_vehiclecost(void)
857 repcost_window_new();
860 static void ui_mainwindow_action_import(GtkAction
*action
)
863 gint filetype = FILETYPE_UNKNOWN;
865 name = gtk_action_get_name(action);
867 if( g_str_has_suffix (name, "QIF"))
868 filetype= FILETYPE_QIF;
870 if( g_str_has_suffix (name, "OFX"))
871 filetype= FILETYPE_OFX;
873 if( g_str_has_suffix (name, "CSV"))
874 filetype= FILETYPE_CSV_HB;*/
876 //DB( g_print("action %s type=%d\n", name, filetype) );
878 ui_import_assistant_new(NULL
);
883 static void ui_mainwindow_action_about(void)
891 static void ui_mainwindow_action_export(void)
895 if( ui_file_chooser_qif(NULL
, &filename
) == TRUE
)
897 hb_export_qif_account_all(filename
);
903 static void ui_mainwindow_action_help(void)
907 link
= g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP
, NULL
);
908 homebank_util_url_show (link
);
913 static void ui_mainwindow_action_help_releasenotes(void)
918 link
= g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog.txt", NULL
);
920 link
= g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog", NULL
);
922 homebank_util_url_show (link
);
927 //todo: move this to a ui-assist-welcome.c
929 static void ui_mainwindow_action_help_welcome1 (GtkButton
*button
, gpointer user_data
)
931 gtk_dialog_response (GTK_DIALOG(user_data
), 1);
934 static void ui_mainwindow_action_help_welcome2 (GtkButton
*button
, gpointer user_data
)
936 gtk_dialog_response (GTK_DIALOG(user_data
), 2);
939 static void ui_mainwindow_action_help_welcome3 (GtkButton
*button
, gpointer user_data
)
941 gtk_dialog_response (GTK_DIALOG(user_data
), 3);
944 static void ui_mainwindow_action_help_welcome4 (GtkButton
*button
, gpointer user_data
)
946 gtk_dialog_response (GTK_DIALOG(user_data
), 4);
949 static void ui_mainwindow_action_help_welcome5 (GtkButton
*button
, gpointer user_data
)
951 gtk_dialog_response (GTK_DIALOG(user_data
), 5);
954 void ui_mainwindow_action_help_welcome(void)
956 GtkWidget
*dialog
, *content_area
;
957 GtkWidget
*mainvbox
, *widget
, *label
;
959 dialog
= gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
960 GTK_WINDOW(GLOBALS
->mainwindow
),
966 content_area
= gtk_dialog_get_content_area(GTK_DIALOG (dialog
));
968 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
969 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, FALSE
, FALSE
, 0);
970 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
972 label
= make_label (_("HomeBank"), 0, 0);
973 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
974 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
976 label
= make_label (_("Free, easy, personal accounting for everyone"), 0, 0);
977 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
979 widget
= gtk_separator_new(GTK_ORIENTATION_HORIZONTAL
);
980 gtk_box_pack_start (GTK_BOX (content_area
), widget
, FALSE
, FALSE
, 0);
982 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, SPACING_MEDIUM
);
983 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, TRUE
, TRUE
, 0);
984 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
986 label
= make_label (_("What do you want to do:"), 0, 0);
987 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
988 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
990 widget
= gtk_button_new_with_mnemonic(_("Read HomeBank _Manual"));
991 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
992 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome1
), dialog
);
994 widget
= gtk_button_new_with_mnemonic(_("Configure _preferences"));
995 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
996 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome2
), dialog
);
998 widget
= gtk_button_new_with_mnemonic(_("Create a _new file"));
999 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
1000 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome3
), dialog
);
1002 widget
= gtk_button_new_with_mnemonic(_("_Open an existing file"));
1003 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
1004 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome4
), dialog
);
1006 widget
= gtk_button_new_with_mnemonic(_("Open the _example file"));
1007 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
1008 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome5
), dialog
);
1010 //connect all our signals
1011 g_signal_connect (dialog
, "destroy", G_CALLBACK (gtk_widget_destroyed
), &dialog
);
1013 gtk_widget_show_all (dialog
);
1016 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
1018 // cleanup and destroy
1019 gtk_widget_destroy (dialog
);
1021 // do appropriate action
1025 ui_mainwindow_action_help();
1028 ui_mainwindow_action_preferences();
1031 ui_mainwindow_action_new();
1034 ui_mainwindow_action_open();
1037 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL
));
1038 ui_mainwindow_open_internal(GLOBALS
->mainwindow
, NULL
);
1045 static void ui_mainwindow_action_help_updates(void)
1047 const gchar
*link
= HOMEBANK_URL_HELP_UPDATES
;
1049 homebank_util_url_show (link
);
1053 static void ui_mainwindow_action_help_online(void)
1055 const gchar
*link
= HOMEBANK_URL_HELP_ONLINE
;
1057 homebank_util_url_show (link
);
1061 static void ui_mainwindow_action_help_translate(void)
1063 const gchar
*link
= HOMEBANK_URL_HELP_TRANSLATE
;
1065 homebank_util_url_show (link
);
1069 static void ui_mainwindow_action_help_problem(void)
1071 const gchar
*link
= HOMEBANK_URL_HELP_PROBLEM
;
1073 homebank_util_url_show (link
);
1077 /* hbfile functions -------------------- */
1083 static void ui_mainwindow_selection(GtkTreeSelection
*treeselection
, gpointer user_data
)
1085 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
1089 static void ui_mainwindow_close_openbooks(void)
1093 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
1095 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1098 Account
*item
= elt
->data
;
1102 gtk_widget_destroy(GTK_WIDGET(item
->window
));
1103 item
->window
= NULL
;
1106 elt
= g_list_next(elt
);
1117 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
)
1119 struct hbfile_data
*data
;
1120 gboolean file_clear
= GPOINTER_TO_INT(user_data
);
1122 DB( g_print("\n[ui-mainwindow] clear\n") );
1124 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1126 // Close opened account window
1128 ui_mainwindow_close_openbooks();
1129 gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_acc
))));
1130 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
))));
1131 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_top
))));
1133 data
->showall
= FALSE
;
1134 ui_hub_account_setup(data
);
1136 hbfile_cleanup(file_clear
);
1137 hbfile_setup(file_clear
);
1143 ** add some transactions directly
1145 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
)
1147 struct hbfile_data
*data
;
1151 gint account
, count
;
1153 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1155 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1157 /* init the transaction */
1158 date
= homebank_app_date_get_julian();
1162 if(data
->acc
!= NULL
)
1163 account
= data
->acc
->key
;
1165 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
, FALSE
, account
);
1167 while(result
== HB_RESPONSE_ADD
|| result
== HB_RESPONSE_ADDKEEP
)
1171 /* fill in the transaction */
1172 if( result
== HB_RESPONSE_ADD
)
1174 ope
= da_transaction_malloc();
1176 ope
->kacc
= account
;
1178 if( PREFS
->heritdate
== FALSE
) //fix: 318733
1179 ope
->date
= GLOBALS
->today
;
1181 da_transaction_set_default_template(ope
);
1184 // normally we can't be in addkeep without initialized ope with add
1186 deftransaction_set_transaction(window
, ope
);
1188 result
= gtk_dialog_run (GTK_DIALOG (window
));
1190 DB( g_print(" - dialog result is %d\n", result
) );
1192 if(result
== HB_RESPONSE_ADD
|| result
== HB_RESPONSE_ADDKEEP
|| result
== GTK_RESPONSE_ACCEPT
)
1194 deftransaction_get(window
, NULL
);
1195 transaction_add(GTK_WINDOW(GLOBALS
->mainwindow
), ope
);
1197 DB( g_print(" - added 1 transaction to %d\n", ope
->kacc
) );
1199 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1202 //todo: still usefull ? store last date
1206 if( result
== HB_RESPONSE_ADD
)
1208 da_transaction_free(ope
);
1215 deftransaction_dispose(window
, NULL
);
1216 gtk_widget_destroy (window
);
1218 /* todo optimize this */
1221 GLOBALS
->changes_count
+= count
;
1222 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
1227 gboolean
ui_mainwindow_open_backup_check_confirm(gchar
*filepath
)
1229 gboolean retval
= FALSE
;
1230 gchar
*basename
, *secondtext
;
1233 basename
= g_path_get_basename(filepath
);
1234 secondtext
= g_strdup_printf (
1235 _("Your are about to open the backup file '%s'.\n\nAre you sure you want to do this ?"), basename
);
1237 result
= ui_dialog_msg_confirm_alert(
1238 GTK_WINDOW(GLOBALS
->mainwindow
),
1239 _("Open the backup file ?"),
1247 if( result
== GTK_RESPONSE_OK
)
1257 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
)
1259 //struct hbfile_data *data;
1260 gboolean bakmode
= GPOINTER_TO_INT(user_data
);;
1261 gboolean doopen
= TRUE
;
1262 gchar
*filename
= NULL
;
1264 DB( g_print("\n[ui-mainwindow] open\n") );
1266 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1268 //#1791554 do ask for save confirm
1269 if( bakmode
!= TRUE
)
1270 doopen
= ui_dialog_msg_savechanges(widget
,NULL
);
1272 if( doopen
== TRUE
)
1274 if( ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN
, &filename
, bakmode
) == TRUE
)
1276 //#1710955 test for backup open
1277 if( hbfile_file_isbackup(filename
) )
1279 if( ui_mainwindow_open_backup_check_confirm(filename
) == TRUE
)
1281 GLOBALS
->hbfile_is_bak
= TRUE
;
1290 hbfile_change_filepath(filename
);
1291 ui_mainwindow_open_internal(widget
, NULL
);
1298 * open the file stored in GLOBALS->xhb_filepath
1300 void ui_mainwindow_open_internal(GtkWidget
*widget
, gpointer user_data
)
1302 struct hbfile_data
*data
;
1305 DB( g_print("\n[ui-mainwindow] open internal\n") );
1307 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1309 if( GLOBALS
->xhb_filepath
!= NULL
)
1311 DB( g_print(" - filename: '%s'\n", GLOBALS
->xhb_filepath
) );
1313 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
1314 GLOBALS
->hbfile_is_new
= FALSE
;
1316 r
= homebank_load_xml(GLOBALS
->xhb_filepath
);
1319 DB( g_print(" - file loaded ok : rcode=%d\n", r
) );
1321 GLOBALS
->xhb_timemodified
= hbfile_file_get_time_modified(GLOBALS
->xhb_filepath
);
1322 hbfile_file_hasrevert(GLOBALS
->xhb_filepath
);
1324 if(PREFS
->appendscheduled
)
1325 scheduled_post_all_pending();
1327 if(PREFS
->do_update_currency
)
1328 ui_cur_manage_dialog_update_currencies(GTK_WINDOW(GLOBALS
->mainwindow
));
1330 homebank_lastopenedfiles_save();
1332 //todo: delete this after computing done at xml read
1333 account_compute_balances();
1335 ui_mainwindow_recent_add(data
, GLOBALS
->xhb_filepath
);
1339 gchar
*msg
= _("Unknown error");
1344 msg
= _("I/O error for file '%s'.");
1346 case XML_FILE_ERROR
:
1347 msg
= _("The file '%s' is not a valid HomeBank file.");
1349 case XML_VERSION_ERROR
:
1350 msg
= _("The file '%s' was saved with a higher version of HomeBank\nand cannot be loaded by the current version.");
1354 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1357 GLOBALS
->xhb_filepath
1360 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
1364 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1365 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1366 ui_hub_spending_populate(GLOBALS
->mainwindow
, NULL
);
1367 ui_hub_transaction_populate(data
);
1369 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1379 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
)
1381 struct hbfile_data
*data
;
1382 gboolean saveas
= GPOINTER_TO_INT(user_data
);
1383 gchar
*filename
= NULL
;
1386 DB( g_print("\n[ui-mainwindow] save\n") );
1388 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1390 if( GLOBALS
->hbfile_is_new
== TRUE
)
1393 //#1710955 test for backup open
1394 if( GLOBALS
->hbfile_is_bak
== TRUE
)
1396 //todo: later for backup, should also remove datetime and .bak
1397 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb"));
1403 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE
, &filename
, FALSE
) == TRUE
)
1405 DB( g_print(" + should save as '%s'\n", filename
) );
1406 homebank_file_ensure_xhb(filename
);
1407 homebank_backup_current_file();
1408 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1409 GLOBALS
->hbfile_is_new
= FALSE
;
1410 GLOBALS
->hbfile_is_bak
= FALSE
;
1417 guint64 time_modified
= hbfile_file_get_time_modified (GLOBALS
->xhb_filepath
);
1418 gint result
= GTK_RESPONSE_OK
;
1420 DB( g_print(" + should quick save '%s'\n + time: open=%lu :: now=%lu\n", GLOBALS
->xhb_filepath
, GLOBALS
->xhb_timemodified
, time_modified
) );
1422 if( GLOBALS
->xhb_timemodified
!= time_modified
)
1424 result
= ui_dialog_msg_confirm_alert(
1425 GTK_WINDOW(GLOBALS
->mainwindow
),
1426 _("The file has been modified since reading it."),
1427 _("If you save it, all the external changes could be lost. Save it anyway?"),
1431 if( result
!= GTK_RESPONSE_OK
)
1435 DB( g_print(" + saving...\n") );
1436 homebank_file_ensure_xhb(NULL
);
1437 homebank_backup_current_file();
1438 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1443 DB( g_print(" + OK...\n") );
1444 GLOBALS
->changes_count
= 0;
1445 GLOBALS
->xhb_timemodified
= hbfile_file_get_time_modified (GLOBALS
->xhb_filepath
);
1446 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1450 gchar
*msg
= _("I/O error for file '%s'.");
1452 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1455 GLOBALS
->xhb_filepath
1461 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
)
1463 struct hbfile_data
*data
;
1466 DB( g_print("\n[ui-mainwindow] update %p\n", user_data
) );
1468 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1469 //data = INST_DATA(widget);
1471 flags
= GPOINTER_TO_INT(user_data
);
1473 /* set window title */
1474 if(flags
& UF_TITLE
)
1479 DB( g_print(" 1: wintitle %p\n", data
->wintitle
) );
1481 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
1483 DB( g_print(" global changes: %d\n", GLOBALS
->changes_count
) );
1485 g_free(data
->wintitle
);
1487 changed
= (GLOBALS
->changes_count
> 0) ? "*" : "";
1490 data
->wintitle
= g_strdup_printf("%s%s (%d)- %s - " PROGNAME
, changed
, basename
, GLOBALS
->changes_count
, GLOBALS
->owner
);
1492 data
->wintitle
= g_strdup_printf("%s%s - %s - " PROGNAME
, changed
, basename
, GLOBALS
->owner
);
1495 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), data
->wintitle
);
1500 /* update disabled things */
1501 if(flags
& UF_SENSITIVE
)
1503 GtkTreeSelection
*selection
;
1504 GtkTreeModel
*model
;
1507 gboolean active
,sensitive
;
1509 DB( g_print(" 2: disabled, opelist count\n") );
1514 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
));
1515 active
= gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1521 path
= gtk_tree_model_get_path(model
, &iter
);
1522 depth
= gtk_tree_path_get_depth(path
);
1526 DB( g_print(" depth is %d\n", depth
) );
1528 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1535 DB( g_print(" changes %d - new %d\n", GLOBALS
->changes_count
, GLOBALS
->hbfile_is_new
) );
1538 sensitive
= (GLOBALS
->changes_count
!= 0 ) ? TRUE
: FALSE
;
1539 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Save"), sensitive
);
1542 sensitive
= ( (GLOBALS
->changes_count
!= 0) && GLOBALS
->xhb_hasrevert
) ? TRUE
: FALSE
;
1543 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Revert"), sensitive
);
1544 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/OpenBak"), sensitive
);
1547 sensitive
= GLOBALS
->define_off
== 0 ? TRUE
: FALSE
;
1548 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Account"), sensitive
);
1549 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Payee"), sensitive
);
1550 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Category"), sensitive
);
1551 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1552 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/EditMenu/Preferences"), sensitive
);
1554 // empty account list: disable Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
1555 sensitive
= da_acc_length() > 0 ? TRUE
: FALSE
;
1556 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Close"), sensitive
);
1557 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Archive"), sensitive
);
1558 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddTxn"), sensitive
);
1559 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowTxn"), sensitive
);
1560 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RStatistics"), sensitive
);
1561 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RTrendTime"), sensitive
);
1562 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBudget"), sensitive
);
1563 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBalance"), sensitive
);
1564 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RVehiculeCost"), sensitive
);
1566 // empty category list: disable Budget
1567 sensitive
= da_cat_length() > 1 ? TRUE
: FALSE
;
1568 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1570 //#1501129 no need to disable, P & C can be created from assign dialog
1571 //sensitive = ((da_cat_length() > 1) || (da_pay_length() > 1)) ? TRUE : FALSE;
1572 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Assign"), sensitive);
1574 // empty archive list: disable scheduled check
1575 sensitive
= g_list_length(GLOBALS
->arc_list
) > 0 ? TRUE
: FALSE
;
1576 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddScheduled"), sensitive
);
1578 // no active account: disable Edit, Over
1580 /* sensitive = (active == TRUE ) ? TRUE : FALSE;
1581 if(data->acc && data->acc->window != NULL)
1583 gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/TxnMenu/ShowTxn"), sensitive);
1587 /* update toolbar, list */
1588 if(flags
& UF_VISUAL
)
1590 DB( g_print(" 8: visual\n") );
1592 if(PREFS
->toolbar_style
== 0)
1593 gtk_toolbar_unset_style(GTK_TOOLBAR(data
->toolbar
));
1595 gtk_toolbar_set_style(GTK_TOOLBAR(data
->toolbar
), PREFS
->toolbar_style
-1);
1597 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_acc
), PREFS
->grid_lines
);
1598 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
1600 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_upc
), PREFS
->grid_lines
);
1601 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
1603 DB( g_print(" - show toolbar=%d\n", PREFS
->wal_toolbar
) );
1604 if(PREFS
->wal_toolbar
)
1605 gtk_widget_show(GTK_WIDGET(data
->toolbar
));
1607 gtk_widget_hide(GTK_WIDGET(data
->toolbar
));
1610 DB( g_print(" - show top_spending=%d\n", PREFS
->wal_spending
) );
1612 hbtk_combo_box_set_active_id(GTK_COMBO_BOX_TEXT(data
->CY_range
), PREFS
->date_range_wal
);
1614 if(PREFS
->wal_spending
)
1615 gtk_widget_show(GTK_WIDGET(data
->GR_top
));
1617 gtk_widget_hide(GTK_WIDGET(data
->GR_top
));
1621 DB( g_print(" - show upcoming=%d\n", PREFS
->wal_upcoming
) );
1622 if(PREFS
->wal_upcoming
)
1623 gtk_widget_show(GTK_WIDGET(data
->GR_upc
));
1625 gtk_widget_hide(GTK_WIDGET(data
->GR_upc
));
1627 DB( g_print(" minor %d\n", PREFS
->euro_active
) );
1628 gtk_action_set_visible(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor"), PREFS
->euro_active
);
1631 /* update balances */
1632 if(flags
& UF_BALANCE
)
1635 DB( g_print(" 4: balances\n") );
1637 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
1639 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
1642 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[0]), data->bank, minor);
1643 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[1]), data->today, minor);
1644 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[2]), data->future, minor);
1648 if(flags
& UF_REFRESHALL
)
1650 DB( g_print(" 16: refreshall\n") );
1652 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1653 ui_hub_spending_populate(GLOBALS
->mainwindow
, NULL
);
1654 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1655 ui_hub_transaction_populate(data
);
1664 ui_mainwindow_onRowActivated (GtkTreeView
*treeview
,
1666 GtkTreeViewColumn
*col
,
1669 GtkTreeModel
*model
;
1672 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
1674 model
= gtk_tree_view_get_model(treeview
);
1676 if (gtk_tree_model_get_iter(model
, &iter
, path
))
1680 gtk_tree_model_get(model
, &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1685 DB( g_print ("Double-clicked row contains name %s\n", acc
->name
) );
1687 ui_mainwindow_action_showtransactions(NULL
);
1695 static void ui_mainwindow_destroy(GtkTreeView
*treeview
, gpointer user_data
)
1697 DB( g_print("\n[ui-mainwindow] destroy\n") );
1705 static gboolean
ui_mainwindow_dispose(GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
1707 struct hbfile_data
*data
= user_data
;
1708 struct WinGeometry
*wg
;
1709 gboolean retval
= FALSE
;
1711 GValue widget_value
= G_VALUE_INIT
;
1712 ext_hook("main_window_disposal", EXT_OBJECT(&widget_value
, widget
), NULL
);
1714 DB( g_print("\n[ui-mainwindow] delete-event\n") );
1716 //store position and size
1717 wg
= &PREFS
->wal_wg
;
1718 gtk_window_get_position(GTK_WINDOW(widget
), &wg
->l
, &wg
->t
);
1719 gtk_window_get_size(GTK_WINDOW(widget
), &wg
->w
, &wg
->h
);
1720 GdkWindow
*gdk_window
= gtk_widget_get_window(GTK_WIDGET(widget
));
1721 GdkWindowState state
= gdk_window_get_state(gdk_window
);
1722 wg
->s
= (state
& GDK_WINDOW_STATE_MAXIMIZED
) ? 1 : 0;
1723 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
) );
1725 PREFS
->wal_vpaned
= gtk_paned_get_position(GTK_PANED(data
->vpaned
));
1726 PREFS
->wal_hpaned
= gtk_paned_get_position(GTK_PANED(data
->hpaned
));
1727 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
1729 if(PREFS
->pnl_list_tab
)
1730 g_free(PREFS
->pnl_list_tab
);
1731 PREFS
->pnl_list_tab
= g_strdup(gtk_stack_get_visible_child_name(GTK_STACK(data
->stack
)));
1734 if(ui_dialog_msg_savechanges(widget
, NULL
) == FALSE
)
1740 //todo: retval is useless and below should move to destroy
1742 gtk_widget_destroy(data
->LV_top
);
1744 g_free(data
->wintitle
);
1745 da_flt_free(data
->filter
);
1751 //TRUE:stop other handlers from being invoked for the event | FALSE: propagate
1756 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser
*chooser
, struct hbfile_data
*data
)
1759 GError
*error
= NULL
;
1761 uri
= gtk_recent_chooser_get_current_uri (chooser
);
1763 path
= g_filename_from_uri (uri
, NULL
, NULL
);
1766 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
1767 g_error_free (error
);
1771 if( ui_dialog_msg_savechanges(data
->window
, NULL
) == TRUE
)
1778 gpw_recent_remove (gpw, path);
1782 hbfile_change_filepath(path
);
1783 ui_mainwindow_open_internal(data
->window
, NULL
);
1793 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
)
1795 GtkRecentData
*recent_data
;
1797 GError
*error
= NULL
;
1799 DB( g_print("\n[ui-mainwindow] recent_add\n") );
1801 DB( g_print(" - file has .xhb suffix = %d\n", g_str_has_suffix (path
, ".xhb") ) );
1803 if( g_str_has_suffix (path
, ".xhb") == FALSE
) //ignore reverted file
1806 uri
= g_filename_to_uri (path
, NULL
, &error
);
1809 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
1810 g_error_free (error
);
1814 recent_data
= g_slice_new (GtkRecentData
);
1816 recent_data
->display_name
= NULL
;
1817 recent_data
->description
= NULL
;
1818 recent_data
->mime_type
= "application/x-homebank";
1819 recent_data
->app_name
= (gchar
*) g_get_application_name ();
1820 recent_data
->app_exec
= g_strjoin (" ", g_get_prgname (), "%u", NULL
);
1821 recent_data
->groups
= NULL
;
1822 recent_data
->is_private
= FALSE
;
1824 if (!gtk_recent_manager_add_full (data
->recent_manager
,
1828 g_warning ("Unable to add '%s' to the list of recently used documents", uri
);
1832 g_free (recent_data
->app_exec
);
1833 g_slice_free (GtkRecentData
, recent_data
);
1846 static GtkTargetEntry drop_types
[] =
1848 {"text/uri-list", 0, TARGET_URI_LIST
}
1851 static void ui_mainwindow_drag_data_received (GtkWidget
*widget
,
1852 GdkDragContext
*context
,
1854 GtkSelectionData
*selection_data
,
1855 guint info
, guint time
, GtkWindow
*window
)
1857 gchar
**uris
, **str
;
1859 gint n_uris
, filetype
, slen
;
1860 GError
*error
= NULL
;
1862 if (info
!= TARGET_URI_LIST
)
1865 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
1867 /* On MS-Windows, it looks like `selection_data->data' is not NULL terminated. */
1868 slen
= gtk_selection_data_get_length(selection_data
);
1869 newseldata
= g_new (gchar
, slen
+ 1);
1870 memcpy (newseldata
, gtk_selection_data_get_data(selection_data
), slen
);
1871 newseldata
[slen
] = 0;
1872 //DB( g_print(" - seldata ='%s'\n", gtk_selection_data_get_data(selection_data) ) );
1873 //DB( g_print(" - newseldata ='%s'\n", newseldata ) );
1875 uris
= g_uri_list_extract_uris (newseldata
);
1876 n_uris
= g_strv_length(uris
);
1877 DB( g_print(" - dragged %d files (len=%d)\n", n_uris
, slen
) );
1881 //single file: check for xhb
1884 filetype
= hb_filename_type_get_by_extension(*uris
);
1886 DB( g_print(" - filetype is homebank (%d)\n", filetype
) );
1888 if( filetype
== FILETYPE_HOMEBANK
)
1890 gchar
*path
= g_filename_from_uri (*uris
, NULL
, &error
);
1894 DB( g_print(" - path is '%s'\n", path
) );
1895 hbfile_change_filepath(g_strdup(path
));
1896 ui_mainwindow_open_internal(GTK_WIDGET(window
), NULL
);
1901 g_warning ("Could not convert uri to local path: %s", error
->message
);
1902 g_error_free (error
);
1906 /* we no more manage error here
1907 ui_dialog_msg_infoerror(GTK_WINDOW(window), GTK_MESSAGE_ERROR,
1909 _("The file %s is not a valid HomeBank file."),
1914 //collect known filetype to import
1915 DB( g_print(" - collect %d files\n", n_uris
) );
1917 gchar
**paths
= g_new (gchar
*, n_uris
+ 1);
1919 for (str
= uris
; *str
; str
++)
1921 filetype
= hb_filename_type_get_by_extension(*str
);
1922 if( filetype
!= FILETYPE_HOMEBANK
&& filetype
!= FILETYPE_UNKNOWN
)
1924 gchar
*path
= g_filename_from_uri (*str
, NULL
, NULL
);
1928 DB( g_print(" - append %d '%s'\n", slen
, path
) );
1929 paths
[slen
++] = path
;
1937 ui_import_assistant_new( paths
);
1946 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
)
1948 GtkWidget
*recent_menu
;
1949 GtkRecentFilter
*filter
;
1951 recent_menu
= gtk_recent_chooser_menu_new_for_manager (manager
);
1952 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu
), FALSE
);
1953 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu
), GTK_RECENT_SORT_MRU
);
1954 //todo: add a user pref for this
1955 gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER (recent_menu
), 10);
1956 gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu
), FALSE
);
1957 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_menu), TRUE);
1959 filter
= gtk_recent_filter_new ();
1960 //gtk_recent_filter_add_application (filter, g_get_application_name());
1961 gtk_recent_filter_add_pattern (filter
, "*.[Xx][Hh][Bb]");
1962 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu
), filter
);
1968 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data
*data
, GtkWidget
*mainvbox
)
1970 GtkUIManager
*manager
;
1971 GtkActionGroup
*actions
;
1973 GError
*error
= NULL
;
1975 manager
= gtk_ui_manager_new ();
1976 data
->manager
= manager
;
1978 gtk_window_add_accel_group (GTK_WINDOW (data
->window
),
1979 gtk_ui_manager_get_accel_group(manager
));
1981 actions
= gtk_action_group_new ("MainWindow");
1982 gtk_action_group_set_translation_domain(actions
, GETTEXT_PACKAGE
);
1984 gtk_action_group_add_actions (actions
,
1989 gtk_action_group_add_toggle_actions (actions
,
1994 gtk_ui_manager_insert_action_group (data
->manager
, actions
, 0);
1995 g_object_unref (actions
);
1996 data
->actions
= actions
;
1998 /* set short labels to use in the toolbar */
1999 action
= gtk_action_group_get_action(actions
, "Open");
2000 g_object_set(action
, "short_label", _("Open"), NULL
);
2002 //action = gtk_action_group_get_action(action_group, "Save");
2003 //g_object_set(action, "is_important", TRUE, NULL);
2005 action
= gtk_action_group_get_action(actions
, "Account");
2006 g_object_set(action
, "short_label", _("Account"), NULL
);
2008 action
= gtk_action_group_get_action(actions
, "Payee");
2009 g_object_set(action
, "short_label", _("Payee"), NULL
);
2011 action
= gtk_action_group_get_action(actions
, "Category");
2012 g_object_set(action
, "short_label", _("Category"), NULL
);
2014 action
= gtk_action_group_get_action(actions
, "Archive");
2015 //TRANSLATORS: an archive is stored transaction buffers (kind of bookmark to prefill manual insertion)
2016 g_object_set(action
, "short_label", _("Archive"), NULL
);
2018 action
= gtk_action_group_get_action(actions
, "Budget");
2019 g_object_set(action
, "short_label", _("Budget"), NULL
);
2021 action
= gtk_action_group_get_action(actions
, "ShowTxn");
2022 g_object_set(action
, "short_label", _("Show"), NULL
);
2024 action
= gtk_action_group_get_action(actions
, "AddTxn");
2025 g_object_set(action
, "is_important", TRUE
, "short_label", _("Add"), NULL
);
2027 action
= gtk_action_group_get_action(actions
, "RStatistics");
2028 g_object_set(action
, "short_label", _("Statistics"), NULL
);
2030 action
= gtk_action_group_get_action(actions
, "RBudget");
2031 g_object_set(action
, "short_label", _("Budget"), NULL
);
2033 action
= gtk_action_group_get_action(actions
, "RBalance");
2034 g_object_set(action
, "short_label", _("Balance"), NULL
);
2036 action
= gtk_action_group_get_action(actions
, "RVehiculeCost");
2037 g_object_set(action
, "short_label", _("Vehicle cost"), NULL
);
2039 /* now load the UI definition */
2040 gtk_ui_manager_add_ui_from_string (data
->manager
, ui_info
, -1, &error
);
2043 g_message ("Building menus failed: %s", error
->message
);
2044 g_error_free (error
);
2048 data
->recent_manager
= gtk_recent_manager_get_default ();
2050 data
->menubar
= gtk_ui_manager_get_widget (manager
, "/MenuBar");
2051 gtk_box_pack_start (GTK_BOX (mainvbox
),
2057 /* recent files menu */
2058 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2060 g_signal_connect (data
->recent_menu
,
2062 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2065 GtkWidget
*widget
= gtk_ui_manager_get_widget (data
->manager
, "/MenuBar/FileMenu/RecentMenu");
2066 gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget
), data
->recent_menu
);
2069 data
->toolbar
= gtk_ui_manager_get_widget (manager
, "/ToolBar");
2070 gtk_box_pack_start (GTK_BOX (mainvbox
),
2076 /* add the custom Open button to the toolbar */
2077 GtkWidget
*image
= gtk_image_new_from_icon_name (ICONNAME_HB_FILE_OPEN
, GTK_ICON_SIZE_BUTTON
);
2078 GtkToolItem
*open_button
= gtk_menu_tool_button_new(image
, _("_Open"));
2079 gtk_tool_item_set_tooltip_text (open_button
, _("Open a file"));
2081 GtkWidget
*recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2082 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button
), recent_menu
);
2083 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button
), _("Open a recently used file"));
2085 g_signal_connect (recent_menu
,
2087 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2090 action
= gtk_action_group_get_action (data
->actions
, "Open");
2091 g_object_set (action
, "short_label", _("Open"), NULL
);
2092 //gtk_action_connect_proxy (action, GTK_WIDGET (open_button));
2093 gtk_activatable_set_related_action (GTK_ACTIVATABLE (open_button
), action
);
2095 gtk_toolbar_insert (GTK_TOOLBAR (data
->toolbar
), open_button
, 1);
2101 ** the window creation
2103 GtkWidget
*create_hbfile_window(GtkWidget
*do_widget
)
2105 struct hbfile_data
*data
;
2106 struct WinGeometry
*wg
;
2107 GtkWidget
*mainvbox
, *vbox
, *box
, *vpaned
, *hpaned
, *sidebar
, *stack
;
2108 GtkWidget
*widget
, *page
;
2112 DB( g_print("\n[ui-mainwindow] create main window\n") );
2114 data
= g_malloc0(sizeof(struct hbfile_data
));
2115 if(!data
) return NULL
;
2117 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
2119 //store our window private data
2120 g_object_set_data(G_OBJECT(window
), "inst_data", (gpointer
)data
);
2121 DB( g_print(" - new window=%p, inst_data=%p\n", window
, data
) );
2123 // this is our mainwindow, so store it to GLOBALS data
2124 data
->window
= window
;
2125 GLOBALS
->mainwindow
= window
;
2127 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2128 gtk_container_add (GTK_CONTAINER (window
), mainvbox
);
2130 ui_mainwindow_create_menu_bar_and_toolbar (data
, mainvbox
);
2132 #if HB_UNSTABLE_SHOW == TRUE
2133 GtkWidget
*bar
, *label
;
2135 bar
= gtk_info_bar_new ();
2136 gtk_box_pack_start (GTK_BOX (mainvbox
), bar
, FALSE
, FALSE
, 0);
2137 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar
), GTK_MESSAGE_WARNING
);
2138 label
= make_label(NULL
, 0.5, 0.5);
2139 gtk_label_set_markup (GTK_LABEL(label
), "Unstable Development Version");
2140 gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar
))), label
, FALSE
, FALSE
, 0);
2143 /* Add the main area */
2144 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2145 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
2146 gtk_box_pack_start (GTK_BOX (mainvbox
), vbox
, TRUE
, TRUE
, 0);
2148 vpaned
= gtk_paned_new(GTK_ORIENTATION_VERTICAL
);
2149 data
->vpaned
= vpaned
;
2150 gtk_box_pack_start (GTK_BOX (vbox
), vpaned
, TRUE
, TRUE
, 0);
2152 hpaned
= gtk_paned_new(GTK_ORIENTATION_HORIZONTAL
);
2153 data
->hpaned
= hpaned
;
2154 gtk_paned_pack1 (GTK_PANED(vpaned
), hpaned
, FALSE
, FALSE
);
2156 widget
= ui_hub_account_create(data
);
2157 //gtk_widget_set_size_request (widget, 100, -1);
2158 gtk_paned_pack1 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
2160 widget
= ui_hub_spending_create(data
);
2161 //gtk_widget_set_size_request (widget, -1, 100);
2162 gtk_paned_pack2 (GTK_PANED(hpaned
), widget
, TRUE
, FALSE
);
2164 box
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
2166 gtk_paned_pack2 (GTK_PANED(vpaned
), box
, TRUE
, FALSE
);
2168 sidebar
= gtk_stack_sidebar_new ();
2169 gtk_box_pack_start (GTK_BOX (box
), sidebar
, FALSE
, FALSE
, 0);
2171 stack
= gtk_stack_new ();
2172 //gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN);
2173 gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar
), GTK_STACK (stack
));
2174 data
->stack
= stack
;
2175 gtk_box_pack_start (GTK_BOX (box
), stack
, TRUE
, TRUE
, 0);
2177 page
= ui_hub_scheduled_create(data
);
2178 gtk_stack_add_titled (GTK_STACK (stack
), page
, "sched", _("Scheduled"));
2179 //gtk_paned_pack2 (GTK_PANED(vpaned), widget, TRUE, FALSE);
2181 page
= ui_hub_transaction_create(data
, HUB_TXN_TYPE_FUTURE
);
2182 gtk_stack_add_titled (GTK_STACK (stack
), page
, "futur", _("Future"));
2184 page
= ui_hub_transaction_create(data
, HUB_TXN_TYPE_REMIND
);
2185 gtk_stack_add_titled (GTK_STACK (stack
), page
, "remin", _("Remind"));
2188 //setup, init and show window
2189 wg
= &PREFS
->wal_wg
;
2192 gtk_window_move(GTK_WINDOW(window
), wg
->l
, wg
->t
);
2193 gtk_window_resize(GTK_WINDOW(window
), wg
->w
, wg
->h
);
2196 gtk_window_maximize(GTK_WINDOW(window
));
2198 gtk_widget_show_all (window
);
2200 //#1662197/1660910 moved after resize/show
2201 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
2203 if(PREFS
->wal_hpaned
> 0)
2204 gtk_paned_set_position(GTK_PANED(data
->hpaned
), PREFS
->wal_hpaned
);
2205 if(PREFS
->wal_vpaned
> 0)
2206 gtk_paned_set_position(GTK_PANED(data
->vpaned
), PREFS
->wal_vpaned
);
2208 if( PREFS
->pnl_list_tab
!= NULL
)
2209 gtk_stack_set_visible_child_name (GTK_STACK(data
->stack
), PREFS
->pnl_list_tab
);
2212 //todo: move this elsewhere
2213 DB( g_print(" - setup stuff\n") );
2215 data
->filter
= da_flt_malloc();
2216 filter_reset(data
->filter
);
2217 hbtk_combo_box_set_active_id(GTK_COMBO_BOX_TEXT(data
->CY_range
), PREFS
->date_range_wal
);
2219 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Toolbar");
2220 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_toolbar
);
2221 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Spending");
2222 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_spending
);
2223 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/BottomLists");
2224 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_upcoming
);
2226 /* Drag and drop support, set targets to NULL because we add the
2227 default uri_targets below */
2229 /* support for opening a file by dragging onto the project window */
2230 gtk_drag_dest_set (GTK_WIDGET (window
),
2231 GTK_DEST_DEFAULT_ALL
,
2233 G_N_ELEMENTS (drop_types
),
2236 g_signal_connect (G_OBJECT (window
), "drag-data-received",
2237 G_CALLBACK (ui_mainwindow_drag_data_received
), window
);
2239 //connect all our signals
2240 DB( g_print(" - connect signals\n") );
2242 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
)), "changed", G_CALLBACK (ui_mainwindow_selection
), NULL
);
2243 g_signal_connect (GTK_TREE_VIEW(data
->LV_acc
), "row-activated", G_CALLBACK (ui_mainwindow_onRowActivated
), GINT_TO_POINTER(2));
2245 /* GtkWindow events */
2246 g_signal_connect (window
, "delete-event", G_CALLBACK (ui_mainwindow_dispose
), (gpointer
)data
);
2247 g_signal_connect (window
, "destroy", G_CALLBACK (ui_mainwindow_destroy
), NULL
);
2249 //gtk_action_group_set_sensitive(data->actions, FALSE);