/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* viking
- * Copyright (C) Guilhem Bonnefille 2009 <guilhem.bonnefille@gmail.com>
+ * Copyright (C) 2009, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
*
* viking is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
static gboolean _coord_to_mapcoord ( VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest );
static void _mapcoord_to_center_coord ( VikMapSource *self, MapCoord *src, VikCoord *dest );
-static int _download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn, void *handle );
-static void * _download_handle_init ( VikMapSource *self);
-static void _download_handle_cleanup ( VikMapSource *self, void *handle);
-static gboolean _supports_if_modified_since (VikMapSource *self );
-static gchar *_get_uri( VikSlippyMapSource *self, MapCoord *src );
-static gchar *_get_hostname( VikSlippyMapSource *self );
-static DownloadOptions *_get_download_options( VikSlippyMapSource *self );
+static gboolean _is_direct_file_access (VikMapSource *self );
+static gboolean _supports_download_only_new (VikMapSource *self );
+
+static gchar *_get_uri( VikMapSourceDefault *self, MapCoord *src );
+static gchar *_get_hostname( VikMapSourceDefault *self );
+static DownloadMapOptions *_get_download_options( VikMapSourceDefault *self );
typedef struct _VikSlippyMapSourcePrivate VikSlippyMapSourcePrivate;
struct _VikSlippyMapSourcePrivate
{
gchar *hostname;
gchar *url;
- DownloadOptions options;
+ DownloadMapOptions options;
+ gboolean is_direct_file_access;
};
#define VIK_SLIPPY_MAP_SOURCE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_TYPE_SLIPPY_MAP_SOURCE, VikSlippyMapSourcePrivate))
PROP_REFERER,
PROP_FOLLOW_LOCATION,
PROP_CHECK_FILE_SERVER_TIME,
+ PROP_USE_ETAG,
+ PROP_IS_DIRECT_FILE_ACCESS,
};
G_DEFINE_TYPE (VikSlippyMapSource, vik_slippy_map_source, VIK_TYPE_MAP_SOURCE_DEFAULT);
priv->options.follow_location = 0;
priv->options.check_file = a_check_map_file;
priv->options.check_file_server_time = FALSE;
+ priv->options.use_etag = FALSE;
+ priv->is_direct_file_access = FALSE;
g_object_set (G_OBJECT (self),
"tilesize-x", 256,
priv->options.check_file_server_time = g_value_get_boolean (value);
break;
+ case PROP_USE_ETAG:
+ priv->options.use_etag = g_value_get_boolean (value);
+ break;
+
+ case PROP_IS_DIRECT_FILE_ACCESS:
+ priv->is_direct_file_access = g_value_get_boolean (value);
+ break;
+
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
g_value_set_boolean (value, priv->options.check_file_server_time);
break;
+ case PROP_USE_ETAG:
+ g_value_set_boolean (value, priv->options.use_etag);
+ break;
+
+ case PROP_IS_DIRECT_FILE_ACCESS:
+ g_value_set_boolean (value, priv->is_direct_file_access);
+ break;
+
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
vik_slippy_map_source_class_init (VikSlippyMapSourceClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
- VikMapSourceClass* parent_class = VIK_MAP_SOURCE_CLASS (klass);
+ VikMapSourceClass* grandparent_class = VIK_MAP_SOURCE_CLASS (klass);
+ VikMapSourceDefaultClass* parent_class = VIK_MAP_SOURCE_DEFAULT_CLASS (klass);
GParamSpec *pspec = NULL;
object_class->set_property = vik_slippy_map_source_set_property;
object_class->get_property = vik_slippy_map_source_get_property;
/* Overiding methods */
- parent_class->coord_to_mapcoord = _coord_to_mapcoord;
- parent_class->mapcoord_to_center_coord = _mapcoord_to_center_coord;
- parent_class->download = _download;
- parent_class->download_handle_init = _download_handle_init;
- parent_class->download_handle_cleanup = _download_handle_cleanup;
- parent_class->supports_if_modified_since = _supports_if_modified_since;
-
- /* Default implementation of methods */
- klass->get_uri = _get_uri;
- klass->get_hostname = _get_hostname;
- klass->get_download_options = _get_download_options;
+ grandparent_class->coord_to_mapcoord = _coord_to_mapcoord;
+ grandparent_class->mapcoord_to_center_coord = _mapcoord_to_center_coord;
+ grandparent_class->is_direct_file_access = _is_direct_file_access;
+ grandparent_class->supports_download_only_new = _supports_download_only_new;
+
+ parent_class->get_uri = _get_uri;
+ parent_class->get_hostname = _get_hostname;
+ parent_class->get_download_options = _get_download_options;
pspec = g_param_spec_string ("hostname",
"Hostname",
"The hostname of the map server",
"<no-set>" /* default value */,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_HOSTNAME, pspec);
pspec = g_param_spec_string ("url",
"URL",
"The template of the tiles' URL",
"<no-set>" /* default value */,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_URL, pspec);
pspec = g_param_spec_string ("referer",
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CHECK_FILE_SERVER_TIME, pspec);
+ pspec = g_param_spec_boolean ("use-etag",
+ "Use etag values with server",
+ "Store etag in a file, and send it to server to check if we have the latest file",
+ FALSE /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_USE_ETAG, pspec);
+
+ pspec = g_param_spec_boolean ("use-direct-file-access",
+ "Use direct file access",
+ "Use direct file access to OSM like tile images - no need for a webservice",
+ FALSE /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_IS_DIRECT_FILE_ACCESS, pspec);
+
g_type_class_add_private (klass, sizeof (VikSlippyMapSourcePrivate));
object_class->finalize = vik_slippy_map_source_finalize;
static const gint num_scales_neg = (sizeof(scale_neg_mpps) / sizeof(scale_neg_mpps[0]));
#define ERROR_MARGIN 0.01
-static gint slippy_zoom ( gdouble mpp ) {
+gint
+vik_slippy_map_source_zoom_to_scale ( gdouble mpp ) {
gint i;
for ( i = 0; i < num_scales; i++ ) {
if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) {
return 255;
}
-gchar *
-vik_slippy_map_source_get_uri( VikSlippyMapSource *self, MapCoord *src )
-{
- VikSlippyMapSourceClass *klass;
- g_return_val_if_fail (self != NULL, 0);
- g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE (self), 0);
- klass = VIK_SLIPPY_MAP_SOURCE_GET_CLASS(self);
-
- g_return_val_if_fail (klass->get_uri != NULL, 0);
-
- return (*klass->get_uri)(self, src);
-}
-
-gchar *
-vik_slippy_map_source_get_hostname( VikSlippyMapSource *self )
-{
- VikSlippyMapSourceClass *klass;
- g_return_val_if_fail (self != NULL, 0);
- g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE (self), 0);
- klass = VIK_SLIPPY_MAP_SOURCE_GET_CLASS(self);
-
- g_return_val_if_fail (klass->get_hostname != NULL, 0);
-
- return (*klass->get_hostname)(self);
-}
-
-DownloadOptions *
-vik_slippy_map_source_get_download_options( VikSlippyMapSource *self )
+gboolean
+_is_direct_file_access (VikMapSource *self)
{
- VikSlippyMapSourceClass *klass;
- g_return_val_if_fail (self != NULL, 0);
- g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE (self), 0);
- klass = VIK_SLIPPY_MAP_SOURCE_GET_CLASS(self);
+ g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE(self), FALSE);
- g_return_val_if_fail (klass->get_download_options != NULL, 0);
+ VikSlippyMapSourcePrivate *priv = VIK_SLIPPY_MAP_SOURCE_PRIVATE(self);
- return (*klass->get_download_options)(self);
+ return priv->is_direct_file_access;
}
gboolean
-_supports_if_modified_since (VikMapSource *self)
+_supports_download_only_new (VikMapSource *self)
{
- g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE(self), FALSE);
+ g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE(self), FALSE);
- VikSlippyMapSourcePrivate *priv = VIK_SLIPPY_MAP_SOURCE_PRIVATE(self);
+ VikSlippyMapSourcePrivate *priv = VIK_SLIPPY_MAP_SOURCE_PRIVATE(self);
- return priv->options.check_file_server_time;
+ return priv->options.check_file_server_time || priv->options.use_etag;
}
+
static gboolean
_coord_to_mapcoord ( VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
{
if ( xzoom != yzoom )
return FALSE;
- dest->scale = slippy_zoom ( xzoom );
+ dest->scale = vik_slippy_map_source_zoom_to_scale ( xzoom );
if ( dest->scale == 255 )
return FALSE;
dest->north_south = DEMERCLAT(180 - ((src->y+0.5) / GZ(17) * socalled_mpp * 360));
}
-static int
-_download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn, void *handle )
-{
- int res;
- gchar *uri = vik_slippy_map_source_get_uri(VIK_SLIPPY_MAP_SOURCE(self), src);
- gchar *host = vik_slippy_map_source_get_hostname(VIK_SLIPPY_MAP_SOURCE(self));
- DownloadOptions *options = vik_slippy_map_source_get_download_options(VIK_SLIPPY_MAP_SOURCE(self));
- res = a_http_download_get_url ( host, uri, dest_fn, options, handle );
- g_free ( uri );
- g_free ( host );
- return res;
-}
-
-static void *
-_download_handle_init ( VikMapSource *self )
-{
- return a_download_handle_init ();
-}
-
-
-static void
-_download_handle_cleanup ( VikMapSource *self, void *handle )
-{
- return a_download_handle_cleanup ( handle );
-}
-
static gchar *
-_get_uri( VikSlippyMapSource *self, MapCoord *src )
+_get_uri( VikMapSourceDefault *self, MapCoord *src )
{
g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE(self), NULL);
}
static gchar *
-_get_hostname( VikSlippyMapSource *self )
+_get_hostname( VikMapSourceDefault *self )
{
g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE(self), NULL);
return g_strdup( priv->hostname );
}
-static DownloadOptions *
-_get_download_options( VikSlippyMapSource *self )
+static DownloadMapOptions *
+_get_download_options( VikMapSourceDefault *self )
{
g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE(self), NULL);