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