mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
FileManager: Set file op progress window's text based on the operation
This commit is contained in:
parent
0a62d517fd
commit
5090b1bdba
4 changed files with 47 additions and 6 deletions
|
@ -47,6 +47,7 @@
|
||||||
font_weight: "Bold"
|
font_weight: "Bold"
|
||||||
text_alignment: "CenterLeft"
|
text_alignment: "CenterLeft"
|
||||||
fixed_width: 80
|
fixed_width: 80
|
||||||
|
name: "current_file_action_label"
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::Label {
|
@GUI::Label {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FileOperationProgressWidget.h"
|
#include "FileOperationProgressWidget.h"
|
||||||
|
#include "FileUtils.h"
|
||||||
#include <Applications/FileManager/FileOperationProgressGML.h>
|
#include <Applications/FileManager/FileOperationProgressGML.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/Notifier.h>
|
#include <LibCore/Notifier.h>
|
||||||
|
@ -17,8 +18,9 @@
|
||||||
|
|
||||||
namespace FileManager {
|
namespace FileManager {
|
||||||
|
|
||||||
FileOperationProgressWidget::FileOperationProgressWidget(NonnullRefPtr<Core::File> helper_pipe)
|
FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation, NonnullRefPtr<Core::File> helper_pipe)
|
||||||
: m_helper_pipe(move(helper_pipe))
|
: m_operation(operation)
|
||||||
|
, m_helper_pipe(move(helper_pipe))
|
||||||
{
|
{
|
||||||
load_from_gml(file_operation_progress_gml);
|
load_from_gml(file_operation_progress_gml);
|
||||||
|
|
||||||
|
@ -39,6 +41,22 @@ FileOperationProgressWidget::FileOperationProgressWidget(NonnullRefPtr<Core::Fil
|
||||||
window()->close();
|
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 = Core::Notifier::construct(m_helper_pipe->fd(), Core::Notifier::Read);
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_ready_to_read = [this] {
|
||||||
auto line = m_helper_pipe->read_line();
|
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);
|
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));
|
estimated_time_label.set_text(estimate_time(bytes_done, total_byte_count));
|
||||||
|
|
||||||
if (total_byte_count) {
|
if (total_byte_count) {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "FileUtils.h"
|
||||||
#include <LibCore/ElapsedTimer.h>
|
#include <LibCore/ElapsedTimer.h>
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ public:
|
||||||
virtual ~FileOperationProgressWidget() override;
|
virtual ~FileOperationProgressWidget() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit FileOperationProgressWidget(NonnullRefPtr<Core::File> helper_pipe);
|
FileOperationProgressWidget(FileOperation, NonnullRefPtr<Core::File> helper_pipe);
|
||||||
|
|
||||||
void did_finish();
|
void did_finish();
|
||||||
void did_error(String message);
|
void did_error(String message);
|
||||||
|
@ -29,6 +30,7 @@ private:
|
||||||
String estimate_time(off_t bytes_done, off_t total_byte_count);
|
String estimate_time(off_t bytes_done, off_t total_byte_count);
|
||||||
Core::ElapsedTimer m_elapsed_timer;
|
Core::ElapsedTimer m_elapsed_timer;
|
||||||
|
|
||||||
|
FileOperation m_operation;
|
||||||
RefPtr<Core::Notifier> m_notifier;
|
RefPtr<Core::Notifier> m_notifier;
|
||||||
RefPtr<Core::File> m_helper_pipe;
|
RefPtr<Core::File> m_helper_pipe;
|
||||||
};
|
};
|
||||||
|
|
|
@ -133,8 +133,18 @@ void run_file_operation(FileOperation operation, Vector<String> const& sources,
|
||||||
auto pipe_input_file = Core::File::construct();
|
auto pipe_input_file = Core::File::construct();
|
||||||
pipe_input_file->open(pipe_fds[0], Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
|
pipe_input_file->open(pipe_fds[0], Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
|
||||||
|
|
||||||
window->set_title("Copying Files...");
|
switch (operation) {
|
||||||
window->set_main_widget<FileOperationProgressWidget>(pipe_input_file);
|
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);
|
window->resize(320, 190);
|
||||||
if (parent_window)
|
if (parent_window)
|
||||||
window->center_within(*parent_window);
|
window->center_within(*parent_window);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue