[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19617 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19617 - gnunet-gtk/src/fs |
Date: |
Wed, 1 Feb 2012 22:47:49 +0100 |
Author: grothoff
Date: 2012-02-01 22:47:49 +0100 (Wed, 01 Feb 2012)
New Revision: 19617
Modified:
gnunet-gtk/src/fs/gnunet-fs-gtk-common.h
gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
Log:
-more documentation and code simplification
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-common.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-common.h 2012-02-01 21:14:17 UTC (rev
19616)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-common.h 2012-02-01 21:47:49 UTC (rev
19617)
@@ -42,7 +42,6 @@
GNUNET_CONTAINER_MetaData *meta);
-
/**
* Initialize the 'expiration_year_adjustment' of the given
* builder to have a lower range of current-year+1 and a
@@ -104,6 +103,7 @@
const char *data_mime_type,
const char *data, size_t data_len);
+
/**
* Converts metadata specified by @data of size @data_len
* and saved in format @format to UTF-8 encoded string.
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:14:17 UTC (rev 19616)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c 2012-02-01
21:47:49 UTC (rev 19617)
@@ -197,48 +197,63 @@
{
gtk_widget_destroy (GTK_WIDGET (ctx->edit_publication_window));
GNUNET_free_non_null (ctx->short_fn);
- // FIXME: destroy builder!
+ // FIXME-LEAK: destroy builder!
GNUNET_free (ctx);
}
+
+/* ****************** metadata editing ******************** */
+
+
+
+/**
+ * Update the set of metatypes listed in the dialog based on the
+ * given code.
+ *
+ * @param ctx main dialog context
+ * @param code which set of metatypes is desired?
+ */
static void
change_metatypes (struct EditPublicationDialogContext *ctx, gint code)
{
- gint pub_type = 0, i;
- gint pubtype_count = 0;
+ gint pubtype_count;
gint max_type;
+ gint i;
GtkTreeIter iter;
- for (pub_type = 0; types[pub_type] != NULL; pub_type++)
- pubtype_count += 1;
-
- if (code < pubtype_count)
- pub_type = code;
- else
- pub_type = 0;
-
+ /* double-check that 'code' is valid */
+ for (pubtype_count = 0; NULL != types[pubtype_count]; pubtype_count++) ;
+ GNUNET_assert (code < pubtype_count);
+
+ /* clear existing selection of metatypes */
gtk_list_store_clear (ctx->metatypes_liststore);
max_type = EXTRACTOR_metatype_get_max ();
- for (i = 0; types[pub_type][i] != EXTRACTOR_METATYPE_RESERVED; i++)
- {
- if (types[pub_type][i] < max_type && types[pub_type][i] > 0)
- gtk_list_store_insert_with_values (ctx->metatypes_liststore, &iter,
G_MAXINT, 0,
- types[pub_type][i], 1,
- EXTRACTOR_METAFORMAT_UTF8, 2,
- EXTRACTOR_metatype_to_string (types
-
[pub_type]
- [i]), 3,
- EXTRACTOR_metatype_to_description
- (types[pub_type][i]), -1);
- }
+ /* add new types based on selection */
+ for (i = 0; types[code][i] != EXTRACTOR_METATYPE_RESERVED; i++)
+ if ( (types[code][i] < max_type) && (types[code][i] > 0) )
+ gtk_list_store_insert_with_values (ctx->metatypes_liststore,
+ &iter, G_MAXINT,
+ 0, types[code][i],
+ 1, EXTRACTOR_METAFORMAT_UTF8,
+ 2, EXTRACTOR_metatype_to_string (types
[code][i]),
+ 3, EXTRACTOR_metatype_to_description
(types[code][i]),
+ -1);
}
+/**
+ * The user has selected a different publication type.
+ * Update the meta type selection.
+ *
+ * @param widget the publication type combo box widget
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
void
GNUNET_GTK_edit_publication_type_combo_changed_cb (GtkComboBox * widget,
- struct
EditPublicationDialogContext *ctx)
+ gpointer user_data)
{
+ struct EditPublicationDialogContext *ctx = user_data;
GtkTreeIter iter;
gint code;
@@ -249,61 +264,34 @@
}
+/**
+ * The user has changed the selection in the meta data tree view.
+ * Update the sensitivity of the 'delete' button.
+ *
+ * @param ts the tree selection object
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
+/* FIXME: connect this signal via glade (modern versions of Glade support
this) */
static void
-metadata_selection_changed_cb (GtkTreeSelection *ts, struct
EditPublicationDialogContext *ctx)
+metadata_selection_changed_cb (GtkTreeSelection *ts,
+ gpointer user_data)
{
- gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object
- (ctx->builder,
"GNUNET_GTK_edit_publication_delete_button")),
- gtk_tree_selection_get_selected (ts, NULL, NULL));
-}
+ struct EditPublicationDialogContext *ctx = user_data;
-
-static void
-keywords_selection_changed_cb (GtkTreeSelection *ts, struct
EditPublicationDialogContext *ctx)
-{
gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object
- (ctx->builder,
-
"GNUNET_GTK_edit_publication_keyword_list_del_button")),
+ (ctx->builder,
+
"GNUNET_GTK_edit_publication_delete_button")),
gtk_tree_selection_get_selected (ts, NULL, NULL));
}
-void
-GNUNET_GTK_edit_publication_add_button_clicked_cb (GtkButton * button,
- struct
EditPublicationDialogContext *ctx)
+void
+GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb
(GtkCellRendererText * renderer,
+ gchar *
path,
+ gchar *
new_text,
+
gpointer user_data)
{
- GtkTreeIter iter;
-
- gtk_list_store_insert (ctx->meta_liststore, &iter, 0);
- /* type == 0 means "not set" */
- gtk_list_store_set (ctx->meta_liststore, &iter, 0, 0, 1,
EXTRACTOR_METAFORMAT_UTF8, 2,
- _("Select a type"), 3, _("Specify a value"), 4, NULL,
-1);
-}
-
-
-gboolean
-GNUNET_GTK_edit_publication_keyword_entry_key_press_event_cb (GtkWidget *
- widget,
- GdkEventKey *
- event,
- struct
EditPublicationDialogContext *ctx)
-{
- if (event->keyval == GDK_KEY_Return)
- {
- GNUNET_GTK_edit_publication_add_button_clicked_cb (GTK_BUTTON
(gtk_builder_get_object (ctx->builder,
-
"GNUNET_GTK_edit_publication_keyword_list_add_button")),
-
- ctx);
- return TRUE;
- }
- return FALSE;
-}
-
-
-void GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb
- (GtkCellRendererText * renderer, gchar * path, gchar * new_text,
- struct EditPublicationDialogContext *ctx)
-{
+ struct EditPublicationDialogContext *ctx = user_data;
GtkTreeModel *combo_model;
GtkTreeIter iter;
gint type_id;
@@ -331,10 +319,13 @@
}
-void GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb
- (GtkCellRendererCombo * combo, gchar * path_string, GtkTreeIter * new_iter,
- struct EditPublicationDialogContext *ctx)
+void
+GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb
(GtkCellRendererCombo * combo,
+ gchar
* path_string,
+
GtkTreeIter * new_iter,
+
gpointer user_data)
{
+ struct EditPublicationDialogContext *ctx = user_data;
if (ctx->meta_combo_selected_iter)
g_free (ctx->meta_combo_selected_iter);
ctx->meta_combo_selected_iter = g_new0 (GtkTreeIter, 1);
@@ -342,10 +333,13 @@
}
-void GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb
- (GtkCellRendererText * renderer, gchar * path, gchar * new_text,
- struct EditPublicationDialogContext *ctx)
+void
+GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb
(GtkCellRendererText * renderer,
+ gchar
* path,
+ gchar
* new_text,
+
gpointer user_data)
{
+ struct EditPublicationDialogContext *ctx = user_data;
GtkTreeIter iter;
gint metatype;
char *avalue;
@@ -392,10 +386,44 @@
}
+
+/**
+ * The user has pushed the 'add' button for metadata. Add a 'dummy' value
+ * to our meta data store (to be edited by the user).
+ *
+ * @param button the 'add' button
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
void
+GNUNET_GTK_edit_publication_add_button_clicked_cb (GtkButton * button,
+ gpointer user_data)
+{
+ struct EditPublicationDialogContext *ctx = user_data;
+ GtkTreeIter iter;
+
+ gtk_list_store_insert_with_values (ctx->meta_liststore,
+ &iter, 0,
+ 0, 0,
+ 1, EXTRACTOR_METAFORMAT_UTF8,
+ 2, _("Select a type"),
+ 3, _("Specify a value"),
+ 4, NULL,
+ -1);
+}
+
+
+/**
+ * The user has pushed the 'del' button for metadata.
+ * If there is a metadata selected, remove it from the list store.
+ *
+ * @param widget the button
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
+void
GNUNET_GTK_edit_publication_delete_button_clicked_cb (GtkButton * button,
- struct
EditPublicationDialogContext *ctx)
+ gpointer user_data)
{
+ struct EditPublicationDialogContext *ctx = user_data;
GtkTreeIter iter;
GtkTreeSelection *meta_selection;
@@ -405,100 +433,173 @@
GNUNET_break (0);
return;
}
- if (gtk_list_store_remove (ctx->meta_liststore, &iter))
- gtk_tree_selection_select_iter (meta_selection, &iter);
+ GNUNET_break (gtk_list_store_remove (ctx->meta_liststore, &iter));
+ gtk_tree_selection_select_iter (meta_selection, &iter);
}
+/**
+ * The user has selected another preview image file. Update the
+ * preview image.
+ *
+ * @param widget the file chooser dialog that completed
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
void
-GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb (GtkButton *
- button,
- struct
EditPublicationDialogContext *ctx)
+GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button_file_set_cb
(GtkFileChooserButton * widget,
+
gpointer user_data)
{
- const char *keyword;
- GtkTreeIter iter;
+ struct EditPublicationDialogContext *ctx = user_data;
+ gchar *fn;
- keyword = gtk_entry_get_text (ctx->keyword_entry);
- if (strlen (keyword) > 0)
- {
- gtk_list_store_insert_with_values (ctx->keywords_liststore, &iter,
G_MAXINT, 0, keyword, 1, TRUE,
- -1);
- gtk_widget_set_sensitive (ctx->confirm_button, TRUE);
- }
- gtk_entry_set_text (ctx->keyword_entry, "");
+ fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
+ gtk_image_set_from_file (ctx->preview_image, fn);
+ g_free (fn);
+ ctx->preview_changed = GNUNET_YES;
}
-static gboolean
-gtk_tree_model_has_items_cb (GtkTreeModel * model, GtkTreePath * path,
- GtkTreeIter * iter, gpointer data)
-{
- gboolean *val = (gboolean *) data;
+/* ****************** keyword list editing ******************** */
- *val = TRUE;
- return TRUE;
-}
-static gboolean
-gtk_tree_model_has_items (GtkTreeModel * model)
+/**
+ * The user has changed the selection in the keyword tree view.
+ * Update the sensitivity of the 'delete' button.
+ *
+ * @param ts the tree selection object
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
+/* FIXME: connect this signal via glade (modern versions of Glade support
this) */
+static void
+keywords_selection_changed_cb (GtkTreeSelection *ts,
+ gpointer user_data)
{
- gboolean b = FALSE;
+ struct EditPublicationDialogContext *ctx = user_data;
- gtk_tree_model_foreach (model, >k_tree_model_has_items_cb, &b);
- return b;
+ gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object
+ (ctx->builder,
+
"GNUNET_GTK_edit_publication_keyword_list_del_button")),
+ gtk_tree_selection_get_selected (ts, NULL, NULL));
}
+/**
+ * The user has edited the keyword entry line. Update the
+ * sensitivity of the 'add' button.
+ *
+ * @param editable the entry line for keywords
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
void
GNUNET_GTK_edit_publication_keyword_entry_changed_cb (GtkEditable * editable,
- struct
EditPublicationDialogContext *ctx)
+ gpointer user_data)
{
+ struct EditPublicationDialogContext *ctx = user_data;
const char *keyword;
keyword = gtk_entry_get_text (ctx->keyword_entry);
gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (ctx->builder,
-
"GNUNET_GTK_edit_publication_keyword_list_add_button")),
+
"GNUNET_GTK_edit_publication_keyword_list_add_button")),
(strlen (keyword) > 0) ? TRUE : FALSE);
}
+/**
+ * The user has pushed the 'del' button for the keyword.
+ * If there is a keyword selected, remove it from the list store.
+ *
+ * @param widget the button
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
void
GNUNET_GTK_edit_publication_keyword_list_del_button_clicked_cb (GtkButton *
button,
- struct
EditPublicationDialogContext *ctx)
-{
+ gpointer
user_data)
+{
+ struct EditPublicationDialogContext *ctx = user_data;
GtkTreeIter iter;
GtkTreeSelection *keywords_selection;
keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview);
-
- if (TRUE != gtk_tree_selection_get_selected (keywords_selection, NULL,
&iter))
+ if (! gtk_tree_selection_get_selected (keywords_selection, NULL, &iter))
{
GNUNET_break (0);
return;
}
- if (gtk_list_store_remove (GTK_LIST_STORE (ctx->keywords_liststore), &iter))
- gtk_tree_selection_select_iter (keywords_selection, &iter);
+ GNUNET_break (gtk_list_store_remove (GTK_LIST_STORE
(ctx->keywords_liststore), &iter));
+ gtk_tree_selection_select_iter (keywords_selection, &iter);
- if (!ctx->allow_no_keywords && !gtk_tree_model_has_items (GTK_TREE_MODEL
(ctx->keywords_liststore)))
+ /* disable confirm button if keywords are required and we have no more
keywords */
+ if ( (! ctx->allow_no_keywords) &&
+ (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL
(ctx->keywords_liststore),
+ &iter)) )
gtk_widget_set_sensitive (ctx->confirm_button, FALSE);
}
-void
GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button_file_set_cb (
- GtkFileChooserButton * widget, struct EditPublicationDialogContext *ctx)
+/**
+ * The user has pushed the 'add' button for the keyword (or pressed RETURN).
+ * If there is a keyword in the line, add it to the list store.
+ *
+ * @param widget the entry line, or NULL (if we are called from 'RETURN')
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
+void
+GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb (GtkButton *
+ button,
+ gpointer
user_data)
{
- gchar *fn;
+ struct EditPublicationDialogContext *ctx = user_data;
+ const char *keyword;
+ GtkTreeIter iter;
- fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
- gtk_image_set_from_file (ctx->preview_image, fn);
- g_free (fn);
- ctx->preview_changed = GNUNET_YES;
+ keyword = gtk_entry_get_text (ctx->keyword_entry);
+ if (strlen (keyword) == 0)
+ return;
+ gtk_list_store_insert_with_values (ctx->keywords_liststore,
+ &iter, G_MAXINT,
+ 0, keyword,
+ 1, TRUE,
+ -1);
+ gtk_widget_set_sensitive (ctx->confirm_button, TRUE);
+ gtk_entry_set_text (ctx->keyword_entry, "");
}
/**
+ * The user has pushed a button in the entry line. Check if it was 'RETURN'
+ * and if so consider executing the 'add' action.
+ *
+ * @param widget the entry line
+ * @param event the event information
+ * @param user_data the 'struct EditPublicationDialogContext'
+ */
+gboolean
+GNUNET_GTK_edit_publication_keyword_entry_key_press_event_cb (GtkWidget *
+ widget,
+ GdkEventKey *
+ event,
+ gpointer
user_data)
+{
+ struct EditPublicationDialogContext *ctx = user_data;
+
+ if (event->keyval != GDK_KEY_Return)
+ return FALSE;
+ GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb (NULL, ctx);
+ return TRUE;
+}
+
+
+/* ****************** handlers for closing the dialog ******************** */
+
+
+
+
+
+
+
+/**
* Copy binary meta data from to the new container and also
* preserve all entries that were not changed.
*
@@ -752,6 +853,10 @@
return TRUE;
}
+
+/* ****************** code for initialization of the dialog
******************** */
+
+
/**
* Add each of the keywords to the keyword list store.
*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19617 - gnunet-gtk/src/fs,
gnunet <=