gnucash master: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Sun Mar 25 21:23:59 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/7d918ea1 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/dfb5de91 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/dedb5265 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a0f49d8b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9cd22ee6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a670238f (commit)
	 via  https://github.com/Gnucash/gnucash/commit/8081e78e (commit)
	 via  https://github.com/Gnucash/gnucash/commit/7b6854c1 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/148c02d2 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/bea89a50 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/2571baff (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9135ec45 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f1dd8cfa (commit)
	 via  https://github.com/Gnucash/gnucash/commit/34d92180 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/2b6047f9 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f05bbe24 (commit)
	from  https://github.com/Gnucash/gnucash/commit/75970adc (commit)



commit 7d918ea1f75af14973457e3be85c899cf9902eb8
Merge: 75970ad dfb5de9
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Mar 25 18:02:36 2018 -0700

    Merge branch 'unstable'


commit dfb5de91ff76cd997ffa0f01a23de36a4f00ad71
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Mar 25 12:37:11 2018 -0700

    Release 2.7.8.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cdfba7e..b8e0adf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,14 +13,14 @@ ENABLE_TESTING()
 # Version number of gnucash
 SET (GNUCASH_MAJOR_VERSION 2)
 SET (GNUCASH_MINOR_VERSION 7)
-SET (GNUCASH_MICRO_VERSION 7)
+SET (GNUCASH_MICRO_VERSION 8)
 SET (GNUCASH_NANO_VERSION 0)
 SET (VERSION "${GNUCASH_MAJOR_VERSION}.${GNUCASH_MINOR_VERSION}.${GNUCASH_MICRO_VERSION}")
 SET (GNUCASH_LATEST_STABLE_SERIES 2.6)
 
 SET (PACKAGE gnucash)
 SET (PACKAGE_NAME GnuCash)
