2 * Copyright (C) 2010 Collabora Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
19 * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
22 #include "empathy-channel-factory.h"
24 #include "empathy-tp-chat.h"
25 #include "empathy-utils.h"
27 #include <telepathy-glib/telepathy-glib.h>
29 static void factory_iface_init (gpointer, gpointer);
31 G_DEFINE_TYPE_WITH_CODE (EmpathyChannelFactory, empathy_channel_factory,
33 G_IMPLEMENT_INTERFACE (TP_TYPE_CLIENT_CHANNEL_FACTORY, factory_iface_init))
35 struct _EmpathyChannelFactoryPrivate
37 TpClientChannelFactory *automatic_factory;
41 empathy_channel_factory_dispose (GObject *object)
43 EmpathyChannelFactory *self = EMPATHY_CHANNEL_FACTORY (object);
44 void (*dispose) (GObject *) =
45 G_OBJECT_CLASS (empathy_channel_factory_parent_class)->dispose;
47 tp_clear_object (&self->priv->automatic_factory);
54 empathy_channel_factory_class_init (EmpathyChannelFactoryClass *cls)
56 GObjectClass *object_class = G_OBJECT_CLASS (cls);
58 g_type_class_add_private (cls, sizeof (EmpathyChannelFactoryPrivate));
60 object_class->dispose = empathy_channel_factory_dispose;
64 empathy_channel_factory_init (EmpathyChannelFactory *self)
66 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
67 EMPATHY_TYPE_CHANNEL_FACTORY, EmpathyChannelFactoryPrivate);
69 self->priv->automatic_factory = TP_CLIENT_CHANNEL_FACTORY (
70 tp_automatic_proxy_factory_dup ());
73 EmpathyChannelFactory *
74 empathy_channel_factory_new (void)
76 return g_object_new (EMPATHY_TYPE_CHANNEL_FACTORY,
80 EmpathyChannelFactory *
81 empathy_channel_factory_dup (void)
83 static EmpathyChannelFactory *singleton = NULL;
85 if (singleton != NULL)
86 return g_object_ref (singleton);
88 singleton = empathy_channel_factory_new ();
90 g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer) &singleton);
96 empathy_channel_factory_create_channel (
97 TpClientChannelFactory *factory,
100 GHashTable *properties,
103 EmpathyChannelFactory *self = (EmpathyChannelFactory *) factory;
104 const gchar *chan_type;
106 chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE);
108 if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
112 account = empathy_get_account_for_connection (conn);
114 return TP_CHANNEL (empathy_tp_chat_new (account, conn, path, properties));
117 return tp_client_channel_factory_create_channel (
118 self->priv->automatic_factory, conn, path, properties, error);
122 empathy_channel_factory_dup_channel_features (
123 TpClientChannelFactory *factory,
126 EmpathyChannelFactory *self = (EmpathyChannelFactory *) factory;
130 features = tp_client_channel_factory_dup_channel_features (
131 self->priv->automatic_factory, channel);
133 if (EMPATHY_IS_TP_CHAT (channel))
135 feature = TP_CHANNEL_FEATURE_CHAT_STATES;
136 g_array_append_val (features, feature);
143 factory_iface_init (gpointer g_iface,
144 gpointer unused G_GNUC_UNUSED)
146 TpClientChannelFactoryInterface *iface = g_iface;
148 iface->obj_create_channel = empathy_channel_factory_create_channel;
149 iface->obj_dup_channel_features =
150 empathy_channel_factory_dup_channel_features;