mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-16 12:52:46 +00:00
Ladybird/Qt: Replace the QString-from-AK helpers with a single method
There's no need for 2 overloads for String and DeprecatedString, we can just use a StringView. This also avoids some cases of needlessly allocating a DeprecatedString from a StringView when calling this method.
This commit is contained in:
parent
4d5d282e6a
commit
1aedb0ae5a
|
@ -294,8 +294,8 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
|
|||
|
||||
auto* user_agent_group = new QActionGroup(this);
|
||||
|
||||
auto add_user_agent = [this, &user_agent_group, &spoof_user_agent_menu](auto const& name, auto const& user_agent) {
|
||||
auto* action = new QAction(qstring_from_ak_deprecated_string(name), this);
|
||||
auto add_user_agent = [this, &user_agent_group, &spoof_user_agent_menu](auto name, auto const& user_agent) {
|
||||
auto* action = new QAction(qstring_from_ak_string(name), this);
|
||||
action->setCheckable(true);
|
||||
user_agent_group->addAction(action);
|
||||
spoof_user_agent_menu->addAction(action);
|
||||
|
@ -306,10 +306,10 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
|
|||
return action;
|
||||
};
|
||||
|
||||
auto* disable_spoofing = add_user_agent("Disabled", Web::default_user_agent);
|
||||
auto* disable_spoofing = add_user_agent("Disabled"sv, Web::default_user_agent);
|
||||
disable_spoofing->setChecked(true);
|
||||
for (auto const& user_agent : WebView::user_agents)
|
||||
add_user_agent(user_agent.key.to_deprecated_string(), user_agent.value.to_deprecated_string());
|
||||
add_user_agent(user_agent.key, user_agent.value.to_deprecated_string());
|
||||
|
||||
auto* custom_user_agent_action = new QAction("Custom...", this);
|
||||
custom_user_agent_action->setCheckable(true);
|
||||
|
@ -413,7 +413,7 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
|
|||
});
|
||||
|
||||
for (size_t i = 0; i < initial_urls.size(); ++i) {
|
||||
auto url_string = qstring_from_ak_deprecated_string(initial_urls[i].serialize());
|
||||
auto url_string = qstring_from_ak_string(initial_urls[i].serialize());
|
||||
new_tab(url_string, (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No);
|
||||
}
|
||||
|
||||
|
@ -480,7 +480,7 @@ Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab)
|
|||
};
|
||||
|
||||
tab_ptr->view().on_tab_open_request = [this](auto url, auto activate_tab) {
|
||||
auto& tab = new_tab(qstring_from_ak_deprecated_string(url.to_deprecated_string()), activate_tab);
|
||||
auto& tab = new_tab(qstring_from_ak_string(url.to_deprecated_string()), activate_tab);
|
||||
return tab.view().handle();
|
||||
};
|
||||
|
||||
|
@ -665,7 +665,7 @@ void BrowserWindow::copy_selected_text()
|
|||
auto text = m_current_tab->view().selected_text();
|
||||
|
||||
auto* clipboard = QGuiApplication::clipboard();
|
||||
clipboard->setText(qstring_from_ak_deprecated_string(text));
|
||||
clipboard->setText(qstring_from_ak_string(text));
|
||||
}
|
||||
|
||||
void BrowserWindow::resizeEvent(QResizeEvent* event)
|
||||
|
|
|
@ -37,7 +37,7 @@ LocationEdit::LocationEdit(QWidget* parent)
|
|||
auto query = MUST(ak_string_from_qstring(text()));
|
||||
|
||||
if (auto url = WebView::sanitize_url(query, search_engine_url); url.has_value())
|
||||
setText(qstring_from_ak_deprecated_string(url->serialize()));
|
||||
setText(qstring_from_ak_string(url->serialize()));
|
||||
});
|
||||
|
||||
connect(this, &QLineEdit::textEdited, [this] {
|
||||
|
|
|
@ -17,7 +17,7 @@ Settings::Settings()
|
|||
m_qsettings = make<QSettings>("SerenityOS", "Ladybird", this);
|
||||
|
||||
auto default_search_engine = WebView::default_search_engine();
|
||||
auto default_search_engine_name = qstring_from_ak_deprecated_string(default_search_engine.name);
|
||||
auto default_search_engine_name = qstring_from_ak_string(default_search_engine.name);
|
||||
|
||||
auto search_engine_name = m_qsettings->value("search_engine_name", default_search_engine_name).toString();
|
||||
auto search_engine = WebView::find_search_engine_by_name(MUST(ak_string_from_qstring(search_engine_name)));
|
||||
|
@ -62,7 +62,7 @@ void Settings::set_is_maximized(bool is_maximized)
|
|||
|
||||
void Settings::set_search_engine(WebView::SearchEngine search_engine)
|
||||
{
|
||||
m_qsettings->setValue("search_engine_name", qstring_from_ak_deprecated_string(search_engine.name));
|
||||
m_qsettings->setValue("search_engine_name", qstring_from_ak_string(search_engine.name));
|
||||
m_search_engine = move(search_engine);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
|
|||
m_enable_search->setChecked(Settings::the()->enable_search());
|
||||
|
||||
m_search_engine_dropdown = make<QPushButton>(this);
|
||||
m_search_engine_dropdown->setText(qstring_from_ak_deprecated_string(Settings::the()->search_engine().name));
|
||||
m_search_engine_dropdown->setText(qstring_from_ak_string(Settings::the()->search_engine().name));
|
||||
m_search_engine_dropdown->setMaximumWidth(200);
|
||||
|
||||
m_enable_autocomplete = make<QCheckBox>(this);
|
||||
|
@ -76,7 +76,7 @@ void SettingsDialog::setup_search_engines()
|
|||
|
||||
QMenu* search_engine_menu = new QMenu(this);
|
||||
for (auto const& search_engine : WebView::search_engines()) {
|
||||
auto search_engine_name = qstring_from_ak_deprecated_string(search_engine.name);
|
||||
auto search_engine_name = qstring_from_ak_string(search_engine.name);
|
||||
QAction* action = new QAction(search_engine_name, this);
|
||||
|
||||
connect(action, &QAction::triggered, this, [&, search_engine_name = std::move(search_engine_name)]() {
|
||||
|
|
|
@ -16,13 +16,7 @@ ErrorOr<String> ak_string_from_qstring(QString const& qstring)
|
|||
return String::from_utf8(StringView(qstring.toUtf8().data(), qstring.size()));
|
||||
}
|
||||
|
||||
QString qstring_from_ak_deprecated_string(AK::DeprecatedString const& ak_deprecated_string)
|
||||
QString qstring_from_ak_string(StringView ak_string)
|
||||
{
|
||||
return QString::fromUtf8(ak_deprecated_string.characters(), ak_deprecated_string.length());
|
||||
}
|
||||
|
||||
QString qstring_from_ak_string(String const& ak_string)
|
||||
{
|
||||
auto view = ak_string.bytes_as_string_view();
|
||||
return QString::fromUtf8(view.characters_without_null_termination(), view.length());
|
||||
return QString::fromUtf8(ak_string.characters_without_null_termination(), static_cast<qsizetype>(ak_string.length()));
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Error.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <QString>
|
||||
|
||||
AK::DeprecatedString ak_deprecated_string_from_qstring(QString const&);
|
||||
ErrorOr<String> ak_string_from_qstring(QString const&);
|
||||
QString qstring_from_ak_deprecated_string(AK::DeprecatedString const&);
|
||||
QString qstring_from_ak_string(String const&);
|
||||
QString qstring_from_ak_string(StringView);
|
||||
|
|
|
@ -107,7 +107,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
|||
};
|
||||
|
||||
view().on_link_hover = [this](auto const& url) {
|
||||
m_hover_label->setText(qstring_from_ak_deprecated_string(url.to_deprecated_string()));
|
||||
m_hover_label->setText(qstring_from_ak_string(url.to_deprecated_string()));
|
||||
update_hover_label();
|
||||
m_hover_label->show();
|
||||
};
|
||||
|
@ -148,7 +148,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
|||
QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &Tab::location_edit_return_pressed);
|
||||
|
||||
view().on_title_change = [this](auto const& title) {
|
||||
m_title = qstring_from_ak_deprecated_string(title);
|
||||
m_title = qstring_from_ak_string(title);
|
||||
m_history.update_title(title);
|
||||
|
||||
emit title_changed(tab_index(), m_title);
|
||||
|
@ -628,7 +628,7 @@ void Tab::open_link_in_new_tab(URL const& url)
|
|||
void Tab::copy_link_url(URL const& url)
|
||||
{
|
||||
auto* clipboard = QGuiApplication::clipboard();
|
||||
clipboard->setText(qstring_from_ak_deprecated_string(url.to_deprecated_string()));
|
||||
clipboard->setText(qstring_from_ak_string(url.to_deprecated_string()));
|
||||
}
|
||||
|
||||
void Tab::location_edit_return_pressed()
|
||||
|
|
|
@ -114,10 +114,10 @@ WebContentView::WebContentView(WebContentOptions const& web_content_options, Str
|
|||
update_cursor(cursor);
|
||||
};
|
||||
|
||||
on_enter_tooltip_area = [this](auto position, auto tooltip) {
|
||||
on_enter_tooltip_area = [this](auto position, auto const& tooltip) {
|
||||
QToolTip::showText(
|
||||
mapToGlobal(QPoint(position.x(), position.y())),
|
||||
qstring_from_ak_deprecated_string(tooltip),
|
||||
qstring_from_ak_string(tooltip),
|
||||
this);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue