diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-download.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-download.c | 67 |
1 files changed, 18 insertions, 49 deletions
diff --git a/src/fs/gnunet-fs-gtk-download.c b/src/fs/gnunet-fs-gtk-download.c index e3ee68c4..dc5b2310 100644 --- a/src/fs/gnunet-fs-gtk-download.c +++ b/src/fs/gnunet-fs-gtk-download.c | |||
@@ -35,9 +35,8 @@ struct DownloadAsDialogContext | |||
35 | struct DownloadContext *dc; | 35 | struct DownloadContext *dc; |
36 | }; | 36 | }; |
37 | 37 | ||
38 | 38 | void | |
39 | static void | 39 | GNUNET_GTK_save_as_dialog_free_download_context (struct DownloadContext *dc) |
40 | free_download_context (struct DownloadContext *dc) | ||
41 | { | 40 | { |
42 | if (NULL != dc->rr) | 41 | if (NULL != dc->rr) |
43 | gtk_tree_row_reference_free (dc->rr); | 42 | gtk_tree_row_reference_free (dc->rr); |
@@ -50,7 +49,6 @@ free_download_context (struct DownloadContext *dc) | |||
50 | GNUNET_free (dc); | 49 | GNUNET_free (dc); |
51 | } | 50 | } |
52 | 51 | ||
53 | |||
54 | gboolean | 52 | gboolean |
55 | GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | 53 | GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, |
56 | gpointer user_data) | 54 | gpointer user_data) |
@@ -58,12 +56,7 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
58 | struct DownloadAsDialogContext *dlc = user_data; | 56 | struct DownloadAsDialogContext *dlc = user_data; |
59 | GtkBuilder *builder; | 57 | GtkBuilder *builder; |
60 | struct DownloadContext *dc; | 58 | struct DownloadContext *dc; |
61 | enum GNUNET_FS_DownloadOptions opt; | ||
62 | struct GNUNET_FS_Handle *fs; | ||
63 | struct DownloadEntry *de; | ||
64 | GtkWidget *cb; | 59 | GtkWidget *cb; |
65 | uint32_t anonymity; | ||
66 | uint64_t len; | ||
67 | 60 | ||
68 | if (dlc == NULL) | 61 | if (dlc == NULL) |
69 | { | 62 | { |
@@ -76,7 +69,7 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
76 | (builder, "GNUNET_GTK_save_as_recursive_check_button")); | 69 | (builder, "GNUNET_GTK_save_as_recursive_check_button")); |
77 | if (GTK_RESPONSE_OK != dlc->response) | 70 | if (GTK_RESPONSE_OK != dlc->response) |
78 | { | 71 | { |
79 | free_download_context (dc); | 72 | GNUNET_GTK_save_as_dialog_free_download_context (dc); |
80 | g_object_unref (G_OBJECT (dlc->builder)); | 73 | g_object_unref (G_OBJECT (dlc->builder)); |
81 | GNUNET_free (dlc); | 74 | GNUNET_free (dlc); |
82 | return FALSE; | 75 | return FALSE; |
@@ -88,50 +81,16 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
88 | (TRUE == | 81 | (TRUE == |
89 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES : | 82 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES : |
90 | GNUNET_NO; | 83 | GNUNET_NO; |
91 | fs = GNUNET_FS_GTK_get_fs_handle (); | 84 | dc->anonymity = |
92 | opt = GNUNET_FS_DOWNLOAD_OPTION_NONE; | ||
93 | if (dc->is_recursive) | ||
94 | opt |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; | ||
95 | anonymity = | ||
96 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | 85 | gtk_spin_button_get_value (GTK_SPIN_BUTTON |
97 | (gtk_builder_get_object | 86 | (gtk_builder_get_object |
98 | (builder, | 87 | (builder, |
99 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); | 88 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); |
100 | len = GNUNET_FS_uri_chk_get_file_size (dc->uri); | ||
101 | g_object_unref (G_OBJECT (builder)); | 89 | g_object_unref (G_OBJECT (builder)); |
102 | 90 | ||
103 | de = GNUNET_malloc (sizeof (struct DownloadEntry)); | ||
104 | de->uri = dc->uri; | ||
105 | dc->uri = NULL; | ||
106 | de->meta = dc->meta; | ||
107 | dc->meta = NULL; | ||
108 | if (dc->rr != NULL) | ||
109 | { | ||
110 | /* We're going to free "dc" very soon */ | ||
111 | de->rr = gtk_tree_row_reference_copy (dc->rr); | ||
112 | de->ts = GTK_TREE_STORE (gtk_tree_row_reference_get_model (dc->rr)); | ||
113 | } | ||
114 | if (dc->sr != NULL) | ||
115 | { | ||
116 | GNUNET_break (NULL != | ||
117 | GNUNET_FS_download_start_from_search (fs, dc->sr, | ||
118 | dc->filename, | ||
119 | NULL /* tempname */ , | ||
120 | 0 /* offset */ , | ||
121 | len, anonymity, opt, | ||
122 | de)); | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | GNUNET_break (NULL != | ||
127 | GNUNET_FS_download_start (fs, de->uri, NULL /* meta */ , | ||
128 | dc->filename, NULL /* tempname */ , | ||
129 | 0 /* offset */ , | ||
130 | len, anonymity, opt, de, | ||
131 | NULL /* parent download ctx */ )); | ||
132 | } | ||
133 | free_download_context (dc); | ||
134 | GNUNET_free (dlc); | 91 | GNUNET_free (dlc); |
92 | |||
93 | dc->cb (dc); | ||
135 | return FALSE; | 94 | return FALSE; |
136 | } | 95 | } |
137 | 96 | ||
@@ -168,7 +127,7 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | |||
168 | if (builder == NULL) | 127 | if (builder == NULL) |
169 | { | 128 | { |
170 | GNUNET_break (0); | 129 | GNUNET_break (0); |
171 | free_download_context (dc); | 130 | GNUNET_GTK_save_as_dialog_free_download_context (dc); |
172 | GNUNET_free (dlc); | 131 | GNUNET_free (dlc); |
173 | return; | 132 | return; |
174 | } | 133 | } |
@@ -181,7 +140,17 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | |||
181 | ad = GTK_WIDGET (gtk_builder_get_object | 140 | ad = GTK_WIDGET (gtk_builder_get_object |
182 | (builder, "GNUNET_GTK_save_as_dialog")); | 141 | (builder, "GNUNET_GTK_save_as_dialog")); |
183 | if (dc->filename != NULL) | 142 | if (dc->filename != NULL) |
184 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), dc->filename); | 143 | { |
144 | char *dirname; | ||
145 | char *basename; | ||
146 | dirname = GNUNET_strdup (dc->filename); | ||
147 | basename = (char *) GNUNET_STRINGS_get_short_name (dirname); | ||
148 | if (basename > dirname) | ||
149 | basename[-1] = '\0'; | ||
150 | gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (ad), dirname); | ||
151 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), basename); | ||
152 | GNUNET_free (dirname); | ||
153 | } | ||
185 | dlc->builder = builder; | 154 | dlc->builder = builder; |
186 | dlc->dialog = ad; | 155 | dlc->dialog = ad; |
187 | dlc->response = 0; | 156 | dlc->response = 0; |