gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r18759 - gnunet-gtk/src/fs
Date: Fri, 23 Dec 2011 10:43:13 +0100

Author: grothoff
Date: 2011-12-23 10:43:13 +0100 (Fri, 23 Dec 2011)
New Revision: 18759

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:
-fixing various crashes introduced by recent #1759-related patches, also some 
major 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       2011-12-23 
08:38:58 UTC (rev 18758)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c       2011-12-23 
09:43:13 UTC (rev 18759)
@@ -30,21 +30,22 @@
 
 #define PUBSTATE "edit-publication-state"
 
-struct edit_publication_state
+struct EditPublicationState
 {
-  int *do_index;
-  char **short_fn;
-  guint *anonymity_level;
-  guint *priority;
+  int do_index;
+  char *short_fn;
+  guint anonymity_level;
+  guint priority;
   struct GNUNET_FS_FileInformation *fip;
   gint preview_changed;
   gboolean allow_no_keywords;
   gboolean is_directory;
-  GNUNET_FS_GTK_edit_publish_dialog_cb cb;
+  GNUNET_FS_GTK_EditPublishDialogCallback cb;
   gchar *root;
   gpointer cls;
 };
 
+
 static void
 metadata_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data)
 {
@@ -67,6 +68,7 @@
                             gtk_tree_selection_get_selected (sel, NULL, NULL));
 }
 
+
 static void
 keywords_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data)
 {
@@ -100,7 +102,7 @@
 
 void
 GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget,
-    gpointer user_data)
+                                              gpointer user_data)
 {
   GtkBuilder *builder;
   GtkListStore *metatypes_list;
@@ -135,9 +137,10 @@
         3, EXTRACTOR_metatype_to_description (type), -1);
 }
 
+
 void
 GNUNET_GTK_edit_publication_add_button_clicked_cb (GtkButton *button,
-    gpointer user_data)
+                                                  gpointer user_data)
 {
   GtkBuilder *builder;
   GtkTreeView *meta_tree;
@@ -155,9 +158,10 @@
       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, gpointer user_data)
+                                                             GdkEventKey 
*event, gpointer user_data)
 {
   GtkBuilder *builder;
   GtkButton *add_button;
@@ -173,10 +177,11 @@
   return FALSE;
 }
 
+
 void
-GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb (
-    GtkCellRendererText *renderer, gchar *path, gchar *new_text,
-    gpointer user_data)
+GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb 
(GtkCellRendererText *renderer, 
+                                                                       gchar 
*path, gchar *new_text,
+                                                                       
gpointer user_data)
 {
   GtkBuilder *builder;
   GtkTreeView *meta_tree;
@@ -212,6 +217,7 @@
   g_free (description);
 }
 
+
 void
 GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb (
     GtkCellRendererCombo *combo, gchar *path_string, GtkTreeIter *new_iter,
@@ -227,6 +233,7 @@
   g_object_set_data (G_OBJECT (combo), "selected-type", pass_data);
 }
 
+
 void
 GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb (
     GtkCellRendererText *renderer, gchar *path, gchar *new_text,
@@ -243,7 +250,7 @@
   char *pos;
 
   GObject *pubwindow;
-  struct edit_publication_state *state = NULL;
+  struct EditPublicationState *state = NULL;
 
   builder = GTK_BUILDER (user_data);
   meta_tree = GTK_TREE_VIEW (gtk_builder_get_object (builder,
@@ -296,9 +303,10 @@
   GNUNET_free_non_null (avalue);
 }
 
+
 void
 GNUNET_GTK_edit_publication_delete_button_clicked_cb (GtkButton *button,
-    gpointer user_data)
+                                                     gpointer user_data)
 {
   GtkTreeView *tv;
   GtkTreeSelection *sel;
@@ -319,9 +327,10 @@
     gtk_tree_selection_select_iter (sel, &iter);
 }
 
+
 void
 GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb (
-    GtkButton *button, gpointer user_data)
+                                                               GtkButton 
*button, gpointer user_data)
 {
   const char *keyword;
   GtkEntry *entry;
@@ -348,15 +357,26 @@
   gtk_entry_set_text (entry, "");
 }
 
-gboolean
-gtk_tree_model_get_item_count_cb (GtkTreeModel *model, GtkTreePath *path,
+
+static gboolean
+gtk_tree_model_has_items_cb (GtkTreeModel *model, GtkTreePath *path,
     GtkTreeIter *iter, gpointer data)
 {
-  gint *counter = (gint *) data;
-  *counter += 1;
-  return FALSE;
+  gboolean *val = (gboolean *) data;
+  *val = TRUE;
+  return TRUE;
 }
 
+
+static gboolean
+gtk_tree_model_has_items (GtkTreeModel *model)
+{
+  gboolean b = FALSE;
+  gtk_tree_model_foreach (model, &gtk_tree_model_has_items_cb, &b);
+  return b;
+}
+
+
 void
 GNUNET_GTK_edit_publication_keyword_entry_changed_cb (GtkEditable *editable,
     gpointer user_data)
@@ -380,31 +400,6 @@
 }
 
 
