[gnome-calendar/wip/flb/weather-forecast: 20/50] weather: Display service attributions in AboutDialog.
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/flb/weather-forecast: 20/50] weather: Display service attributions in AboutDialog.
- Date: Tue, 31 Oct 2017 08:19:30 +0000 (UTC)
commit 73f9d42d94e4f5b13a7739d41d6a903dbcb8f18e
Author: Florian Brosch <flo brosch gmail com>
Date: Sun Oct 15 21:58:57 2017 +0200
weather: Display service attributions in AboutDialog.
Note that this injects strings we can't translate.
src/gcal-application.c | 86 ++++++++++++++++++++++++++++++++-----------
src/gcal-weather-service.c | 24 ++++++++++--
src/gcal-weather-service.h | 1 +
3 files changed, 85 insertions(+), 26 deletions(-)
---
diff --git a/src/gcal-application.c b/src/gcal-application.c
index ce74883..d436aec 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -436,14 +436,53 @@ gcal_application_launch_search (GSimpleAction *search,
}
static void
+on_about_response (GtkAboutDialog *about,
+ int response_id,
+ gpointer user_data)
+{
+ g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
+ g_return_if_fail (user_data == NULL);
+
+ if (response_id == GTK_RESPONSE_CANCEL)
+ gtk_widget_destroy (GTK_WIDGET (about));
+}
+
+static gchar*
+build_about_copyright (GcalApplication *self)
+{
+ GString *builder ; /* owned */
+ const gchar *attribution; /* unowned */
+ g_autoptr (GDateTime) dt = NULL;
+
+ g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL);
+
+ builder = g_string_new ("<span size=\"small\">");
+ dt = g_date_time_new_now_local ();
+
+ /* Build string: */
+ g_string_append_printf (builder,
+ _("Copyright \xC2\xA9 2012\xE2\x80\x93%d " "The Calendar authors"),
+ g_date_time_get_year (dt));
+
+ attribution = gcal_weather_service_get_attribution (self->weather_service);
+ if (attribution != NULL)
+ {
+ g_string_append_c (builder, '\n');
+ g_string_append (builder, attribution);
+ }
+ g_string_append (builder, "</span>");
+
+ return g_string_free (builder, FALSE);
+}
+
+static void
gcal_application_show_about (GSimpleAction *simple,
GVariant *parameter,
gpointer user_data)
{
- GcalApplication *self;
- char *copyright;
- GDateTime *dt;
- int created_year = 2012;
+ GcalApplication *self; /* unowned */
+ GtkWidget *dialog; /* owned */
+
const gchar *authors[] = {
"Erick PĂ©rez Castellanos <erickpc gnome org>",
"Georges Basile Stavracas Neto <georges stavracas gmail com>",
@@ -458,26 +497,15 @@ gcal_application_show_about (GSimpleAction *simple,
NULL
};
- self = GCAL_APPLICATION (user_data);
- dt = g_date_time_new_now_local ();
- if (g_date_time_get_year (dt) == created_year)
- {
- copyright = g_strdup_printf (_("Copyright \xC2\xA9 %d "
- "The Calendar authors"),
- created_year);
- }
- else
- {
- copyright = g_strdup_printf (_("Copyright \xC2\xA9 %d\xE2\x80\x93%d "
- "The Calendar authors"),
- created_year, g_date_time_get_year (dt));
- }
+ self = GCAL_APPLICATION (user_data);
- gtk_show_about_dialog (GTK_WINDOW (self->window),
+ dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
+ "transient-for", GTK_WINDOW (self->window),
+ "modal", TRUE,
+ "destroy-with-parent", TRUE,
"program-name", _("Calendar"),
"version", VERSION,
- "copyright", copyright,
"license-type", GTK_LICENSE_GPL_3_0,
"authors", authors,
"artists", artists,
@@ -485,8 +513,22 @@ gcal_application_show_about (GSimpleAction *simple,
"translator-credits", _("translator-credits"),
NULL);
- g_clear_pointer (©right, g_free);
- g_clear_pointer (&dt, g_date_time_unref);
+ /* Poke AboutDialog internals to display links in
+ * attributions. This workaround is also used by
+ * gnome-weather.
+ */
+ {
+ g_autofree gchar *copyright;
+ GObject *cpyright_lbl; /* unowned */
+
+ copyright = build_about_copyright (self);
+ cpyright_lbl = gtk_widget_get_template_child (GTK_WIDGET (dialog), GTK_TYPE_ABOUT_DIALOG,
"copyright_label");
+ gtk_label_set_markup (GTK_LABEL (cpyright_lbl), copyright);
+ gtk_widget_show (GTK_WIDGET (cpyright_lbl));
+ }
+
+ g_signal_connect (dialog, "response", G_CALLBACK (on_about_response), NULL);
+ gtk_widget_show (dialog);
}
static void
diff --git a/src/gcal-weather-service.c b/src/gcal-weather-service.c
index 0d622b3..7deebb4 100644
--- a/src/gcal-weather-service.c
+++ b/src/gcal-weather-service.c
@@ -847,10 +847,6 @@ gcal_weather_service_update_location (GcalWeatherService *self,
(location == NULL)? "<null>" : gweather_location_get_name (location));
self->gweather_info = gweather_info_new (location, GWEATHER_FORECAST_ZONE | GWEATHER_FORECAST_LIST);
- /* TODO: display weather attributions somewhere:
- * gweather_info_get_attribution (self->gweather_info);
- * Do no roll-out a release without resolving this one before!
- */
/* NOTE: We do not get detailed infos for GWEATHER_PROVIDER_ALL.
* This combination works fine, though. We should open a bug / investigate
@@ -1440,3 +1436,23 @@ gcal_weather_service_get_weather_infos (GcalWeatherService *self)
return self->weather_infos;
}
+
+
+
+/**
+ * gcal_weather_service_get_attribution:
+ *
+ * Returns weather service attribution.
+ *
+ * Returns: (nullable) (transfer none): Text to display.
+ */
+const gchar*
+gcal_weather_service_get_attribution (GcalWeatherService *self)
+{
+ g_return_val_if_fail (GCAL_IS_WEATHER_SERVICE (self), NULL);
+
+ if (self->gweather_info != NULL)
+ return gweather_info_get_attribution (self->gweather_info);
+
+ return NULL;
+}
diff --git a/src/gcal-weather-service.h b/src/gcal-weather-service.h
index 0874e3e..bfaf134 100644
--- a/src/gcal-weather-service.h
+++ b/src/gcal-weather-service.h
@@ -52,6 +52,7 @@ guint gcal_weather_service_get_check_interval (GcalWeatherService
GSList* gcal_weather_service_get_weather_infos (GcalWeatherService *self);
+const gchar* gcal_weather_service_get_attribution (GcalWeatherService *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]