static void ft_manager_stop (EmpathyFTManager *manager) { GtkTreeSelection *selection; GtkTreeIter iter; GtkTreeModel *model; EmpathyFTHandler *handler; EmpathyFTManagerPriv *priv; priv = GET_PRIV (manager); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) return; gtk_tree_model_get (model, &iter, COL_FT_OBJECT, &handler, -1); g_return_if_fail (handler != NULL); DEBUG ("Stopping file transfer: contact=%s, filename=%s", empathy_contact_get_alias (empathy_ft_handler_get_contact (handler)), empathy_ft_handler_get_filename (handler)); empathy_ft_handler_cancel_transfer (handler); g_object_unref (handler); }
static void do_real_transfer_done (EmpathyFTManager *manager, EmpathyFTHandler *handler) { const char *contact_name; const char *filename; char *first_line, *second_line, *message; char *uri; gboolean incoming; GtkTreeRowReference *row_ref; GtkRecentManager *recent_manager; GFile *file; 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_alias (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 (_("“%s” received from %s"), filename, contact_name); else /* translators: first %s is filename, second %s * is the contact name */ first_line = g_strdup_printf (_("“%s” sent to %s"), filename, contact_name); second_line = g_strdup (_("File transfer completed")); message = g_strdup_printf ("%s\n%s", first_line, second_line); ft_manager_update_handler_message (manager, row_ref, message); ft_manager_clear_handler_time (manager, row_ref); /* update buttons */ ft_manager_update_buttons (manager); g_free (message); g_free (first_line); g_free (second_line); recent_manager = gtk_recent_manager_get_default (); file = empathy_ft_handler_get_gfile (handler); uri = g_file_get_uri (file); gtk_recent_manager_add_item (recent_manager, uri); g_free (uri); }
static void ft_manager_remove_file_from_model (EmpathyFTManager *manager, EmpathyFTHandler *handler) { GtkTreeRowReference *row_ref; GtkTreeSelection *selection; GtkTreePath *path = NULL; GtkTreeIter iter; gboolean update_selection; EmpathyFTManagerPriv *priv = GET_PRIV (manager); row_ref = ft_manager_get_row_from_handler (manager, handler); g_return_if_fail (row_ref); DEBUG ("Removing file transfer from window: contact=%s, filename=%s", empathy_contact_get_alias (empathy_ft_handler_get_contact (handler)), empathy_ft_handler_get_filename (handler)); /* Get the iter from the row_ref */ path = gtk_tree_row_reference_get_path (row_ref); gtk_tree_model_get_iter (priv->model, &iter, path); gtk_tree_path_free (path); /* We have to update the selection only if we are removing the selected row */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); update_selection = gtk_tree_selection_iter_is_selected (selection, &iter); /* Remove tp_file's row. After that iter points to the next row */ if (!gtk_list_store_remove (GTK_LIST_STORE (priv->model), &iter)) { gint n_row; /* There is no next row, set iter to the last row */ n_row = gtk_tree_model_iter_n_children (priv->model, NULL); if (n_row > 0) gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, n_row - 1); else update_selection = FALSE; } if (update_selection) gtk_tree_selection_select_iter (selection, &iter); }
static gchar * ft_manager_format_error_message (EmpathyFTHandler *handler, const GError *error) { const char *contact_name, *filename; EmpathyContact *contact; char *first_line, *message; gboolean incoming; contact_name = NULL; incoming = empathy_ft_handler_is_incoming (handler); contact = empathy_ft_handler_get_contact (handler); if (contact) contact_name = empathy_contact_get_alias (contact); filename = empathy_ft_handler_get_filename (handler); if (incoming) /* filename/contact_name here are either both NULL or both valid */ if (filename && contact_name) /* 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 first_line = g_strdup (_("Error receiving a file")); else /* translators: first %s is filename, second %s * is the contact name */ if (filename && contact_name) first_line = g_strdup_printf (_("Error sending “%s” to %s"), filename, contact_name); else first_line = g_strdup (_("Error sending a file")); message = g_strdup_printf ("%s\n%s", first_line, error->message); g_free (first_line); return message; }
void empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler) { GtkWidget *widget; const gchar *dir; EmpathyContact *contact; gchar *title; contact = empathy_ft_handler_get_contact (handler); g_assert (contact != NULL); title = g_strdup_printf (_("Incoming file from %s"), empathy_contact_get_alias (contact)); widget = gtk_file_chooser_dialog_new (title, NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (widget), empathy_ft_handler_get_filename (handler)); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (widget), TRUE); dir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD); if (dir == NULL) /* Fallback to $HOME if $XDG_DOWNLOAD_DIR is not set */ dir = g_get_home_dir (); gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (widget), dir); g_signal_connect (widget, "response", G_CALLBACK (file_manager_receive_file_response_cb), handler); gtk_widget_show (widget); g_free (title); }
static gchar * ft_manager_format_contact_info (EmpathyFTHandler *handler) { gboolean incoming; const char *filename, *contact_name, *first_line_format; char *retval; incoming = empathy_ft_handler_is_incoming (handler); contact_name = empathy_contact_get_alias (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_format = _("Receiving “%s” from %s"); else /* translators: first %s is filename, second %s is the contact name */ first_line_format = _("Sending “%s” to %s"); retval = g_strdup_printf (first_line_format, filename, contact_name); return retval; }