gnucash master: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Thu Sep 6 20:11:10 EDT 2018
Updated via https://github.com/Gnucash/gnucash/commit/61551526 (commit)
via https://github.com/Gnucash/gnucash/commit/148f2413 (commit)
via https://github.com/Gnucash/gnucash/commit/75ccd57d (commit)
via https://github.com/Gnucash/gnucash/commit/f6d873dc (commit)
via https://github.com/Gnucash/gnucash/commit/e47b460a (commit)
via https://github.com/Gnucash/gnucash/commit/705e8664 (commit)
via https://github.com/Gnucash/gnucash/commit/d07f759c (commit)
via https://github.com/Gnucash/gnucash/commit/4c87dd05 (commit)
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/caaf9edc (commit)
via https://github.com/Gnucash/gnucash/commit/baf933ac (commit)
via https://github.com/Gnucash/gnucash/commit/1239876b (commit)
via https://github.com/Gnucash/gnucash/commit/5ffb7fa2 (commit)
via https://github.com/Gnucash/gnucash/commit/fc368b91 (commit)
via https://github.com/Gnucash/gnucash/commit/6dfbf3d5 (commit)
via https://github.com/Gnucash/gnucash/commit/c977c235 (commit)
via https://github.com/Gnucash/gnucash/commit/28691b46 (commit)
via https://github.com/Gnucash/gnucash/commit/b1ee7c6e (commit)
via https://github.com/Gnucash/gnucash/commit/704afc6e (commit)
via https://github.com/Gnucash/gnucash/commit/fe73f52b (commit)
via https://github.com/Gnucash/gnucash/commit/4e88b8cb (commit)
via https://github.com/Gnucash/gnucash/commit/a639dd92 (commit)
via https://github.com/Gnucash/gnucash/commit/e2801fd9 (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/93f3a8ea (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/4a3c6f8f (commit)
via https://github.com/Gnucash/gnucash/commit/995e6b0f (commit)
via https://github.com/Gnucash/gnucash/commit/39b24325 (commit)
via https://github.com/Gnucash/gnucash/commit/54a5097c (commit)
via https://github.com/Gnucash/gnucash/commit/34cb4925 (commit)
via https://github.com/Gnucash/gnucash/commit/6ba47846 (commit)
via https://github.com/Gnucash/gnucash/commit/a650693d (commit)
via https://github.com/Gnucash/gnucash/commit/9423e091 (commit)
via https://github.com/Gnucash/gnucash/commit/c6001d85 (commit)
via https://github.com/Gnucash/gnucash/commit/ed05b895 (commit)
via https://github.com/Gnucash/gnucash/commit/13c5b539 (commit)
via https://github.com/Gnucash/gnucash/commit/72a29a83 (commit)
via https://github.com/Gnucash/gnucash/commit/8a0ee0e3 (commit)
via https://github.com/Gnucash/gnucash/commit/e281b50b (commit)
via https://github.com/Gnucash/gnucash/commit/97a566ae (commit)
via https://github.com/Gnucash/gnucash/commit/6eac7e1e (commit)
via https://github.com/Gnucash/gnucash/commit/632c7c72 (commit)
via https://github.com/Gnucash/gnucash/commit/d74ec9aa (commit)
via https://github.com/Gnucash/gnucash/commit/3f9a8977 (commit)
via https://github.com/Gnucash/gnucash/commit/b50c8a57 (commit)
via https://github.com/Gnucash/gnucash/commit/b4db066d (commit)
via https://github.com/Gnucash/gnucash/commit/c3724431 (commit)
via https://github.com/Gnucash/gnucash/commit/44644694 (commit)
via https://github.com/Gnucash/gnucash/commit/88597d0b (commit)
via https://github.com/Gnucash/gnucash/commit/c08dee67 (commit)
via https://github.com/Gnucash/gnucash/commit/e9098d08 (commit)
via https://github.com/Gnucash/gnucash/commit/35fabe26 (commit)
via https://github.com/Gnucash/gnucash/commit/20f6e4e6 (commit)
via https://github.com/Gnucash/gnucash/commit/755773ac (commit)
via https://github.com/Gnucash/gnucash/commit/b32a8a93 (commit)
via https://github.com/Gnucash/gnucash/commit/62b17ca5 (commit)
via https://github.com/Gnucash/gnucash/commit/358cd979 (commit)
via https://github.com/Gnucash/gnucash/commit/fee589b2 (commit)
via https://github.com/Gnucash/gnucash/commit/92a8cf33 (commit)
via https://github.com/Gnucash/gnucash/commit/44c3dc83 (commit)
via https://github.com/Gnucash/gnucash/commit/c8b372e3 (commit)
via https://github.com/Gnucash/gnucash/commit/b60aef9d (commit)
via https://github.com/Gnucash/gnucash/commit/6f89bd62 (commit)
via https://github.com/Gnucash/gnucash/commit/e7961203 (commit)
via https://github.com/Gnucash/gnucash/commit/dd873240 (commit)
via https://github.com/Gnucash/gnucash/commit/6846a686 (commit)
via https://github.com/Gnucash/gnucash/commit/e3dce951 (commit)
via https://github.com/Gnucash/gnucash/commit/14335b78 (commit)
via https://github.com/Gnucash/gnucash/commit/b3f1104d (commit)
via https://github.com/Gnucash/gnucash/commit/19d6eb90 (commit)
via https://github.com/Gnucash/gnucash/commit/22dd716b (commit)
via https://github.com/Gnucash/gnucash/commit/2f861bc2 (commit)
via https://github.com/Gnucash/gnucash/commit/9768a215 (commit)
via https://github.com/Gnucash/gnucash/commit/5ff8d8da (commit)
via https://github.com/Gnucash/gnucash/commit/847766fc (commit)
via https://github.com/Gnucash/gnucash/commit/1e87d069 (commit)
via https://github.com/Gnucash/gnucash/commit/de2a1e9e (commit)
via https://github.com/Gnucash/gnucash/commit/d69d1f6a (commit)
via https://github.com/Gnucash/gnucash/commit/239ee679 (commit)
via https://github.com/Gnucash/gnucash/commit/e330a781 (commit)
via https://github.com/Gnucash/gnucash/commit/2b0b3d4f (commit)
via https://github.com/Gnucash/gnucash/commit/97c191cd (commit)
via https://github.com/Gnucash/gnucash/commit/641925f2 (commit)
via https://github.com/Gnucash/gnucash/commit/3b74574c (commit)
via https://github.com/Gnucash/gnucash/commit/47ad60c7 (commit)
via https://github.com/Gnucash/gnucash/commit/58ae3f2a (commit)
via https://github.com/Gnucash/gnucash/commit/cabb598c (commit)
via https://github.com/Gnucash/gnucash/commit/8273f3eb (commit)
via https://github.com/Gnucash/gnucash/commit/8cbd4d62 (commit)
via https://github.com/Gnucash/gnucash/commit/47ba21b8 (commit)
via https://github.com/Gnucash/gnucash/commit/78ab26cc (commit)
via https://github.com/Gnucash/gnucash/commit/d87fa3a5 (commit)
via https://github.com/Gnucash/gnucash/commit/4c8b07c0 (commit)
via https://github.com/Gnucash/gnucash/commit/69fef827 (commit)
via https://github.com/Gnucash/gnucash/commit/fe371534 (commit)
via https://github.com/Gnucash/gnucash/commit/2203118d (commit)
via https://github.com/Gnucash/gnucash/commit/cd7a55a9 (commit)
via https://github.com/Gnucash/gnucash/commit/e851f249 (commit)
via https://github.com/Gnucash/gnucash/commit/099b659b (commit)
via https://github.com/Gnucash/gnucash/commit/8c1adaa2 (commit)
via https://github.com/Gnucash/gnucash/commit/68874495 (commit)
via https://github.com/Gnucash/gnucash/commit/ec0d081d (commit)
via https://github.com/Gnucash/gnucash/commit/dd59ba67 (commit)
via https://github.com/Gnucash/gnucash/commit/0a0d4755 (commit)
via https://github.com/Gnucash/gnucash/commit/2c6fbfba (commit)
via https://github.com/Gnucash/gnucash/commit/accd154e (commit)
via https://github.com/Gnucash/gnucash/commit/f9700ba9 (commit)
via https://github.com/Gnucash/gnucash/commit/d6b24577 (commit)
via https://github.com/Gnucash/gnucash/commit/216528c1 (commit)
via https://github.com/Gnucash/gnucash/commit/9cb00f8f (commit)
via https://github.com/Gnucash/gnucash/commit/9993e0ce (commit)
via https://github.com/Gnucash/gnucash/commit/1131aa6f (commit)
via https://github.com/Gnucash/gnucash/commit/40680369 (commit)
via https://github.com/Gnucash/gnucash/commit/827c43d9 (commit)
via https://github.com/Gnucash/gnucash/commit/6d605762 (commit)
via https://github.com/Gnucash/gnucash/commit/773b0703 (commit)
via https://github.com/Gnucash/gnucash/commit/64778fca (commit)
via https://github.com/Gnucash/gnucash/commit/5c90f677 (commit)
via https://github.com/Gnucash/gnucash/commit/5ad584ca (commit)
via https://github.com/Gnucash/gnucash/commit/8edf4478 (commit)
via https://github.com/Gnucash/gnucash/commit/d3439341 (commit)
via https://github.com/Gnucash/gnucash/commit/1ea4310f (commit)
via https://github.com/Gnucash/gnucash/commit/85bb7786 (commit)
via https://github.com/Gnucash/gnucash/commit/193176cc (commit)
via https://github.com/Gnucash/gnucash/commit/93030c61 (commit)
via https://github.com/Gnucash/gnucash/commit/697d2a16 (commit)
via https://github.com/Gnucash/gnucash/commit/fa1b4c68 (commit)
via https://github.com/Gnucash/gnucash/commit/6f1c63db (commit)
via https://github.com/Gnucash/gnucash/commit/c444729d (commit)
via https://github.com/Gnucash/gnucash/commit/294e113f (commit)
via https://github.com/Gnucash/gnucash/commit/414ab99a (commit)
via https://github.com/Gnucash/gnucash/commit/b8ce2b54 (commit)
via https://github.com/Gnucash/gnucash/commit/aa4da810 (commit)
via https://github.com/Gnucash/gnucash/commit/dfe1f345 (commit)
via https://github.com/Gnucash/gnucash/commit/694d0f06 (commit)
via https://github.com/Gnucash/gnucash/commit/57c6f175 (commit)
via https://github.com/Gnucash/gnucash/commit/e2907844 (commit)
via https://github.com/Gnucash/gnucash/commit/ff91056a (commit)
via https://github.com/Gnucash/gnucash/commit/a51be515 (commit)
via https://github.com/Gnucash/gnucash/commit/1fffbaf8 (commit)
via https://github.com/Gnucash/gnucash/commit/374477c3 (commit)
via https://github.com/Gnucash/gnucash/commit/8c4a5adb (commit)
via https://github.com/Gnucash/gnucash/commit/b95981e6 (commit)
via https://github.com/Gnucash/gnucash/commit/aa77b21d (commit)
via https://github.com/Gnucash/gnucash/commit/c513d788 (commit)
via https://github.com/Gnucash/gnucash/commit/0199fef5 (commit)
via https://github.com/Gnucash/gnucash/commit/a75eb4c8 (commit)
via https://github.com/Gnucash/gnucash/commit/3b093131 (commit)
via https://github.com/Gnucash/gnucash/commit/3e37b879 (commit)
via https://github.com/Gnucash/gnucash/commit/36dc2acd (commit)
via https://github.com/Gnucash/gnucash/commit/0e4898fe (commit)
via https://github.com/Gnucash/gnucash/commit/43af50bd (commit)
via https://github.com/Gnucash/gnucash/commit/4c8f822c (commit)
via https://github.com/Gnucash/gnucash/commit/de927d53 (commit)
via https://github.com/Gnucash/gnucash/commit/c2972c75 (commit)
via https://github.com/Gnucash/gnucash/commit/9db7d894 (commit)
via https://github.com/Gnucash/gnucash/commit/983c7ce0 (commit)
via https://github.com/Gnucash/gnucash/commit/756f444a (commit)
via https://github.com/Gnucash/gnucash/commit/e6ea84ba (commit)
via https://github.com/Gnucash/gnucash/commit/38748f20 (commit)
via https://github.com/Gnucash/gnucash/commit/4d013e09 (commit)
via https://github.com/Gnucash/gnucash/commit/ad7c14a5 (commit)
via https://github.com/Gnucash/gnucash/commit/582265d0 (commit)
via https://github.com/Gnucash/gnucash/commit/0594beb0 (commit)
via https://github.com/Gnucash/gnucash/commit/5c8af379 (commit)
via https://github.com/Gnucash/gnucash/commit/d12ee9a4 (commit)
via https://github.com/Gnucash/gnucash/commit/eb0256e3 (commit)
via https://github.com/Gnucash/gnucash/commit/9d5712ef (commit)
via https://github.com/Gnucash/gnucash/commit/87578184 (commit)
via https://github.com/Gnucash/gnucash/commit/f067e832 (commit)
via https://github.com/Gnucash/gnucash/commit/49bd9c41 (commit)
via https://github.com/Gnucash/gnucash/commit/9ab06bc9 (commit)
via https://github.com/Gnucash/gnucash/commit/240c4bd2 (commit)
via https://github.com/Gnucash/gnucash/commit/04424b62 (commit)
via https://github.com/Gnucash/gnucash/commit/00ef7f3a (commit)
via https://github.com/Gnucash/gnucash/commit/463b551d (commit)
via https://github.com/Gnucash/gnucash/commit/3d4201f1 (commit)
via https://github.com/Gnucash/gnucash/commit/b79c9d15 (commit)
via https://github.com/Gnucash/gnucash/commit/d865b149 (commit)
via https://github.com/Gnucash/gnucash/commit/f7ed46a3 (commit)
via https://github.com/Gnucash/gnucash/commit/4e04f6e5 (commit)
via https://github.com/Gnucash/gnucash/commit/8de1625d (commit)
via https://github.com/Gnucash/gnucash/commit/60117491 (commit)
via https://github.com/Gnucash/gnucash/commit/246257de (commit)
via https://github.com/Gnucash/gnucash/commit/5f46553f (commit)
from https://github.com/Gnucash/gnucash/commit/280ed47d (commit)
commit 61551526a860acc44c4cc545f699424d7347d41b
Merge: 280ed47 148f241
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Sep 6 16:26:29 2018 -0700
Merge branch 'maint'
commit 148f24135b18b7b9b777aa21db6593a19b68f37f
Merge: 75ccd57 cd7a55a
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Sep 6 15:21:36 2018 -0700
Merge Bob Fewell's 'fixes9' into maint.
diff --cc gnucash/gnome-search/search-date.c
index 364c7ec,af85414..7a746c2
--- a/gnucash/gnome-search/search-date.c
+++ b/gnucash/gnome-search/search-date.c
@@@ -37,16 -37,17 +37,17 @@@
#define d(x)
+ static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
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;
commit 75ccd57dbf8d26eb0d393a81f48b2337324fb7f3
Author: John Ralls <jralls at ceridwen.us>
Date: Tue Sep 4 11:08:25 2018 -0700
Bug 796734 - Auto-complete entry not highlighting to allow...
for incremental entry.
Because the Quartz Input Method module (imquartz.c) messes with the
selected text, so we cache it in the gnucash_sheet object and restore it
after the input module is done with the keypress.
diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c
index d3f68ac..7e22642 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.c
+++ b/gnucash/register/register-gnome/gnucash-sheet.c
@@ -1040,6 +1040,9 @@ gnucash_sheet_insert_cb (GtkWidget *widget,
if (start_sel != end_sel)
gtk_editable_select_region(editable, start_sel, end_sel);
+ /* Save the selected region in case the input module eats it. */
+ sheet->start_sel = start_sel;
+ sheet->end_sel = end_sel;
g_string_free (new_text_gs, TRUE);
g_string_free (change_text_gs, TRUE);
@@ -1810,10 +1813,17 @@ gnucash_sheet_key_press_event_internal (GtkWidget *widget, GdkEventKey *event)
if (pass_on)
{
gboolean result = FALSE;
- // If sheet is readonly, entry is not realized
- if (gtk_widget_get_realized (GTK_WIDGET(sheet->entry)))
- result = gtk_widget_event (sheet->entry, (GdkEvent *) event);
+ GtkEditable *editable = GTK_EDITABLE(sheet->entry);
+ // If sheet is readonly, entry is not realized
+ if (gtk_widget_get_realized (GTK_WIDGET(editable)))
+ result = gtk_widget_event (GTK_WIDGET(editable), (GdkEvent*)event);
+ /* Restore the stored selection in case it was eaten by the input
+ * module.
+ */
+ if (sheet->start_sel != sheet->end_sel)
+ gtk_editable_select_region(editable, sheet->start_sel,
+ sheet->end_sel);
return result;
}
@@ -1834,13 +1844,15 @@ static gint
gnucash_sheet_key_press_event (GtkWidget *widget, GdkEventKey *event)
{
GnucashSheet *sheet;
+ GtkEditable *editable = NULL;
+ int start_sel = 0, end_sel = 0;
g_return_val_if_fail(widget != NULL, TRUE);
g_return_val_if_fail(GNUCASH_IS_SHEET(widget), TRUE);
g_return_val_if_fail(event != NULL, TRUE);
sheet = GNUCASH_SHEET (widget);
-
+ editable = GTK_EDITABLE(sheet->entry);
/* bug#60582 comment#27 2
save shift state to enable <shift minus> and <shift equal>
bug#618434
@@ -1861,6 +1873,9 @@ gnucash_sheet_key_press_event (GtkWidget *widget, GdkEventKey *event)
sheet->shift_state = event->state & GDK_SHIFT_MASK;
sheet->keyval_state = (event->keyval == GDK_KEY_KP_Decimal) ? GDK_KEY_KP_Decimal : 0;
}
+
+ gtk_editable_get_selection_bounds (editable, &start_sel, &end_sel);
+
if (gtk_im_context_filter_keypress (sheet->im_context, event))
{
sheet->need_im_reset = TRUE;
@@ -2590,6 +2605,7 @@ gnucash_sheet_init (GnucashSheet *sheet)
sheet->delete_surrounding_signal = 0;
sheet->shift_state = 0;
sheet->keyval_state = 0;
+ sheet->start_sel = sheet->end_sel = 0;
}
diff --git a/gnucash/register/register-gnome/gnucash-sheetP.h b/gnucash/register/register-gnome/gnucash-sheetP.h
index bd2ec3c..8881068 100644
--- a/gnucash/register/register-gnome/gnucash-sheetP.h
+++ b/gnucash/register/register-gnome/gnucash-sheetP.h
@@ -112,6 +112,7 @@ struct _GnucashSheet
guint shift_state;
guint keyval_state;
+ int start_sel, end_sel;
};
commit f6d873dc2722a339f284bb84ffa2159b9087e781
Author: Geert Janssens <geert at kobaltwit.be>
Date: Tue Sep 4 11:28:16 2018 +0200
Bug 796833 - Excel csv Format misprocessed
Convert all line ending styles to the one expected by the C++ standard
library before starting to parse a csv file.
diff --git a/gnucash/import-export/csv-imp/gnc-tokenizer.cpp b/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
index 0a15fa0..2f54db6 100644
--- a/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
+++ b/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
@@ -12,6 +12,7 @@
#include <memory>
#include <boost/locale.hpp>
+#include <boost/algorithm/string.hpp>
extern "C" {
#include <go-glib-extras.h>
@@ -79,6 +80,11 @@ GncTokenizer::encoding(const std::string& encoding)
{
m_enc_str = encoding;
m_utf8_contents = boost::locale::conv::to_utf<char>(m_raw_contents, m_enc_str);
+
+ // While we are converting here, let's also normalize line-endings to "\n"
+ // That's what STL expects by default
+ boost::replace_all (m_utf8_contents, "\r\n", "\n");
+ boost::replace_all (m_utf8_contents, "\r", "\n");
}
const std::string&
commit e47b460acb8bec2c540f1bfff74c25e0a9560ee9
Author: Geert Janssens <geert at kobaltwit.be>
Date: Mon Sep 3 19:39:16 2018 +0200
Set toolbar buttons to show both icon and text
And make the icon small to recover some vertical screen estate.
The motivation for this is that Gtk has dropped the ability for users
to change a toolbar's appearance. And as our icons are often less
than descriptive many users benefit from having textual descriptions
as well. This is the best compromise we can make until the gui
gets an in-depth redesign.
diff --git a/gnucash/gnome-utils/gnc-embedded-window.c b/gnucash/gnome-utils/gnc-embedded-window.c
index 605d7dd..617da3e 100644
--- a/gnucash/gnome-utils/gnc-embedded-window.c
+++ b/gnucash/gnome-utils/gnc-embedded-window.c
@@ -308,6 +308,10 @@ gnc_embedded_window_add_widget (GtkUIManager *merge,
if (GTK_IS_TOOLBAR (widget))
{
priv->toolbar = widget;
+ gtk_toolbar_set_style (GTK_TOOLBAR(priv->toolbar),
+ GTK_TOOLBAR_BOTH);
+ gtk_toolbar_set_icon_size (GTK_TOOLBAR(priv->toolbar),
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
}
gtk_box_pack_start (GTK_BOX (priv->menu_dock), widget, FALSE, FALSE, 0);
diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c
index 03a498a..51fba55 100644
--- a/gnucash/gnome-utils/gnc-main-window.c
+++ b/gnucash/gnome-utils/gnc-main-window.c
@@ -3838,6 +3838,10 @@ gnc_main_window_add_widget (GtkUIManager *merge,
if (GTK_IS_TOOLBAR (widget))
{
priv->toolbar = widget;
+ gtk_toolbar_set_style (GTK_TOOLBAR(priv->toolbar),
+ GTK_TOOLBAR_BOTH);
+ gtk_toolbar_set_icon_size (GTK_TOOLBAR(priv->toolbar),
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
}
gtk_box_pack_start (GTK_BOX (priv->menu_dock), widget, FALSE, FALSE, 0);
diff --git a/gnucash/gnome/window-reconcile.c b/gnucash/gnome/window-reconcile.c
index 4446eb1..0553852 100644
--- a/gnucash/gnome/window-reconcile.c
+++ b/gnucash/gnome/window-reconcile.c
@@ -1681,6 +1681,13 @@ recnWindow_add_widget (GtkUIManager *merge,
GtkWidget *widget,
GtkBox *dock)
{
+ if (GTK_IS_TOOLBAR (widget))
+ {
+ gtk_toolbar_set_style (GTK_TOOLBAR(widget),
+ GTK_TOOLBAR_BOTH);
+ gtk_toolbar_set_icon_size (GTK_TOOLBAR(widget),
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
+ }
gtk_box_pack_start (GTK_BOX (dock), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
}
commit 705e86647234dc1416bdfb1c581a02b233ee6f60
Author: Geert Janssens <geert at kobaltwit.be>
Date: Sat Sep 1 16:22:42 2018 +0200
Bug 796054 follow up
Now that a separate wiki section has been written for the side effects of this bug
make the memo field of affected splits point to this wiki section.
diff --git a/libgnucash/engine/ScrubBusiness.c b/libgnucash/engine/ScrubBusiness.c
index 44e0eb4..cf45c41 100644
--- a/libgnucash/engine/ScrubBusiness.c
+++ b/libgnucash/engine/ScrubBusiness.c
@@ -561,7 +561,7 @@ gncScrubBusinessSplit (Split *split)
*/
else if (invoice && (txn != posted_txn))
{
- const gchar *memo = _("Please delete this transaction. Explanation at https://wiki.gnucash.org/wiki/Business_Features_Issues#Double_posting");
+ const gchar *memo = _("Please delete this transaction. Explanation at https://wiki.gnucash.org/wiki/Business_Features_Issues#I_can.27t_delete_a_transaction_of_type_.22I.22_from_the_AR.2FAP_account");
gchar *txn_date = qof_print_date (xaccTransGetDateEntered (txn));
xaccTransClearReadOnly (txn);
xaccTransSetTxnType (txn, TXN_TYPE_NONE);
commit d07f759ca35ef8095c19c5dc8ae4354ce5367ce5
Author: Geert Janssens <geert at kobaltwit.be>
Date: Sat Sep 1 12:00:38 2018 +0200
Use alignment-safe buffer handling
Casting a char* to a struct containing a uint32_t is not universally safe
due to alignment constraints on reads on some platforms. Copy our possibly
unaligned source data into an aligned area of memory to avoid SIGBUS on
armhf.
Reported by vorlonofportland in PR#403. This commit the John's optimized
version of Vorlon's proposed fix.
diff --git a/libgnucash/engine/gnc-timezone.cpp b/libgnucash/engine/gnc-timezone.cpp
index 876df2a..01325b4 100644
--- a/libgnucash/engine/gnc-timezone.cpp
+++ b/libgnucash/engine/gnc-timezone.cpp
@@ -471,7 +471,9 @@ namespace IANAParser
for(uint32_t index = 0; index < type_count; ++index)
{
fb_index = start_index + index * tzinfo_size;
- TTInfo info = *reinterpret_cast<TTInfo*>(&fileblock[fb_index]);
+ /* Use memcpy instead of static_cast to avoid memory alignment issues with chars */
+ TTInfo info{};
+ memcpy(&info, &fileblock[fb_index], ttinfo_size);
endian_swap(&info.gmtoff);
tzinfo.push_back(
{info, &fileblock[abbrev + info.abbrind],
commit 4c87dd05ec8f1da40292f3e2f0004418a573ab89
Author: Geert Janssens <geert at kobaltwit.be>
Date: Sat Sep 1 11:43:04 2018 +0200
Fix compiler warning issues
- add -Wno-deprecated-declarations to CXX_FLAGS as well. This was
reported by vorlonofportland in PR#401 to become necessary for glib 2.58
as that has deprecated g_type_class_add_private which appears in our
c++ code.
- change -Wno-deprecated-register into -Wregister. The former appeared to
be a clang dialect and alias for the latter (see
https://github.com/Barro/compiler-warnings for an overview of clang
and gcc warnings). It was moved to global CXX_FLAGS as it can only be
added for g++.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b2fcffb..b2ecf7d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -572,8 +572,9 @@ set(CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") # FIXME: should be -std=
if (UNIX)
set( CMAKE_C_FLAGS "-Werror -Wdeclaration-after-statement -Wno-pointer-sign -Wall -Wmissing-prototypes -Wmissing-declarations -Wno-unused ${CMAKE_C_FLAGS}")
- set( CMAKE_CXX_FLAGS "-Werror -Wall -Wmissing-declarations -Wno-unused -Wno-error=parentheses ${CMAKE_CXX_FLAGS}")
set( CMAKE_C_FLAGS "-Wno-deprecated-declarations -std=gnu11 -Wno-error=parentheses ${CMAKE_C_FLAGS}")
+ set( CMAKE_CXX_FLAGS "-Werror -Wall -Wmissing-declarations -Wno-unused -Wno-error=parentheses ${CMAKE_CXX_FLAGS}")
+ set( CMAKE_CXX_FLAGS "-Wno-deprecated-declarations -Wno-register ${CMAKE_CXX_FLAGS}")
set( CMAKE_C_FLAGS_RELEASE "-O3 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 ${CMAKE_C_FLAGS}")
endif (UNIX)
if (MINGW)
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index dd9c8fb..526f20f 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -235,7 +235,6 @@ add_dependencies (gncmod-engine swig-runtime-h iso-4217-c)
target_link_libraries(gncmod-engine gnc-core-utils gnc-module ${Boost_DATE_TIME_LIBRARIES} ${Boost_REGEX_LIBRARIES} ${REGEX_LDFLAGS} ${GMODULE_LDFLAGS} ${GLIB2_LDFLAGS} ${GOBJECT_LDFLAGS} ${GUILE_LDFLAGS})
target_compile_definitions (gncmod-engine PRIVATE -DG_LOG_DOMAIN=\"gnc.engine\")
-target_compile_options (gncmod-engine PRIVATE -Wno-deprecated-register)
target_include_directories (gncmod-engine
PRIVATE ${CMAKE_CURRENT_BINARY_DIR} # for iso-4217-currencies.c
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 caaf9edc45ad573b0692bb1a2cde3a38901a5abf
Author: Geert Janssens <geert at kobaltwit.be>
Date: Fri Aug 31 20:57:12 2018 +0200
Use one single function to determine if an invoice is posted to ensure consistent behaviour
While debugging for bug 796054 I found cases where an invoice was unposted, but the toolbar
buttons and menu items were configured for a posted invoice. This should now be solved.
diff --git a/gnucash/gnome/dialog-invoice.c b/gnucash/gnome/dialog-invoice.c
index 8c2ece9..c8aa241 100644
--- a/gnucash/gnome/dialog-invoice.c
+++ b/gnucash/gnome/dialog-invoice.c
@@ -1747,7 +1747,6 @@ gnc_invoice_update_window (InvoiceWindow *iw, GtkWidget *widget)
GtkTextBuffer* text_buffer;
const char *string;
gchar * tmp_string;
- Account *acct;
time64 time;
gtk_entry_set_text (GTK_ENTRY (iw->id_entry), gncInvoiceGetID (invoice));
@@ -1800,16 +1799,13 @@ gnc_invoice_update_window (InvoiceWindow *iw, GtkWidget *widget)
/*
* Next, figure out if we've been posted, and if so set the appropriate
- * bits of information.. Then work on hiding or showing as
- * necessary. This duplicates the logic in gncInvoiceIsPosted, but we
- * need the accout pointer.
+ * bits of information... Then work on hiding or showing as
+ * necessary.
*/
-
- acct = gncInvoiceGetPostedAcc (invoice);
- if (acct)
+ is_posted = gncInvoiceIsPosted (invoice);
+ if (is_posted)
{
- /* Ok, it's definitely posted. Setup the 'posted-invoice' fields now */
- is_posted = TRUE;
+ Account *acct = gncInvoiceGetPostedAcc (invoice);
/* Can we unpost this invoice?
* XXX: right now we always can, but there
@@ -1851,7 +1847,7 @@ gnc_invoice_update_window (InvoiceWindow *iw, GtkWidget *widget)
{
GtkWidget *hide, *show;
- if (is_posted == TRUE)
+ if (is_posted)
{
hide = GTK_WIDGET (gtk_builder_get_object (iw->builder, "hide3"));
gtk_widget_hide (hide);
commit baf933acf2c088e149bc00c90865f5e8ae08dd3d
Author: Geert Janssens <geert at kobaltwit.be>
Date: Fri Aug 31 20:24:39 2018 +0200
Bug 796054 - unposting and reposting invoice doubles amounts
Add scrub function to unblock the double post transaction
diff --git a/libgnucash/engine/ScrubBusiness.c b/libgnucash/engine/ScrubBusiness.c
index a2f421e..44e0eb4 100644
--- a/libgnucash/engine/ScrubBusiness.c
+++ b/libgnucash/engine/ScrubBusiness.c
@@ -518,7 +518,6 @@ gncScrubBusinessLot (GNCLot *lot)
gboolean
gncScrubBusinessSplit (Split *split)
{
- const gchar *memo = _("Please delete this transaction. Explanation at https://wiki.gnucash.org/wiki/Business_Features_Issues#Double_posting");
Transaction *txn;
gboolean deleted_split = FALSE;
@@ -532,6 +531,8 @@ gncScrubBusinessSplit (Split *split)
const gchar *read_only = xaccTransGetReadOnly (txn);
gboolean is_void = xaccTransGetVoidStatus (txn);
GNCLot *lot = xaccSplitGetLot (split);
+ GncInvoice *invoice = gncInvoiceGetInvoiceFromTxn (txn);
+ Transaction *posted_txn = gncInvoiceGetPostedTxn (invoice);
/* Look for transactions as a result of double posting an invoice or bill
* Refer to https://bugs.gnucash.org/show_bug.cgi?id=754209
@@ -544,6 +545,7 @@ gncScrubBusinessSplit (Split *split)
*/
if ((txntype == TXN_TYPE_NONE) && read_only && !is_void && lot)
{
+ const gchar *memo = _("Please delete this transaction. Explanation at https://wiki.gnucash.org/wiki/Business_Features_Issues#Double_posting");
gchar *txn_date = qof_print_date (xaccTransGetDateEntered (txn));
xaccTransClearReadOnly (txn);
xaccSplitSetMemo (split, memo);
@@ -554,6 +556,28 @@ gncScrubBusinessSplit (Split *split)
txn_date);
g_free (txn_date);
}
+ /* Next check for transactions which claim to be the posted transaction of
+ * an invoice but the invoice disagrees. In that case
+ */
+ else if (invoice && (txn != posted_txn))
+ {
+ const gchar *memo = _("Please delete this transaction. Explanation at https://wiki.gnucash.org/wiki/Business_Features_Issues#Double_posting");
+ gchar *txn_date = qof_print_date (xaccTransGetDateEntered (txn));
+ xaccTransClearReadOnly (txn);
+ xaccTransSetTxnType (txn, TXN_TYPE_NONE);
+ xaccSplitSetMemo (split, memo);
+ if (lot)
+ {
+ gnc_lot_remove_split (lot, split);
+ gncInvoiceDetachFromLot (lot);
+ gncOwnerAttachToLot (gncInvoiceGetOwner(invoice), lot);
+ }
+ PWARN("Cleared double post status of transaction \"%s\", dated %s. "
+ "Please delete transaction and verify balance.",
+ xaccTransGetDescription (txn),
+ txn_date);
+ g_free (txn_date);
+ }
/* Next delete any empty splits that aren't part of an invoice transaction
* Such splits may be the result of scrubbing the business lots, which can
* merge splits together while reducing superfluous lot links
commit 1239876b5b9fd61e0dc2f50acac0a4c5bf21a513
Author: Geert Janssens <geert at kobaltwit.be>
Date: Fri Aug 31 19:04:40 2018 +0200
Use GnuCash instead of Gnucash in OSX environment file
This is the result of a discussion on
Bug 796837 - GnuCash 3 has changed the capitalisation of the folder in Application Support on macOS
diff --git a/gnucash/CMakeLists.txt b/gnucash/CMakeLists.txt
index 2ae906a..736f8fc 100644
--- a/gnucash/CMakeLists.txt
+++ b/gnucash/CMakeLists.txt
@@ -183,7 +183,7 @@ if (WITH_PYTHON)
endif()
if (MAC_INTEGRATION)
- file(APPEND ${ENV_FILE_OUT} "XDG_CONFIG_HOME={HOME}/Library/Application Support/Gnucash/config\n")
+ file(APPEND ${ENV_FILE_OUT} "XDG_CONFIG_HOME={HOME}/Library/Application Support/${PACKAGE_NAME}/config\n")
file(APPEND ${ENV_FILE_OUT} "GDK_PIXBUF_MODULE_FILE={SYS_LIB}/gdk-pixbuf-2.0/2.10.0/loaders.cache\n")
file(APPEND ${ENV_FILE_OUT} "FONTCONFIG_FILE={GNC_HOME}/etc/fonts/fonts.conf\n")
file(APPEND ${ENV_FILE_OUT} "OFX_DTD_PATH={GNC_HOME}/share/libofx/dtd\n")
commit 5ffb7fa20bb241b96a13768837713be581aa50fe
Author: Geert Janssens <geert at kobaltwit.be>
Date: Fri Aug 31 14:35:11 2018 +0200
Fix input of invoice post and due dates
In the conversion from a timespec pointer to a time64 in
https://github.com/Gnucash/gnucash/commit/6f89bd62b3cf
we lost the write-back of these two dates to the calling function.
Fixed by making the time64 members pointers again as the timespecs were before.
diff --git a/gnucash/gnome/dialog-date-close.c b/gnucash/gnome/dialog-date-close.c
index 977a637..4f4082c 100644
--- a/gnucash/gnome/dialog-date-close.c
+++ b/gnucash/gnome/dialog-date-close.c
@@ -45,7 +45,7 @@ typedef struct _dialog_date_close_window
GtkWidget *memo_entry;
GtkWidget *question_check;
GncBillTerm *terms;
- time64 t, t2;
+ time64 *t, *t2;
GList * acct_types;
GList * acct_commodities;
QofBook *book;
@@ -87,14 +87,14 @@ gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data)
}
if (ddc->post_date)
- ddc->t2 = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->post_date));
+ *ddc->t2 = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->post_date));
if (ddc->date)
{
if (ddc->terms)
- ddc->t = gncBillTermComputeDueDate (ddc->terms, ddc->t2);
+ *ddc->t = gncBillTermComputeDueDate (ddc->terms, *ddc->t2);
else
- ddc->t = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->date));
+ *ddc->t = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->date));
}
if (ddc->memo_entry && ddc->memo)
@@ -134,7 +134,7 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
return FALSE;
ddc = g_new0 (DialogDateClose, 1);
- ddc->t = *t;
+ ddc->t = t;
builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "dialog-date-close.glade", "date_close_dialog");
@@ -220,8 +220,8 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
return FALSE;
ddc = g_new0 (DialogDateClose, 1);
- ddc->t = *ddue;
- ddc->t2 = *post;
+ ddc->t = ddue;
+ ddc->t2 = post;
ddc->book = book;
ddc->acct_types = acct_types;
ddc->acct_commodities = acct_commodities;
@@ -343,7 +343,7 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
return FALSE;
ddc = g_new0 (DialogDateClose, 1);
- ddc->t = *date;
+ ddc->t = date;
ddc->book = book;
ddc->acct_types = acct_types;
ddc->acct = *acct;
commit fc368b91d2b25c7d21df3fe7cb71afdde7ed5e47
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 30 17:03:41 2018 -0700
Restore the timespec_val column name in the slots table.
Renaming it would require a backwards-incompatible schema change,
something that shouldn't happen in the middle of a stable series.
diff --git a/libgnucash/backend/sql/gnc-slots-sql.cpp b/libgnucash/backend/sql/gnc-slots-sql.cpp
index cf1fc7b..4d19734 100644
--- a/libgnucash/backend/sql/gnc-slots-sql.cpp
+++ b/libgnucash/backend/sql/gnc-slots-sql.cpp
@@ -140,7 +140,7 @@ static const EntryVec col_table
gnc_sql_make_table_entry<CT_DOUBLE>("double_val", 0, 0,
(QofAccessFunc)get_double_val,
set_double_val),
- gnc_sql_make_table_entry<CT_TIME>("time_val", 0, 0,
+ gnc_sql_make_table_entry<CT_TIME>("timespec_val", 0, 0,
(QofAccessFunc)get_time_val,
(QofSetterFunc)set_time_val),
gnc_sql_make_table_entry<CT_GUID>("guid_val", 0, 0,
commit 6dfbf3d5e7bed8e09c650b994e62ff74715bdfc9
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 30 11:02:16 2018 -0700
gnc:get-commodity-totalavg-prices shouldn't use 0-amount splits.
get-commodity-totalavg-prices seeks to create a share-weighted average of
all prices for a commodity and 0-share splits (normally used to book
trading gains) don't represent a price and so distort (sometimes
dramatically) the resulting average as well as creating extra invalid
entries in the resulting alist.
diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index 93ceac8..b21e906 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -116,7 +116,8 @@
;; Returns true if the given pricealist element is a non-zero price.
(define (gnc:price-is-not-zero? elem)
- (not (gnc-numeric-zero-p (second elem))))
+ (and (second elem)
+ (not (gnc-numeric-zero-p (second elem)))))
;; Create a list of all prices of 'price-commodity' measured in the currency
;; 'report-currency'. The prices are taken from all splits in
@@ -155,12 +156,16 @@
(transaction-date (xaccTransGetDate
(xaccSplitGetParent a)))
(foreignlist
- (if (gnc-commodity-equiv transaction-comm
- price-commodity)
- (list account-comm
- share-amount value-amount)
- (list transaction-comm
- value-amount share-amount))))
+ (if (and
+ (not (zero? share-amount))
+ (not (zero? value-amount)))
+ (if (gnc-commodity-equiv transaction-comm
+ price-commodity)
+ (list account-comm
+ share-amount value-amount)
+ (list transaction-comm
+ value-amount share-amount))
+ #f)))
;;(warn "gnc:get-commodity-totalavg-prices: value "
;; (gnc-commodity-numeric->string
@@ -170,8 +175,9 @@
;;price-commodity (third foreignlist)))
;; Try EURO exchange if necessary
- (if (not (gnc-commodity-equiv (first foreignlist)
- report-currency))
+ (if (and foreignlist
+ (not (gnc-commodity-equiv (first foreignlist)
+ report-currency)))
(let ((exchanged (gnc:exchange-by-euro-numeric
(first foreignlist) (second foreignlist)
report-currency transaction-date)))
@@ -183,35 +189,37 @@
(list
transaction-date
- (if (not (gnc-commodity-equiv (first foreignlist)
- report-currency))
- (begin
- (warn "gnc:get-commodity-totalavg-prices: "
- "Sorry, currency exchange not yet implemented:"
- (gnc-commodity-numeric->string
- (first foreignlist) (second foreignlist))
- " (buying "
- (gnc-commodity-numeric->string
- price-commodity (third foreignlist))
- ") =? "
- (gnc-commodity-numeric->string
- report-currency (gnc-numeric-zero)))
- (gnc-numeric-zero))
- (begin
- (set! total-foreign (gnc-numeric-add total-foreign
- (third foreignlist)
- GNC-DENOM-AUTO
- GNC-DENOM-LCD))
- (set! total-domestic (gnc-numeric-add total-domestic
- (second foreignlist)
- GNC-DENOM-AUTO
- GNC-DENOM-LCD))
- (if (not (zero? total-foreign))
- (gnc-numeric-div
- total-domestic
- total-foreign
- GNC-DENOM-AUTO
- (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)) 0))))))
+ (if foreignlist
+ (if (not (gnc-commodity-equiv (first foreignlist)
+ report-currency))
+ (begin
+ (warn "gnc:get-commodity-totalavg-prices: "
+ "Sorry, currency exchange not yet implemented:"
+ (gnc-commodity-numeric->string
+ (first foreignlist) (second foreignlist))
+ " (buying "
+ (gnc-commodity-numeric->string
+ price-commodity (third foreignlist))
+ ") =? "
+ (gnc-commodity-numeric->string
+ report-currency (gnc-numeric-zero)))
+ (gnc-numeric-zero))
+ (begin
+ (set! total-foreign (gnc-numeric-add total-foreign
+ (third foreignlist)
+ GNC-DENOM-AUTO
+ GNC-DENOM-LCD))
+ (set! total-domestic (gnc-numeric-add total-domestic
+ (second foreignlist)
+ GNC-DENOM-AUTO
+ GNC-DENOM-LCD))
+ (if (not (zero? total-foreign))
+ (gnc-numeric-div
+ total-domestic
+ total-foreign
+ GNC-DENOM-AUTO
+ (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)) 0)))
+ #f))))
;; Get all the interesting splits, and sort them according to the
;; date.
(gnc:get-match-commodity-splits-sorted
@@ -985,6 +993,9 @@
(lambda (foreign domestic date)
(gnc:exchange-by-pricealist-nearest
pricealist foreign domestic date))))
+ ;; actual-transactions isn't used, at least not as a value passed to this
+ ;; function. price-scatter.scm does use it but calls
+ ;; gnc:get-commodity-inst-prices directly.
((actual-transactions) (let ((pricealist
(gnc:get-commoditylist-inst-prices
commodity-list report-currency to-date-tp)))
diff --git a/gnucash/report/report-system/test/test-commodity-utils.scm b/gnucash/report/report-system/test/test-commodity-utils.scm
index 1a03a21..728da7e 100644
--- a/gnucash/report/report-system/test/test-commodity-utils.scm
+++ b/gnucash/report/report-system/test/test-commodity-utils.scm
@@ -537,16 +537,16 @@
;; the comment at the gnc:get-commodity-totalavg-prices definition for more
;; about the prices from this function.
(test-equal "MSFT totalavg 2014-12-05"
- (gnc-numeric-div 5232000/100 1500 GNC-DENOM-AUTO
+ (gnc-numeric-div 6637500/100 2000 GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))
(cadr (assoc (gnc-dmy2time64-neutral 5 12 2014)
report-list)))
(test-equal "MSFT totalavg 2015-04-02"
- (gnc-numeric-div 10876200/100 2800 GNC-DENOM-AUTO
+ (gnc-numeric-div 9860700/100 2800 GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))
(cadr (assoc (gnc-dmy2time64-neutral 2 4 2015) report-list)))
(test-equal "MSFT totalavg 2016-03-11"
- (gnc-numeric-div 12634400/100 2800 GNC-DENOM-AUTO
+ (gnc-numeric-div 14637000/100 3700 GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))
(cadr (assoc (gnc-dmy2time64-neutral 11 3 2016)
report-list))))
commit c977c2350a83035fadff61053507104aa9309f26
Merge: 28691b4 a639dd9
Author: Geert Janssens <geert at kobaltwit.be>
Date: Thu Aug 30 12:18:15 2018 +0200
Merge branch 'sort-filter' of https://github.com/Bob-IT/gnucash into maint
commit 28691b46ba5fc198eaddf133d48c5696421915b9
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Aug 18 12:36:22 2018 -0700
Create srfi-64 tests for gnucash/report/report-system/commodity-utils.scm.
diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index 63002ea..93ceac8 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -118,11 +118,24 @@
(define (gnc:price-is-not-zero? elem)
(not (gnc-numeric-zero-p (second elem))))
-;; Create a list of all prices of 'price-commodity' measured in the
-;; currency 'report-currency'. The prices are taken from all splits in
-;; 'currency-accounts' up until the date 'end-date'. Returns a list
-;; of lists. Each listelement looks like the list (time price), where
-;; 'time' is the time64 when the <gnc:numeric*> 'price' was valid.
+;; Create a list of all prices of 'price-commodity' measured in the currency
+;; 'report-currency'. The prices are taken from all splits in
+;; 'currency-accounts' up until the date 'end-date'. Returns a list of
+;; lists. Each listelement looks like the list (time price), where 'time' is the
+;; time64 when the <gnc:numeric*> 'price' was valid. The results are distorted
+;; by the existence of capital gains splits because the amount of the gain is
+;; added to the total value with no adjustment to the total amount. For example
+;; if on day1 one buys 200 shares of XYZ at 20 and on day2 sells 100 at 25
+;; booking a capital gain of 500, the resulting foreignlist will be:
+;; ((day1 4000 200)
+;; (day2 500 0)
+;; (day2 2500 100))
+;; returning the following price list:
+;; ((day1 20)
+;; (day2 22.50)
+;; (day2 23.33))
+;; The intended second price is 6500/300, or 21.67.
+
(define (gnc:get-commodity-totalavg-prices
currency-accounts end-date price-commodity report-currency)
(let ((total-foreign (gnc-numeric-zero))
diff --git a/gnucash/report/report-system/test/CMakeLists.txt b/gnucash/report/report-system/test/CMakeLists.txt
index 7ecd67a..6d78a26 100644
--- a/gnucash/report/report-system/test/CMakeLists.txt
+++ b/gnucash/report/report-system/test/CMakeLists.txt
@@ -17,6 +17,7 @@ set(scm_test_report_system_SOURCES
)
set (scm_test_report_system_with_srfi64_SOURCES
+ test-commodity-utils.scm
test-html-utilities-srfi64.scm
test-report-system.scm
)
diff --git a/gnucash/report/report-system/test/test-commodity-utils.scm b/gnucash/report/report-system/test/test-commodity-utils.scm
new file mode 100644
index 0000000..1a03a21
--- /dev/null
+++ b/gnucash/report/report-system/test/test-commodity-utils.scm
@@ -0,0 +1,590 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; test-commodity-utilities.scm: Test the commodity functions
+;; Copyright 2018 John Ralls <jralls at ceridwen.us>
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2 of
+;; the License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, contact:
+;;
+;; Free Software Foundation Voice: +1-617-542-5942
+;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+;; Boston, MA 02110-1301, USA gnu at gnu.org
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
+(use-modules (srfi srfi-64))
+(use-modules (ice-9 pretty-print))
+(use-modules (gnucash engine test srfi64-extras))
+(use-modules (gnucash engine test test-extras))
+(use-modules (gnucash app-utils))
+(use-modules (gnucash engine))
+(use-modules (sw_engine))
+(use-modules (sw_app_utils))
+(use-modules (gnucash report report-system))
+
+(setlocale LC_ALL "C")
+
+(define (run-test)
+ (test-runner-factory gnc:test-runner)
+ (test-begin "commodity-utils")
+ ;; Tests go here
+ (test-setup)
+ (test-resolve-unknown-comm)
+ (test-get-exchange-totals)
+ (test-get-exchange-cost-totals)
+ (test-get-exchange-cost-totals-trading)
+ (test-exchange-by-pricedb-latest)
+ (test-exchange-by-pricedb-nearest)
+ (test-get-commodity-totalavg-prices)
+ (test-get-commodity-inst-prices)
+ (test-end "commodity-utils"))
+
+(define test-accounts
+ (list "Root" (list (cons 'type ACCT-TYPE-ROOT))
+ (list "Assets"(list (cons 'type ACCT-TYPE-ASSET))
+ (list "Current"
+ (list "Savings" (list (cons 'type ACCT-TYPE-BANK)))
+ (list "Checking" (list (cons 'type ACCT-TYPE-BANK))))
+ (list "Investment"
+ (list "Broker A"
+ (list "Cash-A" (list (cons 'type ACCT-TYPE-BANK)))
+ (list "Stocks" (list (cons 'type ACCT-TYPE-STOCK))
+ (list "AAPL-A")
+ (list "IBM-A")
+ (list "MSFT-A")
+ (list "TSLA-A")))
+ (list "Broker B"
+ (list "Cash-B" (list (cons 'type ACCT-TYPE-BANK)))
+ (list "Stocks" (list (cons 'type ACCT-TYPE-STOCK))
+ (list "AAPL-B")
+ (list "IBM-B")
+ (list "MSFT-B")
+ (list "TSLA-B")))
+ (list "Broker-GBP"
+ (list "Cash-GBP" (list (cons 'type ACCT-TYPE-BANK)))
+ (list "Stocks" (list (cons 'type ACCT-TYPE-STOCK))
+ (list "RDSA")))))
+ (list "Income" (list (cons 'type ACCT-TYPE-INCOME))
+ (list "Capital Gains"))
+ (list "Expenses" (list (cons 'type ACCT-TYPE-EXPENSE)))
+ (list "Liability" (list (cons 'type ACCT-TYPE-LIABILITY)))
+ (list "Equity" (list (cons 'type ACCT-TYPE-EQUITY))
+ (list "Opening Balances"))))
+
+(define (setup trading)
+ (let* ((env (create-test-env))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (AAPL (gnc-commodity-new book "Apple" "NASDAQ" "AAPL" "" 1))
+ (IBM (gnc-commodity-new book "International Business Machines"
+ "NYSE" "IBM" "" 1))
+ (MSFT (gnc-commodity-new book "Microsoft" "NASDAQ" "MSFT" "" 1))
+ (TSLA (gnc-commodity-new book "Tesla Motors" "NASDAQ" "TSLA" "" 1))
+ (RDSA (gnc-commodity-new book "Royal Dutch Shell A" "LSE" "RDSA" "" 1))
+ ;; Yeah, this is fake, it's for testing DEM->EUR conversions.
+ (DMLR (gnc-commodity-new book "Daimler Motors" "FSE" "DMLR" "" 1))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (account-alist (env-create-account-structure-alist env test-accounts))
+ (checking (cdr (assoc "Checking" account-alist)))
+ (saving (cdr (assoc "Savings" account-alist)))
+ (cash-a (cdr (assoc "Cash-A" account-alist)))
+ (aapl-a (cdr (assoc "AAPL-A" account-alist)))
+ (ibm-a (cdr (assoc "IBM-A" account-alist)))
+ (msft-a (cdr (assoc "MSFT-A" account-alist)))
+ (tsla-a (cdr (assoc "TSLA-A" account-alist)))
+ (cash-b (cdr (assoc "Cash-B" account-alist)))
+ (aapl-b (cdr (assoc "AAPL-B" account-alist)))
+ (ibm-b (cdr (assoc "IBM-B" account-alist)))
+ (msft-b (cdr (assoc "MSFT-B" account-alist)))
+ (tsla-b (cdr (assoc "TSLA-B" account-alist)))
+ (capgain (cdr (assoc "Capital Gains" account-alist)))
+ (openbal (cdr (assoc "Opening Balances" account-alist))))
+ ;; Set account commodities
+ (gnc-commodity-table-insert comm-table AAPL)
+ (gnc-commodity-table-insert comm-table MSFT)
+ (gnc-commodity-table-insert comm-table IBM)
+ (gnc-commodity-table-insert comm-table RDSA)
+ (gnc-commodity-table-insert comm-table TSLA)
+ (xaccAccountSetCommodity aapl-a AAPL)
+ (xaccAccountSetCommodity ibm-a IBM)
+ (xaccAccountSetCommodity msft-a MSFT)
+ (xaccAccountSetCommodity tsla-a TSLA)
+ (xaccAccountSetCommodity aapl-b AAPL)
+ (xaccAccountSetCommodity ibm-b IBM)
+ (xaccAccountSetCommodity msft-b MSFT)
+ (xaccAccountSetCommodity tsla-b TSLA)
+ ;; Create transactions in the accounts
+ (env-transfer env 15 11 2011 openbal saving 1553746/100
+ #:description "Fund Savings")
+ (env-transfer env 15 11 2011 openbal checking 329726/100
+ #:description "Fund Checking")
+ (env-transfer env 15 11 2011 openbal cash-a 11543627/100
+ #:description "Fund Broker A")
+ (env-transfer-foreign env 15 01 2012 cash-a ibm-a 3583200/100 200
+ #:description "Buy IBM 200") ;;200 @ $179.16
+ (env-transfer-foreign env 15 01 2012 cash-a msft-a 4216500/100 1500
+ #:description "Buy MSFT 1500") ;;1500 @ $28.11
+ (env-transfer-foreign env 9 8 2013 cash-a aapl-a 3684000/100 600
+ #:description "Buy AAPL 600") ;;600 @ $61.40
+ (env-transfer-foreign env 5 12 2014 cash-a msft-a -2421000/100 -500
+ #:description "Sell MSFT 500");;-500 @ $48.42
+ (env-transfer-foreign env 5 12 2014 capgain msft-a 1015500/100 0
+ #:description "MSFT 500 G/L")
+ (env-transfer-foreign env 8 8 2014 cash-a ibm-a -3732600/100 -200
+ #:description "Sell IBM 200") ;;-200 @ $186.63
+ (env-transfer-foreign env 8 8 2014 capgain ibm-a 149400/100 0
+ #:description "IBM 200 G/L")
+ (env-transfer env 15 6 2014 cash-a cash-b 4000000/100
+ #:description "Fund Broker B")
+ (env-transfer-foreign env 11 7 2014 cash-b aapl-b 3808800/100 400
+ #:description "Buy AAPL 400") ;;400 @ $95.22
+ (env-transfer-foreign env 2 4 2015 cash-a msft-a 3223200/100 800
+ #:description "Buy MSFT 800") ;;800 @ $40.29
+ (env-transfer-foreign env 23 10 2015 cash-a aapl-a -3572400/100 -300
+ #:description "Sell AAPL 300") ;;-300 @ $119.08
+ (env-transfer-foreign env 23 10 2015 capgain aapl-a 1730400/100 0
+ #:description"AAPL 300 G/L")
+ (env-transfer-foreign env 11 3 2016 cash-a msft-a -4776300/100 -900
+ #:description "Sell MSFT 900") ;;-900 @ $53.07
+ (env-transfer-foreign env 11 3 2016 capgain msft-a 1758200/100 0
+ #:description"MSFT 900 G/L")
+ (gnc-pricedb-create USD MSFT (gnc-dmy2time64 1 1 2013) 2674/100)
+ (gnc-pricedb-create USD IBM (gnc-dmy2time64 1 1 2013) 19399/100)
+ (gnc-pricedb-create USD AAPL (gnc-dmy2time64 1 1 2014) 7728/100)
+ (gnc-pricedb-create USD MSFT (gnc-dmy2time64 1 1 2014) 3691/100)
+ (gnc-pricedb-create USD IBM (gnc-dmy2time64 1 1 2014) 18664/100)
+ (gnc-pricedb-create USD AAPL (gnc-dmy2time64 1 1 2015) 10933/100)
+ (gnc-pricedb-create USD MSFT (gnc-dmy2time64 1 1 2015) 4676/100)
+ (gnc-pricedb-create USD IBM (gnc-dmy2time64 1 1 2015) 16206/100)
+ (gnc-pricedb-create USD AAPL (gnc-dmy2time64 1 1 2016) 10526/100)
+ (gnc-pricedb-create USD MSFT (gnc-dmy2time64 1 1 2016) 5548/100)
+ (gnc-pricedb-create USD IBM (gnc-dmy2time64 1 1 2016) 13163/100)
+ (gnc-pricedb-create USD AAPL (gnc-dmy2time64 1 1 2017) 11582/100)
+ (gnc-pricedb-create USD MSFT (gnc-dmy2time64 1 1 2017) 6214/100)
+ (gnc-pricedb-create USD IBM (gnc-dmy2time64 1 1 2017) 16599/100)
+ account-alist))
+
+
+(define (teardown)
+ (let* ((book (gnc-get-current-book))
+ (pricedb (gnc-pricedb-get-db book)))
+ (gnc-pricedb-destroy pricedb)
+ (gnc-clear-current-session)))
+
+(define (collect collector shares value)
+ ((car collector) 'add shares)
+ ((cdr collector) 'add value))
+
+(define (test-setup)
+ ;; This test ensures that our setup function creates a suitable book
+ (let* ((account-alist (setup #f))
+ (cash-a (cdr (assoc "Cash-A" account-alist)))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (pricedb (gnc-pricedb-get-db book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM")))
+ (test-begin "Test Setup")
+ (test-equal "Broker A Cash account balance 73390.27"
+ 7339027/100 (xaccAccountGetBalance cash-a))
+ (test-assert "Have IBM Prices" (gnc-pricedb-has-prices pricedb IBM USD))
+ (let ((ibm-price (gnc-pricedb-lookup-latest pricedb IBM USD)))
+ (test-equal "IBM Latest Price" 16599/100 (gnc-price-get-value ibm-price))
+ (gnc-price-unref ibm-price))
+ (test-end "Test Setup")
+ (teardown)))
+
+(define (test-resolve-unknown-comm)
+ (test-group-with-cleanup "gnc:resolve-unknown-comm"
+ (let* ((account-alist (setup #f))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (DEM (gnc-commodity-table-lookup comm-table "CURRENCY" "DEM"))
+ (MSFT (gnc-commodity-table-lookup comm-table "NASDAQ" "MSFT"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM"))
+ (AAPL (gnc-commodity-table-lookup comm-table "NASDAQ" "AAPL"))
+ (RDSA (gnc-commodity-table-lookup comm-table "LSE" "RDSA"))
+ (DMLR (gnc-commodity-table-lookup comm-table "FSE" "DMLR"))
+ (aapl-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (msft-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (ibm-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (rdsa-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (rdsa-gbp-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (dmlr-dem-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (gbp-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (eur-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (gbp-usd-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (gbp-eur-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (gbp-dem-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (dem-gbp-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (eur-gbp-col (cons (gnc:make-value-collector) (gnc:make-value-collector)))
+ (eur-usd-col (cons (gnc:make-value-collector) (gnc:make-value-collector))))
+ (test-begin "basic")
+ ;; Entries in the report currency just fall through and are emitted in the
+ ;; result alist.
+ (collect aapl-col 600 3684000/100)
+ (collect aapl-col -300 -3572400/100)
+ (collect aapl-col 0 1730400/100) ;; cap gain
+ (let* ((sumlist (list (list USD (list (list AAPL aapl-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-equal "AAPL 700 shares" 300 ((caadr (assoc AAPL return-alist)) 'total #f))
+ (test-equal "AAPL $18420.00" 1842000/100 ((cdadr (assoc AAPL return-alist)) 'total #f)))
+ (test-end "basic")
+ (test-begin "foreign-no-coll")
+ ;; Now we begin to exercise the function. First up is that it fails to
+ ;; register the security at all if there's no pair of prices that can
+ ;; resolve the transaction commodity to the report currency.
+ (collect rdsa-gbp-col 500 3223400/100)
+ ;; We need a report-currency alist with something in it or
+ ;; resolve-unknown-comm crashes.
+ (let* ((sumlist (list (list USD (list (list AAPL aapl-col)))
+ (list GBP (list (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-equal "RDSA #f" #f ((caadr (assoc RDSA return-alist)) 'total #f))
+ (test-equal "RDSA #f" #f ((cdadr (assoc RDSA return-alist)) 'total #f)))
+ (test-end "foreign-no-coll")
+ (test-begin "foreign-no-amount")
+ ;; There's a collector but it doesn't have a price in it so the returned
+ ;; price is 0.
+ (let* ((sumlist (list (list USD (list (list GBP gbp-col)))
+ (list GBP (list (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-equal "RDSA 500 shares" 500 ((caadr (assoc RDSA return-alist)) 'total #f))
+ (test-equal "RDSA $0" 0 ((cdadr (assoc RDSA return-alist)) 'total #f)))
+ (test-end "foreign-no-amount")
+ (test-begin "foreign-coll-and-amount")
+ (collect gbp-col 10000/100 15300/100)
+ (let* ((sumlist (list (list USD (list (list GBP gbp-col)))
+ (list GBP (list (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-equal "RDSA 500 shares" 500 ((caadr (assoc RDSA return-alist)) 'total #f))
+ (test-equal "RDSA $49,318.02" 4931802/100 ((cdadr (assoc RDSA return-alist)) 'total #f)))
+ (test-end "foreign-coll-and-amount")
+ (test-begin "foreign-inv-coll")
+ ;; Now try with a conversion in the foreign currency instead of the native
+ ;; one.
+ (collect gbp-usd-col 15300/100 10000/100)
+ (let* ((sumlist (list (list USD (list (list AAPL aapl-col)))
+ (list GBP (list (list USD gbp-usd-col)
+ (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-equal "RDSA 500 shares" 500 ((caadr (assoc RDSA return-alist)) 'total #f))
+ (test-equal "RDSA $49318.02" 4931802/100 ((cdadr (assoc RDSA return-alist)) 'total #f)))
+ (test-end "foreign-inv-coll")
+ (test-begin "foreign-3way")
+ ;; Three-way conversion, gbp->eur->usd
+ (collect eur-gbp-col 10000/100 121045/1000)
+ (collect eur-col 10000/100 126399/1000)
+ (let* ((sumlist (list (list USD (list (list EUR eur-col)))
+ (list EUR (list (list GBP eur-gbp-col)))
+ (list GBP (list (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-equal "RDSA 500 shares" 500 ((caadr (assoc RDSA return-alist)) 'total #f))
+ (test-equal "RDSA $49317.91" 4931791/100 (gnc-numeric-convert ((cdadr (assoc RDSA return-alist)) 'total #f) 100 GNC-HOW-RND-ROUND)))
+ (test-end "foreign-3way")
+ (test-begin "foreign-3way-ambig")
+ ;; Three-way conversion, gbp->eur->usd The equalities are false because
+ ;; there is both a USD price and a GBP price for
+ ;; RDSA. gnc:get-exchange-totals is supposed to resolve this when writing
+ ;; the sumlist, we're testing that gnc:resolve-unknown-comm writes its
+ ;; warning.
+ (collect eur-gbp-col 10000/100 121045/1000)
+ (collect eur-col 10000/100 126399/1000)
+ (collect eur-usd-col 126399/1000 10000/100)
+ (collect rdsa-col 10000/100 1219300/100)
+ (let* ((sumlist (list (list USD (list (list RDSA rdsa-col)
+ (list EUR eur-col)))
+ (list EUR (list (list GBP eur-gbp-col)
+ (list USD eur-usd-col)))
+ (list GBP (list (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-assert "RDSA 600 shares" (not (equal? 600 ((caadr (assoc RDSA return-alist)) 'total #f))))
+ (test-assert "RDSA $61510.91" (not (equal? 6151091/100 (gnc-numeric-convert ((cdadr (assoc RDSA return-alist)) 'total #f) 100 GNC-HOW-RND-ROUND)))))
+ (test-end "foreign-3way-ambig")
+ (test-begin "foreign-DEM>EUR")
+ ;; Old currency->Euro conversion.
+ (collect dmlr-dem-col 500 2668000/100)
+ (let* ((sumlist (list (list EUR (list (list USD eur-usd-col)))
+ (list DEM (list (list DMLR dmlr-dem-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist EUR)))
+ (test-equal "DMLR 500 shares" 500 ((caadr (assoc DMLR return-alist)) 'total #f))
+ (test-equal "DMLR EUR13631.27" 1364127/100 (gnc-numeric-convert ((cdadr (assoc DMLR return-alist)) 'total #f) 100 GNC-HOW-RND-ROUND)))
+ (test-end "foreign-DEM>EUR")
+ (test-begin "foreign-3way-DEM>EUR")
+ ;; Three-way conversion, gbp->dem->eur->usd
+ ;; Too many levels for resolve-unknown-comm to resolve.
+ (collect gbp-dem-col 10000/100 23665543/100000)
+ (let* ((sumlist (list (list USD (list (list EUR eur-col)))
+ (list GBP (list (list DEM gbp-dem-col)
+ (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-equal "Shares fails" #f ((caadr (assoc RDSA return-alist)) 'total #f))
+ (test-equal "Value fails" #f ((cdadr (assoc RDSA return-alist)) 'total #f)))
+ (test-end "foreign-3way-GBP>DEM")
+ (test-begin "foreign-3way-DEM>GBP")
+ ;; Three-way conversion, gbp->dem->eur->usd
+ ;; Too many levels for resolve-unknown-comm to resolve.
+ (collect gbp-dem-col 23665543/100000 10000/100)
+ (let* ((sumlist (list (list USD (list (list EUR eur-col)))
+ (list DEM (list (list GBP dem-gbp-col)))
+ (list GBP (list (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist USD)))
+ (test-equal "Shares fails" #f ((caadr (assoc RDSA return-alist)) 'total #f))
+ (test-equal "Value fails" #f ((cdadr (assoc RDSA return-alist)) 'total #f)))
+ (test-end "foreign-3way-DEM>GBP")
+ (test-begin "foreign-DEM>EUR")
+ ;; Three-way conversion, gbp->dem->eur
+ ;; Too many levels for resolve-unknown-comm to resolve.
+ (let* ((sumlist (list (list EUR (list (list USD eur-usd-col)))
+ (list GBP (list (list DEM gbp-dem-col)
+ (list RDSA rdsa-gbp-col)))))
+ (return-alist (gnc:resolve-unknown-comm sumlist EUR)))
+ (test-equal "Shares fails" #f ((caadr (assoc RDSA return-alist)) 'total #f))
+ (test-equal "Value fails" #f ((cdadr (assoc RDSA return-alist)) 'total #f)))
+ (test-end "foreign-DEM>EUR"))
+
+ (teardown)))
+
+(define (test-get-exchange-totals)
+ (test-group-with-cleanup "gnc:get-exchange-totals"
+ (let* ((account-alist (setup #f))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (DEM (gnc-commodity-table-lookup comm-table "CURRENCY" "DEM"))
+ (MSFT (gnc-commodity-table-lookup comm-table "NASDAQ" "MSFT"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM"))
+ (AAPL (gnc-commodity-table-lookup comm-table "NASDAQ" "AAPL"))
+ (RDSA (gnc-commodity-table-lookup comm-table "LSE" "RDSA"))
+ (DMLR (gnc-commodity-table-lookup comm-table "FSE" "DMLR")))
+ (test-begin "multiple")
+ (let ((return-alist (gnc:get-exchange-totals USD (gnc-dmy2time64-neutral 1 12 2016))))
+ (test-equal "AAPL 1300 shares" 1300 ((caadr (assoc AAPL return-alist)) 'total #f))
+ (test-equal "AAPL $110652.00" 11065200/100 ((cdadr (assoc AAPL return-alist)) 'total #f))
+ (test-equal "MSFT 3700 shares" 3700 ((caadr (assoc MSFT return-alist)) 'total #f))
+ (test-equal "MSFT $146370.00" 14637000/100 ((cdadr (assoc MSFT return-alist)) 'total #f))
+ (test-equal "IBM 400 shares" 400 ((caadr (assoc IBM return-alist)) 'total #f))
+ (test-equal "IBM $73158" 7315800/100 ((cdadr (assoc IBM return-alist)) 'total #f)))
+ (test-end "multiple"))
+ (teardown)))
+
+(define (test-get-exchange-cost-totals)
+ (test-group-with-cleanup "gnc:get-exchange-cost-totals"
+ (let* ((account-alist (setup #f))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (DEM (gnc-commodity-table-lookup comm-table "CURRENCY" "DEM"))
+ (MSFT (gnc-commodity-table-lookup comm-table "NASDAQ" "MSFT"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM"))
+ (AAPL (gnc-commodity-table-lookup comm-table "NASDAQ" "AAPL"))
+ (RDSA (gnc-commodity-table-lookup comm-table "LSE" "RDSA"))
+ (DMLR (gnc-commodity-table-lookup comm-table "FSE" "DMLR")))
+ (test-begin "multiple")
+ (let ((return-alist (gnc:get-exchange-cost-totals USD (gnc-dmy2time64-neutral 1 12 2016))))
+ (test-equal "AAPL 700 shares" 700 ((caadr (assoc AAPL return-alist)) 'total #f))
+ (test-equal "AAPL $56512.00" 5650800/100 ((cdadr (assoc AAPL return-alist)) 'total #f))
+ (test-equal "MSFT 900 shares" 900 ((caadr (assoc MSFT return-alist)) 'total #f))
+ (test-equal "MSFT $30161.00" 3016100/100 ((cdadr (assoc MSFT return-alist)) 'total #f))
+ (test-equal "IBM 0 shares" 0 ((caadr (assoc IBM return-alist)) 'total #f))
+ (test-equal "IBM $0" 0 ((cdadr (assoc IBM return-alist)) 'total #f)))
+ (test-end "multiple"))
+ (teardown)))
+
+(define (test-get-exchange-cost-totals-trading)
+ (test-group-with-cleanup
+ "gnc:get-exchange-totals-trading"
+ (let* ((account-alist (setup #t))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (DEM (gnc-commodity-table-lookup comm-table "CURRENCY" "DEM"))
+ (MSFT (gnc-commodity-table-lookup comm-table "NASDAQ" "MSFT"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM"))
+ (AAPL (gnc-commodity-table-lookup comm-table "NASDAQ" "AAPL"))
+ (RDSA (gnc-commodity-table-lookup comm-table "LSE" "RDSA"))
+ (DMLR (gnc-commodity-table-lookup comm-table "FSE" "DMLR")))
+ (test-begin "multiple")
+ (let ((return-alist (gnc:get-exchange-cost-totals
+ USD (gnc-dmy2time64-neutral 1 12 2016))))
+ (test-equal "AAPL 700 shares"
+ 700 ((caadr (assoc AAPL return-alist)) 'total #f))
+ (test-equal "AAPL $56512.00"
+ 5650800/100 ((cdadr (assoc AAPL return-alist)) 'total #f))
+ (test-equal "MSFT 900 shares"
+ 900 ((caadr (assoc MSFT return-alist)) 'total #f))
+ (test-equal "MSFT $30161.00"
+ 3016100/100 ((cdadr (assoc MSFT return-alist)) 'total #f))
+ (test-equal "IBM 0 shares"
+ 0 ((caadr (assoc IBM return-alist)) 'total #f))
+ (test-equal "IBM $0"
+ 0 ((cdadr (assoc IBM return-alist)) 'total #f)))
+ (test-end "multiple"))
+ (teardown)))
+
+(define (test-exchange-by-pricedb-latest)
+ (test-group-with-cleanup
+ "gnc:exchange-by-pricedb-latest"
+ (let* ((account-alist (setup #f))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (pricedb (gnc-pricedb-get-db book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (DEM (gnc-commodity-table-lookup comm-table "CURRENCY" "DEM"))
+ (MSFT (gnc-commodity-table-lookup comm-table "NASDAQ" "MSFT"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM"))
+ (AAPL (gnc-commodity-table-lookup comm-table "NASDAQ" "AAPL"))
+ (RDSA (gnc-commodity-table-lookup comm-table "LSE" "RDSA"))
+ (DMLR (gnc-commodity-table-lookup comm-table "FSE" "DMLR")))
+ (test-begin "multiple")
+ (test-equal "AAPL latest" 11582/100 (gnc:gnc-monetary-amount
+ (gnc:exchange-by-pricedb-latest
+ (gnc:make-gnc-monetary AAPL 1) USD)))
+ (test-equal "MSFT latest" 6214/100 (gnc:gnc-monetary-amount
+ (gnc:exchange-by-pricedb-latest
+ (gnc:make-gnc-monetary MSFT 1) USD)))
+ (test-equal "IBM latest" 16599/100 (gnc:gnc-monetary-amount
+ (gnc:exchange-by-pricedb-latest
+ (gnc:make-gnc-monetary IBM 1) USD)))
+ (test-end "multiple"))
+ (teardown)))
+
+(define (test-exchange-by-pricedb-nearest)
+ (test-group-with-cleanup
+ "gnc:exchange-by-pricedb-nearest"
+ (let* ((account-alist (setup #f))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (DEM (gnc-commodity-table-lookup comm-table "CURRENCY" "DEM"))
+ (MSFT (gnc-commodity-table-lookup comm-table "NASDAQ" "MSFT"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM"))
+ (AAPL (gnc-commodity-table-lookup comm-table "NASDAQ" "AAPL"))
+ (RDSA (gnc-commodity-table-lookup comm-table "LSE" "RDSA"))
+ (DMLR (gnc-commodity-table-lookup comm-table "FSE" "DMLR")))
+ (test-begin "multiple")
+ (test-equal "AAPL nearest 23 March 2015"
+ 10933/100 (gnc:gnc-monetary-amount
+ (gnc:exchange-by-pricedb-nearest
+ (gnc:make-gnc-monetary AAPL 1) USD
+ (gnc-dmy2time64 23 3 2015))))
+ (test-equal "MSFT nearest 11 September 2016"
+ 6214/100 (gnc:gnc-monetary-amount
+ (gnc:exchange-by-pricedb-nearest
+ (gnc:make-gnc-monetary MSFT 1) USD
+ (gnc-dmy2time64 11 9 2016))))
+ (test-equal "IBM nearest 1 July 2014"
+ 18664/100 (gnc:gnc-monetary-amount
+ (gnc:exchange-by-pricedb-nearest
+ (gnc:make-gnc-monetary IBM 1) USD
+ (gnc-dmy2time64 1 7 2014))))
+ (test-end "multiple"))
+ (teardown)))
+
+(define (test-get-commodity-totalavg-prices)
+ (test-group-with-cleanup
+ "gnc:get-commodity-totalavg-prices"
+ (let* ((account-alist (setup #f))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (DEM (gnc-commodity-table-lookup comm-table "CURRENCY" "DEM"))
+ (MSFT (gnc-commodity-table-lookup comm-table "NASDAQ" "MSFT"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM"))
+ (AAPL (gnc-commodity-table-lookup comm-table "NASDAQ" "AAPL"))
+ (RDSA (gnc-commodity-table-lookup comm-table "LSE" "RDSA"))
+ (DMLR (gnc-commodity-table-lookup comm-table "FSE" "DMLR")))
+ (test-begin "Microsoft-USD")
+ (let* ((curraccts (gnc-account-get-descendants-sorted
+ (gnc-get-current-root-account)))
+ (report-list
+ (gnc:get-commodity-totalavg-prices curraccts
+ (gnc-dmy2time64 4 7 2016)
+ MSFT USD)))
+ (test-equal "MSFT totalavg 2012-01-15" (/ 4216500/100 1500)
+ (cadr (assoc (gnc-dmy2time64-neutral 15 01 2012)
+ report-list)))
+;; We have to use gnc-numeric-div with rounding in order to match the results
+;; from the function. Astute observers will notice that the totals include the
+;; capital gain split but not the acutal sell split on the day because the
+;; capital gain price is first in the list so that's the one (assoc) finds. See
+;; the comment at the gnc:get-commodity-totalavg-prices definition for more
+;; about the prices from this function.
+ (test-equal "MSFT totalavg 2014-12-05"
+ (gnc-numeric-div 5232000/100 1500 GNC-DENOM-AUTO
+ (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))
+ (cadr (assoc (gnc-dmy2time64-neutral 5 12 2014)
+ report-list)))
+ (test-equal "MSFT totalavg 2015-04-02"
+ (gnc-numeric-div 10876200/100 2800 GNC-DENOM-AUTO
+ (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))
+ (cadr (assoc (gnc-dmy2time64-neutral 2 4 2015) report-list)))
+ (test-equal "MSFT totalavg 2016-03-11"
+ (gnc-numeric-div 12634400/100 2800 GNC-DENOM-AUTO
+ (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))
+ (cadr (assoc (gnc-dmy2time64-neutral 11 3 2016)
+ report-list))))
+ (test-end "Microsoft-USD"))
+ (teardown)))
+
+(define (test-get-commodity-inst-prices)
+ (test-group-with-cleanup
+ "gnc:get-commodity-inst-prices"
+ (let* ((account-alist (setup #f))
+ (book (gnc-get-current-book))
+ (comm-table (gnc-commodity-table-get-table book))
+ (USD (gnc-commodity-table-lookup comm-table "CURRENCY" "USD"))
+ (GBP (gnc-commodity-table-lookup comm-table "CURRENCY" "GBP"))
+ (EUR (gnc-commodity-table-lookup comm-table "CURRENCY" "EUR"))
+ (DEM (gnc-commodity-table-lookup comm-table "CURRENCY" "DEM"))
+ (MSFT (gnc-commodity-table-lookup comm-table "NASDAQ" "MSFT"))
+ (IBM (gnc-commodity-table-lookup comm-table "NYSE" "IBM"))
+ (AAPL (gnc-commodity-table-lookup comm-table "NASDAQ" "AAPL"))
+ (RDSA (gnc-commodity-table-lookup comm-table "LSE" "RDSA"))
+ (DMLR (gnc-commodity-table-lookup comm-table "FSE" "DMLR")))
+ (test-begin "Microsoft-USD")
+ (let* ((curraccts (gnc-account-get-descendants-sorted
+ (gnc-get-current-root-account)))
+ (report-list
+ (gnc:get-commodity-inst-prices curraccts
+ (gnc-dmy2time64 4 7 2016)
+ MSFT USD)))
+ (test-equal "MSFT inst 2012-01-15" (/ 4216500/100 1500)
+ (cadr (assoc (gnc-dmy2time64-neutral 15 01 2012)
+ report-list)))
+ (test-equal "MSFT inst 2014-12-05" (/ 2421000/100 500)
+ (cadr (assoc (gnc-dmy2time64-neutral 5 12 2014)
+ report-list)))
+ (test-equal "MSFT inst 2015-04-02" (/ 3223200/100 800)
+ (cadr (assoc (gnc-dmy2time64-neutral 2 4 2015) report-list)))
+ (test-equal "MSFT inst 2016-03-11" (/ 4776300/100 900)
+ (cadr (assoc (gnc-dmy2time64-neutral 11 3 2016)
+ report-list))))
+ (test-end "Microsoft-USD"))
+ (teardown)))
commit b1ee7c6eec8b18647213d955bdd4b229815a438a
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Aug 24 14:25:43 2018 -0700
Clarify and de-duplicate sumlist and report-list descriptions.
Also correct descriptions of gnc:get-exchange-totals and
gnc:get-exchange-cost-totals. Neither calculates prices.
diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index f7ce0e6..63002ea 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -388,13 +388,24 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions to get one price at a given time (i.e. not time-variant).
+;; Several of the following functions use two types of alist, a return-list or a
+;; sumlist.
+;;
+;; A return-list is an alist with a GncCommodity pointer as the keys and a pair
+;; of gnc-value-collectors, one for amount and the other for value, as the
+;; value.
+;;
+;; A sumlist is an alist having a GncCommodity pointer as the key and a
+;; return-list as the values. The reason for the outer alist is that there might
+;; be commodity transactions which do not involve the report-commodity, but
+;; which can still be calculated after *all* transactions are processed.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Go through all toplevel non-'report-commodity' balances in 'sumlist' and add
+;; them to 'report-commodity', if possible. This function takes a sumlist
+;; (described in gnc:get-exchange-totals) and returns a report-list, This
+;; resulting alist can immediately be plugged into gnc:make-exchange-alist.
-;; Go through all toplevel non-'report-commodity' balances in
-;; 'sumlist' and add them to 'report-commodity', if possible. This
-;; function takes a sumlist (described in gnc:get-exchange-totals) and
-;; returns an alist similar to one value of the sumlist's alist,
-;; e.g. (cadr (assoc report-commodity sumlist))). This resulting alist
-;; can immediately be plugged into gnc:make-exchange-alist.
(define (gnc:resolve-unknown-comm sumlist report-commodity)
;; reportlist contains all known transactions with the
;; report-commodity, and now the transactions with unknown
@@ -529,28 +540,17 @@
;; this functions to use some kind of recursiveness.
-;; Calculate the weighted average exchange rate between all
-;; commodities and the 'report-commodity'. Uses all currency
-;; transactions up until the 'end-date'. Returns an alist, see
-;; sumlist.
+;; Sum the absolute value of the amounts and values in the report commodity of
+;; all exchanges, ignoring gain/loss splits (i.e. those with a 0 amount). For
+;; example, if one bought 1000 GBP for 1210 EUR and then 1190 EUR for 1000 GBP,
+;; if the report currency is EUR the result will be an entry for GBP having an
+;; amount total of 2000 GBP and a value of 2400 EUR. Returns a report-list.
+
(define (gnc:get-exchange-totals report-commodity end-date)
(let ((curr-accounts
;;(filter gnc:account-has-shares? ))
;; -- use all accounts, not only share accounts, since gnucash-1.7
(gnc-account-get-descendants-sorted (gnc-get-current-root-account)))
- ;; sumlist: a multilevel alist. Each element has a commodity
- ;; as key, and another alist as a value. The value-alist's
- ;; elements consist of a commodity as a key, and a pair of two
- ;; value-collectors as value, e.g. with only one (the report-)
- ;; commodity DEM in the outer alist: ( {DEM ( [USD (400 .
- ;; 1000)] [FRF (300 . 100)] ) } ) where DEM,USD,FRF are
- ;; <gnc:commodity> and the numbers are a numeric-collector
- ;; which in turn store a <gnc:numeric>. In the example, USD
- ;; 400 were bought for an amount of DEM 1000, FRF 300 were
- ;; bought for DEM 100. The reason for the outer alist is that
- ;; there might be commodity transactions which do not involve
- ;; the report-commodity, but which can still be calculated
- ;; after *all* transactions are processed.
(sumlist (list (list report-commodity '()))))
(if (not (null? curr-accounts))
@@ -621,27 +621,15 @@
(gnc:resolve-unknown-comm sumlist report-commodity)))
-;; Calculate the volume-weighted average cost of all commodities,
-;; priced in the 'report-commodity'. Uses all transactions up until
-;; the 'end-date'. Returns an alist, see sumlist.
+;; Sum the net amounts and values in the report commodity, including booked
+;; gains and losses, of each commodity across all accounts. Returns a
+;; report-list.
+
(define (gnc:get-exchange-cost-totals report-commodity end-date)
(let ((curr-accounts
;;(filter gnc:account-has-shares? ))
;; -- use all accounts, not only share accounts, since gnucash-1.7
(gnc-account-get-descendants-sorted (gnc-get-current-root-account)))
- ;; sumlist: a multilevel alist. Each element has a commodity
- ;; as key, and another alist as a value. The value-alist's
- ;; elements consist of a commodity as a key, and a pair of two
- ;; value-collectors as value, e.g. with only one (the report-)
- ;; commodity DEM in the outer alist: ( {DEM ( [USD (400 .
- ;; 1000)] [FRF (300 . 100)] ) } ) where DEM,USD,FRF are
- ;; <gnc:commodity> and the numbers are a numeric-collector
- ;; which in turn store a <gnc:numeric>. In the example, USD
- ;; 400 were bought for an amount of DEM 1000, FRF 300 were
- ;; bought for DEM 100. The reason for the outer alist is that
- ;; there might be commodity transactions which do not involve
- ;; the report-commodity, but which can still be calculated
- ;; after *all* transactions are processed.
(sumlist (list (list report-commodity '()))))
(if (not (null? curr-accounts))
commit 704afc6e02fc78f7d8669f6b4ef3be239c05e543
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Aug 24 14:25:04 2018 -0700
Comment to explain structuring an (env-transfer-foreign).
diff --git a/libgnucash/engine/test/test-extras.scm b/libgnucash/engine/test/test-extras.scm
index 90c3ed5..d671e9e 100644
--- a/libgnucash/engine/test/test-extras.scm
+++ b/libgnucash/engine/test/test-extras.scm
@@ -157,6 +157,17 @@
(gnc-price-commit-edit price)
(gnc-pricedb-add-price pricedb price)))
+;; When creating stock transactions always put the stock account and the number
+;; of shares second, using negative numbers for a sale. e.g., to buy 100 shares
+;; of IBM:
+;; (env-transfer-foreign env 15 01 2012 cash-a ibm-a 3583200/100 200
+;; #:description "Buy IBM 200") ;;200 @ $179.16
+;; and to sell them:
+;; (env-transfer-foreign env 8 8 2014 cash-a ibm-a -3732600/100 -200
+;; #:description "Sell IBM 200") ;;-200 @ $186.63
+;; (env-transfer-foreign env 8 8 2014 capgain ibm-a 149400/100 0
+;; #:description "IBM 200 G/L")
+
(define* (env-transfer-foreign
env
DD MM YY ; day/month/year
@@ -204,7 +215,7 @@
(xaccSplitSetMemo split-1 memo)
(xaccSplitSetMemo split-2 memo)))
(if (> amount2 0)
- (gnc-pricedb-create (xaccAccountGetCommodity debit)
+ (gnc-pricedb-create (xaccAccountGetCommodity debit)
(xaccAccountGetCommodity credit)
(gnc-dmy2time64 DD MM YY)
(/ amount1 amount2)))
commit fe73f52bdbdecfe73797aacc327d50f67f29d68d
Author: John Ralls <jralls at ceridwen.us>
Date: Mon Aug 27 18:00:55 2018 -0700
Guard against divide-by-zero errors.
diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index 987f527..f7ce0e6 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -193,11 +193,12 @@
(second foreignlist)
GNC-DENOM-AUTO
GNC-DENOM-LCD))
- (gnc-numeric-div
- total-domestic
- total-foreign
- GNC-DENOM-AUTO
- (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)))))))
+ (if (not (zero? total-foreign))
+ (gnc-numeric-div
+ total-domestic
+ total-foreign
+ GNC-DENOM-AUTO
+ (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)) 0))))))
;; Get all the interesting splits, and sort them according to the
;; date.
(gnc:get-match-commodity-splits-sorted
@@ -295,11 +296,12 @@
(gnc-commodity-numeric->string
report-currency (gnc-numeric-zero)))
(gnc-numeric-zero))
- (gnc-numeric-div
- (second foreignlist)
- (third foreignlist)
- GNC-DENOM-AUTO
- (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))))))
+ (if (not (zero? (third foreignlist)))
+ (gnc-numeric-div
+ (second foreignlist)
+ (third foreignlist)
+ GNC-DENOM-AUTO
+ (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)) 0)))))
;; Get all the interesting splits, sorted by date.
(gnc:get-match-commodity-splits-sorted
currency-accounts
diff --git a/libgnucash/engine/test/test-extras.scm b/libgnucash/engine/test/test-extras.scm
index a040132..90c3ed5 100644
--- a/libgnucash/engine/test/test-extras.scm
+++ b/libgnucash/engine/test/test-extras.scm
@@ -203,10 +203,11 @@
(begin
(xaccSplitSetMemo split-1 memo)
(xaccSplitSetMemo split-2 memo)))
+ (if (> amount2 0)
(gnc-pricedb-create (xaccAccountGetCommodity debit)
(xaccAccountGetCommodity credit)
(gnc-dmy2time64 DD MM YY)
- (/ amount1 amount2))
+ (/ amount1 amount2)))
(xaccTransCommitEdit txn)
txn))
commit 4e88b8cb6c2c2715522a9fe0d5e636c0286530a5
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Aug 18 16:19:43 2018 -0700
Remove the number-collector.
It is redundant and incorrect since gnc-numeric was replaced with Scheme
rationals in the report code.
diff --git a/gnucash/report/business-reports/receipt.scm b/gnucash/report/business-reports/receipt.scm
index 7aea766..780dbf0 100644
--- a/gnucash/report/business-reports/receipt.scm
+++ b/gnucash/report/business-reports/receipt.scm
@@ -46,7 +46,7 @@
(if (or (not taxable) (eq? taxtable '()))
(display " ")
(let* ((amttot (gnc:make-commodity-collector))
- (pctot (gnc:make-number-collector))
+ (pctot (gnc:make-value-collector))
(entries (gncTaxTableGetEntries taxtable))
(amt? #f) ; becomes #t if any entries are amounts
(pc? #f)) ; becomes #t if any entries are percentages
diff --git a/gnucash/report/business-reports/taxinvoice.scm b/gnucash/report/business-reports/taxinvoice.scm
index 326ce4a..685afdb 100644
--- a/gnucash/report/business-reports/taxinvoice.scm
+++ b/gnucash/report/business-reports/taxinvoice.scm
@@ -53,7 +53,7 @@
(if (or (not taxable) (eq? taxtable '()))
(display " ")
(let* ((amttot (gnc:make-commodity-collector))
- (pctot (gnc:make-number-collector))
+ (pctot (gnc:make-value-collector))
(entries (gncTaxTableGetEntries taxtable))
(amt? #f) ; becomes #t if any entries are amounts
(pc? #f)) ; becomes #t if any entries are percentages
diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index 4238d1a..987f527 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -404,8 +404,8 @@
;; numeric-collectors, where [abc] are numeric-collectors. See the
;; real variable names below.
(define (make-newrate unknown-coll un->known-coll known-pair)
- (let ((a (gnc:make-number-collector))
- (b (gnc:make-number-collector)))
+ (let ((a (gnc:make-value-collector))
+ (b (gnc:make-value-collector)))
(a 'add (unknown-coll 'total #f))
(b 'add
;; round to (at least) 8 significant digits
@@ -448,7 +448,7 @@
;; If this is an Euro currency, create the
;; pair of appropriately exchanged amounts.
(if euro-monetary
- (let ((a (gnc:make-number-collector)))
+ (let ((a (gnc:make-value-collector)))
(a 'add
(gnc:gnc-monetary-amount euro-monetary))
(list report-commodity
@@ -578,8 +578,8 @@
;; entry doesn't exist in comm-list
;; create sub-alist from scratch
(let ((pair (list transaction-comm
- (cons (gnc:make-number-collector)
- (gnc:make-number-collector)))))
+ (cons (gnc:make-value-collector)
+ (gnc:make-value-collector)))))
((caadr pair) 'add value-amount)
((cdadr pair) 'add share-amount)
(set! comm-list (list account-comm (list pair)))
@@ -603,8 +603,8 @@
(begin
(set!
pair (list (car foreignlist)
- (cons (gnc:make-number-collector)
- (gnc:make-number-collector))))
+ (cons (gnc:make-value-collector)
+ (gnc:make-value-collector))))
(set!
comm-list (list (car comm-list)
(cons pair (cadr comm-list))))
@@ -665,8 +665,8 @@
(if (not comm-list)
;; no, create sub-alist from scratch
(let ((pair (list transaction-comm
- (cons (gnc:make-number-collector)
- (gnc:make-number-collector)))))
+ (cons (gnc:make-value-collector)
+ (gnc:make-value-collector)))))
((caadr pair) 'add value-amount)
((cdadr pair) 'add share-amount)
(set! comm-list (list account-comm (list pair)))
@@ -690,8 +690,8 @@
(begin
(set!
pair (list (car foreignlist)
- (cons (gnc:make-number-collector)
- (gnc:make-number-collector))))
+ (cons (gnc:make-value-collector)
+ (gnc:make-value-collector))))
(set!
comm-list (list (car comm-list)
(cons pair (cadr comm-list))))
diff --git a/gnucash/report/report-system/report-utilities.scm b/gnucash/report/report-system/report-utilities.scm
index dbe56c6..3ce1255 100644
--- a/gnucash/report/report-system/report-utilities.scm
+++ b/gnucash/report/report-system/report-utilities.scm
@@ -263,28 +263,6 @@
(define (gnc:value-collector-total collector)
(collector 'total #f))
-
-;; Same as above but with gnc:numeric
-(define (gnc:make-number-collector)
- (let ;;; values
- ((value 0))
- (lambda (action amount) ;;; Dispatch function
- (case action
- ((add) (if (number? amount)
- (set! value (gnc-numeric-add amount value
- GNC-DENOM-AUTO GNC-DENOM-LCD))
- (gnc:warn
- "gnc:Number-collector called with wrong argument: "
- amount)))
- ((total) value)
- (else (gnc:warn "bad gnc:number-collector action: " action))))))
-
-;; Replace all 'action function calls by the normal functions below.
-(define (gnc:number-collector-add collector amount)
- (collector 'add amount))
-(define (gnc:number-collector-total collector)
- (collector 'total #f))
-
;; A commodity collector. This is intended to handle multiple
;; currencies' amounts. The amounts are accumulated via 'add, the
;; result can be fetched via 'format. This used to work with strings
@@ -337,12 +315,12 @@
(gnc-commodity-get-fraction commodity) GNC-RND-ROUND)))
(if (not pair)
(begin
- ;; create a new pair, using the gnc:number-collector
- (set! pair (list commodity (gnc:make-number-collector)))
+ ;; create a new pair, using the gnc:value-collector
+ (set! pair (list commodity (gnc:make-value-collector)))
;; and add it to the alist
(set! commoditylist (cons pair commoditylist))))
;; add the value
- (gnc:number-collector-add (cadr pair) rvalue)))
+ (gnc:value-collector-add (cadr pair) rvalue)))
;; helper function to walk an association list, adding each
;; (commodity -> collector) pair to our list at the appropriate
@@ -351,15 +329,14 @@
(cond ((null? clist) '())
(else (add-commodity-value
(caar clist)
- (gnc:number-collector-total (cadar clist)))
+ (gnc:value-collector-total (cadar clist)))
(add-commodity-clist (cdr clist)))))
(define (minus-commodity-clist clist)
(cond ((null? clist) '())
(else (add-commodity-value
(caar clist)
- (gnc-numeric-neg
- (gnc:number-collector-total (cadar clist))))
+ (- (gnc:value-collector-total (cadar clist))))
(minus-commodity-clist (cdr clist)))))
;; helper function walk the association list doing a callback on
@@ -367,7 +344,7 @@
(define (process-commodity-list fn clist)
(map
(lambda (pair) (fn (car pair)
- (gnc:number-collector-total (cadr pair))))
+ (gnc:value-collector-total (cadr pair))))
clist))
;; helper function which is given a commodity and returns, if
@@ -380,8 +357,8 @@
(gnc-numeric-zero)
(if sign?
(gnc-numeric-neg
- (gnc:number-collector-total (cadr pair)))
- (gnc:number-collector-total (cadr pair))))
+ (gnc:value-collector-total (cadr pair)))
+ (gnc:value-collector-total (cadr pair))))
'()))))
;; helper function which is given a commodity and returns, if
@@ -394,8 +371,8 @@
(gnc-numeric-zero)
(if sign?
(gnc-numeric-neg
- (gnc:number-collector-total (cadr pair)))
- (gnc:number-collector-total (cadr pair)))))))
+ (gnc:value-collector-total (cadr pair)))
+ (gnc:value-collector-total (cadr pair)))))))
;; Dispatch function
(lambda (action commodity amount)
commit a639dd92363438eebbb99a675ca931df91c14696
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Aug 28 18:47:15 2018 +0100
Reduce the number of times the register loads
When a register is created an initial query is run and then the filter
and sort item/reverse order is added and after each item the ledger is
refreshed. By adding a parameter to the three main functions to toggle
the refreshing, with a value of false at register creation, and moving
the gnc_ledger_display_refresh command this can be reduced to 2 from 5.
In the sort/filter dialogue the refresh parameter is TRUE allowing the
changes to be seen immediately.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index cd6d8ca..8ec8752 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -139,8 +139,8 @@ static gchar *gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page);
void gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *filter);
static void gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister *page);
-static void gnc_ppr_update_status_query (GncPluginPageRegister *page);
-static void gnc_ppr_update_date_query (GncPluginPageRegister *page);
+static void gnc_ppr_update_status_query (GncPluginPageRegister *page, gboolean refresh);
+static void gnc_ppr_update_date_query (GncPluginPageRegister *page, gboolean refresh);
/* Command callbacks */
static void gnc_plugin_page_register_cmd_print_check (GtkAction *action, GncPluginPageRegister *plugin_page);
@@ -1155,7 +1155,6 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
reg = gnc_ledger_display_get_split_register(priv->ledger);
gnc_split_register_config(reg, reg->type, reg->style,
reg->use_double_line);
- gnc_ledger_display_refresh(priv->ledger);
gnc_plugin_page_register_ui_initial_state (page);
gnc_plugin_page_register_ui_update (NULL, page);
@@ -1178,7 +1177,7 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
g_free(order);
priv->sd.reverse_order = gnc_plugin_page_register_get_sort_reversed(plugin_page);
- gnc_split_reg_set_sort_reversed(priv->gsr, priv->sd.reverse_order);
+ gnc_split_reg_set_sort_reversed(priv->gsr, priv->sd.reverse_order, FALSE);
if (priv->sd.reverse_order)
priv->sd.save_order = TRUE;
@@ -1261,8 +1260,11 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
}
/* Update Query with Filter Status and Dates */
- gnc_ppr_update_status_query (page);
- gnc_ppr_update_date_query(page);
+ gnc_ppr_update_status_query (page, FALSE);
+ gnc_ppr_update_date_query(page, FALSE);
+
+ /* Now do the refresh */
+ gnc_ledger_display_refresh(priv->ledger);
// Set filter tooltip for summary bar
gnc_plugin_page_register_set_filter_tooltip (page);
@@ -2248,7 +2250,7 @@ gnc_plugin_page_register_sort_response_cb (GtkDialog *dialog,
if (response != GTK_RESPONSE_OK)
{
/* Restore the original sort order */
- gnc_split_reg_set_sort_reversed(priv->gsr, priv->sd.original_reverse_order);
+ gnc_split_reg_set_sort_reversed(priv->gsr, priv->sd.original_reverse_order, TRUE);
priv->sd.reverse_order = priv->sd.original_reverse_order;
gnc_split_reg_set_sort_type(priv->gsr, priv->sd.original_sort_type);
priv->sd.save_order = priv->sd.original_save_order;
@@ -2363,7 +2365,7 @@ gnc_plugin_page_register_sort_order_reverse_cb (GtkToggleButton *button,
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
priv->sd.reverse_order = gtk_toggle_button_get_active(button);
- gnc_split_reg_set_sort_reversed(priv->gsr, priv->sd.reverse_order);
+ gnc_split_reg_set_sort_reversed(priv->gsr, priv->sd.reverse_order, TRUE);
LEAVE(" ");
}
@@ -2384,7 +2386,7 @@ gnc_plugin_page_register_sort_order_reverse_cb (GtkToggleButton *button,
* associated with this filter dialog.
*/
static void
-gnc_ppr_update_status_query (GncPluginPageRegister *page)
+gnc_ppr_update_status_query (GncPluginPageRegister *page, gboolean refresh)
{
GncPluginPageRegisterPrivate *priv;
GSList *param_list;
@@ -2414,7 +2416,8 @@ gnc_ppr_update_status_query (GncPluginPageRegister *page)
// Set filter tooltip for summary bar
gnc_plugin_page_register_set_filter_tooltip (page);
- gnc_ledger_display_refresh (priv->ledger);
+ if (refresh)
+ gnc_ledger_display_refresh (priv->ledger);
LEAVE(" ");
}
@@ -2432,7 +2435,7 @@ gnc_ppr_update_status_query (GncPluginPageRegister *page)
* associated with this filter dialog.
*/
static void
-gnc_ppr_update_date_query (GncPluginPageRegister *page)
+gnc_ppr_update_date_query (GncPluginPageRegister *page, gboolean refresh)
{
GncPluginPageRegisterPrivate *priv;
GSList *param_list;
@@ -2485,7 +2488,8 @@ gnc_ppr_update_date_query (GncPluginPageRegister *page)
// Set filter tooltip for summary bar
gnc_plugin_page_register_set_filter_tooltip (page);
- gnc_ledger_display_refresh (priv->ledger);
+ if (refresh)
+ gnc_ledger_display_refresh (priv->ledger);
LEAVE(" ");
}
@@ -2566,7 +2570,7 @@ gnc_plugin_page_register_filter_status_one_cb (GtkToggleButton *button,
priv->fd.cleared_match |= value;
else
priv->fd.cleared_match &= ~value;
- gnc_ppr_update_status_query(page);
+ gnc_ppr_update_status_query(page, TRUE);
LEAVE(" ");
}
@@ -2605,7 +2609,7 @@ gnc_plugin_page_register_filter_status_all_cb (GtkButton *button,
/* Set the requested status */
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
priv->fd.cleared_match = CLEARED_ALL;
- gnc_ppr_update_status_query(page);
+ gnc_ppr_update_status_query(page, TRUE);
LEAVE(" ");
}
@@ -2713,7 +2717,7 @@ gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton *button,
priv->fd.start_time = 0;
priv->fd.end_time = 0;
}
- gnc_ppr_update_date_query(page);
+ gnc_ppr_update_date_query(page, TRUE);
LEAVE(" ");
}
@@ -2741,7 +2745,7 @@ gnc_plugin_page_register_filter_days_changed_cb (GtkSpinButton *button,
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
priv->fd.days = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button));
- gnc_ppr_update_date_query(page);
+ gnc_ppr_update_date_query(page, TRUE);
LEAVE(" ");
}
@@ -2764,7 +2768,7 @@ gnc_plugin_page_register_filter_gde_changed_cb (GtkWidget *unused,
ENTER("(widget %s(%p), page %p)", gtk_buildable_get_name(GTK_BUILDABLE(unused)), unused, page);
get_filter_times(page);
- gnc_ppr_update_date_query(page);
+ gnc_ppr_update_date_query(page, TRUE);
LEAVE(" ");
}
@@ -2811,7 +2815,7 @@ gnc_plugin_page_register_filter_start_cb (GtkWidget *radio,
active = ( g_strcmp0(name, g_strdup("start_date_choose")) == 0 ? 1 : 0 );
gtk_widget_set_sensitive(priv->fd.start_date, active);
get_filter_times(page);
- gnc_ppr_update_date_query(page);
+ gnc_ppr_update_date_query(page, TRUE);
LEAVE(" ");
}
@@ -2858,7 +2862,7 @@ gnc_plugin_page_register_filter_end_cb (GtkWidget *radio,
active = ( g_strcmp0(name, g_strdup("end_date_choose")) == 0 ? 1 : 0 );
gtk_widget_set_sensitive(priv->fd.end_date, active);
get_filter_times(page);
- gnc_ppr_update_date_query(page);
+ gnc_ppr_update_date_query(page, TRUE);
LEAVE(" ");
}
@@ -2922,12 +2926,12 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog *dialog,
{
/* Remove the old status match */
priv->fd.cleared_match = priv->fd.original_cleared_match;
- gnc_ppr_update_status_query(page);
+ gnc_ppr_update_status_query(page, FALSE);
priv->fd.start_time = priv->fd.original_start_time;
priv->fd.end_time = priv->fd.original_end_time;
priv->fd.days = priv->fd.original_days;
priv->fd.save_filter = priv->fd.original_save_filter;
- gnc_ppr_update_date_query(page);
+ gnc_ppr_update_date_query(page, TRUE);
}
else
{
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index f5ddfb5..a82c603 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -1961,7 +1961,7 @@ gnc_split_reg_sort_notes_cb(GtkWidget *w, gpointer data)
void
-gnc_split_reg_set_sort_reversed(GNCSplitReg *gsr, gboolean rev)
+gnc_split_reg_set_sort_reversed(GNCSplitReg *gsr, gboolean rev, gboolean refresh)
{
/* Note: sort_reversed is the boolean opposite of sort_increasing
* so when rev == true, we're sorting decreasing
@@ -1971,7 +1971,8 @@ gnc_split_reg_set_sort_reversed(GNCSplitReg *gsr, gboolean rev)
Query *query = gnc_ledger_display_get_query( gsr->ledger );
qof_query_set_sort_increasing (query, !rev, !rev, !rev);
gsr->sort_rev = rev;
- gnc_ledger_display_refresh( gsr->ledger );
+ if (refresh)
+ gnc_ledger_display_refresh( gsr->ledger );
}
static void
diff --git a/gnucash/gnome/gnc-split-reg.h b/gnucash/gnome/gnc-split-reg.h
index 16ecae1..09ffc73 100644
--- a/gnucash/gnome/gnc-split-reg.h
+++ b/gnucash/gnome/gnc-split-reg.h
@@ -206,7 +206,7 @@ void gnc_split_reg_set_sort_type_force( GNCSplitReg *gsr, SortType t, gboolean f
/**
* Set/get sort order of register
**/
-void gnc_split_reg_set_sort_reversed(GNCSplitReg *gsr, gboolean rev);
+void gnc_split_reg_set_sort_reversed(GNCSplitReg *gsr, gboolean rev, gboolean refresh);
/**
commit e2801fd937451a32a3af712aee1bffac25823558
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sun Aug 19 22:02:47 2018 +0100
Change the default filter for General Ledger
The General Ledger default for the number of days shown is 30 but for
the Register it is 0, meaning show all. So change the default filter
based on ledger type and use this when determining if the setting should
be saved or removed.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index bc7cda6..cd6d8ca 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -90,6 +90,7 @@
static QofLogModule log_module = GNC_MOD_GUI;
#define DEFAULT_LINES_AMOUNT 50
+#define DEFAULT_FILTER_NUM_DAYS_GL "30"
static void gnc_plugin_page_register_class_init (GncPluginPageRegisterClass *klass);
static void gnc_plugin_page_register_init (GncPluginPageRegister *plugin_page);
@@ -1091,6 +1092,15 @@ gnc_plugin_page_register_ui_initial_state (GncPluginPageRegister *page)
/* Virtual Functions */
+static const gchar *
+get_filter_default_num_of_days (GNCLedgerDisplayType ledger_type)
+{
+ if (ledger_type == LD_GL)
+ return DEFAULT_FILTER_NUM_DAYS_GL;
+ else
+ return "0";
+}
+
static GtkWidget *
gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
{
@@ -1204,7 +1214,11 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
filter_changed = filter_changed + 1;
}
- if (filter[3] && (g_strcmp0 (filter[3], "0") != 0 ))
+ // set the default for the number of days
+ priv->fd.days = (gint)g_ascii_strtoll (
+ get_filter_default_num_of_days (ledger_type), NULL, 10);
+
+ if (filter[3] && (g_strcmp0 (filter[3], get_filter_default_num_of_days (ledger_type)) != 0 ))
{
PINFO("Loaded Filter Days is %s", filter[3]);
@@ -1225,13 +1239,8 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
if (reg->type == GENERAL_JOURNAL)
{
- if ((priv->fd.days == 0) && (priv->fd.start_time == 0) && (priv->fd.end_time == 0))
- priv->fd.days = 30; // default number of days for gl
- else
- {
- start_time = priv->fd.start_time;
- end_time = priv->fd.end_time;
- }
+ start_time = priv->fd.start_time;
+ end_time = priv->fd.end_time;
}
else // search ledger and the like
{
@@ -1824,7 +1833,9 @@ gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page)
if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
filter = xaccAccountGetFilter (leader);
}
- return filter ? g_strdup(filter) : g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
+
+ return filter ? g_strdup(filter) : g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER,
+ "0", "0", get_filter_default_num_of_days (ledger_type));
}
static void
@@ -1860,13 +1871,16 @@ gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *fi
GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay *ld;
Account *leader;
- gchar *default_filter = g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
+ gchar *default_filter;
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
ld = priv->ledger;
ledger_type = gnc_ledger_display_type (ld);
leader = gnc_ledger_display_leader (ld);
+ default_filter = g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER,
+ "0", "0", get_filter_default_num_of_days (ledger_type));
+
// save to gcm file for LD_GL or when feature is set
if (ledger_type == LD_GL ||
gnc_features_check_used (gnc_get_current_book (), GNC_FEATURE_REG_SORT_FILTER))
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 93f3a8ea8274862f776ed836ac99b50ea118a827
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 23 11:49:49 2018 -0700
Fix build of jenny.c on 32-bit builds, mingw-w64.
diff --git a/borrowed/jenny/jenny.c b/borrowed/jenny/jenny.c
index fb8254b..d82b10c 100644
--- a/borrowed/jenny/jenny.c
+++ b/borrowed/jenny/jenny.c
@@ -1019,10 +1019,12 @@ parse( int argc, char *argv[], state *s)
int i, j;
ub4 temp;
char *testfile = (char *)0;
+ /* Finesse differences in size_t between 32 and 64-bit builds. */
+ long feature_length = strlen(feature_name);
/* internal check: we have MAX_FEATURES names for features */
- if (strlen(feature_name) != MAX_FEATURES) {
- printf("feature_name length is wrong, %lu\n", strlen(feature_name));
+ if (feature_length != MAX_FEATURES) {
+ printf("feature_name length is wrong, %lu\n", feature_length);
return FALSE;
}
@@ -1098,7 +1100,7 @@ parse( int argc, char *argv[], state *s)
} /* for (each argument) if '-' */
if (s->n_final > s->ndim) {
- printf("jenny: %hhu-tuples are impossible with only %hu dimensions\n",
+ printf("jenny: %u-tuples are impossible with only %u dimensions\n",
s->n_final, s->ndim);
return FALSE;
}
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 4a3c6f8f8594e1ec12208dfbb6b26d0f415c0a45
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Fri Aug 17 11:11:38 2018 +0100
Change saving to .gcm and Kvp for GNC_FEATURE_REG_SORT_FILTER
For the LD_GL save the filter and sort settings to the .gcm always.
For the rest, keep saving the filter and sort settings to kvp only
when the GNC_FEATURE_REG_SORT_FILTER is not set, if set then save
only to the .gcm file. This will be set on first use in version
4.0 where a conversion will be run to only use the .gcm meta file.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 24a3953..bc7cda6 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -62,6 +62,7 @@
#include "gnc-date-edit.h"
#include "gnc-engine.h"
#include "gnc-event.h"
+#include "gnc-features.h"
#include "gnc-gnome-utils.h"
#include "gnc-gobject-utils.h"
#include "gnc-gui-query.h"
@@ -1771,27 +1772,15 @@ gnc_plugin_page_register_get_tab_color (GncPluginPage *plugin_page)
return g_strdup(color ? color : "Not Set");
}
-static gchar *
-gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page)
+static const gchar *
+gnc_plugin_page_register_get_filter_gcm (Account *leader)
{
- GncPluginPageRegisterPrivate *priv;
- GNCLedgerDisplayType ledger_type;
- GNCLedgerDisplay *ld;
- Account *leader;
- const char* filter = NULL;
-
GKeyFile *state_file = gnc_state_get_current();
gchar *state_section;
gchar *filter_text;
gchar acct_guid[GUID_ENCODING_LENGTH + 1];
GError *error = NULL;
-
- g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), _("unknown"));
-
- priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
- ld = priv->ledger;
- ledger_type = gnc_ledger_display_type (ld);
- leader = gnc_ledger_display_leader (ld);
+ const char* filter = NULL;
// get the filter from the .gcm file
guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
@@ -1799,44 +1788,52 @@ gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page)
filter_text = g_key_file_get_string (state_file, state_section, KEY_PAGE_FILTER, &error);
if (error)
- {
- if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
- filter = xaccAccountGetFilter (leader);
g_clear_error (&error);
- }
else
{
filter_text = g_strdelimit (filter_text, ";", ',');
filter = g_strdup (filter_text);
g_free (filter_text);
}
- return filter ? g_strdup(filter) : g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
+ g_free (state_section);
+ return filter;
}
-void
-gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *filter )
+static gchar *
+gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page)
{
GncPluginPageRegisterPrivate *priv;
+ GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay *ld;
Account *leader;
- gchar *default_filter = g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
+ const char* filter = NULL;
- GKeyFile *state_file = gnc_state_get_current();
- gchar *state_section;
- gchar *filter_text;
- gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+ g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), _("unknown"));
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
ld = priv->ledger;
+ ledger_type = gnc_ledger_display_type (ld);
leader = gnc_ledger_display_leader (ld);
- if (leader != NULL)
+ // load from gcm file for LD_GL or when feature is set
+ if (ledger_type == LD_GL ||
+ gnc_features_check_used (gnc_get_current_book (), GNC_FEATURE_REG_SORT_FILTER))
+ filter = gnc_plugin_page_register_get_filter_gcm (leader);
+ else // load from kvp
{
- if (!filter || (g_strcmp0 (filter, default_filter) == 0))
- xaccAccountSetFilter (leader, NULL);
- else
- xaccAccountSetFilter (leader, filter);
+ if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
+ filter = xaccAccountGetFilter (leader);
}
+ return filter ? g_strdup(filter) : g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
+}
+
+static void
+gnc_plugin_page_register_set_filter_gcm (Account *leader, const gchar *filter, gchar *default_filter)
+{
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar *filter_text;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
// save the filter to the .gcm file also
guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
@@ -1853,31 +1850,50 @@ gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *fi
g_key_file_set_string (state_file, state_section, KEY_PAGE_FILTER, filter_text);
g_free (filter_text);
}
- g_free (default_filter);
- return;
+ g_free (state_section);
}
-static gchar *
-gnc_plugin_page_register_get_sort_order (GncPluginPage *plugin_page)
+void
+gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *filter )
{
GncPluginPageRegisterPrivate *priv;
GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay *ld;
Account *leader;
- const char* sort_order = NULL;
+ gchar *default_filter = g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
+
+ priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
+ ld = priv->ledger;
+ ledger_type = gnc_ledger_display_type (ld);
+ leader = gnc_ledger_display_leader (ld);
+
+ // save to gcm file for LD_GL or when feature is set
+ if (ledger_type == LD_GL ||
+ gnc_features_check_used (gnc_get_current_book (), GNC_FEATURE_REG_SORT_FILTER))
+ gnc_plugin_page_register_set_filter_gcm (leader, filter, default_filter);
+ else // save to kvp
+ {
+ if (leader != NULL)
+ {
+ if (!filter || (g_strcmp0 (filter, default_filter) == 0))
+ xaccAccountSetFilter (leader, NULL);
+ else
+ xaccAccountSetFilter (leader, filter);
+ }
+ }
+ g_free (default_filter);
+ return;
+}
+static const gchar *
+gnc_plugin_page_register_get_sort_order_gcm (Account *leader)
+{
GKeyFile *state_file = gnc_state_get_current();
gchar *state_section;
gchar *sort_text;
gchar acct_guid[GUID_ENCODING_LENGTH + 1];
GError *error = NULL;
-
- g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), _("unknown"));
-
- priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
- ld = priv->ledger;
- ledger_type = gnc_ledger_display_type (ld);
- leader = gnc_ledger_display_leader (ld);
+ const char* sort_order = NULL;
// get the sort_order from the .gcm file
guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
@@ -1885,41 +1901,50 @@ gnc_plugin_page_register_get_sort_order (GncPluginPage *plugin_page)
sort_text = g_key_file_get_string (state_file, state_section, KEY_PAGE_SORT, &error);
if (error)
- {
- if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
- sort_order = xaccAccountGetSortOrder (leader);
g_clear_error (&error);
- }
else
{
sort_order = g_strdup (sort_text);
g_free (sort_text);
}
- return g_strdup(sort_order ? sort_order : DEFAULT_SORT_ORDER);
+ g_free (state_section);
+ return sort_order;
}
-void
-gnc_plugin_page_register_set_sort_order (GncPluginPage *plugin_page, const gchar *sort_order )
+static gchar *
+gnc_plugin_page_register_get_sort_order (GncPluginPage *plugin_page)
{
GncPluginPageRegisterPrivate *priv;
+ GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay *ld;
Account *leader;
+ const char* sort_order = NULL;
- GKeyFile *state_file = gnc_state_get_current();
- gchar *state_section;
- gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+ g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), _("unknown"));
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
ld = priv->ledger;
+ ledger_type = gnc_ledger_display_type (ld);
leader = gnc_ledger_display_leader (ld);
- if (leader != NULL)
+ // load from gcm file for LD_GL or when feature is set
+ if (ledger_type == LD_GL ||
+ gnc_features_check_used (gnc_get_current_book (), GNC_FEATURE_REG_SORT_FILTER))
+ sort_order = gnc_plugin_page_register_get_sort_order_gcm (leader);
+ else // load from kvp
{
- if (!sort_order || (g_strcmp0 (sort_order, DEFAULT_SORT_ORDER) == 0))
- xaccAccountSetSortOrder (leader, NULL);
- else
- xaccAccountSetSortOrder (leader, sort_order);
+ if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
+ sort_order = xaccAccountGetSortOrder (leader);
}
+ return g_strdup(sort_order ? sort_order : DEFAULT_SORT_ORDER);
+}
+
+static void
+gnc_plugin_page_register_set_sort_order_gcm (Account *leader, const gchar *sort_order )
+{
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
// save sort_order to the .gcm file also
guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
@@ -1932,61 +1957,93 @@ gnc_plugin_page_register_set_sort_order (GncPluginPage *plugin_page, const gchar
else
g_key_file_set_string (state_file, state_section, KEY_PAGE_SORT, sort_order);
- return;
+ g_free (state_section);
}
-
-static gboolean
-gnc_plugin_page_register_get_sort_reversed (GncPluginPage *plugin_page)
+void
+gnc_plugin_page_register_set_sort_order (GncPluginPage *plugin_page, const gchar *sort_order )
{
GncPluginPageRegisterPrivate *priv;
GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay *ld;
Account *leader;
- gboolean sort_reversed = FALSE;
-
- GKeyFile *state_file = gnc_state_get_current();
- gchar *state_section;
- gchar acct_guid[GUID_ENCODING_LENGTH + 1];
- GError *error = NULL;
-
- g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), FALSE);
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
ld = priv->ledger;
ledger_type = gnc_ledger_display_type (ld);
leader = gnc_ledger_display_leader (ld);
+ // save to gcm file for LD_GL or when feature is set
+ if (ledger_type == LD_GL ||
+ gnc_features_check_used (gnc_get_current_book (), GNC_FEATURE_REG_SORT_FILTER))
+ gnc_plugin_page_register_set_sort_order_gcm (leader, sort_order);
+ else // save to kvp
+ {
+ if (leader != NULL)
+ {
+ if (!sort_order || (g_strcmp0 (sort_order, DEFAULT_SORT_ORDER) == 0))
+ xaccAccountSetSortOrder (leader, NULL);
+ else
+ xaccAccountSetSortOrder (leader, sort_order);
+ }
+ }
+ return;
+}
+
+static gboolean
+gnc_plugin_page_register_get_sort_reversed_gcm (Account *leader)
+{
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+ GError *error = NULL;
+ gboolean sort_reversed = FALSE;
+
// get the sort_reversed from the .gcm file
guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", acct_guid, NULL);
sort_reversed = g_key_file_get_boolean (state_file, state_section, KEY_PAGE_SORT_REV, &error);
if (error)
- {
- if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
- sort_reversed = xaccAccountGetSortReversed (leader);
g_clear_error (&error);
- }
+
+ g_free (state_section);
return sort_reversed;
}
-void
-gnc_plugin_page_register_set_sort_reversed (GncPluginPage *plugin_page, gboolean reverse_order)
+static gboolean
+gnc_plugin_page_register_get_sort_reversed (GncPluginPage *plugin_page)
{
GncPluginPageRegisterPrivate *priv;
+ GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay *ld;
Account *leader;
+ gboolean sort_reversed = FALSE;
- GKeyFile *state_file = gnc_state_get_current();
- gchar *state_section;
- gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+ g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), FALSE);
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
ld = priv->ledger;
+ ledger_type = gnc_ledger_display_type (ld);
leader = gnc_ledger_display_leader (ld);
- if (leader != NULL)
- xaccAccountSetSortReversed (leader, reverse_order);
+ // load from gcm file for LD_GL or when feature is set
+ if (ledger_type == LD_GL ||
+ gnc_features_check_used (gnc_get_current_book (), GNC_FEATURE_REG_SORT_FILTER))
+ sort_reversed = gnc_plugin_page_register_get_sort_reversed_gcm (leader);
+ else // load from kvp
+ {
+ if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
+ sort_reversed = xaccAccountGetSortReversed (leader);
+ }
+ return sort_reversed;
+}
+
+static void
+gnc_plugin_page_register_set_sort_reversed_gcm (Account *leader, gboolean reverse_order)
+{
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
// save reverse_order to the .gcm file also
guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
@@ -1999,6 +2056,31 @@ gnc_plugin_page_register_set_sort_reversed (GncPluginPage *plugin_page, gboolean
else
g_key_file_set_boolean (state_file, state_section, KEY_PAGE_SORT_REV, reverse_order);
+ g_free (state_section);
+}
+
+void
+gnc_plugin_page_register_set_sort_reversed (GncPluginPage *plugin_page, gboolean reverse_order)
+{
+ GncPluginPageRegisterPrivate *priv;
+ GNCLedgerDisplayType ledger_type;
+ GNCLedgerDisplay *ld;
+ Account *leader;
+
+ priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
+ ld = priv->ledger;
+ ledger_type = gnc_ledger_display_type (ld);
+ leader = gnc_ledger_display_leader (ld);
+
+ // save to gcm file for LD_GL or when feature is set
+ if (ledger_type == LD_GL ||
+ gnc_features_check_used (gnc_get_current_book (), GNC_FEATURE_REG_SORT_FILTER))
+ gnc_plugin_page_register_set_sort_reversed_gcm (leader, reverse_order);
+ else // save to kvp
+ {
+ if (leader != NULL)
+ xaccAccountSetSortReversed (leader, reverse_order);
+ }
return;
}
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)
commit 54a5097c60496d005f497b2315f063734d8bcd9f
Author: Geert Janssens <geert at kobaltwit.be>
Date: Sat Aug 11 18:35:33 2018 +0200
Bug 796777 - CVE-2008-1391: Integer overflow in included strfmon function
We only used strfmon in one source file to generate three fixed format
strings. Instead of updating to a newer strfmon in borrowed I have
chosen to reimplement the string formatters for these strings in C++.
Note this is *not* a full c++ conversion of the full functionality
of assistant-loan. Only the string parsing has been redone.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 42a23b6..b2fcffb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -732,7 +732,6 @@ set (HAVE_PTHREAD_PRIO_INHERIT 1)
set (HAVE_SCANF_LLD 1)
set (HAVE_SETENV 1)
set (HAVE_STPCPY 1)
-set (HAVE_STRFMON 1)
set (HAVE_STRPTIME 1)
set (HAVE_STRUCT_TM_GMTOFF 1)
set (HAVE_TIMEGM 1)
diff --git a/borrowed/libc/CMakeLists.txt b/borrowed/libc/CMakeLists.txt
index c88f8d1..f89cfe1 100644
--- a/borrowed/libc/CMakeLists.txt
+++ b/borrowed/libc/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(libc_SOURCES libc-missing-noop.c setenv.c strfmon.c strptime.c)
-set(libc_HEADERS pow.h setenv.h strfmon.h strptime.h)
+set(libc_SOURCES libc-missing-noop.c setenv.c strptime.c)
+set(libc_HEADERS pow.h setenv.h strptime.h)
-set_dist_list(libc_DIST CMakeLists.txt ${libc_SOURCES} ${libc_HEADERS})
\ No newline at end of file
+set_dist_list(libc_DIST CMakeLists.txt ${libc_SOURCES} ${libc_HEADERS})
diff --git a/borrowed/libc/strfmon.c b/borrowed/libc/strfmon.c
deleted file mode 100644
index d5ce44f..0000000
--- a/borrowed/libc/strfmon.c
+++ /dev/null
@@ -1,619 +0,0 @@
-/*-
- * Copyright (c) 2001 Alexey Zelkin <phantom at FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-
-#include <sys/types.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <locale.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "strfmon.h"
-
-/* internal flags */
-#define NEED_GROUPING 0x01 /* print digits grouped (default) */
-#define SIGN_POSN_USED 0x02 /* '+' or '(' usage flag */
-#define LOCALE_POSN 0x04 /* use locale defined +/- (default) */
-#define PARENTH_POSN 0x08 /* enclose negative amount in () */
-#define SUPRESS_CURR_SYMBOL 0x10 /* suppress the currency from output */
-#define LEFT_JUSTIFY 0x20 /* left justify */
-#define USE_INTL_CURRENCY 0x40 /* use international currency symbol */
-#define IS_NEGATIVE 0x80 /* is argument value negative ? */
-
-/* internal macros */
-#define PRINT(CH) do { \
- if (dst >= s + maxsize) \
- goto e2big_error; \
- *dst++ = CH; \
-} while (0)
-
-#define PRINTS(STR) do { \
- char *tmps = STR; \
- while (*tmps != '\0') \
- PRINT(*tmps++); \
-} while (0)
-
-#define GET_NUMBER(VAR) do { \
- VAR = 0; \
- while (isdigit((unsigned char)*fmt)) { \
- VAR *= 10; \
- VAR += *fmt - '0'; \
- fmt++; \
- } \
-} while (0)
-
-#define GRPCPY(howmany) do { \
- int i = howmany; \
- while (i-- > 0) { \
- avalue_size--; \
- *--bufend = *(avalue+avalue_size+padded); \
- } \
-} while (0)
-
-#define GRPSEP do { \
- *--bufend = thousands_sep; \
- groups++; \
-} while (0)
-
-static void __setup_vars(int, char *, char *, char *, char **);
-static int __calc_left_pad(int, char *);
-static char *__format_grouped_double(double, int *, int, int, int);
-
-ssize_t
-strfmon(char * __restrict s, size_t maxsize, const char * __restrict format,
- ...)
-{
- va_list ap;
- char *dst; /* output destination pointer */
- const char *fmt; /* current format position pointer */
- struct lconv *lc; /* pointer to lconv structure */
- char *asciivalue; /* formatted double pointer */
-
- int flags; /* formatting options */
- int pad_char; /* padding character */
- int pad_size; /* pad size */
- int width; /* field width */
- int left_prec; /* left precision */
- int right_prec; /* right precision */
- double value; /* just value */
- char space_char = ' '; /* space after currency */
-
- char cs_precedes, /* values gathered from struct lconv */
- sep_by_space,
- sign_posn,
- *signstr,
- *currency_symbol;
-
- char *tmpptr; /* temporary vars */
- int sverrno;
-
- va_start(ap, format);
-
- lc = localeconv();
- dst = s;
- fmt = format;
- asciivalue = NULL;
- currency_symbol = NULL;
- pad_size = 0;
-
- while (*fmt) {
- /* pass nonformating characters AS IS */
- if (*fmt != '%')
- goto literal;
-
- /* '%' found ! */
-
- /* "%%" mean just '%' */
- if (*(fmt+1) == '%') {
- fmt++;
- literal:
- PRINT(*fmt++);
- continue;
- }
-
- /* set up initial values */
- flags = (NEED_GROUPING|LOCALE_POSN);
- pad_char = ' '; /* padding character is "space" */
- left_prec = -1; /* no left precision specified */
- right_prec = -1; /* no right precision specified */
- width = -1; /* no width specified */
- value = 0; /* we have no value to print now */
-
- /* Flags */
- while (1) {
- switch (*++fmt) {
- case '=': /* fill character */
- pad_char = *++fmt;
- if (pad_char == '\0')
- goto format_error;
- continue;
- case '^': /* not group currency */
- flags &= ~(NEED_GROUPING);
- continue;
- case '+': /* use locale defined signs */
- if (flags & SIGN_POSN_USED)
- goto format_error;
- flags |= (SIGN_POSN_USED|LOCALE_POSN);
- continue;
- case '(': /* enclose negatives with () */
- if (flags & SIGN_POSN_USED)
- goto format_error;
- flags |= (SIGN_POSN_USED|PARENTH_POSN);
- continue;
- case '!': /* suppress currency symbol */
- flags |= SUPRESS_CURR_SYMBOL;
- continue;
- case '-': /* alignment (left) */
- flags |= LEFT_JUSTIFY;
- continue;
- default:
- break;
- }
- break;
- }
-
- /* field Width */
- if (isdigit((unsigned char)*fmt)) {
- GET_NUMBER(width);
- /* Do we have enough space to put number with
- * required width ?
- */
- if (dst + width >= s + maxsize)
- goto e2big_error;
- }
-
- /* Left precision */
- if (*fmt == '#') {
- if (!isdigit((unsigned char)*++fmt))
- goto format_error;
- GET_NUMBER(left_prec);
- }
-
- /* Right precision */
- if (*fmt == '.') {
- if (!isdigit((unsigned char)*++fmt))
- goto format_error;
- GET_NUMBER(right_prec);
- }
-
- /* Conversion Characters */
- switch (*fmt++) {
- case 'i': /* use international currency format */
- flags |= USE_INTL_CURRENCY;
- break;
- case 'n': /* use national currency format */
- flags &= ~(USE_INTL_CURRENCY);
- break;
- default: /* required character is missing or
- premature EOS */
- goto format_error;
- }
-
- if (flags & USE_INTL_CURRENCY) {
- currency_symbol = strdup(lc->int_curr_symbol);
- if (currency_symbol != NULL)
- space_char = *(currency_symbol+3);
- } else
- currency_symbol = strdup(lc->currency_symbol);
-
- if (currency_symbol == NULL)
- goto end_error; /* ENOMEM. */
-
- /* value itself */
- value = va_arg(ap, double);
-
- /* detect sign */
- if (value < 0) {
- flags |= IS_NEGATIVE;
- value = -value;
- }
-
- /* fill left_prec with amount of padding chars */
- if (left_prec >= 0) {
- pad_size = __calc_left_pad((flags ^ IS_NEGATIVE),
- currency_symbol) -
- __calc_left_pad(flags, currency_symbol);
- if (pad_size < 0)
- pad_size = 0;
- }
-
- asciivalue = __format_grouped_double(value, &flags,
- left_prec, right_prec, pad_char);
- if (asciivalue == NULL)
- goto end_error; /* errno already set */
- /* to ENOMEM by malloc() */
-
- /* set some variables for later use */
- __setup_vars(flags, &cs_precedes, &sep_by_space,
- &sign_posn, &signstr);
-
- /*
- * Description of some LC_MONETARY's values:
- *
- * p_cs_precedes & n_cs_precedes
- *
- * = 1 - $currency_symbol precedes the value
- * for a monetary quantity with a non-negative value
- * = 0 - symbol succeeds the value
- *
- * p_sep_by_space & n_sep_by_space
- *
- * = 0 - no space separates $currency_symbol
- * from the value for a monetary quantity with a
- * non-negative value
- * = 1 - space separates the symbol from the value
- * = 2 - space separates the symbol and the sign string,
- * if adjacent.
- *
- * p_sign_posn & n_sign_posn
- *
- * = 0 - parentheses enclose the quantity and the
- * $currency_symbol
- * = 1 - the sign string precedes the quantity and the
- * $currency_symbol
- * = 2 - the sign string succeeds the quantity and the
- * $currency_symbol
- * = 3 - the sign string precedes the $currency_symbol
- * = 4 - the sign string succeeds the $currency_symbol
- *
- */
-
- tmpptr = dst;
-
- while (pad_size-- > 0)
- PRINT(' ');
-
- if (sign_posn == 0 && (flags & IS_NEGATIVE))
- PRINT('(');
-
- if (cs_precedes == 1) {
- if (sign_posn == 1 || sign_posn == 3) {
- PRINTS(signstr);
- if (sep_by_space == 2) /* XXX: ? */
- PRINT(' ');
- }
-
- if (!(flags & SUPRESS_CURR_SYMBOL)) {
- PRINTS(currency_symbol);
-
- if (sign_posn == 4) {
- if (sep_by_space == 2)
- PRINT(space_char);
- PRINTS(signstr);
- if (sep_by_space == 1)
- PRINT(' ');
- } else if (sep_by_space == 1)
- PRINT(space_char);
- }
- } else if (sign_posn == 1)
- PRINTS(signstr);
-
- PRINTS(asciivalue);
-
- if (cs_precedes == 0) {
- if (sign_posn == 3) {
- if (sep_by_space == 1)
- PRINT(' ');
- PRINTS(signstr);
- }
-
- if (!(flags & SUPRESS_CURR_SYMBOL)) {
- if ((sign_posn == 3 && sep_by_space == 2)
- || (sep_by_space == 1
- && (sign_posn == 0
- || sign_posn == 1
- || sign_posn == 2
- || sign_posn == 4)))
- PRINT(space_char);
- PRINTS(currency_symbol); /* XXX: len */
- if (sign_posn == 4) {
- if (sep_by_space == 2)
- PRINT(' ');
- PRINTS(signstr);
- }
- }
- }
-
- if (sign_posn == 2) {
- if (sep_by_space == 2)
- PRINT(' ');
- PRINTS(signstr);
- }
-
- if (sign_posn == 0 && (flags & IS_NEGATIVE))
- PRINT(')');
-
- if (dst - tmpptr < width) {
- if (flags & LEFT_JUSTIFY) {
- while (dst - tmpptr < width)
- PRINT(' ');
- } else {
- pad_size = dst-tmpptr;
- memmove(tmpptr + width-pad_size, tmpptr,
- pad_size);
- memset(tmpptr, ' ', width-pad_size);
- dst += width-pad_size;
- }
- }
- }
-
- PRINT('\0');
- va_end(ap);
- free(asciivalue);
- free(currency_symbol);
- return (dst - s - 1); /* return size of put data except trailing '\0' */
-
-e2big_error:
- errno = E2BIG;
- goto end_error;
-
-format_error:
- errno = EINVAL;
-
-end_error:
- sverrno = errno;
- if (asciivalue != NULL)
- free(asciivalue);
- if (currency_symbol != NULL)
- free(currency_symbol);
- errno = sverrno;
- va_end(ap);
- return (-1);
-}
-
-static void
-__setup_vars(int flags, char *cs_precedes, char *sep_by_space,
- char *sign_posn, char **signstr) {
-
- struct lconv *lc = localeconv();
-
-#if defined _WIN32 && !defined __cygwin__
- if (flags & IS_NEGATIVE) {
-#else
- if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) {
- *cs_precedes = lc->int_n_cs_precedes;
- *sep_by_space = lc->int_n_sep_by_space;
- *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_n_sign_posn;
- *signstr = (lc->negative_sign == '\0') ? "-"
- : lc->negative_sign;
- } else if (flags & USE_INTL_CURRENCY) {
- *cs_precedes = lc->int_p_cs_precedes;
- *sep_by_space = lc->int_p_sep_by_space;
- *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_p_sign_posn;
- *signstr = lc->positive_sign;
- } else if (flags & IS_NEGATIVE) {
-#endif
- *cs_precedes = lc->n_cs_precedes;
- *sep_by_space = lc->n_sep_by_space;
- *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->n_sign_posn;
- *signstr = (lc->negative_sign == NULL) ? "-"
- : lc->negative_sign;
- } else {
- *cs_precedes = lc->p_cs_precedes;
- *sep_by_space = lc->p_sep_by_space;
- *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->p_sign_posn;
- *signstr = lc->positive_sign;
- }
-
- /* Set default values for unspecified information. */
- if (*cs_precedes != 0)
- *cs_precedes = 1;
- if (*sep_by_space == CHAR_MAX)
- *sep_by_space = 0;
- if (*sign_posn == CHAR_MAX)
- *sign_posn = 0;
-}
-
-static int
-__calc_left_pad(int flags, char *cur_symb) {
-
- char cs_precedes, sep_by_space, sign_posn, *signstr;
- int left_chars = 0;
-
- __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr);
-
- if (cs_precedes != 0) {
- left_chars += strlen(cur_symb);
- if (sep_by_space != 0)
- left_chars++;
- }
-
- switch (sign_posn) {
- case 1:
- left_chars += strlen(signstr);
- break;
- case 3:
- case 4:
- if (cs_precedes != 0)
- left_chars += strlen(signstr);
- }
- return (left_chars);
-}
-
-static int
-get_groups(int size, char *grouping) {
-
- int chars = 0;
-
- if (*grouping == CHAR_MAX || *grouping <= 0) /* no grouping ? */
- return (0);
-
- while (size > (int)*grouping) {
- chars++;
- size -= (int)*grouping++;
- /* no more grouping ? */
- if (*grouping == CHAR_MAX)
- break;
- /* rest grouping with same value ? */
- if (*grouping == 0) {
- chars += (size - 1) / *(grouping - 1);
- break;
- }
- }
- return (chars);
-}
-
-#define BUFFSIZE 255
-
-/* convert double to ASCII */
-static char *
-__format_grouped_double(double value, int *flags,
- int left_prec, int right_prec, int pad_char) {
-
- char *rslt;
- char *avalue;
- int avalue_size;
- char fmt[32];
-
- size_t bufsize;
- char *bufend;
-
- int padded;
-
- struct lconv *lc = localeconv();
- char *grouping;
- char decimal_point;
- char thousands_sep;
-
- int groups = 0;
-
- grouping = lc->mon_grouping;
- decimal_point = *lc->mon_decimal_point;
- if (decimal_point == '\0')
- decimal_point = *lc->decimal_point;
- thousands_sep = *lc->mon_thousands_sep;
- if (thousands_sep == '\0')
- thousands_sep = *lc->thousands_sep;
-
- /* fill left_prec with default value */
- if (left_prec == -1)
- left_prec = 0;
-
- /* fill right_prec with default value */
- if (right_prec == -1) {
- if (*flags & USE_INTL_CURRENCY)
- right_prec = lc->int_frac_digits;
- else
- right_prec = lc->frac_digits;
-
- if (right_prec == CHAR_MAX) /* POSIX locale ? */
- right_prec = 2;
- }
-
- if (*flags & NEED_GROUPING)
- left_prec += get_groups(left_prec, grouping);
-
- /* convert to string */
- snprintf(fmt, sizeof(fmt), "%%%d.%df", left_prec + right_prec + 1,
- right_prec);
- avalue = malloc (BUFFSIZE);
- if (!avalue)
- return (NULL);
- avalue_size = snprintf(avalue, BUFFSIZE, fmt, value);
- if (BUFFSIZE < avalue_size)
- {
- avalue = realloc (avalue, avalue_size + 1);
- if (!avalue)
- return (NULL);
- avalue_size = sprintf(avalue, fmt, value);
- }
- if (avalue_size < 0)
- return (NULL);
-
- /* make sure that we've enough space for result string */
- bufsize = strlen(avalue)*2+1;
- rslt = malloc(bufsize);
- if (rslt == NULL) {
- free(avalue);
- return (NULL);
- }
- memset(rslt, 0, bufsize);
- bufend = rslt + bufsize - 1; /* reserve space for trailing '\0' */
-
- /* skip spaces at beginning */
- padded = 0;
- while (avalue[padded] == ' ') {
- padded++;
- avalue_size--;
- }
-
- if (right_prec > 0) {
- bufend -= right_prec;
- memcpy(bufend, avalue + avalue_size+padded-right_prec,
- right_prec);
- *--bufend = decimal_point;
- avalue_size -= (right_prec + 1);
- }
-
- if ((*flags & NEED_GROUPING) &&
- thousands_sep != '\0' && /* XXX: need investigation */
- *grouping != CHAR_MAX &&
- *grouping > 0) {
- while (avalue_size > (int)*grouping) {
- GRPCPY(*grouping);
- GRPSEP;
- grouping++;
-
- /* no more grouping ? */
- if (*grouping == CHAR_MAX)
- break;
-
- /* rest grouping with same value ? */
- if (*grouping == 0) {
- grouping--;
- while (avalue_size > *grouping) {
- GRPCPY(*grouping);
- GRPSEP;
- }
- }
- }
- if (avalue_size != 0)
- GRPCPY(avalue_size);
- padded -= groups;
-
- } else {
- bufend -= avalue_size;
- memcpy(bufend, avalue+padded, avalue_size);
- if (right_prec == 0)
- padded--; /* decrease assumed $decimal_point */
- }
-
- /* do padding with pad_char */
- if (padded > 0) {
- bufend -= padded;
- memset(bufend, pad_char, padded);
- }
-
- bufsize = bufsize - (bufend - rslt) + 1;
- memmove(rslt, bufend, bufsize);
- free(avalue);
- return (rslt);
-}
diff --git a/borrowed/libc/strfmon.h b/borrowed/libc/strfmon.h
deleted file mode 100644
index 8380450..0000000
--- a/borrowed/libc/strfmon.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*-
- * Copyright (c) 2001 Alexey Zelkin <phantom at FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-#ifndef __STRFMON_H__
-#define __STRFMON_H__
-
-#ifndef HAVE_STRFMON
-/*
- * Version of "strfmon()", for the benefit of OSes that don't have it.
- */
-ssize_t
-strfmon(char * __restrict s, size_t maxsize, const char * __restrict format,
- ...);
-
-#endif
-
-#endif
diff --git a/common/config.h.cmake.in b/common/config.h.cmake.in
index 200b129..7a0cc8a 100644
--- a/common/config.h.cmake.in
+++ b/common/config.h.cmake.in
@@ -219,9 +219,6 @@
/* Define to 1 if you have the `stpcpy' function. */
#cmakedefine HAVE_STPCPY 1
-/* Define to 1 if you have the `strfmon' function. */
-#cmakedefine HAVE_STRFMON 1
-
/* Define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H 1
diff --git a/gnucash/gnome/CMakeLists.txt b/gnucash/gnome/CMakeLists.txt
index 80c165e..3e99c19 100644
--- a/gnucash/gnome/CMakeLists.txt
+++ b/gnucash/gnome/CMakeLists.txt
@@ -123,10 +123,6 @@ set (gnc_gnome_SOURCES
set_source_files_properties (${gnc_gnome_SOURCES} PROPERTIES OBJECT_DEPENDS ${CONFIG_H})
-if (WIN32)
- set (gnc_gnome_SOURCES ${gnc_gnome_SOURCES} ${CMAKE_SOURCE_DIR}/borrowed/libc/strfmon.c)
-endif(WIN32)
-
add_library (gnc-gnome ${gnc_gnome_SOURCES} ${gnc_gnome_noinst_HEADERS} ${SWIG_GNOME_C})
target_link_libraries(gnc-gnome gncmod-gnome-search gncmod-ledger-core gncmod-report-gnome gncmod-report-system
gncmod-register-gnome gncmod-register-core gncmod-gnome-utils gncmod-engine ${GTK3_LDFLAGS} ${GTK_MAC_LDFLAGS})
diff --git a/gnucash/gnome/assistant-loan.cpp b/gnucash/gnome/assistant-loan.cpp
index fbca2a7..00af266 100644
--- a/gnucash/gnome/assistant-loan.cpp
+++ b/gnucash/gnome/assistant-loan.cpp
@@ -47,14 +47,15 @@ extern "C"
#include "gnc-ui-util.h"
#include "gnc-frequency.h"
#include "gnc-engine.h"
-
-#ifndef HAVE_STRFMON
-# include "strfmon.h"
-#else
-# include <monetary.h>
-#endif
}
+#include <boost/locale.hpp>
+#include <string>
+#include <sstream>
+#include <iomanip>
+
+namespace bl = boost::locale;
+
#define DIALOG_LOAN_ASSISTANT_CM_CLASS "assistant-loan-setup"
static QofLogModule log_module = GNC_MOD_ASSISTANT;
@@ -2298,26 +2299,46 @@ gfloat loan_apr_to_simple_formula (gfloat rate, gfloat compounding_periods)
return (simple_rate);
}
-#define MAX_FORMULA 1024
+using boost::locale::conv::utf_to_utf;
+
+// Define a monetary facet template for printing monetary values
+// with a custom precision <prec>
+// This will be used to generate the loan formulas, which use 5 decimal places
+// for the loan percentage and 2 decimal places for all other numbers.
+
+// Note this facet is wchar_t based: some locales have non-ascii thousands
+// separators and these can't be handled by a char based moneypunct facet.
+
+template<int prec>
+struct cust_prec_punct : std::moneypunct_byname<wchar_t, false> {
+ cust_prec_punct(const char* name) : moneypunct_byname(name) {}
+ int do_frac_digits() const { return prec; }
+};
+
+// Convert a double to a string hardcoding <prec> decimal places
+template<int prec>
+std::string to_str_with_prec (const gdouble val)
+{
+ auto loc = std::locale(std::locale(""), new cust_prec_punct<prec>(""));
+ std::wstringstream valstr;
+ valstr.imbue(loc);
+ valstr << std::put_money(val * pow(10, prec));
+ return utf_to_utf<char>(valstr.str());
+}
static
void
-loan_get_formula_internal( LoanAssistantData *ldd, GString *gstr, const gchar* tpl )
+loan_get_formula_internal( LoanAssistantData *ldd, GString *gstr, const gchar *tpl )
{
- gint rate_case;
- gfloat pass_thru_rate, period_rate;
- gfloat periods;
- gfloat principal;
- gchar formula[MAX_FORMULA];
-
g_assert( ldd != NULL );
g_assert( gstr != NULL );
- pass_thru_rate = ldd->ld.interestRate / 100;
- periods = (ldd->ld.numPer * (ldd->ld.perSize == GNC_MONTHS ? 1 : 12)) * 1.;
- principal = gnc_numeric_to_double(ldd->ld.principal);
+ gdouble pass_thru_rate = ldd->ld.interestRate / 100.0;
+ gdouble periods = (ldd->ld.numPer * (ldd->ld.perSize == GNC_MONTHS ? 1 : 12)) * 1.;
+ auto principal = gnc_numeric_to_double(ldd->ld.principal);
- rate_case = ldd->ld.rateType;
+ gdouble period_rate;
+ auto rate_case = ldd->ld.rateType;
switch (rate_case)
{
case GNC_IRATE_SIMPLE:
@@ -2343,17 +2364,29 @@ loan_get_formula_internal( LoanAssistantData *ldd, GString *gstr, const gchar* t
break;
}
- if (0 < strfmon (formula, MAX_FORMULA, tpl,
- period_rate, 12.0, periods, principal ))
- g_string_append (gstr, formula);
+ auto period_rate_str = to_str_with_prec<5> (period_rate);
+ auto period_base_str = to_str_with_prec<2> (12.0);
+ auto periods_str = to_str_with_prec<2> (periods);
+ auto principal_str = to_str_with_prec<2> (principal);
+
+ // Using boost::locale::format here to merge a template
+ // with plain strings. We can't use bl::format directly on the double
+ // values as it will use numeric punctuation instead of monetary punctuation.
+ // This is different in several locales (like nl_BE and ru_RU)
+ // and our parsing function does expect monetary punctuation to work properly.
+ // So instead of bl::format we could also have used boost::format.
+ // However at the time of this writing that sublibrary is not yet a requirement
+ // for gnucash. So I stuck with bl::format, which is.
+ auto formula = (bl::format (tpl) % period_rate_str %
+ period_base_str % periods_str % principal_str).str();
+ g_string_append (gstr, formula.c_str());
}
-
static
void
loan_get_pmt_formula( LoanAssistantData *ldd, GString *gstr )
{
- loan_get_formula_internal (ldd, gstr, "pmt( %!.5i / %!0.2i : %!0.2i : %!0.2i : 0 : 0 )");
+ loan_get_formula_internal (ldd, gstr, "pmt( {1} / {2} : {3} : {4} : 0 : 0 )");
}
@@ -2361,7 +2394,7 @@ static
void
loan_get_ppmt_formula( LoanAssistantData *ldd, GString *gstr )
{
- loan_get_formula_internal (ldd, gstr, "ppmt( %!.5i / %!0.2i : i : %!0.2i : %!0.2i : 0 : 0 )");
+ loan_get_formula_internal (ldd, gstr, "ppmt( {1} / {2} : i : {3} : {4} : 0 : 0 )");
}
@@ -2369,7 +2402,7 @@ static
void
loan_get_ipmt_formula( LoanAssistantData *ldd, GString *gstr )
{
- loan_get_formula_internal (ldd, gstr, "ipmt( %!.5i / %!0.2i : i : %!0.2i : %!0.2i : 0 : 0 )");
+ loan_get_formula_internal (ldd, gstr, "ipmt( {1} / {2} : i : {3} : {4} : 0 : 0 )");
}
/******************* Scheduled Transaction Functions ********************/
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 06f9c4d..9f051b9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -36,7 +36,6 @@ borrowed/gwengui-gtk3/w_vspacer.c
borrowed/jenny/jenny.c
borrowed/libc/libc-missing-noop.c
borrowed/libc/setenv.c
-borrowed/libc/strfmon.c
borrowed/libc/strptime.c
doc/tip_of_the_day.list.c
gnucash/gnome/assistant-acct-period.c
commit 34cb4925a4be639e8d3e211ce2020d2190d5a41d
Author: Geert Janssens <geert at kobaltwit.be>
Date: Sat Aug 11 15:33:19 2018 +0200
Compile assistant-loan as c++
Fix only c++ compatibility issues, which primarily boils down
to dealing with stricter type checking.
diff --git a/gnucash/gnome/CMakeLists.txt b/gnucash/gnome/CMakeLists.txt
index 44bd887..80c165e 100644
--- a/gnucash/gnome/CMakeLists.txt
+++ b/gnucash/gnome/CMakeLists.txt
@@ -64,7 +64,7 @@ gnc_add_swig_guile_command (swig-gnome-c
set (gnc_gnome_SOURCES
assistant-acct-period.c
assistant-hierarchy.c
- assistant-loan.c
+ assistant-loan.cpp
assistant-stock-split.c
business-options-gnome.c
business-urls.c
diff --git a/gnucash/gnome/assistant-loan.c b/gnucash/gnome/assistant-loan.cpp
similarity index 94%
rename from gnucash/gnome/assistant-loan.c
rename to gnucash/gnome/assistant-loan.cpp
index 388af79..fbca2a7 100644
--- a/gnucash/gnome/assistant-loan.c
+++ b/gnucash/gnome/assistant-loan.cpp
@@ -23,6 +23,8 @@
* Boston, MA 02110-1301, USA gnu at gnu.org *
\********************************************************************/
+extern "C"
+{
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
@@ -51,6 +53,8 @@
#else
# include <monetary.h>
#endif
+}
+
#define DIALOG_LOAN_ASSISTANT_CM_CLASS "assistant-loan-setup"
static QofLogModule log_module = GNC_MOD_ASSISTANT;
@@ -102,8 +106,8 @@ typedef struct RepayOptData_
**/
typedef struct RepayOptDataDefault_
{
- char *name;
- char *defaultTxnMemo;
+ const char *name;
+ const char *defaultTxnMemo;
gboolean escrowDefault;
gboolean specSrcAcctDefault;
} RepayOptDataDefault;
@@ -362,10 +366,12 @@ static gint loan_find_ttsplit_with_acct( gconstpointer elt, gconstpointer crit )
static void loan_create_sx_from_tcSX( LoanAssistantData *ldd, toCreateSX *tcSX );
static void loan_tcSX_free( gpointer data, gpointer user_data );
+extern "C" {
void loan_assistant_prepare( GtkAssistant *assistant, GtkWidget *page, gpointer user_data );
void loan_assistant_finish( GtkAssistant *gtkassistant, gpointer user_data );
void loan_assistant_cancel( GtkAssistant *gtkassistant, gpointer user_data );
void loan_assistant_close( GtkAssistant *gtkassistant, gpointer user_data );
+}
/*****************************************************************************/
@@ -374,7 +380,7 @@ static
void
loan_assistant_close_handler( gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
gtk_widget_destroy( ldd->window );
}
@@ -383,7 +389,7 @@ static
void
loan_assistant_window_destroy_cb( GtkWidget *object, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
g_assert( ldd );
@@ -951,7 +957,7 @@ static
void
loan_info_prep( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
gnc_amount_edit_set_amount( ldd->prmOrigPrincGAE, ldd->ld.principal );
gtk_spin_button_set_value( ldd->prmIrateSpin, ldd->ld.interestRate );
@@ -959,9 +965,11 @@ loan_info_prep( GtkAssistant *assistant, gpointer user_data )
gtk_combo_box_set_active( ldd->prmType, ldd->ld.type );
if ( ldd->ld.type != GNC_FIXED )
{
- g_signal_handlers_block_by_func( GNC_FREQUENCY( ldd->prmVarGncFreq), loan_info_page_valid_cb , ldd );
+ g_signal_handlers_block_by_func( GNC_FREQUENCY( ldd->prmVarGncFreq),
+ (gpointer) loan_info_page_valid_cb, ldd );
gnc_frequency_setup_recurrence(ldd->prmVarGncFreq, ldd->ld.loan_schedule, ldd->ld.varStartDate);
- g_signal_handlers_unblock_by_func( GNC_FREQUENCY( ldd->prmVarGncFreq), loan_info_page_valid_cb , ldd );
+ g_signal_handlers_unblock_by_func( GNC_FREQUENCY( ldd->prmVarGncFreq),
+ (gpointer) loan_info_page_valid_cb, ldd );
}
/* start date */
@@ -989,7 +997,7 @@ static
void
loan_info_prm_type_cb( GtkWidget *w, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
gint index;
index = gtk_combo_box_get_active( ldd->prmType );
@@ -1002,7 +1010,7 @@ static
void
loan_info_calc_update_cb( GtkWidget *w, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
GDate start, now;
int i, totalVal, total, remain;
@@ -1034,7 +1042,7 @@ loan_info_calc_update_cb( GtkWidget *w, gpointer user_data )
void
loan_info_page_valid_cb (GtkWidget *widget, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
GtkAssistant *assistant = GTK_ASSISTANT(ldd->window);
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
@@ -1048,7 +1056,7 @@ static
gboolean
loan_info_page_complete( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
ldd->ld.primaryAcct = gnc_account_sel_get_account( ldd->prmAccountGAS );
/* Test for valid Account */
@@ -1063,7 +1071,7 @@ static
void
loan_info_page_save( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
ldd->ld.primaryAcct = gnc_account_sel_get_account( ldd->prmAccountGAS );
@@ -1073,8 +1081,8 @@ loan_info_page_save( GtkAssistant *assistant, gpointer user_data )
}
ldd->ld.principal = gnc_amount_edit_get_amount( ldd->prmOrigPrincGAE );
ldd->ld.interestRate = gtk_spin_button_get_value( ldd->prmIrateSpin );
- ldd->ld.rateType = gtk_combo_box_get_active (ldd->prmIrateType );
- ldd->ld.type = gtk_combo_box_get_active( ldd->prmType );
+ ldd->ld.rateType = static_cast<IRateType>( gtk_combo_box_get_active (ldd->prmIrateType ));
+ ldd->ld.type = static_cast<LoanType>( gtk_combo_box_get_active( ldd->prmType ));
if ( ldd->ld.type != GNC_FIXED )
{
@@ -1095,7 +1103,7 @@ loan_info_page_save( GtkAssistant *assistant, gpointer user_data )
{
g_date_set_dmy( ldd->ld.startDate,
tmpTm->tm_mday,
- (tmpTm->tm_mon + 1),
+ static_cast<GDateMonth>(tmpTm->tm_mon + 1),
(1900 + tmpTm->tm_year) );
gnc_tm_free (tmpTm);
}
@@ -1121,7 +1129,7 @@ loan_opt_prep( GtkAssistant *assistant, gpointer user_data )
{
int i;
RepayOptUIData *rouid;
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
/* Save Previous Page ( Information ) */
loan_info_page_save(assistant, ldd);
@@ -1190,7 +1198,7 @@ loan_opt_escrow_toggle_cb( GtkToggleButton *tb, gpointer user_data )
int i;
gboolean newState;
RepayOptUIData *rouid;
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
GtkAssistant *assistant = GTK_ASSISTANT(ldd->window);
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
@@ -1221,7 +1229,7 @@ loan_opt_escrow_toggle_cb( GtkToggleButton *tb, gpointer user_data )
/* prevent the toggle handler from running and "trashing" the
* state of the throughEscrowP selection */
g_signal_handlers_block_by_func( rouid->escrowCb,
- loan_opt_escrow_toggled_cb,
+ (gpointer) loan_opt_escrow_toggled_cb,
rouid );
gtk_toggle_button_set_active(
GTK_TOGGLE_BUTTON(rouid->escrowCb),
@@ -1233,7 +1241,7 @@ loan_opt_escrow_toggle_cb( GtkToggleButton *tb, gpointer user_data )
newState
&& gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(rouid->optCb) ) );
g_signal_handlers_unblock_by_func( rouid->escrowCb,
- loan_opt_escrow_toggled_cb,
+ (gpointer) loan_opt_escrow_toggled_cb,
rouid );
if ( newState )
{
@@ -1261,7 +1269,7 @@ loan_opt_escrow_toggled_cb( GtkToggleButton *tb, gpointer user_data )
void
loan_opt_page_valid_cb (GtkWidget *widget, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
GtkAssistant *assistant = GTK_ASSISTANT(ldd->window);
gint num = gtk_assistant_get_current_page (assistant);
@@ -1276,7 +1284,7 @@ static
gboolean
loan_opt_page_complete( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(ldd->optEscrowCb) ) )
{
@@ -1299,7 +1307,7 @@ static
void
loan_rep_prep( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
GString *str;
if ( ldd->ld.repAmount )
@@ -1322,9 +1330,11 @@ loan_rep_prep( GtkAssistant *assistant, gpointer user_data )
gnc_account_sel_set_account( ldd->repPrincToGAS, ldd->ld.repPriAcct, FALSE );
gnc_account_sel_set_account( ldd->repIntToGAS, ldd->ld.repIntAcct, FALSE );
- g_signal_handlers_block_by_func( ldd->repGncFreq, loan_rep_page_valid_cb , ldd );
+ g_signal_handlers_block_by_func( ldd->repGncFreq,
+ (gpointer) loan_rep_page_valid_cb, ldd );
gnc_frequency_setup_recurrence(ldd->repGncFreq, ldd->ld.repayment_schedule, ldd->ld.repStartDate);
- g_signal_handlers_unblock_by_func( ldd->repGncFreq, loan_rep_page_valid_cb , ldd );
+ g_signal_handlers_unblock_by_func( ldd->repGncFreq,
+ (gpointer) loan_rep_page_valid_cb, ldd );
/* Find the first enabled option */
{
@@ -1345,7 +1355,7 @@ loan_rep_prep( GtkAssistant *assistant, gpointer user_data )
void
loan_rep_page_valid_cb (GtkWidget *widget, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
GtkAssistant *assistant = GTK_ASSISTANT(ldd->window);
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
@@ -1359,7 +1369,7 @@ static
gboolean
loan_rep_page_complete( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
ldd->ld.repFromAcct =
gnc_account_sel_get_account( ldd->repAssetsFromGAS );
@@ -1387,7 +1397,7 @@ static
void
loan_rep_page_save( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
if ( ldd->ld.repMemo )
g_free( ldd->ld.repMemo );
@@ -1420,7 +1430,7 @@ static
void
loan_pay_prep( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
RepayOptData *rod;
GString *str;
@@ -1457,7 +1467,7 @@ loan_pay_prep( GtkAssistant *assistant, gpointer user_data )
{
g_signal_handlers_block_by_func( ldd->payUseEscrow,
- loan_pay_use_esc_toggle_cb,
+ (gpointer) loan_pay_use_esc_toggle_cb,
ldd );
loan_pay_use_esc_setup( ldd,
@@ -1468,38 +1478,43 @@ loan_pay_prep( GtkAssistant *assistant, gpointer user_data )
&& ldd->ld.escrowAcct != NULL) );
g_signal_handlers_unblock_by_func( ldd->payUseEscrow,
- loan_pay_use_esc_toggle_cb,
+ (gpointer) loan_pay_use_esc_toggle_cb,
ldd );
}
{
g_signal_handlers_block_by_func( ldd->paySpecSrcAcct,
- loan_pay_spec_src_toggle_cb,
+ (gpointer) loan_pay_spec_src_toggle_cb,
ldd );
loan_pay_spec_src_setup( ldd, rod->specSrcAcctP );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(ldd->paySpecSrcAcct),
rod->specSrcAcctP );
g_signal_handlers_unblock_by_func( ldd->paySpecSrcAcct,
- loan_pay_spec_src_toggle_cb,
+ (gpointer) loan_pay_spec_src_toggle_cb,
ldd );
}
- g_signal_handlers_block_by_func(ldd->payAcctToGAS, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_block_by_func(ldd->payAcctToGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
gnc_account_sel_set_account( ldd->payAcctToGAS, rod->to, FALSE );
- g_signal_handlers_unblock_by_func(ldd->payAcctToGAS, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_unblock_by_func(ldd->payAcctToGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
- g_signal_handlers_block_by_func(ldd->payTxnFreqUniqRb, loan_pay_freq_toggle_cb, ldd );
+ g_signal_handlers_block_by_func(ldd->payTxnFreqUniqRb,
+ (gpointer) loan_pay_freq_toggle_cb, ldd );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(ldd->payTxnFreqPartRb), !rod->FreqUniq );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(ldd->payTxnFreqUniqRb), rod->FreqUniq );
- g_signal_handlers_unblock_by_func(ldd->payTxnFreqUniqRb, loan_pay_freq_toggle_cb, ldd );
+ g_signal_handlers_unblock_by_func(ldd->payTxnFreqUniqRb,
+ (gpointer) loan_pay_freq_toggle_cb, ldd );
gtk_widget_set_sensitive( GTK_WIDGET(ldd->payFreqHBox), rod->FreqUniq );
if ( rod->FreqUniq )
{
- g_signal_handlers_disconnect_by_func( ldd->payGncFreq, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_disconnect_by_func( ldd->payGncFreq,
+ (gpointer) loan_pay_page_valid_cb, ldd );
gtk_container_remove( GTK_CONTAINER(ldd->payFreqHBox), GTK_WIDGET(ldd->payGncFreq) );
ldd->payGncFreq = NULL;
ldd->payGncFreq = GNC_FREQUENCY(gnc_frequency_new_from_recurrence( rod->schedule, rod->startDate ));
@@ -1516,7 +1531,7 @@ loan_pay_prep( GtkAssistant *assistant, gpointer user_data )
void
loan_pay_page_valid_cb (GtkWidget *widget, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
GtkAssistant *assistant = GTK_ASSISTANT(ldd->window);
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
@@ -1535,12 +1550,16 @@ loan_pay_use_esc_setup( LoanAssistantData *ldd, gboolean newState )
gtk_widget_set_sensitive( GTK_WIDGET(ldd->payEscFromLabel), newState );
if ( newState )
{
- g_signal_handlers_block_by_func( ldd->payAcctEscToGAS, loan_pay_page_valid_cb, ldd );
- g_signal_handlers_block_by_func( ldd->payAcctEscFromGAS, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_block_by_func( ldd->payAcctEscToGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_block_by_func( ldd->payAcctEscFromGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
gnc_account_sel_set_account( ldd->payAcctEscToGAS, ldd->ld.escrowAcct, FALSE );
gnc_account_sel_set_account( ldd->payAcctEscFromGAS, ldd->ld.escrowAcct, FALSE );
- g_signal_handlers_unblock_by_func( ldd->payAcctEscToGAS, loan_pay_page_valid_cb, ldd );
- g_signal_handlers_unblock_by_func( ldd->payAcctEscFromGAS, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_unblock_by_func( ldd->payAcctEscToGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_unblock_by_func( ldd->payAcctEscFromGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
}
}
@@ -1550,7 +1569,7 @@ void
loan_pay_use_esc_toggle_cb( GtkToggleButton *tb, gpointer user_data )
{
gboolean newState;
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
newState = gtk_toggle_button_get_active( tb );
loan_pay_use_esc_setup( ldd, newState );
@@ -1565,16 +1584,20 @@ loan_pay_spec_src_setup( LoanAssistantData *ldd, gboolean newState )
gtk_widget_set_sensitive( GTK_WIDGET(ldd->payAcctFromGAS), newState );
if ( newState )
{
- g_signal_handlers_block_by_func( ldd->payAcctFromGAS, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_block_by_func( ldd->payAcctFromGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
gnc_account_sel_set_account( ldd->payAcctFromGAS, ldd->ld.repayOpts[ldd->currentIdx]->from, FALSE );
- g_signal_handlers_unblock_by_func( ldd->payAcctFromGAS, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_unblock_by_func( ldd->payAcctFromGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
}
else
{
- g_signal_handlers_block_by_func( ldd->payAcctFromGAS, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_block_by_func( ldd->payAcctFromGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
gnc_account_sel_set_account( ldd->payAcctFromGAS, NULL, FALSE );
ldd->ld.repayOpts[ldd->currentIdx]->from = NULL;
- g_signal_handlers_unblock_by_func( ldd->payAcctFromGAS, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_unblock_by_func( ldd->payAcctFromGAS,
+ (gpointer) loan_pay_page_valid_cb, ldd );
}
}
@@ -1584,7 +1607,7 @@ void
loan_pay_spec_src_toggle_cb( GtkToggleButton *tb, gpointer user_data )
{
gboolean newState;
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
newState = gtk_toggle_button_get_active( tb );
loan_pay_spec_src_setup( ldd, newState );
@@ -1595,7 +1618,7 @@ static
void
loan_pay_freq_toggle_cb( GtkToggleButton *tb, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
RepayOptData *rod;
g_assert( ldd->currentIdx >= 0 );
@@ -1620,9 +1643,11 @@ loan_pay_freq_toggle_cb( GtkToggleButton *tb, gpointer user_data )
rod->startDate = g_date_new();
*rod->startDate = *ldd->ld.startDate;
}
- g_signal_handlers_block_by_func( ldd->payGncFreq, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_block_by_func( ldd->payGncFreq,
+ (gpointer) loan_pay_page_valid_cb, ldd );
gnc_frequency_setup_recurrence(ldd->payGncFreq, rod->schedule, rod->startDate);
- g_signal_handlers_unblock_by_func( ldd->payGncFreq, loan_pay_page_valid_cb, ldd );
+ g_signal_handlers_unblock_by_func( ldd->payGncFreq,
+ (gpointer) loan_pay_page_valid_cb, ldd );
}
else
{
@@ -1644,7 +1669,7 @@ void
loan_pay_next_button_cb( GtkButton *button, gpointer user_data )
{
int i;
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
/* save current data */
if ( loan_pay_complete ( GTK_ASSISTANT(ldd->window), user_data ) != FALSE )
@@ -1668,7 +1693,7 @@ void
loan_pay_back_button_cb( GtkButton *button, gpointer user_data )
{
int i;
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
/* save current data */
if ( loan_pay_complete ( GTK_ASSISTANT(ldd->window), user_data ) != FALSE)
@@ -1691,7 +1716,7 @@ static
gboolean
loan_pay_all_opt_valid ( GtkAssistant *assistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
int i;
gboolean all_valid;
all_valid = FALSE;
@@ -1716,7 +1741,7 @@ gboolean
loan_pay_complete( GtkAssistant *assistant, gpointer user_data )
{
gchar *tmpStr;
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
RepayOptData *rod;
g_assert( ldd->currentIdx >= 0 );
@@ -1783,7 +1808,7 @@ loan_rev_prep( GtkAssistant *assistant, gpointer user_data )
{
/* 3, here, does not include the Date column. */
static const int BASE_COLS = 3;
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
GtkListStore *store;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
@@ -1892,7 +1917,7 @@ static
void
loan_rev_range_opt_changed_cb( GtkComboBox *combo, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
int opt;
opt = gtk_combo_box_get_active( ldd->revRangeOpt );
@@ -1912,7 +1937,7 @@ static
void
loan_rev_range_changed_cb( GNCDateEdit *gde, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
{
GDate start, end;
g_date_clear( &start, 1 );
@@ -2085,7 +2110,7 @@ loan_rev_recalc_schedule( LoanAssistantData *ldd )
/* evaluate the expressions given the correct
* sequence number i */
ival = gnc_numeric_create( i, 1 );
- g_hash_table_insert( ivar, "i", &ival );
+ g_hash_table_insert( ivar, (gpointer) "i", &ival );
if ( ! gnc_exp_parser_parse_separate_vars(
pmtFormula->str, &val, &eloc, ivar ) )
@@ -2207,7 +2232,7 @@ static
void
loan_rev_update_view( LoanAssistantData *ldd, GDate *start, GDate *end )
{
- static gchar *NO_AMT_CELL_TEXT = " ";
+ static const gchar *NO_AMT_CELL_TEXT = " ";
GList *l;
GNCPrintAmountInfo pai;
GtkListStore *store;
@@ -2277,7 +2302,7 @@ gfloat loan_apr_to_simple_formula (gfloat rate, gfloat compounding_periods)
static
void
-loan_get_formula_internal( LoanAssistantData *ldd, GString *gstr, const gchar* template )
+loan_get_formula_internal( LoanAssistantData *ldd, GString *gstr, const gchar* tpl )
{
gint rate_case;
gfloat pass_thru_rate, period_rate;
@@ -2318,7 +2343,7 @@ loan_get_formula_internal( LoanAssistantData *ldd, GString *gstr, const gchar* t
break;
}
- if (0 < strfmon (formula, MAX_FORMULA, template,
+ if (0 < strfmon (formula, MAX_FORMULA, tpl,
period_rate, 12.0, periods, principal ))
g_string_append (gstr, formula);
}
@@ -2944,7 +2969,7 @@ loan_create_sxes( LoanAssistantData *ldd )
void
loan_assistant_finish ( GtkAssistant *gtkassistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
loan_create_sxes( ldd );
}
@@ -2953,7 +2978,7 @@ loan_assistant_finish ( GtkAssistant *gtkassistant, gpointer user_data )
void
loan_assistant_cancel( GtkAssistant *gtkassistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
gnc_close_gui_component_by_data( DIALOG_LOAN_ASSISTANT_CM_CLASS, ldd );
}
@@ -2961,7 +2986,7 @@ loan_assistant_cancel( GtkAssistant *gtkassistant, gpointer user_data )
void
loan_assistant_close( GtkAssistant *gtkassistant, gpointer user_data )
{
- LoanAssistantData *ldd = user_data;
+ LoanAssistantData *ldd = static_cast<LoanAssistantData*> (user_data);
gnc_close_gui_component_by_data( DIALOG_LOAN_ASSISTANT_CM_CLASS, ldd );
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 386ea54..06f9c4d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -41,7 +41,7 @@ borrowed/libc/strptime.c
doc/tip_of_the_day.list.c
gnucash/gnome/assistant-acct-period.c
gnucash/gnome/assistant-hierarchy.c
-gnucash/gnome/assistant-loan.c
+gnucash/gnome/assistant-loan.cpp
gnucash/gnome/assistant-stock-split.c
gnucash/gnome/business-gnome-utils.c
gnucash/gnome/business-options-gnome.c
commit 6ba47846c05805deaa1b79867b69f798523d5573
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sun Aug 5 22:39:18 2018 +0100
Improve the generation of the filter text
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 9abfba1..24a3953 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -2892,23 +2892,32 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog *dialog,
LEAVE(" ");
}
-static gchar*
-gpp_get_cleared_match_filter_text (gchar *text_in, gboolean *first, const gchar *text)
+static void
+gpp_update_match_filter_text (cleared_match_t match, const guint mask,
+ const gchar *filter_name, gchar **show, gchar **hide)
{
- gchar *result;
- gchar *temp = g_strdup (text_in);
- g_free (text_in);
-
- if (*first)
+ if ((match & mask) == mask)
{
- result = g_strconcat (temp, text, NULL);
- *first = FALSE;
+ if (*show == NULL)
+ *show = g_strdup (filter_name);
+ else
+ {
+ gchar *temp = g_strdup (*show);
+ g_free (*show);
+ *show = g_strconcat (temp, ", ", filter_name, NULL);
+ }
}
else
- result = g_strconcat (temp, ", ", text, NULL);
- g_free (temp);
-
- return result;
+ {
+ if (*hide == NULL)
+ *hide = g_strdup (filter_name);
+ else
+ {
+ gchar *temp = g_strdup (*hide);
+ g_free (*hide);
+ *hide = g_strconcat (temp, ", ", filter_name, NULL);
+ }
+ }
}
static void
@@ -2951,44 +2960,22 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister *page)
// filtered match items
if (priv->fd.cleared_match != 31)
{
- gchar *show = g_strdup ("");
- gchar *hide = g_strdup ("");
+ gchar *show = NULL;
+ gchar *hide = NULL;
- gboolean first_show = TRUE, first_hide = TRUE;
+ gpp_update_match_filter_text (priv->fd.cleared_match, 0x01, _("Unreconciled"), &show, &hide);
+ gpp_update_match_filter_text (priv->fd.cleared_match, 0x02, _("Cleared"), &show, &hide);
+ gpp_update_match_filter_text (priv->fd.cleared_match, 0x04, _("Reconciled"), &show, &hide);
+ gpp_update_match_filter_text (priv->fd.cleared_match, 0x08, _("Frozen"), &show, &hide);
+ gpp_update_match_filter_text (priv->fd.cleared_match, 0x10, _("Voided"), &show, &hide);
- if ((priv->fd.cleared_match & 0x01) == 0x01)
- show = gpp_get_cleared_match_filter_text (show, &first_show, _("Unreconciled"));
- else
- hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Unreconciled"));
-
- if ((priv->fd.cleared_match & 0x02) == 0x02)
- show = gpp_get_cleared_match_filter_text (show, &first_show, _("Cleared"));
- else
- hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Cleared"));
-
- if ((priv->fd.cleared_match & 0x04) == 0x04)
- show = gpp_get_cleared_match_filter_text (show, &first_show, _("Reconciled"));
- else
- hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Reconciled"));
-
- if ((priv->fd.cleared_match & 0x08) == 0x08)
- show = gpp_get_cleared_match_filter_text (show, &first_show, _("Frozen"));
- else
- hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Frozen"));
-
- if ((priv->fd.cleared_match & 0x10) == 0x10)
- show = gpp_get_cleared_match_filter_text (show, &first_show, _("Voided"));
- else
- hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Voided"));
-
- if (g_strcmp0 (show, "") == 0)
+ if (show == NULL)
text_cleared = g_strconcat (_("Hide:"), " ", hide, NULL);
else
text_cleared = g_strconcat (_("Show:"), " ", show, "\n", _("Hide:"), " ", hide, NULL);
g_free (show);
g_free (hide);
-
}
// create the tooltip based on created text variables
if ((text_start != NULL) || (text_end != NULL) || (text_cleared != NULL))
commit a650693d07269d82515bc132a334dac9aa96d43c
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 17:06:43 2018 +0100
New feature for register sort/filter settings move.
diff --git a/libgnucash/engine/gnc-features.c b/libgnucash/engine/gnc-features.c
index e56491e..453ecfc 100644
--- a/libgnucash/engine/gnc-features.c
+++ b/libgnucash/engine/gnc-features.c
@@ -48,6 +48,7 @@ static gncFeature known_features[] =
{ GNC_FEATURE_GUID_BAYESIAN, "Use account GUID as key for Bayesian data (requires at least GnuCash 2.6.12)" },
{ GNC_FEATURE_GUID_FLAT_BAYESIAN, "Use account GUID as key for bayesian data and store KVP flat (requires at least Gnucash 2.6.19)" },
{ GNC_FEATURE_SQLITE3_ISO_DATES, "Use ISO formatted date-time strings in SQLite3 databases (requires at least GnuCash 2.6.20)"},
+ { GNC_FEATURE_REG_SORT_FILTER, "Store the register sort and filter settings in .gcm metadata file (requires at least GnuCash 3.3)"},
{ NULL },
};
diff --git a/libgnucash/engine/gnc-features.h b/libgnucash/engine/gnc-features.h
index 0386077..a53be43 100644
--- a/libgnucash/engine/gnc-features.h
+++ b/libgnucash/engine/gnc-features.h
@@ -52,6 +52,7 @@ extern "C" {
#define GNC_FEATURE_GUID_BAYESIAN "Account GUID based Bayesian data"
#define GNC_FEATURE_GUID_FLAT_BAYESIAN "Account GUID based bayesian with flat KVP"
#define GNC_FEATURE_SQLITE3_ISO_DATES "ISO-8601 formatted date strings in SQLite3 databases."
+#define GNC_FEATURE_REG_SORT_FILTER "Register sort and filter settings stored in .gcm file"
/** @} */
commit 9423e0913ba4d2878174cb4049c7d3e70e249321
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 17:05:55 2018 +0100
Remove white space and re-indent gnc-features.c
diff --git a/libgnucash/engine/gnc-features.c b/libgnucash/engine/gnc-features.c
index ca4cb9b..e56491e 100644
--- a/libgnucash/engine/gnc-features.c
+++ b/libgnucash/engine/gnc-features.c
@@ -72,7 +72,7 @@ static void gnc_features_init ()
}
static void gnc_features_test_one(gpointer pkey, gpointer value,
- gpointer data)
+ gpointer data)
{
const gchar *key = (const gchar*)pkey;
const gchar *feature_desc = (const gchar*)value;
@@ -89,7 +89,7 @@ static void gnc_features_test_one(gpointer pkey, gpointer value,
g_assert(feature_desc);
*unknown_features = g_list_prepend(*unknown_features,
- (gpointer)feature_desc);
+ (gpointer)feature_desc);
}
/* Check if the session requires features unknown to this version of GnuCash.
@@ -108,25 +108,25 @@ gchar *gnc_features_test_unknown (QofBook *book)
/* Iterate over the members of this frame for unknown features */
g_hash_table_foreach (features_used, &gnc_features_test_one,
- &features_list);
+ &features_list);
if (features_list)
{
- GList *i;
- char* msg = g_strdup(_("This Dataset contains features not supported "
- "by this version of GnuCash. You must use a "
- "newer version of GnuCash in order to support "
- "the following features:"
- ));
-
- for (i = features_list; i; i = i->next)
- {
- char *tmp = g_strconcat(msg, "\n* ", i->data, NULL);
- g_free (msg);
- msg = tmp;
- }
-
- g_list_free(features_list);
- return msg;
+ GList *i;
+ char* msg = g_strdup(_("This Dataset contains features not supported "
+ "by this version of GnuCash. You must use a "
+ "newer version of GnuCash in order to support "
+ "the following features:"
+ ));
+
+ for (i = features_list; i; i = i->next)
+ {
+ char *tmp = g_strconcat(msg, "\n* ", i->data, NULL);
+ g_free (msg);
+ msg = tmp;
+ }
+
+ g_list_free(features_list);
+ return msg;
}
g_hash_table_unref (features_used);
return NULL;
@@ -159,7 +159,7 @@ struct CheckFeature
};
static void gnc_features_check_feature_cb (gpointer pkey, gpointer value,
- gpointer data)
+ gpointer data)
{
const gchar *key = (const gchar*)pkey;
struct CheckFeature * check_data = data;
commit c6001d855aceae1e1cea4777ba5b8d9036b99ff0
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 15:44:15 2018 +0100
Allow loading the sort and filter settings for the GL
By default the GL loads the last 30 days but this can be changed and
saved depending on requirements.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 80e0ff5..9abfba1 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -1151,7 +1151,6 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
ledger_type = gnc_ledger_display_type (priv->ledger);
- if (ledger_type == LD_SINGLE || ledger_type == LD_SUBACCOUNT)
{
/* Set the sort order for the split register and status of save order button */
priv->sd.save_order = FALSE;
@@ -1218,15 +1217,32 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
priv->fd.original_save_filter = priv->fd.save_filter;
g_strfreev(filter);
}
- else // LD_GL
+
+ if (ledger_type == LD_GL)
{
time64 start_time = 0, end_time = 0;
- if ((priv->fd.days == 0) && (reg->type == GENERAL_JOURNAL))
+ if (reg->type == GENERAL_JOURNAL)
{
- priv->fd.days = 30; // default number of days for gl
- priv->fd.original_days = priv->fd.days;
+ if ((priv->fd.days == 0) && (priv->fd.start_time == 0) && (priv->fd.end_time == 0))
+ priv->fd.days = 30; // default number of days for gl
+ else
+ {
+ start_time = priv->fd.start_time;
+ end_time = priv->fd.end_time;
+ }
}
+ else // search ledger and the like
+ {
+ priv->fd.days = 0;
+ priv->fd.cleared_match = (gint)g_ascii_strtoll (DEFAULT_FILTER, NULL, 16);
+ gnc_split_reg_set_sort_type (priv->gsr, SortTypefromString (DEFAULT_SORT_ORDER));
+ priv->sd.reverse_order = FALSE;
+ priv->fd.save_filter = FALSE;
+ priv->sd.save_order = FALSE;
+ }
+
+ priv->fd.original_days = priv->fd.days;
priv->fd.original_start_time = start_time;
priv->fd.start_time = start_time;
commit ed05b89518af94526542b7daf1b70b7262d376a0
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 15:40:43 2018 +0100
Load the sort and filter settings to the .gcm file.
Load the sort and filter settings first from the .gcm file and if none
are found try the account kvp entries. This is part of a transition to
saving and loading these settings only in the .gcm file.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 0c83d58..80e0ff5 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -1762,7 +1762,13 @@ gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page)
GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay *ld;
Account *leader;
- const char* filter;
+ const char* filter = NULL;
+
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar *filter_text;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+ GError *error = NULL;
g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), _("unknown"));
@@ -1770,11 +1776,24 @@ gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page)
ld = priv->ledger;
ledger_type = gnc_ledger_display_type (ld);
leader = gnc_ledger_display_leader (ld);
- filter = NULL;
- if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
- filter = xaccAccountGetFilter (leader);
+ // get the filter from the .gcm file
+ guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", acct_guid, NULL);
+ filter_text = g_key_file_get_string (state_file, state_section, KEY_PAGE_FILTER, &error);
+ if (error)
+ {
+ if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
+ filter = xaccAccountGetFilter (leader);
+ g_clear_error (&error);
+ }
+ else
+ {
+ filter_text = g_strdelimit (filter_text, ";", ',');
+ filter = g_strdup (filter_text);
+ g_free (filter_text);
+ }
return filter ? g_strdup(filter) : g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
}
@@ -1829,7 +1848,13 @@ gnc_plugin_page_register_get_sort_order (GncPluginPage *plugin_page)
GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay *ld;
Account *leader;
- const char* sort_order;
+ const char* sort_order = NULL;
+
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar *sort_text;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+ GError *error = NULL;
g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), _("unknown"));
@@ -1837,11 +1862,23 @@ gnc_plugin_page_register_get_sort_order (GncPluginPage *plugin_page)
ld = priv->ledger;
ledger_type = gnc_ledger_display_type (ld);
leader = gnc_ledger_display_leader (ld);
- sort_order = NULL;
- if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
- sort_order = xaccAccountGetSortOrder (leader);
+ // get the sort_order from the .gcm file
+ guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", acct_guid, NULL);
+ sort_text = g_key_file_get_string (state_file, state_section, KEY_PAGE_SORT, &error);
+ if (error)
+ {
+ if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
+ sort_order = xaccAccountGetSortOrder (leader);
+ g_clear_error (&error);
+ }
+ else
+ {
+ sort_order = g_strdup (sort_text);
+ g_free (sort_text);
+ }
return g_strdup(sort_order ? sort_order : DEFAULT_SORT_ORDER);
}
@@ -1891,6 +1928,11 @@ gnc_plugin_page_register_get_sort_reversed (GncPluginPage *plugin_page)
Account *leader;
gboolean sort_reversed = FALSE;
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+ GError *error = NULL;
+
g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), FALSE);
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
@@ -1898,9 +1940,17 @@ gnc_plugin_page_register_get_sort_reversed (GncPluginPage *plugin_page)
ledger_type = gnc_ledger_display_type (ld);
leader = gnc_ledger_display_leader (ld);
- if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
- sort_reversed = xaccAccountGetSortReversed (leader);
+ // get the sort_reversed from the .gcm file
+ guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", acct_guid, NULL);
+ sort_reversed = g_key_file_get_boolean (state_file, state_section, KEY_PAGE_SORT_REV, &error);
+ if (error)
+ {
+ if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
+ sort_reversed = xaccAccountGetSortReversed (leader);
+ g_clear_error (&error);
+ }
return sort_reversed;
}
commit 13c5b53931a55b634d001f24675fecbe88a5d4fc
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 15:35:25 2018 +0100
Save the sort and filter settings to the .gcm file
Save the sort and filter settings to the .gcm file as well as the
account kvp. If default entries are saved then the corresponding entry
in the .gcm file will be removed. This is part of a transition to saving
these settings only in the .gcm file.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 536d762..0c83d58 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -67,6 +67,7 @@
#include "gnc-gui-query.h"
#include "gnc-icons.h"
#include "gnc-split-reg.h"
+#include "gnc-state.h"
#include "gnc-prefs.h"
#include "gnc-ui-util.h"
#include "gnc-window.h"
@@ -1365,6 +1366,10 @@ static const gchar *style_names[] =
#define KEY_REGISTER_STYLE "RegisterStyle"
#define KEY_DOUBLE_LINE "DoubleLineMode"
+#define KEY_PAGE_SORT "register_order"
+#define KEY_PAGE_SORT_REV "register_reversed"
+#define KEY_PAGE_FILTER "register_filter"
+
#define LABEL_ACCOUNT "Account"
#define LABEL_SUBACCOUNT "SubAccount"
#define LABEL_GL "GL"
@@ -1779,7 +1784,12 @@ gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *fi
GncPluginPageRegisterPrivate *priv;
GNCLedgerDisplay *ld;
Account *leader;
- gchar *default_filter;
+ gchar *default_filter = g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
+
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar *filter_text;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
ld = priv->ledger;
@@ -1787,16 +1797,28 @@ gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *fi
if (leader != NULL)
{
- default_filter = g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
-
if (!filter || (g_strcmp0 (filter, default_filter) == 0))
xaccAccountSetFilter (leader, NULL);
else
xaccAccountSetFilter (leader, filter);
-
- g_free (default_filter);
}
+ // save the filter to the .gcm file also
+ guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", acct_guid, NULL);
+ if (!filter || (g_strcmp0 (filter, default_filter) == 0))
+ {
+ if (g_key_file_has_key (state_file, state_section, KEY_PAGE_FILTER, NULL))
+ g_key_file_remove_key (state_file, state_section, KEY_PAGE_FILTER, NULL);
+ }
+ else
+ {
+ filter_text = g_strdup (filter);
+ filter_text = g_strdelimit (filter_text, ",", ';'); // make it conform to .gcm file list
+ g_key_file_set_string (state_file, state_section, KEY_PAGE_FILTER, filter_text);
+ g_free (filter_text);
+ }
+ g_free (default_filter);
return;
}
@@ -1830,6 +1852,10 @@ gnc_plugin_page_register_set_sort_order (GncPluginPage *plugin_page, const gchar
GNCLedgerDisplay *ld;
Account *leader;
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
ld = priv->ledger;
leader = gnc_ledger_display_leader (ld);
@@ -1842,6 +1868,17 @@ gnc_plugin_page_register_set_sort_order (GncPluginPage *plugin_page, const gchar
xaccAccountSetSortOrder (leader, sort_order);
}
+ // save sort_order to the .gcm file also
+ guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", acct_guid, NULL);
+ if (!sort_order || (g_strcmp0 (sort_order, DEFAULT_SORT_ORDER) == 0))
+ {
+ if (g_key_file_has_key (state_file, state_section, KEY_PAGE_SORT, NULL))
+ g_key_file_remove_key (state_file, state_section, KEY_PAGE_SORT, NULL);
+ }
+ else
+ g_key_file_set_string (state_file, state_section, KEY_PAGE_SORT, sort_order);
+
return;
}
@@ -1874,6 +1911,10 @@ gnc_plugin_page_register_set_sort_reversed (GncPluginPage *plugin_page, gboolean
GNCLedgerDisplay *ld;
Account *leader;
+ GKeyFile *state_file = gnc_state_get_current();
+ gchar *state_section;
+ gchar acct_guid[GUID_ENCODING_LENGTH + 1];
+
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
ld = priv->ledger;
leader = gnc_ledger_display_leader (ld);
@@ -1881,6 +1922,17 @@ gnc_plugin_page_register_set_sort_reversed (GncPluginPage *plugin_page, gboolean
if (leader != NULL)
xaccAccountSetSortReversed (leader, reverse_order);
+ // save reverse_order to the .gcm file also
+ guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", acct_guid, NULL);
+ if (!reverse_order)
+ {
+ if (g_key_file_has_key (state_file, state_section, KEY_PAGE_SORT_REV, NULL))
+ g_key_file_remove_key (state_file, state_section, KEY_PAGE_SORT_REV, NULL);
+ }
+ else
+ g_key_file_set_boolean (state_file, state_section, KEY_PAGE_SORT_REV, reverse_order);
+
return;
}
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index da5ba2c..f5ddfb5 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -60,8 +60,6 @@
// static QofLogModule log_module = GNC_MOD_SX;
static QofLogModule log_module = GNC_MOD_GUI;
-#define STATE_SECTION_REG_PREFIX "Register"
-
/***** PROTOTYPES ***************************************************/
void gnc_split_reg_raise( GNCSplitReg *gsr );
diff --git a/gnucash/gnome/gnc-split-reg.h b/gnucash/gnome/gnc-split-reg.h
index 6dd048e..16ecae1 100644
--- a/gnucash/gnome/gnc-split-reg.h
+++ b/gnucash/gnome/gnc-split-reg.h
@@ -36,6 +36,8 @@
#define GNC_SPLIT_REG_CLASS(klass) G_TYPE_CHECK_CLASS_CAST( klass, gnc_split_reg_get_type(), GNCSplitRegClass )
#define IS_GNC_SPLIT_REG(obj) G_TYPE_CHECK_INSTANCE_TYPE( obj, gnc_split_reg_get_type() )
+#define STATE_SECTION_REG_PREFIX "Register"
+
typedef struct _GNCSplitReg GNCSplitReg;
typedef struct _GNCSplitRegClass GNCSplitRegClass;
commit 72a29a83af4915920a7a2f486346696b2e7fb4e8
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 15:24:07 2018 +0100
Fix the save option on sort/filter dialog
When unticking the save option on the sort and filter dialog the actual
save items are not cleared so check for this and clear the saved items.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 676bccb..536d762 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -2041,6 +2041,12 @@ gnc_plugin_page_register_sort_response_cb (GtkDialog *dialog,
}
else
{
+ // clear the sort when unticking the save option
+ if ((priv->sd.save_order == FALSE) && (priv->sd.original_save_order == TRUE))
+ {
+ gnc_plugin_page_register_set_sort_order (plugin_page, DEFAULT_SORT_ORDER);
+ gnc_plugin_page_register_set_sort_reversed (plugin_page, FALSE);
+ }
priv->sd.original_save_order = priv->sd.save_order;
if (priv->sd.save_order)
@@ -2711,6 +2717,10 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog *dialog,
}
else
{
+ // clear the filter when unticking the save option
+ if ((priv->fd.save_filter == FALSE) && (priv->fd.original_save_filter == TRUE))
+ gnc_plugin_page_register_set_filter (plugin_page, NULL);
+
priv->fd.original_save_filter = priv->fd.save_filter;
if (priv->fd.save_filter)
commit 8a0ee0e38f1e569e8ae8d5e1f3b409356e6aca23
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 10:33:01 2018 +0100
Hide the filter/sort save button when appropiate
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 40969ff..676bccb 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -3446,6 +3446,33 @@ gnc_plugin_page_register_cmd_reverse_transaction (GtkAction *action,
LEAVE(" ");
}
+static gboolean
+gnc_plugin_page_register_show_fs_save (GncPluginPageRegister *page)
+{
+ GncPluginPageRegisterPrivate *priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
+ GNCLedgerDisplayType ledger_type = gnc_ledger_display_type (priv->ledger);
+ SplitRegister *reg = gnc_ledger_display_get_split_register (priv->ledger);
+
+ if (ledger_type == LD_SINGLE || ledger_type == LD_SUBACCOUNT)
+ return TRUE;
+ else
+ {
+ switch (reg->type)
+ {
+ case GENERAL_JOURNAL:
+ return TRUE;
+ break;
+
+ case INCOME_LEDGER:
+ case PORTFOLIO_LEDGER:
+ case SEARCH_LEDGER:
+ default:
+ return FALSE;
+ break;
+ }
+ }
+}
+
static void
gnc_plugin_page_register_cmd_view_sort_by (GtkAction *action,
GncPluginPageRegister *page)
@@ -3495,6 +3522,10 @@ gnc_plugin_page_register_cmd_view_sort_by (GtkAction *action,
if (priv->sd.save_order == TRUE)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
+ // hide the save button if appropiate
+ gtk_widget_set_visible (GTK_WIDGET(button),
+ gnc_plugin_page_register_show_fs_save (page));
+
/* Set the button for the current reverse_order order */
button = GTK_WIDGET(gtk_builder_get_object (builder, "sort_reverse"));
if(priv->sd.reverse_order == TRUE)
@@ -3576,6 +3607,10 @@ gnc_plugin_page_register_cmd_view_filter_by (GtkAction *action,
if (priv->fd.save_filter == TRUE)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
+ // hide the save button if appropiate
+ gtk_widget_set_visible (GTK_WIDGET(button),
+ gnc_plugin_page_register_show_fs_save (page));
+
/* Set up number of days */
priv->fd.num_days = GTK_WIDGET(gtk_builder_get_object (builder, "filter_show_num_days"));
button = GTK_WIDGET(gtk_builder_get_object (builder, "filter_show_days"));
@@ -3694,7 +3729,7 @@ gnc_plugin_page_register_cmd_view_filter_by (GtkAction *action,
gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, page);
/* Show it */
- gtk_widget_show_all(dialog);
+ gtk_widget_show(dialog);
g_object_unref(G_OBJECT(builder));
LEAVE(" ");
}
commit e281b50b2963dfe2243bff1a1383ec9f14310bc4
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 08:13:58 2018 +0100
Add new filter option to register
Add new option to the register filter so that it will display the last
number of days based on current day. This is stored as an extra element
on the end of account filter setting.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 85d3ebd..40969ff 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -128,6 +128,7 @@ void gnc_plugin_page_register_filter_response_cb(GtkDialog *dialog, gint respons
void gnc_plugin_page_register_filter_status_all_cb(GtkButton *button, GncPluginPageRegister *plugin_page);
void gnc_plugin_page_register_filter_status_one_cb(GtkToggleButton *button, GncPluginPageRegister *page);
void gnc_plugin_page_register_filter_save_cb(GtkToggleButton *button, GncPluginPageRegister *page);
+void gnc_plugin_page_register_filter_days_changed_cb (GtkSpinButton *button, GncPluginPageRegister *page);
static time64 gnc_plugin_page_register_filter_dmy2time (char *date_string);
static gchar *gnc_plugin_page_register_filter_time2dmy (time64 raw_time);
@@ -567,12 +568,15 @@ typedef struct GncPluginPageRegisterPrivate
GtkWidget *end_date_choose;
GtkWidget *end_date_today;
GtkWidget *end_date;
+ GtkWidget *num_days;
cleared_match_t original_cleared_match;
cleared_match_t cleared_match;
time64 original_start_time;
time64 original_end_time;
time64 start_time;
time64 end_time;
+ gint days;
+ gint original_days;
gboolean original_save_filter;
gboolean save_filter;
} fd;
@@ -798,6 +802,7 @@ gnc_plugin_page_register_init (GncPluginPageRegister *plugin_page)
priv->lines_default = DEFAULT_LINES_AMOUNT;
priv->read_only = FALSE;
priv->fd.cleared_match = CLEARED_ALL;
+ priv->fd.days = 0;
}
static void
@@ -1198,28 +1203,40 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
filter_changed = filter_changed + 1;
}
+ if (filter[3] && (g_strcmp0 (filter[3], "0") != 0 ))
+ {
+ PINFO("Loaded Filter Days is %s", filter[3]);
+
+ priv->fd.days = (gint)g_ascii_strtoll(filter[3], NULL, 10);
+ filter_changed = filter_changed + 1;
+ }
+
if (filter_changed != 0)
priv->fd.save_filter = TRUE;
priv->fd.original_save_filter = priv->fd.save_filter;
g_strfreev(filter);
-
- /* Update Query with Filter Status and Dates */
- gnc_ppr_update_status_query (page);
- gnc_ppr_update_date_query(page);
}
else // LD_GL
{
- time64 start_time, end_time;
- Query *query = gnc_ledger_display_get_query (priv->ledger);
+ time64 start_time = 0, end_time = 0;
+
+ if ((priv->fd.days == 0) && (reg->type == GENERAL_JOURNAL))
+ {
+ priv->fd.days = 30; // default number of days for gl
+ priv->fd.original_days = priv->fd.days;
+ }
- xaccQueryGetDateMatchTT(query, &start_time, &end_time);
priv->fd.original_start_time = start_time;
priv->fd.start_time = start_time;
priv->fd.original_end_time = end_time;
priv->fd.end_time = end_time;
}
+ /* Update Query with Filter Status and Dates */
+ gnc_ppr_update_status_query (page);
+ gnc_ppr_update_date_query(page);
+
// Set filter tooltip for summary bar
gnc_plugin_page_register_set_filter_tooltip (page);
@@ -1753,7 +1770,7 @@ gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page)
if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT))
filter = xaccAccountGetFilter (leader);
- return filter ? g_strdup(filter) : g_strdup_printf("%s,%s,%s", DEFAULT_FILTER, "0", "0");
+ return filter ? g_strdup(filter) : g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
}
void
@@ -1770,7 +1787,7 @@ gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *fi
if (leader != NULL)
{
- default_filter = g_strdup_printf("%s,%s,%s", DEFAULT_FILTER, "0", "0");
+ default_filter = g_strdup_printf("%s,%s,%s,%s", DEFAULT_FILTER, "0", "0", "0");
if (!filter || (g_strcmp0 (filter, default_filter) == 0))
xaccAccountSetFilter (leader, NULL);
@@ -2233,6 +2250,18 @@ gnc_ppr_update_date_query (GncPluginPageRegister *page)
QOF_QUERY_AND);
}
+ if (priv->fd.days > 0)
+ {
+ time64 start;
+ struct tm tm;
+
+ gnc_tm_get_today_start(&tm);
+
+ tm.tm_mday = tm.tm_mday - priv->fd.days;
+ start = gnc_mktime (&tm);
+ xaccQueryAddDateMatchTT (query, TRUE, start, FALSE, 0, QOF_QUERY_AND);
+ }
+
// Set filter tooltip for summary bar
gnc_plugin_page_register_set_filter_tooltip (page);
@@ -2417,15 +2446,11 @@ get_filter_times(GncPluginPageRegister *page)
}
-/** This function is called when the "select range" radio button
- * changes state. Since there are only two choices in this radio
- * group, this one signal can be used to handle all cases. This
- * function is responsible for setting the sensitivity of the table
- * of widgets underneath the "select range" choice, and updating the
- * time limitation on the register query. This is handled by a
- * helper function when the radio button is selected (as potentially
- * all the widgets in the table need to be inspected), and is trivial
- * for the other case.
+/** This function is called when the radio buttons changes state. This
+ * function is responsible for setting the sensitivity of the widgets
+ * controlled by each radio button choice and updating the time
+ * limitation on the register query. This is handled by a helper
+ * function as potentialy all widgets will need to be examined.
*
* @param button A pointer to the "select range" radio button.
*
@@ -2438,20 +2463,33 @@ gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton *button,
{
GncPluginPageRegisterPrivate *priv;
gboolean active;
+ const gchar *name;
g_return_if_fail(GTK_IS_RADIO_BUTTON(button));
g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(page));
ENTER("(button %p, page %p)", button, page);
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
+ name = gtk_buildable_get_name(GTK_BUILDABLE(button));
active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
- gtk_widget_set_sensitive(priv->fd.table, active);
- if (active)
+
+ if (active && g_strcmp0(name, "filter_show_range") == 0)
{
+ gtk_widget_set_sensitive(priv->fd.table, active);
+ gtk_widget_set_sensitive(priv->fd.num_days, !active);
get_filter_times(page);
}
+ else if (active && g_strcmp0(name, "filter_show_days") == 0)
+ {
+ gtk_widget_set_sensitive(priv->fd.table, !active);
+ gtk_widget_set_sensitive(priv->fd.num_days, active);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->fd.num_days), priv->fd.days);
+ }
else
{
+ gtk_widget_set_sensitive(priv->fd.table, FALSE);
+ gtk_widget_set_sensitive(priv->fd.num_days, FALSE);
+ priv->fd.days = 0;
priv->fd.start_time = 0;
priv->fd.end_time = 0;
}
@@ -2460,6 +2498,34 @@ gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton *button,
}
+/** This function is called when the "number of days" spin button is
+ * changed which is then saved and updates the time limitation on
+ * the register query. This is handled by a helper function as
+ * potentialy all widgets will need to be examined.
+ *
+ * @param button A pointer to the "number of days" spin button.
+ *
+ * @param page A pointer to the GncPluginPageRegister that is
+ * associated with this filter dialog.
+ */
+void
+gnc_plugin_page_register_filter_days_changed_cb (GtkSpinButton *button,
+ GncPluginPageRegister *page)
+{
+ GncPluginPageRegisterPrivate *priv;
+
+ g_return_if_fail(GTK_IS_SPIN_BUTTON(button));
+ g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(page));
+
+ ENTER("(button %p, page %p)", button, page);
+ priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
+
+ priv->fd.days = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button));
+ gnc_ppr_update_date_query(page);
+ LEAVE(" ");
+}
+
+
/** This function is called when one of the start date entry widgets
* is updated. It simply calls common routines to determine the
* start/end times and update the register query.
@@ -2639,6 +2705,7 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog *dialog,
gnc_ppr_update_status_query(page);
priv->fd.start_time = priv->fd.original_start_time;
priv->fd.end_time = priv->fd.original_end_time;
+ priv->fd.days = priv->fd.original_days;
priv->fd.save_filter = priv->fd.original_save_filter;
gnc_ppr_update_date_query(page);
}
@@ -2676,6 +2743,16 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog *dialog,
filter = g_strconcat (tmp, ",0", NULL);
g_free (tmp);
+ tmp = g_strdup (filter);
+ g_free (filter);
+
+ // number of days
+ if (priv->fd.days > 0)
+ filter = g_strdup_printf ("%s,%d", tmp, priv->fd.days);
+ else
+ filter = g_strconcat (tmp, ",0", NULL);
+
+ g_free (tmp);
PINFO("The filter to save is %s", filter);
gnc_plugin_page_register_set_filter (plugin_page, filter);
@@ -2730,6 +2807,11 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister *page)
text_start = g_strdup_printf ("%s %s", _("Start Date:"), sdate);
g_free (sdate);
}
+
+ // filtered number of days
+ if (priv->fd.days > 0)
+ text_start = g_strdup_printf ("%s %d", _("Show previous number of days:"), priv->fd.days);
+
// filtered end time
if (priv->fd.end_time != 0)
{
@@ -2737,6 +2819,7 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister *page)
text_end = g_strdup_printf ("%s %s", _("End Date:"), edate);
g_free (edate);
}
+
// filtered match items
if (priv->fd.cleared_match != 31)
{
@@ -3466,6 +3549,7 @@ gnc_plugin_page_register_cmd_view_filter_by (GtkAction *action,
/* Create the dialog */
builder = gtk_builder_new();
+ gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "days_adjustment");
gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "filter_by_dialog");
dialog = GTK_WIDGET(gtk_builder_get_object (builder, "filter_by_dialog"));
priv->fd.dialog = dialog;
@@ -3492,16 +3576,40 @@ gnc_plugin_page_register_cmd_view_filter_by (GtkAction *action,
if (priv->fd.save_filter == TRUE)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
+ /* Set up number of days */
+ priv->fd.num_days = GTK_WIDGET(gtk_builder_get_object (builder, "filter_show_num_days"));
+ button = GTK_WIDGET(gtk_builder_get_object (builder, "filter_show_days"));
- /* Set the date info */
- button = GTK_WIDGET(gtk_builder_get_object (builder, "filter_show_range"));
query = gnc_ledger_display_get_query (priv->ledger);
- xaccQueryGetDateMatchTT(query, &start_time, &end_time);
+
+ if (priv->fd.days > 0) // using number of days
+ {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(priv->fd.num_days), TRUE);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->fd.num_days), priv->fd.days);
+ priv->fd.original_days = priv->fd.days;
+
+ /* Set the start_time and end_time to 0 */
+ start_time = 0;
+ end_time = 0;
+ }
+ else
+ {
+ gtk_widget_set_sensitive(GTK_WIDGET(priv->fd.num_days), FALSE);
+ priv->fd.original_days = 0;
+ priv->fd.days = 0;
+
+ /* Get the start and end times */
+ xaccQueryGetDateMatchTT(query, &start_time, &end_time);
+ }
+
+ /* Set the date info */
priv->fd.original_start_time = start_time;
priv->fd.start_time = start_time;
priv->fd.original_end_time = end_time;
priv->fd.end_time = end_time;
+ button = GTK_WIDGET(gtk_builder_get_object (builder, "filter_show_range"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), start_time || end_time);
table = GTK_WIDGET(gtk_builder_get_object (builder, "select_range_table"));
priv->fd.table = table;
diff --git a/gnucash/gtkbuilder/gnc-plugin-page-register.glade b/gnucash/gtkbuilder/gnc-plugin-page-register.glade
index 20bf4e0..ba509bd 100644
--- a/gnucash/gtkbuilder/gnc-plugin-page-register.glade
+++ b/gnucash/gtkbuilder/gnc-plugin-page-register.glade
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
+<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.10"/>
+ <object class="GtkAdjustment" id="days_adjustment">
+ <property name="upper">1100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
<object class="GtkDialog" id="filter_by_dialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
@@ -87,19 +92,53 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="label847680">
+ <object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <child>
+ <object class="GtkRadioButton" id="filter_show_days">
+ <property name="label" translatable="yes">Show _number of days</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">filter_show_all</property>
+ <signal name="toggled" handler="gnc_plugin_page_register_filter_select_range_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="filter_show_num_days">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="tooltip_text" translatable="yes">Valid range is 0 to 1100 days
+If 0, all previous days included</property>
+ <property name="adjustment">days_adjustment</property>
+ <property name="numeric">True</property>
+ <signal name="value-changed" handler="gnc_plugin_page_register_filter_days_changed_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">False</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="filter_show_range">
- <property name="label" translatable="yes">Select Range:</property>
+ <property name="label" translatable="yes">Select _Range:</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -123,6 +162,7 @@
<child>
<object class="GtkLabel" id="label847682">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="label" translatable="yes" comments="Filter By Dialog, Date Tab, Start section">Start:</property>
</object>
<packing>
@@ -209,6 +249,7 @@
<child>
<object class="GtkLabel" id="label847684">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="label" translatable="yes" comments="Filter By Dialog, Date Tab, End section">End:</property>
</object>
<packing>
@@ -510,6 +551,9 @@
<action-widget response="-6">cancelbutton4</action-widget>
<action-widget response="-5">okbutton4</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
<object class="GtkAdjustment" id="num_adjustment">
<property name="upper">1000000000</property>
@@ -864,6 +908,9 @@
<action-widget response="-6">cancelbutton2</action-widget>
<action-widget response="-5">okbutton2</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
<object class="GtkAdjustment" id="tnum_adjustment">
<property name="upper">1000000000</property>
@@ -1053,6 +1100,9 @@
<action-widget response="-6">button76</action-widget>
<action-widget response="-5">button77</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
<object class="GtkDialog" id="void_transaction_dialog">
<property name="can_focus">False</property>
@@ -1158,5 +1208,8 @@
<action-widget response="-6">cancelbutton1</action-widget>
<action-widget response="-5">okbutton1</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
</interface>
commit 97a566ae280f664b4172375a331cd7859f78395c
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 06:13:35 2018 +0100
Creating filter was leaking while being put together
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index b779651..85d3ebd 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -2648,29 +2648,36 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog *dialog,
if (priv->fd.save_filter)
{
- gchar* filter;
- filter = g_strdup_printf("0x%04x", priv->fd.cleared_match);
+ gchar* filter = g_strdup_printf("0x%04x", priv->fd.cleared_match); // cleared match
+ gchar *tmp = g_strdup (filter);
+ // start time
if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->fd.start_date_choose)) && priv->fd.start_time != 0 )
{
gchar *timeval = gnc_plugin_page_register_filter_time2dmy(priv->fd.start_time);
- filter = g_strconcat ( filter, ",", timeval, NULL);
+ filter = g_strconcat (tmp, ",", timeval, NULL);
g_free (timeval);
}
else
- filter = g_strconcat ( filter, ",0", NULL);
+ filter = g_strconcat (tmp, ",0", NULL);
+ g_free (tmp);
+ tmp = g_strdup (filter);
+ g_free (filter);
+
+ // end time
if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->fd.end_date_choose)) && priv->fd.end_time != 0 )
{
gchar *timeval = gnc_plugin_page_register_filter_time2dmy(priv->fd.end_time);
- filter = g_strconcat ( filter, ",", timeval, NULL);
+ filter = g_strconcat (tmp, ",", timeval, NULL);
g_free (timeval);
}
else
- filter = g_strconcat ( filter, ",0", NULL);
+ filter = g_strconcat (tmp, ",0", NULL);
- PINFO("The filter to save is %s", filter);
+ g_free (tmp);
+ PINFO("The filter to save is %s", filter);
gnc_plugin_page_register_set_filter (plugin_page, filter);
g_free (filter);
}
commit 6eac7e1ed0b5cfc8e42fb1afd846e387f6aec680
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Jun 19 05:26:11 2018 +0100
There is no reason why you can not just have an end date
Change the logic so the date checks are not nested.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index fc1f903..b779651 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -1187,15 +1187,15 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
priv->fd.start_time = gnc_plugin_page_register_filter_dmy2time (filter[1] );
priv->fd.start_time = gnc_time64_get_day_start(priv->fd.start_time);
filter_changed = filter_changed + 1;
+ }
- if (filter[2] && (g_strcmp0 (filter[2], "0") != 0 ))
- {
- PINFO("Loaded Filter End Date is %s", filter[2]);
+ if (filter[2] && (g_strcmp0 (filter[2], "0") != 0 ))
+ {
+ PINFO("Loaded Filter End Date is %s", filter[2]);
- priv->fd.end_time = gnc_plugin_page_register_filter_dmy2time (filter[2] );
- priv->fd.end_time = gnc_time64_get_day_end(priv->fd.end_time);
- filter_changed = filter_changed + 1;
- }
+ priv->fd.end_time = gnc_plugin_page_register_filter_dmy2time (filter[2] );
+ priv->fd.end_time = gnc_time64_get_day_end(priv->fd.end_time);
+ filter_changed = filter_changed + 1;
}
if (filter_changed != 0)
commit 632c7c724ea4f4137d265e4e034fbec85920aecc
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Mon Jun 18 18:07:46 2018 +0100
Update the filter when General Journal created.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 04c5ab4..fc1f903 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -1208,6 +1208,17 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
gnc_ppr_update_status_query (page);
gnc_ppr_update_date_query(page);
}
+ else // LD_GL
+ {
+ time64 start_time, end_time;
+ Query *query = gnc_ledger_display_get_query (priv->ledger);
+
+ xaccQueryGetDateMatchTT(query, &start_time, &end_time);
+ priv->fd.original_start_time = start_time;
+ priv->fd.start_time = start_time;
+ priv->fd.original_end_time = end_time;
+ priv->fd.end_time = end_time;
+ }
// Set filter tooltip for summary bar
gnc_plugin_page_register_set_filter_tooltip (page);
commit d74ec9aa6cc794d34a6d7082a8948463d896034c
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Mon Jun 18 18:06:13 2018 +0100
Only show update the summary bar left labels when present
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index ad8a6d4..da5ba2c 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -540,21 +540,24 @@ gsr_redraw_all_cb (GnucashRegister *g_reg, gpointer data)
print_info = gnc_account_print_info( leader, TRUE );
reverse = gnc_reverse_balance( leader );
- gsr_update_summary_label( gsr->balance_label,
- xaccAccountGetPresentBalance,
- leader, print_info, commodity, reverse, euro );
- gsr_update_summary_label( gsr->cleared_label,
- xaccAccountGetClearedBalance,
- leader, print_info, commodity, reverse, euro );
- gsr_update_summary_label( gsr->reconciled_label,
- xaccAccountGetReconciledBalance,
- leader, print_info, commodity, reverse, euro );
- gsr_update_summary_label( gsr->future_label,
- xaccAccountGetBalance,
- leader, print_info, commodity, reverse, euro );
- gsr_update_summary_label( gsr->projectedminimum_label,
- xaccAccountGetProjectedMinimumBalance,
- leader, print_info, commodity, reverse, euro );
+ if (gsr->balance_label != NULL) // only test the first as they are a group
+ {
+ gsr_update_summary_label( gsr->balance_label,
+ xaccAccountGetPresentBalance,
+ leader, print_info, commodity, reverse, euro );
+ gsr_update_summary_label( gsr->cleared_label,
+ xaccAccountGetClearedBalance,
+ leader, print_info, commodity, reverse, euro );
+ gsr_update_summary_label( gsr->reconciled_label,
+ xaccAccountGetReconciledBalance,
+ leader, print_info, commodity, reverse, euro );
+ gsr_update_summary_label( gsr->future_label,
+ xaccAccountGetBalance,
+ leader, print_info, commodity, reverse, euro );
+ gsr_update_summary_label( gsr->projectedminimum_label,
+ xaccAccountGetProjectedMinimumBalance,
+ leader, print_info, commodity, reverse, euro );
+ }
// Sort label
if (gsr->sort_label != NULL)
commit 3f9a8977c176eb43131e34de9f83505fb20eb727
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Mon Jun 18 18:05:30 2018 +0100
Add the summary bar to the GL and subaccount registers
Add the summary bar to the General Journal and sub account register but
only show sort and filter labels.
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index 6e20748..ad8a6d4 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -2139,7 +2139,9 @@ gsr_summarybar_set_arrow_draw (GNCSplitReg *gsr)
GtkWidget *
gsr_create_summary_bar( GNCSplitReg *gsr )
{
- GtkWidget *summarybar;
+ GtkWidget *summarybar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
+ gtk_box_set_homogeneous (GTK_BOX (summarybar), FALSE);
+ gtk_widget_set_name (summarybar, "gnc-id-summarybar");
gsr->cleared_label = NULL;
gsr->balance_label = NULL;
@@ -2152,28 +2154,21 @@ gsr_create_summary_bar( GNCSplitReg *gsr )
gsr->shares_label = NULL;
gsr->value_label = NULL;
- if ( gnc_ledger_display_type(gsr->ledger) >= LD_SUBACCOUNT )
- {
- gsr->summarybar = NULL;
- return NULL;
- }
-
- summarybar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
- gtk_box_set_homogeneous (GTK_BOX (summarybar), FALSE);
- gtk_widget_set_name (summarybar, "gnc-id-summarybar");
-
- if (!xaccAccountIsPriced(gnc_ledger_display_leader(gsr->ledger)))
+ if (gnc_ledger_display_type(gsr->ledger) == LD_SINGLE)
{
- gsr->balance_label = add_summary_label (summarybar, TRUE, _("Present:"), NULL);
- gsr->future_label = add_summary_label (summarybar, TRUE, _("Future:"), NULL);
- gsr->cleared_label = add_summary_label (summarybar, TRUE, _("Cleared:"), NULL);
- gsr->reconciled_label = add_summary_label (summarybar, TRUE, _("Reconciled:"), NULL);
- gsr->projectedminimum_label = add_summary_label (summarybar, TRUE, _("Projected Minimum:"), NULL);
- }
- else
- {
- gsr->shares_label = add_summary_label (summarybar, TRUE, _("Shares:"), NULL);
- gsr->value_label = add_summary_label (summarybar, TRUE, _("Current Value:"), NULL);
+ if (!xaccAccountIsPriced(gnc_ledger_display_leader(gsr->ledger)))
+ {
+ gsr->balance_label = add_summary_label (summarybar, TRUE, _("Present:"), NULL);
+ gsr->future_label = add_summary_label (summarybar, TRUE, _("Future:"), NULL);
+ gsr->cleared_label = add_summary_label (summarybar, TRUE, _("Cleared:"), NULL);
+ gsr->reconciled_label = add_summary_label (summarybar, TRUE, _("Reconciled:"), NULL);
+ gsr->projectedminimum_label = add_summary_label (summarybar, TRUE, _("Projected Minimum:"), NULL);
+ }
+ else
+ {
+ gsr->shares_label = add_summary_label (summarybar, TRUE, _("Shares:"), NULL);
+ gsr->value_label = add_summary_label (summarybar, TRUE, _("Current Value:"), NULL);
+ }
}
gsr->filter_label = add_summary_label (summarybar, FALSE, "", NULL);
commit b50c8a57fa539bd50e61739511e28f60e8a09dfc
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Mon Jun 18 17:37:32 2018 +0100
Show whether there is a filter on the right of the summary bar
On the right of the summary bar indicate whether there is a filter and
if there is display a tooltip with the settings. Also the filter label
can be altered by the css class "gnc-class-highlight".
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index d3e7283..04c5ab4 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -133,6 +133,7 @@ static time64 gnc_plugin_page_register_filter_dmy2time (char *date_string);
static gchar *gnc_plugin_page_register_filter_time2dmy (time64 raw_time);
static gchar *gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page);
void gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *filter);
+static void gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister *page);
static void gnc_ppr_update_status_query (GncPluginPageRegister *page);
static void gnc_ppr_update_date_query (GncPluginPageRegister *page);
@@ -1208,6 +1209,9 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
gnc_ppr_update_date_query(page);
}
+ // Set filter tooltip for summary bar
+ gnc_plugin_page_register_set_filter_tooltip (page);
+
plugin_page->summarybar = gsr_create_summary_bar(priv->gsr);
if (plugin_page->summarybar)
{
@@ -2159,6 +2163,9 @@ gnc_ppr_update_status_query (GncPluginPageRegister *page)
if (priv->fd.cleared_match != CLEARED_ALL)
xaccQueryAddClearedMatch(query, priv->fd.cleared_match, QOF_QUERY_AND);
+ // Set filter tooltip for summary bar
+ gnc_plugin_page_register_set_filter_tooltip (page);
+
gnc_ledger_display_refresh (priv->ledger);
LEAVE(" ");
}
@@ -2215,6 +2222,9 @@ gnc_ppr_update_date_query (GncPluginPageRegister *page)
QOF_QUERY_AND);
}
+ // Set filter tooltip for summary bar
+ gnc_plugin_page_register_set_filter_tooltip (page);
+
gnc_ledger_display_refresh (priv->ledger);
LEAVE(" ");
}
@@ -2659,6 +2669,148 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog *dialog,
LEAVE(" ");
}
+static gchar*
+gpp_get_cleared_match_filter_text (gchar *text_in, gboolean *first, const gchar *text)
+{
+ gchar *result;
+ gchar *temp = g_strdup (text_in);
+ g_free (text_in);
+
+ if (*first)
+ {
+ result = g_strconcat (temp, text, NULL);
+ *first = FALSE;
+ }
+ else
+ result = g_strconcat (temp, ", ", text, NULL);
+ g_free (temp);
+
+ return result;
+}
+
+static void
+gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister *page)
+{
+ GncPluginPageRegisterPrivate *priv;
+ GncPluginPage *plugin_page;
+ gchar *text = NULL;
+ gchar *text_header = g_strdup_printf ("%s", _("Filter By:"));
+ gchar *text_start = NULL;
+ gchar *text_end = NULL;
+ gchar *text_cleared = NULL;
+
+ g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(page));
+
+ ENTER(" ");
+ priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
+ plugin_page = GNC_PLUGIN_PAGE(page);
+
+ // filtered start time
+ if (priv->fd.start_time != 0)
+ {
+ gchar *sdate = qof_print_date (priv->fd.start_time);
+ text_start = g_strdup_printf ("%s %s", _("Start Date:"), sdate);
+ g_free (sdate);
+ }
+ // filtered end time
+ if (priv->fd.end_time != 0)
+ {
+ gchar *edate = qof_print_date (priv->fd.end_time);
+ text_end = g_strdup_printf ("%s %s", _("End Date:"), edate);
+ g_free (edate);
+ }
+ // filtered match items
+ if (priv->fd.cleared_match != 31)
+ {
+ gchar *show = g_strdup ("");
+ gchar *hide = g_strdup ("");
+
+ gboolean first_show = TRUE, first_hide = TRUE;
+
+ if ((priv->fd.cleared_match & 0x01) == 0x01)
+ show = gpp_get_cleared_match_filter_text (show, &first_show, _("Unreconciled"));
+ else
+ hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Unreconciled"));
+
+ if ((priv->fd.cleared_match & 0x02) == 0x02)
+ show = gpp_get_cleared_match_filter_text (show, &first_show, _("Cleared"));
+ else
+ hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Cleared"));
+
+ if ((priv->fd.cleared_match & 0x04) == 0x04)
+ show = gpp_get_cleared_match_filter_text (show, &first_show, _("Reconciled"));
+ else
+ hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Reconciled"));
+
+ if ((priv->fd.cleared_match & 0x08) == 0x08)
+ show = gpp_get_cleared_match_filter_text (show, &first_show, _("Frozen"));
+ else
+ hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Frozen"));
+
+ if ((priv->fd.cleared_match & 0x10) == 0x10)
+ show = gpp_get_cleared_match_filter_text (show, &first_show, _("Voided"));
+ else
+ hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Voided"));
+
+ if (g_strcmp0 (show, "") == 0)
+ text_cleared = g_strconcat (_("Hide:"), " ", hide, NULL);
+ else
+ text_cleared = g_strconcat (_("Show:"), " ", show, "\n", _("Hide:"), " ", hide, NULL);
+
+ g_free (show);
+ g_free (hide);
+
+ }
+ // create the tooltip based on created text variables
+ if ((text_start != NULL) || (text_end != NULL) || (text_cleared != NULL))
+ {
+ if (text_start != NULL)
+ text = g_strconcat (text_header, "\n", text_start, NULL);
+
+ if (text_end != NULL)
+ {
+ if (text == NULL)
+ text = g_strconcat (text_header, "\n", text_end, NULL);
+ else
+ {
+ gchar *temp = g_strdup (text);
+ g_free (text);
+ text = g_strconcat (temp, "\n", text_end, NULL);
+ g_free (temp);
+ }
+ }
+
+ if (text_cleared != NULL)
+ {
+ if (text == NULL)
+ text = g_strconcat (text_header, "\n", text_cleared, NULL);
+ else
+ {
+ gchar *temp = g_strdup (text);
+ g_free (text);
+ text = g_strconcat (temp, "\n", text_cleared, NULL);
+ g_free (temp);
+ }
+ }
+ }
+ // free the existing text if present
+ if (priv->gsr->filter_text != NULL)
+ g_free (priv->gsr->filter_text);
+
+ // set the tooltip text variable in the gsr
+ priv->gsr->filter_text = g_strdup (text);
+
+ if (text_start)
+ g_free (text_start);
+ if (text_end)
+ g_free (text_end);
+ if (text_cleared)
+ g_free (text_cleared);
+ g_free (text_header);
+ g_free (text);
+
+ LEAVE(" ");
+}
/************************************************************/
/* Report Helper Functions */
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index 4f87827..6e20748 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -351,6 +351,7 @@ gnc_split_reg_init( GNCSplitReg *gsr )
gsr->sort_type = BY_STANDARD;
gsr->sort_rev = FALSE;
gsr->sort_arrow_handler_id = 0;
+ gsr->filter_text = NULL;
gsr->width = -1;
gsr->height = -1;
gsr->numRows = 10;
@@ -447,6 +448,10 @@ gsr_setup_status_widgets( GNCSplitReg *gsr )
void
gnc_split_reg_destroy_cb(GtkWidget *widget, gpointer data)
{
+ GNCSplitReg *gsr = data;
+
+ if (gsr->filter_text)
+ g_free (gsr->filter_text);
}
/**
@@ -615,6 +620,26 @@ gsr_redraw_all_cb (GnucashRegister *g_reg, gpointer data)
gtk_label_set_text (GTK_LABEL(gsr->sort_label), text);
}
+ // Filter label
+ if (gsr->filter_label != NULL)
+ {
+ gchar *old_tt_text = gtk_widget_get_tooltip_text (GTK_WIDGET(gsr->filter_label));
+
+ // check for a change in text
+ if (g_strcmp0 (old_tt_text, gsr->filter_text) != 0)
+ {
+ if (gsr->filter_text != NULL)
+ gtk_label_set_text (GTK_LABEL(gsr->filter_label), _("Filtered"));
+ else
+ gtk_label_set_text (GTK_LABEL(gsr->filter_label), "");
+
+ gtk_widget_set_tooltip_text (GTK_WIDGET(gsr->filter_label), gsr->filter_text);
+
+ if (old_tt_text)
+ g_free (old_tt_text);
+ }
+ }
+
if (gsr->shares_label == NULL && gsr->value_label == NULL)
return;
amount = xaccAccountGetBalance( leader );
@@ -2092,7 +2117,7 @@ add_summary_label (GtkWidget *summarybar, gboolean pack_start, const char *label
label = gtk_label_new( "" );
gnc_label_set_alignment(label, 1.0, 0.5 );
gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, FALSE, 0 );
-
+
if (extra != NULL)
gtk_box_pack_start( GTK_BOX(hbox), extra, FALSE, FALSE, 0 );
@@ -2123,6 +2148,7 @@ gsr_create_summary_bar( GNCSplitReg *gsr )
gsr->projectedminimum_label = NULL;
gsr->sort_label = NULL;
gsr->sort_arrow = NULL;
+ gsr->filter_label = NULL;
gsr->shares_label = NULL;
gsr->value_label = NULL;
@@ -2150,8 +2176,11 @@ gsr_create_summary_bar( GNCSplitReg *gsr )
gsr->value_label = add_summary_label (summarybar, TRUE, _("Current Value:"), NULL);
}
+ gsr->filter_label = add_summary_label (summarybar, FALSE, "", NULL);
gsr->sort_arrow = gtk_image_new_from_icon_name ("image-missing", GTK_ICON_SIZE_SMALL_TOOLBAR);
gsr->sort_label = add_summary_label (summarybar, FALSE, _("Sort By: "), gsr->sort_arrow);
+
+ gnc_widget_set_style_context (GTK_WIDGET(gsr->filter_label), "gnc-class-highlight");
gnc_widget_set_style_context (GTK_WIDGET(gsr->sort_arrow), "gnc-class-highlight");
gsr->summarybar = summarybar;
diff --git a/gnucash/gnome/gnc-split-reg.h b/gnucash/gnome/gnc-split-reg.h
index a8e2d26..6dd048e 100644
--- a/gnucash/gnome/gnc-split-reg.h
+++ b/gnucash/gnome/gnc-split-reg.h
@@ -76,6 +76,7 @@ struct _GNCSplitReg
GtkWidget *value_label;
GtkWidget *sort_label;
GtkWidget *sort_arrow;
+ GtkWidget *filter_label;
/** The current ledger display. **/
GNCLedgerDisplay *ledger;
@@ -87,6 +88,7 @@ struct _GNCSplitReg
guint sort_type;
gboolean sort_rev;
gulong sort_arrow_handler_id;
+ gchar *filter_text;
gboolean read_only;
};
commit b4db066d84f3ec665928bf6e7c984e1d8dba1505
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Mon Jun 18 13:11:37 2018 +0100
Add the sort order to the right of the summary bar
Add the sort order to the right of the summary bar with a tooltip that
shows whether ascending or descending and an arrow. When arrow can
also be emphasized with css by using the class "gnc-class-highlight".
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index b7829e6..4f87827 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -66,7 +66,9 @@ static QofLogModule log_module = GNC_MOD_GUI;
void gnc_split_reg_raise( GNCSplitReg *gsr );
static GtkWidget* add_summary_label( GtkWidget *summarybar, gboolean pack_start,
- const char *label_str );
+ const char *label_str, GtkWidget *extra );
+
+static void gsr_summarybar_set_arrow_draw (GNCSplitReg *gsr);
static void gnc_split_reg_determine_read_only( GNCSplitReg *gsr );
@@ -347,6 +349,8 @@ gnc_split_reg_init( GNCSplitReg *gsr )
gtk_orientable_set_orientation (GTK_ORIENTABLE(gsr), GTK_ORIENTATION_VERTICAL);
gsr->sort_type = BY_STANDARD;
+ gsr->sort_rev = FALSE;
+ gsr->sort_arrow_handler_id = 0;
gsr->width = -1;
gsr->height = -1;
gsr->numRows = 10;
@@ -546,6 +550,71 @@ gsr_redraw_all_cb (GnucashRegister *g_reg, gpointer data)
gsr_update_summary_label( gsr->projectedminimum_label,
xaccAccountGetProjectedMinimumBalance,
leader, print_info, commodity, reverse, euro );
+
+ // Sort label
+ if (gsr->sort_label != NULL)
+ {
+ gchar *old_tt_text = gtk_widget_get_tooltip_text (GTK_WIDGET(gsr->sort_label));
+ gchar *new_tt_text;
+ gchar *text = NULL;
+
+ switch (gsr->sort_type)
+ {
+ case (0):
+ text = _("None");
+ break;
+ case (1):
+ text = _("Standard Order");
+ break;
+ case (2):
+ text = _("Date");
+ break;
+ case (3):
+ text = _("Date of Entry");
+ break;
+ case (4):
+ text = _("Statement Date");
+ break;
+ case (5):
+ text = _("Number");
+ break;
+ case (6):
+ text = _("Amount");
+ break;
+ case (7):
+ text = _("Memo");
+ break;
+ case (8):
+ text = _("Description");
+ break;
+ case (9):
+ text = _("Action");
+ break;
+ case (10):
+ text = _("Notes");
+ break;
+ }
+
+ if (gsr->sort_rev)
+ gtk_widget_set_tooltip_text (GTK_WIDGET(gsr->sort_label), _("Descending"));
+ else
+ gtk_widget_set_tooltip_text (GTK_WIDGET(gsr->sort_label), _("Ascending"));
+
+ new_tt_text = gtk_widget_get_tooltip_text (GTK_WIDGET(gsr->sort_label));
+
+ // does the arrow need changing
+ if (g_strcmp0 (old_tt_text, new_tt_text) != 0)
+ gsr_summarybar_set_arrow_draw (gsr);
+
+ if (old_tt_text)
+ g_free (old_tt_text);
+
+ if (new_tt_text)
+ g_free (new_tt_text);
+
+ gtk_label_set_text (GTK_LABEL(gsr->sort_label), text);
+ }
+
if (gsr->shares_label == NULL && gsr->value_label == NULL)
return;
amount = xaccAccountGetBalance( leader );
@@ -1868,14 +1937,15 @@ gnc_split_reg_sort_notes_cb(GtkWidget *w, gpointer data)
void
gnc_split_reg_set_sort_reversed(GNCSplitReg *gsr, gboolean rev)
{
- /* Note: sort_reversed is the boolean opposite of sort_increasing
- * so when rev == true, we're sorting decreasing
- * In other words, qof_query_set_sort_increasing should
- * always use the inverse of rev.
- */
- Query *query = gnc_ledger_display_get_query( gsr->ledger );
- qof_query_set_sort_increasing (query, !rev, !rev, !rev);
- gnc_ledger_display_refresh( gsr->ledger );
+ /* Note: sort_reversed is the boolean opposite of sort_increasing
+ * so when rev == true, we're sorting decreasing
+ * In other words, qof_query_set_sort_increasing should
+ * always use the inverse of rev.
+ */
+ Query *query = gnc_ledger_display_get_query( gsr->ledger );
+ qof_query_set_sort_increasing (query, !rev, !rev, !rev);
+ gsr->sort_rev = rev;
+ gnc_ledger_display_refresh( gsr->ledger );
}
static void
@@ -2003,7 +2073,7 @@ gnc_split_reg_size_allocate (GtkWidget *widget,
static
GtkWidget*
-add_summary_label (GtkWidget *summarybar, gboolean pack_start, const char *label_str)
+add_summary_label (GtkWidget *summarybar, gboolean pack_start, const char *label_str, GtkWidget *extra)
{
GtkWidget *hbox;
GtkWidget *label;
@@ -2022,10 +2092,25 @@ add_summary_label (GtkWidget *summarybar, gboolean pack_start, const char *label
label = gtk_label_new( "" );
gnc_label_set_alignment(label, 1.0, 0.5 );
gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, FALSE, 0 );
+
+ if (extra != NULL)
+ gtk_box_pack_start( GTK_BOX(hbox), extra, FALSE, FALSE, 0 );
return label;
}
+static void
+gsr_summarybar_set_arrow_draw (GNCSplitReg *gsr)
+{
+ if (gsr->sort_arrow_handler_id > 0)
+ g_signal_handler_disconnect (G_OBJECT(gsr->sort_arrow), gsr->sort_arrow_handler_id);
+
+ gsr->sort_arrow_handler_id = g_signal_connect (G_OBJECT (gsr->sort_arrow), "draw",
+ G_CALLBACK (gnc_draw_arrow_cb), GINT_TO_POINTER(gsr->sort_rev));
+
+ gtk_widget_queue_draw (gsr->sort_arrow);
+}
+
GtkWidget *
gsr_create_summary_bar( GNCSplitReg *gsr )
{
@@ -2036,6 +2121,8 @@ gsr_create_summary_bar( GNCSplitReg *gsr )
gsr->reconciled_label = NULL;
gsr->future_label = NULL;
gsr->projectedminimum_label = NULL;
+ gsr->sort_label = NULL;
+ gsr->sort_arrow = NULL;
gsr->shares_label = NULL;
gsr->value_label = NULL;
@@ -2047,21 +2134,26 @@ gsr_create_summary_bar( GNCSplitReg *gsr )
summarybar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_box_set_homogeneous (GTK_BOX (summarybar), FALSE);
+ gtk_widget_set_name (summarybar, "gnc-id-summarybar");
if (!xaccAccountIsPriced(gnc_ledger_display_leader(gsr->ledger)))
{
- gsr->balance_label = add_summary_label (summarybar, TRUE, _("Present:"));
- gsr->future_label = add_summary_label (summarybar, TRUE, _("Future:"));
- gsr->cleared_label = add_summary_label (summarybar, TRUE, _("Cleared:"));
- gsr->reconciled_label = add_summary_label (summarybar, TRUE, _("Reconciled:"));
- gsr->projectedminimum_label = add_summary_label (summarybar, TRUE, _("Projected Minimum:"));
+ gsr->balance_label = add_summary_label (summarybar, TRUE, _("Present:"), NULL);
+ gsr->future_label = add_summary_label (summarybar, TRUE, _("Future:"), NULL);
+ gsr->cleared_label = add_summary_label (summarybar, TRUE, _("Cleared:"), NULL);
+ gsr->reconciled_label = add_summary_label (summarybar, TRUE, _("Reconciled:"), NULL);
+ gsr->projectedminimum_label = add_summary_label (summarybar, TRUE, _("Projected Minimum:"), NULL);
}
else
{
- gsr->shares_label = add_summary_label (summarybar, TRUE, _("Shares:"));
- gsr->value_label = add_summary_label (summarybar, TRUE, _("Current Value:"));
+ gsr->shares_label = add_summary_label (summarybar, TRUE, _("Shares:"), NULL);
+ gsr->value_label = add_summary_label (summarybar, TRUE, _("Current Value:"), NULL);
}
+ gsr->sort_arrow = gtk_image_new_from_icon_name ("image-missing", GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gsr->sort_label = add_summary_label (summarybar, FALSE, _("Sort By: "), gsr->sort_arrow);
+ gnc_widget_set_style_context (GTK_WIDGET(gsr->sort_arrow), "gnc-class-highlight");
+
gsr->summarybar = summarybar;
/* Force the first update */
diff --git a/gnucash/gnome/gnc-split-reg.h b/gnucash/gnome/gnc-split-reg.h
index 018836f..a8e2d26 100644
--- a/gnucash/gnome/gnc-split-reg.h
+++ b/gnucash/gnome/gnc-split-reg.h
@@ -74,6 +74,8 @@ struct _GNCSplitReg
GtkWidget *projectedminimum_label;
GtkWidget *shares_label;
GtkWidget *value_label;
+ GtkWidget *sort_label;
+ GtkWidget *sort_arrow;
/** The current ledger display. **/
GNCLedgerDisplay *ledger;
@@ -82,7 +84,9 @@ struct _GNCSplitReg
gint numRows;
- guint sort_type;
+ guint sort_type;
+ gboolean sort_rev;
+ gulong sort_arrow_handler_id;
gboolean read_only;
};
@@ -197,7 +201,7 @@ void gnc_split_reg_set_sort_type_force( GNCSplitReg *gsr, SortType t, gboolean f
/**
* Set/get sort order of register
- **/
+ **/
void gnc_split_reg_set_sort_reversed(GNCSplitReg *gsr, gboolean rev);
commit c3724431e9fd3cd840bc6910e4c0df99bdf08abe
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sun Jun 17 20:39:35 2018 +0100
Add a parameter to add_summary_label to specify packing order
Add boolean pack_start to add_summary_label to indicate whether the
labels should be packed at the start or end of the summary bar.
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index aba9fdc..b7829e6 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -65,7 +65,7 @@ static QofLogModule log_module = GNC_MOD_GUI;
/***** PROTOTYPES ***************************************************/
void gnc_split_reg_raise( GNCSplitReg *gsr );
-static GtkWidget* add_summary_label( GtkWidget *summarybar,
+static GtkWidget* add_summary_label( GtkWidget *summarybar, gboolean pack_start,
const char *label_str );
static void gnc_split_reg_determine_read_only( GNCSplitReg *gsr );
@@ -2003,14 +2003,17 @@ gnc_split_reg_size_allocate (GtkWidget *widget,
static
GtkWidget*
-add_summary_label (GtkWidget *summarybar, const char *label_str)
+add_summary_label (GtkWidget *summarybar, gboolean pack_start, const char *label_str)
{
GtkWidget *hbox;
GtkWidget *label;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
- gtk_box_pack_start( GTK_BOX(summarybar), hbox, FALSE, FALSE, 5 );
+ if (pack_start)
+ gtk_box_pack_start( GTK_BOX(summarybar), hbox, FALSE, FALSE, 5 );
+ else
+ gtk_box_pack_end( GTK_BOX(summarybar), hbox, FALSE, FALSE, 5 );
label = gtk_label_new( label_str );
gnc_label_set_alignment(label, 1.0, 0.5 );
@@ -2047,16 +2050,16 @@ gsr_create_summary_bar( GNCSplitReg *gsr )
if (!xaccAccountIsPriced(gnc_ledger_display_leader(gsr->ledger)))
{
- gsr->balance_label = add_summary_label (summarybar, _("Present:"));
- gsr->future_label = add_summary_label (summarybar, _("Future:"));
- gsr->cleared_label = add_summary_label (summarybar, _("Cleared:"));
- gsr->reconciled_label = add_summary_label (summarybar, _("Reconciled:"));
- gsr->projectedminimum_label = add_summary_label (summarybar, _("Projected Minimum:"));
+ gsr->balance_label = add_summary_label (summarybar, TRUE, _("Present:"));
+ gsr->future_label = add_summary_label (summarybar, TRUE, _("Future:"));
+ gsr->cleared_label = add_summary_label (summarybar, TRUE, _("Cleared:"));
+ gsr->reconciled_label = add_summary_label (summarybar, TRUE, _("Reconciled:"));
+ gsr->projectedminimum_label = add_summary_label (summarybar, TRUE, _("Projected Minimum:"));
}
else
{
- gsr->shares_label = add_summary_label (summarybar, _("Shares:"));
- gsr->value_label = add_summary_label (summarybar, _("Current Value:"));
+ gsr->shares_label = add_summary_label (summarybar, TRUE, _("Shares:"));
+ gsr->value_label = add_summary_label (summarybar, TRUE, _("Current Value:"));
}
gsr->summarybar = summarybar;
commit 446446948404b4fd61846042fc93724a8fe84f95
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 16 16:12:14 2018 -0700
Revert changes associated with Bug 775368
Return commodity-utilities.scm to its state at 5803c141.
Too many changes in between to do a straight revert.
diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index 6d7b5dc..4238d1a 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -63,28 +63,16 @@
(xaccSplitGetParent s)))
(acc-comm
(xaccAccountGetCommodity
- (xaccSplitGetAccount s)))
- (acc-type
- (xaccAccountGetType
- (xaccSplitGetAccount s)))
- (split-amt
- (xaccSplitGetAmount s))
- )
+ (xaccSplitGetAccount s))))
(and
- ;; Same commodities, so no price:
(not (gnc-commodity-equiv
trans-comm acc-comm))
(or
- ;; No commodity, bad split
(not commodity)
- ;; Not a price that interests us
- (gnc-commodity-equiv commodity trans-comm)
- (gnc-commodity-equiv commodity acc-comm))
- ;; No amount, so no price:
- (not (gnc-numeric-zero-p split-amt))
- ;; no trading accounts so we don't count twice
- (not (eq? acc-type ACCT-TYPE-TRADING))
- )))
+ (gnc-commodity-equiv
+ commodity trans-comm)
+ (gnc-commodity-equiv
+ commodity acc-comm)))))
(qof-query-run query)))
(qof-query-destroy query)
splits))
@@ -98,8 +86,9 @@
(sort (gnc:get-match-commodity-splits currency-accounts
end-date commodity)
(lambda (a b)
- (< (xaccTransGetDate (xaccSplitGetParent a))
- (xaccTransGetDate (xaccSplitGetParent b))))))
+ (<
+ (xaccTransGetDate (xaccSplitGetParent a))
+ (xaccTransGetDate (xaccSplitGetParent b))))))
;; Returns a list of all splits in the currency-accounts up to
@@ -368,8 +357,8 @@
;; (gnc-numeric-to-double (second later))))
(if (and earlier later)
- (if (< (abs (- (first earlier) date))
- (abs (- (first later) date)))
+ (if (< (abs (- date (first earlier)))
+ (abs (- date (first later))))
(second earlier)
(second later))
(or
@@ -515,10 +504,17 @@
;; report-commodity ((cdadr newrate) 'total
;; #f))))
(set! reportlist (cons newrate reportlist))))))
- ;; The report-currency showed up on the wrong side, so it was a
- ;; "sell" for that commodity. We ignore those for cost reports
- ;; and they're already aggregated for non-cost reports.
- ))
+ ;; Huh, the report-currency showed up on the wrong side
+ ;; -- we will just add it to the reportlist on the
+ ;; right side.
+ (let ((newrate (list (car otherlist)
+ (cons (cdadr pair) (caadr pair)))))
+ ;; (warn "created new rate: "
+ ;; (gnc-commodity-value->string (list (car newrate)
+ ;; ((caadr newrate) 'total #f))) " = "
+ ;; (gnc-commodity-value->string (list
+ ;; report-commodity ((cdadr newrate) 'total #f))))
+ (set! reportlist (cons newrate reportlist)))))
(cadr otherlist))))
sumlist)
@@ -530,58 +526,29 @@
;; or more runs of gnc:resolve-unknown-comm. Maybe we could transform
;; this functions to use some kind of recursiveness.
-(define (create-commodity-list inner-comm outer-comm value-amount share-amount)
- (let ((pair (list inner-comm
- (cons (gnc:make-number-collector)
- (gnc:make-number-collector)))))
- ((caadr pair) 'add value-amount)
- ((cdadr pair) 'add share-amount)
- (list outer-comm (list pair))))
-
-(define (create-foreign-list comm-list transaction-comm account-comm
- share-amount value-amount)
- (let ((foreign-list
- (if (gnc-commodity-equiv transaction-comm (car comm-list))
- (list account-comm share-amount value-amount)
- (list transaction-comm value-amount share-amount))))
- foreign-list))
-
-(define (create-foreign-cost-list comm-list transaction-comm account-comm
- share-amount value-amount)
- (let ((foreign-list
- (if (gnc-commodity-equiv transaction-comm (car comm-list))
- (list account-comm share-amount value-amount)
- (list transaction-comm (gnc-numeric-neg value-amount)
- (gnc-numeric-neg share-amount)))))
- foreign-list))
-
-(define (create-commodity-pair foreignlist comm-list sumlist)
- (let ((pair (assoc (car foreignlist) (cadr comm-list))))
- ;; no pair already, create one
- (if (not pair)
- (set! pair (list (car foreignlist)
- (cons (gnc:make-number-collector)
- (gnc:make-number-collector)))))
- pair))
-
-;; sumlist: a multilevel alist. Each element has a commodity as key, and another
-;; alist as a value. The value-alist's elements consist of a commodity as a key,
-;; and a pair of two value-collectors as value, e.g. with only one (the report-)
-;; commodity DEM in the outer alist: ( {DEM ( [USD (400 . 1000)] [FRF (300
-;; . 100)] ) } ) where DEM,USD,FRF are <gnc:commodity> and the numbers are a
-;; numeric-collector which in turn store a <gnc:numeric>. In the example, USD
-;; 400 were bought for an amount of DEM 1000, FRF 300 were bought for DEM
-;; 100. The reason for the outer alist is that there might be commodity
-;; transactions which do not involve the report-commodity, but which can still
-;; be calculated after *all* transactions are processed. Calculate the weighted
-;; average exchange rate between all commodities and the
-;; 'report-commodity'. Uses all currency transactions up until the
-;; 'end-date'. Returns an alist, see sumlist.
-(define (gnc:get-exchange-totals report-commodity end-date cost)
+
+;; Calculate the weighted average exchange rate between all
+;; commodities and the 'report-commodity'. Uses all currency
+;; transactions up until the 'end-date'. Returns an alist, see
+;; sumlist.
+(define (gnc:get-exchange-totals report-commodity end-date)
(let ((curr-accounts
;;(filter gnc:account-has-shares? ))
;; -- use all accounts, not only share accounts, since gnucash-1.7
(gnc-account-get-descendants-sorted (gnc-get-current-root-account)))
+ ;; sumlist: a multilevel alist. Each element has a commodity
+ ;; as key, and another alist as a value. The value-alist's
+ ;; elements consist of a commodity as a key, and a pair of two
+ ;; value-collectors as value, e.g. with only one (the report-)
+ ;; commodity DEM in the outer alist: ( {DEM ( [USD (400 .
+ ;; 1000)] [FRF (300 . 100)] ) } ) where DEM,USD,FRF are
+ ;; <gnc:commodity> and the numbers are a numeric-collector
+ ;; which in turn store a <gnc:numeric>. In the example, USD
+ ;; 400 were bought for an amount of DEM 1000, FRF 300 were
+ ;; bought for DEM 100. The reason for the outer alist is that
+ ;; there might be commodity transactions which do not involve
+ ;; the report-commodity, but which can still be calculated
+ ;; after *all* transactions are processed.
(sumlist (list (list report-commodity '()))))
(if (not (null? curr-accounts))
@@ -593,47 +560,170 @@
(xaccSplitGetParent a)))
(account-comm (xaccAccountGetCommodity
(xaccSplitGetAccount a)))
- (share-amount (if cost
- (xaccSplitGetAmount a)
- (gnc-numeric-abs (xaccSplitGetAmount a))))
- (value-amount (if cost
- (xaccSplitGetValue a)
- (gnc-numeric-abs (xaccSplitGetValue a))))
+ ;; Always use the absolute value here.
+ (share-amount (gnc-numeric-abs
+ (xaccSplitGetAmount a)))
+ (value-amount (gnc-numeric-abs
+ (xaccSplitGetValue a)))
(tmp (assoc transaction-comm sumlist))
(comm-list (if (not tmp)
(assoc account-comm sumlist)
tmp)))
- ;; entry exists already in comm-list?
- (if (not comm-list)
- ;; no, create sub-alist from scratch
- (begin
- (set! comm-list (create-commodity-list
- account-comm transaction-comm
- value-amount share-amount))
- (set! sumlist (cons comm-list sumlist)))
-
- ;;yes, check for second commodity
- (let* ((foreignlist (if cost
- (create-foreign-cost-list
- comm-list transaction-comm account-comm
- share-amount value-amount)
- (create-foreign-list
- comm-list transaction-comm account-comm
- share-amount value-amount)))
- (pair (create-commodity-pair foreignlist comm-list
- sumlist)))
- (set! comm-list (list (car comm-list)
- (cons pair (cadr comm-list))))
- (set! sumlist (cons comm-list
- (alist-delete (car comm-list) sumlist)))
- ((caadr pair) 'add (cadr foreignlist))
- ((cdadr pair) 'add (caddr foreignlist))))))
-
- (gnc:get-all-commodity-splits curr-accounts end-date)))
-
- (gnc:resolve-unknown-comm sumlist report-commodity)))
-
-(define (gnc:make-exchange-alist report-commodity end-date cost)
+
+ (cond ((gnc-numeric-zero-p share-amount)
+ ;; Without shares this is not a buy or sell; ignore it.
+ #f)
+
+ ((not comm-list)
+ ;; entry doesn't exist in comm-list
+ ;; create sub-alist from scratch
+ (let ((pair (list transaction-comm
+ (cons (gnc:make-number-collector)
+ (gnc:make-number-collector)))))
+ ((caadr pair) 'add value-amount)
+ ((cdadr pair) 'add share-amount)
+ (set! comm-list (list account-comm (list pair)))
+ ;; and add the new sub-alist to sumlist.
+ (set! sumlist (cons comm-list sumlist))))
+
+ (else
+ (let*
+ ;; Put the amounts in the right place.
+ ((foreignlist
+ (if (gnc-commodity-equiv transaction-comm
+ (car comm-list))
+ (list account-comm
+ share-amount value-amount)
+ (list transaction-comm
+ value-amount share-amount)))
+ ;; second commodity already existing in comm-list?
+ (pair (assoc (car foreignlist) (cadr comm-list))))
+ ;; if not, create a new entry in comm-list.
+ (if (not pair)
+ (begin
+ (set!
+ pair (list (car foreignlist)
+ (cons (gnc:make-number-collector)
+ (gnc:make-number-collector))))
+ (set!
+ comm-list (list (car comm-list)
+ (cons pair (cadr comm-list))))
+ (set!
+ sumlist (cons comm-list
+ (alist-delete
+ (car comm-list) sumlist)))))
+ ;; And add the balances to the comm-list entry.
+ ((caadr pair) 'add (cadr foreignlist))
+ ((cdadr pair) 'add (caddr foreignlist)))))))
+ (gnc:get-all-commodity-splits curr-accounts end-date)))
+
+ (gnc:resolve-unknown-comm sumlist report-commodity)))
+
+;; Calculate the volume-weighted average cost of all commodities,
+;; priced in the 'report-commodity'. Uses all transactions up until
+;; the 'end-date'. Returns an alist, see sumlist.
+(define (gnc:get-exchange-cost-totals report-commodity end-date)
+ (let ((curr-accounts
+ ;;(filter gnc:account-has-shares? ))
+ ;; -- use all accounts, not only share accounts, since gnucash-1.7
+ (gnc-account-get-descendants-sorted (gnc-get-current-root-account)))
+ ;; sumlist: a multilevel alist. Each element has a commodity
+ ;; as key, and another alist as a value. The value-alist's
+ ;; elements consist of a commodity as a key, and a pair of two
+ ;; value-collectors as value, e.g. with only one (the report-)
+ ;; commodity DEM in the outer alist: ( {DEM ( [USD (400 .
+ ;; 1000)] [FRF (300 . 100)] ) } ) where DEM,USD,FRF are
+ ;; <gnc:commodity> and the numbers are a numeric-collector
+ ;; which in turn store a <gnc:numeric>. In the example, USD
+ ;; 400 were bought for an amount of DEM 1000, FRF 300 were
+ ;; bought for DEM 100. The reason for the outer alist is that
+ ;; there might be commodity transactions which do not involve
+ ;; the report-commodity, but which can still be calculated
+ ;; after *all* transactions are processed.
+ (sumlist (list (list report-commodity '()))))
+
+ (if (not (null? curr-accounts))
+ ;; Go through all splits and add up all value-amounts
+ ;; and share-amounts
+ ;; However skip splits in trading accounts as these counterbalance
+ ;; the actual value and share amounts back to zero
+ (for-each
+ (lambda (a)
+ (if (not (eq? (xaccAccountGetType (xaccSplitGetAccount a)) ACCT-TYPE-TRADING))
+ (let* ((transaction-comm (xaccTransGetCurrency
+ (xaccSplitGetParent a)))
+ (account-comm (xaccAccountGetCommodity
+ (xaccSplitGetAccount a)))
+ (share-amount (xaccSplitGetAmount a))
+ (value-amount (xaccSplitGetValue a))
+ (tmp (assoc transaction-comm sumlist))
+ (comm-list (if (not tmp)
+ (assoc account-comm sumlist)
+ tmp)))
+
+ ;; entry exists already in comm-list?
+ (if (not comm-list)
+ ;; no, create sub-alist from scratch
+ (let ((pair (list transaction-comm
+ (cons (gnc:make-number-collector)
+ (gnc:make-number-collector)))))
+ ((caadr pair) 'add value-amount)
+ ((cdadr pair) 'add share-amount)
+ (set! comm-list (list account-comm (list pair)))
+ ;; and add the new sub-alist to sumlist.
+ (set! sumlist (cons comm-list sumlist)))
+ ;; yes, check for second commodity.
+ (let*
+ ;; Put the amounts in the right place.
+ ((foreignlist
+ (if (gnc-commodity-equiv transaction-comm
+ (car comm-list))
+ (list account-comm
+ share-amount value-amount)
+ (list transaction-comm
+ (gnc-numeric-neg value-amount)
+ (gnc-numeric-neg share-amount))))
+ ;; second commodity already existing in comm-list?
+ (pair (assoc (car foreignlist) (cadr comm-list))))
+ ;; if not, create a new entry in comm-list.
+ (if (not pair)
+ (begin
+ (set!
+ pair (list (car foreignlist)
+ (cons (gnc:make-number-collector)
+ (gnc:make-number-collector))))
+ (set!
+ comm-list (list (car comm-list)
+ (cons pair (cadr comm-list))))
+ (set!
+ sumlist (cons comm-list
+ (alist-delete
+ (car comm-list) sumlist)))))
+ ;; And add the balances to the comm-list entry.
+ ((caadr pair) 'add (cadr foreignlist))
+ ((cdadr pair) 'add (caddr foreignlist)))))))
+ (gnc:get-all-commodity-splits curr-accounts end-date)))
+
+ (gnc:resolve-unknown-comm sumlist report-commodity)))
+
+;; Anybody feel free to reimplement any of these functions, either in
+;; scheme or in C. -- cstim
+
+(define (gnc:make-exchange-alist report-commodity end-date)
+ ;; This returns the alist with the actual exchange rates, i.e. the
+ ;; total balances from get-exchange-totals are divided by each
+ ;; other.
+ (map
+ (lambda (e)
+ (list (car e)
+ (gnc-numeric-abs
+ (gnc-numeric-div ((cdadr e) 'total #f)
+ ((caadr e) 'total #f)
+ GNC-DENOM-AUTO
+ (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)))))
+ (gnc:get-exchange-totals report-commodity end-date)))
+
+(define (gnc:make-exchange-cost-alist report-commodity end-date)
;; This returns the alist with the actual exchange rates, i.e. the
;; total balances from get-exchange-totals are divided by each
;; other.
@@ -641,13 +731,16 @@
(lambda (e)
(list (car e)
(if (zero? ((caadr e) 'total #f)) #f
- (gnc-numeric-abs
+ (gnc-numeric-abs
(gnc-numeric-div ((cdadr e) 'total #f)
((caadr e) 'total #f)
GNC-DENOM-AUTO
- (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)))
- )))
- (gnc:get-exchange-totals report-commodity end-date cost)))
+ (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))))))
+ (gnc:get-exchange-cost-totals report-commodity end-date)))
+
+
+
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Actual functions for exchanging amounts.
@@ -839,18 +932,18 @@
;; the value of 'source-option', whose possible values are set in
;; gnc:options-add-price-source!.
(define (gnc:case-exchange-fn
- source-option report-currency to-date)
+ source-option report-currency to-date-tp)
(case source-option
((average-cost) (gnc:make-exchange-function
- (gnc:make-exchange-alist
- report-currency to-date #t)))
+ (gnc:make-exchange-cost-alist
+ report-currency to-date-tp)))
((weighted-average) (gnc:make-exchange-function
(gnc:make-exchange-alist
- report-currency to-date #f)))
+ report-currency to-date-tp)))
((pricedb-latest) gnc:exchange-by-pricedb-latest)
((pricedb-nearest) (lambda (foreign domestic)
(gnc:exchange-by-pricedb-nearest
- foreign domestic to-date)))
+ foreign domestic to-date-tp)))
(else
(begin
;; FIX-ME
@@ -863,7 +956,7 @@
source-option " using pricedb-nearest.")
(lambda (foreign domestic)
(gnc:exchange-by-pricedb-nearest
- foreign domestic to-date))))))
+ foreign domestic to-date-tp))))))
;; Return a ready-to-use function. Which one to use is determined by
;; the value of 'source-option', whose possible values are set in
@@ -873,25 +966,25 @@
;; section of the progress bar while running this function.
;;
(define (gnc:case-exchange-time-fn
- source-option report-currency commodity-list to-date
+ source-option report-currency commodity-list to-date-tp
start-percent delta-percent)
(case source-option
;; Make this the same as gnc:case-exchange-fn
((average-cost) (let* ((exchange-fn (gnc:make-exchange-function
- (gnc:make-exchange-alist
- report-currency to-date #t))))
+ (gnc:make-exchange-cost-alist
+ report-currency to-date-tp))))
(lambda (foreign domestic date)
(exchange-fn foreign domestic))))
((weighted-average) (let ((pricealist
(gnc:get-commoditylist-totalavg-prices
- commodity-list report-currency to-date
+ commodity-list report-currency to-date-tp
start-percent delta-percent)))
(lambda (foreign domestic date)
(gnc:exchange-by-pricealist-nearest
pricealist foreign domestic date))))
((actual-transactions) (let ((pricealist
(gnc:get-commoditylist-inst-prices
- commodity-list report-currency to-date)))
+ commodity-list report-currency to-date-tp)))
(lambda (foreign domestic date)
(gnc:exchange-by-pricealist-nearest
pricealist foreign domestic date))))
commit 88597d0b647076423208ae3e9670ca7415b4ea1c
Merge: 44c3dc8 c08dee6
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 16 10:54:51 2018 -0700
Merge branch 'remove-timespec' into maint
commit c08dee67bae803e4855f6c0a58ad50270a0e7541
Author: John Ralls <jralls at ceridwen.us>
Date: Mon Aug 13 11:51:06 2018 -0700
Preserve timespec-using functions in Guile bindings.
There's an example of use in text-extras.scm, function
gnc-pricedb-create.
Unfortunately the deprecation messages issue no warnings.
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index 72f9417..dd9c8fb 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -10,6 +10,7 @@ set(engine_noinst_HEADERS
SX-book.h
SX-ttinfo.h
TransactionP.h
+ engine-deprecated.h
gnc-backend-prov.hpp
gnc-date-p.h
gnc-hooks-scm.h
@@ -149,6 +150,7 @@ set (engine_SOURCES
Transaction.c
cap-gains.c
cashobjects.c
+ engine-deprecated.c
gnc-aqbanking-templates.cpp
gnc-budget.c
gnc-commodity.c
@@ -304,6 +306,7 @@ set(engine_EXTRA_DIST
design.txt
engine.i
engine-common.i
+ engine-deprecated.i
extensions.txt
iso-4217-currencies.xml
iso-currencies-to-c.xsl
diff --git a/libgnucash/engine/engine-deprecated.c b/libgnucash/engine/engine-deprecated.c
new file mode 100644
index 0000000..eba2641
--- /dev/null
+++ b/libgnucash/engine/engine-deprecated.c
@@ -0,0 +1,208 @@
+/********************************************************************\
+ * engine-deprecated.i: Guile wrappers for deleted C functions. *
+ * Copyright 2018 John Ralls <jralls at ceridwen.us> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+ * *
+\********************************************************************/
+
+/* The functions in this file have been removed from the C library and are
+ * provided here for backward compatibility. They will be removed completely
+ * from the next major release of GnuCash.
+ */
+
+#include "engine-deprecated.h"
+
+#include <libguile/deprecation.h>
+
+void xaccSplitSetDateReconciledTS(Split* s, Timespec *ts)
+{
+ scm_c_issue_deprecation_warning("xaccSplitSetDateReconciled is deprecated. Use xaccSplitSetDateReconciledSecs instead.");
+ xaccSplitSetDateReconciledSecs (s, ts->tv_sec);
+}
+
+void xaccSplitGetDateReconciledTS(Split* s, Timespec *ts)
+{
+ scm_c_issue_deprecation_warning("xaccSplitGetDateReconciled is deprecated. Use xaccSplitGetDateReconciledSecs instead.");
+ ts->tv_sec = xaccSplitGetDateReconciled (s);
+ ts->tv_nsec = 0;
+}
+
+Timespec xaccSplitRetDateReconciledTS(Split* s)
+{
+ Timespec ts = {0, 0};
+ scm_c_issue_deprecation_warning("xaccSplitSetDateReconciled is deprecated. Use xaccSplitSetDateReconciledSecs instead.");
+ ts.tv_sec = xaccSplitGetDateReconciled (s);
+ return ts;
+}
+
+Timespec
+gnc_transaction_get_date_posted(const Transaction *t)
+{
+ Timespec ts = {0, 0};
+ scm_c_issue_deprecation_warning("gnc_transaction_get_date_posted is deprecated. Use xaccTransRetDatePosted instead.");
+ ts.tv_sec = xaccTransRetDatePosted(t);
+ return ts;
+}
+
+Timespec
+gnc_transaction_get_date_entered(const Transaction *t)
+{
+ Timespec ts = {0, 0};
+ scm_c_issue_deprecation_warning("gnc_transaction_get_date_entered is deprecated. Use xaccTransGetDateEntered instead.");
+ ts.tv_sec = xaccTransRetDateEntered(t);
+ return ts;
+}
+
+Timespec
+gnc_split_get_date_reconciled(const Split *s)
+{
+ Timespec ts = {0, 0};
+ scm_c_issue_deprecation_warning("gnc_split_get_date_reconciled is deprecated. Use xaccSplitGetDateReconciled instead.");
+ ts.tv_sec = xaccSplitGetDateReconciled(s);
+ return ts;
+}
+
+void
+gnc_transaction_set_date(Transaction *t, Timespec ts)
+{
+ scm_c_issue_deprecation_warning("gnc_transaction_set_date is deprecated. Use xaccTransSetDatePostedSecs instead.");
+ xaccTransSetDatePostedSecs(t, ts.tv_sec);
+}
+
+Timespec
+gncTaxTableLastModified (const GncTaxTable *table)
+{
+ Timespec t = {0, 0};
+ scm_c_issue_deprecation_warning("gncTaxTableLastModified is deprecated. Use gncTaxTableLastModifiedSecs instead.");
+ t.tv_sec = gncTaxTableLastModifiedSecs (table);
+ return t;
+}
+
+void
+gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn,
+ GList *lots, Account *posted_acc, Account *xfer_acc,
+ gnc_numeric amount, gnc_numeric exch, Timespec date,
+ const char *memo, const char *num,
+ gboolean auto_pay)
+{
+ scm_c_issue_deprecation_warning("gncOwnerApplyPayment is deprecated. Use gncOwnerApplyPaymentSecs instead.");
+ gncOwnerApplyPaymentSecs (owner, preset_txn, lots, posted_acc,
+ xfer_acc, amount, exch, date.tv_sec,
+ memo, num, auto_pay);
+}
+
+GNCLot*
+gncOwnerCreatePaymentLot (const GncOwner *owner,
+ Transaction **preset_txn, Account *posted_acc,
+ Account *xfer_acc, gnc_numeric amount,
+ gnc_numeric exch, Timespec date,
+ const char *memo, const char *num)
+{
+ GNCLot* lot = NULL;
+ scm_c_issue_deprecation_warning("gncOwnerCreatePaymentLot is deprecated. Use gncOwnerCreatePaymentLotSecs instead.");
+ lot = gncOwnerCreatePaymentLotSecs (owner, preset_txn, posted_acc,
+ xfer_acc, amount, exch, date.tv_sec,
+ memo, num);
+ return lot;
+}
+
+void
+gnc_price_set_time (GNCPrice *p, Timespec t)
+{
+ scm_c_issue_deprecation_warning("gnc_price_set_time is deprecated. Use gnc_price_set_time64 instead.");
+ gnc_price_set_time64(p, t.tv_sec);
+}
+
+Timespec
+gnc_price_get_time (GNCPrice *p)
+{
+ Timespec t = {0, 0};
+ scm_c_issue_deprecation_warning("gnc_price_get_time is deprecated. Use gnc_price_get_time64 instead.");
+ t.tv_sec = gnc_price_get_time64(p);
+ return t;
+}
+
+GNCPrice*
+gnc_pricedb_lookup_at_time(GNCPriceDB *db,
+ const gnc_commodity *commodity,
+ const gnc_commodity *currency,
+ Timespec t)
+{
+ scm_c_issue_deprecation_warning("gnc_pricedb_lookup_at_time is deprecated. Use gnc_pricedb_lookup_at_time64 instead.");
+ return gnc_pricedb_lookup_at_time64(db, commodity, currency, t.tv_sec);
+}
+
+GNCPrice*
+gnc_pricedb_lookup_day(GNCPriceDB *db,
+ const gnc_commodity *commodity,
+ const gnc_commodity *currency,
+ Timespec t)
+{
+ scm_c_issue_deprecation_warning("gnc_pricedb_lookup_day is deprecated. Use gnc_pricedb_lookup_day_t64 instead.");
+ return gnc_pricedb_lookup_day_t64(db, commodity, currency, t.tv_sec);
+}
+
+GNCPrice*
+gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db,
+ const gnc_commodity *c,
+ const gnc_commodity *currency,
+ Timespec t)
+{
+ scm_c_issue_deprecation_warning("gnc_pricedb_lookup_nearest_in_time is deprecated. Use gnc_pricedb_lookup_nearest_in_time64 instead.");
+ return gnc_pricedb_lookup_nearest_in_time64(db, c, currency, t.tv_sec);
+}
+
+PriceList*
+gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db,
+ const gnc_commodity *c,
+ Timespec t)
+{
+ scm_c_issue_deprecation_warning("gnc_pricedb_lookup_nearest_in_time_any_currency is deprecated. Use gnc_pricedb_lookup_nearest_in_time_any_currency_t64 instead.");
+ return gnc_pricedb_lookup_nearest_in_time_any_currency_t64(db, c, t.tv_sec);
+}
+
+GNCPrice*
+gnc_pricedb_lookup_latest_before(GNCPriceDB *db,
+ gnc_commodity *c,
+ gnc_commodity *currency,
+ Timespec t)
+{
+ scm_c_issue_deprecation_warning("gnc_pricedb_lookup_latest_before is deprecated. Use gnc_pricedb_lookup_latest_before_t64 instead.");
+ return gnc_pricedb_lookup_latest_before_t64(db, c, currency, t.tv_sec);
+}
+
+PriceList*
+gnc_pricedb_lookup_latest_before_any_currency(GNCPriceDB *db,
+ const gnc_commodity *c,
+ Timespec t)
+{
+ scm_c_issue_deprecation_warning("gnc_pricedb_lookup_latest_before_any_currency is deprecated. Use gnc_pricedb_lookup_latest_before_any_currency_t64 instead.");
+ return gnc_pricedb_lookup_latest_before_any_currency_t64(db, c, t.tv_sec);
+}
+
+gnc_numeric
+gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
+ gnc_numeric balance,
+ const gnc_commodity *balance_currency,
+ const gnc_commodity *new_currency,
+ Timespec t)
+{
+ scm_c_issue_deprecation_warning("gnc_pricedb_convert_balance_nearest_price is deprecated. Use gnc_pricedb_convert_balance_nearest_price_t64 instead.");
+ return gnc_pricedb_convert_balance_nearest_price_t64(pdb, balance, balance_currency, new_currency, t.tv_sec);
+}
diff --git a/libgnucash/engine/engine-deprecated.h b/libgnucash/engine/engine-deprecated.h
new file mode 100644
index 0000000..90bd4a1
--- /dev/null
+++ b/libgnucash/engine/engine-deprecated.h
@@ -0,0 +1,90 @@
+/********************************************************************\
+ * engine-deprecated.h: Guile wrappers for deleted C functions. *
+ * Copyright 2018 John Ralls <jralls at ceridwen.us> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+ * *
+\********************************************************************/
+
+#include "config.h"
+#include "Split.h"
+#include "Transaction.h"
+#include "gncTaxTable.h"
+#include "gncOwner.h"
+
+typedef struct
+{
+ time64 tv_sec;
+ time64 tv_nsec;
+} Timespec;
+
+
+void xaccSplitSetDateReconciledTS(Split* s, Timespec *ts);
+void xaccSplitGetDateReconciledTS(Split* s, Timespec *ts);
+Timespec xaccSplitRetDateReconciledTS(Split* s);
+
+Timespec gnc_transaction_get_date_posted(const Transaction *t);
+Timespec gnc_transaction_get_date_entered(const Transaction *t);
+Timespec gnc_split_get_date_reconciled(const Split *s);
+void gnc_transaction_set_date(Transaction *t, Timespec ts);
+
+Timespec gncTaxTableLastModified (const GncTaxTable *table);
+
+void gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn,
+ GList *lots, Account *posted_acc, Account *xfer_acc,
+ gnc_numeric amount, gnc_numeric exch, Timespec date,
+ const char *memo, const char *num,
+ gboolean auto_pay);
+
+GNCLot* gncOwnerCreatePaymentLot (const GncOwner *owner,
+ Transaction **preset_txn, Account *posted_acc,
+ Account *xfer_acc, gnc_numeric amount,
+ gnc_numeric exch, Timespec date,
+ const char *memo, const char *num);
+
+void gnc_price_set_time (GNCPrice *p, Timespec t);
+Timespec gnc_price_get_time (GNCPrice *p);
+GNCPrice* gnc_pricedb_lookup_at_time(GNCPriceDB *db,
+ const gnc_commodity *commodity,
+ const gnc_commodity *currency,
+ Timespec t);
+GNCPrice* gnc_pricedb_lookup_day(GNCPriceDB *db,
+ const gnc_commodity *commodity,
+ const gnc_commodity *currency,
+ Timespec t);
+GNCPrice* gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db,
+ const gnc_commodity *c,
+ const gnc_commodity *currency,
+ Timespec t);
+PriceList* gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db,
+ const gnc_commodity *c,
+ Timespec t);
+GNCPrice* gnc_pricedb_lookup_latest_before(GNCPriceDB *db,
+ gnc_commodity *c,
+ gnc_commodity *currency,
+ Timespec t);
+PriceList* gnc_pricedb_lookup_latest_before_any_currency(GNCPriceDB *db,
+ const gnc_commodity *c,
+ Timespec t);
+gnc_numeric
+gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
+ gnc_numeric balance,
+ const gnc_commodity *balance_currency,
+ const gnc_commodity *new_currency,
+ Timespec t);
+
diff --git a/libgnucash/engine/engine.i b/libgnucash/engine/engine.i
index 288f484..ec8dd3d 100644
--- a/libgnucash/engine/engine.i
+++ b/libgnucash/engine/engine.i
@@ -33,6 +33,7 @@
#include "gnc-lot.h"
#include "gnc-session.h"
#include "gnc-hooks-scm.h"
+#include "engine-deprecated.h"
#include "engine-helpers.h"
#include "engine-helpers-guile.h"
#include "policy.h"
@@ -80,6 +81,7 @@ engine-common.i */
%newobject gnc_account_get_full_name;
%include "engine-common.i"
+%include "engine-deprecated.h"
%inline %{
static const GncGUID * gncPriceGetGUID(GNCPrice *x)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 80cf8c0..386ea54 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -624,6 +624,7 @@ libgnucash/engine/business-core.scm
libgnucash/engine/cap-gains.c
libgnucash/engine/cashobjects.c
libgnucash/engine/commodity-table.scm
+libgnucash/engine/engine-deprecated.c
libgnucash/engine/engine-helpers.c
libgnucash/engine/engine-interface.scm
libgnucash/engine/engine.scm
commit e9098d08d28167266a8cbe51a0864efed45b24ca
Author: John Ralls <jralls at ceridwen.us>
Date: Mon Aug 13 11:48:56 2018 -0700
Change ISO date format to remove fractional seconds.
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 9f70cd8..fd394b3 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -1115,7 +1115,7 @@ char *
gnc_time64_to_iso8601_buff (time64 time, char * buff)
{
constexpr size_t max_iso_date_length = 32;
- const char* format = "%Y-%m-%d %H:%M:%s %q";
+ const char* format = "%Y-%m-%d %H:%M:%S %q";
if (! buff) return NULL;
try
commit 35fabe26908d8158d4b576dadfe09ca8cdc8b956
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Aug 4 18:06:29 2018 -0700
Remove Timespec from gnc-date.
diff --git a/libgnucash/engine/gnc-date-p.h b/libgnucash/engine/gnc-date-p.h
index 96f6175..0a09d37 100644
--- a/libgnucash/engine/gnc-date-p.h
+++ b/libgnucash/engine/gnc-date-p.h
@@ -74,7 +74,6 @@ const char *qof_win32_get_time_format(QofWin32Picture picture);
/* Test Access for static functions */
typedef struct
{
- void (*timespec_normalize) (Timespec *t);
GTimeZone* (*timezone_new_local) (void);
} Testfuncs;
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 23e2a81..9f70cd8 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -378,114 +378,12 @@ gnc_print_time64(time64 time, const char* format)
/********************************************************************\
\********************************************************************/
-static void
-timespec_normalize(Timespec *t)
-{
- if (t->tv_nsec > NANOS_PER_SECOND)
- {
- t->tv_sec += (t->tv_nsec / NANOS_PER_SECOND);
- t->tv_nsec = t->tv_nsec % NANOS_PER_SECOND;
- }
-
- if (t->tv_nsec < - NANOS_PER_SECOND)
- {
- t->tv_sec += - (-t->tv_nsec / NANOS_PER_SECOND);
- t->tv_nsec = - (-t->tv_nsec % NANOS_PER_SECOND);
- }
-
- if (t->tv_sec > 0 && t->tv_nsec < 0)
- {
- t->tv_sec--;
- t->tv_nsec = NANOS_PER_SECOND + t->tv_nsec;
- }
-
- if (t->tv_sec < 0 && t->tv_nsec > 0)
- {
- t->tv_sec++;
- t->tv_nsec = - NANOS_PER_SECOND + t->tv_nsec;
- }
- return;
-}
-
-gboolean
-timespec_equal (const Timespec *ta, const Timespec *tb)
-{
- Timespec pta, ptb;
-
- if (ta == tb) return TRUE;
-/* Copy and normalize the copies */
- pta = *ta;
- ptb = *tb;
- timespec_normalize (&pta);
- timespec_normalize (&ptb);
-
- if (pta.tv_sec != ptb.tv_sec) return FALSE;
- if (pta.tv_nsec != ptb.tv_nsec) return FALSE;
- return TRUE;
-}
-
-gint
-timespec_cmp(const Timespec *ta, const Timespec *tb)
-{
- Timespec pta, ptb;
-
- if (ta == tb) return 0;
-/* Copy and normalize the copies */
- pta = *ta;
- ptb = *tb;
- timespec_normalize (&pta);
- timespec_normalize (&ptb);
-
- if (pta.tv_sec < ptb.tv_sec) return -1;
- if (pta.tv_sec > ptb.tv_sec) return 1;
- if (pta.tv_nsec < ptb.tv_nsec) return -1;
- if (pta.tv_nsec > ptb.tv_nsec) return 1;
- return 0;
-}
-
-Timespec
-timespec_diff(const Timespec *ta, const Timespec *tb)
-{
- Timespec retval;
- retval.tv_sec = ta->tv_sec - tb->tv_sec;
- retval.tv_nsec = ta->tv_nsec - tb->tv_nsec;
- timespec_normalize(&retval);
- return retval;
-}
-
-Timespec
-timespec_abs(const Timespec *t)
-{
- Timespec retval = *t;
-
- timespec_normalize(&retval);
- if (retval.tv_sec < 0)
- {
- retval.tv_sec = - retval.tv_sec;
- retval.tv_nsec = - retval.tv_nsec;
- }
-
- return retval;
-}
/* Converts any time on a day to midday that day.
* given a timepair contains any time on a certain day (local time)
* converts it to be midday that day.
*/
-Timespec
-timespecCanonicalDayTime(Timespec t)
-{
- struct tm tm;
- Timespec retval;
- time64 t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
- gnc_localtime_r(&t_secs, &tm);
- gnc_tm_set_day_middle(&tm);
- retval.tv_sec = gnc_mktime(&tm);
- retval.tv_nsec = 0;
- return retval;
-}
-
time64
time64CanonicalDayTime (time64 t)
{
@@ -697,20 +595,6 @@ qof_print_date (time64 t)
return g_strdup (buff);
}
-const char *
-gnc_print_date (Timespec ts)
-{
- static char buff[MAX_DATE_LENGTH];
- time64 t;
-
- memset (buff, 0, sizeof (buff));
- t = ts.tv_sec + (time64)(ts.tv_nsec / 1000000000.0);
-
- qof_print_date_buff (buff, MAX_DATE_LENGTH, t);
-
- return buff;
-}
-
/* ============================================================== */
/* return the greatest integer <= a/b; works for b > 0 and positive or
@@ -1230,20 +1114,13 @@ gnc_iso8601_to_time64_gmt(const char *cstr)
char *
gnc_time64_to_iso8601_buff (time64 time, char * buff)
{
- Timespec ts = {time, 0};
- return gnc_timespec_to_iso8601_buff (ts, buff);
-}
-
-char *
-gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
-{
constexpr size_t max_iso_date_length = 32;
const char* format = "%Y-%m-%d %H:%M:%s %q";
if (! buff) return NULL;
try
{
- GncDateTime gncdt(ts.tv_sec);
+ GncDateTime gncdt(time);
auto sstr = gncdt.format(format);
memset(buff, 0, sstr.length() + 1);
@@ -1252,117 +1129,63 @@ gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
}
catch(std::logic_error& err)
{
- PWARN("Error processing time64 %" PRId64 ": %s", ts.tv_sec, err.what());
+ PWARN("Error processing time64 %" PRId64 ": %s", time, err.what());
return buff;
}
catch(std::runtime_error& err)
{
- PWARN("Error processing time64 %" PRId64 ": %s", ts.tv_sec, err.what());
+ PWARN("Error processing time64 %" PRId64 ": %s", time, err.what());
return buff;
}
}
#define THIRTY_TWO_YEARS 0x3c30fc00LL
-static Timespec
-gnc_dmy2timespec_internal (int day, int month, int year, DayPart day_part)
+static time64
+gnc_dmy2time64_internal (int day, int month, int year, DayPart day_part)
{
try
{
auto date = GncDate(year, month, day);
- return { static_cast<time64>(GncDateTime (date, day_part)), 0 };
+ return static_cast<time64>(GncDateTime (date, day_part));
}
catch(const std::logic_error& err)
{
PWARN("Date computation error from Y-M-D %d-%d-%d: %s",
year, month, day, err.what());
- return {INT64_MAX, 0};
+ return INT64_MAX;
}
catch(const std::runtime_error& err)
{
PWARN("Date computation error from Y-M-D %d-%d-%d: %s",
year, month, day, err.what());
- return {INT64_MAX, 0};
+ return INT64_MAX;
}
}
time64
gnc_dmy2time64 (int day, int month, int year)
{
- return gnc_dmy2timespec_internal (day, month, year, DayPart::start).tv_sec;
+ return gnc_dmy2time64_internal (day, month, year, DayPart::start);
}
time64
gnc_dmy2time64_end (int day, int month, int year)
{
- return gnc_dmy2timespec_internal (day, month, year, DayPart::end).tv_sec;
+ return gnc_dmy2time64_internal (day, month, year, DayPart::end);
}
time64
gnc_dmy2time64_neutral (int day, int month, int year)
{
- return gnc_dmy2timespec_internal (day, month, year, DayPart::neutral).tv_sec;
-}
-
-Timespec
-gnc_dmy2timespec (int day, int month, int year)
-{
- return gnc_dmy2timespec_internal (day, month, year, DayPart::start);
-}
-
-Timespec
-gnc_dmy2timespec_end (int day, int month, int year)
-{
- return gnc_dmy2timespec_internal (day, month, year, DayPart::end);
-}
-
-Timespec
-gnc_dmy2timespec_neutral (int day, int month, int year)
-{
- return gnc_dmy2timespec_internal (day, month, year, DayPart::neutral);
-}
-/********************************************************************\
-\********************************************************************/
-void
-timespecFromTime64 ( Timespec *ts, time64 t )
-{
- ts->tv_sec = t;
- ts->tv_nsec = 0;
-}
-
-Timespec
-timespec_now()
-{
- Timespec ts;
- ts.tv_sec = gnc_time(NULL);
- ts.tv_nsec = 0;
- return ts;
+ return gnc_dmy2time64_internal (day, month, year, DayPart::neutral);
}
-time64
-timespecToTime64 (Timespec ts)
-{
- return ts.tv_sec;
-}
/* The GDate setter functions all in the end use g_date_set_time_t,
* which in turn relies on localtime and is therefore subject to the
* 2038 bug.
*/
-GDate timespec_to_gdate (Timespec ts)
-{
- GDate result;
-
- g_date_clear (&result, 1);
- GncDateTime time(ts.tv_sec);
- auto date = time.date().year_month_day();
- g_date_set_dmy (&result, date.day, static_cast<GDateMonth>(date.month),
- date.year);
- g_assert(g_date_valid (&result));
-
- return result;
-}
-
GDate time64_to_gdate (time64 t)
{
GDate result;
@@ -1411,13 +1234,6 @@ time64 gdate_to_time64 (GDate d)
g_date_get_year(&d));
}
-Timespec gdate_to_timespec (GDate d)
-{
- return gnc_dmy2timespec_neutral (g_date_get_day(&d),
- g_date_get_month(&d),
- g_date_get_year(&d));
-}
-
static void
gnc_tm_get_day_start (struct tm *tm, time64 time_val)
{
@@ -1538,14 +1354,6 @@ time64_get_type( void )
return type;
}
-Testfuncs*
-gnc_date_load_funcs (void)
-{
- Testfuncs *tf = g_slice_new (Testfuncs);
- tf->timespec_normalize = timespec_normalize;
- return tf;
-}
-
/* ================================================= */
gboolean
@@ -1799,3 +1607,10 @@ gnc_gdate_set_prev_fiscal_year_end (GDate *date,
gnc_gdate_set_fiscal_year_end(date, fy_end);
g_date_subtract_years(date, 1);
}
+
+Testfuncs*
+gnc_date_load_funcs (void)
+{
+ Testfuncs *tf = g_slice_new (Testfuncs);
+ return tf;
+}
diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h
index 140dc92..b3dc51e 100644
--- a/libgnucash/engine/gnc-date.h
+++ b/libgnucash/engine/gnc-date.h
@@ -91,16 +91,6 @@ typedef struct
} Time64;
-/** The Timespec is just like the unix 'struct timespec'
- * except that we use a 64-bit unsigned int to
- * store the seconds. This should adequately cover dates in the
- * distant future as well as the distant past, as long as they're not
- * more than a couple dozen times the age of the universe
- * Values of this type can range from -9,223,372,036,854,775,808 to
- * 9,223,372,036,854,775,807.
- */
-typedef struct timespec64 Timespec;
-
/** @name GValue
@{
*/
@@ -295,97 +285,29 @@ void gnc_gdate_set_today (GDate* gd);
void gnc_gdate_set_time64 (GDate* gd, time64 time);
/** @} */
-
-/* Datatypes *******************************************************/
-
-/** \brief Use a 64-bit unsigned int timespec
- *
- * struct timespec64 is just like the unix 'struct timespec' except
- * that we use a 64-bit
- * unsigned int to store the seconds. This should adequately cover
- * dates in the distant future as well as the distant past, as long as
- * they're not more than a couple dozen times the age of the universe.
- * Values of this type can range from -9,223,372,036,854,775,808 to
- * 9,223,372,036,854,775,807.
- */
-
-#ifndef SWIG /* swig 1.1p5 can't hack the long long type */
-struct timespec64
-{
- time64 tv_sec;
- glong tv_nsec;
-};
-#endif /* SWIG */
-
-
-
-/* Prototypes ******************************************************/
-
-/** \name Timespec functions */
-// @{
-/** strict equality */
-gboolean timespec_equal(const Timespec *ta, const Timespec *tb);
-
-/** comparison: if (ta < tb) -1; else if (ta > tb) 1; else 0; */
-gint timespec_cmp(const Timespec *ta, const Timespec *tb);
-
-/** difference between ta and tb, results are normalized
- * ie tv_sec and tv_nsec of the result have the same size
- * abs(result.tv_nsec) <= 1000000000 */
-Timespec timespec_diff(const Timespec *ta, const Timespec *tb);
-
-/** absolute value, also normalized */
-Timespec timespec_abs(const Timespec *t);
-
-/** convert a timespec on a certain day (localtime) to
- * the timespec representing midday on that day. Watch out - this is *not* the
+/** convert a time64 on a certain day (localtime) to
+ * the time64 representing midday on that day. Watch out - this is *not* the
* first second of the day, which is returned by various other functions
- * returning a Timespec. */
-Timespec timespecCanonicalDayTime(Timespec t);
-
+ * returning a time64. */
time64 time64CanonicalDayTime(time64 t);
-/** Returns the current clock time as a Timespec, taken from time(2). */
-Timespec timespec_now (void);
-
-/** Turns a time64 into a Timespec */
-void timespecFromTime64 (Timespec *ts, time64 t );
-
-/** Turns a Timespec into a time64 */
-time64 timespecToTime64 (Timespec ts);
-
-GDate time64_to_gdate (time64 t);
-
-/** Turns a Timespec into a GDate */
-GDate timespec_to_gdate (Timespec ts);
-
-/** Turns a GDate into a Timespec, returning the first second of the day */
-Timespec gdate_to_timespec (GDate d);
-
/** Turns a GDate into a time64, returning the first second of the day */
time64 gdate_to_time64 (GDate d);
/** Convert a day, month, and year to a time64, returning the first second of the day */
time64 gnc_dmy2time64 (gint day, gint month, gint year);
-time64 gnc_dmy2time64_neutral (gint day, gint month, gint year);
-
-time64 gnc_dmy2time64_end (gint day, gint month, gint year);
-
-/** Convert a day, month, and year to a Timespec, returning the first second of the day */
-Timespec gnc_dmy2timespec (gint day, gint month, gint year);
-
-/** Same as gnc_dmy2timespec, but last second of the day */
-Timespec gnc_dmy2timespec_end (gint day, gint month, gint year);
-
-/** Converts a day, month, and year to a Timespec representing 11:00:00 UTC
+/** Converts a day, month, and year to a time64 representing 11:00:00 UTC
* 11:00:00 UTC falls on the same time in almost all timezones, the exceptions
* being the +13, +14, and -12 timezones used by countries along the
* International Date Line. Since users in those timezones would see dates
* immediately change by one day, the function checks the current timezone for
* those changes and adjusts the UTC time so that the date will be consistent.
*/
-Timespec gnc_dmy2timespec_neutral (gint day, gint month, gint year);
+time64 gnc_dmy2time64_neutral (gint day, gint month, gint year);
+
+/** Same as gnc_dmy2time64, but last second of the day */
+time64 gnc_dmy2time64_end (gint day, gint month, gint year);
/** The gnc_iso8601_to_time64_gmt() routine converts an ISO-8601 style
* date/time string to time64. Please note that ISO-8601 strings
@@ -405,8 +327,8 @@ Timespec gnc_dmy2timespec_neutral (gint day, gint month, gint year);
*/
time64 gnc_iso8601_to_time64_gmt(const gchar *);
-/** The gnc_timespec_to_iso8601_buff() routine takes the input
- * UTC Timespec value and prints it as an ISO-8601 style string.
+/** The gnc_time64_to_iso8601_buff() routine takes the input
+ * UTC time64 value and prints it as an ISO-8601 style string.
* The buffer must be long enough to contain the NULL-terminated
* string (32 characters + NUL). This routine returns a pointer
* to the null terminator (and can thus be used in the 'stpcpy'
@@ -421,7 +343,6 @@ time64 gnc_iso8601_to_time64_gmt(const gchar *);
* The string generated by this routine uses the local time zone
* on the machine on which it is executing to create the time string.
*/
-gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
gchar * gnc_time64_to_iso8601_buff (time64, char * buff);
// @}
@@ -555,13 +476,6 @@ size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd);
* **/
char * qof_print_date (time64 secs);
-/** Convenience; calls through to qof_print_date_dmy_buff().
- * Return: static global string.
- * \warning This routine is not thread-safe, because it uses a single
- * global buffer to store the return value. Use qof_print_date_buff()
- * or qof_print_date() instead.
- * **/
-const char * gnc_print_date(Timespec ts);
/* ------------------------------------------------------------------ */
/* time printing utilities */
@@ -706,6 +620,11 @@ guint gnc_gdate_hash( gconstpointer gd );
/** \name GDate to time64 conversions */
// @{
+/** Returns the GDate in which the time64 occurs.
+ * @param t The time64
+ * @returns A GDate for the day in which the time64 occurs.
+ */
+GDate time64_to_gdate (time64 t);
/** The gnc_time64_get_day_start() routine will take the given time in
* GLib GDate format and adjust it to the first second of that day.
diff --git a/libgnucash/engine/test/CMakeLists.txt b/libgnucash/engine/test/CMakeLists.txt
index 7d698f5..a19c1fb 100644
--- a/libgnucash/engine/test/CMakeLists.txt
+++ b/libgnucash/engine/test/CMakeLists.txt
@@ -26,7 +26,6 @@ add_dependencies(check test-link)
add_engine_test(test-load-engine test-load-engine.c)
add_engine_test(test-guid test-guid.cpp)
-add_engine_test(test-date test-date.cpp)
add_engine_test(test-object test-object.c)
add_engine_test(test-commodities test-commodities.cpp)
@@ -271,7 +270,6 @@ set(test_engine_SOURCES_DIST
test-business.c
test-commodities.cpp
test-customer.c
- test-date.cpp
test-employee.c
test-engine-kvp-properties.c
test-engine.c
diff --git a/libgnucash/engine/test/test-date.cpp b/libgnucash/engine/test/test-date.cpp
deleted file mode 100644
index acf502a..0000000
--- a/libgnucash/engine/test/test-date.cpp
+++ /dev/null
@@ -1,421 +0,0 @@
-/*
- * -- fix borken timezone test -- linas May 2004
- */
-/********************************************************************\
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
-\********************************************************************/
-
-extern "C"
-{
-#include <config.h>
-#include <ctype.h>
-#include <glib.h>
-#include <time.h>
-
-#include "gnc-date.h"
-#include "gnc-module.h"
-#include "test-stuff.h"
-#include "test-engine-stuff.h"
-}
-
-static gboolean
-check_time (Timespec ts, gboolean always_print)
-{
- Timespec ts_2;
- char str[128];
- gboolean ok;
-
- ts.tv_nsec = MIN (ts.tv_nsec, 999999999);
- ts.tv_nsec /= 1000;
- ts.tv_nsec *= 1000;
-
- gnc_timespec_to_iso8601_buff (ts, str);
-
- /* The time, in seconds, everywhere on the planet, is always
- * the same, and is independent of location. In particular,
- * the time, in seconds, is identical to the local time in
- * Greenwich (GMT).
- */
- ts_2 = {gnc_iso8601_to_time64_gmt (str), 0};
-
- ok = timespec_equal (&ts, &ts_2);
-
- if (!ok || always_print)
- {
- fprintf (stderr,
- "\n%" G_GINT64_FORMAT ":%ld -> %s ->\n"
- "\t%" G_GINT64_FORMAT ":%ld"
- " (diff of %" G_GINT64_FORMAT " secs %ld nsecs)\n",
- ts.tv_sec, ts.tv_nsec, str,
- ts_2.tv_sec, ts_2.tv_nsec,
- ts.tv_sec - ts_2.tv_sec, ts.tv_nsec - ts_2.tv_nsec);
-
- if (!ok)
- {
- failure ("timespec to iso8601 string conversion failed");
- return FALSE;
- }
- }
-
- success ("timespec to iso8601 string conversion passes");
-
- return TRUE;
-}
-
-static gboolean
-check_conversion (const char * str, Timespec expected_ts)
-{
- Timespec ts;
- struct tm tm;
- int day, month, year;
- GDate d1, d2;
-
- ts = {gnc_iso8601_to_time64_gmt (str), 0};
-
- // We test the conversion to GDate against the gnc_localtime_r
- // conversion, and also the conversion back to timespec and again
- // to GDate so that it is still the original GDate
- gnc_localtime_r (&ts.tv_sec, &tm);
- day = tm.tm_mday;
- month = tm.tm_mon + 1;
- year = tm.tm_year + 1900;
- d1 = timespec_to_gdate(ts);
- d2 = timespec_to_gdate(gdate_to_timespec(d1));
- if ((g_date_compare(&d1, &d2) != 0)
- || (g_date_get_day(&d1) != day)
- || (g_date_get_month(&d1) != month)
- || (g_date_get_year(&d1) != year))
- {
- fprintf (stderr,
- "\nmis-converted \"%s\" to GDate. "
- "Got d1(Y-M-D) = %i-%i-%i, d2(Y-M-D) = %i-%i-%i\n",
- str, year, month, day,
- g_date_get_year(&d2), g_date_get_month(&d2), g_date_get_day(&d2));
- failure ("misconverted timespec");
- return FALSE;
- }
-
- if ((expected_ts.tv_sec != ts.tv_sec) || (expected_ts.tv_nsec != ts.tv_nsec))
- {
- fprintf (stderr,
- "\nmis-converted \"%s\" to %" G_GUINT64_FORMAT ".%09ld seconds\n"
- "\twas expecting %" G_GUINT64_FORMAT ".%09ld seconds\n",
- str, ts.tv_sec, ts.tv_nsec,
- expected_ts.tv_sec, expected_ts.tv_nsec);
- failure ("misconverted timespec");
- return FALSE;
- }
- success ("good conversion");
- return TRUE;
-}
-
-static void
-run_test (void)
-{
- Timespec ts;
- int i;
- gboolean do_print = FALSE;
-
- /* Now leaving the 60's:
- *
- * Black Panthers
- * Weather Underground
- * Kent State
- * Evacuation of Vietnam
- * Impeachment
- * Gas Crisis
- * New York Garbage Crisis
- * Stagflation
- * Delapidated Bicentennial
- * Sex Pistols
- * Punk Rock
- *
- * Of course, anything had to be better than the miserable 70's,
- * which explains why Reagan was elected. Food for thought.
- */
- ts.tv_sec = 10 * 365 * 24 * 3600 + 2 * 24 * 3600;
- ts.tv_nsec = 0;
- check_conversion ("1979-12-31 15:00:00.000000 -0900", ts);
- check_conversion ("1979-12-31 16:00:00.000000 -0800", ts);
- check_conversion ("1979-12-31 17:00:00.000000 -0700", ts);
- check_conversion ("1979-12-31 18:00:00.000000 -0600", ts);
- check_conversion ("1979-12-31 19:00:00.000000 -0500", ts);
- check_conversion ("1979-12-31 20:00:00.000000 -0400", ts);
- check_conversion ("1979-12-31 21:00:00.000000 -0300", ts);
- check_conversion ("1979-12-31 22:00:00.000000 -0200", ts);
- check_conversion ("1979-12-31 23:00:00.000000 -0100", ts);
-
- check_conversion ("1980-01-01 00:00:00.000000 -0000", ts);
- check_conversion ("1980-01-01 00:00:00.000000 +0000", ts);
-
- check_conversion ("1980-01-01 01:00:00.000000 +0100", ts);
- check_conversion ("1980-01-01 02:00:00.000000 +0200", ts);
- check_conversion ("1980-01-01 03:00:00.000000 +0300", ts);
- check_conversion ("1980-01-01 04:00:00.000000 +0400", ts);
- check_conversion ("1980-01-01 05:00:00.000000 +0500", ts);
- check_conversion ("1980-01-01 06:00:00.000000 +0600", ts);
- check_conversion ("1980-01-01 07:00:00.000000 +0700", ts);
- check_conversion ("1980-01-01 08:00:00.000000 +0800", ts);
-
- /* check minute-offsets as well */
- check_conversion ("1980-01-01 08:01:00.000000 +0801", ts);
- check_conversion ("1980-01-01 08:02:00.000000 +0802", ts);
- check_conversion ("1980-01-01 08:03:00.000000 +0803", ts);
- check_conversion ("1980-01-01 08:23:00.000000 +0823", ts);
- check_conversion ("1980-01-01 08:35:00.000000 +0835", ts);
- check_conversion ("1980-01-01 08:47:00.000000 +0847", ts);
- check_conversion ("1980-01-01 08:59:00.000000 +0859", ts);
-
- check_conversion ("1979-12-31 15:01:00.000000 -0859", ts);
- check_conversion ("1979-12-31 15:02:00.000000 -0858", ts);
- check_conversion ("1979-12-31 15:03:00.000000 -0857", ts);
- check_conversion ("1979-12-31 15:23:00.000000 -0837", ts);
- check_conversion ("1979-12-31 15:45:00.000000 -0815", ts);
-
-
- /* The 90's */
- ts.tv_sec = 20 * 365 * 24 * 3600 + 5 * 24 * 3600;
- ts.tv_nsec = 0;
- check_conversion ("1989-12-31 15:00:00.000000 -0900", ts);
- check_conversion ("1989-12-31 16:00:00.000000 -0800", ts);
- check_conversion ("1989-12-31 17:00:00.000000 -0700", ts);
- check_conversion ("1989-12-31 18:00:00.000000 -0600", ts);
- check_conversion ("1989-12-31 19:00:00.000000 -0500", ts);
- check_conversion ("1989-12-31 20:00:00.000000 -0400", ts);
- check_conversion ("1989-12-31 21:00:00.000000 -0300", ts);
- check_conversion ("1989-12-31 22:00:00.000000 -0200", ts);
- check_conversion ("1989-12-31 23:00:00.000000 -0100", ts);
-
- check_conversion ("1990-01-01 00:00:00.000000 -0000", ts);
- check_conversion ("1990-01-01 00:00:00.000000 +0000", ts);
-
- check_conversion ("1990-01-01 01:00:00.000000 +0100", ts);
- check_conversion ("1990-01-01 02:00:00.000000 +0200", ts);
- check_conversion ("1990-01-01 03:00:00.000000 +0300", ts);
- check_conversion ("1990-01-01 04:00:00.000000 +0400", ts);
- check_conversion ("1990-01-01 05:00:00.000000 +0500", ts);
- check_conversion ("1990-01-01 06:00:00.000000 +0600", ts);
- check_conversion ("1990-01-01 07:00:00.000000 +0700", ts);
- check_conversion ("1990-01-01 08:00:00.000000 +0800", ts);
-
- /* check minute-offsets as well */
- check_conversion ("1990-01-01 08:01:00.000000 +0801", ts);
- check_conversion ("1990-01-01 08:02:00.000000 +0802", ts);
- check_conversion ("1990-01-01 08:03:00.000000 +0803", ts);
- check_conversion ("1990-01-01 08:23:00.000000 +0823", ts);
- check_conversion ("1990-01-01 08:35:00.000000 +0835", ts);
- check_conversion ("1990-01-01 08:47:00.000000 +0847", ts);
- check_conversion ("1990-01-01 08:59:00.000000 +0859", ts);
-
- check_conversion ("1989-12-31 15:01:00.000000 -0859", ts);
- check_conversion ("1989-12-31 15:02:00.000000 -0858", ts);
- check_conversion ("1989-12-31 15:03:00.000000 -0857", ts);
- check_conversion ("1989-12-31 15:23:00.000000 -0837", ts);
- check_conversion ("1989-12-31 15:45:00.000000 -0815", ts);
-
-
- /* The naughties */
- ts.tv_sec = 30 * 365 * 24 * 3600 + 7 * 24 * 3600;
- ts.tv_nsec = 0;
- check_conversion ("1999-12-31 15:00:00.000000 -0900", ts);
- check_conversion ("1999-12-31 16:00:00.000000 -0800", ts);
- check_conversion ("1999-12-31 17:00:00.000000 -0700", ts);
- check_conversion ("1999-12-31 18:00:00.000000 -0600", ts);
- check_conversion ("1999-12-31 19:00:00.000000 -0500", ts);
- check_conversion ("1999-12-31 20:00:00.000000 -0400", ts);
- check_conversion ("1999-12-31 21:00:00.000000 -0300", ts);
- check_conversion ("1999-12-31 22:00:00.000000 -0200", ts);
- check_conversion ("1999-12-31 23:00:00.000000 -0100", ts);
-
- check_conversion ("2000-01-01 00:00:00.000000 -0000", ts);
- check_conversion ("2000-01-01 00:00:00.000000 +0000", ts);
-
- check_conversion ("2000-01-01 01:00:00.000000 +0100", ts);
- check_conversion ("2000-01-01 02:00:00.000000 +0200", ts);
- check_conversion ("2000-01-01 03:00:00.000000 +0300", ts);
- check_conversion ("2000-01-01 04:00:00.000000 +0400", ts);
- check_conversion ("2000-01-01 05:00:00.000000 +0500", ts);
- check_conversion ("2000-01-01 06:00:00.000000 +0600", ts);
- check_conversion ("2000-01-01 07:00:00.000000 +0700", ts);
- check_conversion ("2000-01-01 08:00:00.000000 +0800", ts);
-
- /* check minute-offsets as well */
- check_conversion ("2000-01-01 08:01:00.000000 +0801", ts);
- check_conversion ("2000-01-01 08:02:00.000000 +0802", ts);
- check_conversion ("2000-01-01 08:03:00.000000 +0803", ts);
- check_conversion ("2000-01-01 08:23:00.000000 +0823", ts);
- check_conversion ("2000-01-01 08:35:00.000000 +0835", ts);
- check_conversion ("2000-01-01 08:47:00.000000 +0847", ts);
- check_conversion ("2000-01-01 08:59:00.000000 +0859", ts);
-
- check_conversion ("1999-12-31 15:01:00.000000 -0859", ts);
- check_conversion ("1999-12-31 15:02:00.000000 -0858", ts);
- check_conversion ("1999-12-31 15:03:00.000000 -0857", ts);
- check_conversion ("1999-12-31 15:23:00.000000 -0837", ts);
- check_conversion ("1999-12-31 15:45:00.000000 -0815", ts);
-
-
- /* The nows */
- ts.tv_sec = 35 * 365 * 24 * 3600 + 9 * 24 * 3600;
- ts.tv_nsec = 0;
- check_conversion ("2004-12-31 15:00:00.000000 -0900", ts);
- check_conversion ("2004-12-31 16:00:00.000000 -0800", ts);
- check_conversion ("2004-12-31 17:00:00.000000 -0700", ts);
- check_conversion ("2004-12-31 18:00:00.000000 -0600", ts);
- check_conversion ("2004-12-31 19:00:00.000000 -0500", ts);
- check_conversion ("2004-12-31 20:00:00.000000 -0400", ts);
- check_conversion ("2004-12-31 21:00:00.000000 -0300", ts);
- check_conversion ("2004-12-31 22:00:00.000000 -0200", ts);
- check_conversion ("2004-12-31 23:00:00.000000 -0100", ts);
-
- check_conversion ("2005-01-01 00:00:00.000000 -0000", ts);
- check_conversion ("2005-01-01 00:00:00.000000 +0000", ts);
-
- check_conversion ("2005-01-01 01:00:00.000000 +0100", ts);
- check_conversion ("2005-01-01 02:00:00.000000 +0200", ts);
- check_conversion ("2005-01-01 03:00:00.000000 +0300", ts);
- check_conversion ("2005-01-01 04:00:00.000000 +0400", ts);
- check_conversion ("2005-01-01 05:00:00.000000 +0500", ts);
- check_conversion ("2005-01-01 06:00:00.000000 +0600", ts);
- check_conversion ("2005-01-01 07:00:00.000000 +0700", ts);
- check_conversion ("2005-01-01 08:00:00.000000 +0800", ts);
-
- /* check minute-offsets as well */
- check_conversion ("2005-01-01 08:01:00.000000 +0801", ts);
- check_conversion ("2005-01-01 08:02:00.000000 +0802", ts);
- check_conversion ("2005-01-01 08:03:00.000000 +0803", ts);
- check_conversion ("2005-01-01 08:23:00.000000 +0823", ts);
- check_conversion ("2005-01-01 08:35:00.000000 +0835", ts);
- check_conversion ("2005-01-01 08:47:00.000000 +0847", ts);
- check_conversion ("2005-01-01 08:59:00.000000 +0859", ts);
-
- check_conversion ("2004-12-31 15:01:00.000000 -0859", ts);
- check_conversion ("2004-12-31 15:02:00.000000 -0858", ts);
- check_conversion ("2004-12-31 15:03:00.000000 -0857", ts);
- check_conversion ("2004-12-31 15:23:00.000000 -0837", ts);
- check_conversion ("2004-12-31 15:45:00.000000 -0815", ts);
-
-
- /* Various leap-year days and near-leap times. */
- ts = {gnc_iso8601_to_time64_gmt ("1980-02-29 00:00:00.000000 -0000"), 0};
- check_time (ts, do_print);
-
- ts = {gnc_iso8601_to_time64_gmt ("1979-02-28 00:00:00.000000 -0000"), 0};
- check_time (ts, do_print);
-
- ts = {gnc_iso8601_to_time64_gmt ("1990-02-28 00:00:00.000000 -0000"), 0};
- check_time (ts, do_print);
-
- ts = {gnc_iso8601_to_time64_gmt ("2000-02-29 00:00:00.000000 -0000"), 0};
- check_time (ts, do_print);
-
- ts = {gnc_iso8601_to_time64_gmt ("2004-02-29 00:00:00.000000 -0000"), 0};
- check_time (ts, do_print);
-
- ts = {gnc_iso8601_to_time64_gmt ("2008-02-29 00:00:00.000000 -0000"), 0};
- check_time (ts, do_print);
-
- ts = {gnc_iso8601_to_time64_gmt ("2008-02-29 00:01:00.000000 -0000"), 0};
- check_time (ts, do_print);
-
- ts = {gnc_iso8601_to_time64_gmt ("2008-02-29 02:02:00.000000 -0000"), 0};
- check_time (ts, do_print);
-
- ts = {gnc_iso8601_to_time64_gmt ("2008-02-28 23:23:23.000000 -0000"), 0};
- check_time (ts, do_print);
-
- /* Here's a date ten days after the 2038 rollover that should work
- if/when we support it. */
- ts.tv_nsec = 0;
- ts.tv_sec = (long long int) 0x7fffffff + 3600 * 24 * 10;
- check_time(ts, do_print);
-
- /* Various 'special' times. What makes these so special? */
- ts.tv_sec = 152098136;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1162088421;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 325659000 - 6500;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1143943200;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1603591171;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1738909365;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1603591171;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1143943200 - 1;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1143943200;
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1143943200 + (7 * 60 * 60);
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = 1143943200 + (8 * 60 * 60);
- ts.tv_nsec = 0;
- check_time (ts, do_print);
-
- ts.tv_sec = get_random_time ();
-
- for (i = 0; i < 10000; i++)
- {
- ts.tv_sec += 10800;
- if (!check_time (ts, FALSE))
- return;
- }
-
- for (i = 0; i < 5000; i++)
- {
- ts.tv_sec = get_random_time ();
-
- if (!check_time (ts, FALSE))
- return;
- }
-}
-
-int
-main (int argc, char **argv)
-{
- run_test ();
-
- success ("dates seem to work");
-
- print_test_results();
- exit(get_rv());
-}
diff --git a/libgnucash/engine/test/test-gnc-date.c b/libgnucash/engine/test/test-gnc-date.c
index c084b3d..2c38565 100644
--- a/libgnucash/engine/test/test-gnc-date.c
+++ b/libgnucash/engine/test/test-gnc-date.c
@@ -61,12 +61,12 @@ typedef struct
TZOffset off_zulu;
TZOffset off_05w;
TZOffset off_0840e;
- Timespec ts0;
- Timespec ts1;
- Timespec ts2;
- Timespec ts3;
- Timespec ts4;
- Timespec ts5;
+ time64 t0;
+ time64 t1;
+ time64 t2;
+ time64 t3;
+ time64 t4;
+ time64 t5;
} FixtureA;
static int
@@ -83,15 +83,15 @@ offset_string (TZOffset tz)
static void setup (FixtureA *f, gconstpointer pData)
{
- f->ts0 = (Timespec){gnc_time(NULL), 0};
+ f->t0 = gnc_time(NULL);
f->off_zulu = (TZOffset){0, 0};
f->off_05w = (TZOffset){-5, 0};
f->off_0840e = (TZOffset){8, 40};
- f->ts1 = (Timespec){607009407, 0}; //1989-3-27 13:43:27 Z
- f->ts2 = (Timespec){1604748079, 0}; //2020-11-7 06:21:19 -05:00
- f->ts3 = (Timespec){1341398864, 0}; //2012-07-04 19:27:44 +08:40
- f->ts4 = (Timespec){-261104801, 0}; //1961-09-22 17:53:19 -05:00
- f->ts5 = (Timespec){2873938879LL, 0}; //2061-01-25 23:21:19 -05:00
+ f->t1 = 607009407; //1989-3-27 13:43:27 Z
+ f->t2 = 1604748079; //2020-11-7 06:21:19 -05:00
+ f->t3 = 1341398864; //2012-07-04 19:27:44 +08:40
+ f->t4 = -261104801; //1961-09-22 17:53:19 -05:00
+ f->t5 = 2873938879LL; //2061-01-25 23:21:19 -05:00
}
typedef struct
@@ -492,217 +492,23 @@ test_gnc_setlocale (int category, gchar *locale)
"if a suffix is needed it's in the suffixes array.");
g_assert_not_reached ();
}
-/* timespec_normalize
-static void
-timespec_normalize(Timespec *t)// Local: 2:0:0
-*/
-static void
-test_timespec_normalize (void)
-{
- const int offset = 4396432;
- const int factor = 2;
- int base = 50;
- Timespec t = { base, factor * NANOS_PER_SECOND + offset };
- Testfuncs *tf = gnc_date_load_funcs ();
-
- tf->timespec_normalize (&t);
- g_assert_cmpint (t.tv_sec, ==, base + factor);
- g_assert_cmpint (t.tv_nsec, ==, offset);
-
- t.tv_sec = base;
- t.tv_nsec = - factor * NANOS_PER_SECOND - offset;
- tf->timespec_normalize (&t);
- g_assert_cmpint (t.tv_sec, ==, base - factor - 1);
- g_assert_cmpint (t.tv_nsec, ==, NANOS_PER_SECOND - offset);
-
- t.tv_sec = - base;
- t.tv_nsec = factor * NANOS_PER_SECOND + offset;
- tf->timespec_normalize (&t);
- g_assert_cmpint (t.tv_sec, ==, - base + factor + 1);
- g_assert_cmpint (t.tv_nsec, ==, - NANOS_PER_SECOND + offset);
-
- t.tv_sec = - base;
- t.tv_nsec = - factor * NANOS_PER_SECOND - offset;
- tf->timespec_normalize (&t);
- g_assert_cmpint (t.tv_sec, ==, - base - factor);
- g_assert_cmpint (t.tv_nsec, ==, - offset);
-
- g_slice_free (Testfuncs, tf);
-}
-
-
-/* timespec_equal
-gboolean
-timespec_equal (const Timespec *ta, const Timespec *tb)// C: 19 in 8 Local: 0:0:0
-*/
-static void
-test_timespec_equal (void)
-{
- const int sec_per_day = 24 * 3600;
- const int sec_per_mo = 30 * sec_per_day;
- const time64 sec_per_yr = 365 * sec_per_day;
- const int nsec1 = 439652, nsec2 = 132794892, nsec3 = 1132794892;
- const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day;
- const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day;
- const time64 secs3 = 72 * sec_per_yr + 2 * sec_per_mo + 26 * sec_per_day;
- Timespec ta = { secs1, nsec1 };
- Timespec tb = { secs2, nsec2 };
- Timespec tc = { secs1, nsec1 };
- Timespec td = { secs3, nsec1 };
- Timespec te = { secs1, nsec2 };
- Timespec tf = { secs2 - 1, nsec3 }; /* When normalized, equal to tb */
-
- g_assert (timespec_equal (&ta, &ta));
- g_assert (timespec_equal (&ta, &tc));
- g_assert (!timespec_equal (&ta, &tb));
- g_assert (!timespec_equal (&ta, &td));
- g_assert (!timespec_equal (&ta, &te));
- g_assert (timespec_equal (&tb, &tf));
-}
-/* timespec_cmp
-gint
-timespec_cmp(const Timespec *ta, const Timespec *tb)// C: 28 in 11 Local: 0:0:0
-*/
-static void
-test_timespec_cmp (void)
-{
- const int sec_per_day = 24 * 3600;
- const int sec_per_mo = 30 * sec_per_day;
- const time64 sec_per_yr = 365 * sec_per_day;
- const int nsec1 = 439652, nsec2 = 132794892, nsec3 = 1132794892;
- const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day;
- const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day;
- const time64 secs3 = 72 * sec_per_yr + 2 * sec_per_mo + 26 * sec_per_day;
- Timespec ta = { secs1, nsec1 };
- Timespec tb = { secs2, nsec2 };
- Timespec tc = { secs1, nsec1 };
- Timespec td = { secs3, nsec1 };
- Timespec te = { secs1, nsec2 };
- Timespec tf = { secs2 - 1, nsec3 }; /* When normalized, equal to tb */
- Timespec tg = { -secs2, nsec2 };
- Timespec th = { secs1, -nsec1 };
-
- g_assert_cmpint (timespec_cmp (&ta, &ta), ==, 0);
- g_assert_cmpint (timespec_cmp (&ta, &tc), ==, 0);
- g_assert_cmpint (timespec_cmp (&tf, &tb), ==, 0);
- g_assert_cmpint (timespec_cmp (&ta, &tb), ==, 1);
- g_assert_cmpint (timespec_cmp (&te, &ta), ==, 1);
- g_assert_cmpint (timespec_cmp (&td, &ta), ==, 1);
- g_assert_cmpint (timespec_cmp (&ta, &te), ==, -1);
- g_assert_cmpint (timespec_cmp (&ta, &tg), ==, 1);
- g_assert_cmpint (timespec_cmp (&th, &ta), ==, -1);
-
-}
-/* timespec_diff
-Timespec
-timespec_diff(const Timespec *ta, const Timespec *tb)// C: 4 in 1 Local: 0:0:0
-*/
-static void
-test_timespec_diff (void)
-{
- const gint sec_per_day = 24 * 3600;
- const gint sec_per_mo = 30 * sec_per_day;
- const time64 sec_per_yr = 365 * sec_per_day;
- const time64 nsec1 = 439652, nsec2 = 132794892, nsec3 = 1132794892;
- const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day;
- const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day;
- const time64 secs3 = 72 * sec_per_yr + 2 * sec_per_mo + 26 * sec_per_day;
- Timespec ta = { secs1, nsec1 };
- Timespec tb = { secs2, nsec2 };
- Timespec td = { secs3, nsec1 };
- Timespec te = { secs1, nsec2 };
- Timespec tf = { secs2 - 1, nsec3 }; /* When normalized, equal to tb */
- Timespec tg = { -secs2, nsec2 };
- Timespec th = { secs1, -nsec3 };
-
- Timespec tt = timespec_diff (&ta, &ta);
-
- g_assert_cmpint (tt.tv_sec, ==, 0);
- g_assert_cmpint (tt.tv_nsec, ==, 0);
-
- tt = timespec_diff (&ta, &tb);
- g_assert_cmpint (tt.tv_sec, ==, secs1 - secs2 - 1);
- g_assert_cmpint (tt.tv_nsec, ==, nsec1 - nsec2 + NANOS_PER_SECOND);
-
- tt = timespec_diff (&ta, &te);
- g_assert_cmpint (tt.tv_sec, ==, 0);
- g_assert_cmpint (tt.tv_nsec, ==, nsec1 - nsec2);
-
- tt = timespec_diff (&tb, &tf);
- g_assert_cmpint (tt.tv_sec, ==, 0);
- g_assert_cmpint (tt.tv_nsec, ==, 0);
-
- tt = timespec_diff (&tf, &th);
- if (sizeof (glong) > 4)
- {
- glong nsec_diff_norm = 2 * nsec3 - 2 * NANOS_PER_SECOND - NANOS_PER_SECOND;
- g_assert_cmpint (tt.tv_sec, ==, secs2 - secs1 + 2);
- g_assert_cmpint (tt.tv_nsec, ==, nsec_diff_norm);
- }
- else
- {
- g_assert_cmpint (tt.tv_sec, ==, secs2 - secs1 - 3);
- g_assert_cmpint (tt.tv_nsec, <, 0); /* Overflow nanosecs */
- }
- tt = timespec_diff (&tg, &td);
- g_assert_cmpint (tt.tv_sec, ==, -secs2 - secs3 + 1);
- g_assert_cmpint (tt.tv_nsec, ==, nsec2 - nsec1 - NANOS_PER_SECOND);
-
-}
-/* timespec_abs
-Timespec
-timespec_abs(const Timespec *t)// C: 4 in 1 Local: 0:0:0
-*/
-static void
-test_timespec_abs (void)
-{
- const int sec_per_day = 24 * 3600;
- const int sec_per_mo = 30 * sec_per_day;
- const int sec_per_yr = 365 * sec_per_day;
- const int nsec1 = 439652, nsec2 = 132794892, nsec3 = 1132794892;
- const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day;
- const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day;
- Timespec ta = { secs1, nsec1 };
- Timespec tf = { secs2 - 1, nsec3 }; /* When normalized, equal to tb */
- Timespec tg = { -secs2, nsec2 };
- Timespec th = { secs1, -nsec1 };
-
- Timespec tt = timespec_abs (&ta);
- g_assert_cmpint (tt.tv_sec, ==, secs1);
- g_assert_cmpint (tt.tv_nsec, ==, nsec1);
-
- tt = timespec_abs (&tf);
- g_assert_cmpint (tt.tv_sec, ==, secs2);
- g_assert_cmpint (tt.tv_nsec, ==, nsec2);
-
- tt = timespec_abs (&tg);
- g_assert_cmpint (tt.tv_sec, ==, secs2 - 1);
- g_assert_cmpint (tt.tv_nsec, ==, NANOS_PER_SECOND - nsec2);
-
- tt = timespec_abs (&th);
- g_assert_cmpint (tt.tv_sec, ==, secs1 - 1);
- g_assert_cmpint (tt.tv_nsec, ==, NANOS_PER_SECOND - nsec1);
-
-}
/* timespecCanonicalDayTime
-Timespec
-timespecCanonicalDayTime(Timespec t)// C: 12 in 5 SCM: 19 in 10 Local: 0:0:0
+time64
+time64CanonicalDayTime(time64 t)// C: 12 in 5 SCM: 19 in 10 Local: 0:0:0
*/
-static Timespec
-compute_noon_of_day (Timespec *ts)
-{
- Timespec nt = {0, 0};
- time_t secs = (time_t)ts->tv_sec;
- struct tm *time = localtime(&secs);
- time->tm_hour = 12;
- time->tm_min = 0;
- time->tm_sec = 0;
- nt.tv_sec = mktime(time);
- return nt;
+static time64
+compute_noon_of_day (const time64 *t)
+{
+ struct tm time;
+ gnc_localtime_r(t, &time);
+ time.tm_hour = 12;
+ time.tm_min = 0;
+ time.tm_sec = 0;
+ return gnc_mktime(&time);
}
static void
-test_timespecCanonicalDayTime (void)
+test_time64CanonicalDayTime (void)
{
const int sec_per_day = 24 * 3600;
const int sec_per_mo = 30 * sec_per_day;
@@ -713,21 +519,17 @@ test_timespecCanonicalDayTime (void)
const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo +
19 * sec_per_day + 21 * 3600 + 9 * 60 + 48; /* 1991-11-19 21:09:48 Z */
- Timespec t0 = { secs, 0 };
- Timespec ta = { secs1, 0 };
- Timespec tb = { secs2, 0 };
+ time64 n0 = compute_noon_of_day (&secs);
+ time64 na = compute_noon_of_day (&secs1);
+ time64 nb = compute_noon_of_day (&secs2);
- Timespec n0 = compute_noon_of_day (&t0);
- Timespec na = compute_noon_of_day (&ta);
- Timespec nb = compute_noon_of_day (&tb);
+ time64 r0 = time64CanonicalDayTime (secs);
+ time64 ra = time64CanonicalDayTime (secs1);
+ time64 rb = time64CanonicalDayTime (secs2);
- Timespec r0 = timespecCanonicalDayTime (t0);
- Timespec ra = timespecCanonicalDayTime (ta);
- Timespec rb = timespecCanonicalDayTime (tb);
-
- g_assert_cmpint (n0.tv_sec, ==, r0.tv_sec);
- g_assert_cmpint (na.tv_sec, ==, ra.tv_sec);
- g_assert_cmpint (nb.tv_sec, ==, rb.tv_sec);
+ g_assert_cmpint (n0, ==, r0);
+ g_assert_cmpint (na, ==, ra);
+ g_assert_cmpint (nb, ==, rb);
}
@@ -1339,74 +1141,6 @@ test_qof_print_date (void)
setlocale (LC_TIME, locale);
g_free (locale);
}
-/* gnc_print_date
-const char *
-gnc_print_date (Timespec ts)// C: 11 in 9 SCM: 166 in 59 Local: 0:0:0
-*/
-static void
-test_gnc_print_date (void)
-{
- gchar t_buff[MAX_DATE_LENGTH];
- gchar *locale = g_strdup (setlocale (LC_TIME, NULL));
- GDate *gd1 = g_date_new_dmy (23, 11, 1974);
- GDate *gd2 = g_date_new_dmy (2, 2, 1961);
- GDate *gd3 = g_date_new_dmy (16, 6, 2045);
- Timespec tm1 = gdate_to_timespec (*gd1);
- Timespec tm2 = gdate_to_timespec (*gd2);
- Timespec tm3 = gdate_to_timespec (*gd3);
-
-
- qof_date_format_set (QOF_DATE_FORMAT_UK);
- g_assert_cmpstr (gnc_print_date (tm1), ==, "23/11/1974");
- g_assert_cmpstr (gnc_print_date (tm2), ==, "02/02/1961");
- g_assert_cmpstr (gnc_print_date (tm3), ==, "16/06/2045");
-
- qof_date_format_set (QOF_DATE_FORMAT_CE);
- g_assert_cmpstr (gnc_print_date (tm1), ==, "23.11.1974");
- g_assert_cmpstr (gnc_print_date (tm2), ==, "02.02.1961");
- g_assert_cmpstr (gnc_print_date (tm3), ==, "16.06.2045");
-
- qof_date_format_set (QOF_DATE_FORMAT_US);
- g_assert_cmpstr (gnc_print_date (tm1), ==, "11/23/1974");
- g_assert_cmpstr (gnc_print_date (tm2), ==, "02/02/1961");
- g_assert_cmpstr (gnc_print_date (tm3), ==, "06/16/2045");
-
- qof_date_format_set (QOF_DATE_FORMAT_ISO);
- g_assert_cmpstr (gnc_print_date (tm1), ==, "1974-11-23");
- g_assert_cmpstr (gnc_print_date (tm2), ==, "1961-02-02");
- g_assert_cmpstr (gnc_print_date (tm3), ==, "2045-06-16");
-
- qof_date_format_set (QOF_DATE_FORMAT_LOCALE);
- test_gnc_setlocale (LC_TIME, "en_US");
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
- g_assert_cmpstr (gnc_print_date (tm1), ==, t_buff);
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
- g_assert_cmpstr (gnc_print_date (tm2), ==, t_buff);
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
- g_assert_cmpstr (gnc_print_date (tm3), ==, t_buff);
-
- test_gnc_setlocale (LC_TIME, "en_GB");
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
- g_assert_cmpstr (gnc_print_date (tm1), ==, t_buff);
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
- g_assert_cmpstr (gnc_print_date (tm2), ==, t_buff);
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
- g_assert_cmpstr (gnc_print_date (tm3), ==, t_buff);
-
- test_gnc_setlocale (LC_TIME, "fr_FR");
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
- g_assert_cmpstr (gnc_print_date (tm1), ==, t_buff);
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
- g_assert_cmpstr (gnc_print_date (tm2), ==, t_buff);
- g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
- g_assert_cmpstr (gnc_print_date (tm3), ==, t_buff);
-
- setlocale (LC_TIME, locale);
- g_free (locale);
- g_date_free (gd1);
- g_date_free (gd2);
- g_date_free (gd3);
-}
/* floordiv
static int
floordiv(int a, int b)// Local: 1:0:0
@@ -1622,9 +1356,9 @@ test_gnc_date_timestamp (void)
g_free (timestr);
}
-/* gnc_iso8601_to_timespec_gmt
-Timespec
-gnc_iso8601_to_timespec_gmt(const char *str)// C: 6 in 3 Local: 0:0:0
+/* gnc_iso8601_to_time64_gmt
+time64
+gnc_iso8601_to_time64_gmt(const char *str)// C: 6 in 3 Local: 0:0:0
*/
static gint
get_nanoseconds (GDateTime *gdt)
@@ -1642,44 +1376,43 @@ test_gnc_iso8601_to_time64_gmt (FixtureA *f, gconstpointer pData)
g_assert_cmpint (t, ==, 0);
t = gnc_iso8601_to_time64_gmt ("1989-03-27 13:43:27");
- g_assert_cmpint (t, ==, f->ts1.tv_sec);
+ g_assert_cmpint (t, ==, f->t1);
t = gnc_iso8601_to_time64_gmt ("2020-11-07 06:21:19 -05");
- g_assert_cmpint (t, ==, f->ts2.tv_sec);
+ g_assert_cmpint (t, ==, f->t2);
t = gnc_iso8601_to_time64_gmt ("2012-07-04 19:27:44.0+08:40");
- g_assert_cmpint (t, ==, f->ts3.tv_sec);
+ g_assert_cmpint (t, ==, f->t3);
t = gnc_iso8601_to_time64_gmt ("1961-09-22 17:53:19 -05");
- g_assert_cmpint (t, ==, f->ts4.tv_sec);
+ g_assert_cmpint (t, ==, f->t4);
t = gnc_iso8601_to_time64_gmt ("2061-01-25 23:21:19.0 -05:00");
- g_assert_cmpint (t, ==, f->ts5.tv_sec);
+ g_assert_cmpint (t, ==, f->t5);
}
-/* gnc_timespec_to_iso8601_buff
+/* gnc_time64_to_iso8601_buff
char *
-gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)// C: 18 in 7 Local: 0:0:0
+gnc_time64_to_iso8601_buff (time64 t, char * buff)// C: 18 in 7 Local: 0:0:0
*/
-static Timespec
-g_date_time_to_timespec (GDateTime *gdt)
+static time64
+g_date_time_to_time64 (GDateTime *gdt)
{
- Timespec t;
- t.tv_sec = g_date_time_to_unix (gdt);
- t.tv_nsec = g_date_time_get_microsecond (gdt) * 1000;
+ time64 t;
+ t = g_date_time_to_unix (gdt);
return t;
}
#define ISO8601_SIZE MAX_DATE_LENGTH + 4
static gchar*
-format_timestring (Timespec ts, TZOffset tz)
+format_timestring (time64 t, TZOffset tz)
{
- static const unsigned tzlen = MAX_DATE_LENGTH - 26;
- char *fmt = "%Y-%m-%d %H:%M:%S";
+ static const unsigned tzlen = MAX_DATE_LENGTH - 26;
+ char *fmt = "%Y-%m-%d %H:%M:%S %z";
struct tm tm;
- char buf[MAX_DATE_LENGTH], *retval;
+ char buf[MAX_DATE_LENGTH + 1];
char tzbuf[tzlen];
memset(tzbuf, 0, sizeof(tzbuf));
- gnc_localtime_r(&ts.tv_sec, &tm);
+ gnc_localtime_r(&t, &tm);
#if PLATFORM(WINDOWS)
strftime(tzbuf, sizeof(tzbuf), "%Z", &tm);
#else
@@ -1687,74 +1420,73 @@ format_timestring (Timespec ts, TZOffset tz)
#endif
memset (buf, 0, sizeof(buf));
strftime(buf, sizeof(buf), fmt, &tm);
- retval = g_strdup_printf ("%s.%06ld %s", buf, ts.tv_nsec / 1000, tzbuf);
- return retval;
+ return g_strdup(buf);
}
static void
-test_gnc_timespec_to_iso8601_buff (FixtureA *f, gconstpointer pData)
+test_gnc_time64_to_iso8601_buff (FixtureA *f, gconstpointer pData)
{
gchar buff[ISO8601_SIZE];
gchar *time_str;
- Timespec t = { 0, 0 };
+ time64 t = 0;
gchar *end;
memset (buff, 0, sizeof buff);
- end = gnc_timespec_to_iso8601_buff (t, NULL);
+ end = gnc_time64_to_iso8601_buff (t, NULL);
g_assert (end == NULL);
- end = gnc_timespec_to_iso8601_buff (f->ts0, buff);
+ end = gnc_time64_to_iso8601_buff (f->t0, buff);
g_assert_cmpint (end - buff, ==, strlen (buff));
- time_str = format_timestring (f->ts0, f->off_zulu);
+ time_str = format_timestring (f->t0, f->off_zulu);
g_assert_cmpstr (buff, ==, time_str);
g_free (time_str);
- end = gnc_timespec_to_iso8601_buff (f->ts1, buff);
- time_str = format_timestring (f->ts1, f->off_zulu);
+ end = gnc_time64_to_iso8601_buff (f->t1, buff);
+ time_str = format_timestring (f->t1, f->off_zulu);
g_assert_cmpstr (buff, ==, time_str);
g_free (time_str);
- end = gnc_timespec_to_iso8601_buff (f->ts2, buff);
- time_str = format_timestring (f->ts2, f->off_05w);
+ end = gnc_time64_to_iso8601_buff (f->t2, buff);
+ time_str = format_timestring (f->t2, f->off_05w);
g_assert_cmpstr (buff, ==, time_str);
g_free (time_str);
- end = gnc_timespec_to_iso8601_buff (f->ts3, buff);
- time_str = format_timestring (f->ts3, f->off_0840e);
+ end = gnc_time64_to_iso8601_buff (f->t3, buff);
+ time_str = format_timestring (f->t3, f->off_0840e);
g_assert_cmpstr (buff, ==, time_str);
g_free (time_str);
- end = gnc_timespec_to_iso8601_buff (f->ts4, buff);
- time_str = format_timestring (f->ts4, f->off_05w);
+ end = gnc_time64_to_iso8601_buff (f->t4, buff);
+ time_str = format_timestring (f->t4, f->off_05w);
g_assert_cmpstr (buff, ==, time_str);
g_free (time_str);
- end = gnc_timespec_to_iso8601_buff (f->ts5, buff);
- time_str = format_timestring (f->ts5, f->off_05w);
+ end = gnc_time64_to_iso8601_buff (f->t5, buff);
+ time_str = format_timestring (f->t5, f->off_05w);
g_assert_cmpstr (buff, ==, time_str);
g_free (time_str);
}
-/* gnc_dmy2timespec_internal
-static Timespec
-gnc_dmy2timespec_internal (int day, int month, int year, gboolean start_of_day)// Local: 2:0:0
+/* gnc_dmy2time64_internal
+static time64
+gnc_dmy2time64_internal (int day, int month, int year, gboolean start_of_day)// Local: 2:0:0
*/
/* static void
-test_gnc_dmy2timespec_internal (void)
+test_gnc_dmy2time64_internal (void)
{
}*/
-/* gnc_dmy2timespec
-Timespec
-gnc_dmy2timespec (int day, int month, int year)// C: 8 in 5 Local: 1:0:0
+/* gnc_dmy2time64
+time64
+gnc_dmy2time64 (int day, int month, int year)// C: 8 in 5 Local: 1:0:0
*/
static void
-test_gnc_dmy2timespec (FixtureB *f, gconstpointer pData)
+test_gnc_dmy2time64 (FixtureB *f, gconstpointer pData)
{
- gchar *msg1 = "[qof_dmy2timespec()] Date computation error from Y-M-D 1257-7-2: Time value is outside the supported year range.";
+ gchar *msg1 = "[qof_dmy2time64()] Date computation error from Y-M-D 1257-7-2: Time value is outside the supported year range.";
gint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL;
gchar *logdomain = "qof.engine";
TestErrorStruct check = {loglevel, logdomain, msg1, 0};
@@ -1769,27 +1501,27 @@ test_gnc_dmy2timespec (FixtureB *f, gconstpointer pData)
struct tm tm = {0, 0, 0, f->test[i].day, f->test[i].mon - 1,
f->test[i].yr - 1900, 0, 0, -1};
#endif
- Timespec r_t = gnc_dmy2timespec (f->test[i].day, f->test[i].mon,
+ time64 r_t = gnc_dmy2time64 (f->test[i].day, f->test[i].mon,
f->test[i].yr);
struct tm time1 = tm, time2 = tm;
int offset = gnc_mktime(&time1) - gnc_timegm(&time2);
if (f->test[i].secs == INT64_MAX)
- /* We use INT64_MAX as invalid timespec.secs.
+ /* We use INT64_MAX as invalid time64.secs.
* As we can't *add* to the max, we can ignore the tz offset in this case. */
- g_assert_cmpint (r_t.tv_sec, ==, INT64_MAX);
+ g_assert_cmpint (r_t, ==, INT64_MAX);
else
- g_assert_cmpint (r_t.tv_sec, ==, f->test[i].secs - offset);
+ g_assert_cmpint (r_t, ==, f->test[i].secs - offset);
}
g_log_set_default_handler (hdlr, 0);
}
-/* gnc_dmy2timespec_end
-Timespec
-gnc_dmy2timespec_end (int day, int month, int year)// C: 1 Local: 0:0:0
+/* gnc_dmy2time64_end
+time64
+gnc_dmy2time64_end (int day, int month, int year)// C: 1 Local: 0:0:0
*/
static void
-test_gnc_dmy2timespec_end (FixtureB *f, gconstpointer pData)
+test_gnc_dmy2time64_end (FixtureB *f, gconstpointer pData)
{
- gchar *msg1 = "[qof_dmy2timespec_end()] Date computation error from Y-M-D 1257-7-2: Time value is outside the supported year range.";
+ gchar *msg1 = "[qof_dmy2time64_end()] Date computation error from Y-M-D 1257-7-2: Time value is outside the supported year range.";
gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
gchar *logdomain = "qof.engine";
TestErrorStruct check = {loglevel, logdomain, msg1, 0};
@@ -1804,15 +1536,15 @@ test_gnc_dmy2timespec_end (FixtureB *f, gconstpointer pData)
struct tm tm = {59, 59, 23, f->test[i].day, f->test[i].mon - 1,
f->test[i].yr - 1900, 0, 0, -1};
#endif
- Timespec r_t = gnc_dmy2timespec_end (f->test[i].day, f->test[i].mon,
+ time64 r_t = gnc_dmy2time64_end (f->test[i].day, f->test[i].mon,
f->test[i].yr);
int offset = gnc_mktime(&tm) - gnc_timegm(&tm);
if (f->test[i].secs == INT64_MAX)
- /* We use INT64_MAX as invalid timespec.secs.
+ /* We use INT64_MAX as invalid time64.secs.
* As we can't *add* to the max, we can ignore the tz offset in this case. */
- g_assert_cmpint (r_t.tv_sec, ==, INT64_MAX);
+ g_assert_cmpint (r_t, ==, INT64_MAX);
else
- g_assert_cmpint (r_t.tv_sec, ==, f->test[i].secs - offset);
+ g_assert_cmpint (r_t, ==, f->test[i].secs - offset);
}
g_log_set_default_handler (hdlr, 0);
}
@@ -1833,18 +1565,18 @@ offset_adjust(GDateTime *gdt)
return new_gdt;
}
-/*gnc_dmy2timespec_neutral*/
+/*gnc_dmy2time64_neutral*/
static void
-test_gnc_dmy2timespec_neutral (FixtureB *f, gconstpointer pData)
+test_gnc_dmy2time64_neutral (FixtureB *f, gconstpointer pData)
{
- gchar *msg1 = "[qof_dmy2timespec_neutral()] Date computation error from Y-M-D 1257-7-2: Time value is outside the supported year range.";
+ gchar *msg1 = "[qof_dmy2time64_neutral()] Date computation error from Y-M-D 1257-7-2: Time value is outside the supported year range.";
gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
gchar *logdomain = "qof.engine";
TestErrorStruct check = {loglevel, logdomain, msg1, 0};
GLogFunc hdlr = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
struct tm check_tz;
gnc_localtime_r(&(f->test[0].secs), &check_tz);
- /* gnc_dmy2timespec_neutral returns the timespec for 10:59:00 Z
+ /* gnc_dmy2time64_neutral returns the time64 for 10:59:00 Z
* for timezones in the range -11 to +13. If the timezone being
* tested is outside that range then the day of the month will be
* different from the one in the test fixture and we skip the
@@ -1855,10 +1587,10 @@ test_gnc_dmy2timespec_neutral (FixtureB *f, gconstpointer pData)
g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
for (int i = 0; i < sizeof(f->test)/sizeof(TimeMap); ++i)
{
- Timespec r_t = gnc_dmy2timespec_neutral (f->test[i].day, f->test[i].mon,
+ time64 r_t = gnc_dmy2time64_neutral (f->test[i].day, f->test[i].mon,
f->test[i].yr);
- g_assert_cmpint (r_t.tv_sec, ==, f->test[i].secs);
+ g_assert_cmpint (r_t, ==, f->test[i].secs);
}
}
g_log_set_default_handler (hdlr, 0);
@@ -1872,83 +1604,59 @@ gnc_timezone (const struct tm *tm)// C: 5 in 2 Local: 2:0:0
test_gnc_timezone (void)
{
}*/
-/* timespecFromtime64
-void
-timespecFromtime64( Timespec *ts, time64 t )// C: 22 in 11 Local: 0:0:0
-*/
-/* static void
-test_timespecFromtime64 (void)
-{
-}*/
-/* timespec_now
-Timespec
-timespec_now()// C: 2 in 2 Local: 0:0:0
-*/
-/* static void
-test_timespec_now (void)
-{
-}*/
-/* timespecTotime64
-time64
-timespecTotime64 (Timespec ts)// C: 10 in 6 Local: 1:0:0
-*/
-/* static void
-test_timespecTotime64 (void)
-{
-}*/
-/* timespec_to_gdate
-GDate timespec_to_gdate (Timespec ts)// C: 5 in 4 Local: 0:0:0
+/* time64_to_gdate
+GDate time64_to_gdate (time64 t)// C: 5 in 4 Local: 0:0:0
*/
static void
-test_timespec_to_gdate (FixtureA *f, gconstpointer pData)
+test_time64_to_gdate (FixtureA *f, gconstpointer pData)
{
GDate date1, date2;
struct tm tm;
g_date_clear (&date2, 1);
- date1 = timespec_to_gdate (f->ts0);
- gnc_localtime_r(&f->ts0.tv_sec, &tm);
+ date1 = time64_to_gdate (f->t0);
+ gnc_localtime_r(&f->t0, &tm);
g_date_set_dmy (&date2, tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
g_assert_cmpint (g_date_get_julian (&date1), ==,
g_date_get_julian (&date2));
- date1 = timespec_to_gdate (f->ts1);
- gnc_localtime_r(&f->ts1.tv_sec, &tm);
+ date1 = time64_to_gdate (f->t1);
+ gnc_localtime_r(&f->t1, &tm);
g_date_set_dmy (&date2, tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
g_assert_cmpint (g_date_get_julian (&date1), ==,
g_date_get_julian (&date2));
- date1 = timespec_to_gdate (f->ts2);
- gnc_localtime_r(&f->ts2.tv_sec, &tm);
+ date1 = time64_to_gdate (f->t2);
+ gnc_localtime_r(&f->t2, &tm);
g_date_set_dmy (&date2, tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
g_assert_cmpint (g_date_get_julian (&date1), ==,
g_date_get_julian (&date2));
- date1 = timespec_to_gdate (f->ts3);
- gnc_localtime_r(&f->ts3.tv_sec, &tm);
+ date1 = time64_to_gdate (f->t3);
+ gnc_localtime_r(&f->t3, &tm);
g_date_set_dmy (&date2, tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
g_assert_cmpint (g_date_get_julian (&date1), ==,
g_date_get_julian (&date2));
- date1 = timespec_to_gdate (f->ts4);
- gnc_localtime_r(&f->ts4.tv_sec, &tm);
+ date1 = time64_to_gdate (f->t4);
+ gnc_localtime_r(&f->t4, &tm);
g_date_set_dmy (&date2, tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
g_assert_cmpint (g_date_get_julian (&date1), ==,
g_date_get_julian (&date2));
- date1 = timespec_to_gdate (f->ts5);
- gnc_localtime_r(&f->ts5.tv_sec, &tm);
+ date1 = time64_to_gdate (f->t5);
+ gnc_localtime_r(&f->t5, &tm);
g_date_set_dmy (&date2, tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
g_assert_cmpint (g_date_get_julian (&date1), ==,
g_date_get_julian (&date2));
}
-/* gdate_to_timespec
-Timespec gdate_to_timespec (GDate d)// C: 7 in 6 Local: 0:0:0
+/* gdate_to_time64
+time64 gdate_to_time64 (GDate d)// C: 7 in 6 Local: 0:0:0
*/
static void
-test_gdate_to_timespec (FixtureB *f, gconstpointer pData)
+test_gdate_to_time64 (FixtureB *f, gconstpointer pData)
{
gchar *msg = "g_date_set_dmy: assertion 'g_date_valid_dmy (day, m, y)' failed";
@@ -1958,7 +1666,7 @@ test_gdate_to_timespec (FixtureB *f, gconstpointer pData)
GLogFunc hdlr = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
struct tm check_tz;
gnc_localtime_r(&(f->test[0].secs), &check_tz);
- /* gdate_to_timespec returns the timespec for 10:59:00 Z
+ /* gdate_to_time64 returns the time64 for 10:59:00 Z
* for timezones in the range -11 to +13. If the timezone being
* tested is outside that range then the day of the month will be
* different from the one in the test fixture and we skip the
@@ -1970,15 +1678,15 @@ test_gdate_to_timespec (FixtureB *f, gconstpointer pData)
for (int i = 0; i < sizeof(f->test)/sizeof(TimeMap); ++i)
{
GDate gd, gd2;
- Timespec r_t;
+ time64 r_t;
g_date_clear(&gd, 1);
g_date_clear(&gd2, 1);
g_date_set_dmy(&gd, f->test[i].day, f->test[i].mon, f->test[i].yr);
- r_t = gdate_to_timespec(gd);
- g_assert_cmpint (r_t.tv_sec, ==, f->test[i].secs);
+ r_t = gdate_to_time64(gd);
+ g_assert_cmpint (r_t, ==, f->test[i].secs);
if (f->test[i].secs < INT64_MAX)
{
- gd2 = timespec_to_gdate(r_t);
+ gd2 = time64_to_gdate(r_t);
g_assert (g_date_compare (&gd2, &gd) == 0);
}
}
@@ -2020,40 +1728,40 @@ test_gnc_time64_get_day_start (FixtureA *f, gconstpointer pData)
struct tm tm;
time64 t_time, r_time;
- gnc_localtime_r(&f->ts0.tv_sec, &tm);
+ gnc_localtime_r(&f->t0, &tm);
tm_day_begin(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_start (f->ts0.tv_sec);
+ r_time = gnc_time64_get_day_start (f->t0);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts1.tv_sec, &tm);
+ gnc_localtime_r(&f->t1, &tm);
tm_day_begin(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_start (f->ts1.tv_sec);
+ r_time = gnc_time64_get_day_start (f->t1);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts2.tv_sec, &tm);
+ gnc_localtime_r(&f->t2, &tm);
tm_day_begin(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_start (f->ts2.tv_sec);
+ r_time = gnc_time64_get_day_start (f->t2);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts3.tv_sec, &tm);
+ gnc_localtime_r(&f->t3, &tm);
tm_day_begin(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_start (f->ts3.tv_sec);
+ r_time = gnc_time64_get_day_start (f->t3);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts4.tv_sec, &tm);
+ gnc_localtime_r(&f->t4, &tm);
tm_day_begin(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_start (f->ts4.tv_sec);
+ r_time = gnc_time64_get_day_start (f->t4);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts5.tv_sec, &tm);
+ gnc_localtime_r(&f->t5, &tm);
tm_day_begin(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_start (f->ts5.tv_sec);
+ r_time = gnc_time64_get_day_start (f->t5);
g_assert_cmpint (t_time, ==, r_time);
}
@@ -2075,40 +1783,40 @@ test_gnc_time64_get_day_end (FixtureA *f, gconstpointer pData)
struct tm tm;
time64 t_time, r_time;
- gnc_localtime_r(&f->ts0.tv_sec, &tm);
+ gnc_localtime_r(&f->t0, &tm);
tm_day_end(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_end (f->ts0.tv_sec);
+ r_time = gnc_time64_get_day_end (f->t0);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts1.tv_sec, &tm);
+ gnc_localtime_r(&f->t1, &tm);
tm_day_end(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_end (f->ts1.tv_sec);
+ r_time = gnc_time64_get_day_end (f->t1);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts2.tv_sec, &tm);
+ gnc_localtime_r(&f->t2, &tm);
tm_day_end(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_end (f->ts2.tv_sec);
+ r_time = gnc_time64_get_day_end (f->t2);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts3.tv_sec, &tm);
+ gnc_localtime_r(&f->t3, &tm);
tm_day_end(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_end (f->ts3.tv_sec);
+ r_time = gnc_time64_get_day_end (f->t3);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts4.tv_sec, &tm);
+ gnc_localtime_r(&f->t4, &tm);
tm_day_end(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_end (f->ts4.tv_sec);
+ r_time = gnc_time64_get_day_end (f->t4);
g_assert_cmpint (t_time, ==, r_time);
- gnc_localtime_r(&f->ts5.tv_sec, &tm);
+ gnc_localtime_r(&f->t5, &tm);
tm_day_end(&tm);
t_time = gnc_mktime(&tm);
- r_time = gnc_time64_get_day_end (f->ts5.tv_sec);
+ r_time = gnc_time64_get_day_end (f->t5);
g_assert_cmpint (t_time, ==, r_time);
}
@@ -2149,26 +1857,26 @@ gnc_dow_abbrev(gchar *buf, int buf_len, int dow)// C: 4 in 2 Local: 0:0:0
test_gnc_dow_abbrev (void)
{
}*/
-/* timespec_boxed_copy_func
+/* time64_boxed_copy_func
static gpointer
-timespec_boxed_copy_func( gpointer in_timespec )// Local: 0:1:0
+time64_boxed_copy_func( gpointer in_time64 )// Local: 0:1:0
*/
/* static void
-test_timespec_boxed_copy_func (void)
+test_time64_boxed_copy_func (void)
{
}*/
-/* timespec_boxed_free_func
+/* time64_boxed_free_func
static void
-timespec_boxed_free_func( gpointer in_timespec )// Local: 0:1:0
+time64_boxed_free_func( gpointer in_time64 )// Local: 0:1:0
*/
/* static void
-test_timespec_boxed_free_func (void)
+test_time64_boxed_free_func (void)
{
}*/
// Not Used
-/* timespec_get_type
+/* time64_get_type
GType
-timespec_get_type( void )// Local: 0:0:0
+time64_get_type( void )// Local: 0:0:0
*/
@@ -2187,12 +1895,7 @@ test_suite_gnc_date (void)
GNC_TEST_ADD_FUNC (suitename, "gnc date string to dateformat", test_gnc_date_string_to_dateformat);
GNC_TEST_ADD_FUNC (suitename, "gnc date monthformat to string", test_gnc_date_monthformat_to_string);
GNC_TEST_ADD_FUNC (suitename, "gnc date string to monthformat", test_gnc_date_string_to_monthformat);
- GNC_TEST_ADD_FUNC (suitename, "timespec normalize", test_timespec_normalize);
- GNC_TEST_ADD_FUNC (suitename, "timespec equal", test_timespec_equal);
- GNC_TEST_ADD_FUNC (suitename, "timespec cmp", test_timespec_cmp);
- GNC_TEST_ADD_FUNC (suitename, "timespec diff", test_timespec_diff);
- GNC_TEST_ADD_FUNC (suitename, "timespec abs", test_timespec_abs);
- GNC_TEST_ADD_FUNC (suitename, "timespecCanonicalDayTime", test_timespecCanonicalDayTime);
+ GNC_TEST_ADD_FUNC (suitename, "time64CanonicalDayTime", test_time64CanonicalDayTime);
GNC_TEST_ADD_FUNC (suitename, "date get last mday", test_gnc_date_get_last_mday);
GNC_TEST_ADD_FUNC (suitename, "qof date format set", test_qof_date_format_set);
// GNC_TEST_ADD_FUNC (suitename, "qof date completion set", test_qof_date_completion_set);
@@ -2200,7 +1903,6 @@ test_suite_gnc_date (void)
GNC_TEST_ADD_FUNC (suitename, "qof print date buff", test_qof_print_date_buff);
GNC_TEST_ADD_FUNC (suitename, "qof print gdate", test_qof_print_gdate);
GNC_TEST_ADD_FUNC (suitename, "qof print date", test_qof_print_date);
- GNC_TEST_ADD_FUNC (suitename, "gnc print date", test_gnc_print_date);
// GNC_TEST_ADD_FUNC (suitename, "floordiv", test_floordiv);
// GNC_TEST_ADD_FUNC (suitename, "qof scan date internal", test_qof_scan_date_internal);
GNC_TEST_ADD_FUNC (suitename, "qof scan date", test_qof_scan_date);
@@ -2211,18 +1913,15 @@ test_suite_gnc_date (void)
// GNC_TEST_ADD_FUNC (suitename, "qof strftime", test_qof_strftime);
GNC_TEST_ADD_FUNC (suitename, "gnc_date_timestamp", test_gnc_date_timestamp);
GNC_TEST_ADD (suitename, "gnc iso8601 to time64 gmt", FixtureA, NULL, setup, test_gnc_iso8601_to_time64_gmt, NULL);
- GNC_TEST_ADD (suitename, "gnc timespec to iso8601 buff", FixtureA, NULL, setup, test_gnc_timespec_to_iso8601_buff, NULL);
-// GNC_TEST_ADD_FUNC (suitename, "gnc dmy2timespec internal", test_gnc_dmy2timespec_internal);
+ GNC_TEST_ADD (suitename, "gnc time64 to iso8601 buff", FixtureA, NULL, setup, test_gnc_time64_to_iso8601_buff, NULL);
+// GNC_TEST_ADD_FUNC (suitename, "gnc dmy2time64 internal", test_gnc_dmy2time64_internal);
- GNC_TEST_ADD (suitename, "gnc dmy2timespec", FixtureB, NULL, setup_begin, test_gnc_dmy2timespec, NULL);
- GNC_TEST_ADD (suitename, "gnc dmy2timespec end", FixtureB, NULL, setup_end, test_gnc_dmy2timespec_end, NULL);
- GNC_TEST_ADD (suitename, "gnc dmy2timespec Neutral", FixtureB, NULL, setup_neutral, test_gnc_dmy2timespec_neutral, NULL);
+ GNC_TEST_ADD (suitename, "gnc dmy2time64", FixtureB, NULL, setup_begin, test_gnc_dmy2time64, NULL);
+ GNC_TEST_ADD (suitename, "gnc dmy2time64 end", FixtureB, NULL, setup_end, test_gnc_dmy2time64_end, NULL);
+ GNC_TEST_ADD (suitename, "gnc dmy2time64 Neutral", FixtureB, NULL, setup_neutral, test_gnc_dmy2time64_neutral, NULL);
// GNC_TEST_ADD_FUNC (suitename, "gnc timezone", test_gnc_timezone);
-// GNC_TEST_ADD_FUNC (suitename, "timespecFromTime t", test_timespecFromtime64);
-// GNC_TEST_ADD_FUNC (suitename, "timespec now", test_timespec_now);
-// GNC_TEST_ADD_FUNC (suitename, "timespecToTime t", test_timespecTotime64);
- GNC_TEST_ADD (suitename, "timespec to gdate", FixtureA, NULL, setup, test_timespec_to_gdate, NULL);
- GNC_TEST_ADD (suitename, "gdate to timespec", FixtureB, NULL, setup_neutral, test_gdate_to_timespec, NULL);
+ GNC_TEST_ADD (suitename, "time64 to gdate", FixtureA, NULL, setup, test_time64_to_gdate, NULL);
+ GNC_TEST_ADD (suitename, "gdate to time64", FixtureB, NULL, setup_neutral, test_gdate_to_time64, NULL);
// GNC_TEST_ADD_FUNC (suitename, "gnc tm get day start", test_gnc_tm_get_day_start);
// GNC_TEST_ADD_FUNC (suitename, "gnc tm get day end", test_gnc_tm_get_day_end);
GNC_TEST_ADD (suitename, "gnc time64 get day start", FixtureA, NULL, setup, test_gnc_time64_get_day_start, NULL);
@@ -2231,7 +1930,7 @@ test_suite_gnc_date (void)
// GNC_TEST_ADD_FUNC (suitename, "gnc timet get today start", test_gnc_time64_get_today_start);
// GNC_TEST_ADD_FUNC (suitename, "gnc timet get today end", test_gnc_time64_get_today_end);
// GNC_TEST_ADD_FUNC (suitename, "gnc dow abbrev", test_gnc_dow_abbrev);
-// GNC_TEST_ADD_FUNC (suitename, "timespec boxed copy func", test_timespec_boxed_copy_func);
-// GNC_TEST_ADD_FUNC (suitename, "timespec boxed free func", test_timespec_boxed_free_func);
+// GNC_TEST_ADD_FUNC (suitename, "time64 boxed copy func", test_time64_boxed_copy_func);
+// GNC_TEST_ADD_FUNC (suitename, "time64 boxed free func", test_time64_boxed_free_func);
g_time_zone_unref(tz);
}
commit 20f6e4e690cf9d29a9181f5cb7f628eb38179bad
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Aug 4 14:18:39 2018 -0700
Remove Timespec from the SQL backend.
diff --git a/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp b/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp
index 4c0d7ac..534c185 100644
--- a/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp
+++ b/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp
@@ -138,7 +138,7 @@ setup_memory (Fixture* fixture, gconstpointer pData)
frame->set ({"int64-val"}, new KvpValue (INT64_C (100)));
frame->set ({"double-val"}, new KvpValue (3.14159));
frame->set ({"numeric-val"}, new KvpValue (gnc_numeric_zero ()));
- frame->set ({"timespec-val"}, new KvpValue (gnc_time(nullptr)));
+ frame->set ({"time-val"}, new KvpValue (gnc_time(nullptr)));
frame->set ({"string-val"}, new KvpValue ("abcdefghijklmnop"));
auto guid = qof_instance_get_guid (QOF_INSTANCE (acct1));
frame->set ({"guid-val"}, new KvpValue (const_cast<GncGUID*> (guid_copy (
diff --git a/libgnucash/backend/sql/gnc-entry-sql.cpp b/libgnucash/backend/sql/gnc-entry-sql.cpp
index f68e210..b22bc55 100644
--- a/libgnucash/backend/sql/gnc-entry-sql.cpp
+++ b/libgnucash/backend/sql/gnc-entry-sql.cpp
@@ -70,9 +70,9 @@ static void entry_set_bill (gpointer pObject, gpointer val);
static EntryVec col_table
({
gnc_sql_make_table_entry<CT_GUID>("guid", 0, COL_NNUL | COL_PKEY, "guid"),
- gnc_sql_make_table_entry<CT_TIME64>("date", 0, COL_NNUL, ENTRY_DATE,
+ gnc_sql_make_table_entry<CT_TIME>("date", 0, COL_NNUL, ENTRY_DATE,
true),
- gnc_sql_make_table_entry<CT_TIME64>("date_entered", 0, 0,
+ gnc_sql_make_table_entry<CT_TIME>("date_entered", 0, 0,
ENTRY_DATE_ENTERED, true),
gnc_sql_make_table_entry<CT_STRING>(
"description", MAX_DESCRIPTION_LEN, 0, "description"),
diff --git a/libgnucash/backend/sql/gnc-invoice-sql.cpp b/libgnucash/backend/sql/gnc-invoice-sql.cpp
index 29a18fd..b134bc7 100644
--- a/libgnucash/backend/sql/gnc-invoice-sql.cpp
+++ b/libgnucash/backend/sql/gnc-invoice-sql.cpp
@@ -67,9 +67,9 @@ static EntryVec col_table
gnc_sql_make_table_entry<CT_GUID>("guid", 0, COL_NNUL | COL_PKEY, "guid"),
gnc_sql_make_table_entry<CT_STRING>("id", MAX_ID_LEN, COL_NNUL, INVOICE_ID,
true),
- gnc_sql_make_table_entry<CT_TIME64>("date_opened", 0, 0, INVOICE_OPENED,
+ gnc_sql_make_table_entry<CT_TIME>("date_opened", 0, 0, INVOICE_OPENED,
true),
- gnc_sql_make_table_entry<CT_TIME64>("date_posted", 0, 0, INVOICE_POSTED,
+ gnc_sql_make_table_entry<CT_TIME>("date_posted", 0, 0, INVOICE_POSTED,
true),
gnc_sql_make_table_entry<CT_STRING>("notes", MAX_NOTES_LEN, COL_NNUL,
"notes"),
diff --git a/libgnucash/backend/sql/gnc-order-sql.cpp b/libgnucash/backend/sql/gnc-order-sql.cpp
index 50cde38..453a7a4 100644
--- a/libgnucash/backend/sql/gnc-order-sql.cpp
+++ b/libgnucash/backend/sql/gnc-order-sql.cpp
@@ -66,9 +66,9 @@ static EntryVec col_table
gnc_sql_make_table_entry<CT_STRING>(
"reference", MAX_REFERENCE_LEN, COL_NNUL, "reference"),
gnc_sql_make_table_entry<CT_BOOLEAN>("active", 0, COL_NNUL, "order"),
- gnc_sql_make_table_entry<CT_TIMESPEC>("date_opened", 0, COL_NNUL,
+ gnc_sql_make_table_entry<CT_TIME>("date_opened", 0, COL_NNUL,
"date-opened"),
- gnc_sql_make_table_entry<CT_TIMESPEC>("date_closed", 0, COL_NNUL,
+ gnc_sql_make_table_entry<CT_TIME>("date_closed", 0, COL_NNUL,
"date-closed"),
gnc_sql_make_table_entry<CT_OWNERREF>("owner", 0, COL_NNUL,
ORDER_OWNER, true),
diff --git a/libgnucash/backend/sql/gnc-price-sql.cpp b/libgnucash/backend/sql/gnc-price-sql.cpp
index 6a12872..1fcc5d5 100644
--- a/libgnucash/backend/sql/gnc-price-sql.cpp
+++ b/libgnucash/backend/sql/gnc-price-sql.cpp
@@ -63,7 +63,7 @@ static const EntryVec col_table
"commodity"),
gnc_sql_make_table_entry<CT_COMMODITYREF>("currency_guid", 0, COL_NNUL,
"currency"),
- gnc_sql_make_table_entry<CT_TIMESPEC>("date", 0, COL_NNUL, "date"),
+ gnc_sql_make_table_entry<CT_TIME>("date", 0, COL_NNUL, "date"),
gnc_sql_make_table_entry<CT_STRING>("source", PRICE_MAX_SOURCE_LEN, 0,
"source"),
gnc_sql_make_table_entry<CT_STRING>("type", PRICE_MAX_TYPE_LEN, 0, "type"),
diff --git a/libgnucash/backend/sql/gnc-slots-sql.cpp b/libgnucash/backend/sql/gnc-slots-sql.cpp
index 6cb48ff..cf1fc7b 100644
--- a/libgnucash/backend/sql/gnc-slots-sql.cpp
+++ b/libgnucash/backend/sql/gnc-slots-sql.cpp
@@ -90,8 +90,8 @@ static gpointer get_string_val (gpointer pObject);
static void set_string_val (gpointer pObject, gpointer pValue);
static gpointer get_double_val (gpointer pObject);
static void set_double_val (gpointer pObject, gpointer pValue);
-static Timespec get_timespec_val (gpointer pObject);
-static void set_timespec_val (gpointer pObject, Timespec *ts);
+static time64 get_time_val (gpointer pObject);
+static void set_time_val (gpointer pObject, time64 t);
static gpointer get_guid_val (gpointer pObject);
static void set_guid_val (gpointer pObject, gpointer pValue);
static gnc_numeric get_numeric_val (gpointer pObject);
@@ -112,7 +112,7 @@ enum
int64_val_col,
string_val_col,
double_val_col,
- timespec_val_col,
+ time_val_col,
guid_val_col,
numeric_val_col,
gdate_val_col
@@ -140,9 +140,9 @@ static const EntryVec col_table
gnc_sql_make_table_entry<CT_DOUBLE>("double_val", 0, 0,
(QofAccessFunc)get_double_val,
set_double_val),
- gnc_sql_make_table_entry<CT_TIMESPEC>("timespec_val", 0, 0,
- (QofAccessFunc)get_timespec_val,
- (QofSetterFunc)set_timespec_val),
+ gnc_sql_make_table_entry<CT_TIME>("time_val", 0, 0,
+ (QofAccessFunc)get_time_val,
+ (QofSetterFunc)set_time_val),
gnc_sql_make_table_entry<CT_GUID>("guid_val", 0, 0,
(QofAccessFunc)get_guid_val,
set_guid_val),
@@ -390,24 +390,24 @@ set_double_val (gpointer pObject, gpointer pValue)
set_slot_from_value (pInfo, value);
}
-static Timespec
-get_timespec_val (gpointer pObject)
+static time64
+get_time_val (gpointer pObject)
{
slot_info_t* pInfo = (slot_info_t*)pObject;
- g_return_val_if_fail (pObject != NULL, gnc_dmy2timespec (1, 1, 1970));
+ g_return_val_if_fail (pObject != NULL, 0);
//if( kvp_value_get_type( pInfo->pKvpValue ) == KvpValue::Type::TIME64 ) {
auto t = pInfo->pKvpValue->get<Time64> ();
- return {t.t, 0};
+ return t.t;
}
static void
-set_timespec_val (gpointer pObject, Timespec *ts)
+set_time_val (gpointer pObject, time64 time)
{
slot_info_t* pInfo = (slot_info_t*)pObject;
KvpValue* value = NULL;
- Time64 t{ts->tv_sec};
+ Time64 t{time};
g_return_if_fail (pObject != NULL);
if (pInfo->value_type != KvpValue::Type::TIME64) return;
diff --git a/libgnucash/backend/sql/gnc-sql-backend.hpp b/libgnucash/backend/sql/gnc-sql-backend.hpp
index bde8700..051b3ed 100644
--- a/libgnucash/backend/sql/gnc-sql-backend.hpp
+++ b/libgnucash/backend/sql/gnc-sql-backend.hpp
@@ -246,7 +246,7 @@ protected:
bool m_loading; /**< We are performing an initial load */
bool m_in_query; /**< We are processing a query */
bool m_is_pristine_db; /**< Are we saving to a new pristine db? */
- const char* m_timespec_format = nullptr; /**< Server-specific date-time string format */
+ const char* m_time_format = nullptr; /**< Server-specific date-time string format */
VersionVec m_versions; /**< Version number for each table */
private:
bool write_account_tree(Account*);
diff --git a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
index 6daed1d..e48c165 100644
--- a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
+++ b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
@@ -367,29 +367,22 @@ GncSqlColumnTableEntryImpl<CT_GUID>::add_to_query(QofIdTypeConst obj_name,
}
}
/* ----------------------------------------------------------------- */
-typedef Timespec (*TimespecAccessFunc) (const gpointer);
-typedef void (*TimespecSetterFunc) (const gpointer, Timespec*);
-
-#define TIMESPEC_COL_SIZE (4+3+3+3+3+3)
+typedef time64 (*Time64AccessFunc) (const gpointer);
+typedef void (*Time64SetterFunc) (const gpointer, time64);
+constexpr int TIME_COL_SIZE = 4 + 3 + 3 + 3 + 3 + 3;
template<> void
-GncSqlColumnTableEntryImpl<CT_TIMESPEC>::load (const GncSqlBackend* sql_be,
- GncSqlRow& row,
- QofIdTypeConst obj_name,
- gpointer pObject) const noexcept
+GncSqlColumnTableEntryImpl<CT_TIME>::load (const GncSqlBackend* sql_be,
+ GncSqlRow& row,
+ QofIdTypeConst obj_name,
+ gpointer pObject)
+ const noexcept
{
-
- Timespec ts = {0, 0};
- gboolean isOK = FALSE;
-
-
- g_return_if_fail (pObject != NULL);
+ time64 t{0};
g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
-
try
{
- auto val = row.get_time64_at_col(m_col_name);
- timespecFromTime64 (&ts, val);
+ t = row.get_time64_at_col (m_col_name);
}
catch (std::invalid_argument&)
{
@@ -397,121 +390,64 @@ GncSqlColumnTableEntryImpl<CT_TIMESPEC>::load (const GncSqlBackend* sql_be,
{
auto val = row.get_string_at_col(m_col_name);
GncDateTime time(val);
- ts.tv_sec = static_cast<time64>(time);
+ t = static_cast<time64>(time);
}
catch (const std::invalid_argument& err)
{
if (strcmp(err.what(), "Column empty.") != 0)
{
- auto val = row.get_string_at_col(m_col_name);
+ auto val = row.get_string_at_col (m_col_name);
PWARN("An invalid date %s was found in your database."
"It has been set to 1 January 1970.", val.c_str());
}
- ts.tv_sec = 0;
}
}
- set_parameter(pObject, &ts,
- reinterpret_cast<TimespecSetterFunc>(get_setter(obj_name)),
- m_gobj_param_name);
- }
-
-template<> void
-GncSqlColumnTableEntryImpl<CT_TIMESPEC>::add_to_table(ColVec& vec) const noexcept
-{
- GncSqlColumnInfo info{*this, BCT_DATETIME, TIMESPEC_COL_SIZE, FALSE};
- vec.emplace_back(std::move(info));
-}
-
-template<> void
-GncSqlColumnTableEntryImpl<CT_TIMESPEC>::add_to_query(QofIdTypeConst obj_name,
- const gpointer pObject,
- PairVec& vec) const noexcept
-{
- TimespecAccessFunc ts_getter;
- Timespec ts;
-/* Can't use get_row_value_from_object because g_object_get returns a
- * Timespec* and the getter returns a Timespec. Will be fixed by the
- * replacement of timespecs with time64s.
- */
- g_return_if_fail (obj_name != NULL);
- g_return_if_fail (pObject != NULL);
-
- if (m_gobj_param_name != NULL)
- {
- Timespec* pts;
- g_object_get (pObject, m_gobj_param_name, &pts, NULL);
- ts = *pts;
- }
- else
+ if (m_gobj_param_name != nullptr)
{
- ts_getter = (TimespecAccessFunc)get_getter (obj_name);
- g_return_if_fail (ts_getter != NULL);
- ts = (*ts_getter) (pObject);
- }
- if (ts.tv_sec > MINTIME && ts.tv_sec < MAXTIME)
- {
- GncDateTime time(ts.tv_sec);
- vec.emplace_back (std::make_pair (std::string{m_col_name},
- time.format_zulu ("'%Y-%m-%d %H:%M:%S'")));
+ Time64 t64{t};
+ set_parameter(pObject, &t64, m_gobj_param_name);
}
else
{
- vec.emplace_back (std::make_pair (std::string{m_col_name},
- "NULL"));
+ set_parameter(pObject, t,
+ reinterpret_cast<Time64SetterFunc>(get_setter(obj_name)),
+ nullptr);
}
}
-/* ----------------------------------------------------------------- */
-typedef time64 (*Time64AccessFunc) (const gpointer);
-typedef void (*Time64SetterFunc) (const gpointer, time64);
template<> void
-GncSqlColumnTableEntryImpl<CT_TIME64>::load (const GncSqlBackend* sql_be,
- GncSqlRow& row,
- QofIdTypeConst obj_name,
- gpointer pObject)
- const noexcept
+GncSqlColumnTableEntryImpl<CT_TIME>::add_to_table(ColVec& vec) const noexcept
{
- time64 t;
- g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
- try
- {
- t = row.get_time64_at_col (m_col_name);
- }
- catch (std::invalid_argument&)
- {
- try
- {
- auto val = row.get_string_at_col(m_col_name);
- GncDateTime time(val);
- t = static_cast<time64>(time);
- }
- catch (std::invalid_argument&)
- {
- return;
- }
- }
- set_parameter(pObject, t,
- reinterpret_cast<Time64SetterFunc>(get_setter(obj_name)),
- m_gobj_param_name);
-}
-template<> void
-GncSqlColumnTableEntryImpl<CT_TIME64>::add_to_table(ColVec& vec) const noexcept
-{
-
- GncSqlColumnInfo info{*this, BCT_DATETIME, TIMESPEC_COL_SIZE, FALSE};
+ GncSqlColumnInfo info{*this, BCT_DATETIME, TIME_COL_SIZE, FALSE};
vec.emplace_back(std::move(info));
}
template<> void
-GncSqlColumnTableEntryImpl<CT_TIME64>::add_to_query(QofIdTypeConst obj_name,
+GncSqlColumnTableEntryImpl<CT_TIME>::add_to_query(QofIdTypeConst obj_name,
const gpointer pObject,
PairVec& vec) const noexcept
{
- auto t = get_row_value_from_object<time64>(obj_name, pObject);
- if (t > MINTIME && t < MAXTIME)
+ /* We still can't use get_row_value_from_object because while g_value could
+ * contentedly store a time64 in an int64, KVP wouldn't be able to tell them
+ * apart, so we have the struct Time64 hack, see engine/gnc-date.c.
+ */
+ time64 t64;
+ if (m_gobj_param_name != nullptr)
+ {
+ Time64* t;
+ g_object_get (pObject, m_gobj_param_name, &t, nullptr);
+ t64 = t->t;
+ }
+ else
+ {
+ auto getter = (Time64AccessFunc)get_getter (obj_name);
+ g_return_if_fail(getter != nullptr);
+ t64 = (*getter)(pObject);
+ }
+ if (t64 > MINTIME && t64 < MAXTIME)
{
- GncDateTime time(t);
+ GncDateTime time(t64);
vec.emplace_back (std::make_pair (std::string{m_col_name},
time.format_zulu ("'%Y-%m-%d %H:%M:%S'")));
}
@@ -539,7 +475,7 @@ GncSqlColumnTableEntryImpl<CT_GDATE>::load (const GncSqlBackend* sql_be,
g_date_clear (&date, 1);
try
{
- /* timespec_to_gdate applies the tz, and gdates are saved
+ /* time64_to_gdate applies the tz, and gdates are saved
* as ymd, so we don't want that.
*/
auto time = row.get_time64_at_col(m_col_name);
@@ -667,7 +603,7 @@ GncSqlColumnTableEntryImpl<CT_NUMERIC>::add_to_query(QofIdTypeConst obj_name,
const gpointer pObject,
PairVec& vec) const noexcept
{
-/* We can't use get_row_value_from_object for the same reason as Timespec. */
+/* We can't use get_row_value_from_object for the same reason as time64. */
NumericGetterFunc getter;
gnc_numeric n;
diff --git a/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp b/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
index b365d4a..7ea6e93 100644
--- a/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
+++ b/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
@@ -71,8 +71,7 @@ enum GncSqlObjectType
CT_GUID,
CT_INT,
CT_INT64,
- CT_TIMESPEC,
- CT_TIME64,
+ CT_TIME,
CT_GDATE,
CT_NUMERIC,
CT_DOUBLE,
diff --git a/libgnucash/backend/sql/gnc-transaction-sql.cpp b/libgnucash/backend/sql/gnc-transaction-sql.cpp
index df1c950..780cfcf 100644
--- a/libgnucash/backend/sql/gnc-transaction-sql.cpp
+++ b/libgnucash/backend/sql/gnc-transaction-sql.cpp
@@ -90,8 +90,8 @@ static const EntryVec tx_col_table
gnc_sql_make_table_entry<CT_COMMODITYREF>("currency_guid", 0, COL_NNUL,
"currency"),
gnc_sql_make_table_entry<CT_STRING>("num", TX_MAX_NUM_LEN, COL_NNUL, "num"),
- gnc_sql_make_table_entry<CT_TIMESPEC>("post_date", 0, 0, "post-date"),
- gnc_sql_make_table_entry<CT_TIMESPEC>("enter_date", 0, 0, "enter-date"),
+ gnc_sql_make_table_entry<CT_TIME>("post_date", 0, 0, "post-date"),
+ gnc_sql_make_table_entry<CT_TIME>("enter_date", 0, 0, "enter-date"),
gnc_sql_make_table_entry<CT_STRING>("description", TX_MAX_DESCRIPTION_LEN,
0, "description"),
};
@@ -116,7 +116,7 @@ static const EntryVec split_col_table
gnc_sql_make_table_entry<CT_STRING>("reconcile_state", 1, COL_NNUL,
(QofAccessFunc)get_split_reconcile_state,
set_split_reconcile_state),
- gnc_sql_make_table_entry<CT_TIMESPEC>("reconcile_date", 0, 0,
+ gnc_sql_make_table_entry<CT_TIME>("reconcile_date", 0, 0,
"reconcile-date"),
gnc_sql_make_table_entry<CT_NUMERIC>("value", 0, COL_NNUL, "value"),
gnc_sql_make_table_entry<CT_NUMERIC>("quantity", 0, COL_NNUL, "amount"),
@@ -127,7 +127,7 @@ static const EntryVec split_col_table
static const EntryVec post_date_col_table
{
- gnc_sql_make_table_entry<CT_TIMESPEC>("post_date", 0, 0, "post-date"),
+ gnc_sql_make_table_entry<CT_TIME>("post_date", 0, 0, "post-date"),
};
static const EntryVec account_guid_col_table
diff --git a/libgnucash/backend/sql/test/utest-gnc-backend-sql.cpp b/libgnucash/backend/sql/test/utest-gnc-backend-sql.cpp
index a990385..81e95e1 100644
--- a/libgnucash/backend/sql/test/utest-gnc-backend-sql.cpp
+++ b/libgnucash/backend/sql/test/utest-gnc-backend-sql.cpp
@@ -597,30 +597,6 @@ gnc_sql_add_objectref_guid_col_info_to_list (,// 1
test_gnc_sql_add_objectref_guid_col_info_to_list (Fixture *fixture, gconstpointer pData)
{
}*/
-/* load_timespec
-static void
-load_timespec (const GncSqlBackend* sql_be, GncSqlRow& row,// 2
-*/
-/* static void
-test_load_timespec (Fixture *fixture, gconstpointer pData)
-{
-}*/
-/* add_timespec_col_info_to_list
-static void
-add_timespec_col_info_to_list (const GncSqlBackend* sql_be, const GncSqlColumnTableEntry& table_row,// 2
-*/
-/* static void
-test_add_timespec_col_info_to_list (Fixture *fixture, gconstpointer pData)
-{
-}*/
-/* add_value_timespec_to_vec
-static void
-add_gvalue_timespec_to_slist (const GncSqlBackend* sql_be, QofIdTypeConst obj_name,// 2
-*/
-/* static void
-test_add_value_timespec_to_vec (Fixture *fixture, gconstpointer pData)
-{
-}*/
/* load_date
static void
load_date (const GncSqlBackend* sql_be, GncSqlRow& row,// 2
@@ -915,9 +891,6 @@ test_suite_gnc_backend_sql (void)
// GNC_TEST_ADD (suitename, "add value guid to vec", Fixture, nullptr, test_add_value_guid_to_vec, teardown);
// GNC_TEST_ADD (suitename, "gnc sql add gvalue objectref guid to slist", Fixture, nullptr, test_gnc_sql_add_objectref_guid_to_vec, teardown);
// GNC_TEST_ADD (suitename, "gnc sql add objectref guid col info to list", Fixture, nullptr, test_gnc_sql_add_objectref_guid_col_info_to_list, teardown);
-// GNC_TEST_ADD (suitename, "load timespec", Fixture, nullptr, test_load_timespec, teardown);
-// GNC_TEST_ADD (suitename, "add timespec col info to list", Fixture, nullptr, test_add_timespec_col_info_to_list, teardown);
-// GNC_TEST_ADD (suitename, "add value timespec to vec", Fixture, nullptr, test_add_value_timespec_to_vec, teardown);
// GNC_TEST_ADD (suitename, "load date", Fixture, nullptr, test_load_date, teardown);
// GNC_TEST_ADD (suitename, "add date col info to list", Fixture, nullptr, test_add_date_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add value date to vec", Fixture, nullptr, test_add_value_date_to_vec, teardown);
commit 755773ac4cf225bbd78000a8290a4809d3b09a18
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Aug 3 14:00:07 2018 -0700
Clean up timespec comments in the XML backend.
Noting where the word must stay; most significantly for KVP types and for
parsing Version 1 XML files.
diff --git a/libgnucash/backend/xml/sixtp-dom-generators.cpp b/libgnucash/backend/xml/sixtp-dom-generators.cpp
index bbb6c70..6cdf405 100644
--- a/libgnucash/backend/xml/sixtp-dom-generators.cpp
+++ b/libgnucash/backend/xml/sixtp-dom-generators.cpp
@@ -271,6 +271,9 @@ add_kvp_value_node (xmlNodePtr node, const gchar* tag, KvpValue* val)
add_text_to_node (val_node, "guid", guidstr);
break;
}
+ /* Note: The type attribute must remain 'timespec' to maintain
+ * compatibility.
+ */
case KvpValue::Type::TIME64:
{
auto t = val->get<Time64> ();
diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.cpp b/libgnucash/backend/xml/sixtp-dom-parsers.cpp
index 5d9cae9..0bde990 100644
--- a/libgnucash/backend/xml/sixtp-dom-parsers.cpp
+++ b/libgnucash/backend/xml/sixtp-dom-parsers.cpp
@@ -348,6 +348,8 @@ struct kvp_val_converter
const gchar* tag;
KvpValue* (*converter) (xmlNodePtr node);
};
+/* Note: The type attribute must remain 'timespec' to maintain compatibility.
+ */
struct kvp_val_converter val_converters[] =
{
@@ -531,17 +533,16 @@ dom_tree_to_time64 (xmlNodePtr node)
/* Turn something like this
<date-posted>
- <s>Mon, 05 Jun 2000 23:16:19 -0500</s>
- <ns>658864000</ns>
+ <ts:date>Mon, 05 Jun 2000 23:16:19 -0500</ts:date>
</date-posted>
- into a time64. If this returns FALSE, the effects on *ts are
- undefined. The XML is valid if it has at least one of <s> or <ns>
- and no more than one of each. Order is irrelevant. */
+ into a time64, returning INT64_MAX that we're using to flag an erroneous
+ date if there's a problem. Only one ts:date element is permitted for any
+ date attribute.
+ */
time64 ret {INT64_MAX};
- gboolean seen_s = FALSE;
- gboolean seen_ns = FALSE;
+ gboolean seen = FALSE;
xmlNodePtr n;
for (n = node->xmlChildrenNode; n; n = n->next)
@@ -554,7 +555,7 @@ dom_tree_to_time64 (xmlNodePtr node)
case XML_ELEMENT_NODE:
if (g_strcmp0 ("ts:date", (char*)n->name) == 0)
{
- if (seen_s)
+ if (seen)
{
return INT64_MAX;
}
@@ -568,21 +569,21 @@ dom_tree_to_time64 (xmlNodePtr node)
ret = gnc_iso8601_to_time64_gmt (content);
g_free (content);
- seen_s = TRUE;
+ seen = TRUE;
}
}
break;
default:
PERR ("unexpected sub-node.");
- return time_parse_failure ();
+ return INT64_MAX;
break;
}
}
- if (!seen_s)
+ if (!seen)
{
PERR ("no ts:date node found.");
- return time_parse_failure ();
+ return INT64_MAX;
}
return ret;
diff --git a/libgnucash/backend/xml/sixtp-utils.cpp b/libgnucash/backend/xml/sixtp-utils.cpp
index 03933c7..12ecd87 100644
--- a/libgnucash/backend/xml/sixtp-utils.cpp
+++ b/libgnucash/backend/xml/sixtp-utils.cpp
@@ -346,7 +346,7 @@ simple_chars_only_parser_new (sixtp_end_handler end_handler)
}
/****************************************************************************/
-/* generic timespec handler.
+/* generic timespec handler for XML Version 1 files.
A collection of node functions intended to parse a sub-node set
that looks like this:
diff --git a/libgnucash/backend/xml/test/test-dom-converters1.cpp b/libgnucash/backend/xml/test/test-dom-converters1.cpp
index 29182d1..aa2b6c3 100644
--- a/libgnucash/backend/xml/test/test-dom-converters1.cpp
+++ b/libgnucash/backend/xml/test/test-dom-converters1.cpp
@@ -138,7 +138,7 @@ test_dom_tree_to_time64 (void)
time64 test_spec2 = dom_tree_to_time64 (test_node);
if (!dom_tree_valid_time64 (test_spec2, (const xmlChar*)"test-spec"))
{
- failure_args ("dom_tree_to_timespec",
+ failure_args ("dom_tree_to_time64",
__FILE__, __LINE__, "NULL return");
printf ("Node looks like:\n");
xmlElemDump (stdout, NULL, test_node);
commit b32a8a9390da697cfddad9b33296efdb1d32f264
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Aug 3 13:52:47 2018 -0700
Remove time64_to_string and string_to_time64 and their tests.
Each was used exactly once and simply wrapped a function call.
Also replace static function time_parse_failure that just returned a
constant with the constant.
diff --git a/libgnucash/backend/xml/sixtp-dom-generators.cpp b/libgnucash/backend/xml/sixtp-dom-generators.cpp
index 4d8fff4..bbb6c70 100644
--- a/libgnucash/backend/xml/sixtp-dom-generators.cpp
+++ b/libgnucash/backend/xml/sixtp-dom-generators.cpp
@@ -131,18 +131,12 @@ commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c)
return ret;
}
-char*
-time64_to_string (time64 time)
-{
- return gnc_print_time64 (time, TIMESPEC_TIME_FORMAT " %q");
-}
-
xmlNodePtr
time64_to_dom_tree (const char* tag, const time64 time)
{
xmlNodePtr ret;
g_return_val_if_fail (time != INT64_MAX, NULL);
- auto date_str = time64_to_string (time);
+ auto date_str = gnc_print_time64 (time, "%Y-%m-%d %H:%M:%S %q");
if (!date_str)
return NULL;
ret = xmlNewNode (NULL, BAD_CAST tag);
diff --git a/libgnucash/backend/xml/sixtp-dom-generators.h b/libgnucash/backend/xml/sixtp-dom-generators.h
index 68a4cf0..daf5bac 100644
--- a/libgnucash/backend/xml/sixtp-dom-generators.h
+++ b/libgnucash/backend/xml/sixtp-dom-generators.h
@@ -41,7 +41,6 @@ xmlNodePtr boolean_to_dom_tree (const char* tag, gboolean val);
xmlNodePtr guid_to_dom_tree (const char* tag, const GncGUID* gid);
xmlNodePtr commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c);
xmlNodePtr time64_to_dom_tree (const char* tag, time64);
-gchar* time64_to_string (time64);
xmlNodePtr gdate_to_dom_tree (const char* tag, const GDate* spec);
xmlNodePtr gnc_numeric_to_dom_tree (const char* tag, const gnc_numeric* num);
xmlNodePtr qof_instance_slots_to_dom_tree (const char* tag,
diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.cpp b/libgnucash/backend/xml/sixtp-dom-parsers.cpp
index 1408004..5d9cae9 100644
--- a/libgnucash/backend/xml/sixtp-dom-parsers.cpp
+++ b/libgnucash/backend/xml/sixtp-dom-parsers.cpp
@@ -524,12 +524,6 @@ dom_tree_to_gnc_numeric (xmlNodePtr node)
return ret;
}
-static time64
-time_parse_failure ()
-{
- return INT64_MAX;
-}
-
time64
dom_tree_to_time64 (xmlNodePtr node)
@@ -562,21 +556,17 @@ dom_tree_to_time64 (xmlNodePtr node)
{
if (seen_s)
{
- return time_parse_failure ();
+ return INT64_MAX;
}
else
{
gchar* content = dom_tree_to_text (n);
if (!content)
{
- return time_parse_failure ();
+ return INT64_MAX;
}
- if (!string_to_time64 (content, &ret))
- {
- g_free (content);
- return time_parse_failure ();
- }
+ ret = gnc_iso8601_to_time64_gmt (content);
g_free (content);
seen_s = TRUE;
}
diff --git a/libgnucash/backend/xml/sixtp-utils.cpp b/libgnucash/backend/xml/sixtp-utils.cpp
index 5c7dfbd..03933c7 100644
--- a/libgnucash/backend/xml/sixtp-utils.cpp
+++ b/libgnucash/backend/xml/sixtp-utils.cpp
@@ -362,13 +362,6 @@ simple_chars_only_parser_new (sixtp_end_handler end_handler)
all goes well, returns the time64 as the result.
*/
-gboolean
-string_to_time64 (const gchar* str, time64* time)
-{
- *time = gnc_iso8601_to_time64_gmt (str);
- return (TRUE);
-}
-
/* Top level timespec node:
input: user end handler *
@@ -436,17 +429,17 @@ generic_timespec_secs_end_handler (gpointer data_for_children,
{
gchar* txt = NULL;
Time64ParseInfo* info = (Time64ParseInfo*) parent_data;
- gboolean ok;
g_return_val_if_fail (parent_data, FALSE);
txt = concatenate_child_result_chars (data_from_children);
g_return_val_if_fail (txt, FALSE);
- ok = string_to_time64 (txt, & info->time);
+ info->time = gnc_iso8601_to_time64_gmt (txt);
g_free (txt);
- g_return_val_if_fail (ok, FALSE);
+// gnc_iso8601_to_time64_gmt returns INT64_MAX on failure.
+ g_return_val_if_fail (info->time < INT64_MAX, FALSE);
info->s_block_count++;
return (TRUE);
diff --git a/libgnucash/backend/xml/sixtp-utils.h b/libgnucash/backend/xml/sixtp-utils.h
index 4129fe3..2ee7aa1 100644
--- a/libgnucash/backend/xml/sixtp-utils.h
+++ b/libgnucash/backend/xml/sixtp-utils.h
@@ -35,10 +35,6 @@ typedef struct
guint s_block_count;
} Time64ParseInfo;
-#define TIMESPEC_TIME_FORMAT "%Y-%m-%d %H:%M:%S"
-#define TIMESPEC_PARSE_TIME_FORMAT "%Y-%m-%d %H:%M:%S"
-#define TIMESPEC_SEC_FORMAT_MAX 256
-
gboolean isspace_str (const gchar* str, int nomorethan);
gboolean allow_and_ignore_only_whitespace (GSList* sibling_data,
@@ -84,8 +80,6 @@ gboolean generic_return_chars_end_handler (gpointer data_for_children,
sixtp* simple_chars_only_parser_new (sixtp_end_handler end_handler);
-gboolean string_to_time64 (const gchar* str, time64* ts);
-
gboolean generic_timespec_start_handler (GSList* sibling_data,
gpointer parent_data,
gpointer global_data,
diff --git a/libgnucash/backend/xml/test/CMakeLists.txt b/libgnucash/backend/xml/test/CMakeLists.txt
index 1468dfe..77b126c 100644
--- a/libgnucash/backend/xml/test/CMakeLists.txt
+++ b/libgnucash/backend/xml/test/CMakeLists.txt
@@ -57,7 +57,7 @@ set(test_backend_xml_module_SOURCES
)
set_local_dist(test_backend_xml_DIST_local CMakeLists.txt grab-types.pl
- README test-date-converting.cpp test-dom-converters1.cpp
+ README test-dom-converters1.cpp
test-dom-parser1.cpp test-file-stuff.cpp test-file-stuff.h test-kvp-frames.cpp
test-load-backend.cpp test-load-example-account.cpp test-load-xml2.cpp
test-save-in-lang.cpp test-string-converters.cpp test-xml2-is-file.cpp
@@ -65,7 +65,6 @@ set_local_dist(test_backend_xml_DIST_local CMakeLists.txt grab-types.pl
test-xml-pricedb.cpp test-xml-transaction.cpp)
set(test_backend_xml_DIST ${test_backend_xml_DIST_local} ${test_backend_xml_test_files_DIST} PARENT_SCOPE)
-add_xml_test(test-date-converting "${test_backend_xml_base_SOURCES};test-date-converting.cpp")
add_xml_test(test-dom-converters1 "${test_backend_xml_base_SOURCES};test-dom-converters1.cpp")
add_xml_test(test-kvp-frames "${test_backend_xml_base_SOURCES};test-kvp-frames.cpp")
add_xml_test(test-load-backend test-load-backend.cpp)
diff --git a/libgnucash/backend/xml/test/test-date-converting.cpp b/libgnucash/backend/xml/test/test-date-converting.cpp
deleted file mode 100644
index d940d81..0000000
--- a/libgnucash/backend/xml/test/test-date-converting.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/********************************************************************\
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
-\********************************************************************/
-extern "C"
-{
-#include <config.h>
-
-#include "test-engine-stuff.h"
-
-#include <stdlib.h>
-}
-
-#include "test-file-stuff.h"
-#include "sixtp-utils.h"
-#include "sixtp-dom-generators.h"
-#include "test-stuff.h"
-
-#define GNC_V2_STRING "gnc-v2"
-const gchar* gnc_v2_xml_version_string = GNC_V2_STRING;
-
-int
-main (int argc, char** argv)
-{
- int i;
-
- for (i = 0; i < 20; i++)
- {
- time64 spec2;
- auto spec1 = get_random_time ();
- auto sec_str = time64_to_string (spec1);
- if (!string_to_time64 (sec_str, &spec2))
- {
- failure_args ("string_to_timespec_secs", __FILE__, __LINE__,
- "string is %s", sec_str);
- }
- else if (spec1 != spec2)
- {
- failure_args ("timespec_secs", __FILE__, __LINE__,
- "not equal ints are %" G_GINT64_FORMAT
- " and %" G_GINT64_FORMAT "\n",
- spec1, spec2);
- }
- else
- {
- success ("timespec");
- }
- g_free (sec_str);
- }
- print_test_results ();
- exit (get_rv ());
-}
commit 62b17ca5db863e3d08182f17c14bdba8c2046f65
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Aug 3 12:51:11 2018 -0700
Timespec removal, engine odds-and-ends.
diff --git a/libgnucash/engine/engine.i b/libgnucash/engine/engine.i
index 9cc7c9d..288f484 100644
--- a/libgnucash/engine/engine.i
+++ b/libgnucash/engine/engine.i
@@ -211,7 +211,6 @@ SplitList * qof_query_run_subquery (QofQuery *q, const QofQuery *q);
%ignore GNC_ERROR_REMAINDER;
%include <gnc-numeric.h>
-Timespec timespecCanonicalDayTime(Timespec t);
time64 time64CanonicalDayTime(time64 t);
%include <gnc-budget.h>
diff --git a/libgnucash/engine/qofinstance-p.h b/libgnucash/engine/qofinstance-p.h
index 8fcff1b..45d4eeb 100644
--- a/libgnucash/engine/qofinstance-p.h
+++ b/libgnucash/engine/qofinstance-p.h
@@ -51,7 +51,7 @@ void qof_instance_set_slots (QofInstance *, KvpFrame *);
* used for comparing version in local memory to that in remote
* server.
*/
-void qof_instance_set_last_update (QofInstance *inst, Timespec ts);
+void qof_instance_set_last_update (QofInstance *inst, time64 time);
/** Set the dirty flag of just the instance. Don't modify the
* collection flag at all. */
diff --git a/libgnucash/engine/qofinstance.cpp b/libgnucash/engine/qofinstance.cpp
index 06ae8ca..670f91b 100644
--- a/libgnucash/engine/qofinstance.cpp
+++ b/libgnucash/engine/qofinstance.cpp
@@ -86,7 +86,7 @@ typedef struct QofInstancePrivate
* SQL backend, this field is reserved for SQL use, to compare
* the version in local memory to the remote, server version.
*/
- Timespec last_update;
+ time64 last_update;
/* Keep track of nesting level of begin/end edit calls */
int editlevel;
@@ -264,8 +264,7 @@ qof_instance_init (QofInstance *inst)
priv = GET_PRIVATE(inst);
priv->book = NULL;
inst->kvp_data = new KvpFrame;
- priv->last_update.tv_sec = 0;
- priv->last_update.tv_nsec = -1;
+ priv->last_update = 0;
priv->editlevel = 0;
priv->do_free = FALSE;
priv->dirty = FALSE;
@@ -415,7 +414,7 @@ qof_instance_set_property (GObject *object,
GParamSpec *pspec)
{
QofInstance *inst;
- Timespec *ts;
+ Time64 t;
g_return_if_fail(QOF_IS_INSTANCE(object));
@@ -435,8 +434,8 @@ qof_instance_set_property (GObject *object,
static_cast<QofBook*>(g_value_get_object(value)));
break;
case PROP_LAST_UPDATE:
- ts = static_cast<Timespec*>(g_value_get_pointer(value));
- qof_instance_set_last_update(inst, *ts);
+ t = *(static_cast<Time64*>(g_value_get_pointer(value)));
+ qof_instance_set_last_update(inst, t.t);
break;
case PROP_DESTROYING:
qof_instance_set_destroying(inst, g_value_get_boolean(value));
@@ -598,10 +597,10 @@ qof_instance_set_slots (QofInstance *inst, KvpFrame *frm)
}
void
-qof_instance_set_last_update (QofInstance *inst, Timespec ts)
+qof_instance_set_last_update (QofInstance *inst, time64 t)
{
if (!inst) return;
- GET_PRIVATE(inst)->last_update = ts;
+ GET_PRIVATE(inst)->last_update = t;
}
gint
@@ -640,11 +639,8 @@ qof_instance_version_cmp (const QofInstance *left, const QofInstance *right)
lpriv = GET_PRIVATE(left);
rpriv = GET_PRIVATE(right);
- if (lpriv->last_update.tv_sec < rpriv->last_update.tv_sec) return -1;
- if (lpriv->last_update.tv_sec > rpriv->last_update.tv_sec) return +1;
- if (lpriv->last_update.tv_nsec < rpriv->last_update.tv_nsec) return -1;
- if (lpriv->last_update.tv_nsec > rpriv->last_update.tv_nsec) return +1;
- return 0;
+ return lpriv->last_update < rpriv->last_update ? -1 :
+ lpriv->last_update > rpriv->last_update ? 1 : 0;
}
gboolean
diff --git a/libgnucash/engine/qofquery.cpp b/libgnucash/engine/qofquery.cpp
index 07278df..f91d204 100644
--- a/libgnucash/engine/qofquery.cpp
+++ b/libgnucash/engine/qofquery.cpp
@@ -1827,9 +1827,12 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
if (!g_strcmp0 (pd->type_name, QOF_TYPE_DATE))
{
query_date_t pdata = (query_date_t) pd;
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset (datebuff, 0, sizeof(datebuff));
+ qof_print_date_buff (datebuff, sizeof(datebuff), pdata->date);
g_string_append_printf (gs, " Match type %s",
qof_query_printDateMatch (pdata->options));
- g_string_append_printf (gs, " query_date: %s", gnc_print_date ({pdata->date, 0}));
+ g_string_append_printf (gs, " query_date: %s", datebuff);
return;
}
if (!g_strcmp0 (pd->type_name, QOF_TYPE_CHAR))
diff --git a/libgnucash/engine/qofquerycore.cpp b/libgnucash/engine/qofquerycore.cpp
index 91c5afa..f9c8b98 100644
--- a/libgnucash/engine/qofquerycore.cpp
+++ b/libgnucash/engine/qofquerycore.cpp
@@ -450,7 +450,7 @@ date_to_string (gpointer object, QofParam *getter)
time64 tt = ((query_date_getter)getter->param_getfcn)(object, getter);
if (tt != INT64_MAX)
- return g_strdup (gnc_print_date ({tt, 0}));
+ return qof_print_date (tt);
return NULL;
}
diff --git a/libgnucash/engine/test-core/test-engine-stuff.cpp b/libgnucash/engine/test-core/test-engine-stuff.cpp
index 24caa5a..05f3203 100644
--- a/libgnucash/engine/test-core/test-engine-stuff.cpp
+++ b/libgnucash/engine/test-core/test-engine-stuff.cpp
@@ -157,20 +157,6 @@ kvp_type_excluded (KvpValue::Type kvp_type)
static gboolean zero_nsec = FALSE;
-void
-random_timespec_zero_nsec (gboolean zero_nsec_in)
-{
- zero_nsec = zero_nsec_in;
-}
-
-static gboolean usec_resolution = FALSE;
-
-void
-random_timespec_usec_resolution (gboolean usec_resolution_in)
-{
- usec_resolution = usec_resolution_in;
-}
-
/* ========================================================== */
static inline gboolean
@@ -236,20 +222,6 @@ get_random_time (void)
return ret;
}
-Timespec*
-get_random_timespec(void)
-{
- Timespec *ret;
-
- ret = g_new0(Timespec, 1);
-
- while (ret->tv_sec <= 0)
- ret->tv_sec = rand();
-
- ret->tv_nsec = 0;
- return ret;
-}
-
GncGUID*
get_random_guid(void)
{
diff --git a/libgnucash/engine/test-core/test-engine-stuff.h b/libgnucash/engine/test-core/test-engine-stuff.h
index 5f8d69d..bc661da 100644
--- a/libgnucash/engine/test-core/test-engine-stuff.h
+++ b/libgnucash/engine/test-core/test-engine-stuff.h
@@ -45,10 +45,8 @@ typedef struct KvpValueImpl KvpValue;
typedef struct KvpFrameImpl KvpFrame;
#define __KVP_FRAME
#endif
-Timespec* get_random_timespec(void);
+
time64 get_random_time(void);
-void random_timespec_zero_nsec (gboolean zero_nsec);
-void random_timespec_usec_resolution (gboolean usec_resolution);
KvpValue* get_random_kvp_value(int type);
diff --git a/libgnucash/engine/test/test-date.cpp b/libgnucash/engine/test/test-date.cpp
index 86f802d..acf502a 100644
--- a/libgnucash/engine/test/test-date.cpp
+++ b/libgnucash/engine/test/test-date.cpp
@@ -391,7 +391,7 @@ run_test (void)
ts.tv_nsec = 0;
check_time (ts, do_print);
- ts = *get_random_timespec ();
+ ts.tv_sec = get_random_time ();
for (i = 0; i < 10000; i++)
{
@@ -402,7 +402,7 @@ run_test (void)
for (i = 0; i < 5000; i++)
{
- ts = *get_random_timespec ();
+ ts.tv_sec = get_random_time ();
if (!check_time (ts, FALSE))
return;
diff --git a/libgnucash/engine/test/test-qofinstance.cpp b/libgnucash/engine/test/test-qofinstance.cpp
index 292e250..6e04b49 100644
--- a/libgnucash/engine/test/test-qofinstance.cpp
+++ b/libgnucash/engine/test/test-qofinstance.cpp
@@ -194,7 +194,7 @@ test_instance_new_destroy( void )
QofInstance *inst;
QofInstanceClass *klass;
/* test var */
- Timespec *timespec_priv;
+ Time64 *time_priv;
const char *msg1 = "qof_instance_get_collection: assertion 'QOF_IS_INSTANCE(ptr)' failed";
const char *msg2 = "qof_instance_get_editlevel: assertion 'QOF_IS_INSTANCE(ptr)' failed";
const char *msg3 = "qof_instance_get_destroying: assertion 'QOF_IS_INSTANCE(ptr)' failed";
@@ -217,9 +217,8 @@ test_instance_new_destroy( void )
g_assert( !qof_instance_get_collection( inst ) );
g_assert( qof_instance_get_book( inst ) == NULL );
g_assert( inst->kvp_data );
- g_object_get( inst, "last-update", ×pec_priv, NULL);
- g_assert_cmpint( timespec_priv->tv_sec, == , 0 );
- g_assert_cmpint( timespec_priv->tv_nsec, == , -1 );
+ g_object_get( inst, "last-update", &time_priv, NULL);
+ g_assert_cmpint( time_priv->t, == , 0 );
g_assert_cmpint( qof_instance_get_editlevel( inst ), == , 0 );
g_assert( !qof_instance_get_destroying( inst ) );
g_assert( !qof_instance_get_dirty_flag( inst ) );
@@ -311,7 +310,7 @@ test_instance_version_cmp( void )
{
QofInstance *left, *right;
int result;
- Timespec timespec_left, timespec_right;
+ time64 time_left = 0, time_right = 1;
/* set up*/
left = static_cast<QofInstance*>(g_object_new( QOF_TYPE_INSTANCE, NULL ));
@@ -330,48 +329,24 @@ test_instance_version_cmp( void )
g_assert_cmpint( result, == , 1 );
g_test_message( "Test left tv_sec lesser than right" );
- timespec_left.tv_sec = 0;
- timespec_right.tv_sec = 1;
- qof_instance_set_last_update( left, timespec_left );
- qof_instance_set_last_update( right, timespec_right );
+ qof_instance_set_last_update( left, time_left );
+ qof_instance_set_last_update( right, time_right );
result = qof_instance_version_cmp( left, right );
g_assert_cmpint( result, == , -1 );
g_test_message( "Test right tv_sec lesser than left" );
- timespec_left.tv_sec = 1;
- timespec_right.tv_sec = 0;
- qof_instance_set_last_update( left, timespec_left );
- qof_instance_set_last_update( right, timespec_right );
- result = qof_instance_version_cmp( left, right );
- g_assert_cmpint( result, == , 1 );
-
- g_test_message( "Test left tv_nsec lesser than right" );
- timespec_left.tv_sec = 1;
- timespec_left.tv_nsec = 0;
- timespec_right.tv_sec = 1;
- timespec_right.tv_nsec = 1;
- qof_instance_set_last_update( left, timespec_left );
- qof_instance_set_last_update( right, timespec_right );
- result = qof_instance_version_cmp( left, right );
- g_assert_cmpint( result, == , -1 );
-
- g_test_message( "Test right tv_sec lesser than left" );
- timespec_left.tv_sec = 1;
- timespec_left.tv_nsec = 1;
- timespec_right.tv_sec = 1;
- timespec_right.tv_nsec = 0;
- qof_instance_set_last_update( left, timespec_left );
- qof_instance_set_last_update( right, timespec_right );
+ time_left = 1;
+ time_right = 0;
+ qof_instance_set_last_update( left, time_left );
+ qof_instance_set_last_update( right, time_right );
result = qof_instance_version_cmp( left, right );
g_assert_cmpint( result, == , 1 );
g_test_message( "Test both equal" );
- timespec_left.tv_sec = 1;
- timespec_left.tv_nsec = 1;
- timespec_right.tv_sec = 1;
- timespec_right.tv_nsec = 1;
- qof_instance_set_last_update( left, timespec_left );
- qof_instance_set_last_update( right, timespec_right );
+ time_left = 1;
+ time_right = 1;
+ qof_instance_set_last_update( left, time_left );
+ qof_instance_set_last_update( right, time_right );
result = qof_instance_version_cmp( left, right );
g_assert_cmpint( result, == , 0 );
commit 358cd979d9376c1795124d18f8cfe0eb551d4d03
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 2 18:19:15 2018 -0700
Remove Timespec from the main engine classes (Transaction, Split, & Account.
diff --git a/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp b/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
index 6a397f6..e7c4c92 100644
--- a/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
@@ -63,15 +63,6 @@ add_time64 (xmlNodePtr node, const gchar * tag, time64 time, gboolean always)
xmlAddChild (node, time64_to_dom_tree (tag, time));
}
-static void
-add_timespec (xmlNodePtr node, const gchar* tag, Timespec tms, gboolean always)
-{
- if (always || tms.tv_sec)
- {
- xmlAddChild (node, time64_to_dom_tree (tag, tms.tv_sec));
- }
-}
-
static xmlNodePtr
split_to_dom_tree (const gchar* tag, Split* spl)
{
@@ -113,8 +104,8 @@ split_to_dom_tree (const gchar* tag, Split* spl)
BAD_CAST tmp);
}
- add_timespec (ret, "split:reconcile-date",
- xaccSplitRetDateReconciledTS (spl), FALSE);
+ add_time64 (ret, "split:reconcile-date",
+ xaccSplitGetDateReconciled (spl), FALSE);
add_gnc_num (ret, "split:value", xaccSplitGetValue (spl));
@@ -445,12 +436,11 @@ set_tran_time64 (xmlNodePtr node, Transaction * trn,
static inline gboolean
set_tran_date (xmlNodePtr node, Transaction* trn,
- void (*func) (Transaction* trn, const Timespec* tm))
+ void (*func) (Transaction* trn, const time64 tm))
{
time64 time = dom_tree_to_time64 (node);
if (!dom_tree_valid_time64 (time, node->name)) time = 0;
- Timespec ts {time, 0};
- func (trn, &ts);
+ func (trn, time);
return TRUE;
}
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 141609d..72ae32b 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -3311,19 +3311,6 @@ xaccAccountGetBalanceAsOfDate (Account *acc, time64 date)
priv = GET_PRIVATE(acc);
balance = priv->balance;
- /* Since transaction post times are stored as a Timespec,
- * convert date into a Timespec as well rather than converting
- * each transaction's Timespec into a time64.
- *
- * FIXME: CAS: I think this comment is a bogus justification for
- * using xaccTransGetDatePostedTS. There's no benefit to using
- * Timespec when the input argument is time64, and it's hard to
- * imagine that casting long long to long and comparing two longs is
- * worse than comparing two long longs every time. IMO,
- * xaccAccountGetPresentBalance gets this right, and its algorithm
- * should be used here.
- */
-
lp = priv->splits;
while ( lp && !found )
{
@@ -3432,7 +3419,6 @@ xaccAccountConvertBalanceToCurrencyAsOfDate(const Account *acc, /* for book */
{
QofBook *book;
GNCPriceDB *pdb;
- Timespec ts;
if (gnc_numeric_zero_p (balance) ||
gnc_commodity_equiv (balance_currency, new_currency))
diff --git a/libgnucash/engine/Recurrence.c b/libgnucash/engine/Recurrence.c
index c9805f4..093836a 100644
--- a/libgnucash/engine/Recurrence.c
+++ b/libgnucash/engine/Recurrence.c
@@ -391,23 +391,23 @@ time64
recurrenceGetPeriodTime(const Recurrence *r, guint period_num, gboolean end)
{
GDate date;
- Timespec ts;
+ time64 time;
recurrenceNthInstance(r, period_num + (end ? 1 : 0), &date);
if (end)
{
g_date_subtract_days(&date, 1);
- ts = gnc_dmy2timespec_end (g_date_get_day(&date),
+ time = gnc_dmy2time64_end (g_date_get_day(&date),
g_date_get_month(&date),
g_date_get_year (&date));
}
else
{
- ts = gnc_dmy2timespec (g_date_get_day(&date),
+ time = gnc_dmy2time64 (g_date_get_day(&date),
g_date_get_month(&date),
g_date_get_year (&date));
}
- return timespecToTime64(ts);
+ return time;
}
gnc_numeric
diff --git a/libgnucash/engine/Split.c b/libgnucash/engine/Split.c
index b709551..65c3e2e 100644
--- a/libgnucash/engine/Split.c
+++ b/libgnucash/engine/Split.c
@@ -115,8 +115,7 @@ gnc_split_init(Split* split)
split->amount = gnc_numeric_zero();
split->value = gnc_numeric_zero();
- split->date_reconciled.tv_sec = 0;
- split->date_reconciled.tv_nsec = 0;
+ split->date_reconciled = 0;
split->balance = gnc_numeric_zero();
split->cleared_balance = gnc_numeric_zero();
@@ -151,6 +150,7 @@ gnc_split_get_property(GObject *object,
{
Split *split;
gchar *key;
+ Time64 t;
g_return_if_fail(GNC_IS_SPLIT(object));
@@ -170,7 +170,8 @@ gnc_split_get_property(GObject *object,
g_value_set_boxed(value, &split->amount);
break;
case PROP_RECONCILE_DATE:
- g_value_set_boxed(value, &split->date_reconciled.tv_sec);
+ t.t = split->date_reconciled;
+ g_value_set_boxed(value, &t);
break;
case PROP_TX:
g_value_take_object(value, split->parent);
@@ -507,8 +508,7 @@ xaccSplitReinit(Split * split)
split->amount = gnc_numeric_zero();
split->value = gnc_numeric_zero();
- split->date_reconciled.tv_sec = 0;
- split->date_reconciled.tv_nsec = 0;
+ split->date_reconciled = 0;
split->balance = gnc_numeric_zero();
split->cleared_balance = gnc_numeric_zero();
@@ -654,6 +654,9 @@ xaccSplitCopyOnto(const Split *from_split, Split *to_split)
void
xaccSplitDump (const Split *split, const char *tag)
{
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset (datebuff, 0, sizeof(datebuff));
+ qof_print_date_buff (datebuff, sizeof(datebuff), split->date_reconciled);
printf(" %s Split %p", tag, split);
printf(" Book: %p\n", qof_instance_get_book(split));
printf(" Account: %p (%s)\n", split->acc,
@@ -668,8 +671,8 @@ xaccSplitDump (const Split *split, const char *tag)
printf(" Memo: %s\n", split->memo ? split->memo : "(null)");
printf(" Action: %s\n", split->action ? split->action : "(null)");
printf(" KVP Data: %s\n", qof_instance_kvp_as_string (QOF_INSTANCE (split)));
- printf(" Recncld: %c (date %s)\n", split->reconciled,
- gnc_print_date(split->date_reconciled));
+ printf(" Recncld: %c (date %s)\n", split->reconciled, datebuff);
+
printf(" Value: %s\n", gnc_numeric_to_string(split->value));
printf(" Amount: %s\n", gnc_numeric_to_string(split->amount));
printf(" Balance: %s\n", gnc_numeric_to_string(split->balance));
@@ -708,8 +711,7 @@ xaccFreeSplit (Split *split)
split->acc = NULL;
split->orig_acc = NULL;
- split->date_reconciled.tv_sec = 0;
- split->date_reconciled.tv_nsec = 0;
+ split->date_reconciled = 0;
G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
// Is this right?
if (split->gains_split) split->gains_split->gains_split = NULL;
@@ -818,7 +820,7 @@ xaccSplitEqual(const Split *sa, const Split *sb,
return FALSE;
}
- if (timespec_cmp(&(sa->date_reconciled), &(sb->date_reconciled)))
+ if (sa->date_reconciled != sb->date_reconciled)
{
PINFO ("reconciled date differs");
return FALSE;
@@ -1514,7 +1516,10 @@ xaccSplitOrder (const Split *sa, const Split *sb)
if (comp > 0) return +1;
/* if dates differ, return */
- DATE_CMP(sa, sb, date_reconciled);
+ if (sa->date_reconciled < sb->date_reconciled)
+ return -1;
+ else if (sa->date_reconciled > sb->date_reconciled)
+ return 1;
/* else, sort on guid - keeps sort stable. */
retval = qof_instance_guid_compare(sa, sb);
@@ -1772,44 +1777,18 @@ xaccSplitSetDateReconciledSecs (Split *split, time64 secs)
if (!split) return;
xaccTransBeginEdit (split->parent);
- split->date_reconciled.tv_sec = secs;
- split->date_reconciled.tv_nsec = 0;
- qof_instance_set_dirty(QOF_INSTANCE(split));
- xaccTransCommitEdit(split->parent);
-
-}
-
-void
-xaccSplitSetDateReconciledTS (Split *split, Timespec *ts)
-{
- if (!split || !ts) return;
- xaccTransBeginEdit (split->parent);
-
- split->date_reconciled = *ts;
+ split->date_reconciled = secs;
qof_instance_set_dirty(QOF_INSTANCE(split));
xaccTransCommitEdit(split->parent);
}
-void
-xaccSplitGetDateReconciledTS (const Split * split, Timespec *ts)
-{
- if (!split || !ts) return;
- *ts = (split->date_reconciled);
-}
-
-Timespec
-xaccSplitRetDateReconciledTS (const Split * split)
-{
- Timespec ts = {0, 0};
- return split ? split->date_reconciled : ts;
-}
/*################## Added for Reg2 #################*/
time64
xaccSplitGetDateReconciled (const Split * split)
{
- return split ? split->date_reconciled.tv_sec : 0;
+ return split ? split->date_reconciled : 0;
}
/*################## Added for Reg2 #################*/
@@ -2004,7 +1983,7 @@ xaccSplitAddPeerSplit (Split *split, const Split *other_split,
guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
xaccTransBeginEdit (split->parent);
qof_instance_kvp_add_guid (QOF_INSTANCE (split), "lot-split",
- timespec_now(), "peer_guid", guid_copy(guid));
+ gnc_time(NULL), "peer_guid", guid_copy(guid));
mark_split (split);
qof_instance_set_dirty (QOF_INSTANCE (split));
xaccTransCommitEdit (split->parent);
diff --git a/libgnucash/engine/Split.h b/libgnucash/engine/Split.h
index 4d7f417..963413e 100644
--- a/libgnucash/engine/Split.h
+++ b/libgnucash/engine/Split.h
@@ -191,15 +191,6 @@ char xaccSplitGetReconcile (const Split *split);
/** Set the date on which this split was reconciled by specifying the
* time as time64. */
void xaccSplitSetDateReconciledSecs (Split *split, time64 time);
-/** Set the date on which this split was reconciled by specifying the
- * time as Timespec. Caller still owns *ts! */
-void xaccSplitSetDateReconciledTS (Split *split, Timespec *ts);
-/** Get the date on which this split was reconciled by having it
- * written into the Timespec that 'ts' is pointing to. */
-void xaccSplitGetDateReconciledTS (const Split *split,
- Timespec *ts);
-/** Returns the date (as Timespec) on which this split was reconciled. */
-Timespec xaccSplitRetDateReconciledTS (const Split *split);
/*################## Added for Reg2 #################*/
/** Retrieve the date when the Split was reconciled. */
diff --git a/libgnucash/engine/SplitP.h b/libgnucash/engine/SplitP.h
index 2832dc8..9815d41 100644
--- a/libgnucash/engine/SplitP.h
+++ b/libgnucash/engine/SplitP.h
@@ -93,8 +93,8 @@ struct split_s
*/
char * action; /* Buy, Sell, Div, etc. */
- Timespec date_reconciled; /* date split was reconciled */
- char reconciled; /* The reconciled field */
+ time64 date_reconciled; /* date split was reconciled */
+ char reconciled; /* The reconciled field */
/* gains is a flag used to track the relationship between
* capital-gains splits. Depending on its value, this flag indicates
@@ -202,28 +202,6 @@ void DxaccSplitSetShareAmount (Split *split, double amount);
\********************************************************************/
-#define DATE_CMP(aaa,bbb,field) { \
- /* if dates differ, return */ \
- if ( (aaa->field.tv_sec) < \
- (bbb->field.tv_sec)) { \
- return -1; \
- } else \
- if ( (aaa->field.tv_sec) > \
- (bbb->field.tv_sec)) { \
- return +1; \
- } \
- \
- /* else, seconds match. check nanoseconds */ \
- if ( (aaa->field.tv_nsec) < \
- (bbb->field.tv_nsec)) { \
- return -1; \
- } else \
- if ( (aaa->field.tv_nsec) > \
- (bbb->field.tv_nsec)) { \
- return +1; \
- } \
-}
-
#define CHECK_GAINS_STATUS(s) \
if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus(s);
diff --git a/libgnucash/engine/TransLog.c b/libgnucash/engine/TransLog.c
index b88d982..50b9ae7 100644
--- a/libgnucash/engine/TransLog.c
+++ b/libgnucash/engine/TransLog.c
@@ -244,7 +244,7 @@ xaccTransWriteLog (Transaction *trans, char flag)
for (node = trans->splits; node; node = node->next)
{
- Timespec ts;
+ time64 time;
Split *split = node->data;
const char * accname = "";
char acc_guid_str[GUID_ENCODING_LENGTH + 1];
@@ -261,8 +261,7 @@ xaccTransWriteLog (Transaction *trans, char flag)
acc_guid_str[0] = '\0';
}
- timespecFromTime64(&ts, split->date_reconciled.tv_sec);
- gnc_timespec_to_iso8601_buff (ts, drecn);
+ gnc_time64_to_iso8601_buff (split->date_reconciled, drecn);
guid_to_string_buff (xaccSplitGetGUID(split), split_guid_str);
amt = xaccSplitGetAmount (split);
diff --git a/libgnucash/engine/Transaction.c b/libgnucash/engine/Transaction.c
index 2223c89..17e8608 100644
--- a/libgnucash/engine/Transaction.c
+++ b/libgnucash/engine/Transaction.c
@@ -310,6 +310,7 @@ gnc_transaction_get_property(GObject* object,
{
Transaction* tx;
gchar *key;
+ Time64 time;
g_return_if_fail(GNC_IS_TRANSACTION(object));
@@ -326,10 +327,12 @@ gnc_transaction_get_property(GObject* object,
g_value_take_object(value, tx->common_currency);
break;
case PROP_POST_DATE:
- g_value_set_boxed(value, &tx->date_posted);
+ time.t = tx->date_posted;
+ g_value_set_boxed(value, &time);
break;
case PROP_ENTER_DATE:
- g_value_set_boxed(value, &tx->date_entered);
+ time.t = tx->date_entered;
+ g_value_set_boxed(value, &time);
break;
case PROP_INVOICE:
qof_instance_get_kvp (QOF_INSTANCE (tx), value, 2, GNC_INVOICE_ID, GNC_INVOICE_GUID);
@@ -530,8 +533,12 @@ xaccTransDump (const Transaction *trans, const char *tag)
GList *node;
printf("%s Trans %p", tag, trans);
- printf(" Entered: %s\n", gnc_print_date(trans->date_entered));
- printf(" Posted: %s\n", gnc_print_date(trans->date_posted));
+ memset(datebuff, 0, sizeof(datebuff));
+ qof_print_date_buff(datebuff, sizeof(datebuff), trans->date_entered);
+ printf(" Entered: %s\n", datebuff);
+ memset(datebuff, 0, sizeof(datebuff));
+ qof_print_date_buff(datebuff, sizeof(datebuff), trans->date_posted);
+ printf(" Posted: %s\n", datebuff);
printf(" Num: %s\n", trans->num ? trans->num : "(null)");
printf(" Description: %s\n",
trans->description ? trans->description : "(null)");
@@ -1955,7 +1962,7 @@ xaccTransSetDatePostedSecs (Transaction *trans, time64 secs)
{
if (!trans) return;
xaccTransSetDateInternal(trans, &trans->date_posted, secs);
- set_gains_date_dirty (trans);
+ set_gains_date_dirty(trans);
}
void
@@ -1974,7 +1981,7 @@ xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
/* We additionally save this date into a kvp frame to ensure in
* the future a date which was set as *date* (without time) can
- * clearly be distinguished from the Timespec. */
+ * clearly be distinguished from the time64. */
g_value_init (&v, G_TYPE_DATE);
g_value_set_boxed (&v, &date);
qof_instance_set_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_DATE_POSTED);
@@ -1992,25 +1999,21 @@ xaccTransSetDateEnteredSecs (Transaction *trans, time64 secs)
}
static void
-qofTransSetDatePosted (Transaction *trans, Timespec ts)
+qofTransSetDatePosted (Transaction *trans, time64 time)
{
if (!trans) return;
- if ((ts.tv_nsec == 0) && (ts.tv_sec == 0)) return;
if (!qof_begin_edit(&trans->inst)) return;
- xaccTransSetDateInternal(trans, &trans->date_posted, ts.tv_sec);
+ xaccTransSetDateInternal(trans, &trans->date_posted, time);
set_gains_date_dirty(trans);
qof_commit_edit(&trans->inst);
}
static void
-qofTransSetDateEntered (Transaction *trans, Timespec ts)
+qofTransSetDateEntered (Transaction *trans, time64 time)
{
- /*This is called from the query framework, so we'll leave the timespec
- * until the query framework is converted, too.*/
if (!trans) return;
- if ((ts.tv_nsec == 0) && (ts.tv_sec == 0)) return;
if (!qof_begin_edit(&trans->inst)) return;
- xaccTransSetDateInternal(trans, &trans->date_entered, ts.tv_sec);
+ xaccTransSetDateInternal(trans, &trans->date_entered, time);
qof_commit_edit(&trans->inst);
}
@@ -2383,7 +2386,7 @@ xaccTransGetDatePostedGDate (const Transaction *trans)
/* Well, this txn doesn't have a GDate saved in a
* slot. Avoid getting the date in the local TZ by
* converting to UTC before generating the
- * date. (timespec_to_gdate doesn't do this so don't use
+ * date. (time64_to_gdate doesn't do this so don't use
* it.
*/
time64 time = xaccTransGetDate(trans);
@@ -2414,7 +2417,7 @@ xaccTransRetDateDue(const Transaction *trans)
if (!trans) return 0;
qof_instance_get_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_DUE_KVP);
if (G_VALUE_HOLDS_BOXED (&v))
- ret = ((Timespec*)g_value_get_boxed (&v))->tv_sec;
+ ret = ((Time64*)g_value_get_boxed (&v))->t;
if (!ret)
return xaccTransRetDatePosted (trans);
return ret;
@@ -2654,7 +2657,7 @@ xaccTransVoid(Transaction *trans, const char *reason)
g_value_set_string (&v, reason);
qof_instance_set_kvp (QOF_INSTANCE (trans), &v, 1, void_reason_str);
- gnc_timespec_to_iso8601_buff (timespec_now (), iso8601_str);
+ gnc_time64_to_iso8601_buff (gnc_time(NULL), iso8601_str);
g_value_set_string (&v, iso8601_str);
qof_instance_set_kvp (QOF_INSTANCE (trans), &v, 1, void_time_str);
@@ -2939,39 +2942,6 @@ trans_is_balanced_p (const Transaction *trans)
return trans ? xaccTransIsBalanced(trans) : FALSE;
}
-static Timespec
-xaccTransRetDateEnteredTS (Transaction * trans)
-{
- Timespec ret = {xaccTransRetDateEntered (trans), 0};
- return ret;
-}
-
-static void
-qofTransSetDateEnteredTS (Transaction * trans, Timespec t)
-{
- xaccTransSetDateEnteredSecs (trans, t.tv_sec);
-}
-
-static Timespec
-xaccTransRetDatePostedTS (Transaction * trans)
-{
- Timespec ret = {xaccTransRetDatePosted (trans), 0};
- return ret;
-}
-
-static void
-qofTransSetDatePostedTS (Transaction * trans, Timespec t)
-{
- xaccTransSetDatePostedSecs (trans, t.tv_sec);
-}
-
-static Timespec
-xaccTransRetDateDueTS (Transaction * trans)
-{
- Timespec ret = {xaccTransRetDateDue (trans), 0};
- return ret;
-}
-
gboolean xaccTransRegister (void)
{
static QofParam params[] =
diff --git a/libgnucash/engine/cap-gains.c b/libgnucash/engine/cap-gains.c
index 9d14d9e..f32f154 100644
--- a/libgnucash/engine/cap-gains.c
+++ b/libgnucash/engine/cap-gains.c
@@ -106,23 +106,21 @@ struct find_lot_s
{
GNCLot *lot;
gnc_commodity *currency;
- Timespec ts;
+ time64 time;
int (*numeric_pred)(gnc_numeric);
- gboolean (*date_pred)(Timespec e, Timespec tr);
+ gboolean (*date_pred)(time64 e, time64 tr);
};
static gboolean
-earliest_pred (Timespec earl, Timespec tran)
+earliest_pred (time64 earl, time64 tran)
{
- return ((earl.tv_sec > tran.tv_sec) ||
- ((earl.tv_sec == tran.tv_sec) && (earl.tv_nsec > tran.tv_nsec)));
+ return earl > tran;
}
static gboolean
-latest_pred (Timespec earl, Timespec tran)
+latest_pred (time64 earl, time64 tran)
{
- return ((earl.tv_sec < tran.tv_sec) ||
- ((earl.tv_sec == tran.tv_sec) && (earl.tv_nsec < tran.tv_nsec)));
+ return earl < tran;
}
static gpointer
@@ -133,7 +131,7 @@ finder_helper (GNCLot *lot, gpointer user_data)
Transaction *trans;
gnc_numeric bal;
gboolean opening_is_positive, bal_is_positive;
- Timespec posted_ts = {0,0};
+ time64 posted = 0;
if (gnc_lot_is_closed (lot)) return NULL;
@@ -158,10 +156,10 @@ finder_helper (GNCLot *lot, gpointer user_data)
return NULL;
}
- posted_ts.tv_sec = trans->date_posted;
- if (els->date_pred (els->ts, posted_ts))
+ posted = trans->date_posted;
+ if (els->date_pred (els->time, posted))
{
- els->ts.tv_sec = trans->date_posted;
+ els->time = trans->date_posted;
els->lot = lot;
}
@@ -172,14 +170,13 @@ static inline GNCLot *
xaccAccountFindOpenLot (Account *acc, gnc_numeric sign,
gnc_commodity *currency,
gint64 guess,
- gboolean (*date_pred)(Timespec, Timespec))
+ gboolean (*date_pred)(time64, time64))
{
struct find_lot_s es;
es.lot = NULL;
es.currency = currency;
- es.ts.tv_sec = guess;
- es.ts.tv_nsec = 0;
+ es.time = guess;
es.date_pred = date_pred;
if (gnc_numeric_positive_p(sign)) es.numeric_pred = gnc_numeric_negative_p;
@@ -324,13 +321,12 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot)
/* If we are here, then (cmp == +1 iff (amt > baln)) and we need
* to split up the split into pieces. Do it. */
{
- time64 now = gnc_time (NULL);
+ time64 now = gnc_time (NULL), time = 0;
Split * new_split;
gnc_numeric amt_a, amt_b, amt_tot;
gnc_numeric val_a, val_b, val_tot;
gnc_numeric frac;
Transaction *trans;
- Timespec ts;
acc = split->acc;
xaccAccountBeginEdit (acc);
@@ -400,8 +396,8 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot)
* split-action which is the same as xaccSplitGetAction */
gnc_set_num_action(NULL, new_split, NULL, gnc_get_num_action(NULL, split));
xaccSplitSetReconcile (new_split, xaccSplitGetReconcile (split));
- ts = xaccSplitRetDateReconciledTS (split);
- xaccSplitSetDateReconciledTS (new_split, &ts);
+ time = xaccSplitGetDateReconciled (split);
+ xaccSplitSetDateReconciledSecs (new_split, time);
/* Set the lot-split and peer_guid properties on the two
* splits to indicate that they're linked.
diff --git a/libgnucash/engine/engine-helpers.c b/libgnucash/engine/engine-helpers.c
index f589346..f078c30 100644
--- a/libgnucash/engine/engine-helpers.c
+++ b/libgnucash/engine/engine-helpers.c
@@ -51,34 +51,6 @@ cannot be considered "standard" or public parts of QOF. */
static QofLogModule log_module = GNC_MOD_ENGINE;
-Timespec
-gnc_transaction_get_date_posted(const Transaction *t)
-{
- Timespec ret = {xaccTransRetDatePosted(t), 0};
- return ret;
-}
-
-Timespec
-gnc_transaction_get_date_entered(const Transaction *t)
-{
- Timespec result = {xaccTransRetDateEntered(t), 0};
- return result;
-}
-
-Timespec
-gnc_split_get_date_reconciled(const Split *s)
-{
- Timespec result;
- xaccSplitGetDateReconciledTS(s, &result);
- return(result);
-}
-
-void
-gnc_transaction_set_date(Transaction *t, Timespec ts)
-{
- xaccTransSetDatePostedSecs(t, ts.tv_sec);
-}
-
/** Gets the transaction Number or split Action based on book option:
* if the book option is TRUE (split action is used for NUM) and a
* split is provided, split-action is returned; if book option is FALSE
diff --git a/libgnucash/engine/engine-helpers.h b/libgnucash/engine/engine-helpers.h
index 757b5b4..6fc38a3 100644
--- a/libgnucash/engine/engine-helpers.h
+++ b/libgnucash/engine/engine-helpers.h
@@ -34,13 +34,6 @@
typedef void (*GncBOCb) (gpointer new_val, gpointer user_data);
-Timespec gnc_transaction_get_date_posted(const Transaction *t);
-Timespec gnc_transaction_get_date_entered(const Transaction *t);
-
-Timespec gnc_split_get_date_reconciled(const Split *s);
-
-void gnc_transaction_set_date(Transaction *t, Timespec ts);
-
/** Gets the transaction Number or split Action based on book option:
* if the book option is TRUE (split action is used for NUM) and a
* split is provided, split-action is returned; if book option is FALSE
diff --git a/libgnucash/engine/qofinstance-p.h b/libgnucash/engine/qofinstance-p.h
index 801663c..8fcff1b 100644
--- a/libgnucash/engine/qofinstance-p.h
+++ b/libgnucash/engine/qofinstance-p.h
@@ -144,7 +144,7 @@ int qof_instance_compare_kvp (const QofInstance *a, const QofInstance *b);
/** Returns a g_strdup'd string which must be g_freed. */
char* qof_instance_kvp_as_string (const QofInstance *inst);
void qof_instance_kvp_add_guid (const QofInstance *inst, const char* path,
- const Timespec time, const char* key,
+ time64 time, const char* key,
const GncGUID *guid);
void qof_instance_kvp_remove_guid (const QofInstance *inst, const char *path,
const char* key, const GncGUID *guid);
diff --git a/libgnucash/engine/qofinstance.cpp b/libgnucash/engine/qofinstance.cpp
index 0ce79c0..06ae8ca 100644
--- a/libgnucash/engine/qofinstance.cpp
+++ b/libgnucash/engine/qofinstance.cpp
@@ -1138,13 +1138,13 @@ qof_instance_kvp_as_string (const QofInstance *inst)
void
qof_instance_kvp_add_guid (const QofInstance *inst, const char* path,
- const Timespec time, const char *key,
+ time64 time, const char *key,
const GncGUID *guid)
{
g_return_if_fail (inst->kvp_data != NULL);
auto container = new KvpFrame;
- Time64 t{time.tv_sec};
+ Time64 t{time};
container->set({key}, new KvpValue(const_cast<GncGUID*>(guid)));
container->set({"date"}, new KvpValue(t));
delete inst->kvp_data->set_path({path}, new KvpValue(container));
diff --git a/libgnucash/engine/test-core/test-engine-stuff.cpp b/libgnucash/engine/test-core/test-engine-stuff.cpp
index a1da304..24caa5a 100644
--- a/libgnucash/engine/test-core/test-engine-stuff.cpp
+++ b/libgnucash/engine/test-core/test-engine-stuff.cpp
@@ -1267,7 +1267,7 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
const gchar *str;
gnc_commodity *com;
int scu, denom;
- Timespec *ts;
+ time64 time;
com = xaccTransGetCurrency (trn);
scu = gnc_commodity_get_fraction(com);
@@ -1281,9 +1281,8 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
xaccSplitSetReconcile(ret, possible_chars[get_random_int_in_range(0, 3)]);
- ts = get_random_timespec();
- xaccSplitSetDateReconciledTS(ret, ts);
- g_free(ts);
+ time = get_random_time();
+ xaccSplitSetDateReconciledSecs (ret, time);
/* Split must be in an account before we can set an amount */
/* and in a transaction before it can be added to an account. */
@@ -1364,7 +1363,7 @@ void
make_random_changes_to_split (Split *split)
{
Transaction *trans;
- Timespec *ts;
+ time64 time;
g_return_if_fail (split);
@@ -1377,9 +1376,8 @@ make_random_changes_to_split (Split *split)
xaccSplitSetReconcile (split, possible_chars[get_random_int_in_range(0, 3)]);
- ts = get_random_timespec();
- xaccSplitSetDateReconciledTS (split, ts);
- g_free(ts);
+ time = get_random_time();
+ xaccSplitSetDateReconciledSecs (split, time);
qof_instance_set_slots (QOF_INSTANCE (split), get_random_kvp_frame());
diff --git a/libgnucash/engine/test/utest-Split.cpp b/libgnucash/engine/test/utest-Split.cpp
index bbf296f..bdc8f3e 100644
--- a/libgnucash/engine/test/utest-Split.cpp
+++ b/libgnucash/engine/test/utest-Split.cpp
@@ -65,7 +65,7 @@ setup (Fixture *fixture, gconstpointer pData)
GNCLot *lot = gnc_lot_new (book);
gnc_numeric value = gnc_numeric_create (123, 240);
gnc_numeric amount = gnc_numeric_create (321, 1000);
- Timespec time = timespec_now ();
+ time64 time = gnc_time(NULL);
Split *gains_split = xaccMallocSplit (book);
fixture->curr = gnc_commodity_new (book, "Gnu Rand", "CURRENCY", "GNR", "", 240);
fixture->comm = gnc_commodity_new (book, "Wildebeest Fund", "FUND", "WBFXX", "", 1000);
@@ -303,7 +303,7 @@ test_xaccDupeSplit (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (split->action, ==, f_split->action);
g_assert (compare (split->inst.kvp_data, f_split->inst.kvp_data) == 0);
g_assert_cmpint (split->reconciled, ==, f_split->reconciled);
- g_assert (timespec_equal (&(split->date_reconciled), &(f_split->date_reconciled)));
+ g_assert_cmpint (split->date_reconciled, ==, f_split->date_reconciled);
g_assert (gnc_numeric_equal (split->value, f_split->value));
g_assert (gnc_numeric_equal (split->amount, f_split->amount));
/* xaccDupeSplit intentionally doesn't copy the balances */
@@ -338,7 +338,7 @@ test_xaccSplitCloneNoKvp (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (split->action, ==, f_split->action);
g_assert (split->inst.kvp_data->empty());
g_assert_cmpint (split->reconciled, ==, f_split->reconciled);
- g_assert (timespec_equal (&(split->date_reconciled), &(f_split->date_reconciled)));
+ g_assert_cmpint (split->date_reconciled, == , f_split->date_reconciled);
g_assert (gnc_numeric_equal (split->value, f_split->value));
g_assert (gnc_numeric_equal (split->amount, f_split->amount));
g_assert (gnc_numeric_equal (split->balance, f_split->balance));
@@ -1204,14 +1204,14 @@ test_xaccSplitOrder (Fixture *fixture, gconstpointer pData)
o_split->value = split->value;
/* Make sure that it doesn't crash if o_split->date_reconciled == NULL */
g_assert_cmpint (xaccSplitOrder (split, o_split), ==, 1);
- o_split->date_reconciled = timespec_now();
- o_split->date_reconciled.tv_sec -= 50;
+ o_split->date_reconciled = gnc_time(NULL);
+ o_split->date_reconciled -= 50;
g_assert_cmpint (xaccSplitOrder (split, o_split), ==, 1);
- o_split->date_reconciled.tv_sec += 100;
+ o_split->date_reconciled += 100;
g_assert_cmpint (xaccSplitOrder (split, o_split), ==, -1);
- o_split->date_reconciled.tv_sec = split->date_reconciled.tv_sec;
- o_split->date_reconciled.tv_nsec = split->date_reconciled.tv_nsec;
+ o_split->date_reconciled = split->date_reconciled;
+ o_split->date_reconciled = split->date_reconciled;
g_assert_cmpint (xaccSplitOrder (split, o_split), ==,
qof_instance_guid_compare (split, o_split));
diff --git a/libgnucash/engine/test/utest-Transaction.cpp b/libgnucash/engine/test/utest-Transaction.cpp
index 370addb..4a3e93c 100644
--- a/libgnucash/engine/test/utest-Transaction.cpp
+++ b/libgnucash/engine/test/utest-Transaction.cpp
@@ -408,7 +408,8 @@ test_gnc_transaction_set_get_property (Fixture *fixture, gconstpointer pData)
gchar *t_num = NULL, *t_desc = NULL;
gnc_commodity *curr = gnc_commodity_new (book, "Gnu Rand", "CURRENCY",
"GNR", "", 240), *t_curr = NULL;
- Timespec now = timespec_now (), *t_entered = NULL, *t_posted = NULL;
+ time64 now = gnc_time(NULL);
+ Time64 *t_entered, *t_posted;
g_assert_cmpstr (txn->num, ==, "");
g_assert_cmpstr (txn->description, ==, "");
g_assert (txn->common_currency == NULL);
@@ -427,8 +428,8 @@ test_gnc_transaction_set_get_property (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (txn->num, ==, num);
g_assert_cmpstr (txn->description, ==, desc);
g_assert (txn->common_currency == curr);
- g_assert (txn->date_entered == now.tv_sec);
- g_assert (txn->date_posted == now.tv_sec);
+ g_assert (txn->date_entered == now);
+ g_assert (txn->date_posted == now);
g_object_get (G_OBJECT (txn),
"num", &t_num,
@@ -441,8 +442,8 @@ test_gnc_transaction_set_get_property (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (t_num, ==, num);
g_assert_cmpstr (t_desc, ==, desc);
g_assert (t_curr == curr);
- g_assert (t_entered->tv_sec == now.tv_sec);
- g_assert (t_posted->tv_sec == now.tv_sec);
+ g_assert_cmpint (t_entered->t, ==, now);
+ g_assert_cmpint (t_posted->t, ==, now);
xaccTransRollbackEdit (txn);
test_destroy (txn);
test_destroy (curr);
@@ -1772,10 +1773,7 @@ test_xaccTransOrder_num_action (Fixture *fixture, gconstpointer pData)
* xaccTransSetDatePostedSecs C: 17 in 13 Local: 0:0:0
* xaccTransSetDatePostedGDate C: 1 Local: 1:0:0
* xaccTransSetDateEnteredSecs C: 10 in 9 Local: 0:0:0
- * xaccTransSetDatePostedTS C: 9 in 8 Local: 2:0:0
- * xaccTransSetDateEnteredTS C: 3 in 3 Local: 1:0:0
* xaccTransSetDate C: 43 in 23 SCM: 2 in 2 Local: 0:0:0
- * xaccTransSetDateDueTS C: 2 in 2 Local: 0:0:0
* xaccTransSetTxnType C: 4 in 3 Local: 0:0:0
* xaccTransClearReadOnly C: 4 in 2 Local: 1:0:0
* xaccTransSetReadOnly C: 2 in 2 Local: 1:0:0
@@ -1843,7 +1841,7 @@ test_xaccTransVoid (Fixture *fixture, gconstpointer pData)
auto frame = fixture->txn->inst.kvp_data;
auto void_reason = "Voided for Unit Test";
auto txn_notes = g_strdup (frame->get_slot({trans_notes_str})->get<const char*>());
- Timespec now = timespec_now ();
+ time64 now = gnc_time(NULL);
char iso8601_str[ISO_DATELENGTH + 1] = "";
GList *split = NULL;
@@ -1854,7 +1852,7 @@ test_xaccTransVoid (Fixture *fixture, gconstpointer pData)
==, txn_notes);
g_assert_cmpstr (frame->get_slot({void_reason_str})->get<const char*>(), ==,
void_reason);
- gnc_timespec_to_iso8601_buff (now, iso8601_str);
+ gnc_time64_to_iso8601_buff (now, iso8601_str);
g_assert_cmpstr (frame->get_slot({void_time_str})->get<const char*>(), ==,
iso8601_str);
g_assert_cmpstr (frame->get_slot({TRANS_READ_ONLY_REASON})->get<const char*>(),
commit fee589b28cb0c554109cb934c24fa573c1dd9757
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 2 15:46:27 2018 -0700
Remove Timespec from pricedb.
Includes removing the time64 specialized functions because the regular ones
handle time64 now.
diff --git a/bindings/python/gnucash_core.py b/bindings/python/gnucash_core.py
index 43fdabc..58e9429 100644
--- a/bindings/python/gnucash_core.py
+++ b/bindings/python/gnucash_core.py
@@ -375,10 +375,10 @@ class GncPriceDB(GnuCashCoreClass):
GncPriceDB.add_methods_with_prefix('gnc_pricedb_')
PriceDB_dict = {
'lookup_latest' : GncPrice,
- 'lookup_nearest_in_time' : GncPrice,
- 'lookup_latest_before' : GncPrice,
+ 'lookup_nearest_in_time64' : GncPrice,
+ 'lookup_latest_before_t64' : GncPrice,
'convert_balance_latest_price' : GncNumeric,
- 'convert_balance_nearest_price' : GncNumeric,
+ 'convert_balance_nearest_price_t64' : GncNumeric,
}
methods_return_instance(GncPriceDB,PriceDB_dict)
GncPriceDB.get_prices = method_function_returns_instance_list(
diff --git a/gnucash/gnome-utils/dialog-transfer.c b/gnucash/gnome-utils/dialog-transfer.c
index fb15697..f77a972 100644
--- a/gnucash/gnome-utils/dialog-transfer.c
+++ b/gnucash/gnome-utils/dialog-transfer.c
@@ -266,7 +266,7 @@ lookup_price(PriceReq *pr, PriceDate pd)
break;
case NEAREST:
prc = gnc_pricedb_lookup_nearest_in_time64 (pr->pricedb, pr->from,
- pr->to, pr->time);
+ pr->to, pr->time);
break;
case LATEST:
prc = gnc_pricedb_lookup_latest (pr->pricedb, pr->from, pr->to);
diff --git a/gnucash/gnome-utils/gnc-tree-model-price.c b/gnucash/gnome-utils/gnc-tree-model-price.c
index 2192806..3656ec0 100644
--- a/gnucash/gnome-utils/gnc-tree-model-price.c
+++ b/gnucash/gnome-utils/gnc-tree-model-price.c
@@ -770,7 +770,7 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
break;
case GNC_TREE_MODEL_PRICE_COL_DATE:
qof_print_date_buff (datebuff, sizeof(datebuff),
- gnc_price_get_time (price));
+ gnc_price_get_time64 (price));
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, datebuff);
break;
diff --git a/gnucash/gnome-utils/window-main-summarybar.c b/gnucash/gnome-utils/window-main-summarybar.c
index 700c94d..aa56466 100644
--- a/gnucash/gnome-utils/window-main-summarybar.c
+++ b/gnucash/gnome-utils/window-main-summarybar.c
@@ -189,10 +189,11 @@ gnc_ui_accounts_recurse (Account *parent, GList **currency_list,
case ACCT_TYPE_RECEIVABLE:
end_amount = xaccAccountGetBalanceAsOfDate(account, options.end_date);
end_amount_default_currency =
- gnc_pricedb_convert_balance_nearest_price (pricedb, end_amount,
- account_currency,
- to_curr,
- options.end_date);
+ gnc_pricedb_convert_balance_nearest_price_t64 (pricedb,
+ end_amount,
+ account_currency,
+ to_curr,
+ options.end_date);
if (!non_currency || options.non_currency)
{
@@ -224,17 +225,18 @@ gnc_ui_accounts_recurse (Account *parent, GList **currency_list,
case ACCT_TYPE_EXPENSE:
start_amount = xaccAccountGetBalanceAsOfDate(account, options.start_date);
start_amount_default_currency =
- gnc_pricedb_convert_balance_nearest_price (pricedb,
- start_amount,
- account_currency,
- to_curr,
- options.start_date);
+ gnc_pricedb_convert_balance_nearest_price_t64 (pricedb,
+ start_amount,
+ account_currency,
+ to_curr,
+ options.start_date);
end_amount = xaccAccountGetBalanceAsOfDate(account, options.end_date);
end_amount_default_currency =
- gnc_pricedb_convert_balance_nearest_price (pricedb, end_amount,
- account_currency,
- to_curr,
- options.end_date);
+ gnc_pricedb_convert_balance_nearest_price_t64 (pricedb,
+ end_amount,
+ account_currency,
+ to_curr,
+ options.end_date);
if (!non_currency || options.non_currency)
{
diff --git a/gnucash/report/locale-specific/us/taxtxf.scm b/gnucash/report/locale-specific/us/taxtxf.scm
index 1ec3fff..67b5a67 100644
--- a/gnucash/report/locale-specific/us/taxtxf.scm
+++ b/gnucash/report/locale-specific/us/taxtxf.scm
@@ -712,7 +712,7 @@
(begin ;; do so
(set! missing-pricedb-entry? #f)
(set! pricedb-lookup-price
- (let ((price (gnc-pricedb-lookup-nearest-in-time64
+ (let ((price (gnc-pricedb-lookup-nearest-in-time-t64
pricedb
account-commodity
USD-currency
@@ -725,9 +725,8 @@
(gnc-price-get-value
pricedb-lookup-price))
(set! pricedb-lookup-price-time
- (gnc-price-get-time64
- pricedb-lookup-price))
- (gnc-pricedb-convert-balance-nearest-price
+ (gnc-price-get-time64 pricedb-lookup-price))
+ (gnc-pricedb-convert-balance-nearest-price-t64
pricedb
(if neg?
(gnc-numeric-neg splt-rpt-amount)
diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index a6b8bbd..6d7b5dc 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -794,7 +794,7 @@
(gnc:exchange-if-same foreign domestic)
(gnc:make-gnc-monetary
domestic
- (gnc-pricedb-convert-balance-nearest-price
+ (gnc-pricedb-convert-balance-nearest-price-t64
(gnc-pricedb-get-db (gnc-get-current-book))
(gnc:gnc-monetary-amount foreign)
(gnc:gnc-monetary-commodity foreign)
diff --git a/libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp b/libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp
index fbde09a..a8d228f 100644
--- a/libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp
@@ -115,8 +115,7 @@ price_parse_xml_sub_node (GNCPrice* p, xmlNodePtr sub_node, QofBook* book)
{
time64 time = dom_tree_to_time64 (sub_node);
if (!dom_tree_valid_time64 (time, sub_node->name)) time = 0;
- Timespec ts {time, 0};
- gnc_price_set_time (p, ts);
+ gnc_price_set_time64 (p, time);
}
else if (g_strcmp0 ("price:source", (char*)sub_node->name) == 0)
{
@@ -416,7 +415,7 @@ gnc_price_to_dom_tree (const xmlChar* tag, GNCPrice* price)
xmlNodePtr tmpnode;
gnc_commodity* commodity;
gnc_commodity* currency;
- Timespec timesp;
+ time64 time;
gnc_numeric value;
if (! (tag && price)) return NULL;
@@ -438,8 +437,8 @@ gnc_price_to_dom_tree (const xmlChar* tag, GNCPrice* price)
tmpnode = commodity_ref_to_dom_tree ("price:currency", currency);
if (!add_child_or_kill_parent (price_xml, tmpnode)) return NULL;
- timesp = gnc_price_get_time (price);
- tmpnode = time64_to_dom_tree ("price:time", timesp.tv_sec);
+ time = gnc_price_get_time64 (price);
+ tmpnode = time64_to_dom_tree ("price:time", time);
if (!add_child_or_kill_parent (price_xml, tmpnode)) return NULL;
sourcestr = gnc_price_get_source_string (price);
diff --git a/libgnucash/backend/xml/io-gncxml-v1.cpp b/libgnucash/backend/xml/io-gncxml-v1.cpp
index c25b5cd..4a605ff 100644
--- a/libgnucash/backend/xml/io-gncxml-v1.cpp
+++ b/libgnucash/backend/xml/io-gncxml-v1.cpp
@@ -2961,8 +2961,7 @@ price_parse_xml_sub_node (GNCPrice* p, xmlNodePtr sub_node, QofBook* book)
{
time64 time = dom_tree_to_time64 (sub_node);
if (!dom_tree_valid_time64 (time, sub_node->name)) time = 0;
- Timespec ts = {time, 0};
- gnc_price_set_time (p, ts);
+ gnc_price_set_time64 (p, time);
}
else if (g_strcmp0 ("price:source", (char*)sub_node->name) == 0)
{
diff --git a/libgnucash/doc/design/engine.texi b/libgnucash/doc/design/engine.texi
index dea627e..2c1baf0 100644
--- a/libgnucash/doc/design/engine.texi
+++ b/libgnucash/doc/design/engine.texi
@@ -1551,7 +1551,7 @@ Return the commodity of @var{p}.
Return the currency of @var{p}.
@end deftypefun
- at deftypefun Timespec gnc_price_get_time (GNCPrice * @var{p})
+ at deftypefun time64 gnc_price_get_time64 (GNCPrice * @var{p})
Return the time of @var{p}.
@end deftypefun
@@ -1596,7 +1596,7 @@ Set the commodity of @var{p} to @var{c}.
Set the currency of @var{p} to @var{c}.
@end deftypefun
- at deftypefun void gnc_price_set_time (GNCPrice * @var{p}, Timespec @var{t})
+ at deftypefun void gnc_price_set_time64 (GNCPrice * @var{p}, time64 @var{t})
Set the time of @var{p} to @var{t}.
@end deftypefun
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 5379b0a..141609d 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -3441,7 +3441,7 @@ xaccAccountConvertBalanceToCurrencyAsOfDate(const Account *acc, /* for book */
book = gnc_account_get_book (acc);
pdb = gnc_pricedb_get_db (book);
- balance = gnc_pricedb_convert_balance_nearest_price(
+ balance = gnc_pricedb_convert_balance_nearest_price_t64(
pdb, balance, balance_currency, new_currency, date);
return balance;
diff --git a/libgnucash/engine/engine.i b/libgnucash/engine/engine.i
index 45c62d6..9cc7c9d 100644
--- a/libgnucash/engine/engine.i
+++ b/libgnucash/engine/engine.i
@@ -97,10 +97,14 @@ functions. */
%newobject gnc_pricedb_lookup_latest_any_currency;
%newobject gnc_pricedb_lookup_nearest_in_time_any_currency;
+%newobject gnc_pricedb_lookup_nearest_in_time_any_currency_t64;
%newobject gnc_pricedb_lookup_latest_before_any_currency;
+%newobject gnc_pricedb_lookup_latest_before_any_currency_t64;
%newobject gnc_pricedb_get_prices;
%newobject gnc_pricedb_lookup_at_time;
+%newobject gnc_pricedb_lookup_at_time64;
%newobject gnc_pricedb_lookup_day;
+%newobject gnc_pricedb_lookup_day_t64;
%newobject xaccQueryGetSplitsUniqueTrans;
%newobject xaccQueryGetTransactions;
diff --git a/libgnucash/engine/gnc-pricedb-p.h b/libgnucash/engine/gnc-pricedb-p.h
index 249580f..06c611e 100644
--- a/libgnucash/engine/gnc-pricedb-p.h
+++ b/libgnucash/engine/gnc-pricedb-p.h
@@ -38,7 +38,7 @@ struct gnc_price_s
GNCPriceDB *db;
gnc_commodity *commodity;
gnc_commodity *currency;
- Timespec tmspec;
+ time64 tmspec;
PriceSource source;
char *type;
gnc_numeric value;
@@ -82,7 +82,7 @@ typedef struct gnc_price_lookup_helper_s
{
GList **return_list;
gnc_commodity *key;
- Timespec time;
+ time64 time;
} GNCPriceLookupHelper;
#define gnc_price_set_guid(P,G) qof_instance_set_guid(QOF_INSTANCE(P),(G))
diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index d148570..e9f1594 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -27,6 +27,7 @@
#include <glib.h>
#include <string.h>
#include <stdint.h>
+#include <stdlib.h>
#include "gnc-date.h"
#include "gnc-pricedb-p.h"
#include <qofinstance-p.h>
@@ -38,7 +39,7 @@ static gboolean add_price(GNCPriceDB *db, GNCPrice *p);
static gboolean remove_price(GNCPriceDB *db, GNCPrice *p, gboolean cleanup);
static GNCPrice *lookup_nearest_in_time(GNCPriceDB *db, const gnc_commodity *c,
const gnc_commodity *currency,
- Timespec t, gboolean sameday);
+ time64 t, gboolean sameday);
static gboolean
pricedb_pricelist_traversal(GNCPriceDB *db,
gboolean (*f)(GList *p, gpointer user_data),
@@ -61,6 +62,13 @@ typedef struct
gpointer value;
} HashEntry;
+/* Like strcmp, returns -1 if a < b, +1 if a > b, and 0 if they're equal. */
+static inline int
+time64_cmp (time64 a, time64 b)
+{
+ return a < b ? -1 : a > b ? 1 : 0;
+}
+
static void
hash_entry_insert(gpointer key, gpointer val, gpointer user_data)
{
@@ -179,7 +187,7 @@ gnc_price_set_property(GObject* object, guint prop_id, const GValue* value, GPar
{
GNCPrice* price;
gnc_numeric* number;
- Timespec* ts;
+ Time64* time;
g_return_if_fail(GNC_IS_PRICE(object));
@@ -205,8 +213,8 @@ gnc_price_set_property(GObject* object, guint prop_id, const GValue* value, GPar
gnc_price_set_currency(price, g_value_get_object(value));
break;
case PROP_DATE:
- ts = g_value_get_boxed(value);
- gnc_price_set_time(price, *ts);
+ time = g_value_get_boxed(value);
+ gnc_price_set_time64(price, time->t);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -380,7 +388,7 @@ gnc_price_clone (GNCPrice* p, QofBook *book)
gnc_price_begin_edit(new_p);
/* never ever clone guid's */
gnc_price_set_commodity(new_p, gnc_price_get_commodity(p));
- gnc_price_set_time(new_p, gnc_price_get_time(p));
+ gnc_price_set_time64(new_p, gnc_price_get_time64(p));
gnc_price_set_source(new_p, gnc_price_get_source(p));
gnc_price_set_typestr(new_p, gnc_price_get_typestr(p));
gnc_price_set_value(new_p, gnc_price_get_value(p));
@@ -397,7 +405,7 @@ gnc_price_invert (GNCPrice *p)
GNCPrice *new_p = gnc_price_create (book);
qof_instance_copy_version(new_p, p);
gnc_price_begin_edit(new_p);
- gnc_price_set_time(new_p, gnc_price_get_time(p));
+ gnc_price_set_time64(new_p, gnc_price_get_time64(p));
gnc_price_set_source(new_p, PRICE_SOURCE_TEMP);
gnc_price_set_typestr(new_p, gnc_price_get_typestr(p));
gnc_price_set_commodity(new_p, gnc_price_get_currency(p));
@@ -499,10 +507,10 @@ gnc_price_set_currency(GNCPrice *p, gnc_commodity *c)
}
void
-gnc_price_set_time(GNCPrice *p, Timespec t)
+gnc_price_set_time64(GNCPrice *p, time64 t)
{
if (!p) return;
- if (!timespec_equal(&(p->tmspec), &t))
+ if (p->tmspec != t)
{
/* Changing the datestamp requires the hash table
* position to be modified. The easiest way of doing
@@ -519,27 +527,6 @@ gnc_price_set_time(GNCPrice *p, Timespec t)
}
void
-gnc_price_set_time64(GNCPrice *p, time64 t64)
-{
- if (!p) return;
- if (p->tmspec.tv_sec != t64) // do we need to check nsec as well?
- {
- /* Changing the datestamp requires the hash table
- * position to be modified. The easiest way of doing
- * this is to remove and reinsert. */
- gnc_price_ref (p);
- remove_price (p->db, p, FALSE);
- gnc_price_begin_edit (p);
- p->tmspec.tv_sec = t64;
- p->tmspec.tv_nsec = 0;
- gnc_price_set_dirty(p);
- gnc_price_commit_edit (p);
- add_price (p->db, p);
- gnc_price_unref (p);
- }
-}
-
-void
gnc_price_set_source(GNCPrice *p, PriceSource s)
{
if (!p) return;
@@ -616,21 +603,7 @@ gnc_price_get_commodity(const GNCPrice *p)
time64
gnc_price_get_time64(const GNCPrice *p)
{
- if (!p) return 0;
- return p->tmspec.tv_sec;
-}
-
-Timespec
-gnc_price_get_time(const GNCPrice *p)
-{
- if (!p)
- {
- Timespec result;
- result.tv_sec = 0;
- result.tv_nsec = 0;
- return result;
- }
- return p->tmspec;
+ return p ? p->tmspec : 0;
}
PriceSource
@@ -675,8 +648,7 @@ gnc_price_get_currency(const GNCPrice *p)
gboolean
gnc_price_equal (const GNCPrice *p1, const GNCPrice *p2)
{
- Timespec ts1;
- Timespec ts2;
+ time64 time1, time2;
if (p1 == p2) return TRUE;
if (!p1 || !p2) return FALSE;
@@ -689,10 +661,10 @@ gnc_price_equal (const GNCPrice *p1, const GNCPrice *p2)
gnc_price_get_currency (p2)))
return FALSE;
- ts1 = gnc_price_get_time (p1);
- ts2 = gnc_price_get_time (p2);
+ time1 = gnc_price_get_time64 (p1);
+ time2 = gnc_price_get_time64 (p2);
- if (!timespec_equal (&ts1, &ts2))
+ if (time1 != time2)
return FALSE;
if (gnc_price_get_source (p1) != gnc_price_get_source (p2))
@@ -715,18 +687,18 @@ gnc_price_equal (const GNCPrice *p1, const GNCPrice *p2)
static gint
compare_prices_by_date(gconstpointer a, gconstpointer b)
{
- Timespec time_a;
- Timespec time_b;
+ time64 time_a, time_b;
gint result;
if (!a && !b) return 0;
/* nothing is always less than something */
if (!a) return -1;
- time_a = gnc_price_get_time((GNCPrice *) a);
- time_b = gnc_price_get_time((GNCPrice *) b);
+ time_a = gnc_price_get_time64((GNCPrice *) a);
+ time_b = gnc_price_get_time64((GNCPrice *) b);
- result = -timespec_cmp(&time_a, &time_b);
+ /* Note we return -1 if time_b is before time_a. */
+ result = time64_cmp(time_b, time_a);
if (result) return result;
/* For a stable sort */
@@ -745,17 +717,17 @@ price_list_is_duplicate( gpointer data, gpointer user_data )
{
GNCPrice* pPrice = (GNCPrice*)data;
PriceListIsDuplStruct* pStruct = (PriceListIsDuplStruct*)user_data;
- Timespec time_a, time_b;
+ time64 time_a, time_b;
- time_a = timespecCanonicalDayTime( gnc_price_get_time( pPrice ) );
- time_b = timespecCanonicalDayTime( gnc_price_get_time( pStruct->pPrice ) );
+ time_a = time64CanonicalDayTime( gnc_price_get_time64( pPrice ) );
+ time_b = time64CanonicalDayTime( gnc_price_get_time64( pStruct->pPrice ) );
/* If the date, currency, commodity and price match, it's a duplicate */
if ( !gnc_numeric_equal( gnc_price_get_value( pPrice ), gnc_price_get_value( pStruct->pPrice ) ) ) return;
if ( gnc_price_get_commodity( pPrice ) != gnc_price_get_commodity( pStruct->pPrice ) ) return;
if ( gnc_price_get_currency( pPrice ) != gnc_price_get_currency( pStruct->pPrice ) ) return;
- if ( timespec_cmp( &time_a, &time_b ) != 0 ) return;
+ if (time_a != time_b) return;
pStruct->isDupl = TRUE;
}
@@ -1137,7 +1109,7 @@ add_price(GNCPriceDB *db, GNCPrice *p)
* add this one. If this price is of equal or better precedence than the old
* one, copy this one over the old one.
*/
- old_price = gnc_pricedb_lookup_day (db, p->commodity, p->currency,
+ old_price = gnc_pricedb_lookup_day_t64 (db, p->commodity, p->currency,
p->tmspec);
if (!db->bulk_update && old_price != NULL)
{
@@ -1299,15 +1271,18 @@ gboolean
gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
{
gboolean rc;
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset(datebuff, 0, sizeof(datebuff));
if (!db || !p) return FALSE;
ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
db, p, qof_instance_get_dirty_flag(p),
qof_instance_get_destroying(p));
gnc_price_ref(p);
-
- DEBUG("Remove Date is %s, Commodity is %s, Source is %s", gnc_print_date (gnc_price_get_time (p)),
- gnc_commodity_get_fullname (gnc_price_get_commodity (p)), gnc_price_get_source_string (p));
+ qof_print_date_buff(datebuff, sizeof(datebuff), gnc_price_get_time64 (p));
+ DEBUG("Remove Date is %s, Commodity is %s, Source is %s", datebuff,
+ gnc_commodity_get_fullname (gnc_price_get_commodity (p)),
+ gnc_price_get_source_string (p));
rc = remove_price (db, p, TRUE);
gnc_pricedb_begin_edit(db);
@@ -1339,7 +1314,7 @@ check_one_price_date (GNCPrice *price, gpointer user_data)
{
remove_info *data = user_data;
PriceSource source;
- Timespec pt;
+ time64 time;
ENTER("price %p (%s), data %p", price,
gnc_commodity_get_mnemonic(gnc_price_get_commodity(price)),
@@ -1359,13 +1334,13 @@ check_one_price_date (GNCPrice *price, gpointer user_data)
return TRUE;
}
- pt = gnc_price_get_time (price);
+ time = gnc_price_get_time64 (price);
{
gchar buf[40];
- gnc_timespec_to_iso8601_buff(pt , buf);
+ gnc_time64_to_iso8601_buff(time, buf);
DEBUG("checking date %s", buf);
}
- if (pt.tv_sec < data->cutoff)
+ if (time < data->cutoff)
{
data->list = g_slist_prepend(data->list, price);
DEBUG("will delete");
@@ -1394,8 +1369,7 @@ pricedb_remove_foreach_pricelist (gpointer key,
static gint
compare_prices_by_commodity_date (gconstpointer a, gconstpointer b)
{
- Timespec time_a;
- Timespec time_b;
+ time64 time_a, time_b;
gnc_commodity *comma;
gnc_commodity *commb;
gnc_commodity *curra;
@@ -1419,10 +1393,11 @@ compare_prices_by_commodity_date (gconstpointer a, gconstpointer b)
if (!gnc_commodity_equal(curra, currb))
return gnc_commodity_compare(curra, currb);
- time_a = gnc_price_get_time((GNCPrice *) a);
- time_b = gnc_price_get_time((GNCPrice *) b);
+ time_a = gnc_price_get_time64((GNCPrice *) a);
+ time_b = gnc_price_get_time64((GNCPrice *) b);
- result = -timespec_cmp(&time_a, &time_b);
+ /* Note we return -1 if time_b is before time_a. */
+ result = time64_cmp(time_b, time_a);
if (result) return result;
/* For a stable sort */
@@ -1448,7 +1423,7 @@ price_commodity_and_currency_equal (GNCPrice *a, GNCPrice *b)
static void
gnc_pricedb_remove_old_prices_pinfo (GNCPrice *price, gboolean keep_message)
{
- GDate price_date = timespec_to_gdate (gnc_price_get_time (price));
+ GDate price_date = time64_to_gdate (gnc_price_get_time64 (price));
char date_buf[MAX_DATE_LENGTH+1];
if (g_date_valid (&price_date))
@@ -1557,8 +1532,8 @@ gnc_pricedb_process_removal_list (GNCPriceDB *db, GDate *fiscal_end_date,
}
// get the price dates
- saved_price_date = timespec_to_gdate (gnc_price_get_time (cloned_price));
- next_price_date = timespec_to_gdate (gnc_price_get_time (item->data));
+ saved_price_date = time64_to_gdate (gnc_price_get_time64 (cloned_price));
+ next_price_date = time64_to_gdate (gnc_price_get_time64 (item->data));
// Keep last price in fiscal year
if (keep == PRICE_REMOVE_KEEP_LAST_PERIOD && save_first_price == FALSE)
@@ -1632,7 +1607,7 @@ gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list,
remove_info data;
GList *node;
char datebuff[MAX_DATE_LENGTH + 1];
- memset (datebuff, sizeof(datebuff), 0);
+ memset (datebuff, 0, sizeof(datebuff));
data.db = db;
data.cutoff = cutoff;
@@ -1810,8 +1785,7 @@ pricedb_get_prices_internal(GNCPriceDB *db, const gnc_commodity *commodity,
return forward_list;
}
-GNCPrice *
-gnc_pricedb_lookup_latest(GNCPriceDB *db,
+GNCPrice *gnc_pricedb_lookup_latest(GNCPriceDB *db,
const gnc_commodity *commodity,
const gnc_commodity *currency)
{
@@ -1837,7 +1811,7 @@ typedef struct
{
GList **list;
const gnc_commodity *com;
- Timespec t;
+ time64 t;
} UsesCommodity;
/* price_list_scan_any_currency is the helper function used with
@@ -1875,8 +1849,8 @@ price_list_scan_any_currency(GList *price_list, gpointer data)
while (node != NULL)
{
GNCPrice *price = node->data;
- Timespec price_t = gnc_price_get_time(price);
- if (timespec_cmp(&price_t, &helper->t) < 0)
+ time64 price_t = gnc_price_get_time64(price);
+ if (price_t < helper->t)
{
/* If there is a previous price add it to the results. */
if (node->prev)
@@ -1917,7 +1891,7 @@ is_in_list (GList *list, const gnc_commodity *c)
* want only the first one before the specified time containing both the target
* and some other commodity. */
static PriceList*
-latest_before (PriceList *prices, const gnc_commodity* target, Timespec t)
+latest_before (PriceList *prices, const gnc_commodity* target, time64 t)
{
GList *node, *found_coms = NULL, *retval = NULL;
for (node = prices; node != NULL; node = g_list_next(node))
@@ -1925,8 +1899,8 @@ latest_before (PriceList *prices, const gnc_commodity* target, Timespec t)
GNCPrice *price = (GNCPrice*)node->data;
gnc_commodity *com = gnc_price_get_commodity(price);
gnc_commodity *cur = gnc_price_get_currency(price);
- Timespec price_t = gnc_price_get_time(price);
- if (timespec_cmp(&t, &price_t) <= 0 ||
+ time64 price_t = gnc_price_get_time64(price);
+ if (t < price_t ||
(com == target && is_in_list(found_coms, cur)) ||
(cur == target && is_in_list(found_coms, com)))
continue;
@@ -1957,14 +1931,14 @@ find_comtime(GPtrArray* array, gnc_commodity *com)
static GList*
add_nearest_price(GList *target_list, GPtrArray *price_array, GNCPrice *price,
- const gnc_commodity *target, Timespec t)
+ const gnc_commodity *target, time64 t)
{
gnc_commodity *com = gnc_price_get_commodity(price);
gnc_commodity *cur = gnc_price_get_currency(price);
- Timespec price_t = gnc_price_get_time(price);
+ time64 price_t = gnc_price_get_time64(price);
gnc_commodity *other = com == target ? cur : com;
GNCPrice **com_price = find_comtime(price_array, other);
- Timespec com_t;
+ time64 com_t;
if (com_price == NULL)
{
com_price = (GNCPrice**)g_slice_new(gpointer);
@@ -1972,19 +1946,19 @@ add_nearest_price(GList *target_list, GPtrArray *price_array, GNCPrice *price,
g_ptr_array_add(price_array, com_price);
/* If the first price we see for this commodity is not newer than
the target date add it to the return list. */
- if (timespec_cmp(&price_t, &t) <= 0)
+ if (price_t <= t)
{
gnc_price_ref(price);
target_list = g_list_prepend(target_list, price);
}
return target_list;
}
- com_t = gnc_price_get_time(*com_price);
- if (timespec_cmp(&com_t, &t) <= 0)
+ com_t = gnc_price_get_time64(*com_price);
+ if (com_t <= t)
/* No point in checking any more prices, they'll all be further from
* t. */
return target_list;
- if (timespec_cmp(&price_t, &t) > 0)
+ if (price_t > t)
/* The price list is sorted newest->oldest, so as long as this price
* is newer than t then it should replace the saved one. */
{
@@ -1992,9 +1966,9 @@ add_nearest_price(GList *target_list, GPtrArray *price_array, GNCPrice *price,
}
else
{
- Timespec com_diff = timespec_diff(&com_t, &t);
- Timespec price_diff = timespec_diff(&t, &price_t);
- if (timespec_cmp(&com_diff, &price_diff) < 0)
+ time64 com_diff = com_t - t;
+ time64 price_diff = t - price_t;
+ if (com_diff < price_diff)
{
gnc_price_ref(*com_price);
target_list = g_list_prepend(target_list, *com_price);
@@ -2010,7 +1984,7 @@ add_nearest_price(GList *target_list, GPtrArray *price_array, GNCPrice *price,
}
static PriceList *
-nearest_to (PriceList *prices, const gnc_commodity* target, Timespec t)
+nearest_to (PriceList *prices, const gnc_commodity* target, time64 t)
{
GList *node, *retval = NULL;
const guint prealloc_size = 5; /*More than 5 "other" is unlikely as long as
@@ -2032,8 +2006,8 @@ nearest_to (PriceList *prices, const gnc_commodity* target, Timespec t)
for (index = 0; index < price_array->len; ++index)
{
GNCPrice **com_price = g_ptr_array_index(price_array, index);
- Timespec price_t = gnc_price_get_time(*com_price);
- if (timespec_cmp(&price_t, &t) >= 0)
+ time64 price_t = gnc_price_get_time64(*com_price);
+ if (price_t >= t)
{
gnc_price_ref(*com_price);
retval = g_list_prepend(retval, *com_price);
@@ -2049,13 +2023,14 @@ PriceList *
gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db,
const gnc_commodity *commodity)
{
- return gnc_pricedb_lookup_latest_before_any_currency(db, commodity, timespec_now());
+ return gnc_pricedb_lookup_latest_before_any_currency_t64(db, commodity,
+ gnc_time(NULL));
}
PriceList *
-gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db,
- const gnc_commodity *commodity,
- Timespec t)
+gnc_pricedb_lookup_nearest_in_time_any_currency_t64(GNCPriceDB *db,
+ const gnc_commodity *commodity,
+ time64 t)
{
GList *prices = NULL, *result;
UsesCommodity helper = {&prices, commodity, t};
@@ -2064,8 +2039,7 @@ gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db,
if (!db || !commodity) return NULL;
ENTER ("db=%p commodity=%p", db, commodity);
- pricedb_pricelist_traversal(db, price_list_scan_any_currency,
- &helper);
+ pricedb_pricelist_traversal(db, price_list_scan_any_currency, &helper);
prices = g_list_sort(prices, compare_prices_by_date);
result = nearest_to(prices, commodity, t);
gnc_price_list_destroy(prices);
@@ -2074,21 +2048,9 @@ gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db,
}
PriceList *
-gnc_pricedb_lookup_nearest_in_time_any_currency_t64(GNCPriceDB *db,
- const gnc_commodity *commodity,
- time64 t64)
-{
- Timespec t;
- t.tv_sec = t64;
- t.tv_nsec = 0;
-
- return gnc_pricedb_lookup_nearest_in_time_any_currency(db, commodity, t);
-}
-
-PriceList *
-gnc_pricedb_lookup_latest_before_any_currency(GNCPriceDB *db,
- const gnc_commodity *commodity,
- Timespec t)
+gnc_pricedb_lookup_latest_before_any_currency_t64(GNCPriceDB *db,
+ const gnc_commodity *commodity,
+ time64 t)
{
GList *prices = NULL, *result;
UsesCommodity helper = {&prices, commodity, t};
@@ -2288,31 +2250,19 @@ gnc_pricedb_nth_price (GNCPriceDB *db,
}
GNCPrice *
-gnc_pricedb_lookup_day(GNCPriceDB *db,
- const gnc_commodity *c,
- const gnc_commodity *currency,
- Timespec t)
-{
- return lookup_nearest_in_time(db, c, currency, t, TRUE);
-}
-
-GNCPrice *
gnc_pricedb_lookup_day_t64(GNCPriceDB *db,
- const gnc_commodity *c,
- const gnc_commodity *currency,
- time64 t64)
+ const gnc_commodity *c,
+ const gnc_commodity *currency,
+ time64 t)
{
- Timespec t;
- t.tv_sec = t64;
- t.tv_nsec = 0;
return lookup_nearest_in_time(db, c, currency, t, TRUE);
}
GNCPrice *
-gnc_pricedb_lookup_at_time(GNCPriceDB *db,
- const gnc_commodity *c,
- const gnc_commodity *currency,
- Timespec t)
+gnc_pricedb_lookup_at_time64(GNCPriceDB *db,
+ const gnc_commodity *c,
+ const gnc_commodity *currency,
+ time64 t)
{
GList *price_list;
GList *item = NULL;
@@ -2324,8 +2274,8 @@ gnc_pricedb_lookup_at_time(GNCPriceDB *db,
while (item)
{
GNCPrice *p = item->data;
- Timespec price_time = gnc_price_get_time(p);
- if (timespec_equal(&price_time, &t))
+ time64 price_time = gnc_price_get_time64(p);
+ if (price_time == t)
{
gnc_price_ref(p);
g_list_free (price_list);
@@ -2342,7 +2292,7 @@ static GNCPrice *
lookup_nearest_in_time(GNCPriceDB *db,
const gnc_commodity *c,
const gnc_commodity *currency,
- Timespec t,
+ time64 t,
gboolean sameday)
{
GList *price_list;
@@ -2352,7 +2302,7 @@ lookup_nearest_in_time(GNCPriceDB *db,
GList *item = NULL;
if (!db || !c || !currency) return NULL;
- if (t.tv_sec == INT64_MAX) return NULL;
+ if (t == INT64_MAX) return NULL;
ENTER ("db=%p commodity=%p currency=%p", db, c, currency);
price_list = pricedb_get_prices_internal (db, c, currency, TRUE);
if (!price_list) return NULL;
@@ -2366,8 +2316,8 @@ lookup_nearest_in_time(GNCPriceDB *db,
while (!next_price && item)
{
GNCPrice *p = item->data;
- Timespec price_time = gnc_price_get_time(p);
- if (timespec_cmp(&price_time, &t) <= 0)
+ time64 price_time = gnc_price_get_time64(p);
+ if (price_time <= t)
{
next_price = item->data;
break;
@@ -2385,11 +2335,11 @@ lookup_nearest_in_time(GNCPriceDB *db,
if (sameday)
{
/* Must be on the same day. */
- Timespec price_day;
- Timespec t_day;
- price_day = timespecCanonicalDayTime(gnc_price_get_time(current_price));
- t_day = timespecCanonicalDayTime(t);
- if (!timespec_equal(&price_day, &t_day))
+ time64 price_day;
+ time64 t_day;
+ price_day = time64CanonicalDayTime(gnc_price_get_time64(current_price));
+ t_day = time64CanonicalDayTime(t);
+ if (price_day != t_day)
result = NULL;
}
}
@@ -2397,25 +2347,25 @@ lookup_nearest_in_time(GNCPriceDB *db,
{
/* If the requested time is not earlier than the first price on the
list, then current_price and next_price will be the same. */
- Timespec current_t = gnc_price_get_time(current_price);
- Timespec next_t = gnc_price_get_time(next_price);
- Timespec diff_current = timespec_diff(¤t_t, &t);
- Timespec diff_next = timespec_diff(&next_t, &t);
- Timespec abs_current = timespec_abs(&diff_current);
- Timespec abs_next = timespec_abs(&diff_next);
+ time64 current_t = gnc_price_get_time64(current_price);
+ time64 next_t = gnc_price_get_time64(next_price);
+ time64 diff_current = current_t - t;
+ time64 diff_next = next_t - t;
+ time64 abs_current = llabs(diff_current);
+ time64 abs_next = llabs(diff_next);
if (sameday)
{
/* Result must be on same day, see if either of the two isn't */
- Timespec t_day = timespecCanonicalDayTime(t);
- Timespec current_day = timespecCanonicalDayTime(current_t);
- Timespec next_day = timespecCanonicalDayTime(next_t);
- if (timespec_equal(¤t_day, &t_day))
+ time64 t_day = time64CanonicalDayTime(t);
+ time64 current_day = time64CanonicalDayTime(current_t);
+ time64 next_day = time64CanonicalDayTime(next_t);
+ if (current_day == t_day)
{
- if (timespec_equal(&next_day, &t_day))
+ if (next_day == t_day)
{
/* Both on same day, return nearest */
- if (timespec_cmp(&abs_current, &abs_next) < 0)
+ if (abs_current < abs_next)
result = current_price;
else
result = next_price;
@@ -2424,7 +2374,7 @@ lookup_nearest_in_time(GNCPriceDB *db,
/* current_price on same day, next_price not */
result = current_price;
}
- else if (timespec_equal(&next_day, &t_day))
+ else if (next_day == t_day)
/* next_price on same day, current_price not */
result = next_price;
}
@@ -2433,7 +2383,7 @@ lookup_nearest_in_time(GNCPriceDB *db,
/* Choose the price that is closest to the given time. In case of
* a tie, prefer the older price since it actually existed at the
* time. (This also fixes bug #541970.) */
- if (timespec_cmp(&abs_current, &abs_next) < 0)
+ if (abs_current < abs_next)
{
result = current_price;
}
@@ -2452,38 +2402,27 @@ lookup_nearest_in_time(GNCPriceDB *db,
}
GNCPrice *
-gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db,
- const gnc_commodity *c,
- const gnc_commodity *currency,
- Timespec t)
-{
- return lookup_nearest_in_time(db, c, currency, t, FALSE);
-}
-
-GNCPrice *
gnc_pricedb_lookup_nearest_in_time64(GNCPriceDB *db,
const gnc_commodity *c,
const gnc_commodity *currency,
- time64 t64)
+ time64 t)
{
- Timespec t;
- t.tv_sec = t64;
- t.tv_nsec = 0;
return lookup_nearest_in_time(db, c, currency, t, FALSE);
}
+
GNCPrice *
-gnc_pricedb_lookup_latest_before (GNCPriceDB *db,
- gnc_commodity *c,
- gnc_commodity *currency,
- Timespec t)
+gnc_pricedb_lookup_latest_before_t64 (GNCPriceDB *db,
+ gnc_commodity *c,
+ gnc_commodity *currency,
+ time64 t)
{
GList *price_list;
GNCPrice *current_price = NULL;
/* GNCPrice *next_price = NULL;
GNCPrice *result = NULL;*/
GList *item = NULL;
- Timespec price_time;
+ time64 price_time;
if (!db || !c || !currency) return NULL;
ENTER ("db=%p commodity=%p currency=%p", db, c, currency);
@@ -2492,12 +2431,12 @@ gnc_pricedb_lookup_latest_before (GNCPriceDB *db,
item = price_list;
do
{
- price_time = gnc_price_get_time (item->data);
- if (timespec_cmp(&price_time, &t) <= 0)
+ price_time = gnc_price_get_time64 (item->data);
+ if (price_time <= t)
current_price = item->data;
item = item->next;
}
- while (timespec_cmp(&price_time, &t) > 0 && item);
+ while (price_time > t && item);
gnc_price_ref(current_price);
g_list_free (price_list);
LEAVE (" ");
@@ -2678,11 +2617,11 @@ gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb,
}
gnc_numeric
-gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
- gnc_numeric balance,
- const gnc_commodity *balance_currency,
- const gnc_commodity *new_currency,
- time64 t)
+gnc_pricedb_convert_balance_nearest_price_t64(GNCPriceDB *pdb,
+ gnc_numeric balance,
+ const gnc_commodity *balance_currency,
+ const gnc_commodity *new_currency,
+ time64 t)
{
gnc_numeric new_value;
@@ -3158,7 +3097,7 @@ price_printable(gpointer obj)
#endif
val = gnc_numeric_to_string (pr->value);
- da = qof_print_date (pr->tmspec.tv_sec);
+ da = qof_print_date (pr->tmspec);
commodity = gnc_price_get_commodity(pr);
currency = gnc_price_get_currency(pr);
diff --git a/libgnucash/engine/gnc-pricedb.h b/libgnucash/engine/gnc-pricedb.h
index 61ed2c9..3fbefe4 100644
--- a/libgnucash/engine/gnc-pricedb.h
+++ b/libgnucash/engine/gnc-pricedb.h
@@ -238,8 +238,7 @@ void gnc_price_commit_edit (GNCPrice *p);
void gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c);
void gnc_price_set_currency(GNCPrice *p, gnc_commodity *c);
-void gnc_price_set_time(GNCPrice *p, Timespec t);
-void gnc_price_set_time64(GNCPrice *p, time64 t64);
+void gnc_price_set_time64(GNCPrice *p, time64 t);
void gnc_price_set_source(GNCPrice *p, PriceSource source);
void gnc_price_set_source_string(GNCPrice *p, const char* s);
void gnc_price_set_typestr(GNCPrice *p, const char* type);
@@ -257,7 +256,6 @@ void gnc_price_set_value(GNCPrice *p, gnc_numeric value);
gnc_commodity * gnc_price_get_commodity(const GNCPrice *p);
/*@ dependent @*/
gnc_commodity * gnc_price_get_currency(const GNCPrice *p);
-Timespec gnc_price_get_time(const GNCPrice *p);
time64 gnc_price_get_time64(const GNCPrice *p);
PriceSource gnc_price_get_source(const GNCPrice *p);
const char * gnc_price_get_source_string(const GNCPrice *p);
@@ -463,21 +461,21 @@ PriceList * gnc_pricedb_get_prices(GNCPriceDB *db,
const gnc_commodity *commodity,
const gnc_commodity *currency);
-/** @brief Find the price between two commodities at a timespec.
+/** @brief Find the price between two commodities at a time64.
*
* The returned GNCPrice may be in either direction so check to ensure that its
* value is correctly applied.
* @param db The pricedb
* @param commodity The first commodity
* @param currency The second commodity
- * @param t The timespec at which to retrieve the price.
+ * @param t The time64 at which to retrieve the price.
* @return A GNCPrice or NULL if none matches.
*/
/* NOT USED */
-GNCPrice * gnc_pricedb_lookup_at_time(GNCPriceDB *db,
- const gnc_commodity *commodity,
- const gnc_commodity *currency,
- Timespec t);
+GNCPrice * gnc_pricedb_lookup_at_time64(GNCPriceDB *db,
+ const gnc_commodity *commodity,
+ const gnc_commodity *currency,
+ time64 t);
/** @brief Return the price between the two commodities on the indicated
* day. Note that the notion of day might be distorted by changes in timezone.
@@ -491,15 +489,10 @@ GNCPrice * gnc_pricedb_lookup_at_time(GNCPriceDB *db,
* according to the local timezone.
* @return A GNCPrice or NULL on failure.
*/
-GNCPrice * gnc_pricedb_lookup_day(GNCPriceDB *db,
- const gnc_commodity *commodity,
- const gnc_commodity *currency,
- Timespec t);
-
GNCPrice * gnc_pricedb_lookup_day_t64(GNCPriceDB *db,
- const gnc_commodity *commodity,
- const gnc_commodity *currency,
- time64 t64);
+ const gnc_commodity *commodity,
+ const gnc_commodity *currency,
+ time64 t);
/** @brief Return the price between the two commoditiesz nearest to the given
* time.
@@ -512,15 +505,10 @@ GNCPrice * gnc_pricedb_lookup_day_t64(GNCPriceDB *db,
* @param t The time nearest to which the returned price should be.
* @return A GNCPrice or NULL if no prices exist between the two commodities.
*/
-GNCPrice * gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db,
- const gnc_commodity *c,
- const gnc_commodity *currency,
- Timespec t);
-
GNCPrice * gnc_pricedb_lookup_nearest_in_time64(GNCPriceDB *db,
- const gnc_commodity *c,
- const gnc_commodity *currency,
- time64 t);
+ const gnc_commodity *c,
+ const gnc_commodity *currency,
+ time64 t);
/** @brief Return the price nearest in time to that given between the given
* commodity and every other.
@@ -534,12 +522,9 @@ GNCPrice * gnc_pricedb_lookup_nearest_in_time64(GNCPriceDB *db,
* @return A PriceList of prices for each commodity pair found or NULL if none
* are.
*/
-PriceList * gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db,
- const gnc_commodity *c,
- Timespec t);
PriceList * gnc_pricedb_lookup_nearest_in_time_any_currency_t64(GNCPriceDB *db,
const gnc_commodity *c,
- time64 t64);
+ time64 t);
/** @brief Return the latest price between the given commodities before the
* given time.
@@ -553,10 +538,10 @@ PriceList * gnc_pricedb_lookup_nearest_in_time_any_currency_t64(GNCPriceDB *db,
* @return A GNCPrice or NULL if no prices are found before t.
*/
/* NOT USED, but see bug 743753 */
-GNCPrice * gnc_pricedb_lookup_latest_before(GNCPriceDB *db,
- gnc_commodity *c,
- gnc_commodity *currency,
- Timespec t);
+GNCPrice * gnc_pricedb_lookup_latest_before_t64(GNCPriceDB *db,
+ gnc_commodity *c,
+ gnc_commodity *currency,
+ time64 t);
/** @brief Return the latest price between the given commodity and any other
* before the given time.
@@ -569,9 +554,9 @@ GNCPrice * gnc_pricedb_lookup_latest_before(GNCPriceDB *db,
* @return A PriceList of prices for each commodity found or NULL if none are.
*/
/* NOT USED, but see bug 743753 */
-PriceList * gnc_pricedb_lookup_latest_before_any_currency(GNCPriceDB *db,
+PriceList * gnc_pricedb_lookup_latest_before_any_currency_t64(GNCPriceDB *db,
const gnc_commodity *c,
- Timespec t);
+ time64 t);
/** @brief Convert a balance from one currency to another using the most recent
@@ -600,11 +585,11 @@ gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb,
* @return A new balance or gnc_numeric_zero if no price is available.
*/
gnc_numeric
-gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
- gnc_numeric balance,
- const gnc_commodity *balance_currency,
- const gnc_commodity *new_currency,
- time64 t);
+gnc_pricedb_convert_balance_nearest_price_t64(GNCPriceDB *pdb,
+ gnc_numeric balance,
+ const gnc_commodity *balance_currency,
+ const gnc_commodity *new_currency,
+ time64 t);
typedef gboolean (*GncPriceForeachFunc)(GNCPrice *p, gpointer user_data);
diff --git a/libgnucash/engine/test-core/test-engine-stuff.cpp b/libgnucash/engine/test-core/test-engine-stuff.cpp
index 045ac34..a1da304 100644
--- a/libgnucash/engine/test-core/test-engine-stuff.cpp
+++ b/libgnucash/engine/test-core/test-engine-stuff.cpp
@@ -647,7 +647,7 @@ make_random_changes_to_commodity_table (gnc_commodity_table *table)
void
make_random_changes_to_price (QofBook *book, GNCPrice *p)
{
- Timespec *ts;
+ time64 time;
PriceSource ps;
char *string;
gnc_commodity *c;
@@ -662,9 +662,8 @@ make_random_changes_to_price (QofBook *book, GNCPrice *p)
c = get_random_commodity (book);
gnc_price_set_currency (p, c);
- ts = get_random_timespec ();
- gnc_price_set_time (p, *ts);
- g_free (ts);
+ time = get_random_time ();
+ gnc_price_set_time64 (p, time);
ps = (PriceSource)get_random_int_in_range((int)PRICE_SOURCE_EDIT_DLG,
(int)PRICE_SOURCE_INVALID);
diff --git a/libgnucash/engine/test/utest-Account.cpp b/libgnucash/engine/test/utest-Account.cpp
index 4e59778..7c14615 100644
--- a/libgnucash/engine/test/utest-Account.cpp
+++ b/libgnucash/engine/test/utest-Account.cpp
@@ -1962,7 +1962,7 @@ test_xaccAccountGetPresentBalance (Fixture *fixture, gconstpointer pData)
* xaccAccountConvertBalanceToCurrency
* xaccAccountConvertBalanceToCurrencyAsOfDate are wrappers around
* gnc_pricedb_convert_balance_latest_price and
- * gnc_pricedb_convert_balance_nearest_price. Don't test.
+ * gnc_pricedb_convert_balance_nearest_price_t64. Don't test.
*
* The rest of these are convenience functions that wrap
* xaccAccountConvertBalanceToCurrency* with one of the balance getter
diff --git a/libgnucash/engine/test/utest-Budget.c b/libgnucash/engine/test/utest-Budget.c
index fd311d1..6b188a4 100644
--- a/libgnucash/engine/test/utest-Budget.c
+++ b/libgnucash/engine/test/utest-Budget.c
@@ -1924,7 +1924,7 @@ test_xaccAccountGetPresentBalance (Fixture *fixture, gconstpointer pData)
* xaccAccountConvertBalanceToCurrency
* xaccAccountConvertBalanceToCurrencyAsOfDate are wrappers around
* gnc_pricedb_convert_balance_latest_price and
- * gnc_pricedb_convert_balance_nearest_price. Don't test.
+ * gnc_pricedb_convert_balance_nearest_price_t64. Don't test.
*
* The rest of these are convenience functions that wrap
* xaccAccountConvertBalanceToCurrency* with one of the balance getter
diff --git a/libgnucash/engine/test/utest-gnc-pricedb.c b/libgnucash/engine/test/utest-gnc-pricedb.c
index 841260a..670bf6f 100644
--- a/libgnucash/engine/test/utest-gnc-pricedb.c
+++ b/libgnucash/engine/test/utest-gnc-pricedb.c
@@ -70,12 +70,12 @@ setup_commodities (QofBook *book)
*/
static GNCPrice *
construct_price(QofBook *book, gnc_commodity *com, gnc_commodity *cur,
- Timespec t, PriceSource source, gnc_numeric price)
+ time64 t, PriceSource source, gnc_numeric price)
{
GNCPrice *p = gnc_price_create(book);
gnc_price_set_commodity(p, com);
gnc_price_set_currency(p, cur);
- gnc_price_set_time(p, t);
+ gnc_price_set_time64(p, t);
gnc_price_set_source(p, source);
gnc_price_set_value(p, price);
return p;
@@ -229,12 +229,12 @@ gnc_price_set_currency(GNCPrice *p, gnc_commodity *c)// C: 7 in 7 SCM: 1 Local:
test_gnc_price_set_currency (Fixture *fixture, gconstpointer pData)
{
}*/
-/* gnc_price_set_time
+/* gnc_price_set_time64
void
-gnc_price_set_time(GNCPrice *p, Timespec t)// C: 9 in 7 SCM: 2 in 1 Local: 2:0:0
+gnc_price_set_time64(GNCPrice *p, time64 t)// C: 9 in 7 SCM: 2 in 1 Local: 2:0:0
*/
/* static void
-test_gnc_price_set_time (Fixture *fixture, gconstpointer pData)
+test_gnc_price_set_time64 (Fixture *fixture, gconstpointer pData)
{
}*/
/* gnc_price_set_source
@@ -285,12 +285,12 @@ gnc_price_get_commodity(const GNCPrice *p)// C: 12 in 5 Local: 20:1:0
test_gnc_price_get_commodity (Fixture *fixture, gconstpointer pData)
{
}*/
-/* gnc_price_get_time
-Timespec
-gnc_price_get_time(const GNCPrice *p)// C: 7 in 4 SCM: 1 Local: 18:1:0
+/* gnc_price_get_time64
+time64
+gnc_price_get_time64(const GNCPrice *p)// C: 7 in 4 SCM: 1 Local: 18:1:0
*/
/* static void
-test_gnc_price_get_time (Fixture *fixture, gconstpointer pData)
+test_gnc_price_get_time64 (Fixture *fixture, gconstpointer pData)
{
}*/
/* gnc_price_get_source
@@ -412,171 +412,171 @@ create_some_prices (PriceDBFixture *fixture)
Commodities *c = fixture->com;
gnc_pricedb_set_bulk_update(db, TRUE);
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
- gnc_dmy2timespec(11, 4, 2009),
+ gnc_dmy2time64(11, 4, 2009),
PRICE_SOURCE_FQ,
gnc_numeric_create(131190, 10000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
- gnc_dmy2timespec(12, 4, 2009),
+ gnc_dmy2time64(12, 4, 2009),
PRICE_SOURCE_USER_PRICE,
gnc_numeric_create(131190, 10000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
- gnc_dmy2timespec(21, 8, 2010),
+ gnc_dmy2time64(21, 8, 2010),
PRICE_SOURCE_FQ,
gnc_numeric_create(111794, 10000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
- gnc_dmy2timespec(1, 8, 2013),
+ gnc_dmy2time64(1, 8, 2013),
PRICE_SOURCE_FQ,
gnc_numeric_create(111878, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
- gnc_dmy2timespec(12, 11, 2014),
+ gnc_dmy2time64(12, 11, 2014),
PRICE_SOURCE_FQ,
gnc_numeric_create(114784, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->usd,
- gnc_dmy2timespec(11, 4, 2009),
+ gnc_dmy2time64(11, 4, 2009),
PRICE_SOURCE_FQ,
gnc_numeric_create(166651, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->aud, c->usd,
- gnc_dmy2timespec(20, 7, 2011),
+ gnc_dmy2time64(20, 7, 2011),
PRICE_SOURCE_FQ,
gnc_numeric_create(106480, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->aud, c->usd,
- gnc_dmy2timespec(17, 11, 2012),
+ gnc_dmy2time64(17, 11, 2012),
PRICE_SOURCE_FQ,
gnc_numeric_create(103415, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->usd,
- gnc_dmy2timespec(21, 8, 2010),
+ gnc_dmy2time64(21, 8, 2010),
PRICE_SOURCE_FQ,
gnc_numeric_create(159037, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->usd,
- gnc_dmy2timespec(20, 7, 2011),
+ gnc_dmy2time64(20, 7, 2011),
PRICE_SOURCE_FQ,
gnc_numeric_create(161643, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->usd,
- gnc_dmy2timespec(17, 11, 2012),
+ gnc_dmy2time64(17, 11, 2012),
PRICE_SOURCE_FQ,
gnc_numeric_create(158855, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->usd,
- gnc_dmy2timespec(13, 10, 2012),
+ gnc_dmy2time64(13, 10, 2012),
PRICE_SOURCE_FQ,
gnc_numeric_create(160705, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->usd,
- gnc_dmy2timespec(1, 8, 2013),
+ gnc_dmy2time64(1, 8, 2013),
PRICE_SOURCE_FQ,
gnc_numeric_create(151173, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->usd,
- gnc_dmy2timespec(12, 11, 2014),
+ gnc_dmy2time64(12, 11, 2014),
PRICE_SOURCE_FQ,
gnc_numeric_create(157658, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(11, 4, 2009),
+ gnc_dmy2time64(11, 4, 2009),
PRICE_SOURCE_FQ,
gnc_numeric_create(111257, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(21, 8, 2010),
+ gnc_dmy2time64(21, 8, 2010),
PRICE_SOURCE_FQ,
gnc_numeric_create(122195, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(20, 7, 2011),
+ gnc_dmy2time64(20, 7, 2011),
PRICE_SOURCE_FQ,
gnc_numeric_create(113289, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(17, 11, 2012),
+ gnc_dmy2time64(17, 11, 2012),
PRICE_SOURCE_FQ,
gnc_numeric_create(124646, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(13, 10, 2012),
+ gnc_dmy2time64(13, 10, 2012),
PRICE_SOURCE_FQ,
gnc_numeric_create(124072, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(1, 8, 2013),
+ gnc_dmy2time64(1, 8, 2013),
PRICE_SOURCE_FQ,
gnc_numeric_create(114420, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(12, 11, 2014),
+ gnc_dmy2time64(12, 11, 2014),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->dkk,
- gnc_dmy2timespec(11, 4, 2009),
+ gnc_dmy2time64(11, 4, 2009),
PRICE_SOURCE_FQ,
gnc_numeric_create(567859, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->dkk,
- gnc_dmy2timespec(21, 8, 2010),
+ gnc_dmy2time64(21, 8, 2010),
PRICE_SOURCE_FQ,
gnc_numeric_create(585810, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->dkk,
- gnc_dmy2timespec(20, 7, 2011),
+ gnc_dmy2time64(20, 7, 2011),
PRICE_SOURCE_FQ,
gnc_numeric_create(522449, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->dkk,
- gnc_dmy2timespec(17, 11, 2012),
+ gnc_dmy2time64(17, 11, 2012),
PRICE_SOURCE_FQ,
gnc_numeric_create(585380, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->dkk,
- gnc_dmy2timespec(1, 8, 2013),
+ gnc_dmy2time64(1, 8, 2013),
PRICE_SOURCE_FQ,
gnc_numeric_create(564281, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->dkk,
- gnc_dmy2timespec(12, 11, 2014),
+ gnc_dmy2time64(12, 11, 2014),
PRICE_SOURCE_FQ,
gnc_numeric_create(598693, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->amzn, c->usd,
- gnc_dmy2timespec(13, 4, 2009),
+ gnc_dmy2time64(13, 4, 2009),
PRICE_SOURCE_FQ,
gnc_numeric_create(7805, 100)));
gnc_pricedb_add_price(db, construct_price(book, c->amzn, c->usd,
- gnc_dmy2timespec(23, 8, 2010),
+ gnc_dmy2time64(23, 8, 2010),
PRICE_SOURCE_FQ,
gnc_numeric_create(12664, 100)));
gnc_pricedb_add_price(db, construct_price(book, c->amzn, c->usd,
- gnc_dmy2timespec(25, 7, 2011),
+ gnc_dmy2time64(25, 7, 2011),
PRICE_SOURCE_FQ,
gnc_numeric_create(22252, 100)));
gnc_pricedb_add_price(db, construct_price(book, c->amzn, c->usd,
- gnc_dmy2timespec(19, 11, 2012),
+ gnc_dmy2time64(19, 11, 2012),
PRICE_SOURCE_FQ,
gnc_numeric_create(23988, 100)));
gnc_pricedb_add_price(db, construct_price(book, c->amzn, c->usd,
- gnc_dmy2timespec(5, 8, 2013),
+ gnc_dmy2time64(5, 8, 2013),
PRICE_SOURCE_FQ,
gnc_numeric_create(29726, 100)));
gnc_pricedb_add_price(db, construct_price(book, c->amzn, c->usd,
- gnc_dmy2timespec(12, 11, 2014),
+ gnc_dmy2time64(12, 11, 2014),
PRICE_SOURCE_FQ,
gnc_numeric_create(31151, 100)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(12, 05, 2007),
+ gnc_dmy2time64(12, 05, 2007),
PRICE_SOURCE_USER_PRICE,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(12, 05, 2008),
+ gnc_dmy2time64(12, 05, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(13, 05, 2008),
+ gnc_dmy2time64(13, 05, 2008),
PRICE_SOURCE_USER_PRICE,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(14, 05, 2008),
+ gnc_dmy2time64(14, 05, 2008),
PRICE_SOURCE_USER_PRICE,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(19, 05, 2008),
+ gnc_dmy2time64(19, 05, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(22, 05, 2008),
+ gnc_dmy2time64(22, 05, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(12, 06, 2008),
+ gnc_dmy2time64(12, 06, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(12, 07, 2008),
+ gnc_dmy2time64(12, 07, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
- gnc_dmy2timespec(12, 11, 2008),
+ gnc_dmy2time64(12, 11, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_set_bulk_update(db, FALSE);
@@ -876,11 +876,11 @@ test_gnc_pricedb_lookup_latest (PriceDBFixture *fixture, gconstpointer pData)
GNCPrice *price2, *price = gnc_pricedb_lookup_latest(fixture->pricedb,
fixture->com->gbp,
fixture->com->eur);
- Timespec t = gnc_dmy2timespec(12, 11, 2014);
- Timespec price_time = gnc_price_get_time(price);
+ time64 t = gnc_dmy2time64(12, 11, 2014);
+ time64 price_time = gnc_price_get_time64(price);
g_assert(gnc_price_get_commodity(price) == fixture->com->gbp);
g_assert(gnc_price_get_currency(price) == fixture->com->eur);
- g_assert(timespec_equal(&price_time, &t));
+ g_assert_cmpint(price_time, ==, t);
price2 = gnc_pricedb_lookup_latest(fixture->pricedb, fixture->com->eur,
fixture->com->gbp);
g_assert(price2 == price);
@@ -910,7 +910,7 @@ test_is_in_list (Fixture *fixture, gconstpointer pData)
}*/
/* latest_before
static PriceList*
-latest_before (PriceList *prices, const gnc_commodity* target, Timespec t)// Local: 2:0:0
+latest_before (PriceList *prices, const gnc_commodity* target, time64 t)// Local: 2:0:0
*/
/* static void
test_latest_before (Fixture *fixture, gconstpointer pData)
@@ -934,7 +934,7 @@ test_add_nearest_price (Fixture *fixture, gconstpointer pData)
}*/
/* nearest_to
static PriceList *
-nearest_to (PriceList *prices, const gnc_commodity* target, Timespec t)// Local: 1:0:0
+nearest_to (PriceList *prices, const gnc_commodity* target, time64 t)// Local: 1:0:0
*/
/* static void
test_nearest_to (PriceDBFixture *fixture, gconstpointer pData)
@@ -974,26 +974,28 @@ test_gnc_pricedb_lookup_latest_any_currency (PriceDBFixture *fixture, gconstpoin
gnc_price_list_destroy(prices);
}
// Make Static
-/* gnc_pricedb_lookup_nearest_in_time_any_currency
+/* gnc_pricedb_lookup_nearest_in_time_any_currency_t64
PriceList *
-gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db,// Local: 2:0:0
+gnc_pricedb_lookup_nearest_in_time_any_currency_t64(GNCPriceDB *db,// Local: 2:0:0
*/
static void
-test_gnc_pricedb_lookup_nearest_in_time_any_currency (PriceDBFixture *fixture, gconstpointer pData)
+test_gnc_pricedb_lookup_nearest_in_time_any_currency_t64 (PriceDBFixture *fixture, gconstpointer pData)
{
- Timespec t1 = gnc_dmy2timespec(25, 3, 2013);
- Timespec t2 = gnc_dmy2timespec(26, 3, 2013);
+ time64 t1 = gnc_dmy2time64(25, 3, 2013);
+ time64 t2 = gnc_dmy2time64(26, 3, 2013);
PriceList *prices =
- gnc_pricedb_lookup_nearest_in_time_any_currency(fixture->pricedb,
- fixture->com->usd, t1);
+ gnc_pricedb_lookup_nearest_in_time_any_currency_t64(fixture->pricedb,
+ fixture->com->usd,
+ t1);
g_assert_cmpint(g_list_length(prices), ==, 4);
prices = g_list_sort(prices, compare_price_commodities);
g_assert_cmpstr(GET_COM_NAME(prices->next->data), ==, "AUD");
g_assert_cmpstr(GET_CUR_NAME(prices->next->data), ==, "USD");
gnc_price_list_destroy(prices);
prices =
- gnc_pricedb_lookup_nearest_in_time_any_currency(fixture->pricedb,
- fixture->com->usd, t2);
+ gnc_pricedb_lookup_nearest_in_time_any_currency_t64(fixture->pricedb,
+ fixture->com->usd,
+ t2);
g_assert_cmpint(g_list_length(prices), ==, 4);
prices = g_list_sort(prices, compare_price_commodities);
g_assert_cmpstr(GET_CUR_NAME(prices->next->data), ==, "AUD");
@@ -1002,18 +1004,18 @@ test_gnc_pricedb_lookup_nearest_in_time_any_currency (PriceDBFixture *fixture, g
}
// Not Used
-/* gnc_pricedb_lookup_latest_before_any_currency
+/* gnc_pricedb_lookup_latest_before_any_currency_t64
PriceList *
-gnc_pricedb_lookup_latest_before_any_currency(GNCPriceDB *db,// Local: 0:0:0
+gnc_pricedb_lookup_latest_before_any_currency_t64(GNCPriceDB *db,// Local: 0:0:0
*/
static void
-test_gnc_pricedb_lookup_latest_before_any_currency (PriceDBFixture *fixture,
+test_gnc_pricedb_lookup_latest_before_any_currency_t64 (PriceDBFixture *fixture,
gconstpointer pData)
{
- Timespec t1 = gnc_dmy2timespec(31, 7, 2013);
- Timespec t2 = gnc_dmy2timespec(5, 8, 2013);
+ time64 t1 = gnc_dmy2time64(31, 7, 2013);
+ time64 t2 = gnc_dmy2time64(5, 8, 2013);
PriceList *prices =
- gnc_pricedb_lookup_latest_before_any_currency(fixture->pricedb,
+ gnc_pricedb_lookup_latest_before_any_currency_t64(fixture->pricedb,
fixture->com->usd, t1);
g_assert_cmpint(g_list_length(prices), ==, 4);
prices = g_list_sort(prices, compare_price_commodities);
@@ -1021,7 +1023,7 @@ test_gnc_pricedb_lookup_latest_before_any_currency (PriceDBFixture *fixture,
g_assert_cmpstr(GET_CUR_NAME(prices->next->data), ==, "USD");
gnc_price_list_destroy(prices);
prices =
- gnc_pricedb_lookup_latest_before_any_currency(fixture->pricedb,
+ gnc_pricedb_lookup_latest_before_any_currency_t64(fixture->pricedb,
fixture->com->usd, t2);
g_assert_cmpint(g_list_length(prices), ==, 4);
prices = g_list_sort(prices, compare_price_commodities);
@@ -1062,31 +1064,31 @@ test_gnc_pricedb_get_prices (PriceDBFixture *fixture, gconstpointer pData)
g_assert_cmpint(g_list_length(prices), ==, 5);
gnc_price_list_destroy(prices);
}
-/* gnc_pricedb_lookup_day
+/* gnc_pricedb_lookup_day_t64
GNCPrice *
-gnc_pricedb_lookup_day(GNCPriceDB *db,// C: 4 in 2 SCM: 2 in 1 Local: 1:0:0
+gnc_pricedb_lookup_day_t64(GNCPriceDB *db,// C: 4 in 2 SCM: 2 in 1 Local: 1:0:0
*/
static void
-test_gnc_pricedb_lookup_day (PriceDBFixture *fixture, gconstpointer pData)
+test_gnc_pricedb_lookup_day_t64 (PriceDBFixture *fixture, gconstpointer pData)
{
gchar *msg1 = "[gnc_dmy2timespec_internal()] Date computation error from Y-M-D 12-11-18: Year is out of valid range: 1400..10000";
gint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL;
gchar *logdomain = "qof.engine";
TestErrorStruct check = {loglevel, logdomain, msg1, 0};
GLogFunc hdlr = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
- Timespec t = gnc_dmy2timespec(17, 11, 2012);
- GNCPrice *price = gnc_pricedb_lookup_day(fixture->pricedb,
+ time64 t = gnc_dmy2time64(17, 11, 2012);
+ GNCPrice *price = gnc_pricedb_lookup_day_t64(fixture->pricedb,
fixture->com->usd,
fixture->com->gbp, t);
g_assert_cmpstr(GET_COM_NAME(price), ==, "GBP");
- t.tv_sec += 20247; /* A random number of seconds later, still the same day.*/
- price = gnc_pricedb_lookup_day(fixture->pricedb,
+ t += 20247; /* A random number of seconds later, still the same day.*/
+ price = gnc_pricedb_lookup_day_t64(fixture->pricedb,
fixture->com->usd,
fixture->com->gbp, t);
g_assert_cmpstr(GET_COM_NAME(price), ==, "GBP");
g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
- t = gnc_dmy2timespec(18, 11, 12);
- price = gnc_pricedb_lookup_day(fixture->pricedb,
+ t = gnc_dmy2time64(18, 11, 12);
+ price = gnc_pricedb_lookup_day_t64(fixture->pricedb,
fixture->com->usd,
fixture->com->gbp, t);
g_assert(price == NULL);
@@ -1094,9 +1096,9 @@ test_gnc_pricedb_lookup_day (PriceDBFixture *fixture, gconstpointer pData)
}
// Not Used
-/* gnc_pricedb_lookup_at_time
+/* gnc_pricedb_lookup_at_time64
GNCPrice *
-gnc_pricedb_lookup_at_time(GNCPriceDB *db,// Local: 0:0:0
+gnc_pricedb_lookup_at_time64(GNCPriceDB *db,// Local: 0:0:0
*/
/* lookup_nearest_in_time
static GNCPrice *
@@ -1105,30 +1107,32 @@ lookup_nearest_in_time(GNCPriceDB *db,// Local: 2:0:0
/* test_lookup_nearest_in_time (Fixture *fixture, gconstpointer pData)
{
}*/
-/* gnc_pricedb_lookup_nearest_in_time
+/* gnc_pricedb_lookup_nearest_in_time64
GNCPrice *
-gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db,// C: 2 in 1 Local: 1:0:0
+gnc_pricedb_lookup_nearest_in_time64(GNCPriceDB *db,// C: 2 in 1 Local: 1:0:0
*/
static void
-test_gnc_pricedb_lookup_nearest_in_time (PriceDBFixture *fixture, gconstpointer pData)
+test_gnc_pricedb_lookup_nearest_in_time64 (PriceDBFixture *fixture, gconstpointer pData)
{
- Timespec t1 = gnc_dmy2timespec(25, 3, 2013);
- Timespec t2 = gnc_dmy2timespec(26, 3, 2013);
+ time64 t1 = gnc_dmy2time64(25, 3, 2013);
+ time64 t2 = gnc_dmy2time64(26, 3, 2013);
GNCPrice *price =
- gnc_pricedb_lookup_nearest_in_time(fixture->pricedb, fixture->com->usd,
- fixture->com->aud, t1);
+ gnc_pricedb_lookup_nearest_in_time64(fixture->pricedb,
+ fixture->com->usd,
+ fixture->com->aud, t1);
g_assert_cmpstr(GET_COM_NAME(price), ==, "AUD");
g_assert_cmpstr(GET_CUR_NAME(price), ==, "USD");
price =
- gnc_pricedb_lookup_nearest_in_time(fixture->pricedb, fixture->com->usd,
- fixture->com->aud, t2);
+ gnc_pricedb_lookup_nearest_in_time64(fixture->pricedb,
+ fixture->com->usd,
+ fixture->com->aud, t2);
g_assert_cmpstr(GET_CUR_NAME(price), ==, "AUD");
g_assert_cmpstr(GET_COM_NAME(price), ==, "USD");
}
// Not Used
-/* gnc_pricedb_lookup_latest_before
+/* gnc_pricedb_lookup_latest_before_t64
GNCPrice *
-gnc_pricedb_lookup_latest_before (GNCPriceDB *db,// Local: 0:0:0
+gnc_pricedb_lookup_latest_before_t64 (GNCPriceDB *db,// Local: 0:0:0
*/
/* direct_balance_conversion
static gnc_numeric
@@ -1199,39 +1203,47 @@ test_gnc_pricedb_convert_balance_latest_price (PriceDBFixture *fixture, gconstpo
}
-/* gnc_pricedb_convert_balance_nearest_price
+/* gnc_pricedb_convert_balance_nearest_price_t64
gnc_numeric
-gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,// C: 1 Local: 0:0:0
+gnc_pricedb_convert_balance_nearest_price_t64(GNCPriceDB *pdb,// C: 1 Local: 0:0:0
*/
static void
-test_gnc_pricedb_convert_balance_nearest_price (PriceDBFixture *fixture, gconstpointer pData)
+test_gnc_pricedb_convert_balance_nearest_price_t64 (PriceDBFixture *fixture, gconstpointer pData)
{
time64 t = gnc_dmy2time64(15, 8, 2011);
gnc_numeric from = gnc_numeric_create(10000, 100);
gnc_numeric result =
- gnc_pricedb_convert_balance_nearest_price(fixture->pricedb, from,
- fixture->com->usd,
- fixture->com->aud, t);
+ gnc_pricedb_convert_balance_nearest_price_t64(fixture->pricedb, from,
+ fixture->com->usd,
+ fixture->com->aud, t);
g_assert_cmpint(result.num, ==, 9391);
g_assert_cmpint(result.denom, ==, 100);
- result = gnc_pricedb_convert_balance_nearest_price(fixture->pricedb, from,
- fixture->com->usd,
- fixture->com->gbp, t);
+ result = gnc_pricedb_convert_balance_nearest_price_t64(fixture->pricedb,
+ from,
+ fixture->com->usd,
+ fixture->com->gbp,
+ t);
g_assert_cmpint(result.num, ==, 6186);
g_assert_cmpint(result.denom, ==, 100);
- result = gnc_pricedb_convert_balance_nearest_price(fixture->pricedb, from,
- fixture->com->usd,
- fixture->com->eur, t);
+ result = gnc_pricedb_convert_balance_nearest_price_t64(fixture->pricedb,
+ from,
+ fixture->com->usd,
+ fixture->com->eur,
+ t);
g_assert_cmpint(result.num, ==, 7009);
g_assert_cmpint(result.denom, ==, 100);
- result = gnc_pricedb_convert_balance_nearest_price(fixture->pricedb, from,
- fixture->com->gbp,
- fixture->com->dkk, t);
+ result = gnc_pricedb_convert_balance_nearest_price_t64(fixture->pricedb,
+ from,
+ fixture->com->gbp,
+ fixture->com->dkk,
+ t);
g_assert_cmpint(result.num, ==, 84450);
g_assert_cmpint(result.denom, ==, 100);
- result = gnc_pricedb_convert_balance_nearest_price(fixture->pricedb, from,
- fixture->com->amzn,
- fixture->com->aud, t);
+ result = gnc_pricedb_convert_balance_nearest_price_t64(fixture->pricedb,
+ from,
+ fixture->com->amzn,
+ fixture->com->aud,
+ t);
g_assert_cmpint(result.num, ==, 2089782);
g_assert_cmpint(result.denom, ==, 100);
@@ -1426,14 +1438,14 @@ test_suite_gnc_pricedb (void)
// GNC_TEST_ADD (suitename, "gnc price set dirty", Fixture, NULL, setup, test_gnc_price_set_dirty, teardown);
// GNC_TEST_ADD (suitename, "gnc price set commodity", Fixture, NULL, setup, test_gnc_price_set_commodity, teardown);
// GNC_TEST_ADD (suitename, "gnc price set currency", Fixture, NULL, setup, test_gnc_price_set_currency, teardown);
-// GNC_TEST_ADD (suitename, "gnc price set time", Fixture, NULL, setup, test_gnc_price_set_time, teardown);
+// GNC_TEST_ADD (suitename, "gnc price set time", Fixture, NULL, setup, test_gnc_price_set_time64, teardown);
// GNC_TEST_ADD (suitename, "gnc price set source", Fixture, NULL, setup, test_gnc_price_set_source, teardown);
// GNC_TEST_ADD (suitename, "gnc price set source string", Fixture, NULL, setup, test_gnc_price_set_source_string, teardown);
// GNC_TEST_ADD (suitename, "gnc price set typestr", Fixture, NULL, setup, test_gnc_price_set_typestr, teardown);
// GNC_TEST_ADD (suitename, "gnc price set value", Fixture, NULL, setup, test_gnc_price_set_value, teardown);
// GNC_TEST_ADD (suitename, "gnc price lookup", Fixture, NULL, setup, test_gnc_price_lookup, teardown);
// GNC_TEST_ADD (suitename, "gnc price get commodity", Fixture, NULL, setup, test_gnc_price_get_commodity, teardown);
-// GNC_TEST_ADD (suitename, "gnc price get time", Fixture, NULL, setup, test_gnc_price_get_time, teardown);
+// GNC_TEST_ADD (suitename, "gnc price get time", Fixture, NULL, setup, test_gnc_price_get_time64, teardown);
// GNC_TEST_ADD (suitename, "gnc price get source", Fixture, NULL, setup, test_gnc_price_get_source, teardown);
// GNC_TEST_ADD (suitename, "gnc price get source string", Fixture, NULL, setup, test_gnc_price_get_source_string, teardown);
// GNC_TEST_ADD (suitename, "gnc price get typestr", Fixture, NULL, setup, test_gnc_price_get_typestr, teardown);
@@ -1478,20 +1490,20 @@ test_suite_gnc_pricedb (void)
// GNC_TEST_ADD (suitename, "add nearest price", Fixture, NULL, setup, test_add_nearest_price, teardown);
// GNC_TEST_ADD (suitename, "nearest to", Fixture, NULL, setup, test_nearest_to, teardown);
GNC_TEST_ADD (suitename, "gnc pricedb lookup latest any currency", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_latest_any_currency, teardown);
- GNC_TEST_ADD (suitename, "gnc pricedb lookup nearest in time any currency", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_nearest_in_time_any_currency, teardown);
- GNC_TEST_ADD (suitename, "gnc pricedb lookup latest before any currency", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_latest_before_any_currency, teardown);
+ GNC_TEST_ADD (suitename, "gnc pricedb lookup nearest in time any currency", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_nearest_in_time_any_currency_t64, teardown);
+ GNC_TEST_ADD (suitename, "gnc pricedb lookup latest before any currency", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_latest_before_any_currency_t64, teardown);
// GNC_TEST_ADD (suitename, "hash values helper", PriceDBFixture, NULL, setup, test_hash_values_helper, teardown);
GNC_TEST_ADD (suitename, "gnc pricedb has prices", PriceDBFixture, NULL, setup, test_gnc_pricedb_has_prices, teardown);
GNC_TEST_ADD (suitename, "gnc pricedb get prices", PriceDBFixture, NULL, setup, test_gnc_pricedb_get_prices, teardown);
- GNC_TEST_ADD (suitename, "gnc pricedb lookup day", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_day, teardown);
+ GNC_TEST_ADD (suitename, "gnc pricedb lookup day", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_day_t64, teardown);
// GNC_TEST_ADD (suitename, "lookup nearest in time", Fixture, NULL, setup, test_lookup_nearest_in_time, teardown);
- GNC_TEST_ADD (suitename, "gnc pricedb lookup nearest in time", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_nearest_in_time, teardown);
+ GNC_TEST_ADD (suitename, "gnc pricedb lookup nearest in time", PriceDBFixture, NULL, setup, test_gnc_pricedb_lookup_nearest_in_time64, teardown);
// GNC_TEST_ADD (suitename, "direct balance conversion", Fixture, NULL, setup, test_direct_balance_conversion, teardown);
// GNC_TEST_ADD (suitename, "extract common prices", Fixture, NULL, setup, test_extract_common_prices, teardown);
// GNC_TEST_ADD (suitename, "convert balance", Fixture, NULL, setup, test_convert_balance, teardown);
// GNC_TEST_ADD (suitename, "indirect balance conversion", Fixture, NULL, setup, test_indirect_balance_conversion, teardown);
GNC_TEST_ADD (suitename, "gnc pricedb convert balance latest price", PriceDBFixture, NULL, setup, test_gnc_pricedb_convert_balance_latest_price, teardown);
- GNC_TEST_ADD (suitename, "gnc pricedb convert balance nearest price", PriceDBFixture, NULL, setup, test_gnc_pricedb_convert_balance_nearest_price, teardown);
+ GNC_TEST_ADD (suitename, "gnc pricedb convert balance nearest price", PriceDBFixture, NULL, setup, test_gnc_pricedb_convert_balance_nearest_price_t64, teardown);
// GNC_TEST_ADD (suitename, "pricedb foreach pricelist", Fixture, NULL, setup, test_pricedb_foreach_pricelist, teardown);
// GNC_TEST_ADD (suitename, "pricedb foreach currencies hash", Fixture, NULL, setup, test_pricedb_foreach_currencies_hash, teardown);
// GNC_TEST_ADD (suitename, "unstable price traversal", Fixture, NULL, setup, test_unstable_price_traversal, teardown);
commit 92a8cf330aece720dd02cc85d181d3bffbcaee08
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 2 13:55:24 2018 -0700
Timespec->time64 in business code.
diff --git a/gnucash/gnome/dialog-payment.c b/gnucash/gnome/dialog-payment.c
index 39465a8..ef3a9ea 100644
--- a/gnucash/gnome/dialog-payment.c
+++ b/gnucash/gnome/dialog-payment.c
@@ -973,9 +973,9 @@ gnc_payment_ok_cb (G_GNUC_UNUSED GtkWidget *widget, gpointer data)
else
auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
- gncOwnerApplyPayment (&pw->owner, &(pw->tx_info->txn), selected_lots,
- pw->post_acct, pw->xfer_acct, pw->amount_tot,
- exch, t, memo, num, auto_pay);
+ gncOwnerApplyPaymentSecs (&pw->owner, &(pw->tx_info->txn), selected_lots,
+ pw->post_acct, pw->xfer_acct, pw->amount_tot,
+ exch, t, memo, num, auto_pay);
}
gnc_resume_gui_refresh ();
diff --git a/libgnucash/engine/gncBillTerm.c b/libgnucash/engine/gncBillTerm.c
index 73e19d7..93c03f6 100644
--- a/libgnucash/engine/gncBillTerm.c
+++ b/libgnucash/engine/gncBillTerm.c
@@ -764,7 +764,7 @@ compute_monthyear (const GncBillTerm *term, time64 post_date,
gnc_localtime_r (&post_date, &tm);
iday = tm.tm_mday;
imonth = tm.tm_mon + 1;
- iyear = tm.tm_year + 1;
+ iyear = tm.tm_year + 1900;
if (cutoff <= 0)
cutoff += gnc_date_get_last_mday (imonth - 1, iyear);
@@ -801,23 +801,23 @@ compute_monthyear (const GncBillTerm *term, time64 post_date,
* detailed explanation of proximo.
*/
-static Timespec
-compute_time (const GncBillTerm *term, Timespec post_date, int days)
+static time64
+compute_time (const GncBillTerm *term, time64 post_date, int days)
{
- Timespec res = post_date;
+ time64 res = post_date;
int day, month, year;
switch (term->type)
{
case GNC_TERM_TYPE_DAYS:
- res.tv_sec += (SECS_PER_DAY * days);
+ res += (SECS_PER_DAY * days);
break;
case GNC_TERM_TYPE_PROXIMO:
- compute_monthyear (term, post_date.tv_sec, &month, &year);
+ compute_monthyear (term, post_date, &month, &year);
day = gnc_date_get_last_mday (month - 1, year);
if (days < day)
day = days;
- res = gnc_dmy2timespec (day, month, year);
+ res = gnc_dmy2time64 (day, month, year);
break;
}
return res;
@@ -826,9 +826,8 @@ compute_time (const GncBillTerm *term, Timespec post_date, int days)
time64
gncBillTermComputeDueDate (const GncBillTerm *term, time64 post_date)
{
- Timespec pass = {post_date, 0};
if (!term) return post_date;
- return compute_time (term, pass, term->due_days).tv_sec;
+ return compute_time (term, post_date, term->due_days);
}
/* Package-Private functions */
diff --git a/libgnucash/engine/gncEntry.c b/libgnucash/engine/gncEntry.c
index a47fd3b..654e7ec 100644
--- a/libgnucash/engine/gncEntry.c
+++ b/libgnucash/engine/gncEntry.c
@@ -1324,20 +1324,20 @@ gncEntryRecomputeValues (GncEntry *entry)
/* See if either tax table changed since we last computed values */
if (entry->i_tax_table)
{
- Timespec modtime = gncTaxTableLastModified (entry->i_tax_table);
- if (entry->i_taxtable_modtime != modtime.tv_sec)
+ time64 modtime = gncTaxTableLastModifiedSecs (entry->i_tax_table);
+ if (entry->i_taxtable_modtime != modtime)
{
entry->values_dirty = TRUE;
- entry->i_taxtable_modtime = modtime.tv_sec;
+ entry->i_taxtable_modtime = modtime;
}
}
if (entry->b_tax_table)
{
- Timespec modtime = gncTaxTableLastModified (entry->b_tax_table);
- if (entry->b_taxtable_modtime == modtime.tv_sec)
+ time64 modtime = gncTaxTableLastModifiedSecs (entry->b_tax_table);
+ if (entry->b_taxtable_modtime == modtime)
{
entry->values_dirty = TRUE;
- entry->b_taxtable_modtime = modtime.tv_sec;
+ entry->b_taxtable_modtime = modtime;
}
}
diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c
index 40d87be..670242c 100644
--- a/libgnucash/engine/gncInvoice.c
+++ b/libgnucash/engine/gncInvoice.c
@@ -1943,9 +1943,10 @@ gncInvoiceApplyPayment (const GncInvoice *invoice, Transaction *txn,
g_return_if_fail (owner->owner.undefined);
/* Create a lot for this payment */
- payment_lot = gncOwnerCreatePaymentLot (owner, &txn, invoice->posted_acc,
- xfer_acc, amount, exch,
- date, memo, num);
+ payment_lot = gncOwnerCreatePaymentLotSecs (owner, &txn,
+ invoice->posted_acc,
+ xfer_acc, amount, exch,
+ date, memo, num);
/* Select the invoice as only payment candidate */
selected_lots = g_list_prepend (selected_lots, invoice->posted_lot);
diff --git a/libgnucash/engine/gncInvoice.h b/libgnucash/engine/gncInvoice.h
index fce06f2..4fc2e52 100644
--- a/libgnucash/engine/gncInvoice.h
+++ b/libgnucash/engine/gncInvoice.h
@@ -246,7 +246,7 @@ gncInvoiceAutoApplyPayments (GncInvoice *invoice);
* or payments for the owner will be considered
* to balance the payment.
*
- * This code is actually a convenience wrapper around gncOwnerCreatePaymentLot
+ * This code is actually a convenience wrapper around gncOwnerCreatePaymentLotSecs
* and gncOwnerAutoApplyPaymentsWithLots. See their descriptions for more
* details on what happens exactly.
*/
diff --git a/libgnucash/engine/gncOwner.c b/libgnucash/engine/gncOwner.c
index 6011936..a409b79 100644
--- a/libgnucash/engine/gncOwner.c
+++ b/libgnucash/engine/gncOwner.c
@@ -723,10 +723,10 @@ gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB)
}
GNCLot *
-gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn,
- Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, time64 date,
- const char *memo, const char *num)
+gncOwnerCreatePaymentLotSecs (const GncOwner *owner, Transaction **preset_txn,
+ Account *posted_acc, Account *xfer_acc,
+ gnc_numeric amount, gnc_numeric exch, time64 date,
+ const char *memo, const char *num)
{
QofBook *book;
Split *split;
@@ -1376,10 +1376,10 @@ void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots)
* then all open lots for the owner are considered.
*/
void
-gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lots,
- Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, time64 date,
- const char *memo, const char *num, gboolean auto_pay)
+gncOwnerApplyPaymentSecs (const GncOwner *owner, Transaction **preset_txn,
+ GList *lots, Account *posted_acc, Account *xfer_acc,
+ gnc_numeric amount, gnc_numeric exch, time64 date,
+ const char *memo, const char *num, gboolean auto_pay)
{
GNCLot *payment_lot = NULL;
GList *selected_lots = NULL;
@@ -1391,8 +1391,10 @@ gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lo
/* If there's a real amount to transfer create a lot for this payment */
if (!gnc_numeric_zero_p (amount))
- payment_lot = gncOwnerCreatePaymentLot (owner, preset_txn, posted_acc, xfer_acc,
- amount, exch, date, memo, num);
+ payment_lot = gncOwnerCreatePaymentLotSecs (owner, preset_txn,
+ posted_acc, xfer_acc,
+ amount, exch, date, memo,
+ num);
if (lots)
selected_lots = lots;
diff --git a/libgnucash/engine/gncOwner.h b/libgnucash/engine/gncOwner.h
index 79bbaba..28251ac 100644
--- a/libgnucash/engine/gncOwner.h
+++ b/libgnucash/engine/gncOwner.h
@@ -214,10 +214,10 @@ gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType
* split in the transfer account).
*/
GNCLot *
-gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn,
- Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, time64 date,
- const char *memo, const char *num);
+gncOwnerCreatePaymentLotSecs (const GncOwner *owner, Transaction **preset_txn,
+ Account *posted_acc, Account *xfer_acc,
+ gnc_numeric amount, gnc_numeric exch, time64 date,
+ const char *memo, const char *num);
/**
* Given a list of lots, try to balance as many of them as possible
@@ -267,10 +267,10 @@ void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots);
* details on what happens exactly.
*/
void
-gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lots,
- Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, time64 date,
- const char *memo, const char *num, gboolean auto_pay);
+gncOwnerApplyPaymentSecs (const GncOwner *owner, Transaction **preset_txn,
+ GList *lots, Account *posted_acc, Account *xfer_acc,
+ gnc_numeric amount, gnc_numeric exch, time64 date,
+ const char *memo, const char *num, gboolean auto_pay);
/** Helper function to find a split in lot that best offsets target_value
* Obviously it should be of opposite sign.
diff --git a/libgnucash/engine/gncTaxTable.c b/libgnucash/engine/gncTaxTable.c
index f691f70..9175216 100644
--- a/libgnucash/engine/gncTaxTable.c
+++ b/libgnucash/engine/gncTaxTable.c
@@ -39,7 +39,7 @@ struct _gncTaxTable
QofInstance inst;
char * name;
GncTaxTableEntryList* entries;
- Timespec modtime; /* internal date of last modtime */
+ time64 modtime; /* internal date of last modtime */
/* See src/doc/business.txt for an explanation of the following */
/* Code that handles this is *identical* to that in gncBillTerm */
@@ -165,7 +165,7 @@ maybe_resort_list (GncTaxTable *table)
static inline void
mod_table (GncTaxTable *table)
{
- timespecFromTime64 (&table->modtime, gnc_time (NULL));
+ table->modtime = gnc_time (NULL);
}
static inline void addObj (GncTaxTable *table)
@@ -761,10 +761,9 @@ gint64 gncTaxTableGetRefcount (const GncTaxTable *table)
return table->refcount;
}
-Timespec gncTaxTableLastModified (const GncTaxTable *table)
+time64 gncTaxTableLastModifiedSecs (const GncTaxTable *table)
{
- Timespec ts = { 0 , 0 };
- if (!table) return ts;
+ if (!table) return 0;
return table->modtime;
}
diff --git a/libgnucash/engine/gncTaxTable.h b/libgnucash/engine/gncTaxTable.h
index 7d9579a..5215585 100644
--- a/libgnucash/engine/gncTaxTable.h
+++ b/libgnucash/engine/gncTaxTable.h
@@ -41,7 +41,7 @@ is *identical* to that in ::GncBillTerm
@param QofInstance inst;
@param char * name;
@param GncTaxTableEntryList* entries;
- at param Timespec modtime;
+ at param time64 modtime;
@param gint64 refcount;
@param GncTaxTable * parent; if non-null, we are an immutable child
@param GncTaxTable * child; if non-null, we have not changed
@@ -162,7 +162,7 @@ GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new);
typedef GList GncTaxTableEntryList;
GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table);
gint64 gncTaxTableGetRefcount (const GncTaxTable *table);
-Timespec gncTaxTableLastModified (const GncTaxTable *table);
+time64 gncTaxTableLastModifiedSecs (const GncTaxTable *table);
Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry);
GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry);
commit 44c3dc836af2c685644370a908bd8bb4388604a0
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Mon Aug 13 15:47:12 2018 +0100
Bug 796785 - dates cannot be keyboard entered on vendor bill
transactions
Make the gncEntryLedgerModel 'get_date_help' function the same format
as that used in the register.
diff --git a/gnucash/register/ledger-core/gncEntryLedgerModel.c b/gnucash/register/ledger-core/gncEntryLedgerModel.c
index ef47c13..f9e2737 100644
--- a/gnucash/register/ledger-core/gncEntryLedgerModel.c
+++ b/gnucash/register/ledger-core/gncEntryLedgerModel.c
@@ -569,19 +569,16 @@ static char * get_date_help (VirtualLocation virt_loc, gpointer user_data)
GncEntryLedger *ledger = user_data;
BasicCell *cell;
char string[1024];
- struct tm tm;
- time64 tt;
+ GDate date;
cell = gnc_table_get_cell (ledger->table, virt_loc);
- if (!cell)
+ if (!cell || !cell->value || *cell->value == '\0')
return NULL;
- if (!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, &tt);
- gnc_localtime_r (&tt, &tm);
- qof_strftime (string, sizeof(string), _("%A %d %B %Y"), &tm);
+ g_date_strftime (string, sizeof (string), _("%A %d %B %Y"), &date);
return g_strdup (string);
}
commit c8b372e3906a365085a91d2a6f0fa6cd572b6162
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Aug 2 13:29:47 2018 -0700
Convert GNC_TYPE_TIMESPEC to GNC_TYPE_TIME64, Kvp::Type::Timespec to Kvp::Type::Time64
They have to go together because of using gvalues to hide KVP from most of
GnuCash.
diff --git a/gnucash/import-export/aqb/gnc-ab-kvp.c b/gnucash/import-export/aqb/gnc-ab-kvp.c
index 4b5b1f6..ed0a1c5 100644
--- a/gnucash/import-export/aqb/gnc-ab-kvp.c
+++ b/gnucash/import-export/aqb/gnc-ab-kvp.c
@@ -98,20 +98,20 @@ gnc_ab_set_account_uid(Account *a, guint32 uid)
time64
gnc_ab_get_account_trans_retrieval(const Account *a)
{
- Timespec *t = NULL;
+ Time64 *t = NULL;
qof_instance_get (QOF_INSTANCE (a),
"ab-trans-retrieval", &t,
NULL);
- return t ? t->tv_sec : 0;
+ return t ? t->t : 0;
}
void
gnc_ab_set_account_trans_retrieval(Account *a, time64 time)
{
- Timespec ts = {time, 0};
+ Time64 t = {time};
xaccAccountBeginEdit(a);
qof_instance_set (QOF_INSTANCE (a),
- "ab-trans-retrieval", &ts,
+ "ab-trans-retrieval", &t,
NULL);
xaccAccountCommitEdit(a);
}
diff --git a/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp b/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp
index 1447f39..4c0d7ac 100644
--- a/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp
+++ b/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp
@@ -138,7 +138,7 @@ setup_memory (Fixture* fixture, gconstpointer pData)
frame->set ({"int64-val"}, new KvpValue (INT64_C (100)));
frame->set ({"double-val"}, new KvpValue (3.14159));
frame->set ({"numeric-val"}, new KvpValue (gnc_numeric_zero ()));
- frame->set ({"timespec-val"}, new KvpValue (timespec_now ()));
+ frame->set ({"timespec-val"}, new KvpValue (gnc_time(nullptr)));
frame->set ({"string-val"}, new KvpValue ("abcdefghijklmnop"));
auto guid = qof_instance_get_guid (QOF_INSTANCE (acct1));
frame->set ({"guid-val"}, new KvpValue (const_cast<GncGUID*> (guid_copy (
diff --git a/libgnucash/backend/sql/gnc-slots-sql.cpp b/libgnucash/backend/sql/gnc-slots-sql.cpp
index d0a5145..6cb48ff 100644
--- a/libgnucash/backend/sql/gnc-slots-sql.cpp
+++ b/libgnucash/backend/sql/gnc-slots-sql.cpp
@@ -397,8 +397,9 @@ get_timespec_val (gpointer pObject)
g_return_val_if_fail (pObject != NULL, gnc_dmy2timespec (1, 1, 1970));
-//if( kvp_value_get_type( pInfo->pKvpValue ) == KvpValue::Type::TIMESPEC ) {
- return pInfo->pKvpValue->get<Timespec> ();
+//if( kvp_value_get_type( pInfo->pKvpValue ) == KvpValue::Type::TIME64 ) {
+ auto t = pInfo->pKvpValue->get<Time64> ();
+ return {t.t, 0};
}
static void
@@ -406,11 +407,11 @@ set_timespec_val (gpointer pObject, Timespec *ts)
{
slot_info_t* pInfo = (slot_info_t*)pObject;
KvpValue* value = NULL;
-
+ Time64 t{ts->tv_sec};
g_return_if_fail (pObject != NULL);
- if (pInfo->value_type != KvpValue::Type::TIMESPEC) return;
- value = new KvpValue {*ts};
+ if (pInfo->value_type != KvpValue::Type::TIME64) return;
+ value = new KvpValue {t};
set_slot_from_value (pInfo, value);
}
diff --git a/libgnucash/backend/xml/sixtp-dom-generators.cpp b/libgnucash/backend/xml/sixtp-dom-generators.cpp
index ce7bc5b..4d8fff4 100644
--- a/libgnucash/backend/xml/sixtp-dom-generators.cpp
+++ b/libgnucash/backend/xml/sixtp-dom-generators.cpp
@@ -237,7 +237,7 @@ add_kvp_value_node (xmlNodePtr node, const gchar* tag, KvpValue* val)
g_free (newstr);
break;
}
- case KvpValue::Type::TIMESPEC:
+ case KvpValue::Type::TIME64:
val_node = NULL;
break;
case KvpValue::Type::GDATE:
@@ -277,10 +277,10 @@ add_kvp_value_node (xmlNodePtr node, const gchar* tag, KvpValue* val)
add_text_to_node (val_node, "guid", guidstr);
break;
}
- case KvpValue::Type::TIMESPEC:
+ case KvpValue::Type::TIME64:
{
- auto ts = val->get<Timespec> ();
- val_node = time64_to_dom_tree (tag, ts.tv_sec);
+ auto t = val->get<Time64> ();
+ val_node = time64_to_dom_tree (tag, t.t);
xmlSetProp (val_node, BAD_CAST "type", BAD_CAST "timespec");
xmlAddChild (node, val_node);
break;
diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.cpp b/libgnucash/backend/xml/sixtp-dom-parsers.cpp
index a788ef0..1408004 100644
--- a/libgnucash/backend/xml/sixtp-dom-parsers.cpp
+++ b/libgnucash/backend/xml/sixtp-dom-parsers.cpp
@@ -235,7 +235,8 @@ dom_tree_to_guid_kvp_value (xmlNodePtr node)
static KvpValue*
dom_tree_to_time64_kvp_value (xmlNodePtr node)
{
- return new KvpValue {Timespec {dom_tree_to_time64 (node), 0}};
+ Time64 t{dom_tree_to_time64 (node)};
+ return new KvpValue {t};
}
static KvpValue*
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 7920660..5379b0a 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -995,7 +995,7 @@ gnc_account_class_init (AccountClass *klass)
"AQBanking Last Transaction Retrieval",
"The time of the last transaction retrieval for this "
"account.",
- GNC_TYPE_TIMESPEC,
+ GNC_TYPE_TIME64,
static_cast<GParamFlags>(G_PARAM_READWRITE)));
}
diff --git a/libgnucash/engine/Split.c b/libgnucash/engine/Split.c
index b10714e..b709551 100644
--- a/libgnucash/engine/Split.c
+++ b/libgnucash/engine/Split.c
@@ -170,7 +170,7 @@ gnc_split_get_property(GObject *object,
g_value_set_boxed(value, &split->amount);
break;
case PROP_RECONCILE_DATE:
- g_value_set_boxed(value, &split->date_reconciled);
+ g_value_set_boxed(value, &split->date_reconciled.tv_sec);
break;
case PROP_TX:
g_value_take_object(value, split->parent);
@@ -223,7 +223,7 @@ gnc_split_set_property(GObject *object,
Split *split;
gnc_numeric* number;
gchar *key;
-
+ Time64 *t;
g_return_if_fail(GNC_IS_SPLIT(object));
split = GNC_SPLIT(object);
@@ -247,7 +247,8 @@ gnc_split_set_property(GObject *object,
xaccSplitSetAmount(split, *number);
break;
case PROP_RECONCILE_DATE:
- xaccSplitSetDateReconciledTS(split, g_value_get_boxed(value));
+ t = g_value_get_boxed(value);
+ xaccSplitSetDateReconciledSecs(split, t->t);
break;
case PROP_TX:
xaccSplitSetParent(split, g_value_get_object(value));
@@ -353,7 +354,7 @@ gnc_split_class_init(SplitClass* klass)
g_param_spec_boxed("reconcile-date",
"Reconcile Date",
"The date this split was reconciled.",
- GNC_TYPE_TIMESPEC,
+ GNC_TYPE_TIME64,
G_PARAM_READWRITE));
g_object_class_install_property
diff --git a/libgnucash/engine/Transaction.c b/libgnucash/engine/Transaction.c
index 8f8469b..2223c89 100644
--- a/libgnucash/engine/Transaction.c
+++ b/libgnucash/engine/Transaction.c
@@ -310,7 +310,6 @@ gnc_transaction_get_property(GObject* object,
{
Transaction* tx;
gchar *key;
- Timespec ts = {0,0};
g_return_if_fail(GNC_IS_TRANSACTION(object));
@@ -327,12 +326,10 @@ gnc_transaction_get_property(GObject* object,
g_value_take_object(value, tx->common_currency);
break;
case PROP_POST_DATE:
- ts.tv_sec = tx->date_posted;
- g_value_set_boxed(value, &ts);
+ g_value_set_boxed(value, &tx->date_posted);
break;
case PROP_ENTER_DATE:
- ts.tv_sec = tx->date_entered;
- g_value_set_boxed(value, &ts);
+ g_value_set_boxed(value, &tx->date_entered);
break;
case PROP_INVOICE:
qof_instance_get_kvp (QOF_INSTANCE (tx), value, 2, GNC_INVOICE_ID, GNC_INVOICE_GUID);
@@ -357,6 +354,7 @@ gnc_transaction_set_property(GObject* object,
{
Transaction* tx;
gchar *key;
+ Time64 *t;
g_return_if_fail(GNC_IS_TRANSACTION(object));
@@ -375,10 +373,12 @@ gnc_transaction_set_property(GObject* object,
xaccTransSetCurrency(tx, g_value_get_object(value));
break;
case PROP_POST_DATE:
- xaccTransSetDatePostedSecs(tx, ((Timespec*)g_value_get_boxed(value))->tv_sec);
+ t = (Time64*)g_value_get_boxed(value);
+ xaccTransSetDatePostedSecs(tx, t->t);
break;
case PROP_ENTER_DATE:
- xaccTransSetDateEnteredSecs(tx, ((Timespec*)g_value_get_boxed(value))->tv_sec);
+ t = (Time64*)g_value_get_boxed(value);
+ xaccTransSetDateEnteredSecs(tx, t->t);
break;
case PROP_INVOICE:
qof_instance_set_kvp (QOF_INSTANCE (tx), value, 2, GNC_INVOICE_ID, GNC_INVOICE_GUID);
@@ -446,7 +446,7 @@ gnc_transaction_class_init(TransactionClass* klass)
g_param_spec_boxed("post-date",
"Post Date",
"The date the transaction occurred.",
- GNC_TYPE_TIMESPEC,
+ GNC_TYPE_TIME64,
G_PARAM_READWRITE));
g_object_class_install_property
@@ -455,7 +455,7 @@ gnc_transaction_class_init(TransactionClass* klass)
g_param_spec_boxed("enter-date",
"Enter Date",
"The date the transaction was entered.",
- GNC_TYPE_TIMESPEC,
+ GNC_TYPE_TIME64,
G_PARAM_READWRITE));
g_object_class_install_property(
@@ -2035,10 +2035,9 @@ void
xaccTransSetDateDue (Transaction * trans, time64 time)
{
GValue v = G_VALUE_INIT;
- Timespec send_ts = {time, 0};
if (!trans) return;
- g_value_init (&v, GNC_TYPE_TIMESPEC);
- g_value_set_boxed (&v, &send_ts);
+ g_value_init (&v, GNC_TYPE_TIME64);
+ g_value_set_boxed (&v, &time);
xaccTransBeginEdit(trans);
qof_instance_set_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_DUE_KVP);
qof_instance_set_dirty(QOF_INSTANCE(trans));
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 3107f1a..23e2a81 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -1262,18 +1262,6 @@ gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
}
}
-void
-gnc_timespec2dmy (Timespec t, int *day, int *month, int *year)
-{
- struct tm result;
- time64 t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
- gnc_localtime_r(&t_secs, &result);
-
- if (day) *day = result.tm_mday;
- if (month) *month = result.tm_mon + 1;
- if (year) *year = result.tm_year + 1900;
-}
-
#define THIRTY_TWO_YEARS 0x3c30fc00LL
static Timespec
@@ -1518,33 +1506,34 @@ gnc_dow_abbrev(gchar *buf, int buf_len, int dow)
/* *******************************************************************
* GValue handling
********************************************************************/
+
static gpointer
-timespec_boxed_copy_func( gpointer in_timespec )
+time64_boxed_copy_func (gpointer in_time64)
{
- Timespec* newvalue;
+ Time64* newvalue;
- newvalue = static_cast<Timespec*>(g_malloc (sizeof (Timespec)));
- memcpy( newvalue, in_timespec, sizeof( Timespec ) );
+ newvalue = static_cast<Time64*>(g_malloc (sizeof (Time64)));
+ memcpy (newvalue, in_time64, sizeof(Time64));
return newvalue;
}
static void
-timespec_boxed_free_func( gpointer in_timespec )
+time64_boxed_free_func (gpointer in_time64)
{
- g_free( in_timespec );
+ g_free (in_time64);
}
GType
-timespec_get_type( void )
+time64_get_type( void )
{
static GType type = 0;
if ( type == 0 )
{
- type = g_boxed_type_register_static( "timespec",
- timespec_boxed_copy_func,
- timespec_boxed_free_func );
+ type = g_boxed_type_register_static( "time64",
+ time64_boxed_copy_func,
+ time64_boxed_free_func );
}
return type;
}
diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h
index ce00801..140dc92 100644
--- a/libgnucash/engine/gnc-date.h
+++ b/libgnucash/engine/gnc-date.h
@@ -82,6 +82,14 @@ extern "C"
* this stops working in 2038, we define our own:
*/
typedef gint64 time64;
+/* A bit of a hack to create a type separate from the alias of int64_t so that
+ * compile-time dispatch can use the right KVP visitor.
+ */
+typedef struct
+{
+ time64 t;
+} Time64;
+
/** The Timespec is just like the unix 'struct timespec'
* except that we use a 64-bit unsigned int to
@@ -96,8 +104,8 @@ typedef struct timespec64 Timespec;
/** @name GValue
@{
*/
-GType timespec_get_type( void );
-#define GNC_TYPE_TIMESPEC (timespec_get_type ())
+GType time64_get_type( void );
+#define GNC_TYPE_TIME64 (time64_get_type ())
/** @} */
/** The default date format for use with strftime. */
diff --git a/libgnucash/engine/gncInvoice.h b/libgnucash/engine/gncInvoice.h
index fa9eedc..fce06f2 100644
--- a/libgnucash/engine/gncInvoice.h
+++ b/libgnucash/engine/gncInvoice.h
@@ -101,7 +101,7 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *other_invoice);
void gncInvoiceSetID (GncInvoice *invoice, const char *id);
void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner);
/** Set the DateOpened using a GDate argument. (Note: Internally this stores
-the date in a time64 as created through timespecCanonicalDayTime()). */
+the date in a time64 as created through time64CanonicalDayTime()). */
void gncInvoiceSetDateOpenedGDate (GncInvoice *invoice, const GDate *date);
void gncInvoiceSetDateOpened (GncInvoice *invoice, time64 date);
void gncInvoiceSetDatePosted (GncInvoice *invoice, time64 date);
diff --git a/libgnucash/engine/gncOrder.c b/libgnucash/engine/gncOrder.c
index b80f406..2130e6d 100644
--- a/libgnucash/engine/gncOrder.c
+++ b/libgnucash/engine/gncOrder.c
@@ -257,7 +257,7 @@ gnc_order_class_init (GncOrderClass *klass)
g_param_spec_boxed("date-opened",
"Date Opened",
"The date the order was opened.",
- GNC_TYPE_TIMESPEC,
+ GNC_TYPE_TIME64,
G_PARAM_READWRITE));
g_object_class_install_property
@@ -266,7 +266,7 @@ gnc_order_class_init (GncOrderClass *klass)
g_param_spec_boxed("date-closed",
"Date Closed",
"The date the order was closed.",
- GNC_TYPE_TIMESPEC,
+ GNC_TYPE_TIME64,
G_PARAM_READWRITE));
g_object_class_install_property
diff --git a/libgnucash/engine/kvp-frame.cpp b/libgnucash/engine/kvp-frame.cpp
index b320814..60a46ed 100644
--- a/libgnucash/engine/kvp-frame.cpp
+++ b/libgnucash/engine/kvp-frame.cpp
@@ -261,7 +261,7 @@ gvalue_from_kvp_value (const KvpValue *kval)
{
GValue *val;
gnc_numeric num;
- Timespec tm;
+ Time64 tm;
GDate gdate;
if (kval == NULL) return NULL;
@@ -290,9 +290,9 @@ gvalue_from_kvp_value (const KvpValue *kval)
g_value_init (val, GNC_TYPE_GUID);
g_value_set_boxed (val, kval->get<GncGUID*>());
break;
- case KvpValue::Type::TIMESPEC:
- g_value_init (val, GNC_TYPE_TIMESPEC);
- tm = kval->get<Timespec>();
+ case KvpValue::Type::TIME64:
+ g_value_init (val, GNC_TYPE_TIME64);
+ tm = kval->get<Time64>();
g_value_set_boxed (val, &tm);
break;
case KvpValue::Type::GDATE:
@@ -357,8 +357,8 @@ kvp_value_from_gvalue (const GValue *gval)
if (boxed != nullptr)
val = new KvpValue(guid_copy(static_cast<GncGUID*>(boxed)));
}
- else if (type == GNC_TYPE_TIMESPEC)
- val = new KvpValue(*(Timespec*)g_value_get_boxed (gval));
+ else if (type == GNC_TYPE_TIME64)
+ val = new KvpValue(*(Time64*)g_value_get_boxed (gval));
else if (type == G_TYPE_DATE)
val = new KvpValue(*(GDate*)g_value_get_boxed (gval));
else if (type == GNC_TYPE_VALUE_LIST)
diff --git a/libgnucash/engine/kvp-value.cpp b/libgnucash/engine/kvp-value.cpp
index 990197e..ab2f3be 100644
--- a/libgnucash/engine/kvp-value.cpp
+++ b/libgnucash/engine/kvp-value.cpp
@@ -85,8 +85,8 @@ KvpValueImpl::get_type() const noexcept
return KvpValue::Type::STRING;
else if (datastore.type() == typeid(GncGUID *))
return KvpValue::Type::GUID;
- else if (datastore.type() == typeid(Timespec))
- return KvpValue::Type::TIMESPEC;
+ else if (datastore.type() == typeid(Time64))
+ return KvpValue::Type::TIME64;
else if (datastore.type() == typeid(GList *))
return KvpValue::Type::GLIST;
else if (datastore.type() == typeid(KvpFrameImpl *))
@@ -155,11 +155,11 @@ struct to_string_visitor : boost::static_visitor<void>
output << ")";
}
- void operator()(Timespec val)
+ void operator()(Time64 val)
{
- char tmp1[40] {};
- gnc_timespec_to_iso8601_buff (val, tmp1);
- output << tmp1 << " (timespec)";
+ char tmp1[MAX_DATE_LENGTH + 1] {};
+ gnc_time64_to_iso8601_buff (val.t, tmp1);
+ output << tmp1 << " (time64)";
}
void operator()(gnc_numeric val)
@@ -301,9 +301,9 @@ template <> int compare_visitor::operator()(GncGUID * const & one, GncGUID * con
{
return guid_compare(one, two);
}
-template <> int compare_visitor::operator()(Timespec const & one, Timespec const & two) const
+template <> int compare_visitor::operator()(Time64 const & one, Time64 const & two) const
{
- return timespec_cmp(&one,&two);
+ return one.t < two.t ? -1 : one.t > two.t ? 1 : 0;
}
template <> int compare_visitor::operator()(GDate const & one, GDate const & two) const
{
diff --git a/libgnucash/engine/kvp-value.hpp b/libgnucash/engine/kvp-value.hpp
index 78a8eb7..acc072b 100644
--- a/libgnucash/engine/kvp-value.hpp
+++ b/libgnucash/engine/kvp-value.hpp
@@ -65,7 +65,7 @@ struct KvpValueImpl
NUMERIC, /**< QOF_TYPE_NUMERIC */
STRING, /**< QOF_TYPE_STRING gchar* */
GUID, /**< QOF_TYPE_GUID */
- TIMESPEC, /**< QOF_TYPE_DATE */
+ TIME64, /**< QOF_TYPE_DATE */
PLACEHOLDER_DONT_USE, /* Replaces KVP_TYPE_BINARY */
GLIST, /**< no QOF equivalent. */
FRAME, /**< no QOF equivalent. */
@@ -156,7 +156,7 @@ struct KvpValueImpl
gnc_numeric,
const char*,
GncGUID *,
- Timespec,
+ Time64,
GList *,
KvpFrame *,
GDate> datastore;
diff --git a/libgnucash/engine/kvp_doc.txt b/libgnucash/engine/kvp_doc.txt
index e9f6717..4f36b40 100644
--- a/libgnucash/engine/kvp_doc.txt
+++ b/libgnucash/engine/kvp_doc.txt
@@ -72,7 +72,7 @@ Use: An enumerated identifier indicating how often books are supposed
\verbatim
Name: /book/close-date
-Type: Timespec
+Type: Time64
Entities: Book
Use: The posted closing date of this book. This book only contains
transactions whose posted date is earlier than this closing date.
@@ -98,7 +98,7 @@ Use: The GUID of the book for which this transaction represents the
\verbatim
Name: /book/log-date
-Type: Timespec
+Type: Time64
Entities: Book
Use: A log of the date which the user performed the closing of the book.
\endverbatim
@@ -131,7 +131,7 @@ Use: User-suplied notes for the book. The user can set this to any value
\verbatim
Name: /book/open-date
-Type: Timespec
+Type: Time64
Entities: Book
Use: The posted opening date of this book. This book only contains transactions
whose posted date is later than this closing date.
@@ -254,7 +254,7 @@ Use: When this appears in an account, then it contains the guid of
\verbatim
Name: /gemini/<type>/date
-Type: timespec
+Type: time64
Entities: Account, Book
Use: date that the copy was created.
\endverbatim
@@ -293,7 +293,7 @@ Use: Country code of the bank of HBCI account
\verbatim
Name: /hbci/trans-retrieval
-Type: Timespec
+Type: Time64
Entities: Account
Use: Time of the last statement retrieval through HBCI for this
specific account
@@ -577,7 +577,7 @@ Use: A user-supplied title for the lot. The user can set this to
\verbatim
Name: trans-date-due
-Type: Timespec
+Type: Time64
Entities: Transaction
Use: Accounts/Receivable, Accounts/Payable Due Date.
\endverbatim
diff --git a/libgnucash/engine/qofinstance.cpp b/libgnucash/engine/qofinstance.cpp
index db5a88b..0ce79c0 100644
--- a/libgnucash/engine/qofinstance.cpp
+++ b/libgnucash/engine/qofinstance.cpp
@@ -1144,8 +1144,9 @@ qof_instance_kvp_add_guid (const QofInstance *inst, const char* path,
g_return_if_fail (inst->kvp_data != NULL);
auto container = new KvpFrame;
+ Time64 t{time.tv_sec};
container->set({key}, new KvpValue(const_cast<GncGUID*>(guid)));
- container->set({"date"}, new KvpValue(time));
+ container->set({"date"}, new KvpValue(t));
delete inst->kvp_data->set_path({path}, new KvpValue(container));
}
diff --git a/libgnucash/engine/test-core/test-engine-stuff.cpp b/libgnucash/engine/test-core/test-engine-stuff.cpp
index 9f9d5f9..045ac34 100644
--- a/libgnucash/engine/test-core/test-engine-stuff.cpp
+++ b/libgnucash/engine/test-core/test-engine-stuff.cpp
@@ -324,11 +324,10 @@ get_random_kvp_value_depth (int type, gint depth)
}
break;
- case KvpValue::Type::TIMESPEC:
+ case KvpValue::Type::TIME64:
{
- Timespec *ts = get_random_timespec();
- ret = new KvpValue(*ts);
- g_free(ts);
+ time64 t = get_random_time();
+ ret = new KvpValue(t);
}
break;
diff --git a/libgnucash/engine/test/test-engine-kvp-properties.c b/libgnucash/engine/test/test-engine-kvp-properties.c
index f857e5d..baddd35 100644
--- a/libgnucash/engine/test/test-engine-kvp-properties.c
+++ b/libgnucash/engine/test/test-engine-kvp-properties.c
@@ -144,8 +144,8 @@ test_account_kvp_properties (Fixture *fixture, gconstpointer pData)
gchar *online_id_r, *ab_acct_id_r, *ab_bank_code_r;
GncGUID *ofx_income_acct = guid_malloc ();
GncGUID *ofx_income_acct_r;
- Timespec trans_retr = timespec_now ();
- Timespec *trans_retr_r;
+ Time64 trans_retr = {gnc_time(NULL)};
+ Time64 *trans_retr_r;
xaccAccountBeginEdit (fixture->acct);
qof_instance_set (QOF_INSTANCE (fixture->acct),
@@ -176,7 +176,7 @@ test_account_kvp_properties (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (ab_acct_id, ==, ab_acct_id_r);
g_assert_cmpstr (ab_bank_code, ==, ab_bank_code_r);
g_assert_cmpint (ab_acct_uid, ==, ab_acct_uid_r);
- g_assert (timespec_equal (&trans_retr, trans_retr_r));
+ g_assert_cmpint (trans_retr.t, ==, trans_retr_r->t);
g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->acct)));
}
diff --git a/libgnucash/engine/test/test-kvp-value.cpp b/libgnucash/engine/test/test-kvp-value.cpp
index f564fe3..b89a408 100644
--- a/libgnucash/engine/test/test-kvp-value.cpp
+++ b/libgnucash/engine/test/test-kvp-value.cpp
@@ -55,14 +55,14 @@ TEST (KvpValueTest, Equality)
v2 = std::unique_ptr<KvpValueImpl> {new KvpValueImpl {guid_copy (guid)}};
EXPECT_EQ (compare (*v1, *v2), 0);
- v1 = std::unique_ptr<KvpValueImpl> {new KvpValueImpl {timespec_now ()}};
+ v1 = std::unique_ptr<KvpValueImpl> {new KvpValueImpl {gnc_time(nullptr)}};
v2 = std::unique_ptr<KvpValueImpl> {new KvpValueImpl {*v1}};
EXPECT_EQ (compare (*v1, *v2), 0);
}
TEST (KvpValueTest, Add)
{
- auto v3 = new KvpValueImpl {timespec_now ()};
+ auto v3 = new KvpValueImpl {gnc_time(nullptr)};
auto v4 = new KvpValueImpl {*v3};
auto new_one = v3->add (v4);
EXPECT_NE (new_one, v3);
diff --git a/libgnucash/engine/test/utest-Split.cpp b/libgnucash/engine/test/utest-Split.cpp
index 23bff9b..bbf296f 100644
--- a/libgnucash/engine/test/utest-Split.cpp
+++ b/libgnucash/engine/test/utest-Split.cpp
@@ -201,7 +201,8 @@ test_gnc_split_set_get_property ()
Account *acc = xaccMallocAccount (book), *racc = NULL;
GNCLot *lot = gnc_lot_new (book), *rlot = NULL;
Split *split = xaccMallocSplit (book);
- Timespec time = timespec_now (), *rtime;
+ time64 time = gnc_time(nullptr);
+ Time64 t = {time}, *rtime;
char *r_action, *r_memo;
gnc_numeric value = gnc_numeric_create (123, 100);
gnc_numeric amount = gnc_numeric_create (321, 100);
@@ -218,7 +219,7 @@ test_gnc_split_set_get_property ()
"memo", "bar",
"value", &value,
"amount", &amount,
- "reconcile-date", &time,
+ "reconcile-date", &t,
"account", acc,
"lot", lot,
"transaction", txn,
@@ -240,7 +241,7 @@ test_gnc_split_set_get_property ()
g_assert (gnc_numeric_equal (*r_value, value));
/* Setting the transaction causes the amount to be scrubbed into the value */
g_assert (gnc_numeric_equal (*r_amount, value));
- g_assert (timespec_equal (rtime, &time));
+ g_assert_cmpint (rtime->t, ==, time);
g_assert (txn == rtxn);
g_assert (acc == racc);
g_assert (lot == rlot);
commit b60aef9d2a5f793227c58c302345975c28a6c774
Author: John Ralls <jralls at ceridwen.us>
Date: Tue Jul 31 16:19:39 2018 -0700
Remove timespec2dmy.
It had only two uses and one was in a test. Replace those calls with
gnc_localtime_r.
diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h
index 2b34ae3..ce00801 100644
--- a/libgnucash/engine/gnc-date.h
+++ b/libgnucash/engine/gnc-date.h
@@ -415,15 +415,6 @@ time64 gnc_iso8601_to_time64_gmt(const gchar *);
*/
gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
gchar * gnc_time64_to_iso8601_buff (time64, char * buff);
-
-/** Set the proleptic Gregorian day, month, and year from a Timespec
- * \param ts: input timespec
- * \param day: output day, 1 - 31
- * \param month: output month, 1 - 12
- * \param year: output year, 0001 - 9999 CE
- */
-void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
-
// @}
/* ======================================================== */
diff --git a/libgnucash/engine/gncBillTerm.c b/libgnucash/engine/gncBillTerm.c
index 525d8f1..73e19d7 100644
--- a/libgnucash/engine/gncBillTerm.c
+++ b/libgnucash/engine/gncBillTerm.c
@@ -753,15 +753,18 @@ gboolean gncBillTermIsDirty (const GncBillTerm *term)
*
*/
static void
-compute_monthyear (const GncBillTerm *term, Timespec post_date,
+compute_monthyear (const GncBillTerm *term, time64 post_date,
int *month, int *year)
{
int iday, imonth, iyear;
+ struct tm tm;
int cutoff = term->cutoff;
g_return_if_fail (term->type == GNC_TERM_TYPE_PROXIMO);
-
- gnc_timespec2dmy (post_date, &iday, &imonth, &iyear);
+ gnc_localtime_r (&post_date, &tm);
+ iday = tm.tm_mday;
+ imonth = tm.tm_mon + 1;
+ iyear = tm.tm_year + 1;
if (cutoff <= 0)
cutoff += gnc_date_get_last_mday (imonth - 1, iyear);
@@ -810,7 +813,7 @@ compute_time (const GncBillTerm *term, Timespec post_date, int days)
res.tv_sec += (SECS_PER_DAY * days);
break;
case GNC_TERM_TYPE_PROXIMO:
- compute_monthyear (term, post_date, &month, &year);
+ compute_monthyear (term, post_date.tv_sec, &month, &year);
day = gnc_date_get_last_mday (month - 1, year);
if (days < day)
day = days;
diff --git a/libgnucash/engine/test/test-date.cpp b/libgnucash/engine/test/test-date.cpp
index 9014fcd..86f802d 100644
--- a/libgnucash/engine/test/test-date.cpp
+++ b/libgnucash/engine/test/test-date.cpp
@@ -82,15 +82,19 @@ static gboolean
check_conversion (const char * str, Timespec expected_ts)
{
Timespec ts;
+ struct tm tm;
int day, month, year;
GDate d1, d2;
ts = {gnc_iso8601_to_time64_gmt (str), 0};
- // We test the conversion to GDate against the timespec2dmy
+ // We test the conversion to GDate against the gnc_localtime_r
// conversion, and also the conversion back to timespec and again
// to GDate so that it is still the original GDate
- gnc_timespec2dmy(ts, &day, &month, &year);
+ gnc_localtime_r (&ts.tv_sec, &tm);
+ day = tm.tm_mday;
+ month = tm.tm_mon + 1;
+ year = tm.tm_year + 1900;
d1 = timespec_to_gdate(ts);
d2 = timespec_to_gdate(gdate_to_timespec(d1));
if ((g_date_compare(&d1, &d2) != 0)
diff --git a/libgnucash/engine/test/test-gnc-date.c b/libgnucash/engine/test/test-gnc-date.c
index b262ff6..c084b3d 100644
--- a/libgnucash/engine/test/test-gnc-date.c
+++ b/libgnucash/engine/test/test-gnc-date.c
@@ -1738,54 +1738,7 @@ test_gnc_timespec_to_iso8601_buff (FixtureA *f, gconstpointer pData)
g_assert_cmpstr (buff, ==, time_str);
g_free (time_str);
}
-/* gnc_timespec2dmy
-void
-gnc_timespec2dmy (Timespec t, int *day, int *month, int *year)// C: 1 Local: 0:0:0
-*/
-static void
-test_gnc_timespec2dmy (FixtureA *f, gconstpointer pData)
-{
- struct tm tm;
- int day, r_day, mo, r_mo, yr, r_yr;
-
-
- gnc_timespec2dmy (f->ts0, &r_day, &r_mo, &r_yr);
- gnc_localtime_r (&f->ts0.tv_sec, &tm);
- g_assert_cmpint (r_day, ==, tm.tm_mday);
- g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
- g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
-
- gnc_timespec2dmy (f->ts1, &r_day, &r_mo, &r_yr);
- gnc_localtime_r (&f->ts1.tv_sec, &tm);
- g_assert_cmpint (r_day, ==, tm.tm_mday);
- g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
- g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
-
- gnc_timespec2dmy (f->ts2, &r_day, &r_mo, &r_yr);
- gnc_localtime_r (&f->ts2.tv_sec, &tm);
- g_assert_cmpint (r_day, ==, tm.tm_mday);
- g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
- g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
-
- gnc_timespec2dmy (f->ts3, &r_day, &r_mo, &r_yr);
- gnc_localtime_r (&f->ts3.tv_sec, &tm);
- g_assert_cmpint (r_day, ==, tm.tm_mday);
- g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
- g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
-
- gnc_timespec2dmy (f->ts4, &r_day, &r_mo, &r_yr);
- gnc_localtime_r (&f->ts4.tv_sec, &tm);
- g_assert_cmpint (r_day, ==, tm.tm_mday);
- g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
- g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
-
- gnc_timespec2dmy (f->ts5, &r_day, &r_mo, &r_yr);
- gnc_localtime_r (&f->ts5.tv_sec, &tm);
- g_assert_cmpint (r_day, ==, tm.tm_mday);
- g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
- g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
-}
/* gnc_dmy2timespec_internal
static Timespec
gnc_dmy2timespec_internal (int day, int month, int year, gboolean start_of_day)// Local: 2:0:0
@@ -2259,7 +2212,6 @@ test_suite_gnc_date (void)
GNC_TEST_ADD_FUNC (suitename, "gnc_date_timestamp", test_gnc_date_timestamp);
GNC_TEST_ADD (suitename, "gnc iso8601 to time64 gmt", FixtureA, NULL, setup, test_gnc_iso8601_to_time64_gmt, NULL);
GNC_TEST_ADD (suitename, "gnc timespec to iso8601 buff", FixtureA, NULL, setup, test_gnc_timespec_to_iso8601_buff, NULL);
- GNC_TEST_ADD (suitename, "gnc timespec2dmy", FixtureA, NULL, setup, test_gnc_timespec2dmy, NULL);
// GNC_TEST_ADD_FUNC (suitename, "gnc dmy2timespec internal", test_gnc_dmy2timespec_internal);
GNC_TEST_ADD (suitename, "gnc dmy2timespec", FixtureB, NULL, setup_begin, test_gnc_dmy2timespec, NULL);
commit 6f89bd62b3cf7089fb10c1c1ed908f0d9b5cc31c
Author: John Ralls <jralls at ceridwen.us>
Date: Tue Jul 31 14:43:27 2018 -0700
Remove timespec from gnucash/gnome.
With a little API bleed into engine.
diff --git a/gnucash/gnome/assistant-acct-period.c b/gnucash/gnome/assistant-acct-period.c
index 87a503a..06e9bb4 100644
--- a/gnucash/gnome/assistant-acct-period.c
+++ b/gnucash/gnome/assistant-acct-period.c
@@ -465,7 +465,6 @@ ap_assistant_finish (GtkAssistant *assistant, gpointer user_data)
gint len;
const char *btitle;
char *bnotes;
- Timespec closing_date;
ENTER("info=%p", info);
@@ -478,8 +477,6 @@ ap_assistant_finish (GtkAssistant *assistant, gpointer user_data)
bnotes = gtk_text_buffer_get_text(buffer, &startiter, &enditer , 0);
PINFO("Book title is - %s\n", btitle);
- timespecFromTime64 (&closing_date,
- gnc_time64_get_day_end_gdate (&info->closing_date));
g_free(bnotes);
/* Report the status back to the user. */
diff --git a/gnucash/gnome/assistant-stock-split.c b/gnucash/gnome/assistant-stock-split.c
index 287a437..77fb8b3 100644
--- a/gnucash/gnome/assistant-stock-split.c
+++ b/gnucash/gnome/assistant-stock-split.c
@@ -388,19 +388,14 @@ gnc_stock_split_assistant_finish (GtkAssistant *assistant,
GNCPrice *price;
GNCPriceDB *pdb;
GNCCurrencyEdit *ce;
- Timespec ts;
ce = GNC_CURRENCY_EDIT (info->price_currency_edit);
-
- ts.tv_sec = date;
- ts.tv_nsec = 0;
-
price = gnc_price_create (gnc_get_current_book ());
gnc_price_begin_edit (price);
gnc_price_set_commodity (price, xaccAccountGetCommodity (account));
gnc_price_set_currency (price, gnc_currency_edit_get_currency (ce));
- gnc_price_set_time (price, ts);
+ gnc_price_set_time64 (price, date);
gnc_price_set_source (price, PRICE_SOURCE_STOCK_SPLIT);
gnc_price_set_typestr (price, PRICE_TYPE_UNK);
gnc_price_set_value (price, amount);
diff --git a/gnucash/gnome/dialog-date-close.c b/gnucash/gnome/dialog-date-close.c
index 6a34d80..977a637 100644
--- a/gnucash/gnome/dialog-date-close.c
+++ b/gnucash/gnome/dialog-date-close.c
@@ -45,7 +45,7 @@ typedef struct _dialog_date_close_window
GtkWidget *memo_entry;
GtkWidget *question_check;
GncBillTerm *terms;
- Timespec *ts, *ts2;
+ time64 t, t2;
GList * acct_types;
GList * acct_commodities;
QofBook *book;
@@ -87,14 +87,14 @@ gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data)
}
if (ddc->post_date)
- ddc->ts2->tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->post_date));
+ ddc->t2 = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->post_date));
if (ddc->date)
{
if (ddc->terms)
- ddc->ts->tv_sec = gncBillTermComputeDueDate (ddc->terms, ddc->ts2->tv_sec);
+ ddc->t = gncBillTermComputeDueDate (ddc->terms, ddc->t2);
else
- ddc->ts->tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->date));
+ ddc->t = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->date));
}
if (ddc->memo_entry && ddc->memo)
@@ -122,7 +122,7 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
const char *label_message,
gboolean ok_is_default,
/* Returned data ... */
- Timespec *ts)
+ time64 *t)
{
DialogDateClose *ddc;
GtkWidget *date_box;
@@ -130,11 +130,11 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
GtkBuilder *builder;
gboolean retval;
- if (!message || !label_message || !ts)
+ if (!message || !label_message || !t)
return FALSE;
ddc = g_new0 (DialogDateClose, 1);
- ddc->ts = ts;
+ ddc->t = *t;
builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "dialog-date-close.glade", "date_close_dialog");
@@ -146,7 +146,7 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
date_box = GTK_WIDGET(gtk_builder_get_object (builder, "date_box"));
ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
- gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), ts->tv_sec);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), *t);
if (parent)
gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
@@ -203,7 +203,7 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
GList * acct_types, GList * acct_commodities,
QofBook *book, GncBillTerm *terms,
/* Returned Data... */
- Timespec *ddue, Timespec *post,
+ time64 *ddue, time64 *post,
char **memo, Account **acct, gboolean *answer)
{
DialogDateClose *ddc;
@@ -220,8 +220,8 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
return FALSE;
ddc = g_new0 (DialogDateClose, 1);
- ddc->ts = ddue;
- ddc->ts2 = post;
+ ddc->t = *ddue;
+ ddc->t2 = *post;
ddc->book = book;
ddc->acct_types = acct_types;
ddc->acct_commodities = acct_commodities;
@@ -278,7 +278,7 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
/* Set the post date widget */
- gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->post_date), post->tv_sec);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->post_date), *post);
/* Deal with the terms handling of the due date */
if (terms)
@@ -289,7 +289,7 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
post_date_changed_cb (GNC_DATE_EDIT (ddc->post_date), ddc);
}
else
- gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), ddue->tv_sec);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), *ddue);
/* Setup the account widget */
fill_in_acct_info (ddc, set_default_acct);
@@ -329,7 +329,7 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
gboolean ok_is_default,
GList * acct_types, QofBook *book,
/* Returned Data... */
- Timespec *date, Account **acct)
+ time64 *date, Account **acct)
{
DialogDateClose *ddc;
GtkLabel *label;
@@ -343,7 +343,7 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
return FALSE;
ddc = g_new0 (DialogDateClose, 1);
- ddc->ts = date;
+ ddc->t = *date;
ddc->book = book;
ddc->acct_types = acct_types;
ddc->acct = *acct;
@@ -378,7 +378,7 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
gtk_label_set_text (label, acct_label_message);
/* Set the date widget */
- gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), date->tv_sec);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), *date);
/* Setup the account widget */
fill_in_acct_info (ddc, FALSE);
diff --git a/gnucash/gnome/dialog-date-close.h b/gnucash/gnome/dialog-date-close.h
index 03d33f0..757113e 100644
--- a/gnucash/gnome/dialog-date-close.h
+++ b/gnucash/gnome/dialog-date-close.h
@@ -33,7 +33,7 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
const char *label_message,
gboolean ok_is_default,
/* Returned data ... */
- Timespec *date);
+ time64 *date);
/*
@@ -55,7 +55,7 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
GList * acct_types, GList * acct_commodities,
QofBook *book, GncBillTerm *terms,
/* Returned Data... */
- Timespec *ddue, Timespec *post,
+ time64 *ddue, time64 *post,
char **memo, Account **acct, gboolean *answer);
@@ -66,6 +66,6 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
gboolean ok_is_default,
GList * acct_types, QofBook *book,
/* Returned Data... */
- Timespec *date, Account **acct);
+ time64 *date, Account **acct);
#endif /* _DIALOG_DATE_CLOSE_H */
diff --git a/gnucash/gnome/dialog-invoice.c b/gnucash/gnome/dialog-invoice.c
index f1cb06a..8c2ece9 100644
--- a/gnucash/gnome/dialog-invoice.c
+++ b/gnucash/gnome/dialog-invoice.c
@@ -686,7 +686,7 @@ gnc_invoice_window_printCB (GtkWindow* parent, gpointer data)
static gboolean
gnc_dialog_post_invoice(InvoiceWindow *iw, char *message,
- Timespec *ddue, Timespec *postdate,
+ time64 *ddue, time64 *postdate,
char **memo, Account **acc, gboolean *accumulate)
{
GncInvoice *invoice;
@@ -719,17 +719,17 @@ gnc_dialog_post_invoice(InvoiceWindow *iw, char *message,
* For Vendor Bills and Employee Vouchers
* that would be the date of the most recent invoice entry.
* Failing that, today is used as a fallback */
- *postdate = timespec_now();
+ *postdate = gnc_time(NULL);
if (entries && ((gncInvoiceGetOwnerType (invoice) == GNC_OWNER_VENDOR) ||
(gncInvoiceGetOwnerType (invoice) == GNC_OWNER_EMPLOYEE)))
{
- postdate->tv_sec = gncEntryGetDate ((GncEntry*)entries->data);
+ *postdate = gncEntryGetDate ((GncEntry*)entries->data);
for (entries_iter = entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter))
{
time64 entrydate = gncEntryGetDate ((GncEntry*)entries_iter->data);
- if (entrydate > postdate->tv_sec)
- postdate->tv_sec = entrydate;
+ if (entrydate > *postdate)
+ *postdate = entrydate;
}
}
@@ -758,8 +758,8 @@ gnc_dialog_post_invoice(InvoiceWindow *iw, char *message,
struct post_invoice_params
{
- Timespec ddue; /* Due date */
- Timespec postdate; /* Date posted */
+ time64 ddue; /* Due date */
+ time64 postdate; /* Date posted */
char *memo; /* Memo for posting transaction */
Account *acc; /* Account to post to */
gboolean accumulate; /* Whether to accumulate splits */
@@ -772,7 +772,7 @@ gnc_invoice_post(InvoiceWindow *iw, struct post_invoice_params *post_params)
GncInvoice *invoice;
char *message, *memo;
Account *acc = NULL;
- Timespec ddue, postdate;
+ time64 ddue, postdate;
gboolean accumulate;
QofInstance *owner_inst;
const char *text;
@@ -873,7 +873,7 @@ gnc_invoice_post(InvoiceWindow *iw, struct post_invoice_params *post_params)
xfer = gnc_xfer_dialog (iw_get_window(iw), acc);
gnc_xfer_dialog_is_exchange_dialog(xfer, &exch_rate);
gnc_xfer_dialog_select_to_currency(xfer, account_currency);
- gnc_xfer_dialog_set_date (xfer, timespecToTime64 (postdate));
+ gnc_xfer_dialog_set_date (xfer, postdate);
/* Even if amount is 0 ask for an exchange rate. It's required
* for the transaction generating code. Use an amount of 1 in
* that case as the dialog won't allow to specify an exchange
@@ -913,7 +913,7 @@ gnc_invoice_post(InvoiceWindow *iw, struct post_invoice_params *post_params)
gnc_price_begin_edit (convprice);
gnc_price_set_commodity (convprice, account_currency);
gnc_price_set_currency (convprice, gncInvoiceGetCurrency (invoice));
- gnc_price_set_time (convprice, postdate);
+ gnc_price_set_time64 (convprice, postdate);
gnc_price_set_source (convprice, PRICE_SOURCE_TEMP);
gnc_price_set_typestr (convprice, PRICE_TYPE_LAST);
gnc_price_set_value (convprice, exch_rate);
@@ -948,7 +948,7 @@ gnc_invoice_post(InvoiceWindow *iw, struct post_invoice_params *post_params)
else
auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
- gncInvoicePostToAccount (invoice, acc, postdate.tv_sec, ddue.tv_sec, memo, accumulate, auto_pay);
+ gncInvoicePostToAccount (invoice, acc, postdate, ddue, memo, accumulate, auto_pay);
cleanup:
gncInvoiceCommitEdit (invoice);
diff --git a/gnucash/gnome/dialog-order.c b/gnucash/gnome/dialog-order.c
index 1cb7cb9..0c9bfbe 100644
--- a/gnucash/gnome/dialog-order.c
+++ b/gnucash/gnome/dialog-order.c
@@ -261,7 +261,7 @@ gnc_order_window_close_order_cb (GtkWidget *widget, gpointer data)
GList *entries;
char *message, *label;
gboolean non_inv = FALSE;
- Timespec ts = {gnc_time (NULL), 0};
+ time64 t = gnc_time (NULL);
/* Make sure the order is ok */
if (!gnc_order_window_verify_ok (ow))
@@ -310,10 +310,10 @@ gnc_order_window_close_order_cb (GtkWidget *widget, gpointer data)
message = _("Do you really want to close the order?");
label = _("Close Date");
- if (!gnc_dialog_date_close_parented (ow->dialog, message, label, TRUE, &ts))
+ if (!gnc_dialog_date_close_parented (ow->dialog, message, label, TRUE, &t))
return;
- gncOrderSetDateClosed (order, ts.tv_nsec);
+ gncOrderSetDateClosed (order, t);
/* save it off */
gnc_order_window_ok_save (ow);
diff --git a/gnucash/gnome/dialog-payment.c b/gnucash/gnome/dialog-payment.c
index ee6d20c..39465a8 100644
--- a/gnucash/gnome/dialog-payment.c
+++ b/gnucash/gnome/dialog-payment.c
@@ -921,7 +921,7 @@ gnc_payment_ok_cb (G_GNUC_UNUSED GtkWidget *widget, gpointer data)
{
const char *memo, *num;
GDate date;
- Timespec ts;
+ time64 t;
gnc_numeric exch = gnc_numeric_create(1, 1); //default to "one to one" rate
GList *selected_lots = NULL;
GtkTreeSelection *selection;
@@ -932,7 +932,7 @@ gnc_payment_ok_cb (G_GNUC_UNUSED GtkWidget *widget, gpointer data)
num = gtk_entry_get_text (GTK_ENTRY (pw->num_entry));
g_date_clear (&date, 1);
gnc_date_edit_get_gdate (GNC_DATE_EDIT (pw->date_edit), &date);
- ts = gdate_to_timespec (date);
+ t = gdate_to_time64 (date);
/* Obtain the list of selected lots (documents/payments) from the dialog */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(pw->docs_list_tree_view));
@@ -974,8 +974,8 @@ gnc_payment_ok_cb (G_GNUC_UNUSED GtkWidget *widget, gpointer data)
auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
gncOwnerApplyPayment (&pw->owner, &(pw->tx_info->txn), selected_lots,
- pw->post_acct, pw->xfer_acct, pw->amount_tot, exch,
- ts, memo, num, auto_pay);
+ pw->post_acct, pw->xfer_acct, pw->amount_tot,
+ exch, t, memo, num, auto_pay);
}
gnc_resume_gui_refresh ();
diff --git a/gnucash/gnome/dialog-price-edit-db.c b/gnucash/gnome/dialog-price-edit-db.c
index 4fdcc09..99835f9 100644
--- a/gnucash/gnome/dialog-price-edit-db.c
+++ b/gnucash/gnome/dialog-price-edit-db.c
@@ -223,7 +223,7 @@ gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
/** Enumeration for the price delete list-store */
enum GncPriceColumn {PRICED_FULL_NAME, PRICED_COMM, PRICED_DATE, PRICED_COUNT};
-static Timespec
+static time64
gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
{
GtkTreeModel *model = gtk_tree_view_get_model (view);
@@ -234,8 +234,7 @@ gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
GList *commodity_list = NULL;
GtkTreeIter iter;
- Timespec oldest_ts = timespec_now ();
- oldest_ts.tv_nsec = 0;
+ time64 oldest = gnc_time (NULL);
namespace_list = g_list_first (namespace_list);
while (namespace_list != NULL)
@@ -256,14 +255,13 @@ gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
PriceList *list = gnc_pricedb_get_prices (pdb, tmp_commodity, NULL);
GList *node = g_list_last (list);
GNCPrice *price = (GNCPrice*)node->data;
- Timespec price_ts = gnc_price_get_time (price);
+ time64 price_time = gnc_price_get_time64 (price);
const gchar *name_str = gnc_commodity_get_printname (tmp_commodity);
gchar *date_str, *num_str;
+ if (oldest > price_time)
+ oldest = price_time;
- if (timespec_cmp(&oldest_ts, &price_ts) >= 0)
- oldest_ts.tv_sec = price_ts.tv_sec;
-
- date_str = g_strdup (gnc_print_date (price_ts));
+ date_str = qof_print_date (price_time);
num_str = g_strdup_printf ("%d", num);
gtk_list_store_append (GTK_LIST_STORE(model), &iter);
@@ -282,7 +280,7 @@ gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
g_list_free (commodity_list);
g_list_free (namespace_list);
- return oldest_ts;
+ return oldest;
}
static GList *
@@ -371,15 +369,16 @@ selection_changed_cb (GtkTreeSelection *selection, gpointer data)
static GDate
get_fiscal_end_date (void)
{
- Timespec ts_end;
- GDate f_end;
-
- timespecFromTime64 (&ts_end, gnc_accounting_period_fiscal_end());
- f_end = timespec_to_gdate (ts_end);
+ time64 end;
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset (datebuff, 0, sizeof(datebuff));
+ end = gnc_accounting_period_fiscal_end();
+ qof_print_date_buff(datebuff, sizeof(datebuff),
+ gnc_accounting_period_fiscal_end());
+ PINFO("Fiscal end date is %s", datebuff);
- PINFO("Fiscal end date is %s", qof_print_date (gnc_accounting_period_fiscal_end()));
+ return time64_to_gdate (end);
- return f_end;
}
void
@@ -393,7 +392,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
GtkTreeSelection *selection;
GtkTreeViewColumn *tree_column;
GtkCellRenderer *cr;
- Timespec first_ts;
+ time64 first;
gint result;
ENTER(" ");
@@ -430,7 +429,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
gtk_cell_renderer_set_alignment (cr, 0.5, 0.5);
// Load the view and get the earliest date
- first_ts = gnc_prices_dialog_load_view (pdb_dialog->remove_view, pdb_dialog->price_db);
+ first = gnc_prices_dialog_load_view (pdb_dialog->remove_view, pdb_dialog->price_db);
gtk_tree_selection_select_all (selection);
g_signal_connect (selection, "changed", G_CALLBACK(selection_changed_cb), pdb_dialog);
@@ -455,7 +454,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
// Are you sure you want to delete the entries and we have commodities
if ((g_list_length (comm_list) != 0) && (gnc_verify_dialog (GTK_WINDOW (pdb_dialog->remove_dialog), FALSE, fmt, NULL)))
{
- Timespec last_ts;
+ time64 last;
GDate fiscal_end_date = get_fiscal_end_date ();
PriceRemoveSourceFlags source = PRICE_REMOVE_SOURCE_FQ;
PriceRemoveKeepOptions keep = PRICE_REMOVE_KEEP_NONE;
@@ -466,8 +465,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
gtk_tree_view_set_model (GTK_TREE_VIEW(pdb_dialog->price_tree), NULL);
DEBUG("deleting prices");
- last_ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
- last_ts.tv_nsec = 0;
+ last = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_week"));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
@@ -486,23 +484,29 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
keep = PRICE_REMOVE_KEEP_SCALED;
if (keep != PRICE_REMOVE_KEEP_SCALED)
- gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date,
- last_ts, pdb_dialog->remove_source, keep);
+ gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list,
+ &fiscal_end_date,
+ last, pdb_dialog->remove_source,
+ keep);
else
{
- Timespec tmp_ts;
- GDate tmp_date = timespec_to_gdate (last_ts);
+ time64 tmp;
+ GDate tmp_date = time64_to_gdate (last);
g_date_subtract_months (&tmp_date, 6);
- tmp_ts = gdate_to_timespec (tmp_date);
+ tmp = gdate_to_time64 (tmp_date);
- gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date, tmp_ts,
- pdb_dialog->remove_source, PRICE_REMOVE_KEEP_LAST_WEEKLY);
+ gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list,
+ &fiscal_end_date, tmp,
+ pdb_dialog->remove_source,
+ PRICE_REMOVE_KEEP_LAST_WEEKLY);
g_date_subtract_months (&tmp_date, 6);
- tmp_ts = gdate_to_timespec (tmp_date);
+ tmp = gdate_to_time64 (tmp_date);
- gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date, tmp_ts,
- pdb_dialog->remove_source, PRICE_REMOVE_KEEP_LAST_MONTHLY);
+ gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list,
+ &fiscal_end_date, tmp,
+ pdb_dialog->remove_source,
+ PRICE_REMOVE_KEEP_LAST_MONTHLY);
}
// reconnect the model to the price treeview
gtk_tree_view_set_model (GTK_TREE_VIEW(pdb_dialog->price_tree), model);
diff --git a/gnucash/gnome/dialog-price-editor.c b/gnucash/gnome/dialog-price-editor.c
index 5b474c6..e6ccfa1 100644
--- a/gnucash/gnome/dialog-price-editor.c
+++ b/gnucash/gnome/dialog-price-editor.c
@@ -143,7 +143,7 @@ price_to_gui (PriceEditDialog *pedit_dialog)
const char *source;
const char *type;
gnc_numeric value;
- Timespec date;
+ time64 date;
if (pedit_dialog->price)
{
@@ -160,7 +160,7 @@ price_to_gui (PriceEditDialog *pedit_dialog)
name_space, fullname);
currency = gnc_price_get_currency (pedit_dialog->price);
- date = gnc_price_get_time (pedit_dialog->price);
+ date = gnc_price_get_time64 (pedit_dialog->price);
source = gnc_price_get_source_string (pedit_dialog->price);
type = gnc_price_get_typestr (pedit_dialog->price);
value = gnc_price_get_value (pedit_dialog->price);
@@ -168,8 +168,7 @@ price_to_gui (PriceEditDialog *pedit_dialog)
else
{
currency = gnc_default_currency ();
- date.tv_sec = gnc_time (NULL);
- date.tv_nsec = 0;
+ date = gnc_time (NULL);
source = "user:price-editor"; //Sync with source_names in gnc-pricedb.c
type = "";
value = gnc_numeric_zero ();
@@ -182,7 +181,7 @@ price_to_gui (PriceEditDialog *pedit_dialog)
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency);
}
- gnc_date_edit_set_time (GNC_DATE_EDIT (pedit_dialog->date_edit), date.tv_sec);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (pedit_dialog->date_edit), date);
gtk_entry_set_text (GTK_ENTRY (pedit_dialog->source_entry), source);
@@ -203,7 +202,7 @@ gui_to_price (PriceEditDialog *pedit_dialog)
const char *source;
const char *type;
gnc_numeric value;
- Timespec date;
+ time64 date;
name_space = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbwe);
fullname = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(pedit_dialog->commodity_cbwe)))));
@@ -217,8 +216,7 @@ gui_to_price (PriceEditDialog *pedit_dialog)
if (!currency)
return _("You must select a Currency.");
- date.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (pedit_dialog->date_edit));
- date.tv_nsec = 0;
+ date = gnc_date_edit_get_date (GNC_DATE_EDIT (pedit_dialog->date_edit));
source = gtk_entry_get_text (GTK_ENTRY (pedit_dialog->source_entry));
@@ -236,7 +234,7 @@ gui_to_price (PriceEditDialog *pedit_dialog)
gnc_price_begin_edit (pedit_dialog->price);
gnc_price_set_commodity (pedit_dialog->price, commodity);
gnc_price_set_currency (pedit_dialog->price, currency);
- gnc_price_set_time (pedit_dialog->price, date);
+ gnc_price_set_time64 (pedit_dialog->price, date);
gnc_price_set_source_string (pedit_dialog->price, source);
gnc_price_set_typestr (pedit_dialog->price, type);
gnc_price_set_value (pedit_dialog->price, value);
diff --git a/gnucash/gnome/dialog-trans-assoc.c b/gnucash/gnome/dialog-trans-assoc.c
index 9429a32..0c1eab8 100644
--- a/gnucash/gnome/dialog-trans-assoc.c
+++ b/gnucash/gnome/dialog-trans-assoc.c
@@ -336,11 +336,12 @@ get_trans_info (AssocDialog *assoc_dialog)
{
gchar *uri_u;
gboolean rel = FALSE;
- Timespec ts = {xaccTransRetDatePosted (trans),0};
-
- if (ts.tv_sec == 0)
- ts.tv_sec = gnc_time (NULL);
-
+ time64 t = xaccTransRetDatePosted (trans);
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset (datebuff, 0, sizeof(datebuff));
+ if (t == 0)
+ t = gnc_time (NULL);
+ qof_print_date_buff (datebuff, sizeof(datebuff), t);
gtk_list_store_append (GTK_LIST_STORE(model), &iter);
if (g_str_has_prefix (uri,"file:/") && !g_str_has_prefix (uri,"file://")) // path is relative
@@ -349,7 +350,7 @@ get_trans_info (AssocDialog *assoc_dialog)
uri_u = convert_uri_to_unescaped (assoc_dialog, uri);
gtk_list_store_set (GTK_LIST_STORE(model), &iter,
- DATE_TRANS, gnc_print_date (ts),
+ DATE_TRANS, datebuff,
DESC_TRANS, xaccTransGetDescription (trans),
URI_U, uri_u, AVAILABLE, _("Unknown"),
URI_SPLIT, split, URI, uri,
diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index daa0aa7..d148570 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -1327,7 +1327,7 @@ gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
typedef struct
{
GNCPriceDB *db;
- Timespec cutoff;
+ time64 cutoff;
gboolean delete_fq;
gboolean delete_user;
gboolean delete_app;
@@ -1365,7 +1365,7 @@ check_one_price_date (GNCPrice *price, gpointer user_data)
gnc_timespec_to_iso8601_buff(pt , buf);
DEBUG("checking date %s", buf);
}
- if (timespec_cmp (&pt, &data->cutoff) < 0)
+ if (pt.tv_sec < data->cutoff)
{
data->list = g_slist_prepend(data->list, price);
DEBUG("will delete");
@@ -1625,12 +1625,14 @@ gnc_pricedb_process_removal_list (GNCPriceDB *db, GDate *fiscal_end_date,
gboolean
gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list,
- GDate *fiscal_end_date, Timespec cutoff,
+ GDate *fiscal_end_date, time64 cutoff,
PriceRemoveSourceFlags source,
PriceRemoveKeepOptions keep)
{
remove_info data;
GList *node;
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset (datebuff, sizeof(datebuff), 0);
data.db = db;
data.cutoff = cutoff;
@@ -1663,7 +1665,9 @@ gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list,
LEAVE("Empty price list");
return FALSE;
}
- DEBUG("Number of Prices in list is %d, Cutoff date is %s", g_slist_length (data.list), gnc_print_date (cutoff));
+ qof_print_date_buff (datebuff, sizeof(datebuff), cutoff);
+ DEBUG("Number of Prices in list is %d, Cutoff date is %s",
+ g_slist_length (data.list), datebuff);
// Check for a valid fiscal end of year date
if (fiscal_end_date == NULL)
diff --git a/libgnucash/engine/gnc-pricedb.h b/libgnucash/engine/gnc-pricedb.h
index 3f0b65e..61ed2c9 100644
--- a/libgnucash/engine/gnc-pricedb.h
+++ b/libgnucash/engine/gnc-pricedb.h
@@ -406,7 +406,7 @@ typedef enum
* @return True if there were prices to process, False if not.
*/
gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, GList *comm_list,
- GDate *fiscal_end_date, Timespec cutoff,
+ GDate *fiscal_end_date, time64 cutoff,
PriceRemoveSourceFlags source,
PriceRemoveKeepOptions keep);
diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c
index 60f643a..40d87be 100644
--- a/libgnucash/engine/gncInvoice.c
+++ b/libgnucash/engine/gncInvoice.c
@@ -1935,7 +1935,6 @@ gncInvoiceApplyPayment (const GncInvoice *invoice, Transaction *txn,
GNCLot *payment_lot;
GList *selected_lots = NULL;
const GncOwner *owner;
- Timespec ts_pass = {date,0};
/* Verify our arguments */
if (!invoice || !gncInvoiceIsPosted (invoice) || !xfer_acc) return;
@@ -1944,8 +1943,9 @@ gncInvoiceApplyPayment (const GncInvoice *invoice, Transaction *txn,
g_return_if_fail (owner->owner.undefined);
/* Create a lot for this payment */
- payment_lot = gncOwnerCreatePaymentLot (owner, &txn, invoice->posted_acc, xfer_acc,
- amount, exch, ts_pass, memo, num);
+ payment_lot = gncOwnerCreatePaymentLot (owner, &txn, invoice->posted_acc,
+ xfer_acc, amount, exch,
+ date, memo, num);
/* Select the invoice as only payment candidate */
selected_lots = g_list_prepend (selected_lots, invoice->posted_lot);
diff --git a/libgnucash/engine/gncOwner.c b/libgnucash/engine/gncOwner.c
index 56b6036..6011936 100644
--- a/libgnucash/engine/gncOwner.c
+++ b/libgnucash/engine/gncOwner.c
@@ -725,7 +725,7 @@ gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB)
GNCLot *
gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn,
Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, Timespec date,
+ gnc_numeric amount, gnc_numeric exch, time64 date,
const char *memo, const char *num)
{
QofBook *book;
@@ -814,7 +814,7 @@ gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn,
/* set per book option */
xaccTransSetCurrency (txn, commodity);
xaccTransSetDateEnteredSecs (txn, gnc_time (NULL));
- xaccTransSetDatePostedSecs (txn, date.tv_sec);
+ xaccTransSetDatePostedSecs (txn, date);
/* The split for the transfer account */
@@ -1378,7 +1378,7 @@ void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots)
void
gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lots,
Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, Timespec date,
+ gnc_numeric amount, gnc_numeric exch, time64 date,
const char *memo, const char *num, gboolean auto_pay)
{
GNCLot *payment_lot = NULL;
diff --git a/libgnucash/engine/gncOwner.h b/libgnucash/engine/gncOwner.h
index 1542f98..79bbaba 100644
--- a/libgnucash/engine/gncOwner.h
+++ b/libgnucash/engine/gncOwner.h
@@ -216,7 +216,7 @@ gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType
GNCLot *
gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn,
Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, Timespec date,
+ gnc_numeric amount, gnc_numeric exch, time64 date,
const char *memo, const char *num);
/**
@@ -269,7 +269,7 @@ void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots);
void
gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lots,
Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, Timespec date,
+ gnc_numeric amount, gnc_numeric exch, time64 date,
const char *memo, const char *num, gboolean auto_pay);
/** Helper function to find a split in lot that best offsets target_value
diff --git a/libgnucash/engine/test/utest-gnc-pricedb.c b/libgnucash/engine/test/utest-gnc-pricedb.c
index 345a34d..841260a 100644
--- a/libgnucash/engine/test/utest-gnc-pricedb.c
+++ b/libgnucash/engine/test/utest-gnc-pricedb.c
@@ -789,9 +789,9 @@ static void test_gnc_pricedb_remove_old_prices (PriceDBFixture *fixture, gconstp
PRICE_REMOVE_SOURCE_USER |
PRICE_REMOVE_SOURCE_APP;
- Timespec t_cut = gnc_dmy2timespec(1, 1, 2008);
- Timespec t_cut1 = gnc_dmy2timespec(1, 1, 2009);
- Timespec t_cut2 = gnc_dmy2timespec(1, 1, 2010);
+ time64 t_cut = gnc_dmy2time64(1, 1, 2008);
+ time64 t_cut1 = gnc_dmy2time64(1, 1, 2009);
+ time64 t_cut2 = gnc_dmy2time64(1, 1, 2010);
GDate *fiscal_end_date = g_date_new ();
g_date_set_dmy (fiscal_end_date, 31, 12, 2017);
commit e79612035946a2b0c2d323918d3f1d63152e535b
Author: John Ralls <jralls at ceridwen.us>
Date: Tue Jul 31 11:25:45 2018 -0700
Remove Timespec from gnucash/gnome-utils.
Plus a bit of bleed into gnome because of deleted functions.
diff --git a/gnucash/gnome-utils/dialog-dup-trans.c b/gnucash/gnome-utils/dialog-dup-trans.c
index bd30860..0b5692d 100644
--- a/gnucash/gnome-utils/dialog-dup-trans.c
+++ b/gnucash/gnome-utils/dialog-dup-trans.c
@@ -282,7 +282,7 @@ gnc_dup_trans_dialog_gdate (GtkWidget * parent, GDate *gdate_p,
time64 tmp_time;
g_assert(gdate_p);
- tmp_time = timespecToTime64(gdate_to_timespec(*gdate_p));
+ tmp_time = gdate_to_time64 (*gdate_p);
return gnc_dup_trans_dialog_internal(parent, NULL, TRUE, &tmp_time, gdate_p,
num, out_num, NULL, NULL);
}
@@ -293,7 +293,7 @@ gnc_dup_date_dialog (GtkWidget * parent, const char* title, GDate *gdate_p)
time64 tmp_time;
g_assert(gdate_p);
- tmp_time = timespecToTime64(gdate_to_timespec(*gdate_p));
+ tmp_time = gdate_to_time64(*gdate_p);
return gnc_dup_trans_dialog_internal(parent, title, TRUE, &tmp_time, gdate_p,
NULL, NULL, NULL, NULL);
}
diff --git a/gnucash/gnome-utils/dialog-transfer.c b/gnucash/gnome-utils/dialog-transfer.c
index 89a4bd9..fb15697 100644
--- a/gnucash/gnome-utils/dialog-transfer.c
+++ b/gnucash/gnome-utils/dialog-transfer.c
@@ -230,7 +230,7 @@ typedef struct
GNCPriceDB *pricedb;
gnc_commodity *from;
gnc_commodity *to;
- Timespec ts;
+ time64 time;
gboolean reverse;
} PriceReq;
@@ -243,7 +243,7 @@ price_request_from_xferData(PriceReq *pr, XferDialog *xd)
pr->pricedb = xd->pricedb;
pr->from = xd->from_commodity;
pr->to = xd->to_commodity;
- pr->ts = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (xd->date_entry));
+ pr->time = gnc_date_edit_get_date (GNC_DATE_EDIT (xd->date_entry));
pr->reverse = FALSE;
}
@@ -261,12 +261,12 @@ lookup_price(PriceReq *pr, PriceDate pd)
{
default:
case SAME_DAY:
- prc = gnc_pricedb_lookup_day (pr->pricedb, pr->from,
- pr->to, pr->ts);
+ prc = gnc_pricedb_lookup_day_t64 (pr->pricedb, pr->from,
+ pr->to, pr->time);
break;
case NEAREST:
- prc = gnc_pricedb_lookup_nearest_in_time (pr->pricedb, pr->from,
- pr->to, pr->ts);
+ prc = gnc_pricedb_lookup_nearest_in_time64 (pr->pricedb, pr->from,
+ pr->to, pr->time);
break;
case LATEST:
prc = gnc_pricedb_lookup_latest (pr->pricedb, pr->from, pr->to);
@@ -1499,7 +1499,7 @@ check_edit(XferDialog *xferData)
}
static void
-create_transaction(XferDialog *xferData, Timespec *ts,
+create_transaction(XferDialog *xferData, time64 time,
Account *from_account, Account* to_account,
gnc_numeric amount, gnc_numeric to_amount)
{
@@ -1513,7 +1513,7 @@ create_transaction(XferDialog *xferData, Timespec *ts,
xaccTransBeginEdit(trans);
xaccTransSetCurrency(trans, xferData->from_commodity);
- xaccTransSetDatePostedSecs(trans, ts->tv_sec);
+ xaccTransSetDatePostedSecs(trans, time);
/* Trans-Num or Split-Action set with gnc_set_num_action below per book
* option */
@@ -1601,7 +1601,7 @@ update_price(XferDialog *xferData, PriceReq *pr)
return;
}
gnc_price_begin_edit (pr->price);
- gnc_price_set_time (pr->price, pr->ts);
+ gnc_price_set_time64 (pr->price, pr->time);
gnc_price_set_typestr(pr->price, xferData->price_type);
gnc_price_set_value (pr->price, value);
gnc_price_commit_edit (pr->price);
@@ -1613,7 +1613,7 @@ update_price(XferDialog *xferData, PriceReq *pr)
}
static void
-new_price(XferDialog *xferData, Timespec ts)
+new_price(XferDialog *xferData, time64 time)
{
GNCPrice *price = NULL;
gnc_commodity *from = xferData->from_commodity;
@@ -1637,7 +1637,7 @@ new_price(XferDialog *xferData, Timespec ts)
gnc_price_begin_edit (price);
gnc_price_set_commodity (price, from);
gnc_price_set_currency (price, to);
- gnc_price_set_time (price, ts);
+ gnc_price_set_time64 (price, time);
gnc_price_set_source (price, xferData->price_source);
gnc_price_set_typestr (price, xferData->price_type);
gnc_price_set_value (price, value);
@@ -1649,7 +1649,7 @@ new_price(XferDialog *xferData, Timespec ts)
}
static void
-create_price(XferDialog *xferData, Timespec ts)
+create_price(XferDialog *xferData, time64 time)
{
PriceReq pr;
@@ -1664,7 +1664,7 @@ create_price(XferDialog *xferData, Timespec ts)
update_price(xferData, &pr);
return;
}
- new_price (xferData, ts);
+ new_price (xferData, time);
}
void
@@ -1674,7 +1674,7 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
Account *to_account;
Account *from_account;
gnc_numeric amount, to_amount;
- Timespec ts;
+ time64 time;
GDate date;
g_return_if_fail (xferData != NULL);
@@ -1718,7 +1718,7 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
}
g_date_clear (&date, 1);
gnc_date_edit_get_gdate (GNC_DATE_EDIT (xferData->date_entry), &date);
- ts = gdate_to_timespec (date);
+ time = gdate_to_time64 (date);
if (!gnc_commodity_equiv(xferData->from_commodity, xferData->to_commodity))
{
@@ -1748,12 +1748,12 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
*(xferData->exch_rate) = gnc_numeric_abs(price_value);
}
else
- create_transaction (xferData, &ts, from_account, to_account,
+ create_transaction (xferData, time, from_account, to_account,
amount, to_amount);
/* try to save this to the pricedb */
if (xferData->pricedb && !gnc_commodity_equal (xferData->from_commodity,
xferData->to_commodity))
- create_price(xferData, ts);
+ create_price(xferData, time);
/* Refresh everything */
gnc_resume_gui_refresh ();
diff --git a/gnucash/gnome-utils/gnc-date-edit.c b/gnucash/gnome-utils/gnc-date-edit.c
index c2e93a9..b729c33 100644
--- a/gnucash/gnome-utils/gnc-date-edit.c
+++ b/gnucash/gnome-utils/gnc-date-edit.c
@@ -184,13 +184,13 @@ gnc_date_edit_popdown(GNCDateEdit *gde)
static void
day_selected (GtkCalendar *calendar, GNCDateEdit *gde)
{
- Timespec t;
+ time64 t;
guint year, month, day;
gde->in_selected_handler = TRUE;
gtk_calendar_get_date (calendar, &year, &month, &day);
/* GtkCalendar returns a 0-based month */
- t = gnc_dmy2timespec (day, month + 1, year);
- gnc_date_edit_set_time_ts (gde, t);
+ t = gnc_dmy2time64 (day, month + 1, year);
+ gnc_date_edit_set_time (gde, t);
gde->in_selected_handler = FALSE;
}
@@ -809,12 +809,6 @@ gnc_date_edit_set_gdate (GNCDateEdit *gde, const GDate *date)
gnc_date_edit_set_time(gde, t);
}
-void
-gnc_date_edit_set_time_ts (GNCDateEdit *gde, Timespec the_time)
-{
- gnc_date_edit_set_time (gde, the_time.tv_sec);
-}
-
/**
* gnc_date_edit_set_popup_range:
* @gde: The GNCDateEdit widget
@@ -1033,13 +1027,6 @@ gnc_date_edit_new (time64 the_time, int show_time, int use_24_format)
| (use_24_format ? GNC_DATE_EDIT_24_HR : 0)));
}
-GtkWidget *
-gnc_date_edit_new_ts (Timespec the_time, int show_time, int use_24_format)
-{
- return gnc_date_edit_new (the_time.tv_sec, show_time, use_24_format);
-}
-
-
/*
* Create a new GncDateEdit widget from a glade file. The widget
* generated is set to today's date, and will not show a time as part
@@ -1193,16 +1180,6 @@ gnc_date_edit_get_gdate (GNCDateEdit *gde, GDate *date)
gnc_gdate_set_time64 (date, t);
}
-Timespec
-gnc_date_edit_get_date_ts (GNCDateEdit *gde)
-{
- Timespec ts = { 0, 0 };
-
- ts.tv_sec = gnc_date_edit_get_date (gde);
-
- return ts;
-}
-
/**
* gnc_date_edit_get_date_end:
* @gde: The GNCDateEdit widget
@@ -1224,16 +1201,6 @@ gnc_date_edit_get_date_end (GNCDateEdit *gde)
return gnc_mktime (&tm);
}
-Timespec
-gnc_date_edit_get_date_end_ts (GNCDateEdit *gde)
-{
- Timespec ts = { 0, 0 };
-
- ts.tv_sec = gnc_date_edit_get_date_end (gde);
-
- return ts;
-}
-
/**
* gnc_date_edit_set_flags:
* @gde: The date editor widget whose flags should be changed.
diff --git a/gnucash/gnome-utils/gnc-date-edit.h b/gnucash/gnome-utils/gnc-date-edit.h
index f6b7472..68f5478 100644
--- a/gnucash/gnome-utils/gnc-date-edit.h
+++ b/gnucash/gnome-utils/gnc-date-edit.h
@@ -93,8 +93,6 @@ GType gnc_date_edit_get_type (void);
GtkWidget *gnc_date_edit_new (time64 the_time,
int show_time, int use_24_format);
-GtkWidget *gnc_date_edit_new_ts (Timespec the_time,
- int show_time, int use_24_format);
/**
* Create a new GncDateEdit widget from a glade file. The widget
@@ -121,16 +119,13 @@ GtkWidget *gnc_date_edit_new_flags (time64 the_time,
void gnc_date_edit_set_gdate (GNCDateEdit *gde, const GDate *date);
void gnc_date_edit_set_time (GNCDateEdit *gde, time64 the_time);
-void gnc_date_edit_set_time_ts (GNCDateEdit *gde, Timespec the_time);
void gnc_date_edit_set_popup_range (GNCDateEdit *gde,
- int low_hour, int up_hour);
+ int low_hour, int up_hour);
void gnc_date_edit_get_gdate (GNCDateEdit *gde, GDate *date);
-time64 gnc_date_edit_get_date (GNCDateEdit *gde);
-Timespec gnc_date_edit_get_date_ts (GNCDateEdit *gde);
-time64 gnc_date_edit_get_date_end (GNCDateEdit *gde);
-Timespec gnc_date_edit_get_date_end_ts (GNCDateEdit *gde);
+time64 gnc_date_edit_get_date (GNCDateEdit *gde);
+time64 gnc_date_edit_get_date_end (GNCDateEdit *gde);
void gnc_date_edit_set_flags (GNCDateEdit *gde,
GNCDateEditFlags flags);
diff --git a/gnucash/gnome-utils/gnc-tree-control-split-reg.c b/gnucash/gnome-utils/gnc-tree-control-split-reg.c
index 3c68ddd..f366e82 100644
--- a/gnucash/gnome-utils/gnc-tree-control-split-reg.c
+++ b/gnucash/gnome-utils/gnc-tree-control-split-reg.c
@@ -1537,15 +1537,15 @@ static gboolean gtcsr_move_current_entry_updown(GncTreeViewSplitReg *view,
}
/* Special treatment if the equality doesn't hold if we access the
- dates as timespec. See the comment in gncEntrySetDateGDate() for the
- reason: Some code used the timespec at noon for the EntryDate, other
- code used the timespec at the start of day. */
+ dates as time64. See the comment in gncEntrySetDateGDate() for the
+ reason: Some code used the time64 at noon for the EntryDate, other
+ code used the time64 at the start of day. */
time1 = xaccTransRetDatePosted(current_trans);
time2 = xaccTransRetDatePosted(target_trans);
if (really_do_it && time1 != time2)
{
- /* Timespecs are not equal, even though the GDates were equal? Then
- we set the GDates again. This will force the timespecs to be equal
+ /* Times are not equal, even though the GDates were equal? Then
+ we set the GDates again. This will force the times to be equal
as well. */
xaccTransSetDatePostedGDate(current_trans, d1);
xaccTransSetDatePostedGDate(target_trans, d2);
diff --git a/gnucash/gnome-utils/gnc-tree-model-price.c b/gnucash/gnome-utils/gnc-tree-model-price.c
index eea39aa..2192806 100644
--- a/gnucash/gnome-utils/gnc-tree-model-price.c
+++ b/gnucash/gnome-utils/gnc-tree-model-price.c
@@ -679,6 +679,8 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
gnc_commodity_namespace *name_space;
gnc_commodity *commodity;
GNCPrice *price;
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset (datebuff, 0, sizeof(datebuff));
g_return_if_fail (GNC_IS_TREE_MODEL_PRICE (model));
g_return_if_fail (iter != NULL);
@@ -767,8 +769,10 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
g_value_set_string (value, gnc_commodity_get_printname (commodity));
break;
case GNC_TREE_MODEL_PRICE_COL_DATE:
+ qof_print_date_buff (datebuff, sizeof(datebuff),
+ gnc_price_get_time (price));
g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, gnc_print_date (gnc_price_get_time (price)));
+ g_value_set_string (value, datebuff);
break;
case GNC_TREE_MODEL_PRICE_COL_SOURCE:
g_value_init (value, G_TYPE_STRING);
diff --git a/gnucash/gnome-utils/gnc-tree-model-split-reg.c b/gnucash/gnome-utils/gnc-tree-model-split-reg.c
index 7965bf3..e44fd76 100644
--- a/gnucash/gnome-utils/gnc-tree-model-split-reg.c
+++ b/gnucash/gnome-utils/gnc-tree-model-split-reg.c
@@ -830,10 +830,11 @@ gnc_tree_model_split_reg_get_tooltip (GncTreeModelSplitReg *model, gint position
{
GncTreeModelSplitRegPrivate *priv;
Transaction *trans;
- const gchar *date_text;
+ char date_text[MAX_DATE_LENGTH + 1];
const gchar *desc_text;
GList *node;
+ memset (date_text, 0, sizeof(date_text));
priv = model->priv;
node = g_list_nth (priv->full_tlist, position);
@@ -848,8 +849,8 @@ gnc_tree_model_split_reg_get_tooltip (GncTreeModelSplitReg *model, gint position
return g_strconcat ("Blank Transaction", NULL);
else
{
- Timespec ts = {xaccTransRetDatePosted (trans), 0};
- date_text = gnc_print_date (ts);
+ time64 t = xaccTransRetDatePosted (trans);
+ qof_print_date_buff (date_text, sizeof(date_text), t);
desc_text = xaccTransGetDescription (trans);
model->current_trans = trans;
return g_strconcat (date_text, "\n", desc_text, NULL);
diff --git a/gnucash/gnome-utils/gnc-tree-view-price.c b/gnucash/gnome-utils/gnc-tree-view-price.c
index ad95cca..f4488fb 100644
--- a/gnucash/gnome-utils/gnc-tree-view-price.c
+++ b/gnucash/gnome-utils/gnc-tree-view-price.c
@@ -219,7 +219,7 @@ static gint
default_sort (GNCPrice *price_a, GNCPrice *price_b)
{
gnc_commodity *curr_a, *curr_b;
- Timespec ts_a, ts_b;
+ time64 time_a, time_b;
gint result;
/* Primary sort (i.e. commodity name) handled by the tree structure. */
@@ -237,9 +237,9 @@ default_sort (GNCPrice *price_a, GNCPrice *price_b)
if (result != 0) return result;
/* tertiary sort: time */
- ts_a = gnc_price_get_time (price_a);
- ts_b = gnc_price_get_time (price_b);
- result = timespec_cmp (&ts_a, &ts_b);
+ time_a = gnc_price_get_time64 (price_a);
+ time_b = gnc_price_get_time64 (price_b);
+ result = time_a < time_b ? -1 : time_a > time_b ? 1 : 0;
if (result)
/* Reverse the result to present the most recent quote first. */
return -result;
@@ -270,16 +270,16 @@ sort_by_date (GtkTreeModel *f_model,
gpointer user_data)
{
GNCPrice *price_a, *price_b;
- Timespec ts_a, ts_b;
+ time64 time_a, time_b;
gboolean result;
if (!get_prices (f_model, f_iter_a, f_iter_b, &price_a, &price_b))
return sort_ns_or_cm (f_model, f_iter_a, f_iter_b);
/* sort by time first */
- ts_a = gnc_price_get_time (price_a);
- ts_b = gnc_price_get_time (price_b);
- result = timespec_cmp (&ts_a, &ts_b);
+ time_a = gnc_price_get_time64 (price_a);
+ time_b = gnc_price_get_time64 (price_b);
+ result = time_a < time_b ? -1 : time_a > time_b ? 1 : 0;
if (result)
/* Reverse the result to present the most recent quote first. */
return -result;
diff --git a/gnucash/gnome-utils/gnc-tree-view-split-reg.c b/gnucash/gnome-utils/gnc-tree-view-split-reg.c
index c10d3af..d6fc079 100644
--- a/gnucash/gnome-utils/gnc-tree-view-split-reg.c
+++ b/gnucash/gnome-utils/gnc-tree-view-split-reg.c
@@ -1394,6 +1394,7 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
gnc_numeric num = gnc_numeric_zero();
const gchar *s = "";
const gchar *row_color;
+ char datebuff[MAX_DATE_LENGTH + 1];
RowDepth depth;
gint *indices;
Account *anchor = view->priv->anchor;
@@ -1462,6 +1463,7 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
switch (viewcol) {
case COL_DATE:
/* Column is DATE */
+ memset (datebuff, 0, sizeof(datebuff));
if (is_split)
g_object_set (cell, "cell-background", "white", (gchar*)NULL);
@@ -1474,65 +1476,60 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
show_extra_dates = TRUE;
if (is_trow1) {
- Timespec ts = {xaccTransRetDatePosted (trans),0};
+ time64 t = xaccTransRetDatePosted (trans);
//If the time returned by xaccTransGetDatePostedTS is 0 then assume it
//is a new transaction and set the time to current time to show current
//date on new transactions
- if (ts.tv_sec == 0)
- ts.tv_sec = gnc_time (NULL);
- s = gnc_print_date (ts);
+ if (t == 0)
+ t = gnc_time (NULL);
+ qof_print_date_buff (datebuff, sizeof(datebuff), t);
editable = TRUE;
}
else if (is_trow2 && show_extra_dates) {
- Timespec ts = {xaccTransRetDateEntered (trans),0};
+ time64 t = xaccTransRetDateEntered (trans);
g_object_set (cell, "cell-background", YELLOWCELL, (gchar*)NULL);
//If the time returned by xaccTransGetDateEnteredTS is 0 then assume it
//is a new transaction and set the time to current time to show current
//date on new transactions
- if (ts.tv_sec == 0)
- ts.tv_sec = gnc_time (NULL);
- s = gnc_print_date (ts);
+ if (t == 0)
+ t = gnc_time (NULL);
+ qof_print_date_buff (datebuff, sizeof(datebuff), t);
editable = FALSE;
}
else if (is_split && show_extra_dates) {
- Timespec ts = {0,0};
+ time64 t = 0;
if (xaccSplitGetReconcile (split) == YREC)
{
- xaccSplitGetDateReconciledTS (split, &ts);
+ t = xaccSplitGetDateReconciled (split);
//If the time returned by xaccTransGetDateEnteredTS is 0 then assume it
//is a new transaction and set the time to current time to show current
//date on new transactions
- if (ts.tv_sec == 0)
+ if (t == 0)
{
- ts.tv_sec = gnc_time (NULL);
+ t = gnc_time (NULL);
//xaccSplitSetDateReconciledTS (split, ts.tv_sec);
}//if
- s = gnc_print_date (ts);
+ qof_print_date_buff (datebuff, sizeof(datebuff), 0);
}
- else
- s = "";
editable = FALSE;
}
else {
- s = "";
editable = FALSE;
}
/* Is this a template */
if (is_template && is_trow1)
{
- s = _(" Scheduled ");
+ strncpy (datebuff, _(" Scheduled "), sizeof(datebuff));
editable = FALSE;
}
else if (is_template && is_trow2 && show_extra_dates)
{
- s = "";
editable = FALSE;
}
else if (is_template && is_split && show_extra_dates)
{
- s = "";
editable = FALSE;
}
@@ -1540,11 +1537,12 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
/* This will remove the calander buttons if FALSE */
g_object_set (cell, "use_buttons", view->priv->show_calendar_buttons, NULL );
- g_object_set (cell, "text", s, "editable", editable, NULL);
+ g_object_set (cell, "text", datebuff, "editable", editable, NULL);
break;
case COL_DUEDATE:
/* Column is DUE DATE */
+ memset (datebuff, 0, sizeof(datebuff));
if (is_split)
g_object_set (cell, "cell-background", "white", (gchar*)NULL);
@@ -1552,18 +1550,17 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
/* Only print the due date for invoice transactions */
if (type == TXN_TYPE_INVOICE)
{
- Timespec ts = {xaccTransRetDateDue (trans), 0};
- s = gnc_print_date (ts);
+ time64 t = xaccTransRetDateDue (trans);
+ qof_print_date_buff (datebuff, sizeof(datebuff), t);
editable = FALSE;
}
else {
- s = "";
editable = FALSE;
}
}
editable = (read_only == TRUE) ? FALSE : editable;
- g_object_set (cell, "text", s, "editable", editable, NULL);
+ g_object_set (cell, "text", datebuff, "editable", editable, NULL);
break;
case COL_NUMACT:
diff --git a/gnucash/gnome/dialog-date-close.c b/gnucash/gnome/dialog-date-close.c
index 5c22725..6a34d80 100644
--- a/gnucash/gnome/dialog-date-close.c
+++ b/gnucash/gnome/dialog-date-close.c
@@ -87,14 +87,14 @@ gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data)
}
if (ddc->post_date)
- *(ddc->ts2) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->post_date));
+ ddc->ts2->tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->post_date));
if (ddc->date)
{
if (ddc->terms)
ddc->ts->tv_sec = gncBillTermComputeDueDate (ddc->terms, ddc->ts2->tv_sec);
else
- *(ddc->ts) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->date));
+ ddc->ts->tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->date));
}
if (ddc->memo_entry && ddc->memo)
@@ -146,7 +146,7 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
date_box = GTK_WIDGET(gtk_builder_get_object (builder, "date_box"));
ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *ts);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), ts->tv_sec);
if (parent)
gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
@@ -184,12 +184,12 @@ static void
post_date_changed_cb (GNCDateEdit *gde, gpointer d)
{
DialogDateClose *ddc = d;
- Timespec post_date;
- Timespec due_date = {0,0};
+ time64 post_date;
+ time64 due_date = 0;
- post_date = gnc_date_edit_get_date_ts (gde);
- due_date.tv_sec = gncBillTermComputeDueDate (ddc->terms, post_date.tv_sec);
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), due_date);
+ post_date = gnc_date_edit_get_date (gde);
+ due_date = gncBillTermComputeDueDate (ddc->terms, post_date);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), due_date);
}
gboolean
@@ -278,7 +278,7 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
/* Set the post date widget */
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->post_date), *post);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->post_date), post->tv_sec);
/* Deal with the terms handling of the due date */
if (terms)
@@ -289,7 +289,7 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
post_date_changed_cb (GNC_DATE_EDIT (ddc->post_date), ddc);
}
else
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *ddue);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), ddue->tv_sec);
/* Setup the account widget */
fill_in_acct_info (ddc, set_default_acct);
@@ -378,7 +378,7 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
gtk_label_set_text (label, acct_label_message);
/* Set the date widget */
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *date);
+ gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), date->tv_sec);
/* Setup the account widget */
fill_in_acct_info (ddc, FALSE);
commit dd8732402f6134ce4e89ab8085f4bff2a185d60f
Author: John Ralls <jralls at ceridwen.us>
Date: Mon Jul 30 17:28:18 2018 -0700
Remove all timespecs from the register.
diff --git a/gnucash/register/ledger-core/gncEntryLedger.c b/gnucash/register/ledger-core/gncEntryLedger.c
index a0d192c..e54c590 100644
--- a/gnucash/register/ledger-core/gncEntryLedger.c
+++ b/gnucash/register/ledger-core/gncEntryLedger.c
@@ -1036,15 +1036,15 @@ void gnc_entry_ledger_move_current_entry_updown (GncEntryLedger *ledger,
return;
/* Special treatment if the equality doesn't hold if we access the
- dates as timespec. See the comment in gncEntrySetDateGDate() for the
- reason: Some code used the timespec at noon for the EntryDate, other
- code used the timespec at the start of day. */
+ dates as time64. See the comment in gncEntrySetDateGDate() for the
+ reason: Some code used the time64 at noon for the EntryDate, other
+ code used the time64 at the start of day. */
t1 = gncEntryGetDate(current);
t2 = gncEntryGetDate(target);
if (t1 != t2)
{
- /* Timespecs are not equal, even though the GDates were equal? Then
- we set the GDates again. This will force the timespecs to be equal
+ /* times are not equal, even though the GDates were equal? Then
+ we set the GDates again. This will force the times to be equal
as well. */
gncEntrySetDateGDate(current, &d1);
gncEntrySetDateGDate(target, &d2);
diff --git a/gnucash/register/ledger-core/gncEntryLedgerModel.c b/gnucash/register/ledger-core/gncEntryLedgerModel.c
index ef47c13..a248fed 100644
--- a/gnucash/register/ledger-core/gncEntryLedgerModel.c
+++ b/gnucash/register/ledger-core/gncEntryLedgerModel.c
@@ -186,13 +186,9 @@ static const char * get_date_entry (VirtualLocation virt_loc,
gpointer user_data)
{
GncEntryLedger *ledger = user_data;
- GncEntry *entry;
- Timespec ts = {0,0};
-
- entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
-
- ts.tv_sec = gncEntryGetDate (entry);
- return gnc_print_date (ts);
+ GncEntry *entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
+ time64 time = gncEntryGetDate (entry);
+ return qof_print_date(time);
}
static const char * get_desc_entry (VirtualLocation virt_loc,
diff --git a/gnucash/register/ledger-core/split-register-load.c b/gnucash/register/ledger-core/split-register-load.c
index c1508f8..d5286ad 100644
--- a/gnucash/register/ledger-core/split-register-load.c
+++ b/gnucash/register/ledger-core/split-register-load.c
@@ -487,7 +487,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
{
GDate *d = qof_book_get_autoreadonly_gdate(gnc_get_current_book());
// "d" is NULL if use_autoreadonly is FALSE
- autoreadonly_time = d ? timespecToTime64(gdate_to_timespec(*d)) : 0;
+ autoreadonly_time = d ? gdate_to_time64 (*d) : 0;
g_date_free(d);
}
diff --git a/gnucash/register/ledger-core/split-register-model.c b/gnucash/register/ledger-core/split-register-model.c
index bc65d38..0ecf31f 100644
--- a/gnucash/register/ledger-core/split-register-model.c
+++ b/gnucash/register/ledger-core/split-register-model.c
@@ -521,11 +521,11 @@ gnc_split_register_get_recn_tooltip (VirtualLocation virt_loc,
if (xaccSplitGetReconcile (split) == YREC)
{
- Timespec ts = {0,0};
- const char *str_rec_date;
- xaccSplitGetDateReconciledTS (split, &ts);
- str_rec_date = gnc_print_date (ts);
- return g_strdup_printf (_("Reconciled on %s"), str_rec_date);
+ char datebuff[MAX_DATE_LENGTH + 1];
+ time64 time = xaccSplitGetDateReconciled (split);
+ memset (datebuff, 0, sizeof(datebuff));
+ qof_print_date_buff (datebuff, sizeof(datebuff), time);
+ return g_strdup_printf (_("Reconciled on %s"), datebuff);
}
else if (xaccSplitGetReconcile (split) == VREC)
{
@@ -904,7 +904,6 @@ gnc_split_register_get_due_date_entry (VirtualLocation virt_loc,
SplitRegister *reg = user_data;
Transaction *trans;
Split *split;
- Timespec ts = {0, 0};
gboolean is_current;
char type;
@@ -941,10 +940,9 @@ gnc_split_register_get_due_date_entry (VirtualLocation virt_loc,
return NULL;
}
- ts.tv_sec = xaccTransRetDateDue (trans);
//PWARN ("returning valid due_date entry");
- return gnc_print_date (ts);
+ return qof_print_date (xaccTransRetDateDue (trans));
}
static const char *
@@ -956,16 +954,12 @@ gnc_split_register_get_date_entry (VirtualLocation virt_loc,
SplitRegister *reg = user_data;
Transaction *trans;
Split *split;
- Timespec ts = {0, 0};
split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);
trans = xaccSplitGetParent (split);
if (!trans)
return NULL;
-
- ts.tv_sec = xaccTransRetDatePosted (trans);
-
- return gnc_print_date (ts);
+ return qof_print_date (xaccTransRetDatePosted (trans));
}
static char *
diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c
index 9e3beac..5d1eb78 100644
--- a/gnucash/register/ledger-core/split-register.c
+++ b/gnucash/register/ledger-core/split-register.c
@@ -2078,7 +2078,6 @@ record_price (SplitRegister *reg, Account *account, gnc_numeric value,
time64 time;
BasicCell *cell = gnc_table_layout_get_cell (reg->table->layout, DATE_CELL);
gboolean swap = FALSE;
- Timespec ts;
/* Only record the price for account types that don't have a
* "rate" cell. They'll get handled later by
@@ -2087,9 +2086,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);
- ts.tv_sec = time;
- ts.tv_nsec = 0;
- price = gnc_pricedb_lookup_day (pricedb, comm, curr, ts);
+ price = gnc_pricedb_lookup_day_t64 (pricedb, comm, curr, time);
if (gnc_commodity_equiv (comm, gnc_price_get_currency (price)))
swap = TRUE;
@@ -2116,7 +2113,7 @@ record_price (SplitRegister *reg, Account *account, gnc_numeric value,
value = gnc_numeric_convert(value, scu * COMMODITY_DENOM_MULT,
GNC_HOW_RND_ROUND_HALF_UP);
gnc_price_begin_edit (price);
- gnc_price_set_time (price, ts);
+ gnc_price_set_time64 (price, time);
gnc_price_set_source (price, source);
gnc_price_set_typestr (price, PRICE_TYPE_TRN);
gnc_price_set_value (price, value);
@@ -2131,7 +2128,7 @@ record_price (SplitRegister *reg, Account *account, gnc_numeric value,
gnc_price_begin_edit (price);
gnc_price_set_commodity (price, comm);
gnc_price_set_currency (price, curr);
- gnc_price_set_time (price, ts);
+ gnc_price_set_time64 (price, time);
gnc_price_set_source (price, source);
gnc_price_set_typestr (price, PRICE_TYPE_TRN);
gnc_price_set_value (price, value);
diff --git a/gnucash/register/register-core/datecell.h b/gnucash/register/register-core/datecell.h
index e49a72f..e3ce703 100644
--- a/gnucash/register/register-core/datecell.h
+++ b/gnucash/register/register-core/datecell.h
@@ -120,13 +120,13 @@ void gnc_date_cell_set_value_secs (DateCell *cell, time64 secs);
*/
void gnc_date_cell_commit (DateCell *cell);
-/** Set a Timespec to the value in the DateCell.
+/** 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.
*/
void gnc_date_cell_get_date (DateCell *cell, time64 *time);
-/** Timespec to the value in the DateCell.
+/** 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.
*/
commit 6846a68691d6bf9b5873ed2dcc434e904d9bbd8c
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Jul 29 17:11:43 2018 -0700
Remove two unused functions, one of which used Timespec.
diff --git a/gnucash/register/ledger-core/split-register-control.c b/gnucash/register/ledger-core/split-register-control.c
index de1bc8d..5effb4c 100644
--- a/gnucash/register/ledger-core/split-register-control.c
+++ b/gnucash/register/ledger-core/split-register-control.c
@@ -1204,36 +1204,6 @@ gnc_split_register_get_account_always (SplitRegister *reg,
return gnc_split_register_get_account_by_name (reg, cell, name);
}
-#if 0 /* Not Used */
-static const char *
-gnc_split_register_get_cell_string (SplitRegister *reg, const char *cell_name)
-{
- BasicCell *cell;
-
- cell = gnc_table_layout_get_cell (reg->table->layout, cell_name);
- if (!cell)
- return "";
-
- return gnc_basic_cell_get_value (cell);
-}
-
-static Timespec
-gnc_split_register_get_cell_date (SplitRegister *reg, const char *cell_name)
-{
- DateCell *cell;
- Timespec ts;
-
- cell = (DateCell*) gnc_table_layout_get_cell (reg->table->layout, cell_name);
-
- if (cell)
- gnc_date_cell_get_date (cell, &ts);
- else
- timespecFromTime64 (&ts, gnc_time (NULL));
-
- return ts;
-}
-#endif /* Not Used */
-
/* Creates a transfer dialog and fills its values from register cells (if
* available) or from the provided transaction and split.
*/
commit e3dce951c714ac94a6e717406f470746fecdc29e
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Jul 29 16:45:39 2018 -0700
Remove Timespec from qif importer.
diff --git a/gnucash/import-export/qif-imp/assistant-qif-import.c b/gnucash/import-export/qif-imp/assistant-qif-import.c
index 1d16f99..dcff2f6 100644
--- a/gnucash/import-export/qif-imp/assistant-qif-import.c
+++ b/gnucash/import-export/qif-imp/assistant-qif-import.c
@@ -1137,7 +1137,8 @@ refresh_old_transactions(QIFImportWindow * wind, int selection)
while (!scm_is_null(possible_matches))
{
- Timespec ts_send = {0,0};
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset(datebuff, 0, sizeof(datebuff));
current_xtn = SCM_CAR(possible_matches);
#define FUNC_NAME "xaccTransCountSplits"
gnc_xtn = SWIG_MustGetPtr(SCM_CAR(current_xtn),
@@ -1159,11 +1160,12 @@ refresh_old_transactions(QIFImportWindow * wind, int selection)
}
gtk_list_store_append(store, &iter);
- ts_send.tv_sec = xaccTransRetDatePosted(gnc_xtn);
+ qof_print_date_buff(datebuff, sizeof(datebuff),
+ xaccTransRetDatePosted(gnc_xtn));
gtk_list_store_set
(store, &iter,
QIF_TRANS_COL_INDEX, rownum++,
- QIF_TRANS_COL_DATE, gnc_print_date(ts_send),
+ QIF_TRANS_COL_DATE, datebuff,
QIF_TRANS_COL_DESCRIPTION, xaccTransGetDescription(gnc_xtn),
QIF_TRANS_COL_AMOUNT, amount_str,
QIF_TRANS_COL_CHECKED, selected != SCM_BOOL_F,
@@ -3138,8 +3140,8 @@ gnc_ui_qif_import_duplicates_match_prepare (GtkAssistant *assistant,
while (!scm_is_null(duplicates))
{
time64 send_time = 0;
- char date_buf[MAX_DATE_LENGTH + 1];
- memset (date_buf, 0, sizeof(date_buf));
+ char datebuff[MAX_DATE_LENGTH + 1];
+ memset (datebuff, 0, sizeof(datebuff));
current_xtn = SCM_CAAR(duplicates);
#define FUNC_NAME "xaccTransCountSplits"
gnc_xtn = SWIG_MustGetPtr(current_xtn,
@@ -3157,12 +3159,12 @@ gnc_ui_qif_import_duplicates_match_prepare (GtkAssistant *assistant,
}
gtk_list_store_append(store, &iter);
send_time = xaccTransRetDatePosted(gnc_xtn);
- qof_print_date_buff (date_buf, sizeof(date_buf), send_time);
+ qof_print_date_buff (datebuff, sizeof(datebuff), send_time);
gtk_list_store_set
(store, &iter,
QIF_TRANS_COL_INDEX, rownum++,
QIF_TRANS_COL_DATE,
- date_buf,
+ datebuff,
QIF_TRANS_COL_DESCRIPTION, xaccTransGetDescription(gnc_xtn),
QIF_TRANS_COL_AMOUNT, amount_str,
-1);
commit 14335b78626762d0eba11888334796cff6809d27
Merge: 22dd716 b3f1104
Author: Geert Janssens <geert at kobaltwit.be>
Date: Sat Aug 11 21:04:26 2018 +0200
Merge branch 'Bug796788' of https://github.com/Bob-IT/gnucash into maint
commit b3f1104d39d2326cba7304e7981836e0725aba6d
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Fri Aug 10 14:29:44 2018 +0100
Fix a possible transient parent dialogue warning
diff --git a/gnucash/gnome-utils/dialog-options.c b/gnucash/gnome-utils/dialog-options.c
index da5c14a..7952fb1 100644
--- a/gnucash/gnome-utils/dialog-options.c
+++ b/gnucash/gnome-utils/dialog-options.c
@@ -4335,7 +4335,7 @@ scm_apply_cb (GNCOptionWin *win, gpointer data)
results = gnc_option_db_commit (win->option_db);
for (iter = results; iter; iter = iter->next)
{
- GtkWidget *dialog = gtk_message_dialog_new(NULL,
+ GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(gnc_options_dialog_widget(win)),
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
diff --git a/gnucash/report/report-gnome/dialog-report-column-view.c b/gnucash/report/report-gnome/dialog-report-column-view.c
index ebd4e7e..4453c10 100644
--- a/gnucash/report/report-gnome/dialog-report-column-view.c
+++ b/gnucash/report/report-gnome/dialog-report-column-view.c
@@ -292,7 +292,7 @@ gnc_column_view_edit_apply_cb(GNCOptionWin * w, gpointer user_data)
results = gnc_option_db_commit (win->odb);
for (iter = results; iter; iter = iter->next)
{
- GtkWidget *dialog = gtk_message_dialog_new(NULL,
+ GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(gnc_options_dialog_widget(w)),
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
commit 19d6eb902824e7dbca1b12476dffb83a58b717b9
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sat Aug 11 12:39:48 2018 +0100
Improve the button sensitivity function
diff --git a/gnucash/report/report-gnome/dialog-report-column-view.c b/gnucash/report/report-gnome/dialog-report-column-view.c
index 82751d1..ebd4e7e 100644
--- a/gnucash/report/report-gnome/dialog-report-column-view.c
+++ b/gnucash/report/report-gnome/dialog-report-column-view.c
@@ -239,44 +239,45 @@ gnc_column_view_update_buttons_cb (GtkTreeSelection *selection,
{
GtkTreeModel *model;
GtkTreeIter iter;
- GtkTreeSelection *available_selection;
+ gboolean is_selected;
- /* compare selection to establish which treeview selected */
- available_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->available));
-
- /* available treeview */
- if (available_selection == selection)
+ /* compare treeviews to establish which selected treeview */
+ if (gtk_tree_selection_get_tree_view (selection) == r->available)
{
- if (gtk_tree_selection_get_selected(selection, &model, &iter))
- gtk_widget_set_sensitive (r->add_button, TRUE);
- else
- gtk_widget_set_sensitive (r->add_button, FALSE);
+ /* available treeview */
+ is_selected = gtk_tree_selection_get_selected (selection, &model, &iter);
+ gtk_widget_set_sensitive (r->add_button, is_selected);
return;
}
/* contents treeview */
- if (gtk_tree_selection_get_selected(selection, &model, &iter))
+ is_selected = gtk_tree_selection_get_selected (selection, &model, &iter);
+ gtk_widget_set_sensitive (r->size_button, is_selected);
+ gtk_widget_set_sensitive (r->remove_button, is_selected);
+
+ if (is_selected)
{
int len = scm_ilength (r->contents_list);
- gtk_tree_model_get(model, &iter,
+ gtk_tree_model_get (model, &iter,
CONTENTS_COL_ROW, &r->contents_selected, -1);
- gtk_widget_set_sensitive (r->size_button, TRUE);
- gtk_widget_set_sensitive (r->remove_button, TRUE);
-
if (len > 1)
{
gtk_widget_set_sensitive (r->up_button, TRUE);
gtk_widget_set_sensitive (r->down_button, TRUE);
+
+ if (r->contents_selected == len -1)
+ gtk_widget_set_sensitive (r->down_button, FALSE);
+
+ if (r->contents_selected == 0)
+ gtk_widget_set_sensitive (r->up_button, FALSE);
}
}
else
{
gtk_widget_set_sensitive (r->up_button, FALSE);
gtk_widget_set_sensitive (r->down_button, FALSE);
- gtk_widget_set_sensitive (r->size_button, FALSE);
- gtk_widget_set_sensitive (r->remove_button, FALSE);
}
}
commit 22dd716b58a6a9c424a71268f78af37b972ab23b
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Aug 10 12:57:46 2018 -0700
Set the SWIG minimum version to 2.0.11 now that we require Guile-2.0.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f5d372e..42a23b6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -285,7 +285,7 @@ endif (WIN32)
# SWIG
if(GENERATE_SWIG_WRAPPERS)
- find_package (SWIG REQUIRED)
+ find_package (SWIG 2.0.10 REQUIRED)
include (${SWIG_USE_FILE})
endif()
commit 2f861bc2a49d77cecce056cbc605a74d0b963f5a
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Aug 10 12:21:28 2018 -0700
Ensure all C++ class member raw pointers are default-initialized to nullptr.
diff --git a/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp b/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
index 336d2c4..0c7e854 100644
--- a/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
+++ b/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
@@ -53,7 +53,7 @@ public:
void add_where_cond(QofIdTypeConst, const PairVec&) override;
private:
- const GncSqlConnection* m_conn;
+ const GncSqlConnection* m_conn = nullptr;
std::string m_sql;
};
diff --git a/libgnucash/backend/dbi/gnc-dbisqlconnection.hpp b/libgnucash/backend/dbi/gnc-dbisqlconnection.hpp
index 56766e1..bb71a96 100644
--- a/libgnucash/backend/dbi/gnc-dbisqlconnection.hpp
+++ b/libgnucash/backend/dbi/gnc-dbisqlconnection.hpp
@@ -86,7 +86,7 @@ public:
const ColVec& info_vec) const noexcept;
bool drop_indexes() noexcept;
private:
- QofBackend* m_qbe;
+ QofBackend* m_qbe = nullptr;
dbi_conn m_conn;
std::unique_ptr<GncDbiProvider> m_provider;
/** Used by the error handler routines to flag if the connection is ok to
diff --git a/libgnucash/backend/dbi/gnc-dbisqlresult.hpp b/libgnucash/backend/dbi/gnc-dbisqlresult.hpp
index c0dd59e..52da0d2 100644
--- a/libgnucash/backend/dbi/gnc-dbisqlresult.hpp
+++ b/libgnucash/backend/dbi/gnc-dbisqlresult.hpp
@@ -63,11 +63,11 @@ protected:
return dbi_result_field_is_null(m_inst->m_dbi_result, col);
}
private:
- GncDbiSqlResult* m_inst;
+ GncDbiSqlResult* m_inst = nullptr;
};
private:
- const GncDbiSqlConnection* m_conn;
+ const GncDbiSqlConnection* m_conn = nullptr;
dbi_result m_dbi_result;
IteratorImpl m_iter;
GncSqlRow m_row;
diff --git a/libgnucash/backend/sql/gnc-sql-backend.hpp b/libgnucash/backend/sql/gnc-sql-backend.hpp
index 1d8a97c..bde8700 100644
--- a/libgnucash/backend/sql/gnc-sql-backend.hpp
+++ b/libgnucash/backend/sql/gnc-sql-backend.hpp
@@ -241,12 +241,12 @@ public:
void finish_progress() const noexcept;
protected:
- GncSqlConnection* m_conn; /**< SQL connection */
- QofBook* m_book; /**< The primary, main open book */
+ GncSqlConnection* m_conn = nullptr; /**< SQL connection */
+ QofBook* m_book = nullptr; /**< The primary, main open book */
bool m_loading; /**< We are performing an initial load */
bool m_in_query; /**< We are processing a query */
bool m_is_pristine_db; /**< Are we saving to a new pristine db? */
- const char* m_timespec_format; /**< Server-specific date-time string format */
+ const char* m_timespec_format = nullptr; /**< Server-specific date-time string format */
VersionVec m_versions; /**< Version number for each table */
private:
bool write_account_tree(Account*);
diff --git a/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp b/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
index 3ded4c4..b365d4a 100644
--- a/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
+++ b/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
@@ -231,12 +231,12 @@ protected:
*/
void add_objectref_guid_to_table (ColVec& vec) const noexcept;
private:
- const char* m_col_name; /**< Column name */
+ const char* m_col_name = nullptr; /**< Column name */
const GncSqlObjectType m_col_type; /**< Column type */
unsigned int m_size; /**< Column size in bytes, for string columns */
ColumnFlags m_flags; /**< Column flags */
- const char* m_gobj_param_name; /**< If non-null, g_object param name */
- const char* m_qof_param_name; /**< If non-null, qof parameter name */
+ const char* m_gobj_param_name = nullptr; /**< If non-null, g_object param name */
+ const char* m_qof_param_name = nullptr; /**< If non-null, qof parameter name */
QofAccessFunc m_getter; /**< General access function */
QofSetterFunc m_setter; /**< General setter function */
template <typename T> T get_row_value_from_object(QofIdTypeConst obj_name,
diff --git a/libgnucash/backend/sql/gnc-sql-object-backend.hpp b/libgnucash/backend/sql/gnc-sql-object-backend.hpp
index 316e64d..bd3f705 100644
--- a/libgnucash/backend/sql/gnc-sql-object-backend.hpp
+++ b/libgnucash/backend/sql/gnc-sql-object-backend.hpp
@@ -131,9 +131,9 @@ struct write_objects_t
void commit (QofInstance* inst) {
if (is_ok) is_ok = obe->commit (be, inst);
}
- GncSqlBackend* be;
- bool is_ok;
- GncSqlObjectBackend* obe;
+ GncSqlBackend* be = nullptr;
+ bool is_ok = false;
+ GncSqlObjectBackend* obe = nullptr;
};
diff --git a/libgnucash/engine/test/test-kvp-frame.cpp b/libgnucash/engine/test/test-kvp-frame.cpp
index 9e0491c..29a162c 100644
--- a/libgnucash/engine/test/test-kvp-frame.cpp
+++ b/libgnucash/engine/test/test-kvp-frame.cpp
@@ -42,8 +42,8 @@ public:
}
protected:
KvpFrameImpl t_root;
- KvpValue *t_int_val;
- KvpValue *t_str_val;
+ KvpValue *t_int_val = nullptr;
+ KvpValue *t_str_val = nullptr;
};
template <typename A, typename B> void
commit 9768a2158d312d3d91c4661fd6f5ed1f4d73218c
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Fri Aug 10 12:40:51 2018 +0100
Save the contents_selected value in selection callback
With the use of the selection call back for button sensitivity it make
sense to use that to store the contents_selected value for the contents
tree view.
diff --git a/gnucash/report/report-gnome/dialog-report-column-view.c b/gnucash/report/report-gnome/dialog-report-column-view.c
index 1dc5587..82751d1 100644
--- a/gnucash/report/report-gnome/dialog-report-column-view.c
+++ b/gnucash/report/report-gnome/dialog-report-column-view.c
@@ -259,6 +259,9 @@ gnc_column_view_update_buttons_cb (GtkTreeSelection *selection,
{
int len = scm_ilength (r->contents_list);
+ gtk_tree_model_get(model, &iter,
+ CONTENTS_COL_ROW, &r->contents_selected, -1);
+
gtk_widget_set_sensitive (r->size_button, TRUE);
gtk_widget_set_sensitive (r->remove_button, TRUE);
@@ -459,7 +462,7 @@ gnc_column_view_edit_add_cb(GtkButton * button, gpointer user_data)
int oldlength, id;
gchar *guid_str;
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->available));
- GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(r->available));
+ GtkTreeModel *model;
GtkTreeIter iter;
/* make sure there is a selected entry */
@@ -526,16 +529,6 @@ gnc_column_view_edit_remove_cb(GtkButton * button, gpointer user_data)
SCM oldlist = r->contents_list;
int count;
int oldlength;
- GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->contents));
- GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(r->contents));
- GtkTreeIter iter;
-
- /* make sure there is a selected entry */
- if (gtk_tree_selection_get_selected(selection, &model, &iter))
- gtk_tree_model_get(model, &iter,
- CONTENTS_COL_ROW, &r->contents_selected, -1);
- else
- return;
if (scm_is_list(r->contents_list))
{
@@ -579,16 +572,6 @@ gnc_edit_column_view_move_up_cb(GtkButton * button, gpointer user_data)
SCM temp;
int oldlength;
int count;
- GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->contents));
- GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(r->contents));
- GtkTreeIter iter;
-
- /* make sure there is a selected entry */
- if (gtk_tree_selection_get_selected(selection, &model, &iter))
- gtk_tree_model_get(model, &iter,
- CONTENTS_COL_ROW, &r->contents_selected, -1);
- else
- return;
oldlength = scm_ilength(r->contents_list);
if ((r->contents_selected > 0) && (oldlength > r->contents_selected))
@@ -627,16 +610,6 @@ gnc_edit_column_view_move_down_cb(GtkButton * button, gpointer user_data)
SCM temp;
int oldlength;
int count;
- GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->contents));
- GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(r->contents));
- GtkTreeIter iter;
-
- /* make sure there is a selected entry */
- if (gtk_tree_selection_get_selected(selection, &model, &iter))
- gtk_tree_model_get(model, &iter,
- CONTENTS_COL_ROW, &r->contents_selected, -1);
- else
- return;
oldlength = scm_ilength(r->contents_list);
if (oldlength > (r->contents_selected + 1))
commit 5ff8d8daba7278b242628ba8c0f9f23fae868904
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Fri Aug 10 11:36:41 2018 +0100
Update buttons on Multicolumn report options
Change the sensitivity of the multicolumn report options based on the
selection in the two tree views using the select callback.
diff --git a/gnucash/gtkbuilder/dialog-report.glade b/gnucash/gtkbuilder/dialog-report.glade
index c7dd029..17d2ea5 100644
--- a/gnucash/gtkbuilder/dialog-report.glade
+++ b/gnucash/gtkbuilder/dialog-report.glade
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
+<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="col_adjustment">
@@ -95,9 +95,10 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="button85">
+ <object class="GtkButton" id="add_button1">
<property name="label" translatable="yes">A_dd >></property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@@ -110,9 +111,10 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="button86">
+ <object class="GtkButton" id="remove_button1">
<property name="label" translatable="yes"><< _Remove</property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@@ -137,9 +139,10 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="button87">
+ <object class="GtkButton" id="up_button1">
<property name="label" translatable="yes">Move _up</property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@@ -152,9 +155,10 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="button88">
+ <object class="GtkButton" id="down_button1">
<property name="label" translatable="yes">Move dow_n</property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@@ -179,9 +183,10 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="button89">
+ <object class="GtkButton" id="size_button1">
<property name="label" translatable="yes">Si_ze...</property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@@ -241,9 +246,11 @@
</child>
</object>
</child>
+ <child type="titlebar">
+ <placeholder/>
+ </child>
</object>
<object class="GtkDialog" id="html_style_sheet_dialog">
- <property name="visible">False</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">HTML Style Sheets</property>
<property name="type_hint">dialog</property>
@@ -416,6 +423,9 @@
<action-widgets>
<action-widget response="-7">closebutton1</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
<object class="GtkAdjustment" id="row_adjustment">
<property name="upper">100</property>
@@ -573,6 +583,9 @@
<action-widget response="-6">cancelbutton</action-widget>
<action-widget response="-5">okbutton</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
<object class="GtkDialog" id="select_style_sheet_dialog">
<property name="can_focus">False</property>
@@ -690,6 +703,9 @@
<action-widget response="2">delete_button</action-widget>
<action-widget response="-7">close_button</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
<object class="GtkListStore" id="template_liststore">
<columns>
@@ -849,5 +865,8 @@
<action-widget response="-6">cancelbutton1</action-widget>
<action-widget response="-5">okbutton1</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
</interface>
diff --git a/gnucash/report/report-gnome/dialog-report-column-view.c b/gnucash/report/report-gnome/dialog-report-column-view.c
index 84bdd93..1dc5587 100644
--- a/gnucash/report/report-gnome/dialog-report-column-view.c
+++ b/gnucash/report/report-gnome/dialog-report-column-view.c
@@ -67,6 +67,12 @@ struct gncp_column_view_edit
SCM available_list;
SCM contents_list;
int contents_selected;
+
+ GtkWidget *add_button;
+ GtkWidget *remove_button;
+ GtkWidget *up_button;
+ GtkWidget *down_button;
+ GtkWidget *size_button;
};
void gnc_column_view_edit_add_cb(GtkButton * button, gpointer user_data);
@@ -228,6 +234,50 @@ update_contents_lists(gnc_column_view_edit * view)
}
static void
+gnc_column_view_update_buttons_cb (GtkTreeSelection *selection,
+ gnc_column_view_edit *r)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreeSelection *available_selection;
+
+ /* compare selection to establish which treeview selected */
+ available_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->available));
+
+ /* available treeview */
+ if (available_selection == selection)
+ {
+ if (gtk_tree_selection_get_selected(selection, &model, &iter))
+ gtk_widget_set_sensitive (r->add_button, TRUE);
+ else
+ gtk_widget_set_sensitive (r->add_button, FALSE);
+ return;
+ }
+
+ /* contents treeview */
+ if (gtk_tree_selection_get_selected(selection, &model, &iter))
+ {
+ int len = scm_ilength (r->contents_list);
+
+ gtk_widget_set_sensitive (r->size_button, TRUE);
+ gtk_widget_set_sensitive (r->remove_button, TRUE);
+
+ if (len > 1)
+ {
+ gtk_widget_set_sensitive (r->up_button, TRUE);
+ gtk_widget_set_sensitive (r->down_button, TRUE);
+ }
+ }
+ else
+ {
+ gtk_widget_set_sensitive (r->up_button, FALSE);
+ gtk_widget_set_sensitive (r->down_button, FALSE);
+ gtk_widget_set_sensitive (r->size_button, FALSE);
+ gtk_widget_set_sensitive (r->remove_button, FALSE);
+ }
+}
+
+static void
gnc_column_view_edit_apply_cb(GNCOptionWin * w, gpointer user_data)
{
SCM dirty_report = scm_c_eval_string("gnc:report-set-dirty?!");
@@ -278,6 +328,7 @@ gnc_column_view_edit_options(SCM options, SCM view)
GtkListStore *store;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
+ GtkTreeSelection *selection;
ptr = scm_call_1(get_editor, view);
if (ptr != SCM_BOOL_F)
@@ -304,6 +355,13 @@ gnc_column_view_edit_options(SCM options, SCM view)
editor = GTK_WIDGET(gtk_builder_get_object (builder, "view_contents_table"));
r->available = GTK_TREE_VIEW (gtk_builder_get_object (builder, "available_view"));
r->contents = GTK_TREE_VIEW (gtk_builder_get_object (builder, "contents_view"));
+
+ r->add_button = GTK_WIDGET(gtk_builder_get_object (builder, "add_button1"));
+ r->remove_button = GTK_WIDGET(gtk_builder_get_object (builder, "remove_button1"));
+ r->up_button = GTK_WIDGET(gtk_builder_get_object (builder, "up_button1"));
+ r->down_button = GTK_WIDGET(gtk_builder_get_object (builder, "down_button1"));
+ r->size_button = GTK_WIDGET(gtk_builder_get_object (builder, "size_button1"));
+
r->options = options;
r->view = view;
r->available_list = SCM_EOL;
@@ -335,6 +393,11 @@ gnc_column_view_edit_options(SCM options, SCM view)
NULL);
gtk_tree_view_append_column(r->available, column);
+ /* use the selection cb to update buttons */
+ selection = gtk_tree_view_get_selection(r->available);
+ g_signal_connect(selection, "changed",
+ G_CALLBACK(gnc_column_view_update_buttons_cb), r);
+
/* Build the 'contents' view */
store = gtk_list_store_new (NUM_CONTENTS_COLS, G_TYPE_STRING, G_TYPE_INT,
G_TYPE_INT, G_TYPE_INT);
@@ -359,6 +422,11 @@ gnc_column_view_edit_options(SCM options, SCM view)
NULL);
gtk_tree_view_append_column(r->contents, column);
+ /* use the selection cb to update buttons */
+ selection = gtk_tree_view_get_selection(r->contents);
+ g_signal_connect(selection, "changed",
+ G_CALLBACK(gnc_column_view_update_buttons_cb), r);
+
update_available_lists(r);
update_contents_lists(r);
commit 847766fc136154dc35ebcb6eeb7dc7bf6c1bc30a
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Wed Aug 8 15:43:36 2018 +0100
Bug 796788 - strange behaviour in options of multicolumn report
This bug stemmed from the use of GTK_TREE_SORTABLE, the list store
entries for available reports are not stored as entered but in a sorted
order. Replaced the use of entry numbers to that of the report guid and
also used the tree selection to maintain a pointer to the
selected report. Also separated the updating of the two treeviews so
selected report position will be maintained.
diff --git a/gnucash/report/report-gnome/dialog-report-column-view.c b/gnucash/report/report-gnome/dialog-report-column-view.c
index 76e0b9d..84bdd93 100644
--- a/gnucash/report/report-gnome/dialog-report-column-view.c
+++ b/gnucash/report/report-gnome/dialog-report-column-view.c
@@ -41,7 +41,7 @@
enum available_cols
{
AVAILABLE_COL_NAME = 0,
- AVAILABLE_COL_ROW,
+ AVAILABLE_COL_GUID,
NUM_AVAILABLE_COLS
};
@@ -65,8 +65,6 @@ struct gncp_column_view_edit
GNCOptionDB * odb;
SCM available_list;
- int available_selected;
-
SCM contents_list;
int contents_selected;
};
@@ -104,82 +102,95 @@ gnc_column_view_edit_destroy(gnc_column_view_edit * view)
}
static void
-update_display_lists(gnc_column_view_edit * view)
+update_available_lists(gnc_column_view_edit * view)
{
SCM get_rpt_guids = scm_c_eval_string("gnc:all-report-template-guids");
SCM template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
- SCM report_menu_name = scm_c_eval_string("gnc:report-menu-name");
SCM rpt_guids = scm_call_0(get_rpt_guids);
- SCM contents =
- gnc_option_db_lookup_option(view->odb, "__general", "report-list",
- SCM_BOOL_F);
- SCM this_report;
SCM selection;
+
gchar *name;
- int row, i, id;
+ gchar *guid_str;
+
+ GtkTreeModel *model;
GtkListStore *store;
GtkTreeIter iter;
- GtkTreePath *path;
GtkTreeSelection *tree_selection;
-
/* Update the list of available reports (left selection box). */
- row = view->available_selected;
+ tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view->available));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW(view->available));
- if (scm_is_list(view->available_list) && !scm_is_null (view->available_list))
+ if (gtk_tree_selection_get_selected(tree_selection, &model, &iter))
{
- row = MIN (row, scm_ilength (view->available_list) - 1);
- selection = scm_list_ref (view->available_list, scm_from_int (row));
+ gchar *guid_str;
+ gtk_tree_model_get(model, &iter,
+ AVAILABLE_COL_GUID, &guid_str,
+ -1);
+ selection = scm_from_utf8_string(guid_str);
+ g_free (guid_str);
}
else
- {
selection = SCM_UNDEFINED;
- }
scm_gc_unprotect_object(view->available_list);
view->available_list = rpt_guids;
scm_gc_protect_object(view->available_list);
- store = GTK_LIST_STORE(gtk_tree_view_get_model(view->available));
+ store = GTK_LIST_STORE(model);
gtk_list_store_clear(store);
if (scm_is_list(rpt_guids))
{
- for (i = 0; !scm_is_null(rpt_guids); rpt_guids = SCM_CDR(rpt_guids), i++)
+ for (int i = 0; !scm_is_null(rpt_guids); rpt_guids = SCM_CDR(rpt_guids), i++)
{
- if (scm_is_equal (SCM_CAR(rpt_guids), selection))
- row = i;
- name = gnc_scm_to_utf8_string (scm_call_2(template_menu_name, SCM_CAR(rpt_guids),
+ SCM rpt_guids_temp = SCM_CAR(rpt_guids);
+
+ guid_str = scm_to_utf8_string (rpt_guids_temp);
+ name = gnc_scm_to_utf8_string (scm_call_2(template_menu_name, rpt_guids_temp,
SCM_BOOL_F));
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
AVAILABLE_COL_NAME, _(name),
- AVAILABLE_COL_ROW, i,
+ AVAILABLE_COL_GUID, guid_str,
-1);
+
+ if (scm_is_equal (rpt_guids_temp, selection))
+ gtk_tree_selection_select_iter (tree_selection, &iter);
+
g_free (name);
+ g_free (guid_str);
}
-
}
+}
- tree_selection = gtk_tree_view_get_selection(view->available);
- path = gtk_tree_path_new_from_indices(row, -1);
- gtk_tree_selection_select_path(tree_selection, path);
- gtk_tree_path_free(path);
+static void
+update_contents_lists(gnc_column_view_edit * view)
+{
+ SCM report_menu_name = scm_c_eval_string("gnc:report-menu-name");
+ SCM contents =
+ gnc_option_db_lookup_option(view->odb, "__general", "report-list",
+ SCM_BOOL_F);
+ SCM this_report;
+ SCM selection;
+ gchar *name;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GtkTreeSelection *tree_selection;
/* Update the list of selected reports (right selection box). */
- row = view->contents_selected;
+ tree_selection = gtk_tree_view_get_selection(view->contents);
if (scm_is_list(view->contents_list) && !scm_is_null (view->contents_list))
{
+ int row = view->contents_selected;
row = MIN (row, scm_ilength (view->contents_list) - 1);
- selection = scm_list_ref (view->contents_list, scm_from_int (row));
+ selection = scm_list_ref (view->contents_list, scm_from_int (row));
}
else
- {
selection = SCM_UNDEFINED;
- }
scm_gc_unprotect_object(view->contents_list);
view->contents_list = contents;
@@ -187,14 +198,15 @@ update_display_lists(gnc_column_view_edit * view)
store = GTK_LIST_STORE(gtk_tree_view_get_model(view->contents));
gtk_list_store_clear(store);
+
if (scm_is_list(contents))
{
- for (i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++)
+ for (int i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++)
{
- if (scm_is_equal (SCM_CAR(contents), selection))
- row = i;
+ SCM contents_temp = SCM_CAR(contents);
+
+ int id = scm_to_int(SCM_CAAR(contents));
- id = scm_to_int(SCM_CAAR(contents));
this_report = gnc_report_find(id);
name = gnc_scm_to_utf8_string (scm_call_1(report_menu_name, this_report));
@@ -203,44 +215,16 @@ update_display_lists(gnc_column_view_edit * view)
(store, &iter,
CONTENTS_COL_NAME, _(name),
CONTENTS_COL_ROW, i,
- CONTENTS_COL_REPORT_COLS, scm_to_int(SCM_CADR(SCM_CAR(contents))),
- CONTENTS_COL_REPORT_ROWS, scm_to_int(SCM_CADDR(SCM_CAR(contents))),
+ CONTENTS_COL_REPORT_COLS, scm_to_int(SCM_CADR(contents_temp)),
+ CONTENTS_COL_REPORT_ROWS, scm_to_int(SCM_CADDR(contents_temp)),
-1);
+
+ if (scm_is_equal (contents_temp, selection))
+ gtk_tree_selection_select_iter (tree_selection, &iter);
+
g_free (name);
}
}
-
- tree_selection = gtk_tree_view_get_selection(view->contents);
- path = gtk_tree_path_new_from_indices(row, -1);
- gtk_tree_selection_select_path(tree_selection, path);
- // gtk_tree_view_scroll_to_cell(view->contents, path, NULL, TRUE, 0.5, 0.0);
- gtk_tree_path_free(path);
-}
-
-static void
-gnc_column_view_select_avail_cb(GtkTreeSelection *selection,
- gnc_column_view_edit *r)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- if (gtk_tree_selection_get_selected(selection, &model, &iter))
- gtk_tree_model_get(model, &iter,
- AVAILABLE_COL_ROW, &r->available_selected,
- -1);
-}
-
-static void
-gnc_column_view_select_contents_cb(GtkTreeSelection *selection,
- gnc_column_view_edit *r)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- if (gtk_tree_selection_get_selected(selection, &model, &iter))
- gtk_tree_model_get(model, &iter,
- AVAILABLE_COL_ROW, &r->contents_selected,
- -1);
}
static void
@@ -294,7 +278,6 @@ gnc_column_view_edit_options(SCM options, SCM view)
GtkListStore *store;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
- GtkTreeSelection *selection;
ptr = scm_call_1(get_editor, view);
if (ptr != SCM_BOOL_F)
@@ -323,7 +306,6 @@ gnc_column_view_edit_options(SCM options, SCM view)
r->contents = GTK_TREE_VIEW (gtk_builder_get_object (builder, "contents_view"));
r->options = options;
r->view = view;
- r->available_selected = 0;
r->available_list = SCM_EOL;
r->contents_selected = 0;
r->contents_list = SCM_EOL;
@@ -342,7 +324,7 @@ gnc_column_view_edit_options(SCM options, SCM view)
scm_gc_protect_object(r->contents_list);
/* Build the 'available' view */
- store = gtk_list_store_new (NUM_AVAILABLE_COLS, G_TYPE_STRING, G_TYPE_INT);
+ store = gtk_list_store_new (NUM_AVAILABLE_COLS, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model(r->available, GTK_TREE_MODEL(store));
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), AVAILABLE_COL_NAME, GTK_SORT_ASCENDING);
g_object_unref(store);
@@ -353,10 +335,6 @@ gnc_column_view_edit_options(SCM options, SCM view)
NULL);
gtk_tree_view_append_column(r->available, column);
- selection = gtk_tree_view_get_selection(r->available);
- g_signal_connect(selection, "changed",
- G_CALLBACK(gnc_column_view_select_avail_cb), r);
-
/* Build the 'contents' view */
store = gtk_list_store_new (NUM_CONTENTS_COLS, G_TYPE_STRING, G_TYPE_INT,
G_TYPE_INT, G_TYPE_INT);
@@ -381,11 +359,8 @@ gnc_column_view_edit_options(SCM options, SCM view)
NULL);
gtk_tree_view_append_column(r->contents, column);
- selection = gtk_tree_view_get_selection(r->contents);
- g_signal_connect(selection, "changed",
- G_CALLBACK(gnc_column_view_select_contents_cb), r);
-
- update_display_lists(r);
+ update_available_lists(r);
+ update_contents_lists(r);
gnc_options_dialog_set_apply_cb(r->optwin,
gnc_column_view_edit_apply_cb, r);
@@ -414,12 +389,22 @@ gnc_column_view_edit_add_cb(GtkButton * button, gpointer user_data)
SCM oldlist = r->contents_list;
int count;
int oldlength, id;
+ gchar *guid_str;
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->available));
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(r->available));
+ GtkTreeIter iter;
+
+ /* make sure there is a selected entry */
+ if (gtk_tree_selection_get_selected(selection, &model, &iter))
+ gtk_tree_model_get(model, &iter,
+ AVAILABLE_COL_GUID, &guid_str, -1);
+ else
+ return;
- if (scm_is_list(r->available_list) &&
- (scm_ilength(r->available_list) > r->available_selected))
+ if (scm_is_list(r->available_list))
{
- template_name = scm_list_ref(r->available_list,
- scm_from_int (r->available_selected));
+ template_name = scm_from_utf8_string(guid_str);
+
new_report = scm_call_1(make_report, template_name);
id = scm_to_int(new_report);
scm_call_2(mark_report, gnc_report_find(id), SCM_BOOL_T);
@@ -461,8 +446,8 @@ gnc_column_view_edit_add_cb(GtkButton * button, gpointer user_data)
r->contents_list);
gnc_options_dialog_changed (r->optwin);
}
-
- update_display_lists(r);
+ g_free (guid_str);
+ update_contents_lists(r);
}
void
@@ -473,6 +458,16 @@ gnc_column_view_edit_remove_cb(GtkButton * button, gpointer user_data)
SCM oldlist = r->contents_list;
int count;
int oldlength;
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->contents));
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(r->contents));
+ GtkTreeIter iter;
+
+ /* make sure there is a selected entry */
+ if (gtk_tree_selection_get_selected(selection, &model, &iter))
+ gtk_tree_model_get(model, &iter,
+ CONTENTS_COL_ROW, &r->contents_selected, -1);
+ else
+ return;
if (scm_is_list(r->contents_list))
{
@@ -504,8 +499,7 @@ gnc_column_view_edit_remove_cb(GtkButton * button, gpointer user_data)
gnc_options_dialog_changed (r->optwin);
}
-
- update_display_lists(r);
+ update_contents_lists(r);
}
void
@@ -517,6 +511,16 @@ gnc_edit_column_view_move_up_cb(GtkButton * button, gpointer user_data)
SCM temp;
int oldlength;
int count;
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->contents));
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(r->contents));
+ GtkTreeIter iter;
+
+ /* make sure there is a selected entry */
+ if (gtk_tree_selection_get_selected(selection, &model, &iter))
+ gtk_tree_model_get(model, &iter,
+ CONTENTS_COL_ROW, &r->contents_selected, -1);
+ else
+ return;
oldlength = scm_ilength(r->contents_list);
if ((r->contents_selected > 0) && (oldlength > r->contents_selected))
@@ -542,7 +546,7 @@ gnc_edit_column_view_move_up_cb(GtkButton * button, gpointer user_data)
gnc_options_dialog_changed (r->optwin);
- update_display_lists(r);
+ update_contents_lists(r);
}
}
@@ -555,6 +559,16 @@ gnc_edit_column_view_move_down_cb(GtkButton * button, gpointer user_data)
SCM temp;
int oldlength;
int count;
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->contents));
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(r->contents));
+ GtkTreeIter iter;
+
+ /* make sure there is a selected entry */
+ if (gtk_tree_selection_get_selected(selection, &model, &iter))
+ gtk_tree_model_get(model, &iter,
+ CONTENTS_COL_ROW, &r->contents_selected, -1);
+ else
+ return;
oldlength = scm_ilength(r->contents_list);
if (oldlength > (r->contents_selected + 1))
@@ -580,7 +594,7 @@ gnc_edit_column_view_move_down_cb(GtkButton * button, gpointer user_data)
gnc_options_dialog_changed (r->optwin);
- update_display_lists(r);
+ update_contents_lists(r);
}
}
@@ -636,7 +650,7 @@ gnc_column_view_edit_size_cb(GtkButton * button, gpointer user_data)
current);
scm_gc_protect_object(r->contents_list);
gnc_options_dialog_changed (r->optwin);
- update_display_lists(r);
+ update_contents_lists(r);
}
g_object_unref(G_OBJECT(builder));
commit 1e87d069f651a1c1642b518d734e4cdf5afcd9fb
Merge: de2a1e9 47ad60c
Author: Geert Janssens <geert at kobaltwit.be>
Date: Wed Aug 8 16:26:35 2018 +0200
Merge branch 'maint-upgrade-test-balsheet' of https://github.com/christopherlam/gnucash into maint
commit de2a1e9e6793575c1f9dbce41d1c484bd96200ff
Author: Geert Janssens <geert at kobaltwit.be>
Date: Wed Aug 8 15:58:38 2018 +0200
A few updates to the guile hacking document
diff --git a/doc/guile-hackers.txt b/doc/guile-hackers.txt
index d759382..df53925 100644
--- a/doc/guile-hackers.txt
+++ b/doc/guile-hackers.txt
@@ -33,10 +33,6 @@ either end. Guile supports a superset of R4RS (the Scheme standard).
For initial experimentation, you can use Guile as an interactive Scheme
shell to play around with the system.
-SLIB is a library for Scheme implementations (including guile)
-that implements a large collection of useful data structures
-and algorithms.
-
FIXME: Starting gnucash as a guile shell. ..
While the Guile documentation (in info format) explains
@@ -50,18 +46,6 @@ FAQs, online copies of the Scheme standard (which is actually
quite readable and useful), and pointers to web tutorials
and other resources.
-g-wrap
-------
-
-Note: gwrap has been replaced by swig and dropped completely in
-SVN-trunk on 2006-10-20 and for gnucash-2.2.0.
-
-(Old info: g-wrap is the tool used to automate the wrapping of C
-functions to make them callable from the guile code. g-wrap is
-now maintained by Rob Browning and is available from
-ftp://ftp.gnucash.org/pub/g-wrap )
-
-
Garbage collection:
-------------------
@@ -97,14 +81,10 @@ use it.
The moral of this story is that if you need to have the C side ferret
away a scheme item for later, you must also keep at least one
reference to that item on the guile side until the C side is finished
-with it. I believe that the guile people have recently come up with a
-nice general solution to this problem, but until that's generally
-available, there are a number of ways you can solve this.
-
-If nothing else, you can just create a global hash on the guile side,
-place the object in question in the hash table, and then have the
-C-side delete that item from the hash when it's finished with it.
+with it.
+You can protect an object using scm_gc_protect_object. When you're done
+with it you can release it using scm_gc_unprotect_object.
Guile Interrupts:
-----------------
commit d69d1f6a32a57ff34f4e80df2e32902719f0c8c8
Merge: 239ee67 2b0b3d4
Author: Geert Janssens <geert at kobaltwit.be>
Date: Wed Aug 8 15:52:51 2018 +0200
Merge branch 'maint' of https://github.com/yurchor/gnucash into maint
commit 239ee6797a95b24f8f865997cc4ddb1d91f882ae
Author: Geert Janssens <geert at kobaltwit.be>
Date: Wed Aug 8 15:46:23 2018 +0200
Fix crash when cancelling a Save As... overwrite action
This was discovered while trying to fix bug 796792. However that bug itself
is totally unrelated.
diff --git a/libgnucash/backend/xml/gnc-xml-backend.hpp b/libgnucash/backend/xml/gnc-xml-backend.hpp
index 2710115..cc3ff7c 100644
--- a/libgnucash/backend/xml/gnc-xml-backend.hpp
+++ b/libgnucash/backend/xml/gnc-xml-backend.hpp
@@ -61,6 +61,6 @@ private:
std::string m_linkfile;
int m_lockfd;
- QofBook* m_book; /* The primary, main open book */
+ QofBook* m_book = nullptr; /* The primary, main open book */
};
#endif // __GNC_XML_BACKEND_HPP__
commit e330a781f0360a1c5a031c47a67cf5fae1db6126
Merge: 3b74574 97c191c
Author: Geert Janssens <geert at kobaltwit.be>
Date: Wed Aug 8 14:22:49 2018 +0200
Merge branch 'Bug796792' of https://github.com/Bob-IT/gnucash into maint
commit 2b0b3d4fce4e2f41e0e6857d5812a1dbc723b02c
Author: Yuri Chornoivan <yurchor at ukr.net>
Date: Tue Aug 7 16:25:37 2018 +0300
Fix more minor typos
Signed-off-by: Yuri Chornoivan <yurchor at ukr.net>
diff --git a/gnucash/gnome-utils/dialog-options.c b/gnucash/gnome-utils/dialog-options.c
index da5c14a..2d1c600 100644
--- a/gnucash/gnome-utils/dialog-options.c
+++ b/gnucash/gnome-utils/dialog-options.c
@@ -639,7 +639,7 @@ gnc_set_default_gain_loss_account_widget(gnc_commodity *commodity)
{
book_currency_data->default_gain_loss_account_text =
gtk_label_new( _("Because no accounts have " \
- "been set up yet,you will need to return to this " \
+ "been set up yet, you will need to return to this " \
"dialog (via File->Properties), after account setup, " \
"if you want to set a default gain/loss account.") );
diff --git a/gnucash/gschemas/org.gnucash.gschema.xml.in b/gnucash/gschemas/org.gnucash.gschema.xml.in
index 53edc3c..9dd28a6 100644
--- a/gnucash/gschemas/org.gnucash.gschema.xml.in
+++ b/gnucash/gschemas/org.gnucash.gschema.xml.in
@@ -72,7 +72,7 @@
</key>
<key name="migrate-prefs-done" type="b">
<default>false</default>
- <summary>Tool to migrate preferences from old backend (CGonf) to new one (GSettings) has run successfully.</summary>
+ <summary>Tool to migrate preferences from old backend (GConf) to new one (GSettings) has run successfully.</summary>
<description>GnuCash switched to another backend to store user preferences between 2.4 and 2.6. To smooth the transition, most preferences will be migrated the first time a 2.6 version of GnuCash is run. This migration should only run once. This preference keeps track whether or not this migration tool has run successfully.</description>
</key>
<key name="retain-type-never" type="b">
diff --git a/gnucash/import-export/csv-exp/assistant-csv-export.c b/gnucash/import-export/csv-exp/assistant-csv-export.c
index a39090c..81d278f 100644
--- a/gnucash/import-export/csv-exp/assistant-csv-export.c
+++ b/gnucash/import-export/csv-exp/assistant-csv-export.c
@@ -88,7 +88,7 @@ static const gchar *finish_trans_string = N_(
static const gchar *finish_trans_search_gl_string = N_(
/* Translators: %s is the file name string. */
- "When you click 'Apply', the transactions will be exported to the file '%s.\n\n"
+ "When you click 'Apply', the transactions will be exported to the file '%s'.\n\n"
"You can also verify your selections by clicking on 'Back' or 'Cancel' to Abort Export.\n");
static const gchar *start_tree_string = N_(
commit 97c191cd4208fb5a8f4894968686dbe178f06bbd
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Aug 7 10:33:04 2018 +0100
Replace tabs with spaces and fix some indenting in gnc-file.c
diff --git a/gnucash/gnome-utils/gnc-file.c b/gnucash/gnome-utils/gnc-file.c
index 840601e..d983061 100644
--- a/gnucash/gnome-utils/gnc-file.c
+++ b/gnucash/gnome-utils/gnc-file.c
@@ -834,8 +834,8 @@ RESTART:
if (!show_session_error (parent, io_err, newfile, GNC_FILE_DIALOG_OPEN))
{
/* user told us to create a new database. Do it. We
- * shouldn't have to worry about locking or clobbering,
- * it's supposed to be new. */
+ * shouldn't have to worry about locking or clobbering,
+ * it's supposed to be new. */
qof_session_begin (new_session, newfile, FALSE, TRUE, FALSE);
}
}
@@ -1193,14 +1193,14 @@ gnc_file_do_export(GtkWindow *parent, const char * filename)
/* Some extra steps for file based uri's only */
if (gnc_uri_is_file_protocol(protocol))
{
- if (check_file_path (path))
- {
- show_session_error (parent, ERR_FILEIO_RESERVED_WRITE, newfile,
- GNC_FILE_DIALOG_SAVE);
- return;
- }
- gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE,
- g_path_get_dirname(path));
+ if (check_file_path (path))
+ {
+ show_session_error (parent, ERR_FILEIO_RESERVED_WRITE, newfile,
+ GNC_FILE_DIALOG_SAVE);
+ return;
+ }
+ gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE,
+ g_path_get_dirname(path));
}
/* Check to see if the user specified the same file as the current
* file. If so, prevent the export from happening to avoid killing this file */
@@ -1425,14 +1425,14 @@ gnc_file_do_save_as (GtkWindow *parent, const char* filename)
/* Some extra steps for file based uri's only */
if (gnc_uri_is_file_protocol(protocol))
{
- if (check_file_path (path))
- {
- show_session_error (parent, ERR_FILEIO_RESERVED_WRITE, newfile,
- GNC_FILE_DIALOG_SAVE);
- return;
- }
- gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE,
- g_path_get_dirname (path));
+ if (check_file_path (path))
+ {
+ show_session_error (parent, ERR_FILEIO_RESERVED_WRITE, newfile,
+ GNC_FILE_DIALOG_SAVE);
+ return;
+ }
+ gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE,
+ g_path_get_dirname (path));
}
/* Check to see if the user specified the same file as the current
commit 641925f2d0b7fc54824b7b05136ada0bd605da6f
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Tue Aug 7 10:31:13 2018 +0100
Bug 796792 - SaveAs Overwrite dialogue in background and not visible
Firstly the wrong parent was being used for these secondary warning
messages, should be the dialogue and not the main Gnucash application so
these have been changed.
Also some of these secondary warning dialogues still had NULL as the
parent and so the transient parent warning would occur, added parent.
diff --git a/gnucash/gnome-utils/dialog-file-access.c b/gnucash/gnome-utils/dialog-file-access.c
index ce88602..3126d3b 100644
--- a/gnucash/gnome-utils/dialog-file-access.c
+++ b/gnucash/gnome-utils/dialog-file-access.c
@@ -146,15 +146,15 @@ gnc_ui_file_access_response_cb(GtkDialog *dialog, gint response, GtkDialog *unus
gboolean open_readonly = faw->readonly_checkbutton
? gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(faw->readonly_checkbutton))
: FALSE;
- gnc_file_open_file (gnc_ui_get_main_window (GTK_WIDGET (dialog)), url, open_readonly);
+ gnc_file_open_file (GTK_WINDOW(dialog), url, open_readonly);
}
else if ( faw->type == FILE_ACCESS_SAVE_AS )
{
- gnc_file_do_save_as (gnc_ui_get_main_window (GTK_WIDGET (dialog)), url);
+ gnc_file_do_save_as (GTK_WINDOW(dialog), url);
}
else if ( faw->type == FILE_ACCESS_EXPORT )
{
- gnc_file_do_export (gnc_ui_get_main_window (GTK_WIDGET (dialog)), url);
+ gnc_file_do_export (GTK_WINDOW(dialog), url);
}
break;
diff --git a/gnucash/gnome-utils/gnc-file.c b/gnucash/gnome-utils/gnc-file.c
index 72dddbe..840601e 100644
--- a/gnucash/gnome-utils/gnc-file.c
+++ b/gnucash/gnome-utils/gnc-file.c
@@ -1019,7 +1019,7 @@ RESTART:
{
gchar *message = gnc_account_name_violations_errmsg ( gnc_get_account_separator_string(),
invalid_account_names );
- gnc_warning_dialog(NULL, "%s", message);
+ gnc_warning_dialog(parent, "%s", message);
g_free ( message );
}
return TRUE;
@@ -1234,7 +1234,7 @@ gnc_file_do_export(GtkWindow *parent, const char * filename)
else
name = gnc_uri_normalize_uri ( newfile, FALSE );
/* if user says cancel, we should break out */
- if (!gnc_verify_dialog (NULL, FALSE, format, name))
+ if (!gnc_verify_dialog (parent, FALSE, format, name))
{
return;
}
@@ -1269,7 +1269,7 @@ gnc_file_do_export(GtkWindow *parent, const char * filename)
/* %s is the strerror(3) error string of the error that occurred. */
const char *format = _("There was an error saving the file.\n\n%s");
- gnc_error_dialog (NULL, format, strerror(errno));
+ gnc_error_dialog (parent, format, strerror(errno));
return;
}
}
@@ -1471,7 +1471,7 @@ gnc_file_do_save_as (GtkWindow *parent, const char* filename)
name = gnc_uri_normalize_uri ( newfile, FALSE );
/* if user says cancel, we should break out */
- if (!gnc_verify_dialog (NULL, FALSE, format, name ))
+ if (!gnc_verify_dialog (parent, FALSE, format, name ))
{
xaccLogDisable();
qof_session_destroy (new_session);
@@ -1600,7 +1600,7 @@ gnc_file_revert (GtkWindow *parent)
else
filename = fileurl;
- if (!gnc_verify_dialog (NULL, FALSE, title, filename))
+ if (!gnc_verify_dialog (parent, FALSE, title, filename))
return;
qof_book_mark_session_saved (qof_session_get_book (session));
commit 3b74574cde3b808d80d60d7ce8d479d321da79c6
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Aug 2 23:50:06 2018 +0800
[test-stress-options] remove need for test-stress-optionlist.scm
This commit modifies test-stress-options to retrieve the report-list,
and for each report-list, retrieve their options, and for each
multichoice and boolean option, add to optionslist. I now know how to
generate the optionslist dynamically from the unit tests, therefore
there's no need to maintain a test-stress-optionslist.scm anymore. Yay!
diff --git a/gnucash/report/standard-reports/test/test-stress-options.scm b/gnucash/report/standard-reports/test/test-stress-options.scm
index 4265273..e85cd61 100644
--- a/gnucash/report/standard-reports/test/test-stress-options.scm
+++ b/gnucash/report/standard-reports/test/test-stress-options.scm
@@ -26,60 +26,35 @@
;;
;; e.g. COMBINATORICS=/home/user/jenny/jenny ninja check
-(load "test-stress-optionslist.scm")
-;; The above optionslist was generated programmatically. It was
-;; generated by running a sentinel function in the middle of an
-;; existing report renderer. The sentinel function is defined as
-;; follows, then was cleaned up using emacs' indenting. No other
-;; processing was done. Only the multichoice and boolean options for
-;; most reports were dumped. Although this cannot provide whole
-;; coverage for option permutations, it can catch many errors while
-;; refactoring inner functions.
-
-;; (define (mydump)
-;; (with-output-to-file "test-stress-optionslist.scm"
-;; (lambda ()
-;; (display "(define optionslist\n (list \n")
-;; (gnc:report-templates-for-each
-;; (lambda (report-id template)
-;; (let* ((options-generator (gnc:report-template-options-generator template))
-;; (name (gnc:report-template-name template))
-;; (options (and (not (string=? name "General Journal"))
-;; (options-generator))))
-;; (define (disp d)
-;; (define (try proc)
-;; (catch 'wrong-type-arg
-;; (lambda () (proc d))
-;; (const #f)))
-;; (or (and (symbol? d) (string-append "'" (symbol->string d)))
-;; (and (list? d) (string-append "(list " (string-join (map disp d) " ") ")"))
-;; (and (pair? d) (format #f "(cons ~a . ~a)"
-;; (disp (car d))
-;; (disp (cdr d))))
-;; (try gnc-commodity-get-mnemonic)
-;; (try xaccAccountGetName)
-;; (try gnc-budget-get-name)
-;; (format #f "~s" d)))
-;; (format #t "(list (cons 'report-id ~s)\n (cons 'report-name ~s)\n (cons 'options\n (list\n"
-;; report-id (gnc:report-template-name template))
-;; (if options
-;; (gnc:options-for-each
-;; (lambda (option)
-;; (if (memq (gnc:option-type option) '(multichoice boolean))
-;; (format #t " (vector ~s ~s '~s '~s)\n"
-;; (gnc:option-section option)
-;; (gnc:option-name option)
-;; (gnc:option-type option)
-;; (case (gnc:option-type option)
-;; ((multichoice) (map (lambda (d) (vector-ref d 0)) (gnc:option-data option)))
-;; ((boolean) (list #t #f))
-;; ;; (else "\"\"")
-;; (else (disp (gnc:option-value option)))))))
-;; options)
-;; )
-;; (display ")))\n"))))
-;; (display "))\n"))))
+(define optionslist '())
+(define (generate-optionslist)
+ (gnc:report-templates-for-each
+ (lambda (report-id template)
+ (let* ((options-generator (gnc:report-template-options-generator template))
+ (name (gnc:report-template-name template))
+ (options (options-generator)))
+ (set! optionslist
+ (cons (list (cons 'report-id report-id)
+ (cons 'report-name (gnc:report-template-name template))
+ (cons 'options (let ((report-options-tested '()))
+ (gnc:options-for-each
+ (lambda (option)
+ (when (memq (gnc:option-type option)
+ '(multichoice boolean))
+ (set! report-options-tested
+ (cons (vector
+ (gnc:option-section option)
+ (gnc:option-name option)
+ (gnc:option-type option)
+ (case (gnc:option-type option)
+ ((multichoice) (map (lambda (d) (vector-ref d 0))
+ (gnc:option-data option)))
+ ((boolean) (list #t #f))))
+ report-options-tested))))
+ options)
+ report-options-tested)))
+ optionslist))))))
;; Explicitly set locale to make the report output predictable
(setlocale LC_ALL "C")
@@ -87,6 +62,7 @@
(define (run-test)
(test-runner-factory gnc:test-runner)
(test-begin "stress options")
+ (generate-optionslist)
(tests)
(test-end "stress options"))
diff --git a/gnucash/report/standard-reports/test/test-stress-optionslist.scm b/gnucash/report/standard-reports/test/test-stress-optionslist.scm
deleted file mode 100644
index b9c0220..0000000
--- a/gnucash/report/standard-reports/test/test-stress-optionslist.scm
+++ /dev/null
@@ -1,972 +0,0 @@
-(define optionslist
- (list
- (list (cons 'report-id "e9cf815f79db44bcb637d0295093ae3d")
- (cons 'report-name "Assets Over Time")
- (cons 'options
- (list
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Chart Type" 'multichoice '(barchart linechart))
- (vector "Display" "Use Stacked Charts" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show long account names" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "e45218c6d76f11e7b5ef0800277ef320")
- (cons 'report-name "Reconciliation Report")
- (cons 'options
- (list
- (vector "Accounts" "Filter Type" 'multichoice '(none include exclude))
- (vector "Display" "Sign Reverses" 'multichoice '(global none income-expense credit-accounts))
- (vector "Display" "Description" 'boolean '(#t #f))
- (vector "Display" "Amount" 'multichoice '(none single double))
- (vector "Display" "Num" 'boolean '(#t #f))
- (vector "Display" "Shares" 'boolean '(#t #f))
- (vector "Display" "Use Full Account Name" 'boolean '(#t #f))
- (vector "Display" "Use Full Other Account Name" 'boolean '(#t #f))
- (vector "Display" "Detail Level" 'multichoice '(multi-line single))
- (vector "Display" "Account Code" 'boolean '(#t #f))
- (vector "Display" "Memo" 'boolean '(#t #f))
- (vector "Display" "Totals" 'boolean '(#t #f))
- (vector "Display" "Account Name" 'boolean '(#t #f))
- (vector "Display" "Other Account Name" 'boolean '(#t #f))
- (vector "Display" "Price" 'boolean '(#t #f))
- (vector "Display" "Other Account Code" 'boolean '(#t #f))
- (vector "Display" "Reconciled Date" 'boolean '(#t #f))
- (vector "Display" "Subtotal Table" 'boolean '(#t #f))
- (vector "Display" "Notes" 'boolean '(#t #f))
- (vector "Display" "Date" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Sort Order" 'multichoice '(ascend descend))
- (vector "Sorting" "Show Full Account Name" 'boolean '(#t #f))
- (vector "Sorting" "Show Account Code" 'boolean '(#t #f))
- (vector "Sorting" "Show Account Description" 'boolean '(#t #f))
- (vector "Sorting" "Primary Subtotal for Date Key" 'multichoice '(none daily weekly monthly quarterly yearly))
- (vector "Sorting" "Secondary Key" 'multichoice '(account-name account-code date reconciled-date reconciled-status register-order corresponding-acc-name corresponding-acc-code amount description number t-number memo notes none))
- (vector "Sorting" "Add indenting columns" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Subtotal" 'boolean '(#t #f))
- (vector "Sorting" "Primary Subtotal" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Subtotal for Date Key" 'multichoice '(none daily weekly monthly quarterly yearly))
- (vector "Sorting" "Primary Key" 'multichoice '(account-name account-code date reconciled-date reconciled-status register-order corresponding-acc-name corresponding-acc-code amount description number t-number memo notes none))
- (vector "Sorting" "Show Informal Debit/Credit Headers" 'boolean '(#t #f))
- (vector "Sorting" "Primary Sort Order" 'multichoice '(ascend descend))
- (vector "Sorting" "Show subtotals only (hide transactional data)" 'boolean '(#t #f))
- (vector "Filter" "Closing transactions" 'multichoice '(exclude-closing include-both closing-only))
- (vector "Filter" "Void Transactions" 'multichoice '(non-void-only void-only both))
- (vector "Filter" "Use regular expressions for transaction filter" 'boolean '(#t #f))
- (vector "Filter" "Use regular expressions for account name filter" 'boolean '(#t #f))
- (vector "Filter" "Reconcile Status" 'multichoice '(all unreconciled cleared reconciled))
- (vector "General" "Show original currency amount" 'boolean '(#t #f))
- (vector "General" "Table for Exporting" 'boolean '(#t #f))
- (vector "General" "Add options summary" 'multichoice '(no-match always never))
- (vector "General" "Common Currency" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "583c313fcc484efc974c4c844404f454")
- (cons 'report-name "Budget Income Statement")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Flatten list to depth limit" 'boolean '(#t #f))
- (vector "Display" "Display as a two column report" 'boolean '(#t #f))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Display" "Parent account balances" 'multichoice '(immediate-bal recursive-bal omit-bal))
- (vector "Display" "Display in standard, income first, order" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Label the revenue section" 'boolean '(#t #f))
- (vector "Display" "Parent account subtotals" 'multichoice '(t f canonically-tabbed))
- (vector "Display" "Include expense total" 'boolean '(#t #f))
- (vector "Display" "Omit zero balance figures" 'boolean '(#t #f))
- (vector "Display" "Include revenue total" 'boolean '(#t #f))
- (vector "Display" "Label the expense section" 'boolean '(#t #f))
- (vector "General" "Report for range of budget periods" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "4166a20981985fd2b07ff8cb3b7d384e")
- (cons 'report-name "Customer Summary")
- (cons 'options
- (list
- (vector "Display" "Sort Order" 'multichoice '(ascend descend))
- (vector "Display" "Show Inactive Customers" 'boolean '(#t #f))
- (vector "Display" "Show Lines with All Zeros" 'boolean '(#t #f))
- (vector "Display" "Show Expense Column" 'boolean '(#t #f))
- (vector "Display" "Sort Column" 'multichoice '(customername profit markup sales expense))
- (vector "Display" "Show Company Address" 'boolean '(#t #f))
- (vector "__reg" "reverse?" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "d8ba4a2e89e8479ca9f6eccdeb164588")
- (cons 'report-name "Multicolumn View")
- (cons 'options
- (list
- )))
- (list (cons 'report-id "216cd0cf6931453ebcce85415aba7082")
- (cons 'report-name "Trial Balance")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Entries" "Adjusting Entries Pattern is regular expression" 'boolean '(#t #f))
- (vector "Entries" "Closing Entries pattern is case-sensitive" 'boolean '(#t #f))
- (vector "Entries" "Adjusting Entries pattern is case-sensitive" 'boolean '(#t #f))
- (vector "Entries" "Closing Entries Pattern is regular expression" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "General" "Report variation" 'multichoice '(current pre-adj work-sheet))
- )))
- (list (cons 'report-id "47f45d7d6d57b68518481c1fc8d4e4ba")
- (cons 'report-name "Future Scheduled Transactions Summary")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Depth limit behavior" 'multichoice '(summarize flatten truncate))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Display" "Parent account balances" 'multichoice '(immediate-bal recursive-bal omit-bal))
- (vector "Display" "Account Description" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Parent account subtotals" 'multichoice '(t f canonically-tabbed))
- (vector "Display" "Account Code" 'boolean '(#t #f))
- (vector "Display" "Omit zero balance figures" 'boolean '(#t #f))
- (vector "Display" "Account Notes" 'boolean '(#t #f))
- (vector "Display" "Account Type" 'boolean '(#t #f))
- (vector "Display" "Account Balance" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "c2a996c8970f43448654ca84f17dda24")
- (cons 'report-name "Equity Statement")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Entries" "Closing Entries pattern is case-sensitive" 'boolean '(#t #f))
- (vector "Entries" "Closing Entries Pattern is regular expression" 'boolean '(#t #f))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "3dbbc2584da64e7a8674355bc3fbfe3d")
- (cons 'report-name "Australian Tax Invoice")
- (cons 'options
- (list
- (vector "Display" "table-border-collapse" 'boolean '(#t #f))
- (vector "Elements" "Show net price" 'boolean '(#t #f))
- (vector "Elements" "column: Units" 'boolean '(#t #f))
- (vector "Elements" "Show Job number" 'boolean '(#t #f))
- (vector "Elements" "row: Address" 'boolean '(#t #f))
- (vector "Elements" "column: Date" 'boolean '(#t #f))
- (vector "Elements" "column: Tax Rate" 'boolean '(#t #f))
- (vector "Elements" "Invoice number next to title" 'boolean '(#t #f))
- (vector "Elements" "row: Company Name" 'boolean '(#t #f))
- (vector "Elements" "row: Invoice Number" 'boolean '(#t #f))
- (vector "Elements" "Show Job name" 'boolean '(#t #f))
- (vector "Elements" "row: Contact" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "2e3751edeb7544e8a20fd19e9d08bb65")
- (cons 'report-name "Balance Sheet (eguile)")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Flatten list to depth limit" 'boolean '(#t #f))
- (vector "Accounts" "Exclude accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Negative amount format" 'multichoice '(negsign negbrackets))
- (vector "Display" "1- or 2-column report" 'multichoice '(autocols onecol twocols))
- )))
- (list (cons 'report-id "e9418ff64f2c11e5b61d1c7508d793ed")
- (cons 'report-name "Securities")
- (cons 'options
- (list
- (vector "Display" "Show Totals" 'boolean '(#t #f))
- (vector "Display" "Show long names" 'boolean '(#t #f))
- (vector "Display" "Show Percents" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- (list (cons 'report-id "e1bd09b8a1dd49dd85760db9d82b045c")
- (cons 'report-name "Income Accounts")
- (cons 'options
- (list
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Show Totals" 'boolean '(#t #f))
- (vector "Display" "Show long names" 'boolean '(#t #f))
- (vector "Display" "Show Percents" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "General" "Show Average" 'multichoice '(None YearDelta MonthDelta WeekDelta))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- (list (cons 'report-id "2e22929e5c5b4b769f615a815ef0c20f")
- (cons 'report-name "General Ledger")
- (cons 'options
- (list
- (vector "Accounts" "Filter Type" 'multichoice '(none include exclude))
- (vector "Display" "Sign Reverses" 'multichoice '(global none income-expense credit-accounts))
- (vector "Display" "Description" 'boolean '(#t #f))
- (vector "Display" "Amount" 'multichoice '(none single double))
- (vector "Display" "Num" 'boolean '(#t #f))
- (vector "Display" "Running Balance" 'boolean '(#t #f))
- (vector "Display" "Shares" 'boolean '(#t #f))
- (vector "Display" "Use Full Account Name" 'boolean '(#t #f))
- (vector "Display" "Use Full Other Account Name" 'boolean '(#t #f))
- (vector "Display" "Detail Level" 'multichoice '(multi-line single))
- (vector "Display" "Account Code" 'boolean '(#t #f))
- (vector "Display" "Memo" 'boolean '(#t #f))
- (vector "Display" "Totals" 'boolean '(#t #f))
- (vector "Display" "Account Name" 'boolean '(#t #f))
- (vector "Display" "Other Account Name" 'boolean '(#t #f))
- (vector "Display" "Price" 'boolean '(#t #f))
- (vector "Display" "Other Account Code" 'boolean '(#t #f))
- (vector "Display" "Reconciled Date" 'boolean '(#t #f))
- (vector "Display" "Subtotal Table" 'boolean '(#t #f))
- (vector "Display" "Notes" 'boolean '(#t #f))
- (vector "Display" "Date" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Sort Order" 'multichoice '(ascend descend))
- (vector "Sorting" "Show Full Account Name" 'boolean '(#t #f))
- (vector "Sorting" "Show Account Code" 'boolean '(#t #f))
- (vector "Sorting" "Show Account Description" 'boolean '(#t #f))
- (vector "Sorting" "Primary Subtotal for Date Key" 'multichoice '(none daily weekly monthly quarterly yearly))
- (vector "Sorting" "Secondary Key" 'multichoice '(account-name account-code date reconciled-date reconciled-status register-order corresponding-acc-name corresponding-acc-code amount description number t-number memo notes none))
- (vector "Sorting" "Add indenting columns" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Subtotal" 'boolean '(#t #f))
- (vector "Sorting" "Primary Subtotal" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Subtotal for Date Key" 'multichoice '(none daily weekly monthly quarterly yearly))
- (vector "Sorting" "Primary Key" 'multichoice '(account-name account-code date reconciled-date reconciled-status register-order corresponding-acc-name corresponding-acc-code amount description number t-number memo notes none))
- (vector "Sorting" "Show Informal Debit/Credit Headers" 'boolean '(#t #f))
- (vector "Sorting" "Primary Sort Order" 'multichoice '(ascend descend))
- (vector "Sorting" "Show subtotals only (hide transactional data)" 'boolean '(#t #f))
- (vector "Filter" "Closing transactions" 'multichoice '(exclude-closing include-both closing-only))
- (vector "Filter" "Void Transactions" 'multichoice '(non-void-only void-only both))
- (vector "Filter" "Use regular expressions for transaction filter" 'boolean '(#t #f))
- (vector "Filter" "Use regular expressions for account name filter" 'boolean '(#t #f))
- (vector "Filter" "Reconcile Status" 'multichoice '(all unreconciled cleared reconciled))
- (vector "General" "Stylesheet" 'multichoice '(Default Easy Footer #{Head or Tail}# Technicolor))
- (vector "General" "Show original currency amount" 'boolean '(#t #f))
- (vector "General" "Table for Exporting" 'boolean '(#t #f))
- (vector "General" "Add options summary" 'multichoice '(no-match always never))
- (vector "General" "Common Currency" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "9cf76bed17f14401b8e3e22d0079cb98")
- (cons 'report-name "Receivable Aging")
- (cons 'options
- (list
- (vector "Display" "Address Name" 'boolean '(#t #f))
- (vector "Display" "Address 1" 'boolean '(#t #f))
- (vector "Display" "Active" 'boolean '(#t #f))
- (vector "Display" "Address 2" 'boolean '(#t #f))
- (vector "Display" "Address 3" 'boolean '(#t #f))
- (vector "Display" "Address Source" 'multichoice '(billing shipping))
- (vector "Display" "Address Email" 'boolean '(#t #f))
- (vector "Display" "Address Phone" 'boolean '(#t #f))
- (vector "Display" "Address 4" 'boolean '(#t #f))
- (vector "Display" "Address Fax" 'boolean '(#t #f))
- (vector "General" "Sort By" 'multichoice '(name total oldest-bracket))
- (vector "General" "Show zero balance items" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Sort Order" 'multichoice '(increasing decreasing))
- (vector "General" "Due or Post Date" 'multichoice '(duedate postdate))
- (vector "General" "Show Multi-currency Totals" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "3ce293441e894423a2425d7a22dd1ac6")
- (cons 'report-name "Fancy Invoice")
- (cons 'options
- (list
- (vector "Display" "Payable to" 'boolean '(#t #f))
- (vector "Display" "Individual Taxes" 'boolean '(#t #f))
- (vector "Display" "Billing Terms" 'boolean '(#t #f))
- (vector "Display" "References" 'boolean '(#t #f))
- (vector "Display" "Totals" 'boolean '(#t #f))
- (vector "Display" "Invoice Notes" 'boolean '(#t #f))
- (vector "Display" "Billing ID" 'boolean '(#t #f))
- (vector "Display" "Payments" 'boolean '(#t #f))
- (vector "Display" "Company contact" 'boolean '(#t #f))
- (vector "Display Columns" "Tax Amount" 'boolean '(#t #f))
- (vector "Display Columns" "Description" 'boolean '(#t #f))
- (vector "Display Columns" "Discount" 'boolean '(#t #f))
- (vector "Display Columns" "Total" 'boolean '(#t #f))
- (vector "Display Columns" "Action" 'boolean '(#t #f))
- (vector "Display Columns" "Taxable" 'boolean '(#t #f))
- (vector "Display Columns" "Quantity" 'boolean '(#t #f))
- (vector "Display Columns" "Price" 'boolean '(#t #f))
- (vector "Display Columns" "Date" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "08ae9c2e884b4f9787144f47eacd7f44")
- (cons 'report-name "Employee Report")
- (cons 'options
- (list
- (vector "Display Columns" "Tax" 'boolean '(#t #f))
- (vector "Display Columns" "Description" 'boolean '(#t #f))
- (vector "Display Columns" "Amount" 'boolean '(#t #f))
- (vector "Display Columns" "Debits" 'boolean '(#t #f))
- (vector "Display Columns" "Type" 'boolean '(#t #f))
- (vector "Display Columns" "Due Date" 'boolean '(#t #f))
- (vector "Display Columns" "Sale" 'boolean '(#t #f))
- (vector "Display Columns" "Reference" 'boolean '(#t #f))
- (vector "Display Columns" "Credits" 'boolean '(#t #f))
- (vector "Display Columns" "Date" 'boolean '(#t #f))
- (vector "General" "Due or Post Date" 'multichoice '(duedate postdate))
- (vector "__reg" "reverse?" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "8758ba23984c40dea5527f5f0ca2779e")
- (cons 'report-name "Profit & Loss")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Flatten list to depth limit" 'boolean '(#t #f))
- (vector "Entries" "Closing Entries pattern is case-sensitive" 'boolean '(#t #f))
- (vector "Entries" "Closing Entries Pattern is regular expression" 'boolean '(#t #f))
- (vector "Display" "Display as a two column report" 'boolean '(#t #f))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Display" "Parent account balances" 'multichoice '(immediate-bal recursive-bal omit-bal))
- (vector "Display" "Display in standard, income first, order" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Label the revenue section" 'boolean '(#t #f))
- (vector "Display" "Parent account subtotals" 'multichoice '(t f canonically-tabbed))
- (vector "Display" "Include expense total" 'boolean '(#t #f))
- (vector "Display" "Include trading accounts total" 'boolean '(#t #f))
- (vector "Display" "Omit zero balance figures" 'boolean '(#t #f))
- (vector "Display" "Include revenue total" 'boolean '(#t #f))
- (vector "Display" "Label the expense section" 'boolean '(#t #f))
- (vector "Display" "Label the trading accounts section" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "c4173ac99b2b448289bf4d11c731af13")
- (cons 'report-name "Balance Sheet")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Flatten list to depth limit" 'boolean '(#t #f))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Display" "Parent account balances" 'multichoice '(immediate-bal recursive-bal omit-bal))
- (vector "Display" "Include assets total" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Parent account subtotals" 'multichoice '(t f canonically-tabbed))
- (vector "Display" "Include liabilities total" 'boolean '(#t #f))
- (vector "Display" "Label the liabilities section" 'boolean '(#t #f))
- (vector "Display" "Omit zero balance figures" 'boolean '(#t #f))
- (vector "Display" "Label the assets section" 'boolean '(#t #f))
- (vector "Display" "Include equity total" 'boolean '(#t #f))
- (vector "Display" "Label the equity section" 'boolean '(#t #f))
- (vector "General" "Single column Balance Sheet" 'boolean '(#t #f))
- (vector "General" "Use standard US layout" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "c146317be32e4948a561ec7fc89d15c1")
- (cons 'report-name "Customer Report")
- (cons 'options
- (list
- (vector "Display Columns" "Tax" 'boolean '(#t #f))
- (vector "Display Columns" "Description" 'boolean '(#t #f))
- (vector "Display Columns" "Amount" 'boolean '(#t #f))
- (vector "Display Columns" "Debits" 'boolean '(#t #f))
- (vector "Display Columns" "Type" 'boolean '(#t #f))
- (vector "Display Columns" "Due Date" 'boolean '(#t #f))
- (vector "Display Columns" "Sale" 'boolean '(#t #f))
- (vector "Display Columns" "Reference" 'boolean '(#t #f))
- (vector "Display Columns" "Credits" 'boolean '(#t #f))
- (vector "Display Columns" "Date" 'boolean '(#t #f))
- (vector "General" "Due or Post Date" 'multichoice '(duedate postdate))
- (vector "__reg" "reverse?" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "2fe3b9833af044abb929a88d5a59620f")
- (cons 'report-name "Transaction Report")
- (cons 'options
- (list
- (vector "Accounts" "Filter Type" 'multichoice '(none include exclude))
- (vector "Display" "Sign Reverses" 'multichoice '(global none income-expense credit-accounts))
- (vector "Display" "Description" 'boolean '(#t #f))
- (vector "Display" "Amount" 'multichoice '(none single double))
- (vector "Display" "Num" 'boolean '(#t #f))
- (vector "Display" "Running Balance" 'boolean '(#t #f))
- (vector "Display" "Shares" 'boolean '(#t #f))
- (vector "Display" "Use Full Account Name" 'boolean '(#t #f))
- (vector "Display" "Use Full Other Account Name" 'boolean '(#t #f))
- (vector "Display" "Detail Level" 'multichoice '(multi-line single))
- (vector "Display" "Account Code" 'boolean '(#t #f))
- (vector "Display" "Memo" 'boolean '(#t #f))
- (vector "Display" "Totals" 'boolean '(#t #f))
- (vector "Display" "Account Name" 'boolean '(#t #f))
- (vector "Display" "Other Account Name" 'boolean '(#t #f))
- (vector "Display" "Price" 'boolean '(#t #f))
- (vector "Display" "Other Account Code" 'boolean '(#t #f))
- (vector "Display" "Reconciled Date" 'boolean '(#t #f))
- (vector "Display" "Subtotal Table" 'boolean '(#t #f))
- (vector "Display" "Notes" 'boolean '(#t #f))
- (vector "Display" "Date" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Sort Order" 'multichoice '(ascend descend))
- (vector "Sorting" "Show Full Account Name" 'boolean '(#t #f))
- (vector "Sorting" "Show Account Code" 'boolean '(#t #f))
- (vector "Sorting" "Show Account Description" 'boolean '(#t #f))
- (vector "Sorting" "Primary Subtotal for Date Key" 'multichoice '(none daily weekly monthly quarterly yearly))
- (vector "Sorting" "Secondary Key" 'multichoice '(account-name account-code date reconciled-date reconciled-status register-order corresponding-acc-name corresponding-acc-code amount description number t-number memo notes none))
- (vector "Sorting" "Add indenting columns" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Subtotal" 'boolean '(#t #f))
- (vector "Sorting" "Primary Subtotal" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Subtotal for Date Key" 'multichoice '(none daily weekly monthly quarterly yearly))
- (vector "Sorting" "Primary Key" 'multichoice '(account-name account-code date reconciled-date reconciled-status register-order corresponding-acc-name corresponding-acc-code amount description number t-number memo notes none))
- (vector "Sorting" "Show Informal Debit/Credit Headers" 'boolean '(#t #f))
- (vector "Sorting" "Primary Sort Order" 'multichoice '(ascend descend))
- (vector "Sorting" "Show subtotals only (hide transactional data)" 'boolean '(#t #f))
- (vector "Filter" "Closing transactions" 'multichoice '(exclude-closing include-both closing-only))
- (vector "Filter" "Void Transactions" 'multichoice '(non-void-only void-only both))
- (vector "Filter" "Use regular expressions for transaction filter" 'boolean '(#t #f))
- (vector "Filter" "Use regular expressions for account name filter" 'boolean '(#t #f))
- (vector "Filter" "Reconcile Status" 'multichoice '(all unreconciled cleared reconciled))
- (vector "General" "Show original currency amount" 'boolean '(#t #f))
- (vector "General" "Table for Exporting" 'boolean '(#t #f))
- (vector "General" "Add options summary" 'multichoice '(no-match always never))
- (vector "General" "Common Currency" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "e57770f2dbca46619d6dac4ac5469b50")
- (cons 'report-name "Payable Aging")
- (cons 'options
- (list
- (vector "Display" "Address Name" 'boolean '(#t #f))
- (vector "Display" "Address 1" 'boolean '(#t #f))
- (vector "Display" "Active" 'boolean '(#t #f))
- (vector "Display" "Address 2" 'boolean '(#t #f))
- (vector "Display" "Address 3" 'boolean '(#t #f))
- (vector "Display" "Address Email" 'boolean '(#t #f))
- (vector "Display" "Address Phone" 'boolean '(#t #f))
- (vector "Display" "Address 4" 'boolean '(#t #f))
- (vector "Display" "Address Fax" 'boolean '(#t #f))
- (vector "General" "Sort By" 'multichoice '(name total oldest-bracket))
- (vector "General" "Show zero balance items" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Sort Order" 'multichoice '(increasing decreasing))
- (vector "General" "Due or Post Date" 'multichoice '(duedate postdate))
- (vector "General" "Show Multi-currency Totals" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "5426e4d987f6444387fe70880e5b28a0")
- (cons 'report-name "Cash Flow Barchart")
- (cons 'options
- (list
- (vector "Accounts" "Include Trading Accounts in report" 'boolean '(#t #f))
- (vector "Display" "Show Table" 'boolean '(#t #f))
- (vector "Display" "Show Money In" 'boolean '(#t #f))
- (vector "Display" "Show Money Out" 'boolean '(#t #f))
- (vector "Display" "Show Net Flow" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "0769e242be474010b4acf264a5512e6e")
- (cons 'report-name "Tax Invoice")
- (cons 'options
- (list
- (vector "Display" "table-border-collapse" 'boolean '(#t #f))
- (vector "Elements" "Show net price" 'boolean '(#t #f))
- (vector "Elements" "column: Units" 'boolean '(#t #f))
- (vector "Elements" "Show Job number" 'boolean '(#t #f))
- (vector "Elements" "row: Address" 'boolean '(#t #f))
- (vector "Elements" "column: Date" 'boolean '(#t #f))
- (vector "Elements" "column: Tax Rate" 'boolean '(#t #f))
- (vector "Elements" "Invoice number next to title" 'boolean '(#t #f))
- (vector "Elements" "row: Company Name" 'boolean '(#t #f))
- (vector "Elements" "row: Invoice Number" 'boolean '(#t #f))
- (vector "Elements" "Show Job name" 'boolean '(#t #f))
- (vector "Elements" "row: Contact" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "dde49fed4ca940959ae7d01b72742530")
- (cons 'report-name "Expenses vs. Day of Week")
- (cons 'options
- (list
- (vector "Accounts" "Include Sub-Accounts" 'boolean '(#t #f))
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Show Totals" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- (list (cons 'report-id "d5adcc61c62e4b8684dd8907448d7900")
- (cons 'report-name "Average Balance")
- (cons 'options
- (list
- (vector "Accounts" "Include Sub-Accounts" 'boolean '(#t #f))
- (vector "Accounts" "Exclude transactions between selected accounts" 'boolean '(#t #f))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show plot" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "25455562bd234dd0b048ecc5a8af9e43")
- (cons 'report-name "General Journal")
- (cons 'options
- (list
- )))
- (list (cons 'report-id "67112f318bef4fc496bdc27d106bbda4")
- (cons 'report-name "Easy Invoice")
- (cons 'options
- (list
- (vector "Display" "My Company" 'boolean '(#t #f))
- (vector "Display" "Subtotal" 'boolean '(#t #f))
- (vector "Display" "Individual Taxes" 'boolean '(#t #f))
- (vector "Display" "Billing Terms" 'boolean '(#t #f))
- (vector "Display" "Due Date" 'boolean '(#t #f))
- (vector "Display" "References" 'boolean '(#t #f))
- (vector "Display" "Totals" 'boolean '(#t #f))
- (vector "Display" "My Company ID" 'boolean '(#t #f))
- (vector "Display" "Invoice Notes" 'boolean '(#t #f))
- (vector "Display" "Billing ID" 'boolean '(#t #f))
- (vector "Display" "Payments" 'boolean '(#t #f))
- (vector "Display Columns" "Tax Amount" 'boolean '(#t #f))
- (vector "Display Columns" "Description" 'boolean '(#t #f))
- (vector "Display Columns" "Discount" 'boolean '(#t #f))
- (vector "Display Columns" "Total" 'boolean '(#t #f))
- (vector "Display Columns" "Charge Type" 'boolean '(#t #f))
- (vector "Display Columns" "Taxable" 'boolean '(#t #f))
- (vector "Display Columns" "Quantity" 'boolean '(#t #f))
- (vector "Display Columns" "Price" 'boolean '(#t #f))
- (vector "Display Columns" "Date" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "3298541c236b494998b236dfad6ad752")
- (cons 'report-name "Account Summary")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Depth limit behavior" 'multichoice '(summarize flatten truncate))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Display" "Parent account balances" 'multichoice '(immediate-bal recursive-bal omit-bal))
- (vector "Display" "Account Description" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Parent account subtotals" 'multichoice '(t f canonically-tabbed))
- (vector "Display" "Account Code" 'boolean '(#t #f))
- (vector "Display" "Omit zero balance figures" 'boolean '(#t #f))
- (vector "Display" "Account Notes" 'boolean '(#t #f))
- (vector "Display" "Account Type" 'boolean '(#t #f))
- (vector "Display" "Account Balance" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "80769921e87943adade887b9835a7685")
- (cons 'report-name "Income/Expense Chart")
- (cons 'options
- (list
- (vector "Display" "Show Income/Expense" 'boolean '(#t #f))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show Net Profit" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "f8921f4e5c284d7caca81e239f468a68")
- (cons 'report-name "Tax Schedule Report/TXF Export")
- (cons 'options
- (list
- (vector "Display" "Do not print transaction detail" 'boolean '(#t #f))
- (vector "Display" "Do not print Action:Memo data" 'boolean '(#t #f))
- (vector "Display" "Currency conversion date" 'multichoice '(conv-to-tran-date conv-to-report-date))
- (vector "Display" "Print TXF export parameters" 'boolean '(#t #f))
- (vector "Display" "Print all Transfer To/From Accounts" 'boolean '(#t #f))
- (vector "Display" "Suppress $0.00 values" 'boolean '(#t #f))
- (vector "Display" "Do not use special date processing" 'boolean '(#t #f))
- (vector "Display" "Do not print full account names" 'boolean '(#t #f))
- (vector "General" "Alternate Period" 'multichoice '(from-to #{1st-est}# #{2nd-est}# #{3rd-est}# #{4th-est}# last-year #{1st-last}# #{2nd-last}# #{3rd-last}# #{4th-last}#))
- )))
- (list (cons 'report-id "810ed4b25ef0486ea43bbd3dddb32b11")
- (cons 'report-name "Budget Report")
- (cons 'options
- (list
- (vector "Accounts" "Always show sub-accounts" 'boolean '(#t #f))
- (vector "Accounts" "Flatten list to depth limit" 'boolean '(#t #f))
- (vector "Accounts" "Account Display Depth" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Show Actual" 'boolean '(#t #f))
- (vector "Display" "Show Budget" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances and budget values" 'boolean '(#t #f))
- (vector "Display" "Roll up budget amounts to parent" 'boolean '(#t #f))
- (vector "Display" "Show Column with Totals" 'boolean '(#t #f))
- (vector "Display" "Show Difference" 'boolean '(#t #f))
- (vector "General" "Report for range of budget periods" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Range end" 'multichoice '(first previous current next last manual))
- (vector "General" "Include collapsed periods before selected." 'boolean '(#t #f))
- (vector "General" "Range start" 'multichoice '(first previous current next last manual))
- (vector "General" "Include collapsed periods after selected." 'boolean '(#t #f))
- (vector "General" "Show Full Account Names" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "cbba1696c8c24744848062c7f1cf4a72")
- (cons 'report-name "Net Worth Barchart")
- (cons 'options
- (list
- (vector "Display" "Show Asset & Liability" 'boolean '(#t #f))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show Net Worth" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "4a6b82e8678c4f3d9e85d9f09634ca89")
- (cons 'report-name "Investment Portfolio")
- (cons 'options
- (list
- (vector "Accounts" "Include accounts with no shares" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- (list (cons 'report-id "44f81bee049b4b3ea908f8dac9a9474e")
- (cons 'report-name "Income Over Time")
- (cons 'options
- (list
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Chart Type" 'multichoice '(barchart linechart))
- (vector "Display" "Use Stacked Charts" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show long account names" 'boolean '(#t #f))
- (vector "General" "Show Average" 'multichoice '(None MonthDelta WeekDelta DayDelta))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "5bf27f249a0d11e7abc4cec278b6b50a")
- (cons 'report-name "Income and GST Statement")
- (cons 'options
- (list
- (vector "Display" "Description" 'boolean '(#t #f))
- (vector "Display" "Num" 'boolean '(#t #f))
- (vector "Display" "Tax payable" 'boolean '(#t #f))
- (vector "Display" "Individual income columns" 'boolean '(#t #f))
- (vector "Display" "Use Full Account Name" 'boolean '(#t #f))
- (vector "Display" "Net Income" 'boolean '(#t #f))
- (vector "Display" "Use Full Other Account Name" 'boolean '(#t #f))
- (vector "Display" "Individual expense columns" 'boolean '(#t #f))
- (vector "Display" "Account Code" 'boolean '(#t #f))
- (vector "Display" "Individual tax columns" 'boolean '(#t #f))
- (vector "Display" "Remittance amount" 'boolean '(#t #f))
- (vector "Display" "Memo" 'boolean '(#t #f))
- (vector "Display" "Totals" 'boolean '(#t #f))
- (vector "Display" "Account Name" 'boolean '(#t #f))
- (vector "Display" "Other Account Name" 'boolean '(#t #f))
- (vector "Display" "Other Account Code" 'boolean '(#t #f))
- (vector "Display" "Reconciled Date" 'boolean '(#t #f))
- (vector "Display" "Subtotal Table" 'boolean '(#t #f))
- (vector "Display" "Notes" 'boolean '(#t #f))
- (vector "Display" "Date" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Sort Order" 'multichoice '(ascend descend))
- (vector "Sorting" "Show Full Account Name" 'boolean '(#t #f))
- (vector "Sorting" "Show Account Code" 'boolean '(#t #f))
- (vector "Sorting" "Show Account Description" 'boolean '(#t #f))
- (vector "Sorting" "Primary Subtotal for Date Key" 'multichoice '(none daily weekly monthly quarterly yearly))
- (vector "Sorting" "Secondary Key" 'multichoice '(account-name account-code date reconciled-date reconciled-status register-order corresponding-acc-name corresponding-acc-code amount description number t-number memo notes none))
- (vector "Sorting" "Add indenting columns" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Subtotal" 'boolean '(#t #f))
- (vector "Sorting" "Primary Subtotal" 'boolean '(#t #f))
- (vector "Sorting" "Secondary Subtotal for Date Key" 'multichoice '(none daily weekly monthly quarterly yearly))
- (vector "Sorting" "Primary Key" 'multichoice '(account-name account-code date reconciled-date reconciled-status register-order corresponding-acc-name corresponding-acc-code amount description number t-number memo notes none))
- (vector "Sorting" "Primary Sort Order" 'multichoice '(ascend descend))
- (vector "Sorting" "Show subtotals only (hide transactional data)" 'boolean '(#t #f))
- (vector "Filter" "Void Transactions" 'multichoice '(non-void-only void-only both))
- (vector "Filter" "Use regular expressions for transaction filter" 'boolean '(#t #f))
- (vector "Filter" "Use regular expressions for account name filter" 'boolean '(#t #f))
- (vector "Filter" "Reconcile Status" 'multichoice '(all unreconciled cleared reconciled))
- (vector "General" "Table for Exporting" 'boolean '(#t #f))
- (vector "General" "Add options summary" 'multichoice '(no-match always never))
- (vector "General" "Common Currency" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "3fe6dce77da24c66bdc8f8efdea7f9ac")
- (cons 'report-name "Liabilities")
- (cons 'options
- (list
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Show Totals" 'boolean '(#t #f))
- (vector "Display" "Show long names" 'boolean '(#t #f))
- (vector "Display" "Show Percents" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- (list (cons 'report-id "5123a759ceb9483abf2182d01c140e8d")
- (cons 'report-name "Printable Invoice")
- (cons 'options
- (list
- (vector "Display" "Individual Taxes" 'boolean '(#t #f))
- (vector "Display" "Billing Terms" 'boolean '(#t #f))
- (vector "Display" "References" 'boolean '(#t #f))
- (vector "Display" "Totals" 'boolean '(#t #f))
- (vector "Display" "Invoice Notes" 'boolean '(#t #f))
- (vector "Display" "Billing ID" 'boolean '(#t #f))
- (vector "Display" "Payments" 'boolean '(#t #f))
- (vector "Display" "Job Details" 'boolean '(#t #f))
- (vector "Display Columns" "Tax Amount" 'boolean '(#t #f))
- (vector "Display Columns" "Description" 'boolean '(#t #f))
- (vector "Display Columns" "Discount" 'boolean '(#t #f))
- (vector "Display Columns" "Total" 'boolean '(#t #f))
- (vector "Display Columns" "Action" 'boolean '(#t #f))
- (vector "Display Columns" "Taxable" 'boolean '(#t #f))
- (vector "Display Columns" "Quantity" 'boolean '(#t #f))
- (vector "Display Columns" "Price" 'boolean '(#t #f))
- (vector "Display Columns" "Date" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "21d7cfc59fc74f22887596ebde7e462d")
- (cons 'report-name "Advanced Portfolio")
- (cons 'options
- (list
- (vector "Accounts" "Include accounts with no shares" 'boolean '(#t #f))
- (vector "Display" "Show ticker symbols" 'boolean '(#t #f))
- (vector "Display" "Show number of shares" 'boolean '(#t #f))
- (vector "Display" "Show prices" 'boolean '(#t #f))
- (vector "Display" "Show listings" 'boolean '(#t #f))
- (vector "General" "How to report brokerage fees" 'multichoice '(include-in-basis include-in-gain ignore-brokerage))
- (vector "General" "Price Source" 'multichoice '(pricedb-latest pricedb-nearest))
- (vector "General" "Basis calculation method" 'multichoice '(average-basis fifo-basis filo-basis))
- (vector "General" "Set preference for price list data" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "7eb3df21073d4c33920a0257da15fba5")
- (cons 'report-name "Receipt")
- (cons 'options
- (list
- )))
- (list (cons 'report-id "e6e34fa3b6e748debde3cb3bc76d3e53")
- (cons 'report-name "Budget Flow")
- (cons 'options
- (list
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- (list (cons 'report-id "b1f15b2052c149df93e698fe85a81ea6")
- (cons 'report-name "Expense Over Time")
- (cons 'options
- (list
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Chart Type" 'multichoice '(barchart linechart))
- (vector "Display" "Use Stacked Charts" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show long account names" 'boolean '(#t #f))
- (vector "General" "Show Average" 'multichoice '(None MonthDelta WeekDelta DayDelta))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "898d78ec92854402bf76e20a36d24ade")
- (cons 'report-name "Hello, World")
- (cons 'options
- (list
- (vector "Hello, World!" "Multi Choice Option" 'multichoice '(first second third fourth))
- (vector "Hello, World!" "Boolean Option" 'boolean '(#t #f))
- (vector "Testing" "Crash the report" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "5e2d129f28d14df881c3e47e3053f604")
- (cons 'report-name "Income vs. Day of Week")
- (cons 'options
- (list
- (vector "Accounts" "Include Sub-Accounts" 'boolean '(#t #f))
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Show Totals" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- (list (cons 'report-id "faf410e8f8da481fbc09e4763da40bcc")
- (cons 'report-name "Liabilities Over Time")
- (cons 'options
- (list
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Chart Type" 'multichoice '(barchart linechart))
- (vector "Display" "Use Stacked Charts" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show long account names" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "0b81a3bdfd504aff849ec2e8630524bc")
- (cons 'report-name "Income Statement")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Flatten list to depth limit" 'boolean '(#t #f))
- (vector "Entries" "Closing Entries pattern is case-sensitive" 'boolean '(#t #f))
- (vector "Entries" "Closing Entries Pattern is regular expression" 'boolean '(#t #f))
- (vector "Display" "Display as a two column report" 'boolean '(#t #f))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Display" "Parent account balances" 'multichoice '(immediate-bal recursive-bal omit-bal))
- (vector "Display" "Display in standard, income first, order" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Label the revenue section" 'boolean '(#t #f))
- (vector "Display" "Parent account subtotals" 'multichoice '(t f canonically-tabbed))
- (vector "Display" "Include expense total" 'boolean '(#t #f))
- (vector "Display" "Include trading accounts total" 'boolean '(#t #f))
- (vector "Display" "Omit zero balance figures" 'boolean '(#t #f))
- (vector "Display" "Include revenue total" 'boolean '(#t #f))
- (vector "Display" "Label the expense section" 'boolean '(#t #f))
- (vector "Display" "Label the trading accounts section" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "415cd38d39054d9e9c4040455290c2b1")
- (cons 'report-name "Budget Chart")
- (cons 'options
- (list
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Chart Type" 'multichoice '(bars lines))
- (vector "Display" "Running Sum" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "f8748b813fab4220ba26e743aedf38da")
- (cons 'report-name "Cash Flow")
- (cons 'options
- (list
- (vector "Accounts" "Always show sub-accounts" 'boolean '(#t #f))
- (vector "Accounts" "Include Trading Accounts in report" 'boolean '(#t #f))
- (vector "Accounts" "Account Display Depth" 'multichoice '(all 1 2 3 4 5 6))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "General" "Show Full Account Names" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "65135608f2014c6ca8412793a8cdf169")
- (cons 'report-name "Welcome to GnuCash")
- (cons 'options
- (list
- )))
- (list (cons 'report-id "d7d1e53505ee4b1b82efad9eacedaea0")
- (cons 'report-name "Vendor Report")
- (cons 'options
- (list
- (vector "Display Columns" "Tax" 'boolean '(#t #f))
- (vector "Display Columns" "Description" 'boolean '(#t #f))
- (vector "Display Columns" "Amount" 'boolean '(#t #f))
- (vector "Display Columns" "Debits" 'boolean '(#t #f))
- (vector "Display Columns" "Type" 'boolean '(#t #f))
- (vector "Display Columns" "Due Date" 'boolean '(#t #f))
- (vector "Display Columns" "Sale" 'boolean '(#t #f))
- (vector "Display Columns" "Reference" 'boolean '(#t #f))
- (vector "Display Columns" "Credits" 'boolean '(#t #f))
- (vector "Display Columns" "Date" 'boolean '(#t #f))
- (vector "General" "Due or Post Date" 'multichoice '(duedate postdate))
- (vector "__reg" "reverse?" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "5518ac227e474f47a34439f2d4d049de")
- (cons 'report-name "Job Report")
- (cons 'options
- (list
- (vector "Display Columns" "Description" 'boolean '(#t #f))
- (vector "Display Columns" "Amount" 'boolean '(#t #f))
- (vector "Display Columns" "Type" 'boolean '(#t #f))
- (vector "Display Columns" "Due Date" 'boolean '(#t #f))
- (vector "Display Columns" "Reference" 'boolean '(#t #f))
- (vector "Display Columns" "Date" 'boolean '(#t #f))
- (vector "__reg" "reverse?" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "e5fa5ce805e840ecbeca4dba3fa4ead9")
- (cons 'report-name "Budget Profit & Loss")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Flatten list to depth limit" 'boolean '(#t #f))
- (vector "Display" "Display as a two column report" 'boolean '(#t #f))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Display" "Parent account balances" 'multichoice '(immediate-bal recursive-bal omit-bal))
- (vector "Display" "Display in standard, income first, order" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Label the revenue section" 'boolean '(#t #f))
- (vector "Display" "Parent account subtotals" 'multichoice '(t f canonically-tabbed))
- (vector "Display" "Include expense total" 'boolean '(#t #f))
- (vector "Display" "Omit zero balance figures" 'boolean '(#t #f))
- (vector "Display" "Include revenue total" 'boolean '(#t #f))
- (vector "Display" "Label the expense section" 'boolean '(#t #f))
- (vector "General" "Report for range of budget periods" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "e533c998186b11e1b2e2001558291366")
- (cons 'report-name "Income & Expense Linechart")
- (cons 'options
- (list
- (vector "Display" "Grid" 'boolean '(#t #f))
- (vector "Display" "Data markers?" 'boolean '(#t #f))
- (vector "Display" "Show Income/Expense" 'boolean '(#t #f))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show Net Profit" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "22104e02654c4adba844ee75a3f8d173")
- (cons 'report-name "Register")
- (cons 'options
- (list
- (vector "Display" "Description" 'boolean '(#t #f))
- (vector "Display" "Account" 'boolean '(#t #f))
- (vector "Display" "Amount" 'multichoice '(single double))
- (vector "Display" "Num" 'boolean '(#t #f))
- (vector "Display" "Running Balance" 'boolean '(#t #f))
- (vector "Display" "Shares" 'boolean '(#t #f))
- (vector "Display" "Lot" 'boolean '(#t #f))
- (vector "Display" "Memo" 'boolean '(#t #f))
- (vector "Display" "Totals" 'boolean '(#t #f))
- (vector "Display" "Price" 'boolean '(#t #f))
- (vector "Display" "Date" 'boolean '(#t #f))
- (vector "Display" "Value" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "d8b63264186b11e19038001558291366")
- (cons 'report-name "Net Worth Linechart")
- (cons 'options
- (list
- (vector "Display" "Grid" 'boolean '(#t #f))
- (vector "Display" "Show Asset & Liability" 'boolean '(#t #f))
- (vector "Display" "Data markers?" 'boolean '(#t #f))
- (vector "Display" "Show table" 'boolean '(#t #f))
- (vector "Display" "Show Net Worth" 'boolean '(#t #f))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "1d241609fd4644caad765c95be20ff4c")
- (cons 'report-name "Price")
- (cons 'options
- (list
- (vector "Display" "Marker" 'multichoice '(diamond circle square cross plus dash filleddiamond filledcircle filledsquare))
- (vector "Price" "Invert prices" 'boolean '(#t #f))
- (vector "Price" "Price Source" 'multichoice '(weighted-average actual-transactions pricedb))
- (vector "General" "Step Size" 'multichoice '(DayDelta WeekDelta TwoWeekDelta MonthDelta QuarterDelta HalfYearDelta YearDelta))
- )))
- (list (cons 'report-id "ecc35ea9dbfa4e20ba389fc85d59cb69")
- (cons 'report-name "Budget Balance Sheet")
- (cons 'options
- (list
- (vector "Commodities" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- (vector "Commodities" "Show Exchange Rates" 'boolean '(#t #f))
- (vector "Commodities" "Show Foreign Currencies" 'boolean '(#t #f))
- (vector "Accounts" "Levels of Subaccounts" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Accounts" "Flatten list to depth limit" 'boolean '(#t #f))
- (vector "Display" "Show accounting-style rules" 'boolean '(#t #f))
- (vector "Display" "Display accounts as hyperlinks" 'boolean '(#t #f))
- (vector "Display" "Parent account balances" 'multichoice '(immediate-bal recursive-bal omit-bal))
- (vector "Display" "Include assets total" 'boolean '(#t #f))
- (vector "Display" "Include accounts with zero total balances" 'boolean '(#t #f))
- (vector "Display" "Parent account subtotals" 'multichoice '(t f canonically-tabbed))
- (vector "Display" "Include liabilities total" 'boolean '(#t #f))
- (vector "Display" "Label the liabilities section" 'boolean '(#t #f))
- (vector "Display" "Include new/existing totals" 'boolean '(#t #f))
- (vector "Display" "Omit zero balance figures" 'boolean '(#t #f))
- (vector "Display" "Label the assets section" 'boolean '(#t #f))
- (vector "Display" "Include equity total" 'boolean '(#t #f))
- (vector "Display" "Label the equity section" 'boolean '(#t #f))
- (vector "General" "Single column Balance Sheet" 'boolean '(#t #f))
- )))
- (list (cons 'report-id "5c7fd8a1fe9a4cd38884ff54214aa88a")
- (cons 'report-name "Assets")
- (cons 'options
- (list
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Show Totals" 'boolean '(#t #f))
- (vector "Display" "Show long names" 'boolean '(#t #f))
- (vector "Display" "Show Percents" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- (list (cons 'report-id "9bf1892805cb4336be6320fe48ce5446")
- (cons 'report-name "Expense Accounts")
- (cons 'options
- (list
- (vector "Accounts" "Show Accounts until level" 'multichoice '(all 1 2 3 4 5 6))
- (vector "Display" "Show Totals" 'boolean '(#t #f))
- (vector "Display" "Show long names" 'boolean '(#t #f))
- (vector "Display" "Show Percents" 'boolean '(#t #f))
- (vector "Display" "Sort Method" 'multichoice '(acct-code alphabetical amount))
- (vector "General" "Show Average" 'multichoice '(None YearDelta MonthDelta WeekDelta))
- (vector "General" "Price Source" 'multichoice '(average-cost weighted-average pricedb-latest pricedb-nearest))
- )))
- ))
commit 47ad60c7235503134f6c1b8cdde232db2b507d48
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jul 31 11:22:07 2018 +0800
[test-balsheet-pnl] add more SELL transactions
this is to thoroughly test average-cost and weighted-average
diff --git a/gnucash/report/standard-reports/test/test-balsheet-pnl.scm b/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
index d02cb48..954798e 100644
--- a/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
@@ -125,8 +125,10 @@
;; pre-existing GBPs
(env-transfer-foreign env 01 01 1970 bank1current foreignsavings 130 100 #:description "buy 100GBP at $1.30")
(env-transfer-foreign env 01 02 1970 bank1current foreignsavings 140 100 #:description "buy 100GBP at $1.40")
+ (env-transfer-foreign env 15 02 1970 bank1current foreignsavings -142 -100 #:description "sell 100GBP at $1.42")
(env-transfer-foreign env 01 03 1970 bank1current foreignsavings 150 100 #:description "buy 100GBP at $1.50")
(env-transfer-foreign env 01 04 1970 bank1current foreignsavings 155 100 #:description "buy 100GBP at $1.55")
+ (env-transfer-foreign env 15 04 1970 bank1current foreignsavings -157 -100 #:description "sell 100GBP at $1.57")
(env-transfer-foreign env 01 05 1970 bank1current foreignsavings -160 -100 #:description "sell 100GBP at $1.60")
(env-transfer-foreign env 01 06 1970 bank1current foreignsavings 155 100 #:description "buy 100GBP at $1.55")
(env-transfer-foreign env 01 07 1970 bank1current foreignsavings -145 -100 #:description "sell 100GBP at $1.45")
@@ -168,25 +170,25 @@
(env-transfer env 01 01 1980 income bank1current 250)
(env-transfer env 01 01 1980 income-GBP foreignsavings 500)
(env-transfer-foreign env 01 02 1980 income-GBP bank1current 100 170 #:description "earn 100GBP into $170")
-
+
;; Finally we can begin testing balsheet
(display "\n\n balsheet tests\n\n")
(let* ((balance-sheet-options (default-balsheet-testing-options))
(sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-default")))
- (test-equal "total assets = $116,010"
- (list "$116,010.00")
+ (test-equal "total assets = $116,009"
+ (list "$116,009.00")
(sxml->table-row-col sxml 1 15 6))
(test-equal "total liabilities = $9,500.00"
(list "$9,500.00")
(sxml->table-row-col sxml 1 23 6))
- (test-equal "total equity = $106,510.00"
- (list "$106,510.00")
+ (test-equal "total equity = $106,509.00"
+ (list "$106,509.00")
(sxml->table-row-col sxml 1 28 6))
(set-option! balance-sheet-options "Commodities" "Price Source" 'weighted-average)
(let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-weighted-average")))
- (test-equal "weighted average assets = $114,072.86"
- (list "$114,072.86")
+ (test-equal "weighted average assets = $114,071.66"
+ (list "$114,071.66")
(sxml->table-row-col sxml 1 15 6)))
(set-option! balance-sheet-options "Commodities" "Price Source" 'average-cost)
@@ -197,14 +199,14 @@
(set-option! balance-sheet-options "Commodities" "Price Source" 'pricedb-nearest)
(let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-pricedb-nearest")))
- (test-equal "pricedb-nearest assets = $116,010"
- (list "$116,010.00")
+ (test-equal "pricedb-nearest assets = $116,009"
+ (list "$116,009.00")
(sxml->table-row-col sxml 1 15 6)))
(set-option! balance-sheet-options "Commodities" "Price Source" 'pricedb-latest)
(let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-pricedb-latest")))
- (test-equal "pricedb-latest assets = $122,090"
- (list "$122,090.00")
+ (test-equal "pricedb-latest assets = $122,049"
+ (list "$122,049.00")
(sxml->table-row-col sxml 1 15 6)))
;; set multilevel subtotal style
@@ -224,8 +226,8 @@
(test-equal "multilevel. bonds = $2,000.00"
(list "$2,000.00")
(sxml->table-row-col sxml 1 6 3))
- (test-equal "multilevel. current = $2310.00"
- (list "$2,310.00")
+ (test-equal "multilevel. current = $2609.00"
+ (list "$2,609.00")
(sxml->table-row-col sxml 1 7 3))
(test-equal "multilevel. empty = $0.00"
(list "$0.00")
@@ -233,8 +235,8 @@
(test-equal "multilevel. savings = $100.00"
(list "$100.00")
(sxml->table-row-col sxml 1 9 3))
- (test-equal "multilevel. total bank1 = $4,410"
- (list "$4,410.00")
+ (test-equal "multilevel. total bank1 = $4709"
+ (list "$4,709.00")
(sxml->table-row-col sxml 1 10 4))
(test-equal "multilevel. broker = $2,000.00"
(list "$2,000.00")
@@ -248,23 +250,23 @@
(test-equal "multilevel. foreign = $0.00"
(list "$0.00")
(sxml->table-row-col sxml 1 14 3))
- (test-equal "multilevel. foreignsavings = #400.00 = $680"
- (list "#400.00" "$680.00" "$680.00")
+ (test-equal "multilevel. foreignsavings = #200.00 = $340"
+ (list "#200.00" "$340.00" "$340.00")
(sxml->table-row-col sxml 1 15 3))
- (test-equal "multilevel. total foreign = $680"
- (list "$680.00")
+ (test-equal "multilevel. total foreign = $340"
+ (list "$340.00")
(sxml->table-row-col sxml 1 16 4))
(test-equal "multilevel. house = $100,000"
(list "$100,000.00")
(sxml->table-row-col sxml 1 17 4))
- (test-equal "multilevel. total asset = $122,090"
- (list "$122,090.00")
+ (test-equal "multilevel. total asset = $122,049"
+ (list "$122,049.00")
(sxml->table-row-col sxml 1 18 5))
- (test-equal "multilevel. total root = $122,090"
- (list "$122,090.00")
+ (test-equal "multilevel. total root = $122,049"
+ (list "$122,049.00")
(sxml->table-row-col sxml 1 19 6))
- (test-equal "multilevel. total assets = $122,090"
- (list "$122,090.00")
+ (test-equal "multilevel. total assets = $122,049"
+ (list "$122,049.00")
(sxml->table-row-col sxml 1 20 6)))
;; set recursive-subtotal subtotal style
@@ -272,19 +274,19 @@
(set-option! balance-sheet-options "Display" "Parent account subtotals" 'f)
(let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-recursive")))
(test-equal "recursive. root = $760+15000+104600"
- (list "#400.00" "$680.00" "30 FUNDS" "$15,000.00" "$106,410.00" "$106,410.00")
+ (list "#200.00" "$340.00" "30 FUNDS" "$15,000.00" "$106,709.00" "$106,709.00")
(sxml->table-row-col sxml 1 3 6))
(test-equal "recursive. assets = $760+15000+104600"
- (list "#400.00" "$680.00" "30 FUNDS" "$15,000.00" "$106,410.00" "$106,410.00")
+ (list "#200.00" "$340.00" "30 FUNDS" "$15,000.00" "$106,709.00" "$106,709.00")
(sxml->table-row-col sxml 1 4 5))
- (test-equal "recursive. bank1 = $4,410.00"
- (list "$4,410.00")
+ (test-equal "recursive. bank1 = $4,709.00"
+ (list "$4,709.00")
(sxml->table-row-col sxml 1 5 4))
(test-equal "recursive. bonds = $2,000.00"
(list "$2,000.00")
(sxml->table-row-col sxml 1 6 3))
- (test-equal "recursive. current = $2310.00"
- (list "$2,310.00")
+ (test-equal "recursive. current = $2609.00"
+ (list "$2,609.00")
(sxml->table-row-col sxml 1 7 3))
(test-equal "recursive. empty = $0.00"
(list "$0.00")
@@ -298,24 +300,24 @@
(test-equal "recursive. funds = $15,000.00"
(list "30 FUNDS" "$15,000.00" "$15,000.00")
(sxml->table-row-col sxml 1 11 3))
- (test-equal "recursive. foreign = $680.00"
- (list "#400.00" "$680.00")
+ (test-equal "recursive. foreign = $340.00"
+ (list "#200.00" "$340.00")
(sxml->table-row-col sxml 1 12 4))
- (test-equal "recursive. foreignsavings = #400.00 = $760"
- (list "#400.00" "$680.00" "$680.00")
+ (test-equal "recursive. foreignsavings = #200.00 = $340"
+ (list "#200.00" "$340.00" "$340.00")
(sxml->table-row-col sxml 1 13 3))
(test-equal "recursive. house = $100,000"
(list "$100,000.00")
(sxml->table-row-col sxml 1 14 4))
- (test-equal "recursive. total assets = $122,090.00"
- (list "$122,090.00")
+ (test-equal "recursive. total assets = $122,049.00"
+ (list "$122,049.00")
(sxml->table-row-col sxml 1 15 6)))
(set-option! balance-sheet-options "Commodities" "Show Foreign Currencies" #f)
(set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #f)
(let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-disable show-fcur show-rates")))
(test-equal "show-fcur disabled"
- (list "$122,090.00")
+ (list "$122,049.00")
(sxml->table-row-col sxml 1 3 6))
(test-equal "show-rates disabled"
'()
@@ -325,7 +327,7 @@
(set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #t)
(let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-enable show-fcur show-rates")))
(test-equal "show-fcur enabled"
- (list "#400.00" "$680.00" "30 FUNDS" "$15,000.00" "$106,410.00" "$106,410.00")
+ (list "#200.00" "$340.00" "30 FUNDS" "$15,000.00" "$106,709.00" "$106,709.00")
(sxml->table-row-col sxml 1 3 6))
(test-equal "show-rates enabled"
(list "1 FUNDS" "$500.00" "#1.00" "$1.70")
@@ -368,14 +370,14 @@
(set-option! pnl-options "Commodities" "Price Source" 'weighted-average)
(let ((sxml (options->sxml pnl-uuid pnl-options "pnl-weighted-average")))
- (test-equal "weighted average revenue = $1163.33"
- (list "$1,163.33" "$1,163.33")
+ (test-equal "weighted average revenue = $1160.36"
+ (list "$1,160.36" "$1,160.36")
(sxml->table-row-col sxml 1 5 6)))
(set-option! pnl-options "Commodities" "Price Source" 'average-cost)
(let ((sxml (options->sxml pnl-uuid pnl-options "pnl-average-cost")))
- (test-equal "average-cost revenue = $1,090"
- (list "$1,090.00" "$1,090.00")
+ (test-equal "average-cost revenue = $976"
+ (list "$976.00" "$976.00")
(sxml->table-row-col sxml 1 5 6)))
(set-option! pnl-options "Commodities" "Price Source" 'pricedb-nearest)
commit 58ae3f2a89f2e3ec6d818234aa1d874fd16bb446
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jul 24 09:29:55 2018 +0800
[test-balsheet-pnl] add income-statement tests
diff --git a/gnucash/report/standard-reports/test/test-balsheet-pnl.scm b/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
index 8a13dc4..d02cb48 100644
--- a/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
@@ -2,6 +2,7 @@
(gnc:module-begin-syntax (gnc:module-load "gnucash/app-utils" 0))
(use-modules (gnucash engine test test-extras))
(use-modules (gnucash report standard-reports balance-sheet))
+(use-modules (gnucash report standard-reports income-statement))
(use-modules (gnucash report stylesheets))
(use-modules (gnucash report report-system))
(use-modules (gnucash report report-system test test-extras))
@@ -10,19 +11,20 @@
(use-modules (sxml simple))
(use-modules (sxml xpath))
-;; This is implementation testing for Balance Sheet.
+;; This is implementation testing for Balance Sheet and Profit&Loss.
(define balance-sheet-uuid "c4173ac99b2b448289bf4d11c731af13")
+(define pnl-uuid "0b81a3bdfd504aff849ec2e8630524bc")
;; Explicitly set locale to make the report output predictable
(setlocale LC_ALL "C")
(define (run-test)
(test-runner-factory gnc:test-runner)
- (test-begin "balsheet.scm")
+ (test-begin "balsheet and profit&loss")
(null-test)
- (balsheet-tests)
- (test-end "balsheet.scm"))
+ (balsheet-pnl-tests)
+ (test-end "balsheet and profit&loss"))
(define (options->sxml uuid options test-title)
(gnc:options->sxml uuid options "test-balsheet-pnl" test-title))
@@ -78,7 +80,7 @@
(let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid)))
(test-assert "null-test" (options->sxml balance-sheet-uuid balance-sheet-options "null-test"))))
-(define (balsheet-tests)
+(define (balsheet-pnl-tests)
;; This function will perform implementation testing on the transaction report.
(let* ((env (create-test-env))
(account-alist (env-create-account-structure-alist env structure))
@@ -103,6 +105,14 @@
(set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #t)
balance-sheet-options))
+ (define (default-pnl-testing-options)
+ (let ((pnl-options (gnc:make-report-options pnl-uuid)))
+ (set-option! pnl-options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 1 1 1980)))
+ (set-option! pnl-options "General" "End Date" (cons 'absolute (gnc-dmy2time64 1 1 1981)))
+ (set-option! pnl-options "Accounts" "Levels of Subaccounts" 'all)
+ (set-option! pnl-options "Commodities" "Show Exchange Rates" #t)
+ pnl-options))
+
;; $100 in Savings account
(env-transfer env 01 01 1970 equity bank1savings 100)
;; $2000 in Bonds
@@ -159,7 +169,8 @@
(env-transfer env 01 01 1980 income-GBP foreignsavings 500)
(env-transfer-foreign env 01 02 1980 income-GBP bank1current 100 170 #:description "earn 100GBP into $170")
- ;; Finally we can begin testing
+ ;; Finally we can begin testing balsheet
+ (display "\n\n balsheet tests\n\n")
(let* ((balance-sheet-options (default-balsheet-testing-options))
(sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-default")))
(test-equal "total assets = $116,010"
@@ -343,4 +354,101 @@
(test-equal "incl-zb-accts=#t"
'("Empty" "$0.00")
(sxml->table-row-col sxml 1 8 #f)))
+ )
+
+ (display "\n\n pnl tests\n\n")
+ (let* ((pnl-options (default-pnl-testing-options))
+ (sxml (options->sxml pnl-uuid pnl-options "pnl-default")))
+ (test-equal "total revenue = $1,270.00"
+ (list "$1,270.00" "$1,270.00")
+ (sxml->table-row-col sxml 1 5 6))
+ (test-equal "total expenses = $0.00"
+ (list "$0.00" "$0.00")
+ (sxml->table-row-col sxml 1 3 6))
+
+ (set-option! pnl-options "Commodities" "Price Source" 'weighted-average)
+ (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-weighted-average")))
+ (test-equal "weighted average revenue = $1163.33"
+ (list "$1,163.33" "$1,163.33")
+ (sxml->table-row-col sxml 1 5 6)))
+
+ (set-option! pnl-options "Commodities" "Price Source" 'average-cost)
+ (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-average-cost")))
+ (test-equal "average-cost revenue = $1,090"
+ (list "$1,090.00" "$1,090.00")
+ (sxml->table-row-col sxml 1 5 6)))
+
+ (set-option! pnl-options "Commodities" "Price Source" 'pricedb-nearest)
+ (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-pricedb-nearest")))
+ (test-equal "pricedb-nearest revenue = $1270"
+ (list "$1,270.00" "$1,270.00")
+ (sxml->table-row-col sxml 1 5 6)))
+
+ (set-option! pnl-options "Commodities" "Price Source" 'pricedb-latest)
+ (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-pricedb-latest")))
+ (test-equal "pricedb-latest revenue = $1270"
+ (list "$1,270.00" "$1,270.00")
+ (sxml->table-row-col sxml 1 5 6)))
+
+ ;; set multilevel subtotal style
+ ;; verifies amount in EVERY line of the report.
+ (set-option! pnl-options "Display" "Parent account balances" 'immediate-bal)
+ (set-option! pnl-options "Display" "Parent account subtotals" 't)
+ (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-multilevel")))
+ (test-equal "multilevel. income = -$250.00"
+ (list "-$250.00" "-$250.00")
+ (sxml->table-row-col sxml 1 3 5))
+ (test-equal "multilevel. income-GBP = $0.00"
+ (list "-#600.00" "-$1,020.00" "-#600.00" "-$1,020.00")
+ (sxml->table-row-col sxml 1 4 5))
+ (test-equal "multilevel. total income = -$1,270.00"
+ (list "-$1,270.00" "-$1,270.00")
+ (sxml->table-row-col sxml 1 5 6))
+ (test-equal "multilevel. total revenue = $1,270.00"
+ (list "$1,270.00" "$1,270.00")
+ (sxml->table-row-col sxml 1 6 6))
+ (test-equal "multilevel. expenses = $0.00"
+ (list "$0.00" "$0.00")
+ (sxml->table-row-col sxml 1 3 6))
+ (test-equal "multilevel. net-income = $1,270"
+ (list "$1,270.00" "$1,270.00")
+ (sxml->table-row-col sxml 1 4 6)))
+
+ ;; set recursive-subtotal subtotal style
+ (set-option! pnl-options "Display" "Parent account balances" 'recursive-bal)
+ (set-option! pnl-options "Display" "Parent account subtotals" 'f)
+ (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-recursive")))
+ (test-equal "recursive. income = $1020+250"
+ (list "-#600.00" "-$1,020.00" "-$250.00" "-$250.00" "$0.00" "-#600.00" "-$1,020.00" "-$250.00" "-$250.00" "$0.00")
+ (sxml->table-row-col sxml 1 3 6))
+ (test-equal "recursive. income-gbp = $1020"
+ (list "-#600.00" "-$1,020.00" "-#600.00" "-$1,020.00")
+ (sxml->table-row-col sxml 1 4 5))
+ (test-equal "recursive. total revenue = $1270"
+ (list "$1,270.00" "$1,270.00")
+ (sxml->table-row-col sxml 1 5 6)))
+
+ (set-option! pnl-options "Commodities" "Show Foreign Currencies" #f)
+ (set-option! pnl-options "Commodities" "Show Exchange Rates" #f)
+ (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-disable show-fcur show-rates")))
+ (test-equal "show-fcur disabled"
+ (list "-$1,270.00" "$0.00" "-$1,270.00" "$0.00")
+ (sxml->table-row-col sxml 1 3 6))
+ (test-equal "show-rates disabled"
+ '()
+ (sxml->table-row-col sxml 2 #f #f)))
+
+ (set-option! pnl-options "Commodities" "Show Foreign Currencies" #t)
+ (set-option! pnl-options "Commodities" "Show Exchange Rates" #t)
+ (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-enable show-fcur show-rates")))
+ (test-equal "show-fcur enabled"
+ (list "-#600.00" "-$1,020.00" "-$250.00" "-$250.00" "$0.00" "-#600.00" "-$1,020.00" "-$250.00" "-$250.00" "$0.00")
+ (sxml->table-row-col sxml 1 3 6))
+ (test-equal "show-rates enabled"
+ (list "#1.00" "$1.70")
+ (sxml->table-row-col sxml 2 #f #f)))
+
+ ;;make-multilevel
+ (set-option! pnl-options "Display" "Parent account balances" 'immediate-bal)
+ (set-option! pnl-options "Display" "Parent account subtotals" 't)
)))
commit cabb598c0f0428d0dcc4f43c3b4713acbb1bb0f5
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jul 24 08:28:45 2018 +0800
[test-balsheet-pnl] rename to allow for pnl tests
diff --git a/gnucash/report/standard-reports/test/CMakeLists.txt b/gnucash/report/standard-reports/test/CMakeLists.txt
index 7fbdd4f..651a06b 100644
--- a/gnucash/report/standard-reports/test/CMakeLists.txt
+++ b/gnucash/report/standard-reports/test/CMakeLists.txt
@@ -9,7 +9,7 @@ set(scm_test_standard_reports_SOURCES
set(scm_test_with_srfi64_SOURCES
test-charts.scm
test-transaction.scm
- test-balance-sheet.scm
+ test-balsheet-pnl.scm
test-income-gst.scm
)
diff --git a/gnucash/report/standard-reports/test/test-balance-sheet.scm b/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
similarity index 100%
rename from gnucash/report/standard-reports/test/test-balance-sheet.scm
rename to gnucash/report/standard-reports/test/test-balsheet-pnl.scm
commit 8273f3eb824d230f347464cc01df2d58f1338e05
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jul 24 08:27:18 2018 +0800
[test-balance-sheet] prepare for pnl tests
This commit prepares for pnl tests - variables are prefixed with
balance-sheet- to accommodate pnl- tests
diff --git a/gnucash/report/standard-reports/test/test-balance-sheet.scm b/gnucash/report/standard-reports/test/test-balance-sheet.scm
index 2876089..8a13dc4 100644
--- a/gnucash/report/standard-reports/test/test-balance-sheet.scm
+++ b/gnucash/report/standard-reports/test/test-balance-sheet.scm
@@ -24,8 +24,8 @@
(balsheet-tests)
(test-end "balsheet.scm"))
-(define (options->sxml options test-title)
- (gnc:options->sxml balance-sheet-uuid options "test-balsheet" test-title))
+(define (options->sxml uuid options test-title)
+ (gnc:options->sxml uuid options "test-balsheet-pnl" test-title))
(define (set-option! options section name value)
(let ((option (gnc:lookup-option options section name)))
@@ -75,8 +75,8 @@
(define (null-test)
;; This null-test tests for the presence of report.
- (let ((options (gnc:make-report-options balance-sheet-uuid)))
- (test-assert "null-test" (options->sxml options "null-test"))))
+ (let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid)))
+ (test-assert "null-test" (options->sxml balance-sheet-uuid balance-sheet-options "null-test"))))
(define (balsheet-tests)
;; This function will perform implementation testing on the transaction report.
@@ -96,12 +96,12 @@
(income-GBP (cdr (assoc "Income-GBP" account-alist)))
(YEAR (gnc:time64-get-year (gnc:get-today))))
- (define (default-testing-options)
- (let ((options (gnc:make-report-options balance-sheet-uuid)))
- (set-option! options "General" "Balance Sheet Date" (cons 'absolute (gnc-dmy2time64 1 1 1971)))
- (set-option! options "Accounts" "Levels of Subaccounts" 'all)
- (set-option! options "Commodities" "Show Exchange Rates" #t)
- options))
+ (define (default-balsheet-testing-options)
+ (let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid)))
+ (set-option! balance-sheet-options "General" "Balance Sheet Date" (cons 'absolute (gnc-dmy2time64 1 1 1971)))
+ (set-option! balance-sheet-options "Accounts" "Levels of Subaccounts" 'all)
+ (set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #t)
+ balance-sheet-options))
;; $100 in Savings account
(env-transfer env 01 01 1970 equity bank1savings 100)
@@ -160,8 +160,8 @@
(env-transfer-foreign env 01 02 1980 income-GBP bank1current 100 170 #:description "earn 100GBP into $170")
;; Finally we can begin testing
- (let* ((options (default-testing-options))
- (sxml (options->sxml options "default")))
+ (let* ((balance-sheet-options (default-balsheet-testing-options))
+ (sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-default")))
(test-equal "total assets = $116,010"
(list "$116,010.00")
(sxml->table-row-col sxml 1 15 6))
@@ -172,35 +172,35 @@
(list "$106,510.00")
(sxml->table-row-col sxml 1 28 6))
- (set-option! options "Commodities" "Price Source" 'weighted-average)
- (let ((sxml (options->sxml options "weighted-average")))
+ (set-option! balance-sheet-options "Commodities" "Price Source" 'weighted-average)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-weighted-average")))
(test-equal "weighted average assets = $114,072.86"
(list "$114,072.86")
(sxml->table-row-col sxml 1 15 6)))
- (set-option! options "Commodities" "Price Source" 'average-cost)
- (let ((sxml (options->sxml options "average-cost")))
+ (set-option! balance-sheet-options "Commodities" "Price Source" 'average-cost)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-average-cost")))
(test-equal "average-cost assets = $113,100"
(list "$113,100.00")
(sxml->table-row-col sxml 1 15 6)))
- (set-option! options "Commodities" "Price Source" 'pricedb-nearest)
- (let ((sxml (options->sxml options "pricedb-nearest")))
+ (set-option! balance-sheet-options "Commodities" "Price Source" 'pricedb-nearest)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-pricedb-nearest")))
(test-equal "pricedb-nearest assets = $116,010"
(list "$116,010.00")
(sxml->table-row-col sxml 1 15 6)))
- (set-option! options "Commodities" "Price Source" 'pricedb-latest)
- (let ((sxml (options->sxml options "pricedb-latest")))
+ (set-option! balance-sheet-options "Commodities" "Price Source" 'pricedb-latest)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-pricedb-latest")))
(test-equal "pricedb-latest assets = $122,090"
(list "$122,090.00")
(sxml->table-row-col sxml 1 15 6)))
;; set multilevel subtotal style
;; verifies amount in EVERY line of the report.
- (set-option! options "Display" "Parent account balances" 'immediate-bal)
- (set-option! options "Display" "Parent account subtotals" 't)
- (let ((sxml (options->sxml options "multilevel")))
+ (set-option! balance-sheet-options "Display" "Parent account balances" 'immediate-bal)
+ (set-option! balance-sheet-options "Display" "Parent account subtotals" 't)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-multilevel")))
(test-equal "multilevel. root = $0.00"
(list "$0.00")
(sxml->table-row-col sxml 1 3 5))
@@ -257,9 +257,9 @@
(sxml->table-row-col sxml 1 20 6)))
;; set recursive-subtotal subtotal style
- (set-option! options "Display" "Parent account balances" 'recursive-bal)
- (set-option! options "Display" "Parent account subtotals" 'f)
- (let ((sxml (options->sxml options "recursive")))
+ (set-option! balance-sheet-options "Display" "Parent account balances" 'recursive-bal)
+ (set-option! balance-sheet-options "Display" "Parent account subtotals" 'f)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-recursive")))
(test-equal "recursive. root = $760+15000+104600"
(list "#400.00" "$680.00" "30 FUNDS" "$15,000.00" "$106,410.00" "$106,410.00")
(sxml->table-row-col sxml 1 3 6))
@@ -300,9 +300,9 @@
(list "$122,090.00")
(sxml->table-row-col sxml 1 15 6)))
- (set-option! options "Commodities" "Show Foreign Currencies" #f)
- (set-option! options "Commodities" "Show Exchange Rates" #f)
- (let ((sxml (options->sxml options "disable show-fcur show-rates")))
+ (set-option! balance-sheet-options "Commodities" "Show Foreign Currencies" #f)
+ (set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #f)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-disable show-fcur show-rates")))
(test-equal "show-fcur disabled"
(list "$122,090.00")
(sxml->table-row-col sxml 1 3 6))
@@ -310,9 +310,9 @@
'()
(sxml->table-row-col sxml 2 #f #f)))
- (set-option! options "Commodities" "Show Foreign Currencies" #t)
- (set-option! options "Commodities" "Show Exchange Rates" #t)
- (let ((sxml (options->sxml options "enable show-fcur show-rates")))
+ (set-option! balance-sheet-options "Commodities" "Show Foreign Currencies" #t)
+ (set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #t)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-enable show-fcur show-rates")))
(test-equal "show-fcur enabled"
(list "#400.00" "$680.00" "30 FUNDS" "$15,000.00" "$106,410.00" "$106,410.00")
(sxml->table-row-col sxml 1 3 6))
@@ -321,12 +321,12 @@
(sxml->table-row-col sxml 2 #f #f)))
;;make-multilevel
- (set-option! options "Display" "Parent account balances" 'immediate-bal)
- (set-option! options "Display" "Parent account subtotals" 't)
+ (set-option! balance-sheet-options "Display" "Parent account balances" 'immediate-bal)
+ (set-option! balance-sheet-options "Display" "Parent account subtotals" 't)
- (set-option! options "Display" "Omit zero balance figures" #t)
- (set-option! options "Display" "Include accounts with zero total balances" #f)
- (let ((sxml (options->sxml options "incl-zb-accts=#f omit-zb-bals=#t")))
+ (set-option! balance-sheet-options "Display" "Omit zero balance figures" #t)
+ (set-option! balance-sheet-options "Display" "Include accounts with zero total balances" #f)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-incl-zb-accts=#f omit-zb-bals=#t")))
(test-equal "omit-zb-bals=#t"
'()
(sxml->table-row-col sxml 1 3 5))
@@ -334,9 +334,9 @@
'("Savings" "$100.00") ;i.e.skips "Empty" account with $0.00
(sxml->table-row-col sxml 1 8 #f)))
- (set-option! options "Display" "Omit zero balance figures" #f)
- (set-option! options "Display" "Include accounts with zero total balances" #t)
- (let ((sxml (options->sxml options "incl-zb-accts=#t omit-zb-bals=#f")))
+ (set-option! balance-sheet-options "Display" "Omit zero balance figures" #f)
+ (set-option! balance-sheet-options "Display" "Include accounts with zero total balances" #t)
+ (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-incl-zb-accts=#t omit-zb-bals=#f")))
(test-equal "omit-zb-bals=#f"
(list "$0.00")
(sxml->table-row-col sxml 1 3 5))
commit 8cbd4d629f8c23e0b312d51a37882cd37904dee2
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Jul 23 22:51:29 2018 +0800
[test-balance-sheet] upgrade to better coverage of balance-sheet
This commit upgrades test-balance-sheet to cover most sensitive data.
It specifically generates the following types of transactions, and
tests the balance sheet generated.
- Equity-USD to nested accounts
- Equity-USD to ForeignBank-GBP
- Equity-USD to Broker:FUNDS
- buy/sell from equity to GBP and FUNDS
- Broker and Broker:FUNDS both have splits with amounts
Two main subtotal strategies are tested: multilevel and recursive-bal,
and all amounts are tested.
diff --git a/gnucash/report/standard-reports/test/test-balance-sheet.scm b/gnucash/report/standard-reports/test/test-balance-sheet.scm
index 61016b1..2876089 100644
--- a/gnucash/report/standard-reports/test/test-balance-sheet.scm
+++ b/gnucash/report/standard-reports/test/test-balance-sheet.scm
@@ -33,18 +33,45 @@
(gnc:option-set-value option value)
(test-assert (format #f "wrong-option ~a ~a" section name) #f))))
+(define (mnemonic->commodity sym)
+ (gnc-commodity-table-lookup
+ (gnc-commodity-table-get-table (gnc-get-current-book))
+ (gnc-commodity-get-namespace (gnc-default-report-currency))
+ sym))
+
+(define USD (gnc-default-report-currency)) ;default currency should be USD because LC_ALL="C"
+(define GBP (mnemonic->commodity "GBP"))
+(define FUNDS (gnc-commodity-new (gnc-get-current-book)
+ "Funds" ;fullname
+ "FUNDS" ;namespace
+ "FUNDS" ;mnemonic
+ "FUNDS" ;cusip
+ 1000 ;fraction
+ ))
+(gnc-commodity-set-user-symbol GBP "#")
+
(define structure
- (list "Root" (list (cons 'type ACCT-TYPE-ASSET))
+ (list "Root" (list (cons 'type ACCT-TYPE-ASSET)
+ (cons 'commodity USD))
(list "Asset"
- (list "Bank"
- (list "Bank-Sub"))
- (list "A/Receivable" (list (cons 'type ACCT-TYPE-RECEIVABLE))))
- (list "Liability" (list (cons 'type ACCT-TYPE-PAYABLE))
- (list "CreditCard")
- (list "A/Payable"))
+ (list "Bank1"
+ (list "Savings")
+ (list "Bonds")
+ (list "Empty")
+ (list "Current"))
+ (list "House")
+ (list "ForeignBank" (list (cons 'commodity GBP))
+ (list "ForeignSavings"))
+ (list "Broker"
+ (list "Funds" (list (cons 'type ACCT-TYPE-STOCK)
+ (cons 'commodity FUNDS)))))
+ (list "Liability" (list (cons 'type ACCT-TYPE-LIABILITY))
+ (list "Bank2"
+ (list "Loan")
+ (list "CreditCard")))
(list "Equity" (list (cons 'type ACCT-TYPE-EQUITY)))
- (list "Income" (list (cons 'type ACCT-TYPE-INCOME)))
- (list "Expenses" (list (cons 'type ACCT-TYPE-EXPENSE)))))
+ (list "Income" (list (cons 'type ACCT-TYPE-INCOME))
+ (list "Income-GBP" (list (cons 'commodity GBP))))))
(define (null-test)
;; This null-test tests for the presence of report.
@@ -55,86 +82,265 @@
;; This function will perform implementation testing on the transaction report.
(let* ((env (create-test-env))
(account-alist (env-create-account-structure-alist env structure))
- (bank (cdr (assoc "Bank" account-alist)))
- (banksub (cdr (assoc "Bank-Sub" account-alist)))
- (income (cdr (assoc "Income" account-alist)))
- (expense (cdr (assoc "Expenses" account-alist)))
+ (bank1savings (cdr (assoc "Savings" account-alist)))
+ (bank1bonds (cdr (assoc "Bonds" account-alist)))
+ (bank1current (cdr (assoc "Current" account-alist)))
+ (house (cdr (assoc "House" account-alist)))
+ (foreignsavings (cdr (assoc "ForeignSavings" account-alist)))
+ (broker (cdr (assoc "Broker" account-alist)))
+ (brokerfunds (cdr (assoc "Funds" account-alist)))
+ (bank2loan (cdr (assoc "Loan" account-alist)))
+ (bank2creditcard (cdr (assoc "CreditCard" account-alist)))
(equity (cdr (assoc "Equity" account-alist)))
- (creditcard (cdr (assoc "CreditCard" account-alist)))
- (payable (cdr (assoc "A/Payable" account-alist)))
- (receivable (cdr (assoc "A/Receivable" account-alist)))
+ (income (cdr (assoc "Income" account-alist)))
+ (income-GBP (cdr (assoc "Income-GBP" account-alist)))
(YEAR (gnc:time64-get-year (gnc:get-today))))
(define (default-testing-options)
- ;; To ease testing of transaction report, we will set default
- ;; options for generating reports. We will elable extra columns
- ;; for Exporting, disable generation of informational text, and
- ;; disable indenting. These options will be tested separately as
- ;; the first test group. By default, we'll select the modern dates.
(let ((options (gnc:make-report-options balance-sheet-uuid)))
- (set-option! options "General" "Balance Sheet Date" (cons 'relative 'end-cal-year))
+ (set-option! options "General" "Balance Sheet Date" (cons 'absolute (gnc-dmy2time64 1 1 1971)))
+ (set-option! options "Accounts" "Levels of Subaccounts" 'all)
+ (set-option! options "Commodities" "Show Exchange Rates" #t)
options))
- (define* (create-txn DD MM YY DESC list-of-splits #:optional txn-type)
- (let ((txn (xaccMallocTransaction (gnc-get-current-book))))
- (xaccTransBeginEdit txn)
- (xaccTransSetDescription txn DESC)
- (xaccTransSetCurrency txn (gnc-default-report-currency))
- (xaccTransSetDate txn DD MM YY)
- (for-each
- (lambda (tfr)
- (let ((split (xaccMallocSplit (gnc-get-current-book))))
- (xaccSplitSetParent split txn)
- (xaccSplitSetAccount split (cdr tfr))
- (xaccSplitSetValue split (car tfr))
- (xaccSplitSetAmount split (car tfr))))
- list-of-splits)
- (if txn-type
- (xaccTransSetTxnType txn txn-type))
- (xaccTransCommitEdit txn)
- txn))
-
- (create-txn 1 1 YEAR "invoice charge $100"
- (list (cons -100 income)
- (cons 100 receivable))
- TXN-TYPE-INVOICE)
-
- (create-txn 1 2 YEAR "receive part-payment $98"
- (list (cons -98 receivable)
- (cons 98 bank))
- TXN-TYPE-PAYMENT)
-
- (create-txn 1 3 YEAR "receive bill $55"
- (list (cons 55 expense)
- (cons -55 payable))
- TXN-TYPE-INVOICE)
-
- (create-txn 1 4 YEAR "part-pay bill $50 using creditcard"
- (list (cons 50 payable)
- (cons -50 creditcard))
- TXN-TYPE-PAYMENT)
-
- (create-txn 1 5 YEAR "part-pay creditcard from bank"
- (list (cons 47 creditcard)
- (cons -47 banksub)))
+ ;; $100 in Savings account
+ (env-transfer env 01 01 1970 equity bank1savings 100)
+ ;; $2000 in Bonds
+ (env-transfer env 01 01 1970 equity bank1bonds 2000)
+ ;; $500 in Current Acc
+ (env-transfer env 01 01 1970 equity bank1current 9000)
+ ;; $100,000 in house
+ (env-transfer env 01 01 1970 equity house 100000)
- ;; Finally we can begin testing
- (test-begin "display options")
+ ;; pre-existing GBPs
+ (env-transfer-foreign env 01 01 1970 bank1current foreignsavings 130 100 #:description "buy 100GBP at $1.30")
+ (env-transfer-foreign env 01 02 1970 bank1current foreignsavings 140 100 #:description "buy 100GBP at $1.40")
+ (env-transfer-foreign env 01 03 1970 bank1current foreignsavings 150 100 #:description "buy 100GBP at $1.50")
+ (env-transfer-foreign env 01 04 1970 bank1current foreignsavings 155 100 #:description "buy 100GBP at $1.55")
+ (env-transfer-foreign env 01 05 1970 bank1current foreignsavings -160 -100 #:description "sell 100GBP at $1.60")
+ (env-transfer-foreign env 01 06 1970 bank1current foreignsavings 155 100 #:description "buy 100GBP at $1.55")
+ (env-transfer-foreign env 01 07 1970 bank1current foreignsavings -145 -100 #:description "sell 100GBP at $1.45")
+ (env-transfer-foreign env 01 08 1970 bank1current foreignsavings 165 100 #:description "buy 100GBP at $1.65")
+
+ ;; broker has $2000
+ (env-transfer env 01 01 1970 equity broker 2000)
+
+ ;; existing FUNDs = 200 USD on 01/01/1970
+ (env-transfer-foreign env 01 01 1970 bank1current brokerfunds 2000 10 #:description "buy 10FUND at $200")
+ (env-transfer-foreign env 01 02 1970 bank1current brokerfunds 2100 10 #:description "buy 10FUND at $210")
+ (env-transfer-foreign env 01 03 1970 bank1current brokerfunds 2250 10 #:description "buy 10FUND at $225")
+ (env-transfer-foreign env 01 04 1970 bank1current brokerfunds 2440 10 #:description "buy 10FUND at $244")
+ (env-transfer-foreign env 01 05 1970 bank1current brokerfunds -2640 -10 #:description "sell 10FUND at $264")
+ (env-transfer-foreign env 01 06 1970 bank1current brokerfunds -2550 -10 #:description "sell 10FUND at $255")
+ (env-transfer-foreign env 01 07 1970 bank1current brokerfunds 2500 10 #:description "buy 10FUND at $250")
+
+ ;; $9000 loan
+ (env-transfer env 01 01 1970 equity bank2loan -9000)
+
+ ;; $500 on creditcard debt
+ (env-transfer env 01 01 1970 equity bank2creditcard -500)
+ ;; further prices into pricedb
+ ;; GBP = 1.50 to 1.90 USD
+ (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1971) 15/10)
+ (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1972) 16/10)
+ (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1973) 17/10)
+ (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1974) 18/10)
+ (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1975) 19/10)
+ ;; FUND = 300 to 500 USD
+ (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1971) 300)
+ (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1972) 350)
+ (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1973) 400)
+ (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1974) 450)
+ (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1975) 500)
+
+ ;; a couple INCOME transactions, a decade later
+ (env-transfer env 01 01 1980 income bank1current 250)
+ (env-transfer env 01 01 1980 income-GBP foreignsavings 500)
+ (env-transfer-foreign env 01 02 1980 income-GBP bank1current 100 170 #:description "earn 100GBP into $170")
+
+ ;; Finally we can begin testing
(let* ((options (default-testing-options))
(sxml (options->sxml options "default")))
+ (test-equal "total assets = $116,010"
+ (list "$116,010.00")
+ (sxml->table-row-col sxml 1 15 6))
+ (test-equal "total liabilities = $9,500.00"
+ (list "$9,500.00")
+ (sxml->table-row-col sxml 1 23 6))
+ (test-equal "total equity = $106,510.00"
+ (list "$106,510.00")
+ (sxml->table-row-col sxml 1 28 6))
+
+ (set-option! options "Commodities" "Price Source" 'weighted-average)
+ (let ((sxml (options->sxml options "weighted-average")))
+ (test-equal "weighted average assets = $114,072.86"
+ (list "$114,072.86")
+ (sxml->table-row-col sxml 1 15 6)))
+
+ (set-option! options "Commodities" "Price Source" 'average-cost)
+ (let ((sxml (options->sxml options "average-cost")))
+ (test-equal "average-cost assets = $113,100"
+ (list "$113,100.00")
+ (sxml->table-row-col sxml 1 15 6)))
+
+ (set-option! options "Commodities" "Price Source" 'pricedb-nearest)
+ (let ((sxml (options->sxml options "pricedb-nearest")))
+ (test-equal "pricedb-nearest assets = $116,010"
+ (list "$116,010.00")
+ (sxml->table-row-col sxml 1 15 6)))
+
+ (set-option! options "Commodities" "Price Source" 'pricedb-latest)
+ (let ((sxml (options->sxml options "pricedb-latest")))
+ (test-equal "pricedb-latest assets = $122,090"
+ (list "$122,090.00")
+ (sxml->table-row-col sxml 1 15 6)))
+
+ ;; set multilevel subtotal style
+ ;; verifies amount in EVERY line of the report.
+ (set-option! options "Display" "Parent account balances" 'immediate-bal)
+ (set-option! options "Display" "Parent account subtotals" 't)
+ (let ((sxml (options->sxml options "multilevel")))
+ (test-equal "multilevel. root = $0.00"
+ (list "$0.00")
+ (sxml->table-row-col sxml 1 3 5))
+ (test-equal "multilevel. assets = $0.00"
+ (list "$0.00")
+ (sxml->table-row-col sxml 1 4 4))
+ (test-equal "multilevel. bank1 = $0.00"
+ (list "$0.00")
+ (sxml->table-row-col sxml 1 5 3))
+ (test-equal "multilevel. bonds = $2,000.00"
+ (list "$2,000.00")
+ (sxml->table-row-col sxml 1 6 3))
+ (test-equal "multilevel. current = $2310.00"
+ (list "$2,310.00")
+ (sxml->table-row-col sxml 1 7 3))
+ (test-equal "multilevel. empty = $0.00"
+ (list "$0.00")
+ (sxml->table-row-col sxml 1 8 3))
+ (test-equal "multilevel. savings = $100.00"
+ (list "$100.00")
+ (sxml->table-row-col sxml 1 9 3))
+ (test-equal "multilevel. total bank1 = $4,410"
+ (list "$4,410.00")
+ (sxml->table-row-col sxml 1 10 4))
+ (test-equal "multilevel. broker = $2,000.00"
+ (list "$2,000.00")
+ (sxml->table-row-col sxml 1 11 3))
+ (test-equal "multilevel. funds = $15,000.00"
+ (list "30 FUNDS" "$15,000.00" "$15,000.00")
+ (sxml->table-row-col sxml 1 12 3))
+ (test-equal "multilevel. total broker = $17,000.00"
+ (list "$17,000.00")
+ (sxml->table-row-col sxml 1 13 4))
+ (test-equal "multilevel. foreign = $0.00"
+ (list "$0.00")
+ (sxml->table-row-col sxml 1 14 3))
+ (test-equal "multilevel. foreignsavings = #400.00 = $680"
+ (list "#400.00" "$680.00" "$680.00")
+ (sxml->table-row-col sxml 1 15 3))
+ (test-equal "multilevel. total foreign = $680"
+ (list "$680.00")
+ (sxml->table-row-col sxml 1 16 4))
+ (test-equal "multilevel. house = $100,000"
+ (list "$100,000.00")
+ (sxml->table-row-col sxml 1 17 4))
+ (test-equal "multilevel. total asset = $122,090"
+ (list "$122,090.00")
+ (sxml->table-row-col sxml 1 18 5))
+ (test-equal "multilevel. total root = $122,090"
+ (list "$122,090.00")
+ (sxml->table-row-col sxml 1 19 6))
+ (test-equal "multilevel. total assets = $122,090"
+ (list "$122,090.00")
+ (sxml->table-row-col sxml 1 20 6)))
+
+ ;; set recursive-subtotal subtotal style
+ (set-option! options "Display" "Parent account balances" 'recursive-bal)
+ (set-option! options "Display" "Parent account subtotals" 'f)
+ (let ((sxml (options->sxml options "recursive")))
+ (test-equal "recursive. root = $760+15000+104600"
+ (list "#400.00" "$680.00" "30 FUNDS" "$15,000.00" "$106,410.00" "$106,410.00")
+ (sxml->table-row-col sxml 1 3 6))
+ (test-equal "recursive. assets = $760+15000+104600"
+ (list "#400.00" "$680.00" "30 FUNDS" "$15,000.00" "$106,410.00" "$106,410.00")
+ (sxml->table-row-col sxml 1 4 5))
+ (test-equal "recursive. bank1 = $4,410.00"
+ (list "$4,410.00")
+ (sxml->table-row-col sxml 1 5 4))
+ (test-equal "recursive. bonds = $2,000.00"
+ (list "$2,000.00")
+ (sxml->table-row-col sxml 1 6 3))
+ (test-equal "recursive. current = $2310.00"
+ (list "$2,310.00")
+ (sxml->table-row-col sxml 1 7 3))
+ (test-equal "recursive. empty = $0.00"
+ (list "$0.00")
+ (sxml->table-row-col sxml 1 8 3))
+ (test-equal "recursive. savings = $100.00"
+ (list "$100.00")
+ (sxml->table-row-col sxml 1 9 3))
+ (test-equal "recursive. broker = $15000+2000.00"
+ (list "30 FUNDS" "$15,000.00" "$2,000.00" "$2,000.00")
+ (sxml->table-row-col sxml 1 10 4))
+ (test-equal "recursive. funds = $15,000.00"
+ (list "30 FUNDS" "$15,000.00" "$15,000.00")
+ (sxml->table-row-col sxml 1 11 3))
+ (test-equal "recursive. foreign = $680.00"
+ (list "#400.00" "$680.00")
+ (sxml->table-row-col sxml 1 12 4))
+ (test-equal "recursive. foreignsavings = #400.00 = $760"
+ (list "#400.00" "$680.00" "$680.00")
+ (sxml->table-row-col sxml 1 13 3))
+ (test-equal "recursive. house = $100,000"
+ (list "$100,000.00")
+ (sxml->table-row-col sxml 1 14 4))
+ (test-equal "recursive. total assets = $122,090.00"
+ (list "$122,090.00")
+ (sxml->table-row-col sxml 1 15 6)))
+
+ (set-option! options "Commodities" "Show Foreign Currencies" #f)
+ (set-option! options "Commodities" "Show Exchange Rates" #f)
+ (let ((sxml (options->sxml options "disable show-fcur show-rates")))
+ (test-equal "show-fcur disabled"
+ (list "$122,090.00")
+ (sxml->table-row-col sxml 1 3 6))
+ (test-equal "show-rates disabled"
+ '()
+ (sxml->table-row-col sxml 2 #f #f)))
- (test-equal "total assets = $53.00"
- (list "Total Assets" "$53.00")
- (sxml->table-row-col sxml 1 7 #f))
+ (set-option! options "Commodities" "Show Foreign Currencies" #t)
+ (set-option! options "Commodities" "Show Exchange Rates" #t)
+ (let ((sxml (options->sxml options "enable show-fcur show-rates")))
+ (test-equal "show-fcur enabled"
+ (list "#400.00" "$680.00" "30 FUNDS" "$15,000.00" "$106,410.00" "$106,410.00")
+ (sxml->table-row-col sxml 1 3 6))
+ (test-equal "show-rates enabled"
+ (list "1 FUNDS" "$500.00" "#1.00" "$1.70")
+ (sxml->table-row-col sxml 2 #f #f)))
- (test-equal "total liabilities = $8.00"
- (list "Total Liabilities" "$8.00")
- (sxml->table-row-col sxml 1 14 #f))
+ ;;make-multilevel
+ (set-option! options "Display" "Parent account balances" 'immediate-bal)
+ (set-option! options "Display" "Parent account subtotals" 't)
- (test-equal "total equity = $45.00"
- (list "Total Equity" "$45.00")
- (sxml->table-row-col sxml 1 19 #f))
+ (set-option! options "Display" "Omit zero balance figures" #t)
+ (set-option! options "Display" "Include accounts with zero total balances" #f)
+ (let ((sxml (options->sxml options "incl-zb-accts=#f omit-zb-bals=#t")))
+ (test-equal "omit-zb-bals=#t"
+ '()
+ (sxml->table-row-col sxml 1 3 5))
+ (test-equal "incl-zb-accts=#f"
+ '("Savings" "$100.00") ;i.e.skips "Empty" account with $0.00
+ (sxml->table-row-col sxml 1 8 #f)))
- )
- (test-end "display options")))
+ (set-option! options "Display" "Omit zero balance figures" #f)
+ (set-option! options "Display" "Include accounts with zero total balances" #t)
+ (let ((sxml (options->sxml options "incl-zb-accts=#t omit-zb-bals=#f")))
+ (test-equal "omit-zb-bals=#f"
+ (list "$0.00")
+ (sxml->table-row-col sxml 1 3 5))
+ (test-equal "incl-zb-accts=#t"
+ '("Empty" "$0.00")
+ (sxml->table-row-col sxml 1 8 #f)))
+ )))
commit 47ba21b8dc62b26dfb167b454c45f6be838e29f8
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Jul 23 23:08:06 2018 +0800
[test-extras] export gnc-pricedb-create
diff --git a/libgnucash/engine/test/test-extras.scm b/libgnucash/engine/test/test-extras.scm
index c1d37b7..a040132 100644
--- a/libgnucash/engine/test/test-extras.scm
+++ b/libgnucash/engine/test/test-extras.scm
@@ -49,6 +49,7 @@
(export env-create-account-structure)
(export env-create-account-structure-alist)
(export env-expense-account-structure)
+(export gnc-pricedb-create)
;;
;; Random test related syntax and the like
commit 78ab26cc2ba78a8e41ad725ae0fd64bc186c92d4
Author: John Ralls <jralls at ceridwen.us>
Date: Mon Aug 6 14:49:07 2018 -0700
Fix gncInvoice test failure.
test_suite_gncInvoice sets up the test suite. It's not part of the test
runtime, so stack variables in it have gone out of scope by the time the
tests are actually run. Making invoiceData static makes it permanent so
it exists at runtime.
diff --git a/libgnucash/engine/test/utest-Invoice.c b/libgnucash/engine/test/utest-Invoice.c
index e772652..4ef8d10 100644
--- a/libgnucash/engine/test/utest-Invoice.c
+++ b/libgnucash/engine/test/utest-Invoice.c
@@ -205,7 +205,7 @@ test_invoice_posted_trans ( Fixture *fixture, gconstpointer pData )
void
test_suite_gncInvoice ( void )
{
- InvoiceData pData = { FALSE, FALSE, { 1000, 100 }, { 2000, 100 } }; // Vendor bill
+ static InvoiceData pData = { FALSE, FALSE, { 1000, 100 }, { 2000, 100 } }; // Vendor bill
GNC_TEST_ADD( suitename, "post/unpost", Fixture, &pData, setup, test_invoice_post, teardown );
GNC_TEST_ADD( suitename, "post trans - vendor bill", Fixture, &pData, setup_with_invoice, test_invoice_posted_trans, teardown_with_invoice );
commit d87fa3a5bed0b948f28651bf8b0897373cc7110e
Author: Geert Janssens <geert at kobaltwit.be>
Date: Mon Aug 6 13:29:12 2018 +0200
Bug 796766 - Credit note creating 'imbalance' with wrong entries
Add fix and regression test.
diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c
index 616ef1b..60f643a 100644
--- a/libgnucash/engine/gncInvoice.c
+++ b/libgnucash/engine/gncInvoice.c
@@ -1509,8 +1509,11 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
total = gncInvoiceGetTotal (invoice);
taxes = gncInvoiceGetTotalTaxList (invoice);
/* The two functions above return signs relative to the document
- * We need to convert them to balance values before we can use them here */
- if (is_cust_doc)
+ * We need to convert them to balance values before we can use them here
+ * Note the odd construct comparing two booleans is to xor them
+ * that is, only evaluate true if both are different.
+ */
+ if (is_cust_doc != is_cn)
{
GList *node;
total = gnc_numeric_neg (total);
diff --git a/libgnucash/engine/test/utest-Invoice.c b/libgnucash/engine/test/utest-Invoice.c
index fe8eb7b..e772652 100644
--- a/libgnucash/engine/test/utest-Invoice.c
+++ b/libgnucash/engine/test/utest-Invoice.c
@@ -31,66 +31,188 @@ void test_suite_gncInvoice ( void );
typedef struct
{
+ gboolean is_cn;
+ gboolean is_cust_doc;
+ gnc_numeric quantity;
+ gnc_numeric price;
+} InvoiceData;
+
+typedef struct
+{
QofBook *book;
Account *account;
+ Account *account2;
GncOwner owner;
GncCustomer *customer;
+ GncVendor *vendor;
gnc_commodity *commodity;
+
+ GncInvoice* invoice;
+ Transaction *trans;
} Fixture;
static void
setup( Fixture *fixture, gconstpointer pData )
{
+ const InvoiceData *data = (InvoiceData*) pData;
+
fixture->book = qof_book_new();
fixture->account = xaccMallocAccount(fixture->book);
+ fixture->account2 = xaccMallocAccount(fixture->book);
fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100);
xaccAccountSetCommodity(fixture->account, fixture->commodity);
+ xaccAccountSetCommodity(fixture->account2, fixture->commodity);
- fixture->customer = gncCustomerCreate(fixture->book);
- gncOwnerInitCustomer(&fixture->owner, fixture->customer);
+ if (data->is_cust_doc)
+ {
+ fixture->customer = gncCustomerCreate(fixture->book);
+ gncOwnerInitCustomer(&fixture->owner, fixture->customer);
+ }
+ else
+ {
+ fixture->vendor = gncVendorCreate(fixture->book);
+ gncOwnerInitVendor(&fixture->owner, fixture->vendor);
+ }
+
+ fixture->invoice = gncInvoiceCreate(fixture->book);
}
static void
teardown( Fixture *fixture, gconstpointer pData )
{
- gncCustomerBeginEdit(fixture->customer);
- gncCustomerDestroy(fixture->customer);
+ const InvoiceData *data = (InvoiceData*) pData;
+
+ gncInvoiceBeginEdit(fixture->invoice);
+ gncInvoiceDestroy(fixture->invoice);
+
+ if (data->is_cust_doc)
+ {
+ gncCustomerBeginEdit(fixture->customer);
+ gncCustomerDestroy(fixture->customer);
+ }
+ else
+ {
+ gncVendorBeginEdit(fixture->vendor);
+ gncVendorDestroy(fixture->vendor);
+ }
xaccAccountBeginEdit(fixture->account);
xaccAccountDestroy(fixture->account);
+ xaccAccountBeginEdit(fixture->account2);
+ xaccAccountDestroy(fixture->account2);
gnc_commodity_destroy(fixture->commodity);
qof_book_destroy( fixture->book );
+};
+
+static void
+setup_with_invoice( Fixture *fixture, gconstpointer pData )
+{
+ const InvoiceData *data = (InvoiceData*) pData;
+
+ time64 ts1 = gnc_time(NULL);
+ time64 ts2 = ts1;
+ const char *desc = "Test description";
+ GncEntry *entry = NULL;
+
+ setup(fixture, pData);
+
+ fixture->invoice = gncInvoiceCreate(fixture->book);
+ gncInvoiceSetCurrency(fixture->invoice, fixture->commodity);
+ gncInvoiceSetOwner(fixture->invoice, &fixture->owner);
+
+ entry = gncEntryCreate(fixture->book);
+ gncEntrySetDate (entry, ts1);
+ gncEntrySetDateEntered (entry, ts1);
+ gncEntrySetDescription (entry, desc);
+ gncEntrySetDocQuantity (entry, data->quantity, data->is_cn);
+
+ if (data->is_cust_doc)
+ {
+ gncEntrySetInvAccount(entry, fixture->account);
+ gncInvoiceAddEntry (fixture->invoice, entry);
+ }
+ else
+ {
+ gncEntrySetBillAccount(entry, fixture->account);
+ gncBillAddEntry(fixture->invoice, entry);
+ }
+
+ fixture->trans = gncInvoicePostToAccount(fixture->invoice, fixture->account2, ts1, ts2, "memo", TRUE, FALSE);
+}
+
+static void
+teardown_with_invoice( Fixture *fixture, gconstpointer pData )
+{
+ gncInvoiceUnpost(fixture->invoice, TRUE);
+ gncInvoiceRemoveEntries (fixture->invoice);
+
+ teardown(fixture, pData);
}
static void
test_invoice_post ( Fixture *fixture, gconstpointer pData )
{
- GncInvoice *invoice = gncInvoiceCreate(fixture->book);
time64 ts1 = gnc_time(NULL);
time64 ts2 = ts1;
- g_assert(invoice);
- g_assert(!gncInvoiceGetIsCreditNote(invoice));
- g_assert(gncInvoiceGetActive(invoice));
- g_assert(gncInvoiceGetPostedAcc(invoice) == NULL);
+ g_assert(fixture->invoice);
+ g_assert(!gncInvoiceGetIsCreditNote(fixture->invoice));
+ g_assert(gncInvoiceGetActive(fixture->invoice));
+ g_assert(gncInvoiceGetPostedAcc(fixture->invoice) == NULL);
- gncInvoiceSetCurrency(invoice, fixture->commodity);
+ gncInvoiceSetCurrency(fixture->invoice, fixture->commodity);
- gncInvoiceSetOwner(invoice, &fixture->owner);
+ gncInvoiceSetOwner(fixture->invoice, &fixture->owner);
g_test_message( "Will now post the invoice" );
- g_assert(!gncInvoiceIsPosted(invoice));
- gncInvoicePostToAccount(invoice, fixture->account, ts1, ts2, "memo", TRUE, FALSE);
- g_assert(gncInvoiceIsPosted(invoice));
+ g_assert(!gncInvoiceIsPosted(fixture->invoice));
+ gncInvoicePostToAccount(fixture->invoice, fixture->account, ts1, ts2, "memo", TRUE, FALSE);
+ g_assert(gncInvoiceIsPosted(fixture->invoice));
+
+ gncInvoiceUnpost(fixture->invoice, TRUE);
+ g_assert(!gncInvoiceIsPosted(fixture->invoice));
+}
+
+static void
+test_invoice_posted_trans ( Fixture *fixture, gconstpointer pData )
+{
+ const InvoiceData *data = (InvoiceData*) pData;
- gncInvoiceUnpost(invoice, TRUE);
- g_assert(!gncInvoiceIsPosted(invoice));
+ gnc_numeric total = gncInvoiceGetTotal(fixture->invoice);
+ gnc_numeric acct_balance, acct2_balance;
+
+ g_assert (1 == xaccAccountCountSplits (fixture->account, FALSE));
+ g_assert (1 == xaccAccountCountSplits (fixture->account2, FALSE));
+
+ acct_balance = xaccAccountGetBalance(fixture->account);
+ acct2_balance = xaccAccountGetBalance(fixture->account2);
+
+ // Handle sign reversals (document values vs balance values)
+ if (data->is_cn != !data->is_cust_doc)
+ {
+ g_assert (gnc_numeric_equal (gnc_numeric_neg(acct_balance), total));
+ g_assert (gnc_numeric_equal (acct2_balance, total));
+ }
+ else
+ {
+ g_assert (gnc_numeric_equal (acct_balance, total));
+ g_assert (gnc_numeric_equal (gnc_numeric_neg(acct2_balance), total));
+ }
}
void
test_suite_gncInvoice ( void )
{
- GNC_TEST_ADD( suitename, "post", Fixture, NULL, setup, test_invoice_post, teardown );
+ InvoiceData pData = { FALSE, FALSE, { 1000, 100 }, { 2000, 100 } }; // Vendor bill
+ GNC_TEST_ADD( suitename, "post/unpost", Fixture, &pData, setup, test_invoice_post, teardown );
+
+ GNC_TEST_ADD( suitename, "post trans - vendor bill", Fixture, &pData, setup_with_invoice, test_invoice_posted_trans, teardown_with_invoice );
+ pData.is_cn = TRUE; // Vendor credit note
+ GNC_TEST_ADD( suitename, "post trans - vendor credit note", Fixture, &pData, setup_with_invoice, test_invoice_posted_trans, teardown_with_invoice );
+ pData.is_cust_doc = TRUE; // Customer credit note
+ GNC_TEST_ADD( suitename, "post trans - customer creditnote", Fixture, &pData, setup_with_invoice, test_invoice_posted_trans, teardown_with_invoice );
+ pData.is_cn = FALSE; // Customer invoice
+ GNC_TEST_ADD( suitename, "post trans - customer invoice", Fixture, &pData, setup_with_invoice, test_invoice_posted_trans, teardown_with_invoice );
}
commit 4c8b07c0fa76b6179fc6e606e5393e056f03426b
Author: Yuri Chornoivan <yurchor at ukr.net>
Date: Thu Aug 2 15:40:00 2018 +0300
More minor fixes
Signed-off-by: Yuri Chornoivan <yurchor at ukr.net>
diff --git a/gnucash/gschemas/org.gnucash.gschema.xml.in b/gnucash/gschemas/org.gnucash.gschema.xml.in
index 8d924c0..53edc3c 100644
--- a/gnucash/gschemas/org.gnucash.gschema.xml.in
+++ b/gnucash/gschemas/org.gnucash.gschema.xml.in
@@ -18,7 +18,7 @@
<key name="account-separator" type="s">
<default>'colon'</default>
<summary>Character to use as separator between account names</summary>
- <description>This setting determines the character that will be used between components of an account name. Possible values are any single non-alphanumeric unicode character, or any of the following strings: "colon" "slash", "backslash", "dash" and "period".</description>
+ <description>This setting determines the character that will be used between components of an account name. Possible values are any single non-alphanumeric unicode character, or any of the following strings: "colon", "slash", "backslash", "dash" and "period".</description>
</key>
<key name="assoc-head" type="s">
<default>''</default>
diff --git a/gnucash/gtkbuilder/dialog-preferences.glade b/gnucash/gtkbuilder/dialog-preferences.glade
index 58dfc66..f3cc770 100644
--- a/gnucash/gtkbuilder/dialog-preferences.glade
+++ b/gnucash/gtkbuilder/dialog-preferences.glade
@@ -825,7 +825,7 @@
<property name="can_focus">True</property>
<property name="events">GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK</property>
<property name="has_tooltip">True</property>
- <property name="tooltip_markup">The character that will be used between components of an account name. A legal value is any single character except letters and numbers, or any of the following strings: "colon" "slash", "backslash", "dash" and "period".</property>
+ <property name="tooltip_markup">The character that will be used between components of an account name. A legal value is any single character except letters and numbers, or any of the following strings: "colon", "slash", "backslash", "dash" and "period".</property>
<property name="tooltip_text" translatable="yes">The character that will be used between components of an account name. A legal value is any single character except letters and numbers, or any of the following strings: "colon" "slash", "backslash", "dash" and "period".</property>
<property name="invisible_char">â</property>
<property name="primary_icon_activatable">False</property>
diff --git a/gnucash/import-export/aqb/gnc-file-aqb-import.c b/gnucash/import-export/aqb/gnc-file-aqb-import.c
index 16cc8d3..b8af4b7 100644
--- a/gnucash/import-export/aqb/gnc-file-aqb-import.c
+++ b/gnucash/import-export/aqb/gnc-file-aqb-import.c
@@ -331,7 +331,7 @@ gnc_file_aqbanking_import(GtkWindow *parent,
if (num_jobs == 0)
{
gnc_info_dialog(parent,
- _("No jobs to be send.")
+ _("No jobs to be sent.")
);
}
else
commit 69fef8277fde56e7d2df700b21c63c19c115852a
Author: Geert Janssens <geert at kobaltwit.be>
Date: Tue Jul 31 17:30:07 2018 +0200
Revert "Add preference to control toolbar appearance"
This reverts commit 3b0931310730a4ae5d028a1e2120d2a619ae975a.
diff --git a/gnucash/gnome-utils/dialog-preferences.c b/gnucash/gnome-utils/dialog-preferences.c
index f17b2d9..815587e 100644
--- a/gnucash/gnome-utils/dialog-preferences.c
+++ b/gnucash/gnome-utils/dialog-preferences.c
@@ -1229,8 +1229,6 @@ gnc_preferences_dialog_create(GtkWindow *parent)
gnc_builder_add_from_file (builder, "dialog-preferences.glade", "retain_days_adj");
gnc_builder_add_from_file (builder, "dialog-preferences.glade", "tab_width_adj");
gnc_builder_add_from_file (builder, "dialog-preferences.glade", "date_formats");
- gnc_builder_add_from_file (builder, "dialog-preferences.glade", "toolbar-styles");
- gnc_builder_add_from_file (builder, "dialog-preferences.glade", "toolbar-icon-sizes");
gnc_builder_add_from_file (builder, "dialog-preferences.glade", "gnucash_preferences_dialog");
dialog = GTK_WIDGET(gtk_builder_get_object (builder, "gnucash_preferences_dialog"));
diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c
index 8089191..ae4505f 100644
--- a/gnucash/gnome-utils/gnc-main-window.c
+++ b/gnucash/gnome-utils/gnc-main-window.c
@@ -3340,28 +3340,6 @@ gnc_main_window_update_tab_position (gpointer prefs, gchar *pref, gpointer user_
LEAVE ("");
}
-static void
-gnc_main_window_update_toolbar (gpointer prefs, gchar *pref, gpointer user_data)
-{
- GncMainWindow *window;
- GtkToolbar *tb;
- GncMainWindowPrivate *priv;
- gint selection;
-
- window = GNC_MAIN_WINDOW(user_data);
- priv = GNC_MAIN_WINDOW_GET_PRIVATE (window);
- tb = GTK_TOOLBAR(priv->toolbar);
-
- selection = gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_STYLE);
- if (gtk_toolbar_get_style (tb) != selection)
- gtk_toolbar_set_style (tb, selection);
-
- selection = gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_ICON_SIZE);
- // prefs has only small and large icons so add 2 to get right enum
- if (gtk_toolbar_get_icon_size (tb) != selection + 2)
- gtk_toolbar_set_icon_size (tb, selection + 2);
-}
-
/*
* Based on code from Epiphany (src/ephy-window.c)
*/
@@ -3728,13 +3706,6 @@ gnc_main_window_setup_window (GncMainWindow *window)
GNC_PREF_TAB_POSITION_RIGHT,
gnc_main_window_update_tab_position,
window);
-
- gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_STYLE,
- gnc_main_window_update_toolbar, window);
-
- gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_ICON_SIZE,
- gnc_main_window_update_toolbar, window);
-
gnc_main_window_update_tab_position(NULL, NULL, window);
gnc_main_window_init_menu_updaters(window);
@@ -3867,13 +3838,6 @@ gnc_main_window_add_widget (GtkUIManager *merge,
if (GTK_IS_TOOLBAR (widget))
{
priv->toolbar = widget;
-
- gtk_toolbar_set_style (GTK_TOOLBAR(priv->toolbar),
- gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_STYLE));
-
- // prefs has only small and large icons so add 2 to get right enum
- gtk_toolbar_set_icon_size (GTK_TOOLBAR(priv->toolbar),
- (gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_ICON_SIZE)) + 2);
}
gtk_box_pack_start (GTK_BOX (priv->menu_dock), widget, FALSE, FALSE, 0);
diff --git a/gnucash/gschemas/org.gnucash.gschema.xml.in b/gnucash/gschemas/org.gnucash.gschema.xml.in
index 8d924c0..6a0bfe2 100644
--- a/gnucash/gschemas/org.gnucash.gschema.xml.in
+++ b/gnucash/gschemas/org.gnucash.gschema.xml.in
@@ -210,16 +210,6 @@
<summary>Display the notebook tabs at the right of the window.</summary>
<description>This setting determines the edge at which the tabs for switching pages in notebooks are drawn. Possible values are "top", "left", "bottom" and "right". It defaults to "top".</description>
</key>
- <key name="toolbar-style" type="i">
- <default>3</default>
- <summary>Toolbar Style choice</summary>
- <description>This setting controls how the toolbar icons are displayed.</description>
- </key>
- <key name="toolbar-icon-size" type="i">
- <default>1</default>
- <summary>Toolbar Icon Size</summary>
- <description>This setting controls the size of the toolbar icons.</description>
- </key>
<key name="summarybar-position-top" type="b">
<default>false</default>
<summary>Display the summary bar at the top of the page.</summary>
@@ -351,7 +341,7 @@
<description>This sets the number of characters before auto complete starts for description, notes and memo fields.</description>
</key>
</schema>
-
+
<schema id="org.gnucash.general.report" path="/org/gnucash/general/report/">
<key name="use-new-window" type="b">
<default>false</default>
diff --git a/gnucash/gtkbuilder/dialog-preferences.glade b/gnucash/gtkbuilder/dialog-preferences.glade
index 58dfc66..4b88f4e 100644
--- a/gnucash/gtkbuilder/dialog-preferences.glade
+++ b/gnucash/gtkbuilder/dialog-preferences.glade
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.4 -->
+<!-- Generated with glade 3.20.2 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="auto_decimal_places_adj">
@@ -97,40 +97,6 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
- <object class="GtkListStore" id="toolbar-icon-sizes">
- <columns>
- <!-- column-name sizes-text -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0" translatable="yes">Small Icons</col>
- </row>
- <row>
- <col id="0" translatable="yes">Large Icons</col>
- </row>
- </data>
- </object>
- <object class="GtkListStore" id="toolbar-styles">
- <columns>
- <!-- column-name styles-text -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0" translatable="yes">Icons</col>
- </row>
- <row>
- <col id="0" translatable="yes">Text</col>
- </row>
- <row>
- <col id="0" translatable="yes">Icons and Text</col>
- </row>
- <row>
- <col id="0" translatable="yes">Icons and Important Text</col>
- </row>
- </data>
- </object>
<object class="GtkDialog" id="gnucash_preferences_dialog">
<property name="can_focus">False</property>
<property name="title" translatable="yes">GnuCash Preferences</property>
@@ -3275,114 +3241,6 @@ many months before the current month:</property>
</packing>
</child>
<child>
- <object class="GtkComboBox" id="pref/general/toolbar-icon-size">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="has_tooltip">True</property>
- <property name="tooltip_markup">Specify the icon size for the toolbars.</property>
- <property name="tooltip_text" translatable="yes">Specify the icon size for the toolbars.</property>
- <property name="halign">start</property>
- <property name="margin_left">12</property>
- <property name="model">toolbar-icon-sizes</property>
- <property name="active">1</property>
- <property name="id_column">0</property>
- <child>
- <object class="GtkCellRendererText" id="toolbar-icon-renderer"/>
- <attributes>
- <attribute name="text">0</attribute>
- </attributes>
- </child>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">15</property>
- <property name="width">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBox" id="pref/general/toolbar-style">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="has_tooltip">True</property>
- <property name="tooltip_markup">Change the way the toolbar items are displayed.</property>
- <property name="tooltip_text" translatable="yes">Change the way the toolbar items are displayed.</property>
- <property name="halign">start</property>
- <property name="margin_left">12</property>
- <property name="model">toolbar-styles</property>
- <property name="active">3</property>
- <property name="id_column">0</property>
- <child>
- <object class="GtkCellRendererText" id="toolbar-style-renderer"/>
- <attributes>
- <attribute name="text">0</attribute>
- </attributes>
- </child>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">18</property>
- <property name="width">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label22">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="label" translatable="yes"><b>Toolbar Icon Size</b></property>
- <property name="use_markup">True</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">14</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label23">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="label" translatable="yes"><b>Toolbar Style</b></property>
- <property name="use_markup">True</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">17</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label24">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">13</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label25">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">16</property>
- </packing>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
<placeholder/>
</child>
<child>
diff --git a/libgnucash/core-utils/gnc-prefs.h b/libgnucash/core-utils/gnc-prefs.h
index 4c9137c..41c241d 100644
--- a/libgnucash/core-utils/gnc-prefs.h
+++ b/libgnucash/core-utils/gnc-prefs.h
@@ -71,8 +71,6 @@
#define GNC_PREF_DATE_BACKMONTHS "date-backmonths"
#define GNC_PREF_SHOW_LEAF_ACCT_NAMES "show-leaf-account-names"
#define GNC_PREF_ENTER_MOVES_TO_END "enter-moves-to-end"
-#define GNC_PREF_TOOLBAR_STYLE "toolbar-style"
-#define GNC_PREF_TOOLBAR_ICON_SIZE "toolbar-icon-size"
/* Register preferences */
#define GNC_PREF_DRAW_HOR_LINES "draw-horizontal-lines"
#define GNC_PREF_DRAW_VERT_LINES "draw-vertical-lines"
commit fe371534c2e2c0f0d39e555754877f80532b53f2
Author: Geert Janssens <geert at kobaltwit.be>
Date: Tue Jul 31 17:29:52 2018 +0200
Revert "Add toolbar preference changes to embedded-window."
This reverts commit a75eb4c8ec2668e4e79895b2923ca6a816c90fe1.
diff --git a/gnucash/gnome-utils/gnc-embedded-window.c b/gnucash/gnome-utils/gnc-embedded-window.c
index c32d1de..605d7dd 100644
--- a/gnucash/gnome-utils/gnc-embedded-window.c
+++ b/gnucash/gnome-utils/gnc-embedded-window.c
@@ -1,6 +1,6 @@
/*
* gnc-main-window.c -- GtkWindow which represents the
- * GnuCash main window.
+ * GnuCash main window.
*
* Copyright (C) 2003 Jan Arne Petersen <jpetersen at uni-bonn.de>
* Copyright (C) 2003 David Hampton <hampton at employees.org>
@@ -38,7 +38,6 @@
#include "gnc-plugin-manager.h"
#include "gnc-ui.h"
#include "gnc-window.h"
-#include "gnc-prefs.h"
#include "dialog-utils.h"
/* Static Globals *******************************************************/
@@ -309,13 +308,6 @@ gnc_embedded_window_add_widget (GtkUIManager *merge,
if (GTK_IS_TOOLBAR (widget))
{
priv->toolbar = widget;
-
- gtk_toolbar_set_style (GTK_TOOLBAR(priv->toolbar),
- gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_STYLE));
-
- // prefs has only small and large icons so add 2 to get right enum
- gtk_toolbar_set_icon_size (GTK_TOOLBAR(priv->toolbar),
- (gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_ICON_SIZE)) + 2);
}
gtk_box_pack_start (GTK_BOX (priv->menu_dock), widget, FALSE, FALSE, 0);
commit 2203118d99f28a08f29af20e163e26ee61fb1fa9
Author: Geert Janssens <geert at kobaltwit.be>
Date: Tue Jul 31 17:29:38 2018 +0200
Revert "Add the toolbar preference changes to window-reconcile."
This reverts commit 0199fef5847fc60f5ed36e1dcf9cc4ed0717dedc.
diff --git a/gnucash/gnome/window-reconcile.c b/gnucash/gnome/window-reconcile.c
index 1bcf896..4446eb1 100644
--- a/gnucash/gnome/window-reconcile.c
+++ b/gnucash/gnome/window-reconcile.c
@@ -81,8 +81,6 @@ struct _RecnWindow
GtkUIManager *ui_merge;
GtkActionGroup *action_group;
- GtkWidget *dock;
- GtkWidget *toolbar;
GtkWidget *starting; /* The starting balance */
GtkWidget *ending; /* The ending balance */
@@ -1681,44 +1679,13 @@ recnWindow (GtkWidget *parent, Account *account)
static void
recnWindow_add_widget (GtkUIManager *merge,
GtkWidget *widget,
- RecnWindow *recnData)
+ GtkBox *dock)
{
-
- if (GTK_IS_TOOLBAR (widget))
- {
- recnData->toolbar = widget;
-
- gtk_toolbar_set_style (GTK_TOOLBAR(widget),
- gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_STYLE));
-
- // prefs has only small and large icons so add 2 to get right enum
- gtk_toolbar_set_icon_size (GTK_TOOLBAR(widget),
- (gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_ICON_SIZE)) + 2);
- }
-
- gtk_box_pack_start (GTK_BOX (recnData->dock), widget, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (dock), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
}
-static void
-recn_window_update_toolbar (gpointer prefs, gchar *pref, RecnWindow *recnData)
-{
- GtkToolbar *tb;
- gint selection;
-
- tb = GTK_TOOLBAR(recnData->toolbar);
-
- selection = gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_STYLE);
- if (gtk_toolbar_get_style (tb) != selection)
- gtk_toolbar_set_style (tb, selection);
-
- selection = gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_ICON_SIZE);
- // prefs has only small and large icons so add 2 to get right enum
- if (gtk_toolbar_get_icon_size (tb) != selection + 2)
- gtk_toolbar_set_icon_size (tb, selection + 2);
-}
-
/********************************************************************\
* recnWindowWithBalance
*
@@ -1785,9 +1752,8 @@ recnWindowWithBalance (Account *account, gnc_numeric new_ending,
GError *error = NULL;
recnData->ui_merge = gtk_ui_manager_new ();
- recnData->dock = dock;
g_signal_connect (recnData->ui_merge, "add_widget",
- G_CALLBACK (recnWindow_add_widget), recnData);
+ G_CALLBACK (recnWindow_add_widget), dock);
action_group = gtk_action_group_new ("ReconcileWindowActions");
recnData->action_group = action_group;
@@ -1965,13 +1931,6 @@ recnWindowWithBalance (Account *account, gnc_numeric new_ending,
recnRefresh (recnData);
}
- /* track toolbar preference changes */
- gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_STYLE,
- recn_window_update_toolbar, recnData);
-
- gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_ICON_SIZE,
- recn_window_update_toolbar, recnData);
-
/* Allow resize */
gtk_window_set_resizable(GTK_WINDOW(recnData->window), TRUE);
gtk_widget_show_all(recnData->window);
@@ -2055,12 +2014,6 @@ recn_destroy_cb (GtkWidget *w, gpointer data)
if (recnData->delete_refresh)
gnc_resume_gui_refresh ();
- gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_STYLE,
- recn_window_update_toolbar, recnData);
-
- gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TOOLBAR_ICON_SIZE,
- recn_window_update_toolbar, recnData);
-
g_free (recnData);
}
commit cd7a55a9ccdb8b79ae439eea6913a4eb1ef5dc4a
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sun Jul 29 12:57:59 2018 +0100
Fix Transient parent warnings in search dialogue
diff --git a/gnucash/gnome-search/dialog-search.c b/gnucash/gnome-search/dialog-search.c
index ece51d9..eebd106 100644
--- a/gnucash/gnome-search/dialog-search.c
+++ b/gnucash/gnome-search/dialog-search.c
@@ -716,6 +716,8 @@ attach_element (GtkWidget *element, GNCSearchWindow *sw, int row)
data = g_object_get_data (G_OBJECT (element), "data");
+ gnc_search_core_type_pass_parent (data->element, GTK_WINDOW(sw->dialog));
+
gtk_grid_attach (GTK_GRID (sw->criteria_table), element, 0, row, 1, 1);
gtk_widget_set_hexpand (element, TRUE);
gtk_widget_set_halign (element, GTK_ALIGN_FILL);
@@ -774,6 +776,8 @@ combo_box_changed (GtkComboBox *combo_box, struct _crit_data *data)
FALSE, FALSE, 0);
}
+ gnc_search_core_type_pass_parent (data->element, GTK_WINDOW(data->dialog));
+
/* Make sure it's visible */
gtk_widget_show_all (data->container);
diff --git a/gnucash/gnome-search/search-account.c b/gnucash/gnome-search/search-account.c
index faf53f2..429e525 100644
--- a/gnucash/gnome-search/search-account.c
+++ b/gnucash/gnome-search/search-account.c
@@ -39,6 +39,7 @@
#define d(x)
+static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
static gboolean gncs_validate (GNCSearchCoreType *fe);
static GtkWidget *gncs_get_widget(GNCSearchCoreType *fe);
@@ -54,6 +55,7 @@ struct _GNCSearchAccountPrivate
{
gboolean match_all;
GList * selected_accounts;
+ GtkWindow *parent;
};
#define _PRIVATE(o) \
@@ -102,6 +104,7 @@ gnc_search_account_class_init (GNCSearchAccountClass *klass)
object_class->finalize = gnc_search_account_finalize;
/* override methods */
+ gnc_search_core_type->pass_parent = pass_parent;
gnc_search_core_type->validate = gncs_validate;
gnc_search_core_type->get_widget = gncs_get_widget;
gnc_search_core_type->get_predicate = gncs_get_predicate;
@@ -170,10 +173,11 @@ gncs_validate (GNCSearchCoreType *fe)
g_return_val_if_fail (IS_GNCSEARCH_ACCOUNT (fi), FALSE);
priv = _PRIVATE(fi);
+
if (priv->selected_accounts == NULL && fi->how )
{
valid = FALSE;
- gnc_error_dialog (NULL, "%s", _("You have not selected any accounts"));
+ gnc_error_dialog (GTK_WINDOW(priv->parent), "%s", _("You have not selected any accounts"));
}
/* XXX */
@@ -257,7 +261,7 @@ button_clicked (GtkButton *button, GNCSearchAccount *fi)
/* Create the dialog */
dialog =
GTK_DIALOG(gtk_dialog_new_with_buttons(_("Select the Accounts to Compare"),
- NULL,
+ GTK_WINDOW(priv->parent),
0,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_OK"), GTK_RESPONSE_OK,
@@ -356,3 +360,16 @@ static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe)
return (GNCSearchCoreType *)se;
}
+
+static void
+pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNCSearchAccount *fi = (GNCSearchAccount *)fe;
+ GNCSearchAccountPrivate *priv;
+
+ g_return_if_fail (fi);
+ g_return_if_fail (IS_GNCSEARCH_ACCOUNT (fi));
+
+ priv = _PRIVATE(fi);
+ priv->parent = GTK_WINDOW(parent);
+}
diff --git a/gnucash/gnome-search/search-boolean.c b/gnucash/gnome-search/search-boolean.c
index a784c12..caecd6b 100644
--- a/gnucash/gnome-search/search-boolean.c
+++ b/gnucash/gnome-search/search-boolean.c
@@ -35,6 +35,7 @@
#define d(x)
+static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
static gboolean gncs_validate (GNCSearchCoreType *fe);
static GtkWidget *gncs_get_widget(GNCSearchCoreType *fe);
@@ -48,6 +49,7 @@ typedef struct _GNCSearchBooleanPrivate GNCSearchBooleanPrivate;
struct _GNCSearchBooleanPrivate
{
+ GtkWindow *parent;
gpointer dummy;
};
@@ -96,6 +98,7 @@ gnc_search_boolean_class_init (GNCSearchBooleanClass *klass)
object_class->finalize = gnc_search_boolean_finalize;
/* override methods */
+ gnc_search_core_type->pass_parent = pass_parent;
gnc_search_core_type->validate = gncs_validate;
gnc_search_core_type->get_widget = gncs_get_widget;
gnc_search_core_type->get_predicate = gncs_get_predicate;
@@ -142,6 +145,19 @@ gnc_search_boolean_set_value (GNCSearchBoolean *fi, gboolean value)
fi->value = value;
}
+static void
+pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNCSearchBoolean *fi = (GNCSearchBoolean *)fe;
+ GNCSearchBooleanPrivate *priv;
+
+ g_return_if_fail (fi);
+ g_return_if_fail (IS_GNCSEARCH_BOOLEAN (fi));
+
+ priv = _PRIVATE(fi);
+ priv->parent = GTK_WINDOW(parent);
+}
+
static gboolean
gncs_validate (GNCSearchCoreType *fe)
{
diff --git a/gnucash/gnome-search/search-core-type.c b/gnucash/gnome-search/search-core-type.c
index b9fbb31..37424ee 100644
--- a/gnucash/gnome-search/search-core-type.c
+++ b/gnucash/gnome-search/search-core-type.c
@@ -149,6 +149,12 @@ gnc_search_core_type_grab_focus (GNCSearchCoreType *fe)
GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->grab_focus (fe);
}
+void
+gnc_search_core_type_pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->pass_parent (fe, parent);
+}
+
gboolean
gnc_search_core_type_validate (GNCSearchCoreType *fe)
{
diff --git a/gnucash/gnome-search/search-core-type.h b/gnucash/gnome-search/search-core-type.h
index 921bc3a..4abd856 100644
--- a/gnucash/gnome-search/search-core-type.h
+++ b/gnucash/gnome-search/search-core-type.h
@@ -46,6 +46,7 @@ typedef struct
/* virtual methods */
void (*grab_focus) (GNCSearchCoreType *fe);
void (*editable_enters) (GNCSearchCoreType *fe);
+ void (*pass_parent) (GNCSearchCoreType *fe, gpointer parent);
gboolean (*validate) (GNCSearchCoreType *fe);
GNCSearchCoreType * (*clone) (GNCSearchCoreType *fe);
GtkWidget * (*get_widget) (GNCSearchCoreType *);
@@ -64,6 +65,7 @@ GNCSearchCoreType * gnc_search_core_type_new_type_name (const char *type);
/* methods */
void gnc_search_core_type_grab_focus (GNCSearchCoreType *fe);
void gnc_search_core_type_editable_enters (GNCSearchCoreType *fe);
+void gnc_search_core_type_pass_parent (GNCSearchCoreType *fe, gpointer parent);
gboolean gnc_search_core_type_validate (GNCSearchCoreType *fe);
GNCSearchCoreType * gnc_search_core_type_clone (GNCSearchCoreType *fe);
GtkWidget * gnc_search_core_type_get_widget (GNCSearchCoreType *fe);
diff --git a/gnucash/gnome-search/search-date.c b/gnucash/gnome-search/search-date.c
index 9523c3f..af85414 100644
--- a/gnucash/gnome-search/search-date.c
+++ b/gnucash/gnome-search/search-date.c
@@ -37,6 +37,7 @@
#define d(x)
+static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
static void editable_enters (GNCSearchCoreType *fe);
static void grab_focus (GNCSearchCoreType *fe);
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
@@ -53,6 +54,7 @@ typedef struct _GNCSearchDatePrivate GNCSearchDatePrivate;
struct _GNCSearchDatePrivate
{
GtkWidget *entry;
+ GtkWindow *parent;
};
#define _PRIVATE(o) \
@@ -100,6 +102,7 @@ gnc_search_date_class_init (GNCSearchDateClass *klass)
object_class->finalize = gnc_search_date_finalize;
/* override methods */
+ gnc_search_core_type->pass_parent = pass_parent;
gnc_search_core_type->editable_enters = editable_enters;
gnc_search_core_type->grab_focus = grab_focus;
gnc_search_core_type->validate = gncs_validate;
@@ -164,6 +167,19 @@ gnc_search_date_set_how (GNCSearchDate *fi, QofQueryCompare how)
fi->how = how;
}
+static void
+pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNCSearchDate *fi = (GNCSearchDate *)fe;
+ GNCSearchDatePrivate *priv;
+
+ g_return_if_fail (fi);
+ g_return_if_fail (IS_GNCSEARCH_DATE (fi));
+
+ priv = _PRIVATE(fi);
+ priv->parent = GTK_WINDOW(parent);
+}
+
static gboolean
gncs_validate (GNCSearchCoreType *fe)
{
diff --git a/gnucash/gnome-search/search-double.c b/gnucash/gnome-search/search-double.c
index e6c45ff..191b270 100644
--- a/gnucash/gnome-search/search-double.c
+++ b/gnucash/gnome-search/search-double.c
@@ -36,6 +36,7 @@
#define d(x)
+static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
static void editable_enters (GNCSearchCoreType *fe);
static void grab_focus (GNCSearchCoreType *fe);
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
@@ -53,6 +54,7 @@ struct _GNCSearchDoublePrivate
{
GtkWidget * entry;
GNCAmountEdit *gae;
+ GtkWindow *parent;
};
#define _PRIVATE(o) \
@@ -100,6 +102,7 @@ gnc_search_double_class_init (GNCSearchDoubleClass *klass)
object_class->finalize = gnc_search_double_finalize;
/* override methods */
+ gnc_search_core_type->pass_parent = pass_parent;
gnc_search_core_type->editable_enters = editable_enters;
gnc_search_core_type->grab_focus = grab_focus;
gnc_search_core_type->validate = gncs_validate;
@@ -156,6 +159,19 @@ gnc_search_double_set_how (GNCSearchDouble *fi, QofQueryCompare how)
fi->how = how;
}
+static void
+pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNCSearchDouble *fi = (GNCSearchDouble *)fe;
+ GNCSearchDoublePrivate *priv;
+
+ g_return_if_fail (fi);
+ g_return_if_fail (IS_GNCSEARCH_DOUBLE (fi));
+
+ priv = _PRIVATE(fi);
+ priv->parent = GTK_WINDOW(parent);
+}
+
static gboolean
gncs_validate (GNCSearchCoreType *fe)
{
diff --git a/gnucash/gnome-search/search-int64.c b/gnucash/gnome-search/search-int64.c
index bc94f61..a1c3f7f 100644
--- a/gnucash/gnome-search/search-int64.c
+++ b/gnucash/gnome-search/search-int64.c
@@ -36,6 +36,7 @@
#define d(x)
+static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
static void editable_enters (GNCSearchCoreType *fe);
static void grab_focus (GNCSearchCoreType *fe);
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
@@ -54,6 +55,7 @@ struct _GNCSearchInt64Private
{
GtkWidget *entry;
GNCAmountEdit *gae;
+ GtkWindow *parent;
};
#define _PRIVATE(o) \
@@ -101,6 +103,7 @@ gnc_search_int64_class_init (GNCSearchInt64Class *klass)
object_class->finalize = gnc_search_int64_finalize;
/* override methods */
+ gnc_search_core_type->pass_parent = pass_parent;
gnc_search_core_type->editable_enters = editable_enters;
gnc_search_core_type->grab_focus = grab_focus;
gnc_search_core_type->validate = gncs_validate;
@@ -157,6 +160,19 @@ gnc_search_int64_set_how (GNCSearchInt64 *fi, QofQueryCompare how)
fi->how = how;
}
+static void
+pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNCSearchInt64 *fi = (GNCSearchInt64 *)fe;
+ GNCSearchInt64Private *priv;
+
+ g_return_if_fail (fi);
+ g_return_if_fail (IS_GNCSEARCH_INT64 (fi));
+
+ priv = _PRIVATE(fi);
+ priv->parent = GTK_WINDOW(parent);
+}
+
static gboolean
gncs_validate (GNCSearchCoreType *fe)
{
diff --git a/gnucash/gnome-search/search-numeric.c b/gnucash/gnome-search/search-numeric.c
index 582e17c..97d0b4f 100644
--- a/gnucash/gnome-search/search-numeric.c
+++ b/gnucash/gnome-search/search-numeric.c
@@ -36,6 +36,7 @@
#define d(x)
+static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
static void editable_enters (GNCSearchCoreType *fe);
static void grab_focus (GNCSearchCoreType *fe);
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
@@ -54,6 +55,7 @@ struct _GNCSearchNumericPrivate
gboolean is_debcred;
GtkWidget * entry;
GNCAmountEdit *gae;
+ GtkWindow *parent;
};
#define _PRIVATE(o) \
@@ -101,6 +103,7 @@ gnc_search_numeric_class_init (GNCSearchNumericClass *klass)
object_class->finalize = gnc_search_numeric_finalize;
/* override methods */
+ gnc_search_core_type->pass_parent = pass_parent;
gnc_search_core_type->editable_enters = editable_enters;
gnc_search_core_type->grab_focus = grab_focus;
gnc_search_core_type->validate = gncs_validate;
@@ -186,6 +189,19 @@ gnc_search_numeric_set_option (GNCSearchNumeric *fi, QofNumericMatch option)
fi->option = option;
}
+static void
+pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNCSearchNumeric *fi = (GNCSearchNumeric *)fe;
+ GNCSearchNumericPrivate *priv;
+
+ g_return_if_fail (fi);
+ g_return_if_fail (IS_GNCSEARCH_NUMERIC (fi));
+
+ priv = _PRIVATE(fi);
+ priv->parent = GTK_WINDOW(parent);
+}
+
static gboolean
gncs_validate (GNCSearchCoreType *fe)
{
diff --git a/gnucash/gnome-search/search-reconciled.c b/gnucash/gnome-search/search-reconciled.c
index 2b9ffe6..565f377 100644
--- a/gnucash/gnome-search/search-reconciled.c
+++ b/gnucash/gnome-search/search-reconciled.c
@@ -36,6 +36,7 @@
#define d(x)
+static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
static gboolean gncs_validate (GNCSearchCoreType *fe);
static GtkWidget *gncs_get_widget(GNCSearchCoreType *fe);
@@ -49,6 +50,7 @@ typedef struct _GNCSearchReconciledPrivate GNCSearchReconciledPrivate;
struct _GNCSearchReconciledPrivate
{
+ GtkWindow *parent;
gpointer dummy;
};
@@ -97,6 +99,7 @@ gnc_search_reconciled_class_init (GNCSearchReconciledClass *klass)
object_class->finalize = gnc_search_reconciled_finalize;
/* override methods */
+ gnc_search_core_type->pass_parent = pass_parent;
gnc_search_core_type->validate = gncs_validate;
gnc_search_core_type->get_widget = gncs_get_widget;
gnc_search_core_type->get_predicate = gncs_get_predicate;
@@ -152,6 +155,19 @@ gnc_search_reconciled_set_how (GNCSearchReconciled *fi, QofCharMatch how)
fi->how = how;
}
+static void
+pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNCSearchReconciled *fi = (GNCSearchReconciled *)fe;
+ GNCSearchReconciledPrivate *priv;
+
+ g_return_if_fail (fi);
+ g_return_if_fail (IS_GNCSEARCH_RECONCILED (fi));
+
+ priv = _PRIVATE(fi);
+ priv->parent = GTK_WINDOW(parent);
+}
+
static gboolean
gncs_validate (GNCSearchCoreType *fe)
{
diff --git a/gnucash/gnome-search/search-string.c b/gnucash/gnome-search/search-string.c
index 1ba224c..6ccfe4e 100644
--- a/gnucash/gnome-search/search-string.c
+++ b/gnucash/gnome-search/search-string.c
@@ -38,6 +38,7 @@
#define d(x)
static void editable_enters (GNCSearchCoreType *fe);
+static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
static void grab_focus (GNCSearchCoreType *fe);
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
static gboolean gncs_validate (GNCSearchCoreType *fe);
@@ -53,6 +54,7 @@ typedef struct _GNCSearchStringPrivate GNCSearchStringPrivate;
struct _GNCSearchStringPrivate
{
GtkWidget *entry;
+ GtkWindow *parent;
};
#define _PRIVATE(o) \
@@ -101,6 +103,7 @@ gnc_search_string_class_init (GNCSearchStringClass *klass)
/* override methods */
gnc_search_core_type->editable_enters = editable_enters;
+ gnc_search_core_type->pass_parent = pass_parent;
gnc_search_core_type->grab_focus = grab_focus;
gnc_search_core_type->validate = gncs_validate;
gnc_search_core_type->get_widget = gncs_get_widget;
@@ -175,15 +178,18 @@ static gboolean
gncs_validate (GNCSearchCoreType *fe)
{
GNCSearchString *fi = (GNCSearchString *)fe;
+ GNCSearchStringPrivate *priv;
gboolean valid = TRUE;
g_return_val_if_fail (fi, FALSE);
g_return_val_if_fail (IS_GNCSEARCH_STRING (fi), FALSE);
+ priv = _PRIVATE(fi);
+
if (!fi->value || *(fi->value) == '\0')
{
GtkWidget *dialog;
- dialog = gtk_message_dialog_new (NULL,
+ dialog = gtk_message_dialog_new (GTK_WINDOW(priv->parent),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
@@ -221,7 +227,7 @@ gncs_validate (GNCSearchCoreType *fe)
fi->value, regmsg);
g_free (regmsg);
- dialog = gtk_message_dialog_new (NULL,
+ dialog = gtk_message_dialog_new (GTK_WINDOW(priv->parent),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
@@ -301,6 +307,19 @@ editable_enters (GNCSearchCoreType *fe)
gtk_entry_set_activates_default(GTK_ENTRY (priv->entry), TRUE);
}
+static void
+pass_parent (GNCSearchCoreType *fe, gpointer parent)
+{
+ GNCSearchString *fi = (GNCSearchString *)fe;
+ GNCSearchStringPrivate *priv;
+
+ g_return_if_fail (fi);
+ g_return_if_fail (IS_GNCSEARCH_STRING (fi));
+
+ priv = _PRIVATE(fi);
+ priv->parent = GTK_WINDOW(parent);
+}
+
static GtkWidget *
gncs_get_widget (GNCSearchCoreType *fe)
{
commit e851f249fc525fd0d2e6d505e43b0c8ce5ffb090
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sat Jul 28 17:53:31 2018 +0100
Fix gnc_window_adjust_for_screen using incorrect monitor
This function was always using the primary monitor to get monitor size
so corrected to use the monitor at the specified window coordinates.
diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c
index 3cc8d84..d4de396 100644
--- a/gnucash/gnome-utils/dialog-utils.c
+++ b/gnucash/gnome-utils/dialog-utils.c
@@ -240,16 +240,21 @@ gnc_save_window_size(const char *group, GtkWindow *window)
void
gnc_window_adjust_for_screen(GtkWindow * window)
{
-#if GTK_CHECK_VERSION(3,22,0)
- GdkWindow *win;
- GdkMonitor *mon;
GdkRectangle monitor_size;
-#endif
- gint screen_width;
- gint screen_height;
+ gint wpos[2];
gint width;
gint height;
+#if GTK_CHECK_VERSION(3,22,0)
+ GdkDisplay *display = gdk_display_get_default ();
+ GdkMonitor *mon;
+#else
+ GdkScreen *screen = gdk_screen_get_default ();
+ gint mon_num;
+#endif
+
+ ENTER("");
+
if (window == NULL)
return;
@@ -257,31 +262,50 @@ gnc_window_adjust_for_screen(GtkWindow * window)
if (gtk_widget_get_window (GTK_WIDGET(window)) == NULL)
return;
+ gtk_window_get_position(GTK_WINDOW(window), &wpos[0], &wpos[1]);
+ gtk_window_get_size(GTK_WINDOW(window), &width, &height);
+
#if GTK_CHECK_VERSION(3,22,0)
- win = gdk_screen_get_root_window (gtk_window_get_screen (window));
- mon = gdk_display_get_monitor_at_window (gtk_widget_get_display (GTK_WIDGET(window)), win);
+ mon = gdk_display_get_monitor_at_point (display, wpos[0], wpos[1]);
gdk_monitor_get_geometry (mon, &monitor_size);
-
- screen_width = monitor_size.width;
- screen_height = monitor_size.height;
#else
- screen_width = gdk_screen_width();
- screen_height = gdk_screen_height();
+ mon_num = gdk_screen_get_monitor_at_point (screen, wpos[0], wpos[1]);
+ gdk_screen_get_monitor_geometry (screen, mon_num, &monitor_size);
#endif
- width = gdk_window_get_width (gtk_widget_get_window (GTK_WIDGET(window)));
- height = gdk_window_get_height (gtk_widget_get_window (GTK_WIDGET(window)));
- if ((width <= screen_width) && (height <= screen_height))
+ DEBUG("monitor width is %d, height is %d; wwindow width is %d, height is %d",
+ monitor_size.width, monitor_size.height, width, height);
+
+ if ((width <= monitor_size.width) && (height <= monitor_size.height))
return;
- width = MIN(width, screen_width - 10);
- width = MAX(width, 0);
+ /* Keep the window on screen if possible */
+ if (wpos[0] - monitor_size.x + width > monitor_size.x + monitor_size.width)
+ wpos[0] = monitor_size.x + monitor_size.width - width;
+
+ if (wpos[1] - monitor_size.y + height > monitor_size.y + monitor_size.height)
+ wpos[1] = monitor_size.y + monitor_size.height - height;
+
+ /* make sure the cordinates have not left the monitor */
+ if (wpos[0] < monitor_size.x)
+ wpos[0] = monitor_size.x;
- height = MIN(height, screen_height - 10);
- height = MAX(height, 0);
+ if (wpos[1] < monitor_size.y)
+ wpos[1] = monitor_size.y;
- gdk_window_resize(gtk_widget_get_window (GTK_WIDGET(window)), width, height);
+ DEBUG("move window to position %d, %d", wpos[0], wpos[1]);
+
+ gtk_window_move(window, wpos[0], wpos[1]);
+
+ /* if window is bigger, set it to monitor sizes */
+ width = MIN(width, monitor_size.width - 10);
+ height = MIN(height, monitor_size.height - 10);
+
+ DEBUG("resize window to width %d, height %d", width, height);
+
+ gtk_window_resize(GTK_WINDOW(window), width, height);
gtk_widget_queue_resize(GTK_WIDGET(window));
+ LEAVE("");
}
/********************************************************************\
commit 099b659b4b002311a9aa07d4622998f396c2d588
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sat Jul 28 17:52:44 2018 +0100
Add debug message to gnc_save_window_size and some text changes
diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c
index 406a091..3cc8d84 100644
--- a/gnucash/gnome-utils/dialog-utils.c
+++ b/gnucash/gnome-utils/dialog-utils.c
@@ -195,7 +195,7 @@ gnc_restore_window_size(const char *group, GtkWindow *window, GtkWindow *parent)
/********************************************************************\
* gnc_save_window_size *
* save the window position and size into options whose names are *
- * prefixed by the group name. *
+ * prefixed by the group name. *
* *
* Args: group - preferences group to save the options in *
* window - the window for which current position and size *
@@ -208,6 +208,8 @@ gnc_save_window_size(const char *group, GtkWindow *window)
gint wpos[2], wsize[2];
GVariant *geometry;
+ ENTER("");
+
g_return_if_fail(group != NULL);
g_return_if_fail(window != NULL);
@@ -216,10 +218,15 @@ gnc_save_window_size(const char *group, GtkWindow *window)
gtk_window_get_position(GTK_WINDOW(window), &wpos[0], &wpos[1]);
gtk_window_get_size(GTK_WINDOW(window), &wsize[0], &wsize[1]);
+
+ DEBUG("save geometry - wpos[0]: %d, wpos[1]: %d, wsize[0]: %d, wsize[1]: %d",
+ wpos[0], wpos[1], wsize[0], wsize[1]);
+
geometry = g_variant_new ("(iiii)", wpos[0], wpos[1],
wsize[0], wsize[1]);
gnc_prefs_set_value (group, GNC_PREF_LAST_GEOMETRY, geometry);
/* Don't unref geometry here, it is consumed by gnc_prefs_set_value */
+ LEAVE("");
}
diff --git a/gnucash/gnome-utils/dialog-utils.h b/gnucash/gnome-utils/dialog-utils.h
index 50611c2..1a93f79 100644
--- a/gnucash/gnome-utils/dialog-utils.h
+++ b/gnucash/gnome-utils/dialog-utils.h
@@ -48,8 +48,7 @@ void gnc_restore_window_size (const char *prefix, GtkWindow *window,
* by the string prefix. *
* *
* Args: prefix - determines the options used to save the values *
- * width - width of the window to save *
- * height - height of the window to save *
+ * window - the window being saved *
* Returns: nothing *
\********************************************************************/
void gnc_save_window_size (const char *section, GtkWindow *window);
commit 8c1adaa28f23770801ff574f5a2b406f75bc92d2
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sat Jul 28 17:51:30 2018 +0100
Fix Transient parent warning for dialog-book-close
diff --git a/gnucash/gnome-utils/dialog-book-close.c b/gnucash/gnome-utils/dialog-book-close.c
index 2d23e41..8cec934 100644
--- a/gnucash/gnome-utils/dialog-book-close.c
+++ b/gnucash/gnome-utils/dialog-book-close.c
@@ -322,7 +322,7 @@ gnc_book_close_response_cb(GtkDialog *dialog, gint response, GtkDialog *unused)
LEAVE("");
}
-void gnc_ui_close_book (QofBook* book)
+void gnc_ui_close_book (QofBook* book, GtkWindow *parent)
{
struct CloseBookWindow *cbw;
GtkBuilder* builder;
@@ -343,6 +343,10 @@ void gnc_ui_close_book (QofBook* book)
// Set the style context for this dialog so it can be easily manipulated with css
gnc_widget_set_style_context (GTK_WIDGET(cbw->dialog), "GncBookCloseDialog");
+ /* parent */
+ if (parent != NULL)
+ gtk_window_set_transient_for (GTK_WINDOW(cbw->dialog), GTK_WINDOW(parent));
+
PINFO("Closed Book Window is %p, Dialog is %p", cbw, cbw->dialog);
/* close date */
diff --git a/gnucash/gnome-utils/dialog-book-close.h b/gnucash/gnome-utils/dialog-book-close.h
index 363c0f1..e8a87de 100644
--- a/gnucash/gnome-utils/dialog-book-close.h
+++ b/gnucash/gnome-utils/dialog-book-close.h
@@ -40,8 +40,9 @@
*
* @param book This parameter specifies the book whose data
* will be closed.
+ * @param parent This parameter specifies the parent window
*/
-void gnc_ui_close_book (QofBook* book);
+void gnc_ui_close_book (QofBook* book, GtkWindow *parent);
/** @} */
diff --git a/gnucash/gnome/gnc-plugin-basic-commands.c b/gnucash/gnome/gnc-plugin-basic-commands.c
index 5e50f6b..566fc97 100644
--- a/gnucash/gnome/gnc-plugin-basic-commands.c
+++ b/gnucash/gnome/gnc-plugin-basic-commands.c
@@ -653,7 +653,7 @@ gnc_main_window_cmd_tools_financial_calculator (GtkAction *action, GncMainWindow
static void
gnc_main_window_cmd_tools_close_book (GtkAction *action, GncMainWindowActionData *data)
{
- gnc_ui_close_book(gnc_get_current_book());
+ gnc_ui_close_book(gnc_get_current_book(), GTK_WINDOW (data->window));
}
static void
commit 68874495e16d5d0a6b78d435438973d9452c29b8
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sat Jul 28 17:50:31 2018 +0100
Change files for changed gnc_restore_window_size format, part2 of 2
Add the parent window to the calling function gnc_restore_window_size
after the change to that function. This required adding the retrieval of
the parent window for the calling dialogues.
diff --git a/gnucash/gnome/dialog-lot-viewer.c b/gnucash/gnome/dialog-lot-viewer.c
index 655ebd7..14f2683 100644
--- a/gnucash/gnome/dialog-lot-viewer.c
+++ b/gnucash/gnome/dialog-lot-viewer.c
@@ -667,7 +667,6 @@ void
lv_window_destroy_cb (GtkWidget *object, gpointer user_data)
{
GNCLotViewer *lv = user_data;
- gnc_close_gui_component_by_data (LOT_VIEWER_CM_CLASS, lv);
gnc_unregister_gui_component_by_data (LOT_VIEWER_CM_CLASS, lv);
g_free (lv);
}
@@ -732,7 +731,7 @@ lv_response_cb (GtkDialog *dialog, gint response, gpointer data)
switch (response)
{
case GTK_RESPONSE_CLOSE:
- lv_close_handler(lv);
+ gnc_close_gui_component_by_data (LOT_VIEWER_CM_CLASS, lv);
return;
case RESPONSE_VIEW:
@@ -979,7 +978,7 @@ lv_init_split_buttons (GNCLotViewer *lv)
/* ======================================================================== */
static void
-lv_create (GNCLotViewer *lv)
+lv_create (GNCLotViewer *lv, GtkWindow *parent)
{
gchar *win_title;
GtkBuilder *builder;
@@ -989,6 +988,8 @@ lv_create (GNCLotViewer *lv)
lv->window = GTK_WIDGET(gtk_builder_get_object (builder, "lot_viewer_dialog"));
+ gtk_window_set_transient_for (GTK_WINDOW (lv->window), parent);
+
// Set the style context for this dialog so it can be easily manipulated with css
gnc_widget_set_style_context (GTK_WIDGET(lv->window), "GncLotViewerDialog");
@@ -1046,13 +1047,13 @@ lv_create (GNCLotViewer *lv)
lv_update_split_buttons(lv);
- gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(lv->window));
+ gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(lv->window), parent);
}
/* ======================================================================== */
GNCLotViewer *
-gnc_lot_viewer_dialog (Account *account)
+gnc_lot_viewer_dialog (GtkWindow *parent, Account *account)
{
GNCLotViewer *lv;
gint component_id;
@@ -1061,7 +1062,7 @@ gnc_lot_viewer_dialog (Account *account)
lv = g_new0 (GNCLotViewer, 1);
lv->account = account;
- lv_create (lv);
+ lv_create (lv, parent);
gnc_lot_viewer_fill (lv);
lv_show_splits_free (lv);
diff --git a/gnucash/gnome/dialog-lot-viewer.h b/gnucash/gnome/dialog-lot-viewer.h
index 74670b3..77bc0d3 100644
--- a/gnucash/gnome/dialog-lot-viewer.h
+++ b/gnucash/gnome/dialog-lot-viewer.h
@@ -30,6 +30,6 @@
typedef struct _GNCLotViewer GNCLotViewer;
/** Create and realize and show a lot-viewing dialog. */
-GNCLotViewer * gnc_lot_viewer_dialog (Account *);
+GNCLotViewer * gnc_lot_viewer_dialog (GtkWindow *parent, Account *account);
#endif /* LOT_VIEWER_H */
diff --git a/gnucash/gnome/dialog-trans-assoc.c b/gnucash/gnome/dialog-trans-assoc.c
index ce4747a..4003d29 100644
--- a/gnucash/gnome/dialog-trans-assoc.c
+++ b/gnucash/gnome/dialog-trans-assoc.c
@@ -387,7 +387,7 @@ get_trans_info (AssocDialog *assoc_dialog)
}
static void
-gnc_assoc_dialog_create (AssocDialog *assoc_dialog)
+gnc_assoc_dialog_create (GtkWindow *parent, AssocDialog *assoc_dialog)
{
GtkWidget *window;
GtkBuilder *builder;
@@ -475,7 +475,7 @@ gnc_assoc_dialog_create (AssocDialog *assoc_dialog)
g_object_unref (G_OBJECT(builder));
- gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(assoc_dialog->window));
+ gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(assoc_dialog->window), parent);
get_trans_info (assoc_dialog);
gtk_widget_show_all (GTK_WIDGET(window));
@@ -525,7 +525,7 @@ show_handler (const char *klass, gint component_id,
* Return: nothing *
\********************************************************************/
void
-gnc_trans_assoc_dialog (void)
+gnc_trans_assoc_dialog (GtkWindow *parent)
{
AssocDialog *assoc_dialog;
@@ -537,12 +537,11 @@ gnc_trans_assoc_dialog (void)
}
assoc_dialog = g_new0 (AssocDialog, 1);
- gnc_assoc_dialog_create (assoc_dialog);
+ gnc_assoc_dialog_create (parent, assoc_dialog);
gnc_register_gui_component (DIALOG_ASSOC_CM_CLASS,
refresh_handler, close_handler,
assoc_dialog);
-// gtk_widget_show (assoc_dialog->window);
LEAVE(" ");
}
diff --git a/gnucash/gnome/dialog-trans-assoc.h b/gnucash/gnome/dialog-trans-assoc.h
index fa82fcb..c95c5b7 100644
--- a/gnucash/gnome/dialog-trans-assoc.h
+++ b/gnucash/gnome/dialog-trans-assoc.h
@@ -23,6 +23,6 @@
#ifndef DIALOG_TRANS_ASSOC_H
#define DIALOG_TRANS_ASSOC_H
-void gnc_trans_assoc_dialog (void);
+void gnc_trans_assoc_dialog (GtkWindow *parent);
#endif
diff --git a/gnucash/gnome/gnc-plugin-basic-commands.c b/gnucash/gnome/gnc-plugin-basic-commands.c
index c019a72..5e50f6b 100644
--- a/gnucash/gnome/gnc-plugin-basic-commands.c
+++ b/gnucash/gnome/gnc-plugin-basic-commands.c
@@ -624,7 +624,7 @@ static void
gnc_main_window_cmd_tools_trans_assoc (GtkAction *action, GncMainWindowActionData *data)
{
gnc_set_busy_cursor (NULL, TRUE);
- gnc_trans_assoc_dialog ();
+ gnc_trans_assoc_dialog (GTK_WINDOW (data->window));
gnc_unset_busy_cursor (NULL);
}
diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c
index 80478f5..46f9517 100644
--- a/gnucash/gnome/gnc-plugin-page-account-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-account-tree.c
@@ -1749,10 +1749,9 @@ static void
gnc_plugin_page_account_tree_cmd_lots (GtkAction *action,
GncPluginPageAccountTree *page)
{
- Account *account;
-
- account = gnc_plugin_page_account_tree_get_current_account (page);
- gnc_lot_viewer_dialog (account);
+ Account *account = gnc_plugin_page_account_tree_get_current_account (page);
+ GtkWidget *window = GNC_PLUGIN_PAGE (page)->window;
+ gnc_lot_viewer_dialog (GTK_WINDOW(window), account);
}
static void
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index d3e7283..0ebb798 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -3547,14 +3547,16 @@ static void
gnc_plugin_page_register_cmd_lots (GtkAction *action,
GncPluginPageRegister *page)
{
+ GtkWindow *window;
Account *account;
ENTER("(action %p, plugin_page %p)", action, page);
g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(page));
+ window = gnc_window_get_gtk_window(GNC_WINDOW(GNC_PLUGIN_PAGE (page)->window));
account = gnc_plugin_page_register_get_account (page);
- gnc_lot_viewer_dialog (account);
+ gnc_lot_viewer_dialog (window, account);
LEAVE(" ");
}
diff --git a/gnucash/gnome/gnc-plugin-page-register2.c b/gnucash/gnome/gnc-plugin-page-register2.c
index 5021607..464d856 100644
--- a/gnucash/gnome/gnc-plugin-page-register2.c
+++ b/gnucash/gnome/gnc-plugin-page-register2.c
@@ -3347,14 +3347,16 @@ static void
gnc_plugin_page_register2_cmd_lots (GtkAction *action,
GncPluginPageRegister2 *page) // this works
{
+ GtkWindow *window;
Account *account;
ENTER("(action %p, plugin_page %p)", action, page);
g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER2(page));
+ window = gnc_window_get_gtk_window(GNC_WINDOW(GNC_PLUGIN_PAGE (page)->window));
account = gnc_plugin_page_register2_get_account (page);
- gnc_lot_viewer_dialog (account);
+ gnc_lot_viewer_dialog (window, account);
LEAVE(" ");
}
diff --git a/gnucash/gnome/window-reconcile.c b/gnucash/gnome/window-reconcile.c
index 1bcf896..675bff5 100644
--- a/gnucash/gnome/window-reconcile.c
+++ b/gnucash/gnome/window-reconcile.c
@@ -1674,7 +1674,7 @@ recnWindow (GtkWidget *parent, Account *account)
enable_subaccounts))
return NULL;
- return recnWindowWithBalance (account, new_ending, statement_date);
+ return recnWindowWithBalance (parent, account, new_ending, statement_date);
}
@@ -1725,13 +1725,14 @@ recn_window_update_toolbar (gpointer prefs, gchar *pref, RecnWindow *recnData)
* Opens up the window to reconcile an account, but with ending
* balance and statement date already given.
*
- * Args: account - The account to reconcile
+ * Args: parent - The parent widget of the new window
+ * account - The account to reconcile
* new_ending - The amount for ending balance
* statement_date - The date of the statement
* Return: recnData - the instance of this RecnWindow
\********************************************************************/
RecnWindow *
-recnWindowWithBalance (Account *account, gnc_numeric new_ending,
+recnWindowWithBalance (GtkWidget *parent, Account *account, gnc_numeric new_ending,
time64 statement_date)
{
RecnWindow *recnData;
@@ -1849,7 +1850,8 @@ recnWindowWithBalance (Account *account, gnc_numeric new_ending,
/* Force a reasonable starting size */
gtk_window_set_default_size(GTK_WINDOW(recnData->window), 800, 600);
- gnc_restore_window_size (GNC_PREFS_GROUP_RECONCILE, GTK_WINDOW(recnData->window));
+ gnc_restore_window_size (GNC_PREFS_GROUP_RECONCILE,
+ GTK_WINDOW(recnData->window), GTK_WINDOW(parent));
gtk_container_add(GTK_CONTAINER(frame), main_area);
gtk_container_set_border_width(GTK_CONTAINER(main_area), 10);
diff --git a/gnucash/gnome/window-reconcile.h b/gnucash/gnome/window-reconcile.h
index 0516140..dac318d 100644
--- a/gnucash/gnome/window-reconcile.h
+++ b/gnucash/gnome/window-reconcile.h
@@ -52,12 +52,13 @@ RecnWindow *recnWindow (GtkWidget *parent, Account *account);
* Opens up the window to reconcile an account, but with ending
* balance and statement date already given.
*
- * Args: account - The account to reconcile
+ * Args: parent - The parent widget of the new window
+ * account - The account to reconcile
* new_ending - The amount for ending balance
* statement_date - The date of the statement
* Return: recnData - the instance of this RecnWindow
\********************************************************************/
-RecnWindow *recnWindowWithBalance (Account *account,
+RecnWindow *recnWindowWithBalance (GtkWidget *parent, Account *account,
gnc_numeric new_ending,
time64 statement_date);
diff --git a/gnucash/import-export/aqb/gnc-ab-utils.c b/gnucash/import-export/aqb/gnc-ab-utils.c
index 03d6539..306413d 100644
--- a/gnucash/import-export/aqb/gnc-ab-utils.c
+++ b/gnucash/import-export/aqb/gnc-ab-utils.c
@@ -1060,7 +1060,7 @@ bal_accountinfo_cb(AB_IMEXPORTER_ACCOUNTINFO *element, gpointer user_data)
/* Show reconciliation window */
if (show_recn_window)
- recnWindowWithBalance(gnc_acc, value, booked_tt);
+ recnWindowWithBalance(GTK_WIDGET (data->parent), gnc_acc, value, booked_tt);
return NULL;
}
commit ec0d081d5e2824de1de9ef97f38cfed25d6825cf
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sat Jul 28 17:45:49 2018 +0100
Change files for changed gnc_restore_window_size format, part1 of 2
Add the parent window to the calling function gnc_restore_window_size
after the change to that function. These files already had access to
the parent window.
diff --git a/gnucash/gnome-search/dialog-search.c b/gnucash/gnome-search/dialog-search.c
index 517b458..ece51d9 100644
--- a/gnucash/gnome-search/dialog-search.c
+++ b/gnucash/gnome-search/dialog-search.c
@@ -1345,7 +1345,7 @@ gnc_search_dialog_create (GtkWindow *parent,
gnc_search_dialog_init_widgets (sw, title);
if (sw->prefs_group)
- gnc_restore_window_size(sw->prefs_group, GTK_WINDOW(sw->dialog));
+ gnc_restore_window_size(sw->prefs_group, GTK_WINDOW(sw->dialog), parent);
gtk_window_set_transient_for(GTK_WINDOW(sw->dialog), parent);
gtk_widget_show(sw->dialog);
diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c
index d6bbf9a..a23429e 100644
--- a/gnucash/gnome-utils/dialog-account.c
+++ b/gnucash/gnome-utils/dialog-account.c
@@ -1435,7 +1435,7 @@ gnc_account_window_create(GtkWindow *parent, AccountWindow *aw)
}
gnc_account_type_view_create (aw, compat_types);
- gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog));
+ gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog), parent);
gtk_widget_grab_focus(GTK_WIDGET(aw->name_entry));
diff --git a/gnucash/gnome-utils/dialog-options.c b/gnucash/gnome-utils/dialog-options.c
index 936addd..5aafb86 100644
--- a/gnucash/gnome-utils/dialog-options.c
+++ b/gnucash/gnome-utils/dialog-options.c
@@ -2268,7 +2268,7 @@ gnc_options_dialog_new_modal(gboolean modal, gchar *title,
gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, retval);
- gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(retval->window));
+ gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(retval->window), parent);
if (title)
gtk_window_set_title(GTK_WINDOW(retval->window), title);
diff --git a/gnucash/gnome-utils/dialog-preferences.c b/gnucash/gnome-utils/dialog-preferences.c
index f17b2d9..7118d4a 100644
--- a/gnucash/gnome-utils/dialog-preferences.c
+++ b/gnucash/gnome-utils/dialog-preferences.c
@@ -1444,7 +1444,7 @@ gnc_preferences_dialog (GtkWindow *parent)
dialog = gnc_preferences_dialog_create(parent);
- gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(dialog));
+ gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(dialog), parent);
gtk_widget_show(dialog);
gnc_register_gui_component(DIALOG_PREFERENCES_CM_CLASS,
diff --git a/gnucash/gnome-utils/dialog-reset-warnings.c b/gnucash/gnome-utils/dialog-reset-warnings.c
index 5c810d2..02dd18c 100644
--- a/gnucash/gnome-utils/dialog-reset-warnings.c
+++ b/gnucash/gnome-utils/dialog-reset-warnings.c
@@ -413,7 +413,7 @@ gnc_reset_warnings_dialog (GtkWindow *parent)
/* Record the pointer to the rw data structure and clean up after */
g_object_set_data_full(G_OBJECT(rw_dialog->dialog), "dialog-structure", rw_dialog, g_free);
- gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(rw_dialog->dialog));
+ gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(rw_dialog->dialog), parent);
gnc_register_gui_component (DIALOG_RESET_WARNINGS_CM_CLASS,
NULL, close_handler, rw_dialog);
diff --git a/gnucash/gnome-utils/dialog-tax-table.c b/gnucash/gnome-utils/dialog-tax-table.c
index dddce0b..9212fa5 100644
--- a/gnucash/gnome-utils/dialog-tax-table.c
+++ b/gnucash/gnome-utils/dialog-tax-table.c
@@ -768,7 +768,7 @@ gnc_ui_tax_table_window_new (GtkWindow *parent, QofBook *book)
ttw);
tax_table_window_refresh (ttw);
- gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW (ttw->dialog));
+ gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW (ttw->dialog), parent);
gtk_widget_show_all (ttw->dialog);
g_object_unref(G_OBJECT(builder));
diff --git a/gnucash/gnome-utils/dialog-totd.c b/gnucash/gnome-utils/dialog-totd.c
index 0aa680e..d7158b0 100644
--- a/gnucash/gnome-utils/dialog-totd.c
+++ b/gnu