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