]> git.street.me.uk Git - andy/viking.git/blame - src/main.c
Enable opening background jobs window from the status bar by clicking on the items...
[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"
18ec873d 31#include "babel.h"
94a036d4 32#include "curl_download.h"
17a1f8f9 33#include "preferences.h"
a7023a1b 34#include "viklayer_defaults.h"
a58aaed4 35#include "globals.h"
55ddef4e 36#include "vikmapslayer.h"
50a14534 37
a5c8699d
EB
38#ifdef VIK_CONFIG_GEOCACHES
39void a_datasource_gc_init();
40#endif
41
51539ae0 42#ifdef HAVE_STDLIB_H
fd0a7199 43#include <stdlib.h>
51539ae0
GB
44#endif
45#ifdef HAVE_STRING_H
50a14534 46#include <string.h>
51539ae0 47#endif
50a14534 48
57e87d1d 49#include <glib/gprintf.h>
a5daec1c 50#include <glib/gi18n.h>
57e87d1d 51
cdcaf41c
QT
52#include "modules.h"
53
6c6f8d24
MA
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. */
57#ifdef WINDOWS
58#undef LOCALEDIR
59#define LOCALEDIR "locale"
60#endif
61
5cd09d57
RN
62#ifdef HAVE_X11_XLIB_H
63#include "X11/Xlib.h"
64#endif
65
14b9e3a4
GB
66#if GLIB_CHECK_VERSION (2, 32, 0)
67/* Callback to log message */
68static void log_debug(const gchar *log_domain,
69 GLogLevelFlags log_level,
70 const gchar *message,
71 gpointer user_data)
72{
73 g_print("** (viking): DEBUG: %s\n", message);
74}
75#else
2936913d
GB
76/* Callback to mute log message */
77static void mute_log(const gchar *log_domain,
78 GLogLevelFlags log_level,
79 const gchar *message,
80 gpointer user_data)
81{
82 /* Nothing to do, we just want to mute */
83}
14b9e3a4 84#endif
50a14534 85
5cd09d57
RN
86#if HAVE_X11_XLIB_H
87static int myXErrorHandler(Display *display, XErrorEvent *theEvent)
88{
89 g_fprintf (stderr,
90 _("Ignoring Xlib error: error code %d request code %d\n"),
91 theEvent->error_code,
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 ()
96 return 0;
97}
98#endif
99
53c54171 100/* Options */
fd0a7199
GB
101static GOptionEntry entries[] =
102{
2936913d
GB
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 },
fd0a7199
GB
106 { NULL }
107};
108
50a14534
EB
109int main( int argc, char *argv[] )
110{
111 VikWindow *first_window;
260703bf 112 GdkPixbuf *main_icon;
50a14534
EB
113 gboolean dashdash_already = FALSE;
114 int i = 0;
fd0a7199
GB
115 GError *error = NULL;
116 gboolean gui_initialized;
a5daec1c
GB
117
118 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
119 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
120 textdomain (GETTEXT_PACKAGE);
50a14534
EB
121
122 g_thread_init ( NULL );
123 gdk_threads_init ();
124
fd0a7199
GB
125 gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
126 if (!gui_initialized)
127 {
128 /* check if we have an error message */
129 if (error == NULL)
130 {
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 : " ");
134 }
135 else
136 {
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]);
141 }
142 return EXIT_FAILURE;
143 }
53c54171 144
2936913d 145 if (vik_version)
53c54171 146 {
c07c1db2 147 g_printf ("%s %s\nCopyright (c) 2003-2008 Evan Battaglia\nCopyright (c) 2008-2012 Viking's contributors\n", PACKAGE_NAME, PACKAGE_VERSION);
53c54171
GB
148 return EXIT_SUCCESS;
149 }
50a14534 150
14b9e3a4
GB
151#if GLIB_CHECK_VERSION (2, 32, 0)
152 if (vik_debug)
153 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL);
154#else
2936913d
GB
155 if (!vik_debug)
156 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL);
14b9e3a4 157#endif
2936913d 158
5cd09d57
RN
159#if HAVE_X11_XLIB_H
160 XSetErrorHandler(myXErrorHandler);
161#endif
162
843b99df
GB
163 a_preferences_init ();
164
a58aaed4
GB
165 a_vik_preferences_init ();
166
a7023a1b
RN
167 a_layer_defaults_init ();
168
6693f5f9
GB
169 a_download_init();
170 curl_download_init();
171
18ec873d
GB
172 a_babel_init ();
173
cdcaf41c
QT
174 /* Init modules/plugins */
175 modules_init();
176
55ddef4e 177 maps_layer_init ();
50a14534
EB
178 a_mapcache_init ();
179 a_background_init ();
a5c8699d
EB
180
181#ifdef VIK_CONFIG_GEOCACHES
182 a_datasource_gc_init();
183#endif
184
260703bf 185 /* Set the icon */
10f9bcb6 186 main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL);
260703bf
GB
187 gtk_window_set_default_icon(main_icon);
188
189 /* Create the first window */
8a13dbd2 190 first_window = vik_window_new_window();
50a14534
EB
191
192 gdk_threads_enter ();
193 while ( ++i < argc ) {
194 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
195 dashdash_already = TRUE; /* hack to open '-' */
d4a8b54d
RN
196 else {
197 VikWindow *newvw = first_window;
198 gboolean change_filename = (i == 1);
199
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;
204 }
205
206 vik_window_open_file ( newvw, argv[i], change_filename );
207 }
50a14534
EB
208 }
209
210 gtk_main ();
211 gdk_threads_leave ();
212
18ec873d
GB
213 a_babel_uninit ();
214
f5e80a61 215 a_background_uninit ();
50a14534 216 a_mapcache_uninit ();
ad0a8c2d 217 a_dems_uninit ();
a7023a1b 218 a_layer_defaults_uninit ();
17a1f8f9 219 a_preferences_uninit ();
50a14534 220
3eba9bbf
RN
221 curl_download_uninit();
222
50a14534
EB
223 return 0;
224}