-SET (PACKAGE_VERSION 2.7.7)
+SET (PACKAGE_VERSION 2.7.8)
 SET (PACKAGE_BUGREPORT gnucash-devel at gnucash.org)
 SET (PACKAGE_TARNAME ${PACKAGE})
 SET (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
diff --git a/NEWS b/NEWS
index c79d298..ed44f60 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,40 @@
 Version history:
 ------- -------
+2.7.8 - 25 March 2018
+
+    The Gnucash Development Team is pleased to release Gnucash 2.7.8,
+    the ninth release of an unstable series leading to Gnucash 3.0. This
+    release is a Release Candidate: If no bugs requiring major work are
+    reported the next release will be 3.0.
+
+    This release changes file locations, binding APIs, report options,
+    and can make your data file no longer compatible with previous
+    versions. See https://wiki.gnucash.org/wiki/UpdateNotes for
+    details.
+
+The following bugs are fixed only in unstable/master:
+    Bug 787439 - Segmentation Fault in Transfer dialog after clearing
+                 Date field and pressing escape.
+    Bug 794242 - Remove keep above setting for assistant hierarchy
+
+Other repairs not marked as bugs in git:
+    When doing a file save from the a new start we have no key file
+        Test for Key_file not being NULL before trying to free it.
+    Stop critical error due to testing null filename
+       g_filename_from_uri returns NULL if it is not a file uri so test
+       for the file:// prefix before doing g_file_test
+    More transient-parent fixes.
+    Add missing response section to the account picker dialog.
+    Glade 3.20 adds surplus padding option to action area
+        When glade files are saved which have GtkAssistants defined a packing
+        section is added to the assistant action area which then causes a
+        warning so remove them.
+    Add XML namespaces for all Account Hierarchy Templates.
+    Increase default options dialog size: The old 400x400 was woefully
+        inadequate for most options especially options involving account trees.
+
+Updated Translations: None.
+
 2.7.7 - 18 March 2018
 
     The Gnucash Development Team is pleased to release Gnucash 2.7.7,

commit dedb5265f0317bc9ebb99b1ca73279c7963d4b7e
Merge: a0f49d8 9cd22ee
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Mar 25 09:36:21 2018 -0700

    Merge branch 'maint' into unstable

diff --cc gnucash/gnome/gnc-plugin-page-account-tree.c
index 176e9bc,0000000..5913b75
mode 100644,000000..100644
--- a/gnucash/gnome/gnc-plugin-page-account-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-account-tree.c
@@@ -1,1808 -1,0 +1,1808 @@@
 +/*
 + * gnc-plugin-page-account-tree.c --
 + *
 + * Copyright (C) 2003 Jan Arne Petersen <jpetersen at uni-bonn.de>
 + * Copyright (C) 2003,2005,2006 David Hampton <hampton at employees.org>
 + *
 + * 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
 + */
 +
 +/** @addtogroup ContentPlugins
 +    @{ */
 +/** @addtogroup GncPluginPageAccountTree An Account Tree Plugin
 +    @{ */
 +/** @file gnc-plugin-page-account-tree.c
 +    @brief Functions providing a chart of account page.
 +    @author Copyright (C) 2003 Jan Arne Petersen <jpetersen at uni-bonn.de>
 +    @author Copyright (C) 2003,2005,2006 David Hampton <hampton at employees.org>
 +*/
 +
 +#include <config.h>
 +
 +#include <gtk/gtk.h>
 +#include <glib/gi18n.h>
 +#include "gnc-plugin-page-account-tree.h"
 +#include "gnc-plugin-page-register.h"
 +#include "gnc-plugin-page-register2.h"
 +
 +#include "Scrub.h"
 +#include "Scrub3.h"
 +#include "ScrubBusiness.h"
 +#include "Transaction.h"
 +#include "dialog-account.h"
 +#include "dialog-transfer.h"
 +#include "dialog-utils.h"
 +#include "assistant-hierarchy.h"
 +#include "gnc-account-sel.h"
 +#include "gnc-component-manager.h"
 +#include "gnc-engine.h"
 +#include "gnc-gnome-utils.h"
 +#include "gnc-gobject-utils.h"
 +#include "gnc-icons.h"
 +#include "gnc-plugin-account-tree.h"
 +#include "gnc-prefs.h"
 +#include "gnc-session.h"
 +#include "gnc-split-reg.h"
 +#include "gnc-state.h"
 +#include "gnc-tree-view-account.h"
 +#include "gnc-tree-model-account-types.h"
 +#include "gnc-ui.h"
 +#include "gnc-ui-util.h"
 +#include "gnc-window.h"
 +#include "dialog-lot-viewer.h"
 +#include "window-reconcile.h"
 +#include "window-autoclear.h"
 +#include "window-main-summarybar.h"
 +#include "dialog-object-references.h"
 +#include "dialog-find-account.h"
 +
 +/* This static indicates the debugging module that this .o belongs to.  */
 +static QofLogModule log_module = GNC_MOD_GUI;
 +
 +#define PLUGIN_PAGE_ACCT_TREE_CM_CLASS "plugin-page-acct-tree"
 +#define STATE_SECTION "Account Hierarchy"
 +
 +#define DELETE_DIALOG_FILTER       "filter"
 +#define DELETE_DIALOG_ACCOUNT      "account"
 +#define DELETE_DIALOG_TRANS_MAS    "trans_mas"
 +#define DELETE_DIALOG_SA_MAS       "sa_mas"
 +#define DELETE_DIALOG_SA_TRANS_MAS "sa_trans_mas"
 +#define DELETE_DIALOG_SA_TRANS     "sa_trans"
 +#define DELETE_DIALOG_SA_SPLITS    "sa_has_split"
 +#define DELETE_DIALOG_OK_BUTTON    "deletebutton"
 +
 +enum
 +{
 +    ACCOUNT_SELECTED,
 +    LAST_SIGNAL
 +};
 +
 +typedef struct GncPluginPageAccountTreePrivate
 +{
 +    GtkWidget   *widget;
 +    GtkTreeView *tree_view;
 +    gint         component_id;
 +    AccountFilterDialog fd;
 +} GncPluginPageAccountTreePrivate;
 +
 +#define GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(o)  \
 +   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_PAGE_ACCOUNT_TREE, GncPluginPageAccountTreePrivate))
 +
 +static GObjectClass *parent_class = NULL;
 +
 +/************************************************************
 + *                        Prototypes                        *
 + ************************************************************/
 +/* Plugin Actions */
 +static void gnc_plugin_page_account_tree_class_init (GncPluginPageAccountTreeClass *klass);
 +static void gnc_plugin_page_account_tree_init (GncPluginPageAccountTree *plugin_page);
 +static void gnc_plugin_page_account_tree_finalize (GObject *object);
 +static void gnc_plugin_page_account_tree_selected (GObject *object, gpointer user_data);
 +
 +static GtkWidget *gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page);
 +static void gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page);
 +static void gnc_plugin_page_account_tree_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
 +static GncPluginPage *gnc_plugin_page_account_tree_recreate_page (GtkWidget *window, GKeyFile *file, const gchar *group);
 +
 +/* Callbacks */
 +static void gnc_plugin_page_account_tree_summarybar_position_changed(gpointer prefs, gchar* pref, gpointer user_data);
 +static gboolean gnc_plugin_page_account_tree_button_press_cb (GtkWidget *widget,
 +        GdkEventButton *event,
 +        GncPluginPage *page);
 +static void gnc_plugin_page_account_tree_double_click_cb (GtkTreeView        *treeview,
 +        GtkTreePath        *path,
 +        GtkTreeViewColumn  *col,
 +        GncPluginPageAccountTree *page);
 +
 +static void gnc_plugin_page_account_tree_selection_changed_cb (GtkTreeSelection *selection,
 +        GncPluginPageAccountTree *page);
 +void gppat_populate_trans_mas_list(GtkToggleButton *sa_mrb, GtkWidget *dialog);
 +void gppat_set_insensitive_iff_rb_active(GtkWidget *widget, GtkToggleButton *b);
 +
 +/* Command callbacks */
 +static void gnc_plugin_page_account_tree_cmd_new_account (GtkAction *action, GncPluginPageAccountTree *plugin_page);
 +static void gnc_plugin_page_account_tree_cmd_file_new_hierarchy (GtkAction *action, GncPluginPageAccountTree *plugin_page);
 +static void gnc_plugin_page_account_tree_cmd_open_account (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_open_subaccounts (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_edit_account (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_find_account (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_find_account_popup (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_renumber_accounts (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_view_filter_by (GtkAction *action, GncPluginPageAccountTree *plugin_page);
 +static void gnc_plugin_page_account_tree_cmd_reconcile (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_autoclear (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_transfer (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_stock_split (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_lots (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_scrub (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_scrub_sub (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_scrub_all (GtkAction *action, GncPluginPageAccountTree *page);
 +
 +/* Command callback for new Register Test */
 +static void gnc_plugin_page_account_tree_cmd_open2_account (GtkAction *action, GncPluginPageAccountTree *page);
 +static void gnc_plugin_page_account_tree_cmd_open2_subaccounts (GtkAction *action, GncPluginPageAccountTree *page);
 +
 +static guint plugin_page_signals[LAST_SIGNAL] = { 0 };
 +
 +
 +static GtkActionEntry gnc_plugin_page_account_tree_actions [] =
 +{
 +    /* Toplevel */
 +    { "FakeToplevel", NULL, "", NULL, NULL, NULL },
 +
 +    /* File menu */
 +    {
 +        "FileNewAccountAction", GNC_ICON_NEW_ACCOUNT, N_("New _Account..."), NULL,
 +        N_("Create a new Account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_new_account)
 +    },
 +    {
 +        "FileAddAccountHierarchyAssistantAction", GNC_ICON_NEW_ACCOUNT, N_("New Account _Hierarchy..."), NULL,
 +        N_("Extend the current book by merging with new account type categories"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_file_new_hierarchy)
 +    },
 +#ifdef REGISTER2_ENABLED
 +    {
 +        "FileOpenAccount2Action", GNC_ICON_OPEN_ACCOUNT, N_("Open _Account"), NULL,
 +        N_("Open the selected account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_open2_account)
 +    },
 +    {
 +        "FileOpenAccountAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _Old Style Register Account"), NULL,
 +        N_("Open the old style register selected account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_open_account)
 +    },
 +#else
 +    {
 +        "FileOpenAccountAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _Account"), NULL,
 +        N_("Open the selected account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_open_account)
 +    },
 +#endif
 +
 +#ifdef REGISTER2_ENABLED
 +    {
 +        "FileOpenSubaccounts2Action", GNC_ICON_OPEN_ACCOUNT, N_("Open _SubAccounts"), NULL,
 +        N_("Open the selected account and all its subaccounts"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_open2_subaccounts)
 +    },
 +    {
 +        "FileOpenSubaccountsAction", GNC_ICON_OPEN_ACCOUNT, N_("Open Old St_yle Subaccounts"), NULL,
 +        N_("Open the old style register selected account and all its subaccounts"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_open_subaccounts)
 +    },
 +#else
 +    {
 +        "FileOpenSubaccountsAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _SubAccounts"), NULL,
 +        N_("Open the selected account and all its subaccounts"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_open_subaccounts)
 +    },
 +#endif
 +
 +    /* Edit menu */
 +    {
 +        "EditEditAccountAction", GNC_ICON_EDIT_ACCOUNT, N_("Edit _Account"), "<primary>e",
 +        N_("Edit the selected account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_edit_account)
 +    },
 +    {
 +        "EditDeleteAccountAction", GNC_ICON_DELETE_ACCOUNT, N_("_Delete Account..."), "Delete",
 +        N_("Delete selected account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_delete_account)
 +    },
 +    {
 +        "EditFindAccountAction", "edit-find", N_("F_ind Account"), "<primary>i",
 +        N_("Find an account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_find_account)
 +    },
 +    {
 +        "EditFindAccountPopupAction", "edit-find", N_("F_ind Account"), "<primary>i",
 +        N_("Find an account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_find_account_popup)
 +    },
 +    {
 +        "EditRenumberSubaccountsAction", NULL, N_("_Renumber Subaccounts..."), NULL,
 +        N_("Renumber the children of the selected account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_renumber_accounts)
 +    },
 +
 +    /* View menu */
 +    {
 +        "ViewFilterByAction", NULL, N_("_Filter By..."), NULL, NULL,
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_view_filter_by)
 +    },
 +
 +    /* Actions menu */
 +    {
 +        "ActionsReconcileAction", NULL, N_("_Reconcile..."), NULL,
 +        N_("Reconcile the selected account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_reconcile)
 +    },
 +    {
 +        "ActionsAutoClearAction", NULL, N_("_Auto-clear..."), NULL,
 +        N_("Automatically clear individual transactions, given a cleared amount"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_autoclear)
 +    },
 +    {
 +        "ActionsTransferAction", NULL, N_("_Transfer..."), "<primary>t",
 +        N_("Transfer funds from one account to another"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_transfer)
 +    },
 +    {
 +        "ActionsStockSplitAction", NULL, N_("Stoc_k Split..."), NULL,
 +        N_("Record a stock split or a stock merger"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_stock_split)
 +    },
 +    {
 +        "ActionsLotsAction", NULL, N_("View _Lots..."), NULL,
 +        N_("Bring up the lot viewer/editor window"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_lots)
 +    },
 +    {
 +        "ScrubAction", NULL, N_("Check & Repair A_ccount"), NULL,
 +        N_("Check for and repair unbalanced transactions and orphan splits " "in this account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_scrub)
 +    },
 +    {
 +        "ScrubSubAction", NULL, N_("Check & Repair Su_baccounts"), NULL,
 +        N_("Check for and repair unbalanced transactions and orphan splits "
 +        "in this account and its subaccounts"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_scrub_sub)
 +    },
 +    {
 +        "ScrubAllAction", NULL, N_("Check & Repair A_ll"), NULL,
 +        N_("Check for and repair unbalanced transactions and orphan splits " "in all accounts"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_scrub_all)
 +    },
 +    /* Extensions Menu */
 +    { "Register2TestAction", NULL, N_("_Register2"), NULL, NULL, NULL },
 +    {
 +        "Register2TestAccountAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _Account"), NULL,
 +        N_("Open the selected account"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_open2_account)
 +    },
 +    {
 +        "Register2TestSubAccountAction", GNC_ICON_OPEN_ACCOUNT, N_("Open _SubAccounts"), NULL,
 +        N_("Open the selected account and all its subaccounts"),
 +        G_CALLBACK (gnc_plugin_page_account_tree_cmd_open2_subaccounts)
 +    },
 +};
 +/** The number of actions provided by this plugin. */
 +static guint gnc_plugin_page_account_tree_n_actions = G_N_ELEMENTS (gnc_plugin_page_account_tree_actions);
 +
 +
 +/** Actions that require an account to be selected before they are
 + *  enabled, and the book is in read-write mode. */
 +static const gchar *actions_requiring_account_rw[] =
 +{
 +    "EditEditAccountAction",
 +    "EditDeleteAccountAction",
 +    "ActionsReconcileAction",
 +    "ActionsAutoClearAction",
 +    NULL
 +};
 +
 +/** Actions that require an account to be selected before they are
 + *  enabled. Those actions can be selected even if the book is in readonly mode. */
 +static const gchar *actions_requiring_account_always[] =
 +{
 +    "FileOpenAccountAction",
 +#ifdef REGISTER2_ENABLED
 +    "FileOpenAccount2Action",
 +#endif
 +    "FileOpenSubaccountsAction",
 +    "ActionsLotsAction",
 +    NULL
 +};
 +
 +/* This is the list of actions which are switched inactive in a read-only book. */
 +static const gchar* readonly_inactive_actions[] =
 +{
 +    "FileNewAccountAction",
 +    "FileAddAccountHierarchyAssistantAction",
 +    "EditEditAccountAction",
 +    "EditDeleteAccountAction",
 +    "EditRenumberSubaccountsAction",
 +    "ActionsTransferAction",
 +    "ActionsReconcileAction",
 +    "ActionsAutoClearAction",
 +    "ActionsStockSplitAction",
 +    "ScrubAction",
 +    "ScrubSubAction",
 +    "ScrubAllAction",
 +    NULL
 +};
 +
 +/** Short labels for use on the toolbar buttons. */
 +static action_toolbar_labels toolbar_labels[] =
 +{
 +    { "FileOpenAccountAction", 	            N_("Open") },
 +#ifdef REGISTER2_ENABLED
 +    { "FileOpenAccount2Action", 	    N_("Open2") },
 +#endif
 +    { "EditEditAccountAction", 	            N_("Edit") },
 +    { "FileNewAccountAction",    	    N_("New") },
 +    { "EditDeleteAccountAction", 	    N_("Delete") },
 +    { NULL, NULL },
 +};
 +
 +
 +GType
 +gnc_plugin_page_account_tree_get_type (void)
 +{
 +    static GType gnc_plugin_page_account_tree_type = 0;
 +
 +    if (gnc_plugin_page_account_tree_type == 0)
 +    {
 +        static const GTypeInfo our_info =
 +        {
 +            sizeof (GncPluginPageAccountTreeClass),
 +            NULL,
 +            NULL,
 +            (GClassInitFunc) gnc_plugin_page_account_tree_class_init,
 +            NULL,
 +            NULL,
 +            sizeof (GncPluginPageAccountTree),
 +            0,
 +            (GInstanceInitFunc) gnc_plugin_page_account_tree_init
 +        };
 +
 +        gnc_plugin_page_account_tree_type = g_type_register_static (GNC_TYPE_PLUGIN_PAGE,
 +                                            GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME,
 +                                            &our_info, 0);
 +    }
 +
 +    return gnc_plugin_page_account_tree_type;
 +}
 +
 +GncPluginPage *
 +gnc_plugin_page_account_tree_new (void)
 +{
 +    GncPluginPageAccountTree *plugin_page;
 +
 +    ENTER(" ");
 +    plugin_page = g_object_new (GNC_TYPE_PLUGIN_PAGE_ACCOUNT_TREE,
 +                                NULL);
 +
 +    LEAVE("new account tree page %p", plugin_page);
 +    return GNC_PLUGIN_PAGE (plugin_page);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_class_init (GncPluginPageAccountTreeClass *klass)
 +{
 +    GObjectClass *object_class = G_OBJECT_CLASS (klass);
 +    GncPluginPageClass *gnc_plugin_class = GNC_PLUGIN_PAGE_CLASS(klass);
 +
 +    parent_class = g_type_class_peek_parent (klass);
 +
 +    object_class->finalize = gnc_plugin_page_account_tree_finalize;
 +
 +    gnc_plugin_class->tab_icon        = GNC_ICON_ACCOUNT;
 +    gnc_plugin_class->plugin_name     = GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME;
 +    gnc_plugin_class->create_widget   = gnc_plugin_page_account_tree_create_widget;
 +    gnc_plugin_class->destroy_widget  = gnc_plugin_page_account_tree_destroy_widget;
 +    gnc_plugin_class->save_page       = gnc_plugin_page_account_tree_save_page;
 +    gnc_plugin_class->recreate_page   = gnc_plugin_page_account_tree_recreate_page;
 +
 +    g_type_class_add_private(klass, sizeof(GncPluginPageAccountTreePrivate));
 +
 +    plugin_page_signals[ACCOUNT_SELECTED] =
 +        g_signal_new ("account_selected",
 +                      G_OBJECT_CLASS_TYPE (object_class),
 +                      G_SIGNAL_RUN_FIRST,
 +                      G_STRUCT_OFFSET (GncPluginPageAccountTreeClass, account_selected),
 +                      NULL, NULL,
 +                      g_cclosure_marshal_VOID__POINTER,
 +                      G_TYPE_NONE, 1,
 +                      G_TYPE_POINTER);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_init (GncPluginPageAccountTree *plugin_page)
 +{
 +    GtkActionGroup *action_group;
 +    GncPluginPageAccountTreePrivate *priv;
 +    GncPluginPage *parent;
 +    const GList *page_list;
 +
 +    ENTER("page %p", plugin_page);
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(plugin_page);
 +
 +    /* Init parent declared variables */
 +    parent = GNC_PLUGIN_PAGE(plugin_page);
 +#ifdef REGISTER2_ENABLED
 +    g_object_set(G_OBJECT(plugin_page),
 +                 "page-name",      _("Accounts"),
 +                 "page-uri",       "default:",
 +                 "ui-description", "gnc-plugin-page-account-tree2-ui.xml",
 +                 NULL);
 +#else
 +    g_object_set(G_OBJECT(plugin_page),
 +                 "page-name",      _("Accounts"),
 +                 "page-uri",       "default:",
 +                 "ui-description", "gnc-plugin-page-account-tree-ui.xml",
 +                 NULL);
 +#endif
 +    g_signal_connect (G_OBJECT (plugin_page), "selected",
 +                      G_CALLBACK (gnc_plugin_page_account_tree_selected), plugin_page);
 +
 +    /* change me when the system supports multiple books */
 +    gnc_plugin_page_add_book(parent, gnc_get_current_book());
 +
 +    /* Is this the first accounts page? */
 +    page_list =
 +        gnc_gobject_tracking_get_list(GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME);
 +    if (plugin_page == page_list->data)
 +    {
 +        g_object_set_data(G_OBJECT(plugin_page), PLUGIN_PAGE_IMMUTABLE,
 +                          GINT_TO_POINTER(1));
 +    }
 +
 +    /* Create menu and toolbar information */
 +    action_group =
 +        gnc_plugin_page_create_action_group(parent,
 +                                            "GncPluginPageAccountTreeActions");
 +    gtk_action_group_add_actions(action_group,
 +                                 gnc_plugin_page_account_tree_actions,
 +                                 gnc_plugin_page_account_tree_n_actions,
 +                                 plugin_page);
 +    gnc_plugin_init_short_names (action_group, toolbar_labels);
 +
 +    /* Visible types */
 +    priv->fd.visible_types = -1; /* Start with all types */
 +    priv->fd.show_hidden = FALSE;
 +    priv->fd.show_unused = TRUE;
 +    priv->fd.show_zero_total = TRUE;
 +    priv->fd.filter_override = g_hash_table_new (g_direct_hash, g_direct_equal);
 +
 +    LEAVE("page %p, priv %p, action group %p",
 +          plugin_page, priv, action_group);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_finalize (GObject *object)
 +{
 +    GncPluginPageAccountTree *page;
 +    GncPluginPageAccountTreePrivate *priv;
 +
 +    ENTER("object %p", object);
 +    page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (object);
 +    g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE (page));
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +    g_return_if_fail (priv != NULL);
 +
 +    G_OBJECT_CLASS (parent_class)->finalize (object);
 +    LEAVE(" ");
 +}
 +
 +void
 +gnc_plugin_page_account_tree_open (Account *account, GtkWindow *win)
 +{
 +    GncPluginPageAccountTreePrivate *priv;
 +    GncPluginPageAccountTree *page;
 +    GncPluginPage *plugin_page = NULL;
 +    const GList *page_list;
 +    GtkWidget   *window;
 +
 +    /* Find Accounts page */
 +    page_list = gnc_gobject_tracking_get_list(GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME);
 +
 +    // If we have a window, look for account page in that window
 +    if (g_list_length ((GList*)page_list) != 0)
 +    {
 +        if (win != NULL)
 +        {
 +            for ( ; page_list; page_list = g_list_next(page_list))
 +            {
 +                plugin_page = GNC_PLUGIN_PAGE(page_list->data);
 +                if (GTK_WINDOW(plugin_page->window) == win)
 +                    break;
 +            }
 +        }
 +        else // if no window, open first account page in list
 +            plugin_page = GNC_PLUGIN_PAGE(page_list->data);
 +    }
 +    else // we have no account pages, create one
 +        plugin_page = gnc_plugin_page_account_tree_new ();
 +
 +    window = plugin_page->window;
 +
 +    gnc_main_window_open_page (GNC_MAIN_WINDOW(window), plugin_page);
 +
 +    page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page);
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +
 +    if (account != NULL)
 +    {
 +        Account *root_account = gnc_get_current_root_account ();
 +        Account *parent_account = NULL;
 +        Account *temp_account = account;
 +
 +        g_hash_table_insert (priv->fd.filter_override, account, account);
 +
 +        // make sure we override all the parent accounts to root
 +        while (parent_account != root_account)
 +        {
 +            parent_account = gnc_account_get_parent (temp_account);
 +
 +            g_hash_table_insert (priv->fd.filter_override, parent_account, parent_account);
 +            temp_account = parent_account;
 +        }
 +        gnc_tree_view_account_refilter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
 +        gnc_tree_view_account_set_selected_account (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), account);
 +    }
 +}
 +
 +Account *
 +gnc_plugin_page_account_tree_get_current_account (GncPluginPageAccountTree *page)
 +{
 +    GncPluginPageAccountTreePrivate *priv;
 +    Account *account;
 +
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +    ENTER("page %p (tree view %p)", page, priv->tree_view);
 +    account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
 +    if (account == NULL)
 +    {
 +        LEAVE("no account");
 +        return NULL;
 +    }
 +
 +    LEAVE("account %p", account);
 +    return account;
 +}
 +
 +gboolean
 +gnc_plugin_page_account_tree_focus (GncPluginPageAccountTree *page)
 +{
 +    if (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page))
 +    {
 +        GncPluginPageAccountTreePrivate *priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +        GtkTreeView *view = GTK_TREE_VIEW(priv->tree_view);
 +
 +        if (!gtk_widget_is_focus (GTK_WIDGET(view)))
 +            gtk_widget_grab_focus (GTK_WIDGET(view));
 +    }
 +    return FALSE;
 +}
 +
 +/* Virtual Functions */
 +
 +static void
 +gnc_plugin_page_account_refresh_cb (GHashTable *changes, gpointer user_data)
 +{
 +    GncPluginPageAccountTree *page = user_data;
 +    GncPluginPageAccountTreePrivate *priv;
 +
 +    g_return_if_fail(GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page));
 +
 +    /* We're only looking for forced updates here. */
 +    if (changes)
 +        return;
 +
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +    gtk_widget_queue_draw(priv->widget);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_close_cb (gpointer user_data)
 +{
 +    GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(user_data);
 +    gnc_main_window_close_page(plugin_page);
 +}
 +
 +static void
 +gnc_plugin_page_account_editing_started_cd (gpointer various, GncPluginPageRegister *page)
 +{
 +    GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(page);
 +    GtkAction *action = gnc_main_window_find_action (GNC_MAIN_WINDOW(plugin_page->window),
 +                                                     "EditDeleteAccountAction");
 +
 +    if (action != NULL)
 +        gtk_action_set_sensitive (action, FALSE);
 +}
 +
 +static void
 +gnc_plugin_page_account_editing_finished_cb (gpointer various, GncPluginPageRegister *page)
 +{
 +    GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(page);
 +    GtkAction *action = gnc_main_window_find_action (GNC_MAIN_WINDOW(plugin_page->window),
 +                                                     "EditDeleteAccountAction");
 +
 +    if (action != NULL)
 +        gtk_action_set_sensitive (action, TRUE);
 +}
 +
 +static GtkWidget *
 +gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page)
 +{
 +    GncPluginPageAccountTree *page;
 +    GncPluginPageAccountTreePrivate *priv;
 +    GtkTreeSelection *selection;
 +    GtkTreeView *tree_view;
 +    GtkWidget *scrolled_window;
 +    GtkTreeViewColumn *col;
 +
 +    ENTER("page %p", plugin_page);
 +    page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page);
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +    if (priv->widget != NULL)
 +    {
 +        LEAVE("widget = %p", priv->widget);
 +        return priv->widget;
 +    }
 +
 +    priv->widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 +    gtk_box_set_homogeneous (GTK_BOX (priv->widget), FALSE);
 +    gtk_widget_show (priv->widget);
 +
 +    // Set the style context for this page so it can be easily manipulated with css
 +    gnc_widget_set_style_context (GTK_WIDGET(priv->widget), "GncAccountPage");
 +
 +    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
 +    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
 +                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 +    gtk_widget_show (scrolled_window);
 +    gtk_box_pack_start (GTK_BOX (priv->widget), scrolled_window,
 +                        TRUE, TRUE, 0);
 +
 +    tree_view = gnc_tree_view_account_new(FALSE);
 +    col = gnc_tree_view_find_column_by_name(
 +              GNC_TREE_VIEW(tree_view), "description");
 +    g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
 +    col = gnc_tree_view_find_column_by_name(
 +              GNC_TREE_VIEW(tree_view), "total");
 +    g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
 +    gnc_tree_view_configure_columns(GNC_TREE_VIEW(tree_view));
 +    g_object_set(G_OBJECT(tree_view),
 +                 "state-section", STATE_SECTION,
 +                 "show-column-menu", TRUE,
 +                 NULL);
 +
 +    /* No name handler; then the user can't click on the name of the
 +       account to open its register. */
 +    gnc_tree_view_account_set_code_edited(GNC_TREE_VIEW_ACCOUNT(tree_view),
 +                                          gnc_tree_view_account_code_edited_cb);
 +    gnc_tree_view_account_set_description_edited(GNC_TREE_VIEW_ACCOUNT(tree_view),
 +            gnc_tree_view_account_description_edited_cb);
 +    gnc_tree_view_account_set_notes_edited(GNC_TREE_VIEW_ACCOUNT(tree_view),
 +                                           gnc_tree_view_account_notes_edited_cb);
 +
 +    // Setup some callbacks so menu actions can be disabled/enabled
 +    gnc_tree_view_account_set_editing_started_cb(GNC_TREE_VIEW_ACCOUNT(tree_view),
 +        (GFunc)gnc_plugin_page_account_editing_started_cd, page);
 +    gnc_tree_view_account_set_editing_finished_cb(GNC_TREE_VIEW_ACCOUNT(tree_view),
 +        (GFunc)gnc_plugin_page_account_editing_finished_cb, page);
 +
 +    priv->tree_view = tree_view;
 +    selection = gtk_tree_view_get_selection(tree_view);
 +    g_signal_connect (G_OBJECT (selection), "changed",
 +                      G_CALLBACK (gnc_plugin_page_account_tree_selection_changed_cb), page);
 +    g_signal_connect (G_OBJECT (tree_view), "button-press-event",
 +                      G_CALLBACK (gnc_plugin_page_account_tree_button_press_cb), page);
 +    g_signal_connect (G_OBJECT (tree_view), "row-activated",
 +                      G_CALLBACK (gnc_plugin_page_account_tree_double_click_cb), page);
 +
 +    gtk_tree_view_set_headers_visible(tree_view, TRUE);
 +    gnc_plugin_page_account_tree_selection_changed_cb (NULL, page);
 +    gtk_widget_show (GTK_WIDGET (tree_view));
 +    gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(tree_view));
 +
 +    priv->fd.tree_view = GNC_TREE_VIEW_ACCOUNT(priv->tree_view);
 +    gnc_tree_view_account_set_filter (
 +        GNC_TREE_VIEW_ACCOUNT(tree_view),
 +        gnc_plugin_page_account_tree_filter_accounts, &priv->fd, NULL);
 +
 +    priv->component_id =
 +        gnc_register_gui_component(PLUGIN_PAGE_ACCT_TREE_CM_CLASS,
 +                                   gnc_plugin_page_account_refresh_cb,
 +                                   gnc_plugin_page_account_tree_close_cb,
 +                                   page);
 +    gnc_gui_component_set_session (priv->component_id,
 +                                   gnc_get_current_session());
 +
 +    plugin_page->summarybar = gnc_main_window_summary_new();
 +    gtk_box_pack_start (GTK_BOX (priv->widget), plugin_page->summarybar,
 +                        FALSE, FALSE, 0);
 +    gtk_widget_show(plugin_page->summarybar);
 +    gnc_plugin_page_account_tree_summarybar_position_changed(NULL, NULL, page);
 +    gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
 +                           GNC_PREF_SUMMARYBAR_POSITION_TOP,
 +                           gnc_plugin_page_account_tree_summarybar_position_changed,
 +                           page);
 +    gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
 +                           GNC_PREF_SUMMARYBAR_POSITION_BOTTOM,
 +                           gnc_plugin_page_account_tree_summarybar_position_changed,
 +                           page);
 +
 +    LEAVE("widget = %p", priv->widget);
 +    return priv->widget;
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page)
 +{
 +    GncPluginPageAccountTree *page;
 +    GncPluginPageAccountTreePrivate *priv;
 +
 +    ENTER("page %p", plugin_page);
 +    page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page);
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +
 +    gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
 +                                 GNC_PREF_SUMMARYBAR_POSITION_TOP,
 +                                 gnc_plugin_page_account_tree_summarybar_position_changed,
 +                                 page);
 +    gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
 +                                 GNC_PREF_SUMMARYBAR_POSITION_BOTTOM,
 +                                 gnc_plugin_page_account_tree_summarybar_position_changed,
 +                                 page);
 +
 +    // Destroy the filter override hash table
 +    g_hash_table_destroy(priv->fd.filter_override);
 +
 +    // Remove the page focus idle function if present
 +    g_idle_remove_by_data (GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page));
 +
 +    if (priv->widget)
 +    {
 +        g_object_unref(G_OBJECT(priv->widget));
 +        priv->widget = NULL;
 +    }
 +
 +    if (priv->component_id)
 +    {
 +        gnc_unregister_gui_component(priv->component_id);
 +        priv->component_id = 0;
 +    }
 +
 +    LEAVE("widget destroyed");
 +}
 +
 +static void update_inactive_actions(GncPluginPage *plugin_page)
 +{
 +    GtkActionGroup *action_group;
 +    gboolean is_sensitive = !qof_book_is_readonly(gnc_get_current_book());
 +
 +    // We are readonly - so we have to switch particular actions to inactive.
 +    g_return_if_fail(plugin_page);
 +    g_return_if_fail(GNC_IS_PLUGIN_PAGE(plugin_page));
 +
 +    /* Get the action group */
 +    action_group = gnc_plugin_page_get_action_group(plugin_page);
 +    g_return_if_fail(GTK_IS_ACTION_GROUP (action_group));
 +
 +    /* Set the action's sensitivity */
 +    gnc_plugin_update_actions (action_group, readonly_inactive_actions,
 +                               "sensitive", is_sensitive);
 +}
 +
 +/**
 + * Called when this page is selected.
 + *
 + * Update the toolbar button sensitivity. */
 +static void gnc_plugin_page_account_tree_selected (GObject *object, gpointer user_data)
 +{
 +    GncPluginPage *plugin_page = GNC_PLUGIN_PAGE (object);
 +    g_return_if_fail (GNC_IS_PLUGIN_PAGE (plugin_page));
 +    update_inactive_actions(plugin_page);
 +}
 +
 +/** Save enough information about this account tree page that it can
 + *  be recreated next time the user starts gnucash.
 + *
 + *  @param plugin_page The page to save.
 + *
 + *  @param key_file A pointer to the GKeyFile data structure where the
 + *  page information should be written.
 + *
 + *  @param group_name The group name to use when saving data. */
 +static void
 +gnc_plugin_page_account_tree_save_page (GncPluginPage *plugin_page,
 +                                        GKeyFile *key_file,
 +                                        const gchar *group_name)
 +{
 +    GncPluginPageAccountTree *account_page;
 +    GncPluginPageAccountTreePrivate *priv;
 +
 +    g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(plugin_page));
 +    g_return_if_fail (key_file != NULL);
 +    g_return_if_fail (group_name != NULL);
 +
 +    ENTER("page %p, key_file %p, group_name %s", plugin_page, key_file,
 +          group_name);
 +
 +    account_page = GNC_PLUGIN_PAGE_ACCOUNT_TREE(plugin_page);
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(account_page);
 +
 +    gnc_tree_view_account_save(GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
 +                               &priv->fd, key_file, group_name);
 +    LEAVE(" ");
 +}
 +
 +
 +
 +/** Create a new account tree page based on the information saved
 + *  during a previous instantiation of gnucash.
 + *
 + *  @param window The window where this page should be installed.
 + *
 + *  @param key_file A pointer to the GKeyFile data structure where the
 + *  page information should be read.
 + *
 + *  @param group_name The group name to use when restoring data. */
 +static GncPluginPage *
 +gnc_plugin_page_account_tree_recreate_page (GtkWidget *window,
 +        GKeyFile *key_file,
 +        const gchar *group_name)
 +{
 +    GncPluginPageAccountTree *account_page;
 +    GncPluginPageAccountTreePrivate *priv;
 +    GncPluginPage *page;
 +
 +    g_return_val_if_fail(key_file, NULL);
 +    g_return_val_if_fail(group_name, NULL);
 +    ENTER("key_file %p, group_name %s", key_file, group_name);
 +
 +    /* Create the new page. */
 +    page = gnc_plugin_page_account_tree_new();
 +    account_page = GNC_PLUGIN_PAGE_ACCOUNT_TREE(page);
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(account_page);
 +
 +    /* Install it now so we can then manipulate the created widget */
 +    gnc_main_window_open_page(GNC_MAIN_WINDOW(window), page);
 +
 +    gnc_tree_view_account_restore(GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
 +                                  &priv->fd, key_file, group_name);
 +    LEAVE(" ");
 +    return page;
 +}
 +
 +
 +/* Callbacks */
 +
 +static void
 +gnc_plugin_page_account_tree_summarybar_position_changed(gpointer prefs, gchar* pref, gpointer user_data)
 +{
 +    GncPluginPage *plugin_page;
 +    GncPluginPageAccountTree *page;
 +    GncPluginPageAccountTreePrivate *priv;
 +    GtkPositionType position = GTK_POS_BOTTOM;
 +
 +    g_return_if_fail(user_data != NULL);
 +
 +    plugin_page = GNC_PLUGIN_PAGE(user_data);
 +    page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (user_data);
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +
 +    if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_SUMMARYBAR_POSITION_TOP))
 +        position = GTK_POS_TOP;
 +
 +    gtk_box_reorder_child(GTK_BOX(priv->widget),
 +                          plugin_page->summarybar,
 +                          (position == GTK_POS_TOP ? 0 : -1) );
 +}
 +
 +/** This button press handler calls the common button press handler
 + *  for all pages.  The GtkTreeView eats all button presses and
 + *  doesn't pass them up the widget tree, even when doesn't do
 + *  anything with them.  The only way to get access to the button
 + *  presses in an account tree page is here on the tree view widget.
 + *  Button presses on all other pages are caught by the signal
 + *  registered in gnc-main-window.c. */
 +static gboolean
 +gnc_plugin_page_account_tree_button_press_cb (GtkWidget *widget,
 +        GdkEventButton *event,
 +        GncPluginPage *page)
 +{
 +
 +    g_return_val_if_fail(GNC_IS_PLUGIN_PAGE(page), FALSE);
 +
 +    ENTER("widget %p, event %p, page %p", widget, event, page);
 +    gnc_main_window_button_press_cb(widget, event, page);
 +    LEAVE(" ");
 +
 +    /* Always return FALSE.  This will let the tree view callback run as
 +     * well which will select the item under the cursor.  By the time
 +     * the user sees the menu both callbacks will have run and the menu
 +     * actions will operate on the just-selected account. */
 +    return FALSE;
 +}
 +
 +static void
 +gppat_open_account_common (GncPluginPageAccountTree *page,
 +                           Account *account,
 +                           gboolean include_subs)
 +{
 +    GtkWidget *window;
 +    GncPluginPage *new_page;
 +
 +    if (account == NULL)
 +        return;
 +
 +    window = GNC_PLUGIN_PAGE (page)->window;
 +    new_page = gnc_plugin_page_register_new (account, include_subs);
 +    gnc_main_window_open_page (GNC_MAIN_WINDOW(window), new_page);
 +}
 +
 +/*################## Added for Reg2 #################*/
 +/*        New Register Common                        */
 +static void
 +gppat_open2_account_common (GncPluginPageAccountTree *page,
 +                            Account *account,
 +                            gboolean include_subs)
 +{
 +    GtkWidget *window;
 +    GncPluginPage *new_page;
 +
 +    if (account == NULL)
 +        return;
 +
 +    window = GNC_PLUGIN_PAGE (page)->window;
 +    new_page = gnc_plugin_page_register2_new (account, include_subs);
 +    gnc_main_window_open_page (GNC_MAIN_WINDOW(window), new_page);
 +}
 +/*################## Added for Reg2 #################*/
 +
 +static void
 +gnc_plugin_page_account_tree_double_click_cb (GtkTreeView *treeview,
 +        GtkTreePath        *path,
 +        GtkTreeViewColumn  *col,
 +        GncPluginPageAccountTree *page)
 +{
 +    GtkTreeModel *model;
 +    GtkTreeIter iter;
 +
 +    g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE (page));
 +    g_return_if_fail (treeview);
 +
 +    model = gtk_tree_view_get_model(treeview);
 +    if (gtk_tree_model_get_iter(model, &iter, path))
 +    {
 +        Account *account = gnc_tree_view_account_get_account_from_path (GNC_TREE_VIEW_ACCOUNT(treeview), path);
 +        if (xaccAccountGetPlaceholder (account))
 +        {
 +            /* This is a placeholder account. Only only show/hide
 +             * subaccount list if there is one.
 +             */
 +            if (gtk_tree_model_iter_has_child(model, &iter))
 +            {
 +                /* There are children,
 +                 * just expand or collapse the row. */
 +                if (gtk_tree_view_row_expanded(treeview, path))
 +                    gtk_tree_view_collapse_row(treeview, path);
 +                else
 +                    gtk_tree_view_expand_row(treeview, path, FALSE);
 +            }
 +        }
 +        else
 +        {
 +            /* No placeholder account, so open its register */
 +#ifdef REGISTER2_ENABLED
 +            gppat_open2_account_common (page, account, FALSE);
 +#else
 +            gppat_open_account_common (page, account, FALSE);
 +#endif
 +        }
 +    }
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_selection_changed_cb (GtkTreeSelection *selection,
 +        GncPluginPageAccountTree *page)
 +{
 +    GtkActionGroup *action_group;
 +    GtkAction *action;
 +    GtkTreeView *view;
 +    Account *account = NULL;
 +    gboolean sensitive;
 +    gboolean subaccounts;
 +    gboolean is_readwrite = !qof_book_is_readonly(gnc_get_current_book());
 +
 +    g_return_if_fail(GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page));
 +
 +    if (!selection)
 +    {
 +        sensitive = FALSE;
 +        subaccounts = FALSE;
 +    }
 +    else
 +    {
 +        g_return_if_fail(GTK_IS_TREE_SELECTION(selection));
 +        view = gtk_tree_selection_get_tree_view (selection);
 +        account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(view));
 +        sensitive = (account != NULL);
 +
 +        subaccounts = account && (gnc_account_n_children(account) != 0);
 +        /* Check here for placeholder accounts, etc. */
 +    }
 +
 +    action_group = gnc_plugin_page_get_action_group(GNC_PLUGIN_PAGE(page));
 +    gnc_plugin_update_actions (action_group, actions_requiring_account_rw,
 +                               "sensitive", is_readwrite && sensitive);
 +    gnc_plugin_update_actions (action_group, actions_requiring_account_always,
 +                               "sensitive", sensitive);
 +    g_signal_emit (page, plugin_page_signals[ACCOUNT_SELECTED], 0, account);
 +
 +    action = gtk_action_group_get_action (action_group, "EditRenumberSubaccountsAction");
 +    g_object_set (G_OBJECT(action), "sensitive",
 +                  is_readwrite && sensitive && subaccounts, NULL);
 +
 +    gnc_plugin_update_actions (action_group, actions_requiring_account_rw,
 +                               "sensitive", is_readwrite && sensitive);
 +    gnc_plugin_update_actions (action_group, actions_requiring_account_always,
 +                               "sensitive", sensitive);
 +}
 +
 +
 +/* Command callbacks */
 +static void
 +gnc_plugin_page_account_tree_cmd_new_account (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    Account *account = gnc_plugin_page_account_tree_get_current_account (page);
 +    GtkWindow *parent = GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (page)));
 +    gnc_ui_new_account_window (parent, gnc_get_current_book(),
 +                               account);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_file_new_hierarchy (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    gnc_ui_hierarchy_assistant(FALSE);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_open_account (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    Account *account;
 +
 +    g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE (page));
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    gppat_open_account_common (page, account, FALSE);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_open_subaccounts (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    Account *account;
 +
 +    g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE (page));
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    gppat_open_account_common (page, account, TRUE);
 +}
 +
 +
 +/*################## Added for Reg2 #################*/
 +/* Register Firing - Single Account to start with    */
 +static void
 +gnc_plugin_page_account_tree_cmd_open2_account (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    Account *account;
 +
 +    g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE (page));
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    gppat_open2_account_common (page, account, FALSE);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_open2_subaccounts (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    Account *account;
 +
 +    g_return_if_fail (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE (page));
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    gppat_open2_account_common (page, account, TRUE);
 +}
 +/*################## Added for Reg2 #################*/
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_edit_account (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    Account *account;
 +    GtkWindow *parent = GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (page)));
 +    ENTER("action %p, page %p", action, page);
 +
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    g_return_if_fail (account != NULL);
 +
 +    gnc_ui_edit_account_window (parent, account);
 +    LEAVE(" ");
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_find_account (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    GtkWidget *window;
 +
 +    ENTER("action %p, page %p", action, page);
 +
 +    window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
 +
 +    gnc_find_account_dialog (window, NULL);
 +    LEAVE(" ");
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_find_account_popup (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    Account *account = NULL;
 +    GtkWidget *window;
 +
 +    ENTER("action %p, page %p", action, page);
 +
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +
 +    window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
 +
 +    gnc_find_account_dialog (window, account);
 +    LEAVE(" ");
 +}
 +
 +/********************************************************************
 + * delete_account_helper
 + * See if this account has any splits present.  Set the user data
 + * and return the same value to stop walking the account tree if
 + * appropriate.
 + ********************************************************************/
 +typedef struct _delete_helper
 +{
 +    gboolean has_splits;
 +    gboolean has_ro_splits;
 +} delete_helper_t;
 +
 +static gpointer
 +delete_account_helper (Account * account, gpointer data)
 +{
 +    delete_helper_t *helper_res = data;
 +    GList *splits;
 +
 +    splits = xaccAccountGetSplitList (account);
 +    if (splits)
 +    {
 +        helper_res->has_splits = TRUE;
 +        while (splits)
 +        {
 +            Split *s = splits->data;
 +            Transaction *txn = xaccSplitGetParent (s);
 +            if (xaccTransGetReadOnly (txn))
 +            {
 +                helper_res->has_ro_splits = TRUE;
 +                break;
 +            }
 +            splits = splits->next;
 +        }
 +    }
 +
 +    return GINT_TO_POINTER (helper_res->has_splits || helper_res->has_ro_splits);
 +}
 +
 +/***
 + *** The OK button of a Delete Account dialog is insensitive if
 + *** and only if a sensitive account selector contains no accounts.
 + ***/
 +static void
 +set_ok_sensitivity(GtkWidget *dialog)
 +{
 +    GtkWidget *button;
 +    GtkWidget *sa_mas, *trans_mas;
 +    gint sa_mas_cnt, trans_mas_cnt;
 +    gboolean sensitive;
 +
 +    sa_mas = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_SA_MAS);
 +    trans_mas = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_TRANS_MAS);
 +    sa_mas_cnt = gnc_account_sel_get_num_account(GNC_ACCOUNT_SEL(sa_mas));
 +    trans_mas_cnt = gnc_account_sel_get_num_account(GNC_ACCOUNT_SEL(trans_mas));
 +
 +    sensitive = (((NULL == sa_mas) ||
 +                  (!gtk_widget_is_sensitive(sa_mas) || sa_mas_cnt)) &&
 +                 ((NULL == trans_mas) ||
 +                  (!gtk_widget_is_sensitive(trans_mas) || trans_mas_cnt)));
 +
 +    button = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_OK_BUTTON);
 +    gtk_widget_set_sensitive(button, sensitive);
 +}
 +
 +static void
 +gppat_populate_gas_list(GtkWidget *dialog,
 +                        GNCAccountSel *gas,
 +                        gboolean exclude_subaccounts)
 +{
 +    Account *account;
 +    GList *filter;
 +
 +    g_return_if_fail(GTK_IS_DIALOG(dialog));
 +    if (gas == NULL)
 +        return;
 +    account = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_ACCOUNT);
 +    filter = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_FILTER);
 +
 +    /* Setting the account type filter triggers GNCAccountSel population. */
 +    gnc_account_sel_set_acct_filters (gas, filter, NULL);
 +
 +    /* Accounts to be deleted must be removed. */
 +    gnc_account_sel_purge_account( gas, account, exclude_subaccounts);
 +
 +    /* The sensitivity of the OK button needs to be reevaluated. */
 +    set_ok_sensitivity(dialog);
 +}
 +
 +void
 +gppat_populate_trans_mas_list(GtkToggleButton *sa_mrb,
 +                              GtkWidget *dialog)
 +{
 +    GtkWidget *trans_mas;
 +
 +    g_return_if_fail(GTK_IS_DIALOG(dialog));
 +
 +    /* Cannot move transactions to subaccounts if they are to be deleted. */
 +    trans_mas = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_TRANS_MAS);
 +    gppat_populate_gas_list(dialog, GNC_ACCOUNT_SEL(trans_mas), !gtk_toggle_button_get_active(sa_mrb));
 +}
 +
 +/* Note that the emitting object (the toggle button) and the signal data
 + * are swapped in below callback function. This is a gtkbuilder feature:
 + * it swaps if you explicitly set an object for a signal handler in the
 + * gtkbuilder xml file.
 + */
 +void
 +gppat_set_insensitive_iff_rb_active(GtkWidget *widget, GtkToggleButton *b)
 +{
 +    GtkWidget *dialog = gtk_widget_get_toplevel(widget);
 +    GtkWidget *subaccount_trans = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_SA_TRANS);
 +    GtkWidget *sa_mas = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_SA_MAS);
 +    gboolean have_splits = GPOINTER_TO_INT (g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_SA_SPLITS));
 +
 +    gtk_widget_set_sensitive(widget, !gtk_toggle_button_get_active(b));
 +
 +    // If we have subaccount splits & delete subaccounts, enable subaccount_trans
 +    if ((have_splits) && !gtk_widget_is_sensitive(sa_mas))
 +        gtk_widget_set_sensitive(subaccount_trans, TRUE);
 +    else
 +        gtk_widget_set_sensitive(subaccount_trans, FALSE);
 +
 +    set_ok_sensitivity(dialog);
 +}
 +
 +static GtkWidget *
 +gppat_setup_account_selector (GtkBuilder *builder, GtkWidget *dialog,
 +                              const gchar *hbox, const gchar *sel_name)
 +{
 +    GtkWidget *selector = gnc_account_sel_new();
 +    GtkWidget *box = GTK_WIDGET(gtk_builder_get_object (builder, hbox));
 +
 +    gtk_box_pack_start (GTK_BOX(box), selector, TRUE, TRUE, 0);
 +    g_object_set_data(G_OBJECT(dialog), sel_name, selector);
 +
 +    gppat_populate_gas_list(dialog, GNC_ACCOUNT_SEL(selector), TRUE);
 +    gtk_widget_show_all(box);
 +
 +    return selector;
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    Account *account = gnc_plugin_page_account_tree_get_current_account (page);
 +    gchar *acct_name;
 +    delete_helper_t delete_res = { FALSE, FALSE };
 +    GtkWidget *window;
 +    GtkWidget *trans_mas = NULL; /* transaction move to account selector */
 +    GtkWidget *sa_mas = NULL;    /* subaccount move to account selector */
 +    GtkWidget *sa_trans_mas = NULL; /* subaccount's transaction move to account selector */
 +    Account *ta = NULL; /* transaction adopter */
 +    Account *saa = NULL; /* subaccount adopter */
 +    Account *sta = NULL; /* subaccount transaction adopter */
 +    GList *splits;
 +    GList* list;
 +    gint response;
 +
 +    if (NULL == account)
 +        return;
 +
 +    /* If the account has objects referring to it, show the list - the account can't be deleted until these
 +       references are dealt with. */
 +    list = qof_instance_get_referring_object_list(QOF_INSTANCE(account));
 +    if (list != NULL)
 +    {
- #define EXPLANATION "The list below shows objects which make use of the account which you want to delete.\nBefore you can delete it, you must either delete those objects or else modify them so they make use\nof another account"
++#define EXPLANATION _("The list below shows objects which make use of the account which you want to delete.\nBefore you can delete it, you must either delete those objects or else modify them so they make use\nof another account")
 +
-         gnc_ui_object_references_show( _(EXPLANATION), list);
++        gnc_ui_object_references_show(EXPLANATION, list);
 +        g_list_free(list);
 +        return;
 +    }
 +
 +    window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
 +    acct_name = gnc_account_get_full_name(account);
 +    if (!acct_name)
 +    {
 +        acct_name = g_strdup (_("(no name)"));
 +    }
 +
 +    splits = xaccAccountGetSplitList(account);
 +
 +    /*
 +     * If the account has transactions or child accounts then present a
 +     * dialog to allow the user to specify what should be done with them.
 +     */
 +    if ((NULL != splits) || (gnc_account_n_children(account) > 0))
 +    {
 +        GList *filter = NULL;
 +        GtkBuilder *builder = NULL;
 +        GtkWidget *dialog = NULL;
 +        GtkWidget *widget = NULL;
 +        gchar *title = NULL;
 +
 +        builder = gtk_builder_new();
 +        gnc_builder_add_from_file (builder, "dialog-account.glade", "account_delete_dialog");
 +
 +        dialog = GTK_WIDGET(gtk_builder_get_object (builder, "account_delete_dialog"));
 +        gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(window));
 +
 +        widget = GTK_WIDGET(gtk_builder_get_object (builder, "header"));
 +        title = g_strdup_printf(_("Deleting account %s"), acct_name);
 +        gtk_label_set_text(GTK_LABEL(widget), title);
 +        g_free(title);
 +
 +        widget = GTK_WIDGET(gtk_builder_get_object (builder, DELETE_DIALOG_OK_BUTTON));
 +        g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_OK_BUTTON, widget);
 +
 +        /*
 +         * Reparent only to accounts of the same
 +         * type as the one being deleted.
 +         */
 +        filter = g_list_prepend(NULL, (gpointer)xaccAccountGetType(account));
 +        g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_FILTER, filter);
 +        g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_ACCOUNT, account);
 +
 +        // Add the account selectors and enable sections as appropiate
 +        // setup transactions selector
 +        trans_mas = gppat_setup_account_selector (builder, dialog, "trans_mas_hbox", DELETE_DIALOG_TRANS_MAS);
 +
 +        // Does the selected account have splits
 +        if (splits)
 +        {
 +            delete_helper_t delete_res2 = { FALSE, FALSE };
 +
 +            delete_account_helper(account, &delete_res2);
 +            if (delete_res2.has_ro_splits)
 +            {
 +                gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "trans_rw")));
 +                widget = GTK_WIDGET(gtk_builder_get_object (builder, "trans_drb"));
 +                gtk_widget_set_sensitive(widget, FALSE);
 +            }
 +            else
 +                gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "trans_ro")));
 +        }
 +        else
 +        {
 +            gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object (builder, "transactions")), FALSE);
 +            gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "trans_ro")));
 +        }
 +
 +        // setup subaccount account selector
 +        sa_mas = gppat_setup_account_selector (builder, dialog, "sa_mas_hbox", DELETE_DIALOG_SA_MAS);
 +
 +        // setup subaccount transaction selector
 +        sa_trans_mas = gppat_setup_account_selector (builder, dialog, "sa_trans_mas_hbox", DELETE_DIALOG_SA_TRANS_MAS);
 +        g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_SA_TRANS,
 +                          GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_trans")));
 +
 +        // Does the selected account have sub accounts
 +        if (gnc_account_n_children(account) > 0)
 +        {
 +            // Check for RO txns in descendants
 +            gnc_account_foreach_descendant_until(account, delete_account_helper,
 +                                                 &delete_res);
 +            if (delete_res.has_splits)
 +            {
 +                if (delete_res.has_ro_splits)
 +                {
 +                    gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_rw")));
 +                    widget = GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_drb"));
 +                    gtk_widget_set_sensitive(widget, FALSE);
 +                }
 +                else
 +                    gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_ro")));
 +
 +                g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_SA_SPLITS, GINT_TO_POINTER(1));
 +            }
 +            else
 +            {
 +                g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_SA_SPLITS, GINT_TO_POINTER(0));
 +                gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_trans")), FALSE);
 +                gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_ro")));
 +            }
 +        }
 +        else
 +        {
 +            gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object (builder, "subaccounts")), FALSE);
 +            gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_trans")), FALSE);
 +            gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_ro")));
 +        }
 +
 +        /* default to cancel */
 +        gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
 +
 +        gtk_builder_connect_signals(builder, dialog);
 +        g_object_unref(G_OBJECT(builder));
 +
 +        /*
 +         * Note that one effect of the modal dialog is preventing
 +         * the account selectors from being repopulated.
 +         */
 +        response = gtk_dialog_run(GTK_DIALOG(dialog));
 +        if (GTK_RESPONSE_ACCEPT != response)
 +        {
 +            /* Account deletion is cancelled, so clean up and return. */
 +            gtk_widget_destroy(dialog);
 +            g_list_free(filter);
 +            g_free(acct_name);
 +            return;
 +        }
 +        if (trans_mas && gtk_widget_is_sensitive(trans_mas))
 +            ta = gnc_account_sel_get_account(GNC_ACCOUNT_SEL(trans_mas));
 +        if (sa_mas && gtk_widget_is_sensitive(sa_mas))
 +            saa = gnc_account_sel_get_account(GNC_ACCOUNT_SEL(sa_mas));
 +        if (sa_trans_mas && gtk_widget_is_sensitive(sa_trans_mas))
 +            sta = gnc_account_sel_get_account(GNC_ACCOUNT_SEL(sa_trans_mas));
 +        gtk_widget_destroy(dialog);
 +        g_list_free(filter);
 +    } /* (NULL != splits) || (NULL != children) */
 +
 +    /*
 +     * Present a message to the user which specifies what will be
 +     * deleted and what will be reparented, then ask for verification.
 +     */
 +    {
 +        const char *format = _("The account %s will be deleted.");
 +        char *lines[8];
 +        char *message;
 +        char *name;
 +        int i = 0;
 +        GtkWidget *dialog;
 +
 +        lines[0] = g_strdup_printf(format, acct_name);
 +        if (splits)
 +        {
 +            if (ta)
 +            {
 +                name = gnc_account_get_full_name(ta);
 +                format = _("All transactions in this account will be moved to "
 +                           "the account %s.");
 +                lines[++i] = g_strdup_printf(format, name);
 +            }
 +            else if (splits)
 +            {
 +                format = _("All transactions in this account will be deleted.");
 +                lines[++i] = g_strdup_printf("%s", format);
 +            }
 +        }
 +        if (gnc_account_n_children(account) > 0)
 +        {
 +            if (saa)
 +            {
 +                name = gnc_account_get_full_name(saa);
 +                format = _("All of its sub-accounts will be moved to "
 +                           "the account %s.");
 +                lines[++i] = g_strdup_printf(format, name);
 +            }
 +            else
 +            {
 +                format = _("All of its subaccounts will be deleted.");
 +                lines[++i] = g_strdup_printf("%s", format);
 +                if (sta)
 +                {
 +                    name = gnc_account_get_full_name(sta);
 +                    format = _("All sub-account transactions will be moved to "
 +                               "the account %s.");
 +                    lines[++i] = g_strdup_printf(format, name);
 +                }
 +                else if (delete_res.has_splits)
 +                {
 +                    format = _("All sub-account transactions will be deleted.");
 +                    lines[++i] = g_strdup_printf("%s", format);
 +                }
 +            }
 +        }
 +        lines[++i] = _("Are you sure you want to do this?");
 +        lines[i] = NULL;
 +        i--; /* Don't try to free the constant question. */
 +        message = g_strjoinv(" ", lines);
 +        while (i--)
 +        {
 +            g_free(lines[i]);
 +        }
 +
 +        dialog =  gtk_message_dialog_new(GTK_WINDOW(window),
 +                                         GTK_DIALOG_DESTROY_WITH_PARENT,
 +                                         GTK_MESSAGE_QUESTION,
 +                                         GTK_BUTTONS_NONE,
 +                                         "%s", message);
 +        g_free(message);
 +        gtk_dialog_add_buttons(GTK_DIALOG(dialog),
 +                               _("_Cancel"), GTK_RESPONSE_CANCEL,
 +                               _("_Delete"), GTK_RESPONSE_ACCEPT,
 +                               (gchar *)NULL);
 +        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
 +        response = gtk_dialog_run(GTK_DIALOG(dialog));
 +        gtk_widget_destroy(dialog);
 +
 +        if (GTK_RESPONSE_ACCEPT == response)
 +        {
 +            GList *acct_list, *ptr;
 +            const GncGUID *guid;
 +            gchar guidstr[GUID_ENCODING_LENGTH+1];
 +
 +            gnc_set_busy_cursor(NULL, TRUE);
 +            gnc_suspend_gui_refresh ();
 +
 +            /* Move subaccounts and transactions if this was requested */
 +            xaccAccountBeginEdit (account);
 +            if (NULL != saa)
 +            {
 +
 +                xaccAccountBeginEdit (saa);
 +                acct_list = gnc_account_get_children(account);
 +                for (ptr = acct_list; ptr; ptr = g_list_next(ptr))
 +                    gnc_account_append_child (saa, ptr->data);
 +                g_list_free(acct_list);
 +                xaccAccountCommitEdit (saa);
 +            }
 +            else if (NULL != sta)
 +            {
 +                /* Move the splits of its subaccounts, if any. */
 +                gnc_account_foreach_descendant(account,
 +                                               (AccountCb)xaccAccountMoveAllSplits,
 +                                               sta);
 +            }
 +            if (NULL != ta)
 +            {
 +                /* Move the splits of the account to be deleted. */
 +                xaccAccountMoveAllSplits (account, ta);
 +            }
 +            xaccAccountCommitEdit (account);
 +
 +            /* Drop all references from the state file for
 +             * any subaccount the account still has
 +             */
 +            acct_list = gnc_account_get_children(account);
 +            for (ptr = acct_list; ptr; ptr = g_list_next(ptr))
 +            {
 +                guid = xaccAccountGetGUID (ptr->data);
 +                guid_to_string_buff (guid, guidstr);
 +                gnc_state_drop_sections_for (guidstr);
 +            }
 +            g_list_free(acct_list);
 +
 +            /* Drop all references from the state file for this account
 +             */
 +            guid = xaccAccountGetGUID (account);
 +            guid_to_string_buff (guid, guidstr);
 +            gnc_state_drop_sections_for (guidstr);
 +
 +            /*
 +             * Finally, delete the account, any subaccounts it may still
 +             * have, and any splits it or its subaccounts may still have.
 +             */
 +            xaccAccountBeginEdit (account);
 +            xaccAccountDestroy (account);
 +            gnc_resume_gui_refresh ();
 +            gnc_unset_busy_cursor(NULL);
 +        }
 +    }
 +    g_free(acct_name);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_renumber_accounts (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    Account *account;
 +    GtkWidget *window;
 +
 +    window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
 +    account = gnc_plugin_page_account_tree_get_current_account(page);
 +    if (!window || !account)
 +        return;
 +
 +    gnc_account_renumber_create_dialog(window, account);
 +}
 +
 +/*********************/
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_view_filter_by (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    GncPluginPageAccountTreePrivate *priv;
 +
 +    g_return_if_fail(GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page));
 +    ENTER("(action %p, page %p)", action, page);
 +
 +    priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
 +    account_filter_dialog_create(&priv->fd, GNC_PLUGIN_PAGE(page));
 +    LEAVE(" ");
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_reconcile (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    GtkWidget *window;
 +    Account *account;
 +    RecnWindow *recnData;
 +
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    g_return_if_fail (account != NULL);
 +
 +    window = GNC_PLUGIN_PAGE (page)->window;
 +    recnData = recnWindow (window, account);
 +    gnc_ui_reconcile_window_raise (recnData);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_autoclear (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    GtkWidget *window;
 +    Account *account;
 +    AutoClearWindow *autoClearData;
 +
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    g_return_if_fail (account != NULL);
 +
 +    window = GNC_PLUGIN_PAGE (page)->window;
 +    autoClearData = autoClearWindow (window, account);
 +    gnc_ui_autoclear_window_raise (autoClearData);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_transfer (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    GtkWidget *window;
 +    Account *account;
 +
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    window = GNC_PLUGIN_PAGE (page)->window;
 +    gnc_xfer_dialog (window, account);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_stock_split (GtkAction *action,
 +        GncPluginPageAccountTree *page)
 +{
 +    GtkWidget *window;
 +    Account *account;
 +
 +    account = gnc_plugin_page_account_tree_get_current_account (page);
 +    window = GNC_PLUGIN_PAGE (page)->window;
 +    gnc_stock_split_dialog (window, account);
 +}
 +
 +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);
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_scrub (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    Account *account = gnc_plugin_page_account_tree_get_current_account (page);
 +    GncWindow *window;
 +
 +    g_return_if_fail (account != NULL);
 +
 +    gnc_suspend_gui_refresh ();
 +
 +    window = GNC_WINDOW(GNC_PLUGIN_PAGE (page)->window);
 +    gnc_window_set_progressbar_window (window);
 +
 +    xaccAccountScrubOrphans (account, gnc_window_show_progress);
 +    xaccAccountScrubImbalance (account, gnc_window_show_progress);
 +
 +    // XXX: Lots/capital gains scrubbing is disabled
 +    if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
 +        xaccAccountScrubLots(account);
 +
 +    gncScrubBusinessAccount(account, gnc_window_show_progress);
 +
 +
 +    gnc_resume_gui_refresh ();
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_scrub_sub (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    Account *account = gnc_plugin_page_account_tree_get_current_account (page);
 +    GncWindow *window;
 +
 +    g_return_if_fail (account != NULL);
 +
 +    gnc_suspend_gui_refresh ();
 +
 +    window = GNC_WINDOW(GNC_PLUGIN_PAGE (page)->window);
 +    gnc_window_set_progressbar_window (window);
 +
 +    xaccAccountTreeScrubOrphans (account, gnc_window_show_progress);
 +    xaccAccountTreeScrubImbalance (account, gnc_window_show_progress);
 +
 +    // XXX: Lots/capital gains scrubbing is disabled
 +    if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
 +        xaccAccountTreeScrubLots(account);
 +
 +    gncScrubBusinessAccountTree(account, gnc_window_show_progress);
 +
 +    gnc_resume_gui_refresh ();
 +}
 +
 +static void
 +gnc_plugin_page_account_tree_cmd_scrub_all (GtkAction *action, GncPluginPageAccountTree *page)
 +{
 +    Account *root = gnc_get_current_root_account ();
 +    GncWindow *window;
 +
 +    gnc_suspend_gui_refresh ();
 +
 +    window = GNC_WINDOW(GNC_PLUGIN_PAGE (page)->window);
 +    gnc_window_set_progressbar_window (window);
 +
 +    xaccAccountTreeScrubOrphans (root, gnc_window_show_progress);
 +    xaccAccountTreeScrubImbalance (root, gnc_window_show_progress);
 +    // XXX: Lots/capital gains scrubbing is disabled
 +    if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
 +        xaccAccountTreeScrubLots(root);
 +
 +    gncScrubBusinessAccountTree(root, gnc_window_show_progress);
 +
 +    gnc_resume_gui_refresh ();
 +}
 +
 +/** @} */
 +/** @} */
diff --cc libgnucash/app-utils/date-utilities.scm
index 1729d08,0000000..1e6b2f6
mode 100644,000000..100644
--- a/libgnucash/app-utils/date-utilities.scm
+++ b/libgnucash/app-utils/date-utilities.scm
@@@ -1,1072 -1,0 +1,1072 @@@
 +;; date-utilities.scm -- date utility functions.
 +;; Bryan Larsen (blarsen at ada-works.com)
 +;; Revised by Christopher Browne
 +;; Improvement to financial year support by Yves-Eric Martin
 +;;
 +;; 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 (gnucash core-utils)
 +             (gnucash gettext))
 +
 +(define gnc:reldate-list '())
 +
 +;; get stuff from localtime date vector
 +(define (gnc:date-get-year datevec)
 +  (+ 1900 (tm:year datevec)))
 +(define (gnc:date-get-quarter datevec)
 +  (+ (quotient (tm:mon datevec) 3) 1))
 +(define (gnc:date-get-month-day datevec)
 +  (tm:mday datevec))
 +;; get month with january==1
 +(define (gnc:date-get-month datevec)
 +  (+ (tm:mon datevec) 1))
 +(define (gnc:date-get-week-day datevec)
 +  (+ (tm:wday datevec) 1))
 +;; jan 1 == 1
 +(define (gnc:date-get-week datevec)
 +  (gnc:date-to-week (gnc:time64-start-day-time
 +                     (gnc-mktime datevec))))
 +
 +(define (gnc:date-get-year-day datevec)
 +  (+ (tm:yday datevec) 1))
 +
 +(define (gnc:time64-get-year t64)
 +  (gnc:date-get-year (gnc-localtime t64)))
 +
 +(define (gnc:time64-get-quarter t64)
 +  (gnc:date-get-quarter (gnc-localtime t64)))
 +
 +(define (gnc:time64-get-month-day t64)
 +  (gnc:date-get-month-day (gnc-localtime t64)))
 +
 +(define (gnc:time64-get-month t64)
 +  (gnc:date-get-month (gnc-localtime t64)))
 +
 +(define (gnc:time64-get-week-day t64)
 +  (gnc:date-get-week-day (gnc-localtime t64)))
 +
 +(define (gnc:time64-get-week t64)
 +  (gnc:date-get-week (gnc-localtime t64)))
 +
 +(define (gnc:time64-get-year-day t64)
 +  (gnc:date-get-year-day (gnc-localtime t64)))
 +
 +(define (gnc:date-get-year-string datevec)
 +  (gnc-locale-to-utf8 (strftime "%Y" datevec)))
 +
 +(define (gnc:date-get-quarter-string datevec)
 +  (format #f "Q~d" (gnc:date-get-quarter datevec)))
 +
 +(define (gnc:date-get-quarter-year-string datevec)
 +  (string-append 
 +   (gnc:date-get-quarter-string datevec) 
 +   " " 
 +   (gnc:date-get-year-string datevec)))
 +
 +(define (gnc:date-get-month-string datevec)
 +  (gnc-locale-to-utf8 (strftime "%B" datevec)))
 +
 +(define (gnc:date-get-month-year-string datevec)
 +  (gnc-locale-to-utf8 (strftime "%B %Y" datevec)))
 +
 +(define (gnc:date-get-week-year-string datevec)
 +  (let* ((beginweekt64 (* (gnc:time64-get-week
 +                            (gnc-mktime datevec))
 +                          604800))
 +         (begin-string (qof-print-date (+ beginweekt64 345600)))
 +         (end-string (qof-print-date (+ beginweekt64 864000))))
 +    (format #f (_ "~a to ~a") begin-string end-string)))
 +
 +;; is leap year?
 +(define (gnc:leap-year? year)
 +  (or (and (zero? (remainder year 4))
 +           (not (zero? (remainder year 100))))
 +      (zero? (remainder year 400))))
 +
 +;; number of days in year
 +(define (gnc:days-in-year year)
 +  (if (gnc:leap-year? year) 366 365))
 +
 +;; number of days in month
 +(define (gnc:days-in-month month year)
 +  (case month
 +    ((1 3 5 7 8 10 12) 31)
 +    ((4 6 9 11) 30)
 +    ((2) (if (gnc:leap-year? year) 29 28))))
 +
 +;; convert a date in seconds since 1970 into # of years since 1970 as
 +;; a fraction.
 +(define (gnc:date-to-year-fraction caltime)
 +  (let ((lt (gnc-localtime caltime)))
 +    (+ (- (gnc:date-get-year lt) 1970)
 +       (/ (- (gnc:date-get-year-day lt) 1.0)
 +	  (* 1.0 (gnc:days-in-year (gnc:date-get-year lt)))))))
 +
 +;; return the number of years (in floating point format) between two dates.
 +(define (gnc:date-year-delta caltime1 caltime2)
 +  (let* ((lt1 (gnc-localtime caltime1))
 +	 (lt2 (gnc-localtime caltime2))
 +	 (day1 (gnc:date-get-year-day lt1))
 +	 (day2 (gnc:date-get-year-day lt2))
 +	 (year1 (gnc:date-get-year lt1))
 +	 (year2 (gnc:date-get-year lt2))
 +	 (dayadj1 (if (and (not (gnc:leap-year? year1))
 +			   (>= day1 59))
 +		      (+ day1 1)
 +		      day1))
 +	 (dayadj2 (if (and (not (gnc:leap-year? year2))
 +			   (>= day2 59))
 +		      (+ day2 1)
 +		      day2)))
 +    (+ (- (gnc:date-get-year lt2) (gnc:date-get-year lt1))
 +       (/ (- dayadj2 dayadj1) 
 +	  366.0))))
 +
 +;; convert a date in seconds since 1970 into # of 1/2 years since 1970 as
 +;; a fraction (doubling date-to-year-fraction)
 +(define (gnc:date-to-halfyear-fraction caltime)
 +  (* (gnc:date-to-year-fraction caltime) 2))
 +
 +;; convert a date in seconds since 1970 into # of quarters since 1970
 +;; (assuming quarter = 3 months and using 1/3 of date-to-month-fraction)
 +(define (gnc:date-to-quarter-fraction caltime)
 +  (/ (gnc:date-to-month-fraction caltime) 3))
 +
 +;; convert a date in seconds since 1970 into # of months since 1970
 +(define (gnc:date-to-month-fraction caltime)
 +  (let ((lt (gnc-localtime caltime)))
 +    (+ (* 12 (- (gnc:date-get-year lt) 1970.0))
 +       (gnc:date-get-month lt) -1
 +       (/ (- (gnc:date-get-month-day lt) 1.0) (gnc:days-in-month 
 +					       (gnc:date-get-month lt)
 +					       (gnc:date-get-year lt))))))
 +
 +;; convert a date in seconds since 1970 into # of two-week periods since
 +;; Jan 4, 1970 ignoring leap-seconds (just halfing date-to-week-fraction)
 +(define (gnc:date-to-twoweek-fraction caltime)
 +  (/ (gnc:date-to-week-fraction caltime) 2))
 +
 +;; convert a date in seconds since 1970 into # of weeks since Jan 4, 1970
 +;; ignoring leap-seconds
 +(define (gnc:date-to-week-fraction caltime)
 +  (/ (- (/ (/ caltime 3600.0) 24) 3) 7))
 +
 +(define (gnc:date-to-week caltime)
 +  (floor (/ (- (/ caltime 86400) 3) 7)))
 +
 +;; convert a date in seconds since 1970 into # of days since Feb 28, 1970
 +;; ignoring leap-seconds
 +(define (gnc:date-to-day-fraction caltime)
 +  (- (/ (/ caltime 3600.0) 24) 59))
 +
 +;; Returns the function that converts a date into a fraction of
 +;; {year,month,week,day} according to the given symbol, or #f if the
 +;; symbol was unknown
 +(define (gnc:date-get-fraction-func interval)
 +  (case interval
 +    ((YearDelta) gnc:date-to-year-fraction)
 +    ((HalfYearDelta) gnc:date-to-halfyear-fraction)
 +    ((QuarterDelta) gnc:date-to-quarter-fraction)
 +    ((MonthDelta) gnc:date-to-month-fraction)
 +    ((TwoWeekDelta) gnc:date-to-twoweek-fraction)
 +    ((WeekDelta) gnc:date-to-week-fraction)
 +    ((DayDelta) gnc:date-to-day-fraction)
 +    (else #f)))
 +
 +;; Modify a date
 +(define (moddate op adate delta)
 +  (let ((newtm (gnc-localtime adate)))
 +    (begin
 +      (set-tm:sec newtm (op (tm:sec newtm) (tm:sec delta)))
 +      (set-tm:min newtm (op (tm:min newtm) (tm:min delta)))
 +      (set-tm:hour newtm (op (tm:hour newtm) (tm:hour delta)))
 +      (set-tm:mday newtm (op (tm:mday newtm) (tm:mday delta)))
 +      (set-tm:mon newtm (op (tm:mon newtm) (tm:mon delta)))
 +      (set-tm:year newtm (op (tm:year newtm) (tm:year delta)))
 +      (set-tm:isdst newtm -1)
 +      (gnc-mktime newtm))))
 +
 +;; Add or subtract time from a date
 +(define (decdate adate delta) (moddate - adate delta ))
 +(define (incdate adate delta) (moddate + adate delta ))
 +
 +;; date-granularity comparison functions.
 +
 +(define (gnc:time64-le-date t1 t2)
 +  (<= (time64CanonicalDayTime t1)
 +      (time64CanonicalDayTime t2)))
 +
 +(define (gnc:time64-ge-date t1 t2)
 +  (gnc:time64-le-date t2 t1))
 +
 +;; Build a list of time intervals. 
 +;;
 +;; Note that the last interval will be shorter than <incr> if
 +;; (<curd>-<endd>) is not an integer multiple of <incr>. If you don't
 +;; want that you'll have to write another function.
 +(define (gnc:make-date-interval-list current-date end-date increment)
 +  (if (< current-date end-date)
 +      (let ((next-date (incdate current-date increment)))
 +        (if (< next-date end-date)
 +            (cons (list current-date (decdate next-date SecDelta) '())
 +                  (gnc:make-date-interval-list next-date end-date increment))
 +            (cons (list current-date end-date '())
 +                  '())))
 +      '()))
 +  
 +;; Build a list of times.  The dates are evenly spaced with the
 +;; stepsize 'incr'. If the difference of 'startdate' and 'enddate' is
 +;; not an integer multiple of 'incr', 'enddate' will be added as the
 +;; last element of the list, thus making the last interval smaller
 +;; than 'incr'.
 +(define (gnc:make-date-list startdate enddate incr)
 +  (if (< startdate enddate)
 +      (cons startdate
 +            (gnc:make-date-list (incdate startdate incr)
 +                                enddate incr))
 +      (list enddate)))
 +
 +; A reference zero date - the Beginning Of The Epoch
 +; Note: use of eval is evil... by making this a generator function, 
 +; each delta function gets its own instance of Zero Date
 +(define (make-zdate) 
 +  (let ((zd (gnc-localtime (current-time))))
 +    (set-tm:hour zd 0)
 +    (set-tm:min zd 0)
 +    (set-tm:sec zd 0)
 +    (set-tm:mday zd 0)
 +    (set-tm:mon zd 0)
 +    (set-tm:year zd 0)
 +    (set-tm:yday zd 0)
 +    (set-tm:wday zd 0)
 +    (set-tm:isdst zd 0)
 +    zd))
 +
 +
 +(define SecDelta 
 +  (let ((ddt (make-zdate)))
 +    (set-tm:sec ddt 1)
 +    ddt))
 +
 +(define DayDelta
 +  (let ((ddt (make-zdate)))
 +    (set-tm:mday ddt 1)
 +    ddt))
 +
 +(define WeekDelta 
 +  (let ((ddt (make-zdate)))
 +    (set-tm:mday ddt 7)
 +    ddt))
 +
 +(define TwoWeekDelta
 +  (let ((ddt (make-zdate)))
 +    (set-tm:mday ddt 14)
 +    ddt))
 +
 +(define MonthDelta
 +  (let ((ddt (make-zdate)))
 +    (set-tm:mon ddt 1)
 +    ddt))
 +
 +(define QuarterDelta
 +  (let ((ddt (make-zdate)))
 +    (set-tm:mon ddt 3)
 +    ddt))
 +
 +(define HalfYearDelta
 +  (let ((ddt (make-zdate)))
 +    (set-tm:mon ddt 6)
 +    ddt))
 +
 +(define YearDelta 
 +  (let ((ddt (make-zdate)))
 +    (set-tm:year ddt 1)
 +    ddt))
 +
 +
 +(define ThirtyDayDelta
 +  (let ((ddt (make-zdate)))
 +    (set-tm:mday ddt 30)
 +    ddt))
 +
 +(define NinetyDayDelta
 +  (let ((ddt (make-zdate)))
 +    (set-tm:mday ddt 90)
 +    ddt))
 +
 +;; if you add any more FooDeltas, add to this list!!!
 +
 +(define deltalist
 +  (list (cons 'SecDelta SecDelta)
 +	(cons 'DayDelta DayDelta)
 +	(cons 'WeekDelta WeekDelta)
 +	(cons 'TwoWeekDelta TwoWeekDelta)
 +	(cons 'MonthDelta MonthDelta)
 +	(cons 'QuarterDelta QuarterDelta)
 +	(cons 'HalfYearDelta HalfYearDelta)
 +	(cons 'YearDelta YearDelta)
 +	(cons 'ThirtyDayDelta ThirtyDayDelta)
 +	(cons 'NinetyDayDelta NinetyDayDelta)))
 +
 +(define (gnc:deltasym-to-delta ds)
 +  (let ((retval (assq ds deltalist)))
 +    (if (pair? retval)
 +	(cdr retval)
 +	#f)))
 +
 +;; given a time64 time on a certain day (local time)
 +;; converts it to be midday that day.
 +
 +(define (gnc:time64-start-day-time t64)
 +  (let ((bdt (gnc-localtime t64)))
 +    (set-tm:sec bdt 0)
 +    (set-tm:min bdt 0)
 +    (set-tm:hour bdt 0)
 +    (set-tm:isdst bdt -1)
 +    (gnc-mktime bdt)))
 +
 +(define (gnc:time64-end-day-time t64)
 +  (let ((bdt (gnc-localtime t64)))
 +    (set-tm:sec bdt 59)
 +    (set-tm:min bdt 59)
 +    (set-tm:hour bdt 23)
 +    (set-tm:isdst bdt -1)
 +    (gnc-mktime bdt)))
 +
 +(define (gnc:time64-previous-day t64)
 +  (decdate t64 DayDelta))
 +
 +(define (gnc:time64-next-day t64)
 +  (incdate t64 DayDelta))
 +
 +
 +(define (gnc:reldate-get-symbol x) (vector-ref x 0))
 +(define (gnc:reldate-get-string x) (vector-ref x 1))
 +(define (gnc:reldate-get-desc x) (vector-ref x 2))
 +(define (gnc:reldate-get-fn x) (vector-ref x 3))
 +
 +(define (gnc:make-reldate-hash hash reldate-list)
 +  (map (lambda (reldate) (hash-set! 
 +			  hash 
 +			  (gnc:reldate-get-symbol reldate)
 +			  reldate))
 +       reldate-list))
 +
 +(define gnc:reldate-string-db (gnc:make-string-database))
 +
 +(define gnc:relative-date-values '())
 +
 +(define gnc:relative-date-hash (make-hash-table 23))
 +
 +(define (gnc:get-absolute-from-relative-date date-symbol)
 +  (let ((rel-date-data (hash-ref gnc:relative-date-hash date-symbol)))
 +    (if rel-date-data
 +       ((gnc:reldate-get-fn rel-date-data))
 +       (gnc:error "Tried to look up an undefined date symbol"))))
 +
 +(define (gnc:get-relative-date-strings date-symbol)
 +  (let ((rel-date-info (hash-ref gnc:relative-date-hash date-symbol)))
 +    
 +    (cons (gnc:reldate-get-string rel-date-info)
 +	  (gnc:relate-get-desc rel-date-info))))
 +
 +(define (gnc:get-relative-date-string date-symbol)
 +  (let ((rel-date-info (hash-ref gnc:relative-date-hash date-symbol)))
 +    (gnc:reldate-get-string rel-date-info)))
 +
 +(define (gnc:get-relative-date-desc date-symbol)
 +  (let ((rel-date-info (hash-ref gnc:relative-date-hash date-symbol)))
 +    (gnc:reldate-get-desc rel-date-info)))
 +
 +(define (gnc:get-start-cal-year)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (set-tm:mon now 0)
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-cal-year)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59)
 +    (set-tm:hour now 23)
 +    (set-tm:mday now 31)
 +    (set-tm:mon now 11)
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-start-prev-year)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (set-tm:mon now 0)
 +    (set-tm:year now (- (tm:year now) 1))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-prev-year)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59)
 +    (set-tm:hour now 23)
 +    (set-tm:mday now 31)
 +    (set-tm:mon now 11)
 +    (set-tm:year now (- (tm:year now) 1))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-start-next-year)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (set-tm:mon now 0)
 +    (set-tm:year now (+ (tm:year now) 1))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-next-year)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59)
 +    (set-tm:hour now 23)
 +    (set-tm:mday now 31)
 +    (set-tm:mon now 11)
 +    (set-tm:year now (+ (tm:year now) 1))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-start-accounting-period)
 +  (gnc-accounting-period-fiscal-start))
 +
 +(define (gnc:get-end-accounting-period)
 +  (gnc-accounting-period-fiscal-end))
 +
 +(define (gnc:get-start-this-month)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-this-month)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59) 
 +    (set-tm:hour now 23)
 +    (set-tm:mday now (gnc:days-in-month (+ (tm:mon now) 1) 
 +					(+ (tm:year now) 1900)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +    
 +(define (gnc:get-start-prev-month)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (if (= (tm:mon now) 0)
 +	(begin 
 +	  (set-tm:mon now 11)
 +	  (set-tm:year now (- (tm:year now) 1)))
 +	(set-tm:mon now (- (tm:mon now) 1)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-prev-month)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59) 
 +    (set-tm:hour now 23)
 +    (if (= (tm:mon now) 0)
 +	(begin
 +	  (set-tm:mon now 11)
 +	  (set-tm:year now (- (tm:year now) 1)))
 +	(set-tm:mon now (- (tm:mon now) 1)))
 +    (set-tm:mday now (gnc:days-in-month (+ (tm:mon now) 1) 
 +					(+ (tm:year now) 1900)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +    
 +(define (gnc:get-start-next-month)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (if (= (tm:mon now) 11)
 +	(begin 
 +	  (set-tm:mon now 0)
 +	  (set-tm:year now (+ (tm:year now) 1)))
 +	(set-tm:mon now (+ (tm:mon now) 1)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-next-month)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59) 
 +    (set-tm:hour now 23)
 +    (if (= (tm:mon now) 11)
 +	(begin
 +	  (set-tm:mon now 0)
 +	  (set-tm:year now (+ (tm:year now) 1)))
 +	(set-tm:mon now (+ (tm:mon now) 1)))
 +    (set-tm:mday now (gnc:days-in-month (+ (tm:mon now) 1) 
 +					(+ (tm:year now) 1900)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +    
 +(define (gnc:get-start-current-quarter)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (set-tm:mon now (- (tm:mon now) (modulo (tm:mon now) 3)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-current-quarter)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59)
 +    (set-tm:hour now 23)
 +    (set-tm:mon now (+ (tm:mon now) 
 +		       (- 2 (modulo (tm:mon now) 3))))
 +    (set-tm:mday now (gnc:days-in-month (+ (tm:mon now) 1)
 +                                        (+ (tm:year now) 1900)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-start-prev-quarter)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (set-tm:mon now (- (tm:mon now) (modulo (tm:mon now) 3)))
 +    (if (= (tm:mon now) 0)
 +	(begin
 +	  (set-tm:mon now 9)
 +	  (set-tm:year now (- (tm:year now) 1)))
 +	(set-tm:mon now (- (tm:mon now) 3)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-prev-quarter)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59)
 +    (set-tm:hour now 23)
 +    (if (< (tm:mon now) 3)
 +	(begin
 +	  (set-tm:mon now 11)
 +	  (set-tm:year now (- (tm:year now) 1)))
 +	(set-tm:mon now (- (tm:mon now) 
 +			     (+ 1 (modulo (tm:mon now) 3)))))
 +    (set-tm:mday now (gnc:days-in-month (+ (tm:mon now) 1)
 +                                        (+ (tm:year now) 1900)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-start-next-quarter)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 0)
 +    (set-tm:min now 0)
 +    (set-tm:hour now 0)
 +    (set-tm:mday now 1)
 +    (if (> (tm:mon now) 8)
 +	(begin
 +	  (set-tm:mon now 0)
 +	  (set-tm:year now (+ (tm:year now) 1)))
 +        (set-tm:mon now (+ (tm:mon now) (- 3 (modulo (tm:mon now) 3)))))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-end-next-quarter)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set-tm:sec now 59)
 +    (set-tm:min now 59)
 +    (set-tm:hour now 23)
 +    (if (> (tm:mon now) 8)
 +	(begin
 +	  (set-tm:mon now 2)
 +	  (set-tm:year now (+ (tm:year now) 1)))
 +	(set-tm:mon now (+ (tm:mon now) 
 +			     (+ 1 (modulo (tm:mon now) 3)))))
 +    (set-tm:mday now (gnc:days-in-month (+ (tm:mon now) 1)
 +                                        (+ (tm:year now) 1900)))
 +    (set-tm:isdst now -1)
 +    (gnc-mktime now)))
 +
 +(define (gnc:get-today)
 +  (current-time))
 +
 +(define (gnc:get-one-month-ago)
 +  (let ((now (gnc-localtime (current-time))))
 +    (if (= (tm:mon now) 0)
 +	(begin
 +	  (set-tm:mon now 11)
 +	  (set-tm:year now (- (tm:year now) 1)))
 +	(set-tm:mon now (- (tm:mon now) 1)))
-     (let ((month-length (gnc:days-in-month (+ (tm:mon now) 1)
-                                            (+ (tm:year now) 1900))))
-       (if (> month-length (tm:mday now))
- 	  (set-tm:mday now month-length))
++    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
++                                         (+ (tm:year now) 1900))))
++      (if (< month-days (tm:mday now))
++	  (set-tm:mday now month-days))
 +      (set-tm:isdst now -1)
 +      (gnc-mktime now))))
 +
 +(define (gnc:get-three-months-ago)
 +  (let ((now (gnc-localtime (current-time))))
 +    (if (< (tm:mon now) 3)
 +	(begin
 +	  (set:tm-mon now (+ (tm:mon now) 12))
 +	  (set:tm-year now  (- (tm:year now) 1))))
 +    (set:tm-mon now (- (tm:mon now) 3))
 +    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
 +                                         (+ (tm:year now) 1900))))
-       (if (> month-days (tm:mday now))
++      (if (< month-days (tm:mday now))
 +	  (set-tm:mday now month-days))
 +      (set-tm:isdst now -1)
 +      (gnc-mktime now))))
 +
 +(define (gnc:get-six-months-ago)
 +  (let ((now (gnc-localtime (current-time))))
 +    (if (< (tm:mon now) 6)
 +	(begin
 +	  (set:tm-mon now (+ (tm:mon now) 12))
 +	  (set:tm-year now  (- (tm:year now) 1))))
 +    (set:tm-mon now (- (tm:mon now) 6))
 +    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
 +                                         (+ (tm:year now) 1900))))
-       (if (> month-days (tm:mday now))
++      (if (< month-days (tm:mday now))
 +	  (set-tm:mday now month-days))
 +      (set-tm:isdst now -1)
 +      (gnc-mktime now))))
 +
 +(define (gnc:get-one-year-ago)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set:tm-year now (- (tm:year now) 1))
 +    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
-                                           (+ (tm:year now) 1900))))
-       (if (> month-days (tm:mday now))
++                                         (+ (tm:year now) 1900))))
++      (if (< month-days (tm:mday now))
 +	  (set-tm:mday now month-days))
 +      (set-tm:isdst now -1)
 +      (gnc-mktime now))))
 +
 +(define (gnc:get-one-month-ahead)
 +  (let ((now (gnc-localtime (current-time))))
 +    (if (= (tm:mon now) 11)
 +	(begin
 +	  (set-tm:mon now 0)
 +	  (set-tm:year now (+ (tm:year now) 1)))
 +	(set-tm:mon now (+ (tm:mon now) 1)))
-     (let ((month-length (gnc:days-in-month (+ (tm:mon now) 1)
-                                            (+ (tm:year now) 1900))))
-       (if (> month-length (tm:mday now))
- 	  (set-tm:mday now month-length))
++    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
++                                         (+ (tm:year now) 1900))))
++      (if (< month-days (tm:mday now))
++	  (set-tm:mday now month-days))
 +      (set-tm:isdst now -1)
 +      (gnc-mktime now))))
 +
 +(define (gnc:get-three-months-ahead)
 +  (let ((now (gnc-localtime (current-time))))
 +    (if (> (tm:mon now) 8)
 +	(begin
 +	  (set:tm-mon now (- (tm:mon now) 9))
 +	  (set:tm-year now  (+ (tm:year now) 1))
-        (set:tm-mon now (+ (tm:mon now) 3))))
++          (set:tm-mon now (+ (tm:mon now) 3))))
 +    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
 +                                         (+ (tm:year now) 1900))))
-       (if (> month-days (tm:mday now))
++      (if (< month-days (tm:mday now))
 +	  (set-tm:mday now month-days))
 +      (set-tm:isdst now -1)
 +      (gnc-mktime now))))
 +
 +(define (gnc:get-six-months-ahead)
 +  (let ((now (gnc-localtime (current-time))))
 +    (if (> (tm:mon now) 5)
 +	(begin
 +	  (set:tm-mon now (- (tm:mon now) 6))
 +	  (set:tm-year now  (+ (tm:year now) 1))
-        (set:tm-mon now (+ (tm:mon now) 6))))
++          (set:tm-mon now (+ (tm:mon now) 6))))
 +    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
 +                                         (+ (tm:year now) 1900))))
-       (if (> month-days (tm:mday now))
++      (if (< month-days (tm:mday now))
 +	  (set-tm:mday now month-days))
 +      (set-tm:isdst now -1)
 +      (gnc-mktime now))))
 +
 +(define (gnc:get-one-year-ahead)
 +  (let ((now (gnc-localtime (current-time))))
 +    (set:tm-year now (+ (tm:year now) 1))
 +    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
-                                           (+ (tm:year now) 1900))))
-       (if (> month-days (tm:mday now))
++                                         (+ (tm:year now) 1900))))
++      (if (< month-days (tm:mday now))
 +	  (set-tm:mday now month-days))
 +      (set-tm:isdst now -1)
 +      (gnc-mktime now))))
 +
 +;; There is no GNC:RELATIVE-DATES list like the one mentioned in
 +;; gnucash-design.info, is there? Here are the currently defined
 +;; items, loosely grouped.
 +;;today
 +;;start-cal-year end-cal-year start-prev-year end-prev-year
 +;;start-this-month end-this-month start-prev-month end-prev-month
 +;;start-current-quarter end-current-quarter start-prev-quarter
 +;;end-prev-quarter
 +;;one-month-ago three-months-ago six-months-ago one-year-ago
 +;;start-cur-fin-year start-prev-fin-year end-prev-fin-year
 +
 +(define (gnc:reldate-initialize)
 +  (gnc:reldate-string-db 
 +   'store 'start-cal-year-string 
 +   (N_ "Start of this year"))
 +  (gnc:reldate-string-db 
 +   'store 'start-cal-year-desc 
 +   (N_ "First day of the current calendar year."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-cal-year-string 
 +   (N_ "End of this year"))
 +  (gnc:reldate-string-db 
 +   'store 'end-cal-year-desc 
 +   (N_ "Last day of the current calendar year."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-prev-year-string 
 +   (N_ "Start of previous year"))
 +  (gnc:reldate-string-db 
 +   'store 'start-prev-year-desc 
 +   (N_ "First day of the previous calendar year."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-prev-year-string 
 +   (N_ "End of previous year"))
 +  (gnc:reldate-string-db 
 +   'store 'end-prev-year-desc 
 +   (N_ "Last day of the previous calendar year."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-next-year-string 
 +   (N_ "Start of next year"))
 +  (gnc:reldate-string-db 
 +   'store 'start-next-year-desc 
 +   (N_ "First day of the next calendar year."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-next-year-string 
 +   (N_ "End of next year"))
 +  (gnc:reldate-string-db 
 +   'store 'end-next-year-desc 
 +   (N_ "Last day of the next calendar year."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-accounting-period-string 
 +   (N_ "Start of accounting period"))
 +  (gnc:reldate-string-db 
 +   'store 'start-accounting-period-desc 
 +   (N_ "First day of the accounting period, as set in the global preferences."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-accounting-period-string 
 +   (N_ "End of accounting period"))
 +  (gnc:reldate-string-db 
 +   'store 'end-accounting-period-desc 
 +   (N_ "Last day of the accounting period, as set in the global preferences."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-this-month-string 
 +   (N_ "Start of this month"))
 +  (gnc:reldate-string-db 
 +   'store 'start-this-month-desc 
 +   (N_ "First day of the current month."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-this-month-string 
 +   (N_ "End of this month"))
 +  (gnc:reldate-string-db 
 +   'store 'end-this-month-desc 
 +   (N_ "Last day of the current month."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-prev-month-string 
 +   (N_ "Start of previous month"))
 +  (gnc:reldate-string-db 
 +   'store 'start-prev-month-desc
 +   (N_ "First day of the previous month."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-prev-month-string 
 +   (N_ "End of previous month"))
 +  (gnc:reldate-string-db 
 +   'store 'end-prev-month-desc
 +   (N_ "Last day of previous month."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-next-month-string 
 +   (N_ "Start of next month"))
 +  (gnc:reldate-string-db 
 +   'store 'start-next-month-desc
 +   (N_ "First day of the next month."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-next-month-string 
 +   (N_ "End of next month"))
 +  (gnc:reldate-string-db 
 +   'store 'end-next-month-desc
 +   (N_ "Last day of next month."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-current-quarter-string 
 +   (N_ "Start of current quarter"))
 +  (gnc:reldate-string-db 
 +   'store 'start-current-quarter-desc
 +   (N_ "First day of the current quarterly accounting period."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-current-quarter-string 
 +   (N_ "End of current quarter"))
 +  (gnc:reldate-string-db 
 +   'store 'end-current-quarter-desc
 +   (N_ "Last day of the current quarterly accounting period."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-prev-quarter-string 
 +   (N_ "Start of previous quarter"))
 +  (gnc:reldate-string-db 
 +   'store 'start-prev-quarter-desc
 +   (N_ "First day of the previous quarterly accounting period."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-prev-quarter-string 
 +   (N_ "End of previous quarter"))
 +  (gnc:reldate-string-db 
 +   'store 'end-prev-quarter-desc 
 +   (N_ "Last day of previous quarterly accounting period."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'start-next-quarter-string 
 +   (N_ "Start of next quarter"))
 +  (gnc:reldate-string-db 
 +   'store 'start-next-quarter-desc
 +   (N_ "First day of the next quarterly accounting period."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'end-next-quarter-string 
 +   (N_ "End of next quarter"))
 +  (gnc:reldate-string-db 
 +   'store 'end-next-quarter-desc 
 +   (N_ "Last day of next quarterly accounting period."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'today-string 
 +   (N_ "Today"))
 +  (gnc:reldate-string-db 
 +   'store 'today-desc (N_ "The current date."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'one-month-ago-string 
 +   (N_ "One Month Ago"))
 +  (gnc:reldate-string-db 
 +   'store 'one-month-ago-desc (N_ "One Month Ago."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'one-week-ago-string 
 +   (N_ "One Week Ago"))
 +  (gnc:reldate-string-db 
 +   'store 'one-week-ago-desc (N_ "One Week Ago."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'three-months-ago-string 
 +   (N_ "Three Months Ago"))
 +  (gnc:reldate-string-db 
 +   'store 'three-months-ago-desc (N_ "Three Months Ago."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'six-months-ago-string 
 +   (N_ "Six Months Ago"))
 +  (gnc:reldate-string-db 
 +   'store 'six-months-ago-desc (N_ "Six Months Ago."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'one-year-ago-string (N_ "One Year Ago"))
 +  (gnc:reldate-string-db 
 +   'store 'one-year-ago-desc (N_ "One Year Ago.")) 
 +
 +  (gnc:reldate-string-db 
 +   'store 'one-month-ahead-string 
 +   (N_ "One Month Ahead"))
 +  (gnc:reldate-string-db 
 +   'store 'one-month-ahead-desc (N_ "One Month Ahead."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'one-week-ahead-string 
 +   (N_ "One Week Ahead"))
 +  (gnc:reldate-string-db 
 +   'store 'one-week-ahead-desc (N_ "One Week Ahead."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'three-months-ahead-string 
 +   (N_ "Three Months Ahead"))
 +  (gnc:reldate-string-db 
 +   'store 'three-months-ahead-desc (N_ "Three Months Ahead."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'six-months-ahead-string 
 +   (N_ "Six Months Ahead"))
 +  (gnc:reldate-string-db 
 +   'store 'six-months-ahead-desc (N_ "Six Months Ahead."))
 +
 +  (gnc:reldate-string-db 
 +   'store 'one-year-ahead-string (N_ "One Year Ahead"))
 +  (gnc:reldate-string-db 
 +   'store 'one-year-ahead-desc (N_ "One Year Ahead.")) 
 +
 +  (set! gnc:relative-date-values 
 +	(list 
 +	 (vector 'start-cal-year 
 +		 (gnc:reldate-string-db 'lookup 'start-cal-year-string)
 +		 (gnc:reldate-string-db 'lookup 'start-cal-year-desc)
 +		 gnc:get-start-cal-year)
 +	 (vector 'end-cal-year 
 +		 (gnc:reldate-string-db 'lookup 'end-cal-year-string)
 +		 (gnc:reldate-string-db 'lookup 'end-cal-year-desc)
 +		 gnc:get-end-cal-year)
 +	 (vector 'start-prev-year
 +		 (gnc:reldate-string-db 'lookup 'start-prev-year-string)
 +		 (gnc:reldate-string-db 'lookup 'start-prev-year-desc)
 +		 gnc:get-start-prev-year)
 +	 (vector 'start-next-year
 +		 (gnc:reldate-string-db 'lookup 'start-next-year-string)
 +		 (gnc:reldate-string-db 'lookup 'start-next-year-desc)
 +		 gnc:get-start-next-year)
 +	 (vector 'end-prev-year
 +		 (gnc:reldate-string-db 'lookup 'end-prev-year-string)
 +		 (gnc:reldate-string-db 'lookup 'end-prev-year-desc)
 +		 gnc:get-end-prev-year)
 +	 (vector 'end-next-year
 +		 (gnc:reldate-string-db 'lookup 'end-next-year-string)
 +		 (gnc:reldate-string-db 'lookup 'end-next-year-desc)
 +		 gnc:get-end-next-year)
 +	 (vector 'start-accounting-period
 +		 (gnc:reldate-string-db 'lookup 'start-accounting-period-string)
 +		 (gnc:reldate-string-db 'lookup 'start-accounting-period-desc)
 +		 gnc:get-start-accounting-period)
 +	 (vector 'end-accounting-period
 +		 (gnc:reldate-string-db 'lookup 'end-accounting-period-string)
 +		 (gnc:reldate-string-db 'lookup 'end-accounting-period-desc)
 +		 gnc:get-end-accounting-period)
 +	 (vector 'start-this-month
 +		 (gnc:reldate-string-db 'lookup 'start-this-month-string)
 +		 (gnc:reldate-string-db 'lookup 'start-this-month-desc)
 +		 gnc:get-start-this-month)
 +	 (vector 'end-this-month
 +		 (gnc:reldate-string-db 'lookup 'end-this-month-string)
 +		 (gnc:reldate-string-db 'lookup 'end-this-month-desc)
 +		 gnc:get-end-this-month)
 +	 (vector 'start-prev-month
 +		 (gnc:reldate-string-db 'lookup 'start-prev-month-string)
 +		 (gnc:reldate-string-db 'lookup 'start-prev-month-desc)
 +		 gnc:get-start-prev-month)
 +	 (vector 'end-prev-month
 +		 (gnc:reldate-string-db 'lookup 'end-prev-month-string)
 +		 (gnc:reldate-string-db 'lookup 'end-prev-month-desc)
 +		 gnc:get-end-prev-month)
 +	 (vector 'start-next-month
 +		 (gnc:reldate-string-db 'lookup 'start-next-month-string)
 +		 (gnc:reldate-string-db 'lookup 'start-next-month-desc)
 +		 gnc:get-start-next-month)
 +	 (vector 'end-next-month
 +		 (gnc:reldate-string-db 'lookup 'end-next-month-string)
 +		 (gnc:reldate-string-db 'lookup 'end-next-month-desc)
 +		 gnc:get-end-next-month)
 +	 (vector 'start-current-quarter
 +		 (gnc:reldate-string-db 'lookup 'start-current-quarter-string)
 +		 (gnc:reldate-string-db 'lookup 'start-current-quarter-desc)
 +		 gnc:get-start-current-quarter)
 +	 (vector 'end-current-quarter
 +		 (gnc:reldate-string-db 'lookup 'end-current-quarter-string)
 +		 (gnc:reldate-string-db 'lookup 'end-current-quarter-desc)
 +		 gnc:get-end-current-quarter)
 +	 (vector 'start-prev-quarter
 +		 (gnc:reldate-string-db 'lookup 'start-prev-quarter-string)
 +		 (gnc:reldate-string-db 'lookup 'start-prev-quarter-desc)
 +		 gnc:get-start-prev-quarter)
 +	 (vector 'end-prev-quarter
 +		 (gnc:reldate-string-db 'lookup 'end-prev-quarter-string)
 +		 (gnc:reldate-string-db 'lookup 'end-prev-quarter-desc)
 +		 gnc:get-end-prev-quarter)
 +	 (vector 'start-next-quarter
 +		 (gnc:reldate-string-db 'lookup 'start-next-quarter-string)
 +		 (gnc:reldate-string-db 'lookup 'start-next-quarter-desc)
 +		 gnc:get-start-next-quarter)
 +	 (vector 'end-next-quarter
 +		 (gnc:reldate-string-db 'lookup 'end-next-quarter-string)
 +		 (gnc:reldate-string-db 'lookup 'end-next-quarter-desc)
 +		 gnc:get-end-next-quarter)
 +	 (vector 'today
 +		 (gnc:reldate-string-db 'lookup 'today-string)
 +		 (gnc:reldate-string-db 'lookup 'today-desc)
 +		 gnc:get-today)
 +	 (vector 'one-month-ago
 +		 (gnc:reldate-string-db 'lookup 'one-month-ago-string)
 +		 (gnc:reldate-string-db 'lookup 'one-month-ago-desc)
 +		 gnc:get-one-month-ago)
 +	 (vector 'three-months-ago
 +		 (gnc:reldate-string-db 'lookup 'three-months-ago-string)
 +		 (gnc:reldate-string-db 'lookup 'three-months-ago-desc)
 +		 gnc:get-three-months-ago)
 +	 (vector 'six-months-ago
 +		 (gnc:reldate-string-db 'lookup 'six-months-ago-string)
 +		 (gnc:reldate-string-db 'lookup 'six-months-ago-desc)
 +		 gnc:get-three-months-ago)
 +	 (vector 'one-year-ago
 +		 (gnc:reldate-string-db 'lookup 'one-year-ago-string)
 +		 (gnc:reldate-string-db 'lookup 'one-year-ago-desc)
 +		 gnc:get-one-year-ago)
 +	 (vector 'one-month-ahead
 +		 (gnc:reldate-string-db 'lookup 'one-month-ahead-string)
 +		 (gnc:reldate-string-db 'lookup 'one-month-ahead-desc)
 +		 gnc:get-one-month-ahead)
 +	 (vector 'three-months-ahead
 +		 (gnc:reldate-string-db 'lookup 'three-months-ahead-string)
 +		 (gnc:reldate-string-db 'lookup 'three-months-ahead-desc)
 +		 gnc:get-three-months-ahead)
 +	 (vector 'six-months-ahead
 +		 (gnc:reldate-string-db 'lookup 'six-months-ahead-string)
 +		 (gnc:reldate-string-db 'lookup 'six-months-ahead-desc)
 +		 gnc:get-three-months-ahead)
 +	 (vector 'one-year-ahead
 +		 (gnc:reldate-string-db 'lookup 'one-year-ahead-string)
 +		 (gnc:reldate-string-db 'lookup 'one-year-ahead-desc)
 +		 gnc:get-one-year-ahead)))
 +
 +
 +  (gnc:make-reldate-hash gnc:relative-date-hash gnc:relative-date-values)
 +  (set! gnc:reldate-list
 +	(map (lambda (x) (vector-ref x 0)) gnc:relative-date-values)))

commit a0f49d8b17dede2c6f4835b700e18badf4acb025
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Mar 25 09:17:17 2018 -0700

    Revert "Load the environment file when initializing the python bindings."
    
    It's unnecessary, the swigged gnucash_core init function already does it.
    This reverts commit 7b6854c1631e27e634a6b3d4e22ee6a8389836dd.

diff --git a/bindings/python/__init__.py b/bindings/python/__init__.py
index 4082cfe..1c87473 100644
--- a/bindings/python/__init__.py
+++ b/bindings/python/__init__.py
@@ -4,7 +4,6 @@
 # instead of
 # >>> from gnucash.gnucash_core import thingy
 from gnucash.gnucash_core import *
-gnc_environment_setup()
 ##  @file
 #   @brief helper file for the importing of gnucash
 #   @author Mark Jenkins, ParIT Worker Co-operative <mark at parit.ca>

commit 9cd22ee66766f0f188becf6489cd1c87446d5262
Merge: 2b6047f a670238
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Mar 25 09:02:43 2018 -0700

    Merge Chris Lam's Fix-794030 into maint


commit a670238f80a92552f7b4771be424f7fc382df69b
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Mar 25 15:47:35 2018 +0800

    Bug 794030 - relative date functions compute wrong day of month
    
    Convert > to < and rename month-length to month-days for consistency.

diff --git a/src/app-utils/date-utilities.scm b/src/app-utils/date-utilities.scm
index 72eb0f3..5ecd844 100644
--- a/src/app-utils/date-utilities.scm
+++ b/src/app-utils/date-utilities.scm
@@ -718,10 +718,10 @@
 	  (set-tm:mon now 11)
 	  (set-tm:year now (- (tm:year now) 1)))
 	(set-tm:mon now (- (tm:mon now) 1)))
-    (let ((month-length (gnc:days-in-month (+ (tm:mon now) 1)
-                                           (+ (tm:year now) 1900))))
-      (if (> month-length (tm:mday now))
-	  (set-tm:mday now month-length))
+    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
+                                         (+ (tm:year now) 1900))))
+      (if (< month-days (tm:mday now))
+	  (set-tm:mday now month-days))
       (set-tm:isdst now -1)
       (gnc:date->timepair now))))
 
@@ -734,7 +734,7 @@
     (set:tm-mon now (- (tm:mon now) 3))
     (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
                                          (+ (tm:year now) 1900))))
-      (if (> month-days (tm:mday now))
+      (if (< month-days (tm:mday now))
 	  (set-tm:mday now month-days))
       (set-tm:isdst now -1)
       (gnc:date->timepair now))))
@@ -748,7 +748,7 @@
     (set:tm-mon now (- (tm:mon now) 6))
     (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
                                          (+ (tm:year now) 1900))))
-      (if (> month-days (tm:mday now))
+      (if (< month-days (tm:mday now))
 	  (set-tm:mday now month-days))
       (set-tm:isdst now -1)
       (gnc:date->timepair now))))
@@ -757,8 +757,8 @@
   (let ((now (gnc-localtime (current-time))))
     (set:tm-year now (- (tm:year now) 1))
     (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
-                                          (+ (tm:year now) 1900))))
-      (if (> month-days (tm:mday now))
+                                         (+ (tm:year now) 1900))))
+      (if (< month-days (tm:mday now))
 	  (set-tm:mday now month-days))
       (set-tm:isdst now -1)
       (gnc:date->timepair now))))
@@ -770,10 +770,10 @@
 	  (set-tm:mon now 0)
 	  (set-tm:year now (+ (tm:year now) 1)))
 	(set-tm:mon now (+ (tm:mon now) 1)))
-    (let ((month-length (gnc:days-in-month (+ (tm:mon now) 1)
-                                           (+ (tm:year now) 1900))))
-      (if (> month-length (tm:mday now))
-	  (set-tm:mday now month-length))
+    (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
+                                         (+ (tm:year now) 1900))))
+      (if (< month-days (tm:mday now))
+	  (set-tm:mday now month-days))
       (set-tm:isdst now -1)
       (gnc:date->timepair now))))
 
@@ -783,10 +783,10 @@
 	(begin
 	  (set:tm-mon now (- (tm:mon now) 9))
 	  (set:tm-year now  (+ (tm:year now) 1))
-       (set:tm-mon now (+ (tm:mon now) 3))))
+          (set:tm-mon now (+ (tm:mon now) 3))))
     (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
                                          (+ (tm:year now) 1900))))
