gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11989 - in gnunet-gtk: . src


From: gnunet
Subject: [GNUnet-SVN] r11989 - in gnunet-gtk: . src
Date: Sun, 27 Jun 2010 18:03:47 +0200

Author: grothoff
Date: 2010-06-27 18:03:47 +0200 (Sun, 27 Jun 2010)
New Revision: 11989

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

Modified: gnunet-gtk/TODO
===================================================================
--- gnunet-gtk/TODO     2010-06-27 15:43:05 UTC (rev 11988)
+++ gnunet-gtk/TODO     2010-06-27 16:03:47 UTC (rev 11989)
@@ -1 +1 @@
-* How should the user trigger 'download stop' in the new GUI?
+

Modified: gnunet-gtk/src/common.c
===================================================================
--- gnunet-gtk/src/common.c     2010-06-27 15:43:05 UTC (rev 11988)
+++ gnunet-gtk/src/common.c     2010-06-27 16:03:47 UTC (rev 11989)
@@ -89,4 +89,62 @@
 }
 
 
+/**
+ * mmap the given file and run the GNUNET_FS_directory_list_contents
+ * function on it.
+ */
+void
+GNUNET_GTK_mmap_and_scan (const char *filename,
+                         GNUNET_FS_DirectoryEntryProcessor dep,
+                         void *dep_cls)
+{
+  struct GNUNET_DISK_FileHandle *fh;
+  struct GNUNET_DISK_MapHandle *mh;
+  uint64_t fsize;
+  void * ddata;
+
+  if (GNUNET_OK !=
+      GNUNET_DISK_file_size (filename,
+                            &fsize,
+                            GNUNET_YES))
+    {
+      GNUNET_break (0);
+      return;
+    }
+  fh = GNUNET_DISK_file_open (filename,
+                             GNUNET_DISK_OPEN_READ,
+                             GNUNET_DISK_PERM_NONE);
+  if (fh == NULL)
+    {
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
+      return;
+    }
+  ddata = GNUNET_DISK_file_map (fh,
+                               &mh,
+                               GNUNET_DISK_MAP_TYPE_READ,
+                               (size_t) fsize);
+  if (ddata == NULL)
+    {
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename);
+      GNUNET_break (GNUNET_OK ==
+                   GNUNET_DISK_file_close (fh));
+      return;
+    }
+  if (GNUNET_SYSERR ==
+      GNUNET_FS_directory_list_contents ((size_t) fsize,
+                                        ddata,
+                                        0,
+                                        dep, dep_cls))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Selected file `%s' is not a GNUnet directory!\n"),
+                 filename);
+    }
+  GNUNET_break (GNUNET_OK ==
+               GNUNET_DISK_file_unmap (mh));
+  GNUNET_break (GNUNET_OK ==
+               GNUNET_DISK_file_close (fh));
+}
+
+
 /* end of common.c */

Modified: gnunet-gtk/src/common.h
===================================================================
--- gnunet-gtk/src/common.h     2010-06-27 15:43:05 UTC (rev 11988)
+++ gnunet-gtk/src/common.h     2010-06-27 16:03:47 UTC (rev 11989)
@@ -53,6 +53,16 @@
 
 
 /**
+ * mmap the given file and run the GNUNET_FS_directory_list_contents
+ * function on it.
+ */
+void
+GNUNET_GTK_mmap_and_scan (const char *filename,
+                         GNUNET_FS_DirectoryEntryProcessor dep,
+                         void *dep_cls);
+
+
+/**
  * Create an initialize a new builder based on the
  * GNUnet-GTK glade file.
  *

Modified: gnunet-gtk/src/fs_event_handler.c
===================================================================
--- gnunet-gtk/src/fs_event_handler.c   2010-06-27 15:43:05 UTC (rev 11988)
+++ gnunet-gtk/src/fs_event_handler.c   2010-06-27 16:03:47 UTC (rev 11989)
@@ -219,6 +219,11 @@
       /* FIXME: consider merging it in... */
       return;
     }
+  if (ade->check_duplicates == GNUNET_YES)
+    {
+      /* FIXME: check if 'uri' is already in the tab... */
+      GNUNET_break (0);
+    }
   GNUNET_GTK_add_search_result (ade->de->tab,
                                &iter,
                                ade->de->sr,
@@ -229,42 +234,6 @@
 }
 
 
-
-/**
- * Add search results from directory to the view
- *
- * @param de download entry to process
- * @param check_duplicates check if enties already exist
- * @param block_data directory data
- * @param offset starting offset
- * @param block_size size of block_data
- */
-static void
-add_directory_entries (struct DownloadEntry *de,
-                      int check_duplicates,
-                      const void *block_data,
-                      uint64_t offset,
-                      uint64_t block_size)
-{
-  struct AddDirectoryEntryContext ade;
-
-  ade.de = de;
-  ade.check_duplicates = check_duplicates;
-  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"));
-    }
-
-}
-                      
-
-
 static struct DownloadEntry *
 mark_download_progress (struct DownloadEntry *de,
                        uint64_t size,
@@ -274,6 +243,7 @@
                        uint64_t block_size,
                        unsigned int depth)
 {
+  struct AddDirectoryEntryContext ade;
   GtkTreeIter iter;
   GtkTreePath *path;
   
@@ -290,21 +260,42 @@
                      4, (guint) ((size > 0) ? (100 * completed / size) : 100) 
/* progress */,
                      -1);
   if ( (depth == 0) &&
+       (block_size > 0) &&
        (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) )
-    add_directory_entries (de, GNUNET_NO,
-                          block_data, offset, 0);
+    {
+      ade.de = de;
+      ade.check_duplicates = GNUNET_NO;
+      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"));
+       }
+    }
   return de;
 }
 
 
 static struct DownloadEntry *
 mark_download_completed (struct DownloadEntry *de,
-                        uint64_t size)
+                        uint64_t size,
+                        const char *filename)
 {
+  struct AddDirectoryEntryContext ade;
+
   (void) mark_download_progress (de, size, size, NULL, 0, 0, 0);
-  if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta))
+  if ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) &&
+       (filename != NULL) )
     {
-      GNUNET_break (0);
+      ade.de = de;
+      ade.check_duplicates = GNUNET_NO;      
+      GNUNET_GTK_mmap_and_scan (filename,
+                               &add_directory_entry,
+                               &ade);
     }
   (void) change_download_colour (de, "green");
   return de;
@@ -418,13 +409,14 @@
     de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
   if (pde != NULL)
     {
-      /* find 'rr' starting at parent */
+      /* 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;
     }
   else if (de->rr == NULL)
     {
@@ -1422,7 +1414,8 @@
                                     "red");
     case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 
       return mark_download_completed (info->value.download.cctx,
-                                     info->value.download.size);
+                                     info->value.download.size,
+                                     info->value.download.filename);
     case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
       stop_download (info->value.download.cctx, GNUNET_NO);
       return NULL;

Modified: gnunet-gtk/src/main_window_open_directory.c
===================================================================
--- gnunet-gtk/src/main_window_open_directory.c 2010-06-27 15:43:05 UTC (rev 
11988)
+++ gnunet-gtk/src/main_window_open_directory.c 2010-06-27 16:03:47 UTC (rev 
11989)
@@ -105,11 +105,7 @@
   GtkWidget *ad;
   GtkBuilder *builder;
   char *filename;
-  struct GNUNET_DISK_FileHandle *fh;
-  struct GNUNET_DISK_MapHandle *mh;
   GtkFileFilter *ff;
-  uint64_t fsize;
-  void * ddata;
 
   builder = GNUNET_GTK_get_new_builder ("open_directory_dialog.glade");
   if (builder == NULL)
@@ -132,54 +128,11 @@
   filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad));
   gtk_widget_destroy (ad);
   g_object_unref (G_OBJECT (builder));
-
-  if (GNUNET_OK !=
-      GNUNET_DISK_file_size (filename,
-                            &fsize,
-                            GNUNET_YES))
-    {
-      GNUNET_break (0);
-      g_free (filename);
-      return;
-    }
-  fh = GNUNET_DISK_file_open (filename,
-                             GNUNET_DISK_OPEN_READ,
-                             GNUNET_DISK_PERM_NONE);
-  if (fh == NULL)
-    {
-      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
-      g_free (filename);
-      return;
-    }
-  ddata = GNUNET_DISK_file_map (fh,
-                               &mh,
-                               GNUNET_DISK_MAP_TYPE_READ,
-                               (size_t) fsize);
-  if (ddata == NULL)
-    {
-      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename);
-      GNUNET_break (GNUNET_OK ==
-                   GNUNET_DISK_file_close (fh));
-      g_free (filename);
-      return;
-    }
   acc.filename = filename;
   acc.ts = NULL;
-  if (GNUNET_SYSERR ==
-      GNUNET_FS_directory_list_contents ((size_t) fsize,
-                                        ddata,
-                                        0,
-                                        &add_child,
-                                        &acc))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                 _("Selected file `%s' is not a GNUnet directory!\n"),
-                 filename);
-    }
-  GNUNET_break (GNUNET_OK ==
-               GNUNET_DISK_file_unmap (mh));
-  GNUNET_break (GNUNET_OK ==
-               GNUNET_DISK_file_close (fh));
+  GNUNET_GTK_mmap_and_scan (filename,
+                           &add_child,
+                           &acc);
   g_free (filename);
 }
 




reply via email to

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