]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Aggiunte le funzioni SolipaUtils::gtktreemodel_get_gtypes e SolipaUtils::gtktreemodel...
authorAndrea Zagli <azagli@libero.it>
Mon, 29 Aug 2011 07:21:16 +0000 (09:21 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 29 Aug 2011 07:21:16 +0000 (09:21 +0200)
Entrambe da testare; gtktreemodel_copy da terminare.

src/utils.c
src/utils.h

index c63b8b0464b198b376274dd999edf8bb97f3a8c3..eaf3d3448d5fcb198440bc6346499ed5addeaba2 100644 (file)
@@ -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,
index d5baeb4cf7b6413daed3c4626b33a744341ea529..366985982b94b92140026a428ce6aa456cc659dd 100644 (file)
@@ -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);