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