]> git.itanic.dy.fi Git - maemo-mapper/blob - src/data.c
Added basic APRS support - Can be disabled by removing definition of INCLUDE_APRS
[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 #ifdef HAVE_CONFIG_H
25 #    include "config.h"
26 #endif
27
28 #define _GNU_SOURCE
29
30 #include "types.h"
31 #include "data.h"
32 #include "defines.h"
33
34 /* Constants regarding enums and defaults. */
35 gchar *UNITS_ENUM_TEXT[UNITS_ENUM_COUNT];
36
37 /* UNITS_CONVERT, when multiplied, converts from NM. */
38 gdouble UNITS_CONVERT[] =
39 {
40     1.85200,
41     1.150779448,
42     1.0,
43 };
44
45 gchar *UNBLANK_ENUM_TEXT[UNBLANK_ENUM_COUNT];
46 gchar *INFO_FONT_ENUM_TEXT[INFO_FONT_ENUM_COUNT];
47 gchar *ROTATE_DIR_ENUM_TEXT[ROTATE_DIR_ENUM_COUNT];
48 gint ROTATE_DIR_ENUM_DEGREES[ROTATE_DIR_ENUM_COUNT] = { 0, 90, 180, 270 };
49 gchar *CUSTOM_ACTION_ENUM_TEXT[CUSTOM_ACTION_ENUM_COUNT];
50 gchar *CUSTOM_KEY_GCONF[CUSTOM_KEY_ENUM_COUNT];
51 gchar *CUSTOM_KEY_ICON[CUSTOM_KEY_ENUM_COUNT];
52 CustomAction CUSTOM_KEY_DEFAULT[CUSTOM_KEY_ENUM_COUNT];
53 gchar *COLORABLE_GCONF[COLORABLE_ENUM_COUNT];
54 GdkColor COLORABLE_DEFAULT[COLORABLE_ENUM_COUNT] =
55 {
56     {0, 0x0000, 0x0000, 0xc000}, /* COLORABLE_MARK */
57     {0, 0x6000, 0x6000, 0xf800}, /* COLORABLE_MARK_VELOCITY */
58     {0, 0x8000, 0x8000, 0x8000}, /* COLORABLE_MARK_OLD */
59     {0, 0xe000, 0x0000, 0x0000}, /* COLORABLE_TRACK */
60     {0, 0xa000, 0x0000, 0x0000}, /* COLORABLE_TRACK_MARK */
61     {0, 0x7000, 0x0000, 0x0000}, /* COLORABLE_TRACK_BREAK */
62     {0, 0x0000, 0xa000, 0x0000}, /* COLORABLE_ROUTE */
63     {0, 0x0000, 0x8000, 0x0000}, /* COLORABLE_ROUTE_WAY */
64     {0, 0x0000, 0x6000, 0x0000}, /* COLORABLE_ROUTE_BREAK */
65     {0, 0xa000, 0x0000, 0xa000}, /* COLORABLE_POI */
66     {0, 0xa000, 0x0000, 0xa000}  /* COLORABLE_APRS_STATION */
67 };
68 CoordFormatSetup DEG_FORMAT_ENUM_TEXT[DEG_FORMAT_ENUM_COUNT];
69 gchar *SPEED_LOCATION_ENUM_TEXT[SPEED_LOCATION_ENUM_COUNT];
70 gchar *GPS_RCVR_ENUM_TEXT[GPS_RCVR_ENUM_COUNT];
71
72 /** The main GtkContainer of the application. */
73 GtkWidget *_window = NULL;
74
75 /** The main OSSO context of the application. */
76 osso_context_t *_osso = NULL;
77
78 /** The widget that provides the visual display of the map. */
79 GtkWidget *_map_widget = NULL;
80
81 /** The backing pixmap of _map_widget. */
82 GdkPixmap *_map_pixmap = NULL;
83
84 /** The backing pixmap of _map_widget. */
85 GdkPixbuf *_map_pixbuf = NULL;
86
87 /** The context menu for the map. */
88 GtkMenu *_map_cmenu = NULL;
89
90 gint _map_offset_devx;
91 gint _map_offset_devy;
92
93 gint _map_rotate_angle = 0;
94 gfloat _map_rotate_matrix[4] = { 1.f, 0.f, 0.f, 1.f };
95 gfloat _map_reverse_matrix[4] = { 1.f, 0.f, 0.f, 1.f };
96
97 GtkWidget *_gps_widget = NULL;
98 GtkWidget *_text_lat = NULL;
99 GtkWidget *_text_lon = NULL;
100 GtkWidget *_text_speed = NULL;
101 GtkWidget *_text_alt = NULL;
102 GtkWidget *_sat_panel = NULL;
103 GtkWidget *_text_time = NULL;
104 GtkWidget *_heading_panel = NULL;
105
106 /** GPS data. */
107 Point _pos = { 0, 0, 0, INT_MIN};
108 const Point _point_null = { 0, 0, 0, 0};
109
110 GpsData _gps;
111 GpsSatelliteData _gps_sat[12];
112 gboolean _satdetails_on = FALSE;
113
114 gboolean _is_first_time = FALSE;
115
116
117 /** VARIABLES FOR MAINTAINING STATE OF THE CURRENT VIEW. */
118
119 /** The "zoom" level defines the resolution of a pixel, from 0 to MAX_ZOOM.
120  * Each pixel in the current view is exactly (1 << _zoom) "units" wide. */
121 gint _zoom = 3; /* zoom level, from 0 to MAX_ZOOM. */
122 Point _center = {-1, -1}; /* current center location, X. */
123
124 gint _next_zoom = 3;
125 Point _next_center = {-1, -1};
126 gint _next_map_rotate_angle = 0;
127 GdkPixbuf *_redraw_wait_icon = NULL;
128 GdkRectangle _redraw_wait_bounds = { 0, 0, 0, 0};
129
130 gint _map_correction_unitx = 0;
131 gint _map_correction_unity = 0;
132
133 /** CACHED SCREEN INFORMATION THAT IS DEPENDENT ON THE CURRENT VIEW. */
134 gint _view_width_pixels = 0;
135 gint _view_height_pixels = 0;
136 gint _view_halfwidth_pixels = 0;
137 gint _view_halfheight_pixels = 0;
138
139 /** The current track and route. */
140 Path _track;
141 Path _route;
142 gint _track_index_last_saved = 0;
143
144 /** THE GdkGC OBJECTS USED FOR DRAWING. */
145 GdkGC *_gc[COLORABLE_ENUM_COUNT];
146 GdkColor _color[COLORABLE_ENUM_COUNT];
147
148 /** BANNERS. */
149 GtkWidget *_connect_banner = NULL;
150 GtkWidget *_fix_banner = NULL;
151 GtkWidget *_waypoint_banner = NULL;
152 GtkWidget *_download_banner = NULL;
153
154 /** DOWNLOAD PROGRESS. */
155 gboolean _conic_is_connected = FALSE;
156 GMutex *_mapdb_mutex = NULL;
157 GMutex *_mouse_mutex = NULL;
158 volatile gint _num_downloads = 0;
159 gint _curr_download = 0;
160 GHashTable *_mut_exists_table = NULL;
161 GTree *_mut_priority_tree = NULL;
162 GMutex *_mut_priority_mutex = NULL;
163 /* NOMORE gint _dl_errors = 0; */
164 GThreadPool *_mut_thread_pool = NULL;
165 GThreadPool *_mrt_thread_pool = NULL;
166
167 /* Need to refresh map after downloads finished. This is needed when during render task we find tile
168    to download and we have something to draw on top of it. */
169 gboolean _refresh_map_after_download = FALSE;
170
171 /** CONFIGURATION INFORMATION. */
172 GpsRcvrInfo _gri = { 0, 0, 0, 0, 0 };
173 ConnState _gps_state;
174 gchar *_route_dir_uri = NULL;
175 gchar *_track_file_uri = NULL;
176 CenterMode _center_mode = CENTER_LEAD;
177 gboolean _center_rotate = TRUE;
178 gboolean _fullscreen = FALSE;
179 gboolean _enable_gps = TRUE;
180 gboolean _enable_tracking = TRUE;
181 gboolean _gps_info = FALSE;
182 gchar *_route_dl_url = NULL;
183 gint _route_dl_radius = 4;
184 gchar *_poi_dl_url = NULL;
185 gint _show_paths = 0;
186 gboolean _show_zoomlevel = TRUE;
187 gboolean _show_scale = TRUE;
188 gboolean _show_comprose = TRUE;
189 gboolean _show_velvec = TRUE;
190 gboolean _show_poi = TRUE;
191 gboolean _auto_download = FALSE;
192 gint _auto_download_precache = 2;
193 gint _lead_ratio = 5;
194 gboolean _lead_is_fixed = FALSE;
195 gint _center_ratio = 5;
196 gint _draw_width = 5;
197 gint _rotate_sens = 5;
198 gint _ac_min_speed = 2;
199 RotateDir _rotate_dir = ROTATE_DIR_UP;
200 gboolean _enable_announce = TRUE;
201 gint _announce_notice_ratio = 8;
202 gboolean _enable_voice = TRUE;
203 GSList *_loc_list;
204 GtkListStore *_loc_model;
205 UnitType _units = UNITS_KM;
206 CustomAction _action[CUSTOM_KEY_ENUM_COUNT];
207 gint _degformat = DDPDDDDD;
208 gboolean _speed_limit_on = FALSE;
209 gint _speed_limit = 100;
210 gboolean _speed_excess = FALSE;
211 SpeedLocation _speed_location = SPEED_LOCATION_TOP_RIGHT;
212 UnblankOption _unblank_option = UNBLANK_FULLSCREEN;
213 InfoFontSize _info_font_size = INFO_FONT_MEDIUM;
214
215 GList *_repo_list = NULL;
216 RepoData *_curr_repo = NULL;
217
218 // APRS config
219 #ifdef INCLUDE_APRS
220
221 gboolean _aprs_enable = FALSE;     // APRS support is enabled
222 gboolean _aprs_inet_enable = FALSE; // Connection to APRS server is enabled
223 gboolean _aprs_tty_enable = FALSE;
224
225 gchar *  _aprs_tnc_bt_mac = NULL;
226 TTncConnection _aprs_tnc_method = TNC_CONNECTION_BT;
227
228 gchar *  _aprs_tty_port = NULL;
229 gchar *  _aprs_server = NULL;      // Server address
230 guint    _aprs_server_port = 23;   // Server port
231 gint     _aprs_std_pos_hist = 1;   // Not currently implemented, so fix as 1
232 gint     _aprs_max_stations = 200; // 0 - no limit
233 gchar *  _aprs_inet_server_validation = NULL; // -1 if not known
234
235 gboolean _aprs_enable_inet_tx = FALSE;
236 gboolean _aprs_enable_tty_tx = FALSE;
237 gchar *  _aprs_mycall = NULL;      // My APRS call
238 gchar *  _aprs_beacon_comment = NULL;  // My TNC Aprs Beacon comment
239
240 gint     _aprs_inet_beacon_interval = 0; // 0 = disabled
241 gint     _aprs_tty_beacon_interval = 0;  // 0 = disabled
242 gchar *  _aprs_inet_beacon_comment = NULL;
243 gboolean _aprs_transmit_compressed_posit = TRUE;
244 gboolean _aprs_show_new_station_alert = TRUE;
245 time_t   _aprs_sec_remove;              /* Station removed after */
246 ConnState _aprs_inet_state;             // State of APRS iNet connection
247 ConnState _aprs_tty_state;
248 gint     _aprs_server_auto_filter_km = 100;
249 gboolean _aprs_server_auto_filter_on = FALSE;
250 //GtkWidget *_aprs_connect_banner = NULL;
251 gchar *  _aprs_unproto_path = NULL;
252 gchar    _aprs_beacon_group;
253 gchar    _aprs_beacon_symbol;
254
255 #endif // INCLUDE_APRS
256 //----------------------
257
258
259 /** POI */
260 gchar *_poi_db_filename = NULL;
261 gchar *_poi_db_dirname = NULL;
262 gint _poi_zoom = 6;
263 gboolean _poi_enabled = FALSE;
264
265 /** The singleton auto-route-download data. */
266 AutoRouteDownloadData _autoroute_data;
267
268
269 /*********************
270  * BELOW: MENU ITEMS *
271  *********************/
272
273 /* Menu items for the "Route" submenu. */
274 GtkWidget *_menu_route_open_item = NULL;
275 GtkWidget *_menu_route_download_item = NULL;
276 GtkWidget *_menu_route_save_item = NULL;
277 GtkWidget *_menu_route_distnext_item = NULL;
278 GtkWidget *_menu_route_distlast_item = NULL;
279 GtkWidget *_menu_route_reset_item = NULL;
280 GtkWidget *_menu_route_clear_item = NULL;
281
282 /* Menu items for the "Track" submenu. */
283 GtkWidget *_menu_track_open_item = NULL;
284 GtkWidget *_menu_track_save_item = NULL;
285 GtkWidget *_menu_track_insert_break_item = NULL;
286 GtkWidget *_menu_track_insert_mark_item = NULL;
287 GtkWidget *_menu_track_distlast_item = NULL;
288 GtkWidget *_menu_track_distfirst_item = NULL;
289 GtkWidget *_menu_track_clear_item = NULL;
290 GtkWidget *_menu_track_enable_tracking_item = NULL;
291
292 /* Menu items for the "POI" submenu. */
293 GtkWidget *_menu_poi_item = NULL;
294 GtkWidget *_menu_poi_import_item = NULL;
295 GtkWidget *_menu_poi_download_item = NULL;
296 GtkWidget *_menu_poi_browse_item = NULL;
297 GtkWidget *_menu_poi_categories_item = NULL;
298
299 /* Menu items for the "Maps" submenu. */
300 GtkWidget *_menu_maps_submenu = NULL;
301 GtkWidget *_menu_layers_submenu = NULL;
302 GtkWidget *_menu_maps_mapman_item = NULL;
303 GtkWidget *_menu_maps_auto_download_item = NULL;
304 GtkWidget *_menu_maps_repoman_item = NULL;
305 GtkWidget *_menu_maps_repodown_item = NULL;
306
307 /* Menu items for the "View" submenu. */
308 GtkWidget *_menu_view_zoom_in_item = NULL;
309 GtkWidget *_menu_view_zoom_out_item = NULL;
310
311 GtkWidget *_menu_view_rotate_clock_item = NULL;
312 GtkWidget *_menu_view_rotate_counter_item = NULL;
313 GtkWidget *_menu_view_rotate_reset_item = NULL;
314 GtkWidget *_menu_view_rotate_auto_item = NULL;
315
316 GtkWidget *_menu_view_pan_up_item = NULL;
317 GtkWidget *_menu_view_pan_down_item = NULL;
318 GtkWidget *_menu_view_pan_left_item = NULL;
319 GtkWidget *_menu_view_pan_right_item = NULL;
320 GtkWidget *_menu_view_pan_north_item = NULL;
321 GtkWidget *_menu_view_pan_south_item = NULL;
322 GtkWidget *_menu_view_pan_west_item = NULL;
323 GtkWidget *_menu_view_pan_east_item = NULL;
324
325 GtkWidget *_menu_view_fullscreen_item = NULL;
326
327 GtkWidget *_menu_view_show_zoomlevel_item = NULL;
328 GtkWidget *_menu_view_show_scale_item = NULL;
329 GtkWidget *_menu_view_show_comprose_item = NULL;
330 GtkWidget *_menu_view_show_routes_item = NULL;
331 GtkWidget *_menu_view_show_tracks_item = NULL;
332 GtkWidget *_menu_view_show_velvec_item = NULL;
333 GtkWidget *_menu_view_show_poi_item = NULL;
334
335 GtkWidget *_menu_view_ac_latlon_item = NULL;
336 GtkWidget *_menu_view_ac_lead_item = NULL;
337 GtkWidget *_menu_view_ac_none_item = NULL;
338
339 GtkWidget *_menu_view_goto_latlon_item = NULL;
340 GtkWidget *_menu_view_goto_address_item = NULL;
341 GtkWidget *_menu_view_goto_gps_item = NULL;
342 GtkWidget *_menu_view_goto_nextway_item = NULL;
343 GtkWidget *_menu_view_goto_nearpoi_item = NULL;
344
345 /* Menu items for the "GPS" submenu. */
346 GtkWidget *_menu_gps_enable_item = NULL;
347 GtkWidget *_menu_gps_show_info_item = NULL;
348 GtkWidget *_menu_gps_details_item = NULL;
349 GtkWidget *_menu_gps_reset_item = NULL;
350
351 #ifdef INCLUDE_APRS
352 /* Menu items for the "APRS" menu items. */
353 GtkWidget *_menu_aprs_settings_item = NULL;
354 GtkWidget *_menu_enable_aprs_inet_item = NULL;
355 GtkWidget *_menu_enable_aprs_tty_item = NULL;
356 GtkWidget *_menu_list_aprs_stations_item = NULL;
357 GtkWidget *_menu_list_aprs_messages_item = NULL;
358 #endif // INCLUDE_APRS
359
360 /* Menu items for the other menu items. */
361 GtkWidget *_menu_settings_item = NULL;
362 GtkWidget *_menu_help_item = NULL;
363 GtkWidget *_menu_about_item = NULL;
364 GtkWidget *_menu_close_item = NULL;
365
366 /*********************
367  * ABOVE: MENU ITEMS *
368  *********************/
369
370
371 /*****************************
372  * BELOW: CONTEXT MENU ITEMS *
373  *****************************/
374
375 gboolean _mouse_is_dragging = FALSE;
376 gboolean _mouse_is_down = FALSE;
377 gint _cmenu_position_x = 0;
378 gint _cmenu_position_y = 0;
379
380 /* Menu items for the "Location" context menu. */
381 GtkWidget *_cmenu_loc_show_latlon_item = NULL;
382 GtkWidget *_cmenu_loc_route_to_item = NULL;
383 GtkWidget *_cmenu_loc_distance_to_item = NULL;
384 GtkWidget *_cmenu_loc_download_poi_item = NULL;
385 GtkWidget *_cmenu_loc_browse_poi_item = NULL;
386 GtkWidget *_cmenu_loc_add_route_item = NULL;
387 GtkWidget *_cmenu_loc_add_way_item = NULL;
388 GtkWidget *_cmenu_loc_add_poi_item = NULL;
389 GtkWidget *_cmenu_loc_set_gps_item = NULL;
390 GtkWidget *_cmenu_loc_apply_correction_item = NULL;
391
392 /* Menu items for the "Waypoint" context menu. */
393 GtkWidget *_cmenu_way_show_latlon_item = NULL;
394 GtkWidget *_cmenu_way_show_desc_item = NULL;
395 GtkWidget *_cmenu_way_clip_latlon_item = NULL;
396 GtkWidget *_cmenu_way_clip_desc_item = NULL;
397 GtkWidget *_cmenu_way_route_to_item = NULL;
398 GtkWidget *_cmenu_way_distance_to_item = NULL;
399 GtkWidget *_cmenu_way_delete_item = NULL;
400 GtkWidget *_cmenu_way_add_poi_item = NULL;
401 GtkWidget *_cmenu_way_goto_nextway_item = NULL;
402
403 /* Menu items for the "POI" context menu. */
404 GtkWidget *_cmenu_poi_submenu = NULL;
405 GtkWidget *_cmenu_poi_edit_poi_item = NULL;
406 GtkWidget *_cmenu_poi_route_to_item = NULL;
407 GtkWidget *_cmenu_poi_distance_to_item = NULL;
408 GtkWidget *_cmenu_poi_add_route_item = NULL;
409 GtkWidget *_cmenu_poi_add_way_item = NULL;
410 GtkWidget *_cmenu_poi_goto_nearpoi_item = NULL;
411
412 /*****************************
413  * ABOVE: CONTEXT MENU ITEMS *
414  *****************************/
415