[gnome-control-center] component: PpPPDSelectionDialog



commit 26e8f115665302e6347e211951db24d68712707b
Author: Brandon Nielsen <nielsenb jetfuse net>
Date:   Fri Sep 18 08:30:06 2020 -0500

    component: PpPPDSelectionDialog
    
    G_IS_OBJECT checks fail when calling g_signal_connect_object because
    PpPPDSelectionDialog is a struct, not a type descending from G_OBJECT.
    
    This makes the changes required for PpPPDSelectionDialog to be a
    GObject, and defines PpPPDSelectionDialog as a GObject. It also updates
    consumers of PpPPDSelectionDialog to destroy created PpPPDSelectionDialogs as GObjects.
    
    https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1126

 panels/printers/pp-details-dialog.c       |   2 +-
 panels/printers/pp-new-printer-dialog.c   |   2 +-
 panels/printers/pp-ppd-selection-dialog.c | 117 ++++++++++++++++++------------
 panels/printers/pp-ppd-selection-dialog.h |   4 +-
 4 files changed, 75 insertions(+), 50 deletions(-)
---
diff --git a/panels/printers/pp-details-dialog.c b/panels/printers/pp-details-dialog.c
index f9d97e5c1..98ca1d409 100644
--- a/panels/printers/pp-details-dialog.c
+++ b/panels/printers/pp-details-dialog.c
@@ -174,7 +174,7 @@ ppd_selection_dialog_response_cb (GtkDialog *dialog,
         }
     }
 
-  pp_ppd_selection_dialog_free (self->pp_ppd_selection_dialog);
+  g_clear_object (&self->pp_ppd_selection_dialog);
   self->pp_ppd_selection_dialog = NULL;
 }
 
