gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r25182 - gnunet-gtk/src/setup


From: gnunet
Subject: [GNUnet-SVN] r25182 - gnunet-gtk/src/setup
Date: Mon, 3 Dec 2012 10:54:22 +0100

Author: grothoff
Date: 2012-12-03 10:54:21 +0100 (Mon, 03 Dec 2012)
New Revision: 25182

Modified:
   gnunet-gtk/src/setup/gnunet-setup-gns.c
Log:
-more preparations for custom edit dialog

Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c     2012-12-03 08:37:51 UTC (rev 
25181)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c     2012-12-03 09:54:21 UTC (rev 
25182)
@@ -140,7 +140,14 @@
    * A gchararray with the name of the color to use for the
    * name column.
    */
-  GNS_TREESTORE_COL_NAME_COLOR
+  GNS_TREESTORE_COL_NAME_COLOR,
+
+
+  /**
+   * A gboolean; TRUE if the 'type' column can still be changed;
+   * FALSE once we have edited the value.
+   */
+  GNS_TREESTORE_COL_TYPE_IS_EDITABLE
 };
 
 
@@ -858,6 +865,7 @@
         (NULL == n_value) ||
         (GNUNET_OK != GNUNET_NAMESTORE_string_to_value(n_type, n_value, &data, 
&data_size)) )
     {
+      GNUNET_break (0);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Invalid record, skipping\n");
       records--;
@@ -1021,18 +1029,14 @@
   GtkTreeIter it;
   GtkTreeIter parent;
   char *name;
-  int valid = GNUNET_YES;
   struct GNUNET_NAMESTORE_RecordData rd;
   struct RemoveContext *rc;
   char *n_name;
   int n_type;
   gboolean n_public;
-  char *n_exp_color;
   guint64 n_exp_time;
-  char *n_exp_str;
   gboolean n_is_relative;
   char *n_value;
-  char *n_value_color;
 
   gtk_tree_model_get_iter_from_string (tm, &it, path);
   gtk_tree_model_get (tm, &it,
@@ -1047,62 +1051,30 @@
                        GNS_TREESTORE_COL_NAME, &n_name,
                        GNS_TREESTORE_COL_RECORD_TYPE, &n_type,
                        GNS_TREESTORE_COL_IS_PUBLIC, &n_public,
-                       GNS_TREESTORE_COL_EXP_TIME_COLOR, &n_exp_color,
                        GNS_TREESTORE_COL_EXP_TIME, &n_exp_time,
                        GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative,
-                       GNS_TREESTORE_COL_EXP_TIME_AS_STR, &n_exp_str,
                        GNS_TREESTORE_COL_VAL_AS_STR, &n_value,
-                       GNS_TREESTORE_COL_VAL_COLOR, &n_value_color,
                        -1);
     
     /* valid name */
-    if (NULL == n_name)
-        valid = GNUNET_NO;
+    if (n_public)
+      rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
+    else
+      rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
+    if (n_is_relative)
+      rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+    rd.record_type = n_type;
+    rd.expiration_time = n_exp_time;
+    GNUNET_NAMESTORE_string_to_value (n_type, n_value,
+                                     (void**)&rd.data, &rd.data_size);
     
-    /* valid record type */
-    if (0 == n_type)
-      valid = GNUNET_NO;
-    
-    /* valid expiration */
-    if ( (NULL != n_exp_color) || 
-        (NULL == n_exp_str) || 
-        (0 == n_exp_time) )
-      valid = GNUNET_NO;
-    
-    /* valid value */
-    if ( (NULL != n_value_color) || 
-        (NULL == n_value) )
-      valid = GNUNET_NO;
-    
-    if (GNUNET_YES == valid)
-    {
-      if (n_public)
-        rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
-      else
-        rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
-      if (n_is_relative)
-       rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
-      rd.record_type = n_type;
-      rd.expiration_time = n_exp_time;
-      GNUNET_NAMESTORE_string_to_value (n_type, n_value,
-                                        (void**)&rd.data, &rd.data_size);
-
-      rc = GNUNET_malloc (sizeof (struct RemoveContext));
-      rc->path = strdup (path);
-      rc->qe = GNUNET_NAMESTORE_record_remove (namestore, pkey, name, &rd, 
-                                              &update_treemodel_after_remove, 
rc);
-      GNUNET_free ((void *) rd.data);
-    }
-    else
-    {
-      gtk_tree_model_get_iter_from_string(tm, &it, path);
-      gtk_tree_store_remove (ts, &it);
-    }
+    rc = GNUNET_malloc (sizeof (struct RemoveContext));
+    rc->path = strdup (path);
+    rc->qe = GNUNET_NAMESTORE_record_remove (namestore, pkey, name, &rd, 
+                                            &update_treemodel_after_remove, 
rc);
+    GNUNET_free ((void *) rd.data);
     g_free (n_name);
-    g_free (n_exp_color);
-    g_free (n_exp_str);
     g_free (n_value);
-    g_free (n_value_color);
   }
   else if (0 != strcmp (name, ROOT_STR))
   {
@@ -1117,9 +1089,25 @@
 
 
 /**
+ * Edit the record at the currently selected row.  If the old record
+ * exists, allow the user to modify or delete it; if it does not
+ * exist, remove it _only_ from the model (by offering the user the
+ * 'cancel' option; hide 'delete' in this case).
+ *
+ * @param old_record_in_namestore GNUNET_YES if the old record exists in the 
namestore,
+ *                                GNUNET_NO if this is a new record that 
doesn't exist yet
+ */
+static void
+edit_selected_row (int old_record_in_namestore)
+{
+  // FIXME
+  GNUNET_break (0);
+}
+
+
+/**
  * The user has selected a new record type.  Update the
- * model, possibly invalidating (marking 'red') the existing
- * value.
+ * model and then start the 'edit' dialog.
  *
  * @param renderer updated renderer
  * @param path the path identifying the edited cell
@@ -1136,14 +1124,7 @@
   GtkTreeIter it;
   GtkTreeIter child;
   guint type;
-  gboolean not_dummy_row;
   char *name_str;
-  char *value_str;
-  int is_valid;
-  void *data;
-  size_t data_size;
-  GtkTreePath *tp;
-  GtkTreeViewColumn *value_column;
 
   type = GNUNET_NAMESTORE_typename_to_number (new_text);
   if (UINT32_MAX == type)
@@ -1151,69 +1132,33 @@
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Invalid or unsupported record type `%s'\n",
                new_text);
+    show_error_message (_("Unsupported record type"),
+                       new_text);
     return;
   }
   /* check if this is a new record */
   gtk_tree_model_get_iter_from_string (tm, &it, path);
   gtk_tree_model_get (tm, &it,
-                     GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy_row, 
-                     GNS_TREESTORE_COL_NAME, &name_str, 
-                     GNS_TREESTORE_COL_VAL_AS_STR, &value_str, 
+                     GNS_TREESTORE_COL_NAME, &name_str,
                      -1);
-  is_valid = GNUNET_NO;
-  if ( (NULL != value_str) &&
-       (GNUNET_OK == GNUNET_NAMESTORE_string_to_value (type,
-                                                      value_str,
-                                                      &data,
-                                                      &data_size)) )
-  {
-    is_valid = GNUNET_YES;
-    GNUNET_free_non_null (data);
-  }
-  if (not_dummy_row)
-  {
-    /* Updating an existing record */
-    gtk_tree_store_set (ts, &it,
-                       GNS_TREESTORE_COL_RECORD_TYPE, type,
-                       GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, new_text,
-                       GNS_TREESTORE_COL_VAL_COLOR, (GNUNET_NO == is_valid) ? 
"red" : NULL,
-                       -1);
-  }
-  else if ((NULL != name_str) && (0 != strcmp (NEW_NAME_STR, name_str)))
-  {
-    /* Adding a new record */
-    gtk_tree_store_insert_with_values (ts, &child , &it, -1,
-                                      GNS_TREESTORE_COL_NAME, name_str,
-                                      GNS_TREESTORE_COL_NAME_IS_VISIBLE, FALSE,
-                                      GNS_TREESTORE_COL_RECORD_TYPE, type,
-                                      GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, 
new_text,
-                                      GNS_TREESTORE_COL_EXP_TIME_AS_STR, 
EXPIRE_NEVER_STRING,
-                                      GNS_TREESTORE_COL_EXP_TIME, 
GNUNET_TIME_UNIT_FOREVER_ABS,
-                                      GNS_TREESTORE_COL_EXP_TIME_IS_REL, FALSE,
-                                      GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE,
-                                      GNS_TREESTORE_COL_NOT_DUMMY_ROW, TRUE,
-                                      GNS_TREESTORE_COL_VAL_COLOR, "red",
-                                      -1);
-    /* select new row and start editing 'value' */
-    gtk_tree_view_expand_row (tv, gtk_tree_model_get_path(tm, &it), 0);
-    sel = gtk_tree_view_get_selection (tv);
-    gtk_tree_selection_select_iter (sel, &child);
-    value_column = GTK_TREE_VIEW_COLUMN (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_value_treeviewcolumn"));
-    tp = gtk_tree_model_get_path (tm, &child);
-    gtk_tree_view_set_cursor (tv,
-                             tp,
-                             value_column,
-                             TRUE);
-    gtk_tree_path_free (tp);
-  }
-  else
-  {
-    /* type should not have been editable! */
-    GNUNET_break (0);
-  }
-  GNUNET_free_non_null (value_str);
-  GNUNET_free_non_null (name_str);
-  check_name_validity_and_commit (&it, NULL);
+  gtk_tree_store_insert_with_values (ts, &child , &it, -1,
+                                    GNS_TREESTORE_COL_NAME, name_str,
+                                    GNS_TREESTORE_COL_NAME_IS_VISIBLE, FALSE,
+                                    GNS_TREESTORE_COL_RECORD_TYPE, type,
+                                    GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, 
new_text,
+                                    GNS_TREESTORE_COL_EXP_TIME_AS_STR, 
EXPIRE_NEVER_STRING,
+                                    GNS_TREESTORE_COL_EXP_TIME, 
GNUNET_TIME_UNIT_FOREVER_ABS,
+                                    GNS_TREESTORE_COL_EXP_TIME_IS_REL, FALSE,
+                                    GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE,
+                                    GNS_TREESTORE_COL_NOT_DUMMY_ROW, TRUE,
+                                    GNS_TREESTORE_COL_TYPE_IS_EDITABLE, FALSE,
+                                    -1);
+  /* select new row and start editing 'value' */
+  gtk_tree_view_expand_row (tv, gtk_tree_model_get_path (tm, &it), 0);
+  sel = gtk_tree_view_get_selection (tv);
+  gtk_tree_selection_select_iter (sel, &child);
+  g_free (name_str);
+  edit_selected_row (GNUNET_NO);
 }
 
 
@@ -1345,6 +1290,7 @@
                         GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, 
_(NEW_RECORD_STR),
                         GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE,
                        GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE,
+                       GNS_TREESTORE_COL_TYPE_IS_EDITABLE, TRUE,
                         -1);
     check_name_validity_and_commit (&it,
                                    name);
