[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19619 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19619 - gnunet-gtk/src/fs |
Date: |
Thu, 2 Feb 2012 00:30:24 +0100 |
Author: grothoff
Date: 2012-02-02 00:30:24 +0100 (Thu, 02 Feb 2012)
New Revision: 19619
Modified:
gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
Log:
-improved cleaning of filenames, some code cleanup
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c 2012-02-01
21:57:36 UTC (rev 19618)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c 2012-02-01
23:30:24 UTC (rev 19619)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet
- (C) 2005, 2006, 2010 Christian Grothoff (and other contributing authors)
+ (C) 2005, 2006, 2010, 2012 Christian Grothoff (and other contributing
authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -131,9 +131,10 @@
GtkToggleButton *index_checkbutton;
/**
- * ???
+ * Type ID of the last selected item in the GtkCellRendererCombo
+ * of the meta data tree view.
*/
- GtkTreeIter *meta_combo_selected_iter;
+ gint meta_combo_selected_type_id;
/**
* Continuation to call once the dialog has been closed
@@ -286,11 +287,12 @@
/**
- * The user changed the type of a meta-data item in the meta data
- * tree view. Update the type and text in the list store accordingly.
+ * The user changed (and confirmed the change) the type of a
+ * meta-data item in the meta data tree view. Update the type and
+ * text in the list store accordingly.
*
* @param renderer widget where the change happened
- * @param path which item was changed
+ * @param path which item was changed in the tree view
* @param new_text new value for the item
* @param user_data the 'struct EditPublicationDialogContext'
*/
@@ -301,10 +303,8 @@
gpointer user_data)
{
struct EditPublicationDialogContext *ctx = user_data;
- GtkTreeModel *combo_model;
GtkTreeIter iter;
gint type_id;
- gchar *description = NULL;
if (! gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL
(ctx->meta_liststore),
&iter,
@@ -313,28 +313,33 @@
GNUNET_break (0);
return;
}
- if (NULL == ctx->meta_combo_selected_iter)
+ if (-1 == ctx->meta_combo_selected_type_id)
{
GNUNET_break (0);
return;
}
- /* FIXME from here... */
- g_object_get (GTK_CELL_RENDERER_COMBO (gtk_builder_get_object
- (ctx->builder,
-
"GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer")),
- "model", &combo_model, NULL);
- gtk_tree_model_get (combo_model, ctx->meta_combo_selected_iter, 0, &type_id,
2, &description, -1);
- g_object_unref (combo_model);
- g_free (ctx->meta_combo_selected_iter);
- ctx->meta_combo_selected_iter = NULL;
-
- gtk_list_store_set (ctx->meta_liststore, &iter, 0, type_id, 1,
- EXTRACTOR_METAFORMAT_UTF8, 2, new_text, 4, description,
+ type_id = ctx->meta_combo_selected_type_id;
+ ctx->meta_combo_selected_type_id = -1;
+ gtk_list_store_set (ctx->meta_liststore, &iter,
+ 0, type_id,
+ 1, EXTRACTOR_METAFORMAT_UTF8,
+ 2, EXTRACTOR_metatype_to_string (type_id),
+ 4, EXTRACTOR_metatype_to_description (type_id),
-1);
- g_free (description);
}
+/**
+ * The user changed the type of a meta-data item in the meta data
+ * tree view. Obtain the selected type_id and store it in
+ * the 'meta_combo_selected_type_id' field for use by
+ * 'GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb'.
+ *
+ * @param combo combo box that was dropped down
+ * @param path which item was changed in the tree view
+ * @param new_iter item that is now selected in the drop-down combo box
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
void
GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb
(GtkCellRendererCombo * combo,
gchar
* path_string,
@@ -342,14 +347,28 @@
gpointer user_data)
{
struct EditPublicationDialogContext *ctx = user_data;
+ GtkTreeModel *combo_model;
+ gint type_id;
- if (ctx->meta_combo_selected_iter)
- g_free (ctx->meta_combo_selected_iter);
- ctx->meta_combo_selected_iter = g_new0 (GtkTreeIter, 1);
- *ctx->meta_combo_selected_iter = *new_iter;
+ g_object_get (combo,
+ "model", &combo_model, NULL);
+ gtk_tree_model_get (combo_model, new_iter,
+ 0, &type_id,
+ -1);
+ ctx->meta_combo_selected_type_id = type_id;
}
+/**
+ * The user changed (and confirmed the change) the value of a
+ * meta-data item in the meta data tree view. Update the value
+ * in the list store accordingly.
+ *
+ * @param renderer widget where the change happened
+ * @param path which item was changed in the tree view
+ * @param new_text new value for the item
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
void
GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb
(GtkCellRendererText * renderer,
gchar
* path,
@@ -364,32 +383,47 @@
size_t slen;
char *pos;
- if (!gtk_tree_model_get_iter_from_string
- (GTK_TREE_MODEL (ctx->meta_liststore), &iter, path))
+ if (! gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL
(ctx->meta_liststore),
+ &iter,
+ path))
+ {
+ GNUNET_break (0);
return;
+ }
- gtk_tree_model_get (GTK_TREE_MODEL (ctx->meta_liststore), &iter, 0,
&metatype, -1);
- if (metatype == EXTRACTOR_METATYPE_FILENAME &&
- new_text[strlen (new_text) - 1] != '/' && ctx->is_directory)
+ gtk_tree_model_get (GTK_TREE_MODEL (ctx->meta_liststore), &iter,
+ 0, &metatype, -1);
+ if (metatype == EXTRACTOR_METATYPE_FILENAME)
{
- GNUNET_asprintf (&avalue, "%s/", new_text);
- /* if user typed '\' instead of '/', change it! */
+ /* apply filename rules */
+ /* First, use UNIX-style separators */
+ avalue = GNUNET_strdup (new_text);
+ while (NULL != (pos = strstr (avalue, "\\")))
+ *pos = '/';
+
+ /* if user put '/' at the end, remove it' */
slen = strlen (avalue);
- while ((slen > 1) && (avalue[slen - 2] == '\\'))
+ while ( (slen > 1) && (avalue[slen - 1] == '\\'))
{
- avalue[slen - 2] = '/';
avalue[slen - 1] = '\0';
slen--;
}
- while (NULL != (pos = strstr (avalue, "\\")))
- *pos = '/';
- // remove '../' everywhere
- while (NULL != (pos = strstr (avalue, "../")))
+
+ /* However, directories must end with '/', so add it */
+ if ( (new_text[strlen (new_text) - 1] != '/') &&
+ ctx->is_directory )
{
- pos[0] = '_';
- pos[1] = '_';
- pos[2] = '_';
+ char * tmp;
+
+ GNUNET_asprintf (&tmp, "%s/", avalue);
+ GNUNET_free (avalue);
+ avalue = tmp;
}
+
+ /* Also, replace '../' everywhere with "___" */
+ while (NULL != (pos = strstr (avalue, "../")))
+ memset (pos, '_', 3);
+
ivalue = avalue;
}
else
@@ -397,13 +431,13 @@
ivalue = new_text;
avalue = NULL;
}
-
- gtk_list_store_set (ctx->meta_liststore, &iter, 3, ivalue, -1);
+ gtk_list_store_set (ctx->meta_liststore, &iter,
+ 3, ivalue,
+ -1);
GNUNET_free_non_null (avalue);
}
-
/**
* The user has pushed the 'add' button for metadata. Add a 'dummy' value
* to our meta data store (to be edited by the user).
@@ -991,7 +1025,7 @@
GNUNET_free (ctx);
return;
}
-
+ ctx->meta_combo_selected_type_id = -1;
ctx->pubtypes_liststore =
GTK_LIST_STORE (gtk_builder_get_object
(ctx->builder,
"GNUNET_GTK_publication_types_liststore"));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19619 - gnunet-gtk/src/fs,
gnunet <=