2001-08-17 00:44:01 +00:00
|
|
|
/********************************************************************\
|
2006-10-15 19:02:05 +00:00
|
|
|
* gnc-helpers.c -- gnucash app-util helper functions *
|
2001-08-17 00:44:01 +00:00
|
|
|
* Copyright (C) 2000 Linas Vepstas *
|
|
|
|
|
* *
|
|
|
|
|
* 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 *
|
2005-11-17 05:35:02 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2001-08-17 00:44:01 +00:00
|
|
|
* *
|
|
|
|
|
\********************************************************************/
|
|
|
|
|
|
2017-10-26 11:14:21 +02:00
|
|
|
#include <config.h>
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2003-02-22 08:15:53 +00:00
|
|
|
#include <libguile.h>
|
2001-08-17 00:44:01 +00:00
|
|
|
#include <string.h>
|
2006-10-15 19:02:05 +00:00
|
|
|
#include "swig-runtime.h"
|
2019-04-27 13:23:54 -07:00
|
|
|
#include "guile-mappings.h"
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
#include "gnc-engine.h"
|
2013-04-13 10:40:55 +00:00
|
|
|
#include "engine-helpers-guile.h"
|
2001-08-18 08:18:58 +00:00
|
|
|
#include "gnc-helpers.h"
|
|
|
|
|
#include "gnc-ui-util.h"
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 00:44:01 +00:00
|
|
|
/* Type converters for GNCPrintAmountInfo */
|
|
|
|
|
SCM
|
|
|
|
|
gnc_printinfo2scm(GNCPrintAmountInfo info)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
SCM info_scm = SCM_EOL;
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = scm_cons (SCM_BOOL (info.round), info_scm);
|
|
|
|
|
info_scm = scm_cons (SCM_BOOL (info.force_fit), info_scm);
|
|
|
|
|
info_scm = scm_cons (SCM_BOOL (info.monetary), info_scm);
|
|
|
|
|
info_scm = scm_cons (SCM_BOOL (info.use_locale), info_scm);
|
|
|
|
|
info_scm = scm_cons (SCM_BOOL (info.use_symbol), info_scm);
|
|
|
|
|
info_scm = scm_cons (SCM_BOOL (info.use_separators), info_scm);
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2012-12-15 17:58:58 +00:00
|
|
|
info_scm = scm_cons (scm_from_int (info.min_decimal_places), info_scm);
|
|
|
|
|
info_scm = scm_cons (scm_from_int (info.max_decimal_places), info_scm);
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = scm_cons (gnc_commodity_to_scm (info.commodity), info_scm);
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2012-12-15 17:58:58 +00:00
|
|
|
info_scm = scm_cons (scm_from_locale_symbol ("print-info"), info_scm);
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return info_scm;
|
2001-08-17 00:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GNCPrintAmountInfo
|
|
|
|
|
gnc_scm2printinfo(SCM info_scm)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
GNCPrintAmountInfo info;
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* skip type */
|
|
|
|
|
info_scm = SCM_CDR (info_scm);
|
|
|
|
|
info.commodity = gnc_scm_to_commodity (SCM_CAR (info_scm));
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = SCM_CDR (info_scm);
|
2012-12-15 17:58:58 +00:00
|
|
|
info.max_decimal_places = scm_to_int (SCM_CAR (info_scm));
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = SCM_CDR (info_scm);
|
2012-12-15 17:58:58 +00:00
|
|
|
info.min_decimal_places = scm_to_int (SCM_CAR (info_scm));
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = SCM_CDR (info_scm);
|
2009-12-31 14:41:12 +00:00
|
|
|
info.use_separators = scm_is_true (SCM_CAR (info_scm));
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = SCM_CDR (info_scm);
|
2009-12-31 14:41:12 +00:00
|
|
|
info.use_symbol = scm_is_true (SCM_CAR (info_scm));
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = SCM_CDR (info_scm);
|
2009-12-31 14:41:12 +00:00
|
|
|
info.use_locale = scm_is_true (SCM_CAR (info_scm));
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = SCM_CDR (info_scm);
|
2009-12-31 14:41:12 +00:00
|
|
|
info.monetary = scm_is_true (SCM_CAR (info_scm));
|
2001-08-17 00:44:01 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = SCM_CDR (info_scm);
|
2009-12-31 14:41:12 +00:00
|
|
|
info.force_fit = scm_is_true (SCM_CAR (info_scm));
|
2002-12-16 01:40:26 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info_scm = SCM_CDR (info_scm);
|
2009-12-31 14:41:12 +00:00
|
|
|
info.round = scm_is_true (SCM_CAR (info_scm));
|
2002-12-16 01:40:26 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return info;
|
2001-08-17 00:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-11 00:45:03 +00:00
|
|
|
/* This is a scaled down version of the routine that would be needed
|
|
|
|
|
* to fully convert a gnc-commodity to a scheme data structure. In an
|
|
|
|
|
* attempt to optimize the speed of price quote retrieval, this
|
|
|
|
|
* routine only converts the fields that price-quotes.scm uses. Since
|
|
|
|
|
* it converts these fields all at once, it should prevent multiple
|
2006-10-15 19:02:05 +00:00
|
|
|
* transitions back and forth from Scheme to C to extract
|
2003-05-11 00:45:03 +00:00
|
|
|
* the data from a pointers to a gnc-commodity (the older method).
|
|
|
|
|
* This is *not* a reversible conversion as it drops data.
|
|
|
|
|
*
|
|
|
|
|
* When this routine was written, gnucash retrieved all quotes into
|
|
|
|
|
* the user's default currency. (Did earlier version do any
|
|
|
|
|
* different?) This routine inserts that default currency into the
|
|
|
|
|
* returned structure as another optimization.
|
|
|
|
|
*/
|
|
|
|
|
SCM
|
|
|
|
|
gnc_quoteinfo2scm(gnc_commodity *comm)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gnc_quote_source *source;
|
|
|
|
|
const char *name, *tz;
|
|
|
|
|
SCM info_scm = SCM_EOL, comm_scm, def_comm_scm;
|
|
|
|
|
|
|
|
|
|
if (!comm)
|
|
|
|
|
return SCM_EOL;
|
|
|
|
|
|
|
|
|
|
source = gnc_commodity_get_quote_source (comm);
|
|
|
|
|
name = gnc_quote_source_get_internal_name (source);
|
|
|
|
|
tz = gnc_commodity_get_quote_tz (comm);
|
|
|
|
|
comm_scm = SWIG_NewPointerObj(comm, SWIG_TypeQuery("_p_gnc_commodity"), 0);
|
|
|
|
|
def_comm_scm = SWIG_NewPointerObj(gnc_default_currency (),
|
|
|
|
|
SWIG_TypeQuery("_p_gnc_commodity"), 0);
|
|
|
|
|
|
|
|
|
|
if (tz)
|
2013-12-13 20:21:41 +00:00
|
|
|
info_scm = scm_cons (scm_from_utf8_string (tz), info_scm);
|
2009-12-29 20:12:48 +00:00
|
|
|
else
|
|
|
|
|
info_scm = scm_cons (SCM_BOOL_F, info_scm);
|
|
|
|
|
info_scm = scm_cons (def_comm_scm, info_scm);
|
|
|
|
|
info_scm = scm_cons (comm_scm, info_scm);
|
2013-12-13 20:21:41 +00:00
|
|
|
info_scm = scm_cons (name ? scm_from_utf8_string (name) : SCM_BOOL_F, info_scm);
|
2009-12-29 20:12:48 +00:00
|
|
|
return info_scm;
|
2003-05-11 00:45:03 +00:00
|
|
|
}
|