gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19612 - gnunet-gtk/src/fs
Date: Wed, 1 Feb 2012 21:57:26 +0100

Author: grothoff
Date: 2012-02-01 21:57:25 +0100 (Wed, 01 Feb 2012)
New Revision: 19612

Modified:
   gnunet-gtk/src/fs/gnunet-fs-gtk-common.c
   gnunet-gtk/src/fs/gnunet-fs-gtk-common.h
   gnunet-gtk/src/fs/gnunet-fs-gtk-download.c
   gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
Log:
-documenting and simplifying code some more

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-common.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-common.c    2012-02-01 18:09:25 UTC (rev 
19611)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-common.c    2012-02-01 20:57:25 UTC (rev 
19612)
@@ -42,38 +42,38 @@
 GNUNET_FS_GTK_dubious_meta_to_utf8 (enum EXTRACTOR_MetaFormat format,
                                     const char *data, size_t data_len)
 {
-  gchar *result = NULL;
-
-  if (format == EXTRACTOR_METAFORMAT_UTF8)
+  switch (format)
   {
+  case EXTRACTOR_METAFORMAT_UTF8:
     /* data must not contain NULLs (hence the -1) */
     if (g_utf8_validate (data, data_len - 1, NULL))
-      result = GNUNET_strdup (data);
-    else
+      return GNUNET_strdup (data);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               _("Failed to validate supposedly utf-8 string `%s' of length 
%u, assuming it to be a C string\n"),
+               data, 
+               (unsigned int) data_len);
+    format = EXTRACTOR_METAFORMAT_C_STRING;
+    /* fall-through */
+  case EXTRACTOR_METAFORMAT_C_STRING:  
+    if (data_len > 0)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "Failed to validate supposedly utf-8 string `%s' of length 
%u, assuming it to be a C string\n",
-                  data, data_len);
-      format = EXTRACTOR_METAFORMAT_C_STRING;
-    }
-  }
-  if (format == EXTRACTOR_METAFORMAT_C_STRING)
-  {
-    if (data_len > 0)
-    { /* There are no guarantees that data is NULL-terminated, AFAIU,
-      * so let's play it safe, shall we?
-      */
-      char *data_copy = GNUNET_malloc (data_len + 1);
+      /* There are no guarantees that data is NULL-terminated, AFAIU,
+       * so let's play it safe, shall we?
+       */
+      char data_copy[data_len + 1];
 
       memcpy (data_copy, data, data_len);
       data_copy[data_len] = '\0';
-      result = GNUNET_GTK_from_loc_to_utf8 (data_copy);
-      GNUNET_free (data_copy);
+      return GNUNET_GTK_from_loc_to_utf8 (data_copy);
     }
+    break;
+  default:
+    break;
   }
-  return result;
+  return NULL;
 }
 
+
 /**
  * Add meta data to list store.
  *
@@ -98,18 +98,15 @@
                                            const char *data, size_t data_len)
 {
   GtkListStore *ls = GTK_LIST_STORE (cls);
-  gchar *data_to_insert = NULL;
+  char *data_to_insert;
 
   data_to_insert = GNUNET_FS_GTK_dubious_meta_to_utf8 (format, data, data_len);
-
-  if (NULL != data_to_insert)
-  {
-    gtk_list_store_insert_with_values (ls, NULL, G_MAXINT, 0, type, 1, format,
-                                       2, EXTRACTOR_metatype_to_string (type),
-                                       3, data_to_insert, -1);
-    g_free (data_to_insert);
-  }
-
+  if (NULL == data_to_insert)
+    return 0;
+  gtk_list_store_insert_with_values (ls, NULL, G_MAXINT, 0, type, 1, format,
+                                    2, EXTRACTOR_metatype_to_string (type),
+                                    3, data_to_insert, -1);
+  GNUNET_free (data_to_insert); 
   return 0;
 }
 
@@ -117,6 +114,9 @@
 /**
  * Convert the year from the spin button to an expiration
  * time (on midnight, January 1st of that year).
+ *
+ * @param spin button with an expiration year
+ * @return expiration time in the usual GNUnet format
  */
 struct GNUNET_TIME_Absolute
 GNUNET_FS_GTK_get_expiration_time (GtkSpinButton * spin)
