From d4367f42ba53c4359fbf7286fd53c9ac1eed1994 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Mon, 9 Jan 2023 21:28:05 +0100 Subject: PDFViewer: Port to Core::Stream::File --- Userland/Applications/PDFViewer/PDFViewerWidget.cpp | 14 +++++++------- Userland/Applications/PDFViewer/PDFViewerWidget.h | 4 ++-- Userland/Applications/PDFViewer/main.cpp | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'Userland') diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index 6be1475080..d0e5063341 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -211,9 +211,9 @@ void PDFViewerWidget::initialize_menubar(GUI::Window& window) { auto& file_menu = window.add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { - auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(&window); + auto response = FileSystemAccessClient::Client::the().open_file(&window); if (!response.is_error()) - open_file(*response.value()); + open_file(response.value().filename(), response.value().release_stream()); })); file_menu.add_separator(); file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { @@ -349,9 +349,9 @@ void PDFViewerWidget::initialize_toolbar(GUI::Toolbar& toolbar) m_show_images->on_checked = [&](auto checked) { m_viewer->set_show_images(checked); }; } -void PDFViewerWidget::open_file(Core::File& file) +void PDFViewerWidget::open_file(StringView path, NonnullOwnPtr file) { - auto maybe_error = try_open_file(file); + auto maybe_error = try_open_file(path, move(file)); if (maybe_error.is_error()) { auto error = maybe_error.release_error(); warnln("{}", error.message()); @@ -360,11 +360,11 @@ void PDFViewerWidget::open_file(Core::File& file) } } -PDF::PDFErrorOr PDFViewerWidget::try_open_file(Core::File& file) +PDF::PDFErrorOr PDFViewerWidget::try_open_file(StringView path, NonnullOwnPtr file) { - window()->set_title(DeprecatedString::formatted("{} - PDF Viewer", file.filename())); + window()->set_title(DeprecatedString::formatted("{} - PDF Viewer", path)); - m_buffer = file.read_all(); + m_buffer = TRY(file->read_until_eof()); auto document = TRY(PDF::Document::create(m_buffer)); if (auto sh = document->security_handler(); sh && !sh->has_user_password()) { diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.h b/Userland/Applications/PDFViewer/PDFViewerWidget.h index 785896abe4..cd1171f259 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.h +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.h @@ -26,13 +26,13 @@ public: ~PDFViewerWidget() override = default; void initialize_menubar(GUI::Window&); - void open_file(Core::File&); + void open_file(StringView path, NonnullOwnPtr file); private: PDFViewerWidget(); void initialize_toolbar(GUI::Toolbar&); - PDF::PDFErrorOr try_open_file(Core::File&); + PDF::PDFErrorOr try_open_file(StringView path, NonnullOwnPtr file); RefPtr m_viewer; RefPtr m_sidebar; diff --git a/Userland/Applications/PDFViewer/main.cpp b/Userland/Applications/PDFViewer/main.cpp index ba799e8820..748ea0a7e8 100644 --- a/Userland/Applications/PDFViewer/main.cpp +++ b/Userland/Applications/PDFViewer/main.cpp @@ -47,10 +47,10 @@ ErrorOr serenity_main(Main::Arguments arguments) window->set_icon(app_icon.bitmap_for_size(16)); if (file_path) { - auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, file_path); + auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, file_path); if (response.is_error()) return 1; - pdf_viewer_widget->open_file(*response.value()); + pdf_viewer_widget->open_file(response.value().filename(), response.value().release_stream()); } return app->exec(); -- cgit v1.2.3