aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-06-27 16:03:47 +0000
committerChristian Grothoff <christian@grothoff.org>2010-06-27 16:03:47 +0000
commit79e054c0b9016088f436c1faa424465312851998 (patch)
tree02a8c8476b4ac9559db41bc19ba8b9ab8010bb2e
parent0019fe9a8678b44285bd01231b920a63514d18db (diff)
downloadgnunet-gtk-79e054c0b9016088f436c1faa424465312851998.tar.gz
gnunet-gtk-79e054c0b9016088f436c1faa424465312851998.zip
stuff
-rw-r--r--TODO2
-rw-r--r--src/common.c58
-rw-r--r--src/common.h10
-rw-r--r--src/fs_event_handler.c79
-rw-r--r--src/main_window_open_directory.c53
5 files changed, 108 insertions, 94 deletions
diff --git a/TODO b/TODO
index 54e55137..8b137891 100644
--- a/TODO
+++ b/TODO
@@ -1 +1 @@
* How should the user trigger 'download stop' in the new GUI?
diff --git a/src/common.c b/src/common.c
index 99f9704f..2b086d8d 100644
--- a/src/common.c
+++ b/src/common.c
@@ -89,4 +89,62 @@ GNUNET_GTK_get_thumbnail_from_meta_data (const struct GNUNET_CONTAINER_MetaData
89} 89}
90 90
91 91
92/**
93 * mmap the given file and run the GNUNET_FS_directory_list_contents
94 * function on it.
95 */
96void
97GNUNET_GTK_mmap_and_scan (const char *filename,
98 GNUNET_FS_DirectoryEntryProcessor dep,
99 void *dep_cls)
100{
101 struct GNUNET_DISK_FileHandle *fh;
102 struct GNUNET_DISK_MapHandle *mh;
103 uint64_t fsize;
104 void * ddata;
105
106 if (GNUNET_OK !=
107 GNUNET_DISK_file_size (filename,
108 &fsize,
109 GNUNET_YES))
110 {
111 GNUNET_break (0);
112 return;
113 }
114 fh = GNUNET_DISK_file_open (filename,
115 GNUNET_DISK_OPEN_READ,
116 GNUNET_DISK_PERM_NONE);
117 if (fh == NULL)
118 {
119 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
120 return;
121 }
122 ddata = GNUNET_DISK_file_map (fh,
123 &mh,
124 GNUNET_DISK_MAP_TYPE_READ,
125 (size_t) fsize);
126 if (ddata == NULL)
127 {
128 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename);
129 GNUNET_break (GNUNET_OK ==
130 GNUNET_DISK_file_close (fh));
131 return;
132 }
133 if (GNUNET_SYSERR ==
134 GNUNET_FS_directory_list_contents ((size_t) fsize,
135 ddata,
136 0,
137 dep, dep_cls))
138 {
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
140 _("Selected file `%s' is not a GNUnet directory!\n"),
141 filename);
142 }
143 GNUNET_break (GNUNET_OK ==
144 GNUNET_DISK_file_unmap (mh));
145 GNUNET_break (GNUNET_OK ==
146 GNUNET_DISK_file_close (fh));
147}
148
149
92/* end of common.c */ 150/* end of common.c */
diff --git a/src/common.h b/src/common.h
index 51e031f0..069ea115 100644
--- a/src/common.h
+++ b/src/common.h
@@ -53,6 +53,16 @@ GNUNET_GTK_get_thumbnail_from_meta_data (const struct GNUNET_CONTAINER_MetaData
53 53
54 54
55/** 55/**
56 * mmap the given file and run the GNUNET_FS_directory_list_contents
57 * function on it.
58 */
59void
60GNUNET_GTK_mmap_and_scan (const char *filename,
61 GNUNET_FS_DirectoryEntryProcessor dep,
62 void *dep_cls);
63
64
65/**
56 * Create an initialize a new builder based on the 66 * Create an initialize a new builder based on the
57 * GNUnet-GTK glade file. 67 * GNUnet-GTK glade file.
58 * 68 *
diff --git a/src/fs_event_handler.c b/src/fs_event_handler.c
index 1973a774..695f308d 100644
--- a/src/fs_event_handler.c
+++ b/src/fs_event_handler.c
@@ -219,6 +219,11 @@ add_directory_entry (void *cls,
219 /* FIXME: consider merging it in... */ 219 /* FIXME: consider merging it in... */
220 return; 220 return;
221 } 221 }
222 if (ade->check_duplicates == GNUNET_YES)
223 {
224 /* FIXME: check if 'uri' is already in the tab... */
225 GNUNET_break (0);
226 }
222 GNUNET_GTK_add_search_result (ade->de->tab, 227 GNUNET_GTK_add_search_result (ade->de->tab,
223 &iter, 228 &iter,
224 ade->de->sr, 229 ade->de->sr,
@@ -229,42 +234,6 @@ add_directory_entry (void *cls,
229} 234}
230 235
231 236
232
233/**
234 * Add search results from directory to the view
235 *
236 * @param de download entry to process
237 * @param check_duplicates check if enties already exist
238 * @param block_data directory data
239 * @param offset starting offset
240 * @param block_size size of block_data
241 */
242static void
243add_directory_entries (struct DownloadEntry *de,
244 int check_duplicates,
245 const void *block_data,
246 uint64_t offset,
247 uint64_t block_size)
248{
249 struct AddDirectoryEntryContext ade;
250
251 ade.de = de;
252 ade.check_duplicates = check_duplicates;
253 if (GNUNET_SYSERR ==
254 GNUNET_FS_directory_list_contents ((size_t) block_size,
255 block_data,
256 offset,
257 &add_directory_entry,
258 &ade))
259 {
260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
261 _("Metadata wrongly claims that this is a GNUnet directory!\n"));
262 }
263
264}
265
266
267
268static struct DownloadEntry * 237static struct DownloadEntry *
269mark_download_progress (struct DownloadEntry *de, 238mark_download_progress (struct DownloadEntry *de,
270 uint64_t size, 239 uint64_t size,
@@ -274,6 +243,7 @@ mark_download_progress (struct DownloadEntry *de,
274 uint64_t block_size, 243 uint64_t block_size,
275 unsigned int depth) 244 unsigned int depth)
276{ 245{
246 struct AddDirectoryEntryContext ade;
277 GtkTreeIter iter; 247 GtkTreeIter iter;
278 GtkTreePath *path; 248 GtkTreePath *path;
279 249
@@ -290,21 +260,42 @@ mark_download_progress (struct DownloadEntry *de,
290 4, (guint) ((size > 0) ? (100 * completed / size) : 100) /* progress */, 260 4, (guint) ((size > 0) ? (100 * completed / size) : 100) /* progress */,
291 -1); 261 -1);
292 if ( (depth == 0) && 262 if ( (depth == 0) &&
263 (block_size > 0) &&
293 (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) ) 264 (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) )
294 add_directory_entries (de, GNUNET_NO, 265 {
295 block_data, offset, 0); 266 ade.de = de;
267 ade.check_duplicates = GNUNET_NO;
268 if (GNUNET_SYSERR ==
269 GNUNET_FS_directory_list_contents ((size_t) block_size,
270 block_data,
271 offset,
272 &add_directory_entry,
273 &ade))
274 {
275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
276 _("Metadata wrongly claims that this is a GNUnet directory!\n"));
277 }
278 }
296 return de; 279 return de;
297} 280}
298 281
299 282
300static struct DownloadEntry * 283static struct DownloadEntry *
301mark_download_completed (struct DownloadEntry *de, 284mark_download_completed (struct DownloadEntry *de,
302 uint64_t size) 285 uint64_t size,
286 const char *filename)
303{ 287{
288 struct AddDirectoryEntryContext ade;
289
304 (void) mark_download_progress (de, size, size, NULL, 0, 0, 0); 290 (void) mark_download_progress (de, size, size, NULL, 0, 0, 0);
305 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) 291 if ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) &&
292 (filename != NULL) )
306 { 293 {
307 GNUNET_break (0); 294 ade.de = de;
295 ade.check_duplicates = GNUNET_NO;
296 GNUNET_GTK_mmap_and_scan (filename,
297 &add_directory_entry,
298 &ade);
308 } 299 }
309 (void) change_download_colour (de, "green"); 300 (void) change_download_colour (de, "green");
310 return de; 301 return de;
@@ -418,13 +409,14 @@ setup_download (struct DownloadEntry *de,
418 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 409 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
419 if (pde != NULL) 410 if (pde != NULL)
420 { 411 {
421 /* find 'rr' starting at parent */ 412 /* FIXME: find 'rr' starting at parent (!?) */
422 GNUNET_break (0); 413 GNUNET_break (0);
423 } 414 }
424 else if (sr != NULL) 415 else if (sr != NULL)
425 { 416 {
426 de->rr = gtk_tree_row_reference_copy (sr->rr); 417 de->rr = gtk_tree_row_reference_copy (sr->rr);
427 de->ts = sr->tab->ts; 418 de->ts = sr->tab->ts;
419 de->tab = sr->tab;
428 } 420 }
429 else if (de->rr == NULL) 421 else if (de->rr == NULL)
430 { 422 {
@@ -1422,7 +1414,8 @@ GNUNET_GTK_fs_event_handler (void *cls,
1422 "red"); 1414 "red");
1423 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 1415 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
1424 return mark_download_completed (info->value.download.cctx, 1416 return mark_download_completed (info->value.download.cctx,
1425 info->value.download.size); 1417 info->value.download.size,
1418 info->value.download.filename);
1426 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 1419 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
1427 stop_download (info->value.download.cctx, GNUNET_NO); 1420 stop_download (info->value.download.cctx, GNUNET_NO);
1428 return NULL; 1421 return NULL;
diff --git a/src/main_window_open_directory.c b/src/main_window_open_directory.c
index 5c66bb83..698a52b0 100644
--- a/src/main_window_open_directory.c
+++ b/src/main_window_open_directory.c
@@ -105,11 +105,7 @@ GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy,
105 GtkWidget *ad; 105 GtkWidget *ad;
106 GtkBuilder *builder; 106 GtkBuilder *builder;
107 char *filename; 107 char *filename;
108 struct GNUNET_DISK_FileHandle *fh;
109 struct GNUNET_DISK_MapHandle *mh;
110 GtkFileFilter *ff; 108 GtkFileFilter *ff;
111 uint64_t fsize;
112 void * ddata;
113 109
114 builder = GNUNET_GTK_get_new_builder ("open_directory_dialog.glade"); 110 builder = GNUNET_GTK_get_new_builder ("open_directory_dialog.glade");
115 if (builder == NULL) 111 if (builder == NULL)
@@ -132,54 +128,11 @@ GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy,
132 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad)); 128 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad));
133 gtk_widget_destroy (ad); 129 gtk_widget_destroy (ad);
134 g_object_unref (G_OBJECT (builder)); 130 g_object_unref (G_OBJECT (builder));
135
136 if (GNUNET_OK !=
137 GNUNET_DISK_file_size (filename,
138 &fsize,
139 GNUNET_YES))
140 {
141 GNUNET_break (0);
142 g_free (filename);
143 return;
144 }
145 fh = GNUNET_DISK_file_open (filename,
146 GNUNET_DISK_OPEN_READ,
147 GNUNET_DISK_PERM_NONE);
148 if (fh == NULL)
149 {
150 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
151 g_free (filename);
152 return;
153 }
154 ddata = GNUNET_DISK_file_map (fh,
155 &mh,
156 GNUNET_DISK_MAP_TYPE_READ,
157 (size_t) fsize);
158 if (ddata == NULL)
159 {
160 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename);
161 GNUNET_break (GNUNET_OK ==
162 GNUNET_DISK_file_close (fh));
163 g_free (filename);
164 return;
165 }
166 acc.filename = filename; 131 acc.filename = filename;
167 acc.ts = NULL; 132 acc.ts = NULL;
168 if (GNUNET_SYSERR == 133 GNUNET_GTK_mmap_and_scan (filename,
169 GNUNET_FS_directory_list_contents ((size_t) fsize, 134 &add_child,
170 ddata, 135 &acc);
171 0,
172 &add_child,
173 &acc))
174 {
175 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
176 _("Selected file `%s' is not a GNUnet directory!\n"),
177 filename);
178 }
179 GNUNET_break (GNUNET_OK ==
180 GNUNET_DISK_file_unmap (mh));
181 GNUNET_break (GNUNET_OK ==
182 GNUNET_DISK_file_close (fh));
183 g_free (filename); 136 g_free (filename);
184} 137}
185 138