gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r19628 - gnunet-gtk/src/fs


From: gnunet
Subject: [GNUnet-SVN] r19628 - gnunet-gtk/src/fs
Date: Thu, 2 Feb 2012 13:57:54 +0100

Author: grothoff
Date: 2012-02-02 13:57:54 +0100 (Thu, 02 Feb 2012)
New Revision: 19628

Modified:
   gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
   gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.h
   gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
   gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c
Log:
-more code clean up in edit dialog

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-02 
12:47:26 UTC (rev 19627)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c       2012-02-02 
12:57:54 UTC (rev 19628)
@@ -73,11 +73,6 @@
   GtkComboBox *anonymity_combo;
 
   /**
-   * Liststore of the 'anonymity_combo' with the anonymity levels.
-   */
-  GtkListStore *anonymity_liststore;
-
-  /**
    * Liststore of possible publication types.
    */
   GtkListStore *pubtypes_liststore;
@@ -147,11 +142,6 @@
   void *cb_cls;
 
   /**
-   * Short name of the file being published (or NULL).
-   */
-  char *short_fn;
-
-  /**
    * Briefly used temporary meta data set.
    */
   struct GNUNET_CONTAINER_MetaData *md;
@@ -175,9 +165,8 @@
 
   /**
    * Is it allowed for the user to supply keywords in this dialog?
-   * FIXME: why 'gboolean'?
    */
-  gboolean allow_no_keywords;
+  int allow_no_keywords;
 
 };
 
@@ -191,7 +180,6 @@
 free_edit_dialog_context (struct EditPublicationDialogContext *ctx)
 {
   gtk_widget_destroy (GTK_WIDGET (ctx->edit_publication_window));
-  GNUNET_free_non_null (ctx->short_fn);
   // FIXME-LEAK: destroy builder!
   GNUNET_free (ctx);
 }
@@ -652,7 +640,7 @@
 {
   struct EditPublicationDialogContext *ctx = user_data;
 
-  ctx->cb (ctx->cb_cls, GNUNET_SYSERR, NULL, NULL, NULL, GTK_RESPONSE_CANCEL);
+  ctx->cb (ctx->cb_cls, GTK_RESPONSE_CANCEL, NULL);
   free_edit_dialog_context (ctx);
 }
 
@@ -672,17 +660,25 @@
 {
   struct EditPublicationDialogContext *ctx = user_data;
 
-  ctx->cb (ctx->cb_cls, GNUNET_SYSERR, NULL, NULL, NULL, GTK_RESPONSE_CANCEL);
+  ctx->cb (ctx->cb_cls, GTK_RESPONSE_CANCEL, NULL);
   free_edit_dialog_context (ctx);
   return TRUE;
 }
 
 
 /**
- * Copy binary meta data from to the new container and also
- * preserve all entries that were not changed.
+ * Copy binary meta data from to the new container and also preserve
+ * all entries that were not changed.  In particular, all binary meta
+ * data is removed if the preview was changed, otherwise it is all
+ * kept.  Similarly, if values are still in the liststore, they are
+ * fully kept (including plugin name and original format).  "Keeping"
+ * a value means that it is added to the 'md' meta data in the dialog
+ * context.
  *
- * @param cls closure, a 'struct FileInformationUpdateContext'
+ * @param cls closure, a 'struct FileInformationUpdateContext';
+ *        contains the 'new' meta data to construct in the 'md'
+ *        field and the liststore to check the current value
+ *        against in 'meta_liststore'.
  * @param plugin_name name of the plugin that produced this value;
  *        special values can be used (i.e. '<zlib>' for zlib being
  *        used in the main libextractor library and yielding
@@ -752,7 +748,8 @@
 
 
 /**
- * Function called to update the information in FI.
+ * Function called to update the information in FI based on the changes made in
+ * the edit dialog.
  *
  * @param cls closure with a 'struct FileInformationUpdateContext *'
  * @param fi the entry in the publish-structure
@@ -774,55 +771,58 @@
 {
   struct EditPublicationDialogContext *ctx = cls;
   GtkTreeIter iter;
-  struct GNUNET_FS_Uri *nxt;
-  struct GNUNET_FS_Uri *mrg;
-  gchar *value;
-  guint ntype;
-  guint nformat;
-  gchar *fn;
-  char *data;
-  gsize data_size;
-  const char *mime;
-  GFile *f;
-  GFileInfo *finfo;
-  char *sfn;
+  gint year;
 
+  /* gather publishing options  */
   *do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
