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_POINTER,
77 G_TYPE_NONE, 2, EMPATHY_TYPE_FT_HANDLER, G_TYPE_POINTER);
79 signals[NEW_INCOMING_TRANSFER] =
80 g_signal_new ("new-incoming-transfer",
81 G_TYPE_FROM_CLASS (klass),
84 _empathy_marshal_VOID__OBJECT_POINTER,
85 G_TYPE_NONE, 2, EMPATHY_TYPE_FT_HANDLER, G_TYPE_POINTER);
89 empathy_ft_factory_init (EmpathyFTFactory *self)
95 ft_handler_outgoing_ready_cb (EmpathyFTHandler *handler,
99 EmpathyFTFactory *factory = user_data;
101 g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, error);
105 ft_handler_incoming_ready_cb (EmpathyFTHandler *handler,
109 EmpathyFTFactory *factory = user_data;
111 g_signal_emit (factory, signals[NEW_INCOMING_TRANSFER], 0, handler, error);
117 empathy_ft_factory_dup_singleton (void)
119 return g_object_new (EMPATHY_TYPE_FT_FACTORY, NULL);
123 empathy_ft_factory_new_transfer_outgoing (EmpathyFTFactory *factory,
124 EmpathyContact *contact,
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 (source));
132 empathy_ft_handler_new_outgoing (contact, source, use_hash,
133 ft_handler_outgoing_ready_cb, factory);
137 empathy_ft_factory_claim_channel (EmpathyFTFactory *factory,
138 EmpathyDispatchOperation *operation)
140 EmpathyTpFile *tp_file;
142 g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
143 g_return_if_fail (EMPATHY_IS_DISPATCH_OPERATION (operation));
145 /* own a reference to the EmpathyTpFile */
146 tp_file = EMPATHY_TP_FILE
147 ((empathy_dispatch_operation_get_channel_wrapper (operation)));
149 empathy_ft_handler_new_incoming (tp_file, ft_handler_incoming_ready_cb,
152 empathy_dispatch_operation_claim (operation);
156 empathy_ft_factory_set_destination_for_incoming_handler
157 (EmpathyFTFactory *factory,
158 EmpathyFTHandler *handler,
162 g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
163 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
164 g_return_if_fail (G_IS_FILE (destination));
166 empathy_ft_handler_incoming_set_destination (handler, destination, use_hash);
168 g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, FALSE);