diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-event_handler.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-event_handler.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c index ada9cf86..9334600b 100644 --- a/src/fs/gnunet-fs-gtk-event_handler.c +++ b/src/fs/gnunet-fs-gtk-event_handler.c | |||
@@ -194,12 +194,17 @@ get_default_download_directory (char *buffer, size_t size) | |||
194 | * Called recursively to build a suggested filename by prepending | 194 | * Called recursively to build a suggested filename by prepending |
195 | * suggested names for its parent directories (if any). | 195 | * suggested names for its parent directories (if any). |
196 | * | 196 | * |
197 | * @param tm FIXME | 197 | * @param tm tree model this function gets the data from |
198 | * @param iter FIXME | 198 | * @param iter current position in the tree, for which we want a suggested filename |
199 | * @param top FIXME | 199 | * @param top GNUNET_YES for the original call to this function, |
200 | * @param local_parents set to GNUNET_YES if all parents are directories, and are downloaded. | 200 | * GNUNET_NO for recursive calls; used to decide if the |
201 | * @param anonymity FIXME | 201 | * current call is eligible to set 'anonymity' and 'local_parents' |
202 | * @param filename_is_absolute FIXME | 202 | * @param local_parents set to GNUNET_YES if all parents are directories, and are downloaded. |
203 | * @param anonymity set to the anonymity level of the closest ancestor download (if any); | ||
204 | * set to "-1" for uninitialized initially (will be left at -1 if | ||
205 | * no suitable parent download was found) | ||
206 | * @param filename_is_absolute set to GNUNET_YES if the suggestion is an absolute filename, | ||
207 | * GNUNET_NO for relative filenames (gotten from meta data) | ||
203 | * @return suggested filename, possibly NULL | 208 | * @return suggested filename, possibly NULL |
204 | */ | 209 | */ |
205 | static char * | 210 | static char * |
@@ -212,30 +217,41 @@ get_suggested_filename_anonymity (GtkTreeModel *tm, | |||
212 | { | 217 | { |
213 | char *result; | 218 | char *result; |
214 | char *dirname; | 219 | char *dirname; |
215 | char *local_filename, *filename; | 220 | char *local_filename; |
221 | char *filename; | ||
216 | int downloaded_anonymity; | 222 | int downloaded_anonymity; |
217 | int have_a_parent; | 223 | int have_a_parent; |
218 | struct GNUNET_CONTAINER_MetaData *meta; | 224 | struct GNUNET_CONTAINER_MetaData *meta; |
219 | GtkTreeIter parent; | 225 | GtkTreeIter parent; |
220 | gtk_tree_model_get (tm, iter, 0, &meta, 15, &local_filename, 16, &downloaded_anonymity, -1); | 226 | const char *basename; |
221 | if (local_filename == NULL && !top) | 227 | char *dot; |
228 | |||
229 | gtk_tree_model_get (tm, iter, 0, &meta, | ||
230 | 15, &local_filename, | ||
231 | 16, &downloaded_anonymity, | ||
232 | -1); | ||
233 | if ( (NULL == local_filename) && (GNUNET_NO == top) ) | ||
222 | *local_parents = GNUNET_NO; | 234 | *local_parents = GNUNET_NO; |
223 | if (downloaded_anonymity != -1 && *anonymity == -1 && !top) | 235 | if ( (downloaded_anonymity != -1) && (*anonymity == -1) && (GNUNET_NO == top) ) |
224 | *anonymity = downloaded_anonymity; | 236 | *anonymity = downloaded_anonymity; |
225 | if (gtk_tree_model_iter_parent (tm, &parent, iter)) | 237 | if (gtk_tree_model_iter_parent (tm, &parent, iter)) |
226 | { | 238 | { |
227 | have_a_parent = GNUNET_YES; | 239 | have_a_parent = GNUNET_YES; |
228 | dirname = get_suggested_filename_anonymity (tm, &parent, GNUNET_NO, local_parents, anonymity, filename_is_absolute); | 240 | dirname = get_suggested_filename_anonymity (tm, &parent, GNUNET_NO, |
241 | local_parents, anonymity, | ||
242 | filename_is_absolute); | ||
229 | } | 243 | } |
230 | else | 244 | else |
231 | { | 245 | { |
232 | have_a_parent = GNUNET_NO; | 246 | have_a_parent = GNUNET_NO; |
233 | dirname = NULL; | 247 | dirname = NULL; |
234 | if (top) | 248 | if (GNUNET_NO == top) |
235 | *local_parents = GNUNET_NO; | 249 | *local_parents = GNUNET_NO; |
236 | } | 250 | } |
237 | if (local_filename == NULL) | 251 | if (local_filename == NULL) |
252 | { | ||
238 | filename = GNUNET_FS_meta_data_suggest_filename (meta); | 253 | filename = GNUNET_FS_meta_data_suggest_filename (meta); |
254 | } | ||
239 | else | 255 | else |
240 | { | 256 | { |
241 | /* This directory was downloaded as /foo/bar/baz/somedirname | 257 | /* This directory was downloaded as /foo/bar/baz/somedirname |
@@ -245,37 +261,38 @@ get_suggested_filename_anonymity (GtkTreeModel *tm, | |||
245 | * Without the .gnd extension we're going to just use a copy | 261 | * Without the .gnd extension we're going to just use a copy |
246 | * of the directory file name - and that would fail. Sad. | 262 | * of the directory file name - and that would fail. Sad. |
247 | */ | 263 | */ |
248 | const char *basename; | 264 | if ( (NULL == dirname) && (GNUNET_NO == have_a_parent)) |
249 | if (dirname == NULL && !have_a_parent) | ||
250 | { | 265 | { |
251 | /* This is the ealderlest parent directory. Use absolute path. */ | 266 | /* This is the ealderlest parent directory. Use absolute path. */ |
252 | basename = (const char *) local_filename; | 267 | basename = (const char *) local_filename; |
253 | *filename_is_absolute = GNUNET_YES; | 268 | *filename_is_absolute = GNUNET_YES; |
254 | } | 269 | } |
255 | else | 270 | else |
271 | { | ||
256 | basename = GNUNET_STRINGS_get_short_name (local_filename); | 272 | basename = GNUNET_STRINGS_get_short_name (local_filename); |
257 | if (basename != NULL && strlen (basename) > 0) | 273 | } |
274 | if ( (NULL != basename) && (strlen (basename) > 0) ) | ||
258 | { | 275 | { |
259 | char *dot; | ||
260 | filename = GNUNET_strdup (basename); | 276 | filename = GNUNET_strdup (basename); |
261 | dot = strrchr (filename, '.'); | 277 | dot = strrchr (filename, '.'); |
262 | if (dot) | 278 | if (dot) |
263 | *dot = '\0'; | 279 | *dot = '\0'; |
264 | } | 280 | } |
265 | else | 281 | else |
282 | { | ||
266 | filename = GNUNET_FS_meta_data_suggest_filename (meta); | 283 | filename = GNUNET_FS_meta_data_suggest_filename (meta); |
284 | } | ||
267 | } | 285 | } |
268 | if (dirname && filename) | 286 | if ( (NULL != dirname) && (NULL != filename) ) |
269 | { | 287 | { |
270 | GNUNET_asprintf (&result, "%s%s%s", dirname, DIR_SEPARATOR_STR, filename); | 288 | GNUNET_asprintf (&result, "%s%s%s", dirname, DIR_SEPARATOR_STR, filename); |
271 | GNUNET_free (filename); | 289 | GNUNET_free (filename); |
272 | GNUNET_free (dirname); | 290 | GNUNET_free (dirname); |
273 | return result; | 291 | return result; |
274 | } | 292 | } |
275 | else if (filename) | 293 | if (NULL != filename) |
276 | return filename; | 294 | return filename; |
277 | else | 295 | return NULL; |
278 | return NULL; | ||
279 | } | 296 | } |
280 | 297 | ||
281 | 298 | ||