From ea689586dea863cd6a5b2e9d3c0da1467fa14c7b Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Fri, 21 Dec 2001 07:43:12 +0000 Subject: [PATCH] * src/gnome/top-level.h: update for api changes * src/gnome/top-level.c: remove some gnome initialization & shutdown. change ui init api. * src/gnome/gw-gnc-spec.scm: update for api changes * src/gnome/argv-list-converters.h: remove * src/gnome/argv-list-converters.c: remove * src/gnome/Makefile.am: remove argv-list-converters.[ch] * src/gnome/top-level.c: take out component manager initialization and shutdown git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6408 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/gnome/Makefile.am | 3 +- src/gnome/argv-list-converters.c | 130 ------------------ src/gnome/argv-list-converters.h | 58 -------- src/gnome/gw-gnc-spec.scm | 18 +-- src/gnome/top-level.c | 224 ++----------------------------- src/gnome/top-level.h | 17 +-- 6 files changed, 28 insertions(+), 422 deletions(-) delete mode 100644 src/gnome/argv-list-converters.c delete mode 100644 src/gnome/argv-list-converters.h diff --git a/src/gnome/Makefile.am b/src/gnome/Makefile.am index 0cc03a4cf5..1dde7a518d 100644 --- a/src/gnome/Makefile.am +++ b/src/gnome/Makefile.am @@ -23,7 +23,6 @@ libgw_gnc_la_LDFLAGS = -module \ libgw_gnc_la_LIBADD = libgncgnome_la_SOURCES = \ - argv-list-converters.c \ dialog-commodities.c \ dialog-fincalc.c \ dialog-find-transactions.c \ @@ -64,7 +63,6 @@ mimedir = $(datadir)/mime-info mime_DATA = gnucash.keys gnucash.mime noinst_HEADERS = \ - argv-list-converters.h \ dialog-fincalc.h \ dialog-find-transactions.h \ dialog-new-user.h \ @@ -155,6 +153,7 @@ gw-gnc.scm gw-gnc.h gw-gnc.c gw-gnc.html: gw-gnc-spec.scm .scm-links FLAVOR=gnome guile -c \ "(set! %load-path (cons \"${G_WRAP_MODULE_DIR}\" %load-path)) \ (set! %load-path (cons \"../engine\" %load-path)) \ + (set! %load-path (cons \"../app-utils\" %load-path)) \ (set! %load-path (cons \"../gnome-utils\" %load-path)) \ (set! %load-path (cons \"../report/report-gnome\" %load-path)) \ (primitive-load \"./gw-gnc-spec.scm\") \ diff --git a/src/gnome/argv-list-converters.c b/src/gnome/argv-list-converters.c deleted file mode 100644 index 7729a6ebb0..0000000000 --- a/src/gnome/argv-list-converters.c +++ /dev/null @@ -1,130 +0,0 @@ -/********************************************************************\ - * argv-list-converters.c * - * Copyright (C) 2000 Gnumatic, Inc * - * Copyright (C) 2000 James LewisMoss * - * * - * 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 * - * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * - * Boston, MA 02111-1307, USA gnu@gnu.org * -\********************************************************************/ - -#include "config.h" - -#include -#include - -#include "argv-list-converters.h" - - -char** -gnc_scheme_list_to_nulltermcharpp(int prelen, const char **prepend, SCM list) -{ - SCM next = list; - char **ret; - int len = 0; - int loc; - - if(gh_pair_p(list)) - { - int i; - len = gh_length(list) + prelen; - ret = g_new(char *, len + 1); - ret[len] = NULL; - for(i = 0; i < prelen; i++) - { - ret[i] = g_strdup(prepend[i]); - } - } - else - { - return NULL; - } - - loc = prelen; - while(gh_pair_p(next)) - { - SCM scm_string = gh_car(next); - next = gh_cdr(next); - if(gh_string_p(scm_string)) - { - char *onestr = gh_scm2newstr(scm_string, 0); - ret[loc] = g_strdup (onestr); - if (onestr) - free (onestr); - } - else - { - int i; - - for (i = 0; i < loc; i++) - g_free (ret[i]); - g_free(ret); - return NULL; - } - loc++; - } - - return ret; -} - -SCM -gnc_argvarr_to_scheme_list(int argc, const char** argv) -{ - int i; - SCM ret = SCM_EOL; - - for(i = 0; i < argc; i++) - { - /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ - ret = gh_cons(gh_str02scm((char *) argv[i]), ret); - } - - return gh_reverse(ret); -} - -void -gnc_free_argv(char** argv) -{ - char **now = argv; - - if(!argv) - { - return; - } - - while(*now != 0) - { - g_free(*now); - now++; - } - g_free(argv); -} - -int -argv_length(char** nulltermlist) -{ - int ret = 0; - - if(!nulltermlist) - { - return 0; - } - - while(nulltermlist[ret] != 0) - ret++; - return ret; -} - diff --git a/src/gnome/argv-list-converters.h b/src/gnome/argv-list-converters.h deleted file mode 100644 index e0ddcea45f..0000000000 --- a/src/gnome/argv-list-converters.h +++ /dev/null @@ -1,58 +0,0 @@ -/********************************************************************\ - * argv-list-converters.h * - * Copyright (C) 2000 Gnumatic, Inc * - * Copyright (C) 2000 James LewisMoss * - * * - * 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 * - * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * - * Boston, MA 02111-1307, USA gnu@gnu.org * -\********************************************************************/ - -#ifndef ARGV_LIST_CONVERTERS_H -#define ARGV_LIST_CONVERTERS_H - - -/* - * This function takes a SCM value. Determines whether it is a list - * and whether that list contains only strings and returns a null - * terminated array of strings (char*'s) - */ -char** gnc_scheme_list_to_nulltermcharpp(int prelen, const char **prepend, - SCM list); - - -/* - * This function takes a length and char** and makes a scheme list - * with similar contents - */ -SCM gnc_argvarr_to_scheme_list(int argc, const char** argv); - -/* - * Frees the strings and the argv array - */ -void gnc_free_argv(char** argv); - -/* - * print out the argv array in a nice manner - */ -void print_argv(char **argv); - -/* - * get the length of null terminated char* array - */ -int argv_length(char** nulltermlist); - -#endif diff --git a/src/gnome/gw-gnc-spec.scm b/src/gnome/gw-gnc-spec.scm index b468331b37..6749245a8b 100644 --- a/src/gnome/gw-gnc-spec.scm +++ b/src/gnome/gw-gnc-spec.scm @@ -111,25 +111,25 @@ (gw:wrap-function mod - 'gnc:ui-init - ' - "gnucash_ui_init" - '() - "Initialize the lower level ui parts.") + 'gnc:gui-init + ' + "gnc_gui_init" + '(( command-line)) + "Initialize the lower level ui parts. Returns remaining command line.") (gw:wrap-function mod - 'gnc:ui-shutdown + 'gnc:gui-shutdown ' - "gnc_ui_shutdown" + "gnc_gui_shutdown" '() "Shutdown the UI.") (gw:wrap-function mod - 'gnc:ui-destroy + 'gnc:gui-destroy ' - "gnc_ui_destroy" + "gnc_gui_destroy" '() "Destroy the UI.") diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index 3f9ba2016b..c36e9439e8 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -28,15 +28,11 @@ #include #include #include -#ifdef GTKHTML_HAVE_GCONF -#include -#endif #include #include #include "AccWindow.h" #include "TransLog.h" -#include "argv-list-converters.h" #include "combocell.h" #include "date.h" #include "dialog-commodity.h" @@ -51,10 +47,8 @@ #include "gnc-menu-extensions.h" #include "gnc-network.h" #include "gnc-splash.h" -#ifdef USE_GUPPI -#include "gnc-html-guppi.h" -#endif #include "gnc-html.h" +#include "gnc-gnome-utils.h" #include "gnc-gpg.h" #include "gnc-report.h" #include "gnc-ui.h" @@ -126,52 +120,12 @@ gnucash_ui_is_terminating(void) return gnome_is_terminating; } -static const char* gnc_scheme_remaining_var = "gnc:*command-line-remaining*"; - -static char** -gnc_get_remaining_argv(int prelen, const char **prependargv) -{ - /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ - SCM rem = gh_eval_str ((char *) gnc_scheme_remaining_var); - return gnc_scheme_list_to_nulltermcharpp (prelen, prependargv, rem); -} - -static void -gnc_set_remaining_argv(int len, const char **rest) -{ - SCM toput = gnc_argvarr_to_scheme_list(len, rest); - /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ - gh_define((char *) gnc_scheme_remaining_var, toput); -} - - static void gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat) { helpWindow (NULL, NULL, HH_GLOBPREFS); } -static gboolean -gnc_html_file_stream_cb (const char *location, char ** data) -{ - return (gncReadFile (location, data) > 0); -} - -static gboolean -gnc_html_report_stream_cb (const char *location, char ** data) -{ - gboolean ok; - - ok = gnc_run_report_id_string (location, data); - - if (!ok) - *data = g_strdup (_("

