diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk_anonymity-widgets.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk_anonymity-widgets.c | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/src/fs/gnunet-fs-gtk_anonymity-widgets.c b/src/fs/gnunet-fs-gtk_anonymity-widgets.c new file mode 100644 index 00000000..e54dd4cb --- /dev/null +++ b/src/fs/gnunet-fs-gtk_anonymity-widgets.c | |||
@@ -0,0 +1,177 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2005, 2006, 2010, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/fs/gnunet-fs-gtk_anonymtiy-widgets.c | ||
23 | * @author Christian Grothoff | ||
24 | * @brief operations to manage user's anonymity level selections | ||
25 | */ | ||
26 | #include "gnunet-fs-gtk-common.h" | ||
27 | #include "gnunet-fs-gtk-anonymity_spin_buttons.h" | ||
28 | #include <gdk/gdk.h> | ||
29 | |||
30 | /** | ||
31 | * Spin button is changed, update its color. NOTE: This function will eventually | ||
32 | * become obsolete as we migrate to the drop-down style of anonymity-level selection. | ||
33 | * | ||
34 | * @param w the spin button that changed | ||
35 | * @param builder's closure, unused | ||
36 | */ | ||
37 | void | ||
38 | GNUNET_GTK_anonymity_spin_button_value_changed_cb (GtkWidget * w, gpointer data) | ||
39 | { | ||
40 | #ifdef GdkRBGA | ||
41 | GtkSpinButton *spin; | ||
42 | gint val; | ||
43 | GdkRGBA bcolor; | ||
44 | GdkRGBA fcolor; | ||
45 | |||
46 | spin = GTK_SPIN_BUTTON (w); | ||
47 | if (spin == NULL) | ||
48 | { | ||
49 | GNUNET_break (0); | ||
50 | return; | ||
51 | } | ||
52 | val = gtk_spin_button_get_value_as_int (spin); | ||
53 | if (val == 0) | ||
54 | { | ||
55 | if ((TRUE == gdk_rgba_parse (&bcolor, "red")) && | ||
56 | (TRUE == gdk_rgba_parse (&fcolor, "black"))) | ||
57 | { | ||
58 | gtk_widget_override_background_color (w, GTK_STATE_NORMAL, &bcolor); | ||
59 | gtk_widget_override_color (w, GTK_STATE_NORMAL, &fcolor); | ||
60 | } | ||
61 | else | ||
62 | { | ||
63 | GNUNET_break (0); | ||
64 | } | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | gtk_widget_override_background_color (w, GTK_STATE_NORMAL, NULL); | ||
69 | gtk_widget_override_color (w, GTK_STATE_NORMAL, NULL); | ||
70 | } | ||
71 | #endif | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Obtain the numeric anonymity level selected by a GtkComboBox. | ||
77 | * | ||
78 | * @param builder builder for looking up widgets | ||
79 | * @param combo_name name of the GtkComboBox with the anonymity selection | ||
80 | * @param p_level where to store the anonymity level | ||
81 | * @return TRUE on success, FALSE on failure | ||
82 | */ | ||
83 | gboolean | ||
84 | GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder, | ||
85 | gchar * combo_name, guint * p_level) | ||
86 | { | ||
87 | GtkComboBox *combo; | ||
88 | |||
89 | combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name)); | ||
90 | if (!combo) | ||
91 | return FALSE; | ||
92 | return GNUNET_GTK_get_selected_anonymity_combo_level (combo, p_level); | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Obtain the numeric anonymity level selected by a GtkComboBox. | ||
98 | * | ||
99 | * @param combo the GtkComboBox with the anonymity selection | ||
100 | * @param p_level where to store the anonymity level | ||
101 | * @return TRUE on success, FALSE on failure | ||
102 | */ | ||
103 | gboolean | ||
104 | GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level) | ||
105 | { | ||
106 | GtkTreeIter iter; | ||
107 | GtkTreeModel *model; | ||
108 | guint level; | ||
109 | |||
110 | if (! gtk_combo_box_get_active_iter (combo, &iter)) | ||
111 | return FALSE; | ||
112 | model = gtk_combo_box_get_model (combo); | ||
113 | if (!model) | ||
114 | return FALSE; | ||
115 | gtk_tree_model_get (model, &iter, 1, &level, -1); | ||
116 | if (p_level) | ||
117 | *p_level = level; | ||
118 | return TRUE; | ||
119 | } | ||
120 | |||
121 | |||
122 | /** | ||
123 | * Set the anonymity level displayed by a combo box. | ||
124 | * | ||
125 | * @param builder the builder of the combo box | ||
126 | * @param combo_name name of the combo box | ||
127 | * @param sel_level desired anonymity level | ||
128 | * @return TRUE on success, FALSE on failure | ||
129 | */ | ||
130 | gboolean | ||
131 | GNUNET_GTK_select_anonymity_level (GtkBuilder * builder, gchar * combo_name, | ||
132 | guint sel_level) | ||
133 | { | ||
134 | GtkComboBox *combo; | ||
135 | |||
136 | combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name)); | ||
137 | if (!combo) | ||
138 | return FALSE; | ||
139 | return GNUNET_GTK_select_anonymity_combo_level (combo, sel_level); | ||
140 | } | ||
141 | |||
142 | |||
143 | /** | ||
144 | * Set the anonymity level displayed by a combo box. | ||
145 | * | ||
146 | * @param combo the combo box | ||
147 | * @param sel_level desired anonymity level | ||
148 | * @return TRUE on success, FALSE on failure | ||
149 | */ | ||
150 | gboolean | ||
151 | GNUNET_GTK_select_anonymity_combo_level (GtkComboBox *combo, guint sel_level) | ||
152 | { | ||
153 | GtkTreeIter iter; | ||
154 | GtkTreeModel *model; | ||
155 | guint level; | ||
156 | |||
157 | model = gtk_combo_box_get_model (combo); | ||
158 | if (!model) | ||
159 | return FALSE; | ||
160 | if (! gtk_tree_model_get_iter_first (model, &iter)) | ||
161 | return FALSE; | ||
162 | do | ||
163 | { | ||
164 | gtk_tree_model_get (model, &iter, 1, &level, -1); | ||
165 | if (level == sel_level) | ||
166 | { | ||
167 | gtk_combo_box_set_active_iter (combo, &iter); | ||
168 | return TRUE; | ||
169 | } | ||
170 | } | ||
171 | while (gtk_tree_model_iter_next (model, &iter)); | ||
172 | return FALSE; | ||
173 | } | ||
174 | |||
175 | |||
176 | |||
177 | /* end of gnunet-fs-gtk-anonymtiy_spin_buttons.c */ | ||