1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 Collabora Ltd.
4 * Copyright (C) 2007 Marco Barisione <marco@barisione.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Authors: Marco Barisione <marco@barisione.org>
21 * Jonny Lamb <jonny.lamb@collabora.co.uk>
28 #include <sys/types.h>
29 #include <sys/socket.h>
32 #include <glib/gi18n.h>
35 #include <gio/gunixinputstream.h>
36 #include <gio/gunixoutputstream.h>
38 #include <libtelepathy/tp-conn.h>
39 #include <libtelepathy/tp-helpers.h>
40 #include <libtelepathy/tp-props-iface.h>
42 #include <telepathy-glib/proxy-subclass.h>
44 #include "empathy-tp-file.h"
45 #include "empathy-contact-factory.h"
46 #include "empathy-marshal.h"
47 #include "empathy-time.h"
48 #include "empathy-utils.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_FT
51 #include "empathy-debug.h"
54 * SECTION:empathy-tp-file
55 * @short_description: File channel
56 * @see_also: #EmpathyTpFile, #EmpathyContact, empathy_send_file()
57 * @include: libempthy/empathy-tp-file.h
59 * The #EmpathyTpFile object represents a Telepathy file channel.
63 * EMPATHY_TP_FILE_UNKNOWN_SIZE:
65 * Value used for the "size" or "estimated-size" properties when the size of
66 * the transferred file is unknown.
69 /* Functions to copy the content of a GInputStream to a GOutputStream */
72 #define BUFFER_SIZE 4096
77 GCancellable *cancellable;
78 char *buff[N_BUFFERS]; /* the temporary buffers */
79 gsize count[N_BUFFERS]; /* how many bytes are used in the buffers */
80 gboolean is_full[N_BUFFERS]; /* whether the buffers contain data */
81 gint curr_read; /* index of the buffer used for reading */
82 gint curr_write; /* index of the buffer used for writing */
83 gboolean is_reading; /* we are reading */
84 gboolean is_writing; /* we are writing */
85 guint n_closed; /* number of streams that have been closed */
88 static void schedule_next (CopyData *copy);
91 free_copy_data_if_closed (CopyData *copy)
95 /* Free the data only if both the input and output streams have
98 if (copy->n_closed < 2)
101 if (copy->in != NULL)
102 g_object_unref (copy->in);
104 if (copy->out != NULL)
105 g_object_unref (copy->out);
107 for (i = 0; i < N_BUFFERS; i++)
108 g_free (copy->buff[i]);
110 g_object_unref (copy->cancellable);
115 io_error (CopyData *copy,
118 g_cancellable_cancel (copy->cancellable);
121 g_warning ("I/O error");
122 else if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
123 ; /* Ignore cancellations */
125 g_warning ("I/O error: %d: %s\n", error->code, error->message);
127 if (copy->in != NULL)
128 g_input_stream_close (copy->in, NULL, NULL);
130 if (copy->out != NULL)
131 g_output_stream_close (copy->out, NULL, NULL);
133 free_copy_data_if_closed (copy);
137 close_done (GObject *source_object,
141 CopyData *copy = user_data;
143 g_object_unref (source_object);
144 free_copy_data_if_closed (copy);
148 write_done_cb (GObject *source_object,
152 CopyData *copy = user_data;
154 GError *error = NULL;
156 count_write = g_output_stream_write_finish (copy->out, res, &error);
158 if (count_write <= 0)
160 io_error (copy, error);
161 g_error_free (error);
165 copy->is_full[copy->curr_write] = FALSE;
166 copy->curr_write = (copy->curr_write + 1) % N_BUFFERS;
167 copy->is_writing = FALSE;
169 schedule_next (copy);
173 read_done_cb (GObject *source_object,
177 CopyData *copy = user_data;
179 GError *error = NULL;
181 count_read = g_input_stream_read_finish (copy->in, res, &error);
185 g_input_stream_close_async (copy->in, 0, copy->cancellable,
189 else if (count_read < 0)
191 io_error (copy, error);
192 g_error_free (error);
196 copy->count[copy->curr_read] = count_read;
197 copy->is_full[copy->curr_read] = TRUE;
198 copy->curr_read = (copy->curr_read + 1) % N_BUFFERS;
199 copy->is_reading = FALSE;
201 schedule_next (copy);
205 schedule_next (CopyData *copy)
207 if (copy->in != NULL &&
209 !copy->is_full[copy->curr_read])
211 /* We are not reading and the current buffer is empty, so
212 * start an async read. */
213 copy->is_reading = TRUE;
214 g_input_stream_read_async (copy->in,
215 copy->buff[copy->curr_read],
216 BUFFER_SIZE, 0, copy->cancellable,
220 if (!copy->is_writing &&
221 copy->is_full[copy->curr_write])
223 if (copy->count[copy->curr_write] == 0)
225 /* The last read on the buffer read 0 bytes, this
226 * means that we got an EOF, so we can close
227 * the output channel. */
228 g_output_stream_close_async (copy->out, 0,
235 /* We are not writing and the current buffer contains
236 * data, so start an async write. */
237 copy->is_writing = TRUE;
238 g_output_stream_write_async (copy->out,
239 copy->buff[copy->curr_write],
240 copy->count[copy->curr_write],
241 0, copy->cancellable,
242 write_done_cb, copy);
248 copy_stream (GInputStream *in,
250 GCancellable *cancellable)
255 g_return_if_fail (in != NULL);
256 g_return_if_fail (out != NULL);
258 copy = g_new0 (CopyData, 1);
259 copy->in = g_object_ref (in);
260 copy->out = g_object_ref (out);
262 if (cancellable != NULL)
263 copy->cancellable = g_object_ref (cancellable);
265 copy->cancellable = g_cancellable_new ();
267 for (i = 0; i < N_BUFFERS; i++)
268 copy->buff[i] = g_malloc (BUFFER_SIZE);
270 schedule_next (copy);
273 /* EmpathyTpFile object */
275 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
276 EMPATHY_TYPE_TP_FILE, EmpathyTpFilePriv))
278 typedef struct _EmpathyTpFilePriv EmpathyTpFilePriv;
280 struct _EmpathyTpFilePriv {
281 EmpathyContactFactory *factory;
287 EmpathyTpFile *cached_empathy_file;
288 EmpathyContact *contact;
289 GInputStream *in_stream;
290 GOutputStream *out_stream;
293 EmpFileTransferState state;
294 EmpFileTransferStateChangeReason state_change_reason;
296 guint64 transferred_bytes;
298 gchar *unix_socket_path;
300 EmpFileHashType content_hash_type;
303 GCancellable *cancellable;
315 PROP_TRANSFERRED_BYTES,
316 PROP_CONTENT_HASH_TYPE,
321 G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT);
324 empathy_tp_file_init (EmpathyTpFile *tp_file)
329 tp_file_destroy_cb (TpChannel *file_channel,
330 EmpathyTpFile *tp_file)
332 EmpathyTpFilePriv *priv;
334 priv = GET_PRIV (tp_file);
336 DEBUG ("Channel Closed or CM crashed");
338 g_object_unref (priv->channel);
339 priv->channel = NULL;
343 tp_file_finalize (GObject *object)
345 EmpathyTpFilePriv *priv;
346 EmpathyTpFile *tp_file;
348 tp_file = EMPATHY_TP_FILE (object);
349 priv = GET_PRIV (tp_file);
353 DEBUG ("Closing channel..");
354 g_signal_handlers_disconnect_by_func (priv->channel,
355 tp_file_destroy_cb, object);
356 tp_cli_channel_call_close (priv->channel, -1, NULL, NULL, NULL, NULL);
357 if (G_IS_OBJECT (priv->channel))
358 g_object_unref (priv->channel);
363 g_object_unref (priv->factory);
367 g_object_unref (priv->account);
371 g_object_unref (priv->mc);
375 g_free (priv->filename);
376 g_free (priv->unix_socket_path);
377 g_free (priv->description);
378 g_free (priv->content_hash);
379 g_free (priv->content_type);
382 g_object_unref (priv->in_stream);
384 if (priv->out_stream)
385 g_object_unref (priv->out_stream);
388 g_object_unref (priv->contact);
390 if (priv->cancellable)
391 g_object_unref (priv->cancellable);
393 G_OBJECT_CLASS (empathy_tp_file_parent_class)->finalize (object);
397 tp_file_get_all_cb (TpProxy *proxy,
398 GHashTable *properties,
401 GObject *weak_object)
403 EmpathyTpFilePriv *priv = (EmpathyTpFilePriv *) user_data;
407 DEBUG ("Failed to get properties: %s", error->message);
411 priv->size = g_value_get_uint64 (
412 g_hash_table_lookup (properties, "Size"));
414 priv->state = g_value_get_uint (
415 g_hash_table_lookup (properties, "State"));
417 /* Invalid reason, so empathy_file_get_state_change_reason() can give
418 * a warning if called for a not closed file transfer. */
419 priv->state_change_reason = -1;
421 priv->transferred_bytes = g_value_get_uint64 (
422 g_hash_table_lookup (properties, "TransferredBytes"));
424 priv->filename = g_value_dup_string (
425 g_hash_table_lookup (properties, "Filename"));
427 priv->content_hash = g_value_dup_string (
428 g_hash_table_lookup (properties, "ContentHash"));
430 priv->description = g_value_dup_string (
431 g_hash_table_lookup (properties, "Description"));
433 if (priv->state == EMP_FILE_TRANSFER_STATE_LOCAL_PENDING)
434 priv->incoming = TRUE;
436 g_hash_table_destroy (properties);
440 tp_file_closed_cb (TpChannel *file_channel,
441 EmpathyTpFile *tp_file,
442 GObject *weak_object)
444 EmpathyTpFilePriv *priv;
446 priv = GET_PRIV (tp_file);
448 /* The channel is closed, do just like if the proxy was destroyed */
449 g_signal_handlers_disconnect_by_func (priv->channel,
452 tp_file_destroy_cb (file_channel, tp_file);
460 g_get_current_time (&tv);
461 return ((gint64) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
465 _get_local_socket (EmpathyTpFile *tp_file)
469 struct sockaddr_un addr;
470 EmpathyTpFilePriv *priv;
472 priv = GET_PRIV (tp_file);
474 if (G_STR_EMPTY (priv->unix_socket_path))
477 fd = socket (PF_UNIX, SOCK_STREAM, 0);
481 memset (&addr, 0, sizeof (addr));
482 addr.sun_family = AF_UNIX;
483 path_len = strlen (priv->unix_socket_path);
484 strncpy (addr.sun_path, priv->unix_socket_path, path_len);
486 if (connect (fd, (struct sockaddr*) &addr,
497 send_tp_file (EmpathyTpFile *tp_file)
500 GOutputStream *socket_stream;
501 EmpathyTpFilePriv *priv;
503 priv = GET_PRIV (tp_file);
505 DEBUG ("Sending file content: filename=%s",
508 g_return_if_fail (priv->in_stream);
510 socket_fd = _get_local_socket (tp_file);
513 DEBUG ("failed to get local socket fd");
516 DEBUG ("got local socket fd");
517 socket_stream = g_unix_output_stream_new (socket_fd, TRUE);
519 priv->cancellable = g_cancellable_new ();
521 copy_stream (priv->in_stream, socket_stream, priv->cancellable);
523 g_object_unref (socket_stream);
527 receive_tp_file (EmpathyTpFile *tp_file)
529 EmpathyTpFilePriv *priv;
530 GInputStream *socket_stream;
533 priv = GET_PRIV (tp_file);
535 socket_fd = _get_local_socket (tp_file);
540 socket_stream = g_unix_input_stream_new (socket_fd, TRUE);
542 priv->cancellable = g_cancellable_new ();
544 copy_stream (socket_stream, priv->out_stream, priv->cancellable);
546 g_object_unref (socket_stream);
550 tp_file_state_changed_cb (DBusGProxy *tp_file_iface,
551 EmpFileTransferState state,
552 EmpFileTransferStateChangeReason reason,
553 EmpathyTpFile *tp_file)
555 EmpathyTpFilePriv *priv;
557 priv = GET_PRIV (tp_file);
559 DEBUG ("File transfer state changed: filename=%s, "
560 "old state=%u, state=%u, reason=%u",
561 priv->filename, priv->state, state, reason);
563 if (state == EMP_FILE_TRANSFER_STATE_OPEN)
564 priv->start_time = get_time_msec ();
566 DEBUG ("state = %u, incoming = %s, in_stream = %s, out_stream = %s",
567 state, priv->incoming ? "yes" : "no",
568 priv->in_stream ? "present" : "not present",
569 priv->out_stream ? "present" : "not present");
571 if (state == EMP_FILE_TRANSFER_STATE_OPEN && !priv->incoming &&
573 send_tp_file (tp_file);
574 else if (state == EMP_FILE_TRANSFER_STATE_OPEN && priv->incoming &&
576 receive_tp_file (tp_file);
579 priv->state_change_reason = reason;
581 g_object_notify (G_OBJECT (tp_file), "state");
585 tp_file_transferred_bytes_changed_cb (TpProxy *proxy,
587 EmpathyTpFile *tp_file,
588 GObject *weak_object)
590 EmpathyTpFilePriv *priv;
592 priv = GET_PRIV (tp_file);
594 if (priv->transferred_bytes == count)
597 priv->transferred_bytes = count;
599 g_object_notify (G_OBJECT (tp_file), "transferred-bytes");
603 tp_file_constructor (GType type,
605 GObjectConstructParam *props)
608 EmpathyTpFilePriv *priv;
611 tp_file = G_OBJECT_CLASS (empathy_tp_file_parent_class)->constructor (type,
614 priv = GET_PRIV (tp_file);
616 priv->factory = empathy_contact_factory_new ();
617 priv->mc = empathy_mission_control_new ();
619 tp_cli_channel_connect_to_closed (priv->channel,
620 (tp_cli_channel_signal_callback_closed) tp_file_closed_cb,
624 emp_cli_channel_type_file_connect_to_file_transfer_state_changed (
625 TP_PROXY (priv->channel),
626 (emp_cli_channel_type_file_signal_callback_file_transfer_state_changed)
627 tp_file_state_changed_cb,
631 emp_cli_channel_type_file_connect_to_transferred_bytes_changed (
632 TP_PROXY (priv->channel),
633 (emp_cli_channel_type_file_signal_callback_transferred_bytes_changed)
634 tp_file_transferred_bytes_changed_cb,
639 handle = tp_channel_get_handle (priv->channel, NULL);
640 priv->contact = empathy_contact_factory_get_from_handle (priv->factory,
644 tp_cli_dbus_properties_call_get_all (priv->channel,
645 -1, EMP_IFACE_CHANNEL_TYPE_FILE, tp_file_get_all_cb, priv, NULL, NULL);
651 tp_file_get_property (GObject *object,
656 EmpathyTpFilePriv *priv;
657 EmpathyTpFile *tp_file;
659 priv = GET_PRIV (object);
660 tp_file = EMPATHY_TP_FILE (object);
665 g_value_set_object (value, priv->account);
668 g_value_set_object (value, priv->channel);
671 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
677 tp_file_channel_set_dbus_property (gpointer proxy,
678 const gchar *property,
681 DEBUG ("Setting %s property", property);
682 tp_cli_dbus_properties_call_set (TP_PROXY (proxy), -1,
683 EMP_IFACE_CHANNEL_TYPE_FILE, property, value,
684 NULL, NULL, NULL, NULL);
689 tp_file_set_property (GObject *object,
694 EmpathyTpFilePriv *priv;
696 priv = GET_PRIV (object);
701 priv->account = g_object_ref (g_value_get_object (value));
704 priv->channel = g_object_ref (g_value_get_object (value));
707 priv->state = g_value_get_uint (value);
710 priv->incoming = g_value_get_boolean (value);
713 g_free (priv->filename);
714 priv->filename = g_value_dup_string (value);
715 tp_file_channel_set_dbus_property (priv->channel, "Filename", value);
718 priv->size = g_value_get_uint64 (value);
719 tp_file_channel_set_dbus_property (priv->channel, "Size", value);
721 case PROP_CONTENT_TYPE:
722 tp_file_channel_set_dbus_property (priv->channel, "ContentType", value);
723 g_free (priv->content_type);
724 priv->content_type = g_value_dup_string (value);
726 case PROP_CONTENT_HASH:
727 tp_file_channel_set_dbus_property (priv->channel, "ContentHash", value);
728 g_free (priv->content_hash);
729 priv->content_hash = g_value_dup_string (value);
733 g_object_unref (priv->in_stream);
734 priv->in_stream = g_object_ref (g_value_get_object (value));
737 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
743 * empathy_tp_file_new:
744 * @account: the #McAccount for the channel
745 * @channel: a Telepathy channel
747 * Creates a new #EmpathyTpFile wrapping @channel.
749 * Returns: a new #EmpathyTpFile
752 empathy_tp_file_new (McAccount *account,
755 return g_object_new (EMPATHY_TYPE_TP_FILE,
762 * empathy_tp_file_get_id:
763 * @tp_file: an #EmpathyTpFile
765 * Returns the ID of @tp_file.
770 empathy_tp_file_get_id (EmpathyTpFile *tp_file)
772 EmpathyTpFilePriv *priv;
774 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
776 priv = GET_PRIV (tp_file);
782 * empathy_tp_file_get_channel
783 * @tp_file: an #EmpathyTpFile
785 * Returns the Telepathy file transfer channel
787 * Returns: the #TpChannel
790 empathy_tp_file_get_channel (EmpathyTpFile *tp_file)
792 EmpathyTpFilePriv *priv;
794 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
796 priv = GET_PRIV (tp_file);
798 return priv->channel;
802 tp_file_method_cb (TpProxy *proxy,
803 const GValue *address,
806 GObject *weak_object)
808 EmpathyTpFilePriv *priv = (EmpathyTpFilePriv *) user_data;
812 DEBUG ("Error: %s", error->message);
816 if (priv->unix_socket_path)
817 g_free (priv->unix_socket_path);
819 priv->unix_socket_path = g_value_dup_string (address);
821 DEBUG ("Got unix socket path: %s", priv->unix_socket_path);
826 * empathy_tp_file_accept:
827 * @tp_file: an #EmpathyTpFile
829 * Accepts a file transfer that's in the "local pending" state (i.e.
830 * EMP_FILE_TRANSFER_STATE_LOCAL_PENDING).
833 empathy_tp_file_accept (EmpathyTpFile *tp_file,
836 EmpathyTpFilePriv *priv;
837 GValue nothing = { 0 };
839 g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
841 priv = GET_PRIV (tp_file);
843 g_return_if_fail (priv->out_stream != NULL);
845 DEBUG ("Accepting file: filename=%s", priv->filename);
847 g_value_init (¬hing, G_TYPE_STRING);
848 g_value_set_string (¬hing, "");
850 emp_cli_channel_type_file_call_accept_file (TP_PROXY (priv->channel),
851 -1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
852 ¬hing, offset, tp_file_method_cb, priv, NULL, NULL);
856 * empathy_tp_file_offer:
857 * @tp_file: an #EmpathyTpFile
859 * Offers a file transfer that's in the "not offered" state (i.e.
860 * EMP_FILE_TRANSFER_STATE_NOT_OFFERED).
863 empathy_tp_file_offer (EmpathyTpFile *tp_file)
865 EmpathyTpFilePriv *priv;
866 GValue nothing = { 0 };
868 g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
870 priv = GET_PRIV (tp_file);
872 g_value_init (¬hing, G_TYPE_STRING);
873 g_value_set_string (¬hing, "");
875 emp_cli_channel_type_file_call_offer_file (TP_PROXY (priv->channel),
876 -1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
877 ¬hing, tp_file_method_cb, priv, NULL, NULL);
881 empathy_tp_file_get_contact (EmpathyTpFile *tp_file)
883 EmpathyTpFilePriv *priv;
885 priv = GET_PRIV (tp_file);
887 return priv->contact;
891 empathy_tp_file_get_input_stream (EmpathyTpFile *tp_file)
893 EmpathyTpFilePriv *priv;
895 priv = GET_PRIV (tp_file);
897 return priv->in_stream;
901 empathy_tp_file_get_output_stream (EmpathyTpFile *tp_file)
903 EmpathyTpFilePriv *priv;
905 priv = GET_PRIV (tp_file);
907 return priv->out_stream;
911 empathy_tp_file_get_filename (EmpathyTpFile *tp_file)
913 EmpathyTpFilePriv *priv;
915 priv = GET_PRIV (tp_file);
917 return priv->filename;
921 empathy_tp_file_get_incoming (EmpathyTpFile *tp_file)
923 EmpathyTpFilePriv *priv;
925 priv = GET_PRIV (tp_file);
927 return priv->incoming;
931 empathy_tp_file_get_state (EmpathyTpFile *tp_file)
933 EmpathyTpFilePriv *priv;
935 priv = GET_PRIV (tp_file);
940 EmpFileTransferStateChangeReason
941 empathy_tp_file_get_state_change_reason (EmpathyTpFile *tp_file)
943 EmpathyTpFilePriv *priv;
945 priv = GET_PRIV (tp_file);
947 g_return_val_if_fail (priv->state_change_reason >= 0,
948 EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE);
950 return priv->state_change_reason;
954 empathy_tp_file_get_size (EmpathyTpFile *tp_file)
956 EmpathyTpFilePriv *priv;
958 priv = GET_PRIV (tp_file);
964 empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file)
966 EmpathyTpFilePriv *priv;
968 priv = GET_PRIV (tp_file);
970 return priv->transferred_bytes;
974 empathy_tp_file_get_remaining_time (EmpathyTpFile *tp_file)
976 EmpathyTpFilePriv *priv;
977 gint64 curr_time, elapsed_time;
978 gdouble time_per_byte;
979 gdouble remaining_time;
981 priv = GET_PRIV (tp_file);
983 if (priv->size == EMPATHY_TP_FILE_UNKNOWN_SIZE)
986 if (priv->transferred_bytes == priv->size)
989 curr_time = get_time_msec ();
990 elapsed_time = curr_time - priv->start_time;
991 time_per_byte = (gdouble) elapsed_time / (gdouble) priv->transferred_bytes;
992 remaining_time = (time_per_byte * (priv->size - priv->transferred_bytes)) / 1000;
994 return (gint) (remaining_time + 0.5);
998 empathy_tp_file_cancel (EmpathyTpFile *tp_file)
1000 EmpathyTpFilePriv *priv;
1002 priv = GET_PRIV (tp_file);
1004 tp_cli_channel_call_close (priv->channel, -1, NULL, NULL, NULL, NULL);
1006 g_cancellable_cancel (priv->cancellable);
1010 empathy_tp_file_set_input_stream (EmpathyTpFile *tp_file,
1011 GInputStream *in_stream)
1013 EmpathyTpFilePriv *priv;
1015 priv = GET_PRIV (tp_file);
1017 if (priv->in_stream == in_stream)
1021 g_warning ("Setting an input stream for incoming file "
1022 "transfers is useless");
1024 if (priv->in_stream)
1025 g_object_unref (priv->in_stream);
1028 g_object_ref (in_stream);
1030 priv->in_stream = in_stream;
1032 g_object_notify (G_OBJECT (tp_file), "in-stream");
1036 empathy_tp_file_set_output_stream (EmpathyTpFile *tp_file,
1037 GOutputStream *out_stream)
1039 EmpathyTpFilePriv *priv;
1041 priv = GET_PRIV (tp_file);
1043 if (priv->out_stream == out_stream)
1046 if (!priv->incoming)
1047 g_warning ("Setting an output stream for outgoing file "
1048 "transfers is useless");
1050 if (priv->out_stream)
1051 g_object_unref (priv->out_stream);
1054 g_object_ref (out_stream);
1056 priv->out_stream = out_stream;
1060 empathy_tp_file_set_filename (EmpathyTpFile *tp_file,
1061 const gchar *filename)
1063 EmpathyTpFilePriv *priv;
1065 priv = GET_PRIV (tp_file);
1067 g_return_if_fail (filename != NULL);
1069 if (priv->filename && strcmp (filename, priv->filename) == 0)
1072 g_free (priv->filename);
1073 priv->filename = g_strdup (filename);
1075 g_object_notify (G_OBJECT (tp_file), "filename");
1079 empathy_tp_file_class_init (EmpathyTpFileClass *klass)
1081 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1083 object_class->finalize = tp_file_finalize;
1084 object_class->constructor = tp_file_constructor;
1085 object_class->get_property = tp_file_get_property;
1086 object_class->set_property = tp_file_set_property;
1088 /* Construct-only properties */
1089 g_object_class_install_property (object_class,
1091 g_param_spec_object ("account",
1093 "The account associated with the channel",
1096 G_PARAM_CONSTRUCT_ONLY));
1098 g_object_class_install_property (object_class,
1100 g_param_spec_object ("channel",
1101 "telepathy channel",
1102 "The file transfer channel",
1105 G_PARAM_CONSTRUCT_ONLY));
1107 g_object_class_install_property (object_class,
1109 g_param_spec_uint ("state",
1110 "state of the transfer",
1111 "The file transfer state",
1116 G_PARAM_CONSTRUCT));
1118 g_object_class_install_property (object_class,
1120 g_param_spec_boolean ("incoming",
1122 "Whether the transfer is incoming",
1125 G_PARAM_CONSTRUCT));
1127 g_object_class_install_property (object_class,
1129 g_param_spec_string ("filename",
1130 "name of the transfer",
1131 "The file transfer filename",
1133 G_PARAM_READWRITE));
1135 g_object_class_install_property (object_class,
1137 g_param_spec_uint64 ("size",
1139 "The file transfer size",
1143 G_PARAM_READWRITE));
1145 g_object_class_install_property (object_class,
1147 g_param_spec_string ("content-type",
1148 "file transfer content-type",
1149 "The file transfer content-type",
1151 G_PARAM_READWRITE));
1153 g_object_class_install_property (object_class,
1154 PROP_CONTENT_HASH_TYPE,
1155 g_param_spec_uint ("content-hash-type",
1156 "file transfer hash type",
1157 "The type of the file transfer hash",
1161 G_PARAM_READWRITE));
1163 g_object_class_install_property (object_class,
1165 g_param_spec_string ("content-hash",
1166 "file transfer hash",
1167 "The hash of the transfer's contents",
1169 G_PARAM_READWRITE));
1171 g_object_class_install_property (object_class,
1172 PROP_TRANSFERRED_BYTES,
1173 g_param_spec_uint64 ("transferred-bytes",
1174 "bytes transferred",
1175 "The number of bytes transferred",
1179 G_PARAM_READWRITE));
1181 g_object_class_install_property (object_class,
1183 g_param_spec_object ("in-stream",
1184 "transfer input stream",
1185 "The input stream for file transfer",
1186 G_TYPE_INPUT_STREAM,
1187 G_PARAM_READWRITE));
1189 g_type_class_add_private (object_class, sizeof (EmpathyTpFilePriv));