Files | |
| file | qofgobj.h |
| QOF to GLib GObject mapping. | |
Functions | |
| void | qof_gobject_init (void) |
| void | qof_gobject_shutdown (void) |
| void | qof_gobject_register (QofType type, GObjectClass *obclass) |
| void | qof_gobject_register_instance (QofBook *book, QofType, GObject *) |
XXX Only GObject properties are searchable, data and other hanging off the GObject is not. Fix this. This needs fixing.
| void qof_gobject_init | ( | void | ) |
Initalize and shut down this subsystem.
Definition at line 46 of file qofgobj.c.
00047 { 00048 if (initialized) return; 00049 initialized = TRUE; 00050 00051 // gobjectClassTable = g_hash_table_new (g_str_hash, g_str_equal); 00052 00053 /* Init the other subsystems that we need */ 00054 qof_object_initialize(); 00055 qof_query_init (); 00056 }
| void qof_gobject_register | ( | QofType | type, | |
| GObjectClass * | obclass | |||
| ) |
Register a GObject class with the QOF subsystem. Doing this will make the properties associated with this GObject searchable using the QOF subsystem.
The QofType can be any string you desire, although typically you might want to set it to G_OBJECT_CLASS_NAME() of the object class. Note that this type will become the name of the "table" that is searched by SQL queries: e.g. in order to be able to say "SELECT * FROM MyStuff;" you must first say: qof_gobject_register ("MyStuff", gobj_class);
Definition at line 214 of file qofgobj.c.
00215 { 00216 int i; 00217 int j; 00218 QofParam *qof_param_list, *qpar; 00219 QofObject *class_def; 00220 GParamSpec **prop_list, *gparam; 00221 guint n_props; 00222 00223 /* Get the GObject properties, convert to QOF properties */ 00224 prop_list = g_object_class_list_properties (obclass, &n_props); 00225 00226 qof_param_list = g_new0 (QofParam, n_props); 00227 paramList = g_slist_prepend (paramList, qof_param_list); 00228 00229 PINFO ("object %s has %d props", e_type, n_props); 00230 j = 0; 00231 for (i = 0; i < n_props; i++) 00232 { 00233 gparam = prop_list[i]; 00234 qpar = &qof_param_list[j]; 00235 00236 PINFO ("param %d %s is type %s", 00237 i, gparam->name, G_PARAM_SPEC_TYPE_NAME(gparam)); 00238 00239 qpar->param_name = g_param_spec_get_name (gparam); 00240 qpar->param_getfcn = (QofAccessFunc)qof_gobject_getter; 00241 qpar->param_setfcn = NULL; 00242 qpar->param_userdata = gparam; 00243 if ((G_IS_PARAM_SPEC_INT(gparam)) || 00244 (G_IS_PARAM_SPEC_UINT(gparam)) || 00245 (G_IS_PARAM_SPEC_ENUM(gparam)) || 00246 (G_IS_PARAM_SPEC_FLAGS(gparam))) 00247 { 00248 qpar->param_type = QOF_TYPE_INT32; 00249 j++; 00250 } 00251 else if ((G_IS_PARAM_SPEC_INT64(gparam)) || 00252 (G_IS_PARAM_SPEC_UINT64(gparam))) 00253 { 00254 qpar->param_type = QOF_TYPE_INT64; 00255 j++; 00256 } 00257 else if (G_IS_PARAM_SPEC_BOOLEAN(gparam)) 00258 { 00259 qpar->param_type = QOF_TYPE_BOOLEAN; 00260 j++; 00261 } 00262 else if (G_IS_PARAM_SPEC_STRING(gparam)) 00263 { 00264 qpar->param_type = QOF_TYPE_STRING; 00265 j++; 00266 } 00267 else if ((G_IS_PARAM_SPEC_POINTER(gparam)) || 00268 (G_IS_PARAM_SPEC_OBJECT(gparam))) 00269 { 00270 /* No-op, silently ignore. Someday we should handle this ... */ 00271 } 00272 else if ((G_IS_PARAM_SPEC_FLOAT(gparam)) || 00273 (G_IS_PARAM_SPEC_DOUBLE(gparam))) 00274 { 00275 qpar->param_getfcn = (QofAccessFunc) qof_gobject_double_getter; 00276 qpar->param_type = QOF_TYPE_DOUBLE; 00277 j++; 00278 } 00279 else if (G_IS_PARAM_SPEC_CHAR(gparam)) 00280 { 00281 qpar->param_type = QOF_TYPE_CHAR; 00282 j++; 00283 } 00284 else 00285 { 00286 PWARN ("Unknown/unhandled parameter type %s on %s:%s\n", 00287 G_PARAM_SPEC_TYPE_NAME(gparam), e_type, qpar->param_name); 00288 } 00289 } 00290 00291 /* NULL-terminated list! */ 00292 qof_param_list[j].param_type = NULL; 00293 00294 qof_class_register (e_type, NULL, qof_param_list); 00295 00296 /* ------------------------------------------------------ */ 00297 /* Now do the class itself */ 00298 class_def = g_new0 (QofObject, 1); 00299 classList = g_slist_prepend (classList, class_def); 00300 00301 class_def->interface_version = QOF_OBJECT_VERSION; 00302 class_def->e_type = e_type; 00303 /* We could let the user specify a "nick" here, but 00304 * the actual class name seems reasonable, e.g. for debugging. */ 00305 class_def->type_label = G_OBJECT_CLASS_NAME (obclass); 00306 class_def->create = NULL; 00307 class_def->book_begin = NULL; 00308 class_def->book_end = NULL; 00309 class_def->is_dirty = NULL; 00310 class_def->mark_clean = NULL; 00311 class_def->foreach = qof_gobject_foreach; 00312 class_def->printable = NULL; 00313 class_def->version_cmp = NULL; 00314 00315 qof_object_register (class_def); 00316 }
Register an instance of a GObject with the QOF subsystem.
The QofType can be any string you desire, although typically you might want to set it to G_OBJECT_CLASS_NAME() of the object class. Note that this type will become the name of the "table" that is searched by SQL queries: e.g. in order to be able to say "SELECT * FROM MyStuff;" you must first say: qof_gobject_register_instance (book, "MyStuff", obj);
The 'book' argument specifies an anchor point for the collection of all of the registered instances. By working with disjoint books, you can have multiple disjoint searchable sets of objects.
Definition at line 87 of file qofgobj.c.
00088 { 00089 QofCollection *coll; 00090 GSList *instance_list; 00091 00092 if (!book || !type) return; 00093 00094 coll = qof_book_get_collection (book, type); 00095 00096 instance_list = qof_collection_get_data (coll); 00097 instance_list = g_slist_prepend (instance_list, gob); 00098 qof_collection_set_data (coll, instance_list); 00099 }
1.5.7.1