2007-11-15 10:02:25 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-11-29 15:01:21 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_FOO,
|
|
|
|
COLUMN_BAR,
|
|
|
|
|
|
|
|
N_COLUMNS
|
|
|
|
};
|
|
|
|
|
2007-11-15 10:02:25 +00:00
|
|
|
static void
|
2007-12-14 17:25:55 +00:00
|
|
|
print_iter (ClutterModelIter *iter,
|
|
|
|
const gchar *text)
|
2007-11-15 10:02:25 +00:00
|
|
|
{
|
2007-11-29 15:01:21 +00:00
|
|
|
ClutterModel *model;
|
2007-11-15 10:02:25 +00:00
|
|
|
gint i;
|
|
|
|
gchar *string;
|
|
|
|
|
2007-11-29 15:01:21 +00:00
|
|
|
model = clutter_model_iter_get_model (iter);
|
2007-12-14 17:25:55 +00:00
|
|
|
|
2007-11-29 15:01:21 +00:00
|
|
|
clutter_model_iter_get (iter, COLUMN_FOO, &i, COLUMN_BAR, &string, -1);
|
|
|
|
|
2007-12-14 17:25:55 +00:00
|
|
|
g_print ("[row:%02d]: %s: (%s: %d), (%s: %s)\n",
|
|
|
|
clutter_model_iter_get_row (iter),
|
2007-11-29 15:01:21 +00:00
|
|
|
text,
|
|
|
|
clutter_model_get_column_name (model, COLUMN_FOO), i,
|
|
|
|
clutter_model_get_column_name (model, COLUMN_BAR), string);
|
|
|
|
|
2007-11-15 10:02:25 +00:00
|
|
|
g_free (string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-12-14 17:25:55 +00:00
|
|
|
foreach_func (ClutterModel *model,
|
|
|
|
ClutterModelIter *iter,
|
|
|
|
gpointer dummy)
|
2007-11-15 10:02:25 +00:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gchar *string;
|
|
|
|
|
2007-11-29 15:01:21 +00:00
|
|
|
clutter_model_iter_get (iter, COLUMN_FOO, &i, COLUMN_BAR, &string, -1);
|
2007-12-14 17:25:55 +00:00
|
|
|
|
|
|
|
g_print ("[row:%02d]: Foreach: %d, %s\n",
|
|
|
|
clutter_model_iter_get_row (iter),
|
|
|
|
i, string);
|
2007-11-15 10:02:25 +00:00
|
|
|
|
|
|
|
g_free (string);
|
2007-12-14 17:25:55 +00:00
|
|
|
|
2007-11-15 10:02:25 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-12-14 17:25:55 +00:00
|
|
|
filter_func (ClutterModel *model,
|
|
|
|
ClutterModelIter *iter,
|
|
|
|
gpointer dummy)
|
2007-11-15 10:02:25 +00:00
|
|
|
{
|
|
|
|
gint i = 0;
|
|
|
|
|
2007-11-29 15:01:21 +00:00
|
|
|
clutter_model_iter_get (iter, COLUMN_FOO, &i, -1);
|
2007-11-15 10:02:25 +00:00
|
|
|
|
|
|
|
return !(i % 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
sort_func (ClutterModel *model,
|
|
|
|
const GValue *a,
|
|
|
|
const GValue *b,
|
2007-12-14 17:25:55 +00:00
|
|
|
gpointer dummy)
|
2007-11-15 10:02:25 +00:00
|
|
|
{
|
|
|
|
return -1 * strcmp (g_value_get_string (a), g_value_get_string (b));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-14 17:25:55 +00:00
|
|
|
on_row_changed (ClutterModel *model,
|
|
|
|
ClutterModelIter *iter)
|
2007-11-15 10:02:25 +00:00
|
|
|
{
|
|
|
|
print_iter (iter, "Changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
filter_model (ClutterModel *model)
|
|
|
|
{
|
|
|
|
ClutterModelIter *iter;
|
|
|
|
|
2007-12-15 13:02:06 +00:00
|
|
|
g_print ("\n* Filter function: even rows\n");
|
2007-11-15 10:02:25 +00:00
|
|
|
clutter_model_set_filter (model, filter_func, NULL, NULL);
|
|
|
|
|
|
|
|
iter = clutter_model_get_first_iter (model);
|
|
|
|
while (!clutter_model_iter_is_last (iter))
|
2007-12-14 17:25:55 +00:00
|
|
|
{
|
|
|
|
print_iter (iter, "Filtered Forward Iteration");
|
|
|
|
|
|
|
|
iter = clutter_model_iter_next (iter);
|
|
|
|
}
|
2007-11-15 10:02:25 +00:00
|
|
|
g_object_unref (iter);
|
|
|
|
|
2007-12-15 13:02:06 +00:00
|
|
|
g_print ("\n* Sorting function: reverse alpha\n");
|
2007-11-29 15:01:21 +00:00
|
|
|
clutter_model_set_sort (model, COLUMN_BAR, sort_func, NULL, NULL);
|
2007-11-15 10:02:25 +00:00
|
|
|
|
2007-12-14 17:25:55 +00:00
|
|
|
g_signal_connect (model, "row-changed", G_CALLBACK (on_row_changed), NULL);
|
2007-11-15 10:02:25 +00:00
|
|
|
|
|
|
|
iter = clutter_model_get_iter_at_row (model, 0);
|
2007-11-29 15:01:21 +00:00
|
|
|
clutter_model_iter_set (iter, COLUMN_BAR, "Changed string of 0th row, "
|
|
|
|
"automatically gets sorted",
|
|
|
|
-1);
|
2007-11-15 10:02:25 +00:00
|
|
|
g_object_unref (iter);
|
|
|
|
|
|
|
|
clutter_model_foreach (model, foreach_func, NULL);
|
|
|
|
|
2007-12-15 13:02:06 +00:00
|
|
|
g_print ("\n* Unset filter\n");
|
2007-11-15 10:02:25 +00:00
|
|
|
clutter_model_set_filter (model, NULL, NULL, NULL);
|
2007-12-14 17:25:55 +00:00
|
|
|
|
2007-11-15 10:02:25 +00:00
|
|
|
while (clutter_model_get_n_rows (model))
|
|
|
|
clutter_model_remove (model, 0);
|
|
|
|
|
|
|
|
clutter_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
iterate (ClutterModel *model)
|
|
|
|
{
|
|
|
|
ClutterModelIter *iter;
|
|
|
|
|
|
|
|
iter = clutter_model_get_first_iter (model);
|
|
|
|
|
|
|
|
while (!clutter_model_iter_is_last (iter))
|
2007-12-14 17:25:55 +00:00
|
|
|
{
|
|
|
|
print_iter (iter, "Forward Iteration");
|
|
|
|
iter = clutter_model_iter_next (iter);
|
|
|
|
}
|
2007-11-15 10:02:25 +00:00
|
|
|
g_object_unref (iter);
|
|
|
|
|
|
|
|
iter = clutter_model_get_last_iter (model);
|
|
|
|
do
|
2007-12-14 17:25:55 +00:00
|
|
|
{
|
|
|
|
print_iter (iter, "Reverse Iteration");
|
|
|
|
iter = clutter_model_iter_prev (iter);
|
|
|
|
}
|
2007-11-15 10:02:25 +00:00
|
|
|
while (!clutter_model_iter_is_first (iter));
|
|
|
|
|
|
|
|
print_iter (iter, "Reverse Iteration");
|
|
|
|
g_object_unref (iter);
|
|
|
|
|
|
|
|
filter_model (model);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
populate_model (ClutterModel *model)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
gchar *string = g_strdup_printf ("String %d", i);
|
|
|
|
|
|
|
|
clutter_model_append (model,
|
2007-11-29 15:01:21 +00:00
|
|
|
COLUMN_FOO, i,
|
|
|
|
COLUMN_BAR, string,
|
2007-11-15 10:02:25 +00:00
|
|
|
-1);
|
|
|
|
g_free (string);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_model_foreach (model, foreach_func, NULL);
|
|
|
|
iterate (model);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-14 17:25:55 +00:00
|
|
|
on_row_added (ClutterModel *model,
|
|
|
|
ClutterModelIter *iter,
|
|
|
|
gpointer dummy)
|
2007-11-15 10:02:25 +00:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gchar *string;
|
|
|
|
|
2007-11-29 15:01:21 +00:00
|
|
|
clutter_model_iter_get (iter, COLUMN_FOO, &i, COLUMN_BAR, &string, -1);
|
2007-11-15 10:02:25 +00:00
|
|
|
|
2007-12-14 17:25:55 +00:00
|
|
|
g_print ("[row:%02d]: Added: %d, %s\n",
|
|
|
|
clutter_model_iter_get_row (iter),
|
|
|
|
i, string);
|
2007-11-15 10:02:25 +00:00
|
|
|
|
|
|
|
g_free (string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-14 17:25:55 +00:00
|
|
|
on_row_removed (ClutterModel *model,
|
|
|
|
ClutterModelIter *iter,
|
|
|
|
gpointer dummy)
|
2007-11-15 10:02:25 +00:00
|
|
|
{
|
|
|
|
print_iter (iter, "Removed");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_sort_changed (ClutterModel *model)
|
|
|
|
{
|
2007-12-15 13:02:06 +00:00
|
|
|
g_print ("*** Sort Changed ***\n\n");
|
2007-11-15 10:02:25 +00:00
|
|
|
clutter_model_foreach (model, foreach_func, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_filter_changed (ClutterModel *model)
|
|
|
|
{
|
2007-12-15 13:02:06 +00:00
|
|
|
g_print ("*** Filter Changed ***\n\n");
|
2007-11-15 10:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ClutterModel *model;
|
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
2007-12-14 17:25:55 +00:00
|
|
|
model = clutter_model_default_new (N_COLUMNS,
|
|
|
|
G_TYPE_INT, "Foo",
|
|
|
|
G_TYPE_STRING, "Bar");
|
2007-11-15 10:02:25 +00:00
|
|
|
|
2007-12-14 17:25:55 +00:00
|
|
|
g_timeout_add (1000, (GSourceFunc) populate_model, model);
|
2007-11-15 10:02:25 +00:00
|
|
|
|
|
|
|
g_signal_connect (model, "row-added",
|
|
|
|
G_CALLBACK (on_row_added), NULL);
|
|
|
|
g_signal_connect (model, "row-removed",
|
|
|
|
G_CALLBACK (on_row_removed), NULL);
|
|
|
|
g_signal_connect (model, "sort-changed",
|
|
|
|
G_CALLBACK (on_sort_changed), NULL);
|
|
|
|
g_signal_connect (model, "filter-changed",
|
|
|
|
G_CALLBACK (on_filter_changed), NULL);
|
|
|
|
|
|
|
|
clutter_main();
|
|
|
|
|
|
|
|
g_object_unref (model);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|