2 * This file is part of mapper
4 * Copyright (C) 2007 Kaj-Michael Lang
5 * Copyright (C) 2006-2007 John Costigan.
7 * POI and GPS-Info code originally written by Cezary Jackiewicz.
9 * Default map data provided by http://www.openstreetmap.org/
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.
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.
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.
37 #include <glib/gstdio.h>
38 #include <glib/gi18n.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>
53 #ifdef WITH_HILDON_DBUS_BT
57 #include "hildon-mapper.h"
60 #include "mapper-types.h"
67 #include "ui-common.h"
73 #include "config-gconf.h"
75 DBusConnection *dbus_conn;
77 gfloat UNITS_CONVERT[] = {1.85200,1.15077945,1.f,};
79 GdkColor COLORABLE_DEFAULT[COLORABLE_ENUM_COUNT] = {
80 {0, 0x0000, 0x0000, 0xc000}
81 , /* COLORABLE_MARK */
82 {0, 0x6000, 0x6000, 0xf800}
83 , /* COLORABLE_MARK_VELOCITY */
84 {0, 0x8000, 0x8000, 0x8000}
85 , /* COLORABLE_MARK_OLD */
86 {0, 0xe000, 0x0000, 0x0000}
87 , /* COLORABLE_TRACK */
88 {0, 0xa000, 0x0000, 0x0000}
89 , /* COLORABLE_TRACK_MARK */
90 {0, 0x7000, 0x0000, 0x0000}
91 , /* COLORABLE_TRACK_BREAK */
92 {0, 0x0000, 0xa000, 0x0000}
93 , /* COLORABLE_ROUTE */
94 {0, 0x0000, 0x8000, 0x0000}
95 , /* COLORABLE_ROUTE_WAY */
96 {0, 0x0000, 0x6000, 0x0000}
97 , /* COLORABLE_ROUTE_BREAK */
98 {0, 0xa000, 0x0000, 0xa000} /* COLORABLE_POI */
113 guint mis=MAPPER_INIT_START;
115 static GtkWidget *init_progress;
116 static GtkWidget *init_dialog;
119 * Save state and destroy all non-UI elements created by this program in
120 * preparation for exiting.
128 map_download_deinit();
130 g_source_remove(_curl_sid);
133 #if defined (WITH_GST) && defined (WITH_ESPEAK)
141 gnome_vfs_shutdown();
143 osso_deinitialize(_osso);
145 curl_global_cleanup();
149 mapper_osso_init(void)
152 /* Initialize _osso. */
153 _osso = osso_initialize("org.tal.mapper", VERSION, TRUE, NULL);
155 g_printerr("osso_initialize failed.\n");
163 mapper_osso_cb_init(void)
166 gchar *filter_string;
168 if (OSSO_OK != osso_rpc_set_default_cb_f(_osso, dbus_cb_default, NULL)) {
169 g_printerr("osso_rpc_set_default_cb_f failed.\n");
173 filter_string = g_strdup_printf("interface=%s", ICD_DBUS_INTERFACE);
175 dbus_bus_add_match(dbus_conn, filter_string, NULL);
176 g_free(filter_string);
177 /* add the callback */
178 dbus_connection_add_filter(dbus_conn, get_connection_status_signal_cb, NULL, NULL);
180 osso_iap_cb(iap_callback);
193 localtime_r(&time1, &time2);
194 _gmtoffset = time2.tm_gmtoff;
198 mapper_init(gpointer data)
200 GError *error = NULL;
204 case MAPPER_INIT_START:
205 _conn_state = RCVR_OFF;
206 curl_global_init(CURL_GLOBAL_NOTHING);
210 mapper_init_variables();
213 mis=MAPPER_INIT_CONFIG;
215 case MAPPER_INIT_CONFIG:
220 case MAPPER_INIT_GPS:
226 mis=MAPPER_INIT_VOICE;
228 case MAPPER_INIT_VOICE:
229 #if defined (WITH_GST) && defined (WITH_ESPEAK)
230 speak_init("en",_voice_speed,_voice_pitch);
232 mis=MAPPER_INIT_MISC;
234 case MAPPER_INIT_MISC:
236 osso_hw_set_event_cb(_osso, NULL, osso_cb_hw_state, NULL);
239 /* Initialize D-Bus. */
240 if (NULL == (dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error))) {
241 g_printerr("Failed to open connection to D-Bus: %s.\n", error->message);
244 #ifdef WITH_HILDON_DBUS_BT
245 if (NULL == (_rfcomm_req_proxy = dbus_g_proxy_new_for_name(dbus_conn, BTCOND_SERVICE, BTCOND_REQ_PATH, BTCOND_REQ_INTERFACE))) {
246 g_printerr("Failed to open connection to %s.\n", BTCOND_REQ_INTERFACE);
253 mis=MAPPER_INIT_GOTO;
255 case MAPPER_INIT_GOTO:
256 if (map_goto_position(&_home)==FALSE)
257 g_printf("Home is not set\n");
258 mis=MAPPER_INIT_DONE;
260 case MAPPER_INIT_DONE:
261 progress_dialog_remove(init_dialog);
266 gtk_progress_bar_pulse(GTK_PROGRESS(init_progress));
271 main(gint argc, gchar * argv[])
273 /* Initialize localization. */
274 setlocale(LC_ALL, "");
275 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
276 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
277 textdomain(GETTEXT_PACKAGE);
281 g_set_application_name("Mapper");
282 gtk_init(&argc, &argv);
283 if (mapper_osso_init()!=0)
285 if (mapper_osso_cb_init()!=0)
287 #if defined (WITH_GST)
288 gst_init(&argc, &argv);
291 init_progress=gtk_progress_bar_new();
292 init_dialog=progress_dialog("Mapper starting...",init_progress);
293 g_idle_add((GSourceFunc)mapper_init, NULL);