[gnome-panel] libgnome-panel: create only one about dialog



commit 43f3f9c91017bc36f0bde2da4b7dc2e2525c94ac
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Apr 3 17:31:27 2020 +0300

    libgnome-panel: create only one about dialog

 libgnome-panel/gp-applet.c         | 22 +++++++++++++++++++++-
 libgnome-panel/gp-module-private.h |  4 ++--
 libgnome-panel/gp-module.c         | 14 +++++++-------
 3 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/libgnome-panel/gp-applet.c b/libgnome-panel/gp-applet.c
index 3c14fc409..b60b6d956 100644
--- a/libgnome-panel/gp-applet.c
+++ b/libgnome-panel/gp-applet.c
@@ -84,6 +84,8 @@ typedef struct
 
   guint               panel_icon_size;
   guint               menu_icon_size;
+
+  GtkWidget          *about_dialog;
 } GpAppletPrivate;
 
 enum
@@ -374,6 +376,8 @@ gp_applet_dispose (GObject *object)
   g_clear_pointer (&priv->initial_settings, g_variant_unref);
   g_clear_object (&priv->general_settings);
 
+  g_clear_pointer (&priv->about_dialog, gtk_widget_destroy);
+
   G_OBJECT_CLASS (gp_applet_parent_class)->dispose (object);
 }
 
@@ -1396,7 +1400,23 @@ gp_applet_show_about (GpApplet *applet)
   g_return_if_fail (GP_IS_APPLET (applet));
   priv = gp_applet_get_instance_private (applet);
 
-  gp_module_show_about (priv->module, NULL, priv->id);
+  if (priv->about_dialog != NULL)
+    {
+      gtk_window_present (GTK_WINDOW (priv->about_dialog));
+      return;
+    }
+
+  priv->about_dialog = gp_module_create_about_dialog (priv->module,
+                                                      NULL,
+                                                      priv->id);
+
+  if (priv->about_dialog == NULL)
+    return;
+
+  g_object_add_weak_pointer (G_OBJECT (priv->about_dialog),
+                             (gpointer *) &priv->about_dialog);
+
+  gtk_window_present (GTK_WINDOW (priv->about_dialog));
 }
 
 /**
diff --git a/libgnome-panel/gp-module-private.h b/libgnome-panel/gp-module-private.h
index 16f4f6efa..b627d5a49 100644
--- a/libgnome-panel/gp-module-private.h
+++ b/libgnome-panel/gp-module-private.h
@@ -59,11 +59,11 @@ GpApplet            *gp_module_applet_new             (GpModule     *module,
                                                        GVariant     *initial_settings,
                                                        GError      **error);
 
-void                gp_module_show_about              (GpModule     *module,
+GtkWidget           *gp_module_create_about_dialog    (GpModule     *module,
                                                        GtkWindow    *parent,
                                                        const char   *applet);
 
-void                gp_module_show_help               (GpModule     *module,
+void                 gp_module_show_help              (GpModule     *module,
                                                        GtkWindow    *parent,
                                                        const char   *applet,
                                                        const char   *page);
diff --git a/libgnome-panel/gp-module.c b/libgnome-panel/gp-module.c
index bfa49d6cf..0e131d6f3 100644
--- a/libgnome-panel/gp-module.c
+++ b/libgnome-panel/gp-module.c
@@ -652,10 +652,10 @@ gp_module_applet_new (GpModule     *module,
                        NULL);
 }
 
-void
-gp_module_show_about (GpModule   *module,
-                      GtkWindow  *parent,
-                      const char *applet)
+GtkWidget *
+gp_module_create_about_dialog (GpModule   *module,
+                               GtkWindow  *parent,
+                               const char *applet)
 {
   GpAppletInfo *info;
   GtkAboutDialog *dialog;
@@ -664,7 +664,7 @@ gp_module_show_about (GpModule   *module,
   g_assert (info != NULL);
 
   if (info->about_dialog_func == NULL)
-    return;
+    return NULL;
 
   dialog = GTK_ABOUT_DIALOG (gtk_about_dialog_new ());
 
@@ -672,9 +672,9 @@ gp_module_show_about (GpModule   *module,
   gtk_about_dialog_set_comments (dialog, info->description);
   gtk_about_dialog_set_logo_icon_name (dialog, info->icon_name);
   gtk_about_dialog_set_version (dialog, module->version);
-
   info->about_dialog_func (dialog);
-  gtk_window_present (GTK_WINDOW (dialog));
+
+  return GTK_WIDGET (dialog);
 }
 
 void


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