@@ -1357,6 +1303,7 @@
                                         GNS_TREESTORE_COL_RECORD_TYPE, 
GNUNET_DNSPARSER_TYPE_A,
                                         GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE,
                                         GNS_TREESTORE_COL_IS_RECORD_ROW, FALSE,
+                                        GNS_TREESTORE_COL_TYPE_IS_EDITABLE, 
FALSE,
                                         -1);
     }
   }
@@ -1381,19 +1328,6 @@
 
     check_name_validity_and_commit (&it, name);
   }
-
-  if (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (new_text))
-  {
-    gtk_tree_store_set (ts, &it,
-                        GNS_TREESTORE_COL_NAME_COLOR, "red",
-                        -1);
-  }
-  else
-  {
-    gtk_tree_store_set (ts, &it,
-                        GNS_TREESTORE_COL_NAME_COLOR, NULL,
-                        -1);
-  }
 }
 
 
@@ -1480,7 +1414,7 @@
 GNUNET_setup_gns_popup_edit_button_activate_cb (GtkWidget *widget,
                                                gpointer user_data)
 {
-  // FIXME: create dialog to edit_selected_row ();
+  edit_selected_row (GNUNET_YES);
 }
 
 
@@ -1864,7 +1798,12 @@
     gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_zone_selection_hbuttonbox")));
     return;
   }
