Rewire gnome and gnome-utils to use GncOptionDB.

pull/1191/head
John Ralls 6 years ago
parent 41e59df71f
commit 28438e3126

@ -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);

@ -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);

@ -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

@ -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);
}

@ -27,13 +27,14 @@
//#include "gnc-html.h"
#include "qof.h"
#include <gnc-optiondb.h>
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

@ -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<bool>(clear_options));
}
}
void
gnc_option_db_book_options(GncOptionDB*)

@ -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

@ -42,6 +42,12 @@
#ifdef __cplusplus
#include <glib.h> //To preempt it being included extern "C" in a later header.
class GncOptionDB;
#else
#include <option-util.h>
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

Loading…
Cancel
Save