]> git.itanic.dy.fi Git - maemo-mapper/blob - src/data.c
fc68babc204cce591b6d690f93ee8ad36b4613bb
[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 /** The context menu for the map. */
83 GtkMenu *_map_cmenu = NULL;
84
85 gint _map_offset_devx;
86 gint _map_offset_devy;
87
88 gint _map_rotate_angle = 0;
89 gfloat _map_rotate_matrix[4] = { 1.f, 0.f, 0.f, 1.f };
90 gfloat _map_reverse_matrix[4] = { 1.f, 0.f, 0.f, 1.f };
91
92 GtkWidget *_gps_widget = NULL;
93 GtkWidget *_text_lat = NULL;
94 GtkWidget *_text_lon = NULL;
95 GtkWidget *_text_speed = NULL;
96 GtkWidget *_text_alt = NULL;
97 GtkWidget *_sat_panel = NULL;
98 GtkWidget *_text_time = NULL;
99 GtkWidget *_heading_panel = NULL;
100
101 /** GPS data. */
102 Point _pos = { 0, 0, 0, INT_MIN};
103 const Point _point_null = { 0, 0, 0, 0};
104
105 GpsData _gps;
106 GpsSatelliteData _gps_sat[12];
107 gboolean _satdetails_on = FALSE;
108
109 gboolean _is_first_time = FALSE;
110
111
112 /** VARIABLES FOR MAINTAINING STATE OF THE CURRENT VIEW. */
113
114 /** The "zoom" level defines the resolution of a pixel, from 0 to MAX_ZOOM.
115  * Each pixel in the current view is exactly (1 << _zoom) "units" wide. */
116 gint _zoom = 3; /* zoom level, from 0 to MAX_ZOOM. */
117 Point _center = {-1, -1}; /* current center location, X. */
118
119 gint _next_zoom = 3;
120 Point _next_center = {-1, -1};
121 gint _next_map_rotate_angle = 0;
122 GdkPixbuf *_redraw_wait_icon = NULL;
123 GdkRectangle _redraw_wait_bounds = { 0, 0, 0, 0};
124
125 gint _map_correction_unitx = 0;
126 gint _map_correction_unity = 0;
127
128 /** CACHED SCREEN INFORMATION THAT IS DEPENDENT ON THE CURRENT VIEW. */
129 gint _view_width_pixels = 0;
130 gint _view_height_pixels = 0;
131 gint _view_halfwidth_pixels = 0;
132 gint _view_halfheight_pixels = 0;
133
134 /** The current track and route. */
135 Path _track;
136 Path _route;
137 gint _track_index_last_saved = 0;
138
139 /** THE GdkGC OBJECTS USED FOR DRAWING. */
140 GdkGC *_gc[COLORABLE_ENUM_COUNT];
141 GdkColor _color[COLORABLE_ENUM_COUNT];
142
143 /** BANNERS. */
144 GtkWidget *_connect_banner = NULL;
145 GtkWidget *_fix_banner = NULL;
146 GtkWidget *_waypoint_banner = NULL;
147 GtkWidget *_download_banner = NULL;
148
149 /** DOWNLOAD PROGRESS. */
150 gboolean _conic_is_connected = FALSE;
151 GMutex *_mapdb_mutex = NULL;
152 GMutex *_mouse_mutex = NULL;
153 volatile gint _num_downloads = 0;
154 gint _curr_download = 0;
155 GHashTable *_mut_exists_table = NULL;
156 GTree *_mut_priority_tree = NULL;
157 GMutex *_mut_priority_mutex = NULL;
158 /* NOMORE gint _dl_errors = 0; */
159 GThreadPool *_mut_thread_pool = NULL;
160 GThreadPool *_mrt_thread_pool = NULL;
161
162 /* Need to refresh map after downloads finished. This is needed when during render task we find tile
163    to download and we have something to draw on top of it. */
164 gboolean _refresh_map_after_download = FALSE;
165
166 /** CONFIGURATION INFORMATION. */
167 GpsRcvrInfo _gri = { 0, 0, 0, 0, 0 };
168 ConnState _gps_state;
169 gchar *_route_dir_uri = NULL;
170 gchar *_track_file_uri = NULL;
171 CenterMode _center_mode = CENTER_LEAD;
172 gboolean _center_rotate = TRUE;
173 gboolean _fullscreen = FALSE;
174 gboolean _enable_gps = TRUE;
175 gboolean _enable_tracking = TRUE;
176 gboolean _gps_info = FALSE;
177 gchar *_route_dl_url = NULL;
178 gint _route_dl_radius = 4;
179 gchar *_poi_dl_url = NULL;
180 gint _show_paths = 0;
181 gboolean _show_zoomlevel = TRUE;
182 gboolean _show_scale = TRUE;
183 gboolean _show_comprose = TRUE;
184 gboolean _show_velvec = TRUE;
185 gboolean _show_poi = TRUE;
186 gboolean _auto_download = FALSE;
187 gint _auto_download_precache = 2;
188 gint _lead_ratio = 5;
189 gboolean _lead_is_fixed = FALSE;
190 gint _center_ratio = 5;
191 gint _draw_width = 5;
192 gint _rotate_sens = 5;
193 gint _ac_min_speed = 2;
194 RotateDir _rotate_dir = ROTATE_DIR_UP;
195 gboolean _enable_announce = TRUE;
196 gint _announce_notice_ratio = 8;
197 gboolean _enable_voice = TRUE;
198 GSList *_loc_list;
199 GtkListStore *_loc_model;
200 UnitType _units = UNITS_KM;
201 CustomAction _action[CUSTOM_KEY_ENUM_COUNT];
202 gint _degformat = DDPDDDDD;
203 gboolean _speed_limit_on = FALSE;
204 gint _speed_limit = 100;
205 gboolean _speed_excess = FALSE;
206 SpeedLocation _speed_location = SPEED_LOCATION_TOP_RIGHT;
207 UnblankOption _unblank_option = UNBLANK_FULLSCREEN;
208 InfoFontSize _info_font_size = INFO_FONT_MEDIUM;
209
210 GList *_repo_list = NULL;
211 RepoData *_curr_repo = NULL;
212
213 /** POI */
214 gchar *_poi_db_filename = NULL;
215 gchar *_poi_db_dirname = NULL;
216 gint _poi_zoom = 6;
217 gboolean _poi_enabled = FALSE;
218
219 /** The singleton auto-route-download data. */
220 AutoRouteDownloadData _autoroute_data;
221
222
223 /*********************
224  * BELOW: MENU ITEMS *
225  *********************/
226
227 /* Menu items for the "Route" submenu. */
228 GtkWidget *_menu_route_open_item = NULL;
229 GtkWidget *_menu_route_download_item = NULL;
230 GtkWidget *_menu_route_save_item = NULL;
231 GtkWidget *_menu_route_distnext_item = NULL;
232 GtkWidget *_menu_route_distlast_item = NULL;
233 GtkWidget *_menu_route_reset_item = NULL;
234 GtkWidget *_menu_route_clear_item = NULL;
235
236 /* Menu items for the "Track" submenu. */
237 GtkWidget *_menu_track_open_item = NULL;
238 GtkWidget *_menu_track_save_item = NULL;
239 GtkWidget *_menu_track_insert_break_item = NULL;
240 GtkWidget *_menu_track_insert_mark_item = NULL;
241 GtkWidget *_menu_track_distlast_item = NULL;
242 GtkWidget *_menu_track_distfirst_item = NULL;
243 GtkWidget *_menu_track_clear_item = NULL;
244 GtkWidget *_menu_track_enable_tracking_item = NULL;
245
246 /* Menu items for the "POI" submenu. */
247 GtkWidget *_menu_poi_item = NULL;
248 GtkWidget *_menu_poi_import_item = NULL;
249 GtkWidget *_menu_poi_download_item = NULL;
250 GtkWidget *_menu_poi_browse_item = NULL;
251 GtkWidget *_menu_poi_categories_item = NULL;
252
253 /* Menu items for the "Maps" submenu. */
254 GtkWidget *_menu_maps_submenu = NULL;
255 GtkWidget *_menu_layers_submenu = NULL;
256 GtkWidget *_menu_maps_mapman_item = NULL;
257 GtkWidget *_menu_maps_auto_download_item = NULL;
258 GtkWidget *_menu_maps_repoman_item = NULL;
259 GtkWidget *_menu_maps_repodown_item = NULL;
260
261 /* Menu items for the "View" submenu. */
262 GtkWidget *_menu_view_zoom_in_item = NULL;
263 GtkWidget *_menu_view_zoom_out_item = NULL;
264
265 GtkWidget *_menu_view_rotate_clock_item = NULL;
266 GtkWidget *_menu_view_rotate_counter_item = NULL;
267 GtkWidget *_menu_view_rotate_reset_item = NULL;
268 GtkWidget *_menu_view_rotate_auto_item = NULL;
269
270 GtkWidget *_menu_view_pan_up_item = NULL;
271 GtkWidget *_menu_view_pan_down_item = NULL;
272 GtkWidget *_menu_view_pan_left_item = NULL;
273 GtkWidget *_menu_view_pan_right_item = NULL;
274 GtkWidget *_menu_view_pan_north_item = NULL;
275 GtkWidget *_menu_view_pan_south_item = NULL;
276 GtkWidget *_menu_view_pan_west_item = NULL;
277 GtkWidget *_menu_view_pan_east_item = NULL;
278
279 GtkWidget *_menu_view_fullscreen_item = NULL;
280
281 GtkWidget *_menu_view_show_zoomlevel_item = NULL;
282 GtkWidget *_menu_view_show_scale_item = NULL;
283 GtkWidget *_menu_view_show_comprose_item = NULL;
284 GtkWidget *_menu_view_show_routes_item = NULL;
285 GtkWidget *_menu_view_show_tracks_item = NULL;
286 GtkWidget *_menu_view_show_velvec_item = NULL;
287 GtkWidget *_menu_view_show_poi_item = NULL;
288
289 GtkWidget *_menu_view_ac_latlon_item = NULL;
290 GtkWidget *_menu_view_ac_lead_item = NULL;
291 GtkWidget *_menu_view_ac_none_item = NULL;
292
293 GtkWidget *_menu_view_goto_latlon_item = NULL;
294 GtkWidget *_menu_view_goto_address_item = NULL;
295 GtkWidget *_menu_view_goto_gps_item = NULL;
296 GtkWidget *_menu_view_goto_nextway_item = NULL;
297 GtkWidget *_menu_view_goto_nearpoi_item = NULL;
298
299 /* Menu items for the "GPS" submenu. */
300 GtkWidget *_menu_gps_enable_item = NULL;
301 GtkWidget *_menu_gps_show_info_item = NULL;
302 GtkWidget *_menu_gps_details_item = NULL;
303 GtkWidget *_menu_gps_reset_item = NULL;
304
305 /* Menu items for the other menu items. */
306 GtkWidget *_menu_settings_item = NULL;
307 GtkWidget *_menu_help_item = NULL;
308 GtkWidget *_menu_about_item = NULL;
309 GtkWidget *_menu_close_item = NULL;
310
311 /*********************
312  * ABOVE: MENU ITEMS *
313  *********************/
314
315
316 /*****************************
317  * BELOW: CONTEXT MENU ITEMS *
318  *****************************/
319
320 gboolean _mouse_is_dragging = FALSE;
321 gboolean _mouse_is_down = FALSE;
322 gint _cmenu_position_x = 0;
323 gint _cmenu_position_y = 0;
324
325 /* Menu items for the "Location" context menu. */
326 GtkWidget *_cmenu_loc_show_latlon_item = NULL;
327 GtkWidget *_cmenu_loc_route_to_item = NULL;
328 GtkWidget *_cmenu_loc_distance_to_item = NULL;
329 GtkWidget *_cmenu_loc_download_poi_item = NULL;
330 GtkWidget *_cmenu_loc_browse_poi_item = NULL;
331 GtkWidget *_cmenu_loc_add_route_item = NULL;
332 GtkWidget *_cmenu_loc_add_way_item = NULL;
333 GtkWidget *_cmenu_loc_add_poi_item = NULL;
334 GtkWidget *_cmenu_loc_set_gps_item = NULL;
335 GtkWidget *_cmenu_loc_apply_correction_item = NULL;
336
337 /* Menu items for the "Waypoint" context menu. */
338 GtkWidget *_cmenu_way_show_latlon_item = NULL;
339 GtkWidget *_cmenu_way_show_desc_item = NULL;
340 GtkWidget *_cmenu_way_clip_latlon_item = NULL;
341 GtkWidget *_cmenu_way_clip_desc_item = NULL;
342 GtkWidget *_cmenu_way_route_to_item = NULL;
343 GtkWidget *_cmenu_way_distance_to_item = NULL;
344 GtkWidget *_cmenu_way_delete_item = NULL;
345 GtkWidget *_cmenu_way_add_poi_item = NULL;
346 GtkWidget *_cmenu_way_goto_nextway_item = NULL;
347
348 /* Menu items for the "POI" context menu. */
349 GtkWidget *_cmenu_poi_submenu = NULL;
350 GtkWidget *_cmenu_poi_edit_poi_item = NULL;
351 GtkWidget *_cmenu_poi_route_to_item = NULL;
352 GtkWidget *_cmenu_poi_distance_to_item = NULL;
353 GtkWidget *_cmenu_poi_add_route_item = NULL;
354 GtkWidget *_cmenu_poi_add_way_item = NULL;
355 GtkWidget *_cmenu_poi_goto_nearpoi_item = NULL;
356
357 /*****************************
358  * ABOVE: CONTEXT MENU ITEMS *
359  *****************************/
360