+  GNUNET_break (GNUNET_GTK_get_selected_anonymity_combo_level 
(ctx->anonymity_combo,
+                                                              
&bo->anonymity_level));
+  bo->content_priority = gtk_spin_button_get_value (ctx->priority_spin);
+  bo->replication_level = gtk_spin_button_get_value (ctx->replication_spin);
+  year = gtk_spin_button_get_value (ctx->expiration_year_spin);
+  bo->expiration_time = GNUNET_FS_year_to_time (year);
 
-  /* update URI */
+  /* update keyword-URI */
   if (NULL != (*uri))
     GNUNET_FS_uri_destroy (*uri);
   *uri = NULL;
-  nxt = NULL;
-  mrg = NULL;
-
-  if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL 
(ctx->keywords_liststore), &iter))
+  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->keywords_liststore), 
&iter))
   {
     do
     {
+      gchar *value;
+
       gtk_tree_model_get (GTK_TREE_MODEL (ctx->keywords_liststore), &iter, 0, 
&value, -1);
-      nxt = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &value);
-      mrg = GNUNET_FS_uri_ksk_merge (nxt, *uri);
-      GNUNET_FS_uri_destroy (nxt);
-      if (NULL != *uri)
-        GNUNET_FS_uri_destroy (*uri);
-      *uri = mrg;
+      if (NULL == *uri)
+       *uri = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &value);
+      else
+       GNUNET_FS_uri_ksk_add_keyword (*uri, value, GNUNET_NO);
       g_free (value);
     }
-    while (TRUE == gtk_tree_model_iter_next (GTK_TREE_MODEL 
(ctx->keywords_liststore), &iter));
+    while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ctx->keywords_liststore), 
&iter));
   }
 
-  /* update meta */
+  /* update meta data; first, we copy the unchanged values from the original 
meta data */
   ctx->md = GNUNET_CONTAINER_meta_data_create ();
   GNUNET_CONTAINER_meta_data_iterate (meta, 
                                      &preserve_meta_items, 
                                      ctx);
-
+  /* clear original meta data */
   GNUNET_CONTAINER_meta_data_clear (meta);
-  if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL 
(ctx->meta_liststore), &iter))
+  /* add all of the 'preserved' values */
+  GNUNET_CONTAINER_meta_data_merge (meta, ctx->md);
+  GNUNET_CONTAINER_meta_data_destroy (ctx->md);
+  ctx->md = NULL;
+  /* now add all of the values from the model; adding will simply do 
+     nothing for values that are already in the set because they were 
preserved */
+  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->meta_liststore), 
&iter))
   {
     do
     {
+      guint ntype;
+      guint nformat;
+      gchar *value;
+
       gtk_tree_model_get (GTK_TREE_MODEL (ctx->meta_liststore), &iter, 0, 
&ntype, 1, &nformat, 3, &value, -1);
       if (ntype > 0)
         GNUNET_CONTAINER_meta_data_insert (ctx->md, "<user>", ntype, nformat,
@@ -830,11 +830,19 @@
                                            strlen (value) + 1);
       g_free (value);
     }
-    while (TRUE == gtk_tree_model_iter_next (GTK_TREE_MODEL 
(ctx->meta_liststore), &iter));
+    while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ctx->meta_liststore), 
&iter));
   }
-  GNUNET_CONTAINER_meta_data_merge (meta, ctx->md);
+  
+  /* finally, if we got a new preview, add it as well */
   if (ctx->preview_changed == GNUNET_YES)
   {
+    gchar *fn;
+    char *data;
+    gsize data_size;
+    const char *mime;
+    GFile *f;
+    GFileInfo *finfo;
+
     fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER
                                         (gtk_builder_get_object
                                          (ctx->builder,
@@ -843,7 +851,7 @@
     finfo =
         g_file_query_info (f, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL,
                            NULL);
-    if (FALSE == g_file_load_contents (f, NULL, &data, &data_size, NULL, NULL))
+    if (! g_file_load_contents (f, NULL, &data, &data_size, NULL, NULL))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _("Could not load preview `%s' into memory\n"), fn);
@@ -862,18 +870,6 @@
     g_object_unref (f);
     g_free (fn);
   }
-  GNUNET_CONTAINER_meta_data_destroy (ctx->md);
-  ctx->md = NULL;
-
-  /* update short_fn */
-  sfn = GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
-                                                      
EXTRACTOR_METATYPE_FILENAME,
-                                                      -1);
-  if (NULL != sfn)
-  {
-    GNUNET_free_non_null (ctx->short_fn);
-    ctx->short_fn = sfn;
-  }
   return GNUNET_SYSERR;         /* only visit top-level item */
 }
 
