gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r1921 - GNUnet/src/applications/fs/fsui GNUnet/src/include


From: grothoff
Subject: [GNUnet-SVN] r1921 - GNUnet/src/applications/fs/fsui GNUnet/src/include GNUnet/src/util gnunet-gtk gnunet-gtk/src/plugins/fs
Date: Fri, 26 Aug 2005 01:08:28 -0700 (PDT)

Author: grothoff
Date: 2005-08-26 01:08:25 -0700 (Fri, 26 Aug 2005)
New Revision: 1921

Modified:
   GNUnet/src/applications/fs/fsui/namespace_info.c
   GNUnet/src/include/gnunet_fsui_lib.h
   GNUnet/src/util/storage.c
   gnunet-gtk/gnunet-gtk.glade
   gnunet-gtk/src/plugins/fs/download.c
   gnunet-gtk/src/plugins/fs/fs.h
   gnunet-gtk/src/plugins/fs/search.c
   gnunet-gtk/src/plugins/fs/search.h
Log:
towards fixing 911

Modified: GNUnet/src/applications/fs/fsui/namespace_info.c
===================================================================
--- GNUnet/src/applications/fs/fsui/namespace_info.c    2005-08-26 07:00:28 UTC 
(rev 1920)
+++ GNUnet/src/applications/fs/fsui/namespace_info.c    2005-08-26 08:08:25 UTC 
(rev 1921)
@@ -785,4 +785,15 @@
   FREE(name);
 }
 
