More conversion to read/write objects from sql backend using gobject parameters

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18766 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2010-02-28 23:19:34 +00:00
parent 1d6e7701ac
commit 45203aec4b
10 changed files with 192 additions and 96 deletions

View File

@ -66,7 +66,7 @@ static const GncSqlColumnTableEntry col_table[] =
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" }, { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
{ "name", CT_STRING, ACCOUNT_MAX_NAME_LEN, COL_NNUL, "name" }, { "name", CT_STRING, ACCOUNT_MAX_NAME_LEN, COL_NNUL, "name" },
{ "account_type", CT_STRING, ACCOUNT_MAX_TYPE_LEN, COL_NNUL, NULL, ACCOUNT_TYPE_ }, { "account_type", CT_STRING, ACCOUNT_MAX_TYPE_LEN, COL_NNUL, NULL, ACCOUNT_TYPE_ },
{ "commodity_guid", CT_COMMODITYREF, 0, 0, "commodity" }, { "commodity_guid", CT_COMMODITYREF, 0, 0, "commodity" },
{ "commodity_scu", CT_INT, 0, COL_NNUL, "commodity-scu" }, { "commodity_scu", CT_INT, 0, COL_NNUL, "commodity-scu" },
{ "non_std_scu", CT_BOOLEAN, 0, COL_NNUL, "non-std-scu" }, { "non_std_scu", CT_BOOLEAN, 0, COL_NNUL, "non-std-scu" },
{ "parent_guid", CT_GUID, 0, 0, NULL, NULL, { "parent_guid", CT_GUID, 0, 0, NULL, NULL,

View File

@ -1805,11 +1805,9 @@ load_numeric( const GncSqlBackend* be, GncSqlRow* row,
gint64 num, denom; gint64 num, denom;
gnc_numeric n; gnc_numeric n;
gboolean isNull = FALSE; gboolean isNull = FALSE;
NumericSetterFunc n_setter = (NumericSetterFunc)setter;
g_return_if_fail( be != NULL ); g_return_if_fail( be != NULL );
g_return_if_fail( row != NULL ); g_return_if_fail( row != NULL );
g_return_if_fail( setter != NULL );
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
@ -1833,7 +1831,12 @@ load_numeric( const GncSqlBackend* be, GncSqlRow* row,
} }
n = gnc_numeric_create( num, denom ); n = gnc_numeric_create( num, denom );
if( !isNull ) { if( !isNull ) {
(*n_setter)( pObject, n ); if( table_row->gobj_param_name != NULL ) {
g_object_set( pObject, table_row->gobj_param_name, &n, NULL );
} else {
NumericSetterFunc n_setter = (NumericSetterFunc)setter;
(*n_setter)( pObject, n );
}
} }
} }
@ -1882,16 +1885,18 @@ add_gvalue_numeric_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
// if( table_row->gobj_param_name != NULL ) { if( table_row->gobj_param_name != NULL ) {
// g_object_get( pObject, table_row->gobj_param_name, &s, NULL ); gnc_numeric *s;
// } else { g_object_get( pObject, table_row->gobj_param_name, &s, NULL );
n = *s;
} else {
getter = (NumericGetterFunc)gnc_sql_get_getter( obj_name, table_row ); getter = (NumericGetterFunc)gnc_sql_get_getter( obj_name, table_row );
if( getter != NULL ) { if( getter != NULL ) {
n = (*getter)( pObject ); n = (*getter)( pObject );
} else { } else {
n = gnc_numeric_zero(); n = gnc_numeric_zero();
} }
// } }
num_value = g_new0( GValue, 1 ); num_value = g_new0( GValue, 1 );
g_assert( num_value != NULL ); g_assert( num_value != NULL );

View File

@ -60,7 +60,7 @@ static const GncSqlColumnTableEntry col_table[] =
{ "date", CT_TIMESPEC, 0, COL_NNUL, NULL, PRICE_DATE }, { "date", CT_TIMESPEC, 0, COL_NNUL, NULL, PRICE_DATE },
{ "source", CT_STRING, PRICE_MAX_SOURCE_LEN, 0, "source" }, { "source", CT_STRING, PRICE_MAX_SOURCE_LEN, 0, "source" },
{ "type", CT_STRING, PRICE_MAX_TYPE_LEN, 0, "type" }, { "type", CT_STRING, PRICE_MAX_TYPE_LEN, 0, "type" },
{ "value", CT_NUMERIC, 0, COL_NNUL, NULL, PRICE_VALUE }, { "value", CT_NUMERIC, 0, COL_NNUL, "value" },
{ NULL } { NULL }
/*@ +full_init_block @*/ /*@ +full_init_block @*/
}; };

