gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r19595 - gnunet-gtk/src/fs


From: gnunet
Subject: [GNUnet-SVN] r19595 - gnunet-gtk/src/fs
Date: Wed, 1 Feb 2012 13:27:26 +0100

Author: grothoff
Date: 2012-02-01 13:27:26 +0100 (Wed, 01 Feb 2012)
New Revision: 19595

Modified:
   gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
   gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.h
Log:
-more code cleanup

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c     2012-02-01 11:50:19 UTC 
(rev 19594)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c     2012-02-01 12:27:26 UTC 
(rev 19595)
@@ -546,7 +546,7 @@
   char *uris;
   GtkClipboard *cb;
 
-  if (current_context_row_reference == NULL)
+  if (NULL == current_context_row_reference)
   {
     GNUNET_break (0);
     return;
@@ -558,7 +558,7 @@
                       (current_context_search_tab->builder,
                        "_search_result_frame"));
   tm = gtk_tree_view_get_model (tv);
-  if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
+  if (! gtk_tree_model_get_iter (tm, &iter, path))
   {
     GNUNET_break (0);
     gtk_tree_path_free (path);
@@ -1391,13 +1391,13 @@
 /**
  * Setup a new search tab.
  *
- * @param sc context with FS for the search
- * @param query the query
- * @param anonymity anonymity level
+ * @param sc context with FS for the search, NULL for none (open-URI/orphan 
tab)
+ * @param query the query, NULL for none (open-URI/orphan tab)
+ * @return search tab handle
  */
 static struct SearchTab *
-setup_search (struct GNUNET_FS_SearchContext *sc,
-              const struct GNUNET_FS_Uri *query)
+setup_search_tab (struct GNUNET_FS_SearchContext *sc,
+                 const struct GNUNET_FS_Uri *query)
 {
   struct SearchTab *tab;
   GtkTreeView *tv;
@@ -1405,16 +1405,12 @@
   GtkWindow *sf;
   gint pages;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Setting up a search for %p\n", sc);
-
   tab = GNUNET_malloc (sizeof (struct SearchTab));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Allocated a tab %p\n", tab);
   GNUNET_CONTAINER_DLL_insert (search_tab_head, search_tab_tail, tab);
   tab->sc = sc;
   if (query == NULL)
   {
+    /* no real query, tab is for non-queries, use special label */
     tab->query_txt = GNUNET_strdup ("*");
   }
   else
@@ -1547,20 +1543,18 @@
 }
 
 
-
-
 /**
- * Setup a new top-level entry in the URI tab.  If necessary, create
+ * Setup a new top-level entry in the URI/orphan tab.  If necessary, create
  * the URI tab first.
  *
- * @param iter set to the new entry
- * @param srp set to search result
+ * @param iter set to the new entry (OUT only)
+ * @param srp set to search result (can be NULL)
  * @param meta metadata for the new entry
  * @param uri URI for the new entry
- * @return NULL on error, otherwise tree store matching iter
+ * @return the 'uri_tab' the result was added to
  */
 struct SearchTab *
-GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, struct SearchResult **srp,
+GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, struct SearchResult **srp,
                            const struct GNUNET_CONTAINER_MetaData *meta,
                            const struct GNUNET_FS_Uri *uri)
 {
@@ -1568,27 +1562,23 @@
   GtkNotebook *notebook;
   gint page;
 
-  if (uri_tab == NULL)
+  if (NULL == uri_tab)
   {
-    uri_tab = setup_search (NULL, NULL);
+    uri_tab = setup_search_tab (NULL, NULL);
     gtk_widget_set_visible (uri_tab->close_button, FALSE);
     gtk_widget_set_visible (uri_tab->pause_button, FALSE);
   }
-  else
-  {
-    /* make 'utab' the current page */
-    notebook =
-        GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
-                      ("GNUNET_GTK_main_window_notebook"));
-    for (page = 0; page < gtk_notebook_get_n_pages (notebook); page++)
-      if (uri_tab->frame == gtk_notebook_get_nth_page (notebook, page))
-      {
-        gtk_notebook_set_current_page (notebook, page);
-        break;
-      }
-  }
+  /* make 'uri_tab' the current page */
+  notebook =
+    GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
+                 ("GNUNET_GTK_main_window_notebook"));
+  for (page = 0; page < gtk_notebook_get_n_pages (notebook); page++)
+    if (uri_tab->frame == gtk_notebook_get_nth_page (notebook, page))
+    {
+      gtk_notebook_set_current_page (notebook, page);
+      break;
+    }
   sr = GNUNET_GTK_add_search_result (uri_tab, iter, NULL, uri, meta, NULL, 0);
