weather: Display service attributions in AboutDialog.

Note that this injects strings we can't translate.
This commit is contained in:
Florian Brosch
2017-12-11 21:29:33 -02:00
committed by Georges Basile Stavracas Neto
parent a188c68653
commit 2cbdba9a95
3 changed files with 85 additions and 26 deletions
+64 -22
View File
@@ -456,15 +456,54 @@ gcal_application_launch_search (GSimpleAction *search,
gcal_window_set_search_mode (GCAL_WINDOW (self->window), TRUE);
}
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>",
@@ -479,26 +518,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));
}
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,
@@ -506,8 +534,22 @@ gcal_application_show_about (GSimpleAction *simple,
"translator-credits", _("translator-credits"),
NULL);
g_clear_pointer (&copyright, 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
+20 -4
View File
@@ -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;
}
+1
View File
@@ -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