-      (if (> month-days (tm:mday now))
+      (if (< month-days (tm:mday now))
 	  (set-tm:mday now month-days))
       (set-tm:isdst now -1)
       (gnc:date->timepair now))))
@@ -797,10 +797,10 @@
 	(begin
 	  (set:tm-mon now (- (tm:mon now) 6))
 	  (set:tm-year now  (+ (tm:year now) 1))
-       (set:tm-mon now (+ (tm:mon now) 6))))
+          (set:tm-mon now (+ (tm:mon now) 6))))
     (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
                                          (+ (tm:year now) 1900))))
-      (if (> month-days (tm:mday now))
+      (if (< month-days (tm:mday now))
 	  (set-tm:mday now month-days))
       (set-tm:isdst now -1)
       (gnc:date->timepair now))))
@@ -809,8 +809,8 @@
   (let ((now (gnc-localtime (current-time))))
     (set:tm-year now (+ (tm:year now) 1))
     (let ((month-days (gnc:days-in-month (+ (tm:mon now) 1)
-                                          (+ (tm:year now) 1900))))
-      (if (> month-days (tm:mday now))
+                                         (+ (tm:year now) 1900))))
+      (if (< month-days (tm:mday now))
 	  (set-tm:mday now month-days))
       (set-tm:isdst now -1)
       (gnc:date->timepair now))))

