diff --git a/src/bin/gnucash-bin.c b/src/bin/gnucash-bin.c index 91dca1a237..1a04cc5828 100644 --- a/src/bin/gnucash-bin.c +++ b/src/bin/gnucash-bin.c @@ -60,6 +60,7 @@ static int gnucash_show_version; static const char *add_quotes_file; static int nofile; static const char *file_to_load; +static int loglevel; static void gnc_print_unstable_message(void) @@ -215,7 +216,7 @@ gnucash_command_line(int argc, char **argv) _("Show GnuCash version"), NULL}, {"debug", '\0', POPT_ARG_NONE, &debugging, 0, _("Enable debugging mode"), NULL}, - {"loglevel", '\0', POPT_ARG_INT, NULL, 0, + {"loglevel", '\0', POPT_ARG_INT, &loglevel, 0, _("Set the logging level from 0 (least) to 6 (most)"), _("LOGLEVEL")}, {"nofile", '\0', POPT_ARG_NONE, &nofile, 0, @@ -256,24 +257,6 @@ gnucash_command_line(int argc, char **argv) gnc_main_set_namespace_regexp(namespace_regexp); } -static void -shutdown(int status) -{ - if (gnucash_ui_is_running()) { - if (!gnucash_ui_is_terminating()) { - if (gnc_file_query_save()) { - gnc_hook_run(HOOK_UI_SHUTDOWN, NULL); - gnc_gui_shutdown(); - } - } - } else { - gnc_gui_destroy(); - gnc_hook_run(HOOK_SHUTDOWN, NULL); - gnc_engine_shutdown(); - exit(status); - } -} - static void load_gnucash_modules() { @@ -334,10 +317,10 @@ inner_main_add_price_quotes(void *closure, int argc, char **argv) if (!SCM_NFALSEP(scm_result)) { g_error("Failed to add quotes to %s.", add_quotes_file); - shutdown(1); + gnc_shutdown(1); } gnc_engine_resume_events(); - shutdown(0); + gnc_shutdown(0); return; } @@ -360,17 +343,20 @@ inner_main (void *closure, int argc, char **argv) main_mod = scm_c_resolve_module("gnucash main"); scm_set_current_module(main_mod); - /* TODO: After some more guile-extraction, this should happen - even before booting guile. */ - gnc_gui_init(); + /* TODO: After some more guile-extraction, this should happen even + before booting guile. */ + gnc_main_gui_init(); load_gnucash_modules(); + + qof_log_set_level_global(loglevel); + load_system_config(); load_user_config(); gnc_hook_add_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit, NULL); scm_c_eval_string("(gnc:main)"); - + gnc_hook_run(HOOK_STARTUP, NULL); if (!nofile && (fn = get_file_to_load())) { gnc_update_splash_screen(_("Loading data...")); @@ -391,7 +377,7 @@ inner_main (void *closure, int argc, char **argv) gnc_ui_start_event_loop(); gnc_hook_remove_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit); - shutdown(0); + gnc_shutdown(0); return; } diff --git a/src/business/business-gnome/business-gnome.scm b/src/business/business-gnome/business-gnome.scm index 0a5e7d00c0..29127d4ce5 100644 --- a/src/business/business-gnome/business-gnome.scm +++ b/src/business/business-gnome/business-gnome.scm @@ -14,10 +14,17 @@ (use-modules (gnucash report business-reports)) (use-modules (gnucash main)) ;for gnc:debug +(export gnc:reload-module) + (define top-level (N_ "_Business")) (define new-label (N_ "New")) (define find-label (N_ "Find")) +(define (gnc:reload-module name) + (let ((m (current-module))) + (load-from-path name) + (set-current-module m))) + (define (business-report-function) (gnc:add-extension (gnc:make-menu gnc:menuname-business-reports diff --git a/src/gnome-utils/gnc-gnome-utils.c b/src/gnome-utils/gnc-gnome-utils.c index cc91921324..ad5602e5b6 100644 --- a/src/gnome-utils/gnc-gnome-utils.c +++ b/src/gnome-utils/gnc-gnome-utils.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "gnc-html-graph-gog.h" @@ -36,11 +37,74 @@ #include "gnc-html.h" #include "gnc-engine.h" #include "gnc-ui.h" - +#include "gnc-file.h" +#include "gnc-hooks.h" +#include "gnc-filepath-utils.h" +#include "gnc-menu-extensions.h" +#include "gnc-component-manager.h" +#include "gnc-splash.h" +#include "gnc-window.h" +#include "gnc-icons.h" +#include "dialog-options.h" +#include "dialog-commodity.h" +#include "gnc-ui-util.h" #include static QofLogModule log_module = GNC_MOD_GUI; static GnomeProgram *gnucash_program = NULL; +static int gnome_is_running = FALSE; +static int gnome_is_terminating = FALSE; +static int gnome_is_initialized = FALSE; + + +#define ACCEL_MAP_NAME "accelerator-map" + +static void +gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat) +{ + gnc_gnome_help (HF_CUSTOM, HL_GLOBPREFS); +} + +static void +gnc_commodity_help_cb (void) +{ + gnc_gnome_help (HF_USAGE, HL_COMMODITY); +} + +/* gnc_configure_date_format + * sets dateFormat to the current value on the scheme side + * + * Args: Nothing + * Returns: Nothing + */ +static void +gnc_configure_date_format (void) +{ + char *format_code = gnc_gconf_get_string(GCONF_GENERAL, + KEY_DATE_FORMAT, NULL); + + QofDateFormat df; + + if (format_code == NULL) + format_code = g_strdup("locale"); + if (*format_code == '\0') { + g_free(format_code); + format_code = g_strdup("locale"); + } + + if (gnc_date_string_to_dateformat(format_code, &df)) + { + PERR("Incorrect date format code"); + if (format_code != NULL) + free(format_code); + return; + } + + qof_date_format_set(df); + + if (format_code != NULL) + free(format_code); +} char * gnc_gnome_locate_pixmap (const char *name) @@ -152,11 +216,6 @@ gnc_gnome_init (int argc, char **argv, const char * version) return; } -void -gnc_gnome_shutdown (void) -{ -} - void gnc_gnome_help (const char *file_name, const char *anchor) { @@ -233,27 +292,171 @@ gnc_gnome_get_gdkpixbuf (const char *name) return pixbuf; } +static gboolean +gnc_ui_check_events (gpointer not_used) +{ + QofSession *session; + gboolean force; -/* shutdown gnucash. This function will call the Scheme side of - * GnuCash to initiate an orderly shutdown, and when that has - * finished it will exit the program. + if (gtk_main_level() != 1) + return TRUE; + + session = qof_session_get_current_session (); + if (!session) + return TRUE; + + if (gnc_gui_refresh_suspended ()) + return TRUE; + + if (!qof_session_events_pending (session)) + return TRUE; + + gnc_suspend_gui_refresh (); + + force = qof_session_process_events (session); + + gnc_resume_gui_refresh (); + + if (force) + gnc_gui_refresh_all (); + + return TRUE; +} + +static int +gnc_x_error (Display *display, XErrorEvent *error) +{ + if (error->error_code) + { + char buf[64]; + + XGetErrorText (display, error->error_code, buf, 63); + + g_warning ("X-ERROR **: %s\n serial %ld error_code %d " + "request_code %d minor_code %d\n", + buf, + error->serial, + error->error_code, + error->request_code, + error->minor_code); + } + + return 0; +} + +int +gnc_ui_start_event_loop (void) +{ + guint id; + + gnome_is_running = TRUE; + + id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000, /* 10 secs */ + gnc_ui_check_events, NULL, NULL); + + XSetErrorHandler (gnc_x_error); + + /* Enter gnome event loop */ + gtk_main (); + + g_source_remove (id); + + gnome_is_running = FALSE; + gnome_is_terminating = FALSE; + + return 0; +} + +GncMainWindow * +gnc_gui_init(void) +{ + static GncMainWindow *main_window; + gchar *map; + + if (gnome_is_initialized) { + return main_window; + } + + gnc_gui_init_splash(); + + gnome_is_initialized = TRUE; + + gnc_ui_util_init(); + gnc_configure_date_format(); + + gnc_gconf_general_register_cb( + KEY_DATE_FORMAT, (GncGconfGeneralCb)gnc_configure_date_format, NULL); + gnc_gconf_general_register_any_cb( + (GncGconfGeneralAnyCb)gnc_gui_refresh_all, NULL); + + gnc_ui_commodity_set_help_callback (gnc_commodity_help_cb); + gnc_file_set_shutdown_callback (gnc_shutdown); + + gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL); + + main_window = gnc_main_window_new (); + gtk_widget_show (GTK_WIDGET (main_window)); + gnc_window_set_progressbar_window (GNC_WINDOW(main_window)); + + map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME); + gtk_accel_map_load(map); + g_free(map); + + gnc_load_stock_icons(); + + return main_window; +} + +gboolean +gnucash_ui_is_running(void) +{ + return gnome_is_running; +} + +static void +gnc_gui_destroy (void) +{ + if (!gnome_is_initialized) + return; + + gnc_extensions_shutdown (); +} + +static void +gnc_gui_shutdown (void) +{ + gchar *map; + + if (gnome_is_running && !gnome_is_terminating) + { + gnome_is_terminating = TRUE; + + map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME); + gtk_accel_map_save(map); + g_free(map); + + gtk_main_quit(); + } +} + +/* shutdown gnucash. This function will initiate an orderly + * shutdown, and when that has finished it will exit the program. */ void gnc_shutdown (int exit_status) { - /*SCM scm_shutdown = gnc_scm_lookup("gnucash bootstrap", "gnc:shutdown");*/ - SCM scm_shutdown = scm_c_eval_string("gnc:shutdown"); - - if(scm_procedure_p(scm_shutdown) != SCM_BOOL_F) - { - SCM scm_exit_code = scm_long2num(exit_status); - scm_call_1(scm_shutdown, scm_exit_code); - } - else - { - /* Either guile is not running, or for some reason we - can't find gnc:shutdown. Either way, just exit. */ - g_warning("couldn't find gnc:shutdown -- exiting anyway."); - exit(exit_status); - } + if (gnucash_ui_is_running()) { + if (!gnome_is_terminating) { + if (gnc_file_query_save()) { + gnc_hook_run(HOOK_UI_SHUTDOWN, NULL); + gnc_gui_shutdown(); + } + } + } else { + gnc_gui_destroy(); + gnc_hook_run(HOOK_SHUTDOWN, NULL); + gnc_engine_shutdown(); + exit(exit_status); + } } + diff --git a/src/gnome-utils/gnc-gnome-utils.h b/src/gnome-utils/gnc-gnome-utils.h index 2c9c76b68c..a9106275bb 100644 --- a/src/gnome-utils/gnc-gnome-utils.h +++ b/src/gnome-utils/gnc-gnome-utils.h @@ -36,14 +36,11 @@ #define GNC_GNOME_UTILS_H #include +#include /** Initialize the Gnome libraries. */ void gnc_gnome_init (int argc, char **argv, const char * version); -/** Shutdown/cleanup any gnome related libraries. */ -void gnc_gnome_shutdown (void); - - /** Given a pixmap/pixbuf file name, find the file in the pixmap * directory associated with this application. This routine will * display an error message if it can't find the file. @@ -139,14 +136,17 @@ GtkWidget * gnc_gnome_get_pixmap (const char *name); GdkPixbuf * gnc_gnome_get_gdkpixbuf (const char *name); -/** Shutdown gnucash. This function will call the Scheme side of - * GnuCash to initiate an orderly shutdown, and when that has - * finished it will exit the program. +/** Shutdown gnucash. This function will initiate an orderly + * shutdown, and when that has finished it will exit the program. * * @param exit_status The exit status for the program. */ void gnc_shutdown (int exit_status); +void gnc_gui_init_splash (void); +GncMainWindow *gnc_gui_init (void); +int gnc_ui_start_event_loop (void); +gboolean gnucash_ui_is_running (void); #endif /** @} */ diff --git a/src/gnome-utils/gnc-splash.c b/src/gnome-utils/gnc-splash.c index c0163b5881..8b28f57345 100644 --- a/src/gnome-utils/gnc-splash.c +++ b/src/gnome-utils/gnc-splash.c @@ -32,7 +32,7 @@ static GtkWidget * splash = NULL; static GtkWidget * progress = NULL; - +static int splash_is_initialized = FALSE; static void splash_destroy_cb (GtkObject *object, gpointer user_data) @@ -40,6 +40,15 @@ splash_destroy_cb (GtkObject *object, gpointer user_data) splash = NULL; } +void +gnc_gui_init_splash (void) +{ + if (!splash_is_initialized) { + splash_is_initialized = TRUE; + gnc_show_splash_screen (); + } +} + void gnc_show_splash_screen (void) { diff --git a/src/gnome-utils/gnc-splash.h b/src/gnome-utils/gnc-splash.h index 6bf68830a7..fdaff012b2 100644 --- a/src/gnome-utils/gnc-splash.h +++ b/src/gnome-utils/gnc-splash.h @@ -26,5 +26,6 @@ void gnc_show_splash_screen (void); void gnc_destroy_splash_screen (void); void gnc_update_splash_screen (const gchar *string); +void gnc_gui_init_splash (void); #endif diff --git a/src/gnome-utils/gw-gnome-utils-spec.scm b/src/gnome-utils/gw-gnome-utils-spec.scm index 5bb9102209..5f0d33ec2b 100644 --- a/src/gnome-utils/gw-gnome-utils-spec.scm +++ b/src/gnome-utils/gw-gnome-utils-spec.scm @@ -46,17 +46,10 @@ "#include \n" "#include \n" "#include \n" + "#include \n" ))) - (gw:wrap-function - ws - 'gnc:gnome-shutdown - ' - "gnc_gnome_shutdown" - '() - "Shutdown the GnuCash gnome system.") - (gw:wrap-as-wct ws ' "GtkWidget*" "const GtkWidget*") (gw:wrap-as-wct ws ' "GtkWindow*" "const GtkWindow*") (gw:wrap-as-wct ws ' "gncUIWidget" "const gncUIWidget") @@ -501,4 +494,21 @@ if they say 'Yes'. The return is false if the user says 'Cancel'.") "gnc_gnome_locate_data_file" '((( caller-owned const) name)) "Find the file in the application data directory.") + + (gw:wrap-function + ws + 'gnc:ui-is-running? + ' + "gnucash_ui_is_running" + '() + "Predicate to determine if the UI is running.") + + (gw:wrap-function + ws + 'gnc:update-splash-screen + ' + "gnc_update_splash_screen" + '((( caller-owned const) string)) + "Update the progress box on the splash screen dialog.") + ) diff --git a/src/gnome/gw-gnc-spec.scm b/src/gnome/gw-gnc-spec.scm index 25745da4aa..a79a21af7a 100644 --- a/src/gnome/gw-gnc-spec.scm +++ b/src/gnome/gw-gnc-spec.scm @@ -48,22 +48,6 @@ "#include \n" "#include \n" ))) - (gw:wrap-function - ws - 'gnc:ui-is-running? - ' - "gnucash_ui_is_running" - '() - "Predicate to determine if the UI is running.") - - (gw:wrap-function - ws - 'gnc:ui-is-terminating? - ' - "gnucash_ui_is_terminating" - '() - "Predicate to determine if the UI is in the process of terminating.") - (gw:wrap-function ws 'gnc:new-user-dialog @@ -72,38 +56,6 @@ '() "Show the new user dialog.") - (gw:wrap-function - ws - 'gnc:update-splash-screen - ' - "gnc_update_splash_screen" - '((( caller-owned const) string)) - "Update the progress box on the splash screen dialog.") - - (gw:wrap-function - ws - 'gnc:destroy-splash-screen - ' - "gnc_destroy_splash_screen" - '() - "Destroy the splash screen dialog.") - - (gw:wrap-function - ws - 'gnc:gui-shutdown - ' - "gnc_gui_shutdown" - '() - "Shutdown the UI.") - - (gw:wrap-function - ws - 'gnc:gui-destroy - ' - "gnc_gui_destroy" - '() - "Destroy the UI.") - (gw:wrap-as-wct ws ' "GNCProgressDialog *" "const GNCProgressDialog *") diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index e6c3e305ca..d2756f3da0 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -26,10 +26,7 @@ #include #include -#include #include -#include -#include #include "TransLog.h" #include "combocell.h" @@ -57,8 +54,6 @@ #include "gnc-plugin-budget.h" #include "gnc-plugin-page-register.h" #include "gnc-plugin-manager.h" /* FIXME Remove this line*/ -#include "gnc-icons.h" /* FIXME Remove this line*/ -#include "gnc-splash.h" #include "gnc-html.h" #include "gnc-gnome-utils.h" #include "gnc-report.h" @@ -74,48 +69,12 @@ #include "gnc-window.h" -#define ACCEL_MAP_NAME "accelerator-map" - -/** PROTOTYPES ******************************************************/ -static void gnc_configure_date_format(void); - - /** GLOBALS *********************************************************/ /* This static indicates the debugging module that this .o belongs to. */ static QofLogModule log_module = GNC_MOD_GUI; -static int gnome_is_running = FALSE; -static int splash_is_initialized = FALSE; -static int gnome_is_initialized = FALSE; -static int gnome_is_terminating = FALSE; - - -gboolean -gnucash_ui_is_running(void) -{ - return gnome_is_running; -} - -gboolean -gnucash_ui_is_terminating(void) -{ - return gnome_is_terminating; -} - -static void -gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat) -{ - gnc_gnome_help (HF_CUSTOM, HL_GLOBPREFS); -} - -static void -gnc_commodity_help_cb (void) -{ - gnc_gnome_help (HF_USAGE, HL_COMMODITY); -} - /* ============================================================== */ -/* HTML Hadler for reports. */ +/* HTML Handler for reports. */ #define IF_TYPE(URL_TYPE_STR,ENTITY_TYPE) \ if (strncmp (URL_TYPE_STR, location, strlen (URL_TYPE_STR)) == 0) \ @@ -236,49 +195,13 @@ gnc_html_price_url_cb (const char *location, const char *label, return TRUE; } -/* ============================================================== */ - void -gnc_gui_init_splash (void) -{ - ENTER (" "); - - if (!splash_is_initialized) - { - splash_is_initialized = TRUE; - - /* put up splash screen */ - gnc_show_splash_screen (); - } - - LEAVE (" "); -} - -void -gnc_gui_init (void) +gnc_main_gui_init (void) { GncMainWindow *main_window; - gchar *map; - ENTER (" "); - - if (gnome_is_initialized) { - LEAVE("already initialized"); - return; - } - - /* Make sure the splash (and hense gnome) was initialized */ - if (!splash_is_initialized) - gnc_gui_init_splash(); - - gnome_is_initialized = TRUE; - - gnc_ui_util_init(); - gnc_configure_date_format(); - gnc_gconf_general_register_cb( - KEY_DATE_FORMAT, (GncGconfGeneralCb)gnc_configure_date_format, NULL); - gnc_gconf_general_register_any_cb( - (GncGconfGeneralAnyCb)gnc_gui_refresh_all, NULL); + ENTER(" "); + main_window = gnc_gui_init(); if (!gnucash_style_init()) gnc_shutdown(1); @@ -290,23 +213,10 @@ gnc_gui_init (void) gnc_html_register_url_handler (URL_TYPE_PRICE, gnc_html_price_url_cb); - gnc_ui_commodity_set_help_callback (gnc_commodity_help_cb); - - gnc_file_set_shutdown_callback (gnc_shutdown); - - gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL); - gnc_ui_sx_initialize(); - main_window = gnc_main_window_new (); - gtk_widget_show (GTK_WIDGET (main_window)); - gnc_totd_dialog(GTK_WINDOW(main_window), TRUE); - map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME); - gtk_accel_map_load(map); - g_free(map); - /* FIXME Remove this test code */ gnc_plugin_manager_add_plugin ( gnc_plugin_manager_get (), gnc_plugin_account_tree_new ()); @@ -323,162 +233,11 @@ gnc_gui_init (void) Anyway... Oh, maybe... nah */ gnc_plugin_manager_add_plugin (gnc_plugin_manager_get (), gnc_plugin_budget_new ()); - gnc_load_stock_icons (); gnc_ui_hierarchy_druid_initialize(); /* Run the ui startup hooks. */ gnc_hook_run(HOOK_UI_STARTUP, NULL); - - gnc_window_set_progressbar_window (GNC_WINDOW(main_window)); - - LEAVE (" "); - + LEAVE(" "); return; } - -/* ============================================================== */ - -void -gnc_gui_shutdown (void) -{ - gchar *map; - - if (gnome_is_running && !gnome_is_terminating) - { - gnome_is_terminating = TRUE; - - map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME); - gtk_accel_map_save(map); - g_free(map); - - gtk_main_quit(); - - gnc_gnome_shutdown (); - } -} - -/* ============================================================== */ - -void -gnc_gui_destroy (void) -{ - if (!gnome_is_initialized) - return; - - gnc_extensions_shutdown (); -} - -/* ============================================================== */ - -static gboolean -gnc_ui_check_events (gpointer not_used) -{ - QofSession *session; - gboolean force; - - if (gtk_main_level() != 1) - return TRUE; - - session = qof_session_get_current_session (); - if (!session) - return TRUE; - - if (gnc_gui_refresh_suspended ()) - return TRUE; - - if (!qof_session_events_pending (session)) - return TRUE; - - gnc_suspend_gui_refresh (); - - force = qof_session_process_events (session); - - gnc_resume_gui_refresh (); - - if (force) - gnc_gui_refresh_all (); - - return TRUE; -} - -static int -gnc_x_error (Display *display, XErrorEvent *error) -{ - if (error->error_code) - { - char buf[64]; - - XGetErrorText (display, error->error_code, buf, 63); - - g_warning ("X-ERROR **: %s\n serial %ld error_code %d " - "request_code %d minor_code %d\n", - buf, - error->serial, - error->error_code, - error->request_code, - error->minor_code); - } - - return 0; -} - -int -gnc_ui_start_event_loop (void) -{ - guint id; - - gnome_is_running = TRUE; - - id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000, /* 10 secs */ - gnc_ui_check_events, NULL, NULL); - - XSetErrorHandler (gnc_x_error); - - /* Enter gnome event loop */ - gtk_main (); - - g_source_remove (id); - - gnome_is_running = FALSE; - gnome_is_terminating = FALSE; - - return 0; -} - -/* ============================================================== */ - -/* gnc_configure_date_format - * sets dateFormat to the current value on the scheme side - * - * Args: Nothing - * Returns: Nothing - */ -static void -gnc_configure_date_format (void) -{ - char *format_code = gnc_gconf_get_string(GCONF_GENERAL, KEY_DATE_FORMAT, NULL); - - QofDateFormat df; - - if (format_code == NULL) - format_code = g_strdup("locale"); - if (*format_code == '\0') { - g_free(format_code); - format_code = g_strdup("locale"); - } - - if (gnc_date_string_to_dateformat(format_code, &df)) - { - PERR("Incorrect date format code"); - if (format_code != NULL) - free(format_code); - return; - } - - qof_date_format_set(df); - - if (format_code != NULL) - free(format_code); -} - /****************** END OF FILE **********************/ diff --git a/src/gnome/top-level.h b/src/gnome/top-level.h index e2c33547cf..64a483f4cf 100644 --- a/src/gnome/top-level.h +++ b/src/gnome/top-level.h @@ -25,12 +25,6 @@ #include -gboolean gnucash_ui_is_running (void); -gboolean gnucash_ui_is_terminating (void); -void gnc_gui_init_splash (void); -void gnc_gui_init (void); -void gnc_gui_shutdown (void); -void gnc_gui_destroy (void); -int gnc_ui_start_event_loop (void); +void gnc_main_gui_init(void); #endif diff --git a/src/scm/command-line.scm b/src/scm/command-line.scm index e5b7afe984..885ffe36ed 100644 --- a/src/scm/command-line.scm +++ b/src/scm/command-line.scm @@ -22,7 +22,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Configuration variables -(define gnc:*arg-no-file* #f) (define gnc:*loglevel* #f) (define gnc:*doc-path* #f) @@ -67,13 +66,6 @@ (define (gnc:initialize-config-vars) ;; We use a function so we don't do this at file load time. - (set! gnc:*arg-no-file* - (gnc:make-config-var - (N_ "Don't load any file, including autoloading the last file.") - (lambda (var value) (if (boolean? value) (list value) #f)) - eq? - #f)) - ;; Convert the temporary startup value into a config var. (let ((current-value gnc:*debugging?*)) (set! @@ -133,13 +125,6 @@ the current value of the path.") "LOGLEVEL" (N_ "Set the logging level from 0 (least) to 6 (most)")) - (list "nofile" - 'boolean - (lambda (val) - (gnc:config-var-value-set! gnc:*arg-no-file* #f val)) - #f - (N_ "Do not load the last file opened")) - (list "doc-path" 'string (lambda (val) diff --git a/src/scm/main.scm b/src/scm/main.scm index db5e208262..a164731792 100644 --- a/src/scm/main.scm +++ b/src/scm/main.scm @@ -50,16 +50,12 @@ (export gnc:error) (export gnc:msg) (export gnc:debug) -(export build-path) -(export gnc:use-module-here!) -(export item-list->hash!) (export string-join) (export gnc:backtrace-if-exception) (export gnc:find-file) (export gnc:find-localized-file) (export gnc:main) (export gnc:safe-strcmp) ;; only used by aging.scm atm... -(export gnc:reload-module) (re-export hash-fold) (re-export string-split) @@ -93,16 +89,6 @@ ;;(use-modules (ice-9 statprof)) -;; -;; A flag: is this a development version? This will flag whether or not -;; to print out various 'development version' strings throughout the code. -;; #t == development version, #f == stable version -;; -;; NOTE: You still need to comment out the message in -;; tip_of_the_day.list.in by hand! -;; -(define gnc:*is-development-version?* #t) - ;; These will be converted to config vars later (see command-line.scm) (define gnc:*debugging?* (if (getenv "GNC_DEBUG") #t #f)) @@ -137,11 +123,6 @@ (b -1) (else 0))))) -(define (gnc:reload-module name) - (let ((m (current-module))) - (load-from-path name) - (set-current-module m))) - (if (not (defined? 'hash-fold)) (define (hash-fold proc init table) (for-each @@ -152,35 +133,6 @@ bin)) (vector->list table)))) -(define (item-list->hash! lst hash - getkey getval - hashref hashset - list-duplicates?) - ;; Takes a list of the form (item item item item) and returns a hash - ;; formed by traversing the list, and getting the key and val from - ;; each item using the supplied get-key and get-val functions, and - ;; building a hash table from the result using the given hashref and - ;; hashset functions. list-duplicates? determines whether or not in - ;; the resulting hash, the value for a given key is a list of all - ;; the values associated with that key in the input or just the - ;; first one encountered. - - (define (handle-item item) - (let* ((key (getkey item)) - (val (getval item)) - (existing-val (hashref hash key))) - - (if (not list-duplicates?) - ;; ignore if not first value. - (if (not existing-val) (hashset hash key val)) - ;; else result is list. - (if existing-val - (hashset hash key (cons val existing-val)) - (hashset hash key (list val)))))) - - (for-each handle-item lst) - hash) - (define (string-join lst joinstr) ;; This should avoid a bunch of unnecessary intermediate string-appends. ;; I'm presuming those are more expensive than cons... @@ -207,6 +159,7 @@ (set! parts (cons (substring str 0 last-char) parts)))) parts)) +;; only used by doc-path (define (gnc:flatten tree) (let ((result '())) (let loop ((remaining-items tree)) @@ -322,22 +275,7 @@ string and 'directories' must be a list of strings." (define (gnc:shutdown exit-status) (gnc:debug "Shutdown -- exit-status: " exit-status) - - (cond ((gnc:ui-is-running?) - (if (not (gnc:ui-is-terminating?)) - (if (gnc:file-query-save) - (begin - (gnc:hook-run-danglers gnc:*ui-shutdown-hook*) - (gnc:gui-shutdown))))) - (else - (gnc:gui-destroy) - (gnc:hook-run-danglers gnc:*shutdown-hook*) - (gnc:engine-shutdown) - (exit exit-status)))) - -(define (gnc:gui-finish) - (gnc:debug "UI Shutdown hook.") - (gnc:file-quit)) + (exit exit-status)) ;; Temporary Stub until command-line.scm dies (define (gnc:strip-path path) (let* ((parts-in (string-split path #\/)) @@ -356,43 +294,6 @@ string and 'directories' must be a list of strings." ;; Put it back together (string-join (reverse parts-out) "/"))) -(define (gnc:normalize-path file) - (let* ((parts-in (string-split file #\/)) - (parts-out '())) - - ;; Convert to a path based at the root. If the filename starts - ;; with a '/' then the first component of the list is a null - ;; string. If the path starts with foo:// then the first - ;; component will contain a ':' and the second will be null. - (cond ((string-null? (car parts-in)) - (gnc:strip-path file)) - ((and (string=? (car parts-in) "file:") - (string-null? (cadr parts-in))) - (gnc:strip-path file)) - ((and (string-index (car parts-in) #\:) - (string-null? (cadr parts-in))) - file) - (else - (gnc:strip-path (string-append (getenv "PWD") "/" file)))) - ) -) - -(define (gnc:account-file-to-load) - (let ((ok (not (gnc:config-var-value-get gnc:*arg-no-file*))) - (file (if (pair? gnc:*command-line-remaining*) - (car gnc:*command-line-remaining*) - (gnc:history-get-last)))) - (and ok (string? file) (gnc:normalize-path file)))) - -(define (gnc:load-account-file) - (let ((file (gnc:account-file-to-load))) - (if file - (begin - (gnc:update-splash-screen (_ "Loading data...")) - (and (not (gnc:file-open-file file)) - (gnc:hook-run-danglers gnc:*book-opened-hook* #f))) - (and (gnc:hook-run-danglers gnc:*book-opened-hook* #f))))) - (define (gnc:main) ;; (statprof-reset 0 50000) ;; 20 times/sec @@ -430,11 +331,6 @@ string and 'directories' must be a list of strings." (list gnc:menuname-reports gnc:menuname-utility "") (lambda (window) (gnc:main-window-open-report (gnc:make-welcome-report) window)))) - - (gnc:hook-run-danglers gnc:*startup-hook*) - - (if (gnc:config-var-value-get gnc:*loglevel*) - (gnc:set-log-level-global (gnc:config-var-value-get gnc:*loglevel*))) - + ;;return to C ) diff --git a/src/scm/price-quotes.scm b/src/scm/price-quotes.scm index 14eaef8ecf..9e82add7b7 100644 --- a/src/scm/price-quotes.scm +++ b/src/scm/price-quotes.scm @@ -47,6 +47,35 @@ ;; (use-modules (srfi srfi-19)) when available (see below). +(define (item-list->hash! lst hash + getkey getval + hashref hashset + list-duplicates?) + ;; Takes a list of the form (item item item item) and returns a hash + ;; formed by traversing the list, and getting the key and val from + ;; each item using the supplied get-key and get-val functions, and + ;; building a hash table from the result using the given hashref and + ;; hashset functions. list-duplicates? determines whether or not in + ;; the resulting hash, the value for a given key is a list of all + ;; the values associated with that key in the input or just the + ;; first one encountered. + + (define (handle-item item) + (let* ((key (getkey item)) + (val (getval item)) + (existing-val (hashref hash key))) + + (if (not list-duplicates?) + ;; ignore if not first value. + (if (not existing-val) (hashset hash key val)) + ;; else result is list. + (if existing-val + (hashset hash key (cons val existing-val)) + (hashset hash key (list val)))))) + + (for-each handle-item lst) + hash) + (define (yahoo-get-historical-quotes symbol start-year start-month start-day end-year end-month end-day)