aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-gns-gtk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/gnunet-gns-gtk.c')
-rw-r--r--src/gns/gnunet-gns-gtk.c187
1 files changed, 185 insertions, 2 deletions
diff --git a/src/gns/gnunet-gns-gtk.c b/src/gns/gnunet-gns-gtk.c
index 9a49bc6f..d40dbb1e 100644
--- a/src/gns/gnunet-gns-gtk.c
+++ b/src/gns/gnunet-gns-gtk.c
@@ -24,6 +24,7 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet_gtk.h" 26#include "gnunet_gtk.h"
27#include <gnunet/gnunet_namestore_service.h>
27 28
28/** 29/**
29 * Handle to our main loop. 30 * Handle to our main loop.
@@ -35,6 +36,36 @@ static struct GNUNET_GTK_MainLoop *ml;
35 */ 36 */
36static int tray_only; 37static int tray_only;
37 38
39/**
40 * Hash of the public key of our zone.
41 */
42static GNUNET_HashCode zone;
43
44/**
45 * Private key for the our zone.
46 */
47static struct GNUNET_CRYPTO_RsaPrivateKey *zone_pkey;
48
49/**
50 * Handle to the namestore.
51 */
52static struct GNUNET_NAMESTORE_Handle *ns;
53
54/**
55 * Name of our zone as a string.
56 */
57static char *zone_as_string;
58
59
60/**
61 * Get cfg.
62 */
63static const struct GNUNET_CONFIGURATION_Handle *
64get_configuration ()
65{
66 return GNUNET_GTK_main_loop_get_configuration (ml);
67}
68
38 69
39/** 70/**
40 * Get an object from the main window. 71 * Get an object from the main window.
@@ -50,6 +81,82 @@ get_object (const char *name)
50 81
51 82
52/** 83/**
84 * The user edited the preferred name (PSEU) of this namespace.
85 * Push the update to the namestore.
86 *
87 * @param editable the edited widget
88 * @param user_data unused
89 */
90void
91GNUNET_GNS_GTK_pseu_entry_changed_cb (GtkEditable *editable,
92 gpointer user_data)
93{
94 GNUNET_break (0); // FIXME, not implemented
95}
96
97
98/**
99 * The user toggled the 'autoshort' option. Update the configuration.
100 *
101 * @param checkmenuitem the menu item
102 * @param user_data unused
103 */
104void
105GNUNET_GNS_GTK_autoshort_imagemenuitem_toggled_cb (GtkCheckMenuItem *checkmenuitem,
106 gpointer user_data)
107{
108 GNUNET_break (0); // FIXME, not implemented
109}
110
111
112/**
113 * The user selected 'NEW' in the menu. Open a dialog to enter a filename
114 * to create a new zone (for editing).
115 *
116 * @param checkmenuitem the menu item
117 * @param user_data unused
118 */
119void
120GNUNET_GNS_GTK_new_imagemenuitem_activate_cb (GtkMenuItem *menuitem,
121 gpointer user_data)
122{
123 GNUNET_break (0); // FIXME, not implemented
124}
125
126/**
127 * The user selected 'NEW' in the menu. Open a dialog to select
128 * a different zonefile (for editing).
129 *
130 * @param checkmenuitem the menu item
131 * @param user_data unused
132 */
133void
134GNUNET_GNS_GTK_open_imagemenuitem_activate_cb (GtkMenuItem *menuitem,
135 gpointer user_data)
136{
137 GNUNET_break (0); // FIXME, not implemented
138}
139
140
141/**
142 * The user clicked on the 'copy' button. Copy the full string
143 * with the hash of our public key to the clipboard.
144 *
145 * @param button the button that was clicked
146 * @param user_data unused
147 */
148void
149GNUNET_GNS_GTK_public_key_copy_button_clicked_cb (GtkButton *button,
150 gpointer user_data)
151{
152 GtkClipboard *cb;
153
154 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
155 gtk_clipboard_set_text (cb, zone_as_string, -1);
156}
157
158
159/**
53 * Task run on shutdown. 160 * Task run on shutdown.
54 * 161 *
55 * @param cls unused 162 * @param cls unused
@@ -58,14 +165,46 @@ get_object (const char *name)
58static void 165static void
59shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 166shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
60{ 167{
168 if (NULL != ns)
169 {
170 GNUNET_NAMESTORE_disconnect (ns, GNUNET_NO);
171 ns = NULL;
172 }
173 if (NULL != zone_pkey)
174 {
175 GNUNET_CRYPTO_rsa_key_free (zone_pkey);
176 zone_pkey = NULL;
177 }
178}
179
180
181/**
182 * Callback invoked if the application is supposed to exit (via menu).
183 *
184 * @param menuitem the quit menu
185 * @param user_data unused
186 */
187void
188GNUNET_GNS_GTK_quit_imagemenuitem_activate_cb (GtkMenuItem *menuitem,
189 gpointer user_data)
190{
191 GNUNET_GTK_tray_icon_destroy ();
192 GNUNET_GTK_main_loop_quit (ml);
193 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
61} 194}
62 195
63 196
64/** 197/**
65 * Callback invoked if the application is supposed to exit. 198 * Callback invoked if the application is supposed to exit (via window-close).
199 *
200 * @param widget the main window
201 * @param event deletion event
202 * @param user_data unused
66 */ 203 */
67void 204void
68GNUNET_GNS_GTK_quit_cb (GObject * object, gpointer user_data) 205GNUNET_GNS_GTK_main_window_delete_event_cb (GtkWidget *widget,
206 GdkEvent *event,
207 gpointer user_data)
69{ 208{
70 GNUNET_GTK_tray_icon_destroy (); 209 GNUNET_GTK_tray_icon_destroy ();
71 GNUNET_GTK_main_loop_quit (ml); 210 GNUNET_GTK_main_loop_quit (ml);
@@ -76,16 +215,60 @@ GNUNET_GNS_GTK_quit_cb (GObject * object, gpointer user_data)
76/** 215/**
77 * Actual main function run right after GNUnet's scheduler 216 * Actual main function run right after GNUnet's scheduler
78 * is initialized. Initializes up GTK and Glade. 217 * is initialized. Initializes up GTK and Glade.
218 *
219 * @param cls the 'struct GNUNET_GTK_MainLoop'
220 * @param tc scheduler context
79 */ 221 */
80static void 222static void
81run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 223run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82{ 224{
225 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
83 GtkWidget *main_window; 226 GtkWidget *main_window;
227 char *keyfile;
228 char *label;
84 229
85 ml = cls; 230 ml = cls;
231 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (get_configuration (),
232 "gns",
233 "ZONEKEY",
234 &keyfile))
235 {
236 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
237 _("Option `%s' missing in section `%s'\n"),
238 "ZONEKEY", "gns");
239 return;
240 }
241 zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
242 GNUNET_free (keyfile);
243 keyfile = NULL;
244 if (NULL == zone_pkey)
245 {
246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
247 _("Failed to read or create private zone key\n"));
248 return;
249 }
250 GNUNET_CRYPTO_rsa_key_get_public (zone_pkey,
251 &pub);
252 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &zone);
86 253
254 ns = GNUNET_NAMESTORE_connect (get_configuration ());
255 if (NULL == ns)
256 {
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
258 _("Failed to connect to namestore\n"));
259 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
260 return;
261 }
262 zone_as_string = GNUNET_strdup (GNUNET_h2s_full (&zone));
263 GNUNET_asprintf (&label,
264 "<b>%s</b>",
265 zone_as_string);
266 gtk_label_set_text (GTK_LABEL (get_object ("GNUNET_GNS_GTK_zone_label")),
267 label);
268 GNUNET_free (label);
87 if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL)) 269 if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL))
88 { 270 {
271 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
89 return; 272 return;
90 } 273 }
91 274