diff options
Diffstat (limited to 'src/common/iterators.c')
-rw-r--r-- | src/common/iterators.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/common/iterators.c b/src/common/iterators.c index d7441753..b1a54826 100644 --- a/src/common/iterators.c +++ b/src/common/iterators.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "gnunetgtk_common.h" | 27 | #include "gnunetgtk_common.h" |
28 | #include <GNUnet/gnunet_util_crypto.h> | 28 | #include <GNUnet/gnunet_util_crypto.h> |
29 | #include <glib.h> | 29 | #include <glib.h> |
30 | |||
30 | /** | 31 | /** |
31 | * Identical to "gtk_tree_selection_selected_foreach", | 32 | * Identical to "gtk_tree_selection_selected_foreach", |
32 | * except that modifications of the underlying model | 33 | * except that modifications of the underlying model |
@@ -75,3 +76,62 @@ void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection, | |||
75 | size, | 76 | size, |
76 | 0); | 77 | 0); |
77 | } | 78 | } |
79 | |||
80 | typedef struct { | ||
81 | GtkTreeRowReference ** refs; | ||
82 | unsigned int pos; | ||
83 | unsigned int size; | ||
84 | } CollectData; | ||
85 | |||
86 | static gboolean | ||
87 | collectAllRows(GtkTreeModel * model, | ||
88 | GtkTreePath * path, | ||
89 | GtkTreeIter * iter, | ||
90 | gpointer cls) { | ||
91 | CollectData * cd = cls; | ||
92 | |||
93 | if (cd->size == cd->pos) | ||
94 | GROW(cd->refs, | ||
95 | cd->size, | ||
96 | cd->size * 2 + 4); | ||
97 | cd->refs[cd->pos++] = gtk_tree_row_reference_new(model, | ||
98 | path); | ||
99 | return FALSE; | ||
100 | } | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Identical to "gtk_tree_model_foreach", | ||
105 | * except that modifications of the underlying model | ||
106 | * during the iteration are tolerated. | ||
107 | */ | ||
108 | void ggc_tree_model_foreach(GtkTreeModel * model, | ||
109 | GtkTreeSelectionForeachFunc func, | ||
110 | gpointer data) { | ||
111 | unsigned int i; | ||
112 | GtkTreePath * path; | ||
113 | GtkTreeIter iter; | ||
114 | CollectData cd; | ||
115 | |||
116 | memset(&cd, | ||
117 | 0, | ||
118 | sizeof(CollectData)); | ||
119 | gtk_tree_model_foreach(model, | ||
120 | &collectAllRows, | ||
121 | &cd); | ||
122 | for (i=0;i<cd.pos;i++) { | ||
123 | path = gtk_tree_row_reference_get_path(cd.refs[i]); | ||
124 | gtk_tree_row_reference_free(cd.refs[i]); | ||
125 | if (TRUE == gtk_tree_model_get_iter(model, | ||
126 | &iter, | ||
127 | path)) | ||
128 | func(model, | ||
129 | path, | ||
130 | &iter, | ||
131 | data); | ||
132 | gtk_tree_path_free(path); | ||
133 | } | ||
134 | GROW(cd.refs, | ||
135 | cd.size, | ||
136 | 0); | ||
137 | } | ||