@@ -132,6 +132,14 @@
 }
 
 
+/**
+ * Initialize the 'expiration_year_adjustment' of the given
+ * builder to have a lower range of current-year+1 and a
+ * default of current-year+2.
+ *
+ * @param builder builder object for which we should manipulate
+ * the adjustment
+ */
 void
 GNUNET_FS_GTK_setup_expiration_year_adjustment (GtkBuilder * builder)
 {
@@ -146,6 +154,12 @@
 }
 
 
+/**
+ * Obtain pixbuf from thumbnail data in meta data.
+ *
+ * @param meta input meta data
+ * @return NULL on error, otherwise the embedded thumbnail
+ */
 GdkPixbuf *
 GNUNET_FS_GTK_get_thumbnail_from_meta_data (const struct
                                             GNUNET_CONTAINER_MetaData *meta)
@@ -157,13 +171,13 @@
 
   thumb = NULL;
   ts = GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb);
-  if (ts == 0)
+  if (0 == ts)
     return NULL;
   loader = gdk_pixbuf_loader_new ();
   gdk_pixbuf_loader_write (loader, (const guchar *) thumb, ts, NULL);
   pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
   gdk_pixbuf_loader_close (loader, NULL);
-  if (pixbuf != NULL)
+  if (NULL != pixbuf)
     g_object_ref (pixbuf);
   g_object_unref (loader);
   GNUNET_free (thumb);
@@ -174,6 +188,10 @@
 /**
  * mmap the given file and run the GNUNET_FS_directory_list_contents
  * function on it.
+ *
+ * @param filename name with the directory
+ * @param dep function to call on each entry
+ * @param dep_cls closure for 'dep'
  */
 void
 GNUNET_FS_GTK_mmap_and_scan (const char *filename,
@@ -190,16 +208,13 @@
     GNUNET_break (0);
     return;
   }
-  fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
-                              GNUNET_DISK_PERM_NONE);
-  if (fh == NULL)
+  if (NULL == (fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
+                                          GNUNET_DISK_PERM_NONE)))
   {
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
     return;
   }
-  ddata =
-      GNUNET_DISK_file_map (fh, &mh, GNUNET_DISK_MAP_TYPE_READ, (size_t) 
fsize);
-  if (ddata == NULL)
+  if (NULL == (ddata = GNUNET_DISK_file_map (fh, &mh, 
GNUNET_DISK_MAP_TYPE_READ, (size_t) fsize)))
   {
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename);
     GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-common.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-common.h    2012-02-01 18:09:25 UTC (rev 
19611)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-common.h    2012-02-01 20:57:25 UTC (rev 
19612)
@@ -42,12 +42,15 @@
                                             GNUNET_CONTAINER_MetaData *meta);
 
 
+
 /**
+ * Initialize the 'expiration_year_adjustment' of the given
+ * builder to have a lower range of current-year+1 and a
+ * default of current-year+2.
  * FIXME: odd API...
- * Setup the expiration year adjustment to start with the
- * next year and default to next year plus one.
  *
- * @param builder
+ * @param builder builder object for which we should manipulate
+ * the adjustment
  */
 void
 GNUNET_FS_GTK_setup_expiration_year_adjustment (GtkBuilder * builder);

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-download.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-download.c  2012-02-01 18:09:25 UTC (rev 
19611)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-download.c  2012-02-01 20:57:25 UTC (rev 
19612)
@@ -145,7 +145,7 @@
      call the handler manually */
   GNUNET_GTK_save_as_dialog_delete_event_cb (GTK_WIDGET (dialog), NULL,
                                              user_data);
-  /* FIXME: isn't the dialog going to be destroyed with the builder? 
+  /* FIXME-BUG-MAYBE: isn't the dialog going to be destroyed with the builder? 
      Is this legal and/or required? */
   gtk_widget_destroy (GTK_WIDGET (dialog));
 }
