mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
114 lines
3.2 KiB
C++
114 lines
3.2 KiB
C++
/*
|
|
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
|
|
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "Settings.h"
|
|
#include "StringUtils.h"
|
|
#include <BrowserSettings/Defaults.h>
|
|
|
|
namespace Ladybird {
|
|
|
|
Settings::Settings()
|
|
: m_search_engine(WebView::default_search_engine())
|
|
{
|
|
m_qsettings = make<QSettings>("SerenityOS", "Ladybird", this);
|
|
|
|
auto default_search_engine = WebView::default_search_engine();
|
|
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(ak_string_from_qstring(search_engine_name));
|
|
|
|
if (search_engine.has_value())
|
|
m_search_engine = search_engine.release_value();
|
|
else
|
|
set_search_engine(move(default_search_engine));
|
|
}
|
|
|
|
Optional<QPoint> Settings::last_position()
|
|
{
|
|
if (m_qsettings->contains("last_position"))
|
|
return m_qsettings->value("last_position", QPoint()).toPoint();
|
|
return {};
|
|
}
|
|
|
|
void Settings::set_last_position(QPoint const& last_position)
|
|
{
|
|
m_qsettings->setValue("last_position", last_position);
|
|
}
|
|
|
|
QSize Settings::last_size()
|
|
{
|
|
return m_qsettings->value("last_size", QSize(800, 600)).toSize();
|
|
}
|
|
|
|
void Settings::set_last_size(QSize const& last_size)
|
|
{
|
|
m_qsettings->setValue("last_size", last_size);
|
|
}
|
|
|
|
bool Settings::is_maximized()
|
|
{
|
|
return m_qsettings->value("is_maximized", QVariant(false)).toBool();
|
|
}
|
|
|
|
void Settings::set_is_maximized(bool is_maximized)
|
|
{
|
|
m_qsettings->setValue("is_maximized", is_maximized);
|
|
}
|
|
|
|
void Settings::set_search_engine(WebView::SearchEngine search_engine)
|
|
{
|
|
m_qsettings->setValue("search_engine_name", qstring_from_ak_string(search_engine.name));
|
|
m_search_engine = move(search_engine);
|
|
}
|
|
|
|
Settings::EngineProvider Settings::autocomplete_engine()
|
|
{
|
|
EngineProvider engine_provider;
|
|
engine_provider.name = m_qsettings->value("autocomplete_engine_name", "Google").toString();
|
|
engine_provider.url = m_qsettings->value("autocomplete_engine", "https://www.google.com/complete/search?client=chrome&q={}").toString();
|
|
return engine_provider;
|
|
}
|
|
|
|
void Settings::set_autocomplete_engine(EngineProvider const& engine_provider)
|
|
{
|
|
m_qsettings->setValue("autocomplete_engine_name", engine_provider.name);
|
|
m_qsettings->setValue("autocomplete_engine", engine_provider.url);
|
|
}
|
|
|
|
QString Settings::new_tab_page()
|
|
{
|
|
static auto const default_new_tab_url = qstring_from_ak_string(Browser::default_new_tab_url);
|
|
return m_qsettings->value("new_tab_page", default_new_tab_url).toString();
|
|
}
|
|
|
|
void Settings::set_new_tab_page(QString const& page)
|
|
{
|
|
m_qsettings->setValue("new_tab_page", page);
|
|
}
|
|
|
|
bool Settings::enable_autocomplete()
|
|
{
|
|
return m_qsettings->value("enable_autocomplete", false).toBool();
|
|
}
|
|
|
|
void Settings::set_enable_autocomplete(bool enable)
|
|
{
|
|
m_qsettings->setValue("enable_autocomplete", enable);
|
|
}
|
|
|
|
bool Settings::enable_search()
|
|
{
|
|
return m_qsettings->value("enable_search", false).toBool();
|
|
}
|
|
|
|
void Settings::set_enable_search(bool enable)
|
|
{
|
|
m_qsettings->setValue("enable_search", enable);
|
|
}
|
|
|
|
}
|