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(void);
114 static void ui_mainwindow_action_showalltransactions(void);
116 static void ui_mainwindow_action_addtransactions(void);
117 static void ui_mainwindow_action_checkscheduled(void);
119 static void ui_mainwindow_action_statistic(void);
120 static void ui_mainwindow_action_trendtime(void);
121 static void ui_mainwindow_action_budget(void);
122 static void ui_mainwindow_action_balance(void);
123 static void ui_mainwindow_action_vehiclecost(void);
125 static void ui_mainwindow_action_import(GtkAction
*action
);
126 static void ui_mainwindow_action_export(void);
127 static void ui_mainwindow_action_anonymize(void);
128 static void ui_mainwindow_action_file_statistics(void);
130 static void ui_mainwindow_action_pluginprefs(void);
132 static void ui_mainwindow_action_help(void);
133 void ui_mainwindow_action_help_welcome(void);
134 static void ui_mainwindow_action_help_online(void);
135 static void ui_mainwindow_action_help_updates(void);
136 static void ui_mainwindow_action_help_releasenotes(void);
137 static void ui_mainwindow_action_help_translate(void);
138 static void ui_mainwindow_action_help_problem(void);
139 static void ui_mainwindow_action_about(void);
142 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
);
144 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
);
146 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
);
147 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
);
148 void ui_mainwindow_action(GtkWidget
*widget
, gpointer user_data
);
149 void ui_mainwindow_toggle_minor(GtkWidget
*widget
, gpointer user_data
);
150 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
);
152 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
);
153 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
);
154 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
156 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
158 static void ui_mainwindow_showprefs(gint page
);
160 static GtkActionEntry entries
[] = {
162 /* name, icon-name, label */
164 { "FileMenu" , NULL
, N_("_File"), NULL
, NULL
, NULL
},
165 //{ "ImportMenu" , NULL, N_("_Import"), NULL, NULL, NULL },
166 { "RecentMenu" , NULL
, N_("Open _Recent"), NULL
, NULL
, NULL
},
167 { "EditMenu" , NULL
, N_("_Edit"), NULL
, NULL
, NULL
},
168 { "ViewMenu" , NULL
, N_("_View"), NULL
, NULL
, NULL
},
169 { "ManageMenu" , NULL
, N_("_Manage"), NULL
, NULL
, NULL
},
170 { "TxnMenu" , NULL
, N_("_Transactions"), NULL
, NULL
, NULL
},
171 { "ReportMenu" , NULL
, N_("_Reports"), NULL
, NULL
, NULL
},
172 { "ToolsMenu" , NULL
, N_("_Tools"), NULL
, NULL
, NULL
},
173 { "PluginMenu" , NULL
, N_("_Plugins"), NULL
, NULL
, NULL
},
174 { "HelpMenu" , NULL
, N_("_Help"), NULL
, NULL
, NULL
},
176 // { "Import" , NULL, N_("Import") },
177 // { "Export" , NULL, N_("Export to") },
178 /* name, icon-name, label, accelerator, tooltip */
181 { "New" , ICONNAME_HB_FILE_NEW
, N_("_New") , "<control>N", N_("Create a new file"), G_CALLBACK (ui_mainwindow_action_new
) },
182 { "Open" , ICONNAME_HB_FILE_OPEN
, N_("_Open...") , "<control>O", N_("Open a file"), G_CALLBACK (ui_mainwindow_action_open
) },
183 { "Save" , ICONNAME_HB_FILE_SAVE
, N_("_Save") , "<control>S", N_("Save the current file"), G_CALLBACK (ui_mainwindow_action_save
) },
184 { "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
) },
186 { "Revert" , ICONNAME_REVERT
, N_("Revert") , NULL
, N_("Revert to a saved version of this file"), G_CALLBACK (ui_mainwindow_action_revert
) },
187 { "OpenBak" , NULL
, N_("Restore backup") , NULL
, N_("Restore from a backup file"), G_CALLBACK (ui_mainwindow_action_openbak
) },
189 { "Properties" , ICONNAME_PROPERTIES
, N_("Properties..."), NULL
, N_("Configure the file"), G_CALLBACK (ui_mainwindow_action_properties
) },
190 { "Close" , ICONNAME_CLOSE
, N_("_Close") , "<control>W", N_("Close the current file"), G_CALLBACK (ui_mainwindow_action_close
) },
191 { "Quit" , ICONNAME_QUIT
, N_("_Quit") , "<control>Q", N_("Quit HomeBank"), G_CALLBACK (ui_mainwindow_action_quit
) },
194 { "Import" , ICONNAME_HB_FILE_IMPORT
, N_("Import...") , NULL
, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import
) },
195 //{ "ImportQIF" , ICONNAME_HB_FILE_IMPORT , N_("QIF file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
196 //{ "ImportOFX" , ICONNAME_HB_FILE_IMPORT , N_("OFX/QFX file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
197 //{ "ImportCSV" , ICONNAME_HB_FILE_IMPORT , N_("CSV file...") , NULL, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import) },
199 { "ExportQIF" , ICONNAME_HB_FILE_EXPORT
, N_("Export as QIF...") , NULL
, N_("Export all account in a QIF file"), G_CALLBACK (ui_mainwindow_action_export
) },
202 { "Preferences", ICONNAME_PREFERENCES
, N_("Preferences..."), NULL
, N_("Configure HomeBank"), G_CALLBACK (ui_mainwindow_action_preferences
) },
205 { "Currency" , ICONNAME_HB_CURRENCY
, N_("Currencies...") , NULL
, N_("Configure the currencies"), G_CALLBACK (ui_mainwindow_action_defcurrency
) },
206 { "Account" , ICONNAME_HB_ACCOUNT
, N_("Acc_ounts...") , NULL
, N_("Configure the accounts"), G_CALLBACK (ui_mainwindow_action_defaccount
) },
207 { "Payee" , ICONNAME_HB_PAYEE
, N_("_Payees...") , NULL
, N_("Configure the payees"), G_CALLBACK (ui_mainwindow_action_defpayee
) },
208 { "Category" , ICONNAME_HB_CATEGORY
, N_("Categories...") , NULL
, N_("Configure the categories"), G_CALLBACK (ui_mainwindow_action_defcategory
) },
209 { "Archive" , ICONNAME_HB_ARCHIVE
, N_("Scheduled/Template...") , NULL
, N_("Configure the scheduled/template transactions"), G_CALLBACK (ui_mainwindow_action_defarchive
) },
210 { "Budget" , ICONNAME_HB_BUDGET
, N_("Budget...") , NULL
, N_("Configure the budget"), G_CALLBACK (ui_mainwindow_action_defbudget
) },
211 { "Assign" , ICONNAME_HB_ASSIGN
, N_("Assignments..."), NULL
, N_("Configure the automatic assignments"), G_CALLBACK (ui_mainwindow_action_defassign
) },
212 { "Tag" , NULL
, N_("Tags..."), NULL
, N_("Configure the tags"), G_CALLBACK (ui_mainwindow_action_deftag
) },
215 { "AddTxn" , ICONNAME_HB_OPE_ADD
, N_("Add...") , NULL
, N_("Add transactions"), G_CALLBACK (ui_mainwindow_action_addtransactions
) },
216 { "ShowTxn" , ICONNAME_HB_OPE_SHOW
, N_("Show...") , NULL
, N_("Shows selected account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions
) },
217 { "ShowAllTxn" , ICONNAME_HB_OPE_SHOW
, N_("Show all...") , NULL
, N_("Shows all account transactions"), G_CALLBACK (ui_mainwindow_action_showalltransactions
) },
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(void)
780 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
786 if( data
->acc
->window
== NULL
)
788 window
= register_panel_window_new(data
->acc
);
789 register_panel_window_init(window
, NULL
);
793 if(GTK_IS_WINDOW(data
->acc
->window
))
794 gtk_window_present(GTK_WINDOW(data
->acc
->window
));
801 static void ui_mainwindow_action_showalltransactions(void)
805 if( GLOBALS
->alltxnwindow
== NULL
)
807 window
= register_panel_window_new(NULL
);
808 register_panel_window_init(window
, NULL
);
812 if(GTK_IS_WINDOW(GLOBALS
->alltxnwindow
))
813 gtk_window_present(GTK_WINDOW(GLOBALS
->alltxnwindow
));
819 static void ui_mainwindow_action_addtransactions(void)
821 ui_mainwindow_addtransactions(GLOBALS
->mainwindow
, NULL
);
824 static void ui_mainwindow_action_checkscheduled(void)
826 ui_hub_scheduled_postall(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
829 static void ui_mainwindow_action_statistic(void)
831 ui_repdist_window_new();
834 static void ui_mainwindow_action_trendtime(void)
836 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
838 ui_reptime_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
841 static void ui_mainwindow_action_budget(void)
843 repbudget_window_new();
846 static void ui_mainwindow_action_balance(void)
848 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
850 repbalance_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
853 static void ui_mainwindow_action_vehiclecost(void)
855 repcost_window_new();
858 static void ui_mainwindow_action_import(GtkAction
*action
)
861 gint filetype = FILETYPE_UNKNOWN;
863 name = gtk_action_get_name(action);
865 if( g_str_has_suffix (name, "QIF"))
866 filetype= FILETYPE_QIF;
868 if( g_str_has_suffix (name, "OFX"))
869 filetype= FILETYPE_OFX;
871 if( g_str_has_suffix (name, "CSV"))
872 filetype= FILETYPE_CSV_HB;*/
874 //DB( g_print("action %s type=%d\n", name, filetype) );
876 ui_import_assistant_new(NULL
);
881 static void ui_mainwindow_action_about(void)
889 static void ui_mainwindow_action_export(void)
893 if( ui_file_chooser_qif(NULL
, &filename
) == TRUE
)
895 hb_export_qif_account_all(filename
);
901 static void ui_mainwindow_action_help(void)
905 link
= g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP
, NULL
);
906 homebank_util_url_show (link
);
911 static void ui_mainwindow_action_help_releasenotes(void)
916 link
= g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog.txt", NULL
);
918 link
= g_build_filename("file:///", homebank_app_get_datas_dir(), "ChangeLog", NULL
);
920 homebank_util_url_show (link
);
925 //todo: move this to a ui-assist-welcome.c
927 static void ui_mainwindow_action_help_welcome1 (GtkButton
*button
, gpointer user_data
)
929 gtk_dialog_response (GTK_DIALOG(user_data
), 1);
932 static void ui_mainwindow_action_help_welcome2 (GtkButton
*button
, gpointer user_data
)
934 gtk_dialog_response (GTK_DIALOG(user_data
), 2);
937 static void ui_mainwindow_action_help_welcome3 (GtkButton
*button
, gpointer user_data
)
939 gtk_dialog_response (GTK_DIALOG(user_data
), 3);
942 static void ui_mainwindow_action_help_welcome4 (GtkButton
*button
, gpointer user_data
)
944 gtk_dialog_response (GTK_DIALOG(user_data
), 4);
947 static void ui_mainwindow_action_help_welcome5 (GtkButton
*button
, gpointer user_data
)
949 gtk_dialog_response (GTK_DIALOG(user_data
), 5);
952 void ui_mainwindow_action_help_welcome(void)
954 GtkWidget
*dialog
, *content_area
;
955 GtkWidget
*mainvbox
, *widget
, *label
;
957 dialog
= gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
958 GTK_WINDOW(GLOBALS
->mainwindow
),
964 content_area
= gtk_dialog_get_content_area(GTK_DIALOG (dialog
));
966 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
967 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, FALSE
, FALSE
, 0);
968 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
970 label
= make_label (_("HomeBank"), 0, 0);
971 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
972 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
974 label
= make_label (_("Free, easy, personal accounting for everyone"), 0, 0);
975 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
977 widget
= gtk_separator_new(GTK_ORIENTATION_HORIZONTAL
);
978 gtk_box_pack_start (GTK_BOX (content_area
), widget
, FALSE
, FALSE
, 0);
980 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, SPACING_MEDIUM
);
981 gtk_box_pack_start (GTK_BOX (content_area
), mainvbox
, TRUE
, TRUE
, 0);
982 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), SPACING_MEDIUM
);
984 label
= make_label (_("What do you want to do:"), 0, 0);
985 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
986 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
988 widget
= gtk_button_new_with_mnemonic(_("Read HomeBank _Manual"));
989 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
990 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome1
), dialog
);
992 widget
= gtk_button_new_with_mnemonic(_("Configure _preferences"));
993 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
994 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome2
), dialog
);
996 widget
= gtk_button_new_with_mnemonic(_("Create a _new file"));
997 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
998 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome3
), dialog
);
1000 widget
= gtk_button_new_with_mnemonic(_("_Open an existing file"));
1001 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
1002 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome4
), dialog
);
1004 widget
= gtk_button_new_with_mnemonic(_("Open the _example file"));
1005 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
1006 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome5
), dialog
);
1008 //connect all our signals
1009 g_signal_connect (dialog
, "destroy", G_CALLBACK (gtk_widget_destroyed
), &dialog
);
1011 gtk_widget_show_all (dialog
);
1014 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
1016 // cleanup and destroy
1017 gtk_widget_destroy (dialog
);
1019 // do appropriate action
1023 ui_mainwindow_action_help();
1026 ui_mainwindow_action_preferences();
1029 ui_mainwindow_action_new();
1032 ui_mainwindow_action_open();
1035 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL
));
1036 ui_mainwindow_open_internal(GLOBALS
->mainwindow
, NULL
);
1043 static void ui_mainwindow_action_help_updates(void)
1045 const gchar
*link
= HOMEBANK_URL_HELP_UPDATES
;
1047 homebank_util_url_show (link
);
1051 static void ui_mainwindow_action_help_online(void)
1053 const gchar
*link
= HOMEBANK_URL_HELP_ONLINE
;
1055 homebank_util_url_show (link
);
1059 static void ui_mainwindow_action_help_translate(void)
1061 const gchar
*link
= HOMEBANK_URL_HELP_TRANSLATE
;
1063 homebank_util_url_show (link
);
1067 static void ui_mainwindow_action_help_problem(void)
1069 const gchar
*link
= HOMEBANK_URL_HELP_PROBLEM
;
1071 homebank_util_url_show (link
);
1075 /* hbfile functions -------------------- */
1081 static void ui_mainwindow_selection(GtkTreeSelection
*treeselection
, gpointer user_data
)
1083 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
1087 static void ui_mainwindow_close_openbooks(void)
1091 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
1093 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1096 Account
*item
= elt
->data
;
1100 gtk_widget_destroy(GTK_WIDGET(item
->window
));
1101 item
->window
= NULL
;
1104 elt
= g_list_next(elt
);
1115 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
)
1117 struct hbfile_data
*data
;
1118 gboolean file_clear
= GPOINTER_TO_INT(user_data
);
1120 DB( g_print("\n[ui-mainwindow] clear\n") );
1122 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1124 // Close opened account window
1126 ui_mainwindow_close_openbooks();
1127 gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_acc
))));
1128 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
))));
1129 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_top
))));
1131 data
->showall
= FALSE
;
1132 ui_hub_account_setup(data
);
1134 hbfile_cleanup(file_clear
);
1135 hbfile_setup(file_clear
);
1141 ** add some transactions directly
1143 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
)
1145 struct hbfile_data
*data
;
1149 gint account
, count
;
1151 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1153 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1155 /* init the transaction */
1156 date
= homebank_app_date_get_julian();
1160 if(data
->acc
!= NULL
)
1161 account
= data
->acc
->key
;
1163 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
, FALSE
, account
);
1165 while(result
== HB_RESPONSE_ADD
|| result
== HB_RESPONSE_ADDKEEP
)
1169 /* fill in the transaction */
1170 if( result
== HB_RESPONSE_ADD
)
1172 ope
= da_transaction_malloc();
1174 ope
->kacc
= account
;
1176 if( PREFS
->heritdate
== FALSE
) //fix: 318733
1177 ope
->date
= GLOBALS
->today
;
1179 da_transaction_set_default_template(ope
);
1182 // normally we can't be in addkeep without initialized ope with add
1184 deftransaction_set_transaction(window
, ope
);
1186 result
= gtk_dialog_run (GTK_DIALOG (window
));
1188 DB( g_print(" - dialog result is %d\n", result
) );
1190 if(result
== HB_RESPONSE_ADD
|| result
== HB_RESPONSE_ADDKEEP
|| result
== GTK_RESPONSE_ACCEPT
)
1192 deftransaction_get(window
, NULL
);
1193 transaction_add(GTK_WINDOW(GLOBALS
->mainwindow
), ope
);
1195 DB( g_print(" - added 1 transaction to %d\n", ope
->kacc
) );
1197 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1200 //todo: still usefull ? store last date
1204 if( result
== HB_RESPONSE_ADD
)
1206 da_transaction_free(ope
);
1213 deftransaction_dispose(window
, NULL
);
1214 gtk_widget_destroy (window
);
1216 /* todo optimize this */
1219 GLOBALS
->changes_count
+= count
;
1220 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
1225 gboolean
ui_mainwindow_open_backup_check_confirm(gchar
*filepath
)
1227 gboolean retval
= FALSE
;
1228 gchar
*basename
, *secondtext
;
1231 basename
= g_path_get_basename(filepath
);
1232 secondtext
= g_strdup_printf (
1233 _("Your are about to open the backup file '%s'.\n\nAre you sure you want to do this ?"), basename
);
1235 result
= ui_dialog_msg_confirm_alert(
1236 GTK_WINDOW(GLOBALS
->mainwindow
),
1237 _("Open the backup file ?"),
1245 if( result
== GTK_RESPONSE_OK
)
1255 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
)
1257 //struct hbfile_data *data;
1258 gboolean bakmode
= GPOINTER_TO_INT(user_data
);;
1259 gboolean doopen
= TRUE
;
1260 gchar
*filename
= NULL
;
1262 DB( g_print("\n[ui-mainwindow] open\n") );
1264 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1266 //#1791554 do ask for save confirm
1267 if( bakmode
!= TRUE
)
1268 doopen
= ui_dialog_msg_savechanges(widget
,NULL
);
1270 if( doopen
== TRUE
)
1272 if( ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN
, &filename
, bakmode
) == TRUE
)
1274 //#1710955 test for backup open
1275 if( hbfile_file_isbackup(filename
) )
1277 if( ui_mainwindow_open_backup_check_confirm(filename
) == TRUE
)
1279 GLOBALS
->hbfile_is_bak
= TRUE
;
1288 hbfile_change_filepath(filename
);
1289 ui_mainwindow_open_internal(widget
, NULL
);
1296 * open the file stored in GLOBALS->xhb_filepath
1298 void ui_mainwindow_open_internal(GtkWidget
*widget
, gpointer user_data
)
1300 struct hbfile_data
*data
;
1303 DB( g_print("\n[ui-mainwindow] open internal\n") );
1305 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1307 if( GLOBALS
->xhb_filepath
!= NULL
)
1309 DB( g_print(" - filename: '%s'\n", GLOBALS
->xhb_filepath
) );
1311 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
1312 GLOBALS
->hbfile_is_new
= FALSE
;
1314 r
= homebank_load_xml(GLOBALS
->xhb_filepath
);
1317 DB( g_print(" - file loaded ok : rcode=%d\n", r
) );
1319 GLOBALS
->xhb_timemodified
= hbfile_file_get_time_modified(GLOBALS
->xhb_filepath
);
1320 hbfile_file_hasrevert(GLOBALS
->xhb_filepath
);
1322 if(PREFS
->appendscheduled
)
1323 scheduled_post_all_pending();
1325 if(PREFS
->do_update_currency
)
1326 ui_cur_manage_dialog_update_currencies(GTK_WINDOW(GLOBALS
->mainwindow
));
1328 homebank_lastopenedfiles_save();
1330 //todo: delete this after computing done at xml read
1331 account_compute_balances();
1333 ui_mainwindow_recent_add(data
, GLOBALS
->xhb_filepath
);
1337 gchar
*msg
= _("Unknown error");
1342 msg
= _("I/O error for file '%s'.");
1344 case XML_FILE_ERROR
:
1345 msg
= _("The file '%s' is not a valid HomeBank file.");
1347 case XML_VERSION_ERROR
:
1348 msg
= _("The file '%s' was saved with a higher version of HomeBank\nand cannot be loaded by the current version.");
1352 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1355 GLOBALS
->xhb_filepath
1358 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
1362 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1363 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1364 ui_hub_spending_populate(GLOBALS
->mainwindow
, NULL
);
1365 ui_hub_transaction_populate(data
);
1367 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1377 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
)
1379 struct hbfile_data
*data
;
1380 gboolean saveas
= GPOINTER_TO_INT(user_data
);
1381 gchar
*filename
= NULL
;
1384 DB( g_print("\n[ui-mainwindow] save\n") );
1386 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1388 if( GLOBALS
->hbfile_is_new
== TRUE
)
1391 //#1710955 test for backup open
1392 if( GLOBALS
->hbfile_is_bak
== TRUE
)
1394 //todo: later for backup, should also remove datetime and .bak
1395 hbfile_change_filepath(hb_filename_new_with_extension(GLOBALS
->xhb_filepath
, "xhb"));
1401 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE
, &filename
, FALSE
) == TRUE
)
1403 DB( g_print(" + should save as '%s'\n", filename
) );
1404 homebank_file_ensure_xhb(filename
);
1405 homebank_backup_current_file();
1406 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1407 GLOBALS
->hbfile_is_new
= FALSE
;
1408 GLOBALS
->hbfile_is_bak
= FALSE
;
1415 guint64 time_modified
= hbfile_file_get_time_modified (GLOBALS
->xhb_filepath
);
1416 gint result
= GTK_RESPONSE_OK
;
1418 DB( g_print(" + should quick save '%s'\n + time: open=%lu :: now=%lu\n", GLOBALS
->xhb_filepath
, GLOBALS
->xhb_timemodified
, time_modified
) );
1420 if( GLOBALS
->xhb_timemodified
!= time_modified
)
1422 result
= ui_dialog_msg_confirm_alert(
1423 GTK_WINDOW(GLOBALS
->mainwindow
),
1424 _("The file has been modified since reading it."),
1425 _("If you save it, all the external changes could be lost. Save it anyway?"),
1429 if( result
!= GTK_RESPONSE_OK
)
1433 DB( g_print(" + saving...\n") );
1434 homebank_file_ensure_xhb(NULL
);
1435 homebank_backup_current_file();
1436 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1441 DB( g_print(" + OK...\n") );
1442 GLOBALS
->changes_count
= 0;
1443 GLOBALS
->xhb_timemodified
= hbfile_file_get_time_modified (GLOBALS
->xhb_filepath
);
1444 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1448 gchar
*msg
= _("I/O error for file '%s'.");
1450 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1453 GLOBALS
->xhb_filepath
1459 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
)
1461 struct hbfile_data
*data
;
1464 DB( g_print("\n[ui-mainwindow] update %p\n", user_data
) );
1466 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1467 //data = INST_DATA(widget);
1469 flags
= GPOINTER_TO_INT(user_data
);
1471 /* set window title */
1472 if(flags
& UF_TITLE
)
1477 DB( g_print(" 1: wintitle %p\n", data
->wintitle
) );
1479 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
1481 DB( g_print(" global changes: %d\n", GLOBALS
->changes_count
) );
1483 g_free(data
->wintitle
);
1485 changed
= (GLOBALS
->changes_count
> 0) ? "*" : "";
1488 data
->wintitle
= g_strdup_printf("%s%s (%d)- %s - " PROGNAME
, changed
, basename
, GLOBALS
->changes_count
, GLOBALS
->owner
);
1490 data
->wintitle
= g_strdup_printf("%s%s - %s - " PROGNAME
, changed
, basename
, GLOBALS
->owner
);
1493 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), data
->wintitle
);
1498 /* update disabled things */
1499 if(flags
& UF_SENSITIVE
)
1501 GtkTreeSelection
*selection
;
1502 GtkTreeModel
*model
;
1505 gboolean active
,sensitive
;
1507 DB( g_print(" 2: disabled, opelist count\n") );
1512 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
));
1513 active
= gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1519 path
= gtk_tree_model_get_path(model
, &iter
);
1520 depth
= gtk_tree_path_get_depth(path
);
1524 DB( g_print(" depth is %d\n", depth
) );
1526 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1533 DB( g_print(" changes %d - new %d\n", GLOBALS
->changes_count
, GLOBALS
->hbfile_is_new
) );
1536 sensitive
= (GLOBALS
->changes_count
!= 0 ) ? TRUE
: FALSE
;
1537 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Save"), sensitive
);
1540 sensitive
= ( (GLOBALS
->changes_count
!= 0) && GLOBALS
->xhb_hasrevert
) ? TRUE
: FALSE
;
1541 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Revert"), sensitive
);
1542 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/OpenBak"), sensitive
);
1545 sensitive
= GLOBALS
->define_off
== 0 ? TRUE
: FALSE
;
1546 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Account"), sensitive
);
1547 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Payee"), sensitive
);
1548 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Category"), sensitive
);
1549 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1550 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/EditMenu/Preferences"), sensitive
);
1552 // empty account list: disable Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
1553 sensitive
= da_acc_length() > 0 ? TRUE
: FALSE
;
1554 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Close"), sensitive
);
1555 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Archive"), sensitive
);
1556 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddTxn"), sensitive
);
1557 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowTxn"), sensitive
);
1558 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RStatistics"), sensitive
);
1559 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RTrendTime"), sensitive
);
1560 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBudget"), sensitive
);
1561 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBalance"), sensitive
);
1562 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RVehiculeCost"), sensitive
);
1564 // empty category list: disable Budget
1565 sensitive
= da_cat_length() > 1 ? TRUE
: FALSE
;
1566 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1568 //#1501129 no need to disable, P & C can be created from assign dialog
1569 //sensitive = ((da_cat_length() > 1) || (da_pay_length() > 1)) ? TRUE : FALSE;
1570 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Assign"), sensitive);
1572 // empty archive list: disable scheduled check
1573 sensitive
= g_list_length(GLOBALS
->arc_list
) > 0 ? TRUE
: FALSE
;
1574 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/AddScheduled"), sensitive
);
1576 // no active account: disable Edit, Over
1577 sensitive
= (active
== TRUE
) ? TRUE
: FALSE
;
1578 if(data
->acc
&& data
->acc
->window
!= NULL
)
1580 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TxnMenu/ShowTxn"), sensitive
);
1583 /* update toolbar, list */
1584 if(flags
& UF_VISUAL
)
1586 DB( g_print(" 8: visual\n") );
1588 if(PREFS
->toolbar_style
== 0)
1589 gtk_toolbar_unset_style(GTK_TOOLBAR(data
->toolbar
));
1591 gtk_toolbar_set_style(GTK_TOOLBAR(data
->toolbar
), PREFS
->toolbar_style
-1);
1593 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_acc
), PREFS
->grid_lines
);
1594 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
1596 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (data
->LV_upc
), PREFS
->grid_lines
);
1597 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
1599 DB( g_print(" - show toolbar=%d\n", PREFS
->wal_toolbar
) );
1600 if(PREFS
->wal_toolbar
)
1601 gtk_widget_show(GTK_WIDGET(data
->toolbar
));
1603 gtk_widget_hide(GTK_WIDGET(data
->toolbar
));
1606 DB( g_print(" - show top_spending=%d\n", PREFS
->wal_spending
) );
1608 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
1610 if(PREFS
->wal_spending
)
1611 gtk_widget_show(GTK_WIDGET(data
->GR_top
));
1613 gtk_widget_hide(GTK_WIDGET(data
->GR_top
));
1617 DB( g_print(" - show upcoming=%d\n", PREFS
->wal_upcoming
) );
1618 if(PREFS
->wal_upcoming
)
1619 gtk_widget_show(GTK_WIDGET(data
->GR_upc
));
1621 gtk_widget_hide(GTK_WIDGET(data
->GR_upc
));
1623 DB( g_print(" minor %d\n", PREFS
->euro_active
) );
1624 gtk_action_set_visible(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor"), PREFS
->euro_active
);
1627 /* update balances */
1628 if(flags
& UF_BALANCE
)
1631 DB( g_print(" 4: balances\n") );
1633 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
1635 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
1638 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[0]), data->bank, minor);
1639 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[1]), data->today, minor);
1640 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[2]), data->future, minor);
1644 if(flags
& UF_REFRESHALL
)
1646 DB( g_print(" 16: refreshall\n") );
1648 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
1649 ui_hub_spending_populate(GLOBALS
->mainwindow
, NULL
);
1650 ui_hub_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1651 ui_hub_transaction_populate(data
);
1660 ui_mainwindow_onRowActivated (GtkTreeView
*treeview
,
1662 GtkTreeViewColumn
*col
,
1665 GtkTreeModel
*model
;
1668 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
1670 model
= gtk_tree_view_get_model(treeview
);
1672 if (gtk_tree_model_get_iter(model
, &iter
, path
))
1676 gtk_tree_model_get(model
, &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1681 DB( g_print ("Double-clicked row contains name %s\n", acc
->name
) );
1683 ui_mainwindow_action_showtransactions();
1691 static void ui_mainwindow_destroy(GtkTreeView
*treeview
, gpointer user_data
)
1693 DB( g_print("\n[ui-mainwindow] destroy\n") );
1701 static gboolean
ui_mainwindow_dispose(GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
1703 struct hbfile_data
*data
= user_data
;
1704 struct WinGeometry
*wg
;
1705 gboolean retval
= FALSE
;
1707 GValue widget_value
= G_VALUE_INIT
;
1708 ext_hook("main_window_disposal", EXT_OBJECT(&widget_value
, widget
), NULL
);
1710 DB( g_print("\n[ui-mainwindow] delete-event\n") );
1712 //store position and size
1713 wg
= &PREFS
->wal_wg
;
1714 gtk_window_get_position(GTK_WINDOW(widget
), &wg
->l
, &wg
->t
);
1715 gtk_window_get_size(GTK_WINDOW(widget
), &wg
->w
, &wg
->h
);
1716 GdkWindow
*gdk_window
= gtk_widget_get_window(GTK_WIDGET(widget
));
1717 GdkWindowState state
= gdk_window_get_state(gdk_window
);
1718 wg
->s
= (state
& GDK_WINDOW_STATE_MAXIMIZED
) ? 1 : 0;
1719 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
) );
1721 PREFS
->wal_vpaned
= gtk_paned_get_position(GTK_PANED(data
->vpaned
));
1722 PREFS
->wal_hpaned
= gtk_paned_get_position(GTK_PANED(data
->hpaned
));
1723 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
1725 if(PREFS
->pnl_list_tab
)
1726 g_free(PREFS
->pnl_list_tab
);
1727 PREFS
->pnl_list_tab
= g_strdup(gtk_stack_get_visible_child_name(GTK_STACK(data
->stack
)));
1730 if(ui_dialog_msg_savechanges(widget
, NULL
) == FALSE
)
1736 //todo: retval is useless and below should move to destroy
1738 gtk_widget_destroy(data
->LV_top
);
1740 g_free(data
->wintitle
);
1741 da_flt_free(data
->filter
);
1747 //TRUE:stop other handlers from being invoked for the event | FALSE: propagate
1752 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser
*chooser
, struct hbfile_data
*data
)
1755 GError
*error
= NULL
;
1757 uri
= gtk_recent_chooser_get_current_uri (chooser
);
1759 path
= g_filename_from_uri (uri
, NULL
, NULL
);
1762 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
1763 g_error_free (error
);
1767 if( ui_dialog_msg_savechanges(data
->window
, NULL
) == TRUE
)
1774 gpw_recent_remove (gpw, path);
1778 hbfile_change_filepath(path
);
1779 ui_mainwindow_open_internal(data
->window
, NULL
);
1789 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
)
1791 GtkRecentData
*recent_data
;
1793 GError
*error
= NULL
;
1795 DB( g_print("\n[ui-mainwindow] recent_add\n") );
1797 DB( g_print(" - file has .xhb suffix = %d\n", g_str_has_suffix (path
, ".xhb") ) );
1799 if( g_str_has_suffix (path
, ".xhb") == FALSE
) //ignore reverted file
1802 uri
= g_filename_to_uri (path
, NULL
, &error
);
1805 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
1806 g_error_free (error
);
1810 recent_data
= g_slice_new (GtkRecentData
);
1812 recent_data
->display_name
= NULL
;
1813 recent_data
->description
= NULL
;
1814 recent_data
->mime_type
= "application/x-homebank";
1815 recent_data
->app_name
= (gchar
*) g_get_application_name ();
1816 recent_data
->app_exec
= g_strjoin (" ", g_get_prgname (), "%u", NULL
);
1817 recent_data
->groups
= NULL
;
1818 recent_data
->is_private
= FALSE
;
1820 if (!gtk_recent_manager_add_full (data
->recent_manager
,
1824 g_warning ("Unable to add '%s' to the list of recently used documents", uri
);
1828 g_free (recent_data
->app_exec
);
1829 g_slice_free (GtkRecentData
, recent_data
);
1842 static GtkTargetEntry drop_types
[] =
1844 {"text/uri-list", 0, TARGET_URI_LIST
}
1847 static void ui_mainwindow_drag_data_received (GtkWidget
*widget
,
1848 GdkDragContext
*context
,
1850 GtkSelectionData
*selection_data
,
1851 guint info
, guint time
, GtkWindow
*window
)
1853 gchar
**uris
, **str
;
1855 gint n_uris
, filetype
, slen
;
1856 GError
*error
= NULL
;
1858 if (info
!= TARGET_URI_LIST
)
1861 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
1863 /* On MS-Windows, it looks like `selection_data->data' is not NULL terminated. */
1864 slen
= gtk_selection_data_get_length(selection_data
);
1865 newseldata
= g_new (gchar
, slen
+ 1);
1866 memcpy (newseldata
, gtk_selection_data_get_data(selection_data
), slen
);
1867 newseldata
[slen
] = 0;
1868 //DB( g_print(" - seldata ='%s'\n", gtk_selection_data_get_data(selection_data) ) );
1869 //DB( g_print(" - newseldata ='%s'\n", newseldata ) );
1871 uris
= g_uri_list_extract_uris (newseldata
);
1872 n_uris
= g_strv_length(uris
);
1873 DB( g_print(" - dragged %d files (len=%d)\n", n_uris
, slen
) );
1877 //single file: check for xhb
1880 filetype
= hb_filename_type_get_by_extension(*uris
);
1882 DB( g_print(" - filetype is homebank (%d)\n", filetype
) );
1884 if( filetype
== FILETYPE_HOMEBANK
)
1886 gchar
*path
= g_filename_from_uri (*uris
, NULL
, &error
);
1890 DB( g_print(" - path is '%s'\n", path
) );
1891 hbfile_change_filepath(g_strdup(path
));
1892 ui_mainwindow_open_internal(GTK_WIDGET(window
), NULL
);
1897 g_warning ("Could not convert uri to local path: %s", error
->message
);
1898 g_error_free (error
);
1902 /* we no more manage error here
1903 ui_dialog_msg_infoerror(GTK_WINDOW(window), GTK_MESSAGE_ERROR,
1905 _("The file %s is not a valid HomeBank file."),
1910 //collect known filetype to import
1911 DB( g_print(" - collect %d files\n", n_uris
) );
1913 gchar
**paths
= g_new (gchar
*, n_uris
+ 1);
1915 for (str
= uris
; *str
; str
++)
1917 filetype
= hb_filename_type_get_by_extension(*str
);
1918 if( filetype
!= FILETYPE_HOMEBANK
&& filetype
!= FILETYPE_UNKNOWN
)
1920 gchar
*path
= g_filename_from_uri (*str
, NULL
, NULL
);
1924 DB( g_print(" - append %d '%s'\n", slen
, path
) );
1925 paths
[slen
++] = path
;
1933 ui_import_assistant_new( paths
);
1942 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
)
1944 GtkWidget
*recent_menu
;
1945 GtkRecentFilter
*filter
;
1947 recent_menu
= gtk_recent_chooser_menu_new_for_manager (manager
);
1948 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu
), FALSE
);
1949 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu
), GTK_RECENT_SORT_MRU
);
1950 //todo: add a user pref for this
1951 gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER (recent_menu
), 10);
1952 gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu
), FALSE
);
1953 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_menu), TRUE);
1955 filter
= gtk_recent_filter_new ();
1956 //gtk_recent_filter_add_application (filter, g_get_application_name());
1957 gtk_recent_filter_add_pattern (filter
, "*.[Xx][Hh][Bb]");
1958 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu
), filter
);
1964 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data
*data
, GtkWidget
*mainvbox
)
1966 GtkUIManager
*manager
;
1967 GtkActionGroup
*actions
;
1969 GError
*error
= NULL
;
1971 manager
= gtk_ui_manager_new ();
1972 data
->manager
= manager
;
1974 gtk_window_add_accel_group (GTK_WINDOW (data
->window
),
1975 gtk_ui_manager_get_accel_group(manager
));
1977 actions
= gtk_action_group_new ("MainWindow");
1978 gtk_action_group_set_translation_domain(actions
, GETTEXT_PACKAGE
);
1980 gtk_action_group_add_actions (actions
,
1985 gtk_action_group_add_toggle_actions (actions
,
1990 gtk_ui_manager_insert_action_group (data
->manager
, actions
, 0);
1991 g_object_unref (actions
);
1992 data
->actions
= actions
;
1994 /* set short labels to use in the toolbar */
1995 action
= gtk_action_group_get_action(actions
, "Open");
1996 g_object_set(action
, "short_label", _("Open"), NULL
);
1998 //action = gtk_action_group_get_action(action_group, "Save");
1999 //g_object_set(action, "is_important", TRUE, NULL);
2001 action
= gtk_action_group_get_action(actions
, "Account");
2002 g_object_set(action
, "short_label", _("Account"), NULL
);
2004 action
= gtk_action_group_get_action(actions
, "Payee");
2005 g_object_set(action
, "short_label", _("Payee"), NULL
);
2007 action
= gtk_action_group_get_action(actions
, "Category");
2008 g_object_set(action
, "short_label", _("Category"), NULL
);
2010 action
= gtk_action_group_get_action(actions
, "Archive");
2011 //TRANSLATORS: an archive is stored transaction buffers (kind of bookmark to prefill manual insertion)
2012 g_object_set(action
, "short_label", _("Archive"), NULL
);
2014 action
= gtk_action_group_get_action(actions
, "Budget");
2015 g_object_set(action
, "short_label", _("Budget"), NULL
);
2017 action
= gtk_action_group_get_action(actions
, "ShowTxn");
2018 g_object_set(action
, "short_label", _("Show"), NULL
);
2020 action
= gtk_action_group_get_action(actions
, "AddTxn");
2021 g_object_set(action
, "is_important", TRUE
, "short_label", _("Add"), NULL
);
2023 action
= gtk_action_group_get_action(actions
, "RStatistics");
2024 g_object_set(action
, "short_label", _("Statistics"), NULL
);
2026 action
= gtk_action_group_get_action(actions
, "RBudget");
2027 g_object_set(action
, "short_label", _("Budget"), NULL
);
2029 action
= gtk_action_group_get_action(actions
, "RBalance");
2030 g_object_set(action
, "short_label", _("Balance"), NULL
);
2032 action
= gtk_action_group_get_action(actions
, "RVehiculeCost");
2033 g_object_set(action
, "short_label", _("Vehicle cost"), NULL
);
2035 /* now load the UI definition */
2036 gtk_ui_manager_add_ui_from_string (data
->manager
, ui_info
, -1, &error
);
2039 g_message ("Building menus failed: %s", error
->message
);
2040 g_error_free (error
);
2044 data
->recent_manager
= gtk_recent_manager_get_default ();
2046 data
->menubar
= gtk_ui_manager_get_widget (manager
, "/MenuBar");
2047 gtk_box_pack_start (GTK_BOX (mainvbox
),
2053 /* recent files menu */
2054 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2056 g_signal_connect (data
->recent_menu
,
2058 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2061 GtkWidget
*widget
= gtk_ui_manager_get_widget (data
->manager
, "/MenuBar/FileMenu/RecentMenu");
2062 gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget
), data
->recent_menu
);
2065 data
->toolbar
= gtk_ui_manager_get_widget (manager
, "/ToolBar");
2066 gtk_box_pack_start (GTK_BOX (mainvbox
),
2072 /* add the custom Open button to the toolbar */
2073 GtkWidget
*image
= gtk_image_new_from_icon_name (ICONNAME_HB_FILE_OPEN
, GTK_ICON_SIZE_BUTTON
);
2074 GtkToolItem
*open_button
= gtk_menu_tool_button_new(image
, _("_Open"));
2075 gtk_tool_item_set_tooltip_text (open_button
, _("Open a file"));
2077 GtkWidget
*recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2078 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button
), recent_menu
);
2079 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button
), _("Open a recently used file"));
2081 g_signal_connect (recent_menu
,
2083 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2086 action
= gtk_action_group_get_action (data
->actions
, "Open");
2087 g_object_set (action
, "short_label", _("Open"), NULL
);
2088 //gtk_action_connect_proxy (action, GTK_WIDGET (open_button));
2089 gtk_activatable_set_related_action (GTK_ACTIVATABLE (open_button
), action
);
2091 gtk_toolbar_insert (GTK_TOOLBAR (data
->toolbar
), open_button
, 1);
2097 ** the window creation
2099 GtkWidget
*create_hbfile_window(GtkWidget
*do_widget
)
2101 struct hbfile_data
*data
;
2102 struct WinGeometry
*wg
;
2103 GtkWidget
*mainvbox
, *vbox
, *box
, *vpaned
, *hpaned
, *sidebar
, *stack
;
2104 GtkWidget
*widget
, *page
;
2108 DB( g_print("\n[ui-mainwindow] create main window\n") );
2110 data
= g_malloc0(sizeof(struct hbfile_data
));
2111 if(!data
) return NULL
;
2113 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
2115 //store our window private data
2116 g_object_set_data(G_OBJECT(window
), "inst_data", (gpointer
)data
);
2117 DB( g_print(" - new window=%p, inst_data=%p\n", window
, data
) );
2119 // this is our mainwindow, so store it to GLOBALS data
2120 data
->window
= window
;
2121 GLOBALS
->mainwindow
= window
;
2123 mainvbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2124 gtk_container_add (GTK_CONTAINER (window
), mainvbox
);
2126 ui_mainwindow_create_menu_bar_and_toolbar (data
, mainvbox
);
2128 #if HB_UNSTABLE_SHOW == TRUE
2129 GtkWidget
*bar
, *label
;
2131 bar
= gtk_info_bar_new ();
2132 gtk_box_pack_start (GTK_BOX (mainvbox
), bar
, FALSE
, FALSE
, 0);
2133 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar
), GTK_MESSAGE_WARNING
);
2134 label
= make_label(NULL
, 0.5, 0.5);
2135 gtk_label_set_markup (GTK_LABEL(label
), "Unstable Development Version");
2136 gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar
))), label
, FALSE
, FALSE
, 0);
2139 /* Add the main area */
2140 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
2141 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
2142 gtk_box_pack_start (GTK_BOX (mainvbox
), vbox
, TRUE
, TRUE
, 0);
2144 vpaned
= gtk_paned_new(GTK_ORIENTATION_VERTICAL
);
2145 data
->vpaned
= vpaned
;
2146 gtk_box_pack_start (GTK_BOX (vbox
), vpaned
, TRUE
, TRUE
, 0);
2148 hpaned
= gtk_paned_new(GTK_ORIENTATION_HORIZONTAL
);
2149 data
->hpaned
= hpaned
;
2150 gtk_paned_pack1 (GTK_PANED(vpaned
), hpaned
, FALSE
, FALSE
);
2152 widget
= ui_hub_account_create(data
);
2153 //gtk_widget_set_size_request (widget, 100, -1);
2154 gtk_paned_pack1 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
2156 widget
= ui_hub_spending_create(data
);
2157 //gtk_widget_set_size_request (widget, -1, 100);
2158 gtk_paned_pack2 (GTK_PANED(hpaned
), widget
, TRUE
, FALSE
);
2160 box
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
2162 gtk_paned_pack2 (GTK_PANED(vpaned
), box
, TRUE
, FALSE
);
2164 sidebar
= gtk_stack_sidebar_new ();
2165 gtk_box_pack_start (GTK_BOX (box
), sidebar
, FALSE
, FALSE
, 0);
2167 stack
= gtk_stack_new ();
2168 //gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN);
2169 gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar
), GTK_STACK (stack
));
2170 data
->stack
= stack
;
2171 gtk_box_pack_start (GTK_BOX (box
), stack
, TRUE
, TRUE
, 0);
2173 page
= ui_hub_scheduled_create(data
);
2174 gtk_stack_add_titled (GTK_STACK (stack
), page
, "sched", _("Scheduled"));
2175 //gtk_paned_pack2 (GTK_PANED(vpaned), widget, TRUE, FALSE);
2177 page
= ui_hub_transaction_create(data
, HUB_TXN_TYPE_FUTURE
);
2178 gtk_stack_add_titled (GTK_STACK (stack
), page
, "futur", _("Future"));
2180 page
= ui_hub_transaction_create(data
, HUB_TXN_TYPE_REMIND
);
2181 gtk_stack_add_titled (GTK_STACK (stack
), page
, "remin", _("Remind"));
2184 //setup, init and show window
2185 wg
= &PREFS
->wal_wg
;
2188 gtk_window_move(GTK_WINDOW(window
), wg
->l
, wg
->t
);
2189 gtk_window_resize(GTK_WINDOW(window
), wg
->w
, wg
->h
);
2192 gtk_window_maximize(GTK_WINDOW(window
));
2194 gtk_widget_show_all (window
);
2196 //#1662197/1660910 moved after resize/show
2197 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
2199 if(PREFS
->wal_hpaned
> 0)
2200 gtk_paned_set_position(GTK_PANED(data
->hpaned
), PREFS
->wal_hpaned
);
2201 if(PREFS
->wal_vpaned
> 0)
2202 gtk_paned_set_position(GTK_PANED(data
->vpaned
), PREFS
->wal_vpaned
);
2204 if( PREFS
->pnl_list_tab
!= NULL
)
2205 gtk_stack_set_visible_child_name (GTK_STACK(data
->stack
), PREFS
->pnl_list_tab
);
2208 //todo: move this elsewhere
2209 DB( g_print(" - setup stuff\n") );
2211 data
->filter
= da_flt_malloc();
2212 filter_reset(data
->filter
);
2213 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
2215 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Toolbar");
2216 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_toolbar
);
2217 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Spending");
2218 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_spending
);
2219 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/BottomLists");
2220 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_upcoming
);
2222 /* Drag and drop support, set targets to NULL because we add the
2223 default uri_targets below */
2225 /* support for opening a file by dragging onto the project window */
2226 gtk_drag_dest_set (GTK_WIDGET (window
),
2227 GTK_DEST_DEFAULT_ALL
,
2229 G_N_ELEMENTS (drop_types
),
2232 g_signal_connect (G_OBJECT (window
), "drag-data-received",
2233 G_CALLBACK (ui_mainwindow_drag_data_received
), window
);
2235 //connect all our signals
2236 DB( g_print(" - connect signals\n") );
2238 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
)), "changed", G_CALLBACK (ui_mainwindow_selection
), NULL
);
2239 g_signal_connect (GTK_TREE_VIEW(data
->LV_acc
), "row-activated", G_CALLBACK (ui_mainwindow_onRowActivated
), GINT_TO_POINTER(2));
2241 /* GtkWindow events */
2242 g_signal_connect (window
, "delete-event", G_CALLBACK (ui_mainwindow_dispose
), (gpointer
)data
);
2243 g_signal_connect (window
, "destroy", G_CALLBACK (ui_mainwindow_destroy
), NULL
);
2245 //gtk_action_group_set_sensitive(data->actions, FALSE);