/
gnc-plugin-page-register.c
5216 lines (4452 loc) · 180 KB
/
gnc-plugin-page-register.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-register.c -- register page functions *
* *
* Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de> *
* Copyright (C) 2003,2005,2006 David Hampton <hampton@employees.org> *
* Copyright (C) 2011, Robert Fewell *
* *
* 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 RegisterPlugin Register Page
@{ */
/** @file gnc-plugin-page-register.c
@brief Functions providing a register page for the GnuCash UI
@author Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
@author Copyright (C) 2003,2005 David Hampton <hampton@employees.org>
*/
#include <config.h>
#include <libguile.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "swig-runtime.h"
#include "guile-mappings.h"
#include "gnc-plugin-page-register.h"
/*################## Added for Reg2 #################*/
#include "gnc-plugin-page-register2.h"
/*################## Added for Reg2 #################*/
#include "gnc-plugin-register.h"
#include "gnc-plugin-menu-additions.h"
#include "gnc-plugin-page-report.h"
#include "gnc-plugin-business.h"
#include "dialog-account.h"
#include "dialog-find-account.h"
#include "dialog-find-transactions.h"
#include "dialog-print-check.h"
#include "dialog-invoice.h"
#include "dialog-transfer.h"
#include "dialog-utils.h"
#include "assistant-stock-split.h"
#include "gnc-component-manager.h"
#include "gnc-date.h"
#include "gnc-date-edit.h"
#include "gnc-engine.h"
#include "gnc-event.h"
#include "gnc-features.h"
#include "gnc-gnome-utils.h"
#include "gnc-gobject-utils.h"
#include "gnc-gui-query.h"
#include "gnc-icons.h"
#include "gnc-split-reg.h"
#include "gnc-state.h"
#include "gnc-prefs.h"
#include "gnc-ui-util.h"
#include "gnc-window.h"
#include "gnc-main-window.h"
#include "gnc-session.h"
#include "gnc-warnings.h"
#include "gnucash-sheet.h"
#include "dialog-lot-viewer.h"
#include "Scrub.h"
#include "ScrubBusiness.h"
#include "qof.h"
#include "window-reconcile.h"
#include "window-autoclear.h"
#include "window-report.h"
#include "engine-helpers.h"
#include "qofbookslots.h"
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_GUI;
#define DEFAULT_LINES_AMOUNT 50
#define DEFAULT_FILTER_NUM_DAYS_GL "30"
static void gnc_plugin_page_register_class_init (GncPluginPageRegisterClass*
klass);
static void gnc_plugin_page_register_init (GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_finalize (GObject* object);
/* static Account *gnc_plugin_page_register_get_current_account (GncPluginPageRegister *page); */
static GtkWidget* gnc_plugin_page_register_create_widget (
GncPluginPage* plugin_page);
static void gnc_plugin_page_register_destroy_widget (GncPluginPage*
plugin_page);
static void gnc_plugin_page_register_window_changed (GncPluginPage*
plugin_page, GtkWidget* window);
static gboolean gnc_plugin_page_register_focus_widget (GncPluginPage*
plugin_page);
static void gnc_plugin_page_register_focus (GncPluginPage* plugin_page,
gboolean current_page);
static void gnc_plugin_page_register_save_page (GncPluginPage* plugin_page,
GKeyFile* file, const gchar* group);
static GncPluginPage* gnc_plugin_page_register_recreate_page (
GtkWidget* window, GKeyFile* file, const gchar* group);
static void gnc_plugin_page_register_update_edit_menu (GncPluginPage* page,
gboolean hide);
static gboolean gnc_plugin_page_register_finish_pending (GncPluginPage* page);
static gchar* gnc_plugin_page_register_get_tab_name (GncPluginPage*
plugin_page);
static gchar* gnc_plugin_page_register_get_tab_color (GncPluginPage*
plugin_page);
static gchar* gnc_plugin_page_register_get_long_name (GncPluginPage*
plugin_page);
static void gnc_plugin_page_register_summarybar_position_changed (
gpointer prefs, gchar* pref, gpointer user_data);
/* Callbacks for the "Sort By" dialog */
void gnc_plugin_page_register_sort_button_cb (GtkToggleButton* button,
GncPluginPageRegister* page);
void gnc_plugin_page_register_sort_response_cb (GtkDialog* dialog,
gint response, GncPluginPageRegister* plugin_page);
void gnc_plugin_page_register_sort_order_save_cb (GtkToggleButton* button,
GncPluginPageRegister* page);
void gnc_plugin_page_register_sort_order_reverse_cb (GtkToggleButton* button,
GncPluginPageRegister* page);
static gchar* gnc_plugin_page_register_get_sort_order (GncPluginPage*
plugin_page);
void gnc_plugin_page_register_set_sort_order (GncPluginPage* plugin_page,
const gchar* sort_order);
static gboolean gnc_plugin_page_register_get_sort_reversed (
GncPluginPage* plugin_page);
void gnc_plugin_page_register_set_sort_reversed (GncPluginPage* plugin_page,
gboolean reverse_order);
/* Callbacks for the "Filter By" dialog */
void gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton* button,
GncPluginPageRegister* page);
void gnc_plugin_page_register_filter_start_cb (GtkWidget* radio,
GncPluginPageRegister* page);
void gnc_plugin_page_register_filter_end_cb (GtkWidget* radio,
GncPluginPageRegister* page);
void gnc_plugin_page_register_filter_response_cb (GtkDialog* dialog,
gint response, GncPluginPageRegister* plugin_page);
void gnc_plugin_page_register_filter_status_all_cb (GtkButton* button,
GncPluginPageRegister* plugin_page);
void gnc_plugin_page_register_filter_status_one_cb (GtkToggleButton* button,
GncPluginPageRegister* page);
void gnc_plugin_page_register_filter_save_cb (GtkToggleButton* button,
GncPluginPageRegister* page);
void gnc_plugin_page_register_filter_days_changed_cb (GtkSpinButton* button,
GncPluginPageRegister* page);
static time64 gnc_plugin_page_register_filter_dmy2time (char* date_string);
static gchar* gnc_plugin_page_register_filter_time2dmy (time64 raw_time);
static gchar* gnc_plugin_page_register_get_filter (GncPluginPage* plugin_page);
void gnc_plugin_page_register_set_filter (GncPluginPage* plugin_page,
const gchar* filter);
static void gnc_plugin_page_register_set_filter_tooltip (
GncPluginPageRegister* page);
static void gnc_ppr_update_status_query (GncPluginPageRegister* page);
static void gnc_ppr_update_date_query (GncPluginPageRegister* page);
/* Command callbacks */
static void gnc_plugin_page_register_cmd_print_check (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_cut (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_copy (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_paste (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_edit_account (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_find_account (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_find_transactions (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_cut_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_copy_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_paste_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_void_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_unvoid_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_reverse_transaction (
GtkAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_view_sort_by (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_view_filter_by (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_style_changed (GtkAction* action,
GtkRadioAction* current, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_style_double_line (
GtkToggleAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_reconcile (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_autoclear (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_transfer (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_stock_split (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_lots (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_enter_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_cancel_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_delete_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_blank_transaction (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_duplicate_transaction (
GtkAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_reinitialize_transaction (
GtkAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_expand_transaction (
GtkToggleAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_exchange_rate (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_jump (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_reload (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_schedule (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_scrub_all (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_scrub_current (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_account_report (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_transaction_report (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_associate_file_transaction (
GtkAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_associate_location_transaction (
GtkAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_execassociated_transaction (
GtkAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_jump_associated_invoice (
GtkAction* action, GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_help_changed_cb (GNCSplitReg* gsr,
GncPluginPageRegister* register_page);
static void gnc_plugin_page_popup_menu_cb (GNCSplitReg* gsr,
GncPluginPageRegister* register_page);
static void gnc_plugin_page_register_refresh_cb (GHashTable* changes,
gpointer user_data);
static void gnc_plugin_page_register_close_cb (gpointer user_data);
static void gnc_plugin_page_register_ui_update (gpointer various,
GncPluginPageRegister* page);
static void gppr_account_destroy_cb (Account* account);
static void gnc_plugin_page_register_event_handler (QofInstance* entity,
QofEventId event_type,
GncPluginPageRegister* page,
GncEventData* ed);
static GncInvoice* invoice_from_split (Split* split);
/************************************************************/
/* Actions */
/************************************************************/
#define CUT_TRANSACTION_LABEL N_("Cu_t Transaction")
#define COPY_TRANSACTION_LABEL N_("_Copy Transaction")
#define PASTE_TRANSACTION_LABEL N_("_Paste Transaction")
#define DUPLICATE_TRANSACTION_LABEL N_("Dup_licate Transaction")
#define DELETE_TRANSACTION_LABEL N_("_Delete Transaction")
#define ASSOCIATE_TRANSACTION_FILE_LABEL N_("_Associate File with Transaction")
#define ASSOCIATE_TRANSACTION_LOCATION_LABEL N_("_Associate Location with Transaction")
#define EXECASSOCIATED_TRANSACTION_LABEL N_("_Open Associated File/Location")
#define JUMP_ASSOCIATED_INVOICE_LABEL N_("Open Associated Invoice")
#define CUT_SPLIT_LABEL N_("Cu_t Split")
#define COPY_SPLIT_LABEL N_("_Copy Split")
#define PASTE_SPLIT_LABEL N_("_Paste Split")
#define DUPLICATE_SPLIT_LABEL N_("Dup_licate Split")
#define DELETE_SPLIT_LABEL N_("_Delete Split")
#define CUT_TRANSACTION_TIP N_("Cut the selected transaction into clipboard")
#define COPY_TRANSACTION_TIP N_("Copy the selected transaction into clipboard")
#define PASTE_TRANSACTION_TIP N_("Paste the transaction from the clipboard")
#define DUPLICATE_TRANSACTION_TIP N_("Make a copy of the current transaction")
#define DELETE_TRANSACTION_TIP N_("Delete the current transaction")
#define ASSOCIATE_TRANSACTION_FILE_TIP N_("Associate a file with the current transaction")
#define ASSOCIATE_TRANSACTION_LOCATION_TIP N_("Associate a location with the current transaction")
#define EXECASSOCIATED_TRANSACTION_TIP N_("Open the associated file or location with the current transaction")
#define JUMP_ASSOCIATED_INVOICE_TIP N_("Open the associated invoice")
#define CUT_SPLIT_TIP N_("Cut the selected split into clipboard")
#define COPY_SPLIT_TIP N_("Copy the selected split into clipboard")
#define PASTE_SPLIT_TIP N_("Paste the split from the clipboard")
#define DUPLICATE_SPLIT_TIP N_("Make a copy of the current split")
#define DELETE_SPLIT_TIP N_("Delete the current split")
static GtkActionEntry gnc_plugin_page_register_actions [] =
{
/* File menu */
{
"FilePrintAction", "document-print", N_ ("_Print Checks..."), "<primary>p", NULL,
G_CALLBACK (gnc_plugin_page_register_cmd_print_check)
},
/* Edit menu */
{
"EditCutAction", "edit-cut", N_ ("Cu_t"), "<primary>X",
N_ ("Cut the current selection and copy it to clipboard"),
G_CALLBACK (gnc_plugin_page_register_cmd_cut)
},
{
"EditCopyAction", "edit-copy", N_ ("_Copy"), "<primary>C",
N_ ("Copy the current selection to clipboard"),
G_CALLBACK (gnc_plugin_page_register_cmd_copy)
},
{
"EditPasteAction", "edit-paste", N_ ("_Paste"), "<primary>V",
N_ ("Paste the clipboard content at the cursor position"),
G_CALLBACK (gnc_plugin_page_register_cmd_paste)
},
{
"EditEditAccountAction", GNC_ICON_EDIT_ACCOUNT, N_ ("Edit _Account"), "<primary>e",
N_ ("Edit the selected account"),
G_CALLBACK (gnc_plugin_page_register_cmd_edit_account)
},
{
"EditFindAccountAction", "edit-find", N_ ("F_ind Account"), "<primary>i",
N_ ("Find an account"),
G_CALLBACK (gnc_plugin_page_register_cmd_find_account)
},
{
"EditFindTransactionsAction", "edit-find", N_ ("_Find..."), "<primary>f",
N_ ("Find transactions with a search"),
G_CALLBACK (gnc_plugin_page_register_cmd_find_transactions)
},
/* Transaction menu */
{
"CutTransactionAction", "edit-cut", CUT_TRANSACTION_LABEL, "",
CUT_TRANSACTION_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_cut_transaction)
},
{
"CopyTransactionAction", "edit-copy", COPY_TRANSACTION_LABEL, "",
COPY_TRANSACTION_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_copy_transaction)
},
{
"PasteTransactionAction", "edit-paste", PASTE_TRANSACTION_LABEL, "",
PASTE_TRANSACTION_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_paste_transaction)
},
{
"DuplicateTransactionAction", "edit-copy", DUPLICATE_TRANSACTION_LABEL, "",
DUPLICATE_TRANSACTION_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_duplicate_transaction)
},
{
"DeleteTransactionAction", "edit-delete", DELETE_TRANSACTION_LABEL, NULL,
DELETE_TRANSACTION_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_delete_transaction)
},
{
"RemoveTransactionSplitsAction", "edit-clear", N_ ("Remo_ve Other Splits"), NULL,
N_ ("Remove all splits in the current transaction"),
G_CALLBACK (gnc_plugin_page_register_cmd_reinitialize_transaction)
},
{
"RecordTransactionAction", "list-add", N_ ("_Enter Transaction"), NULL,
N_ ("Record the current transaction"),
G_CALLBACK (gnc_plugin_page_register_cmd_enter_transaction)
},
{
"CancelTransactionAction", "process-stop", N_ ("Ca_ncel Transaction"), NULL,
N_ ("Cancel the current transaction"),
G_CALLBACK (gnc_plugin_page_register_cmd_cancel_transaction)
},
{
"VoidTransactionAction", NULL, N_ ("_Void Transaction"), NULL, NULL,
G_CALLBACK (gnc_plugin_page_register_cmd_void_transaction)
},
{
"UnvoidTransactionAction", NULL, N_ ("_Unvoid Transaction"), NULL, NULL,
G_CALLBACK (gnc_plugin_page_register_cmd_unvoid_transaction)
},
{
"ReverseTransactionAction", NULL, N_ ("Add _Reversing Transaction"), NULL, NULL,
G_CALLBACK (gnc_plugin_page_register_cmd_reverse_transaction)
},
{
"AssociateTransactionFileAction", NULL, ASSOCIATE_TRANSACTION_FILE_LABEL, NULL,
ASSOCIATE_TRANSACTION_FILE_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_associate_file_transaction)
},
{
"AssociateTransactionLocationAction", NULL, ASSOCIATE_TRANSACTION_LOCATION_LABEL, NULL,
ASSOCIATE_TRANSACTION_LOCATION_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_associate_location_transaction)
},
{
"ExecAssociatedTransactionAction", NULL, EXECASSOCIATED_TRANSACTION_LABEL, NULL,
EXECASSOCIATED_TRANSACTION_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_execassociated_transaction)
},
{
"JumpAssociatedInvoiceAction", NULL, JUMP_ASSOCIATED_INVOICE_LABEL, NULL,
JUMP_ASSOCIATED_INVOICE_TIP,
G_CALLBACK (gnc_plugin_page_register_cmd_jump_associated_invoice)
},
/* View menu */
{
"ViewSortByAction", NULL, N_ ("_Sort By..."), NULL, NULL,
G_CALLBACK (gnc_plugin_page_register_cmd_view_sort_by)
},
{
"ViewFilterByAction", NULL, N_ ("_Filter By..."), NULL, NULL,
G_CALLBACK (gnc_plugin_page_register_cmd_view_filter_by)
},
{
"ViewRefreshAction", "view-refresh", N_ ("_Refresh"), "<primary>r",
N_ ("Refresh this window"),
G_CALLBACK (gnc_plugin_page_register_cmd_reload)
},
/* Actions menu */
{
"ActionsTransferAction", GNC_ICON_TRANSFER, N_ ("_Transfer..."), "<primary>t",
N_ ("Transfer funds from one account to another"),
G_CALLBACK (gnc_plugin_page_register_cmd_transfer)
},
{
"ActionsReconcileAction", "edit-select-all", N_ ("_Reconcile..."), NULL,
N_ ("Reconcile the selected account"),
G_CALLBACK (gnc_plugin_page_register_cmd_reconcile)
},
{
"ActionsAutoClearAction", "edit-select-all", N_ ("_Auto-clear..."), NULL,
N_ ("Automatically clear individual transactions, so as to reach a certain cleared amount"),
G_CALLBACK (gnc_plugin_page_register_cmd_autoclear)
},
{
"ActionsStockSplitAction", NULL, N_ ("Stoc_k Split..."), NULL,
N_ ("Record a stock split or a stock merger"),
G_CALLBACK (gnc_plugin_page_register_cmd_stock_split)
},
{
"ActionsLotsAction", NULL, N_ ("View _Lots..."), NULL,
N_ ("Bring up the lot viewer/editor window"),
G_CALLBACK (gnc_plugin_page_register_cmd_lots)
},
{
"BlankTransactionAction", "go-bottom", N_ ("_Blank Transaction"), "<primary>Page_Down",
N_ ("Move to the blank transaction at the bottom of the register"),
G_CALLBACK (gnc_plugin_page_register_cmd_blank_transaction)
},
{
"EditExchangeRateAction", NULL, N_ ("Edit E_xchange Rate"), NULL,
N_ ("Edit the exchange rate for the current transaction"),
G_CALLBACK (gnc_plugin_page_register_cmd_exchange_rate)
},
{
"JumpTransactionAction", GNC_ICON_JUMP_TO, N_ ("_Jump"), NULL,
N_ ("Jump to the corresponding transaction in the other account"),
G_CALLBACK (gnc_plugin_page_register_cmd_jump)
},
{
"ScheduleTransactionAction", GNC_ICON_SCHEDULE, N_ ("Sche_dule..."), NULL,
N_ ("Create a Scheduled Transaction with the current transaction as a template"),
G_CALLBACK (gnc_plugin_page_register_cmd_schedule)
},
{
"ScrubAllAction", NULL,
/* Translators: The following 2 are Scrub actions in register view */
N_ ("_All transactions"), NULL, NULL,
G_CALLBACK (gnc_plugin_page_register_cmd_scrub_all)
},
{
"ScrubCurrentAction", NULL, N_ ("_This transaction"), NULL, NULL,
G_CALLBACK (gnc_plugin_page_register_cmd_scrub_current)
},
/* Reports menu */
{
"ReportsAccountReportAction", NULL, N_ ("Account Report"), NULL,
N_ ("Open a register report for this Account"),
G_CALLBACK (gnc_plugin_page_register_cmd_account_report)
},
{
"ReportsAcctTransReportAction", NULL, N_ ("Account Report - Single Transaction"), NULL,
N_ ("Open a register report for the selected Transaction"),
G_CALLBACK (gnc_plugin_page_register_cmd_transaction_report)
},
};
static guint gnc_plugin_page_register_n_actions = G_N_ELEMENTS (
gnc_plugin_page_register_actions);
static GtkToggleActionEntry toggle_entries[] =
{
{
"ViewStyleDoubleLineAction", NULL, N_ ("_Double Line"), NULL,
N_ ("Show two lines of information for each transaction"),
G_CALLBACK (gnc_plugin_page_register_cmd_style_double_line), FALSE
},
{
"SplitTransactionAction", GNC_ICON_SPLIT_TRANS, N_ ("S_plit Transaction"), NULL,
N_ ("Show all splits in the current transaction"),
G_CALLBACK (gnc_plugin_page_register_cmd_expand_transaction), FALSE
},
};
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
static GtkRadioActionEntry radio_entries_2 [] =
{
/* Translators: This is a menu item in the View menu */
{
"ViewStyleBasicAction", NULL, N_ ("_Basic Ledger"), NULL,
N_ ("Show transactions on one or two lines"), REG_STYLE_LEDGER
},
/* Translators: This is a menu item in the View menu */
{
"ViewStyleAutoSplitAction", NULL, N_ ("_Auto-Split Ledger"), NULL,
N_ ("Show transactions on one or two lines and expand the current transaction"), REG_STYLE_AUTO_LEDGER
},
/* Translators: This is a menu item in the View menu */
{
"ViewStyleJournalAction", NULL, N_ ("Transaction _Journal"), NULL,
N_ ("Show expanded transactions with all splits"), REG_STYLE_JOURNAL
}
};
static guint n_radio_entries_2 = G_N_ELEMENTS (radio_entries_2);
/** These are the "important" actions provided by the register page.
* Their labels will appear when the toolbar is set to "Icons and
* important text" (e.g. GTK_TOOLBAR_BOTH_HORIZ) mode. */
static const gchar* important_actions[] =
{
"SplitTransactionAction",
NULL,
};
/** Actions that require an account to be selected before they are
* enabled. */
static const gchar* actions_requiring_account[] =
{
"EditEditAccountAction",
"ActionsReconcileAction",
"ActionsAutoClearAction",
"ActionsLotsAction",
NULL
};
/** View Style actions */
static const gchar* view_style_actions[] =
{
"ViewStyleBasicAction",
"ViewStyleAutoSplitAction",
"ViewStyleJournalAction",
NULL
};
/** Short labels for use on the toolbar buttons. */
static action_toolbar_labels toolbar_labels[] =
{
{ "ActionsTransferAction", N_ ("Transfer") },
{ "RecordTransactionAction", N_ ("Enter") },
{ "CancelTransactionAction", N_ ("Cancel") },
{ "DeleteTransactionAction", N_ ("Delete") },
{ "DuplicateTransactionAction", N_ ("Duplicate") },
{ "SplitTransactionAction", N_ ("Split") },
{ "ScheduleTransactionAction", N_ ("Schedule") },
{ "BlankTransactionAction", N_ ("Blank") },
{ "ActionsReconcileAction", N_ ("Reconcile") },
{ "ActionsAutoClearAction", N_ ("Auto-clear") },
{ "AssociateTransactionFileAction", N_ ("Associate File") },
{ "AssociateTransactionLocationAction", N_ ("Associate Location") },
{ "ExecAssociatedTransactionAction", N_ ("Open File/Location") },
{ "JumpAssociatedInvoiceAction", N_ ("Open Invoice") },
{ NULL, NULL },
};
struct status_action
{
const char* action_name;
int value;
GtkWidget* widget;
};
static struct status_action status_actions[] =
{
{ "filter_status_reconciled", CLEARED_RECONCILED, NULL },
{ "filter_status_cleared", CLEARED_CLEARED, NULL },
{ "filter_status_voided", CLEARED_VOIDED, NULL },
{ "filter_status_frozen", CLEARED_FROZEN, NULL },
{ "filter_status_unreconciled", CLEARED_NO, NULL },
{ NULL, 0, NULL },
};
#define CLEARED_VALUE "cleared_value"
#define DEFAULT_FILTER "0x001f"
#define DEFAULT_SORT_ORDER "BY_STANDARD"
/************************************************************/
/* Data Structures */
/************************************************************/
typedef struct GncPluginPageRegisterPrivate
{
GNCLedgerDisplay* ledger;
GNCSplitReg* gsr;
GtkWidget* widget;
gint event_handler_id;
gint component_manager_id;
GncGUID key; /* The guid of the Account we're watching */
gint lines_default;
gboolean read_only;
gboolean page_focus;
gboolean enable_refresh; // used to reduce ledger display refreshes
Query* search_query; // saved search query for comparison
Query* filter_query; // saved filter query for comparison
struct
{
GtkWidget* dialog;
GtkWidget* num_radio;
GtkWidget* act_radio;
SortType original_sort_type;
gboolean original_save_order;
gboolean save_order;
gboolean reverse_order;
gboolean original_reverse_order;
} sd;
struct
{
GtkWidget* dialog;
GtkWidget* table;
GtkWidget* start_date_choose;
GtkWidget* start_date_today;
GtkWidget* start_date;
GtkWidget* end_date_choose;
GtkWidget* end_date_today;
GtkWidget* end_date;
GtkWidget* num_days;
cleared_match_t original_cleared_match;
cleared_match_t cleared_match;
time64 original_start_time;
time64 original_end_time;
time64 start_time;
time64 end_time;
gint days;
gint original_days;
gboolean original_save_filter;
gboolean save_filter;
} fd;
} GncPluginPageRegisterPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GncPluginPageRegister, gnc_plugin_page_register,
GNC_TYPE_PLUGIN_PAGE)
#define GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(o) \
((GncPluginPageRegisterPrivate*)g_type_instance_get_private((GTypeInstance*)o, GNC_TYPE_PLUGIN_PAGE_REGISTER))
static GObjectClass* parent_class = NULL;
/************************************************************/
/* Implementation */
/************************************************************/
static GncPluginPage*
gnc_plugin_page_register_new_common (GNCLedgerDisplay* ledger)
{
GncPluginPageRegister* register_page;
GncPluginPageRegisterPrivate* priv;
GncPluginPage* plugin_page;
GNCSplitReg* gsr;
const GList* item;
GList* book_list;
gchar* label;
gchar* label_color;
QofQuery* q;
/* Is there an existing page? */
gsr = gnc_ledger_display_get_user_data (ledger);
if (gsr)
{
item = gnc_gobject_tracking_get_list (GNC_PLUGIN_PAGE_REGISTER_NAME);
for (; item; item = g_list_next (item))
{
register_page = (GncPluginPageRegister*)item->data;
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (register_page);
if (priv->gsr == gsr)
return GNC_PLUGIN_PAGE (register_page);
}
}
register_page = g_object_new (GNC_TYPE_PLUGIN_PAGE_REGISTER, NULL);
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (register_page);
priv->ledger = ledger;
priv->key = *guid_null();
plugin_page = GNC_PLUGIN_PAGE (register_page);
label = gnc_plugin_page_register_get_tab_name (plugin_page);
gnc_plugin_page_set_page_name (plugin_page, label);
g_free (label);
label_color = gnc_plugin_page_register_get_tab_color (plugin_page);
gnc_plugin_page_set_page_color (plugin_page, label_color);
g_free (label_color);
label = gnc_plugin_page_register_get_long_name (plugin_page);
gnc_plugin_page_set_page_long_name (plugin_page, label);
g_free (label);
q = gnc_ledger_display_get_query (ledger);
book_list = qof_query_get_books (q);
for (item = book_list; item; item = g_list_next (item))
gnc_plugin_page_add_book (plugin_page, (QofBook*)item->data);
// Do not free the list. It is owned by the query.
priv->component_manager_id = 0;
return plugin_page;
}
static gpointer
gnc_plug_page_register_check_commodity (Account* account, void* usr_data)
{
// Check that account's commodity matches the commodity in usr_data
gnc_commodity* com0 = (gnc_commodity*) usr_data;
gnc_commodity* com1 = xaccAccountGetCommodity (account);
return gnc_commodity_equal (com1, com0) ? NULL : com1;
}
GncPluginPage*
gnc_plugin_page_register_new (Account* account, gboolean subaccounts)
{
GNCLedgerDisplay* ledger;
GncPluginPage* page;
GncPluginPageRegisterPrivate* priv;
gnc_commodity* com0;
gnc_commodity* com1;
/*################## Added for Reg2 #################*/
const GList* item;
GncPluginPageRegister2* new_register_page;
/*################## Added for Reg2 #################*/
ENTER ("account=%p, subaccounts=%s", account,
subaccounts ? "TRUE" : "FALSE");
/*################## Added for Reg2 #################*/
// We test for the new register being open here, ie matching account guids
item = gnc_gobject_tracking_get_list (GNC_PLUGIN_PAGE_REGISTER2_NAME);
for (; item; item = g_list_next (item))
{
Account* new_account;
new_register_page = (GncPluginPageRegister2*)item->data;
new_account = gnc_plugin_page_register2_get_account (new_register_page);
if (guid_equal (xaccAccountGetGUID (account),
xaccAccountGetGUID (new_account)))
{
GtkWindow* window = GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (
new_register_page)));
gnc_error_dialog (window, "%s",
_ ("You have tried to open an account in the old register while it is open in the new register."));
return NULL;
}
}
/*################## Added for Reg2 #################*/
com0 = gnc_account_get_currency_or_parent (account);
com1 = gnc_account_foreach_descendant_until (account,
gnc_plug_page_register_check_commodity, com0);
if (subaccounts)
ledger = gnc_ledger_display_subaccounts (account, com1 != NULL);
else
ledger = gnc_ledger_display_simple (account);
page = gnc_plugin_page_register_new_common (ledger);
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page);
priv->key = *xaccAccountGetGUID (account);
LEAVE ("%p", page);
return page;
}
GncPluginPage*
gnc_plugin_page_register_new_gl (void)
{
GNCLedgerDisplay* ledger;
ledger = gnc_ledger_display_gl();
return gnc_plugin_page_register_new_common (ledger);
}
GncPluginPage*
gnc_plugin_page_register_new_ledger (GNCLedgerDisplay* ledger)
{
return gnc_plugin_page_register_new_common (ledger);
}
static void
gnc_plugin_page_register_class_init (GncPluginPageRegisterClass* 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_register_finalize;
gnc_plugin_class->tab_icon = GNC_ICON_ACCOUNT;
gnc_plugin_class->plugin_name = GNC_PLUGIN_PAGE_REGISTER_NAME;
gnc_plugin_class->create_widget = gnc_plugin_page_register_create_widget;
gnc_plugin_class->destroy_widget = gnc_plugin_page_register_destroy_widget;
gnc_plugin_class->window_changed = gnc_plugin_page_register_window_changed;
gnc_plugin_class->focus_page = gnc_plugin_page_register_focus;
gnc_plugin_class->save_page = gnc_plugin_page_register_save_page;
gnc_plugin_class->recreate_page = gnc_plugin_page_register_recreate_page;
gnc_plugin_class->update_edit_menu_actions =
gnc_plugin_page_register_update_edit_menu;
gnc_plugin_class->finish_pending = gnc_plugin_page_register_finish_pending;
gnc_plugin_class->focus_page_function = gnc_plugin_page_register_focus_widget;
gnc_ui_register_account_destroy_callback (gppr_account_destroy_cb);
}
static void
gnc_plugin_page_register_init (GncPluginPageRegister* plugin_page)
{
GncPluginPageRegisterPrivate* priv;
GncPluginPage* parent;
GtkActionGroup* action_group;
gboolean use_new;
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (plugin_page);
/* Init parent declared variables */
parent = GNC_PLUGIN_PAGE (plugin_page);
use_new = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER,
GNC_PREF_USE_NEW);
g_object_set (G_OBJECT (plugin_page),
"page-name", _ ("General Journal"),
"page-uri", "default:",
"ui-description", "gnc-plugin-page-register-ui.xml",
"use-new-window", use_new,
NULL);
/* Create menu and toolbar information */
action_group =
gnc_plugin_page_create_action_group (parent,
"GncPluginPageRegisterActions");
gtk_action_group_add_actions (action_group, gnc_plugin_page_register_actions,
gnc_plugin_page_register_n_actions, plugin_page);
gtk_action_group_add_toggle_actions (action_group,
toggle_entries, n_toggle_entries,
plugin_page);
gtk_action_group_add_radio_actions (action_group,
radio_entries_2, n_radio_entries_2,
REG_STYLE_LEDGER,
G_CALLBACK (gnc_plugin_page_register_cmd_style_changed),
plugin_page);
gnc_plugin_init_short_names (action_group, toolbar_labels);
gnc_plugin_set_important_actions (action_group, important_actions);
priv->lines_default = DEFAULT_LINES_AMOUNT;
priv->read_only = FALSE;
priv->fd.cleared_match = CLEARED_ALL;
priv->fd.days = 0;
priv->enable_refresh = TRUE;
priv->search_query = NULL;
priv->filter_query = NULL;
}
static void
gnc_plugin_page_register_finalize (GObject* object)
{
g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (object));
ENTER ("object %p", object);
G_OBJECT_CLASS (parent_class)->finalize (object);
LEAVE (" ");
}
Account*
gnc_plugin_page_register_get_account (GncPluginPageRegister* page)
{
GncPluginPageRegisterPrivate* priv;
GNCLedgerDisplayType ledger_type;
Account* leader;
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page);
ledger_type = gnc_ledger_display_type (priv->ledger);
leader = gnc_ledger_display_leader (priv->ledger);
if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
return leader;
return NULL;
}
Transaction*
gnc_plugin_page_register_get_current_txn (GncPluginPageRegister* page)
{
GncPluginPageRegisterPrivate* priv;
SplitRegister* reg;
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page);
reg = gnc_ledger_display_get_split_register (priv->ledger);
return gnc_split_register_get_current_trans (reg);
}
/**
* Whenever the current page is changed, if a register page is
* the current page, set focus on the sheet.
*/
static gboolean
gnc_plugin_page_register_focus_widget (GncPluginPage* register_plugin_page)
{
if (GNC_IS_PLUGIN_PAGE_REGISTER (register_plugin_page))
{
GNCSplitReg* gsr = gnc_plugin_page_register_get_gsr (GNC_PLUGIN_PAGE (
register_plugin_page));
gnc_split_reg_focus_on_sheet (gsr);
}
return FALSE;
}
/* This is the list of actions which are switched inactive in a read-only book. */
static const char* readonly_inactive_actions[] =
{
"EditCutAction",
"EditPasteAction",
"CutTransactionAction",
"PasteTransactionAction",
"DuplicateTransactionAction",
"DeleteTransactionAction",
"RemoveTransactionSplitsAction",
"RecordTransactionAction",
"CancelTransactionAction",
"UnvoidTransactionAction",
"VoidTransactionAction",
"ReverseTransactionAction",
"ActionsTransferAction",
"ActionsReconcileAction",
"ActionsStockSplitAction",
"ScheduleTransactionAction",
"ScrubAllAction",
"ScrubCurrentAction",
"AssociateTransactionFileAction",
"AssociateTransactionLocationAction",
NULL
};
/* This is the list of actions whose text needs to be changed based on whether */
/* the current cursor class is transaction or split. */
static const char* tran_vs_split_actions[] =
{
"CutTransactionAction",
"CopyTransactionAction",
"PasteTransactionAction",
"DuplicateTransactionAction",
"DeleteTransactionAction",
NULL
};
/* This is the list of labels for when the current cursor class is transaction. */