app: add alternative "Check for updates" button in the About dialog.

When an update is available, a big frame is visible, proposing to go to
the download page. Now a button is also available to explicitly request
for an update check in other cases (bypassing the wait delay for a
future startup).

(cherry picked from commit 827473fd88)
This commit is contained in:
Jehan
2019-12-29 10:51:59 +01:00
parent 52e3b02768
commit bb316e5376
4 changed files with 119 additions and 35 deletions

View File

@ -287,7 +287,7 @@ app_run (const gchar *full_prog_name,
* Thus we have to add a special flag when we make an update * Thus we have to add a special flag when we make an update
* check so that the timestamp is saved. * check so that the timestamp is saved.
*/ */
save_gimprc_at_exit = gimp_update_check (gimp->config); save_gimprc_at_exit = gimp_update_auto_check (gimp->config);
/* Initialize the error handling after creating/migrating the config /* Initialize the error handling after creating/migrating the config
* directory because it will create some folders for backup and crash * directory because it will create some folders for backup and crash

View File

@ -40,6 +40,7 @@
#include "about-dialog.h" #include "about-dialog.h"
#include "authors.h" #include "authors.h"
#include "gimp-update.h"
#include "gimp-intl.h" #include "gimp-intl.h"
@ -55,6 +56,8 @@ typedef struct
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *update_frame;
GtkWidget *anim_area; GtkWidget *anim_area;
PangoLayout *layout; PangoLayout *layout;
@ -81,9 +84,8 @@ static void about_dialog_add_animation (GtkWidget *vbox,
static gboolean about_dialog_anim_expose (GtkWidget *widget, static gboolean about_dialog_anim_expose (GtkWidget *widget,
GdkEventExpose *event, GdkEventExpose *event,
GimpAboutDialog *dialog); GimpAboutDialog *dialog);
static void about_dialog_add_update (GtkWidget *vbox, static void about_dialog_add_update (GimpAboutDialog *dialog,
GimpCoreConfig *config, GimpCoreConfig *config);
GimpAboutDialog *dialog);
static void about_dialog_reshuffle (GimpAboutDialog *dialog); static void about_dialog_reshuffle (GimpAboutDialog *dialog);
static gboolean about_dialog_timer (gpointer data); static gboolean about_dialog_timer (gpointer data);
@ -92,6 +94,10 @@ static void about_dialog_add_unstable_message
(GtkWidget *vbox); (GtkWidget *vbox);
#endif /* GIMP_UNSTABLE */ #endif /* GIMP_UNSTABLE */
static void about_dialog_last_release_changed
(GimpCoreConfig *config,
const GParamSpec *pspec,
GimpAboutDialog *dialog);
GtkWidget * GtkWidget *
about_dialog_create (GimpCoreConfig *config) about_dialog_create (GimpCoreConfig *config)
@ -161,12 +167,11 @@ about_dialog_create (GimpCoreConfig *config)
if (GTK_IS_BOX (children->data)) if (GTK_IS_BOX (children->data))
{ {
about_dialog_add_update (children->data,
config, &dialog);
about_dialog_add_animation (children->data, &dialog); about_dialog_add_animation (children->data, &dialog);
#ifdef GIMP_UNSTABLE #ifdef GIMP_UNSTABLE
about_dialog_add_unstable_message (children->data); about_dialog_add_unstable_message (children->data);
#endif /* GIMP_UNSTABLE */ #endif /* GIMP_UNSTABLE */
about_dialog_add_update (&dialog, config);
} }
else else
g_warning ("%s: ooops, no box in this container?", G_STRLOC); g_warning ("%s: ooops, no box in this container?", G_STRLOC);
@ -259,16 +264,13 @@ about_dialog_add_animation (GtkWidget *vbox,
} }
static void static void
about_dialog_add_update (GtkWidget *vbox, about_dialog_add_update (GimpAboutDialog *dialog,
GimpCoreConfig *config, GimpCoreConfig *config)
GimpAboutDialog *dialog)
{ {
if (config->last_known_release != NULL) GtkWidget *container;
{ GList *children;
/* There is a newer version. */ GtkWidget *vbox;
GtkWidget *link;
GtkWidget *box2;
GtkWidget *image;
GtkWidget *frame; GtkWidget *frame;
GtkWidget *box; GtkWidget *box;
GtkWidget *label; GtkWidget *label;
@ -276,17 +278,30 @@ about_dialog_add_update (GtkWidget *vbox,
gchar *date; gchar *date;
gchar *text; gchar *text;
/* Get the dialog vbox. */
container = gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog));
children = gtk_container_get_children (GTK_CONTAINER (container));
g_return_if_fail (GTK_IS_BOX (children->data));
vbox = children->data;
g_list_free (children);
/* 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);
/* The update frame. */ /* The update frame. */
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 2);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (frame), box); gtk_container_add (GTK_CONTAINER (frame), box);
if (config->last_known_release != NULL)
/* The preferred localized date representation without the time. */ {
datetime = g_date_time_new_from_unix_local (config->check_update_timestamp); /* There is a newer version. */
date = g_date_time_format (datetime, "%x"); GtkWidget *link;
g_date_time_unref (datetime); GtkWidget *box2;
GtkWidget *image;
/* We want the frame to stand out. */ /* We want the frame to stand out. */
label = gtk_label_new (NULL); label = gtk_label_new (NULL);
@ -298,7 +313,7 @@ about_dialog_add_update (GtkWidget *vbox,
gtk_frame_set_label_widget (GTK_FRAME (frame), 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_label_align (GTK_FRAME (frame), 0.5, 0.5);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
gtk_box_reorder_child (GTK_BOX (vbox), frame, 2); gtk_box_reorder_child (GTK_BOX (vbox), frame, 3);
/* Explanation text with update image. */ /* Explanation text with update image. */
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
@ -314,7 +329,6 @@ about_dialog_add_update (GtkWidget *vbox,
"It is recommended to update."), "It is recommended to update."),
config->last_known_release, date); config->last_known_release, date);
label = gtk_label_new (text); label = gtk_label_new (text);
g_free (date);
g_free (text); g_free (text);
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
@ -325,10 +339,43 @@ about_dialog_add_update (GtkWidget *vbox,
_("Go to download page")); _("Go to download page"));
gtk_box_pack_start (GTK_BOX (box), link, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box), link, FALSE, FALSE, 0);
gtk_widget_show (link); gtk_widget_show (link);
}
else
{
/* Show a check update version. */
GtkWidget *button;
gchar *text2;
gtk_box_reorder_child (GTK_BOX (vbox), frame, 4);
text2 = g_strdup_printf (_("Last checked on %s"), date);
text = g_strdup_printf ("%s\n<i>%s</i>",
_("Check for updates"), text2);
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), text);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
g_free (text);
g_free (text2);
button = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (button), label);
gtk_widget_show (label);
g_signal_connect (config, "notify::last-known-release",
(GCallback) about_dialog_last_release_changed,
dialog);
g_signal_connect_swapped (button, "clicked",
(GCallback) gimp_update_check, config);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
gtk_widget_show (button);
}
g_free (date);
gtk_widget_show (box); gtk_widget_show (box);
gtk_widget_show (frame); gtk_widget_show (frame);
}
dialog->update_frame = frame;
} }
static void static void
@ -698,3 +745,20 @@ about_dialog_add_unstable_message (GtkWidget *vbox)
} }
#endif /* GIMP_UNSTABLE */ #endif /* GIMP_UNSTABLE */
static void
about_dialog_last_release_changed (GimpCoreConfig *config,
const GParamSpec *pspec,
GimpAboutDialog *dialog)
{
g_signal_handlers_disconnect_by_func (config,
(GCallback) about_dialog_last_release_changed,
dialog);
if (dialog->update_frame)
{
gtk_widget_destroy (dialog->update_frame);
dialog->update_frame = NULL;
}
about_dialog_add_update (dialog, config);
}