@@ -891,31 +887,25 @@
                                                        gpointer user_data)
 {
   struct EditPublicationDialogContext *ctx = user_data;
-  struct GNUNET_FS_BlockOptions bo;
-  gint year;
 
+  /* push back changes to file-information */
   GNUNET_FS_file_information_inspect (ctx->fip, 
                                      &file_information_update,
                                      ctx);
-  GNUNET_break (GNUNET_GTK_get_selected_anonymity_combo_level 
(ctx->anonymity_combo,
-                                                              
&bo.anonymity_level));
-  bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin);
-  bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin);
-  year = gtk_spin_button_get_value (ctx->expiration_year_spin);
-  bo.expiration_time = GNUNET_FS_year_to_time (year);
+  /* call our continuation */
   ctx->cb (ctx->cb_cls, 
-          gtk_toggle_button_get_active (ctx->index_checkbutton),
-          ctx->short_fn,
-          &bo,
-          gtk_entry_get_text (ctx->root_entry),
-          GTK_RESPONSE_OK);
+          GTK_RESPONSE_OK,
+          gtk_entry_get_text (ctx->root_entry));
+  /* free resources from the edit dialog */
   free_edit_dialog_context (ctx);
 }
 
 
+
 /* ****************** code for initialization of the dialog 
******************** */
 
 
+
 /**
  * Add each of the keywords to the keyword list store.
  *
@@ -931,18 +921,20 @@
   GtkTreeIter iter;
 
   ls = GTK_LIST_STORE (cls);
-  gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, keyword, 1, FALSE,
+  gtk_list_store_insert_with_values (ls, &iter, G_MAXINT,
+                                    0, keyword, 
+                                    1, FALSE,
                                      -1);
   return GNUNET_OK;
 }
 
 
 /**
- * Function called to extract the information from FI.
+ * Function called to extract the information from FI to populate the edit 
dialog.
  *
- * @param cls closure
- * @param fi the entry in the publish-structure
- * @param length length of the file or directory
+ * @param cls the 'struct EditPublicationDialogContext'
+ * @param fi the entry in the publish-structure (unused)
+ * @param length length of the file or directory (unused)
  * @param meta metadata for the file or directory (can be modified)
  * @param uri pointer to the keywords that will be used for this entry (can be 
modified)
  * @param bo block options
@@ -951,19 +943,34 @@
  * @return GNUNET_SYSERR (aborts after first call)
  */
 static int
-file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi,
-                          uint64_t length,
-                          struct GNUNET_CONTAINER_MetaData *meta,
-                          struct GNUNET_FS_Uri **uri,
-                          struct GNUNET_FS_BlockOptions *bo, int *do_index,
-                          void **client_info)
+file_information_import (void *cls, 
+                        struct GNUNET_FS_FileInformation *fi,
+                        uint64_t length,
+                        struct GNUNET_CONTAINER_MetaData *meta,
+                        struct GNUNET_FS_Uri **uri,
+                        struct GNUNET_FS_BlockOptions *bo, int *do_index,
+                        void **client_info)
 {
   struct EditPublicationDialogContext *ctx = cls;
   GdkPixbuf *pixbuf;
+  char *short_fn;
   int year;
 
+  /* import options */
+  year = (int) GNUNET_FS_time_to_year (bo->expiration_time);
+  gtk_spin_button_set_value (ctx->expiration_year_spin, year);
+  GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo,
+                                          bo->anonymity_level);
+  gtk_spin_button_set_value (ctx->priority_spin, bo->content_priority);
+  gtk_spin_button_set_value (ctx->replication_spin, bo->replication_level);
+  gtk_toggle_button_set_active (ctx->index_checkbutton, *do_index);
+
+
+  /* import keywords */
   if (NULL != *uri)
     GNUNET_FS_uri_ksk_get_keywords (*uri, &add_keyword, 
ctx->keywords_liststore);
+
+  /* import meta data */
   if (NULL != meta)
   {
     GNUNET_CONTAINER_meta_data_iterate (meta,
@@ -975,43 +982,41 @@
       gtk_image_set_from_pixbuf (ctx->preview_image, pixbuf);
     }
   }
