feat(ukcc-plugin):add the ai index switch.

This commit is contained in:
JunjieBai 2024-04-18 14:55:34 +08:00 committed by iaom
parent 2e5899b674
commit 192c8831df
2 changed files with 43 additions and 0 deletions

View File

@ -28,6 +28,7 @@ static const QString WEB_ENGINE_KEY = QStringLiteral("webEngine");
static const QString CONTENT_FUZZY_SEARCH_KEY = QStringLiteral("contentFuzzySearch");
static const QString CONTENT_INDEX_ENABLE_KEY = QStringLiteral("contentIndexEnable");
static const QString CONTENT_INDEX_ENABLE_OCR_KEY = QStringLiteral("contentIndexEnableOcr");
static const QString AI_INDEX_ENABLE_KEY = QStringLiteral("aiIndexEnable");
Search::Search()
{
@ -110,6 +111,14 @@ QWidget *Search::pluginUi()
m_ocrSwitchBtn->setEnabled(false);
}
if (m_gsettings->keys().contains(AI_INDEX_ENABLE_KEY)) {
bool aiIndexOn = m_gsettings->get(AI_INDEX_ENABLE_KEY).toBool();
m_aiIndexBtn->setChecked(aiIndexOn);
} else {
m_aiIndexBtn->setEnabled(false);
}
if (m_gsettings->keys().contains(WEB_ENGINE_KEY)) {
//当前网页搜索的搜索引擎
QString engine = m_gsettings->get(WEB_ENGINE_KEY).toString();
@ -154,6 +163,11 @@ QWidget *Search::pluginUi()
m_ocrSwitchBtn->blockSignals(true);
m_ocrSwitchBtn->setChecked(m_gsettings->get(CONTENT_INDEX_ENABLE_OCR_KEY).toBool());
m_ocrSwitchBtn->blockSignals(false);
} else if (key == AI_INDEX_ENABLE_KEY) {
bool isAiIndexOn = m_gsettings->get(AI_INDEX_ENABLE_KEY).toBool();
m_aiIndexBtn->blockSignals(true);
m_aiIndexBtn->setChecked(isAiIndexOn);
m_aiIndexBtn->blockSignals(false);
} else if (key == WEB_ENGINE_KEY) {
QString engine = m_gsettings->get(WEB_ENGINE_KEY).toString();
m_webEngineFrame->mCombox->blockSignals(true);
@ -206,6 +220,11 @@ QWidget *Search::pluginUi()
}
}
});
connect(m_aiIndexBtn, &kdk::KSwitchButton::stateChanged, this, [ = ](bool checked) {
if (m_gsettings && m_gsettings->keys().contains(AI_INDEX_ENABLE_KEY)) {
m_gsettings->set(AI_INDEX_ENABLE_KEY, checked);
}
});
connect(m_webEngineFrame->mCombox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=] {
if (m_gsettings && m_gsettings->keys().contains(WEB_ENGINE_KEY)) {
m_gsettings->set(WEB_ENGINE_KEY, m_webEngineFrame->mCombox->currentData().toString());
@ -411,6 +430,24 @@ void Search::initUi()
m_mainLyt->addWidget(m_setFrame);
//Ai索引开关
m_aiIndexFrame = new QFrame(m_pluginWidget);
m_aiIndexFrame->setFrameShape(QFrame::Shape::Box);
m_aiIndexFrame->setFixedHeight(64);
m_aiIndexLyt = new QHBoxLayout(m_aiIndexFrame);
m_aiIndexLyt->setContentsMargins(16, 20, 16, 20);
m_aiIndexFrame->setLayout(m_aiIndexLyt);
m_aiIndexLabel = new QLabel(m_aiIndexFrame);
//~ contents_path /Search/Create ai index
m_aiIndexLabel->setText(tr("Create ai index"));
m_aiIndexLabel->setContentsMargins(0, 0, 0, 0);
m_aiIndexBtn = new kdk::KSwitchButton(m_aiIndexFrame);
m_aiIndexLyt->addWidget(m_aiIndexLabel);
m_aiIndexLyt->addStretch();
m_aiIndexLyt->addWidget(m_aiIndexBtn);
m_mainLyt->addWidget(m_aiIndexFrame);
//添加搜索目录部分ui
m_searchDirTitleLabel = new TitleLabel(m_pluginWidget);
//~ contents_path /Search/Search Folders

View File

@ -141,6 +141,12 @@ private:
QHBoxLayout *m_ocrSwitchLyt = nullptr;
kdk::KSwitchButton *m_ocrSwitchBtn = nullptr;
//AI索引开关设置
QFrame *m_aiIndexFrame = nullptr;
QHBoxLayout *m_aiIndexLyt = nullptr;
QLabel *m_aiIndexLabel = nullptr;
kdk::KSwitchButton *m_aiIndexBtn = nullptr;
//设置当前搜索目录
TitleLabel *m_searchDirTitleLabel = nullptr;
QLabel *m_searchDirDescLabel = nullptr;