1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

PDFViewer: Port to Core::Stream::File

This commit is contained in:
Karol Kosek 2023-01-09 21:28:05 +01:00 committed by Sam Atkins
parent 7826cb2556
commit d4367f42ba
3 changed files with 11 additions and 11 deletions

View file

@ -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<Core::Stream::File> 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<void> PDFViewerWidget::try_open_file(Core::File& file)
PDF::PDFErrorOr<void> PDFViewerWidget::try_open_file(StringView path, NonnullOwnPtr<Core::Stream::File> 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()) {