]> git.0d.be Git - empathy.git/blob - libempathy/empathy-ft-factory.c
Initial commit for EmpathyFTFactory and EmpathyFTHandler.
[empathy.git] / libempathy / empathy-ft-factory.c
1 /*
2  * empathy-ft-factory.c - Source for EmpathyFTFactory
3  * Copyright (C) 2009 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Author: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
20  */
21  
22 /* empathy-ft-factory.c */
23
24 #include "empathy-ft-factory.h"
25 #include "empathy-marshal.h"
26 #include "empathy-utils.h"
27
28 G_DEFINE_TYPE (EmpathyFTFactory, empathy_ft_factory, G_TYPE_OBJECT);
29
30 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTFactoryPriv)
31
32 enum {
33   NEW_FT_HANDLER,
34   LAST_SIGNAL
35 }
36
37 typedef struct {
38   gboolean dispose_run;
39 } EmpathyFTFactoryPriv;
40
41 static EmpathyFTFactory *factory_singleton = NULL;
42 static guint signals[LAST_SIGNAL] = { 0 };
43
44 static void
45 do_dispose (GObject *object)
46 {
47   EmpathyFTFactoryPriv *priv = GET_PRIV (object);
48
49   if (priv->dispose_run)
50     return;
51
52   priv->dispose_run = TRUE;
53
54   G_OBJECT_CLASS (empathy_ft_factory_parent_class)->dispose (object);
55 }
56
57 static void
58 do_finalize (GObject *object)
59 {
60   G_OBJECT_CLASS (empathy_ft_factory_parent_class)->finalize (object);
61 }
62
63 static GObject *
64 do_constructor (GType type,
65                 guint n_props,
66                 GObjectConstructParam *props)
67 {
68         GObject *retval;
69
70         if (factory_singleton) {
71                 retval = g_object_ref (factory_singleton);
72         } else {
73                 retval = G_OBJECT_CLASS (empathy_ft_factory_parent_class)->constructor
74                         (type, n_props, props);
75
76                 factory_singleton = EMPATHY_FT_FACTORY (retval);
77                 g_object_add_weak_pointer (retval, (gpointer *) &factory_singleton);
78         }
79
80         return retval;
81 }
82
83 static void
84 empathy_ft_factory_class_init (EmpathyFTFactoryClass *klass)
85 {
86   GObjectClass *object_class = G_OBJECT_CLASS (klass);
87
88   g_type_class_add_private (klass, sizeof (EmpathyFTFactoryPriv));
89
90   object_class->dispose = do_dispose;
91   object_class->finalize = do_finalize;
92   object_class->constructor = do_constructor;
93
94   signals[NEW_FT_HANDLER] =
95     g_signal_new ("new-ft-handler",
96       G_TYPE_FROM_CLASS (empathy_call_factory_class),
97       G_SIGNAL_RUN_LAST, 0,
98       NULL, NULL,
99       _empathy_marshal_VOID__OBJECT_BOOLEAN,
100       G_TYPE_NONE,
101       2, EMPATHY_TYPE_FT_HANDLER, G_TYPE_BOOLEAN);
102 }
103
104 static void
105 empathy_ft_factory_init (EmpathyFTFactory *self)
106 {
107   EmpathyFTFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
108     EMPATHY_TYPE_FT_FACTORY, EmpathyFTFactoryPriv);
109
110   self->priv = priv;
111 }
112
113 /* public methods */
114
115 EmpathyFTFactory*
116 empathy_ft_factory_dup_singleton (void)
117 {
118   return g_object_new (EMPATHY_TYPE_FT_FACTORY, NULL);
119 }
120
121 void
122 empathy_ft_factory_new_transfer (EmpathyFTFactory *factory,
123                                  EmpathyContact *contact,
124                                  GFile *file)
125 {
126   EmpathyFTHandler *handler;
127
128   g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
129   g_return_if_fail (EMPATHY_IS_CONTACT (contact));
130   g_return_if_fail (G_IS_FILE (file));
131
132   handler = empathy_ft_handler_new (contact, file);
133   g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, TRUE);
134
135   g_object_unref (handler);
136 }
137
138 void
139 empathy_ft_factory_claim_channel (EmpathyFTFactory *factory,
140                                   EmpathyDispatchOperation *operation)
141 {
142   g_return_val_if_fail (EMPATHY_IS_FACTORY (factory));
143   g_return_val_if_fail (EMPATHY_IS_DISPATCH_OPERATION (operation));
144
145   /* TODO */
146 }
147