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