@@ -189,7 +189,7 @@
                                dc->is_recursive);   
 
   /* initialize filename based on filename from 'dc' */
-  if (dc->filename != NULL)
+  if (NULL != dc->filename)
   {
     char *dirname;
     char *basename;
@@ -200,6 +200,7 @@
     if (basename > dirname)
       basename[-1] = '\0';
 
+    /* FIXME: remove following lines after testing... */
     fprintf (stderr,
             "Splitting `%s' into `%s' + `%s' for file chooser dialog.\n",
             dc->filename,
@@ -237,7 +238,7 @@
   dc->uri = NULL;
   de->meta = dc->meta;
   dc->meta = NULL;
-  if (dc->rr != NULL)
+  if (NULL != dc->rr)
   {
     de->rr = gtk_tree_row_reference_copy (dc->rr);
     de->ts = GTK_TREE_STORE (gtk_tree_row_reference_get_model (dc->rr));
@@ -268,7 +269,7 @@
   if (dc->is_recursive)
     opt |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
   len = GNUNET_FS_uri_chk_get_file_size (dc->uri);
-  if (dc->sr != NULL)
+  if (NULL != dc->sr)
   {
     GNUNET_break (NULL !=
                   GNUNET_FS_download_start_from_search (fs, dc->sr,

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 
18:09:25 UTC (rev 19611)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-edit_publish_dialog.c       2012-02-01 
20:57:25 UTC (rev 19612)
@@ -29,67 +29,180 @@
 
 #include "metatypes.c"
 
+
+/**
+ * Internal state kept for each "edit" dialog where the user can edit
+ * publishing information for a file.
+ */
 struct EditPublicationDialogContext
 {
+  /**
+   * Builder for the dialog.
+   */
   GtkBuilder *builder;
 
-  GtkListStore *metatypes_liststore;
+  /**
+   * The 'window' object for the dialog.
+   */
+  GtkWindow *edit_publication_window;
 
-  GtkListStore *meta_liststore;
+  /**
+   * The confirmation button which closes the dialog (only sensitive
+   * if the values entered are valid).
+   */
+  GtkWidget *confirm_button;
+
+  /**
+   * Tree view showing the meta data for the file.
+   */
   GtkTreeView *meta_treeview;
-  GtkTreeSelection *meta_selection;
-  GtkButton *meta_add_button;
-  GtkWidget *meta_del_button;
 
-  GtkCellRendererCombo *meta_combo;
+  /**
+   * Tree view showing the keywords for the file.
+   */
+  GtkTreeView *keywords_treeview;
 
+  /**
+   * Image showing the preview image for the file.
+   */
+  GtkImage *preview_image;
+
+  /**
+   * Combo box where the user can select the anonymity level.
+   */
+  GtkComboBox *anonymity_combo;
+
+  /**
+   * Liststore of the 'anonymity_combo' with the anonymity levels.
+   */
+  GtkListStore *anonymity_liststore;
+
+  /**
+   * Liststore of possible publication types.
+   */
   GtkListStore *pubtypes_liststore;
-  GtkComboBox *pubtypes_combo;
 
+  /**
+   * Liststore of all possible meta types the user can choose from.
+   * (updated to based on the selected publication type).
+   */
+  GtkListStore *metatypes_liststore;
+
+  /**
+   * Liststore showing the meta data of the file (associated with
+   * the 'meta_treeview'.
+   */
+  GtkListStore *meta_liststore;
+
+  /**
+   * Liststore with the keywords of the file (associated with the
+   * 'keywords_treeview'.
+   */
   GtkListStore *keywords_liststore;
-  GtkTreeView *keywords_treeview;
-  GtkTreeSelection *keywords_selection;
-  GtkWidget *keyword_add_button;
-  GtkWidget *keyword_del_button;
 
-  GtkEntry *keyword_entry;
+  /**
+   * Spin button to select content priority level for the file.
+   */
+  GtkSpinButton *priority_spin;
 
-  GObject *pubwindow;
+  /**
+   * Spin button to select the expiration year.
+   */
+  GtkSpinButton *expiration_year_spin;
 
-  GtkWidget *ok;
-  GtkButton *cancel;
+  /**
+   * Spin button to select the replication level.
+   */
+  GtkSpinButton *replication_spin;
 
-  GtkImage *image;
+  /**
+   * Entry line for adding additional keywords.
+   */
+  GtkEntry *keyword_entry;
 
-  GtkToggleButton *index_checkbutton;
-  GtkLabel *index_label;
+  /**
+   * Entry line for setting a namespace root (possibly invisible).
+   */
   GtkEntry *root_entry;
-  GtkLabel *root_label;
 
-  GtkSpinButton *priority_spin;
-  GtkSpinButton *year_spin;
-  GtkSpinButton *replication_spin;
+  /**
+   * Entry line to check indexing vs. inserting (possibly invisible)
+   */
+  GtkToggleButton *index_checkbutton;
 
-  GtkComboBox *anonymity_combo;
-  GtkListStore *anonymity_liststore;
+  /**
+   * ???
+   */
+  GtkTreeIter *meta_combo_selected_iter;
 
-  int do_index;
+  /**
+   * Continuation to call once the dialog has been closed
+   */
+  GNUNET_FS_GTK_EditPublishDialogCallback cb;
+
+  /**
+   * Closure for 'cb'.
+   */
+  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;
+
+  /**
+   * Information about the file being published as seen by the FS-API.
+   * This is what we are primarily editing.
+   */
+  struct GNUNET_FS_FileInformation *fip;
+
+  /**
+   * Overall options for the publish operation.  This is also what
+   * we are primarily editing.
+   */
   struct GNUNET_FS_BlockOptions bo;
-  struct GNUNET_FS_FileInformation *fip;
-  gint preview_changed;
+
+  /**
+   * Flag to track if we changed the preview and thus should keep/discard
+   * certain metadata. (FIXME: yucky!)
+   */
+  int preview_changed;
+
+  /**
+   * Is this operation for a directory?
+   */
+  int is_directory;
+
+  /**
+   * Is it allowed for the user to supply keywords in this dialog?
+   * FIXME: why 'gboolean'?
+   */
   gboolean allow_no_keywords;
-  gboolean is_directory;
-  GNUNET_FS_GTK_EditPublishDialogCallback cb;
-  gchar *root;
-  gpointer cls;
 
-  struct GNUNET_CONTAINER_MetaData *md;
-
-  GtkTreeIter *meta_combo_selected_iter;
 };
 
+
+/**
+ * Free resources associated with the edit publication dialog.
+ *
+ * @param ctx the context of the dialog to release resources of
+ */
 static void
+free_edit_dialog_context (struct EditPublicationDialogContext *ctx)
+{
+  gtk_widget_destroy (GTK_WIDGET (ctx->edit_publication_window));
+  GNUNET_free_non_null (ctx->short_fn);
+  // FIXME: destroy builder!
+  GNUNET_free (ctx);
+}
+
+
+static void
 change_metatypes (struct EditPublicationDialogContext *ctx, gint code)
 {
   gint pub_type = 0, i;
@@ -129,11 +242,9 @@
   GtkTreeIter iter;
   gint code;
 
-  if (!gtk_combo_box_get_active_iter (widget, &iter))
+  if (! gtk_combo_box_get_active_iter (widget, &iter))
     return;
-
   gtk_tree_model_get (GTK_TREE_MODEL (ctx->pubtypes_liststore), &iter, 0, 
&code, -1);
-
   change_metatypes (ctx, code);
 }
 
@@ -141,7 +252,8 @@
 static void
 metadata_selection_changed_cb (GtkTreeSelection *ts, struct 
EditPublicationDialogContext *ctx)
 {
-  gtk_widget_set_sensitive (ctx->meta_del_button,
+  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));
 }
 
@@ -149,7 +261,9 @@
 static void
 keywords_selection_changed_cb (GtkTreeSelection *ts, struct 
EditPublicationDialogContext *ctx)
 {
-  gtk_widget_set_sensitive (ctx->keyword_del_button,
+  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));
 }
 
@@ -176,7 +290,10 @@
 {
   if (event->keyval == GDK_KEY_Return)
   {
-    GNUNET_GTK_edit_publication_add_button_clicked_cb (GTK_BUTTON 
(ctx->keyword_add_button), ctx);
+    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;
@@ -198,7 +315,10 @@
 
   if (!ctx->meta_combo_selected_iter)
     return;
-  g_object_get (ctx->meta_combo, "model", &combo_model, NULL);
+  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);
@@ -277,14 +397,16 @@
                                                       struct 
EditPublicationDialogContext *ctx)
 {
   GtkTreeIter iter;
+  GtkTreeSelection *meta_selection;
 
-  if (TRUE != gtk_tree_selection_get_selected (ctx->meta_selection, NULL, 
&iter))
+  meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview);
+  if (! gtk_tree_selection_get_selected (meta_selection, NULL, &iter))
   {
     GNUNET_break (0);
     return;
   }
   if (gtk_list_store_remove (ctx->meta_liststore, &iter))
-    gtk_tree_selection_select_iter (ctx->meta_selection, &iter);
+    gtk_tree_selection_select_iter (meta_selection, &iter);
 }
 
 
@@ -301,7 +423,7 @@
   {
     gtk_list_store_insert_with_values (ctx->keywords_liststore, &iter, 
G_MAXINT, 0, keyword, 1, TRUE,
                                        -1);
-    gtk_widget_set_sensitive (ctx->ok, TRUE);
+    gtk_widget_set_sensitive (ctx->confirm_button, TRUE);
   }
   gtk_entry_set_text (ctx->keyword_entry, "");
 }
@@ -335,7 +457,9 @@
   const char *keyword;
 
   keyword = gtk_entry_get_text (ctx->keyword_entry);
-  gtk_widget_set_sensitive (ctx->keyword_add_button, (strlen (keyword) > 0) ? 
TRUE : FALSE);
+  gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (ctx->builder,
+                                                                               
           "GNUNET_GTK_edit_publication_keyword_list_add_button")), 
+                           (strlen (keyword) > 0) ? TRUE : FALSE);
 }
 
 
