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