2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2006-2012, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
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
27 #include <glib/gstdio.h>
37 #include "terraserver.h"
40 #include "osm-traces.h"
41 #include "bluemarble.h"
44 #include "vikmapslayer.h"
45 #include "vikexttools.h"
47 #include "vikgobjectbuilder.h"
49 #define VIKING_MAPS_FILE "maps.xml"
50 #define VIKING_EXTTOOLS_FILE "external_tools.xml"
51 #define VIKING_GOTOTOOLS_FILE "goto_tools.xml"
54 modules_register_map_source(VikGobjectBuilder *self, GObject *object)
56 g_debug (__FUNCTION__);
57 VikMapSource *mapsource = VIK_MAP_SOURCE (object);
58 /* FIXME label should be hosted by object */
59 maps_layer_register_map_source (mapsource);
63 modules_register_exttools(VikGobjectBuilder *self, GObject *object)
65 g_debug (__FUNCTION__);
66 VikExtTool *tool = VIK_EXT_TOOL (object);
67 vik_ext_tools_register (tool);
71 modules_register_gototools(VikGobjectBuilder *self, GObject *object)
73 g_debug (__FUNCTION__);
74 VikGotoTool *tool = VIK_GOTO_TOOL (object);
75 vik_goto_register (tool);
79 modules_load_config_dir(const gchar *dir)
81 g_debug("Loading configurations from directory %s", dir);
84 gchar *maps = g_build_filename(dir, VIKING_MAPS_FILE, NULL);
85 if (g_access (maps, R_OK) == 0)
87 VikGobjectBuilder *builder = vik_gobject_builder_new ();
88 g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_map_source), NULL);
89 vik_gobject_builder_parse (builder, maps);
90 g_object_unref (builder);
94 gchar *tools = g_build_filename(dir, VIKING_EXTTOOLS_FILE, NULL);
95 if (g_access (tools, R_OK) == 0)
97 VikGobjectBuilder *builder = vik_gobject_builder_new ();
98 g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_exttools), NULL);
99 vik_gobject_builder_parse (builder, tools);
100 g_object_unref (builder);
103 /* Go-to search engines */
104 gchar *go_to = g_build_filename(dir, VIKING_GOTOTOOLS_FILE, NULL);
105 if (g_access (go_to, R_OK) == 0)
107 VikGobjectBuilder *builder = vik_gobject_builder_new ();
108 g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_gototools), NULL);
109 vik_gobject_builder_parse (builder, go_to);
110 g_object_unref (builder);
115 modules_load_config(void)
117 /* Look in the directories of data path */
118 gchar * * data_dirs = a_get_viking_data_path();
119 /* Priority is standard one:
120 left element is more important than right one.
121 But our logic is to load all existing files and overwrite
122 overlapping config with last recent one.
123 So, we have to process directories in reverse order. */
124 /* First: find the last element */
125 gchar * * ptr = data_dirs;
126 while (*ptr != NULL) ptr++;
127 /* Second: deduce the number of directories */
128 int nb_data_dirs = 0;
129 nb_data_dirs = ptr - data_dirs;
130 /* Last: parse them in reverse order */
131 for (; nb_data_dirs > 0 ; nb_data_dirs--)
133 modules_load_config_dir(data_dirs[nb_data_dirs-1]);
135 g_strfreev(data_dirs);
137 /* Check if system config is set */
138 modules_load_config_dir(VIKING_SYSCONFDIR);
140 const gchar *data_home = a_get_viking_data_home ();
143 modules_load_config_dir(data_home);
146 /* Check user's home config */
147 modules_load_config_dir(a_get_viking_dir());
152 #ifdef VIK_CONFIG_BING
155 #ifdef VIK_CONFIG_GOOGLE
158 #ifdef VIK_CONFIG_EXPEDIA
161 #ifdef VIK_CONFIG_TERRASERVER
164 #ifdef VIK_CONFIG_OPENSTREETMAP
168 #ifdef VIK_CONFIG_BLUEMARBLE
171 #ifdef VIK_CONFIG_GEONAMES
174 #ifdef VIK_CONFIG_SPOTMAPS
178 /* As modules are loaded, we can load configuration files */
179 modules_load_config ();