From 37ddf86b521f1655724bd895849905fd023c7915 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1=D1?=
 =?UTF-8?q?=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
Date: Mon, 12 Dec 2011 00:43:48 +0400
Subject: [PATCH 1/2] A lump of GUI changes and tweaks

* Real namespaces are now fetched from FS instead of dummies
* Used Size Group to make entries and combobox in search bar have the same height
* Reworked namespace selection toggle button - now it consists of separate label and
  button. Could have made it to look more comboboxy, but there seems to be no pressing
  need for that.
* Removed some unneded widgets.
* MIME type selector now has more columns, and got an entry to input arbitrary MIME type.
---
 contrib/gnunet_fs_gtk_main_window.glade |  237 +++++++++++++++++++-----------
 src/fs/gnunet-fs-gtk.c                  |   85 ++++++++++--
 2 files changed, 223 insertions(+), 99 deletions(-)

diff --git a/contrib/gnunet_fs_gtk_main_window.glade b/contrib/gnunet_fs_gtk_main_window.glade
index 799c1b1..4fdc888 100644
--- a/contrib/gnunet_fs_gtk_main_window.glade
+++ b/contrib/gnunet_fs_gtk_main_window.glade
@@ -2,70 +2,6 @@
 <interface>
   <requires lib="gtk+" version="2.24"/>
   <!-- interface-naming-policy project-wide -->
-  <object class="GtkListStore" id="GNUNET_GTK_meta_data_list_store">
-    <columns>
-      <!-- column-name extractor_meta_type -->
-      <column type="guint"/>
-      <!-- column-name extractor_meta_format -->
-      <column type="guint"/>
-      <!-- column-name extractor_meta_type_string -->
-      <column type="gchararray"/>
-      <!-- column-name extracotr_meta_value -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
-  <object class="GtkImage" id="image2">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-go-up</property>
-  </object>
-  <object class="GtkImage" id="image3">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-new</property>
-  </object>
-  <object class="GtkImage" id="image4">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-find</property>
-  </object>
-  <object class="GtkImage" id="image5">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-go-down</property>
-  </object>
-  <object class="GtkImage" id="image6">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-index</property>
-  </object>
-  <object class="GtkListStore" id="main_window_search_anonymity_liststore">
-    <columns>
-      <!-- column-name Name -->
-      <column type="gchararray"/>
-      <!-- column-name Level -->
-      <column type="guint"/>
-      <!-- column-name Color -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">None</col>
-        <col id="1">0</col>
-        <col id="2" translatable="yes">#AAAA00000000</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Normal</col>
-        <col id="1">1</col>
-        <col id="2" translatable="yes">#000000000000</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Paranoid</col>
-        <col id="1">10</col>
-        <col id="2" translatable="yes">#0000AAAA0000</col>
-      </row>
-    </data>
-  </object>
   <object class="GtkWindow" id="GNUNET_GTK_main_window">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">gnunet-fs-gtk</property>
@@ -389,30 +325,51 @@
               </packing>
             </child>
             <child>
+              <object class="GtkLabel" id="main_window_search_selected_namespace_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label">&lt;none&gt;</property>
+                <property name="single_line_mode">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkAlignment" id="main_window_search_namespace_combobox_alignment">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="xscale">0</property>
                 <property name="yscale">0</property>
                 <child>
                   <object class="GtkToggleButton" id="main_window_search_namespace_dropdown_button">
-                    <property name="label" translatable="yes">&lt;none&gt;</property>
                     <property name="use_action_appearance">False</property>
+                    <property name="width_request">21</property>
+                    <property name="height_request">21</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
                     <property name="events">GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK</property>
-                    <property name="image">image10</property>
                     <property name="image_position">right</property>
                     <signal name="toggled" handler="main_window_search_namespace_dropdown_button_toggled_cb" swapped="no"/>
                     <signal name="enter-notify-event" handler="main_window_search_namespace_dropdown_button_enter_notify_event_cb" swapped="no"/>
                     <signal name="leave-notify-event" handler="namespace_selector_window_leave_notify_event_cb" swapped="no"/>
+                    <child>
+                      <object class="GtkArrow" id="arrow1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="arrow_type">down</property>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
             <child>
@@ -424,7 +381,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">2</property>
+                <property name="position">3</property>
               </packing>
             </child>
             <child>
@@ -442,7 +399,7 @@
               <packing>
                 <property name="expand">True</property>
                 <property name="fill">True</property>
-                <property name="position">3</property>
+                <property name="position">4</property>
               </packing>
             </child>
             <child>
