]> git.0d.be Git - empathy.git/blob - libempathy/empathy-call-factory.c
08d35f0c2ebf1a7a893c2e42c18b696f333836cc
[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 void
136 empathy_call_factory_new_call (EmpathyCallFactory *factory,
137   EmpathyContact *contact)
138 {
139   EmpathyCallHandler *handler;
140
141   g_return_if_fail (factory != NULL);
142   g_return_if_fail (contact != NULL);
143
144   handler = empathy_call_handler_new_for_contact (contact);
145
146   g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
147     handler, TRUE);
148
149   g_object_unref (handler);
150 }
151
152 void
153 empathy_call_factory_claim_channel (EmpathyCallFactory *factory,
154   EmpathyDispatchOperation *operation)
155 {
156   EmpathyCallHandler *handler;
157   EmpathyTpCall *call;
158
159   g_return_if_fail (factory != NULL);
160   g_return_if_fail (operation != NULL);
161
162   call = EMPATHY_TP_CALL (
163     empathy_dispatch_operation_get_channel_wrapper (operation));
164
165   handler = empathy_call_handler_new_for_channel (call);
166   empathy_dispatch_operation_claim (operation);
167
168   /* FIXME should actually look at the channel */
169   g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
170     handler, FALSE);
171
172   g_object_unref (handler);
173 }
174