]> git.itanic.dy.fi Git - maemo-mapper/blob - src/data.c
* Added an in-memory map cache to improve pan performance (thanks to Tim
[maemo-mapper] / src / data.c
1 /*
2  * Copyright (C) 2006, 2007 John Costigan.
3  *
4  * POI and GPS-Info code originally written by Cezary Jackiewicz.
5  *
6  * Default map data provided by http://www.openstreetmap.org/
7  *
8  * This file is part of Maemo Mapper.
9  *
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.
14  *
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.
19  *
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/>.
22  */
23
24 #define _GNU_SOURCE
25
26 #include "types.h"
27 #include "data.h"
28 #include "defines.h"
29
30 /* Constants regarding enums and defaults. */
31 gchar *UNITS_ENUM_TEXT[UNITS_ENUM_COUNT];
32
33 /* UNITS_CONVERT, when multiplied, converts from NM. */
34 gdouble UNITS_CONVERT[] =
35 {
36     1.85200,
37     1.150779448,
38     1.0,
39 };
40
41 gchar *UNBLANK_ENUM_TEXT[UNBLANK_ENUM_COUNT];
42 gchar *INFO_FONT_ENUM_TEXT[INFO_FONT_ENUM_COUNT];
43 gchar *ROTATE_DIR_ENUM_TEXT[ROTATE_DIR_ENUM_COUNT];
44 gint ROTATE_DIR_ENUM_DEGREES[ROTATE_DIR_ENUM_COUNT] = { 0, 90, 180, 270 };
45 gchar *CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_ENUM_COUNT];
46 gchar *CUSTOM_KEY_GCONF[CUSTOM_KEY_ENUM_COUNT];
47 gchar *CUSTOM_KEY_ICON[CUSTOM_KEY_ENUM_COUNT];
48 CustomAction CUSTOM_KEY_DEFAULT[CUSTOM_KEY_ENUM_COUNT];
49 gchar *COLORABLE_GCONF[COLORABLE_ENUM_COUNT];
50 GdkColor COLORABLE_DEFAULT[COLORABLE_ENUM_COUNT] =
51 {
52     {0, 0x0000, 0x0000, 0xc000}, /* COLORABLE_MARK */
53     {0, 0x6000, 0x6000, 0xf800}, /* COLORABLE_MARK_VELOCITY */
54     {0, 0x8000, 0x8000, 0x8000}, /* COLORABLE_MARK_OLD */
55     {0, 0xe000, 0x0000, 0x0000}, /* COLORABLE_TRACK */
56     {0, 0xa000, 0x0000, 0x0000}, /* COLORABLE_TRACK_MARK */
57     {0, 0x7000, 0x0000, 0x0000}, /* COLORABLE_TRACK_BREAK */
58     {0, 0x0000, 0xa000, 0x0000}, /* COLORABLE_ROUTE */
59     {0, 0x0000, 0x8000, 0x0000}, /* COLORABLE_ROUTE_WAY */
60     {0, 0x0000, 0x6000, 0x0000}, /* COLORABLE_ROUTE_BREAK */
61     {0, 0xa000, 0x0000, 0xa000}  /* COLORABLE_POI */
62 };
63 gchar *DEG_FORMAT_ENUM_TEXT[DEG_FORMAT_ENUM_COUNT];
64 gchar *SPEED_LOCATION_ENUM_TEXT[SPEED_LOCATION_ENUM_COUNT];
65 gchar *GPS_RCVR_ENUM_TEXT[GPS_RCVR_ENUM_COUNT];
66
67 /** The main GtkContainer of the application. */
68 GtkWidget *_window = NULL;
69
70 /** The main OSSO context of the application. */
71 osso_context_t *_osso = NULL;
72
73 /** The widget that provides the visual display of the map. */
74 GtkWidget *_map_widget = NULL;
75
76 /** The backing pixmap of _map_widget. */
77 GdkPixmap *_map_pixmap = NULL;
78
79 /** The backing pixmap of _map_widget. */
80 GdkPixbuf *_map_pixbuf = NULL;
81
82 gint _map_offset_devx;
83 gint _map_offset_devy;
84
85 gint _map_rotate_angle = 0;
86 gfloat _map_rotate_matrix[4] = { 1.f, 0.f, 0.f, 1.f };
87 gfloat _map_reverse_matrix[4] = { 1.f, 0.f, 0.f, 1.f };
88
89 GtkWidget *_gps_widget = NULL;
90 GtkWidget *_text_lat = NULL;
91 GtkWidget *_text_lon = NULL;
92 GtkWidget *_text_speed = NULL;
93 GtkWidget *_text_alt = NULL;
94 GtkWidget *_sat_panel = NULL;
95 GtkWidget *_text_time = NULL;
96 GtkWidget *_heading_panel = NULL;
97
98 /** GPS data. */
99 Point _pos = { 0, 0, 0, INT_MIN};
100 const Point _point_null = { 0, 0, 0, 0};
101
102 GpsData _gps;
103 GpsSatelliteData _gps_sat[12];
104 gboolean _satdetails_on = FALSE;
105
106 gboolean _is_first_time = FALSE;
107
108
109 /** VARIABLES FOR MAINTAINING STATE OF THE CURRENT VIEW. */
110
111 /** The "zoom" level defines the resolution of a pixel, from 0 to MAX_ZOOM.
112  * Each pixel in the current view is exactly (1 << _zoom) "units" wide. */
113 gint _zoom = 3; /* zoom level, from 0 to MAX_ZOOM. */
114 Point _center = {-1, -1}; /* current center location, X. */
115
116 gint _next_zoom = 3;
117 Point _next_center = {-1, -1};
118 gint _next_map_rotate_angle = 0;
119 GdkPixbuf *_redraw_wait_icon = NULL;
120 GdkRectangle _redraw_wait_bounds = { 0, 0, 0, 0};
121
122
123 /** CACHED SCREEN INFORMATION THAT IS DEPENDENT ON THE CURRENT VIEW. */
124 gint _view_width_pixels = 0;
125 gint _view_height_pixels = 0;
126 gint _view_halfwidth_pixels = 0;
127 gint _view_halfheight_pixels = 0;
128
129 /** The current track and route. */
130 Path _track;
131 Path _route;
132 gint _track_index_last_saved = 0;
133
134 /** THE GdkGC OBJECTS USED FOR DRAWING. */
135 GdkGC *_gc[COLORABLE_ENUM_COUNT];
136 GdkColor _color[COLORABLE_ENUM_COUNT];
137
138 /** BANNERS. */
139 GtkWidget *_connect_banner = NULL;
140 GtkWidget *_fix_banner = NULL;
141 GtkWidget *_waypoint_banner = NULL;
142 GtkWidget *_download_banner = NULL;
143
144 /** DOWNLOAD PROGRESS. */
145 gboolean _conic_is_connected = FALSE;
146 GMutex *_mapdb_mutex = NULL;
147 GMutex *_mouse_mutex = NULL;
148 volatile gint _num_downloads = 0;
149 gint _curr_download = 0;
150 GHashTable *_mut_exists_table = NULL;
151 GTree *_mut_priority_tree = NULL;
152 GMutex *_mut_priority_mutex = NULL;
153 /* NOMORE gint _dl_errors = 0; */
154 GThreadPool *_mut_thread_pool = NULL;
155 GThreadPool *_mrt_thread_pool = NULL;
156
157 /** CONFIGURATION INFORMATION. */
158 GpsRcvrInfo _gri = { 0, 0, 0, 0, 0 };
159 ConnState _gps_state;
160 gchar *_route_dir_uri = NULL;
161 gchar *_track_file_uri = NULL;
162 CenterMode _center_mode = CENTER_LEAD;
163 gboolean _center_rotate = TRUE;
164 gboolean _fullscreen = FALSE;
165 gboolean _enable_gps = FALSE;
166 gboolean _gps_info = FALSE;
167 gchar *_route_dl_url = NULL;
168 gint _route_dl_radius = 4;
169 gchar *_poi_dl_url = NULL;
170 gint _show_paths = 0;
171 gboolean _show_zoomlevel = TRUE;
172 gboolean _show_scale = TRUE;
173 gboolean _show_comprose = TRUE;
174 gboolean _show_velvec = TRUE;
175 gboolean _show_poi = TRUE;
176 gboolean _auto_download = FALSE;
177 gint _auto_download_precache = 2;
178 gint _lead_ratio = 5;
179 gboolean _lead_is_fixed = FALSE;
180 gint _center_ratio = 5;
181 gint _draw_width = 5;
182 gint _rotate_sens = 5;
183 gint _ac_min_speed = 2;
184 RotateDir _rotate_dir = ROTATE_DIR_UP;
185 gboolean _enable_announce = TRUE;
186 gint _announce_notice_ratio = 8;
187 gboolean _enable_voice = TRUE;
188 GSList *_loc_list;
189 GtkListStore *_loc_model;
190 UnitType _units = UNITS_KM;
191 CustomAction _action[CUSTOM_KEY_ENUM_COUNT];
192 gint _degformat = DDPDDDDD;
193 gboolean _speed_limit_on = FALSE;
194 gint _speed_limit = 100;
195 gboolean _speed_excess = FALSE;
196 SpeedLocation _speed_location = SPEED_LOCATION_TOP_RIGHT;
197 UnblankOption _unblank_option = UNBLANK_FULLSCREEN;
198 InfoFontSize _info_font_size = INFO_FONT_MEDIUM;
199
200 GList *_repo_list = NULL;
201 RepoData *_curr_repo = NULL;
202
203 /** POI */
204 gchar *_poi_db_filename = NULL;
205 gchar *_poi_db_dirname = NULL;
206 gint _poi_zoom = 6;
207 gboolean _poi_enabled = FALSE;
208
209 /** The singleton auto-route-download data. */
210 AutoRouteDownloadData _autoroute_data;
211
212
213 /*********************
214  * BELOW: MENU ITEMS *
215  *********************/
216
217 /* Menu items for the "Route" submenu. */
218 GtkWidget *_menu_route_open_item = NULL;
219 GtkWidget *_menu_route_download_item = NULL;
220 GtkWidget *_menu_route_save_item = NULL;
221 GtkWidget *_menu_route_distnext_item = NULL;
222 GtkWidget *_menu_route_distlast_item = NULL;
223 GtkWidget *_menu_route_reset_item = NULL;
224 GtkWidget *_menu_route_clear_item = NULL;
225
226 /* Menu items for the "Track" submenu. */
227 GtkWidget *_menu_track_open_item = NULL;
228 GtkWidget *_menu_track_save_item = NULL;
229 GtkWidget *_menu_track_insert_break_item = NULL;
230 GtkWidget *_menu_track_insert_mark_item = NULL;
231 GtkWidget *_menu_track_distlast_item = NULL;
232 GtkWidget *_menu_track_distfirst_item = NULL;
233 GtkWidget *_menu_track_clear_item = NULL;
234
235 /* Menu items for the "POI" submenu. */
236 GtkWidget *_menu_poi_item = NULL;
237 GtkWidget *_menu_poi_import_item = NULL;
238 GtkWidget *_menu_poi_download_item = NULL;
239 GtkWidget *_menu_poi_browse_item = NULL;
240 GtkWidget *_menu_poi_categories_item = NULL;
241
242 /* Menu items for the "Maps" submenu. */
243 GtkWidget *_menu_maps_submenu = NULL;
244 GtkWidget *_menu_maps_mapman_item = NULL;
245 GtkWidget *_menu_maps_repoman_item = NULL;
246 GtkWidget *_menu_maps_auto_download_item = NULL;
247
248 /* Menu items for the "View" submenu. */
249 GtkWidget *_menu_view_zoom_in_item = NULL;
250 GtkWidget *_menu_view_zoom_out_item = NULL;
251
252 GtkWidget *_menu_view_rotate_clock_item = NULL;
253 GtkWidget *_menu_view_rotate_counter_item = NULL;
254 GtkWidget *_menu_view_rotate_reset_item = NULL;
255 GtkWidget *_menu_view_rotate_auto_item = NULL;
256
257 GtkWidget *_menu_view_pan_up_item = NULL;
258 GtkWidget *_menu_view_pan_down_item = NULL;
259 GtkWidget *_menu_view_pan_left_item = NULL;
260 GtkWidget *_menu_view_pan_right_item = NULL;
261 GtkWidget *_menu_view_pan_north_item = NULL;
262 GtkWidget *_menu_view_pan_south_item = NULL;
263 GtkWidget *_menu_view_pan_west_item = NULL;
264 GtkWidget *_menu_view_pan_east_item = NULL;
265
266 GtkWidget *_menu_view_fullscreen_item = NULL;
267
268 GtkWidget *_menu_view_show_zoomlevel_item = NULL;
269 GtkWidget *_menu_view_show_scale_item = NULL;
270 GtkWidget *_menu_view_show_comprose_item = NULL;
271 GtkWidget *_menu_view_show_routes_item = NULL;
272 GtkWidget *_menu_view_show_tracks_item = NULL;
273 GtkWidget *_menu_view_show_velvec_item = NULL;
274 GtkWidget *_menu_view_show_poi_item = NULL;
275
276 GtkWidget *_menu_view_ac_latlon_item = NULL;
277 GtkWidget *_menu_view_ac_lead_item = NULL;
278 GtkWidget *_menu_view_ac_none_item = NULL;
279
280 GtkWidget *_menu_view_goto_latlon_item = NULL;
281 GtkWidget *_menu_view_goto_address_item = NULL;
282 GtkWidget *_menu_view_goto_gps_item = NULL;
283 GtkWidget *_menu_view_goto_nextway_item = NULL;
284 GtkWidget *_menu_view_goto_nearpoi_item = NULL;
285
286 /* Menu items for the "GPS" submenu. */
287 GtkWidget *_menu_enable_gps_item = NULL;
288 GtkWidget *_menu_gps_show_info_item = NULL;
289 GtkWidget *_menu_gps_details_item = NULL;
290 GtkWidget *_menu_gps_reset_item = NULL;
291
292 /* Menu items for the other menu items. */
293 GtkWidget *_menu_settings_item = NULL;
294 GtkWidget *_menu_help_item = NULL;
295 GtkWidget *_menu_about_item = NULL;
296 GtkWidget *_menu_close_item = NULL;
297
298 /*********************
299  * ABOVE: MENU ITEMS *
300  *********************/
301
302
303 /*****************************
304  * BELOW: CONTEXT MENU ITEMS *
305  *****************************/
306
307 gboolean _mouse_is_dragging = FALSE;
308 gboolean _mouse_is_down = FALSE;
309 gint _cmenu_position_x = 0;
310 gint _cmenu_position_y = 0;
311
312 /* Menu items for the "Location" context menu. */
313 GtkWidget *_cmenu_loc_show_latlon_item = NULL;
314 GtkWidget *_cmenu_loc_route_to_item = NULL;
315 GtkWidget *_cmenu_loc_distance_to_item = NULL;
316 GtkWidget *_cmenu_loc_download_poi_item = NULL;
317 GtkWidget *_cmenu_loc_browse_poi_item = NULL;
318 GtkWidget *_cmenu_loc_add_route_item = NULL;
319 GtkWidget *_cmenu_loc_add_way_item = NULL;
320 GtkWidget *_cmenu_loc_add_poi_item = NULL;
321 GtkWidget *_cmenu_loc_set_gps_item = NULL;
322
323 /* Menu items for the "Waypoint" context menu. */
324 GtkWidget *_cmenu_way_show_latlon_item = NULL;
325 GtkWidget *_cmenu_way_show_desc_item = NULL;
326 GtkWidget *_cmenu_way_clip_latlon_item = NULL;
327 GtkWidget *_cmenu_way_clip_desc_item = NULL;
328 GtkWidget *_cmenu_way_route_to_item = NULL;
329 GtkWidget *_cmenu_way_distance_to_item = NULL;
330 GtkWidget *_cmenu_way_delete_item = NULL;
331 GtkWidget *_cmenu_way_add_poi_item = NULL;
332 GtkWidget *_cmenu_way_goto_nextway_item = NULL;
333
334 /* Menu items for the "POI" context menu. */
335 GtkWidget *_cmenu_poi_submenu = NULL;
336 GtkWidget *_cmenu_poi_edit_poi_item = NULL;
337 GtkWidget *_cmenu_poi_route_to_item = NULL;
338 GtkWidget *_cmenu_poi_distance_to_item = NULL;
339 GtkWidget *_cmenu_poi_add_route_item = NULL;
340 GtkWidget *_cmenu_poi_add_way_item = NULL;
341 GtkWidget *_cmenu_poi_goto_nearpoi_item = NULL;
342
343 /*****************************
344  * ABOVE: CONTEXT MENU ITEMS *
345  *****************************/
346