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
|
/*
This file is part of GNUnet.
(C) 2011, 2013 Christian Grothoff (and other contributing authors)
GNUnet 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.
GNUnet 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 GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file src/lib/misc.c
* @brief misc functions
* @author Christian Grothoff
*/
#include "gnunet_gtk.h"
/**
* Initialize the 'expiration_year_adjustment' of the given
* builder to have a lower range of current-year+1 and a
* default of current-year+2.
*
* @param builder builder object for which we should manipulate
* the adjustment
*/
void
GNUNET_GTK_setup_expiration_year_adjustment (GtkBuilder * builder)
{
GtkAdjustment *aj;
unsigned int year;
year = GNUNET_TIME_get_current_year ();
aj = GTK_ADJUSTMENT (gtk_builder_get_object
(builder, "expiration_year_adjustment"));
gtk_adjustment_set_value (aj, year + 2);
gtk_adjustment_set_lower (aj, year + 1);
}
/**
* Convert the year from the spin button to an expiration
* time (on midnight, January 1st of that year).
*
* @param spin button with an expiration year
* @return expiration time in the usual GNUnet format
*/
struct GNUNET_TIME_Absolute
GNUNET_GTK_get_expiration_time (GtkSpinButton * spin)
{
struct GNUNET_TIME_Absolute ret;
int year;
year = gtk_spin_button_get_value_as_int (spin);
GNUNET_assert (year >= 0);
ret = GNUNET_TIME_year_to_time ((unsigned int) year);
GNUNET_break (GNUNET_TIME_absolute_get ().abs_value_us < ret.abs_value_us);
return ret;
}
/**
* Obtain the numeric anonymity level selected by a GtkComboBox.
*
* @param builder builder for looking up widgets
* @param combo_name name of the GtkComboBox with the anonymity selection
* @param p_level where to store the anonymity level
* @return TRUE on success, FALSE on failure
*/
gboolean
GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
gchar * combo_name, guint * p_level)
{
GtkComboBox *combo;
combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
if (!combo)
return FALSE;
return GNUNET_GTK_get_selected_anonymity_combo_level (combo, p_level);
}
/**
* Obtain the numeric anonymity level selected by a GtkComboBox.
*
* @param combo the GtkComboBox with the anonymity selection
* @param p_level where to store the anonymity level
* @return TRUE on success, FALSE on failure
*/
gboolean
GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level)
{
GtkTreeIter iter;
GtkTreeModel *model;
guint level;
if (! gtk_combo_box_get_active_iter (combo, &iter))
return FALSE;
model = gtk_combo_box_get_model (combo);
if (!model)
return FALSE;
gtk_tree_model_get (model, &iter,
GNUNET_GTK_ANONYMITY_LEVEL_MC_LEVEL,
&level,
-1);
if (p_level)
*p_level = level;
return TRUE;
}
/* end of misc.c */
|