[libshumate] Revert "license: Get license info from the map"



commit ad04824c9b2738db75d9c39b1acf9113d15257bc
Author: James Westman <james jwestman net>
Date:   Tue Dec 21 12:02:25 2021 -0600

    Revert "license: Get license info from the map"
    
    This reverts commit ec6552681e809e06ac4d88ff0df6ee6c9d10b5c1.

 demos/shumate-demo-window.c  | 11 +++++
 demos/shumate-demo-window.ui |  1 -
 shumate/shumate-layer.c      | 72 --------------------------------
 shumate/shumate-layer.h      |  6 ---
 shumate/shumate-license.c    | 99 +++++++++++---------------------------------
 shumate/shumate-license.h    | 10 +++--
 shumate/shumate-map-layer.c  | 26 ------------
 shumate/shumate-map.c        | 43 -------------------
 shumate/shumate-map.h        |  3 --
 tests/meson.build            |  1 -
 10 files changed, 42 insertions(+), 230 deletions(-)
---
diff --git a/demos/shumate-demo-window.c b/demos/shumate-demo-window.c
index 051c640..77638bd 100644
--- a/demos/shumate-demo-window.c
+++ b/demos/shumate-demo-window.c
@@ -35,6 +35,8 @@ struct _ShumateDemoWindow
   ShumateMapLayer *tile_layer;
   ShumateMarkerLayer *marker_layer;
   ShumatePathLayer *path_layer;
+
+  ShumateMapSource *current_source;
 };
 
 G_DEFINE_TYPE (ShumateDemoWindow, shumate_demo_window, GTK_TYPE_APPLICATION_WINDOW)
@@ -69,6 +71,12 @@ set_map_source (ShumateDemoWindow *self, ShumateMapSource *new_source)
   ShumateViewport *viewport = shumate_map_get_viewport (self->map);
   ShumateMapLayer *tile_layer;
 
+  if (self->current_source) {
+    shumate_license_remove_map_source (self->license, self->current_source);
+  }
+
+  g_set_object (&self->current_source, new_source);
+
   shumate_viewport_set_reference_map_source (viewport, new_source);
   shumate_map_set_map_source (self->map, new_source);
 
@@ -78,6 +86,8 @@ set_map_source (ShumateDemoWindow *self, ShumateMapSource *new_source)
     shumate_map_remove_layer (self->map, SHUMATE_LAYER (self->tile_layer));
   }
   self->tile_layer = tile_layer;
+
+  shumate_license_append_map_source (self->license, new_source);
 }
 
 static void
