2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
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.
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.
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
24 #endif /* HAVE_CONFIG */
27 #include "icons/icons.h"
29 #include "background.h"
32 #include "curl_download.h"
33 #include "preferences.h"
34 #include "viklayer_defaults.h"
36 #include "vikmapslayer.h"
37 #include "vikrouting.h"
40 #ifdef VIK_CONFIG_GEOCACHES
41 void a_datasource_gc_init();
51 #include <glib/gprintf.h>
52 #include <glib/gi18n.h>
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. */
61 #define LOCALEDIR "locale"
64 #ifdef HAVE_X11_XLIB_H
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,
75 g_print("** (viking): DEBUG: %s\n", message);
78 /* Callback to mute log message */
79 static void mute_log(const gchar *log_domain,
80 GLogLevelFlags log_level,
84 /* Nothing to do, we just want to mute */
89 static int myXErrorHandler(Display *display, XErrorEvent *theEvent)
92 _("Ignoring Xlib error: error code %d request code %d\n"),
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 ()
103 static GOptionEntry entries[] =
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 },
111 int main( int argc, char *argv[] )
113 VikWindow *first_window;
114 GdkPixbuf *main_icon;
115 gboolean dashdash_already = FALSE;
117 GError *error = NULL;
118 gboolean gui_initialized;
120 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
121 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
122 textdomain (GETTEXT_PACKAGE);
124 #if ! GLIB_CHECK_VERSION (2, 32, 0)
125 g_thread_init ( NULL );
129 gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
130 if (!gui_initialized)
132 /* check if we have an error message */
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 : " ");
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]);
151 g_printf ("%s %s\nCopyright (c) 2003-2008 Evan Battaglia\nCopyright (c) 2008-2012 Viking's contributors\n", PACKAGE_NAME, PACKAGE_VERSION);
155 #if GLIB_CHECK_VERSION (2, 32, 0)
157 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL);
160 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL);
164 XSetErrorHandler(myXErrorHandler);
167 a_preferences_init ();
169 a_vik_preferences_init ();
171 a_layer_defaults_init ();
174 curl_download_init();
178 /* Init modules/plugins */
183 a_background_init ();
185 #ifdef VIK_CONFIG_GEOCACHES
186 a_datasource_gc_init();
189 vik_routing_prefs_init();
192 main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL);
193 gtk_window_set_default_icon(main_icon);
195 gdk_threads_enter ();
197 /* Create the first window */
198 first_window = vik_window_new_window();
200 check_latest_version ( GTK_WINDOW(first_window) );
202 while ( ++i < argc ) {
203 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
204 dashdash_already = TRUE; /* hack to open '-' */
206 VikWindow *newvw = first_window;
207 gboolean change_filename = (i == 1);
209 // Open any subsequent .vik files in their own window
210 if ( i > 1 && check_file_magic_vik ( argv[i] ) ) {
211 newvw = vik_window_new_window ();
212 change_filename = TRUE;
215 vik_window_open_file ( newvw, argv[i], change_filename );
220 gdk_threads_leave ();
224 a_background_uninit ();
225 a_mapcache_uninit ();
227 a_layer_defaults_uninit ();
228 a_preferences_uninit ();
230 curl_download_uninit();