static void gtk_form_decoder_on_btn_browse_clicked (GtkButton *button,
gpointer user_data);
+static gboolean gtk_form_decoder_on_completion_match_selected (GtkEntryCompletion *widget,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data);
+
static GtkWidgetClass *parent_class = NULL;
GdaEx *gdaex;
gchar *sql;
+
+ GdaDataModel *completion_dm;
+ guint completion_text_column;
+ guint completion_key_column;
};
G_DEFINE_TYPE (GtkFormDecoder, gtk_form_decoder, GTK_TYPE_BIN)
return gtk_widget_get_visible (priv->btn_browse);
}
+void
+gtk_form_decoder_set_completion (GtkFormDecoder *decoder,
+ const gchar *sql,
+ GdaDataModel *data_model,
+ guint key_column,
+ guint text_column)
+{
+ gchar *_sql;
+
+ GtkTreeModel *model;
+ GtkEntryCompletion *completion;
+
+ g_return_if_fail (GTK_IS_FORM_DECODER (decoder));
+
+ GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
+
+ if (decoder == NULL)
+ {
+ priv->completion_dm = NULL;
+ priv->completion_text_column = 0;
+ priv->completion_key_column = 0;
+
+ gtk_entry_set_completion (GTK_ENTRY (priv->txt_decoded), NULL);
+ gtk_editable_set_editable (GTK_EDITABLE (priv->txt_decoded), FALSE);
+ return;
+ }
+
+ g_return_if_fail (sql != NULL || GDA_IS_DATA_MODEL (data_model));
+
+ if (!GDA_IS_DATA_MODEL (data_model))
+ {
+ _sql = g_strstrip (g_strdup (sql));
+ g_return_if_fail (g_strcmp0 (_sql, "") != 0);
+
+ if (!IS_GDAEX (priv->gdaex))
+ {
+ g_warning (_("No GdaEx object inside GtkFormDecoder."));
+ return;
+ }
+
+ priv->completion_dm = gdaex_query (priv->gdaex, sql);
+ if (priv->completion_dm == NULL)
+ {
+ g_warning (_("Unable to create the GdaDataModel for completion."));
+ return;
+ }
+ }
+ else
+ {
+ priv->completion_dm = data_model;
+ }
+
+ priv->completion_text_column = text_column;
+ priv->completion_key_column = key_column;
+
+ model = GTK_TREE_MODEL (gdaex_data_model_to_gtkliststore (priv->completion_dm, FALSE));
+ if (model == NULL)
+ {
+ return;
+ }
+
+ completion = gtk_entry_completion_new ();
+ gtk_entry_set_completion (GTK_ENTRY (priv->txt_decoded), completion);
+
+ g_signal_connect (G_OBJECT (completion), "match-selected",
+ G_CALLBACK (gtk_form_decoder_on_completion_match_selected), (gpointer)decoder);
+
+ g_object_unref (completion);
+
+ gtk_entry_completion_set_model (completion, model);
+ gtk_entry_completion_set_minimum_key_length (completion, 3);
+ gtk_entry_completion_set_text_column (completion, text_column);
+
+ gtk_editable_set_editable (GTK_EDITABLE (priv->txt_decoded), TRUE);
+}
+
/* CALLBACKS */
static void
gtk_form_decoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
g_signal_emit (G_OBJECT (user_data), klass->btn_browse_clicked_signal_id, 0);
}
+
+static gboolean
+gtk_form_decoder_on_completion_match_selected (GtkEntryCompletion *widget,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ GValue gval = {0};
+
+ GtkFormDecoder *decoder = (GtkFormDecoder *)user_data;
+ GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
+
+ gtk_tree_model_get_value (model, iter, priv->completion_key_column, &gval);
+
+ gtk_form_decoder_set_key (decoder, gda_value_stringify (&gval));
+
+ return TRUE;
+}