View File

@ -162,10 +162,15 @@ gimp_check_updates_callback (GObject *source,
} }
} }
/*
* gimp_update_auto_check:
* @config:
*
* Run the check for newer versions of GIMP if conditions are right.
*/
gboolean gboolean
gimp_update_check (GimpCoreConfig *config) gimp_update_auto_check (GimpCoreConfig *config)
{ {
GFile *gimp_versions;
gint64 prev_update_timestamp; gint64 prev_update_timestamp;
gint64 current_timestamp; gint64 current_timestamp;
@ -187,6 +192,20 @@ gimp_update_check (GimpCoreConfig *config)
return FALSE; return FALSE;
#endif #endif
return gimp_update_check (config);
}
/*
* gimp_update_check:
* @config:
*
* Run the check for newer versions of GIMP inconditionnally.
*/
gboolean
gimp_update_check (GimpCoreConfig *config)
{
GFile *gimp_versions;
#ifdef GIMP_UNSTABLE #ifdef GIMP_UNSTABLE
if (g_getenv ("GIMP_DEV_VERSIONS_JSON")) if (g_getenv ("GIMP_DEV_VERSIONS_JSON"))
gimp_versions = g_file_new_for_path (g_getenv ("GIMP_DEV_VERSIONS_JSON")); gimp_versions = g_file_new_for_path (g_getenv ("GIMP_DEV_VERSIONS_JSON"));

View File

@ -22,6 +22,7 @@
#define __APP_GIMP_UPDATE_H__ #define __APP_GIMP_UPDATE_H__
gboolean gimp_update_auto_check (GimpCoreConfig *config);
gboolean gimp_update_check (GimpCoreConfig *config); gboolean gimp_update_check (GimpCoreConfig *config);