gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Tue Jun 12 19:16:13 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/9c7fa77d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/5d3ae6c6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/64837820 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/2384af60 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a73f9123 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1f14d0f6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/00e6ccdd (commit)
	from  https://github.com/Gnucash/gnucash/commit/ffe6044c (commit)



commit 9c7fa77d3b1d161e9319d8b392bb89148318e8b0
Merge: 5d3ae6c 6483782
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Jun 12 16:12:48 2018 -0700

    Merge Bob Fewell's 'fixes6' into maint.


commit 5d3ae6c672e95327b8b7476a800e5e9cb6afbb28
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Jun 12 16:12:30 2018 -0700

    Fix test-tokenizer failure due to not nulling the GError*.

diff --git a/gnucash/import-export/csv-imp/gnc-tokenizer.cpp b/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
index f8917f7..0a15fa0 100644
--- a/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
+++ b/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
@@ -47,7 +47,7 @@ GncTokenizer::load_file(const std::string& path)
     m_imp_file_str = path;
     char *raw_contents;
     size_t raw_length;
-    GError *error;
+    GError *error = nullptr;
 
     if (!g_file_get_contents(path.c_str(), &raw_contents, &raw_length, &error))
       throw std::ifstream::failure(error->message);

commit 64837820edbb2eb6f6e4371f73b43f476edd48f0
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Jun 10 14:26:39 2018 +0100

    Bug 795831 - When read only threshold set, dates are silently changed
    
    When you have specified a read only threshold, the date is silently
    changed if it's beyond the threshold. There was already code to present
    a dialog informing of this but was disabled so enable it.

diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c
index aa7f877..203152f 100644
--- a/gnucash/gnome-utils/dialog-utils.c
+++ b/gnucash/gnome-utils/dialog-utils.c
@@ -333,15 +333,26 @@ gnc_gdate_in_valid_range (GDate *test_date, gboolean warn)
     GDate *max_date = g_date_new_dmy (1,1,10000);
     GDate *min_date;
     gboolean ret = FALSE;
+    gboolean max_date_ok = FALSE;
+    gboolean min_date_ok = FALSE;
 
     if (use_autoreadonly)
         min_date = qof_book_get_autoreadonly_gdate (gnc_get_current_book());
     else
         min_date = g_date_new_dmy (1,1,1400);
 