-
+  if (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name))
+  {
+    GNUNET_break (0);
+    GNUNET_NAMESTORE_zone_iterator_next (zc_ctx->it);
+    return;
+  }
   GNUNET_CRYPTO_short_hash_to_enc (&zc_ctx->zone, &shenc);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
              "Zone `%s' iteration result `%s', %u records\n",
@@ -1879,19 +1818,14 @@
                      GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE,
                      -1);
 
-  if (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name))
-  {
-    gtk_tree_store_set (ts, &iter_name,
-                        GNS_TREESTORE_COL_NAME_COLOR, "red",
-                        -1);
-  }
   /* Append elements for records */
   for (c = 0; c < rd_count; c ++)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Record %u: type %u flags %u expiration %llu data_size %u\n",
                c, rd[c].record_type, rd[c].flags,
-               rd[c].expiration_time, rd[c].data_size);
+               rd[c].expiration_time,
+               rd[c].data_size);
 
     /* Set public toggle */
     public = ((rd[c].flags & GNUNET_NAMESTORE_RF_PRIVATE) != 
GNUNET_NAMESTORE_RF_PRIVATE);
@@ -1923,7 +1857,7 @@
     if (NULL != GNUNET_NAMESTORE_number_to_typename (rd[c].record_type))
       type_str = strdup (GNUNET_NAMESTORE_number_to_typename 
(rd[c].record_type));
     else
-      GNUNET_asprintf(&type_str, "%s", EXPIRE_INVALID_STRING);
+      GNUNET_asprintf (&type_str, "%s", EXPIRE_INVALID_STRING);
 
     if ( (0 == strcmp (name, ROOT_STR)) && 
         (GNUNET_NAMESTORE_TYPE_PSEU == rd[c].record_type) )




reply via email to

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