]> err.no Git - mapper/blob - src/mapper.c
Many many changes.
[mapper] / src / mapper.c
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2007 Kaj-Michael Lang
5  * Copyright (C) 2006-2007 John Costigan.
6  *
7  * POI and GPS-Info code originally written by Cezary Jackiewicz.
8  *
9  * Default map data provided by http://www.openstreetmap.org/
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #define _GNU_SOURCE
27
28 #include <config.h>
29 #include <unistd.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <strings.h>
33 #include <stddef.h>
34 #include <math.h>
35 #include <errno.h>
36 #include <sys/wait.h>
37 #include <glib/gstdio.h>
38 #include <glib/gi18n.h>
39 #ifdef WITH_GST
40 #include <gst/gst.h>
41 #endif
42 #include <gtk/gtk.h>
43 #include <fcntl.h>
44 #include <gdk/gdkkeysyms.h>
45 #include <dbus/dbus.h>
46 #include <dbus/dbus-glib.h>
47 #include <libgnomevfs/gnome-vfs.h>
48 #include <curl/multi.h>
49 #include <gconf/gconf-client.h>
50 #include <libintl.h>
51 #include <locale.h>
52
53 #include "hildon-mapper.h"
54
55 #include "utils.h"
56 #include "mapper-types.h"
57 #include "settings.h"
58 #include "gps.h"
59 #include "map.h"
60 #include "route.h"
61 #include "track.h"
62 #include "bt.h"
63 #include "ui-common.h"
64 #include "db.h"
65 #include "osm-db.h"
66 #include "cb.h"
67 #include "speak.h"
68 #include "gpx.h"
69 #include "config-gconf.h"
70
71 DBusConnection *dbus_conn;
72
73 gfloat UNITS_CONVERT[] = {1.85200,1.15077945,1.f,};
74
75 GdkColor COLORABLE_DEFAULT[COLORABLE_ENUM_COUNT] = {
76         {0, 0x0000, 0x0000, 0xc000}
77         ,                       /* COLORABLE_MARK */
78         {0, 0x6000, 0x6000, 0xf800}
79         ,                       /* COLORABLE_MARK_VELOCITY */
80         {0, 0x8000, 0x8000, 0x8000}
81         ,                       /* COLORABLE_MARK_OLD */
82         {0, 0xe000, 0x0000, 0x0000}
83         ,                       /* COLORABLE_TRACK */
84         {0, 0xa000, 0x0000, 0x0000}
85         ,                       /* COLORABLE_TRACK_MARK */
86         {0, 0x7000, 0x0000, 0x0000}
87         ,                       /* COLORABLE_TRACK_BREAK */
88         {0, 0x0000, 0xa000, 0x0000}
89         ,                       /* COLORABLE_ROUTE */
90         {0, 0x0000, 0x8000, 0x0000}
91         ,                       /* COLORABLE_ROUTE_WAY */
92         {0, 0x0000, 0x6000, 0x0000}
93         ,                       /* COLORABLE_ROUTE_BREAK */
94         {0, 0xa000, 0x0000, 0xa000}     /* COLORABLE_POI */
95 };
96
97 /**
98  * Save state and destroy all non-UI elements created by this program in
99  * preparation for exiting.
100  */
101 static void 
102 mapper_destroy(void)
103 {
104 config_save();
105 config_save_repo();
106 rcvr_disconnect();
107 map_download_deinit();
108 if (_curl_sid) {
109         g_source_remove(_curl_sid);
110         _curl_sid = 0;
111 }
112 osm_deinit();
113 db_close(&_db);
114 track_deinit();
115 route_deinit();
116 }
117
118 static void 
119 set_var_defaults(void)
120 {
121 _conn_state = RCVR_OFF;
122 }
123
124 static gint 
125 mapper_osso_init(void)
126 {
127 #ifdef WITH_OSSO
128 /* Initialize _osso. */
129 _osso = osso_initialize("org.tal.mapper", VERSION, TRUE, NULL);
130 if (!_osso) {
131         g_printerr("osso_initialize failed.\n");
132         return 1;
133 }
134 #endif
135 return 0;
136 }
137
138 static gint 
139 mapper_osso_cb_init(void)
140 {
141 #ifdef WITH_OSSO
142 gchar *filter_string;
143
144 if (OSSO_OK != osso_rpc_set_default_cb_f(_osso, dbus_cb_default, NULL)) {
145         g_printerr("osso_rpc_set_default_cb_f failed.\n");
146         return 1;
147 }
148
149 filter_string = g_strdup_printf("interface=%s", ICD_DBUS_INTERFACE);
150 /* add match */
151 dbus_bus_add_match(dbus_conn, filter_string, NULL);
152 g_free(filter_string);
153 /* add the callback */
154 dbus_connection_add_filter(dbus_conn, get_connection_status_signal_cb, NULL, NULL);
155
156 osso_iap_cb(iap_callback);
157
158 #endif
159 return 0;
160 }
161
162 static void 
163 timezone_init(void)
164 {
165 time_t time1;
166 struct tm time2;
167
168 time1 = time(NULL);
169 localtime_r(&time1, &time2);
170 _gmtoffset = time2.tm_gmtoff;
171 }
172
173 static void 
174 mapper_init(gint argc, gchar ** argv)
175 {
176 DBusGConnection *dbus_conn;
177 GError *error = NULL;
178
179 g_set_application_name("Mapper");
180
181 mapper_init_variables();
182 track_init();
183 route_init();
184 config_init();
185 map_download_init();
186 osm_init();
187 gps_init();
188 mapper_ui_init();
189
190 #ifdef WITH_OSSO
191 osso_hw_set_event_cb(_osso, NULL, osso_cb_hw_state, NULL);
192 #endif
193
194 /* Initialize D-Bus. */
195 if (NULL == (dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error))) {
196         g_printerr("Failed to open connection to D-Bus: %s.\n", error->message);
197         error = NULL;
198 }
199 #ifdef WITH_HILDON_DBUS_BT
200 if (NULL == (_rfcomm_req_proxy = dbus_g_proxy_new_for_name(dbus_conn, BTCOND_SERVICE, BTCOND_REQ_PATH, BTCOND_REQ_INTERFACE))) {
201         g_printerr("Failed to open connection to %s.\n", BTCOND_REQ_INTERFACE);
202 }
203 #endif
204
205 }
206
207 gint 
208 main(gint argc, gchar * argv[])
209 {
210         printf("%s()\n", __PRETTY_FUNCTION__);
211
212         /* Initialize localization. */
213         setlocale(LC_ALL, "");
214         bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
215         bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
216         textdomain(GETTEXT_PACKAGE);
217
218         g_thread_init(NULL);
219         g_type_init();
220         if (mapper_osso_init()!=0)
221                 return 1;
222         set_var_defaults();     
223 #ifdef WITH_GST
224         gst_init(&argc, &argv);
225         speak_init(120,50);
226 #endif
227         gtk_init(&argc, &argv);
228         gconf_init(argc, argv, NULL);
229         gnome_vfs_init();
230         curl_global_init(CURL_GLOBAL_NOTHING);
231         timezone_init();
232         gpx_init();
233         mapper_init(argc, argv);
234         if (mapper_osso_cb_init()!=0)
235                 return 1;
236         gtk_main();
237         mapper_destroy();
238 #ifdef WITH_GST
239         speak_deinit();
240 #endif
241         gnome_vfs_shutdown();
242 #ifdef WITH_OSSO
243         osso_deinitialize(_osso);
244 #endif
245         vprintf("%s(): return\n", __PRETTY_FUNCTION__);
246         return 0;
247 }