GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-helpers.c
1 /********************************************************************\
2  * gnc-helpers.c -- gnucash app-util helper functions *
3  * Copyright (C) 2000 Linas Vepstas *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA [email protected] *
21  * *
22 \********************************************************************/
23 
24 #include "config.h"
25 
26 #include <libguile.h>
27 #include "guile-mappings.h"
28 #include <string.h>
29 #include "swig-runtime.h"
30 
31 #include "gnc-engine.h"
32 #include "engine-helpers-guile.h"
33 #include "gnc-helpers.h"
34 #include "gnc-ui-util.h"
35 
36 
37 /* Type converters for GNCPrintAmountInfo */
38 SCM
39 gnc_printinfo2scm(GNCPrintAmountInfo info)
40 {
41  SCM info_scm = SCM_EOL;
42 
43  info_scm = scm_cons (SCM_BOOL (info.round), info_scm);
44  info_scm = scm_cons (SCM_BOOL (info.force_fit), info_scm);
45  info_scm = scm_cons (SCM_BOOL (info.monetary), info_scm);
46  info_scm = scm_cons (SCM_BOOL (info.use_locale), info_scm);
47  info_scm = scm_cons (SCM_BOOL (info.use_symbol), info_scm);
48  info_scm = scm_cons (SCM_BOOL (info.use_separators), info_scm);
49 
50  info_scm = scm_cons (scm_from_int (info.min_decimal_places), info_scm);
51  info_scm = scm_cons (scm_from_int (info.max_decimal_places), info_scm);
52 
53  info_scm = scm_cons (gnc_commodity_to_scm (info.commodity), info_scm);
54 
55  info_scm = scm_cons (scm_from_locale_symbol ("print-info"), info_scm);
56 
57  return info_scm;
58 }
59 
61 gnc_scm2printinfo(SCM info_scm)
62 {
63  GNCPrintAmountInfo info;
64 
65  /* skip type */
66  info_scm = SCM_CDR (info_scm);
67  info.commodity = gnc_scm_to_commodity (SCM_CAR (info_scm));
68 
69  info_scm = SCM_CDR (info_scm);
70  info.max_decimal_places = scm_to_int (SCM_CAR (info_scm));
71 
72  info_scm = SCM_CDR (info_scm);
73  info.min_decimal_places = scm_to_int (SCM_CAR (info_scm));
74 
75  info_scm = SCM_CDR (info_scm);
76  info.use_separators = scm_is_true (SCM_CAR (info_scm));
77 
78  info_scm = SCM_CDR (info_scm);
79  info.use_symbol = scm_is_true (SCM_CAR (info_scm));
80 
81  info_scm = SCM_CDR (info_scm);
82  info.use_locale = scm_is_true (SCM_CAR (info_scm));
83 
84  info_scm = SCM_CDR (info_scm);
85  info.monetary = scm_is_true (SCM_CAR (info_scm));
86 
87  info_scm = SCM_CDR (info_scm);
88  info.force_fit = scm_is_true (SCM_CAR (info_scm));
89 
90  info_scm = SCM_CDR (info_scm);
91  info.round = scm_is_true (SCM_CAR (info_scm));
92 
93  return info;
94 }
95 
96 /* This is a scaled down version of the routine that would be needed
97  * to fully convert a gnc-commodity to a scheme data structure. In an
98  * attempt to optimize the speed of price quote retrieval, this
99  * routine only converts the fields that price-quotes.scm uses. Since
100  * it converts these fields all at once, it should prevent multiple
101  * transitions back and forth from Scheme to C to extract
102  * the data from a pointers to a gnc-commodity (the older method).
103  * This is *not* a reversible conversion as it drops data.
104  *
105  * When this routine was written, gnucash retrieved all quotes into
106  * the user's default currency. (Did earlier version do any
107  * different?) This routine inserts that default currency into the
108  * returned structure as another optimization.
109  */
110 SCM
111 gnc_quoteinfo2scm(gnc_commodity *comm)
112 {
113  gnc_quote_source *source;
114  const char *name, *tz;
115  SCM info_scm = SCM_EOL, comm_scm, def_comm_scm;
116 
117  if (!comm)
118  return SCM_EOL;
119 
120  source = gnc_commodity_get_quote_source (comm);
121  name = gnc_quote_source_get_internal_name (source);
122  tz = gnc_commodity_get_quote_tz (comm);
123  comm_scm = SWIG_NewPointerObj(comm, SWIG_TypeQuery("_p_gnc_commodity"), 0);
124  def_comm_scm = SWIG_NewPointerObj(gnc_default_currency (),
125  SWIG_TypeQuery("_p_gnc_commodity"), 0);
126 
127  if (tz)
128  info_scm = scm_cons (scm_from_utf8_string (tz), info_scm);
129  else
130  info_scm = scm_cons (SCM_BOOL_F, info_scm);
131  info_scm = scm_cons (def_comm_scm, info_scm);
132  info_scm = scm_cons (comm_scm, info_scm);
133  info_scm = scm_cons (name ? scm_from_utf8_string (name) : SCM_BOOL_F, info_scm);
134  return info_scm;
135 }
utility functions for the GnuCash UI
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
gnc_commodity * gnc_default_currency(void)
Definition: gnc-ui-util.c:939
All type declarations for the whole Gnucash engine.
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
const char * gnc_quote_source_get_internal_name(const gnc_quote_source *source)