1 /********************************************************************\
2  * engine-helpers.h -- gnucash engine helper functions              *
3  * Copyright (C) 2000 Linas Vepstas <linas@linas.org>               *
4  * Copyright (C) 2001 Linux Developers Group, Inc.                  *
5  *                                                                  *
6  * This program is free software; you can redistribute it and/or    *
7  * modify it under the terms of the GNU General Public License as   *
8  * published by the Free Software Foundation; either version 2 of   *
9  * the License, or (at your option) any later version.              *
10  *                                                                  *
11  * This program is distributed in the hope that it will be useful,  *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
14  * GNU General Public License for more details.                     *
15  *                                                                  *
16  * You should have received a copy of the GNU General Public License*
17  * along with this program; if not, contact:                        *
18  *                                                                  *
19  * Free Software Foundation           Voice:  +1-617-542-5942       *
20  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
21  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
22  *                                                                  *
23 \********************************************************************/
24 
25 #ifndef ENGINE_HELPERS_H
26 #define ENGINE_HELPERS_H
27 
28 #ifdef __cplusplus
29 extern "C++" {
30 #include <glib.h>
31 }
32 #endif
33 
34 #include "gnc-engine.h"
35 #include "Account.h"
36 #include "Query.h"
37 #include "Transaction.h"
38 
39 typedef void (*GncBOCb)    (gpointer new_val, gpointer user_data);
40 
41 /** Gets the transaction Number or split Action based on book option:
42   * if the book option is TRUE (split action is used for NUM) and a
43   * split is provided, split-action is returned; if book option is FALSE
44   * (tran-num is used for NUM) and a trans is provided, transaction-num
45   * is returned; if split is provided and tran is NULL, split-action is
46   * returned; if tran is provided and split is NULL, transaction-num is
47   * returned. Otherwise NULL is returned.*/
48 const char *  gnc_get_num_action (const Transaction *trans, const Split *split);
49 
50 /** Opposite of 'gnc_get_num_action'; if the book option is TRUE (split action
51   * is used for NUM) and a trans is provided, transaction-num is returned; if
52   * book option is FALSE (tran-num is used for NUM) and a split is provided,
53   * split-action is returned; if split is provided and tran is NULL,
54   * split-action is returned; if tran is provided and split is NULL,
55   * transaction-num is returned. Otherwise NULL is returned.*/
56 const char *  gnc_get_action_num (const Transaction *trans, const Split *split);
57 
58 /** Sets the transaction Number and/or split Action based on book option:
59   * if the book option is TRUE (split action is to be used for NUM) then 'num'
60   * sets split-action and, if 'tran' and 'action' are provided, 'action'
61   * sets transaction-num; if book option is FALSE (tran-num is to be used for NUM)
62   * then 'num' sets transaction-num and, if 'split' and 'action' are
63   * provided, 'action' sets 'split-action'. If any arguments are NULL,
64   * no change is made to the field that would otherwise be
65   * affected. If 'tran' and 'num' are passed with 'split and 'action' set to
66   * NULL, it is xaccTransSetNum (trans, num). Likewise, if 'split and 'action'
67   * are passed with 'tran' and 'num' set to NULL, it is xaccSplitSetAction (split,
68   * action). */
69 void gnc_set_num_action (Transaction *trans, Split *split,
70                             const char *num, const char *action);
71 
72 /** Calls registered callbacks when num_field_source book option changes so that
73   * registers/reports can update themselves */
74 void
75 gnc_book_option_num_field_source_change (gboolean num_action);
76 
77 /** Calls registered callbacks when book_currency book option changes so that
78   * registers/reports can update themselves */
79 void
80 gnc_book_option_book_currency_selected (gboolean use_book_currency);
81 
82 /** Registers callbacks to be called when the book option changes for the
83   * specified book option key */
84 void
85 gnc_book_option_register_cb (gchar *key, GncBOCb func, gpointer user_data);
86 
87 /** Removes previously registered callbacks for the specified book option key */
88 void
89 gnc_book_option_remove_cb (gchar *key, GncBOCb func, gpointer user_data);
90 
91 #endif
92