From 0622d2bc069f320b4894bfd71b155538f4d7c73e Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Mon, 29 Oct 2001 08:14:42 +0000 Subject: [PATCH] Untable app-file and app-file-gnome dependencies. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5738 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-file/gnc-file-p.h | 12 +++- src/app-file/gnc-file.c | 42 ++++++++++-- src/app-file/gnome/.cvsignore | 5 ++ src/app-file/gnome/Makefile.am | 31 ++++++++- src/app-file/gnome/gncmod-app-file-gnome.c | 32 +++++++-- src/app-file/gnome/gw-app-file-gnome-spec.scm | 67 +++++++++++++++++++ src/app-file/gw-app-file-spec.scm | 23 +------ 7 files changed, 180 insertions(+), 32 deletions(-) create mode 100644 src/app-file/gnome/gw-app-file-gnome-spec.scm diff --git a/src/app-file/gnc-file-p.h b/src/app-file/gnc-file-p.h index d5b98976ef..3121d811a1 100644 --- a/src/app-file/gnc-file-p.h +++ b/src/app-file/gnc-file-p.h @@ -24,5 +24,15 @@ void gnc_file_init (void); -#endif +typedef void (*GNCHistoryAddFileFunc) (const char *filename); +typedef const char * (*GNCHistoryGetLastFunc) (void); +typedef const char * (*GNCFileDialogFunc) (const char * title, + const char * filter, + const char * default_name); + +void gnc_file_set_handlers (GNCHistoryAddFileFunc history_add_file_func, + GNCHistoryGetLastFunc history_get_last_func, + GNCFileDialogFunc file_dialog_func); + +#endif diff --git a/src/app-file/gnc-file.c b/src/app-file/gnc-file.c index f93f6858ac..d7ec13d260 100644 --- a/src/app-file/gnc-file.c +++ b/src/app-file/gnc-file.c @@ -50,6 +50,21 @@ static short module = MOD_GUI; static GNCSession * current_session = NULL; static GNCCanCancelSaveCB can_cancel_cb = NULL; +static GNCHistoryAddFileFunc history_add_file_func = NULL; +static GNCHistoryGetLastFunc history_get_last_func = NULL; + +static GNCFileDialogFunc file_dialog_func = NULL; + + +void +gnc_file_set_handlers (GNCHistoryAddFileFunc history_add_file_func_in, + GNCHistoryGetLastFunc history_get_last_func_in, + GNCFileDialogFunc file_dialog_func_in) +{ + history_add_file_func = history_add_file_func_in; + history_get_last_func = history_get_last_func_in; + file_dialog_func = file_dialog_func_in; +} static GNCSession * gnc_get_current_session_internal (void) @@ -223,17 +238,21 @@ static void gnc_add_history (GNCSession * session) { char *url; + char *file; if (!session) return; + if (!history_add_file_func) return; url = xaccResolveURL (gnc_session_get_url (session)); if (!url) return; if (strncmp (url, "file:", 5) == 0) - gnc_history_add_file (url + 5); + file = url + 5; else - gnc_history_add_file (url); + file = url; + + history_add_file_func (file); g_free (url); } @@ -477,12 +496,20 @@ gboolean gnc_file_open (void) { const char * newfile; + const char * last; gboolean result; if (!gnc_file_query_save ()) return FALSE; - newfile = gnc_file_dialog (_("Open"), NULL, gnc_history_get_last ()); + if (!file_dialog_func) + { + PWARN ("no file dialog function"); + return FALSE; + } + + last = history_get_last_func ? history_get_last_func () : NULL; + newfile = file_dialog_func (_("Open"), NULL, last); result = gnc_post_file_open (newfile); /* This dialogue can show up early in the startup process. If the @@ -570,7 +597,14 @@ gnc_file_save_as (void) GNCBackendError io_err = ERR_BACKEND_NO_ERR; ENTER(" "); - filename = gnc_file_dialog (_("Save"), "*.gnc", NULL); + + if (!file_dialog_func) + { + PWARN ("no file dialog func"); + return; + } + + filename = file_dialog_func (_("Save"), "*.gnc", NULL); if (!filename) return; /* Check to see if the user specified the same file as the current diff --git a/src/app-file/gnome/.cvsignore b/src/app-file/gnome/.cvsignore index 0d0371d7dc..70d6bd08dd 100644 --- a/src/app-file/gnome/.cvsignore +++ b/src/app-file/gnome/.cvsignore @@ -4,3 +4,8 @@ Makefile.in *.la .deps .libs +.scm-links +gw-app-file-gnome.c +gw-app-file-gnome.scm +gw-app-file-gnome.h +gw-app-file-gnome.html diff --git a/src/app-file/gnome/Makefile.am b/src/app-file/gnome/Makefile.am index e073c36c18..f04aea78cc 100644 --- a/src/app-file/gnome/Makefile.am +++ b/src/app-file/gnome/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = . #test -pkglib_LTLIBRARIES = libgncmod-app-file-gnome.la +pkglib_LTLIBRARIES = libgncmod-app-file-gnome.la libgw-app-file-gnome.la AM_CFLAGS = \ -I${top_srcdir}/src/gnc-module \ @@ -32,3 +32,32 @@ libgncmod_app_file_gnome_la_LIBADD = \ ${GNOMEUI_LIBS} \ ${GNOME_LIBDIR} \ ${GLIB_LIBS} + +libgw_app_file_gnome_la_SOURCES = gw-app-file-gnome.c +libgw_app_file_gnome_la_LDFLAGS = -module + +gwmoddir = ${GNC_GWRAP_LIBDIR} +gwmod_DATA = gw-app-file-gnome-spec.scm gw-app-file-gnome.scm + +noinst_DATA = .scm-links + +EXTRA_DIST = \ + ${gwmod_DATA} + +.scm-links: + rm -f gnucash g-wrapped + ln -sf . gnucash + ln -sf . g-wrapped + touch .scm-links + +gw-app-file-gnome.scm gw-app-file-gnome.c gw-app-file-gnome.h: .scm-links gw-app-file-gnome-spec.scm + FLAVOR=gnome guile -c \ + "(set! %load-path (cons \"${G_WRAP_MODULE_DIR}\" %load-path)) \ + (set! %load-path (cons \"${PWD}\" %load-path)) \ + (set! %load-path (cons \"${top_srcdir}/src/engine\" %load-path)) \ + (primitive-load \"./gw-app-file-gnome-spec.scm\") \ + (gw:generate-module \"gw-app-file-gnome\")" + +BUILT_SOURCES = gw-app-file-gnome.scm gw-app-file-gnome.c gw-app-file-gnome.h +CLEANFILES = gw-app-file-gnome.scm gw-app-file-gnome.c gw-app-file-gnome.h \ + gw-app-file-gnome.html gnucash g-wrapped .scm-links diff --git a/src/app-file/gnome/gncmod-app-file-gnome.c b/src/app-file/gnome/gncmod-app-file-gnome.c index 488623dbe4..702ae29e5d 100644 --- a/src/app-file/gnome/gncmod-app-file-gnome.c +++ b/src/app-file/gnome/gncmod-app-file-gnome.c @@ -11,7 +11,9 @@ #include #include +#include "gnc-file-dialog.h" #include "gnc-file-p.h" +#include "gnc-file-history.h" #include "gnc-module.h" #include "gnc-module-api.h" @@ -24,26 +26,48 @@ int gnc_module_revision = 0; int gnc_module_age = 0; char * -gnc_module_path(void) { +gnc_module_path(void) +{ return g_strdup("gnucash/app-file/gnome"); } char * -gnc_module_description(void) { +gnc_module_description(void) +{ return g_strdup("Application level file interface for Gnome"); } +static void +lmod(char * mn) +{ + char * form = g_strdup_printf("(use-modules %s)\n", mn); + gh_eval_str(form); + g_free(form); +} + int -gnc_module_init(int refcount) { +gnc_module_init(int refcount) +{ /* load the calculation module (we depend on it) */ if(!gnc_module_load("gnucash/app-file", 0)) { return FALSE; } + lmod ("(g-wrapped gw-app-file-gnome)"); + + if (refcount == 0) + gnc_file_set_handlers (gnc_history_add_file, + gnc_history_get_last, + gnc_file_dialog); + return TRUE; } int -gnc_module_end(int refcount) { +gnc_module_end(int refcount) +{ + if (refcount == 0) + gnc_file_set_handlers (NULL, NULL, NULL); + return TRUE; } diff --git a/src/app-file/gnome/gw-app-file-gnome-spec.scm b/src/app-file/gnome/gw-app-file-gnome-spec.scm new file mode 100644 index 0000000000..54c069cbbb --- /dev/null +++ b/src/app-file/gnome/gw-app-file-gnome-spec.scm @@ -0,0 +1,67 @@ +;;; -*-scheme-*- +(use-modules (g-wrap)) + +(debug-set! maxdepth 100000) +(debug-set! stack 2000000) + +(define-module (g-wrapped gw-app-file-gnome-spec) + :use-module (g-wrap)) + +(use-modules (g-wrapped gw-engine-spec)) +(use-modules (g-wrapped gw-glib-spec)) + +(let ((mod (gw:new-module "gw-app-file-gnome"))) + (define (standard-c-call-gen result func-call-code) + (list (gw:result-get-c-name result) " = " func-call-code ";\n")) + + (define (add-standard-result-handlers! type c->scm-converter) + (define (standard-pre-handler result) + (let* ((ret-type-name (gw:result-get-proper-c-type-name result)) + (ret-var-name (gw:result-get-c-name result))) + (list "{\n" + " " ret-type-name " " ret-var-name ";\n"))) + + (gw:type-set-pre-call-result-ccodegen! type standard-pre-handler) + + (gw:type-set-post-call-result-ccodegen! + type + (lambda (result) + (let* ((scm-name (gw:result-get-scm-name result)) + (c-name (gw:result-get-c-name result))) + (list + (c->scm-converter scm-name c-name) + " }\n"))))) + + (gw:module-depends-on mod "gw-runtime") + (gw:module-depends-on mod "gw-engine") + (gw:module-depends-on mod "gw-glib") + + (gw:module-set-guile-module! mod '(g-wrapped gw-app-file-gnome)) + + (gw:module-set-declarations-ccodegen! + mod + (lambda (client-only?) + (list + "#include \n" + "#include \n"))) + + + (gw:wrap-function + mod + 'gnc:history-get-last + '( gw:const) + "gnc_history_get_last" + '() + "Get the last file opened by the user.") + + (gw:wrap-function + mod + 'gnc:file-selection-dialog + '( gw:const) + "gnc_file_dialog" + '((( gw:const) title) + (( gw:const) filter) + (( gw:const) default)) + "Lets the user select a file. Dialog has given title, filter, +or default name. Either filter, default, or both should be NULL.") + ) diff --git a/src/app-file/gw-app-file-spec.scm b/src/app-file/gw-app-file-spec.scm index 77273da28f..4e75555f03 100644 --- a/src/app-file/gw-app-file-spec.scm +++ b/src/app-file/gw-app-file-spec.scm @@ -42,9 +42,7 @@ mod (lambda (client-only?) (list - "#include \n" - "#include \n" - "#include \n"))) + "#include \n"))) (gw:wrap-function @@ -71,23 +69,4 @@ if they say 'Yes'. The return is false if the user says 'Cancel'.") "gnc_file_open_file" '((( gw:const) filename)) "Open filename.") - - (gw:wrap-function - mod - 'gnc:history-get-last - '( gw:const) - "gnc_history_get_last" - '() - "Get the last file opened by the user.") - - (gw:wrap-function - mod - 'gnc:file-selection-dialog - '( gw:const) - "gnc_file_dialog" - '((( gw:const) title) - (( gw:const) filter) - (( gw:const) default)) - "Lets the user select a file. Dialog has given title, filter, -or default name. Either filter, default, or both should be NULL.") )