commit 8081e78ee39a33bfb97bc8f458f2ad4732db996a
Merge: 7b6854c 2571baf
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Mar 24 17:50:38 2018 -0700

    Merge Bob Fewell's Bug 794360 PR into unstable.


commit 7b6854c1631e27e634a6b3d4e22ee6a8389836dd
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Mar 24 17:49:01 2018 -0700

    Load the environment file when initializing the python bindings.

diff --git a/bindings/python/__init__.py b/bindings/python/__init__.py
index 1c87473..4082cfe 100644
--- a/bindings/python/__init__.py
+++ b/bindings/python/__init__.py
@@ -4,6 +4,7 @@
 # instead of
 # >>> from gnucash.gnucash_core import thingy
 from gnucash.gnucash_core import *
+gnc_environment_setup()
 ##  @file
 #   @brief helper file for the importing of gnucash
 #   @author Mark Jenkins, ParIT Worker Co-operative <mark at parit.ca>

commit 148c02d231f3c1e545e62e23616a6f32018c5208
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Mar 22 15:29:08 2018 -0700

    [python bindings] Add required posted dates to the transactions.

diff --git a/bindings/python/example_scripts/simple_test.py b/bindings/python/example_scripts/simple_test.py
index 7156fd9..2741641 100644
--- a/bindings/python/example_scripts/simple_test.py
+++ b/bindings/python/example_scripts/simple_test.py
@@ -61,9 +61,11 @@ split3.SetAccount(savings_acct)
 split3.SetParent(trans2)
 
 trans1.SetCurrency(cad)
