gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11992 - gnunet-gtk/src


From: gnunet
Subject: [GNUnet-SVN] r11992 - gnunet-gtk/src
Date: Sun, 27 Jun 2010 21:52:54 +0200

Author: grothoff
Date: 2010-06-27 21:52:54 +0200 (Sun, 27 Jun 2010)
New Revision: 11992

Modified:
   gnunet-gtk/src/fs_event_handler.c
   gnunet-gtk/src/fs_event_handler.h
   gnunet-gtk/src/main_window_open_directory.c
Log:
stuff

Modified: gnunet-gtk/src/fs_event_handler.c
===================================================================
--- gnunet-gtk/src/fs_event_handler.c   2010-06-27 17:02:47 UTC (rev 11991)
+++ gnunet-gtk/src/fs_event_handler.c   2010-06-27 19:52:54 UTC (rev 11992)
@@ -97,11 +97,9 @@
   struct GNUNET_FS_SearchResult *result;
 
   /**
-   * Parent for results that are not top-level.
+   * Associated download, or NULL for none.
    */
-  struct SearchResult *parent;
-
-  /* FIXME: keep download status here? */
+  struct DownloadEntry *download;
 };
 
 
@@ -182,6 +180,11 @@
 
   struct DownloadEntry *de;
 
+  /**
+   * Row reference of parent (the directory).
+   */ 
+  GtkTreeRowReference *prr;
+
   int check_duplicates;
 
 };
