[libshumate/tintou/no-tile-source] map-source: Make this class capable




commit a7fbaccaac64f8c0e8b16f12527ae336a2f11fec
Author: Corentin Noël <corentin noel collabora com>
Date:   Thu Jun 10 16:21:04 2021 +0200

    map-source: Make this class capable
    
    Remove tile-source as there was no gain having a distinction between the two

 demos/shumate-test-tile-source.c       |   4 +-
 demos/shumate-test-tile-source.h       |   2 +-
 docs/reference/libshumate-docs.sgml    |   1 -
 docs/reference/libshumate-sections.txt |  35 +-
 shumate/meson.build                    |   2 -
 shumate/shumate-map-source.c           | 598 ++++++++++++++++++++++++++++-----
 shumate/shumate-map-source.h           |  51 +--
 shumate/shumate-network-tile-source.c  |   2 +-
 shumate/shumate-network-tile-source.h  |   6 +-
 shumate/shumate-tile-source.c          | 593 --------------------------------
 shumate/shumate-tile-source.h          |  67 ----
 shumate/shumate.h                      |   4 -
 12 files changed, 558 insertions(+), 807 deletions(-)
---
diff --git a/demos/shumate-test-tile-source.c b/demos/shumate-test-tile-source.c
index 3c970a9..5d479ba 100644
--- a/demos/shumate-test-tile-source.c
+++ b/demos/shumate-test-tile-source.c
@@ -20,10 +20,10 @@
 
 struct _ShumateTestTileSource
 {
-  ShumateTileSource parent_instance;
+  ShumateMapSource parent_instance;
 };
 
-G_DEFINE_TYPE (ShumateTestTileSource, shumate_test_tile_source, SHUMATE_TYPE_TILE_SOURCE)
+G_DEFINE_TYPE (ShumateTestTileSource, shumate_test_tile_source, SHUMATE_TYPE_MAP_SOURCE)
 
 
 ShumateTestTileSource *
diff --git a/demos/shumate-test-tile-source.h b/demos/shumate-test-tile-source.h
index 83956b5..e1c456c 100644
--- a/demos/shumate-test-tile-source.h
+++ b/demos/shumate-test-tile-source.h
@@ -25,7 +25,7 @@ G_BEGIN_DECLS
 
 #define SHUMATE_TYPE_TEST_TILE_SOURCE (shumate_test_tile_source_get_type())
 
-G_DECLARE_FINAL_TYPE (ShumateTestTileSource, shumate_test_tile_source, SHUMATE, TEST_TILE_SOURCE, 
ShumateTileSource)
+G_DECLARE_FINAL_TYPE (ShumateTestTileSource, shumate_test_tile_source, SHUMATE, TEST_TILE_SOURCE, 
ShumateMapSource)
 
 ShumateTestTileSource *shumate_test_tile_source_new (void);
 
diff --git a/docs/reference/libshumate-docs.sgml b/docs/reference/libshumate-docs.sgml
index 493a36e..8a40530 100644
--- a/docs/reference/libshumate-docs.sgml
+++ b/docs/reference/libshumate-docs.sgml
@@ -76,7 +76,6 @@
     <xi:include href="xml/shumate-map-source-registry.xml"/>
     <chapter>
       <title>Tile Sources</title>
-      <xi:include href="xml/shumate-tile-source.xml"/>
       <xi:include href="xml/shumate-network-tile-source.xml"/>
     </chapter>
     <chapter>
diff --git a/docs/reference/libshumate-sections.txt b/docs/reference/libshumate-sections.txt
index ce98127..3d2dc76 100644
--- a/docs/reference/libshumate-sections.txt
+++ b/docs/reference/libshumate-sections.txt
@@ -4,13 +4,21 @@
 ShumateMapSource
 ShumateMapProjection
 shumate_map_source_get_id
+shumate_map_source_set_id
 shumate_map_source_get_name
+shumate_map_source_set_name
 shumate_map_source_get_license
+shumate_map_source_set_license
 shumate_map_source_get_license_uri
+shumate_map_source_set_license_uri
 shumate_map_source_get_min_zoom_level
+shumate_map_source_set_min_zoom_level
 shumate_map_source_get_max_zoom_level
+shumate_map_source_set_max_zoom_level
 shumate_map_source_get_tile_size
+shumate_map_source_set_tile_size
 shumate_map_source_get_projection
+shumate_map_source_set_projection
 shumate_map_source_get_x
 shumate_map_source_get_y
 shumate_map_source_get_longitude
@@ -392,33 +400,6 @@ ShumateLicenseClass
 ShumateLicensePrivate
 </SECTION>
 
