I18N: Adding minimal stuff
[viking.git] / src / main.c
blobec35b84e73ae1920f8930e368b09802d087a1e6f
1 /*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
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.
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.
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
22 #ifdef HAVE_CONFIG
23 #include "config.h"
24 #endif /* HAVE_CONFIG */
26 #include "viking.h"
27 #include "icons/viking_icon.png_h"
28 #include "mapcache.h"
29 #include "background.h"
30 #include "dems.h"
31 #include "curl_download.h"
33 #include <stdlib.h>
34 #include <string.h>
36 #include <glib/gprintf.h>
37 #include <glib/gi18n.h>
39 #include "modules.h"
41 #define MAX_WINDOWS 1024
43 static guint window_count = 0;
45 static VikWindow *new_window ();
46 static void open_window ( VikWindow *vw, const gchar **files );
47 static void destroy( GtkWidget *widget,
48 gpointer data );
51 /* Another callback */
52 static void destroy( GtkWidget *widget,
53 gpointer data )
55 if ( ! --window_count )
56 gtk_main_quit ();
59 static VikWindow *new_window ()
61 if ( window_count < MAX_WINDOWS )
63 VikWindow *vw = vik_window_new ();
65 g_signal_connect (G_OBJECT (vw), "destroy",
66 G_CALLBACK (destroy), NULL);
67 g_signal_connect (G_OBJECT (vw), "newwindow",
68 G_CALLBACK (new_window), NULL);
69 g_signal_connect (G_OBJECT (vw), "openwindow",
70 G_CALLBACK (open_window), NULL);
72 gtk_widget_show_all ( GTK_WIDGET(vw) );
74 window_count++;
76 return vw;
78 return NULL;
81 static void open_window ( VikWindow *vw, const gchar **files )
83 VikWindow *newvw = new_window();
84 gboolean change_fn = (!files[1]); /* only change fn if one file */
85 if ( newvw )
86 while ( *files ) {
87 vik_window_open_file ( newvw, *(files++), change_fn );
91 /* Options */
92 static gboolean version = FALSE;
94 static GOptionEntry entries[] =
96 { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Show version", NULL },
97 { NULL }
100 int main( int argc, char *argv[] )
102 VikWindow *first_window;
103 GdkPixbuf *main_icon;
104 gboolean dashdash_already = FALSE;
105 int i = 0;
106 GError *error = NULL;
107 gboolean gui_initialized;
109 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
110 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
111 textdomain (GETTEXT_PACKAGE);
113 g_thread_init ( NULL );
114 gdk_threads_init ();
116 gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
117 if (!gui_initialized)
119 /* check if we have an error message */
120 if (error == NULL)
122 /* no error message, the GUI initialization failed */
123 const gchar *display_name = gdk_get_display_arg_name ();
124 g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " ");
126 else
128 /* yep, there's an error, so print it */
129 g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message);
130 g_error_free (error);
131 g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]);
133 return EXIT_FAILURE;
136 if (version)
138 g_printf ("%s %s, Copyright (c) 2003-2007 Evan Battaglia\n", PACKAGE_NAME, PACKAGE_VERSION);
139 return EXIT_SUCCESS;
142 curl_download_init();
144 /* Init modules/plugins */
145 modules_init();
147 a_mapcache_init ();
148 a_background_init ();
149 vik_layer_cursors_init ();
150 vik_window_cursors_init ();
152 /* Set the icon */
153 main_icon = gdk_pixbuf_from_pixdata(&viking_icon, FALSE, NULL);
154 gtk_window_set_default_icon(main_icon);
156 /* Create the first window */
157 first_window = new_window();
159 gdk_threads_enter ();
160 while ( ++i < argc ) {
161 if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
162 dashdash_already = TRUE; /* hack to open '-' */
163 else
164 vik_window_open_file ( first_window, argv[i], argc == 2 );
167 gtk_main ();
168 gdk_threads_leave ();
170 a_mapcache_uninit ();
171 a_dems_uninit ();
172 vik_layer_cursors_uninit ();
173 vik_window_cursors_uninit ();
175 return 0;