[libshumate] license: Get license info from the map
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libshumate] license: Get license info from the map
- Date: Mon, 1 Nov 2021 22:21:04 +0000 (UTC)
commit ec6552681e809e06ac4d88ff0df6ee6c9d10b5c1
Author: James Westman <james jwestman net>
Date: Wed Oct 13 11:58:42 2021 -0500
license: Get license info from the map
Removed the {append|prepend|remove}_map_source methods from
ShumateLicense and replaced them with a `map` property. The license
monitors changes to the map layers through a new `layers-changed`
signal and updates the license text automatically.
This also required adding `license` and `license-uri` properties to
ShumateLayer. Currently only ShumateMapLayer implements them and they
are taken from the map source.
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/license.c | 104 +++++++++++++++++++++++++++++++++++++++++++
tests/meson.build | 1 +
11 files changed, 334 insertions(+), 42 deletions(-)
---
diff --git a/demos/shumate-demo-window.c b/demos/shumate-demo-window.c
index a89369a..794979d 100644
--- a/demos/shumate-demo-window.c
+++ b/demos/shumate-demo-window.c
@@ -35,8 +35,6 @@ 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)
@@ -71,12 +69,6 @@ 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);
@@ -86,8 +78,6 @@ 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
@@ -102,7 +92,6 @@ 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 d2ee6d0..c326e3d 100644
--- a/demos/shumate-demo-window.ui
+++ b/demos/shumate-demo-window.ui
@@ -41,6 +41,7 @@
<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 c2122c0..fbf2820 100644
--- a/shumate/shumate-layer.c
+++ b/shumate/shumate-layer.c
@@ -33,6 +33,8 @@
enum
{
PROP_VIEWPORT = 1,
+ PROP_LICENSE,
+ PROP_LICENSE_URI,
N_PROPERTIES
};
@@ -80,6 +82,14 @@ 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;
@@ -107,17 +117,33 @@ 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",
@@ -125,6 +151,20 @@ 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);
@@ -158,3 +198,35 @@ 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 ff699e6..7b87b7c 100644
--- a/shumate/shumate-layer.h
+++ b/shumate/shumate-layer.h
@@ -35,10 +35,16 @@ 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 4db7b8c..7eaafd9 100644
--- a/shumate/shumate-license.c
+++ b/shumate/shumate-license.c
@@ -29,6 +29,7 @@ enum
{
PROP_EXTRA_TEXT = 1,
PROP_XALIGN,
+ PROP_MAP,
N_PROPERTIES,
};
@@ -40,7 +41,8 @@ struct _ShumateLicense
GtkWidget *extra_text_label;
GtkWidget *license_label;
- GPtrArray *map_sources;
+
+ ShumateMap *map;
};
G_DEFINE_TYPE (ShumateLicense, shumate_license, GTK_TYPE_WIDGET);
@@ -63,6 +65,10 @@ 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);
}
@@ -87,6 +93,10 @@ 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);
}
@@ -96,15 +106,20 @@ static void
shumate_license_sources_changed (ShumateLicense *self)
{
g_autoptr(GString) license_str = NULL;
- guint i;
+ g_autoptr(GList) layers = NULL;
+ GList *l;
g_assert (SHUMATE_IS_LICENSE (self));
license_str = g_string_new (NULL);
- for (i = 0; i < self->map_sources->len; i++)
+
+ if (self->map)
+ layers = shumate_map_get_layers (self->map);
+
+ for (l = layers; l != NULL; l = l->next)
{
- ShumateMapSource *map_source = g_ptr_array_index (self->map_sources, i);
- const char *license = shumate_map_source_get_license (map_source);
+ ShumateLayer *layer = SHUMATE_LAYER (l->data);
+ const char *license = shumate_layer_get_license (layer);
if (license == NULL)
continue;
@@ -123,9 +138,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);
}
@@ -167,6 +182,18 @@ 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"));
@@ -187,7 +214,6 @@ 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);
@@ -296,32 +322,55 @@ shumate_license_get_xalign (ShumateLicense *license)
return gtk_label_get_xalign (GTK_LABEL (license->license_label));
}
-void
-shumate_license_append_map_source (ShumateLicense *license,
- ShumateMapSource *map_source)
+/**
+ * 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)
{
- g_return_if_fail (SHUMATE_IS_LICENSE (license));
+ g_return_val_if_fail (SHUMATE_IS_LICENSE (self), NULL);
- g_ptr_array_add (license->map_sources, g_object_ref (map_source));
- shumate_license_sources_changed (license);
+ return self->map;
}
-void
-shumate_license_prepend_map_source (ShumateLicense *license,
- ShumateMapSource *map_source)
+static void
+on_layers_changed (ShumateLicense *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_sources_changed (self);
}
+/**
+ * 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_remove_map_source (ShumateLicense *license,
- ShumateMapSource *map_source)
+shumate_license_set_map (ShumateLicense *self,
+ ShumateMap *map)
{
- g_return_if_fail (SHUMATE_IS_LICENSE (license));
+ 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_ptr_array_remove (license->map_sources, map_source);
- shumate_license_sources_changed (license);
+ g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_MAP]);
}
diff --git a/shumate/shumate-license.h b/shumate/shumate-license.h
index d28fc3e..7d59e0a 100644
--- a/shumate/shumate-license.h
+++ b/shumate/shumate-license.h
@@ -25,6 +25,7 @@
#define SHUMATE_LICENSE_H
#include <shumate/shumate-map-source.h>
+#include <shumate/shumate-map.h>
#include <glib-object.h>
#include <gtk/gtk.h>
@@ -44,12 +45,9 @@ void shumate_license_set_xalign (ShumateLicense *license,
float xalign);
float shumate_license_get_xalign (ShumateLicense *license);
-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);
+ShumateMap *shumate_license_get_map (ShumateLicense *self);
+void shumate_license_set_map (ShumateLicense *self,
+ ShumateMap *map);
G_END_DECLS
diff --git a/shumate/shumate-map-layer.c b/shumate/shumate-map-layer.c
index b88c813..0e86abe 100644
--- a/shumate/shumate-map-layer.c
+++ b/shumate/shumate-map-layer.c
@@ -541,11 +541,34 @@ 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;
@@ -556,6 +579,9 @@ 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 deb57c2..dd9b27a 100644
--- a/shumate/shumate-map.c
+++ b/shumate/shumate-map.c
@@ -63,6 +63,7 @@ enum
{
/* normal signals */
ANIMATION_COMPLETED,
+ LAYERS_CHANGED,
LAST_SIGNAL
};
@@ -813,6 +814,20 @@ 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"));
@@ -1057,6 +1072,7 @@ 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);
}
@@ -1080,6 +1096,7 @@ 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);
}
@@ -1103,6 +1120,7 @@ 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);
}
@@ -1127,6 +1145,31 @@ 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 28f111c..12b0a73 100644
--- a/shumate/shumate-map.h
+++ b/shumate/shumate-map.h
@@ -72,6 +72,9 @@ 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/license.c b/tests/license.c
new file mode 100644
index 0000000..2fde5cf
--- /dev/null
+++ b/tests/license.c
@@ -0,0 +1,104 @@
+#include <gtk/gtk.h>
+#include <shumate/shumate.h>
+
+static void
+test_license_map ()
+{
+ g_autoptr(ShumateLicense) license = shumate_license_new ();
+ g_autoptr(ShumateMap) map1 = shumate_map_new ();
+ ShumateViewport *viewport1 = shumate_map_get_viewport (map1);
+ g_autoptr(ShumateNetworkTileSource) source1 = NULL;
+ ShumateLayer *layer1 = NULL;
+ g_autoptr(ShumateMap) map2 = shumate_map_new ();
+ ShumateViewport *viewport2 = shumate_map_get_viewport (map2);
+ g_autoptr(ShumateNetworkTileSource) source2 = NULL;
+ ShumateLayer *layer2 = NULL;
+ g_autoptr(ShumateNetworkTileSource) source2b = NULL;
+ ShumateLayer *layer2b = NULL;
+ GtkWidget *label;
+
+ g_object_ref_sink (license);
+ g_object_ref_sink (map1);
+ g_object_ref_sink (map2);
+
+ label = gtk_widget_get_first_child (GTK_WIDGET (license));
+ g_assert (GTK_IS_LABEL (label));
+
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "");
+
+ shumate_license_set_map (license, map1);
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "");
+
+ source1 = shumate_network_tile_source_new_full ("test",
+ "test",
+ "Hello, world!",
+ NULL, 0, 0, 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ NULL);
+ layer1 = SHUMATE_LAYER (shumate_map_layer_new (SHUMATE_MAP_SOURCE (source1), viewport1));
+ shumate_map_add_layer (map1, layer1);
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "Hello, world!");
+
+ shumate_map_add_layer (map1, SHUMATE_LAYER (shumate_path_layer_new (viewport1)));
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "Hello, world!");
+
+ shumate_map_remove_layer (map1, layer1);
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "");
+
+ source2 = shumate_network_tile_source_new_full ("test",
+ "test",
+ "Goodbye, world!",
+ NULL, 0, 0, 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ NULL);
+ layer2 = SHUMATE_LAYER (shumate_map_layer_new (SHUMATE_MAP_SOURCE (source2), viewport2));
+ shumate_map_add_layer (map2, layer2);
+
+ shumate_license_set_map (license, map2);
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "Goodbye, world!");
+
+ source2b = shumate_network_tile_source_new_full ("test",
+ "test",
+ "source2b || !source2b",
+ NULL, 0, 0, 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ NULL);
+ layer2b = SHUMATE_LAYER (shumate_map_layer_new (SHUMATE_MAP_SOURCE (source2b), viewport2));
+ shumate_map_insert_layer_above (map2, layer2b, NULL);
+
+ shumate_license_set_map (license, map2);
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "source2b || !source2b\nGoodbye, world!");
+
+ shumate_license_set_map (license, NULL);
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "");
+}
+
+static void
+test_license_extra_text ()
+{
+ g_autoptr(ShumateLicense) license = shumate_license_new ();
+ GtkWidget *label;
+
+ g_object_ref_sink (license);
+
+ shumate_license_set_extra_text (license, "Hello, world!");
+ g_assert_cmpstr (shumate_license_get_extra_text (license), ==, "Hello, world!");
+
+ label = gtk_widget_get_last_child (GTK_WIDGET (license));
+ g_assert (GTK_IS_LABEL (label));
+
+ g_assert_cmpstr (gtk_label_get_text (GTK_LABEL (label)), ==, "Hello, world!");
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ gtk_init ();
+
+ g_test_add_func ("/license/map", test_license_map);
+ g_test_add_func ("/license/extra-text", test_license_extra_text);
+
+ return g_test_run ();
+}
diff --git a/tests/meson.build b/tests/meson.build
index 20b9dfb..9cbb99d 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -9,6 +9,7 @@ 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]