anastasis-gtk

Demonstrator GUI for Anastasis
Log | Files | Refs | README | LICENSE

anastasis-gtk_handle-method-question.c (5052B)


      1 /*
      2      This file is part of anastasis-gtk.
      3      Copyright (C) 2020 Anastasis SARL
      4 
      5      Anastasis is free software; you can redistribute it and/or modify
      6      it under the terms of the GNU General Public License as published
      7      by the Free Software Foundation; either version 3, or (at your
      8      option) any later version.
      9 
     10      Anastasis is distributed in the hope that it will be useful, but
     11      WITHOUT ANY WARRANTY; without even the implied warranty of
     12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13      General Public License for more details.
     14 
     15      You should have received a copy of the GNU General Public License
     16      along with Anastasis; see the file COPYING.  If not, write to the
     17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18      Boston, MA 02110-1301, USA.
     19 */
     20 
     21 /**
     22  * @file src/anastasis/anastasis-gtk_handle-method-question.c
     23  * @brief Handle dialogs for security question
     24  * @author Christian Grothoff
     25  */
     26 #include <gnunet/gnunet_util_lib.h>
     27 #include "anastasis_gtk_util.h"
     28 #include "anastasis-gtk_action.h"
     29 #include "anastasis-gtk_helper.h"
     30 #include "anastasis-gtk_handle-identity-changed.h"
     31 #include <jansson.h>
     32 
     33 
     34 /**
     35  * Function called from the security-question dialog upon completion.
     36  *
     37  * @param dialog the pseudonym selection dialog
     38  * @param response_id response code from the dialog
     39  * @param user_data the builder of the dialog
     40  */
     41 void
     42 anastasis_gtk_b_question_dialog_response_cb (GtkDialog *dialog,
     43                                              gint response_id,
     44                                              gpointer user_data)
     45 {
     46   GtkBuilder *builder = GTK_BUILDER (user_data);
     47   GtkEntry *q;
     48   GtkEntry *a;
     49   const char *qs;
     50   const char *as;
     51   json_t *args;
     52 
     53   if (GTK_RESPONSE_OK != response_id)
     54   {
     55     gtk_widget_destroy (GTK_WIDGET (dialog));
     56     g_object_unref (G_OBJECT (builder));
     57     return;
     58   }
     59   q = GTK_ENTRY (gtk_builder_get_object (builder,
     60                                          "anastasis_gtk_b_question_dialog_question_entry"));
     61   qs = gtk_entry_get_text (q);
     62   a = GTK_ENTRY (gtk_builder_get_object (builder,
     63                                          "anastasis_gtk_b_question_dialog_answer_entry"));
     64   as = gtk_entry_get_text (a);
     65   args = json_pack ("{ s:{s:s, s:o, s:s}}",
     66                     "authentication_method",
     67                     "type",
     68                     "question",
     69                     "challenge",
     70                     GNUNET_JSON_from_data (as,
     71                                            strlen (as)),
     72                     "instructions",
     73                     qs);
     74   gtk_widget_destroy (GTK_WIDGET (dialog));
     75   g_object_unref (G_OBJECT (builder));
     76   AG_freeze ();
     77   AG_ra = ANASTASIS_redux_action (AG_redux_state,
     78                                   "add_authentication",
     79                                   args,
     80                                   &AG_action_cb,
     81                                   NULL);
     82   json_decref (args);
     83 }
     84 
     85 
     86 static void
     87 update_sensitivity (GtkBuilder *builder)
     88 {
     89   GtkEntry *q;
     90   GtkEntry *a;
     91   const char *qs;
     92   const char *as;
     93 
     94   q = GTK_ENTRY (gtk_builder_get_object (builder,
     95                                          "anastasis_gtk_b_question_dialog_question_entry"));
     96   qs = gtk_entry_get_text (q);
     97   a = GTK_ENTRY (gtk_builder_get_object (builder,
     98                                          "anastasis_gtk_b_question_dialog_answer_entry"));
     99   as = gtk_entry_get_text (a);
    100   gtk_widget_set_sensitive (
    101     GTK_WIDGET (gtk_builder_get_object (builder,
    102                                         "anastasis_gtk_b_question_dialog_btn_ok")),
    103     ( (NULL != qs) &&
    104       (0 < strlen (qs)) &&
    105       (NULL != as) &&
    106       (0 < strlen (as)) ));
    107 }
    108 
    109 
    110 void
    111 anastasis_gtk_b_question_dialog_question_entry_changed_cb (GtkEntry *entry,
    112                                                            gpointer user_data)
    113 {
    114   GtkBuilder *builder = GTK_BUILDER (user_data);
    115 
    116   update_sensitivity (builder);
    117 }
    118 
    119 
    120 void
    121 anastasis_gtk_b_question_dialog_answer_entry_changed_cb (GtkEntry *entry,
    122                                                          gpointer user_data)
    123 {
    124   GtkBuilder *builder = GTK_BUILDER (user_data);
    125 
    126   update_sensitivity (builder);
    127 }
    128 
    129 
    130 /**
    131  * Callback invoked if the the "secure question"-button is clicked.
    132  *
    133  * @param object
    134  * @param user_data unused
    135  */
    136 void
    137 anastasis_gtk_btn_add_auth_question_clicked_cb (GObject *object,
    138                                                 gpointer user_data)
    139 {
    140   GtkWidget *ad;
    141   GtkBuilder *builder;
    142 
    143   builder = ANASTASIS_GTK_get_new_builder (
    144     ANASTASIS_GTK_project_data (),
    145     "anastasis_gtk_auth_add_question.glade",
    146     NULL);
    147   if (NULL == builder)
    148   {
    149     GNUNET_break (0);
    150     return;
    151   }
    152   ad = GTK_WIDGET (gtk_builder_get_object (builder,
    153                                            "anastasis_gtk_b_question_dialog"));
    154   {
    155     GtkWidget *toplevel;
    156 
    157     toplevel = gtk_widget_get_toplevel (GTK_WIDGET (object));
    158     gtk_window_set_transient_for (GTK_WINDOW (ad),
    159                                   GTK_WINDOW (toplevel));
    160     gtk_window_present (GTK_WINDOW (ad));
    161   }
    162 }