gnucash maint: Multiple changes pushed
Geert Janssens
gjanssens at code.gnucash.org
Fri Aug 31 17:58:08 EDT 2018
Updated via https://github.com/Gnucash/gnucash/commit/bf00330e (commit)
via https://github.com/Gnucash/gnucash/commit/131df821 (commit)
via https://github.com/Gnucash/gnucash/commit/2dcb3162 (commit)
via https://github.com/Gnucash/gnucash/commit/fd750a22 (commit)
via https://github.com/Gnucash/gnucash/commit/8ad6e045 (commit)
via https://github.com/Gnucash/gnucash/commit/3456596a (commit)
via https://github.com/Gnucash/gnucash/commit/67ee1d99 (commit)
via https://github.com/Gnucash/gnucash/commit/aabae1ca (commit)
via https://github.com/Gnucash/gnucash/commit/dd49756f (commit)
via https://github.com/Gnucash/gnucash/commit/995e6b0f (commit)
via https://github.com/Gnucash/gnucash/commit/39b24325 (commit)
from https://github.com/Gnucash/gnucash/commit/caaf9edc (commit)
commit bf00330eedba3543e66417224788dcfc1406b96d
Merge: 131df82 995e6b0
Author: Geert Janssens <geert at kobaltwit.be>
Date: Fri Aug 31 23:55:01 2018 +0200
Merge branch 'Bug796725' of https://github.com/Bob-IT/gnucash into maint
commit 131df82135e67fa5b5b941b9a5f60b6545071b6d
Merge: caaf9ed 2dcb316
Author: Geert Janssens <geert at kobaltwit.be>
Date: Fri Aug 31 22:01:45 2018 +0200
Merge branch 'date-bugs' of https://github.com/Bob-IT/gnucash into maint
commit 2dcb31628094636219a0a3e5466d7d802b117e0d
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sat Aug 25 11:08:32 2018 +0100
White space removal and change tabs to spaces in qofbook.cpp/h
diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp
index 1ac6223..15f3a7f 100644
--- a/libgnucash/engine/qofbook.cpp
+++ b/libgnucash/engine/qofbook.cpp
@@ -66,30 +66,30 @@ static QofLogModule log_module = QOF_MOD_ENGINE;
enum
{
PROP_0,
-// PROP_ROOT_ACCOUNT, /* Table */
-// PROP_ROOT_TEMPLATE, /* Table */
+// PROP_ROOT_ACCOUNT, /* Table */
+// PROP_ROOT_TEMPLATE, /* Table */
/* keep trading accounts property, while adding book-currency, default gains
policy and default gains account properties, so that files prior to 2.7 can
be read/processed; GUI changed to use all four properties as of 2.7.
Trading accounts, on the one hand, and book-currency plus default-gains-
policy, and optionally, default gains account, on the other, are mutually
exclusive */
- PROP_OPT_TRADING_ACCOUNTS, /* KVP */
+ PROP_OPT_TRADING_ACCOUNTS, /* KVP */
/* Book currency and default gains policy properties only apply if currency
accounting method selected in GUI is 'book-currency'; both required and
both are exclusive with trading accounts */
- PROP_OPT_BOOK_CURRENCY, /* KVP */
- PROP_OPT_DEFAULT_GAINS_POLICY, /* KVP */
+ PROP_OPT_BOOK_CURRENCY, /* KVP */
+ PROP_OPT_DEFAULT_GAINS_POLICY, /* KVP */
/* Default gains account property only applies if currency accounting method
selected in GUI is 'book-currency'; its use is optional but exclusive with
trading accounts */
- PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID, /* KVP */
- PROP_OPT_AUTO_READONLY_DAYS,/* KVP */
- PROP_OPT_NUM_FIELD_SOURCE, /* KVP */
- PROP_OPT_DEFAULT_BUDGET, /* KVP */
- PROP_OPT_FY_END, /* KVP */
- PROP_AB_TEMPLATES, /* KVP */
- N_PROPERTIES /* Just a counter */
+ PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID, /* KVP */
+ PROP_OPT_AUTO_READONLY_DAYS, /* KVP */
+ PROP_OPT_NUM_FIELD_SOURCE, /* KVP */
+ PROP_OPT_DEFAULT_BUDGET, /* KVP */
+ PROP_OPT_FY_END, /* KVP */
+ PROP_AB_TEMPLATES, /* KVP */
+ N_PROPERTIES /* Just a counter */
};
static void
@@ -167,9 +167,9 @@ static const std::string str_OPTION_NAME_NUM_FIELD_SOURCE(OPTION_NAME_NUM_FIELD_
static void
qof_book_get_property (GObject* object,
- guint prop_id,
- GValue* value,
- GParamSpec* pspec)
+ guint prop_id,
+ GValue* value,
+ GParamSpec* pspec)
{
QofBook *book;
gchar *key;
@@ -221,9 +221,9 @@ qof_book_get_property (GObject* object,
static void
qof_book_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
QofBook *book;
gchar *key;
@@ -288,9 +288,9 @@ qof_book_class_init (QofBookClass *klass)
PROP_OPT_TRADING_ACCOUNTS,
g_param_spec_string("trading-accts",
"Use Trading Accounts",
- "Scheme true ('t') or NULL. If 't', then the book "
- "uses trading accounts for managing multiple-currency "
- "transactions.",
+ "Scheme true ('t') or NULL. If 't', then the book "
+ "uses trading accounts for managing multiple-currency "
+ "transactions.",
NULL,
G_PARAM_READWRITE));
@@ -299,9 +299,9 @@ qof_book_class_init (QofBookClass *klass)
PROP_OPT_BOOK_CURRENCY,
g_param_spec_string("book-currency",
"Select Book Currency",
- "The reference currency used to manage multiple-currency "
- "transactions when 'book-currency' currency accounting method "
- "selected; requires valid default gains/loss policy.",
+ "The reference currency used to manage multiple-currency "
+ "transactions when 'book-currency' currency accounting method "
+ "selected; requires valid default gains/loss policy.",
NULL,
G_PARAM_READWRITE));
@@ -310,10 +310,10 @@ qof_book_class_init (QofBookClass *klass)
PROP_OPT_DEFAULT_GAINS_POLICY,
g_param_spec_string("default-gains-policy",
"Select Default Gains Policy",
- "The default policy to be used to calculate gains/losses on "
- "dispositions of currencies/commodities other than "
- "'book-currency' when 'book-currency' currency accounting "
- "method selected; requires valid book-currency.",
+ "The default policy to be used to calculate gains/losses on "
+ "dispositions of currencies/commodities other than "
+ "'book-currency' when 'book-currency' currency accounting "
+ "method selected; requires valid book-currency.",
NULL,
G_PARAM_READWRITE));
@@ -322,10 +322,10 @@ qof_book_class_init (QofBookClass *klass)
PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID,
g_param_spec_boxed("default-gain-loss-account-guid",
"Select Default Gain/Loss Account",
- "The default account to be used for calculated gains/losses on "
- "dispositions of currencies/commodities other than "
- "'book-currency' when 'book-currency' currency accounting "
- "method selected; requires valid book-currency.",
+ "The default account to be used for calculated gains/losses on "
+ "dispositions of currencies/commodities other than "
+ "'book-currency' when 'book-currency' currency accounting "
+ "method selected; requires valid book-currency.",
GNC_TYPE_GUID,
G_PARAM_READWRITE));
@@ -334,8 +334,8 @@ qof_book_class_init (QofBookClass *klass)
PROP_OPT_NUM_FIELD_SOURCE,
g_param_spec_string(PARAM_NAME_NUM_FIELD_SOURCE,
"Use Split-Action in the Num Field",
- "Scheme true ('t') or NULL. If 't', then the book "
- "will put the split action value in the Num field.",
+ "Scheme true ('t') or NULL. If 't', then the book "
+ "will put the split action value in the Num field.",
NULL,
G_PARAM_READWRITE));
@@ -344,11 +344,11 @@ qof_book_class_init (QofBookClass *klass)
PROP_OPT_AUTO_READONLY_DAYS,
g_param_spec_double("autoreadonly-days",
"Transaction Auto-read-only Days",
- "Prevent editing of transactions posted more than "
- "this many days ago.",
- 0,
+ "Prevent editing of transactions posted more than "
+ "this many days ago.",
+ 0,
G_MAXDOUBLE,
- 0,
+ 0,
G_PARAM_READWRITE));
g_object_class_install_property
@@ -365,7 +365,7 @@ qof_book_class_init (QofBookClass *klass)
g_param_spec_boxed("fy-end",
"Book Fiscal Year End",
"A GDate with a bogus year having the last Month and "
- "Day of the Fiscal year for the book.",
+ "Day of the Fiscal year for the book.",
G_TYPE_DATE,
G_PARAM_READWRITE));
g_object_class_install_property
@@ -561,7 +561,7 @@ qof_book_set_data_fin (QofBook *book, const char *key, gpointer data, QofBookFin
if (!cb) return;
g_hash_table_insert (book->data_table_finalizers, (gpointer)key,
- reinterpret_cast<void*>(cb));
+ reinterpret_cast<void*>(cb));
}
gpointer
@@ -979,8 +979,8 @@ qof_book_get_book_currency_name (QofBook *book)
{
const gchar *opt = NULL;
qof_instance_get (QOF_INSTANCE (book),
- "book-currency", &opt,
- NULL);
+ "book-currency", &opt,
+ NULL);
return opt;
}
@@ -994,8 +994,8 @@ qof_book_get_default_gains_policy (QofBook *book)
{
const gchar *opt = NULL;
qof_instance_get (QOF_INSTANCE (book),
- "default-gains-policy", &opt,
- NULL);
+ "default-gains-policy", &opt,
+ NULL);
return opt;
}
@@ -1009,8 +1009,8 @@ qof_book_get_default_gain_loss_acct_guid (QofBook *book)
{
GncGUID *guid = NULL;
qof_instance_get (QOF_INSTANCE (book),
- "default-gain-loss-account-guid", &guid,
- NULL);
+ "default-gain-loss-account-guid", &guid,
+ NULL);
return guid;
}
@@ -1021,8 +1021,8 @@ qof_book_use_trading_accounts (const QofBook *book)
{
const char *opt = NULL;
qof_instance_get (QOF_INSTANCE (book),
- "trading-accts", &opt,
- NULL);
+ "trading-accts", &opt,
+ NULL);
if (opt && opt[0] == 't' && opt[1] == 0)
return TRUE;
return FALSE;
@@ -1225,7 +1225,7 @@ qof_book_load_options (QofBook *book, GNCOptionLoad load_cb, GNCOptionDB *odb)
void
qof_book_save_options (QofBook *book, GNCOptionSave save_cb,
- GNCOptionDB* odb, gboolean clear)
+ GNCOptionDB* odb, gboolean clear)
{
/* Wrap this in begin/commit so that it commits only once instead of doing
* so for every option. Qof_book_set_option will take care of dirtying the
diff --git a/libgnucash/engine/qofbook.h b/libgnucash/engine/qofbook.h
index 266e118..f2b4ae4 100644
--- a/libgnucash/engine/qofbook.h
+++ b/libgnucash/engine/qofbook.h
@@ -148,15 +148,16 @@ struct _QofBook
* from the session. Better solutions welcome ... */
QofBackend *backend;
- /* A cached value of the OPTION_NAME_NUM_FIELD_SOURCE option value because
- * it is queried quite a lot, so we want to avoid a KVP lookup on each query
- */
+ /* A cached value of the OPTION_NAME_NUM_FIELD_SOURCE option value
+ * because it is queried quite a lot, so we want to avoid a KVP
+ * lookup on each query */
gboolean cached_num_field_source;
/* Whether the above cached value is valid. */
gboolean cached_num_field_source_isvalid;
- /* A cahed value of the "autoreadonly-days" option value because it is
- * queried quite a lot, so we want to avoid a KVP lookup on each query */
+ /* A cahed value of the "autoreadonly-days" option value because
+ * it is queried quite a lot, so we want to avoid a KVP lookup on
+ * each query */
gint cached_num_days_autoreadonly;
/* Whether the above cached value is valid. */
gboolean cached_num_days_autoreadonly_isvalid;
@@ -180,7 +181,7 @@ GType qof_book_get_type(void);
* but not somewhere inline in the code. */
#define QOF_BOOK_RETURN_ENTITY(book,guid,e_type,c_type) { \
QofInstance *val = NULL; \
- if ((guid != NULL) && (book != NULL)) { \
+ if ((guid != NULL) && (book != NULL)) { \
const QofCollection *col; \
col = qof_book_get_collection (book, e_type); \
val = qof_collection_lookup_entity (col, guid); \
@@ -191,7 +192,7 @@ GType qof_book_get_type(void);
/** GList of QofBook */
-typedef GList QofBookList;
+typedef GList QofBookList;
typedef void (*QofBookFinalCB) (QofBook *, gpointer key, gpointer user_data);
@@ -204,7 +205,7 @@ QofBook * qof_book_new (void);
/** End any editing sessions associated with book, and free all memory
associated with it. */
-void qof_book_destroy (QofBook *book);
+void qof_book_destroy (QofBook *book);
/** Close a book to editing.
@@ -390,7 +391,7 @@ void qof_book_commit_edit(QofBook *book);
* @param odb: The GNCOptionDB to load.
*/
void qof_book_load_options (QofBook *book, GNCOptionLoad load_cb,
- GNCOptionDB *odb);
+ GNCOptionDB *odb);
/** Save a GNCOptionsDB back to the book's KVP.
* @param book: The book.
* @param save_cb: A callback function that does the saving.
commit fd750a22ebe34fad3ec78a7fb69e51537cd3eaec
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Fri Aug 24 16:57:58 2018 +0100
Cache the number of days read only value
The KVP value for the qof_book_get_num_days_autoreadonly was being
called many times so it makes sense to cache it in the book to avoid
the KVP lookup.
diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c
index 77e7539..03a498a 100644
--- a/gnucash/gnome-utils/gnc-main-window.c
+++ b/gnucash/gnome-utils/gnc-main-window.c
@@ -4025,7 +4025,8 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
qof_book_use_split_action_for_num_field (book);
gboolean use_book_currency_before =
gnc_book_use_book_currency (book);
- gint use_read_only_threshold_before = qof_book_get_num_days_autoreadonly (book);
+ gint use_read_only_threshold_before =
+ qof_book_get_num_days_autoreadonly (book);
gboolean use_split_action_for_num_after;
gboolean use_book_currency_after;
gint use_read_only_threshold_after;
@@ -4037,7 +4038,7 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
results = gnc_option_db_commit (options);
for (iter = results; iter; iter = iter->next)
{
- GtkWidget *dialog = gtk_message_dialog_new(NULL,
+ GtkWidget *dialog = gtk_message_dialog_new(gnc_ui_get_main_window (NULL),
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
@@ -4053,7 +4054,11 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
use_split_action_for_num_after =
qof_book_use_split_action_for_num_field (book);
use_book_currency_after = gnc_book_use_book_currency (book);
+
+ // mark cached value as invalid so we get new value
+ book->cached_num_days_autoreadonly_isvalid = FALSE;
use_read_only_threshold_after = qof_book_get_num_days_autoreadonly (book);
+
if (use_split_action_for_num_before != use_split_action_for_num_after)
{
gnc_book_option_num_field_source_change_cb (
diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp
index bf54dcc..1ac6223 100644
--- a/libgnucash/engine/qofbook.cpp
+++ b/libgnucash/engine/qofbook.cpp
@@ -96,8 +96,14 @@ static void
qof_book_option_num_field_source_changed_cb (GObject *gobject,
GParamSpec *pspec,
gpointer user_data);
+static void
+qof_book_option_num_autoreadonly_changed_cb (GObject *gobject,
+ GParamSpec *pspec,
+ gpointer user_data);
+
// Use a #define for the GParam name to avoid typos
#define PARAM_NAME_NUM_FIELD_SOURCE "split-action-num-field"
+#define PARAM_NAME_NUM_AUTOREAD_ONLY "autoreadonly-days"
QOF_GOBJECT_GET_TYPE(QofBook, qof_book, QOF_TYPE_INSTANCE, {});
QOF_GOBJECT_DISPOSE(qof_book);
@@ -134,6 +140,7 @@ qof_book_init (QofBook *book)
book->session_dirty = FALSE;
book->version = 0;
book->cached_num_field_source_isvalid = FALSE;
+ book->cached_num_days_autoreadonly_isvalid = FALSE;
// Register a callback on this NUM_FIELD_SOURCE property of that object
// because it gets called quite a lot, so that its value must be stored in
@@ -142,6 +149,14 @@ qof_book_init (QofBook *book)
"notify::" PARAM_NAME_NUM_FIELD_SOURCE,
G_CALLBACK (qof_book_option_num_field_source_changed_cb),
book);
+
+ // Register a callback on this NUM_AUTOREAD_ONLY property of that object
+ // because it gets called quite a lot, so that its value must be stored in
+ // a bool member variable instead of a KVP lookup on each getter call.
+ g_signal_connect (G_OBJECT(book),
+ "notify::" PARAM_NAME_NUM_AUTOREAD_ONLY,
+ G_CALLBACK (qof_book_option_num_autoreadonly_changed_cb),
+ book);
}
static const std::string str_KVP_OPTION_PATH(KVP_OPTION_PATH);
@@ -1065,11 +1080,21 @@ gboolean qof_book_uses_autoreadonly (const QofBook *book)
gint qof_book_get_num_days_autoreadonly (const QofBook *book)
{
g_assert(book);
- double tmp;
- qof_instance_get (QOF_INSTANCE (book),
- "autoreadonly-days", &tmp,
- NULL);
- return (gint) tmp;
+
+ if (!book->cached_num_days_autoreadonly_isvalid)
+ {
+ double tmp;
+
+ // No cached value? Then do the expensive KVP lookup
+ qof_instance_get (QOF_INSTANCE (book),
+ PARAM_NAME_NUM_AUTOREAD_ONLY, &tmp,
+ NULL);
+
+ const_cast<QofBook*>(book)->cached_num_days_autoreadonly = tmp;
+ const_cast<QofBook*>(book)->cached_num_days_autoreadonly_isvalid = TRUE;
+ }
+ // Value is cached now. Use the cheap variable returning.
+ return (gint) book->cached_num_days_autoreadonly;
}
GDate* qof_book_get_autoreadonly_gdate (const QofBook *book)
@@ -1087,6 +1112,19 @@ GDate* qof_book_get_autoreadonly_gdate (const QofBook *book)
return result;
}
+// The callback that is called when the KVP option value of
+// "autoreadonly-days" changes, so that we mark the cached value as
+// invalid.
+static void
+qof_book_option_num_autoreadonly_changed_cb (GObject *gobject,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ QofBook *book = reinterpret_cast<QofBook*>(user_data);
+ g_return_if_fail(QOF_IS_BOOK(book));
+ book->cached_num_days_autoreadonly_isvalid = FALSE;
+}
+
/* Note: this will fail if the book slots we're looking for here are flattened at some point !
* When that happens, this function can be removed. */
static Path opt_name_to_path (const char* opt_name)
diff --git a/libgnucash/engine/qofbook.h b/libgnucash/engine/qofbook.h
index c695de3..266e118 100644
--- a/libgnucash/engine/qofbook.h
+++ b/libgnucash/engine/qofbook.h
@@ -154,6 +154,12 @@ struct _QofBook
gboolean cached_num_field_source;
/* Whether the above cached value is valid. */
gboolean cached_num_field_source_isvalid;
+
+ /* A cahed value of the "autoreadonly-days" option value because it is
+ * queried quite a lot, so we want to avoid a KVP lookup on each query */
+ gint cached_num_days_autoreadonly;
+ /* Whether the above cached value is valid. */
+ gboolean cached_num_days_autoreadonly_isvalid;
};
struct _QofBookClass
commit 8ad6e04549e8f971ad76baee29fabfaa9240cb4a
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Fri Aug 24 16:52:17 2018 +0100
Book Options did not raise when already open
If you open File->Properties and the dialogue gets hidden and you go to
open it again the existing dialogue was not being raised to the front.
This was due to a bad cast.
diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c
index 240aed1..77e7539 100644
--- a/gnucash/gnome-utils/gnc-main-window.c
+++ b/gnucash/gnome-utils/gnc-main-window.c
@@ -4098,10 +4098,15 @@ static gboolean
show_handler (const char *class_name, gint component_id,
gpointer user_data, gpointer iter_data)
{
- GtkWidget *dialog;
+ GNCOptionWin *optwin = user_data;
+ GtkWidget *widget;
- dialog = GTK_WIDGET(user_data);
- gtk_window_present(GTK_WINDOW(dialog));
+ if (!optwin)
+ return(FALSE);
+
+ widget = gnc_options_dialog_widget(optwin);
+
+ gtk_window_present(GTK_WINDOW(widget));
return(TRUE);
}
commit 3456596a1c006b5ec317e4482b9455548ef0a579
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Wed Aug 22 20:40:17 2018 +0100
Bug 796814 - Changing a book's read-only threshold doesn't immediately affect open registers
Add test for change of read-only threshold to helper function for the
gnc_book_options_dialog_apply_cb which will then do a gui refresh.
diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c
index ae4505f..240aed1 100644
--- a/gnucash/gnome-utils/gnc-main-window.c
+++ b/gnucash/gnome-utils/gnc-main-window.c
@@ -4025,8 +4025,10 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
qof_book_use_split_action_for_num_field (book);
gboolean use_book_currency_before =
gnc_book_use_book_currency (book);
+ gint use_read_only_threshold_before = qof_book_get_num_days_autoreadonly (book);
gboolean use_split_action_for_num_after;
gboolean use_book_currency_after;
+ gint use_read_only_threshold_after;
gboolean return_val = FALSE;
GList *results = NULL, *iter;
@@ -4051,6 +4053,7 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
use_split_action_for_num_after =
qof_book_use_split_action_for_num_field (book);
use_book_currency_after = gnc_book_use_book_currency (book);
+ use_read_only_threshold_after = qof_book_get_num_days_autoreadonly (book);
if (use_split_action_for_num_before != use_split_action_for_num_after)
{
gnc_book_option_num_field_source_change_cb (
@@ -4062,6 +4065,9 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
gnc_book_option_book_currency_selected_cb (use_book_currency_after);
return_val = TRUE;
}
+ if (use_read_only_threshold_before != use_read_only_threshold_after)
+ return_val = TRUE;
+
qof_book_commit_edit (book);
return return_val;
}
commit 67ee1d99a4e7b226c98ab84a04864ed390ba9f2f
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Wed Aug 22 20:38:36 2018 +0100
Bug 796812 - gnc_date_cell_get_date and gnc_date_cell_get_date_gdate have different date validation behaviour - part 2
Change the two register get_help functions to use gnc_date_cell_get_date
with the warn parameter FALSE, this way we only get one warning when the
date is out of range.
Also as no functions use gnc_date_cell_get_date_gdate it can be removed.
diff --git a/gnucash/register/ledger-core/gncEntryLedgerModel.c b/gnucash/register/ledger-core/gncEntryLedgerModel.c
index 190809d..0a12383 100644
--- a/gnucash/register/ledger-core/gncEntryLedgerModel.c
+++ b/gnucash/register/ledger-core/gncEntryLedgerModel.c
@@ -564,19 +564,18 @@ static char * get_date_help (VirtualLocation virt_loc, gpointer user_data)
{
GncEntryLedger *ledger = user_data;
BasicCell *cell;
- char string[1024];
- GDate date;
+ const char *date_string;
+ time64 cell_time;
cell = gnc_table_get_cell (ledger->table, virt_loc);
if (!cell || !cell->value || *cell->value == '\0')
return NULL;
- g_date_clear (&date, 1);
- gnc_date_cell_get_date_gdate ((DateCell *) cell, &date);
+ gnc_date_cell_get_date ((DateCell *) cell, &cell_time, FALSE);
- g_date_strftime (string, sizeof (string), _("%A %d %B %Y"), &date);
+ date_string = gnc_print_time64 (cell_time, _("%A %d %B %Y"));
- return g_strdup (string);
+ return g_strdup (date_string);
}
static char * get_desc_help (VirtualLocation virt_loc, gpointer user_data)
diff --git a/gnucash/register/ledger-core/split-register-model.c b/gnucash/register/ledger-core/split-register-model.c
index 0ecf31f..d4c28d5 100644
--- a/gnucash/register/ledger-core/split-register-model.c
+++ b/gnucash/register/ledger-core/split-register-model.c
@@ -968,19 +968,18 @@ gnc_split_register_get_date_help (VirtualLocation virt_loc,
{
SplitRegister *reg = user_data;
BasicCell *cell;
- char string[1024];
- GDate date;
+ const char *date_string;
+ time64 cell_time;
cell = gnc_table_get_cell (reg->table, virt_loc);
if (!cell || !cell->value || *cell->value == '\0')
return NULL;
- g_date_clear (&date, 1);
- gnc_date_cell_get_date_gdate ((DateCell *) cell, &date);
+ gnc_date_cell_get_date ((DateCell *) cell, &cell_time, FALSE);
- g_date_strftime (string, sizeof (string), _("%A %d %B %Y"), &date);
+ date_string = gnc_print_time64 (cell_time, _("%A %d %B %Y"));
- return g_strdup (string);
+ return g_strdup (date_string);
}
static const char *
diff --git a/gnucash/register/register-core/datecell.h b/gnucash/register/register-core/datecell.h
index 709b7bc..8f96b7a 100644
--- a/gnucash/register/register-core/datecell.h
+++ b/gnucash/register/register-core/datecell.h
@@ -127,11 +127,5 @@ void gnc_date_cell_commit (DateCell *cell);
*/
void gnc_date_cell_get_date (DateCell *cell, time64 *time, gboolean warn);
-/** Set a GDate to the value in the DateCell.
- * @param cell The DateCell
- * @param date A GDate* into which the functino will write the date.
- */
-
-void gnc_date_cell_get_date_gdate (DateCell *cell, GDate *date);
/** @} */
#endif
diff --git a/gnucash/register/register-gnome/datecell-gnome.c b/gnucash/register/register-gnome/datecell-gnome.c
index 3b0399b..8018516 100644
--- a/gnucash/register/register-gnome/datecell-gnome.c
+++ b/gnucash/register/register-gnome/datecell-gnome.c
@@ -715,22 +715,6 @@ gnc_date_cell_leave (BasicCell *bcell)
}
void
-gnc_date_cell_get_date_gdate (DateCell *cell, GDate *date)
-{
- PopBox *box = cell->cell.gui_private;
-
- if (!cell || !date)
- return;
-
- gnc_parse_date (&(box->date), cell->cell.value, FALSE);
-
- g_date_set_dmy(date,
- box->date.tm_mday,
- box->date.tm_mon + 1,
- box->date.tm_year + 1900);
-}
-
-void
gnc_date_cell_get_date (DateCell *cell, time64 *time, gboolean warn)
{
PopBox *box = cell->cell.gui_private;
commit aabae1caf9e0cbf70266ecf8a265c97ffb3326a0
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Wed Aug 22 20:36:51 2018 +0100
Bug 796812 - gnc_date_cell_get_date and gnc_date_cell_get_date_gdate have different date validation behaviour - part 1
Add gboolean parameter to gnc_date_cell_get_date to enable warning for
the date out of range dialogue and update every occurrence accordingly.
diff --git a/gnucash/register/ledger-core/gncEntryLedgerModel.c b/gnucash/register/ledger-core/gncEntryLedgerModel.c
index 574a480..190809d 100644
--- a/gnucash/register/ledger-core/gncEntryLedgerModel.c
+++ b/gnucash/register/ledger-core/gncEntryLedgerModel.c
@@ -1012,7 +1012,7 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
cell = gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DATE_CELL);
- gnc_date_cell_get_date ((DateCell *) cell, &cell_time);
+ gnc_date_cell_get_date ((DateCell *) cell, &cell_time, TRUE);
/* commit any pending changes */
gnc_date_cell_commit ((DateCell *) cell);
diff --git a/gnucash/register/ledger-core/split-register-control.c b/gnucash/register/ledger-core/split-register-control.c
index 5effb4c..0bb8ebe 100644
--- a/gnucash/register/ledger-core/split-register-control.c
+++ b/gnucash/register/ledger-core/split-register-control.c
@@ -1258,7 +1258,7 @@ gnc_split_register_xfer_dialog(SplitRegister *reg, Transaction *txn,
if (cell)
{
time64 time;
- gnc_date_cell_get_date((DateCell*) cell, &time);
+ gnc_date_cell_get_date((DateCell*) cell, &time, TRUE);
gnc_xfer_dialog_set_date(xfer, time);
}
else
diff --git a/gnucash/register/ledger-core/split-register-model-save.c b/gnucash/register/ledger-core/split-register-model-save.c
index f0f2ccf..d4b24db 100644
--- a/gnucash/register/ledger-core/split-register-model-save.c
+++ b/gnucash/register/ledger-core/split-register-model-save.c
@@ -67,7 +67,7 @@ gnc_split_register_save_date_cell (BasicCell * cell,
DEBUG ("DATE: %s", value ? value : "(null)");
- gnc_date_cell_get_date ((DateCell *) cell, &cell_time);
+ gnc_date_cell_get_date ((DateCell *) cell, &cell_time, TRUE);
/* commit any pending changes */
gnc_date_cell_commit ((DateCell *) cell);
@@ -103,7 +103,7 @@ gnc_split_register_save_due_date_cell (BasicCell * cell,
/* commit any pending changes */
gnc_date_cell_commit ((DateCell *) cell);
DEBUG ("DATE: %s", value ? value : "(null)");
- gnc_date_cell_get_date ((DateCell *) cell, &time);
+ gnc_date_cell_get_date ((DateCell *) cell, &time, TRUE);
xaccTransSetDateDue (sd->trans, time);
}
diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c
index 5d1eb78..f37dcd8 100644
--- a/gnucash/register/ledger-core/split-register.c
+++ b/gnucash/register/ledger-core/split-register.c
@@ -1385,7 +1385,7 @@ gnc_split_register_save_to_scm (SplitRegister *reg,
BasicCell *cell;
time64 time;
cell = gnc_table_layout_get_cell (reg->table->layout, DATE_CELL);
- gnc_date_cell_get_date ((DateCell *) cell, &time);
+ gnc_date_cell_get_date ((DateCell *) cell, &time, TRUE);
xaccTransSetDatePostedSecsNormalized(trans, time);
}
@@ -2085,7 +2085,7 @@ record_price (SplitRegister *reg, Account *account, gnc_numeric value,
*/
if (gnc_split_reg_has_rate_cell (reg->type))
return;
- gnc_date_cell_get_date ((DateCell*)cell, &time);
+ gnc_date_cell_get_date ((DateCell*)cell, &time, TRUE);
price = gnc_pricedb_lookup_day_t64 (pricedb, comm, curr, time);
if (gnc_commodity_equiv (comm, gnc_price_get_currency (price)))
swap = TRUE;
diff --git a/gnucash/register/register-core/datecell.h b/gnucash/register/register-core/datecell.h
index e3ce703..709b7bc 100644
--- a/gnucash/register/register-core/datecell.h
+++ b/gnucash/register/register-core/datecell.h
@@ -123,8 +123,9 @@ void gnc_date_cell_commit (DateCell *cell);
/** Set a time64 to the value in the DateCell.
* @param cell The DateCell
* @param time A time64* to which the function will write the time.
+ * @param warn Whether to warn of parse errors or silently change to a valid one.
*/
-void gnc_date_cell_get_date (DateCell *cell, time64 *time);
+void gnc_date_cell_get_date (DateCell *cell, time64 *time, gboolean warn);
/** Set a GDate to the value in the DateCell.
* @param cell The DateCell
diff --git a/gnucash/register/register-gnome/datecell-gnome.c b/gnucash/register/register-gnome/datecell-gnome.c
index f38374c..3b0399b 100644
--- a/gnucash/register/register-gnome/datecell-gnome.c
+++ b/gnucash/register/register-gnome/datecell-gnome.c
@@ -710,7 +710,7 @@ gnc_date_cell_leave (BasicCell *bcell)
box->calendar_popped = FALSE;
/* Refresh the date to expand any shortcuts. */
- gnc_date_cell_get_date ((DateCell *)bcell, &time);
+ gnc_date_cell_get_date ((DateCell *)bcell, &time, TRUE);
gnc_date_cell_set_value_secs ((DateCell *)bcell, time);
}
@@ -731,13 +731,13 @@ gnc_date_cell_get_date_gdate (DateCell *cell, GDate *date)
}
void
-gnc_date_cell_get_date (DateCell *cell, time64 *time)
+gnc_date_cell_get_date (DateCell *cell, time64 *time, gboolean warn)
{
PopBox *box = cell->cell.gui_private;
if (!cell || !time)
return;
- gnc_parse_date (&(box->date), cell->cell.value, TRUE);
+ gnc_parse_date (&(box->date), cell->cell.value, warn);
*time = gnc_mktime (&box->date);
}
commit dd49756f4ebdbdb9e9d57f089206dc1a0068e278
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Wed Aug 22 20:35:54 2018 +0100
Bug 796813 - Date validation inconsistent
Change gnc_split_register_save_date_cell function and the equivalent one
in gncEntryLedgerModel to use time64 version of gnc_date_cell_get_date
which includes the warning for dates out of range.
diff --git a/gnucash/register/ledger-core/gncEntryLedgerModel.c b/gnucash/register/ledger-core/gncEntryLedgerModel.c
index a409b55..574a480 100644
--- a/gnucash/register/ledger-core/gncEntryLedgerModel.c
+++ b/gnucash/register/ledger-core/gncEntryLedgerModel.c
@@ -1008,15 +1008,17 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
ENTRY_DATE_CELL, TRUE))
{
BasicCell *cell;
- GDate date;
+ time64 cell_time;
cell = gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DATE_CELL);
+ gnc_date_cell_get_date ((DateCell *) cell, &cell_time);
+
/* commit any pending changes */
gnc_date_cell_commit ((DateCell *) cell);
- gnc_date_cell_get_date_gdate ((DateCell *) cell, &date);
- gncEntrySetDateGDate (entry, &date);
+ /* Note use of time64CanonicalDayTime to set time part to midday */
+ gncEntrySetDate (entry, time64CanonicalDayTime(cell_time));
}
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
diff --git a/gnucash/register/ledger-core/split-register-model-save.c b/gnucash/register/ledger-core/split-register-model-save.c
index e785827..f0f2ccf 100644
--- a/gnucash/register/ledger-core/split-register-model-save.c
+++ b/gnucash/register/ledger-core/split-register-model-save.c
@@ -59,20 +59,20 @@ gnc_split_register_save_date_cell (BasicCell * cell,
{
SRSaveData *sd = save_data;
const char *value;
- GDate gdate;
+ time64 cell_time;
g_return_if_fail (gnc_basic_cell_has_name (cell, DATE_CELL));
value = gnc_basic_cell_get_value (cell);
- /* commit any pending changes */
- gnc_date_cell_commit ((DateCell *) cell);
-
DEBUG ("DATE: %s", value ? value : "(null)");
- gnc_date_cell_get_date_gdate ((DateCell *) cell, &gdate);
+ gnc_date_cell_get_date ((DateCell *) cell, &cell_time);
+
+ /* commit any pending changes */
+ gnc_date_cell_commit ((DateCell *) cell);
- xaccTransSetDatePostedGDate (sd->trans, gdate);
+ xaccTransSetDatePostedSecsNormalized (sd->trans, cell_time);
}
static void
commit 995e6b0f956a876a3c4f3b8a60b09dd94a5cf81b
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Thu Aug 16 11:23:30 2018 +0100
White space and tabs changed in search-date.c
diff --git a/gnucash/gnome-search/search-date.c b/gnucash/gnome-search/search-date.c
index 02d9573..364c7ec 100644
--- a/gnucash/gnome-search/search-date.c
+++ b/gnucash/gnome-search/search-date.c
@@ -39,14 +39,14 @@
static void editable_enters (GNCSearchCoreType *fe);
static void grab_focus (GNCSearchCoreType *fe);
-static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
+static GNCSearchCoreType *gncs_clone (GNCSearchCoreType *fe);
static gboolean gncs_validate (GNCSearchCoreType *fe);
-static GtkWidget *gncs_get_widget(GNCSearchCoreType *fe);
+static GtkWidget *gncs_get_widget (GNCSearchCoreType *fe);
static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe);
-static void gnc_search_date_class_init (GNCSearchDateClass *klass);
-static void gnc_search_date_init (GNCSearchDate *gspaper);
-static void gnc_search_date_finalize (GObject *obj);
+static void gnc_search_date_class_init (GNCSearchDateClass *klass);
+static void gnc_search_date_init (GNCSearchDate *gspaper);
+static void gnc_search_date_finalize (GObject *obj);
typedef struct _GNCSearchDatePrivate GNCSearchDatePrivate;
@@ -69,14 +69,14 @@ gnc_search_date_get_type (void)
{
GTypeInfo type_info =
{
- sizeof(GNCSearchDateClass), /* class_size */
- NULL, /* base_init */
- NULL, /* base_finalize */
+ sizeof(GNCSearchDateClass), /* class_size */
+ NULL, /* base_init */
+ NULL, /* base_finalize */
(GClassInitFunc)gnc_search_date_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof(GNCSearchDate), /* */
- 0, /* n_preallocs */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof(GNCSearchDate), /* */
+ 0, /* n_preallocs */
(GInstanceInitFunc)gnc_search_date_init,
};
commit 39b24325d92b080ef69e4f18e7f5d03d398deafe
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Thu Aug 16 11:22:44 2018 +0100
Bug 796725 - 4 of 6 Date Posted options fail to return
matching transactions.
gnc_date_edit_get_date returns the time64 value set to 00:00:00 for the
day entered so for the LTE and GT options gnc_date_edit_get_date_end
needs to be used for 23:59:59. For finding transactions on the date,
the use of QOF_DATE_MATCH_DAY needs to be used.
diff --git a/gnucash/gnome-search/search-date.c b/gnucash/gnome-search/search-date.c
index 9523c3f..02d9573 100644
--- a/gnucash/gnome-search/search-date.c
+++ b/gnucash/gnome-search/search-date.c
@@ -179,9 +179,22 @@ gncs_validate (GNCSearchCoreType *fe)
}
static void
+gnc_search_date_set_date_from_edit (GNCSearchDate *fe, GNCDateEdit *de)
+{
+ /* The gnc_date_edit_get_date function returns a value set to the
+ * start of the day 00:00:00, use gnc_date_edit_get_date_end to get
+ * value for day end 23:59:59 for LessThanEqual and GreaterThan */
+
+ if (fe->how == QOF_COMPARE_LTE || fe->how == QOF_COMPARE_GT)
+ fe->tt = gnc_date_edit_get_date_end (de);
+ else
+ fe->tt = gnc_date_edit_get_date (de);
+}
+
+static void
date_changed (GNCDateEdit *date_edit, GNCSearchDate *fe)
{
- fe->tt = gnc_date_edit_get_date (date_edit);
+ gnc_search_date_set_date_from_edit (fe, date_edit);
}
static GtkWidget *
@@ -272,9 +285,12 @@ static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe)
/* Make sure we actually use the currently-entered date */
priv = _PRIVATE(fi);
if (priv->entry)
- fi->tt = gnc_date_edit_get_date (GNC_DATE_EDIT (priv->entry));
+ gnc_search_date_set_date_from_edit (fi, GNC_DATE_EDIT (priv->entry));
- return qof_query_date_predicate (fi->how, QOF_DATE_MATCH_NORMAL, fi->tt);
+ if (fi->how == QOF_COMPARE_EQUAL || fi->how == QOF_COMPARE_NEQ)
+ return qof_query_date_predicate (fi->how, QOF_DATE_MATCH_DAY, fi->tt);
+ else
+ return qof_query_date_predicate (fi->how, QOF_DATE_MATCH_NORMAL, fi->tt);
}
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe)
Summary of changes:
gnucash/gnome-search/search-date.c | 46 ++++---
gnucash/gnome-utils/gnc-main-window.c | 24 +++-
gnucash/register/ledger-core/gncEntryLedgerModel.c | 19 +--
.../register/ledger-core/split-register-control.c | 2 +-
.../ledger-core/split-register-model-save.c | 14 +-
.../register/ledger-core/split-register-model.c | 11 +-
gnucash/register/ledger-core/split-register.c | 4 +-
gnucash/register/register-core/datecell.h | 9 +-
gnucash/register/register-gnome/datecell-gnome.c | 22 +---
libgnucash/engine/qofbook.cpp | 146 +++++++++++++--------
libgnucash/engine/qofbook.h | 21 ++-
11 files changed, 187 insertions(+), 131 deletions(-)
More information about the gnucash-changes
mailing list