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 */
25 #include "empathy-ft-handler.h"
27 #include <glib/gi18n-lib.h>
28 #include <tp-account-widgets/tpaw-time.h>
29 #include <tp-account-widgets/tpaw-utils.h>
30 #include <telepathy-glib/telepathy-glib-dbus.h>
32 #include "empathy-utils.h"
34 #define DEBUG_FLAG EMPATHY_DEBUG_FT
35 #include "empathy-debug.h"
38 * SECTION:empathy-ft-handler
39 * @title: EmpathyFTHandler
40 * @short_description: an object representing a File Transfer
41 * @include: libempathy/empathy-ft-handler
43 * #EmpathyFTHandler is the object which represents a File Transfer with all
45 * The creation of an #EmpathyFTHandler is done with
46 * empathy_ft_handler_new_outgoing() or empathy_ft_handler_new_incoming(),
47 * even though clients should not need to call them directly, as
48 * #EmpathyFTFactory does it for them. Remember that for the file transfer
49 * to work with an incoming handler,
50 * empathy_ft_handler_incoming_set_destination() should be called after
51 * empathy_ft_handler_new_incoming(). #EmpathyFTFactory does this
53 * It's important to note that, as the creation of the handlers is async, once
54 * an handler is created, it already has all the interesting properties set,
55 * like filename, total bytes, content type and so on, making it useful
56 * to be displayed in an UI.
57 * The transfer API works like a state machine; it has three signals,
58 * ::transfer-started, ::transfer-progress, ::transfer-done, which will be
59 * emitted in the relevant phases.
60 * In addition, if the handler is created with checksumming enabled,
61 * other three signals (::hashing-started, ::hashing-progress, ::hashing-done)
62 * will be emitted before or after the transfer, depending on the direction
63 * (respectively outgoing and incoming) of the handler.
64 * At any time between the call to empathy_ft_handler_start_transfer() and
65 * the last signal, a ::transfer-error can be emitted, indicating that an
66 * error has happened in the operation. The message of the error is localized
70 G_DEFINE_TYPE (EmpathyFTHandler
, empathy_ft_handler
, G_TYPE_OBJECT
)
72 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTHandler)
74 #define BUFFER_SIZE 4096
83 PROP_MODIFICATION_TIME
,
85 PROP_TRANSFERRED_BYTES
,
101 GInputStream
*stream
;
102 GError
*error
/* comment to make the style checker happy */;
107 EmpathyFTHandler
*handler
;
111 EmpathyFTHandlerReadyCallback callback
;
113 EmpathyFTHandler
*handler
;
118 gboolean dispose_run
;
121 TpFileTransferChannel
*channel
;
122 GCancellable
*cancellable
;
125 /* request for the new transfer */
128 /* transfer properties */
129 EmpathyContact
*contact
;
134 guint64 transferred_bytes
;
137 TpFileHashType content_hash_type
;
139 gint64 user_action_time
;
143 guint remaining_time
;
144 gint64 last_update_time
;
146 gboolean is_completed
;
147 } EmpathyFTHandlerPriv
;
149 static guint signals
[LAST_SIGNAL
] = { 0 };
151 static gboolean
do_hash_job_incoming (GIOSchedulerJob
*job
,
152 GCancellable
*cancellable
, gpointer user_data
);
154 /* GObject implementations */
156 do_get_property (GObject
*object
,
161 EmpathyFTHandlerPriv
*priv
= GET_PRIV (object
);
166 g_value_set_object (value
, priv
->contact
);
168 case PROP_CONTENT_TYPE
:
169 g_value_set_string (value
, priv
->content_type
);
171 case PROP_DESCRIPTION
:
172 g_value_set_string (value
, priv
->description
);
175 g_value_set_string (value
, priv
->filename
);
177 case PROP_MODIFICATION_TIME
:
178 g_value_set_uint64 (value
, priv
->mtime
);
180 case PROP_TOTAL_BYTES
:
181 g_value_set_uint64 (value
, priv
->total_bytes
);
183 case PROP_TRANSFERRED_BYTES
:
184 g_value_set_uint64 (value
, priv
->transferred_bytes
);
187 g_value_set_object (value
, priv
->gfile
);
190 g_value_set_object (value
, priv
->channel
);
192 case PROP_USER_ACTION_TIME
:
193 g_value_set_int64 (value
, priv
->user_action_time
);
196 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
201 do_set_property (GObject
*object
,
206 EmpathyFTHandlerPriv
*priv
= GET_PRIV (object
);
211 priv
->contact
= g_value_dup_object (value
);
213 case PROP_CONTENT_TYPE
:
214 priv
->content_type
= g_value_dup_string (value
);
216 case PROP_DESCRIPTION
:
217 priv
->description
= g_value_dup_string (value
);
220 priv
->filename
= g_value_dup_string (value
);
222 case PROP_MODIFICATION_TIME
:
223 priv
->mtime
= g_value_get_uint64 (value
);
225 case PROP_TOTAL_BYTES
:
226 priv
->total_bytes
= g_value_get_uint64 (value
);
228 case PROP_TRANSFERRED_BYTES
:
229 priv
->transferred_bytes
= g_value_get_uint64 (value
);
232 priv
->gfile
= g_value_dup_object (value
);
235 priv
->channel
= g_value_dup_object (value
);
237 case PROP_USER_ACTION_TIME
:
238 priv
->user_action_time
= g_value_get_int64 (value
);
241 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
246 do_dispose (GObject
*object
)
248 EmpathyFTHandlerPriv
*priv
= GET_PRIV (object
);
250 if (priv
->dispose_run
)
253 priv
->dispose_run
= TRUE
;
255 if (priv
->contact
!= NULL
) {
256 g_object_unref (priv
->contact
);
257 priv
->contact
= NULL
;
260 if (priv
->gfile
!= NULL
) {
261 g_object_unref (priv
->gfile
);
265 if (priv
->channel
!= NULL
) {
266 tp_channel_close_async (TP_CHANNEL (priv
->channel
), NULL
, NULL
);
267 g_object_unref (priv
->channel
);
268 priv
->channel
= NULL
;
271 if (priv
->cancellable
!= NULL
) {
272 g_object_unref (priv
->cancellable
);
273 priv
->cancellable
= NULL
;
276 if (priv
->request
!= NULL
)
278 g_hash_table_unref (priv
->request
);
279 priv
->request
= NULL
;
282 G_OBJECT_CLASS (empathy_ft_handler_parent_class
)->dispose (object
);
286 do_finalize (GObject
*object
)
288 EmpathyFTHandlerPriv
*priv
= GET_PRIV (object
);
290 DEBUG ("%p", object
);
292 g_free (priv
->content_type
);
293 priv
->content_type
= NULL
;
295 g_free (priv
->filename
);
296 priv
->filename
= NULL
;
298 g_free (priv
->description
);
299 priv
->description
= NULL
;
301 g_free (priv
->content_hash
);
302 priv
->content_hash
= NULL
;
304 G_OBJECT_CLASS (empathy_ft_handler_parent_class
)->finalize (object
);
308 empathy_ft_handler_class_init (EmpathyFTHandlerClass
*klass
)
310 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
311 GParamSpec
*param_spec
;
313 g_type_class_add_private (klass
, sizeof (EmpathyFTHandlerPriv
));
315 object_class
->get_property
= do_get_property
;
316 object_class
->set_property
= do_set_property
;
317 object_class
->dispose
= do_dispose
;
318 object_class
->finalize
= do_finalize
;
323 * EmpathyFTHandler:contact:
325 * The remote #EmpathyContact for the transfer
327 param_spec
= g_param_spec_object ("contact",
328 "contact", "The remote contact",
329 EMPATHY_TYPE_CONTACT
,
330 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
331 g_object_class_install_property (object_class
, PROP_CONTACT
, param_spec
);
334 * EmpathyFTHandler:content-type:
336 * The content type of the file being transferred
338 param_spec
= g_param_spec_string ("content-type",
339 "content-type", "The content type of the file", NULL
,
340 G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
341 g_object_class_install_property (object_class
,
342 PROP_CONTENT_TYPE
, param_spec
);
345 * EmpathyFTHandler:description:
347 * The description of the file being transferred
349 param_spec
= g_param_spec_string ("description",
350 "description", "The description of the file", NULL
,
351 G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
352 g_object_class_install_property (object_class
,
353 PROP_DESCRIPTION
, param_spec
);
356 * EmpathyFTHandler:filename:
358 * The name of the file being transferred
360 param_spec
= g_param_spec_string ("filename",
361 "filename", "The name of the file", NULL
,
362 G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
363 g_object_class_install_property (object_class
,
364 PROP_FILENAME
, param_spec
);
367 * EmpathyFTHandler:modification-time:
369 * The modification time of the file being transferred
371 param_spec
= g_param_spec_uint64 ("modification-time",
372 "modification-time", "The mtime of the file", 0,
373 G_MAXUINT64
, 0, G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
374 g_object_class_install_property (object_class
,
375 PROP_MODIFICATION_TIME
, param_spec
);
378 * EmpathyFTHandler:total-bytes:
380 * The size (in bytes) of the file being transferred
382 param_spec
= g_param_spec_uint64 ("total-bytes",
383 "total-bytes", "The size of the file", 0,
384 G_MAXUINT64
, 0, G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
385 g_object_class_install_property (object_class
,
386 PROP_TOTAL_BYTES
, param_spec
);
389 * EmpathyFTHandler:transferred-bytes:
391 * The number of the bytes already transferred
393 param_spec
= g_param_spec_uint64 ("transferred-bytes",
394 "transferred-bytes", "The number of bytes already transferred", 0,
395 G_MAXUINT64
, 0, G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
396 g_object_class_install_property (object_class
,
397 PROP_TRANSFERRED_BYTES
, param_spec
);
400 * EmpathyFTHandler:gfile:
402 * The #GFile object where the transfer actually happens
404 param_spec
= g_param_spec_object ("gfile",
405 "gfile", "The GFile we're handling",
407 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
408 g_object_class_install_property (object_class
, PROP_G_FILE
, param_spec
);
411 * EmpathyFTHandler:channel:
413 * The underlying #TpFileTransferChannel managing the transfer
415 param_spec
= g_param_spec_object ("channel",
416 "channel", "The file transfer channel",
417 TP_TYPE_FILE_TRANSFER_CHANNEL
,
418 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
419 g_object_class_install_property (object_class
, PROP_CHANNEL
, param_spec
);
421 param_spec
= g_param_spec_int64 ("user-action-time", "user action time",
424 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
425 g_object_class_install_property (object_class
, PROP_USER_ACTION_TIME
,
431 * EmpathyFTHandler::transfer-started
432 * @handler: the object which has received the signal
433 * @channel: the #TpFileTransferChannel for which the transfer has started
435 * This signal is emitted when the actual transfer starts.
437 signals
[TRANSFER_STARTED
] =
438 g_signal_new ("transfer-started", G_TYPE_FROM_CLASS (klass
),
439 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
440 g_cclosure_marshal_generic
,
442 1, TP_TYPE_FILE_TRANSFER_CHANNEL
);
445 * EmpathyFTHandler::transfer-done
446 * @handler: the object which has received the signal
447 * @channel: the #TpFileTransferChannel for which the transfer has started
449 * This signal will be emitted when the actual transfer is completed
452 signals
[TRANSFER_DONE
] =
453 g_signal_new ("transfer-done", G_TYPE_FROM_CLASS (klass
),
454 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
455 g_cclosure_marshal_generic
,
457 1, TP_TYPE_FILE_TRANSFER_CHANNEL
);
460 * EmpathyFTHandler::transfer-error
461 * @handler: the object which has received the signal
464 * This signal can be emitted anytime between the call to
465 * empathy_ft_handler_start_transfer() and the last expected signal
466 * (::transfer-done or ::hashing-done), and it's guaranteed to be the last
467 * signal coming from the handler, meaning that no other operation will
468 * take place after this signal.
470 signals
[TRANSFER_ERROR
] =
471 g_signal_new ("transfer-error", G_TYPE_FROM_CLASS (klass
),
472 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
473 g_cclosure_marshal_generic
,
478 * EmpathyFTHandler::transfer-progress
479 * @handler: the object which has received the signal
480 * @current_bytes: the bytes currently transferred
481 * @total_bytes: the total bytes of the handler
482 * @remaining_time: the number of seconds remaining for the transfer
484 * @speed: the current speed of the transfer (in KB/s)
486 * This signal is emitted to notify clients of the progress of the
489 signals
[TRANSFER_PROGRESS
] =
490 g_signal_new ("transfer-progress", G_TYPE_FROM_CLASS (klass
),
491 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
492 g_cclosure_marshal_generic
,
494 4, G_TYPE_UINT64
, G_TYPE_UINT64
, G_TYPE_UINT
, G_TYPE_DOUBLE
);
497 * EmpathyFTHandler::hashing-started
498 * @handler: the object which has received the signal
500 * This signal is emitted when the hashing operation of the handler
501 * is started. Note that this might happen or not, depending on the CM
502 * and remote contact capabilities. Clients shoud use
503 * empathy_ft_handler_get_use_hash() before calling
504 * empathy_ft_handler_start_transfer() to know whether they should connect
507 signals
[HASHING_STARTED
] =
508 g_signal_new ("hashing-started", G_TYPE_FROM_CLASS (klass
),
509 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
510 g_cclosure_marshal_generic
,
514 * EmpathyFTHandler::hashing-progress
515 * @handler: the object which has received the signal
516 * @current_bytes: the bytes currently hashed
517 * @total_bytes: the total bytes of the handler
519 * This signal is emitted to notify clients of the progress of the
522 signals
[HASHING_PROGRESS
] =
523 g_signal_new ("hashing-progress", G_TYPE_FROM_CLASS (klass
),
524 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
525 g_cclosure_marshal_generic
,
527 2, G_TYPE_UINT64
, G_TYPE_UINT64
);
530 * EmpathyFTHandler::hashing-done
531 * @handler: the object which has received the signal
533 * This signal is emitted when the hashing operation of the handler
536 signals
[HASHING_DONE
] =
537 g_signal_new ("hashing-done", G_TYPE_FROM_CLASS (klass
),
538 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
539 g_cclosure_marshal_generic
,
544 empathy_ft_handler_init (EmpathyFTHandler
*self
)
546 EmpathyFTHandlerPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
547 EMPATHY_TYPE_FT_HANDLER
, EmpathyFTHandlerPriv
);
550 priv
->cancellable
= g_cancellable_new ();
553 /* private functions */
556 hash_data_free (HashingData
*data
)
558 g_free (data
->buffer
);
560 if (data
->stream
!= NULL
)
561 g_object_unref (data
->stream
);
563 if (data
->checksum
!= NULL
)
564 g_checksum_free (data
->checksum
);
566 if (data
->error
!= NULL
)
567 g_error_free (data
->error
);
569 if (data
->handler
!= NULL
)
570 g_object_unref (data
->handler
);
572 g_slice_free (HashingData
, data
);
576 tp_file_hash_to_g_checksum (TpFileHashType type
)
578 GChecksumType retval
;
582 case TP_FILE_HASH_TYPE_MD5
:
583 retval
= G_CHECKSUM_MD5
;
585 case TP_FILE_HASH_TYPE_SHA1
:
586 retval
= G_CHECKSUM_SHA1
;
588 case TP_FILE_HASH_TYPE_SHA256
:
589 retval
= G_CHECKSUM_SHA256
;
591 case TP_FILE_HASH_TYPE_NONE
:
593 g_assert_not_reached ();
601 check_hash_incoming (EmpathyFTHandler
*handler
)
603 HashingData
*hash_data
;
604 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
606 if (!TPAW_STR_EMPTY (priv
->content_hash
))
608 hash_data
= g_slice_new0 (HashingData
);
609 hash_data
->total_bytes
= priv
->total_bytes
;
610 hash_data
->handler
= g_object_ref (handler
);
611 hash_data
->checksum
= g_checksum_new
612 (tp_file_hash_to_g_checksum (priv
->content_hash_type
));
614 g_signal_emit (handler
, signals
[HASHING_STARTED
], 0);
616 g_io_scheduler_push_job (do_hash_job_incoming
, hash_data
, NULL
,
617 G_PRIORITY_DEFAULT
, priv
->cancellable
);
622 emit_error_signal (EmpathyFTHandler
*handler
,
625 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
627 DEBUG ("Error in transfer: %s\n", error
->message
);
629 if (!g_cancellable_is_cancelled (priv
->cancellable
))
630 g_cancellable_cancel (priv
->cancellable
);
632 g_signal_emit (handler
, signals
[TRANSFER_ERROR
], 0, error
);
636 update_remaining_time_and_speed (EmpathyFTHandler
*handler
,
637 guint64 transferred_bytes
)
639 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
640 gint64 elapsed_time
, current_time
;
641 guint64 transferred
, last_transferred_bytes
;
645 last_transferred_bytes
= priv
->transferred_bytes
;
646 priv
->transferred_bytes
= transferred_bytes
;
648 current_time
= tpaw_time_get_current ();
649 elapsed_time
= current_time
- priv
->last_update_time
;
651 if (elapsed_time
>= 1)
653 transferred
= transferred_bytes
- last_transferred_bytes
;
654 speed
= (gdouble
) transferred
/ (gdouble
) elapsed_time
;
655 remaining_time
= (priv
->total_bytes
- priv
->transferred_bytes
) / speed
;
657 priv
->remaining_time
= remaining_time
;
658 priv
->last_update_time
= current_time
;
663 ft_transfer_transferred_bytes_cb (TpFileTransferChannel
*channel
,
665 EmpathyFTHandler
*handler
)
667 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
670 if (empathy_ft_handler_is_cancelled (handler
))
673 bytes
= tp_file_transfer_channel_get_transferred_bytes (channel
);
675 if (priv
->transferred_bytes
== 0)
677 priv
->last_update_time
= tpaw_time_get_current ();
678 g_signal_emit (handler
, signals
[TRANSFER_STARTED
], 0, channel
);
681 if (priv
->transferred_bytes
!= bytes
)
683 update_remaining_time_and_speed (handler
, bytes
);
685 g_signal_emit (handler
, signals
[TRANSFER_PROGRESS
], 0,
686 bytes
, priv
->total_bytes
, priv
->remaining_time
,
692 ft_transfer_provide_cb (GObject
*source
,
693 GAsyncResult
*result
,
696 TpFileTransferChannel
*channel
= TP_FILE_TRANSFER_CHANNEL (source
);
697 EmpathyFTHandler
*handler
= user_data
;
698 GError
*error
= NULL
;
700 if (!tp_file_transfer_channel_provide_file_finish (channel
, result
, &error
))
702 emit_error_signal (handler
, error
);
703 g_clear_error (&error
);
708 ft_transfer_accept_cb (GObject
*source
,
709 GAsyncResult
*result
,
712 TpFileTransferChannel
*channel
= TP_FILE_TRANSFER_CHANNEL (source
);
713 EmpathyFTHandler
*handler
= user_data
;
714 GError
*error
= NULL
;
716 if (!tp_file_transfer_channel_accept_file_finish (channel
, result
, &error
))
718 emit_error_signal (handler
, error
);
719 g_clear_error (&error
);
724 error_from_state_change_reason (TpFileTransferStateChangeReason reason
)
727 GError
*retval
= NULL
;
733 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE
:
734 string
= _("No reason was specified");
736 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED
:
737 string
= _("The change in state was requested");
739 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED
:
740 string
= _("You canceled the file transfer");
742 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED
:
743 string
= _("The other participant canceled the file transfer");
745 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR
:
746 string
= _("Error while trying to transfer the file");
748 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR
:
749 string
= _("The other participant is unable to transfer the file");
752 string
= _("Unknown reason");
756 retval
= g_error_new_literal (EMPATHY_FT_ERROR_QUARK
,
757 EMPATHY_FT_ERROR_TP_ERROR
, string
);
763 ft_transfer_state_cb (TpFileTransferChannel
*channel
,
765 EmpathyFTHandler
*handler
)
767 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
768 TpFileTransferStateChangeReason reason
;
769 TpFileTransferState state
= tp_file_transfer_channel_get_state (
772 if (state
== TP_FILE_TRANSFER_STATE_COMPLETED
)
774 priv
->is_completed
= TRUE
;
775 g_signal_emit (handler
, signals
[TRANSFER_DONE
], 0, channel
);
777 tp_channel_close_async (TP_CHANNEL (channel
), NULL
, NULL
);
779 if (empathy_ft_handler_is_incoming (handler
) && priv
->use_hash
)
781 check_hash_incoming (handler
);
784 else if (state
== TP_FILE_TRANSFER_STATE_CANCELLED
)
786 GError
*error
= error_from_state_change_reason (reason
);
787 emit_error_signal (handler
, error
);
788 g_clear_error (&error
);
793 ft_handler_create_channel_cb (GObject
*source
,
794 GAsyncResult
*result
,
797 EmpathyFTHandler
*handler
= user_data
;
798 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
799 GError
*error
= NULL
;
802 DEBUG ("Dispatcher create channel CB");
804 channel
= tp_account_channel_request_create_and_handle_channel_finish (
805 TP_ACCOUNT_CHANNEL_REQUEST (source
), result
, NULL
, &error
);
808 DEBUG ("Failed to request FT channel: %s", error
->message
);
810 g_cancellable_set_error_if_cancelled (priv
->cancellable
, &error
);
814 emit_error_signal (handler
, error
);
816 g_clear_object (&channel
);
817 g_error_free (error
);
821 priv
->channel
= TP_FILE_TRANSFER_CHANNEL (channel
);
823 tp_g_signal_connect_object (priv
->channel
, "notify::state",
824 G_CALLBACK (ft_transfer_state_cb
), handler
, 0);
825 tp_g_signal_connect_object (priv
->channel
, "notify::transferred-bytes",
826 G_CALLBACK (ft_transfer_transferred_bytes_cb
), handler
, 0);
828 tp_file_transfer_channel_provide_file_async (priv
->channel
, priv
->gfile
,
829 ft_transfer_provide_cb
, handler
);
833 ft_handler_push_to_dispatcher (EmpathyFTHandler
*handler
)
836 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
837 TpAccountChannelRequest
*req
;
839 DEBUG ("Pushing request to the dispatcher");
841 account
= empathy_contact_get_account (priv
->contact
);
843 req
= tp_account_channel_request_new (account
, priv
->request
,
844 priv
->user_action_time
);
846 tp_account_channel_request_create_and_handle_channel_async (req
, NULL
,
847 ft_handler_create_channel_cb
, handler
);
849 g_object_unref (req
);
853 ft_handler_populate_outgoing_request (EmpathyFTHandler
*handler
)
855 guint contact_handle
;
856 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
859 contact_handle
= empathy_contact_get_handle (priv
->contact
);
860 uri
= g_file_get_uri (priv
->gfile
);
862 priv
->request
= tp_asv_new (
863 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
864 TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER
,
865 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, G_TYPE_UINT
,
866 TP_HANDLE_TYPE_CONTACT
,
867 TP_PROP_CHANNEL_TARGET_HANDLE
, G_TYPE_UINT
,
869 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE
, G_TYPE_STRING
,
871 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME
, G_TYPE_STRING
,
873 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE
, G_TYPE_UINT64
,
875 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_DATE
, G_TYPE_UINT64
,
877 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_URI
, G_TYPE_STRING
, uri
,
884 hash_job_done (gpointer user_data
)
886 HashingData
*hash_data
= user_data
;
887 EmpathyFTHandler
*handler
= hash_data
->handler
;
888 EmpathyFTHandlerPriv
*priv
;
889 GError
*error
= NULL
;
891 DEBUG ("Closing stream after hashing.");
893 priv
= GET_PRIV (handler
);
895 if (hash_data
->error
!= NULL
)
897 error
= hash_data
->error
;
898 hash_data
->error
= NULL
;
902 DEBUG ("Got file hash %s", g_checksum_get_string (hash_data
->checksum
));
904 if (empathy_ft_handler_is_incoming (handler
))
906 if (g_strcmp0 (g_checksum_get_string (hash_data
->checksum
),
909 DEBUG ("Hash mismatch when checking incoming handler: "
910 "received %s, calculated %s", priv
->content_hash
,
911 g_checksum_get_string (hash_data
->checksum
));
913 error
= g_error_new_literal (EMPATHY_FT_ERROR_QUARK
,
914 EMPATHY_FT_ERROR_HASH_MISMATCH
,
915 _("File transfer completed, but the file was corrupted"));
920 DEBUG ("Hash verification matched, received %s, calculated %s",
922 g_checksum_get_string (hash_data
->checksum
));
927 /* set the checksum in the request...
928 * org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHash
930 tp_asv_set_string (priv
->request
,
931 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH
,
932 g_checksum_get_string (hash_data
->checksum
));
939 emit_error_signal (handler
, error
);
940 g_clear_error (&error
);
944 g_signal_emit (handler
, signals
[HASHING_DONE
], 0);
946 if (!empathy_ft_handler_is_incoming (handler
))
947 /* the request is complete now, push it to the dispatcher */
948 ft_handler_push_to_dispatcher (handler
);
951 hash_data_free (hash_data
);
957 emit_hashing_progress (gpointer user_data
)
959 HashingData
*hash_data
= user_data
;
961 g_signal_emit (hash_data
->handler
, signals
[HASHING_PROGRESS
], 0,
962 (guint64
) hash_data
->total_read
, (guint64
) hash_data
->total_bytes
);
968 do_hash_job (GIOSchedulerJob
*job
,
969 GCancellable
*cancellable
,
972 HashingData
*hash_data
= user_data
;
974 GError
*error
= NULL
;
977 if (hash_data
->buffer
== NULL
)
978 hash_data
->buffer
= g_malloc0 (BUFFER_SIZE
);
980 bytes_read
= g_input_stream_read (hash_data
->stream
, hash_data
->buffer
,
981 BUFFER_SIZE
, cancellable
, &error
);
985 hash_data
->total_read
+= bytes_read
;
987 /* we now have the chunk */
990 g_checksum_update (hash_data
->checksum
, hash_data
->buffer
, bytes_read
);
991 g_io_scheduler_job_send_to_mainloop_async (job
, emit_hashing_progress
,
994 g_free (hash_data
->buffer
);
995 hash_data
->buffer
= NULL
;
1001 g_input_stream_close (hash_data
->stream
, cancellable
, &error
);
1006 hash_data
->error
= error
;
1008 g_io_scheduler_job_send_to_mainloop_async (job
, hash_job_done
,
1015 do_hash_job_incoming (GIOSchedulerJob
*job
,
1016 GCancellable
*cancellable
,
1019 HashingData
*hash_data
= user_data
;
1020 EmpathyFTHandler
*handler
= hash_data
->handler
;
1021 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1022 GError
*error
= NULL
;
1024 DEBUG ("checking integrity for incoming handler");
1026 /* need to get the stream first */
1028 G_INPUT_STREAM (g_file_read (priv
->gfile
, cancellable
, &error
));
1032 hash_data
->error
= error
;
1033 g_io_scheduler_job_send_to_mainloop_async (job
, hash_job_done
,
1038 return do_hash_job (job
, cancellable
, user_data
);
1042 ft_handler_read_async_cb (GObject
*source
,
1046 GFileInputStream
*stream
;
1047 GError
*error
= NULL
;
1048 HashingData
*hash_data
;
1049 EmpathyFTHandler
*handler
= user_data
;
1050 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1052 DEBUG ("GFile read async CB.");
1054 stream
= g_file_read_finish (priv
->gfile
, res
, &error
);
1057 emit_error_signal (handler
, error
);
1058 g_clear_error (&error
);
1063 hash_data
= g_slice_new0 (HashingData
);
1064 hash_data
->stream
= G_INPUT_STREAM (stream
);
1065 hash_data
->total_bytes
= priv
->total_bytes
;
1066 hash_data
->handler
= g_object_ref (handler
);
1067 /* FIXME: MD5 is the only ContentHashType supported right now */
1068 hash_data
->checksum
= g_checksum_new (G_CHECKSUM_MD5
);
1070 tp_asv_set_uint32 (priv
->request
,
1071 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE
,
1072 TP_FILE_HASH_TYPE_MD5
);
1074 g_signal_emit (handler
, signals
[HASHING_STARTED
], 0);
1076 g_io_scheduler_push_job (do_hash_job
, hash_data
, NULL
,
1077 G_PRIORITY_DEFAULT
, priv
->cancellable
);
1081 callbacks_data_free (gpointer user_data
)
1083 CallbacksData
*data
= user_data
;
1085 if (data
->handler
!= NULL
)
1086 g_object_unref (data
->handler
);
1088 g_slice_free (CallbacksData
, data
);
1092 set_content_hash_type_from_classes (EmpathyFTHandler
*handler
,
1095 GArray
*possible_values
;
1098 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1099 gboolean support_ft
= FALSE
;
1102 possible_values
= g_array_new (TRUE
, TRUE
, sizeof (guint
));
1104 for (i
= 0; i
< classes
->len
; i
++)
1108 const gchar
*chan_type
;
1110 tp_value_array_unpack (g_ptr_array_index (classes
, i
), 2,
1113 chan_type
= tp_asv_get_string (fixed
, TP_PROP_CHANNEL_CHANNEL_TYPE
);
1115 if (tp_strdiff (chan_type
, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER
))
1118 if (tp_asv_get_uint32 (fixed
, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, NULL
) !=
1119 TP_HANDLE_TYPE_CONTACT
)
1124 value
= tp_asv_get_uint32
1125 (fixed
, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE
,
1129 g_array_append_val (possible_values
, value
);
1134 g_array_unref (possible_values
);
1138 if (possible_values
->len
== 0)
1140 /* there are no channel classes with hash support, disable it. */
1141 priv
->use_hash
= FALSE
;
1142 priv
->content_hash_type
= TP_FILE_HASH_TYPE_NONE
;
1147 priv
->use_hash
= TRUE
;
1149 if (possible_values
->len
== 1)
1151 priv
->content_hash_type
= g_array_index (possible_values
, guint
, 0);
1155 /* order the array and pick the first non zero, so that MD5
1156 * is the preferred value.
1158 g_array_sort (possible_values
, empathy_uint_compare
);
1160 if (g_array_index (possible_values
, guint
, 0) == 0)
1161 priv
->content_hash_type
= g_array_index (possible_values
, guint
, 1);
1163 priv
->content_hash_type
= g_array_index (possible_values
, guint
, 0);
1167 g_array_unref (possible_values
);
1169 DEBUG ("Hash enabled %s; setting content hash type as %u",
1170 priv
->use_hash
? "True" : "False", priv
->content_hash_type
);
1176 check_hashing (CallbacksData
*data
)
1178 EmpathyFTHandler
*handler
= data
->handler
;
1179 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1180 GError
*myerr
= NULL
;
1181 TpCapabilities
*caps
;
1185 conn
= empathy_contact_get_connection (priv
->contact
);
1187 caps
= tp_connection_get_capabilities (conn
);
1190 data
->callback (handler
, NULL
, data
->user_data
);
1194 classes
= tp_capabilities_get_channel_classes (caps
);
1196 /* set whether we support hash and the type of it */
1197 if (!set_content_hash_type_from_classes (handler
, classes
))
1199 g_set_error_literal (&myerr
, EMPATHY_FT_ERROR_QUARK
,
1200 EMPATHY_FT_ERROR_NOT_SUPPORTED
,
1201 _("File transfer not supported by remote contact"));
1203 if (!g_cancellable_is_cancelled (priv
->cancellable
))
1204 g_cancellable_cancel (priv
->cancellable
);
1206 data
->callback (handler
, myerr
, data
->user_data
);
1207 g_clear_error (&myerr
);
1211 /* get back to the caller now */
1212 data
->callback (handler
, NULL
, data
->user_data
);
1216 callbacks_data_free (data
);
1220 ft_handler_complete_request (EmpathyFTHandler
*handler
)
1222 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1224 /* populate the request table with all the known properties */
1225 ft_handler_populate_outgoing_request (handler
);
1228 /* start hashing the file */
1229 g_file_read_async (priv
->gfile
, G_PRIORITY_DEFAULT
,
1230 priv
->cancellable
, ft_handler_read_async_cb
, handler
);
1232 /* push directly the handler to the dispatcher */
1233 ft_handler_push_to_dispatcher (handler
);
1237 ft_handler_gfile_ready_cb (GObject
*source
,
1239 CallbacksData
*cb_data
)
1242 GError
*error
= NULL
;
1244 EmpathyFTHandlerPriv
*priv
= GET_PRIV (cb_data
->handler
);
1246 DEBUG ("Got GFileInfo.");
1248 info
= g_file_query_info_finish (priv
->gfile
, res
, &error
);
1253 if (g_file_info_get_file_type (info
) != G_FILE_TYPE_REGULAR
)
1255 error
= g_error_new_literal (EMPATHY_FT_ERROR_QUARK
,
1256 EMPATHY_FT_ERROR_INVALID_SOURCE_FILE
,
1257 _("The selected file is not a regular file"));
1261 priv
->total_bytes
= g_file_info_get_size (info
);
1262 if (priv
->total_bytes
== 0)
1264 error
= g_error_new_literal (EMPATHY_FT_ERROR_QUARK
,
1265 EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE
,
1266 _("The selected file is empty"));
1270 priv
->content_type
= g_strdup (g_file_info_get_content_type (info
));
1271 priv
->filename
= g_strdup (g_file_info_get_display_name (info
));
1272 g_file_info_get_modification_time (info
, &mtime
);
1273 priv
->mtime
= mtime
.tv_sec
;
1274 priv
->transferred_bytes
= 0;
1275 priv
->description
= NULL
;
1277 g_object_unref (info
);
1282 if (!g_cancellable_is_cancelled (priv
->cancellable
))
1283 g_cancellable_cancel (priv
->cancellable
);
1285 cb_data
->callback (cb_data
->handler
, error
, cb_data
->user_data
);
1286 g_error_free (error
);
1288 callbacks_data_free (cb_data
);
1292 /* see if FT/hashing are allowed */
1293 check_hashing (cb_data
);
1298 channel_get_all_properties_cb (TpProxy
*proxy
,
1299 GHashTable
*properties
,
1300 const GError
*error
,
1302 GObject
*weak_object
)
1304 CallbacksData
*cb_data
= user_data
;
1305 EmpathyFTHandler
*handler
= EMPATHY_FT_HANDLER (weak_object
);
1306 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1311 if (!g_cancellable_is_cancelled (priv
->cancellable
))
1312 g_cancellable_cancel (priv
->cancellable
);
1314 cb_data
->callback (handler
, (GError
*) error
, cb_data
->user_data
);
1316 callbacks_data_free (cb_data
);
1320 priv
->content_hash
= g_value_dup_string (
1321 g_hash_table_lookup (properties
, "ContentHash"));
1323 priv
->content_hash_type
= g_value_get_uint (
1324 g_hash_table_lookup (properties
, "ContentHashType"));
1326 contact
= tp_channel_get_target_contact (TP_CHANNEL (proxy
));
1327 priv
->contact
= empathy_contact_dup_from_tp_contact (contact
);
1329 cb_data
->callback (handler
, NULL
, cb_data
->user_data
);
1332 /* public methods */
1335 * empathy_ft_handler_new_outgoing:
1336 * @contact: the #EmpathyContact to send @source to
1337 * @source: the #GFile to send
1338 * @callback: callback to be called when the handler has been created
1339 * @user_data: user data to be passed to @callback
1341 * Triggers the creation of a new #EmpathyFTHandler for an outgoing transfer.
1344 empathy_ft_handler_new_outgoing (EmpathyContact
*contact
,
1347 EmpathyFTHandlerReadyCallback callback
,
1350 EmpathyFTHandler
*handler
;
1351 CallbacksData
*data
;
1352 EmpathyFTHandlerPriv
*priv
;
1354 DEBUG ("New handler outgoing");
1356 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1357 g_return_if_fail (G_IS_FILE (source
));
1359 handler
= g_object_new (EMPATHY_TYPE_FT_HANDLER
,
1362 "user-action-time", action_time
,
1365 priv
= GET_PRIV (handler
);
1367 data
= g_slice_new0 (CallbacksData
);
1368 data
->callback
= callback
;
1369 data
->user_data
= user_data
;
1370 data
->handler
= g_object_ref (handler
);
1372 /* start collecting info about the file */
1373 g_file_query_info_async (priv
->gfile
,
1374 G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
","
1375 G_FILE_ATTRIBUTE_STANDARD_SIZE
","
1376 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
","
1377 G_FILE_ATTRIBUTE_STANDARD_TYPE
","
1378 G_FILE_ATTRIBUTE_TIME_MODIFIED
,
1379 G_FILE_QUERY_INFO_NONE
, G_PRIORITY_DEFAULT
,
1380 NULL
, (GAsyncReadyCallback
) ft_handler_gfile_ready_cb
, data
);
1384 * empathy_ft_handler_new_incoming:
1385 * @channel: the #TpFileTransferChannel proxy to the incoming channel
1386 * @callback: callback to be called when the handler has been created
1387 * @user_data: user data to be passed to @callback
1389 * Triggers the creation of a new #EmpathyFTHandler for an incoming transfer.
1390 * Note that for the handler to be useful, you will have to set a destination
1391 * file with empathy_ft_handler_incoming_set_destination() after the handler
1395 empathy_ft_handler_new_incoming (TpFileTransferChannel
*channel
,
1396 EmpathyFTHandlerReadyCallback callback
,
1399 EmpathyFTHandler
*handler
;
1400 CallbacksData
*data
;
1401 EmpathyFTHandlerPriv
*priv
;
1403 g_return_if_fail (TP_IS_FILE_TRANSFER_CHANNEL (channel
));
1405 handler
= g_object_new (EMPATHY_TYPE_FT_HANDLER
,
1406 "channel", channel
, NULL
);
1408 priv
= GET_PRIV (handler
);
1410 data
= g_slice_new0 (CallbacksData
);
1411 data
->callback
= callback
;
1412 data
->user_data
= user_data
;
1413 data
->handler
= g_object_ref (handler
);
1415 priv
->total_bytes
= tp_file_transfer_channel_get_size (channel
);
1417 priv
->transferred_bytes
= tp_file_transfer_channel_get_transferred_bytes (
1420 priv
->filename
= g_strdup (tp_file_transfer_channel_get_filename (channel
));
1422 priv
->content_type
= g_strdup (tp_file_transfer_channel_get_mime_type (
1425 priv
->description
= g_strdup (tp_file_transfer_channel_get_description (
1428 tp_cli_dbus_properties_call_get_all (channel
,
1429 -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER
,
1430 channel_get_all_properties_cb
, data
, NULL
, G_OBJECT (handler
));
1434 * empathy_ft_handler_start_transfer:
1435 * @handler: an #EmpathyFTHandler
1437 * Starts the transfer machinery. After this call, the transfer and hashing
1438 * signals will be emitted by the handler.
1441 empathy_ft_handler_start_transfer (EmpathyFTHandler
*handler
)
1443 EmpathyFTHandlerPriv
*priv
;
1445 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler
));
1447 priv
= GET_PRIV (handler
);
1449 if (priv
->channel
== NULL
)
1451 ft_handler_complete_request (handler
);
1455 /* TODO: add support for resume. */
1456 tp_file_transfer_channel_accept_file_async (priv
->channel
,
1457 priv
->gfile
, 0, ft_transfer_accept_cb
, handler
);
1459 tp_g_signal_connect_object (priv
->channel
, "notify::state",
1460 G_CALLBACK (ft_transfer_state_cb
), handler
, 0);
1461 tp_g_signal_connect_object (priv
->channel
, "notify::transferred-bytes",
1462 G_CALLBACK (ft_transfer_transferred_bytes_cb
), handler
, 0);
1467 * empathy_ft_handler_cancel_transfer:
1468 * @handler: an #EmpathyFTHandler
1470 * Cancels an ongoing handler operation. Note that this doesn't destroy
1471 * the object, which will keep all the properties, altough it won't be able
1472 * to do any more I/O.
1475 empathy_ft_handler_cancel_transfer (EmpathyFTHandler
*handler
)
1477 EmpathyFTHandlerPriv
*priv
;
1479 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler
));
1481 priv
= GET_PRIV (handler
);
1483 /* if we don't have a channel, we are hashing, so
1484 * we can just cancel the GCancellable to stop it.
1486 if (priv
->channel
== NULL
)
1487 g_cancellable_cancel (priv
->cancellable
);
1489 tp_channel_close_async (TP_CHANNEL (priv
->channel
), NULL
, NULL
);
1493 * empathy_ft_handler_incoming_set_destination:
1494 * @handler: an #EmpathyFTHandler
1495 * @destination: the #GFile where the transfer should be saved
1497 * Sets the destination of the incoming handler to be @destination.
1498 * Note that calling this method is mandatory before starting the transfer
1499 * for incoming handlers.
1502 empathy_ft_handler_incoming_set_destination (EmpathyFTHandler
*handler
,
1505 EmpathyFTHandlerPriv
*priv
;
1507 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler
));
1508 g_return_if_fail (G_IS_FILE (destination
));
1510 priv
= GET_PRIV (handler
);
1512 g_object_set (handler
, "gfile", destination
, NULL
);
1514 /* check if hash is supported. if it isn't, set use_hash to FALSE
1515 * anyway, so that clients won't be expecting us to checksum.
1517 if (TPAW_STR_EMPTY (priv
->content_hash
) ||
1518 priv
->content_hash_type
== TP_FILE_HASH_TYPE_NONE
)
1519 priv
->use_hash
= FALSE
;
1521 priv
->use_hash
= TRUE
;
1525 * empathy_ft_handler_get_filename:
1526 * @handler: an #EmpathyFTHandler
1528 * Returns the name of the file being transferred.
1530 * Return value: the name of the file being transferred
1533 empathy_ft_handler_get_filename (EmpathyFTHandler
*handler
)
1535 EmpathyFTHandlerPriv
*priv
;
1537 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), NULL
);
1539 priv
= GET_PRIV (handler
);
1541 return priv
->filename
;
1545 * empathy_ft_handler_get_content_type:
1546 * @handler: an #EmpathyFTHandler
1548 * Returns the content type of the file being transferred.
1550 * Return value: the content type of the file being transferred
1553 empathy_ft_handler_get_content_type (EmpathyFTHandler
*handler
)
1555 EmpathyFTHandlerPriv
*priv
;
1557 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), NULL
);
1559 priv
= GET_PRIV (handler
);
1561 return priv
->content_type
;
1565 * empathy_ft_handler_get_contact:
1566 * @handler: an #EmpathyFTHandler
1568 * Returns the remote #EmpathyContact at the other side of the transfer.
1570 * Return value: the remote #EmpathyContact for @handler
1573 empathy_ft_handler_get_contact (EmpathyFTHandler
*handler
)
1575 EmpathyFTHandlerPriv
*priv
;
1577 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), NULL
);
1579 priv
= GET_PRIV (handler
);
1581 return priv
->contact
;
1585 * empathy_ft_handler_get_gfile:
1586 * @handler: an #EmpathyFTHandler
1588 * Returns the #GFile where the transfer is being read/saved.
1590 * Return value: the #GFile where the transfer is being read/saved
1593 empathy_ft_handler_get_gfile (EmpathyFTHandler
*handler
)
1595 EmpathyFTHandlerPriv
*priv
;
1597 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), NULL
);
1599 priv
= GET_PRIV (handler
);
1605 * empathy_ft_handler_get_use_hash:
1606 * @handler: an #EmpathyFTHandler
1608 * Returns whether @handler has checksumming enabled. This can depend on
1609 * the CM and the remote contact capabilities.
1611 * Return value: %TRUE if the handler has checksumming enabled,
1615 empathy_ft_handler_get_use_hash (EmpathyFTHandler
*handler
)
1617 EmpathyFTHandlerPriv
*priv
;
1619 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), FALSE
);
1621 priv
= GET_PRIV (handler
);
1623 return priv
->use_hash
;
1627 * empathy_ft_handler_is_incoming:
1628 * @handler: an #EmpathyFTHandler
1630 * Returns whether @handler is incoming or outgoing.
1632 * Return value: %TRUE if the handler is incoming, %FALSE otherwise.
1635 empathy_ft_handler_is_incoming (EmpathyFTHandler
*handler
)
1637 EmpathyFTHandlerPriv
*priv
;
1639 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), FALSE
);
1641 priv
= GET_PRIV (handler
);
1643 if (priv
->channel
== NULL
)
1646 return !tp_channel_get_requested ((TpChannel
*) priv
->channel
);
1650 * empathy_ft_handler_get_transferred_bytes:
1651 * @handler: an #EmpathyFTHandler
1653 * Returns the number of bytes already transferred by the handler.
1655 * Return value: the number of bytes already transferred by the handler.
1658 empathy_ft_handler_get_transferred_bytes (EmpathyFTHandler
*handler
)
1660 EmpathyFTHandlerPriv
*priv
;
1662 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), 0);
1664 priv
= GET_PRIV (handler
);
1666 return priv
->transferred_bytes
;
1670 * empathy_ft_handler_get_total_bytes:
1671 * @handler: an #EmpathyFTHandler
1673 * Returns the total size of the file being transferred by the handler.
1675 * Return value: a number of bytes indicating the total size of the file being
1676 * transferred by the handler.
1679 empathy_ft_handler_get_total_bytes (EmpathyFTHandler
*handler
)
1681 EmpathyFTHandlerPriv
*priv
;
1683 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), 0);
1685 priv
= GET_PRIV (handler
);
1687 return priv
->total_bytes
;
1691 * empathy_ft_handler_is_completed:
1692 * @handler: an #EmpathyFTHandler
1694 * Returns whether the transfer for @handler has been completed succesfully.
1696 * Return value: %TRUE if the handler has been transferred correctly, %FALSE
1700 empathy_ft_handler_is_completed (EmpathyFTHandler
*handler
)
1702 EmpathyFTHandlerPriv
*priv
;
1704 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), FALSE
);
1706 priv
= GET_PRIV (handler
);
1708 return priv
->is_completed
;
1712 * empathy_ft_handler_is_cancelled:
1713 * @handler: an #EmpathyFTHandler
1715 * Returns whether the transfer for @handler has been cancelled or has stopped
1718 * Return value: %TRUE if the transfer for @handler has been cancelled
1719 * or has stopped due to an error, %FALSE otherwise.
1722 empathy_ft_handler_is_cancelled (EmpathyFTHandler
*handler
)
1724 EmpathyFTHandlerPriv
*priv
;
1726 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), FALSE
);
1728 priv
= GET_PRIV (handler
);
1730 return g_cancellable_is_cancelled (priv
->cancellable
);