From: Pierre-Luc Beaudoin Date: Thu, 28 Aug 2008 18:47:45 +0000 (-0400) Subject: Offline mode X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad997749a37e958a25bf1828e36e18e73276a9a6;p=libchamplain Offline mode --- diff --git a/champlain/champlainview.c b/champlain/champlainview.c index 8ec6305..698a358 100644 --- a/champlain/champlainview.c +++ b/champlain/champlainview.c @@ -49,12 +49,14 @@ enum PROP_LONGITUDE, PROP_LATITUDE, PROP_ZOOM_LEVEL, - PROP_MAP_SOURCE + PROP_MAP_SOURCE, + PROP_OFFLINE }; static guint champlain_view_signals[LAST_SIGNAL] = { 0, }; #define CHAMPLAIN_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_VIEW, ChamplainViewPrivate)) + #define CHAMPLAIN_PARAM_READABLE \ (G_PARAM_READABLE | \ G_PARAM_STATIC_NICK | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB) @@ -74,6 +76,8 @@ struct _ChamplainViewPrivate ClutterActor *fingerScroll; GdkRectangle viewportSize; Map *map; + + gboolean offline; }; @@ -160,6 +164,9 @@ champlain_view_get_property(GObject* object, guint prop_id, GValue* value, GPara case PROP_MAP_SOURCE: g_value_set_int(value, priv->mapSource); break; + case PROP_OFFLINE: + g_value_set_boolean(value, priv->offline); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); } @@ -232,12 +239,14 @@ champlain_view_set_property(GObject* object, guint prop_id, const GValue* value, currentLevel = priv->map->zoom_levels; map_load_level(priv->map, currentLevel); - map_load_visible_tiles (priv->map, priv->viewportSize); + map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline); clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group); } } break; } + case PROP_OFFLINE: + priv->offline = g_value_get_boolean(value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -304,12 +313,12 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) */ g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL, g_param_spec_int("zoom-level", - "Zoom level", - "The level of zoom of the map", - 0, - 20, - 1.0f, - CHAMPLAIN_PARAM_READWRITE)); + "Zoom level", + "The level of zoom of the map", + 0, + 20, + 1.0f, + CHAMPLAIN_PARAM_READWRITE)); /** @@ -321,26 +330,40 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) */ g_object_class_install_property(objectClass, PROP_MAP_SOURCE, g_param_spec_int("map-source", - "Map source", - "The map source being displayed", - 0, - CHAMPLAIN_MAP_SOURCE_COUNT, - CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP, - CHAMPLAIN_PARAM_READWRITE)); + "Map source", + "The map source being displayed", + 0, + CHAMPLAIN_MAP_SOURCE_COUNT, + CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP, + CHAMPLAIN_PARAM_READWRITE)); + + /** + * ChamplainView:offline: + * + * If true, will fetch tiles from the Internet, otherwise, will only use cached content. + * + * Since: 0.2 + */ + g_object_class_install_property(objectClass, PROP_OFFLINE, + g_param_spec_boolean("offline", + "Offline Mode", + "If viewer is in offline mode.", + FALSE, + CHAMPLAIN_PARAM_READWRITE)); } static void champlain_view_init (ChamplainView *champlainView) { ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); + priv->mapSource = CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP; priv->zoomLevel = 0; + priv->offline = FALSE; } static void -viewport_x_changed_cb(GObject *gobject, - GParamSpec *arg1, - ChamplainView *champlainView) +viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *champlainView) { ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); @@ -356,7 +379,7 @@ viewport_x_changed_cb(GObject *gobject, priv->viewportSize.x = rect.x; priv->viewportSize.y = rect.y; - map_load_visible_tiles (priv->map, priv->viewportSize); + map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline); g_object_notify(G_OBJECT(champlainView), "longitude"); g_object_notify(G_OBJECT(champlainView), "latitude"); @@ -371,7 +394,7 @@ view_size_allocated_cb (GtkWidget *view, GtkAllocation *allocation, ChamplainVie priv->viewportSize.height = allocation->height; resize_viewport(champlainView); - map_load_visible_tiles (priv->map, priv->viewportSize); + map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline); } /** @@ -446,7 +469,7 @@ champlain_view_center_on (ChamplainView *champlainView, gdouble longitude, gdoub g_object_notify(G_OBJECT(champlainView), "longitude"); g_object_notify(G_OBJECT(champlainView), "latitude"); - map_load_visible_tiles (priv->map, priv->viewportSize); + map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline); } /** diff --git a/champlain/error.svg b/champlain/error.svg new file mode 100644 index 0000000..3664ca0 --- /dev/null +++ b/champlain/error.svg @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/champlain/map.c b/champlain/map.c index bf61494..e5256d7 100644 --- a/champlain/map.c +++ b/champlain/map.c @@ -63,7 +63,7 @@ map_load_level(Map* map, gint zoom_level) } void -map_load_visible_tiles (Map* map, GdkRectangle viewport) +map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline) { gint x_count = ceil((float)viewport.width / map->tile_size) + 1; gint y_count = ceil((float)viewport.height / map->tile_size) + 1; @@ -92,7 +92,7 @@ map_load_visible_tiles (Map* map, GdkRectangle viewport) if(!exist) { - Tile* tile = tile_load(map, map->current_level->level, i, j); + Tile* tile = tile_load(map, map->current_level->level, i, j, offline); g_ptr_array_add (map->current_level->tiles, tile); } } diff --git a/champlain/map.h b/champlain/map.h index 8de4e86..7893ce4 100644 --- a/champlain/map.h +++ b/champlain/map.h @@ -54,7 +54,7 @@ struct _Map Map* map_new (ChamplainMapSource source); -void map_load_visible_tiles (Map* map, GdkRectangle viewport); +void map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline); void map_free (Map* map); diff --git a/champlain/tile.c b/champlain/tile.c index 8884871..fd4deb4 100644 --- a/champlain/tile.c +++ b/champlain/tile.c @@ -147,7 +147,7 @@ file_loaded_cb (SoupSession *session, } Tile* -tile_load (Map* map, guint zoom_level, guint x, guint y) +tile_load (Map* map, guint zoom_level, guint x, guint y, gboolean offline) { static SoupSession * session; gchar* filename, *map_filename; @@ -177,7 +177,7 @@ tile_load (Map* map, guint zoom_level, guint x, guint y) clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); } - else + else if (!offline) { SoupMessage *msg; if (!session) @@ -188,7 +188,8 @@ tile_load (Map* map, guint zoom_level, guint x, guint y) soup_session_queue_message (session, msg, file_loaded_cb, ptr); - } + } + // If a tile is neither in cache or can be fetched, do nothing, it'll show up as empty g_free (filename); g_free (map_filename);