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