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>
31 #include "empathy-utils.h"
33 #define DEBUG_FLAG EMPATHY_DEBUG_FT
34 #include "empathy-debug.h"
37 * SECTION:empathy-ft-handler
38 * @title: EmpathyFTHandler
39 * @short_description: an object representing a File Transfer
40 * @include: libempathy/empathy-ft-handler
42 * #EmpathyFTHandler is the object which represents a File Transfer with all
44 * The creation of an #EmpathyFTHandler is done with
45 * empathy_ft_handler_new_outgoing() or empathy_ft_handler_new_incoming(),
46 * even though clients should not need to call them directly, as
47 * #EmpathyFTFactory does it for them. Remember that for the file transfer
48 * to work with an incoming handler,
49 * empathy_ft_handler_incoming_set_destination() should be called after
50 * empathy_ft_handler_new_incoming(). #EmpathyFTFactory does this
52 * It's important to note that, as the creation of the handlers is async, once
53 * an handler is created, it already has all the interesting properties set,
54 * like filename, total bytes, content type and so on, making it useful
55 * to be displayed in an UI.
56 * The transfer API works like a state machine; it has three signals,
57 * ::transfer-started, ::transfer-progress, ::transfer-done, which will be
58 * emitted in the relevant phases.
59 * In addition, if the handler is created with checksumming enabled,
60 * other three signals (::hashing-started, ::hashing-progress, ::hashing-done)
61 * will be emitted before or after the transfer, depending on the direction
62 * (respectively outgoing and incoming) of the handler.
63 * At any time between the call to empathy_ft_handler_start_transfer() and
64 * the last signal, a ::transfer-error can be emitted, indicating that an
65 * error has happened in the operation. The message of the error is localized
69 G_DEFINE_TYPE (EmpathyFTHandler, empathy_ft_handler, G_TYPE_OBJECT)
71 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTHandler)
73 #define BUFFER_SIZE 4096
82 PROP_MODIFICATION_TIME,
84 PROP_TRANSFERRED_BYTES,
100 GInputStream *stream;
101 GError *error /* comment to make the style checker happy */;
106 EmpathyFTHandler *handler;
110 EmpathyFTHandlerReadyCallback callback;
112 EmpathyFTHandler *handler;
117 gboolean dispose_run;
120 TpFileTransferChannel *channel;
121 GCancellable *cancellable;
124 /* request for the new transfer */
127 /* transfer properties */
128 EmpathyContact *contact;
133 guint64 transferred_bytes;
136 TpFileHashType content_hash_type;
138 gint64 user_action_time;
142 guint remaining_time;
143 gint64 last_update_time;
145 gboolean is_completed;
146 } EmpathyFTHandlerPriv;
148 static guint signals[LAST_SIGNAL] = { 0 };
150 static gboolean do_hash_job_incoming (GIOSchedulerJob *job,
151 GCancellable *cancellable, gpointer user_data);
153 /* GObject implementations */
155 do_get_property (GObject *object,
160 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
165 g_value_set_object (value, priv->contact);
167 case PROP_CONTENT_TYPE:
168 g_value_set_string (value, priv->content_type);
170 case PROP_DESCRIPTION:
171 g_value_set_string (value, priv->description);
174 g_value_set_string (value, priv->filename);
176 case PROP_MODIFICATION_TIME:
177 g_value_set_uint64 (value, priv->mtime);
179 case PROP_TOTAL_BYTES:
180 g_value_set_uint64 (value, priv->total_bytes);
182 case PROP_TRANSFERRED_BYTES:
183 g_value_set_uint64 (value, priv->transferred_bytes);
186 g_value_set_object (value, priv->gfile);
189 g_value_set_object (value, priv->channel);
191 case PROP_USER_ACTION_TIME:
192 g_value_set_int64 (value, priv->user_action_time);
195 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
200 do_set_property (GObject *object,
205 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
210 priv->contact = g_value_dup_object (value);
212 case PROP_CONTENT_TYPE:
213 priv->content_type = g_value_dup_string (value);
215 case PROP_DESCRIPTION:
216 priv->description = g_value_dup_string (value);
219 priv->filename = g_value_dup_string (value);
221 case PROP_MODIFICATION_TIME:
222 priv->mtime = g_value_get_uint64 (value);
224 case PROP_TOTAL_BYTES:
225 priv->total_bytes = g_value_get_uint64 (value);
227 case PROP_TRANSFERRED_BYTES:
228 priv->transferred_bytes = g_value_get_uint64 (value);
231 priv->gfile = g_value_dup_object (value);
234 priv->channel = g_value_dup_object (value);
236 case PROP_USER_ACTION_TIME:
237 priv->user_action_time = g_value_get_int64 (value);
240 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
245 do_dispose (GObject *object)
247 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
249 if (priv->dispose_run)
252 priv->dispose_run = TRUE;
254 if (priv->contact != NULL) {
255 g_object_unref (priv->contact);
256 priv->contact = NULL;
259 if (priv->gfile != NULL) {
260 g_object_unref (priv->gfile);
264 if (priv->channel != NULL) {
265 tp_channel_close_async (TP_CHANNEL (priv->channel), NULL, NULL);
266 g_object_unref (priv->channel);
267 priv->channel = NULL;
270 if (priv->cancellable != NULL) {
271 g_object_unref (priv->cancellable);
272 priv->cancellable = NULL;
275 if (priv->request != NULL)
277 g_hash_table_unref (priv->request);
278 priv->request = NULL;
281 G_OBJECT_CLASS (empathy_ft_handler_parent_class)->dispose (object);
285 do_finalize (GObject *object)
287 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
289 DEBUG ("%p", object);
291 g_free (priv->content_type);
292 priv->content_type = NULL;
294 g_free (priv->filename);
295 priv->filename = NULL;
297 g_free (priv->description);
298 priv->description = NULL;
300 g_free (priv->content_hash);
301 priv->content_hash = NULL;
303 G_OBJECT_CLASS (empathy_ft_handler_parent_class)->finalize (object);
307 empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
309 GObjectClass *object_class = G_OBJECT_CLASS (klass);
310 GParamSpec *param_spec;
312 g_type_class_add_private (klass, sizeof (EmpathyFTHandlerPriv));
314 object_class->get_property = do_get_property;
315 object_class->set_property = do_set_property;
316 object_class->dispose = do_dispose;
317 object_class->finalize = do_finalize;
322 * EmpathyFTHandler:contact:
324 * The remote #EmpathyContact for the transfer
326 param_spec = g_param_spec_object ("contact",
327 "contact", "The remote contact",
328 EMPATHY_TYPE_CONTACT,
329 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
330 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
333 * EmpathyFTHandler:content-type:
335 * The content type of the file being transferred
337 param_spec = g_param_spec_string ("content-type",
338 "content-type", "The content type of the file", NULL,
339 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
340 g_object_class_install_property (object_class,
341 PROP_CONTENT_TYPE, param_spec);
344 * EmpathyFTHandler:description:
346 * The description of the file being transferred
348 param_spec = g_param_spec_string ("description",
349 "description", "The description of the file", NULL,
350 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
351 g_object_class_install_property (object_class,
352 PROP_DESCRIPTION, param_spec);
355 * EmpathyFTHandler:filename:
357 * The name of the file being transferred
359 param_spec = g_param_spec_string ("filename",
360 "filename", "The name of the file", NULL,
361 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
362 g_object_class_install_property (object_class,
363 PROP_FILENAME, param_spec);
366 * EmpathyFTHandler:modification-time:
368 * The modification time of the file being transferred
370 param_spec = g_param_spec_uint64 ("modification-time",
371 "modification-time", "The mtime of the file", 0,
372 G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
373 g_object_class_install_property (object_class,
374 PROP_MODIFICATION_TIME, param_spec);
377 * EmpathyFTHandler:total-bytes:
379 * The size (in bytes) of the file being transferred
381 param_spec = g_param_spec_uint64 ("total-bytes",
382 "total-bytes", "The size of the file", 0,
383 G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
384 g_object_class_install_property (object_class,
385 PROP_TOTAL_BYTES, param_spec);
388 * EmpathyFTHandler:transferred-bytes:
390 * The number of the bytes already transferred
392 param_spec = g_param_spec_uint64 ("transferred-bytes",
393 "transferred-bytes", "The number of bytes already transferred", 0,
394 G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
395 g_object_class_install_property (object_class,
396 PROP_TRANSFERRED_BYTES, param_spec);
399 * EmpathyFTHandler:gfile:
401 * The #GFile object where the transfer actually happens
403 param_spec = g_param_spec_object ("gfile",
404 "gfile", "The GFile we're handling",
406 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
407 g_object_class_install_property (object_class, PROP_G_FILE, param_spec);
410 * EmpathyFTHandler:channel:
412 * The underlying #TpFileTransferChannel managing the transfer
414 param_spec = g_param_spec_object ("channel",
415 "channel", "The file transfer channel",
416 TP_TYPE_FILE_TRANSFER_CHANNEL,
417 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
418 g_object_class_install_property (object_class, PROP_CHANNEL, param_spec);
420 param_spec = g_param_spec_int64 ("user-action-time", "user action time",
423 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
424 g_object_class_install_property (object_class, PROP_USER_ACTION_TIME,
430 * EmpathyFTHandler::transfer-started
431 * @handler: the object which has received the signal
432 * @channel: the #TpFileTransferChannel for which the transfer has started
434 * This signal is emitted when the actual transfer starts.
436 signals[TRANSFER_STARTED] =
437 g_signal_new ("transfer-started", G_TYPE_FROM_CLASS (klass),
438 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
439 g_cclosure_marshal_generic,
441 1, TP_TYPE_FILE_TRANSFER_CHANNEL);
444 * EmpathyFTHandler::transfer-done
445 * @handler: the object which has received the signal
446 * @channel: the #TpFileTransferChannel for which the transfer has started
448 * This signal will be emitted when the actual transfer is completed
451 signals[TRANSFER_DONE] =
452 g_signal_new ("transfer-done", G_TYPE_FROM_CLASS (klass),
453 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
454 g_cclosure_marshal_generic,
456 1, TP_TYPE_FILE_TRANSFER_CHANNEL);
459 * EmpathyFTHandler::transfer-error
460 * @handler: the object which has received the signal
463 * This signal can be emitted anytime between the call to
464 * empathy_ft_handler_start_transfer() and the last expected signal
465 * (::transfer-done or ::hashing-done), and it's guaranteed to be the last
466 * signal coming from the handler, meaning that no other operation will
467 * take place after this signal.
469 signals[TRANSFER_ERROR] =
470 g_signal_new ("transfer-error", G_TYPE_FROM_CLASS (klass),
471 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
472 g_cclosure_marshal_generic,
477 * EmpathyFTHandler::transfer-progress
478 * @handler: the object which has received the signal
479 * @current_bytes: the bytes currently transferred
480 * @total_bytes: the total bytes of the handler
481 * @remaining_time: the number of seconds remaining for the transfer
483 * @speed: the current speed of the transfer (in KB/s)
485 * This signal is emitted to notify clients of the progress of the
488 signals[TRANSFER_PROGRESS] =
489 g_signal_new ("transfer-progress", G_TYPE_FROM_CLASS (klass),
490 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
491 g_cclosure_marshal_generic,
493 4, G_TYPE_UINT64, G_TYPE_UINT64, G_TYPE_UINT, G_TYPE_DOUBLE);
496 * EmpathyFTHandler::hashing-started
497 * @handler: the object which has received the signal
499 * This signal is emitted when the hashing operation of the handler
500 * is started. Note that this might happen or not, depending on the CM
501 * and remote contact capabilities. Clients shoud use
502 * empathy_ft_handler_get_use_hash() before calling
503 * empathy_ft_handler_start_transfer() to know whether they should connect
506 signals[HASHING_STARTED] =
507 g_signal_new ("hashing-started", G_TYPE_FROM_CLASS (klass),
508 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
509 g_cclosure_marshal_generic,
513 * EmpathyFTHandler::hashing-progress
514 * @handler: the object which has received the signal
515 * @current_bytes: the bytes currently hashed
516 * @total_bytes: the total bytes of the handler
518 * This signal is emitted to notify clients of the progress of the
521 signals[HASHING_PROGRESS] =
522 g_signal_new ("hashing-progress", G_TYPE_FROM_CLASS (klass),
523 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
524 g_cclosure_marshal_generic,
526 2, G_TYPE_UINT64, G_TYPE_UINT64);
529 * EmpathyFTHandler::hashing-done
530 * @handler: the object which has received the signal
532 * This signal is emitted when the hashing operation of the handler
535 signals[HASHING_DONE] =
536 g_signal_new ("hashing-done", G_TYPE_FROM_CLASS (klass),
537 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
538 g_cclosure_marshal_generic,
543 empathy_ft_handler_init (EmpathyFTHandler *self)
545 EmpathyFTHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
546 EMPATHY_TYPE_FT_HANDLER, EmpathyFTHandlerPriv);
549 priv->cancellable = g_cancellable_new ();
552 /* private functions */
555 hash_data_free (HashingData *data)
557 g_free (data->buffer);
559 if (data->stream != NULL)
560 g_object_unref (data->stream);
562 if (data->checksum != NULL)
563 g_checksum_free (data->checksum);
565 if (data->error != NULL)
566 g_error_free (data->error);
568 if (data->handler != NULL)
569 g_object_unref (data->handler);
571 g_slice_free (HashingData, data);
575 tp_file_hash_to_g_checksum (TpFileHashType type)
577 GChecksumType retval;
581 case TP_FILE_HASH_TYPE_MD5:
582 retval = G_CHECKSUM_MD5;
584 case TP_FILE_HASH_TYPE_SHA1:
585 retval = G_CHECKSUM_SHA1;
587 case TP_FILE_HASH_TYPE_SHA256:
588 retval = G_CHECKSUM_SHA256;
590 case TP_FILE_HASH_TYPE_NONE:
592 g_assert_not_reached ();
600 check_hash_incoming (EmpathyFTHandler *handler)
602 HashingData *hash_data;
603 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
605 if (!TPAW_STR_EMPTY (priv->content_hash))
607 hash_data = g_slice_new0 (HashingData);
608 hash_data->total_bytes = priv->total_bytes;
609 hash_data->handler = g_object_ref (handler);
610 hash_data->checksum = g_checksum_new
611 (tp_file_hash_to_g_checksum (priv->content_hash_type));
613 g_signal_emit (handler, signals[HASHING_STARTED], 0);
615 g_io_scheduler_push_job (do_hash_job_incoming, hash_data, NULL,
616 G_PRIORITY_DEFAULT, priv->cancellable);
621 emit_error_signal (EmpathyFTHandler *handler,
624 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
626 DEBUG ("Error in transfer: %s\n", error->message);
628 if (!g_cancellable_is_cancelled (priv->cancellable))
629 g_cancellable_cancel (priv->cancellable);
631 g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error);
635 update_remaining_time_and_speed (EmpathyFTHandler *handler,
636 guint64 transferred_bytes)
638 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
639 gint64 elapsed_time, current_time;
640 guint64 transferred, last_transferred_bytes;
644 last_transferred_bytes = priv->transferred_bytes;
645 priv->transferred_bytes = transferred_bytes;
647 current_time = tpaw_time_get_current ();
648 elapsed_time = current_time - priv->last_update_time;
650 if (elapsed_time >= 1)
652 transferred = transferred_bytes - last_transferred_bytes;
653 speed = (gdouble) transferred / (gdouble) elapsed_time;
654 remaining_time = (priv->total_bytes - priv->transferred_bytes) / speed;
656 priv->remaining_time = remaining_time;
657 priv->last_update_time = current_time;
662 ft_transfer_transferred_bytes_cb (TpFileTransferChannel *channel,
664 EmpathyFTHandler *handler)
666 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
669 if (empathy_ft_handler_is_cancelled (handler))
672 bytes = tp_file_transfer_channel_get_transferred_bytes (channel);
674 if (priv->transferred_bytes == 0)
676 priv->last_update_time = tpaw_time_get_current ();
677 g_signal_emit (handler, signals[TRANSFER_STARTED], 0, channel);
680 if (priv->transferred_bytes != bytes)
682 update_remaining_time_and_speed (handler, bytes);
684 g_signal_emit (handler, signals[TRANSFER_PROGRESS], 0,
685 bytes, priv->total_bytes, priv->remaining_time,
691 ft_transfer_provide_cb (GObject *source,
692 GAsyncResult *result,
695 TpFileTransferChannel *channel = TP_FILE_TRANSFER_CHANNEL (source);
696 EmpathyFTHandler *handler = user_data;
697 GError *error = NULL;
699 if (!tp_file_transfer_channel_provide_file_finish (channel, result, &error))
701 emit_error_signal (handler, error);
702 g_clear_error (&error);
707 ft_transfer_accept_cb (GObject *source,
708 GAsyncResult *result,
711 TpFileTransferChannel *channel = TP_FILE_TRANSFER_CHANNEL (source);
712 EmpathyFTHandler *handler = user_data;
713 GError *error = NULL;
715 if (!tp_file_transfer_channel_accept_file_finish (channel, result, &error))
717 emit_error_signal (handler, error);
718 g_clear_error (&error);
723 error_from_state_change_reason (TpFileTransferStateChangeReason reason)
726 GError *retval = NULL;
732 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE:
733 string = _("No reason was specified");
735 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED:
736 string = _("The change in state was requested");
738 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED:
739 string = _("You canceled the file transfer");
741 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED:
742 string = _("The other participant canceled the file transfer");
744 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR:
745 string = _("Error while trying to transfer the file");
747 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR:
748 string = _("The other participant is unable to transfer the file");
751 string = _("Unknown reason");
755 retval = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
756 EMPATHY_FT_ERROR_TP_ERROR, string);
762 ft_transfer_state_cb (TpFileTransferChannel *channel,
764 EmpathyFTHandler *handler)
766 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
767 TpFileTransferStateChangeReason reason;
768 TpFileTransferState state = tp_file_transfer_channel_get_state (
771 if (state == TP_FILE_TRANSFER_STATE_COMPLETED)
773 priv->is_completed = TRUE;
774 g_signal_emit (handler, signals[TRANSFER_DONE], 0, channel);
776 tp_channel_close_async (TP_CHANNEL (channel), NULL, NULL);
778 if (empathy_ft_handler_is_incoming (handler) && priv->use_hash)
780 check_hash_incoming (handler);
783 else if (state == TP_FILE_TRANSFER_STATE_CANCELLED)
785 GError *error = error_from_state_change_reason (reason);
786 emit_error_signal (handler, error);
787 g_clear_error (&error);
792 ft_handler_create_channel_cb (GObject *source,
793 GAsyncResult *result,
796 EmpathyFTHandler *handler = user_data;
797 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
798 GError *error = NULL;
801 DEBUG ("Dispatcher create channel CB");
803 channel = tp_account_channel_request_create_and_handle_channel_finish (
804 TP_ACCOUNT_CHANNEL_REQUEST (source), result, NULL, &error);
807 DEBUG ("Failed to request FT channel: %s", error->message);
809 g_cancellable_set_error_if_cancelled (priv->cancellable, &error);
813 emit_error_signal (handler, error);
815 g_clear_object (&channel);
816 g_error_free (error);
820 priv->channel = TP_FILE_TRANSFER_CHANNEL (channel);
822 tp_g_signal_connect_object (priv->channel, "notify::state",
823 G_CALLBACK (ft_transfer_state_cb), handler, 0);
824 tp_g_signal_connect_object (priv->channel, "notify::transferred-bytes",
825 G_CALLBACK (ft_transfer_transferred_bytes_cb), handler, 0);
827 tp_file_transfer_channel_provide_file_async (priv->channel, priv->gfile,
828 ft_transfer_provide_cb, handler);
832 ft_handler_push_to_dispatcher (EmpathyFTHandler *handler)
835 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
836 TpAccountChannelRequest *req;
838 DEBUG ("Pushing request to the dispatcher");
840 account = empathy_contact_get_account (priv->contact);
842 req = tp_account_channel_request_new (account, priv->request,
843 priv->user_action_time);
845 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
846 ft_handler_create_channel_cb, handler);
848 g_object_unref (req);
852 ft_handler_populate_outgoing_request (EmpathyFTHandler *handler)
854 guint contact_handle;
855 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
858 contact_handle = empathy_contact_get_handle (priv->contact);
859 uri = g_file_get_uri (priv->gfile);
861 priv->request = tp_asv_new (
862 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
863 TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
864 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
865 TP_HANDLE_TYPE_CONTACT,
866 TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT,
868 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE, G_TYPE_STRING,
870 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME, G_TYPE_STRING,
872 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE, G_TYPE_UINT64,
874 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_DATE, G_TYPE_UINT64,
876 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_URI, G_TYPE_STRING, uri,
883 hash_job_done (gpointer user_data)
885 HashingData *hash_data = user_data;
886 EmpathyFTHandler *handler = hash_data->handler;
887 EmpathyFTHandlerPriv *priv;
888 GError *error = NULL;
890 DEBUG ("Closing stream after hashing.");
892 priv = GET_PRIV (handler);
894 if (hash_data->error != NULL)
896 error = hash_data->error;
897 hash_data->error = NULL;
901 DEBUG ("Got file hash %s", g_checksum_get_string (hash_data->checksum));
903 if (empathy_ft_handler_is_incoming (handler))
905 if (g_strcmp0 (g_checksum_get_string (hash_data->checksum),
908 DEBUG ("Hash mismatch when checking incoming handler: "
909 "received %s, calculated %s", priv->content_hash,
910 g_checksum_get_string (hash_data->checksum));
912 error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
913 EMPATHY_FT_ERROR_HASH_MISMATCH,
914 _("File transfer completed, but the file was corrupted"));
919 DEBUG ("Hash verification matched, received %s, calculated %s",
921 g_checksum_get_string (hash_data->checksum));
926 /* set the checksum in the request...
927 * org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHash
929 tp_asv_set_string (priv->request,
930 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH,
931 g_checksum_get_string (hash_data->checksum));
938 emit_error_signal (handler, error);
939 g_clear_error (&error);
943 g_signal_emit (handler, signals[HASHING_DONE], 0);
945 if (!empathy_ft_handler_is_incoming (handler))
946 /* the request is complete now, push it to the dispatcher */
947 ft_handler_push_to_dispatcher (handler);
950 hash_data_free (hash_data);
956 emit_hashing_progress (gpointer user_data)
958 HashingData *hash_data = user_data;
960 g_signal_emit (hash_data->handler, signals[HASHING_PROGRESS], 0,
961 (guint64) hash_data->total_read, (guint64) hash_data->total_bytes);
967 do_hash_job (GIOSchedulerJob *job,
968 GCancellable *cancellable,
971 HashingData *hash_data = user_data;
973 GError *error = NULL;
976 if (hash_data->buffer == NULL)
977 hash_data->buffer = g_malloc0 (BUFFER_SIZE);
979 bytes_read = g_input_stream_read (hash_data->stream, hash_data->buffer,
980 BUFFER_SIZE, cancellable, &error);
984 hash_data->total_read += bytes_read;
986 /* we now have the chunk */
989 g_checksum_update (hash_data->checksum, hash_data->buffer, bytes_read);
990 g_io_scheduler_job_send_to_mainloop_async (job, emit_hashing_progress,
993 g_free (hash_data->buffer);
994 hash_data->buffer = NULL;
1000 g_input_stream_close (hash_data->stream, cancellable, &error);
1005 hash_data->error = error;
1007 g_io_scheduler_job_send_to_mainloop_async (job, hash_job_done,
1014 do_hash_job_incoming (GIOSchedulerJob *job,
1015 GCancellable *cancellable,
1018 HashingData *hash_data = user_data;
1019 EmpathyFTHandler *handler = hash_data->handler;
1020 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1021 GError *error = NULL;
1023 DEBUG ("checking integrity for incoming handler");
1025 /* need to get the stream first */
1027 G_INPUT_STREAM (g_file_read (priv->gfile, cancellable, &error));
1031 hash_data->error = error;
1032 g_io_scheduler_job_send_to_mainloop_async (job, hash_job_done,
1037 return do_hash_job (job, cancellable, user_data);
1041 ft_handler_read_async_cb (GObject *source,
1045 GFileInputStream *stream;
1046 GError *error = NULL;
1047 HashingData *hash_data;
1048 EmpathyFTHandler *handler = user_data;
1049 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1051 DEBUG ("GFile read async CB.");
1053 stream = g_file_read_finish (priv->gfile, res, &error);
1056 emit_error_signal (handler, error);
1057 g_clear_error (&error);
1062 hash_data = g_slice_new0 (HashingData);
1063 hash_data->stream = G_INPUT_STREAM (stream);
1064 hash_data->total_bytes = priv->total_bytes;
1065 hash_data->handler = g_object_ref (handler);
1066 /* FIXME: MD5 is the only ContentHashType supported right now */
1067 hash_data->checksum = g_checksum_new (G_CHECKSUM_MD5);
1069 tp_asv_set_uint32 (priv->request,
1070 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE,
1071 TP_FILE_HASH_TYPE_MD5);
1073 g_signal_emit (handler, signals[HASHING_STARTED], 0);
1075 g_io_scheduler_push_job (do_hash_job, hash_data, NULL,
1076 G_PRIORITY_DEFAULT, priv->cancellable);
1080 callbacks_data_free (gpointer user_data)
1082 CallbacksData *data = user_data;
1084 if (data->handler != NULL)
1085 g_object_unref (data->handler);
1087 g_slice_free (CallbacksData, data);
1091 set_content_hash_type_from_classes (EmpathyFTHandler *handler,
1094 GArray *possible_values;
1097 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1098 gboolean support_ft = FALSE;
1101 possible_values = g_array_new (TRUE, TRUE, sizeof (guint));
1103 for (i = 0; i < classes->len; i++)
1107 const gchar *chan_type;
1109 tp_value_array_unpack (g_ptr_array_index (classes, i), 2,
1112 chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
1114 if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
1117 if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) !=
1118 TP_HANDLE_TYPE_CONTACT)
1123 value = tp_asv_get_uint32
1124 (fixed, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE,
1128 g_array_append_val (possible_values, value);
1133 g_array_unref (possible_values);
1137 if (possible_values->len == 0)
1139 /* there are no channel classes with hash support, disable it. */
1140 priv->use_hash = FALSE;
1141 priv->content_hash_type = TP_FILE_HASH_TYPE_NONE;
1146 priv->use_hash = TRUE;
1148 if (possible_values->len == 1)
1150 priv->content_hash_type = g_array_index (possible_values, guint, 0);
1154 /* order the array and pick the first non zero, so that MD5
1155 * is the preferred value.
1157 g_array_sort (possible_values, empathy_uint_compare);
1159 if (g_array_index (possible_values, guint, 0) == 0)
1160 priv->content_hash_type = g_array_index (possible_values, guint, 1);
1162 priv->content_hash_type = g_array_index (possible_values, guint, 0);
1166 g_array_unref (possible_values);
1168 DEBUG ("Hash enabled %s; setting content hash type as %u",
1169 priv->use_hash ? "True" : "False", priv->content_hash_type);
1175 check_hashing (CallbacksData *data)
1177 EmpathyFTHandler *handler = data->handler;
1178 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1179 GError *myerr = NULL;
1180 TpCapabilities *caps;
1184 conn = empathy_contact_get_connection (priv->contact);
1186 caps = tp_connection_get_capabilities (conn);
1189 data->callback (handler, NULL, data->user_data);
1193 classes = tp_capabilities_get_channel_classes (caps);
1195 /* set whether we support hash and the type of it */
1196 if (!set_content_hash_type_from_classes (handler, classes))
1198 g_set_error_literal (&myerr, EMPATHY_FT_ERROR_QUARK,
1199 EMPATHY_FT_ERROR_NOT_SUPPORTED,
1200 _("File transfer not supported by remote contact"));
1202 if (!g_cancellable_is_cancelled (priv->cancellable))
1203 g_cancellable_cancel (priv->cancellable);
1205 data->callback (handler, myerr, data->user_data);
1206 g_clear_error (&myerr);
1210 /* get back to the caller now */
1211 data->callback (handler, NULL, data->user_data);
1215 callbacks_data_free (data);
1219 ft_handler_complete_request (EmpathyFTHandler *handler)
1221 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1223 /* populate the request table with all the known properties */
1224 ft_handler_populate_outgoing_request (handler);
1227 /* start hashing the file */
1228 g_file_read_async (priv->gfile, G_PRIORITY_DEFAULT,
1229 priv->cancellable, ft_handler_read_async_cb, handler);
1231 /* push directly the handler to the dispatcher */
1232 ft_handler_push_to_dispatcher (handler);
1236 ft_handler_gfile_ready_cb (GObject *source,
1238 CallbacksData *cb_data)
1241 GError *error = NULL;
1243 EmpathyFTHandlerPriv *priv = GET_PRIV (cb_data->handler);
1245 DEBUG ("Got GFileInfo.");
1247 info = g_file_query_info_finish (priv->gfile, res, &error);
1252 if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR)
1254 error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
1255 EMPATHY_FT_ERROR_INVALID_SOURCE_FILE,
1256 _("The selected file is not a regular file"));
1260 priv->total_bytes = g_file_info_get_size (info);
1261 if (priv->total_bytes == 0)
1263 error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
1264 EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE,
1265 _("The selected file is empty"));
1269 priv->content_type = g_strdup (g_file_info_get_content_type (info));
1270 priv->filename = g_strdup (g_file_info_get_display_name (info));
1271 g_file_info_get_modification_time (info, &mtime);
1272 priv->mtime = mtime.tv_sec;
1273 priv->transferred_bytes = 0;
1274 priv->description = NULL;
1276 g_object_unref (info);
1281 if (!g_cancellable_is_cancelled (priv->cancellable))
1282 g_cancellable_cancel (priv->cancellable);
1284 cb_data->callback (cb_data->handler, error, cb_data->user_data);
1285 g_error_free (error);
1287 callbacks_data_free (cb_data);
1291 /* see if FT/hashing are allowed */
1292 check_hashing (cb_data);
1297 channel_get_all_properties_cb (TpProxy *proxy,
1298 GHashTable *properties,
1299 const GError *error,
1301 GObject *weak_object)
1303 CallbacksData *cb_data = user_data;
1304 EmpathyFTHandler *handler = EMPATHY_FT_HANDLER (weak_object);
1305 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1310 if (!g_cancellable_is_cancelled (priv->cancellable))
1311 g_cancellable_cancel (priv->cancellable);
1313 cb_data->callback (handler, (GError *) error, cb_data->user_data);
1315 callbacks_data_free (cb_data);
1319 priv->content_hash = g_value_dup_string (
1320 g_hash_table_lookup (properties, "ContentHash"));
1322 priv->content_hash_type = g_value_get_uint (
1323 g_hash_table_lookup (properties, "ContentHashType"));
1325 contact = tp_channel_get_target_contact (TP_CHANNEL (proxy));
1326 priv->contact = empathy_contact_dup_from_tp_contact (contact);
1328 cb_data->callback (handler, NULL, cb_data->user_data);
1331 /* public methods */
1334 * empathy_ft_handler_new_outgoing:
1335 * @contact: the #EmpathyContact to send @source to
1336 * @source: the #GFile to send
1337 * @callback: callback to be called when the handler has been created
1338 * @user_data: user data to be passed to @callback
1340 * Triggers the creation of a new #EmpathyFTHandler for an outgoing transfer.
1343 empathy_ft_handler_new_outgoing (EmpathyContact *contact,
1346 EmpathyFTHandlerReadyCallback callback,
1349 EmpathyFTHandler *handler;
1350 CallbacksData *data;
1351 EmpathyFTHandlerPriv *priv;
1353 DEBUG ("New handler outgoing");
1355 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1356 g_return_if_fail (G_IS_FILE (source));
1358 handler = g_object_new (EMPATHY_TYPE_FT_HANDLER,
1361 "user-action-time", action_time,
1364 priv = GET_PRIV (handler);
1366 data = g_slice_new0 (CallbacksData);
1367 data->callback = callback;
1368 data->user_data = user_data;
1369 data->handler = g_object_ref (handler);
1371 /* start collecting info about the file */
1372 g_file_query_info_async (priv->gfile,
1373 G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
1374 G_FILE_ATTRIBUTE_STANDARD_SIZE ","
1375 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
1376 G_FILE_ATTRIBUTE_STANDARD_TYPE ","
1377 G_FILE_ATTRIBUTE_TIME_MODIFIED,
1378 G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
1379 NULL, (GAsyncReadyCallback) ft_handler_gfile_ready_cb, data);
1383 * empathy_ft_handler_new_incoming:
1384 * @channel: the #TpFileTransferChannel proxy to the incoming channel
1385 * @callback: callback to be called when the handler has been created
1386 * @user_data: user data to be passed to @callback
1388 * Triggers the creation of a new #EmpathyFTHandler for an incoming transfer.
1389 * Note that for the handler to be useful, you will have to set a destination
1390 * file with empathy_ft_handler_incoming_set_destination() after the handler
1394 empathy_ft_handler_new_incoming (TpFileTransferChannel *channel,
1395 EmpathyFTHandlerReadyCallback callback,
1398 EmpathyFTHandler *handler;
1399 CallbacksData *data;
1400 EmpathyFTHandlerPriv *priv;
1402 g_return_if_fail (TP_IS_FILE_TRANSFER_CHANNEL (channel));
1404 handler = g_object_new (EMPATHY_TYPE_FT_HANDLER,
1405 "channel", channel, NULL);
1407 priv = GET_PRIV (handler);
1409 data = g_slice_new0 (CallbacksData);
1410 data->callback = callback;
1411 data->user_data = user_data;
1412 data->handler = g_object_ref (handler);
1414 priv->total_bytes = tp_file_transfer_channel_get_size (channel);
1416 priv->transferred_bytes = tp_file_transfer_channel_get_transferred_bytes (
1419 priv->filename = g_strdup (tp_file_transfer_channel_get_filename (channel));
1421 priv->content_type = g_strdup (tp_file_transfer_channel_get_mime_type (
1424 priv->description = g_strdup (tp_file_transfer_channel_get_description (
1427 tp_cli_dbus_properties_call_get_all (channel,
1428 -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
1429 channel_get_all_properties_cb, data, NULL, G_OBJECT (handler));
1433 * empathy_ft_handler_start_transfer:
1434 * @handler: an #EmpathyFTHandler
1436 * Starts the transfer machinery. After this call, the transfer and hashing
1437 * signals will be emitted by the handler.
1440 empathy_ft_handler_start_transfer (EmpathyFTHandler *handler)
1442 EmpathyFTHandlerPriv *priv;
1444 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
1446 priv = GET_PRIV (handler);
1448 if (priv->channel == NULL)
1450 ft_handler_complete_request (handler);
1454 /* TODO: add support for resume. */
1455 tp_file_transfer_channel_accept_file_async (priv->channel,
1456 priv->gfile, 0, ft_transfer_accept_cb, handler);
1458 tp_g_signal_connect_object (priv->channel, "notify::state",
1459 G_CALLBACK (ft_transfer_state_cb), handler, 0);
1460 tp_g_signal_connect_object (priv->channel, "notify::transferred-bytes",
1461 G_CALLBACK (ft_transfer_transferred_bytes_cb), handler, 0);
1466 * empathy_ft_handler_cancel_transfer:
1467 * @handler: an #EmpathyFTHandler
1469 * Cancels an ongoing handler operation. Note that this doesn't destroy
1470 * the object, which will keep all the properties, altough it won't be able
1471 * to do any more I/O.
1474 empathy_ft_handler_cancel_transfer (EmpathyFTHandler *handler)
1476 EmpathyFTHandlerPriv *priv;
1478 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
1480 priv = GET_PRIV (handler);
1482 /* if we don't have a channel, we are hashing, so
1483 * we can just cancel the GCancellable to stop it.
1485 if (priv->channel == NULL)
1486 g_cancellable_cancel (priv->cancellable);
1488 tp_channel_close_async (TP_CHANNEL (priv->channel), NULL, NULL);
1492 * empathy_ft_handler_incoming_set_destination:
1493 * @handler: an #EmpathyFTHandler
1494 * @destination: the #GFile where the transfer should be saved
1496 * Sets the destination of the incoming handler to be @destination.
1497 * Note that calling this method is mandatory before starting the transfer
1498 * for incoming handlers.
1501 empathy_ft_handler_incoming_set_destination (EmpathyFTHandler *handler,
1504 EmpathyFTHandlerPriv *priv;
1506 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
1507 g_return_if_fail (G_IS_FILE (destination));
1509 priv = GET_PRIV (handler);
1511 g_object_set (handler, "gfile", destination, NULL);
1513 /* check if hash is supported. if it isn't, set use_hash to FALSE
1514 * anyway, so that clients won't be expecting us to checksum.
1516 if (TPAW_STR_EMPTY (priv->content_hash) ||
1517 priv->content_hash_type == TP_FILE_HASH_TYPE_NONE)
1518 priv->use_hash = FALSE;
1520 priv->use_hash = TRUE;
1524 * empathy_ft_handler_get_filename:
1525 * @handler: an #EmpathyFTHandler
1527 * Returns the name of the file being transferred.
1529 * Return value: the name of the file being transferred
1532 empathy_ft_handler_get_filename (EmpathyFTHandler *handler)
1534 EmpathyFTHandlerPriv *priv;
1536 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
1538 priv = GET_PRIV (handler);
1540 return priv->filename;
1544 * empathy_ft_handler_get_content_type:
1545 * @handler: an #EmpathyFTHandler
1547 * Returns the content type of the file being transferred.
1549 * Return value: the content type of the file being transferred
1552 empathy_ft_handler_get_content_type (EmpathyFTHandler *handler)
1554 EmpathyFTHandlerPriv *priv;
1556 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
1558 priv = GET_PRIV (handler);
1560 return priv->content_type;
1564 * empathy_ft_handler_get_contact:
1565 * @handler: an #EmpathyFTHandler
1567 * Returns the remote #EmpathyContact at the other side of the transfer.
1569 * Return value: the remote #EmpathyContact for @handler
1572 empathy_ft_handler_get_contact (EmpathyFTHandler *handler)
1574 EmpathyFTHandlerPriv *priv;
1576 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
1578 priv = GET_PRIV (handler);
1580 return priv->contact;
1584 * empathy_ft_handler_get_gfile:
1585 * @handler: an #EmpathyFTHandler
1587 * Returns the #GFile where the transfer is being read/saved.
1589 * Return value: the #GFile where the transfer is being read/saved
1592 empathy_ft_handler_get_gfile (EmpathyFTHandler *handler)
1594 EmpathyFTHandlerPriv *priv;
1596 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
1598 priv = GET_PRIV (handler);
1604 * empathy_ft_handler_get_use_hash:
1605 * @handler: an #EmpathyFTHandler
1607 * Returns whether @handler has checksumming enabled. This can depend on
1608 * the CM and the remote contact capabilities.
1610 * Return value: %TRUE if the handler has checksumming enabled,
1614 empathy_ft_handler_get_use_hash (EmpathyFTHandler *handler)
1616 EmpathyFTHandlerPriv *priv;
1618 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), FALSE);
1620 priv = GET_PRIV (handler);
1622 return priv->use_hash;
1626 * empathy_ft_handler_is_incoming:
1627 * @handler: an #EmpathyFTHandler
1629 * Returns whether @handler is incoming or outgoing.
1631 * Return value: %TRUE if the handler is incoming, %FALSE otherwise.
1634 empathy_ft_handler_is_incoming (EmpathyFTHandler *handler)
1636 EmpathyFTHandlerPriv *priv;
1638 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), FALSE);
1640 priv = GET_PRIV (handler);
1642 if (priv->channel == NULL)
1645 return !tp_channel_get_requested ((TpChannel *) priv->channel);
1649 * empathy_ft_handler_get_transferred_bytes:
1650 * @handler: an #EmpathyFTHandler
1652 * Returns the number of bytes already transferred by the handler.
1654 * Return value: the number of bytes already transferred by the handler.
1657 empathy_ft_handler_get_transferred_bytes (EmpathyFTHandler *handler)
1659 EmpathyFTHandlerPriv *priv;
1661 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), 0);
1663 priv = GET_PRIV (handler);
1665 return priv->transferred_bytes;
1669 * empathy_ft_handler_get_total_bytes:
1670 * @handler: an #EmpathyFTHandler
1672 * Returns the total size of the file being transferred by the handler.
1674 * Return value: a number of bytes indicating the total size of the file being
1675 * transferred by the handler.
1678 empathy_ft_handler_get_total_bytes (EmpathyFTHandler *handler)
1680 EmpathyFTHandlerPriv *priv;
1682 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), 0);
1684 priv = GET_PRIV (handler);
1686 return priv->total_bytes;
1690 * empathy_ft_handler_is_completed:
1691 * @handler: an #EmpathyFTHandler
1693 * Returns whether the transfer for @handler has been completed succesfully.
1695 * Return value: %TRUE if the handler has been transferred correctly, %FALSE
1699 empathy_ft_handler_is_completed (EmpathyFTHandler *handler)
1701 EmpathyFTHandlerPriv *priv;
1703 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), FALSE);
1705 priv = GET_PRIV (handler);
1707 return priv->is_completed;
1711 * empathy_ft_handler_is_cancelled:
1712 * @handler: an #EmpathyFTHandler
1714 * Returns whether the transfer for @handler has been cancelled or has stopped
1717 * Return value: %TRUE if the transfer for @handler has been cancelled
1718 * or has stopped due to an error, %FALSE otherwise.
1721 empathy_ft_handler_is_cancelled (EmpathyFTHandler *handler)
1723 EmpathyFTHandlerPriv *priv;
1725 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), FALSE);
1727 priv = GET_PRIV (handler);
1729 return g_cancellable_is_cancelled (priv->cancellable);