diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk_open-uri.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk_open-uri.c | 69 |
1 files changed, 30 insertions, 39 deletions
diff --git a/src/fs/gnunet-fs-gtk_open-uri.c b/src/fs/gnunet-fs-gtk_open-uri.c index 7c0900fc..93a164cc 100644 --- a/src/fs/gnunet-fs-gtk_open-uri.c +++ b/src/fs/gnunet-fs-gtk_open-uri.c | |||
@@ -28,11 +28,38 @@ | |||
28 | */ | 28 | */ |
29 | #include "gnunet-fs-gtk_common.h" | 29 | #include "gnunet-fs-gtk_common.h" |
30 | #include "gnunet-fs-gtk_download-save-as.h" | 30 | #include "gnunet-fs-gtk_download-save-as.h" |
31 | #include "gnunet-fs-gtk_open-uri.h" | ||
31 | #include "gnunet-fs-gtk.h" | 32 | #include "gnunet-fs-gtk.h" |
32 | #include <gdk/gdkkeysyms.h> | 33 | #include <gdk/gdkkeysyms.h> |
33 | 34 | ||
34 | 35 | ||
35 | /** | 36 | /** |
37 | * Handle a URI string by running the appropriate action. | ||
38 | * | ||
39 | * @param uris string we got | ||
40 | * @param anonymity_level anonymity level to use | ||
41 | * @return GNUNET_OK on success, GNUNET_NO if the URI type is not supported, GNUNET_SYSERR if we failed to | ||
42 | * parse the URI | ||
43 | */ | ||
44 | int | ||
45 | GNUNET_FS_GTK_handle_uri_string (const char *uris, | ||
46 | guint anonymity_level) | ||
47 | { | ||
48 | struct GNUNET_FS_Uri *uri; | ||
49 | char *perr; | ||
50 | |||
51 | uri = GNUNET_FS_uri_parse (uris, &perr); | ||
52 | if (uri == NULL) | ||
53 | { | ||
54 | GNUNET_free (perr); | ||
55 | return GNUNET_SYSERR; | ||
56 | } | ||
57 | GNUNET_FS_GTK_handle_uri (uri, anonymity_level); | ||
58 | return GNUNET_OK; | ||
59 | } | ||
60 | |||
61 | |||
62 | /** | ||
36 | * User selected "execute" in the open-URI dialog. | 63 | * User selected "execute" in the open-URI dialog. |
37 | * | 64 | * |
38 | * @param button the execute button | 65 | * @param button the execute button |
@@ -48,9 +75,7 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, | |||
48 | GtkTextIter ti_start; | 75 | GtkTextIter ti_start; |
49 | GtkTextIter ti_end; | 76 | GtkTextIter ti_end; |
50 | guint anonymity_level; | 77 | guint anonymity_level; |
51 | char *perr; | ||
52 | char *uris; | 78 | char *uris; |
53 | struct GNUNET_FS_Uri *uri; | ||
54 | 79 | ||
55 | dialog = | 80 | dialog = |
56 | GTK_WIDGET (gtk_builder_get_object | 81 | GTK_WIDGET (gtk_builder_get_object |
@@ -62,7 +87,6 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, | |||
62 | gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); | 87 | gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); |
63 | 88 | ||
64 | uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE); | 89 | uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE); |
65 | |||
66 | if (!GNUNET_GTK_get_selected_anonymity_level | 90 | if (!GNUNET_GTK_get_selected_anonymity_level |
67 | (builder, "main_window_search_anonymity_combobox", &anonymity_level)) | 91 | (builder, "main_window_search_anonymity_combobox", &anonymity_level)) |
68 | { | 92 | { |
@@ -71,42 +95,9 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, | |||
71 | g_object_unref (G_OBJECT (builder)); | 95 | g_object_unref (G_OBJECT (builder)); |
72 | return; | 96 | return; |
73 | } | 97 | } |
74 | uri = GNUNET_FS_uri_parse (uris, &perr); | 98 | GNUNET_break (GNUNET_OK == |
75 | g_free (uris); | 99 | GNUNET_FS_GTK_handle_uri_string (uris, anonymity_level)); |
76 | if (uri == NULL) | 100 | g_free (uris); |
77 | { | ||
78 | /* Why was "execute" button sensitive!? */ | ||
79 | GNUNET_break (0); | ||
80 | GNUNET_free (perr); | ||
81 | gtk_widget_destroy (dialog); | ||
82 | g_object_unref (G_OBJECT (builder)); | ||
83 | return; | ||
84 | } | ||
85 | if (GNUNET_FS_uri_test_sks (uri) || GNUNET_FS_uri_test_ksk (uri)) | ||
86 | { | ||
87 | GNUNET_break (NULL != | ||
88 | GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri, | ||
89 | anonymity_level, | ||
90 | GNUNET_FS_SEARCH_OPTION_NONE, NULL)); | ||
91 | GNUNET_FS_uri_destroy (uri); | ||
92 | gtk_widget_destroy (dialog); | ||
93 | g_object_unref (G_OBJECT (builder)); | ||
94 | return; | ||
95 | } | ||
96 | if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)) | ||
97 | { | ||
98 | struct DownloadEntry *de; | ||
99 | |||
100 | de = GNUNET_malloc (sizeof (struct DownloadEntry)); | ||
101 | de->uri = uri; | ||
102 | de->anonymity = anonymity_level; | ||
103 | GNUNET_FS_GTK_open_download_as_dialog (de); | ||
104 | gtk_widget_destroy (dialog); | ||
105 | g_object_unref (G_OBJECT (builder)); | ||
106 | return; | ||
107 | } | ||
108 | GNUNET_break (0); | ||
109 | GNUNET_FS_uri_destroy (uri); | ||
110 | gtk_widget_destroy (dialog); | 101 | gtk_widget_destroy (dialog); |
111 | g_object_unref (G_OBJECT (builder)); | 102 | g_object_unref (G_OBJECT (builder)); |
112 | } | 103 | } |