]> git.street.me.uk Git - andy/viking.git/blame - src/dialog.c
Remove dependencies to gob2
[andy/viking.git] / src / dialog.c
CommitLineData
50a14534
EB
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
4c77d5e0
GB
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
50a14534
EB
26#include "viking.h"
27#include "thumbnails.h"
acaf7113 28#include "garminsymbols.h"
dfad9456 29#include "degrees_converters.h"
e8947958 30#include "authors.h"
014128f6 31#include "googlesearch.h"
85beadba 32#include "util.h"
50a14534 33
4c77d5e0
GB
34#include <glib/gi18n.h>
35
50a14534
EB
36#include <stdlib.h>
37#include <string.h>
38#include <ctype.h>
39
40void a_dialog_msg ( GtkWindow *parent, gint type, const gchar *info, const gchar *extra )
41{
42 GtkWidget *msgbox = gtk_message_dialog_new ( parent, GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK, info, extra );
43 gtk_dialog_run ( GTK_DIALOG(msgbox) );
44 gtk_widget_destroy ( msgbox );
45}
46
47gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old )
48{
7760b0cf 49 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"),
50a14534
EB
50 parent,
51 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
52 GTK_STOCK_CANCEL,
53 GTK_RESPONSE_REJECT,
54 GTK_STOCK_OK,
55 GTK_RESPONSE_ACCEPT,
56 NULL);
57 GtkWidget *latlabel, *lonlabel;
58 GtkWidget *lat, *lon;
59 gchar *tmp_lat, *tmp_lon;
60
7760b0cf 61 latlabel = gtk_label_new (_("Latitude:"));
50a14534
EB
62 lat = gtk_entry_new ();
63 tmp_lat = g_strdup_printf ( "%f", old->lat );
64 gtk_entry_set_text ( GTK_ENTRY(lat), tmp_lat );
65 g_free ( tmp_lat );
66
7760b0cf 67 lonlabel = gtk_label_new (_("Longitude:"));
50a14534
EB
68 lon = gtk_entry_new ();
69 tmp_lon = g_strdup_printf ( "%f", old->lon );
70 gtk_entry_set_text ( GTK_ENTRY(lon), tmp_lon );
71 g_free ( tmp_lon );
72
73 gtk_widget_show ( latlabel );
74 gtk_widget_show ( lonlabel );
75 gtk_widget_show ( lat );
76 gtk_widget_show ( lon );
77
78 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0);
79 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lat, FALSE, FALSE, 0);
80 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0);
81 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lon, FALSE, FALSE, 0);
82
83 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
84 {
dfad9456
GB
85 ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) );
86 ll->lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lon) ) );
50a14534
EB
87 gtk_widget_destroy ( dialog );
88 return TRUE;
89 }
90
91 gtk_widget_destroy ( dialog );
92 return FALSE;
93}
94
95gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old )
96{
7760b0cf 97 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"),
50a14534
EB
98 parent,
99 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
100 GTK_STOCK_CANCEL,
101 GTK_RESPONSE_REJECT,
102 GTK_STOCK_OK,
103 GTK_RESPONSE_ACCEPT,
104 NULL);
105 GtkWidget *norlabel, *easlabel, *nor, *eas;
106 GtkWidget *zonehbox, *zonespin, *letterentry;
107 gchar *tmp_eas, *tmp_nor;
108 gchar tmp_letter[2];
109
7760b0cf 110 norlabel = gtk_label_new (_("Northing:"));
50a14534
EB
111 nor = gtk_entry_new ();
112 tmp_nor = g_strdup_printf("%ld", (long) old->northing );
113 gtk_entry_set_text ( GTK_ENTRY(nor), tmp_nor );
114 g_free ( tmp_nor );
115
7760b0cf 116 easlabel = gtk_label_new (_("Easting:"));
50a14534
EB
117 eas = gtk_entry_new ();
118 tmp_eas = g_strdup_printf("%ld", (long) old->easting );
119 gtk_entry_set_text ( GTK_ENTRY(eas), tmp_eas );
120 g_free ( tmp_eas );
121
122 zonehbox = gtk_hbox_new ( FALSE, 0 );
7760b0cf 123 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 );
50a14534
EB
124 zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 5 ), 1, 0 );
125 gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 );
7760b0cf 126 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 );
50a14534
EB
127 letterentry = gtk_entry_new ();
128 gtk_entry_set_max_length ( GTK_ENTRY(letterentry), 1 );
129 gtk_entry_set_width_chars ( GTK_ENTRY(letterentry), 2 );
130 tmp_letter[0] = old->letter;
131 tmp_letter[1] = '\0';
132 gtk_entry_set_text ( GTK_ENTRY(letterentry), tmp_letter );
133 gtk_box_pack_start ( GTK_BOX(zonehbox), letterentry, FALSE, FALSE, 5 );
134
135 gtk_widget_show ( norlabel );
136 gtk_widget_show ( easlabel );
137 gtk_widget_show ( nor );
138 gtk_widget_show ( eas );
139
140 gtk_widget_show_all ( zonehbox );
141
142 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), norlabel, FALSE, FALSE, 0);
143 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nor, FALSE, FALSE, 0);
144 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), easlabel, FALSE, FALSE, 0);
145 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), eas, FALSE, FALSE, 0);
146 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zonehbox, FALSE, FALSE, 0);
147
148 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
149 {
150 const gchar *letter;
151 utm->northing = atof ( gtk_entry_get_text ( GTK_ENTRY(nor) ) );
152 utm->easting = atof ( gtk_entry_get_text ( GTK_ENTRY(eas) ) );
153 utm->zone = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(zonespin) );
154 letter = gtk_entry_get_text ( GTK_ENTRY(letterentry) );
155 if (*letter)
156 utm->letter = toupper(*letter);
157 gtk_widget_destroy ( dialog );
158 return TRUE;
159 }
160
161 gtk_widget_destroy ( dialog );
162 return FALSE;
163}
164
165void a_dialog_response_accept ( GtkDialog *dialog )
166{
167 gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT );
168}
169
170/* todo: less on this side, like add track */
171gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *wp, GHashTable *waypoints, VikCoordMode coord_mode )
172{
7760b0cf 173 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Create"),
50a14534
EB
174 parent,
175 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
176 GTK_STOCK_CANCEL,
177 GTK_RESPONSE_REJECT,
178 GTK_STOCK_OK,
179 GTK_RESPONSE_ACCEPT,
180 NULL);
181 struct LatLon ll;
e1e6f7fa 182 GtkWidget *latlabel, *lonlabel, *namelabel, *latentry, *lonentry, *altentry, *altlabel, *nameentry=NULL, *commentlabel,
acaf7113
AF
183 *commententry, *imagelabel, *imageentry, *symbollabel, *symbolentry;
184 GtkListStore *store;
185
186
187
50a14534
EB
188
189 gchar *lat, *lon, *alt;
190
191 vik_coord_to_latlon ( &(wp->coord), &ll );
192
193 lat = g_strdup_printf ( "%f", ll.lat );
194 lon = g_strdup_printf ( "%f", ll.lon );
195 alt = g_strdup_printf ( "%f", wp->altitude );
196
197 if ( dest != NULL )
198 {
7760b0cf 199 namelabel = gtk_label_new (_("Name:"));
50a14534 200 nameentry = gtk_entry_new ();
a8fe53f8
EB
201 if ( *dest ) {
202 gtk_entry_set_text( GTK_ENTRY(nameentry), *dest );
203 g_free ( *dest );
204 *dest = NULL;
205 }
50a14534
EB
206 g_signal_connect_swapped ( nameentry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
207 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), namelabel, FALSE, FALSE, 0);
208 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nameentry, FALSE, FALSE, 0);
209 }
210
7760b0cf 211 latlabel = gtk_label_new (_("Latitude:"));
50a14534
EB
212 latentry = gtk_entry_new ();
213 gtk_entry_set_text ( GTK_ENTRY(latentry), lat );
214 g_free ( lat );
215
7760b0cf 216 lonlabel = gtk_label_new (_("Longitude:"));
50a14534
EB
217 lonentry = gtk_entry_new ();
218 gtk_entry_set_text ( GTK_ENTRY(lonentry), lon );
219 g_free ( lon );
220
7760b0cf 221 altlabel = gtk_label_new (_("Altitude:"));
50a14534
EB
222 altentry = gtk_entry_new ();
223 gtk_entry_set_text ( GTK_ENTRY(altentry), alt );
224 g_free ( alt );
225
7760b0cf 226 commentlabel = gtk_label_new (_("Comment:"));
50a14534 227 commententry = gtk_entry_new ();
8ece78c0 228 gchar *cmt = a_googlesearch_get_search_string_for_this_place(VIK_WINDOW(parent));
014128f6
QT
229 if (cmt)
230 gtk_entry_set_text(GTK_ENTRY(commententry), cmt);
50a14534 231
7760b0cf 232 imagelabel = gtk_label_new (_("Image:"));
50a14534
EB
233 imageentry = vik_file_entry_new ();
234
acaf7113
AF
235 {
236 GtkCellRenderer *r;
7760b0cf 237 symbollabel = gtk_label_new (_("Symbol:"));
acaf7113
AF
238 GtkTreeIter iter;
239
ea3933fc 240 store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING);
acaf7113 241 symbolentry = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
886031df 242 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(symbolentry), 3);
acaf7113 243 gtk_list_store_append (store, &iter);
7760b0cf 244 gtk_list_store_set (store, &iter, 0, NULL, 1, NULL, 2, _("(none)"), -1);
acaf7113
AF
245 a_populate_sym_list(store);
246
247 r = gtk_cell_renderer_pixbuf_new ();
248 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE);
249 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "pixbuf", 1, NULL);
250
ea3933fc
EB
251 r = gtk_cell_renderer_text_new ();
252 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE);
253 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "text", 2, NULL);
254
acaf7113
AF
255 if ( dest == NULL && wp->symbol ) {
256 gboolean ok;
257 gchar *sym;
258 for (ok = gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &iter ); ok; ok = gtk_tree_model_iter_next ( GTK_TREE_MODEL(store), &iter)) {
259 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
ea3933fc 260 if (sym && !strcmp(sym, wp->symbol)) {
acaf7113
AF
261 g_free(sym);
262 break;
263 } else {
264 g_free(sym);
265 }
266 }
886031df 267 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter);
acaf7113
AF
268 }
269 }
270
50a14534
EB
271 if ( dest == NULL && wp->comment )
272 gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment );
273
274 if ( dest == NULL && wp->image )
275 vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image );
276
50a14534
EB
277
278 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0);
279 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latentry, FALSE, FALSE, 0);
280 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0);
281 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonentry, FALSE, FALSE, 0);
282 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altlabel, FALSE, FALSE, 0);
283 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altentry, FALSE, FALSE, 0);
284 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commentlabel, FALSE, FALSE, 0);
285 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commententry, FALSE, FALSE, 0);
286 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imagelabel, FALSE, FALSE, 0);
287 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imageentry, FALSE, FALSE, 0);
acaf7113
AF
288 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), symbollabel, FALSE, FALSE, 0);
289 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(symbolentry), FALSE, FALSE, 0);
50a14534
EB
290
291 gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
acaf7113 292
50a14534
EB
293 while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
294 {
295 if ( dest )
296 {
297 const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(nameentry) );
298 if ( strlen(constname) == 0 ) /* TODO: other checks (isalpha or whatever ) */
7760b0cf 299 a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") );
50a14534 300 else {
50a14534
EB
301 gchar *name = g_strdup ( constname );
302
7760b0cf 303 if ( g_hash_table_lookup ( waypoints, name ) && !a_dialog_overwrite ( parent, _("The waypoint \"%s\" exists, do you want to overwrite it?"), name ) )
50a14534
EB
304 g_free ( name );
305 else
306 {
307 /* Do It */
308 *dest = name;
dfad9456
GB
309 ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) );
310 ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) );
50a14534
EB
311 vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll );
312 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
313 vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) );
314 vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) );
315 if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) )
316 a_thumbnails_create ( wp->image );
acaf7113
AF
317
318 {
319 GtkTreeIter iter, first;
320 gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first );
886031df 321 if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) {
acaf7113
AF
322 vik_waypoint_set_symbol ( wp, NULL );
323 } else {
324 gchar *sym;
325 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
326 vik_waypoint_set_symbol ( wp, sym );
327 g_free(sym);
328 }
329 }
330
50a14534
EB
331 gtk_widget_destroy ( dialog );
332 return TRUE;
333 }
334 } /* else (valid name) */
335 }
336 else
337 {
dfad9456
GB
338 ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) );
339 ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) );
50a14534
EB
340 vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll );
341 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
342 if ( (! wp->comment) || strcmp ( wp->comment, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ) != 0 )
343 vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) );
344 if ( (! wp->image) || strcmp ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY ( imageentry ) ) ) != 0 )
345 {
346 vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) );
347 if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) )
348 a_thumbnails_create ( wp->image );
349 }
350
acaf7113
AF
351 {
352 GtkTreeIter iter, first;
353 gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first );
886031df 354 if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) {
acaf7113
AF
355 vik_waypoint_set_symbol ( wp, NULL );
356 } else {
357 gchar *sym;
358 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
359 vik_waypoint_set_symbol ( wp, sym );
360 g_free(sym);
361 }
362 }
363
50a14534
EB
364 gtk_widget_destroy ( dialog );
365
366 return TRUE;
367 }
368 }
369 gtk_widget_destroy ( dialog );
370 return FALSE;
371}
372
373gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks )
374{
7760b0cf 375 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Add Track"),
50a14534
EB
376 parent,
377 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
378 GTK_STOCK_CANCEL,
379 GTK_RESPONSE_REJECT,
380 GTK_STOCK_OK,
381 GTK_RESPONSE_ACCEPT,
382 NULL);
7760b0cf 383 GtkWidget *label = gtk_label_new ( _("Track Name:") );
50a14534
EB
384 GtkWidget *entry = gtk_entry_new ();
385
386 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
387 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE, FALSE, 0);
388
389 g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
390
391 gtk_widget_show ( label );
392 gtk_widget_show ( entry );
393
394 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
395 {
396 const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) );
397 if ( *constname == '\0' )
7760b0cf 398 a_dialog_info_msg ( parent, _("Please enter a name for the track.") );
50a14534
EB
399 else {
400 gchar *name = g_strdup ( constname );
50a14534 401
7760b0cf 402 if ( g_hash_table_lookup( tracks, name ) && !a_dialog_overwrite ( parent, _("The track \"%s\" exists, do you want to overwrite it?"), gtk_entry_get_text ( GTK_ENTRY(entry) ) ) )
50a14534
EB
403 {
404 g_free ( name );
405 }
406 else
407 {
408 gtk_widget_destroy ( dialog );
409 return name;
410 }
411 }
412 }
413 gtk_widget_destroy ( dialog );
414 return NULL;
415}
416
417/* creates a vbox full of labels */
418GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count )
419{
420 GtkWidget *vbox, *label;
421 int i;
422 vbox = gtk_vbox_new( TRUE, 3 );
423
424 for ( i = 0; i < label_count; i++ )
425 {
426 label = gtk_label_new(NULL);
4c77d5e0 427 gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) );
50a14534
EB
428 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, 5 );
429 }
430 return vbox;
431}
432
433gboolean a_dialog_overwrite ( GtkWindow *parent, const gchar *message, const gchar *extra )
434{
435 GtkWidget *dia;
436 dia = gtk_message_dialog_new ( parent,
437 GTK_DIALOG_DESTROY_WITH_PARENT,
438 GTK_MESSAGE_QUESTION,
439 GTK_BUTTONS_YES_NO,
440 message, extra );
441
442 if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES )
443 {
444 gtk_widget_destroy ( dia );
445 return TRUE;
446 }
447 else
448 {
449 gtk_widget_destroy ( dia );
450 return FALSE;
451 }
452}
453
454static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] )
455{
456 if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(pass_along[2]) ) )
457 gtk_spin_button_set_value (
458 GTK_SPIN_BUTTON(pass_along[GTK_WIDGET(spin) == pass_along[0] ? 1 : 0]),
459 gtk_spin_button_get_value ( spin ) );
460}
461
462gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp )
463{
7760b0cf 464 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."),
50a14534
EB
465 parent,
466 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
467 GTK_STOCK_CANCEL,
468 GTK_RESPONSE_REJECT,
469 GTK_STOCK_OK,
470 GTK_RESPONSE_ACCEPT,
471 NULL);
472 GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck;
473 GtkWidget *pass_along[3];
474
475 table = gtk_table_new ( 4, 2, FALSE );
476 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 );
477
7760b0cf
JJ
478 label = gtk_label_new ( _("Zoom factor (in meters per pixel:") );
479 xlabel = gtk_label_new ( _("X (easting): "));
480 ylabel = gtk_label_new ( _("Y (northing): "));
50a14534
EB
481
482 pass_along[0] = xspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *xmpp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 );
483 pass_along[1] = yspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *ympp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 );
484
7760b0cf 485 pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") );
50a14534
EB
486 /* TODO -- same factor */
487 /* samecheck = gtk_check_button_new_with_label ( "Same x/y zoom factor" ); */
488
489 if ( *xmpp == *ympp )
490 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE );
491
492 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
493 gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 1, 2 );
494 gtk_table_attach_defaults ( GTK_TABLE(table), xspin, 1, 2, 1, 2 );
495 gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 2, 3 );
496 gtk_table_attach_defaults ( GTK_TABLE(table), yspin, 1, 2, 2, 3 );
497 gtk_table_attach_defaults ( GTK_TABLE(table), samecheck, 0, 2, 3, 4 );
498
499 gtk_widget_show_all ( table );
500
501 g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
502 g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
503
504 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
505 {
506 *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) );
507 *ympp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin) );
508 gtk_widget_destroy ( dialog );
509 return TRUE;
510 }
511 gtk_widget_destroy ( dialog );
512 return FALSE;
513}
111fa174
AF
514
515static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] )
516{
517 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1);
518}
519
520gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr )
521{
522 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
523 parent,
524 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
525 GTK_STOCK_CANCEL,
526 GTK_RESPONSE_REJECT,
527 GTK_STOCK_OK,
528 GTK_RESPONSE_ACCEPT,
529 NULL);
530 GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label;
531 GtkWidget *pass_along[1];
532
533 table = gtk_table_new ( 4, 2, FALSE );
534 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 );
535
536 label = gtk_label_new (label_text);
537
7760b0cf
JJ
538 t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") );
539 t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") );
540 t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") );
541 t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") );
111fa174
AF
542
543 pass_along[0] = t4;
544
545 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 5 ), 1, 0 );
546
547 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
548 gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 );
549 gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 );
550 gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 );
551 gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 );
552 gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 );
553
554 gtk_widget_show_all ( table );
555
556 g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
557
558 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
559 {
560 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
561 *thr = 1;
562 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) {
563 *thr = 60;
564 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) {
565 *thr = 60 * 24;
566 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) {
567 *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
568 }
569 gtk_widget_destroy ( dialog );
570 return TRUE;
571 }
572 gtk_widget_destroy ( dialog );
573 return FALSE;
574}
d0a5f320 575
3530c91e
GB
576static void about_url_hook (GtkAboutDialog *about,
577 const gchar *link,
578 gpointer data)
85beadba 579{
3530c91e
GB
580 open_url (GTK_WINDOW(about), link);
581}
582
583static void about_email_hook (GtkAboutDialog *about,
584 const gchar *email,
585 gpointer data)
586{
587 new_email (GTK_WINDOW(about), email);
85beadba 588}
d0a5f320
AF
589
590void a_dialog_about ( GtkWindow *parent )
591{
85beadba
GB
592 const gchar *program_name = PACKAGE_NAME;
593 const gchar *version = VIKING_VERSION;
594 const gchar *website = VIKING_URL;
595 const gchar *copyright = "2003-2008, Evan Battaglia";
596 const gchar *comments = _("GPS Data and Topo Analyzer, Explorer, and Manager.");
597 const gchar *license = _("This program is free software; you can redistribute it and/or modify "
d0a5f320
AF
598 "it under the terms of the GNU General Public License as published by "
599 "the Free Software Foundation; either version 2 of the License, or "
600 "(at your option) any later version."
601 "\n\n"
602 "This program is distributed in the hope that it will be useful, "
603 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
604 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
605 "GNU General Public License for more details."
606 "\n\n"
607 "You should have received a copy of the GNU General Public License "
608 "along with this program; if not, write to the Free Software "
85beadba
GB
609 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA");
610
3530c91e
GB
611 gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL);
612 gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
85beadba
GB
613 gtk_show_about_dialog (parent,
614 /* TODO do not set program-name and correctly set info for g_get_application_name */
615 "program-name", program_name,
616 "version", version,
617 "website", website,
618 "comments", comments,
619 "copyright", copyright,
620 "license", license,
621 "wrap-license", TRUE,
622 /* logo automatically retrieved via gtk_window_get_default_icon_list */
623 "authors", AUTHORS,
624 NULL);
d0a5f320 625}
7114e879
QT
626
627gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_map, gchar *zoom_list[], gint default_zoom, gint *selected_map, gint *selected_zoom)
628{
629 gchar **s;
630
7760b0cf 631 GtkWidget *dialog = gtk_dialog_new_with_buttons ( _("Download along track"), parent, 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL );
7114e879 632
7760b0cf 633 GtkWidget *map_label = gtk_label_new(_("Map type:"));
8ece78c0 634 GtkComboBox *map_combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
7114e879
QT
635 for (s = mapnames; *s; s++)
636 gtk_combo_box_append_text(map_combo, *s);
637 gtk_combo_box_set_active (map_combo, default_map);
7760b0cf 638 GtkWidget *zoom_label = gtk_label_new(_("Zoom level:"));
8ece78c0 639 GtkComboBox *zoom_combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
7114e879
QT
640 for (s = zoom_list; *s; s++)
641 gtk_combo_box_append_text(zoom_combo, *s);
642 gtk_combo_box_set_active (zoom_combo, default_zoom);
643
644 GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE));
645 gtk_table_attach_defaults(box, GTK_WIDGET(map_label), 0, 1, 0, 1);
646 gtk_table_attach_defaults(box, GTK_WIDGET(map_combo), 1, 2, 0, 1);
647 gtk_table_attach_defaults(box, GTK_WIDGET(zoom_label), 0, 1, 1, 2);
648 gtk_table_attach_defaults(box, GTK_WIDGET(zoom_combo), 1, 2, 1, 2);
649
650 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(box), FALSE, FALSE, 5 );
651
652 gtk_widget_show_all ( dialog );
653 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
654 gtk_widget_destroy(dialog);
655 return FALSE;
656 }
657
658 *selected_map = gtk_combo_box_get_active(map_combo);
659 *selected_zoom = gtk_combo_box_get_active(zoom_combo);
660
661 gtk_widget_destroy(dialog);
662 return TRUE;
663}