@@ -454,7 +411,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">4</property>
+                <property name="position">5</property>
               </packing>
             </child>
             <child>
@@ -487,7 +444,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">5</property>
+                <property name="position">6</property>
               </packing>
             </child>
             <child>
@@ -499,14 +456,13 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">6</property>
+                <property name="position">7</property>
               </packing>
             </child>
             <child>
               <object class="GtkAlignment" id="main_window_search_mime_combobox_alignment">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="xscale">0</property>
                 <property name="yscale">0</property>
                 <child>
                   <object class="GtkComboBox" id="main_window_search_mime_combobox">
@@ -514,16 +470,38 @@
                     <property name="can_focus">False</property>
                     <property name="model">main_window_search_mime_liststore</property>
                     <property name="active">0</property>
+                    <property name="has_entry">True</property>
+                    <property name="entry_text_column">0</property>
+                    <signal name="popdown" handler="main_window_search_mime_combobox_popdown_cb" swapped="no"/>
+                    <signal name="popup" handler="main_window_search_mime_combobox_popup_cb" swapped="no"/>
                     <child>
                       <object class="GtkCellRendererText" id="main_window_search_mime_renderer_description"/>
                       <attributes>
-                        <attribute name="text">0</attribute>
+                        <attribute name="text">1</attribute>
                       </attributes>
                     </child>
                     <child>
                       <object class="GtkCellRendererText" id="main_window_search_mime_renderer_type"/>
                       <attributes>
-                        <attribute name="text">1</attribute>
+                        <attribute name="text">0</attribute>
+                      </attributes>
+                    </child>
+                    <child>
+                      <object class="GtkCellRendererText" id="main_window_search_mime_renderer_extension"/>
+                      <attributes>
+                        <attribute name="text">2</attribute>
+                      </attributes>
+                    </child>
+                    <child>
+                      <object class="GtkCellRendererText" id="main_window_search_mime_renderer_lossyness"/>
+                      <attributes>
+                        <attribute name="text">3</attribute>
+                      </attributes>
+                    </child>
+                    <child>
+                      <object class="GtkCellRendererText" id="main_window_search_mime_renderer_freedom"/>
+                      <attributes>
+                        <attribute name="text">4</attribute>
                       </attributes>
                     </child>
                   </object>
@@ -532,7 +510,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">7</property>
+                <property name="position">8</property>
               </packing>
             </child>
             <child>
@@ -554,7 +532,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">8</property>
+                <property name="position">9</property>
               </packing>
             </child>
           </object>
@@ -690,18 +668,16 @@
       </object>
     </child>
   </object>
-  <object class="GtkListStore" id="GNUNET_GTK_peer_info_list_store">
+  <object class="GtkListStore" id="GNUNET_GTK_meta_data_list_store">
     <columns>
-      <!-- column-name peer_identity -->
-      <column type="gchararray"/>
-      <!-- column-name number_of_known_addresses -->
+      <!-- column-name extractor_meta_type -->
       <column type="guint"/>
-      <!-- column-name country_name -->
+      <!-- column-name extractor_meta_format -->
+      <column type="guint"/>
+      <!-- column-name extractor_meta_type_string -->
+      <column type="gchararray"/>
+      <!-- column-name extracotr_meta_value -->
       <column type="gchararray"/>
-      <!-- column-name country_flag -->
-      <column type="GdkPixbuf"/>
-      <!-- column-name bandwidth -->
-      <column type="guint64"/>
     </columns>
   </object>
   <object class="GtkAdjustment" id="adjustment1">
@@ -716,6 +692,20 @@
     <property name="page_increment">10</property>
     <property name="page_size">10</property>
   </object>
+  <object class="GtkListStore" id="GNUNET_GTK_peer_info_list_store">
+    <columns>
+      <!-- column-name peer_identity -->
+      <column type="gchararray"/>
+      <!-- column-name number_of_known_addresses -->
+      <column type="guint"/>
+      <!-- column-name country_name -->
+      <column type="gchararray"/>
+      <!-- column-name country_flag -->
+      <column type="GdkPixbuf"/>
+      <!-- column-name bandwidth -->
+      <column type="guint64"/>
+    </columns>
+  </object>
   <object class="GtkAdjustment" id="adjustment3">
     <property name="upper">100</property>
     <property name="step_increment">1</property>
@@ -733,7 +723,27 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-open</property>
   </object>
