]> git.0d.be Git - empathy.git/blob - libempathy/empathy-call-factory.c
add myself to AUTHORS
[empathy.git] / libempathy / empathy-call-factory.c
1 /*
2  * empathy-call-factory.c - Source for EmpathyCallFactory
3  * Copyright (C) 2008 Collabora Ltd.
4  * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
5  *
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.
10  *
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.
15  *
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
19  */
20
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "empathy-marshal.h"
26 #include "empathy-call-factory.h"
27 #include "empathy-utils.h"
28
29 G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, G_TYPE_OBJECT)
30
31 /* signal enum */
32 enum
33 {
34     NEW_CALL_HANDLER,
35     LAST_SIGNAL
36 };
37
38 static guint signals[LAST_SIGNAL] = {0};
39
40 /* private structure */
41 typedef struct {
42   gboolean dispose_has_run;
43 } EmpathyCallFactoryPriv;
44
45 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallFactory)
46
47 static GObject *call_factory = NULL;
48
49 static void
50 empathy_call_factory_init (EmpathyCallFactory *obj)
51 {
52   EmpathyCallFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
53     EMPATHY_TYPE_CALL_FACTORY, EmpathyCallFactoryPriv);
54
55   obj->priv = priv;
56 }
57
58 static GObject *
59 empathy_call_factory_constructor (GType type, guint n_construct_params,
60   GObjectConstructParam *construct_params)
61 {
62   g_return_val_if_fail (call_factory == NULL, NULL);
63
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);
67
68   return call_factory;
69 }
70
71 static void
72 empathy_call_factory_finalize (GObject *object)
73 {
74   /* free any data held directly by the object here */
75
76   if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize)
77     G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize (object);
78 }
79
80 static void
81 empathy_call_factory_dispose (GObject *object)
82 {
83   EmpathyCallFactoryPriv *priv = GET_PRIV (object);
84
85   if (priv->dispose_has_run)
86     return;
87
88   priv->dispose_has_run = TRUE;
89
90   /* release any references held by the object here */
91
92   if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose)
93     G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose (object);
94 }
95
96 static void
97 empathy_call_factory_class_init (
98   EmpathyCallFactoryClass *empathy_call_factory_class)
99 {
100   GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_factory_class);
101
102   g_type_class_add_private (empathy_call_factory_class,
103     sizeof (EmpathyCallFactoryPriv));
104
105   object_class->constructor = empathy_call_factory_constructor;
106   object_class->dispose = empathy_call_factory_dispose;
107   object_class->finalize = empathy_call_factory_finalize;
108
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);
117 }
118
119 EmpathyCallFactory *
120 empathy_call_factory_initialise (void)
121 {
122   g_return_val_if_fail (call_factory == NULL, NULL);
123
124   return EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY, NULL));
125 }
126
127 EmpathyCallFactory *
128 empathy_call_factory_get (void)
129 {
130   g_return_val_if_fail (call_factory != NULL, NULL);
131
132   return EMPATHY_CALL_FACTORY (call_factory);
133 }
134
135 /**
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
141  *
142  * Initiate a new call with @contact.
143  */
144 void
145 empathy_call_factory_new_call_with_streams (EmpathyCallFactory *factory,
146     EmpathyContact *contact,
147     gboolean initial_audio,
148     gboolean initial_video)
149 {
150   EmpathyCallHandler *handler;
151
152   g_return_if_fail (factory != NULL);
153   g_return_if_fail (contact != NULL);
154
155   handler = empathy_call_handler_new_for_contact_with_streams (contact,
156     initial_audio, initial_video);
157
158   g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
159     handler, TRUE);
160
161   g_object_unref (handler);
162 }
163
164
165 /**
166  * empathy_call_factory_new_call:
167  * @factory: an #EmpathyCallFactory
168  * @contact: an #EmpathyContact
169  *
170  * Initiate a new call with @contact.
171  */
172 void
173 empathy_call_factory_new_call (EmpathyCallFactory *factory,
174     EmpathyContact *contact)
175 {
176   empathy_call_factory_new_call_with_streams (factory, contact, TRUE, FALSE);
177 }
178
179 void
180 empathy_call_factory_claim_channel (EmpathyCallFactory *factory,
181   EmpathyDispatchOperation *operation)
182 {
183   EmpathyCallHandler *handler;
184   EmpathyTpCall *call;
185
186   g_return_if_fail (factory != NULL);
187   g_return_if_fail (operation != NULL);
188
189   call = EMPATHY_TP_CALL (
190     empathy_dispatch_operation_get_channel_wrapper (operation));
191
192   handler = empathy_call_handler_new_for_channel (call);
193   empathy_dispatch_operation_claim (operation);
194
195   /* FIXME should actually look at the channel */
196   g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
197     handler, FALSE);
198
199   g_object_unref (handler);
200 }
201