anastasis-gtk

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

anastasis-gtk_handle-core-secret-changed.c (3104B)


      1 /*
      2      This file is part of anastasis-gtk.
      3      Copyright (C) 2020-2021 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  * @file src/anastasis/anastasis-gtk_handle-core-secret.c
     22  * @brief
     23  * @author Christian Grothoff
     24  */
     25 #include <gnunet/gnunet_util_lib.h>
     26 #include "anastasis-gtk_helper.h"
     27 #include "anastasis-gtk_action.h"
     28 #include "anastasis-gtk_attributes.h"
     29 #include "anastasis-gtk_handle-identity-changed.h"
     30 #include "anastasis-gtk_handle-expiration-change.h"
     31 #include <jansson.h>
     32 
     33 
     34 void
     35 anastasis_gtk_enter_secret_textbuffer_changed_cb (GtkTextBuffer *tb,
     36                                                   gpointer user_data)
     37 {
     38   json_t *arguments;
     39   struct GNUNET_TIME_Timestamp expiration;
     40   GtkTextIter start;
     41   GtkTextIter end;
     42   const char *text;
     43 
     44   gtk_text_buffer_get_start_iter (tb,
     45                                   &start);
     46   gtk_text_buffer_get_end_iter (tb,
     47                                 &end);
     48   text = gtk_text_buffer_get_text (tb,
     49                                    &start,
     50                                    &end,
     51                                    true);
     52   if (AG_in_action)
     53     return;
     54   AG_in_secret_editing = true;
     55   expiration = AG_get_desired_expiration ();
     56   if (GNUNET_TIME_absolute_is_zero (expiration.abs_time))
     57     return;   /* failured */
     58   if ( (NULL == text) ||
     59        (0 == strlen (text)) )
     60   {
     61     AG_freeze ();
     62     AG_ra = ANASTASIS_redux_action (AG_redux_state,
     63                                     "clear_secret",
     64                                     NULL,
     65                                     &AG_action_cb,
     66                                     NULL);
     67     AG_focus ("anastasis_gtk_enter_secret_textview");
     68     return;
     69   }
     70   arguments = json_pack ("{s:{s:s,s:s},s:o}",
     71                          "secret",
     72                          "text",
     73                          text,
     74                          "mime",
     75                          "text/plain",
     76                          "expiration",
     77                          GNUNET_JSON_from_timestamp (expiration));
     78   GNUNET_assert (NULL != arguments);
     79   AG_freeze ();
     80   AG_ra = ANASTASIS_redux_action (AG_redux_state,
     81                                   "enter_secret",
     82                                   arguments,
     83                                   &AG_action_cb,
     84                                   NULL);
     85   json_decref (arguments);
     86   AG_focus ("anastasis_gtk_enter_secret_textview");
     87   AG_in_secret_editing = false;
     88 }