]>
Commit | Line | Data |
---|---|---|
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" |
a58aaed4 | 34 | #include "globals.h" |
55ddef4e | 35 | #include "vikmapslayer.h" |
50a14534 | 36 | |
a5c8699d EB |
37 | #ifdef VIK_CONFIG_GEOCACHES |
38 | void a_datasource_gc_init(); | |
39 | #endif | |
40 | ||
51539ae0 | 41 | #ifdef HAVE_STDLIB_H |
fd0a7199 | 42 | #include <stdlib.h> |
51539ae0 GB |
43 | #endif |
44 | #ifdef HAVE_STRING_H | |
50a14534 | 45 | #include <string.h> |
51539ae0 | 46 | #endif |
50a14534 | 47 | |
57e87d1d | 48 | #include <glib/gprintf.h> |
a5daec1c | 49 | #include <glib/gi18n.h> |
57e87d1d | 50 | |
cdcaf41c QT |
51 | #include "modules.h" |
52 | ||
50a14534 EB |
53 | #define MAX_WINDOWS 1024 |
54 | ||
6c6f8d24 MA |
55 | /* FIXME LOCALEDIR must be configured by ./configure --localedir */ |
56 | /* But something does not work actually. */ | |
57 | /* So, we need to redefine this variable on windows. */ | |
58 | #ifdef WINDOWS | |
59 | #undef LOCALEDIR | |
60 | #define LOCALEDIR "locale" | |
61 | #endif | |
62 | ||
50a14534 EB |
63 | static guint window_count = 0; |
64 | ||
65 | static VikWindow *new_window (); | |
08812b09 | 66 | static void open_window ( VikWindow *vw, GSList *files ); |
90142302 | 67 | static void statusbar_update ( VikWindow *vw, const gchar *message ); |
50a14534 EB |
68 | static void destroy( GtkWidget *widget, |
69 | gpointer data ); | |
70 | ||
14b9e3a4 GB |
71 | #if GLIB_CHECK_VERSION (2, 32, 0) |
72 | /* Callback to log message */ | |
73 | static void log_debug(const gchar *log_domain, | |
74 | GLogLevelFlags log_level, | |
75 | const gchar *message, | |
76 | gpointer user_data) | |
77 | { | |
78 | g_print("** (viking): DEBUG: %s\n", message); | |
79 | } | |
80 | #else | |
2936913d GB |
81 | /* Callback to mute log message */ |
82 | static void mute_log(const gchar *log_domain, | |
83 | GLogLevelFlags log_level, | |
84 | const gchar *message, | |
85 | gpointer user_data) | |
86 | { | |
87 | /* Nothing to do, we just want to mute */ | |
88 | } | |
14b9e3a4 | 89 | #endif |
50a14534 EB |
90 | |
91 | /* Another callback */ | |
92 | static void destroy( GtkWidget *widget, | |
93 | gpointer data ) | |
94 | { | |
95 | if ( ! --window_count ) | |
96 | gtk_main_quit (); | |
97 | } | |
98 | ||
90142302 RN |
99 | // Only here because other signal handlers are! |
100 | // TODO: why can't we just move all these into VikWindow and be done with it?! | |
101 | static void statusbar_update ( VikWindow *vw, const gchar *message ) | |
102 | { | |
103 | vik_window_statusbar_update ( vw, message ); | |
104 | } | |
105 | ||
50a14534 EB |
106 | static VikWindow *new_window () |
107 | { | |
108 | if ( window_count < MAX_WINDOWS ) | |
109 | { | |
110 | VikWindow *vw = vik_window_new (); | |
111 | ||
112 | g_signal_connect (G_OBJECT (vw), "destroy", | |
113 | G_CALLBACK (destroy), NULL); | |
114 | g_signal_connect (G_OBJECT (vw), "newwindow", | |
115 | G_CALLBACK (new_window), NULL); | |
116 | g_signal_connect (G_OBJECT (vw), "openwindow", | |
117 | G_CALLBACK (open_window), NULL); | |
90142302 RN |
118 | g_signal_connect (G_OBJECT (vw), "statusbarupdate", |
119 | G_CALLBACK (statusbar_update), NULL); | |
50a14534 EB |
120 | |
121 | gtk_widget_show_all ( GTK_WIDGET(vw) ); | |
122 | ||
123 | window_count++; | |
124 | ||
125 | return vw; | |
126 | } | |
127 | return NULL; | |
128 | } | |
129 | ||
08812b09 | 130 | static void open_window ( VikWindow *vw, GSList *files ) |
50a14534 | 131 | { |
08812b09 RN |
132 | gboolean change_fn = (g_slist_length(files) == 1); /* only change fn if one file */ |
133 | GSList *cur_file = files; | |
134 | while ( cur_file ) { | |
49bf732a | 135 | // Only open a new window if a viking file |
08812b09 RN |
136 | gchar *file_name = cur_file->data; |
137 | if (vw != NULL && check_file_magic_vik ( file_name ) ) { | |
49bf732a RN |
138 | VikWindow *newvw = new_window(); |
139 | if (newvw) | |
08812b09 | 140 | vik_window_open_file ( newvw, file_name, change_fn ); |
50a14534 | 141 | } |
49bf732a | 142 | else { |
08812b09 | 143 | vik_window_open_file ( vw, file_name, change_fn ); |
49bf732a | 144 | } |
08812b09 RN |
145 | g_free (file_name); |
146 | cur_file = g_slist_next (cur_file); | |
49bf732a | 147 | } |
08812b09 | 148 | g_slist_free (files); |
50a14534 EB |
149 | } |
150 | ||
53c54171 | 151 | /* Options */ |
fd0a7199 GB |
152 | static GOptionEntry entries[] = |
153 | { | |
2936913d GB |
154 | { "debug", 'd', 0, G_OPTION_ARG_NONE, &vik_debug, N_("Enable debug output"), NULL }, |
155 | { "verbose", 'V', 0, G_OPTION_ARG_NONE, &vik_verbose, N_("Enable verbose output"), NULL }, | |
156 | { "version", 'v', 0, G_OPTION_ARG_NONE, &vik_version, N_("Show version"), NULL }, | |
fd0a7199 GB |
157 | { NULL } |
158 | }; | |
159 | ||
50a14534 EB |
160 | int main( int argc, char *argv[] ) |
161 | { | |
162 | VikWindow *first_window; | |
260703bf | 163 | GdkPixbuf *main_icon; |
50a14534 EB |
164 | gboolean dashdash_already = FALSE; |
165 | int i = 0; | |
fd0a7199 GB |
166 | GError *error = NULL; |
167 | gboolean gui_initialized; | |
a5daec1c GB |
168 | |
169 | bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); | |
170 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); | |
171 | textdomain (GETTEXT_PACKAGE); | |
50a14534 EB |
172 | |
173 | g_thread_init ( NULL ); | |
174 | gdk_threads_init (); | |
175 | ||
fd0a7199 GB |
176 | gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error); |
177 | if (!gui_initialized) | |
178 | { | |
179 | /* check if we have an error message */ | |
180 | if (error == NULL) | |
181 | { | |
182 | /* no error message, the GUI initialization failed */ | |
183 | const gchar *display_name = gdk_get_display_arg_name (); | |
184 | g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " "); | |
185 | } | |
186 | else | |
187 | { | |
188 | /* yep, there's an error, so print it */ | |
189 | g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message); | |
190 | g_error_free (error); | |
191 | g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]); | |
192 | } | |
193 | return EXIT_FAILURE; | |
194 | } | |
53c54171 | 195 | |
2936913d | 196 | if (vik_version) |
53c54171 | 197 | { |
c07c1db2 | 198 | g_printf ("%s %s\nCopyright (c) 2003-2008 Evan Battaglia\nCopyright (c) 2008-2012 Viking's contributors\n", PACKAGE_NAME, PACKAGE_VERSION); |
53c54171 GB |
199 | return EXIT_SUCCESS; |
200 | } | |
50a14534 | 201 | |
14b9e3a4 GB |
202 | #if GLIB_CHECK_VERSION (2, 32, 0) |
203 | if (vik_debug) | |
204 | g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL); | |
205 | #else | |
2936913d GB |
206 | if (!vik_debug) |
207 | g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL); | |
14b9e3a4 | 208 | #endif |
2936913d | 209 | |
843b99df GB |
210 | a_preferences_init (); |
211 | ||
a58aaed4 GB |
212 | a_vik_preferences_init (); |
213 | ||
6693f5f9 GB |
214 | a_download_init(); |
215 | curl_download_init(); | |
216 | ||
18ec873d GB |
217 | a_babel_init (); |
218 | ||
cdcaf41c QT |
219 | /* Init modules/plugins */ |
220 | modules_init(); | |
221 | ||
55ddef4e | 222 | maps_layer_init (); |
50a14534 EB |
223 | a_mapcache_init (); |
224 | a_background_init (); | |
a5c8699d EB |
225 | |
226 | #ifdef VIK_CONFIG_GEOCACHES | |
227 | a_datasource_gc_init(); | |
228 | #endif | |
229 | ||
260703bf | 230 | /* Set the icon */ |
10f9bcb6 | 231 | main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL); |
260703bf GB |
232 | gtk_window_set_default_icon(main_icon); |
233 | ||
234 | /* Create the first window */ | |
50a14534 EB |
235 | first_window = new_window(); |
236 | ||
237 | gdk_threads_enter (); | |
238 | while ( ++i < argc ) { | |
239 | if ( strcmp(argv[i],"--") == 0 && !dashdash_already ) | |
240 | dashdash_already = TRUE; /* hack to open '-' */ | |
241 | else | |
242 | vik_window_open_file ( first_window, argv[i], argc == 2 ); | |
243 | } | |
244 | ||
245 | gtk_main (); | |
246 | gdk_threads_leave (); | |
247 | ||
18ec873d GB |
248 | a_babel_uninit (); |
249 | ||
f5e80a61 | 250 | a_background_uninit (); |
50a14534 | 251 | a_mapcache_uninit (); |
ad0a8c2d | 252 | a_dems_uninit (); |
17a1f8f9 | 253 | a_preferences_uninit (); |
50a14534 | 254 | |
3eba9bbf RN |
255 | curl_download_uninit(); |
256 | ||
50a14534 EB |
257 | return 0; |
258 | } |