summaryrefslogtreecommitdiff
path: root/src/anastasis/anastasis-gtk_backup.c
blob: 72963872cab3d9e861671faad45a228cefa9b5a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
     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_backup.c
 * @brief Main function of anastasis-gtk
 * @author Christian Grothoff
 * @author Dennis Neufeld
 */
#include <gnunet/platform.h>
#include <gnunet/gnunet_util_lib.h>
#include "anastasis-gtk_action.h"
#include "anastasis-gtk_helper.h"
#include <jansson.h>


/**
 * Callback invoked if the the "video OK"-button is clicked.
 *
 * @param object
 * @param user_data unused
 */
void
anastasis_gtk_b_video_dialog_btn_ok_clicked_cb (GObject *object,
                                                gpointer user_data)
{
  GtkHBox *hbox;
  GtkBox *vbox = GTK_BOX (GCG_get_main_window_object (
                            "anastasis_gtk_b_authentication_vbox"));

  bool is_box = GTK_IS_BOX (user_data);
  if (is_box)
  {
    hbox = (GtkHBox *) user_data;
    // if is_box is true, we are editing and have to delete the old method
    delete_auth_method (user_data);
  }
  else
    hbox = (GtkHBox *) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  // set labels
  GtkLabel *label_prefix = (GtkLabel *) gtk_label_new ("VIDEO: ");
  const gchar *photo_path = gtk_entry_get_text (
    GTK_ENTRY (GCG_get_main_window_object (
                 "anastasis_gtk_b_video_dialog_photo_path_entry")));
  GtkLabel *label_photo_path = (GtkLabel *) gtk_label_new (photo_path);
  {
    // build json arguments for reducer
    json_t *arguments = json_object ();
    json_t *auth_method = json_object ();
    json_t *method_data = json_object ();

    json_object_set_new (auth_method, "method", json_string ("video"));
    json_object_set_new (method_data, "picture", json_string (photo_path));       // FIXME: load photo, not only path
    json_object_set_new (auth_method, "data", method_data);
    json_object_set_new (arguments, "authentication_method", method_data);

    ra = ANASTASIS_redux_action (AG_redux_state,
                                 "add_authentication",
                                 arguments,
                                 &AG_action_cb,
                                 NULL);
  }

  // set buttons
  GtkHButtonBox *buttons = (GtkHButtonBox *) gtk_box_new (1, 0);
  GtkButton  *edit_btn = (GtkButton *) gtk_button_new_from_icon_name (
    "gtk-edit", GTK_ICON_SIZE_BUTTON);
  g_signal_connect (edit_btn,
                    "clicked",
                    G_CALLBACK (
                      anastasis_gtk_b_auth_method_btn_edit_clicked_cb),
                    hbox);
  GtkButton  *delete_btn = (GtkButton *) gtk_button_new_from_icon_name (
    "gtk-delete", GTK_ICON_SIZE_BUTTON);
  g_signal_connect (delete_btn,
                    "clicked",
                    G_CALLBACK (
                      anastasis_gtk_b_auth_method_btn_delete_clicked_cb),
                    hbox);
  gtk_box_pack_start (GTK_BOX (buttons), GTK_WIDGET (edit_btn), 0, 0, 0);
  gtk_box_pack_start (GTK_BOX (buttons), GTK_WIDGET (delete_btn), 0, 0, 0);

  gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (label_prefix), 0, 0, 0);
  gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (label_photo_path), 0, 0, 0);
  gtk_box_pack_end (GTK_BOX (hbox), GTK_WIDGET (buttons), 0, 0, 0);

  if (! is_box)
  {
    gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (hbox), 0, 0, 0);
  }

  gtk_widget_show (GTK_WIDGET (hbox));
  gtk_widget_show (GTK_WIDGET (label_prefix));
  gtk_widget_show (GTK_WIDGET (label_photo_path));
  gtk_widget_show (GTK_WIDGET (buttons));
  gtk_widget_show (GTK_WIDGET (edit_btn));
  gtk_widget_show (GTK_WIDGET (delete_btn));

  gtk_entry_set_text (GTK_ENTRY (
                        GCG_get_main_window_object (
                          "anastasis_gtk_b_video_dialog_photo_path_entry")),
                      "");
  gtk_widget_hide (GTK_WIDGET (GCG_get_main_window_object (
                                 "anastasis_gtk_b_video_dialog")));
  gtk_widget_set_sensitive (GTK_WIDGET (GCG_get_main_window_object (
                                          "anastasis_gtk_main_window_forward_button")),
                            true);
}


/**
 * Callback invoked if the the "video"-button is clicked.
 *
 * @param object
 * @param user_data unused
 */
void
anastasis_gtk_btn_add_auth_video_clicked_cb (GObject *object,
                                             gpointer user_data)
{
  gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
                                 "anastasis_gtk_b_video_dialog")));
}