2020-12-30 15:31:36 +08:00
|
|
|
#include "setting-match.h"
|
2020-12-30 21:41:00 +08:00
|
|
|
#include "file-utils.h"
|
2020-12-30 15:31:36 +08:00
|
|
|
SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
xmlElement();
|
|
|
|
}
|
|
|
|
|
2020-12-30 21:41:00 +08:00
|
|
|
/**
|
|
|
|
* @brief SettingsMatch::startMatchApp
|
|
|
|
* 返回给页面
|
|
|
|
* @param source
|
|
|
|
* 获取的字符串
|
|
|
|
* @return
|
|
|
|
*/
|
2020-12-30 15:31:36 +08:00
|
|
|
QStringList SettingsMatch::startMatchApp(const QString &source){
|
|
|
|
m_sourceText=source;
|
|
|
|
// qDebug()<<m_sourceText;
|
|
|
|
QStringList settingList=matching();
|
|
|
|
return settingList;
|
|
|
|
}
|
|
|
|
|
2020-12-30 21:41:00 +08:00
|
|
|
/**
|
|
|
|
* @brief SettingsMatch::xmlElement
|
|
|
|
* 将xml文件内容读到内存
|
|
|
|
*/
|
2020-12-30 15:31:36 +08:00
|
|
|
void SettingsMatch::xmlElement(){
|
|
|
|
QString pinyinIndex;
|
|
|
|
QString ChineseIndex;
|
|
|
|
|
2020-12-30 17:23:03 +08:00
|
|
|
QFile file(QString::fromLocal8Bit("/usr/share/ukui-control-center/shell/res/search.xml"));
|
2020-12-30 15:31:36 +08:00
|
|
|
if (!file.open(QIODevice::ReadOnly)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QDomDocument doc;
|
|
|
|
doc.setContent(&file);
|
|
|
|
QDomElement root=doc.documentElement();
|
|
|
|
QDomNode node = root.previousSibling();
|
|
|
|
node=root.firstChild();
|
|
|
|
|
|
|
|
while(!node.isNull()){
|
|
|
|
QDomElement element=node.toElement();
|
|
|
|
QString key=element.attribute("name");;
|
|
|
|
m_chine_searchResult=m_chine_searchList.value(key);
|
|
|
|
m_pinyin_searchResult=m_pinyin_searchList.value(key);
|
|
|
|
QDomNodeList list=element.childNodes();
|
|
|
|
for(int i=0;i<list.count();++i){
|
|
|
|
QDomNode n=list.at(i);
|
|
|
|
|
|
|
|
if(n.nodeName()==QString::fromLocal8Bit("pinyinPlugin")){
|
|
|
|
pinyinIndex=n.toElement().text();
|
|
|
|
}
|
|
|
|
if(n.nodeName()==QString::fromLocal8Bit("pinyinfunc")){
|
2020-12-30 21:41:00 +08:00
|
|
|
pinyinIndex+=QString::fromLocal8Bit("/")+n.toElement().text();
|
2020-12-30 15:31:36 +08:00
|
|
|
m_pinyin_searchResult.append(pinyinIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(n.nodeName()==QString::fromLocal8Bit("ChinesePlugin")){
|
|
|
|
ChineseIndex=n.toElement().text();
|
|
|
|
}
|
|
|
|
if(n.nodeName()==QString::fromLocal8Bit("ChineseFunc")){
|
|
|
|
ChineseIndex+=QString::fromLocal8Bit("/")+n.toElement().text();
|
|
|
|
|
|
|
|
m_chine_searchResult.append(ChineseIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_pinyin_searchList.insert(key,m_pinyin_searchResult);
|
|
|
|
m_chine_searchList.insert(key,m_chine_searchResult);
|
|
|
|
|
|
|
|
node=node.nextSibling();
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
// qDebug()<<pinyin_searchlist;
|
|
|
|
// qDebug()<<chine_searchlist;
|
|
|
|
}
|
|
|
|
|
2020-12-30 21:41:00 +08:00
|
|
|
/**
|
|
|
|
* @brief SettingsMatch::matching
|
|
|
|
* 进行关键字匹配
|
|
|
|
* @return
|
|
|
|
*/
|
2020-12-30 15:31:36 +08:00
|
|
|
QStringList SettingsMatch::matching(){
|
|
|
|
QStringList returnresult;
|
|
|
|
QStringList regmatch;
|
|
|
|
QString key;
|
|
|
|
QMap<QString, QStringList>::const_iterator i;
|
|
|
|
for(i=m_chine_searchList.constBegin();i!=m_chine_searchList.constEnd();++i){
|
|
|
|
regmatch=*i;
|
|
|
|
key=i.key();
|
|
|
|
// qDebug()<<key;
|
|
|
|
for(int t=0; t<regmatch.size();t++)
|
|
|
|
{
|
|
|
|
QString str =regmatch.at(t);
|
|
|
|
if(str.contains(m_sourceText))
|
|
|
|
{
|
|
|
|
str=key+"/"+str;
|
|
|
|
returnresult.append(str);//中文名
|
2021-01-06 09:13:13 +08:00
|
|
|
continue;
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
2020-12-30 21:41:00 +08:00
|
|
|
QString pinyin=FileUtils::findMultiToneWords(str).at(0);// 中文转拼音
|
|
|
|
if(pinyin.contains(m_sourceText,Qt::CaseInsensitive)){
|
|
|
|
str=key+"/"+str;
|
|
|
|
returnresult.append(str);
|
2021-01-06 09:13:13 +08:00
|
|
|
continue;
|
2020-12-30 21:41:00 +08:00
|
|
|
}
|
|
|
|
QString shouzimu=FileUtils::findMultiToneWords(str).at(1);// 中文转首字母
|
|
|
|
if(shouzimu.contains(m_sourceText,Qt::CaseInsensitive)){
|
|
|
|
str=key+"/"+str;
|
|
|
|
returnresult.append(str);
|
|
|
|
}
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// qDebug()<<returnresult;
|
|
|
|
return returnresult;
|
|
|
|
}
|