From 63369cbc268ec537649056a04ca334882543fff9 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 14 May 2009 13:04:37 +0200 Subject: Remove the singleton logic from the manager Don't use a singleton logic for the FT Manager, but let the manager itself hold the references according to the state of the toplevel window. --- src/empathy-ft-manager.c | 51 ++++++++++++++++++++++------------------------- src/empathy-ft-manager.h | 10 ++++------ src/empathy-main-window.c | 7 +------ src/empathy.c | 8 +------- 4 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/empathy-ft-manager.c b/src/empathy-ft-manager.c index 1eb3b2d3d..e0b95b263 100644 --- a/src/empathy-ft-manager.c +++ b/src/empathy-ft-manager.c @@ -868,6 +868,8 @@ ft_manager_delete_event_cb (GtkWidget *widget, { EmpathyFTManagerPriv *priv = GET_PRIV (manager); + DEBUG ("%p", manager); + /* remove all the completed/cancelled/errored transfers */ ft_manager_clear (manager); @@ -876,7 +878,7 @@ ft_manager_delete_event_cb (GtkWidget *widget, /* There is still FTs on flight, just hide the window */ DEBUG ("Hiding window"); gtk_widget_hide (widget); - return TRUE; + return TRUE; } return FALSE; @@ -886,6 +888,8 @@ static void ft_manager_destroy_cb (GtkWidget *widget, EmpathyFTManager *manager) { + DEBUG ("%p", manager); + g_object_unref (manager); } @@ -1017,7 +1021,7 @@ empathy_ft_manager_finalize (GObject *object) { EmpathyFTManagerPriv *priv = GET_PRIV (object); - DEBUG ("%p", object); + DEBUG ("FT Manager %p", object); g_hash_table_destroy (priv->ft_handler_to_row_ref); @@ -1053,7 +1057,7 @@ empathy_ft_manager_constructor (GType type, if (manager_singleton) { - retval = g_object_ref (manager_singleton); + retval = G_OBJECT (manager_singleton); } else { @@ -1080,55 +1084,48 @@ empathy_ft_manager_class_init (EmpathyFTManagerClass *klass) /* public methods */ -/** - * empathy_ft_manager_dup_singleton: - * - * Returns a reference to the #EmpathyFTManager singleton object. - * - * Returns: a #EmpathyFTManager - */ -EmpathyFTManager * -empathy_ft_manager_dup_singleton (void) -{ - return g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL); -} - void -empathy_ft_manager_add_handler (EmpathyFTManager *manager, - EmpathyFTHandler *handler) +empathy_ft_manager_add_handler (EmpathyFTHandler *handler) { - EmpathyFTManagerPriv *priv = GET_PRIV (manager); + EmpathyFTManager *manager; + EmpathyFTManagerPriv *priv; DEBUG ("Adding handler"); - g_return_if_fail (EMPATHY_IS_FT_MANAGER (manager)); g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler)); + manager = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL); + priv = GET_PRIV (manager); + ft_manager_add_handler_to_list (manager, handler, NULL); gtk_window_present (GTK_WINDOW (priv->window)); } void -empathy_ft_manager_display_error (EmpathyFTManager *manager, - EmpathyFTHandler *handler, +empathy_ft_manager_display_error (EmpathyFTHandler *handler, const GError *error) { - EmpathyFTManagerPriv *priv = GET_PRIV (manager); + EmpathyFTManager *manager; + EmpathyFTManagerPriv *priv; - g_return_if_fail (EMPATHY_IS_FT_MANAGER (manager)); g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler)); g_return_if_fail (error != NULL); + manager = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL); + priv = GET_PRIV (manager); + ft_manager_add_handler_to_list (manager, handler, error); gtk_window_present (GTK_WINDOW (priv->window)); } void -empathy_ft_manager_show (EmpathyFTManager *manager) +empathy_ft_manager_show (void) { - EmpathyFTManagerPriv *priv = GET_PRIV (manager); + EmpathyFTManager *manager; + EmpathyFTManagerPriv *priv; - g_return_if_fail (EMPATHY_IS_FT_MANAGER (manager)); + manager = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL); + priv = GET_PRIV (manager); gtk_window_present (GTK_WINDOW (priv->window)); } diff --git a/src/empathy-ft-manager.h b/src/empathy-ft-manager.h index 7200f3f08..0ff820f06 100644 --- a/src/empathy-ft-manager.h +++ b/src/empathy-ft-manager.h @@ -61,12 +61,10 @@ struct _EmpathyFTManagerClass { GType empathy_ft_manager_get_type (void); /* public methods */ -EmpathyFTManager *empathy_ft_manager_dup_singleton (void); -void empathy_ft_manager_add_handler (EmpathyFTManager *ft_manager, - EmpathyFTHandler *handler); -void empathy_ft_manager_display_error (EmpathyFTManager *ft_manager, - EmpathyFTHandler *handler, const GError *error); -void empathy_ft_manager_show (EmpathyFTManager *manager); +void empathy_ft_manager_add_handler (EmpathyFTHandler *handler); +void empathy_ft_manager_display_error (EmpathyFTHandler *handler, + const GError *error); +void empathy_ft_manager_show (void); G_END_DECLS diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 43e9224bb..6dcd6975e 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -695,12 +695,7 @@ static void main_window_view_show_ft_manager (GtkAction *action, EmpathyMainWindow *window) { - EmpathyFTManager *manager; - - manager = empathy_ft_manager_dup_singleton (); - empathy_ft_manager_show (manager); - - g_object_unref (manager); + empathy_ft_manager_show (); } static void diff --git a/src/empathy.c b/src/empathy.c index d3cc12ca9..ffdb97949 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -417,10 +417,7 @@ new_ft_handler_cb (EmpathyFTFactory *factory, EmpathyFTHandler *handler, gpointer user_data) { - EmpathyFTManager *ft_manager; - - ft_manager = empathy_ft_manager_dup_singleton (); - empathy_ft_manager_add_handler (ft_manager, handler); + empathy_ft_manager_add_handler (handler); g_object_unref (handler); } @@ -446,7 +443,6 @@ main (int argc, char *argv[]) EmpathyDispatcher *dispatcher; EmpathyLogManager *log_manager; EmpathyChatroomManager *chatroom_manager; - EmpathyFTManager *ft_manager; EmpathyCallFactory *call_factory; EmpathyFTFactory *ft_factory; GtkWidget *window; @@ -596,8 +592,6 @@ main (int argc, char *argv[]) chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL); empathy_chatroom_manager_observe (chatroom_manager, dispatcher); - ft_manager = empathy_ft_manager_dup_singleton (); - notify_init (_(PACKAGE_NAME)); /* Create the call factory */ call_factory = empathy_call_factory_initialise (); -- cgit v1.2.3