-gint
-gtk_tree_model_get_item_count (GtkTreeModel *model)
-{
-  gint c = 0;
-  gtk_tree_model_foreach (model, &gtk_tree_model_get_item_count_cb, &c);
-  return c;
-}
-
-gboolean
-gtk_tree_model_has_items_cb (GtkTreeModel *model, GtkTreePath *path,
-    GtkTreeIter *iter, gpointer data)
-{
-  gboolean *val = (gboolean *) data;
-  *val = TRUE;
-  return TRUE;
-}
-
-gboolean
-gtk_tree_model_has_items (GtkTreeModel *model)
-{
-  gboolean b = FALSE;
-  gtk_tree_model_foreach (model, &gtk_tree_model_has_items_cb, &b);
-  return b;
-}
-
 void
 GNUNET_GTK_edit_publication_keyword_list_del_button_clicked_cb (
     GtkButton *button, gpointer user_data)
@@ -416,7 +411,7 @@
   GtkBuilder *builder;
   GtkWidget *ok;
   GObject *pubwindow;
-  struct edit_publication_state *state = NULL;
+  struct EditPublicationState *state = NULL;
   builder = GTK_BUILDER (user_data);
 
   tv = GTK_TREE_VIEW (gtk_builder_get_object
@@ -448,6 +443,7 @@
     gtk_widget_set_sensitive (ok, FALSE);
 }
 
+
 void
 GNUNET_GTK_edit_publication_keyword_list_normalize_button_clicked_cb (
     GtkButton *button, gpointer user_data)
@@ -494,6 +490,7 @@
   g_free (value);
 }
 
+
 void
 GNUNET_GTK_edit_publication_normalization_checkbox_toggled_cb (
     GtkToggleButton *button, gpointer user_data)
@@ -507,6 +504,7 @@
       !gtk_toggle_button_get_active (norm_button));
 }
 
+
 void
 GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button_file_set_cb (
     GtkFileChooserButton *widget, gpointer user_data)
@@ -515,7 +513,7 @@
   GtkImage *image;
   GObject *pubwindow;
   GtkBuilder *builder = GTK_BUILDER (user_data);
-  struct edit_publication_state *state = NULL;
+  struct EditPublicationState *state = NULL;
 
   pubwindow = gtk_builder_get_object (builder,
       "GNUNET_GTK_edit_publication_window");
@@ -535,19 +533,22 @@
   state->preview_changed = GNUNET_YES;
 }
 
-struct fiu_context
+
+struct FileInformationUpdateContext
 {
   GtkBuilder *builder;
-  char **short_fn;
+  char *short_fn;
   gchar *root;
   struct GNUNET_CONTAINER_MetaData *md;
+  gboolean allow_no_keywords;
 };
 
+
 /**
  * Copy binary meta data from to the new container and also
  * preserve all entries that were not changed.
  *
- * @param cls closure, new meta data container
+ * @param cls closure, a 'struct FileInformationUpdateContext'
  * @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
@@ -567,7 +568,7 @@
                      const char *data_mime_type, const char *data,
                      size_t data_len)
 {
-  struct fiu_context *context = (struct fiu_context *) cls;
+  struct FileInformationUpdateContext *context = cls;
   GtkBuilder *builder = context->builder;
   struct GNUNET_CONTAINER_MetaData *md = context->md;
   GtkTreeModel *tm;
@@ -578,7 +579,7 @@
   int keep;
 
   GObject *pubwindow;
-  struct edit_publication_state *state = NULL;
+  struct EditPublicationState *state = NULL;
 
   pubwindow = gtk_builder_get_object (builder,
       "GNUNET_GTK_edit_publication_window");
@@ -636,7 +637,7 @@
 /**
  * Function called to update the information in FI.
  *
- * @param cls closure (short_fn to update)
+ * @param cls closure with a 'struct FileInformationUpdateContext *'
  * @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)
@@ -654,8 +655,8 @@
                          struct GNUNET_FS_BlockOptions *bo, int *do_index,
                          void **client_info)
 {
-  struct fiu_context *context = (struct fiu_context *) cls;
-  char **short_fn = context->short_fn;
+  struct FileInformationUpdateContext *context = cls;
+  char **short_fn = &context->short_fn;
   GtkBuilder *builder = context->builder;
   struct GNUNET_CONTAINER_MetaData *nm;
   GtkTreeModel *tm;
@@ -673,9 +674,8 @@
   GFile *f;
   GFileInfo *finfo;
   gboolean auto_normalize = FALSE;
-
   GObject *pubwindow;
-  struct edit_publication_state *state = NULL;
+  struct EditPublicationState *state = NULL;
 
   pubwindow = gtk_builder_get_object (builder,
       "GNUNET_GTK_edit_publication_window");
@@ -708,13 +708,15 @@
                          
"GNUNET_GTK_edit_publication_expiration_year_spin_button"));
   bo->expiration_time = GNUNET_FS_GTK_get_expiration_time (sb);
 
-  g_free (context->root);
-  context->root =
+  if (! context->allow_no_keywords)
+  {
+    g_free (context->root);
+    context->root =
       g_strdup (gtk_entry_get_text (GTK_ENTRY
-                          (gtk_builder_get_object
-                           (builder,
-                            "GNUNET_GTK_edit_publication_root_entry"))));
-
+                                   (gtk_builder_get_object
+                                    (builder,
+                                     
"GNUNET_GTK_edit_publication_root_entry"))));
+  }
   /* update URI */
   if (NULL != (*uri))
     GNUNET_FS_uri_destroy (*uri);
