aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fs_event_handler.c12
-rw-r--r--src/main_window_open_directory.c124
2 files changed, 120 insertions, 16 deletions
diff --git a/src/fs_event_handler.c b/src/fs_event_handler.c
index f37d575e..d1c88d6b 100644
--- a/src/fs_event_handler.c
+++ b/src/fs_event_handler.c
@@ -770,7 +770,8 @@ add_search_result (struct SearchTab *tab,
770 char *uris; 770 char *uris;
771 GdkPixbuf *pixbuf; 771 GdkPixbuf *pixbuf;
772 772
773 if ( (!GNUNET_FS_uri_test_loc (uri)) && 773 if ( (uri != NULL) &&
774 (!GNUNET_FS_uri_test_loc (uri)) &&
774 (!GNUNET_FS_uri_test_chk (uri)) ) 775 (!GNUNET_FS_uri_test_chk (uri)) )
775 { 776 {
776 /* SKS support not implemented yet */ 777 /* SKS support not implemented yet */
@@ -791,7 +792,10 @@ add_search_result (struct SearchTab *tab,
791 -1); 792 -1);
792 if (desc == NULL) 793 if (desc == NULL)
793 desc = GNUNET_strdup (_("no description supplied")); 794 desc = GNUNET_strdup (_("no description supplied"));
794 uris = GNUNET_FS_uri_to_string (uri); 795 if (uri == NULL)
796 uris = GNUNET_strdup (_("no URI"));
797 else
798 uris = GNUNET_FS_uri_to_string (uri);
795 mime = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 799 mime = GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
796 EXTRACTOR_METATYPE_MIMETYPE, 800 EXTRACTOR_METATYPE_MIMETYPE,
797 EXTRACTOR_METATYPE_FORMAT, 801 EXTRACTOR_METATYPE_FORMAT,
@@ -807,8 +811,8 @@ add_search_result (struct SearchTab *tab,
807 NULL, 811 NULL,
808 G_MAXINT, 812 G_MAXINT,
809 0, GNUNET_CONTAINER_meta_data_duplicate (meta), 813 0, GNUNET_CONTAINER_meta_data_duplicate (meta),
810 1, GNUNET_FS_uri_dup (uri), 814 1, (uri == NULL) ? NULL : GNUNET_FS_uri_dup (uri),
811 2, GNUNET_FS_uri_chk_get_file_size (uri), 815 2, (uri == NULL) ? 0 : GNUNET_FS_uri_chk_get_file_size (uri),
812 3, pixbuf /* preview */, 816 3, pixbuf /* preview */,
813 4, 0 /* percent progress */, 817 4, 0 /* percent progress */,
814 5, 0 /* percent availability */, 818 5, 0 /* percent availability */,
diff --git a/src/main_window_open_directory.c b/src/main_window_open_directory.c
index 5384222d..75871c50 100644
--- a/src/main_window_open_directory.c
+++ b/src/main_window_open_directory.c
@@ -23,6 +23,66 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25#include "common.h" 25#include "common.h"
26#include "fs_event_handler.h"
27
28struct AddChildContext
29{
30 const char *filename;
31 GtkTreeStore *ts;
32 GtkTreeIter iter;
33};
34
35
36/**
37 * Function used to process entries in a directory.
38 *
39 * @param cls closure, our 'struct AddChildContext*'
40 * @param filename name of the file in the directory
41 * @param uri URI of the file
42 * @param metadata metadata for the file; metadata for
43 * the directory if everything else is NULL/zero
44 * @param length length of the available data for the file
45 * (of type size_t since data must certainly fit
46 * into memory; if files are larger than size_t
47 * permits, then they will certainly not be
48 * embedded with the directory itself).
49 * @param data data available for the file (length bytes)
50 */
51static void
52add_child (void *cls,
53 const char *filename,
54 const struct GNUNET_FS_Uri *uri,
55 const struct GNUNET_CONTAINER_MetaData *meta,
56 size_t length,
57 const void *data)
58{
59 struct AddChildContext *acc = cls;
60 struct GNUNET_CONTAINER_MetaData *dmeta;
61
62 if (uri == NULL)
63 {
64 /* directory meta data itself */
65 dmeta = GNUNET_CONTAINER_meta_data_duplicate (meta);
66 GNUNET_CONTAINER_meta_data_insert (dmeta,
67 "<user>",
68 EXTRACTOR_METATYPE_FILENAME,
69 EXTRACTOR_METAFORMAT_C_STRING,
70 "text/plain",
71 acc->filename,
72 strlen (acc->filename) + 1);
73 acc->ts = GNUNET_GTK_add_to_uri_tab (&acc->iter,
74 dmeta,
75 NULL);
76 GNUNET_CONTAINER_meta_data_destroy (dmeta);
77 return;
78 }
79 if (acc->ts == NULL)
80 return;
81 /* FIXME */
82 GNUNET_break (0);
83 acc = NULL;
84}
85
26 86
27/** 87/**
28 * User selected "Open directory" in menu. Display dialog, open 88 * User selected "Open directory" in menu. Display dialog, open
@@ -32,9 +92,14 @@ void
32GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy, 92GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy,
33 gpointer data) 93 gpointer data)
34{ 94{
95 struct AddChildContext acc;
35 GtkWidget *ad; 96 GtkWidget *ad;
36 GtkBuilder *builder; 97 GtkBuilder *builder;
37 char *filename; 98 char *filename;
99 struct GNUNET_DISK_FileHandle *fh;
100 struct GNUNET_DISK_MapHandle *mh;
101 uint64_t fsize;
102 void * ddata;
38 103
39 builder = GNUNET_GTK_get_new_builder ("open_directory_dialog.glade"); 104 builder = GNUNET_GTK_get_new_builder ("open_directory_dialog.glade");
40 if (builder == NULL) 105 if (builder == NULL)
@@ -53,19 +118,54 @@ GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy,
53 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad)); 118 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad));
54 gtk_widget_destroy (ad); 119 gtk_widget_destroy (ad);
55 g_object_unref (G_OBJECT (builder)); 120 g_object_unref (G_OBJECT (builder));
56#if 0
57 open_directory;
58 uri = compute_uri_from_file (filename);
59 meta = new;
60 meta_make_directory ();
61 meta_add (filename);
62 ts = setup_entry_in_uri_tab (&iter,
63 meta,
64 uri);
65 directory_iterate (add_child, ts, &iter);
66 121
67 GNUNET_break (0); 122 if (GNUNET_OK !=
68#endif 123 GNUNET_DISK_file_size (filename,
124 &fsize,
125 GNUNET_YES))
126 {
127 GNUNET_break (0);
128 g_free (filename);
129 return;
130 }
131 fh = GNUNET_DISK_file_open (filename,
132 GNUNET_DISK_OPEN_READ,
133 GNUNET_DISK_PERM_NONE);
134 if (fh == NULL)
135 {
136 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
137 g_free (filename);
138 return;
139 }
140 ddata = GNUNET_DISK_file_map (fh,
141 &mh,
142 GNUNET_DISK_MAP_TYPE_READ,
143 (size_t) fsize);
144 if (ddata == NULL)
145 {
146 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename);
147 GNUNET_break (GNUNET_OK ==
148 GNUNET_DISK_file_close (fh));
149 g_free (filename);
150 return;
151 }
152 acc.filename = filename;
153 acc.ts = NULL;
154 if (GNUNET_SYSERR ==
155 GNUNET_FS_directory_list_contents ((size_t) fsize,
156 ddata,
157 0,
158 &add_child,
159 &acc))
160 {
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
162 _("Selected file `%s' is not a GNUnet directory!\n"),
163 filename);
164 }
165 GNUNET_break (GNUNET_OK ==
166 GNUNET_DISK_file_unmap (mh));
167 GNUNET_break (GNUNET_OK ==
168 GNUNET_DISK_file_close (fh));
69 g_free (filename); 169 g_free (filename);
70} 170}
71 171