+trans1.SetDate(14, 3, 2006)
 trans1.SetDescription("Groceries")
 
 trans2.SetCurrency(cad)
+trans2.SetDate(7, 11, 1995)
 trans2.SetDescription("Opening Savings Balance")
 
 split2 = Split(book)

commit bea89a50ac0656c229c0ec6e54053fc08563397c
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Mar 22 15:08:22 2018 -0700

    More python 3 fixups.

diff --git a/bindings/python/example_scripts/account_analysis.py b/bindings/python/example_scripts/account_analysis.py
index dd7fc4a..87e1dfe 100644
--- a/bindings/python/example_scripts/account_analysis.py
+++ b/bindings/python/example_scripts/account_analysis.py
@@ -152,13 +152,13 @@ def account_from_path(top_account, account_path, original_path=None):
 def main():
 
     if len(argv) < 10:
-        print 'not enough parameters'
-        print 'usage: account_analysis.py {book url} {start year} {start month, numeric} {period type: monthly, quarterly, or yearly} {number of periods to show, from start year and month} {whether to show debits: debits-show for true, all other values false} {whether to show credits: credits-show for true, all other values false} {space separated account path, as many nested levels as desired} '
-        print 'examples:\n'
-        print "The following example analyzes 12 months of 'Assets:Test Account' from /home/username/test.gnucash, starting in January of 2010, and shows both credits and debits"
-        print "gnucash-env python account_analysis.py '/home/username/test.gnucash' 2010 1 monthly 12 debits-show credits-show Assets 'Test Account'\n"
-        print "The following example analyzes 2 quarters of 'Liabilities:First Level:Second Level' from /home/username/test.gnucash, starting March 2011, and shows credits but not debits"
-        print "gnucash-env python account_analysis.py '/home/username/test.gnucash' 2011 3 quarterly 2 debits-noshow credits-show Liabilities 'First Level' 'Second Level"
+        print('not enough parameters')
+        print('usage: account_analysis.py {book url} {start year} {start month, numeric} {period type: monthly, quarterly, or yearly} {number of periods to show, from start year and month} {whether to show debits: debits-show for true, all other values false} {whether to show credits: credits-show for true, all other values false} {space separated account path, as many nested levels as desired} ')
+        print('examples:\n')
+        print("The following example analyzes 12 months of 'Assets:Test Account' from /home/username/test.gnucash, starting in January of 2010, and shows both credits and debits")
+        print("gnucash-env python account_analysis.py '/home/username/test.gnucash' 2010 1 monthly 12 debits-show credits-show Assets 'Test Account'\n")
+        print("The following example analyzes 2 quarters of 'Liabilities:First Level:Second Level' from /home/username/test.gnucash, starting March 2011, and shows credits but not debits")
+        print("gnucash-env python account_analysis.py '/home/username/test.gnucash' 2011 3 quarterly 2 debits-noshow credits-show Liabilities 'First Level' 'Second Level")
         return
 
     try:
diff --git a/bindings/python/example_scripts/gncinvoice_jinja.py b/bindings/python/example_scripts/gncinvoice_jinja.py
index 6e4eaff..ec93ed0 100644
--- a/bindings/python/example_scripts/gncinvoice_jinja.py
+++ b/bindings/python/example_scripts/gncinvoice_jinja.py
@@ -39,8 +39,8 @@ try:
     import jinja2
     from gncinvoicefkt import *
 except ImportError as import_error:
-    print "Problem importing modules."
-    print import_error
+    print("Problem importing modules.")
+    print(import_error)
     sys.exit(2)
 
 class Usage(Exception):
@@ -68,26 +68,26 @@ def main(argv=None):
 
         for opt in opts:
             if opt[0] in ["-f"]:
-                print "ignoring lock"
+                print("ignoring lock")
                 ignore_lock = True
             if opt[0] in ["-h","--help"]:
                 raise Usage("Help:")
             if opt[0] in ["-I"]:
                 invoice_id = opt[1]
-                print "using invoice ID '" + str(invoice_id) + "'."
+                print("using invoice ID '" + str(invoice_id) + "'.")
             if opt[0] in ["-o"]:
                 filename_output = opt[1]
-                print "using output file", filename_output
+                print("using output file", filename_output)
             if opt[0] in ["-t"]:
                 filename_template = opt[1]