@@ -226,7 +229,7 @@
     }
   GNUNET_GTK_add_search_result (ade->de->tab,
                                &iter,
-                               ade->de->sr,
+                               ade->prr,
                                uri,
                                meta,
                                NULL,
@@ -264,6 +267,7 @@
        (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) )
     {
       ade.de = de;
+      ade.prr = de->rr;
       ade.check_duplicates = GNUNET_NO;
       if (GNUNET_SYSERR ==
          GNUNET_FS_directory_list_contents ((size_t) block_size,
@@ -292,6 +296,7 @@
        (filename != NULL) )
     {
       ade.de = de;
+      ade.prr = de->rr;
       ade.check_duplicates = GNUNET_NO;      
       GNUNET_GTK_mmap_and_scan (filename,
                                &add_directory_entry,
@@ -399,6 +404,8 @@
   if (de == NULL)
     {
       de = GNUNET_malloc (sizeof (struct DownloadEntry));
+      GNUNET_assert (sr->download == NULL);
+      sr->download = de;
       de->sr = sr;
       de->dc = dc;
       de->uri = GNUNET_FS_uri_dup (uri);
@@ -407,13 +414,8 @@
   if ( (meta != NULL) &&
        (de->meta == NULL) )
     de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
-  if (pde != NULL)
+  if (sr != NULL)
     {
-      /* FIXME: find 'rr' starting at parent (!?) */
-      GNUNET_break (0);
-    }
-  else if (sr != NULL)
-    {
       de->rr = gtk_tree_row_reference_copy (sr->rr);      
       de->ts = sr->tab->ts;
       de->tab = sr->tab;
@@ -545,6 +547,9 @@
   GtkWidget *child;
   GtkTreePath *path;
   GtkTreeModel *tm;
+  GtkTreeIter iter;
+  struct SearchResult *sr;
+  int have_entries;
  
   tv = GTK_TREE_VIEW (widget);
   if (event->type == GDK_BUTTON_PRESS)
@@ -569,6 +574,10 @@
              return FALSE;
            }
          tm = gtk_tree_view_get_model (tv);
+         gtk_tree_model_get_iter (tm, &iter, path);
+         gtk_tree_model_get (tm, &iter,
+                             9, &sr,
+                             -1);        
          current_context_row_reference = gtk_tree_row_reference_new (tm,
                                                                      path);
          gtk_tree_path_free (path);
@@ -581,21 +590,32 @@
             - abort active download (!) 
             => need to know download status before creating menu! 
          */
+         have_entries = GNUNET_NO;
          menu = GTK_MENU (gtk_menu_new ());
-         child = gtk_menu_item_new_with_label (_("_Download"));
-         g_signal_connect (child,
-                            "activate",
-                            G_CALLBACK (start_download_ctx_menu),
-                            NULL /*FIXME */);
-         gtk_label_set_use_underline (GTK_LABEL
-                                      (gtk_bin_get_child (GTK_BIN (child))), 
-                                      TRUE);
-         gtk_widget_show (child);
-         gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
-         gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
-                         event_button->button,
-                         event_button->time);
-
+         if (sr->download == NULL)
+           {
+             child = gtk_menu_item_new_with_label (_("_Download"));
+             g_signal_connect (child,
+                               "activate",
+                               G_CALLBACK (start_download_ctx_menu),
+                               NULL /*FIXME */);
+             gtk_label_set_use_underline (GTK_LABEL
+                                          (gtk_bin_get_child (GTK_BIN 
(child))), 
+                                          TRUE);
+             gtk_widget_show (child);
+             have_entries = GNUNET_YES;
+           }
+         if (have_entries != GNUNET_NO)
+           {
+             gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+             gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
+                             event_button->button,
+                             event_button->time);          
+           }
+         else
+           {
+             g_object_unref (G_OBJECT(menu));
+           }
        }
     }
   return FALSE;
@@ -921,7 +941,7 @@
  *
  * @param tab search tab to extend
  * @param iter set to position where search result is added
- * @param parent parent entry in search tab
+ * @param parent_rr reference to parent entry in search tab
  * @param uri uri to add
  * @param meta metadata of the entry
  * @param result associated FS search result (can be NULL)
@@ -931,7 +951,7 @@
 struct SearchResult *
 GNUNET_GTK_add_search_result (struct SearchTab *tab,
                              GtkTreeIter *iter,
-                             struct SearchResult *parent,
+                             GtkTreeRowReference *parent_rr,
                              const struct GNUNET_FS_Uri *uri,
                              const struct GNUNET_CONTAINER_MetaData *meta,
                              struct GNUNET_FS_SearchResult *result,
@@ -947,6 +967,7 @@
   GtkTreeIter pmem;
   GtkTreePath *path;
   GtkTreeModel *tm;  
+  GtkTreeStore *ts;
 
   if ( (uri != NULL) &&
        (!GNUNET_FS_uri_test_loc (uri)) &&
@@ -980,14 +1001,13 @@
                                                        -1);
   pixbuf = GNUNET_GTK_get_thumbnail_from_meta_data (meta);
   sr = GNUNET_malloc (sizeof (struct SearchResult));
-  sr->parent = parent;
   sr->result = result;
   sr->tab = tab;
-  if (parent != NULL)
+  if (parent_rr != NULL)
     {
       /* get piter from parent */
-      path = gtk_tree_row_reference_get_path (parent->rr);
-      tm = gtk_tree_row_reference_get_model (parent->rr);
+      path = gtk_tree_row_reference_get_path (parent_rr);
+      tm = gtk_tree_row_reference_get_model (parent_rr);
       if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (tm), 
                                           &pmem, path))
        {
@@ -1000,13 +1020,15 @@
        {
          pitr = &pmem;
        }
+      ts = GTK_TREE_STORE (tm);
     }
   else
     {
       /* top-level result */
       pitr = NULL;
+      ts = tab->ts;
     }
-  gtk_tree_store_insert_with_values (tab->ts,
+  gtk_tree_store_insert_with_values (ts,
                                     iter,
                                     pitr,
                                     G_MAXINT,
@@ -1025,15 +1047,16 @@
                                     12, 0 /* avail-cert */,
                                     13, 0 /* avail-rank */,
                                     -1);
-  tab->num_results++;
+  if (tab != NULL)
+    tab->num_results++;
   if (pixbuf != NULL)
     g_object_unref (pixbuf);
   GNUNET_free (uris);
   GNUNET_free (desc);
   GNUNET_free_non_null (mime);
-  tp = gtk_tree_model_get_path (GTK_TREE_MODEL (tab->ts),
+  tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts),
                                iter);
-  sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (tab->ts),
+  sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts),
                                       tp);
   gtk_tree_path_free (tp);
   return sr;
