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