r18762 - gnucash/trunk/src/engine - Add a few gobject properties to some engine object types. This adds more of the gobject infrastructure to Transaction, Split, SchedXaction and GNCPrice. Gobject properties provides a standardized interface to the engine objects which should allow standard and simplified read/write mechanisms. For the sql backend, for example, db columns can be mapped to properties. In a generalized csv importer, csv columns can be mapped to properties.

Phil Longstaff plongstaff at code.gnucash.org
Sun Feb 28 12:35:54 EST 2010


Author: plongstaff
Date: 2010-02-28 12:35:53 -0500 (Sun, 28 Feb 2010)
New Revision: 18762
Trac: http://svn.gnucash.org/trac/changeset/18762

Modified:
   gnucash/trunk/src/engine/SchedXaction.c
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/gnc-pricedb.c
Log:
Add a few gobject properties to some engine object types.  This adds more of the gobject infrastructure to Transaction, Split, SchedXaction and GNCPrice.  Gobject properties provides a standardized interface to the engine objects which should allow standard and simplified read/write mechanisms.  For the sql backend, for example, db columns can be mapped to properties.  In a generalized csv importer, csv columns can be mapped to properties.


Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c	2010-02-28 13:56:59 UTC (rev 18761)
+++ gnucash/trunk/src/engine/SchedXaction.c	2010-02-28 17:35:53 UTC (rev 18762)
@@ -44,25 +44,111 @@
 
 void sxprivtransactionListMapDelete( gpointer data, gpointer user_data );
 
+enum {
+    PROP_0,
+	PROP_NAME
+};
+
 /* GObject initialization */
-QOF_GOBJECT_IMPL(gnc_schedxaction, SchedXaction, QOF_TYPE_INSTANCE);
+G_DEFINE_TYPE(SchedXaction, gnc_schedxaction, QOF_TYPE_INSTANCE);
 
 static void
 gnc_schedxaction_init(SchedXaction* sx)
 {
+   sx->schedule = NULL;
+
+   g_date_clear( &sx->last_date, 1 );
+   g_date_clear( &sx->start_date, 1 );
+   g_date_clear( &sx->end_date, 1 );
+
+   sx->enabled = 1;
+   sx->num_occurances_total = 0;
+   sx->autoCreateOption = FALSE;
+   sx->autoCreateNotify = FALSE;
+   sx->advanceCreateDays = 0;
+   sx->advanceRemindDays = 0;
+   sx->instance_num = 0;
+   sx->deferredList = NULL;
 }
 
 static void
-gnc_schedxaction_dispose_real (GObject *sxp)
+gnc_schedxaction_dispose(GObject *sxp)
 {
+    G_OBJECT_CLASS(gnc_schedxaction_parent_class)->dispose(sxp);
 }
 
 static void
-gnc_schedxaction_finalize_real(GObject* sxp)
+gnc_schedxaction_finalize(GObject* sxp)
 {
+    G_OBJECT_CLASS(gnc_schedxaction_parent_class)->finalize(sxp);
 }
 
 static void
+gnc_schedxaction_get_property (GObject         *object,
+			  guint            prop_id,
+			  GValue          *value,
+			  GParamSpec      *pspec)
+{
+    SchedXaction *sx;
+
+    g_return_if_fail(GNC_IS_SCHEDXACTION(object));
+
+    sx = GNC_SCHEDXACTION(object);
+	switch(prop_id) {
+	case PROP_NAME:
+	    g_value_set_string(value, sx->name);
+		break;
+	default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+	    break;
+    }
+}
+
+static void
+gnc_schedxaction_set_property (GObject         *object,
+			  guint            prop_id,
+			  const GValue     *value,
+			  GParamSpec      *pspec)
+{
+    SchedXaction *sx;
+
+    g_return_if_fail(GNC_IS_SCHEDXACTION(object));
+
+    sx = GNC_SCHEDXACTION(object);
+	switch(prop_id) {
+	case PROP_NAME:
+	    xaccSchedXactionSetName(sx, g_value_get_string(value));
+		break;
+	default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+	    break;
+    }
+}
+
+static void
+gnc_schedxaction_class_init (SchedXactionClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+	
+    gobject_class->dispose = gnc_schedxaction_dispose;
+    gobject_class->finalize = gnc_schedxaction_finalize;
+    gobject_class->set_property = gnc_schedxaction_set_property;
+    gobject_class->get_property = gnc_schedxaction_get_property;
+
+    g_object_class_install_property
+	(gobject_class,
+	 PROP_NAME,
+	 g_param_spec_string ("name",
+			      "Scheduled Transaction Name",
+			      "The name is an arbitrary string "
+			      "assigned by the user.  It is intended to "
+			      "a short, 5 to 30 character long string "
+			      "that is displayed by the GUI.",
+			      NULL,
+			      G_PARAM_READWRITE));
+}
+
+static void
 xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
 {
    Account        *ra;
@@ -70,21 +156,6 @@
 
    qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);
 
