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