mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
app-utils - move gnc_get_debit/credit_str functions to Account
Eliminates another scm file (prefs.scm). The old scm functions are declared deprecated.
This commit is contained in:
parent
0a635fadee
commit
759bbe1da0
@ -1104,30 +1104,13 @@ gnc_reconcile_key_press_cb (GtkWidget *widget, GdkEventKey *event,
|
||||
static void
|
||||
gnc_reconcile_window_set_titles(RecnWindow *recnData)
|
||||
{
|
||||
gboolean formal;
|
||||
gchar *title;
|
||||
|
||||
formal = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS);
|
||||
|
||||
if (formal)
|
||||
title = _("Debits");
|
||||
else
|
||||
title = gnc_get_debit_string(ACCT_TYPE_NONE);
|
||||
const gchar *title;
|
||||
|
||||
title = gnc_account_get_debit_string(ACCT_TYPE_NONE);
|
||||
gtk_frame_set_label(GTK_FRAME(recnData->debit_frame), title);
|
||||
|
||||
if (!formal)
|
||||
g_free(title);
|
||||
|
||||
if (formal)
|
||||
title = _("Credits");
|
||||
else
|
||||
title = gnc_get_credit_string(ACCT_TYPE_NONE);
|
||||
|
||||
title = gnc_account_get_credit_string(ACCT_TYPE_NONE);
|
||||
gtk_frame_set_label(GTK_FRAME(recnData->credit_frame), title);
|
||||
|
||||
if (!formal)
|
||||
g_free(title);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1063,30 +1063,13 @@ gnc_reconcile_key_press_cb (GtkWidget *widget, GdkEventKey *event,
|
||||
static void
|
||||
gnc_reconcile_window_set_titles (RecnWindow2 *recnData)
|
||||
{
|
||||
gboolean formal;
|
||||
gchar *title;
|
||||
|
||||
formal = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS);
|
||||
|
||||
if (formal)
|
||||
title = _("Debits");
|
||||
else
|
||||
title = gnc_get_debit_string (ACCT_TYPE_NONE);
|
||||
const gchar *title;
|
||||
|
||||
title = gnc_account_get_debit_string (ACCT_TYPE_NONE);
|
||||
gtk_frame_set_label (GTK_FRAME (recnData->debit_frame), title);
|
||||
|
||||
if (!formal)
|
||||
g_free(title);
|
||||
|
||||
if (formal)
|
||||
title = _("Credits");
|
||||
else
|
||||
title = gnc_get_credit_string (ACCT_TYPE_NONE);
|
||||
|
||||
title = gnc_account_get_credit_string (ACCT_TYPE_NONE);
|
||||
gtk_frame_set_label (GTK_FRAME (recnData->credit_frame), title);
|
||||
|
||||
if (!formal)
|
||||
g_free(title);
|
||||
}
|
||||
|
||||
|
||||
|
@ -126,8 +126,8 @@ struct sr_info
|
||||
GncGUID template_account;
|
||||
|
||||
/** configured strings for debit/credit headers */
|
||||
char *debit_str;
|
||||
char *credit_str;
|
||||
const char *debit_str;
|
||||
const char *credit_str;
|
||||
char *tdebit_str;
|
||||
char *tcredit_str;
|
||||
|
||||
|
@ -2500,7 +2500,7 @@ gnc_split_register_get_debit_string (SplitRegister *reg)
|
||||
return info->debit_str;
|
||||
|
||||
info->debit_str =
|
||||
gnc_get_debit_string
|
||||
gnc_account_get_debit_string
|
||||
(gnc_split_register_type_to_account_type (reg->type));
|
||||
|
||||
if (info->debit_str)
|
||||
@ -2523,7 +2523,7 @@ gnc_split_register_get_credit_string (SplitRegister *reg)
|
||||
return info->credit_str;
|
||||
|
||||
info->credit_str =
|
||||
gnc_get_credit_string
|
||||
gnc_account_get_credit_string
|
||||
(gnc_split_register_type_to_account_type (reg->type));
|
||||
|
||||
if (info->credit_str)
|
||||
@ -2798,9 +2798,7 @@ split_register_pref_changed (gpointer prefs, gchar *pref, gpointer user_data)
|
||||
if (g_str_has_suffix(pref, GNC_PREF_ACCOUNTING_LABELS))
|
||||
{
|
||||
/* Release current strings. Will be reloaded at next reference. */
|
||||
g_free (info->debit_str);
|
||||
g_free (info->tdebit_str);
|
||||
g_free (info->credit_str);
|
||||
g_free (info->tcredit_str);
|
||||
|
||||
info->debit_str = NULL;
|
||||
@ -3033,9 +3031,7 @@ gnc_split_register_destroy_info (SplitRegister *reg)
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
g_free (info->debit_str);
|
||||
g_free (info->tdebit_str);
|
||||
g_free (info->credit_str);
|
||||
g_free (info->tcredit_str);
|
||||
|
||||
info->debit_str = NULL;
|
||||
|
@ -1264,8 +1264,8 @@ be excluded from periodic reporting.")
|
||||
(row-currency (lambda (s) (if (column-uses? 'common-currency)
|
||||
(opt-val gnc:pagename-general optname-currency)
|
||||
(split-currency s))))
|
||||
(friendly-debit (lambda (a) (gnc:get-debit-string (xaccAccountGetType a))))
|
||||
(friendly-credit (lambda (a) (gnc:get-credit-string (xaccAccountGetType a))))
|
||||
(friendly-debit (lambda (a) (gnc-account-get-debit-string (xaccAccountGetType a))))
|
||||
(friendly-credit (lambda (a) (gnc-account-get-credit-string (xaccAccountGetType a))))
|
||||
(header-commodity (lambda (str)
|
||||
(string-append
|
||||
str
|
||||
|
@ -166,7 +166,6 @@ set (app_utils_SCHEME_1
|
||||
c-interface.scm
|
||||
date-utilities.scm
|
||||
options.scm
|
||||
prefs.scm
|
||||
fin.scm
|
||||
)
|
||||
|
||||
|
@ -152,11 +152,6 @@
|
||||
(list category key))))
|
||||
(export gnc:option-get-value)
|
||||
|
||||
;; prefs.scm
|
||||
(export gnc:get-debit-string)
|
||||
(export gnc:get-credit-string)
|
||||
(export gnc:config-file-format-version)
|
||||
|
||||
;; gw-engine-spec.scm
|
||||
(re-export HOOK-SAVE-OPTIONS)
|
||||
|
||||
@ -256,7 +251,6 @@
|
||||
|
||||
(load-from-path "gnucash/app-utils/c-interface")
|
||||
(load-from-path "gnucash/app-utils/options")
|
||||
(load-from-path "gnucash/app-utils/prefs")
|
||||
(load-from-path "gnucash/app-utils/date-utilities")
|
||||
|
||||
;; Business options
|
||||
@ -311,3 +305,15 @@
|
||||
|
||||
(load-from-path "gnucash/app-utils/business-options")
|
||||
(load-from-path "gnucash/app-utils/business-prefs")
|
||||
|
||||
|
||||
;; Symbols deprecated in 4.x, to remove for 5.x
|
||||
(define-public (gnc:get-debit-string acct-type)
|
||||
(issue-deprecation-warning "gnc:get-debit-string is deprecated. Please use (gnucash engine)'s gnc-account-get-debit-string instead.")
|
||||
(gnc-account-get-debit-string acct-type))
|
||||
(define-public (gnc:get-credit-string acct-type)
|
||||
(issue-deprecation-warning "gnc:get-credit-string is deprecated. Please use (gnucash engine)'s gnc-account-get-credit-string instead.")
|
||||
(gnc-account-get-debit-string acct-type))
|
||||
(define-public (gnc:config-file-format-version version)
|
||||
(issue-deprecation-warning "gnc:config-file-format-version is deprecated and will be removed from a future version.")
|
||||
#t)
|
||||
|
@ -63,12 +63,6 @@
|
||||
/* This static indicates the debugging module this .o belongs to. */
|
||||
static QofLogModule UNUSED_VAR log_module = GNC_MOD_GUILE;
|
||||
|
||||
struct _getters
|
||||
{
|
||||
SCM debit_string;
|
||||
SCM credit_string;
|
||||
} getters;
|
||||
|
||||
struct _Process
|
||||
{
|
||||
GPid pid;
|
||||
@ -79,83 +73,6 @@ struct _Process
|
||||
gboolean detached;
|
||||
};
|
||||
|
||||
static void
|
||||
initialize_scm_functions()
|
||||
{
|
||||
static gboolean scm_funcs_inited = FALSE;
|
||||
|
||||
if (scm_funcs_inited)
|
||||
return;
|
||||
|
||||
getters.debit_string = scm_c_eval_string("gnc:get-debit-string");
|
||||
getters.credit_string = scm_c_eval_string("gnc:get-credit-string");
|
||||
|
||||
scm_funcs_inited = TRUE;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_get_debit_string *
|
||||
* return a debit string for a given account type *
|
||||
* *
|
||||
* Args: account_type - type of account to get debit string for *
|
||||
* Return: g_malloc'd debit string or NULL *
|
||||
\********************************************************************/
|
||||
char *
|
||||
gnc_get_debit_string(GNCAccountType account_type)
|
||||
{
|
||||
SCM result;
|
||||
SCM arg;
|
||||
|
||||
initialize_scm_functions();
|
||||
|
||||
if (gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS))
|
||||
return g_strdup(_("Debit"));
|
||||
|
||||
if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES))
|
||||
account_type = ACCT_TYPE_NONE;
|
||||
|
||||
arg = scm_from_long (account_type);
|
||||
|
||||
result = scm_call_1(getters.debit_string, arg);
|
||||
if (!scm_is_string(result))
|
||||
return NULL;
|
||||
|
||||
return scm_to_utf8_string(result);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************\
|
||||
* gnc_get_credit_string *
|
||||
* return a credit string for a given account type *
|
||||
* *
|
||||
* Args: account_type - type of account to get credit string for *
|
||||
* Return: g_malloc'd credit string or NULL, must be freed with g_free *
|
||||
\************************************************************************/
|
||||
char *
|
||||
gnc_get_credit_string(GNCAccountType account_type)
|
||||
{
|
||||
SCM result;
|
||||
SCM arg;
|
||||
|
||||
initialize_scm_functions();
|
||||
|
||||
if (gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS))
|
||||
return g_strdup(_("Credit"));
|
||||
|
||||
if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES))
|
||||
account_type = ACCT_TYPE_NONE;
|
||||
|
||||
arg = scm_from_long (account_type);
|
||||
|
||||
result = scm_call_1(getters.credit_string, arg);
|
||||
if (!scm_is_string(result))
|
||||
return NULL;
|
||||
|
||||
return gnc_scm_to_utf8_string(result);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
on_child_exit (GPid pid, gint status, gpointer data)
|
||||
{
|
||||
|
@ -32,13 +32,6 @@
|
||||
#include "Account.h"
|
||||
#include "gnc-guile-utils.h"
|
||||
|
||||
|
||||
/* Two functions that return string synonyms for the terms 'debit' and
|
||||
* 'credit' as appropriate for the given account type and user preferences.
|
||||
* They should be g_freed when no longer needed. */
|
||||
char * gnc_get_debit_string(GNCAccountType account_type);
|
||||
char * gnc_get_credit_string(GNCAccountType account_type);
|
||||
|
||||
/** An opaque process structure returned by gnc_spawn_process_async. */
|
||||
typedef struct _Process Process;
|
||||
|
||||
|
@ -1,100 +0,0 @@
|
||||
;; Preferences
|
||||
;;
|
||||
;; 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@gnu.org
|
||||
|
||||
;; (define gnc:*double-entry-restriction*
|
||||
;; (gnc:make-config-var
|
||||
;; "Determines how the splits in a transaction will be balanced.
|
||||
;; The following values have significance:
|
||||
;;
|
||||
;; #f anything goes
|
||||
;;
|
||||
;; 'force The sum of all splits in a transaction will be
|
||||
;; forced to be zero, even if this requires the
|
||||
;; creation of additional splits. Note that a split
|
||||
;; whose value is zero (e.g. a stock price) can exist
|
||||
;; by itself. Otherwise, all splits must come in at
|
||||
;; least pairs.
|
||||
;;
|
||||
;; 'collect splits without parents will be forced into a
|
||||
;; lost & found account. (Not implemented)"
|
||||
;; (lambda (var value)
|
||||
;; (cond
|
||||
;; ((eq? value #f)
|
||||
;; (_gnc_set_force_double_entry_ 0)
|
||||
;; (list value))
|
||||
;; ((eq? value 'force)
|
||||
;; (_gnc_set_force_double_entry_ 1)
|
||||
;; (list value))
|
||||
;; ((eq? value 'collect)
|
||||
;; (gnc:warn
|
||||
;; "gnc:*double-entry-restriction* -- 'collect not supported yet. "
|
||||
;; "Ignoring.")
|
||||
;; #f)
|
||||
;; (else
|
||||
;; (gnc:warn
|
||||
;; "gnc:*double-entry-restriction* -- " value " not supported. Ignoring.")
|
||||
;; #f)))
|
||||
;; eq?
|
||||
;; #f))
|
||||
(use-modules (gnucash gettext))
|
||||
|
||||
;; Old-school config files depend on this API
|
||||
(define (gnc:config-file-format-version version) #t)
|
||||
|
||||
;;;;;; Create config vars
|
||||
|
||||
(define gnc:*debit-strings*
|
||||
(list (cons ACCT-TYPE-NONE (N_ "Funds In"))
|
||||
(cons ACCT-TYPE-BANK (N_ "Deposit"))
|
||||
(cons ACCT-TYPE-CASH (N_ "Receive"))
|
||||
(cons ACCT-TYPE-CREDIT (N_ "Payment"))
|
||||
(cons ACCT-TYPE-ASSET (N_ "Increase"))
|
||||
(cons ACCT-TYPE-LIABILITY (N_ "Decrease"))
|
||||
(cons ACCT-TYPE-STOCK (N_ "Buy"))
|
||||
(cons ACCT-TYPE-MUTUAL (N_ "Buy"))
|
||||
(cons ACCT-TYPE-CURRENCY (N_ "Buy"))
|
||||
(cons ACCT-TYPE-INCOME (N_ "Charge"))
|
||||
(cons ACCT-TYPE-EXPENSE (N_ "Expense"))
|
||||
(cons ACCT-TYPE-PAYABLE (N_ "Payment"))
|
||||
(cons ACCT-TYPE-RECEIVABLE (N_ "Invoice"))
|
||||
(cons ACCT-TYPE-TRADING (N_ "Decrease"))
|
||||
(cons ACCT-TYPE-EQUITY (N_ "Decrease"))))
|
||||
|
||||
(define gnc:*credit-strings*
|
||||
(list (cons ACCT-TYPE-NONE (N_ "Funds Out"))
|
||||
(cons ACCT-TYPE-BANK (N_ "Withdrawal"))
|
||||
(cons ACCT-TYPE-CASH (N_ "Spend"))
|
||||
(cons ACCT-TYPE-CREDIT (N_ "Charge"))
|
||||
(cons ACCT-TYPE-ASSET (N_ "Decrease"))
|
||||
(cons ACCT-TYPE-LIABILITY (N_ "Increase"))
|
||||
(cons ACCT-TYPE-STOCK (N_ "Sell"))
|
||||
(cons ACCT-TYPE-MUTUAL (N_ "Sell"))
|
||||
(cons ACCT-TYPE-CURRENCY (N_ "Sell"))
|
||||
(cons ACCT-TYPE-INCOME (N_ "Income"))
|
||||
(cons ACCT-TYPE-EXPENSE (N_ "Rebate"))
|
||||
(cons ACCT-TYPE-PAYABLE (N_ "Bill"))
|
||||
(cons ACCT-TYPE-RECEIVABLE (N_ "Payment"))
|
||||
(cons ACCT-TYPE-TRADING (N_ "Increase"))
|
||||
(cons ACCT-TYPE-EQUITY (N_ "Increase"))))
|
||||
|
||||
(define (gnc:get-debit-string type)
|
||||
(_ (assoc-ref gnc:*debit-strings* type)))
|
||||
|
||||
(define (gnc:get-credit-string type)
|
||||
(_ (assoc-ref gnc:*credit-strings* type)))
|
@ -25,6 +25,10 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
extern "C" {
|
||||
#include "gnc-prefs.h"
|
||||
}
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <stdlib.h>
|
||||
@ -44,6 +48,7 @@
|
||||
#include "guid.hpp"
|
||||
|
||||
#include <numeric>
|
||||
#include <map>
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_ACCOUNT;
|
||||
|
||||
@ -127,6 +132,46 @@ enum
|
||||
#define GET_PRIVATE(o) \
|
||||
((AccountPrivate*)g_type_instance_get_private((GTypeInstance*)o, GNC_TYPE_ACCOUNT))
|
||||
|
||||
/* This map contains a set of strings representing the different column types. */
|
||||
std::map<GNCAccountType, const char*> gnc_acct_debit_strs = {
|
||||
{ ACCT_TYPE_NONE, _("Funds In") },
|
||||
{ ACCT_TYPE_BANK, _("Deposit") },
|
||||
{ ACCT_TYPE_CASH, _("Receive") },
|
||||
{ ACCT_TYPE_CREDIT, _("Payment") },
|
||||
{ ACCT_TYPE_ASSET, _("Increase") },
|
||||
{ ACCT_TYPE_LIABILITY, _("Decrease") },
|
||||
{ ACCT_TYPE_STOCK, _("Buy") },
|
||||
{ ACCT_TYPE_MUTUAL, _("Buy") },
|
||||
{ ACCT_TYPE_CURRENCY, _("Buy") },
|
||||
{ ACCT_TYPE_INCOME, _("Charge") },
|
||||
{ ACCT_TYPE_EXPENSE, _("Expense") },
|
||||
{ ACCT_TYPE_PAYABLE, _("Payment") },
|
||||
{ ACCT_TYPE_RECEIVABLE, _("Invoice") },
|
||||
{ ACCT_TYPE_TRADING, _("Decrease") },
|
||||
{ ACCT_TYPE_EQUITY, _("Decrease") },
|
||||
};
|
||||
const char* dflt_acct_debit_str = _("Debit");
|
||||
|
||||
/* This map contains a set of strings representing the different column types. */
|
||||
std::map<GNCAccountType, const char*> gnc_acct_credit_strs = {
|
||||
{ ACCT_TYPE_NONE, _("Funds Out") },
|
||||
{ ACCT_TYPE_BANK, _("Withdrawal") },
|
||||
{ ACCT_TYPE_CASH, _("Spend") },
|
||||
{ ACCT_TYPE_CREDIT, _("Charge") },
|
||||
{ ACCT_TYPE_ASSET, _("Decrease") },
|
||||
{ ACCT_TYPE_LIABILITY, _("Increase") },
|
||||
{ ACCT_TYPE_STOCK, _("Sell") },
|
||||
{ ACCT_TYPE_MUTUAL, _("Sell") },
|
||||
{ ACCT_TYPE_CURRENCY, _("Sell") },
|
||||
{ ACCT_TYPE_INCOME, _("Income") },
|
||||
{ ACCT_TYPE_EXPENSE, _("Rebate") },
|
||||
{ ACCT_TYPE_PAYABLE, _("Bill") },
|
||||
{ ACCT_TYPE_RECEIVABLE, _("Payment") },
|
||||
{ ACCT_TYPE_TRADING, _("Increase") },
|
||||
{ ACCT_TYPE_EQUITY, _("Increase") },
|
||||
};
|
||||
const char* dflt_acct_credit_str = _("Credit");
|
||||
|
||||
/********************************************************************\
|
||||
* Because I can't use C++ for this project, doesn't mean that I *
|
||||
* can't pretend to! These functions perform actions on the *
|
||||
@ -4024,6 +4069,34 @@ xaccAccountSetTaxUSCopyNumber (Account *acc, gint64 copy_number)
|
||||
xaccAccountCommitEdit (acc);
|
||||
}
|
||||
|
||||
/*********************************************************************\
|
||||
\ ********************************************************************/
|
||||
|
||||
|
||||
const char *gnc_account_get_debit_string (GNCAccountType acct_type)
|
||||
{
|
||||
if (gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS))
|
||||
return dflt_acct_debit_str;
|
||||
|
||||
auto result = gnc_acct_debit_strs.find(acct_type);
|
||||
if (result != gnc_acct_debit_strs.end())
|
||||
return result->second;
|
||||
else
|
||||
return dflt_acct_debit_str;
|
||||
}
|
||||
|
||||
const char *gnc_account_get_credit_string (GNCAccountType acct_type)
|
||||
{
|
||||
if (gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS))
|
||||
return dflt_acct_credit_str;
|
||||
|
||||
auto result = gnc_acct_credit_strs.find(acct_type);
|
||||
if (result != gnc_acct_credit_strs.end())
|
||||
return result->second;
|
||||
else
|
||||
return dflt_acct_credit_str;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
|
@ -1238,6 +1238,17 @@ gint64 xaccAccountGetTaxUSCopyNumber (const Account *account);
|
||||
void xaccAccountSetTaxUSCopyNumber (Account *account, gint64 copy_number);
|
||||
/** @} */
|
||||
|
||||
/** @name Account type debit/credit string getters
|
||||
@ { *
|
||||
*/
|
||||
|
||||
/** Get the debit string associated with this account type */
|
||||
const char *gnc_account_get_debit_string (GNCAccountType acct_type);
|
||||
/** Get the credit string associated with this account type */
|
||||
const char *gnc_account_get_credit_string (GNCAccountType acct_type);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
/** @name Account marking
|
||||
@{
|
||||
|
@ -545,7 +545,6 @@ libgnucash/app-utils/gnc-ui-util.c
|
||||
libgnucash/app-utils/guile-util.c
|
||||
libgnucash/app-utils/options.scm
|
||||
libgnucash/app-utils/option-util.c
|
||||
libgnucash/app-utils/prefs.scm
|
||||
libgnucash/app-utils/QuickFill.c
|
||||
libgnucash/backend/dbi/gnc-backend-dbi.cpp
|
||||
libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user