@@ -819,13 +821,14 @@
   return GNUNET_SYSERR;         /* only visit top-level item */
 }
 
+
 void
 GNUNET_GTK_edit_publication_cancel_button_clicked_cb (
     GtkButton *button, gpointer user_data)
 {
   GtkBuilder *builder;
   GObject *pubwindow;
-  struct edit_publication_state *state = NULL;
+  struct EditPublicationState *state = NULL;
 
   builder = GTK_BUILDER (user_data);
 
@@ -839,20 +842,20 @@
   }
 
   state->cb (state->cls, state->do_index, state->short_fn,
-      state->anonymity_level, state->priority, NULL, state->fip, 
GTK_RESPONSE_CANCEL);
+            state->anonymity_level, state->priority, NULL, 
GTK_RESPONSE_CANCEL);
   g_free (state);
   g_object_set_data (pubwindow, PUBSTATE, NULL);
   gtk_widget_hide (GTK_WIDGET (pubwindow));
 }
 
+
 void
-GNUNET_GTK_edit_publication_confirm_button_clicked_cb (
-    GtkButton *button, gpointer user_data)
+GNUNET_GTK_edit_publication_confirm_button_clicked_cb (GtkButton *button, 
gpointer user_data)
 {
   GtkBuilder *builder;
   GObject *pubwindow;
-  struct edit_publication_state *state = NULL;
-  struct fiu_context ctx;
+  struct EditPublicationState *state;
+  struct FileInformationUpdateContext ctx;
 
   builder = GTK_BUILDER (user_data);
 
@@ -869,30 +872,37 @@
   ctx.short_fn = state->short_fn;
   ctx.root = NULL;
   ctx.md = NULL;
+  ctx.allow_no_keywords = state->allow_no_keywords;
 
   GNUNET_FS_file_information_inspect (state->fip, &file_information_update, 
&ctx);
   if (!GNUNET_GTK_get_selected_anonymity_level (builder,
-      "GNUNET_GTK_edit_publication_anonymity_combobox", 
state->anonymity_level))
-  *state->priority =
+                                               
"GNUNET_GTK_edit_publication_anonymity_combobox", 
+                                               &state->anonymity_level))
+    state->priority =
       gtk_spin_button_get_value (GTK_SPIN_BUTTON
                                  (gtk_builder_get_object
                                   (builder,
                                    
"GNUNET_GTK_edit_publication_priority_spin_button")));
-  *state->do_index =
-      gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
-                                    (gtk_builder_get_object
-                                     (builder,
-                                      
"GNUNET_GTK_edit_publication_index_checkbutton")));
+  state->do_index =
+    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
+                                 (gtk_builder_get_object
+                                  (builder,
+                                   
"GNUNET_GTK_edit_publication_index_checkbutton")));
 
 
-  state->cb (state->cls, state->do_index, state->short_fn,
-      state->anonymity_level, state->priority, ctx.root, state->fip,
-      GTK_RESPONSE_OK);
-  g_free (state);
+  state->cb (state->cls, 
+            state->do_index,
+            state->short_fn,
+            state->anonymity_level, 
+            state->priority, ctx.root, 
+            GTK_RESPONSE_OK);
+  GNUNET_free (state->short_fn);
+  GNUNET_free (state);
   g_object_set_data (pubwindow, PUBSTATE, NULL);
   gtk_widget_hide (GTK_WIDGET (pubwindow));
 }
 
