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 */
126 TpAccountChannelRequest
*request
;
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 g_clear_object (&priv
->request
);
278 G_OBJECT_CLASS (empathy_ft_handler_parent_class
)->dispose (object
);
282 do_finalize (GObject
*object
)
284 EmpathyFTHandlerPriv
*priv
= GET_PRIV (object
);
286 DEBUG ("%p", object
);
288 g_free (priv
->content_type
);
289 priv
->content_type
= NULL
;
291 g_free (priv
->filename
);
292 priv
->filename
= NULL
;
294 g_free (priv
->description
);
295 priv
->description
= NULL
;
297 g_free (priv
->content_hash
);
298 priv
->content_hash
= NULL
;
300 G_OBJECT_CLASS (empathy_ft_handler_parent_class
)->finalize (object
);
304 empathy_ft_handler_class_init (EmpathyFTHandlerClass
*klass
)
306 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
307 GParamSpec
*param_spec
;
309 g_type_class_add_private (klass
, sizeof (EmpathyFTHandlerPriv
));
311 object_class
->get_property
= do_get_property
;
312 object_class
->set_property
= do_set_property
;
313 object_class
->dispose
= do_dispose
;
314 object_class
->finalize
= do_finalize
;
319 * EmpathyFTHandler:contact:
321 * The remote #EmpathyContact for the transfer
323 param_spec
= g_param_spec_object ("contact",
324 "contact", "The remote contact",
325 EMPATHY_TYPE_CONTACT
,
326 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
327 g_object_class_install_property (object_class
, PROP_CONTACT
, param_spec
);
330 * EmpathyFTHandler:content-type:
332 * The content type of the file being transferred
334 param_spec
= g_param_spec_string ("content-type",
335 "content-type", "The content type of the file", NULL
,
336 G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
337 g_object_class_install_property (object_class
,
338 PROP_CONTENT_TYPE
, param_spec
);
341 * EmpathyFTHandler:description:
343 * The description of the file being transferred
345 param_spec
= g_param_spec_string ("description",
346 "description", "The description of the file", NULL
,
347 G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
348 g_object_class_install_property (object_class
,
349 PROP_DESCRIPTION
, param_spec
);
352 * EmpathyFTHandler:filename:
354 * The name of the file being transferred
356 param_spec
= g_param_spec_string ("filename",
357 "filename", "The name of the file", NULL
,
358 G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
359 g_object_class_install_property (object_class
,
360 PROP_FILENAME
, param_spec
);
363 * EmpathyFTHandler:modification-time:
365 * The modification time of the file being transferred
367 param_spec
= g_param_spec_uint64 ("modification-time",
368 "modification-time", "The mtime of the file", 0,
369 G_MAXUINT64
, 0, G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
370 g_object_class_install_property (object_class
,
371 PROP_MODIFICATION_TIME
, param_spec
);
374 * EmpathyFTHandler:total-bytes:
376 * The size (in bytes) of the file being transferred
378 param_spec
= g_param_spec_uint64 ("total-bytes",
379 "total-bytes", "The size of the file", 0,
380 G_MAXUINT64
, 0, G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
381 g_object_class_install_property (object_class
,
382 PROP_TOTAL_BYTES
, param_spec
);
385 * EmpathyFTHandler:transferred-bytes:
387 * The number of the bytes already transferred
389 param_spec
= g_param_spec_uint64 ("transferred-bytes",
390 "transferred-bytes", "The number of bytes already transferred", 0,
391 G_MAXUINT64
, 0, G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
392 g_object_class_install_property (object_class
,
393 PROP_TRANSFERRED_BYTES
, param_spec
);
396 * EmpathyFTHandler:gfile:
398 * The #GFile object where the transfer actually happens
400 param_spec
= g_param_spec_object ("gfile",
401 "gfile", "The GFile we're handling",
403 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
404 g_object_class_install_property (object_class
, PROP_G_FILE
, param_spec
);
407 * EmpathyFTHandler:channel:
409 * The underlying #TpFileTransferChannel managing the transfer
411 param_spec
= g_param_spec_object ("channel",
412 "channel", "The file transfer channel",
413 TP_TYPE_FILE_TRANSFER_CHANNEL
,
414 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
415 g_object_class_install_property (object_class
, PROP_CHANNEL
, param_spec
);
417 param_spec
= g_param_spec_int64 ("user-action-time", "user action time",
420 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
421 g_object_class_install_property (object_class
, PROP_USER_ACTION_TIME
,
427 * EmpathyFTHandler::transfer-started
428 * @handler: the object which has received the signal
429 * @channel: the #TpFileTransferChannel for which the transfer has started
431 * This signal is emitted when the actual transfer starts.
433 signals
[TRANSFER_STARTED
] =
434 g_signal_new ("transfer-started", G_TYPE_FROM_CLASS (klass
),
435 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
436 g_cclosure_marshal_generic
,
438 1, TP_TYPE_FILE_TRANSFER_CHANNEL
);
441 * EmpathyFTHandler::transfer-done
442 * @handler: the object which has received the signal
443 * @channel: the #TpFileTransferChannel for which the transfer has started
445 * This signal will be emitted when the actual transfer is completed
448 signals
[TRANSFER_DONE
] =
449 g_signal_new ("transfer-done", G_TYPE_FROM_CLASS (klass
),
450 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
451 g_cclosure_marshal_generic
,
453 1, TP_TYPE_FILE_TRANSFER_CHANNEL
);
456 * EmpathyFTHandler::transfer-error
457 * @handler: the object which has received the signal
460 * This signal can be emitted anytime between the call to
461 * empathy_ft_handler_start_transfer() and the last expected signal
462 * (::transfer-done or ::hashing-done), and it's guaranteed to be the last
463 * signal coming from the handler, meaning that no other operation will
464 * take place after this signal.
466 signals
[TRANSFER_ERROR
] =
467 g_signal_new ("transfer-error", G_TYPE_FROM_CLASS (klass
),
468 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
469 g_cclosure_marshal_generic
,
474 * EmpathyFTHandler::transfer-progress
475 * @handler: the object which has received the signal
476 * @current_bytes: the bytes currently transferred
477 * @total_bytes: the total bytes of the handler
478 * @remaining_time: the number of seconds remaining for the transfer
480 * @speed: the current speed of the transfer (in KB/s)
482 * This signal is emitted to notify clients of the progress of the
485 signals
[TRANSFER_PROGRESS
] =
486 g_signal_new ("transfer-progress", G_TYPE_FROM_CLASS (klass
),
487 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
488 g_cclosure_marshal_generic
,
490 4, G_TYPE_UINT64
, G_TYPE_UINT64
, G_TYPE_UINT
, G_TYPE_DOUBLE
);
493 * EmpathyFTHandler::hashing-started
494 * @handler: the object which has received the signal
496 * This signal is emitted when the hashing operation of the handler
497 * is started. Note that this might happen or not, depending on the CM
498 * and remote contact capabilities. Clients shoud use
499 * empathy_ft_handler_get_use_hash() before calling
500 * empathy_ft_handler_start_transfer() to know whether they should connect
503 signals
[HASHING_STARTED
] =
504 g_signal_new ("hashing-started", G_TYPE_FROM_CLASS (klass
),
505 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
506 g_cclosure_marshal_generic
,
510 * EmpathyFTHandler::hashing-progress
511 * @handler: the object which has received the signal
512 * @current_bytes: the bytes currently hashed
513 * @total_bytes: the total bytes of the handler
515 * This signal is emitted to notify clients of the progress of the
518 signals
[HASHING_PROGRESS
] =
519 g_signal_new ("hashing-progress", G_TYPE_FROM_CLASS (klass
),
520 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
521 g_cclosure_marshal_generic
,
523 2, G_TYPE_UINT64
, G_TYPE_UINT64
);
526 * EmpathyFTHandler::hashing-done
527 * @handler: the object which has received the signal
529 * This signal is emitted when the hashing operation of the handler
532 signals
[HASHING_DONE
] =
533 g_signal_new ("hashing-done", G_TYPE_FROM_CLASS (klass
),
534 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
,
535 g_cclosure_marshal_generic
,
540 empathy_ft_handler_init (EmpathyFTHandler
*self
)
542 EmpathyFTHandlerPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
543 EMPATHY_TYPE_FT_HANDLER
, EmpathyFTHandlerPriv
);
546 priv
->cancellable
= g_cancellable_new ();
549 /* private functions */
552 hash_data_free (HashingData
*data
)
554 g_free (data
->buffer
);
556 if (data
->stream
!= NULL
)
557 g_object_unref (data
->stream
);
559 if (data
->checksum
!= NULL
)
560 g_checksum_free (data
->checksum
);
562 if (data
->error
!= NULL
)
563 g_error_free (data
->error
);
565 if (data
->handler
!= NULL
)
566 g_object_unref (data
->handler
);
568 g_slice_free (HashingData
, data
);
572 tp_file_hash_to_g_checksum (TpFileHashType type
)
574 GChecksumType retval
;
578 case TP_FILE_HASH_TYPE_MD5
:
579 retval
= G_CHECKSUM_MD5
;
581 case TP_FILE_HASH_TYPE_SHA1
:
582 retval
= G_CHECKSUM_SHA1
;
584 case TP_FILE_HASH_TYPE_SHA256
:
585 retval
= G_CHECKSUM_SHA256
;
587 case TP_FILE_HASH_TYPE_NONE
:
589 g_assert_not_reached ();
597 check_hash_incoming (EmpathyFTHandler
*handler
)
599 HashingData
*hash_data
;
600 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
602 if (!TPAW_STR_EMPTY (priv
->content_hash
))
604 hash_data
= g_slice_new0 (HashingData
);
605 hash_data
->total_bytes
= priv
->total_bytes
;
606 hash_data
->handler
= g_object_ref (handler
);
607 hash_data
->checksum
= g_checksum_new
608 (tp_file_hash_to_g_checksum (priv
->content_hash_type
));
610 g_signal_emit (handler
, signals
[HASHING_STARTED
], 0);
612 g_io_scheduler_push_job (do_hash_job_incoming
, hash_data
, NULL
,
613 G_PRIORITY_DEFAULT
, priv
->cancellable
);
618 emit_error_signal (EmpathyFTHandler
*handler
,
621 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
623 DEBUG ("Error in transfer: %s\n", error
->message
);
625 if (!g_cancellable_is_cancelled (priv
->cancellable
))
626 g_cancellable_cancel (priv
->cancellable
);
628 g_signal_emit (handler
, signals
[TRANSFER_ERROR
], 0, error
);
632 update_remaining_time_and_speed (EmpathyFTHandler
*handler
,
633 guint64 transferred_bytes
)
635 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
636 gint64 elapsed_time
, current_time
;
637 guint64 transferred
, last_transferred_bytes
;
641 last_transferred_bytes
= priv
->transferred_bytes
;
642 priv
->transferred_bytes
= transferred_bytes
;
644 current_time
= tpaw_time_get_current ();
645 elapsed_time
= current_time
- priv
->last_update_time
;
647 if (elapsed_time
>= 1)
649 transferred
= transferred_bytes
- last_transferred_bytes
;
650 speed
= (gdouble
) transferred
/ (gdouble
) elapsed_time
;
651 remaining_time
= (priv
->total_bytes
- priv
->transferred_bytes
) / speed
;
653 priv
->remaining_time
= remaining_time
;
654 priv
->last_update_time
= current_time
;
659 ft_transfer_transferred_bytes_cb (TpFileTransferChannel
*channel
,
661 EmpathyFTHandler
*handler
)
663 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
666 if (empathy_ft_handler_is_cancelled (handler
))
669 bytes
= tp_file_transfer_channel_get_transferred_bytes (channel
);
671 if (priv
->transferred_bytes
== 0)
673 priv
->last_update_time
= tpaw_time_get_current ();
674 g_signal_emit (handler
, signals
[TRANSFER_STARTED
], 0, channel
);
677 if (priv
->transferred_bytes
!= bytes
)
679 update_remaining_time_and_speed (handler
, bytes
);
681 g_signal_emit (handler
, signals
[TRANSFER_PROGRESS
], 0,
682 bytes
, priv
->total_bytes
, priv
->remaining_time
,
688 ft_transfer_provide_cb (GObject
*source
,
689 GAsyncResult
*result
,
692 TpFileTransferChannel
*channel
= TP_FILE_TRANSFER_CHANNEL (source
);
693 EmpathyFTHandler
*handler
= user_data
;
694 GError
*error
= NULL
;
696 if (!tp_file_transfer_channel_provide_file_finish (channel
, result
, &error
))
698 emit_error_signal (handler
, error
);
699 g_clear_error (&error
);
704 ft_transfer_accept_cb (GObject
*source
,
705 GAsyncResult
*result
,
708 TpFileTransferChannel
*channel
= TP_FILE_TRANSFER_CHANNEL (source
);
709 EmpathyFTHandler
*handler
= user_data
;
710 GError
*error
= NULL
;
712 if (!tp_file_transfer_channel_accept_file_finish (channel
, result
, &error
))
714 emit_error_signal (handler
, error
);
715 g_clear_error (&error
);
720 error_from_state_change_reason (TpFileTransferStateChangeReason reason
)
723 GError
*retval
= NULL
;
729 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE
:
730 string
= _("No reason was specified");
732 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED
:
733 string
= _("The change in state was requested");
735 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED
:
736 string
= _("You canceled the file transfer");
738 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED
:
739 string
= _("The other participant canceled the file transfer");
741 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR
:
742 string
= _("Error while trying to transfer the file");
744 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR
:
745 string
= _("The other participant is unable to transfer the file");
748 string
= _("Unknown reason");
752 retval
= g_error_new_literal (EMPATHY_FT_ERROR_QUARK
,
753 EMPATHY_FT_ERROR_TP_ERROR
, string
);
759 ft_transfer_state_cb (TpFileTransferChannel
*channel
,
761 EmpathyFTHandler
*handler
)
763 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
764 TpFileTransferStateChangeReason reason
;
765 TpFileTransferState state
= tp_file_transfer_channel_get_state (
768 if (state
== TP_FILE_TRANSFER_STATE_COMPLETED
)
770 priv
->is_completed
= TRUE
;
771 g_signal_emit (handler
, signals
[TRANSFER_DONE
], 0, channel
);
773 tp_channel_close_async (TP_CHANNEL (channel
), NULL
, NULL
);
775 if (empathy_ft_handler_is_incoming (handler
) && priv
->use_hash
)
777 check_hash_incoming (handler
);
780 else if (state
== TP_FILE_TRANSFER_STATE_CANCELLED
)
782 GError
*error
= error_from_state_change_reason (reason
);
783 emit_error_signal (handler
, error
);
784 g_clear_error (&error
);
789 ft_handler_create_channel_cb (GObject
*source
,
790 GAsyncResult
*result
,
793 EmpathyFTHandler
*handler
= user_data
;
794 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
795 GError
*error
= NULL
;
798 DEBUG ("Dispatcher create channel CB");
800 channel
= tp_account_channel_request_create_and_handle_channel_finish (
801 TP_ACCOUNT_CHANNEL_REQUEST (source
), result
, NULL
, &error
);
804 DEBUG ("Failed to request FT channel: %s", error
->message
);
806 g_cancellable_set_error_if_cancelled (priv
->cancellable
, &error
);
810 emit_error_signal (handler
, error
);
812 g_clear_object (&channel
);
813 g_error_free (error
);
817 priv
->channel
= TP_FILE_TRANSFER_CHANNEL (channel
);
819 tp_g_signal_connect_object (priv
->channel
, "notify::state",
820 G_CALLBACK (ft_transfer_state_cb
), handler
, 0);
821 tp_g_signal_connect_object (priv
->channel
, "notify::transferred-bytes",
822 G_CALLBACK (ft_transfer_transferred_bytes_cb
), handler
, 0);
824 tp_file_transfer_channel_provide_file_async (priv
->channel
, priv
->gfile
,
825 ft_transfer_provide_cb
, handler
);
829 ft_handler_push_to_dispatcher (EmpathyFTHandler
*handler
)
831 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
833 DEBUG ("Pushing request to the dispatcher");
835 tp_account_channel_request_create_and_handle_channel_async (priv
->request
,
836 NULL
, ft_handler_create_channel_cb
, handler
);
840 ft_handler_populate_outgoing_request (EmpathyFTHandler
*handler
)
842 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
846 uri
= g_file_get_uri (priv
->gfile
);
847 account
= empathy_contact_get_account (priv
->contact
);
849 priv
->request
= tp_account_channel_request_new_file_transfer (account
,
850 priv
->filename
, priv
->content_type
, priv
->total_bytes
,
851 priv
->user_action_time
);
853 tp_account_channel_request_set_target_contact (priv
->request
,
854 empathy_contact_get_tp_contact (priv
->contact
));
856 tp_account_channel_request_set_file_transfer_timestamp (priv
->request
,
858 tp_account_channel_request_set_file_transfer_uri (priv
->request
, uri
);
864 hash_job_done (gpointer user_data
)
866 HashingData
*hash_data
= user_data
;
867 EmpathyFTHandler
*handler
= hash_data
->handler
;
868 EmpathyFTHandlerPriv
*priv
;
869 GError
*error
= NULL
;
871 DEBUG ("Closing stream after hashing.");
873 priv
= GET_PRIV (handler
);
875 if (hash_data
->error
!= NULL
)
877 error
= hash_data
->error
;
878 hash_data
->error
= NULL
;
882 DEBUG ("Got file hash %s", g_checksum_get_string (hash_data
->checksum
));
884 if (empathy_ft_handler_is_incoming (handler
))
886 if (g_strcmp0 (g_checksum_get_string (hash_data
->checksum
),
889 DEBUG ("Hash mismatch when checking incoming handler: "
890 "received %s, calculated %s", priv
->content_hash
,
891 g_checksum_get_string (hash_data
->checksum
));
893 error
= g_error_new_literal (EMPATHY_FT_ERROR_QUARK
,
894 EMPATHY_FT_ERROR_HASH_MISMATCH
,
895 _("File transfer completed, but the file was corrupted"));
900 DEBUG ("Hash verification matched, received %s, calculated %s",
902 g_checksum_get_string (hash_data
->checksum
));
907 /* set the checksum in the request...
908 * org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHash
910 tp_account_channel_request_set_file_transfer_hash (priv
->request
,
911 TP_FILE_HASH_TYPE_MD5
, g_checksum_get_string (hash_data
->checksum
));
918 emit_error_signal (handler
, error
);
919 g_clear_error (&error
);
923 g_signal_emit (handler
, signals
[HASHING_DONE
], 0);
925 if (!empathy_ft_handler_is_incoming (handler
))
926 /* the request is complete now, push it to the dispatcher */
927 ft_handler_push_to_dispatcher (handler
);
930 hash_data_free (hash_data
);
936 emit_hashing_progress (gpointer user_data
)
938 HashingData
*hash_data
= user_data
;
940 g_signal_emit (hash_data
->handler
, signals
[HASHING_PROGRESS
], 0,
941 (guint64
) hash_data
->total_read
, (guint64
) hash_data
->total_bytes
);
947 do_hash_job (GIOSchedulerJob
*job
,
948 GCancellable
*cancellable
,
951 HashingData
*hash_data
= user_data
;
953 GError
*error
= NULL
;
956 if (hash_data
->buffer
== NULL
)
957 hash_data
->buffer
= g_malloc0 (BUFFER_SIZE
);
959 bytes_read
= g_input_stream_read (hash_data
->stream
, hash_data
->buffer
,
960 BUFFER_SIZE
, cancellable
, &error
);
964 hash_data
->total_read
+= bytes_read
;
966 /* we now have the chunk */
969 g_checksum_update (hash_data
->checksum
, hash_data
->buffer
, bytes_read
);
970 g_io_scheduler_job_send_to_mainloop_async (job
, emit_hashing_progress
,
973 g_free (hash_data
->buffer
);
974 hash_data
->buffer
= NULL
;
980 g_input_stream_close (hash_data
->stream
, cancellable
, &error
);
985 hash_data
->error
= error
;
987 g_io_scheduler_job_send_to_mainloop_async (job
, hash_job_done
,
994 do_hash_job_incoming (GIOSchedulerJob
*job
,
995 GCancellable
*cancellable
,
998 HashingData
*hash_data
= user_data
;
999 EmpathyFTHandler
*handler
= hash_data
->handler
;
1000 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1001 GError
*error
= NULL
;
1003 DEBUG ("checking integrity for incoming handler");
1005 /* need to get the stream first */
1007 G_INPUT_STREAM (g_file_read (priv
->gfile
, cancellable
, &error
));
1011 hash_data
->error
= error
;
1012 g_io_scheduler_job_send_to_mainloop_async (job
, hash_job_done
,
1017 return do_hash_job (job
, cancellable
, user_data
);
1021 ft_handler_read_async_cb (GObject
*source
,
1025 GFileInputStream
*stream
;
1026 GError
*error
= NULL
;
1027 HashingData
*hash_data
;
1028 EmpathyFTHandler
*handler
= user_data
;
1029 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1031 DEBUG ("GFile read async CB.");
1033 stream
= g_file_read_finish (priv
->gfile
, res
, &error
);
1036 emit_error_signal (handler
, error
);
1037 g_clear_error (&error
);
1042 hash_data
= g_slice_new0 (HashingData
);
1043 hash_data
->stream
= G_INPUT_STREAM (stream
);
1044 hash_data
->total_bytes
= priv
->total_bytes
;
1045 hash_data
->handler
= g_object_ref (handler
);
1046 /* FIXME: MD5 is the only ContentHashType supported right now */
1047 hash_data
->checksum
= g_checksum_new (G_CHECKSUM_MD5
);
1049 g_signal_emit (handler
, signals
[HASHING_STARTED
], 0);
1051 g_io_scheduler_push_job (do_hash_job
, hash_data
, NULL
,
1052 G_PRIORITY_DEFAULT
, priv
->cancellable
);
1056 callbacks_data_free (gpointer user_data
)
1058 CallbacksData
*data
= user_data
;
1060 if (data
->handler
!= NULL
)
1061 g_object_unref (data
->handler
);
1063 g_slice_free (CallbacksData
, data
);
1067 set_content_hash_type_from_classes (EmpathyFTHandler
*handler
,
1070 GArray
*possible_values
;
1073 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1074 gboolean support_ft
= FALSE
;
1077 possible_values
= g_array_new (TRUE
, TRUE
, sizeof (guint
));
1079 for (i
= 0; i
< classes
->len
; i
++)
1083 const gchar
*chan_type
;
1085 tp_value_array_unpack (g_ptr_array_index (classes
, i
), 2,
1088 chan_type
= tp_asv_get_string (fixed
, TP_PROP_CHANNEL_CHANNEL_TYPE
);
1090 if (tp_strdiff (chan_type
, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER
))
1093 if (tp_asv_get_uint32 (fixed
, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, NULL
) !=
1094 TP_HANDLE_TYPE_CONTACT
)
1099 value
= tp_asv_get_uint32
1100 (fixed
, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE
,
1104 g_array_append_val (possible_values
, value
);
1109 g_array_unref (possible_values
);
1113 if (possible_values
->len
== 0)
1115 /* there are no channel classes with hash support, disable it. */
1116 priv
->use_hash
= FALSE
;
1117 priv
->content_hash_type
= TP_FILE_HASH_TYPE_NONE
;
1122 priv
->use_hash
= TRUE
;
1124 if (possible_values
->len
== 1)
1126 priv
->content_hash_type
= g_array_index (possible_values
, guint
, 0);
1130 /* order the array and pick the first non zero, so that MD5
1131 * is the preferred value.
1133 g_array_sort (possible_values
, empathy_uint_compare
);
1135 if (g_array_index (possible_values
, guint
, 0) == 0)
1136 priv
->content_hash_type
= g_array_index (possible_values
, guint
, 1);
1138 priv
->content_hash_type
= g_array_index (possible_values
, guint
, 0);
1142 g_array_unref (possible_values
);
1144 DEBUG ("Hash enabled %s; setting content hash type as %u",
1145 priv
->use_hash
? "True" : "False", priv
->content_hash_type
);
1151 check_hashing (CallbacksData
*data
)
1153 EmpathyFTHandler
*handler
= data
->handler
;
1154 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1155 GError
*myerr
= NULL
;
1156 TpCapabilities
*caps
;
1160 conn
= empathy_contact_get_connection (priv
->contact
);
1162 caps
= tp_connection_get_capabilities (conn
);
1165 data
->callback (handler
, NULL
, data
->user_data
);
1169 classes
= tp_capabilities_get_channel_classes (caps
);
1171 /* set whether we support hash and the type of it */
1172 if (!set_content_hash_type_from_classes (handler
, classes
))
1174 g_set_error_literal (&myerr
, EMPATHY_FT_ERROR_QUARK
,
1175 EMPATHY_FT_ERROR_NOT_SUPPORTED
,
1176 _("File transfer not supported by remote contact"));
1178 if (!g_cancellable_is_cancelled (priv
->cancellable
))
1179 g_cancellable_cancel (priv
->cancellable
);
1181 data
->callback (handler
, myerr
, data
->user_data
);
1182 g_clear_error (&myerr
);
1186 /* get back to the caller now */
1187 data
->callback (handler
, NULL
, data
->user_data
);
1191 callbacks_data_free (data
);
1195 ft_handler_complete_request (EmpathyFTHandler
*handler
)
1197 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1199 /* populate the request table with all the known properties */
1200 ft_handler_populate_outgoing_request (handler
);
1203 /* start hashing the file */
1204 g_file_read_async (priv
->gfile
, G_PRIORITY_DEFAULT
,
1205 priv
->cancellable
, ft_handler_read_async_cb
, handler
);
1207 /* push directly the handler to the dispatcher */
1208 ft_handler_push_to_dispatcher (handler
);
1212 ft_handler_gfile_ready_cb (GObject
*source
,
1214 CallbacksData
*cb_data
)
1217 GError
*error
= NULL
;
1219 EmpathyFTHandlerPriv
*priv
= GET_PRIV (cb_data
->handler
);
1221 DEBUG ("Got GFileInfo.");
1223 info
= g_file_query_info_finish (priv
->gfile
, res
, &error
);
1228 if (g_file_info_get_file_type (info
) != G_FILE_TYPE_REGULAR
)
1230 error
= g_error_new_literal (EMPATHY_FT_ERROR_QUARK
,
1231 EMPATHY_FT_ERROR_INVALID_SOURCE_FILE
,
1232 _("The selected file is not a regular file"));
1236 priv
->total_bytes
= g_file_info_get_size (info
);
1237 if (priv
->total_bytes
== 0)
1239 error
= g_error_new_literal (EMPATHY_FT_ERROR_QUARK
,
1240 EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE
,
1241 _("The selected file is empty"));
1245 priv
->content_type
= g_strdup (g_file_info_get_content_type (info
));
1246 priv
->filename
= g_strdup (g_file_info_get_display_name (info
));
1247 g_file_info_get_modification_time (info
, &mtime
);
1248 priv
->mtime
= mtime
.tv_sec
;
1249 priv
->transferred_bytes
= 0;
1250 priv
->description
= NULL
;
1252 g_object_unref (info
);
1257 if (!g_cancellable_is_cancelled (priv
->cancellable
))
1258 g_cancellable_cancel (priv
->cancellable
);
1260 cb_data
->callback (cb_data
->handler
, error
, cb_data
->user_data
);
1261 g_error_free (error
);
1263 callbacks_data_free (cb_data
);
1267 /* see if FT/hashing are allowed */
1268 check_hashing (cb_data
);
1273 channel_get_all_properties_cb (TpProxy
*proxy
,
1274 GHashTable
*properties
,
1275 const GError
*error
,
1277 GObject
*weak_object
)
1279 CallbacksData
*cb_data
= user_data
;
1280 EmpathyFTHandler
*handler
= EMPATHY_FT_HANDLER (weak_object
);
1281 EmpathyFTHandlerPriv
*priv
= GET_PRIV (handler
);
1286 if (!g_cancellable_is_cancelled (priv
->cancellable
))
1287 g_cancellable_cancel (priv
->cancellable
);
1289 cb_data
->callback (handler
, (GError
*) error
, cb_data
->user_data
);
1291 callbacks_data_free (cb_data
);
1295 priv
->content_hash
= g_value_dup_string (
1296 g_hash_table_lookup (properties
, "ContentHash"));
1298 priv
->content_hash_type
= g_value_get_uint (
1299 g_hash_table_lookup (properties
, "ContentHashType"));
1301 contact
= tp_channel_get_target_contact (TP_CHANNEL (proxy
));
1302 priv
->contact
= empathy_contact_dup_from_tp_contact (contact
);
1304 cb_data
->callback (handler
, NULL
, cb_data
->user_data
);
1307 /* public methods */
1310 * empathy_ft_handler_new_outgoing:
1311 * @contact: the #EmpathyContact to send @source to
1312 * @source: the #GFile to send
1313 * @callback: callback to be called when the handler has been created
1314 * @user_data: user data to be passed to @callback
1316 * Triggers the creation of a new #EmpathyFTHandler for an outgoing transfer.
1319 empathy_ft_handler_new_outgoing (EmpathyContact
*contact
,
1322 EmpathyFTHandlerReadyCallback callback
,
1325 EmpathyFTHandler
*handler
;
1326 CallbacksData
*data
;
1327 EmpathyFTHandlerPriv
*priv
;
1329 DEBUG ("New handler outgoing");
1331 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1332 g_return_if_fail (G_IS_FILE (source
));
1334 handler
= g_object_new (EMPATHY_TYPE_FT_HANDLER
,
1337 "user-action-time", action_time
,
1340 priv
= GET_PRIV (handler
);
1342 data
= g_slice_new0 (CallbacksData
);
1343 data
->callback
= callback
;
1344 data
->user_data
= user_data
;
1345 data
->handler
= g_object_ref (handler
);
1347 /* start collecting info about the file */
1348 g_file_query_info_async (priv
->gfile
,
1349 G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
","
1350 G_FILE_ATTRIBUTE_STANDARD_SIZE
","
1351 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
","
1352 G_FILE_ATTRIBUTE_STANDARD_TYPE
","
1353 G_FILE_ATTRIBUTE_TIME_MODIFIED
,
1354 G_FILE_QUERY_INFO_NONE
, G_PRIORITY_DEFAULT
,
1355 NULL
, (GAsyncReadyCallback
) ft_handler_gfile_ready_cb
, data
);
1359 * empathy_ft_handler_new_incoming:
1360 * @channel: the #TpFileTransferChannel proxy to the incoming channel
1361 * @callback: callback to be called when the handler has been created
1362 * @user_data: user data to be passed to @callback
1364 * Triggers the creation of a new #EmpathyFTHandler for an incoming transfer.
1365 * Note that for the handler to be useful, you will have to set a destination
1366 * file with empathy_ft_handler_incoming_set_destination() after the handler
1370 empathy_ft_handler_new_incoming (TpFileTransferChannel
*channel
,
1371 EmpathyFTHandlerReadyCallback callback
,
1374 EmpathyFTHandler
*handler
;
1375 CallbacksData
*data
;
1376 EmpathyFTHandlerPriv
*priv
;
1378 g_return_if_fail (TP_IS_FILE_TRANSFER_CHANNEL (channel
));
1380 handler
= g_object_new (EMPATHY_TYPE_FT_HANDLER
,
1381 "channel", channel
, NULL
);
1383 priv
= GET_PRIV (handler
);
1385 data
= g_slice_new0 (CallbacksData
);
1386 data
->callback
= callback
;
1387 data
->user_data
= user_data
;
1388 data
->handler
= g_object_ref (handler
);
1390 priv
->total_bytes
= tp_file_transfer_channel_get_size (channel
);
1392 priv
->transferred_bytes
= tp_file_transfer_channel_get_transferred_bytes (
1395 priv
->filename
= g_strdup (tp_file_transfer_channel_get_filename (channel
));
1397 priv
->content_type
= g_strdup (tp_file_transfer_channel_get_mime_type (
1400 priv
->description
= g_strdup (tp_file_transfer_channel_get_description (
1403 tp_cli_dbus_properties_call_get_all (channel
,
1404 -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER
,
1405 channel_get_all_properties_cb
, data
, NULL
, G_OBJECT (handler
));
1409 * empathy_ft_handler_start_transfer:
1410 * @handler: an #EmpathyFTHandler
1412 * Starts the transfer machinery. After this call, the transfer and hashing
1413 * signals will be emitted by the handler.
1416 empathy_ft_handler_start_transfer (EmpathyFTHandler
*handler
)
1418 EmpathyFTHandlerPriv
*priv
;
1420 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler
));
1422 priv
= GET_PRIV (handler
);
1424 if (priv
->channel
== NULL
)
1426 ft_handler_complete_request (handler
);
1430 /* TODO: add support for resume. */
1431 tp_file_transfer_channel_accept_file_async (priv
->channel
,
1432 priv
->gfile
, 0, ft_transfer_accept_cb
, handler
);
1434 tp_g_signal_connect_object (priv
->channel
, "notify::state",
1435 G_CALLBACK (ft_transfer_state_cb
), handler
, 0);
1436 tp_g_signal_connect_object (priv
->channel
, "notify::transferred-bytes",
1437 G_CALLBACK (ft_transfer_transferred_bytes_cb
), handler
, 0);
1442 * empathy_ft_handler_cancel_transfer:
1443 * @handler: an #EmpathyFTHandler
1445 * Cancels an ongoing handler operation. Note that this doesn't destroy
1446 * the object, which will keep all the properties, altough it won't be able
1447 * to do any more I/O.
1450 empathy_ft_handler_cancel_transfer (EmpathyFTHandler
*handler
)
1452 EmpathyFTHandlerPriv
*priv
;
1454 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler
));
1456 priv
= GET_PRIV (handler
);
1458 /* if we don't have a channel, we are hashing, so
1459 * we can just cancel the GCancellable to stop it.
1461 if (priv
->channel
== NULL
)
1462 g_cancellable_cancel (priv
->cancellable
);
1464 tp_channel_close_async (TP_CHANNEL (priv
->channel
), NULL
, NULL
);
1468 * empathy_ft_handler_incoming_set_destination:
1469 * @handler: an #EmpathyFTHandler
1470 * @destination: the #GFile where the transfer should be saved
1472 * Sets the destination of the incoming handler to be @destination.
1473 * Note that calling this method is mandatory before starting the transfer
1474 * for incoming handlers.
1477 empathy_ft_handler_incoming_set_destination (EmpathyFTHandler
*handler
,
1480 EmpathyFTHandlerPriv
*priv
;
1482 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler
));
1483 g_return_if_fail (G_IS_FILE (destination
));
1485 priv
= GET_PRIV (handler
);
1487 g_object_set (handler
, "gfile", destination
, NULL
);
1489 /* check if hash is supported. if it isn't, set use_hash to FALSE
1490 * anyway, so that clients won't be expecting us to checksum.
1492 if (TPAW_STR_EMPTY (priv
->content_hash
) ||
1493 priv
->content_hash_type
== TP_FILE_HASH_TYPE_NONE
)
1494 priv
->use_hash
= FALSE
;
1496 priv
->use_hash
= TRUE
;
1500 * empathy_ft_handler_get_filename:
1501 * @handler: an #EmpathyFTHandler
1503 * Returns the name of the file being transferred.
1505 * Return value: the name of the file being transferred
1508 empathy_ft_handler_get_filename (EmpathyFTHandler
*handler
)
1510 EmpathyFTHandlerPriv
*priv
;
1512 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), NULL
);
1514 priv
= GET_PRIV (handler
);
1516 return priv
->filename
;
1520 * empathy_ft_handler_get_content_type:
1521 * @handler: an #EmpathyFTHandler
1523 * Returns the content type of the file being transferred.
1525 * Return value: the content type of the file being transferred
1528 empathy_ft_handler_get_content_type (EmpathyFTHandler
*handler
)
1530 EmpathyFTHandlerPriv
*priv
;
1532 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), NULL
);
1534 priv
= GET_PRIV (handler
);
1536 return priv
->content_type
;
1540 * empathy_ft_handler_get_contact:
1541 * @handler: an #EmpathyFTHandler
1543 * Returns the remote #EmpathyContact at the other side of the transfer.
1545 * Return value: the remote #EmpathyContact for @handler
1548 empathy_ft_handler_get_contact (EmpathyFTHandler
*handler
)
1550 EmpathyFTHandlerPriv
*priv
;
1552 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), NULL
);
1554 priv
= GET_PRIV (handler
);
1556 return priv
->contact
;
1560 * empathy_ft_handler_get_gfile:
1561 * @handler: an #EmpathyFTHandler
1563 * Returns the #GFile where the transfer is being read/saved.
1565 * Return value: the #GFile where the transfer is being read/saved
1568 empathy_ft_handler_get_gfile (EmpathyFTHandler
*handler
)
1570 EmpathyFTHandlerPriv
*priv
;
1572 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), NULL
);
1574 priv
= GET_PRIV (handler
);
1580 * empathy_ft_handler_get_use_hash:
1581 * @handler: an #EmpathyFTHandler
1583 * Returns whether @handler has checksumming enabled. This can depend on
1584 * the CM and the remote contact capabilities.
1586 * Return value: %TRUE if the handler has checksumming enabled,
1590 empathy_ft_handler_get_use_hash (EmpathyFTHandler
*handler
)
1592 EmpathyFTHandlerPriv
*priv
;
1594 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), FALSE
);
1596 priv
= GET_PRIV (handler
);
1598 return priv
->use_hash
;
1602 * empathy_ft_handler_is_incoming:
1603 * @handler: an #EmpathyFTHandler
1605 * Returns whether @handler is incoming or outgoing.
1607 * Return value: %TRUE if the handler is incoming, %FALSE otherwise.
1610 empathy_ft_handler_is_incoming (EmpathyFTHandler
*handler
)
1612 EmpathyFTHandlerPriv
*priv
;
1614 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), FALSE
);
1616 priv
= GET_PRIV (handler
);
1618 if (priv
->channel
== NULL
)
1621 return !tp_channel_get_requested ((TpChannel
*) priv
->channel
);
1625 * empathy_ft_handler_get_transferred_bytes:
1626 * @handler: an #EmpathyFTHandler
1628 * Returns the number of bytes already transferred by the handler.
1630 * Return value: the number of bytes already transferred by the handler.
1633 empathy_ft_handler_get_transferred_bytes (EmpathyFTHandler
*handler
)
1635 EmpathyFTHandlerPriv
*priv
;
1637 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), 0);
1639 priv
= GET_PRIV (handler
);
1641 return priv
->transferred_bytes
;
1645 * empathy_ft_handler_get_total_bytes:
1646 * @handler: an #EmpathyFTHandler
1648 * Returns the total size of the file being transferred by the handler.
1650 * Return value: a number of bytes indicating the total size of the file being
1651 * transferred by the handler.
1654 empathy_ft_handler_get_total_bytes (EmpathyFTHandler
*handler
)
1656 EmpathyFTHandlerPriv
*priv
;
1658 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), 0);
1660 priv
= GET_PRIV (handler
);
1662 return priv
->total_bytes
;
1666 * empathy_ft_handler_is_completed:
1667 * @handler: an #EmpathyFTHandler
1669 * Returns whether the transfer for @handler has been completed succesfully.
1671 * Return value: %TRUE if the handler has been transferred correctly, %FALSE
1675 empathy_ft_handler_is_completed (EmpathyFTHandler
*handler
)
1677 EmpathyFTHandlerPriv
*priv
;
1679 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), FALSE
);
1681 priv
= GET_PRIV (handler
);
1683 return priv
->is_completed
;
1687 * empathy_ft_handler_is_cancelled:
1688 * @handler: an #EmpathyFTHandler
1690 * Returns whether the transfer for @handler has been cancelled or has stopped
1693 * Return value: %TRUE if the transfer for @handler has been cancelled
1694 * or has stopped due to an error, %FALSE otherwise.
1697 empathy_ft_handler_is_cancelled (EmpathyFTHandler
*handler
)
1699 EmpathyFTHandlerPriv
*priv
;
1701 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler
), FALSE
);
1703 priv
= GET_PRIV (handler
);
1705 return g_cancellable_is_cancelled (priv
->cancellable
);