diff options
Diffstat (limited to 'src/fs/download.c')
-rw-r--r-- | src/fs/download.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/fs/download.c b/src/fs/download.c new file mode 100644 index 00000000..6a0e172c --- /dev/null +++ b/src/fs/download.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 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/download.c | ||
23 | * @brief functions for downloading | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "download.h" | ||
27 | #include "gnunet-fs-gtk.h" | ||
28 | #include "fs_event_handler.h" | ||
29 | |||
30 | void | ||
31 | GNUNET_GTK_open_download_as_dialog (struct DownloadContext *dc) | ||
32 | { | ||
33 | GtkWidget *ad; | ||
34 | GtkBuilder *builder; | ||
35 | struct GNUNET_FS_Handle *fs; | ||
36 | uint64_t len; | ||
37 | enum GNUNET_FS_DownloadOptions opt; | ||
38 | uint32_t anonymity; | ||
39 | struct DownloadEntry *de; | ||
40 | GtkWidget *cb; | ||
41 | |||
42 | builder = GNUNET_GTK_get_new_builder ("download_as.glade"); | ||
43 | if (builder == NULL) | ||
44 | { | ||
45 | if (dc->rr != NULL) | ||
46 | gtk_tree_row_reference_free (dc->rr); | ||
47 | GNUNET_free_non_null (dc->mime); | ||
48 | GNUNET_free_non_null (dc->filename); | ||
49 | GNUNET_FS_uri_destroy (dc->uri); | ||
50 | GNUNET_free (dc); | ||
51 | return; | ||
52 | } | ||
53 | cb = GTK_WIDGET (gtk_builder_get_object (builder, | ||
54 | "GNUNET_GTK_save_as_recursive_check_button")); | ||
55 | if (GNUNET_FS_meta_data_test_for_directory (dc->meta)) | ||
56 | gtk_widget_set_sensitive (cb, TRUE); | ||
57 | ad = GTK_WIDGET (gtk_builder_get_object (builder, | ||
58 | "GNUNET_GTK_save_as_dialog")); | ||
59 | if (dc->filename != NULL) | ||
60 | { | ||
61 | char buf[1024]; | ||
62 | if (NULL != getcwd (buf, sizeof(buf))) | ||
63 | { | ||
64 | if (strlen (buf) + strlen (dc->filename) + 2 < sizeof(buf)) | ||
65 | { | ||
66 | strcat (buf, DIR_SEPARATOR_STR); | ||
67 | strcat (buf, dc->filename); | ||
68 | } | ||
69 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), | ||
70 | buf); | ||
71 | } | ||
72 | } | ||
73 | if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) | ||
74 | { | ||
75 | gtk_widget_destroy (ad); | ||
76 | g_object_unref (G_OBJECT (builder)); | ||
77 | if (dc->rr != NULL) | ||
78 | gtk_tree_row_reference_free (dc->rr); | ||
79 | GNUNET_free_non_null (dc->mime); | ||
80 | GNUNET_free_non_null (dc->filename); | ||
81 | GNUNET_FS_uri_destroy (dc->uri); | ||
82 | GNUNET_free (dc); | ||
83 | return; | ||
84 | } | ||
85 | GNUNET_free_non_null (dc->filename); | ||
86 | dc->filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad)); | ||
87 | dc->is_recursive = (TRUE == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES : GNUNET_NO; | ||
88 | fs = GNUNET_FS_GTK_get_fs_handle (); | ||
89 | opt = GNUNET_FS_DOWNLOAD_OPTION_NONE; | ||
90 | if (dc->is_recursive) | ||
91 | opt |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; | ||
92 | anonymity = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, | ||
93 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); | ||
94 | len = GNUNET_FS_uri_chk_get_file_size (dc->uri); | ||
95 | gtk_widget_destroy (ad); | ||
96 | g_object_unref (G_OBJECT (builder)); | ||
97 | de = GNUNET_malloc (sizeof (struct DownloadEntry)); | ||
98 | de->uri = dc->uri; | ||
99 | de->meta = dc->meta; | ||
100 | if (dc->rr != NULL) | ||
101 | { | ||
102 | de->rr = dc->rr; | ||
103 | de->ts = GTK_TREE_STORE (gtk_tree_row_reference_get_model (dc->rr)); | ||
104 | } | ||
105 | if (dc->sr != NULL) | ||
106 | { | ||
107 | GNUNET_break (NULL != | ||
108 | GNUNET_FS_download_start_from_search (fs, | ||
109 | dc->sr, | ||
110 | dc->filename, | ||
111 | NULL /* tempname */, | ||
112 | 0 /* offset */, | ||
113 | len, | ||
114 | anonymity, | ||
115 | opt, | ||
116 | de)); | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | GNUNET_break (NULL != | ||
121 | GNUNET_FS_download_start (fs, | ||
122 | dc->uri, | ||
123 | NULL /* meta */, | ||
124 | dc->filename, | ||
125 | NULL /* tempname */, | ||
126 | 0 /* offset */, | ||
127 | len, | ||
128 | anonymity, | ||
129 | opt, | ||
130 | de, | ||
131 | NULL /* parent download ctx */)); | ||
132 | } | ||
133 | GNUNET_free (dc); | ||
134 | } | ||
135 | |||
136 | /* end of download.c */ | ||