@@ -92,6 +102,7 @@ shumate_demo_window_dispose (GObject *object)
 {
   ShumateDemoWindow *self = SHUMATE_DEMO_WINDOW (object);
 
+  g_clear_object (&self->current_source);
   g_clear_object (&self->registry);
 
   G_OBJECT_CLASS (shumate_demo_window_parent_class)->dispose (object);
diff --git a/demos/shumate-demo-window.ui b/demos/shumate-demo-window.ui
index c326e3d..d2ee6d0 100644
--- a/demos/shumate-demo-window.ui
+++ b/demos/shumate-demo-window.ui
@@ -41,7 +41,6 @@
             <child>
               <object class="ShumateLicense" id="license">
                 <property name="halign">end</property>
-                <property name="map">map</property>
               </object>
             </child>
           </object>
diff --git a/shumate/shumate-layer.c b/shumate/shumate-layer.c
index fbf2820..c2122c0 100644
--- a/shumate/shumate-layer.c
+++ b/shumate/shumate-layer.c
@@ -33,8 +33,6 @@
 enum
 {
   PROP_VIEWPORT = 1,
-  PROP_LICENSE,
-  PROP_LICENSE_URI,
   N_PROPERTIES
 };
 
@@ -82,14 +80,6 @@ shumate_layer_get_property (GObject    *object,
       g_value_set_object (value, priv->viewport);
       break;
 
-    case PROP_LICENSE:
-      g_value_set_string (value, shumate_layer_get_license (self));
-      break;
-
-    case PROP_LICENSE_URI:
-      g_value_set_string (value, shumate_layer_get_license (self));
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -117,33 +107,17 @@ shumate_layer_constructed (GObject *object)
   G_OBJECT_CLASS (shumate_layer_parent_class)->constructed (object);
 }
 
-static const char *
-shumate_layer_real_get_license (ShumateLayer *self)
-{
-  return NULL;
-}
-
-static const char *
-shumate_layer_real_get_license_uri (ShumateLayer *self)
-{
-  return NULL;
-}
-
 static void
 shumate_layer_class_init (ShumateLayerClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  ShumateLayerClass *layer_class = SHUMATE_LAYER_CLASS (klass);
 
   object_class->set_property = shumate_layer_set_property;
   object_class->get_property = shumate_layer_get_property;
   object_class->dispose = shumate_layer_dispose;
   object_class->constructed = shumate_layer_constructed;
 
-  layer_class->get_license = shumate_layer_real_get_license;
-  layer_class->get_license_uri = shumate_layer_real_get_license_uri;
-
   obj_properties[PROP_VIEWPORT] =
     g_param_spec_object ("viewport",
                          "Viewport",
@@ -151,20 +125,6 @@ shumate_layer_class_init (ShumateLayerClass *klass)
                          SHUMATE_TYPE_VIEWPORT,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
 
-  obj_properties[PROP_LICENSE] =
-    g_param_spec_string ("license",
-                         "License",
-                         "License",
-                         NULL,
-                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
-  obj_properties[PROP_LICENSE_URI] =
-    g_param_spec_string ("license-uri",
-                         "License URI",
-                         "License URI",
-                         NULL,
-                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
   g_object_class_install_properties (object_class,
                                      N_PROPERTIES,
                                      obj_properties);
@@ -198,35 +158,3 @@ shumate_layer_get_viewport (ShumateLayer *self)
 
   return priv->viewport;
 }
-
-
-/**
- * shumate_layer_get_license:
- * @self: a [class@Layer]
- *
- * Gets the license text to show on the map for this layer.
- *
- * Returns: (nullable): the license text
- */
-const char *
-shumate_layer_get_license (ShumateLayer *self)
-{
-  g_return_val_if_fail (SHUMATE_IS_LAYER (self), NULL);
-  return SHUMATE_LAYER_GET_CLASS (self)->get_license (self);
-}
-
-
-/**
- * shumate_layer_get_license_uri:
- * @self: a [class@Layer]
- *
- * Gets a link to view more information about the layer's license, if available.
- *
- * Returns: (nullable): a URI
- */
-const char *
-shumate_layer_get_license_uri (ShumateLayer *self)
-{
-  g_return_val_if_fail (SHUMATE_IS_LAYER (self), NULL);
-  return SHUMATE_LAYER_GET_CLASS (self)->get_license_uri (self);
-}
diff --git a/shumate/shumate-layer.h b/shumate/shumate-layer.h
index 7b87b7c..ff699e6 100644
--- a/shumate/shumate-layer.h
+++ b/shumate/shumate-layer.h
@@ -35,16 +35,10 @@ G_DECLARE_DERIVABLE_TYPE (ShumateLayer, shumate_layer, SHUMATE, LAYER, GtkWidget
 struct _ShumateLayerClass
 {
   GtkWidgetClass parent_class;
-
-  const char *(*get_license)     (ShumateLayer *self);
-  const char *(*get_license_uri) (ShumateLayer *self);
 };
 
 ShumateViewport *shumate_layer_get_viewport (ShumateLayer *self);
 
-const char *shumate_layer_get_license     (ShumateLayer *self);
-const char *shumate_layer_get_license_uri (ShumateLayer *self);
-
 G_END_DECLS
 
 #endif /* __SHUMATE_LAYER_H__ */
diff --git a/shumate/shumate-license.c b/shumate/shumate-license.c
index 7eaafd9..4db7b8c 100644
--- a/shumate/shumate-license.c
+++ b/shumate/shumate-license.c
@@ -29,7 +29,6 @@ enum
 {
   PROP_EXTRA_TEXT = 1,
   PROP_XALIGN,
-  PROP_MAP,
   N_PROPERTIES,
 };
 
@@ -41,8 +40,7 @@ struct _ShumateLicense
 
   GtkWidget *extra_text_label;
   GtkWidget *license_label;
-
-  ShumateMap *map;
+  GPtrArray *map_sources;
 };
 
 G_DEFINE_TYPE (ShumateLicense, shumate_license, GTK_TYPE_WIDGET);
@@ -65,10 +63,6 @@ shumate_license_get_property (GObject    *object,
       g_value_set_float (value, gtk_label_get_xalign (GTK_LABEL (self->license_label)));
       break;
 
-    case PROP_MAP:
-      g_value_set_object (value, shumate_license_get_map (self));
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -93,10 +87,6 @@ shumate_license_set_property (GObject      *object,
       shumate_license_set_xalign (license, g_value_get_float (value));
       break;
 
-    case PROP_MAP:
-      shumate_license_set_map (license, g_value_get_object (value));
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -106,20 +96,15 @@ static void
 shumate_license_sources_changed (ShumateLicense *self)
 {
   g_autoptr(GString) license_str = NULL;
-  g_autoptr(GList) layers = NULL;
-  GList *l;
+  guint i;
 
   g_assert (SHUMATE_IS_LICENSE (self));
 
   license_str = g_string_new (NULL);
-
-  if (self->map)
-    layers = shumate_map_get_layers (self->map);
-
-  for (l = layers; l != NULL; l = l->next)
+  for (i = 0; i < self->map_sources->len; i++)
     {
-      ShumateLayer *layer = SHUMATE_LAYER (l->data);
-      const char *license = shumate_layer_get_license (layer);
+      ShumateMapSource *map_source = g_ptr_array_index (self->map_sources, i);
+      const char *license = shumate_map_source_get_license (map_source);
 
       if (license == NULL)
         continue;
@@ -138,9 +123,9 @@ shumate_license_dispose (GObject *object)
 {
   ShumateLicense *self = SHUMATE_LICENSE (object);
 
+  g_clear_pointer (&self->map_sources, g_ptr_array_unref);
   g_clear_pointer (&self->extra_text_label, gtk_widget_unparent);
   g_clear_pointer (&self->license_label, gtk_widget_unparent);
-  g_clear_object (&self->map);
 
   G_OBJECT_CLASS (shumate_license_parent_class)->dispose (object);
 }
@@ -182,18 +167,6 @@ shumate_license_class_init (ShumateLicenseClass *klass)
                         0.0, 1.0, 0.5,
                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
-  /**
-   * ShumateLicense:map:
-   *
-   * The map to show license information for
-   */
-  obj_properties[PROP_MAP] =
-    g_param_spec_object ("map",
-                         "Map",
-                         "Map",
-                         SHUMATE_TYPE_MAP,
-                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
-
   g_object_class_install_properties (object_class, N_PROPERTIES, obj_properties);
 
   gtk_widget_class_set_css_name (widget_class, g_intern_static_string ("map-license"));
@@ -214,6 +187,7 @@ shumate_license_class_init (ShumateLicenseClass *klass)
 static void
 shumate_license_init (ShumateLicense *self)
 {
+  self->map_sources = g_ptr_array_new_with_free_func (g_object_unref);
   self->license_label = gtk_label_new (NULL);
   self->extra_text_label = gtk_label_new (NULL);
 
@@ -322,55 +296,32 @@ shumate_license_get_xalign (ShumateLicense *license)
   return gtk_label_get_xalign (GTK_LABEL (license->license_label));
 }
 
-/**
- * shumate_license_get_map:
- * @self: a [class@License]
- *
- * Gets the map that the license is showing information for.
- *
- * Returns: (nullable)(transfer none): the map
- */
-ShumateMap *
-shumate_license_get_map (ShumateLicense *self)
+void
+shumate_license_append_map_source (ShumateLicense   *license,
+                                   ShumateMapSource *map_source)
 {
-  g_return_val_if_fail (SHUMATE_IS_LICENSE (self), NULL);
+  g_return_if_fail (SHUMATE_IS_LICENSE (license));
 
-  return self->map;
+  g_ptr_array_add (license->map_sources, g_object_ref (map_source));
+  shumate_license_sources_changed (license);
 }
 
-static void
-on_layers_changed (ShumateLicense *self)
+void
+shumate_license_prepend_map_source (ShumateLicense   *license,
+                                    ShumateMapSource *map_source)
 {
-  shumate_license_sources_changed (self);
+  g_return_if_fail (SHUMATE_IS_LICENSE (license));
+
+  g_ptr_array_insert (license->map_sources, 0, g_object_ref (map_source));
+  shumate_license_sources_changed (license);
 }
 
-/**
- * shumate_license_set_map:
- * @self: a [class@License]
- * @map: (nullable): a [class@Map]
- *
- * Sets a map widget to show license information for. The license text will be
- * collected from the map's layers, if they provide it.
- */
 void
-shumate_license_set_map (ShumateLicense *self,
-                         ShumateMap     *map)
+shumate_license_remove_map_source (ShumateLicense   *license,
+                                   ShumateMapSource *map_source)
 {
-  g_return_if_fail (SHUMATE_IS_LICENSE (self));
-  g_return_if_fail (map == NULL || SHUMATE_IS_MAP (map));
-
-  if (self->map == map)
-    return;
-
-  if (self->map != NULL)
-    g_signal_handlers_disconnect_by_data (self->map, self);
-
-  g_set_object (&self->map, map);
-
-  if (self->map != NULL)
-    g_signal_connect_object (self->map, "layers-changed", (GCallback)on_layers_changed, G_OBJECT (self), 
G_CONNECT_SWAPPED);
-
-  shumate_license_sources_changed (self);
+  g_return_if_fail (SHUMATE_IS_LICENSE (license));
 
-  g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_MAP]);
+  g_ptr_array_remove (license->map_sources, map_source);
+  shumate_license_sources_changed (license);
 }
diff --git a/shumate/shumate-license.h b/shumate/shumate-license.h
index 7d59e0a..d28fc3e 100644
--- a/shumate/shumate-license.h
+++ b/shumate/shumate-license.h
@@ -25,7 +25,6 @@
 #define SHUMATE_LICENSE_H
 
 #include <shumate/shumate-map-source.h>
-#include <shumate/shumate-map.h>
 
 #include <glib-object.h>
 #include <gtk/gtk.h>
@@ -45,9 +44,12 @@ void shumate_license_set_xalign (ShumateLicense *license,
                                  float           xalign);
 float shumate_license_get_xalign (ShumateLicense *license);
 
-ShumateMap *shumate_license_get_map (ShumateLicense *self);
-void        shumate_license_set_map (ShumateLicense *self,
-                                     ShumateMap     *map);
+void shumate_license_append_map_source (ShumateLicense   *license,
+                                        ShumateMapSource *map_source);
+void shumate_license_prepend_map_source (ShumateLicense   *license,
+                                         ShumateMapSource *map_source);
+void shumate_license_remove_map_source (ShumateLicense   *license,
+                                        ShumateMapSource *map_source);
 
 G_END_DECLS
 
diff --git a/shumate/shumate-map-layer.c b/shumate/shumate-map-layer.c
index 0e86abe..b88c813 100644
--- a/shumate/shumate-map-layer.c
+++ b/shumate/shumate-map-layer.c
@@ -541,34 +541,11 @@ shumate_map_layer_snapshot (GtkWidget *widget, GtkSnapshot *snapshot)
   GTK_WIDGET_CLASS (shumate_map_layer_parent_class)->snapshot (widget, snapshot);
 }
 
-static const char *
-shumate_map_layer_get_license (ShumateLayer *layer)
-{
-  ShumateMapLayer *self = SHUMATE_MAP_LAYER (layer);
-
-  if (self->map_source == NULL)
-    return NULL;
-
-  return shumate_map_source_get_license (self->map_source);
-}
-
-static const char *
-shumate_map_layer_get_license_uri (ShumateLayer *layer)
-{
-  ShumateMapLayer *self = SHUMATE_MAP_LAYER (layer);
-
-  if (self->map_source == NULL)
-    return NULL;
-
-  return shumate_map_source_get_license_uri (self->map_source);
-}
-
 static void
 shumate_map_layer_class_init (ShumateMapLayerClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  ShumateLayerClass *layer_class = SHUMATE_LAYER_CLASS (klass);
 
   object_class->set_property = shumate_map_layer_set_property;
   object_class->get_property = shumate_map_layer_get_property;
@@ -579,9 +556,6 @@ shumate_map_layer_class_init (ShumateMapLayerClass *klass)
   widget_class->snapshot = shumate_map_layer_snapshot;
   widget_class->measure = shumate_map_layer_measure;
 
-  layer_class->get_license = shumate_map_layer_get_license;
-  layer_class->get_license_uri = shumate_map_layer_get_license_uri;
-
   obj_properties[PROP_MAP_SOURCE] =
     g_param_spec_object ("map-source",
                          "Map Source",
diff --git a/shumate/shumate-map.c b/shumate/shumate-map.c
index dd9b27a..deb57c2 100644
--- a/shumate/shumate-map.c
+++ b/shumate/shumate-map.c
@@ -63,7 +63,6 @@ enum
 {
   /* normal signals */
   ANIMATION_COMPLETED,
-  LAYERS_CHANGED,
   LAST_SIGNAL
 };
 
@@ -814,20 +813,6 @@ shumate_map_class_init (ShumateMapClass *klass)
                   G_TYPE_NONE,
                   0);
 
-  /**
-   * ShumateMap::layers-changed:
-   *
-   * Emitted when the list of layers changes.
-   */
-  signals[LAYERS_CHANGED] =
-    g_signal_new ("layers-changed",
-                  G_OBJECT_CLASS_TYPE (object_class),
-                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
-                  0, NULL, NULL,
-                  NULL,
-                  G_TYPE_NONE,
-                  0);
-
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
   gtk_widget_class_set_css_name (widget_class, g_intern_static_string ("map-view"));
 
@@ -1072,7 +1057,6 @@ shumate_map_add_layer (ShumateMap   *self,
   g_return_if_fail (SHUMATE_IS_LAYER (layer));
 
   gtk_widget_insert_before (GTK_WIDGET (layer), GTK_WIDGET (self), NULL);
-  g_signal_emit (G_OBJECT (self), signals[LAYERS_CHANGED], 0);
 }
 
 
@@ -1096,7 +1080,6 @@ shumate_map_insert_layer_behind (ShumateMap   *self,
   g_return_if_fail (next_sibling == NULL || gtk_widget_get_parent (GTK_WIDGET (next_sibling)) == GTK_WIDGET 
(self));
 
   gtk_widget_insert_before (GTK_WIDGET (layer), GTK_WIDGET (self), GTK_WIDGET (next_sibling));
-  g_signal_emit (G_OBJECT (self), signals[LAYERS_CHANGED], 0);
 }
 
 
@@ -1120,7 +1103,6 @@ shumate_map_insert_layer_above (ShumateMap   *self,
   g_return_if_fail (next_sibling == NULL || gtk_widget_get_parent (GTK_WIDGET (next_sibling)) == GTK_WIDGET 
(self));
 
   gtk_widget_insert_after (GTK_WIDGET (layer), GTK_WIDGET (self), GTK_WIDGET (next_sibling));
-  g_signal_emit (G_OBJECT (self), signals[LAYERS_CHANGED], 0);
 }
 
 
@@ -1145,31 +1127,6 @@ shumate_map_remove_layer (ShumateMap  *self,
     }
 
   gtk_widget_unparent (GTK_WIDGET (layer));
-  g_signal_emit (G_OBJECT (self), signals[LAYERS_CHANGED], 0);
-}
-
-/**
- * shumate_map_get_layers:
- * @self: a [class@Map]
- *
- * Gets a list of the layers in the map.
- *
- * Returns: (transfer container)(element-type ShumateLayer): a list of layers in the map
- */
-GList *
-shumate_map_get_layers (ShumateMap *self)
-{
-  GList *list = NULL;
-  GtkWidget *child;
-
-  g_return_val_if_fail (SHUMATE_IS_MAP (self), NULL);
-
-  for (child = gtk_widget_get_first_child (GTK_WIDGET (self));
-       child != NULL;
-       child = gtk_widget_get_next_sibling (child))
-    list = g_list_prepend (list, child);
-
-  return g_list_reverse (list);
 }
 
 /**
diff --git a/shumate/shumate-map.h b/shumate/shumate-map.h
index 12b0a73..28f111c 100644
--- a/shumate/shumate-map.h
+++ b/shumate/shumate-map.h
@@ -72,9 +72,6 @@ void shumate_map_insert_layer_behind (ShumateMap   *self,
 void shumate_map_insert_layer_above (ShumateMap   *self,
                                      ShumateLayer *layer,
                                      ShumateLayer *next_sibling);
-
-GList *shumate_map_get_layers (ShumateMap *self);
-
 gboolean shumate_map_get_zoom_on_double_click (ShumateMap *self);
 gboolean shumate_map_get_animate_zoom (ShumateMap *self);
 ShumateState shumate_map_get_state (ShumateMap *self);
diff --git a/tests/meson.build b/tests/meson.build
index 24a307d..d9a0f20 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -9,7 +9,6 @@ test_env = [
 tests = [
   'coordinate',
   'file-cache',
-  'license',
   'marker',
   'map',
   'marker-layer',


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