@@ -345,17 +469,20 @@
                                                                 struct 
EditPublicationDialogContext *ctx)
 {
   GtkTreeIter iter;
+  GtkTreeSelection *keywords_selection;
 
-  if (TRUE != gtk_tree_selection_get_selected (ctx->keywords_selection, NULL, 
&iter))
+  keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview);
+
+  if (TRUE != 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 (ctx->keywords_selection, &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)))
-    gtk_widget_set_sensitive (ctx->ok, FALSE);
+    gtk_widget_set_sensitive (ctx->confirm_button, FALSE);
 }
 
 
@@ -365,7 +492,7 @@
   gchar *fn;
 
   fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
-  gtk_image_set_from_file (ctx->image, fn);
+  gtk_image_set_from_file (ctx->preview_image, fn);
   g_free (fn);
   ctx->preview_changed = GNUNET_YES;
 }
@@ -478,6 +605,7 @@
   const char *mime;
   GFile *f;
   GFileInfo *finfo;
+  char *sfn;
 
   if (!GNUNET_GTK_get_selected_anonymity_combo_level
       (ctx->anonymity_combo, &ctx->bo.anonymity_level))
@@ -485,13 +613,8 @@
   ctx->bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin);
   ctx->bo.replication_level = gtk_spin_button_get_value 
(ctx->replication_spin);
   *do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
-  ctx->bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (ctx->year_spin);
+  ctx->bo.expiration_time = GNUNET_FS_GTK_get_expiration_time 
(ctx->expiration_year_spin);
 
-  if (!ctx->allow_no_keywords)
-  {
-    g_free (ctx->root);
-    ctx->root = g_strdup (gtk_entry_get_text (ctx->root_entry));
-  }
   /* update URI */
   if (NULL != (*uri))
     GNUNET_FS_uri_destroy (*uri);
@@ -564,13 +687,17 @@
     g_free (fn);
   }
   GNUNET_CONTAINER_meta_data_destroy (ctx->md);
+  ctx->md = NULL;
 
   /* update short_fn */
-  GNUNET_free_non_null (ctx->short_fn);
-  ctx->short_fn =
-      GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
-                                                     
EXTRACTOR_METATYPE_FILENAME,
-                                                     -1);
+  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 */
 }
 
@@ -579,17 +706,24 @@
 GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GtkButton * button,
                                                       struct 
EditPublicationDialogContext *ctx)
 {
-  ctx->cb (ctx->cls, ctx->do_index, ctx->short_fn,
-      &ctx->bo, NULL, GTK_RESPONSE_CANCEL);
-  gtk_widget_destroy (GTK_WIDGET (ctx->pubwindow));
+  int do_index;
+
+  /* FIXME: why are we passing half of these values here? */
+  do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
+  ctx->cb (ctx->cb_cls, do_index, ctx->short_fn,
+          &ctx->bo, NULL, GTK_RESPONSE_CANCEL);
+  free_edit_dialog_context (ctx);
 }
 
 
