2 * empathy-ft-handler.c - Source for EmpathyFTHandler
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-handler.c */
24 #include "empathy-ft-handler.h"
26 G_DEFINE_TYPE (EmpathyFTHandler, empathy_ft_handler, G_TYPE_OBJECT)
28 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTHandlerPriv)
36 typedef struct EmpathyFTHandlerPriv {
38 EmpathyContact *contact;
40 EmpathyTpFile *tpfile;
44 do_get_property (GObject *object,
49 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
54 g_value_set_object (value, priv->contact);
57 g_value_set_object (value, priv->gfile);
60 g_value_set_object (value, priv->tpfile);
63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68 do_set_property (GObject *object,
73 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
78 priv->contact = g_value_dup_object (value);
81 priv->gfile = g_value_dup_object (value);
84 priv->tpfile = g_value_dup_object (value);
87 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
92 do_dispose (GObject *object)
94 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
96 if (priv->dispose_run)
99 priv->dispose_run = TRUE;
102 g_object_unref (priv->contact);
103 priv->contact = NULL;
107 g_object_unref (priv->gfile);
112 empathy_tp_file_close (priv->tpfile);
113 g_object_unref (priv->tpfile);
117 G_OBJECT_CLASS (empathy_ft_handler_parent_class)->dispose (object);
121 do_finalize (GObject *object)
123 G_OBJECT_CLASS (empathy_ft_handler_parent_class)->finalize (object);
127 empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
129 GObjectClass *object_class = G_OBJECT_CLASS (klass);
130 GParamSpec *param_spec;
132 g_type_class_add_private (klass, sizeof (EmpathyFTHandlerPrivate));
134 object_class->get_property = do_get_property;
135 object_class->set_property = do_set_property;
136 object_class->dispose = do_dispose;
137 object_class->finalize = do_finalize;
139 param_spec = g_param_spec_object ("contact",
140 "contact", "The remote contact",
141 EMPATHY_TYPE_CONTACT,
142 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
143 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
145 param_spec = g_param_spec_object ("gfile",
146 "gfile", "The GFile we're handling",
148 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
149 g_object_class_install_property (object_class, PROP_G_FILE, param_spec);
151 param_spec = g_param_spec_object ("tp-file",
152 "tp-file", "The file's channel wrapper",
153 EMPATHY_TYPE_TP_FILE,
154 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
155 g_object_class_install_property (object_class, PROP_TP_FILE, param_spec);
159 empathy_ft_handler_init (EmpathyFTHandler *self)
161 EmpathyFTHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
162 EMPATHY_TYPE_FT_HANDLER, EmpathyFTHandlerPriv);
168 empathy_ft_handler_contact_ready_cb (EmpathyContact *contact,
171 GObject *weak_object);
173 EmpathyFTHandler *handler = EMPATHY_FT_HANDLER (weak_object);
174 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
176 /* start collecting info about the file */
182 empathy_ft_handler_new (EmpathyContact *contact,
185 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
186 g_return_val_if_fail (G_IS_FILE (file), NULL);
188 return g_object_new (EMPATHY_TYPE_FT_HANDLER,
189 "contact", contact, "gfile", file, NULL);
193 empathy_ft_handler_new_for_channel (EmpathyTpFile *file)
195 g_return_val_if_fail (EMPATHY_IS_TP_FILE (file), NULL);
197 return g_object_new (EMPATHY_TYPE_FT_HANDLER,
198 "tp-file", file, NULL);
202 empathy_ft_handler_start_transfer (EmpathyFTHandler *handler)
204 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
206 if (priv->tpfile == NULL)
208 empathy_contact_call_when_ready (priv->contact,
209 EMPATHY_CONTACT_READY_HANDLE,
210 empathy_ft_handler_contact_ready_cb, NULL, NULL, G_OBJECT (handler));