-   sx->schedule = NULL;
-
-   g_date_clear( &sx->last_date, 1 );
-   g_date_clear( &sx->start_date, 1 );
-   g_date_clear( &sx->end_date, 1 );
-
-   sx->enabled = 1;
-   sx->num_occurances_total = 0;
-   sx->autoCreateOption = FALSE;
-   sx->autoCreateNotify = FALSE;
-   sx->advanceCreateDays = 0;
-   sx->advanceRemindDays = 0;
-   sx->instance_num = 0;
-   sx->deferredList = NULL;
-
    /* create a new template account for our splits */
    sx->template_acct = xaccMallocAccount(book);
    guid = qof_instance_get_guid( sx );

Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2010-02-28 13:56:59 UTC (rev 18761)
+++ gnucash/trunk/src/engine/Split.c	2010-02-28 17:35:53 UTC (rev 18762)
@@ -59,32 +59,18 @@
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_ENGINE;
 
+enum {
+    PROP_0,
+	PROP_ACTION,
+	PROP_MEMO
+};
+
 /* GObject Initialization */
-QOF_GOBJECT_IMPL(gnc_split, Split, QOF_TYPE_INSTANCE);
+G_DEFINE_TYPE(Split, gnc_split, QOF_TYPE_INSTANCE)
 
 static void
 gnc_split_init(Split* split)
 {
-}
-
-static void
-gnc_split_dispose_real (GObject *splitp)
-{
-}
-
-static void
-gnc_split_finalize_real(GObject* splitp)
-{
-}
-
-/********************************************************************\
- * xaccInitSplit
- * Initialize a Split structure
-\********************************************************************/
-
-static void
-xaccInitSplit(Split * split, QofBook *book)
-{
   /* fill in some sane defaults */
   split->acc         = NULL;
   split->orig_acc    = NULL;
@@ -106,7 +92,111 @@
 
   split->gains = GAINS_STATUS_UNKNOWN;
   split->gains_split = NULL;
+}
 
+static void
+gnc_split_dispose(GObject *splitp)
+{
+    G_OBJECT_CLASS(gnc_split_parent_class)->dispose(splitp);
+}
+
+static void
+gnc_split_finalize(GObject* splitp)
+{
+    G_OBJECT_CLASS(gnc_split_parent_class)->finalize(splitp);
+}
+
+static void
+gnc_split_get_property(GObject         *object,
+			  guint            prop_id,
+			  GValue          *value,
+			  GParamSpec      *pspec)
+{
+    Split *split;
+
+    g_return_if_fail(GNC_IS_SPLIT(object));
+
+    split = GNC_SPLIT(object);
+    switch (prop_id) {
+	case PROP_ACTION:
+	    g_value_set_string(value, split->action);
+		break;
+	case PROP_MEMO:
+	    g_value_set_string(value, split->memo);
+		break;
+	default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+	    break;
+	}
+}
+
+static void
+gnc_split_set_property(GObject         *object,
+			  guint            prop_id,
+			  const GValue     *value,
+			  GParamSpec      *pspec)
+{
+    Split *split;
+
+    g_return_if_fail(GNC_IS_SPLIT(object));
+
+    split = GNC_SPLIT(object);
+    switch (prop_id) {
+	case PROP_ACTION:
+	    xaccSplitSetAction(split, g_value_get_string(value));
+		break;
+	case PROP_MEMO:
+	    xaccSplitSetMemo(split, g_value_get_string(value));
+		break;
+	default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+	    break;
+	}
+}
+
+static void
+gnc_split_class_init(SplitClass* klass)
+{
+    GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->dispose = gnc_split_dispose;
+    gobject_class->finalize = gnc_split_finalize;
+    gobject_class->set_property = gnc_split_set_property;
+    gobject_class->get_property = gnc_split_get_property;
+
+	g_object_class_install_property
+	(gobject_class,
+	 PROP_ACTION,
+	 g_param_spec_string("action",
+	                     "Action",
+						 "The action is an arbitrary string assigned "
+						 "by the user.  It is intended to be a short "
+						 "string that contains extra information about "
+						 "this split.",
+						 NULL,
+						 G_PARAM_READWRITE));
+
+	g_object_class_install_property
+	(gobject_class,
+	 PROP_MEMO,
+	 g_param_spec_string("memo",
+	                     "Memo",
+						 "The action is an arbitrary string assigned "
+						 "by the user.  It is intended to be a short "
+						 "string that describes the purpose of "
+						 "this split.",
+						 NULL,
+						 G_PARAM_READWRITE));
+}
+
+/********************************************************************\
+ * xaccInitSplit
+ * Initialize a Split structure
+\********************************************************************/
+
+static void
+xaccInitSplit(Split * split, QofBook *book)
+{
   qof_instance_init_data(&split->inst, GNC_ID_SPLIT, book);
 }
 

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2010-02-28 13:56:59 UTC (rev 18761)
+++ gnucash/trunk/src/engine/Transaction.c	2010-02-28 17:35:53 UTC (rev 18762)
@@ -186,6 +186,12 @@
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_ENGINE;
 
