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