From 52e3b027680de8e9502523b3423b1b4b8932b51a Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 28 Dec 2019 23:15:50 +0100 Subject: [PATCH] app: show new version availability in About dialog. I was wondering which shape should take the new version notification (again some ugly pop-up?!) and realized using the About dialog was a good idea. This is preparatory work for this to happen. (cherry picked from commit 826ece3b86b21a7f8c9671fcf53566382298b030) --- app/dialogs/about-dialog.c | 86 ++++++++++++++++++++++++++++-- app/dialogs/about-dialog.h | 2 +- app/dialogs/dialogs-constructors.c | 2 +- 3 files changed, 85 insertions(+), 5 deletions(-) diff --git a/app/dialogs/about-dialog.c b/app/dialogs/about-dialog.c index cdbce7948a..510c041b9f 100644 --- a/app/dialogs/about-dialog.c +++ b/app/dialogs/about-dialog.c @@ -28,6 +28,8 @@ #include "dialogs-types.h" +#include "config/gimpcoreconfig.h" + #include "core/gimp.h" #include "core/gimpcontext.h" @@ -79,6 +81,9 @@ static void about_dialog_add_animation (GtkWidget *vbox, static gboolean about_dialog_anim_expose (GtkWidget *widget, GdkEventExpose *event, GimpAboutDialog *dialog); +static void about_dialog_add_update (GtkWidget *vbox, + GimpCoreConfig *config, + GimpAboutDialog *dialog); static void about_dialog_reshuffle (GimpAboutDialog *dialog); static gboolean about_dialog_timer (gpointer data); @@ -89,11 +94,11 @@ static void about_dialog_add_unstable_message GtkWidget * -about_dialog_create (GimpContext *context) +about_dialog_create (GimpCoreConfig *config) { static GimpAboutDialog dialog; - g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); + g_return_val_if_fail (GIMP_IS_CORE_CONFIG (config), NULL); if (! dialog.dialog) { @@ -156,6 +161,8 @@ about_dialog_create (GimpContext *context) if (GTK_IS_BOX (children->data)) { + about_dialog_add_update (children->data, + config, &dialog); about_dialog_add_animation (children->data, &dialog); #ifdef GIMP_UNSTABLE about_dialog_add_unstable_message (children->data); @@ -235,7 +242,7 @@ about_dialog_add_animation (GtkWidget *vbox, dialog->anim_area = gtk_drawing_area_new (); gtk_box_pack_start (GTK_BOX (vbox), dialog->anim_area, FALSE, FALSE, 0); - gtk_box_reorder_child (GTK_BOX (vbox), dialog->anim_area, 4); + gtk_box_reorder_child (GTK_BOX (vbox), dialog->anim_area, 5); gtk_widget_show (dialog->anim_area); dialog->layout = gtk_widget_create_pango_layout (dialog->anim_area, NULL); @@ -251,6 +258,79 @@ about_dialog_add_animation (GtkWidget *vbox, dialog); } +static void +about_dialog_add_update (GtkWidget *vbox, + GimpCoreConfig *config, + GimpAboutDialog *dialog) +{ + if (config->last_known_release != NULL) + { + /* There is a newer version. */ + GtkWidget *link; + GtkWidget *box2; + GtkWidget *image; + GtkWidget *frame; + GtkWidget *box; + GtkWidget *label; + GDateTime *datetime; + gchar *date; + gchar *text; + + /* The update frame. */ + frame = gtk_frame_new (NULL); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 2); + + box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_container_add (GTK_CONTAINER (frame), box); + + /* The preferred localized date representation without the time. */ + datetime = g_date_time_new_from_unix_local (config->check_update_timestamp); + date = g_date_time_format (datetime, "%x"); + g_date_time_unref (datetime); + + /* We want the frame to stand out. */ + label = gtk_label_new (NULL); + text = g_strdup_printf ("%s", + _("New version available!")); + gtk_label_set_markup (GTK_LABEL (label), text); + g_free (text); + gtk_widget_show (label); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_label_align (GTK_FRAME (frame), 0.5, 0.5); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT); + gtk_box_reorder_child (GTK_BOX (vbox), frame, 2); + + /* Explanation text with update image. */ + box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start (GTK_BOX (box), box2, FALSE, FALSE, 0); + gtk_widget_show (box2); + + image = gtk_image_new_from_icon_name ("software-update-available", + GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (box2), image, FALSE, FALSE, 0); + gtk_widget_show (image); + + text = g_strdup_printf (_("A new version of GIMP (%s) was released on %s.\n" + "It is recommended to update."), + config->last_known_release, date); + label = gtk_label_new (text); + g_free (date); + g_free (text); + + gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + /* Finally the download link. */ + link = gtk_link_button_new_with_label ("https://www.gimp.org/downloads/", + _("Go to download page")); + gtk_box_pack_start (GTK_BOX (box), link, FALSE, FALSE, 0); + gtk_widget_show (link); + + gtk_widget_show (box); + gtk_widget_show (frame); + } +} + static void about_dialog_reshuffle (GimpAboutDialog *dialog) { diff --git a/app/dialogs/about-dialog.h b/app/dialogs/about-dialog.h index dbefb44fa8..516d7da500 100644 --- a/app/dialogs/about-dialog.h +++ b/app/dialogs/about-dialog.h @@ -19,7 +19,7 @@ #define __ABOUT_DIALOG_H__ -GtkWidget * about_dialog_create (GimpContext *context); +GtkWidget * about_dialog_create (GimpCoreConfig *config); #endif /* __ABOUT_DIALOG_H__ */ diff --git a/app/dialogs/dialogs-constructors.c b/app/dialogs/dialogs-constructors.c index 3586a39488..09cdf91286 100644 --- a/app/dialogs/dialogs-constructors.c +++ b/app/dialogs/dialogs-constructors.c @@ -195,7 +195,7 @@ dialogs_about_get (GimpDialogFactory *factory, GimpUIManager *ui_manager, gint view_size) { - return about_dialog_create (context); + return about_dialog_create (context->gimp->config); } GtkWidget *