gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Tue Dec 23 11:19:19 EST 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/69355c05 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a5d77e44 (commit)
	from  https://github.com/Gnucash/gnucash/commit/0820090e (commit)



commit 69355c05489e01fef0e22835c51ad18a0d40ac4e
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Tue Dec 23 17:19:00 2014 +0100

    Bug 741810 - Compilation fails because of creating .gnucash

diff --git a/src/core-utils/gnc-filepath-utils.c b/src/core-utils/gnc-filepath-utils.c
index 7e60493..54cdc18 100644
--- a/src/core-utils/gnc-filepath-utils.c
+++ b/src/core-utils/gnc-filepath-utils.c
@@ -299,12 +299,13 @@ gnc_path_find_localized_html_file (const gchar *file_name)
  *
  * @param dirname The path to check
  */
-static void
-gnc_validate_directory (const gchar *dirname)
+static gboolean
+gnc_validate_directory (const gchar *dirname, gchar **msg)
 {
     struct stat statbuf;
     gint rc;
 
+    *msg = NULL;
     rc = g_stat (dirname, &statbuf);
     if (rc)
     {
@@ -320,70 +321,72 @@ gnc_validate_directory (const gchar *dirname)
                          );
             if (rc)
             {
-                g_fprintf(stderr,
+                *msg = g_strdup_printf(
                           _("An error occurred while creating the directory:\n"
                             "  %s\n"
                             "Please correct the problem and restart GnuCash.\n"
                             "The reported error was '%s' (errno %d).\n"),
                           dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
-                exit(1);
+                return FALSE;
             }
             g_stat (dirname, &statbuf);
             break;
 
         case EACCES:
-            g_fprintf(stderr,
+            *msg = g_strdup_printf(
                       _("The directory\n"
                         "  %s\n"
                         "exists but cannot be accessed. This program \n"
                         "must have full access (read/write/execute) to \n"
                         "the directory in order to function properly.\n"),
                       dirname);
-            exit(1);
+            return FALSE;
 
         case ENOTDIR:
-            g_fprintf(stderr,
+            *msg = g_strdup_printf(
                       _("The path\n"
                         "  %s\n"
                         "exists but it is not a directory. Please delete\n"
                         "the file and start GnuCash again.\n"),
                       dirname);
-            exit(1);
+            return FALSE;
 
         default:
-            g_fprintf(stderr,
+            *msg = g_strdup_printf(
                       _("An unknown error occurred when validating that the\n"
                         "  %s\n"
                         "directory exists and is usable. Please correct the\n"
                         "problem and restart GnuCash. The reported error \n"
                         "was '%s' (errno %d)."),
                       dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
-            exit(1);
+            return FALSE;
         }
     }
 
     if ((statbuf.st_mode & S_IFDIR) != S_IFDIR)
     {
-        g_fprintf(stderr,
+        *msg = g_strdup_printf(
                   _("The path\n"
                     "  %s\n"
                     "exists but it is not a directory. Please delete\n"
                     "the file and start GnuCash again.\n"),
                   dirname);
-        exit(1);
+        return FALSE;
     }
 #ifndef G_OS_WIN32
     /* The mode argument is ignored on windows anyway */
     if ((statbuf.st_mode & S_IRWXU) != S_IRWXU)
     {
-        g_fprintf(stderr,
+        *msg = g_strdup_printf(
                   _("The permissions are wrong on the directory\n"
                     "  %s\n"
                     "They must be at least 'rwx' for the user.\n"),
                   dirname);
-        exit(1);
+        return FALSE;
     }
 #endif
+
+    return TRUE;
 }
 
 /** @fn const gchar * gnc_dotgnucash_dir ()
@@ -399,6 +402,7 @@ gnc_dotgnucash_dir (void)
 {
     static gchar *dotgnucash = NULL;
     gchar *tmp_dir;
+    gchar *errmsg = NULL;
 
     if (dotgnucash)
         return dotgnucash;
@@ -408,26 +412,31 @@ gnc_dotgnucash_dir (void)
     if (!dotgnucash)
     {
         const gchar *home = g_get_home_dir();
-        if (!home)
+        if (!home || !gnc_validate_directory(home, &errmsg))
         {
-            g_warning("Cannot find home directory. Using tmp directory instead.");
+            g_free(errmsg);
+            g_warning("Cannot find suitable home directory. Using tmp directory instead.");
             home = g_get_tmp_dir();
         }
         g_assert(home);
 
         dotgnucash = g_build_filename(home, ".gnucash", (gchar *)NULL);
     }
-    gnc_validate_directory(dotgnucash);
+    if (!gnc_validate_directory(dotgnucash, &errmsg))
+        exit(1);
 
     /* Since we're in code that is only executed once.... */
     tmp_dir = g_build_filename(dotgnucash, "books", (gchar *)NULL);
-    gnc_validate_directory(tmp_dir);
+    if (!gnc_validate_directory(tmp_dir, &errmsg))
+        exit(1);
     g_free(tmp_dir);
     tmp_dir = g_build_filename(dotgnucash, "checks", (gchar *)NULL);
-    gnc_validate_directory(tmp_dir);
+    if (!gnc_validate_directory(tmp_dir, &errmsg))
+        exit(1);
     g_free(tmp_dir);
-    tmp_dir = g_build_filename(dotgnucash, "translog", (gchar *)NULL);
-    gnc_validate_directory(tmp_dir);
+    tmp_dir = g_build_filename(tmp_dir, "translog", (gchar *)NULL);
+    if (!gnc_validate_directory(dotgnucash, &errmsg))
+        exit(1);
     g_free(tmp_dir);
 
     return dotgnucash;

commit a5d77e4430319e81fbd2f6b5a005851857fb290e
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Tue Dec 23 12:03:38 2014 +0100

    Move code to open report options dialog from guile to C
    
    This code was switching a lot between the guile and C context.
    This move at least reduces some of them. The switches can only
    be eliminated completely when the options code itself gets
    rewritten in C(++).

diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c
index 828f4b5..3ec09f0 100644
--- a/src/report/report-gnome/gnc-plugin-page-report.c
+++ b/src/report/report-gnome/gnc-plugin-page-report.c
@@ -1593,24 +1593,13 @@ static void
 gnc_plugin_page_report_options_cb( GtkAction *action, GncPluginPageReport *report )
 {
     GncPluginPageReportPrivate *priv;
-    SCM start_editor = scm_c_eval_string("gnc:report-edit-options");
-    SCM result;
 
     priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
     if (priv->cur_report == SCM_BOOL_F)
         return;
 
-    result = gfec_apply(start_editor, scm_cons(priv->cur_report, SCM_EOL),
-                        error_handler);
-    if (result == SCM_BOOL_F || result == SCM_UNDEFINED)
-    {
-        gnc_warning_dialog(GTK_WIDGET(gnc_ui_get_toplevel()), "%s",
-                           _("There are no options for this report."));
-    }
-    else
-    {
+    if (gnc_report_edit_options (priv->cur_report))
         gnc_plugin_page_report_add_edited_report(priv, priv->cur_report);
-    }
 }
 
 static GncInvoice *lookup_invoice(GncPluginPageReportPrivate *priv)
diff --git a/src/report/report-gnome/report-gnome.i b/src/report/report-gnome/report-gnome.i
index 9e49ac0..605523d 100644
--- a/src/report/report-gnome/report-gnome.i
+++ b/src/report/report-gnome/report-gnome.i
@@ -3,7 +3,6 @@
 /* Includes the header in the wrapper code */
 #include <config.h>
 #include <gtk/gtk.h>
-#include <dialog-report-column-view.h>
 #include <gnc-plugin-page-report.h>
 #include <window-report.h>
 #include <dialog-custom-report.h>
@@ -18,10 +17,5 @@ SCM scm_init_sw_report_gnome_module (void);
 
 %import "base-typemaps.i"
 
-void gnc_report_raise_editor(SCM report);
 void gnc_main_window_open_report(int report_id, GncMainWindow *window);
-GtkWidget * gnc_report_window_default_params_editor(SCM options, SCM report);
-GtkWidget * gnc_column_view_edit_options(SCM options, SCM view);
-
 void gnc_ui_custom_report(GncMainWindow * window);
-
diff --git a/src/report/report-gnome/report-gnome.scm b/src/report/report-gnome/report-gnome.scm
index b68350b..4825f53 100644
--- a/src/report/report-gnome/report-gnome.scm
+++ b/src/report/report-gnome/report-gnome.scm
@@ -26,33 +26,9 @@
 (gnc:module-load "gnucash/report/report-system" 0)
 (gnc:module-load "gnucash/report/utility-reports" 0)
 
-(export gnc:report-edit-options)
 (export gnc:report-menu-setup)
 (export gnc:add-report-template-menu-items)
 
-;; returns a function that takes a list: (options, report),
-;; and returns a widget
-(define (gnc:report-options-editor report) 
-  (if (equal? (gnc:report-type report) "d8ba4a2e89e8479ca9f6eccdeb164588")
-      gnc-column-view-edit-options
-      gnc-report-window-default-params-editor))
-
-;; do not rely on the return value of this function - it has none.
-;; instead, this function's side-effect is to set the report's editor widget.
-(define (gnc:report-edit-options report) 
-  (let* ((editor-widg (gnc:report-editor-widget report)))
-    (if (and editor-widg (not (null? editor-widg)))
-        (gnc-report-raise-editor report)
-        (begin
-          (if (gnc:report-options report) 
-              (begin 
-                (set! editor-widg
-                      ((gnc:report-options-editor report)
-                       (gnc:report-options report)
-                       report))
-                (gnc:report-set-editor-widget! report editor-widg))
-              (gnc-warning-dialog '() (_ "This report has no options.")))))))
-
 (define (gnc:add-report-template-menu-items)
   (define *template-items* '())
 
diff --git a/src/report/report-gnome/window-report.c b/src/report/report-gnome/window-report.c
index bb68a7d..00d7b1a 100644
--- a/src/report/report-gnome/window-report.c
+++ b/src/report/report-gnome/window-report.c
@@ -34,6 +34,7 @@
 
 #include "swig-runtime.h"
 #include "dialog-options.h"
+#include "dialog-report-column-view.h"
 #include "file-utils.h"
 #include "gnc-gkeyfile-utils.h"
 #include "gnc-guile-utils.h"
@@ -120,11 +121,28 @@ gnc_options_dialog_close_cb(GNCOptionWin * propertybox,
     g_free(win);
 }
 
+static gboolean
+gnc_report_raise_editor(SCM report)
+{
+    SCM get_editor   = scm_c_eval_string("gnc:report-editor-widget");
+    SCM editor       = scm_call_1(get_editor, report);
+    if (editor != SCM_BOOL_F)
+    {
+#define FUNC_NAME "gnc-report-raise-editor"
+        GtkWidget *w = SWIG_MustGetPtr(editor,
+                                   SWIG_TypeQuery("_p_GtkWidget"), 1, 0);
+#undef FUNC_NAME
+        gtk_window_present(GTK_WINDOW(w));
+        return TRUE;
+    }
+    else
+        return FALSE;
+}
+
 
 GtkWidget *
 gnc_report_window_default_params_editor(SCM options, SCM report)
 {
-    SCM get_editor        = scm_c_eval_string("gnc:report-editor-widget");
     SCM get_report_type   = scm_c_eval_string("gnc:report-type");
     SCM get_template      = scm_c_eval_string("gnc:find-report-template");
     SCM get_template_name = scm_c_eval_string("gnc:report-template-name");
@@ -132,15 +150,8 @@ gnc_report_window_default_params_editor(SCM options, SCM report)
 
     const gchar *title = NULL;
 
-    ptr = scm_call_1(get_editor, report);
-    if (ptr != SCM_BOOL_F)
-    {
-#define FUNC_NAME "gtk_window_present"
-        GtkWindow * w = SWIG_MustGetPtr(ptr, SWIG_TypeQuery("_p_GtkWidget"), 1, 0);
-        gtk_window_present(w);
-#undef FUNC_NAME
+    if (gnc_report_raise_editor (report))
         return NULL;
-    }
     else
     {
         struct report_default_params_data * prm =
@@ -187,16 +198,48 @@ gnc_report_window_default_params_editor(SCM options, SCM report)
     }
 }
 
-void
-gnc_report_raise_editor(SCM report)
+gboolean
+gnc_report_edit_options(SCM report)
 {
-    SCM get_editor = scm_c_eval_string("gnc:report-editor-widget");
-    SCM editor = scm_call_1(get_editor, report);
-#define FUNC_NAME "gtk_window_present"
-    GtkWidget *w = SWIG_MustGetPtr(editor,
-                                   SWIG_TypeQuery("_p_GtkWidget"), 1, 0);
+    SCM set_editor        = scm_c_eval_string("gnc:report-set-editor-widget!");
+    SCM get_options       = scm_c_eval_string("gnc:report-options");
+    SCM get_report_type   = scm_c_eval_string("gnc:report-type");
+    SCM ptr;
+    SCM options;
+    GtkWidget *options_widget = NULL;
+
+    /* If the options editor widget already exists we simply raise it */
+    if (gnc_report_raise_editor (report))
+        return TRUE;
+
+    /* Check if this report has options to edit */
+    options = scm_call_1(get_options, report);
+    if (options == SCM_BOOL_F)
+    {
+        gnc_warning_dialog(GTK_WIDGET(gnc_ui_get_toplevel()), "%s",
+                           _("There are no options for this report."));
+        return FALSE;
+    }
+
+    /* Multi-column type reports need a special options dialog */
+    ptr = scm_call_1(get_report_type, report);
+    if (scm_is_string(ptr))
+    {
+        gchar *rpt_type = gnc_scm_to_utf8_string (ptr);
+        if (g_strcmp0 (rpt_type, "d8ba4a2e89e8479ca9f6eccdeb164588") == 0)
+            options_widget = gnc_column_view_edit_options (options, report);
+        else
+            options_widget = gnc_report_window_default_params_editor (options, report);
+        g_free (rpt_type);
+    }
+
+    /* Store the options editor widget for future reuse */
+#define FUNC_NAME "gnc-report-edit-options"
+    ptr = SWIG_NewPointerObj (options_widget, SWIG_TypeQuery("_p_GtkWidget"), 0);
 #undef FUNC_NAME
-    gtk_window_present(GTK_WINDOW(w));
+    scm_call_2 (set_editor, report, ptr);
+
+    return TRUE;
 }
 
 static gboolean
@@ -236,7 +279,6 @@ static gboolean
 gnc_html_options_url_cb (const char *location, const char *label,
                          gboolean new_window, GNCURLResult *result)
 {
-    SCM start_editor = scm_c_eval_string ("gnc:report-edit-options");
     SCM report;
     int report_id;
 
@@ -266,7 +308,7 @@ gnc_html_options_url_cb (const char *location, const char *label,
             return FALSE;
         }
 
-        scm_call_1 (start_editor, report);
+        gnc_report_edit_options (report);
 
         return TRUE;
     }
diff --git a/src/report/report-gnome/window-report.h b/src/report/report-gnome/window-report.h
index cacba95..96f33ce 100644
--- a/src/report/report-gnome/window-report.h
+++ b/src/report/report-gnome/window-report.h
@@ -39,8 +39,7 @@ GtkWidget * gnc_report_window_default_params_editor(SCM options, SCM report);
 // [business-gnome/dialog-invoice.c;gnome/window-register.c]; and
 // scm-exposed; 3-liner which calls gnc_main_window_open_report after handling busy-cursor.
 void       reportWindow(int id);
-// scm-exposed; ~priv
-void       gnc_report_raise_editor(SCM report);
+gboolean   gnc_report_edit_options(SCM report);
 // module[/plugin]-init
 void       gnc_report_init (void);
 



Summary of changes:
 src/core-utils/gnc-filepath-utils.c              | 51 ++++++++-------
 src/report/report-gnome/gnc-plugin-page-report.c | 13 +---
 src/report/report-gnome/report-gnome.i           |  6 --
 src/report/report-gnome/report-gnome.scm         | 24 -------
 src/report/report-gnome/window-report.c          | 80 ++++++++++++++++++------
 src/report/report-gnome/window-report.h          |  3 +-
 6 files changed, 93 insertions(+), 84 deletions(-)



More information about the gnucash-changes mailing list