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