diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-12 17:38:42 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-12 17:38:42 +0000 |
commit | 3e7867781a077b5ed972ef3c38f2a76f1b395a3a (patch) | |
tree | 3e0b849291087a1d6f16fdde964430029ce94c34 | |
parent | 8d6d25bf19eaf612b11053f56d3de5db986c733c (diff) | |
download | gnunet-gtk-3e7867781a077b5ed972ef3c38f2a76f1b395a3a.tar.gz gnunet-gtk-3e7867781a077b5ed972ef3c38f2a76f1b395a3a.zip |
- open dialog
-rw-r--r-- | src/gns/gnunet-gns-gtk.c | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/src/gns/gnunet-gns-gtk.c b/src/gns/gnunet-gns-gtk.c index 48879e9c..a9c451f0 100644 --- a/src/gns/gnunet-gns-gtk.c +++ b/src/gns/gnunet-gns-gtk.c | |||
@@ -56,6 +56,12 @@ static struct GNUNET_NAMESTORE_Handle *ns; | |||
56 | */ | 56 | */ |
57 | static char *zone_as_string; | 57 | static char *zone_as_string; |
58 | 58 | ||
59 | /** | ||
60 | * Default directory of zone files as a string. | ||
61 | */ | ||
62 | static char *zonefile_directory; | ||
63 | |||
64 | GtkWidget *main_window; | ||
59 | 65 | ||
60 | /** | 66 | /** |
61 | * Get cfg. | 67 | * Get cfg. |
@@ -124,7 +130,7 @@ GNUNET_GNS_GTK_new_imagemenuitem_activate_cb (GtkMenuItem *menuitem, | |||
124 | } | 130 | } |
125 | 131 | ||
126 | /** | 132 | /** |
127 | * The user selected 'NEW' in the menu. Open a dialog to select | 133 | * The user selected 'OPEN' in the menu. Open a dialog to select |
128 | * a different zonefile (for editing). | 134 | * a different zonefile (for editing). |
129 | * | 135 | * |
130 | * @param checkmenuitem the menu item | 136 | * @param checkmenuitem the menu item |
@@ -134,7 +140,45 @@ void | |||
134 | GNUNET_GNS_GTK_open_imagemenuitem_activate_cb (GtkMenuItem *menuitem, | 140 | GNUNET_GNS_GTK_open_imagemenuitem_activate_cb (GtkMenuItem *menuitem, |
135 | gpointer user_data) | 141 | gpointer user_data) |
136 | { | 142 | { |
137 | GNUNET_break (0); // FIXME, not implemented | 143 | GtkWidget *dialog; |
144 | dialog = gtk_file_chooser_dialog_new ("Open zone file...", | ||
145 | main_window, | ||
146 | GTK_FILE_CHOOSER_ACTION_OPEN, | ||
147 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | ||
148 | GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | ||
149 | NULL); | ||
150 | if (NULL != zonefile_directory) | ||
151 | gtk_file_chooser_set_current_folder (dialog, zonefile_directory); | ||
152 | if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) | ||
153 | { | ||
154 | char *filename; | ||
155 | filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); | ||
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
157 | _("Opening `%s'\n"), filename); | ||
158 | if (NULL != zone_pkey) | ||
159 | { | ||
160 | GNUNET_CRYPTO_rsa_key_free(zone_pkey); | ||
161 | zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file(filename); | ||
162 | if (NULL == zone_pkey) | ||
163 | { | ||
164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
165 | _("Not a valid zone file `%s'\n"), filename); | ||
166 | |||
167 | GtkWidget *err_dialog; | ||
168 | err_dialog = gtk_message_dialog_new (main_window, | ||
169 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
170 | GTK_MESSAGE_ERROR, | ||
171 | GTK_BUTTONS_CLOSE, | ||
172 | _("Error loading file '%s':\n not a valid zone file"), | ||
173 | filename); | ||
174 | gtk_dialog_run (GTK_DIALOG (err_dialog)); | ||
175 | gtk_widget_destroy (err_dialog); | ||
176 | } | ||
177 | //if (zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);) | ||
178 | } | ||
179 | g_free (filename); | ||
180 | } | ||
181 | gtk_widget_destroy (dialog); | ||
138 | } | 182 | } |
139 | 183 | ||
140 | 184 | ||
@@ -175,6 +219,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
175 | GNUNET_CRYPTO_rsa_key_free (zone_pkey); | 219 | GNUNET_CRYPTO_rsa_key_free (zone_pkey); |
176 | zone_pkey = NULL; | 220 | zone_pkey = NULL; |
177 | } | 221 | } |
222 | if (NULL != zonefile_directory) | ||
223 | { | ||
224 | GNUNET_free (zonefile_directory); | ||
225 | zonefile_directory = NULL; | ||
226 | } | ||
178 | } | 227 | } |
179 | 228 | ||
180 | 229 | ||
@@ -223,12 +272,23 @@ static void | |||
223 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 272 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
224 | { | 273 | { |
225 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 274 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
226 | GtkWidget *main_window; | 275 | |
227 | char *keyfile; | 276 | char *keyfile; |
228 | char *label; | 277 | char *label; |
229 | 278 | ||
230 | ml = cls; | 279 | ml = cls; |
231 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (get_configuration (), | 280 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (get_configuration (), |
281 | "namestore", | ||
282 | "ZONEFILE_DIRECTORY", | ||
283 | &zonefile_directory)) | ||
284 | { | ||
285 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
286 | _("Option `%s' missing in section `%s'\n"), | ||
287 | "ZONEFILE_DIRECTORY", "namestore"); | ||
288 | return; | ||
289 | } | ||
290 | |||
291 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (get_configuration (), | ||
232 | "gns", | 292 | "gns", |
233 | "ZONEKEY", | 293 | "ZONEKEY", |
234 | &keyfile)) | 294 | &keyfile)) |
@@ -276,7 +336,7 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
276 | GNUNET_GTK_setup_nls (); | 336 | GNUNET_GTK_setup_nls (); |
277 | /* setup main window */ | 337 | /* setup main window */ |
278 | main_window = GTK_WIDGET (get_object ("GNUNET_GNS_GTK_main_window")); | 338 | main_window = GTK_WIDGET (get_object ("GNUNET_GNS_GTK_main_window")); |
279 | gtk_window_maximize (GTK_WINDOW (main_window)); | 339 | //gtk_window_maximize (GTK_WINDOW (main_window)); |
280 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), | 340 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), |
281 | "gnunet-gtk" /* FIXME: different icon? */ , | 341 | "gnunet-gtk" /* FIXME: different icon? */ , |
282 | "gnunet-gns-gtk"); | 342 | "gnunet-gns-gtk"); |