-  year = (int) GNUNET_FS_time_to_year (bo->expiration_time);
-  gtk_spin_button_set_value (ctx->expiration_year_spin, year);
-  GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo,
-                                          bo->anonymity_level);
-  gtk_spin_button_set_value (ctx->priority_spin, bo->content_priority);
-  gtk_spin_button_set_value (ctx->replication_spin, bo->replication_level);
-  gtk_toggle_button_set_active (ctx->index_checkbutton, *do_index);
+  
+  /* Also update window title based on filename */
+  short_fn = GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
+                                                           
EXTRACTOR_METATYPE_FILENAME,
+                                                           -1);
+  if (NULL == short_fn)
+  {
+    gtk_window_set_title (ctx->edit_publication_window, _("<unnamed>"));
+  }
+  else
+  {
+    /* FIXME: ensure that short_fn is UTF-8 encoded */
+    gtk_window_set_title (ctx->edit_publication_window, short_fn);
+    GNUNET_free (short_fn);
+  }
   return GNUNET_SYSERR;         /* only visit top-level item */
 }
 
 
-void
-GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget, struct 
EditPublicationDialogContext *ctx)
-{
-  GtkTreeSelection *meta_selection;
-  GtkTreeSelection *keywords_selection;
-
-  /* FIXME: these can be set by (modern) versions of Glade */
-  keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview);
-  meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview);
-
-  g_signal_connect (G_OBJECT (keywords_selection), "changed",
-                    G_CALLBACK (keywords_selection_changed_cb), ctx);
-
-  g_signal_connect (G_OBJECT (meta_selection), "changed",
-                    G_CALLBACK (metadata_selection_changed_cb), ctx);
-}
-
 /**
  * Open the dialog to edit file information data.
- * short_fn MUST be UTF-8-encoded
+ *
+ * @param parent parent window of the dialog
+ * @param fip information about the file information that is to be edited
+ * @param allow_no_keywords is it OK to close the dialog without any keywords?
+ *                          also used to indicate that this is a namespace 
operation
+ *                          (FIXME: overloaded/badly-named argument)
+ * @param anon_liststore liststore with anonymity options (FIXME: bad sharing)
+ * @param cb function to call when the dialog is closed
+ * @param cb_cls closure for 'cb'
  */
 void
 GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
-                                  const char *short_fn,
                                    struct GNUNET_FS_FileInformation *fip,
-                                   gboolean allow_no_keywords,
+                                   int allow_no_keywords,
                                    GtkListStore *anon_liststore,
                                    GNUNET_FS_GTK_EditPublishDialogCallback cb,
                                    gpointer cb_cls)
@@ -1022,8 +1027,17 @@
   GtkLabel *index_label;
   GtkLabel *root_label;
   struct EditPublicationDialogContext *ctx;
+  GtkTreeSelection *meta_selection;
+  GtkTreeSelection *keywords_selection;
 
   ctx = GNUNET_malloc (sizeof (struct EditPublicationDialogContext));
+  ctx->fip = fip;
+  ctx->preview_changed = GNUNET_NO;
+  ctx->allow_no_keywords = allow_no_keywords;
+  ctx->is_directory = GNUNET_FS_file_information_is_directory (fip);
+  ctx->cb = cb;
+  ctx->cb_cls = cb_cls;
+  ctx->meta_combo_selected_type_id = -1;
   ctx->builder = GNUNET_GTK_get_new_builder 
("gnunet_fs_gtk_edit_publication.glade", ctx);
 
   if (ctx->builder == NULL)
@@ -1031,7 +1045,8 @@
     GNUNET_free (ctx);
     return;
   }
-  ctx->meta_combo_selected_type_id = -1;
+
+  /* obtain various widgets for use later */
   ctx->pubtypes_liststore =
       GTK_LIST_STORE (gtk_builder_get_object
                       (ctx->builder, 
"GNUNET_GTK_publication_types_liststore"));
@@ -1046,7 +1061,8 @@
                       (ctx->builder,
                        "GNUNET_GTK_edit_publication_keyword_list_tree_view"));
   ctx->edit_publication_window =
