gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6908 - gnunet-gtk/src/plugins/fs


From: gnunet
Subject: [GNUnet-SVN] r6908 - gnunet-gtk/src/plugins/fs
Date: Mon, 26 May 2008 20:50:49 -0600 (MDT)

Author: grothoff
Date: 2008-05-26 20:50:49 -0600 (Mon, 26 May 2008)
New Revision: 6908

Modified:
   gnunet-gtk/src/plugins/fs/search.c
Log:
always create pixbuf

Modified: gnunet-gtk/src/plugins/fs/search.c
===================================================================
--- gnunet-gtk/src/plugins/fs/search.c  2008-05-27 02:41:47 UTC (rev 6907)
+++ gnunet-gtk/src/plugins/fs/search.c  2008-05-27 02:50:49 UTC (rev 6908)
@@ -97,6 +97,97 @@
   GNUNET_free (new_title);
 }
 
+static GdkPixbuf *
+make_ranking_pixbuf(int availability_rank,
+                   unsigned int availability_certainty,
+                   unsigned int applicability_rank)
+{
+  GdkPixbuf *pixbuf;
+  guchar * pixels;
+  guchar * pixel;
+  int n_channels;
+  int rowstride;
+  unsigned int x;
+  unsigned int y;
+  unsigned int kwords;
+
+#define P_HEIGHT 21
+#define P_WIDTH 60 
+  pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
+                         TRUE, /* alpha */
+                         8, /* bits per sample */
+                         P_WIDTH, /* width */
+                         P_HEIGHT /* height */
+                         );
+  n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+  pixels = gdk_pixbuf_get_pixels(pixbuf);
+  rowstride = gdk_pixbuf_get_rowstride(pixbuf);
+  for (x=0;x<P_WIDTH;x++)
+    for (y=0;y<P_HEIGHT;y++)
+      {
+       pixel = pixels + y * rowstride + x * n_channels;
+#define PX_RED 0
+#define PX_GREEN 1
+#define PX_BLUE 2
+#define PX_ALPHA 3
+       pixel[PX_RED]   = 0;
+       pixel[PX_GREEN] = 0;
+       pixel[PX_BLUE]  = 0;
+       pixel[PX_ALPHA] = 0;
+       if (y < P_HEIGHT / 2)
+         {
+           /* applicability */
+           if (x * kwords < applicability_rank * P_WIDTH)
+             {
+               pixel[PX_RED]   = 0;
+               pixel[PX_GREEN] = 0;
+               pixel[PX_BLUE]  = 255;
+               pixel[PX_ALPHA] = 255;
+             }
+         }
+       else if ( (y > P_HEIGHT / 2) &&
+                 ( (y-P_HEIGHT/2) * GNUNET_FSUI_MAX_PROBES 
+                   < availability_certainty * P_HEIGHT / 2) )
+         {
+           /* availability */
+           if (availability_rank < 0)
+             {
+               if ( (x * GNUNET_FSUI_MAX_PROBES > -availability_rank * 
P_WIDTH/2) &&
+                    (x <= P_WIDTH/2) )
+                 {
+                   pixel[PX_RED]   = 255;
+                   pixel[PX_GREEN] = 0;
+                   pixel[PX_BLUE]  = 0;
+                   pixel[PX_ALPHA] = 255;
+                 }
+             }
+           else if (availability_rank > 0)
+             {
+               if ( (x >= P_WIDTH/2) &&
+                    ( (x - (P_WIDTH/2)) * GNUNET_FSUI_MAX_PROBES < 
availability_rank * P_WIDTH/2) )
+                 {
+                   pixel[PX_RED]   = 0;
+                   pixel[PX_GREEN] = 255;
+                   pixel[PX_BLUE]  = 0;
+                   pixel[PX_ALPHA] = 255;
+                 }
+             }
+           else
+             {
+               if (x == P_WIDTH / 2)
+                 {
+                   /* yellow */
+                   pixel[PX_RED]   = 255;
+                   pixel[PX_GREEN] = 255;
+                   pixel[PX_BLUE]  = 0;
+                   pixel[PX_ALPHA] = 255;
+                 }
+             }
+         }
+      } 
+  return pixbuf;
+}
+
 /**
  * Add the given search result to the search
  * tree at the specified position.
@@ -112,6 +203,7 @@
   unsigned long long size;
   char *size_h;
   GdkPixbuf *pixbuf;
+  GdkPixbuf *rankbuf;
   enum GNUNET_URITRACK_STATE state;
 
   state = GNUNET_URITRACK_get_state (ectx, cfg, info->uri);
@@ -125,6 +217,7 @@
     0;
   pixbuf = getThumbnailFromMetaData (info->meta);
   size_h = GNUNET_get_byte_size_as_fancy_string (size);
+  rankbuf = make_ranking_pixbuf(0, 0, 1);
   gtk_tree_store_set (searchContext->tree,
                       iter,
                       SEARCH_NAME, name,
@@ -134,12 +227,17 @@
                       SEARCH_DESC, desc,
                       SEARCH_PIXBUF, pixbuf,
                       SEARCH_URI, GNUNET_ECRS_uri_duplicate (info->uri),
-                      SEARCH_META,
-                      GNUNET_ECRS_meta_data_duplicate (info->meta),
+                      SEARCH_META, GNUNET_ECRS_meta_data_duplicate 
(info->meta),
                       SEARCH_CELL_BG_COLOR, getColorCode (state),
-                      SEARCH_CELL_FG_COLOR, "black", SEARCH_INTERNAL,
-                      searchContext, SEARCH_INTERNAL_PARENT, downloadParent,
-                      SEARCH_STATUS, getStatusName (state), -1);
+                      SEARCH_CELL_FG_COLOR, "black", 
+                     SEARCH_INTERNAL, searchContext, 
+                     SEARCH_INTERNAL_PARENT, downloadParent,
+                      SEARCH_STATUS, getStatusName (state), 
+                     SEARCH_APPLICABILITY_RANK, 1, 
+                     SEARCH_RANK_SORT, (long long) 1,
+                     SEARCH_RANK_PIXBUF, rankbuf,
+                     -1);
+  g_object_unref(rankbuf);
   if (pixbuf != NULL)
     g_object_unref (pixbuf);
   GNUNET_free (size_h);
@@ -212,13 +310,7 @@
   GtkTreeIter iter;
   struct GNUNET_ECRS_URI *have;
   GdkPixbuf *pixbuf;
-  guchar * pixels;
-  guchar * pixel;
   long long rank;
-  int n_channels;
-  int rowstride;
-  unsigned int x;
-  unsigned int y;
   unsigned int kwords;
 
   kwords = GNUNET_ECRS_uri_get_keyword_count_from_ksk(searchContext->uri);
@@ -236,81 +328,9 @@
            {
              /* gotcha, create pixbuf and rank info! */
              rank = (int) applicability_rank + (int) (availability_rank * 
(int) availability_certainty * 65536);
-#define P_HEIGHT 21
-#define P_WIDTH 100 
-             pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
-                                     TRUE, /* alpha */
-                                     8, /* bits per sample */
-                                     P_WIDTH, /* width */
-                                     P_HEIGHT /* height */
-                                     );
-             n_channels = gdk_pixbuf_get_n_channels (pixbuf);
-             pixels = gdk_pixbuf_get_pixels(pixbuf);
-             rowstride = gdk_pixbuf_get_rowstride(pixbuf);
-             for (x=0;x<P_WIDTH;x++)
-               for (y=0;y<P_HEIGHT;y++)
-                 {
-                   pixel = pixels + y * rowstride + x * n_channels;
-#define PX_RED 0
-#define PX_GREEN 1
-#define PX_BLUE 2
-#define PX_ALPHA 3
-                   pixel[PX_RED]   = 0;
-                   pixel[PX_GREEN] = 0;
-                   pixel[PX_BLUE]  = 0;
-                   pixel[PX_ALPHA] = 0;
-                   if (y < P_HEIGHT / 2)
-                     {
-                       /* applicability */
-                       if (x * kwords < applicability_rank * P_WIDTH)
-                         {
-                           pixel[PX_RED]   = 0;
-                           pixel[PX_GREEN] = 0;
-                           pixel[PX_BLUE]  = 255;
-                           pixel[PX_ALPHA] = 255;
-                         }
-                     }
-                   else if ( (y > P_HEIGHT / 2) &&
-                             ( (y-P_HEIGHT/2) * GNUNET_FSUI_MAX_PROBES 
-                               < availability_certainty * P_HEIGHT / 2) )
-                     {
-                       /* availability */
-                       if (availability_rank < 0)
-                         {
-                           if ( (x * GNUNET_FSUI_MAX_PROBES > 
-availability_rank * P_WIDTH/2) &&
-                                (x <= P_WIDTH/2) )
-                             {
-                               pixel[PX_RED]   = 255;
-                               pixel[PX_GREEN] = 0;
-                               pixel[PX_BLUE]  = 0;
-                               pixel[PX_ALPHA] = 255;
-                             }
-                         }
-                       else if (availability_rank > 0)
-                         {
-                           if ( (x >= P_WIDTH/2) &&
-                                ( (x - (P_WIDTH/2)) * GNUNET_FSUI_MAX_PROBES < 
availability_rank * P_WIDTH/2) )
-                             {
-                               pixel[PX_RED]   = 0;
-                               pixel[PX_GREEN] = 255;
-                               pixel[PX_BLUE]  = 0;
-                               pixel[PX_ALPHA] = 255;
-                             }
-                         }
-                       else
-                         {
-                           if (x == P_WIDTH / 2)
-                             {
-                               /* yellow */
-                               pixel[PX_RED]   = 255;
-                               pixel[PX_GREEN] = 255;
-                               pixel[PX_BLUE]  = 0;
-                               pixel[PX_ALPHA] = 255;
-                             }
-                         }
-                     }
-                 }
-             
+             pixbuf = make_ranking_pixbuf(availability_rank,
+                                          availability_certainty,
+                                          applicability_rank);
              gtk_tree_store_set(searchContext->tree,
                                 &iter,
                                 SEARCH_AVAILABILITY_RANK, availability_rank,
@@ -678,8 +698,8 @@
   gtk_tree_view_column_set_reorderable (column, TRUE);
   gtk_tree_view_column_set_sort_column_id (column, SEARCH_MIME);
 
-
-  
+#if 0  
+  /* colums for data visualized graphically */
   renderer = gtk_cell_renderer_text_new ();
   gtk_tree_view_insert_column_with_attributes (list->treeview,
                                               -1,
@@ -708,8 +728,8 @@
                                               renderer,
                                               "text", SEARCH_RANK_SORT,
                                               NULL);
+#endif
 
-
   renderer = gtk_cell_renderer_pixbuf_new ();
   col = gtk_tree_view_insert_column_with_attributes (list->treeview,
                                                      -1,
@@ -821,7 +841,10 @@
       if (meta != NULL)
         GNUNET_ECRS_meta_data_destroy (meta);
       gtk_tree_store_set (GTK_TREE_STORE (tree),
-                          iter, SEARCH_URI, NULL, SEARCH_META, NULL, -1);
+                          iter, 
+                         SEARCH_URI, NULL, 
+                         SEARCH_META, NULL,
+                         -1);
       if (gtk_tree_model_iter_children (tree, &child, iter))
         freeIterSubtree (tree, &child);
     }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]