]>
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" |
9f30939a | 37 | #include "vikrouting.h" |
5ab2942c | 38 | #include "vikutils.h" |
44871dd1 | 39 | #include "util.h" |
50a14534 | 40 | |
a5c8699d EB |
41 | #ifdef VIK_CONFIG_GEOCACHES |
42 | void a_datasource_gc_init(); | |
43 | #endif | |
44 | ||
51539ae0 | 45 | #ifdef HAVE_STDLIB_H |
fd0a7199 | 46 | #include <stdlib.h> |
51539ae0 GB |
47 | #endif |
48 | #ifdef HAVE_STRING_H | |
50a14534 | 49 | #include <string.h> |
51539ae0 | 50 | #endif |
50a14534 | 51 | |
57e87d1d | 52 | #include <glib/gprintf.h> |
a5daec1c | 53 | #include <glib/gi18n.h> |
57e87d1d | 54 | |
cdcaf41c QT |
55 | #include "modules.h" |
56 | ||
6c6f8d24 MA |
57 | /* FIXME LOCALEDIR must be configured by ./configure --localedir */ |
58 | /* But something does not work actually. */ | |
59 | /* So, we need to redefine this variable on windows. */ | |
60 | #ifdef WINDOWS | |
61 | #undef LOCALEDIR | |
62 | #define LOCALEDIR "locale" | |
63 | #endif | |
64 | ||
5cd09d57 RN |
65 | #ifdef HAVE_X11_XLIB_H |
66 | #include "X11/Xlib.h" | |
67 | #endif | |
68 | ||
14b9e3a4 GB |
69 | #if GLIB_CHECK_VERSION (2, 32, 0) |
70 | /* Callback to log message */ | |
71 | static void log_debug(const gchar *log_domain, | |
72 | GLogLevelFlags log_level, | |
73 | const gchar *message, | |
74 | gpointer user_data) | |
75 | { | |
76 | g_print("** (viking): DEBUG: %s\n", message); | |
77 | } | |
78 | #else | |
2936913d GB |
79 | /* Callback to mute log message */ |
80 | static void mute_log(const gchar *log_domain, | |
81 | GLogLevelFlags log_level, | |
82 | const gchar *message, | |
83 | gpointer user_data) | |
84 | { | |
85 | /* Nothing to do, we just want to mute */ | |
86 | } | |
14b9e3a4 | 87 | #endif |
50a14534 | 88 | |
5cd09d57 RN |
89 | #if HAVE_X11_XLIB_H |
90 | static int myXErrorHandler(Display *display, XErrorEvent *theEvent) | |
91 | { | |
92 | g_fprintf (stderr, | |
93 | _("Ignoring Xlib error: error code %d request code %d\n"), | |
94 | theEvent->error_code, | |
95 | theEvent->request_code); | |
96 | // No exit on X errors! | |
97 | // mainly to handle out of memory error when requesting large pixbuf from user request | |
98 | // see vikwindow.c::save_image_file () | |
99 | return 0; | |
100 | } | |
101 | #endif | |
102 | ||
53c54171 | 103 | /* Options */ |
fd0a7199 GB |
104 | static GOptionEntry entries[] = |
105 | { | |
2936913d GB |
106 | { "debug", 'd', 0, G_OPTION_ARG_NONE, &vik_debug, N_("Enable debug output"), NULL }, |
107 | { "verbose", 'V', 0, G_OPTION_ARG_NONE, &vik_verbose, N_("Enable verbose output"), NULL }, | |
108 | { "version", 'v', 0, G_OPTION_ARG_NONE, &vik_version, N_("Show version"), NULL }, | |
fd0a7199 GB |
109 | { NULL } |
110 | }; | |
111 | ||
50a14534 EB |
112 | int main( int argc, char *argv[] ) |
113 | { | |
114 | VikWindow *first_window; | |
260703bf | 115 | GdkPixbuf *main_icon; |
50a14534 EB |
116 | gboolean dashdash_already = FALSE; |
117 | int i = 0; | |
fd0a7199 GB |
118 | GError *error = NULL; |
119 | gboolean gui_initialized; | |
a5daec1c GB |
120 | |
121 | bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); | |
122 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); | |
123 | textdomain (GETTEXT_PACKAGE); | |
50a14534 | 124 | |
b832ea69 | 125 | #if ! GLIB_CHECK_VERSION (2, 32, 0) |
50a14534 | 126 | g_thread_init ( NULL ); |
b832ea69 | 127 | #endif |
50a14534 EB |
128 | gdk_threads_init (); |
129 | ||
fd0a7199 GB |
130 | gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error); |
131 | if (!gui_initialized) | |
132 | { | |
133 | /* check if we have an error message */ | |
134 | if (error == NULL) | |
135 | { | |
136 | /* no error message, the GUI initialization failed */ | |
137 | const gchar *display_name = gdk_get_display_arg_name (); | |
138 | g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " "); | |
139 | } | |
140 | else | |
141 | { | |
142 | /* yep, there's an error, so print it */ | |
143 | g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message); | |
144 | g_error_free (error); | |
145 | g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]); | |
146 | } | |
147 | return EXIT_FAILURE; | |
148 | } | |
53c54171 | 149 | |
2936913d | 150 | if (vik_version) |
53c54171 | 151 | { |
c07c1db2 | 152 | g_printf ("%s %s\nCopyright (c) 2003-2008 Evan Battaglia\nCopyright (c) 2008-2012 Viking's contributors\n", PACKAGE_NAME, PACKAGE_VERSION); |
53c54171 GB |
153 | return EXIT_SUCCESS; |
154 | } | |
50a14534 | 155 | |
14b9e3a4 GB |
156 | #if GLIB_CHECK_VERSION (2, 32, 0) |
157 | if (vik_debug) | |
158 | g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL); | |
159 | #else | |
2936913d GB |
160 | if (!vik_debug) |
161 | g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL); | |
14b9e3a4 | 162 | #endif |
2936913d | 163 | |
5cd09d57 RN |
164 | #if HAVE_X11_XLIB_H |
165 | XSetErrorHandler(myXErrorHandler); | |
166 | #endif | |
167 | ||
20015a31 RN |
168 | // Discover if this is the very first run |
169 | a_vik_very_first_run (); | |
170 | ||
66b23637 | 171 | a_settings_init (); |
843b99df GB |
172 | a_preferences_init (); |
173 | ||
a58aaed4 GB |
174 | a_vik_preferences_init (); |
175 | ||
a7023a1b RN |
176 | a_layer_defaults_init (); |
177 | ||
6693f5f9 GB |
178 | a_download_init(); |
179 | curl_download_init(); | |
180 | ||
18ec873d GB |
181 | a_babel_init (); |
182 | ||
cdcaf41c QT |
183 | /* Init modules/plugins */ |
184 | modules_init(); | |
185 | ||
55ddef4e | 186 | maps_layer_init (); |
50a14534 EB |
187 | a_mapcache_init (); |
188 | a_background_init (); | |
a5c8699d EB |
189 | |
190 | #ifdef VIK_CONFIG_GEOCACHES | |
191 | a_datasource_gc_init(); | |
192 | #endif | |
193 | ||
9f30939a GB |
194 | vik_routing_prefs_init(); |
195 | ||
74562734 RN |
196 | if ( a_vik_get_time_ref_frame() == VIK_TIME_REF_WORLD ) |
197 | vu_setup_lat_lon_tz_lookup(); | |
198 | ||
260703bf | 199 | /* Set the icon */ |
10f9bcb6 | 200 | main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL); |
260703bf GB |
201 | gtk_window_set_default_icon(main_icon); |
202 | ||
940e85ee RN |
203 | gdk_threads_enter (); |
204 | ||
0d66c56c | 205 | // Ask for confirmation of default settings on first run |
5ab2942c | 206 | vu_set_auto_features_on_first_run (); |
0d66c56c | 207 | |
260703bf | 208 | /* Create the first window */ |
8a13dbd2 | 209 | first_window = vik_window_new_window(); |
50a14534 | 210 | |
5ab2942c | 211 | vu_check_latest_version ( GTK_WINDOW(first_window) ); |
91c46f90 | 212 | |
50a14534 EB |
213 | while ( ++i < argc ) { |
214 | if ( strcmp(argv[i],"--") == 0 && !dashdash_already ) | |
215 | dashdash_already = TRUE; /* hack to open '-' */ | |
d4a8b54d RN |
216 | else { |
217 | VikWindow *newvw = first_window; | |
218 | gboolean change_filename = (i == 1); | |
219 | ||
220 | // Open any subsequent .vik files in their own window | |
221 | if ( i > 1 && check_file_magic_vik ( argv[i] ) ) { | |
222 | newvw = vik_window_new_window (); | |
223 | change_filename = TRUE; | |
224 | } | |
225 | ||
226 | vik_window_open_file ( newvw, argv[i], change_filename ); | |
227 | } | |
50a14534 EB |
228 | } |
229 | ||
8fa25c61 RN |
230 | vik_window_new_window_finish ( first_window ); |
231 | ||
50a14534 EB |
232 | gtk_main (); |
233 | gdk_threads_leave (); | |
234 | ||
18ec873d GB |
235 | a_babel_uninit (); |
236 | ||
f5e80a61 | 237 | a_background_uninit (); |
50a14534 | 238 | a_mapcache_uninit (); |
ad0a8c2d | 239 | a_dems_uninit (); |
a7023a1b | 240 | a_layer_defaults_uninit (); |
17a1f8f9 | 241 | a_preferences_uninit (); |
66b23637 | 242 | a_settings_uninit (); |
50a14534 | 243 | |
3eba9bbf RN |
244 | curl_download_uninit(); |
245 | ||
74562734 RN |
246 | vu_finalize_lat_lon_tz_lookup (); |
247 | ||
44871dd1 RN |
248 | // Clean up any temporary files |
249 | util_remove_all_in_deletion_list (); | |
250 | ||
50a14534 EB |
251 | return 0; |
252 | } |