[epiphany] downloader-view: change lifetime logic



commit 355994be201180a7d695844114fb465d0a5b9b39
Author: Diego Escalante Urrelo <descalante igalia com>
Date:   Wed Mar 10 16:43:30 2010 -0500

    downloader-view: change lifetime logic
    
    The DV follows the same goal as before (being alive while there are downloads).
    
    Now every download holds a reference to the DV and releases it when the
    download is removed (finished, cancelled, etc).
    The DV clears its own reference once and only once when a download is removed
    and there are no more downloads in queue.
    
    Bug #611779

 embed/downloader-view.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/embed/downloader-view.c b/embed/downloader-view.c
index 7fbb1e5..db4e8ee 100644
--- a/embed/downloader-view.c
+++ b/embed/downloader-view.c
@@ -69,6 +69,7 @@ struct _DownloaderViewPrivate
 	GtkWidget *abort_button;
 
 	GtkStatusIcon *status_icon;
+	gboolean ownref;
 
 #ifdef HAVE_LIBNOTIFY
 	NotifyNotification *notification;
@@ -225,6 +226,7 @@ remove_download (WebKitDownload *download,
 		webkit_download_cancel (download);
 
 	g_object_unref (download);
+	g_object_unref (dv);
 	return TRUE;
 }
 
@@ -261,6 +263,8 @@ downloader_view_init (DownloaderView *dv)
 
 	downloader_view_build_ui (dv);
 
+	dv->priv->ownref = TRUE;
+
 	show_status_icon (dv);
 
 	g_signal_connect_object (embed_shell, "prepare_close",
@@ -706,7 +710,7 @@ downloader_view_add_download (DownloaderView *dv,
 	update_status_icon (dv);
 
 	selection = gtk_tree_view_get_selection
-		(GTK_TREE_VIEW(dv->priv->treeview));
+		(GTK_TREE_VIEW (dv->priv->treeview));
 	gtk_tree_selection_unselect_all (selection);
 	gtk_tree_selection_select_iter (selection, &iter);
 
@@ -789,9 +793,6 @@ downloader_view_add_download (DownloaderView *dv,
 #endif
 
 	dv->priv->source_id = g_timeout_add (100, (GSourceFunc) update_buttons_timeout_cb, dv);
-
-	/* see above */
-	g_object_unref (dv);
 }
 
 static void
@@ -1038,7 +1039,12 @@ downloader_view_remove_download (DownloaderView *dv, WebKitDownload *download)
 		gtk_widget_set_sensitive (dv->priv->abort_button, FALSE);
 		gtk_widget_set_sensitive (dv->priv->pause_button, FALSE);
 		ephy_dialog_hide (EPHY_DIALOG (dv));
-		g_object_unref (dv);
+
+		if (dv->priv->ownref)
+		{
+			dv->priv->ownref = FALSE;
+			g_object_unref (dv);
+		}
 	}
 }
 



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