The attached patch (from svn diff) adds GObject property definitions to
the gnc_commodity object.
Phil
Index: src/engine/gnc-commodity.c
===================================================================
--- src/engine/gnc-commodity.c (revision 16730)
+++ src/engine/gnc-commodity.c (working copy)
@@ -44,6 +44,21 @@
* of the smallest-transactional-units of the currency are there
* in a 'unitname' unit. */
+enum {
+ PROP_0,
+ PROP_NAMESPACE,
+ PROP_FULL_NAME,
+ PROP_MNEMONIC,
+ PROP_PRINTNAME,
+ PROP_CUSIP,
+ PROP_FRACTION,
+ PROP_UNIQUE_NAME,
+ PROP_QUOTE_FLAG,
+ PROP_QUOTE_SOURCE,
+ PROP_QUOTE_TZ,
+ PROP_REFCOUNT,
+};
+
struct gnc_commodity_s
{
QofInstance inst;
@@ -373,7 +388,7 @@
* Accessor functions - get functions only. There are no set functions.
********************************************************************/
QuoteSourceType
-gnc_quote_source_get_type (gnc_quote_source *source)
+gnc_quote_source_get_type (const gnc_quote_source *source)
{
ENTER("%p", source);
if (!source) {
@@ -386,7 +401,7 @@
}
gint
-gnc_quote_source_get_index (gnc_quote_source *source)
+gnc_quote_source_get_index (const gnc_quote_source *source)
{
ENTER("%p", source);
if (!source) {
@@ -399,7 +414,7 @@
}
gboolean
-gnc_quote_source_get_supported (gnc_quote_source *source)
+gnc_quote_source_get_supported (const gnc_quote_source *source)
{
ENTER("%p", source);
if (!source) {
@@ -412,7 +427,7 @@
}
const char *
-gnc_quote_source_get_user_name (gnc_quote_source *source)
+gnc_quote_source_get_user_name (const gnc_quote_source *source)
{
ENTER("%p", source);
if (!source) {
@@ -424,7 +439,7 @@
}
const char *
-gnc_quote_source_get_old_internal_name (gnc_quote_source *source)
+gnc_quote_source_get_old_internal_name (const gnc_quote_source *source)
{
ENTER("%p", source);
if (!source) {
@@ -436,7 +451,7 @@
}
const char *
-gnc_quote_source_get_internal_name (gnc_quote_source *source)
+gnc_quote_source_get_internal_name (const gnc_quote_source *source)
{
ENTER("%p", source);
if (!source) {
@@ -454,11 +469,11 @@
* installed.
********************************************************************/
void
-gnc_quote_source_set_fq_installed (GList *sources_list)
+gnc_quote_source_set_fq_installed (const GList *sources_list)
{
gnc_quote_source *source;
char *source_name;
- GList *node;
+ const GList *node;
ENTER(" ");
fq_is_installed = TRUE;
@@ -538,7 +553,9 @@
}
/* GObject Initialization */
-QOF_GOBJECT_IMPL(gnc_commodity, gnc_commodity, QOF_TYPE_INSTANCE);
+QOF_GOBJECT_GET_TYPE(gnc_commodity, gnc_commodity, QOF_TYPE_INSTANCE, {});
+QOF_GOBJECT_DISPOSE(gnc_commodity);
+QOF_GOBJECT_FINALIZE(gnc_commodity);
static void
gnc_commodity_init(gnc_commodity* com)
@@ -555,6 +572,200 @@
{
}
+static void
+gnc_commodity_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ gnc_commodity *commodity;
+
+ g_return_if_fail(GNC_IS_COMMODITY(object));
+
+ commodity = GNC_COMMODITY(object);
+ switch (prop_id) {
+ case PROP_NAMESPACE:
+ g_value_set_object(value, commodity->namespace);
+ break;
+ case PROP_FULL_NAME:
+ g_value_set_string(value, commodity->fullname);
+ break;
+ case PROP_MNEMONIC:
+ g_value_set_string(value, commodity->mnemonic);
+ break;
+ case PROP_PRINTNAME:
+ g_value_set_string(value, commodity->printname);
+ break;
+ case PROP_CUSIP:
+ g_value_set_string(value, commodity->cusip);
+ break;
+ case PROP_FRACTION:
+ g_value_set_int(value, commodity->fraction);
+ break;
+ case PROP_UNIQUE_NAME:
+ g_value_set_string(value, commodity->unique_name);
+ break;
+ case PROP_QUOTE_FLAG:
+ g_value_set_boolean(value, commodity->quote_flag);
+ break;
+ case PROP_QUOTE_SOURCE:
+ g_value_set_pointer(value, commodity->quote_source);
+ break;
+ case PROP_QUOTE_TZ:
+ g_value_set_string(value, commodity->quote_tz);
+ break;
+ case PROP_REFCOUNT:
+ g_value_set_int(value, commodity->usage_count);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gnc_commodity_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ gnc_commodity *commodity;
+ gnc_numeric *number;
+
+ g_return_if_fail(GNC_IS_COMMODITY(object));
+
+ commodity = GNC_COMMODITY(object);
+
+ switch (prop_id) {
+ case PROP_NAMESPACE:
+ gnc_commodity_set_namespace(commodity, g_value_get_object(value));
+ break;
+ case PROP_FULL_NAME:
+ gnc_commodity_set_fullname(commodity, g_value_get_string(value));
+ break;
+ case PROP_MNEMONIC:
+ gnc_commodity_set_mnemonic(commodity, g_value_get_string(value));
+ break;
+ case PROP_CUSIP:
+ gnc_commodity_set_cusip(commodity, g_value_get_string(value));
+ break;
+ case PROP_FRACTION:
+ gnc_commodity_set_fraction(commodity, g_value_get_int(value));
+ break;
+ case PROP_QUOTE_FLAG:
+ gnc_commodity_set_quote_flag(commodity, g_value_get_boolean(value));
+ break;
+ case PROP_QUOTE_SOURCE:
+ gnc_commodity_set_quote_source(commodity, g_value_get_pointer(value));
+ break;
+ case PROP_QUOTE_TZ:
+ gnc_commodity_set_quote_tz(commodity, g_value_get_string(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+static void
+gnc_commodity_class_init(struct _GncCommodityClass* klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ gobject_class->dispose = gnc_commodity_dispose;
+ gobject_class->finalize = gnc_commodity_finalize;
+
+ gobject_class->set_property = gnc_commodity_set_property;
+ gobject_class->get_property = gnc_commodity_get_property;
+
+ g_object_class_install_property(gobject_class,
+ PROP_NAMESPACE,
+ g_param_spec_object ("namespace",
+ "Namespace",
+ "The namespace field denotes the "
+ "namespace for this commodity, either "
+ "a currency or symbol from a quote source.",
+ GNC_TYPE_COMMODITY_NAMESPACE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_FULL_NAME,
+ g_param_spec_string ("fullname",
+ "Full Commodity Name",
+ "The fullname is the official full name of"
+ "the currency.",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_MNEMONIC,
+ g_param_spec_string ("mnemonic",
+ "Commodity Mnemonic",
+ "The mnemonic is the official abbreviated"
+ "designation for the currency.",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_PRINTNAME,
+ g_param_spec_string ("printname",
+ "Commodity Print Name",
+ "Printable form of the commodity name.",
+ NULL,
+ G_PARAM_READABLE));
+ g_object_class_install_property(gobject_class,
+ PROP_CUSIP,
+ g_param_spec_string ("cusip",
+ "Commodity CUSIP Code",
+ "?????",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_FRACTION,
+ g_param_spec_int ("fraction",
+ "Fraction",
+ "The fraction is the number of sub-units that "
+ "the basic commodity can be divided into.",
+ 1,
+ 100,
+ 1,
+ G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_UNIQUE_NAME,
+ g_param_spec_string ("unique-name",
+ "Commodity Unique Name",
+ "Unique form of the commodity name which combines "
+ "the namespace name and the commodity name.",
+ NULL,
+ G_PARAM_READABLE));
+ g_object_class_install_property(gobject_class,
+ PROP_QUOTE_FLAG,
+ g_param_spec_boolean ("quote_flag",
+ "Quote Flag",
+ "TRUE if prices are to be downloaded for this "
+ "commodity from a quote source.",
+ FALSE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_QUOTE_SOURCE,
+ g_param_spec_pointer("quote-source",
+ "Quote Source",
+ "The quote source from which prices are downloaded.",
+ G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_QUOTE_TZ,
+ g_param_spec_string ("quote-tz",
+ "Commodity Quote Timezone",
+ "?????",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_REFCOUNT,
+ g_param_spec_int ("refcount",
+ "Reference count",
+ "The reference count is the number of other objects "
+ "that refer to this commodity.",
+ 0,
+ 1000000000,
+ 0,
+ G_PARAM_READABLE));
+}
+
gnc_commodity *
gnc_commodity_new(QofBook *book, const char * fullname,
const char * namespace, const char * mnemonic,
@@ -644,7 +855,7 @@
}
void
-gnc_commodity_copy(gnc_commodity * dest, gnc_commodity *src)
+gnc_commodity_copy(gnc_commodity * dest, const gnc_commodity *src)
{
gnc_commodity_set_fullname (dest, src->fullname);
dest->namespace = src->namespace;
@@ -658,7 +869,7 @@
}
gnc_commodity *
-gnc_commodity_clone(gnc_commodity *src, QofBook *dest_book)
+gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
{
gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, dest_book);
@@ -1204,7 +1415,7 @@
* Namespace functions *
************************************************************/
const char *
-gnc_commodity_namespace_get_name (gnc_commodity_namespace *ns)
+gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns)
{
if (ns == NULL)
return NULL;
@@ -1261,7 +1472,7 @@
}
gnc_commodity *
-gnc_commodity_obtain_twin (gnc_commodity *from, QofBook *book)
+gnc_commodity_obtain_twin (const gnc_commodity *from, QofBook *book)
{
gnc_commodity *twin;
const char * ucom;
@@ -1287,7 +1498,7 @@
********************************************************************/
guint
-gnc_commodity_table_get_number_of_namespaces(gnc_commodity_table* tbl)
+gnc_commodity_table_get_number_of_namespaces(const gnc_commodity_table* tbl)
{
g_return_val_if_fail(tbl, 0);
g_return_val_if_fail(tbl->ns_table, 0);
@@ -1312,7 +1523,7 @@
}
guint
-gnc_commodity_table_get_size(gnc_commodity_table* tbl)
+gnc_commodity_table_get_size(const gnc_commodity_table* tbl)
{
guint count = 0;
g_return_val_if_fail(tbl, 0);
Index: src/engine/gnc-commodity.h
===================================================================
--- src/engine/gnc-commodity.h (revision 16730)
+++ src/engine/gnc-commodity.h (working copy)
@@ -149,7 +149,7 @@
* @param sources_list A list of strings containing the source names
* as they are known to F::Q.
*/
-void gnc_quote_source_set_fq_installed (GList *sources_list);
+void gnc_quote_source_set_fq_installed (const GList *sources_list);
/** Return the number of entries for a given type of quote source.
*
@@ -202,7 +202,7 @@
*
* @return TRUE if the user's computer supports this quote source.
*/
-gboolean gnc_quote_source_get_supported (gnc_quote_source *source);
+gboolean gnc_quote_source_get_supported (const gnc_quote_source *source);
/** Given a gnc_quote_source data structure, return the type of this
* particular quote source. (SINGLE, MULTI, UNKNOWN)
@@ -211,7 +211,7 @@
*
* @return The type of this quote source.
*/
-QuoteSourceType gnc_quote_source_get_type (gnc_quote_source *source);
+QuoteSourceType gnc_quote_source_get_type (const gnc_quote_source *source);
/** Given a gnc_quote_source data structure, return the index of this
* particular quote source within its type.
@@ -220,7 +220,7 @@
*
* @return The index of this quote source in its type.
*/
-gint gnc_quote_source_get_index (gnc_quote_source *source);
+gint gnc_quote_source_get_index (const gnc_quote_source *source);
/** Given a gnc_quote_source data structure, return the user friendly
* name of this quote source. E.G. "Yahoo Australia" or "Australia
@@ -230,7 +230,7 @@
*
* @return The user friendly name.
*/
-const char *gnc_quote_source_get_user_name (gnc_quote_source *source);
+const char *gnc_quote_source_get_user_name (const gnc_quote_source *source);
/** Given a gnc_quote_source data structure, return the internal name
* of this quote source. This is the name used by both gnucash and
@@ -240,7 +240,7 @@
*
* @return The internal name.
*/
-const char *gnc_quote_source_get_internal_name (gnc_quote_source *source);
+const char *gnc_quote_source_get_internal_name (const gnc_quote_source *source);
/** Given a gnc_quote_source data structure, return the internal name
* of this quote source. This is the name used by both gnucash and
@@ -254,7 +254,7 @@
*
* @return The internal name.
*/
-const char *gnc_quote_source_get_old_internal_name (gnc_quote_source *source);
+const char *gnc_quote_source_get_old_internal_name (const gnc_quote_source *source);
/** @} */
@@ -309,10 +309,10 @@
void gnc_commodity_destroy(gnc_commodity * cm);
/** Copy src into dest */
-void gnc_commodity_copy(gnc_commodity * dest, gnc_commodity *src);
+void gnc_commodity_copy(gnc_commodity * dest, const gnc_commodity *src);
/** allocate and copy */
-gnc_commodity * gnc_commodity_clone(gnc_commodity *src, QofBook *dest_book);
+gnc_commodity * gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book);
/** @} */
@@ -768,7 +768,7 @@
*
* @return A pointer to the name of the namespace. This string is
* owned by the engine and should not be freed by the caller. */
-const char * gnc_commodity_namespace_get_name (gnc_commodity_namespace *ns) ;
+const char * gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns) ;
/** Return a list of all commodity data structures in the specified namespace.
@@ -785,7 +785,7 @@
*
* @return The number of namespaces. Zero if an invalid argument was
* supplied or there was an error. */
-guint gnc_commodity_table_get_number_of_namespaces(gnc_commodity_table* tbl);
+guint gnc_commodity_table_get_number_of_namespaces(const gnc_commodity_table* tbl);
/** Test to see if the indicated namespace exits in the commodity table.
*
@@ -862,7 +862,7 @@
*
* @return The number of commodities in the table. 0 if there are no
* commodities, or the routine was passed a bad argument. */
-guint gnc_commodity_table_get_size(gnc_commodity_table* tbl);
+guint gnc_commodity_table_get_size(const gnc_commodity_table* tbl);
/** Return a list of all commodities in the commodity table that are
* in the given namespace.
@@ -943,7 +943,7 @@
* the indicated book. This routine is primarily useful for setting
* up clones of things across multiple books.
*/
-gnc_commodity * gnc_commodity_obtain_twin (gnc_commodity *from, QofBook *book);
+gnc_commodity * gnc_commodity_obtain_twin (const gnc_commodity *from, QofBook *book);
/** You should probably not be using gnc_commodity_table_register()
* It is an internal routine for registering the gncObject for the
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel