diff options
Diffstat (limited to 'src/plugins/fs/search.c')
-rw-r--r-- | src/plugins/fs/search.c | 981 |
1 files changed, 58 insertions, 923 deletions
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index 63d7622c..f026d07e 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -22,12 +22,6 @@ | |||
22 | * @file src/plugins/fs/search.c | 22 | * @file src/plugins/fs/search.c |
23 | * @brief code for searching with gnunet-gtk | 23 | * @brief code for searching with gnunet-gtk |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * | ||
26 | * | ||
27 | * TODO: | ||
28 | * - figure out how to handle directories displayed on the | ||
29 | * search page (and how to communicate for downloads that | ||
30 | * they do or do not hang in the search page!) | ||
31 | */ | 25 | */ |
32 | 26 | ||
33 | #include "platform.h" | 27 | #include "platform.h" |
@@ -40,123 +34,6 @@ | |||
40 | #include <GNUnet/gnunet_util_crypto.h> | 34 | #include <GNUnet/gnunet_util_crypto.h> |
41 | #include <GNUnet/gnunet_namespace_lib.h> | 35 | #include <GNUnet/gnunet_namespace_lib.h> |
42 | 36 | ||
43 | |||
44 | /** | ||
45 | * @brief linked list of pages in the search notebook | ||
46 | */ | ||
47 | typedef struct SL { | ||
48 | struct SL * next; | ||
49 | /** | ||
50 | * Reference to the glade XML context that was | ||
51 | * used to create the search page. | ||
52 | */ | ||
53 | GladeXML * searchXML; | ||
54 | |||
55 | /** | ||
56 | * Reference to the glade XML context that was | ||
57 | * used to create the search label. | ||
58 | */ | ||
59 | GladeXML * labelXML; | ||
60 | |||
61 | /** | ||
62 | * Tree view widget that is used to display the | ||
63 | * search results. | ||
64 | */ | ||
65 | GtkTreeView * treeview; | ||
66 | |||
67 | /** | ||
68 | * Model of the tree view. | ||
69 | */ | ||
70 | GtkTreeStore * tree; | ||
71 | |||
72 | /** | ||
73 | * The label used in the notebook page. | ||
74 | */ | ||
75 | GtkLabel * tab_label; | ||
76 | |||
77 | /** | ||
78 | * The notebook page that is associated with this | ||
79 | * search. | ||
80 | */ | ||
81 | GtkWidget * searchpage; | ||
82 | |||
83 | /** | ||
84 | * Path to the entry in the summary list | ||
85 | * for this search. | ||
86 | */ | ||
87 | GtkTreeRowReference * summaryViewRowReference; | ||
88 | |||
89 | /** | ||
90 | * URI for this search. | ||
91 | */ | ||
92 | struct ECRS_URI * uri; | ||
93 | |||
94 | /** | ||
95 | * String describing the search. | ||
96 | */ | ||
97 | char * searchString; | ||
98 | |||
99 | /** | ||
100 | * Number of results received so far. | ||
101 | */ | ||
102 | unsigned int resultsReceived; | ||
103 | |||
104 | /** | ||
105 | * FSUI search handle. | ||
106 | */ | ||
107 | struct FSUI_SearchList * fsui_list; | ||
108 | } SearchList; | ||
109 | |||
110 | typedef struct DL { | ||
111 | struct DL * next; | ||
112 | |||
113 | /** | ||
114 | * URI of the download. | ||
115 | */ | ||
116 | struct ECRS_URI * uri; | ||
117 | |||
118 | /** | ||
119 | * Where is the download being saved to? | ||
120 | */ | ||
121 | char * filename; | ||
122 | |||
123 | /** | ||
124 | * Path in the summary view for this download. | ||
125 | */ | ||
126 | GtkTreeRowReference * summaryViewRowReference; | ||
127 | |||
128 | /** | ||
129 | * Search that this download belongs to. | ||
130 | * Maybe NULL. | ||
131 | */ | ||
132 | struct SL * searchList; | ||
133 | |||
134 | /** | ||
135 | * Path in the search view that this | ||
136 | * download is represented by. Maybe NULL | ||
137 | * if search has been closed or if download | ||
138 | * was initiated from URI without search. | ||
139 | */ | ||
140 | GtkTreeRowReference * searchViewRowReference; | ||
141 | |||
142 | /** | ||
143 | * FSUI reference for the download. | ||
144 | */ | ||
145 | struct FSUI_DownloadList * fsui_list; | ||
146 | } DownloadList; | ||
147 | |||
148 | static SearchList * search_head; | ||
149 | |||
150 | static DownloadList * download_head; | ||
151 | |||
152 | static GtkListStore * search_summary; | ||
153 | |||
154 | static GtkTreeStore * download_summary; | ||
155 | |||
156 | static struct GE_Context * ectx; | ||
157 | |||
158 | static struct GC_Configuration * cfg; | ||
159 | |||
160 | /** | 37 | /** |
161 | * The user has clicked the "SEARCH" button. | 38 | * The user has clicked the "SEARCH" button. |
162 | * Initiate a search. | 39 | * Initiate a search. |
@@ -301,7 +178,7 @@ void on_closeSearchButton_clicked_fs(GtkWidget * searchPage, | |||
301 | list = search_head; | 178 | list = search_head; |
302 | while (list != NULL) { | 179 | while (list != NULL) { |
303 | if ( (list->searchpage == searchPage) || | 180 | if ( (list->searchpage == searchPage) || |
304 | (list->tab_label == searchPage) ) | 181 | (list->tab_label == searchPage) ) |
305 | break; | 182 | break; |
306 | list = list->next; | 183 | list = list->next; |
307 | } | 184 | } |
@@ -332,7 +209,7 @@ static void stopSearch(GtkTreeModel * model, | |||
332 | GtkTreePath * path, | 209 | GtkTreePath * path, |
333 | GtkTreeIter * iter, | 210 | GtkTreeIter * iter, |
334 | gpointer unused) { | 211 | gpointer unused) { |
335 | struct SL * s; | 212 | SearchList * s; |
336 | 213 | ||
337 | s = NULL; | 214 | s = NULL; |
338 | gtk_tree_model_get(model, | 215 | gtk_tree_model_get(model, |
@@ -362,7 +239,7 @@ static void abortSearch(GtkTreeModel * model, | |||
362 | GtkTreePath * path, | 239 | GtkTreePath * path, |
363 | GtkTreeIter * iter, | 240 | GtkTreeIter * iter, |
364 | gpointer unused) { | 241 | gpointer unused) { |
365 | struct SL * s; | 242 | SearchList * s; |
366 | 243 | ||
367 | s = NULL; | 244 | s = NULL; |
368 | gtk_tree_model_get(model, | 245 | gtk_tree_model_get(model, |
@@ -392,11 +269,11 @@ void on_abortSearchSummaryButton_clicked_fs(GtkWidget * treeview, | |||
392 | * Update the number of results received for the given | 269 | * Update the number of results received for the given |
393 | * search in the summary and in the label of the tab. | 270 | * search in the summary and in the label of the tab. |
394 | */ | 271 | */ |
395 | static void updateSearchSummary(struct SL * searchContext) { | 272 | static void updateSearchSummary(SearchList * searchContext) { |
396 | GtkTreePath * path; | 273 | GtkTreePath * path; |
397 | GtkTreeIter iter; | 274 | GtkTreeIter iter; |
398 | char * new_title; | 275 | char * new_title; |
399 | GtkWidget * label; | 276 | GtkLabel * label; |
400 | 277 | ||
401 | path = gtk_tree_row_reference_get_path(searchContext->summaryViewRowReference); | 278 | path = gtk_tree_row_reference_get_path(searchContext->summaryViewRowReference); |
402 | if (TRUE != gtk_tree_model_get_iter(GTK_TREE_MODEL(search_summary), | 279 | if (TRUE != gtk_tree_model_get_iter(GTK_TREE_MODEL(search_summary), |
@@ -418,45 +295,35 @@ static void updateSearchSummary(struct SL * searchContext) { | |||
418 | g_strdup_printf("%s (%u)", | 295 | g_strdup_printf("%s (%u)", |
419 | searchContext->searchString, | 296 | searchContext->searchString, |
420 | searchContext->resultsReceived); | 297 | searchContext->resultsReceived); |
421 | label = glade_xml_get_widget(searchContext->labelXML, | 298 | label = GTK_LABEL(glade_xml_get_widget(searchContext->labelXML, |
422 | "searchTabLabel"); | 299 | "searchTabLabel")); |
423 | gtk_label_set(label, new_title); | 300 | gtk_label_set(label, new_title); |
424 | FREE(new_title); | 301 | FREE(new_title); |
425 | } | 302 | } |
426 | 303 | ||
427 | /** | 304 | /** |
428 | * Add the given result to the model (search result | 305 | * Add the given search result to the search |
429 | * list). | 306 | * tree at the specified position. |
430 | * | ||
431 | * @param info the information to add to the model | ||
432 | * @param uri the search URI | ||
433 | * @param searchContext identifies the search page | ||
434 | */ | 307 | */ |
435 | void fs_search_result_received(struct SL * searchContext, | 308 | void addEntryToSearchTree(SearchList * searchContext, |
436 | const ECRS_FileInfo * info, | 309 | DownloadList * downloadParent, |
437 | const struct ECRS_URI * uri) { | 310 | const ECRS_FileInfo * info, |
311 | GtkTreeIter * iter) { | ||
438 | char * name; | 312 | char * name; |
439 | char * mime; | 313 | char * mime; |
440 | char * desc; | 314 | char * desc; |
441 | unsigned long long size; | 315 | unsigned long long size; |
442 | char * size_h; | 316 | char * size_h; |
443 | GtkTreeStore * model; | 317 | GdkPixbuf * pixbuf; |
444 | GtkTreeIter iter; | ||
445 | 318 | ||
446 | mime = getMimeTypeFromMetaData(info->meta); | 319 | mime = getMimeTypeFromMetaData(info->meta); |
447 | desc = getDescriptionFromMetaData(info->meta); | 320 | desc = getDescriptionFromMetaData(info->meta); |
448 | name = getFileNameFromMetaData(info->meta); | 321 | name = getFileNameFromMetaData(info->meta); |
449 | size = ECRS_isFileUri(info->uri) ? ECRS_fileSize(info->uri) : 0 | 322 | size = ECRS_isFileUri(info->uri) ? ECRS_fileSize(info->uri) : 0; |
450 | pixbuf = getThumbnailFromMetaData(info->meta); | 323 | pixbuf = getThumbnailFromMetaData(info->meta); |
451 | size_h = string_get_fancy_byte_size(size); | 324 | size_h = string_get_fancy_byte_size(size); |
452 | model = GTK_TREE_STORE | 325 | gtk_tree_store_set(searchContext->tree, |
453 | (gtk_tree_view_get_model | 326 | iter, |
454 | (GTK_TREE_VIEW(searchContext->treeview))); | ||
455 | gtk_tree_store_append(model, | ||
456 | &iter, | ||
457 | NULL); | ||
458 | gtk_tree_store_set(model, | ||
459 | &iter, | ||
460 | SEARCH_NAME, name, | 327 | SEARCH_NAME, name, |
461 | SEARCH_SIZE, size, | 328 | SEARCH_SIZE, size, |
462 | SEARCH_HSIZE, size_h, | 329 | SEARCH_HSIZE, size_h, |
@@ -466,12 +333,36 @@ void fs_search_result_received(struct SL * searchContext, | |||
466 | SEARCH_URI, ECRS_dupUri(info->uri), | 333 | SEARCH_URI, ECRS_dupUri(info->uri), |
467 | SEARCH_META, ECRS_dupMetaData(info->meta), | 334 | SEARCH_META, ECRS_dupMetaData(info->meta), |
468 | SEARCH_INTERNAL, searchContext, | 335 | SEARCH_INTERNAL, searchContext, |
336 | SEARCH_INTERNAL_PARENT, downloadParent, | ||
469 | -1); | 337 | -1); |
470 | FREE(size_h); | 338 | FREE(size_h); |
471 | FREE(name); | 339 | FREE(name); |
472 | FREE(desc); | 340 | FREE(desc); |
473 | FREE(mime); | 341 | FREE(mime); |
474 | /* UNREF pixbuf? */ | 342 | } |
343 | |||
344 | /** | ||
345 | * Add the given result to the model (search result | ||
346 | * list). | ||
347 | * | ||
348 | * @param info the information to add to the model | ||
349 | * @param uri the search URI | ||
350 | * @param searchContext identifies the search page | ||
351 | */ | ||
352 | void fs_search_result_received(SearchList * searchContext, | ||
353 | const ECRS_FileInfo * info, | ||
354 | const struct ECRS_URI * uri) { | ||
355 | GtkTreeStore * model; | ||
356 | GtkTreeIter iter; | ||
357 | |||
358 | model = GTK_TREE_STORE(gtk_tree_view_get_model(searchContext->treeview)); | ||
359 | gtk_tree_store_append(model, | ||
360 | &iter, | ||
361 | NULL); | ||
362 | addEntryToSearchTree(searchContext, | ||
363 | NULL, | ||
364 | info, | ||
365 | &iter); | ||
475 | searchContext->resultsReceived++; | 366 | searchContext->resultsReceived++; |
476 | updateSearchSummary(searchContext); | 367 | updateSearchSummary(searchContext); |
477 | } | 368 | } |
@@ -480,23 +371,23 @@ void fs_search_result_received(struct SL * searchContext, | |||
480 | * FSUI event: a search was started; create the | 371 | * FSUI event: a search was started; create the |
481 | * tab and add an entry to the summary. | 372 | * tab and add an entry to the summary. |
482 | */ | 373 | */ |
483 | struct SL * | 374 | SearchList * |
484 | fs_search_started(struct FSUI_SearchList * fsui_list, | 375 | fs_search_started(struct FSUI_SearchList * fsui_list, |
485 | const struct ECRS_URI * uri, | 376 | const struct ECRS_URI * uri, |
486 | unsigned int anonymityLevel, | 377 | unsigned int anonymityLevel, |
487 | unsigned int resultCount, | 378 | unsigned int resultCount, |
488 | const ECRS_FileInfo * results) { | 379 | const ECRS_FileInfo * results) { |
489 | struct SL * list; | 380 | SearchList * list; |
490 | gint pages; | 381 | gint pages; |
491 | char * description; | 382 | char * description; |
492 | const char * dhead; | 383 | const char * dhead; |
493 | GtkContainer * window; | ||
494 | GtkTreeViewColumn * column; | 384 | GtkTreeViewColumn * column; |
495 | GtkCellRenderer * renderer; | 385 | GtkCellRenderer * renderer; |
496 | int col; | ||
497 | GtkNotebook * notebook; | 386 | GtkNotebook * notebook; |
498 | GtkTreePath * path; | 387 | GtkTreePath * path; |
499 | GtkTreeIter iter; | 388 | GtkTreeIter iter; |
389 | int col; | ||
390 | int i; | ||
500 | 391 | ||
501 | description = ECRS_uriToString(uri); | 392 | description = ECRS_uriToString(uri); |
502 | if (description == NULL) { | 393 | if (description == NULL) { |
@@ -515,10 +406,10 @@ fs_search_started(struct FSUI_SearchList * fsui_list, | |||
515 | strlen(ECRS_SUBSPACE_INFIX))) | 406 | strlen(ECRS_SUBSPACE_INFIX))) |
516 | dhead = &dhead[strlen(ECRS_SUBSPACE_INFIX)]; | 407 | dhead = &dhead[strlen(ECRS_SUBSPACE_INFIX)]; |
517 | list | 408 | list |
518 | = MALLOC(sizeof(struct SL)); | 409 | = MALLOC(sizeof(SearchList)); |
519 | memset(list, | 410 | memset(list, |
520 | 0, | 411 | 0, |
521 | sizeof(struct SL)); | 412 | sizeof(SearchList)); |
522 | list->searchString | 413 | list->searchString |
523 | = STRDUP(dhead); | 414 | = STRDUP(dhead); |
524 | FREE(description); | 415 | FREE(description); |
@@ -551,7 +442,8 @@ fs_search_started(struct FSUI_SearchList * fsui_list, | |||
551 | GDK_TYPE_PIXBUF, /* preview */ | 442 | GDK_TYPE_PIXBUF, /* preview */ |
552 | G_TYPE_POINTER, /* url */ | 443 | G_TYPE_POINTER, /* url */ |
553 | G_TYPE_POINTER, /* meta */ | 444 | G_TYPE_POINTER, /* meta */ |
554 | G_TYPE_POINTER); /* internal: download info/NULL */ | 445 | G_TYPE_POINTER, /* internal: search list */ |
446 | G_TYPE_POINTER); /* internal: download parent list */ | ||
555 | 447 | ||
556 | gtk_tree_view_set_model(list->treeview, | 448 | gtk_tree_view_set_model(list->treeview, |
557 | GTK_TREE_MODEL(list->tree)); | 449 | GTK_TREE_MODEL(list->tree)); |
@@ -721,13 +613,12 @@ static void freeIterSubtree(GtkTreeModel * tree, | |||
721 | */ | 613 | */ |
722 | void fs_search_stopped(SearchList * list) { | 614 | void fs_search_stopped(SearchList * list) { |
723 | GtkNotebook * notebook; | 615 | GtkNotebook * notebook; |
724 | int index; | ||
725 | int i; | ||
726 | GtkTreeIter iter; | 616 | GtkTreeIter iter; |
727 | struct ECRS_URI * euri; | ||
728 | SearchList * prev; | 617 | SearchList * prev; |
729 | DownloadList * downloads; | 618 | DownloadList * downloads; |
730 | GtkTreePath * path; | 619 | GtkTreePath * path; |
620 | int index; | ||
621 | int i; | ||
731 | 622 | ||
732 | /* remove from linked list */ | 623 | /* remove from linked list */ |
733 | if (search_head == list) { | 624 | if (search_head == list) { |
@@ -742,10 +633,10 @@ void fs_search_stopped(SearchList * list) { | |||
742 | /* remove links from download views */ | 633 | /* remove links from download views */ |
743 | downloads = download_head; | 634 | downloads = download_head; |
744 | while (downloads != NULL) { | 635 | while (downloads != NULL) { |
745 | if (download->searchList == list) { | 636 | if (downloads->searchList == list) { |
746 | gtk_tree_row_reference_free(download->searchViewRowReference); | 637 | gtk_tree_row_reference_free(downloads->searchViewRowReference); |
747 | download->searchViewRowReference = NULL; | 638 | downloads->searchViewRowReference = NULL; |
748 | download->searchList = NULL; | 639 | downloads->searchList = NULL; |
749 | } | 640 | } |
750 | downloads = downloads->next; | 641 | downloads = downloads->next; |
751 | } | 642 | } |
@@ -764,9 +655,9 @@ void fs_search_stopped(SearchList * list) { | |||
764 | index); | 655 | index); |
765 | 656 | ||
766 | /* recursively free search model */ | 657 | /* recursively free search model */ |
767 | if (gtk_tree_model_get_iter_first(list->model, | 658 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list->tree), |
768 | &iter)) | 659 | &iter)) |
769 | freeIterSubtree(list->model, | 660 | freeIterSubtree(GTK_TREE_MODEL(list->tree), |
770 | &iter); | 661 | &iter); |
771 | 662 | ||
772 | /* destroy entry in summary */ | 663 | /* destroy entry in summary */ |
@@ -788,760 +679,4 @@ void fs_search_stopped(SearchList * list) { | |||
788 | } | 679 | } |
789 | 680 | ||
790 | 681 | ||
791 | |||
792 | |||
793 | |||
794 | |||
795 | |||
796 | |||
797 | #if 0 | ||
798 | static int addFilesToDirectory | ||
799 | (const ECRS_FileInfo * fi, | ||
800 | const HashCode512 * key, | ||
801 | int isRoot, | ||
802 | void * closure) { | ||
803 | struct ECRS_URI * uri = closure; | ||
804 | DownloadList * pos; | ||
805 | GtkTreeIter iter; | ||
806 | GtkTreeIter child; | ||
807 | int i; | ||
808 | GtkTreePath * path; | ||
809 | |||
810 | if (isRoot == YES) | ||
811 | return OK; | ||
812 | DEBUG_BEGIN(); | ||
813 | pos = download_head; | ||
814 | while (pos != NULL) { | ||
815 | if (ECRS_equalsUri(uri, | ||
816 | pos->uri)) | ||
817 | break; | ||
818 | pos = pos->next; | ||
819 | } | ||
820 | if (pos != NULL) { | ||
821 | if (! gtk_tree_row_reference_valid(pos->rr)) | ||
822 | return SYSERR; | ||
823 | path = gtk_tree_row_reference_get_path(pos->rr); | ||
824 | gtk_tree_model_get_iter(GTK_TREE_MODEL(pos->model), | ||
825 | &iter, | ||
826 | path); | ||
827 | gtk_tree_path_free(path); | ||
828 | for (i=gtk_tree_model_iter_n_children(pos->model, | ||
829 | &iter)-1;i>=0;i--) { | ||
830 | if (TRUE == gtk_tree_model_iter_nth_child(pos->model, | ||
831 | &child, | ||
832 | &iter, | ||
833 | i)) { | ||
834 | struct ECRS_URI * uri; | ||
835 | uri = NULL; | ||
836 | gtk_tree_model_get(pos->model, | ||
837 | &child, | ||
838 | SEARCH_URI, &uri, | ||
839 | -1); | ||
840 | if ( (uri != NULL) && | ||
841 | (ECRS_equalsUri(uri, | ||
842 | fi->uri)) ) | ||
843 | return OK; | ||
844 | } | ||
845 | } | ||
846 | gtk_tree_store_append(GTK_TREE_STORE(pos->model), | ||
847 | &child, | ||
848 | &iter); | ||
849 | addEntryToSearchTree(GTK_TREE_STORE(pos->model), | ||
850 | &child, | ||
851 | fi->uri, | ||
852 | fi->meta); | ||
853 | } | ||
854 | DEBUG_END(); | ||
855 | return OK; | ||
856 | } | ||
857 | #endif | ||
858 | |||
859 | |||
860 | /** | ||
861 | * A download has been started. Add an entry | ||
862 | * to the search tree view (if applicable) and | ||
863 | * the download summary. | ||
864 | */ | ||
865 | struct DL * | ||
866 | fs_download_started(struct FSUI_DownloadList * fsui_dl, | ||
867 | struct DL * dl_parent, | ||
868 | struct SL * sl_parent, | ||
869 | unsigned long long total, | ||
870 | unsigned int anonymityLevel, | ||
871 | const ECRS_FileInfo * fi, | ||
872 | const char * filename, | ||
873 | unsigned long long completed, | ||
874 | cron_t eta) { | ||
875 | DownloadList * list; | ||
876 | GtkTreeIter iiter; | ||
877 | unsigned long long size; | ||
878 | char * size_h; | ||
879 | const char * sname; | ||
880 | int progress; | ||
881 | char * uri_name; | ||
882 | |||
883 | /* setup visualization */ | ||
884 | list = MALLOC(sizeof(DownloadList)); | ||
885 | list->fsui_list = fsui_dl; | ||
886 | list->rr = NULL; | ||
887 | list->model = NULL; | ||
888 | #if 0 | ||
889 | if (YES == ECRS_isDirectory(fi->meta)) { | ||
890 | list->rr = gtk_tree_row_reference_new(model, path); | ||
891 | list->model = model; | ||
892 | } | ||
893 | #endif | ||
894 | list->uri = ECRS_dupUri(fi->uri); | ||
895 | list->filename = STRDUP(filename); | ||
896 | size = ECRS_fileSize(fi->uri); | ||
897 | size_h = string_get_fancy_byte_size(size); | ||
898 | sname = &filename[strlen(filename)-1]; | ||
899 | while ( (sname > filename) && | ||
900 | (sname[-1] != '/') && | ||
901 | (sname[-1] != '\\') ) | ||
902 | sname--; | ||
903 | if (size != 0) | ||
904 | progress = completed * 100 / size; | ||
905 | else | ||
906 | progress = 100; | ||
907 | uri_name = ECRS_uriToString(fi->uri); | ||
908 | gtk_tree_store_append(download_summary, | ||
909 | &iiter, | ||
910 | NULL); | ||
911 | gtk_tree_store_set(download_summary, | ||
912 | &iiter, | ||
913 | DOWNLOAD_FILENAME, filename, | ||
914 | DOWNLOAD_SHORTNAME, sname, | ||
915 | DOWNLOAD_SIZE, size, | ||
916 | DOWNLOAD_HSIZE, size_h, | ||
917 | DOWNLOAD_PROGRESS, progress, | ||
918 | DOWNLOAD_URISTRING, uri_name, | ||
919 | DOWNLOAD_URI, ECRS_dupUri(fi->uri), | ||
920 | DOWNLOAD_TREEPATH, list->rr, /* internal: row reference! */ | ||
921 | DOWNLOAD_POS, list, | ||
922 | -1); | ||
923 | FREE(uri_name); | ||
924 | FREE(size_h); | ||
925 | list->next = download_head; | ||
926 | download_head = list; | ||
927 | DEBUG_END(); | ||
928 | return list; | ||
929 | } | ||
930 | |||
931 | |||
932 | |||
933 | |||
934 | static void initiateDownload(GtkTreeModel * model, | ||
935 | GtkTreePath * path, | ||
936 | GtkTreeIter * iter, | ||
937 | gpointer unused) { | ||
938 | char * uri_name; | ||
939 | char * final_download_dir; | ||
940 | GtkTreeIter iiter; | ||
941 | GtkWidget * spin; | ||
942 | const char * oname; | ||
943 | const char * cname; | ||
944 | char * dname; | ||
945 | GtkTreePath *dirTreePath; | ||
946 | char *dirPath; | ||
947 | unsigned int dirPathLen; | ||
948 | struct ECRS_URI * idc_uri; | ||
949 | struct ECRS_MetaData * idc_meta; | ||
950 | const char * idc_name; | ||
951 | const char * idc_mime; | ||
952 | char * idc_final_download_destination; | ||
953 | unsigned int idc_anon; | ||
954 | struct SL * searchContext; | ||
955 | |||
956 | #ifdef WINDOWS | ||
957 | char *filehash = NULL; | ||
958 | #endif | ||
959 | |||
960 | DEBUG_BEGIN(); | ||
961 | idc_uri = NULL; | ||
962 | idc_meta = NULL; | ||
963 | idc_name = NULL; | ||
964 | idc_mime = NULL; | ||
965 | gtk_tree_model_get(model, | ||
966 | iter, | ||
967 | SEARCH_NAME, &idc_name, | ||
968 | SEARCH_URI, &idc_uri, | ||
969 | SEARCH_META, &idc_meta, | ||
970 | SEARCH_MIME, &idc_mime, | ||
971 | SEARCH_INTERNAL, &searchContext, | ||
972 | -1); | ||
973 | if (idc_uri == NULL) { | ||
974 | GE_BREAK(ectx, 0); | ||
975 | return; | ||
976 | } | ||
977 | |||
978 | spin = searchContext->anonymityButton; | ||
979 | if (spin == NULL) { | ||
980 | GE_BREAK(ectx, 0); | ||
981 | idc_anon = 1; | ||
982 | } else { | ||
983 | idc_anon = gtk_spin_button_get_value_as_int | ||
984 | (GTK_SPIN_BUTTON(spin)); | ||
985 | } | ||
986 | if (! ECRS_isFileUri(idc_uri)) { | ||
987 | if (ECRS_isNamespaceUri(idc_uri)) { | ||
988 | /* start namespace search; would probably be better | ||
989 | to add this as a subtree, but for simplicity | ||
990 | we'll just add it as a new tab for now */ | ||
991 | FSUI_startSearch(ctx, | ||
992 | idc_anon, | ||
993 | 1000, /* FIXME: max results */ | ||
994 | 99 * cronYEARS, /* fixme: timeout */ | ||
995 | idc_uri); | ||
996 | return; | ||
997 | } else { | ||
998 | GE_BREAK(ectx, 0); /* unsupported URI type (i.e. ksk or loc) */ | ||
999 | return; | ||
1000 | } | ||
1001 | } | ||
1002 | |||
1003 | uri_name = ECRS_uriToString(idc_uri); | ||
1004 | if ( (uri_name == NULL) || | ||
1005 | (strlen(uri_name) < | ||
1006 | strlen(ECRS_URI_PREFIX) + | ||
1007 | strlen(ECRS_FILE_INFIX)) ) { | ||
1008 | GE_BREAK(ectx, 0); | ||
1009 | FREENONNULL(uri_name); | ||
1010 | return; | ||
1011 | } | ||
1012 | |||
1013 | if (idc_name == NULL) { | ||
1014 | #ifdef WINDOWS | ||
1015 | filehash = STRDUP(uri_name); | ||
1016 | filehash[16] = 0; | ||
1017 | idc_name = filehash; | ||
1018 | #else | ||
1019 | idc_name = uri_name; | ||
1020 | #endif | ||
1021 | } | ||
1022 | |||
1023 | cname = idc_name; | ||
1024 | oname = idc_name; | ||
1025 | dname = MALLOC(strlen(idc_name)+1); | ||
1026 | dname[0] = '\0'; | ||
1027 | while (*idc_name != '\0') { | ||
1028 | if ( (*idc_name == DIR_SEPARATOR) && | ||
1029 | (idc_name[1] != '\0') ) { | ||
1030 | memcpy(dname, oname, idc_name - oname); | ||
1031 | dname[idc_name - oname] = '\0'; | ||
1032 | cname = &idc_name[1]; | ||
1033 | } | ||
1034 | idc_name++; | ||
1035 | } | ||
1036 | if (*cname == '\0') /* name ended in '/' - likely directory */ | ||
1037 | cname = oname; | ||
1038 | idc_name = cname; | ||
1039 | GC_get_configuration_value_filename(cfg, | ||
1040 | "FS", | ||
1041 | "INCOMINGDIR", | ||
1042 | "$HOME/gnunet-downloads/", | ||
1043 | &final_download_dir); | ||
1044 | if (strlen(dname) > 0) { | ||
1045 | char * tmp; | ||
1046 | tmp = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); | ||
1047 | strcpy(tmp, final_download_dir); | ||
1048 | if (tmp[strlen(tmp)] != DIR_SEPARATOR) | ||
1049 | strcat(tmp, DIR_SEPARATOR_STR); | ||
1050 | if (dname[0] == DIR_SEPARATOR) | ||
1051 | strcat(tmp, &dname[1]); | ||
1052 | else | ||
1053 | strcat(tmp, dname); | ||
1054 | FREE(final_download_dir); | ||
1055 | final_download_dir = tmp; | ||
1056 | } | ||
1057 | FREE(dname); | ||
1058 | disk_directory_create(ectx, final_download_dir); | ||
1059 | |||
1060 | |||
1061 | /* If file is inside a directory, get the full path */ | ||
1062 | dirTreePath = gtk_tree_path_copy(path); | ||
1063 | dirPath = MALLOC(1); | ||
1064 | dirPath[0] = '\0'; | ||
1065 | dirPathLen = 0; | ||
1066 | while (gtk_tree_path_get_depth(dirTreePath) > 1) { | ||
1067 | const char * dirname; | ||
1068 | char * new; | ||
1069 | |||
1070 | if (! gtk_tree_path_up(dirTreePath)) | ||
1071 | break; | ||
1072 | |||
1073 | if (!gtk_tree_model_get_iter(model, | ||
1074 | &iiter, | ||
1075 | dirTreePath)) | ||
1076 | break; | ||
1077 | gtk_tree_model_get(model, | ||
1078 | &iiter, | ||
1079 | SEARCH_NAME, &dirname, | ||
1080 | -1); | ||
1081 | dirPathLen = strlen(dirPath) + strlen(dirname) + strlen(DIR_SEPARATOR_STR) + 1; | ||
1082 | new = MALLOC(dirPathLen + 1); | ||
1083 | strcpy(new, dirname); | ||
1084 | if (new[strlen(new)-1] != DIR_SEPARATOR) | ||
1085 | strcat(new, DIR_SEPARATOR_STR); | ||
1086 | strcat(new, dirPath); | ||
1087 | FREE(dirPath); | ||
1088 | dirPath = new; | ||
1089 | } | ||
1090 | gtk_tree_path_free(dirTreePath); | ||
1091 | |||
1092 | |||
1093 | /* construct completed/directory/real-filename */ | ||
1094 | idc_final_download_destination = MALLOC(strlen(final_download_dir) + 2 + | ||
1095 | strlen(idc_name) + strlen(GNUNET_DIRECTORY_EXT) + | ||
1096 | strlen(dirPath)); | ||
1097 | strcpy(idc_final_download_destination, final_download_dir); | ||
1098 | if (idc_final_download_destination[strlen(idc_final_download_destination)-1] != DIR_SEPARATOR) | ||
1099 | strcat(idc_final_download_destination, | ||
1100 | DIR_SEPARATOR_STR); | ||
1101 | strcat(idc_final_download_destination, dirPath); | ||
1102 | disk_directory_create(ectx, | ||
1103 | idc_final_download_destination); | ||
1104 | strcat(idc_final_download_destination, idc_name); | ||
1105 | if ( (idc_final_download_destination[strlen(idc_final_download_destination) - 1] == '/') || | ||
1106 | (idc_final_download_destination[strlen(idc_final_download_destination) - 1] == '\\') ) | ||
1107 | idc_final_download_destination[strlen(idc_final_download_destination) - 1] = '\0'; | ||
1108 | /* append ".gnd" if needed (== directory and .gnd not present) */ | ||
1109 | if ( (idc_mime != NULL) && | ||
1110 | (0 == strcmp(idc_mime, GNUNET_DIRECTORY_MIME)) && | ||
1111 | ( (strlen(idc_final_download_destination) < strlen(GNUNET_DIRECTORY_EXT)) || | ||
1112 | (0 != strcmp(&idc_final_download_destination[strlen(idc_final_download_destination) | ||
1113 | - strlen(GNUNET_DIRECTORY_EXT)], | ||
1114 | GNUNET_DIRECTORY_EXT)) ) ) | ||
1115 | strcat(idc_final_download_destination, GNUNET_DIRECTORY_EXT); | ||
1116 | |||
1117 | addLogEntry(_("Downloading `%s'"), idc_name); | ||
1118 | FSUI_startDownload(ctx, | ||
1119 | idc_anon, | ||
1120 | NO, /* FIXME: isRecursive */ | ||
1121 | idc_uri, | ||
1122 | idc_meta, | ||
1123 | idc_final_download_destination, | ||
1124 | NULL, | ||
1125 | NULL); | ||
1126 | FREE(uri_name); | ||
1127 | FREE(dirPath); | ||
1128 | FREENONNULL(final_download_dir); | ||
1129 | #ifdef WINDOWS | ||
1130 | FREENONNULL(filehash); | ||
1131 | #endif | ||
1132 | } | ||
1133 | |||
1134 | void on_downloadButton_clicked_fs(GtkWidget * treeview, | ||
1135 | GtkWidget * downloadButton) { | ||
1136 | GtkTreeSelection * selection; | ||
1137 | |||
1138 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | ||
1139 | gtk_tree_selection_selected_foreach | ||
1140 | (selection, | ||
1141 | &initiateDownload, | ||
1142 | NULL); | ||
1143 | } | ||
1144 | |||
1145 | |||
1146 | void on_statusDownloadURIEntry_editing_done_fs(GtkWidget * entry, | ||
1147 | GtkWidget * downloadButton) { | ||
1148 | struct ECRS_URI * idc_uri; | ||
1149 | struct ECRS_MetaData * idc_meta; | ||
1150 | char * idc_final_download_destination; | ||
1151 | unsigned int idc_anon; | ||
1152 | const char * uris; | ||
1153 | char * urid; | ||
1154 | GtkWidget * spin; | ||
1155 | char * final_download_dir; | ||
1156 | const char * dname; | ||
1157 | |||
1158 | uris = gtk_entry_get_text(GTK_ENTRY(entry)); | ||
1159 | urid = STRDUP(uris); | ||
1160 | gtk_entry_set_text(GTK_ENTRY(entry), | ||
1161 | ECRS_URI_PREFIX); | ||
1162 | idc_uri = ECRS_stringToUri(ectx, urid); | ||
1163 | if (idc_uri == NULL) { | ||
1164 | addLogEntry(_("Invalid URI `%s'"), urid); | ||
1165 | FREE(urid); | ||
1166 | return; | ||
1167 | } | ||
1168 | if (ECRS_isKeywordUri(idc_uri)) { | ||
1169 | addLogEntry(_("Please use the search function for keyword (KSK) URIs!")); | ||
1170 | FREE(urid); | ||
1171 | ECRS_freeUri(idc_uri); | ||
1172 | return; | ||
1173 | } else if (ECRS_isLocationUri(idc_uri)) { | ||
1174 | addLogEntry(_("Location URIs are not yet supported")); | ||
1175 | FREE(urid); | ||
1176 | ECRS_freeUri(idc_uri); | ||
1177 | return; | ||
1178 | } | ||
1179 | GC_get_configuration_value_filename(cfg, | ||
1180 | "FS", | ||
1181 | "INCOMINGDIR", | ||
1182 | "$HOME/gnunet-downloads/", | ||
1183 | &final_download_dir); | ||
1184 | disk_directory_create(ectx, final_download_dir); | ||
1185 | dname = &uris[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]; | ||
1186 | idc_final_download_destination = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); | ||
1187 | strcpy(idc_final_download_destination, final_download_dir); | ||
1188 | FREE(final_download_dir); | ||
1189 | if (idc_final_download_destination[strlen(idc_final_download_destination)] != DIR_SEPARATOR) | ||
1190 | strcat(idc_final_download_destination, DIR_SEPARATOR_STR); | ||
1191 | strcat(idc_final_download_destination, dname); | ||
1192 | |||
1193 | /* get anonymity level */ | ||
1194 | spin = glade_xml_get_widget(getMainXML(), | ||
1195 | "fsstatusAnonymitySpin"); | ||
1196 | if (spin == NULL) { | ||
1197 | GE_BREAK(ectx, 0); | ||
1198 | idc_anon = 1; | ||
1199 | } else { | ||
1200 | idc_anon = gtk_spin_button_get_value_as_int | ||
1201 | (GTK_SPIN_BUTTON(spin)); | ||
1202 | } | ||
1203 | addLogEntry(_("Downloading `%s'"), uris); | ||
1204 | idc_meta = ECRS_createMetaData(); | ||
1205 | FSUI_startDownload(ctx, | ||
1206 | idc_anon, | ||
1207 | NO, /* FIXME: isRecursive */ | ||
1208 | idc_uri, | ||
1209 | idc_meta, | ||
1210 | idc_final_download_destination, | ||
1211 | NULL, | ||
1212 | NULL); | ||
1213 | ECRS_freeMetaData(idc_meta); | ||
1214 | FREE(urid); | ||
1215 | } | ||
1216 | |||
1217 | |||
1218 | void fs_download_update(struct DL * downloadContext, | ||
1219 | unsigned long long completed, | ||
1220 | const char * data, | ||
1221 | unsigned int size) { | ||
1222 | GtkTreeIter iter; | ||
1223 | unsigned int val; | ||
1224 | unsigned long long total; | ||
1225 | struct DL * p; | ||
1226 | |||
1227 | DEBUG_BEGIN(); | ||
1228 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(download_summary), | ||
1229 | &iter)) { | ||
1230 | do { | ||
1231 | gtk_tree_model_get(GTK_TREE_MODEL(download_summary), | ||
1232 | &iter, | ||
1233 | DOWNLOAD_SIZE, &total, | ||
1234 | DOWNLOAD_POS, &p, | ||
1235 | -1); | ||
1236 | if (p == downloadContext) { | ||
1237 | if (total != 0) | ||
1238 | val = completed * 100 / total; | ||
1239 | else | ||
1240 | val = 100; | ||
1241 | gtk_tree_store_set(download_summary, | ||
1242 | &iter, | ||
1243 | DOWNLOAD_PROGRESS, val, | ||
1244 | -1); | ||
1245 | break; | ||
1246 | } | ||
1247 | } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(download_summary), | ||
1248 | &iter)); | ||
1249 | } | ||
1250 | #if 0 | ||
1251 | meta = NULL; | ||
1252 | ECRS_listDirectory(ectx, | ||
1253 | data, | ||
1254 | size, | ||
1255 | &meta, | ||
1256 | &addFilesToDirectory, | ||
1257 | downloadContext->uri); | ||
1258 | if (meta != NULL) | ||
1259 | ECRS_freeMetaData(meta); | ||
1260 | #endif | ||
1261 | DEBUG_END(); | ||
1262 | } | ||
1263 | |||
1264 | void fs_download_completed(struct DL * downloadContext) { | ||
1265 | unsigned long long size; | ||
1266 | char * data; | ||
1267 | int fd; | ||
1268 | struct ECRS_MetaData * meta; | ||
1269 | |||
1270 | DEBUG_BEGIN(); | ||
1271 | GE_LOG(ectx, | ||
1272 | GE_STATUS | GE_USER | GE_BULK, | ||
1273 | _("Download '%s' complete.\n"), | ||
1274 | downloadContext->filename); | ||
1275 | /* Not available for resumed downloads */ | ||
1276 | if ( (downloadContext->rr != NULL) && | ||
1277 | (gtk_tree_row_reference_valid(downloadContext->rr)) ) { | ||
1278 | /* update directory view (if applicable!) */ | ||
1279 | if (OK == disk_file_size(ectx, | ||
1280 | downloadContext->filename, | ||
1281 | &size, | ||
1282 | YES)) { | ||
1283 | GE_LOG(ectx, | ||
1284 | GE_DEBUG, | ||
1285 | "Updating directory view of '%s'\n", | ||
1286 | downloadContext->filename); | ||
1287 | |||
1288 | meta = NULL; | ||
1289 | fd = disk_file_open(ectx, | ||
1290 | downloadContext->filename, | ||
1291 | O_RDONLY); | ||
1292 | if (fd != -1) { | ||
1293 | data = MMAP(NULL, | ||
1294 | size, | ||
1295 | PROT_READ, | ||
1296 | MAP_SHARED, | ||
1297 | fd, | ||
1298 | 0); | ||
1299 | if (data == MAP_FAILED) { | ||
1300 | GE_LOG_STRERROR_FILE(ectx, | ||
1301 | GE_ERROR | GE_ADMIN | GE_BULK, | ||
1302 | "mmap", | ||
1303 | downloadContext->filename); | ||
1304 | } else { | ||
1305 | #if 0 | ||
1306 | if (data != NULL) { | ||
1307 | ECRS_listDirectory(ectx, | ||
1308 | data, | ||
1309 | size, | ||
1310 | &meta, | ||
1311 | &addFilesToDirectory, | ||
1312 | downloadContext->uri); | ||
1313 | MUNMAP(data, size); | ||
1314 | } | ||
1315 | #endif | ||
1316 | } | ||
1317 | CLOSE(fd); | ||
1318 | } | ||
1319 | if (meta != NULL) | ||
1320 | ECRS_freeMetaData(meta); | ||
1321 | } | ||
1322 | } | ||
1323 | DEBUG_END(); | ||
1324 | } | ||
1325 | |||
1326 | void fs_download_stopped(struct DL * downloadContext) { | ||
1327 | GtkTreeIter iter; | ||
1328 | struct DL * d; | ||
1329 | |||
1330 | DEBUG_BEGIN(); | ||
1331 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(download_summary), | ||
1332 | &iter)) { | ||
1333 | do { | ||
1334 | gtk_tree_model_get(GTK_TREE_MODEL(download_summary), | ||
1335 | &iter, | ||
1336 | DOWNLOAD_POS, &d, | ||
1337 | -1); | ||
1338 | if (d == downloadContext) { | ||
1339 | gtk_tree_store_remove(download_summary, | ||
1340 | &iter); | ||
1341 | break; | ||
1342 | } | ||
1343 | } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(download_summary), | ||
1344 | &iter)); | ||
1345 | } | ||
1346 | DEBUG_END(); | ||
1347 | /* FIXME: free dl downloadContext! */ | ||
1348 | } | ||
1349 | |||
1350 | void on_clearCompletedDownloadsButton_clicked_fs(void * unused, | ||
1351 | GtkWidget * clearButton) { | ||
1352 | /* FIXME */ | ||
1353 | } | ||
1354 | |||
1355 | static void abortDownloadCallback(GtkTreeModel * model, | ||
1356 | GtkTreePath * path, | ||
1357 | GtkTreeIter * iter, | ||
1358 | gpointer unused) { | ||
1359 | struct DL * dl; | ||
1360 | |||
1361 | GE_ASSERT(ectx, model == GTK_TREE_MODEL(download_summary)); | ||
1362 | gtk_tree_model_get(model, | ||
1363 | iter, | ||
1364 | DOWNLOAD_POS, &dl, | ||
1365 | -1); | ||
1366 | FSUI_abortDownload(ctx, | ||
1367 | dl->fsui_list); | ||
1368 | } | ||
1369 | |||
1370 | void on_abortDownloadButton_clicked_fs(void * unused, | ||
1371 | GtkWidget * clearButton) { | ||
1372 | GtkTreeSelection * selection; | ||
1373 | GtkWidget * downloadList; | ||
1374 | |||
1375 | DEBUG_BEGIN(); | ||
1376 | downloadList = glade_xml_get_widget(getMainXML(), | ||
1377 | "activeDownloadsList"); | ||
1378 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(downloadList)); | ||
1379 | gtk_tree_selection_selected_foreach | ||
1380 | (selection, | ||
1381 | &abortDownloadCallback, | ||
1382 | NULL); | ||
1383 | DEBUG_END(); | ||
1384 | } | ||
1385 | |||
1386 | |||
1387 | |||
1388 | |||
1389 | |||
1390 | |||
1391 | |||
1392 | |||
1393 | |||
1394 | /* *************** startup/shutdown ****************** */ | ||
1395 | |||
1396 | /** | ||
1397 | * Setup the summary views (in particular the models | ||
1398 | * and the renderers). | ||
1399 | */ | ||
1400 | void fs_search_start(struct GE_Context * e, | ||
1401 | struct GC_Configuration * c) { | ||
1402 | GtkComboBoxEntry * searchCB; | ||
1403 | GtkTreeView * searchList; | ||
1404 | GtkTreeView * downloadList; | ||
1405 | GtkListStore * model; | ||
1406 | GtkCellRenderer * renderer; | ||
1407 | GtkTreeViewColumn * column; | ||
1408 | int col; | ||
1409 | |||
1410 | ectx = e; | ||
1411 | cfg = c; | ||
1412 | searchCB | ||
1413 | = GTK_COMBO_BOX_ENTRY(glade_xml_get_widget(getMainXML(), | ||
1414 | "fssearchKeywordComboBoxEntry")); | ||
1415 | |||
1416 | model = gtk_list_store_new(NS_SEARCH_NUM, | ||
1417 | G_TYPE_STRING, /* what we show */ | ||
1418 | G_TYPE_STRING, /* EncName of namespace */ | ||
1419 | G_TYPE_POINTER, /* ECRS MetaData */ | ||
1420 | G_TYPE_POINTER, /* FSUI search list */ | ||
1421 | G_TYPE_INT); /* Meta-data about namespace */ | ||
1422 | gtk_combo_box_set_model(GTK_COMBO_BOX(searchCB), | ||
1423 | GTK_TREE_MODEL(model)); | ||
1424 | gtk_combo_box_entry_set_text_column(searchCB, | ||
1425 | NS_SEARCH_DESCRIPTION); | ||
1426 | searchList = GTK_TREE_VIEW(glade_xml_get_widget(getMainXML(), | ||
1427 | "activeSearchesSummary")); | ||
1428 | search_summary = | ||
1429 | gtk_list_store_new(SER_SUM_NUM, | ||
1430 | G_TYPE_STRING, /* name */ | ||
1431 | G_TYPE_INT, /* # results */ | ||
1432 | G_TYPE_POINTER); /* internal: search list */ | ||
1433 | gtk_tree_view_set_model(searchList, | ||
1434 | GTK_TREE_MODEL(search_summary)); | ||
1435 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(searchList), | ||
1436 | GTK_SELECTION_MULTIPLE); | ||
1437 | |||
1438 | renderer = gtk_cell_renderer_text_new(); | ||
1439 | col = gtk_tree_view_insert_column_with_attributes(searchList, | ||
1440 | -1, | ||
1441 | _("Query"), | ||
1442 | renderer, | ||
1443 | "text", SERARCH_SUMMARY_NAME, | ||
1444 | NULL); | ||
1445 | column = gtk_tree_view_get_column(searchList, | ||
1446 | col - 1); | ||
1447 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1448 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
1449 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
1450 | gtk_tree_view_column_set_sort_column_id(column, SER_SUM_NAME); | ||
1451 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1452 | renderer = gtk_cell_renderer_text_new(); | ||
1453 | col = gtk_tree_view_insert_column_with_attributes(searchList, | ||
1454 | -1, | ||
1455 | _("Results"), | ||
1456 | renderer, | ||
1457 | "text", SERARCH_SUMMARY_RESULT_COUNT, | ||
1458 | NULL); | ||
1459 | column = gtk_tree_view_get_column(searchList, | ||
1460 | col - 1); | ||
1461 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1462 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
1463 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
1464 | gtk_tree_view_column_set_sort_column_id(column, SER_SUM_COUNT); | ||
1465 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1466 | |||
1467 | |||
1468 | downloadList = GTK_TREE_VIEW(glade_xml_get_widget(getMainXML(), | ||
1469 | "activeDownloadsList")); | ||
1470 | download_summary = | ||
1471 | gtk_tree_store_new(DOWNLOAD_NUM, | ||
1472 | G_TYPE_STRING, /* name (full-path file name) */ | ||
1473 | G_TYPE_STRING, /* name (user-friendly name) */ | ||
1474 | G_TYPE_UINT64, /* size */ | ||
1475 | G_TYPE_STRING, /* human readable size */ | ||
1476 | G_TYPE_INT, /* progress */ | ||
1477 | G_TYPE_STRING, /* uri as string */ | ||
1478 | G_TYPE_POINTER); /* internal download list ptr */ | ||
1479 | gtk_tree_view_set_model(downloadList, | ||
1480 | GTK_TREE_MODEL(download_summary)); | ||
1481 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(downloadList), | ||
1482 | GTK_SELECTION_MULTIPLE); | ||
1483 | renderer = gtk_cell_renderer_progress_new(); | ||
1484 | col = gtk_tree_view_insert_column_with_attributes(downloadList, | ||
1485 | -1, | ||
1486 | _("Name"), | ||
1487 | renderer, | ||
1488 | "value", DOWNLOAD_PROGRESS, | ||
1489 | "text", DOWNLOAD_SHORTNAME, | ||
1490 | NULL); | ||
1491 | column = gtk_tree_view_get_column(downloadList, | ||
1492 | col - 1); | ||
1493 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1494 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
1495 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
1496 | gtk_tree_view_column_set_sort_column_id(column, DOWNLOAD_PROGRESS); | ||
1497 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | ||
1498 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1499 | renderer = gtk_cell_renderer_text_new(); | ||
1500 | g_object_set (renderer, "xalign", 1.00, NULL); | ||
1501 | col = gtk_tree_view_insert_column_with_attributes(downloadList, | ||
1502 | -1, | ||
1503 | _("Size"), | ||
1504 | renderer, | ||
1505 | "text", DOWNLOAD_HSIZE, | ||
1506 | NULL); | ||
1507 | |||
1508 | column = gtk_tree_view_get_column(downloadList, | ||
1509 | col - 1); | ||
1510 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1511 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
1512 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
1513 | gtk_tree_view_column_set_sort_column_id(column, DOWNLOAD_SIZE); | ||
1514 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | ||
1515 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1516 | renderer = gtk_cell_renderer_text_new(); | ||
1517 | col = gtk_tree_view_insert_column_with_attributes(downloadList, | ||
1518 | -1, | ||
1519 | _("URI"), | ||
1520 | renderer, | ||
1521 | "text", DOWNLOAD_URISTRING, | ||
1522 | NULL); | ||
1523 | column = gtk_tree_view_get_column(downloadList, | ||
1524 | col - 1); | ||
1525 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1526 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
1527 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | ||
1528 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
1529 | } | ||
1530 | |||
1531 | /** | ||
1532 | * Shutdown. | ||
1533 | */ | ||
1534 | void fs_search_stop() { | ||
1535 | GtkComboBox * searchCB; | ||
1536 | GtkListStore * model; | ||
1537 | |||
1538 | searchCB | ||
1539 | = GTK_COMBO_BOX(glade_xml_get_widget(getMainXML(), | ||
1540 | "fssearchKeywordComboBoxEntry")); | ||
1541 | model = gtk_combo_box_get_model(searchCB); | ||
1542 | /* FIXME: iterate over model entries | ||
1543 | and free URIs and MetaData! */ | ||
1544 | } | ||
1545 | |||
1546 | |||
1547 | /* end of search.c */ | 682 | /* end of search.c */ |