]> git.street.me.uk Git - andy/viking.git/blame - src/globals.c
Map data license does not need to be shown every time for the default map.
[andy/viking.git] / src / globals.c
CommitLineData
2936913d
GB
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, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
1219fd23 6 * Copyright (C) 2010-2013, Rob Norris <rw_norris@hotmail.com>
2936913d
GB
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 */
a58aaed4
GB
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
6cdf89e5
RN
26#ifdef HAVE_STDLIB_H
27#include <stdlib.h>
28#endif
a58aaed4
GB
29
30#include <glib/gi18n.h>
2936913d
GB
31
32#include "globals.h"
a58aaed4 33#include "preferences.h"
6cdf89e5 34#include "math.h"
20015a31 35#include "dir.h"
2936913d
GB
36
37gboolean vik_debug = FALSE;
38gboolean vik_verbose = FALSE;
39gboolean vik_version = FALSE;
40
6cdf89e5
RN
41/**
42 * viking_version_to_number:
43 * @version: The string of the Viking version.
44 * This should be in the form of N.N.N.N, where the 3rd + 4th numbers are optional
45 * Often you'll want to pass in VIKING_VERSION
46 *
47 * Returns: a single number useful for comparison
48 */
49gint viking_version_to_number ( gchar *version )
50{
51 // Basic method, probably can be improved
52 gint version_number = 0;
53 gchar** parts = g_strsplit ( version, ".", 0 );
54 gint part_num = 0;
55 gchar *part = parts[part_num];
56 // Allow upto 4 parts to the version number
57 while ( part && part_num < 4 ) {
58 // Allow each part to have upto 100
59 version_number = version_number + ( atol(part) * pow(100, 3-part_num) );
60 part_num++;
61 part = parts[part_num];
62 }
63 g_strfreev ( parts );
64 return version_number;
65}
66
a58aaed4 67static gchar * params_degree_formats[] = {"DDD", "DMM", "DMS", NULL};
6f9336aa 68static gchar * params_units_distance[] = {"Kilometres", "Miles", NULL};
a4c92313 69static gchar * params_units_speed[] = {"km/h", "mph", "m/s", "knots", NULL};
6027a9c5 70static gchar * params_units_height[] = {"Metres", "Feet", NULL};
5210c3d3
GB
71static VikLayerParamScale params_scales_lat[] = { {-90.0, 90.0, 0.05, 2} };
72static VikLayerParamScale params_scales_long[] = { {-180.0, 180.0, 0.05, 2} };
88542aa9
RN
73static gchar * params_vik_fileref[] = {N_("Absolute"), N_("Relative"), NULL};
74
4fe48116 75static VikLayerParam general_prefs[] = {
a7023a1b 76 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "degree_format", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Degree format:"), VIK_LAYER_WIDGET_COMBOBOX, params_degree_formats, NULL, NULL },
a7023a1b 77 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "units_distance", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Distance units:"), VIK_LAYER_WIDGET_COMBOBOX, params_units_distance, NULL, NULL },
a7023a1b 78 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "units_speed", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Speed units:"), VIK_LAYER_WIDGET_COMBOBOX, params_units_speed, NULL, NULL },
a7023a1b 79 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "units_height", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Height units:"), VIK_LAYER_WIDGET_COMBOBOX, params_units_height, NULL, NULL },
a7023a1b 80 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "use_large_waypoint_icons", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Use large waypoint icons:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL },
4fe48116
RN
81 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "default_latitude", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Default latitude:"), VIK_LAYER_WIDGET_SPINBUTTON, params_scales_lat, NULL, NULL },
82 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "default_longitude", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Default longitude:"), VIK_LAYER_WIDGET_SPINBUTTON, params_scales_long, NULL, NULL },
5210c3d3
GB
83};
84
60dbd0ad
RN
85/* External/Export Options */
86
87static gchar * params_kml_export_units[] = {"Metric", "Statute", "Nautical", NULL};
b02cd3a3 88static gchar * params_gpx_export_trk_sort[] = {N_("Alphabetical"), N_("Time"), N_("Creation"), NULL };
72f067ad 89static gchar * params_gpx_export_wpt_symbols[] = {N_("Title Case"), N_("Lowercase"), NULL};
60dbd0ad
RN
90
91static VikLayerParam io_prefs[] = {
72f067ad
RN
92 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_IO_NAMESPACE "kml_export_units", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("KML File Export Units:"), VIK_LAYER_WIDGET_COMBOBOX, params_kml_export_units, NULL, NULL, NULL },
93 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_IO_NAMESPACE "gpx_export_track_sort", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("GPX Track Order:"), VIK_LAYER_WIDGET_COMBOBOX, params_gpx_export_trk_sort, NULL, NULL, NULL },
94 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_IO_NAMESPACE "gpx_export_wpt_sym_names", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("GPX Waypoint Symbols:"), VIK_LAYER_WIDGET_COMBOBOX, params_gpx_export_wpt_symbols, NULL,
95 N_("Save GPX Waypoint Symbol names in the specified case. May be useful for compatibility with various devices"), NULL },
60dbd0ad
RN
96};
97
3317dc4e
RN
98#ifndef WINDOWS
99static VikLayerParam io_prefs_non_windows[] = {
a7023a1b 100 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_IO_NAMESPACE "image_viewer", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Image Viewer:"), VIK_LAYER_WIDGET_FILEENTRY, NULL, NULL, NULL },
3317dc4e
RN
101};
102#endif
103
ccccf356 104static VikLayerParam io_prefs_external_gpx[] = {
a7023a1b
RN
105 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_IO_NAMESPACE "external_gpx_1", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("External GPX Program 1:"), VIK_LAYER_WIDGET_FILEENTRY, NULL, NULL, NULL },
106 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_IO_NAMESPACE "external_gpx_2", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("External GPX Program 2:"), VIK_LAYER_WIDGET_FILEENTRY, NULL, NULL, NULL },
ccccf356
RN
107};
108
88542aa9
RN
109static VikLayerParam prefs_advanced[] = {
110 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_ADVANCED_NAMESPACE "save_file_reference_mode", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Save File Reference Mode:"), VIK_LAYER_WIDGET_COMBOBOX, params_vik_fileref, NULL,
111 N_("When saving a Viking .vik file, this determines how the directory paths of filenames are written."), NULL },
90611609 112 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_ADVANCED_NAMESPACE "create_track_tooltip", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Show Tooltip during Track Creation:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL, NULL },
88542aa9
RN
113};
114
a14f46cf 115static gchar * params_startup_methods[] = {N_("Home Location"), N_("Last Location"), N_("Specified File"), N_("Auto Location"), NULL};
7143d1e4 116
1219fd23
RN
117static VikLayerParam startup_prefs[] = {
118 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "restore_window_state", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Restore Window Setup:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL,
119 N_("Restore window size and layout"), NULL, },
8fa25c61
RN
120 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "add_default_map_layer", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Add a Default Map Layer:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL,
121 N_("The default map layer added is defined by the Layer Defaults. Use the menu Edit->Layer Defaults->Map... to change the map type and other values."), NULL, },
7143d1e4
RN
122 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_method", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Startup Method:"), VIK_LAYER_WIDGET_COMBOBOX, params_startup_methods, NULL, NULL, NULL },
123 { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_file", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Startup File:"), VIK_LAYER_WIDGET_FILEENTRY, NULL, NULL,
124 N_("The default file to load on startup. Only applies when the startup method is set to 'Specified File'"), NULL, },
1219fd23 125};
60dbd0ad
RN
126/* End of Options static stuff */
127
20015a31
RN
128/**
129 * Detect when Viking is run for the very first time
130 * Call this very early in the startup sequence to ensure subsequent correct results
131 * The return value is cached, since later on the test will no longer be true
132 */
133gboolean a_vik_very_first_run ()
134{
135 static gboolean vik_very_first_run_known = FALSE;
136 static gboolean vik_very_first_run = FALSE;
137
138 // use cached result if available
139 if ( vik_very_first_run_known )
140 return vik_very_first_run;
141
142 gchar *dir = a_get_viking_dir_no_create();
143 // NB: will need extra logic if default dir gets changed e.g. from ~/.viking to ~/.config/viking
144 if ( dir ) {
145 // If directory exists - Viking has been run before
146 vik_very_first_run = ! g_file_test ( dir, G_FILE_TEST_EXISTS );
147 g_free ( dir );
148 }
149 else
150 vik_very_first_run = TRUE;
151 vik_very_first_run_known = TRUE;
152
153 return vik_very_first_run;
154}
155
a58aaed4
GB
156void a_vik_preferences_init ()
157{
6cdf89e5
RN
158 g_debug ( "VIKING VERSION as number: %d", viking_version_to_number (VIKING_VERSION) );
159
f02faa96 160 // Defaults for the options are setup here
1b03d66d 161 a_preferences_register_group ( VIKING_PREFERENCES_GROUP_KEY, _("General") );
a58aaed4
GB
162
163 VikLayerParamData tmp;
164 tmp.u = VIK_DEGREE_FORMAT_DMS;
4fe48116 165 a_preferences_register(&general_prefs[0], tmp, VIKING_PREFERENCES_GROUP_KEY);
6f9336aa
RN
166
167 tmp.u = VIK_UNITS_DISTANCE_KILOMETRES;
4fe48116 168 a_preferences_register(&general_prefs[1], tmp, VIKING_PREFERENCES_GROUP_KEY);
13bdea80
RN
169
170 tmp.u = VIK_UNITS_SPEED_KILOMETRES_PER_HOUR;
4fe48116 171 a_preferences_register(&general_prefs[2], tmp, VIKING_PREFERENCES_GROUP_KEY);
6027a9c5
RN
172
173 tmp.u = VIK_UNITS_HEIGHT_METRES;
4fe48116 174 a_preferences_register(&general_prefs[3], tmp, VIKING_PREFERENCES_GROUP_KEY);
9be0449f
RN
175
176 tmp.b = TRUE;
4fe48116 177 a_preferences_register(&general_prefs[4], tmp, VIKING_PREFERENCES_GROUP_KEY);
5210c3d3
GB
178
179 /* Maintain the default location to New York */
180 tmp.d = 40.714490;
4fe48116 181 a_preferences_register(&general_prefs[5], tmp, VIKING_PREFERENCES_GROUP_KEY);
5210c3d3 182 tmp.d = -74.007130;
4fe48116 183 a_preferences_register(&general_prefs[6], tmp, VIKING_PREFERENCES_GROUP_KEY);
2702f416 184
b49d8528
RN
185 // New Tab
186 a_preferences_register_group ( VIKING_PREFERENCES_STARTUP_GROUP_KEY, _("Startup") );
187
1219fd23
RN
188 tmp.b = FALSE;
189 a_preferences_register(&startup_prefs[0], tmp, VIKING_PREFERENCES_STARTUP_GROUP_KEY);
190
8fa25c61
RN
191 tmp.b = FALSE;
192 a_preferences_register(&startup_prefs[1], tmp, VIKING_PREFERENCES_STARTUP_GROUP_KEY);
193
7143d1e4
RN
194 tmp.u = VIK_STARTUP_METHOD_HOME_LOCATION;
195 a_preferences_register(&startup_prefs[2], tmp, VIKING_PREFERENCES_STARTUP_GROUP_KEY);
196
197 tmp.s = "";
198 a_preferences_register(&startup_prefs[3], tmp, VIKING_PREFERENCES_STARTUP_GROUP_KEY);
199
2702f416
RN
200 // New Tab
201 a_preferences_register_group ( VIKING_PREFERENCES_IO_GROUP_KEY, _("Export/External") );
60dbd0ad
RN
202
203 tmp.u = VIK_KML_EXPORT_UNITS_METRIC;
204 a_preferences_register(&io_prefs[0], tmp, VIKING_PREFERENCES_IO_GROUP_KEY);
3317dc4e 205
d13f1a57
RN
206 tmp.u = VIK_GPX_EXPORT_TRK_SORT_TIME;
207 a_preferences_register(&io_prefs[1], tmp, VIKING_PREFERENCES_IO_GROUP_KEY);
208
5f2a108d 209 tmp.b = VIK_GPX_EXPORT_WPT_SYM_NAME_TITLECASE;
72f067ad
RN
210 a_preferences_register(&io_prefs[2], tmp, VIKING_PREFERENCES_IO_GROUP_KEY);
211
3317dc4e 212#ifndef WINDOWS
0b386bf3 213 tmp.s = "xdg-open";
3317dc4e
RN
214 a_preferences_register(&io_prefs_non_windows[0], tmp, VIKING_PREFERENCES_IO_GROUP_KEY);
215#endif
ccccf356 216
1e6db2e3 217 // JOSM for OSM editing around a GPX track
ccccf356
RN
218 tmp.s = "josm";
219 a_preferences_register(&io_prefs_external_gpx[0], tmp, VIKING_PREFERENCES_IO_GROUP_KEY);
ff02058b
RN
220 // Add a second external program - another OSM editor by default
221 tmp.s = "merkaartor";
222 a_preferences_register(&io_prefs_external_gpx[1], tmp, VIKING_PREFERENCES_IO_GROUP_KEY);
29277258
RN
223
224 // 'Advanced' Properties
225 a_preferences_register_group ( VIKING_PREFERENCES_ADVANCED_GROUP_KEY, _("Advanced") );
88542aa9
RN
226
227 tmp.u = VIK_FILE_REF_FORMAT_ABSOLUTE;
228 a_preferences_register(&prefs_advanced[0], tmp, VIKING_PREFERENCES_ADVANCED_GROUP_KEY);
90611609
RN
229
230 tmp.b = TRUE;
231 a_preferences_register(&prefs_advanced[1], tmp, VIKING_PREFERENCES_ADVANCED_GROUP_KEY);
a58aaed4
GB
232}
233
234vik_degree_format_t a_vik_get_degree_format ( )
235{
236 vik_degree_format_t format;
237 format = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "degree_format")->u;
238 return format;
a58aaed4 239}
6f9336aa
RN
240
241vik_units_distance_t a_vik_get_units_distance ( )
242{
243 vik_units_distance_t units;
244 units = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "units_distance")->u;
245 return units;
246}
13bdea80
RN
247
248vik_units_speed_t a_vik_get_units_speed ( )
249{
250 vik_units_speed_t units;
251 units = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "units_speed")->u;
252 return units;
253}
6027a9c5
RN
254
255vik_units_height_t a_vik_get_units_height ( )
256{
257 vik_units_height_t units;
258 units = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "units_height")->u;
259 return units;
260}
9be0449f
RN
261
262gboolean a_vik_get_use_large_waypoint_icons ( )
263{
264 gboolean use_large_waypoint_icons;
265 use_large_waypoint_icons = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "use_large_waypoint_icons")->b;
266 return use_large_waypoint_icons;
267}
5210c3d3
GB
268
269gdouble a_vik_get_default_lat ( )
270{
271 gdouble data;
272 data = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "default_latitude")->d;
273 return data;
274}
275
276gdouble a_vik_get_default_long ( )
277{
278 gdouble data;
279 data = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "default_longitude")->d;
280 return data;
281}
60dbd0ad
RN
282
283/* External/Export Options */
284
285vik_kml_export_units_t a_vik_get_kml_export_units ( )
286{
287 vik_kml_export_units_t units;
71eede92 288 units = a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "kml_export_units")->u;
60dbd0ad
RN
289 return units;
290}
3317dc4e 291
d13f1a57
RN
292vik_gpx_export_trk_sort_t a_vik_get_gpx_export_trk_sort ( )
293{
294 vik_gpx_export_trk_sort_t sort;
295 sort = a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "gpx_export_track_sort")->u;
296 return sort;
297}
298
72f067ad
RN
299vik_gpx_export_wpt_sym_name_t a_vik_gpx_export_wpt_sym_name ( )
300{
301 gboolean val;
5f2a108d 302 val = a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "gpx_export_wpt_sym_names")->b;
72f067ad
RN
303 return val;
304}
305
3317dc4e
RN
306#ifndef WINDOWS
307const gchar* a_vik_get_image_viewer ( )
308{
309 return a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "image_viewer")->s;
310}
311#endif
ccccf356
RN
312
313const gchar* a_vik_get_external_gpx_program_1 ( )
314{
315 return a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "external_gpx_1")->s;
316}
ff02058b
RN
317
318const gchar* a_vik_get_external_gpx_program_2 ( )
319{
320 return a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "external_gpx_2")->s;
321}
88542aa9
RN
322
323vik_file_ref_format_t a_vik_get_file_ref_format ( )
324{
325 vik_file_ref_format_t format;
326 format = a_preferences_get(VIKING_PREFERENCES_ADVANCED_NAMESPACE "save_file_reference_mode")->u;
327 return format;
328}
90611609
RN
329
330gboolean a_vik_get_create_track_tooltip ( )
331{
332 return a_preferences_get(VIKING_PREFERENCES_ADVANCED_NAMESPACE "create_track_tooltip")->b;
333}
1219fd23
RN
334
335// Startup Options
336gboolean a_vik_get_restore_window_state ( )
337{
338 gboolean data;
339 data = a_preferences_get(VIKING_PREFERENCES_STARTUP_NAMESPACE "restore_window_state")->b;
340 return data;
341}
8fa25c61
RN
342
343gboolean a_vik_get_add_default_map_layer ( )
344{
345 gboolean data;
346 data = a_preferences_get(VIKING_PREFERENCES_STARTUP_NAMESPACE "add_default_map_layer")->b;
347 return data;
348}
7143d1e4
RN
349
350vik_startup_method_t a_vik_get_startup_method ( )
351{
352 vik_startup_method_t data;
353 data = a_preferences_get(VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_method")->u;
354 return data;
355}
356
357const gchar *a_vik_get_startup_file ( )
358{
359 return a_preferences_get(VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_file")->s;
360}