-<SECTION>
-<FILE>shumate-tile-source</FILE>
-<TITLE>ShumateTileSource</TITLE>
-ShumateTileSource
-shumate_tile_source_set_cache
-shumate_tile_source_get_cache
-shumate_tile_source_set_id
-shumate_tile_source_set_name
-shumate_tile_source_set_license
-shumate_tile_source_set_license_uri
-shumate_tile_source_set_min_zoom_level
-shumate_tile_source_set_max_zoom_level
-shumate_tile_source_set_tile_size
-shumate_tile_source_set_projection
-<SUBSECTION Standard>
-SHUMATE_TILE_SOURCE
-SHUMATE_IS_TILE_SOURCE
-SHUMATE_TYPE_TILE_SOURCE
-shumate_tile_source_get_type
-SHUMATE_TILE_SOURCE_CLASS
-SHUMATE_IS_TILE_SOURCE_CLASS
-SHUMATE_TILE_SOURCE_GET_CLASS
-<SUBSECTION Private>
-ShumateTileSourceClass
-ShumateTileSourcePrivate
-</SECTION>
-
 <SECTION>
 <FILE>shumate-file-cache</FILE>
 <TITLE>ShumateFileCache</TITLE>
diff --git a/shumate/meson.build b/shumate/meson.build
index 80c19f4..2398ba5 100644
--- a/shumate/meson.build
+++ b/shumate/meson.build
@@ -14,7 +14,6 @@ libshumate_public_h = [
   'shumate-path-layer.h',
   'shumate-point.h',
   'shumate-scale.h',
-  'shumate-tile-source.h',
   'shumate-tile.h',
   'shumate-view.h',
   'shumate-viewport.h',
@@ -43,7 +42,6 @@ libshumate_sources = [
   'shumate-path-layer.c',
   'shumate-point.c',
   'shumate-scale.c',
-  'shumate-tile-source.c',
   'shumate-tile.c',
   'shumate-view.c',
   'shumate-viewport.c',
diff --git a/shumate/shumate-map-source.c b/shumate/shumate-map-source.c
index 0f1008a..364b2cb 100644
--- a/shumate/shumate-map-source.c
+++ b/shumate/shumate-map-source.c
@@ -31,24 +31,265 @@
 
 #include "shumate-map-source.h"
 #include "shumate-location.h"
+#include "shumate-enum-types.h"
 
 #include <math.h>
 
-G_DEFINE_ABSTRACT_TYPE (ShumateMapSource, shumate_map_source, G_TYPE_OBJECT);
+typedef struct {
+  char *id;
+  char *name;
+  char *license;
+  char *license_uri;
+  guint min_zoom_level;
+  guint max_zoom_level;
+  guint tile_size;
+  ShumateMapProjection projection;
+} ShumateMapSourcePrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ShumateMapSource, shumate_map_source, G_TYPE_OBJECT);
+
+enum
+{
+  PROP_ID = 1,
+  PROP_NAME,
+  PROP_LICENSE,
+  PROP_LICENSE_URI,
+  PROP_MIN_ZOOM_LEVEL,
+  PROP_MAX_ZOOM_LEVEL,
+  PROP_TILE_SIZE,
+  PROP_PROJECTION,
+  N_PROPERTIES
+};
+
+static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
+
+static void
+shumate_map_source_finalize (GObject *object)
+{
+  ShumateMapSource *map_source = SHUMATE_MAP_SOURCE (object);
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_clear_pointer (&priv->id, g_free);
+  g_clear_pointer (&priv->name, g_free);
+  g_clear_pointer (&priv->license, g_free);
+  g_clear_pointer (&priv->license_uri, g_free);
+
+  G_OBJECT_CLASS (shumate_map_source_parent_class)->finalize (object);
+}
+
+static void
+shumate_map_source_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  ShumateMapSource *map_source = SHUMATE_MAP_SOURCE (object);
+
+  switch (prop_id)
+    {
+      case PROP_ID:
+        g_value_set_string (value, shumate_map_source_get_id (map_source));
+        break;
+
+      case PROP_NAME:
+        g_value_set_string (value, shumate_map_source_get_name (map_source));
+        break;
+
+      case PROP_LICENSE:
+        g_value_set_string (value, shumate_map_source_get_license (map_source));
+        break;
+
+      case PROP_LICENSE_URI:
+        g_value_set_string (value, shumate_map_source_get_license_uri (map_source));
+        break;
+
+      case PROP_MIN_ZOOM_LEVEL:
+        g_value_set_uint (value, shumate_map_source_get_min_zoom_level (map_source));
+        break;
+
+      case PROP_MAX_ZOOM_LEVEL:
+        g_value_set_uint (value, shumate_map_source_get_max_zoom_level (map_source));
+        break;
+
+      case PROP_TILE_SIZE:
+        g_value_set_uint (value, shumate_map_source_get_tile_size (map_source));
+        break;
+
+      case PROP_PROJECTION:
+        g_value_set_enum (value, shumate_map_source_get_projection (map_source));
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+
+static void
+shumate_map_source_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  ShumateMapSource *map_source = SHUMATE_MAP_SOURCE (object);
+
+  switch (prop_id)
+    {
+      case PROP_ID:
+        shumate_map_source_set_id (map_source,
+                                   g_value_get_string (value));
+
+      case PROP_NAME:
+        shumate_map_source_set_name (map_source,
+                                     g_value_get_string (value));
+        break;
+
+      case PROP_LICENSE:
+        shumate_map_source_set_license (map_source,
+                                        g_value_get_string (value));
+        break;
+
+      case PROP_LICENSE_URI:
+        shumate_map_source_set_license_uri (map_source,
+                                            g_value_get_string (value));
+        break;
+
+      case PROP_MIN_ZOOM_LEVEL:
+        shumate_map_source_set_min_zoom_level (map_source,
+                                               g_value_get_uint (value));
+        break;
+
+      case PROP_MAX_ZOOM_LEVEL:
+        shumate_map_source_set_max_zoom_level (map_source,
+                                               g_value_get_uint (value));
+        break;
+
+      case PROP_TILE_SIZE:
+        shumate_map_source_set_tile_size (map_source,
+                                          g_value_get_uint (value));
+        break;
+
+      case PROP_PROJECTION:
+        shumate_map_source_set_projection (map_source,
+                                           g_value_get_enum (value));
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
 
 static void
 shumate_map_source_class_init (ShumateMapSourceClass *klass)
 {
-  klass->get_id = NULL;
-  klass->get_name = NULL;
-  klass->get_license = NULL;
-  klass->get_license_uri = NULL;
-  klass->get_min_zoom_level = NULL;
-  klass->get_max_zoom_level = NULL;
-  klass->get_tile_size = NULL;
-  klass->get_projection = NULL;
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = shumate_map_source_set_property;
+  object_class->get_property = shumate_map_source_get_property;
+  object_class->finalize = shumate_map_source_finalize;
 
   klass->fill_tile_async = NULL;
+
+  /**
+   * ShumateMapSource:id:
+   *
+   * The id of the map source
+   */
+  obj_properties[PROP_ID] =
+    g_param_spec_string ("id",
+                         "Id",
+                         "The id of the map source",
+                         NULL,
+                         G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * ShumateMapSource:name:
+   *
+   * The name of the map source
+   */
+  obj_properties[PROP_NAME] =
+    g_param_spec_string ("name",
+                         "Name",
+                         "The name of the map source",
+                         NULL,
+                         G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * ShumateMapSource:license:
+   *
+   * The usage license of the map source
+   */
+  obj_properties[PROP_LICENSE] =
+    g_param_spec_string ("license",
+                         "License",
+                         "The usage license of the map source",
+                         NULL,
+                         G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * ShumateMapSource:license-uri:
+   *
+   * The usage license's uri for more information
+   */
+  obj_properties[PROP_LICENSE_URI] =
+    g_param_spec_string ("license-uri",
+                         "License-uri",
+                         "The usage license's uri for more information",
+                         NULL,
+                         G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * ShumateMapSource:min-zoom-level:
+   *
+   * The minimum zoom level
+   */
+  obj_properties[PROP_MIN_ZOOM_LEVEL] =
+    g_param_spec_uint ("min-zoom-level",
+                       "Minimum Zoom Level",
+                       "The minimum zoom level",
+                       0, 50, 0,
+                       G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * ShumateMapSource:max-zoom-level:
+   *
+   * The maximum zoom level
+   */
+  obj_properties[PROP_MAX_ZOOM_LEVEL] =
+    g_param_spec_uint ("max-zoom-level",
+                       "Maximum Zoom Level",
+                       "The maximum zoom level",
+                       0, 50, 18,
+                       G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * ShumateMapSource:tile-size:
+   *
+   * The tile size of the map source
+   */
+  obj_properties[PROP_TILE_SIZE] =
+    g_param_spec_uint ("tile-size",
+                       "Tile Size",
+                       "The map size",
+                       0, 2048, 256,
+                       G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * ShumateMapSource:projection:
+   *
+   * The map projection of the map source
+   */
+  obj_properties[PROP_PROJECTION] =
+    g_param_spec_enum ("projection",
+                       "Projection",
+                       "The map projection",
+                       SHUMATE_TYPE_MAP_PROJECTION,
+                       SHUMATE_MAP_PROJECTION_MERCATOR,
+                       G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
G_PARAM_EXPLICIT_NOTIFY);
+
+  g_object_class_install_properties (object_class,
+                                     N_PROPERTIES,
+                                     obj_properties);
 }
 
 static double
@@ -74,11 +315,36 @@ shumate_map_source_init (ShumateMapSource *map_source)
 const char *
 shumate_map_source_get_id (ShumateMapSource *map_source)
 {
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), NULL);
 
-  return SHUMATE_MAP_SOURCE_GET_CLASS (map_source)->get_id (map_source);
+  return priv->id;
 }
 
+/**
+ * shumate_map_source_set_id:
+ * @map_source: a #ShumateMapSource
+ * @id: an id
+ *
+ * Sets the map source's id.
+ */
+void
+shumate_map_source_set_id (ShumateMapSource *map_source,
+                           const char       *id)
+{
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+  if (g_strcmp0 (priv->id, id) != 0)
+    {
+      g_free (priv->id);
+      priv->id = g_strdup (id);
+
+      g_object_notify_by_pspec (G_OBJECT (map_source), obj_properties[PROP_ID]);
+    }
+}
 
 /**
  * shumate_map_source_get_name:
@@ -91,11 +357,36 @@ shumate_map_source_get_id (ShumateMapSource *map_source)
 const char *
 shumate_map_source_get_name (ShumateMapSource *map_source)
 {
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), NULL);
 
-  return SHUMATE_MAP_SOURCE_GET_CLASS (map_source)->get_name (map_source);
+  return priv->name;
 }
 
+/**
+ * shumate_map_source_set_name:
+ * @map_source: a #ShumateMapSource
+ * @name: a name
+ *
+ * Sets the map source's name.
+ */
+void
+shumate_map_source_set_name (ShumateMapSource *map_source,
+                             const char       *name)
+{
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+  if (g_strcmp0 (priv->name, name) != 0)
+    {
+      g_free (priv->name);
+      priv->name = g_strdup (name);
+
+      g_object_notify_by_pspec (G_OBJECT (map_source), obj_properties[PROP_NAME]);
+    }
+}
 
 /**
  * shumate_map_source_get_license:
@@ -108,11 +399,36 @@ shumate_map_source_get_name (ShumateMapSource *map_source)
 const char *
 shumate_map_source_get_license (ShumateMapSource *map_source)
 {
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), NULL);
 
-  return SHUMATE_MAP_SOURCE_GET_CLASS (map_source)->get_license (map_source);
+  return priv->license;
 }
 
+/**
+ * shumate_map_source_set_license:
+ * @map_source: a #ShumateMapSource
+ * @license: the licence
+ *
+ * Sets the map source's license.
+ */
+void
+shumate_map_source_set_license (ShumateMapSource *map_source,
+                                const char       *license)
+{
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+  if (g_strcmp0 (priv->license, license) != 0)
+    {
+      g_free (priv->license);
+      priv->license = g_strdup (license);
+
+      g_object_notify_by_pspec (G_OBJECT (map_source), obj_properties[PROP_LICENSE]);
+    }
+}
 
 /**
  * shumate_map_source_get_license_uri:
@@ -125,11 +441,36 @@ shumate_map_source_get_license (ShumateMapSource *map_source)
 const char *
 shumate_map_source_get_license_uri (ShumateMapSource *map_source)
 {
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), NULL);
 
-  return SHUMATE_MAP_SOURCE_GET_CLASS (map_source)->get_license_uri (map_source);
+  return priv->license_uri;
 }
 
+/**
+ * shumate_map_source_set_license_uri:
+ * @map_source: a #ShumateMapSource
+ * @license_uri: the licence URI
+ *
+ * Sets the map source's license URI.
+ */
+void
+shumate_map_source_set_license_uri (ShumateMapSource *map_source,
+                                    const char       *license_uri)
+{
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+  if (g_strcmp0 (priv->license_uri, license_uri) != 0)
+    {
+      g_free (priv->license_uri);
+      priv->license_uri = g_strdup (license_uri);
+
+      g_object_notify_by_pspec (G_OBJECT (map_source), obj_properties[PROP_LICENSE_URI]);
+    }
+}
 
 /**
  * shumate_map_source_get_min_zoom_level:
@@ -142,11 +483,35 @@ shumate_map_source_get_license_uri (ShumateMapSource *map_source)
 guint
 shumate_map_source_get_min_zoom_level (ShumateMapSource *map_source)
 {
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), 0);
 
-  return SHUMATE_MAP_SOURCE_GET_CLASS (map_source)->get_min_zoom_level (map_source);
+  return priv->min_zoom_level;
 }
 
+/**
+ * shumate_map_source_set_min_zoom_level:
+ * @map_source: a #ShumateMapSource
+ * @zoom_level: the minimal zoom level
+ *
+ * Sets the map source's minimal zoom level.
+ */
+void
+shumate_map_source_set_min_zoom_level (ShumateMapSource *map_source,
+                                       guint             zoom_level)
+{
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+  if (priv->min_zoom_level != zoom_level)
+    {
+      priv->min_zoom_level = zoom_level;
+
+      g_object_notify_by_pspec (G_OBJECT (map_source), obj_properties[PROP_MIN_ZOOM_LEVEL]);
+    }
+}
 
 /**
  * shumate_map_source_get_max_zoom_level:
@@ -159,11 +524,35 @@ shumate_map_source_get_min_zoom_level (ShumateMapSource *map_source)
 guint
 shumate_map_source_get_max_zoom_level (ShumateMapSource *map_source)
 {
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), 0);
 
-  return SHUMATE_MAP_SOURCE_GET_CLASS (map_source)->get_max_zoom_level (map_source);
+  return priv->max_zoom_level;
 }
 
+/**
+ * shumate_map_source_set_max_zoom_level:
+ * @map_source: a #ShumateMapSource
+ * @zoom_level: the maximum zoom level
+ *
+ * Sets the map source's maximum zoom level.
+ */
+void
+shumate_map_source_set_max_zoom_level (ShumateMapSource *map_source,
+                                       guint             zoom_level)
+{
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+  if (priv->max_zoom_level != zoom_level)
+    {
+      priv->max_zoom_level = zoom_level;
+
+      g_object_notify_by_pspec (G_OBJECT (map_source), obj_properties[PROP_MAX_ZOOM_LEVEL]);
+    }
+}
 
 /**
  * shumate_map_source_get_tile_size:
@@ -176,11 +565,35 @@ shumate_map_source_get_max_zoom_level (ShumateMapSource *map_source)
 guint
 shumate_map_source_get_tile_size (ShumateMapSource *map_source)
 {
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), 0);
 
-  return SHUMATE_MAP_SOURCE_GET_CLASS (map_source)->get_tile_size (map_source);
+  return priv->tile_size;
 }
 
+/**
+ * shumate_map_source_set_tile_size:
+ * @map_source: a #ShumateMapSource
+ * @tile_size: the tile size
+ *
+ * Sets the map source's tile size.
+ */
+void
+shumate_map_source_set_tile_size (ShumateMapSource *map_source,
+                                  guint             tile_size)
+{
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+  if (priv->tile_size != tile_size)
+    {
+      priv->tile_size = tile_size;
+
+      g_object_notify_by_pspec (G_OBJECT (map_source), obj_properties[PROP_TILE_SIZE]);
+    }
+}
 
 /**
  * shumate_map_source_get_projection:
@@ -193,11 +606,81 @@ shumate_map_source_get_tile_size (ShumateMapSource *map_source)
 ShumateMapProjection
 shumate_map_source_get_projection (ShumateMapSource *map_source)
 {
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), SHUMATE_MAP_PROJECTION_MERCATOR);
 
-  return SHUMATE_MAP_SOURCE_GET_CLASS (map_source)->get_projection (map_source);
+  return priv->projection;
+}
+
+/**
+ * shumate_map_source_set_projection:
+ * @map_source: a #ShumateMapSource
+ * @projection: a #ShumateMapProjection
+ *
+ * Sets the map source's projection.
+ */
+void
+shumate_map_source_set_projection (ShumateMapSource     *map_source,
+                                   ShumateMapProjection  projection)
+{
+  ShumateMapSourcePrivate *priv = shumate_map_source_get_instance_private (map_source);
+
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+  if (priv->projection != projection)
+    {
+      priv->projection = projection;
+
+      g_object_notify_by_pspec (G_OBJECT (map_source), obj_properties[PROP_PROJECTION]);
+    }
+}
+
+/**
+ * shumate_map_source_fill_tile_async:
+ * @self: a #ShumateMapSource
+ * @tile: a #ShumateTile
+ * @cancellable: (nullable): a #GCancellable
+ * @callback: a #GAsyncReadyCallback to execute upon completion
+ * @user_data: closure data for @callback
+ *
+ * Asynchronous version of shumate_map_source_fill_tile().
+ */
+void
+shumate_map_source_fill_tile_async (ShumateMapSource    *self,
+                                    ShumateTile         *tile,
+                                    GCancellable        *cancellable,
+                                    GAsyncReadyCallback  callback,
+                                    gpointer             user_data)
+{
+  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (self));
+  g_return_if_fail (SHUMATE_IS_TILE (tile));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  return SHUMATE_MAP_SOURCE_GET_CLASS (self)->fill_tile_async (self, tile, cancellable, callback, user_data);
 }
 
+/**
+ * shumate_map_source_fill_tile_finish:
+ * @self: a #ShumateMapSource
+ * @result: a #GAsyncResult provided to callback
+ * @error: a location for a #GError, or %NULL
+ *
+ * Gets the success value of a completed shumate_map_source_fill_tile_async()
+ * operation.
+ *
+ * Returns: %TRUE if the tile was filled with valid data, otherwise %FALSE
+ */
+gboolean
+shumate_map_source_fill_tile_finish (ShumateMapSource  *self,
+                                     GAsyncResult      *result,
+                                     GError           **error)
+{
+  g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (self), FALSE);
+  g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
+
+  return g_task_propagate_boolean (G_TASK (result), error);
+}
 
 /**
  * shumate_map_source_get_x:
@@ -212,8 +695,8 @@ shumate_map_source_get_projection (ShumateMapSource *map_source)
  */
 double
 shumate_map_source_get_x (ShumateMapSource *map_source,
-    double zoom_level,
-    double longitude)
+                          double            zoom_level,
+                          double            longitude)
 {
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), 0.0);
 
@@ -223,7 +706,6 @@ shumate_map_source_get_x (ShumateMapSource *map_source,
   return ((longitude + 180.0) / 360.0) * map_size (map_source, zoom_level);
 }
 
-
 /**
  * shumate_map_source_get_y:
  * @map_source: a #ShumateMapSource
@@ -237,8 +719,8 @@ shumate_map_source_get_x (ShumateMapSource *map_source,
  */
 double
 shumate_map_source_get_y (ShumateMapSource *map_source,
-    double zoom_level,
-    double latitude)
+                          double            zoom_level,
+                          double            latitude)
 {
   double sin_latitude;
 
@@ -250,7 +732,6 @@ shumate_map_source_get_y (ShumateMapSource *map_source,
   return (0.5 - log ((1.0 + sin_latitude) / (1.0 - sin_latitude)) / (4.0 * G_PI)) * map_size (map_source, 
zoom_level);
 }
 
-
 /**
  * shumate_map_source_get_longitude:
  * @map_source: a #ShumateMapSource
@@ -264,8 +745,8 @@ shumate_map_source_get_y (ShumateMapSource *map_source,
  */
 double
 shumate_map_source_get_longitude (ShumateMapSource *map_source,
-    double zoom_level,
-    double x)
+                                  double            zoom_level,
+                                  double            x)
 {
   double longitude;
 
@@ -277,7 +758,6 @@ shumate_map_source_get_longitude (ShumateMapSource *map_source,
   return CLAMP (longitude, SHUMATE_MIN_LONGITUDE, SHUMATE_MAX_LONGITUDE);
 }
 
-
 /**
  * shumate_map_source_get_latitude:
  * @map_source: a #ShumateMapSource
@@ -291,8 +771,8 @@ shumate_map_source_get_longitude (ShumateMapSource *map_source,
  */
 double
 shumate_map_source_get_latitude (ShumateMapSource *map_source,
-    double zoom_level,
-    double y)
+                                 double            zoom_level,
+                                 double            y)
 {
   double latitude, dy;
 
@@ -304,7 +784,6 @@ shumate_map_source_get_latitude (ShumateMapSource *map_source,
   return CLAMP (latitude, SHUMATE_MIN_LATITUDE, SHUMATE_MAX_LATITUDE);
 }
 
-
 /**
  * shumate_map_source_get_row_count:
  * @map_source: a #ShumateMapSource
@@ -316,14 +795,13 @@ shumate_map_source_get_latitude (ShumateMapSource *map_source,
  */
 guint
 shumate_map_source_get_row_count (ShumateMapSource *map_source,
-    guint zoom_level)
+                                  guint             zoom_level)
 {
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), 0);
   /* FIXME: support other projections */
   return (zoom_level != 0) ? 2 << (zoom_level - 1) : 1;
 }
 
-
 /**
  * shumate_map_source_get_column_count:
  * @map_source: a #ShumateMapSource
@@ -336,14 +814,13 @@ shumate_map_source_get_row_count (ShumateMapSource *map_source,
  */
 guint
 shumate_map_source_get_column_count (ShumateMapSource *map_source,
-    guint zoom_level)
+                                     guint             zoom_level)
 {
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), 0);
   /* FIXME: support other projections */
   return (zoom_level != 0) ? 2 << (zoom_level - 1) : 1;
 }
 
