]> git.street.me.uk Git - andy/viking.git/blobdiff - src/modules.c
Allow attempting to open a URL in a waypoint comment or description.
[andy/viking.git] / src / modules.c
index 68a8cb9f20a52a6295888dfc60adaea17d879732..c8c146f85de7f46d8ab451da311e1804df374f89 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
- * Copyright (C) 2006-2010, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ * Copyright (C) 2006-2012, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,6 +31,8 @@
 
 #include "modules.h"
 
+#include "bing.h"
+#include "spotmaps.h"
 #include "google.h"
 #include "terraserver.h"
 #include "expedia.h"
@@ -38,7 +40,7 @@
 #include "osm-traces.h"
 #include "bluemarble.h"
 #include "geonames.h"
-#include "file.h"
+#include "dir.h"
 #include "vikmapslayer.h"
 #include "vikexttools.h"
 #include "vikgoto.h"
@@ -74,10 +76,12 @@ modules_register_gototools(VikGobjectBuilder *self, GObject *object)
 }
 
 static void
-modules_load_config(void)
+modules_load_config_dir(const gchar *dir)
 {
+  g_debug("Loading configurations from directory %s", dir);
+
   /* Maps sources */
-  gchar *maps = g_build_filename(a_get_viking_dir(), VIKING_MAPS_FILE, NULL);
+  gchar *maps = g_build_filename(dir, VIKING_MAPS_FILE, NULL);
   if (g_access (maps, R_OK) == 0)
   {
        VikGobjectBuilder *builder = vik_gobject_builder_new ();
@@ -87,7 +91,7 @@ modules_load_config(void)
   }
 
   /* External tools */
-  gchar *tools = g_build_filename(a_get_viking_dir(), VIKING_EXTTOOLS_FILE, NULL);
+  gchar *tools = g_build_filename(dir, VIKING_EXTTOOLS_FILE, NULL);
   if (g_access (tools, R_OK) == 0)
   {
        VikGobjectBuilder *builder = vik_gobject_builder_new ();
@@ -97,7 +101,7 @@ modules_load_config(void)
   }
 
   /* Go-to search engines */
-  gchar *go_to = g_build_filename(a_get_viking_dir(), VIKING_GOTOTOOLS_FILE, NULL);
+  gchar *go_to = g_build_filename(dir, VIKING_GOTOTOOLS_FILE, NULL);
   if (g_access (go_to, R_OK) == 0)
   {
        VikGobjectBuilder *builder = vik_gobject_builder_new ();
@@ -107,8 +111,47 @@ modules_load_config(void)
   }
 }
 
+static void
+modules_load_config(void)
+{
+  /* Look in the directories of data path */
+  gchar * * data_dirs = a_get_viking_data_path();
+  /* Priority is standard one:
+     left element is more important than right one.
+     But our logic is to load all existing files and overwrite
+     overlapping config with last recent one.
+     So, we have to process directories in reverse order. */
+  /* First: find the last element */
+  gchar * * ptr = data_dirs;
+  while (*ptr != NULL) ptr++;
+  /* Second: deduce the number of directories */
+  int nb_data_dirs = 0;
+  nb_data_dirs = ptr - data_dirs;
+  /* Last: parse them in reverse order */
+  for (; nb_data_dirs > 0 ; nb_data_dirs--)
+  {
+    modules_load_config_dir(data_dirs[nb_data_dirs-1]);
+  }
+  g_strfreev(data_dirs);
+       
+  /* Check if system config is set */
+  modules_load_config_dir(VIKING_SYSCONFDIR);
+
+  const gchar *data_home = a_get_viking_data_home ();
+  if (data_home)
+  {
+    modules_load_config_dir(data_home);
+  }
+       
+  /* Check user's home config */
+  modules_load_config_dir(a_get_viking_dir());
+}
+
 void modules_init()
 {
+#ifdef VIK_CONFIG_BING
+  bing_init();
+#endif
 #ifdef VIK_CONFIG_GOOGLE 
   google_init();
 #endif
@@ -128,7 +171,10 @@ void modules_init()
 #ifdef VIK_CONFIG_GEONAMES
   geonames_init();
 #endif
-  
+#ifdef VIK_CONFIG_SPOTMAPS
+  spotmaps_init();
+#endif
+
   /* As modules are loaded, we can load configuration files */
   modules_load_config ();
 }