-    if ((g_date_compare (max_date, test_date) > 0) &&
-        (g_date_compare (min_date, test_date) <= 0))
-        ret = TRUE;
+    // max date
+    if (g_date_compare (max_date, test_date) > 0)
+        max_date_ok = TRUE;
+
+    // min date
+    if (g_date_compare (min_date, test_date) <= 0)
+        min_date_ok = TRUE;
+
+    if (use_autoreadonly && warn)
+        ret = max_date_ok;
+    else
+        ret = min_date_ok & max_date_ok;
 
     if (warn && !ret)
     {
diff --git a/gnucash/register/register-gnome/datecell-gnome.c b/gnucash/register/register-gnome/datecell-gnome.c
index 71bf525..f38374c 100644
--- a/gnucash/register/register-gnome/datecell-gnome.c
+++ b/gnucash/register/register-gnome/datecell-gnome.c
@@ -41,6 +41,7 @@
 
 #include "datecell.h"
 #include "dialog-utils.h"
+#include "gnc-ui.h"
 #include "gnc-ui-util.h"
 #include "gnucash-date-picker.h"
 #include "gnucash-item-edit.h"
@@ -92,34 +93,35 @@ static gboolean gnc_date_cell_enter (BasicCell *bcell,
 static void gnc_date_cell_leave (BasicCell *bcell);
 
 static gboolean
-check_readonly_threshold (const gchar *datestr, GDate *d)
+check_readonly_threshold (const gchar *datestr, GDate *d, gboolean warn)
 {
     GDate *readonly_threshold = qof_book_get_autoreadonly_gdate(gnc_get_current_book());
     if (g_date_compare(d, readonly_threshold) < 0)
     {
-#if 0
-    gchar *dialog_msg = _("The entered date of the new transaction is "
-                  "older than the \"Read-Only Threshold\" set for "
-                  "this book. This setting can be changed in "
-                  "File -> Properties -> Accounts.");
-    gchar *dialog_title = _("Cannot store a transaction at this date");
-    GtkWidget *dialog = gtk_message_dialog_new(NULL,
-                           0,
-                           GTK_MESSAGE_ERROR,
-                           GTK_BUTTONS_OK,
-                           "%s", dialog_title);
-    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
-                         "%s", dialog_msg);
-    gtk_dialog_run(GTK_DIALOG(dialog));
-    gtk_widget_destroy(dialog);
-#endif
-    g_warning("Entered date %s is before the \"auto-read-only threshold\";"
-          " resetting to the threshold.", datestr);
-
-    // Reset the date to the threshold date
-    g_date_set_julian (d, g_date_get_julian (readonly_threshold));
-    g_date_free (readonly_threshold);
-    return TRUE;
+        if (warn)
+        {
+            gchar *dialog_msg = _("The entered date of the transaction is "
+                          "older than the \"Read-Only Threshold\" set for "
+                          "this book. This setting can be changed in "
+                          "File -> Properties -> Accounts, resetting to the threshold.");
+            gchar *dialog_title = _("Cannot store a transaction at this date");
+            GtkWidget *dialog = gtk_message_dialog_new(gnc_ui_get_main_window (NULL),
+                                   0,
+                                   GTK_MESSAGE_ERROR,
+                                   GTK_BUTTONS_OK,
+                                   "%s", dialog_title);
+            gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
+                                 "%s", dialog_msg);
+            gtk_dialog_run (GTK_DIALOG(dialog));
+            gtk_widget_destroy (dialog);
+
+//        g_warning("Entered date %s is before the \"auto-read-only threshold\";"
+//              " resetting to the threshold.", datestr);
+        }
+        // Reset the date to the threshold date
+        g_date_set_julian (d, g_date_get_julian (readonly_threshold));
+        g_date_free (readonly_threshold);
+        return TRUE;
     }
     g_date_free (readonly_threshold);
     return FALSE;
@@ -161,14 +163,13 @@ gnc_parse_date (struct tm *parsed, const char * datestr, gboolean warn)
     // older than the threshold.
     if (use_autoreadonly)
     {
-        GDate *d = g_date_new_dmy(day, month, year);
-        if (check_readonly_threshold (datestr, d))
+        g_date_set_dmy (test_date, day, month, year);
+        if (check_readonly_threshold (datestr, test_date, warn))
         {
-            day = g_date_get_day (d);
-            month = g_date_get_month (d);
-            year = g_date_get_year (d);
+            day = g_date_get_day (test_date);
+            month = g_date_get_month (test_date);
+            year = g_date_get_year (test_date);
         }
-        g_date_free (d);
     }
     g_date_free (test_date);
 

commit 2384af6068741641487316b83a6ac5de1454989c
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Jun 10 14:24:34 2018 +0100

    Add a dialog to warn users that date is out of range
    
    When the date is out of range present a dialog advising this and also
    advise that date will be reset to this year.

diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c
index 0cd369e..aa7f877 100644
--- a/gnucash/gnome-utils/dialog-utils.c
+++ b/gnucash/gnome-utils/dialog-utils.c
@@ -39,6 +39,7 @@
 #include "gnc-path.h"
 #include "gnc-engine.h"
 #include "gnc-euro.h"
+#include "gnc-ui.h"
 #include "gnc-ui-util.h"
 #include "gnc-prefs.h"
 #include "gnc-combott.h"
@@ -325,16 +326,16 @@ gnc_draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer direction)
 }
 
 
-static gboolean
-gnc_gdate_in_valid_range (GDate *test_date)
+gboolean
+gnc_gdate_in_valid_range (GDate *test_date, gboolean warn)
 {
-    gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());
+    gboolean use_autoreadonly = qof_book_uses_autoreadonly (gnc_get_current_book());
     GDate *max_date = g_date_new_dmy (1,1,10000);
     GDate *min_date;
     gboolean ret = FALSE;
 
     if (use_autoreadonly)
