|
@@ -41,15 +41,10 @@ void PDFViewerWidget::initialize_menubar(GUI::Window& window)
|
|
{
|
|
{
|
|
auto& file_menu = window.add_menu("&File");
|
|
auto& file_menu = window.add_menu("&File");
|
|
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
|
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
|
- auto response = FileSystemAccessClient::Client::the().open_file(window.window_id());
|
|
|
|
-
|
|
|
|
- if (response.error != 0) {
|
|
|
|
- if (response.error != -1)
|
|
|
|
- GUI::MessageBox::show_error(&window, String::formatted("Opening \"{}\" failed: {}", *response.chosen_file, strerror(response.error)));
|
|
|
|
|
|
+ auto response = FileSystemAccessClient::Client::the().try_open_file(&window);
|
|
|
|
+ if (response.is_error())
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
-
|
|
|
|
- open_file(*response.fd, *response.chosen_file);
|
|
|
|
|
|
+ open_file(*response.value());
|
|
}));
|
|
}));
|
|
file_menu.add_separator();
|
|
file_menu.add_separator();
|
|
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
|
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
|
@@ -151,19 +146,14 @@ void PDFViewerWidget::create_toolbar()
|
|
toolbar.add_action(*m_rotate_clockwise_action);
|
|
toolbar.add_action(*m_rotate_clockwise_action);
|
|
}
|
|
}
|
|
|
|
|
|
-void PDFViewerWidget::open_file(int fd, String const& path)
|
|
|
|
|
|
+void PDFViewerWidget::open_file(Core::File& file)
|
|
{
|
|
{
|
|
- auto file = Core::File::construct();
|
|
|
|
- if (!file->open(fd, Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes) && file->error() != ENOENT) {
|
|
|
|
- GUI::MessageBox::show(window(), String::formatted("Opening \"{}\" failed: {}", path, strerror(errno)), "Error", GUI::MessageBox::Type::Error);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- window()->set_title(String::formatted("{} - PDF Viewer", path));
|
|
|
|
|
|
+ window()->set_title(String::formatted("{} - PDF Viewer", file.filename()));
|
|
|
|
|
|
- m_buffer = file->read_all();
|
|
|
|
|
|
+ m_buffer = file.read_all();
|
|
auto document = PDF::Document::create(m_buffer);
|
|
auto document = PDF::Document::create(m_buffer);
|
|
if (!document) {
|
|
if (!document) {
|
|
- GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't load PDF: {}", path));
|
|
|
|
|
|
+ GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't load PDF: {}", file.filename()));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|