Book-Currency Feature step 4

Set feature flag if book-currency option selected and initiate registered
callbacks when currency accounting book option changes to book-currency so that registers/reports can update themselves.

The changes made are:

    app-utils/gnc-ui-util.c & h - define gnc_book_option_book_currency_selected_cb
    core-utils/gnc-features.c & h - define GNC_FEATURE_BOOK_CURRENCY
    engine/engine-helpers.c & h - define gnc_book_option_book_currency_selected
        to call registered callbacks and set feature
    gnome-utils/gnc-main-window.c & h - add checking of book-currency option to
        gnc_book_options_dialog_apply_cb function; refactor common code with
        assistant-hiearchy.c by creating gnc_book_options_dialog_apply_helper
    gnome/assistant-hierarchy.c - use gnc_book_options_dialog_apply_helper
This commit is contained in:
Alex Aycinena 2015-08-13 17:16:02 -07:00
parent fa6fbc5585
commit 558cae3d9c
9 changed files with 84 additions and 30 deletions

View File

@ -266,6 +266,26 @@ gnc_book_option_num_field_source_change_cb (gboolean num_action)
gnc_gui_refresh_all ();
}
/** 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

View File

@ -81,6 +81,11 @@ const gchar * gnc_get_current_book_tax_type (void);
* registers/reports can update themselves; sets feature flag */
void gnc_book_option_num_field_source_change_cb (gboolean num_action);
/** 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);
/** 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);

View File

@ -44,6 +44,7 @@ static gncFeature known_features[] =
{ GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at least GnuCash 2.5.0)" },
{ GNC_FEATURE_NUM_FIELD_SOURCE, "User specifies source of 'num' field'; either transaction number or split action (requires at least GnuCash 2.5.0)" },
{ GNC_FEATURE_KVP_EXTRA_DATA, "Extra data for addresses, jobs or invoice entries (requires at least GnuCash 2.6.4)" },
{ GNC_FEATURE_BOOK_CURRENCY, "User specifies a 'book-currency'; costs of other currencies/commodities tracked in terms of book-currency (requires at least GnuCash 2.7.0)" },
{ NULL },
};

View File

@ -44,6 +44,7 @@
#define GNC_FEATURE_CREDIT_NOTES "Credit Notes"
#define GNC_FEATURE_NUM_FIELD_SOURCE "Number Field Source"
#define GNC_FEATURE_KVP_EXTRA_DATA "Extra data in addresses, jobs or invoice entries"
#define GNC_FEATURE_BOOK_CURRENCY "Use a Book-Currency"
/** @} */

View File

@ -221,6 +221,22 @@ gnc_book_option_num_field_source_change (gboolean num_action)
g_hook_list_invoke(bo_final_hook_list, TRUE);
}
/** Calls registered callbacks when book_currency book option changes so that
* registers/reports can update themselves */
void
gnc_book_option_book_currency_selected (gboolean use_book_currency)
{
GHookList *hook_list;
const gchar *key = OPTION_NAME_BOOK_CURRENCY;
g_once(&bo_init_once, bo_init, NULL);
hook_list = g_hash_table_lookup(bo_callback_hash, key);
if (hook_list != NULL)
g_hook_list_marshal(hook_list, TRUE, bo_call_hook, &use_book_currency);
g_hook_list_invoke(bo_final_hook_list, TRUE);
}
void
gnc_book_option_register_cb (gchar *key, GncBOCb func, gpointer user_data)
{

View File

@ -77,6 +77,11 @@ void gnc_set_num_action (Transaction *trans, Split *split,
void
gnc_book_option_num_field_source_change (gboolean num_action);
/** Calls registered callbacks when book_currency book option changes so that
* registers/reports can update themselves */
void
gnc_book_option_book_currency_selected (gboolean use_book_currency);
/** Registers callbacks to be called when the book option changes for the
* specified book option key */
void

View File

@ -3936,15 +3936,16 @@ gnc_main_window_cmd_page_setup (GtkAction *action,
gnc_ui_page_setup(gtk_window);
}
static void
gnc_book_options_dialog_apply_cb(GNCOptionWin * optionwin,
gpointer user_data)
void
gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
{
GNCOptionDB * options = user_data;
gboolean use_split_action_for_num_before =
qof_book_use_split_action_for_num_field (gnc_get_current_book ());
gboolean use_split_action_for_num_after;
QofBook *book = gnc_get_current_book ();
gboolean use_split_action_for_num_before =
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;
if (!options) return;
@ -3952,12 +3953,25 @@ gnc_book_options_dialog_apply_cb(GNCOptionWin * optionwin,
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_book_option_num_field_source_change_cb (
use_split_action_for_num_after);
if (use_book_currency_before != use_book_currency_after)
gnc_book_option_book_currency_selected_cb (use_book_currency_after);
qof_book_commit_edit (book);
}
static void
gnc_book_options_dialog_apply_cb(GNCOptionWin * optionwin,
gpointer user_data)
{
GNCOptionDB * options = user_data;
if (!options) return;
gnc_book_options_dialog_apply_helper (options);
}
static void
gnc_book_options_dialog_close_cb(GNCOptionWin * optionwin,
gpointer user_data)

View File

@ -422,6 +422,18 @@ void gnc_main_window_show_all_windows(void);
**/
GtkWidget *gnc_book_options_dialog_cb (gboolean modal, gchar *title);
/**
* Processes selected options in the Book Options dialog: checks book_currency
* and use_split_action_for_num to see if features kvp shuold be set. To be used
* where ever a new book situation requires book option selection (e.g., not
* just in Book Options dialog opened from main window but also in new-file
* assistant).
*
* @param GNCOptionDB * options.
*
**/
void gnc_book_options_dialog_apply_helper(GNCOptionDB * options);
#endif /* __GNC_MAIN_WINDOW_H */
/** @} */

View File

@ -1008,26 +1008,6 @@ on_cancel (GtkAssistant *gtkassistant,
gnc_resume_gui_refresh ();
}
static void
finish_book_options_helper(GNCOptionWin * optionwin,
gpointer user_data)
{
GNCOptionDB * options = user_data;
QofBook *book = gnc_get_current_book ();
gboolean use_split_action_for_num_before =
qof_book_use_split_action_for_num_field (book);
gboolean use_split_action_for_num_after;
if (!options) return;
gnc_option_db_commit (options);
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 (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);
}
static void
starting_balance_helper (Account *account, hierarchy_data *data)
{
@ -1062,7 +1042,7 @@ on_finish (GtkAssistant *gtkassistant,
/* Set book options based on the user's choices */
if (data->new_book)
finish_book_options_helper(data->optionwin, data->options);
gnc_book_options_dialog_apply_helper(data->options);
// delete before we suspend GUI events, and then muck with the model,
// because the model doesn't seem to handle this correctly.