-        min_date = qof_book_get_autoreadonly_gdate(gnc_get_current_book());
+        min_date = qof_book_get_autoreadonly_gdate (gnc_get_current_book());
     else
         min_date = g_date_new_dmy (1,1,1400);
 
@@ -342,6 +343,21 @@ gnc_gdate_in_valid_range (GDate *test_date)
         (g_date_compare (min_date, test_date) <= 0))
         ret = TRUE;
 
+    if (warn && !ret)
+    {
+        gchar *dialog_msg = _("The entered date is out of the range "
+                  "01/01/1400 - 31/12/9999, resetting to this year");
+        gchar *dialog_title = _("Date out of range");
+        GtkWidget *dialog = gtk_message_dialog_new (gnc_ui_get_main_window (NULL),
+                               0,
+                               GTK_MESSAGE_ERROR,
+                               GTK_BUTTONS_OK,
+                               "%s", dialog_title);
+        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
+                             "%s", dialog_msg);
+        gtk_dialog_run (GTK_DIALOG(dialog));
+        gtk_widget_destroy (dialog);
+    }
     g_date_free (max_date);
     g_date_free (min_date);
     return ret;
@@ -392,7 +408,7 @@ gnc_handle_date_accelerator (GdkEventKey *event,
         else
             g_date_add_days (&gdate, 1);
 
-        if (gnc_gdate_in_valid_range (&gdate))
+        if (gnc_gdate_in_valid_range (&gdate, FALSE))
             g_date_to_struct_tm (&gdate, tm);
         return TRUE;
 
@@ -428,7 +444,7 @@ gnc_handle_date_accelerator (GdkEventKey *event,
         else
             g_date_subtract_days (&gdate, 1);
 
-        if (gnc_gdate_in_valid_range (&gdate))
+        if (gnc_gdate_in_valid_range (&gdate, FALSE))
             g_date_to_struct_tm (&gdate, tm);
         return TRUE;
 
@@ -499,7 +515,7 @@ gnc_handle_date_accelerator (GdkEventKey *event,
     default:
         return FALSE;
     }
-    if (gnc_gdate_in_valid_range (&gdate))
+    if (gnc_gdate_in_valid_range (&gdate, FALSE))
         g_date_to_struct_tm (&gdate, tm);
 
     return TRUE;
diff --git a/gnucash/gnome-utils/dialog-utils.h b/gnucash/gnome-utils/dialog-utils.h
index 06d7ff8..37cb849 100644
--- a/gnucash/gnome-utils/dialog-utils.h
+++ b/gnucash/gnome-utils/dialog-utils.h
@@ -98,6 +98,8 @@ void gnc_widget_set_style_context (GtkWidget *widget, const char *gnc_class);
 \********************************************************************/
 gboolean gnc_draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer direction);
 
+gboolean gnc_gdate_in_valid_range (GDate *test_date, gboolean warn);
+
 gboolean gnc_handle_date_accelerator (GdkEventKey *event,
                                       struct tm *tm,
                                       const char *date_str);
diff --git a/gnucash/register/register-gnome/datecell-gnome.c b/gnucash/register/register-gnome/datecell-gnome.c
index 47bdd8d..71bf525 100644
--- a/gnucash/register/register-gnome/datecell-gnome.c
+++ b/gnucash/register/register-gnome/datecell-gnome.c
@@ -126,10 +126,11 @@ check_readonly_threshold (const gchar *datestr, GDate *d)
 }
 
 static void
-gnc_parse_date (struct tm *parsed, const char * datestr)
+gnc_parse_date (struct tm *parsed, const char * datestr, gboolean warn)
 {
     int day, month, year;
     gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());
+    GDate *test_date;
 
     if (!parsed) return;
     if (!datestr) return;
@@ -146,6 +147,16 @@ gnc_parse_date (struct tm *parsed, const char * datestr)
         year = tm_today.tm_year + 1900;
     }
 