@@ -1042,7 +1065,7 @@
 
 static struct SearchResult *
 process_search_result (void *cls,
-                      void *parent,
+                      struct SearchResult *parent,
                       const struct GNUNET_FS_Uri *uri,
                       const struct GNUNET_CONTAINER_MetaData *meta,
                       struct GNUNET_FS_SearchResult *result,
@@ -1052,7 +1075,9 @@
   struct SearchResult *sr;
   GtkTreeIter iter;
 
-  sr = GNUNET_GTK_add_search_result (tab, &iter, parent, uri,
+  sr = GNUNET_GTK_add_search_result (tab, &iter, 
+                                    (parent != NULL) ? parent->rr : NULL, 
+                                    uri,
                                     meta, result, applicability_rank);
   update_search_label (tab);
   return sr;

Modified: gnunet-gtk/src/fs_event_handler.h
===================================================================
--- gnunet-gtk/src/fs_event_handler.h   2010-06-27 17:02:47 UTC (rev 11991)
+++ gnunet-gtk/src/fs_event_handler.h   2010-06-27 19:52:54 UTC (rev 11992)
@@ -73,20 +73,49 @@
 
 struct DownloadEntry
 {
+
+  /**
+   * Download entry of the parent (for recursive downloads),
+   * NULL if we are either a top-level download (from URI,
+   * from opened directory, orphaned from search or direct
+   * search result).
+   */
   struct DownloadEntry *pde;
 
+  /**
+   * Associated search result, or NULL if we don't belong
+   * to a search directly (download entry).
+   */
   struct SearchResult *sr;
 
+  /**
+   * FS handle to control the download.
+   */
   struct GNUNET_FS_DownloadContext *dc;
 
+  /**
+   * URI for the download.
+   */
   struct GNUNET_FS_Uri *uri;
 
+  /**
+   * Meta data for the download.
+   */
   struct GNUNET_CONTAINER_MetaData *meta;
 
+  /**
+   * Where in the tree view is this download being displayed.
+   */
   GtkTreeRowReference *rr;
 
+  /**
+   * Tree store where we are stored.
+   */
   GtkTreeStore *ts;
-
+  
+  /**
+   * Tab where this download is currently on display.
+   */
   struct SearchTab *tab;
 };
 
@@ -116,7 +145,7 @@
  *
  * @param tab search tab to extend
  * @param iter set to position where search result is added
- * @param parent parent entry in search tab
+ * @param parent_rr reference to parent entry in search tab
  * @param uri uri to add
  * @param meta metadata of the entry
  * @param result associated FS search result (can be NULL)
@@ -126,7 +155,7 @@
 struct SearchResult *
 GNUNET_GTK_add_search_result (struct SearchTab *tab,
                              GtkTreeIter *iter,
-                             struct SearchResult *parent,
+                             GtkTreeRowReference *parent_rr,
                              const struct GNUNET_FS_Uri *uri,
                              const struct GNUNET_CONTAINER_MetaData *meta,
                              struct GNUNET_FS_SearchResult *result,

Modified: gnunet-gtk/src/main_window_open_directory.c
===================================================================
--- gnunet-gtk/src/main_window_open_directory.c 2010-06-27 17:02:47 UTC (rev 
11991)
+++ gnunet-gtk/src/main_window_open_directory.c 2010-06-27 19:52:54 UTC (rev 
11992)
@@ -31,6 +31,7 @@
   GtkTreeStore *ts;
   struct SearchTab *tab;
   struct SearchResult *par;
+  GtkTreeRowReference *prr;
   GtkTreeIter iter; 
 };
 
@@ -60,6 +61,7 @@
 {
   struct AddChildContext *acc = cls;
   struct GNUNET_CONTAINER_MetaData *dmeta;
+  GtkTreePath *tp;
   GtkTreeIter iter;
 
   if (uri == NULL)
@@ -77,19 +79,25 @@
                                            &acc->par,
                                            dmeta,
                                            NULL); 
+      tp = gtk_tree_model_get_path (GTK_TREE_MODEL (acc->tab->ts),
+                                   &acc->iter);
+      acc->prr = gtk_tree_row_reference_new (GTK_TREE_MODEL (acc->tab->ts),
+                                            tp);
+      gtk_tree_path_free (tp);
       acc->ts = acc->tab->ts;
       GNUNET_CONTAINER_meta_data_destroy (dmeta);
       return;
     }
   if (acc->ts == NULL)
     return;
-  GNUNET_GTK_add_search_result (acc->tab,
-                               &iter,
-                               acc->par,
-                               uri,
-                               meta,
-                               NULL,
-                               0);
+  GNUNET_assert (NULL !=
+                GNUNET_GTK_add_search_result (acc->tab,
+                                              &iter,
+                                              acc->prr,
+                                              uri,
+                                              meta,
+                                              NULL,
+                                              0));
 }
 
 




reply via email to

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