FileManager: Use Core::Stream for FileOperationProgressWidget
This commit is contained in:
parent
dc5a318aa9
commit
1925bde3c0
Notes:
sideshowbarker
2024-07-17 17:28:27 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/1925bde3c0 Pull-request: https://github.com/SerenityOS/serenity/pull/13009
3 changed files with 16 additions and 11 deletions
|
@ -18,7 +18,7 @@
|
|||
|
||||
namespace FileManager {
|
||||
|
||||
FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation, NonnullRefPtr<Core::File> helper_pipe)
|
||||
FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation, NonnullOwnPtr<Core::Stream::BufferedFile> helper_pipe, int helper_pipe_fd)
|
||||
: m_operation(operation)
|
||||
, m_helper_pipe(move(helper_pipe))
|
||||
{
|
||||
|
@ -69,14 +69,17 @@ FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
m_notifier = Core::Notifier::construct(m_helper_pipe->fd(), Core::Notifier::Read);
|
||||
m_notifier = Core::Notifier::construct(helper_pipe_fd, Core::Notifier::Read);
|
||||
m_notifier->on_ready_to_read = [this] {
|
||||
auto line = m_helper_pipe->read_line();
|
||||
if (line.is_null()) {
|
||||
auto line_buffer = ByteBuffer::create_zeroed(1 * KiB).release_value_but_fixme_should_propagate_errors();
|
||||
auto line_length_or_error = m_helper_pipe->read_line(line_buffer.bytes());
|
||||
if (line_length_or_error.is_error() || line_length_or_error.value() == 0) {
|
||||
did_error("Read from pipe returned null."sv);
|
||||
return;
|
||||
}
|
||||
|
||||
StringView line { line_buffer.bytes().data(), line_length_or_error.value() };
|
||||
|
||||
auto parts = line.split_view(' ');
|
||||
VERIFY(!parts.is_empty());
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "FileUtils.h"
|
||||
#include <LibCore/ElapsedTimer.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
|
||||
namespace FileManager {
|
||||
|
@ -19,7 +20,8 @@ public:
|
|||
virtual ~FileOperationProgressWidget() override;
|
||||
|
||||
private:
|
||||
FileOperationProgressWidget(FileOperation, NonnullRefPtr<Core::File> helper_pipe);
|
||||
// FIXME: The helper_pipe_fd parameter is only needed because we can't get the fd from a Core::Stream.
|
||||
FileOperationProgressWidget(FileOperation, NonnullOwnPtr<Core::Stream::BufferedFile> helper_pipe, int helper_pipe_fd);
|
||||
|
||||
void did_finish();
|
||||
void did_error(StringView message);
|
||||
|
@ -32,6 +34,6 @@ private:
|
|||
|
||||
FileOperation m_operation;
|
||||
RefPtr<Core::Notifier> m_notifier;
|
||||
RefPtr<Core::File> m_helper_pipe;
|
||||
OwnPtr<Core::Stream::BufferedFile> m_helper_pipe;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "FileUtils.h"
|
||||
#include "FileOperationProgressWidget.h"
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <unistd.h>
|
||||
|
@ -87,9 +87,6 @@ ErrorOr<void> run_file_operation(FileOperation operation, Vector<String> const&
|
|||
auto window = TRY(GUI::Window::try_create());
|
||||
TRY(file_operation_windows.try_set(window));
|
||||
|
||||
auto pipe_input_file = TRY(Core::File::try_create());
|
||||
pipe_input_file->open(pipe_fds[0], Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
|
||||
|
||||
switch (operation) {
|
||||
case FileOperation::Copy:
|
||||
window->set_title("Copying Files...");
|
||||
|
@ -104,7 +101,10 @@ ErrorOr<void> run_file_operation(FileOperation operation, Vector<String> const&
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
(void)TRY(window->try_set_main_widget<FileOperationProgressWidget>(operation, pipe_input_file));
|
||||
auto pipe_input_file = TRY(Core::Stream::File::adopt_fd(pipe_fds[0], Core::Stream::OpenMode::Read));
|
||||
auto buffered_pipe = TRY(Core::Stream::BufferedFile::create(move(pipe_input_file)));
|
||||
|
||||
(void)TRY(window->try_set_main_widget<FileOperationProgressWidget>(operation, move(buffered_pipe), pipe_fds[0]));
|
||||
window->resize(320, 190);
|
||||
if (parent_window)
|
||||
window->center_within(*parent_window);
|
||||
|
|
Loading…
Add table
Reference in a new issue