QOF
0.7.5
|
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 *) |
The API defined in this file allows a user to register any GLib GObject (and any object derived from one, e.g. GTK/Gnome) with the QOF system, as a QOF Object Class. This allows the QOF Query routines to be used to search over collections of GObjects.
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 48 of file qofgobj.c.
{ if (initialized) return; initialized = TRUE; // gobjectClassTable = g_hash_table_new (g_str_hash, g_str_equal); /* Init the other subsystems that we need */ qof_object_initialize (); qof_query_init (); }
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 222 of file qofgobj.c.
{ guint i, j; QofParam *qof_param_list, *qpar; QofObject *class_def; GParamSpec **prop_list, *gparam; guint n_props; /* Get the GObject properties, convert to QOF properties */ prop_list = g_object_class_list_properties (obclass, &n_props); qof_param_list = g_new0 (QofParam, n_props); paramList = g_slist_prepend (paramList, qof_param_list); PINFO ("object %s has %d props", e_type, n_props); j = 0; for (i = 0; i < n_props; i++) { gparam = prop_list[i]; qpar = &qof_param_list[j]; PINFO ("param %d %s is type %s", i, gparam->name, G_PARAM_SPEC_TYPE_NAME (gparam)); qpar->param_name = g_param_spec_get_name (gparam); qpar->param_getfcn = (QofAccessFunc) qof_gobject_getter; qpar->param_setfcn = NULL; qpar->param_userdata = gparam; if ((G_IS_PARAM_SPEC_INT (gparam)) || (G_IS_PARAM_SPEC_UINT (gparam)) || (G_IS_PARAM_SPEC_ENUM (gparam)) || (G_IS_PARAM_SPEC_FLAGS (gparam))) { qpar->param_type = QOF_TYPE_INT32; j++; } else if ((G_IS_PARAM_SPEC_INT64 (gparam)) || (G_IS_PARAM_SPEC_UINT64 (gparam))) { qpar->param_type = QOF_TYPE_INT64; j++; } else if (G_IS_PARAM_SPEC_BOOLEAN (gparam)) { qpar->param_type = QOF_TYPE_BOOLEAN; j++; } else if (G_IS_PARAM_SPEC_STRING (gparam)) { qpar->param_type = QOF_TYPE_STRING; j++; } else if ((G_IS_PARAM_SPEC_POINTER (gparam)) || (G_IS_PARAM_SPEC_OBJECT (gparam))) { /* No-op, silently ignore. Someday we should handle this ... */ } else if ((G_IS_PARAM_SPEC_FLOAT (gparam)) || (G_IS_PARAM_SPEC_DOUBLE (gparam))) { qpar->param_getfcn = (QofAccessFunc) qof_gobject_double_getter; qpar->param_type = QOF_TYPE_DOUBLE; j++; } else if (G_IS_PARAM_SPEC_CHAR (gparam)) { qpar->param_type = QOF_TYPE_CHAR; j++; } else { PWARN ("Unknown/unhandled parameter type %s on %s:%s\n", G_PARAM_SPEC_TYPE_NAME (gparam), e_type, qpar->param_name); } } /* NULL-terminated list! */ qof_param_list[j].param_type = NULL; qof_class_register (e_type, NULL, qof_param_list); /* ------------------------------------------------------ */ /* Now do the class itself */ class_def = g_new0 (QofObject, 1); classList = g_slist_prepend (classList, class_def); class_def->interface_version = QOF_OBJECT_VERSION; class_def->e_type = e_type; /* We could let the user specify a "nick" here, but * the actual class name seems reasonable, e.g. for debugging. */ class_def->type_label = G_OBJECT_CLASS_NAME (obclass); class_def->create = NULL; class_def->book_begin = NULL; class_def->book_end = NULL; class_def->is_dirty = NULL; class_def->mark_clean = NULL; class_def->foreach = qof_gobject_foreach; class_def->printable = NULL; class_def->version_cmp = NULL; qof_object_register (class_def); }
void qof_gobject_register_instance | ( | QofBook * | book, |
QofType | , | ||
GObject * | |||
) |
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 93 of file qofgobj.c.
{ QofCollection *coll; GSList *instance_list; if (!book || !type) return; coll = qof_book_get_collection (book, type); instance_list = qof_collection_get_data (coll); instance_list = g_slist_prepend (instance_list, gob); qof_collection_set_data (coll, instance_list); }