diff --git a/panels/printers/pp-new-printer-dialog.c b/panels/printers/pp-new-printer-dialog.c
index e05a95ddf..bc3af4609 100644
--- a/panels/printers/pp-new-printer-dialog.c
+++ b/panels/printers/pp-new-printer-dialog.c
@@ -1902,7 +1902,7 @@ ppd_selection_cb (GtkDialog *_dialog,
 
   ppd_name = pp_ppd_selection_dialog_get_ppd_name (self->ppd_selection_dialog);
   ppd_display_name = pp_ppd_selection_dialog_get_ppd_display_name (self->ppd_selection_dialog);
-  pp_ppd_selection_dialog_free (self->ppd_selection_dialog);
+  g_clear_object (&self->ppd_selection_dialog);
   self->ppd_selection_dialog = NULL;
 
   if (ppd_name)
diff --git a/panels/printers/pp-ppd-selection-dialog.c b/panels/printers/pp-ppd-selection-dialog.c
index 025b47300..73b79767c 100644
--- a/panels/printers/pp-ppd-selection-dialog.c
+++ b/panels/printers/pp-ppd-selection-dialog.c
@@ -51,19 +51,71 @@ enum
 
 
 struct _PpPPDSelectionDialog {
-  GtkBuilder *builder;
-  GtkWidget  *dialog;
+       GObject parent_instance;
 
-  UserResponseCallback user_callback;
-  gpointer             user_data;
+       GtkBuilder *builder;
+       GtkWidget  *dialog;
 
-  gchar           *ppd_name;
-  gchar           *ppd_display_name;
-  gchar           *manufacturer;
+       UserResponseCallback user_callback;
+       gpointer             user_data;
 
-  PPDList *list;
+       gchar           *ppd_name;
+       gchar           *ppd_display_name;
+       gchar           *manufacturer;
+
+       PPDList *list;
 };
 
+G_DEFINE_TYPE (PpPPDSelectionDialog, pp_ppd_selection_dialog, G_TYPE_OBJECT)
+
+static void populate_dialog (PpPPDSelectionDialog *self);
+
+static void pp_ppd_selection_dialog_finalize (GObject *object);
+
+static void
+pp_ppd_selection_dialog_class_init (PpPPDSelectionDialogClass *klass)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (klass);
+  object_class->finalize = pp_ppd_selection_dialog_finalize;
+}
+
+
+PpPPDSelectionDialog *
+pp_ppd_selection_dialog_new (GtkWindow            *parent,
+                             PPDList              *ppd_list,
+                             const gchar          *manufacturer,
+                             UserResponseCallback  user_callback,
+                             gpointer              user_data)
+{
+  PpPPDSelectionDialog *self;
+  GtkWidget            *widget;
+  g_autoptr(GError)     error = NULL;
+
+       self = g_object_new (PP_TYPE_PPD_SELECTION_DIALOG, NULL);
+
+  self->user_callback = user_callback;
+  self->user_data = user_data;
+
+  self->list = ppd_list_copy (ppd_list);
+
+  self->manufacturer = get_standard_manufacturers_name (manufacturer);
+
+  gtk_window_set_transient_for (GTK_WINDOW (self->dialog), GTK_WINDOW (parent));
+
+  widget = (GtkWidget*)
+    gtk_builder_get_object (self->builder, "ppd-spinner");
+  gtk_spinner_start (GTK_SPINNER (widget));
+
+       populate_dialog (self);
+
+  gtk_window_present (GTK_WINDOW (self->dialog));
+  gtk_widget_show_all (GTK_WIDGET (self->dialog));
+
+  return PP_PPD_SELECTION_DIALOG (self);
+}
+
 static void
 manufacturer_selection_changed_cb (PpPPDSelectionDialog *self)
 {
@@ -314,21 +366,13 @@ ppd_selection_dialog_response_cb (PpPPDSelectionDialog *self,
   self->user_callback (GTK_DIALOG (self->dialog), response_id, self->user_data);
 }
 
-PpPPDSelectionDialog *
-pp_ppd_selection_dialog_new (GtkWindow            *parent,
-                             PPDList              *ppd_list,
-                             const gchar          *manufacturer,
-                             UserResponseCallback  user_callback,
-                             gpointer              user_data)
+static void
+pp_ppd_selection_dialog_init (PpPPDSelectionDialog *self)
 {
-  PpPPDSelectionDialog *self;
-  GtkWidget            *widget;
   g_autoptr(GError)     error = NULL;
   gchar                *objects[] = { "ppd-selection-dialog", NULL };
   guint                 builder_result;
 
-  self = g_new0 (PpPPDSelectionDialog, 1);
-
   self->builder = gtk_builder_new ();
 
   builder_result = gtk_builder_add_objects_from_resource (self->builder,
@@ -338,49 +382,30 @@ pp_ppd_selection_dialog_new (GtkWindow            *parent,
   if (builder_result == 0)
     {
       g_warning ("Could not load ui: %s", error->message);
-      return NULL;
     }
 
   self->dialog = (GtkWidget *) gtk_builder_get_object (self->builder, "ppd-selection-dialog");
-  self->user_callback = user_callback;
-  self->user_data = user_data;
-
-  self->list = ppd_list_copy (ppd_list);
-
-  self->manufacturer = get_standard_manufacturers_name (manufacturer);
 
   /* connect signals */
   g_signal_connect (self->dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
   g_signal_connect_object (self->dialog, "response", G_CALLBACK (ppd_selection_dialog_response_cb), self, 
G_CONNECT_SWAPPED);
-
-  gtk_window_set_transient_for (GTK_WINDOW (self->dialog), GTK_WINDOW (parent));
-
-  widget = (GtkWidget*)
-    gtk_builder_get_object (self->builder, "ppd-spinner");
-  gtk_spinner_start (GTK_SPINNER (widget));
-
-  populate_dialog (self);
-
-  gtk_window_present (GTK_WINDOW (self->dialog));
-  gtk_widget_show_all (GTK_WIDGET (self->dialog));
-
-  return self;
 }
 
-void
-pp_ppd_selection_dialog_free (PpPPDSelectionDialog *self)
+static void
+pp_ppd_selection_dialog_finalize (GObject *object)
 {
-  gtk_widget_destroy (GTK_WIDGET (self->dialog));
+       PpPPDSelectionDialog *self = PP_PPD_SELECTION_DIALOG (object);
 
   g_clear_object (&self->builder);
+       g_clear_pointer (&self->dialog, gtk_widget_destroy);
 
-  g_free (self->ppd_name);
-
-  g_free (self->ppd_display_name);
+       g_clear_pointer (&self->ppd_name, g_free);
+       g_clear_pointer (&self->ppd_name, g_free);
+       g_clear_pointer (&self->ppd_display_name, g_free);
 
-  g_free (self->manufacturer);
+       g_clear_pointer (&self->list, ppd_list_free);
 
-  g_free (self);
+       G_OBJECT_CLASS (pp_ppd_selection_dialog_parent_class)->finalize (object);
 }
 
 gchar *
diff --git a/panels/printers/pp-ppd-selection-dialog.h b/panels/printers/pp-ppd-selection-dialog.h
index 3cca00243..36c0342e1 100644
--- a/panels/printers/pp-ppd-selection-dialog.h
+++ b/panels/printers/pp-ppd-selection-dialog.h
@@ -25,7 +25,8 @@
 
 G_BEGIN_DECLS
 
-typedef struct _PpPPDSelectionDialog PpPPDSelectionDialog;
+#define PP_TYPE_PPD_SELECTION_DIALOG (pp_ppd_selection_dialog_get_type ())
+G_DECLARE_FINAL_TYPE (PpPPDSelectionDialog, pp_ppd_selection_dialog, PP, PPD_SELECTION_DIALOG, GObject)
 
 PpPPDSelectionDialog *pp_ppd_selection_dialog_new                  (GtkWindow                 *parent,
                                                                     PPDList                   *ppd_list,
@@ -36,6 +37,5 @@ gchar                *pp_ppd_selection_dialog_get_ppd_name         (PpPPDSelecti
 gchar                *pp_ppd_selection_dialog_get_ppd_display_name (PpPPDSelectionDialog      *dialog);
 void                  pp_ppd_selection_dialog_set_ppd_list         (PpPPDSelectionDialog      *dialog,
                                                                     PPDList                   *list);
-void                  pp_ppd_selection_dialog_free                 (PpPPDSelectionDialog      *dialog);
 
 G_END_DECLS


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