+
 void
 GNUNET_GTK_edit_publication_confirm_button_clicked_cb (GtkButton * button,
                                                        struct 
EditPublicationDialogContext *ctx)
 {
   gint year;
+  const char *root;
+  int do_index;
 
   GNUNET_FS_file_information_inspect (ctx->fip, &file_information_update, ctx);
   if (!GNUNET_GTK_get_selected_anonymity_combo_level (ctx->anonymity_combo,
@@ -597,13 +731,13 @@
     ctx->bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin);
   ctx->bo.replication_level = gtk_spin_button_get_value 
(ctx->replication_spin);
 
-  ctx->do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
-  year = gtk_spin_button_get_value (ctx->year_spin);
+  do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
+  year = gtk_spin_button_get_value (ctx->expiration_year_spin);
   ctx->bo.expiration_time = GNUNET_FS_year_to_time (year);
-  ctx->cb (ctx->cls, ctx->do_index, ctx->short_fn,
-      &ctx->bo, ctx->root, GTK_RESPONSE_OK);
-  GNUNET_free_non_null (ctx->short_fn);
-  gtk_widget_destroy (GTK_WIDGET (ctx->pubwindow));
+  root = gtk_entry_get_text (ctx->root_entry);
+  ctx->cb (ctx->cb_cls, do_index, ctx->short_fn,
+      &ctx->bo, root, GTK_RESPONSE_OK);
+  free_edit_dialog_context (ctx);
 }
 
 
@@ -612,7 +746,9 @@
                                                     GdkEvent * event,
                                                     struct 
EditPublicationDialogContext *ctx)
 {
-  GNUNET_GTK_edit_publication_cancel_button_clicked_cb (ctx->cancel, ctx);
+  GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GTK_BUTTON 
(gtk_builder_get_object
+                                                                   
(ctx->builder, "GNUNET_GTK_edit_publication_cancel_button")),
+                                                       ctx);
   return TRUE;
 }
 
@@ -672,11 +808,11 @@
     pixbuf = GNUNET_FS_GTK_get_thumbnail_from_meta_data (meta);
     if (pixbuf != NULL)
     {
-      gtk_image_set_from_pixbuf (ctx->image, pixbuf);
+      gtk_image_set_from_pixbuf (ctx->preview_image, pixbuf);
     }
   }
   year = (int) GNUNET_FS_time_to_year (ctx->bo.expiration_time);
-  gtk_spin_button_set_value (ctx->year_spin, year);
+  gtk_spin_button_set_value (ctx->expiration_year_spin, year);
   GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo,
       ctx->bo.anonymity_level);
   gtk_spin_button_set_value (ctx->priority_spin, ctx->bo.content_priority);
