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"
38 #ifdef VIK_CONFIG_GEOCACHES
39 void a_datasource_gc_init();
49 #include <glib/gprintf.h>
50 #include <glib/gi18n.h>
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. */
59 #define LOCALEDIR "locale"
62 #ifdef HAVE_X11_XLIB_H
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,
73 g_print("** (viking): DEBUG: %s\n", message);
76 /* Callback to mute log message */
77 static void mute_log(const gchar *log_domain,
78 GLogLevelFlags log_level,
82 /* Nothing to do, we just want to mute */
87 static int myXErrorHandler(Display *display, XErrorEvent *theEvent)
90 _("Ignoring Xlib error: error code %d request code %d\n"),
92 theEvent->request_code);
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 ()
101 static GOptionEntry entries[] =
103 { "debug", 'd', 0, G_OPTION_ARG_NONE, &vik_debug, N_("Enable debug output"), NULL },
104 { "verbose", 'V', 0, G_OPTION_ARG_NONE, &vik_verbose, N_("Enable verbose output"), NULL },
105 { "version", 'v', 0, G_OPTION_ARG_NONE, &vik_version, N_("Show version"), NULL },
109 int main( int argc, char *argv[] )
111 VikWindow *first_window;
112 GdkPixbuf *main_icon;
113 gboolean dashdash_already = FALSE;
115 GError *error = NULL;
116 gboolean gui_initialized;
118 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
119 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
120 textdomain (GETTEXT_PACKAGE);
122 g_thread_init ( NULL );
125 gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
126 if (!gui_initialized)
128 /* check if we have an error message */
131 /* no error message, the GUI initialization failed */
132 const gchar *display_name = gdk_get_display_arg_name ();
133 g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " ");
137 /* yep, there's an error, so print it */
138 g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message);
139 g_error_free (error);
140 g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]);
147 g_printf ("%s %s\nCopyright (c) 2003-2008 Evan Battaglia\nCopyright (c) 2008-2012 Viking's contributors\n", PACKAGE_NAME, PACKAGE_VERSION);
151 #if GLIB_CHECK_VERSION (2, 32, 0)
153 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL);
156 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL);
160 XSetErrorHandler(myXErrorHandler);
163 a_preferences_init ();
165 a_vik_preferences_init ();
167 a_layer_defaults_init ();
170 curl_download_init();
174 /* Init modules/plugins */
179 a_background_init ();
181 #ifdef VIK_CONFIG_GEOCACHES
182 a_datasource_gc_init();
186 main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL);
187 gtk_window_set_default_icon(main_icon);
189 /* Create the first window */
190 first_window = vik_window_new_window();
192 gdk_threads_enter ();
193 while ( ++i < argc ) {
194 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
195 dashdash_already = TRUE; /* hack to open '-' */
197 VikWindow *newvw = first_window;
198 gboolean change_filename = (i == 1);
200 // Open any subsequent .vik files in their own window
201 if ( i > 1 && check_file_magic_vik ( argv[i] ) ) {
202 newvw = vik_window_new_window ();
203 change_filename = TRUE;
206 vik_window_open_file ( newvw, argv[i], change_filename );
211 gdk_threads_leave ();
215 a_background_uninit ();
216 a_mapcache_uninit ();
218 a_layer_defaults_uninit ();
219 a_preferences_uninit ();
221 curl_download_uninit();