From 28438e312632aa7b490b33d59da1ddbb14718ac6 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 4 Apr 2020 14:26:49 -0700 Subject: [PATCH] Rewire gnome and gnome-utils to use GncOptionDB. --- gnucash/gnome/assistant-hierarchy.c | 7 ++-- gnucash/gnome/dialog-report-style-sheet.c | 14 +++---- gnucash/gnome/gnc-plugin-page-report.c | 49 ++++++++++++----------- gnucash/gnome/window-report.c | 26 ++++++------ gnucash/gnome/window-report.h | 3 +- libgnucash/app-utils/gnc-optiondb.cpp | 5 +-- libgnucash/engine/qofbook.cpp | 6 +-- libgnucash/engine/qofbook.h | 35 ++++++++-------- 8 files changed, 74 insertions(+), 71 deletions(-) diff --git a/gnucash/gnome/assistant-hierarchy.c b/gnucash/gnome/assistant-hierarchy.c index 5d07d85dec..4682477ec6 100644 --- a/gnucash/gnome/assistant-hierarchy.c +++ b/gnucash/gnome/assistant-hierarchy.c @@ -119,7 +119,7 @@ typedef struct gboolean use_defaults; gboolean new_book; /* presumably only used for new book creation but we check*/ - GNCOptionDB *options; + GncOptionDB *options; GNCOptionWin *optionwin; GncHierarchyAssistantFinishedCallback when_completed; @@ -1503,7 +1503,7 @@ static void book_options_dialog_close_cb(GNCOptionWin * optionwin, gpointer user_data) { - GNCOptionDB * options = user_data; + GncOptionDB * options = user_data; gnc_options_dialog_destroy(optionwin); gnc_option_db_destroy(options); @@ -1516,7 +1516,8 @@ assistant_insert_book_options_page (hierarchy_data *data) GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_set_homogeneous (GTK_BOX (vbox), FALSE); - data->options = gnc_option_db_new_for_type (QOF_ID_BOOK); + data->options = gnc_option_db_new(); + gnc_option_db_book_options(data->options); qof_book_load_options (gnc_get_current_book (), gnc_option_db_load, data->options); gnc_option_db_clean (data->options); diff --git a/gnucash/gnome/dialog-report-style-sheet.c b/gnucash/gnome/dialog-report-style-sheet.c index 1df072a859..a9c5d84151 100644 --- a/gnucash/gnome/dialog-report-style-sheet.c +++ b/gnucash/gnome/dialog-report-style-sheet.c @@ -55,10 +55,10 @@ struct _stylesheetdialog typedef struct ss_info { - GNCOptionWin * odialog; - GNCOptionDB * odb; - SCM stylesheet; - GtkTreeRowReference * row_ref; + GNCOptionWin * odialog; + GncOptionDB * odb; + SCM stylesheet; + GtkTreeRowReference *row_ref; } ss_info; enum @@ -169,9 +169,9 @@ gnc_style_sheet_dialog_create (StyleSheetDialog * ss, gchar * title; GtkWindow * parent = GTK_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET(ss->list_view))); - title = g_strdup_printf (_("HTML Style Sheet Properties: %s"), name); - ssinfo->odialog = gnc_options_dialog_new (title, parent); - ssinfo->odb = gnc_option_db_new (scm_options); + title = g_strdup_printf(_("HTML Style Sheet Properties: %s"), name); + ssinfo->odialog = gnc_options_dialog_new(title, parent); + ssinfo->odb = (GncOptionDB *)scm_to_pointer(scm_options); ssinfo->stylesheet = sheet_info; ssinfo->row_ref = row_ref; g_free (title); diff --git a/gnucash/gnome/gnc-plugin-page-report.c b/gnucash/gnome/gnc-plugin-page-report.c index 3c5f4104c6..bd1e5f40bc 100644 --- a/gnucash/gnome/gnc-plugin-page-report.c +++ b/gnucash/gnome/gnc-plugin-page-report.c @@ -105,14 +105,14 @@ typedef struct GncPluginPageReportPrivate /// The report which this Page is satisfying SCM cur_report; /// The Option DB for this report. - GNCOptionDB *cur_odb; + GncOptionDB *cur_odb; SCM option_change_cb_id; /* 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; + GncOptionDB * initial_odb; SCM name_change_cb_id; /* keep a list of edited reports so that we can destroy them when @@ -648,18 +648,23 @@ gnc_plugin_page_report_load_cb(GncHtml * html, URLType type, 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_option_db_new(scm_call_1(get_options, inst_report)); + priv->initial_odb = + (GncOptionDB *)scm_to_pointer(scm_call_1(get_options, inst_report)); +/* priv->name_change_cb_id = gnc_option_db_register_change_callback(priv->initial_odb, gnc_plugin_page_report_refresh, priv, "General", "Report name"); +*/ } if ((priv->cur_report != SCM_BOOL_F) && (priv->cur_odb != NULL)) { +/* gnc_option_db_unregister_change_callback_id(priv->cur_odb, priv->option_change_cb_id); +*/ gnc_option_db_destroy(priv->cur_odb); priv->cur_odb = NULL; } @@ -669,12 +674,14 @@ gnc_plugin_page_report_load_cb(GncHtml * html, URLType type, priv->cur_report = inst_report; scm_gc_protect_object(priv->cur_report); - priv->cur_odb = gnc_option_db_new(scm_call_1(get_options, inst_report)); + priv->cur_odb = (GncOptionDB *)scm_to_pointer(scm_call_1(get_options, + inst_report)); +/* priv->option_change_cb_id = gnc_option_db_register_change_callback(priv->cur_odb, gnc_plugin_page_report_option_change_cb, report, NULL, NULL); - +*/ if (gnc_html_history_forward_p(gnc_html_get_history(priv->html))) { gnc_plugin_page_report_set_fwd_button(report, TRUE); @@ -730,8 +737,9 @@ gnc_plugin_page_report_option_change_cb(gpointer data) /* 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 = gnc_option_db_lookup_string_option(priv->cur_odb, "General", - "Report name", NULL); + 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 @@ -1033,8 +1041,8 @@ gnc_plugin_page_report_name_changed (GncPluginPage *page, const gchar *name) priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(page); /* Is this a redundant call? */ - old_name = gnc_option_db_lookup_string_option(priv->cur_odb, "General", - "Report name", NULL); + old_name = gnc_option_db_lookup_string_value(priv->cur_odb, "General", + "Report name"); DEBUG("Comparing old name '%s' to new name '%s'", old_name ? old_name : "(null)", name); if (old_name && (strcmp(old_name, name) == 0)) @@ -1044,7 +1052,7 @@ gnc_plugin_page_report_name_changed (GncPluginPage *page, const gchar *name) } /* Store the new name for the report. */ - gnc_option_db_set_string_option(priv->cur_odb, "General", + gnc_option_db_set_string_value(priv->cur_odb, "General", "Report name", name); /* Have to manually call the option change hook. */ @@ -1110,9 +1118,7 @@ gnc_plugin_page_report_destroy(GncPluginPageReportPrivate * priv) if (priv->initial_odb) { - gnc_option_db_unregister_change_callback_id(priv->initial_odb, - priv->name_change_cb_id); - +//Remove this if there's a double-free gnc_option_db_destroy(priv->initial_odb); priv->initial_odb = NULL; } @@ -1787,14 +1793,10 @@ gnc_plugin_page_report_options_cb( GtkAction *action, GncPluginPageReport *repor static GncInvoice* lookup_invoice(GncPluginPageReportPrivate *priv) { - SCM opt_val = gnc_option_db_lookup_option(priv->cur_odb, "General", - "Invoice Number", NULL); - if (opt_val == SCM_UNDEFINED) - return NULL; - -#define FUNC_NAME G_STRFUNC - return SWIG_MustGetPtr(opt_val, SWIG_TypeQuery("_p__gncInvoice"), 1, 0); -#undef FUNC_NAME + const QofInstance* opt_val = + gnc_option_db_lookup_qofinstance_value(priv->cur_odb, "General", + "Invoice Number"); + return GNC_INVOICE(opt_val); } #define GNC_PREFS_GROUP_REPORT_PDFEXPORT GNC_PREFS_GROUP_GENERAL_REPORT ".pdf-export" @@ -1849,8 +1851,9 @@ static gchar *report_create_jobname(GncPluginPageReportPrivate *priv) * so I added yet another hack below for this. cstim. */ GncInvoice *invoice; - report_name = gnc_option_db_lookup_string_option(priv->cur_odb, "General", - "Report name", NULL); + report_name = g_strdup(gnc_option_db_lookup_string_value(priv->cur_odb, + "General", + "Report name")); if (!report_name) report_name = g_strdup (_(default_jobname)); if (g_strcmp0(report_name, _("Printable Invoice")) == 0 diff --git a/gnucash/gnome/window-report.c b/gnucash/gnome/window-report.c index 31df07d5b2..25fb3f6aa0 100644 --- a/gnucash/gnome/window-report.c +++ b/gnucash/gnome/window-report.c @@ -63,8 +63,7 @@ reportWindow(int report_id, GtkWindow *parent) struct report_default_params_data { GNCOptionWin * win; - GNCOptionDB * db; - SCM scm_options; + GncOptionDB * odb; SCM cur_report; }; @@ -78,7 +77,7 @@ gnc_options_dialog_apply_cb(GNCOptionWin * propertybox, GList *results = NULL, *iter; if (!win) return; - results = gnc_option_db_commit (win->db); + results = gnc_option_db_commit (win->odb); for (iter = results; iter; iter = iter->next) { GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW (win->win), @@ -124,8 +123,7 @@ gnc_options_dialog_close_cb(GNCOptionWin * propertybox, scm_call_2(set_editor, win->cur_report, SCM_BOOL_F); gnc_options_dialog_destroy(win->win); - gnc_option_db_destroy(win->db); - scm_gc_unprotect_object(win->scm_options); + gnc_option_db_destroy(win->odb); g_free(win); } @@ -149,7 +147,7 @@ gnc_report_raise_editor(SCM report) GtkWidget * -gnc_report_window_default_params_editor(SCM options, SCM report, +gnc_report_window_default_params_editor(GncOptionDB* odb, SCM report, GtkWindow *parent) { SCM get_report_type = scm_c_eval_string("gnc:report-type"); @@ -166,9 +164,8 @@ gnc_report_window_default_params_editor(SCM options, SCM report, struct report_default_params_data * prm = g_new0(struct report_default_params_data, 1); - prm->scm_options = options; + prm->odb = odb; prm->cur_report = report; - prm->db = gnc_option_db_new(prm->scm_options); /* Get the title of the report's template. */ ptr = scm_call_1(get_report_type, report); @@ -188,11 +185,10 @@ gnc_report_window_default_params_editor(SCM options, SCM report, g_free ((gpointer *) title); - scm_gc_protect_object(prm->scm_options); scm_gc_protect_object(prm->cur_report); - gnc_options_dialog_build_contents(prm->win, prm->db); - gnc_option_db_clean(prm->db); + gnc_options_dialog_build_contents(prm->win, prm->odb); + gnc_option_db_clean(prm->odb); gnc_options_dialog_set_apply_cb(prm->win, gnc_options_dialog_apply_cb, @@ -215,6 +211,7 @@ gnc_report_edit_options(SCM report, GtkWindow *parent) SCM get_report_type = scm_c_eval_string("gnc:report-type"); SCM ptr; SCM options; + GncOptionDB* odb; GtkWidget *options_widget = NULL; /* If the options editor widget already exists we simply raise it */ @@ -229,16 +226,19 @@ gnc_report_edit_options(SCM report, GtkWindow *parent) _("There are no options for this report.")); return FALSE; } + odb = (GncOptionDB*)scm_to_pointer(options); /* Multi-column type reports need a special options dialog */ ptr = scm_call_1(get_report_type, report); if (scm_is_string(ptr)) { gchar *rpt_type = gnc_scm_to_utf8_string (ptr); +#if 0 if (g_strcmp0 (rpt_type, "d8ba4a2e89e8479ca9f6eccdeb164588") == 0) - options_widget = gnc_column_view_edit_options (options, report); + options_widget = gnc_column_view_edit_options (odb, report); else - options_widget = gnc_report_window_default_params_editor (options, report, parent); +#endif + options_widget = gnc_report_window_default_params_editor (odb, report, parent); g_free (rpt_type); } diff --git a/gnucash/gnome/window-report.h b/gnucash/gnome/window-report.h index e51bbc0a1d..17ff0195c2 100644 --- a/gnucash/gnome/window-report.h +++ b/gnucash/gnome/window-report.h @@ -27,13 +27,14 @@ //#include "gnc-html.h" #include "qof.h" +#include typedef struct gnc_report_window_s gnc_report_window; /** PROTOTYPES ******************************************************/ // scm-exposed -GtkWidget * gnc_report_window_default_params_editor(SCM options, SCM report, GtkWindow *parent); +GtkWidget * gnc_report_window_default_params_editor(GncOptionDB* odb, SCM report, GtkWindow *parent); // called from multiple places // [gnome-business/dialog-invoice.c;gnome/window-register.c]; and diff --git a/libgnucash/app-utils/gnc-optiondb.cpp b/libgnucash/app-utils/gnc-optiondb.cpp index 0aea402c7f..f0018994e3 100644 --- a/libgnucash/app-utils/gnc-optiondb.cpp +++ b/libgnucash/app-utils/gnc-optiondb.cpp @@ -897,7 +897,7 @@ gnc_register_internal_option(GncOptionDB* db, const char* section, void gnc_register_owner_option(GncOptionDB* db, const char* section, const char* name, const char* key, - const char* doc_string, GncInvoice* value) + const char* doc_string, GncOwner* value) { GncOption option{section, name, key, doc_string, (const QofInstance*)value, GncOptionUIType::INVOICE}; @@ -907,7 +907,7 @@ gnc_register_owner_option(GncOptionDB* db, const char* section, void gnc_register_invoice_option(GncOptionDB* db, const char* section, const char* name, const char* key, - const char* doc_string, GncOwner* value) + const char* doc_string, GncInvoice* value) { GncOption option{section, name, key, doc_string, (const QofInstance*)value, GncOptionUIType::OWNER}; @@ -1132,7 +1132,6 @@ gnc_option_db_save(GncOptionDB* odb, QofBook* book, { odb->save_to_kvp(book, static_cast(clear_options)); } -} void gnc_option_db_book_options(GncOptionDB*) diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp index 53873e8e94..01e32ea6c0 100644 --- a/libgnucash/engine/qofbook.cpp +++ b/libgnucash/engine/qofbook.cpp @@ -1137,14 +1137,14 @@ qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr) } void -qof_book_load_options (QofBook *book, GNCOptionLoad load_cb, GNCOptionDB *odb) +qof_book_load_options (QofBook *book, GncOptionLoad load_cb, GncOptionDB *odb) { load_cb (odb, book); } void -qof_book_save_options (QofBook *book, GNCOptionSave save_cb, - GNCOptionDB* odb, gboolean clear) +qof_book_save_options (QofBook *book, GncOptionSave save_cb, + GncOptionDB* odb, gboolean clear) { /* Wrap this in begin/commit so that it commits only once instead of doing * so for every option. Qof_book_set_option will take care of dirtying the diff --git a/libgnucash/engine/qofbook.h b/libgnucash/engine/qofbook.h index 7c0d330355..5932ecab15 100644 --- a/libgnucash/engine/qofbook.h +++ b/libgnucash/engine/qofbook.h @@ -42,6 +42,12 @@ #ifdef __cplusplus #include //To preempt it being included extern "C" in a later header. +class GncOptionDB; +#else +#include +typedef GNCOptionDB GncOptionDB; +#endif +#ifdef __cplusplus extern "C" { #endif @@ -74,15 +80,8 @@ typedef struct KvpValueImpl KvpValue; typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data); -#ifdef __cplusplus -class GncOptionDB; -using GNCOptionDB = GncOptionDB; -#else -typedef struct gnc_option_db GNCOptionDB; -#endif - -typedef void (*GNCOptionSave) (GNCOptionDB*, QofBook*, gboolean); -typedef void (*GNCOptionLoad) (GNCOptionDB*, QofBook*); +typedef void (*GncOptionSave) (GncOptionDB*, QofBook*, gboolean); +typedef void (*GncOptionLoad) (GncOptionDB*, QofBook*); /* Book structure */ struct _QofBook @@ -375,21 +374,21 @@ void qof_book_commit_edit(QofBook *book); /** @ingroup KVP @{ */ -/** Load a GNCOptionsDB from KVP data. +/** Load a GncOptionsDB from KVP data. * @param book: The book. * @param load_cb: A callback function that does the loading. - * @param odb: The GNCOptionDB to load. + * @param odb: The GncOptionDB to load. */ -void qof_book_load_options (QofBook *book, GNCOptionLoad load_cb, - GNCOptionDB *odb); -/** Save a GNCOptionsDB back to the book's KVP. +void qof_book_load_options (QofBook *book, GncOptionLoad load_cb, + GncOptionDB *odb); +/** Save a GncOptionsDB back to the book's KVP. * @param book: The book. * @param save_cb: A callback function that does the saving. - * @param odb: The GNCOptionsDB to save from. - * @param clear: Should the GNCOptionsDB be emptied after the save? + * @param odb: The GncOptionsDB to save from. + * @param clear: Should the GncOptionsDB be emptied after the save? */ -void qof_book_save_options (QofBook *book, GNCOptionSave save_cb, - GNCOptionDB* odb, gboolean clear); +void qof_book_save_options (QofBook *book, GncOptionSave save_cb, + GncOptionDB* odb, gboolean clear); /** Save a single option value. * Used from Scheme, the KvpValue<-->SCM translation is handled by the functions * in kvp-scm.c and automated by SWIG. The starting element is set as