-                print "using template file", filename_template
+                print("using template file", filename_template)
             if opt[0] in ["-l"]:
                 list_invoices = True
-                print "listing invoices"
+                print("listing invoices")
 
         # Check for correct input
         if len(args)>1:
-            print "opts:",opts,"args:",args
+            print("opts:",opts,"args:",args)
             raise Usage("Only one input possible !")
         if len(args)==0:
             raise Usage("No input given !")
@@ -103,41 +103,41 @@ def main(argv=None):
         if not filename_output:
             if filename_template:
                 filename_output = filename_template + ".out"
-                print "no output filename given, will be:", filename_output
+                print("no output filename given, will be:", filename_output)
 
     except Usage, err:
         if err.msg == "Help:":
             retcode=0
         else:
-            print >>sys.stderr, "Error:",err.msg
-            print >>sys.stderr, "for help use --help"
+            print(>>sys.stderr, "Error:",err.msg)
+            print(>>sys.stderr, "for help use --help")
             retcode=2
 
-        print
-        print "Usage:"
-        print
-        print "Invoke with",prog_name,"gnucash_url."
-        print "where input is"
-        print "   filename"
-        print "or file://filename"
-        print "or mysql://user:password@host/databasename"
-        print
-        print "-f             force open = ignore lock"
-        print "-l             list all invoices"
-        print "-h or --help   for this help"
-        print "-I ID          use invoice ID"
-        print "-t filename    use filename as template file"
-        print "-o filename    use filename as output file"
+        print()
+        print("Usage:")
+        print()
+        print("Invoke with",prog_name,"gnucash_url.")
+        print("where input is")
+        print("   filename")
+        print("or file://filename")
+        print("or mysql://user:password@host/databasename")
+        print()
+        print("-f             force open = ignore lock")
+        print("-l             list all invoices")
+        print("-h or --help   for this help")
+        print("-I ID          use invoice ID")
+        print("-t filename    use filename as template file")
+        print("-o filename    use filename as output file")
 
         return retcode
 
     # Try to open the given input
     try:
-        print "Opening", input_url, "."
+        print("Opening", input_url, ".")
         session = gnucash.Session(input_url, ignore_lock=ignore_lock)
     except Exception as exception:
-        print "Problem opening input."
-        print exception
+        print("Problem opening input.")
+        print(exception)
         return 2
 
     book = session.book
@@ -149,22 +149,22 @@ def main(argv=None):
 
     if list_invoices:
        for number,invoice in enumerate(invoice_list):
-           print str(number)+")"
-           print invoice
+           print(str(number)+")")
+           print(invoice)
 
     if not (no_output):
 
         if invoice_id:
             invoice = book.InvoiceLookupByID(invoice_id)
             if not invoice:
-                print "ID not found."
+                print("ID not found.")
                 return 2
 
         if invoice_number:
             invoice = invoice_list[invoice_number]
 
-        print "Using the following invoice:"
-        print invoice
+        print("Using the following invoice:")
+        print(invoice)
 
         loader = jinja2.FileSystemLoader('.')
         env = jinja2.Environment(loader=loader)
@@ -174,7 +174,7 @@ def main(argv=None):
         #IPython.embed()
         output = template.render(invoice=invoice, locale=locale)
 
-        print "Writing output", filename_output, "."
+        print("Writing output", filename_output, ".")
         with open(filename_output, 'w') as f:
             f.write(output.encode('utf-8'))
 
diff --git a/bindings/python/example_scripts/gncinvoicefkt.py b/bindings/python/example_scripts/gncinvoicefkt.py
index 9e0ffa0..ef778b4 100644
--- a/bindings/python/example_scripts/gncinvoicefkt.py
+++ b/bindings/python/example_scripts/gncinvoicefkt.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF-8 -*-
+# -*- coding: utf-8 -*-
 
 ##@file
 # @brief some help for working with invoices, used in \ref py_invoice_export
@@ -22,8 +22,8 @@ try:
             GNC_DISC_PRETAX
     import str_methods
 except ImportError as import_error:
-    print "Problem importing modules."
-    print import_error
+    print("Problem importing modules.")
+    print(import_error)
     sys.exit(2)
 
 def get_all_lots(account):
diff --git a/bindings/python/example_scripts/latex_invoices.py b/bindings/python/example_scripts/latex_invoices.py
index 8b738fa..4c6c1d4 100644
--- a/bindings/python/example_scripts/latex_invoices.py
+++ b/bindings/python/example_scripts/latex_invoices.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF-8 -*-
+# -*- coding: utf-8 -*-
 
 ##@file
 # @brief Exports an invoice to lco-file for use with LaTeX, see \ref py_invoice_export
@@ -66,8 +66,8 @@ try:
             GNC_DISC_PRETAX
     import locale
 except ImportError as import_error:
-    print "Problem importing modules."
-    print import_error
+    print("Problem importing modules.")
+    print(import_error)
     sys.exit(2)
 
 class Usage(Exception):
@@ -157,7 +157,7 @@ def invoice_to_lco(invoice):
       line_str += uprice
       line_str += u"}"
 
-      #print line_str
+      #print(line_str)
       ent_str += line_str
 
   lco_out += write_variable("entries",ent_str)
@@ -184,25 +184,25 @@ def main(argv=None):
 
         for opt in opts:
             if opt[0] in ["-f"]:
-                print "ignoring lock"
+                print("ignoring lock")
                 ignore_lock = True
             if opt[0] in ["-h","--help"]:
                 raise Usage("Help:")
             if opt[0] in ["-i"]:
-                print "Using ipshell"
+                print("Using ipshell")
                 with_ipshell = True
             if opt[0] in ["-l"]:
-                print "listing all invoices"
+                print("listing all invoices")
                 list_invoices=True
             if opt[0] in ["-n"]:
                 invoice_number = int(opt[1])
-                print "using invoice number", invoice_number
+                print("using invoice number", invoice_number)
                 no_latex_output = False
             if opt[0] in ["-o"]:
                 output_file_name = opt[1]
-                print "using output file", output_file_name
+                print("using output file", output_file_name)
         if len(args)>1:
-            print "opts:",opts,"args:",args
+            print("opts:",opts,"args:",args)
             raise Usage("Only one input can be accepted !")
         if len(args)==0:
             raise Usage("No input given !")
@@ -211,26 +211,26 @@ def main(argv=None):
         if err.msg == "Help:":
             retcode=0
         else:
-            print >>sys.stderr, "Error:",err.msg
-            print >>sys.stderr, "for help use --help"
+            print(>>sys.stderr, "Error:",err.msg)
+            print(>>sys.stderr, "for help use --help")
             retcode=2
 
-        print "Generate a LaTeX invoice or print out all invoices."
-        print
-        print "Usage:"
-        print
-        print "Invoke with",prog_name,"input."
-        print "where input is"
-        print "   filename"
-        print "or file://filename"
-        print "or mysql://user:password@host/databasename"
-        print
-        print "-f             force open = ignore lock"
-        print "-h or --help   for this help"
-        print "-i             for ipython shell"
-        print "-l             list all invoices"
-        print "-n number      use invoice number (no. from previous run with -l)"
-        print "-o name        use name as outputfile. default: data.lco"
+        print("Generate a LaTeX invoice or print out all invoices.")
+        print()
+        print("Usage:")
+        print()
+        print("Invoke with",prog_name,"input.")
+        print("where input is")
+        print("   filename")
+        print("or file://filename")
+        print("or mysql://user:password@host/databasename")
+        print()
+        print("-f             force open = ignore lock")
+        print("-h or --help   for this help")
+        print("-i             for ipython shell")
+        print("-l             list all invoices")
+        print("-n number      use invoice number (no. from previous run with -l)")
+        print("-o name        use name as outputfile. default: data.lco")
 
         return retcode
 
@@ -238,8 +238,8 @@ def main(argv=None):
     try:
         session = gnucash.Session(input_url,ignore_lock=ignore_lock)
     except Exception as exception:
-        print "Problem opening input."
-        print exception
+        print("Problem opening input.")
+        print(exception)
         return 2
 
     book = session.book
@@ -251,18 +251,18 @@ def main(argv=None):
 
     if list_invoices:
         for number,invoice in enumerate(invoice_list):
-            print str(number)+")"
-            print invoice
+            print(str(number)+")")
+            print(invoice)
 
     if not (no_latex_output):
 
         if invoice_number == None:
-            print "Using the first invoice:"
+            print("Using the first invoice:")
             invoice_number=0
 
         invoice=invoice_list[invoice_number]
-        print "Using the following invoice:"
-        print invoice
+        print("Using the following invoice:")
+        print(invoice)
 
         lco_str=invoice_to_lco(invoice)
 
diff --git a/bindings/python/example_scripts/new_book_with_opening_balances.py b/bindings/python/example_scripts/new_book_with_opening_balances.py
index 08a08de..0ee02c4 100644
--- a/bindings/python/example_scripts/new_book_with_opening_balances.py
+++ b/bindings/python/example_scripts/new_book_with_opening_balances.py
@@ -290,11 +290,11 @@ def create_opening_balance_transaction(commodtable, namespace, mnemonic,
 def main():
 
     if len(argv) < 3:
-        print 'not enough parameters'
-        print 'usage: new_book_with_opening_balances.py {source_book_url} {destination_book_url}'
-        print 'examples:'
-        print "gnucash-env python new_book_with_opening_balances.py '/home/username/test.gnucash' 'sqlite3:///home/username/new_test.gnucash'"
-        print "gnucash-env python new_book_with_opening_balances.py '/home/username/test.gnucash' 'xml:///crypthome/username/finances/new_test.gnucash'"
+        print('not enough parameters')
+        print('usage: new_book_with_opening_balances.py {source_book_url} {destination_book_url}')
+        print('examples:')
+        print("gnucash-env python new_book_with_opening_balances.py '/home/username/test.gnucash' 'sqlite3:///home/username/new_test.gnucash'")
+        print("gnucash-env python new_book_with_opening_balances.py '/home/username/test.gnucash' 'xml:///crypthome/username/finances/new_test.gnucash'")
         return
 
     #have everything in a try block to unable us to release our hold on stuff to the extent possible
diff --git a/bindings/python/example_scripts/priceDB_test.py b/bindings/python/example_scripts/priceDB_test.py
index fcd30e2..41f42fb 100644
--- a/bindings/python/example_scripts/priceDB_test.py
+++ b/bindings/python/example_scripts/priceDB_test.py
@@ -41,11 +41,11 @@ for pr in pl:
    time = pr.get_time()
    v=pr.get_value()
    price = float(v.num)/v.denom
-   print time, source, price
+   print(time, source, price)
 
 if len(pl) > 0:
    v0 = pl[0].get_value()
-   print arm.get_fullname(), float(v0.num) / float(v0.denom )
+   print(arm.get_fullname(), float(v0.num) / float(v0.denom ))
 
 session.end()
 session.destroy()
diff --git a/bindings/python/example_scripts/price_database_example.py b/bindings/python/example_scripts/price_database_example.py
index 86db033..b9b10e8 100755
--- a/bindings/python/example_scripts/price_database_example.py
+++ b/bindings/python/example_scripts/price_database_example.py
@@ -57,12 +57,12 @@ for namespace in namespaces:
 
   if len(commodities) == 0 :
 
-    print "No commodity in namespace "+namespace_name+"."
+    print("No commodity in namespace "+namespace_name+".")
   else:
     if commodity_fullname:
-      print "Searching commodity '"+commodity_fullname+"' in namespace "+namespace_name
+      print("Searching commodity '"+commodity_fullname+"' in namespace "+namespace_name)
     else:
-      print "Commoditys in namespace "+namespace_name+":"
+      print("Commoditys in namespace "+namespace_name+":")
 
 
     for i, c in enumerate(commodities):
@@ -70,12 +70,12 @@ for namespace in namespaces:
       c_fullname = c.get_fullname()
 
       if not(commodity_fullname) or (commodity_fullname == c_fullname):
-        print "["+str(i)+"] Full Name :", c.get_fullname()
+        print("["+str(i)+"] Full Name :", c.get_fullname())
         if show_prices:
           pl = pdb.get_prices(c,cur)
 
           if len(pl) > 0 :
-            print "{0} {1:20}{2:>10} {3}".format("Time      ","Source","Price","Currency")
+            print("{0} {1:20}{2:>10} {3}".format("Time      ","Source","Price","Currency"))
             for pr in pl:
 
                source = pr.get_source()
@@ -83,7 +83,7 @@ for namespace in namespaces:
                v=pr.get_value()
                price = float(v.num)/v.denom
 
-               print "{0} {1:20}{2:10.4f} {3}".format(time,source,price,cur_name)
+               print("{0} {1:20}{2:10.4f} {3}".format(time,source,price,cur_name))
                # I didn't find out how to format the time option...
 
 session.end()
diff --git a/bindings/python/example_scripts/quotes_historic.py b/bindings/python/example_scripts/quotes_historic.py
index da70cc7..964c70f 100644
--- a/bindings/python/example_scripts/quotes_historic.py
+++ b/bindings/python/example_scripts/quotes_historic.py
@@ -60,14 +60,14 @@ stock = ac.GetCommodity()
 # Add the prices
 pdb = book.get_price_db()
 if len(ac.GetSplitList())<1:
-  print 'Need at least one Split to get currency info ... '
+  print('Need at least one Split to get currency info ... ')
   raise SystemExit
 cur = ac.GetSplitList()[0].GetParent().GetCurrency()
 
 # Get stock data
 pl = pdb.get_prices(stock,cur)
 if len(pl)<1:
-  print 'Need at least one database entry to clone ...'
+  print('Need at least one database entry to clone ...')
   raise SystemExit
 
 pl0 = pl[0]
@@ -77,7 +77,7 @@ for i in range(1,len(pl)):
 for i in range(0,len(stock_date)):
   p_new = pl0.clone(book)
   p_new = gnucash.GncPrice(instance=p_new)
-  print 'Adding',i,stock_date[i],stock_price[i]
+  print('Adding',i,stock_date[i],stock_price[i])
   p_new.set_time(stock_date[i])
   v = p_new.get_value()
   v.num = int(Fraction.from_float(stock_price[i]).limit_denominator(100000).numerator)
diff --git a/bindings/python/example_scripts/rest-api/gnucash_rest.py b/bindings/python/example_scripts/rest-api/gnucash_rest.py
index f6a4dc9..5444b98 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_rest.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_rest.py
@@ -835,7 +835,7 @@ def getAccountsFlat(book):
     for n, account in enumerate(flat_accounts):
         if account['type_id'] in type_ids:
             filtered_flat_account.append(account)
-            print account['name'] + ' ' + str(account['type_id'])
+            print(account['name'] + ' ' + str(account['type_id']))
 
     return filtered_flat_account
 
@@ -1846,7 +1846,7 @@ def shutdown():
     session.save()
     session.end()
     session.destroy()
-    print 'Shutdown'
+    print('Shutdown')
 
 class Error(Exception):
     """Base class for exceptions in this module."""
@@ -1858,12 +1858,12 @@ class Error(Exception):
 try:
     options, arguments = getopt.getopt(sys.argv[1:], 'nh:', ['host=', 'new='])
 except getopt.GetoptError as err:
-    print str(err) # will print something like "option -a not recognized"
-    print 'Usage: python-rest.py <connection string>'
+    print(str(err) # will print something like "option -a not recognized")
+    print('Usage: python-rest.py <connection string>')
     sys.exit(2)
 
 if len(arguments) == 0:
-    print 'Usage: python-rest.py <connection string>'
+    print('Usage: python-rest.py <connection string>')
     sys.exit(2)
 
 #set default host for Flask
diff --git a/bindings/python/example_scripts/simple_book.py b/bindings/python/example_scripts/simple_book.py
index bbc3354..4bde608 100644
--- a/bindings/python/example_scripts/simple_book.py
+++ b/bindings/python/example_scripts/simple_book.py
@@ -10,16 +10,16 @@ from gnucash import Session
 # We need to tell GnuCash the data format to create the new file as (xml://)
 uri = "xml:///tmp/simple_book.gnucash"
 
-print "uri:", uri
+print("uri:", uri)
 ses = Session(uri, is_new=True)
 book = ses.get_book()
 
 #Call some methods that produce output to show that Book works
 book.get_root_account().SetDescription("hello, book")
-print "Book is saved:", not book.session_not_saved()
+print("Book is saved:", not book.session_not_saved())
 
-print "saving..."
+print("saving...")
 ses.save()
 
-print "Book is saved:", not book.session_not_saved()
+print("Book is saved:", not book.session_not_saved())
 ses.end()
diff --git a/bindings/python/example_scripts/simple_business_create.py b/bindings/python/example_scripts/simple_business_create.py
index 40a2c3a..75a0022 100644
--- a/bindings/python/example_scripts/simple_business_create.py
+++ b/bindings/python/example_scripts/simple_business_create.py
@@ -62,10 +62,10 @@ from gnucash.gnucash_core_c import \
     GNC_OWNER_CUSTOMER, ACCT_TYPE_LIABILITY
 
 if len(argv) < 2:
-    print 'not enough parameters'
-    print 'usage: simple_business_create.py {new_book_url}'
-    print 'example:'
-    print "gnucash-env python simple_business_create.py sqlite3:///home/blah/blah.gnucash"
+    print('not enough parameters')
+    print('usage: simple_business_create.py {new_book_url}')
+    print('example:')
+    print("gnucash-env python simple_business_create.py sqlite3:///home/blah/blah.gnucash")
     exit()
     
 
diff --git a/bindings/python/example_scripts/test_imbalance_transaction.py b/bindings/python/example_scripts/test_imbalance_transaction.py
index f50dea9..d220728 100644
--- a/bindings/python/example_scripts/test_imbalance_transaction.py
+++ b/bindings/python/example_scripts/test_imbalance_transaction.py
@@ -42,10 +42,10 @@ from gnucash import Session, Transaction, Split, Account, GncNumeric, \
 # and trading accounts disabled
 
 if len(argv) < 2:    
-    print 'not enough parameters'
-    print 'usage: test_imbalance_transaction.py {book_url}'
-    print 'examples:'
-    print "gnucash-env python test_imbalance_transaction.py '/home/username/test.gnucash'"
+    print('not enough parameters')
+    print('usage: test_imbalance_transaction.py {book_url}')
+    print('examples:')
+    print("gnucash-env python test_imbalance_transaction.py '/home/username/test.gnucash'")
     exit()
 
 
@@ -86,12 +86,12 @@ try:
     s2.SetAccount(account2)
     s2.SetValue(GncNumeric(4))
     s2.SetAmount(GncNumeric(4))
-    print 'overall imbalance', a.GetImbalanceValue().to_string()
+    print('overall imbalance', a.GetImbalanceValue().to_string())
 
-    print 'per-currency imbalances'
+    print('per-currency imbalances')
     imbalance_list = a.GetImbalance()
     for (commod, value) in imbalance_list:
-        print value.to_string(), commod.get_mnemonic()
+        print(value.to_string(), commod.get_mnemonic())
 
     a.CommitEdit()
 
diff --git a/gnucash/python/pycons/ishell.py b/gnucash/python/pycons/ishell.py
index aa84467..371f32c 100644
--- a/gnucash/python/pycons/ishell.py
+++ b/gnucash/python/pycons/ishell.py
@@ -125,10 +125,10 @@ class Shell:
 
     def shell(self, cmd,verbose=0,debug=0,header=''):
         stat = 0
-        if verbose or debug: print header+cmd
+        if verbose or debug: print(header+cmd)
         if not debug:
             input, output = os.popen4(cmd)
-            print output.read()
+            print(output.read())
             output.close()
             input.close()
 
diff --git a/gnucash/python/pycons/shell.py b/gnucash/python/pycons/shell.py
index 6569d17..d50043e 100644
--- a/gnucash/python/pycons/shell.py
+++ b/gnucash/python/pycons/shell.py
@@ -153,7 +153,7 @@ class Shell:
                             console.write (buf, 'output')
                             if len(buf) < 256: break
                     # Command output
-                    print `r`
+                    print(`r`)
             except SyntaxError:
                 exec self.command in self.globals
         except:
@@ -166,8 +166,8 @@ class Shell:
                     tb = sys.exc_traceback
                     if tb:
                         tb=tb.tb_next
-                    traceback.print_exception (sys.exc_type, sys.exc_value, tb)
+                    traceback.print(_exception (sys.exc_type, sys.exc_value, tb))
                 except:
                     sys.stderr, console.stderr = console.stderr, sys.stderr
-                    traceback.print_exc()
+                    traceback.print(_exc())
 

commit 2571baff9fde514791ad8f2eb1758ee16ec3499c
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Mar 21 13:05:49 2018 +0000

    Bug 794644 - Deleting prices slow
    
    Detach the price tree model from the price tree view while prices are
    being deleted and then reattach.

diff --git a/gnucash/gnome/dialog-price-edit-db.c b/gnucash/gnome/dialog-price-edit-db.c
index f6d5efb..4fdcc09 100644
--- a/gnucash/gnome/dialog-price-edit-db.c
+++ b/gnucash/gnome/dialog-price-edit-db.c
@@ -387,6 +387,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
 {
     PricesDialog *pdb_dialog = data;
     GtkBuilder *builder;
+    GtkTreeModel *model;
     GtkWidget *date, *label, *box;
     GtkWidget *button;
     GtkTreeSelection *selection;
@@ -459,6 +460,11 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
             PriceRemoveSourceFlags source = PRICE_REMOVE_SOURCE_FQ;
             PriceRemoveKeepOptions keep = PRICE_REMOVE_KEEP_NONE;
 
+            // disconnect the model to the price treeview
+            model = gtk_tree_view_get_model (GTK_TREE_VIEW(pdb_dialog->price_tree));
+            g_object_ref (G_OBJECT(model));
+            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;
@@ -498,6 +504,9 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
                 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);
             }
+            // reconnect the model to the price treeview
+            gtk_tree_view_set_model (GTK_TREE_VIEW(pdb_dialog->price_tree), model);
+            g_object_unref(G_OBJECT(model));
         }
         g_list_free (comm_list);
     }

