diff options
author | Cosimo Cecchi <cosimo.cecchi@collabora.co.uk> | 2009-05-04 08:14:43 +0800 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2009-06-01 23:47:38 +0800 |
commit | a6b83fc7b0d3a0dbbd2d0266f6b2250221e803bb (patch) | |
tree | 40cdc85cac524753ec9a28a5adfd94bd6b733044 /libempathy | |
parent | 1f239a9cb9595292b71fc0336e5d0055c5b81860 (diff) | |
download | gsoc2013-empathy-a6b83fc7b0d3a0dbbd2d0266f6b2250221e803bb.tar gsoc2013-empathy-a6b83fc7b0d3a0dbbd2d0266f6b2250221e803bb.tar.gz gsoc2013-empathy-a6b83fc7b0d3a0dbbd2d0266f6b2250221e803bb.tar.bz2 gsoc2013-empathy-a6b83fc7b0d3a0dbbd2d0266f6b2250221e803bb.tar.lz gsoc2013-empathy-a6b83fc7b0d3a0dbbd2d0266f6b2250221e803bb.tar.xz gsoc2013-empathy-a6b83fc7b0d3a0dbbd2d0266f6b2250221e803bb.tar.zst gsoc2013-empathy-a6b83fc7b0d3a0dbbd2d0266f6b2250221e803bb.zip |
First implementation of error handling
Implement the callback in EmpathyFTManager.
Erase a redundant is_cancelled property in EmpathyFTHandler and rely on
the GCancellable, which is shared by EmpathyTpFile and EmpathyFTHandler.
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-ft-handler.c | 61 | ||||
-rw-r--r-- | libempathy/empathy-ft-handler.h | 2 | ||||
-rw-r--r-- | libempathy/empathy-tp-file.c | 34 | ||||
-rw-r--r-- | libempathy/empathy-tp-file.h | 2 |
4 files changed, 27 insertions, 72 deletions
diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c index 765de8bbd..d7a65aaa7 100644 --- a/libempathy/empathy-ft-handler.c +++ b/libempathy/empathy-ft-handler.c @@ -97,7 +97,6 @@ typedef struct { TpFileTransferState current_state; gboolean is_completed; - gboolean is_cancelled; } EmpathyFTHandlerPriv; static guint signals[LAST_SIGNAL] = { 0 }; @@ -302,6 +301,7 @@ empathy_ft_handler_init (EmpathyFTHandler *self) EMPATHY_TYPE_FT_HANDLER, EmpathyFTHandlerPriv); self->priv = priv; + priv->cancellable = g_cancellable_new (); } /* private functions */ @@ -342,6 +342,18 @@ hash_data_free (HashingData *data) } static void +emit_error_signal (EmpathyFTHandler *handler, + const GError *error) +{ + EmpathyFTHandlerPriv *priv = GET_PRIV (handler); + + if (!g_cancellable_is_cancelled (priv->cancellable)) + g_cancellable_cancel (priv->cancellable); + + g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error); +} + +static void ft_transfer_operation_callback (EmpathyTpFile *tp_file, const GError *error, gpointer user_data) @@ -353,8 +365,7 @@ ft_transfer_operation_callback (EmpathyTpFile *tp_file, if (error != NULL) { - priv->is_cancelled = TRUE; - g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error); + emit_error_signal (handler, error); } else { @@ -386,24 +397,21 @@ ft_handler_create_channel_cb (EmpathyDispatchOperation *operation, { EmpathyFTHandler *handler = user_data; EmpathyFTHandlerPriv *priv = GET_PRIV (handler); - GError *my_error = NULL; + GError *my_error = (GError *) error; DEBUG ("Dispatcher create channel CB"); - if (error != NULL) + if (my_error == NULL) { - priv->is_cancelled = TRUE; - g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error); - return; + g_cancellable_set_error_if_cancelled (priv->cancellable, &my_error); } - g_cancellable_set_error_if_cancelled (priv->cancellable, &my_error); - if (my_error != NULL) { - priv->is_cancelled = TRUE; - g_signal_emit (handler, signals[TRANSFER_ERROR], 0, my_error); - g_clear_error (&my_error); + emit_error_signal (handler, my_error); + + if (my_error != error) + g_clear_error (&my_error); return; } @@ -570,9 +578,7 @@ cleanup: if (error != NULL) { - priv->is_cancelled = TRUE; - g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error); - g_clear_error (&error); + emit_error_signal (handler, error); } else { @@ -664,8 +670,7 @@ ft_handler_read_async_cb (GObject *source, stream = g_file_read_finish (priv->gfile, res, &error); if (error != NULL) { - priv->is_cancelled = TRUE; - g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error); + emit_error_signal (handler, error); g_clear_error (&error); return; @@ -705,9 +710,7 @@ ft_handler_complete_request (EmpathyFTHandler *handler) EMPATHY_FT_ERROR_NOT_SUPPORTED, _("File transfer not supported by remote contact")); - priv->is_cancelled = TRUE; - g_signal_emit (handler, signals[TRANSFER_ERROR], 0, myerr); - g_clear_error (&myerr); + emit_error_signal (handler, myerr); return; } @@ -918,7 +921,6 @@ empathy_ft_handler_start_transfer (EmpathyFTHandler *handler) g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler)); priv = GET_PRIV (handler); - priv->cancellable = g_cancellable_new (); if (priv->tpfile == NULL) { @@ -1010,19 +1012,6 @@ empathy_ft_handler_get_gfile (EmpathyFTHandler *handler) return priv->gfile; } -TpFileTransferState -empathy_ft_handler_get_state (EmpathyFTHandler *handler, - char **state_string) -{ - EmpathyFTHandlerPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), -1); - - priv = GET_PRIV (handler); - - return priv->current_state; -} - gboolean empathy_ft_handler_is_incoming (EmpathyFTHandler *handler) { @@ -1083,5 +1072,5 @@ empathy_ft_handler_is_cancelled (EmpathyFTHandler *handler) priv = GET_PRIV (handler); - return priv->is_cancelled; + return g_cancellable_is_cancelled (priv->cancellable); }
\ No newline at end of file diff --git a/libempathy/empathy-ft-handler.h b/libempathy/empathy-ft-handler.h index c561fe29f..728db809f 100644 --- a/libempathy/empathy-ft-handler.h +++ b/libempathy/empathy-ft-handler.h @@ -77,8 +77,6 @@ const char * empathy_ft_handler_get_filename (EmpathyFTHandler *handler); const char * empathy_ft_handler_get_content_type (EmpathyFTHandler *handler); EmpathyContact * empathy_ft_handler_get_contact (EmpathyFTHandler *handler); GFile * empathy_ft_handler_get_gfile (EmpathyFTHandler *handler); -TpFileTransferState empathy_ft_handler_get_state (EmpathyFTHandler *handler, - char **state_string); gboolean empathy_ft_handler_is_incoming (EmpathyFTHandler *handler); guint64 empathy_ft_handler_get_transferred_bytes (EmpathyFTHandler *handler); guint64 empathy_ft_handler_get_total_bytes (EmpathyFTHandler *handler); diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c index 098440a42..88d13f358 100644 --- a/libempathy/empathy-tp-file.c +++ b/libempathy/empathy-tp-file.c @@ -737,37 +737,6 @@ empathy_tp_file_is_incoming (EmpathyTpFile *tp_file) return priv->incoming; } -/** - * empathy_tp_file_get_state: - * @tp_file: an #EmpathyTpFile - * @reason: return location for state change reason, or %NULL - * - * Gets the current state of @tp_file. If @reason is not %NULL, then - * it is set to the reason of the last state change. - * - * Return value: a #TpFileTransferState - */ -TpFileTransferState -empathy_tp_file_get_state (EmpathyTpFile *tp_file, - TpFileTransferStateChangeReason *reason) -{ - EmpathyTpFilePriv *priv = GET_PRIV (tp_file); - - g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), - TP_FILE_TRANSFER_STATE_NONE); - - if (reason != NULL) - *reason = priv->state_change_reason; - - return priv->state; -} - -/** - * empathy_tp_file_cancel: - * @tp_file: an #EmpathyTpFile - * - * Cancels the file transfer, @tp_file. - */ void empathy_tp_file_cancel (EmpathyTpFile *tp_file) { @@ -781,7 +750,8 @@ empathy_tp_file_cancel (EmpathyTpFile *tp_file) tp_cli_channel_call_close (priv->channel, -1, NULL, NULL, NULL, NULL); - if (priv->cancellable != NULL) + if (priv->cancellable != NULL && + !g_cancellable_is_cancelled (priv->cancellable)) g_cancellable_cancel (priv->cancellable); } diff --git a/libempathy/empathy-tp-file.h b/libempathy/empathy-tp-file.h index 04da254c1..612c00a44 100644 --- a/libempathy/empathy-tp-file.h +++ b/libempathy/empathy-tp-file.h @@ -93,8 +93,6 @@ void empathy_tp_file_close (EmpathyTpFile *tp_file); gboolean empathy_tp_file_is_incoming (EmpathyTpFile *tp_file); -TpFileTransferState empathy_tp_file_get_state (EmpathyTpFile *tp_file, guint *reason); - G_END_DECLS #endif /* __EMPATHY_TP_FILE_H__ */ |