gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19682 - gnunet-gtk/src/fs
Date: Sat, 4 Feb 2012 20:30:07 +0100

Author: grothoff
Date: 2012-02-04 20:30:06 +0100 (Sat, 04 Feb 2012)
New Revision: 19682

Modified:
   gnunet-gtk/src/fs/gnunet-fs-gtk_download-save-as.c
   gnunet-gtk/src/fs/gnunet-fs-gtk_download-save-as.h
   gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
   gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.h
   gnunet-gtk/src/fs/gnunet-fs-gtk_open-directory.c
   gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.c
Log:
-simplify data structures by eliminating the DownloadContext -- virtually a 
full duplicate of the DownloadEntry

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_download-save-as.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_download-save-as.c  2012-02-04 17:56:27 UTC 
(rev 19681)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_download-save-as.c  2012-02-04 19:30:06 UTC 
(rev 19682)
@@ -34,10 +34,10 @@
 {
 
   /**
-   * Download context for which this dialog determines the
+   * Download entry for which this dialog determines the
    * filename (and other options).
    */
-  struct DownloadContext *dc;
+  struct DownloadEntry *de;
 
   /**
    * Builder for the dialog.
@@ -53,21 +53,24 @@
 
 
 /**
- * Free resources associated with the given download context.
+ * Free resources associated with the given download entry.
  *
- * @param dc context to free
+ * @param de context to free
  */
-static void
-save_as_dialog_free_download_context (struct DownloadContext *dc)
+void
+GNUNET_FS_GTK_free_download_entry (struct DownloadEntry *de)
 {
-  if (NULL != dc->rr)
-    gtk_tree_row_reference_free (dc->rr);
-  GNUNET_free_non_null (dc->filename);
-  if (NULL != dc->meta)
-    GNUNET_CONTAINER_meta_data_destroy (dc->meta);
-  if (NULL != dc->uri)
-    GNUNET_FS_uri_destroy (dc->uri);
-  GNUNET_free (dc);  
+  GNUNET_assert (NULL == de->dc);
+  if (NULL != de->sr)
+  {
+    GNUNET_assert (de->sr->download == de); 
+    de->sr->download = NULL;
+  }
+  GNUNET_free_non_null (de->filename);
+  if (NULL != de->meta)
+    GNUNET_CONTAINER_meta_data_destroy (de->meta);
+  GNUNET_FS_uri_destroy (de->uri);
+  GNUNET_free (de);  
 }
 
 
@@ -87,7 +90,7 @@
 {
   struct DownloadAsDialogContext *dlc = user_data;
 
-  save_as_dialog_free_download_context (dlc->dc);
+  GNUNET_FS_GTK_free_download_entry (dlc->de);
   g_object_unref (G_OBJECT (dlc->builder));
   GNUNET_free (dlc);
   return FALSE;
@@ -108,37 +111,36 @@
                                        gpointer user_data)
 {
   struct DownloadAsDialogContext *dlc = user_data;
-  struct DownloadContext *dc;
+  struct DownloadEntry *de;
   GtkToggleButton *cb;
 
-  dc = dlc->dc;
-
+  de = dlc->de;
   if (GTK_RESPONSE_OK != response_id)
   {
-    save_as_dialog_free_download_context (dc);
+    GNUNET_FS_GTK_free_download_entry (de);
     gtk_widget_destroy (GTK_WIDGET (dialog));
     g_object_unref (G_OBJECT (dlc->builder));
     GNUNET_free (dlc);
     return;
   }
-  GNUNET_free_non_null (dc->filename);
-  dc->filename =
+  GNUNET_free_non_null (de->filename);
+  de->filename =
       GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER 
(dlc->dialog));
   cb = GTK_TOGGLE_BUTTON (gtk_builder_get_object
                          (dlc->builder, 
"GNUNET_GTK_save_as_recursive_check_button"));
-  dc->is_recursive =
+  de->is_recursive =
       (TRUE ==
        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES :
       GNUNET_NO;
-  dc->anonymity =
-      gtk_spin_button_get_value (GTK_SPIN_BUTTON
-                                 (gtk_builder_get_object
-                                  (dlc->builder,
-                                   
"GNUNET_GTK_save_as_dialog_anonymity_spin_button")));
+  de->anonymity =
+    (uint32_t) gtk_spin_button_get_value (GTK_SPIN_BUTTON
+                                         (gtk_builder_get_object
+                                          (dlc->builder,
+                                           
"GNUNET_GTK_save_as_dialog_anonymity_spin_button")));
   gtk_widget_destroy (GTK_WIDGET (dialog));
   g_object_unref (G_OBJECT (dlc->builder));
   GNUNET_free (dlc);
-  GNUNET_FS_GTK_download_context_start_download (dc);
+  GNUNET_FS_GTK_download_context_start_download (de);
 }
 
 
@@ -147,23 +149,23 @@
  * continutation when the dialog is complete.  Will release the 'dc'
  * resources if the dialog is cancelled.
  *
- * @param dc download context for the file/directory 
+ * @param de download context for the file/directory 
  */
 void
-GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc)
+GNUNET_FS_GTK_open_download_as_dialog (struct DownloadEntry *de)
 {
   struct DownloadAsDialogContext *dlc;
   GtkWidget *cb;
 
   dlc = GNUNET_malloc (sizeof (struct DownloadAsDialogContext));
-  dlc->dc = dc;
+  dlc->de = de;
   dlc->builder =
     GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade",
                                dlc);
   if (NULL == dlc->builder)
   {
     GNUNET_break (0);
-    save_as_dialog_free_download_context (dc);
+    GNUNET_FS_GTK_free_download_entry (de);
     GNUNET_free (dlc);
     return;
   }
