aboutsummaryrefslogtreecommitdiff
path: root/src/common/iterators.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/iterators.c')
-rw-r--r--src/common/iterators.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/common/iterators.c b/src/common/iterators.c
new file mode 100644
index 00000000..36fe7dba
--- /dev/null
+++ b/src/common/iterators.c
@@ -0,0 +1,74 @@
1/*
2 This file is part of GNUnet
3 (C) 2006 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file src/common/iterators.c
22 * @brief This file contains GTK helper functions related to iterations
23 * @author Igor Wronsky
24 * @author Christian Grothoff
25 */
26
27/**
28 * Identical to "gtk_tree_selection_selected_foreach",
29 * except that modifications of the underlying model
30 * during the iteration are tolerated.
31 */
32void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection,
33 GtkTreeSelectionForeachFunc func,
34 gpointer data) {
35 unsigned int i;
36 unsigned int size;
37 GList * selected;
38 GtkTreeRowReference ** refs;
39 GtkTreeModel * model;
40 GtkTreePath * path;
41 GtkTreeIter iter;
42
43 selected = gtk_tree_selection_get_selected_rows(selection,
44 &model);
45
46 i = g_list_length(selected);
47 size = 0;
48 refs = NULL;
49 GROW(refs,
50 size,
51 i);
52 for (i=0;i<size;i++)
53 refs[i] = gtk_tree_row_reference_new(model,
54 g_list_nth_data(selected, i));
55 g_list_foreach(selected,
56 (GFunc) &gtk_tree_path_free,
57 NULL);
58 g_list_free(selected);
59 for (i=0;i<size;i++) {
60 path = gtk_tree_row_reference_get_path(refs[i]);
61 gtk_tree_row_reference_free(refs[i]);
62 if (TRUE == gtk_tree_model_get_iter(model,
63 &iter,
64 path))
65 func(model,
66 path,
67 &iter,
68 data);
69 gtk_tree_path_free(path);
70 }
71 GROW(refs,
72 size,
73 0);
74}