-    GTK_WINDOW (gtk_builder_get_object (ctx->builder, 
"GNUNET_GTK_edit_publication_window"));
+    GTK_WINDOW (gtk_builder_get_object (ctx->builder, 
+                                       "GNUNET_GTK_edit_publication_window"));
   ctx->keywords_liststore = GTK_LIST_STORE (gtk_builder_get_object
                        (ctx->builder, 
"GNUNET_GTK_publication_keywords_liststore"));
   ctx->keyword_entry =
@@ -1061,11 +1077,8 @@
   ctx->meta_liststore = GTK_LIST_STORE (gtk_builder_get_object
                          (ctx->builder,
                           "GNUNET_GTK_publication_metadata_liststore"));
-
   ctx->root_entry = GTK_ENTRY (gtk_builder_get_object
                     (ctx->builder, "GNUNET_GTK_edit_publication_root_entry"));
-
-
   ctx->expiration_year_spin = GTK_SPIN_BUTTON
                              (gtk_builder_get_object
                               (ctx->builder,
@@ -1083,33 +1096,18 @@
                                  (ctx->builder,
                                   
"GNUNET_GTK_edit_publication_index_checkbutton"));
   ctx->anonymity_combo = GTK_COMBO_BOX (gtk_builder_get_object (ctx->builder,
-      "GNUNET_GTK_edit_publication_anonymity_combobox"));
-  gtk_combo_box_set_model (ctx->anonymity_combo, GTK_TREE_MODEL 
(anon_liststore));
-  ctx->anonymity_liststore = anon_liststore;
+                                                               
"GNUNET_GTK_edit_publication_anonymity_combobox"));
 
+  /* Basic initialization of widgets models and visibility */
+  gtk_combo_box_set_model (ctx->anonymity_combo, 
+                          GTK_TREE_MODEL (anon_liststore));
   GNUNET_FS_GTK_setup_expiration_year_adjustment (ctx->builder);
-  /* indexing does not apply to directories */
-  gtk_widget_set_visible (GTK_WIDGET (ctx->index_checkbutton),
-      !GNUNET_FS_file_information_is_directory (fip));
-  index_label = GTK_LABEL (gtk_builder_get_object
-                    (ctx->builder, "GNUNET_GTK_edit_publication_index_label"));
-  gtk_widget_set_visible (GTK_WIDGET (index_label),
-      !GNUNET_FS_file_information_is_directory (fip));
-  gtk_widget_set_visible (GTK_WIDGET (ctx->root_entry),
-      !allow_no_keywords);
-  root_label = GTK_LABEL (gtk_builder_get_object
-                         (ctx->builder, 
"GNUNET_GTK_edit_publication_root_label"));
-  gtk_widget_set_visible (GTK_WIDGET (root_label),
-      !allow_no_keywords);
 
+  /* FIXME-UNCLEAN: are the following three even required anymore? */
   gtk_list_store_clear (ctx->keywords_liststore);
   gtk_list_store_clear (ctx->meta_liststore);
+  gtk_entry_set_text (ctx->keyword_entry, "");
 
-  if (NULL != short_fn)
-    gtk_window_set_title (ctx->edit_publication_window, short_fn);
-  else                                                       
-    gtk_window_set_title (ctx->edit_publication_window, _("<unnamed>"));
-
   pubtypes_combo =
       GTK_COMBO_BOX (gtk_builder_get_object
                      (ctx->builder, "GNUNET_GTK_edit_publication_type_combo"));
@@ -1121,19 +1119,42 @@
   else
     gtk_combo_box_set_active (pubtypes_combo, 0);
 
-  if (NULL != short_fn)
-    ctx->short_fn = GNUNET_strdup (short_fn);
-  ctx->fip = fip;
-  ctx->preview_changed = GNUNET_NO;
-  ctx->allow_no_keywords = allow_no_keywords;
-  ctx->is_directory = GNUNET_FS_file_information_is_directory (fip);
-  ctx->cb = cb;
-  ctx->cb_cls = cb_cls;
+  /* indexing does not apply to directories */
+  gtk_widget_set_visible (GTK_WIDGET (ctx->index_checkbutton),
+                         ! ctx->is_directory);
+  index_label = GTK_LABEL (gtk_builder_get_object
+                          (ctx->builder,
+                           "GNUNET_GTK_edit_publication_index_label"));
+  gtk_widget_set_visible (GTK_WIDGET (index_label),
+                         ! ctx->is_directory);
 
