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"
35 #include "vikmapslayer.h"
37 #ifdef VIK_CONFIG_GEOCACHES
38 void a_datasource_gc_init();
48 #include <glib/gprintf.h>
49 #include <glib/gi18n.h>
53 /* FIXME LOCALEDIR must be configured by ./configure --localedir */
54 /* But something does not work actually. */
55 /* So, we need to redefine this variable on windows. */
58 #define LOCALEDIR "locale"
61 #if GLIB_CHECK_VERSION (2, 32, 0)
62 /* Callback to log message */
63 static void log_debug(const gchar *log_domain,
64 GLogLevelFlags log_level,
68 g_print("** (viking): DEBUG: %s\n", message);
71 /* Callback to mute log message */
72 static void mute_log(const gchar *log_domain,
73 GLogLevelFlags log_level,
77 /* Nothing to do, we just want to mute */
82 static GOptionEntry entries[] =
84 { "debug", 'd', 0, G_OPTION_ARG_NONE, &vik_debug, N_("Enable debug output"), NULL },
85 { "verbose", 'V', 0, G_OPTION_ARG_NONE, &vik_verbose, N_("Enable verbose output"), NULL },
86 { "version", 'v', 0, G_OPTION_ARG_NONE, &vik_version, N_("Show version"), NULL },
90 int main( int argc, char *argv[] )
92 VikWindow *first_window;
94 gboolean dashdash_already = FALSE;
97 gboolean gui_initialized;
99 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
100 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
101 textdomain (GETTEXT_PACKAGE);
103 g_thread_init ( NULL );
106 gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
107 if (!gui_initialized)
109 /* check if we have an error message */
112 /* no error message, the GUI initialization failed */
113 const gchar *display_name = gdk_get_display_arg_name ();
114 g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " ");
118 /* yep, there's an error, so print it */
119 g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message);
120 g_error_free (error);
121 g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]);
128 g_printf ("%s %s\nCopyright (c) 2003-2008 Evan Battaglia\nCopyright (c) 2008-2012 Viking's contributors\n", PACKAGE_NAME, PACKAGE_VERSION);
132 #if GLIB_CHECK_VERSION (2, 32, 0)
134 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL);
137 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL);
140 a_preferences_init ();
142 a_vik_preferences_init ();
145 curl_download_init();
149 /* Init modules/plugins */
154 a_background_init ();
156 #ifdef VIK_CONFIG_GEOCACHES
157 a_datasource_gc_init();
161 main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL);
162 gtk_window_set_default_icon(main_icon);
164 /* Create the first window */
165 first_window = vik_window_new_window();
167 gdk_threads_enter ();
168 while ( ++i < argc ) {
169 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
170 dashdash_already = TRUE; /* hack to open '-' */
172 vik_window_open_file ( first_window, argv[i], argc == 2 );
176 gdk_threads_leave ();
180 a_background_uninit ();
181 a_mapcache_uninit ();
183 a_preferences_uninit ();
185 curl_download_uninit();