]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikmapsource.c
Add the storage and retrieval of any kind of track or waypoint selected item (either...
[andy/viking.git] / src / vikmapsource.c
index 05897360ee0a9a6067a8111a6974009189cfe5e6..5467e01236877ca36ef7eee322180b1ce166eed0 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-2010, 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
  * 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
@@ -30,34 +38,9 @@ static void vik_map_source_init (VikMapSource *object);
 static void vik_map_source_finalize (GObject *object);
 static void vik_map_source_class_init (VikMapSourceClass *klass);
 
-G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,);
-
-/*
-GType
-vik_map_source_get_type (void)
-{
-       static GType type = 0;
-
-       if (!type) {
-               static const GTypeInfo info = {
-                       sizeof (VikMapSourceClass),
-                       (GBaseInitFunc) NULL,
-                       (GBaseFinalizeFunc) NULL,
-                       (GClassInitFunc) vik_map_source_class_init,
-                       (GClassFinalizeFunc) NULL,
-                       NULL /* class_data * /,
-                       sizeof (VikMapSource),
-                       0 /* n_preallocs * /,
-                       (GInstanceInitFunc) vik_map_source_init,
-                       NULL
-               };
-
-               type = g_type_register_static (G_TYPE_OBJECT, "VikMapSource", &info, (GTypeFlags)G_TYPE_FLAG_ABSTRACT);
-       }
+static gboolean _supports_download_only_new (VikMapSource *object);
 
-       return type;
-}
-*/
+G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,);
 
 static void
 vik_map_source_init (VikMapSource *object)
@@ -78,17 +61,93 @@ vik_map_source_class_init (VikMapSourceClass *klass)
 {
        GObjectClass* object_class = G_OBJECT_CLASS (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->supports_download_only_new = _supports_download_only_new;
        klass->coord_to_mapcoord = NULL;
        klass->mapcoord_to_center_coord = NULL;
        klass->download = NULL;
+       klass->download_handle_init = NULL;
+       klass->download_handle_cleanup = NULL;
        
        object_class->finalize = vik_map_source_finalize;
 }
 
+gboolean
+_supports_download_only_new (VikMapSource *self)
+{
+       // Default feature: does not support
+       return FALSE;
+}
+
+/**
+ * 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.
+ *
+ * retreive 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_if_fail (self != NULL);
+       g_return_if_fail (VIK_IS_MAP_SOURCE (self));
+       klass = VIK_MAP_SOURCE_GET_CLASS(self);
+
+       g_return_if_fail (klass->get_copyright != NULL);
+
+       (*klass->get_copyright)(self, bbox, zoom, fct, data);
+}
+
+const gchar *
+vik_map_source_get_license (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_license != NULL, NULL);
+
+       return (*klass->get_license)(self);
+}
+
+const gchar *
+vik_map_source_get_license_url (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_license_url != NULL, NULL);
+
+       return (*klass->get_license_url)(self);
+}
+
+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);
+}
 
 guint8
 vik_map_source_get_uniq_id (VikMapSource *self)
@@ -103,6 +162,19 @@ vik_map_source_get_uniq_id (VikMapSource *self)
        return (*klass->get_uniq_id)(self);
 }
 
+const gchar *
+vik_map_source_get_label (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_label != NULL, NULL);
+
+       return (*klass->get_label)(self);
+}
+
 guint16
 vik_map_source_get_tilesize_x (VikMapSource *self)
 {
@@ -142,6 +214,19 @@ vik_map_source_get_drawmode (VikMapSource *self)
        return (*klass->get_drawmode)(self);
 }
 
+gboolean
+vik_map_source_supports_download_only_new (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->supports_download_only_new != NULL, 0);
+
+       return (*klass->supports_download_only_new)(self);
+}
+
 gboolean
 vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
 {
@@ -165,11 +250,11 @@ 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 (VikMapSource * self, MapCoord * src, const gchar * dest_fn)
+vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
 {
        VikMapSourceClass *klass;
        g_return_val_if_fail (self != NULL, 0);
@@ -178,5 +263,31 @@ vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest
 
        g_return_val_if_fail (klass->download != NULL, 0);
 
-       return (*klass->download)(self, src, dest_fn);
+       return (*klass->download)(self, src, dest_fn, handle);
+}
+
+void *
+vik_map_source_download_handle_init (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->download_handle_init != NULL, 0);
+
+       return (*klass->download_handle_init)(self);
+}
+
+void
+vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
+{
+       VikMapSourceClass *klass;
+       g_return_if_fail (self != NULL);
+       g_return_if_fail (VIK_IS_MAP_SOURCE (self));
+       klass = VIK_MAP_SOURCE_GET_CLASS(self);
+
+       g_return_if_fail (klass->download_handle_cleanup != NULL);
+
+       (*klass->download_handle_cleanup)(self, handle);
 }