-  GNUNET_FS_file_information_inspect (fip, &file_information_extract, ctx);
+  /* show root label only if we must have keywords, which is also only the
+     case for namespaces (FIXME-UNCLEAN: overloaded use of the argument) */
+  gtk_widget_set_visible (GTK_WIDGET (ctx->root_entry),
+                         !allow_no_keywords);
+  root_label = GTK_LABEL (gtk_builder_get_object
+                         (ctx->builder, 
"GNUNET_GTK_edit_publication_root_label"));
+  gtk_widget_set_visible (GTK_WIDGET (root_label),
+                         !allow_no_keywords);
+  
+  /* FIXME-UNCLEAN: what if we already have keywords? Again, does not really
+     apply to namespace-case, but this seems a bit ugly */
+  gtk_widget_set_sensitive (ctx->confirm_button, allow_no_keywords ? TRUE : 
FALSE);
 
-  gtk_entry_set_text (ctx->keyword_entry, "");
-  gtk_widget_set_sensitive (ctx->confirm_button, allow_no_keywords ? TRUE : 
FALSE);
+
+  /* FIXME: these signal handlers can be set by (modern) versions of Glade */
+  keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview);
+  g_signal_connect (G_OBJECT (keywords_selection), "changed",
+                    G_CALLBACK (keywords_selection_changed_cb), ctx);
+  meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview);
+  g_signal_connect (G_OBJECT (meta_selection), "changed",
+                    G_CALLBACK (metadata_selection_changed_cb), ctx);
+
+  /* import meta data and options */
+  GNUNET_FS_file_information_inspect (fip, &file_information_import, ctx);
+
+
+  /* Finally, display window */
   gtk_window_set_transient_for (ctx->edit_publication_window, parent);
   gtk_window_present (ctx->edit_publication_window);
 }

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.h       2012-02-02 
12:47:26 UTC (rev 19627)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.h       2012-02-02 
12:57:54 UTC (rev 19628)
@@ -34,29 +34,31 @@
  * Function called when the edit publish dialog has been closed.
  *
  * @param cls closure
- * @param do_index index flag set?
- * @param short_fn short filename
- * @param anonymity_level anonymity degree chosen for publishing
- * @param priority replication setting (rename!)
+ * @param ret GTK_RESPONSE_OK if the dialog was closed with "OK"
  * @param root namespace root, NULL for file publishing
- * @param ret GTK_RESPONSE_OK if the dialog was closed with "OK"
  */
 typedef void (*GNUNET_FS_GTK_EditPublishDialogCallback) (gpointer cls,
-                                                         int do_index,
-                                                         const char *short_fn,
-                                                        const struct 
GNUNET_FS_BlockOptions *bo,
-                                                         const char *root,
-                                                         int ret);
+                                                        int ret,
+                                                         const char *root);
 
 
 /**
  * Open the dialog to edit file information data.
+ *
+ * @param parent parent window of the dialog
+ * @param fip information about the file information that is to be edited
+ * @param allow_no_keywords is it OK to close the dialog without any keywords?
+ *                          also used to indicate that this is a namespace 
operation
+ *                          (FIXME: overloaded/badly-named argument)
+ * @param anon_liststore liststore with anonymity options (FIXME: bad sharing)
+ * @param cb function to call when the dialog is closed
+ * @param cb_cls closure for 'cb'
  */
 void
 GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
-                                   const char *short_fn,
                                    struct GNUNET_FS_FileInformation *fip,
-                                   gboolean allow_no_keywords, GtkListStore 
*anon_liststore,
+                                   int allow_no_keywords, 
+                                  GtkListStore *anon_liststore,
                                    GNUNET_FS_GTK_EditPublishDialogCallback cb,
                                    gpointer cls);
 

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c 2012-02-02 
12:47:26 UTC (rev 19627)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c 2012-02-02 
12:57:54 UTC (rev 19628)
@@ -26,6 +26,8 @@
 #include "gnunet-fs-gtk.h"
 #include "gnunet-fs-gtk-edit_publish_dialog.h"
 
+
+
 gboolean
 GNUNET_GTK_select_pseudonym_dialog_delete_event_cb (GtkWidget * widget,
                                                     GdkEvent * event,
@@ -35,6 +37,7 @@
   return TRUE;
 }
 
