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.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18762 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2010-02-28 17:35:53 +00:00
parent ce7f2889b9
commit 181286c970
4 changed files with 408 additions and 73 deletions

View File

@ -44,32 +44,17 @@
void sxprivtransactionListMapDelete( gpointer data, gpointer user_data ); void sxprivtransactionListMapDelete( gpointer data, gpointer user_data );
enum {
PROP_0,
PROP_NAME
};
/* GObject initialization */ /* GObject initialization */
QOF_GOBJECT_IMPL(gnc_schedxaction, SchedXaction, QOF_TYPE_INSTANCE); G_DEFINE_TYPE(SchedXaction, gnc_schedxaction, QOF_TYPE_INSTANCE);
static void static void
gnc_schedxaction_init(SchedXaction* sx) gnc_schedxaction_init(SchedXaction* sx)
{ {
}
static void
gnc_schedxaction_dispose_real (GObject *sxp)
{
}
static void
gnc_schedxaction_finalize_real(GObject* sxp)
{
}
static void
xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
{
Account *ra;
const GUID *guid;
qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);
sx->schedule = NULL; sx->schedule = NULL;
g_date_clear( &sx->last_date, 1 ); g_date_clear( &sx->last_date, 1 );
@ -84,6 +69,92 @@ xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
sx->advanceRemindDays = 0; sx->advanceRemindDays = 0;
sx->instance_num = 0; sx->instance_num = 0;
sx->deferredList = NULL; sx->deferredList = NULL;
}
static void
gnc_schedxaction_dispose(GObject *sxp)
{
G_OBJECT_CLASS(gnc_schedxaction_parent_class)->dispose(sxp);
}
static void
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;
const GUID *guid;
qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);
/* create a new template account for our splits */ /* create a new template account for our splits */
sx->template_acct = xaccMallocAccount(book); sx->template_acct = xaccMallocAccount(book);

View File

@ -59,31 +59,17 @@ const char *void_former_val_str = "void-former-value";
/* This static indicates the debugging module that this .o belongs to. */ /* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_ENGINE; static QofLogModule log_module = GNC_MOD_ENGINE;
enum {
PROP_0,
PROP_ACTION,
PROP_MEMO
};
/* GObject Initialization */ /* GObject Initialization */
QOF_GOBJECT_IMPL(gnc_split, Split, QOF_TYPE_INSTANCE); G_DEFINE_TYPE(Split, gnc_split, QOF_TYPE_INSTANCE)
static void static void
gnc_split_init(Split* split) 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 */ /* fill in some sane defaults */
split->acc = NULL; split->acc = NULL;
@ -106,7 +92,111 @@ xaccInitSplit(Split * split, QofBook *book)
split->gains = GAINS_STATUS_UNKNOWN; split->gains = GAINS_STATUS_UNKNOWN;
split->gains_split = NULL; 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); qof_instance_init_data(&split->inst, GNC_ID_SPLIT, book);
} }

View File

@ -186,6 +186,12 @@ const char *void_former_notes_str = "void-former-notes";
/* This static indicates the debugging module that this .o belongs to. */ /* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_ENGINE; static QofLogModule log_module = GNC_MOD_ENGINE;
enum {
PROP_0,
PROP_NUM,
PROP_DESCRIPTION
};
void check_open (const Transaction *trans) void check_open (const Transaction *trans)
{ {
if (trans && 0 >= qof_instance_get_editlevel(trans)) if (trans && 0 >= qof_instance_get_editlevel(trans))
@ -241,31 +247,10 @@ void gen_event_trans (Transaction *trans)
} }
/* GObject Initialization */ /* GObject Initialization */
QOF_GOBJECT_IMPL(gnc_transaction, Transaction, QOF_TYPE_INSTANCE); G_DEFINE_TYPE(Transaction, gnc_transaction, QOF_TYPE_INSTANCE)
static void static void
gnc_transaction_init(Transaction* txn) gnc_transaction_init(Transaction* trans)
{
}
static void
gnc_transaction_dispose_real (GObject *txnp)
{
}
static void
gnc_transaction_finalize_real(GObject* txnp)
{
}
/********************************************************************\
* xaccInitTransaction
* Initialize a transaction structure
\********************************************************************/
static void
xaccInitTransaction (Transaction * trans, QofBook *book)
{ {
ENTER ("trans=%p", trans); ENTER ("trans=%p", trans);
/* Fill in some sane defaults */ /* Fill in some sane defaults */
@ -283,7 +268,113 @@ xaccInitTransaction (Transaction * trans, QofBook *book)
trans->marker = 0; trans->marker = 0;
trans->orig = NULL; trans->orig = NULL;
LEAVE (" ");
}
static void
gnc_transaction_dispose(GObject *txnp)
{
G_OBJECT_CLASS(gnc_transaction_parent_class)->dispose(txnp);
}
static void
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
\********************************************************************/
static void
xaccInitTransaction (Transaction * trans, QofBook *book)
{
ENTER ("trans=%p", trans);
qof_instance_init_data (&trans->inst, GNC_ID_TRANS, book); qof_instance_init_data (&trans->inst, GNC_ID_TRANS, book);
LEAVE (" "); LEAVE (" ");
} }

View File

@ -35,22 +35,110 @@ static QofLogModule log_module = GNC_MOD_PRICE;
static gboolean add_price(GNCPriceDB *db, GNCPrice *p); static gboolean add_price(GNCPriceDB *db, GNCPrice *p);
static gboolean remove_price(GNCPriceDB *db, GNCPrice *p, gboolean cleanup); static gboolean remove_price(GNCPriceDB *db, GNCPrice *p, gboolean cleanup);
enum {
PROP_0,
PROP_SOURCE,
PROP_TYPE
};
/* GObject Initialization */ /* GObject Initialization */
QOF_GOBJECT_IMPL(gnc_price, GNCPrice, QOF_TYPE_INSTANCE); G_DEFINE_TYPE(GNCPrice, gnc_price, QOF_TYPE_INSTANCE);
static void static void
gnc_price_init(GNCPrice* price) gnc_price_init(GNCPrice* price)
{ {
price->refcount = 1;
price->value = gnc_numeric_zero();
price->type = NULL;
price->source = NULL;
} }
static void static void
gnc_price_dispose_real (GObject *pricep) gnc_price_dispose(GObject *pricep)
{ {
G_OBJECT_CLASS(gnc_price_parent_class)->dispose(pricep);
} }
static void 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));
} }
/* ==================================================================== */ /* ==================================================================== */
@ -67,11 +155,6 @@ gnc_price_create (QofBook *book)
p = g_object_new(GNC_TYPE_PRICE, NULL); 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_instance_init_data (&p->inst, GNC_ID_PRICE, book);
qof_event_gen (&p->inst, QOF_EVENT_CREATE, NULL); qof_event_gen (&p->inst, QOF_EVENT_CREATE, NULL);