/*
     This file is part of anastasis-gtk.
     Copyright (C) 2020 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-payqr-selection-changed.c
 * @brief
 * @author Christian Grothoff
 */
#include <gnunet/gnunet_util_lib.h>
#include "anastasis-gtk_action.h"
#include "anastasis-gtk_helper.h"
#include "anastasis-gtk_rows.h"
#include <jansson.h>


/**
 * Callback invoked if the QR code selection changed.
 *
 * @param selection the selection of the list of payment requests
 * @param pspec unused
 * @param user_data user data set when the signal handler was connected.
 */
void
unpaid_qr_tree_selection_changed_cb (GtkSingleSelection *selection,
                                     GParamSpec *pspec,
                                     gpointer user_data)
{
  AGRow *row;
  GdkClipboard *cb;
  GtkWidget *tv;
  const char *uri = "";

  (void) pspec;
  (void) user_data;
  tv = GTK_WIDGET (GCG_get_main_window_object ("unpaid_qr_treeview"));
  if (NULL == tv)
  {
    GNUNET_break (0);
    return;
  }
  cb = gtk_widget_get_primary_clipboard (tv);
  GNUNET_assert (NULL != cb);
  row = AG_selected (selection);
  if (NULL != row)
  {
    const char *url = AG_row_string (row,
                                     "url");

    if (NULL != url)
      uri = url;
  }
  gdk_clipboard_set_text (cb,
                          uri);
}
