diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-edit_publish_dialog.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-edit_publish_dialog.c | 126 |
1 files changed, 80 insertions, 46 deletions
diff --git a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c index bf941106..ea5d7b5e 100644 --- a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c +++ b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2005, 2006, 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2005, 2006, 2010, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -131,9 +131,10 @@ struct EditPublicationDialogContext | |||
131 | GtkToggleButton *index_checkbutton; | 131 | GtkToggleButton *index_checkbutton; |
132 | 132 | ||
133 | /** | 133 | /** |
134 | * ??? | 134 | * Type ID of the last selected item in the GtkCellRendererCombo |
135 | * of the meta data tree view. | ||
135 | */ | 136 | */ |
136 | GtkTreeIter *meta_combo_selected_iter; | 137 | gint meta_combo_selected_type_id; |
137 | 138 | ||
138 | /** | 139 | /** |
139 | * Continuation to call once the dialog has been closed | 140 | * Continuation to call once the dialog has been closed |
@@ -286,11 +287,12 @@ metadata_selection_changed_cb (GtkTreeSelection *ts, | |||
286 | 287 | ||
287 | 288 | ||
288 | /** | 289 | /** |
289 | * The user changed the type of a meta-data item in the meta data | 290 | * The user changed (and confirmed the change) the type of a |
290 | * tree view. Update the type and text in the list store accordingly. | 291 | * meta-data item in the meta data tree view. Update the type and |
292 | * text in the list store accordingly. | ||
291 | * | 293 | * |
292 | * @param renderer widget where the change happened | 294 | * @param renderer widget where the change happened |
293 | * @param path which item was changed | 295 | * @param path which item was changed in the tree view |
294 | * @param new_text new value for the item | 296 | * @param new_text new value for the item |
295 | * @param user_data the 'struct EditPublicationDialogContext' | 297 | * @param user_data the 'struct EditPublicationDialogContext' |
296 | */ | 298 | */ |
@@ -301,10 +303,8 @@ GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb (GtkCellR | |||
301 | gpointer user_data) | 303 | gpointer user_data) |
302 | { | 304 | { |
303 | struct EditPublicationDialogContext *ctx = user_data; | 305 | struct EditPublicationDialogContext *ctx = user_data; |
304 | GtkTreeModel *combo_model; | ||
305 | GtkTreeIter iter; | 306 | GtkTreeIter iter; |
306 | gint type_id; | 307 | gint type_id; |
307 | gchar *description = NULL; | ||
308 | 308 | ||
309 | if (! gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ctx->meta_liststore), | 309 | if (! gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ctx->meta_liststore), |
310 | &iter, | 310 | &iter, |
@@ -313,28 +313,33 @@ GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb (GtkCellR | |||
313 | GNUNET_break (0); | 313 | GNUNET_break (0); |
314 | return; | 314 | return; |
315 | } | 315 | } |
316 | if (NULL == ctx->meta_combo_selected_iter) | 316 | if (-1 == ctx->meta_combo_selected_type_id) |
317 | { | 317 | { |
318 | GNUNET_break (0); | 318 | GNUNET_break (0); |
319 | return; | 319 | return; |
320 | } | 320 | } |
321 | /* FIXME from here... */ | 321 | type_id = ctx->meta_combo_selected_type_id; |
322 | g_object_get (GTK_CELL_RENDERER_COMBO (gtk_builder_get_object | 322 | ctx->meta_combo_selected_type_id = -1; |
323 | (ctx->builder, | 323 | gtk_list_store_set (ctx->meta_liststore, &iter, |
324 | "GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer")), | 324 | 0, type_id, |
325 | "model", &combo_model, NULL); | 325 | 1, EXTRACTOR_METAFORMAT_UTF8, |
326 | gtk_tree_model_get (combo_model, ctx->meta_combo_selected_iter, 0, &type_id, 2, &description, -1); | 326 | 2, EXTRACTOR_metatype_to_string (type_id), |
327 | g_object_unref (combo_model); | 327 | 4, EXTRACTOR_metatype_to_description (type_id), |
328 | g_free (ctx->meta_combo_selected_iter); | ||
329 | ctx->meta_combo_selected_iter = NULL; | ||
330 | |||
331 | gtk_list_store_set (ctx->meta_liststore, &iter, 0, type_id, 1, | ||
332 | EXTRACTOR_METAFORMAT_UTF8, 2, new_text, 4, description, | ||
333 | -1); | 328 | -1); |
334 | g_free (description); | ||
335 | } | 329 | } |
336 | 330 | ||
337 | 331 | ||
332 | /** | ||
333 | * The user changed the type of a meta-data item in the meta data | ||
334 | * tree view. Obtain the selected type_id and store it in | ||
335 | * the 'meta_combo_selected_type_id' field for use by | ||
336 | * 'GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb'. | ||
337 | * | ||
338 | * @param combo combo box that was dropped down | ||
339 | * @param path which item was changed in the tree view | ||
340 | * @param new_iter item that is now selected in the drop-down combo box | ||
341 | * @param user_data the 'struct EditPublicationDialogContext' | ||
342 | */ | ||
338 | void | 343 | void |
339 | GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb (GtkCellRendererCombo * combo, | 344 | GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb (GtkCellRendererCombo * combo, |
340 | gchar * path_string, | 345 | gchar * path_string, |
@@ -342,14 +347,28 @@ GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb (GtkCell | |||
342 | gpointer user_data) | 347 | gpointer user_data) |
343 | { | 348 | { |
344 | struct EditPublicationDialogContext *ctx = user_data; | 349 | struct EditPublicationDialogContext *ctx = user_data; |
350 | GtkTreeModel *combo_model; | ||
351 | gint type_id; | ||
345 | 352 | ||
346 | if (ctx->meta_combo_selected_iter) | 353 | g_object_get (combo, |
347 | g_free (ctx->meta_combo_selected_iter); | 354 | "model", &combo_model, NULL); |
348 | ctx->meta_combo_selected_iter = g_new0 (GtkTreeIter, 1); | 355 | gtk_tree_model_get (combo_model, new_iter, |
349 | *ctx->meta_combo_selected_iter = *new_iter; | 356 | 0, &type_id, |
357 | -1); | ||
358 | ctx->meta_combo_selected_type_id = type_id; | ||
350 | } | 359 | } |
351 | 360 | ||
352 | 361 | ||
362 | /** | ||
363 | * The user changed (and confirmed the change) the value of a | ||
364 | * meta-data item in the meta data tree view. Update the value | ||
365 | * in the list store accordingly. | ||
366 | * | ||
367 | * @param renderer widget where the change happened | ||
368 | * @param path which item was changed in the tree view | ||
369 | * @param new_text new value for the item | ||
370 | * @param user_data the 'struct EditPublicationDialogContext' | ||
371 | */ | ||
353 | void | 372 | void |
354 | GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb (GtkCellRendererText * renderer, | 373 | GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb (GtkCellRendererText * renderer, |
355 | gchar * path, | 374 | gchar * path, |
@@ -364,32 +383,47 @@ GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb (GtkCell | |||
364 | size_t slen; | 383 | size_t slen; |
365 | char *pos; | 384 | char *pos; |
366 | 385 | ||
367 | if (!gtk_tree_model_get_iter_from_string | 386 | if (! gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ctx->meta_liststore), |
368 | (GTK_TREE_MODEL (ctx->meta_liststore), &iter, path)) | 387 | &iter, |
388 | path)) | ||
389 | { | ||
390 | GNUNET_break (0); | ||
369 | return; | 391 | return; |
392 | } | ||
370 | 393 | ||
371 | gtk_tree_model_get (GTK_TREE_MODEL (ctx->meta_liststore), &iter, 0, &metatype, -1); | 394 | gtk_tree_model_get (GTK_TREE_MODEL (ctx->meta_liststore), &iter, |
372 | if (metatype == EXTRACTOR_METATYPE_FILENAME && | 395 | 0, &metatype, -1); |
373 | new_text[strlen (new_text) - 1] != '/' && ctx->is_directory) | 396 | if (metatype == EXTRACTOR_METATYPE_FILENAME) |
374 | { | 397 | { |
375 | GNUNET_asprintf (&avalue, "%s/", new_text); | 398 | /* apply filename rules */ |
376 | /* if user typed '\' instead of '/', change it! */ | 399 | /* First, use UNIX-style separators */ |
400 | avalue = GNUNET_strdup (new_text); | ||
401 | while (NULL != (pos = strstr (avalue, "\\"))) | ||
402 | *pos = '/'; | ||
403 | |||
404 | /* if user put '/' at the end, remove it' */ | ||
377 | slen = strlen (avalue); | 405 | slen = strlen (avalue); |
378 | while ((slen > 1) && (avalue[slen - 2] == '\\')) | 406 | while ( (slen > 1) && (avalue[slen - 1] == '\\')) |
379 | { | 407 | { |
380 | avalue[slen - 2] = '/'; | ||
381 | avalue[slen - 1] = '\0'; | 408 | avalue[slen - 1] = '\0'; |
382 | slen--; | 409 | slen--; |
383 | } | 410 | } |
384 | while (NULL != (pos = strstr (avalue, "\\"))) | 411 | |
385 | *pos = '/'; | 412 | /* However, directories must end with '/', so add it */ |
386 | // remove '../' everywhere | 413 | if ( (new_text[strlen (new_text) - 1] != '/') && |
387 | while (NULL != (pos = strstr (avalue, "../"))) | 414 | ctx->is_directory ) |
388 | { | 415 | { |
389 | pos[0] = '_'; | 416 | char * tmp; |
390 | pos[1] = '_'; | 417 | |
391 | pos[2] = '_'; | 418 | GNUNET_asprintf (&tmp, "%s/", avalue); |
419 | GNUNET_free (avalue); | ||
420 | avalue = tmp; | ||
392 | } | 421 | } |
422 | |||
423 | /* Also, replace '../' everywhere with "___" */ | ||
424 | while (NULL != (pos = strstr (avalue, "../"))) | ||
425 | memset (pos, '_', 3); | ||
426 | |||
393 | ivalue = avalue; | 427 | ivalue = avalue; |
394 | } | 428 | } |
395 | else | 429 | else |
@@ -397,13 +431,13 @@ GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb (GtkCell | |||
397 | ivalue = new_text; | 431 | ivalue = new_text; |
398 | avalue = NULL; | 432 | avalue = NULL; |
399 | } | 433 | } |
400 | 434 | gtk_list_store_set (ctx->meta_liststore, &iter, | |
401 | gtk_list_store_set (ctx->meta_liststore, &iter, 3, ivalue, -1); | 435 | 3, ivalue, |
436 | -1); | ||
402 | GNUNET_free_non_null (avalue); | 437 | GNUNET_free_non_null (avalue); |
403 | } | 438 | } |
404 | 439 | ||
405 | 440 | ||
406 | |||
407 | /** | 441 | /** |
408 | * The user has pushed the 'add' button for metadata. Add a 'dummy' value | 442 | * The user has pushed the 'add' button for metadata. Add a 'dummy' value |
409 | * to our meta data store (to be edited by the user). | 443 | * to our meta data store (to be edited by the user). |
@@ -991,7 +1025,7 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, | |||
991 | GNUNET_free (ctx); | 1025 | GNUNET_free (ctx); |
992 | return; | 1026 | return; |
993 | } | 1027 | } |
994 | 1028 | ctx->meta_combo_selected_type_id = -1; | |
995 | ctx->pubtypes_liststore = | 1029 | ctx->pubtypes_liststore = |
996 | GTK_LIST_STORE (gtk_builder_get_object | 1030 | GTK_LIST_STORE (gtk_builder_get_object |
997 | (ctx->builder, "GNUNET_GTK_publication_types_liststore")); | 1031 | (ctx->builder, "GNUNET_GTK_publication_types_liststore")); |