From: Andrea Zagli Date: Mon, 29 Aug 2011 07:21:16 +0000 (+0200) Subject: Aggiunte le funzioni SolipaUtils::gtktreemodel_get_gtypes e SolipaUtils::gtktreemodel... X-Git-Tag: 0.5.0~38 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=b4e60b84ca5f992927fbe2c5607133628f0c4f51;p=solipa%2Flibsolipa Aggiunte le funzioni SolipaUtils::gtktreemodel_get_gtypes e SolipaUtils::gtktreemodel_copy. Entrambe da testare; gtktreemodel_copy da terminare. --- diff --git a/src/utils.c b/src/utils.c index c63b8b0..eaf3d34 100644 --- a/src/utils.c +++ b/src/utils.c @@ -483,6 +483,91 @@ solipa_gtktreemodel_to_csv_gui (Solipa *solipa, return ret; } +GType +*solipa_gtktreemodel_get_gtypes (GtkTreeModel *model, guint *cols) +{ + GType *ret; + + guint _cols; + guint _col; + + ret = NULL; + + _cols = gtk_tree_model_get_n_columns (model); + if (_cols > 0) + { + if (cols != NULL) + { + *cols = _cols; + } + + ret = (GType *)g_malloc0 (_cols * sizeof (GType)); + for (_col = 0; _col < _cols; _col++) + { + ret[_col] = gtk_tree_model_get_column_type (model, _col); + } + } + + return ret; +} + +GtkTreeModel +*solipa_gtktreemodel_copy (GtkTreeModel *model, gboolean only_schema) +{ + GtkTreeModel *ret; + + GType *gtypes; + guint cols; + guint col; + + GtkTreeIter iter; + GtkTreeIter iter_new; + + ret = NULL; + + gtypes = solipa_gtktreemodel_get_gtypes (model, &cols); + if (gtypes != NULL) + { + if (GTK_IS_LIST_STORE (model)) + { + ret = GTK_TREE_MODEL (gtk_list_store_newv (cols, gtypes)); + + if (!only_schema) + { + if (gtk_tree_model_get_iter_first (model, &iter)) + { + do + { + gtk_list_store_append (GTK_LIST_STORE (ret), &iter_new); + for (col = 0; col < cols; col++) + { + GValue gval = {0}; + gtk_tree_model_get_value (model, &iter, col, &gval); + gtk_list_store_set_value (GTK_LIST_STORE (ret), &iter_new, col, &gval); + g_value_unset (&gval); + } + } while (gtk_tree_model_iter_next (model, &iter)); + } + } + } + else if (GTK_IS_TREE_MODEL (model)) + { + ret = GTK_TREE_MODEL (gtk_tree_store_newv (cols, gtypes)); + + if (!only_schema) + { + + } + } + else + { + g_warning ("GtkTreeModel type not expected."); + } + } + + return ret; +} + gchar *solipa_string_replace (const gchar *string, const gchar *origin, diff --git a/src/utils.h b/src/utils.h index d5baeb4..3669859 100644 --- a/src/utils.h +++ b/src/utils.h @@ -48,6 +48,9 @@ guint solipa_gtktreemodel_to_csv_gui (Solipa *solipa, gchar **columns_title, guint n_columns); +GType *solipa_gtktreemodel_get_gtypes (GtkTreeModel *model, guint *cols); +GtkTreeModel *solipa_gtktreemodel_copy (GtkTreeModel *model, gboolean only_schema); + gchar *solipa_string_replace (const gchar *string, const gchar *origin, const gchar *replace);