aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/download.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2007-07-10 09:01:06 +0000
committerChristian Grothoff <christian@grothoff.org>2007-07-10 09:01:06 +0000
commitce124c66c8aff19abaa695a16127a742050d01b4 (patch)
treeec813c1b394f5566655fa6ff52cfba45a14847d7 /src/plugins/fs/download.c
parentb2f6fe964b05c6995bcb50ebe29cf25f1c185f84 (diff)
downloadgnunet-gtk-ce124c66c8aff19abaa695a16127a742050d01b4.tar.gz
gnunet-gtk-ce124c66c8aff19abaa695a16127a742050d01b4.zip
indent
Diffstat (limited to 'src/plugins/fs/download.c')
-rw-r--r--src/plugins/fs/download.c1344
1 files changed, 660 insertions, 684 deletions
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c
index 2d825f71..c58a18e4 100644
--- a/src/plugins/fs/download.c
+++ b/src/plugins/fs/download.c
@@ -39,136 +39,113 @@
39 * by the download list. 39 * by the download list.
40 */ 40 */
41static int 41static int
42addFilesToDirectory(const ECRS_FileInfo * fi, 42addFilesToDirectory (const ECRS_FileInfo * fi,
43 const HashCode512 * key, 43 const HashCode512 * key, int isRoot, void *closure)
44 int isRoot, 44{
45 void * closure) { 45 DownloadList *list = closure;
46 DownloadList * list = closure;
47 GtkTreeIter iter; 46 GtkTreeIter iter;
48 GtkTreeIter child; 47 GtkTreeIter child;
49 int i; 48 int i;
50 GtkTreePath * path; 49 GtkTreePath *path;
51 GtkTreeModel * model; 50 GtkTreeModel *model;
52 51
53 if (isRoot == YES) 52 if (isRoot == YES)
54 return OK; 53 return OK;
55 if (! gtk_tree_row_reference_valid(list->searchViewRowReference)) 54 if (!gtk_tree_row_reference_valid (list->searchViewRowReference))
56 return SYSERR; 55 return SYSERR;
57 model = GTK_TREE_MODEL(list->searchList->tree); 56 model = GTK_TREE_MODEL (list->searchList->tree);
58 path = gtk_tree_row_reference_get_path(list->searchViewRowReference); 57 path = gtk_tree_row_reference_get_path (list->searchViewRowReference);
59 if (path == NULL) { 58 if (path == NULL)
60 GE_BREAK(ectx, 0); 59 {
61 return SYSERR; 60 GE_BREAK (ectx, 0);
62 } 61 return SYSERR;
63 gtk_tree_model_get_iter(model, 62 }
64 &iter, 63 gtk_tree_model_get_iter (model, &iter, path);
65 path); 64 gtk_tree_path_free (path);
66 gtk_tree_path_free(path);
67 /* check for existing entry -- this function maybe called multiple 65 /* check for existing entry -- this function maybe called multiple
68 times for the same directory entry */ 66 times for the same directory entry */
69 for (i=gtk_tree_model_iter_n_children(model, 67 for (i = gtk_tree_model_iter_n_children (model, &iter) - 1; i >= 0; i--)
70 &iter)-1;i>=0;i--) { 68 {
71 if (TRUE == gtk_tree_model_iter_nth_child(model, 69 if (TRUE == gtk_tree_model_iter_nth_child (model, &child, &iter, i))
72 &child, 70 {
73 &iter, 71 struct ECRS_URI *uri;
74 i)) { 72 uri = NULL;
75 struct ECRS_URI * uri; 73 gtk_tree_model_get (model, &child, SEARCH_URI, &uri, -1);
76 uri = NULL; 74 if ((uri != NULL) && (ECRS_equalsUri (uri, fi->uri)))
77 gtk_tree_model_get(model, 75 return OK;
78 &child, 76 }
79 SEARCH_URI, &uri, 77 }
80 -1); 78 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
81 if ( (uri != NULL) && 79 addEntryToSearchTree (list->searchList, list, fi, &child);
82 (ECRS_equalsUri(uri,
83 fi->uri)) )
84 return OK;
85 }
86 }
87 gtk_tree_store_append(GTK_TREE_STORE(model),
88 &child,
89 &iter);
90 addEntryToSearchTree(list->searchList,
91 list,
92 fi,
93 &child);
94 return OK; 80 return OK;
95} 81}
96 82
97static void 83static void
98refreshDirectoryViewFromDisk(DownloadList * list) { 84refreshDirectoryViewFromDisk (DownloadList * list)
85{
99 unsigned long long size; 86 unsigned long long size;
100 char * data; 87 char *data;
101 int fd; 88 int fd;
102 char * fn; 89 char *fn;
103 struct ECRS_MetaData * meta; 90 struct ECRS_MetaData *meta;
104 struct stat buf; 91 struct stat buf;
105 const char * f; 92 const char *f;
106 93
107 if ( (list->is_directory != YES) || 94 if ((list->is_directory != YES) ||
108 (list->searchList == NULL) || 95 (list->searchList == NULL) ||
109 (list->searchViewRowReference == NULL) || 96 (list->searchViewRowReference == NULL) ||
110 (! gtk_tree_row_reference_valid(list->searchViewRowReference)) ) 97 (!gtk_tree_row_reference_valid (list->searchViewRowReference)))
111 return; 98 return;
112 99
113 if (0 != stat(list->filename, 100 if (0 != stat (list->filename, &buf))
114 &buf))
115 return; 101 return;
116 if (S_ISDIR(buf.st_mode)) { 102 if (S_ISDIR (buf.st_mode))
117 fn = MALLOC(strlen(list->filename) + strlen(GNUNET_DIRECTORY_EXT) + 1); 103 {
118 strcpy(fn, list->filename); 104 fn =
119 if (fn[strlen(fn)-1] == '/') 105 MALLOC (strlen (list->filename) + strlen (GNUNET_DIRECTORY_EXT) + 1);
120 fn[strlen(fn)-1] = '\0'; 106 strcpy (fn, list->filename);
121 strcat(fn, GNUNET_DIRECTORY_EXT); 107 if (fn[strlen (fn) - 1] == '/')
122 if (0 != stat(list->filename, 108 fn[strlen (fn) - 1] = '\0';
123 &buf)) { 109 strcat (fn, GNUNET_DIRECTORY_EXT);
124 FREE(fn); 110 if (0 != stat (list->filename, &buf))
125 return; 111 {
112 FREE (fn);
113 return;
114 }
115 f = fn;
116 }
117 else
118 {
119 fn = NULL;
120 f = list->filename;
126 } 121 }
127 f = fn;
128 } else {
129 fn = NULL;
130 f = list->filename;
131 }
132 size = buf.st_size; 122 size = buf.st_size;
133 if (size == 0) { 123 if (size == 0)
134 FREENONNULL(fn); 124 {
135 return; 125 FREENONNULL (fn);
136 } 126 return;
137 fd = disk_file_open(ectx, 127 }
138 list->filename, 128 fd = disk_file_open (ectx, list->filename, O_RDONLY);
139 O_RDONLY); 129 if (fd == -1)
140 if (fd == -1) { 130 {
141 FREENONNULL(fn); 131 FREENONNULL (fn);
142 return; 132 return;
143 } 133 }
144 data = MMAP(NULL, 134 data = MMAP (NULL, size, PROT_READ, MAP_SHARED, fd, 0);
145 size, 135 if ((data == MAP_FAILED) || (data == NULL))
146 PROT_READ, 136 {
147 MAP_SHARED, 137 GE_LOG_STRERROR_FILE (ectx, GE_ERROR | GE_ADMIN | GE_BULK, "mmap", f);
148 fd, 138 CLOSE (fd);
149 0); 139 FREENONNULL (fn);
150 if ( (data == MAP_FAILED) || 140 return;
151 (data == NULL) ) { 141 }
152 GE_LOG_STRERROR_FILE(ectx, 142 FREENONNULL (fn);
153 GE_ERROR | GE_ADMIN | GE_BULK,
154 "mmap",
155 f);
156 CLOSE(fd);
157 FREENONNULL(fn);
158 return;
159 }
160 FREENONNULL(fn);
161 meta = NULL; 143 meta = NULL;
162 ECRS_listDirectory(ectx, 144 ECRS_listDirectory (ectx, data, size, &meta, &addFilesToDirectory, list);
163 data, 145 MUNMAP (data, size);
164 size, 146 CLOSE (fd);
165 &meta,
166 &addFilesToDirectory,
167 list);
168 MUNMAP(data, size);
169 CLOSE(fd);
170 if (meta != NULL) 147 if (meta != NULL)
171 ECRS_freeMetaData(meta); 148 ECRS_freeMetaData (meta);
172} 149}
173 150
174/** 151/**
@@ -177,162 +154,158 @@ refreshDirectoryViewFromDisk(DownloadList * list) {
177 * the download summary. 154 * the download summary.
178 */ 155 */
179DownloadList * 156DownloadList *
180fs_download_started(struct FSUI_DownloadList * fsui_dl, 157fs_download_started (struct FSUI_DownloadList *fsui_dl,
181 DownloadList * dl_parent, 158 DownloadList * dl_parent,
182 SearchList * sl_parent, 159 SearchList * sl_parent,
183 unsigned long long total, 160 unsigned long long total,
184 unsigned int anonymityLevel, 161 unsigned int anonymityLevel,
185 const ECRS_FileInfo * fi, 162 const ECRS_FileInfo * fi,
186 const char * filename, 163 const char *filename,
187 unsigned long long completed, 164 unsigned long long completed,
188 cron_t eta, 165 cron_t eta, FSUI_State state)
189 FSUI_State state) { 166{
190 DownloadList * list; 167 DownloadList *list;
191 GtkTreeIter iter; 168 GtkTreeIter iter;
192 GtkTreeIter piter; 169 GtkTreeIter piter;
193 GtkTreePath * path; 170 GtkTreePath *path;
194 unsigned long long size; 171 unsigned long long size;
195 char * size_h; 172 char *size_h;
196 const char * sname; 173 const char *sname;
197 int progress; 174 int progress;
198 char * uri_name; 175 char *uri_name;
199 gboolean valid; 176 gboolean valid;
200 struct ECRS_URI * u; 177 struct ECRS_URI *u;
201 GtkTreeModel * model; 178 GtkTreeModel *model;
202 179
203 /* setup visualization */ 180 /* setup visualization */
204 list = MALLOC(sizeof(DownloadList)); 181 list = MALLOC (sizeof (DownloadList));
205 memset(list, 182 memset (list, 0, sizeof (DownloadList));
206 0, 183 list->uri = ECRS_dupUri (fi->uri);
207 sizeof(DownloadList)); 184 list->filename = STRDUP (filename);
208 list->uri = ECRS_dupUri(fi->uri); 185 if ((dl_parent != NULL) &&
209 list->filename = STRDUP(filename); 186 (NULL !=
210 if ( (dl_parent != NULL) && 187 (path =
211 (NULL != (path = gtk_tree_row_reference_get_path(dl_parent->summaryViewRowReference) ) ) ) { 188 gtk_tree_row_reference_get_path (dl_parent->
212 valid = gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), 189 summaryViewRowReference))))
213 &piter, 190 {
214 path); 191 valid = gtk_tree_model_get_iter (GTK_TREE_MODEL (download_summary),
215 if (valid) { 192 &piter, path);
216 gtk_tree_store_append(download_summary, 193 if (valid)
217 &iter, 194 {
218 &piter); 195 gtk_tree_store_append (download_summary, &iter, &piter);
219 } else { 196 }
220 gtk_tree_store_append(download_summary, 197 else
221 &iter, 198 {
222 NULL); 199 gtk_tree_store_append (download_summary, &iter, NULL);
223 } 200 }
224 gtk_tree_path_free(path); 201 gtk_tree_path_free (path);
225 } else { 202 }
226 gtk_tree_store_append(download_summary, 203 else
227 &iter, 204 {
228 NULL); 205 gtk_tree_store_append (download_summary, &iter, NULL);
229 } 206 }
230 size = ECRS_fileSize(fi->uri); 207 size = ECRS_fileSize (fi->uri);
231 size_h = string_get_fancy_byte_size(size); 208 size_h = string_get_fancy_byte_size (size);
232 sname = &filename[strlen(filename)-1]; 209 sname = &filename[strlen (filename) - 1];
233 while ( (sname > filename) && 210 while ((sname > filename) && (sname[-1] != '/') && (sname[-1] != '\\'))
234 (sname[-1] != '/') &&
235 (sname[-1] != '\\') )
236 sname--; 211 sname--;
237 if (size != 0) 212 if (size != 0)
238 progress = completed * 100 / size; 213 progress = completed * 100 / size;
239 else 214 else
240 progress = 100; 215 progress = 100;
241 uri_name = ECRS_uriToString(fi->uri); 216 uri_name = ECRS_uriToString (fi->uri);
242 gtk_tree_store_set(download_summary, 217 gtk_tree_store_set (download_summary,
243 &iter, 218 &iter,
244 DOWNLOAD_FILENAME, filename, 219 DOWNLOAD_FILENAME, filename,
245 DOWNLOAD_SHORTNAME, sname, 220 DOWNLOAD_SHORTNAME, sname,
246 DOWNLOAD_SIZE, size, 221 DOWNLOAD_SIZE, size,
247 DOWNLOAD_HSIZE, size_h, 222 DOWNLOAD_HSIZE, size_h,
248 DOWNLOAD_PROGRESS, progress, 223 DOWNLOAD_PROGRESS, progress,
249 DOWNLOAD_URISTRING, uri_name, 224 DOWNLOAD_URISTRING, uri_name,
250 DOWNLOAD_INTERNAL, list, 225 DOWNLOAD_INTERNAL, list, -1);
251 -1); 226 FREE (uri_name);
252 FREE(uri_name); 227 FREE (size_h);
253 FREE(size_h); 228 path = gtk_tree_model_get_path (GTK_TREE_MODEL (download_summary), &iter);
254 path = gtk_tree_model_get_path(GTK_TREE_MODEL(download_summary),
255 &iter);
256 list->summaryViewRowReference 229 list->summaryViewRowReference
257 = gtk_tree_row_reference_new(GTK_TREE_MODEL(download_summary), 230 = gtk_tree_row_reference_new (GTK_TREE_MODEL (download_summary), path);
258 path); 231 gtk_tree_path_free (path);
259 gtk_tree_path_free(path);
260 list->searchList = sl_parent; 232 list->searchList = sl_parent;
261 list->searchViewRowReference = NULL; 233 list->searchViewRowReference = NULL;
262 if (sl_parent != NULL) { 234 if (sl_parent != NULL)
263 model = GTK_TREE_MODEL(sl_parent->tree); 235 {
264 if (dl_parent != NULL) { 236 model = GTK_TREE_MODEL (sl_parent->tree);
265 /* have parent, must be download from 237 if (dl_parent != NULL)
266 directory inside of search */ 238 {
267 /* FIXME: this requires GTK 2.8. Since it doesn't support Win9x, the quick 239 /* have parent, must be download from
268 solution is to #ifndef it */ 240 directory inside of search */
241 /* FIXME: this requires GTK 2.8. Since it doesn't support Win9x, the quick
242 solution is to #ifndef it */
269#ifndef MINGW 243#ifndef MINGW
270 GE_BREAK(ectx, 244 GE_BREAK (ectx,
271 gtk_tree_row_reference_get_model(dl_parent->searchViewRowReference) 245 gtk_tree_row_reference_get_model (dl_parent->
272 == model); 246 searchViewRowReference)
247 == model);
273#endif 248#endif
274 path = gtk_tree_row_reference_get_path(dl_parent->searchViewRowReference); 249 path =
275 if (path != NULL) { 250 gtk_tree_row_reference_get_path (dl_parent->
276 valid = gtk_tree_model_get_iter(model, 251 searchViewRowReference);
277 &piter, 252 if (path != NULL)
278 path); 253 {
279 GE_BREAK(ectx, valid == TRUE); 254 valid = gtk_tree_model_get_iter (model, &piter, path);
280 if (valid == TRUE) { 255 GE_BREAK (ectx, valid == TRUE);
281 valid = gtk_tree_model_iter_children(model, 256 if (valid == TRUE)
282 &iter, 257 {
283 &piter); 258 valid = gtk_tree_model_iter_children (model, &iter, &piter);
284 GE_BREAK(ectx, valid == TRUE); 259 GE_BREAK (ectx, valid == TRUE);
285 } 260 }
286 } else { 261 }
287 GE_BREAK(ectx, 0); 262 else
288 valid = FALSE; 263 {
289 } 264 GE_BREAK (ectx, 0);
290 } else { 265 valid = FALSE;
291 /* no download-parent, must be top-level entry in search */ 266 }
292 valid = gtk_tree_model_get_iter_first(model, 267 }
293 &iter); 268 else
294 GE_BREAK(ectx, valid == TRUE); 269 {
295 } 270 /* no download-parent, must be top-level entry in search */
296 while (valid == TRUE) { 271 valid = gtk_tree_model_get_iter_first (model, &iter);
297 /* find matching entry */ 272 GE_BREAK (ectx, valid == TRUE);
298 gtk_tree_model_get(model, 273 }
299 &iter, 274 while (valid == TRUE)
300 SEARCH_URI, &u, 275 {
301 -1); 276 /* find matching entry */
302 if (ECRS_equalsUri(u, 277 gtk_tree_model_get (model, &iter, SEARCH_URI, &u, -1);
303 fi->uri)) { 278 if (ECRS_equalsUri (u, fi->uri))
304 path = gtk_tree_model_get_path(model, 279 {
305 &iter); 280 path = gtk_tree_model_get_path (model, &iter);
306 list->searchViewRowReference 281 list->searchViewRowReference
307 = gtk_tree_row_reference_new(model, 282 = gtk_tree_row_reference_new (model, path);
308 path); 283 gtk_tree_path_free (path);
309 gtk_tree_path_free(path); 284 gtk_tree_store_set (sl_parent->tree,
310 gtk_tree_store_set(sl_parent->tree, 285 &iter,
311 &iter, 286 SEARCH_CELL_BG_COLOR,
312 SEARCH_CELL_BG_COLOR, getColorCode(URITRACK_DOWNLOAD_STARTED), 287 getColorCode (URITRACK_DOWNLOAD_STARTED),
313 -1); 288 -1);
314 break; 289 break;
315 } 290 }
316 valid = gtk_tree_model_iter_next(model, 291 valid = gtk_tree_model_iter_next (model, &iter);
317 &iter); 292 }
318 } 293 if (valid == FALSE)
319 if (valid == FALSE) { 294 {
320 /* did not find matching entry in search list -- bug! Continue 295 /* did not find matching entry in search list -- bug! Continue
321 without adding to to search list! */ 296 without adding to to search list! */
322 GE_BREAK(ectx, 0); 297 GE_BREAK (ectx, 0);
323 list->searchList = NULL; 298 list->searchList = NULL;
324 } 299 }
325 } 300 }
326 list->fsui_list = fsui_dl; 301 list->fsui_list = fsui_dl;
327 list->total = total; 302 list->total = total;
328 list->is_directory = ECRS_isDirectory(fi->meta); 303 list->is_directory = ECRS_isDirectory (fi->meta);
329 list->has_terminated = ( (state != FSUI_ACTIVE) && 304 list->has_terminated = ((state != FSUI_ACTIVE) && (state != FSUI_PENDING));
330 (state != FSUI_PENDING) );
331 list->next = download_head; 305 list->next = download_head;
332 download_head = list; 306 download_head = list;
333 if ( (list->is_directory == YES) && 307 if ((list->is_directory == YES) && (completed != 0))
334 (completed != 0) ) 308 refreshDirectoryViewFromDisk (list);
335 refreshDirectoryViewFromDisk(list);
336 return list; 309 return list;
337} 310}
338 311
@@ -341,158 +314,166 @@ fs_download_started(struct FSUI_DownloadList * fsui_dl,
341 * summary and the preview of the directory 314 * summary and the preview of the directory
342 * contents in the search page (if applicable). 315 * contents in the search page (if applicable).
343 */ 316 */
344void fs_download_update(DownloadList * list, 317void
345 unsigned long long completed, 318fs_download_update (DownloadList * list,
346 const char * data, 319 unsigned long long completed,
347 unsigned int size) { 320 const char *data, unsigned int size)
321{
348 GtkTreeIter iter; 322 GtkTreeIter iter;
349 GtkTreePath * path; 323 GtkTreePath *path;
350 unsigned int val; 324 unsigned int val;
351 struct ECRS_MetaData * meta; 325 struct ECRS_MetaData *meta;
352 326
353 path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); 327 path = gtk_tree_row_reference_get_path (list->summaryViewRowReference);
354 if (path == NULL) { 328 if (path == NULL)
355 GE_BREAK(ectx, 0); 329 {
356 return; 330 GE_BREAK (ectx, 0);
357 } 331 return;
358 gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), 332 }
359 &iter, 333 gtk_tree_model_get_iter (GTK_TREE_MODEL (download_summary), &iter, path);
360 path); 334 gtk_tree_path_free (path);
361 gtk_tree_path_free(path);
362 if (list->total != 0) 335 if (list->total != 0)
363 val = completed * 100 / list->total; 336 val = completed * 100 / list->total;
364 else 337 else
365 val = 100; 338 val = 100;
366 gtk_tree_store_set(download_summary, 339 gtk_tree_store_set (download_summary, &iter, DOWNLOAD_PROGRESS, val, -1);
367 &iter, 340 if ((list->is_directory == YES) &&
368 DOWNLOAD_PROGRESS, val, 341 (list->searchList != NULL) && (list->searchViewRowReference != NULL))
369 -1); 342 {
370 if ( (list->is_directory == YES) && 343 meta = NULL;
371 (list->searchList != NULL) && 344 ECRS_listDirectory (ectx,
372 (list->searchViewRowReference != NULL) ) { 345 data, size, &meta, &addFilesToDirectory, list);
373 meta = NULL; 346 if (meta != NULL)
374 ECRS_listDirectory(ectx, 347 ECRS_freeMetaData (meta);
375 data, 348 }
376 size,
377 &meta,
378 &addFilesToDirectory,
379 list);
380 if (meta != NULL)
381 ECRS_freeMetaData(meta);
382 }
383} 349}
384 350
385/** 351/**
386 * A download has terminated successfully. Update summary and 352 * A download has terminated successfully. Update summary and
387 * possibly refresh directory listing. 353 * possibly refresh directory listing.
388 */ 354 */
389void fs_download_completed(DownloadList * downloadContext) { 355void
356fs_download_completed (DownloadList * downloadContext)
357{
390 GtkTreeIter iter; 358 GtkTreeIter iter;
391 GtkTreePath * path; 359 GtkTreePath *path;
392 360
393 if (downloadContext->searchViewRowReference != NULL) { 361 if (downloadContext->searchViewRowReference != NULL)
394 path = gtk_tree_row_reference_get_path(downloadContext->searchViewRowReference); 362 {
395 gtk_tree_model_get_iter(GTK_TREE_MODEL(downloadContext->searchList->tree), 363 path =
396 &iter, 364 gtk_tree_row_reference_get_path (downloadContext->
397 path); 365 searchViewRowReference);
398 gtk_tree_path_free(path); 366 gtk_tree_model_get_iter (GTK_TREE_MODEL
399 gtk_tree_store_set(downloadContext->searchList->tree, 367 (downloadContext->searchList->tree), &iter,
400 &iter, 368 path);
401 SEARCH_CELL_BG_COLOR, getColorCode(URITRACK_DOWNLOAD_COMPLETED), 369 gtk_tree_path_free (path);
402 -1); 370 gtk_tree_store_set (downloadContext->searchList->tree,
403 } 371 &iter,
372 SEARCH_CELL_BG_COLOR,
373 getColorCode (URITRACK_DOWNLOAD_COMPLETED), -1);
374 }
404 downloadContext->has_terminated = YES; 375 downloadContext->has_terminated = YES;
405 refreshDirectoryViewFromDisk(downloadContext); 376 refreshDirectoryViewFromDisk (downloadContext);
406} 377}
407 378
408/** 379/**
409 * A download has been aborted. Update summary and 380 * A download has been aborted. Update summary and
410 * possibly refresh directory listing. 381 * possibly refresh directory listing.
411 */ 382 */
412void fs_download_aborted(DownloadList * downloadContext) { 383void
384fs_download_aborted (DownloadList * downloadContext)
385{
413 GtkTreeIter iter; 386 GtkTreeIter iter;
414 GtkTreePath * path; 387 GtkTreePath *path;
415 388
416 if (downloadContext->searchViewRowReference != NULL) { 389 if (downloadContext->searchViewRowReference != NULL)
417 path = gtk_tree_row_reference_get_path(downloadContext->searchViewRowReference); 390 {
418 gtk_tree_model_get_iter(GTK_TREE_MODEL(downloadContext->searchList->tree), 391 path =
419 &iter, 392 gtk_tree_row_reference_get_path (downloadContext->
420 path); 393 searchViewRowReference);
421 gtk_tree_path_free(path); 394 gtk_tree_model_get_iter (GTK_TREE_MODEL
422 gtk_tree_store_set(downloadContext->searchList->tree, 395 (downloadContext->searchList->tree), &iter,
423 &iter, 396 path);
424 SEARCH_CELL_BG_COLOR, getColorCode(URITRACK_DOWNLOAD_ABORTED), 397 gtk_tree_path_free (path);
425 -1); 398 gtk_tree_store_set (downloadContext->searchList->tree,
426 } 399 &iter,
400 SEARCH_CELL_BG_COLOR,
401 getColorCode (URITRACK_DOWNLOAD_ABORTED), -1);
402 }
427 downloadContext->has_terminated = YES; 403 downloadContext->has_terminated = YES;
428 refreshDirectoryViewFromDisk(downloadContext); 404 refreshDirectoryViewFromDisk (downloadContext);
429} 405}
430 406
431/** 407/**
432 * A download has been stopped. Remove from summary 408 * A download has been stopped. Remove from summary
433 * and free associated resources. 409 * and free associated resources.
434 */ 410 */
435void fs_download_stopped(DownloadList * list) { 411void
412fs_download_stopped (DownloadList * list)
413{
436 GtkTreeIter iter; 414 GtkTreeIter iter;
437 GtkTreeIter piter; 415 GtkTreeIter piter;
438 GtkTreePath * path; 416 GtkTreePath *path;
439 DownloadList * prev; 417 DownloadList *prev;
440 int valid; 418 int valid;
441 GtkTreeModel * model; 419 GtkTreeModel *model;
442 420
443 path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); 421 path = gtk_tree_row_reference_get_path (list->summaryViewRowReference);
444 if (path == NULL) { 422 if (path == NULL)
445 GE_BREAK(ectx, 0); 423 {
446 } else { 424 GE_BREAK (ectx, 0);
447 gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), 425 }
448 &iter, 426 else
449 path); 427 {
450 gtk_tree_path_free(path); 428 gtk_tree_model_get_iter (GTK_TREE_MODEL (download_summary),
451 gtk_tree_row_reference_free(list->summaryViewRowReference); 429 &iter, path);
452 list->summaryViewRowReference = NULL; 430 gtk_tree_path_free (path);
453 gtk_tree_store_remove(download_summary, 431 gtk_tree_row_reference_free (list->summaryViewRowReference);
454 &iter); 432 list->summaryViewRowReference = NULL;
455 } 433 gtk_tree_store_remove (download_summary, &iter);
456 FREE(list->filename); 434 }
457 ECRS_freeUri(list->uri); 435 FREE (list->filename);
436 ECRS_freeUri (list->uri);
458 437
459 /* if we have child-results in view, remove them! */ 438 /* if we have child-results in view, remove them! */
460 if (list->searchList != NULL) { 439 if (list->searchList != NULL)
461 path = gtk_tree_row_reference_get_path(list->searchViewRowReference); 440 {
462 if (path == NULL) { 441 path = gtk_tree_row_reference_get_path (list->searchViewRowReference);
463 GE_BREAK(ectx, 0); 442 if (path == NULL)
464 } else { 443 {
465 model = GTK_TREE_MODEL(list->searchList->tree); 444 GE_BREAK (ectx, 0);
466 gtk_tree_model_get_iter(model, 445 }
467 &piter, 446 else
468 path); 447 {
469 gtk_tree_path_free(path); 448 model = GTK_TREE_MODEL (list->searchList->tree);
470 valid = gtk_tree_model_iter_children(model, 449 gtk_tree_model_get_iter (model, &piter, path);
471 &iter, 450 gtk_tree_path_free (path);
472 &piter); 451 valid = gtk_tree_model_iter_children (model, &iter, &piter);
473 while (TRUE == valid) 452 while (TRUE == valid)
474 valid = gtk_tree_store_remove(GTK_TREE_STORE(model), 453 valid = gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
475 &iter); 454 }
476 } 455 }
477 } 456 if (list->searchViewRowReference != NULL)
478 if (list->searchViewRowReference != NULL) { 457 {
479 gtk_tree_row_reference_free(list->searchViewRowReference); 458 gtk_tree_row_reference_free (list->searchViewRowReference);
480 list->searchViewRowReference = NULL; 459 list->searchViewRowReference = NULL;
481 } 460 }
482 461
483 if (download_head == list) { 462 if (download_head == list)
484 download_head = list->next; 463 {
485 } else { 464 download_head = list->next;
486 prev = download_head; 465 }
487 while ( (prev != NULL) && 466 else
488 (prev->next != list) ) 467 {
489 prev = prev->next; 468 prev = download_head;
490 if (prev != NULL) 469 while ((prev != NULL) && (prev->next != list))
491 prev->next = list->next; 470 prev = prev->next;
492 else 471 if (prev != NULL)
493 GE_BREAK(ectx, 0); 472 prev->next = list->next;
494 } 473 else
495 FREE(list); 474 GE_BREAK (ectx, 0);
475 }
476 FREE (list);
496} 477}
497 478
498 479
@@ -506,59 +487,60 @@ void fs_download_stopped(DownloadList * list) {
506 * such a download is already active. 487 * such a download is already active.
507 */ 488 */
508static int 489static int
509check_pending(const char * filename, 490check_pending (const char *filename, GtkTreeIter * parent)
510 GtkTreeIter * parent) { 491{
511 GtkTreeModel * model; 492 GtkTreeModel *model;
512 GtkTreeIter iter; 493 GtkTreeIter iter;
513 char * name; 494 char *name;
514 495
515 model = GTK_TREE_MODEL(download_summary); 496 model = GTK_TREE_MODEL (download_summary);
516 if (gtk_tree_model_iter_children(model, 497 if (gtk_tree_model_iter_children (model, &iter, parent))
517 &iter, 498 {
518 parent)) { 499 do
519 do { 500 {
520 gtk_tree_model_get(model, 501 gtk_tree_model_get (model, &iter, DOWNLOAD_FILENAME, &name, -1);
521 &iter, 502 if ((name != NULL) && (0 == strcmp (name, filename)))
522 DOWNLOAD_FILENAME, &name, 503 {
523 -1); 504 free (name);
524 if ( (name != NULL) && 505 return SYSERR;
525 (0 == strcmp(name, filename)) ) { 506 }
526 free(name); 507 if (name != NULL)
527 return SYSERR; 508 free (name);
528 } 509 if (SYSERR == check_pending (filename, &iter))
529 if (name != NULL) 510 return SYSERR;
530 free(name); 511 }
531 if (SYSERR == check_pending(filename, 512 while (gtk_tree_model_iter_next (model, &iter));
532 &iter)) 513 }
533 return SYSERR;
534 } while (gtk_tree_model_iter_next(model,
535 &iter));
536 }
537 return OK; 514 return OK;
538} 515}
539 516
540typedef struct { 517typedef struct
541 char * uri_name; 518{
542 struct ECRS_URI * idc_uri; 519 char *uri_name;
543 struct ECRS_MetaData * idc_meta; 520 struct ECRS_URI *idc_uri;
544 char * idc_final_download_destination; 521 struct ECRS_MetaData *idc_meta;
545 SearchList * searchContext; 522 char *idc_final_download_destination;
546 DownloadList * parentContext; 523 SearchList *searchContext;
524 DownloadList *parentContext;
547 unsigned int anonymity; 525 unsigned int anonymity;
548 int recursive; 526 int recursive;
549} SDC; 527} SDC;
550 528
551static void * init_download_helper(void * cls) { 529static void *
552 SDC * sdc = cls; 530init_download_helper (void *cls)
553 531{
554 FSUI_startDownload(ctx, 532 SDC *sdc = cls;
555 sdc->anonymity, 533
556 sdc->recursive, 534 FSUI_startDownload (ctx,
557 sdc->idc_uri, 535 sdc->anonymity,
558 sdc->idc_meta, 536 sdc->recursive,
559 sdc->idc_final_download_destination, 537 sdc->idc_uri,
560 (sdc->searchContext != NULL) ? sdc->searchContext->fsui_list : NULL, 538 sdc->idc_meta,
561 (sdc->parentContext != NULL) ? sdc->parentContext->fsui_list : NULL); 539 sdc->idc_final_download_destination,
540 (sdc->searchContext !=
541 NULL) ? sdc->searchContext->fsui_list : NULL,
542 (sdc->parentContext !=
543 NULL) ? sdc->parentContext->fsui_list : NULL);
562 return NULL; 544 return NULL;
563} 545}
564 546
@@ -567,21 +549,20 @@ static void * init_download_helper(void * cls) {
567 * Start the download of the selected entry. 549 * Start the download of the selected entry.
568 */ 550 */
569static void 551static void
570initiateDownload(GtkTreeModel * model, 552initiateDownload (GtkTreeModel * model,
571 GtkTreePath * path, 553 GtkTreePath * path, GtkTreeIter * iter, gpointer unused)
572 GtkTreeIter * iter, 554{
573 gpointer unused) {
574 SDC sdc; 555 SDC sdc;
575 char * final_download_dir; 556 char *final_download_dir;
576 GtkTreeIter iiter; 557 GtkTreeIter iiter;
577 char * tmp; 558 char *tmp;
578 char * cname; 559 char *cname;
579 char * dname; 560 char *dname;
580 GtkTreePath *dirTreePath; 561 GtkTreePath *dirTreePath;
581 char *dirPath; 562 char *dirPath;
582 unsigned int dirPathLen; 563 unsigned int dirPathLen;
583 char * idc_name; 564 char *idc_name;
584 char * idc_mime; 565 char *idc_mime;
585 566
586 sdc.idc_uri = NULL; 567 sdc.idc_uri = NULL;
587 sdc.idc_meta = NULL; 568 sdc.idc_meta = NULL;
@@ -589,178 +570,183 @@ initiateDownload(GtkTreeModel * model,
589 idc_mime = NULL; 570 idc_mime = NULL;
590 sdc.searchContext = NULL; 571 sdc.searchContext = NULL;
591 sdc.parentContext = NULL; 572 sdc.parentContext = NULL;
592 gtk_tree_model_get(model, 573 gtk_tree_model_get (model,
593 iter, 574 iter,
594 SEARCH_NAME, &idc_name, 575 SEARCH_NAME, &idc_name,
595 SEARCH_URI, &sdc.idc_uri, 576 SEARCH_URI, &sdc.idc_uri,
596 SEARCH_META, &sdc.idc_meta, 577 SEARCH_META, &sdc.idc_meta,
597 SEARCH_MIME, &idc_mime, 578 SEARCH_MIME, &idc_mime,
598 SEARCH_INTERNAL, &sdc.searchContext, 579 SEARCH_INTERNAL, &sdc.searchContext,
599 SEARCH_INTERNAL_PARENT, &sdc.parentContext, 580 SEARCH_INTERNAL_PARENT, &sdc.parentContext, -1);
600 -1); 581 if ((sdc.idc_uri == NULL) ||
601 if ( (sdc.idc_uri == NULL) || 582 (!(ECRS_isFileUri (sdc.idc_uri) || ECRS_isLocationUri (sdc.idc_uri))))
602 (! (ECRS_isFileUri(sdc.idc_uri) || 583 {
603 ECRS_isLocationUri(sdc.idc_uri) ) ) ) { 584 GE_BREAK (ectx, 0);
604 GE_BREAK(ectx, 0); 585 FREENONNULL (idc_name);
605 FREENONNULL(idc_name); 586 FREENONNULL (idc_mime);
606 FREENONNULL(idc_mime); 587 return;
607 return; 588 }
608 } 589 sdc.uri_name = ECRS_uriToString (sdc.idc_uri);
609 sdc.uri_name = ECRS_uriToString(sdc.idc_uri); 590 if ((sdc.uri_name == NULL) ||
610 if ( (sdc.uri_name == NULL) || 591 (strlen (sdc.uri_name) <
611 (strlen(sdc.uri_name) < 592 strlen (ECRS_URI_PREFIX) + strlen (ECRS_FILE_INFIX)))
612 strlen(ECRS_URI_PREFIX) + 593 {
613 strlen(ECRS_FILE_INFIX)) ) { 594 GE_BREAK (ectx, 0);
614 GE_BREAK(ectx, 0); 595 FREENONNULL (sdc.uri_name);
615 FREENONNULL(sdc.uri_name); 596 FREENONNULL (idc_name);
616 FREENONNULL(idc_name); 597 FREENONNULL (idc_mime);
617 FREENONNULL(idc_mime); 598 return;
618 return; 599 }
619 }
620 /* reduce "//" to "/" */ 600 /* reduce "//" to "/" */
621 if (idc_name != NULL) { 601 if (idc_name != NULL)
622 while (strstr(idc_name, "//") != NULL) 602 {
623 memcpy(strstr(idc_name, "//"), 603 while (strstr (idc_name, "//") != NULL)
624 strstr(idc_name, "//") + 1, 604 memcpy (strstr (idc_name, "//"),
625 strlen(strstr(idc_name, "//"))); 605 strstr (idc_name, "//") + 1,
626 } 606 strlen (strstr (idc_name, "//")));
607 }
627 /* if no name given or just "/", produce better name */ 608 /* if no name given or just "/", produce better name */
628 if ( (idc_name == NULL) || 609 if ((idc_name == NULL) || (0 == strcmp ("/", idc_name)))
629 (0 == strcmp("/", idc_name)) ) { 610 {
630#ifdef WINDOWS 611#ifdef WINDOWS
631 char * filehash; 612 char *filehash;
632 613
633 GE_ASSERT(NULL, 614 GE_ASSERT (NULL,
634 strlen(sdc.uri_name) > strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)); 615 strlen (sdc.uri_name) >
635 FREENONNULL(idc_name); 616 strlen (ECRS_URI_PREFIX) + strlen (ECRS_FILE_INFIX));
636 filehash = STRDUP(&sdc.uri_name[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]); 617 FREENONNULL (idc_name);
637 filehash[16] = 0; 618 filehash =
638 idc_name = STRDUP(filehash); 619 STRDUP (&sdc.
639 FREENONNULL(filehash); 620 uri_name[strlen (ECRS_URI_PREFIX) +
621 strlen (ECRS_FILE_INFIX)]);
622 filehash[16] = 0;
623 idc_name = STRDUP (filehash);
624 FREENONNULL (filehash);
640#else 625#else
641 GE_ASSERT(NULL, 626 GE_ASSERT (NULL,
642 strlen(sdc.uri_name) > strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)); 627 strlen (sdc.uri_name) >
643 FREENONNULL(idc_name); 628 strlen (ECRS_URI_PREFIX) + strlen (ECRS_FILE_INFIX));
644 idc_name = STRDUP(&sdc.uri_name[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]); 629 FREENONNULL (idc_name);
630 idc_name =
631 STRDUP (&sdc.
632 uri_name[strlen (ECRS_URI_PREFIX) +
633 strlen (ECRS_FILE_INFIX)]);
645#endif 634#endif
646 } 635 }
647 636
648 /* dname = directory portion of idc_name */ 637 /* dname = directory portion of idc_name */
649 cname = idc_name; 638 cname = idc_name;
650 dname = STRDUP(idc_name); 639 dname = STRDUP (idc_name);
651 cname = &dname[strlen(dname)-1]; 640 cname = &dname[strlen (dname) - 1];
652 if (cname != dname) 641 if (cname != dname)
653 cname--; /* ignore tailing '/' */ 642 cname--; /* ignore tailing '/' */
654 while ( (cname != dname) && 643 while ((cname != dname) && (*cname != DIR_SEPARATOR))
655 (*cname != DIR_SEPARATOR) )
656 cname--; 644 cname--;
657 if (*cname == DIR_SEPARATOR) { 645 if (*cname == DIR_SEPARATOR)
658 *cname = '\0'; 646 {
659 FREE(idc_name); 647 *cname = '\0';
660 idc_name = STRDUP(cname + 1); 648 FREE (idc_name);
661 } else { 649 idc_name = STRDUP (cname + 1);
662 *cname = '\0'; 650 }
663 } 651 else
652 {
653 *cname = '\0';
654 }
664 cname = NULL; 655 cname = NULL;
665 656
666 GC_get_configuration_value_filename(cfg, 657 GC_get_configuration_value_filename (cfg,
667 "FS", 658 "FS",
668 "INCOMINGDIR", 659 "INCOMINGDIR",
669 "$HOME/gnunet-downloads/", 660 "$HOME/gnunet-downloads/",
670 &final_download_dir); 661 &final_download_dir);
671 if (strlen(dname) > 0) { 662 if (strlen (dname) > 0)
672 tmp = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); 663 {
673 strcpy(tmp, final_download_dir); 664 tmp = MALLOC (strlen (final_download_dir) + strlen (dname) + 2);
674 if (tmp[strlen(tmp)] != DIR_SEPARATOR) 665 strcpy (tmp, final_download_dir);
675 strcat(tmp, DIR_SEPARATOR_STR); 666 if (tmp[strlen (tmp)] != DIR_SEPARATOR)
676 if (dname[0] == DIR_SEPARATOR) 667 strcat (tmp, DIR_SEPARATOR_STR);
677 strcat(tmp, &dname[1]); 668 if (dname[0] == DIR_SEPARATOR)
678 else 669 strcat (tmp, &dname[1]);
679 strcat(tmp, dname); 670 else
680 FREE(final_download_dir); 671 strcat (tmp, dname);
681 final_download_dir = tmp; 672 FREE (final_download_dir);
682 } 673 final_download_dir = tmp;
683 FREE(dname); 674 }
675 FREE (dname);
684 dname = NULL; 676 dname = NULL;
685 /* If file is inside a directory, get the full path */ 677 /* If file is inside a directory, get the full path */
686 dirTreePath = gtk_tree_path_copy(path); 678 dirTreePath = gtk_tree_path_copy (path);
687 dirPath = MALLOC(1); 679 dirPath = MALLOC (1);
688 dirPath[0] = '\0'; 680 dirPath[0] = '\0';
689 dirPathLen = 0; 681 dirPathLen = 0;
690 while (gtk_tree_path_get_depth(dirTreePath) > 1) { 682 while (gtk_tree_path_get_depth (dirTreePath) > 1)
691 char * dirname; 683 {
692 char * newPath; 684 char *dirname;
693 685 char *newPath;
694 if (! gtk_tree_path_up(dirTreePath)) 686
695 break; 687 if (!gtk_tree_path_up (dirTreePath))
696 if (! gtk_tree_model_get_iter(model, 688 break;
697 &iiter, 689 if (!gtk_tree_model_get_iter (model, &iiter, dirTreePath))
698 dirTreePath)) 690 break;
699 break; 691 gtk_tree_model_get (model, &iiter, SEARCH_NAME, &dirname, -1);
700 gtk_tree_model_get(model, 692 dirPathLen =
701 &iiter, 693 strlen (dirPath) + strlen (dirname) + strlen (DIR_SEPARATOR_STR) + 1;
702 SEARCH_NAME, &dirname, 694 newPath = MALLOC (dirPathLen + 1);
703 -1); 695 strcpy (newPath, dirname);
704 dirPathLen = strlen(dirPath) + strlen(dirname) + strlen(DIR_SEPARATOR_STR) + 1; 696 if (newPath[strlen (newPath) - 1] != DIR_SEPARATOR)
705 newPath = MALLOC(dirPathLen + 1); 697 strcat (newPath, DIR_SEPARATOR_STR);
706 strcpy(newPath, dirname); 698 strcat (newPath, dirPath);
707 if (newPath[strlen(newPath)-1] != DIR_SEPARATOR) 699 FREE (dirPath);
708 strcat(newPath, DIR_SEPARATOR_STR); 700 dirPath = newPath;
709 strcat(newPath, dirPath); 701 free (dirname);
710 FREE(dirPath); 702 }
711 dirPath = newPath; 703 gtk_tree_path_free (dirTreePath);
712 free(dirname);
713 }
714 gtk_tree_path_free(dirTreePath);
715 704
716 /* construct completed/directory/real-filename */ 705 /* construct completed/directory/real-filename */
717 sdc.idc_final_download_destination = MALLOC(strlen(final_download_dir) + 2 + 706 sdc.idc_final_download_destination =
718 strlen(idc_name) + strlen(GNUNET_DIRECTORY_EXT) + 707 MALLOC (strlen (final_download_dir) + 2 + strlen (idc_name) +
719 strlen(dirPath)); 708 strlen (GNUNET_DIRECTORY_EXT) + strlen (dirPath));
720 strcpy(sdc.idc_final_download_destination, 709 strcpy (sdc.idc_final_download_destination, final_download_dir);
721 final_download_dir); 710 if (sdc.
722 if (sdc.idc_final_download_destination[strlen(sdc.idc_final_download_destination)-1] != DIR_SEPARATOR) 711 idc_final_download_destination[strlen
723 strcat(sdc.idc_final_download_destination, 712 (sdc.idc_final_download_destination) -
724 DIR_SEPARATOR_STR); 713 1] != DIR_SEPARATOR)
725 strcat(sdc.idc_final_download_destination, 714 strcat (sdc.idc_final_download_destination, DIR_SEPARATOR_STR);
726 dirPath); 715 strcat (sdc.idc_final_download_destination, dirPath);
727 strcat(sdc.idc_final_download_destination, 716 strcat (sdc.idc_final_download_destination, idc_name);
728 idc_name); 717 sdc.anonymity = getSpinButtonValue (sdc.searchContext->searchXML,
729 sdc.anonymity = getSpinButtonValue(sdc.searchContext->searchXML, 718 "downloadAnonymitySpinButton");
730 "downloadAnonymitySpinButton"); 719 sdc.recursive = getToggleButtonValue (sdc.searchContext->searchXML,
731 sdc.recursive = getToggleButtonValue(sdc.searchContext->searchXML, 720 "downloadRecursiveCheckButton");
732 "downloadRecursiveCheckButton"); 721 if (OK == check_pending (idc_name, NULL))
733 if (OK == check_pending(idc_name, 722 {
734 NULL)) { 723 addLogEntry (_("Downloading `%s'\n"), idc_name);
735 addLogEntry(_("Downloading `%s'\n"), 724 run_with_save_calls (&init_download_helper, &sdc);
736 idc_name); 725 }
737 run_with_save_calls(&init_download_helper, 726 else
738 &sdc); 727 {
739 } else { 728 addLogEntry (_("ERROR: already downloading `%s'"), idc_name);
740 addLogEntry(_("ERROR: already downloading `%s'"), 729 }
741 idc_name); 730 FREE (sdc.uri_name);
742 } 731 FREE (dirPath);
743 FREE(sdc.uri_name); 732 FREE (sdc.idc_final_download_destination);
744 FREE(dirPath); 733 FREENONNULL (final_download_dir);
745 FREE(sdc.idc_final_download_destination); 734 FREENONNULL (idc_name);
746 FREENONNULL(final_download_dir); 735 FREENONNULL (idc_mime);
747 FREENONNULL(idc_name);
748 FREENONNULL(idc_mime);
749} 736}
750 737
751/** 738/**
752 * The download button in the search dialog was 739 * The download button in the search dialog was
753 * clicked. Download all selected entries. 740 * clicked. Download all selected entries.
754 */ 741 */
755void on_downloadButton_clicked_fs(GtkWidget * treeview, 742void
756 GtkWidget * downloadButton) { 743on_downloadButton_clicked_fs (GtkWidget * treeview,
757 GtkTreeSelection * selection; 744 GtkWidget * downloadButton)
758 745{
759 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); 746 GtkTreeSelection *selection;
760 ggc_tree_selection_selected_foreach 747
761 (selection, 748 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
762 &initiateDownload, 749 ggc_tree_selection_selected_foreach (selection, &initiateDownload, NULL);
763 NULL);
764} 750}
765 751
766 752
@@ -773,161 +759,151 @@ void on_downloadButton_clicked_fs(GtkWidget * treeview,
773 * - support for user-specified filename 759 * - support for user-specified filename
774 * - enable button only if valid URI is entered 760 * - enable button only if valid URI is entered
775 */ 761 */
776void on_statusDownloadURIEntry_editing_done_fs(GtkWidget * entry, 762void
777 GtkWidget * downloadButton) { 763on_statusDownloadURIEntry_editing_done_fs (GtkWidget * entry,
778 const char * uris; 764 GtkWidget * downloadButton)
779 char * urid; 765{
780 char * final_download_dir; 766 const char *uris;
781 const char * dname; 767 char *urid;
768 char *final_download_dir;
769 const char *dname;
782 SDC sdc; 770 SDC sdc;
783 771
784 uris = gtk_entry_get_text(GTK_ENTRY(entry)); 772 uris = gtk_entry_get_text (GTK_ENTRY (entry));
785 urid = STRDUP(uris); 773 urid = STRDUP (uris);
786 gtk_entry_set_text(GTK_ENTRY(entry), 774 gtk_entry_set_text (GTK_ENTRY (entry), ECRS_URI_PREFIX);
787 ECRS_URI_PREFIX); 775 sdc.idc_uri = ECRS_stringToUri (ectx, urid);
788 sdc.idc_uri = ECRS_stringToUri(ectx, urid); 776 if (sdc.idc_uri == NULL)
789 if (sdc.idc_uri == NULL) { 777 {
790 addLogEntry(_("Invalid URI `%s'"), urid); 778 addLogEntry (_("Invalid URI `%s'"), urid);
791 FREE(urid); 779 FREE (urid);
792 return; 780 return;
793 } 781 }
794 if (ECRS_isKeywordUri(sdc.idc_uri)) { 782 if (ECRS_isKeywordUri (sdc.idc_uri))
795 addLogEntry(_("Please use the search function for keyword (KSK) URIs!")); 783 {
796 FREE(urid); 784 addLogEntry (_
797 ECRS_freeUri(sdc.idc_uri); 785 ("Please use the search function for keyword (KSK) URIs!"));
798 return; 786 FREE (urid);
799 } else if (ECRS_isLocationUri(sdc.idc_uri)) { 787 ECRS_freeUri (sdc.idc_uri);
800 addLogEntry(_("Location URIs are not yet supported")); 788 return;
801 FREE(urid); 789 }
802 ECRS_freeUri(sdc.idc_uri); 790 else if (ECRS_isLocationUri (sdc.idc_uri))
803 return; 791 {
804 } 792 addLogEntry (_("Location URIs are not yet supported"));
805 GC_get_configuration_value_filename(cfg, 793 FREE (urid);
806 "FS", 794 ECRS_freeUri (sdc.idc_uri);
807 "INCOMINGDIR", 795 return;
808 "$HOME/gnunet-downloads/", 796 }
809 &final_download_dir); 797 GC_get_configuration_value_filename (cfg,
810 disk_directory_create(ectx, final_download_dir); 798 "FS",
811 dname = &uris[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]; 799 "INCOMINGDIR",
812 sdc.idc_final_download_destination = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); 800 "$HOME/gnunet-downloads/",
813 strcpy(sdc.idc_final_download_destination, 801 &final_download_dir);
814 final_download_dir); 802 disk_directory_create (ectx, final_download_dir);
815 FREE(final_download_dir); 803 dname = &uris[strlen (ECRS_URI_PREFIX) + strlen (ECRS_FILE_INFIX)];
816 if (sdc.idc_final_download_destination[strlen(sdc.idc_final_download_destination)] != DIR_SEPARATOR) 804 sdc.idc_final_download_destination =
817 strcat(sdc.idc_final_download_destination, 805 MALLOC (strlen (final_download_dir) + strlen (dname) + 2);
818 DIR_SEPARATOR_STR); 806 strcpy (sdc.idc_final_download_destination, final_download_dir);
819 strcat(sdc.idc_final_download_destination, 807 FREE (final_download_dir);
820 dname); 808 if (sdc.
821 809 idc_final_download_destination[strlen
822 addLogEntry(_("Downloading `%s'\n"), 810 (sdc.idc_final_download_destination)] !=
823 uris); 811 DIR_SEPARATOR)
824 sdc.idc_meta = ECRS_createMetaData(); 812 strcat (sdc.idc_final_download_destination, DIR_SEPARATOR_STR);
825 sdc.anonymity = getSpinButtonValue(getMainXML(), 813 strcat (sdc.idc_final_download_destination, dname);
826 "fsstatusAnonymitySpin"); 814
815 addLogEntry (_("Downloading `%s'\n"), uris);
816 sdc.idc_meta = ECRS_createMetaData ();
817 sdc.anonymity = getSpinButtonValue (getMainXML (), "fsstatusAnonymitySpin");
827 sdc.recursive = NO; 818 sdc.recursive = NO;
828 sdc.searchContext = NULL; 819 sdc.searchContext = NULL;
829 sdc.parentContext = NULL; 820 sdc.parentContext = NULL;
830 run_with_save_calls(&init_download_helper, 821 run_with_save_calls (&init_download_helper, &sdc);
831 &sdc); 822 ECRS_freeMetaData (sdc.idc_meta);
832 ECRS_freeMetaData(sdc.idc_meta); 823 FREE (sdc.idc_final_download_destination);
833 FREE(sdc.idc_final_download_destination); 824 FREE (urid);
834 FREE(urid);
835} 825}
836 826
837struct FCBC { 827struct FCBC
838 int (*method)(struct FSUI_Context * ctx, 828{
839 struct FSUI_DownloadList * list); 829 int (*method) (struct FSUI_Context * ctx, struct FSUI_DownloadList * list);
840 struct FSUI_DownloadList * argument; 830 struct FSUI_DownloadList *argument;
841}; 831};
842 832
843static void * fsui_callback(void * cls) { 833static void *
844 struct FCBC * fcbc = cls; 834fsui_callback (void *cls)
845 fcbc->method(ctx, 835{
846 fcbc->argument); 836 struct FCBC *fcbc = cls;
837 fcbc->method (ctx, fcbc->argument);
847 return NULL; 838 return NULL;
848} 839}
849 840
850static void 841static void
851clearCompletedDownloadCallback(GtkTreeModel * model, 842clearCompletedDownloadCallback (GtkTreeModel * model,
852 GtkTreePath * path, 843 GtkTreePath * path,
853 GtkTreeIter * iter, 844 GtkTreeIter * iter, gpointer unused)
854 gpointer unused) { 845{
855 DownloadList * dl; 846 DownloadList *dl;
856 struct FCBC fcbc; 847 struct FCBC fcbc;
857 848
858 GE_ASSERT(ectx, 849 GE_ASSERT (ectx, model == GTK_TREE_MODEL (download_summary));
859 model == GTK_TREE_MODEL(download_summary)); 850 gtk_tree_model_get (model, iter, DOWNLOAD_INTERNAL, &dl, -1);
860 gtk_tree_model_get(model, 851 if ((FALSE == gtk_tree_model_iter_has_child (model,
861 iter, 852 iter)) && (dl->has_terminated))
862 DOWNLOAD_INTERNAL, &dl, 853 {
863 -1); 854 fcbc.method = &FSUI_stopDownload;
864 if ( (FALSE == gtk_tree_model_iter_has_child(model, 855 fcbc.argument = dl->fsui_list;
865 iter)) && 856 run_with_save_calls (&fsui_callback, &fcbc);
866 (dl->has_terminated) ) { 857 }
867 fcbc.method = &FSUI_stopDownload;
868 fcbc.argument = dl->fsui_list;
869 run_with_save_calls(&fsui_callback,
870 &fcbc);
871 }
872} 858}
873 859
874void on_clearCompletedDownloadsButton_clicked_fs(void * unused, 860void
875 GtkWidget * clearButton) { 861on_clearCompletedDownloadsButton_clicked_fs (void *unused,
876 ggc_tree_model_foreach(GTK_TREE_MODEL(download_summary), 862 GtkWidget * clearButton)
877 &clearCompletedDownloadCallback, 863{
878 NULL); 864 ggc_tree_model_foreach (GTK_TREE_MODEL (download_summary),
865 &clearCompletedDownloadCallback, NULL);
879} 866}
880 867
881static void 868static void
882fsuiCallDownloadCallback(GtkTreeModel * model, 869fsuiCallDownloadCallback (GtkTreeModel * model,
883 GtkTreePath * path, 870 GtkTreePath * path,
884 GtkTreeIter * iter, 871 GtkTreeIter * iter, gpointer fsui_call)
885 gpointer fsui_call) { 872{
886 DownloadList * dl; 873 DownloadList *dl;
887 struct FCBC fcbc; 874 struct FCBC fcbc;
888 875
889 GE_ASSERT(ectx, 876 GE_ASSERT (ectx, model == GTK_TREE_MODEL (download_summary));
890 model == GTK_TREE_MODEL(download_summary)); 877 gtk_tree_model_get (model, iter, DOWNLOAD_INTERNAL, &dl, -1);
891 gtk_tree_model_get(model,
892 iter,
893 DOWNLOAD_INTERNAL, &dl,
894 -1);
895 fcbc.method = fsui_call; 878 fcbc.method = fsui_call;
896 fcbc.argument = dl->fsui_list; 879 fcbc.argument = dl->fsui_list;
897 run_with_save_calls(&fsui_callback, 880 run_with_save_calls (&fsui_callback, &fcbc);
898 &fcbc);
899} 881}
900 882
901void on_abortDownloadButton_clicked_fs(void * unused, 883void
902 GtkWidget * abortButton) { 884on_abortDownloadButton_clicked_fs (void *unused, GtkWidget * abortButton)
903 GtkTreeSelection * selection; 885{
904 GtkWidget * downloadList; 886 GtkTreeSelection *selection;
887 GtkWidget *downloadList;
905 888
906 downloadList = glade_xml_get_widget(getMainXML(), 889 downloadList = glade_xml_get_widget (getMainXML (), "activeDownloadsList");
907 "activeDownloadsList"); 890 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (downloadList));
908 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(downloadList));
909 ggc_tree_selection_selected_foreach 891 ggc_tree_selection_selected_foreach
910 (selection, 892 (selection, &fsuiCallDownloadCallback, &FSUI_abortDownload);
911 &fsuiCallDownloadCallback,
912 &FSUI_abortDownload);
913} 893}
914 894
915void on_stopDownloadButton_clicked_fs(void * unused, 895void
916 GtkWidget * stopButton) { 896on_stopDownloadButton_clicked_fs (void *unused, GtkWidget * stopButton)
917 GtkTreeSelection * selection; 897{
918 GtkWidget * downloadList; 898 GtkTreeSelection *selection;
899 GtkWidget *downloadList;
919 900
920 downloadList = glade_xml_get_widget(getMainXML(), 901 downloadList = glade_xml_get_widget (getMainXML (), "activeDownloadsList");
921 "activeDownloadsList"); 902 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (downloadList));
922 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(downloadList));
923 ggc_tree_selection_selected_foreach 903 ggc_tree_selection_selected_foreach
924 (selection, 904 (selection, &fsuiCallDownloadCallback, &FSUI_abortDownload);
925 &fsuiCallDownloadCallback,
926 &FSUI_abortDownload);
927 ggc_tree_selection_selected_foreach 905 ggc_tree_selection_selected_foreach
928 (selection, 906 (selection, &fsuiCallDownloadCallback, &FSUI_stopDownload);
929 &fsuiCallDownloadCallback,
930 &FSUI_stopDownload);
931} 907}
932 908
933/* end of download.c */ 909/* end of download.c */