+
 /**
  * Add each of the keywords to the keyword list store.
  *
@@ -912,6 +922,7 @@
   return GNUNET_OK;
 }
 
+
 /**
  * Function called to extract the information from FI.
  *
@@ -973,7 +984,7 @@
                                
"GNUNET_GTK_edit_publication_expiration_year_spin_button")),
                              year);
   GNUNET_GTK_select_anonymity_level (builder,
-      "GNUNET_GTK_edit_publication_anonymity_combobox", bo->anonymity_level);
+                                    
"GNUNET_GTK_edit_publication_anonymity_combobox", bo->anonymity_level);
   gtk_spin_button_set_value (GTK_SPIN_BUTTON
                              (gtk_builder_get_object
                               (builder,
@@ -992,16 +1003,21 @@
  * Open the dialog to edit file information data.
  */
 void
-GNUNET_FS_GTK_edit_publish_dialog (GtkBuilder *builder, GtkWindow *parent, int 
*do_index,
-    char **short_fn, guint *anonymity_level, guint *priority,
-    struct GNUNET_FS_FileInformation *fip, gboolean allow_no_keywords,
-    GNUNET_FS_GTK_edit_publish_dialog_cb cb, gpointer cls)
+GNUNET_FS_GTK_edit_publish_dialog (GtkBuilder *builder, 
+                                  GtkWindow *parent, 
+                                  int do_index,
+                                  const char *short_fn, 
+                                  uint32_t anonymity_level, 
+                                  uint32_t priority,
+                                  struct GNUNET_FS_FileInformation *fip,
+                                  gboolean allow_no_keywords,
+                                  GNUNET_FS_GTK_EditPublishDialogCallback cb, 
gpointer cls)
 {
   GtkWidget *dialog;
   GObject *pubwindow;
   GtkEntry *entry;
   GtkWidget *ok;
-  struct edit_publication_state *state;
+  struct EditPublicationState *state;
 
   GNUNET_FS_GTK_setup_expiration_year_adjustment (builder);
   if (GNUNET_FS_file_information_is_directory (fip))
@@ -1019,9 +1035,9 @@
   if (allow_no_keywords)
   {
     gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (builder,
-        "GNUNET_GTK_edit_publication_root_entry")));
+                                                        
"GNUNET_GTK_edit_publication_root_entry")));
     gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (builder,
-        "GNUNET_GTK_edit_publication_root_label")));
+                                                        
"GNUNET_GTK_edit_publication_root_label")));
   }
   gtk_list_store_clear (GTK_LIST_STORE (gtk_builder_get_object (
       builder, "GNUNET_GTK_publication_keywords_liststore")));
@@ -1029,18 +1045,15 @@
       builder, "GNUNET_GTK_publication_metadata_liststore")));
 
   GNUNET_FS_file_information_inspect (fip, &file_information_extract, builder);
-
   dialog = GTK_WIDGET (gtk_builder_get_object (builder,
-      "GNUNET_GTK_edit_publication_window"));
+                                              
"GNUNET_GTK_edit_publication_window"));
+  gtk_window_set_title (GTK_WINDOW (dialog), short_fn);
 
-  gtk_window_set_title (GTK_WINDOW (dialog), *short_fn);
-
-  state = g_new0 (struct edit_publication_state, 1);
+  state = GNUNET_malloc (sizeof (struct EditPublicationState));
   state->do_index = do_index;
-  state->short_fn = short_fn;
-  state->root = NULL;
-  state->anonymity_level = anonymity_level;
-  state->priority = priority;
+  state->short_fn = GNUNET_strdup (short_fn);
+  state->anonymity_level = (guint) anonymity_level;
+  state->priority = (guint) priority;
   state->fip = fip;
   state->preview_changed = GNUNET_NO;
   state->allow_no_keywords = allow_no_keywords;
@@ -1052,18 +1065,15 @@
       GTK_ENTRY (gtk_builder_get_object
                  (builder, "GNUNET_GTK_edit_publication_keyword_entry"));
   gtk_entry_set_text (entry, "");
-
   pubwindow = gtk_builder_get_object (builder,
-      "GNUNET_GTK_edit_publication_window");
+                                     "GNUNET_GTK_edit_publication_window");
   g_object_set_data (pubwindow, PUBSTATE, state);
-
   ok = GTK_WIDGET (gtk_builder_get_object (builder,
-      "GNUNET_GTK_edit_publication_confirm_button"));
+                                          
"GNUNET_GTK_edit_publication_confirm_button"));
   gtk_widget_set_sensitive (ok, allow_no_keywords ? TRUE : FALSE);
-
   gtk_window_set_transient_for (GTK_WINDOW (pubwindow), parent);
-
   gtk_window_present (GTK_WINDOW (dialog));
 }
 
+
 /* end of gnunet-fs-gtk-edit_publish_dialog.c */

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.h       2011-12-23 
08:38:58 UTC (rev 18758)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.h       2011-12-23 
09:43:13 UTC (rev 18759)
@@ -30,20 +30,39 @@
 #include <gnunet/gnunet_fs_service.h>
 
 
