2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5 * Copyright (C) 2008, Hein Ragas <viking@ragas.nl>
6 * Copyright (C) 2010, Rob Norris <rw_norris@hotmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "thumbnails.h"
30 #include "garminsymbols.h"
31 #include "degrees_converters.h"
33 #include "documenters.h"
37 #include <glib/gi18n.h>
43 void a_dialog_msg ( GtkWindow *parent, gint type, const gchar *info, const gchar *extra )
45 GtkWidget *msgbox = gtk_message_dialog_new ( parent, GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK, info, extra );
46 gtk_dialog_run ( GTK_DIALOG(msgbox) );
47 gtk_widget_destroy ( msgbox );
50 gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old )
52 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"),
54 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
60 GtkWidget *latlabel, *lonlabel;
62 gchar *tmp_lat, *tmp_lon;
64 latlabel = gtk_label_new (_("Latitude:"));
65 lat = gtk_entry_new ();
66 tmp_lat = g_strdup_printf ( "%f", old->lat );
67 gtk_entry_set_text ( GTK_ENTRY(lat), tmp_lat );
70 lonlabel = gtk_label_new (_("Longitude:"));
71 lon = gtk_entry_new ();
72 tmp_lon = g_strdup_printf ( "%f", old->lon );
73 gtk_entry_set_text ( GTK_ENTRY(lon), tmp_lon );
76 gtk_widget_show ( latlabel );
77 gtk_widget_show ( lonlabel );
78 gtk_widget_show ( lat );
79 gtk_widget_show ( lon );
81 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0);
82 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lat, FALSE, FALSE, 0);
83 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0);
84 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lon, FALSE, FALSE, 0);
86 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
88 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
90 ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) );
91 ll->lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lon) ) );
92 gtk_widget_destroy ( dialog );
96 gtk_widget_destroy ( dialog );
100 gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old )
102 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"),
104 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
110 GtkWidget *norlabel, *easlabel, *nor, *eas;
111 GtkWidget *zonehbox, *zonespin, *letterentry;
112 gchar *tmp_eas, *tmp_nor;
115 norlabel = gtk_label_new (_("Northing:"));
116 nor = gtk_entry_new ();
117 tmp_nor = g_strdup_printf("%ld", (long) old->northing );
118 gtk_entry_set_text ( GTK_ENTRY(nor), tmp_nor );
121 easlabel = gtk_label_new (_("Easting:"));
122 eas = gtk_entry_new ();
123 tmp_eas = g_strdup_printf("%ld", (long) old->easting );
124 gtk_entry_set_text ( GTK_ENTRY(eas), tmp_eas );
127 zonehbox = gtk_hbox_new ( FALSE, 0 );
128 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 );
129 zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 0 ), 1, 0 );
130 gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 );
131 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 );
132 letterentry = gtk_entry_new ();
133 gtk_entry_set_max_length ( GTK_ENTRY(letterentry), 1 );
134 gtk_entry_set_width_chars ( GTK_ENTRY(letterentry), 2 );
135 tmp_letter[0] = old->letter;
136 tmp_letter[1] = '\0';
137 gtk_entry_set_text ( GTK_ENTRY(letterentry), tmp_letter );
138 gtk_box_pack_start ( GTK_BOX(zonehbox), letterentry, FALSE, FALSE, 5 );
140 gtk_widget_show ( norlabel );
141 gtk_widget_show ( easlabel );
142 gtk_widget_show ( nor );
143 gtk_widget_show ( eas );
145 gtk_widget_show_all ( zonehbox );
147 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), norlabel, FALSE, FALSE, 0);
148 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nor, FALSE, FALSE, 0);
149 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), easlabel, FALSE, FALSE, 0);
150 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), eas, FALSE, FALSE, 0);
151 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zonehbox, FALSE, FALSE, 0);
153 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
155 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
158 utm->northing = atof ( gtk_entry_get_text ( GTK_ENTRY(nor) ) );
159 utm->easting = atof ( gtk_entry_get_text ( GTK_ENTRY(eas) ) );
160 utm->zone = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(zonespin) );
161 letter = gtk_entry_get_text ( GTK_ENTRY(letterentry) );
163 utm->letter = toupper(*letter);
164 gtk_widget_destroy ( dialog );
168 gtk_widget_destroy ( dialog );
172 void a_dialog_response_accept ( GtkDialog *dialog )
174 gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT );
177 static void symbol_entry_changed_cb(GtkWidget *combo, GtkListStore *store)
182 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter))
185 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
186 /* Note: symm is NULL when "(none)" is select (first cell is empty) */
187 gtk_widget_set_tooltip_text(combo, sym);
191 /* todo: less on this side, like add track */
192 gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *wp, GHashTable *waypoints, VikCoordMode coord_mode )
194 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"),
196 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
203 GtkWidget *latlabel, *lonlabel, *namelabel, *latentry, *lonentry, *altentry, *altlabel, *nameentry=NULL, *commentlabel,
204 *commententry, *imagelabel, *imageentry, *symbollabel, *symbolentry;
210 gchar *lat, *lon, *alt;
212 vik_coord_to_latlon ( &(wp->coord), &ll );
214 lat = g_strdup_printf ( "%f", ll.lat );
215 lon = g_strdup_printf ( "%f", ll.lon );
216 vik_units_height_t height_units = a_vik_get_units_height ();
217 switch (height_units) {
218 case VIK_UNITS_HEIGHT_METRES:
219 alt = g_strdup_printf ( "%f", wp->altitude );
221 case VIK_UNITS_HEIGHT_FEET:
222 alt = g_strdup_printf ( "%f", VIK_METERS_TO_FEET(wp->altitude) );
225 alt = g_strdup_printf ( "%f", wp->altitude );
226 g_critical("Houston, we've had a problem. height=%d", height_units);
231 namelabel = gtk_label_new (_("Name:"));
232 nameentry = gtk_entry_new ();
234 gtk_entry_set_text( GTK_ENTRY(nameentry), *dest );
238 g_signal_connect_swapped ( nameentry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
239 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), namelabel, FALSE, FALSE, 0);
240 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nameentry, FALSE, FALSE, 0);
243 latlabel = gtk_label_new (_("Latitude:"));
244 latentry = gtk_entry_new ();
245 gtk_entry_set_text ( GTK_ENTRY(latentry), lat );
248 lonlabel = gtk_label_new (_("Longitude:"));
249 lonentry = gtk_entry_new ();
250 gtk_entry_set_text ( GTK_ENTRY(lonentry), lon );
253 altlabel = gtk_label_new (_("Altitude:"));
254 altentry = gtk_entry_new ();
255 gtk_entry_set_text ( GTK_ENTRY(altentry), alt );
258 commentlabel = gtk_label_new (_("Comment:"));
259 commententry = gtk_entry_new ();
261 cmt = a_vik_goto_get_search_string_for_this_place(VIK_WINDOW(parent));
263 gtk_entry_set_text(GTK_ENTRY(commententry), cmt);
265 imagelabel = gtk_label_new (_("Image:"));
266 imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN);
270 symbollabel = gtk_label_new (_("Symbol:"));
273 store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING);
274 symbolentry = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
275 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(symbolentry), 6);
277 g_signal_connect(symbolentry, "changed", G_CALLBACK(symbol_entry_changed_cb), store);
278 gtk_list_store_append (store, &iter);
279 gtk_list_store_set (store, &iter, 0, NULL, 1, NULL, 2, _("(none)"), -1);
280 a_populate_sym_list(store);
282 r = gtk_cell_renderer_pixbuf_new ();
283 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE);
284 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "pixbuf", 1, NULL);
286 r = gtk_cell_renderer_text_new ();
287 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE);
288 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "text", 2, NULL);
290 if ( dest == NULL && wp->symbol ) {
293 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)) {
294 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
295 if (sym && !strcmp(sym, wp->symbol)) {
302 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter);
306 if ( dest == NULL && wp->comment )
307 gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment );
309 if ( dest == NULL && wp->image )
310 vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image );
313 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0);
314 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latentry, FALSE, FALSE, 0);
315 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0);
316 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonentry, FALSE, FALSE, 0);
317 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altlabel, FALSE, FALSE, 0);
318 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altentry, FALSE, FALSE, 0);
319 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commentlabel, FALSE, FALSE, 0);
320 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commententry, FALSE, FALSE, 0);
321 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imagelabel, FALSE, FALSE, 0);
322 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imageentry, FALSE, FALSE, 0);
323 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), symbollabel, FALSE, FALSE, 0);
324 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(symbolentry), FALSE, FALSE, 0);
326 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
328 gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
330 while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
334 const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(nameentry) );
335 if ( strlen(constname) == 0 ) /* TODO: other checks (isalpha or whatever ) */
336 a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") );
338 gchar *name = g_strdup ( constname );
340 if ( g_hash_table_lookup ( waypoints, name ) && !a_dialog_overwrite ( parent, _("The waypoint \"%s\" exists, do you want to overwrite it?"), name ) )
346 ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) );
347 ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) );
348 vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll );
349 // Always store in metres
350 switch (height_units) {
351 case VIK_UNITS_HEIGHT_METRES:
352 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
354 case VIK_UNITS_HEIGHT_FEET:
355 wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ));
358 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
359 g_critical("Houston, we've had a problem. height=%d", height_units);
361 vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) );
362 vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) );
363 if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) )
364 a_thumbnails_create ( wp->image );
367 GtkTreeIter iter, first;
368 gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first );
369 if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) {
370 vik_waypoint_set_symbol ( wp, NULL );
373 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
374 vik_waypoint_set_symbol ( wp, sym );
379 gtk_widget_destroy ( dialog );
382 } /* else (valid name) */
386 ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) );
387 ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) );
388 vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll );
389 switch (height_units) {
390 case VIK_UNITS_HEIGHT_METRES:
391 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
393 case VIK_UNITS_HEIGHT_FEET:
394 wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ));
397 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
398 g_critical("Houston, we've had a problem. height=%d", height_units);
400 if ( (! wp->comment) || strcmp ( wp->comment, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ) != 0 )
401 vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) );
402 if ( (! wp->image) || strcmp ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY ( imageentry ) ) ) != 0 )
404 vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) );
405 if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) )
406 a_thumbnails_create ( wp->image );
410 GtkTreeIter iter, first;
411 gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first );
412 if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) {
413 vik_waypoint_set_symbol ( wp, NULL );
416 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
417 vik_waypoint_set_symbol ( wp, sym );
422 gtk_widget_destroy ( dialog );
427 gtk_widget_destroy ( dialog );
431 static void get_selected_foreach_func(GtkTreeModel *model,
438 gtk_tree_model_get (model, iter, 0, &name, -1);
439 *list = g_list_prepend(*list, name);
442 GList *a_dialog_select_from_list ( GtkWindow *parent, GHashTable *tracks, GList *track_names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg )
445 GtkCellRenderer *renderer;
448 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
450 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
456 /* When something is selected then OK */
457 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
458 GtkWidget *response_w = NULL;
459 #if GTK_CHECK_VERSION (2, 20, 0)
460 /* Default to not apply - as initially nothing is selected! */
461 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT );
463 GtkWidget *label = gtk_label_new ( msg );
464 GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
466 GList *track_runner = track_names;
469 gtk_list_store_append(store, &iter);
470 gtk_list_store_set(store, &iter, 0, track_runner->data, -1);
471 track_runner = g_list_next(track_runner);
474 view = gtk_tree_view_new();
475 renderer = gtk_cell_renderer_text_new();
476 gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW(view), -1, NULL, renderer, "text", 0, NULL);
477 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
478 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(view), FALSE);
479 gtk_tree_selection_set_mode( gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
480 multiple_selection_allowed ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE );
481 g_object_unref(store);
483 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
484 gtk_widget_show ( label );
485 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), view, FALSE, FALSE, 0);
486 gtk_widget_show ( view );
489 gtk_widget_grab_focus ( response_w );
491 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
494 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
495 gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names);
498 gtk_widget_destroy ( dialog );
501 a_dialog_error_msg(parent, _("Nothing was selected"));
503 gtk_widget_destroy ( dialog );
507 gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *default_name )
509 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Add Track"),
511 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
517 GtkWidget *label = gtk_label_new ( _("Track Name:") );
518 GtkWidget *entry = gtk_entry_new ();
521 gtk_entry_set_text ( GTK_ENTRY(entry), default_name );
523 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
524 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE, FALSE, 0);
526 g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
528 gtk_widget_show ( label );
529 gtk_widget_show ( entry );
531 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
533 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
535 const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) );
536 if ( *constname == '\0' )
537 a_dialog_info_msg ( parent, _("Please enter a name for the track.") );
539 gchar *name = g_strdup ( constname );
541 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) ) ) )
547 gtk_widget_destroy ( dialog );
552 gtk_widget_destroy ( dialog );
556 /* creates a vbox full of labels */
557 GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count )
559 GtkWidget *vbox, *label;
561 vbox = gtk_vbox_new( TRUE, 3 );
563 for ( i = 0; i < label_count; i++ )
565 label = gtk_label_new(NULL);
566 gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) );
567 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, 5 );
572 gboolean a_dialog_overwrite ( GtkWindow *parent, const gchar *message, const gchar *extra )
575 dia = gtk_message_dialog_new ( parent,
576 GTK_DIALOG_DESTROY_WITH_PARENT,
577 GTK_MESSAGE_QUESTION,
581 if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES )
583 gtk_widget_destroy ( dia );
588 gtk_widget_destroy ( dia );
593 static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] )
595 if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(pass_along[2]) ) )
596 gtk_spin_button_set_value (
597 GTK_SPIN_BUTTON(pass_along[GTK_WIDGET(spin) == pass_along[0] ? 1 : 0]),
598 gtk_spin_button_get_value ( spin ) );
601 gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp )
603 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."),
605 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
611 GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck;
612 GtkWidget *pass_along[3];
614 table = gtk_table_new ( 4, 2, FALSE );
615 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 );
617 label = gtk_label_new ( _("Zoom factor (in meters per pixel):") );
618 xlabel = gtk_label_new ( _("X (easting): "));
619 ylabel = gtk_label_new ( _("Y (northing): "));
621 pass_along[0] = xspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *xmpp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 0 ), 1, 8 );
622 pass_along[1] = yspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *ympp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 0 ), 1, 8 );
624 pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") );
625 /* TODO -- same factor */
626 /* samecheck = gtk_check_button_new_with_label ( "Same x/y zoom factor" ); */
628 if ( *xmpp == *ympp )
629 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE );
631 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
632 gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 1, 2 );
633 gtk_table_attach_defaults ( GTK_TABLE(table), xspin, 1, 2, 1, 2 );
634 gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 2, 3 );
635 gtk_table_attach_defaults ( GTK_TABLE(table), yspin, 1, 2, 2, 3 );
636 gtk_table_attach_defaults ( GTK_TABLE(table), samecheck, 0, 2, 3, 4 );
638 gtk_widget_show_all ( table );
640 g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
641 g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
643 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
645 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
647 *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) );
648 *ympp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin) );
649 gtk_widget_destroy ( dialog );
652 gtk_widget_destroy ( dialog );
656 static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] )
658 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1);
661 gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr )
663 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
665 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
671 GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label;
672 GtkWidget *pass_along[1];
674 table = gtk_table_new ( 4, 2, FALSE );
675 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 );
677 label = gtk_label_new (label_text);
679 t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") );
680 t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") );
681 t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") );
682 t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") );
686 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 );
688 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
689 gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 );
690 gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 );
691 gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 );
692 gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 );
693 gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 );
695 gtk_widget_show_all ( table );
697 g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
699 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
701 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
703 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
705 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) {
707 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) {
709 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) {
710 *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
712 gtk_widget_destroy ( dialog );
715 gtk_widget_destroy ( dialog );
719 static void about_url_hook (GtkAboutDialog *about,
723 open_url (GTK_WINDOW(about), link);
726 static void about_email_hook (GtkAboutDialog *about,
730 new_email (GTK_WINDOW(about), email);
733 void a_dialog_about ( GtkWindow *parent )
735 const gchar *program_name = PACKAGE_NAME;
736 const gchar *version = VIKING_VERSION;
737 const gchar *website = VIKING_URL;
738 const gchar *copyright = "2003-2008, Evan Battaglia\n2008-2010, Viking's contributors";
739 const gchar *comments = _("GPS Data and Topo Analyzer, Explorer, and Manager.");
740 const gchar *license = _("This program is free software; you can redistribute it and/or modify "
741 "it under the terms of the GNU General Public License as published by "
742 "the Free Software Foundation; either version 2 of the License, or "
743 "(at your option) any later version."
745 "This program is distributed in the hope that it will be useful, "
746 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
747 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
748 "GNU General Public License for more details."
750 "You should have received a copy of the GNU General Public License "
751 "along with this program; if not, write to the Free Software "
752 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA");
754 gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL);
755 gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
756 gtk_show_about_dialog (parent,
757 /* TODO do not set program-name and correctly set info for g_get_application_name */
758 "program-name", program_name,
761 "comments", comments,
762 "copyright", copyright,
764 "wrap-license", TRUE,
765 /* logo automatically retrieved via gtk_window_get_default_icon_list */
767 "documenters", DOCUMENTERS,
768 "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
772 gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_map, gchar *zoom_list[], gint default_zoom, gint *selected_map, gint *selected_zoom)
776 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 );
777 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
778 GtkWidget *response_w = NULL;
779 #if GTK_CHECK_VERSION (2, 20, 0)
780 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
782 GtkWidget *map_label = gtk_label_new(_("Map type:"));
783 GtkComboBox *map_combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
784 for (s = mapnames; *s; s++)
785 gtk_combo_box_append_text(map_combo, *s);
786 gtk_combo_box_set_active (map_combo, default_map);
787 GtkWidget *zoom_label = gtk_label_new(_("Zoom level:"));
788 GtkComboBox *zoom_combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
789 for (s = zoom_list; *s; s++)
790 gtk_combo_box_append_text(zoom_combo, *s);
791 gtk_combo_box_set_active (zoom_combo, default_zoom);
793 GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE));
794 gtk_table_attach_defaults(box, GTK_WIDGET(map_label), 0, 1, 0, 1);
795 gtk_table_attach_defaults(box, GTK_WIDGET(map_combo), 1, 2, 0, 1);
796 gtk_table_attach_defaults(box, GTK_WIDGET(zoom_label), 0, 1, 1, 2);
797 gtk_table_attach_defaults(box, GTK_WIDGET(zoom_combo), 1, 2, 1, 2);
799 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(box), FALSE, FALSE, 5 );
802 gtk_widget_grab_focus ( response_w );
804 gtk_widget_show_all ( dialog );
805 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
806 gtk_widget_destroy(dialog);
810 *selected_map = gtk_combo_box_get_active(map_combo);
811 *selected_zoom = gtk_combo_box_get_active(zoom_combo);
813 gtk_widget_destroy(dialog);
818 * Display a dialog presenting the license of a map.
819 * Allow to read the license by launching a web browser.
821 void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url)
823 GtkWidget *dialog = gtk_message_dialog_new (parent,
824 GTK_DIALOG_DESTROY_WITH_PARENT,
827 _("The map data is licensed: %s."),
829 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
830 _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>.\n"
831 "Please, read the license before continuing."),
833 #define RESPONSE_OPEN_LICENSE 600
835 gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE);
839 response = gtk_dialog_run (GTK_DIALOG (dialog));
840 if (response == RESPONSE_OPEN_LICENSE) {
841 open_url (parent, url);
843 } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK);
844 gtk_widget_destroy (dialog);