+enum {
+  PROP_0,
+  PROP_NUM,
+  PROP_DESCRIPTION
+};
+
 void check_open (const Transaction *trans)
 {
   if (trans && 0 >= qof_instance_get_editlevel(trans))
@@ -241,24 +247,125 @@
 }
 
 /* GObject Initialization */
-QOF_GOBJECT_IMPL(gnc_transaction, Transaction, QOF_TYPE_INSTANCE);
+G_DEFINE_TYPE(Transaction, gnc_transaction, QOF_TYPE_INSTANCE)
 
 static void
-gnc_transaction_init(Transaction* txn)
+gnc_transaction_init(Transaction* trans)
 {
+  ENTER ("trans=%p", trans);
+  /* Fill in some sane defaults */
+  trans->num         = CACHE_INSERT("");
+  trans->description = CACHE_INSERT("");
+
+  trans->common_currency = NULL;
+  trans->splits = NULL;
+
+  trans->date_entered.tv_sec  = 0;
+  trans->date_entered.tv_nsec = 0;
+
+  trans->date_posted.tv_sec  = 0;
+  trans->date_posted.tv_nsec = 0;
+
+  trans->marker = 0;
+  trans->orig = NULL;
+  LEAVE (" ");
 }
 
 static void
-gnc_transaction_dispose_real (GObject *txnp)
+gnc_transaction_dispose(GObject *txnp)
 {
+    G_OBJECT_CLASS(gnc_transaction_parent_class)->dispose(txnp);
 }
 
 static void
-gnc_transaction_finalize_real(GObject* txnp)
+gnc_transaction_finalize(GObject* txnp)
 {
+    G_OBJECT_CLASS(gnc_transaction_parent_class)->finalize(txnp);
 }
 
+static void
+gnc_transaction_get_property(GObject* object,
+                            guint prop_id,
+							GValue* value,
+							GParamSpec* pspec)
+{
+    Transaction* tx;
 
+	g_return_if_fail(GNC_IS_TRANSACTION(object));
+
+	tx = GNC_TRANSACTION(object);
+	switch(prop_id) {
+	case PROP_NUM:
+        g_value_set_string(value, tx->num);
+		break;
+	case PROP_DESCRIPTION:
+        g_value_set_string(value, tx->description);
+		break;
+    default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+	}
+}
+
+static void
+gnc_transaction_set_property(GObject* object,
+							guint prop_id,
+							const GValue* value,
+							GParamSpec* pspec)
+{
+    Transaction* tx;
+
+	g_return_if_fail(GNC_IS_TRANSACTION(object));
+
+	tx = GNC_TRANSACTION(object);
+	switch(prop_id) {
+	case PROP_NUM:
+        xaccTransSetNum( tx, g_value_get_string(value));
+		break;
+	case PROP_DESCRIPTION:
+        xaccTransSetDescription(tx, g_value_get_string(value));
+		break;
+    default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+	}
+}
+
+static void
+gnc_transaction_class_init(TransactionClass* klass)
+{
+    GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
+
+	gobject_class->dispose = gnc_transaction_dispose;
+	gobject_class->finalize = gnc_transaction_finalize;
+	gobject_class->set_property = gnc_transaction_set_property;
+	gobject_class->get_property = gnc_transaction_get_property;
+
+	g_object_class_install_property
+	 (gobject_class,
+	 PROP_NUM,
+	 g_param_spec_string("num",
+	                     "Transaction Number",
+						 "The transactionNumber is an arbitrary string "
+						 "assigned by the user.  It is intended to be "
+						 "a short 1-6 character string that is displayed "
+						 "by the register.  For checks, it is usually the "
+						 "check number.  For other types of transactions, "
+						 "it can be any string.",
+						 NULL,
+						 G_PARAM_READWRITE));
+
+	g_object_class_install_property
+	 (gobject_class,
+	 PROP_DESCRIPTION,
+	 g_param_spec_string("description",
+	                     "Transaction Description",
+						 "The transaction description is an arbitrary string "
+						 "assigned by the user.  It is usually the customer, "
+						 "vendor or other organization associated with the "
+						 "transaction.",
+						 NULL,
+						 G_PARAM_READWRITE));
+}
+
 /********************************************************************\
  * xaccInitTransaction
  * Initialize a transaction structure
@@ -268,22 +375,6 @@
 xaccInitTransaction (Transaction * trans, QofBook *book)
 {
   ENTER ("trans=%p", trans);
-  /* Fill in some sane defaults */
-  trans->num         = CACHE_INSERT("");
-  trans->description = CACHE_INSERT("");
-
-  trans->common_currency = NULL;
-  trans->splits = NULL;
-
-  trans->date_entered.tv_sec  = 0;
-  trans->date_entered.tv_nsec = 0;
-
-  trans->date_posted.tv_sec  = 0;
-  trans->date_posted.tv_nsec = 0;
-
-  trans->marker = 0;
-  trans->orig = NULL;
-
   qof_instance_init_data (&trans->inst, GNC_ID_TRANS, book);
   LEAVE (" ");
 }

