/
gnc-plugin-page-report.cpp
2127 lines (1802 loc) · 72 KB
/
gnc-plugin-page-report.cpp
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-report.c
* Copyright (C) 2004 Joshua Sled <jsled@asynchronous.org>
* Copyright (C) 2005 David Hampton <hampton@employees.org>
*
* Originally from window-report.c:
* Copyright (C) 1997 Robin D. Clark
* Copyright (C) 1998 Linas Vepstas
* Copyright (C) 1999 Jeremy Collins ( gtk-xmhtml port )
* Copyright (C) 2000 Dave Peticolas
* Copyright (C) 2000 Bill Gribble
*
* 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 GUI
@{ */
/** @addtogroup GuiReport Reports
@{ */
/** @file gnc-plugin-page-report.c
@brief Report page.
@author Copyright (C) 2004 Joshua Sled <jsled@asynchronous.org>
@author Copyright (C) 2005 David Hampton <hampton@employees.org>
*/
#include <libguile.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
extern "C"
{
#include <config.h>
#include <sys/stat.h>
#include <errno.h>
#include <gnc-glib-utils.h>
#include "gfec.h"
#include "dialog-custom-report.h"
#include "dialog-utils.h"
#include "gnc-component-manager.h"
#include "gnc-engine.h"
#include "gnc-gnome-utils.h"
#include "gnc-guile-utils.h"
#include "gnc-html-history.h"
#include "gnc-html.h"
#include "gnc-html-factory.h"
#include "gnc-file.h"
#include "gnc-filepath-utils.h"
#include "gnc-gtk-utils.h"
#include "gnc-plugin.h"
#include "gnc-plugin-page-report.h"
#include "gnc-plugin-file-history.h"
#include "gnc-prefs.h"
#include "gnc-session.h"
#include "gnc-ui-util.h"
#include "gnc-ui.h"
#include "gnc-window.h"
#include "window-report.h"
#include "swig-runtime.h"
#include "guile-mappings.h"
#include "gnc-icons.h"
#include "print-session.h"
}
#include <memory>
#include <gnc-report.h>
#include "gnc-optiondb-impl.hpp"
/* NW: you can add GNC_MOD_REPORT to gnc-engine.h
or simply define it locally. Any unique string with
a gnucash- prefix will do. Then just set a log level
with qof_log_set_level().*/
static QofLogModule log_module = GNC_MOD_GUI;
static GObjectClass *parent_class = nullptr;
// A static GHashTable to record the usage count for each printer
// output name. FIXME: Currently this isn't cleaned up at program
// shutdown because there isn't a place to easily insert a finalize()
// function for this. Oh well.
static GHashTable *static_report_printnames = nullptr;
// Property-id values.
enum
{
PROP_0,
PROP_REPORT_ID,
};
typedef struct GncPluginPageReportPrivate
{
/// The report-id
int reportId;
gint component_manager_id;
/// The report which this Page is satisfying
SCM cur_report;
/// The Option DB for this report.
GncOptionDB *cur_odb;
size_t option_change_cb_id = 0;
/* initial_report is special; it's the one that's saved and
* restored. The name_change_callback only gets called when
* the initial_report name is changed. */
SCM initial_report;
GncOptionDB * initial_odb;
size_t name_change_cb_id;
/* keep a list of edited reports so that we can destroy them when
* the window is closed. */
SCM edited_reports;
/* The page is in the process of reloading the html */
gboolean reloading;
gboolean loaded;
/// the gnc_html abstraction this PluginPage contains
// gnc_html *html;
GncHtml *html;
gboolean webkit2;
/// the container the above HTML widget is in.
GtkContainer *container;
} GncPluginPageReportPrivate;
G_DEFINE_TYPE_WITH_PRIVATE(GncPluginPageReport, gnc_plugin_page_report, GNC_TYPE_PLUGIN_PAGE)
#define GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(o) \
((GncPluginPageReportPrivate*)gnc_plugin_page_report_get_instance_private((GncPluginPageReport*)o))
static void gnc_plugin_page_report_class_init( GncPluginPageReportClass *klass );
static void gnc_plugin_page_report_init( GncPluginPageReport *plugin_page );
static GObject *gnc_plugin_page_report_constructor(GType this_type, guint n_properties, GObjectConstructParam *properties);
static void gnc_plugin_page_report_finalize (GObject *object);
static void gnc_plugin_page_report_setup( GncPluginPage *ppage );
static void gnc_plugin_page_report_constr_init(GncPluginPageReport *plugin_page, gint reportId);
static GtkWidget* gnc_plugin_page_report_create_widget( GncPluginPage *plugin_page );
static void gnc_plugin_page_report_destroy_widget( GncPluginPage *plugin_page );
static void gnc_plugin_page_report_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
static GncPluginPage *gnc_plugin_page_report_recreate_page (GtkWidget *window, GKeyFile *file, const gchar *group);
static void gnc_plugin_page_report_name_changed (GncPluginPage *page, const gchar *name);
static void gnc_plugin_page_report_update_edit_menu (GncPluginPage *page, gboolean hide);
static gboolean gnc_plugin_page_report_finish_pending (GncPluginPage *page);
static void gnc_plugin_page_report_load_uri (GncPluginPage *page);
static int gnc_plugin_page_report_check_urltype(URLType t);
//static void gnc_plugin_page_report_load_cb(gnc_html * html, URLType type,
static void gnc_plugin_page_report_load_cb(GncHtml * html, URLType type,
const gchar * location, const gchar * label,
gpointer data);
static void gnc_plugin_page_report_refresh (gpointer data);
static void gnc_plugin_page_report_set_fwd_button(GncPluginPageReport * page, int enabled);
static void gnc_plugin_page_report_set_back_button(GncPluginPageReport * page, int enabled);
static void gnc_plugin_page_report_history_destroy_cb(gnc_html_history_node * node, gpointer user_data);
static void close_handler(gpointer user_data);
void gnc_plugin_page_report_destroy(GncPluginPageReportPrivate *priv);
static void gnc_plugin_page_report_option_change_cb(gpointer data);
void gnc_plugin_page_report_remove_edited_report(GncPluginPageReportPrivate *priv, SCM report);
void gnc_plugin_page_report_add_edited_report(GncPluginPageReportPrivate *priv, SCM report);
static void gnc_plugin_page_report_menu_updates (GncPluginPage *plugin_page);
void gnc_plugin_page_report_raise_editor(SCM report);
static void gnc_plugin_page_report_forw_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_back_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_reload_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_stop_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_save_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_save_as_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_export_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_options_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_print_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_exportpdf_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_copy_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static void gnc_plugin_page_report_edit_tax_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
static GActionEntry report_actions[] =
{
{ "FilePrintAction", gnc_plugin_page_report_print_cb, nullptr, nullptr, nullptr },
{ "FilePrintPDFAction", gnc_plugin_page_report_exportpdf_cb, nullptr, nullptr, nullptr },
{ "EditCopyAction", gnc_plugin_page_report_copy_cb, nullptr, nullptr, nullptr },
{ "EditTaxOptionsAction", gnc_plugin_page_report_edit_tax_cb, nullptr, nullptr, nullptr },
{ "ViewRefreshAction", gnc_plugin_page_report_reload_cb, nullptr, nullptr, nullptr },
{ "ReportSaveAction", gnc_plugin_page_report_save_cb, nullptr, nullptr, nullptr },
{ "ReportSaveAsAction", gnc_plugin_page_report_save_as_cb, nullptr, nullptr, nullptr },
{ "ReportExportAction", gnc_plugin_page_report_export_cb, nullptr, nullptr, nullptr },
{ "ReportOptionsAction", gnc_plugin_page_report_options_cb, nullptr, nullptr, nullptr },
{ "ReportBackAction", gnc_plugin_page_report_back_cb, nullptr, nullptr, nullptr },
{ "ReportForwAction", gnc_plugin_page_report_forw_cb, nullptr, nullptr, nullptr },
{ "ReportReloadAction", gnc_plugin_page_report_reload_cb, nullptr, nullptr, nullptr },
{ "ReportStopAction", gnc_plugin_page_report_stop_cb, nullptr, nullptr, nullptr },
};
static guint num_report_actions = G_N_ELEMENTS(report_actions);
/** The default menu items that need to be add to the menu */
static const gchar *gnc_plugin_load_ui_items [] =
{
"FilePlaceholder3",
"FilePlaceholder4",
"FilePlaceholder5",
"EditPlaceholder6",
"ReportsPlaceholder1",
NULL,
};
/** Short labels for use on the toolbar buttons. */
static GncToolBarShortNames toolbar_labels[] =
{
{ "FilePrintAction", N_("Print") },
{ "ReportExportAction", N_("Export") },
{ "ReportOptionsAction", N_("Options") },
/* Translators: This string is meant to be a short alternative for "Save Report Configuration"
to be used as toolbar button label. */
{ "ReportSaveAction", N_("Save Config") },
/* Translators: This string is meant to be a short alternative for "Save Report Configuration As..."
to be used as toolbar button label. */
{ "ReportSaveAsAction", N_("Save Config As...") },
{ "FilePrintPDFAction", N_("Make Pdf") },
{ nullptr, nullptr },
};
static void
gnc_plugin_page_report_get_property( GObject *obj,
guint prop_id,
GValue *value,
GParamSpec *pspec )
{
GncPluginPageReport *rep;
GncPluginPageReportPrivate *priv;
rep = GNC_PLUGIN_PAGE_REPORT( obj );
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(rep);
switch ( prop_id )
{
case PROP_REPORT_ID:
g_value_set_int( value, priv->reportId );
break;
default:
PERR( "Unknown property id %d", prop_id );
break;
}
}
static void
gnc_plugin_page_report_set_property( GObject *obj,
guint prop_id,
const GValue *value,
GParamSpec *pspec )
{
GncPluginPageReport *rep;
GncPluginPageReportPrivate *priv;
rep = GNC_PLUGIN_PAGE_REPORT( obj );
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(rep);
DEBUG( "setting property with id %d / %p to value %d",
prop_id, priv, g_value_get_int( value ) );
switch ( prop_id )
{
case PROP_REPORT_ID:
priv->reportId = g_value_get_int( value );
break;
default:
PERR( "unknown property id %d", prop_id );
break;
}
}
/**
* Whenever the current page is changed, if a report page is
* the current page, set focus on the report.
*/
static gboolean
gnc_plugin_page_report_focus_widget (GncPluginPage *report_plugin_page)
{
if (GNC_IS_PLUGIN_PAGE_REPORT(report_plugin_page))
{
GncPluginPageReportPrivate *priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report_plugin_page);
GtkWidget *window;
GAction *action;
if (!priv)
return FALSE;
/* Disable the Transaction Menu */
action = gnc_main_window_find_action (GNC_MAIN_WINDOW(report_plugin_page->window), "TransactionAction");
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), FALSE);
/* Disable the Schedule menu */
action = gnc_main_window_find_action (GNC_MAIN_WINDOW(report_plugin_page->window), "ScheduledAction");
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), FALSE);
gnc_main_window_update_menu_and_toolbar (GNC_MAIN_WINDOW(report_plugin_page->window),
report_plugin_page,
gnc_plugin_load_ui_items);
// setup any short toolbar names
gnc_main_window_init_short_names (GNC_MAIN_WINDOW(report_plugin_page->window), toolbar_labels);
gnc_plugin_page_report_menu_updates (report_plugin_page);
window = gnc_plugin_page_get_window (report_plugin_page);
if (window && !gnc_main_window_is_restoring_pages (GNC_MAIN_WINDOW(window)))
{
GtkWidget *widget = gnc_html_get_webview (priv->html);
if (!priv->loaded) // so we only do the load once
gnc_plugin_page_report_load_uri (report_plugin_page);
if (GTK_IS_WIDGET(widget))
{
if (!gtk_widget_is_focus (GTK_WIDGET(widget)))
gtk_widget_grab_focus (GTK_WIDGET(widget));
}
}
}
return FALSE;
}
static void
gnc_plugin_page_report_class_init (GncPluginPageReportClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginPageClass *gnc_plugin_page_class = GNC_PLUGIN_PAGE_CLASS(klass);
parent_class = static_cast<GObjectClass*>(g_type_class_peek_parent (klass));
object_class->constructor = gnc_plugin_page_report_constructor;
object_class->finalize = gnc_plugin_page_report_finalize;
object_class->set_property = gnc_plugin_page_report_set_property;
object_class->get_property = gnc_plugin_page_report_get_property;
gnc_plugin_page_class->tab_icon = GNC_ICON_ACCOUNT_REPORT;
gnc_plugin_page_class->plugin_name = GNC_PLUGIN_PAGE_REPORT_NAME;
gnc_plugin_page_class->create_widget = gnc_plugin_page_report_create_widget;
gnc_plugin_page_class->destroy_widget = gnc_plugin_page_report_destroy_widget;
gnc_plugin_page_class->save_page = gnc_plugin_page_report_save_page;
gnc_plugin_page_class->recreate_page = gnc_plugin_page_report_recreate_page;
gnc_plugin_page_class->page_name_changed = gnc_plugin_page_report_name_changed;
gnc_plugin_page_class->update_edit_menu_actions = gnc_plugin_page_report_update_edit_menu;
gnc_plugin_page_class->finish_pending = gnc_plugin_page_report_finish_pending;
gnc_plugin_page_class->focus_page_function = gnc_plugin_page_report_focus_widget;
// create the "reportId" property
auto paramspec{static_cast<GParamFlags>(G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)};
g_object_class_install_property( object_class,
PROP_REPORT_ID,
g_param_spec_int( "report-id",
_("The numeric ID of the report."),
_("The numeric ID of the report."),
-1, G_MAXINT, -1,
paramspec));
// Also initialize the report name usage count table
if (!static_report_printnames)
static_report_printnames = g_hash_table_new_full(g_str_hash,
g_str_equal, g_free, nullptr);
}
static void
gnc_plugin_page_report_finalize (GObject *object)
{
g_return_if_fail (GNC_IS_PLUGIN_PAGE_REPORT (object));
ENTER("object %p", object);
G_OBJECT_CLASS (parent_class)->finalize (object);
LEAVE(" ");
}
static void
gnc_plugin_page_report_set_progressbar (GncPluginPage *page, gboolean set)
{
GtkWidget *progressbar;
GtkAllocation allocation;
progressbar = gnc_window_get_progressbar (GNC_WINDOW(page->window));
gtk_widget_get_allocation (GTK_WIDGET(progressbar), &allocation);
// this sets the minimum size of the progressbar to that allocated
if (set)
gtk_widget_set_size_request (GTK_WIDGET(progressbar), -1, allocation.height);
else
gtk_widget_set_size_request (GTK_WIDGET(progressbar), -1, -1); //reset
}
static void
gnc_plugin_page_report_load_uri (GncPluginPage *page)
{
GncPluginPageReport *report;
GncPluginPageReportPrivate *priv;
URLType type;
char * id_name;
char * child_name;
char * url_location = nullptr;
char * url_label = nullptr;
report = GNC_PLUGIN_PAGE_REPORT(page);
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
if (!priv)
return; // No priv means the page doesn't exist anymore.
DEBUG( "Load uri id=%d", priv->reportId );
id_name = g_strdup_printf("id=%d", priv->reportId );
child_name = gnc_build_url( URL_TYPE_REPORT, id_name, nullptr );
type = gnc_html_parse_url( priv->html, child_name, &url_location, &url_label);
DEBUG( "passing id_name=[%s] child_name=[%s] type=[%s], location=[%s], label=[%s]",
id_name, child_name ? child_name : "(null)",
type ? type : "(null)", url_location ? url_location : "(null)",
url_label ? url_label : "(null)" );
g_free(id_name);
g_free(child_name);
gtk_widget_show_all( GTK_WIDGET(priv->container) );
priv->loaded = TRUE;
// this sets the window for the progressbar
gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
// this sets the minimum size of the progressbar to that allocated
gnc_plugin_page_report_set_progressbar( page, TRUE );
gnc_html_show_url(priv->html, type, url_location, url_label, 0);
g_free(url_location);
gnc_plugin_page_report_set_progressbar( page, FALSE );
// this resets the window for the progressbar to nullptr
gnc_window_set_progressbar_window( nullptr );
}
/* used to capture Ctrl+Alt+PgUp/Down for tab selection */
static gboolean
webkit_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
GncPluginPageReport *report = GNC_PLUGIN_PAGE_REPORT(user_data);
GncPluginPageReportPrivate *priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
GdkModifierType modifiers = gtk_accelerator_get_default_mod_mask ();
GtkWidget *window = gnc_plugin_page_get_window (GNC_PLUGIN_PAGE(report));
if (GNC_PLUGIN_PAGE(report) != gnc_main_window_get_current_page (GNC_MAIN_WINDOW(window)))
return FALSE;
if ((event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down ||
event->keyval == GDK_KEY_KP_Page_Up || event->keyval == GDK_KEY_KP_Page_Down)
&& (event->state & modifiers) == (GDK_CONTROL_MASK | GDK_MOD1_MASK))
{
GtkNotebook *notebook = GTK_NOTEBOOK(gtk_widget_get_parent (GTK_WIDGET(priv->container)));
gint pages = gtk_notebook_get_n_pages (notebook);
gint current_page = gtk_notebook_get_current_page (notebook);
if (event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_KP_Page_Up)
{
if (current_page == 0)
gtk_notebook_set_current_page (notebook, pages - 1);
else
gtk_notebook_prev_page (notebook);
}
else
{
if (pages == current_page + 1)
gtk_notebook_set_current_page (notebook, 0);
else
gtk_notebook_next_page (notebook);
}
return TRUE;
}
return FALSE;
}
static
GtkWidget*
gnc_plugin_page_report_create_widget( GncPluginPage *page )
{
GncPluginPageReport *report;
GncPluginPageReportPrivate *priv;
GtkWindow *topLvl;
GAction *action;
GtkWidget *webview;
URLType type;
char * id_name;
char * child_name;
char * url_location = nullptr;
char * url_label = nullptr;
ENTER("page %p", page);
report = GNC_PLUGIN_PAGE_REPORT(page);
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
#ifndef WEBKIT1
/* Hide the ExportPdf action for Webkit2 */
priv->webkit2 = TRUE;
#endif
topLvl = gnc_ui_get_main_window (nullptr);
// priv->html = gnc_html_new( topLvl );
priv->html = gnc_html_factory_create_html();
gnc_html_set_parent( priv->html, topLvl );
priv->loaded = FALSE;
gnc_html_history_set_node_destroy_cb(gnc_html_get_history(priv->html),
gnc_plugin_page_report_history_destroy_cb,
(gpointer)priv);
priv->container = GTK_CONTAINER(gtk_frame_new(nullptr));
gtk_frame_set_shadow_type(GTK_FRAME(priv->container), GTK_SHADOW_NONE);
// Set the name for this widget so it can be easily manipulated with css
gtk_widget_set_name (GTK_WIDGET(priv->container), "gnc-id-report-page");
gtk_container_add(GTK_CONTAINER(priv->container),
gnc_html_get_widget(priv->html));
priv->component_manager_id =
gnc_register_gui_component(WINDOW_REPORT_CM_CLASS, nullptr,
close_handler, page);
gnc_gui_component_set_session(priv->component_manager_id,
gnc_get_current_session());
gnc_html_set_urltype_cb(priv->html, gnc_plugin_page_report_check_urltype);
gnc_html_set_load_cb(priv->html, gnc_plugin_page_report_load_cb, report);
/* We need to call the load call back so the report appears to have been run
so it will get saved properly if the report is not realized in session */
id_name = g_strdup_printf("id=%d", priv->reportId );
child_name = gnc_build_url( URL_TYPE_REPORT, id_name, nullptr );
type = gnc_html_parse_url( priv->html, child_name, &url_location, &url_label);
gnc_plugin_page_report_load_cb (priv->html, type, id_name, url_label, report);
g_free(id_name);
g_free(child_name);
g_free (url_label);
g_free (url_location);
// FIXME. This is f^-1(f(x)), isn't it?
DEBUG( "id=%d", priv->reportId );
g_signal_connect (G_OBJECT(page), "inserted",
G_CALLBACK(gnc_plugin_page_inserted_cb),
nullptr);
// used to capture Ctrl+Alt+PgUp/Down for tab selection
webview = gnc_html_get_webview (priv->html);
if (webview)
{
gtk_widget_add_events (webview, gtk_widget_get_events (webview) |
GDK_KEY_PRESS_MASK);
g_signal_connect (webview, "key-press-event",
G_CALLBACK(webkit_key_press_event_cb),
page);
}
gtk_widget_show_all( GTK_WIDGET(priv->container) );
LEAVE("container %p", priv->container);
return GTK_WIDGET( priv->container );
}
/********************************************************************
* gnc_plugin_page_report_check_urltype
* is it OK to show a certain URLType in this window?
********************************************************************/
static int
gnc_plugin_page_report_check_urltype(URLType t)
{
if (!g_strcmp0 (t, URL_TYPE_REPORT))
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
* Simply get the initial report given the id, so we can do initialization
* things like setup the tab name based on the report's name.
**/
static void
gnc_plugin_page_report_setup( GncPluginPage *ppage )
{
GncPluginPageReport *report = GNC_PLUGIN_PAGE_REPORT(ppage);
GncPluginPageReportPrivate *priv;
SCM set_needs_save = scm_c_eval_string("gnc:report-set-needs-save?!");
SCM inst_report;
int report_id;
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
priv->cur_report = SCM_BOOL_F;
priv->initial_report = SCM_BOOL_F;
priv->edited_reports = SCM_EOL;
priv->name_change_cb_id = 0;
g_object_get( ppage, "report-id", &report_id, nullptr );
PINFO("report-id: %d\n", report_id);
/* get the inst-report from the Scheme-side hash, and get its
* options and editor thunk */
if ((inst_report = gnc_report_find(report_id)) == SCM_BOOL_F)
{
return;
}
if (priv->initial_report == SCM_BOOL_F)
{
priv->initial_report = inst_report;
scm_gc_protect_object(priv->initial_report);
}
// all reports need [to be] saved immediately after they're created.
PINFO("set needs save");
scm_call_2(set_needs_save, inst_report, SCM_BOOL_T);
}
/********************************************************************
* gnc_plugin_page_report_load_cb
* called after a report is loaded into the gnc_html widget
********************************************************************/
static void
gnc_plugin_page_report_load_cb (GncHtml * html, URLType type,
const gchar * location, const gchar * label,
gpointer data)
{
GncPluginPageReport *report = GNC_PLUGIN_PAGE_REPORT(data);
GncPluginPageReportPrivate *priv;
int report_id;
SCM set_needs_save = scm_c_eval_string("gnc:report-set-needs-save?!");
SCM inst_report;
ENTER( "load_cb: type=[%s], location=[%s], label=[%s]",
type ? type : "(null)", location ? location : "(null)",
label ? label : "(null)" );
/* we get this callback if a new report is requested to be loaded OR
* if any URL is clicked. If an options URL is clicked, we want to
* know about it */
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
if (!g_strcmp0 (type, URL_TYPE_REPORT)
&& location
&& (strlen(location) > 3)
&& !strncmp("id=", location, 3))
{
report_id = atoi(location + 3);
DEBUG( "parsed id=%d", report_id );
}
else if (!g_strcmp0( type, URL_TYPE_OPTIONS)
&& location
&& (strlen(location) > 10)
&& !strncmp("report-id=", location, 10))
{
report_id = atoi(location + 10);
inst_report = gnc_report_find(report_id);
if (inst_report != SCM_BOOL_F)
{
gnc_plugin_page_report_add_edited_report(priv, inst_report);
}
LEAVE("");
return;
}
else
{
LEAVE( " unknown URL type [%s] location [%s]", type, location );
return;
}
/* get the inst-report from the hash, and get its
* options and editor thunk */
if ((inst_report = gnc_report_find(report_id)) == SCM_BOOL_F)
{
LEAVE( "error getting inst_report" );
return;
}
if (priv->initial_report == SCM_BOOL_F)
{
priv->initial_report = inst_report;
scm_gc_protect_object(priv->initial_report);
DEBUG("calling set_needs_save for report with id=%d", report_id);
scm_call_2(set_needs_save, inst_report, SCM_BOOL_T);
priv->initial_odb = gnc_get_report_optiondb(inst_report);
priv->name_change_cb_id =
priv->initial_odb->register_callback(
gnc_plugin_page_report_refresh, priv);
}
if ((priv->cur_report != SCM_BOOL_F) && (priv->cur_odb != nullptr))
{
priv->cur_odb->unregister_callback(priv->option_change_cb_id);
priv->option_change_cb_id = 0;
priv->cur_odb = nullptr;
}
if (priv->cur_report != SCM_BOOL_F)
scm_gc_unprotect_object(priv->cur_report);
priv->cur_report = inst_report;
scm_gc_protect_object(priv->cur_report);
priv->cur_odb = gnc_get_report_optiondb(inst_report);
priv->option_change_cb_id =
priv->cur_odb->register_callback(
gnc_plugin_page_report_option_change_cb, report);
if (gnc_html_history_forward_p(gnc_html_get_history(priv->html)))
{
gnc_plugin_page_report_set_fwd_button(report, TRUE);
}
else
{
gnc_plugin_page_report_set_fwd_button(report, FALSE);
}
if (gnc_html_history_back_p(gnc_html_get_history(priv->html)))
{
gnc_plugin_page_report_set_back_button(report, TRUE);
}
else
{
gnc_plugin_page_report_set_back_button(report, FALSE);
}
LEAVE( "done" );
}
/** This function is called when one of the options for a report
* page has changed. It is responsible for marking the report as
* dirty, and causing the report to reload using the new options.
*
* @note This function currently also calls the main window code to
* update it if the name of the report has changed. This code should
* eventually go away, and the only way to change the name should be
* via the main window.
*
* @param data A pointer to the GncPluginPageReport data structure
* that describes a report. */
static void
gnc_plugin_page_report_option_change_cb(gpointer data)
{
GncPluginPage *page;
GncPluginPageReport *report;
GncPluginPageReportPrivate *priv;
SCM dirty_report = scm_c_eval_string("gnc:report-set-dirty?!");
const gchar *old_name;
gchar *new_name;
g_return_if_fail(GNC_IS_PLUGIN_PAGE_REPORT(data));
report = GNC_PLUGIN_PAGE_REPORT(data);
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
page = GNC_PLUGIN_PAGE(report);
DEBUG( "option_change" );
if (priv->cur_report == SCM_BOOL_F)
return;
DEBUG( "set-dirty, queue-draw" );
/* Update the page (i.e. the notebook tab and window title) */
old_name = gnc_plugin_page_get_page_name(GNC_PLUGIN_PAGE(report));
new_name = g_strdup(gnc_option_db_lookup_string_value(priv->cur_odb,
"General",
"Report name"));
if (strcmp(old_name, new_name) != 0)
{
/* Bug 727130, 760711 - remove only the non-printable
* characters from the new name */
gnc_utf8_strip_invalid_and_controls(new_name);
ENTER("Cleaned-up new report name: %s", new_name);
main_window_update_page_name(GNC_PLUGIN_PAGE(report), new_name);
}
g_free(new_name);
/* it's probably already dirty, but make sure */
scm_call_2(dirty_report, priv->cur_report, SCM_BOOL_T);
// prevent closing this page while loading...
priv->reloading = TRUE;
// this sets the window for the progressbar
gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
// this sets the minimum size of the progressbar to that allocated
gnc_plugin_page_report_set_progressbar( page, TRUE );
/* Now queue the fact that we need to reload this report */
gnc_html_reload( priv->html, TRUE ); //reload by rebuild
gnc_plugin_page_report_set_progressbar( page, FALSE );
// this resets the window for the progressbar to nullptr
gnc_window_set_progressbar_window( nullptr );
priv->reloading = FALSE;
}
/* FIXME: This function does... nothing? */
static void
gnc_plugin_page_report_history_destroy_cb(gnc_html_history_node * node,
gpointer user_data)
{
#if 0
static SCM remover = SCM_BOOL_F;
int report_id;
if (remover == SCM_BOOL_F)
{
remover = scm_c_eval_string("gnc:report-remove-by-id");
}
if (node
&& !g_strcmp0 (node->type, URL_TYPE_REPORT)\
&& !strncmp("id=", node->location, 3))
{
sscanf(node->location + 3, "%d", &report_id);
/* printf("unreffing report %d and children\n", report_id);
scm_call_1(remover, scm_from_int (report_id)); */
}
else
{
return;
}
#endif
}
// @param data is actually GncPluginPageReportPrivate
static void
gnc_plugin_page_report_refresh(gpointer data)
{
// FIXME?
DEBUG( "report-refresh called" );
// something like ... gnc_plugin_page_report_redraw( nullptr, (GncPluginPageReportPrivate*)data );
return;
}
static void
gnc_plugin_page_report_destroy_widget(GncPluginPage *plugin_page)
{
GncPluginPageReportPrivate *priv;
// FIXME: cleanup other resources.
PINFO("destroy widget");
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(plugin_page);
// 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->component_manager_id)
{
gnc_unregister_gui_component(priv->component_manager_id);
priv->component_manager_id = 0;
}
gnc_plugin_page_report_destroy(priv);
gnc_report_remove_by_id(priv->reportId);
}
/** The key name used it the state file for storing the report
* options. */
#define SCHEME_OPTIONS "SchemeOptions"
#define SCHEME_OPTIONS_N "SchemeOptions%d"
/** Save enough information about this report 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_report_save_page (GncPluginPage *plugin_page,
GKeyFile *key_file,
const gchar *group_name)
{
GncPluginPageReport *report;
GncPluginPageReportPrivate *priv;
SCM gen_save_text, scm_text;
SCM get_embedded_list, embedded, item, tmp_report;
SCM get_options;
gint count, id;
gchar *text, *key_name;
g_return_if_fail (GNC_IS_PLUGIN_PAGE_REPORT(plugin_page));
g_return_if_fail (key_file != nullptr);
g_return_if_fail (group_name != nullptr);
ENTER("page %p, key_file %p, group_name %s", plugin_page, key_file,
group_name);
report = GNC_PLUGIN_PAGE_REPORT(plugin_page);
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
if (!priv || !priv->cur_report || scm_is_null(priv->cur_report) ||
SCM_UNBNDP(priv->cur_report) || SCM_BOOL_F == priv->cur_report)
{
LEAVE("not saving invalid report");
return;
}
gen_save_text = scm_c_eval_string("gnc:report-serialize");
get_embedded_list = scm_c_eval_string("gnc:report-embedded-list");
get_options = scm_c_eval_string("gnc:report-options");
embedded = scm_call_1(get_embedded_list, scm_call_1(get_options, priv->cur_report));
count = scm_ilength(embedded);
while (count-- > 0)
{
item = SCM_CAR(embedded);
embedded = SCM_CDR(embedded);
if (!scm_is_number(item))
continue;
id = scm_to_int (item);
tmp_report = gnc_report_find(id);
scm_text = scm_call_1(gen_save_text, tmp_report);
if (!scm_is_string (scm_text))
{
DEBUG("child report %d: nothing to save", id);
continue;
}
key_name = g_strdup_printf(SCHEME_OPTIONS_N, id);
text = gnc_scm_strip_comments(scm_text);
g_key_file_set_value(key_file, group_name, key_name, text);
g_free(text);
g_free(key_name);
}
scm_text = scm_call_1(gen_save_text, priv->cur_report);
if (!scm_is_string (scm_text))
{
LEAVE("nothing to save");
return;
}
text = gnc_scm_strip_comments(scm_text);
g_key_file_set_value(key_file, group_name, SCHEME_OPTIONS, text);
g_free(text);
LEAVE(" ");
}
/** Create a new report 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_report_recreate_page (GtkWidget *window,
GKeyFile *key_file,
const gchar *group_name)
{
GncPluginPage *page;
gchar **keys;
gsize i, num_keys;
GError *error = nullptr;
gchar *option_string;
gint report_id;
SCM scm_id, final_id = SCM_BOOL_F;
SCM report;