-
   if (NULL != srp)
     *srp = sr;
   return uri_tab;
@@ -1596,12 +1586,10 @@
 
 
 
+/* ***************** Download event handling ****************** */
 
 
 
-/* ***************** Download event handling ****************** */
-
-
 /**
  * Change the (background) color of the given download entry.
  *
@@ -1619,12 +1607,6 @@
              "Changing download DE=%p color to %s\n", 
              de, color);
   path = gtk_tree_row_reference_get_path (de->rr);
-  if (NULL == path)
-  {
-    GNUNET_break (0);
-    gtk_tree_path_free (path);
-    return;
-  }
   if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
   {
     GNUNET_break (0);
@@ -1650,23 +1632,19 @@
   GtkTreeModel *tm;
   struct SearchResult *search_result;
 
+  tm = gtk_tree_row_reference_get_model (de->rr);
   path = gtk_tree_row_reference_get_path (de->rr);
-  tm = gtk_tree_row_reference_get_model (de->rr);
-  if (path != NULL)
+  if (! gtk_tree_model_get_iter (tm, &iter, path))
   {
-    if (! gtk_tree_model_get_iter (tm, &iter, path))
-    {
-      GNUNET_break (0);
-    }
-    else
-    {
-      gtk_tree_model_get (tm, &iter, 9, &search_result, -1);
-      GNUNET_assert (search_result->download == de); 
-      search_result->download = NULL;
-      change_download_color (de, "white");
-    }
     gtk_tree_path_free (path);
+    GNUNET_break (0);
+    return;
   }
+  gtk_tree_path_free (path);
+  gtk_tree_model_get (tm, &iter, 9, &search_result, -1);
+  GNUNET_assert (search_result->download == de); 
+  search_result->download = NULL;
+  change_download_color (de, "white");
   gtk_tree_row_reference_free (de->rr);
   GNUNET_FS_uri_destroy (de->uri);
   GNUNET_CONTAINER_meta_data_destroy (de->meta);
@@ -1674,7 +1652,6 @@
 }
 
 
-
 /**
  * Closure for 'add_directory_entry'.
  */
@@ -1682,9 +1659,9 @@
 {
 
   /**
-   * FIXME
+   * Search tab where we need to expand the result list.
    */
-  struct DownloadEntry *de;
+  struct SearchTab *tab;
 
   /**
    * Row reference of parent (the directory).
@@ -1704,11 +1681,19 @@
 
 
 /**
- * Function used to process entries in a directory.
+ * Function used to process entries in a directory.  Whenever we
+ * download a directory, this function is called on the entries in the
+ * directory to add them to the search tab.  Note that the function
+ * maybe called twice for the same entry, once during incremental
+ * processing and later once more when we have the complete directory.
  *
+ * For the second round, the 'check_duplicates' flag will be set in
+ * the closure.  If called on an entry that already exists, the
+ * function should simply do nothing.
+ *
  * @param cls closure, our 'struct AddDirectoryEntryContext*'
  * @param filename name of the file in the directory
- * @param uri URI of the file
+ * @param uri URI of the file, NULL for the directory itself
  * @param metadata metadata for the file; metadata for
  *        the directory if everything else is NULL/zero
  * @param length length of the available data for the file
@@ -1730,19 +1715,23 @@
   GtkTreePath *path;
   GtkTreeModel *tm;
   struct GNUNET_FS_Uri *xuri;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding directory entry `%s'\n", 
filename);
 
-  if (uri == NULL)
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+             "Adding directory entry `%s'\n", 
+             filename);
+
+  if (NULL == uri)
   {
     /* directory meta data itself */
-    /* FIXME: consider merging it in... */
+    /* FIXME: consider merging it with the meta data from
+       the original search result... */
     return;
   }
   if (ade->check_duplicates == GNUNET_YES)
   {
+    tm = gtk_tree_row_reference_get_model (ade->prr);
     path = gtk_tree_row_reference_get_path (ade->prr);
-    tm = gtk_tree_row_reference_get_model (ade->prr);
-    if (TRUE != gtk_tree_model_get_iter (tm, &piter, path))
+    if (! gtk_tree_model_get_iter (tm, &piter, path)) 
     {
       GNUNET_break (0);
       gtk_tree_path_free (path);
@@ -1760,12 +1749,25 @@
       while (TRUE == gtk_tree_model_iter_next (tm, &iter));
     }
   }
