diff options
author | Bastien Nocera <hadess@hadess.net> | 2021-01-12 14:54:55 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2021-01-12 15:11:55 +0100 |
commit | 32f0436a699fa15c5e8470800ae743a93ef6e167 (patch) | |
tree | cdc01d346f9da23008ab37da683bedcde42bccd4 /libgweather | |
parent | 4579ac3f0a85d6e07f8cd808a73eedf7fcdd2b77 (diff) | |
download | libgweather-32f0436a699fa15c5e8470800ae743a93ef6e167.tar.gz |
gweather: Add required "contact-info" property
Similarly to the application ID, contact information must be provided to
use the online weather providers.
Diffstat (limited to 'libgweather')
-rw-r--r-- | libgweather/gweather-private.h | 1 | ||||
-rw-r--r-- | libgweather/gweather-weather.c | 68 | ||||
-rw-r--r-- | libgweather/gweather-weather.h | 3 | ||||
-rw-r--r-- | libgweather/test_libgweather.c | 1 |
4 files changed, 71 insertions, 2 deletions
diff --git a/libgweather/gweather-private.h b/libgweather/gweather-private.h index e460949..4653536 100644 --- a/libgweather/gweather-private.h +++ b/libgweather/gweather-private.h @@ -116,6 +116,7 @@ struct _GWeatherInfo { GWeatherProvider providers; GSettings *settings; char *application_id; + char *contact_info; gboolean valid; gboolean network_error; diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c index b30bf36..f83a4db 100644 --- a/libgweather/gweather-weather.c +++ b/libgweather/gweather-weather.c @@ -67,6 +67,7 @@ enum { PROP_LOCATION, PROP_ENABLED_PROVIDERS, PROP_APPLICATION_ID, + PROP_CONTACT_INFO, PROP_LAST }; @@ -634,8 +635,10 @@ ref_session (GWeatherInfo *info) return g_object_ref (session); session = soup_session_new (); - user_agent = g_strdup_printf ("libgweather/%s (+https://gitlab.gnome.org/GNOME/libgweather/) %s", - LIBGWEATHER_VERSION, info->application_id); + user_agent = g_strdup_printf ("libgweather/%s %s (%s)", + LIBGWEATHER_VERSION, + info->application_id, + info->contact_info); g_object_set (G_OBJECT (session), SOUP_SESSION_USER_AGENT, user_agent, NULL); cache = get_cache (); @@ -697,6 +700,7 @@ gweather_info_update (GWeatherInfo *info) g_return_if_fail (info->application_id != NULL); g_return_if_fail (g_application_id_is_valid (info->application_id)); + g_return_if_fail (info->contact_info != NULL); /* Update in progress */ if (!requests_init (info)) @@ -2231,6 +2235,53 @@ gweather_info_set_application_id (GWeatherInfo *info, } } +/** + * gweather_info_get_contact_info: + * @info: a #GWeatherInfo + * + * Get the contact information of the application fetching the weather. + * + * Returns: the contact information + */ +const char * +gweather_info_get_contact_info (GWeatherInfo *info) +{ + g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); + + return info->contact_info; +} + +/** + * gweather_info_set_contact_info: + * @info: a #GWeatherInfo + * @application_id: the contact information for the application + * + * Sets the contact information for the application fetching the + * weather. It is a requirement for using any of the online + * weather providers as it allows API providers to contact application + * developers in case of terms of use breaches. + * + * The contact information should be an email address, or the full + * URL to an online contact form which weather providers can use + * to contact the application developer. Avoid using bug tracker + * URLs which require creating accounts. + */ +void +gweather_info_set_contact_info (GWeatherInfo *info, + const char *contact_info) +{ + g_return_if_fail (GWEATHER_IS_INFO (info)); + g_return_if_fail (contact_info != NULL); + + g_clear_pointer (&info->contact_info, g_free); + info->contact_info = g_strdup (contact_info); + + if (info->session) { + g_clear_object (&info->session); + info->session = ref_session (info); + } +} + static void gweather_info_set_property (GObject *object, guint property_id, @@ -2249,6 +2300,9 @@ gweather_info_set_property (GObject *object, case PROP_APPLICATION_ID: gweather_info_set_application_id (self, g_value_get_string (value)); break; + case PROP_CONTACT_INFO: + gweather_info_set_contact_info (self, g_value_get_string (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -2272,6 +2326,9 @@ gweather_info_get_property (GObject *object, case PROP_APPLICATION_ID: g_value_set_string (value, self->application_id); break; + case PROP_CONTACT_INFO: + g_value_set_string (value, self->contact_info); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -2327,6 +2384,13 @@ gweather_info_class_init (GWeatherInfoClass *klass) G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE); g_object_class_install_property (gobject_class, PROP_APPLICATION_ID, pspec); + pspec = g_param_spec_string ("contact-info", + "Contact information", + "An email address or contact form URL", + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_CONTACT_INFO, pspec); + /** * GWeatherInfo::updated: * @object: the emitter of the signal. diff --git a/libgweather/gweather-weather.h b/libgweather/gweather-weather.h index 02fcaa4..3bf8298 100644 --- a/libgweather/gweather-weather.h +++ b/libgweather/gweather-weather.h @@ -74,6 +74,9 @@ const char * gweather_info_get_application_id (GWeatherInfo *info); void gweather_info_set_application_id (GWeatherInfo *info, const char *application_id); +const char * gweather_info_get_contact_info (GWeatherInfo *info); +void gweather_info_set_contact_info (GWeatherInfo *info, + const char *contact_info); gboolean gweather_info_is_valid (GWeatherInfo *info); gboolean gweather_info_network_error (GWeatherInfo *info); diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c index a1adbe4..b10c1f1 100644 --- a/libgweather/test_libgweather.c +++ b/libgweather/test_libgweather.c @@ -785,6 +785,7 @@ test_weather_loop_use_after_free (void) loop = g_main_loop_new (NULL, TRUE); info = gweather_info_new (NULL); gweather_info_set_application_id (info, "org.gnome.LibGWeather"); + gweather_info_set_contact_info (info, "https://gitlab.gnome.org/GNOME/libgweather/"); gweather_info_set_enabled_providers (info, GWEATHER_PROVIDER_METAR | GWEATHER_PROVIDER_IWIN | |