[libgda] Added gdaui_plugin_declare(), and misc corrections
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] Added gdaui_plugin_declare(), and misc corrections
- Date: Mon, 19 Oct 2009 18:43:19 +0000 (UTC)
commit e44f4edfc1dbabc142e35f7baa70a6e08673da0a
Author: Vivien Malerba <malerba gnome-db org>
Date: Mon Oct 19 20:29:20 2009 +0200
Added gdaui_plugin_declare(), and misc corrections
doc/C/libgda-4.0-docs.sgml | 2 +
doc/C/libgda-ui-sections.txt | 9 ++++
libgda-ui/Makefile.am | 6 +-
libgda-ui/data-entries/gdaui-entry-shell.c | 13 ++----
libgda-ui/data-entries/gdaui-entry-wrapper.c | 8 +--
libgda-ui/gdaui-data-widget-info.c | 4 +-
libgda-ui/gdaui-init.c | 54 +++++++++++++++++++++++++-
libgda-ui/gdaui-plugin.h | 18 ++++++++-
libgda-ui/libgda-ui.symbols | 1 +
9 files changed, 92 insertions(+), 23 deletions(-)
---
diff --git a/doc/C/libgda-4.0-docs.sgml b/doc/C/libgda-4.0-docs.sgml
index 60adabb..cd59673 100644
--- a/doc/C/libgda-4.0-docs.sgml
+++ b/doc/C/libgda-4.0-docs.sgml
@@ -134,6 +134,7 @@
<!ENTITY libgdaui-GdauiCombo SYSTEM "xml/gdaui-combo.xml">
<!ENTITY libgdaui-GdauiDataEntry SYSTEM "xml/gdaui-data-entry.xml">
<!ENTITY libgdaui-gdaui-easy SYSTEM "xml/gdaui-easy.xml">
+<!ENTITY libgdaui-gdaui-plugins SYSTEM "xml/gdaui-plugins.xml">
<!ENTITY libgdaui-GdauiDataStore SYSTEM "xml/gdaui-data-store.xml">
<!ENTITY libgdaui-GdauiDataWidgetFilter SYSTEM "xml/gdaui-data-widget-filter.xml">
<!ENTITY libgdaui-GdauiDataWidget SYSTEM "xml/gdaui-data-widget.xml">
@@ -1248,6 +1249,7 @@ g_object_unref (store);
&libgdaui-GdauiProviderSelector;
&libgdaui-GdauiBasicForm;
+ &libgdaui-gdaui-plugins;
&libgdaui-GdauiForm;
&libgdaui-GdauiGrid;
diff --git a/doc/C/libgda-ui-sections.txt b/doc/C/libgda-ui-sections.txt
index e7a009a..d3d7e36 100644
--- a/doc/C/libgda-ui-sections.txt
+++ b/doc/C/libgda-ui-sections.txt
@@ -5,6 +5,15 @@ gdaui_new_data_entry
</SECTION>
<SECTION>
+<FILE>gdaui-plugins</FILE>
+<TITLE>UI plugins</TITLE>
+GdauiEntryCreateFunc
+GdauiCellCreateFunc
+GdauiPlugin
+gdaui_plugin_declare
+</SECTION>
+
+<SECTION>
<FILE>gdaui-basic-form</FILE>
<TITLE>GdauiBasicForm</TITLE>
GdauiBasicForm
diff --git a/libgda-ui/Makefile.am b/libgda-ui/Makefile.am
index 4be868b..a4ce1d2 100644
--- a/libgda-ui/Makefile.am
+++ b/libgda-ui/Makefile.am
@@ -32,7 +32,8 @@ ui_headers = \
gdaui-raw-grid.h \
gdaui-server-operation.h \
gdaui-set.h \
- gdaui-tree-store.h
+ gdaui-tree-store.h \
+ gdaui-plugin.h
libgda_ui_4_0_la_SOURCES = \
$(ui_headers) \
@@ -53,8 +54,7 @@ libgda_ui_4_0_la_SOURCES = \
gdaui-server-operation.c \
gdaui-set.c \
gdaui-tree-store.c \
- gdaui-init.c \
- gdaui-plugin.h
+ gdaui-init.c
gdaui-enum-types.h: s-enum-types-h
@true
diff --git a/libgda-ui/data-entries/gdaui-entry-shell.c b/libgda-ui/data-entries/gdaui-entry-shell.c
index f00ee3f..d6003df 100644
--- a/libgda-ui/data-entries/gdaui-entry-shell.c
+++ b/libgda-ui/data-entries/gdaui-entry-shell.c
@@ -118,8 +118,8 @@ gdaui_entry_shell_class_init (GdauiEntryShellClass * class)
object_class->set_property = gdaui_entry_shell_set_property;
object_class->get_property = gdaui_entry_shell_get_property;
g_object_class_install_property (object_class, PROP_HANDLER,
- g_param_spec_pointer ("handler", NULL, NULL,
- (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+ g_param_spec_object ("handler", NULL, NULL, GDA_TYPE_DATA_HANDLER,
+ (G_PARAM_READABLE | G_PARAM_WRITABLE)));
g_object_class_install_property (object_class, PROP_ACTIONS,
g_param_spec_boolean ("actions", NULL, NULL, TRUE,
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
@@ -227,14 +227,13 @@ gdaui_entry_shell_set_property (GObject *object,
if (shell->priv) {
switch (param_id) {
case PROP_HANDLER:
- ptr = g_value_get_pointer (value);
+ ptr = g_value_get_object (value);
if (shell->priv->data_handler) {
g_object_unref (shell->priv->data_handler);
shell->priv->data_handler = NULL;
}
if (ptr) {
- g_assert (GDA_IS_DATA_HANDLER (ptr));
shell->priv->data_handler = GDA_DATA_HANDLER (ptr);
g_object_ref (G_OBJECT (shell->priv->data_handler));
}
@@ -275,11 +274,7 @@ gdaui_entry_shell_get_property (GObject *object,
if (shell->priv) {
switch (param_id) {
case PROP_HANDLER:
- if (!shell->priv->data_handler && !GDAUI_IS_ENTRY_NONE (object))
- g_message (_("Widget of class '%s' does not have any associated GdaDataHandler, "
- "(to be set using the 'handler' property) expect some mis-behaviours"),
- G_OBJECT_TYPE_NAME (object));
- g_value_set_pointer (value, shell->priv->data_handler);
+ g_value_set_object (value, shell->priv->data_handler);
break;
case PROP_ACTIONS:
g_value_set_boolean (value, shell->priv->show_actions);
diff --git a/libgda-ui/data-entries/gdaui-entry-wrapper.c b/libgda-ui/data-entries/gdaui-entry-wrapper.c
index 1dcbc3a..d7e3e64 100644
--- a/libgda-ui/data-entries/gdaui-entry-wrapper.c
+++ b/libgda-ui/data-entries/gdaui-entry-wrapper.c
@@ -811,16 +811,14 @@ gdaui_entry_wrapper_get_attributes (GdauiDataEntry *iface)
static GdaDataHandler *
gdaui_entry_wrapper_get_handler (GdauiDataEntry *iface)
{
- GValue val = { 0, };
GdaDataHandler *dh;
g_return_val_if_fail (GDAUI_IS_ENTRY_WRAPPER (iface), NULL);
g_return_val_if_fail (GDAUI_ENTRY_WRAPPER (iface)->priv, NULL);
- g_value_init (&val, G_TYPE_POINTER);
- g_object_get_property (G_OBJECT (iface), "handler", &val);
- dh = g_value_get_pointer (&val);
- g_value_unset (&val);
+ g_object_get (G_OBJECT (iface), "handler", &dh, NULL);
+ if (dh) /* loose the reference before returning the object */
+ g_object_unref (dh);
return dh;
}
diff --git a/libgda-ui/gdaui-data-widget-info.c b/libgda-ui/gdaui-data-widget-info.c
index 2c7a730..ed74354 100644
--- a/libgda-ui/gdaui-data-widget-info.c
+++ b/libgda-ui/gdaui-data-widget-info.c
@@ -293,10 +293,8 @@ gdaui_data_widget_info_set_property (GObject *object,
gtk_widget_destroy (info->priv->buttons_bar);
info->priv->buttons_bar = NULL;
}
- if (info->priv->current_sample) {
- gtk_widget_destroy (info->priv->current_sample);
+ if (info->priv->current_sample)
info->priv->current_sample = NULL;
- }
if (info->priv->row_spin) {
gtk_widget_destroy (info->priv->row_spin);
info->priv->row_spin = NULL;
diff --git a/libgda-ui/gdaui-init.c b/libgda-ui/gdaui-init.c
index d8946ec..45cf083 100644
--- a/libgda-ui/gdaui-init.c
+++ b/libgda-ui/gdaui-init.c
@@ -42,6 +42,7 @@
/* plugins list */
+typedef GSList *(*GdauiPluginInit) (GError **);
static GHashTable *init_plugins_hash (void);
GHashTable *gdaui_plugins_hash = NULL; /* key = plugin name, value = GdauiPlugin structure pointer */
@@ -73,7 +74,8 @@ gdaui_init (void)
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
gda_init ();
- gdaui_plugins_hash = init_plugins_hash ();
+ if (! gdaui_plugins_hash)
+ gdaui_plugins_hash = init_plugins_hash ();
initialized = TRUE;
}
@@ -223,6 +225,56 @@ _gdaui_new_cell_renderer (GType type, const gchar *plugin_name)
return cell;
}
+/**
+ * gdaui_plugin_declare
+ * @plugin: a pointer to a structure filled to describe the new plugin
+ *
+ * Adds a new plugin which will be used by the forms and grids. The new plugin, as
+ * described by @plugin can declare a custom widget to be used for forms, grids, or both.
+ *
+ * If a plugin is already declared with the same name as the requested name, then
+ * a warning is issued and the operation fails.
+ */
+void
+gdaui_plugin_declare (const GdauiPlugin *plugin)
+{
+ GdauiPlugin *np;
+
+ g_return_if_fail (plugin);
+ g_return_if_fail (plugin->plugin_name);
+ if (!gdaui_plugins_hash)
+ gdaui_plugins_hash = init_plugins_hash ();
+ if (g_hash_table_lookup (gdaui_plugins_hash, plugin->plugin_name)) {
+ g_warning ("Plugin '%s' already declared", plugin->plugin_name);
+ return;
+ }
+ if (((plugin->nb_g_types < 1) && plugin->valid_g_types) ||
+ ((plugin->nb_g_types > 0) && !plugin->valid_g_types)) {
+ g_warning ("Invalid description of plugin accepted types");
+ return;
+ }
+ g_return_if_fail (plugin->entry_create_func || plugin->cell_create_func);
+
+ np = g_new0 (GdauiPlugin, 1);
+ np->plugin_name = g_strdup (plugin->plugin_name);
+ if (plugin->plugin_descr)
+ np->plugin_descr = g_strdup (plugin->plugin_descr);
+ np->plugin_file = g_strdup (plugin->plugin_file);
+
+ np->nb_g_types = plugin->nb_g_types;
+ if (plugin->valid_g_types) {
+ np->valid_g_types = g_new0 (GType, np->nb_g_types);
+ memcpy (np->valid_g_types, plugin->valid_g_types, np->nb_g_types);
+ }
+
+ if (plugin->options_xml_spec)
+ np->options_xml_spec = g_strdup (plugin->options_xml_spec);
+ np->entry_create_func = plugin->entry_create_func;
+ np->cell_create_func = plugin->cell_create_func;
+
+ g_hash_table_insert (gdaui_plugins_hash, np->plugin_name, np);
+}
+
static GdauiDataEntry *entry_none_create_func (GdaDataHandler *handler, GType type, const gchar *options);
static GdauiDataEntry *entry_boolean_create_func (GdaDataHandler *handler, GType type, const gchar *options);
static GdauiDataEntry *entry_bin_create_func (GdaDataHandler *handler, GType type, const gchar *options);
diff --git a/libgda-ui/gdaui-plugin.h b/libgda-ui/gdaui-plugin.h
index a30c5e8..218c98e 100644
--- a/libgda-ui/gdaui-plugin.h
+++ b/libgda-ui/gdaui-plugin.h
@@ -25,13 +25,25 @@
#include <libgda/gda-value.h>
#include "gdaui-decl.h"
-typedef GSList *(*GdauiPluginInit) (GError **);
typedef GdauiDataEntry *(*GdauiEntryCreateFunc)(GdaDataHandler *, GType, const gchar *);
typedef GtkCellRenderer *(*GdauiCellCreateFunc) (GdaDataHandler *, GType, const gchar *);
/**
- * Structure representing a plugin
+ * GdauiPlugin:
+ * @plugin_name: the name of the plugin
+ * @plugin_descr: a description for the plugin, or %NULL
+ * @plugin_file: the shared object implementing the plugin, can be %NULL for internal plugins
+ * @nb_g_types: number of types the plugin can handle, or %0 for any type
+ * @valid_g_types: an array of #GType, containing the accepted types, its size is @nb_g_types,
+ * or %NULL if @nb_g_types is %0
+ * @options_xml_spec: a string describing the plugin's options, or %NULL
+ * @entry_create_func: the function called to create a #GdauiDataEntry, or %NULL
+ * @cell_create_func: the function called to create a #GtkCellRenderer, or %NULL
+ *
+ * Structure representing a plugin.
+ *
+ * Note: @entry_create_func and @cell_create_func can't be %NULL at the same time
*/
typedef struct {
gchar *plugin_name;
@@ -48,4 +60,6 @@ typedef struct {
GdauiCellCreateFunc cell_create_func;
} GdauiPlugin;
+void gdaui_plugin_declare (const GdauiPlugin *plugin);
+
#endif
diff --git a/libgda-ui/libgda-ui.symbols b/libgda-ui/libgda-ui.symbols
index 4a7a235..85c6496 100644
--- a/libgda-ui/libgda-ui.symbols
+++ b/libgda-ui/libgda-ui.symbols
@@ -142,6 +142,7 @@
gdaui_numeric_entry_get_type
gdaui_numeric_entry_get_value
gdaui_numeric_entry_new
+ gdaui_plugin_declare
gdaui_plugins_hash
gdaui_provider_selector_get_provider
gdaui_provider_selector_get_provider_obj
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]