]> git.street.me.uk Git - andy/viking.git/blame - src/modules.c
Allow uploading a single track via the GPS layer interface.
[andy/viking.git] / src / modules.c
CommitLineData
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"
4c629122 46#include "vikgoto.h"
54b5d793
GB
47#include "vikgobjectbuilder.h"
48
df82a41c 49#define VIKING_MAPS_FILE "maps.xml"
54b5d793 50#define VIKING_EXTTOOLS_FILE "external_tools.xml"
4c629122 51#define VIKING_GOTOTOOLS_FILE "goto_tools.xml"
54b5d793 52
df82a41c
GB
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
54b5d793
GB
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
4c629122
GB
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
54b5d793 78static void
29f1598c 79modules_load_config_dir(const gchar *dir)
54b5d793 80{
29f1598c
GB
81 g_debug("Loading configurations from directory %s", dir);
82
df82a41c 83 /* Maps sources */
29f1598c 84 gchar *maps = g_build_filename(dir, VIKING_MAPS_FILE, NULL);
df82a41c
GB
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
54b5d793 93 /* External tools */
29f1598c 94 gchar *tools = g_build_filename(dir, VIKING_EXTTOOLS_FILE, NULL);
54b5d793
GB
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 }
4c629122
GB
102
103 /* Go-to search engines */
29f1598c 104 gchar *go_to = g_build_filename(dir, VIKING_GOTOTOOLS_FILE, NULL);
4c629122
GB
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 }
54b5d793 112}
cdcaf41c 113
29f1598c
GB
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
cdcaf41c
QT
150void modules_init()
151{
9f58c4b4
GB
152#ifdef VIK_CONFIG_BING
153 bing_init();
154#endif
36c78d6d
QT
155#ifdef VIK_CONFIG_GOOGLE
156 google_init();
157#endif
cdcaf41c
QT
158#ifdef VIK_CONFIG_EXPEDIA
159 expedia_init();
160#endif
161#ifdef VIK_CONFIG_TERRASERVER
162 terraserver_init();
163#endif
ca9eb04a 164#ifdef VIK_CONFIG_OPENSTREETMAP
67209ca8 165 osm_init();
843b99df 166 osm_traces_init();
ca9eb04a 167#endif
7363caa7
GB
168#ifdef VIK_CONFIG_BLUEMARBLE
169 bluemarble_init();
170#endif
bf5cef41
GB
171#ifdef VIK_CONFIG_GEONAMES
172 geonames_init();
173#endif
dd84b6d1
GB
174#ifdef VIK_CONFIG_SPOTMAPS
175 spotmaps_init();
176#endif
177
54b5d793
GB
178 /* As modules are loaded, we can load configuration files */
179 modules_load_config ();
cdcaf41c
QT
180}
181