Improve default display name for Facebook accounts
[empathy-mirror.git] / libempathy / empathy-call-factory.c
blobd02b58327d645e953642ea3e9585228afbe2cbe1
1 /*
2 * empathy-call-factory.c - Source for EmpathyCallFactory
3 * Copyright (C) 2008 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <stdio.h>
23 #include <stdlib.h>
25 #include "empathy-marshal.h"
26 #include "empathy-call-factory.h"
27 #include "empathy-utils.h"
29 G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, G_TYPE_OBJECT)
31 /* signal enum */
32 enum
34 NEW_CALL_HANDLER,
35 LAST_SIGNAL
38 static guint signals[LAST_SIGNAL] = {0};
40 /* private structure */
41 typedef struct {
42 gboolean dispose_has_run;
43 } EmpathyCallFactoryPriv;
45 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallFactory)
47 static GObject *call_factory = NULL;
49 static void
50 empathy_call_factory_init (EmpathyCallFactory *obj)
52 EmpathyCallFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
53 EMPATHY_TYPE_CALL_FACTORY, EmpathyCallFactoryPriv);
55 obj->priv = priv;
58 static GObject *
59 empathy_call_factory_constructor (GType type, guint n_construct_params,
60 GObjectConstructParam *construct_params)
62 g_return_val_if_fail (call_factory == NULL, NULL);
64 call_factory = G_OBJECT_CLASS (empathy_call_factory_parent_class)->constructor
65 (type, n_construct_params, construct_params);
66 g_object_add_weak_pointer (call_factory, (gpointer)&call_factory);
68 return call_factory;
71 static void
72 empathy_call_factory_finalize (GObject *object)
74 /* free any data held directly by the object here */
76 if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize)
77 G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize (object);
80 static void
81 empathy_call_factory_dispose (GObject *object)
83 EmpathyCallFactoryPriv *priv = GET_PRIV (object);
85 if (priv->dispose_has_run)
86 return;
88 priv->dispose_has_run = TRUE;
90 /* release any references held by the object here */
92 if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose)
93 G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose (object);
96 static void
97 empathy_call_factory_class_init (
98 EmpathyCallFactoryClass *empathy_call_factory_class)
100 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_factory_class);
102 g_type_class_add_private (empathy_call_factory_class,
103 sizeof (EmpathyCallFactoryPriv));
105 object_class->constructor = empathy_call_factory_constructor;
106 object_class->dispose = empathy_call_factory_dispose;
107 object_class->finalize = empathy_call_factory_finalize;
109 signals[NEW_CALL_HANDLER] =
110 g_signal_new ("new-call-handler",
111 G_TYPE_FROM_CLASS (empathy_call_factory_class),
112 G_SIGNAL_RUN_LAST, 0,
113 NULL, NULL,
114 _empathy_marshal_VOID__OBJECT_BOOLEAN,
115 G_TYPE_NONE,
116 2, EMPATHY_TYPE_CALL_HANDLER, G_TYPE_BOOLEAN);
119 EmpathyCallFactory *
120 empathy_call_factory_initialise (void)
122 g_return_val_if_fail (call_factory == NULL, NULL);
124 return EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY, NULL));
127 EmpathyCallFactory *
128 empathy_call_factory_get (void)
130 g_return_val_if_fail (call_factory != NULL, NULL);
132 return EMPATHY_CALL_FACTORY (call_factory);
136 * empathy_call_factory_new_call_with_streams:
137 * @factory: an #EmpathyCallFactory
138 * @contact: an #EmpathyContact
139 * @initial_audio: if %TRUE the call will be started with audio
140 * @initial_video: if %TRUE the call will be started with video
142 * Initiate a new call with @contact.
144 void
145 empathy_call_factory_new_call_with_streams (EmpathyCallFactory *factory,
146 EmpathyContact *contact,
147 gboolean initial_audio,
148 gboolean initial_video)
150 EmpathyCallHandler *handler;
152 g_return_if_fail (factory != NULL);
153 g_return_if_fail (contact != NULL);
155 handler = empathy_call_handler_new_for_contact_with_streams (contact,
156 initial_audio, initial_video);
158 g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
159 handler, TRUE);
161 g_object_unref (handler);
166 * empathy_call_factory_new_call:
167 * @factory: an #EmpathyCallFactory
168 * @contact: an #EmpathyContact
170 * Initiate a new call with @contact.
172 void
173 empathy_call_factory_new_call (EmpathyCallFactory *factory,
174 EmpathyContact *contact)
176 empathy_call_factory_new_call_with_streams (factory, contact, TRUE, FALSE);
179 void
180 empathy_call_factory_claim_channel (EmpathyCallFactory *factory,
181 EmpathyDispatchOperation *operation)
183 EmpathyCallHandler *handler;
184 EmpathyTpCall *call;
186 g_return_if_fail (factory != NULL);
187 g_return_if_fail (operation != NULL);
189 call = EMPATHY_TP_CALL (
190 empathy_dispatch_operation_get_channel_wrapper (operation));
192 handler = empathy_call_handler_new_for_channel (call);
193 empathy_dispatch_operation_claim (operation);
195 /* FIXME should actually look at the channel */
196 g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
197 handler, FALSE);
199 g_object_unref (handler);