2 * empathy-ft-factory.c - Source for EmpathyFTFactory
3 * Copyright (C) 2009 Collabora Ltd.
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.
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.
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
19 * Author: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
22 /* empathy-ft-factory.c */
26 #include "empathy-ft-factory.h"
27 #include "empathy-ft-handler.h"
28 #include "empathy-marshal.h"
29 #include "empathy-utils.h"
31 G_DEFINE_TYPE (EmpathyFTFactory, empathy_ft_factory, G_TYPE_OBJECT);
33 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTFactory)
37 NEW_INCOMING_TRANSFER,
41 static EmpathyFTFactory *factory_singleton = NULL;
42 static guint signals[LAST_SIGNAL] = { 0 };
45 do_constructor (GType type,
47 GObjectConstructParam *props)
51 if (factory_singleton) {
52 retval = g_object_ref (factory_singleton);
54 retval = G_OBJECT_CLASS (empathy_ft_factory_parent_class)->constructor
55 (type, n_props, props);
57 factory_singleton = EMPATHY_FT_FACTORY (retval);
58 g_object_add_weak_pointer (retval, (gpointer *) &factory_singleton);
65 empathy_ft_factory_class_init (EmpathyFTFactoryClass *klass)
67 GObjectClass *object_class = G_OBJECT_CLASS (klass);
69 object_class->constructor = do_constructor;
71 signals[NEW_FT_HANDLER] =
72 g_signal_new ("new-ft-handler",
73 G_TYPE_FROM_CLASS (klass),
76 _empathy_marshal_VOID__OBJECT_BOOLEAN,
78 2, EMPATHY_TYPE_FT_HANDLER, G_TYPE_BOOLEAN);
80 signals[NEW_INCOMING_TRANSFER] =
81 g_signal_new ("new-incoming-transfer",
82 G_TYPE_FROM_CLASS (klass),
85 g_cclosure_marshal_VOID__OBJECT,
86 G_TYPE_NONE, 1, EMPATHY_TYPE_FT_HANDLER);
90 empathy_ft_factory_init (EmpathyFTFactory *self)
96 ft_handler_outgoing_ready_cb (EmpathyFTHandler *handler,
100 EmpathyFTFactory *factory = user_data;
104 /* TODO: error handling */
108 g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, TRUE);
112 ft_handler_incoming_ready_cb (EmpathyFTHandler *handler,
116 EmpathyFTFactory *factory = user_data;
120 /* TODO: error handling */
124 g_signal_emit (factory, signals[NEW_INCOMING_TRANSFER], 0, handler);
130 empathy_ft_factory_dup_singleton (void)
132 return g_object_new (EMPATHY_TYPE_FT_FACTORY, NULL);
136 empathy_ft_factory_new_transfer_outgoing (EmpathyFTFactory *factory,
137 EmpathyContact *contact,
140 g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
141 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
142 g_return_if_fail (G_IS_FILE (source));
144 empathy_ft_handler_new_outgoing (contact, source,
145 ft_handler_outgoing_ready_cb, factory);
149 empathy_ft_factory_claim_channel (EmpathyFTFactory *factory,
150 EmpathyDispatchOperation *operation)
152 EmpathyTpFile *tp_file;
154 g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
155 g_return_if_fail (EMPATHY_IS_DISPATCH_OPERATION (operation));
157 /* own a reference to the EmpathyTpFile */
158 tp_file = EMPATHY_TP_FILE
159 ((empathy_dispatch_operation_get_channel_wrapper (operation)));
161 empathy_ft_handler_new_incoming (tp_file, ft_handler_incoming_ready_cb,
164 empathy_dispatch_operation_claim (operation);
168 empathy_ft_factory_set_destination_for_incoming_handler
169 (EmpathyFTFactory *factory,
170 EmpathyFTHandler *handler,
173 g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
174 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
175 g_return_if_fail (G_IS_FILE (destination));
177 empathy_ft_handler_incoming_set_destination (handler, destination);
179 g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, FALSE);