]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
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> | |
7 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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 | |
21 | * | |
22 | */ | |
23 | ||
24 | #ifdef HAVE_CONFIG_H | |
25 | #include "config.h" | |
26 | #endif | |
27 | ||
28 | #include "viking.h" | |
29 | #include "thumbnails.h" | |
30 | #include "garminsymbols.h" | |
31 | #include "degrees_converters.h" | |
32 | #include "authors.h" | |
33 | #include "documenters.h" | |
34 | #include "vikgoto.h" | |
35 | #include "util.h" | |
36 | ||
37 | #include <glib/gi18n.h> | |
38 | ||
39 | #include <stdlib.h> | |
40 | #include <string.h> | |
41 | #include <ctype.h> | |
42 | #include <time.h> | |
43 | ||
44 | void a_dialog_msg ( GtkWindow *parent, gint type, const gchar *info, const gchar *extra ) | |
45 | { | |
46 | GtkWidget *msgbox = gtk_message_dialog_new ( parent, GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK, info, extra ); | |
47 | gtk_dialog_run ( GTK_DIALOG(msgbox) ); | |
48 | gtk_widget_destroy ( msgbox ); | |
49 | } | |
50 | ||
51 | gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old ) | |
52 | { | |
53 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"), | |
54 | parent, | |
55 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
56 | GTK_STOCK_CANCEL, | |
57 | GTK_RESPONSE_REJECT, | |
58 | GTK_STOCK_OK, | |
59 | GTK_RESPONSE_ACCEPT, | |
60 | NULL); | |
61 | GtkWidget *latlabel, *lonlabel; | |
62 | GtkWidget *lat, *lon; | |
63 | gchar *tmp_lat, *tmp_lon; | |
64 | ||
65 | latlabel = gtk_label_new (_("Latitude:")); | |
66 | lat = gtk_entry_new (); | |
67 | tmp_lat = g_strdup_printf ( "%f", old->lat ); | |
68 | gtk_entry_set_text ( GTK_ENTRY(lat), tmp_lat ); | |
69 | g_free ( tmp_lat ); | |
70 | ||
71 | lonlabel = gtk_label_new (_("Longitude:")); | |
72 | lon = gtk_entry_new (); | |
73 | tmp_lon = g_strdup_printf ( "%f", old->lon ); | |
74 | gtk_entry_set_text ( GTK_ENTRY(lon), tmp_lon ); | |
75 | g_free ( tmp_lon ); | |
76 | ||
77 | gtk_widget_show ( latlabel ); | |
78 | gtk_widget_show ( lonlabel ); | |
79 | gtk_widget_show ( lat ); | |
80 | gtk_widget_show ( lon ); | |
81 | ||
82 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), latlabel, FALSE, FALSE, 0); | |
83 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lat, FALSE, FALSE, 0); | |
84 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lonlabel, FALSE, FALSE, 0); | |
85 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lon, FALSE, FALSE, 0); | |
86 | ||
87 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
88 | ||
89 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
90 | { | |
91 | ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) ); | |
92 | ll->lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lon) ) ); | |
93 | gtk_widget_destroy ( dialog ); | |
94 | return TRUE; | |
95 | } | |
96 | ||
97 | gtk_widget_destroy ( dialog ); | |
98 | return FALSE; | |
99 | } | |
100 | ||
101 | gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old ) | |
102 | { | |
103 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"), | |
104 | parent, | |
105 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
106 | GTK_STOCK_CANCEL, | |
107 | GTK_RESPONSE_REJECT, | |
108 | GTK_STOCK_OK, | |
109 | GTK_RESPONSE_ACCEPT, | |
110 | NULL); | |
111 | GtkWidget *norlabel, *easlabel, *nor, *eas; | |
112 | GtkWidget *zonehbox, *zonespin, *letterentry; | |
113 | gchar *tmp_eas, *tmp_nor; | |
114 | gchar tmp_letter[2]; | |
115 | ||
116 | norlabel = gtk_label_new (_("Northing:")); | |
117 | nor = gtk_entry_new (); | |
118 | tmp_nor = g_strdup_printf("%ld", (long) old->northing ); | |
119 | gtk_entry_set_text ( GTK_ENTRY(nor), tmp_nor ); | |
120 | g_free ( tmp_nor ); | |
121 | ||
122 | easlabel = gtk_label_new (_("Easting:")); | |
123 | eas = gtk_entry_new (); | |
124 | tmp_eas = g_strdup_printf("%ld", (long) old->easting ); | |
125 | gtk_entry_set_text ( GTK_ENTRY(eas), tmp_eas ); | |
126 | g_free ( tmp_eas ); | |
127 | ||
128 | zonehbox = gtk_hbox_new ( FALSE, 0 ); | |
129 | gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 ); | |
130 | zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 0 ), 1, 0 ); | |
131 | gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 ); | |
132 | gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 ); | |
133 | letterentry = gtk_entry_new (); | |
134 | gtk_entry_set_max_length ( GTK_ENTRY(letterentry), 1 ); | |
135 | gtk_entry_set_width_chars ( GTK_ENTRY(letterentry), 2 ); | |
136 | tmp_letter[0] = old->letter; | |
137 | tmp_letter[1] = '\0'; | |
138 | gtk_entry_set_text ( GTK_ENTRY(letterentry), tmp_letter ); | |
139 | gtk_box_pack_start ( GTK_BOX(zonehbox), letterentry, FALSE, FALSE, 5 ); | |
140 | ||
141 | gtk_widget_show ( norlabel ); | |
142 | gtk_widget_show ( easlabel ); | |
143 | gtk_widget_show ( nor ); | |
144 | gtk_widget_show ( eas ); | |
145 | ||
146 | gtk_widget_show_all ( zonehbox ); | |
147 | ||
148 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), norlabel, FALSE, FALSE, 0); | |
149 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), nor, FALSE, FALSE, 0); | |
150 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), easlabel, FALSE, FALSE, 0); | |
151 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), eas, FALSE, FALSE, 0); | |
152 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), zonehbox, FALSE, FALSE, 0); | |
153 | ||
154 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
155 | ||
156 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
157 | { | |
158 | const gchar *letter; | |
159 | utm->northing = atof ( gtk_entry_get_text ( GTK_ENTRY(nor) ) ); | |
160 | utm->easting = atof ( gtk_entry_get_text ( GTK_ENTRY(eas) ) ); | |
161 | utm->zone = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(zonespin) ); | |
162 | letter = gtk_entry_get_text ( GTK_ENTRY(letterentry) ); | |
163 | if (*letter) | |
164 | utm->letter = toupper(*letter); | |
165 | gtk_widget_destroy ( dialog ); | |
166 | return TRUE; | |
167 | } | |
168 | ||
169 | gtk_widget_destroy ( dialog ); | |
170 | return FALSE; | |
171 | } | |
172 | ||
173 | void a_dialog_response_accept ( GtkDialog *dialog ) | |
174 | { | |
175 | gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT ); | |
176 | } | |
177 | ||
178 | static void symbol_entry_changed_cb(GtkWidget *combo, GtkListStore *store) | |
179 | { | |
180 | GtkTreeIter iter; | |
181 | gchar *sym; | |
182 | ||
183 | if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) | |
184 | return; | |
185 | ||
186 | gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); | |
187 | /* Note: symm is NULL when "(none)" is select (first cell is empty) */ | |
188 | gtk_widget_set_tooltip_text(combo, sym); | |
189 | g_free(sym); | |
190 | } | |
191 | ||
192 | /* Specify if a new waypoint or not */ | |
193 | /* If a new waypoint then it uses the default_name for the suggested name allowing the user to change it. | |
194 | The name to use is returned | |
195 | */ | |
196 | /* todo: less on this side, like add track */ | |
197 | gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *vtl, VikWaypoint *wp, VikCoordMode coord_mode, gboolean is_new, gboolean *updated ) | |
198 | { | |
199 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"), | |
200 | parent, | |
201 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
202 | GTK_STOCK_CANCEL, | |
203 | GTK_RESPONSE_REJECT, | |
204 | GTK_STOCK_OK, | |
205 | GTK_RESPONSE_ACCEPT, | |
206 | NULL); | |
207 | struct LatLon ll; | |
208 | GtkWidget *latlabel, *lonlabel, *namelabel, *latentry, *lonentry, *altentry, *altlabel, *nameentry=NULL; | |
209 | GtkWidget *commentlabel, *commententry, *descriptionlabel, *descriptionentry, *imagelabel, *imageentry, *symbollabel, *symbolentry; | |
210 | GtkWidget *timelabel = NULL; | |
211 | GtkWidget *timevaluelabel = NULL; // No editing of time allowed ATM | |
212 | GtkListStore *store; | |
213 | ||
214 | gchar *lat, *lon, *alt; | |
215 | ||
216 | vik_coord_to_latlon ( &(wp->coord), &ll ); | |
217 | ||
218 | lat = g_strdup_printf ( "%f", ll.lat ); | |
219 | lon = g_strdup_printf ( "%f", ll.lon ); | |
220 | vik_units_height_t height_units = a_vik_get_units_height (); | |
221 | switch (height_units) { | |
222 | case VIK_UNITS_HEIGHT_METRES: | |
223 | alt = g_strdup_printf ( "%f", wp->altitude ); | |
224 | break; | |
225 | case VIK_UNITS_HEIGHT_FEET: | |
226 | alt = g_strdup_printf ( "%f", VIK_METERS_TO_FEET(wp->altitude) ); | |
227 | break; | |
228 | default: | |
229 | alt = g_strdup_printf ( "%f", wp->altitude ); | |
230 | g_critical("Houston, we've had a problem. height=%d", height_units); | |
231 | } | |
232 | ||
233 | *updated = FALSE; | |
234 | ||
235 | namelabel = gtk_label_new (_("Name:")); | |
236 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), namelabel, FALSE, FALSE, 0); | |
237 | // Name is now always changeable | |
238 | nameentry = gtk_entry_new (); | |
239 | if ( default_name ) | |
240 | gtk_entry_set_text( GTK_ENTRY(nameentry), default_name ); | |
241 | g_signal_connect_swapped ( nameentry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) ); | |
242 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), nameentry, FALSE, FALSE, 0); | |
243 | ||
244 | latlabel = gtk_label_new (_("Latitude:")); | |
245 | latentry = gtk_entry_new (); | |
246 | gtk_entry_set_text ( GTK_ENTRY(latentry), lat ); | |
247 | g_free ( lat ); | |
248 | ||
249 | lonlabel = gtk_label_new (_("Longitude:")); | |
250 | lonentry = gtk_entry_new (); | |
251 | gtk_entry_set_text ( GTK_ENTRY(lonentry), lon ); | |
252 | g_free ( lon ); | |
253 | ||
254 | altlabel = gtk_label_new (_("Altitude:")); | |
255 | altentry = gtk_entry_new (); | |
256 | gtk_entry_set_text ( GTK_ENTRY(altentry), alt ); | |
257 | g_free ( alt ); | |
258 | ||
259 | commentlabel = gtk_label_new (_("Comment:")); | |
260 | commententry = gtk_entry_new (); | |
261 | gchar *cmt = NULL; | |
262 | // Auto put in some kind of 'name' as a comment if one previously 'goto'ed this exact location | |
263 | cmt = a_vik_goto_get_search_string_for_this_place(VIK_WINDOW(parent)); | |
264 | if (cmt) | |
265 | gtk_entry_set_text(GTK_ENTRY(commententry), cmt); | |
266 | ||
267 | descriptionlabel = gtk_label_new (_("Description:")); | |
268 | descriptionentry = gtk_entry_new (); | |
269 | ||
270 | imagelabel = gtk_label_new (_("Image:")); | |
271 | imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN); | |
272 | ||
273 | { | |
274 | GtkCellRenderer *r; | |
275 | symbollabel = gtk_label_new (_("Symbol:")); | |
276 | GtkTreeIter iter; | |
277 | ||
278 | store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING); | |
279 | symbolentry = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); | |
280 | gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(symbolentry), 6); | |
281 | ||
282 | g_signal_connect(symbolentry, "changed", G_CALLBACK(symbol_entry_changed_cb), store); | |
283 | gtk_list_store_append (store, &iter); | |
284 | gtk_list_store_set (store, &iter, 0, NULL, 1, NULL, 2, _("(none)"), -1); | |
285 | a_populate_sym_list(store); | |
286 | ||
287 | r = gtk_cell_renderer_pixbuf_new (); | |
288 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE); | |
289 | gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "pixbuf", 1, NULL); | |
290 | ||
291 | r = gtk_cell_renderer_text_new (); | |
292 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE); | |
293 | gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "text", 2, NULL); | |
294 | ||
295 | if ( !is_new && wp->symbol ) { | |
296 | gboolean ok; | |
297 | gchar *sym; | |
298 | 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)) { | |
299 | gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); | |
300 | if (sym && !strcmp(sym, wp->symbol)) { | |
301 | g_free(sym); | |
302 | break; | |
303 | } else { | |
304 | g_free(sym); | |
305 | } | |
306 | } | |
307 | // Ensure is it a valid symbol in the given symbol set (large vs small) | |
308 | // Not all symbols are available in both | |
309 | // The check prevents a Gtk Critical message | |
310 | if ( iter.stamp ) | |
311 | gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter); | |
312 | } | |
313 | } | |
314 | ||
315 | if ( !is_new && wp->comment ) | |
316 | gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment ); | |
317 | ||
318 | if ( !is_new && wp->description ) | |
319 | gtk_entry_set_text ( GTK_ENTRY(descriptionentry), wp->description ); | |
320 | ||
321 | if ( !is_new && wp->image ) | |
322 | vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image ); | |
323 | ||
324 | if ( !is_new && wp->has_timestamp ) { | |
325 | gchar tmp_str[64]; | |
326 | timelabel = gtk_label_new ( _("Time:") ); | |
327 | timevaluelabel = gtk_label_new ( NULL ); | |
328 | strftime ( tmp_str, sizeof(tmp_str), "%c", localtime(&(wp->timestamp)) ); | |
329 | gtk_label_set_text ( GTK_LABEL(timevaluelabel), tmp_str ); | |
330 | } | |
331 | ||
332 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), latlabel, FALSE, FALSE, 0); | |
333 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), latentry, FALSE, FALSE, 0); | |
334 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lonlabel, FALSE, FALSE, 0); | |
335 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lonentry, FALSE, FALSE, 0); | |
336 | if ( timelabel ) { | |
337 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), timelabel, FALSE, FALSE, 0); | |
338 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), timevaluelabel, FALSE, FALSE, 0); | |
339 | } | |
340 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), altlabel, FALSE, FALSE, 0); | |
341 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), altentry, FALSE, FALSE, 0); | |
342 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), commentlabel, FALSE, FALSE, 0); | |
343 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), commententry, FALSE, FALSE, 0); | |
344 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), descriptionlabel, FALSE, FALSE, 0); | |
345 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), descriptionentry, FALSE, FALSE, 0); | |
346 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), imagelabel, FALSE, FALSE, 0); | |
347 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), imageentry, FALSE, FALSE, 0); | |
348 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), symbollabel, FALSE, FALSE, 0); | |
349 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(symbolentry), FALSE, FALSE, 0); | |
350 | ||
351 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
352 | ||
353 | gtk_widget_show_all ( gtk_dialog_get_content_area(GTK_DIALOG(dialog)) ); | |
354 | ||
355 | if ( !is_new ) { | |
356 | // Shift left<->right to try not to obscure the waypoint. | |
357 | trw_layer_dialog_shift ( vtl, GTK_WINDOW(dialog), &(wp->coord), FALSE ); | |
358 | } | |
359 | ||
360 | while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
361 | { | |
362 | if ( strlen((gchar*)gtk_entry_get_text ( GTK_ENTRY(nameentry) )) == 0 ) /* TODO: other checks (isalpha or whatever ) */ | |
363 | a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") ); | |
364 | else { | |
365 | // NB: No check for unique names - this allows generation of same named entries. | |
366 | gchar *entered_name = g_strdup ( (gchar*)gtk_entry_get_text ( GTK_ENTRY(nameentry) ) ); | |
367 | ||
368 | /* Do It */ | |
369 | ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) ); | |
370 | ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) ); | |
371 | vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll ); | |
372 | // Always store in metres | |
373 | switch (height_units) { | |
374 | case VIK_UNITS_HEIGHT_METRES: | |
375 | wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); | |
376 | break; | |
377 | case VIK_UNITS_HEIGHT_FEET: | |
378 | wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) )); | |
379 | break; | |
380 | default: | |
381 | wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); | |
382 | g_critical("Houston, we've had a problem. height=%d", height_units); | |
383 | } | |
384 | if ( g_strcmp0 ( wp->comment, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ) ) | |
385 | vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ); | |
386 | if ( g_strcmp0 ( wp->description, gtk_entry_get_text ( GTK_ENTRY(descriptionentry) ) ) ) | |
387 | vik_waypoint_set_description ( wp, gtk_entry_get_text ( GTK_ENTRY(descriptionentry) ) ); | |
388 | if ( g_strcmp0 ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ) ) | |
389 | vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ); | |
390 | if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) ) | |
391 | a_thumbnails_create ( wp->image ); | |
392 | ||
393 | GtkTreeIter iter, first; | |
394 | gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first ); | |
395 | if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) { | |
396 | vik_waypoint_set_symbol ( wp, NULL ); | |
397 | } else { | |
398 | gchar *sym; | |
399 | gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); | |
400 | vik_waypoint_set_symbol ( wp, sym ); | |
401 | g_free(sym); | |
402 | } | |
403 | ||
404 | gtk_widget_destroy ( dialog ); | |
405 | if ( is_new ) | |
406 | return entered_name; | |
407 | else { | |
408 | *updated = TRUE; | |
409 | // See if name has been changed | |
410 | if ( g_strcmp0 (default_name, entered_name ) ) | |
411 | return entered_name; | |
412 | else | |
413 | return NULL; | |
414 | } | |
415 | } | |
416 | } | |
417 | gtk_widget_destroy ( dialog ); | |
418 | return NULL; | |
419 | } | |
420 | ||
421 | static void get_selected_foreach_func(GtkTreeModel *model, | |
422 | GtkTreePath *path, | |
423 | GtkTreeIter *iter, | |
424 | gpointer data) | |
425 | { | |
426 | GList **list = data; | |
427 | gchar *name; | |
428 | gtk_tree_model_get (model, iter, 0, &name, -1); | |
429 | *list = g_list_prepend(*list, name); | |
430 | } | |
431 | ||
432 | GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg ) | |
433 | { | |
434 | GtkTreeIter iter; | |
435 | GtkCellRenderer *renderer; | |
436 | GtkWidget *view; | |
437 | ||
438 | GtkWidget *dialog = gtk_dialog_new_with_buttons (title, | |
439 | parent, | |
440 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
441 | GTK_STOCK_CANCEL, | |
442 | GTK_RESPONSE_REJECT, | |
443 | GTK_STOCK_OK, | |
444 | GTK_RESPONSE_ACCEPT, | |
445 | NULL); | |
446 | /* When something is selected then OK */ | |
447 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
448 | GtkWidget *response_w = NULL; | |
449 | #if GTK_CHECK_VERSION (2, 20, 0) | |
450 | /* Default to not apply - as initially nothing is selected! */ | |
451 | response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT ); | |
452 | #endif | |
453 | GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING); | |
454 | ||
455 | GtkWidget *scrolledwindow; | |
456 | ||
457 | GList *runner = names; | |
458 | while (runner) | |
459 | { | |
460 | gtk_list_store_append(store, &iter); | |
461 | gtk_list_store_set(store, &iter, 0, runner->data, -1); | |
462 | runner = g_list_next(runner); | |
463 | } | |
464 | ||
465 | view = gtk_tree_view_new(); | |
466 | renderer = gtk_cell_renderer_text_new(); | |
467 | // Use the column header to display the message text, | |
468 | // this makes the overall widget allocation simple as treeview takes up all the space | |
469 | GtkTreeViewColumn *column; | |
470 | column = gtk_tree_view_column_new_with_attributes (msg, renderer, "text", 0, NULL ); | |
471 | gtk_tree_view_column_set_sort_column_id (column, 0); | |
472 | gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); | |
473 | ||
474 | gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); | |
475 | gtk_tree_selection_set_mode( gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), | |
476 | multiple_selection_allowed ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE ); | |
477 | g_object_unref(store); | |
478 | ||
479 | scrolledwindow = gtk_scrolled_window_new ( NULL, NULL ); | |
480 | gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC ); | |
481 | gtk_container_add ( GTK_CONTAINER(scrolledwindow), view ); | |
482 | ||
483 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), scrolledwindow, TRUE, TRUE, 0 ); | |
484 | // Ensure a reasonable number of items are shown, but let the width be automatically sized | |
485 | gtk_widget_set_size_request ( dialog, -1, 400) ; | |
486 | ||
487 | gtk_widget_show_all ( dialog ); | |
488 | ||
489 | if ( response_w ) | |
490 | gtk_widget_grab_focus ( response_w ); | |
491 | ||
492 | while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) | |
493 | { | |
494 | GList *names = NULL; | |
495 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); | |
496 | gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names); | |
497 | if (names) | |
498 | { | |
499 | gtk_widget_destroy ( dialog ); | |
500 | return (names); | |
501 | } | |
502 | a_dialog_error_msg(parent, _("Nothing was selected")); | |
503 | } | |
504 | gtk_widget_destroy ( dialog ); | |
505 | return NULL; | |
506 | } | |
507 | ||
508 | gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *default_name, gboolean is_route ) | |
509 | { | |
510 | GtkWidget *dialog = gtk_dialog_new_with_buttons ( is_route ? _("Add Route") : _("Add Track"), | |
511 | parent, | |
512 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
513 | GTK_STOCK_CANCEL, | |
514 | GTK_RESPONSE_REJECT, | |
515 | GTK_STOCK_OK, | |
516 | GTK_RESPONSE_ACCEPT, | |
517 | NULL); | |
518 | GtkWidget *label = gtk_label_new ( is_route ? _("Route Name:") : _("Track Name:") ); | |
519 | GtkWidget *entry = gtk_entry_new (); | |
520 | ||
521 | if (default_name) | |
522 | gtk_entry_set_text ( GTK_ENTRY(entry), default_name ); | |
523 | ||
524 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label, FALSE, FALSE, 0); | |
525 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry, FALSE, FALSE, 0); | |
526 | ||
527 | g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) ); | |
528 | ||
529 | gtk_widget_show ( label ); | |
530 | gtk_widget_show ( entry ); | |
531 | ||
532 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
533 | ||
534 | while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) | |
535 | { | |
536 | const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) ); | |
537 | if ( *constname == '\0' ) | |
538 | a_dialog_info_msg ( parent, _("Please enter a name for the track.") ); | |
539 | else { | |
540 | gchar *name = g_strdup ( constname ); | |
541 | gtk_widget_destroy ( dialog ); | |
542 | return name; | |
543 | } | |
544 | } | |
545 | gtk_widget_destroy ( dialog ); | |
546 | return NULL; | |
547 | } | |
548 | ||
549 | /* creates a vbox full of labels */ | |
550 | GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count, gint spacing, gint padding ) | |
551 | { | |
552 | GtkWidget *vbox, *label; | |
553 | int i; | |
554 | vbox = gtk_vbox_new( TRUE, spacing ); | |
555 | ||
556 | for ( i = 0; i < label_count; i++ ) | |
557 | { | |
558 | label = gtk_label_new(NULL); | |
559 | gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) ); | |
560 | gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding ); | |
561 | } | |
562 | return vbox; | |
563 | } | |
564 | ||
565 | gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra ) | |
566 | { | |
567 | GtkWidget *dia; | |
568 | dia = gtk_message_dialog_new ( parent, | |
569 | GTK_DIALOG_DESTROY_WITH_PARENT, | |
570 | GTK_MESSAGE_QUESTION, | |
571 | GTK_BUTTONS_YES_NO, | |
572 | message, extra ); | |
573 | ||
574 | if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES ) | |
575 | { | |
576 | gtk_widget_destroy ( dia ); | |
577 | return TRUE; | |
578 | } | |
579 | else | |
580 | { | |
581 | gtk_widget_destroy ( dia ); | |
582 | return FALSE; | |
583 | } | |
584 | } | |
585 | ||
586 | static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] ) | |
587 | { | |
588 | if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(pass_along[2]) ) ) | |
589 | gtk_spin_button_set_value ( | |
590 | GTK_SPIN_BUTTON(pass_along[GTK_WIDGET(spin) == pass_along[0] ? 1 : 0]), | |
591 | gtk_spin_button_get_value ( spin ) ); | |
592 | } | |
593 | ||
594 | gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp ) | |
595 | { | |
596 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."), | |
597 | parent, | |
598 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
599 | GTK_STOCK_CANCEL, | |
600 | GTK_RESPONSE_REJECT, | |
601 | GTK_STOCK_OK, | |
602 | GTK_RESPONSE_ACCEPT, | |
603 | NULL); | |
604 | GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck; | |
605 | GtkWidget *pass_along[3]; | |
606 | ||
607 | table = gtk_table_new ( 4, 2, FALSE ); | |
608 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); | |
609 | ||
610 | label = gtk_label_new ( _("Zoom factor (in meters per pixel):") ); | |
611 | xlabel = gtk_label_new ( _("X (easting): ")); | |
612 | ylabel = gtk_label_new ( _("Y (northing): ")); | |
613 | ||
614 | 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 ); | |
615 | 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 ); | |
616 | ||
617 | pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") ); | |
618 | /* TODO -- same factor */ | |
619 | /* samecheck = gtk_check_button_new_with_label ( "Same x/y zoom factor" ); */ | |
620 | ||
621 | if ( *xmpp == *ympp ) | |
622 | gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE ); | |
623 | ||
624 | gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 ); | |
625 | gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 1, 2 ); | |
626 | gtk_table_attach_defaults ( GTK_TABLE(table), xspin, 1, 2, 1, 2 ); | |
627 | gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 2, 3 ); | |
628 | gtk_table_attach_defaults ( GTK_TABLE(table), yspin, 1, 2, 2, 3 ); | |
629 | gtk_table_attach_defaults ( GTK_TABLE(table), samecheck, 0, 2, 3, 4 ); | |
630 | ||
631 | gtk_widget_show_all ( table ); | |
632 | ||
633 | g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along ); | |
634 | g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along ); | |
635 | ||
636 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
637 | ||
638 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
639 | { | |
640 | *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) ); | |
641 | *ympp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin) ); | |
642 | gtk_widget_destroy ( dialog ); | |
643 | return TRUE; | |
644 | } | |
645 | gtk_widget_destroy ( dialog ); | |
646 | return FALSE; | |
647 | } | |
648 | ||
649 | static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] ) | |
650 | { | |
651 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1); | |
652 | } | |
653 | ||
654 | gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr ) | |
655 | { | |
656 | GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text, | |
657 | parent, | |
658 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
659 | GTK_STOCK_CANCEL, | |
660 | GTK_RESPONSE_REJECT, | |
661 | GTK_STOCK_OK, | |
662 | GTK_RESPONSE_ACCEPT, | |
663 | NULL); | |
664 | GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label; | |
665 | GtkWidget *pass_along[1]; | |
666 | ||
667 | table = gtk_table_new ( 4, 2, FALSE ); | |
668 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); | |
669 | ||
670 | label = gtk_label_new (label_text); | |
671 | ||
672 | t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") ); | |
673 | t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") ); | |
674 | t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") ); | |
675 | t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") ); | |
676 | ||
677 | pass_along[0] = t4; | |
678 | ||
679 | spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 ); | |
680 | ||
681 | gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 ); | |
682 | gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 ); | |
683 | gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 ); | |
684 | gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 ); | |
685 | gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 ); | |
686 | gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 ); | |
687 | ||
688 | gtk_widget_show_all ( table ); | |
689 | ||
690 | g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along ); | |
691 | ||
692 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
693 | ||
694 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
695 | { | |
696 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) { | |
697 | *thr = 1; | |
698 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) { | |
699 | *thr = 60; | |
700 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) { | |
701 | *thr = 60 * 24; | |
702 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) { | |
703 | *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) ); | |
704 | } | |
705 | gtk_widget_destroy ( dialog ); | |
706 | return TRUE; | |
707 | } | |
708 | gtk_widget_destroy ( dialog ); | |
709 | return FALSE; | |
710 | } | |
711 | ||
712 | /** | |
713 | * a_dialog_get_positive_number: | |
714 | * | |
715 | * Dialog to return a positive number via a spinbox within the supplied limits | |
716 | * | |
717 | * Returns: A value of zero indicates the dialog was cancelled | |
718 | */ | |
719 | guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step ) | |
720 | { | |
721 | GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text, | |
722 | parent, | |
723 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
724 | GTK_STOCK_CANCEL, | |
725 | GTK_RESPONSE_REJECT, | |
726 | GTK_STOCK_OK, | |
727 | GTK_RESPONSE_ACCEPT, | |
728 | NULL); | |
729 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
730 | GtkWidget *response_w = NULL; | |
731 | #if GTK_CHECK_VERSION (2, 20, 0) | |
732 | response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
733 | #endif | |
734 | ||
735 | GtkWidget *table, *spin, *label; | |
736 | guint result = default_num; | |
737 | ||
738 | table = gtk_table_new ( 2, 1, FALSE ); | |
739 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); | |
740 | ||
741 | label = gtk_label_new (label_text); | |
742 | spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( default_num, min, max, step, 5, 0 ), 1, 0 ); | |
743 | ||
744 | gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 1, 0, 1 ); | |
745 | gtk_table_attach_defaults ( GTK_TABLE(table), spin, 0, 1, 1, 2 ); | |
746 | ||
747 | if ( response_w ) | |
748 | gtk_widget_grab_focus ( response_w ); | |
749 | ||
750 | gtk_widget_show_all ( table ); | |
751 | ||
752 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
753 | { | |
754 | result = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) ); | |
755 | gtk_widget_destroy ( dialog ); | |
756 | return result; | |
757 | } | |
758 | ||
759 | // Dialog cancelled | |
760 | gtk_widget_destroy ( dialog ); | |
761 | return 0; | |
762 | } | |
763 | ||
764 | #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24) | |
765 | static void about_url_hook (GtkAboutDialog *about, | |
766 | const gchar *link, | |
767 | gpointer data) | |
768 | { | |
769 | open_url (GTK_WINDOW(about), link); | |
770 | } | |
771 | ||
772 | static void about_email_hook (GtkAboutDialog *about, | |
773 | const gchar *email, | |
774 | gpointer data) | |
775 | { | |
776 | new_email (GTK_WINDOW(about), email); | |
777 | } | |
778 | #endif | |
779 | ||
780 | void a_dialog_about ( GtkWindow *parent ) | |
781 | { | |
782 | const gchar *program_name = PACKAGE_NAME; | |
783 | const gchar *version = VIKING_VERSION; | |
784 | const gchar *website = VIKING_URL; | |
785 | const gchar *copyright = "2003-2008, Evan Battaglia\n2008-2010, Viking's contributors"; | |
786 | const gchar *comments = _("GPS Data and Topo Analyzer, Explorer, and Manager."); | |
787 | const gchar *license = _("This program is free software; you can redistribute it and/or modify " | |
788 | "it under the terms of the GNU General Public License as published by " | |
789 | "the Free Software Foundation; either version 2 of the License, or " | |
790 | "(at your option) any later version." | |
791 | "\n\n" | |
792 | "This program is distributed in the hope that it will be useful, " | |
793 | "but WITHOUT ANY WARRANTY; without even the implied warranty of " | |
794 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " | |
795 | "GNU General Public License for more details." | |
796 | "\n\n" | |
797 | "You should have received a copy of the GNU General Public License " | |
798 | "along with this program; if not, write to the Free Software " | |
799 | "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA"); | |
800 | ||
801 | // Newer versions of GTK 'just work', calling gtk_show_uri() on the URL or email and opens up the appropriate program | |
802 | // This is the old method: | |
803 | #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24) | |
804 | gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL); | |
805 | gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL); | |
806 | #endif | |
807 | gtk_show_about_dialog (parent, | |
808 | /* TODO do not set program-name and correctly set info for g_get_application_name */ | |
809 | "program-name", program_name, | |
810 | "version", version, | |
811 | "website", website, | |
812 | "comments", comments, | |
813 | "copyright", copyright, | |
814 | "license", license, | |
815 | "wrap-license", TRUE, | |
816 | /* logo automatically retrieved via gtk_window_get_default_icon_list */ | |
817 | "authors", AUTHORS, | |
818 | "documenters", DOCUMENTERS, | |
819 | "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"), | |
820 | NULL); | |
821 | } | |
822 | ||
823 | 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) | |
824 | { | |
825 | gchar **s; | |
826 | ||
827 | 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 ); | |
828 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
829 | GtkWidget *response_w = NULL; | |
830 | #if GTK_CHECK_VERSION (2, 20, 0) | |
831 | response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
832 | #endif | |
833 | ||
834 | GtkWidget *map_label = gtk_label_new(_("Map type:")); | |
835 | GtkWidget *map_combo = vik_combo_box_text_new(); | |
836 | for (s = mapnames; *s; s++) | |
837 | vik_combo_box_text_append (GTK_COMBO_BOX(map_combo), *s); | |
838 | gtk_combo_box_set_active (GTK_COMBO_BOX(map_combo), default_map); | |
839 | ||
840 | GtkWidget *zoom_label = gtk_label_new(_("Zoom level:")); | |
841 | GtkWidget *zoom_combo = vik_combo_box_text_new(); | |
842 | for (s = zoom_list; *s; s++) | |
843 | vik_combo_box_text_append (GTK_COMBO_BOX(zoom_combo), *s); | |
844 | gtk_combo_box_set_active (GTK_COMBO_BOX(zoom_combo), default_zoom); | |
845 | ||
846 | GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE)); | |
847 | gtk_table_attach_defaults(box, map_label, 0, 1, 0, 1); | |
848 | gtk_table_attach_defaults(box, map_combo, 1, 2, 0, 1); | |
849 | gtk_table_attach_defaults(box, zoom_label, 0, 1, 1, 2); | |
850 | gtk_table_attach_defaults(box, zoom_combo, 1, 2, 1, 2); | |
851 | ||
852 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 ); | |
853 | ||
854 | if ( response_w ) | |
855 | gtk_widget_grab_focus ( response_w ); | |
856 | ||
857 | gtk_widget_show_all ( dialog ); | |
858 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) { | |
859 | gtk_widget_destroy(dialog); | |
860 | return FALSE; | |
861 | } | |
862 | ||
863 | *selected_map = gtk_combo_box_get_active(GTK_COMBO_BOX(map_combo)); | |
864 | *selected_zoom = gtk_combo_box_get_active(GTK_COMBO_BOX(zoom_combo)); | |
865 | ||
866 | gtk_widget_destroy(dialog); | |
867 | return TRUE; | |
868 | } | |
869 | ||
870 | /** | |
871 | * Display a dialog presenting the license of a map. | |
872 | * Allow to read the license by launching a web browser. | |
873 | */ | |
874 | void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url) | |
875 | { | |
876 | GtkWidget *dialog = gtk_message_dialog_new (parent, | |
877 | GTK_DIALOG_DESTROY_WITH_PARENT, | |
878 | GTK_MESSAGE_INFO, | |
879 | GTK_BUTTONS_OK, | |
880 | _("The map data is licensed: %s."), | |
881 | license); | |
882 | gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), | |
883 | _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>.\n" | |
884 | "Please, read the license before continuing."), | |
885 | map, license); | |
886 | #define RESPONSE_OPEN_LICENSE 600 | |
887 | if (url != NULL) { | |
888 | gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE); | |
889 | } | |
890 | gint response; | |
891 | do { | |
892 | response = gtk_dialog_run (GTK_DIALOG (dialog)); | |
893 | if (response == RESPONSE_OPEN_LICENSE) { | |
894 | open_url (parent, url); | |
895 | } | |
896 | } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK); | |
897 | gtk_widget_destroy (dialog); | |
898 | } |