Index: src/applications/afs/gtkui/download.c =================================================================== RCS file: /var/cvs/GNUnet/GNUnet/src/applications/afs/gtkui/download.c,v retrieving revision 1.63 diff -u -r1.63 download.c --- src/applications/afs/gtkui/download.c 19 Mar 2004 21:24:52 -0000 1.63 +++ src/applications/afs/gtkui/download.c 24 Mar 2004 15:27:26 -0000 @@ -82,7 +82,7 @@ static void abortHelper(void); static void hideHelper(void); static gint abortSelectedDownloads(GtkWidget * widget, - GtkWidget * clist); + GtkWidget * clist); static GtkItemFactoryEntry dlWindowMenu[] = { { "/Select all", NULL, selectAll, 0, "" }, @@ -198,6 +198,39 @@ gtk_clist_freeze(clist); gtk_clist_sort(clist); gtk_clist_thaw(clist); +} + + +/** + * Counts the active Downloads in the download window and + * returns the number of them (0 when no window present) + * + **/ +gint activeDownloads(void) +{ + GList * tmp; + int row; + gint count=0; + GtkWidget * clist; + + if (!dlWindow) return 0; + clist = gtk_object_get_data(GTK_OBJECT(dlWindow), + "LIST"); + /** + * FIXME: gtk_container_children() is depricated but + * somehow it doesnt link with gtk_container_get_children() + */ + tmp = (GList*) gtk_container_children(GTK_CONTAINER(clist)); + while (tmp) { + row = (int)tmp->data; + tmp = tmp->next; + + /* if dlm is not NULL, count it as active */ + if (gtk_clist_get_row_data(GTK_CLIST(clist),row)) + count++; + FREE(tmp); + } + return count; } /** Index: src/applications/afs/gtkui/download.h =================================================================== RCS file: /var/cvs/GNUnet/GNUnet/src/applications/afs/gtkui/download.h,v retrieving revision 1.4 diff -u -r1.4 download.h --- src/applications/afs/gtkui/download.h 19 Mar 2004 21:24:52 -0000 1.4 +++ src/applications/afs/gtkui/download.h 24 Mar 2004 15:27:26 -0000 @@ -66,6 +66,8 @@ void startDownload(gchar * filename, RootNode * root); +gint activeDownloads(void); + void fetchURI(GtkWidget * widget, gpointer data); Index: src/applications/afs/gtkui/search.c =================================================================== RCS file: /var/cvs/GNUnet/GNUnet/src/applications/afs/gtkui/search.c,v retrieving revision 1.72 diff -u -r1.72 search.c --- src/applications/afs/gtkui/search.c 19 Mar 2004 21:24:52 -0000 1.72 +++ src/applications/afs/gtkui/search.c 24 Mar 2004 15:27:27 -0000 @@ -24,6 +24,9 @@ * @author Igor Wronsky **/ +/* should be on the safe side (i could do up to 140) */ +#define GNUNET_MAX_DNL 100 + #include "gnunet_afs_esed2.h" #include "helper.h" #include "download.h" @@ -287,6 +290,7 @@ void downloadGTK(GtkWidget * widget, ListModel * listModel) { gint row; + int free_slots; GList * tmp; tmp=GTK_CLIST(listModel->search_result_list)->selection; @@ -297,16 +301,19 @@ } gtk_clist_freeze(GTK_CLIST(listModel->search_result_list)); + free_slots=GNUNET_MAX_DNL-activeDownloads(); /* download all selected entries */ - while (tmp) { + while (tmp && free_slots) { RootNode * rootNode; row = (int)tmp->data; tmp = tmp->next; rootNode = (RootNode *) - gtk_clist_get_row_data(GTK_CLIST(listModel->search_result_list), - row); + gtk_clist_get_row_data(GTK_CLIST(listModel->search_result_list), + row); + + free_slots--; openSaveAs(rootNode); /* Remove entry from search results. Yes, @@ -315,11 +322,21 @@ after all, if you cancel, it's probably because it took too long to download anyway... If you really need it back, just search again! */ - gtk_clist_remove(GTK_CLIST(listModel->search_result_list), - row); +// gtk_clist_remove(GTK_CLIST(listModel->search_result_list), +// row); +// FREE(rootNode); + + GdkColor white={0, 0xFFFF, 0xFFFF, 0xFFFF}; + GdkColor aqua={0, 0xAAAA, 0xAAAA, 0xEEEE}; + gtk_clist_set_foreground(GTK_CLIST(listModel->search_result_list), + row, + &white); + gtk_clist_set_background(GTK_CLIST(listModel->search_result_list), + row, + &aqua); - FREE(rootNode); } + if (tmp) guiMessage("Maximum count of simultaneous downloads reached.\n"); gtk_clist_thaw(GTK_CLIST(listModel->search_result_list)); }