]>
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> | |
a482007a GB |
5 | * Copyright (C) 2008, Hein Ragas <viking@ragas.nl> |
6 | * Copyright (C) 2010, Rob Norris <rw_norris@hotmail.com> | |
50a14534 EB |
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 | ||
4c77d5e0 GB |
24 | #ifdef HAVE_CONFIG_H |
25 | #include "config.h" | |
26 | #endif | |
27 | ||
50a14534 EB |
28 | #include "viking.h" |
29 | #include "thumbnails.h" | |
acaf7113 | 30 | #include "garminsymbols.h" |
dfad9456 | 31 | #include "degrees_converters.h" |
e8947958 | 32 | #include "authors.h" |
eb6a42c9 | 33 | #include "documenters.h" |
34e71b99 | 34 | #include "vikgoto.h" |
85beadba | 35 | #include "util.h" |
50a14534 | 36 | |
4c77d5e0 GB |
37 | #include <glib/gi18n.h> |
38 | ||
50a14534 EB |
39 | #include <stdlib.h> |
40 | #include <string.h> | |
41 | #include <ctype.h> | |
f5ef9b95 | 42 | #include <time.h> |
50a14534 EB |
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 | { | |
7760b0cf | 53 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"), |
50a14534 EB |
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 | ||
7760b0cf | 65 | latlabel = gtk_label_new (_("Latitude:")); |
50a14534 EB |
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 | ||
7760b0cf | 71 | lonlabel = gtk_label_new (_("Longitude:")); |
50a14534 EB |
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 | ||
9b082b39 RN |
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); | |
50a14534 | 86 | |
355fba11 RN |
87 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
88 | ||
50a14534 EB |
89 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) |
90 | { | |
dfad9456 GB |
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) ) ); | |
50a14534 EB |
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 | { | |
a0f3579f | 103 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"), |
50a14534 EB |
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 | ||
7760b0cf | 116 | norlabel = gtk_label_new (_("Northing:")); |
50a14534 EB |
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 | ||
7760b0cf | 122 | easlabel = gtk_label_new (_("Easting:")); |
50a14534 EB |
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 ); | |
7760b0cf | 129 | gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 ); |
ac33062d | 130 | zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 0 ), 1, 0 ); |
50a14534 | 131 | gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 ); |
7760b0cf | 132 | gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 ); |
50a14534 EB |
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 | ||
9b082b39 RN |
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); | |
50a14534 | 153 | |
355fba11 RN |
154 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
155 | ||
50a14534 EB |
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 | ||
8eb76f51 QT |
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 | ||
ac1bde8b RN |
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 | |
ac1bde8b | 195 | */ |
50a14534 | 196 | /* todo: less on this side, like add track */ |
d6175f49 | 197 | gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *vtl, VikWaypoint *wp, VikCoordMode coord_mode, gboolean is_new, gboolean *updated ) |
50a14534 | 198 | { |
490b1aa6 | 199 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"), |
50a14534 EB |
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; | |
6b2f262e RN |
208 | GtkWidget *latlabel, *lonlabel, *namelabel, *latentry, *lonentry, *altentry, *altlabel, *nameentry=NULL; |
209 | GtkWidget *commentlabel, *commententry, *descriptionlabel, *descriptionentry, *imagelabel, *imageentry, *symbollabel, *symbolentry; | |
f5ef9b95 RN |
210 | GtkWidget *timelabel = NULL; |
211 | GtkWidget *timevaluelabel = NULL; // No editing of time allowed ATM | |
acaf7113 AF |
212 | GtkListStore *store; |
213 | ||
50a14534 EB |
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 ); | |
6027a9c5 RN |
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: | |
6c20e59a | 226 | alt = g_strdup_printf ( "%f", VIK_METERS_TO_FEET(wp->altitude) ); |
6027a9c5 RN |
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 | } | |
50a14534 | 232 | |
ac1bde8b RN |
233 | *updated = FALSE; |
234 | ||
235 | namelabel = gtk_label_new (_("Name:")); | |
9b082b39 | 236 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), namelabel, FALSE, FALSE, 0); |
6761d8a4 RN |
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); | |
50a14534 | 243 | |
7760b0cf | 244 | latlabel = gtk_label_new (_("Latitude:")); |
50a14534 EB |
245 | latentry = gtk_entry_new (); |
246 | gtk_entry_set_text ( GTK_ENTRY(latentry), lat ); | |
247 | g_free ( lat ); | |
248 | ||
7760b0cf | 249 | lonlabel = gtk_label_new (_("Longitude:")); |
50a14534 EB |
250 | lonentry = gtk_entry_new (); |
251 | gtk_entry_set_text ( GTK_ENTRY(lonentry), lon ); | |
252 | g_free ( lon ); | |
253 | ||
7760b0cf | 254 | altlabel = gtk_label_new (_("Altitude:")); |
50a14534 EB |
255 | altentry = gtk_entry_new (); |
256 | gtk_entry_set_text ( GTK_ENTRY(altentry), alt ); | |
257 | g_free ( alt ); | |
258 | ||
7760b0cf | 259 | commentlabel = gtk_label_new (_("Comment:")); |
50a14534 | 260 | commententry = gtk_entry_new (); |
ba4a5e11 | 261 | gchar *cmt = NULL; |
6b2f262e | 262 | // Auto put in some kind of 'name' as a comment if one previously 'goto'ed this exact location |
34e71b99 | 263 | cmt = a_vik_goto_get_search_string_for_this_place(VIK_WINDOW(parent)); |
014128f6 QT |
264 | if (cmt) |
265 | gtk_entry_set_text(GTK_ENTRY(commententry), cmt); | |
50a14534 | 266 | |
6b2f262e RN |
267 | descriptionlabel = gtk_label_new (_("Description:")); |
268 | descriptionentry = gtk_entry_new (); | |
269 | ||
7760b0cf | 270 | imagelabel = gtk_label_new (_("Image:")); |
79672b85 | 271 | imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN); |
50a14534 | 272 | |
acaf7113 AF |
273 | { |
274 | GtkCellRenderer *r; | |
7760b0cf | 275 | symbollabel = gtk_label_new (_("Symbol:")); |
acaf7113 AF |
276 | GtkTreeIter iter; |
277 | ||
ea3933fc | 278 | store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING); |
acaf7113 | 279 | symbolentry = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); |
8eb76f51 | 280 | gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(symbolentry), 6); |
9be0449f RN |
281 | |
282 | g_signal_connect(symbolentry, "changed", G_CALLBACK(symbol_entry_changed_cb), store); | |
acaf7113 | 283 | gtk_list_store_append (store, &iter); |
7760b0cf | 284 | gtk_list_store_set (store, &iter, 0, NULL, 1, NULL, 2, _("(none)"), -1); |
acaf7113 AF |
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 | ||
ea3933fc EB |
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 | ||
ac1bde8b | 295 | if ( !is_new && wp->symbol ) { |
acaf7113 AF |
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 ); | |
ea3933fc | 300 | if (sym && !strcmp(sym, wp->symbol)) { |
acaf7113 AF |
301 | g_free(sym); |
302 | break; | |
303 | } else { | |
304 | g_free(sym); | |
305 | } | |
306 | } | |
705af621 RN |
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); | |
acaf7113 AF |
312 | } |
313 | } | |
314 | ||
ac1bde8b | 315 | if ( !is_new && wp->comment ) |
50a14534 EB |
316 | gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment ); |
317 | ||
6b2f262e RN |
318 | if ( !is_new && wp->description ) |
319 | gtk_entry_set_text ( GTK_ENTRY(descriptionentry), wp->description ); | |
320 | ||
ac1bde8b | 321 | if ( !is_new && wp->image ) |
50a14534 EB |
322 | vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image ); |
323 | ||
f5ef9b95 | 324 | if ( !is_new && wp->has_timestamp ) { |
fff4e5e3 | 325 | gchar tmp_str[64]; |
f5ef9b95 RN |
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 | } | |
50a14534 | 331 | |
9b082b39 RN |
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); | |
f5ef9b95 RN |
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 | } | |
9b082b39 RN |
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); | |
50a14534 | 350 | |
f703e735 RN |
351 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
352 | ||
9b082b39 | 353 | gtk_widget_show_all ( gtk_dialog_get_content_area(GTK_DIALOG(dialog)) ); |
acaf7113 | 354 | |
d6175f49 RN |
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 | ||
50a14534 EB |
360 | while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) |
361 | { | |
6761d8a4 RN |
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) ) ); | |
c9570f86 | 367 | |
6761d8a4 | 368 | /* Do It */ |
dfad9456 GB |
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) ) ); | |
50a14534 | 371 | vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll ); |
6761d8a4 | 372 | // Always store in metres |
6027a9c5 RN |
373 | switch (height_units) { |
374 | case VIK_UNITS_HEIGHT_METRES: | |
6761d8a4 RN |
375 | wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); |
376 | break; | |
6027a9c5 | 377 | case VIK_UNITS_HEIGHT_FEET: |
6761d8a4 RN |
378 | wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) )); |
379 | break; | |
6027a9c5 | 380 | default: |
6761d8a4 RN |
381 | wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); |
382 | g_critical("Houston, we've had a problem. height=%d", height_units); | |
6027a9c5 | 383 | } |
6761d8a4 | 384 | if ( g_strcmp0 ( wp->comment, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ) ) |
50a14534 | 385 | vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ); |
6761d8a4 | 386 | if ( g_strcmp0 ( wp->description, gtk_entry_get_text ( GTK_ENTRY(descriptionentry) ) ) ) |
6b2f262e | 387 | vik_waypoint_set_description ( wp, gtk_entry_get_text ( GTK_ENTRY(descriptionentry) ) ); |
6761d8a4 | 388 | if ( g_strcmp0 ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ) ) |
50a14534 | 389 | vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ); |
6761d8a4 RN |
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); | |
50a14534 EB |
402 | } |
403 | ||
404 | gtk_widget_destroy ( dialog ); | |
6761d8a4 RN |
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 | } | |
50a14534 EB |
415 | } |
416 | } | |
417 | gtk_widget_destroy ( dialog ); | |
ac1bde8b | 418 | return NULL; |
50a14534 EB |
419 | } |
420 | ||
7767aa02 QT |
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 | ||
02bba540 | 432 | GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg ) |
291edcab HR |
433 | { |
434 | GtkTreeIter iter; | |
435 | GtkCellRenderer *renderer; | |
436 | GtkWidget *view; | |
437 | ||
7767aa02 | 438 | GtkWidget *dialog = gtk_dialog_new_with_buttons (title, |
291edcab HR |
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); | |
93ece96d RN |
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 | |
291edcab HR |
453 | GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING); |
454 | ||
a814d755 RN |
455 | GtkWidget *scrolledwindow; |
456 | ||
02bba540 RN |
457 | GList *runner = names; |
458 | while (runner) | |
291edcab | 459 | { |
15f45edc | 460 | gtk_list_store_append(store, &iter); |
02bba540 RN |
461 | gtk_list_store_set(store, &iter, 0, runner->data, -1); |
462 | runner = g_list_next(runner); | |
291edcab | 463 | } |
291edcab HR |
464 | |
465 | view = gtk_tree_view_new(); | |
466 | renderer = gtk_cell_renderer_text_new(); | |
a814d755 RN |
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 | |
be64b02f RN |
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 | ||
291edcab | 474 | gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); |
7767aa02 QT |
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 ); | |
291edcab HR |
477 | g_object_unref(store); |
478 | ||
a814d755 RN |
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 | ||
9b082b39 | 483 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), scrolledwindow, TRUE, TRUE, 0 ); |
a814d755 RN |
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 ); | |
291edcab | 488 | |
93ece96d RN |
489 | if ( response_w ) |
490 | gtk_widget_grab_focus ( response_w ); | |
491 | ||
291edcab HR |
492 | while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) |
493 | { | |
7767aa02 | 494 | GList *names = NULL; |
291edcab | 495 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); |
7767aa02 QT |
496 | gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names); |
497 | if (names) | |
291edcab | 498 | { |
291edcab | 499 | gtk_widget_destroy ( dialog ); |
7767aa02 | 500 | return (names); |
291edcab | 501 | } |
7767aa02 | 502 | a_dialog_error_msg(parent, _("Nothing was selected")); |
291edcab HR |
503 | } |
504 | gtk_widget_destroy ( dialog ); | |
505 | return NULL; | |
506 | } | |
507 | ||
e37b2a6d | 508 | gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *default_name, gboolean is_route ) |
50a14534 | 509 | { |
e37b2a6d | 510 | GtkWidget *dialog = gtk_dialog_new_with_buttons ( is_route ? _("Add Route") : _("Add Track"), |
50a14534 EB |
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); | |
e37b2a6d | 518 | GtkWidget *label = gtk_label_new ( is_route ? _("Route Name:") : _("Track Name:") ); |
50a14534 EB |
519 | GtkWidget *entry = gtk_entry_new (); |
520 | ||
e13ab673 RN |
521 | if (default_name) |
522 | gtk_entry_set_text ( GTK_ENTRY(entry), default_name ); | |
523 | ||
9b082b39 RN |
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); | |
50a14534 EB |
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 | ||
79d73727 RN |
532 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
533 | ||
50a14534 EB |
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' ) | |
7760b0cf | 538 | a_dialog_info_msg ( parent, _("Please enter a name for the track.") ); |
50a14534 EB |
539 | else { |
540 | gchar *name = g_strdup ( constname ); | |
00277caf RN |
541 | gtk_widget_destroy ( dialog ); |
542 | return name; | |
50a14534 EB |
543 | } |
544 | } | |
545 | gtk_widget_destroy ( dialog ); | |
546 | return NULL; | |
547 | } | |
548 | ||
549 | /* creates a vbox full of labels */ | |
870e0b9a | 550 | GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count, gint spacing, gint padding ) |
50a14534 EB |
551 | { |
552 | GtkWidget *vbox, *label; | |
553 | int i; | |
870e0b9a | 554 | vbox = gtk_vbox_new( TRUE, spacing ); |
50a14534 EB |
555 | |
556 | for ( i = 0; i < label_count; i++ ) | |
557 | { | |
558 | label = gtk_label_new(NULL); | |
4c77d5e0 | 559 | gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) ); |
870e0b9a | 560 | gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding ); |
50a14534 EB |
561 | } |
562 | return vbox; | |
563 | } | |
564 | ||
d91e5f2b | 565 | gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra ) |
50a14534 EB |
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 | { | |
7760b0cf | 596 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."), |
50a14534 EB |
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 ); | |
9b082b39 | 608 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); |
50a14534 | 609 | |
da0a736b | 610 | label = gtk_label_new ( _("Zoom factor (in meters per pixel):") ); |
7760b0cf JJ |
611 | xlabel = gtk_label_new ( _("X (easting): ")); |
612 | ylabel = gtk_label_new ( _("Y (northing): ")); | |
50a14534 | 613 | |
ac33062d RN |
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 ); | |
50a14534 | 616 | |
7760b0cf | 617 | pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") ); |
50a14534 EB |
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 | ||
79d73727 RN |
636 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
637 | ||
50a14534 EB |
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 | } | |
111fa174 AF |
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 ); | |
9b082b39 | 668 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); |
111fa174 AF |
669 | |
670 | label = gtk_label_new (label_text); | |
671 | ||
7760b0cf JJ |
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):") ); | |
111fa174 AF |
676 | |
677 | pass_along[0] = t4; | |
678 | ||
ac33062d | 679 | spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 ); |
111fa174 AF |
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 | ||
79d73727 RN |
692 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
693 | ||
111fa174 AF |
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 | } | |
d0a5f320 | 711 | |
16c7d8fc | 712 | /** |
a0dd9023 GB |
713 | * a_dialog_get_positive_number: |
714 | * | |
16c7d8fc | 715 | * Dialog to return a positive number via a spinbox within the supplied limits |
a0dd9023 GB |
716 | * |
717 | * Returns: A value of zero indicates the dialog was cancelled | |
16c7d8fc RN |
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 ); | |
9b082b39 | 739 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); |
16c7d8fc RN |
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 | ||
cbb35e4b | 764 | #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24) |
3530c91e GB |
765 | static void about_url_hook (GtkAboutDialog *about, |
766 | const gchar *link, | |
767 | gpointer data) | |
85beadba | 768 | { |
3530c91e GB |
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); | |
85beadba | 777 | } |
cbb35e4b | 778 | #endif |
d0a5f320 AF |
779 | |
780 | void a_dialog_about ( GtkWindow *parent ) | |
781 | { | |
85beadba GB |
782 | const gchar *program_name = PACKAGE_NAME; |
783 | const gchar *version = VIKING_VERSION; | |
784 | const gchar *website = VIKING_URL; | |
8192ebe3 | 785 | const gchar *copyright = "2003-2008, Evan Battaglia\n2008-2010, Viking's contributors"; |
85beadba GB |
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 " | |
d0a5f320 AF |
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 " | |
85beadba GB |
799 | "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA"); |
800 | ||
cbb35e4b RN |
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) | |
3530c91e GB |
804 | gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL); |
805 | gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL); | |
cbb35e4b | 806 | #endif |
85beadba GB |
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, | |
eb6a42c9 | 818 | "documenters", DOCUMENTERS, |
551e7a38 | 819 | "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"), |
85beadba | 820 | NULL); |
d0a5f320 | 821 | } |
7114e879 QT |
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 | ||
7760b0cf | 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 ); |
6e450795 RN |
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 | |
1bc1c05b | 833 | |
7760b0cf | 834 | GtkWidget *map_label = gtk_label_new(_("Map type:")); |
1bc1c05b | 835 | GtkWidget *map_combo = vik_combo_box_text_new(); |
7114e879 | 836 | for (s = mapnames; *s; s++) |
1bc1c05b RN |
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 | ||
7760b0cf | 840 | GtkWidget *zoom_label = gtk_label_new(_("Zoom level:")); |
1bc1c05b | 841 | GtkWidget *zoom_combo = vik_combo_box_text_new(); |
7114e879 | 842 | for (s = zoom_list; *s; s++) |
1bc1c05b RN |
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); | |
7114e879 QT |
845 | |
846 | GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE)); | |
1bc1c05b RN |
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); | |
7114e879 | 851 | |
9b082b39 | 852 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 ); |
7114e879 | 853 | |
6e450795 RN |
854 | if ( response_w ) |
855 | gtk_widget_grab_focus ( response_w ); | |
856 | ||
7114e879 QT |
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 | ||
1bc1c05b RN |
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)); | |
7114e879 QT |
865 | |
866 | gtk_widget_destroy(dialog); | |
867 | return TRUE; | |
868 | } | |
53ac8302 GB |
869 | |
870 | /** | |
871 | * Display a dialog presenting the license of a map. | |
872 | * Allow to read the license by launching a web browser. | |
873 | */ | |
4033fba0 | 874 | void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url) |
53ac8302 GB |
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 | } |