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