]> git.street.me.uk Git - andy/viking.git/blame - src/main.c
SRTM download now works for regions outside North_America too.
[andy/viking.git] / src / main.c
CommitLineData
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
38static guint window_count = 0;
39
40static VikWindow *new_window ();
41static void open_window ( VikWindow *vw, const gchar **files );
42static void destroy( GtkWidget *widget,
43 gpointer data );
44
45
46/* Another callback */
47static void destroy( GtkWidget *widget,
48 gpointer data )
49{
50 if ( ! --window_count )
51 gtk_main_quit ();
52}
53
54static 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
76static 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
fd0a7199
GB
86static GOptionEntry entries[] =
87{
88 { NULL }
89};
90
50a14534
EB
91int main( int argc, char *argv[] )
92{
93 VikWindow *first_window;
260703bf 94 GdkPixbuf *main_icon;
50a14534
EB
95 gboolean dashdash_already = FALSE;
96 int i = 0;
fd0a7199
GB
97 GError *error = NULL;
98 gboolean gui_initialized;
50a14534
EB
99
100 g_thread_init ( NULL );
101 gdk_threads_init ();
102
fd0a7199
GB
103 gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
104 if (!gui_initialized)
105 {
106 /* check if we have an error message */
107 if (error == NULL)
108 {
109 /* no error message, the GUI initialization failed */
110 const gchar *display_name = gdk_get_display_arg_name ();
111 g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " ");
112 }
113 else
114 {
115 /* yep, there's an error, so print it */
116 g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message);
117 g_error_free (error);
118 g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]);
119 }
120 return EXIT_FAILURE;
121 }
50a14534 122
80d0ff2b 123 curl_download_init();
80d0ff2b 124
cdcaf41c
QT
125 /* Init modules/plugins */
126 modules_init();
127
50a14534
EB
128 a_mapcache_init ();
129 a_background_init ();
130
260703bf 131 /* Set the icon */
ef20e3f6 132 main_icon = gdk_pixbuf_from_pixdata(&viking_icon, FALSE, NULL);
260703bf
GB
133 gtk_window_set_default_icon(main_icon);
134
135 /* Create the first window */
50a14534
EB
136 first_window = new_window();
137
138 gdk_threads_enter ();
139 while ( ++i < argc ) {
140 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
141 dashdash_already = TRUE; /* hack to open '-' */
142 else
143 vik_window_open_file ( first_window, argv[i], argc == 2 );
144 }
145
146 gtk_main ();
147 gdk_threads_leave ();
148
50a14534 149 a_mapcache_uninit ();
ad0a8c2d 150 a_dems_uninit ();
50a14534
EB
151
152 return 0;
153}