]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikmapsource.c
Add capability to save layer defaults from outside the layer defaults code.
[andy/viking.git] / src / vikmapsource.c
index 53784479fa34738fc032ad07b74fae2c72c940a4..7d4cc97cb7111dc8c9441a8ff0e89534d2db8201 100644 (file)
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
+ /**
+  * SECTION:vikmapsource
+  * @short_description: the base class to describe map source
+  * 
+  * The #VikMapSource class is both the interface and the base class
+  * for the hierarchie of map source.
+  */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -23,7 +31,7 @@
 #include "vikviewport.h"
 #include "vikcoord.h"
 #include "mapcoord.h"
-
+#include "download.h"
 #include "vikmapsource.h"
 
 static void vik_map_source_init (VikMapSource *object);
@@ -32,7 +40,7 @@ static void vik_map_source_class_init (VikMapSourceClass *klass);
 
 static gboolean _supports_download_only_new (VikMapSource *object);
 
-G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,);
+G_DEFINE_ABSTRACT_TYPE (VikMapSource, vik_map_source, G_TYPE_OBJECT);
 
 static void
 vik_map_source_init (VikMapSource *object)
@@ -56,11 +64,14 @@ vik_map_source_class_init (VikMapSourceClass *klass)
        klass->get_copyright = NULL;
        klass->get_license = NULL;
        klass->get_license_url = NULL;
+       klass->get_logo = NULL;
        klass->get_uniq_id = NULL;
        klass->get_label = NULL;
        klass->get_tilesize_x = NULL;
        klass->get_tilesize_y = NULL;
        klass->get_drawmode = NULL;
+       klass->is_direct_file_access = NULL;
+       klass->is_mbtiles = NULL;
        klass->supports_download_only_new = _supports_download_only_new;
        klass->coord_to_mapcoord = NULL;
        klass->mapcoord_to_center_coord = NULL;
@@ -78,17 +89,27 @@ _supports_download_only_new (VikMapSource *self)
        return FALSE;
 }
 
-const gchar *
-vik_map_source_get_copyright (VikMapSource *self)
+/**
+ * vik_map_source_get_copyright:
+ * @self: the VikMapSource of interest.
+ * @bbox: bounding box of interest.
+ * @zoom: the zoom level of interest.
+ * @fct: the callback function to use to return matching copyrights.
+ * @data: the user data to use to call the callbaack function.
+ *
+ * Retrieve copyright(s) for the corresponding bounding box and zoom level.
+ */
+void
+vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data)
 {
        VikMapSourceClass *klass;
-       g_return_val_if_fail (self != NULL, NULL);
-       g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
+       g_return_if_fail (self != NULL);
+       g_return_if_fail (VIK_IS_MAP_SOURCE (self));
        klass = VIK_MAP_SOURCE_GET_CLASS(self);
 
-       g_return_val_if_fail (klass->get_copyright != NULL, NULL);
+       g_return_if_fail (klass->get_copyright != NULL);
 
-       return (*klass->get_copyright)(self);
+       (*klass->get_copyright)(self, bbox, zoom, fct, data);
 }
 
 const gchar *
@@ -117,15 +138,28 @@ vik_map_source_get_license_url (VikMapSource *self)
        return (*klass->get_license_url)(self);
 }
 
-guint8
+const GdkPixbuf *
+vik_map_source_get_logo (VikMapSource *self)
+{
+       VikMapSourceClass *klass;
+       g_return_val_if_fail (self != NULL, NULL);
+       g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
+       klass = VIK_MAP_SOURCE_GET_CLASS(self);
+
+       g_return_val_if_fail (klass->get_logo != NULL, NULL);
+
+       return (*klass->get_logo)(self);
+}
+
+guint16
 vik_map_source_get_uniq_id (VikMapSource *self)
 {
        VikMapSourceClass *klass;
-       g_return_val_if_fail (self != NULL, (guint8 )0);
-       g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint8 )0);
+       g_return_val_if_fail (self != NULL, (guint16 )0);
+       g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
        klass = VIK_MAP_SOURCE_GET_CLASS(self);
 
-       g_return_val_if_fail (klass->get_uniq_id != NULL, (guint8 )0);
+       g_return_val_if_fail (klass->get_uniq_id != NULL, (guint16 )0);
 
        return (*klass->get_uniq_id)(self);
 }
@@ -182,6 +216,47 @@ vik_map_source_get_drawmode (VikMapSource *self)
        return (*klass->get_drawmode)(self);
 }
 
+/**
+ * vik_map_source_is_direct_file_access:
+ * @self: the VikMapSource of interest.
+ *
+ *   Return true when we can bypass all this download malarky
+ *   Treat the files as a pre generated data set in OSM tile server layout: tiledir/%d/%d/%d.png
+ */
+gboolean
+vik_map_source_is_direct_file_access (VikMapSource * self)
+{
+       VikMapSourceClass *klass;
+       g_return_val_if_fail (self != NULL, 0);
+       g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
+       klass = VIK_MAP_SOURCE_GET_CLASS(self);
+
+       g_return_val_if_fail (klass->is_direct_file_access != NULL, 0);
+
+       return (*klass->is_direct_file_access)(self);
+}
+
+/**
+ * vik_map_source_is_mbtiles:
+ * @self: the VikMapSource of interest.
+ *
+ *   Return true when the map is in an MB Tiles format.
+ *   See http://github.com/mapbox/mbtiles-spec
+ *   (Read Only ATM)
+ */
+gboolean
+vik_map_source_is_mbtiles (VikMapSource * self)
+{
+       VikMapSourceClass *klass;
+       g_return_val_if_fail (self != NULL, 0);
+       g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
+       klass = VIK_MAP_SOURCE_GET_CLASS(self);
+
+       g_return_val_if_fail (klass->is_mbtiles != NULL, 0);
+
+       return (*klass->is_mbtiles)(self);
+}
+
 gboolean
 vik_map_source_supports_download_only_new (VikMapSource * self)
 {
@@ -218,10 +293,19 @@ vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikC
 
        g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
 
-       return (*klass->mapcoord_to_center_coord)(self, src, dest);
+       (*klass->mapcoord_to_center_coord)(self, src, dest);
 }
 
-int
+/**
+ * vik_map_source_download:
+ * @self:    The VikMapSource of interest.
+ * @src:     The map location to download
+ * @dest_fn: The filename to save the result in
+ * @handle:  Potential reusable Curl Handle (may be NULL)
+ *
+ * Returns: How successful the download was as per the type #DownloadResult_t
+ */
+DownloadResult_t
 vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
 {
        VikMapSourceClass *klass;