-  <object class="GtkImage" id="image10">
+  <object class="GtkImage" id="image2">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-go-up</property>
+  </object>
+  <object class="GtkImage" id="image3">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-new</property>
+  </object>
+  <object class="GtkImage" id="image4">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-find</property>
+  </object>
+  <object class="GtkImage" id="image5">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-go-down</property>
+  </object>
+  <object class="GtkImage" id="image6">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="stock">gtk-index</property>
@@ -753,29 +763,74 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-index</property>
   </object>
+  <object class="GtkListStore" id="main_window_search_anonymity_liststore">
+    <columns>
+      <!-- column-name Name -->
+      <column type="gchararray"/>
+      <!-- column-name Level -->
+      <column type="guint"/>
+      <!-- column-name Color -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">None</col>
+        <col id="1">0</col>
+        <col id="2" translatable="yes">#AAAA00000000</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Normal</col>
+        <col id="1">1</col>
+        <col id="2" translatable="yes">#000000000000</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Paranoid</col>
+        <col id="1">10</col>
+        <col id="2" translatable="yes">#0000AAAA0000</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkListStore" id="main_window_search_mime_liststore">
     <columns>
       <!-- column-name MIME -->
       <column type="gchararray"/>
       <!-- column-name Type -->
       <column type="gchararray"/>
+      <!-- column-name Extension -->
+      <column type="gchararray"/>
+      <!-- column-name Lossyness -->
+      <column type="gchararray"/>
+      <!-- column-name Freedom -->
+      <column type="gchararray"/>
     </columns>
     <data>
       <row>
         <col id="0"> </col>
         <col id="1" translatable="yes">Any</col>
+        <col id="2" translatable="yes"> </col>
+        <col id="3" translatable="yes"> </col>
+        <col id="4" translatable="yes"> </col>
       </row>
       <row>
         <col id="0">plain/text</col>
         <col id="1" translatable="yes">Text</col>
+        <col id="2">txt</col>
+        <col id="3" translatable="yes">N/A</col>
+        <col id="4" translatable="yes">N/A</col>
       </row>
       <row>
         <col id="0">application/zip</col>
         <col id="1" translatable="yes">Zip</col>
+        <col id="2">zip</col>
+        <col id="3" translatable="yes">lossless</col>
+        <col id="4" translatable="yes">free</col>
       </row>
       <row>
         <col id="0">audio/mpeg</col>
         <col id="1" translatable="yes">MPEG audio</col>
+        <col id="2">mp3, mp2, mpeg</col>
+        <col id="3" translatable="yes">lossy</col>
+        <col id="4" translatable="yes">non-free</col>
       </row>
     </data>
   </object>
@@ -791,6 +846,14 @@
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkSizeGroup" id="enties_and_comboboxes_sizegroup">
+    <property name="mode">vertical</property>
+    <widgets>
+      <widget name="main_window_search_entry"/>
+      <widget name="main_window_search_anonymity_combobox"/>
+      <widget name="main_window_search_mime_combobox"/>
+    </widgets>
+  </object>
   <object class="GtkWindow" id="namespace_selector_window">
     <property name="can_focus">False</property>
     <property name="events">GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK</property>
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index 68c6be6..6833783 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -351,6 +351,7 @@ namespace_selector_treeview_cursor_changed_cb (GtkWidget *widget,
 {
   GtkBuilder *builder;
   GtkToggleButton *toggle_button;
+  GtkLabel *sel_namespace_label;
   gchar *value;
   GtkTreePath *treepath;
 
@@ -363,9 +364,13 @@ namespace_selector_treeview_cursor_changed_cb (GtkWidget *widget,
   if (!toggle_button)
     return;
 
+  sel_namespace_label = GTK_LABEL (gtk_builder_get_object (builder, "main_window_search_selected_namespace_label"));
+  if (sel_namespace_label)
+    return;
+
   if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 0,
       &value))
-    gtk_button_set_label (GTK_BUTTON (toggle_button), value);
+    gtk_label_set_text (sel_namespace_label, value);
 
   gtk_tree_path_free (treepath);
 
@@ -446,6 +451,64 @@ main_window_search_button_clicked_cb (GtkButton *button, gpointer user_data)
   GNUNET_FS_uri_destroy (uri);
 }
 
