diff options
author | Christian Grothoff <christian@grothoff.org> | 2008-05-27 02:50:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2008-05-27 02:50:49 +0000 |
commit | 73f26eebe1fb1b92753b5c99884a09020085ea91 (patch) | |
tree | 260f891c4b5778c34d5f2f9328e74220b85c3551 | |
parent | 573e31724848a11b4a45e46aa908d811071293ea (diff) | |
download | gnunet-gtk-73f26eebe1fb1b92753b5c99884a09020085ea91.tar.gz gnunet-gtk-73f26eebe1fb1b92753b5c99884a09020085ea91.zip |
always create pixbuf
-rw-r--r-- | src/plugins/fs/search.c | 203 |
1 files changed, 113 insertions, 90 deletions
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index 77214f76..e42474de 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -97,6 +97,97 @@ updateSearchSummary (SearchList * searchContext) | |||
97 | GNUNET_free (new_title); | 97 | GNUNET_free (new_title); |
98 | } | 98 | } |
99 | 99 | ||
100 | static GdkPixbuf * | ||
101 | make_ranking_pixbuf(int availability_rank, | ||
102 | unsigned int availability_certainty, | ||
103 | unsigned int applicability_rank) | ||
104 | { | ||
105 | GdkPixbuf *pixbuf; | ||
106 | guchar * pixels; | ||
107 | guchar * pixel; | ||
108 | int n_channels; | ||
109 | int rowstride; | ||
110 | unsigned int x; | ||
111 | unsigned int y; | ||
112 | unsigned int kwords; | ||
113 | |||
114 | #define P_HEIGHT 21 | ||
115 | #define P_WIDTH 60 | ||
116 | pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, | ||
117 | TRUE, /* alpha */ | ||
118 | 8, /* bits per sample */ | ||
119 | P_WIDTH, /* width */ | ||
120 | P_HEIGHT /* height */ | ||
121 | ); | ||
122 | n_channels = gdk_pixbuf_get_n_channels (pixbuf); | ||
123 | pixels = gdk_pixbuf_get_pixels(pixbuf); | ||
124 | rowstride = gdk_pixbuf_get_rowstride(pixbuf); | ||
125 | for (x=0;x<P_WIDTH;x++) | ||
126 | for (y=0;y<P_HEIGHT;y++) | ||
127 | { | ||
128 | pixel = pixels + y * rowstride + x * n_channels; | ||
129 | #define PX_RED 0 | ||
130 | #define PX_GREEN 1 | ||
131 | #define PX_BLUE 2 | ||
132 | #define PX_ALPHA 3 | ||
133 | pixel[PX_RED] = 0; | ||
134 | pixel[PX_GREEN] = 0; | ||
135 | pixel[PX_BLUE] = 0; | ||
136 | pixel[PX_ALPHA] = 0; | ||
137 | if (y < P_HEIGHT / 2) | ||
138 | { | ||
139 | /* applicability */ | ||
140 | if (x * kwords < applicability_rank * P_WIDTH) | ||
141 | { | ||
142 | pixel[PX_RED] = 0; | ||
143 | pixel[PX_GREEN] = 0; | ||
144 | pixel[PX_BLUE] = 255; | ||
145 | pixel[PX_ALPHA] = 255; | ||
146 | } | ||
147 | } | ||
148 | else if ( (y > P_HEIGHT / 2) && | ||
149 | ( (y-P_HEIGHT/2) * GNUNET_FSUI_MAX_PROBES | ||
150 | < availability_certainty * P_HEIGHT / 2) ) | ||
151 | { | ||
152 | /* availability */ | ||
153 | if (availability_rank < 0) | ||
154 | { | ||
155 | if ( (x * GNUNET_FSUI_MAX_PROBES > -availability_rank * P_WIDTH/2) && | ||
156 | (x <= P_WIDTH/2) ) | ||
157 | { | ||
158 | pixel[PX_RED] = 255; | ||
159 | pixel[PX_GREEN] = 0; | ||
160 | pixel[PX_BLUE] = 0; | ||
161 | pixel[PX_ALPHA] = 255; | ||
162 | } | ||
163 | } | ||
164 | else if (availability_rank > 0) | ||
165 | { | ||
166 | if ( (x >= P_WIDTH/2) && | ||
167 | ( (x - (P_WIDTH/2)) * GNUNET_FSUI_MAX_PROBES < availability_rank * P_WIDTH/2) ) | ||
168 | { | ||
169 | pixel[PX_RED] = 0; | ||
170 | pixel[PX_GREEN] = 255; | ||
171 | pixel[PX_BLUE] = 0; | ||
172 | pixel[PX_ALPHA] = 255; | ||
173 | } | ||
174 | } | ||
175 | else | ||
176 | { | ||
177 | if (x == P_WIDTH / 2) | ||
178 | { | ||
179 | /* yellow */ | ||
180 | pixel[PX_RED] = 255; | ||
181 | pixel[PX_GREEN] = 255; | ||
182 | pixel[PX_BLUE] = 0; | ||
183 | pixel[PX_ALPHA] = 255; | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | return pixbuf; | ||
189 | } | ||
190 | |||
100 | /** | 191 | /** |
101 | * Add the given search result to the search | 192 | * Add the given search result to the search |
102 | * tree at the specified position. | 193 | * tree at the specified position. |
@@ -112,6 +203,7 @@ addEntryToSearchTree (SearchList * searchContext, | |||
112 | unsigned long long size; | 203 | unsigned long long size; |
113 | char *size_h; | 204 | char *size_h; |
114 | GdkPixbuf *pixbuf; | 205 | GdkPixbuf *pixbuf; |
206 | GdkPixbuf *rankbuf; | ||
115 | enum GNUNET_URITRACK_STATE state; | 207 | enum GNUNET_URITRACK_STATE state; |
116 | 208 | ||
117 | state = GNUNET_URITRACK_get_state (ectx, cfg, info->uri); | 209 | state = GNUNET_URITRACK_get_state (ectx, cfg, info->uri); |
@@ -125,6 +217,7 @@ addEntryToSearchTree (SearchList * searchContext, | |||
125 | 0; | 217 | 0; |
126 | pixbuf = getThumbnailFromMetaData (info->meta); | 218 | pixbuf = getThumbnailFromMetaData (info->meta); |
127 | size_h = GNUNET_get_byte_size_as_fancy_string (size); | 219 | size_h = GNUNET_get_byte_size_as_fancy_string (size); |
220 | rankbuf = make_ranking_pixbuf(0, 0, 1); | ||
128 | gtk_tree_store_set (searchContext->tree, | 221 | gtk_tree_store_set (searchContext->tree, |
129 | iter, | 222 | iter, |
130 | SEARCH_NAME, name, | 223 | SEARCH_NAME, name, |
@@ -134,12 +227,17 @@ addEntryToSearchTree (SearchList * searchContext, | |||
134 | SEARCH_DESC, desc, | 227 | SEARCH_DESC, desc, |
135 | SEARCH_PIXBUF, pixbuf, | 228 | SEARCH_PIXBUF, pixbuf, |
136 | SEARCH_URI, GNUNET_ECRS_uri_duplicate (info->uri), | 229 | SEARCH_URI, GNUNET_ECRS_uri_duplicate (info->uri), |
137 | SEARCH_META, | 230 | SEARCH_META, GNUNET_ECRS_meta_data_duplicate (info->meta), |
138 | GNUNET_ECRS_meta_data_duplicate (info->meta), | ||
139 | SEARCH_CELL_BG_COLOR, getColorCode (state), | 231 | SEARCH_CELL_BG_COLOR, getColorCode (state), |
140 | SEARCH_CELL_FG_COLOR, "black", SEARCH_INTERNAL, | 232 | SEARCH_CELL_FG_COLOR, "black", |
141 | searchContext, SEARCH_INTERNAL_PARENT, downloadParent, | 233 | SEARCH_INTERNAL, searchContext, |
142 | SEARCH_STATUS, getStatusName (state), -1); | 234 | SEARCH_INTERNAL_PARENT, downloadParent, |
235 | SEARCH_STATUS, getStatusName (state), | ||
236 | SEARCH_APPLICABILITY_RANK, 1, | ||
237 | SEARCH_RANK_SORT, (long long) 1, | ||
238 | SEARCH_RANK_PIXBUF, rankbuf, | ||
239 | -1); | ||
240 | g_object_unref(rankbuf); | ||
143 | if (pixbuf != NULL) | 241 | if (pixbuf != NULL) |
144 | g_object_unref (pixbuf); | 242 | g_object_unref (pixbuf); |
145 | GNUNET_free (size_h); | 243 | GNUNET_free (size_h); |
@@ -212,13 +310,7 @@ void fs_search_update (SearchList * searchContext, | |||
212 | GtkTreeIter iter; | 310 | GtkTreeIter iter; |
213 | struct GNUNET_ECRS_URI *have; | 311 | struct GNUNET_ECRS_URI *have; |
214 | GdkPixbuf *pixbuf; | 312 | GdkPixbuf *pixbuf; |
215 | guchar * pixels; | ||
216 | guchar * pixel; | ||
217 | long long rank; | 313 | long long rank; |
218 | int n_channels; | ||
219 | int rowstride; | ||
220 | unsigned int x; | ||
221 | unsigned int y; | ||
222 | unsigned int kwords; | 314 | unsigned int kwords; |
223 | 315 | ||
224 | kwords = GNUNET_ECRS_uri_get_keyword_count_from_ksk(searchContext->uri); | 316 | kwords = GNUNET_ECRS_uri_get_keyword_count_from_ksk(searchContext->uri); |
@@ -236,81 +328,9 @@ void fs_search_update (SearchList * searchContext, | |||
236 | { | 328 | { |
237 | /* gotcha, create pixbuf and rank info! */ | 329 | /* gotcha, create pixbuf and rank info! */ |
238 | rank = (int) applicability_rank + (int) (availability_rank * (int) availability_certainty * 65536); | 330 | rank = (int) applicability_rank + (int) (availability_rank * (int) availability_certainty * 65536); |
239 | #define P_HEIGHT 21 | 331 | pixbuf = make_ranking_pixbuf(availability_rank, |
240 | #define P_WIDTH 100 | 332 | availability_certainty, |
241 | pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, | 333 | applicability_rank); |
242 | TRUE, /* alpha */ | ||
243 | 8, /* bits per sample */ | ||
244 | P_WIDTH, /* width */ | ||
245 | P_HEIGHT /* height */ | ||
246 | ); | ||
247 | n_channels = gdk_pixbuf_get_n_channels (pixbuf); | ||
248 | pixels = gdk_pixbuf_get_pixels(pixbuf); | ||
249 | rowstride = gdk_pixbuf_get_rowstride(pixbuf); | ||
250 | for (x=0;x<P_WIDTH;x++) | ||
251 | for (y=0;y<P_HEIGHT;y++) | ||
252 | { | ||
253 | pixel = pixels + y * rowstride + x * n_channels; | ||
254 | #define PX_RED 0 | ||
255 | #define PX_GREEN 1 | ||
256 | #define PX_BLUE 2 | ||
257 | #define PX_ALPHA 3 | ||
258 | pixel[PX_RED] = 0; | ||
259 | pixel[PX_GREEN] = 0; | ||
260 | pixel[PX_BLUE] = 0; | ||
261 | pixel[PX_ALPHA] = 0; | ||
262 | if (y < P_HEIGHT / 2) | ||
263 | { | ||
264 | /* applicability */ | ||
265 | if (x * kwords < applicability_rank * P_WIDTH) | ||
266 | { | ||
267 | pixel[PX_RED] = 0; | ||
268 | pixel[PX_GREEN] = 0; | ||
269 | pixel[PX_BLUE] = 255; | ||
270 | pixel[PX_ALPHA] = 255; | ||
271 | } | ||
272 | } | ||
273 | else if ( (y > P_HEIGHT / 2) && | ||
274 | ( (y-P_HEIGHT/2) * GNUNET_FSUI_MAX_PROBES | ||
275 | < availability_certainty * P_HEIGHT / 2) ) | ||
276 | { | ||
277 | /* availability */ | ||
278 | if (availability_rank < 0) | ||
279 | { | ||
280 | if ( (x * GNUNET_FSUI_MAX_PROBES > -availability_rank * P_WIDTH/2) && | ||
281 | (x <= P_WIDTH/2) ) | ||
282 | { | ||
283 | pixel[PX_RED] = 255; | ||
284 | pixel[PX_GREEN] = 0; | ||
285 | pixel[PX_BLUE] = 0; | ||
286 | pixel[PX_ALPHA] = 255; | ||
287 | } | ||
288 | } | ||
289 | else if (availability_rank > 0) | ||
290 | { | ||
291 | if ( (x >= P_WIDTH/2) && | ||
292 | ( (x - (P_WIDTH/2)) * GNUNET_FSUI_MAX_PROBES < availability_rank * P_WIDTH/2) ) | ||
293 | { | ||
294 | pixel[PX_RED] = 0; | ||
295 | pixel[PX_GREEN] = 255; | ||
296 | pixel[PX_BLUE] = 0; | ||
297 | pixel[PX_ALPHA] = 255; | ||
298 | } | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | if (x == P_WIDTH / 2) | ||
303 | { | ||
304 | /* yellow */ | ||
305 | pixel[PX_RED] = 255; | ||
306 | pixel[PX_GREEN] = 255; | ||
307 | pixel[PX_BLUE] = 0; | ||
308 | pixel[PX_ALPHA] = 255; | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | |||
314 | gtk_tree_store_set(searchContext->tree, | 334 | gtk_tree_store_set(searchContext->tree, |
315 | &iter, | 335 | &iter, |
316 | SEARCH_AVAILABILITY_RANK, availability_rank, | 336 | SEARCH_AVAILABILITY_RANK, availability_rank, |
@@ -678,8 +698,8 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
678 | gtk_tree_view_column_set_reorderable (column, TRUE); | 698 | gtk_tree_view_column_set_reorderable (column, TRUE); |
679 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_MIME); | 699 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_MIME); |
680 | 700 | ||
681 | 701 | #if 0 | |
682 | 702 | /* colums for data visualized graphically */ | |
683 | renderer = gtk_cell_renderer_text_new (); | 703 | renderer = gtk_cell_renderer_text_new (); |
684 | gtk_tree_view_insert_column_with_attributes (list->treeview, | 704 | gtk_tree_view_insert_column_with_attributes (list->treeview, |
685 | -1, | 705 | -1, |
@@ -708,7 +728,7 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
708 | renderer, | 728 | renderer, |
709 | "text", SEARCH_RANK_SORT, | 729 | "text", SEARCH_RANK_SORT, |
710 | NULL); | 730 | NULL); |
711 | 731 | #endif | |
712 | 732 | ||
713 | renderer = gtk_cell_renderer_pixbuf_new (); | 733 | renderer = gtk_cell_renderer_pixbuf_new (); |
714 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, | 734 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, |
@@ -821,7 +841,10 @@ freeIterSubtree (GtkTreeModel * tree, GtkTreeIter * iter) | |||
821 | if (meta != NULL) | 841 | if (meta != NULL) |
822 | GNUNET_ECRS_meta_data_destroy (meta); | 842 | GNUNET_ECRS_meta_data_destroy (meta); |
823 | gtk_tree_store_set (GTK_TREE_STORE (tree), | 843 | gtk_tree_store_set (GTK_TREE_STORE (tree), |
824 | iter, SEARCH_URI, NULL, SEARCH_META, NULL, -1); | 844 | iter, |
845 | SEARCH_URI, NULL, | ||
846 | SEARCH_META, NULL, | ||
847 | -1); | ||
825 | if (gtk_tree_model_iter_children (tree, &child, iter)) | 848 | if (gtk_tree_model_iter_children (tree, &child, iter)) |
826 | freeIterSubtree (tree, &child); | 849 | freeIterSubtree (tree, &child); |
827 | } | 850 | } |