GLib GObjects
[Object: Describing data structure.]


Detailed Description

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.


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 *)


Function Documentation

void qof_gobject_init ( void   ) 

Initalize and shut down this subsystem.

Definition at line 48 of file qofgobj.c.

00049 {
00050     if (initialized)
00051         return;
00052     initialized = TRUE;
00053 
00054     // gobjectClassTable = g_hash_table_new (g_str_hash, g_str_equal);
00055 
00056     /* Init the other subsystems that we need */
00057     qof_object_initialize ();
00058     qof_query_init ();
00059 }

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.

00223 {
00224     guint i, j;
00225     QofParam *qof_param_list, *qpar;
00226     QofObject *class_def;
00227     GParamSpec **prop_list, *gparam;
00228     guint n_props;
00229 
00230     /* Get the GObject properties, convert to QOF properties */
00231     prop_list = g_object_class_list_properties (obclass, &n_props);
00232 
00233     qof_param_list = g_new0 (QofParam, n_props);
00234     paramList = g_slist_prepend (paramList, qof_param_list);
00235 
00236     PINFO ("object %s has %d props", e_type, n_props);
00237     j = 0;
00238     for (i = 0; i < n_props; i++)
00239     {
00240         gparam = prop_list[i];
00241         qpar = &qof_param_list[j];
00242 
00243         PINFO ("param %d %s is type %s",
00244             i, gparam->name, G_PARAM_SPEC_TYPE_NAME (gparam));
00245 
00246         qpar->param_name = g_param_spec_get_name (gparam);
00247         qpar->param_getfcn = (QofAccessFunc) qof_gobject_getter;
00248         qpar->param_setfcn = NULL;
00249         qpar->param_userdata = gparam;
00250         if ((G_IS_PARAM_SPEC_INT (gparam)) ||
00251             (G_IS_PARAM_SPEC_UINT (gparam)) ||
00252             (G_IS_PARAM_SPEC_ENUM (gparam)) ||
00253             (G_IS_PARAM_SPEC_FLAGS (gparam)))
00254         {
00255             qpar->param_type = QOF_TYPE_INT32;
00256             j++;
00257         }
00258         else if ((G_IS_PARAM_SPEC_INT64 (gparam)) ||
00259             (G_IS_PARAM_SPEC_UINT64 (gparam)))
00260         {
00261             qpar->param_type = QOF_TYPE_INT64;
00262             j++;
00263         }
00264         else if (G_IS_PARAM_SPEC_BOOLEAN (gparam))
00265         {
00266             qpar->param_type = QOF_TYPE_BOOLEAN;
00267             j++;
00268         }
00269         else if (G_IS_PARAM_SPEC_STRING (gparam))
00270         {
00271             qpar->param_type = QOF_TYPE_STRING;
00272             j++;
00273         }
00274         else if ((G_IS_PARAM_SPEC_POINTER (gparam)) ||
00275             (G_IS_PARAM_SPEC_OBJECT (gparam)))
00276         {
00277             /* No-op, silently ignore.  Someday we should handle this ...  */
00278         }
00279         else if ((G_IS_PARAM_SPEC_FLOAT (gparam)) ||
00280             (G_IS_PARAM_SPEC_DOUBLE (gparam)))
00281         {
00282             qpar->param_getfcn = (QofAccessFunc) qof_gobject_double_getter;
00283             qpar->param_type = QOF_TYPE_DOUBLE;
00284             j++;
00285         }
00286         else if (G_IS_PARAM_SPEC_CHAR (gparam))
00287         {
00288             qpar->param_type = QOF_TYPE_CHAR;
00289             j++;
00290         }
00291         else
00292         {
00293             PWARN ("Unknown/unhandled parameter type %s on %s:%s\n",
00294                 G_PARAM_SPEC_TYPE_NAME (gparam), e_type, qpar->param_name);
00295         }
00296     }
00297 
00298     /* NULL-terminated list! */
00299     qof_param_list[j].param_type = NULL;
00300 
00301     qof_class_register (e_type, NULL, qof_param_list);
00302 
00303     /* ------------------------------------------------------ */
00304     /* Now do the class itself */
00305     class_def = g_new0 (QofObject, 1);
00306     classList = g_slist_prepend (classList, class_def);
00307 
00308     class_def->interface_version = QOF_OBJECT_VERSION;
00309     class_def->e_type = e_type;
00310     /* We could let the user specify a "nick" here, but
00311      * the actual class name seems reasonable, e.g. for debugging. */
00312     class_def->type_label = G_OBJECT_CLASS_NAME (obclass);
00313     class_def->create = NULL;
00314     class_def->book_begin = NULL;
00315     class_def->book_end = NULL;
00316     class_def->is_dirty = NULL;
00317     class_def->mark_clean = NULL;
00318     class_def->foreach = qof_gobject_foreach;
00319     class_def->printable = NULL;
00320     class_def->version_cmp = NULL;
00321 
00322     qof_object_register (class_def);
00323 }

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.

00094 {
00095     QofCollection *coll;
00096     GSList *instance_list;
00097 
00098     if (!book || !type)
00099         return;
00100 
00101     coll = qof_book_get_collection (book, type);
00102 
00103     instance_list = qof_collection_get_data (coll);
00104     instance_list = g_slist_prepend (instance_list, gob);
00105     qof_collection_set_data (coll, instance_list);
00106 }


Generated on Thu Jan 31 22:50:27 2008 for QOF by  doxygen 1.5.4