return chr;
}
+const gchar
+*gdaex_get_guifile (GdaEx *gdaex)
+{
+ GdaExPrivate *priv;
+
+ g_return_val_if_fail (IS_GDAEX (gdaex), NULL);
+
+ priv = GDAEX_GET_PRIVATE (gdaex);
+
+ return (const gchar *)g_strdup (priv->guifile);
+}
+
+GtkBuilder
+*gdaex_get_gtkbuilder (GdaEx *gdaex)
+{
+ GdaExPrivate *priv;
+
+ g_return_val_if_fail (IS_GDAEX (gdaex), NULL);
+
+ priv = GDAEX_GET_PRIVATE (gdaex);
+
+ return priv->gtkbuilder;
+}
+
+ void
+ gdaex_fill_liststore_from_sql (GdaEx *gdaex,
+ GtkListStore *lstore,
+ const gchar *sql,
+ guint *cols_formatted,
+ gchar *(*cols_format_func) (GdaDataModelIter *, guint))
+ {
+ GdaDataModel *dm;
+
+ gchar *_sql;
+
+ g_return_if_fail (IS_GDAEX (gdaex));
+ g_return_if_fail (sql != NULL);
+
+ _sql = g_strstrip (g_strdup (sql));
+
+ g_return_if_fail (g_strcmp0 (_sql, "") != 0);
+
+ dm = gdaex_query (gdaex, _sql);
+ gdaex_fill_liststore_from_datamodel (gdaex, lstore, dm, cols_formatted, cols_format_func);
+ }
+
+ void
+ gdaex_fill_liststore_from_datamodel (GdaEx *gdaex,
+ GtkListStore *lstore,
+ GdaDataModel *dm,
+ guint *cols_formatted,
+ gchar *(*cols_format_func) (GdaDataModelIter *, guint))
+ {
+ GtkTreeIter iter;
+
+ GdaDataModelIter *gda_iter;
+
+ guint cols;
+ guint col;
+
+ GType col_gtype;
+
+ GdaColumn *gcol;
+ GType gcol_gtype;
+
+ gint *columns;
+ GValue *values;
+
+ gdouble dval;
+ GDateTime *gdatetime;
+
+ g_return_if_fail (IS_GDAEX (gdaex));
+ g_return_if_fail (GTK_IS_LIST_STORE (lstore));
+ g_return_if_fail (GDA_IS_DATA_MODEL (dm));
+
+ cols = gtk_tree_model_get_n_columns (GTK_TREE_MODEL (lstore));
+
+ gtk_list_store_clear (lstore);
+
+ gda_iter = gda_data_model_create_iter (dm);
+ if (gda_iter == NULL)
+ {
+ return;
+ }
+
+ columns = g_malloc0 (cols * sizeof (gint));
+ values = g_malloc0 (cols * sizeof (GValue));
+
+ while (gda_data_model_iter_move_next (gda_iter))
+ {
+ gtk_list_store_append (lstore, &iter);
+
+ for (col = 0; col < cols; col++)
+ {
+ columns[col] = col;
+
+ col_gtype = gtk_tree_model_get_column_type (GTK_TREE_MODEL (lstore), col);
+
+ GValue gval = {0};
+ g_value_init (&gval, col_gtype);
+ switch (col_gtype)
+ {
+ case G_TYPE_STRING:
+ gcol = gda_data_model_describe_column (dm, col);
+ gcol_gtype = gda_column_get_g_type (gcol);
+
+ switch (gcol_gtype)
+ {
+ case G_TYPE_STRING:
+ g_value_set_string (&gval, gdaex_data_model_iter_get_value_stringify_at (gda_iter, col));
+ break;
+
+ case G_TYPE_BOOLEAN:
+ g_value_set_string (&gval, gdaex_data_model_iter_get_value_boolean_at (gda_iter, col) ? "X" : "");
+ break;
+
+ case G_TYPE_INT:
+ case G_TYPE_FLOAT:
+ case G_TYPE_DOUBLE:
+ dval = gdaex_data_model_iter_get_value_double_at (gda_iter, col);
+ g_value_set_string (&gval, gdaex_format_money (dval, -1, FALSE));
+ break;
+
+ default:
+ if (cols_format_func != NULL)
+ {
+ g_value_set_string (&gval, (*cols_format_func) (gda_iter, col));
+ }
+ else if (gcol_gtype == G_TYPE_DATE
+ || gcol_gtype == GDA_TYPE_TIMESTAMP
+ || gcol_gtype == G_TYPE_DATE_TIME)
+ {
+ gdatetime = gdaex_data_model_iter_get_value_gdatetime_at (gda_iter, col);
+ /* TODO find default format from locale */
+ g_value_set_string (&gval, g_date_time_format (gdatetime, gcol_gtype == G_TYPE_DATE ? "%d/%m/%Y" : "%d/%m/%Y %H.%M.%S"));
+ }
+ else
+ {
+ g_value_set_string (&gval, gda_value_stringify (gda_data_model_iter_get_value_at (gda_iter, col)));
+ }
+ break;
+ }
+
+ values[col] = gval;
+ break;
+
+ case G_TYPE_INT:
+ g_value_set_int (&gval, gdaex_data_model_iter_get_value_integer_at (gda_iter, col));
+ values[col] = gval;
+ break;
+
+ case G_TYPE_FLOAT:
+ g_value_set_float (&gval, gdaex_data_model_iter_get_value_float_at (gda_iter, col));
+ values[col] = gval;
+ break;
+
+ case G_TYPE_DOUBLE:
+ g_value_set_double (&gval, gdaex_data_model_iter_get_value_double_at (gda_iter, col));
+ values[col] = gval;
+ break;
+
+ case G_TYPE_BOOLEAN:
+ g_value_set_boolean (&gval, gdaex_data_model_iter_get_value_boolean_at (gda_iter, col));
+ values[col] = gval;
+ break;
+
+ default:
+ values[col] = *gda_value_new_from_string (gdaex_data_model_iter_get_value_stringify_at (gda_iter, col), col_gtype);
+ break;
+ }
+ }
+
+ gtk_list_store_set_valuesv (lstore, &iter, columns, values, cols);
+ }
+ }
+
+ gchar
+ *gdaex_format_money (gdouble number,
+ gint decimals,
+ gboolean with_currency_symbol)
+ {
+ gchar *ret;
+
+ GRegex *regex;
+ GError *error;
+
+ gchar *str_format;
+ gchar *str;
+ gssize str_len;
+
+ /* TODO
+ * - get number of decimals from locale
+ * - get grouping char from locale
+ * - get currency symbol from locale
+ */
+
+ ret = g_strdup ("");
+
+ error = NULL;
+ regex = g_regex_new ("(^[-\\d]?\\d+)(\\d\\d\\d)", 0, 0, &error);
+ if (error != NULL)
+ {
+ g_warning ("Error on creating regex: %s.",
+ error->message != NULL ? error->message : "no details");
+ return "";
+ }
+
+ str_format = g_strdup_printf ("%%0%sf", decimals == 0 ? ".0" : (decimals < 0 ? ".2" : g_strdup_printf (".%d", decimals)));
+ ret = g_strdup_printf (str_format, number);
+
+ while (TRUE)
+ {
+ error = NULL;
+ str_len = g_utf8_strlen (ret, -1);
+ str = g_regex_replace ((const GRegex *)regex,
+ ret, str_len, 0,
+ "\\1.\\2", 0,
+ &error);
+ if (error != NULL)
+ {
+ g_warning ("Error on regex replacing: %s.",
+ error->message != NULL ? error->message : "no details");
+ g_regex_unref (regex);
+ return "";
+ }
+ if (g_strcmp0 (ret, str) != 0)
+ {
+ ret = g_strdup (str);
+ g_free (str);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (with_currency_symbol)
+ {
+ ret = g_strconcat ("€ ", ret, NULL);
+ }
+
+ g_regex_unref (regex);
+
+ return ret;
+ }
+
/* PRIVATE */
static void
gdaex_create_connection_parser (GdaEx *gdaex)