Important: I changed the view plug-in API recently and you should skip this chapter waiting I rewrote it
There is a sample plugin logically called 'hello' which is a minimal implementation of a classic (it only shows one record at the same time) plugin.
When Gaby starts it reads the description of the database to be used (which is guess from the name you used to invoke Gaby or from the --as flags). I'll not talk about this file here but somewhere it will have a line like this : viewable as form,list,xlist. from which Gaby "guess" it has to load form, list and xlist plugins. The first step is to initialize those plugins [1] which is done looking for a function like this in the plugin :
#include <gaby.h> |
int init_view_plugin
(ViewPluginData *vpd);Important: If you want your plug-in to support being part of the huge binary produced when configuring with "Miguel wishes" you'll have to enclose the function in a #ifndef FOLLOW_MIGUEL.
The ViewPluginData structure is defined in gaby.h (like all structures used in Gaby) :
typedef struct _ViewPluginData ViewPluginData; struct _ViewPluginData { GModule *handle; int (*init_plugin) ( ViewPluginData *vpd ); void (*view_create) (gabywindow *win, gboolean first); void (*view_fill) (gabywindow *win); void (*view_save) (gabywindow *win); #ifndef NO_GTK GtkWidget* (*configure) (ViewPluginData *vpd); #endif gchar *name; gchar *i18n_name; enum { ALL_RECORDS = 1 << 0, ONE_RECORD = 1 << 1, FILTER = 1 << 2 } type; enum { NONE = 0, EDITABLE = 1 << 0, FILTERABLE = 1 << 1, } capabilities; }; |
I believe you already have a good picture of what will have its place in init_view_plugin. To confirm :
Example 12-1. Initializing a view plug-in
int init_view_plugin(ViewPluginData *vpd) { vpd->view_create = hello_create; vpd->view_fill = hello_fill; vpd->configure = NULL; vpd->name = "hello"; vpd->i18n_name = _("Hello"); vpd->type = ONE_RECORD; vpd->capabilities = NONE; return 0; } |
FIXME: a few comments would be welcomed.
[1] | Note that this could be done only when the user asks for them but since it is not implemented this way ... |