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



commit 827473fd881627eed63188cf70d8a04fe9d1cda8
Author: Jehan <jehan girinstud io>
Date:   Sun Dec 29 10:51:59 2019 +0100

    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).

 app/app.c                  |   2 +-
 app/dialogs/about-dialog.c | 124 ++++++++++++++++++++++++++++++++++-----------
 app/gimp-update.c          |  23 ++++++++-
 app/gimp-update.h          |   3 +-
 4 files changed, 118 insertions(+), 34 deletions(-)
---
diff --git a/app/app.c b/app/app.c
index a2c4d403d1..903aacbb24 100644
--- a/app/app.c
+++ b/app/app.c
@@ -292,7 +292,7 @@ app_run (const gchar         *full_prog_name,
    * Thus we have to add a special flag when we make an update
    * 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
    * directory because it will create some folders for backup and crash
diff --git a/app/dialogs/about-dialog.c b/app/dialogs/about-dialog.c
index 7ec494313b..a25311d731 100644
--- a/app/dialogs/about-dialog.c
+++ b/app/dialogs/about-dialog.c
@@ -35,6 +35,7 @@
 
 #include "about-dialog.h"
 #include "authors.h"
+#include "gimp-update.h"
 
 #include "gimp-intl.h"
 
@@ -50,6 +51,8 @@ typedef struct
 {
   GtkWidget   *dialog;
 
+  GtkWidget   *update_frame;
+
   GtkWidget   *anim_area;
   PangoLayout *layout;
 
@@ -72,9 +75,8 @@ static void        about_dialog_unmap         (GtkWidget       *widget,
 static GdkPixbuf * about_dialog_load_logo     (void);
 static void        about_dialog_add_animation (GtkWidget       *vbox,
                                                GimpAboutDialog *dialog);
-static void        about_dialog_add_update    (GtkWidget       *vbox,
-                                               GimpCoreConfig  *config,
-                                               GimpAboutDialog *dialog);
+static void        about_dialog_add_update    (GimpAboutDialog *dialog,
+                                               GimpCoreConfig  *config);
 static gboolean    about_dialog_anim_draw     (GtkWidget       *widget,
                                                cairo_t         *cr,
                                                GimpAboutDialog *dialog);
@@ -86,6 +88,10 @@ static void        about_dialog_add_unstable_message
                                               (GtkWidget       *vbox);
 #endif /* GIMP_UNSTABLE */
 
+static void        about_dialog_last_release_changed
+                                              (GimpCoreConfig   *config,
+                                               const GParamSpec *pspec,
+                                               GimpAboutDialog  *dialog);
 
 GtkWidget *
 about_dialog_create (GimpCoreConfig *config)
@@ -153,12 +159,11 @@ about_dialog_create (GimpCoreConfig *config)
 
       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);
 #endif /* GIMP_UNSTABLE */
+          about_dialog_add_update (&dialog, config);
         }
       else
         g_warning ("%s: ooops, no box in this container?", G_STRLOC);
@@ -249,34 +254,44 @@ about_dialog_add_animation (GtkWidget       *vbox,
 }
 
 static void
-about_dialog_add_update (GtkWidget       *vbox,
-                         GimpCoreConfig  *config,
-                         GimpAboutDialog *dialog)
+about_dialog_add_update (GimpAboutDialog *dialog,
+                         GimpCoreConfig  *config)
 {
+  GtkWidget *container;
+  GList     *children;
+  GtkWidget *vbox;
+
+  GtkWidget *frame;
+  GtkWidget *box;
+  GtkWidget *label;
+  GDateTime *datetime;
+  gchar     *date;
+  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. */
+  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);
   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);
@@ -288,7 +303,7 @@ about_dialog_add_update (GtkWidget       *vbox,
       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);
+      gtk_box_reorder_child (GTK_BOX (vbox), frame, 3);
 
       /* Explanation text with update image. */
       box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
@@ -304,7 +319,6 @@ about_dialog_add_update (GtkWidget       *vbox,
                                 "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);
@@ -315,10 +329,43 @@ about_dialog_add_update (GtkWidget       *vbox,
                                              _("Go to download page"));
       gtk_box_pack_start (GTK_BOX (box), link, FALSE, FALSE, 0);
       gtk_widget_show (link);
+    }
+  else
+    {
+      /* Show a check update version. */
+      GtkWidget *button;
+      gchar     *text2;
+
+      gtk_box_reorder_child (GTK_BOX (vbox), frame, 4);
 
-      gtk_widget_show (box);
-      gtk_widget_show (frame);
+      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 (frame);
+
+  dialog->update_frame = frame;
 }
 
 static void
@@ -613,3 +660,20 @@ about_dialog_add_unstable_message (GtkWidget *vbox)
 }
 
 #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);
+}
diff --git a/app/gimp-update.c b/app/gimp-update.c
index 29c284bd07..471bfbf20b 100644
--- a/app/gimp-update.c
+++ b/app/gimp-update.c
@@ -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
-gimp_update_check (GimpCoreConfig *config)
+gimp_update_auto_check (GimpCoreConfig *config)
 {
-  GFile *gimp_versions;
   gint64 prev_update_timestamp;
   gint64 current_timestamp;
 
@@ -187,6 +192,20 @@ gimp_update_check (GimpCoreConfig *config)
     return FALSE;
 #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
   if (g_getenv ("GIMP_DEV_VERSIONS_JSON"))
     gimp_versions = g_file_new_for_path (g_getenv ("GIMP_DEV_VERSIONS_JSON"));
diff --git a/app/gimp-update.h b/app/gimp-update.h
index 43e841102d..dcc665d94a 100644
--- a/app/gimp-update.h
+++ b/app/gimp-update.h
@@ -22,7 +22,8 @@
 #define __APP_GIMP_UPDATE_H__
 
 
-gboolean gimp_update_check (GimpCoreConfig *config);
+gboolean gimp_update_auto_check (GimpCoreConfig *config);
+gboolean gimp_update_check      (GimpCoreConfig *config);
 
 
 #endif /* __APP_GIMP_UPDATE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]