]> git.street.me.uk Git - andy/viking.git/blobdiff - src/main.c
Correct OSM URL
[andy/viking.git] / src / main.c
index babcadc6b0cb9c9c043310c90379431d22572d51..899548cb9198b60a25377478a627a2ea360a809d 100644 (file)
  *
  */
 
+#ifdef HAVE_CONFIG
+#include "config.h"
+#endif /* HAVE_CONFIG */
+
 #include "viking.h"
+#include "icons/viking_icon.png_h"
 #include "mapcache.h"
 #include "background.h"
+#include "dems.h"
+#include "curl_download.h"
+#include "preferences.h"
+
+#ifdef VIK_CONFIG_GEOCACHES
+void a_datasource_gc_init();
+#endif
 
+#include <stdlib.h>
 #include <string.h>
 
+#include <glib/gprintf.h>
+#include <glib/gi18n.h>
+
 #include "modules.h"
 
 #define MAX_WINDOWS 1024
@@ -74,27 +90,81 @@ static void open_window ( VikWindow *vw, const gchar **files )
   if ( newvw )
     while ( *files ) {
       vik_window_open_file ( newvw, *(files++), change_fn );
-      files++;
     }
 }
 
+/* Options */
+static gboolean version = FALSE;
+
+static GOptionEntry entries[] = 
+{
+  { "version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Show version"), NULL },
+  { NULL }
+};
+
 int main( int argc, char *argv[] )
 {
   VikWindow *first_window;
+  GdkPixbuf *main_icon;
   gboolean dashdash_already = FALSE;
   int i = 0;
+  GError *error = NULL;
+  gboolean gui_initialized;
+       
+  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);  
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
 
   g_thread_init ( NULL );
   gdk_threads_init ();
 
-  gtk_init (&argc, &argv);
+  gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
+  if (!gui_initialized)
+  {
+    /* check if we have an error message */
+    if (error == NULL)
+    {
+      /* no error message, the GUI initialization failed */
+      const gchar *display_name = gdk_get_display_arg_name ();
+      g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " ");
+    }
+    else
+    {
+      /* yep, there's an error, so print it */
+      g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message);
+      g_error_free (error);
+      g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]);
+    }
+    return EXIT_FAILURE;
+  }
+   
+  if (version)
+  {
+    g_printf ("%s %s, Copyright (c) 2003-2007 Evan Battaglia\n", PACKAGE_NAME, PACKAGE_VERSION);
+    return EXIT_SUCCESS;
+  }
+
+  curl_download_init();
 
   /* Init modules/plugins */
   modules_init();
 
   a_mapcache_init ();
   a_background_init ();
+  a_preferences_init ();
+
+#ifdef VIK_CONFIG_GEOCACHES
+  a_datasource_gc_init();
+#endif
+
+  vik_layer_cursors_init ();
+  vik_window_cursors_init ();
+
+  /* Set the icon */
+  main_icon = gdk_pixbuf_from_pixdata(&viking_icon, FALSE, NULL);
+  gtk_window_set_default_icon(main_icon);
 
+  /* Create the first window */
   first_window = new_window();
 
   gdk_threads_enter ();
@@ -109,6 +179,10 @@ int main( int argc, char *argv[] )
   gdk_threads_leave ();
 
   a_mapcache_uninit ();
+  a_dems_uninit ();
+  a_preferences_uninit ();
+  vik_layer_cursors_uninit ();
+  vik_window_cursors_uninit ();
 
   return 0;
 }