+/**
+ * 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 root namespace root, NULL for file publishing
+ * @param ret GTK_RESPONSE_OK if the dialog was closed with "OK"
+ */
 typedef void
-(*GNUNET_FS_GTK_edit_publish_dialog_cb) (gpointer cls, int *do_index, char 
**short_fn,
-                                   guint * anonymity_level, guint * priority, 
gchar *root,
-                                   struct GNUNET_FS_FileInformation *fip, gint 
ret);
+(*GNUNET_FS_GTK_EditPublishDialogCallback) (gpointer cls, int do_index, 
+                                           const char *short_fn,
+                                           guint anonymity_level, 
+                                           guint priority, 
+                                           const char *root,
+                                           int ret);
 
 
 /**
  * Open the dialog to edit file information data.
  */
 void
-GNUNET_FS_GTK_edit_publish_dialog (GtkBuilder *builder, GtkWindow *parent, int 
*do_index,
-    char **short_fn, guint * anonymity_level, guint * priority,
-    struct GNUNET_FS_FileInformation *fip, gboolean allow_no_keywords,
-    GNUNET_FS_GTK_edit_publish_dialog_cb cb, gpointer cls);
+GNUNET_FS_GTK_edit_publish_dialog (GtkBuilder *builder,
+                                  GtkWindow *parent,
+                                  int do_index,
+                                  const char *short_fn, 
+                                  uint32_t anonymity_level, 
+                                  uint32_t priority,
+                                  struct GNUNET_FS_FileInformation *fip,
+                                  gboolean allow_no_keywords,
+                                  GNUNET_FS_GTK_EditPublishDialogCallback cb, 
gpointer cls);
 
 #endif
 /* end of gnunet-fs-gtk-edit_publish_dialog.h */

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 2011-12-23 
08:38:58 UTC (rev 18758)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c 2011-12-23 
09:43:13 UTC (rev 18759)
@@ -66,20 +66,22 @@
     gtk_widget_set_sensitive (ok_button, FALSE);
 }
 
-struct namespace_data_struct
+struct NamespaceAdvertisementContext
 {
   struct GNUNET_FS_Namespace *ns;
   int do_index;
-  char *short_fn;
+  const char *short_fn;
   guint anonymity_level;
   guint priority;
-  gchar *root;
+  const char *root;
+  struct GNUNET_FS_FileInformation *fip;
 };
 
+
 /**
  * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
  *
- * @param cls closure
+ * @param cls closure, a 'struct NamespaceAdvertisementContext *'
  * @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)
@@ -91,41 +93,44 @@
  *         this entry from the directory, GNUNET_SYSERR
  *         to abort the iteration
  */
-int
+static int
 advertise_namespace (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)
+                    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 namespace_data_struct *nds;
-  nds = (struct namespace_data_struct *) cls;
+  struct NamespaceAdvertisementContext *nds = cls;
+
   GNUNET_FS_namespace_advertise (GNUNET_FS_GTK_get_fs_handle (), *uri,
       nds->ns, meta, bo, nds->root, NULL, NULL);
   return GNUNET_SYSERR;
 }
 
-void
-adv_pseudonym_edit_publish_dialog_cb (gpointer cls, int *do_index, char 
**short_fn,
-    guint * anonymity_level, guint * priority, gchar *root,
-    struct GNUNET_FS_FileInformation *fip, gint ret)
+
+static void
+adv_pseudonym_edit_publish_dialog_cb (gpointer cls, 
+                                     int do_index, 
+                                     const char *short_fn,
+                                     guint anonymity_level, 
+                                     guint priority, 
+                                     const char *root,                         
      
+                                     gint ret)
 {
-  struct namespace_data_struct *nds;
-  nds = (struct namespace_data_struct *) cls;
+  struct NamespaceAdvertisementContext *nds = cls;
 
   if (ret == GTK_RESPONSE_OK)
   {
-    nds->do_index = *do_index;
-    nds->short_fn = *short_fn;
-    nds->anonymity_level = *anonymity_level;
-    nds->priority = *priority;
+    nds->do_index = do_index;
+    nds->short_fn = short_fn;
+    nds->anonymity_level = anonymity_level;
+    nds->priority = priority;
     nds->root = root;
-    GNUNET_FS_file_information_inspect (fip,
-        advertise_namespace, nds);
+    GNUNET_FS_file_information_inspect (nds->fip,
+                                       &advertise_namespace, nds);
   }
-  g_free (nds->root);
   GNUNET_FS_namespace_delete (nds->ns, GNUNET_NO);
-  g_free (nds);
-  GNUNET_FS_file_information_destroy (fip, NULL, NULL);
+  GNUNET_FS_file_information_destroy (nds->fip, NULL, NULL);
+  GNUNET_free (nds);
 }
 
 void
