anastasis-gtk

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

anastasis-gtk_handle-expiration-change.c (3060B)


      1 /*
      2      This file is part of anastasis-gtk.
      3      Copyright (C) 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-expiration-change.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 <jansson.h>
     29 
     30 
     31 struct GNUNET_TIME_Timestamp
     32 AG_get_desired_expiration ()
     33 {
     34   GtkSpinButton *spin_button;
     35   gint value;
     36   struct GNUNET_TIME_Timestamp exp_time;
     37   struct GNUNET_JSON_Specification spec[] = {
     38     GNUNET_JSON_spec_timestamp ("expiration",
     39                                 &exp_time),
     40     GNUNET_JSON_spec_end ()
     41   };
     42   struct tm tv;
     43 
     44   if (GNUNET_OK !=
     45       GNUNET_JSON_parse (AG_redux_state,
     46                          spec,
     47                          NULL, NULL))
     48   {
     49     GNUNET_break (0);
     50     AG_error ("State did not parse correctly: lacks expiration");
     51     return GNUNET_TIME_UNIT_ZERO_TS;
     52   }
     53 
     54   {
     55     time_t t;
     56 
     57     t = exp_time.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us;
     58     GNUNET_assert (NULL !=
     59                    localtime_r (&t,
     60                                 &tv));
     61   }
     62 
     63   spin_button = GTK_SPIN_BUTTON (GCG_get_main_window_object (
     64                                    "expiration_year_spin_button"));
     65   value = gtk_spin_button_get_value_as_int (spin_button);
     66   tv.tm_year = value - 1900;
     67   {
     68     time_t t = mktime (&tv);
     69 
     70     return GNUNET_TIME_timestamp_from_s (t);
     71   }
     72 }
     73 
     74 
     75 /**
     76  * Callback invoked if the user changed when the
     77  * backup may expire. Update cost.
     78  *
     79  * @param spin_button the spin button that changed
     80  * @param user_data NULL
     81  */
     82 void
     83 expiration_year_spin_button_value_changed_cb (
     84   GtkSpinButton *spin_button,
     85   gpointer user_data)
     86 {
     87   json_t *arg;
     88   struct GNUNET_TIME_Timestamp expiration;
     89 
     90   if (AG_in_action)
     91     return;
     92   expiration = AG_get_desired_expiration ();
     93   if (GNUNET_TIME_absolute_is_zero (expiration.abs_time))
     94     return; /* failured */
     95   arg = GNUNET_JSON_PACK (
     96     GNUNET_JSON_pack_timestamp ("expiration",
     97                                 expiration));
     98   AG_freeze ();
     99   AG_ra = ANASTASIS_redux_action (AG_redux_state,
    100                                   "update_expiration",
    101                                   arg,
    102                                   &AG_action_cb,
    103                                   NULL);
    104   json_decref (arg);
    105 }