]> git.street.me.uk Git - andy/viking.git/blame - src/main.c
Fix a bug that causes crashes when using "Maps Download" tool.
[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
EB
28
29#include <string.h>
30
cdcaf41c
QT
31#include "modules.h"
32
50a14534
EB
33#define MAX_WINDOWS 1024
34
35static guint window_count = 0;
36
37static VikWindow *new_window ();
38static void open_window ( VikWindow *vw, const gchar **files );
39static void destroy( GtkWidget *widget,
40 gpointer data );
41
42
43/* Another callback */
44static void destroy( GtkWidget *widget,
45 gpointer data )
46{
47 if ( ! --window_count )
48 gtk_main_quit ();
49}
50
51static VikWindow *new_window ()
52{
53 if ( window_count < MAX_WINDOWS )
54 {
55 VikWindow *vw = vik_window_new ();
56
57 g_signal_connect (G_OBJECT (vw), "destroy",
58 G_CALLBACK (destroy), NULL);
59 g_signal_connect (G_OBJECT (vw), "newwindow",
60 G_CALLBACK (new_window), NULL);
61 g_signal_connect (G_OBJECT (vw), "openwindow",
62 G_CALLBACK (open_window), NULL);
63
64 gtk_widget_show_all ( GTK_WIDGET(vw) );
65
66 window_count++;
67
68 return vw;
69 }
70 return NULL;
71}
72
73static void open_window ( VikWindow *vw, const gchar **files )
74{
75 VikWindow *newvw = new_window();
76 gboolean change_fn = (!files[1]); /* only change fn if one file */
77 if ( newvw )
78 while ( *files ) {
79 vik_window_open_file ( newvw, *(files++), change_fn );
50a14534
EB
80 }
81}
82
83int main( int argc, char *argv[] )
84{
85 VikWindow *first_window;
260703bf 86 GdkPixbuf *main_icon;
50a14534
EB
87 gboolean dashdash_already = FALSE;
88 int i = 0;
89
90 g_thread_init ( NULL );
91 gdk_threads_init ();
92
93 gtk_init (&argc, &argv);
94
80d0ff2b 95 curl_download_init();
80d0ff2b 96
cdcaf41c
QT
97 /* Init modules/plugins */
98 modules_init();
99
50a14534
EB
100 a_mapcache_init ();
101 a_background_init ();
102
260703bf 103 /* Set the icon */
ef20e3f6 104 main_icon = gdk_pixbuf_from_pixdata(&viking_icon, FALSE, NULL);
260703bf
GB
105 gtk_window_set_default_icon(main_icon);
106
107 /* Create the first window */
50a14534
EB
108 first_window = new_window();
109
110 gdk_threads_enter ();
111 while ( ++i < argc ) {
112 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
113 dashdash_already = TRUE; /* hack to open '-' */
114 else
115 vik_window_open_file ( first_window, argv[i], argc == 2 );
116 }
117
118 gtk_main ();
119 gdk_threads_leave ();
120
50a14534 121 a_mapcache_uninit ();
ad0a8c2d 122 a_dems_uninit ();
50a14534
EB
123
124 return 0;
125}