aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-main_window_file_download.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-main_window_file_download.c')
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_file_download.c182
1 files changed, 116 insertions, 66 deletions
diff --git a/src/fs/gnunet-fs-gtk-main_window_file_download.c b/src/fs/gnunet-fs-gtk-main_window_file_download.c
index 19f78172..0d1114af 100644
--- a/src/fs/gnunet-fs-gtk-main_window_file_download.c
+++ b/src/fs/gnunet-fs-gtk-main_window_file_download.c
@@ -25,82 +25,66 @@
25#include "gnunet-fs-gtk-common.h" 25#include "gnunet-fs-gtk-common.h"
26#include "gnunet-fs-gtk-download.h" 26#include "gnunet-fs-gtk-download.h"
27#include "gnunet-fs-gtk.h" 27#include "gnunet-fs-gtk.h"
28#include <gdk/gdkkeysyms.h>
28 29
29static GtkBuilder *builder; 30/**
30 31 * User selected "Open URI" in main window.
32 */
31void 33void
32GNUNET_GTK_open_url_dialog_url_entry_changed_cb (GtkEditable * editable, 34GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy,
33 gpointer user_data) 35 gpointer user_data)
34{ 36{
35 struct GNUNET_FS_Uri *uri; 37 GtkBuilder *builder;
36 char *perr; 38 GtkWidget *dialog;
37 const char *uris; 39 GtkTextBuffer *tb;
40 GtkTextIter ti_start, ti_end;
38 41
39 perr = NULL; 42 builder = GTK_BUILDER (user_data);
40 uris =
41 gtk_entry_get_text (GTK_ENTRY
42 (gtk_builder_get_object
43 (builder, "GNUNET_GTK_open_url_dialog_url_entry")));
44 if (uris != NULL)
45 uri = GNUNET_FS_uri_parse (uris, &perr);
46 else
47 uri = NULL;
48 gtk_widget_set_sensitive (GTK_WIDGET
49 (gtk_builder_get_object
50 (builder,
51 "GNUNET_GTK_open_url_dialog_execute_button")),
52 (uri == NULL) ? FALSE : TRUE);
53 if (uri != NULL)
54 GNUNET_FS_uri_destroy (uri);
55 else
56 GNUNET_free_non_null (perr);
57}
58 43
44 dialog = GTK_WIDGET (gtk_builder_get_object (builder, "GNUNET_GTK_open_url_window"));
45
46 tb = GTK_TEXT_BUFFER (gtk_builder_get_object (builder, "GNUNET_GTK_open_url_dialog_url_textview_buffer"));
47 gtk_text_buffer_get_iter_at_offset (tb, &ti_start, 0);
48 gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1);
49 gtk_text_buffer_delete (tb, &ti_start, &ti_end);
50
51 /* TODO: queue the clipboard, maybe there's valid URI in there?
52 * If so, get it. */
53
54 gtk_widget_show (dialog);
55}
59 56
60/**
61 * User selected "Open URI" in main window.
62 */
63void 57void
64GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy, 58GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton *button,
65 gpointer data) 59 gpointer user_data)
66{ 60{
67 GtkWidget *ad; 61 GtkBuilder *builder;
68 const char *uris; 62 GtkWidget *dialog;
69 uint32_t anonymity; 63 GtkTextBuffer *tb;
70 struct GNUNET_FS_Uri *uri; 64 GtkTextIter ti_start, ti_end;
65 guint anonymity_level;
71 char *perr; 66 char *perr;
72 struct DownloadContext *dc; 67 char *uris;
68 struct GNUNET_FS_Uri *uri;
73 69
74 GNUNET_assert (builder == NULL); 70 builder = GTK_BUILDER (user_data);
75 builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_open_url_dialog.glade"); 71
76 if (builder == NULL) 72 dialog = GTK_WIDGET (gtk_builder_get_object (builder, "GNUNET_GTK_open_url_window"));
77 { 73
78 GNUNET_break (0); 74 gtk_widget_hide (dialog);
79 return; 75
80 } 76 tb = GTK_TEXT_BUFFER (gtk_builder_get_object (builder, "GNUNET_GTK_open_url_dialog_url_textview_buffer"));
81 ad = GTK_WIDGET (gtk_builder_get_object 77 gtk_text_buffer_get_iter_at_offset (tb, &ti_start, 0);
82 (builder, "GNUNET_GTK_open_url_dialog")); 78 gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1);
83 if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) 79
84 { 80 uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE);
85 gtk_widget_destroy (ad); 81
86 g_object_unref (G_OBJECT (builder)); 82 if (!GNUNET_GTK_get_selected_anonymity_level (builder,
87 builder = NULL; 83 "main_window_search_anonymity_combobox", &anonymity_level))
88 fprintf (stderr, "Dialog closed!\n");
89 return; 84 return;
90 } 85
91 uris =
92 gtk_entry_get_text (GTK_ENTRY
93 (gtk_builder_get_object
94 (builder, "GNUNET_GTK_open_url_dialog_url_entry")));
95 anonymity =
96 gtk_spin_button_get_value (GTK_SPIN_BUTTON
97 (gtk_builder_get_object
98 (builder,
99 "GNUNET_GTK_open_url_dialog_anonymity_spin_button")));
100 uri = GNUNET_FS_uri_parse (uris, &perr); 86 uri = GNUNET_FS_uri_parse (uris, &perr);
101 gtk_widget_destroy (ad); 87 g_free (uris);
102 g_object_unref (G_OBJECT (builder));
103 builder = NULL;
104 if (uri == NULL) 88 if (uri == NULL)
105 { 89 {
106 GNUNET_free (perr); 90 GNUNET_free (perr);
@@ -113,16 +97,17 @@ GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy,
113 fprintf (stderr, "Starting search!\n"); 97 fprintf (stderr, "Starting search!\n");
114 GNUNET_break (NULL != 98 GNUNET_break (NULL !=
115 GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri, 99 GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri,
116 anonymity, 100 anonymity_level,
117 GNUNET_FS_SEARCH_OPTION_NONE, NULL)); 101 GNUNET_FS_SEARCH_OPTION_NONE, NULL));
118 GNUNET_FS_uri_destroy (uri); 102 GNUNET_FS_uri_destroy (uri);
119 return; 103 return;
120 } 104 }
121 if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)) 105 if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))
122 { 106 {
107 struct DownloadContext *dc;
123 dc = GNUNET_malloc (sizeof (struct DownloadContext)); 108 dc = GNUNET_malloc (sizeof (struct DownloadContext));
124 dc->uri = uri; 109 dc->uri = uri;
125 dc->anonymity = anonymity; 110 dc->anonymity = anonymity_level;
126 GNUNET_FS_GTK_open_download_as_dialog (dc); 111 GNUNET_FS_GTK_open_download_as_dialog (dc);
127 return; 112 return;
128 } 113 }
@@ -130,4 +115,69 @@ GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy,
130 GNUNET_FS_uri_destroy (uri); 115 GNUNET_FS_uri_destroy (uri);
131} 116}
132 117
118void
119GNUNET_GTK_open_url_dialog_cancel_button_clicked_cb (GtkButton *button,
120 gpointer user_data)
121{
122 GtkBuilder *builder;
123 builder = GTK_BUILDER (user_data);
124
125 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (builder, "GNUNET_GTK_open_url_window")));
126 return;
127}
128
129gboolean
130GNUNET_GTK_open_url_dialog_url_textview_key_press_event_cb (GtkWidget *widget,
131 GdkEventKey *event, gpointer user_data)
132{
133 GtkBuilder *builder;
134 builder = GTK_BUILDER (user_data);
135
136 if (event->keyval == GDK_KEY_Return)
137 {
138 GtkWidget *execute = GTK_WIDGET (gtk_builder_get_object (builder,
139 "GNUNET_GTK_open_url_dialog_execute_button"));
140 if (gtk_widget_get_sensitive (execute))
141 GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (
142 GTK_BUTTON (execute), user_data);
143 return TRUE;
144 }
145 return FALSE;
146}
147
148void
149GNUNET_GTK_open_url_dialog_url_textview_buffer_changed_cb (
150 GtkTextBuffer *textbuffer, gpointer user_data)
151{
152 struct GNUNET_FS_Uri *uri;
153 GtkTextBuffer *tb;
154 GtkTextIter ti_start, ti_end;
155 GtkBuilder *builder;
156 char *perr;
157 char *uris;
158
159 builder = GTK_BUILDER (user_data);
160
161 perr = NULL;
162 tb = GTK_TEXT_BUFFER (gtk_builder_get_object (builder, "GNUNET_GTK_open_url_dialog_url_textview_buffer"));
163 gtk_text_buffer_get_iter_at_offset (tb, &ti_start, 0);
164 gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1);
165
166 uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE);
167 if (uris != NULL)
168 uri = GNUNET_FS_uri_parse (uris, &perr);
169 else
170 uri = NULL;
171 g_free (uris);
172 gtk_widget_set_sensitive (GTK_WIDGET
173 (gtk_builder_get_object
174 (builder,
175 "GNUNET_GTK_open_url_dialog_execute_button")),
176 (uri == NULL) ? FALSE : TRUE);
177 if (uri != NULL)
178 GNUNET_FS_uri_destroy (uri);
179 else
180 GNUNET_free_non_null (perr);
181}
182
133/* end of gnunet-fs-gtk-main_window_file_download.c */ 183/* end of gnunet-fs-gtk-main_window_file_download.c */