-  GNUNET_GTK_add_search_result (ade->de->tab, &iter, ade->prr, uri, meta, NULL,
+  GNUNET_GTK_add_search_result (ade->tab, &iter, ade->prr, uri, meta, NULL,
                                 0);
 }
 
 
-static struct DownloadEntry *
+/**
+ * We got an event that some download is progressing.  Update the tree
+ * model accordingly.  If the download is a directory, try to display
+ * the contents.
+ *
+ * @param de download entry that is progressing
+ * @param size overall size of the download
+ * @param completed number of bytes we have completed
+ * @param block_data current block we've downloaded
+ * @param offset offset of block_data in the overall file
+ * @param block_size number of bytes in block_data
+ * @param depth depth of the block in the ECRS tree
+ */
+static void
 mark_download_progress (struct DownloadEntry *de, uint64_t size,
                         uint64_t completed, const void *block_data,
                         uint64_t offset, uint64_t block_size,
@@ -1775,65 +1777,74 @@
   GtkTreePath *path;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Marking download progress for DE=%p, %llu/%llu, address@hidden 
depth=%u\n",
-      de, completed, size, block_size, offset, depth);
+             "Marking download progress for DE=%p, %llu/%llu, address@hidden 
depth=%u\n",
+             de, completed, size, block_size, offset, depth);
 
-
   path = gtk_tree_row_reference_get_path (de->rr);
-  if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
+  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
   {
     GNUNET_break (0);
     gtk_tree_path_free (path);
-    return de;
+    return;
   }
   gtk_tree_path_free (path);
-  gtk_tree_store_set (de->ts, &iter, 4,
-                      (guint) ((size >
-                                0) ? (100 * completed /
-                                      size) : 100) /* progress */ ,
-                      14, completed, -1);
-  if ((depth == 0) && (block_size > 0) &&
-      (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)))
+  /* FIXME: update availability-score here as well! */
+  gtk_tree_store_set (de->ts, &iter, 
+                     4, (guint) ((size >
+                                  0) ? (100 * completed /
+                                        size) : 100) /* progress */ ,
+                      14, completed, 
+                     -1);
+  if ( (depth == 0) &&
+       (block_size > 0) &&
+       (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) )
   {
+    /* got a data block of a directory, list its contents */
     struct AddDirectoryEntryContext ade;
-    ade.de = de;
+
+    ade.tab = de->tab;
     ade.prr = de->rr;
     ade.check_duplicates = GNUNET_NO;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "It is a directory, list its 
contents\n");
     if (GNUNET_SYSERR ==
         GNUNET_FS_directory_list_contents ((size_t) block_size, block_data,
                                            offset, &add_directory_entry, &ade))
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _
-                  ("Metadata wrongly claims that this is a GNUnet 
directory!\n"));
+      /* Mime type was wrong, this is not a directory, update model! */
+      GNUNET_break (GNUNET_OK ==
+                   GNUNET_CONTAINER_meta_data_delete (de->meta,
+                                                      
EXTRACTOR_METATYPE_MIMETYPE, NULL, 0));
+      gtk_tree_store_set (de->ts, &iter, 
+                         10, "" /* unknown mime type */, -1);
     }
   }
-  return de;
 }
 
 
-static struct DownloadEntry *
-mark_download_error (struct DownloadEntry *de, const char *emsg)
+/**
+ * FS-API encountered an error downloading a file.  Update the
+ * view accordingly.
+ *
+ * @param de download that had an error
+ * @param emsg error message to display
+ */
+static void
+mark_download_error (struct DownloadEntry *de,
+                    const char *emsg)
 {
   GtkTreeIter iter;
   GtkTreePath *path;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Marking download error for DE=%p: %s\n", de, emsg);
   change_download_color (de, "red");
   de->is_done = GNUNET_YES;
   path = gtk_tree_row_reference_get_path (de->rr);
-  if (TRUE !=
-      gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path))
+  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path))
   {
     GNUNET_break (0);
     gtk_tree_path_free (path);
-    return de;
+    return;
   }
   gtk_tree_path_free (path);
   gtk_tree_store_set (de->tab->ts, &iter, 4, 0, 7, emsg, -1);
-  return de;
 }
 
 
@@ -1848,11 +1859,11 @@
       de, size, filename);
 
   de->is_done = GNUNET_YES;