+/**
+ * Add pseudonym data to tree store
+ *
+ * @param cls closure (the 'GtkListStore')
+ * @param pseudonym hash code of public key of pseudonym
+ * @param md meta data known about the pseudonym
+ * @param rating the local rating of the pseudonym
+ * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
+ */
+static int
+add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym,
+    const struct GNUNET_CONTAINER_MetaData *md, int rating)
+{
+  GtkTreeStore *ts = cls;
+  char *root;
+  char *ns_name;
+  GNUNET_HashCode *nsid;
+  char *description;
+  char *uris;
+  char *emsg;
+  struct GNUNET_FS_Uri *uri;
+  GtkTreeIter iter;
+
+  ns_name =
+      GNUNET_PSEUDONYM_id_to_name (GNUNET_FS_GTK_get_configuration (),
+                                   pseudonym);
+  nsid = GNUNET_malloc (sizeof (GNUNET_HashCode));
+  *nsid = *pseudonym;
+  root = NULL;
+  uris = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_URI);
+  if (uris != NULL)
+  {
+    emsg = NULL;
+    uri = GNUNET_FS_uri_parse (uris, &emsg);
+    if (uri == NULL)
+      GNUNET_free (emsg);
+    root = GNUNET_FS_uri_sks_get_content_id (uri);
+    GNUNET_FS_uri_destroy (uri);
+  }
+  description =
+      GNUNET_CONTAINER_meta_data_get_first_by_types (md,
+                                                     EXTRACTOR_METATYPE_TITLE,
+                                                     EXTRACTOR_METATYPE_BOOK_TITLE,
+                                                     EXTRACTOR_METATYPE_DESCRIPTION,
+                                                     EXTRACTOR_METATYPE_SUMMARY,
+                                                     EXTRACTOR_METATYPE_ALBUM,
+                                                     EXTRACTOR_METATYPE_COMMENT,
+                                                     EXTRACTOR_METATYPE_SUBJECT,
+                                                     EXTRACTOR_METATYPE_KEYWORDS,
+                                                     -1);
+  gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1,
+      nsid, 2, root, 3, description, -1);
+  GNUNET_free (ns_name);
+  GNUNET_free_non_null (root);
+  GNUNET_free_non_null (description);
+  return GNUNET_OK;
+}
+
 void
 GNUNET_GTK_main_window_realize_cb (GtkWidget *widget, gpointer user_data)
 {
@@ -453,7 +516,6 @@ GNUNET_GTK_main_window_realize_cb (GtkWidget *widget, gpointer user_data)
   GtkTreeView *namespace_tree;
   GtkTreeStore *namespace_treestore;
   GtkBuilder *builder;
-  GtkToggleButton *toggle_button;
   GtkWidget *namespace_selector_window;
 
   builder = GTK_BUILDER (user_data);
@@ -463,24 +525,23 @@ GNUNET_GTK_main_window_realize_cb (GtkWidget *widget, gpointer user_data)
   namespace_tree = GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
       ("namespace_selector_treeview"));
 
-  /* TODO: fetch real values from somewhere instead of filling the store with dummies */
-  gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, 0, 0, "Any", 1, NULL, 2, "", 3, "Do not search in any particular namespace", -1);
-  gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, 1, 0, "foo", 1, NULL, 2, "IAMTHEBESTOBEYMENOCARRIER", 3, "Tooltip1", -1);
-  gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, 2, 0, "bar", 1, NULL, 2, "NOONEWILLKNOWTHISIDBECAUSEITSSECRET", 3, "Tooltip2", -1);
-  gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, 3, 0, "baz", 1, NULL, 2, "SSLOPENSSHGNUGTKGNUNETFTWYAYA", 3, "Tooltip3", -1);
+  gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL,
+      G_MAXINT, 0, "Any", 1, NULL, 2, "", 3,
+      "Do not search in any particular namespace", -1);
+  GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (),
+                             &add_namespace_to_ts, namespace_treestore);
 
   /* FIXME: read currently selected namespace from somewhere instead of selecting 0th item */
   if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (namespace_treestore), &iter))
   {
     gchar *value;
+    GtkLabel *sel_namespace_label;
     GtkTreePath *treepath = gtk_tree_path_new_first ();
     gtk_tree_selection_select_iter (gtk_tree_view_get_selection (
         namespace_tree), &iter);
-    toggle_button = GTK_TOGGLE_BUTTON (GNUNET_FS_GTK_get_main_window_object
-        ("main_window_search_namespace_dropdown_button"));
-    if (GNUNET_GTK_get_tree_string (namespace_tree,
-        treepath, 0, &value))
-      gtk_button_set_label (GTK_BUTTON (toggle_button), value);
+    sel_namespace_label = GTK_LABEL (gtk_builder_get_object (builder, "main_window_search_selected_namespace_label"));
+    if (GNUNET_GTK_get_tree_string (namespace_tree, treepath, 0, &value))
+      gtk_label_set_text (sel_namespace_label, value);
     gtk_tree_path_free (treepath);
   }
 
-- 
1.7.4

