FileManager: Set file op progress window's text based on the operation

This commit is contained in:
Sam Atkins 2021-06-22 12:56:40 +01:00 committed by Andreas Kling
parent 0a62d517fd
commit 5090b1bdba
Notes: sideshowbarker 2024-07-18 08:34:29 +09:00
4 changed files with 47 additions and 6 deletions

View file

@ -47,6 +47,7 @@
font_weight: "Bold"
text_alignment: "CenterLeft"
fixed_width: 80
name: "current_file_action_label"
}
@GUI::Label {

View file

@ -5,6 +5,7 @@
*/
#include "FileOperationProgressWidget.h"
#include "FileUtils.h"
#include <Applications/FileManager/FileOperationProgressGML.h>
#include <LibCore/File.h>
#include <LibCore/Notifier.h>
@ -17,8 +18,9 @@
namespace FileManager {
FileOperationProgressWidget::FileOperationProgressWidget(NonnullRefPtr<Core::File> helper_pipe)
: m_helper_pipe(move(helper_pipe))
FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation, NonnullRefPtr<Core::File> helper_pipe)
: m_operation(operation)
, m_helper_pipe(move(helper_pipe))
{
load_from_gml(file_operation_progress_gml);
@ -39,6 +41,22 @@ FileOperationProgressWidget::FileOperationProgressWidget(NonnullRefPtr<Core::Fil
window()->close();
};
auto& files_copied_label = *find_descendant_of_type_named<GUI::Label>("files_copied_label");
auto& current_file_action_label = *find_descendant_of_type_named<GUI::Label>("current_file_action_label");
switch (m_operation) {
case FileOperation::Copy:
files_copied_label.set_text("Copying files...");
current_file_action_label.set_text("Copying: ");
break;
case FileOperation::Cut:
files_copied_label.set_text("Moving files...");
current_file_action_label.set_text("Moving: ");
break;
default:
VERIFY_NOT_REACHED();
}
m_notifier = Core::Notifier::construct(m_helper_pipe->fd(), Core::Notifier::Read);
m_notifier->on_ready_to_read = [this] {
auto line = m_helper_pipe->read_line();
@ -143,7 +161,17 @@ void FileOperationProgressWidget::did_progress(off_t bytes_done, off_t total_byt
current_file_label.set_text(current_filename);
files_copied_label.set_text(String::formatted("Copying file {} of {}", files_done, total_file_count));
switch (m_operation) {
case FileOperation::Copy:
files_copied_label.set_text(String::formatted("Copying file {} of {}", files_done, total_file_count));
break;
case FileOperation::Cut:
files_copied_label.set_text(String::formatted("Moving file {} of {}", files_done, total_file_count));
break;
default:
VERIFY_NOT_REACHED();
}
estimated_time_label.set_text(estimate_time(bytes_done, total_byte_count));
if (total_byte_count) {

View file

@ -6,6 +6,7 @@
#pragma once
#include "FileUtils.h"
#include <LibCore/ElapsedTimer.h>
#include <LibGUI/Widget.h>
@ -18,7 +19,7 @@ public:
virtual ~FileOperationProgressWidget() override;
private:
explicit FileOperationProgressWidget(NonnullRefPtr<Core::File> helper_pipe);
FileOperationProgressWidget(FileOperation, NonnullRefPtr<Core::File> helper_pipe);
void did_finish();
void did_error(String message);
@ -29,6 +30,7 @@ private:
String estimate_time(off_t bytes_done, off_t total_byte_count);
Core::ElapsedTimer m_elapsed_timer;
FileOperation m_operation;
RefPtr<Core::Notifier> m_notifier;
RefPtr<Core::File> m_helper_pipe;
};

View file

@ -133,8 +133,18 @@ void run_file_operation(FileOperation operation, Vector<String> const& sources,
auto pipe_input_file = Core::File::construct();
pipe_input_file->open(pipe_fds[0], Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
window->set_title("Copying Files...");
window->set_main_widget<FileOperationProgressWidget>(pipe_input_file);
switch (operation) {
case FileOperation::Copy:
window->set_title("Copying Files...");
break;
case FileOperation::Cut:
window->set_title("Moving Files...");
break;
default:
VERIFY_NOT_REACHED();
}
window->set_main_widget<FileOperationProgressWidget>(operation, pipe_input_file);
window->resize(320, 190);
if (parent_window)
window->center_within(*parent_window);