[gedit] Correctly disconnect signals attached to the print job operation.



commit 9599b3e448e87f74155976e6e69a658297eb8782
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Oct 7 12:25:16 2010 +0200

    Correctly disconnect signals attached to the print job operation.

 gedit/gedit-print-job.c |   39 ++++++++++++++++++++++++++++++---------
 gedit/gedit-tab.c       |   21 +++++++++++++++++++--
 2 files changed, 49 insertions(+), 11 deletions(-)
---
diff --git a/gedit/gedit-print-job.c b/gedit/gedit-print-job.c
index 45695eb..6ff6b56 100644
--- a/gedit/gedit-print-job.c
+++ b/gedit/gedit-print-job.c
@@ -108,6 +108,14 @@ static guint print_job_signals[LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (GeditPrintJob, gedit_print_job, G_TYPE_OBJECT)
 
+static void          end_print_cb      (GtkPrintOperation *operation, 
+                                        GtkPrintContext   *context,
+                                        GeditPrintJob     *job);
+
+static void          done_cb           (GtkPrintOperation       *operation,
+                                        GtkPrintOperationResult  result,
+                                        GeditPrintJob           *job);
+
 static void
 set_view (GeditPrintJob *job, GeditView *view)
 {
@@ -159,12 +167,6 @@ gedit_print_job_finalize (GObject *object)
 	GeditPrintJob *job = GEDIT_PRINT_JOB (object);
 
 	g_free (job->priv->status_string);
-	
-	if (job->priv->compositor != NULL)
-		g_object_unref (job->priv->compositor);
-
-	if (job->priv->operation != NULL)
-		g_object_unref (job->priv->operation);
 
 	G_OBJECT_CLASS (gedit_print_job_parent_class)->finalize (object);
 }
@@ -173,12 +175,28 @@ static void
 gedit_print_job_dispose (GObject *object)
 {
 	GeditPrintJob *job = GEDIT_PRINT_JOB (object);
-	
+
 	if (job->priv->print_settings != NULL)
 	{
 		g_object_unref (job->priv->print_settings);
 		job->priv->print_settings = NULL;
 	}
+
+	if (job->priv->compositor != NULL)
+	{
+		g_object_unref (job->priv->compositor);
+		job->priv->compositor = NULL;
+	}
+
+	if (job->priv->operation != NULL)
+	{
+		g_signal_handlers_disconnect_by_func (job->priv->operation,
+		                                      end_print_cb, job);
+		g_signal_handlers_disconnect_by_func (job->priv->operation,
+		                                      done_cb, job);
+		g_object_unref (job->priv->operation);
+		job->priv->operation = NULL;
+	}
 	
 	G_OBJECT_CLASS (gedit_print_job_parent_class)->dispose (object);
 }
@@ -702,8 +720,11 @@ end_print_cb (GtkPrintOperation *operation,
 	      GtkPrintContext   *context,
 	      GeditPrintJob     *job)
 {
-	g_object_unref (job->priv->compositor);
-	job->priv->compositor = NULL;
+	if (job->priv->compositor != NULL)
+	{
+		g_object_unref (job->priv->compositor);
+		job->priv->compositor = NULL;
+	}
 }
 
 static void
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index c998fda..f09331a 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -106,6 +106,11 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 static gboolean gedit_tab_auto_save (GeditTab *tab);
 
+static void done_printing_cb        (GeditPrintJob       *job,
+                                     GeditPrintJobResult  result,
+                                     const GError        *error,
+                                     GeditTab            *tab);
+
 static void
 install_auto_save_timeout (GeditTab *tab)
 {
@@ -236,6 +241,15 @@ gedit_tab_dispose (GObject *object)
 {
 	GeditTab *tab = GEDIT_TAB (object);
 
+	if (tab->priv->print_job != NULL)
+	{
+		g_signal_handlers_disconnect_by_func (tab->priv->print_job,
+		                                      done_printing_cb, tab);
+		g_object_unref (tab->priv->print_job);
+		tab->priv->print_job = NULL;
+		tab->priv->print_preview = NULL;
+	}
+
 	if (tab->priv->tmp_save_location != NULL)
 	{
 		g_object_unref (tab->priv->tmp_save_location);
@@ -2489,8 +2503,11 @@ done_printing_cb (GeditPrintJob       *job,
 	view = gedit_tab_get_view (tab);
 	gtk_widget_grab_focus (GTK_WIDGET (view));
 
- 	g_object_unref (tab->priv->print_job);
-	tab->priv->print_job = NULL;
+	if (tab->priv->print_job != NULL)
+	{
+		g_object_unref (tab->priv->print_job);
+		tab->priv->print_job = NULL;
+	}
 }
 
 #if 0



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