#include <math.h>
#include <string.h>
-void champlain_map_source_real_get_tile (ChamplainMapSource *map_source,
- ChamplainView *view, gint zoom_level, ChamplainTile *tile);
+void champlain_map_source_real_fill_tile (ChamplainMapSource *map_source,
+ ChamplainTile *tile);
enum
{
object_class->get_property = champlain_map_source_get_property;
object_class->set_property = champlain_map_source_set_property;
- klass->get_tile = champlain_map_source_real_get_tile;
+ klass->fill_tile = champlain_map_source_real_fill_tile;
/**
* ChamplainMapSource:name:
}
void
-champlain_map_source_get_tile (ChamplainMapSource *map_source,
- ChamplainView *view,
- gint zoom_level,
+champlain_map_source_fill_tile (ChamplainMapSource *map_source,
ChamplainTile *tile)
{
g_return_if_fail (CHAMPLAIN_IS_MAP_SOURCE (map_source));
- CHAMPLAIN_MAP_SOURCE_GET_CLASS (map_source)->get_tile (map_source, view, zoom_level, tile);
+ CHAMPLAIN_MAP_SOURCE_GET_CLASS (map_source)->fill_tile (map_source, tile);
}
void
-champlain_map_source_real_get_tile (ChamplainMapSource *map_source,
- ChamplainView *view,
- gint zoom_level,
+champlain_map_source_real_fill_tile (ChamplainMapSource *map_source,
ChamplainTile *tile)
{
g_error ("Should not be reached");
object_class->set_property = champlain_network_map_source_set_property;
ChamplainMapSourceClass *map_source_class = CHAMPLAIN_MAP_SOURCE_CLASS (klass);
- map_source_class->get_tile = champlain_network_map_source_get_tile;
+ map_source_class->fill_tile = champlain_network_map_source_fill_tile;
/**
* ChamplainNetworkMapSource:uri-format
static gchar *
get_filename (ChamplainNetworkMapSource *network_map_source,
- gint zoom_level,
ChamplainTile *tile)
{
//ChamplainNetworkMapSourcePrivate *priv = network_map_source->priv;
"%s" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S
"%d" G_DIR_SEPARATOR_S "%d.png", g_get_user_cache_dir (),
CACHE_SUBDIR, champlain_map_source_get_name (CHAMPLAIN_MAP_SOURCE (network_map_source)),
- zoom_level,
+ champlain_tile_get_zoom_level (tile),
champlain_tile_get_x (tile), champlain_tile_get_y (tile));
}
-typedef struct {
- ChamplainView *view;
- ChamplainTile *tile;
-} FileLoadedCallbackContext;
-
static void
create_error_tile (ChamplainTile* tile)
{
SoupMessage *msg,
gpointer user_data)
{
- FileLoadedCallbackContext *ctx = (FileLoadedCallbackContext*) user_data;
+ ChamplainTile *tile = CHAMPLAIN_TILE (user_data);
GdkPixbufLoader* loader;
GError *error = NULL;
gchar* path = NULL;
guint filesize = 0;
ChamplainCache *cache = champlain_cache_get_default ();
- filename = champlain_tile_get_filename (ctx->tile);
+ filename = champlain_tile_get_filename (tile);
DEBUG ("Got reply %d", msg->status_code);
if (msg->status_code == 304)
g_object_unref (info);
g_free (now);
- champlain_tile_set_state (ctx->tile, CHAMPLAIN_STATE_DONE);
- g_object_unref (ctx->tile);
- g_free (ctx);
+ champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
+ g_object_unref (tile);
return;
}
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
{
DEBUG ("Unable to download tile %d, %d: %s",
- champlain_tile_get_x (ctx->tile),
- champlain_tile_get_y (ctx->tile),
+ champlain_tile_get_x (tile),
+ champlain_tile_get_y (tile),
soup_status_get_phrase(msg->status_code));
- create_error_tile (ctx->tile);
+ create_error_tile (tile);
goto finish;
}
{
g_warning ("Unable to load the pixbuf: %s", error->message);
g_error_free (error);
- create_error_tile (ctx->tile);
+ create_error_tile (tile);
goto cleanup;
}
{
g_warning ("Unable to close the pixbuf loader: %s", error->message);
g_error_free (error);
- create_error_tile (ctx->tile);
+ create_error_tile (tile);
goto cleanup;
}
if (etag != NULL)
{
- champlain_tile_set_etag (ctx->tile, etag);
+ champlain_tile_set_etag (tile, etag);
}
- champlain_cache_update_tile (cache, ctx->tile, filesize); //XXX
+ champlain_cache_update_tile (cache, tile, filesize); //XXX
/* Load the image into clutter */
GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
{
g_warning ("Unable to transfer to clutter: %s", error->message);
g_error_free (error);
- create_error_tile (ctx->tile);
+ create_error_tile (tile);
g_object_unref (actor);
goto cleanup;
}
}
- champlain_tile_set_content (ctx->tile, actor, TRUE);
+ champlain_tile_set_content (tile, actor, TRUE);
DEBUG ("Tile loaded from network");
cleanup:
g_object_unref (loader);
g_free (path);
finish:
- champlain_tile_set_state (ctx->tile, CHAMPLAIN_STATE_DONE);
- g_object_unref (ctx->tile);
- g_free (ctx);
+ champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
+ g_object_unref (tile);
}
void
-champlain_network_map_source_get_tile (ChamplainMapSource *map_source,
- ChamplainView *view,
- gint zoom_level,
+champlain_network_map_source_fill_tile (ChamplainMapSource *map_source,
ChamplainTile *tile)
{
gchar* filename;
gboolean in_cache = FALSE;
gboolean validate_cache = FALSE;
+ gint zoom_level = champlain_tile_get_zoom_level (tile);
ChamplainNetworkMapSource *network_map_source = CHAMPLAIN_NETWORK_MAP_SOURCE (map_source);
ChamplainNetworkMapSourcePrivate *priv = network_map_source->priv;
ChamplainCache *cache = champlain_cache_get_default ();
/* Try the cached version first */
- filename = get_filename (network_map_source, zoom_level, tile);
+ filename = get_filename (network_map_source, tile);
champlain_tile_set_filename (tile, filename);
champlain_tile_set_size (tile, champlain_map_source_get_tile_size (map_source));
{
SoupMessage *msg;
gchar *uri;
- FileLoadedCallbackContext *ctx = g_new0 (FileLoadedCallbackContext, 1);
- ctx->view = view;
- ctx->tile = tile;
/* Ref the tile as it may be freeing during the loading
* Unref when the loading is done.
soup_session_queue_message (soup_session, msg,
file_loaded_cb,
- ctx);
+ tile);
g_free (uri);
}
g_free (filename);
{
DEBUG ("Loading tile %d, %d, %d", champlain_zoom_level_get_zoom_level (level), i, j);
ChamplainTile *tile = champlain_tile_new ();
- g_object_set (G_OBJECT (tile), "x", i, "y", j, NULL);
+ g_object_set (G_OBJECT (tile), "x", i, "y", j, "zoom-level", champlain_zoom_level_get_zoom_level (level), NULL);
g_signal_connect (tile, "notify::state", G_CALLBACK (tile_state_notify), view);
clutter_container_add (CLUTTER_CONTAINER (champlain_zoom_level_get_actor (level)),
champlain_tile_get_actor (tile), NULL);
champlain_zoom_level_add_tile (level, tile);
- champlain_map_source_get_tile (priv->map_source, view,
- champlain_zoom_level_get_zoom_level (level), tile);
+ champlain_map_source_fill_tile (priv->map_source, tile);
g_object_unref (tile);
}