Report error

" - "

An error occurred while running the report.

" - "")); - - return ok; -} - static gboolean gnc_html_register_url_cb (const char *location, const char *label, gboolean new_window, GNCURLResult *result) @@ -274,102 +228,6 @@ gnc_html_register_url_cb (const char *location, const char *label, return TRUE; } -static gboolean -gnc_html_report_url_cb (const char *location, const char *label, - gboolean new_window, GNCURLResult *result) -{ - g_return_val_if_fail (location != NULL, FALSE); - g_return_val_if_fail (result != NULL, FALSE); - - /* make a new window if necessary */ - if (new_window) - { - char *url; - - url = gnc_build_url (URL_TYPE_REPORT, location, label); - gnc_main_window_open_report_url (url, FALSE); - g_free (url); - - result->load_to_stream = FALSE; - } - else - { - result->load_to_stream = TRUE; - } - - return TRUE; -} - -static gboolean -gnc_html_options_url_cb (const char *location, const char *label, - gboolean new_window, GNCURLResult *result) -{ - SCM find_report = gh_eval_str ("gnc:find-report"); - SCM start_editor = gh_eval_str ("gnc:report-edit-options"); - SCM report; - int report_id; - - g_return_val_if_fail (location != NULL, FALSE); - g_return_val_if_fail (result != NULL, FALSE); - - result->load_to_stream = FALSE; - - /* href="gnc-options:report-id=2676" */ - if (strncmp ("report-id=", location, 10) == 0) - { - if (sscanf (location + 10, "%d", &report_id) != 1) - { - result->error_message = - g_strdup_printf (_("Badly formed options URL: %s"), location); - - return FALSE; - } - - report = gh_call1 (find_report, gh_int2scm (report_id)); - if (report == SCM_UNDEFINED || - report == SCM_BOOL_F) - { - result->error_message = - g_strdup_printf (_("Badly report id: %s"), location); - - return FALSE; - } - - gh_call1 (start_editor, report); - - return TRUE; - } - else - { - result->error_message = - g_strdup_printf (_("Badly formed options URL: %s"), location); - - return FALSE; - } -} - -static gboolean -gnc_html_help_url_cb (const char *location, const char *label, - gboolean new_window, GNCURLResult *result) -{ - g_return_val_if_fail (location != NULL, FALSE); - g_return_val_if_fail (result != NULL, FALSE); - - if (new_window) - { - gnc_help_window * help; - - help = gnc_help_window_new (); - gnc_help_window_show_help (help, location, label); - - result->load_to_stream = FALSE; - } - else - result->load_to_stream = TRUE; - - return TRUE; -} - static void gnc_commodity_help_cb (void) { @@ -378,75 +236,21 @@ gnc_commodity_help_cb (void) /* ============================================================== */ -/* These gnucash_ui_init and gnucash_ui functions are just hacks to get - the guile stuff up and running. Expect a more formal definition of - what they should do soon, and expect that the open/select functions - will be merged with the code in FMB_OPEN in MainWindow.c */ - -static const char *default_argv[] = {"gnucash", 0}; - -static const struct poptOption nullPoptTable[] = { - { NULL, 0, 0, NULL, 0 } -}; - -int -gnucash_ui_init(void) +SCM +gnc_gui_init (SCM command_line) { - int restargc; - char **restargv; - char **restargv2; - poptContext returnedPoptContext; - -#ifdef GTKHTML_HAVE_GCONF - GError *gerror; -#endif + SCM ret = command_line; ENTER (" "); - /* We're going to have to have other ways to handle X and GUI - specific args... */ if (!gnome_is_initialized) { - restargv = gnc_get_remaining_argv(1, default_argv); - if(restargv == NULL) - { - restargv = g_new(char*, 2); - restargv[0] = g_strdup(default_argv[0]); - restargv[1] = NULL; - } - - restargc = argv_length(restargv); - - gnome_init_with_popt_table("GnuCash", VERSION, restargc, restargv, - nullPoptTable, 0, &returnedPoptContext); + ret = gnc_gnome_init ("gnucash", "GnuCash", VERSION, command_line); gnome_is_initialized = TRUE; - restargv2 = (char**)poptGetArgs(returnedPoptContext); - gnc_set_remaining_argv(argv_length(restargv2), (const char**)restargv2); - -#ifdef GTKHTML_HAVE_GCONF - if( !gconf_init(restargc, restargv, &gerror) ) - g_error_free(gerror); - gerror = NULL; -#endif - - /* this must come after using the poptGetArgs return value */ - poptFreeContext (returnedPoptContext); - gnc_free_argv (restargv); - - /* initialization required for gtkhtml */ - gdk_rgb_init (); - gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); - gtk_widget_set_default_visual (gdk_rgb_get_visual ()); - /* load default HTML action handlers */ gnc_network_init(); -#ifdef USE_GUPPI - /* initialize guppi handling in gnc-html */ - gnc_html_guppi_init(); -#endif - /* put up splash screen */ gnc_show_splash_screen (); @@ -512,16 +316,8 @@ gnucash_ui_init(void) gnucash_style_init(); gnucash_color_init(); - gnc_html_register_stream_handler (URL_TYPE_HELP, gnc_html_file_stream_cb); - gnc_html_register_stream_handler (URL_TYPE_FILE, gnc_html_file_stream_cb); - gnc_html_register_stream_handler (URL_TYPE_REPORT, - gnc_html_report_stream_cb); - gnc_html_register_url_handler (URL_TYPE_REGISTER, gnc_html_register_url_cb); - gnc_html_register_url_handler (URL_TYPE_REPORT, gnc_html_report_url_cb); - gnc_html_register_url_handler (URL_TYPE_OPTIONS, gnc_html_options_url_cb); - gnc_html_register_url_handler (URL_TYPE_HELP, gnc_html_help_url_cb); gnc_ui_commodity_set_help_callback (gnc_commodity_help_cb); @@ -543,13 +339,13 @@ gnucash_ui_init(void) LEAVE (" "); - return 0; + return ret; } /* ============================================================== */ void -gnc_ui_shutdown (void) +gnc_gui_shutdown (void) { if (gnome_is_running && !gnome_is_terminating) { @@ -557,16 +353,14 @@ gnc_ui_shutdown (void) gtk_main_quit(); -#ifdef USE_GUPPI - gnc_html_guppi_shutdown(); -#endif + gnc_gnome_shutdown (); } } /* ============================================================== */ void -gnc_ui_destroy (void) +gnc_gui_destroy (void) { if (!gnome_is_initialized) return; diff --git a/src/gnome/top-level.h b/src/gnome/top-level.h index d1fbbcf11b..b14ad8f762 100644 --- a/src/gnome/top-level.h +++ b/src/gnome/top-level.h @@ -24,16 +24,17 @@ #define TOP_LEVEL_H #include +#include #include "window-main.h" -gboolean gnucash_ui_is_running(void); -gboolean gnucash_ui_is_terminating(void); -int gnucash_ui_init(void); -void gnc_ui_shutdown(void); -void gnc_ui_destroy(void); -int gnc_ui_start_event_loop(void); -gboolean gnc_reverse_balance_type(GNCAccountType type); -gboolean gnc_reverse_balance(Account *account); +gboolean gnucash_ui_is_running (void); +gboolean gnucash_ui_is_terminating (void); +SCM gnc_gui_init (SCM command_line); +void gnc_gui_shutdown (void); +void gnc_gui_destroy (void); +int gnc_ui_start_event_loop (void); +gboolean gnc_reverse_balance_type (GNCAccountType type); +gboolean gnc_reverse_balance (Account *account); #endif