diff options
Diffstat (limited to 'src/fs/main_window_file_download.c')
-rw-r--r-- | src/fs/main_window_file_download.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/src/fs/main_window_file_download.c b/src/fs/main_window_file_download.c new file mode 100644 index 00000000..0a41bfba --- /dev/null +++ b/src/fs/main_window_file_download.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2005, 2006, 2010 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/main_window_file_download.c | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "common.h" | ||
26 | #include "download.h" | ||
27 | #include "gnunet-fs-gtk.h" | ||
28 | |||
29 | static GtkBuilder *builder; | ||
30 | |||
31 | void | ||
32 | GNUNET_GTK_open_url_dialog_url_entry_changed_cb (GtkEditable *editable, | ||
33 | gpointer user_data) | ||
34 | { | ||
35 | struct GNUNET_FS_Uri *uri; | ||
36 | char *perr; | ||
37 | const char *uris; | ||
38 | |||
39 | perr = NULL; | ||
40 | uris = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, | ||
41 | "GNUNET_GTK_open_url_dialog_url_entry"))); | ||
42 | if (uris != NULL) | ||
43 | uri = GNUNET_FS_uri_parse (uris, &perr); | ||
44 | else | ||
45 | uri = NULL; | ||
46 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, | ||
47 | "GNUNET_GTK_open_url_dialog_execute_button")), | ||
48 | (uri == NULL) ? FALSE : TRUE); | ||
49 | if (uri != NULL) | ||
50 | GNUNET_FS_uri_destroy (uri); | ||
51 | else | ||
52 | GNUNET_free_non_null (perr); | ||
53 | } | ||
54 | |||
55 | |||
56 | /** | ||
57 | * User selected "Open URI" in main window. | ||
58 | */ | ||
59 | void | ||
60 | GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy, | ||
61 | gpointer data) | ||
62 | { | ||
63 | GtkWidget *ad; | ||
64 | const char *uris; | ||
65 | uint32_t anonymity; | ||
66 | struct GNUNET_FS_Uri *uri; | ||
67 | char *perr; | ||
68 | struct DownloadContext *dc; | ||
69 | |||
70 | GNUNET_assert (builder == NULL); | ||
71 | builder = GNUNET_GTK_get_new_builder ("open_url_dialog.glade"); | ||
72 | if (builder == NULL) | ||
73 | { | ||
74 | GNUNET_break (0); | ||
75 | return; | ||
76 | } | ||
77 | ad = GTK_WIDGET (gtk_builder_get_object (builder, | ||
78 | "GNUNET_GTK_open_url_dialog")); | ||
79 | if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) | ||
80 | { | ||
81 | gtk_widget_destroy (ad); | ||
82 | g_object_unref (G_OBJECT (builder)); | ||
83 | builder = NULL; | ||
84 | fprintf (stderr, | ||
85 | "Dialog closed!\n"); | ||
86 | return; | ||
87 | } | ||
88 | uris = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, | ||
89 | "GNUNET_GTK_open_url_dialog_url_entry"))); | ||
90 | anonymity = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, | ||
91 | "GNUNET_GTK_open_url_dialog_anonymity_spin_button"))); | ||
92 | uri = GNUNET_FS_uri_parse (uris, &perr); | ||
93 | gtk_widget_destroy (ad); | ||
94 | g_object_unref (G_OBJECT (builder)); | ||
95 | builder = NULL; | ||
96 | if (uri == NULL) | ||
97 | { | ||
98 | GNUNET_free (perr); | ||
99 | /* Why was "execute" button sensitive!? */ | ||
100 | GNUNET_break (0); | ||
101 | return; | ||
102 | } | ||
103 | if (GNUNET_FS_uri_test_sks (uri) || | ||
104 | GNUNET_FS_uri_test_ksk (uri)) | ||
105 | { | ||
106 | fprintf (stderr, | ||
107 | "Starting search!\n"); | ||
108 | GNUNET_break (NULL != | ||
109 | GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), | ||
110 | uri, | ||
111 | anonymity, | ||
112 | GNUNET_FS_SEARCH_OPTION_NONE, | ||
113 | NULL)); | ||
114 | GNUNET_FS_uri_destroy (uri); | ||
115 | return; | ||
116 | } | ||
117 | if (GNUNET_FS_uri_test_chk (uri) || | ||
118 | GNUNET_FS_uri_test_loc (uri)) | ||
119 | { | ||
120 | dc = GNUNET_malloc (sizeof (struct DownloadContext)); | ||
121 | dc->uri = uri; | ||
122 | dc->anonymity = anonymity; | ||
123 | GNUNET_GTK_open_download_as_dialog (dc); | ||
124 | return; | ||
125 | } | ||
126 | GNUNET_break (0); | ||
127 | GNUNET_FS_uri_destroy (uri); | ||
128 | } | ||
129 | |||
130 | /* end of main_window_file_download.c */ | ||