gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r29953 - gnunet-gtk/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r29953 - gnunet-gtk/src/namestore
Date: Tue, 8 Oct 2013 09:25:15 +0200

Author: grothoff
Date: 2013-10-08 09:25:15 +0200 (Tue, 08 Oct 2013)
New Revision: 29953

Modified:
   gnunet-gtk/src/namestore/gnunet-namestore-gtk.c
   gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.c
   gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.h
Log:
allow editing of PHONE records (#3053)

Modified: gnunet-gtk/src/namestore/gnunet-namestore-gtk.c
===================================================================
--- gnunet-gtk/src/namestore/gnunet-namestore-gtk.c     2013-10-08 07:24:54 UTC 
(rev 29952)
+++ gnunet-gtk/src/namestore/gnunet-namestore-gtk.c     2013-10-08 07:25:15 UTC 
(rev 29953)
@@ -792,7 +792,6 @@
 }
 
 
-
 /**
  * Process a record that was stored in the namestore.
  *
@@ -999,10 +998,12 @@
       struct GNUNET_HashCode query;
 
       /* determine target zone */
-      if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
-                                                               "gns",
-                                                               
edc->new_zone_option,
-                                                               &keyfile))
+      if ( (GNUNET_OK !=
+            GNUNET_CONFIGURATION_get_value_filename (cfg,
+                                                     "gns",
+                                                     edc->new_zone_option,
+                                                     &keyfile)) ||
+           (NULL == keyfile) )
       {
        char *emsg;
 
@@ -1012,6 +1013,7 @@
        show_error_message (_("Failed to access key for target zone"),
                            emsg);
        GNUNET_free (emsg);
+        break;
       }
       pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
       GNUNET_free (keyfile);
@@ -1127,6 +1129,9 @@
   case GNUNET_NAMESTORE_TYPE_LEHO:
     GNS_edit_dialog_leho (edc);
     break;
+  case GNUNET_NAMESTORE_TYPE_PHONE:
+    GNS_edit_dialog_phone (edc);
+    break;
   case GNUNET_NAMESTORE_TYPE_PKEY:
     GNS_edit_dialog_pkey (edc);
     break;

Modified: gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.c
===================================================================
--- gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.c        2013-10-08 
07:24:54 UTC (rev 29952)
+++ gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.c        2013-10-08 
07:25:15 UTC (rev 29953)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2012 Christian Grothoff (and other contributing authors)
+     (C) 2012, 2013 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -1107,6 +1107,149 @@
 }
 
 
+/* ************************ PHONE records *********************** */
+
+/**
+ * Check validity of the value in the edit dialog for PHONE-records.
+ * Then call the shared validity check if the result is OK.
+ *
+ * @param edc edit dialog context
+ */
+static void
+edit_dialog_phone_validity_check (struct EditDialogContext *edc)
+{
+  GtkEditable *entry;
+  const gchar *preedit;
+  struct GNUNET_CRYPTO_EccPublicSignKey pub;
+
+  entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder,
+                                               
"edit_dialog_phone_peer_entry")),
+  preedit = gtk_editable_get_chars (entry, 0, -1);
+  if ( (NULL == preedit) ||
+       (GNUNET_OK !=
+       GNUNET_CRYPTO_ecc_public_sign_key_from_string (preedit,
+                                                       strlen (preedit),
+                                                       &pub)) )
+  {
+    edit_dialog_disable_save (edc);
+    return;
+  }
+  edit_dialog_check_save (edc);
+}
+
+
+/**
+ * Editing dialog was closed, get the data and call the
+ * continuation.
+ *
+ * @param dialog editing dialog
+ * @param response_id action that caused the dialog to be closed
+ * @param user_data the 'struct EditDialogContext'
+ */
+void
+GNS_edit_phone_dialog_response_cb (GtkDialog *dialog,
+                                  gint response_id,
+                                  gpointer user_data)
+{
+  struct EditDialogContext *edc = user_data;
+  GtkEntry *entry;
+  GtkSpinButton *spin;
+  const gchar *value;
+  unsigned int line;
+
+  if (GTK_RESPONSE_OK == response_id)
+  {
+    edit_dialog_putes_common_elements (edc);
+    entry = GTK_ENTRY (gtk_builder_get_object (edc->builder,
+                                              "edit_dialog_phone_peer_entry"));
+    value = gtk_entry_get_text (entry);
+    spin = GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder,
+                                                    
"edit_dialog_phone_line_spinbutton"));
+    line = gtk_spin_button_get_value (spin);
+    g_free (edc->n_value);
+    GNUNET_asprintf (&edc->n_value,
+                     "%u-%s",
+                     line,
+                     value);
+  }
+  gtk_widget_destroy (GTK_WIDGET (edc->dialog));
+  g_object_unref (edc->builder);
+  edc->builder = NULL;
+  edc->cont (edc, response_id);
+}
+
+
+/**
+ * The user has edited the PHONE record value.  Enable/disable 'save'
+ * button depending on the validity of the value.
+ *
+ * @param entry editing widget
+ * @param user_data the 'struct EditDialogContext' of the dialog
+ */
+void
+GNS_edit_dialog_phone_peer_entry_changed_cb (GtkEditable *entry,
+                                             gpointer user_data)
+{
+  struct EditDialogContext *edc = user_data;
+
+  edit_dialog_phone_validity_check (edc);
+}
+
+
+/**
+ * Run an GNS Edit dialog for a 'PHONE' Record.
+ *
+ * @param edc editing context to use
+ */
+void
+GNS_edit_dialog_phone (struct EditDialogContext *edc)
+{
+  const char *minus;
+  unsigned int line;
+
+  edc->builder = GNUNET_GTK_get_new_builder 
("gnunet_namestore_edit_phone.glade",
+                                            edc);
+  if (NULL == edc->builder)
+  {
+    GNUNET_break (0);
+    edc->cont (edc, GTK_RESPONSE_CANCEL);  /* treat as 'cancel' */
+    return;
+  }
+  if (GNUNET_YES ==
+      edc->old_record_in_namestore)
+  {
+    /* set PKEY record */
+    if (1 != (sscanf (edc->n_value,
+                      "%u-",
+                      &line)))
+    {
+      GNUNET_break (0);
+    }
+    else
+    {
+      gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object 
(edc->builder,
+                                                                          
"edit_dialog_phone_line_spinbutton")),
+                                 line);
+
+    }
+    if (NULL == (minus = strchr (edc->n_value, '-')))
+    {
+      GNUNET_break (0);
+    }
+    else
+    {
+      gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder,
+                                                             
"edit_dialog_phone_peer_entry")),
+                          minus + 1);
+    }
+  }
+  edc->validator = &edit_dialog_phone_validity_check;
+  edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder,
+                                                   "edit_phone_dialog"));
+  run_edit_dialog (edc);
+}
+
+
 /* ************************ PKEY records *********************** */
 
 /**

Modified: gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.h
===================================================================
--- gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.h        2013-10-08 
07:24:54 UTC (rev 29952)
+++ gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.h        2013-10-08 
07:25:15 UTC (rev 29953)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2012 Christian Grothoff (and other contributing authors)
+     (C) 2012, 2013 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -197,6 +197,15 @@
 
 
 /**
+ * Run an GNS Edit dialog for a 'PHONE' Record.
+ *
+ * @param edc editing context to use
+ */
+void
+GNS_edit_dialog_phone (struct EditDialogContext *edc);
+
+
+/**
  * Run an GNS Edit dialog for an 'PKEY' Record.
  *
  * @param edc editing context to use




reply via email to

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