1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

FileManager+FileOperation: Show byte progress of current file

What I meant for the GUI progress bars to show:

- Bytes copied of the current file
- Files copied of the total set

What it actually showed:

- Bytes copied of the total bytes
- Files copied of the total set

This patch fixes it by showing byte progress of the current file
instead of byte progress of total bytes.
This commit is contained in:
Andreas Kling 2021-04-13 10:08:59 +02:00
parent 1ca22b46f9
commit bf1ef6533c
Notes: sideshowbarker 2024-07-18 20:26:22 +09:00
3 changed files with 12 additions and 7 deletions

View file

@ -64,13 +64,15 @@ FileOperationProgressWidget::FileOperationProgressWidget(NonnullRefPtr<Core::Fil
}
if (parts[0] == "PROGRESS"sv) {
VERIFY(parts.size() >= 6);
VERIFY(parts.size() >= 8);
did_progress(
parts[3].to_uint().value_or(0),
parts[4].to_uint().value_or(0),
parts[1].to_uint().value_or(0),
parts[2].to_uint().value_or(0),
parts[5]);
parts[5].to_uint().value_or(0),
parts[6].to_uint().value_or(0),
parts[7]);
}
};
}
@ -94,7 +96,7 @@ void FileOperationProgressWidget::did_error()
window()->close();
}
void FileOperationProgressWidget::did_progress(off_t bytes_done, off_t total_byte_count, size_t files_done, size_t total_file_count, const StringView& current_file_name)
void FileOperationProgressWidget::did_progress([[maybe_unused]] off_t bytes_done, [[maybe_unused]] off_t total_byte_count, size_t files_done, size_t total_file_count, off_t current_file_done, off_t current_file_size, const StringView& current_file_name)
{
auto& current_file_label = *find_descendant_of_type_named<GUI::Label>("current_file_label");
auto& current_file_progress_bar = *find_descendant_of_type_named<GUI::ProgressBar>("current_file_progress_bar");
@ -102,8 +104,8 @@ void FileOperationProgressWidget::did_progress(off_t bytes_done, off_t total_byt
auto& overall_progress_bar = *find_descendant_of_type_named<GUI::ProgressBar>("overall_progress_bar");
current_file_label.set_text(current_file_name);
current_file_progress_bar.set_max(total_byte_count);
current_file_progress_bar.set_value(bytes_done);
current_file_progress_bar.set_max(current_file_size);
current_file_progress_bar.set_value(current_file_done);
overall_progress_label.set_text(String::formatted("{} of {}", files_done, total_file_count));
overall_progress_bar.set_max(total_file_count);

View file

@ -41,7 +41,7 @@ private:
void did_finish();
void did_error();
void did_progress(off_t bytes_done, off_t total_byte_count, size_t files_done, size_t total_file_count, const StringView& current_file_name);
void did_progress(off_t bytes_done, off_t total_byte_count, size_t files_done, size_t total_file_count, off_t current_file_done, off_t current_file_size, const StringView& current_file_name);
void close_pipe();

View file

@ -120,8 +120,9 @@ int perform_copy(const String& source, const String& destination)
for (size_t i = 0; i < items.size(); ++i) {
auto& item = items[i];
off_t item_done = 0;
auto print_progress = [&] {
outln("PROGRESS {} {} {} {} {}", i, items.size(), bytes_copied_so_far, total_bytes_to_copy, item.source);
outln("PROGRESS {} {} {} {} {} {} {}", i, items.size(), bytes_copied_so_far, total_bytes_to_copy, item_done, item.size, item.source);
};
if (item.type == WorkItem::Type::CreateDirectory) {
outln("MKDIR {}", item.destination);
@ -146,6 +147,7 @@ int perform_copy(const String& source, const String& destination)
auto& destination_file = *destination_file_or_error.value();
while (true) {
print_progress();
auto buffer = source_file.read(65536);
if (buffer.is_null())
break;
@ -153,6 +155,7 @@ int perform_copy(const String& source, const String& destination)
warnln("Failed to write to destination file: {}", destination_file.error_string());
return 1;
}
item_done += buffer.size();
bytes_copied_so_far += buffer.size();
print_progress();
// FIXME: Remove this once the kernel is smart enough to schedule other threads