diff options
author | Nils Durner <durner@gnunet.org> | 2005-08-27 21:41:51 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2005-08-27 21:41:51 +0000 |
commit | b25f5691f65ad4a05e977c225ae2b5ba4c2892d7 (patch) | |
tree | a9c33952c192e11be0570a02510cccf5d20f1ae4 | |
parent | 4ae62dcffbb4825a99caacb19997fc61b4ea6f20 (diff) | |
download | gnunet-gtk-b25f5691f65ad4a05e977c225ae2b5ba4c2892d7.tar.gz gnunet-gtk-b25f5691f65ad4a05e977c225ae2b5ba4c2892d7.zip |
rename directory files
-rw-r--r-- | src/plugins/fs/download.c | 51 | ||||
-rw-r--r-- | src/plugins/fs/fs.h | 1 |
2 files changed, 51 insertions, 1 deletions
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c index 2fd3e2b9..639c5a69 100644 --- a/src/plugins/fs/download.c +++ b/src/plugins/fs/download.c | |||
@@ -118,6 +118,9 @@ static void initiateDownload(GtkTreeModel * model, | |||
118 | const char * name; | 118 | const char * name; |
119 | struct stat sbuf; | 119 | struct stat sbuf; |
120 | unsigned int anon; | 120 | unsigned int anon; |
121 | GtkTreePath *dirTreePath; | ||
122 | char *dirPath; | ||
123 | unsigned int dirPathLen; | ||
121 | 124 | ||
122 | uri = NULL; | 125 | uri = NULL; |
123 | meta = NULL; | 126 | meta = NULL; |
@@ -226,6 +229,31 @@ static void initiateDownload(GtkTreeModel * model, | |||
226 | FREE(pfx); | 229 | FREE(pfx); |
227 | pfx = STRDUP(lnk); | 230 | pfx = STRDUP(lnk); |
228 | } | 231 | } |
232 | |||
233 | /* If file is inside a directory, get the full path */ | ||
234 | dirTreePath = gtk_tree_path_copy(path); | ||
235 | dirPath = MALLOC(1); | ||
236 | dirPathLen = 0; | ||
237 | while (gtk_tree_path_up(dirTreePath)) { | ||
238 | const char *dirname; | ||
239 | char *new; | ||
240 | |||
241 | if (!gtk_tree_model_get_iter(model, &iiter, dirTreePath)) | ||
242 | break; | ||
243 | gtk_tree_model_get(model, | ||
244 | &iiter, | ||
245 | SEARCH_NAME, &dirname, | ||
246 | -1); | ||
247 | dirPathLen += strlen(dirname) + 1; | ||
248 | new = MALLOC(dirPathLen + 1); | ||
249 | strcpy(new, dirname); | ||
250 | strcat(new, DIR_SEPARATOR_STR); | ||
251 | strcat(new, dirPath); | ||
252 | FREE(dirPath); | ||
253 | dirPath = new; | ||
254 | } | ||
255 | g_object_unref(dirTreePath); | ||
256 | |||
229 | list->filename = pfx; | 257 | list->filename = pfx; |
230 | head = list; | 258 | head = list; |
231 | gtk_tree_store_insert(summary, | 259 | gtk_tree_store_insert(summary, |
@@ -241,6 +269,7 @@ static void initiateDownload(GtkTreeModel * model, | |||
241 | DOWNLOAD_URISTRING, filename, | 269 | DOWNLOAD_URISTRING, filename, |
242 | DOWNLOAD_URI, ECRS_dupUri(uri), | 270 | DOWNLOAD_URI, ECRS_dupUri(uri), |
243 | DOWNLOAD_TREEPATH, list->rr, | 271 | DOWNLOAD_TREEPATH, list->rr, |
272 | DOWNLOAD_DIRPATH, dirPath, | ||
244 | /* internal: row reference! */ | 273 | /* internal: row reference! */ |
245 | -1); | 274 | -1); |
246 | FREE(filename); | 275 | FREE(filename); |
@@ -326,6 +355,7 @@ void displayDownloadComplete(const struct ECRS_URI * uri, | |||
326 | GtkTreeIter iter; | 355 | GtkTreeIter iter; |
327 | GtkTreePath * path; | 356 | GtkTreePath * path; |
328 | struct ECRS_URI * u; | 357 | struct ECRS_URI * u; |
358 | char *dirPath; | ||
329 | 359 | ||
330 | pos = head; | 360 | pos = head; |
331 | while (pos != NULL) { | 361 | while (pos != NULL) { |
@@ -381,6 +411,7 @@ void displayDownloadComplete(const struct ECRS_URI * uri, | |||
381 | DOWNLOAD_URI, &u, | 411 | DOWNLOAD_URI, &u, |
382 | DOWNLOAD_FILENAME, &fn, | 412 | DOWNLOAD_FILENAME, &fn, |
383 | DOWNLOAD_LINKNAME, &ln, | 413 | DOWNLOAD_LINKNAME, &ln, |
414 | DOWNLOAD_DIRPATH, &dirPath, | ||
384 | -1); | 415 | -1); |
385 | if (ECRS_equalsUri(u, uri)) { | 416 | if (ECRS_equalsUri(u, uri)) { |
386 | char *dstPath, *newFn, *dstFile; | 417 | char *dstPath, *newFn, *dstFile; |
@@ -394,6 +425,20 @@ void displayDownloadComplete(const struct ECRS_URI * uri, | |||
394 | " in section `%s' under `%s'.")); | 425 | " in section `%s' under `%s'.")); |
395 | if (!dstPath) | 426 | if (!dstPath) |
396 | return; | 427 | return; |
428 | |||
429 | /* If file is contained in a directory, create directory structure in | ||
430 | the file system. */ | ||
431 | if (dirPath) { | ||
432 | unsigned int pathLen = strlen(dirPath); | ||
433 | if (pathLen) { | ||
434 | pathLen += strlen(dstPath) + 2; | ||
435 | dstPath = REALLOC(dstPath, pathLen); | ||
436 | strcat(dstPath, DIR_SEPARATOR_STR); | ||
437 | strcat(dstPath, dirPath); | ||
438 | FREE(dirPath); | ||
439 | } | ||
440 | } | ||
441 | |||
397 | mkdirp(dstPath); | 442 | mkdirp(dstPath); |
398 | 443 | ||
399 | dstFile = MALLOC(strlen(dstPath) + strlen(newFn) + 2); | 444 | dstFile = MALLOC(strlen(dstPath) + strlen(newFn) + 2); |
@@ -575,7 +620,8 @@ void fs_download_start() { | |||
575 | G_TYPE_INT, /* progress */ | 620 | G_TYPE_INT, /* progress */ |
576 | G_TYPE_STRING, /* uri */ | 621 | G_TYPE_STRING, /* uri */ |
577 | G_TYPE_POINTER, /* url */ | 622 | G_TYPE_POINTER, /* url */ |
578 | G_TYPE_POINTER); /* internal: gtk tree path / NULL */ | 623 | G_TYPE_POINTER, /* internal: gtk tree path / NULL */ |
624 | G_TYPE_POINTER); /* directory path if file is inside a dir */ | ||
579 | gtk_tree_view_set_model(GTK_TREE_VIEW(downloadList), | 625 | gtk_tree_view_set_model(GTK_TREE_VIEW(downloadList), |
580 | GTK_TREE_MODEL(summary)); | 626 | GTK_TREE_MODEL(summary)); |
581 | renderer = gtk_cell_renderer_progress_new(); | 627 | renderer = gtk_cell_renderer_progress_new(); |
@@ -611,6 +657,7 @@ void fs_download_stop() { | |||
611 | GtkTreeIter iter; | 657 | GtkTreeIter iter; |
612 | struct ECRS_URI * u; | 658 | struct ECRS_URI * u; |
613 | DownloadList * pos; | 659 | DownloadList * pos; |
660 | char *dirPath; | ||
614 | 661 | ||
615 | /* free URIs in summary model */ | 662 | /* free URIs in summary model */ |
616 | if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary), | 663 | if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary), |
@@ -620,6 +667,7 @@ void fs_download_stop() { | |||
620 | gtk_tree_model_get(GTK_TREE_MODEL(summary), | 667 | gtk_tree_model_get(GTK_TREE_MODEL(summary), |
621 | &iter, | 668 | &iter, |
622 | DOWNLOAD_URI, &u, | 669 | DOWNLOAD_URI, &u, |
670 | DOWNLOAD_DIRPATH, &dirPath, | ||
623 | -1); | 671 | -1); |
624 | gtk_tree_store_set(summary, | 672 | gtk_tree_store_set(summary, |
625 | &iter, | 673 | &iter, |
@@ -627,6 +675,7 @@ void fs_download_stop() { | |||
627 | -1); | 675 | -1); |
628 | if (u != NULL) | 676 | if (u != NULL) |
629 | ECRS_freeUri(u); | 677 | ECRS_freeUri(u); |
678 | FREENONNULL(dirPath); | ||
630 | } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary), | 679 | } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary), |
631 | &iter)); | 680 | &iter)); |
632 | while (head != NULL) { | 681 | while (head != NULL) { |
diff --git a/src/plugins/fs/fs.h b/src/plugins/fs/fs.h index b995af32..08896d51 100644 --- a/src/plugins/fs/fs.h +++ b/src/plugins/fs/fs.h | |||
@@ -65,6 +65,7 @@ enum { | |||
65 | DOWNLOAD_URISTRING, | 65 | DOWNLOAD_URISTRING, |
66 | DOWNLOAD_URI, | 66 | DOWNLOAD_URI, |
67 | DOWNLOAD_TREEPATH, | 67 | DOWNLOAD_TREEPATH, |
68 | DOWNLOAD_DIRPATH, | ||
68 | DOWNLOAD_NUM | 69 | DOWNLOAD_NUM |
69 | }; | 70 | }; |
70 | 71 | ||