aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-26 21:12:35 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-26 21:12:35 +0000
commit4bf208e608d26cc24660d03b374c297cd4c12837 (patch)
tree4f36dfcd2013cd91bbc3bae726f7b7ebbe1d397e
parentaa8ce7b2fea4038ed751f0b5bffae3283fe27937 (diff)
downloadgnunet-gtk-4bf208e608d26cc24660d03b374c297cd4c12837.tar.gz
gnunet-gtk-4bf208e608d26cc24660d03b374c297cd4c12837.zip
gnunet-gns-gtk integrated with gnunet-setup
-rw-r--r--configure.ac9
-rw-r--r--contrib/gnunet_gns_gtk_about_window.glade340
-rw-r--r--contrib/gnunet_gns_gtk_main_window.glade483
-rw-r--r--contrib/gnunet_gns_gtk_zone_open.glade72
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gns/Makefile.am23
-rw-r--r--src/gns/gnunet-gns-gtk.c616
-rw-r--r--src/gns/gnunet-gns-gtk.h67
-rw-r--r--src/gns/gnunet-gns-gtk_about.c42
-rw-r--r--src/gns/gnunet-gns-gtk_zone.c1268
10 files changed, 1 insertions, 2921 deletions
diff --git a/configure.ac b/configure.ac
index 14ecba3d..8c6c4a83 100644
--- a/configure.ac
+++ b/configure.ac
@@ -125,14 +125,6 @@ AS_IF([test "x$enable_fs_app" != "xno"], [
125]) 125])
126AC_SUBST(GNUNET_FS_APP) 126AC_SUBST(GNUNET_FS_APP)
127 127
128GNUNET_GNS_APP=""
129AC_ARG_ENABLE([gns-app],
130 AS_HELP_STRING([--disable-gns-app],[Do not build gnunet-gns-gtk application]))
131AS_IF([test "x$enable_gns_app" != "xno"], [
132 GNUNET_GNS_APP="gns"
133])
134AC_SUBST(GNUNET_GNS_APP)
135
136GNUNET_SETUP_APP="" 128GNUNET_SETUP_APP=""
137AC_ARG_ENABLE([setup-app], 129AC_ARG_ENABLE([setup-app],
138 AS_HELP_STRING([--disable-setup-app],[Do not build gnunet-setup application])) 130 AS_HELP_STRING([--disable-setup-app],[Do not build gnunet-setup application]))
@@ -495,7 +487,6 @@ src/Makefile
495src/include/Makefile 487src/include/Makefile
496src/lib/Makefile 488src/lib/Makefile
497src/fs/Makefile 489src/fs/Makefile
498src/gns/Makefile
499src/peerinfo/Makefile 490src/peerinfo/Makefile
500src/setup/Makefile 491src/setup/Makefile
501src/statistics/Makefile 492src/statistics/Makefile
diff --git a/contrib/gnunet_gns_gtk_about_window.glade b/contrib/gnunet_gns_gtk_about_window.glade
deleted file mode 100644
index fac0c6e9..00000000
--- a/contrib/gnunet_gns_gtk_about_window.glade
+++ /dev/null
@@ -1,340 +0,0 @@
1<?xml version="1.0"?>
2<interface>
3 <requires lib="gtk+" version="2.20"/>
4 <!-- interface-naming-policy project-wide -->
5 <object class="GtkWindow" id="about_window">
6 <property name="title" translatable="yes">gnunet-gns-gtk</property>
7 <property name="modal">True</property>
8 <property name="destroy_with_parent">True</property>
9 <signal name="realize" handler="GNUNET_GTK_about_window_realized"/>
10 <signal name="delete_event" handler="GNUNET_GTK_about_window_got_delete_event"/>
11 <child>
12 <object class="GtkVBox" id="about_main_vbox">
13 <property name="visible">True</property>
14 <property name="border_width">10</property>
15 <property name="orientation">vertical</property>
16 <child>
17 <object class="GtkImage" id="about_logo_image">
18 <property name="visible">True</property>
19 <property name="pixbuf">gnunet_logo.png</property>
20 </object>
21 <packing>
22 <property name="expand">False</property>
23 <property name="position">0</property>
24 </packing>
25 </child>
26 <child>
27 <object class="GtkLabel" id="about_name_version_label">
28 <property name="visible">True</property>
29 <property name="label">GNUnet-FS-GTK r20167</property>
30 <attributes>
31 <attribute name="weight" value="bold"/>
32 <attribute name="size" value="200"/>
33 </attributes>
34 </object>
35 <packing>
36 <property name="expand">False</property>
37 <property name="position">1</property>
38 </packing>
39 </child>
40 <child>
41 <object class="GtkLabel" id="about_copyright_label">
42 <property name="visible">True</property>
43 <property name="label">(C) 2010-2012 The GNUnet Project</property>
44 </object>
45 <packing>
46 <property name="expand">False</property>
47 <property name="position">2</property>
48 </packing>
49 </child>
50 <child>
51 <object class="GtkLabel" id="about_link_label">
52 <property name="visible">True</property>
53 <property name="label">&lt;a href="https://gnunet.org/"&gt;GNUnet: GNU's Framework for Secure P2P Networking&lt;/a&gt;</property>
54 <property name="use_markup">True</property>
55 <property name="wrap">True</property>
56 </object>
57 <packing>
58 <property name="expand">False</property>
59 <property name="position">3</property>
60 </packing>
61 </child>
62 <child>
63 <object class="GtkNotebook" id="about_credits_notebook">
64 <property name="can_focus">True</property>
65 <child>
66 <object class="GtkScrolledWindow" id="about_credits_authors_scroller">
67 <property name="visible">True</property>
68 <property name="can_focus">True</property>
69 <property name="hscrollbar_policy">automatic</property>
70 <property name="vscrollbar_policy">automatic</property>
71 <child>
72 <object class="GtkTextView" id="about_credits_authors_textview">
73 <property name="visible">True</property>
74 <property name="can_focus">True</property>
75 <property name="editable">False</property>
76 <property name="wrap_mode">word</property>
77 <property name="cursor_visible">False</property>
78 <property name="buffer">credits_authors_contents</property>
79 <property name="accepts_tab">False</property>
80 </object>
81 </child>
82 </object>
83 </child>
84 <child type="tab">
85 <object class="GtkLabel" id="about_credits_authors_tab">
86 <property name="visible">True</property>
87 <property name="label" translatable="yes">Developed by</property>
88 </object>
89 <packing>
90 <property name="tab_fill">False</property>
91 </packing>
92 </child>
93 <child>
94 <object class="GtkScrolledWindow" id="about_credits_docs_scroller">
95 <property name="visible">True</property>
96 <property name="can_focus">True</property>
97 <property name="hscrollbar_policy">automatic</property>
98 <property name="vscrollbar_policy">automatic</property>
99 <child>
100 <object class="GtkTextView" id="about_credits_docs_textview">
101 <property name="visible">True</property>
102 <property name="can_focus">True</property>
103 <property name="editable">False</property>
104 <property name="wrap_mode">word</property>
105 <property name="cursor_visible">False</property>
106 <property name="buffer">credits_docs_contents</property>
107 <property name="accepts_tab">False</property>
108 </object>
109 </child>
110 </object>
111 <packing>
112 <property name="position">1</property>
113 </packing>
114 </child>
115 <child type="tab">
116 <object class="GtkLabel" id="about_credits_docs_tab">
117 <property name="visible">True</property>
118 <property name="label" translatable="yes">Documented by</property>
119 </object>
120 <packing>
121 <property name="position">1</property>
122 <property name="tab_fill">False</property>
123 </packing>
124 </child>
125 <child>
126 <object class="GtkScrolledWindow" id="about_credits_trans_scroller">
127 <property name="visible">True</property>
128 <property name="can_focus">True</property>
129 <property name="hscrollbar_policy">automatic</property>
130 <property name="vscrollbar_policy">automatic</property>
131 <child>
132 <object class="GtkTextView" id="about_credits_trans_textview">
133 <property name="visible">True</property>
134 <property name="can_focus">True</property>
135 <property name="editable">False</property>
136 <property name="wrap_mode">word</property>
137 <property name="cursor_visible">False</property>
138 <property name="buffer">credits_trans_contents</property>
139 <property name="accepts_tab">False</property>
140 </object>
141 </child>
142 </object>
143 <packing>
144 <property name="position">2</property>
145 </packing>
146 </child>
147 <child type="tab">
148 <object class="GtkLabel" id="about_credits_trans_tab">
149 <property name="visible">True</property>
150 <property name="label" translatable="yes">Translated by</property>
151 </object>
152 <packing>
153 <property name="position">2</property>
154 <property name="tab_fill">False</property>
155 </packing>
156 </child>
157 <child>
158 <object class="GtkScrolledWindow" id="about_credits_art_scroller">
159 <property name="visible">True</property>
160 <property name="can_focus">True</property>
161 <property name="hscrollbar_policy">automatic</property>
162 <property name="vscrollbar_policy">automatic</property>
163 <child>
164 <object class="GtkTextView" id="about_credits_art_textview">
165 <property name="visible">True</property>
166 <property name="can_focus">True</property>
167 <property name="editable">False</property>
168 <property name="wrap_mode">word</property>
169 <property name="cursor_visible">False</property>
170 <property name="buffer">credits_art_contents</property>
171 <property name="accepts_tab">False</property>
172 </object>
173 </child>
174 </object>
175 <packing>
176 <property name="position">3</property>
177 </packing>
178 </child>
179 <child type="tab">
180 <object class="GtkLabel" id="about_credits_art_tab">
181 <property name="visible">True</property>
182 <property name="label" translatable="yes">Artwork by</property>
183 </object>
184 <packing>
185 <property name="position">3</property>
186 <property name="tab_fill">False</property>
187 </packing>
188 </child>
189 </object>
190 <packing>
191 <property name="position">4</property>
192 </packing>
193 </child>
194 <child>
195 <object class="GtkScrolledWindow" id="about_license_scroller">
196 <property name="can_focus">True</property>
197 <property name="hscrollbar_policy">never</property>
198 <property name="shadow_type">out</property>
199 <child>
200 <object class="GtkTextView" id="about_license_textview">
201 <property name="visible">True</property>
202 <property name="can_focus">True</property>
203 <property name="editable">False</property>
204 <property name="wrap_mode">word</property>
205 <property name="cursor_visible">False</property>
206 <property name="buffer">license_contents</property>
207 <property name="accepts_tab">False</property>
208 </object>
209 </child>
210 </object>
211 <packing>
212 <property name="position">5</property>
213 </packing>
214 </child>
215 <child>
216 <object class="GtkHBox" id="about_buttons_hbox">
217 <property name="visible">True</property>
218 <property name="border_width">5</property>
219 <property name="homogeneous">True</property>
220 <child>
221 <object class="GtkButton" id="about_credits_button">
222 <property name="label" translatable="yes">Credits</property>
223 <property name="visible">True</property>
224 <property name="can_focus">True</property>
225 <property name="receives_default">True</property>
226 <signal name="clicked" handler="GNUNET_GTK_about_credits_button_clicked"/>
227 </object>
228 <packing>
229 <property name="fill">False</property>
230 <property name="position">0</property>
231 </packing>
232 </child>
233 <child>
234 <object class="GtkButton" id="about_license_button">
235 <property name="label" translatable="yes">License</property>
236 <property name="visible">True</property>
237 <property name="can_focus">True</property>
238 <property name="receives_default">True</property>
239 <signal name="clicked" handler="GNUNET_GTK_about_license_button_clicked"/>
240 </object>
241 <packing>
242 <property name="fill">False</property>
243 <property name="position">1</property>
244 </packing>
245 </child>
246 <child>
247 <placeholder/>
248 </child>
249 <child>
250 <object class="GtkButton" id="about_close_button">
251 <property name="label">gtk-close</property>
252 <property name="visible">True</property>
253 <property name="can_focus">True</property>
254 <property name="receives_default">True</property>
255 <property name="use_stock">True</property>
256 <signal name="clicked" handler="GNUNET_GTK_about_close_button_clicked"/>
257 </object>
258 <packing>
259 <property name="fill">False</property>
260 <property name="pack_type">end</property>
261 <property name="position">2</property>
262 </packing>
263 </child>
264 </object>
265 <packing>
266 <property name="expand">False</property>
267 <property name="fill">False</property>
268 <property name="pack_type">end</property>
269 <property name="position">6</property>
270 </packing>
271 </child>
272 </object>
273 </child>
274 </object>
275 <object class="GtkTextBuffer" id="credits_art_contents">
276 <property name="text">Jakub 'jimmac' Steiner &lt;jimmac@ximian.org&gt;
277Christian Muellner &lt;chris@flop.de&gt;
278Alex Jones &lt;alexrjones@ntlworld.com&gt;
279Nicklas Larsson &lt;whybill@gmail.com&gt;
280</property>
281 </object>
282 <object class="GtkTextBuffer" id="credits_authors_contents">
283 <property name="text">Juergen Appel &lt;jappel@linux01.gwdg.de&gt;
284Krista Grothoff &lt;krista@grothoff.org&gt;
285James Blackwell &lt;jblack@linuxguru.net&gt;
286Ludovic Courtes &lt;ludo@chbouib.org&gt;
287Nils Durner &lt;durner@gnunet.org&gt;
288Renaldo Ferreira &lt;rf@cs.purdue.edu&gt;
289Christian Grothoff &lt;christian@grothoff.org&gt;
290Eric Haumant
291Tzvetan Horozov &lt;horozov@motorola.com&gt;
292Gerd Knorr &lt;kraxel@bytesex.org&gt;
293Werner Koch &lt;libgcrypt@g10code.com&gt;
294Uli Luckas &lt;luckas@musoft.de&gt;
295Blake Matheny
296Glenn McGrath
297Hendrik Pagenhardt &lt;Hendrik.Pagenhardt@gmx.net&gt;
298Ioana Patrascu &lt;ioanapatrascu@yahoo.com&gt;
299Marko Raeihae
300Paul Ruth &lt;ruth@cs.purdue.edu&gt;
301Risto Saarelma
302Antti Salonen
303Tiberius Stef &lt;tstef@cs.purdue.edu&gt;
304Tuomas Toivonen
305Tomi Tukiainen
306Kevin Vandersloot &lt;kfv101@psu.edu&gt;
307Simo Viitanen
308Larry Waldo
309Igor Wronsky &lt;iwronsky@users.sourceforge.net&gt;
310&lt;january@hushmail.com&gt;</property>
311 </object>
312 <object class="GtkTextBuffer" id="credits_docs_contents">
313 <property name="text">Christian Grothoff &lt;christian@grothoff.org&gt;
314Anders Carlsson &lt;andersca@gnu.org&gt;
315Nils Durner &lt;durner@gnunet.org&gt;
316Nicklas Larsson &lt;whybill@gmail.com&gt;
317Milan Bouchet-Valat &lt;nalimilan@club.fr&gt;
318Igor Wronsky &lt;iwronsky@users.sourceforge.net&gt;
319</property>
320 </object>
321 <object class="GtkTextBuffer" id="credits_trans_contents">
322 <property name="text">Di Ma
323Jens Palsberg &lt;palsberg@cs.ucla.edu&gt;
324Christian Grothoff &lt;christian@grothoff.org&gt;
325Nils Durner &lt;durner@gnunet.org&gt;
326Mathieu &lt;mollo@bghflt.org&gt;
327Eric Haumant
328milan@skoid.org
329Hiroshi Yamauchi &lt;yamauchi@cs.purdue.edu&gt;
330Adam Welc &lt;welc@cs.purdue.edu&gt;
331Bogdan Carbunar &lt;carbunar@cs.purdue.edu&gt;
332Steven Michael Murphy &lt;murf@e-tools.com&gt;
333Phan Vinh Thinh &lt;teppi82@gmail.com&gt;
334Daniel Nylander &lt;po@danielnylander.se&gt;
335</property>
336 </object>
337 <object class="GtkTextBuffer" id="license_contents">
338 <property name="text" translatable="yes">License should be loaded here at runtime from the license file (no need to copy the whole GPL in here...).</property>
339 </object>
340</interface>
diff --git a/contrib/gnunet_gns_gtk_main_window.glade b/contrib/gnunet_gns_gtk_main_window.glade
deleted file mode 100644
index 603c1f55..00000000
--- a/contrib/gnunet_gns_gtk_main_window.glade
+++ /dev/null
@@ -1,483 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<interface>
3 <requires lib="gtk+" version="2.20"/>
4 <!-- interface-naming-policy project-wide -->
5 <object class="GtkMenu" id="GNUNET_GNS_GTK_delete_popup_menu">
6 <property name="visible">True</property>
7 <property name="can_focus">False</property>
8 <child>
9 <object class="GtkMenuItem" id="GNUNET_GNS_GTK_delete_button">
10 <property name="use_action_appearance">False</property>
11 <property name="visible">True</property>
12 <property name="can_focus">False</property>
13 <property name="label" translatable="yes">Delete Record</property>
14 <signal name="activate" handler="GNUNET_GNS_GTK_delete_popup_menu_delete_cb" swapped="no"/>
15 </object>
16 </child>
17 <child>
18 <object class="GtkSeparatorMenuItem" id="GNUNET_GTK_delete_sep">
19 <property name="use_action_appearance">False</property>
20 <property name="visible">True</property>
21 <property name="can_focus">False</property>
22 </object>
23 </child>
24 <child>
25 <object class="GtkMenuItem" id="1d_exp">
26 <property name="use_action_appearance">False</property>
27 <property name="visible">True</property>
28 <property name="can_focus">False</property>
29 <property name="label" translatable="yes">Record expires in 1 day</property>
30 <property name="use_underline">True</property>
31 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb" swapped="no"/>
32 </object>
33 </child>
34 <child>
35 <object class="GtkMenuItem" id="1w_exp">
36 <property name="use_action_appearance">False</property>
37 <property name="visible">True</property>
38 <property name="can_focus">False</property>
39 <property name="label" translatable="yes">Record expires in 1 week</property>
40 <property name="use_underline">True</property>
41 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1w_cb" swapped="no"/>
42 </object>
43 </child>
44 <child>
45 <object class="GtkMenuItem" id="1y_exp">
46 <property name="use_action_appearance">False</property>
47 <property name="visible">True</property>
48 <property name="can_focus">False</property>
49 <property name="label" translatable="yes">Record expires in 1 year</property>
50 <property name="use_underline">True</property>
51 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1y_cb" swapped="no"/>
52 </object>
53 </child>
54 <child>
55 <object class="GtkMenuItem" id="exp_inf">
56 <property name="use_action_appearance">False</property>
57 <property name="visible">True</property>
58 <property name="can_focus">False</property>
59 <property name="label" translatable="yes">Record never expires</property>
60 <property name="use_underline">True</property>
61 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_expinf_cb" swapped="no"/>
62 </object>
63 </child>
64 </object>
65 <object class="GtkTreeStore" id="GNUNET_GNS_GTK_treestore">
66 <columns>
67 <!-- column-name name -->
68 <column type="gchararray"/>
69 <!-- column-name is_public -->
70 <column type="gboolean"/>
71 <!-- column-name record_type -->
72 <column type="guint"/>
73 <!-- column-name record_type_as_string -->
74 <column type="gchararray"/>
75 <!-- column-name expiration_time -->
76 <column type="guint64"/>
77 <!-- column-name expiration_time_is_relative -->
78 <column type="gboolean"/>
79 <!-- column-name expiration_time_as_string -->
80 <column type="gchararray"/>
81 <!-- column-name value_as_string -->
82 <column type="gchararray"/>
83 <!-- column-name value_color -->
84 <column type="gchararray"/>
85 <!-- column-name name_is_editable -->
86 <column type="gboolean"/>
87 <!-- column-name name_is_row -->
88 <column type="gboolean"/>
89 <!-- column-name not_dummy_row -->
90 <column type="gboolean"/>
91 <!-- column-name expiration_time_as_color -->
92 <column type="gchararray"/>
93 <!-- column-name name_color -->
94 <column type="gchararray"/>
95 </columns>
96 </object>
97 <object class="GtkListStore" id="GNUNET_GNS_GTK_type_liststore">
98 <columns>
99 <!-- column-name type -->
100 <column type="guint"/>
101 <!-- column-name typename -->
102 <column type="gchararray"/>
103 </columns>
104 <data>
105 <row>
106 <col id="0">1</col>
107 <col id="1" translatable="yes">A</col>
108 </row>
109 <row>
110 <col id="0">2</col>
111 <col id="1" translatable="yes">NS</col>
112 </row>
113 <row>
114 <col id="0">5</col>
115 <col id="1" translatable="yes">CNAME</col>
116 </row>
117 <row>
118 <col id="0">6</col>
119 <col id="1" translatable="yes">SOA</col>
120 </row>
121 <row>
122 <col id="0">12</col>
123 <col id="1" translatable="yes">PTR</col>
124 </row>
125 <row>
126 <col id="0">15</col>
127 <col id="1" translatable="yes">MX</col>
128 </row>
129 <row>
130 <col id="0">16</col>
131 <col id="1" translatable="yes">TXT</col>
132 </row>
133 <row>
134 <col id="0">28</col>
135 <col id="1" translatable="yes">AAAA</col>
136 </row>
137 <row>
138 <col id="0">65536</col>
139 <col id="1" translatable="yes">PKEY</col>
140 </row>
141 <row>
142 <col id="0">65538</col>
143 <col id="1" translatable="yes">LEHO</col>
144 </row>
145 </data>
146 </object>
147 <object class="GtkWindow" id="GNUNET_GNS_GTK_main_window">
148 <property name="can_focus">False</property>
149 <property name="title" translatable="yes">gnunet-gns-gtk</property>
150 <property name="default_height">500</property>
151 <signal name="delete-event" handler="GNUNET_GNS_GTK_main_window_delete_event_cb" swapped="no"/>
152 <child>
153 <object class="GtkVBox" id="GNUNET_GNS_GTK_main_vbox">
154 <property name="visible">True</property>
155 <property name="can_focus">False</property>
156 <child>
157 <object class="GtkMenuBar" id="GNUNET_GNS_GTK_menubar">
158 <property name="visible">True</property>
159 <property name="can_focus">False</property>
160 <child>
161 <object class="GtkMenuItem" id="GNUNET_GNS_GTK_file_menuitem">
162 <property name="use_action_appearance">False</property>
163 <property name="visible">True</property>
164 <property name="can_focus">False</property>
165 <property name="label" translatable="yes">_File</property>
166 <property name="use_underline">True</property>
167 <child type="submenu">
168 <object class="GtkMenu" id="menu1">
169 <property name="visible">True</property>
170 <property name="can_focus">False</property>
171 <child>
172 <object class="GtkImageMenuItem" id="GNUNET_GNS_GTK_new_imagemenuitem">
173 <property name="label">gtk-new</property>
174 <property name="use_action_appearance">False</property>
175 <property name="visible">True</property>
176 <property name="can_focus">False</property>
177 <property name="use_underline">True</property>
178 <property name="use_stock">True</property>
179 <signal name="activate" handler="GNUNET_GNS_GTK_new_imagemenuitem_activate_cb" swapped="no"/>
180 </object>
181 </child>
182 <child>
183 <object class="GtkImageMenuItem" id="GNUNET_GNS_GTK_open_imagemenuitem">
184 <property name="label">gtk-open</property>
185 <property name="use_action_appearance">False</property>
186 <property name="visible">True</property>
187 <property name="can_focus">False</property>
188 <property name="use_underline">True</property>
189 <property name="use_stock">True</property>
190 <signal name="activate" handler="GNUNET_GNS_GTK_open_imagemenuitem_activate_cb" swapped="no"/>
191 </object>
192 </child>
193 <child>
194 <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
195 <property name="visible">True</property>
196 <property name="can_focus">False</property>
197 </object>
198 </child>
199 <child>
200 <object class="GtkImageMenuItem" id="GNUNET_GNS_GTK_quit_imagemenuitem">
201 <property name="label">gtk-quit</property>
202 <property name="use_action_appearance">False</property>
203 <property name="visible">True</property>
204 <property name="can_focus">False</property>
205 <property name="use_underline">True</property>
206 <property name="use_stock">True</property>
207 <signal name="activate" handler="GNUNET_GNS_GTK_quit_imagemenuitem_activate_cb" swapped="no"/>
208 </object>
209 </child>
210 </object>
211 </child>
212 </object>
213 </child>
214 <child>
215 <object class="GtkMenuItem" id="GNUNET_GNS_GTK_options_menuitem">
216 <property name="use_action_appearance">False</property>
217 <property name="visible">True</property>
218 <property name="can_focus">False</property>
219 <property name="label" translatable="yes">_Options</property>
220 <property name="use_underline">True</property>
221 <child type="submenu">
222 <object class="GtkMenu" id="menu2">
223 <property name="visible">True</property>
224 <property name="can_focus">False</property>
225 <child>
226 <object class="GtkCheckMenuItem" id="GNUNET_GNS_GTK_autoshort_imagemenuitem">
227 <property name="use_action_appearance">False</property>
228 <property name="visible">True</property>
229 <property name="can_focus">False</property>
230 <property name="label" translatable="yes">Automatically shorten names</property>
231 <property name="use_underline">True</property>
232 <signal name="toggled" handler="GNUNET_GNS_GTK_autoshort_imagemenuitem_toggled_cb" swapped="no"/>
233 </object>
234 </child>
235 </object>
236 </child>
237 </object>
238 </child>
239 <child>
240 <object class="GtkMenuItem" id="GNUNET_GNS_GTK_help_menuitem">
241 <property name="use_action_appearance">False</property>
242 <property name="visible">True</property>
243 <property name="can_focus">False</property>
244 <property name="label" translatable="yes">_Help</property>
245 <property name="use_underline">True</property>
246 <child type="submenu">
247 <object class="GtkMenu" id="menu3">
248 <property name="visible">True</property>
249 <property name="can_focus">False</property>
250 <child>
251 <object class="GtkImageMenuItem" id="GNUNET_GNS_GTK_about_imagemenuitem">
252 <property name="label">gtk-about</property>
253 <property name="use_action_appearance">False</property>
254 <property name="visible">True</property>
255 <property name="can_focus">False</property>
256 <property name="use_underline">True</property>
257 <property name="use_stock">True</property>
258 <signal name="activate" handler="GNUNET_GNS_GTK_about_imagemenuitem_activate_cb" swapped="no"/>
259 </object>
260 </child>
261 </object>
262 </child>
263 </object>
264 </child>
265 </object>
266 <packing>
267 <property name="expand">False</property>
268 <property name="fill">True</property>
269 <property name="position">0</property>
270 </packing>
271 </child>
272 <child>
273 <object class="GtkFrame" id="GNUNET_GNS_GTK_main_frame">
274 <property name="visible">True</property>
275 <property name="can_focus">False</property>
276 <property name="label_xalign">0</property>
277 <property name="shadow_type">none</property>
278 <child>
279 <object class="GtkAlignment" id="GNUNET_GNS_GTK_main_alignment">
280 <property name="visible">True</property>
281 <property name="can_focus">False</property>
282 <property name="left_padding">12</property>
283 <child>
284 <object class="GtkHBox" id="GNUNET_GNS_GTK_pseu_hbox">
285 <property name="visible">True</property>
286 <property name="can_focus">False</property>
287 <child>
288 <object class="GtkLabel" id="GNUNET_GNS_GTK_pseu_label">
289 <property name="visible">True</property>
290 <property name="can_focus">False</property>
291 <property name="label" translatable="yes">Preferred zone name (PSEU):</property>
292 </object>
293 <packing>
294 <property name="expand">False</property>
295 <property name="fill">False</property>
296 <property name="padding">5</property>
297 <property name="position">0</property>
298 </packing>
299 </child>
300 <child>
301 <object class="GtkEntry" id="GNUNET_GNS_GTK_pseu_entry">
302 <property name="visible">True</property>
303 <property name="can_focus">True</property>
304 <property name="tooltip_text" translatable="yes">Enter the preferred name for this zone here. The value will be stored in the PSEU record for your public key. This is the GNS equivalent of your domain name. You should try to pick a name that is globally unique.</property>
305 <property name="max_length">63</property>
306 <property name="invisible_char">●</property>
307 <property name="primary_icon_activatable">False</property>
308 <property name="secondary_icon_activatable">False</property>
309 <property name="primary_icon_sensitive">True</property>
310 <property name="secondary_icon_sensitive">True</property>
311 <signal name="changed" handler="GNUNET_GNS_GTK_pseu_entry_changed_cb" swapped="no"/>
312 </object>
313 <packing>
314 <property name="expand">True</property>
315 <property name="fill">True</property>
316 <property name="padding">5</property>
317 <property name="position">1</property>
318 </packing>
319 </child>
320 <child>
321 <object class="GtkButton" id="GNUNET_GNS_GTK_public_key_copy_button">
322 <property name="label">gtk-copy</property>
323 <property name="use_action_appearance">False</property>
324 <property name="visible">True</property>
325 <property name="can_focus">True</property>
326 <property name="receives_default">True</property>
327 <property name="tooltip_text" translatable="yes">Copy the public key of this zone to the clipboard.</property>
328 <property name="use_stock">True</property>
329 <signal name="clicked" handler="GNUNET_GNS_GTK_public_key_copy_button_clicked_cb" swapped="no"/>
330 </object>
331 <packing>
332 <property name="expand">False</property>
333 <property name="fill">False</property>
334 <property name="padding">20</property>
335 <property name="position">2</property>
336 </packing>
337 </child>
338 </object>
339 </child>
340 </object>
341 </child>
342 <child type="label">
343 <object class="GtkLabel" id="GNUNET_GNS_GTK_zone_label">
344 <property name="visible">True</property>
345 <property name="can_focus">False</property>
346 <property name="label" translatable="yes">&lt;b&gt;SET TO PUBLIC KEY OF THE ZONE&lt;/b&gt;</property>
347 <property name="use_markup">True</property>
348 </object>
349 </child>
350 </object>
351 <packing>
352 <property name="expand">False</property>
353 <property name="fill">False</property>
354 <property name="padding">5</property>
355 <property name="position">1</property>
356 </packing>
357 </child>
358 <child>
359 <object class="GtkScrolledWindow" id="GNUNET_GNS_GTK_main_scrolledwindow">
360 <property name="visible">True</property>
361 <property name="can_focus">True</property>
362 <property name="hscrollbar_policy">automatic</property>
363 <property name="vscrollbar_policy">automatic</property>
364 <child>
365 <object class="GtkTreeView" id="GNUNET_GNS_GTK_main_treeview">
366 <property name="visible">True</property>
367 <property name="can_focus">True</property>
368 <property name="model">GNUNET_GNS_GTK_treestore</property>
369 <signal name="button-press-event" handler="GNUNET_GNS_GTK_main_treeview_button_press_popup_menu_cb" swapped="no"/>
370 <signal name="key-press-event" handler="GNUNET_GNS_GTK_main_treeview_key_press_popup_menu_cb" after="yes" swapped="no"/>
371 <signal name="realize" handler="GNUNET_GNS_GTK_main_treeview_realize_cb" swapped="no"/>
372 <signal name="popup-menu" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_cb" swapped="no"/>
373 <child>
374 <object class="GtkTreeViewColumn" id="GNUNET_GNS_GTK_name_treeviewcolumn">
375 <property name="title">Name</property>
376 <property name="clickable">True</property>
377 <property name="reorderable">True</property>
378 <property name="sort_indicator">True</property>
379 <property name="sort_column_id">0</property>
380 <child>
381 <object class="GtkCellRendererText" id="GNUNET_GNS_GTK_name_cellrenderertext">
382 <signal name="edited" handler="GNUNET_GNS_GTK_name_cellrenderertext_edited_cb" swapped="no"/>
383 </object>
384 <attributes>
385 <attribute name="visible">9</attribute>
386 <attribute name="background">13</attribute>
387 <attribute name="editable">9</attribute>
388 <attribute name="text">0</attribute>
389 </attributes>
390 </child>
391 </object>
392 </child>
393 <child>
394 <object class="GtkTreeViewColumn" id="GNUNET_GNS_GTK_ispublic_treeviewcolumn">
395 <property name="sizing">fixed</property>
396 <property name="fixed_width">50</property>
397 <property name="title">Public</property>
398 <property name="clickable">True</property>
399 <child>
400 <object class="GtkCellRendererToggle" id="GNUNET_GNS_GTK_ispublic_cellrenderertoggle">
401 <signal name="toggled" handler="GNUNET_GNS_GTK_ispublic_cellrenderertoggle_toggled_cb" swapped="no"/>
402 </object>
403 <attributes>
404 <attribute name="visible">10</attribute>
405 <attribute name="active">1</attribute>
406 </attributes>
407 </child>
408 </object>
409 </child>
410 <child>
411 <object class="GtkTreeViewColumn" id="GNUNET_GNS_GTK_type_treeviewcolumn">
412 <property name="sizing">autosize</property>
413 <property name="fixed_width">90</property>
414 <property name="title">Type</property>
415 <property name="clickable">True</property>
416 <property name="reorderable">True</property>
417 <property name="sort_indicator">True</property>
418 <property name="sort_column_id">3</property>
419 <child>
420 <object class="GtkCellRendererCombo" id="GNUNET_GNS_GTK_type_cellrenderercombo">
421 <property name="editable">True</property>
422 <property name="model">GNUNET_GNS_GTK_type_liststore</property>
423 <property name="text_column">1</property>
424 <signal name="changed" handler="GNUNET_GNS_GTK_type_cellrenderercombo_changed_cb" swapped="no"/>
425 </object>
426 <attributes>
427 <attribute name="visible">11</attribute>
428 <attribute name="text">3</attribute>
429 </attributes>
430 </child>
431 </object>
432 </child>
433 <child>
434 <object class="GtkTreeViewColumn" id="GNUNET_GNS_GTK_expiration_treeviewcolumn">
435 <property name="title">Expiration</property>
436 <property name="reorderable">True</property>
437 <property name="sort_indicator">True</property>
438 <property name="sort_column_id">4</property>
439 <child>
440 <object class="GtkCellRendererText" id="GNUNET_GNS_GTK_expiration_cellrenderertext">
441 <property name="editable">True</property>
442 <signal name="edited" handler="GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb" swapped="no"/>
443 </object>
444 <attributes>
445 <attribute name="visible">10</attribute>
446 <attribute name="background">12</attribute>
447 <attribute name="text">6</attribute>
448 </attributes>
449 </child>
450 </object>
451 </child>
452 <child>
453 <object class="GtkTreeViewColumn" id="GNUNET_GNS_GTK_value_treeviewcolumn">
454 <property name="sizing">autosize</property>
455 <property name="title">Value</property>
456 <property name="expand">True</property>
457 <property name="sort_column_id">7</property>
458 <child>
459 <object class="GtkCellRendererText" id="GNUNET_GNS_GTK_value_cellrenderertext">
460 <property name="editable">True</property>
461 <signal name="edited" handler="GNUNET_GNS_GTK_value_cellrenderertext_edited_cb" swapped="no"/>
462 </object>
463 <attributes>
464 <attribute name="visible">10</attribute>
465 <attribute name="background">8</attribute>
466 <attribute name="text">7</attribute>
467 </attributes>
468 </child>
469 </object>
470 </child>
471 </object>
472 </child>
473 </object>
474 <packing>
475 <property name="expand">True</property>
476 <property name="fill">True</property>
477 <property name="position">2</property>
478 </packing>
479 </child>
480 </object>
481 </child>
482 </object>
483</interface>
diff --git a/contrib/gnunet_gns_gtk_zone_open.glade b/contrib/gnunet_gns_gtk_zone_open.glade
deleted file mode 100644
index 2d6916b6..00000000
--- a/contrib/gnunet_gns_gtk_zone_open.glade
+++ /dev/null
@@ -1,72 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<interface>
3 <!-- interface-requires gtk+ 3.0 -->
4 <object class="GtkFileFilter" id="GNUNET_GNS_GTK_zone_open_filefilter">
5 </object>
6 <object class="GtkFileChooserDialog" id="GNUNET_GNS_GTK_zone_open_filechooserdialog">
7 <property name="can_focus">False</property>
8 <property name="border_width">5</property>
9 <property name="title" translatable="yes">Open zone file...</property>
10 <property name="type_hint">dialog</property>
11 <property name="filter">GNUNET_GNS_GTK_zone_open_filefilter</property>
12 <signal name="response" handler="GNUNET_GNS_GTK_zone_open_dialog_response_cb" swapped="no"/>
13 <child internal-child="vbox">
14 <object class="GtkBox" id="GNUNET_GNS_GTK_zone_open_filechooserdialog-vbox">
15 <property name="can_focus">False</property>
16 <property name="orientation">vertical</property>
17 <property name="spacing">2</property>
18 <child internal-child="action_area">
19 <object class="GtkButtonBox" id="GNUNET_GNS_GTK_zone_open_filechooserdialog-action_area">
20 <property name="can_focus">False</property>
21 <property name="layout_style">end</property>
22 <child>
23 <object class="GtkButton" id="GNUNET_GNS_GTK_zone_open_cancel_button">
24 <property name="label">gtk-cancel</property>
25 <property name="use_action_appearance">False</property>
26 <property name="visible">True</property>
27 <property name="can_focus">True</property>
28 <property name="receives_default">True</property>
29 <property name="use_action_appearance">False</property>
30 <property name="use_stock">True</property>
31 </object>
32 <packing>
33 <property name="expand">False</property>
34 <property name="fill">True</property>
35 <property name="position">0</property>
36 </packing>
37 </child>
38 <child>
39 <object class="GtkButton" id="GNUNET_GNS_GTK_zone_open_ok_button">
40 <property name="label">gtk-ok</property>
41 <property name="use_action_appearance">False</property>
42 <property name="visible">True</property>
43 <property name="can_focus">True</property>
44 <property name="receives_default">True</property>
45 <property name="use_action_appearance">False</property>
46 <property name="use_stock">True</property>
47 </object>
48 <packing>
49 <property name="expand">False</property>
50 <property name="fill">True</property>
51 <property name="position">1</property>
52 </packing>
53 </child>
54 </object>
55 <packing>
56 <property name="expand">False</property>
57 <property name="fill">True</property>
58 <property name="pack_type">end</property>
59 <property name="position">0</property>
60 </packing>
61 </child>
62 <child>
63 <placeholder/>
64 </child>
65 </object>
66 </child>
67 <action-widgets>
68 <action-widget response="-6">GNUNET_GNS_GTK_zone_open_cancel_button</action-widget>
69 <action-widget response="-5">GNUNET_GNS_GTK_zone_open_ok_button</action-widget>
70 </action-widgets>
71 </object>
72</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 749665ca..d0768e0f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1 +1 @@
SUBDIRS = . include lib $(GNUNET_FS_APP) $(GNUNET_GNS_APP) $(GNUNET_SETUP_APP) $(GNUNET_PEERINFO_APP) statistics SUBDIRS = . include lib $(GNUNET_FS_APP) $(GNUNET_SETUP_APP) $(GNUNET_PEERINFO_APP) statistics
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
deleted file mode 100644
index 35ae86ec..00000000
--- a/src/gns/Makefile.am
+++ /dev/null
@@ -1,23 +0,0 @@
1SUBDIRS = .
2
3INCLUDES = \
4 -I$(top_srcdir)/ \
5 -I$(top_srcdir)/src/include \
6 @GTK_CFLAGS@ \
7 @GNUNET_CFLAGS@ \
8 @GLADE_CFLAGS@
9
10bin_PROGRAMS = gnunet-gns-gtk
11
12gnunet_gns_gtk_SOURCES = \
13 gnunet-gns-gtk.c gnunet-gns-gtk.h \
14 gnunet-gns-gtk_about.c \
15 gnunet-gns-gtk_zone.c
16gnunet_gns_gtk_LDADD = \
17 $(top_builddir)/src/lib/libgnunetgtk.la \
18 @GTK_LIBS@ \
19 @GLADE_LIBS@ @GNUNET_LIBS@ \
20 -lgnunetutil -lgnunetnamestore \
21 $(INTLLIBS)
22gnunet_gns_gtk_LDFLAGS = \
23 -export-dynamic
diff --git a/src/gns/gnunet-gns-gtk.c b/src/gns/gnunet-gns-gtk.c
deleted file mode 100644
index 229e4b38..00000000
--- a/src/gns/gnunet-gns-gtk.c
+++ /dev/null
@@ -1,616 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 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/gns/gnunet-gns-gtk.c
23 * @brief Main function of gnunet-gns-gtk
24 * @author Christian Grothoff
25 */
26#include "gnunet_gtk.h"
27#include "gnunet-gns-gtk.h"
28#include <gnunet/gnunet_namestore_service.h>
29
30
31/**
32 * Columns in the gns model.
33 */
34enum GNS_ModelColumns
35 {
36 /**
37 * A gchararray
38 */
39 GNS_MC_NAME = 0,
40
41 /**
42 * A gboolean
43 */
44 GNS_MC_IS_PUBLIC = 1,
45
46 /**
47 * A guint
48 */
49 GNS_MC_RECORD_TYPE = 2,
50
51 /**
52 * A gchararray
53 */
54 GNS_MC_RECORD_TYPE_AS_STRING = 3,
55
56 /**
57 * A guint64
58 */
59 GNS_MC_EXPIRATION_TIME = 4,
60
61 /**
62 * A gboolean
63 */
64 GNS_MC_EXPIRATION_TIME_IS_RELATIVE = 5,
65
66 /**
67 * A gchararray
68 */
69 GNS_MC_EXPIRATION_TIME_AS_STRING = 6,
70
71 /**
72 * A gchararray
73 */
74 GNS_MC_VALUE_AS_STRING = 7,
75
76 /**
77 * A gchararray
78 */
79 GNS_MC_VALUE_COLOR = 8,
80 };
81
82
83/**
84 * Columns in the gns type model.
85 */
86enum GNS_TypeModelColumns
87 {
88 /**
89 * A guint
90 */
91 GNS_TYPE_MC_TYPE = 0,
92
93 /**
94 * A gchararray
95 */
96 GNS_TYPE_MC_TYPENAME = 1,
97 };
98
99
100/**
101 * Handle to our main loop.
102 */
103static struct GNUNET_GTK_MainLoop *ml;
104
105/**
106 * Should gnunet-gns-gtk start in tray mode?
107 */
108static int tray_only;
109
110
111/**
112 * Name of our zone as a string.
113 */
114static char *zone_as_string;
115
116/**
117 * Default directory of zone files as a string.
118 */
119static char *zonekey_directory;
120
121/**
122 * Get cfg.
123 */
124static const struct GNUNET_CONFIGURATION_Handle *
125get_configuration ()
126{
127 return GNUNET_GTK_main_loop_get_configuration (ml);
128}
129
130
131/**
132 * Get an object from the main window.
133 *
134 * @param name name of the object
135 * @return NULL on error
136 */
137static GObject *
138get_object (const char *name)
139{
140 return GNUNET_GTK_main_loop_get_object (ml, name);
141}
142
143
144static void
145pseu_change_cont (void *cls,
146 int32_t success,
147 const char *emsg)
148{
149 struct GNUNET_GNS_Context *gns = cls;
150 GtkWidget *dialog;
151 if (GNUNET_SYSERR == success)
152 {
153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("New Pseudonym could not be set: `%s'\n"), emsg);
154 dialog = gtk_message_dialog_new (GTK_WINDOW (gns->main_window),
155 GTK_DIALOG_DESTROY_WITH_PARENT,
156 GTK_MESSAGE_ERROR,
157 GTK_BUTTONS_CLOSE,
158 _("New Pseudonym could not be set: `%s'\n"),
159 emsg);
160 g_signal_connect_swapped (dialog, "response",
161 G_CALLBACK (gtk_widget_destroy),
162 dialog);
163 gtk_widget_show_all (dialog);
164 }
165}
166
167
168/**
169 * Task run on shutdown.
170 *
171 * @param cls unused
172 * @param tc scheduler context, unused
173 */
174static void
175shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
176{
177
178 struct GNUNET_GNS_Context *gns = cls;
179 if (NULL == gns)
180 return;
181 if (NULL != gns->ns)
182 {
183 GNUNET_NAMESTORE_disconnect (gns->ns);
184 gns->ns = NULL;
185 }
186 if (NULL != gns->pkey)
187 {
188 GNUNET_CRYPTO_rsa_key_free (gns->pkey);
189 gns->pkey = NULL;
190 }
191 if (NULL != zonekey_directory)
192 {
193 GNUNET_free (zonekey_directory);
194 zonekey_directory = NULL;
195 }
196 GNUNET_free (gns);
197}
198
199
200void
201GNUNET_GNS_GTK_shutdown (struct GNUNET_GNS_Context *gns)
202{
203 GNUNET_GTK_tray_icon_destroy ();
204 GNUNET_GTK_main_loop_quit (ml);
205 GNUNET_SCHEDULER_add_now (&shutdown_task, gns);
206}
207
208
209gboolean
210GNUNET_GNS_GTK_pseu_entry_enter_cb (GtkWidget *widget,
211 GdkEvent *event,
212 gpointer user_data)
213{
214 const gchar * pseu;
215
216 pseu = gtk_entry_get_text (GTK_ENTRY(widget));
217
218 if ((pseu == NULL) || (0 == strcmp (pseu, "")))
219 {
220 //gtk_entry_set_text (GTK_ENTRY(widget), PSEU_EMPTY_STR);
221 }
222 return FALSE;
223}
224
225
226/**
227 * The user edited the preferred name (PSEU) of this namespace.
228 * Push the update to the namestore.
229 *
230 * @param editable the edited widget
231 * @param user_data unused
232 */
233void
234GNUNET_GNS_GTK_pseu_entry_changed_cb (GtkEditable *editable,
235 gpointer user_data)
236{
237 struct GNUNET_GNS_Context *gns = user_data;
238 struct GNUNET_NAMESTORE_RecordData rd;
239 const gchar * pseu;
240
241 pseu = gtk_entry_get_text (GTK_ENTRY(editable));
242 if ((pseu != NULL) && (0 != strcmp (pseu, PSEU_EMPTY_STR)) && (0 != strcmp ("", pseu)) && (GNUNET_NO == gns->iteration))
243 {
244
245 rd.record_type = GNUNET_NAMESTORE_TYPE_PSEU;
246 rd.expiration_time = UINT64_MAX;
247 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
248 rd.data_size = strlen (pseu) + 1;
249 rd.data = strdup (pseu);
250 GNUNET_NAMESTORE_record_create(gns->ns, gns->pkey, "+", &rd, pseu_change_cont, gns);
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New Pseudonym is `%s' %u\n", (char *) rd.data, rd.data_size);
252 }
253 else if ((0 != strcmp (pseu, PSEU_EMPTY_STR)) && ((pseu == NULL) || (0 == strcmp ("", pseu))))
254 {
255 gtk_entry_set_text (GTK_ENTRY(editable), PSEU_EMPTY_STR);
256 }
257
258}
259
260/**
261 * The user toggled the 'autoshort' option. Update the configuration.
262 *
263 * @param checkmenuitem the menu item
264 * @param user_data unused
265 */
266void
267GNUNET_GNS_GTK_autoshort_imagemenuitem_toggled_cb (GtkCheckMenuItem *checkmenuitem,
268 gpointer user_data)
269{
270 struct GNUNET_GNS_Context *gns = user_data;
271 GtkWidget *dialog;
272 struct GNUNET_CONFIGURATION_Handle *cfg = (struct GNUNET_CONFIGURATION_Handle *) get_configuration();
273
274 gboolean state = gtk_check_menu_item_get_active (gns->shorten_menu);
275 if (TRUE == state)
276 GNUNET_CONFIGURATION_set_value_string(cfg,"gns", "AUTO_IMPORT_PKEY","YES");
277 else
278 GNUNET_CONFIGURATION_set_value_string(cfg,"gns", "AUTO_IMPORT_PKEY","NO");
279
280 char * cfgfile = strdup (GNUNET_GTK_main_loop_get_configuration_file(ml));
281 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write(cfg, cfgfile))
282 {
283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Changes to autoshorten could not be written to configuration file: `%s'\n"), cfgfile);
284 dialog = gtk_message_dialog_new (GTK_WINDOW (gns->main_window),
285 GTK_DIALOG_DESTROY_WITH_PARENT,
286 GTK_MESSAGE_ERROR,
287 GTK_BUTTONS_CLOSE,
288 _("Changes to autoshorten option could not be written to configuration file: `%s'\n"),
289 cfgfile);
290 g_signal_connect_swapped (dialog, "response",
291 G_CALLBACK (gtk_widget_destroy),
292 dialog);
293 gtk_widget_show_all (dialog);
294 }
295 GNUNET_free (cfgfile);
296}
297
298
299/**
300 * The user selected 'NEW' in the menu. Open a dialog to enter a filename
301 * to create a new zone (for editing).
302 *
303 * @param checkmenuitem the menu item
304 * @param user_data unused
305 */
306void
307GNUNET_GNS_GTK_new_imagemenuitem_activate_cb (GtkMenuItem *menuitem,
308 gpointer user_data)
309{
310 GNUNET_break (0); // FIXME, not implemented
311}
312
313
314/**
315 * Function called from the open-directory dialog upon completion.
316 *
317 * @param dialog the pseudonym selection dialog
318 * @param response_id response code from the dialog
319 * @param user_data the builder of the dialog
320 */
321void
322GNUNET_GNS_GTK_zone_open_dialog_response_cb (GtkDialog * dialog,
323 gint response_id,
324 gpointer user_data)
325{
326 char *filename;
327
328 if (GTK_RESPONSE_OK != response_id)
329 {
330 gtk_widget_destroy (GTK_WIDGET (dialog));
331 g_object_unref (G_OBJECT (dialog));
332 return;
333 }
334 filename = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (dialog));
335 gtk_widget_destroy (GTK_WIDGET (dialog));
336 g_object_unref (G_OBJECT (dialog));
337
338 /* FIXME: move to new zone 'filename' */
339 fprintf (stderr, "Got zone `%s'\n", filename);
340 GNUNET_free (filename);
341}
342
343
344/**
345 * The user selected 'OPEN' in the menu. Open a dialog to select
346 * a different zonefile (for editing).
347 *
348 * @param checkmenuitem the menu item
349 * @param user_data unused
350 */
351void
352GNUNET_GNS_GTK_open_imagemenuitem_activate_cb (GtkMenuItem *menuitem,
353 gpointer user_data)
354{
355 GtkWidget *ad;
356 GtkBuilder *builder;
357 GtkWidget *toplevel;
358 GtkFileFilter *ff;
359 GtkFileChooser *fc;
360
361 builder =
362 GNUNET_GTK_get_new_builder ("gnunet_gns_gtk_zone_open.glade", NULL);
363 if (NULL == builder)
364 {
365 GNUNET_break (0);
366 return;
367 }
368 /* This file filter could be set with glade if we use gtk3
369 * With gtk2 we have to set it manually */
370 ff = GTK_FILE_FILTER (gtk_builder_get_object
371 (builder, "GNUNET_GNS_GTK_zone_open_filefilter"));
372 gtk_file_filter_add_pattern (ff, "*.zkey");
373
374 ad = GTK_WIDGET (gtk_builder_get_object
375 (builder, "GNUNET_GNS_GTK_zone_open_filechooserdialog"));
376
377 if (GTK_IS_FILE_CHOOSER(ad))
378 {
379 fc = GTK_FILE_CHOOSER(ad);
380 if (NULL != fc)
381 gtk_file_chooser_set_current_folder(fc, zonekey_directory);
382 }
383
384 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menuitem));
385 if (GTK_IS_WINDOW (toplevel))
386 gtk_window_set_transient_for (GTK_WINDOW (ad), GTK_WINDOW (toplevel));
387 gtk_window_present (GTK_WINDOW (ad));
388}
389
390
391/**
392 * The user clicked on the 'copy' button. Copy the full string
393 * with the hash of our public key to the clipboard.
394 *
395 * @param button the button that was clicked
396 * @param user_data unused
397 */
398void
399GNUNET_GNS_GTK_public_key_copy_button_clicked_cb (GtkButton *button,
400 gpointer user_data)
401{
402 GtkClipboard *cb;
403
404 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
405 gtk_clipboard_set_text (cb, zone_as_string, -1);
406}
407
408
409
410/**
411 * Callback invoked if the application is supposed to exit (via menu).
412 *
413 * @param menuitem the quit menu
414 * @param user_data unused
415 */
416void
417GNUNET_GNS_GTK_quit_imagemenuitem_activate_cb (GtkMenuItem *menuitem,
418 gpointer user_data)
419{
420 GNUNET_GTK_tray_icon_destroy ();
421 GNUNET_GTK_main_loop_quit (ml);
422 GNUNET_SCHEDULER_add_now (&shutdown_task, user_data);
423}
424
425
426/**
427 * Callback invoked if the application is supposed to exit (via window-close).
428 *
429 * @param widget the main window
430 * @param event deletion event
431 * @param user_data unused
432 */
433void
434GNUNET_GNS_GTK_main_window_delete_event_cb (GtkWidget *widget,
435 GdkEvent *event,
436 gpointer user_data)
437{
438 GNUNET_GTK_tray_icon_destroy ();
439 GNUNET_GTK_main_loop_quit (ml);
440 GNUNET_SCHEDULER_add_now (&shutdown_task, user_data);
441}
442
443
444static void
445close_error_box (GtkDialog *dialog,
446 gint response_id,
447 gpointer user_data)
448{
449 gtk_widget_destroy (GTK_WIDGET(dialog));
450 GNUNET_GNS_GTK_shutdown (user_data);
451}
452
453static void
454namestore_service_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
455{
456 struct GNUNET_GNS_Context *gns = NULL;
457 struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
458 GtkWidget *dialog;
459 char *label;
460 char *keyfile;
461 char *servicehome;
462
463 gns = GNUNET_malloc (sizeof (struct GNUNET_GNS_Context));
464
465 if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
466 {
467 char * message = _("Namestore service is not running!\n");
468 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, message);
469 dialog = gtk_message_dialog_new (GTK_WINDOW (gns->main_window),
470 GTK_DIALOG_DESTROY_WITH_PARENT,
471 GTK_MESSAGE_ERROR,
472 GTK_BUTTONS_CLOSE,
473 "%s",
474 message);
475
476 g_signal_connect (dialog, "response", G_CALLBACK(close_error_box), gns);
477 gtk_widget_show_all (dialog);
478 return;
479 }
480
481 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (get_configuration (),
482 "PATHS",
483 "SERVICEHOME",
484 &servicehome))
485 {
486 GNUNET_asprintf(&zonekey_directory, "");
487 }
488 else
489 {
490 GNUNET_asprintf(&zonekey_directory, "%s%s%s",servicehome, DIR_SEPARATOR_STR, "gns");
491 GNUNET_free (servicehome);
492 }
493
494 /* setup crypto keys */
495 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (get_configuration (),
496 "gns",
497 "ZONEKEY",
498 &keyfile))
499 {
500 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
501 _("Option `%s' missing in section `%s'\n"), "ZONEKEY", "gns");
502 return;
503 }
504 else
505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using `%s'\n", keyfile);
506 gns->pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
507 GNUNET_free (keyfile);
508 keyfile = NULL;
509 if (NULL == gns->pkey)
510 {
511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
512 _("Failed to read or create private zone key\n"));
513 return;
514 }
515 GNUNET_CRYPTO_rsa_key_get_public (gns->pkey, &gns->pubkey);
516 GNUNET_CRYPTO_short_hash (&gns->pubkey,
517 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
518 &gns->zone);
519 GNUNET_CRYPTO_short_hash_to_enc(&gns->zone, &shenc);
520
521 /* connect to namestore */
522 gns->ns = GNUNET_NAMESTORE_connect (get_configuration ());
523 if (NULL == gns->ns)
524 {
525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
526 _("Failed to connect to namestore\n"));
527 GNUNET_SCHEDULER_add_now (&shutdown_task, gns);
528 return;
529 }
530
531 /* setup gui */
532 if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, gns))
533 {
534 GNUNET_break (0);
535 GNUNET_SCHEDULER_add_now (&shutdown_task, gns);
536 return;
537 }
538 gns->builder = GNUNET_GTK_main_loop_get_builder(ml);
539 gns->main_window = GTK_WIDGET (get_object ("GNUNET_GNS_GTK_main_window"));
540 gns->ts = GTK_TREE_STORE (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_treestore"));
541 gns->ls = GTK_LIST_STORE (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_type_liststore"));
542 gns->tv = GTK_TREE_VIEW (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_main_treeview"));
543 gns->tm = GTK_TREE_MODEL(gns->ts);
544 gns->shorten_menu = GTK_CHECK_MENU_ITEM(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_autoshort_imagemenuitem"));
545 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (get_configuration (),
546 "gns",
547 "AUTO_IMPORT_PKEY"))
548 gtk_check_menu_item_set_active (gns->shorten_menu, TRUE);
549 else
550 gtk_check_menu_item_set_active (gns->shorten_menu, FALSE);
551
552 /* TODO: implements menus */
553 gtk_widget_set_visible (GTK_WIDGET (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_new_imagemenuitem")), FALSE);
554 gtk_widget_set_visible (GTK_WIDGET (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_open_imagemenuitem")), FALSE);
555
556 zone_as_string = GNUNET_strdup ((char *) &shenc);
557 label = g_markup_printf_escaped (_("<b>Editing zone %s</b>"),
558 zone_as_string);
559 gtk_label_set_markup (GTK_LABEL (get_object ("GNUNET_GNS_GTK_zone_label")),
560 label);
561 g_free (label);
562
563 GNUNET_GTK_set_icon_search_path ();
564 GNUNET_GTK_setup_nls ();
565 /* setup main window */
566 GNUNET_GTK_tray_icon_create (GTK_WINDOW (gns->main_window),
567 "gnunet-gtk" /* FIXME: different icon? */ ,
568 "gnunet-gns-gtk");
569
570 /* make GUI visible */
571 if (!tray_only)
572 {
573 gtk_widget_show (gns->main_window);
574 gtk_window_present (GTK_WINDOW (gns->main_window));
575 }
576}
577
578
579/**
580 * Actual main function run right after GNUnet's scheduler
581 * is initialized. Initializes up GTK and Glade.
582 *
583 * @param cls the 'struct GNUNET_GTK_MainLoop'
584 * @param tc scheduler context
585 */
586static void
587run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
588{
589 ml = cls;
590 GNUNET_CLIENT_service_test("namestore", get_configuration(), GNUNET_TIME_UNIT_SECONDS, &namestore_service_check, NULL);
591}
592
593
594int
595main (int argc, char *const *argv)
596{
597 static struct GNUNET_GETOPT_CommandLineOption options[] = {
598 {'t', "tray", NULL,
599 gettext_noop ("start in tray mode"), 0,
600 &GNUNET_GETOPT_set_one, &tray_only},
601
602 GNUNET_GETOPT_OPTION_END
603 };
604
605 if (GNUNET_OK !=
606 GNUNET_GTK_main_loop_start ("gnunet-gns-gtk",
607 "GTK GUI for editing our zone", argc,
608 argv, options,
609 "gnunet_gns_gtk_main_window.glade",
610 &run))
611 return 1;
612 return 0;
613}
614
615
616/* end of gnunet-gns-gtk.c */
diff --git a/src/gns/gnunet-gns-gtk.h b/src/gns/gnunet-gns-gtk.h
deleted file mode 100644
index b0330aef..00000000
--- a/src/gns/gnunet-gns-gtk.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 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/gns/gnunet-gns-gtk.h
23 * @brief Main function header of gnunet-gns-gtk
24 * @author Christian Grothoff
25 */
26#include "gnunet_gtk.h"
27#include <gnunet/gnunet_namestore_service.h>
28
29#define NEW_NAME_STR "<new name>"
30#define NEW_RECORD_STR "<new record>"
31#define ROOT_STR "+"
32#define EXPIRE_NEVER_STRING "never"
33#define EXPIRE_INVALID_STRING "invalid"
34#define PSEU_EMPTY_STR "<empty>"
35
36
37struct GNUNET_GNS_Context
38{
39 /**
40 * Handle to the namestore.
41 */
42 struct GNUNET_NAMESTORE_Handle *ns;
43
44 GtkCheckMenuItem *shorten_menu;
45
46 GtkBuilder *builder;
47
48 GtkWidget *main_window;
49
50 GtkTreeStore *ts;
51 GtkListStore *ls;
52 GtkTreeModel *tm;
53 GtkTreeView *tv;
54
55 struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
56 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
57
58 struct GNUNET_CRYPTO_ShortHashCode zone;
59 int iteration;
60};
61
62
63
64
65
66
67/* end of gnunet-gns-gtk.h */
diff --git a/src/gns/gnunet-gns-gtk_about.c b/src/gns/gnunet-gns-gtk_about.c
deleted file mode 100644
index 378eb86f..00000000
--- a/src/gns/gnunet-gns-gtk_about.c
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 This file is part of GNUnet
3 (C) 2005, 2006, 2010 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/gns/gnunet-gns-gtk_about.c
23 * @author Christian Grothoff
24 * @author Igor Wronsky
25 *
26 * This file contains the about dialog.
27 */
28#include "gnunet_gtk.h"
29
30
31/**
32 * This displays an about window
33 */
34void
35GNUNET_GNS_GTK_about_imagemenuitem_activate_cb (GtkWidget * dummy,
36 gpointer data)
37{
38 GNUNET_GTK_display_about ("gnunet_gns_gtk_about_window.glade");
39}
40
41
42/* end of gnunet-gns-gtk_about.c */
diff --git a/src/gns/gnunet-gns-gtk_zone.c b/src/gns/gnunet-gns-gtk_zone.c
deleted file mode 100644
index 4015248d..00000000
--- a/src/gns/gnunet-gns-gtk_zone.c
+++ /dev/null
@@ -1,1268 +0,0 @@
1/*
2 This file is part of GNUnet
3 (C) 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/gns/gnunet-gns-gtk_zone.c
23 * @author Christian Grothoff
24 * @brief everything releated to the zone tree view
25 */
26#include "gnunet_gtk.h"
27#include "gnunet-gns-gtk.h"
28
29
30/**
31 * FIXME: duplicated with "enum GNS_ModelColumns"!
32 */
33enum GNSTreestoreColumn
34{
35 /**
36 *
37 */
38 GNS_TREESTORE_COL_NAME = 0,
39
40 /**
41 *
42 */
43 GNS_TREESTORE_COL_IS_PUBLIC,
44
45 /**
46 *
47 */
48 GNS_TREESTORE_COL_RECORD_TYPE,
49
50 /**
51 *
52 */
53 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR,
54
55 /**
56 *
57 */
58 GNS_TREESTORE_COL_EXP_TIME,
59
60 /**
61 *
62 */
63 GNS_TREESTORE_COL_EXP_TIME_IS_REL,
64
65 /**
66 *
67 */
68 GNS_TREESTORE_COL_EXP_TIME_AS_STR,
69
70 /**
71 *
72 */
73 GNS_TREESTORE_COL_VAL_AS_STR,
74
75 /**
76 *
77 */
78 GNS_TREESTORE_COL_VAL_COLOR,
79
80 /**
81 *
82 */
83 GNS_TREESTORE_COL_NAME_IS_VISIBLE,
84
85 /**
86 *
87 */
88 GNS_TREESTORE_COL_IS_RECORD_ROW,
89
90 /**
91 *
92 */
93 GNS_TREESTORE_COL_NOT_DUMMY_ROW,
94
95 /**
96 *
97 */
98 GNS_TREESTORE_COL_EXP_TIME_COLOR,
99
100 /**
101 *
102 */
103 GNS_TREESTORE_COL_NAME_COLOR
104};
105
106
107/**
108 *
109 */
110enum LIST_COLUMNS
111{
112
113 /**
114 *
115 */
116 GNS_TYPE_TO_NAME_LISTSTORE_COLUMN_TYPE = 0,
117
118
119 /**
120 *
121 */
122 GNS_TYPE_TO_NAME_LISTSTORE_COLUMN_TYPENAME
123};
124
125
126/**
127 *
128 */
129struct UpdateContext
130{
131 /**
132 *
133 */
134 struct GNUNET_GNS_Context *gns;
135
136 /**
137 *
138 */
139 struct GNUNET_NAMESTORE_RecordData *rd;
140
141 /**
142 *
143 */
144 char * name;
145
146 /**
147 *
148 */
149 unsigned int rd_count;
150};
151
152
153static void
154check_name_validity_and_commit_remove_proc (void *cls,
155 int32_t success,
156 const char *emsg)
157{
158 struct UpdateContext * uc = cls;
159 unsigned int c;
160 if ((GNUNET_OK == success) || (GNUNET_NO == success))
161 {
162 for (c = 0; c < uc->rd_count; c++)
163 {
164 GNUNET_NAMESTORE_record_create(uc->gns->ns, uc->gns->pkey,
165 uc->name, &uc->rd[c],NULL, NULL);
166 GNUNET_free ((void *) uc->rd[c].data);
167 }
168 GNUNET_free (uc->rd);
169 GNUNET_free (uc->name);
170 GNUNET_free (uc);
171 }
172 else if (GNUNET_SYSERR == success)
173 {
174 for (c = 0; c < uc->rd_count; c++)
175 GNUNET_free ((void *) uc->rd[c].data);
176 GNUNET_free (uc->rd);
177 GNUNET_free (uc->name);
178 GNUNET_free (uc);
179 }
180 else
181 {
182 GNUNET_break (0);
183 GNUNET_free (uc);
184 }
185}
186
187
188static void
189check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path, char * oldname)
190{
191 GtkTreeIter it;
192 GtkTreeIter parent;
193 int records;
194 int children;
195 int append_pseu;
196 int c;
197 int valid = GNUNET_YES;
198 char * name;
199 void * data;
200 size_t data_size;
201 const gchar * pseu;
202
203 char *n_name;
204 int n_type;
205 gboolean n_public;
206 char *n_exp_color;
207 guint64 n_exp_time;
208 char *n_exp_str;
209 gboolean n_is_relative;
210 char *n_value;
211 char *n_value_color;
212
213
214 gtk_tree_model_get_iter_from_string(gns->tm, &it, path);
215
216 if (FALSE == gtk_tree_model_iter_parent (gns->tm, &parent, &it))
217 parent = it;
218
219 children = gtk_tree_model_iter_n_children (gns->tm, &parent);
220 if (children < 1)
221 {
222 return;
223 }
224
225 gtk_tree_model_get(gns->tm, &parent,
226 GNS_TREESTORE_COL_NAME, &name,
227 -1);
228
229 if (0 == strcmp (name, ROOT_STR))
230 {
231 /* We have to append PSEU RECORD */
232 append_pseu = GNUNET_YES;
233 records = children + 1;
234 }
235 else
236 {
237 append_pseu = GNUNET_NO;
238 records = children;
239 }
240
241 struct GNUNET_NAMESTORE_RecordData *rd = GNUNET_malloc (records * sizeof (struct GNUNET_NAMESTORE_RecordData));
242
243 if (FALSE == gtk_tree_model_iter_children (gns->tm, &it, &parent))
244 return;
245
246 for (c = 0; c < children; c++)
247 {
248 gtk_tree_model_get(gns->tm, &it,
249 GNS_TREESTORE_COL_NAME, &n_name,
250 GNS_TREESTORE_COL_RECORD_TYPE, &n_type,
251 GNS_TREESTORE_COL_IS_PUBLIC, &n_public,
252 GNS_TREESTORE_COL_EXP_TIME_COLOR, &n_exp_color,
253 GNS_TREESTORE_COL_EXP_TIME, &n_exp_time,
254 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative,
255 GNS_TREESTORE_COL_EXP_TIME_AS_STR, &n_exp_str,
256 GNS_TREESTORE_COL_VAL_AS_STR, &n_value,
257 GNS_TREESTORE_COL_VAL_COLOR, &n_value_color,
258 -1);
259 /* valid name */
260 if (NULL == n_name)
261 valid = GNUNET_NO;
262 else
263 {
264 if (GNUNET_SYSERR == GNUNET_NAMESTORE_check_name (n_name))
265 valid = GNUNET_NO;
266 }
267
268 /* valid record type */
269 if (0 == n_type)
270 valid = GNUNET_NO;
271
272 /* valid expiration */
273 if ((n_exp_color != NULL) || (NULL == n_exp_str) || (0 == n_exp_time))
274 valid = GNUNET_NO;
275
276 /* valid value */
277 if ((n_value_color != NULL) || (NULL == n_value))
278 valid = GNUNET_NO;
279 if (NULL != n_value)
280 {
281 if (GNUNET_OK != GNUNET_NAMESTORE_string_to_value(n_type, n_value, &data, &data_size))
282 valid = GNUNET_NO;
283 }
284
285 if (GNUNET_YES == valid)
286 {
287 if (FALSE == n_public)
288 rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
289 else
290 rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE;
291 rd[c].record_type = n_type;
292 rd[c].expiration_time = n_exp_time;
293 rd[c].data_size = data_size;
294 rd[c].data = GNUNET_malloc(data_size);
295 memcpy ((void *) rd[c].data, data, data_size);
296 }
297 g_free (n_name);
298 g_free (n_exp_color);
299 g_free (n_exp_str);
300 g_free (n_value);
301 g_free (n_value_color);
302
303 if (FALSE == gtk_tree_model_iter_next (gns->tm, &it))
304 break;
305 }
306
307 if (GNUNET_NO == valid)
308 {
309 for (c = 0; c < children; c++)
310 GNUNET_free_non_null ((void *) rd[c].data);
311 GNUNET_free_non_null (rd);
312 }
313 else
314 {
315
316 if (GNUNET_YES == append_pseu)
317 {
318 GNUNET_assert (children == (records -1));
319
320 /* Append PSEU record */
321 GtkEntry * entry = GTK_ENTRY (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_pseu_entry"));
322 pseu = gtk_entry_get_text (GTK_ENTRY(entry));
323 if ((NULL != pseu) && (0 != strcmp (PSEU_EMPTY_STR, pseu)) && (0 != strcmp ("", pseu)))
324 {
325 if (GNUNET_OK != GNUNET_NAMESTORE_string_to_value(GNUNET_NAMESTORE_TYPE_PSEU,
326 pseu,
327 (void **) &rd[records - 1].data,
328 &rd[records - 1].data_size))
329 {
330 GNUNET_break (0);
331 for (c = 0; c < records; c++)
332 GNUNET_free_non_null ((void *) rd[c].data);
333 GNUNET_free_non_null (rd);
334 }
335 rd[records - 1].record_type = GNUNET_NAMESTORE_TYPE_PSEU;
336 rd[records - 1].expiration_time = UINT64_MAX;
337 rd[records - 1].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE;
338 }
339 else
340 {
341 GNUNET_break (0);
342 }
343 }
344
345 /* Remove old entries */
346 struct UpdateContext * uc = GNUNET_malloc (sizeof (struct UpdateContext));
347 uc->gns = gns;
348 uc->rd = rd;
349 uc->rd_count = records;
350 uc->name = strdup (name);
351 if (oldname != NULL)
352 GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, oldname, NULL, &check_name_validity_and_commit_remove_proc, uc);
353 else
354 GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, &check_name_validity_and_commit_remove_proc, uc);
355 g_free (name);
356 }
357}
358
359
360/**
361 *
362 */
363struct Remove_Context
364{
365
366 /**
367 *
368 */
369 struct GNUNET_GNS_Context *gns;
370
371 /**
372 *
373 */
374 char *path;
375};
376
377
378static void
379check_name_validity_and_remove_proc (void *cls,
380 int32_t success,
381 const char *emsg)
382{
383 struct Remove_Context *rcc = cls;
384 GtkDialog *dialog;
385 GtkTreeIter it;
386 if (GNUNET_SYSERR == success)
387 {
388 char * message = _("Record could not be deleted:");
389 dialog = GTK_DIALOG(gtk_message_dialog_new (GTK_WINDOW (rcc->gns->main_window),
390 GTK_DIALOG_DESTROY_WITH_PARENT,
391 GTK_MESSAGE_ERROR,
392 GTK_BUTTONS_CLOSE,
393 _("%s\n%s\n"),
394 message,
395 emsg));
396
397 g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), rcc->gns);
398 gtk_widget_show_all (GTK_WIDGET(dialog));
399 }
400 else
401 {
402 gtk_tree_model_get_iter_from_string(rcc->gns->tm, &it, rcc->path);
403 gtk_tree_store_remove (rcc->gns->ts, &it);
404 }
405 GNUNET_free (rcc->path);
406 GNUNET_free (rcc);
407}
408
409
410static void
411check_name_validity_and_remove (struct GNUNET_GNS_Context *gns, gchar *path)
412{
413 GtkTreeIter it;
414 GtkTreeIter parent;
415 char *name;
416 int valid = GNUNET_YES;
417 struct GNUNET_NAMESTORE_RecordData rd;
418 struct Remove_Context *rcc;
419
420 char *n_name;
421 int n_type;
422 gboolean n_public;
423 char *n_exp_color;
424 guint64 n_exp_time;
425 char *n_exp_str;
426 gboolean n_is_relative;
427 char *n_value;
428 char *n_value_color;
429
430 gtk_tree_model_get_iter_from_string(gns->tm, &it, path);
431 gtk_tree_model_get(gns->tm, &it,
432 GNS_TREESTORE_COL_NAME, &name,
433 -1);
434
435 if (TRUE == gtk_tree_model_iter_parent (gns->tm, &parent, &it))
436 {
437 /* Removing a single record */
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
439 "Removing single record for name `%s'\n", name);
440
441 gtk_tree_model_get(gns->tm, &it,
442 GNS_TREESTORE_COL_NAME, &n_name,
443 GNS_TREESTORE_COL_RECORD_TYPE, &n_type,
444 GNS_TREESTORE_COL_IS_PUBLIC, &n_public,
445 GNS_TREESTORE_COL_EXP_TIME_COLOR, &n_exp_color,
446 GNS_TREESTORE_COL_EXP_TIME, &n_exp_time,
447 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative,
448 GNS_TREESTORE_COL_EXP_TIME_AS_STR, &n_exp_str,
449 GNS_TREESTORE_COL_VAL_AS_STR, &n_value,
450 GNS_TREESTORE_COL_VAL_COLOR, &n_value_color,
451 -1);
452
453 /* valid name */
454 if (NULL == n_name)
455 valid = GNUNET_NO;
456
457 /* valid record type */
458 if (0 == n_type)
459 valid = GNUNET_NO;
460
461 /* valid expiration */
462 if ((n_exp_color != NULL) || (NULL == n_exp_str) || (0 == n_exp_time))
463 valid = GNUNET_NO;
464
465 /* valid value */
466 if ((n_value_color != NULL) || (NULL == n_value))
467 valid = GNUNET_NO;
468
469 if (GNUNET_YES == valid)
470 {
471 if (FALSE == n_public)
472 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
473 else
474 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE;
475 rd.record_type = n_type;
476 rd.expiration_time = n_exp_time;
477 rd.data_size = strlen (n_value) + 1;
478 rd.data = GNUNET_malloc(rd.data_size);
479 memcpy ((void *) rd.data, n_value, rd.data_size);
480
481 rcc = GNUNET_malloc(sizeof (struct Remove_Context));
482 rcc->gns = gns;
483 rcc->path = strdup (path);
484 GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, &rd, &check_name_validity_and_remove_proc, rcc);
485 GNUNET_free ((void *) rd.data);
486 }
487 else
488 {
489 gtk_tree_model_get_iter_from_string(gns->tm, &it, path);
490 gtk_tree_store_remove (gns->ts, &it);
491 }
492 g_free (n_name);
493 g_free (n_exp_color);
494 g_free (n_exp_str);
495 g_free (n_value);
496 g_free (n_value_color);
497 }
498 else if (0 != strcmp (name, ROOT_STR))
499 {
500 /* Removing the whole name record */
501 rcc = GNUNET_malloc(sizeof (struct Remove_Context));
502 rcc->gns = gns;
503 rcc->path = strdup (path);
504 GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, &check_name_validity_and_remove_proc, rcc);
505 }
506 g_free (name);
507}
508
509
510/**
511 * The user has selected a new record type. Update the
512 * model, possibly invalidating (marking 'red') the existing
513 * value.
514 *
515 * @param renderer updated renderer
516 * @param path the path identifying the edited cell
517 * @param new_iter selected cell in the combo's model (with the record type)
518 * @param user_data unused
519 */
520void
521GNUNET_GNS_GTK_type_cellrenderercombo_changed_cb (GtkCellRendererCombo *combo,
522 gchar *path,
523 GtkTreeIter *new_iter,
524 gpointer user_data)
525{
526 struct GNUNET_GNS_Context *gns = user_data;
527 GtkTreeIter it;
528 GtkTreeIter child;
529 guint type;
530 int record_row;
531 char *type_str;
532 char *value_str;
533 char *name_str;
534 void *data;
535 size_t data_size;
536
537 gtk_tree_model_get(GTK_TREE_MODEL(gns->ls), new_iter, 0, &type, -1);
538 gtk_tree_model_get(GTK_TREE_MODEL(gns->ls), new_iter, GNS_TYPE_TO_NAME_LISTSTORE_COLUMN_TYPENAME, &type_str, -1);
539
540
541 /* check if this is a new record */
542 gtk_tree_model_get_iter_from_string(gns->tm, &it, path);
543 gtk_tree_model_get(gns->tm, &it, GNS_TREESTORE_COL_IS_RECORD_ROW, &record_row, -1);
544 gtk_tree_model_get(gns->tm, &it, GNS_TREESTORE_COL_NAME, &name_str, -1);
545
546 if (GNUNET_YES == record_row)
547 {
548 /* Updating an existing record */
549 gtk_tree_store_set(gns->ts, &it,
550 GNS_TREESTORE_COL_RECORD_TYPE, type,
551 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, type_str,
552 -1);
553 }
554 else if ((NULL != name_str) && (0 != strcmp (NEW_NAME_STR, name_str)))
555 {
556 /* Adding a new record */
557
558 gtk_tree_store_insert_with_values(gns->ts, &child , &it, 0,
559 GNS_TREESTORE_COL_NAME, name_str,
560 GNS_TREESTORE_COL_NAME_IS_VISIBLE, FALSE,
561 GNS_TREESTORE_COL_RECORD_TYPE, type,
562 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, type_str,
563 GNS_TREESTORE_COL_EXP_TIME_AS_STR, EXPIRE_NEVER_STRING,
564 GNS_TREESTORE_COL_EXP_TIME, GNUNET_TIME_UNIT_FOREVER_ABS,
565 GNS_TREESTORE_COL_EXP_TIME_IS_REL, FALSE,
566 GNS_TREESTORE_COL_IS_RECORD_ROW, GNUNET_YES,
567 GNS_TREESTORE_COL_NOT_DUMMY_ROW, GNUNET_YES,
568 -1);
569 gtk_tree_view_expand_row (gns->tv, gtk_tree_model_get_path(gns->tm, &it), 0);
570
571 }
572 GNUNET_free (type_str);
573
574 /* check if value is still valid */
575 gtk_tree_model_get(gns->tm, &it, GNS_TREESTORE_COL_VAL_AS_STR, &value_str, -1);
576 if (NULL != value_str)
577 {
578 if (GNUNET_OK != GNUNET_NAMESTORE_string_to_value (type,
579 value_str,
580 &data,
581 &data_size))
582 gtk_tree_store_set (gns->ts, &it, GNS_TREESTORE_COL_VAL_COLOR, "red", -1);
583 else
584 gtk_tree_store_set (gns->ts, &it, GNS_TREESTORE_COL_VAL_COLOR, NULL, -1);
585 GNUNET_free (value_str);
586 }
587 else if (NULL == value_str)
588 {
589 /* Empty value field */
590 if (GNUNET_YES == record_row)
591 gtk_tree_store_set (gns->ts, &it, GNS_TREESTORE_COL_VAL_COLOR, "red", -1);
592 else
593 gtk_tree_store_set (gns->ts, &child, GNS_TREESTORE_COL_VAL_COLOR, "red", -1);
594 }
595
596 check_name_validity_and_commit (gns, path, NULL);
597 GNUNET_free_non_null (name_str);
598}
599
600
601/**
602 * The user has toggled the 'public' checkmark of a cell. Update the
603 * model.
604 *
605 * @param renderer updated renderer
606 * @param path the path identifying the edited cell
607 * @param user_data unused
608 */
609void
610GNUNET_GNS_GTK_ispublic_cellrenderertoggle_toggled_cb (GtkCellRendererToggle *cell_renderer,
611 gchar *path,
612 gpointer user_data)
613{
614 struct GNUNET_GNS_Context *gns = user_data;
615 GtkTreeIter it;
616 gboolean value;
617
618 gtk_tree_model_get_iter_from_string(gns->tm, &it, path);
619 gtk_tree_model_get(gns->tm, &it, GNS_TREESTORE_COL_IS_PUBLIC, &value, -1);
620 gtk_tree_store_set(gns->ts, &it, GNS_TREESTORE_COL_IS_PUBLIC, !value, -1);
621
622 check_name_validity_and_commit (gns, path, NULL);
623}
624
625
626static char *
627convert_time_to_string (struct GNUNET_TIME_Absolute t)
628{
629 time_t tt;
630 struct tm *time;
631 char *ret;
632
633 if (t.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
634 return GNUNET_strdup (_(EXPIRE_NEVER_STRING));
635 if (t.abs_value == GNUNET_TIME_UNIT_ZERO_ABS.abs_value)
636 return GNUNET_strdup (_(EXPIRE_INVALID_STRING));
637
638 tt = t.abs_value / 1000;
639 time = localtime (&tt);
640
641 GNUNET_asprintf(&ret, "%02u/%02u/%04u %02u:%02u",time->tm_mon, time->tm_mday, 1900 + time->tm_year, time->tm_hour, time->tm_min);
642 return ret;
643}
644
645
646static int
647check_time (const char * text)
648{
649 unsigned int t_mon;
650 unsigned int t_day;
651 unsigned int t_year;
652 unsigned int t_hrs;
653 unsigned int t_min;
654
655 int count = SSCANF (text, "%02u/%02u/%04u %02u:%02u", &t_mon, &t_day, &t_year, &t_hrs, &t_min);
656 if ((EOF == count) || (5 != count))
657 return GNUNET_SYSERR;
658
659 if (t_mon > 12)
660 return GNUNET_SYSERR;
661 if (t_day > 31)
662 return GNUNET_SYSERR;
663 if (t_hrs > 24)
664 return GNUNET_SYSERR;
665 if (t_min > 59)
666 return GNUNET_SYSERR;
667
668 return GNUNET_OK;
669}
670
671
672static const struct GNUNET_TIME_Absolute
673convert_string_to_abs_time (const char * text)
674{
675 static struct GNUNET_TIME_Absolute abs_t;
676 struct tm time;
677 time_t t;
678
679 int t_mon;
680 int t_day;
681 int t_year;
682 int t_hrs;
683 int t_min;
684
685 GNUNET_assert (NULL != text);
686
687 if (0 == strcmp(text, EXPIRE_NEVER_STRING))
688 return GNUNET_TIME_UNIT_FOREVER_ABS;
689
690 memset (&time, '\0', sizeof (struct tm));
691
692 if (GNUNET_SYSERR == check_time(text))
693 {
694 GNUNET_break (0);
695 return GNUNET_TIME_UNIT_ZERO_ABS;
696 }
697
698 int count = SSCANF (text, "%02d/%02d/%04d %02d:%02d", &t_mon, &t_day, &t_year, &t_hrs, &t_min);
699 if ((EOF == count) || (5 != count))
700 return GNUNET_TIME_UNIT_ZERO_ABS;
701
702 time.tm_mon = (t_mon - 1);
703 time.tm_mday = t_day;
704 time.tm_year = t_year - 1900;
705 time.tm_hour = (t_hrs);
706 time.tm_min = t_min;
707
708 t = mktime (&time);
709 if (-1 == t)
710 return GNUNET_TIME_UNIT_ZERO_ABS;
711
712 abs_t.abs_value = t * 1000;
713
714 return abs_t;
715}
716
717
718/**
719 * The user has edited a 'expiration' cell. Update the model.
720 *
721 * @param renderer updated renderer
722 * @param path the path identifying the edited cell
723 * @param new_text the new expiration time
724 * @param user_data unused
725 */
726void
727GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
728 gchar *path,
729 gchar *new_text,
730 gpointer user_data)
731{
732 struct GNUNET_GNS_Context * gns = user_data;
733 GtkTreeIter it;
734 struct GNUNET_TIME_Absolute abstime;
735 gboolean is_rel;
736 char *old_text;
737
738 if ((NULL != new_text))
739 {
740 gtk_tree_model_get_iter_from_string(gns->tm, &it, path);
741 gtk_tree_model_get(gns->tm, &it,
742 GNS_TREESTORE_COL_EXP_TIME_AS_STR, &old_text,
743 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &is_rel,
744 -1);
745 if (0 == strcmp(new_text, old_text))
746 return;
747
748 if ((0 == strcmp(new_text,"")) || (0 == strcmp(new_text,EXPIRE_NEVER_STRING)))
749 {
750 new_text = EXPIRE_NEVER_STRING;
751 abstime = GNUNET_TIME_UNIT_FOREVER_ABS;
752 }
753 else
754 {
755 if (GNUNET_SYSERR == check_time(new_text))
756 {
757 gtk_tree_store_set (gns->ts, &it,
758 GNS_TREESTORE_COL_EXP_TIME_AS_STR, new_text,
759 GNS_TREESTORE_COL_EXP_TIME_COLOR, "red",
760 GNS_TREESTORE_COL_EXP_TIME, 0,
761 -1);
762 abstime = GNUNET_TIME_UNIT_ZERO_ABS;
763 return;
764 }
765 /* TODO: fix this when we have relative time */
766 if (TRUE == is_rel)
767 {
768 abstime = convert_string_to_abs_time(new_text);
769 }
770 else
771 {
772 abstime = convert_string_to_abs_time(new_text);
773 }
774 }
775 gtk_tree_store_set (gns->ts, &it,
776 GNS_TREESTORE_COL_EXP_TIME_AS_STR, new_text,
777 GNS_TREESTORE_COL_EXP_TIME, abstime.abs_value,
778 GNS_TREESTORE_COL_EXP_TIME_COLOR, NULL,
779 -1);
780 check_name_validity_and_commit (gns, path, NULL);
781 }
782}
783
784
785/**
786 * The user has edited a 'value' cell. Update the model,
787 * including the status on the consistency of the value with
788 * the type.
789 *
790 * @param renderer updated renderer
791 * @param path the path identifying the edited cell
792 * @param new_text the new value
793 * @param user_data unused
794 */
795void
796GNUNET_GNS_GTK_value_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
797 gchar *path,
798 gchar *new_text,
799 gpointer user_data)
800{
801 struct GNUNET_GNS_Context *gns = user_data;
802 GtkTreeModel *tm = GTK_TREE_MODEL(gns->ts);
803 GtkTreeIter it;
804 size_t data_size;
805 void * data;
806 int type;
807 gchar * old_value;
808
809 if (0 != strcmp(new_text,""))
810 {
811 gtk_tree_model_get_iter_from_string(tm, &it, path);
812 gtk_tree_model_get(tm, &it,
813 GNS_TREESTORE_COL_RECORD_TYPE, &type,
814 GNS_TREESTORE_COL_VAL_AS_STR, &old_value,
815 -1);
816
817 if (old_value != NULL)
818 {
819 if (0 == strcmp(new_text, old_value))
820 {
821 GNUNET_free (old_value);
822 return;
823 }
824 GNUNET_free (old_value);
825 }
826
827 if (GNUNET_OK == GNUNET_NAMESTORE_string_to_value (type,
828 new_text,
829 &data,
830 &data_size))
831 {
832 gtk_tree_store_set (gns->ts, &it, GNS_TREESTORE_COL_VAL_COLOR, NULL, -1);
833 gtk_tree_store_set (gns->ts, &it, GNS_TREESTORE_COL_VAL_AS_STR, new_text, -1);
834 check_name_validity_and_commit (gns, path, NULL);
835 }
836 else
837 {
838 gtk_tree_store_set (gns->ts, &it, GNS_TREESTORE_COL_VAL_COLOR, "red", -1);
839 gtk_tree_store_set (gns->ts, &it, GNS_TREESTORE_COL_VAL_AS_STR, new_text, -1);
840 }
841 }
842}
843
844
845/**
846 * The user has edited a 'name' cell. Update the model (and if needed
847 * create another fresh line for additional records).
848 *
849 * @param renderer updated renderer
850 * @param path the path identifying the edited cell
851 * @param new_text the new name
852 * @param user_data unused
853 */
854void
855GNUNET_GNS_GTK_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
856 gchar *path,
857 gchar *new_text,
858 gpointer user_data)
859{
860 struct GNUNET_GNS_Context *gns = user_data;
861 GtkTreeIter it;
862 GtkTreeIter child;
863 GtkTreeModel *tm = GTK_TREE_MODEL(gns->ts);
864 int not_dummy;
865 char *name;
866
867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", path, new_text);
868 if ((0 == strcmp (new_text, NEW_NAME_STR)) || (0 == strcmp (new_text, "")))
869 return;
870
871 gtk_tree_model_get_iter_from_string(tm, &it, path);
872 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy, -1);
873 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NAME, &name, -1);
874
875 if (not_dummy == GNUNET_NO)
876 {
877 /* update name */
878 gtk_tree_store_set (gns->ts, &it,
879 GNS_TREESTORE_COL_NAME, new_text,
880 GNS_TREESTORE_COL_RECORD_TYPE, 0,
881 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, _(NEW_RECORD_STR),
882 GNS_TREESTORE_COL_NOT_DUMMY_ROW, GNUNET_YES,
883 -1);
884 check_name_validity_and_commit (gns, gtk_tree_model_get_string_from_iter(gns->tm, &it), name);
885
886 /* add a new dummy line */
887 gtk_tree_store_insert_with_values (gns->ts, &it,NULL, 0,
888 GNS_TREESTORE_COL_NAME, _(NEW_NAME_STR),
889 GNS_TREESTORE_COL_NAME_IS_VISIBLE, TRUE,
890 GNS_TREESTORE_COL_RECORD_TYPE, 1,
891 GNS_TREESTORE_COL_NOT_DUMMY_ROW, GNUNET_NO,
892 GNS_TREESTORE_COL_IS_RECORD_ROW, GNUNET_NO,
893 -1);
894 }
895 else
896 {
897 /* update name */
898 gtk_tree_store_set (gns->ts, &it, GNS_TREESTORE_COL_NAME, new_text, -1);
899
900 if (TRUE == gtk_tree_model_iter_children (gns->tm, &child, &it))
901 {
902 do
903 {
904 gtk_tree_store_set (gns->ts, &child,
905 GNS_TREESTORE_COL_NAME, &new_text,
906 -1);
907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", path, new_text);
908 }
909 while (TRUE == gtk_tree_model_iter_next (gns->tm, &child));
910 }
911
912 check_name_validity_and_commit (gns, gtk_tree_model_get_string_from_iter(gns->tm, &it), name);
913 }
914
915 if (GNUNET_SYSERR == GNUNET_NAMESTORE_check_name (new_text))
916 {
917 gtk_tree_store_set (gns->ts, &it,
918 GNS_TREESTORE_COL_NAME_COLOR, "red",
919 -1);
920 }
921 else
922 {
923 gtk_tree_store_set (gns->ts, &it,
924 GNS_TREESTORE_COL_NAME_COLOR, NULL,
925 -1);
926 }
927}
928
929
930/**
931 * The zone treeview pop up menu is supposed to be created.
932 * (Note: this is not the only method that might need to be
933 * written to handle events to create pop up menus; right-clicks
934 * might need to be managed separately).
935 *
936 * @param widget the widget
937 * @param user_data unused
938 * @return TRUE if a menu was activated
939 */
940gboolean
941GNUNET_GNS_GTK_main_treeview_popup_menu_cb (GtkWidget *widget,
942 gpointer user_data)
943{
944 struct GNUNET_GNS_Context *gns = user_data;
945 GtkTreeModel *tm;
946 GtkTreeIter it;
947 GtkMenu *popup;
948 GtkTreeSelection * ts;
949 int not_dummy;
950
951 ts = gtk_tree_view_get_selection(gns->tv);
952 if (! gtk_tree_selection_get_selected (ts, &tm, &it))
953 return TRUE;
954 gtk_tree_model_get(gns->tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy, -1);
955 if (GNUNET_NO == not_dummy)
956 return TRUE;
957
958 popup = GTK_MENU(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_delete_popup_menu"));
959 gtk_widget_show_all (GTK_WIDGET(popup));
960 gtk_menu_popup(popup, NULL, NULL, NULL, NULL, 0, 0);
961 return TRUE;
962}
963
964
965static void
966set_relative_expiration_time (struct GNUNET_GNS_Context *gns, struct GNUNET_TIME_Relative reltime)
967{
968 GtkTreeIter it;
969 GtkTreeIter parent;
970 GtkCellRendererText *renderer;
971 GtkTreeModel *tm;
972 GtkTreeSelection * ts = gtk_tree_view_get_selection(gns->tv);
973 gboolean has_parent;
974 struct GNUNET_TIME_Absolute abstime;
975 char *path;
976 int not_dummy;
977
978 if (! gtk_tree_selection_get_selected (ts, &tm, &it))
979 return;
980
981 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy, -1);
982 if (GNUNET_NO == not_dummy)
983 return;
984
985 /* Has parent? */
986 has_parent = gtk_tree_model_iter_parent (tm, &parent, &it);
987
988 if (FALSE == has_parent)
989 return;
990
991 abstime = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), reltime);
992
993 /* this is a single record */
994 renderer = GTK_CELL_RENDERER_TEXT((gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_name_cellrenderertext")));
995 path = gtk_tree_model_get_string_from_iter (tm, &it);
996 GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (renderer,
997 path,
998 convert_time_to_string (abstime),
999 gns);
1000}
1001
1002
1003gboolean
1004GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb (GtkWidget *widget,
1005 gpointer user_data)
1006{
1007 set_relative_expiration_time (user_data, GNUNET_TIME_UNIT_DAYS);
1008 return TRUE;
1009}
1010
1011
1012gboolean
1013GNUNET_GNS_GTK_main_treeview_popup_menu_exp1w_cb (GtkWidget *widget,
1014 gpointer user_data)
1015{
1016 set_relative_expiration_time (user_data, GNUNET_TIME_UNIT_WEEKS);
1017 return TRUE;
1018}
1019
1020
1021gboolean
1022GNUNET_GNS_GTK_main_treeview_popup_menu_exp1y_cb (GtkWidget *widget,
1023 gpointer user_data)
1024{
1025 set_relative_expiration_time (user_data, GNUNET_TIME_UNIT_YEARS);
1026 return TRUE;
1027}
1028
1029
1030gboolean
1031GNUNET_GNS_GTK_main_treeview_popup_menu_expinf_cb (GtkWidget *widget,
1032 gpointer user_data)
1033{
1034 set_relative_expiration_time (user_data, GNUNET_TIME_UNIT_FOREVER_REL);
1035 return TRUE;
1036}
1037
1038
1039gboolean
1040GNUNET_GNS_GTK_main_treeview_button_press_popup_menu_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
1041{
1042 /* Check for right click*/
1043 if (NULL == widget)
1044 return FALSE;
1045 if (event->type == GDK_BUTTON_PRESS && event->button == 3)
1046 GNUNET_GNS_GTK_main_treeview_popup_menu_cb (widget, user_data);
1047 return FALSE;
1048}
1049
1050
1051gboolean
1052GNUNET_GNS_GTK_main_treeview_key_press_popup_menu_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
1053{
1054 /* Check for delete key */
1055 if ((event->type == GDK_KEY_PRESS) && (GDK_KEY_Delete == event->keyval))
1056 GNUNET_GNS_GTK_main_treeview_popup_menu_cb (widget, user_data);
1057 return FALSE;
1058}
1059
1060
1061struct ZoneIteration_Context
1062{
1063 struct GNUNET_GNS_Context *gns;
1064 struct GNUNET_CRYPTO_ShortHashCode zone;
1065 struct GNUNET_NAMESTORE_ZoneIterator * it;
1066 char *label;
1067};
1068
1069
1070void
1071GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem,
1072 gpointer user_data)
1073{
1074 struct GNUNET_GNS_Context *gns = user_data;
1075 GtkTreeIter it;
1076 GtkTreeModel *tm;
1077 GtkTreeSelection * ts;
1078 int not_dummy;
1079 char *path;
1080
1081 ts = gtk_tree_view_get_selection(gns->tv);
1082 if (gtk_tree_selection_get_selected (ts, &tm, &it))
1083 {
1084 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy, -1);
1085 if (GNUNET_NO == not_dummy)
1086 return; /* do not delete the dummy line */
1087
1088 path = gtk_tree_model_get_string_from_iter (gns->tm, &it);
1089 check_name_validity_and_remove(gns, path);
1090 g_free (path);
1091 }
1092}
1093
1094
1095static void
1096zone_iteration_proc (void *cls,
1097 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
1098 struct GNUNET_TIME_Absolute expire,
1099 const char *name,
1100 unsigned int rd_count,
1101 const struct GNUNET_NAMESTORE_RecordData *rd,
1102 const struct GNUNET_CRYPTO_RsaSignature *signature)
1103{
1104 struct ZoneIteration_Context * zc_ctx = cls;
1105 GtkTreeIter iter_name;
1106 GtkTreeIter iter_record;
1107 GtkEntry *pseu_entry;
1108 int c;
1109 int time_is_relative;
1110
1111 char *exp;
1112 char *val;
1113 char * type_str;
1114 int public;
1115 guint64 exp_t;
1116
1117 GNUNET_assert (zc_ctx != NULL);
1118 if ((NULL == zone_key) && (NULL == name))
1119 {
1120 struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
1121 GNUNET_CRYPTO_short_hash_to_enc(&zc_ctx->zone, &shenc);
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone `%s 'iteration done\n", &shenc);
1123 pseu_entry = GTK_ENTRY((gtk_builder_get_object (zc_ctx->gns->builder, "GNUNET_GNS_GTK_pseu_entry")));
1124 if (zc_ctx->label == NULL)
1125 GNUNET_asprintf(&zc_ctx->label, "%s", PSEU_EMPTY_STR);
1126 gtk_entry_set_text (pseu_entry, zc_ctx->label);
1127 zc_ctx->gns->iteration = GNUNET_NO;
1128 GNUNET_free (zc_ctx->label);
1129 GNUNET_free (zc_ctx);
1130 return;
1131 }
1132
1133
1134 struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
1135 GNUNET_CRYPTO_short_hash_to_enc(&zc_ctx->zone, &shenc);
1136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone `%s' iteration result `%s', %u records\n",
1137 &shenc, name, rd_count);
1138
1139 GNUNET_assert(GTK_IS_TREE_STORE(zc_ctx->gns->ts));
1140 gtk_tree_store_append(zc_ctx->gns->ts, &iter_name, NULL);
1141 gtk_tree_store_set(zc_ctx->gns->ts, &iter_name,
1142 GNS_TREESTORE_COL_NAME, name,
1143 GNS_TREESTORE_COL_NAME_IS_VISIBLE, TRUE,
1144 GNS_TREESTORE_COL_RECORD_TYPE, 0,
1145 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, _(NEW_RECORD_STR),
1146 GNS_TREESTORE_COL_IS_RECORD_ROW, GNUNET_NO,
1147 GNS_TREESTORE_COL_NOT_DUMMY_ROW, GNUNET_YES,
1148 -1);
1149
1150 if (GNUNET_SYSERR == GNUNET_NAMESTORE_check_name (name))
1151 {
1152 gtk_tree_store_set (zc_ctx->gns->ts, &iter_name,
1153 GNS_TREESTORE_COL_NAME_COLOR, "red",
1154 -1);
1155 }
1156 /* Append elements for records */
1157 for (c = 0; c < rd_count; c ++)
1158 {
1159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %u: type %u flags %u expiration %llu data_size %u\n",
1160 c, rd[c].record_type, rd[c].flags, rd[c].expiration_time, rd[c].data_size);
1161
1162 /* Set public toggle */
1163 if ((rd[c].flags & GNUNET_NAMESTORE_RF_PRIVATE) == GNUNET_NAMESTORE_RF_PRIVATE)
1164 {
1165 public = GNUNET_NO;
1166 }
1167 else
1168 {
1169 public = GNUNET_YES;
1170 }
1171
1172 /* Expiration time */
1173 time_is_relative = GNUNET_NO;
1174
1175 if (GNUNET_YES == time_is_relative)
1176 {
1177 /* TODO: FIX THIS WHEN WE HAVE RELATIVE TIME */
1178 struct GNUNET_TIME_Relative rel_time = GNUNET_TIME_UNIT_ZERO;
1179 struct GNUNET_TIME_Absolute exp_abs;
1180 exp_abs = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time);
1181 exp_t = exp_abs.abs_value;
1182 exp = convert_time_to_string (exp_abs);
1183 }
1184 else
1185 {
1186 struct GNUNET_TIME_Absolute exp_abs;
1187
1188 exp_abs.abs_value = rd[c].expiration_time;
1189 exp_t = exp_abs.abs_value;
1190 exp = convert_time_to_string (exp_abs);
1191 }
1192 /* value */
1193 val = GNUNET_NAMESTORE_value_to_string (rd[c].record_type,
1194 rd[c].data,
1195 rd[c].data_size);
1196 if (NULL == val)
1197 GNUNET_asprintf(&val, "%s", EXPIRE_INVALID_STRING);
1198
1199 if (NULL != GNUNET_NAMESTORE_number_to_typename(rd[c].record_type))
1200 type_str = strdup (GNUNET_NAMESTORE_number_to_typename(rd[c].record_type));
1201 else
1202 GNUNET_asprintf(&type_str, "%s", EXPIRE_INVALID_STRING);
1203
1204 if ((0 ==strcmp (name, ROOT_STR)) && (GNUNET_NAMESTORE_TYPE_PSEU == rd[c].record_type))
1205 {
1206 zc_ctx->label = strdup(val);
1207 zc_ctx->gns->iteration = GNUNET_YES;
1208 }
1209 else
1210 {
1211 gtk_tree_store_insert_with_values(zc_ctx->gns->ts, &iter_record , &iter_name, 0,
1212 GNS_TREESTORE_COL_NAME, name,
1213 GNS_TREESTORE_COL_NAME_IS_VISIBLE, FALSE,
1214 GNS_TREESTORE_COL_RECORD_TYPE, rd[c].record_type,
1215 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, type_str,
1216 GNS_TREESTORE_COL_IS_PUBLIC, public,
1217 GNS_TREESTORE_COL_EXP_TIME, exp_t,
1218 GNS_TREESTORE_COL_EXP_TIME_AS_STR, exp,
1219 GNS_TREESTORE_COL_EXP_TIME_IS_REL, time_is_relative,
1220 GNS_TREESTORE_COL_VAL_AS_STR, val,
1221 GNS_TREESTORE_COL_IS_RECORD_ROW, GNUNET_YES,
1222 GNS_TREESTORE_COL_NOT_DUMMY_ROW, GNUNET_YES,
1223 -1);
1224 }
1225 GNUNET_free (type_str);
1226 GNUNET_free (exp);
1227 GNUNET_free (val);
1228 }
1229
1230 GNUNET_NAMESTORE_zone_iterator_next(zc_ctx->it);
1231}
1232
1233
1234/**
1235 * The zone treeview was realized. Setup the model.
1236 *
1237 * @param widget the widget
1238 * @param user_data unused
1239 */
1240void
1241GNUNET_GNS_GTK_main_treeview_realize_cb (GtkWidget *widget,
1242 gpointer user_data)
1243{
1244 struct GNUNET_GNS_Context *gns = user_data;
1245 struct ZoneIteration_Context *zc_ctx;
1246 GtkTreeIter toplevel;
1247
1248 /* Append a top level row and leave it empty */
1249 gtk_tree_store_insert_with_values(gns->ts, &toplevel, NULL, 0,
1250 GNS_TREESTORE_COL_NAME, _(NEW_NAME_STR),
1251 GNS_TREESTORE_COL_NAME_IS_VISIBLE, TRUE,
1252 GNS_TREESTORE_COL_RECORD_TYPE, 1,
1253 GNS_TREESTORE_COL_IS_RECORD_ROW, GNUNET_NO,
1254 GNS_TREESTORE_COL_NOT_DUMMY_ROW, GNUNET_NO,
1255 -1);
1256
1257 zc_ctx = GNUNET_malloc (sizeof (struct ZoneIteration_Context));
1258 zc_ctx->gns = user_data;
1259 zc_ctx->zone = gns->zone;
1260 zc_ctx->it = GNUNET_NAMESTORE_zone_iteration_start(gns->ns, &gns->zone,
1261 GNUNET_NAMESTORE_RF_NONE,
1262 GNUNET_NAMESTORE_RF_NONE,
1263 &zone_iteration_proc,
1264 zc_ctx);
1265}
1266
1267
1268/* end of gnunet-gns-gtk_zone.c */