@@ -141,12 +146,11 @@
   struct GNUNET_FS_Namespace *ns;
   struct GNUNET_FS_Namespace *nso;
   GtkWindow *transient;
-  struct namespace_data_struct *nds;
-  struct GNUNET_FS_FileInformation *fip;
+  struct NamespaceAdvertisementContext *nds;
   struct GNUNET_CONTAINER_MetaData *meta;
-  builder = GTK_BUILDER (user_data);
   struct GNUNET_FS_BlockOptions bo;
 
+  builder = GTK_BUILDER (user_data);
   ad = GTK_WIDGET (gtk_builder_get_object
                    (builder, "GNUNET_GTK_select_pseudonym_dialog"));
 
@@ -178,7 +182,7 @@
 
   meta = GNUNET_CONTAINER_meta_data_create ();
 
-  nds = g_new0 (struct namespace_data_struct, 1);
+  nds = GNUNET_malloc (sizeof (struct NamespaceAdvertisementContext));
   nds->ns = ns;
   nds->do_index = FALSE;
   nds->short_fn = NULL;
@@ -188,14 +192,16 @@
   /* This is a bogus fileinfo. It's needed because edit_publish_dialog
    * was written to work with fileinfo, and return a fileinfo.
    */
-  memset (&bo, 0, sizeof (bo));
-  fip = GNUNET_FS_file_information_create_empty_directory (NULL, NULL,
-      NULL, meta, &bo);
+  nds->fip = GNUNET_FS_file_information_create_empty_directory (NULL, NULL,
+                                                               NULL, meta, 
&bo);
+    memset (&bo, 0, sizeof (bo));
   GNUNET_CONTAINER_meta_data_destroy (meta);
-
-  GNUNET_FS_GTK_edit_publish_dialog (builder, transient, &nds->do_index,
-      &nds->short_fn, &nds->anonymity_level, &nds->priority,
-      fip, FALSE, &adv_pseudonym_edit_publish_dialog_cb, nds);
+  GNUNET_FS_GTK_edit_publish_dialog (builder, transient, 
+                                    nds->do_index,
+                                    nds->short_fn, 
+                                    nds->anonymity_level, 
+                                    nds->priority,
+                                    nds->fip, FALSE, 
&adv_pseudonym_edit_publish_dialog_cb, nds);
 }
 
 void

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  2011-12-23 
08:38:58 UTC (rev 18758)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c  2011-12-23 
09:43:13 UTC (rev 18759)
@@ -278,7 +278,6 @@
 }
 
 
-
 /**
  * Add an empty directory to the tree model.
  *
@@ -873,7 +872,6 @@
   GtkBuilder *builder;
   
   builder = GTK_BUILDER (data);
-
   gtk_tree_model_get (tm, old, 0, &fsf, 1, &do_index, 2, &short_fn, 3,
                       &anonymity_level, 4, &priority, 5, &fip, -1);
   gtk_tree_store_set (GTK_TREE_STORE (tm), newpos, 0, fsf, 1, do_index, 2,
@@ -926,20 +924,21 @@
   update_selectivity (data);
 }
 
+
 /**
  * User has changed the "current" identifier for the content in
  * the GtkTreeView.  Update the model.
  */