-  (void) mark_download_progress (de, size, size, NULL, 0, 0, 0);
+  mark_download_progress (de, size, size, NULL, 0, 0, 0);
   if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) &&
       (filename != NULL))
   {
-    ade.de = de;
+    ade.tab = de->tab;
     ade.prr = de->rr;
     ade.check_duplicates = GNUNET_YES;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "It is a directory, scan its 
contents\n");
@@ -1995,11 +2006,6 @@
   tm_old = gtk_tree_row_reference_get_model (rr_old);
   path = gtk_tree_row_reference_get_path (rr_old);
   gtk_tree_row_reference_free (rr_old);
-  if (NULL == path)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
   if (TRUE != gtk_tree_model_get_iter (tm_old, &iter_old, path))
   {
     GNUNET_break (0);
@@ -2146,11 +2152,6 @@
              "Changing publish PE=%p color to %s\n", 
              pe, color);
   path = gtk_tree_row_reference_get_path (pe->rr);
-  if (NULL == path)
-  {
-    GNUNET_break (0);
-    return;
-  }
   if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path))
   {
     GNUNET_break (0);
@@ -2494,29 +2495,28 @@
                         info->value.download.size,
                         info->value.download.completed);
     if (info->value.download.specifics.resume.message != NULL)
-    {
-      ret =
-          mark_download_error (ret,
-                               info->value.download.specifics.resume.message);
-    }
+      mark_download_error (ret,
+                          info->value.download.specifics.resume.message);   
     return ret;
   case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
     stop_download (info->value.download.cctx);
     return NULL;
   case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
-    return mark_download_progress (info->value.download.cctx,
-                                   info->value.download.size,
-                                   info->value.download.completed,
-                                   
info->value.download.specifics.progress.data,
-                                   info->value.download.specifics.progress.
-                                   offset,
-                                   info->value.download.specifics.progress.
-                                   data_len,
-                                   info->value.download.specifics.progress.
-                                   depth);
+    mark_download_progress (info->value.download.cctx,
+                           info->value.download.size,
+                           info->value.download.completed,
+                           info->value.download.specifics.progress.data,
+                           info->value.download.specifics.progress.
+                           offset,
+                           info->value.download.specifics.progress.
+                           data_len,
+                           info->value.download.specifics.progress.
+                           depth);
+    return info->value.download.cctx;
   case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
-    return mark_download_error (info->value.download.cctx,
-                                info->value.download.specifics.error.message);
+    mark_download_error (info->value.download.cctx,
+                        info->value.download.specifics.error.message);
+    return info->value.download.cctx;
   case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
     return mark_download_completed (info->value.download.cctx,
                                     info->value.download.size,
@@ -2539,9 +2539,9 @@
     if (info->value.search.pctx != NULL)
       return setup_inner_search (info->value.search.sc,
                                  info->value.search.pctx);
-    return setup_search (info->value.search.sc, info->value.search.query);
+    return setup_search_tab (info->value.search.sc, info->value.search.query);
   case GNUNET_FS_STATUS_SEARCH_RESUME:
-    ret = setup_search (info->value.search.sc, info->value.search.query);
+    ret = setup_search_tab (info->value.search.sc, info->value.search.query);
     if (info->value.search.specifics.resume.message)
       handle_search_error (ret,
                           info->value.search.specifics.resume.message);

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.h     2012-02-01 11:50:19 UTC 
(rev 19594)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.h     2012-02-01 12:27:26 UTC 
(rev 19595)
@@ -175,17 +175,15 @@
 };
 
 
-
-
 /**
- * Setup a new top-level entry in the URI tab.  If necessary, create
+ * Setup a new top-level entry in the URI/orphan tab.  If necessary, create
  * the URI tab first.
  *
- * @param iter set to the new entry
- * @param srp set to search result
+ * @param iter set to the new entry (OUT only)
+ * @param srp set to search result (can be NULL)
  * @param meta metadata for the new entry
  * @param uri URI for the new entry
- * @return NULL on error, otherwise search tab with the new entry
+ * @return the 'uri_tab' the result was added to
  */
 struct SearchTab *
 GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, struct SearchResult **sr,
@@ -193,7 +191,6 @@
                            const struct GNUNET_FS_Uri *uri);
 
 
-
 /**
  * Add a search result to the given search tab.
  *
@@ -212,8 +209,9 @@
  *                model at 'iter')
  */
 struct SearchResult *
-GNUNET_GTK_add_search_result (struct SearchTab *tab, GtkTreeIter * iter,
-                              GtkTreeRowReference * parent_rr,
+GNUNET_GTK_add_search_result (struct SearchTab *tab, 
+                             GtkTreeIter *iter,
+                              GtkTreeRowReference *parent_rr,
                               const struct GNUNET_FS_Uri *uri,
                               const struct GNUNET_CONTAINER_MetaData *meta,
                               struct GNUNET_FS_SearchResult *result,




reply via email to

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