2 * Copyright (C) 2006, 2007 John Costigan.
4 * POI and GPS-Info code originally written by Cezary Jackiewicz.
6 * Default map data provided by http://www.openstreetmap.org/
8 * This file is part of Maemo Mapper.
10 * Maemo Mapper is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * Maemo Mapper is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Maemo Mapper. If not, see <http://www.gnu.org/licenses/>.
33 #include <dbus/dbus-glib.h>
36 #include <gconf/gconf-client.h>
38 #ifdef MAEMO_CHANGES /* probably not the best macro to check for here */
39 # include <device_symbols.h>
43 # include <conicconnection.h>
44 # include <conicconnectionevent.h>
48 # include <hildon/hildon-program.h>
49 # include <hildon/hildon-banner.h>
51 # include <hildon-widgets/hildon-program.h>
52 # include <hildon-widgets/hildon-banner.h>
73 static void osso_cb_hw_state(osso_hw_state_t *state, gpointer data);
75 static HildonProgram *_program = NULL;
78 static ConIcConnection *_conic_conn = NULL;
79 static gboolean _conic_is_connecting = FALSE;
80 static gboolean _conic_conn_failed = FALSE;
81 static GMutex *_conic_connection_mutex = NULL;
82 static GCond *_conic_connection_cond = NULL;
85 /* Dynamically-sized in-memory map cache. */
86 static size_t _map_cache_size = (32*1024*1024);
87 static gboolean _map_cache_enabled = TRUE;
91 conic_conn_event(ConIcConnection *connection, ConIcConnectionEvent *event)
93 ConIcConnectionStatus status;
94 printf("%s()\n", __PRETTY_FUNCTION__);
96 g_mutex_lock(_conic_connection_mutex);
98 status = con_ic_connection_event_get_status(event);
100 if((_conic_is_connected = (status == CON_IC_STATUS_CONNECTED)))
102 /* We're connected. */
103 _conic_conn_failed = FALSE;
104 if(_download_banner != NULL)
105 gtk_widget_show(_download_banner);
109 /* We're not connected. */
110 /* Mark as a failed connection, if we had been trying to connect. */
111 _conic_conn_failed = _conic_is_connecting;
112 if(_download_banner != NULL)
113 gtk_widget_hide(_download_banner);
116 _conic_is_connecting = FALSE; /* No longer trying to connect. */
117 g_cond_broadcast(_conic_connection_cond);
118 g_mutex_unlock(_conic_connection_mutex);
120 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
125 conic_recommend_connected()
127 printf("%s()\n", __PRETTY_FUNCTION__);
129 #if defined(__arm__) && defined(CONIC)
130 g_mutex_lock(_conic_connection_mutex);
131 if(!_conic_is_connecting)
133 /* Fire up a connection request. */
134 con_ic_connection_connect(_conic_conn, CON_IC_CONNECT_FLAG_NONE);
135 _conic_is_connecting = TRUE;
137 g_mutex_unlock(_conic_connection_mutex);
140 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
144 conic_ensure_connected()
146 printf("%s()\n", __PRETTY_FUNCTION__);
148 #if defined(__arm__) && defined(CONIC)
149 while(_window && !_conic_is_connected)
151 g_mutex_lock(_conic_connection_mutex);
152 /* If we're not connected, and if we're not connecting, and if we're
153 * not in the wake of a connection failure, then try to connect. */
154 if(!_conic_is_connected && !_conic_is_connecting &&!_conic_conn_failed)
156 /* Fire up a connection request. */
157 con_ic_connection_connect(_conic_conn, CON_IC_CONNECT_FLAG_NONE);
158 _conic_is_connecting = TRUE;
160 g_cond_wait(_conic_connection_cond, _conic_connection_mutex);
161 g_mutex_unlock(_conic_connection_mutex);
164 _conic_is_connected = TRUE;
167 vprintf("%s(): return %d\n", __PRETTY_FUNCTION__,
168 _window && _conic_is_connected);
169 return _window && _conic_is_connected;
173 * Save state and destroy all non-UI elements created by this program in
174 * preparation for exiting.
177 maemo_mapper_destroy()
179 printf("%s()\n", __PRETTY_FUNCTION__);
181 /* _program and widgets have already been destroyed. */
192 g_mutex_lock(_mut_priority_mutex);
193 _mut_priority_tree = g_tree_new((GCompareFunc)mut_priority_comparefunc);
194 g_mutex_unlock(_mut_priority_mutex);
196 /* Allow remaining downloads to finish. */
198 g_mutex_lock(_conic_connection_mutex);
199 g_cond_broadcast(_conic_connection_cond);
200 g_mutex_unlock(_conic_connection_mutex);
202 g_thread_pool_free(_mut_thread_pool, TRUE, TRUE);
207 g_mutex_lock(_mapdb_mutex);
208 sqlite3_close(_curr_repo->db);
209 _curr_repo->db = NULL;
210 g_mutex_unlock(_mapdb_mutex);
212 g_mutex_lock(_mapdb_mutex);
213 gdbm_close(_curr_repo->db);
214 _curr_repo->db = NULL;
215 g_mutex_unlock(_mapdb_mutex);
222 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
226 * Initialize everything required in preparation for calling gtk_main().
229 maemo_mapper_init(gint argc, gchar **argv)
231 GtkWidget *hbox, *label, *vbox;
232 printf("%s()\n", __PRETTY_FUNCTION__);
234 /* Set enum-based constants. */
235 UNITS_ENUM_TEXT[UNITS_KM] = _("km");
236 UNITS_ENUM_TEXT[UNITS_MI] = _("mi.");
237 UNITS_ENUM_TEXT[UNITS_NM] = _("n.m.");
239 ROTATE_DIR_ENUM_TEXT[ROTATE_DIR_UP] = _("Up");
240 ROTATE_DIR_ENUM_TEXT[ROTATE_DIR_RIGHT] = _("Right");
241 ROTATE_DIR_ENUM_TEXT[ROTATE_DIR_DOWN] = _("Down");
242 ROTATE_DIR_ENUM_TEXT[ROTATE_DIR_LEFT] = _("Left");
244 UNBLANK_ENUM_TEXT[UNBLANK_WITH_GPS] = _("When Receiving Any GPS Data");
245 UNBLANK_ENUM_TEXT[UNBLANK_WHEN_MOVING] = _("When Moving");
246 UNBLANK_ENUM_TEXT[UNBLANK_FULLSCREEN] = _("When Moving (Full Screen Only)");
247 UNBLANK_ENUM_TEXT[UNBLANK_WAYPOINT] = _("When Approaching a Waypoint");
248 UNBLANK_ENUM_TEXT[UNBLANK_NEVER] = _("Never");
250 INFO_FONT_ENUM_TEXT[INFO_FONT_XXSMALL] = "xx-small";
251 INFO_FONT_ENUM_TEXT[INFO_FONT_XSMALL] = "x-small";
252 INFO_FONT_ENUM_TEXT[INFO_FONT_SMALL] = "small";
253 INFO_FONT_ENUM_TEXT[INFO_FONT_MEDIUM] = "medium";
254 INFO_FONT_ENUM_TEXT[INFO_FONT_LARGE] = "large";
255 INFO_FONT_ENUM_TEXT[INFO_FONT_XLARGE] = "x-large";
256 INFO_FONT_ENUM_TEXT[INFO_FONT_XXLARGE] = "xx-large";
258 #ifdef MAEMO_CHANGES /* probably not the best macro to check for here */
259 CUSTOM_KEY_ICON[CUSTOM_KEY_UP] = HWK_BUTTON_UP;
260 CUSTOM_KEY_ICON[CUSTOM_KEY_LEFT] = HWK_BUTTON_LEFT;
261 CUSTOM_KEY_ICON[CUSTOM_KEY_DOWN] = HWK_BUTTON_DOWN;
262 CUSTOM_KEY_ICON[CUSTOM_KEY_RIGHT] = HWK_BUTTON_RIGHT;
263 CUSTOM_KEY_ICON[CUSTOM_KEY_SELECT] = HWK_BUTTON_SELECT;
264 CUSTOM_KEY_ICON[CUSTOM_KEY_INCREASE] = HWK_BUTTON_INCREASE;
265 CUSTOM_KEY_ICON[CUSTOM_KEY_DECREASE] = HWK_BUTTON_DECREASE;
266 CUSTOM_KEY_ICON[CUSTOM_KEY_FULLSCREEN] = HWK_BUTTON_VIEW;
267 CUSTOM_KEY_ICON[CUSTOM_KEY_ESC] = HWK_BUTTON_CANCEL;
269 CUSTOM_KEY_ICON[CUSTOM_KEY_UP] = "Up";
270 CUSTOM_KEY_ICON[CUSTOM_KEY_LEFT] = "Left";
271 CUSTOM_KEY_ICON[CUSTOM_KEY_DOWN] = "Down";
272 CUSTOM_KEY_ICON[CUSTOM_KEY_RIGHT] = "Right";
273 CUSTOM_KEY_ICON[CUSTOM_KEY_SELECT] = "Enter";
274 CUSTOM_KEY_ICON[CUSTOM_KEY_INCREASE] = "F7";
275 CUSTOM_KEY_ICON[CUSTOM_KEY_DECREASE] = "F8";
276 CUSTOM_KEY_ICON[CUSTOM_KEY_FULLSCREEN] = "F6";
277 CUSTOM_KEY_ICON[CUSTOM_KEY_ESC] = "Esc";
280 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_UP] = CUSTOM_ACTION_RESET_VIEW_ANGLE;
281 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_LEFT] =CUSTOM_ACTION_ROTATE_COUNTERCLOCKWISE;
282 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_DOWN] = CUSTOM_ACTION_TOGGLE_AUTOROTATE;
283 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_RIGHT] = CUSTOM_ACTION_ROTATE_CLOCKWISE;
284 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_SELECT] = CUSTOM_ACTION_TOGGLE_AUTOCENTER;
285 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_INCREASE] = CUSTOM_ACTION_ZOOM_IN;
286 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_DECREASE] = CUSTOM_ACTION_ZOOM_OUT;
287 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_FULLSCREEN]= CUSTOM_ACTION_TOGGLE_FULLSCREEN;
288 CUSTOM_KEY_DEFAULT[CUSTOM_KEY_ESC] = CUSTOM_ACTION_TOGGLE_TRACKS;
290 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_PAN_NORTH] = _("Pan North");
291 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_PAN_WEST] = _("Pan West");
292 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_PAN_SOUTH] = _("Pan South");
293 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_PAN_EAST] = _("Pan East");
294 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_PAN_UP] = _("Pan Up");
295 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_PAN_DOWN] = _("Pan Down");
296 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_PAN_LEFT] = _("Pan Left");
297 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_PAN_RIGHT] = _("Pan Right");
298 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_RESET_VIEW_ANGLE]
299 = _("Reset Viewing Angle");
300 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_ROTATE_CLOCKWISE]
301 = _("Rotate View Clockwise");
302 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_ROTATE_COUNTERCLOCKWISE]
303 = _("Rotate View Counter-Clockwise");
304 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_AUTOCENTER]
305 = _("Toggle Auto-Center");
306 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_AUTOROTATE]
307 = _("Toggle Auto-Rotate");
308 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_FULLSCREEN]
309 = _("Toggle Fullscreen");
310 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_ZOOM_IN] = _("Zoom In");
311 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_ZOOM_OUT] = _("Zoom Out");
312 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_TRACKING]
313 = _("Toggle Tracking");
314 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_TRACKS]
315 = _("Toggle Tracks/Routes");
316 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_SCALE] = _("Toggle Scale");
317 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_POI] = _("Toggle POIs");
318 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_CHANGE_REPO]
319 = _("Select Next Repository");
320 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_ROUTE_DISTNEXT]
321 = _("Show Distance to Next Waypoint");
322 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_ROUTE_DISTLAST]
323 = _("Show Distance to End of Route");
324 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TRACK_BREAK]=_("Insert Track Break");
325 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TRACK_CLEAR] = _("Clear Track");
326 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TRACK_DISTLAST]
327 = _("Show Distance from Last Break");
328 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TRACK_DISTFIRST]
329 = _("Show Distance from Beginning");
330 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_GPS] = _("Toggle GPS");
331 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_GPSINFO]=_("Toggle GPS Info");
332 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_TOGGLE_SPEEDLIMIT]
333 = _("Toggle Speed Limit");
334 CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_RESET_BLUETOOTH]
335 = _("Reset Bluetooth");
337 DEG_FORMAT_ENUM_TEXT[DDPDDDDD] = "-dd.ddddd°";
338 DEG_FORMAT_ENUM_TEXT[DD_MMPMMM] = "-dd°mm.mmm'";
339 DEG_FORMAT_ENUM_TEXT[DD_MM_SSPS] = "-dd°mm'ss.s\"";
340 DEG_FORMAT_ENUM_TEXT[DDPDDDDD_NSEW] = "dd.ddddd° S";
341 DEG_FORMAT_ENUM_TEXT[DD_MMPMMM_NSEW] = "dd°mm.mmm' S";
342 DEG_FORMAT_ENUM_TEXT[DD_MM_SSPS_NSEW] = "dd°mm'ss.s\" S";
343 DEG_FORMAT_ENUM_TEXT[NSEW_DDPDDDDD] = "S dd.ddddd°";
344 DEG_FORMAT_ENUM_TEXT[NSEW_DD_MMPMMM] = "S dd° mm.mmm'";
345 DEG_FORMAT_ENUM_TEXT[NSEW_DD_MM_SSPS] = "S dd° mm' ss.s\"";
347 SPEED_LOCATION_ENUM_TEXT[SPEED_LOCATION_TOP_LEFT] = _("Top-Left");
348 SPEED_LOCATION_ENUM_TEXT[SPEED_LOCATION_TOP_RIGHT] = _("Top-Right");
349 SPEED_LOCATION_ENUM_TEXT[SPEED_LOCATION_BOTTOM_RIGHT] = _("Bottom-Right");
350 SPEED_LOCATION_ENUM_TEXT[SPEED_LOCATION_BOTTOM_LEFT] = _("Bottom-Left");
352 GPS_RCVR_ENUM_TEXT[GPS_RCVR_BT] = _("Bluetooth");
353 GPS_RCVR_ENUM_TEXT[GPS_RCVR_GPSD] = _("GPSD");
354 GPS_RCVR_ENUM_TEXT[GPS_RCVR_FILE] = _("File");
356 /* Set up track array (must be done before config). */
357 memset(&_track, 0, sizeof(_track));
358 memset(&_route, 0, sizeof(_route));
359 /* initialisation of paths is done in path_init() */
361 _mapdb_mutex = g_mutex_new();
362 _mut_priority_mutex = g_mutex_new();
363 _mouse_mutex = g_mutex_new();
366 _conic_connection_mutex = g_mutex_new();
367 _conic_connection_cond = g_cond_new();
371 map_cache_init(_map_cache_size);
373 /* Initialize _program. */
374 _program = HILDON_PROGRAM(hildon_program_get_instance());
375 g_set_application_name("Maemo Mapper");
377 /* Initialize _window. */
378 _window = GTK_WIDGET(hildon_window_new());
379 hildon_program_add_window(_program, HILDON_WINDOW(_window));
381 gtk_window_set_default_size(GTK_WINDOW(_window), 800, 480);
383 /* Lets go fullscreen if so requested in saved config */
385 gtk_window_fullscreen(GTK_WINDOW(_window));
388 /* Create and add widgets and supporting data. */
389 hbox = gtk_hbox_new(FALSE, 0);
390 gtk_container_add(GTK_CONTAINER(_window), hbox);
392 _gps_widget = gtk_frame_new("GPS Info");
393 gtk_container_add(GTK_CONTAINER(_gps_widget),
394 vbox = gtk_vbox_new(FALSE, 0));
395 gtk_widget_set_size_request(GTK_WIDGET(_gps_widget), 180, 0);
396 gtk_box_pack_start(GTK_BOX(hbox), _gps_widget, FALSE, TRUE, 0);
398 label = gtk_label_new(" ");
399 gtk_widget_set_size_request(GTK_WIDGET(label), -1, 10);
400 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
402 _text_lat = gtk_label_new(" --- ");
403 gtk_widget_set_size_request(GTK_WIDGET(_text_lat), -1, 30);
404 gtk_box_pack_start(GTK_BOX(vbox), _text_lat, FALSE, TRUE, 0);
406 _text_lon = gtk_label_new(" --- ");
407 gtk_widget_set_size_request(GTK_WIDGET(_text_lon), -1, 30);
408 gtk_box_pack_start(GTK_BOX(vbox), _text_lon, FALSE, TRUE, 0);
410 _text_speed = gtk_label_new(" --- ");
411 gtk_widget_set_size_request(GTK_WIDGET(_text_speed), -1, 30);
412 gtk_box_pack_start(GTK_BOX(vbox), _text_speed, FALSE, TRUE, 0);
414 _text_alt = gtk_label_new(" --- ");
415 gtk_widget_set_size_request(GTK_WIDGET(_text_alt), -1, 30);
416 gtk_box_pack_start(GTK_BOX(vbox), _text_alt, FALSE, TRUE, 0);
418 label = gtk_label_new(" ");
419 gtk_widget_set_size_request(GTK_WIDGET(label), -1, 10);
420 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
422 _sat_panel = gtk_drawing_area_new ();
423 gtk_widget_set_size_request (_sat_panel, -1, 100);
424 gtk_box_pack_start(GTK_BOX(vbox), _sat_panel, TRUE, TRUE, 0);
426 label = gtk_label_new(" ");
427 gtk_widget_set_size_request(GTK_WIDGET(label), -1, 10);
428 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
430 _text_time = gtk_label_new("--:--:--");
431 gtk_widget_set_size_request(GTK_WIDGET(_text_time), -1, 30);
432 gtk_box_pack_start(GTK_BOX(vbox), _text_time, FALSE, TRUE, 0);
434 _heading_panel = gtk_drawing_area_new ();
435 gtk_widget_set_size_request (_heading_panel, -1, 100);
436 gtk_box_pack_start(GTK_BOX(vbox), _heading_panel, TRUE, TRUE, 0);
438 _map_widget = gtk_drawing_area_new();
440 gtk_box_pack_start(GTK_BOX(hbox), _map_widget, TRUE, TRUE, 0);
442 gtk_widget_show_all(hbox);
443 gps_show_info(); /* hides info, if necessary. */
445 gtk_widget_realize(_map_widget);
447 /* Tweak the foreground and background colors a little bit... */
451 GdkColormap *colormap = gtk_widget_get_colormap(_map_widget);
454 _map_widget->style->fg_gc[GTK_STATE_NORMAL],
456 gdk_colormap_query_color(colormap, values.foreground.pixel, &color);
457 gtk_widget_modify_fg(_map_widget, GTK_STATE_ACTIVE, &color);
460 _map_widget->style->bg_gc[GTK_STATE_NORMAL],
462 gdk_colormap_query_color(colormap, values.foreground.pixel, &color);
463 gtk_widget_modify_bg(_map_widget, GTK_STATE_ACTIVE, &color);
465 /* Use a black background for _map_widget, since missing tiles are
466 * also drawn with a black background. */
467 color.red = 0; color.green = 0; color.blue = 0;
468 gtk_widget_modify_bg(_map_widget,
469 GTK_STATE_NORMAL, &color);
472 _map_pixmap = gdk_pixmap_new(_map_widget->window, 1, 1, -1);
473 /* -1: use bit depth of widget->window. */
475 _map_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1);
477 _mut_exists_table = g_hash_table_new(
478 (GHashFunc)mut_exists_hashfunc, (GEqualFunc)mut_exists_equalfunc);
479 _mut_priority_tree = g_tree_new((GCompareFunc)mut_priority_comparefunc);
481 _mut_thread_pool = g_thread_pool_new(
482 (GFunc)thread_proc_mut, NULL, NUM_DOWNLOAD_THREADS, FALSE, NULL);
483 _mrt_thread_pool = g_thread_pool_new(
484 (GFunc)thread_render_map, NULL, 1, FALSE, NULL);
486 /* Connect signals. */
487 g_signal_connect(G_OBJECT(_window), "destroy",
488 G_CALLBACK(gtk_main_quit), NULL);
490 memset(&_autoroute_data, 0, sizeof(_autoroute_data));
492 latlon2unit(_gps.lat, _gps.lon, _pos.unitx, _pos.unity);
494 /* Initialize our line styles. */
506 /* If present, attempt to load the file specified on the command line. */
509 GnomeVFSResult vfs_result;
514 /* Get the selected filename. */
515 file_uri = gnome_vfs_make_uri_from_shell_arg(argv[1]);
517 if(GNOME_VFS_OK != (vfs_result = gnome_vfs_read_entire_file(
518 file_uri, &size, &buffer)))
520 gchar buffer[BUFFER_SIZE];
521 snprintf(buffer, sizeof(buffer),
522 "%s:\n%s", _("Failed to open file for reading"),
523 gnome_vfs_result_to_string(vfs_result));
524 popup_error(_window, buffer);
528 if(gpx_path_parse(&_route, buffer, size, 0))
530 path_save_route_to_db();
531 MACRO_BANNER_SHOW_INFO(_window, _("Route Opened"));
534 popup_error(_window, _("Error parsing GPX file."));
540 /* If we have a route, calculate the next point. */
541 route_find_nearest_point();
544 _conic_conn = con_ic_connection_new();
545 g_object_set(_conic_conn, "automatic-connection-events", TRUE, NULL);
546 g_signal_connect(G_OBJECT(_conic_conn), "connection-event",
547 G_CALLBACK(conic_conn_event), NULL);
550 g_idle_add((GSourceFunc)window_present, NULL);
553 osso_hw_set_event_cb(_osso, NULL, osso_cb_hw_state, NULL);
555 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
559 osso_cb_hw_state_idle(osso_hw_state_t *state)
561 static gboolean _must_save_data = FALSE;
562 printf("%s(inact=%d, save=%d, shut=%d, memlow=%d, state=%d)\n",
563 __PRETTY_FUNCTION__, state->system_inactivity_ind,
564 state->save_unsaved_data_ind, state->shutdown_ind,
565 state->memory_low_ind, state->sig_device_mode_ind);
567 if(state->shutdown_ind)
569 maemo_mapper_destroy();
573 if(state->save_unsaved_data_ind)
576 _must_save_data = TRUE;
579 if(state->memory_low_ind)
581 // Disable the map cache and set the next max cache size to
582 // slightly less than the current cache size.
583 _map_cache_size = map_cache_resize(0) * 0.8;
584 _map_cache_enabled = FALSE;
588 if(!_map_cache_enabled)
590 // Restore the map cache.
591 map_cache_resize(_map_cache_size);
592 _map_cache_enabled = TRUE;
598 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
603 osso_cb_hw_state(osso_hw_state_t *state, gpointer data)
605 printf("%s()\n", __PRETTY_FUNCTION__);
606 osso_hw_state_t *state_copy = g_new(osso_hw_state_t, 1);
607 memcpy(state_copy, state, sizeof(osso_hw_state_t));
608 g_idle_add((GSourceFunc)osso_cb_hw_state_idle, state_copy);
609 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
613 main(gint argc, gchar *argv[])
615 printf("%s()\n", __PRETTY_FUNCTION__);
617 /* Initialize localization. */
618 setlocale(LC_ALL, "");
619 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
620 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
621 textdomain(GETTEXT_PACKAGE);
625 /* Initialize _osso. */
626 _osso = osso_initialize("com.gnuite.maemo_mapper", VERSION, TRUE, NULL);
629 g_printerr("osso_initialize failed.\n");
633 gtk_init(&argc, &argv);
637 gconf_init(argc, argv, NULL);
639 /* Init Gnome-VFS. */
643 /* This is just some helpful DBUS testing code. */
646 /* Try to set the center to a new lat/lon. */
647 GError *error = NULL;
650 DBusGConnection *bus;
653 bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
656 g_printerr("Error: %s\n", error->message);
660 proxy = dbus_g_proxy_new_for_name(bus,
661 MM_DBUS_SERVICE, MM_DBUS_PATH, MM_DBUS_INTERFACE);
663 lat = g_ascii_strtod((argv[1]), &error_check);
664 if(error_check == argv[1])
666 g_printerr("Failed to parse string as float: %s\n", argv[1]);
670 lon = g_ascii_strtod((argv[2]), &error_check);
671 if(error_check == argv[2])
673 g_printerr("Failed to parse string as float: %s\n", argv[2]);
680 /* We are specifying a zoom. */
683 zoom = g_ascii_strtod((argv[3]), &error_check);
684 if(error_check == argv[3])
686 g_printerr("Failed to parse string as integer: %s\n", argv[3]);
689 if(!dbus_g_proxy_call(proxy, MM_DBUS_METHOD_SET_VIEW_POSITION,
691 G_TYPE_DOUBLE, lat, G_TYPE_DOUBLE, lon,
692 G_TYPE_INT, zoom, G_TYPE_INVALID,
696 g_printerr("Error: %s\n", error->message);
702 /* Not specifying a zoom. */
703 if(!dbus_g_proxy_call(proxy, MM_DBUS_METHOD_SET_VIEW_POSITION,
705 G_TYPE_DOUBLE, lat, G_TYPE_DOUBLE, lon, G_TYPE_INVALID,
709 g_printerr("Error: %s\n", error->message);
714 g_object_unref(proxy);
715 dbus_g_connection_unref(bus);
721 maemo_mapper_init(argc, argv);
725 maemo_mapper_destroy();
727 osso_deinitialize(_osso);
729 vprintf("%s(): return\n", __PRETTY_FUNCTION__);