anastasis-gtk

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

anastasis-gtk_handle-main-window-back-clicked.c (3237B)


      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-main-window-back-clicked.c
     23  * @brief
     24  * @author Christian Grothoff
     25  * @author Dennis Neufeld
     26  */
     27 #include <gnunet/gnunet_util_lib.h>
     28 #include "anastasis-gtk_action.h"
     29 #include "anastasis-gtk_helper.h"
     30 #include <jansson.h>
     31 
     32 
     33 /**
     34  * Start interaction from the beginning.
     35  */
     36 static void
     37 fresh_start (void)
     38 {
     39   AG_hide_all_frames ();
     40   json_decref (AG_redux_state);
     41   AG_redux_state = NULL;
     42   AG_hide ("anastasis_gtk_progress_vbox");
     43   AG_hide ("anastasis_gtk_backup_progress_scrolled_window");
     44   AG_hide ("anastasis_gtk_recovery_progress_scrolled_window");
     45   AG_hide ("anastasis_gtk_restart_button");
     46   AG_hide ("anastasis_gtk_main_control_vbox");
     47   AG_show ("anastasis_gtk_start_frame");
     48 }
     49 
     50 
     51 /**
     52  * Callback invoked if the "back"-button is clicked.
     53  *
     54  * @param object
     55  * @param user_data unused
     56  */
     57 void
     58 anastasis_gtk_main_window_back_clicked (GObject *object,
     59                                         gpointer user_data)
     60 {
     61   const char *state;
     62 
     63   (void) object;
     64   (void) user_data;
     65   if (NULL != AG_ra)
     66   {
     67     /* This happens if we were long polling for payment */
     68     ANASTASIS_redux_action_cancel (AG_ra);
     69     AG_ra = NULL;
     70   }
     71   if (NULL != AG_pd)
     72   {
     73     ANASTASIS_policy_discovery_stop (AG_pd);
     74     AG_pd = NULL;
     75   }
     76   AG_stop_long_action ();
     77   state = json_string_value (json_object_get (AG_redux_state,
     78                                               "recovery_state"));
     79   if (NULL == state)
     80     state = json_string_value (json_object_get (AG_redux_state,
     81                                                 "backup_state"));
     82 
     83   if ( (0 == strcasecmp (state,
     84                          "CONTINENT_SELECTING")) ||
     85        (0 == strcasecmp (state,
     86                          "COUNTRY_SELECTING")) )
     87   {
     88     AG_hide ("anastasis_gtk_continent_frame");
     89     fresh_start ();
     90     return;
     91   }
     92   AG_freeze ();
     93   AG_ra = ANASTASIS_redux_action (AG_redux_state,
     94                                   "back",
     95                                   NULL,
     96                                   &AG_action_cb,
     97                                   NULL);
     98 }
     99 
    100 
    101 /**
    102  * Callback invoked if the "restart"-button is clicked.
    103  *
    104  * @param object
    105  * @param user_data unused
    106  */
    107 void
    108 anastasis_gtk_restart_button_clicked_cb (GObject *object,
    109                                          gpointer user_data)
    110 {
    111   (void) object;
    112   (void) user_data;
    113   AG_hide ("anastasis_gtk_restart_button");
    114   fresh_start ();
    115 }