-void GNUNET_GTK_master_publish_dialog_pseudonym_updates_renderer_edited_cb
-    (GtkCellRendererText * renderer, gchar * cpath, gchar * new_text,
-     gpointer user_data)
+void 
+GNUNET_GTK_master_publish_dialog_pseudonym_updates_renderer_edited_cb 
(GtkCellRendererText * renderer, 
+                                                                      gchar * 
cpath, gchar * new_text,
+                                                                      gpointer 
user_data)
 {
   GtkTreeIter iter;
   GtkTreeStore *ts;
   GtkBuilder *builder;
   
   builder = GTK_BUILDER (user_data);
-
   ts = GTK_TREE_STORE (gtk_builder_get_object
                        (builder, "GNUNET_GTK_pseudonym_tree_store"));
 
@@ -958,16 +957,16 @@
  * User has changed the "current" identifier for the content in
  * the GtkTreeView.  Update the model.
  */
-void GNUNET_GTK_master_publish_dialog_pseudonym_identifier_renderer_edited_cb
-    (GtkCellRendererText * renderer, gchar * cpath, gchar * new_text,
-     gpointer user_data)
+void 
+GNUNET_GTK_master_publish_dialog_pseudonym_identifier_renderer_edited_cb 
(GtkCellRendererText * renderer, 
+                                                                         gchar 
* cpath, gchar * new_text,
+                                                                         
gpointer user_data)
 {
   GtkTreeIter iter;
   GtkTreeStore *ts;
   GtkBuilder *builder;
   
   builder = GTK_BUILDER (user_data);
-
   ts = GTK_TREE_STORE (gtk_builder_get_object
                        (builder, "GNUNET_GTK_pseudonym_tree_store"));
 
@@ -1228,35 +1227,48 @@
   gtk_window_present (GTK_WINDOW (ad));
 }
 
-struct edit_pub_cb_args
+
+struct EditPublishContext
 {
   GtkTreeModel *tm;
   GtkTreeIter iter;
-  /* FIXME: this indirection madness is not really required any longer.
-   * we only need to pass over *tm and iter, everything else can be
-   * copied.
-   */
-  gchar *short_fn;
-  struct GNUNET_FS_FileInformation *fip;
-  int do_index;
-  guint anonymity_level;
-  guint priority;
 };
 
-void
-master_publish_edit_publish_dialog_cb (gpointer cls, int *do_index, char 
**short_fn,
-    guint * anonymity_level, guint * priority, gchar *root,
-    struct GNUNET_FS_FileInformation *fip, gint ret)
+
+/**
+ * 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 root always NULL here
+ * @param ret GTK_RESPONSE_OK if the dialog was closed with "OK"
+ */
+static void
+master_publish_edit_publish_dialog_cb (gpointer cls, 
+                                      int do_index, 
+                                      const char *short_fn,
+                                      uint32_t anonymity_level,
+                                      uint32_t priority, 
+                                      const char *root,
+                                      gint ret)
 {
-  struct edit_pub_cb_args *cbargs = (struct edit_pub_cb_args *) cls;
+  struct EditPublishContext *cbargs = cls;
+  
+  GNUNET_assert (NULL == root);
   if (ret == GTK_RESPONSE_OK)
     gtk_tree_store_set (GTK_TREE_STORE (cbargs->tm), &cbargs->iter,
-        1, *do_index, 2, *short_fn, 3, *anonymity_level, 4, *priority, -1);
-  g_free (root);
-  g_free (short_fn);
-  g_free (cbargs);
+                       1, do_index, 
+                       2, short_fn, 
+                       3, (guint) anonymity_level, 
+                       4, (guint) priority, 
+                       -1);
+  GNUNET_free (cbargs);
 }
 
+
 void
 GNUNET_GTK_master_publish_dialog_edit_button_clicked_cb (GtkWidget * dummy,
                                                          gpointer data)
@@ -1264,36 +1276,47 @@
   GtkTreeView *tv;
   GtkTreeModel *tm;
   GtkTreeSelection *sel;
-  struct edit_pub_cb_args *cbargs;
+  struct EditPublishContext *cbargs;
   GtkBuilder *builder;
   GtkWindow *master_pubdialog;
+  gint do_index;
+  char *short_fn;
+  guint anonymity_level;
+  guint priority;
+  struct GNUNET_FS_FileInformation *fip;
 
   builder = GTK_BUILDER (data);
-
   tv = GTK_TREE_VIEW (gtk_builder_get_object
                       (builder,
                        
"GNUNET_GTK_master_publish_dialog_file_information_tree_view"));
 
-  cbargs = g_new0 (struct edit_pub_cb_args, 1);
+  cbargs = GNUNET_malloc (sizeof (struct EditPublishContext));
   cbargs->tm = gtk_tree_view_get_model (tv);
-
   master_pubdialog = GTK_WINDOW (gtk_builder_get_object (builder,
-      "GNUNET_GTK_master_publish_dialog"));
+                                                        
"GNUNET_GTK_master_publish_dialog"));
   sel = gtk_tree_view_get_selection (tv);
   if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &cbargs->iter))
   {
     GNUNET_break (0);
-    g_free (cbargs);
+    GNUNET_free (cbargs);
     return;
   }
 
-  gtk_tree_model_get (tm, &cbargs->iter, 1, &cbargs->do_index, 2,
-      &cbargs->short_fn, 3, &cbargs->anonymity_level, 4, &cbargs->priority,
-      5, &cbargs->fip, -1);
-
-  GNUNET_FS_GTK_edit_publish_dialog (builder, master_pubdialog, 
&cbargs->do_index,
-      &cbargs->short_fn, &cbargs->anonymity_level, &cbargs->priority,
-      cbargs->fip, TRUE, &master_publish_edit_publish_dialog_cb, cbargs);
+  gtk_tree_model_get (tm, &cbargs->iter, 
+                     1, &do_index, 
+                     2, &short_fn, 
+                     3, &anonymity_level, 
+                     4, &priority,
+                     5, &fip,
+                     -1);
+  /* FIXME: shouldn't this use a fresh builder? */
+  GNUNET_FS_GTK_edit_publish_dialog (builder, master_pubdialog, 
+                                    do_index,
+                                    short_fn, 
+                                    (uint32_t) anonymity_level, 
+                                    (uint32_t) priority,
+                                    fip,
+                                    TRUE, 
&master_publish_edit_publish_dialog_cb, cbargs);
 }
 
 
