summaryrefslogtreecommitdiff
path: root/archived/projt-launcher/launcher/ui/setupwizard/SearchWizardPage.cpp
blob: 573c7844f7dc8f88964ee0d11b4b9bc1a05b66e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2026 Project Tick
// SPDX-FileContributor: Project Tick Team

#include "SearchWizardPage.h"

#include <QComboBox>
#include <QLabel>
#include <QVBoxLayout>

#include "Application.h"
#include "BuildConfig.h"
#include "ui/widgets/HubSearchProvider.h"

SearchWizardPage::SearchWizardPage(QWidget* parent) : BaseWizardPage(parent)
{
	setObjectName(QStringLiteral("searchPage"));

	auto* layout = new QVBoxLayout(this);
	layout->setContentsMargins(0, 0, 0, 0);

	m_descriptionLabel = new QLabel(this);
	m_descriptionLabel->setWordWrap(true);

	m_providerCombo = new QComboBox(this);
	for (const auto& provider : hubSearchProviders())
	{
		m_providerCombo->addItem(provider.displayName, provider.id);
	}

	const QString currentProvider =
		APPLICATION->settings() ? normalizedHubSearchProviderId(APPLICATION->settings()->get("HubSearchEngine").toString())
								: defaultHubSearchProviderId();
	const int currentIndex = m_providerCombo->findData(currentProvider);
	m_providerCombo->setCurrentIndex(currentIndex >= 0 ? currentIndex : 0);

	layout->addWidget(m_descriptionLabel);
	layout->addWidget(m_providerCombo);
	layout->addStretch(1);

	retranslate();
}

SearchWizardPage::~SearchWizardPage() = default;

bool SearchWizardPage::validatePage()
{
	if (APPLICATION->settings())
	{
		APPLICATION->settings()->set("HubSearchEngine", m_providerCombo->currentData().toString());
	}
	return true;
}

void SearchWizardPage::retranslate()
{
	setTitle(tr("Search"));
	setSubTitle(tr("Choose the default search engine for Launcher Hub."));
	m_descriptionLabel->setText(tr("When you type plain text like \"How to install Linux?\" into the Hub address bar, %1 will search with this provider by default.")
								 .arg(BuildConfig.LAUNCHER_DISPLAYNAME));
}