}
static GtkTreeIter
-*solipa_gtktreemodel_get_iter_child (GtkTreeIter *iter, GtkTreeModel **models, guint n_models)
+*solipa_gtktreemodel_get_iter_child (GtkTreeIter *iter, GPtrArray *models)
{
+ GtkTreeModel *model;
GtkTreeIter *iter_parent;
GtkTreeIter *iter_child;
iter_parent = iter;
iter_child = (GtkTreeIter *)g_malloc0 (sizeof (GtkTreeIter));
- for (n = 0; n < (n_models - 1); n++)
+ for (n = 0; n < (models->len - 1); n++)
{
- if (GTK_IS_TREE_MODEL_SORT (models[n]))
+ model = (GtkTreeModel *)g_ptr_array_index (models, n);
+ if (GTK_IS_TREE_MODEL_SORT (model))
{
- gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (models[n]),
+ gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (model),
iter_child, iter_parent);
iter_parent = iter_child;
iter_child = (GtkTreeIter *)g_malloc0 (sizeof (GtkTreeIter));
}
- else if (GTK_IS_TREE_MODEL_FILTER (models[n]))
+ else if (GTK_IS_TREE_MODEL_FILTER (model))
{
- gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (models[n]),
+ gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
iter_child, iter_parent);
iter_parent = iter_child;
iter_child = (GtkTreeIter *)g_malloc0 (sizeof (GtkTreeIter));
static void
solipa_gtktreemodel_copy_iter (GtkTreeModel *ret,
GtkTreeModel *model,
- GtkTreeModel **models,
- guint n_models,
+ GPtrArray *models,
gboolean is_list_store,
guint cols,
GtkTreeIter *iter,
{
gtk_tree_store_append (GTK_TREE_STORE (ret), &iter_new, iter_parent);
}
-continue;
- iter_child = solipa_gtktreemodel_get_iter_child (iter, models, n_models);
+
+ iter_child = solipa_gtktreemodel_get_iter_child (iter, models);
for (col = 0; col < cols; col++)
{
GValue gval = {0};
- gtk_tree_model_get_value (models[n_models - 1],
+ gtk_tree_model_get_value ((GtkTreeModel *)g_ptr_array_index (models, models->len - 1),
iter_child,
col, &gval);
if (gtk_tree_model_iter_children (model, &iter_children, iter_child))
{
- solipa_gtktreemodel_copy_iter (ret, model, models, n_models, is_list_store, cols, &iter_children, &iter_new);
+ solipa_gtktreemodel_copy_iter (ret, model, models, is_list_store, cols, &iter_children, &iter_new);
}
}
} while (gtk_tree_model_iter_next (model, iter));
}
static void
-solipa_gtktreemodel_get_models_chain (GtkTreeModel *model, GtkTreeModel **models, guint *n_models)
+solipa_gtktreemodel_get_models_chain (GtkTreeModel *model, GPtrArray *models)
{
+ GtkTreeModel *my_model;
+
if (GTK_IS_TREE_MODEL_SORT (model))
{
- *n_models = *n_models + 1;
- models = (GtkTreeModel **)g_realloc (models, *n_models * sizeof (GtkTreeModel *));
-
- models[*n_models - 1] = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model));
+ my_model = (gpointer)gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model));
+ g_ptr_array_add (models, my_model);
- solipa_gtktreemodel_get_models_chain (models[*n_models - 1], models, n_models);
+ solipa_gtktreemodel_get_models_chain (my_model, models);
}
else if (GTK_IS_TREE_MODEL_FILTER (model))
{
- *n_models = *n_models + 1;
- models = (GtkTreeModel **)g_realloc (models, *n_models * sizeof (GtkTreeModel *));
+ my_model = (gpointer)gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
+ g_ptr_array_add (models, my_model);
- models[*n_models - 1] = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
-
- solipa_gtktreemodel_get_models_chain (models[*n_models - 1], models, n_models);
+ solipa_gtktreemodel_get_models_chain (my_model, models);
}
}
GType *gtypes;
guint cols;
- guint col;
- guint n_models;
- GtkTreeModel **models;
+ GPtrArray *models; /* GtkTreeModel */
GtkTreeIter iter;
ret = NULL;
gtypes = solipa_gtktreemodel_get_gtypes (model, &cols);
- if (gtypes != NULL)
+ if (gtypes != NULL && cols > 0)
{
- n_models = 1;
- models = (GtkTreeModel **)g_malloc0 (sizeof (GtkTreeModel *));
- models[0] = model;
+ models = g_ptr_array_new ();
+ g_ptr_array_add (models, (gpointer)model);
if (GTK_IS_TREE_MODEL_SORT (model) ||
GTK_IS_TREE_MODEL_FILTER (model))
{
- solipa_gtktreemodel_get_models_chain (model, models, &n_models);
+ solipa_gtktreemodel_get_models_chain (model, models);
}
- if (GTK_IS_LIST_STORE (models[n_models - 1]))
+ if (GTK_IS_LIST_STORE ((GtkTreeModel *)g_ptr_array_index (models, models->len - 1)))
{
ret = GTK_TREE_MODEL (gtk_list_store_newv (cols, gtypes));
{
if (gtk_tree_model_get_iter_first (model, &iter))
{
- solipa_gtktreemodel_copy_iter (ret, model, models, n_models, TRUE, cols, &iter, NULL);
+ solipa_gtktreemodel_copy_iter (ret, model, models, TRUE, cols, &iter, NULL);
}
}
}
- else if (GTK_IS_TREE_STORE (models[n_models - 1]))
+ else if (GTK_IS_TREE_STORE ((GtkTreeModel *)g_ptr_array_index (models, models->len - 1)))
{
ret = GTK_TREE_MODEL (gtk_tree_store_newv (cols, gtypes));
{
if (gtk_tree_model_get_iter_first (model, &iter))
{
- solipa_gtktreemodel_copy_iter (ret, model, models, n_models, FALSE, cols, &iter, NULL);
+ solipa_gtktreemodel_copy_iter (ret, model, models, FALSE, cols, &iter, NULL);
}
}
}
{
g_warning ("GtkTreeModel type not expected.");
}
+
+ g_ptr_array_free (models, TRUE);
}
return ret;