Optimize the contructor and pluginUi function of search plugin for ukcc.

This commit is contained in:
JunjieBai 2022-11-09 11:31:35 +08:00
parent b95c481a9e
commit fde4d184b0
1 changed files with 14 additions and 7 deletions

View File

@ -12,11 +12,17 @@ Search::Search()
m_plugin_name = tr("Search"); m_plugin_name = tr("Search");
m_plugin_type = SEARCH_F; m_plugin_type = SEARCH_F;
initUi();
setupConnection();
m_dirSettings = new QSettings(QDir::homePath() + CONFIG_FILE, QSettings::NativeFormat, this); m_dirSettings = new QSettings(QDir::homePath() + CONFIG_FILE, QSettings::NativeFormat, this);
m_dirSettings->setIniCodec(QTextCodec::codecForName("UTF-8")); m_dirSettings->setIniCodec(QTextCodec::codecForName("UTF-8"));
initBlockDirsList(); initBlockDirsList();
const QByteArray id(UKUI_SEARCH_SCHEMAS);
if (QGSettings::isSchemaInstalled(id)) {
m_gsettings = new QGSettings(id, QByteArray(), this);
} else {
qCritical() << UKUI_SEARCH_SCHEMAS << " not installed!\n";
}
} }
QString Search::plugini18nName() QString Search::plugini18nName()
@ -31,11 +37,10 @@ int Search::pluginTypes()
QWidget *Search::pluginUi() QWidget *Search::pluginUi()
{ {
m_pluginWidget->setAttribute(Qt::WA_DeleteOnClose); initUi();
connect(m_addBlockDirWidget, &QPushButton::clicked, this, &Search::onBtnAddFolderClicked);
const QByteArray id(UKUI_SEARCH_SCHEMAS); if (m_gsettings) {
if (QGSettings::isSchemaInstalled(id)) {
m_gsettings = new QGSettings(id, QByteArray(), this);
//按钮状态初始化 //按钮状态初始化
if (m_gsettings->keys().contains(SEARCH_METHOD_KEY)) { if (m_gsettings->keys().contains(SEARCH_METHOD_KEY)) {
//当前是否使用索引搜索/暴力搜索 //当前是否使用索引搜索/暴力搜索
@ -76,10 +81,11 @@ QWidget *Search::pluginUi()
} }
}); });
} else { } else {
qCritical() << UKUI_SEARCH_SCHEMAS << " not installed!\n"; qCritical() << "Gsettings of the search plugin for ukcc is not initialized!";
m_searchMethodBtn->setEnabled(false); m_searchMethodBtn->setEnabled(false);
m_webEngineFrame->mCombox->setEnabled(false); m_webEngineFrame->mCombox->setEnabled(false);
} }
return m_pluginWidget; return m_pluginWidget;
} }
@ -114,6 +120,7 @@ bool Search::isEnable() const
void Search::initUi() void Search::initUi()
{ {
m_pluginWidget = new QWidget; m_pluginWidget = new QWidget;
m_pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
m_mainLyt = new QVBoxLayout(m_pluginWidget); m_mainLyt = new QVBoxLayout(m_pluginWidget);
m_pluginWidget->setLayout(m_mainLyt); m_pluginWidget->setLayout(m_mainLyt);