]> err.no Git - mapper/blob - src/utils.h
Misc. Renames and code moving.
[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 #define _GNU_SOURCE
25
26 #include <config.h>
27 #include <unistd.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <stddef.h>
32 #include <locale.h>
33 #include <math.h>
34 #include <errno.h>
35 #include <sys/wait.h>
36 #include <glib/gstdio.h>
37 #include <glib/gi18n.h>
38 #include <gtk/gtk.h>
39 #include <curl/multi.h>
40 #include <gconf/gconf-client.h>
41
42 #include "path.h"
43 #include "mapper-types.h"
44 #include "gpsdata.h"
45
46 /****************************************************************************
47  * BELOW: DEFINES ***********************************************************
48  ****************************************************************************/
49
50 /* #define DEBUG */
51
52 #ifndef DEBUG
53 #define printf(...)
54 #endif
55
56 /* Set the below if to determine whether to get verbose output. */
57 #if 1
58 #define vprintf printf
59 #else
60 #define vprintf(...)
61 #endif
62
63 #define BOUND(x, a, b) { \
64     if((x) < (a)) \
65         (x) = (a); \
66     else if((x) > (b)) \
67         (x) = (b); \
68 }
69
70 #define SQR(s) ((s)*(s))
71
72 #define ARRAY_CHUNK_SIZE (1024)
73 #define BUFFER_SIZE (2048)
74
75 #define MACRO_PARSE_INT(tofill, str) { \
76     gchar *error_check; \
77     (tofill) = strtol((str), &error_check, 10); \
78     if(error_check == (str)) \
79     { \
80         g_printerr("Line %d: Failed to parse string as int: %s\n", __LINE__, str); \
81         MACRO_BANNER_SHOW_INFO(_window, _("Invalid NMEA input from receiver!")); \
82         return; \
83     } \
84 }
85 #define MACRO_PARSE_FLOAT(tofill, str) { \
86     gchar *error_check; \
87     (tofill) = g_ascii_strtod((str), &error_check); \
88     if(error_check == (str)) \
89     { \
90         g_printerr("Failed to parse string as float: %s\n", str); \
91         MACRO_BANNER_SHOW_INFO(_window, _("Invalid NMEA input from receiver!")); \
92         return; \
93     } \
94 }
95
96 #define DISTANCE_SQUARED(a, b) \
97    ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\
98   + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
99
100
101 #ifdef WITH_OSSO
102 #define KEEP_DISPLAY_ON() { \
103     /* Note that the flag means keep on ONLY when fullscreen. */ \
104     if(_always_keep_on || _fullscreen) \
105     { \
106         osso_display_state_on(_osso); \
107         osso_display_blanking_pause(_osso); \
108     } \
109 }
110 #else
111 #define KEEP_DISPLAY_ON()
112 #endif
113
114 #define TRACKS_MASK 0x00000001
115 #define ROUTES_MASK 0x00000002
116
117 #define g_timeout_add(I, F, D) g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, \
118           (I), (F), (D), NULL)
119
120 #define MACRO_CURL_EASY_INIT(C) { \
121     C = curl_easy_init(); \
122     curl_easy_setopt(C, CURLOPT_NOPROGRESS, 1); \
123     curl_easy_setopt(C, CURLOPT_FOLLOWLOCATION, 1); \
124     curl_easy_setopt(C, CURLOPT_MAXREDIRS, 20); \
125     curl_easy_setopt(C, CURLOPT_FAILONERROR, 1); \
126     curl_easy_setopt(C, CURLOPT_USERAGENT, \
127             "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060701 Firefox/1.5.0.4"); \
128     curl_easy_setopt(C, CURLOPT_TIMEOUT, 30); \
129     curl_easy_setopt(C, CURLOPT_CONNECTTIMEOUT, 10); \
130 }
131
132 #define MACRO_CURL_PROXY(C) { \
133 if (_http_proxy_host) { \
134         curl_easy_setopt(C, CURLOPT_PROXY, _http_proxy_host);\
135         if (_http_proxy_port) \
136                 curl_easy_setopt(C, CURLOPT_PROXYPORT, _http_proxy_port); \
137 } \
138 }
139
140 #ifdef WITH_HILDON
141 #define MACRO_BANNER_SHOW_INFO(A, S) { \
142     gchar *my_macro_buffer = g_strdup_printf("<span size='%s'>%s</span>", \
143             INFO_FONT_TEXT[_info_font_size], (S)); \
144     hildon_banner_show_information_with_markup(A, NULL, my_macro_buffer); \
145     g_free(my_macro_buffer); \
146 }
147 #else
148 #define MACRO_BANNER_SHOW_INFO(A, S) { hildon_banner_show_information(A, NULL, S); }
149 #endif
150
151 void sound_noise(void);
152
153 #endif