diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp index 878da0b0cdc..140661be07c 100644 --- a/UI/Qt/BrowserWindow.cpp +++ b/UI/Qt/BrowserWindow.cpp @@ -596,7 +596,7 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, IsPopupWindow auto* about_action = new QAction("&About Ladybird", this); help_menu->addAction(about_action); QObject::connect(about_action, &QAction::triggered, this, [this] { - new_tab_from_url("about:version"sv, Web::HTML::ActivateTab::Yes); + new_tab_from_url(URL::about_version(), Web::HTML::ActivateTab::Yes); }); m_hamburger_menu->addSeparator(); @@ -609,7 +609,9 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, IsPopupWindow QObject::connect(quit_action, &QAction::triggered, this, &QMainWindow::close); QObject::connect(m_new_tab_action, &QAction::triggered, this, [this] { - auto& tab = new_tab_from_url(ak_url_from_qstring(Settings::the()->new_tab_page()), Web::HTML::ActivateTab::Yes); + auto url = ak_url_from_qstring(Settings::the()->new_tab_page()); + VERIFY(url.has_value()); + auto& tab = new_tab_from_url(url.release_value(), Web::HTML::ActivateTab::Yes); tab.set_url_is_hidden(true); tab.focus_location_editor(); }); diff --git a/UI/Qt/SettingsDialog.cpp b/UI/Qt/SettingsDialog.cpp index 67f6109073b..104a1ae96cd 100644 --- a/UI/Qt/SettingsDialog.cpp +++ b/UI/Qt/SettingsDialog.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -50,11 +51,11 @@ SettingsDialog::SettingsDialog(QMainWindow* window) m_new_tab_page->setText(Settings::the()->new_tab_page()); QObject::connect(m_new_tab_page, &QLineEdit::textChanged, this, [this] { auto url_string = ak_string_from_qstring(m_new_tab_page->text()); - m_new_tab_page->setStyleSheet(URL::URL(url_string).is_valid() ? "" : "border: 1px solid red;"); + m_new_tab_page->setStyleSheet(URL::Parser::basic_parse(url_string).has_value() ? "" : "border: 1px solid red;"); }); QObject::connect(m_new_tab_page, &QLineEdit::editingFinished, this, [this] { auto url_string = ak_string_from_qstring(m_new_tab_page->text()); - if (URL::URL(url_string).is_valid()) + if (URL::Parser::basic_parse(url_string).has_value()) Settings::the()->set_new_tab_page(m_new_tab_page->text()); }); QObject::connect(m_new_tab_page, &QLineEdit::returnPressed, this, [this] { diff --git a/UI/Qt/StringUtils.cpp b/UI/Qt/StringUtils.cpp index 0da9216b505..1f5f113b6ae 100644 --- a/UI/Qt/StringUtils.cpp +++ b/UI/Qt/StringUtils.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include AK::ByteString ak_byte_string_from_qstring(QString const& qstring) @@ -23,13 +24,13 @@ QString qstring_from_ak_string(StringView ak_string) return QString::fromUtf8(ak_string.characters_without_null_termination(), static_cast(ak_string.length())); } -URL::URL ak_url_from_qstring(QString const& qstring) +Optional ak_url_from_qstring(QString const& qstring) { auto utf8_data = qstring.toUtf8(); - return URL::URL(StringView(utf8_data.data(), utf8_data.size())); + return URL::Parser::basic_parse(StringView(utf8_data.data(), utf8_data.size())); } URL::URL ak_url_from_qurl(QUrl const& qurl) { - return ak_url_from_qstring(qurl.toString()); + return ak_url_from_qstring(qurl.toString()).value(); } diff --git a/UI/Qt/StringUtils.h b/UI/Qt/StringUtils.h index 7fa6c112f65..a0bd03bd538 100644 --- a/UI/Qt/StringUtils.h +++ b/UI/Qt/StringUtils.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -18,5 +19,5 @@ AK::ByteString ak_byte_string_from_qstring(QString const&); String ak_string_from_qstring(QString const&); QString qstring_from_ak_string(StringView); -URL::URL ak_url_from_qstring(QString const&); +Optional ak_url_from_qstring(QString const&); URL::URL ak_url_from_qurl(QUrl const&); diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp index a0d0a9a1e57..1e665697c61 100644 --- a/UI/Qt/Tab.cpp +++ b/UI/Qt/Tab.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -466,8 +467,10 @@ Tab::Tab(BrowserWindow* window, RefPtr parent_client, auto* search_selected_text_action = new QAction("&Search for ", this); search_selected_text_action->setIcon(load_icon_from_uri("resource://icons/16x16/find.png"sv)); QObject::connect(search_selected_text_action, &QAction::triggered, this, [this]() { - auto url = MUST(String::formatted(Settings::the()->search_engine().query_url, URL::percent_encode(*m_page_context_menu_search_text))); - m_window->new_tab_from_url(URL::URL(url), Web::HTML::ActivateTab::Yes); + auto url_string = MUST(String::formatted(Settings::the()->search_engine().query_url, URL::percent_encode(*m_page_context_menu_search_text))); + auto url = URL::Parser::basic_parse(url_string); + VERIFY(url.has_value()); + m_window->new_tab_from_url(url.release_value(), Web::HTML::ActivateTab::Yes); }); auto take_screenshot = [this](auto type) { diff --git a/UI/Qt/main.cpp b/UI/Qt/main.cpp index 92ef4b28052..940b2c7fbf7 100644 --- a/UI/Qt/main.cpp +++ b/UI/Qt/main.cpp @@ -73,7 +73,9 @@ ErrorOr serenity_main(Main::Arguments arguments) Core::EventLoopManager::install(*new WebView::EventLoopManagerQt); - auto app = Ladybird::Application::create(arguments, ak_url_from_qstring(Ladybird::Settings::the()->new_tab_page())); + auto url = ak_url_from_qstring(Ladybird::Settings::the()->new_tab_page()); + VERIFY(url.has_value()); + auto app = Ladybird::Application::create(arguments, url.release_value()); static_cast(Core::EventLoop::current().impl()).set_main_loop(); TRY(handle_attached_debugger());