From d86e5fad004492b3d2ee7e2dc5323344750f3f78 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Sat, 2 May 2009 13:10:18 -0400 Subject: [PATCH] Continue API simplification Since the fill_tile doesn't call a callback on the view and that ChamplainTile already contain the zoom_level information, there is no need to pass the view and the zoom level to this function Rename get_tile as fill_tile as you are not getting a tile but filling the tile with data --- champlain/champlain-map-source.c | 16 +++---- champlain/champlain-map-source.h | 8 +--- champlain/champlain-network-map-source.c | 54 +++++++++--------------- champlain/champlain-network-map-source.h | 4 +- champlain/champlain-view.c | 5 +-- 5 files changed, 32 insertions(+), 55 deletions(-) diff --git a/champlain/champlain-map-source.c b/champlain/champlain-map-source.c index dee4abf..7c0773e 100644 --- a/champlain/champlain-map-source.c +++ b/champlain/champlain-map-source.c @@ -34,8 +34,8 @@ #include #include -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 { @@ -171,7 +171,7 @@ champlain_map_source_class_init (ChamplainMapSourceClass *klass) 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: @@ -348,20 +348,16 @@ champlain_map_source_get_column_count (ChamplainMapSource *map_source, } 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"); diff --git a/champlain/champlain-map-source.h b/champlain/champlain-map-source.h index 536ecad..5d02d1a 100644 --- a/champlain/champlain-map-source.h +++ b/champlain/champlain-map-source.h @@ -57,9 +57,7 @@ struct _ChamplainMapSourceClass { GObjectClass parent_class; - void (*get_tile) (ChamplainMapSource *map_source, - ChamplainView *view, - gint zoom_level, + void (*fill_tile) (ChamplainMapSource *map_source, ChamplainTile *tile); }; @@ -93,9 +91,7 @@ guint champlain_map_source_get_row_count (ChamplainMapSource *map_source, guint champlain_map_source_get_column_count (ChamplainMapSource *map_source, gint zoom_level); -void champlain_map_source_get_tile (ChamplainMapSource *map_source, - ChamplainView *view, - gint zoom_level, +void champlain_map_source_fill_tile (ChamplainMapSource *map_source, ChamplainTile *tile); void champlain_map_source_set_name (ChamplainMapSource *map_source, diff --git a/champlain/champlain-network-map-source.c b/champlain/champlain-network-map-source.c index ae12ff0..dc467a9 100644 --- a/champlain/champlain-network-map-source.c +++ b/champlain/champlain-network-map-source.c @@ -159,7 +159,7 @@ champlain_network_map_source_class_init (ChamplainNetworkMapSourceClass *klass) 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 @@ -344,7 +344,6 @@ champlain_map_source_new_mff_relief (void) static gchar * get_filename (ChamplainNetworkMapSource *network_map_source, - gint zoom_level, ChamplainTile *tile) { //ChamplainNetworkMapSourcePrivate *priv = network_map_source->priv; @@ -352,15 +351,10 @@ get_filename (ChamplainNetworkMapSource *network_map_source, "%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) { @@ -406,7 +400,7 @@ file_loaded_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { - FileLoadedCallbackContext *ctx = (FileLoadedCallbackContext*) user_data; + ChamplainTile *tile = CHAMPLAIN_TILE (user_data); GdkPixbufLoader* loader; GError *error = NULL; gchar* path = NULL; @@ -417,7 +411,7 @@ file_loaded_cb (SoupSession *session, 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) @@ -439,18 +433,17 @@ file_loaded_cb (SoupSession *session, 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; } @@ -465,7 +458,7 @@ file_loaded_cb (SoupSession *session, { 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; } @@ -477,7 +470,7 @@ file_loaded_cb (SoupSession *session, { 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; } @@ -508,9 +501,9 @@ file_loaded_cb (SoupSession *session, 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); @@ -530,40 +523,38 @@ file_loaded_cb (SoupSession *session, { 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)); @@ -587,9 +578,6 @@ champlain_network_map_source_get_tile (ChamplainMapSource *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. @@ -641,7 +629,7 @@ champlain_network_map_source_get_tile (ChamplainMapSource *map_source, soup_session_queue_message (soup_session, msg, file_loaded_cb, - ctx); + tile); g_free (uri); } g_free (filename); diff --git a/champlain/champlain-network-map-source.h b/champlain/champlain-network-map-source.h index 88636aa..31c7d09 100644 --- a/champlain/champlain-network-map-source.h +++ b/champlain/champlain-network-map-source.h @@ -73,9 +73,7 @@ gchar * champlain_network_map_source_get_tile_uri (ChamplainNetworkMapSource *so void champlain_network_map_source_set_tile_uri (ChamplainNetworkMapSource *network_map_source, const gchar *uri_format); -void champlain_network_map_source_get_tile (ChamplainMapSource *map_source, - ChamplainView *view, - gint zoom_level, +void champlain_network_map_source_fill_tile (ChamplainMapSource *map_source, ChamplainTile *tile); G_END_DECLS diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index 0fdceb9..68ee7be 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -1506,15 +1506,14 @@ view_load_visible_tiles (ChamplainView *view) { 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); } -- 2.39.5