]> git.street.me.uk Git - andy/viking.git/blame - src/main.c
Add ability to turn off Garmin GPS after transfer.
[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"
94a036d4 31#include "curl_download.h"
17a1f8f9 32#include "preferences.h"
a58aaed4 33#include "globals.h"
55ddef4e 34#include "vikmapslayer.h"
50a14534 35
a5c8699d
EB
36#ifdef VIK_CONFIG_GEOCACHES
37void a_datasource_gc_init();
38#endif
39
fd0a7199 40#include <stdlib.h>
50a14534
EB
41#include <string.h>
42
57e87d1d 43#include <glib/gprintf.h>
a5daec1c 44#include <glib/gi18n.h>
57e87d1d 45
cdcaf41c
QT
46#include "modules.h"
47
50a14534
EB
48#define MAX_WINDOWS 1024
49
6c6f8d24
MA
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. */
53#ifdef WINDOWS
54#undef LOCALEDIR
55#define LOCALEDIR "locale"
56#endif
57
50a14534
EB
58static guint window_count = 0;
59
60static VikWindow *new_window ();
61static void open_window ( VikWindow *vw, const gchar **files );
62static void destroy( GtkWidget *widget,
63 gpointer data );
64
2936913d
GB
65/* Callback to mute log message */
66static void mute_log(const gchar *log_domain,
67 GLogLevelFlags log_level,
68 const gchar *message,
69 gpointer user_data)
70{
71 /* Nothing to do, we just want to mute */
72}
50a14534
EB
73
74/* Another callback */
75static void destroy( GtkWidget *widget,
76 gpointer data )
77{
78 if ( ! --window_count )
79 gtk_main_quit ();
80}
81
82static VikWindow *new_window ()
83{
84 if ( window_count < MAX_WINDOWS )
85 {
86 VikWindow *vw = vik_window_new ();
87
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);
94
95 gtk_widget_show_all ( GTK_WIDGET(vw) );
96
97 window_count++;
98
99 return vw;
100 }
101 return NULL;
102}
103
104static void open_window ( VikWindow *vw, const gchar **files )
105{
106 VikWindow *newvw = new_window();
107 gboolean change_fn = (!files[1]); /* only change fn if one file */
108 if ( newvw )
109 while ( *files ) {
110 vik_window_open_file ( newvw, *(files++), change_fn );
50a14534
EB
111 }
112}
113
53c54171 114/* Options */
fd0a7199
GB
115static GOptionEntry entries[] =
116{
2936913d
GB
117 { "debug", 'd', 0, G_OPTION_ARG_NONE, &vik_debug, N_("Enable debug output"), NULL },
118 { "verbose", 'V', 0, G_OPTION_ARG_NONE, &vik_verbose, N_("Enable verbose output"), NULL },
119 { "version", 'v', 0, G_OPTION_ARG_NONE, &vik_version, N_("Show version"), NULL },
fd0a7199
GB
120 { NULL }
121};
122
50a14534
EB
123int main( int argc, char *argv[] )
124{
125 VikWindow *first_window;
260703bf 126 GdkPixbuf *main_icon;
50a14534
EB
127 gboolean dashdash_already = FALSE;
128 int i = 0;
fd0a7199
GB
129 GError *error = NULL;
130 gboolean gui_initialized;
a5daec1c
GB
131
132 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
133 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
134 textdomain (GETTEXT_PACKAGE);
50a14534
EB
135
136 g_thread_init ( NULL );
137 gdk_threads_init ();
138
fd0a7199
GB
139 gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
140 if (!gui_initialized)
141 {
142 /* check if we have an error message */
143 if (error == NULL)
144 {
145 /* no error message, the GUI initialization failed */
146 const gchar *display_name = gdk_get_display_arg_name ();
147 g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " ");
148 }
149 else
150 {
151 /* yep, there's an error, so print it */
152 g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message);
153 g_error_free (error);
154 g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]);
155 }
156 return EXIT_FAILURE;
157 }
53c54171 158
2936913d 159 if (vik_version)
53c54171 160 {
8734a931 161 g_printf ("%s %s, Copyright (c) 2003-2008 Evan Battaglia\n", PACKAGE_NAME, PACKAGE_VERSION);
53c54171
GB
162 return EXIT_SUCCESS;
163 }
50a14534 164
2936913d
GB
165 if (!vik_debug)
166 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL);
167
843b99df
GB
168 a_preferences_init ();
169
a58aaed4
GB
170 a_vik_preferences_init ();
171
6693f5f9
GB
172 a_download_init();
173 curl_download_init();
174
cdcaf41c
QT
175 /* Init modules/plugins */
176 modules_init();
177
55ddef4e 178 maps_layer_init ();
50a14534
EB
179 a_mapcache_init ();
180 a_background_init ();
a5c8699d
EB
181
182#ifdef VIK_CONFIG_GEOCACHES
183 a_datasource_gc_init();
184#endif
185
260703bf 186 /* Set the icon */
10f9bcb6 187 main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL);
260703bf
GB
188 gtk_window_set_default_icon(main_icon);
189
190 /* Create the first window */
50a14534
EB
191 first_window = new_window();
192
193 gdk_threads_enter ();
194 while ( ++i < argc ) {
195 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
196 dashdash_already = TRUE; /* hack to open '-' */
197 else
198 vik_window_open_file ( first_window, argv[i], argc == 2 );
199 }
200
201 gtk_main ();
202 gdk_threads_leave ();
203
f5e80a61 204 a_background_uninit ();
50a14534 205 a_mapcache_uninit ();
ad0a8c2d 206 a_dems_uninit ();
17a1f8f9 207 a_preferences_uninit ();
50a14534
EB
208
209 return 0;
210}