/*
     This file is part of anastasis-gtk.
     Copyright (C) 2021 Anastasis SARL

     Anastasis is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     Anastasis is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with Anastasis; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     Boston, MA 02110-1301, USA.
*/

/**
 * @file src/anastasis/anastasis-gtk_handle-policy-activate.c
 * @brief Handle double-click in policy review
 * @author Christian Grothoff
 */
#include <gnunet/gnunet_util_lib.h>
#include "anastasis-gtk_action.h"
#include "anastasis-gtk_helper.h"
#include "anastasis-gtk_pe.h"
#include "anastasis-gtk_rows.h"
#include <jansson.h>


/**
 * The user double-clicked a row of the policy review.
 *
 * @param view the column view showing the policies
 * @param position index of the row that was activated
 * @param user_data NULL
 */
void
anastasis_gtk_review_policy_treeview_row_activated_cb (
  GtkColumnView *view,
  guint position,
  gpointer user_data)
{
  GListModel *model = G_LIST_MODEL (gtk_column_view_get_model (view));
  AGRow *row;
  gpointer item;

  (void) user_data;
  item = g_list_model_get_item (model,
                                position);
  if (NULL == item)
  {
    GNUNET_break (0);
    return;
  }
  row = AG_row_of (item);
  if (AG_row_bool (row,
                   "is_challenge"))
    AG_edit_policy (AG_row_uint (row,
                                 "policy_index"));
  g_object_unref (item);
}