-
 #define EARTH_RADIUS 6378137.0 /* meters, Equatorial radius */
 
 /**
@@ -358,10 +835,10 @@ shumate_map_source_get_column_count (ShumateMapSource *map_source,
  * Returns: the meters per pixel
  */
 double
-shumate_map_source_get_meters_per_pixel (ShumateMapSource *map_source,
-    double zoom_level,
-    double latitude,
-    G_GNUC_UNUSED double longitude)
+shumate_map_source_get_meters_per_pixel (ShumateMapSource    *map_source,
+                                         double               zoom_level,
+                                         double               latitude,
+                                         G_GNUC_UNUSED double longitude)
 {
   g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (map_source), 0.0);
 
@@ -375,50 +852,3 @@ shumate_map_source_get_meters_per_pixel (ShumateMapSource *map_source,
   /* FIXME: support other projections */
   return 2.0 * G_PI * EARTH_RADIUS * sin (G_PI / 2.0 - G_PI / 180.0 * latitude) / map_size (map_source, 
zoom_level);
 }
-
-
-/**
- * shumate_map_source_fill_tile_async:
- * @self: a #ShumateMapSource
- * @tile: a #ShumateTile
- * @cancellable: (nullable): a #GCancellable
- * @callback: a #GAsyncReadyCallback to execute upon completion
- * @user_data: closure data for @callback
- *
- * Asynchronous version of shumate_map_source_fill_tile().
- */
-void
-shumate_map_source_fill_tile_async (ShumateMapSource *self,
-                                    ShumateTile *tile,
-                                    GCancellable *cancellable,
-                                    GAsyncReadyCallback callback,
-                                    gpointer user_data)
-{
-  g_return_if_fail (SHUMATE_IS_MAP_SOURCE (self));
-  g_return_if_fail (SHUMATE_IS_TILE (tile));
-  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
-
-  return SHUMATE_MAP_SOURCE_GET_CLASS (self)->fill_tile_async (self, tile, cancellable, callback, user_data);
-}
-
-/**
- * shumate_map_source_fill_tile_finish:
- * @self: a #ShumateMapSource
- * @result: a #GAsyncResult provided to callback
- * @error: a location for a #GError, or %NULL
- *
- * Gets the success value of a completed shumate_map_source_fill_tile_async()
- * operation.
- *
- * Returns: %TRUE if the tile was filled with valid data, otherwise %FALSE
- */
-gboolean
-shumate_map_source_fill_tile_finish (ShumateMapSource *self,
-                                     GAsyncResult *result,
-                                     GError **error)
-{
-  g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE (self), FALSE);
-  g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
-
-  return g_task_propagate_boolean (G_TASK (result), error);
-}
diff --git a/shumate/shumate-map-source.h b/shumate/shumate-map-source.h
index 39424e3..c359f0c 100644
--- a/shumate/shumate-map-source.h
+++ b/shumate/shumate-map-source.h
@@ -53,15 +53,6 @@ struct _ShumateMapSourceClass
 {
   GObjectClass parent_class;
 
-  const char * (*get_id)(ShumateMapSource *map_source);
-  const char * (*get_name)(ShumateMapSource *map_source);
-  const char * (*get_license)(ShumateMapSource *map_source);
-  const char * (*get_license_uri)(ShumateMapSource *map_source);
-  guint (*get_min_zoom_level)(ShumateMapSource *map_source);
-  guint (*get_max_zoom_level)(ShumateMapSource *map_source);
-  guint (*get_tile_size)(ShumateMapSource *map_source);
-  ShumateMapProjection (*get_projection)(ShumateMapSource *map_source);
-
   void (*fill_tile_async)  (ShumateMapSource     *self,
                             ShumateTile          *tile,
                             GCancellable         *cancellable,
@@ -70,34 +61,50 @@ struct _ShumateMapSourceClass
 };
 
 const char *shumate_map_source_get_id (ShumateMapSource *map_source);
+void shumate_map_source_set_id (ShumateMapSource *map_source,
+                                const char       *id);
 const char *shumate_map_source_get_name (ShumateMapSource *map_source);
+void shumate_map_source_set_name (ShumateMapSource *map_source,
+                                  const char       *name);
 const char *shumate_map_source_get_license (ShumateMapSource *map_source);
+void shumate_map_source_set_license (ShumateMapSource *map_source,
+                                     const char       *license);
 const char *shumate_map_source_get_license_uri (ShumateMapSource *map_source);
+void shumate_map_source_set_license_uri (ShumateMapSource *map_source,
+                                         const char       *license_uri);
 guint shumate_map_source_get_min_zoom_level (ShumateMapSource *map_source);
+void shumate_map_source_set_min_zoom_level (ShumateMapSource *map_source,
+                                            guint             zoom_level);
 guint shumate_map_source_get_max_zoom_level (ShumateMapSource *map_source);
+void shumate_map_source_set_max_zoom_level (ShumateMapSource *map_source,
+                                            guint             zoom_level);
 guint shumate_map_source_get_tile_size (ShumateMapSource *map_source);
+void shumate_map_source_set_tile_size (ShumateMapSource *map_source,
+                                       guint             tile_size);
 ShumateMapProjection shumate_map_source_get_projection (ShumateMapSource *map_source);
+void shumate_map_source_set_projection (ShumateMapSource     *map_source,
+                                        ShumateMapProjection  projection);
 
 double shumate_map_source_get_x (ShumateMapSource *map_source,
-    double zoom_level,
-    double longitude);
+                                 double            zoom_level,
+                                 double            longitude);
 double shumate_map_source_get_y (ShumateMapSource *map_source,
-    double zoom_level,
-    double latitude);
+                                 double            zoom_level,
+                                 double            latitude);
 double shumate_map_source_get_longitude (ShumateMapSource *map_source,
-    double zoom_level,
-    double x);
+                                         double            zoom_level,
+                                         double            x);
 double shumate_map_source_get_latitude (ShumateMapSource *map_source,
-    double zoom_level,
-    double y);
+                                        double            zoom_level,
+                                        double            y);
 guint shumate_map_source_get_row_count (ShumateMapSource *map_source,
-    guint zoom_level);
+                                        guint             zoom_level);
 guint shumate_map_source_get_column_count (ShumateMapSource *map_source,
-    guint zoom_level);
+                                           guint             zoom_level);
 double shumate_map_source_get_meters_per_pixel (ShumateMapSource *map_source,
-    double zoom_level,
-    double latitude,
-    double longitude);
+                                                double            zoom_level,
+                                                double            latitude,
+                                                double            longitude);
 
 void shumate_map_source_fill_tile_async (ShumateMapSource    *self,
                                          ShumateTile         *tile,
diff --git a/shumate/shumate-network-tile-source.c b/shumate/shumate-network-tile-source.c
index d1a1b94..41181f9 100644
--- a/shumate/shumate-network-tile-source.c
+++ b/shumate/shumate-network-tile-source.c
@@ -71,7 +71,7 @@ typedef struct
   ShumateFileCache *file_cache;
 } ShumateNetworkTileSourcePrivate;
 