Modified: gnucash/trunk/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb.c	2010-02-28 13:56:59 UTC (rev 18761)
+++ gnucash/trunk/src/engine/gnc-pricedb.c	2010-02-28 17:35:53 UTC (rev 18762)
@@ -35,24 +35,112 @@
 static gboolean add_price(GNCPriceDB *db, GNCPrice *p);
 static gboolean remove_price(GNCPriceDB *db, GNCPrice *p, gboolean cleanup);
 
+enum {
+    PROP_0,
+	PROP_SOURCE,
+	PROP_TYPE
+};
+
 /* GObject Initialization */
-QOF_GOBJECT_IMPL(gnc_price, GNCPrice, QOF_TYPE_INSTANCE);
+G_DEFINE_TYPE(GNCPrice, gnc_price, QOF_TYPE_INSTANCE);
 
 static void
 gnc_price_init(GNCPrice* price)
 {
+  price->refcount = 1;
+  price->value = gnc_numeric_zero();
+  price->type = NULL;
+  price->source = NULL;
 }
 
 static void
-gnc_price_dispose_real (GObject *pricep)
+gnc_price_dispose(GObject *pricep)
 {
+    G_OBJECT_CLASS(gnc_price_parent_class)->dispose(pricep);
 }
 
 static void
-gnc_price_finalize_real(GObject* pricep)
+gnc_price_finalize(GObject* pricep)
 {
+    G_OBJECT_CLASS(gnc_price_parent_class)->finalize(pricep);
 }
 
+static void
+gnc_price_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
+{
+    GNCPrice* price;
+
+	g_return_if_fail(GNC_IS_PRICE(object));
+
+	price = GNC_PRICE(object);
+	switch (prop_id) {
+	case PROP_SOURCE:
+	    g_value_set_string(value, price->source);
+        break;
+	case PROP_TYPE:
+	    g_value_set_string(value, price->type);
+        break;
+	default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+	    break;
+    }
+}
+
+static void
+gnc_price_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
+{
+    GNCPrice* price;
+
+	g_return_if_fail(GNC_IS_PRICE(object));
+
+	price = GNC_PRICE(object);
+	switch (prop_id) {
+	case PROP_SOURCE:
+	    gnc_price_set_source(price, g_value_get_string(value));
+        break;
+	case PROP_TYPE:
+	    gnc_price_set_typestr(price, g_value_get_string(value));
+        break;
+	default:
+	    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+	    break;
+    }
+}
+
+static void
+gnc_price_class_init(GNCPriceClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+	
+    gobject_class->dispose = gnc_price_dispose;
+    gobject_class->finalize = gnc_price_finalize;
+    gobject_class->set_property = gnc_price_set_property;
+    gobject_class->get_property = gnc_price_get_property;
+
+    g_object_class_install_property
+	(gobject_class,
+	 PROP_SOURCE,
+	 g_param_spec_string ("source",
+			      "Price source",
+			      "The price source is a string describing the "
+				  "source of a price quote.  It will be something "
+				  "like this: 'Finance::Quote', 'user:misc', "
+				  "'user:foo', etc.",
+			      NULL,
+			      G_PARAM_READWRITE));
+
+    g_object_class_install_property
+	(gobject_class,
+	 PROP_TYPE,
+	 g_param_spec_string ("type",
+			      "Quote type",
+			      "The quote type is a string describing the "
+				  "type of a price quote.  Types possible now "
+				  "are 'bid', 'ask', 'last', 'nav' and 'unknown'.",
+			      NULL,
+				  G_PARAM_READWRITE));
+}
+
 /* ==================================================================== */
 /* GNCPrice functions
  */
@@ -67,11 +155,6 @@
 
   p = g_object_new(GNC_TYPE_PRICE, NULL);
 
-  p->refcount = 1;
-  p->value = gnc_numeric_zero();
-  p->type = NULL;
-  p->source = NULL;
-
   qof_instance_init_data (&p->inst, GNC_ID_PRICE, book);
   qof_event_gen (&p->inst, QOF_EVENT_CREATE, NULL);
 



More information about the gnucash-changes mailing list