aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-event_handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-event_handler.c')
-rw-r--r--src/fs/gnunet-fs-gtk-event_handler.c76
1 files changed, 33 insertions, 43 deletions
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c
index 9334600b..eb29b708 100644
--- a/src/fs/gnunet-fs-gtk-event_handler.c
+++ b/src/fs/gnunet-fs-gtk-event_handler.c
@@ -155,24 +155,6 @@ static struct SearchTab *current_context_search_tab;
155 155
156 156
157/** 157/**
158 * Closure for the 'start_download' callback.
159 */
160struct StartDownloadContext
161{
162 /**
163 * Search tab to search for the request.
164 */
165 struct SearchTab *tab;
166
167 /**
168 * Was the 'recursive' option requested?
169 */
170 gboolean recursive;
171
172};
173
174
175/**
176 * This should get the default download directory (so that GNUnet 158 * This should get the default download directory (so that GNUnet
177 * won't offer the user to download files to the 'bin' subdirectory, 159 * won't offer the user to download files to the 'bin' subdirectory,
178 * or whatever is the cwd). Returns NULL on failure (such as 160 * or whatever is the cwd). Returns NULL on failure (such as
@@ -303,15 +285,15 @@ get_suggested_filename_anonymity (GtkTreeModel *tm,
303 * 285 *
304 * @param tree_view tree view with the details 286 * @param tree_view tree view with the details
305 * @param path path selecting which entry we want to download 287 * @param path path selecting which entry we want to download
306 * @param column unused entry specifying which column the mouse was in 288 * @param tab the search tab where the user triggered the download request
307 * @param user_data a 'struct StartDownloadContext' with additional details 289 * @param is_recursive was the request for a recursive download?
308 */ 290 */
309static void 291static void
310start_download (GtkTreeView * tree_view, GtkTreePath * path, 292start_download (GtkTreeView * tree_view,
311 GtkTreeViewColumn * column, gpointer user_data) 293 GtkTreePath * path,
294 struct SearchTab *tab,
295 int is_recursive)
312{ 296{
313 struct StartDownloadContext *sdc = user_data;
314 struct SearchTab *tab = sdc->tab;
315 GtkTreeModel *tm; 297 GtkTreeModel *tm;
316 GtkTreeIter iter; 298 GtkTreeIter iter;
317 struct GNUNET_FS_Uri *uri; 299 struct GNUNET_FS_Uri *uri;
@@ -332,15 +314,13 @@ start_download (GtkTreeView * tree_view, GtkTreePath * path,
332 314
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "Starting a %sdownload\n", 316 "Starting a %sdownload\n",
335 sdc->recursive ? "recursive " : ""); 317 is_recursive ? "recursive " : "");
336 318
337 GNUNET_assert (tab != NULL); 319 GNUNET_assert (tab != NULL);
338 tm = gtk_tree_view_get_model (tree_view); 320 tm = gtk_tree_view_get_model (tree_view);
339 if (TRUE != gtk_tree_model_get_iter (tm, &iter, path)) 321 if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
340 { 322 {
341 GNUNET_break (0); 323 GNUNET_break (0);
342 // FIXME: this is bad...
343 GNUNET_free (sdc);
344 return; 324 return;
345 } 325 }
346 gtk_tree_model_get (tm, &iter, 0, &meta, 1, &uri, 9, &sr, 10, &mime, -1); 326 gtk_tree_model_get (tm, &iter, 0, &meta, 1, &uri, 9, &sr, 10, &mime, -1);
@@ -348,8 +328,7 @@ start_download (GtkTreeView * tree_view, GtkTreePath * path,
348 { 328 {
349 /* user clicked on directory that was opened (not downloaded!), so we 329 /* user clicked on directory that was opened (not downloaded!), so we
350 have no URI and downloading makes no sense. Ignore! */ 330 have no URI and downloading makes no sense. Ignore! */
351 if (NULL != mime) 331 g_free (mime);
352 g_free (mime);
353 return; 332 return;
354 } 333 }
355 if (!(GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))) 334 if (!(GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)))
@@ -416,7 +395,7 @@ start_download (GtkTreeView * tree_view, GtkTreePath * path,
416 dc->rr = gtk_tree_row_reference_new (tm, path); 395 dc->rr = gtk_tree_row_reference_new (tm, path);
417 dc->sr = sr->result; 396 dc->sr = sr->result;
418 dc->anonymity = anonymity; 397 dc->anonymity = anonymity;
419 dc->is_recursive = sdc->recursive; 398 dc->is_recursive = is_recursive;
420 dc->tab = tab; 399 dc->tab = tab;
421 if (local_parents && have_a_suggestion) 400 if (local_parents && have_a_suggestion)
422 /* Skip the dialog, call directly */ 401 /* Skip the dialog, call directly */
@@ -444,6 +423,27 @@ search_list_popup_selection_done (GtkMenuShell *menushell,
444} 423}
445 424
446 425
426
427/**
428 * This function is called when the user double-clicks on a search
429 * result. Begins the download, if necessary by opening the "save as"
430 * window.
431 *
432 * @param tree_view tree view with the details
433 * @param path path selecting which entry we want to download
434 * @param column unused entry specifying which column the mouse was in
435 * @param user_data the 'struct SearchTab' that was activated
436 */
437static void
438start_download_row_activated (GtkTreeView * tree_view, GtkTreePath * path,
439 GtkTreeViewColumn * column, gpointer user_data)
440{
441 struct SearchTab *tab = user_data;
442
443 start_download (tree_view, path, tab, GNUNET_NO);
444}
445
446
447/** 447/**
448 * "Download" was selected in the current search context menu. 448 * "Download" was selected in the current search context menu.
449 * 449 *
@@ -455,7 +455,6 @@ start_download_ctx_menu (GtkMenuItem *item, gpointer user_data)
455{ 455{
456 GtkTreePath *path; 456 GtkTreePath *path;
457 GtkTreeView *tv; 457 GtkTreeView *tv;
458 struct StartDownloadContext sdc;
459 458
460 if (current_context_row_reference == NULL) 459 if (current_context_row_reference == NULL)
461 { 460 {
@@ -468,9 +467,7 @@ start_download_ctx_menu (GtkMenuItem *item, gpointer user_data)
468 tv = GTK_TREE_VIEW (gtk_builder_get_object 467 tv = GTK_TREE_VIEW (gtk_builder_get_object
469 (current_context_search_tab->builder, 468 (current_context_search_tab->builder,
470 "_search_result_frame")); 469 "_search_result_frame"));
471 sdc.tab = current_context_search_tab; 470 start_download (tv, path, current_context_search_tab, GNUNET_NO);
472 sdc.recursive = FALSE;
473 start_download (tv, path, NULL, &sdc);
474 gtk_tree_path_free (path); 471 gtk_tree_path_free (path);
475 current_context_search_tab = NULL; 472 current_context_search_tab = NULL;
476} 473}
@@ -487,7 +484,6 @@ start_download_recursively_ctx_menu (GtkMenuItem *item, gpointer user_data)
487{ 484{
488 GtkTreePath *path; 485 GtkTreePath *path;
489 GtkTreeView *tv; 486 GtkTreeView *tv;
490 struct StartDownloadContext sdc;
491 487
492 if (current_context_row_reference == NULL) 488 if (current_context_row_reference == NULL)
493 { 489 {
@@ -500,9 +496,7 @@ start_download_recursively_ctx_menu (GtkMenuItem *item, gpointer user_data)
500 tv = GTK_TREE_VIEW (gtk_builder_get_object 496 tv = GTK_TREE_VIEW (gtk_builder_get_object
501 (current_context_search_tab->builder, 497 (current_context_search_tab->builder,
502 "_search_result_frame")); 498 "_search_result_frame"));
503 sdc.tab = current_context_search_tab; 499 start_download (tv, path, current_context_search_tab, GNUNET_YES);
504 sdc.recursive = TRUE;
505 start_download (tv, path, NULL, &sdc);
506 gtk_tree_path_free (path); 500 gtk_tree_path_free (path);
507 current_context_search_tab = NULL; 501 current_context_search_tab = NULL;
508} 502}
@@ -1595,7 +1589,6 @@ setup_search (struct GNUNET_FS_SearchContext *sc,
1595 GtkNotebook *notebook; 1589 GtkNotebook *notebook;
1596 GtkWindow *sf; 1590 GtkWindow *sf;
1597 gint pages; 1591 gint pages;
1598 struct StartDownloadContext *sdc;
1599 1592
1600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1601 "Setting up a search for %p\n", sc); 1594 "Setting up a search for %p\n", sc);
@@ -1670,11 +1663,8 @@ setup_search (struct GNUNET_FS_SearchContext *sc,
1670 /* add signal handlers */ 1663 /* add signal handlers */
1671 tv = GTK_TREE_VIEW (gtk_builder_get_object 1664 tv = GTK_TREE_VIEW (gtk_builder_get_object
1672 (tab->builder, "_search_result_frame")); 1665 (tab->builder, "_search_result_frame"));
1673 sdc = GNUNET_malloc (sizeof (struct StartDownloadContext));
1674 sdc->tab = tab;
1675 sdc->recursive = FALSE;
1676 g_signal_connect_data (G_OBJECT (tv), "row-activated", 1666 g_signal_connect_data (G_OBJECT (tv), "row-activated",
1677 G_CALLBACK (start_download), sdc, 1667 G_CALLBACK (start_download_row_activated), tab,
1678 &closure_notify_free, 0); 1668 &closure_notify_free, 0);
1679 g_signal_connect (G_OBJECT (tv), "cursor-changed", 1669 g_signal_connect (G_OBJECT (tv), "cursor-changed",
1680 G_CALLBACK (update_meta_data_views), tab); 1670 G_CALLBACK (update_meta_data_views), tab);