diff options
Diffstat (limited to 'src/plugins/fs/search.c')
-rw-r--r-- | src/plugins/fs/search.c | 125 |
1 files changed, 122 insertions, 3 deletions
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index 1b33b5af..d0f8e7ca 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -211,7 +211,17 @@ void fs_search_update (SearchList * searchContext, | |||
211 | GtkTreeStore *model; | 211 | GtkTreeStore *model; |
212 | GtkTreeIter iter; | 212 | GtkTreeIter iter; |
213 | struct GNUNET_ECRS_URI *have; | 213 | struct GNUNET_ECRS_URI *have; |
214 | 214 | GdkPixbuf *pixbuf; | |
215 | guchar * pixels; | ||
216 | guchar * pixel; | ||
217 | long long rank; | ||
218 | int n_channels; | ||
219 | int rowstride; | ||
220 | unsigned int x; | ||
221 | unsigned int y; | ||
222 | unsigned int kwords; | ||
223 | |||
224 | kwords = GNUNET_ECRS_uri_get_keyword_count_from_ksk(searchContext->uri); | ||
215 | model = GTK_TREE_STORE (gtk_tree_view_get_model (searchContext->treeview)); | 225 | model = GTK_TREE_STORE (gtk_tree_view_get_model (searchContext->treeview)); |
216 | /* find existing entry */ | 226 | /* find existing entry */ |
217 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) | 227 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) |
@@ -224,13 +234,105 @@ void fs_search_update (SearchList * searchContext, | |||
224 | if ( (have != NULL) && | 234 | if ( (have != NULL) && |
225 | (GNUNET_ECRS_uri_test_equal (have, info->uri)) ) | 235 | (GNUNET_ECRS_uri_test_equal (have, info->uri)) ) |
226 | { | 236 | { |
227 | /* gotcha! */ | 237 | /* gotcha, create pixbuf and rank info! */ |
238 | rank = (applicability_rank << 30) + (availability_rank * availability_certainty); | ||
239 | #define P_HEIGHT 11 | ||
240 | #define P_WIDTH 10 | ||
241 | pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, | ||
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 | if (y < P_HEIGHT / 2) | ||
259 | { | ||
260 | /* applicability */ | ||
261 | if (x * kwords < applicability_rank * P_WIDTH) | ||
262 | { | ||
263 | pixel[PX_RED] = 0; | ||
264 | pixel[PX_GREEN] = 255; | ||
265 | pixel[PX_BLUE] = 0; | ||
266 | pixel[PX_ALPHA] = 0; | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | pixel[PX_RED] = 0; | ||
271 | pixel[PX_GREEN] = 0; | ||
272 | pixel[PX_BLUE] = 0; | ||
273 | pixel[PX_ALPHA] = 255; | ||
274 | } | ||
275 | } | ||
276 | else if (y > P_HEIGHT / 2) | ||
277 | { | ||
278 | /* availability */ | ||
279 | pixel[PX_RED] = 0; | ||
280 | pixel[PX_GREEN] = 0; | ||
281 | pixel[PX_BLUE] = 0; | ||
282 | pixel[PX_ALPHA] = 255; | ||
283 | if (availability_rank < 0) | ||
284 | { | ||
285 | if ( (x * GNUNET_FSUI_MAX_PROBES > -availability_rank * P_WIDTH/2) && | ||
286 | (x <= P_WIDTH/2) ) | ||
287 | { | ||
288 | pixel[PX_RED] = 255; | ||
289 | pixel[PX_GREEN] = 0; | ||
290 | pixel[PX_BLUE] = 0; | ||
291 | pixel[PX_ALPHA] = 0; | ||
292 | } | ||
293 | } | ||
294 | else if (availability_rank > 0) | ||
295 | { | ||
296 | if ( (x - (P_WIDTH/2) * GNUNET_FSUI_MAX_PROBES < availability_rank * P_WIDTH/2) && | ||
297 | (x >= P_WIDTH/2) ) | ||
298 | { | ||
299 | pixel[PX_RED] = 0; | ||
300 | pixel[PX_GREEN] = 255; | ||
301 | pixel[PX_BLUE] = 0; | ||
302 | pixel[PX_ALPHA] = 0; | ||
303 | } | ||
304 | } | ||
305 | else | ||
306 | { | ||
307 | if (x == P_WIDTH / 2) | ||
308 | { | ||
309 | /* yellow */ | ||
310 | pixel[PX_RED] = 255; | ||
311 | pixel[PX_GREEN] = 255; | ||
312 | pixel[PX_BLUE] = 0; | ||
313 | pixel[PX_ALPHA] = 0; | ||
314 | } | ||
315 | } | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | /* 1px separator bar */ | ||
320 | pixel[PX_RED] = 0; | ||
321 | pixel[PX_GREEN] = 0; | ||
322 | pixel[PX_BLUE] = 0; | ||
323 | pixel[PX_ALPHA] = 255; | ||
324 | } | ||
325 | } | ||
326 | |||
228 | gtk_tree_store_set(searchContext->tree, | 327 | gtk_tree_store_set(searchContext->tree, |
229 | &iter, | 328 | &iter, |
230 | SEARCH_AVAILABILITY_RANK, availability_rank, | 329 | SEARCH_AVAILABILITY_RANK, availability_rank, |
231 | SEARCH_AVAILABILITY_CERTAINTY, availability_certainty, | 330 | SEARCH_AVAILABILITY_CERTAINTY, availability_certainty, |
232 | SEARCH_APPLICABILITY_RANK, applicability_rank, | 331 | SEARCH_APPLICABILITY_RANK, applicability_rank, |
332 | SEARCH_RANK_PIXBUF, pixbuf, | ||
333 | SEARCH_RANK_SORT, rank, | ||
233 | -1); | 334 | -1); |
335 | g_object_unref (pixbuf); | ||
234 | return; /* done! */ | 336 | return; /* done! */ |
235 | } | 337 | } |
236 | } | 338 | } |
@@ -512,7 +614,9 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
512 | G_TYPE_STRING, /* status */ | 614 | G_TYPE_STRING, /* status */ |
513 | G_TYPE_INT, /* availability rank */ | 615 | G_TYPE_INT, /* availability rank */ |
514 | G_TYPE_UINT, /* availability certainty */ | 616 | G_TYPE_UINT, /* availability certainty */ |
515 | G_TYPE_UINT /* applicability rank */ | 617 | G_TYPE_UINT, /* applicability rank */ |
618 | GDK_TYPE_PIXBUF, /* ranking visualization */ | ||
619 | G_TYPE_INT64 /* numeric sort */ | ||
516 | ); | 620 | ); |
517 | 621 | ||
518 | gtk_tree_view_set_model (list->treeview, GTK_TREE_MODEL (list->tree)); | 622 | gtk_tree_view_set_model (list->treeview, GTK_TREE_MODEL (list->tree)); |
@@ -587,6 +691,21 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
587 | gtk_tree_view_column_set_reorderable (column, TRUE); | 691 | gtk_tree_view_column_set_reorderable (column, TRUE); |
588 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_MIME); | 692 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_MIME); |
589 | 693 | ||
694 | |||
695 | renderer = gtk_cell_renderer_pixbuf_new (); | ||
696 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, | ||
697 | -1, | ||
698 | _("Ranking"), | ||
699 | renderer, | ||
700 | "pixbuf", SEARCH_RANK_PIXBUF, | ||
701 | NULL); | ||
702 | column = gtk_tree_view_get_column (list->treeview, col - 1); | ||
703 | gtk_tree_view_column_set_resizable (column, FALSE); | ||
704 | gtk_tree_view_column_set_clickable (column, TRUE); | ||
705 | gtk_tree_view_column_set_reorderable (column, TRUE); | ||
706 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_RANK_SORT); | ||
707 | |||
708 | |||
590 | if (GNUNET_YES != GNUNET_GC_get_configuration_value_yesno (cfg, | 709 | if (GNUNET_YES != GNUNET_GC_get_configuration_value_yesno (cfg, |
591 | "GNUNET-GTK", | 710 | "GNUNET-GTK", |
592 | "DISABLE-PREVIEWS", | 711 | "DISABLE-PREVIEWS", |