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 struct _EmpathyTpFilePriv {
276 EmpathyContactFactory *factory;
281 EmpathyContact *contact;
282 GInputStream *in_stream;
283 GOutputStream *out_stream;
286 EmpFileTransferState state;
287 EmpFileTransferStateChangeReason state_change_reason;
289 guint64 transferred_bytes;
291 gchar *unix_socket_path;
293 EmpFileHashType content_hash_type;
296 GCancellable *cancellable;
307 PROP_TRANSFERRED_BYTES,
308 PROP_CONTENT_HASH_TYPE,
313 G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT);
316 empathy_tp_file_init (EmpathyTpFile *tp_file)
318 EmpathyTpFilePriv *priv;
320 priv = G_TYPE_INSTANCE_GET_PRIVATE ((tp_file),
321 EMPATHY_TYPE_TP_FILE, EmpathyTpFilePriv);
323 tp_file->priv = priv;
327 tp_file_destroy_cb (TpChannel *file_channel,
328 EmpathyTpFile *tp_file)
330 DEBUG ("Channel Closed or CM crashed");
332 g_object_unref (tp_file->priv->channel);
333 tp_file->priv->channel = NULL;
337 tp_file_finalize (GObject *object)
339 EmpathyTpFile *tp_file;
341 tp_file = EMPATHY_TP_FILE (object);
343 if (tp_file->priv->channel)
345 DEBUG ("Closing channel..");
346 g_signal_handlers_disconnect_by_func (tp_file->priv->channel,
347 tp_file_destroy_cb, object);
348 tp_cli_channel_call_close (tp_file->priv->channel, -1, NULL, NULL,
350 if (G_IS_OBJECT (tp_file->priv->channel))
351 g_object_unref (tp_file->priv->channel);
354 if (tp_file->priv->factory)
356 g_object_unref (tp_file->priv->factory);
358 if (tp_file->priv->mc)
360 g_object_unref (tp_file->priv->mc);
363 g_free (tp_file->priv->id);
364 g_free (tp_file->priv->filename);
365 g_free (tp_file->priv->unix_socket_path);
366 g_free (tp_file->priv->description);
367 g_free (tp_file->priv->content_hash);
368 g_free (tp_file->priv->content_type);
370 if (tp_file->priv->in_stream)
371 g_object_unref (tp_file->priv->in_stream);
373 if (tp_file->priv->out_stream)
374 g_object_unref (tp_file->priv->out_stream);
376 if (tp_file->priv->contact)
377 g_object_unref (tp_file->priv->contact);
379 if (tp_file->priv->cancellable)
380 g_object_unref (tp_file->priv->cancellable);
382 G_OBJECT_CLASS (empathy_tp_file_parent_class)->finalize (object);
386 tp_file_closed_cb (TpChannel *file_channel,
387 EmpathyTpFile *tp_file,
388 GObject *weak_object)
390 /* The channel is closed, do just like if the proxy was destroyed */
391 g_signal_handlers_disconnect_by_func (tp_file->priv->channel,
394 tp_file_destroy_cb (file_channel, tp_file);
398 _get_local_socket (EmpathyTpFile *tp_file)
402 struct sockaddr_un addr;
404 if (G_STR_EMPTY (tp_file->priv->unix_socket_path))
407 fd = socket (PF_UNIX, SOCK_STREAM, 0);
411 memset (&addr, 0, sizeof (addr));
412 addr.sun_family = AF_UNIX;
413 path_len = strlen (tp_file->priv->unix_socket_path);
414 strncpy (addr.sun_path, tp_file->priv->unix_socket_path, path_len);
416 if (connect (fd, (struct sockaddr*) &addr,
427 send_tp_file (EmpathyTpFile *tp_file)
430 GOutputStream *socket_stream;
432 DEBUG ("Sending file content: filename=%s",
433 tp_file->priv->filename);
435 g_return_if_fail (tp_file->priv->in_stream);
437 socket_fd = _get_local_socket (tp_file);
440 DEBUG ("failed to get local socket fd");
443 DEBUG ("got local socket fd");
444 socket_stream = g_unix_output_stream_new (socket_fd, TRUE);
446 tp_file->priv->cancellable = g_cancellable_new ();
448 copy_stream (tp_file->priv->in_stream, socket_stream,
449 tp_file->priv->cancellable);
451 g_object_unref (socket_stream);
455 receive_tp_file (EmpathyTpFile *tp_file)
457 GInputStream *socket_stream;
460 socket_fd = _get_local_socket (tp_file);
465 socket_stream = g_unix_input_stream_new (socket_fd, TRUE);
467 tp_file->priv->cancellable = g_cancellable_new ();
469 copy_stream (socket_stream, tp_file->priv->out_stream,
470 tp_file->priv->cancellable);
472 g_object_unref (socket_stream);
476 tp_file_state_changed_cb (DBusGProxy *tp_file_iface,
477 EmpFileTransferState state,
478 EmpFileTransferStateChangeReason reason,
479 EmpathyTpFile *tp_file)
481 DEBUG ("File transfer state changed: filename=%s, "
482 "old state=%u, state=%u, reason=%u",
483 tp_file->priv->filename, tp_file->priv->state, state, reason);
485 if (state == EMP_FILE_TRANSFER_STATE_OPEN)
486 tp_file->priv->start_time = empathy_time_get_current ();
488 DEBUG ("state = %u, incoming = %s, in_stream = %s, out_stream = %s",
489 state, tp_file->priv->incoming ? "yes" : "no",
490 tp_file->priv->in_stream ? "present" : "not present",
491 tp_file->priv->out_stream ? "present" : "not present");
493 if (state == EMP_FILE_TRANSFER_STATE_OPEN && !tp_file->priv->incoming &&
494 tp_file->priv->in_stream)
495 send_tp_file (tp_file);
496 else if (state == EMP_FILE_TRANSFER_STATE_OPEN && tp_file->priv->incoming &&
497 tp_file->priv->out_stream)
498 receive_tp_file (tp_file);
500 tp_file->priv->state = state;
501 tp_file->priv->state_change_reason = reason;
503 g_object_notify (G_OBJECT (tp_file), "state");
507 tp_file_transferred_bytes_changed_cb (TpProxy *proxy,
509 EmpathyTpFile *tp_file,
510 GObject *weak_object)
512 if (tp_file->priv->transferred_bytes == count)
515 tp_file->priv->transferred_bytes = count;
517 g_object_notify (G_OBJECT (tp_file), "transferred-bytes");
521 tp_file_constructor (GType type,
523 GObjectConstructParam *props)
526 EmpathyTpFile *tp_file;
528 GHashTable *properties;
531 file_obj = G_OBJECT_CLASS (empathy_tp_file_parent_class)->constructor (type,
534 tp_file = EMPATHY_TP_FILE (file_obj);
536 tp_file->priv->factory = empathy_contact_factory_new ();
537 tp_file->priv->mc = empathy_mission_control_new ();
539 tp_cli_channel_connect_to_closed (tp_file->priv->channel,
540 (tp_cli_channel_signal_callback_closed) tp_file_closed_cb,
544 emp_cli_channel_type_file_connect_to_file_transfer_state_changed (
545 TP_PROXY (tp_file->priv->channel),
546 (emp_cli_channel_type_file_signal_callback_file_transfer_state_changed)
547 tp_file_state_changed_cb,
551 emp_cli_channel_type_file_connect_to_transferred_bytes_changed (
552 TP_PROXY (tp_file->priv->channel),
553 (emp_cli_channel_type_file_signal_callback_transferred_bytes_changed)
554 tp_file_transferred_bytes_changed_cb,
558 account = empathy_channel_get_account (tp_file->priv->channel);
560 handle = tp_channel_get_handle (tp_file->priv->channel, NULL);
561 tp_file->priv->contact = empathy_contact_factory_get_from_handle (
562 tp_file->priv->factory, account, (guint) handle);
564 tp_cli_dbus_properties_run_get_all (tp_file->priv->channel,
565 -1, EMP_IFACE_CHANNEL_TYPE_FILE, &properties, NULL, NULL);
567 tp_file->priv->size = g_value_get_uint64 (
568 g_hash_table_lookup (properties, "Size"));
570 tp_file->priv->state = g_value_get_uint (
571 g_hash_table_lookup (properties, "State"));
573 /* Invalid reason, so empathy_file_get_state_change_reason() can give
574 * a warning if called for a not closed file transfer. */
575 tp_file->priv->state_change_reason = -1;
577 tp_file->priv->transferred_bytes = g_value_get_uint64 (
578 g_hash_table_lookup (properties, "TransferredBytes"));
580 tp_file->priv->filename = g_value_dup_string (
581 g_hash_table_lookup (properties, "Filename"));
583 tp_file->priv->content_hash = g_value_dup_string (
584 g_hash_table_lookup (properties, "ContentHash"));
586 tp_file->priv->description = g_value_dup_string (
587 g_hash_table_lookup (properties, "Description"));
589 if (tp_file->priv->state == EMP_FILE_TRANSFER_STATE_LOCAL_PENDING)
590 tp_file->priv->incoming = TRUE;
592 g_hash_table_destroy (properties);
593 g_object_unref (account);
599 tp_file_get_property (GObject *object,
604 EmpathyTpFile *tp_file;
606 tp_file = EMPATHY_TP_FILE (object);
611 g_value_set_object (value, tp_file->priv->channel);
614 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
620 tp_file_channel_set_dbus_property (gpointer proxy,
621 const gchar *property,
624 DEBUG ("Setting %s property", property);
625 tp_cli_dbus_properties_call_set (TP_PROXY (proxy), -1,
626 EMP_IFACE_CHANNEL_TYPE_FILE, property, value,
627 NULL, NULL, NULL, NULL);
632 tp_file_set_property (GObject *object,
637 EmpathyTpFile *tp_file = (EmpathyTpFile *) object;
641 tp_file->priv->channel = g_object_ref (g_value_get_object (value));
644 tp_file->priv->state = g_value_get_uint (value);
647 tp_file->priv->incoming = g_value_get_boolean (value);
650 g_free (tp_file->priv->filename);
651 tp_file->priv->filename = g_value_dup_string (value);
652 tp_file_channel_set_dbus_property (tp_file->priv->channel,
656 tp_file->priv->size = g_value_get_uint64 (value);
657 tp_file_channel_set_dbus_property (tp_file->priv->channel,
660 case PROP_CONTENT_TYPE:
661 tp_file_channel_set_dbus_property (tp_file->priv->channel,
662 "ContentType", value);
663 g_free (tp_file->priv->content_type);
664 tp_file->priv->content_type = g_value_dup_string (value);
666 case PROP_CONTENT_HASH:
667 tp_file_channel_set_dbus_property (tp_file->priv->channel,
668 "ContentHash", value);
669 g_free (tp_file->priv->content_hash);
670 tp_file->priv->content_hash = g_value_dup_string (value);
673 if (tp_file->priv->in_stream)
674 g_object_unref (tp_file->priv->in_stream);
675 tp_file->priv->in_stream = g_object_ref (g_value_get_object (value));
678 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
684 * empathy_tp_file_new:
685 * @channel: a Telepathy channel
687 * Creates a new #EmpathyTpFile wrapping @channel.
689 * Returns: a new #EmpathyTpFile
692 empathy_tp_file_new (TpChannel *channel)
694 g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
696 return g_object_new (EMPATHY_TYPE_TP_FILE,
702 * empathy_tp_file_get_id:
703 * @tp_file: an #EmpathyTpFile
705 * Returns the ID of @tp_file.
710 empathy_tp_file_get_id (EmpathyTpFile *tp_file)
712 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
714 return tp_file->priv->id;
718 * empathy_tp_file_get_channel
719 * @tp_file: an #EmpathyTpFile
721 * Returns the Telepathy file transfer channel
723 * Returns: the #TpChannel
726 empathy_tp_file_get_channel (EmpathyTpFile *tp_file)
728 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
730 return tp_file->priv->channel;
734 tp_file_method_cb (TpProxy *proxy,
735 const GValue *address,
738 GObject *weak_object)
740 EmpathyTpFile *tp_file = (EmpathyTpFile *) user_data;
744 DEBUG ("Error: %s", error->message);
748 if (tp_file->priv->unix_socket_path)
749 g_free (tp_file->priv->unix_socket_path);
751 tp_file->priv->unix_socket_path = g_value_dup_string (address);
753 DEBUG ("Got unix socket path: %s", tp_file->priv->unix_socket_path);
758 * empathy_tp_file_accept:
759 * @tp_file: an #EmpathyTpFile
761 * Accepts a file transfer that's in the "local pending" state (i.e.
762 * EMP_FILE_TRANSFER_STATE_LOCAL_PENDING).
765 empathy_tp_file_accept (EmpathyTpFile *tp_file,
768 GValue nothing = { 0 };
770 g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
772 g_return_if_fail (tp_file->priv->out_stream != NULL);
774 DEBUG ("Accepting file: filename=%s", tp_file->priv->filename);
776 g_value_init (¬hing, G_TYPE_STRING);
777 g_value_set_string (¬hing, "");
779 emp_cli_channel_type_file_call_accept_file (TP_PROXY (tp_file->priv->channel),
780 -1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
781 ¬hing, offset, tp_file_method_cb, tp_file, NULL, NULL);
785 * empathy_tp_file_offer:
786 * @tp_file: an #EmpathyTpFile
788 * Offers a file transfer that's in the "not offered" state (i.e.
789 * EMP_FILE_TRANSFER_STATE_NOT_OFFERED).
792 empathy_tp_file_offer (EmpathyTpFile *tp_file)
794 GValue nothing = { 0 };
796 g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
798 g_value_init (¬hing, G_TYPE_STRING);
799 g_value_set_string (¬hing, "");
801 emp_cli_channel_type_file_call_offer_file (
802 TP_PROXY (tp_file->priv->channel), -1,
803 TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
804 ¬hing, tp_file_method_cb, tp_file, NULL, NULL);
808 empathy_tp_file_get_contact (EmpathyTpFile *tp_file)
810 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
811 return tp_file->priv->contact;
815 empathy_tp_file_get_input_stream (EmpathyTpFile *tp_file)
817 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
818 return tp_file->priv->in_stream;
822 empathy_tp_file_get_output_stream (EmpathyTpFile *tp_file)
824 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
825 return tp_file->priv->out_stream;
829 empathy_tp_file_get_filename (EmpathyTpFile *tp_file)
831 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
832 return tp_file->priv->filename;
836 empathy_tp_file_get_incoming (EmpathyTpFile *tp_file)
838 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), FALSE);
839 return tp_file->priv->incoming;
843 empathy_tp_file_get_state (EmpathyTpFile *tp_file)
845 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file),
846 EMP_FILE_TRANSFER_STATE_NONE);
847 return tp_file->priv->state;
850 EmpFileTransferStateChangeReason
851 empathy_tp_file_get_state_change_reason (EmpathyTpFile *tp_file)
853 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file),
854 EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE);
855 g_return_val_if_fail (tp_file->priv->state_change_reason >= 0,
856 EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE);
858 return tp_file->priv->state_change_reason;
862 empathy_tp_file_get_size (EmpathyTpFile *tp_file)
864 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file),
865 EMPATHY_TP_FILE_UNKNOWN_SIZE);
866 return tp_file->priv->size;
870 empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file)
872 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), 0);
873 return tp_file->priv->transferred_bytes;
877 empathy_tp_file_get_remaining_time (EmpathyTpFile *tp_file)
879 time_t curr_time, elapsed_time;
880 gdouble time_per_byte;
881 gdouble remaining_time;
883 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), -1);
885 if (tp_file->priv->size == EMPATHY_TP_FILE_UNKNOWN_SIZE)
888 if (tp_file->priv->transferred_bytes == tp_file->priv->size)
891 curr_time = empathy_time_get_current ();
892 elapsed_time = curr_time - tp_file->priv->start_time;
893 time_per_byte = (gdouble) elapsed_time /
894 (gdouble) tp_file->priv->transferred_bytes;
895 remaining_time = time_per_byte * (tp_file->priv->size -
896 tp_file->priv->transferred_bytes);
898 return (gint) (remaining_time + 0.5);
902 empathy_tp_file_cancel (EmpathyTpFile *tp_file)
904 g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
906 tp_cli_channel_call_close (tp_file->priv->channel, -1, NULL, NULL, NULL, NULL);
908 g_cancellable_cancel (tp_file->priv->cancellable);
912 empathy_tp_file_set_input_stream (EmpathyTpFile *tp_file,
913 GInputStream *in_stream)
915 g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
916 g_return_if_fail (G_IS_INPUT_STREAM (in_stream));
918 if (tp_file->priv->in_stream == in_stream)
921 if (tp_file->priv->incoming)
922 g_warning ("Setting an input stream for incoming file "
923 "transfers is useless");
925 if (tp_file->priv->in_stream)
926 g_object_unref (tp_file->priv->in_stream);
929 g_object_ref (in_stream);
931 tp_file->priv->in_stream = in_stream;
933 g_object_notify (G_OBJECT (tp_file), "in-stream");
937 empathy_tp_file_set_output_stream (EmpathyTpFile *tp_file,
938 GOutputStream *out_stream)
940 g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
941 g_return_if_fail (G_IS_OUTPUT_STREAM (out_stream));
943 if (tp_file->priv->out_stream == out_stream)
946 if (!tp_file->priv->incoming)
947 g_warning ("Setting an output stream for outgoing file "
948 "transfers is useless");
950 if (tp_file->priv->out_stream)
951 g_object_unref (tp_file->priv->out_stream);
954 g_object_ref (out_stream);
956 tp_file->priv->out_stream = out_stream;
960 empathy_tp_file_set_filename (EmpathyTpFile *tp_file,
961 const gchar *filename)
963 g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
964 g_return_if_fail (filename != NULL);
966 if (tp_file->priv->filename && strcmp (filename,
967 tp_file->priv->filename) == 0)
970 g_free (tp_file->priv->filename);
971 tp_file->priv->filename = g_strdup (filename);
973 g_object_notify (G_OBJECT (tp_file), "filename");
977 empathy_tp_file_class_init (EmpathyTpFileClass *klass)
979 GObjectClass *object_class = G_OBJECT_CLASS (klass);
981 object_class->finalize = tp_file_finalize;
982 object_class->constructor = tp_file_constructor;
983 object_class->get_property = tp_file_get_property;
984 object_class->set_property = tp_file_set_property;
986 /* Construct-only properties */
987 g_object_class_install_property (object_class,
989 g_param_spec_object ("channel",
991 "The file transfer channel",
994 G_PARAM_CONSTRUCT_ONLY));
996 g_object_class_install_property (object_class,
998 g_param_spec_uint ("state",
999 "state of the transfer",
1000 "The file transfer state",
1005 G_PARAM_CONSTRUCT));
1007 g_object_class_install_property (object_class,
1009 g_param_spec_boolean ("incoming",
1011 "Whether the transfer is incoming",
1014 G_PARAM_CONSTRUCT));
1016 g_object_class_install_property (object_class,
1018 g_param_spec_string ("filename",
1019 "name of the transfer",
1020 "The file transfer filename",
1022 G_PARAM_READWRITE));
1024 g_object_class_install_property (object_class,
1026 g_param_spec_uint64 ("size",
1028 "The file transfer size",
1032 G_PARAM_READWRITE));
1034 g_object_class_install_property (object_class,
1036 g_param_spec_string ("content-type",
1037 "file transfer content-type",
1038 "The file transfer content-type",
1040 G_PARAM_READWRITE));
1042 g_object_class_install_property (object_class,
1043 PROP_CONTENT_HASH_TYPE,
1044 g_param_spec_uint ("content-hash-type",
1045 "file transfer hash type",
1046 "The type of the file transfer hash",
1050 G_PARAM_READWRITE));
1052 g_object_class_install_property (object_class,
1054 g_param_spec_string ("content-hash",
1055 "file transfer hash",
1056 "The hash of the transfer's contents",
1058 G_PARAM_READWRITE));
1060 g_object_class_install_property (object_class,
1061 PROP_TRANSFERRED_BYTES,
1062 g_param_spec_uint64 ("transferred-bytes",
1063 "bytes transferred",
1064 "The number of bytes transferred",
1068 G_PARAM_READWRITE));
1070 g_object_class_install_property (object_class,
1072 g_param_spec_object ("in-stream",
1073 "transfer input stream",
1074 "The input stream for file transfer",
1075 G_TYPE_INPUT_STREAM,
1076 G_PARAM_READWRITE));
1078 g_type_class_add_private (object_class, sizeof (EmpathyTpFilePriv));