+    test_date = g_date_new_dmy (day, month, year);
+
+    if (!gnc_gdate_in_valid_range (test_date, warn))
+    {
+        struct tm tm_today;
+        memset (&tm_today, 0, sizeof (struct tm));
+        gnc_tm_get_today_start (&tm_today);
+        year = tm_today.tm_year + 1900;
+    }
+
     // If we have an auto-read-only threshold, do not accept a date that is
     // older than the threshold.
     if (use_autoreadonly)
@@ -159,6 +170,7 @@ gnc_parse_date (struct tm *parsed, const char * datestr)
         }
         g_date_free (d);
     }
+    g_date_free (test_date);
 
     parsed->tm_mday = day;
     parsed->tm_mon  = month - 1;
@@ -452,7 +464,7 @@ gnc_date_cell_commit (DateCell *cell)
     if (!cell)
         return;
 
-    gnc_parse_date (&(box->date), cell->cell.value);
+    gnc_parse_date (&(box->date), cell->cell.value, FALSE);
 
     qof_print_date_dmy_buff (buff, MAX_DATE_LENGTH,
                              box->date.tm_mday,
@@ -581,9 +593,8 @@ gnc_date_cell_modify_verify (BasicCell *_cell,
     /* keep a copy of the new value */
     if (accept)
     {
-
         gnc_basic_cell_set_value_internal (&cell->cell, newval);
-        gnc_parse_date (&(box->date), newval);
+        gnc_parse_date (&(box->date), newval, FALSE);
 
         if (!box->date_picker)
             return;
@@ -710,7 +721,7 @@ gnc_date_cell_get_date_gdate (DateCell *cell, GDate *date)
     if (!cell || !date)
         return;
 
-    gnc_parse_date (&(box->date), cell->cell.value);
+    gnc_parse_date (&(box->date), cell->cell.value, FALSE);
 
     g_date_set_dmy(date,
                    box->date.tm_mday,
@@ -724,7 +735,8 @@ gnc_date_cell_get_date (DateCell *cell, time64 *time)
     PopBox *box = cell->cell.gui_private;
     if (!cell || !time)
         return;
-    gnc_parse_date (&(box->date), cell->cell.value);
+
+    gnc_parse_date (&(box->date), cell->cell.value, TRUE);
     *time = gnc_mktime (&box->date);
 }
 
@@ -735,7 +747,7 @@ gnc_date_cell_set_value_internal (BasicCell *_cell, const char *str)
     PopBox *box = cell->cell.gui_private;
     char buff[DATE_BUF];
 
-    gnc_parse_date (&(box->date), str);
+    gnc_parse_date (&(box->date), str, FALSE);
 
     qof_print_date_dmy_buff (buff, MAX_DATE_LENGTH,
                              box->date.tm_mday,

commit a73f9123f9fc936bbbfe0ea05b0cc06c52b9ab6e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Jun 9 15:10:12 2018 +0100

    Fix some indentation in datecell-gnome.c

diff --git a/gnucash/register/register-gnome/datecell-gnome.c b/gnucash/register/register-gnome/datecell-gnome.c
index 604933c..47bdd8d 100644
--- a/gnucash/register/register-gnome/datecell-gnome.c
+++ b/gnucash/register/register-gnome/datecell-gnome.c
@@ -139,7 +139,7 @@ gnc_parse_date (struct tm *parsed, const char * datestr)
         // Couldn't parse date, use today
         struct tm tm_today;
 
-    memset (&tm_today, 0, sizeof (struct tm));
+        memset (&tm_today, 0, sizeof (struct tm));
         gnc_tm_get_today_start (&tm_today);
         day = tm_today.tm_mday;
         month = tm_today.tm_mon + 1;
@@ -151,13 +151,13 @@ gnc_parse_date (struct tm *parsed, const char * datestr)
     if (use_autoreadonly)
     {
         GDate *d = g_date_new_dmy(day, month, year);
-    if (check_readonly_threshold (datestr, d))
-    {
-        day = g_date_get_day (d);
-        month = g_date_get_month (d);
-        year = g_date_get_year (d);
-    }
-    g_date_free (d);
+        if (check_readonly_threshold (datestr, d))
+        {
+            day = g_date_get_day (d);
+            month = g_date_get_month (d);
+            year = g_date_get_year (d);
+        }
+        g_date_free (d);
     }
 
     parsed->tm_mday = day;

commit 1f14d0f6296e69ace72ccc9f7042f89d74a16e55
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Jun 9 15:04:27 2018 +0100

    In qof_scan_date returns valid date when day and month are 0
    
    If you start typing a date in the register with the enable autoreadonly
    option starting with a 0, gdate complains when trying to create a valid
    date.

diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index edd6eac..3107f1a 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -936,6 +936,9 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
 
     g_free (dupe);
 
+    if ((imonth == 0) || (iday == 0))
+        return FALSE;
+
     if ((12 < imonth) || (31 < iday))
     {
         /*

commit 00e6ccdda0fbc5bccbc9167e3f224a8200617061
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Jun 9 15:01:30 2018 +0100

    Bug 796398 - Restrict accelerator keys to valid date range
    
    Valid date range is 01/01/1400 - 31/12/9999 so only allow accelerator
    keys in this range.

diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c
index f6db0e0..0cd369e 100644
--- a/gnucash/gnome-utils/dialog-utils.c
+++ b/gnucash/gnome-utils/dialog-utils.c
@@ -325,6 +325,29 @@ gnc_draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer direction)
 }
 
 
+static gboolean
+gnc_gdate_in_valid_range (GDate *test_date)
+{
+    gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());
+    GDate *max_date = g_date_new_dmy (1,1,10000);
+    GDate *min_date;
+    gboolean ret = FALSE;
+
+    if (use_autoreadonly)
+        min_date = qof_book_get_autoreadonly_gdate(gnc_get_current_book());
+    else
+        min_date = g_date_new_dmy (1,1,1400);
+
+    if ((g_date_compare (max_date, test_date) > 0) &&
+        (g_date_compare (min_date, test_date) <= 0))
+        ret = TRUE;
+
+    g_date_free (max_date);
+    g_date_free (min_date);
+    return ret;
+}
+
+
 gboolean
 gnc_handle_date_accelerator (GdkEventKey *event,
                              struct tm *tm,
@@ -368,7 +391,9 @@ gnc_handle_date_accelerator (GdkEventKey *event,
             g_date_add_years (&gdate, 1);
         else
             g_date_add_days (&gdate, 1);
-        g_date_to_struct_tm (&gdate, tm);
+
+        if (gnc_gdate_in_valid_range (&gdate))
+            g_date_to_struct_tm (&gdate, tm);
         return TRUE;
 
     case GDK_KEY_minus:
@@ -402,7 +427,9 @@ gnc_handle_date_accelerator (GdkEventKey *event,
             g_date_subtract_years (&gdate, 1);
         else
             g_date_subtract_days (&gdate, 1);
-        g_date_to_struct_tm (&gdate, tm);
+
+        if (gnc_gdate_in_valid_range (&gdate))
+            g_date_to_struct_tm (&gdate, tm);
         return TRUE;
 
     default:
@@ -472,8 +499,8 @@ gnc_handle_date_accelerator (GdkEventKey *event,
     default:
         return FALSE;
     }
-
-    g_date_to_struct_tm (&gdate, tm);
+    if (gnc_gdate_in_valid_range (&gdate))
+        g_date_to_struct_tm (&gdate, tm);
 
     return TRUE;
 }



Summary of changes:
 gnucash/gnome-utils/dialog-utils.c               | 62 +++++++++++++++-
 gnucash/gnome-utils/dialog-utils.h               |  2 +
 gnucash/import-export/csv-imp/gnc-tokenizer.cpp  |  2 +-
 gnucash/register/register-gnome/datecell-gnome.c | 93 ++++++++++++++----------
 libgnucash/engine/gnc-date.cpp                   |  3 +
 5 files changed, 117 insertions(+), 45 deletions(-)



More information about the gnucash-changes mailing list