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