From 192c8831df24e1c9f465f0b8d92dcbd7ca75e035 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Thu, 18 Apr 2024 14:55:34 +0800 Subject: [PATCH] feat(ukcc-plugin):add the ai index switch. --- search-ukcc-plugin/search.cpp | 37 +++++++++++++++++++++++++++++++++++ search-ukcc-plugin/search.h | 6 ++++++ 2 files changed, 43 insertions(+) diff --git a/search-ukcc-plugin/search.cpp b/search-ukcc-plugin/search.cpp index 7b318e6..408cfea 100644 --- a/search-ukcc-plugin/search.cpp +++ b/search-ukcc-plugin/search.cpp @@ -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::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 diff --git a/search-ukcc-plugin/search.h b/search-ukcc-plugin/search.h index dfce015..2595950 100644 --- a/search-ukcc-plugin/search.h +++ b/search-ukcc-plugin/search.h @@ -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;