aboutsummaryrefslogtreecommitdiff
path: root/src/anastasis/anastasis-gtk_progress.c
blob: d3863bd340d0374efd50d160a3397a447eee0152 (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
141
142
143
144
145
146
147
148
149
150
151
152
/*
     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_progress.c
 * @brief Functions dealing with the tree views used to show the user where we are in the process
 * @author Christian Grothoff
 */
#include <gnunet/gnunet_util_lib.h>
#include "anastasis-gtk_helper.h"
#include <gdk-pixbuf/gdk-pixbuf.h>


/**
 * Ensure signals are ignored where the user
 * clicks in the widget.
 */
gboolean
anastasis_gtk_backup_progress_treeview_button_press_event_cb (GtkWidget *widget,
                                                              GdkEvent  *event,
                                                              gpointer user_data)
{
  return TRUE;
}


/**
 * Ensure signals are ignored where the user
 * clicks in the widget.
 */
gboolean
anastasis_gtk_recovery_progress_treeview_button_press_event_cb (
  GtkWidget *widget,
  GdkEvent  *event,
  gpointer
  user_data)
{
  return TRUE;
}


/**
 * Function to validate an input by regular expression ("validation-regex").
 *
 * @param input text to validate
 * @param regexp regular expression to validate form
 * @return true if validation passed, else false
 */
static bool
validate_regex (const char *input,
                const char *regexp)
{
  regex_t regex;

  if (0 != regcomp (&regex,
                    regexp,
                    REG_EXTENDED))
  {
    GNUNET_break (0);
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Failed to compile regular expression `%s'.",
                regexp);
    return true;
  }
  /* check if input has correct form */
  if (0 != regexec (&regex,
                    input,
                    0,
                    NULL,
                    0))
  {
    regfree (&regex);
    return false;
  }
  regfree (&regex);
  return true;
}


void
AG_progress_update (void)
{
  GtkTreeSelection *ts;
  GtkTreeModel *tm;
  GtkTreeIter iter;
  const char *state;

  state = json_string_value (json_object_get (AG_redux_state,
                                              "backup_state"));
  if (NULL == state)
  {
    state = json_string_value (json_object_get (AG_redux_state,
                                                "recovery_state"));
    if (NULL == state)
    {
      GNUNET_break (0);
      return;
    }
    ts = GTK_TREE_SELECTION (GCG_get_main_window_object (
                               "anastasis_gtk_recovery_progress_tree_selection"));
  }
  else
  {
    ts = GTK_TREE_SELECTION (GCG_get_main_window_object (
                               "anastasis_gtk_backup_progress_tree_selection"));
  }
  gtk_tree_selection_get_selected (ts,
                                   &tm,
                                   &iter);
  if (! gtk_tree_model_get_iter_first (tm,
                                       &iter))
  {
    GNUNET_break (0);
    return;
  }
  do {
    char *regex;

    gtk_tree_model_get (tm,
                        &iter,
                        AG_PRGMC_REGEX, &regex,
                        -1);
    if (validate_regex (state,
                        regex))
    {
      g_free (regex);
      gtk_tree_selection_select_iter (ts,
                                      &iter);
      return;
    }
    g_free (regex);
  } while (gtk_tree_model_iter_next (tm,
                                     &iter));
  GNUNET_break (0);
  return;
}