]> git.street.me.uk Git - andy/viking.git/blob - src/modules.c
Merge branch 'i18n-launchpad' into master
[andy/viking.git] / src / modules.c
1 /*
2  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3  *
4  * Copyright (C) 2006-2010, 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 "google.h"
35 #include "terraserver.h"
36 #include "expedia.h"
37 #include "osm.h"
38 #include "osm-traces.h"
39 #include "bluemarble.h"
40 #include "geonames.h"
41 #include "file.h"
42 #include "vikmapslayer.h"
43 #include "vikexttools.h"
44 #include "vikgoto.h"
45 #include "vikgobjectbuilder.h"
46
47 #define VIKING_MAPS_FILE "maps.xml"
48 #define VIKING_EXTTOOLS_FILE "external_tools.xml"
49 #define VIKING_GOTOTOOLS_FILE "goto_tools.xml"
50
51 static void
52 modules_register_map_source(VikGobjectBuilder *self, GObject *object)
53 {
54   g_debug (__FUNCTION__);
55   VikMapSource *mapsource = VIK_MAP_SOURCE (object);
56   /* FIXME label should be hosted by object */
57   maps_layer_register_map_source (mapsource);
58 }
59
60 static void
61 modules_register_exttools(VikGobjectBuilder *self, GObject *object)
62 {
63   g_debug (__FUNCTION__);
64   VikExtTool *tool = VIK_EXT_TOOL (object);
65   vik_ext_tools_register (tool);
66 }
67
68 static void
69 modules_register_gototools(VikGobjectBuilder *self, GObject *object)
70 {
71   g_debug (__FUNCTION__);
72   VikGotoTool *tool = VIK_GOTO_TOOL (object);
73   vik_goto_register (tool);
74 }
75
76 static void
77 modules_load_config(void)
78 {
79   /* Maps sources */
80   gchar *maps = g_build_filename(a_get_viking_dir(), VIKING_MAPS_FILE, NULL);
81   if (g_access (maps, R_OK) == 0)
82   {
83         VikGobjectBuilder *builder = vik_gobject_builder_new ();
84         g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_map_source), NULL);
85         vik_gobject_builder_parse (builder, maps);
86         g_object_unref (builder);
87   }
88
89   /* External tools */
90   gchar *tools = g_build_filename(a_get_viking_dir(), VIKING_EXTTOOLS_FILE, NULL);
91   if (g_access (tools, R_OK) == 0)
92   {
93         VikGobjectBuilder *builder = vik_gobject_builder_new ();
94         g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_exttools), NULL);
95         vik_gobject_builder_parse (builder, tools);
96         g_object_unref (builder);
97   }
98
99   /* Go-to search engines */
100   gchar *go_to = g_build_filename(a_get_viking_dir(), VIKING_GOTOTOOLS_FILE, NULL);
101   if (g_access (go_to, R_OK) == 0)
102   {
103         VikGobjectBuilder *builder = vik_gobject_builder_new ();
104         g_signal_connect (builder, "new-object", G_CALLBACK (modules_register_gototools), NULL);
105         vik_gobject_builder_parse (builder, go_to);
106         g_object_unref (builder);
107   }
108 }
109
110 void modules_init()
111 {
112 #ifdef VIK_CONFIG_GOOGLE 
113   google_init();
114 #endif
115 #ifdef VIK_CONFIG_EXPEDIA
116   expedia_init();
117 #endif
118 #ifdef VIK_CONFIG_TERRASERVER
119   terraserver_init();
120 #endif
121 #ifdef VIK_CONFIG_OPENSTREETMAP
122   osm_init();
123   osm_traces_init();
124 #endif
125 #ifdef VIK_CONFIG_BLUEMARBLE
126   bluemarble_init();
127 #endif
128 #ifdef VIK_CONFIG_GEONAMES
129   geonames_init();
130 #endif
131   
132   /* As modules are loaded, we can load configuration files */
133   modules_load_config ();
134 }
135