@@ -174,18 +176,18 @@
      set recursive 'default' value based on what the 'dc' tells us */
   cb = GTK_WIDGET (gtk_builder_get_object
                    (dlc->builder, 
"GNUNET_GTK_save_as_recursive_check_button"));
-  if (GNUNET_FS_meta_data_test_for_directory (dc->meta))
+  if (GNUNET_FS_meta_data_test_for_directory (de->meta))
     gtk_widget_set_sensitive (cb, TRUE);  
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb),
-                               dc->is_recursive);   
+                               de->is_recursive);   
 
   /* initialize filename based on filename from 'dc' */
-  if (NULL != dc->filename)
+  if (NULL != de->filename)
   {
     char *dirname;
     char *basename;
 
-    dirname = GNUNET_strdup (dc->filename);
+    dirname = GNUNET_strdup (de->filename);
     basename = (char *) GNUNET_STRINGS_get_short_name (dirname);
     /* basename now points into 'dirname'; cut 'dirname' off at the '/' before 
basename */
     if (basename > dirname)
@@ -194,7 +196,7 @@
     /* FIXME: remove following lines after testing... */
     fprintf (stderr,
             "Splitting `%s' into `%s' + `%s' for file chooser dialog.\n",
-            dc->filename,
+            de->filename,
             dirname,
             basename);
 
@@ -214,74 +216,45 @@
  * respective tree model and trigger a start of the download using the
  * FS-API.
  *
- * @param dc download context of the download to execute
+ * @param de download context of the download to execute
  */
 void
-GNUNET_FS_GTK_download_context_start_download (struct DownloadContext *dc)
+GNUNET_FS_GTK_download_context_start_download (struct DownloadEntry *de)
 {
   enum GNUNET_FS_DownloadOptions opt;
   struct GNUNET_FS_Handle *fs;
-  struct DownloadEntry *de;
   uint64_t len;
-  GtkTreeIter iter;
-  GtkTreePath *path;
 
-  de = GNUNET_malloc (sizeof (struct DownloadEntry));
-  de->uri = dc->uri;
-  dc->uri = NULL;
-  de->meta = dc->meta;
-  de->tab = dc->tab;
-  dc->meta = NULL;
-  if (NULL != dc->rr)
-  {
-    de->rr = gtk_tree_row_reference_copy (dc->rr);
-    path = gtk_tree_row_reference_get_path (de->rr);
-    if  ( (NULL != path) &&
-         (gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path)) 
)
-    {
-      /* Store filename and anonymity as specified by the user.
-       * These will be re-used when this is a directory, and the user
-       * downloads its children.
-       */
-      gtk_tree_store_set (de->tab->ts, &iter, 15, dc->filename, 16, 
dc->anonymity, -1);
-    } 
-    else
-    {
-      /* We could not find the referenced row in the search tab; this is
-        conceivable as the search tab might have been closed by the 
-        user while the 'save as' dialog was open.  In this case, this
-        is equivalent to having no search, so we drop the (now invalid)
-        'sr' reference */
-      dc->sr = NULL;
-    }
-    if (NULL != path)
-      gtk_tree_path_free (path);
-  }
   fs = GNUNET_FS_GTK_get_fs_handle ();
   opt = GNUNET_FS_DOWNLOAD_OPTION_NONE;
-  if (dc->is_recursive)
+  if (de->is_recursive)
     opt |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
   len = GNUNET_FS_uri_chk_get_file_size (de->uri);
-  if (NULL != dc->sr)
+  if (NULL != de->sr)
   {
     GNUNET_break (NULL !=
-                  GNUNET_FS_download_start_from_search (fs, dc->sr,
-                                                        dc->filename,
+                  GNUNET_FS_download_start_from_search (fs, 
+                                                       de->sr->result,
+                                                        de->filename,
                                                         NULL /* tempname */ ,
                                                         0 /* offset */ ,
-                                                        len, dc->anonymity, 
opt,
+                                                        len, 
+                                                       de->anonymity, opt,
                                                         de));
   }
   else
   {
     GNUNET_break (NULL !=
-                  GNUNET_FS_download_start (fs, de->uri, NULL /* meta */ ,
-                                            dc->filename, NULL /* tempname */ ,
+                  GNUNET_FS_download_start (fs, 
+                                           de->uri, 
+                                           de->meta,
+                                            de->filename, NULL /* tempname */ ,
                                             0 /* offset */ ,
-                                            len, dc->anonymity, opt, de,
-                                            NULL /* parent download ctx */ ));
+                                            len, 
+                                           de->anonymity, opt, 
+                                           de,
+                                            (NULL != de->pde) ? de->pde->dc : 
NULL));
   }
-  save_as_dialog_free_download_context (dc);
 }
 
 

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_download-save-as.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_download-save-as.h  2012-02-04 17:56:27 UTC 
(rev 19681)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_download-save-as.h  2012-02-04 19:30:06 UTC 
(rev 19682)
@@ -27,74 +27,19 @@
 #define GNUNET_FS_GTK_DOWNLOAD_SAVE_AS_H
 
 #include "gnunet-fs-gtk_common.h"