-G_DEFINE_TYPE_WITH_PRIVATE (ShumateNetworkTileSource, shumate_network_tile_source, SHUMATE_TYPE_TILE_SOURCE);
+G_DEFINE_TYPE_WITH_PRIVATE (ShumateNetworkTileSource, shumate_network_tile_source, SHUMATE_TYPE_MAP_SOURCE);
 
 /* The osm.org tile set require us to use no more than 2 simultaneous
  * connections so let that be the default.
diff --git a/shumate/shumate-network-tile-source.h b/shumate/shumate-network-tile-source.h
index 76e3fe9..94a0f3a 100644
--- a/shumate/shumate-network-tile-source.h
+++ b/shumate/shumate-network-tile-source.h
@@ -25,7 +25,7 @@
 #ifndef _SHUMATE_NETWORK_TILE_SOURCE_H_
 #define _SHUMATE_NETWORK_TILE_SOURCE_H_
 
-#include <shumate/shumate-tile-source.h>
+#include <shumate/shumate-map-source.h>
 
 G_BEGIN_DECLS
 
@@ -60,7 +60,7 @@ typedef enum {
 
 
 #define SHUMATE_TYPE_NETWORK_TILE_SOURCE shumate_network_tile_source_get_type ()
-G_DECLARE_DERIVABLE_TYPE (ShumateNetworkTileSource, shumate_network_tile_source, SHUMATE, 
NETWORK_TILE_SOURCE, ShumateTileSource)
+G_DECLARE_DERIVABLE_TYPE (ShumateNetworkTileSource, shumate_network_tile_source, SHUMATE, 
NETWORK_TILE_SOURCE, ShumateMapSource)
 
 /**
  * ShumateNetworkTileSource:
@@ -71,7 +71,7 @@ G_DECLARE_DERIVABLE_TYPE (ShumateNetworkTileSource, shumate_network_tile_source,
 
 struct _ShumateNetworkTileSourceClass
 {
-  ShumateTileSourceClass parent_class;
+  ShumateMapSourceClass parent_class;
 };
 
 ShumateNetworkTileSource *shumate_network_tile_source_new_full (const char *id,
diff --git a/shumate/shumate.h b/shumate/shumate.h
index 591d40c..47c4aea 100644
--- a/shumate/shumate.h
+++ b/shumate/shumate.h
@@ -39,12 +39,8 @@
 #include "shumate/shumate-view.h"
 #include "shumate/shumate-viewport.h"
 #include "shumate/shumate-scale.h"
-
 #include "shumate/shumate-map-source.h"
-#include "shumate/shumate-tile-source.h"
-
 #include "shumate/shumate-map-source-registry.h"
-
 #include "shumate/shumate-network-tile-source.h"
 
 #include "shumate/shumate-memory-cache.h"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]