commit 9135ec45244f193d75b95e894b394a3593297363
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Mar 21 13:04:42 2018 +0000

    Fix a couple of Transient parent warnings

diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index 1cb02f2..ac90943 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -786,7 +786,7 @@ gnc_split_reg_reverse_trans_cb (GtkWidget *w, gpointer data)
 
 
 static gboolean
-is_trans_readonly_and_warn (const Transaction *trans)
+is_trans_readonly_and_warn (GtkWindow *parent, const Transaction *trans)
 {
     GtkWidget *dialog;
     const gchar *reason;
@@ -798,7 +798,7 @@ is_trans_readonly_and_warn (const Transaction *trans)
 
     if (xaccTransIsReadonlyByPostedDate (trans))
     {
-        dialog = gtk_message_dialog_new(NULL,
+        dialog = gtk_message_dialog_new(parent,
                                         0,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_OK,
@@ -814,7 +814,7 @@ is_trans_readonly_and_warn (const Transaction *trans)
     reason = xaccTransGetReadOnly (trans);
     if (reason)
     {
-        dialog = gtk_message_dialog_new(NULL,
+        dialog = gtk_message_dialog_new(parent,
                                         0,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_OK,
@@ -848,7 +848,7 @@ gsr_default_reinit_handler( GNCSplitReg *gsr, gpointer data )
     reg = gnc_ledger_display_get_split_register( gsr->ledger );
 
     trans = gnc_split_register_get_current_trans (reg);
-    if (is_trans_readonly_and_warn(trans))
+    if (is_trans_readonly_and_warn(GTK_WINDOW(gsr->window), trans))
         return;
     dialog = gtk_message_dialog_new(GTK_WINDOW(gsr->window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -1056,7 +1056,7 @@ gsr_default_associate_handler (GNCSplitReg *gsr, gboolean uri_is_file)
     if (cursor_class == CURSOR_CLASS_NONE)
         return;
 
-    if (is_trans_readonly_and_warn (trans))
+    if (is_trans_readonly_and_warn (GTK_WINDOW(gsr->window), trans))
         return;
 
     // get the existing uri
@@ -1183,7 +1183,7 @@ gsr_default_delete_handler( GNCSplitReg *gsr, gpointer data )
     if (cursor_class == CURSOR_CLASS_NONE)
         return;
 
-    if (is_trans_readonly_and_warn(trans))
+    if (is_trans_readonly_and_warn(GTK_WINDOW(gsr->window), trans))
         return;
 
     /* On a split cursor, just delete the one split. */
diff --git a/gnucash/register/ledger-core/split-register-model.c b/gnucash/register/ledger-core/split-register-model.c
index 48d7a0b..bd13295 100644
--- a/gnucash/register/ledger-core/split-register-model.c
+++ b/gnucash/register/ledger-core/split-register-model.c
@@ -1957,7 +1957,7 @@ gnc_split_register_get_security_io_flags (VirtualLocation virt_loc,
 }
 
 static gboolean
-xaccTransWarnReadOnly (const Transaction *trans)
+xaccTransWarnReadOnly (GtkWidget *parent, const Transaction *trans)
 {
     GtkWidget *dialog;
     const gchar *reason;
@@ -1970,7 +1970,7 @@ xaccTransWarnReadOnly (const Transaction *trans)
     reason = xaccTransGetReadOnly (trans);
     if (reason)
     {
-        dialog = gtk_message_dialog_new(NULL,
+        dialog = gtk_message_dialog_new(GTK_WINDOW(parent),
                                         0,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_OK,
@@ -2007,7 +2007,7 @@ gnc_split_register_confirm (VirtualLocation virt_loc, gpointer user_data)
         return TRUE;
 
     trans = xaccSplitGetParent (split);
-    if (xaccTransWarnReadOnly(trans))
+    if (xaccTransWarnReadOnly(gnc_split_register_get_parent(reg), trans))
         return FALSE;
 
     if (!xaccTransHasReconciledSplits (trans))

commit f1dd8cfaf13395e8fe44768211a76a98fe358e1f
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Mar 21 12:28:34 2018 +0000

    Component not found error when accounts are deleted
    
    When accounts are deleted that have an open register window a component
    not found error is triggered. After the account is destroyed, a call to
    'gnc_resume_gui_refresh' calls 'gnc_gui_refresh_internal' and this then
    calls 'find_component_ids_by_class' which is used in order resulting in
    'register-single' being unregistered before 'GncPluginPageRegister' and
    hence 'ld' being freed but the register not knowing this. Reversing the
    list fixes this.

diff --git a/gnucash/register/ledger-core/gnc-ledger-display.c b/gnucash/register/ledger-core/gnc-ledger-display.c
index ea390ee..c84c1f7 100644
--- a/gnucash/register/ledger-core/gnc-ledger-display.c
+++ b/gnucash/register/ledger-core/gnc-ledger-display.c
@@ -594,6 +594,7 @@ close_handler (gpointer user_data)
         return;
 
     gnc_unregister_gui_component (ld->component_id);
+    ld->component_id = NO_COMPONENT;
 
     if (ld->destroy)
         ld->destroy (ld);
diff --git a/libgnucash/app-utils/gnc-component-manager.c b/libgnucash/app-utils/gnc-component-manager.c
index e788b48..c32be01 100644
--- a/libgnucash/app-utils/gnc-component-manager.c
+++ b/libgnucash/app-utils/gnc-component-manager.c
@@ -690,6 +690,8 @@ gnc_gui_refresh_internal (gboolean force)
 #endif
 
     list = find_component_ids_by_class (NULL);
+    // reverse the list so class GncPluginPageRegister is before register-single
+    list = g_list_reverse (list);
 
     for (node = list; node; node = node->next)
     {

commit 34d921803de8d8bbd7b29280f59c99bb6050fdca
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Mar 21 12:24:00 2018 +0000

    Bug 794360 Critical error when deleting accounts with children
    
    When an account is deleted which has sub accounts a dialog is displayed
    that had parts destroyed so they are not shown depending on certain
    criteria and as a result an error occurred as it tried to get the
    sensitivity of a destroyed widget. Change this so all parts of the
    dialog are present but made in-sensitive when not applicable so the
    dialog layout is the same on all occurrences.

diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c
index d4dbd5c..176e9bc 100644
--- a/gnucash/gnome/gnc-plugin-page-account-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-account-tree.c
@@ -82,6 +82,8 @@ static QofLogModule log_module = GNC_MOD_GUI;
 #define DELETE_DIALOG_TRANS_MAS    "trans_mas"
 #define DELETE_DIALOG_SA_MAS       "sa_mas"
 #define DELETE_DIALOG_SA_TRANS_MAS "sa_trans_mas"
+#define DELETE_DIALOG_SA_TRANS     "sa_trans"
+#define DELETE_DIALOG_SA_SPLITS    "sa_has_split"
 #define DELETE_DIALOG_OK_BUTTON    "deletebutton"
 
 enum
@@ -1286,8 +1288,36 @@ gppat_populate_trans_mas_list(GtkToggleButton *sa_mrb,
 void
 gppat_set_insensitive_iff_rb_active(GtkWidget *widget, GtkToggleButton *b)
 {
+    GtkWidget *dialog = gtk_widget_get_toplevel(widget);
+    GtkWidget *subaccount_trans = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_SA_TRANS);
+    GtkWidget *sa_mas = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_SA_MAS);
+    gboolean have_splits = GPOINTER_TO_INT (g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_SA_SPLITS));
+
     gtk_widget_set_sensitive(widget, !gtk_toggle_button_get_active(b));
-    set_ok_sensitivity(gtk_widget_get_toplevel(widget));
+
+    // If we have subaccount splits & delete subaccounts, enable subaccount_trans
+    if ((have_splits) && !gtk_widget_is_sensitive(sa_mas))
+        gtk_widget_set_sensitive(subaccount_trans, TRUE);
+    else
+        gtk_widget_set_sensitive(subaccount_trans, FALSE);
+
+    set_ok_sensitivity(dialog);
+}
+
+static GtkWidget *
+gppat_setup_account_selector (GtkBuilder *builder, GtkWidget *dialog,
+                              const gchar *hbox, const gchar *sel_name)
+{
+    GtkWidget *selector = gnc_account_sel_new();
+    GtkWidget *box = GTK_WIDGET(gtk_builder_get_object (builder, hbox));
+
+    gtk_box_pack_start (GTK_BOX(box), selector, TRUE, TRUE, 0);
+    g_object_set_data(G_OBJECT(dialog), sel_name, selector);
+
+    gppat_populate_gas_list(dialog, GNC_ACCOUNT_SEL(selector), TRUE);
+    gtk_widget_show_all(box);
+
+    return selector;
 }
 
 static void
@@ -1332,7 +1362,7 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
     splits = xaccAccountGetSplitList(account);
 
     /*
-     * If the account has transactions or child accounts then conduct a
+     * If the account has transactions or child accounts then present a
      * dialog to allow the user to specify what should be done with them.
      */
     if ((NULL != splits) || (gnc_account_n_children(account) > 0))
@@ -1340,7 +1370,6 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
         GList *filter = NULL;
         GtkBuilder *builder = NULL;
         GtkWidget *dialog = NULL;
-        GtkWidget *box = NULL;
         GtkWidget *widget = NULL;
         gchar *title = NULL;
 
@@ -1366,78 +1395,70 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
         g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_FILTER, filter);
         g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_ACCOUNT, account);
 
-        /*
-         * Adjust the dialog based on whether the account has
-         * transactions.
-         */
+        // Add the account selectors and enable sections as appropiate
+        // setup transactions selector
+        trans_mas = gppat_setup_account_selector (builder, dialog, "trans_mas_hbox", DELETE_DIALOG_TRANS_MAS);
+
+        // Does the selected account have splits
         if (splits)
         {
             delete_helper_t delete_res2 = { FALSE, FALSE };
 
-            trans_mas = gnc_account_sel_new();
-            box = GTK_WIDGET(gtk_builder_get_object (builder, "trans_mas_hbox"));
-            gtk_box_pack_start (GTK_BOX(box), trans_mas, TRUE, TRUE, 0);
-            g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_TRANS_MAS, trans_mas);
-            gppat_populate_gas_list(dialog, GNC_ACCOUNT_SEL(trans_mas), FALSE);
-
             delete_account_helper(account, &delete_res2);
             if (delete_res2.has_ro_splits)
             {
-                gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "trans_rw")));
+                gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "trans_rw")));
                 widget = GTK_WIDGET(gtk_builder_get_object (builder, "trans_drb"));
                 gtk_widget_set_sensitive(widget, FALSE);
             }
             else
-            {
-                gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "trans_ro")));
-            }
+                gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "trans_ro")));
         }
         else
         {
-            gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "transactions")));
+            gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object (builder, "transactions")), FALSE);
+            gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "trans_ro")));
         }
 
-        /*
-         * Adjust the dialog based on whether the account has children.
-         */
+        // setup subaccount account selector
+        sa_mas = gppat_setup_account_selector (builder, dialog, "sa_mas_hbox", DELETE_DIALOG_SA_MAS);
+
+        // setup subaccount transaction selector
+        sa_trans_mas = gppat_setup_account_selector (builder, dialog, "sa_trans_mas_hbox", DELETE_DIALOG_SA_TRANS_MAS);
+        g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_SA_TRANS,
+                          GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_trans")));
+
+        // Does the selected account have sub accounts
         if (gnc_account_n_children(account) > 0)
         {
-            /*
-             * Check for RO txns in descendants
-             */
+            // Check for RO txns in descendants
             gnc_account_foreach_descendant_until(account, delete_account_helper,
                                                  &delete_res);
-            if (delete_res.has_ro_splits)
+            if (delete_res.has_splits)
             {
-                gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_rw")));
-                widget = GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_drb"));
-                gtk_widget_set_sensitive(widget, FALSE);
-            }
-            else if (delete_res.has_splits)
-            {
-                gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_ro")));
+                if (delete_res.has_ro_splits)
+                {
+                    gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_rw")));
+                    widget = GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_drb"));
+                    gtk_widget_set_sensitive(widget, FALSE);
+                }
+                else
+                    gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_ro")));
+
+                g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_SA_SPLITS, GINT_TO_POINTER(1));
             }
             else
             {
-                gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_trans")));
+                g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_SA_SPLITS, GINT_TO_POINTER(0));
+                gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_trans")), FALSE);
+                gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_ro")));
             }
-
-            sa_mas = gnc_account_sel_new();
-            box = GTK_WIDGET(gtk_builder_get_object (builder, "sa_mas_hbox"));
-            gtk_box_pack_start (GTK_BOX(box), sa_mas, TRUE, TRUE, 0);
-            g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_SA_MAS, sa_mas);
-            gppat_populate_gas_list(dialog, GNC_ACCOUNT_SEL(sa_mas), TRUE);
-
-            sa_trans_mas = gnc_account_sel_new();
-            box = GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_mas_hbox"));
-            gtk_box_pack_start (GTK_BOX(box), sa_trans_mas, TRUE, TRUE, 0);
-            g_object_set_data(G_OBJECT(dialog), DELETE_DIALOG_SA_TRANS_MAS, sa_trans_mas);
-            gppat_populate_gas_list(dialog, GNC_ACCOUNT_SEL(sa_trans_mas), TRUE);
         }
         else
         {
-            gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "subaccounts")));
-            gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_trans")));
+            gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object (builder, "subaccounts")), FALSE);
+            gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_trans")), FALSE);
+            gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "sa_trans_ro")));
         }
 
         /* default to cancel */
@@ -1450,7 +1471,6 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
          * Note that one effect of the modal dialog is preventing
          * the account selectors from being repopulated.
          */
-        gtk_widget_show_all(dialog);
         response = gtk_dialog_run(GTK_DIALOG(dialog));
         if (GTK_RESPONSE_ACCEPT != response)
         {
diff --git a/gnucash/gtkbuilder/dialog-account.glade b/gnucash/gtkbuilder/dialog-account.glade
index 9569ca7..5a9c210 100644
--- a/gnucash/gtkbuilder/dialog-account.glade
+++ b/gnucash/gtkbuilder/dialog-account.glade
@@ -195,7 +195,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
             <child>
@@ -302,7 +302,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">2</property>
+                <property name="position">1</property>
               </packing>
             </child>
             <child>

commit 2b6047f9529b6cde899e8bb208636f64e9e90ed9
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Mar 20 11:41:21 2018 -0700

    Fix a string msgid generation.
    
    Call gettext in the macro, not on the macro. xgettext doesn't run cpp and can't see inside macros.

diff --git a/src/gnome/gnc-plugin-page-account-tree.c b/src/gnome/gnc-plugin-page-account-tree.c
index ce67bd6..0d24978 100644
--- a/src/gnome/gnc-plugin-page-account-tree.c
+++ b/src/gnome/gnc-plugin-page-account-tree.c
@@ -1162,9 +1162,9 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
     list = qof_instance_get_referring_object_list(QOF_INSTANCE(account));
     if (list != NULL)
     {
-#define EXPLANATION "The list below shows objects which make use of the account which you want to delete.\nBefore you can delete it, you must either delete those objects or else modify them so they make use\nof another account"
+#define EXPLANATION _("The list below shows objects which make use of the account which you want to delete.\nBefore you can delete it, you must either delete those objects or else modify them so they make use\nof another account")
 
-        gnc_ui_object_references_show( _(EXPLANATION), list);
+        gnc_ui_object_references_show (EXPLANATION, list);
         g_list_free(list);
         return;
     }

commit f05bbe24752d576f5356472f6441ca166e988196
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Mar 19 15:52:06 2018 -0700

    Bug 794330 - Scheduled Transaction Editor Transfer Button Does Not Work
    
    It works fine, it just doesn't have anything to do with scheduled
    transactions. Remove it from the SX Editor toolbar.

diff --git a/gnucash/ui/gnc-sxed-window-ui-full.xml b/gnucash/ui/gnc-sxed-window-ui-full.xml
index 65ea884..df8a774 100644
--- a/gnucash/ui/gnc-sxed-window-ui-full.xml
+++ b/gnucash/ui/gnc-sxed-window-ui-full.xml
@@ -45,7 +45,6 @@
       <separator name="ToolbarSep67"/>
       <toolitem name="ToolbarBlankTransaction"     action="BlankTransactionAction"/>
       <separator name="ToolbarSep68"/>
-      <toolitem name="ToolbarTransfer"             action="ActionsTransferAction"/>
     </placeholder>
   </toolbar>
 



Summary of changes:
 CMakeLists.txt                                     |   4 +-
 NEWS                                               |  35 ++++++
 .../python/example_scripts/account_analysis.py     |  14 +--
 .../python/example_scripts/gncinvoice_jinja.py     |  70 ++++++------
 bindings/python/example_scripts/gncinvoicefkt.py   |   6 +-
 bindings/python/example_scripts/latex_invoices.py  |  70 ++++++------
 .../new_book_with_opening_balances.py              |  10 +-
 bindings/python/example_scripts/priceDB_test.py    |   4 +-
 .../example_scripts/price_database_example.py      |  12 +--
 bindings/python/example_scripts/quotes_historic.py |   6 +-
 .../example_scripts/rest-api/gnucash_rest.py       |  10 +-
 bindings/python/example_scripts/simple_book.py     |   8 +-
 .../example_scripts/simple_business_create.py      |   8 +-
 bindings/python/example_scripts/simple_test.py     |   2 +
 .../example_scripts/test_imbalance_transaction.py  |  14 +--
 gnucash/gnome/dialog-price-edit-db.c               |   9 ++
 gnucash/gnome/gnc-plugin-page-account-tree.c       | 120 ++++++++++++---------
 gnucash/gnome/gnc-split-reg.c                      |  12 +--
 gnucash/gtkbuilder/dialog-account.glade            |   4 +-
 gnucash/python/pycons/ishell.py                    |   4 +-
 gnucash/python/pycons/shell.py                     |   6 +-
 gnucash/register/ledger-core/gnc-ledger-display.c  |   1 +
 .../register/ledger-core/split-register-model.c    |   6 +-
 gnucash/ui/gnc-sxed-window-ui-full.xml             |   1 -
 libgnucash/app-utils/date-utilities.scm            |  36 +++----
 libgnucash/app-utils/gnc-component-manager.c       |   2 +
 26 files changed, 271 insertions(+), 203 deletions(-)



More information about the gnucash-changes mailing list