+#include "gnunet-fs-gtk_event-handler.h"
 
 
 /**
- * Information we keep for a download.
- */
-struct DownloadContext;
-
-
-/**
- * Information we keep for a download.
- */
-struct DownloadContext
-{
-  /**
-   * URI for the download.
-   */
-  struct GNUNET_FS_Uri *uri;
-
-  /**
-   * Meta data.
-   */
-  struct GNUNET_CONTAINER_MetaData *meta;
-
-  /**
-   * Suggested filename, or NULL.
-   */
-  char *filename;
-
-  /**
-   * Row reference (if URI was found by search, or
-   * part of directory, etc.); otherwise NULL (download by URI).
-   */
-  GtkTreeRowReference *rr;
-
-  /**
-   * Associated search result, or NULL.
-   */
-  struct GNUNET_FS_SearchResult *sr;
-
-  /**
-   * Is this a recursive download?
-   */
-  int is_recursive;
-
-  /**
-   * Desired (default) anonymity level.
-   */
-  int anonymity;
-
-  /**
-   * Tab where this download is currently on display.
-   * (this is the same as sr->tab, but sr is opaque here).
-   */
-  struct SearchTab *tab;
-
-};
-
-
-/**
  * Actually start the download that is specified by the given download
  * context and its options.  Will add a download entry to the
  * respective tree model and trigger a start of the download using the
  * FS-API.
  *
- * @param dc download context of the download to execute
+ * @param de download entry of the download to execute
  */
 void
-GNUNET_FS_GTK_download_context_start_download (struct DownloadContext *dc);
+GNUNET_FS_GTK_download_context_start_download (struct DownloadEntry *de);
 
 
 /**
@@ -106,7 +51,17 @@
  * @param dc download context for the file/directory 
  */
 void
-GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc);
+GNUNET_FS_GTK_open_download_as_dialog (struct DownloadEntry *de);
 
 
+/**
+ * Free resources associated with the given download entry.
+ *
+ * @param de context to free
+ */
+void
+GNUNET_FS_GTK_free_download_entry (struct DownloadEntry *de);
+
+
+
 #endif

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c     2012-02-04 17:56:27 UTC 
(rev 19681)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c     2012-02-04 19:30:06 UTC 
(rev 19682)
@@ -88,38 +88,7 @@
 };
 
 
-/**
- * Information we keep for each search result entry in any search tab.
- * An entry like this is also generated for downloads by-URI.  Used to
- * quickly identify the tab and row of the result; stored in the
- * user-context of the FS library for the search result.
- */
-struct SearchResult
-{
-  /**
-   * Where in the tab is this result?
-   */
-  GtkTreeRowReference *rr;
 
-  /**
-   * Tab storing this result.
-   */
-  struct SearchTab *tab;
-
-  /**
-   * Search result for top-level results and
-   * namespace-update results.
-   */
-  struct GNUNET_FS_SearchResult *result;
-
-  /**
-   * Associated download, or NULL for none.
-   */
-  struct DownloadEntry *download;
-};
-
-
-
 /**
  * Head of linked list of tabs for searches.
  */
@@ -327,7 +296,7 @@
   struct GNUNET_FS_Uri *uri;
   struct GNUNET_CONTAINER_MetaData *meta;
   struct SearchResult *sr;
-  struct DownloadContext *dc;
+  struct DownloadEntry *de;
   char *buf = NULL;
   char *tmp;
   size_t tmplen;
@@ -357,6 +326,11 @@
        have no URI and downloading makes no sense. Ignore! */
     return;
   }
+  if (NULL != sr->download)
+  {
+    /* download already active! */
+    return;
+  }
   if (!(GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)))
   {
     /* can only download chk/loc URIs, ignore */
@@ -414,16 +388,14 @@
   GNUNET_free_non_null (filename);
 
   /* now setup everything for the save-as dialog */
-  dc = GNUNET_malloc (sizeof (struct DownloadContext));
-  dc->uri = GNUNET_FS_uri_dup (uri);
-
-  dc->filename = buf;
-  dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
-  dc->rr = gtk_tree_row_reference_new (tm, path);
-  dc->sr = sr->result;
-  dc->anonymity = anonymity;
-  dc->is_recursive = is_recursive;
-  dc->tab = tab;
+  de = GNUNET_malloc (sizeof (struct DownloadEntry));
+  de->uri = GNUNET_FS_uri_dup (uri);
+  de->filename = buf;
+  de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
+  de->sr = sr;
+  sr->download = de;
+  de->anonymity = anonymity;
+  de->is_recursive = is_recursive;
   fprintf (stderr,
           "lp %d, have-sug: %d\n",
           local_parents,
@@ -431,9 +403,9 @@
   if ( (GNUNET_YES == local_parents) &&
        (GNUNET_YES == have_a_suggestion) )
     /* Skip the dialog, call directly */
-    GNUNET_FS_GTK_download_context_start_download (dc);
+    GNUNET_FS_GTK_download_context_start_download (de);
   else
-    GNUNET_FS_GTK_open_download_as_dialog (dc);
+    GNUNET_FS_GTK_open_download_as_dialog (de);
 }
 
 
@@ -1511,18 +1483,16 @@
  * 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 (OUT only)
- * @param srp set to search result (can be NULL)
+ * @param iter set to the new entry (OUT only) -- FIXME: remove, obtainable as 
'RETVAL->rr'
  * @param meta metadata for the new entry
  * @param uri URI for the new entry
- * @return the 'uri_tab' the result was added to
+ * @return the search result that was set up
  */
-struct SearchTab *
-GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, struct SearchResult **srp,
+struct SearchResult *
+GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, 
                            const struct GNUNET_CONTAINER_MetaData *meta,
                            const struct GNUNET_FS_Uri *uri)
 {
-  struct SearchResult *sr;
   GtkNotebook *notebook;
   gint page;
 
@@ -1542,10 +1512,7 @@
       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;
+  return GNUNET_GTK_add_search_result (uri_tab, iter, NULL, uri, meta, NULL, 
0);
 }
 
 
@@ -1570,15 +1537,15 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
              "Changing download DE=%p color to %s\n", 
              de, color);
