/
gnc-plugin-page-account-tree.c
2008 lines (1707 loc) · 71.6 KB
/
gnc-plugin-page-account-tree.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
/*
* gnc-plugin-page-account-tree.c --
*
* Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2003,2005,2006 David Hampton <hampton@employees.org>
*
* 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
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
* Boston, MA 02110-1301, USA gnu@gnu.org
*/
/** @addtogroup ContentPlugins
@{ */
/** @addtogroup GncPluginPageAccountTree An Account Tree Plugin
@{ */
/** @file gnc-plugin-page-account-tree.c
@brief Functions providing a chart of account page.
@author Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
@author Copyright (C) 2003,2005,2006 David Hampton <hampton@employees.org>
*/
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "gnc-plugin-page-account-tree.h"
#include "gnc-plugin-page-register.h"
#include "gnc-plugin-page-register2.h"
#include "Scrub.h"
#include "Scrub3.h"
#include "ScrubBusiness.h"
#include "Transaction.h"
#include "dialog-account.h"
#include "dialog-transfer.h"
#include "dialog-utils.h"
#include "assistant-hierarchy.h"
#include "gnc-account-sel.h"
#include "gnc-component-manager.h"
#include "gnc-engine.h"
#include "gnc-gnome-utils.h"
#include "gnc-gobject-utils.h"
#include "gnc-icons.h"
#include "gnc-plugin-account-tree.h"
#include "gnc-prefs.h"
#include "gnc-session.h"
#include "gnc-split-reg.h"
#include "gnc-state.h"
#include "gnc-tree-view-account.h"
#include "gnc-tree-model-account-types.h"
#include "gnc-ui.h"
#include "gnc-ui-util.h"
#include "gnc-window.h"
#include "dialog-lot-viewer.h"
#include "window-reconcile.h"
#include "window-autoclear.h"
#include "window-main-summarybar.h"
#include "dialog-object-references.h"
#include "dialog-find-account.h"
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_GUI;
/********************************************************************
* delete_account_helper
* See if this account has any splits present. Set the user data
* and return the same value to stop walking the account tree if
* appropriate.
********************************************************************/
typedef struct _delete_helper
{
gboolean has_splits;
gboolean has_ro_splits;
} delete_helper_t;
#define PLUGIN_PAGE_ACCT_TREE_CM_CLASS "plugin-page-acct-tree"
#define STATE_SECTION "Account Hierarchy"
#define DELETE_DIALOG_FILTER "filter"
#define DELETE_DIALOG_ACCOUNT "account"
#define DELETE_DIALOG_TRANS_MAS "trans_mas"
#define DELETE_DIALOG_SA_MAS "sa_mas"
#define DELETE_DIALOG_SA_TRANS_MAS "sa_trans_mas"
#define DELETE_DIALOG_SA_TRANS "sa_trans"
#define DELETE_DIALOG_SA_SPLITS "sa_has_split"
#define DELETE_DIALOG_OK_BUTTON "deletebutton"
enum
{
ACCOUNT_SELECTED,
LAST_SIGNAL
};
typedef struct GncPluginPageAccountTreePrivate
{
GtkWidget *widget;
GtkTreeView *tree_view;
gint component_id;
AccountFilterDialog fd;
} GncPluginPageAccountTreePrivate;
#define GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(o) \
((GncPluginPageAccountTreePrivate*)g_type_instance_get_private((GTypeInstance*)o, GNC_TYPE_PLUGIN_PAGE_ACCOUNT_TREE))
static GObjectClass *parent_class = NULL;
/************************************************************
* Prototypes *
************************************************************/
/* Plugin Actions */
static void gnc_plugin_page_account_tree_class_init (GncPluginPageAccountTreeClass *klass);
static void gnc_plugin_page_account_tree_init (GncPluginPageAccountTree *plugin_page);
static void gnc_plugin_page_account_tree_finalize (GObject *object);
static void gnc_plugin_page_account_tree_selected (GObject *object, gpointer user_data);
static gboolean gnc_plugin_page_account_tree_focus_widget (GncPluginPage *plugin_page);
static GtkWidget *gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page);
static void gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page);
static void gnc_plugin_page_account_tree_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
static GncPluginPage *gnc_plugin_page_account_tree_recreate_page (GtkWidget *window, GKeyFile *file, const gchar *group);
/* Callbacks */
static void gnc_plugin_page_account_tree_summarybar_position_changed(gpointer prefs, gchar* pref, gpointer user_data);
static gboolean gnc_plugin_page_account_tree_button_press_cb (GtkWidget *widget,
GdkEventButton *event,
GncPluginPage *page);
static void gnc_plugin_page_account_tree_double_click_cb (GtkTreeView *treeview,
GtkTreePath *path,
GtkTreeViewColumn *col,
GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_selection_changed_cb (GtkTreeSelection *selection,
GncPluginPageAccountTree *page);
void gppat_populate_trans_mas_list(GtkToggleButton *sa_mrb, GtkWidget *dialog);
void gppat_set_insensitive_iff_rb_active(GtkWidget *widget, GtkToggleButton *b);
/* Command callbacks */
static void gnc_plugin_page_account_tree_cmd_new_account (GtkAction *action, GncPluginPageAccountTree *plugin_page);
static void gnc_plugin_page_account_tree_cmd_file_new_hierarchy (GtkAction *action, GncPluginPageAccountTree *plugin_page);
static void gnc_plugin_page_account_tree_cmd_open_account (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_open_subaccounts (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_edit_account (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_find_account (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_find_account_popup (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_renumber_accounts (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_view_filter_by (GtkAction *action, GncPluginPageAccountTree *plugin_page);
static void gnc_plugin_page_account_tree_cmd_reconcile (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_refresh (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_autoclear (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_transfer (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_stock_split (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_lots (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_scrub (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_scrub_sub (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_scrub_all (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_cascade_account_properties (GtkAction *action, GncPluginPageAccountTree *page);
/* Command callback for new Register Test */
static void gnc_plugin_page_account_tree_cmd_open2_account (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_open2_subaccounts (GtkAction *action, GncPluginPageAccountTree *page);
/* Account Deletion Actions. */
static int confirm_delete_account (GtkAction *action,
GncPluginPageAccountTree *page, Account* ta,
Account* sta, Account* saa,
delete_helper_t delete_res);
static void do_delete_account (Account* account, Account* saa, Account* sta,
Account* ta);
static guint plugin_page_signals[LAST_SIGNAL] = { 0 };
static GtkActionEntry gnc_plugin_page_account_tree_actions [] =
{
/* Toplevel */
{ "FakeToplevel", NULL, "", NULL, NULL, NULL },
/* File menu */
{
"FileNewAccountAction", GNC_ICON_NEW_ACCOUNT, N_("New _Account..."), NULL,
N_("Create a new Account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_new_account)
},
{
"FileAddAccountHierarchyAssistantAction", GNC_ICON_NEW_ACCOUNT, N_("New Account _Hierarchy..."), NULL,
N_("Extend the current book by merging with new account type categories"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_file_new_hierarchy)
},
#ifdef REGISTER2_ENABLED
{
"FileOpenAccount2Action", GNC_ICON_OPEN_ACCOUNT, N_("Open _Account"), NULL,
N_("Open the selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_open2_account)
},
{
"FileOpenAccountAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _Old Style Register Account"), NULL,
N_("Open the old style register selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_open_account)
},
#else
{
"FileOpenAccountAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _Account"), NULL,
N_("Open the selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_open_account)
},
#endif
#ifdef REGISTER2_ENABLED
{
"FileOpenSubaccounts2Action", GNC_ICON_OPEN_ACCOUNT, N_("Open _SubAccounts"), NULL,
N_("Open the selected account and all its subaccounts"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_open2_subaccounts)
},
{
"FileOpenSubaccountsAction", GNC_ICON_OPEN_ACCOUNT, N_("Open Old St_yle Subaccounts"), NULL,
N_("Open the old style register selected account and all its subaccounts"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_open_subaccounts)
},
#else
{
"FileOpenSubaccountsAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _SubAccounts"), NULL,
N_("Open the selected account and all its subaccounts"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_open_subaccounts)
},
#endif
/* Edit menu */
{
"EditEditAccountAction", GNC_ICON_EDIT_ACCOUNT, N_("Edit _Account"), "<primary>e",
N_("Edit the selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_edit_account)
},
{
"EditDeleteAccountAction", GNC_ICON_DELETE_ACCOUNT, N_("_Delete Account..."), "Delete",
N_("Delete selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_delete_account)
},
{
"EditCascadeAccountAction", NULL, N_("_Cascade Account Properties..."), NULL,
N_("Cascade selected properties for account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_cascade_account_properties)
},
{
"EditFindAccountAction", "edit-find", N_("F_ind Account"), "<primary>i",
N_("Find an account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_find_account)
},
{
"EditFindAccountPopupAction", "edit-find", N_("F_ind Account"), "<primary>i",
N_("Find an account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_find_account_popup)
},
{
"EditRenumberSubaccountsAction", NULL, N_("_Renumber Subaccounts..."), NULL,
N_("Renumber the children of the selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_renumber_accounts)
},
/* View menu */
{
"ViewFilterByAction", NULL, N_("_Filter By..."), NULL, NULL,
G_CALLBACK (gnc_plugin_page_account_tree_cmd_view_filter_by)
},
{
"ViewRefreshAction", "view-refresh", N_("_Refresh"), "<primary>r",
N_("Refresh this window"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_refresh)
},
/* Actions menu */
{
"ActionsReconcileAction", NULL, N_("_Reconcile..."), NULL,
N_("Reconcile the selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_reconcile)
},
{
"ActionsAutoClearAction", NULL, N_("_Auto-clear..."), NULL,
N_("Automatically clear individual transactions, given a cleared amount"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_autoclear)
},
{
"ActionsTransferAction", NULL, N_("_Transfer..."), "<primary>t",
N_("Transfer funds from one account to another"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_transfer)
},
{
"ActionsStockSplitAction", NULL, N_("Stoc_k Split..."), NULL,
N_("Record a stock split or a stock merger"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_stock_split)
},
{
"ActionsLotsAction", NULL, N_("View _Lots..."), NULL,
N_("Bring up the lot viewer/editor window"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_lots)
},
{
"ScrubAction", NULL, N_("Check & Repair A_ccount"), NULL,
N_("Check for and repair unbalanced transactions and orphan splits " "in this account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_scrub)
},
{
"ScrubSubAction", NULL, N_("Check & Repair Su_baccounts"), NULL,
N_("Check for and repair unbalanced transactions and orphan splits "
"in this account and its subaccounts"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_scrub_sub)
},
{
"ScrubAllAction", NULL, N_("Check & Repair A_ll"), NULL,
N_("Check for and repair unbalanced transactions and orphan splits " "in all accounts"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_scrub_all)
},
/* Extensions Menu */
{ "Register2TestAction", NULL, N_("_Register2"), NULL, NULL, NULL },
{
"Register2TestAccountAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _Account"), NULL,
N_("Open the selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_open2_account)
},
{
"Register2TestSubAccountAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _SubAccounts"), NULL,
N_("Open the selected account and all its subaccounts"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_open2_subaccounts)
},
};
/** The number of actions provided by this plugin. */
static guint gnc_plugin_page_account_tree_n_actions = G_N_ELEMENTS (gnc_plugin_page_account_tree_actions);
/** Actions that require an account to be selected before they are
* enabled, and the book is in read-write mode. */
static const gchar *actions_requiring_account_rw[] =
{
"EditEditAccountAction",
"EditDeleteAccountAction",
"ActionsReconcileAction",
"ActionsAutoClearAction",
NULL
};
/** Actions that require an account to be selected before they are
* enabled. Those actions can be selected even if the book is in readonly mode. */
static const gchar *actions_requiring_account_always[] =
{
"FileOpenAccountAction",
#ifdef REGISTER2_ENABLED
"FileOpenAccount2Action",
#endif
"FileOpenSubaccountsAction",
"ActionsLotsAction",
NULL
};
/* This is the list of actions which are switched inactive in a read-only book. */
static const gchar* readonly_inactive_actions[] =
{
"FileNewAccountAction",
"FileAddAccountHierarchyAssistantAction",
"EditEditAccountAction",
"EditDeleteAccountAction",
"EditRenumberSubaccountsAction",
"ActionsTransferAction",
"ActionsReconcileAction",
"ActionsAutoClearAction",
"ActionsStockSplitAction",
"ScrubAction",
"ScrubSubAction",
"ScrubAllAction",
NULL
};
/** Short labels for use on the toolbar buttons. */
static action_toolbar_labels toolbar_labels[] =
{
{ "FileOpenAccountAction", N_("Open") },
#ifdef REGISTER2_ENABLED
{ "FileOpenAccount2Action", N_("Open2") },
#endif
{ "EditEditAccountAction", N_("Edit") },
{ "FileNewAccountAction", N_("New") },
{ "EditDeleteAccountAction", N_("Delete") },
{ NULL, NULL },
};
GncPluginPage *
gnc_plugin_page_account_tree_new (void)
{
GncPluginPageAccountTree *plugin_page;
ENTER(" ");
plugin_page = g_object_new (GNC_TYPE_PLUGIN_PAGE_ACCOUNT_TREE,
NULL);
LEAVE("new account tree page %p", plugin_page);
return GNC_PLUGIN_PAGE (plugin_page);
}
G_DEFINE_TYPE_WITH_PRIVATE(GncPluginPageAccountTree, gnc_plugin_page_account_tree, GNC_TYPE_PLUGIN_PAGE)
static void
prepare_scrubbing ()
{
gnc_suspend_gui_refresh ();
gnc_set_abort_scrub (FALSE);
}
static gboolean
finish (GncPluginPage* page)
{
if (gnc_get_ongoing_scrub ())
{
gboolean ret = gnc_verify_dialog (GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (page))), FALSE, _("A scrubbing operation is currently pending, do you want to abort it?"));
if (ret)
{
gnc_set_abort_scrub (TRUE);
gnc_resume_gui_refresh (); // This is so quit does not complain about an ongoing operation.
return TRUE;
}
return FALSE;
}
return TRUE;
}
static void
gnc_plugin_page_account_tree_class_init (GncPluginPageAccountTreeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginPageClass *gnc_plugin_class = GNC_PLUGIN_PAGE_CLASS(klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gnc_plugin_page_account_tree_finalize;
gnc_plugin_class->tab_icon = GNC_ICON_ACCOUNT;
gnc_plugin_class->plugin_name = GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME;
gnc_plugin_class->create_widget = gnc_plugin_page_account_tree_create_widget;
gnc_plugin_class->destroy_widget = gnc_plugin_page_account_tree_destroy_widget;
gnc_plugin_class->save_page = gnc_plugin_page_account_tree_save_page;
gnc_plugin_class->recreate_page = gnc_plugin_page_account_tree_recreate_page;
gnc_plugin_class->focus_page_function = gnc_plugin_page_account_tree_focus_widget;
gnc_plugin_class->finish_pending = finish;
plugin_page_signals[ACCOUNT_SELECTED] =
g_signal_new ("account_selected",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GncPluginPageAccountTreeClass, account_selected),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
}
static void
gnc_plugin_page_account_tree_init (GncPluginPageAccountTree *plugin_page)
{
GtkActionGroup *action_group;
GncPluginPageAccountTreePrivate *priv;
GncPluginPage *parent;
const GList *page_list;
ENTER("page %p", plugin_page);
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(plugin_page);
/* Init parent declared variables */
parent = GNC_PLUGIN_PAGE(plugin_page);
#ifdef REGISTER2_ENABLED
g_object_set(G_OBJECT(plugin_page),
"page-name", _("Accounts"),
"page-uri", "default:",
"ui-description", "gnc-plugin-page-account-tree2-ui.xml",
NULL);
#else
g_object_set(G_OBJECT(plugin_page),
"page-name", _("Accounts"),
"page-uri", "default:",
"ui-description", "gnc-plugin-page-account-tree-ui.xml",
NULL);
#endif
g_signal_connect (G_OBJECT (plugin_page), "selected",
G_CALLBACK (gnc_plugin_page_account_tree_selected), plugin_page);
/* change me when the system supports multiple books */
gnc_plugin_page_add_book(parent, gnc_get_current_book());
/* Is this the first accounts page? */
page_list =
gnc_gobject_tracking_get_list(GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME);
if (!page_list || plugin_page == page_list->data)
{
g_object_set_data(G_OBJECT(plugin_page), PLUGIN_PAGE_IMMUTABLE,
GINT_TO_POINTER(1));
}
/* Create menu and toolbar information */
action_group =
gnc_plugin_page_create_action_group(parent,
"GncPluginPageAccountTreeActions");
gtk_action_group_add_actions(action_group,
gnc_plugin_page_account_tree_actions,
gnc_plugin_page_account_tree_n_actions,
plugin_page);
gnc_plugin_init_short_names (action_group, toolbar_labels);
/* Visible types */
priv->fd.visible_types = -1; /* Start with all types */
priv->fd.show_hidden = FALSE;
priv->fd.show_unused = TRUE;
priv->fd.show_zero_total = TRUE;
priv->fd.filter_override = g_hash_table_new (g_direct_hash, g_direct_equal);
LEAVE("page %p, priv %p, action group %p",
plugin_page, priv, action_group);
}
static void
gnc_plugin_page_account_tree_finalize (GObject *object)
{
GncPluginPageAccountTree *page;
GncPluginPageAccountTreePrivate *priv;
ENTER("object %p", object);
page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (object);
g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE (page));
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
g_return_if_fail (priv != NULL);
G_OBJECT_CLASS (parent_class)->finalize (object);
LEAVE(" ");
}
void
gnc_plugin_page_account_tree_open (Account *account, GtkWindow *win)
{
GncPluginPageAccountTreePrivate *priv;
GncPluginPageAccountTree *page;
GncPluginPage *plugin_page = NULL;
const GList *page_list;
GtkWidget *window;
/* Find Accounts page */
page_list = gnc_gobject_tracking_get_list(GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME);
// If we have a window, look for account page in that window
if (g_list_length ((GList*)page_list) != 0)
{
if (win != NULL)
{
for ( ; page_list; page_list = g_list_next(page_list))
{
plugin_page = GNC_PLUGIN_PAGE(page_list->data);
if (GTK_WINDOW(plugin_page->window) == win)
break;
}
}
else // if no window, open first account page in list
plugin_page = GNC_PLUGIN_PAGE(page_list->data);
}
else // we have no account pages, create one
plugin_page = gnc_plugin_page_account_tree_new ();
g_return_if_fail(plugin_page);
window = plugin_page->window;
gnc_main_window_open_page (GNC_MAIN_WINDOW(window), plugin_page);
page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page);
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
if (account != NULL)
{
Account *root_account = gnc_get_current_root_account ();
Account *parent_account = NULL;
Account *temp_account = account;
g_hash_table_insert (priv->fd.filter_override, account, account);
// make sure we override all the parent accounts to root
while (parent_account != root_account)
{
parent_account = gnc_account_get_parent (temp_account);
g_hash_table_insert (priv->fd.filter_override, parent_account, parent_account);
temp_account = parent_account;
}
gnc_tree_view_account_refilter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
gnc_tree_view_account_set_selected_account (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), account);
}
}
Account *
gnc_plugin_page_account_tree_get_current_account (GncPluginPageAccountTree *page)
{
GncPluginPageAccountTreePrivate *priv;
Account *account;
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
ENTER("page %p (tree view %p)", page, priv->tree_view);
account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
if (account == NULL)
{
LEAVE("no account");
return NULL;
}
LEAVE("account %p", account);
return account;
}
/**
* Whenever the current page is changed, if an account page is
* the current page, set focus on the tree view.
*/
static gboolean
gnc_plugin_page_account_tree_focus_widget (GncPluginPage *account_plugin_page)
{
if (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(account_plugin_page))
{
GncPluginPageAccountTreePrivate *priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(account_plugin_page);
GtkTreeView *view = GTK_TREE_VIEW(priv->tree_view);
if (!gtk_widget_is_focus (GTK_WIDGET(view)))
gtk_widget_grab_focus (GTK_WIDGET(view));
}
return FALSE;
}
/* Virtual Functions */
static void
gnc_plugin_page_account_refresh_cb (GHashTable *changes, gpointer user_data)
{
GncPluginPageAccountTree *page = user_data;
GncPluginPageAccountTreePrivate *priv;
g_return_if_fail(GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page));
/* We're only looking for forced updates here. */
if (changes)
return;
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
gnc_tree_view_account_clear_model_cache (GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
gtk_widget_queue_draw(priv->widget);
}
static void
gnc_plugin_page_account_tree_close_cb (gpointer user_data)
{
GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(user_data);
gnc_main_window_close_page(plugin_page);
}
static void
gnc_plugin_page_account_editing_started_cd (gpointer various, GncPluginPageRegister *page)
{
GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(page);
GtkAction *action = gnc_main_window_find_action (GNC_MAIN_WINDOW(plugin_page->window),
"EditDeleteAccountAction");
if (action != NULL)
gtk_action_set_sensitive (action, FALSE);
}
static void
gnc_plugin_page_account_editing_finished_cb (gpointer various, GncPluginPageRegister *page)
{
GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(page);
GtkAction *action = gnc_main_window_find_action (GNC_MAIN_WINDOW(plugin_page->window),
"EditDeleteAccountAction");
if (action != NULL)
gtk_action_set_sensitive (action, TRUE);
}
static GtkWidget *
gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page)
{
GncPluginPageAccountTree *page;
GncPluginPageAccountTreePrivate *priv;
GtkTreeSelection *selection;
GtkTreeView *tree_view;
GtkWidget *scrolled_window;
GtkTreeViewColumn *col;
ENTER("page %p", plugin_page);
page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page);
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
if (priv->widget != NULL)
{
LEAVE("widget = %p", priv->widget);
return priv->widget;
}
priv->widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_box_set_homogeneous (GTK_BOX (priv->widget), FALSE);
gtk_widget_show (priv->widget);
// Set the name for this widget so it can be easily manipulated with css
gtk_widget_set_name (GTK_WIDGET(priv->widget), "gnc-id-account-page");
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_widget_show (scrolled_window);
gtk_box_pack_start (GTK_BOX (priv->widget), scrolled_window,
TRUE, TRUE, 0);
tree_view = gnc_tree_view_account_new(FALSE);
col = gnc_tree_view_find_column_by_name(
GNC_TREE_VIEW(tree_view), "description");
g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
col = gnc_tree_view_find_column_by_name(
GNC_TREE_VIEW(tree_view), "total");
g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
gnc_tree_view_configure_columns(GNC_TREE_VIEW(tree_view));
g_object_set(G_OBJECT(tree_view),
"state-section", STATE_SECTION,
"show-column-menu", TRUE,
NULL);
/* No name handler; then the user can't click on the name of the
account to open its register. */
gnc_tree_view_account_set_code_edited(GNC_TREE_VIEW_ACCOUNT(tree_view),
gnc_tree_view_account_code_edited_cb);
gnc_tree_view_account_set_description_edited(GNC_TREE_VIEW_ACCOUNT(tree_view),
gnc_tree_view_account_description_edited_cb);
gnc_tree_view_account_set_notes_edited(GNC_TREE_VIEW_ACCOUNT(tree_view),
gnc_tree_view_account_notes_edited_cb);
// Setup some callbacks so menu actions can be disabled/enabled
gnc_tree_view_account_set_editing_started_cb(GNC_TREE_VIEW_ACCOUNT(tree_view),
(GFunc)gnc_plugin_page_account_editing_started_cd, page);
gnc_tree_view_account_set_editing_finished_cb(GNC_TREE_VIEW_ACCOUNT(tree_view),
(GFunc)gnc_plugin_page_account_editing_finished_cb, page);
priv->tree_view = tree_view;
selection = gtk_tree_view_get_selection(tree_view);
g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (gnc_plugin_page_account_tree_selection_changed_cb), page);
g_signal_connect (G_OBJECT (tree_view), "button-press-event",
G_CALLBACK (gnc_plugin_page_account_tree_button_press_cb), page);
g_signal_connect (G_OBJECT (tree_view), "row-activated",
G_CALLBACK (gnc_plugin_page_account_tree_double_click_cb), page);
gtk_tree_view_set_headers_visible(tree_view, TRUE);
gnc_plugin_page_account_tree_selection_changed_cb (NULL, page);
gtk_widget_show (GTK_WIDGET (tree_view));
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(tree_view));
priv->fd.tree_view = GNC_TREE_VIEW_ACCOUNT(priv->tree_view);
gnc_tree_view_account_set_filter (
GNC_TREE_VIEW_ACCOUNT(tree_view),
gnc_plugin_page_account_tree_filter_accounts, &priv->fd, NULL);
priv->component_id =
gnc_register_gui_component(PLUGIN_PAGE_ACCT_TREE_CM_CLASS,
gnc_plugin_page_account_refresh_cb,
gnc_plugin_page_account_tree_close_cb,
page);
gnc_gui_component_set_session (priv->component_id,
gnc_get_current_session());
plugin_page->summarybar = gnc_main_window_summary_new();
gtk_box_pack_start (GTK_BOX (priv->widget), plugin_page->summarybar,
FALSE, FALSE, 0);
gtk_widget_show(plugin_page->summarybar);
gnc_plugin_page_account_tree_summarybar_position_changed(NULL, NULL, page);
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
GNC_PREF_SUMMARYBAR_POSITION_TOP,
gnc_plugin_page_account_tree_summarybar_position_changed,
page);
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
GNC_PREF_SUMMARYBAR_POSITION_BOTTOM,
gnc_plugin_page_account_tree_summarybar_position_changed,
page);
g_signal_connect (G_OBJECT(plugin_page), "inserted",
G_CALLBACK(gnc_plugin_page_inserted_cb),
NULL);
// Read account filter state information from account section
gnc_tree_view_account_restore_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), &priv->fd,
gnc_state_get_current(), gnc_tree_view_get_state_section (GNC_TREE_VIEW(priv->tree_view)));
LEAVE("widget = %p", priv->widget);
return priv->widget;
}
static void
gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page)
{
GncPluginPageAccountTree *page;
GncPluginPageAccountTreePrivate *priv;
ENTER("page %p", plugin_page);
page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page);
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
GNC_PREF_SUMMARYBAR_POSITION_TOP,
gnc_plugin_page_account_tree_summarybar_position_changed,
page);
gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
GNC_PREF_SUMMARYBAR_POSITION_BOTTOM,
gnc_plugin_page_account_tree_summarybar_position_changed,
page);
// Save account filter state information to account section
gnc_tree_view_account_save_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), &priv->fd,
gnc_state_get_current(), gnc_tree_view_get_state_section (GNC_TREE_VIEW(priv->tree_view)));
// Destroy the filter override hash table
g_hash_table_destroy(priv->fd.filter_override);
// Remove the page_changed signal callback
gnc_plugin_page_disconnect_page_changed (GNC_PLUGIN_PAGE(plugin_page));
// Remove the page focus idle function if present
g_idle_remove_by_data (plugin_page);
if (priv->widget)
{
g_object_unref(G_OBJECT(priv->widget));
priv->widget = NULL;
}
if (priv->component_id)
{
gnc_unregister_gui_component(priv->component_id);
priv->component_id = 0;
}
LEAVE("widget destroyed");
}
static void update_inactive_actions(GncPluginPage *plugin_page)
{
GtkActionGroup *action_group;
gboolean is_sensitive = !qof_book_is_readonly(gnc_get_current_book());
// We are readonly - so we have to switch particular actions to inactive.
g_return_if_fail(plugin_page);
g_return_if_fail(GNC_IS_PLUGIN_PAGE(plugin_page));
/* Get the action group */
action_group = gnc_plugin_page_get_action_group(plugin_page);
g_return_if_fail(GTK_IS_ACTION_GROUP (action_group));
/* Set the action's sensitivity */
gnc_plugin_update_actions (action_group, readonly_inactive_actions,
"sensitive", is_sensitive);
}
/**
* Called when this page is selected.
*
* Update the toolbar button sensitivity. */
static void gnc_plugin_page_account_tree_selected (GObject *object, gpointer user_data)
{
GncPluginPage *plugin_page = GNC_PLUGIN_PAGE (object);
g_return_if_fail (GNC_IS_PLUGIN_PAGE (plugin_page));
update_inactive_actions(plugin_page);
}
/** Save enough information about this account tree page that it can
* be recreated next time the user starts gnucash.
*
* @param plugin_page The page to save.
*
* @param key_file A pointer to the GKeyFile data structure where the
* page information should be written.
*
* @param group_name The group name to use when saving data. */
static void
gnc_plugin_page_account_tree_save_page (GncPluginPage *plugin_page,
GKeyFile *key_file,
const gchar *group_name)
{
GncPluginPageAccountTree *account_page;
GncPluginPageAccountTreePrivate *priv;
g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(plugin_page));
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
ENTER("page %p, key_file %p, group_name %s", plugin_page, key_file,
group_name);
account_page = GNC_PLUGIN_PAGE_ACCOUNT_TREE(plugin_page);
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(account_page);
gnc_tree_view_account_save(GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
&priv->fd, key_file, group_name);
LEAVE(" ");
}
/** Create a new account tree page based on the information saved
* during a previous instantiation of gnucash.
*
* @param window The window where this page should be installed.
*
* @param key_file A pointer to the GKeyFile data structure where the
* page information should be read.
*
* @param group_name The group name to use when restoring data. */
static GncPluginPage *
gnc_plugin_page_account_tree_recreate_page (GtkWidget *window,
GKeyFile *key_file,
const gchar *group_name)
{
GncPluginPageAccountTree *account_page;
GncPluginPageAccountTreePrivate *priv;
GncPluginPage *page;
g_return_val_if_fail(key_file, NULL);
g_return_val_if_fail(group_name, NULL);
ENTER("key_file %p, group_name %s", key_file, group_name);
/* Create the new page. */
page = gnc_plugin_page_account_tree_new();
account_page = GNC_PLUGIN_PAGE_ACCOUNT_TREE(page);
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(account_page);
/* Install it now so we can then manipulate the created widget */
gnc_main_window_open_page(GNC_MAIN_WINDOW(window), page);
gnc_tree_view_account_restore(GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
&priv->fd, key_file, group_name);
LEAVE(" ");
return page;
}
/* Callbacks */
static void
gnc_plugin_page_account_tree_summarybar_position_changed(gpointer prefs, gchar* pref, gpointer user_data)
{
GncPluginPage *plugin_page;
GncPluginPageAccountTree *page;
GncPluginPageAccountTreePrivate *priv;
GtkPositionType position = GTK_POS_BOTTOM;
g_return_if_fail(user_data != NULL);
plugin_page = GNC_PLUGIN_PAGE(user_data);
page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (user_data);
priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_SUMMARYBAR_POSITION_TOP))
position = GTK_POS_TOP;
gtk_box_reorder_child(GTK_BOX(priv->widget),
plugin_page->summarybar,
(position == GTK_POS_TOP ? 0 : -1) );
}
/** This button press handler calls the common button press handler
* for all pages. The GtkTreeView eats all button presses and
* doesn't pass them up the widget tree, even when doesn't do
* anything with them. The only way to get access to the button
* presses in an account tree page is here on the tree view widget.
* Button presses on all other pages are caught by the signal
* registered in gnc-main-window.c. */
static gboolean
gnc_plugin_page_account_tree_button_press_cb (GtkWidget *widget,
GdkEventButton *event,
GncPluginPage *page)
{
g_return_val_if_fail(GNC_IS_PLUGIN_PAGE(page), FALSE);
ENTER("widget %p, event %p, page %p", widget, event, page);
gnc_main_window_button_press_cb(widget, event, page);
LEAVE(" ");
/* Always return FALSE. This will let the tree view callback run as
* well which will select the item under the cursor. By the time
* the user sees the menu both callbacks will have run and the menu