anastasis-gtk

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

anastasis-gtk_handle-policy-button.c (2428B)


      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 /**
     22  * @file src/anastasis/anastasis-gtk_handle-policy-button.c
     23  * @brief Handle right-click context menu in policy review
     24  * @author Christian Grothoff
     25  */
     26 #include <gnunet/gnunet_util_lib.h>
     27 #include "anastasis-gtk_action.h"
     28 #include "anastasis-gtk_helper.h"
     29 #include "anastasis-gtk_pe.h"
     30 #include "anastasis-gtk_rows.h"
     31 #include <jansson.h>
     32 
     33 
     34 /**
     35  * The user pressed a key while the policy list had the focus.  'Delete'
     36  * removes the selected policy or challenge.
     37  *
     38  * @param controller the key controller of the tree view
     39  * @param keyval the key that was pressed
     40  * @param keycode the hardware code of that key
     41  * @param state the modifiers that were held
     42  * @param user_data NULL
     43  * @return TRUE if the key was handled here
     44  */
     45 gboolean
     46 anastasis_gtk_review_policy_treeview_key_pressed_cb (
     47   GtkEventControllerKey *controller,
     48   guint keyval,
     49   guint keycode,
     50   GdkModifierType state,
     51   gpointer user_data)
     52 {
     53   AGRow *row;
     54   guint pindex;
     55 
     56   (void) controller;
     57   (void) keycode;
     58   (void) state;
     59   (void) user_data;
     60   if (GDK_KEY_Delete != keyval)
     61     return FALSE;
     62   row = AG_selected_row ("anastasis_gtk_review_policy_selection");
     63   if (NULL == row)
     64   {
     65     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     66                 "Nothing selected, cannot delete\n");
     67     return FALSE;
     68   }
     69   pindex = AG_row_uint (row,
     70                         "policy_index");
     71   if (AG_row_bool (row,
     72                    "is_challenge"))
     73     AG_delete_challenge (pindex,
     74                          AG_row_uint (row,
     75                                       "method_index"));
     76   else
     77     AG_delete_policy (pindex);
     78   return TRUE;
     79 }