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"
31 #include "curl_download.h"
32 #include "preferences.h"
34 #include "vikmapslayer.h"
36 #ifdef VIK_CONFIG_GEOCACHES
37 void a_datasource_gc_init();
43 #include <glib/gprintf.h>
44 #include <glib/gi18n.h>
48 #define MAX_WINDOWS 1024
50 /* FIXME LOCALEDIR must be configured by ./configure --localedir */
51 /* But something does not work actually. */
52 /* So, we need to redefine this variable on windows. */
55 #define LOCALEDIR "locale"
58 static guint window_count = 0;
60 static VikWindow *new_window ();
61 static void open_window ( VikWindow *vw, const gchar **files );
62 static void destroy( GtkWidget *widget,
65 /* Callback to mute log message */
66 static void mute_log(const gchar *log_domain,
67 GLogLevelFlags log_level,
71 /* Nothing to do, we just want to mute */
74 /* Another callback */
75 static void destroy( GtkWidget *widget,
78 if ( ! --window_count )
82 static VikWindow *new_window ()
84 if ( window_count < MAX_WINDOWS )
86 VikWindow *vw = vik_window_new ();
88 g_signal_connect (G_OBJECT (vw), "destroy",
89 G_CALLBACK (destroy), NULL);
90 g_signal_connect (G_OBJECT (vw), "newwindow",
91 G_CALLBACK (new_window), NULL);
92 g_signal_connect (G_OBJECT (vw), "openwindow",
93 G_CALLBACK (open_window), NULL);
95 gtk_widget_show_all ( GTK_WIDGET(vw) );
104 static void open_window ( VikWindow *vw, const gchar **files )
106 VikWindow *newvw = new_window();
107 gboolean change_fn = (!files[1]); /* only change fn if one file */
110 vik_window_open_file ( newvw, *(files++), change_fn );
115 static GOptionEntry entries[] =
117 { "small_waypoint", 's', 0, G_OPTION_ARG_NONE, &vik_use_small_wp_icons, N_("Use smaller symbols for waypoints"), NULL },
118 { "debug", 'd', 0, G_OPTION_ARG_NONE, &vik_debug, N_("Enable debug output"), NULL },
119 { "verbose", 'V', 0, G_OPTION_ARG_NONE, &vik_verbose, N_("Enable verbose output"), NULL },
120 { "version", 'v', 0, G_OPTION_ARG_NONE, &vik_version, N_("Show version"), NULL },
124 int main( int argc, char *argv[] )
126 VikWindow *first_window;
127 GdkPixbuf *main_icon;
128 gboolean dashdash_already = FALSE;
130 GError *error = NULL;
131 gboolean gui_initialized;
133 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
134 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
135 textdomain (GETTEXT_PACKAGE);
137 g_thread_init ( NULL );
140 gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
141 if (!gui_initialized)
143 /* check if we have an error message */
146 /* no error message, the GUI initialization failed */
147 const gchar *display_name = gdk_get_display_arg_name ();
148 g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " ");
152 /* yep, there's an error, so print it */
153 g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message);
154 g_error_free (error);
155 g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]);
162 g_printf ("%s %s, Copyright (c) 2003-2008 Evan Battaglia\n", PACKAGE_NAME, PACKAGE_VERSION);
167 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL);
170 curl_download_init();
172 a_preferences_init ();
174 a_vik_preferences_init ();
176 /* Init modules/plugins */
181 a_background_init ();
183 #ifdef VIK_CONFIG_GEOCACHES
184 a_datasource_gc_init();
188 main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL);
189 gtk_window_set_default_icon(main_icon);
191 /* Create the first window */
192 first_window = new_window();
194 gdk_threads_enter ();
195 while ( ++i < argc ) {
196 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
197 dashdash_already = TRUE; /* hack to open '-' */
199 vik_window_open_file ( first_window, argv[i], argc == 2 );
203 gdk_threads_leave ();
205 a_background_uninit ();
206 a_mapcache_uninit ();
208 a_preferences_uninit ();