1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:17:44 +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()) {

View file

@ -26,13 +26,13 @@ public:
~PDFViewerWidget() override = default;
void initialize_menubar(GUI::Window&);
void open_file(Core::File&);
void open_file(StringView path, NonnullOwnPtr<Core::Stream::File> file);
private:
PDFViewerWidget();
void initialize_toolbar(GUI::Toolbar&);
PDF::PDFErrorOr<void> try_open_file(Core::File&);
PDF::PDFErrorOr<void> try_open_file(StringView path, NonnullOwnPtr<Core::Stream::File> file);
RefPtr<PDFViewer> m_viewer;
RefPtr<SidebarWidget> m_sidebar;

View file

@ -47,10 +47,10 @@ ErrorOr<int> 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();