-  path = gtk_tree_row_reference_get_path (de->rr);
-  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path))
+  path = gtk_tree_row_reference_get_path (de->sr->rr);
+  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, 
path))
   {
     GNUNET_break (0);
     gtk_tree_path_free (path);
     return;
   }
   gtk_tree_path_free (path);
-  gtk_tree_store_set (de->tab->ts, &iter, 8, color, -1);
+  gtk_tree_store_set (de->sr->tab->ts, &iter, 8, color, -1);
 }
 
 
@@ -1591,16 +1558,8 @@
 static void
 stop_download (struct DownloadEntry *de)
 {
-  if (NULL != de->sr)
-  {
-    GNUNET_assert (de->sr->download == de); 
-    de->sr->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);
-  GNUNET_free (de);
+  GNUNET_FS_GTK_free_download_entry (de);
 }
 
 
@@ -1732,8 +1691,8 @@
              "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 (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path))
+  path = gtk_tree_row_reference_get_path (de->sr->rr);
+  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, 
path))
   {
     GNUNET_break (0);
     gtk_tree_path_free (path);
@@ -1744,7 +1703,7 @@
      'progress' once the download has started and re-use the
      space in the display? Probably yes, at least once we have
      a custom CellRenderer... */
-  gtk_tree_store_set (de->tab->ts, &iter, 
+  gtk_tree_store_set (de->sr->tab->ts, &iter, 
                      4, (guint) ((size >
                                   0) ? (100 * completed /
                                         size) : 100) /* progress */,
@@ -1760,8 +1719,8 @@
     /* got a data block of a directory, list its contents */
     struct AddDirectoryEntryContext ade;
 
-    ade.tab = de->tab;
-    ade.prr = de->rr;
+    ade.tab = de->sr->tab;
+    ade.prr = de->sr->rr;
     ade.check_duplicates = GNUNET_NO;
     if (GNUNET_SYSERR ==
         GNUNET_FS_directory_list_contents ((size_t) block_size, block_data,
@@ -1771,7 +1730,7 @@
       GNUNET_break (GNUNET_OK ==
                    GNUNET_CONTAINER_meta_data_delete (de->meta,
                                                       
EXTRACTOR_METATYPE_MIMETYPE, NULL, 0));
-      gtk_tree_store_set (de->tab->ts, &iter, 
+      gtk_tree_store_set (de->sr->tab->ts, &iter, 
                          10, "" /* unknown mime type */, -1);
     }
   }
@@ -1794,15 +1753,15 @@
 
   change_download_color (de, "red");
   de->is_done = GNUNET_YES;
-  path = gtk_tree_row_reference_get_path (de->rr);
-  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path))
+  path = gtk_tree_row_reference_get_path (de->sr->rr);
+  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, 
path))
   {
     GNUNET_break (0);
     gtk_tree_path_free (path);
     return;
   }
   gtk_tree_path_free (path);
-  gtk_tree_store_set (de->tab->ts, &iter, 4, 0, 7, emsg, -1);
+  gtk_tree_store_set (de->sr->tab->ts, &iter, 4, 0, 7, emsg, -1);
 }
 
 
@@ -1832,8 +1791,8 @@
   {
     /* download was for a directory (and we have a temp file for scanning);
        add contents of the directory to the view */
-    ade.tab = de->tab;
-    ade.prr = de->rr;
+    ade.tab = de->sr->tab;
+    ade.prr = de->sr->rr;
     ade.check_duplicates = GNUNET_YES;
     GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade);
   }
@@ -1915,12 +1874,6 @@
     search_result->rr = gtk_tree_row_reference_new (dst_model, path);
     search_result->result = NULL;
     gtk_tree_path_free (path);
-    if (search_result->download != NULL)
-    {
-      gtk_tree_row_reference_free (search_result->download->rr);
-      search_result->download->rr =
-       gtk_tree_row_reference_copy (search_result->rr);
-    }
     copy_children (src_model, &src_child, dst_model, &dst_child);
   }
   while (TRUE == gtk_tree_model_iter_next (src_model, &src_child));
