]> git.street.me.uk Git - andy/viking.git/blobdiff - src/terraservermapsource.c
[I18N] Mark translatable string
[andy/viking.git] / src / terraservermapsource.c
index 889301c6d04e1bf511b39f505c457825f66511cb..9e6dd70993271183cc8e6c81a5f35121357959a3 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- 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 _is_direct_file_access ( VikMapSource *self );
+
+static gchar *_get_uri( VikMapSourceDefault *self, MapCoord *src );
+static gchar *_get_hostname( VikMapSourceDefault *self );
+static DownloadMapOptions *_get_download_options( VikMapSourceDefault *self );
 
 /* FIXME Huge gruik */
-static DownloadOptions terraserver_options = { NULL, 0, a_check_map_file };
+static DownloadMapOptions terraserver_options = { FALSE, FALSE, NULL, 0, a_check_map_file };
 
 typedef struct _TerraserverMapSourcePrivate TerraserverMapSourcePrivate;
 struct _TerraserverMapSourcePrivate
@@ -52,7 +54,7 @@ enum
   PROP_TYPE,
 };
 
-G_DEFINE_TYPE_EXTENDED (TerraserverMapSource, terraserver_map_source, VIK_TYPE_MAP_SOURCE_DEFAULT, (GTypeFlags)0,);
+G_DEFINE_TYPE (TerraserverMapSource, terraserver_map_source, VIK_TYPE_MAP_SOURCE_DEFAULT);
 
 static void
 terraserver_map_source_init (TerraserverMapSource *self)
@@ -121,18 +123,21 @@ static void
 terraserver_map_source_class_init (TerraserverMapSourceClass *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 = terraserver_map_source_set_property;
     object_class->get_property = terraserver_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;
+       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;
+       
+       parent_class->get_uri = _get_uri;
+       parent_class->get_hostname = _get_hostname;
+       parent_class->get_download_options = _get_download_options;
 
        pspec = g_param_spec_uint ("type",
                                   "Type",
@@ -148,7 +153,7 @@ terraserver_map_source_class_init (TerraserverMapSourceClass *klass)
        object_class->finalize = terraserver_map_source_finalize;
 }
 
-#define TERRASERVER_SITE "terraserver-usa.com"
+#define TERRASERVER_SITE "msrmaps.com"
 #define MARGIN_OF_ERROR 0.001
 
 static int mpp_to_scale ( gdouble mpp, guint8 type )
@@ -187,7 +192,8 @@ _coord_to_mapcoord ( VikMapSource *self, const VikCoord *src, gdouble xmpp, gdou
        
        TerraserverMapSourcePrivate *priv = TERRASERVER_MAP_SOURCE_PRIVATE(self);
        int type = priv->type;
-       g_assert ( src->mode == VIK_COORD_UTM );
+       if ( src->mode != VIK_COORD_UTM )
+               return FALSE;
 
        if ( xmpp != ympp )
                return FALSE;
@@ -202,6 +208,12 @@ _coord_to_mapcoord ( VikMapSource *self, const VikCoord *src, gdouble xmpp, gdou
        return TRUE;
 }
 
+static gboolean
+_is_direct_file_access ( VikMapSource *self )
+{
+       return FALSE;
+}
+
 static void
 _mapcoord_to_center_coord ( VikMapSource *self, MapCoord *src, VikCoord *dest )
 {
@@ -213,35 +225,55 @@ _mapcoord_to_center_coord ( VikMapSource *self, MapCoord *src, VikCoord *dest )
        dest->north_south = ((src->y * 200) + 100) * mpp;
 }
 
-static int
-_download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn, void *handle )
+static gchar *
+_get_uri( VikMapSourceDefault *self, MapCoord *src )
 {
-       g_return_val_if_fail(TERRASERVER_IS_MAP_SOURCE(self), FALSE);
+       g_return_val_if_fail (TERRASERVER_IS_MAP_SOURCE(self), NULL);
        
-       TerraserverMapSourcePrivate *priv = TERRASERVER_MAP_SOURCE_PRIVATE(self);  int res = -1;
+       TerraserverMapSourcePrivate *priv = TERRASERVER_MAP_SOURCE_PRIVATE(self);
        int type = priv->type;
        gchar *uri = g_strdup_printf ( "/tile.ashx?T=%d&S=%d&X=%d&Y=%d&Z=%d", type,
                                   src->scale, src->x, src->y, src->z );
-       res = a_http_download_get_url ( TERRASERVER_SITE, uri, dest_fn, &terraserver_options, handle );
-       g_free ( uri );
-       return res;
-}
+       return uri;
+} 
 
-static void *
-_download_handle_init ( VikMapSource *self )
+static gchar *
+_get_hostname( VikMapSourceDefault *self )
 {
-       return a_download_handle_init ();
+       g_return_val_if_fail (TERRASERVER_IS_MAP_SOURCE(self), NULL);
+       
+       return g_strdup( TERRASERVER_SITE );
 }
 
-
-static void
-_download_handle_cleanup ( VikMapSource *self, void *handle )
+static DownloadMapOptions *
+_get_download_options( VikMapSourceDefault *self )
 {
-       return a_download_handle_cleanup ( handle );
+       g_return_val_if_fail (TERRASERVER_IS_MAP_SOURCE(self), NULL);
+       
+       return &terraserver_options;
 }
 
 TerraserverMapSource *
 terraserver_map_source_new_with_id (guint8 id, const char *label, int type)
 {
-       return g_object_new(TERRASERVER_TYPE_MAP_SOURCE, "id", id, "label", label, "type", type, NULL);
+       char *copyright = NULL;
+       switch (type)
+       {
+       case 1:
+               copyright = "© DigitalGlobe";
+               break;
+       case 2:
+               copyright = "© LandVoyage";
+               break;
+       case 4:
+               copyright = "© DigitalGlobe";
+               break;
+       default:
+               g_critical("Houston, we've had a problem. type=%d", type);
+       }
+
+       return g_object_new(TERRASERVER_TYPE_MAP_SOURCE,
+                           "id", id, "label", label, "type", type,
+                           "copyright", copyright,
+                           NULL);
 }