]> err.no Git - mapper/blob - src/utils.h
Allow a bit faster movement for the random gps simulator.
[mapper] / src / utils.h
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2006-2007 John Costigan.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #ifndef _MAPPER_UTILS_H
22 #define _MAPPER_UTILS_H
23
24 #include "config.h"
25 #include <unistd.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <strings.h>
29 #include <stddef.h>
30 #include <locale.h>
31 #include <math.h>
32 #include <errno.h>
33 #include <sys/wait.h>
34 #include <glib/gstdio.h>
35 #include <glib/gi18n.h>
36 #include <gtk/gtk.h>
37 #include <curl/multi.h>
38 #include <gconf/gconf-client.h>
39
40 #include "path.h"
41 #include "mapper-types.h"
42 #include "gpsdata.h"
43
44 /****************************************************************************
45  * BELOW: DEFINES ***********************************************************
46  ****************************************************************************/
47
48 /* #define DEBUG */
49
50 #ifndef DEBUG
51 #define printf(...)
52 #endif
53
54 /* Set the below if to determine whether to get verbose output. */
55 #if 1
56 #define vprintf printf
57 #else
58 #define vprintf(...)
59 #endif
60
61 #define BOUND(x, a, b) { \
62     if((x) < (a)) \
63         (x) = (a); \
64     else if((x) > (b)) \
65         (x) = (b); \
66 }
67
68 #define SQR(s) ((s)*(s))
69
70 #define ARRAY_CHUNK_SIZE (1024)
71 #define BUFFER_SIZE (2048)
72
73 #define MACRO_PARSE_INT(tofill, str) { \
74     gchar *error_check; \
75     (tofill) = strtol((str), &error_check, 10); \
76     if(error_check == (str)) \
77     { \
78         g_printerr("Line %d: Failed to parse string as int: %s\n", __LINE__, str); \
79         return; \
80     } \
81 }
82 #define MACRO_PARSE_FLOAT(tofill, str) { \
83     gchar *error_check; \
84     (tofill) = g_ascii_strtod((str), &error_check); \
85     if(error_check == (str)) \
86     { \
87         g_printerr("Failed to parse string as float: %s\n", str); \
88         return; \
89     } \
90 }
91
92 #ifdef WITH_OSSO
93 #define KEEP_DISPLAY_ON() { \
94     /* Note that the flag means keep on ONLY when fullscreen. */ \
95     if(_always_keep_on || _fullscreen) \
96     { \
97         osso_display_state_on(_osso); \
98         osso_display_blanking_pause(_osso); \
99     } \
100 }
101 #else
102 #define KEEP_DISPLAY_ON()
103 #endif
104
105 #define TRACKS_MASK 0x00000001
106 #define ROUTES_MASK 0x00000002
107
108 #define g_timeout_add(I, F, D) g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, \
109           (I), (F), (D), NULL)
110
111 #define MACRO_CURL_EASY_INIT(C) { \
112     C = curl_easy_init(); \
113     curl_easy_setopt(C, CURLOPT_NOPROGRESS, 1); \
114     curl_easy_setopt(C, CURLOPT_FOLLOWLOCATION, 1); \
115     curl_easy_setopt(C, CURLOPT_MAXREDIRS, 20); \
116     curl_easy_setopt(C, CURLOPT_FAILONERROR, 1); \
117     curl_easy_setopt(C, CURLOPT_USERAGENT, \
118             "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060701 Firefox/1.5.0.4"); \
119     curl_easy_setopt(C, CURLOPT_TIMEOUT, 30); \
120     curl_easy_setopt(C, CURLOPT_CONNECTTIMEOUT, 10); \
121 }
122
123 #define MACRO_CURL_PROXY(C) { \
124 if (_http_proxy_host) { \
125         curl_easy_setopt(C, CURLOPT_PROXY, _http_proxy_host);\
126         if (_http_proxy_port) \
127                 curl_easy_setopt(C, CURLOPT_PROXYPORT, _http_proxy_port); \
128 } \
129 }
130
131 #ifdef WITH_HILDON
132 #define MACRO_BANNER_SHOW_INFO(A, S) { \
133     gchar *my_macro_buffer = g_markup_printf_escaped("<span size='%s'>%s</span>", \
134             INFO_FONT_TEXT[_info_font_size], (S)); \
135     hildon_banner_show_information_with_markup(A, NULL, my_macro_buffer); \
136     g_free(my_macro_buffer); \
137 }
138 #else
139 #define MACRO_BANNER_SHOW_INFO(A, S) { hildon_banner_show_information(A, NULL, S); }
140 #endif
141
142 void sound_noise(void);
143
144 #endif