+
 /**
  * Callback with information about local (!) namespaces.
  * Contains the names of the local namespace and the global
@@ -74,12 +77,10 @@
     gtk_widget_set_sensitive (ok_button, FALSE);
 }
 
+
 struct NamespaceAdvertisementContext
 {
   struct GNUNET_FS_Namespace *ns;
-  int do_index;
-  const char *short_fn;
-  struct GNUNET_FS_BlockOptions bo;
   const char *root;
   struct GNUNET_FS_FileInformation *fip;
 };
@@ -116,26 +117,24 @@
 
 
 static void
-adv_pseudonym_edit_publish_dialog_cb (gpointer cls, int do_index,
-                                      const char *short_fn,
-                                      const struct GNUNET_FS_BlockOptions *bo,
-                                      const char *root, gint ret)
+adv_pseudonym_edit_publish_dialog_cb (gpointer cls, 
+                                     gint ret,
+                                      const char *root)
 {
   struct NamespaceAdvertisementContext *nds = cls;
 
   if (ret == GTK_RESPONSE_OK)
   {
-    nds->do_index = do_index;
-    nds->short_fn = short_fn;
-    nds->bo = *bo;
     nds->root = root;
     GNUNET_FS_file_information_inspect (nds->fip, &advertise_namespace, nds);
+    nds->root = NULL;
   }
   GNUNET_FS_namespace_delete (nds->ns, GNUNET_NO);
   GNUNET_FS_file_information_destroy (nds->fip, NULL, NULL);
   GNUNET_free (nds);
 }
 
+
 void
 GNUNET_GTK_select_pseudonym_dialog_response_cb (GtkDialog * dialog,
                                                 gint response_id,
@@ -153,6 +152,7 @@
   GtkListStore *anon_liststore;
   struct NamespaceAdvertisementContext *nds;
   struct GNUNET_CONTAINER_MetaData *meta;
+  struct GNUNET_FS_BlockOptions bo;
 
   builder = GTK_BUILDER (user_data);
   ad = GTK_WIDGET (gtk_builder_get_object
@@ -189,28 +189,27 @@
 
   nds = GNUNET_malloc (sizeof (struct NamespaceAdvertisementContext));
   nds->ns = ns;
-  nds->do_index = FALSE;
-  nds->short_fn = NULL;
-  nds->bo.anonymity_level = 1;
-  nds->bo.content_priority = 1000;
-  nds->root = NULL;
   /* This is a bogus fileinfo. It's needed because edit_publish_dialog
    * was written to work with fileinfo, and return a fileinfo.
    */
-  memset (&nds->bo, 0, sizeof (struct GNUNET_FS_BlockOptions));
-  nds->bo.expiration_time =
+  memset (&bo, 0, sizeof (struct GNUNET_FS_BlockOptions));
+  bo.expiration_time =
     GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
-  nds->bo.anonymity_level = 1;
+  bo.anonymity_level = 1;
+  bo.content_priority = 1000;
   nds->fip =
       GNUNET_FS_file_information_create_empty_directory (NULL, NULL, NULL, 
meta,
-                                                         &nds->bo, NULL);
+                                                         &bo, NULL);
   GNUNET_CONTAINER_meta_data_destroy (meta);
   GNUNET_FS_GTK_edit_publish_dialog (transient, 
-                                     nds->short_fn, nds->fip, FALSE, 
anon_liststore,
+                                    nds->fip, 
+                                    GNUNET_NO,
+                                    anon_liststore,
                                      &adv_pseudonym_edit_publish_dialog_cb,
                                      nds);
 }
 
+
 void
 GNUNET_GTK_select_pseudonym_dialog_realize_cb (GtkWidget * widget,
                                                gpointer user_data)
@@ -228,6 +227,7 @@
                     G_CALLBACK (selection_changed_cb), user_data);
 }
 
