diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-09 18:06:19 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-09 18:06:19 +0800 |
commit | 90aaa7510e765521b3cb4d49349b62766986069a (patch) | |
tree | 151506f88a0555de8876ca95175ae34adb056345 /src | |
parent | 00c9111bef2e541e74eae9f23cbc1d82ad822ea6 (diff) | |
download | gsoc2013-empathy-90aaa7510e765521b3cb4d49349b62766986069a.tar gsoc2013-empathy-90aaa7510e765521b3cb4d49349b62766986069a.tar.gz gsoc2013-empathy-90aaa7510e765521b3cb4d49349b62766986069a.tar.bz2 gsoc2013-empathy-90aaa7510e765521b3cb4d49349b62766986069a.tar.lz gsoc2013-empathy-90aaa7510e765521b3cb4d49349b62766986069a.tar.xz gsoc2013-empathy-90aaa7510e765521b3cb4d49349b62766986069a.tar.zst gsoc2013-empathy-90aaa7510e765521b3cb4d49349b62766986069a.zip |
Port EmpathyFTManager to the new singleton policy.
svn path=/trunk/; revision=2118
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-ft-manager.c | 43 | ||||
-rw-r--r-- | src/empathy-ft-manager.h | 2 | ||||
-rw-r--r-- | src/empathy.c | 2 |
3 files changed, 32 insertions, 15 deletions
diff --git a/src/empathy-ft-manager.c b/src/empathy-ft-manager.c index 3bc812621..8cbfd8502 100644 --- a/src/empathy-ft-manager.c +++ b/src/empathy-ft-manager.c @@ -94,6 +94,8 @@ enum G_DEFINE_TYPE (EmpathyFTManager, empathy_ft_manager, G_TYPE_OBJECT); +static EmpathyFTManager *manager_singleton = NULL; + static gchar * ft_manager_format_interval (gint interval) { @@ -768,36 +770,51 @@ empathy_ft_manager_init (EmpathyFTManager *ft_manager) ft_manager_build_ui (ft_manager); } +static GObject * +empathy_ft_manager_constructor (GType type, + guint n_props, + GObjectConstructParam *props) +{ + GObject *retval; + + if (manager_singleton) + { + retval = g_object_ref (manager_singleton); + } + else + { + retval = G_OBJECT_CLASS (empathy_ft_manager_parent_class)->constructor + (type, n_props, props); + g_object_add_weak_pointer (retval, (gpointer *) &retval); + + manager_singleton = EMPATHY_FT_MANAGER (retval); + } + + return retval; +} + static void empathy_ft_manager_class_init (EmpathyFTManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = empathy_ft_manager_finalize; + object_class->constructor = empathy_ft_manager_constructor; g_type_class_add_private (object_class, sizeof (EmpathyFTManagerPriv)); } /** - * empathy_ft_manager_get_default: + * empathy_ft_manager_dup_singleton: * - * Returns a new #EmpathyFTManager if there is not already one, or the existing - * one if it exists. + * Returns a reference to the #EmpathyFTManager singleton object. * * Returns: a #EmpathyFTManager */ EmpathyFTManager * -empathy_ft_manager_get_default (void) +empathy_ft_manager_dup_singleton (void) { - static EmpathyFTManager *manager_p = NULL; - - if (!manager_p) - { - manager_p = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL); - g_object_add_weak_pointer (G_OBJECT (manager_p), (gpointer) &manager_p); - } - - return manager_p; + return g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL); } /** diff --git a/src/empathy-ft-manager.h b/src/empathy-ft-manager.h index d8cab58d7..4803bc814 100644 --- a/src/empathy-ft-manager.h +++ b/src/empathy-ft-manager.h @@ -58,7 +58,7 @@ struct _EmpathyFTManagerClass GType empathy_ft_manager_get_type (void); -EmpathyFTManager *empathy_ft_manager_get_default (void); +EmpathyFTManager *empathy_ft_manager_dup_singleton (void); void empathy_ft_manager_add_tp_file (EmpathyFTManager *ft_manager, EmpathyTpFile *tp_file); GtkWidget *empathy_ft_manager_get_dialog (EmpathyFTManager *ft_manager); diff --git a/src/empathy.c b/src/empathy.c index e449247ac..412c1efa6 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -110,7 +110,7 @@ dispatch_channel_cb (EmpathyDispatcher *dispatcher, EmpathyFTManager *ft_manager; EmpathyTpFile *tp_file; - ft_manager = empathy_ft_manager_get_default (); + ft_manager = empathy_ft_manager_dup_singleton (); tp_file = empathy_tp_file_new (channel); empathy_ft_manager_add_tp_file (ft_manager, tp_file); g_object_unref (tp_file); |