-
Notifications
You must be signed in to change notification settings - Fork 761
/
window-main.c
1482 lines (1240 loc) · 39.6 KB
/
window-main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************************\
* window-main.c -- the main window, and associated helper functions*
* and callback functions for GnuCash *
* Copyright (C) 1998,1999 Jeremy Collins *
* Copyright (C) 1998,1999,2000 Linas Vepstas *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
\********************************************************************/
#include "config.h"
#include <gnome.h>
#include <guile/gh.h>
#include <string.h>
#include "AccWindow.h"
#include "Destroy.h"
#include "EuroUtils.h"
#include "FileDialog.h"
#include "MainWindow.h"
#include "Refresh.h"
#include "RegWindow.h"
#include "Scrub.h"
#include "account-tree.h"
#include "dialog-account.h"
#include "dialog-fincalc.h"
#include "dialog-find-transactions.h"
#include "dialog-options.h"
#include "dialog-totd.h"
#include "dialog-transfer.h"
#include "dialog-utils.h"
#include "file-history.h"
#include "global-options.h"
#include "gnc-commodity.h"
#include "gnc-engine-util.h"
#include "gnc-engine.h"
#include "gnc-ui.h"
#include "gnucash.h"
#include "gtkselect.h"
#include "messages.h"
#include "mainwindow-account-tree.h"
#include "window-help.h"
#include "window-main.h"
#include "window-reconcile.h"
#include "window-register.h"
/* FIXME get rid of these */
#include <g-wrap.h>
#include "gnc.h"
/* Main Window information structure */
typedef struct _GNCMainInfo GNCMainInfo;
struct _GNCMainInfo
{
GtkWidget *account_tree;
GtkWidget *totals_combo;
GList *totals_list;
SCM main_window_change_callback_id;
SCM euro_change_callback_id;
SCM toolbar_change_callback_id;
GSList *account_sensitives;
};
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_GUI;
/* Codes for the file menu */
enum {
FMB_NEW,
FMB_OPEN,
FMB_IMPORT,
FMB_SAVE,
FMB_SAVEAS,
FMB_QUIT,
};
/** Static function declarations ***************************************/
static GNCMainInfo * gnc_get_main_info(void);
/* An accumulator for a given currency.
*
* This is used during the update to the status bar to contain the
* accumulation for a single currency. These are placed in a GList and
* kept around for the duration of the calculation. There may, in fact
* be better ways to do this, but none occurred. */
struct _GNCCurrencyAcc {
const gnc_commodity * currency;
gnc_numeric assets;
gnc_numeric profits;
};
typedef struct _GNCCurrencyAcc GNCCurrencyAcc;
/* An item to appear in the selector box in the status bar.
*
* This is maintained for the duration, where there is one per
* currency, plus (eventually) one for the default currency
* accumulation (like the EURO). */
struct _GNCCurrencyItem {
const gnc_commodity * currency;
GtkWidget *listitem;
GtkWidget *assets_label;
GtkWidget *profits_label;
gint touched : 1;
};
typedef struct _GNCCurrencyItem GNCCurrencyItem;
/* Build a single currency item.
*
* This function handles the building of a single currency item for the
* selector. It looks like the old code in the update function, but now
* only handles a single currency.
*/
static GNCCurrencyItem *
gnc_ui_build_currency_item(const gnc_commodity * currency)
{
GtkWidget *label;
GtkWidget *topbox;
GtkWidget *hbox;
GtkWidget *listitem;
GNCCurrencyItem *item = g_new0(GNCCurrencyItem, 1);
item->currency = currency;
listitem = gtk_list_item_new();
item->listitem = listitem;
topbox = gtk_hbox_new(FALSE, 2);
gtk_widget_show(topbox);
gtk_container_add(GTK_CONTAINER(listitem), topbox);
hbox = gtk_hbox_new(FALSE, 2);
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(topbox), hbox, FALSE, FALSE, 5);
label = gtk_label_new(gnc_commodity_get_mnemonic(currency));
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
hbox = gtk_hbox_new(FALSE, 2);
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(topbox), hbox, FALSE, FALSE, 5);
label = gtk_label_new(_("Net Assets:"));
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
label = gtk_label_new("");
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_show(label);
item->assets_label = label;
hbox = gtk_hbox_new(FALSE, 2);
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(topbox), hbox, FALSE, FALSE, 5);
label = gtk_label_new(_("Profits:"));
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
label = gtk_label_new("");
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
item->profits_label = label;
gtk_widget_show(item->listitem);
return item;
}
/* Get a currency accumulator.
*
* This will search the given list, and if no accumulator is found,
* will allocate a fresh one. */
static GNCCurrencyAcc *
gnc_ui_get_currency_accumulator(GList **list, const gnc_commodity * currency)
{
GList *current;
GNCCurrencyAcc *found;
for (current = g_list_first(*list); current;
current = g_list_next(current)) {
found = current->data;
if (gnc_commodity_equiv(currency, found->currency)) {
return found;
}
}
found = g_new0 (GNCCurrencyAcc, 1);
found->currency = currency;
found->assets = gnc_numeric_zero ();
found->profits = gnc_numeric_zero ();
*list = g_list_append (*list, found);
return found;
}
/* Get a currency item.
*
* This will search the given list, and if no accumulator is found, will
* create a fresh one.
*
* It looks just like the function above, with some extra stuff to get
* the item into the list. */
static GNCCurrencyItem *
gnc_ui_get_currency_item(GList **list, const gnc_commodity * currency,
GtkWidget *holder)
{
GList *current;
GNCCurrencyItem *found;
for (current = g_list_first(*list); current;
current = g_list_next(current)) {
found = current->data;
if (gnc_commodity_equiv(found->currency, currency)) {
return found;
}
}
found = gnc_ui_build_currency_item(currency);
*list = g_list_append(*list, found);
current = g_list_append(NULL, found->listitem);
gtk_select_append_items(GTK_SELECT(holder), current);
return found;
}
static void
gnc_ui_accounts_recurse (AccountGroup *group, GList **currency_list,
gboolean euro)
{
gnc_numeric amount;
AccountGroup *children;
Account *account;
int num_accounts;
GNCAccountType account_type;
const gnc_commodity * account_currency;
const gnc_commodity * default_currency;
const gnc_commodity * euro_commodity;
GNCCurrencyAcc *currency_accum;
GNCCurrencyAcc *euro_accum = NULL;
int i;
default_currency =
gnc_lookup_currency_option("International",
"Default Currency",
gnc_locale_default_currency ());
if (euro)
{
euro_commodity = gnc_get_euro ();
euro_accum = gnc_ui_get_currency_accumulator(currency_list,
euro_commodity);
}
else
euro_commodity = NULL;
num_accounts = xaccGroupGetNumAccounts(group);
for (i = 0; i < num_accounts; i++)
{
account = xaccGroupGetAccount(group, i);
account_type = xaccAccountGetType(account);
account_currency = xaccAccountGetCurrency(account);
children = xaccAccountGetChildren(account);
currency_accum = gnc_ui_get_currency_accumulator(currency_list,
account_currency);
switch (account_type)
{
case BANK:
case CASH:
case ASSET:
case STOCK:
case MUTUAL:
case CREDIT:
case LIABILITY:
amount = xaccAccountGetBalance(account);
currency_accum->assets =
gnc_numeric_add (currency_accum->assets, amount,
gnc_commodity_get_fraction (account_currency),
GNC_RND_ROUND);
if (euro)
euro_accum->assets =
gnc_numeric_add (euro_accum->assets,
gnc_convert_to_euro(account_currency, amount),
gnc_commodity_get_fraction (euro_commodity),
GNC_RND_ROUND);
if (children != NULL)
gnc_ui_accounts_recurse(children, currency_list, euro);
break;
case INCOME:
case EXPENSE:
amount = xaccAccountGetBalance(account);
currency_accum->profits =
gnc_numeric_sub (currency_accum->profits, amount,
gnc_commodity_get_fraction (account_currency),
GNC_RND_ROUND);
if (euro)
gnc_numeric_sub (euro_accum->profits,
gnc_convert_to_euro(account_currency, amount),
gnc_commodity_get_fraction (euro_commodity),
GNC_RND_ROUND);
if (children != NULL)
gnc_ui_accounts_recurse(children, currency_list, euro);
break;
case EQUITY:
/* no-op, see comments at top about summing assets */
break;
case CURRENCY:
default:
break;
}
}
}
/* The gnc_ui_refresh_statusbar() subroutine redraws
* the statusbar at the bottom of the main window. The statusbar
* includes two fields, titled 'profits' and 'assets'. The total
* assets equal the sum of all of the non-equity, non-income
* accounts. In theory, assets also equals the grand total
* value of the equity accounts, but that assumes that folks are
* using the equity account type correctly (which is not likely).
* Thus we show the sum of assets, rather than the sum of equities.
*
* The EURO gets special treatment. There can be one line with
* EUR amounts and a EUR (total) line which summs up all EURO
* member currencies.
*
* There should be a 'grand total', too, which sums up all accounts
* converted to one common currency.
*/
static void
gnc_ui_refresh_statusbar (void)
{
GNCMainInfo *main_info;
AccountGroup *group;
char asset_string[256];
char profit_string[256];
const gnc_commodity * default_currency;
GNCCurrencyAcc *currency_accum;
GNCCurrencyItem *currency_item;
GList *currency_list;
GList *current;
gboolean euro;
default_currency =
gnc_lookup_currency_option("International",
"Default Currency",
gnc_locale_default_currency ());
euro = gnc_lookup_boolean_option("International",
"Enable EURO support",
FALSE);
main_info = gnc_get_main_info();
if (main_info == NULL)
return;
currency_list = NULL;
/* Make sure there's at least one accumulator in the list. */
gnc_ui_get_currency_accumulator (¤cy_list, default_currency);
group = gncGetCurrentGroup ();
gnc_ui_accounts_recurse(group, ¤cy_list, euro);
for (current = g_list_first(main_info->totals_list); current;
current = g_list_next(current))
{
currency_item = current->data;
currency_item->touched = 0;
}
for (current = g_list_first(currency_list); current;
current = g_list_next(current))
{
currency_accum = current->data;
currency_item = gnc_ui_get_currency_item(&main_info->totals_list,
currency_accum->currency,
main_info->totals_combo);
currency_item->touched = 1;
xaccSPrintAmount(asset_string, currency_accum->assets,
gnc_commodity_print_info(currency_accum->currency, TRUE));
gtk_label_set_text(GTK_LABEL(currency_item->assets_label), asset_string);
gnc_set_label_color(currency_item->assets_label, currency_accum->assets);
xaccSPrintAmount(profit_string, currency_accum->profits,
gnc_commodity_print_info(currency_accum->currency, TRUE));
gtk_label_set_text(GTK_LABEL(currency_item->profits_label), profit_string);
gnc_set_label_color(currency_item->profits_label, currency_accum->profits);
g_free(currency_accum);
current->data = NULL;
}
g_list_free(currency_list);
currency_list = NULL;
current = g_list_first(main_info->totals_list);
while (current)
{
GList *next = current->next;
currency_item = current->data;
if (currency_item->touched == 0
&& !gnc_commodity_equiv(currency_item->currency,
default_currency)) {
currency_list = g_list_append(currency_list, currency_item->listitem);
main_info->totals_list = g_list_remove_link(main_info->totals_list,
current);
g_free(currency_item);
current->data = NULL;
g_list_free_1(current);
}
current = next;
}
if (currency_list)
{
gtk_select_remove_items(GTK_SELECT(main_info->totals_combo),
currency_list);
g_list_free(currency_list);
}
}
static void
gnc_refresh_main_window_title()
{
GtkWidget *main_window;
GNCBook *book;
const char *filename;
char *title;
main_window = gnc_get_ui_data();
if (main_window == NULL)
return;
book = gncGetCurrentBook ();
filename = gnc_book_get_file_path (book);
if ((filename == NULL) || (*filename == '\0'))
filename = _("Untitled");
title = g_strconcat("GnuCash - ", filename, NULL);
gtk_window_set_title(GTK_WINDOW(main_window), title);
g_free(title);
}
void
gnc_refresh_main_window()
{
xaccRecomputeGroupBalance(gncGetCurrentGroup());
gnc_ui_refresh_statusbar();
gnc_history_update_menu();
gnc_account_tree_refresh_all();
gnc_refresh_main_window_title();
}
static void
gnc_ui_find_transactions_cb (GtkWidget *widget, gpointer data)
{
gnc_ui_find_transactions_dialog_create(NULL);
}
static void
gnc_ui_exit_cb (GtkWidget *widget, gpointer data)
{
gnc_shutdown (0);
}
static void
gnc_ui_about_cb (GtkWidget *widget, gpointer data)
{
GtkWidget *about;
const gchar *message = _("The GnuCash personal finance manager.\n"
"The GNU way to manage your money!");
const gchar *copyright = "(C) 1998-2000 Linas Vepstas";
const gchar *authors[] = {
"Linas Vepstas <linas@linas.org>",
NULL
};
about = gnome_about_new("GnuCash", VERSION, copyright,
authors, message, NULL);
gnome_dialog_run_and_close(GNOME_DIALOG(about));
}
static void
gnc_ui_totd_cb (GtkWidget *widget, gpointer data)
{
gnc_ui_totd_dialog_create_and_run();
return;
}
static void
gnc_ui_help_cb (GtkWidget *widget, gpointer data)
{
helpWindow(NULL, NULL, HH_MAIN);
}
static void
gnc_ui_add_account (GtkWidget *widget, gpointer data)
{
gnc_ui_new_account_window (NULL);
}
static void
gnc_ui_delete_account (Account *account)
{
/* Step 1: Delete associated windows */
xaccAccountWindowDestroy(account);
/* Step 2: Remove the account from all trees */
gnc_account_tree_remove_account_all(account);
/* Step 3: Delete the actual account */
xaccRemoveAccount(account);
xaccFreeAccount(account);
/* Step 4: Refresh things */
gnc_refresh_main_window();
gnc_group_ui_refresh(gncGetCurrentGroup());
}
static void
gnc_ui_delete_account_cb (GtkWidget *widget, gpointer data)
{
Account *account = gnc_get_current_account();
if (account)
{
const char *format = _("Are you sure you want to delete the %s account?");
char *message;
char *name;
name = xaccAccountGetFullName(account, gnc_get_account_separator ());
message = g_strdup_printf(format, name);
if (gnc_verify_dialog(message, FALSE))
gnc_ui_delete_account(account);
g_free(name);
g_free(message);
}
else
{
const char *message = _("To delete an account, you must first\n"
"choose an account to delete.\n");
gnc_error_dialog(message);
}
}
static void
gnc_ui_mainWindow_toolbar_open (GtkWidget *widget, gpointer data)
{
RegWindow *regData;
Account *account = gnc_get_current_account();
if (account == NULL)
{
const char *message = _("To open an account, you must first\n"
"choose an account to open.");
gnc_error_dialog(message);
return;
}
PINFO ("calling regWindowSimple(%p)\n", account);
regData = regWindowSimple(account);
gnc_register_raise(regData);
}
static void
gnc_ui_mainWindow_toolbar_open_subs(GtkWidget *widget, gpointer data)
{
RegWindow *regData;
Account *account = gnc_get_current_account();
if (account == NULL)
{
const char *message = _("To open an account, you must first\n"
"choose an account to open.");
gnc_error_dialog(message);
return;
}
PINFO ("calling regWindowAccGroup(%p)\n", account);
regData = regWindowAccGroup(account);
gnc_register_raise(regData);
}
static void
gnc_ui_mainWindow_toolbar_edit (GtkWidget *widget, gpointer data)
{
Account *account = gnc_get_current_account();
AccountWindow *edit_window_data;
if (account != NULL)
{
edit_window_data = gnc_ui_edit_account_window(account);
gnc_ui_edit_account_window_raise(edit_window_data);
}
else
{
const char *message = _("To edit an account, you must first\n"
"choose an account to edit.\n");
gnc_error_dialog(message);
}
}
static void
gnc_ui_mainWindow_reconcile(GtkWidget *widget, gpointer data)
{
Account *account = gnc_get_current_account();
RecnWindow *recnData;
if (account != NULL)
{
recnData = recnWindow(gnc_get_ui_data(), account);
gnc_ui_reconcile_window_raise(recnData);
}
else
{
const char *message = _("To reconcile an account, you must first\n"
"choose an account to reconcile.");
gnc_error_dialog(message);
}
}
static void
gnc_ui_mainWindow_transfer(GtkWidget *widget, gpointer data)
{
gnc_xfer_dialog(gnc_get_ui_data(), gnc_get_current_account());
}
static void
gnc_ui_mainWindow_scrub(GtkWidget *widget, gpointer data)
{
Account *account = gnc_get_current_account();
if (account == NULL)
{
const char *message = _("You must select an account to scrub.");
gnc_error_dialog(message);
return;
}
xaccAccountScrubOrphans(account);
xaccAccountScrubImbalance(account);
gnc_account_ui_refresh(account);
gnc_refresh_main_window();
}
static void
gnc_ui_mainWindow_scrub_sub(GtkWidget *widget, gpointer data)
{
Account *account = gnc_get_current_account();
if (account == NULL)
{
const char *message = _("You must select an account to scrub.");
gnc_error_dialog(message);
return;
}
xaccAccountTreeScrubOrphans(account);
xaccAccountTreeScrubImbalance(account);
gnc_account_ui_refresh(account);
gnc_refresh_main_window();
}
static void
gnc_ui_mainWindow_scrub_all(GtkWidget *widget, gpointer data)
{
AccountGroup *group = gncGetCurrentGroup();
xaccGroupScrubOrphans(group);
xaccGroupScrubImbalance(group);
gnc_group_ui_refresh(group);
gnc_refresh_main_window();
}
static void
gnc_ui_options_cb(GtkWidget *widget, gpointer data)
{
gnc_show_options_dialog();
}
static void
gnc_ui_filemenu_cb(GtkWidget *widget, gpointer menuItem)
{
switch(GPOINTER_TO_INT(menuItem))
{
case FMB_NEW:
gncFileNew();
gnc_refresh_main_window();
break;
case FMB_OPEN:
gncFileOpen();
gnc_refresh_main_window();
break;
case FMB_SAVE:
gncFileSave();
break;
case FMB_SAVEAS:
gncFileSaveAs();
break;
case FMB_IMPORT:
gncFileQIFImport();
gnc_refresh_main_window();
break;
case FMB_QUIT:
gnc_shutdown(0);
break;
default:
break;
}
}
static void
gnc_ui_mainWindow_fincalc_cb(GtkWidget *widget, gpointer data)
{
gnc_ui_fincalc_dialog_create();
}
static gboolean
gnc_ui_mainWindow_delete_cb(GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
/* Don't allow deletes if we're in a modal dialog */
if (gtk_main_level() == 1)
gnc_shutdown(0);
/* Don't delete the window, we'll handle things ourselves. */
return TRUE;
}
static gboolean
gnc_ui_mainWindow_destroy_event_cb(GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
return FALSE;
}
void
gnc_ui_mainWindow_save_size(void)
{
GtkWidget *app;
int width = 0;
int height = 0;
app = gnc_get_ui_data();
gdk_window_get_geometry(GTK_WIDGET(app)->window, NULL, NULL,
&width, &height, NULL);
gnc_save_window_size("main_win", width, height);
}
static void
gnc_ui_mainWindow_destroy_cb(GtkObject *object, gpointer user_data)
{
GNCMainInfo *main_info = user_data;
gnc_unregister_option_change_callback_id
(main_info->main_window_change_callback_id);
gnc_unregister_option_change_callback_id
(main_info->euro_change_callback_id);
gnc_unregister_option_change_callback_id
(main_info->toolbar_change_callback_id);
g_slist_free(main_info->account_sensitives);
main_info->account_sensitives = NULL;
g_free(main_info);
}
GNCMainWinAccountTree *
gnc_get_current_account_tree(void)
{
GNCMainInfo *main_info;
main_info = gnc_get_main_info();
if (main_info == NULL)
return NULL;
return GNC_MAINWIN_ACCOUNT_TREE(main_info->account_tree);
}
Account *
gnc_get_current_account(void)
{
GNCMainWinAccountTree *list = gnc_get_current_account_tree();
return gnc_mainwin_account_tree_get_current_account(list);
}
GList *
gnc_get_current_accounts(void)
{
GNCMainWinAccountTree *tree = gnc_get_current_account_tree();
return gnc_mainwin_account_tree_get_current_accounts(tree);
}
static void
gnc_account_tree_activate_cb(GNCMainWinAccountTree *tree,
Account *account,
gpointer user_data)
{
RegWindow *regData;
gboolean expand;
expand = gnc_lookup_boolean_option("Main Window",
"Double click expands parent accounts",
FALSE);
if (expand)
{
AccountGroup *group;
group = xaccAccountGetChildren(account);
if (xaccGroupGetNumAccounts(group) > 0)
{
gnc_mainwin_account_tree_toggle_account_expansion(tree, account);
return;
}
}
regData = regWindowSimple(account);
gnc_register_raise(regData);
}
static void
gnc_configure_account_tree(void *data)
{
GNCMainInfo *info;
GNCMainWinAccountTree *tree;
AccountViewInfo new_avi;
GSList *list, *node;
memset(&new_avi, 0, sizeof(new_avi));
info = gnc_get_main_info();
tree = GNC_MAINWIN_ACCOUNT_TREE(info->account_tree);
list = gnc_lookup_list_option("Main Window",
"Account types to display",
NULL);
for (node = list; node != NULL; node = node->next)
{
if (safe_strcmp(node->data, "bank") == 0)
new_avi.include_type[BANK] = TRUE;
else if (safe_strcmp(node->data, "cash") == 0)
new_avi.include_type[CASH] = TRUE;
else if (safe_strcmp(node->data, "credit") == 0)
new_avi.include_type[CREDIT] = TRUE;
else if (safe_strcmp(node->data, "asset") == 0)
new_avi.include_type[ASSET] = TRUE;
else if (safe_strcmp(node->data, "liability") == 0)
new_avi.include_type[LIABILITY] = TRUE;
else if (safe_strcmp(node->data, "stock") == 0)
new_avi.include_type[STOCK] = TRUE;
else if (safe_strcmp(node->data, "mutual") == 0)
new_avi.include_type[MUTUAL] = TRUE;
else if (safe_strcmp(node->data, "currency") == 0)
new_avi.include_type[CURRENCY] = TRUE;
else if (safe_strcmp(node->data, "income") == 0)
new_avi.include_type[INCOME] = TRUE;
else if (safe_strcmp(node->data, "expense") == 0)
new_avi.include_type[EXPENSE] = TRUE;
else if (safe_strcmp(node->data, "equity") == 0)
new_avi.include_type[EQUITY] = TRUE;
}
gnc_free_list_option_value(list);
list = gnc_lookup_list_option("Main Window",
"Account fields to display",
NULL);
for (node = list; node != NULL; node = node->next)
{
if (safe_strcmp(node->data, "type") == 0)
new_avi.show_field[ACCOUNT_TYPE] = TRUE;
else if (safe_strcmp(node->data, "code") == 0)
new_avi.show_field[ACCOUNT_CODE] = TRUE;
else if (safe_strcmp(node->data, "description") == 0)
new_avi.show_field[ACCOUNT_DESCRIPTION] = TRUE;
else if (safe_strcmp(node->data, "notes") == 0)
new_avi.show_field[ACCOUNT_NOTES] = TRUE;
else if (safe_strcmp(node->data, "currency") == 0)
new_avi.show_field[ACCOUNT_CURRENCY] = TRUE;
else if (safe_strcmp(node->data, "security") == 0)
new_avi.show_field[ACCOUNT_SECURITY] = TRUE;
else if (safe_strcmp(node->data, "balance") == 0)
{
new_avi.show_field[ACCOUNT_BALANCE] = TRUE;
if(gnc_lookup_boolean_option("International",
"Enable EURO support", FALSE))
new_avi.show_field[ACCOUNT_BALANCE_EURO] = TRUE;
}
else if (safe_strcmp(node->data, "total") == 0)
{
new_avi.show_field[ACCOUNT_TOTAL] = TRUE;
if(gnc_lookup_boolean_option("International",
"Enable EURO support", FALSE))
new_avi.show_field[ACCOUNT_TOTAL_EURO] = TRUE;
}
}
gnc_free_list_option_value(list);
new_avi.show_field[ACCOUNT_NAME] = TRUE;
gnc_mainwin_account_tree_set_view_info(tree, new_avi);
return;
}
static void
gnc_euro_change(void *data)
{
gnc_ui_refresh_statusbar();
gnc_configure_account_tree(data);
gnc_group_ui_refresh(gncGetCurrentGroup());
}
static void
gnc_main_create_toolbar(GnomeApp *app, GNCMainInfo *main_info)
{
GSList *list;
static GnomeUIInfo toolbar[] =
{
{ GNOME_APP_UI_ITEM,
N_("Save"),