]> git.street.me.uk Git - andy/viking.git/blame_incremental - src/modules.c
Use elevation values in creating waypoints from Wikipedia.
[andy/viking.git] / src / modules.c
... / ...
CommitLineData
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2006-2012, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
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#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <glib.h>
27#include <glib/gstdio.h>
28#ifdef HAVE_UNISTD_H
29#include <unistd.h>
30#endif
31
32#include "modules.h"
33
34#include "bing.h"
35#include "spotmaps.h"
36#include "google.h"
37#include "terraserver.h"
38#include "expedia.h"
39#include "osm.h"
40#include "osm-traces.h"
41#include "bluemarble.h"
42#include "geonames.h"
43#include "dir.h"
44#include "vikmapslayer.h"
45#include "vikexttools.h"
46#include "vikgoto.h"
47#include "vikgobjectbuilder.h"
48
49#define VIKING_MAPS_FILE "maps.xml"
50#define VIKING_EXTTOOLS_FILE "external_tools.xml"
51#define VIKING_GOTOTOOLS_FILE "goto_tools.xml"
52
53static void
54modules_register_map_source(VikGobjectBuilder *self, GObject *object)
55{
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);
60}
61
62static void
63modules_register_exttools(VikGobjectBuilder *self, GObject *object)
64{
65 g_debug (__FUNCTION__);
66 VikExtTool *tool = VIK_EXT_TOOL (object);
67 vik_ext_tools_register (tool);
68}
69
70static void
71modules_register_gototools(VikGobjectBuilder *self, GObject *object)
72{
73 g_debug (__FUNCTION__);
74 VikGotoTool *tool = VIK_GOTO_TOOL (object);
75 vik_goto_register (tool);
76}
77
78static void
79modules_load_config_dir(const gchar *dir)
80{
81 g_debug("Loading configurations from directory %s", dir);
82
83 /* Maps sources */
84 gchar *maps = g_build_filename(dir, VIKING_MAPS_FILE, NULL);
85 if (g_access (maps, R_OK) == 0)
86 {
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);
91 }
92
93 /* External tools */
94 gchar *tools = g_build_filename(dir, VIKING_EXTTOOLS_FILE, NULL);
95 if (g_access (tools, R_OK) == 0)
96 {
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);
101 }
102
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)
106 {
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);
111 }
112}
113
114static void
115modules_load_config(void)
116{
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--)
132 {
133 modules_load_config_dir(data_dirs[nb_data_dirs-1]);
134 }
135 g_strfreev(data_dirs);
136
137 /* Check if system config is set */
138 modules_load_config_dir(VIKING_SYSCONFDIR);
139
140 const gchar *data_home = a_get_viking_data_home ();
141 if (data_home)
142 {
143 modules_load_config_dir(data_home);
144 }
145
146 /* Check user's home config */
147 modules_load_config_dir(a_get_viking_dir());
148}
149
150void modules_init()
151{
152#ifdef VIK_CONFIG_BING
153 bing_init();
154#endif
155#ifdef VIK_CONFIG_GOOGLE
156 google_init();
157#endif
158#ifdef VIK_CONFIG_EXPEDIA
159 expedia_init();
160#endif
161#ifdef VIK_CONFIG_TERRASERVER
162 terraserver_init();
163#endif
164#ifdef VIK_CONFIG_OPENSTREETMAP
165 osm_init();
166 osm_traces_init();
167#endif
168#ifdef VIK_CONFIG_BLUEMARBLE
169 bluemarble_init();
170#endif
171#ifdef VIK_CONFIG_GEONAMES
172 geonames_init();
173#endif
174#ifdef VIK_CONFIG_SPOTMAPS
175 spotmaps_init();
176#endif
177
178 /* As modules are loaded, we can load configuration files */
179 modules_load_config ();
180}
181