]> git.0d.be Git - empathy.git/blob - libempathy/empathy-call-factory.c
9e7272409535ae2f72e55bebef0299467ad6904d
[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
28 G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, G_TYPE_OBJECT)
29
30 /* signal enum */
31 enum
32 {
33     NEW_CALL_HANDLER,
34     LAST_SIGNAL
35 };
36
37 static guint signals[LAST_SIGNAL] = {0};
38
39 /* private structure */
40 typedef struct _EmpathyCallFactoryPrivate EmpathyCallFactoryPrivate;
41
42 struct _EmpathyCallFactoryPrivate
43 {
44   gboolean dispose_has_run;
45 };
46
47 #define EMPATHY_CALL_FACTORY_GET_PRIVATE(o)  \
48  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
49   EMPATHY_TYPE_CALL_FACTORY, EmpathyCallFactoryPrivate))
50
51 static void
52 empathy_call_factory_init (EmpathyCallFactory *obj)
53 {
54   //EmpathyCallFactoryPrivate *priv = EMPATHY_CALL_FACTORY_GET_PRIVATE (obj);
55
56   /* allocate any data required by the object here */
57 }
58
59 static void empathy_call_factory_dispose (GObject *object);
60 static void empathy_call_factory_finalize (GObject *object);
61
62 static GObject *call_factory = NULL;
63
64 static GObject *
65 empathy_call_factory_constructor (GType type, guint n_construct_params,
66   GObjectConstructParam *construct_params)
67 {
68   g_return_val_if_fail (call_factory == NULL, NULL);
69
70   call_factory = G_OBJECT_CLASS (empathy_call_factory_parent_class)->constructor
71           (type, n_construct_params, construct_params);
72   g_object_add_weak_pointer (call_factory, (gpointer *)&call_factory);
73
74   return call_factory;
75 }
76
77 static void
78 empathy_call_factory_class_init (
79   EmpathyCallFactoryClass *empathy_call_factory_class)
80 {
81   GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_factory_class);
82
83   g_type_class_add_private (empathy_call_factory_class,
84     sizeof (EmpathyCallFactoryPrivate));
85
86   object_class->constructor = empathy_call_factory_constructor;
87   object_class->dispose = empathy_call_factory_dispose;
88   object_class->finalize = empathy_call_factory_finalize;
89
90   signals[NEW_CALL_HANDLER] =
91     g_signal_new ("new-call-handler",
92       G_TYPE_FROM_CLASS (empathy_call_factory_class),
93       G_SIGNAL_RUN_LAST, 0,
94       NULL, NULL,
95       _empathy_marshal_VOID__OBJECT_BOOLEAN,
96       G_TYPE_NONE,
97       2, EMPATHY_TYPE_CALL_HANDLER, G_TYPE_BOOLEAN);
98 }
99
100 void
101 empathy_call_factory_dispose (GObject *object)
102 {
103   EmpathyCallFactory *self = EMPATHY_CALL_FACTORY (object);
104   EmpathyCallFactoryPrivate *priv = EMPATHY_CALL_FACTORY_GET_PRIVATE (self);
105
106   if (priv->dispose_has_run)
107     return;
108
109   priv->dispose_has_run = TRUE;
110
111   /* release any references held by the object here */
112
113   if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose)
114     G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose (object);
115 }
116
117 void
118 empathy_call_factory_finalize (GObject *object)
119 {
120   //EmpathyCallFactory *self = EMPATHY_CALL_FACTORY (object);
121   //EmpathyCallFactoryPrivate *priv = EMPATHY_CALL_FACTORY_GET_PRIVATE (self);
122
123   /* free any data held directly by the object here */
124
125   G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize (object);
126 }
127
128 EmpathyCallFactory *
129 empathy_call_factory_initialise (void)
130 {
131   g_return_val_if_fail (call_factory == NULL, NULL);
132
133   return EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY, NULL));
134 }
135
136 EmpathyCallFactory *
137 empathy_call_factory_get (void)
138 {
139   g_return_val_if_fail (call_factory != NULL, NULL);
140
141   return EMPATHY_CALL_FACTORY (call_factory);
142 }
143
144 EmpathyCallHandler *
145 empathy_call_factory_new_call (EmpathyCallFactory *factory,
146   EmpathyContact *contact)
147 {
148   EmpathyCallHandler *handler;
149
150   g_return_val_if_fail (factory != NULL, NULL);
151   g_return_val_if_fail (contact != NULL, NULL);
152
153   handler = empathy_call_handler_new_for_contact (contact);
154
155   g_signal_emit (G_OBJECT (factory), signals[NEW_CALL_HANDLER], 0,
156     handler, TRUE);
157
158   return handler;
159 }
160
161 EmpathyCallHandler *
162 empathy_call_factory_claim_channel (EmpathyCallFactory *factory,
163   EmpathyDispatchOperation *operation)
164 {
165   EmpathyCallHandler *handler;
166   EmpathyTpCall *call;
167
168   g_return_val_if_fail (factory != NULL, NULL);
169   g_return_val_if_fail (operation != NULL, NULL);
170
171   call = EMPATHY_TP_CALL (
172     empathy_dispatch_operation_get_channel_wrapper (operation));
173
174   handler = empathy_call_handler_new_for_channel (call);
175   empathy_dispatch_operation_claim (operation);
176
177   /* FIXME should actually look at the channel */
178   g_signal_emit (G_OBJECT (factory), signals[NEW_CALL_HANDLER], 0,
179     handler, FALSE);
180
181   return handler;
182 }
183