gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19587 - gnunet-gtk/src/fs
Date: Wed, 1 Feb 2012 00:21:22 +0100

Author: grothoff
Date: 2012-02-01 00:21:22 +0100 (Wed, 01 Feb 2012)
New Revision: 19587

Modified:
   gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
Log:
-eliminating ugly SearchDownloadContext and memory leak and possible free of 
pointer on stack

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c     2012-01-31 23:13:03 UTC 
(rev 19586)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c     2012-01-31 23:21:22 UTC 
(rev 19587)
@@ -155,24 +155,6 @@
 
 
 /**
- * Closure for the 'start_download' callback.
- */
-struct StartDownloadContext
-{
-  /**
-   * Search tab to search for the request.
-   */
-  struct SearchTab *tab;
-
-  /**
-   * Was the 'recursive' option requested?
-   */
-  gboolean recursive;
-
-};
-
-
-/**
  * This should get the default download directory (so that GNUnet
  * won't offer the user to download files to the 'bin' subdirectory,
  * or whatever is the cwd).  Returns NULL on failure (such as
@@ -303,15 +285,15 @@
  *
  * @param tree_view tree view with the details
  * @param path path selecting which entry we want to download
- * @param column unused entry specifying which column the mouse was in
- * @param user_data a 'struct StartDownloadContext' with additional details
+ * @param tab the search tab where the user triggered the download request
+ * @param is_recursive was the request for a recursive download?
  */
 static void
-start_download (GtkTreeView * tree_view, GtkTreePath * path,
-                GtkTreeViewColumn * column, gpointer user_data)
+start_download (GtkTreeView * tree_view, 
+               GtkTreePath * path,
+                struct SearchTab *tab,
+               int is_recursive)
 {
-  struct StartDownloadContext *sdc = user_data;
-  struct SearchTab *tab = sdc->tab;
   GtkTreeModel *tm;
   GtkTreeIter iter;
   struct GNUNET_FS_Uri *uri;
@@ -332,15 +314,13 @@
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Starting a %sdownload\n", 
-             sdc->recursive ? "recursive " : "");
+             is_recursive ? "recursive " : "");
 
   GNUNET_assert (tab != NULL);
   tm = gtk_tree_view_get_model (tree_view);
   if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
   {
     GNUNET_break (0);
-    // FIXME: this is bad...
-    GNUNET_free (sdc);
     return;
   }
   gtk_tree_model_get (tm, &iter, 0, &meta, 1, &uri, 9, &sr, 10, &mime, -1);
@@ -348,8 +328,7 @@
   {
     /* user clicked on directory that was opened (not downloaded!), so we
        have no URI and downloading makes no sense. Ignore! */
-    if (NULL != mime)
-      g_free (mime);
+    g_free (mime);
     return;
   }
   if (!(GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)))
@@ -416,7 +395,7 @@
   dc->rr = gtk_tree_row_reference_new (tm, path);
   dc->sr = sr->result;
   dc->anonymity = anonymity;
-  dc->is_recursive = sdc->recursive;
+  dc->is_recursive = is_recursive;
   dc->tab = tab;
   if (local_parents && have_a_suggestion)
     /* Skip the dialog, call directly */
@@ -444,7 +423,28 @@
 }
 
 
+
 /**
+ * This function is called when the user double-clicks on a search
+ * result.  Begins the download, if necessary by opening the "save as"
+ * window.
+ *
+ * @param tree_view tree view with the details
+ * @param path path selecting which entry we want to download
+ * @param column unused entry specifying which column the mouse was in
+ * @param user_data the 'struct SearchTab' that was activated
+ */
+static void
+start_download_row_activated (GtkTreeView * tree_view, GtkTreePath * path,
+                             GtkTreeViewColumn * column, gpointer user_data)
+{
+  struct SearchTab *tab = user_data;
+
+  start_download (tree_view, path, tab, GNUNET_NO);
+}
+
+
+/**
  * "Download" was selected in the current search context menu.
  * 
  * @param item the 'download' menu item
@@ -455,7 +455,6 @@
 {
   GtkTreePath *path;
   GtkTreeView *tv;
-  struct StartDownloadContext sdc;
 
   if (current_context_row_reference == NULL)
   {
@@ -468,9 +467,7 @@
   tv = GTK_TREE_VIEW (gtk_builder_get_object
                       (current_context_search_tab->builder,
                        "_search_result_frame"));
-  sdc.tab = current_context_search_tab;
-  sdc.recursive = FALSE;
-  start_download (tv, path, NULL, &sdc);
+  start_download (tv, path, current_context_search_tab, GNUNET_NO);
   gtk_tree_path_free (path);
   current_context_search_tab = NULL;
 }
@@ -487,7 +484,6 @@
 {
   GtkTreePath *path;
   GtkTreeView *tv;
-  struct StartDownloadContext sdc;
 
   if (current_context_row_reference == NULL)
   {
@@ -500,9 +496,7 @@
   tv = GTK_TREE_VIEW (gtk_builder_get_object
                       (current_context_search_tab->builder,
                        "_search_result_frame"));
-  sdc.tab = current_context_search_tab;
-  sdc.recursive = TRUE;
-  start_download (tv, path, NULL, &sdc);
+  start_download (tv, path, current_context_search_tab, GNUNET_YES);
   gtk_tree_path_free (path);
   current_context_search_tab = NULL;
 }
@@ -1595,7 +1589,6 @@
   GtkNotebook *notebook;
   GtkWindow *sf;
   gint pages;
-  struct StartDownloadContext *sdc;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
       "Setting up a search for %p\n", sc);
@@ -1670,11 +1663,8 @@
   /* add signal handlers */
   tv = GTK_TREE_VIEW (gtk_builder_get_object
                       (tab->builder, "_search_result_frame"));
-  sdc = GNUNET_malloc (sizeof (struct StartDownloadContext));
-  sdc->tab = tab;
-  sdc->recursive = FALSE;
   g_signal_connect_data (G_OBJECT (tv), "row-activated", 
-                        G_CALLBACK (start_download), sdc, 
+                        G_CALLBACK (start_download_row_activated), tab, 
                         &closure_notify_free, 0);
   g_signal_connect (G_OBJECT (tv), "cursor-changed",
                     G_CALLBACK (update_meta_data_views), tab);




reply via email to

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