@@ -1320,7 +1343,6 @@
 }
 
 
-
 void
 GNUNET_GTK_master_publish_dialog_delete_button_clicked_cb (GtkWidget * dummy,
                                                            gpointer data)
@@ -1333,7 +1355,6 @@
   GtkBuilder *builder;
   
   builder = GTK_BUILDER (data);
-
   tv = GTK_TREE_VIEW (gtk_builder_get_object
                       (builder,
                        
"GNUNET_GTK_master_publish_dialog_file_information_tree_view"));
@@ -1349,9 +1370,10 @@
   update_selectivity (data);
 }
 
+
 void
 GNUNET_GTK_publish_directory_dialog_response_cb (GtkDialog *dialog,
-    gint response_id, gpointer user_data)
+                                                gint response_id, gpointer 
user_data)
 {
   char *filename;
   int do_index;
@@ -1361,10 +1383,8 @@
   GtkBuilder *builder;
 
   builder = GTK_BUILDER (user_data);
-
   ad = GTK_WIDGET (gtk_builder_get_object (builder,
-      "GNUNET_GTK_publish_directory_dialog"));
-
+                                          
"GNUNET_GTK_publish_directory_dialog"));
   if (response_id == -5)
   {
     filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (ad));
@@ -1637,9 +1657,10 @@
   }
 }
 
+
 void
 GNUNET_GTK_master_publish_dialog_realize_cb (GtkWidget *widget,
-    gpointer user_data)
+                                            gpointer user_data)
 {
   GtkTreeView *tv;
   GtkTreeSelection *sel;
@@ -1661,7 +1682,8 @@
                     G_CALLBACK (selection_changed_cb), user_data);
 }
 
-void
+
+static void
 hide_master_publish_dialog (gpointer user_data, gint ret)
 {
   GtkTreeView *tv, *ptv;
@@ -1673,11 +1695,11 @@
   gchar *namespace_uid;
   struct GNUNET_FS_FileInformation *fi;
   GtkWidget *ad;
-  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkBuilder *builder;
 
+  builder = GTK_BUILDER (user_data);
   ad = GTK_WIDGET (gtk_builder_get_object
                    (builder, "GNUNET_GTK_master_publish_dialog"));
-
   ptv = GTK_TREE_VIEW (gtk_builder_get_object
                       (builder,
                        
"GNUNET_GTK_master_publish_dialog_pseudonym_tree_view"));
@@ -1732,35 +1754,40 @@
     }
     while (TRUE == gtk_tree_model_iter_next (tm, &iter));
   gtk_tree_store_clear (GTK_TREE_STORE (tm));
-
   gtk_widget_hide (ad);
+  /* FIXME: doesn't this leak everything (builder + window)?
+     I think we need to unref the builder here! */
 }
 
+
 void
 GNUNET_GTK_master_publish_dialog_execute_button_clicked_cb (GtkButton *button,
-    gpointer user_data)
+                                                           gpointer user_data)
 {
   hide_master_publish_dialog (user_data, GTK_RESPONSE_OK);
 }
 
+
 void
 GNUNET_GTK_master_publish_dialog_cancel_button_clicked_cb (GtkButton *button,
-    gpointer user_data)
+                                                          gpointer user_data)
 {
   hide_master_publish_dialog (user_data, GTK_RESPONSE_CANCEL);
 }
 
+
 gboolean
 GNUNET_GTK_master_publish_dialog_delete_event_cb (GtkWidget *widget,
-    GdkEvent *event, gpointer user_data)
+                                                 GdkEvent *event, gpointer 
user_data)
 {
   hide_master_publish_dialog (user_data, GTK_RESPONSE_CANCEL);
   return TRUE;
 }
 
+
 void
 GNUNET_GTK_publish_file_dialog_response_cb (GtkDialog *dialog,
-    gint response_id, gpointer user_data)
+                                           gint response_id, gpointer 
user_data)
 {
   char *filename;
   struct GNUNET_FS_BlockOptions bo;
@@ -1802,6 +1829,7 @@
   gtk_widget_hide (ad);
 }
 
+
 /**
  */
 void
@@ -1812,10 +1840,8 @@
   GtkBuilder *builder;
   
   builder = GTK_BUILDER (data);
-
   ad = GTK_WIDGET (gtk_builder_get_object
                    (builder, "GNUNET_GTK_master_publish_dialog"));
-
   if (!gtk_widget_get_visible (ad))
   {
     ts = GTK_TREE_STORE (gtk_builder_get_object (builder,
@@ -1823,7 +1849,6 @@
     GNUNET_FS_namespace_list (GNUNET_FS_GTK_get_fs_handle (),
         &add_namespace_to_ts, ts);
   }
-
   gtk_window_present (GTK_WINDOW (ad));
 }
 




reply via email to

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