mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-10 19:46:03 +00:00
PDFViewer: Display error dialog if necessary instead of crashing
This commit is contained in:
parent
1ef5071d1b
commit
e7b70a1435
Notes:
sideshowbarker
2024-07-18 12:21:38 +09:00
Author: https://github.com/mattco98
Commit: e7b70a1435
Pull-request: https://github.com/SerenityOS/serenity/pull/7675
Reviewed-by: https://github.com/FireFox317
Reviewed-by: https://github.com/alimpfard
1 changed files with 11 additions and 3 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/Menubar.h>
|
#include <LibGUI/Menubar.h>
|
||||||
|
#include <LibGUI/MessageBox.h>
|
||||||
#include <LibGUI/Splitter.h>
|
#include <LibGUI/Splitter.h>
|
||||||
#include <LibGUI/Toolbar.h>
|
#include <LibGUI/Toolbar.h>
|
||||||
#include <LibGUI/ToolbarContainer.h>
|
#include <LibGUI/ToolbarContainer.h>
|
||||||
|
@ -103,11 +104,18 @@ void PDFViewerWidget::open_file(const String& path)
|
||||||
{
|
{
|
||||||
window()->set_title(String::formatted("{} - PDF Viewer", path));
|
window()->set_title(String::formatted("{} - PDF Viewer", path));
|
||||||
auto file_result = Core::File::open(path, Core::OpenMode::ReadOnly);
|
auto file_result = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||||
VERIFY(!file_result.is_error());
|
if (file_result.is_error()) {
|
||||||
|
GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't open file: {}", path));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_buffer = file_result.value()->read_all();
|
m_buffer = file_result.value()->read_all();
|
||||||
auto document = PDF::Document::create(m_buffer);
|
auto document = PDF::Document::create(m_buffer);
|
||||||
// FIXME: Show error dialog if the Document is invalid
|
if (!document) {
|
||||||
VERIFY(document);
|
GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't load PDF: {}", path));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_viewer->set_document(document);
|
m_viewer->set_document(document);
|
||||||
m_total_page_label->set_text(String::formatted("of {}", document->get_page_count()));
|
m_total_page_label->set_text(String::formatted("of {}", document->get_page_count()));
|
||||||
m_total_page_label->set_fixed_width(30);
|
m_total_page_label->set_fixed_width(30);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue