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