r22650 - gnucash/trunk/src - Rewrite option dialog callback in C
Geert Janssens
gjanssens at code.gnucash.org
Sat Dec 15 12:58:28 EST 2012
Author: gjanssens
Date: 2012-12-15 12:58:27 -0500 (Sat, 15 Dec 2012)
New Revision: 22650
Trac: http://svn.gnucash.org/trac/changeset/22650
Removed:
gnucash/trunk/src/scm/main-window.scm
Modified:
gnucash/trunk/src/app-utils/option-util.c
gnucash/trunk/src/app-utils/option-util.h
gnucash/trunk/src/gnome-utils/gnc-main-window.c
gnucash/trunk/src/scm/Makefile.am
gnucash/trunk/src/scm/main.scm
Log:
Rewrite option dialog callback in C
This reduces the number of guile<->c roundtrips for the book options
dialog and eliminates the guile dependency from one more file.
Modified: gnucash/trunk/src/app-utils/option-util.c
===================================================================
--- gnucash/trunk/src/app-utils/option-util.c 2012-12-15 10:30:35 UTC (rev 22649)
+++ gnucash/trunk/src/app-utils/option-util.c 2012-12-15 17:58:27 UTC (rev 22650)
@@ -305,6 +305,42 @@
scm_call_3 (kvp_to_scm, odb->guile_options, scm_slots, kvp_option_path);
}
+
+void
+gnc_option_db_save_to_kvp(GNCOptionDB* odb, kvp_frame *slots, gboolean clear_kvp)
+{
+ static SCM scm_to_kvp = SCM_UNDEFINED;
+ static SCM kvp_option_path = SCM_UNDEFINED;
+ SCM scm_slots;
+ SCM scm_clear_kvp;
+
+ if (!odb || !slots) return;
+
+ if (scm_to_kvp == SCM_UNDEFINED)
+ {
+ scm_to_kvp = scm_c_eval_string("gnc:options-scm->kvp");
+ if (!scm_is_procedure (scm_to_kvp))
+ {
+ PERR ("not a procedure\n");
+ scm_to_kvp = SCM_UNDEFINED;
+ return;
+ }
+ }
+
+ if (kvp_option_path == SCM_UNDEFINED)
+ {
+ kvp_option_path = scm_c_eval_string("gnc:*kvp-option-path*");
+ if (kvp_option_path == SCM_UNDEFINED)
+ {
+ PERR ("can't find the option path");
+ return;
+ }
+ }
+ scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery("_p_KvpFrame"), 0);
+ scm_clear_kvp = scm_from_bool (clear_kvp);
+
+ scm_call_4 (scm_to_kvp, odb->guile_options, scm_slots, kvp_option_path, scm_clear_kvp);
+}
/********************************************************************\
* gnc_option_db_destroy *
* unregister the scheme options and free all the memory *
Modified: gnucash/trunk/src/app-utils/option-util.h
===================================================================
--- gnucash/trunk/src/app-utils/option-util.h 2012-12-15 10:30:35 UTC (rev 22649)
+++ gnucash/trunk/src/app-utils/option-util.h 2012-12-15 17:58:27 UTC (rev 22650)
@@ -72,6 +72,7 @@
*/
GNCOptionDB * gnc_option_db_new_for_type(QofIdType id_type);
void gnc_option_db_load_from_kvp(GNCOptionDB* odb, kvp_frame *slots);
+void gnc_option_db_save_to_kvp(GNCOptionDB* odb, kvp_frame *slots, gboolean clear_kvp);
void gnc_register_kvp_option_generator(QofIdType id_type, SCM generator);
SCM gnc_make_kvp_options(QofIdType id_type);
Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c 2012-12-15 10:30:35 UTC (rev 22649)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c 2012-12-15 17:58:27 UTC (rev 22650)
@@ -36,13 +36,12 @@
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
-#include <libguile.h>
-#include "guile-mappings.h"
#include "gnc-plugin.h"
#include "gnc-plugin-manager.h"
#include "gnc-main-window.h"
+#include "dialog-options.h"
#include "dialog-preferences.h"
#include "dialog-reset-warnings.h"
#include "dialog-transfer.h"
@@ -65,6 +64,7 @@
#include "gnc-window.h"
#include "gnc-main.h"
#include "gnc-gconf-utils.h"
+#include "option-util.h"
// +JSLED
//#include "gnc-html.h"
#include "gnc-autosave.h"
@@ -3754,15 +3754,49 @@
}
static void
+gnc_options_dialog_apply_cb(GNCOptionWin * optionwin,
+ gpointer user_data)
+{
+ GNCOptionDB * options = user_data;
+ kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
+
+ if (!options) return;
+
+ gnc_option_db_commit (options);
+ gnc_option_db_save_to_kvp (options, slots, TRUE);
+ qof_book_kvp_changed (gnc_get_current_book());
+}
+
+static void
+gnc_options_dialog_close_cb(GNCOptionWin * optionwin,
+ gpointer user_data)
+{
+ GNCOptionDB * options = user_data;
+
+ gnc_options_dialog_destroy(optionwin);
+ gnc_option_db_destroy(options);
+}
+
+static void
gnc_main_window_cmd_file_properties (GtkAction *action, GncMainWindow *window)
{
- SCM func = scm_c_eval_string("gnc:main-window-properties-cb");
- if (!scm_is_procedure (func))
- {
- PERR ("not a procedure\n");
- return;
- }
- scm_call_0(func);
+ kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
+ GNCOptionDB *options;
+ GNCOptionWin *optionwin;
+
+ options = gnc_option_db_new_for_type (QOF_ID_BOOK);
+ gnc_option_db_load_from_kvp (options, slots);
+ gnc_option_db_clean (options);
+
+ optionwin = gnc_options_dialog_new (_( "Book Options"));
+ gnc_options_dialog_build_contents (optionwin, options);
+
+ gnc_options_dialog_set_apply_cb (optionwin,
+ gnc_options_dialog_apply_cb,
+ (gpointer)options);
+ gnc_options_dialog_set_close_cb (optionwin,
+ gnc_options_dialog_close_cb,
+ (gpointer)options);
}
static void
Modified: gnucash/trunk/src/scm/Makefile.am
===================================================================
--- gnucash/trunk/src/scm/Makefile.am 2012-12-15 10:30:35 UTC (rev 22649)
+++ gnucash/trunk/src/scm/Makefile.am 2012-12-15 17:58:27 UTC (rev 22650)
@@ -9,7 +9,6 @@
gnc_regular_scm_files = \
string.scm \
fin.scm \
- main-window.scm \
substring-search.scm \
xml-generator.scm
Deleted: gnucash/trunk/src/scm/main-window.scm
===================================================================
--- gnucash/trunk/src/scm/main-window.scm 2012-12-15 10:30:35 UTC (rev 22649)
+++ gnucash/trunk/src/scm/main-window.scm 2012-12-15 17:58:27 UTC (rev 22650)
@@ -1,41 +0,0 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; main-window.scm : utilities for dealing with main window
-;; Copyright 2001 Bill Gribble <grib at gnumatic.com>
-;;
-;; 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 at gnu.org
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; book open and close hooks for mdi
-;;
-;; we need to save all the active report and acct tree info during
-;; book close.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
-(define (gnc:main-window-properties-cb)
- (let* ((book (gnc-get-current-book))
- (slots (qof-book-get-slots book)))
-
- (define (changed_cb)
- (qof-book-kvp-changed book))
-
- (gnc:kvp-option-dialog QOF-ID-BOOK-SCM
- slots (_ "Book Options")
- changed_cb)))
-
Modified: gnucash/trunk/src/scm/main.scm
===================================================================
--- gnucash/trunk/src/scm/main.scm 2012-12-15 10:30:35 UTC (rev 22649)
+++ gnucash/trunk/src/scm/main.scm 2012-12-15 17:58:27 UTC (rev 22650)
@@ -35,7 +35,6 @@
;; files we can load from the top-level because they're "well behaved"
;; (these should probably be in modules eventually)
(load-from-path "string.scm")
-(load-from-path "main-window.scm") ;; depends on app-utils (N_, etc.)...
(load-from-path "fin.scm")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -53,9 +52,6 @@
(re-export hash-fold)
-;; from main-window.scm
-(export gnc:main-window-properties-cb)
-
;; Get the Makefile.am/configure.in generated variables.
(load-from-path "build-config.scm")
More information about the gnucash-changes
mailing list