+
+/**
+ * Get the root of the namespace (if we have one).
+ * @return SYSERR on error, OK on success
+ */
+int FSUI_getNamespaceRoot(const char * ns,
+                         HashCode512 * root) {
+  return SYSERR; /* FIXME: not implemented */
+}
+
+
 /* end of namespace_info.c */

Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h        2005-08-26 07:00:28 UTC (rev 
1920)
+++ GNUnet/src/include/gnunet_fsui_lib.h        2005-08-26 08:08:25 UTC (rev 
1921)
@@ -680,7 +680,13 @@
 #define FSUI_deleteNamespace ECRS_deleteNamespace
 
 /**
- * Change the ranking of a namespace.
+ * Change the ranking of a (non-local) namespace.
+ *
+ * @param ns the name of the namespace, as obtained
+ *  from ECRS_getNamespaceName
+ * @param delta by how much should the rating be
+ *  changed?
+ * @return new rating of the namespace
  */
 int FSUI_rankNamespace(struct FSUI_Context * ctx,
                       const char * ns,
@@ -696,7 +702,16 @@
 void FSUI_addNamespaceInfo(const struct ECRS_URI * uri,
                           const struct ECRS_MetaData * meta);
 
+
 /**
+ * Get the root of the namespace (if we have one).
+ * @return SYSERR on error, OK on success
+ */
+int FSUI_getNamespaceRoot(const char * ns,
+                         HashCode512 * root);
+
+
+/**
  * List all available (local or non-local) namespaces.
  *
  * @param local only list local namespaces (if NO, only

Modified: GNUnet/src/util/storage.c
===================================================================
--- GNUnet/src/util/storage.c   2005-08-26 07:00:28 UTC (rev 1920)
+++ GNUnet/src/util/storage.c   2005-08-26 08:08:25 UTC (rev 1921)
@@ -647,21 +647,24 @@
   }
 }
 
+/**
+ * Convert a given filesize into a fancy human-readable format.
+ */
 char * fileSizeToFancyString(unsigned long long size) {
-  const char * unit = _(/* size unit */ "b");
+const char * unit = _(/* size unit */ "b");
   char * ret;
 
-  if (delta > 5 * 1024) {
-    delta = delta / 1024;
+  if (size > 5 * 1024) {
+    size = size / 1024;
     unit = _(/* size unit */ "k");
-    if (delta > 5 * 1024) {
-      delta = delta / 1024;
+    if (size > 5 * 1024) {
+      size = size / 1024;
       unit = _(/* size unit */ "m");
-      if (delta > 5 * 1024) {
-       delta = delta / 1024;
+      if (size > 5 * 1024) {
+       size = size / 1024;
        unit = _(/* size unit */ "g");
-       if (delta > 5 * 1024) {
-         delta = delta / 1024;
+       if (size > 5 * 1024) {
+         size = size / 1024;
          unit = _(/* size unit */ "t");              
        }           
       }                
@@ -671,7 +674,7 @@
   SNPRINTF(ret, 
           32, 
           "%llu%s",
-          delta, 
+          size, 
           unit);
   return ret;
 }

Modified: gnunet-gtk/gnunet-gtk.glade
===================================================================
--- gnunet-gtk/gnunet-gtk.glade 2005-08-26 07:00:28 UTC (rev 1920)
+++ gnunet-gtk/gnunet-gtk.glade 2005-08-26 08:08:25 UTC (rev 1921)
@@ -1110,6 +1110,53 @@
                      </child>
 
                      <child>
+                       <widget class="GtkLabel" id="searchAnonymityLabel">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">with 
_anonymity</property>
+                         <property name="use_underline">True</property>
+                         <property name="use_markup">False</property>
+                         <property name="justify">GTK_JUSTIFY_LEFT</property>
+                         <property name="wrap">False</property>
+                         <property name="selectable">False</property>
+                         <property name="xalign">0.5</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">5</property>
+                         <property name="ypad">0</property>
+                         <property 
name="mnemonic_widget">searchAnonymitySelectionSpinButton</property>
+                         <property 
name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                         <property name="width_chars">-1</property>
+                         <property name="single_line_mode">False</property>
+                         <property name="angle">0</property>
+                       </widget>
+                       <packing>
+                         <property name="padding">0</property>
+                         <property name="expand">False</property>
+                         <property name="fill">False</property>
+                       </packing>
+                     </child>
+
+                     <child>
+                       <widget class="GtkSpinButton" 
id="searchAnonymitySelectionSpinButton">
+                         <property agent="glademm" 
name="cxx_visibility">public</property>
+                         <property name="visible">True</property>
+                         <property name="tooltip" translatable="yes">Specify 
the anonymity level for the search, 0 for no anonymity.  Higher values provide 
more privacy but also less performance.</property>
+                         <property name="can_focus">True</property>
+                         <property name="climb_rate">1</property>
+                         <property name="digits">0</property>
+                         <property name="numeric">True</property>
+                         <property 
name="update_policy">GTK_UPDATE_ALWAYS</property>
+                         <property name="snap_to_ticks">False</property>
+                         <property name="wrap">False</property>
+                         <property name="adjustment">1 0 100000 1 10 
10</property>
+                       </widget>
+                       <packing>
+                         <property name="padding">0</property>
+                         <property name="expand">False</property>
+                         <property name="fill">True</property>
+                       </packing>
+                     </child>
+
+                     <child>
                        <widget class="GtkLabel" id="label40">
                          <property name="visible">True</property>
                          <property name="label" translatable="yes">in 
_namespace</property>
@@ -1154,6 +1201,7 @@
                              <property name="add_tearoffs">False</property>
                              <property name="has_frame">True</property>
                              <property name="focus_on_click">True</property>
+                             <signal name="changed" 
handler="on_searchNamespaceComboBoxEntry_changed" last_modification_time="Fri, 
26 Aug 2005 07:56:07 GMT"/>
                            </widget>
                          </child>
                        </widget>
@@ -1165,36 +1213,10 @@
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="searchAnonymityLabel">
+                       <widget class="GtkSpinButton" 
id="namespaceRatingSpinButton">
                          <property name="visible">True</property>
-                         <property name="label" 
translatable="yes">_Anonymity:</property>
-                         <property name="use_underline">True</property>
-                         <property name="use_markup">False</property>
-                         <property name="justify">GTK_JUSTIFY_LEFT</property>
-                         <property name="wrap">False</property>
-                         <property name="selectable">False</property>
-                         <property name="xalign">0.5</property>
-                         <property name="yalign">0.5</property>
-                         <property name="xpad">5</property>
-                         <property name="ypad">0</property>
-                         <property 
name="mnemonic_widget">searchAnonymitySelectionSpinButton</property>
-                         <property 
name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                         <property name="width_chars">-1</property>
-                         <property name="single_line_mode">False</property>
-                         <property name="angle">0</property>
-                       </widget>
-                       <packing>
-                         <property name="padding">0</property>
-                         <property name="expand">False</property>
-                         <property name="fill">False</property>
-                       </packing>
-                     </child>
-
-                     <child>
-                       <widget class="GtkSpinButton" 
id="searchAnonymitySelectionSpinButton">
-                         <property agent="glademm" 
name="cxx_visibility">public</property>
-                         <property name="visible">True</property>
-                         <property name="tooltip" translatable="yes">Specify 
the anonymity level for the search, 0 for no anonymity.  Higher values provide 
more privacy but also less performance.</property>
+                         <property name="sensitive">False</property>
+                         <property name="tooltip" translatable="yes">This is 
the rating that you have given this namespace so far.  Ratings are private and 
not shared with other users in any way.  They are supposed to help each user 
remember which namespace is worthwile for him.</property>
                          <property name="can_focus">True</property>
                          <property name="climb_rate">1</property>
                          <property name="digits">0</property>
@@ -1202,12 +1224,13 @@
                          <property 
name="update_policy">GTK_UPDATE_ALWAYS</property>
                          <property name="snap_to_ticks">False</property>
                          <property name="wrap">False</property>
-                         <property name="adjustment">1 0 100000 1 10 
10</property>
+                         <property name="adjustment">0 -100000 100000 1 10 
10</property>
+                         <signal name="changed" 
handler="on_namespaceRatingSpinButton_changed" last_modification_time="Fri, 26 
Aug 2005 07:55:50 GMT"/>
                        </widget>
                        <packing>
                          <property name="padding">0</property>
                          <property name="expand">False</property>
-                         <property name="fill">True</property>
+                         <property name="fill">False</property>
                        </packing>
                      </child>
                    </widget>

Modified: gnunet-gtk/src/plugins/fs/download.c
===================================================================
--- gnunet-gtk/src/plugins/fs/download.c        2005-08-26 07:00:28 UTC (rev 
1920)
+++ gnunet-gtk/src/plugins/fs/download.c        2005-08-26 08:08:25 UTC (rev 
1921)
@@ -132,6 +132,33 @@
     BREAK();
     return;
   }
+  spin = getAnonymityButtonFromTM(model);
+  if (spin == NULL) {
+    BREAK();
+    anon = 1;
+  } else {
+    anon = gtk_spin_button_get_value_as_int
+      (GTK_SPIN_BUTTON(spin));
+  }  
+  if (! ECRS_isFileUri(uri)) {
+    if (ECRS_isNamespaceUri(uri)) {
+      /* start namespace search; would probably be better
+        to add this as a subtree, but for simplicity
+        we'll just add it as a new tab for now */
+      if (OK == FSUI_startSearch(ctx,
+                                anon,
+                                uri))
+       openTabForSearch(NULL,
+                        uri,
+                        anon,
+                        0,
+                        NULL);
+      return;
+    } else {
+      BREAK(); /* unsupported URI type (i.e. ksk or loc) */
+      return;
+    }
+  }
   filename = ECRS_uriToString(uri);  
   if ( (filename == NULL) ||
        (strlen(filename) < 
@@ -201,14 +228,7 @@
                      /* internal: row reference! */
                      -1);
   FREE(filename);
-  spin = getAnonymityButtonFromTM(model);
-  if (spin == NULL) {
-    BREAK();
-    anon = 1;
-  } else {
-    anon = gtk_spin_button_get_value_as_int
-      (GTK_SPIN_BUTTON(spin));
-  }  
+
   FSUI_startDownload(ctx,
                      anon,
                      uri,

Modified: gnunet-gtk/src/plugins/fs/fs.h
===================================================================
--- gnunet-gtk/src/plugins/fs/fs.h      2005-08-26 07:00:28 UTC (rev 1920)
+++ gnunet-gtk/src/plugins/fs/fs.h      2005-08-26 08:08:25 UTC (rev 1921)
@@ -43,6 +43,14 @@
 };
 
 enum {
+  NS_SEARCH_DESCRIPTION = 0,
+  NS_SEARCH_ENCNAME,
+  NS_SEARCH_METADATA,
+  NS_SEARCH_RATING,
+  NS_SEARCH_NUM,
+};
+
+enum {
   SER_SUM_NAME = 0,
   SER_SUM_COUNT,
   SER_SUM_URI,

Modified: gnunet-gtk/src/plugins/fs/search.c
===================================================================
--- gnunet-gtk/src/plugins/fs/search.c  2005-08-26 07:00:28 UTC (rev 1920)
+++ gnunet-gtk/src/plugins/fs/search.c  2005-08-26 08:08:25 UTC (rev 1921)
@@ -99,10 +99,11 @@
                                   -1);
   if (name == NULL)
     name = STRDUP(_("no name given")); 
-  if (ECRS_isFileUri(uri))
+  if (ECRS_isFileUri(uri)) {
     size = ECRS_fileSize(uri);
-  else
-    size = 0;
+  } else {
+    size = 0;  
+  }
   thumb = NULL;
   ts = ECRS_getThumbnailFromMetaData(meta,
                                     &thumb);
@@ -187,6 +188,124 @@
                                 
 }
 
+/**
+ * The spin button giving the rating for a particular namespace
+ * has been changed.  Store the new rating for the namespace.
+ */
+void on_namespaceRatingSpinButton_changed(GtkWidget * dummy,
+                                         GtkWidget * dummy2) {
+  GtkWidget * spin;
+  GtkWidget * ncbe;
+  GtkTreeModel * model;
+  GtkTreeIter iter;
+  char * encStr;
+  int rating;
+
+  spin
+    = glade_xml_get_widget(getMainXML(),
+                          "namespaceRatingSpinButton");
+  ncbe
+    = glade_xml_get_widget(getMainXML(),
+                          "searchNamespaceComboBoxEntry");
+  model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe));
+  if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe),
+                                           &iter)) {   
+    gtk_tree_model_get(model,
+                      &iter,
+                      NS_SEARCH_ENCNAME, &encStr,
+                      NS_SEARCH_RATING, &rating,
+                      -1);
+    if (0 == strcmp(encStr,
+                   _("globally"))) {
+      BREAK(); /* spin button should be insensitive! */
+      gtk_widget_set_sensitive(spin,
+                              FALSE);
+    } else {
+      FSUI_rankNamespace(ctx,
+                        encStr,
+                        rating - FSUI_rankNamespace(ctx,
+                                                    encStr,
+                                                    0));
+      gtk_list_store_set(GTK_LIST_STORE(model),
+                        &iter,
+                        NS_SEARCH_RATING, rating,
+                        -1);      
+    }   
+  } else {
+    /* FIXME: if enc2hash succeeds, we may want to keep this 
+       active */
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
+                             0);
+    gtk_widget_set_sensitive(spin,
+                            FALSE);
+  }  
+}
+
+/**
+ * The namespace in the search window has changed.
+ * Update the trust level (possibly changing sensitivity)
+ * and set the search string to the root (if available).
+ */
+void on_searchNamespaceComboBoxEntry_changed(GtkWidget * dummy,
+                                            GtkWidget * dummy2) {
+  GtkWidget * keyword;
+  GtkWidget * spin;
+  GtkWidget * ncbe;
+  GtkTreeModel * model;
+  GtkTreeIter iter;
+  int rating;
+  char * encStr;
+  HashCode512 ns;
+  HashCode512 root;
+  EncName enc;
+
+  spin
+    = glade_xml_get_widget(getMainXML(),
+                          "namespaceRatingSpinButton");
+  ncbe
+    = glade_xml_get_widget(getMainXML(),
+                          "searchNamespaceComboBoxEntry");
+  model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe));
+  if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe),
+                                           &iter)) {
+    gtk_tree_model_get(model,
+                      &iter,
+                      NS_SEARCH_ENCNAME, &encStr,
+                      NS_SEARCH_RATING, &rating,
+                      -1);
+    if (0 == strcmp(encStr,
+                   _("globally"))) {
+      gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
+                               0);
+      gtk_widget_set_sensitive(spin,
+                              FALSE);
+    } else {
+      enc2hash(encStr,
+              &ns);
+      gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
+                               rating);
+      gtk_widget_set_sensitive(spin,
+                              TRUE);
+      if (OK == FSUI_getNamespaceRoot(encStr,
+                                     &root)) {
+       hash2enc(&root,
+                &enc);
+       keyword
+         = glade_xml_get_widget(getMainXML(),
+                                "fssearchKeywordComboBoxEntry");
+       gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(keyword))),
+                          (const gchar*) &enc);
+      }
+    }
+  } else {
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
+                             0);
+    gtk_widget_set_sensitive(spin,
+                            FALSE);
+  }
+
+}
+
 void on_searchResults_destroy(GtkWidget * dummy,
                              GtkWidget * treeview) {
   GtkTreeStore * tree;
@@ -603,31 +722,61 @@
   FREE(tabtxt);
 }
 
