]>
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> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | ||
a5daec1c GB |
22 | #ifdef HAVE_CONFIG |
23 | #include "config.h" | |
24 | #endif /* HAVE_CONFIG */ | |
25 | ||
50a14534 | 26 | #include "viking.h" |
b6e6dfbd | 27 | #include "icons/icons.h" |
50a14534 EB |
28 | #include "mapcache.h" |
29 | #include "background.h" | |
ad0a8c2d | 30 | #include "dems.h" |
18ec873d | 31 | #include "babel.h" |
94a036d4 | 32 | #include "curl_download.h" |
17a1f8f9 | 33 | #include "preferences.h" |
a7023a1b | 34 | #include "viklayer_defaults.h" |
a58aaed4 | 35 | #include "globals.h" |
55ddef4e | 36 | #include "vikmapslayer.h" |
3bd57299 | 37 | #include "vikgeoreflayer.h" |
9f30939a | 38 | #include "vikrouting.h" |
44871dd1 | 39 | #include "util.h" |
75b7457a | 40 | #include "toolbar.h" |
50a14534 | 41 | |
51539ae0 | 42 | #ifdef HAVE_STDLIB_H |
fd0a7199 | 43 | #include <stdlib.h> |
51539ae0 GB |
44 | #endif |
45 | #ifdef HAVE_STRING_H | |
50a14534 | 46 | #include <string.h> |
51539ae0 | 47 | #endif |
50a14534 | 48 | |
57e87d1d | 49 | #include <glib/gprintf.h> |
a5daec1c | 50 | #include <glib/gi18n.h> |
57e87d1d | 51 | |
cdcaf41c QT |
52 | #include "modules.h" |
53 | ||
6c6f8d24 MA |
54 | /* FIXME LOCALEDIR must be configured by ./configure --localedir */ |
55 | /* But something does not work actually. */ | |
56 | /* So, we need to redefine this variable on windows. */ | |
57 | #ifdef WINDOWS | |
58 | #undef LOCALEDIR | |
59 | #define LOCALEDIR "locale" | |
60 | #endif | |
61 | ||
5cd09d57 RN |
62 | #ifdef HAVE_X11_XLIB_H |
63 | #include "X11/Xlib.h" | |
64 | #endif | |
65 | ||
14b9e3a4 GB |
66 | #if GLIB_CHECK_VERSION (2, 32, 0) |
67 | /* Callback to log message */ | |
68 | static void log_debug(const gchar *log_domain, | |
69 | GLogLevelFlags log_level, | |
70 | const gchar *message, | |
71 | gpointer user_data) | |
72 | { | |
73 | g_print("** (viking): DEBUG: %s\n", message); | |
74 | } | |
75 | #else | |
2936913d GB |
76 | /* Callback to mute log message */ |
77 | static void mute_log(const gchar *log_domain, | |
78 | GLogLevelFlags log_level, | |
79 | const gchar *message, | |
80 | gpointer user_data) | |
81 | { | |
82 | /* Nothing to do, we just want to mute */ | |
83 | } | |
14b9e3a4 | 84 | #endif |
50a14534 | 85 | |
5cd09d57 RN |
86 | #if HAVE_X11_XLIB_H |
87 | static int myXErrorHandler(Display *display, XErrorEvent *theEvent) | |
88 | { | |
d5819fad RN |
89 | (void)g_fprintf (stderr, |
90 | _("Ignoring Xlib error: error code %d request code %d\n"), | |
91 | theEvent->error_code, | |
92 | theEvent->request_code); | |
5cd09d57 RN |
93 | // No exit on X errors! |
94 | // mainly to handle out of memory error when requesting large pixbuf from user request | |
95 | // see vikwindow.c::save_image_file () | |
96 | return 0; | |
97 | } | |
98 | #endif | |
99 | ||
c12d4347 RN |
100 | // Default values that won't actually get applied unless changed by command line parameter values |
101 | static gdouble latitude = 0.0; | |
102 | static gdouble longitude = 0.0; | |
103 | static gint zoom_level_osm = -1; | |
104 | static gint map_id = -1; | |
105 | ||
53c54171 | 106 | /* Options */ |
fd0a7199 GB |
107 | static GOptionEntry entries[] = |
108 | { | |
2936913d GB |
109 | { "debug", 'd', 0, G_OPTION_ARG_NONE, &vik_debug, N_("Enable debug output"), NULL }, |
110 | { "verbose", 'V', 0, G_OPTION_ARG_NONE, &vik_verbose, N_("Enable verbose output"), NULL }, | |
111 | { "version", 'v', 0, G_OPTION_ARG_NONE, &vik_version, N_("Show version"), NULL }, | |
c12d4347 RN |
112 | { "latitude", 0, 0, G_OPTION_ARG_DOUBLE, &latitude, N_("Latitude in decimal degrees"), NULL }, |
113 | { "longitude", 0, 0, G_OPTION_ARG_DOUBLE, &longitude, N_("Longitude in decimal degrees"), NULL }, | |
114 | { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom_level_osm, N_("Zoom Level (OSM). Value can be 0 - 22"), NULL }, | |
115 | { "map", 'm', 0, G_OPTION_ARG_INT, &map_id, N_("Add a map layer by id value. Use 0 for the default map."), NULL }, | |
fd0a7199 GB |
116 | { NULL } |
117 | }; | |
118 | ||
50a14534 EB |
119 | int main( int argc, char *argv[] ) |
120 | { | |
121 | VikWindow *first_window; | |
260703bf | 122 | GdkPixbuf *main_icon; |
50a14534 EB |
123 | gboolean dashdash_already = FALSE; |
124 | int i = 0; | |
fd0a7199 GB |
125 | GError *error = NULL; |
126 | gboolean gui_initialized; | |
a5daec1c GB |
127 | |
128 | bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); | |
129 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); | |
130 | textdomain (GETTEXT_PACKAGE); | |
50a14534 | 131 | |
b832ea69 | 132 | #if ! GLIB_CHECK_VERSION (2, 32, 0) |
50a14534 | 133 | g_thread_init ( NULL ); |
b832ea69 | 134 | #endif |
50a14534 | 135 | |
fd0a7199 GB |
136 | gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error); |
137 | if (!gui_initialized) | |
138 | { | |
139 | /* check if we have an error message */ | |
140 | if (error == NULL) | |
141 | { | |
142 | /* no error message, the GUI initialization failed */ | |
143 | const gchar *display_name = gdk_get_display_arg_name (); | |
d5819fad | 144 | (void)g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " "); |
fd0a7199 GB |
145 | } |
146 | else | |
147 | { | |
148 | /* yep, there's an error, so print it */ | |
d5819fad | 149 | (void)g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message); |
fd0a7199 | 150 | g_error_free (error); |
d5819fad | 151 | (void)g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]); |
fd0a7199 GB |
152 | } |
153 | return EXIT_FAILURE; | |
154 | } | |
53c54171 | 155 | |
2936913d | 156 | if (vik_version) |
53c54171 | 157 | { |
14dd983a | 158 | (void)g_printf (_("%s %s\nCopyright (c) 2003-2008 Evan Battaglia\nCopyright (c) 2008-%s Viking's contributors\n"), PACKAGE_NAME, PACKAGE_VERSION, THEYEAR); |
53c54171 GB |
159 | return EXIT_SUCCESS; |
160 | } | |
50a14534 | 161 | |
14b9e3a4 GB |
162 | #if GLIB_CHECK_VERSION (2, 32, 0) |
163 | if (vik_debug) | |
164 | g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL); | |
165 | #else | |
2936913d GB |
166 | if (!vik_debug) |
167 | g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL); | |
14b9e3a4 | 168 | #endif |
2936913d | 169 | |
5cd09d57 RN |
170 | #if HAVE_X11_XLIB_H |
171 | XSetErrorHandler(myXErrorHandler); | |
172 | #endif | |
173 | ||
2a0372d1 RN |
174 | // Ensure correct capitalization of the program name |
175 | g_set_application_name ("Viking"); | |
176 | ||
20015a31 RN |
177 | // Discover if this is the very first run |
178 | a_vik_very_first_run (); | |
179 | ||
66b23637 | 180 | a_settings_init (); |
843b99df GB |
181 | a_preferences_init (); |
182 | ||
e530cc9f RN |
183 | /* |
184 | * First stage initialization | |
185 | * | |
186 | * Should not use a_preferences_get() yet | |
187 | * | |
188 | * Since the first time a_preferences_get() is called it loads any preferences values from disk, | |
189 | * but of course for preferences not registered yet it can't actually understand them | |
190 | * so subsequent initial attempts to get those preferences return the default value, until the values have changed | |
191 | */ | |
a58aaed4 GB |
192 | a_vik_preferences_init (); |
193 | ||
a7023a1b RN |
194 | a_layer_defaults_init (); |
195 | ||
6693f5f9 GB |
196 | a_download_init(); |
197 | curl_download_init(); | |
198 | ||
18ec873d GB |
199 | a_babel_init (); |
200 | ||
cdcaf41c QT |
201 | /* Init modules/plugins */ |
202 | modules_init(); | |
203 | ||
3bd57299 | 204 | vik_georef_layer_init (); |
55ddef4e | 205 | maps_layer_init (); |
50a14534 EB |
206 | a_mapcache_init (); |
207 | a_background_init (); | |
a5c8699d | 208 | |
75b7457a | 209 | a_toolbar_init(); |
9f30939a GB |
210 | vik_routing_prefs_init(); |
211 | ||
e530cc9f RN |
212 | /* |
213 | * Second stage initialization | |
214 | * | |
215 | * Can now use a_preferences_get() | |
216 | */ | |
217 | a_background_post_init (); | |
218 | a_babel_post_init (); | |
219 | modules_post_init (); | |
220 | ||
221 | // May need to initialize the Positonal TimeZone lookup | |
74562734 RN |
222 | if ( a_vik_get_time_ref_frame() == VIK_TIME_REF_WORLD ) |
223 | vu_setup_lat_lon_tz_lookup(); | |
224 | ||
260703bf | 225 | /* Set the icon */ |
10f9bcb6 | 226 | main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL); |
260703bf GB |
227 | gtk_window_set_default_icon(main_icon); |
228 | ||
0d66c56c | 229 | // Ask for confirmation of default settings on first run |
5ab2942c | 230 | vu_set_auto_features_on_first_run (); |
0d66c56c | 231 | |
260703bf | 232 | /* Create the first window */ |
8a13dbd2 | 233 | first_window = vik_window_new_window(); |
50a14534 | 234 | |
5ab2942c | 235 | vu_check_latest_version ( GTK_WINDOW(first_window) ); |
91c46f90 | 236 | |
0c874f29 RN |
237 | // Load startup file first so that subsequent files are loaded on top |
238 | // Especially so that new tracks+waypoints will be above any maps in a startup file | |
239 | if ( a_vik_get_startup_method () == VIK_STARTUP_METHOD_SPECIFIED_FILE ) { | |
240 | gboolean load_startup_file = TRUE; | |
241 | // When a viking file is to be loaded via the command line | |
242 | // then we'll skip loading any startup file | |
243 | int jj = 0; | |
244 | while ( ++jj < argc ) { | |
245 | if ( check_file_magic_vik(argv[jj]) ) | |
246 | load_startup_file = FALSE; | |
247 | } | |
248 | if ( load_startup_file ) | |
249 | vik_window_open_file ( first_window, a_vik_get_startup_file(), TRUE ); | |
250 | } | |
251 | ||
50a14534 EB |
252 | while ( ++i < argc ) { |
253 | if ( strcmp(argv[i],"--") == 0 && !dashdash_already ) | |
254 | dashdash_already = TRUE; /* hack to open '-' */ | |
d4a8b54d RN |
255 | else { |
256 | VikWindow *newvw = first_window; | |
257 | gboolean change_filename = (i == 1); | |
258 | ||
259 | // Open any subsequent .vik files in their own window | |
260 | if ( i > 1 && check_file_magic_vik ( argv[i] ) ) { | |
261 | newvw = vik_window_new_window (); | |
262 | change_filename = TRUE; | |
263 | } | |
264 | ||
265 | vik_window_open_file ( newvw, argv[i], change_filename ); | |
266 | } | |
50a14534 EB |
267 | } |
268 | ||
8fa25c61 RN |
269 | vik_window_new_window_finish ( first_window ); |
270 | ||
c12d4347 RN |
271 | vu_command_line ( first_window, latitude, longitude, zoom_level_osm, map_id ); |
272 | ||
50a14534 | 273 | gtk_main (); |
50a14534 | 274 | |
18ec873d | 275 | a_babel_uninit (); |
75b7457a | 276 | a_toolbar_uninit (); |
f5e80a61 | 277 | a_background_uninit (); |
50a14534 | 278 | a_mapcache_uninit (); |
ad0a8c2d | 279 | a_dems_uninit (); |
a7023a1b | 280 | a_layer_defaults_uninit (); |
17a1f8f9 | 281 | a_preferences_uninit (); |
66b23637 | 282 | a_settings_uninit (); |
50a14534 | 283 | |
e3da2277 RN |
284 | modules_uninit(); |
285 | ||
3eba9bbf RN |
286 | curl_download_uninit(); |
287 | ||
74562734 RN |
288 | vu_finalize_lat_lon_tz_lookup (); |
289 | ||
44871dd1 RN |
290 | // Clean up any temporary files |
291 | util_remove_all_in_deletion_list (); | |
292 | ||
50a14534 EB |
293 | return 0; |
294 | } |