diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 3c08d12a0c..f7c26b0000 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -1666,11 +1666,9 @@ xaccTransCommitEdit (Transaction *trans) /* XXX hack alert -- turn this into a gui dialog */ if (ERR_BACKEND_MODIFIED == errcode) { - PWARN("Another user has modified this transaction\n" - "\tjust a moment ago. Please look at their changes,\n" - "\tand try again, if needed.\n" - "\t(This dialog should be a gui dialog and \n" - "\tshould check for errors)\n"); + PWARN_GUI(_("Another user has modified this transaction\n" + "\tjust a moment ago. Please look at their changes,\n" + "\tand try again, if needed.\n")); } /* push error back onto the stack */ diff --git a/src/engine/gnc-engine-util.c b/src/engine/gnc-engine-util.c index 2dceb16eef..bb64471b8c 100644 --- a/src/engine/gnc-engine-util.c +++ b/src/engine/gnc-engine-util.c @@ -454,5 +454,51 @@ g_hash_table_kv_pair_free_gfunc(gpointer data, gpointer user_data) } +/********************************************************************\ + Callbacks so that the engine can display gui messages. +\********************************************************************/ + +static GNCGuiMessage gnc_gui_warning_func = NULL; +static GNCGuiMessage gnc_gui_error_func = NULL; + +void gnc_set_warning_message (GNCGuiMessage func) +{ + gnc_gui_warning_func = func; +} + +void gnc_set_error_message (GNCGuiMessage func) +{ + gnc_gui_error_func = func; +} + +gboolean +gnc_send_gui_warning(const gchar *format, ...) +{ + va_list args; + + if (!gnc_gui_warning_func) + return(FALSE); + + va_start(args, format); + gnc_gui_warning_func(format, args); + va_end(args); + return(TRUE); +} + +gboolean +gnc_send_gui_error(const gchar *format, ...) +{ + va_list args; + + if (!gnc_gui_error_func) + return(FALSE); + + va_start(args, format); + gnc_gui_error_func(format, args); + va_end(args); + return(TRUE); +} + + /************************* END OF FILE ******************************\ \********************************************************************/ diff --git a/src/engine/gnc-engine-util.h b/src/engine/gnc-engine-util.h index 682d452876..4c1ffb4dc0 100644 --- a/src/engine/gnc-engine-util.h +++ b/src/engine/gnc-engine-util.h @@ -80,6 +80,14 @@ typedef enum GNC_LOG_TRACE = 6, } gncLogLevel; + +typedef void (*GNCGuiMessage) (const gchar *format, va_list args); +void gnc_set_warning_message (GNCGuiMessage func); +void gnc_set_error_message (GNCGuiMessage func); + +gboolean gnc_send_gui_warning (const gchar *format, ...); +gboolean gnc_send_gui_error (const gchar *format, ...); + /* FIXME: these logging functions should proably get replaced by * the glib.h g_error(), etc functions. That way, we would have * unified logging mechanism, instead of having some messages @@ -113,6 +121,11 @@ void gnc_log (gncModuleType module, gncLogLevel log_level, __FUNCTION__, format, ## args); \ } +#define PWARN_GUI(format, args...) { \ + if (!gnc_send_gui_error(format, ## args)) \ + PWARN(format, ## args); \ +} + #define PINFO(format, args...) { \ if (gnc_should_log (module, GNC_LOG_INFO)) \ gnc_log (module, GNC_LOG_INFO, "Info", \ diff --git a/src/gnome-utils/gnc-gui-query.c b/src/gnome-utils/gnc-gui-query.c index 2007a32fb8..00059091e4 100644 --- a/src/gnome-utils/gnc-gui-query.c +++ b/src/gnome-utils/gnc-gui-query.c @@ -359,6 +359,9 @@ gnc_warning_dialog_common(GtkWidget *parent, const gchar *format, va_list args) GtkWidget *warning_box = NULL; gchar *buffer; + if (parent == NULL) + parent = GTK_WIDGET(gnc_ui_get_toplevel()); + buffer = g_strdup_vprintf(format, args); warning_box = gnome_warning_dialog_parented(buffer, GTK_WINDOW(parent)); g_free(buffer); @@ -366,13 +369,19 @@ gnc_warning_dialog_common(GtkWidget *parent, const gchar *format, va_list args) gnome_dialog_run_and_close(GNOME_DIALOG(warning_box)); } +void +gnc_warning_dialog_va(const gchar *format, va_list args) +{ + gnc_warning_dialog_common(NULL, format, args); +} + void gnc_warning_dialog(const gchar *format, ...) { va_list args; va_start(args, format); - gnc_warning_dialog_common(gnc_ui_get_toplevel(), format, args); + gnc_warning_dialog_common(NULL, format, args); va_end(args); } @@ -382,8 +391,7 @@ gnc_warning_dialog_parented(GtkWidget *parent, const gchar *format, ...) va_list args; va_start(args, format); - gnc_warning_dialog_common(parent ? parent : gnc_ui_get_toplevel(), - format, args); + gnc_warning_dialog_common(parent, format, args); va_end(args); } @@ -403,9 +411,14 @@ gnc_warning_dialog_parented(GtkWidget *parent, const gchar *format, ...) static void gnc_error_dialog_common(GtkWindow *parent, const gchar *format, va_list args) { - GtkWidget *error_box = NULL; + GtkWidget *top_window, *error_box = NULL; gchar *buffer; + if (parent == NULL) { + top_window = gnc_ui_get_toplevel(); + parent = top_window ? GTK_WINDOW(top_window) : NULL; + } + buffer = g_strdup_vprintf(format, args); error_box = gnome_error_dialog_parented(buffer, parent); g_free(buffer); @@ -413,16 +426,19 @@ gnc_error_dialog_common(GtkWindow *parent, const gchar *format, va_list args) gnome_dialog_run_and_close(GNOME_DIALOG(error_box)); } +void +gnc_error_dialog_va(const gchar *format, va_list args) +{ + gnc_error_dialog_common(NULL, format, args); +} + void gnc_error_dialog(const gchar *format, ...) { - GtkWidget *parent; va_list args; - parent = gnc_ui_get_toplevel(); - va_start(args, format); - gnc_error_dialog_common(parent ? GTK_WINDOW(parent) : NULL, format, args); + gnc_error_dialog_common(NULL, format, args); va_end(args); } @@ -432,8 +448,7 @@ gnc_error_dialog_parented(GtkWindow *parent, const gchar *format, ...) va_list args; va_start(args, format); - gnc_error_dialog_common(parent ? parent : GTK_WINDOW(gnc_ui_get_toplevel()), - format, args); + gnc_error_dialog_common(parent, format, args); va_end(args); } diff --git a/src/gnome-utils/gnc-gui-query.h b/src/gnome-utils/gnc-gui-query.h index fb0441263b..d95f9f0f20 100644 --- a/src/gnome-utils/gnc-gui-query.h +++ b/src/gnome-utils/gnc-gui-query.h @@ -32,11 +32,15 @@ gnc_info_dialog_parented(GtkWindow *parent, extern void gnc_warning_dialog(const char *format, ...) G_GNUC_PRINTF (1, 2); +extern void +gnc_warning_dialog_va(const char *format, va_list args); extern void gnc_error_dialog(const char *format, ...) G_GNUC_PRINTF (1, 2); extern void +gnc_error_dialog_va(const char *format, va_list args); +extern void gnc_error_dialog_parented(GtkWindow *parent, const char *forrmat, ...) G_GNUC_PRINTF (2, 3); diff --git a/src/gnome-utils/gncmod-gnome-utils.c b/src/gnome-utils/gncmod-gnome-utils.c index 065ddfca2d..6b93fbb963 100644 --- a/src/gnome-utils/gncmod-gnome-utils.c +++ b/src/gnome-utils/gncmod-gnome-utils.c @@ -14,6 +14,8 @@ #include "dialog-options.h" #include "gnc-html.h" +#include "gnc-engine-util.h" +#include "gnc-gui-query.h" /* version of the gnc module system interface we require */ int libgncmod_gnome_utils_LTX_gnc_module_system_interface = 0; @@ -80,10 +82,15 @@ libgncmod_gnome_utils_LTX_gnc_module_init(int refcount) { gnc_html_initialize (); } + gnc_set_warning_message(gnc_warning_dialog_va); + gnc_set_error_message(gnc_error_dialog_va); return TRUE; } int -libgncmod_gnome_utils_LTX_gnc_module_end(int refcount) { +libgncmod_gnome_utils_LTX_gnc_module_end(int refcount) +{ + gnc_set_warning_message(NULL); + gnc_set_error_message(NULL); return TRUE; }