-static int addNamespace(GtkListStore * model,
+static int addNamespace(void * arg,
                        const char * namespaceName,
                        const HashCode512 * namespaceId,
                        const struct ECRS_MetaData * md,
                        int rating) {
+  GtkListStore * model = arg;
   GtkTreeIter iter;
   EncName enc;
   char * name;
+  struct ECRS_MetaData * dmd;
+  char * desc;
+  size_t n;
   
   hash2enc(namespaceId,
           &enc);
-  name = MALLOC(strlen(namespaceName) + sizeof(EncName) + 2);
+  if (md == NULL) {
+    dmd = NULL;
+    desc = STRDUP("");
+  } else {
+    dmd = ECRS_dupMetaData(md);
+    desc = ECRS_getFirstFromMetaData(md,
+                                    EXTRACTOR_DESCRIPTION,
+                                    EXTRACTOR_TITLE,
+                                    EXTRACTOR_AUTHOR,
+                                    EXTRACTOR_GENRE,
+                                    EXTRACTOR_SUBJECT,
+                                    EXTRACTOR_CREATOR,
+                                    EXTRACTOR_PRODUCER,
+                                    EXTRACTOR_GROUP,
+                                    EXTRACTOR_CREATED_FOR,
+                                    EXTRACTOR_SUMMARY,
+                                    EXTRACTOR_OWNER);
+    if (desc == NULL)
+      desc = STRDUP("");
+  }
+  
+  n = strlen(desc) + 64;
+  name = MALLOC(n);
   SNPRINTF(name,
-          strlen(namespaceName) + sizeof(EncName) + 2,
-          "%s: %s",
-          &enc,
-          namespaceName);
+          n,
+          "%s: %*.s",
+          desc,
+          rating,
+          20,
+          &enc);
   gtk_list_store_append(model,
                        &iter);
   gtk_list_store_set(model,
                     &iter,
-                    0,
-                    name,
+                    NS_SEARCH_DESCRIPTION, name,
+                    NS_SEARCH_ENCNAME, &enc,
+                    NS_SEARCH_METADATA, dmd,
+                    NS_SEARCH_RATING, rating
                     -1);
-  FREE(name);               
+  FREE(name);     
   return OK;
 }
 