View File

@ -55,10 +55,6 @@
#define SX_MAX_NAME_LEN 2048 #define SX_MAX_NAME_LEN 2048
static gboolean get_autocreate( gpointer pObject );
static void set_autocreate( gpointer pObject, gboolean value );
static gboolean get_autonotify( gpointer pObject );
static void set_autonotify( gpointer pObject, gboolean value );
static gint get_instance_count( gpointer pObject ); static gint get_instance_count( gpointer pObject );
static /*@ null @*/ gpointer get_template_act_guid( gpointer pObject ); static /*@ null @*/ gpointer get_template_act_guid( gpointer pObject );
static void set_template_act_guid( gpointer pObject, /*@ null @*/ gpointer pValue ); static void set_template_act_guid( gpointer pObject, /*@ null @*/ gpointer pValue );
@ -74,18 +70,12 @@ static const GncSqlColumnTableEntry col_table[] =
{ "end_date", CT_GDATE, 0, 0, NULL, NULL, { "end_date", CT_GDATE, 0, 0, NULL, NULL,
(QofAccessFunc)xaccSchedXactionGetEndDate, (QofSetterFunc)xaccSchedXactionSetEndDate }, (QofAccessFunc)xaccSchedXactionGetEndDate, (QofSetterFunc)xaccSchedXactionSetEndDate },
{ "last_occur", CT_GDATE, 0, 0, NULL, GNC_SX_LAST_DATE }, { "last_occur", CT_GDATE, 0, 0, NULL, GNC_SX_LAST_DATE },
{ "num_occur", CT_INT, 0, COL_NNUL, NULL, GNC_SX_NUM_OCCUR }, { "num_occur", CT_INT, 0, COL_NNUL, "num-occurance" },
{ "rem_occur", CT_INT, 0, COL_NNUL, NULL, GNC_SX_REM_OCCUR }, { "rem_occur", CT_INT, 0, COL_NNUL, "rem-occurance" },
{ "auto_create", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL, { "auto_create", CT_BOOLEAN, 0, COL_NNUL, "auto-create" },
(QofAccessFunc)get_autocreate, (QofSetterFunc)set_autocreate }, { "auto_notify", CT_BOOLEAN, 0, COL_NNUL, "auto-create-notify" },
{ "auto_notify", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL, { "adv_creation", CT_INT, 0, COL_NNUL, "advance-creation-days" },
(QofAccessFunc)get_autonotify, (QofSetterFunc)set_autonotify }, { "adv_notify", CT_INT, 0, COL_NNUL, "advance-reminder-days" },
{ "adv_creation", CT_INT, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)xaccSchedXactionGetAdvanceCreation,
(QofSetterFunc)xaccSchedXactionSetAdvanceCreation },
{ "adv_notify", CT_INT, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)xaccSchedXactionGetAdvanceReminder,
(QofSetterFunc)xaccSchedXactionSetAdvanceReminder },
{ "instance_count", CT_INT, 0, COL_NNUL, NULL, NULL, { "instance_count", CT_INT, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)get_instance_count, (QofSetterFunc)gnc_sx_set_instance_count }, (QofAccessFunc)get_instance_count, (QofSetterFunc)gnc_sx_set_instance_count },
{ "template_act_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, { "template_act_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
@ -96,66 +86,6 @@ static const GncSqlColumnTableEntry col_table[] =
/* ================================================================= */ /* ================================================================= */
static gboolean
get_autocreate( gpointer pObject )
{
const SchedXaction* pSx;
gboolean autoCreate;
gboolean autoNotify;
g_return_val_if_fail( pObject != NULL, FALSE );
g_return_val_if_fail( GNC_IS_SX(pObject), FALSE );
pSx = GNC_SX(pObject);
xaccSchedXactionGetAutoCreate( pSx, &autoCreate, &autoNotify );
return autoCreate;
}
static void
set_autocreate( gpointer pObject, gboolean value )
{
SchedXaction* pSx;
gboolean autoNotify;
gboolean dummy;
g_return_if_fail( pObject != NULL );
g_return_if_fail( GNC_IS_SX(pObject) );
pSx = GNC_SX(pObject);
xaccSchedXactionGetAutoCreate( pSx, &dummy, &autoNotify );
xaccSchedXactionSetAutoCreate( pSx, value, autoNotify );
}
static gboolean
get_autonotify( gpointer pObject )
{
const SchedXaction* pSx;
gboolean autoCreate;
gboolean autoNotify;
g_return_val_if_fail( pObject != NULL, FALSE );
g_return_val_if_fail( GNC_IS_SX(pObject), FALSE );
pSx = GNC_SX(pObject);
xaccSchedXactionGetAutoCreate( pSx, &autoCreate, &autoNotify );
return autoNotify;
}
static void
set_autonotify( gpointer pObject, gboolean value )
{
SchedXaction* pSx;
gboolean autoCreate;
gboolean dummy;
g_return_if_fail( pObject != NULL );
g_return_if_fail( GNC_IS_SX(pObject) );
pSx = GNC_SX(pObject);
xaccSchedXactionGetAutoCreate( pSx, &autoCreate, &dummy );
xaccSchedXactionSetAutoCreate( pSx, autoCreate, value );
}
static gint static gint
get_instance_count( gpointer pObject ) get_instance_count( gpointer pObject )
{ {

View File

@ -108,8 +108,8 @@ static const GncSqlColumnTableEntry split_col_table[] =
(QofAccessFunc)get_split_reconcile_state, set_split_reconcile_state }, (QofAccessFunc)get_split_reconcile_state, set_split_reconcile_state },
{ "reconcile_date", CT_TIMESPEC, 0, 0, NULL, NULL, { "reconcile_date", CT_TIMESPEC, 0, 0, NULL, NULL,
(QofAccessFunc)xaccSplitRetDateReconciledTS, (QofSetterFunc)set_split_reconcile_date }, (QofAccessFunc)xaccSplitRetDateReconciledTS, (QofSetterFunc)set_split_reconcile_date },
{ "value", CT_NUMERIC, 0, COL_NNUL, NULL, SPLIT_VALUE }, { "value", CT_NUMERIC, 0, COL_NNUL, "value" },
{ "quantity", CT_NUMERIC, 0, COL_NNUL, NULL, SPLIT_AMOUNT }, { "quantity", CT_NUMERIC, 0, COL_NNUL, "amount" },
{ "lot_guid", CT_LOTREF, 0, 0, NULL, NULL, { "lot_guid", CT_LOTREF, 0, 0, NULL, NULL,
(QofAccessFunc)xaccSplitGetLot, set_split_lot }, (QofAccessFunc)xaccSplitGetLot, set_split_lot },
{ NULL } { NULL }

View File

@ -461,8 +461,6 @@ gnc_account_set_property (GObject *object,
} }
} }
static void static void
gnc_account_class_init (AccountClass *klass) gnc_account_class_init (AccountClass *klass)
{ {

View File

@ -46,7 +46,13 @@ void sxprivtransactionListMapDelete( gpointer data, gpointer user_data );
enum { enum {
PROP_0, PROP_0,
PROP_NAME PROP_NAME,
PROP_NUM_OCCURANCE,
PROP_REM_OCCURANCE,
PROP_AUTO_CREATE,
PROP_AUTO_CREATE_NOTIFY,
PROP_ADVANCE_CREATION_DAYS,
PROP_ADVANCE_REMINDER_DAYS
}; };
/* GObject initialization */ /* GObject initialization */
@ -98,6 +104,24 @@ gnc_schedxaction_get_property (GObject *object,
case PROP_NAME: case PROP_NAME:
g_value_set_string(value, sx->name); g_value_set_string(value, sx->name);
break; break;
case PROP_NUM_OCCURANCE:
g_value_set_int(value, sx->num_occurances_total);
break;
case PROP_REM_OCCURANCE:
g_value_set_int(value, sx->num_occurances_remain);
break;
case PROP_AUTO_CREATE:
g_value_set_boolean(value, sx->autoCreateOption);
break;
case PROP_AUTO_CREATE_NOTIFY:
g_value_set_boolean(value, sx->autoCreateNotify);
break;
case PROP_ADVANCE_CREATION_DAYS:
g_value_set_int(value, sx->advanceCreateDays);
break;
case PROP_ADVANCE_REMINDER_DAYS:
g_value_set_int(value, sx->advanceRemindDays);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -119,6 +143,24 @@ gnc_schedxaction_set_property (GObject *object,
case PROP_NAME: case PROP_NAME:
xaccSchedXactionSetName(sx, g_value_get_string(value)); xaccSchedXactionSetName(sx, g_value_get_string(value));
break; break;
case PROP_NUM_OCCURANCE:
xaccSchedXactionSetNumOccur(sx, g_value_get_int(value));
break;
case PROP_REM_OCCURANCE:
xaccSchedXactionSetRemOccur(sx, g_value_get_int(value));
break;
case PROP_AUTO_CREATE:
xaccSchedXactionSetAutoCreate(sx, g_value_get_boolean(value), sx->autoCreateNotify);
break;
case PROP_AUTO_CREATE_NOTIFY:
xaccSchedXactionSetAutoCreate(sx, sx->autoCreateOption, g_value_get_boolean(value));
break;
case PROP_ADVANCE_CREATION_DAYS:
xaccSchedXactionSetAdvanceCreation(sx, g_value_get_int(value));
break;
case PROP_ADVANCE_REMINDER_DAYS:
xaccSchedXactionSetAdvanceReminder(sx, g_value_get_int(value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -146,6 +188,70 @@ gnc_schedxaction_class_init (SchedXactionClass *klass)
"that is displayed by the GUI.", "that is displayed by the GUI.",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_NUM_OCCURANCE,
g_param_spec_int ("num-occurance",
"Number of occurances",
"Total number of occurances for this scheduled transaction.",
0,
G_MAXINT16,
1,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_REM_OCCURANCE,
g_param_spec_int ("rem-occurance",
"Number of occurances remaining",
"Remaining number of occurances for this scheduled transaction.",
0,
G_MAXINT16,
1,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_AUTO_CREATE,
g_param_spec_boolean ("auto-create",
"Auto-create",
"TRUE if the transaction will be automatically "
"created when its time comes.",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_AUTO_CREATE_NOTIFY,
g_param_spec_boolean ("auto-create-notify",
"Auto-create-notify",
"TRUE if the the user will be notified when the transaction "
"is automatically created.",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_ADVANCE_CREATION_DAYS,
g_param_spec_int ("advance-creation-days",
"Days in advance to create",
"Number of days in advance to create this scheduled transaction.",
0,
G_MAXINT16,
0,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_ADVANCE_REMINDER_DAYS,
g_param_spec_int ("advance-reminder-days",
"Days in advance to remind",
"Number of days in advance to remind about this scheduled transaction.",
0,
G_MAXINT16,
0,
G_PARAM_READWRITE));
} }
static void static void

View File

@ -62,7 +62,9 @@ static QofLogModule log_module = GNC_MOD_ENGINE;
enum { enum {
PROP_0, PROP_0,
PROP_ACTION, PROP_ACTION,
PROP_MEMO PROP_MEMO,
PROP_VALUE,
PROP_AMOUNT
}; };
/* GObject Initialization */ /* GObject Initialization */
@ -124,6 +126,12 @@ gnc_split_get_property(GObject *object,
case PROP_MEMO: case PROP_MEMO:
g_value_set_string(value, split->memo); g_value_set_string(value, split->memo);
break; break;
case PROP_VALUE:
g_value_set_boxed(value, &split->value);
break;
case PROP_AMOUNT:
g_value_set_boxed(value, &split->amount);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -137,6 +145,7 @@ gnc_split_set_property(GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
Split *split; Split *split;
gnc_numeric* number;
g_return_if_fail(GNC_IS_SPLIT(object)); g_return_if_fail(GNC_IS_SPLIT(object));
@ -148,6 +157,14 @@ gnc_split_set_property(GObject *object,
case PROP_MEMO: case PROP_MEMO:
xaccSplitSetMemo(split, g_value_get_string(value)); xaccSplitSetMemo(split, g_value_get_string(value));
break; break;
case PROP_VALUE:
number = g_value_get_boxed(value);
xaccSplitSetValue(split, *number);
break;
case PROP_AMOUNT:
number = g_value_get_boxed(value);
xaccSplitSetAmount(split, *number);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -187,6 +204,28 @@ gnc_split_class_init(SplitClass* klass)
"this split.", "this split.",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_VALUE,
g_param_spec_boxed("value",
"Split Value",
"The value for this split in the common currency. "
"The value and the amount provide enough information to "
"calculate a conversion rate.",
GNC_TYPE_NUMERIC,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_AMOUNT,
g_param_spec_boxed("amount",
"Split Amount",
"The value for this split in the currency of its account. "
"The value and the amount provide enough information to "
"calculate a conversion rate.",
GNC_TYPE_NUMERIC,
G_PARAM_READWRITE));
} }
/********************************************************************\ /********************************************************************\

View File

@ -38,7 +38,8 @@ static gboolean remove_price(GNCPriceDB *db, GNCPrice *p, gboolean cleanup);
enum { enum {
PROP_0, PROP_0,
PROP_SOURCE, PROP_SOURCE,
PROP_TYPE PROP_TYPE,
PROP_VALUE
}; };
/* GObject Initialization */ /* GObject Initialization */
@ -80,6 +81,9 @@ gnc_price_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec
case PROP_TYPE: case PROP_TYPE:
g_value_set_string(value, price->type); g_value_set_string(value, price->type);
break; break;
case PROP_VALUE:
g_value_set_boxed(value, &price->value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -90,6 +94,7 @@ static void
gnc_price_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) gnc_price_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
{ {
GNCPrice* price; GNCPrice* price;
gnc_numeric* number;
g_return_if_fail(GNC_IS_PRICE(object)); g_return_if_fail(GNC_IS_PRICE(object));
@ -101,6 +106,10 @@ gnc_price_set_property(GObject* object, guint prop_id, const GValue* value, GPar
case PROP_TYPE: case PROP_TYPE:
gnc_price_set_typestr(price, g_value_get_string(value)); gnc_price_set_typestr(price, g_value_get_string(value));
break; break;
case PROP_VALUE:
number = g_value_get_boxed(value);
gnc_price_set_value(price, *number);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -139,6 +148,15 @@ gnc_price_class_init(GNCPriceClass *klass)
"are 'bid', 'ask', 'last', 'nav' and 'unknown'.", "are 'bid', 'ask', 'last', 'nav' and 'unknown'.",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_VALUE,
g_param_spec_boxed("value",
"Value",
"The value of the price quote.",
GNC_TYPE_NUMERIC,
G_PARAM_READWRITE));
} }
/* ==================================================================== */ /* ==================================================================== */

View File

@ -1048,11 +1048,11 @@
account-balances) account-balances)
total)) total))
;; Adds "file://" to the beginning of a URL if it doesn't already exist ;; Adds "file:///" to the beginning of a URL if it doesn't already exist
;; ;;
;; @param url URL ;; @param url URL
;; @return URL with "file://" as the URL type if it isn't already there ;; @return URL with "file:///" as the URL type if it isn't already there
(define (make-file-url url) (define (make-file-url url)
(if (string-prefix? "file://" url) (if (string-prefix? "file:///" url)
url url
(string-append "file://" url))) (string-append "file:///" url)))