@@ -1957,7 +1910,6 @@
 {
   GtkTreeIter iter;
   GtkTreePath *path;
-  struct SearchTab *tab;
   GtkTreeRowReference *rr_old;
   GtkTreeModel *tm_old;
   GtkTreeIter iter_old;
@@ -1965,17 +1917,16 @@
   GtkTreeModel *model;
 
   /* first, move the root of the respective 'de'-tree */
-  rr_old = de->rr;
-  tab = GNUNET_GTK_add_to_uri_tab (&iter, &de->sr, de->meta, de->uri);
-  de->tab = tab;
+  rr_old = de->sr->rr;
+  de->sr = GNUNET_GTK_add_to_uri_tab (&iter, de->meta, de->uri);
   de->sr->download = de;
-  model = GTK_TREE_MODEL (de->tab->ts);
-  path = gtk_tree_model_get_path (model, &iter);
-  de->rr = gtk_tree_row_reference_new (model, path);
-  gtk_tree_path_free (path);
+
+  model = GTK_TREE_MODEL (de->sr->tab->ts);
+
   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 (! gtk_tree_model_get_iter (tm_old, &iter_old, path))
   {
     GNUNET_break (0);
@@ -2014,13 +1965,11 @@
 {
   GtkTreeIter iter;
   GtkTreePath *path;
-  struct SearchResult *srp;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Setting up download, initially DE=%p, PDE=%p for %p & %p into 
%llu/%llu `%s'\n",
              de, pde, sr, dc, completed, size, filename);
   GNUNET_assert (NULL != uri);
-  srp = NULL;
   if (NULL == de)
   {
     /* no existing download entry to build on, create a fresh one */
@@ -2032,47 +1981,49 @@
     GNUNET_assert (GNUNET_YES == GNUNET_FS_uri_test_equal (de->uri, uri));
   }
   de->dc = dc;
-  de->sr = sr;
   de->pde = pde;
   if ( (meta != NULL) && (de->meta == NULL) )
     de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
-  if (NULL != sr)
+  if (NULL != sr) 
   {
-    /* got a search result; display the download in the same location as the 
search result */
-    GNUNET_assert (sr->download == NULL);
-    sr->download = de;
-    de->rr = gtk_tree_row_reference_copy (sr->rr);
-    de->tab = sr->tab;
-    srp = sr;
+    /* have a search result, establish mapping de <--> sr */
+    if (NULL == de->sr)
+    {
+      GNUNET_assert (sr->download == NULL);
+      de->sr = sr;
+      sr->download = de;
+    } 
+    else
+    {
+      GNUNET_assert (sr == de->sr);
+    }
   }
-  if (NULL == de->rr)
+  if (NULL == de->sr)
   {
     /* Stand-alone download with no 'row'/search result affiliated
        with the download so far; create a fresh entry for this
        download in the URI tab */
-    de->tab = GNUNET_GTK_add_to_uri_tab (&iter, &srp, meta, uri);
-    path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->tab->ts), &iter);
-    de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->tab->ts), path);
-    gtk_tree_path_free (path);
-    srp->download = de;
+    de->sr = GNUNET_GTK_add_to_uri_tab (&iter, meta, uri);
+    de->sr->download = de;
   }
-  GNUNET_assert (NULL != de->tab);
-  path = gtk_tree_row_reference_get_path (de->rr);
-  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path))
+  path = gtk_tree_row_reference_get_path (de->sr->rr);
+  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, 
path))
   {
     GNUNET_break (0);
     gtk_tree_path_free (path);
     return de;
   }
   gtk_tree_path_free (path);
-  gtk_tree_store_set (de->tab->ts, &iter, 
+  gtk_tree_store_set (de->sr->tab->ts, &iter, 
                      4,   (guint) ((size >
                                 0) ? (100 * completed /
                                       size) : 100) /* progress */ ,
                       6, filename /* filename/description */ ,
                       8, "blue" /* status colour: pending */ ,
-                     9, srp,
+                     9, de->sr,
                      14, completed,
+                     15, de->filename,
+                     16, de->anonymity,
                       -1);
   return de;
 }

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.h     2012-02-04 17:56:27 UTC 
(rev 19681)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.h     2012-02-04 19:30:06 UTC 
(rev 19682)
@@ -23,6 +23,9 @@
  * @brief Main event handler for file-sharing
  * @author Christian Grothoff
  */
+#ifndef GNUNET_FS_GTK_EVENT_HANDLER_H
+#define GNUNET_FS_GTK_EVENT_HANDLER_H
+
 #include "gnunet-fs-gtk_common.h"
 
 
@@ -133,35 +136,75 @@
   struct SearchResult *sr;
 
   /**
-   * FS handle to control the download.
+   * FS handle to control the download, NULL if the download
+   * has not yet started.
    */
   struct GNUNET_FS_DownloadContext *dc;
 
   /**
-   * URI for the download.
+   * URI for the download, never NULL.
    */
   struct GNUNET_FS_Uri *uri;
 
   /**
-   * Meta data for the download.
+   * Meta data for the download, can be NULL (i.e. for download
+   * by URI).  In that case, we'll need to figure out if the 
+   * result is a directory later!
    */
   struct GNUNET_CONTAINER_MetaData *meta;
 
   /**
-   * Where in the tree view is this download being displayed.
+   * Suggested (or selected) filename for the download on the
+   * local disk, or NULL for on suggestion.
    */
+  char *filename;
+
+  /**
+   * Is this a recursive download?
+   */
+  int is_recursive;
+
+  /**
+   * Desired (default) anonymity level.
+   */
+  uint32_t anonymity;
+
+  /**
+   * Has the download completed (or failed)?
+   */
+  int is_done;
+
+};
+
+
+/**
+ * Information we keep for each search result entry in any search tab.
+ * An entry like this is also generated for downloads by-URI.  Used to
+ * quickly identify the tab and row of the result; stored in the
+ * user-context of the FS library for the search result.
+ */
+struct SearchResult
+{
+  /**
+   * Where in the tab is this result?
+   */
   GtkTreeRowReference *rr;
 
   /**
-   * Tab where this download is currently on display.
+   * Tab storing this result.
    */
   struct SearchTab *tab;
 
   /**
-   * Has the download completed (or errored)?
+   * Search result for top-level results and
+   * namespace-update results.
    */
-  int is_done;
+  struct GNUNET_FS_SearchResult *result;
 
+  /**
+   * Associated download, or NULL for none.
+   */
+  struct DownloadEntry *download;
 };
 
 
@@ -170,13 +213,12 @@
  * the URI tab first.
  *
  * @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 the 'uri_tab' the result was added to
+ * @return the search result that was set up
  */
-struct SearchTab *
-GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, struct SearchResult **sr,
+struct SearchResult *
+GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, 
                            const struct GNUNET_CONTAINER_MetaData *meta,
                            const struct GNUNET_FS_Uri *uri);
 
@@ -228,4 +270,5 @@
                              const struct GNUNET_FS_ProgressInfo *info);
 
 
+#endif
 /* end of gnunet-fs-gtk-event_handler.h */

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_open-directory.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_open-directory.c    2012-02-04 17:56:27 UTC 
(rev 19681)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_open-directory.c    2012-02-04 19:30:06 UTC 
(rev 19682)
@@ -90,7 +90,7 @@
                                        EXTRACTOR_METAFORMAT_UTF8, "text/plain",
                                        acc->filename,
                                        strlen (acc->filename) + 1);
-    acc->tab = GNUNET_GTK_add_to_uri_tab (&iter, NULL, dmeta, NULL);
+    acc->tab = GNUNET_GTK_add_to_uri_tab (&iter, dmeta, NULL)->tab;
     tp = gtk_tree_model_get_path (GTK_TREE_MODEL (acc->tab->ts), &iter);
     acc->prr = gtk_tree_row_reference_new (GTK_TREE_MODEL (acc->tab->ts), tp);
     gtk_tree_path_free (tp);

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.c  2012-02-04 17:56:27 UTC (rev 
19681)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.c  2012-02-04 19:30:06 UTC (rev 
19682)
@@ -94,12 +94,12 @@
   }
   if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))
   {
-    struct DownloadContext *dc;
+    struct DownloadEntry *de;
 
-    dc = GNUNET_malloc (sizeof (struct DownloadContext));
-    dc->uri = uri;
-    dc->anonymity = anonymity_level;
-    GNUNET_FS_GTK_open_download_as_dialog (dc);
+    de = GNUNET_malloc (sizeof (struct DownloadEntry));
+    de->uri = uri;
+    de->anonymity = anonymity_level;
+    GNUNET_FS_GTK_open_download_as_dialog (de);
     gtk_widget_destroy (dialog);
     g_object_unref (G_OBJECT (builder));  
     return;




reply via email to

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