]>
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:")); |
857baaa3 | 275 | imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, VF_FILTER_IMAGE); |
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 | ||
a77c32c8 RN |
553 | /** |
554 | * a_dialog_get_date: | |
555 | * | |
556 | * Returns: a date as a string - always in ISO8601 format (YYYY-MM-DD) | |
557 | * This string can be NULL (especially when the dialog is cancelled) | |
558 | * Free the string after use | |
559 | */ | |
560 | gchar *a_dialog_get_date ( GtkWindow *parent, const gchar *title ) | |
561 | { | |
562 | GtkWidget *dialog = gtk_dialog_new_with_buttons ( title, | |
563 | parent, | |
564 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
565 | GTK_STOCK_CANCEL, | |
566 | GTK_RESPONSE_REJECT, | |
567 | GTK_STOCK_OK, | |
568 | GTK_RESPONSE_ACCEPT, | |
569 | NULL); | |
570 | GtkWidget *cal = gtk_calendar_new (); | |
571 | ||
572 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), cal, FALSE, FALSE, 0); | |
573 | ||
574 | gtk_widget_show ( cal ); | |
575 | ||
576 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
577 | ||
578 | gchar *date_str = NULL; | |
579 | if ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) | |
580 | { | |
581 | guint year; | |
582 | guint month; | |
583 | guint day; | |
584 | gtk_calendar_get_date ( GTK_CALENDAR(cal), &year, &month, &day ); | |
585 | month = month+1; | |
586 | date_str = g_strdup_printf ( "%d-%02d-%02d", year, month, day ); | |
587 | } | |
588 | gtk_widget_destroy ( dialog ); | |
589 | return date_str; | |
590 | } | |
591 | ||
50a14534 | 592 | /* creates a vbox full of labels */ |
870e0b9a | 593 | GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count, gint spacing, gint padding ) |
50a14534 EB |
594 | { |
595 | GtkWidget *vbox, *label; | |
596 | int i; | |
870e0b9a | 597 | vbox = gtk_vbox_new( TRUE, spacing ); |
50a14534 EB |
598 | |
599 | for ( i = 0; i < label_count; i++ ) | |
600 | { | |
601 | label = gtk_label_new(NULL); | |
4c77d5e0 | 602 | gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) ); |
870e0b9a | 603 | gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding ); |
50a14534 EB |
604 | } |
605 | return vbox; | |
606 | } | |
607 | ||
d91e5f2b | 608 | gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra ) |
50a14534 EB |
609 | { |
610 | GtkWidget *dia; | |
611 | dia = gtk_message_dialog_new ( parent, | |
612 | GTK_DIALOG_DESTROY_WITH_PARENT, | |
613 | GTK_MESSAGE_QUESTION, | |
614 | GTK_BUTTONS_YES_NO, | |
615 | message, extra ); | |
616 | ||
617 | if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES ) | |
618 | { | |
619 | gtk_widget_destroy ( dia ); | |
620 | return TRUE; | |
621 | } | |
622 | else | |
623 | { | |
624 | gtk_widget_destroy ( dia ); | |
625 | return FALSE; | |
626 | } | |
627 | } | |
628 | ||
629 | static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] ) | |
630 | { | |
631 | if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(pass_along[2]) ) ) | |
632 | gtk_spin_button_set_value ( | |
633 | GTK_SPIN_BUTTON(pass_along[GTK_WIDGET(spin) == pass_along[0] ? 1 : 0]), | |
634 | gtk_spin_button_get_value ( spin ) ); | |
635 | } | |
636 | ||
637 | gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp ) | |
638 | { | |
7760b0cf | 639 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."), |
50a14534 EB |
640 | parent, |
641 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
642 | GTK_STOCK_CANCEL, | |
643 | GTK_RESPONSE_REJECT, | |
644 | GTK_STOCK_OK, | |
645 | GTK_RESPONSE_ACCEPT, | |
646 | NULL); | |
647 | GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck; | |
648 | GtkWidget *pass_along[3]; | |
649 | ||
650 | table = gtk_table_new ( 4, 2, FALSE ); | |
9b082b39 | 651 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); |
50a14534 | 652 | |
da0a736b | 653 | label = gtk_label_new ( _("Zoom factor (in meters per pixel):") ); |
7760b0cf JJ |
654 | xlabel = gtk_label_new ( _("X (easting): ")); |
655 | ylabel = gtk_label_new ( _("Y (northing): ")); | |
50a14534 | 656 | |
ac33062d RN |
657 | 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 ); |
658 | 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 | 659 | |
7760b0cf | 660 | pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") ); |
50a14534 EB |
661 | /* TODO -- same factor */ |
662 | /* samecheck = gtk_check_button_new_with_label ( "Same x/y zoom factor" ); */ | |
663 | ||
664 | if ( *xmpp == *ympp ) | |
665 | gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE ); | |
666 | ||
667 | gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 ); | |
668 | gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 1, 2 ); | |
669 | gtk_table_attach_defaults ( GTK_TABLE(table), xspin, 1, 2, 1, 2 ); | |
670 | gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 2, 3 ); | |
671 | gtk_table_attach_defaults ( GTK_TABLE(table), yspin, 1, 2, 2, 3 ); | |
672 | gtk_table_attach_defaults ( GTK_TABLE(table), samecheck, 0, 2, 3, 4 ); | |
673 | ||
674 | gtk_widget_show_all ( table ); | |
675 | ||
676 | g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along ); | |
677 | g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along ); | |
678 | ||
79d73727 RN |
679 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
680 | ||
50a14534 EB |
681 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) |
682 | { | |
683 | *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) ); | |
684 | *ympp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin) ); | |
685 | gtk_widget_destroy ( dialog ); | |
686 | return TRUE; | |
687 | } | |
688 | gtk_widget_destroy ( dialog ); | |
689 | return FALSE; | |
690 | } | |
111fa174 AF |
691 | |
692 | static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] ) | |
693 | { | |
694 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1); | |
695 | } | |
696 | ||
697 | gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr ) | |
698 | { | |
699 | GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text, | |
700 | parent, | |
701 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
702 | GTK_STOCK_CANCEL, | |
703 | GTK_RESPONSE_REJECT, | |
704 | GTK_STOCK_OK, | |
705 | GTK_RESPONSE_ACCEPT, | |
706 | NULL); | |
707 | GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label; | |
708 | GtkWidget *pass_along[1]; | |
709 | ||
710 | table = gtk_table_new ( 4, 2, FALSE ); | |
9b082b39 | 711 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); |
111fa174 AF |
712 | |
713 | label = gtk_label_new (label_text); | |
714 | ||
7760b0cf JJ |
715 | t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") ); |
716 | t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") ); | |
717 | t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") ); | |
718 | t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") ); | |
111fa174 AF |
719 | |
720 | pass_along[0] = t4; | |
721 | ||
ac33062d | 722 | spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 ); |
111fa174 AF |
723 | |
724 | gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 ); | |
725 | gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 ); | |
726 | gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 ); | |
727 | gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 ); | |
728 | gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 ); | |
729 | gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 ); | |
730 | ||
731 | gtk_widget_show_all ( table ); | |
732 | ||
733 | g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along ); | |
734 | ||
79d73727 RN |
735 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
736 | ||
111fa174 AF |
737 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) |
738 | { | |
739 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) { | |
740 | *thr = 1; | |
741 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) { | |
742 | *thr = 60; | |
743 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) { | |
744 | *thr = 60 * 24; | |
745 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) { | |
746 | *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) ); | |
747 | } | |
748 | gtk_widget_destroy ( dialog ); | |
749 | return TRUE; | |
750 | } | |
751 | gtk_widget_destroy ( dialog ); | |
752 | return FALSE; | |
753 | } | |
d0a5f320 | 754 | |
16c7d8fc | 755 | /** |
a0dd9023 GB |
756 | * a_dialog_get_positive_number: |
757 | * | |
16c7d8fc | 758 | * Dialog to return a positive number via a spinbox within the supplied limits |
a0dd9023 GB |
759 | * |
760 | * Returns: A value of zero indicates the dialog was cancelled | |
16c7d8fc RN |
761 | */ |
762 | guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step ) | |
763 | { | |
764 | GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text, | |
765 | parent, | |
766 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
767 | GTK_STOCK_CANCEL, | |
768 | GTK_RESPONSE_REJECT, | |
769 | GTK_STOCK_OK, | |
770 | GTK_RESPONSE_ACCEPT, | |
771 | NULL); | |
772 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
773 | GtkWidget *response_w = NULL; | |
774 | #if GTK_CHECK_VERSION (2, 20, 0) | |
775 | response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
776 | #endif | |
777 | ||
778 | GtkWidget *table, *spin, *label; | |
779 | guint result = default_num; | |
780 | ||
781 | table = gtk_table_new ( 2, 1, FALSE ); | |
9b082b39 | 782 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); |
16c7d8fc RN |
783 | |
784 | label = gtk_label_new (label_text); | |
785 | spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( default_num, min, max, step, 5, 0 ), 1, 0 ); | |
786 | ||
787 | gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 1, 0, 1 ); | |
788 | gtk_table_attach_defaults ( GTK_TABLE(table), spin, 0, 1, 1, 2 ); | |
789 | ||
790 | if ( response_w ) | |
791 | gtk_widget_grab_focus ( response_w ); | |
792 | ||
793 | gtk_widget_show_all ( table ); | |
794 | ||
795 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
796 | { | |
797 | result = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) ); | |
798 | gtk_widget_destroy ( dialog ); | |
799 | return result; | |
800 | } | |
801 | ||
802 | // Dialog cancelled | |
803 | gtk_widget_destroy ( dialog ); | |
804 | return 0; | |
805 | } | |
806 | ||
cbb35e4b | 807 | #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24) |
3530c91e GB |
808 | static void about_url_hook (GtkAboutDialog *about, |
809 | const gchar *link, | |
810 | gpointer data) | |
85beadba | 811 | { |
3530c91e GB |
812 | open_url (GTK_WINDOW(about), link); |
813 | } | |
814 | ||
815 | static void about_email_hook (GtkAboutDialog *about, | |
816 | const gchar *email, | |
817 | gpointer data) | |
818 | { | |
819 | new_email (GTK_WINDOW(about), email); | |
85beadba | 820 | } |
cbb35e4b | 821 | #endif |
d0a5f320 AF |
822 | |
823 | void a_dialog_about ( GtkWindow *parent ) | |
824 | { | |
85beadba GB |
825 | const gchar *program_name = PACKAGE_NAME; |
826 | const gchar *version = VIKING_VERSION; | |
827 | const gchar *website = VIKING_URL; | |
6493fea2 | 828 | const gchar *copyright = "2003-2008, Evan Battaglia\n2008-2013, Viking's contributors"; |
85beadba GB |
829 | const gchar *comments = _("GPS Data and Topo Analyzer, Explorer, and Manager."); |
830 | const gchar *license = _("This program is free software; you can redistribute it and/or modify " | |
d0a5f320 AF |
831 | "it under the terms of the GNU General Public License as published by " |
832 | "the Free Software Foundation; either version 2 of the License, or " | |
833 | "(at your option) any later version." | |
834 | "\n\n" | |
835 | "This program is distributed in the hope that it will be useful, " | |
836 | "but WITHOUT ANY WARRANTY; without even the implied warranty of " | |
837 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " | |
838 | "GNU General Public License for more details." | |
839 | "\n\n" | |
840 | "You should have received a copy of the GNU General Public License " | |
841 | "along with this program; if not, write to the Free Software " | |
85beadba GB |
842 | "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA"); |
843 | ||
23392193 RN |
844 | // Would be nice to use gtk_about_dialog_add_credit_section (), but that requires gtk 3.4 |
845 | // For now shove it in the 'artists' section so at least the information is easily visible | |
846 | // Something more advanced might have proper version information too... | |
847 | const gchar *libs[] = { | |
848 | "Compiled in libraries:", | |
849 | // Default libs | |
850 | "libglib-2.0", | |
851 | "libgthread-2.0", | |
852 | "libgtk+-2.0", | |
853 | "libgio-2.0", | |
854 | // Potentially optional libs (but probably couldn't build without them) | |
855 | #ifdef HAVE_LIBM | |
856 | "libm", | |
857 | #endif | |
858 | #ifdef HAVE_LIBZ | |
859 | "libz", | |
860 | #endif | |
861 | #ifdef HAVE_LIBCURL | |
862 | "libcurl", | |
863 | #endif | |
864 | // Actually optional libs | |
865 | #ifdef HAVE_LIBGPS | |
866 | "libgps", | |
867 | #endif | |
868 | #ifdef HAVE_LIBEXIF | |
869 | "libexif", | |
870 | #endif | |
871 | #ifdef HAVE_LIBX11 | |
872 | "libX11", | |
04da83cd RN |
873 | #endif |
874 | #ifdef HAVE_LIBMAGIC | |
875 | "libmagic", | |
876 | #endif | |
877 | #ifdef HAVE_LIBBZ2 | |
878 | "libbz2", | |
0fb11294 RN |
879 | #endif |
880 | #ifdef HAVE_LIBSQLITE3 | |
881 | "libsqlite3", | |
23392193 RN |
882 | #endif |
883 | NULL | |
884 | }; | |
cbb35e4b RN |
885 | // Newer versions of GTK 'just work', calling gtk_show_uri() on the URL or email and opens up the appropriate program |
886 | // This is the old method: | |
887 | #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24) | |
3530c91e GB |
888 | gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL); |
889 | gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL); | |
cbb35e4b | 890 | #endif |
23392193 | 891 | |
85beadba GB |
892 | gtk_show_about_dialog (parent, |
893 | /* TODO do not set program-name and correctly set info for g_get_application_name */ | |
894 | "program-name", program_name, | |
895 | "version", version, | |
896 | "website", website, | |
897 | "comments", comments, | |
898 | "copyright", copyright, | |
899 | "license", license, | |
900 | "wrap-license", TRUE, | |
901 | /* logo automatically retrieved via gtk_window_get_default_icon_list */ | |
902 | "authors", AUTHORS, | |
eb6a42c9 | 903 | "documenters", DOCUMENTERS, |
551e7a38 | 904 | "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"), |
23392193 | 905 | "artists", libs, |
85beadba | 906 | NULL); |
d0a5f320 | 907 | } |
7114e879 QT |
908 | |
909 | 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) | |
910 | { | |
911 | gchar **s; | |
912 | ||
7760b0cf | 913 | 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 |
914 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
915 | GtkWidget *response_w = NULL; | |
916 | #if GTK_CHECK_VERSION (2, 20, 0) | |
917 | response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
918 | #endif | |
1bc1c05b | 919 | |
7760b0cf | 920 | GtkWidget *map_label = gtk_label_new(_("Map type:")); |
1bc1c05b | 921 | GtkWidget *map_combo = vik_combo_box_text_new(); |
7114e879 | 922 | for (s = mapnames; *s; s++) |
1bc1c05b RN |
923 | vik_combo_box_text_append (GTK_COMBO_BOX(map_combo), *s); |
924 | gtk_combo_box_set_active (GTK_COMBO_BOX(map_combo), default_map); | |
925 | ||
7760b0cf | 926 | GtkWidget *zoom_label = gtk_label_new(_("Zoom level:")); |
1bc1c05b | 927 | GtkWidget *zoom_combo = vik_combo_box_text_new(); |
7114e879 | 928 | for (s = zoom_list; *s; s++) |
1bc1c05b RN |
929 | vik_combo_box_text_append (GTK_COMBO_BOX(zoom_combo), *s); |
930 | gtk_combo_box_set_active (GTK_COMBO_BOX(zoom_combo), default_zoom); | |
7114e879 QT |
931 | |
932 | GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE)); | |
1bc1c05b RN |
933 | gtk_table_attach_defaults(box, map_label, 0, 1, 0, 1); |
934 | gtk_table_attach_defaults(box, map_combo, 1, 2, 0, 1); | |
935 | gtk_table_attach_defaults(box, zoom_label, 0, 1, 1, 2); | |
936 | gtk_table_attach_defaults(box, zoom_combo, 1, 2, 1, 2); | |
7114e879 | 937 | |
9b082b39 | 938 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 ); |
7114e879 | 939 | |
6e450795 RN |
940 | if ( response_w ) |
941 | gtk_widget_grab_focus ( response_w ); | |
942 | ||
7114e879 QT |
943 | gtk_widget_show_all ( dialog ); |
944 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) { | |
945 | gtk_widget_destroy(dialog); | |
946 | return FALSE; | |
947 | } | |
948 | ||
1bc1c05b RN |
949 | *selected_map = gtk_combo_box_get_active(GTK_COMBO_BOX(map_combo)); |
950 | *selected_zoom = gtk_combo_box_get_active(GTK_COMBO_BOX(zoom_combo)); | |
7114e879 QT |
951 | |
952 | gtk_widget_destroy(dialog); | |
953 | return TRUE; | |
954 | } | |
53ac8302 GB |
955 | |
956 | /** | |
957 | * Display a dialog presenting the license of a map. | |
958 | * Allow to read the license by launching a web browser. | |
959 | */ | |
4033fba0 | 960 | void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url) |
53ac8302 GB |
961 | { |
962 | GtkWidget *dialog = gtk_message_dialog_new (parent, | |
963 | GTK_DIALOG_DESTROY_WITH_PARENT, | |
964 | GTK_MESSAGE_INFO, | |
965 | GTK_BUTTONS_OK, | |
966 | _("The map data is licensed: %s."), | |
967 | license); | |
968 | gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), | |
b03ae39b | 969 | _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>."), |
53ac8302 GB |
970 | map, license); |
971 | #define RESPONSE_OPEN_LICENSE 600 | |
972 | if (url != NULL) { | |
973 | gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE); | |
974 | } | |
975 | gint response; | |
976 | do { | |
977 | response = gtk_dialog_run (GTK_DIALOG (dialog)); | |
978 | if (response == RESPONSE_OPEN_LICENSE) { | |
979 | open_url (parent, url); | |
980 | } | |
981 | } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK); | |
982 | gtk_widget_destroy (dialog); | |
983 | } |