35 |
#include <glib.h> |
#include <glib.h> |
36 |
#include <glib/gprintf.h> |
#include <glib/gprintf.h> |
37 |
#include <libsoup/soup.h> |
#include <libsoup/soup.h> |
38 |
|
#include <glib/ghash.h> |
39 |
|
|
40 |
#include "converter.h" |
#include "converter.h" |
41 |
#include "osm-gps-map-types.h" |
#include "osm-gps-map-types.h" |
172 |
static void osm_gps_map_print_images (OsmGpsMap *map); |
static void osm_gps_map_print_images (OsmGpsMap *map); |
173 |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
174 |
static void osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y); |
static void osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y); |
|
static void osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data); |
|
175 |
static void osm_gps_map_download_tile (OsmGpsMap *map, int zoom, int x, int y, gboolean redraw); |
static void osm_gps_map_download_tile (OsmGpsMap *map, int zoom, int x, int y, gboolean redraw); |
176 |
static void osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y); |
static void osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y); |
177 |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
622 |
{ |
{ |
623 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
624 |
|
|
625 |
g_debug("Queing redraw @ %d,%d (w:%d h:%d)", offset_x,offset_y, TILESIZE,TILESIZE); |
g_debug("Queing redraw @ %d,%d (w:%d h:%d)", offset_x,offset_y, |
626 |
|
TILESIZE,TILESIZE); |
627 |
|
|
628 |
/* draw pixbuf onto pixmap */ |
/* draw pixbuf onto pixmap */ |
629 |
gdk_draw_pixbuf (priv->pixmap, |
gdk_draw_pixbuf (priv->pixmap, |
635 |
GDK_RGB_DITHER_NONE, 0, 0); |
GDK_RGB_DITHER_NONE, 0, 0); |
636 |
} |
} |
637 |
|
|
638 |
|
/* soup 2.2 and soup 2.4 use different ways to store the body data */ |
639 |
|
#ifdef SOUP22 |
640 |
|
#define soup_message_headers_append(a,b,c) soup_message_add_header(a,b,c) |
641 |
|
#define MSG_RESPONSE_BODY(a) ((a)->response.body) |
642 |
|
#define MSG_RESPONSE_LEN(a) ((a)->response.length) |
643 |
|
#else |
644 |
|
#define MSG_RESPONSE_BODY(a) ((a)->response_body->data) |
645 |
|
#define MSG_RESPONSE_LEN(a) ((a)->response_body->length) |
646 |
|
#endif |
647 |
|
|
648 |
|
#ifdef SOUP22 |
649 |
|
static void |
650 |
|
osm_gps_map_tile_download_complete (SoupMessage *msg, gpointer user_data) |
651 |
|
#else |
652 |
static void |
static void |
653 |
osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data) |
osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data) |
654 |
|
#endif |
655 |
{ |
{ |
656 |
#ifndef NO_DISK_CACHE |
#ifndef NO_DISK_CACHE |
657 |
int fd; |
int fd; |
668 |
fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
669 |
if (fd != -1) |
if (fd != -1) |
670 |
{ |
{ |
671 |
write (fd, msg->response_body->data, msg->response_body->length); |
write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg)); |
672 |
g_debug("Wrote %lld bytes to %s", msg->response_body->length, dl->filename); |
|
673 |
|
g_debug("Wrote %lld bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
674 |
close (fd); |
close (fd); |
675 |
#endif |
#endif |
676 |
if (dl->redraw) |
if (dl->redraw) |
679 |
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (dl->filename, NULL); |
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (dl->filename, NULL); |
680 |
#else |
#else |
681 |
GdkPixbufLoader *loader = gdk_pixbuf_loader_new_with_type("png", NULL); |
GdkPixbufLoader *loader = gdk_pixbuf_loader_new_with_type("png", NULL); |
682 |
if(!gdk_pixbuf_loader_write(loader, (unsigned char*)msg->response_body->data, |
if(!gdk_pixbuf_loader_write(loader, (unsigned char*)MSG_RESPONSE_BODY(msg), |
683 |
msg->response_body->length, NULL)) |
MSG_RESPONSE_LEN(msg), NULL)) |
684 |
g_warning("Error: Decoding of image failed"); |
g_warning("Error: Decoding of image failed"); |
685 |
|
|
686 |
gdk_pixbuf_loader_close(loader, NULL); |
gdk_pixbuf_loader_close(loader, NULL); |
737 |
} |
} |
738 |
else |
else |
739 |
{ |
{ |
740 |
|
#ifdef SOUP22 |
741 |
|
soup_session_requeue_message(dl->session, msg); |
742 |
|
#else |
743 |
soup_session_requeue_message(session, msg); |
soup_session_requeue_message(session, msg); |
744 |
|
#endif |
745 |
return; |
return; |
746 |
} |
} |
747 |
} |
} |
759 |
//calculate the uri to download |
//calculate the uri to download |
760 |
dl->uri = replace_map_uri(map, priv->repo_uri, zoom, x, y); |
dl->uri = replace_map_uri(map, priv->repo_uri, zoom, x, y); |
761 |
|
|
762 |
|
#ifdef SOUP22 |
763 |
|
dl->session = priv->soup_session; |
764 |
|
#endif |
765 |
|
|
766 |
//check the tile has not already been queued for download, |
//check the tile has not already been queued for download, |
767 |
//or has been attempted, and its missing |
//or has been attempted, and its missing |
768 |
if (g_hash_table_lookup_extended(priv->tile_queue, dl->uri, NULL, NULL) || |
if (g_hash_table_lookup_extended(priv->tile_queue, dl->uri, NULL, NULL) || |
791 |
if (cookie) { |
if (cookie) { |
792 |
g_debug("Adding Google Cookie"); |
g_debug("Adding Google Cookie"); |
793 |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
794 |
|
|
795 |
} |
} |
796 |
} |
} |
797 |
} |
} |
1121 |
static void |
static void |
1122 |
osm_gps_map_purge_cache (OsmGpsMap *map) |
osm_gps_map_purge_cache (OsmGpsMap *map) |
1123 |
{ |
{ |
1124 |
|
#if 0 //XXX |
1125 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1126 |
GHashTableIter iter; |
GHashTableIter iter; |
1127 |
OsmCachedTile *tile; |
OsmCachedTile *tile; |
1137 |
if (tile->redraw_cycle != priv->redraw_cycle) |
if (tile->redraw_cycle != priv->redraw_cycle) |
1138 |
g_hash_table_iter_remove (&iter); |
g_hash_table_iter_remove (&iter); |
1139 |
} |
} |
1140 |
|
#endif |
1141 |
} |
} |
1142 |
|
|
1143 |
static gboolean |
static gboolean |
1213 |
priv->uri_format = 0; |
priv->uri_format = 0; |
1214 |
priv->the_google = FALSE; |
priv->the_google = FALSE; |
1215 |
|
|
1216 |
|
#ifndef SOUP22 |
1217 |
//Change naumber of concurrent connections option? |
//Change naumber of concurrent connections option? |
1218 |
priv->soup_session = soup_session_async_new_with_options( |
priv->soup_session = soup_session_async_new_with_options( |
1219 |
SOUP_SESSION_USER_AGENT, |
SOUP_SESSION_USER_AGENT, |
1220 |
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11", |
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11", |
1221 |
NULL); |
NULL); |
1222 |
|
#endif |
1223 |
|
|
1224 |
//Hash table which maps tile d/l URIs to SoupMessage requests |
//Hash table which maps tile d/l URIs to SoupMessage requests |
1225 |
priv->tile_queue = g_hash_table_new (g_str_hash, g_str_equal); |
priv->tile_queue = g_hash_table_new (g_str_hash, g_str_equal); |
1253 |
priv = OSM_GPS_MAP_PRIVATE(object); |
priv = OSM_GPS_MAP_PRIVATE(object); |
1254 |
|
|
1255 |
if (!priv->cache_dir_is_full_path) { |
if (!priv->cache_dir_is_full_path) { |
1256 |
|
#ifdef G_CHECKSUM_MD5 |
1257 |
char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1); |
char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1); |
1258 |
|
#else |
1259 |
|
char *md5 = g_strdup("dummy"); // XXX |
1260 |
|
#endif |
1261 |
|
|
1262 |
if (priv->cache_dir) { |
if (priv->cache_dir) { |
1263 |
char *old = priv->cache_dir; |
char *old = priv->cache_dir; |
1350 |
break; |
break; |
1351 |
case PROP_PROXY_URI: |
case PROP_PROXY_URI: |
1352 |
if ( g_value_get_string(value) ) { |
if ( g_value_get_string(value) ) { |
1353 |
|
#ifndef SOUP22 |
1354 |
GValue val = {0}; |
GValue val = {0}; |
1355 |
|
|
1356 |
priv->proxy_uri = g_value_dup_string (value); |
priv->proxy_uri = g_value_dup_string (value); |
1357 |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
|
|
|
1358 |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
1359 |
g_value_init(&val, SOUP_TYPE_URI); |
g_value_init(&val, SOUP_TYPE_URI); |
1360 |
g_value_take_boxed(&val, uri); |
g_value_take_boxed(&val, uri); |
1361 |
|
|
1362 |
g_object_set_property(G_OBJECT(priv->soup_session),SOUP_SESSION_PROXY_URI,&val); |
g_object_set_property(G_OBJECT(priv->soup_session),SOUP_SESSION_PROXY_URI,&val); |
1363 |
|
#else |
1364 |
|
#warning "Proxy setting doesn't work in Soup 2.2 yet" |
1365 |
|
printf("setting proxy doesn't work yet with soup22\n"); |
1366 |
|
#endif |
1367 |
} else |
} else |
1368 |
priv->proxy_uri = NULL; |
priv->proxy_uri = NULL; |
1369 |
|
|