]> git.0d.be Git - empathy.git/blob - libempathy/empathy-ft-handler.c
Little cleanup.
[empathy.git] / libempathy / empathy-ft-handler.c
1 /*
2  * empathy-ft-handler.c - Source for EmpathyFTHandler
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-handler.c */
23
24 #include "empathy-ft-handler.h"
25
26 G_DEFINE_TYPE (EmpathyFTHandler, empathy_ft_handler, G_TYPE_OBJECT)
27
28 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTHandlerPriv)
29
30 enum {
31   PROP_TP_FILE = 1,
32   PROP_G_FILE,
33   PROP_CONTACT
34 };
35
36 typedef struct EmpathyFTHandlerPriv {
37   gboolean dispose_run;
38   EmpathyContact *contact;
39   GFile *gfile;
40   EmpathyTpFile *tpfile;
41 };
42
43 static void
44 do_get_property (GObject *object,
45                  guint property_id,
46                  GValue *value,
47                  GParamSpec *pspec)
48 {
49   EmpathyFTHandlerPriv *priv = GET_PRIV (object);
50
51   switch (property_id)
52     {
53       case PROP_CONTACT:
54         g_value_set_object (value, priv->contact);
55         break;
56       case PROP_G_FILE:
57         g_value_set_object (value, priv->gfile);
58         break;
59       case PROP_TP_FILE:
60         g_value_set_object (value, priv->tpfile);
61         break;
62       default:
63         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
64     }
65 }
66
67 static void
68 do_set_property (GObject *object,
69                  guint property_id, 
70                  const GValue *value,
71                  GParamSpec *pspec)
72 {
73   EmpathyCallHandlerPriv *priv = GET_PRIV (object);
74
75   switch (property_id)
76     {
77       case PROP_CONTACT:
78         priv->contact = g_value_dup_object (value);
79         break;
80       case PROP_G_FILE:
81         priv->gfile = g_value_dup_object (value);
82         break;
83       case PROP_TP_FILE:
84         priv->tpfile = g_value_dup_object (value);
85         break;
86       default:
87         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
88     }
89 }
90
91 static void
92 do_dispose (GObject *object)
93 {
94   EmpathyFTHandlerPriv *priv = GET_PRIV (object);
95
96   if (priv->dispose_run)
97     return;
98
99   priv->dispose_run = TRUE;
100
101   if (priv->contact) {
102     g_object_unref (priv->contact);
103     priv->contact = NULL;
104   }
105
106   if (priv->gfile) {
107     g_object_unref (priv->gfile);
108     priv->gfile = NULL;
109   }
110
111   if (priv->tpfile) {
112     empathy_tp_file_close (priv->tpfile);
113     g_object_unref (priv->tpfile);
114     priv->tpfile = NULL;
115   }
116
117   G_OBJECT_CLASS (empathy_ft_handler_parent_class)->dispose (object);
118 }
119
120 static void
121 do_finalize (GObject *object)
122 {
123   G_OBJECT_CLASS (empathy_ft_handler_parent_class)->finalize (object);
124 }
125
126 static void
127 empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
128 {
129   GObjectClass *object_class = G_OBJECT_CLASS (klass);
130   GParamSpec *param_spec;
131
132   g_type_class_add_private (klass, sizeof (EmpathyFTHandlerPrivate));
133
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;
138
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);
144
145   param_spec = g_param_spec_object ("gfile",
146     "gfile", "The GFile we're handling",
147     G_TYPE_FILE,
148     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
149   g_object_class_install_property (object_class, PROP_G_FILE, param_spec);
150
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);
156 }
157
158 static void
159 empathy_ft_handler_init (EmpathyFTHandler *self)
160 {
161   EmpathyFTHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
162     EMPATHY_TYPE_FT_HANDLER, EmpathyFTHandlerPriv);
163
164   self->priv = priv;
165 }
166
167 static void
168 empathy_ft_handler_contact_ready_cb (EmpathyContact *contact,
169                                      const GError *error,
170                                      gpointer user_data,
171                                      GObject *weak_object);
172 {
173   EmpathyFTHandler *handler = EMPATHY_FT_HANDLER (weak_object);
174   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
175
176   /* start collecting info about the file */
177 }
178
179 /* public methods */
180
181 EmpathyFTHandler*
182 empathy_ft_handler_new (EmpathyContact *contact,
183                         GFile *file)
184 {
185   g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
186   g_return_val_if_fail (G_IS_FILE (file), NULL);
187
188   return g_object_new (EMPATHY_TYPE_FT_HANDLER,
189                        "contact", contact, "gfile", file, NULL);
190 }
191
192 EmpathyFTHandler *
193 empathy_ft_handler_new_for_channel (EmpathyTpFile *file)
194 {
195   g_return_val_if_fail (EMPATHY_IS_TP_FILE (file), NULL);
196
197   return g_object_new (EMPATHY_TYPE_FT_HANDLER,
198                        "tp-file", file, NULL);
199 }
200
201 void
202 empathy_ft_handler_start_transfer (EmpathyFTHandler *handler)
203 {
204   g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
205
206   if (priv->tpfile == NULL)
207     {
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));
211     }
212   else
213     {
214       /* TODO: */
215     }
216 }