+
 /**
  * Advertise pseudonym selected.
  */

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c  2012-02-02 
12:47:26 UTC (rev 19627)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c  2012-02-02 
12:57:54 UTC (rev 19628)
@@ -1037,44 +1037,66 @@
 
 struct EditPublishContext
 {
+  struct GNUNET_FS_FileInformation *fip;
+
   GtkTreeModel *tm;
+
   GtkTreeIter iter;
 };
 
 
 /**
+ * Update tree view based on the information from the
+ * GNUNET_FS_FileInformation publish-structure.
+ *
+ * @param cls closure, a 'struct EditPublishContext *'
+ * @param fi the entry in the publish-structure
+ * @param length length of the file or directory
+ * @param meta metadata for the file or directory (can be modified)
+ * @param uri pointer to the keywords that will be used for this entry (can be 
modified)
+ * @param bo block options (can be modified)
+ * @param do_index should we index (can be modified)
+ * @param client_info pointer to client context set upon creation (can be 
modified)
+ * @return GNUNET_OK to continue, GNUNET_NO to remove
+ *         this entry from the directory, GNUNET_SYSERR
+ *         to abort the iteration
+ */
+static int
+update_treeview_after_edit (void *cls, struct GNUNET_FS_FileInformation *fi,
+                           uint64_t length, struct GNUNET_CONTAINER_MetaData 
*meta,
+                           struct GNUNET_FS_Uri **uri,
+                           struct GNUNET_FS_BlockOptions *bo, int *do_index,
+                           void **client_info)
+{
+  struct EditPublishContext *epc = cls;
+  
+  gtk_tree_store_set (GTK_TREE_STORE (epc->tm), &epc->iter, 
+                     1, *do_index,
+                     3, (guint) bo->anonymity_level, 
+                     4, (guint) bo->content_priority, 
+                     6, (guint64) bo->expiration_time.abs_value,
+                     7, (guint) bo->replication_level,                 
+                     -1); 
+  return GNUNET_SYSERR;
+}
+
+
+/**
  * Function called when the edit publish dialog has been closed.
  *
  * @param cls closure
- * @param do_index index flag set?
- * @param short_fn short filename
- * @param bo block options for publishing
- * @param root always NULL here
  * @param ret GTK_RESPONSE_OK if the dialog was closed with "OK"
+ * @param root unused (namespace root name)
  */
 static void
-master_publish_edit_publish_dialog_cb (gpointer cls, int do_index,
-                                       const char *short_fn,
-                                       const struct GNUNET_FS_BlockOptions *bo,
-                                       const char *root,
-                                       gint ret)
+master_publish_edit_publish_dialog_cb (gpointer cls,
+                                      gint ret,
+                                       const char *root)
 {
   struct EditPublishContext *cbargs = cls;
-  struct GNUNET_FS_FileInformation *fi;
 
   if (ret == GTK_RESPONSE_OK)
-  {
-    gtk_tree_store_set (GTK_TREE_STORE (cbargs->tm), &cbargs->iter, 
-                       1, do_index,
-                        2, short_fn,
-                       3, (guint) bo->anonymity_level, 
-                       4, (guint) bo->content_priority, 
-                       6, (guint64) bo->expiration_time.abs_value,
-                       7, (guint) bo->replication_level,                       
-                       -1);
-    gtk_tree_model_get (cbargs->tm, &cbargs->iter, 5, &fi, -1);
-    GNUNET_FS_file_information_set_filename (fi, short_fn);
-  }
+    GNUNET_FS_file_information_inspect (cbargs->fip, 
&update_treeview_after_edit, cbargs);
   GNUNET_free (cbargs);
 }
 
@@ -1084,8 +1106,6 @@
                                                          struct 
MainPublishingDialogContext *ctx)
 {
   struct EditPublishContext *cbargs;
-  char *short_fn;
-  struct GNUNET_FS_FileInformation *fip;
   GtkListStore *anon_liststore;
 
   anon_liststore = GTK_LIST_STORE (gtk_builder_get_object 
(ctx->main_window_builder, 
@@ -1099,13 +1119,14 @@
     return;
   }
   gtk_tree_model_get (ctx->file_info_treemodel, &cbargs->iter,
-                     2, &short_fn, 
-                     5, &fip, 
+                     5, &cbargs->fip, 
                      -1);
   /* FIXME: can we just give our anon_liststore out like this? What about
      (unintended) sharing of state? */
   GNUNET_FS_GTK_edit_publish_dialog (ctx->master_pubdialog, 
-                                     short_fn, fip, TRUE, anon_liststore,
+                                     cbargs->fip, 
+                                    GNUNET_YES, 
+                                    anon_liststore,
                                      &master_publish_edit_publish_dialog_cb,
                                      cbargs);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]