]> git.itanic.dy.fi Git - maemo-mapper/blob - src/defines.h
Added (default) support for SQLite3 in lieu of GDBM.
[maemo-mapper] / src / defines.h
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 #ifndef MAEMO_MAPPER_DEFINES
25 #define MAEMO_MAPPER_DEFINES
26
27 #include <libintl.h>
28
29 #define _(String) gettext(String)
30
31 #ifndef DEBUG
32 #define printf(...)
33 #endif
34
35 /* Set the below if to determine whether to get verbose output. */
36 #if 1
37 #define vprintf printf
38 #else
39 #define vprintf(...)
40 #endif
41
42 #define BOUND(x, a, b) { \
43     if((x) < (a)) \
44         (x) = (a); \
45     else if((x) > (b)) \
46         (x) = (b); \
47 }
48
49 #define PI   (3.14159265358979323846)
50
51 #define EARTH_RADIUS (3443.91847)
52
53 /* BT dbus service location */
54 #define BASE_PATH                "/org/bluez"
55 #define BASE_INTERFACE           "org.bluez"
56 //#define ADAPTER_PATH             BASE_PATH
57 #define ADAPTER_INTERFACE        BASE_INTERFACE ".Adapter"
58 #define MANAGER_PATH             BASE_PATH
59 #define MANAGER_INTERFACE        BASE_INTERFACE ".Manager"
60 #define ERROR_INTERFACE          BASE_INTERFACE ".Error"
61 #define SECURITY_INTERFACE       BASE_INTERFACE ".Security"
62 #define RFCOMM_INTERFACE         BASE_INTERFACE ".RFCOMM"
63 #define BLUEZ_DBUS               BASE_INTERFACE
64
65 #define LIST_ADAPTERS            "ListAdapters"
66 #define LIST_BONDINGS            "ListBondings"
67 //#define CREATE_BONDING           "CreateBonding"
68 #define GET_REMOTE_NAME          "GetRemoteName"
69 #define GET_REMOTE_SERVICE_CLASSES "GetRemoteServiceClasses"
70
71 #define BTCOND_PATH              "/com/nokia/btcond/request"
72 #define BTCOND_BASE              "com.nokia.btcond"
73 #define BTCOND_INTERFACE         BTCOND_BASE ".request"
74 #define BTCOND_REQUEST           BTCOND_INTERFACE
75 #define BTCOND_CONNECT           "rfcomm_connect"
76 #define BTCOND_DISCONNECT        "rfcomm_disconnect"
77 #define BTCOND_DBUS              BTCOND_BASE
78
79
80 /** MAX_ZOOM defines the largest map zoom level we will download.
81  * (MAX_ZOOM - 1) is the largest map zoom level that the user can zoom to.
82  */
83 #define MIN_ZOOM (0)
84 #define MAX_ZOOM (20)
85
86 #define TILE_SIZE_PIXELS (256)
87 #define TILE_HALFDIAG_PIXELS (181)
88 #define TILE_SIZE_P2 (8)
89
90 #define ARRAY_CHUNK_SIZE (1024)
91
92 #define BUFFER_SIZE (2048)
93 #define APRS_BUFFER_SIZE (4096)
94 #define APRS_MAX_COMMENT  80
95 #define APRS_CONVERSE_MODE "k"
96
97 #define GPSD_PORT_DEFAULT (2947)
98
99 #define NUM_DOWNLOAD_THREADS (4)
100 #define WORLD_SIZE_UNITS (2 << (MAX_ZOOM + TILE_SIZE_P2))
101
102 #define HOURGLASS_SEPARATION (7)
103
104 #define deg2rad(deg) ((deg) * (PI / 180.0))
105 #define rad2deg(rad) ((rad) * (180.0 / PI))
106
107 #define tile2pixel(TILE) ((TILE) << TILE_SIZE_P2)
108 #define pixel2tile(PIXEL) ((PIXEL) >> TILE_SIZE_P2)
109 #define tile2unit(TILE) ((TILE) << (TILE_SIZE_P2 + _zoom))
110 #define unit2tile(unit) ((unit) >> (TILE_SIZE_P2 + _zoom))
111 #define tile2zunit(TILE, ZOOM) ((TILE) << (TILE_SIZE_P2 + (ZOOM)))
112 #define unit2ztile(unit, ZOOM) ((unit) >> (TILE_SIZE_P2 + (ZOOM)))
113
114 #define pixel2unit(PIXEL) ((PIXEL) << _zoom)
115 #define unit2pixel(PIXEL) ((PIXEL) >> _zoom)
116 #define pixel2zunit(PIXEL, ZOOM) ((PIXEL) << (ZOOM))
117 #define unit2zpixel(PIXEL, ZOOM) ((PIXEL) >> (ZOOM))
118
119 #define unit2buf_full(UNITX, UNITY, BUFX, BUFY, CENTER, MATRIX) { \
120     gfloat fdevx, fdevy; \
121     gdk_pixbuf_rotate_vector(&fdevx, &fdevy, (MATRIX), \
122             (gint)((UNITX) - (CENTER).unitx), \
123             (gint)((UNITY) - (CENTER).unity)); \
124     (BUFX) = unit2pixel((gint)(fdevx)) + _view_halfwidth_pixels; \
125     (BUFY) = unit2pixel((gint)(fdevy)) + _view_halfheight_pixels; \
126 }
127
128 #define unit2buf(UNITX, UNITY, BUFX, BUFY) \
129     (unit2buf_full(UNITX, UNITY, BUFX, BUFY, _center, _map_rotate_matrix))
130
131 #define pixel2buf_full(PIXELX, PIXELY, BUFX, BUFY, CENTER, ZOOM, MATRIX) { \
132     gfloat fdevx, fdevy; \
133     gdk_pixbuf_rotate_vector(&fdevx, &fdevy, MATRIX, \
134             (gint)((PIXELX) - unit2zpixel((CENTER).unitx, (ZOOM))), \
135             (gint)((PIXELY) - unit2zpixel((CENTER).unity, (ZOOM)))); \
136     (BUFX) = fdevx + _view_halfwidth_pixels; \
137     (BUFY) = fdevy + _view_halfheight_pixels; \
138 }
139
140 #define pixel2buf(PIXELX, PIXELY, BUFX, BUFY) \
141     (pixel2buf_full(PIXELX, PIXELY, BUFX, BUFY, _center, _zoom, \
142                     _map_rotate_matrix))
143
144
145 #define unit2screen_full(UNITX, UNITY, SCREENX, SCREENY, CENTER, MATRIX) { \
146     unit2buf_full(UNITX, UNITY, SCREENX, SCREENY, CENTER, MATRIX); \
147     (SCREENX) = (SCREENX) + _map_offset_devx; \
148     (SCREENY) = (SCREENY) + _map_offset_devy; \
149 }
150
151 #define unit2screen(UNITX, UNITY, SCREENX, SCREENY) \
152     (unit2screen_full(UNITX, UNITY, SCREENX, SCREENY, _center, \
153                       _map_rotate_matrix))
154
155 #define pixel2screen_full(PIXELX, PIXELY, SCREENX, SCREENY, CENTER, MATRIX) { \
156     pixel2buf_full(PIXELX, PIXELY, SCREENX, SCREENY, CENTER, ZOOM, MATRIX); \
157     (SCREENX) = (SCREENX) + _map_offset_devx; \
158     (SCREENY) = (SCREENY) + _map_offset_devy; \
159 }
160
161 #define pixel2screen(PIXELX, PIXELY, SCREENX, SCREENY) \
162     (pixel2screen_full(PIXELX, PIXELY, SCREENX, SCREENY, _center, \
163                        _map_rotate_matrix))
164
165 #define buf2unit_full(BUFX, BUFY, UNITX, UNITY, CENTER, MATRIX) { \
166     gfloat funitx, funity; \
167     gdk_pixbuf_rotate_vector(&funitx, &funity, MATRIX, \
168             pixel2unit((gint)((BUFX) - _view_halfwidth_pixels)), \
169             pixel2unit((gint)((BUFY) - _view_halfheight_pixels))); \
170     (UNITX) = (CENTER).unitx + (gint)funitx; \
171     (UNITY) = (CENTER).unity + (gint)funity; \
172 }
173
174 #define buf2unit(BUFX, BUFY, UNITX, UNITY) \
175     (buf2unit_full(BUFX, BUFY, UNITX, UNITY, _center, _map_reverse_matrix))
176
177 #define buf2pixel_full(BUFX, BUFY, PIXELX, PIXELY, CENTER, MATRIX) { \
178     gfloat fpixelx, fpixely; \
179     gdk_pixbuf_rotate_vector(&fpixelx, &fpixely, MATRIX, \
180             (gint)(BUFX) - _view_halfwidth_pixels, \
181             (gint)(BUFY) - _view_halfheight_pixels); \
182     (PIXELX) = unit2pixel((CENTER).unitx) + (gint)fpixelx; \
183     (PIXELY) = unit2pixel((CENTER).unity) + (gint)fpixely; \
184 }
185
186 #define buf2pixel(BUFX, BUFY, PIXELX, PIXELY) \
187     (buf2pixel_full(BUFX, BUFY, PIXELX, PIXELY, _center, _map_reverse_matrix))
188
189 #define screen2unit_full(SCREENX, SCREENY, UNITX, UNITY, CENTER, MATRIX) ( \
190     buf2unit_full((SCREENX) - _map_offset_devx, (SCREENY) - _map_offset_devy, \
191         UNITX, UNITY, CENTER, MATRIX))
192
193 #define screen2unit(SCREENX, SCREENY, UNITX, UNITY) \
194     (screen2unit_full(SCREENX, SCREENY, UNITX, UNITY, _center, \
195                       _map_reverse_matrix))
196
197 #define screen2pixel_full(SCREENX, SCREENY, PIXELX, PIXELY, CENTER, MATRIX) ( \
198     buf2pixel_full((SCREENX) - _map_offset_devx, (SCREENY) - _map_offset_devy,\
199         PIXELX, PIXELY, CENTER, MATRIX))
200
201 #define screen2pixel(SCREENX, SCREENY, PIXELX, PIXELY) ( \
202     screen2pixel_full(SCREENX, SCREENY, PIXELX, PIXELY, \
203         _center,_map_reverse_matrix))
204
205 /* Pans are done 64 pixels at a time. */
206 #define PAN_PIXELS (64)
207 #define ROTATE_DEGREES (30)
208
209 #define INITIAL_DOWNLOAD_RETRIES (3)
210
211 #define CONFIG_DIR_NAME "~/.maemo-mapper/"
212 #define CONFIG_PATH_DB_FILE "paths.db"
213
214 #define REPO_DEFAULT_NAME "OpenStreet"
215 #define REPO_DEFAULT_CACHE_BASE "~/MyDocs/.documents/Maps/"
216 #define REPO_DEFAULT_CACHE_DIR REPO_DEFAULT_CACHE_BASE"OpenStreet.db"
217 #define REPO_DEFAULT_MAP_URI "http://tile.openstreetmap.org/%0d/%d/%d.png"
218 #define REPO_DEFAULT_DL_ZOOM_STEPS (2)
219 #define REPO_DEFAULT_VIEW_ZOOM_STEPS (1)
220 #define REPO_DEFAULT_MIN_ZOOM (4)
221 #define REPO_DEFAULT_MAX_ZOOM (20)
222
223 #define XML_DATE_FORMAT "%FT%T"
224
225 #define HELP_ID_PREFIX "help_maemomapper_"
226 #define HELP_ID_INTRO HELP_ID_PREFIX"intro"
227 #define HELP_ID_GETSTARTED HELP_ID_PREFIX"getstarted"
228 #define HELP_ID_ABOUT HELP_ID_PREFIX"about"
229 #define HELP_ID_SETTINGS HELP_ID_PREFIX"settings"
230 #define HELP_ID_NEWREPO HELP_ID_PREFIX"newrepo"
231 #define HELP_ID_REPOMAN HELP_ID_PREFIX"repoman"
232 #define HELP_ID_MAPMAN HELP_ID_PREFIX"mapman"
233 #define HELP_ID_DOWNROUTE HELP_ID_PREFIX"downroute"
234 #define HELP_ID_DOWNPOI HELP_ID_PREFIX"downpoi"
235 #define HELP_ID_BROWSEPOI HELP_ID_PREFIX"browsepoi"
236 #define HELP_ID_POILIST HELP_ID_PREFIX"poilist"
237 #define HELP_ID_POICAT HELP_ID_PREFIX"poicat"
238
239 #define MERCATOR_SPAN (-6.28318377773622)
240 #define MERCATOR_TOP (3.14159188886811)
241 #define latlon2unit(lat, lon, unitx, unity) { \
242     gdouble tmp; \
243     unitx = (lon + 180.0) * (WORLD_SIZE_UNITS / 360.0) + 0.5; \
244     tmp = sin(deg2rad(lat)); \
245     unity = 0.5 + (WORLD_SIZE_UNITS / MERCATOR_SPAN) \
246         * (log((1.0 + tmp) / (1.0 - tmp)) * 0.5 - MERCATOR_TOP); \
247 }
248
249 #define unit2latlon(unitx, unity, lat, lon) { \
250     (lon) = ((unitx) * (360.0 / WORLD_SIZE_UNITS)) - 180.0; \
251     (lat) = (360.0 * (atan(exp(((unity) * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) \
252                      + MERCATOR_TOP)))) * (1.0 / PI) - 90.0; \
253 }
254
255 #define MACRO_PATH_INIT(path) { \
256     (path).head = (path).tail = g_new(Point, ARRAY_CHUNK_SIZE); \
257     *((path).tail) = _point_null; \
258     (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
259     (path).whead = g_new(WayPoint, ARRAY_CHUNK_SIZE); \
260     (path).wtail = (path).whead - 1; \
261     (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
262 }
263
264 #define MACRO_PATH_FREE(path) if((path).head) { \
265     WayPoint *curr; \
266     g_free((path).head); \
267     (path).head = (path).tail = (path).cap = NULL; \
268     for(curr = (path).whead - 1; curr++ != (path).wtail; ) \
269         g_free(curr->desc); \
270     g_free((path).whead); \
271     (path).whead = (path).wtail = (path).wcap = NULL; \
272 }
273
274 #define MACRO_PATH_INCREMENT_TAIL(route) { \
275     if(++(route).tail == (route).cap) \
276         path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
277 }
278
279 #define MACRO_PATH_INCREMENT_WTAIL(route) { \
280     if(++(route).wtail == (route).wcap) \
281         path_wresize(&(route), \
282                 (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \
283 }
284
285 #define DISTANCE_SQUARED(a, b) \
286    ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\
287   + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
288
289 #define MACRO_QUEUE_DRAW_AREA() \
290     gtk_widget_queue_draw_area( \
291             _map_widget, \
292             0, 0, \
293             _view_width_pixels, \
294             _view_height_pixels)
295
296 /* Render all on-map metadata an annotations, including POI and paths. */
297 #ifdef INCLUDE_APRS
298 #define MACRO_MAP_RENDER_DATA() { \
299     if(_show_poi) \
300         map_render_poi(); \
301     if(_show_paths > 0) \
302         map_render_paths(); \
303     if(_aprs_enable) \
304         map_render_aprs(); \
305 }
306 #else
307 #define MACRO_MAP_RENDER_DATA() { \
308     if(_show_poi) \
309         map_render_poi(); \
310     if(_show_paths > 0) \
311         map_render_paths(); \
312 }
313 #endif //INCLUDE_APRS
314
315 #define UNBLANK_SCREEN(MOVING, APPROACHING_WAYPOINT) { \
316     /* Check if we need to unblank the screen. */ \
317     switch(_unblank_option) \
318     { \
319         case UNBLANK_NEVER: \
320             break; \
321         case UNBLANK_WAYPOINT: \
322             if(APPROACHING_WAYPOINT) \
323             { \
324                 printf("Unblanking screen...\n"); \
325                 osso_display_state_on(_osso); \
326                 osso_display_blanking_pause(_osso); \
327             } \
328             break; \
329         default: \
330         case UNBLANK_FULLSCREEN: \
331             if(!_fullscreen) \
332                 break; \
333         case UNBLANK_WHEN_MOVING: \
334             if(!(MOVING)) \
335                 break; \
336         case UNBLANK_WITH_GPS: \
337             printf("Unblanking screen...\n"); \
338             osso_display_state_on(_osso); \
339             osso_display_blanking_pause(_osso); \
340     } \
341 }
342
343 #define LL_FMT_LEN 20
344 #define lat_format(A, B) deg_format((A), (B), 'S', 'N')
345 #define lon_format(A, B) deg_format((A), (B), 'W', 'E')
346
347 #define TRACKS_MASK 0x00000001
348 #define ROUTES_MASK 0x00000002
349
350 #define MACRO_BANNER_SHOW_INFO(A, S) { \
351     gchar *my_macro_buffer = g_markup_printf_escaped( \
352             "<span size='%s'>%s</span>", \
353             INFO_FONT_ENUM_TEXT[_info_font_size], (S)); \
354     hildon_banner_show_information_with_markup(A, NULL, my_macro_buffer); \
355     g_free(my_macro_buffer); \
356 }
357
358 #define MAPDB_EXISTS(map_repo) ( ((map_repo)->is_sqlite) \
359     ? ((map_repo)->sqlite_db != NULL) \
360     : ((map_repo)->gdbm_db != NULL) )
361 #define _voice_synth_path "/usr/bin/flite"
362
363 #endif /* ifndef MAEMO_MAPPER_DEFINES */