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