1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2014 Maxime DOYEN
4 * This file is part of HomeBank.
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "dsp_mainwindow.h"
25 #include "list_account.h"
26 #include "list_upcoming.h"
27 #include "list_topspending.h"
29 #include "dsp_account.h"
32 #include "ui-assist-start.h"
33 #include "ui-account.h"
35 #include "ui-category.h"
36 #include "ui-archive.h"
37 #include "ui-assign.h"
38 #include "ui-budget.h"
40 #include "ui-hbfile.h"
41 #include "ui-transaction.h"
43 #include "rep_balance.h"
44 #include "rep_budget.h"
45 #include "rep_stats.h"
47 #include "rep_vehicle.h"
49 #include "gtk-chart.h"
51 //#define HOMEBANK_URL_HELP "http://homebank.free.fr/help/"
52 #define HOMEBANK_URL_HELP "index.html"
53 #define HOMEBANK_URL_HELP_ONLINE "https://launchpad.net/homebank/+addquestion"
54 #define HOMEBANK_URL_HELP_TRANSLATE "https://launchpad.net/homebank/+translations"
55 #define HOMEBANK_URL_HELP_PROBLEM "https://launchpad.net/homebank/+filebug"
58 /****************************************************************************/
60 /****************************************************************************/
68 /* our global datas */
69 extern struct HomeBank
*GLOBALS
;
70 extern struct Preferences
*PREFS
;
71 extern gchar
*homebank_pixmaps_dir
;
74 /* our functions prototype */
75 static void ui_mainwindow_action_new(void);
76 static void ui_mainwindow_action_open(void);
77 static void ui_mainwindow_action_save(void);
78 static void ui_mainwindow_action_saveas(void);
79 static void ui_mainwindow_action_revert(void);
80 static void ui_mainwindow_action_properties(void);
81 static void ui_mainwindow_action_close(void);
82 static void ui_mainwindow_action_quit(void);
84 static void ui_mainwindow_action_defaccount(void);
85 static void ui_mainwindow_action_defpayee(void);
86 static void ui_mainwindow_action_defcategory(void);
87 static void ui_mainwindow_action_defarchive(void);
88 static void ui_mainwindow_action_defbudget(void);
89 static void ui_mainwindow_action_defassign(void);
90 static void ui_mainwindow_action_preferences(void);
92 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction
*action
);
93 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction
*action
);
94 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction
*action
);
95 static void ui_mainwindow_action_toggle_minor(GtkToggleAction
*action
);
97 static void ui_mainwindow_action_showtransactions(void);
98 static void ui_mainwindow_action_addtransactions(void);
99 static void ui_mainwindow_action_checkscheduled(void);
101 static void ui_mainwindow_action_statistic(void);
102 static void ui_mainwindow_action_trendtime(void);
103 static void ui_mainwindow_action_budget(void);
104 static void ui_mainwindow_action_balance(void);
105 static void ui_mainwindow_action_vehiclecost(void);
107 static void ui_mainwindow_action_import(void);
108 static void ui_mainwindow_action_export(void);
109 static void ui_mainwindow_action_anonymize(void);
111 static void ui_mainwindow_action_help(void);
112 void ui_mainwindow_action_help_welcome(void);
113 static void ui_mainwindow_action_help_online(void);
114 static void ui_mainwindow_action_help_translate(void);
115 static void ui_mainwindow_action_help_problem(void);
116 static void ui_mainwindow_action_about(void);
119 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
);
121 static void ui_mainwindow_populate_topspending(GtkWidget
*widget
, gpointer user_data
);
123 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
);
125 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
);
126 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
);
127 void ui_mainwindow_action(GtkWidget
*widget
, gpointer user_data
);
128 void ui_mainwindow_toggle_minor(GtkWidget
*widget
, gpointer user_data
);
129 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
);
131 gboolean
ui_dialog_msg_savechanges(GtkWidget
*widget
, gpointer user_data
);
133 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
);
134 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
);
135 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
);
137 static void ui_mainwindow_scheduled_populate(GtkWidget
*widget
, gpointer user_data
);
138 void ui_mainwindow_scheduled_postall(GtkWidget
*widget
, gpointer user_data
);
141 extern gchar
*CYA_ACC_TYPE
[];
143 static GtkActionEntry entries
[] = {
145 /* name, stock id, label */
147 { "FileMenu" , NULL
, N_("_File"), NULL
, NULL
, NULL
},
148 { "EditMenu" , NULL
, N_("_Edit"), NULL
, NULL
, NULL
},
149 { "ViewMenu" , NULL
, N_("_View"), NULL
, NULL
, NULL
},
150 { "ManageMenu" , NULL
, N_("_Manage"), NULL
, NULL
, NULL
},
151 { "TransactionMenu", NULL
, N_("_Transactions"), NULL
, NULL
, NULL
},
152 { "ReportMenu" , NULL
, N_("_Reports"), NULL
, NULL
, NULL
},
153 { "HelpMenu" , NULL
, N_("_Help"), NULL
, NULL
, NULL
},
155 // { "Import" , NULL, N_("Import") },
156 // { "Export" , NULL, N_("Export to") },
157 /* name, stock id, label, accelerator, tooltip */
160 { "New" , GTK_STOCK_NEW
, N_("_New") , NULL
, N_("Create a new file"), G_CALLBACK (ui_mainwindow_action_new
) },
161 { "Open" , GTK_STOCK_OPEN
, N_("_Open...") , NULL
, N_("Open a file"), G_CALLBACK (ui_mainwindow_action_open
) },
162 { "Save" , GTK_STOCK_SAVE
, N_("_Save") , NULL
, N_("Save the current file"), G_CALLBACK (ui_mainwindow_action_save
) },
163 { "SaveAs" , GTK_STOCK_SAVE_AS
, N_("Save As...") , "<shift><control>S", N_("Save the current file with a different name"), G_CALLBACK (ui_mainwindow_action_saveas
) },
164 { "Revert" , GTK_STOCK_REVERT_TO_SAVED
, N_("Revert") , NULL
, N_("Revert to a saved version of this file"), G_CALLBACK (ui_mainwindow_action_revert
) },
166 { "Properties" , GTK_STOCK_PROPERTIES
, N_("_Properties..."), NULL
, N_("Configure the file"), G_CALLBACK (ui_mainwindow_action_properties
) },
167 { "Close" , GTK_STOCK_CLOSE
, N_("_Close") , NULL
, N_("Close the current file"), G_CALLBACK (ui_mainwindow_action_close
) },
168 { "Quit" , GTK_STOCK_QUIT
, N_("_Quit") , NULL
, N_("Quit homebank"), G_CALLBACK (ui_mainwindow_action_quit
) },
171 { "FileImport" , "hb-file-import" , N_("Import QIF/OFX/CSV...") , NULL
, N_("Open the import assistant"), G_CALLBACK (ui_mainwindow_action_import
) },
172 { "ExportQIF" , "hb-file-export" , N_("Export QIF...") , NULL
, N_("Open the export to QIF assistant"), G_CALLBACK (ui_mainwindow_action_export
) },
173 { "Anonymize" , NULL
, N_("Anonymize...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_anonymize
) },
176 { "Preferences", GTK_STOCK_PREFERENCES
, N_("Preferences..."), NULL
, N_("Configure homebank"), G_CALLBACK (ui_mainwindow_action_preferences
) },
179 // { "Currency" , "hb-currency" , N_("Currencies...") , NULL, N_("Configure the currencies"), G_CALLBACK (ui_mainwindow_action_defcurrency) },
180 { "Account" , "hb-account" , N_("Acc_ounts...") , NULL
, N_("Configure the accounts"), G_CALLBACK (ui_mainwindow_action_defaccount
) },
181 { "Payee" , "hb-payee" , N_("_Payees...") , NULL
, N_("Configure the payees"), G_CALLBACK (ui_mainwindow_action_defpayee
) },
182 { "Category" , "hb-category" , N_("Categories...") , NULL
, N_("Configure the categories"), G_CALLBACK (ui_mainwindow_action_defcategory
) },
183 { "Archive" , "hb-archive" , N_("Scheduled/Template...") , NULL
, N_("Configure the scheduled/template transactions"), G_CALLBACK (ui_mainwindow_action_defarchive
) },
184 { "Budget" , "hb-budget" , N_("Budget...") , NULL
, N_("Configure the budget"), G_CALLBACK (ui_mainwindow_action_defbudget
) },
185 { "Assign" , "hb-assign" , N_("Assignments..."), NULL
, N_("Configure the automatic assignments"), G_CALLBACK (ui_mainwindow_action_defassign
) },
187 /* TransactionMenu */
188 { "ShowOpe" , HB_STOCK_OPE_SHOW
, N_("Show...") , NULL
, N_("Shows selected account transactions"), G_CALLBACK (ui_mainwindow_action_showtransactions
) },
189 { "AddOpe" , HB_STOCK_OPE_ADD
, N_("Add...") , NULL
, N_("Add transaction"), G_CALLBACK (ui_mainwindow_action_addtransactions
) },
190 { "Scheduler" , NULL
, N_("Set scheduler...") , NULL
, N_("Configure the transaction scheduler"), G_CALLBACK (ui_mainwindow_action_properties
) },
191 { "AddScheduled" , NULL
, N_("Process scheduled..."), NULL
, N_("Insert pending scheduled transactions"), G_CALLBACK (ui_mainwindow_action_checkscheduled
) },
194 { "RStatistics" , HB_STOCK_REP_STATS
, N_("_Statistics...") , NULL
, N_("Open the Statistics report"), G_CALLBACK (ui_mainwindow_action_statistic
) },
195 { "RTrendTime" , HB_STOCK_REP_TIME
, N_("_Trend Time...") , NULL
, N_("Open the Trend Time report"), G_CALLBACK (ui_mainwindow_action_trendtime
) },
196 { "RBudget" , HB_STOCK_REP_BUDGET
, N_("B_udget...") , NULL
, N_("Open the Budget report"), G_CALLBACK (ui_mainwindow_action_budget
) },
197 { "RBalance" , HB_STOCK_REP_BALANCE
, N_("Balance...") , NULL
, N_("Open the Balance report"), G_CALLBACK (ui_mainwindow_action_balance
) },
198 { "RVehiculeCost" , HB_STOCK_REP_CAR
, N_("_Vehicle cost...") , NULL
, N_("Open the Vehicle cost report"), G_CALLBACK (ui_mainwindow_action_vehiclecost
) },
201 { "Contents" , GTK_STOCK_HELP
, N_("_Contents") , "F1", N_("Documentation about HomeBank"), G_CALLBACK (ui_mainwindow_action_help
) },
202 { "Welcome" , NULL
, N_("Show welcome dialog...") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_help_welcome
) },
203 { "Online" , "lpi-help" , N_("Get Help Online...") , NULL
, N_("Connect to the LaunchPad website for online help"), G_CALLBACK (ui_mainwindow_action_help_online
) },
204 { "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
) },
205 { "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
) },
207 { "About" , GTK_STOCK_ABOUT
, N_("_About") , NULL
, N_("About HomeBank") ,G_CALLBACK (ui_mainwindow_action_about
) },
210 static guint n_entries
= G_N_ELEMENTS (entries
);
213 static GtkToggleActionEntry toggle_entries
[] = {
214 /* name , stockid, label, accelerator, tooltip, callback, is_active */
215 { "Toolbar" , NULL
, N_("_Toolbar") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_toolbar
), TRUE
},
216 { "Spending" , NULL
, N_("_Top spending") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_topspending
), TRUE
},
217 { "Upcoming" , NULL
, N_("_Scheduled list") , NULL
, NULL
, G_CALLBACK (ui_mainwindow_action_toggle_upcoming
), TRUE
},
218 { "AsMinor" , NULL
, N_("Minor currency"), "<control>M", NULL
, G_CALLBACK (ui_mainwindow_action_toggle_minor
), FALSE
},
221 static guint n_toggle_entries
= G_N_ELEMENTS (toggle_entries
);
224 static const gchar
*ui_info
=
227 " <menubar name='MenuBar'>"
228 " <menu action='FileMenu'>"
229 " <menuitem action='New'/>"
230 " <menuitem action='Open'/>"
232 " <menuitem action='Save'/>"
233 " <menuitem action='SaveAs'/>"
234 " <menuitem action='Revert'/>"
236 " <menuitem action='FileImport'/>"
237 " <menuitem action='ExportQIF'/>"
239 // print to come here
241 " <menuitem action='Properties'/>"
242 " <menuitem action='Anonymize'/>"
244 " <menuitem action='Close'/>"
245 " <menuitem action='Quit'/>"
247 " <menu action='EditMenu'>"
248 " <menuitem action='Preferences'/>"
250 " <menu action='ViewMenu'>"
251 " <menuitem action='Toolbar'/>"
252 " <menuitem action='Spending'/>"
253 " <menuitem action='Upcoming'/>"
255 " <menuitem action='AsMinor'/>"
257 " <menu action='ManageMenu'>"
258 //" <menuitem action='Currency'/>"
259 " <menuitem action='Account'/>"
260 " <menuitem action='Payee'/>"
261 " <menuitem action='Category'/>"
262 " <menuitem action='Assign'/>"
263 " <menuitem action='Archive'/>"
264 " <menuitem action='Budget'/>"
266 " <menu action='TransactionMenu'>"
267 " <menuitem action='ShowOpe'/>"
268 " <menuitem action='AddOpe'/>"
270 " <menuitem action='Scheduler'/>"
271 " <menuitem action='AddScheduled'/>"
273 " <menu action='ReportMenu'>"
274 " <menuitem action='RStatistics'/>"
275 " <menuitem action='RTrendTime'/>"
276 " <menuitem action='RBalance'/>"
277 " <menuitem action='RBudget'/>"
278 " <menuitem action='RVehiculeCost'/>"
280 " <menu action='HelpMenu'>"
281 " <menuitem action='Contents'/>"
283 " <menuitem action='Welcome'/>"
285 " <menuitem action='Online'/>"
286 " <menuitem action='Translate'/>"
287 " <menuitem action='Problem'/>"
289 " <menuitem action='About'/>"
293 " <toolbar name='ToolBar'>"
294 " <toolitem action='New'/>"
295 " <toolitem action='Save'/>"
297 //" <toolitem action='Currency'/>"
298 " <toolitem action='Account'/>"
299 " <toolitem action='Payee'/>"
300 " <toolitem action='Category'/>"
301 " <toolitem action='Assign'/>"
302 " <toolitem action='Archive'/>"
303 " <toolitem action='Budget'/>"
305 " <toolitem action='ShowOpe'/>"
306 " <toolitem action='AddOpe'/>"
308 " <toolitem action='RStatistics'/>"
309 " <toolitem action='RTrendTime'/>"
310 " <toolitem action='RBalance'/>"
311 " <toolitem action='RBudget'/>"
312 " <toolitem action='RVehiculeCost'/>"
324 void ui_mainwindow_revert(GtkWidget
*widget
, gpointer user_data
)
326 //struct hbfile_data *data;
331 DB( g_print("\n[ui-mainwindow] revert\n") );
333 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
335 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
336 dialog
= gtk_message_dialog_new
338 GTK_WINDOW(GLOBALS
->mainwindow
),
339 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
,
340 GTK_MESSAGE_QUESTION
,
342 _("Revert to the previously saved file of '%s'?"),
347 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog
),
348 _("- Changes made to the file will be permanently lost\n"
349 "- File will be restored to the last save (.xhb~)")
352 gtk_dialog_add_buttons (GTK_DIALOG(dialog
),
354 GTK_STOCK_REVERT_TO_SAVED
, 1,
357 result
= gtk_dialog_run( GTK_DIALOG( dialog
) );
358 gtk_widget_destroy( dialog
);
362 DB( g_print(" - should revert\n") );
364 hbfile_change_filepath(hb_filename_new_with_extention(GLOBALS
->xhb_filepath
, "xhb~"));
365 ui_mainwindow_open_internal(widget
, NULL
);
366 hbfile_change_filepath(hb_filename_new_with_extention(GLOBALS
->xhb_filepath
, "xhb"));
373 activate_url (GtkAboutDialog
*about
,
377 DB( g_print("activate url %s\n", link
) );
379 homebank_util_url_show (link
);
382 static void hbfile_about(void)
389 static const gchar
*artists
[] = {
394 static const gchar
*authors
[] = {
395 "Lead developer:\n" \
398 "Ga\xc3\xabtan LORIDANT (Maths formulas for charts)\n",
403 const gchar *documenters[] = {
409 static const gchar license
[] =
410 "This program is free software; you can redistribute it and/or modify\n"
411 "it under the terms of the GNU General Public License as\n"
412 "published by the Free Software Foundation; either version 2 of the\n"
413 "License, or (at your option) any later version.\n\n"
414 "This program is distributed in the hope that it will be useful,\n"
415 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
416 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
417 "GNU General Public License for more details.\n\n"
418 "You should have received a copy of the GNU General Public License\n"
419 "along with this program; if not, write to the Free Software\n"
420 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, "
421 "MA 02110-1301, USA.";
423 static const gchar
*copyright
= "Copyright \xc2\xa9 1995-2014 - Maxime DOYEN";
426 pathfilename
= g_build_filename(homebank_app_get_images_dir(), "splash.png", NULL
);
427 pixbuf
= gdk_pixbuf_new_from_file(pathfilename
, NULL
);
428 g_free(pathfilename
);
430 about
= gtk_about_dialog_new();
431 gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(about
), g_get_application_name ());
432 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about
), PACKAGE_VERSION
);
433 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about
), copyright
);
434 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about
), _("Free, easy, personal accounting for everyone."));
435 gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about
), license
);
436 //gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(about), );
437 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about
), "http://homebank.free.fr");
438 gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(about
), "Visit the HomeBank website");
439 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about
), authors
);
440 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(about
), artists
);
441 //gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(about), );
442 //gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(about), );
443 gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(about
), "homebank");
444 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about
), pixbuf
);
447 gtk_show_about_dialog(GTK_WINDOW(GLOBALS->mainwindow),
448 "name", g_get_application_name (),
449 "logo-icon-name", "homebank",
453 // "translator-credits" , "trans",
454 "comments" , _("Free, easy, personal accounting for everyone."),
456 "copyright" , copyright,
457 "version" , PACKAGE_VERSION,
458 "website" , "http://homebank.free.fr",
459 "website-label", "Visit the HomeBank website",
462 g_signal_connect (about
, "activate-link", G_CALLBACK (activate_url
), NULL
);
464 gtk_dialog_run (GTK_DIALOG (about
));
466 gtk_widget_destroy (about
);
468 g_object_unref (pixbuf
);
476 /* hbfile action functions -------------------- */
477 static void ui_mainwindow_action_new(void)
479 GtkWidget
*widget
= GLOBALS
->mainwindow
;
481 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
483 //clear all, and init GLOBALS->xhb_filepath to default
484 ui_mainwindow_clear(widget
, GINT_TO_POINTER(TRUE
)); // GPOINTER_TO_INT(
485 ui_mainwindow_update(widget
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
489 static void ui_mainwindow_action_open(void)
491 ui_mainwindow_open(GLOBALS
->mainwindow
, NULL
);
494 static void ui_mainwindow_action_save(void)
496 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
499 static void ui_mainwindow_action_saveas(void)
501 ui_mainwindow_save(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
504 static void ui_mainwindow_action_revert(void)
506 ui_mainwindow_revert(GLOBALS
->mainwindow
, NULL
);
509 static void ui_mainwindow_action_close(void)
511 GtkWidget
*widget
= GLOBALS
->mainwindow
;
513 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
515 //clear all, and init GLOBALS->xhb_filepath to default
516 ui_mainwindow_clear(widget
, GINT_TO_POINTER(TRUE
));
517 ui_mainwindow_update(widget
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
523 static void ui_mainwindow_action_quit(void)
527 //gtk_widget_destroy(GLOBALS->mainwindow);
529 g_signal_emit_by_name(GLOBALS
->mainwindow
, "delete-event", NULL
, &result
);
537 static void ui_mainwindow_action_properties(void)
539 create_defhbfile_dialog();
540 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
543 static void ui_mainwindow_action_anonymize(void)
547 result
= ui_dialog_msg_question(
548 GTK_WINDOW(GLOBALS
->mainwindow
),
549 _("Anonymize the file ?"),
550 _("Proceeding will changes name/memo to anonymous datas,\n"
554 if( result
== GTK_RESPONSE_NO
)
558 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_REFRESHALL
));
562 static void ui_mainwindow_action_defcurrency(void)
564 //ui_cur_manage_dialog();
565 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE));
569 static void ui_mainwindow_action_defaccount(void)
571 ui_acc_manage_dialog();
573 //our global list has changed, so update the treeview
574 //todo: optimize this, should not call compute balance here
575 account_compute_balances ();
576 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
578 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
));
581 static void ui_mainwindow_action_defpayee(void)
583 ui_pay_manage_dialog();
584 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
587 static void ui_mainwindow_action_defcategory(void)
589 ui_cat_manage_dialog();
590 //todo:why refresh upcoming here??
591 //ui_mainwindow_populate_upcoming(GLOBALS->mainwindow, NULL);
592 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
595 static void ui_mainwindow_action_defarchive(void)
597 struct hbfile_data
*data
;
600 data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
602 // upcoming list have direct pointer to the arc (which may have changed)
603 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
));
604 gtk_list_store_clear (GTK_LIST_STORE(model
));
606 ui_arc_manage_dialog();
608 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
610 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
614 static void ui_mainwindow_action_defbudget(void)
616 ui_bud_manage_dialog();
617 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
621 static void ui_mainwindow_action_defassign(void)
624 ui_asg_manage_dialog();
626 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
));
630 static void ui_mainwindow_action_preferences(void)
632 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
634 defpref_dialog_new();
635 if(!PREFS
->euro_active
)
637 GtkToggleAction
*action
= (GtkToggleAction
*)gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor");
639 gtk_toggle_action_set_active(action
, FALSE
);
640 ui_mainwindow_action_toggle_minor(action
);
642 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
+UF_REFRESHALL
));
647 static void ui_mainwindow_action_toggle_toolbar(GtkToggleAction
*action
)
649 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
651 PREFS
->wal_toolbar
= gtk_toggle_action_get_active(action
);
652 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
655 static void ui_mainwindow_action_toggle_upcoming(GtkToggleAction
*action
)
657 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
659 PREFS
->wal_upcoming
= gtk_toggle_action_get_active(action
);
660 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
663 static void ui_mainwindow_action_toggle_topspending(GtkToggleAction
*action
)
665 //struct hbfile_data *data = g_object_get_data(G_OBJECT(GLOBALS->mainwindow), "inst_data");
667 PREFS
->wal_spending
= gtk_toggle_action_get_active(action
);
668 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_VISUAL
));
671 static void ui_mainwindow_action_toggle_minor(GtkToggleAction
*action
)
673 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
675 GLOBALS
->minor
= gtk_toggle_action_get_active(action
);
677 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
678 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_upc
));
681 gtk_chart_show_minor(GTK_CHART(data
->RE_pie
), GLOBALS
->minor
);
682 hb_label_set_amount(GTK_LABEL(data
->TX_topamount
), data
->toptotal
, GLOBALS
->minor
);
686 static void ui_mainwindow_action_showtransactions(void)
688 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
694 if( data
->acc
->window
== NULL
)
696 window
= register_panel_window_new(data
->acc
->key
, data
->acc
);
697 register_panel_window_init(window
, NULL
);
701 if(GTK_IS_WINDOW(data
->acc
->window
))
702 gtk_window_present(data
->acc
->window
);
709 static void ui_mainwindow_action_addtransactions(void)
711 ui_mainwindow_addtransactions(GLOBALS
->mainwindow
, NULL
);
714 static void ui_mainwindow_action_checkscheduled(void)
716 ui_mainwindow_scheduled_postall(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
719 static void ui_mainwindow_action_statistic(void)
721 ui_repdist_window_new();
724 static void ui_mainwindow_action_trendtime(void)
726 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
728 ui_reptime_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
731 static void ui_mainwindow_action_budget(void)
733 repbudget_window_new();
736 static void ui_mainwindow_action_balance(void)
738 struct hbfile_data
*data
= g_object_get_data(G_OBJECT(GLOBALS
->mainwindow
), "inst_data");
740 repbalance_window_new(data
->acc
!= NULL
? data
->acc
->key
: 0);
743 static void ui_mainwindow_action_vehiclecost(void)
745 repcost_window_new();
748 static void ui_mainwindow_action_import(void)
750 ui_import_window_new();
756 static void ui_mainwindow_action_about(void)
763 static void ui_mainwindow_action_export(void)
767 if( ui_file_chooser_qif(NULL
, &filename
) == TRUE
)
769 hb_export_qif_account_all(filename
);
774 static void ui_mainwindow_action_help(void)
778 link
= g_build_filename("file:///", homebank_app_get_help_dir(), HOMEBANK_URL_HELP
, NULL
);
779 homebank_util_url_show (link
);
785 //todo: move this to a ui-assist-welcome.c
787 static void ui_mainwindow_action_help_welcome1 (GtkButton
*button
, gpointer user_data
)
789 gtk_dialog_response (GTK_DIALOG(user_data
), 1);
792 static void ui_mainwindow_action_help_welcome2 (GtkButton
*button
, gpointer user_data
)
794 gtk_dialog_response (GTK_DIALOG(user_data
), 2);
797 static void ui_mainwindow_action_help_welcome3 (GtkButton
*button
, gpointer user_data
)
799 gtk_dialog_response (GTK_DIALOG(user_data
), 3);
802 static void ui_mainwindow_action_help_welcome4 (GtkButton
*button
, gpointer user_data
)
804 gtk_dialog_response (GTK_DIALOG(user_data
), 4);
807 static void ui_mainwindow_action_help_welcome5 (GtkButton
*button
, gpointer user_data
)
809 gtk_dialog_response (GTK_DIALOG(user_data
), 5);
812 void ui_mainwindow_action_help_welcome(void)
814 GtkWidget
*dialog
, *content
;
815 GtkWidget
*mainvbox
, *widget
, *label
;
817 dialog
= gtk_dialog_new_with_buttons (_("Welcome to HomeBank"),
818 GTK_WINDOW(GLOBALS
->mainwindow
),
824 content
= gtk_dialog_get_content_area(GTK_DIALOG (dialog
));
826 mainvbox
= gtk_vbox_new (FALSE
, 0);
827 gtk_box_pack_start (GTK_BOX (content
), mainvbox
, FALSE
, FALSE
, 0);
828 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), HB_MAINBOX_SPACING
);
830 label
= make_label (_("HomeBank"), 0, 0);
831 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
832 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
834 label
= make_label (_("Free, easy, personal accounting for everyone."), 0, 0);
835 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
837 widget
= gtk_hseparator_new();
838 gtk_box_pack_start (GTK_BOX (content
), widget
, FALSE
, FALSE
, 0);
840 mainvbox
= gtk_vbox_new (FALSE
, HB_MAINBOX_SPACING
);
841 gtk_box_pack_start (GTK_BOX (content
), mainvbox
, TRUE
, TRUE
, 0);
842 gtk_container_set_border_width (GTK_CONTAINER(mainvbox
), HB_MAINBOX_SPACING
);
844 label
= make_label (_("What do you want to do:"), 0, 0);
845 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
846 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
848 widget
= gtk_button_new_with_mnemonic(_("Read HomeBank _Manual"));
849 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
850 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome1
), dialog
);
852 widget
= gtk_button_new_with_mnemonic(_("Configure _Preferences"));
853 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
854 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome2
), dialog
);
856 widget
= gtk_button_new_with_mnemonic(_("Create a _new file"));
857 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
858 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome3
), dialog
);
860 widget
= gtk_button_new_with_mnemonic(_("_Open an existing file"));
861 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
862 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome4
), dialog
);
864 widget
= gtk_button_new_with_mnemonic(_("Open the _example file"));
865 gtk_box_pack_start (GTK_BOX (mainvbox
), widget
, FALSE
, FALSE
, 0);
866 g_signal_connect (widget
, "clicked", G_CALLBACK (ui_mainwindow_action_help_welcome5
), dialog
);
868 //connect all our signals
869 g_signal_connect (dialog
, "destroy", G_CALLBACK (gtk_widget_destroyed
), &dialog
);
871 gtk_widget_show_all (dialog
);
874 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
876 // cleanup and destroy
877 gtk_widget_destroy (dialog
);
879 // do appropriate action
883 ui_mainwindow_action_help();
886 ui_mainwindow_action_preferences();
889 ui_mainwindow_action_new();
892 ui_mainwindow_action_open();
895 hbfile_change_filepath(g_build_filename(homebank_app_get_datas_dir(), "example.xhb", NULL
));
896 ui_mainwindow_open_internal(GLOBALS
->mainwindow
, NULL
);
904 static void ui_mainwindow_action_help_online(void)
906 const gchar
*link
= HOMEBANK_URL_HELP_ONLINE
;
908 homebank_util_url_show (link
);
912 static void ui_mainwindow_action_help_translate(void)
914 const gchar
*link
= HOMEBANK_URL_HELP_TRANSLATE
;
916 homebank_util_url_show (link
);
920 static void ui_mainwindow_action_help_problem(void)
922 const gchar
*link
= HOMEBANK_URL_HELP_PROBLEM
;
924 homebank_util_url_show (link
);
931 /* hbfile functions -------------------- */
939 static void ui_mainwindow_selection(GtkTreeSelection
*treeselection
, gpointer user_data
)
941 ui_mainwindow_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
945 static void ui_mainwindow_close_openbooks(void)
949 DB( g_print("\n[ui-mainwindow] close openbooks\n") );
951 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
954 Account
*item
= elt
->data
;
958 gtk_widget_destroy(GTK_WIDGET(item
->window
));
962 elt
= g_list_next(elt
);
973 void ui_mainwindow_clear(GtkWidget
*widget
, gpointer user_data
)
975 //struct hbfile_data *data;
976 gboolean file_clear
= GPOINTER_TO_INT(user_data
);
978 DB( g_print("\n[ui-mainwindow] clear\n") );
980 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
982 // Close opened account window
984 ui_mainwindow_close_openbooks();
985 //gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_acc))));
986 //gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_upc))));
987 //gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_top))));
989 hbfile_cleanup(file_clear
);
990 hbfile_setup(file_clear
);
992 if(file_clear
== TRUE
)
994 ui_start_assistant();
995 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
996 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
997 ui_mainwindow_populate_topspending(GLOBALS
->mainwindow
, NULL
);
1004 ** add some transactions directly
1006 void ui_mainwindow_addtransactions(GtkWidget
*widget
, gpointer user_data
)
1008 struct hbfile_data
*data
;
1012 gint account
= 1, count
;
1014 DB( g_print("\n[ui-mainwindow] add transactions\n") );
1016 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1018 /* init the transaction */
1019 date
= homebank_app_date_get_julian();
1020 if(data
->acc
!= NULL
)
1021 account
= data
->acc
->key
;
1023 window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
);
1025 while(result
== GTK_RESPONSE_ADD
)
1029 /* fill in the transaction */
1030 ope
= da_transaction_malloc();
1032 ope
->kacc
= account
;
1034 if( PREFS
->heritdate
== FALSE
) //fix: 318733
1035 ope
->date
= GLOBALS
->today
;
1037 deftransaction_set_transaction(window
, ope
);
1039 result
= gtk_dialog_run (GTK_DIALOG (window
));
1041 DB( g_print(" -> dialog result is %d\n", result
) );
1043 if(result
== GTK_RESPONSE_ADD
|| result
== GTK_RESPONSE_ACCEPT
)
1045 deftransaction_get(window
, NULL
);
1046 transaction_add(ope
, NULL
, ope
->kacc
);
1048 DB( g_print(" -> added 1 transaction to %d\n", ope
->kacc
) );
1050 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
1057 da_transaction_free(ope
);
1063 deftransaction_dispose(window
, NULL
);
1064 gtk_widget_destroy (window
);
1066 /* todo optimize this */
1069 GLOBALS
->changes_count
+= count
;
1070 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_REFRESHALL
));
1080 static gint
tmptop_compare_func(struct tmptop
*tt1
, struct tmptop
*tt2
)
1082 return tt1
->value
> tt2
->value
? 1 : -1;
1086 static void ui_mainwindow_populate_topspending(GtkWidget
*widget
, gpointer user_data
)
1088 struct hbfile_data
*data
;
1089 GtkTreeModel
*model
;
1093 guint n_result
, i
, n_items
;
1095 gdouble total
, other
;
1098 #define MAX_TOPSPENDING 5
1100 DB( g_print("\n[ui-mainwindow] populate_topspending\n") );
1102 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1104 range
= gtk_combo_box_get_active(GTK_COMBO_BOX(data
->CY_range
));
1106 DB( g_print(" - range=%d\n", range
) );
1107 DB( g_print(" - pref range=%d\n", PREFS
->date_range_wal
) );
1109 if(range
== FLT_RANGE_OTHER
)
1112 filter_preset_daterange_set(data
->filter
, range
);
1115 n_result
= da_cat_get_max_key() + 1;
1118 DB( g_print(" - max key is %d\n", n_result
) );
1120 /* allocate some memory */
1121 garray
= g_array_sized_new(FALSE
, FALSE
, sizeof(struct tmptop
), n_result
);
1125 struct tmptop zero
= { .key
=0, .value
=0.0 };
1127 //DB( g_print(" - array length=%d\n", garray->len) );
1129 for(i
=0 ; i
<n_result
; i
++)
1131 g_array_append_vals(garray
, &zero
, 1);
1132 //g_array_insert_vals(garray, i, &zero, 1);
1134 //struct tmptop *tt = &g_array_index (garray, struct tmptop, i);
1135 //DB( g_print("%4d, %4d %f\n", i, tt->key, tt->value) );
1138 //DB( g_print("\n - end array length=%d\n", garray->len) );
1140 /* compute the results */
1141 list
= g_list_first(GLOBALS
->ope_list
);
1142 while (list
!= NULL
)
1144 Transaction
*ope
= list
->data
;
1147 //DB( g_print(" - eval txn: '%s', cat=%d ==> flt-test=%d\n", ope->wording, ope->kcat, filter_test(data->filter, ope)) );
1148 acc
= da_acc_get(ope
->kacc
);
1149 if(acc
== NULL
) goto next1
;
1150 if((acc
->flags
& (AF_CLOSED
|AF_NOREPORT
))) goto next1
;
1151 if(ope
->paymode
== PAYMODE_INTXFER
) goto next1
;
1153 if( !(ope
->flags
& OF_REMIND
) )
1155 if( (ope
->date
>= data
->filter
->mindate
) && (ope
->date
<= data
->filter
->maxdate
) )
1160 //trn_amount = to_base_amount(ope->amount, acc->kcur);
1161 trn_amount
= ope
->amount
;
1163 if( ope
->flags
& OF_SPLIT
)
1165 guint nbsplit
= da_transaction_splits_count(ope
);
1167 struct tmptop
*item
;
1169 for(i
=0;i
<nbsplit
;i
++)
1171 split
= ope
->splits
[i
];
1172 Category
*catentry
= da_cat_get(split
->kcat
);
1174 pos
= (catentry
->flags
& GF_SUB
) ? catentry
->parent
: catentry
->key
;
1176 //trn_amount = to_base_amount(split->amount, acc->kcur);
1177 trn_amount
= split
->amount
;
1178 //#1297054 if( trn_amount < 0 ) {
1179 item
= &g_array_index (garray
, struct tmptop
, pos
);
1181 item
->value
+= trn_amount
;
1182 DB( g_print(" - stored %.2f to item %d\n", trn_amount
, pos
) );
1188 Category
*catentry
= da_cat_get(ope
->kcat
);
1189 struct tmptop
*item
;
1192 pos
= (catentry
->flags
& GF_SUB
) ? catentry
->parent
: catentry
->key
;
1194 //#1297054 if( trn_amount < 0 ) {
1195 item
= &g_array_index (garray
, struct tmptop
, pos
);
1197 item
->value
+= trn_amount
;
1198 DB( g_print(" - stored %.2f to item %d\n", trn_amount
, pos
) );
1205 list
= g_list_next(list
);
1209 // we need to sort this and limit before
1210 g_array_sort(garray
, (GCompareFunc
)tmptop_compare_func
);
1212 n_items
= MIN(garray
->len
,MAX_TOPSPENDING
);
1214 for(i
=0 ; i
<garray
->len
; i
++)
1216 struct tmptop
*item
;
1218 item
= &g_array_index (garray
, struct tmptop
, i
);
1221 total
+= item
->value
;
1224 other
+= item
->value
;
1226 DB( g_print(" - %d : k='%d' v='%f' t='%f'\n", i
, item
->key
, item
->value
, total
) );
1231 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_top
));
1232 gtk_list_store_clear (GTK_LIST_STORE(model
));
1233 g_object_ref(model
); /* Make sure the model stays with us after the tree view unrefs it */
1234 gtk_tree_view_set_model(GTK_TREE_VIEW(data
->LV_top
), NULL
); /* Detach model from view */
1236 /* insert into the treeview */
1237 for(i
=0 ; i
<MIN(garray
->len
,MAX_TOPSPENDING
) ; i
++)
1241 struct tmptop
*item
;
1244 item
= &g_array_index (garray
, struct tmptop
, i
);
1246 if(!item
->value
) continue;
1248 value
= arrondi(item
->value
, 2);
1249 entry
= da_cat_get(item
->key
);
1250 if(entry
== NULL
) continue;
1252 name
= entry
->key
== 0 ? _("(no category)") : entry
->name
;
1255 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1256 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1258 LST_TOPSPEND_KEY
, 0,
1259 LST_TOPSPEND_NAME
, name
,
1260 LST_TOPSPEND_AMOUNT
, value
,
1261 //LST_TOPSPEND_RATE, (gint)(((ABS(value)*100)/ABS(total)) + 0.5),
1269 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1270 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1271 LST_TOPSPEND_ID
, n_items
,
1272 LST_TOPSPEND_KEY
, 0,
1273 LST_TOPSPEND_NAME
, _("Other"),
1274 LST_TOPSPEND_AMOUNT
, other
,
1275 //LST_TOPSPEND_RATE, (gint)(((ABS(other)*100)/ABS(total)) + 0.5),
1279 /* Re-attach model to view */
1280 gtk_tree_view_set_model(GTK_TREE_VIEW(data
->LV_top
), model
);
1281 g_object_unref(model
);
1283 data
->toptotal
= total
;
1284 hb_label_set_amount(GTK_LABEL(data
->TX_topamount
), total
, GLOBALS
->minor
);
1286 gtk_chart_set_color_scheme(GTK_CHART(data
->RE_pie
), PREFS
->report_color_scheme
);
1287 gtk_chart_set_datas(GTK_CHART(data
->RE_pie
), model
, LST_TOPSPEND_AMOUNT
, NULL
);
1288 //gtk_chart_show_legend(GTK_CHART(data->RE_pie), FALSE);
1290 /* update info range text */
1294 daterange
= filter_daterange_text_get(data
->filter
);
1295 gtk_widget_set_tooltip_markup(GTK_WIDGET(data
->CY_range
), daterange
);
1300 /* free our memory */
1301 g_array_free (garray
, TRUE
);
1306 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1308 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1310 ui_mainwindow_scheduled_get_selected_item(GtkTreeView
*treeview
)
1312 GtkTreeSelection
*treeselection
;
1313 GtkTreeModel
*model
;
1316 treeselection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
1317 if( gtk_tree_selection_get_selected(treeselection
, &model
, &iter
) )
1321 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPUPC_DATAS
, &arc
, -1);
1329 static void ui_mainwindow_scheduled_post_cb(GtkWidget
*widget
, gpointer user_data
)
1331 struct hbfile_data
*data
= user_data
;
1333 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1337 if( scheduled_is_postable(arc
) )
1339 Transaction
*txn
= da_transaction_malloc ();
1341 da_transaction_init_from_template(txn
, arc
);
1342 txn
->date
= scheduled_get_postdate(arc
, arc
->nextdate
);
1343 transaction_add(txn
, NULL
, 0);
1344 GLOBALS
->changes_count
++;
1346 scheduled_date_advance(arc
);
1348 da_transaction_free (txn
);
1352 GtkWidget
*window
= create_deftransaction_window(GTK_WINDOW(data
->window
), TRANSACTION_EDIT_ADD
);
1356 /* fill in the transaction */
1357 txn
= da_transaction_malloc();
1358 da_transaction_init_from_template(txn
, arc
);
1359 txn
->date
= scheduled_get_postdate(arc
, arc
->nextdate
);
1361 deftransaction_set_transaction(window
, txn
);
1363 result
= gtk_dialog_run (GTK_DIALOG (window
));
1365 DB( g_print(" -> dialog result is %d\n", result
) );
1367 if(result
== GTK_RESPONSE_ADD
|| result
== GTK_RESPONSE_ACCEPT
)
1369 deftransaction_get(window
, NULL
);
1370 transaction_add(txn
, NULL
, txn
->kacc
);
1371 GLOBALS
->changes_count
++;
1373 scheduled_date_advance(arc
);
1375 DB( g_print(" -> added 1 transaction to %d\n", txn
->kacc
) );
1378 da_transaction_free(txn
);
1380 deftransaction_dispose(window
, NULL
);
1381 gtk_widget_destroy (window
);
1385 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_REFRESHALL
));
1394 static void ui_mainwindow_scheduled_skip_cb(GtkWidget
*widget
, gpointer user_data
)
1396 struct hbfile_data
*data
= user_data
;
1398 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1399 if( (arc
!= NULL
) && (arc
->flags
& OF_AUTO
) )
1401 scheduled_date_advance(arc
);
1403 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1409 static void ui_mainwindow_scheduled_update(GtkWidget
*widget
, gpointer user_data
)
1411 struct hbfile_data
*data
;
1414 DB( g_print("\n[ui-mainwindow] scheduled update\n") );
1416 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1418 //filter = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_sched_filter));
1420 Archive
*arc
= ui_mainwindow_scheduled_get_selected_item(GTK_TREE_VIEW(data
->LV_upc
));
1424 DB( g_print("archive is %s\n", arc
->wording
) );
1426 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_post
), TRUE
);
1427 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_skip
), TRUE
);
1431 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_post
), FALSE
);
1432 gtk_widget_set_sensitive(GTK_WIDGET(data
->BT_sched_skip
), FALSE
);
1439 static void ui_mainwindow_scheduled_selection_cb(GtkTreeSelection
*treeselection
, gpointer user_data
)
1443 ui_mainwindow_scheduled_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection
)), GINT_TO_POINTER(UF_SENSITIVE
));
1449 ** called after load, importamiga, on demand
1451 void ui_mainwindow_scheduled_postall(GtkWidget
*widget
, gpointer user_data
)
1453 //struct hbfile_data *data;
1455 gint usermode
= GPOINTER_TO_INT(user_data
);
1457 DB( g_print("\n[ui-mainwindow] check scheduled\n") );
1459 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1461 count
= scheduled_post_all_pending();
1464 if(usermode
== TRUE
)
1471 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_REFRESHALL
));
1475 txt
= _("No transaction to add");
1477 txt
= _("transaction added: %d");
1479 ui_dialog_msg_infoerror(GTK_WINDOW(GLOBALS
->mainwindow
), GTK_MESSAGE_INFO
,
1480 _("Check scheduled transactions result"),
1488 static void ui_mainwindow_scheduled_populate(GtkWidget
*widget
, gpointer user_data
)
1490 struct hbfile_data
*data
;
1491 GtkTreeModel
*model
;
1498 guint32 maxpostdate
;
1502 DB( g_print("\n[ui-mainwindow] scheduled populate list\n") );
1504 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1506 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_upc
));
1507 gtk_list_store_clear (GTK_LIST_STORE(model
));
1509 homebank_app_date_get_julian();
1511 maxpostdate
= scheduled_date_get_post_max();
1513 date
= g_date_new_julian (maxpostdate
);
1514 g_date_strftime (buffer
, 256-1, PREFS
->date_format
, date
);
1517 gtk_label_set_text(GTK_LABEL(data
->LB_maxpostdate
), buffer
);
1520 list
= g_list_first(GLOBALS
->arc_list
);
1521 while (list
!= NULL
)
1523 Archive
*arc
= list
->data
;
1524 guint nbdays
, nblate
;
1526 if((arc
->flags
& OF_AUTO
) ) //&& arc->kacc > 0)
1529 nbdays
= arc
->nextdate
- maxpostdate
;
1530 nblate
= scheduled_get_latepost_count(arc
, GLOBALS
->today
);
1532 DB( g_print(" - append '%s' : %d\n", arc
->wording
, nbdays
) );
1534 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1535 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1536 LST_DSPUPC_DATAS
, arc
,
1537 LST_DSPUPC_WORDING
, arc
->wording
,
1538 LST_DSPUPC_EXPENSE
, !(arc
->flags
& OF_INCOME
) ? arc
->amount
: 0.0,
1539 LST_DSPUPC_INCOME
, (arc
->flags
& OF_INCOME
) ? arc
->amount
: 0.0,
1540 LST_DSPUPC_REMAINING
, nbdays
,
1541 LST_DSPUPC_NB_LATE
, nblate
,
1544 //acc = da_acc_get(arc->kacc);
1545 //total += to_base_amount(arc->amount, acc->kcur);
1546 if(arc
->flags
& OF_INCOME
)
1547 totinc
+= arc
->amount
;
1549 totexp
+= arc
->amount
;
1552 list
= g_list_next(list
);
1558 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
1559 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
1560 LST_DSPUPC_DATAS
, NULL
,
1561 LST_DSPUPC_WORDING
, _("Total"),
1562 LST_DSPUPC_EXPENSE
, totexp
,
1563 LST_DSPUPC_INCOME
, totinc
,
1568 ui_mainwindow_scheduled_update(widget
, NULL
);
1578 void ui_mainwindow_open(GtkWidget
*widget
, gpointer user_data
)
1580 //struct hbfile_data *data;
1581 gchar
*filename
= NULL
;
1583 DB( g_print("\n[ui-mainwindow] open\n") );
1585 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1587 if( ui_dialog_msg_savechanges(widget
,NULL
) == TRUE
)
1589 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_OPEN
, &filename
) == TRUE
)
1591 hbfile_change_filepath(filename
);
1593 ui_mainwindow_open_internal(widget
, NULL
);
1601 * open the file stored in GLOBALS->xhb_filepath
1603 void ui_mainwindow_open_internal(GtkWidget
*widget
, gpointer user_data
)
1605 struct hbfile_data
*data
;
1608 DB( g_print("\n[ui-mainwindow] open internal\n") );
1610 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1612 DB( g_print(" -> filename: '%s'\n", GLOBALS
->xhb_filepath
) );
1614 if( GLOBALS
->xhb_filepath
!= NULL
)
1616 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(FALSE
));
1617 GLOBALS
->hbfile_is_new
= FALSE
;
1619 r
= homebank_load_xml(GLOBALS
->xhb_filepath
);
1622 DB( g_print(" -> file loaded ok : rcode=%d\n", r
) );
1624 hbfile_file_hasbackup(GLOBALS
->xhb_filepath
);
1626 if(PREFS
->appendscheduled
)
1627 scheduled_post_all_pending();
1629 homebank_lastopenedfiles_save();
1631 //todo: remove this after computing done at xml read
1632 account_compute_balances();
1634 ui_mainwindow_recent_add(data
, GLOBALS
->xhb_filepath
);
1635 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
1636 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
1637 ui_mainwindow_populate_topspending(GLOBALS
->mainwindow
, NULL
);
1641 gchar
*msg
= _("Unknow error");
1646 msg
= _("I/O error for file '%s'.");
1648 case XML_FILE_ERROR
:
1649 msg
= _("The file '%s' is not a valid HomeBank file.");
1651 case XML_VERSION_ERROR
:
1652 msg
= _("The file '%s' was saved with a higher version of HomeBank\nand cannot be loaded by the current version.");
1656 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1659 GLOBALS
->xhb_filepath
1662 ui_mainwindow_clear(GLOBALS
->mainwindow
, GINT_TO_POINTER(TRUE
));
1666 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1675 void ui_mainwindow_save(GtkWidget
*widget
, gpointer user_data
)
1677 struct hbfile_data
*data
;
1678 gboolean saveas
= GPOINTER_TO_INT(user_data
);
1679 gchar
*filename
= NULL
;
1682 DB( g_print("\n[ui-mainwindow] save\n") );
1684 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1686 if( GLOBALS
->hbfile_is_new
== TRUE
)
1691 if(ui_file_chooser_xhb(GTK_FILE_CHOOSER_ACTION_SAVE
, &filename
) == TRUE
)
1693 DB( g_print(" + should save as %s\n", GLOBALS
->xhb_filepath
) );
1694 hbfile_change_filepath(filename
);
1695 homebank_backup_current_file(GLOBALS
->xhb_filepath
);
1696 homebank_file_ensure_xhb();
1697 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1698 GLOBALS
->hbfile_is_new
= FALSE
;
1705 DB( g_print(" + should quick save %s\n", GLOBALS
->xhb_filepath
) );
1706 homebank_backup_current_file(GLOBALS
->xhb_filepath
);
1707 homebank_file_ensure_xhb();
1708 r
= homebank_save_xml(GLOBALS
->xhb_filepath
);
1714 GLOBALS
->changes_count
= 0;
1715 ui_mainwindow_update(GLOBALS
->mainwindow
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_VISUAL
));
1719 gchar
*msg
= _("I/O error for file %s.");
1721 ui_dialog_msg_infoerror(GTK_WINDOW(data
->window
), GTK_MESSAGE_ERROR
,
1724 GLOBALS
->xhb_filepath
1733 void ui_mainwindow_populate_accounts(GtkWidget
*widget
, gpointer user_data
)
1735 struct hbfile_data
*data
;
1736 GtkTreeModel
*model
;
1737 GtkTreeIter iter1
, child_iter
;
1741 gdouble gtbank
, gttoday
, gtfuture
;
1743 DB( g_print("\n[ui-mainwindow] populate accounts\n") );
1745 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1747 /* here we create a count and a list of every account pointer by type */
1749 GPtrArray
*typeacc
[ACC_TYPE_MAXVALUE
] = {0};
1750 lacc
= elt
= g_hash_table_get_values(GLOBALS
->h_acc
);
1755 if( !(acc
->flags
& (AF_CLOSED
|AF_NOSUMMARY
)) )
1757 DB( g_print(" -> insert %d:%s\n", acc
->key
, acc
->name
) );
1759 if(typeacc
[acc
->type
] == NULL
)
1760 typeacc
[acc
->type
] = g_ptr_array_sized_new(da_acc_length ());
1762 g_ptr_array_add(typeacc
[acc
->type
], (gpointer
)acc
);
1764 elt
= g_list_next(elt
);
1768 gtbank
= gttoday
= gtfuture
= 0;
1770 DB( g_print(" -> populate listview\n") );
1773 /* then populate the listview */
1774 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_acc
));
1775 gtk_tree_store_clear (GTK_TREE_STORE(model
));
1778 for(i
=0;i
<ACC_TYPE_MAXVALUE
;i
++)
1780 GPtrArray
*gpa
= typeacc
[i
];
1781 gdouble tbank
, ttoday
, tfuture
;
1786 //1: Header: Bank, Cash, ...
1787 DB( g_print(" -> append type '%s'\n", CYA_ACC_TYPE
[i
]) );
1789 gtk_tree_store_append (GTK_TREE_STORE(model
), &iter1
, NULL
);
1790 gtk_tree_store_set (GTK_TREE_STORE(model
), &iter1
,
1791 LST_DSPACC_DATATYPE
, DSPACC_TYPE_HEADER
,
1792 LST_DSPACC_NAME
, _(CYA_ACC_TYPE
[i
]),
1795 tbank
= ttoday
= tfuture
= 0;
1797 //2: Accounts for real
1798 for(j
=0;j
<gpa
->len
;j
++)
1800 acc
= g_ptr_array_index(gpa
, j
);
1802 //if(acc->kcur == GLOBALS->kcur)
1804 tbank
+= acc
->bal_bank
;
1805 ttoday
+= acc
->bal_today
;
1806 tfuture
+= acc
->bal_future
;
1810 tbank += to_base_amount(acc->bal_bank, acc->kcur);
1811 ttoday += to_base_amount(acc->bal_today, acc->kcur);
1812 tfuture += to_base_amount(acc->bal_future, acc->kcur);
1815 DB( g_print(" - insert '%s' :: %.2f %.2f %.2f\n", acc
->name
, acc
->bal_bank
, acc
->bal_today
, acc
->bal_future
) );
1817 gtk_tree_store_append (GTK_TREE_STORE(model
), &child_iter
, &iter1
);
1818 gtk_tree_store_set (GTK_TREE_STORE(model
), &child_iter
,
1819 LST_DSPACC_DATAS
, acc
,
1820 LST_DSPACC_DATATYPE
, DSPACC_TYPE_NORMAL
,
1821 LST_DSPACC_BANK
, acc
->bal_bank
,
1822 LST_DSPACC_TODAY
, acc
->bal_today
,
1823 LST_DSPACC_FUTURE
, acc
->bal_future
,
1829 DB( g_print(" - type totals :: %.2f %.2f %.2f\n", tbank
, ttoday
, tfuture
) );
1831 // insert the total line
1832 gtk_tree_store_append (GTK_TREE_STORE(model
), &child_iter
, &iter1
);
1833 gtk_tree_store_set (GTK_TREE_STORE(model
), &child_iter
,
1834 LST_DSPACC_DATATYPE
, DSPACC_TYPE_SUBTOTAL
,
1835 LST_DSPACC_NAME
, _("Total"),
1836 LST_DSPACC_BANK
, tbank
,
1837 LST_DSPACC_TODAY
, ttoday
,
1838 LST_DSPACC_FUTURE
, tfuture
,
1842 /* set balance to header to display when collasped */
1843 gtk_tree_store_set (GTK_TREE_STORE(model
), &iter1
,
1844 LST_DSPACC_BANK
, tbank
,
1845 LST_DSPACC_TODAY
, ttoday
,
1846 LST_DSPACC_FUTURE
, tfuture
,
1849 /* add to grand total */
1852 gtfuture
+= tfuture
;
1858 DB( g_print(" - grand totals :: %.2f %.2f %.2f\n", gtbank
, gttoday
, gtfuture
) );
1863 gtk_tree_store_append (GTK_TREE_STORE(model
), &iter1
, NULL
);
1864 gtk_tree_store_set (GTK_TREE_STORE(model
), &iter1
,
1865 LST_DSPACC_DATATYPE
, DSPACC_TYPE_SUBTOTAL
,
1866 LST_DSPACC_NAME
, _("Grand total"),
1867 LST_DSPACC_BANK
, gtbank
,
1868 LST_DSPACC_TODAY
, gttoday
,
1869 LST_DSPACC_FUTURE
, gtfuture
,
1874 gtk_tree_view_expand_all(GTK_TREE_VIEW(data
->LV_acc
));
1876 DB( g_print(" -> free ressources\n") );
1879 /* free all temp stuff */
1880 for(i
=0;i
<ACC_TYPE_MAXVALUE
;i
++)
1882 GPtrArray
*gpa
= typeacc
[i
];
1885 g_ptr_array_free (gpa
, TRUE
);
1892 void ui_mainwindow_update(GtkWidget
*widget
, gpointer user_data
)
1894 struct hbfile_data
*data
;
1897 DB( g_print("\n[ui-mainwindow] refresh_display\n") );
1899 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
1900 //data = INST_DATA(widget);
1902 flags
= GPOINTER_TO_INT(user_data
);
1904 /* set window title */
1905 if(flags
& UF_TITLE
)
1910 DB( printf(" + 1: wintitle %x\n", (gint
)data
->wintitle
) );
1912 basename
= g_path_get_basename(GLOBALS
->xhb_filepath
);
1914 DB( printf(" global changes: %d\n", GLOBALS
->changes_count
) );
1916 g_free(data
->wintitle
);
1918 changed
= (GLOBALS
->changes_count
> 0) ? "*" : "";
1920 data
->wintitle
= g_strdup_printf("%s%s - %s - " PROGNAME
, changed
, basename
, GLOBALS
->owner
);
1922 gtk_window_set_title (GTK_WINDOW (gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), data
->wintitle
);
1927 /* update disabled things */
1928 if(flags
& UF_SENSITIVE
)
1930 GtkTreeSelection
*selection
;
1931 GtkTreeModel
*model
;
1934 gboolean active
,sensitive
;
1936 DB( printf(" + 2: disabled, opelist count\n") );
1938 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
));
1940 active
= gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1946 path
= gtk_tree_model_get_path(model
, &iter
);
1947 depth
= gtk_tree_path_get_depth(path
);
1951 DB( printf(" depth is %d\n", depth
) );
1953 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, LST_DSPACC_DATAS
, &acc
, -1);
1962 //ensure data->acc will not be null
1963 data
->acc
= da_acc_get(1);
1967 // no change: disable save
1968 DB( printf(" changes %d - new %d\n", GLOBALS
->changes_count
, GLOBALS
->hbfile_is_new
) );
1971 sensitive
= (GLOBALS
->changes_count
!= 0 ) ? TRUE
: FALSE
;
1972 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/FileMenu/SaveAs"), sensitive);
1973 //if(sensitive == TRUE && GLOBALS->hbfile_is_new == TRUE) sensitive = FALSE;
1974 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Save"), sensitive
);
1975 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Revert"), GLOBALS
->xhb_hasbak
);
1979 sensitive
= GLOBALS
->define_off
== 0 ? TRUE
: FALSE
;
1981 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Account"), sensitive
);
1982 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Payee"), sensitive
);
1983 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Category"), sensitive
);
1984 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data->manager, "/MenuBar/ManageMenu/Assign"), sensitive);
1985 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
1986 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/EditMenu/Preferences"), sensitive
);
1988 // empty account list: disable Import, Archives, Edit, Filter, Add, Statistics, Overdrawn, Car Cost
1989 sensitive
= da_acc_length() > 0 ? TRUE
: FALSE
;
1991 //gtk_action_set_sensitive(gtk_ui_manager_get_action(data-data->manager, "/MenuBar/FileMenu/Import"), sensitive);
1993 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/FileMenu/Close"), sensitive
);
1994 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Archive"), sensitive
);
1995 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TransactionMenu/AddOpe"), sensitive
);
1996 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TransactionMenu/ShowOpe"), sensitive
);
1997 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RStatistics"), sensitive
);
1998 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RTrendTime"), sensitive
);
1999 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBudget"), sensitive
);
2000 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RBalance"), sensitive
);
2001 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ReportMenu/RVehiculeCost"), sensitive
);
2003 // empty category list: disable Budget & Budget report
2004 sensitive
= da_cat_length() > 1 ? TRUE
: FALSE
;
2006 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ManageMenu/Budget"), sensitive
);
2008 // empty archive list: disable scheduled check
2009 sensitive
= g_list_length(GLOBALS
->arc_list
) > 0 ? TRUE
: FALSE
;
2011 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TransactionMenu/AddScheduled"), sensitive
);
2013 // no active account: disable Edit, Over
2014 sensitive
= (active
== TRUE
) ? TRUE
: FALSE
;
2015 if(data
->acc
&& data
->acc
->window
!= NULL
)
2018 gtk_action_set_sensitive(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/TransactionMenu/ShowOpe"), sensitive
);
2022 /* update toolbar, list */
2023 if(flags
& UF_VISUAL
)
2025 DB( printf(" + 8: visual\n") );
2027 if(PREFS
->toolbar_style
== 0)
2028 gtk_toolbar_unset_style(GTK_TOOLBAR(data
->toolbar
));
2030 gtk_toolbar_set_style(GTK_TOOLBAR(data
->toolbar
), PREFS
->toolbar_style
-1);
2032 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (data
->LV_acc
), PREFS
->rules_hint
);
2033 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
2035 DB( printf(" - show toolbar=%d\n", PREFS
->wal_toolbar
) );
2036 if(PREFS
->wal_toolbar
)
2037 gtk_widget_show(GTK_WIDGET(data
->toolbar
));
2039 gtk_widget_hide(GTK_WIDGET(data
->toolbar
));
2042 DB( printf(" - show top_spending=%d\n", PREFS
->wal_spending
) );
2044 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
2046 if(PREFS
->wal_spending
)
2047 gtk_widget_show(GTK_WIDGET(data
->GR_top
));
2049 gtk_widget_hide(GTK_WIDGET(data
->GR_top
));
2053 DB( printf(" - show upcoming=%d\n", PREFS
->wal_upcoming
) );
2054 if(PREFS
->wal_upcoming
)
2055 gtk_widget_show(GTK_WIDGET(data
->GR_upc
));
2057 gtk_widget_hide(GTK_WIDGET(data
->GR_upc
));
2059 DB( printf(" minor %d\n", PREFS
->euro_active
) );
2060 gtk_action_set_visible(gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/AsMinor"), PREFS
->euro_active
);
2063 /* update balances */
2064 if(flags
& UF_BALANCE
)
2067 DB( printf(" + 4: balances\n") );
2069 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data
->LV_acc
));
2071 //minor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_minor));
2074 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[0]), data->bank, minor);
2075 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[1]), data->today, minor);
2076 hb-label_set_colvalue(GTK_LABEL(data->TX_balance[2]), data->future, minor);
2080 if(flags
& UF_REFRESHALL
)
2082 DB( printf(" + 8: refreshall\n") );
2084 ui_mainwindow_populate_accounts(GLOBALS
->mainwindow
, NULL
);
2085 ui_mainwindow_populate_topspending(GLOBALS
->mainwindow
, NULL
);
2086 ui_mainwindow_scheduled_populate(GLOBALS
->mainwindow
, NULL
);
2095 ui_mainwindow_onRowActivated (GtkTreeView
*treeview
,
2097 GtkTreeViewColumn
*col
,
2100 GtkTreeModel
*model
;
2103 DB( g_print ("\n[ui-mainwindow] A row has been double-clicked!\n") );
2105 model
= gtk_tree_view_get_model(treeview
);
2107 if (gtk_tree_model_get_iter(model
, &iter
, path
))
2111 gtk_tree_model_get(model
, &iter
, LST_DSPACC_DATAS
, &acc
, -1);
2116 DB( g_print ("Double-clicked row contains name %s\n", acc
->name
) );
2118 ui_mainwindow_action_showtransactions();
2128 static gboolean
ui_mainwindow_dispose(GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
2130 struct hbfile_data
*data
= user_data
;
2131 struct WinGeometry
*wg
;
2132 gboolean retval
= FALSE
;
2134 DB( g_print("\n[ui-mainwindow] dispose\n") );
2136 //store position and size
2137 wg
= &PREFS
->wal_wg
;
2138 gtk_window_get_position(GTK_WINDOW(widget
), &wg
->l
, &wg
->t
);
2139 gtk_window_get_size(GTK_WINDOW(widget
), &wg
->w
, &wg
->h
);
2140 GdkWindow
*gdk_window
= gtk_widget_get_window(GTK_WIDGET(widget
));
2141 GdkWindowState state
= gdk_window_get_state(gdk_window
);
2142 wg
->s
= (state
& GDK_WINDOW_STATE_MAXIMIZED
) ? 1 : 0;
2144 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
) );
2146 PREFS
->wal_vpaned
= gtk_paned_get_position(GTK_PANED(data
->vpaned
));
2147 PREFS
->wal_hpaned
= gtk_paned_get_position(GTK_PANED(data
->hpaned
));
2149 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
2152 if(ui_dialog_msg_savechanges(widget
, NULL
) == FALSE
)
2158 DB( g_print(" free wintitle %x\n", (gint
)data
->wintitle
) );
2160 gtk_widget_destroy(data
->LV_top
);
2162 g_free(data
->wintitle
);
2163 da_filter_free(data
->filter
);
2170 //delete-event TRUE abort/FALSE destroy
2175 static void ui_mainwindow_recent_chooser_item_activated_cb (GtkRecentChooser
*chooser
, struct hbfile_data
*data
)
2178 GError
*error
= NULL
;
2180 uri
= gtk_recent_chooser_get_current_uri (chooser
);
2182 path
= g_filename_from_uri (uri
, NULL
, NULL
);
2185 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
2186 g_error_free (error
);
2190 if( ui_dialog_msg_savechanges(data
->window
, NULL
) == TRUE
)
2197 gpw_recent_remove (gpw, path);
2201 hbfile_change_filepath(path
);
2202 ui_mainwindow_open_internal(data
->window
, NULL
);
2212 static void ui_mainwindow_window_screen_changed_cb (GtkWidget
*widget
,
2213 GdkScreen
*old_screen
,
2214 struct hbfile_data
*data
)
2217 DB( g_print("\n[ui-mainwindow] screen_changed_cb\n") );
2220 data
->recent_manager
= gtk_recent_manager_get_default ();
2222 gtk_menu_detach (GTK_MENU (data
->recent_menu
));
2223 g_object_unref (G_OBJECT (data
->recent_menu
));
2225 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2227 g_signal_connect (data
->recent_menu
,
2229 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2232 //menu_item = gtk_ui_manager_get_widget (data->manager, "/MenuBar/FileMenu/OpenRecent");
2233 //gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), data->recent_menu);
2237 void ui_mainwindow_recent_add (struct hbfile_data
*data
, const gchar
*path
)
2239 GtkRecentData
*recent_data
;
2241 GError
*error
= NULL
;
2243 DB( g_print("\n[ui-mainwindow] recent_add\n") );
2245 DB( g_print(" - suffix xhb %d", g_str_has_suffix (path
, ".xhb") ) );
2247 if( g_str_has_suffix (path
, ".xhb") == FALSE
) //ignore reverted file
2250 uri
= g_filename_to_uri (path
, NULL
, &error
);
2253 g_warning ("Could not convert uri \"%s\" to a local path: %s", uri
, error
->message
);
2254 g_error_free (error
);
2258 recent_data
= g_slice_new (GtkRecentData
);
2260 recent_data
->display_name
= NULL
;
2261 recent_data
->description
= NULL
;
2262 recent_data
->mime_type
= "application/x-homebank";
2263 recent_data
->app_name
= (gchar
*) g_get_application_name ();
2264 recent_data
->app_exec
= g_strjoin (" ", g_get_prgname (), "%u", NULL
);
2265 recent_data
->groups
= NULL
;
2266 recent_data
->is_private
= FALSE
;
2268 if (!gtk_recent_manager_add_full (data
->recent_manager
,
2272 g_warning ("Unable to add '%s' to the list of recently used documents", uri
);
2276 g_free (recent_data
->app_exec
);
2277 g_slice_free (GtkRecentData
, recent_data
);
2290 static GtkTargetEntry drop_types
[] =
2292 {"text/uri-list", 0, TARGET_URI_LIST
}
2295 static void ui_mainwindow_drag_data_received (GtkWidget
*widget
,
2296 GdkDragContext
*context
,
2298 GtkSelectionData
*selection_data
,
2299 guint info
, guint time
, GtkWindow
*window
)
2301 gchar
**uris
, **str
;
2303 gint filetype
, slen
;
2305 if (info
!= TARGET_URI_LIST
)
2308 DB( g_print("\n[ui-mainwindow] drag_data_received\n") );
2310 /* On MS-Windows, it looks like `selection_data->data' is not NULL terminated. */
2311 slen
= gtk_selection_data_get_length(selection_data
);
2312 data
= g_new (gchar
, slen
+ 1);
2313 memcpy (data
, gtk_selection_data_get_data(selection_data
), slen
);
2316 uris
= g_uri_list_extract_uris (data
);
2319 //for (str = uris; *str; str++)
2322 GError
*error
= NULL
;
2323 gchar
*path
= g_filename_from_uri (*str
, NULL
, &error
);
2327 filetype
= homebank_alienfile_recognize(path
);
2329 DB( g_print(" - dragged %s, type is %d\n", path
, filetype
) );
2331 if( filetype
== FILETYPE_HOMEBANK
)
2333 hbfile_change_filepath(path
);
2334 ui_mainwindow_open_internal(GTK_WIDGET(window
), NULL
);
2338 //todo: future here to implement import for other filetype
2340 ui_dialog_msg_infoerror(GTK_WINDOW(window
), GTK_MESSAGE_ERROR
,
2342 _("The file %s is not a valid HomeBank file."),
2352 g_warning ("Could not convert uri to local path: %s", error
->message
);
2354 g_error_free (error
);
2362 static GtkWidget
*ui_mainwindow_create_recent_chooser_menu (GtkRecentManager
*manager
)
2364 GtkWidget
*toolbar_recent_menu
;
2365 GtkRecentFilter
*filter
;
2367 toolbar_recent_menu
= gtk_recent_chooser_menu_new_for_manager (manager
);
2369 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu
),
2371 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu
),
2372 GTK_RECENT_SORT_MRU
);
2373 //todo: add a user pref for this
2374 gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER (toolbar_recent_menu
),
2378 //gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (toolbar_recent_menu), FALSE);
2380 //gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (toolbar_recent_menu), TRUE);
2382 filter
= gtk_recent_filter_new ();
2383 //gtk_recent_filter_add_application (filter, g_get_application_name());
2384 gtk_recent_filter_add_pattern (filter
, "*.[Xx][Hh][Bb]");
2385 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (toolbar_recent_menu
), filter
);
2387 return toolbar_recent_menu
;
2391 static void ui_mainwindow_create_menu_bar_and_toolbar(struct hbfile_data
*data
, GtkWidget
*mainvbox
)
2393 GtkUIManager
*manager
;
2394 GtkActionGroup
*action_group
;
2396 GError
*error
= NULL
;
2398 manager
= gtk_ui_manager_new ();
2399 data
->manager
= manager
;
2401 gtk_window_add_accel_group (GTK_WINDOW (data
->window
),
2402 gtk_ui_manager_get_accel_group(manager
));
2404 action_group
= gtk_action_group_new ("MainWindow");
2405 gtk_action_group_set_translation_domain(action_group
, GETTEXT_PACKAGE
);
2407 gtk_action_group_add_actions (action_group
,
2412 gtk_action_group_add_toggle_actions (action_group
,
2417 gtk_ui_manager_insert_action_group (data
->manager
, action_group
, 0);
2418 g_object_unref (action_group
);
2419 data
->actions
= action_group
;
2421 /* set short labels to use in the toolbar */
2422 action
= gtk_action_group_get_action(action_group
, "Open");
2423 g_object_set(action
, "short_label", _("Open"), NULL
);
2425 action
= gtk_action_group_get_action(action_group
, "Save");
2426 g_object_set(action
, "is_important", TRUE
, NULL
);
2428 action
= gtk_action_group_get_action(action_group
, "Account");
2429 g_object_set(action
, "short_label", _("Account"), NULL
);
2431 action
= gtk_action_group_get_action(action_group
, "Payee");
2432 g_object_set(action
, "short_label", _("Payee"), NULL
);
2434 action
= gtk_action_group_get_action(action_group
, "Category");
2435 g_object_set(action
, "short_label", _("Category"), NULL
);
2437 action
= gtk_action_group_get_action(action_group
, "Archive");
2438 //TRANSLATORS: an archive is stored transaction buffers (kind of bookmark to prefill manual insertion)
2439 g_object_set(action
, "short_label", _("Archive"), NULL
);
2441 action
= gtk_action_group_get_action(action_group
, "Budget");
2442 g_object_set(action
, "short_label", _("Budget"), NULL
);
2444 action
= gtk_action_group_get_action(action_group
, "ShowOpe");
2445 g_object_set(action
, "short_label", _("Show"), NULL
);
2447 action
= gtk_action_group_get_action(action_group
, "AddOpe");
2448 g_object_set(action
, "is_important", TRUE
, "short_label", _("Add"), NULL
);
2450 action
= gtk_action_group_get_action(action_group
, "RStatistics");
2451 g_object_set(action
, "short_label", _("Statistics"), NULL
);
2453 action
= gtk_action_group_get_action(action_group
, "RBudget");
2454 g_object_set(action
, "short_label", _("Budget"), NULL
);
2456 action
= gtk_action_group_get_action(action_group
, "RBalance");
2457 g_object_set(action
, "short_label", _("Balance"), NULL
);
2459 action
= gtk_action_group_get_action(action_group
, "RVehiculeCost");
2460 g_object_set(action
, "short_label", _("Vehicle cost"), NULL
);
2462 /* now load the UI definition */
2463 gtk_ui_manager_add_ui_from_string (data
->manager
, ui_info
, -1, &error
);
2466 g_message ("Building menus failed: %s", error
->message
);
2467 g_error_free (error
);
2471 data
->menubar
= gtk_ui_manager_get_widget (manager
, "/MenuBar");
2472 gtk_box_pack_start (GTK_BOX (mainvbox
),
2478 data
->toolbar
= gtk_ui_manager_get_widget (manager
, "/ToolBar");
2479 gtk_box_pack_start (GTK_BOX (mainvbox
),
2485 /* recent files menu */
2489 data
->recent_manager
= gtk_recent_manager_get_default ();
2491 data
->recent_menu
= ui_mainwindow_create_recent_chooser_menu (data
->recent_manager
);
2493 g_signal_connect (data
->recent_menu
,
2495 G_CALLBACK (ui_mainwindow_recent_chooser_item_activated_cb
),
2499 widget = gtk_ui_manager_get_widget (data->manager, "/MenuBar/FileMenu/OpenRecent");
2500 gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), data->recent_menu);
2504 /* add the custom Open button to the toolbar */
2505 GtkToolItem
*open_button
= gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN
);
2506 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button
),
2509 gtk_tool_item_set_tooltip_text (open_button
, _("Open a file"));
2510 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button
),
2511 _("Open a recently used file"));
2514 action
= gtk_action_group_get_action (data
->actions
, "Open");
2515 g_object_set (action
,
2516 "short_label", _("Open"),
2518 //gtk_action_connect_proxy (action, GTK_WIDGET (open_button));
2519 gtk_activatable_set_related_action (GTK_ACTIVATABLE (open_button
), action
);
2521 gtk_toolbar_insert (GTK_TOOLBAR (data
->toolbar
),
2528 static GtkWidget
*ui_mainwindow_create_youraccounts(struct hbfile_data
*data
)
2530 GtkWidget
*mainvbox
, *align
, *label
, *widget
, *sw
;
2532 mainvbox
= gtk_vbox_new (FALSE
, 0);
2534 label
= make_label(_("Your accounts"), 0.0, 0.5);
2535 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
2536 gtk_misc_set_padding (GTK_MISC(label
), HB_BOX_SPACING
, HB_BOX_SPACING
/2);
2537 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
2539 align
= gtk_alignment_new(0, 0, 1.0, 1.0);
2540 // top, bottom, left, right
2541 gtk_alignment_set_padding (GTK_ALIGNMENT(align
), 0, HB_BOX_SPACING
, 2*HB_BOX_SPACING
, HB_BOX_SPACING
);
2542 gtk_box_pack_start (GTK_BOX (mainvbox
), align
, TRUE
, TRUE
, 0);
2544 sw
= gtk_scrolled_window_new (NULL
, NULL
);
2545 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw
), GTK_SHADOW_ETCHED_IN
);
2546 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw
), GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2547 gtk_container_add (GTK_CONTAINER (align
), sw
);
2549 widget
= (GtkWidget
*)create_list_account();
2550 data
->LV_acc
= widget
;
2551 gtk_container_add (GTK_CONTAINER (sw
), widget
);
2557 static GtkWidget
*ui_mainwindow_create_topspending(struct hbfile_data
*data
)
2559 GtkWidget
*mainvbox
, *hbox
, *vbox
;
2560 GtkWidget
*label
, *align
, *widget
;
2562 mainvbox
= gtk_vbox_new (FALSE
, 0);
2563 data
->GR_top
= mainvbox
;
2565 label
= make_label(_("Where your money goes"), 0.0, 0.5);
2566 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
2567 gtk_misc_set_padding (GTK_MISC(label
), HB_BOX_SPACING
, HB_BOX_SPACING
/2);
2568 gtk_box_pack_start (GTK_BOX (mainvbox
), label
, FALSE
, FALSE
, 0);
2570 align
= gtk_alignment_new(0, 0, 1.0, 1.0);
2571 // top, bottom, left, right
2572 gtk_alignment_set_padding (GTK_ALIGNMENT(align
), 0, HB_BOX_SPACING
, 2*HB_BOX_SPACING
, HB_BOX_SPACING
);
2573 gtk_box_pack_start (GTK_BOX (mainvbox
), align
, TRUE
, TRUE
, 0);
2575 vbox
= gtk_vbox_new (FALSE
, HB_BOX_SPACING
);
2576 gtk_container_add (GTK_CONTAINER (align
), vbox
);
2578 /* total + date range */
2579 hbox
= gtk_hbox_new (FALSE
, HB_BOX_SPACING
);
2580 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
2582 label
= make_label(_("Top 5 spending"), 0.0, 0.5);
2583 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
2585 label
= make_label(NULL
, 0.0, 0.5);
2586 data
->TX_topamount
= label
;
2587 gtk_box_pack_start (GTK_BOX (hbox
), label
, TRUE
, TRUE
, 0);
2589 data
->CY_range
= make_daterange(label
, FALSE
);
2590 gtk_box_pack_end (GTK_BOX (hbox
), data
->CY_range
, FALSE
, FALSE
, 0);
2592 /* pie + listview */
2593 hbox
= gtk_hbox_new (FALSE
, 0);
2594 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, TRUE
, TRUE
, 0);
2596 widget
= gtk_chart_new(CHART_TYPE_PIE
);
2597 data
->RE_pie
= widget
;
2598 gtk_chart_set_minor_prefs(GTK_CHART(widget
), PREFS
->euro_value
, PREFS
->minor_cur
.symbol
);
2599 gtk_box_pack_start (GTK_BOX (hbox
), widget
, TRUE
, TRUE
, 0);
2602 sw = gtk_scrolled_window_new (NULL, NULL);
2603 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
2604 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2605 gtk_box_pack_start (GTK_BOX (hbox), sw, FALSE, FALSE, 0);
2608 widget
= (GtkWidget
*)create_list_topspending();
2609 data
->LV_top
= widget
;
2611 gtk_chart_show_legend(GTK_CHART(data
->RE_pie
), TRUE
, TRUE
);
2613 // gtk_container_add (GTK_CONTAINER (sw), widget);
2619 static GtkWidget
*ui_mainwindow_scheduled_create(struct hbfile_data
*data
)
2621 GtkWidget
*mainvbox
, *hbox
, *vbox
, *sw
, *tbar
;
2622 GtkWidget
*label
, *image
, *align
, *widget
;
2623 GtkToolItem
*toolitem
;
2625 mainvbox
= gtk_vbox_new (FALSE
, 0);
2626 data
->GR_upc
= mainvbox
;
2628 hbox
= gtk_hbox_new (FALSE
, HB_BOX_SPACING
);
2629 gtk_box_pack_start (GTK_BOX (mainvbox
), hbox
, FALSE
, FALSE
, 0);
2631 label
= make_label(_("Scheduled transactions"), 0.0, 0.5);
2632 //gtk_label_set_angle(GTK_LABEL(label), 90.0);
2633 gimp_label_set_attributes(GTK_LABEL(label
), PANGO_ATTR_WEIGHT
, PANGO_WEIGHT_BOLD
, -1);
2634 gtk_misc_set_padding (GTK_MISC(label
), HB_BOX_SPACING
, HB_BOX_SPACING
/2);
2635 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
2637 label
= make_label(_("maximum post date"), 0.0, 0.7);
2638 gimp_label_set_attributes (GTK_LABEL (label
), PANGO_ATTR_SCALE
, PANGO_SCALE_SMALL
, -1);
2639 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
2641 label
= make_label(NULL
, 0.0, 0.7);
2642 data
->LB_maxpostdate
= label
;
2643 gimp_label_set_attributes (GTK_LABEL (label
), PANGO_ATTR_SCALE
, PANGO_SCALE_SMALL
, -1);
2644 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
2646 align
= gtk_alignment_new(0, 0, 1.0, 1.0);
2647 // top, bottom, left, right
2648 gtk_alignment_set_padding (GTK_ALIGNMENT(align
), 0, HB_BOX_SPACING
, 2*HB_BOX_SPACING
, HB_BOX_SPACING
);
2649 gtk_box_pack_start (GTK_BOX (mainvbox
), align
, TRUE
, TRUE
, 0);
2651 vbox
= gtk_vbox_new (FALSE
, 0);
2652 gtk_container_add (GTK_CONTAINER (align
), vbox
);
2654 sw
= gtk_scrolled_window_new (NULL
, NULL
);
2655 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw
), GTK_SHADOW_ETCHED_IN
);
2656 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw
), GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2657 gtk_box_pack_start (GTK_BOX (vbox
), sw
, TRUE
, TRUE
, 0);
2659 widget
= (GtkWidget
*)create_list_upcoming();
2660 data
->LV_upc
= widget
;
2661 gtk_container_add (GTK_CONTAINER (sw
), widget
);
2663 tbar
= gtk_toolbar_new();
2664 gtk_toolbar_set_icon_size (GTK_TOOLBAR(tbar
), GTK_ICON_SIZE_MENU
);
2665 gtk_toolbar_set_style(GTK_TOOLBAR(tbar
), GTK_TOOLBAR_ICONS
);
2666 gtk_box_pack_start (GTK_BOX (vbox
), tbar
, FALSE
, FALSE
, 0);
2668 /*widget = gtk_tool_item_new ();
2669 label = gtk_label_new("test");
2670 gtk_container_add(GTK_CONTAINER(widget), label);
2671 gtk_toolbar_insert(GTK_TOOLBAR(tbar), GTK_TOOL_ITEM(widget), -1);*/
2673 image
= gtk_image_new_from_icon_name ("media-skip-forward", GTK_ICON_SIZE_MENU
);
2674 toolitem
= gtk_tool_button_new(image
, NULL
);
2675 data
->BT_sched_skip
= toolitem
;
2676 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2677 gtk_widget_set_tooltip_text(GTK_WIDGET(toolitem
), _("Skip"));
2679 image
= gtk_image_new_from_icon_name ("media-playback-start", GTK_ICON_SIZE_MENU
);
2680 toolitem
= gtk_tool_button_new(image
, NULL
);
2681 data
->BT_sched_post
= toolitem
;
2682 gtk_toolbar_insert(GTK_TOOLBAR(tbar
), GTK_TOOL_ITEM(toolitem
), -1);
2683 gtk_widget_set_tooltip_text(GTK_WIDGET(toolitem
), _("Post"));
2691 ** the window creation
2693 GtkWidget
*create_hbfile_window(GtkWidget
*do_widget
)
2695 struct hbfile_data
*data
;
2696 struct WinGeometry
*wg
;
2697 GtkWidget
*mainvbox
, *vbox
, *vpaned
, *hpaned
;
2702 DB( g_print("\n[ui-mainwindow] create main window\n") );
2704 data
= g_malloc0(sizeof(struct hbfile_data
));
2705 if(!data
) return NULL
;
2707 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
2709 //store our window private data
2710 g_object_set_data(G_OBJECT(window
), "inst_data", (gpointer
)data
);
2711 DB( g_print(" - new window=%x, inst_data=%0x\n", (gint
)window
, (gint
)data
) );
2713 // this is our mainwindow, so store it to GLOBALS data
2714 data
->window
= window
;
2715 GLOBALS
->mainwindow
= window
;
2717 //setup, init and show window
2718 wg
= &PREFS
->wal_wg
;
2721 gtk_window_move(GTK_WINDOW(window
), wg
->l
, wg
->t
);
2722 gtk_window_resize(GTK_WINDOW(window
), wg
->w
, wg
->h
);
2725 gtk_window_maximize(GTK_WINDOW(window
));
2727 gtk_widget_show (window
);
2729 mainvbox
= gtk_vbox_new (FALSE
, 0);
2730 gtk_container_add (GTK_CONTAINER (window
), mainvbox
);
2732 ui_mainwindow_create_menu_bar_and_toolbar (data
, mainvbox
);
2734 #if HB_UNSTABLE == TRUE
2735 GtkWidget
*bar
, *label
;
2737 bar
= gtk_info_bar_new ();
2738 gtk_box_pack_start (GTK_BOX (mainvbox
), bar
, FALSE
, FALSE
, 0);
2739 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar
), GTK_MESSAGE_WARNING
);
2740 label
= make_label(NULL
, 0.5, 0.5);
2741 gtk_label_set_markup (GTK_LABEL(label
), "Unstable Development Version");
2742 gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar
))), label
, FALSE
, FALSE
, 0);
2745 /* Add the main area */
2746 vbox
= gtk_vbox_new (FALSE
, 0);
2747 //gtk_container_set_border_width (GTK_CONTAINER(vbox), HB_MAINBOX_SPACING);
2748 gtk_box_pack_start (GTK_BOX (mainvbox
), vbox
, TRUE
, TRUE
, 0);
2750 vpaned
= gtk_vpaned_new();
2751 data
->vpaned
= vpaned
;
2752 gtk_box_pack_start (GTK_BOX (vbox
), vpaned
, TRUE
, TRUE
, 0);
2754 hpaned
= gtk_hpaned_new();
2755 data
->hpaned
= hpaned
;
2756 gtk_paned_pack1 (GTK_PANED(vpaned
), hpaned
, FALSE
, FALSE
);
2758 widget
= ui_mainwindow_scheduled_create(data
);
2759 gtk_paned_pack2 (GTK_PANED(vpaned
), widget
, FALSE
, FALSE
);
2761 widget
= ui_mainwindow_create_youraccounts(data
);
2762 gtk_paned_pack1 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
2764 widget
= ui_mainwindow_create_topspending(data
);
2765 gtk_paned_pack2 (GTK_PANED(hpaned
), widget
, FALSE
, FALSE
);
2768 DB( g_print(" - vpaned=%d hpaned=%d\n", PREFS
->wal_vpaned
, PREFS
->wal_hpaned
) );
2770 if(PREFS
->wal_hpaned
> 0)
2771 gtk_paned_set_position(GTK_PANED(data
->hpaned
), PREFS
->wal_hpaned
);
2772 if(PREFS
->wal_vpaned
> 0)
2773 gtk_paned_set_position(GTK_PANED(data
->vpaned
), PREFS
->wal_vpaned
);
2775 gtk_widget_show_all (window
);
2777 //todo: move this elsewhere
2778 DB( g_print(" - setup stuff\n") );
2780 data
->filter
= da_filter_malloc();
2781 filter_default_all_set(data
->filter
);
2782 gtk_combo_box_set_active(GTK_COMBO_BOX(data
->CY_range
), PREFS
->date_range_wal
);
2786 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Toolbar");
2787 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_toolbar
);
2788 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Spending");
2789 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_spending
);
2790 action
= gtk_ui_manager_get_action(data
->manager
, "/MenuBar/ViewMenu/Upcoming");
2791 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action
), PREFS
->wal_upcoming
);
2793 /* Drag and drop support, set targets to NULL because we add the
2794 default uri_targets below */
2796 /* support for opening a file by dragging onto the project window */
2797 gtk_drag_dest_set (GTK_WIDGET (window
),
2798 GTK_DEST_DEFAULT_ALL
,
2800 G_N_ELEMENTS (drop_types
),
2803 g_signal_connect (G_OBJECT (window
), "drag-data-received",
2804 G_CALLBACK (ui_mainwindow_drag_data_received
), window
);
2808 //connect all our signals
2809 DB( g_print(" - connect signals\n") );
2812 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_acc
)), "changed", G_CALLBACK (ui_mainwindow_selection
), NULL
);
2813 g_signal_connect (GTK_TREE_VIEW(data
->LV_acc
), "row-activated", G_CALLBACK (ui_mainwindow_onRowActivated
), GINT_TO_POINTER(2));
2815 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data
->LV_upc
)), "changed", G_CALLBACK (ui_mainwindow_scheduled_selection_cb
), NULL
);
2816 g_signal_connect (G_OBJECT (data
->BT_sched_post
), "clicked", G_CALLBACK (ui_mainwindow_scheduled_post_cb
), data
);
2817 g_signal_connect (G_OBJECT (data
->BT_sched_skip
), "clicked", G_CALLBACK (ui_mainwindow_scheduled_skip_cb
), data
);
2819 g_signal_connect (data
->CY_range
, "changed", G_CALLBACK (ui_mainwindow_populate_topspending
), NULL
);
2822 /* GtkWindow events */
2823 g_signal_connect (window
, "delete-event", G_CALLBACK (ui_mainwindow_dispose
), (gpointer
)data
);
2826 g_signal_connect (window
, "screen-changed",
2827 G_CALLBACK (ui_mainwindow_window_screen_changed_cb
),
2831 //gtk_action_group_set_sensitive(data->actions, FALSE);