gnucash master: Multiple changes pushed
J. Alex Aycinena
alex.aycinena at code.gnucash.org
Mon Jun 6 19:28:42 EDT 2016
Updated via https://github.com/Gnucash/gnucash/commit/9f3dc0c8 (commit)
via https://github.com/Gnucash/gnucash/commit/c0086e15 (commit)
from https://github.com/Gnucash/gnucash/commit/58b35eb7 (commit)
commit 9f3dc0c82657d99316a0477a2a36ab5fa00c4ed9
Merge: 58b35eb c0086e1
Author: Alex Aycinena <alex.aycinena at gmail.com>
Date: Mon Jun 6 16:28:04 2016 -0700
Merge maint.
diff --cc src/app-utils/gnc-ui-util.c
index ea28d48,e27bffc..54295ee
--- a/src/app-utils/gnc-ui-util.c
+++ b/src/app-utils/gnc-ui-util.c
@@@ -265,89 -265,6 +265,88 @@@ gnc_book_option_num_field_source_change
gnc_resume_gui_refresh ();
}
+/** Calls gnc_book_option_book_currency_selected to initiate registered
+ * callbacks when currency accounting book option changes to book-currency so
+ * that registers/reports can update themselves; sets feature flag */
+void
+gnc_book_option_book_currency_selected_cb (gboolean use_book_currency)
+{
+ gnc_suspend_gui_refresh ();
+ if (use_book_currency)
+ {
+ /* Set a feature flag in the book for use of book currency. This will
+ * prevent older GnuCash versions that don't support this feature from
+ * opening this file. */
+ gnc_features_set_used (gnc_get_current_book(),
+ GNC_FEATURE_BOOK_CURRENCY);
+ }
+ gnc_book_option_book_currency_selected (use_book_currency);
+ gnc_resume_gui_refresh ();
- gnc_gui_refresh_all ();
+}
+
+/** Returns TRUE if both book-currency and default gain/loss policy KVPs exist
+ * and are valid and trading accounts are not used. */
+gboolean
+gnc_book_use_book_currency (QofBook *book)
+{
+ const gchar *policy;
+ const gchar *currency;
+
+ if (!book) return FALSE;
+
+ policy = qof_book_get_default_gains_policy (book);
+ currency = qof_book_get_book_currency (book);
+
+ /* If either a default gain/loss policy or a book-currency does not exist,
+ book-currency accounting method not valid */
+ if (!policy || !currency)
+ return FALSE;
+
+ /* If both exist, both must be valid */
+ if (!gnc_valid_policy (policy) || !gnc_commodity_table_lookup
+ (gnc_commodity_table_get_table
+ (gnc_get_current_book()),
+ GNC_COMMODITY_NS_CURRENCY,
+ currency))
+ return FALSE;
+
+ /* If both exist and are valid, there must be no trading accounts flag */
+ if (qof_book_use_trading_accounts (book))
+ return FALSE;
+
+ return TRUE;
+}
+
+/** Returns pointer to Book Currency name for book or NULL; determines
+ * that both book-currency and default gain/loss policy KVPs exist and that
+ * both are valid, a requirement for the 'book-currency' currency accounting
+ * method to apply. */
+const gchar *
+gnc_book_get_book_currency (QofBook *book)
+{
+ if (!book) return NULL;
+
+ if (gnc_book_use_book_currency (book))
+ return qof_book_get_book_currency (book);
+
+ return NULL;
+}
+
+/** Returns pointer to default gain/loss policy for book or NULL; determines
+ * that both book-currency and default gain/loss policy KVPs exist and that
+ * both are valid, a requirement for the 'book-currency' currency accounting
+ * method to apply. */
+const gchar *
+gnc_book_get_default_gains_policy (QofBook *book)
+{
+ if (!book) return NULL;
+
+ if (gnc_book_use_book_currency (book))
+ return qof_book_get_default_gains_policy (book);
+
+ return NULL;
+}
+
Account *
gnc_get_current_root_account (void)
{
diff --cc src/gnome-utils/gnc-main-window.c
index 52ea626,cff961f..14b22e4
--- a/src/gnome-utils/gnc-main-window.c
+++ b/src/gnome-utils/gnc-main-window.c
@@@ -3923,58 -3935,28 +3923,51 @@@ gnc_main_window_cmd_page_setup (GtkActi
gnc_ui_page_setup(gtk_window);
}
-static void
-gnc_book_options_dialog_apply_cb(GNCOptionWin * optionwin,
- gpointer user_data)
+gboolean
+gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
{
- GNCOptionDB * options = user_data;
- kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
+ QofBook *book = gnc_get_current_book ();
gboolean use_split_action_for_num_before =
- qof_book_use_split_action_for_num_field (gnc_get_current_book ());
+ qof_book_use_split_action_for_num_field (book);
+ gboolean use_book_currency_before =
+ gnc_book_use_book_currency (book);
gboolean use_split_action_for_num_after;
+ gboolean use_book_currency_after;
+ gboolean return_val = FALSE;
- if (!options) return;
+ if (!options) return return_val;
gnc_option_db_commit (options);
- gnc_option_db_save_to_kvp (options, slots, TRUE);
- qof_book_kvp_changed (gnc_get_current_book());
+ qof_book_begin_edit (book);
+ qof_book_save_options (book, gnc_option_db_save, options, TRUE);
use_split_action_for_num_after =
- qof_book_use_split_action_for_num_field (gnc_get_current_book ());
+ qof_book_use_split_action_for_num_field (book);
+ use_book_currency_after = gnc_book_use_book_currency (book);
if (use_split_action_for_num_before != use_split_action_for_num_after)
{
- gnc_book_option_num_field_source_change_cb (use_split_action_for_num_after);
- gnc_gui_refresh_all ();
+ gnc_book_option_num_field_source_change_cb (
+ use_split_action_for_num_after);
+ return_val = TRUE;
}
+ if (use_book_currency_before != use_book_currency_after)
+ {
+ gnc_book_option_book_currency_selected_cb (use_book_currency_after);
+ return_val = TRUE;
+ }
+ qof_book_commit_edit (book);
+ return return_val;
+}
+
+static void
+gnc_book_options_dialog_apply_cb(GNCOptionWin * optionwin,
+ gpointer user_data)
+{
+ GNCOptionDB * options = user_data;
+
+ if (!options) return;
+
+ if (gnc_book_options_dialog_apply_helper (options))
- {
+ gnc_gui_refresh_all ();
- if (!optionwin) return;
- /* the previous stmt causes the 'apply' and 'OK' buttons to be set to
- sensitive on the open Book Options dialog; the next stmt resets them
- to insensitive, as they should be */
- gnc_options_dialog_not_changed (optionwin);
- }
}
static void
commit c0086e15e957df3589918abbea9c6a3579d24933
Author: Alex Aycinena <alex.aycinena at gmail.com>
Date: Mon Jun 6 15:17:55 2016 -0700
Partially revert commit B555f495 and solve problem more simply by instead resequencing prior statements.
diff --git a/src/gnome-utils/dialog-options.c b/src/gnome-utils/dialog-options.c
index 48d4267..3b7bab7 100644
--- a/src/gnome-utils/dialog-options.c
+++ b/src/gnome-utils/dialog-options.c
@@ -168,14 +168,6 @@ gnc_options_dialog_changed (GNCOptionWin *win)
}
void
-gnc_options_dialog_not_changed (GNCOptionWin *win)
-{
- if (!win) return;
-
- gnc_options_dialog_changed_internal (win->dialog, FALSE);
-}
-
-void
gnc_option_changed_widget_cb(GtkWidget *widget, GNCOption *option)
{
gnc_option_set_changed (option, TRUE);
@@ -1321,14 +1313,16 @@ gnc_options_dialog_response_cb(GtkDialog *dialog, gint response, GNCOptionWin *w
case GTK_RESPONSE_OK:
case GTK_RESPONSE_APPLY:
- gnc_options_dialog_changed_internal (window->dialog, FALSE);
close_cb = window->close_cb;
window->close_cb = NULL;
if (window->apply_cb)
window->apply_cb (window, window->apply_cb_data);
window->close_cb = close_cb;
if (response == GTK_RESPONSE_APPLY)
+ {
+ gnc_options_dialog_changed_internal (window->dialog, FALSE);
break;
+ }
/* fall through */
default:
diff --git a/src/gnome-utils/dialog-options.h b/src/gnome-utils/dialog-options.h
index a981894..4cdcbb1 100644
--- a/src/gnome-utils/dialog-options.h
+++ b/src/gnome-utils/dialog-options.h
@@ -46,7 +46,6 @@ GtkWidget * gnc_options_page_list(GNCOptionWin * win);
GtkWidget * gnc_options_dialog_notebook(GNCOptionWin * win);
void gnc_options_dialog_changed (GNCOptionWin *win);
-void gnc_options_dialog_not_changed (GNCOptionWin *win);
void gnc_option_changed_widget_cb(GtkWidget *widget, GNCOption *option);
void gnc_option_changed_option_cb(GtkWidget *dummy, GNCOption *option);
diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c
index 681f469..cff961f 100644
--- a/src/gnome-utils/gnc-main-window.c
+++ b/src/gnome-utils/gnc-main-window.c
@@ -3956,10 +3956,6 @@ gnc_book_options_dialog_apply_cb(GNCOptionWin * optionwin,
{
gnc_book_option_num_field_source_change_cb (use_split_action_for_num_after);
gnc_gui_refresh_all ();
- /* the previous stmt causes the 'apply' and 'OK' buttons to be set to
- sensitive on the open Book Options dialog; the next stmt resets them
- to insensitive, as they should be */
- gnc_options_dialog_not_changed (optionwin);
}
}
Summary of changes:
src/app-utils/gnc-ui-util.c | 1 -
src/gnome-utils/dialog-options.c | 12 +++---------
src/gnome-utils/dialog-options.h | 1 -
src/gnome-utils/gnc-main-window.c | 7 -------
4 files changed, 3 insertions(+), 18 deletions(-)
More information about the gnucash-changes
mailing list