@@ -640,16 +789,23 @@
   GtkListStore * model;
   GtkTreeIter iter;
  
-  model = gtk_list_store_new(1, G_TYPE_STRING);
+  model = gtk_list_store_new(NS_SEARCH_NUM, 
+                            G_TYPE_STRING, /* what we show */
+                            G_TYPE_STRING, /* EncName of namespace */
+                            G_TYPE_POINTER,
+                            G_TYPE_INT);  /* Meta-data about namespace */
   gtk_list_store_append(model,
                        &iter);
   gtk_list_store_set(model,
                     &iter,
-                    0, _("globally"),
+                    NS_SEARCH_DESCRIPTION, _("globally"),
+                    NS_SEARCH_ENCNAME, NULL,
+                    NS_SEARCH_METADATA, NULL,               
+                    NS_SEARCH_RATING, 0,
                     -1);
   FSUI_listNamespaces(ctx,
                      NO,
-                     (FSUI_NamespaceIterator)&addNamespace,
+                     &addNamespace,
                      model);
   searchNamespaceCB
     = glade_xml_get_widget(getMainXML(),
@@ -672,12 +828,11 @@
  * Open a tab for the given search
  * (and display the results).
  */
-static int 
-openTabForSearch(void * unused,
-                const struct ECRS_URI * uri,
-                unsigned int anonymityLevel,
-                unsigned int resultCount,
-                const ECRS_FileInfo * results) {
+int openTabForSearch(void * unused,
+                    const struct ECRS_URI * uri,
+                    unsigned int anonymityLevel,
+                    unsigned int resultCount,
+                    const ECRS_FileInfo * results) {
   SearchList * list;
   char * description;
   char * dhead;
@@ -755,11 +910,15 @@
     = glade_xml_get_widget(getMainXML(),
                           "fssearchKeywordComboBoxEntry");
 
-  model = gtk_list_store_new(1, G_TYPE_STRING);
+  model = gtk_list_store_new(NS_SEARCH_NUM, 
+                            G_TYPE_STRING, /* what we show */
+                            G_TYPE_STRING, /* EncName of namespace */
+                            G_TYPE_POINTER,
+                            G_TYPE_INT);  /* Meta-data about namespace */
   gtk_combo_box_set_model(GTK_COMBO_BOX(searchCB),
                          GTK_TREE_MODEL(model));
   gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(searchCB),
-                                     0);
+                                     NS_SEARCH_DESCRIPTION);
   addCronJob(&updateNCBModel,
             0,
             5 * cronMINUTES,
@@ -808,12 +967,8 @@
     ECRS_freeUri(list->uri);
 
 #if 0
-  /* FIXME - memory leak.  The following is still incorrect:
-     a) does not free entire tree (need to recurse!)
-     b) needs to be invoked earlier; the model
-        may have already gone bye-bye at this point!
-        (idea: bind code to destroy signal from
-         searchPage!)
+  /* FIXME - memory leak.  The following is still incorrect;
+     it does not free entire tree (need to recurse!)
   */
     if (gtk_tree_model_get_iter_first(head->model,
                                      &iter)) {

Modified: gnunet-gtk/src/plugins/fs/search.h
===================================================================
--- gnunet-gtk/src/plugins/fs/search.h  2005-08-26 07:00:28 UTC (rev 1920)
+++ gnunet-gtk/src/plugins/fs/search.h  2005-08-26 08:08:25 UTC (rev 1921)
@@ -59,6 +59,11 @@
  */
 GtkWidget * getAnonymityButtonFromTM(GtkTreeModel * model);
 
+int openTabForSearch(void * unused,
+                    const struct ECRS_URI * uri,
+                    unsigned int anonymityLevel,
+                    unsigned int resultCount,
+                    const ECRS_FileInfo * results);
 
 void fs_search_start(void);
 





reply via email to

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