18 |
*/ |
*/ |
19 |
|
|
20 |
#include "gpxview.h" |
#include "gpxview.h" |
21 |
|
#include <math.h> // for isnan |
22 |
|
|
23 |
#ifdef ENABLE_OSM_GPS_MAP |
#ifdef ENABLE_OSM_GPS_MAP |
24 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
25 |
#endif |
#endif |
26 |
|
|
27 |
typedef struct { |
typedef struct { |
28 |
|
appdata_t *appdata; |
29 |
GtkWidget *widget; |
GtkWidget *widget; |
30 |
GtkWidget *zoomin, *zoomout, *gps; |
GtkWidget *zoomin, *zoomout, *gps; |
31 |
gint handler_id; |
gint handler_id; |
32 |
} map_context_t; |
} map_context_t; |
33 |
|
|
34 |
static const char *get_proxy_uri(void) { |
#define PROXY_KEY "/system/http_proxy/" |
35 |
static char proxy_buffer[64]; |
|
36 |
|
static const char *get_proxy_uri(appdata_t *appdata) { |
37 |
|
static char proxy_buffer[64] = ""; |
38 |
|
|
39 |
/* use environment settings if preset */ |
/* use environment settings if preset */ |
40 |
const char *proxy = g_getenv("http_proxy"); |
const char *proxy = g_getenv("http_proxy"); |
43 |
return proxy; |
return proxy; |
44 |
} |
} |
45 |
|
|
46 |
#if 0 |
/* ------------- get proxy settings -------------------- */ |
47 |
/* otherwise try settings */ |
if(gconf_client_get_bool(appdata->gconf_client, |
48 |
if(!settings || !settings->proxy || |
PROXY_KEY "use_http_proxy", NULL)) { |
49 |
!settings->proxy->host) return NULL; |
|
50 |
|
/* we can savely ignore things like "ignore_hosts" since we */ |
51 |
snprintf(proxy_buffer, sizeof(proxy_buffer), "%s%s:%u", |
/* are pretty sure not inside the net of one of our map renderers */ |
52 |
strncmp(settings->proxy->host, "http://", 7)?"http://":"", |
/* (unless the user works at google :-) */ |
53 |
settings->proxy->host, settings->proxy->port); |
|
54 |
|
/* get basic settings */ |
55 |
|
char *host = |
56 |
|
gconf_client_get_string(appdata->gconf_client, PROXY_KEY "host", NULL); |
57 |
|
if(host) { |
58 |
|
int port = |
59 |
|
gconf_client_get_int(appdata->gconf_client, PROXY_KEY "port", NULL); |
60 |
|
|
61 |
proxy_buffer[sizeof(proxy_buffer)-1] = 0; |
snprintf(proxy_buffer, sizeof(proxy_buffer), |
62 |
printf("gconf_proxy: %s\n", proxy_buffer); |
"http://%s:%u", host, port); |
63 |
#endif |
|
64 |
|
g_free(host); |
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
return proxy_buffer; |
return proxy_buffer; |
69 |
} |
} |
91 |
return FALSE; |
return FALSE; |
92 |
} |
} |
93 |
|
|
94 |
|
#define DEG2RAD(a) ((a) * M_PI / 180.0) |
95 |
|
|
96 |
static gboolean |
static gboolean |
97 |
cb_map_gps(GtkButton *button, map_context_t *context) { |
cb_map_gps(GtkButton *button, map_context_t *context) { |
98 |
|
pos_t *refpos = get_pos(context->appdata); |
99 |
|
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
100 |
|
printf("pos is %f %f\n", refpos->lat, refpos->lon); |
101 |
|
|
102 |
// osm_gps_map_set_center(OSM_GPS_MAP(context->widget), |
osm_gps_map_set_center(OSM_GPS_MAP(context->widget), |
103 |
// DEG2RAD(pos.lat), DEG2RAD(pos.lon)); |
DEG2RAD(refpos->lat), DEG2RAD(refpos->lon)); |
104 |
|
} |
105 |
|
|
106 |
return FALSE; |
return FALSE; |
107 |
} |
} |
122 |
static gboolean map_gps_update(gpointer data) { |
static gboolean map_gps_update(gpointer data) { |
123 |
map_context_t *context = (map_context_t*)data; |
map_context_t *context = (map_context_t*)data; |
124 |
|
|
125 |
// gtk_widget_set_sensitive(context->map.gps, gps_fix); |
pos_t *refpos = get_pos(context->appdata); |
126 |
|
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
127 |
|
|
128 |
|
/* get reference position and go there */ |
129 |
|
gtk_widget_set_sensitive(context->gps, ok); |
130 |
|
|
131 |
return TRUE; |
return TRUE; |
132 |
} |
} |
134 |
|
|
135 |
void map(appdata_t *appdata) { |
void map(appdata_t *appdata) { |
136 |
map_context_t context; |
map_context_t context; |
137 |
|
context.appdata = appdata; |
138 |
|
|
139 |
GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Map"), |
GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Map"), |
140 |
GTK_WINDOW(appdata->window), |
GTK_WINDOW(appdata->window), |
154 |
|
|
155 |
context.widget = g_object_new(OSM_TYPE_GPS_MAP, |
context.widget = g_object_new(OSM_TYPE_GPS_MAP, |
156 |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
157 |
"proxy-uri", get_proxy_uri(), |
"proxy-uri", get_proxy_uri(appdata), |
158 |
"tile-cache", path, |
"tile-cache", path, |
159 |
NULL); |
NULL); |
160 |
|
|