@@ -689,13 +825,17 @@
 void
 GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget, struct 
EditPublicationDialogContext *ctx)
 {
-  ctx->keywords_selection = gtk_tree_view_get_selection 
(ctx->keywords_treeview);
-  ctx->meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview);
+  GtkTreeSelection *meta_selection;
+  GtkTreeSelection *keywords_selection;
 
-  g_signal_connect (G_OBJECT (ctx->keywords_selection), "changed",
+  /* 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 (ctx->meta_selection), "changed",
+  g_signal_connect (G_OBJECT (meta_selection), "changed",
                     G_CALLBACK (metadata_selection_changed_cb), ctx);
 }
 
@@ -705,17 +845,20 @@
  */
 void
 GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
-                                   int do_index, const char *short_fn,
+                                   int do_index /* FIXME: not needed? */, 
+                                  const char *short_fn,
                                   const struct GNUNET_FS_BlockOptions bo,
                                    struct GNUNET_FS_FileInformation *fip,
                                    gboolean allow_no_keywords,
                                    GtkListStore *anon_liststore,
                                    GNUNET_FS_GTK_EditPublishDialogCallback cb,
-                                   gpointer cls)
+                                   gpointer cb_cls)
 {
   GtkTreeIter iter;
   gint code;
-
+  GtkComboBox *pubtypes_combo;
+  GtkLabel *index_label;
+  GtkLabel *root_label;
   struct EditPublicationDialogContext *ctx;
 
   ctx = GNUNET_malloc (sizeof (struct EditPublicationDialogContext));
@@ -737,59 +880,31 @@
   ctx->meta_treeview = GTK_TREE_VIEW (gtk_builder_get_object
                       (ctx->builder,
                        "GNUNET_GTK_edit_publication_metadata_tree_view"));
-  ctx->meta_del_button =
-      GTK_WIDGET (gtk_builder_get_object
-                  (ctx->builder, "GNUNET_GTK_edit_publication_delete_button"));
   ctx->keywords_treeview = GTK_TREE_VIEW (gtk_builder_get_object
                       (ctx->builder,
                        "GNUNET_GTK_edit_publication_keyword_list_tree_view"));
-  ctx->keyword_del_button =
-      GTK_WIDGET (gtk_builder_get_object
-                  (ctx->builder,
-                   "GNUNET_GTK_edit_publication_keyword_list_del_button"));
-  ctx->meta_add_button =
-        GTK_BUTTON (gtk_builder_get_object
-                    (ctx->builder, "GNUNET_GTK_edit_publication_add_button"));
-  ctx->meta_combo =
-      GTK_CELL_RENDERER_COMBO (gtk_builder_get_object
-                               (ctx->builder,
-                                
"GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer"));
-  ctx->pubwindow =
-      gtk_builder_get_object (ctx->builder, 
"GNUNET_GTK_edit_publication_window");
+  ctx->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 =
       GTK_ENTRY (gtk_builder_get_object
                  (ctx->builder, "GNUNET_GTK_edit_publication_keyword_entry"));
-  ctx->ok = GTK_WIDGET (gtk_builder_get_object
+  ctx->confirm_button = GTK_WIDGET (gtk_builder_get_object
                      (ctx->builder, 
"GNUNET_GTK_edit_publication_confirm_button"));
-  ctx->keyword_add_button =
-      GTK_WIDGET (gtk_builder_get_object
-                  (ctx->builder,
-                   "GNUNET_GTK_edit_publication_keyword_list_add_button"));
-  ctx->image =
+  ctx->preview_image =
       GTK_IMAGE (gtk_builder_get_object
                  (ctx->builder,
                   "GNUNET_GTK_edit_publication_metadata_preview_image"));
   ctx->meta_liststore = GTK_LIST_STORE (gtk_builder_get_object
                          (ctx->builder,
                           "GNUNET_GTK_publication_metadata_liststore"));
-  ctx->cancel =
-      GTK_BUTTON (gtk_builder_get_object
-                  (ctx->builder, "GNUNET_GTK_edit_publication_cancel_button"));
 
-  ctx->index_label = GTK_LABEL (gtk_builder_get_object
-                    (ctx->builder, "GNUNET_GTK_edit_publication_index_label"));
   ctx->root_entry = GTK_ENTRY (gtk_builder_get_object
                     (ctx->builder, "GNUNET_GTK_edit_publication_root_entry"));
-  ctx->root_label = GTK_LABEL (gtk_builder_get_object
-                    (ctx->builder, "GNUNET_GTK_edit_publication_root_label"));
 
-  ctx->pubtypes_combo =
-      GTK_COMBO_BOX (gtk_builder_get_object
-                     (ctx->builder, "GNUNET_GTK_edit_publication_type_combo"));
 
-  ctx->year_spin = GTK_SPIN_BUTTON
+  ctx->expiration_year_spin = GTK_SPIN_BUTTON
                              (gtk_builder_get_object
                               (ctx->builder,
                                
"GNUNET_GTK_edit_publication_expiration_year_spin_button"));
@@ -814,30 +929,36 @@
   /* indexing does not apply to directories */
   gtk_widget_set_visible (GTK_WIDGET (ctx->index_checkbutton),
       !GNUNET_FS_file_information_is_directory (fip));
-  gtk_widget_set_visible (GTK_WIDGET (ctx->index_label),
+  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);
-  gtk_widget_set_visible (GTK_WIDGET (ctx->root_label),
+  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);
 
   gtk_list_store_clear (ctx->keywords_liststore);
   gtk_list_store_clear (ctx->meta_liststore);
 
   if (NULL != short_fn)
-    gtk_window_set_title (GTK_WINDOW (ctx->pubwindow), short_fn);
+    gtk_window_set_title (ctx->edit_publication_window, short_fn);
   else                                                       
-    gtk_window_set_title (GTK_WINDOW (ctx->pubwindow), _("<unnamed>"));
+    gtk_window_set_title (ctx->edit_publication_window, _("<unnamed>"));
 
-  if (gtk_combo_box_get_active_iter (ctx->pubtypes_combo, &iter))
+  pubtypes_combo =
+      GTK_COMBO_BOX (gtk_builder_get_object
+                     (ctx->builder, "GNUNET_GTK_edit_publication_type_combo"));
+  if (gtk_combo_box_get_active_iter (pubtypes_combo, &iter))
   {
     gtk_tree_model_get (GTK_TREE_MODEL (ctx->pubtypes_liststore), &iter, 0, 
&code, -1);
     change_metatypes (ctx, 0);
   }
   else
-    gtk_combo_box_set_active (ctx->pubtypes_combo, 0);
+    gtk_combo_box_set_active (pubtypes_combo, 0);
 
-  ctx->do_index = do_index;
   if (NULL != short_fn)
     ctx->short_fn = GNUNET_strdup (short_fn);
   ctx->bo = bo;
@@ -846,14 +967,14 @@
   ctx->allow_no_keywords = allow_no_keywords;
   ctx->is_directory = GNUNET_FS_file_information_is_directory (fip);
   ctx->cb = cb;
-  ctx->cls = cls;
+  ctx->cb_cls = cb_cls;
 
   GNUNET_FS_file_information_inspect (fip, &file_information_extract, ctx);
 
   gtk_entry_set_text (ctx->keyword_entry, "");
-  gtk_widget_set_sensitive (ctx->ok, allow_no_keywords ? TRUE : FALSE);
-  gtk_window_set_transient_for (GTK_WINDOW (ctx->pubwindow), parent);
-  gtk_window_present (GTK_WINDOW (ctx->pubwindow));
+  gtk_widget_set_sensitive (ctx->confirm_button, allow_no_keywords ? TRUE : 
FALSE);
+  gtk_window_set_transient_for (ctx->edit_publication_window, parent);
+  gtk_window_present (ctx->edit_publication_window);
 }
 
 




reply via email to

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