]>
Commit | Line | Data |
---|---|---|
cdcaf41c QT |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
29f1598c | 4 | * Copyright (C) 2006-2012, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> |
cdcaf41c QT |
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 | ||
54b5d793 GB |
26 | #include <glib.h> |
27 | #include <glib/gstdio.h> | |
28 | #ifdef HAVE_UNISTD_H | |
29 | #include <unistd.h> | |
30 | #endif | |
31 | ||
cdcaf41c QT |
32 | #include "modules.h" |
33 | ||
9f58c4b4 | 34 | #include "bing.h" |
dd84b6d1 | 35 | #include "spotmaps.h" |
cdcaf41c | 36 | #include "google.h" |
cdcaf41c | 37 | #include "terraserver.h" |
cdcaf41c | 38 | #include "expedia.h" |
67209ca8 | 39 | #include "osm.h" |
843b99df | 40 | #include "osm-traces.h" |
7363caa7 | 41 | #include "bluemarble.h" |
bf5cef41 | 42 | #include "geonames.h" |
29f1598c | 43 | #include "dir.h" |
df82a41c | 44 | #include "vikmapslayer.h" |
54b5d793 | 45 | #include "vikexttools.h" |
82993cc7 | 46 | #include "vikexttool_datasources.h" |
4c629122 | 47 | #include "vikgoto.h" |
54b5d793 GB |
48 | #include "vikgobjectbuilder.h" |
49 | ||
df82a41c | 50 | #define VIKING_MAPS_FILE "maps.xml" |
54b5d793 | 51 | #define VIKING_EXTTOOLS_FILE "external_tools.xml" |
82993cc7 | 52 | #define VIKING_DATASOURCES_FILE "datasources.xml" |
4c629122 | 53 | #define VIKING_GOTOTOOLS_FILE "goto_tools.xml" |
54b5d793 | 54 | |
df82a41c GB |
55 | static void |
56 | modules_register_map_source(VikGobjectBuilder *self, GObject *object) | |
57 | { | |
58 | g_debug (__FUNCTION__); | |
59 | VikMapSource *mapsource = VIK_MAP_SOURCE (object); | |
60 | /* FIXME label should be hosted by object */ | |
61 | maps_layer_register_map_source (mapsource); | |
62 | } | |
63 | ||
54b5d793 GB |
64 | static void |
65 | modules_register_exttools(VikGobjectBuilder *self, GObject *object) | |
66 | { | |
67 | g_debug (__FUNCTION__); | |
68 | VikExtTool *tool = VIK_EXT_TOOL (object); | |
69 | vik_ext_tools_register (tool); | |
70 | } | |
71 | ||
82993cc7 RN |
72 | static void |
73 | modules_register_datasources(VikGobjectBuilder *self, GObject *object) | |
74 | { | |
75 | g_debug (__FUNCTION__); | |
76 | VikExtTool *tool = VIK_EXT_TOOL (object); | |
77 | vik_ext_tool_datasources_register (tool); | |
78 | } | |
79 | ||
4c629122 GB |
80 | static void |
81 | modules_register_gototools(VikGobjectBuilder *self, GObject *object) | |
82 | { | |
83 | g_debug (__FUNCTION__); | |
84 | VikGotoTool *tool = VIK_GOTO_TOOL (object); | |
85 | vik_goto_register (tool); | |
86 | } | |
87 | ||
54b5d793 | 88 | static void |
29f1598c | 89 | modules_load_config_dir(const gchar *dir) |
54b5d793 | 90 | { |
29f1598c GB |
91 | g_debug("Loading configurations from directory %s", dir); |
92 | ||
df82a41c | 93 | /* Maps sources */ |
29f1598c | 94 | gchar *maps = g_build_filename(dir, VIKING_MAPS_FILE, NULL); |
df82a41c GB |
95 | if (g_access (maps, R_OK) == 0) |
96 | { | |
97 | VikGobjectBuilder *builder = vik_gobject_builder_new (); | |
98 | g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_map_source), NULL); | |
99 | vik_gobject_builder_parse (builder, maps); | |
100 | g_object_unref (builder); | |
101 | } | |
102 | ||
54b5d793 | 103 | /* External tools */ |
29f1598c | 104 | gchar *tools = g_build_filename(dir, VIKING_EXTTOOLS_FILE, NULL); |
54b5d793 GB |
105 | if (g_access (tools, R_OK) == 0) |
106 | { | |
107 | VikGobjectBuilder *builder = vik_gobject_builder_new (); | |
108 | g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_exttools), NULL); | |
109 | vik_gobject_builder_parse (builder, tools); | |
110 | g_object_unref (builder); | |
111 | } | |
4c629122 | 112 | |
82993cc7 RN |
113 | gchar *datasources = g_build_filename(dir, VIKING_DATASOURCES_FILE, NULL); |
114 | if (g_access (datasources, R_OK) == 0) | |
115 | { | |
116 | VikGobjectBuilder *builder = vik_gobject_builder_new (); | |
117 | g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_datasources), NULL); | |
118 | vik_gobject_builder_parse (builder, datasources); | |
119 | g_object_unref (builder); | |
120 | } | |
121 | ||
4c629122 | 122 | /* Go-to search engines */ |
29f1598c | 123 | gchar *go_to = g_build_filename(dir, VIKING_GOTOTOOLS_FILE, NULL); |
4c629122 GB |
124 | if (g_access (go_to, R_OK) == 0) |
125 | { | |
126 | VikGobjectBuilder *builder = vik_gobject_builder_new (); | |
127 | g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_gototools), NULL); | |
128 | vik_gobject_builder_parse (builder, go_to); | |
129 | g_object_unref (builder); | |
130 | } | |
54b5d793 | 131 | } |
cdcaf41c | 132 | |
29f1598c GB |
133 | static void |
134 | modules_load_config(void) | |
135 | { | |
136 | /* Look in the directories of data path */ | |
137 | gchar * * data_dirs = a_get_viking_data_path(); | |
138 | /* Priority is standard one: | |
139 | left element is more important than right one. | |
140 | But our logic is to load all existing files and overwrite | |
141 | overlapping config with last recent one. | |
142 | So, we have to process directories in reverse order. */ | |
143 | /* First: find the last element */ | |
144 | gchar * * ptr = data_dirs; | |
145 | while (*ptr != NULL) ptr++; | |
146 | /* Second: deduce the number of directories */ | |
147 | int nb_data_dirs = 0; | |
148 | nb_data_dirs = ptr - data_dirs; | |
149 | /* Last: parse them in reverse order */ | |
150 | for (; nb_data_dirs > 0 ; nb_data_dirs--) | |
151 | { | |
152 | modules_load_config_dir(data_dirs[nb_data_dirs-1]); | |
153 | } | |
154 | g_strfreev(data_dirs); | |
155 | ||
156 | /* Check if system config is set */ | |
157 | modules_load_config_dir(VIKING_SYSCONFDIR); | |
158 | ||
159 | const gchar *data_home = a_get_viking_data_home (); | |
160 | if (data_home) | |
161 | { | |
162 | modules_load_config_dir(data_home); | |
163 | } | |
164 | ||
165 | /* Check user's home config */ | |
166 | modules_load_config_dir(a_get_viking_dir()); | |
167 | } | |
168 | ||
cdcaf41c QT |
169 | void modules_init() |
170 | { | |
9f58c4b4 GB |
171 | #ifdef VIK_CONFIG_BING |
172 | bing_init(); | |
173 | #endif | |
36c78d6d QT |
174 | #ifdef VIK_CONFIG_GOOGLE |
175 | google_init(); | |
176 | #endif | |
cdcaf41c QT |
177 | #ifdef VIK_CONFIG_EXPEDIA |
178 | expedia_init(); | |
179 | #endif | |
180 | #ifdef VIK_CONFIG_TERRASERVER | |
181 | terraserver_init(); | |
182 | #endif | |
ca9eb04a | 183 | #ifdef VIK_CONFIG_OPENSTREETMAP |
67209ca8 | 184 | osm_init(); |
843b99df | 185 | osm_traces_init(); |
ca9eb04a | 186 | #endif |
7363caa7 GB |
187 | #ifdef VIK_CONFIG_BLUEMARBLE |
188 | bluemarble_init(); | |
189 | #endif | |
bf5cef41 GB |
190 | #ifdef VIK_CONFIG_GEONAMES |
191 | geonames_init(); | |
192 | #endif | |
dd84b6d1 GB |
193 | #ifdef VIK_CONFIG_SPOTMAPS |
194 | spotmaps_init(); | |
195 | #endif | |
196 | ||
54b5d793 GB |
197 | /* As modules are loaded, we can load configuration files */ |
198 | modules_load_config (); | |
cdcaf41c QT |
199 | } |
200 |