From a1dd90f1f8731f683d14a63abb8c411418fbba1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Thu, 10 Oct 2024 20:17:59 +0200 Subject: [PATCH] FileOperations: Continue to move some report functions to Vala (#2503) Co-authored-by: Jeremy Wootten --- libcore/FileOperations/CommonJob.vala | 21 +- libcore/FileOperations/CopyMoveJob.vala | 205 +++++++++++++ libcore/FileOperations/DeleteJob.vala | 77 +++++ libcore/marlin-file-operations.c | 381 ++---------------------- 4 files changed, 311 insertions(+), 373 deletions(-) diff --git a/libcore/FileOperations/CommonJob.vala b/libcore/FileOperations/CommonJob.vala index a1dbb25c57..0aec44179c 100644 --- a/libcore/FileOperations/CommonJob.vala +++ b/libcore/FileOperations/CommonJob.vala @@ -17,25 +17,28 @@ */ public class Files.FileOperations.CommonJob { + protected const int NSEC_PER_MSEC = 1000000; + protected const int SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE = 15; + [Compact] [CCode (cname = "SourceInfo")] protected class SourceInfo { [CCode (has_target = false, cname = "CountProgressCallback")] - protected delegate void CountProgressCallback (Files.FileOperations.CommonJob job, Files.FileOperations.CommonJob.SourceInfo info); + internal delegate void CountProgressCallback (Files.FileOperations.CommonJob job, Files.FileOperations.CommonJob.SourceInfo info); - protected int num_files; - protected size_t num_bytes; - protected int num_files_since_progress; - protected weak CountProgressCallback count_callback; + internal int num_files; + internal size_t num_bytes; + internal int num_files_since_progress; + internal weak CountProgressCallback count_callback; } [Compact] [CCode (cname = "TransferInfo")] protected class TransferInfo { - protected int num_files; - protected size_t num_bytes; - protected uint64 last_report_time; - protected int last_reported_files_left; + internal int num_files; + internal size_t num_bytes; + internal uint64 last_report_time; + internal int last_reported_files_left; } protected unowned Gtk.Window? parent_window; diff --git a/libcore/FileOperations/CopyMoveJob.vala b/libcore/FileOperations/CopyMoveJob.vala index 2a2f641fbd..508c49cd85 100644 --- a/libcore/FileOperations/CopyMoveJob.vala +++ b/libcore/FileOperations/CopyMoveJob.vala @@ -42,4 +42,209 @@ public class Files.FileOperations.CopyMoveJob : CommonJob { this.destination = destination; is_move = true; } + + protected void report_copy_move_count_progress (CommonJob.SourceInfo source_info) { + string s; + string num_bytes_format = GLib.format_size (source_info.num_bytes); + + if (!is_move) { + /// TRANSLATORS: %'d is a placeholder for a number. It must not be translated or removed. + /// %s is a placeholder for a size like "2 bytes" or "3 MB". It must not be translated or removed. + /// So this represents something like "Preparing to copy 100 files (200 MB)" + /// The order in which %'d and %s appear can be changed by using the right positional specifier. + s = ngettext ( + "Preparing to copy %'d file (%s)", + "Preparing to copy %'d files (%s)", + source_info.num_files + ).printf (source_info.num_files, num_bytes_format); + } else { + /// TRANSLATORS: %'d is a placeholder for a number. It must not be translated or removed. + /// %s is a placeholder for a size like "2 bytes" or "3 MB". It must not be translated or removed. + /// So this represents something like "Preparing to move 100 files (200 MB)" + /// The order in which %'d and %s appear can be changed by using the right positional specifier. + s = ngettext ( + "Preparing to move %'d file (%s)", + "Preparing to move %'d files (%s)", + source_info.num_files + ).printf (source_info.num_files, num_bytes_format); + } + + progress.take_details (s); + progress.pulse_progress (); + } + + protected void report_link_progress (int total, int left) { + /// TRANSLATORS: '\"%s\"' is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed + /// '\"' is an escaped quoted mark. This may be replaced with another suitable character (escaped if necessary) + var s = _("Creating links in \"%s\"").printf (destination.get_parse_name ()); + + progress.take_status (s); + progress.take_details ( + ngettext ( + "Making link to %'d file", + "Making links to %'d files", + left + ).printf (left) + ); + + progress.update_progress (left, total); + } + + protected void report_copy_progress (CommonJob.SourceInfo source_info, CommonJob.TransferInfo transfer_info) { + int64 now = GLib.get_monotonic_time () * 1000; // in ns + + if (transfer_info.last_report_time != 0 && + ((int64)transfer_info.last_report_time - now).abs () < 100 * CommonJob.NSEC_PER_MSEC) { + return; + } + + /* See https://github.com/elementary/files/issues/464. The job data may become invalid, possibly + * due to a race. */ + if (files.data == null || destination == null) { + return; + } + + var srcname = FileUtils.custom_basename_from_file (files.data); + var destname = FileUtils.custom_basename_from_file (destination); + + transfer_info.last_report_time = now; + + int files_left = source_info.num_files - transfer_info.num_files; + + /* Races and whatnot could cause this to be negative... */ + if (files_left < 0) { + return; + } + + if (files_left != transfer_info.last_reported_files_left || + transfer_info.last_reported_files_left == 0) { + string s; + + /* Avoid changing this unless files_left changed since last time */ + transfer_info.last_reported_files_left = files_left; + + if (source_info.num_files == 1) { + if (destination != null) { + /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. + /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). + s = (is_move ? _("Moving \"%s\" to \"%s\"") : _("Copying \"%s\" to \"%s\"")).printf (srcname, destname); + } else { + /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. + /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). + s = _("Duplicating \"%s\"").printf (srcname); + } + } else if (files != null && files.next == null) { + if (destination != null) { + /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. + /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). + /// %'d is a placeholder for a number. It must not be translated or removed. + /// Placeholders must appear in the same order but otherwise may change position. + s = (is_move ? + ngettext ( + "Moving %'d file (in \"%s\") to \"%s\"", + "Moving %'d files (in \"%s\") to \"%s\"", + files_left + ) : + ngettext ( + "Copying %'d file (in \"%s\") to \"%s\"", + "Copying %'d files (in \"%s\") to \"%s\"", + files_left + ) + ).printf (files_left, srcname, destname); + } else { + /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. + /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). + s = ngettext ( + "Duplicating %'d file (in \"%s\")", + "Duplicating %'d files (in \"%s\")", + files_left + ).printf (files_left, destname); + } + } else { + if (destination != null) { + /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. + /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). + /// %'d is a placeholder for a number. It must not be translated or removed. + /// Placeholders must appear in the same order but otherwise may change position. + s = (is_move ? + ngettext ( + "Moving %'d file to \"%s\"", + "Moving %'d files to \"%s\"", + files_left + ) : + ngettext ( + "Copying %'d file to \"%s\"", + "Copying %'d files to \"%s\"", + files_left + ) + ).printf (files_left, destname); + } else { + s = ngettext ( + "Duplicating %'d file", + "Duplicating %'d files", + files_left + ).printf (files_left); + } + } + + progress.take_status ((owned) s); + } + + var total_size = size_t.max (source_info.num_bytes, transfer_info.num_bytes); + + double elapsed = time.elapsed (); + double transfer_rate = 0; + if (elapsed > 0) { + transfer_rate = transfer_info.num_bytes / elapsed; + } + + if (elapsed < CommonJob.SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE && + transfer_rate > 0) { + var num_bytes_format = GLib.format_size (transfer_info.num_bytes); + var total_size_format = GLib.format_size (total_size); + /// TRANSLATORS: %s is a placeholder for a size like "2 bytes" or "3 MB". It must not be translated or removed. So this represents something like "4 kb of 4 MB". + progress.take_details (_("%s of %s").printf (num_bytes_format, total_size_format)); + } else { + var num_bytes_format = GLib.format_size (transfer_info.num_bytes); + var total_size_format = GLib.format_size (total_size); + var transfer_rate_format = GLib.format_size ((uint64) transfer_rate); + int remaining_time = (int )((total_size - transfer_info.num_bytes) / transfer_rate); + int formated_time_unit; + var formated_remaining_time = FileUtils.format_time (remaining_time, out formated_time_unit); + + + /// TRANSLATORS: The two first %s and the last %s will expand to a size + /// like "2 bytes" or "3 MB", the third %s to a time duration like + /// "2 minutes". It must not be translated or removed. + /// So the whole thing will be something like "2 kb of 4 MB -- 2 hours left (4kb/sec)" + /// The singular/plural form will be used depending on the remaining time (i.e. the "%s left" part). + /// The order in which %s appear can be changed by using the right positional specifier. + var s = ngettext ( + "%s of %s \xE2\x80\x94 %s left (%s/sec)", + "%s of %s \xE2\x80\x94 %s left (%s/sec)", + formated_time_unit + ).printf (num_bytes_format, total_size_format, formated_remaining_time, transfer_rate_format); //FIXME Remove opaque hex + progress.take_details ((owned) s); + } + + progress.update_progress (transfer_info.num_bytes, total_size); + } + + protected void report_move_progress (int total, int left) { + var dest_basename = Files.FileUtils.custom_basename_from_file (destination); + /// TRANSLATORS: '\"%s\"' is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed + /// '\"' is an escaped quoted mark. This may be replaced with another suitable character (escaped if necessary) + var s = _("Preparing to move to \"%s\"").printf (dest_basename); + + progress.take_status (s); + progress.take_details ( + ngettext ( + "Preparing to move %'d file", + "Preparing to move %'d files", + left + ).printf (left) + ); + + progress.pulse_progress (); + } } diff --git a/libcore/FileOperations/DeleteJob.vala b/libcore/FileOperations/DeleteJob.vala index 510d9c5745..0d8bab9976 100644 --- a/libcore/FileOperations/DeleteJob.vala +++ b/libcore/FileOperations/DeleteJob.vala @@ -84,4 +84,81 @@ public class Files.FileOperations.DeleteJob : CommonJob { false, CANCEL, DELETE) == 1; } + + protected void report_delete_progress (CommonJob.SourceInfo source_info, CommonJob.TransferInfo transfer_info) { + int64 now = GLib.get_monotonic_time () * 1000; // in ns + if (transfer_info.last_report_time != 0 && + ((int64)transfer_info.last_report_time - now).abs () < 100 * CommonJob.NSEC_PER_MSEC) { + return; + } + + transfer_info.last_report_time = now; + + int files_left = source_info.num_files - transfer_info.num_files; + + /* Races and whatnot could cause this to be negative... */ + if (files_left < 0) { + files_left = 1; + } + + string files_left_s = ngettext ( + "%'d file left to delete", + "%'d files left to delete", + files_left + ).printf (files_left); + + progress.take_status (_("Deleting files")); + + double elapsed = time.elapsed (); + if (elapsed < CommonJob.SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE) { + progress.take_details ((owned) files_left_s); + } else { + double transfer_rate = transfer_info.num_files / elapsed; + int remaining_time = (int) GLib.Math.floor (files_left / transfer_rate); + int formated_time_unit; + string formated_time = FileUtils.format_time (remaining_time, out formated_time_unit); + + /// TRANSLATORS: %s will expand to a time like "2 minutes". It must not be translated or removed. + /// The singular/plural form will be used depending on the remaining time (i.e. the %s argument). + string time_left_s = ngettext ("%s left", "%s left", formated_time_unit).printf (formated_time); + + string details = files_left_s.concat ("\xE2\x80\x94", time_left_s); //FIXME Remove opaque hex + progress.take_details ((owned) details); + } + + if (source_info.num_files != 0) { + progress.update_progress (transfer_info.num_files, source_info.num_files); + } + } + + protected void report_delete_count_progress (CommonJob.SourceInfo source_info) { + /// TRANSLATORS: %'d is a placeholder for a number. It must not be translated or removed. + /// %s is a placeholder for a size like "2 bytes" or "3 MB". It must not be translated or removed. + /// So this represents something like "Preparing to delete 100 files (200 MB)" + /// The order in which %'d and %s appear can be changed by using the right positional specifier. + var s = ngettext ( + "Preparing to delete %'d file (%s)", + "Preparing to delete %'d files (%s)", + source_info.num_files + ).printf (source_info.num_files, GLib.format_size (source_info.num_bytes)); + progress.take_details (s); + progress.pulse_progress (); + } + + protected void report_trash_progress (int files_trashed, int total_files) { + var files_left = total_files - files_trashed; + + progress.take_status (_("Moving files to trash")); + + var s = ngettext ( + "%'d file left to trash", + "%'d files left to trash", + files_left + ).printf (files_left); + progress.take_details (s); + + if (total_files != 0) { + progress.update_progress (files_trashed, total_files); + } + } } diff --git a/libcore/marlin-file-operations.c b/libcore/marlin-file-operations.c index b3c453174a..6610499ce4 100644 --- a/libcore/marlin-file-operations.c +++ b/libcore/marlin-file-operations.c @@ -64,70 +64,6 @@ should_confirm_trash (void) return files_preferences_get_confirm_trash (files_preferences_get_default ()); } -static void -report_delete_progress (FilesFileOperationsCommonJob *job, - SourceInfo *source_info, - TransferInfo *transfer_info) -{ - int files_left; - double elapsed, transfer_rate; - int remaining_time; - guint64 now; - char *files_left_s; - - now = g_thread_gettime (); - if (transfer_info->last_report_time != 0 && - ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MSEC) { - return; - } - transfer_info->last_report_time = now; - - files_left = source_info->num_files - transfer_info->num_files; - - /* Races and whatnot could cause this to be negative... */ - if (files_left < 0) { - files_left = 1; - } - - files_left_s = g_strdup_printf (ngettext ("%'d file left to delete", - "%'d files left to delete", - files_left), - files_left); - - pf_progress_info_take_status (job->progress, g_strdup (_("Deleting files"))); - - elapsed = g_timer_elapsed (job->time, NULL); - if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE) { - pf_progress_info_set_details (job->progress, files_left_s); - } else { - char *details, *time_left_s; - gchar *formated_time; - transfer_rate = transfer_info->num_files / elapsed; - remaining_time = files_left / transfer_rate; - int formated_time_unit; - formated_time = files_file_utils_format_time (remaining_time, &formated_time_unit); - - /// TRANSLATORS: %s will expand to a time like "2 minutes". It must not be translated or removed. - /// The singular/plural form will be used depending on the remaining time (i.e. the %s argument). - time_left_s = g_strdup_printf (ngettext ("%s left", - "%s left", - formated_time_unit), - formated_time); - g_free (formated_time); - - details = g_strconcat (files_left_s, "\xE2\x80\x94", time_left_s, NULL); //FIXME Remove opaque hex - pf_progress_info_take_details (job->progress, details); - - g_free (time_left_s); - } - - g_free (files_left_s); - - if (source_info->num_files != 0) { - pf_progress_info_update_progress (job->progress, transfer_info->num_files, source_info->num_files); - } -} - static void delete_file (FilesFileOperationsDeleteJob *del_job, GFile *file, gboolean *skipped_file, SourceInfo *source_info, @@ -300,7 +236,7 @@ delete_dir (FilesFileOperationsDeleteJob *del_job, GFile *dir, } else { files_file_changes_queue_file_removed (dir); transfer_info->num_files ++; - report_delete_progress (job, source_info, transfer_info); + marlin_file_operations_delete_job_report_delete_progress (del_job, source_info, transfer_info); return; } } @@ -331,7 +267,7 @@ delete_file (FilesFileOperationsDeleteJob *del_job, GFile *file, if (g_file_delete (file, job->cancellable, &error)) { files_file_changes_queue_file_removed (file); transfer_info->num_files ++; - report_delete_progress (job, source_info, transfer_info); + marlin_file_operations_delete_job_report_delete_progress (del_job, source_info, transfer_info); return; } @@ -383,28 +319,6 @@ delete_file (FilesFileOperationsDeleteJob *del_job, GFile *file, *skipped_file = TRUE; } -static void -report_delete_count_progress (FilesFileOperationsDeleteJob *job, - SourceInfo *source_info) -{ - FilesFileOperationsCommonJob *common = MARLIN_FILE_OPERATIONS_COMMON_JOB (job); - char *s; - gchar *num_bytes_format; - - num_bytes_format = g_format_size (source_info->num_bytes); - /// TRANSLATORS: %'d is a placeholder for a number. It must not be translated or removed. - /// %s is a placeholder for a size like "2 bytes" or "3 MB". It must not be translated or removed. - /// So this represents something like "Preparing to delete 100 files (200 MB)" - /// The order in which %'d and %s appear can be changed by using the right positional specifier. - s = g_strdup_printf (ngettext("Preparing to delete %'d file (%s)", - "Preparing to delete %'d files (%s)", - source_info->num_files), - source_info->num_files, num_bytes_format); - g_free (num_bytes_format); - pf_progress_info_take_details (common->progress, s); - pf_progress_info_pulse_progress (common->progress); -} - static void delete_files (FilesFileOperationsDeleteJob *del_job, GList *files, int *files_skipped) { @@ -421,7 +335,7 @@ delete_files (FilesFileOperationsDeleteJob *del_job, GList *files, int *files_sk scan_sources (files, &source_info, - (CountProgressCallback) report_delete_count_progress, + (CountProgressCallback) marlin_file_operations_delete_job_report_delete_count_progress, job); if (marlin_file_operations_common_job_aborted (job)) { return; @@ -430,7 +344,7 @@ delete_files (FilesFileOperationsDeleteJob *del_job, GList *files, int *files_sk g_timer_start (job->time); memset (&transfer_info, 0, sizeof (transfer_info)); - report_delete_progress (job, &source_info, &transfer_info); + marlin_file_operations_delete_job_report_delete_progress (del_job, &source_info, &transfer_info); for (l = files; l != NULL && !marlin_file_operations_common_job_aborted (job); @@ -452,31 +366,6 @@ delete_files (FilesFileOperationsDeleteJob *del_job, GList *files, int *files_sk pf_sound_manager_play_delete_sound (sm); } -static void -report_trash_progress (FilesFileOperationsDeleteJob *del_job, - int files_trashed, - int total_files) -{ - FilesFileOperationsCommonJob *job = MARLIN_FILE_OPERATIONS_COMMON_JOB (del_job); - int files_left; - char *s; - - files_left = total_files - files_trashed; - - pf_progress_info_take_status (job->progress, - g_strdup (_("Moving files to trash"))); - - s = g_strdup_printf (ngettext ("%'d file left to trash", - "%'d files left to trash", - files_left), - files_left); - pf_progress_info_take_details (job->progress, s); - - if (total_files != 0) { - pf_progress_info_update_progress (job->progress, files_trashed, total_files); - } -} - static void trash_files (FilesFileOperationsDeleteJob *del_job, GList *files, int *files_skipped) @@ -509,7 +398,7 @@ trash_files (FilesFileOperationsDeleteJob *del_job, GList *files, int *files_ski total_files = g_list_length (files); files_trashed = 0; - report_trash_progress (del_job, files_trashed, total_files); + marlin_file_operations_delete_job_report_trash_progress (del_job, files_trashed, total_files); to_delete = NULL; for (l = files; @@ -641,7 +530,7 @@ trash_files (FilesFileOperationsDeleteJob *del_job, GList *files, int *files_ski // End UNDO-REDO files_trashed++; - report_trash_progress (del_job, files_trashed, total_files); + marlin_file_operations_delete_job_report_trash_progress (del_job, files_trashed, total_files); } } @@ -780,41 +669,6 @@ marlin_file_operations_delete_finish (GAsyncResult *result, return g_task_propagate_boolean (G_TASK (result), error); } -static void -report_copy_move_count_progress (FilesFileOperationsCopyMoveJob *job, - SourceInfo *source_info) -{ - FilesFileOperationsCommonJob *common = MARLIN_FILE_OPERATIONS_COMMON_JOB (job); - char *s; - gchar *num_bytes_format; - - if (!job->is_move) { - num_bytes_format = g_format_size (source_info->num_bytes); - /// TRANSLATORS: %'d is a placeholder for a number. It must not be translated or removed. - /// %s is a placeholder for a size like "2 bytes" or "3 MB". It must not be translated or removed. - /// So this represents something like "Preparing to copy 100 files (200 MB)" - /// The order in which %'d and %s appear can be changed by using the right positional specifier. - s = g_strdup_printf (ngettext("Preparing to copy %'d file (%s)", - "Preparing to copy %'d files (%s)", - source_info->num_files), - source_info->num_files, num_bytes_format); - } else { - num_bytes_format = g_format_size (source_info->num_bytes); - /// TRANSLATORS: %'d is a placeholder for a number. It must not be translated or removed. - /// %s is a placeholder for a size like "2 bytes" or "3 MB". It must not be translated or removed. - /// So this represents something like "Preparing to move 100 files (200 MB)" - /// The order in which %'d and %s appear can be changed by using the right positional specifier. - s = g_strdup_printf (ngettext("Preparing to move %'d file (%s)", - "Preparing to move %'d files (%s)", - source_info->num_files), - source_info->num_files, num_bytes_format); - } - - g_free (num_bytes_format); - pf_progress_info_take_details (common->progress, s); - pf_progress_info_pulse_progress (common->progress); -} - static void count_file (GFileInfo *info, FilesFileOperationsCommonJob *job, @@ -1110,166 +964,6 @@ scan_sources (GList *files, source_info->count_callback (job, source_info); } -static void -report_copy_progress (FilesFileOperationsCopyMoveJob *copy_job, - SourceInfo *source_info, - TransferInfo *transfer_info) -{ - FilesFileOperationsCommonJob *job = MARLIN_FILE_OPERATIONS_COMMON_JOB (copy_job); - gboolean is_move = copy_job->is_move; - int files_left; - goffset total_size; - double elapsed, transfer_rate; - int remaining_time; - guint64 now = g_thread_gettime (); - gchar *s = NULL; - gchar *srcname = NULL; - gchar *destname = NULL; - - if (transfer_info->last_report_time != 0 && - ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MSEC) { - return; - } - - /* See https://github.com/elementary/files/issues/464. The job data may become invalid, possibly - * due to a race. */ - if (!G_IS_FILE (copy_job->files->data) || ! G_IS_FILE (copy_job->destination)) { - return; - } else { - srcname = files_file_utils_custom_basename_from_file ((GFile *)copy_job->files->data); - destname = files_file_utils_custom_basename_from_file (copy_job->destination); - } - - transfer_info->last_report_time = now; - - files_left = source_info->num_files - transfer_info->num_files; - - /* Races and whatnot could cause this to be negative... */ - if (files_left < 0) { - return; - } - - if (files_left != transfer_info->last_reported_files_left || - transfer_info->last_reported_files_left == 0) { - /* Avoid changing this unless files_left changed since last time */ - transfer_info->last_reported_files_left = files_left; - - if (source_info->num_files == 1) { - if (copy_job->destination != NULL) { - /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. - /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). - s = g_strdup_printf (is_move ? _("Moving \"%s\" to \"%s\"") : - _("Copying \"%s\" to \"%s\""), srcname, destname); - } else { - /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. - /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). - s = g_strdup_printf (_("Duplicating \"%s\""), srcname); - } - } else if (copy_job->files != NULL && copy_job->files->next == NULL) { - if (copy_job->destination != NULL) { - /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. - /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). - /// %'d is a placeholder for a number. It must not be translated or removed. - /// Placeholders must appear in the same order but otherwise may change position. - s = g_strdup_printf (is_move ? ngettext ("Moving %'d file (in \"%s\") to \"%s\"", - "Moving %'d files (in \"%s\") to \"%s\"", - files_left) : - ngettext ("Copying %'d file (in \"%s\") to \"%s\"", - "Copying %'d files (in \"%s\") to \"%s\"", - files_left), - files_left, - srcname, - destname); - } else { - /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. - /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). - s = g_strdup_printf (ngettext ("Duplicating %'d file (in \"%s\")", - "Duplicating %'d files (in \"%s\")", - files_left), - files_left, - destname); - } - } else { - if (copy_job->destination != NULL) { - /// TRANSLATORS: \"%s\" is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed. - /// \" is an escaped quotation mark. This may be replaced with another suitable character (escaped if necessary). - /// %'d is a placeholder for a number. It must not be translated or removed. - /// Placeholders must appear in the same order but otherwise may change position. - s = g_strdup_printf (is_move ? ngettext ("Moving %'d file to \"%s\"", - "Moving %'d files to \"%s\"", - files_left) : - ngettext ("Copying %'d file to \"%s\"", - "Copying %'d files to \"%s\"", - files_left), - files_left, - destname); - } else { - s = g_strdup_printf (ngettext ("Duplicating %'d file", - "Duplicating %'d files", - files_left), - files_left); - } - } - } - - if (s != NULL) - { - pf_progress_info_take_status (job->progress, s); - } - - g_free (srcname); - g_free (destname); - - total_size = MAX (source_info->num_bytes, transfer_info->num_bytes); - - elapsed = g_timer_elapsed (job->time, NULL); - transfer_rate = 0; - if (elapsed > 0) { - transfer_rate = transfer_info->num_bytes / elapsed; - } - - if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE && - transfer_rate > 0) { - char *s; - gchar *num_bytes_format = g_format_size (transfer_info->num_bytes); - gchar *total_size_format = g_format_size (total_size); - /// TRANSLATORS: %s is a placeholder for a size like "2 bytes" or "3 MB". It must not be translated or removed. So this represents something like "4 kb of 4 MB". - s = g_strdup_printf (_("%s of %s"), num_bytes_format, total_size_format); - g_free (num_bytes_format); - g_free (total_size_format); - pf_progress_info_take_details (job->progress, s); - } else { - char *s, *formated_remaining_time; - gchar *num_bytes_format = g_format_size (transfer_info->num_bytes); - gchar *total_size_format = g_format_size (total_size); - gchar *transfer_rate_format = g_format_size (transfer_rate); - remaining_time = (total_size - transfer_info->num_bytes) / transfer_rate; - int formated_time_unit; - formated_remaining_time = files_file_utils_format_time (remaining_time, &formated_time_unit); - - - /// TRANSLATORS: The two first %s and the last %s will expand to a size - /// like "2 bytes" or "3 MB", the third %s to a time duration like - /// "2 minutes". It must not be translated or removed. - /// So the whole thing will be something like "2 kb of 4 MB -- 2 hours left (4kb/sec)" - /// The singular/plural form will be used depending on the remaining time (i.e. the "%s left" part). - /// The order in which %s appear can be changed by using the right positional specifier. - s = g_strdup_printf (ngettext ("%s of %s \xE2\x80\x94 %s left (%s/sec)", - "%s of %s \xE2\x80\x94 %s left (%s/sec)", - formated_time_unit), - num_bytes_format, total_size_format, - formated_remaining_time, - transfer_rate_format); //FIXME Remove opaque hex - g_free (num_bytes_format); - g_free (total_size_format); - g_free (formated_remaining_time); - g_free (transfer_rate_format); - pf_progress_info_take_details (job->progress, s); - } - - pf_progress_info_update_progress (job->progress, transfer_info->num_bytes, total_size); -} - static GFile * get_unique_target_file (GFile *src, GFile *dest_dir, @@ -1727,7 +1421,7 @@ copy_move_directory (FilesFileOperationsCopyMoveJob *copy_job, /* Count the copied directory as a file */ transfer_info->num_files ++; - report_copy_progress (copy_job, source_info, transfer_info); + marlin_file_operations_copy_move_job_report_copy_progress (copy_job, source_info, transfer_info); if (debuting_files) { g_hash_table_replace (debuting_files, g_object_ref (*dest), GINT_TO_POINTER (create_dest)); @@ -2009,7 +1703,7 @@ copy_file_progress_callback (goffset current_num_bytes, if (new_size > 0) { pdata->transfer_info->num_bytes += new_size; pdata->last_size = current_num_bytes; - report_copy_progress (pdata->job, + marlin_file_operations_copy_move_job_report_copy_progress (pdata->job, pdata->source_info, pdata->transfer_info); } @@ -2281,7 +1975,7 @@ copy_move_file (FilesFileOperationsCopyMoveJob *copy_job, if (res) { transfer_info->num_files ++; - report_copy_progress (copy_job, source_info, transfer_info); + marlin_file_operations_copy_move_job_report_copy_progress (copy_job, source_info, transfer_info); if (debuting_files) { /*if (position) { @@ -2590,7 +2284,7 @@ copy_files (FilesFileOperationsCopyMoveJob *job, dest_fs_type = NULL; readonly_source_fs = FALSE; - report_copy_progress (job, source_info, transfer_info); + marlin_file_operations_copy_move_job_report_copy_progress (job, source_info, transfer_info); /* Query the source dir, not the file because if its a symlink we'll follow it */ source_dir = g_file_get_parent ((GFile *) job->files->data); @@ -2655,7 +2349,7 @@ copy_job (GTask *task, pf_progress_info_start (common->progress); scan_sources (job->files, &source_info, - (CountProgressCallback) report_copy_move_count_progress, + (CountProgressCallback) marlin_file_operations_copy_move_job_report_copy_move_count_progress, common); if (marlin_file_operations_common_job_aborted (common)) { goto aborted; @@ -2733,27 +2427,6 @@ marlin_file_operations_copy_finish (GAsyncResult *result, return g_task_propagate_boolean (G_TASK (result), error); } -static void -report_move_progress (FilesFileOperationsCopyMoveJob *move_job, int total, int left) -{ - FilesFileOperationsCommonJob *job = MARLIN_FILE_OPERATIONS_COMMON_JOB (move_job); - gchar *s, *dest_basename; - - dest_basename = files_file_utils_custom_basename_from_file (move_job->destination); - /// TRANSLATORS: '\"%s\"' is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed - /// '\"' is an escaped quoted mark. This may be replaced with another suitable character (escaped if necessary) - s = g_strdup_printf (_("Preparing to move to \"%s\""), dest_basename); - g_free (dest_basename); - - pf_progress_info_take_status (job->progress, s); - pf_progress_info_take_details (job->progress, - g_strdup_printf (ngettext ("Preparing to move %'d file", - "Preparing to move %'d files", - left), left)); - - pf_progress_info_pulse_progress (job->progress); -} - typedef struct { GFile *file; gboolean overwrite; @@ -3032,7 +2705,7 @@ move_files_prepare (FilesFileOperationsCopyMoveJob *job, total = left = g_list_length (job->files); - report_move_progress (job, total, left); + marlin_file_operations_copy_move_job_report_move_progress (job, total, left); i = 0; for (l = job->files; @@ -3050,7 +2723,7 @@ move_files_prepare (FilesFileOperationsCopyMoveJob *job, job->debuting_files, fallbacks, left); - report_move_progress (job, total, --left); + marlin_file_operations_copy_move_job_report_move_progress (job, total, --left); i++; } @@ -3075,7 +2748,7 @@ move_files (FilesFileOperationsCopyMoveJob *job, gboolean skipped_file; MoveFileCopyFallback *fallback; - report_copy_progress (job, source_info, transfer_info); + marlin_file_operations_copy_move_job_report_copy_progress (job, source_info, transfer_info); i = 0; for (l = fallbacks; @@ -3137,7 +2810,7 @@ move_job (GTask *task, fallback_files = get_files_from_fallbacks (fallbacks); scan_sources (fallback_files, &source_info, - (CountProgressCallback) report_copy_move_count_progress, + (CountProgressCallback) marlin_file_operations_copy_move_job_report_copy_move_count_progress, common); g_list_free (fallback_files); @@ -3212,26 +2885,6 @@ marlin_file_operations_move_finish (GAsyncResult *result, return g_task_propagate_boolean (G_TASK (result), error); } -static void -report_link_progress (FilesFileOperationsCopyMoveJob *link_job, int total, int left) -{ - FilesFileOperationsCommonJob *job = MARLIN_FILE_OPERATIONS_COMMON_JOB (link_job); - gchar *s; - gchar *dest_name = g_file_get_parse_name (link_job->destination); - /// TRANSLATORS: '\"%s\"' is a placeholder for the quoted basename of a file. It may change position but must not be translated or removed - /// '\"' is an escaped quoted mark. This may be replaced with another suitable character (escaped if necessary) - s = g_strdup_printf (_("Creating links in \"%s\""), dest_name); - g_free (dest_name); - - pf_progress_info_take_status (job->progress, s); - pf_progress_info_take_details (job->progress, - g_strdup_printf (ngettext ("Making link to %'d file", - "Making links to %'d files", - left), left)); - - pf_progress_info_update_progress (job->progress, left, total); -} - static void link_file (FilesFileOperationsCopyMoveJob *job, GFile *src, GFile *dest_dir, @@ -3400,7 +3053,7 @@ link_job (GTask *task, total = left = g_list_length (job->files); - report_link_progress (job, total, left); + marlin_file_operations_copy_move_job_report_link_progress (job, total, left); i = 0; for (l = job->files; @@ -3412,7 +3065,7 @@ link_job (GTask *task, link_file (job, src, job->destination, &dest_fs_type, job->debuting_files, left); - report_link_progress (job, total, --left); + marlin_file_operations_copy_move_job_report_link_progress (job, total, --left); i++; }