]> git.0d.be Git - empathy.git/commitdiff
First implementation of error handling
authorCosimo Cecchi <cosimo.cecchi@collabora.co.uk>
Mon, 4 May 2009 00:14:43 +0000 (02:14 +0200)
committerCosimo Cecchi <cosimoc@gnome.org>
Mon, 1 Jun 2009 15:47:38 +0000 (17:47 +0200)
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.

libempathy/empathy-ft-handler.c
libempathy/empathy-ft-handler.h
libempathy/empathy-tp-file.c
libempathy/empathy-tp-file.h
src/empathy-ft-manager.c

index 765de8bbd8cb0efa1bea938d92b00cbb1456a984..d7a65aaa7ac3c36944dd9d88a54215b4dc8c2923 100644 (file)
@@ -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 */
@@ -341,6 +341,18 @@ hash_data_free (HashingData *data)
   g_slice_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,
@@ -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
index c561fe29f1cf07528edfa46de8c2f5bff852dafe..728db809f3f4adc807a5573caacb52dc124502d8 100644 (file)
@@ -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);
index 098440a42845c2cdbf684a04ed79849b6f3a0458..88d13f358003a8bda7a9cf360f078d2fdd7a23b1 100644 (file)
@@ -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);
 }
 
index 04da254c12243b7d01df01d3005d5ce37750040a..612c00a44f1fe69c6bf97008c653de272f15ce9e 100644 (file)
@@ -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__ */
index 5424e057b379c7c39a502322aa56592fc29f6de9..8d94e397dd887e21b1b4220a6709c7fd4c1d2e57 100644 (file)
@@ -125,12 +125,7 @@ ft_manager_update_buttons (EmpathyFTManager *manager)
   GtkTreeSelection *selection;
   GtkTreeModel *model;
   GtkTreeIter iter;
-<<<<<<< HEAD:src/empathy-ft-manager.c
-  EmpathyTpFile *tp_file;
-  TpFileTransferState state;
-=======
   EmpathyFTHandler *handler;
->>>>>>> Use the proper TP interface instead of emp_cli:src/empathy-ft-manager.c
   gboolean open_enabled = FALSE;
   gboolean abort_enabled = FALSE;
   gboolean is_completed, is_cancelled;
@@ -146,19 +141,10 @@ ft_manager_update_buttons (EmpathyFTManager *manager)
       is_cancelled = empathy_ft_handler_is_cancelled (handler);
 
       /* I can open the file if the transfer is completed and was incoming */
-<<<<<<< HEAD:src/empathy-ft-manager.c
-      open_enabled = (state == TP_FILE_TRANSFER_STATE_COMPLETED &&
-        empathy_tp_file_is_incoming (tp_file));
-
-      /* I can abort if the transfer is not already finished */
-      abort_enabled = (state != TP_FILE_TRANSFER_STATE_CANCELLED &&
-        state != TP_FILE_TRANSFER_STATE_COMPLETED);
-=======
       open_enabled = (is_completed && empathy_ft_handler_is_incoming (handler));
 
       /* I can abort if the transfer is not already finished */
       abort_enabled = (is_cancelled == FALSE && is_completed == FALSE);
->>>>>>> Use the proper TP interface instead of emp_cli:src/empathy-ft-manager.c
 
       g_object_unref (handler);
     }
@@ -387,7 +373,39 @@ ft_handler_transfer_error_cb (EmpathyFTHandler *handler,
                               GError *error,
                               EmpathyFTManager *manager)
 {
-  /* TODO: implement */
+  const char *contact_name, *filename;
+  char *first_line, *message;
+  gboolean incoming;
+  GtkTreeRowReference *row_ref;
+
+  DEBUG ("Transfer error %s", error->message);
+
+  row_ref = ft_manager_get_row_from_handler (manager, handler);
+  g_return_if_fail (row_ref != NULL);
+
+  incoming = empathy_ft_handler_is_incoming (handler);  
+  contact_name = empathy_contact_get_name
+    (empathy_ft_handler_get_contact (handler));
+  filename = empathy_ft_handler_get_filename (handler);
+
+  if (incoming)
+    /* translators: first %s is filename, second %s
+     * is the contact name */
+    first_line = g_strdup_printf (_("Error receiving \"%s\" from %s"), filename,
+        contact_name);
+  else
+    /* translators: first %s is filename, second %s
+     * is the contact name */
+    first_line = g_strdup_printf (_("Error sensing \"%s\" to %s"), filename,
+        contact_name);
+
+  message = g_strdup_printf ("%s\n%s", first_line, error->message);
+
+  ft_manager_update_handler_message (manager, row_ref, message);
+  ft_manager_update_buttons (manager);
+
+  g_free (first_line);
+  g_free (message);
 }
 
 static void