forked from openkylin/ukui-search
更新搜索服务接口,完善应用搜索和文件搜索机制
This commit is contained in:
parent
bf22f0e150
commit
d354773177
|
@ -22,7 +22,7 @@ namespace UkuiSearch {
|
|||
return argument;
|
||||
}
|
||||
|
||||
QDBusArgument &operator << (QDBusArgument &argument, const PropertyMap &appPropertyInfo)
|
||||
QDBusArgument &operator << (QDBusArgument &argument, const ApplicationPropertyMap &appPropertyInfo)
|
||||
{
|
||||
argument.beginMap(/*qMetaTypeId<ApplicationProperty::Property>()*/QVariant::Int, qMetaTypeId<QDBusVariant>());
|
||||
for (auto i = appPropertyInfo.constBegin(); i != appPropertyInfo.constEnd(); ++i) {
|
||||
|
@ -35,7 +35,7 @@ namespace UkuiSearch {
|
|||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument &operator >> (const QDBusArgument &argument, PropertyMap &appPropertyInfo)
|
||||
const QDBusArgument &operator >> (const QDBusArgument &argument, ApplicationPropertyMap &appPropertyInfo)
|
||||
{
|
||||
argument.beginMap();
|
||||
while (!argument.atEnd()) {
|
||||
|
@ -52,7 +52,7 @@ namespace UkuiSearch {
|
|||
|
||||
QDBusArgument &operator << (QDBusArgument &argument, const ApplicationInfoMap &appInfo)
|
||||
{
|
||||
argument.beginMap(QVariant::String, qMetaTypeId<PropertyMap>());
|
||||
argument.beginMap(QVariant::String, qMetaTypeId<ApplicationPropertyMap>());
|
||||
for (auto i = appInfo.constBegin(); i != appInfo.constEnd(); ++i) {
|
||||
argument.beginMapEntry();
|
||||
argument << i.key() << i.value();
|
||||
|
@ -67,7 +67,7 @@ namespace UkuiSearch {
|
|||
argument.beginMap();
|
||||
while (!argument.atEnd()) {
|
||||
QString key;
|
||||
PropertyMap value;
|
||||
ApplicationPropertyMap value;
|
||||
argument.beginMapEntry();
|
||||
argument >> key >> value;
|
||||
argument.endMapEntry();
|
||||
|
|
|
@ -25,8 +25,8 @@ static AppInfoTable *global_intance = nullptr;
|
|||
AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent), q(parent), m_database(new QSqlDatabase())
|
||||
{
|
||||
//dbus接收数据库信号
|
||||
qRegisterMetaType<PropertyMap>("PropertyMap");
|
||||
qDBusRegisterMetaType<PropertyMap>();
|
||||
qRegisterMetaType<ApplicationPropertyMap>("ApplicationPropertyMap");
|
||||
qDBusRegisterMetaType<ApplicationPropertyMap>();
|
||||
|
||||
qRegisterMetaType<ApplicationInfoMap>("ApplicationInfoMap");
|
||||
qDBusRegisterMetaType<ApplicationInfoMap>();
|
||||
|
@ -352,13 +352,16 @@ AppInfoTable::AppInfoTable(QObject *parent) : QObject(parent), d(new AppInfoTabl
|
|||
{
|
||||
}
|
||||
|
||||
bool AppInfoTable::query(PropertyMap &propertyMap, const QString &desktopFile, Properties properties)
|
||||
bool AppInfoTable::query(ApplicationPropertyMap &propertyMap, const QString &desktopFile, ApplicationProperties properties)
|
||||
{
|
||||
QString field;
|
||||
for(const ApplicationProperty::Property &pro : properties) {
|
||||
field.append(ApplicationPropertyHelper(pro).dataBaseField() + ",");
|
||||
}
|
||||
field.remove(field.length() - 1, 1);
|
||||
if(field.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
QSqlQuery query(*d->m_database);
|
||||
query.setForwardOnly(true);
|
||||
query.prepare(QString("SELECT %0 FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFile").arg(field));
|
||||
|
@ -375,12 +378,18 @@ bool AppInfoTable::query(PropertyMap &propertyMap, const QString &desktopFile, P
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties)
|
||||
bool AppInfoTable::query(ApplicationInfoMap &infoMap, ApplicationProperties properties)
|
||||
{
|
||||
QString field(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField());
|
||||
QString field;
|
||||
for(const ApplicationProperty::Property &pro : properties) {
|
||||
field.append("," + ApplicationPropertyHelper(pro).dataBaseField());
|
||||
field.append(ApplicationPropertyHelper(pro).dataBaseField() + ",");
|
||||
}
|
||||
if(!properties.contains(ApplicationProperty::Property::DesktopFilePath)) {
|
||||
field.append(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField());
|
||||
} else if(!field.isEmpty()) {
|
||||
field.remove(field.length() - 1, 1);
|
||||
}
|
||||
|
||||
QString sql = QString("SELECT %0 FROM APPINFO").arg(field);
|
||||
QSqlQuery query(*d->m_database);
|
||||
query.setForwardOnly(true);
|
||||
|
@ -390,20 +399,26 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties)
|
|||
return false;
|
||||
}
|
||||
while (query.next()) {
|
||||
PropertyMap propertyMap;
|
||||
for(int i = 0; i< properties.size(); i++) {
|
||||
propertyMap.insert(properties.at(i), query.value(i + 1));
|
||||
ApplicationPropertyMap propertyMap;
|
||||
for(const ApplicationProperty::Property &pro : properties) {
|
||||
propertyMap.insert(pro, query.value(ApplicationPropertyHelper(pro).dataBaseField()));
|
||||
|
||||
}
|
||||
infoMap.insert(query.value(0).toString(), propertyMap);
|
||||
infoMap.insert(query.value(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField()).toString(), propertyMap);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, PropertyMap restrictions)
|
||||
bool AppInfoTable::query(ApplicationInfoMap &infoMap, ApplicationProperties properties, ApplicationPropertyMap restrictions)
|
||||
{
|
||||
QString field = ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField();
|
||||
QString field;
|
||||
for(const ApplicationProperty::Property &pro : properties) {
|
||||
field.append("," + ApplicationPropertyHelper(pro).dataBaseField());
|
||||
field.append(ApplicationPropertyHelper(pro).dataBaseField() + ",");
|
||||
}
|
||||
if(!properties.contains(ApplicationProperty::Property::DesktopFilePath)) {
|
||||
field.append(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField());
|
||||
} else if(!field.isEmpty()) {
|
||||
field.remove(field.length() - 1, 1);
|
||||
}
|
||||
|
||||
QString condition;
|
||||
|
@ -427,20 +442,26 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, Pro
|
|||
return false;
|
||||
}
|
||||
while (query.next()) {
|
||||
PropertyMap propertyMap;
|
||||
for(int i = 0; i< properties.size(); i++) {
|
||||
propertyMap.insert(properties.at(i), query.value(i + 1));
|
||||
ApplicationPropertyMap propertyMap;
|
||||
for(const ApplicationProperty::Property &pro : properties) {
|
||||
propertyMap.insert(pro, query.value(ApplicationPropertyHelper(pro).dataBaseField()));
|
||||
|
||||
}
|
||||
infoMap.insert(query.value(0).toString(), propertyMap);
|
||||
infoMap.insert(query.value(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField()).toString(), propertyMap);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, const QString &keyword, PropertyMap restrictions)
|
||||
bool AppInfoTable::query(ApplicationInfoMap &infoMap, ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions)
|
||||
{
|
||||
QString field(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField());
|
||||
QString field;
|
||||
for(const ApplicationProperty::Property &pro : properties) {
|
||||
field.append("," + ApplicationPropertyHelper(pro).dataBaseField());
|
||||
field.append(ApplicationPropertyHelper(pro).dataBaseField() + ",");
|
||||
}
|
||||
if(!properties.contains(ApplicationProperty::Property::DesktopFilePath)) {
|
||||
field.append(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField());
|
||||
} else if(!field.isEmpty()) {
|
||||
field.remove(field.length() - 1, 1);
|
||||
}
|
||||
|
||||
QString condition;
|
||||
|
@ -448,75 +469,22 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, con
|
|||
condition.append(ApplicationPropertyHelper(prop).dataBaseField() + "=? AND ");
|
||||
}
|
||||
|
||||
QString cmd;
|
||||
if (keyword.size() < 2) {
|
||||
cmd = QString("SELECT %0 FROM APPINFO WHERE %1(LOCAL_NAME || NAME_EN || NAME_ZH || FIRST_LETTER_OF_PINYIN) LIKE ?")
|
||||
.arg(field)
|
||||
.arg(condition);
|
||||
} else {
|
||||
cmd = QString("SELECT %0 FROM APPINFO WHERE %1(LOCAL_NAME || NAME_EN || NAME_ZH || PINYIN_NAME || FIRST_LETTER_OF_PINYIN) LIKE ?")
|
||||
.arg(field)
|
||||
.arg(condition);
|
||||
}
|
||||
|
||||
QSqlQuery query(*d->m_database);
|
||||
query.setForwardOnly(true);
|
||||
query.prepare(cmd);
|
||||
int count = 0;
|
||||
for (const QVariant &conditionValue : restrictions) {
|
||||
query.bindValue(count, conditionValue);
|
||||
count++;
|
||||
}
|
||||
query.bindValue(count, "%" + keyword + "%");
|
||||
if (!query.exec()) {
|
||||
qWarning() << d->m_database->lastError() << query.lastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
while (query.next()) {
|
||||
PropertyMap propertyMap;
|
||||
for(int i = 0; i< properties.size(); i++) {
|
||||
propertyMap.insert(properties.at(i), query.value(i + 1));
|
||||
}
|
||||
infoMap.insert(query.value(0).toString(), propertyMap);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, const QStringList &keywords, PropertyMap restrictions)
|
||||
{
|
||||
QString field(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField());
|
||||
for(const ApplicationProperty::Property &pro : properties) {
|
||||
field.append("," + ApplicationPropertyHelper(pro).dataBaseField());
|
||||
}
|
||||
|
||||
QString condition;
|
||||
for (const ApplicationProperty::Property prop: restrictions.keys()) {
|
||||
condition.append(ApplicationPropertyHelper(prop).dataBaseField() + "=? AND ");
|
||||
}
|
||||
|
||||
QString cmd;
|
||||
if (keywords.at(0).size() < 2) {
|
||||
cmd = QString("SELECT %0 FROM APPINFO WHERE %1(LOCAL_NAME || NAME_EN || NAME_ZH || FIRST_LETTER_OF_PINYIN) LIKE ?")
|
||||
.arg(field)
|
||||
.arg(condition);
|
||||
} else {
|
||||
cmd = QString("SELECT %0 FROM APPINFO WHERE %1(LOCAL_NAME || NAME_EN || NAME_ZH || PINYIN_NAME || FIRST_LETTER_OF_PINYIN) LIKE ?")
|
||||
.arg(field)
|
||||
.arg(condition);
|
||||
}
|
||||
for (int i = 1; i < keywords.size(); i++) {
|
||||
if (keywords.at(i).size() < 2) {
|
||||
cmd += " AND (LOCAL_NAME || NAME_EN || NAME_ZH || FIRST_LETTER_OF_PINYIN) LIKE ?";
|
||||
QString keywordCondition;
|
||||
for(const QString& keyword : keywords) {
|
||||
if(keyword.size() < 2) {
|
||||
keywordCondition.append("(ifnull(LOCAL_NAME, '') like ? or ifnull(NAME_EN, '') like ? or ifnull(NAME_ZH, '') like ? or ifnull(FIRST_LETTER_OF_PINYIN, '') like ?) AND");
|
||||
} else {
|
||||
cmd += " AND (LOCAL_NAME || NAME_EN || NAME_ZH || FIRST_LETTER_OF_PINYIN || PINYIN_NAME) LIKE ?";
|
||||
keywordCondition.append("(ifnull(LOCAL_NAME, '') like ? or ifnull(NAME_EN, '') like ? or ifnull(NAME_ZH, '') like ? or ifnull(FIRST_LETTER_OF_PINYIN, '') like ? or ifnull(PINYIN_NAME, '') like ?) AND");
|
||||
}
|
||||
}
|
||||
cmd += QString(" ORDER BY LENGTH(LOCAL_NAME)");
|
||||
if(!keywordCondition.isEmpty()) {
|
||||
keywordCondition.remove(keywordCondition.length() - 3, 3);
|
||||
}
|
||||
|
||||
QString sql = QString("SELECT %0 FROM APPINFO WHERE %1 %2 ORDER BY LENGTH(LOCAL_NAME)").arg(field).arg(condition).arg(keywordCondition);
|
||||
QSqlQuery query(*d->m_database);
|
||||
query.setForwardOnly(true);
|
||||
query.prepare(cmd);
|
||||
query.prepare(sql);
|
||||
|
||||
int count = 0;
|
||||
for (const QVariant &conditionValue : restrictions) {
|
||||
|
@ -524,21 +492,30 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, con
|
|||
count++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < keywords.size(); i++) {
|
||||
query.bindValue(count + i, "%" + keywords.at(i) + "%");
|
||||
for(const QString &keyword : keywords) {
|
||||
int i = 5;
|
||||
if(keyword.size() < 2) {
|
||||
i--;
|
||||
}
|
||||
for (int bindCount = 0; bindCount < i; bindCount++) {
|
||||
query.bindValue(count, "%" + keyword + "%");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
qDebug() << query.lastQuery() << query.boundValues();
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << d->m_database->lastError() << query.lastError();
|
||||
qWarning() << d->m_database->lastError() << query.lastError() << query.lastQuery() << query.boundValues();
|
||||
return false;
|
||||
}
|
||||
|
||||
while (query.next()) {
|
||||
PropertyMap propertyMap;
|
||||
for(int i = 0; i< properties.size(); i++) {
|
||||
propertyMap.insert(properties.at(i), query.value(i + 1));
|
||||
ApplicationPropertyMap propertyMap;
|
||||
for(const ApplicationProperty::Property &pro : properties) {
|
||||
propertyMap.insert(pro, query.value(ApplicationPropertyHelper(pro).dataBaseField()));
|
||||
|
||||
}
|
||||
infoMap.insert(query.value(0).toString(), propertyMap);
|
||||
infoMap.insert(query.value(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField()).toString(), propertyMap);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ public:
|
|||
|
||||
AppInfoTable(AppInfoTable &) = delete;
|
||||
AppInfoTable &operator =(const AppInfoTable &) = delete;
|
||||
bool query(PropertyMap &propertyMap, const QString &desktopFile, Properties properties);
|
||||
bool query(ApplicationInfoMap &infoMap, Properties properties);
|
||||
bool query(ApplicationInfoMap &infoMap, Properties properties, PropertyMap restrictions);
|
||||
bool query(ApplicationInfoMap &infoMap, Properties properties, const QString &keyword, PropertyMap restrictions);
|
||||
bool query(ApplicationInfoMap &infoMap, Properties properties, const QStringList &keywords, PropertyMap restrictions);
|
||||
|
||||
bool query(ApplicationPropertyMap &propertyMap, const QString &desktopFile, ApplicationProperties properties);
|
||||
bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties);
|
||||
bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties, ApplicationPropertyMap restrictions);
|
||||
bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions);
|
||||
|
||||
/**
|
||||
* @brief AppInfoTable::setAppFavoritesState
|
||||
|
|
|
@ -26,40 +26,41 @@ ApplicationInfo::~ApplicationInfo()
|
|||
|
||||
QVariant UkuiSearch::ApplicationInfo::getInfo(const QString &desktopFile, ApplicationProperty::Property property)
|
||||
{
|
||||
PropertyMap map;
|
||||
AppInfoTable::self()->query(map, desktopFile, Properties{property});
|
||||
ApplicationPropertyMap map;
|
||||
AppInfoTable::self()->query(map, desktopFile, ApplicationProperties{property});
|
||||
return map.value(property);
|
||||
}
|
||||
|
||||
PropertyMap ApplicationInfo::getInfo(const QString &desktopFile, Properties properties)
|
||||
ApplicationPropertyMap ApplicationInfo::getInfo(const QString &desktopFile, ApplicationProperties properties)
|
||||
{
|
||||
PropertyMap propertyMap;
|
||||
ApplicationPropertyMap propertyMap;
|
||||
AppInfoTable::self()->query(propertyMap, desktopFile, properties);
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
ApplicationInfoMap ApplicationInfo::getInfo(Properties properties)
|
||||
ApplicationInfoMap ApplicationInfo::getInfo(ApplicationProperties properties)
|
||||
{
|
||||
ApplicationInfoMap infoMap;
|
||||
AppInfoTable::self()->query(infoMap, properties);
|
||||
return infoMap;
|
||||
}
|
||||
|
||||
ApplicationInfoMap ApplicationInfo::getInfo(Properties properties, PropertyMap restrictions)
|
||||
ApplicationInfoMap ApplicationInfo::getInfo(ApplicationProperties properties, ApplicationPropertyMap restrictions)
|
||||
{
|
||||
ApplicationInfoMap infoMap;
|
||||
AppInfoTable::self()->query(infoMap, properties, restrictions);
|
||||
return infoMap;
|
||||
}
|
||||
|
||||
ApplicationInfoMap ApplicationInfo::searchApp(Properties properties, const QString &keyword, PropertyMap restrictions)
|
||||
|
||||
ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties, const QString &keyword, ApplicationPropertyMap restrictions)
|
||||
{
|
||||
ApplicationInfoMap infoMap;
|
||||
AppInfoTable::self()->query(infoMap, properties, keyword, restrictions);
|
||||
AppInfoTable::self()->query(infoMap, properties, QStringList{keyword}, restrictions);
|
||||
return infoMap;
|
||||
}
|
||||
|
||||
ApplicationInfoMap ApplicationInfo::searchApp(Properties properties, const QStringList &keywords, PropertyMap restrictions)
|
||||
ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions)
|
||||
{
|
||||
ApplicationInfoMap infoMap;
|
||||
AppInfoTable::self()->query(infoMap, properties, keywords, restrictions);
|
||||
|
|
|
@ -25,13 +25,13 @@ public:
|
|||
* @param properties
|
||||
* @return
|
||||
*/
|
||||
PropertyMap getInfo(const QString &desktopFile, Properties properties);
|
||||
ApplicationPropertyMap getInfo(const QString &desktopFile, ApplicationProperties properties);
|
||||
/**
|
||||
* @brief getInfo 查询所有应用的多个属性
|
||||
* @param property
|
||||
* @return
|
||||
*/
|
||||
ApplicationInfoMap getInfo(Properties properties);
|
||||
ApplicationInfoMap getInfo(ApplicationProperties properties);
|
||||
|
||||
/**
|
||||
* @brief ApplicationInfo::getInfo
|
||||
|
@ -40,7 +40,7 @@ public:
|
|||
* @param properties: Each application's information should contain these properties
|
||||
* @return ApplicationInfoMap: the search result
|
||||
*/
|
||||
ApplicationInfoMap getInfo(Properties properties, PropertyMap restrictions);
|
||||
ApplicationInfoMap getInfo(ApplicationProperties properties, ApplicationPropertyMap restrictions);
|
||||
|
||||
/**
|
||||
* @brief ApplicationInfo::searchApp
|
||||
|
@ -48,8 +48,8 @@ public:
|
|||
* @param installAppInfoRes: the search results of applications
|
||||
* @return ApplicationInfoMap: the search result
|
||||
*/
|
||||
ApplicationInfoMap searchApp(Properties properties, const QString &keyword, PropertyMap restrictions);
|
||||
ApplicationInfoMap searchApp(Properties properties, const QStringList &keywords, PropertyMap restrictions);
|
||||
ApplicationInfoMap searchApp(ApplicationProperties properties, const QString &keyword, ApplicationPropertyMap restrictions);
|
||||
ApplicationInfoMap searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions);
|
||||
|
||||
/**
|
||||
* @brief ApplicationInfo::setAppFavoritesState
|
||||
|
|
|
@ -36,9 +36,9 @@ enum Property {
|
|||
DontDisplay //是否不需要显示(设置了Nodisplay等字段)
|
||||
};
|
||||
} //namespace ApplicationProperty
|
||||
typedef QVector<ApplicationProperty::Property> Properties;
|
||||
typedef QMap<ApplicationProperty::Property, QVariant> PropertyMap;
|
||||
typedef QMap<QString, PropertyMap> ApplicationInfoMap; // desktopFile->PropertyMap
|
||||
typedef QVector<ApplicationProperty::Property> ApplicationProperties;
|
||||
typedef QMap<ApplicationProperty::Property, QVariant> ApplicationPropertyMap;
|
||||
typedef QMap<QString, ApplicationPropertyMap> ApplicationInfoMap; // desktopFile->ApplicationPropertyMap
|
||||
}
|
||||
Q_DECLARE_METATYPE(UkuiSearch::ApplicationProperty::Property)
|
||||
#endif // APPLICATIONPROPERTY_H
|
||||
|
|
|
@ -23,13 +23,14 @@ AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearch
|
|||
m_timer->moveToThread(this);
|
||||
|
||||
m_appSearchResults = m_appSearchTask->init();
|
||||
m_appSearchTask->initSearchPlugin(SearchType::Application);
|
||||
m_appSearchTask->initSearchPlugin(SearchProperty::SearchType::Application);
|
||||
m_appSearchTask->setSearchOnlineApps(true);
|
||||
m_appSearchTask->setResultDataType(SearchType::Application, UkuiSearch::ApplicationDesktopPath |
|
||||
UkuiSearch::ApplicationLocalName |
|
||||
UkuiSearch::ApplicationIconName |
|
||||
UkuiSearch::ApplicationDescription |
|
||||
UkuiSearch::IsOnlineApplication);
|
||||
m_appSearchTask->setResultProperties(SearchProperty::SearchType::Application,
|
||||
SearchResultProperties{SearchProperty::SearchResultProperty::ApplicationDesktopPath,
|
||||
SearchProperty::SearchResultProperty::ApplicationLocalName,
|
||||
SearchProperty::SearchResultProperty::ApplicationIconName,
|
||||
SearchProperty::SearchResultProperty::ApplicationDescription,
|
||||
SearchProperty::SearchResultProperty::IsOnlineApplication});
|
||||
}
|
||||
|
||||
AppSearchPlugin::~AppSearchPlugin()
|
||||
|
@ -65,7 +66,7 @@ void AppSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIface
|
|||
m_searchResult = searchResult;
|
||||
m_appSearchTask->clearKeyWords();
|
||||
m_appSearchTask->addKeyword(keyword);
|
||||
m_appSearchTask->startSearch(SearchType::Application);
|
||||
m_appSearchTask->startSearch(SearchProperty::SearchType::Application);
|
||||
|
||||
// AppSearch *appsearch = new AppSearch(searchResult, m_appSearchResults, m_appSearchTask, keyword, uniqueSymbol);
|
||||
// m_pool.start(appsearch);
|
||||
|
@ -163,7 +164,8 @@ void AppSearchPlugin::run()
|
|||
{
|
||||
while(!isInterruptionRequested()) {
|
||||
ResultItem oneResult = m_appSearchResults->tryDequeue();
|
||||
if(oneResult.getSearchId() == 0 && oneResult.getItemKey().isEmpty() && oneResult.getExtral().isEmpty()) {
|
||||
SearchResultPropertyMap data = oneResult.getAllValue();
|
||||
if(oneResult.getSearchId() == 0 && oneResult.getItemKey().isEmpty() && data.isEmpty()) {
|
||||
if(!m_timer->isActive()) {
|
||||
m_timer->start();
|
||||
}
|
||||
|
@ -171,14 +173,14 @@ void AppSearchPlugin::run()
|
|||
} else {
|
||||
m_timer->stop();
|
||||
SearchPluginIface::ResultInfo ri;
|
||||
ri.actionKey = oneResult.getExtral().at(0).toString();
|
||||
ri.name = oneResult.getExtral().at(1).toString();
|
||||
ri.icon = XdgIcon::fromTheme(oneResult.getExtral().at(2).toString(), QIcon(":/res/icons/unknown.svg"));
|
||||
ri.actionKey = data.value(SearchProperty::SearchResultProperty::ApplicationDesktopPath).toString();
|
||||
ri.name = data.value(SearchProperty::SearchResultProperty::ApplicationLocalName).toString();
|
||||
ri.icon = XdgIcon::fromTheme(data.value(SearchProperty::SearchResultProperty::ApplicationIconName).toString(), QIcon(":/res/icons/unknown.svg"));
|
||||
SearchPluginIface::DescriptionInfo description;
|
||||
description.key = QString(tr("Application Description:"));
|
||||
description.value = oneResult.getExtral().at(3).toString();
|
||||
description.value = data.value(SearchProperty::SearchResultProperty::ApplicationDescription).toString();
|
||||
ri.description.append(description);
|
||||
ri.type = oneResult.getExtral().at(4).toInt();
|
||||
ri.type = data.value(SearchProperty::SearchResultProperty::IsOnlineApplication).toInt();
|
||||
m_searchResult->enqueue(ri);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,10 @@ static const int OCR_MIN_SIZE = 200;
|
|||
static const QByteArray UKUI_SEARCH_SCHEMAS = QByteArrayLiteral("org.ukui.search.settings");
|
||||
static const QString SEARCH_METHOD_KEY = QStringLiteral("fileIndexEnable");
|
||||
static const QString INDEX_DATABASE_VERSION = QStringLiteral("1.0.0");
|
||||
static const QString CONTENT_DATABASE_VERSION = QStringLiteral("1.0.0");
|
||||
/**
|
||||
* changelog 1.1.0 增加文件修改时间value
|
||||
*/
|
||||
static const QString CONTENT_DATABASE_VERSION = QStringLiteral("1.1.0");
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -57,7 +57,10 @@ bool fileContentIndexer::index()
|
|||
m_document.addTerm("PARENTTERM" + FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep)));
|
||||
m_document.addValue(1, m_filePath);
|
||||
m_document.addValue(2, suffix);
|
||||
m_document.setIndexTime(info.lastModified().toString("yyyyMMddHHmmsszzz"));
|
||||
|
||||
QString time = info.lastModified().toString("yyyyMMddHHmmsszzz");
|
||||
m_document.addSortableSerialiseValue(3, time);
|
||||
m_document.setIndexTime(time);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -84,6 +84,8 @@ void IndexScheduler::stop()
|
|||
m_state = Stop;
|
||||
qDebug() << "Index scheduler has been stopped.";
|
||||
Q_EMIT stateChange(m_state);
|
||||
m_statusRecorder->setStatus(INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Off);
|
||||
m_statusRecorder->setStatus(CONTENT_INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Off);
|
||||
}
|
||||
|
||||
void IndexScheduler::start()
|
||||
|
|
|
@ -39,7 +39,8 @@ public:
|
|||
Initializing = 0,
|
||||
Error = 1,
|
||||
Ready = 2,
|
||||
Updating = 3
|
||||
Updating = 3,
|
||||
Off = 4
|
||||
};
|
||||
Q_ENUM(State)
|
||||
|
||||
|
|
|
@ -109,7 +109,8 @@ unix {
|
|||
appdata/application-property.h \
|
||||
appdata/application-property-helper.h \
|
||||
searchinterface/ukui-search-task.h \
|
||||
searchinterface/result-item.h
|
||||
searchinterface/result-item.h \
|
||||
searchinterface/search-result-property.h
|
||||
|
||||
header.files += development-files/header-files/*
|
||||
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
#ifndef COMMONDEFINES_H
|
||||
#define COMMONDEFINES_H
|
||||
#include <QFlags>
|
||||
namespace UkuiSearch {
|
||||
/**
|
||||
* @brief The SearchType enum
|
||||
*
|
||||
*/
|
||||
enum class SearchType
|
||||
{
|
||||
File = 1u << 0,
|
||||
FileContent = 1u << 1,
|
||||
Application = 1u << 2,
|
||||
Setting = 1u << 3,
|
||||
Note = 1u << 4,
|
||||
Mail = 1u << 5,
|
||||
Custom = 1u << 6
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The ResultDataType enum
|
||||
*
|
||||
*/
|
||||
enum ResultDataType
|
||||
{
|
||||
FilePath = 1u << 0,
|
||||
FileIconName = 1u << 1,
|
||||
FileName = 1u << 2,
|
||||
ModifiedTime = 1u << 3,
|
||||
ApplicationDesktopPath = 1u << 4,
|
||||
ApplicationLocalName = 1u << 5,
|
||||
ApplicationIconName = 1u << 6,
|
||||
ApplicationDescription = 1u << 7,
|
||||
IsOnlineApplication = 1u << 8
|
||||
//add more...
|
||||
|
||||
};
|
||||
Q_DECLARE_FLAGS(ResultDataTypes, ResultDataType)
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(UkuiSearch::ResultDataTypes)
|
||||
|
||||
#endif // COMMONDEFINES_H
|
|
@ -6,7 +6,7 @@
|
|||
#include <QObject>
|
||||
#include <QtPlugin>
|
||||
#include "plugin-iface.h"
|
||||
#include "common-defines.h"
|
||||
#include "search-result-property.h"
|
||||
#include "search-controller.h"
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ class SearchTaskPluginIface : public QObject, public PluginInterface
|
|||
Q_OBJECT
|
||||
public:
|
||||
virtual QString getCustomSearchType() = 0;
|
||||
virtual SearchType getSearchType() = 0;
|
||||
virtual SearchProperty::SearchType getSearchType() = 0;
|
||||
//Asynchronous,multithread.
|
||||
virtual void startSearch(std::shared_ptr<SearchController> searchController) = 0;
|
||||
virtual void stop() = 0;
|
||||
|
|
|
@ -16,16 +16,16 @@ SearchTaskPluginManager *SearchTaskPluginManager::getInstance()
|
|||
return global_instance;
|
||||
}
|
||||
|
||||
void SearchTaskPluginManager::initPlugins(SearchType searchType)
|
||||
void SearchTaskPluginManager::initPlugins(SearchProperty::SearchType searchType)
|
||||
{
|
||||
switch (searchType) {
|
||||
case SearchType::File:
|
||||
case SearchProperty::SearchType::File:
|
||||
registerBuildinPlugin(new FileSearchTask(this));
|
||||
break;
|
||||
case SearchType::FileContent:
|
||||
case SearchProperty::SearchType::FileContent:
|
||||
registerBuildinPlugin(new FileContentSearchTask(this));
|
||||
break;
|
||||
case SearchType::Application:
|
||||
case SearchProperty::SearchType::Application:
|
||||
registerBuildinPlugin(new AppSearchTask(this));
|
||||
default:
|
||||
break;
|
||||
|
@ -59,7 +59,7 @@ SearchTaskPluginManager::SearchTaskPluginManager(QObject *parent) : QObject(pare
|
|||
{
|
||||
}
|
||||
|
||||
void SearchTaskPluginManager::pluginSearch(SearchType searchType, std::shared_ptr<SearchController> searchController)
|
||||
void SearchTaskPluginManager::pluginSearch(SearchProperty::SearchType searchType, std::shared_ptr<SearchController> searchController)
|
||||
{
|
||||
size_t type = static_cast<size_t>(searchType);
|
||||
qDebug() << "search type" << type;
|
||||
|
@ -88,13 +88,13 @@ void SearchTaskPluginManager::pluginSearch(QString customSearchType, std::shared
|
|||
}
|
||||
}
|
||||
|
||||
bool SearchTaskPluginManager::startSearch(const QUuid &uuid, std::shared_ptr<SearchController> searchController, SearchType searchType, const QString &customType)
|
||||
bool SearchTaskPluginManager::startSearch(const QUuid &uuid, std::shared_ptr<SearchController> searchController, SearchProperty::SearchType searchType, const QString &customType)
|
||||
{
|
||||
if (m_managedPlugins.contains(uuid)) {
|
||||
ManagedPlugin* managedPlugin = m_managedPlugins.value(uuid);
|
||||
|
||||
SearchTaskPluginIface *plugin = nullptr;
|
||||
if (searchType == SearchType::Custom) {
|
||||
if (searchType == SearchProperty::SearchType::Custom) {
|
||||
plugin = managedPlugin->externalPlugin(customType);
|
||||
|
||||
} else {
|
||||
|
@ -110,10 +110,10 @@ bool SearchTaskPluginManager::startSearch(const QUuid &uuid, std::shared_ptr<Sea
|
|||
return false;
|
||||
}
|
||||
|
||||
SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchType searchType, const QString& customType)
|
||||
SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchProperty::SearchType searchType, const QString& customType)
|
||||
{
|
||||
SearchTaskPluginIface *searchPlugin = nullptr;
|
||||
if (searchType == SearchType::Custom) {
|
||||
if (searchType == SearchProperty::SearchType::Custom) {
|
||||
if (m_loadedPluginPath.contains(customType)) {
|
||||
QPluginLoader pluginLoader(m_loadedPluginPath.value(customType));
|
||||
QObject *plugin = pluginLoader.instance();
|
||||
|
@ -124,13 +124,13 @@ SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchType searchType,
|
|||
|
||||
} else {
|
||||
switch (searchType) {
|
||||
case SearchType::File:
|
||||
case SearchProperty::SearchType::File:
|
||||
searchPlugin = new FileSearchTask(this);
|
||||
break;
|
||||
case SearchType::FileContent:
|
||||
case SearchProperty::SearchType::FileContent:
|
||||
searchPlugin = new FileContentSearchTask(this);
|
||||
break;
|
||||
case SearchType::Application:
|
||||
case SearchProperty::SearchType::Application:
|
||||
searchPlugin = new AppSearchTask(this);
|
||||
break;
|
||||
default:
|
||||
|
@ -148,7 +148,7 @@ void SearchTaskPluginManager::registerPluginPath(const QString& customType, cons
|
|||
}
|
||||
}
|
||||
|
||||
SearchTaskPluginIface *SearchTaskPluginManager::initPlugins(const QUuid& uuid, SearchType searchType, const QString& customType)
|
||||
SearchTaskPluginIface *SearchTaskPluginManager::initPlugins(const QUuid& uuid, SearchProperty::SearchType searchType, const QString& customType)
|
||||
{
|
||||
if (!m_managedPlugins.contains(uuid)) {
|
||||
m_managedPlugins.insert(uuid, new ManagedPlugin(nullptr));
|
||||
|
@ -156,7 +156,7 @@ SearchTaskPluginIface *SearchTaskPluginManager::initPlugins(const QUuid& uuid, S
|
|||
|
||||
SearchTaskPluginIface *plugin = getPlugin(searchType, customType);
|
||||
bool succeed = false;
|
||||
if (searchType == SearchType::Custom) {
|
||||
if (searchType == SearchProperty::SearchType::Custom) {
|
||||
succeed = m_managedPlugins.value(uuid)->insertExternalPlugin(customType, plugin);
|
||||
|
||||
} else {
|
||||
|
@ -181,7 +181,7 @@ ManagedPlugin::~ManagedPlugin()
|
|||
|
||||
}
|
||||
|
||||
bool ManagedPlugin::insertInternalPlugin(const SearchType &searchType, SearchTaskPluginIface *plugin)
|
||||
bool ManagedPlugin::insertInternalPlugin(const SearchProperty::SearchType &searchType, SearchTaskPluginIface *plugin)
|
||||
{
|
||||
if (plugin) {
|
||||
auto type = static_cast<size_t>(searchType);
|
||||
|
@ -213,7 +213,7 @@ bool ManagedPlugin::insertExternalPlugin(const QString &customType, SearchTaskPl
|
|||
return false;
|
||||
}
|
||||
|
||||
inline SearchTaskPluginIface *ManagedPlugin::internalPlugin(const SearchType &searchType)
|
||||
inline SearchTaskPluginIface *ManagedPlugin::internalPlugin(const SearchProperty::SearchType &searchType)
|
||||
{
|
||||
auto type = static_cast<size_t>(searchType);
|
||||
if (m_internalPlugins.contains(type)) {
|
||||
|
|
|
@ -15,10 +15,10 @@ public:
|
|||
explicit ManagedPlugin(QObject *parent) : QObject(parent) {}
|
||||
~ManagedPlugin() override;
|
||||
|
||||
inline SearchTaskPluginIface *internalPlugin(const SearchType& searchType);
|
||||
inline SearchTaskPluginIface *internalPlugin(const SearchProperty::SearchType& searchType);
|
||||
inline SearchTaskPluginIface *externalPlugin(const QString& customType);
|
||||
|
||||
bool insertInternalPlugin(const SearchType& searchType, SearchTaskPluginIface* plugin);
|
||||
bool insertInternalPlugin(const SearchProperty::SearchType& searchType, SearchTaskPluginIface* plugin);
|
||||
bool insertExternalPlugin(const QString& customType, SearchTaskPluginIface* plugin);
|
||||
|
||||
private:
|
||||
|
@ -31,16 +31,16 @@ class SearchTaskPluginManager : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
static SearchTaskPluginManager *getInstance();
|
||||
void initPlugins(SearchType searchType);
|
||||
SearchTaskPluginIface *initPlugins(const QUuid&, SearchType, const QString& customType = QString());
|
||||
void initPlugins(SearchProperty::SearchType searchType);
|
||||
SearchTaskPluginIface *initPlugins(const QUuid&, SearchProperty::SearchType, const QString& customType = QString());
|
||||
bool registerPlugin(SearchTaskPluginIface *plugin);
|
||||
bool registerBuildinPlugin(SearchTaskPluginIface *plugin);
|
||||
void pluginSearch(SearchType searchType, std::shared_ptr<SearchController> searchController);
|
||||
void pluginSearch(SearchProperty::SearchType searchType, std::shared_ptr<SearchController> searchController);
|
||||
void pluginSearch(QString customSearchType, std::shared_ptr<SearchController> searchController);
|
||||
bool startSearch(const QUuid&, std::shared_ptr<SearchController>, SearchType, const QString& customType = QString());
|
||||
bool startSearch(const QUuid&, std::shared_ptr<SearchController>, SearchProperty::SearchType, const QString& customType = QString());
|
||||
void destroyPlugins(const QUuid& uuid);
|
||||
|
||||
SearchTaskPluginIface *getPlugin(SearchType searchType, const QString& customType = QString());
|
||||
SearchTaskPluginIface *getPlugin(SearchProperty::SearchType searchType, const QString& customType = QString());
|
||||
void registerPluginPath(const QString& customType, const QString& pluginPath);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
|
@ -1,81 +1,69 @@
|
|||
#include "result-item.h"
|
||||
#include "result-item-private.h"
|
||||
using namespace UkuiSearch;
|
||||
ResultItemPrivate::ResultItemPrivate::ResultItemPrivate(ResultItem *parent) : q(parent)
|
||||
namespace UkuiSearch {
|
||||
class ResultItemPrivate
|
||||
{
|
||||
friend class ResultItem;
|
||||
private:
|
||||
size_t m_searchId = 0;
|
||||
QString m_itemKey;
|
||||
SearchResultPropertyMap m_data;
|
||||
};
|
||||
}
|
||||
ResultItem::ResultItem() : d(new ResultItemPrivate())
|
||||
{
|
||||
}
|
||||
|
||||
ResultItemPrivate::~ResultItemPrivate()
|
||||
ResultItem::ResultItem(const size_t searchId) : d(new ResultItemPrivate())
|
||||
{
|
||||
d->m_searchId = searchId;
|
||||
}
|
||||
|
||||
void ResultItemPrivate::setSearchId(size_t searchId)
|
||||
ResultItem::ResultItem(const QString &itemKey) : d(new ResultItemPrivate())
|
||||
{
|
||||
m_searchId = searchId;
|
||||
d->m_itemKey = itemKey;
|
||||
}
|
||||
|
||||
void ResultItemPrivate::setItemKey(QString itemKey)
|
||||
ResultItem::ResultItem(const size_t searchId, const QString &itemKey, const SearchResultPropertyMap &map) : d(new ResultItemPrivate())
|
||||
{
|
||||
m_itemKey = itemKey;
|
||||
d->m_searchId = searchId;
|
||||
d->m_itemKey = itemKey;
|
||||
d->m_data = map;
|
||||
}
|
||||
|
||||
void ResultItemPrivate::setExtral(QVariantList extral)
|
||||
void ResultItem::setSearchId(const size_t searchId)
|
||||
{
|
||||
for (auto &info : extral) {
|
||||
m_extral.append(info);
|
||||
}
|
||||
d->m_searchId = searchId;
|
||||
}
|
||||
|
||||
size_t ResultItemPrivate::getSearchId()
|
||||
void ResultItem::setItemKey(const QString &itemKey)
|
||||
{
|
||||
return m_searchId;
|
||||
d->m_itemKey = itemKey;
|
||||
}
|
||||
|
||||
QString ResultItemPrivate::getItemKey()
|
||||
{
|
||||
return m_itemKey;
|
||||
}
|
||||
|
||||
QVariantList ResultItemPrivate::getExtral()
|
||||
{
|
||||
return m_extral;
|
||||
}
|
||||
|
||||
ResultItem::ResultItem() : d(new ResultItemPrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
ResultItem::ResultItem(const size_t searchId) : d(new ResultItemPrivate(this))
|
||||
{
|
||||
d->setSearchId(searchId);
|
||||
}
|
||||
|
||||
ResultItem::ResultItem(const QString itemKey) : d(new ResultItemPrivate(this))
|
||||
{
|
||||
d->setItemKey(itemKey);
|
||||
}
|
||||
|
||||
ResultItem::ResultItem(const size_t searchId, const QString itemKey, QVariantList extral) : d(new ResultItemPrivate(this))
|
||||
{
|
||||
d->setSearchId(searchId);
|
||||
d->setItemKey(itemKey);
|
||||
d->setExtral(extral);
|
||||
}
|
||||
|
||||
|
||||
size_t ResultItem::getSearchId() const
|
||||
{
|
||||
return d->getSearchId();
|
||||
return d->m_searchId;
|
||||
}
|
||||
|
||||
QString ResultItem::getItemKey() const
|
||||
{
|
||||
return d->getItemKey();
|
||||
return d->m_itemKey;
|
||||
}
|
||||
|
||||
QVariantList ResultItem::getExtral() const
|
||||
void ResultItem::setValue(SearchProperty::SearchResultProperty property, const QVariant &value)
|
||||
{
|
||||
return d->getExtral();
|
||||
d->m_data.insert(property, value);
|
||||
}
|
||||
|
||||
QVariant ResultItem::getValue(SearchProperty::SearchResultProperty property) const
|
||||
{
|
||||
return d->m_data.value(property);
|
||||
}
|
||||
|
||||
SearchResultPropertyMap ResultItem::getAllValue() const
|
||||
{
|
||||
return d->m_data;
|
||||
}
|
||||
|
||||
ResultItem::~ResultItem()
|
||||
|
@ -85,9 +73,6 @@ ResultItem::~ResultItem()
|
|||
d = nullptr;
|
||||
}
|
||||
|
||||
ResultItem::ResultItem(const ResultItem &item): d(new ResultItemPrivate(this))
|
||||
ResultItem::ResultItem(const ResultItem &item): d(new ResultItemPrivate(*item.d))
|
||||
{
|
||||
d->setSearchId(item.getSearchId());
|
||||
d->setItemKey(item.getItemKey());
|
||||
d->setExtral(item.getExtral());
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define RESULTITEM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include "search-result-property.h"
|
||||
namespace UkuiSearch {
|
||||
class ResultItemPrivate;
|
||||
class ResultItem
|
||||
|
@ -13,11 +13,15 @@ public:
|
|||
|
||||
ResultItem(const ResultItem &item);
|
||||
explicit ResultItem(const size_t searchId);
|
||||
explicit ResultItem(const QString itemKey);
|
||||
explicit ResultItem(const size_t searchId, const QString itemKey, QVariantList extral = QVariantList());
|
||||
explicit ResultItem(const QString &itemKey);
|
||||
ResultItem(const size_t searchId, const QString &itemKey, const SearchResultPropertyMap &map);
|
||||
void setSearchId(const size_t searchId);
|
||||
void setItemKey(const QString &itemKey);
|
||||
size_t getSearchId() const;
|
||||
QString getItemKey() const;
|
||||
QVariantList getExtral() const;
|
||||
void setValue(SearchProperty::SearchResultProperty property, const QVariant &value);
|
||||
QVariant getValue(SearchProperty::SearchResultProperty property) const;
|
||||
SearchResultPropertyMap getAllValue() const;
|
||||
|
||||
private:
|
||||
ResultItemPrivate *d;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QMutex>
|
||||
#include <QMap>
|
||||
#include "search-controller.h"
|
||||
#include "search-result-property.h"
|
||||
namespace UkuiSearch {
|
||||
|
||||
class SearchControllerPrivate
|
||||
|
@ -26,7 +27,7 @@ public:
|
|||
|
||||
size_t getCurrentSearchId();
|
||||
DataQueue<ResultItem>* getDataQueue();
|
||||
ResultDataTypes getResultDataType(SearchType searchType);
|
||||
SearchResultProperties getResultProperties(SearchProperty::SearchType searchType);
|
||||
QStringList getCustomResultDataType(QString customSearchType);
|
||||
bool beginSearchIdCheck(size_t searchId);
|
||||
void finishSearchIdCheck();
|
||||
|
@ -44,16 +45,15 @@ public:
|
|||
void clearSearchDir();
|
||||
void clearFileLabel();
|
||||
|
||||
bool setResultDataType(SearchType searchType, ResultDataTypes dataType);
|
||||
bool setCustomResultDataType(QString customSearchType, QStringList dataType);
|
||||
bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
|
||||
void setCustomResultDataType(QString customSearchType, QStringList dataType);
|
||||
|
||||
/**
|
||||
* @brief 分页选项
|
||||
* @param first 指定起始位置
|
||||
* @brief
|
||||
* @param maxResults 每次搜索结果集的数量
|
||||
*/
|
||||
void setPagination(unsigned int first, unsigned int maxResults);
|
||||
unsigned int first() const;
|
||||
void setMaxResultNum(unsigned int maxResults);
|
||||
|
||||
unsigned int maxResults() const;
|
||||
|
||||
private:
|
||||
|
@ -74,11 +74,9 @@ private:
|
|||
bool m_onlySearchFile = false;
|
||||
bool m_onlySearchDir = false;
|
||||
bool m_searchOnlineApps = false;
|
||||
|
||||
unsigned int m_first = 0;
|
||||
unsigned int m_maxResults = 100; //默认取100条结果
|
||||
|
||||
QMap<SearchType, ResultDataTypes> m_searchType2ResultDataType;
|
||||
QMap<SearchProperty::SearchType, SearchResultProperties> m_searchType2ResultProperties;
|
||||
QMap<QString, QStringList> m_customSearchType2ResultDataType;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -96,9 +96,9 @@ DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
|
|||
return m_sharedDataQueue.get();
|
||||
}
|
||||
|
||||
ResultDataTypes SearchControllerPrivate::getResultDataType(SearchType searchType)
|
||||
SearchResultProperties SearchControllerPrivate::getResultProperties(SearchProperty::SearchType searchType)
|
||||
{
|
||||
return m_searchType2ResultDataType[searchType];
|
||||
return m_searchType2ResultProperties[searchType];
|
||||
}
|
||||
|
||||
QStringList SearchControllerPrivate::getCustomResultDataType(QString customSearchType)
|
||||
|
@ -209,31 +209,23 @@ void SearchControllerPrivate::clearFileLabel()
|
|||
m_FileLabels.clear();
|
||||
}
|
||||
|
||||
bool SearchControllerPrivate::setResultDataType(SearchType searchType, ResultDataTypes dataType)
|
||||
bool SearchControllerPrivate::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
||||
{
|
||||
bool res(true);
|
||||
m_searchType2ResultDataType[searchType] = dataType;
|
||||
m_searchType2ResultProperties[searchType] = searchResultProperties;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||
void SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||
{
|
||||
bool res(true);
|
||||
m_customSearchType2ResultDataType[customSearchType] = dataType;
|
||||
return res;
|
||||
}
|
||||
|
||||
void SearchControllerPrivate::setPagination(unsigned int first, unsigned int maxResults)
|
||||
void SearchControllerPrivate::setMaxResultNum(unsigned int maxResults)
|
||||
{
|
||||
m_first = first;
|
||||
m_maxResults = maxResults;
|
||||
}
|
||||
|
||||
unsigned int SearchControllerPrivate::first() const
|
||||
{
|
||||
return m_first;
|
||||
}
|
||||
|
||||
unsigned int SearchControllerPrivate::maxResults() const
|
||||
{
|
||||
return m_maxResults;
|
||||
|
@ -291,9 +283,9 @@ DataQueue<ResultItem> *SearchController::getDataQueue()
|
|||
return d->getDataQueue();
|
||||
}
|
||||
|
||||
ResultDataTypes SearchController::getResultDataType(SearchType searchType)
|
||||
SearchResultProperties SearchController::getResultProperties(SearchProperty::SearchType searchType)
|
||||
{
|
||||
return d->getResultDataType(searchType);
|
||||
return d->getResultProperties(searchType);
|
||||
}
|
||||
|
||||
QStringList SearchController::getCustomResultDataType(QString customSearchType)
|
||||
|
@ -401,14 +393,9 @@ void SearchController::clearFileLabel()
|
|||
d->clearFileLabel();
|
||||
}
|
||||
|
||||
void SearchController::setPagination(unsigned int first, unsigned int maxResults)
|
||||
void SearchController::setMaxResultNum(unsigned int maxResults)
|
||||
{
|
||||
d->setPagination(first, maxResults);
|
||||
}
|
||||
|
||||
unsigned int SearchController::first() const
|
||||
{
|
||||
return d->first();
|
||||
d->setMaxResultNum(maxResults);
|
||||
}
|
||||
|
||||
unsigned int SearchController::maxResults() const
|
||||
|
@ -416,12 +403,12 @@ unsigned int SearchController::maxResults() const
|
|||
return d->maxResults();
|
||||
}
|
||||
|
||||
bool SearchController::setResultDataType(SearchType searchType, ResultDataTypes dataType)
|
||||
bool SearchController::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
||||
{
|
||||
return d->setResultDataType(searchType, dataType);
|
||||
return d->setResultProperties(searchType, searchResultProperties);
|
||||
}
|
||||
|
||||
bool SearchController::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||
void SearchController::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||
{
|
||||
return d->setCustomResultDataType(customSearchType, dataType);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QStringList>
|
||||
#include <memory>
|
||||
#include "data-queue.h"
|
||||
#include "common-defines.h"
|
||||
#include "search-result-property.h"
|
||||
//todo: url parser?
|
||||
namespace UkuiSearch {
|
||||
class UkuiSearchTask;
|
||||
|
@ -39,7 +39,7 @@ public:
|
|||
//以下方法插件可以调用
|
||||
size_t getCurrentSearchId();
|
||||
DataQueue<ResultItem>* getDataQueue();
|
||||
ResultDataTypes getResultDataType(SearchType searchType);
|
||||
SearchResultProperties getResultProperties(SearchProperty::SearchType searchType);
|
||||
QStringList getCustomResultDataType(QString customSearchType);
|
||||
bool beginSearchIdCheck(size_t searchId);
|
||||
void finishSearchIdCheck();
|
||||
|
@ -57,12 +57,12 @@ public:
|
|||
void clearSearchDir();
|
||||
void clearFileLabel();
|
||||
|
||||
void setPagination(unsigned int first, unsigned int maxResults);
|
||||
void setMaxResultNum(unsigned int maxResults);
|
||||
unsigned int first() const;
|
||||
unsigned int maxResults() const;
|
||||
|
||||
bool setResultDataType(SearchType searchType, ResultDataTypes dataType);
|
||||
bool setCustomResultDataType(QString customSearchType, QStringList dataType);
|
||||
bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
|
||||
void setCustomResultDataType(QString customSearchType, QStringList dataType);
|
||||
private:
|
||||
std::shared_ptr<SearchController> m_parent = nullptr;
|
||||
SearchControllerPrivate *d = nullptr;
|
||||
|
|
|
@ -2,15 +2,18 @@ INCLUDEPATH += $$PWD
|
|||
include(searchtasks/search-tasks.pri)
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/result-item-private.h \
|
||||
# $$PWD/result-item-private.h \
|
||||
$$PWD/search-controller-private.h \
|
||||
$$PWD/search-controller.h \
|
||||
$$PWD/result-item.h \
|
||||
$$PWD/ukui-search-task-private.h \
|
||||
$$PWD/search-result-property-info.h \
|
||||
$$PWD/search-result-property.h \
|
||||
# $$PWD/ukui-search-task-private.h \
|
||||
$$PWD/ukui-search-task.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/search-controller.cpp \
|
||||
$$PWD/result-item.cpp \
|
||||
$$PWD/search-result-property-info.cpp \
|
||||
$$PWD/ukui-search-task.cpp
|
||||
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
#include "search-result-property-info.h"
|
||||
#include <QMetaType>
|
||||
#include <QVariant>
|
||||
using namespace UkuiSearch;
|
||||
class UkuiSearch::SearchResultPropertyInfoPrivate
|
||||
{
|
||||
public:
|
||||
SearchProperty::SearchResultProperty m_property;
|
||||
QString m_name;
|
||||
QString m_displayName;
|
||||
QMetaType::Type m_valueType;
|
||||
};
|
||||
SearchResultPropertyInfo::SearchResultPropertyInfo():d(new SearchResultPropertyInfoPrivate)
|
||||
{
|
||||
d->m_property = SearchProperty::SearchResultProperty::Invalid;
|
||||
d->m_name = QStringLiteral("Invalid");
|
||||
d->m_valueType = QMetaType::UnknownType;
|
||||
}
|
||||
|
||||
SearchResultPropertyInfo::SearchResultPropertyInfo(SearchProperty::SearchResultProperty property): d(new SearchResultPropertyInfoPrivate)
|
||||
{
|
||||
d->m_property = property;
|
||||
switch (property) {
|
||||
case SearchProperty::SearchResultProperty::FilePath:
|
||||
d->m_name = QStringLiteral("FilePath");
|
||||
d->m_displayName = tr("file path");
|
||||
d->m_valueType = QMetaType::QString;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::FileName:
|
||||
d->m_name = QStringLiteral("FileName");
|
||||
d->m_displayName = tr("file name");
|
||||
d->m_valueType = QMetaType::QString;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::FileIconName:
|
||||
d->m_name = QStringLiteral("FileIconName");
|
||||
d->m_displayName = tr("file icon name");
|
||||
d->m_valueType = QMetaType::QString;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::ModifiedTime:
|
||||
d->m_name = QStringLiteral("ModifiedTime");
|
||||
d->m_displayName = tr("modified time");
|
||||
d->m_valueType = QMetaType::QDateTime;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::ApplicationDesktopPath:
|
||||
d->m_name = QStringLiteral("ApplicationDesktopPath");
|
||||
d->m_displayName = tr("application desktop file path");
|
||||
d->m_valueType = QMetaType::QString;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::ApplicationLocalName:
|
||||
d->m_name = QStringLiteral("ApplicationLocalName");
|
||||
d->m_displayName = tr("application local name");
|
||||
d->m_valueType = QMetaType::QString;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::ApplicationIconName:
|
||||
d->m_name = QStringLiteral("ApplicationIconName");
|
||||
d->m_displayName = tr("application icon name");
|
||||
d->m_valueType = QMetaType::QString;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::ApplicationDescription:
|
||||
d->m_name = QStringLiteral("ApplicationDescription");
|
||||
d->m_displayName = tr("application description");
|
||||
d->m_valueType = QMetaType::QString;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::IsOnlineApplication:
|
||||
d->m_name = QStringLiteral("IsOnlineApplication");
|
||||
d->m_displayName = tr("is online application");
|
||||
d->m_valueType = QMetaType::Int;
|
||||
break;
|
||||
|
||||
case SearchProperty::SearchResultProperty::ApplicationPkgName:
|
||||
d->m_name = QStringLiteral("ApplicationPkgName");
|
||||
d->m_displayName = tr("application package name");
|
||||
d->m_valueType = QMetaType::QString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SearchResultPropertyInfo::SearchResultPropertyInfo(const SearchResultPropertyInfo &other): d(new SearchResultPropertyInfoPrivate(*other.d))
|
||||
{
|
||||
}
|
||||
|
||||
SearchResultPropertyInfo &UkuiSearch::SearchResultPropertyInfo::operator=(const SearchResultPropertyInfo &rhs)
|
||||
{
|
||||
*d = *rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool SearchResultPropertyInfo::operator==(const SearchResultPropertyInfo &rhs) const
|
||||
{
|
||||
return d->m_name == rhs.d->m_name && d->m_displayName == rhs.d->m_displayName &&
|
||||
d->m_property == rhs.d->m_property;
|
||||
}
|
||||
|
||||
SearchProperty::SearchResultProperty UkuiSearch::SearchResultPropertyInfo::property() const
|
||||
{
|
||||
return d->m_property;
|
||||
}
|
||||
|
||||
QString SearchResultPropertyInfo::name() const
|
||||
{
|
||||
return d->m_name;
|
||||
}
|
||||
|
||||
QString SearchResultPropertyInfo::displayName() const
|
||||
{
|
||||
return d->m_displayName;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef SEARCHRESULTPROPERTYINFO_H
|
||||
#define SEARCHRESULTPROPERTYINFO_H
|
||||
#include "search-result-property.h"
|
||||
#include <QObject>
|
||||
namespace UkuiSearch {
|
||||
class SearchResultPropertyInfoPrivate;
|
||||
class SearchResultPropertyInfo: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SearchResultPropertyInfo();
|
||||
SearchResultPropertyInfo(SearchProperty::SearchResultProperty property);
|
||||
SearchResultPropertyInfo(const SearchResultPropertyInfo &other);
|
||||
SearchResultPropertyInfo& operator=(const SearchResultPropertyInfo& rhs);
|
||||
bool operator==(const SearchResultPropertyInfo& rhs) const;
|
||||
|
||||
SearchProperty::SearchResultProperty property() const;
|
||||
QString name() const;
|
||||
QString displayName() const;
|
||||
private:
|
||||
SearchResultPropertyInfoPrivate *d = nullptr;
|
||||
};
|
||||
}
|
||||
#endif // SEARCHRESULTPROPERTYINFO_H
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef SEARCHRESULTPROPERTY_H
|
||||
#define SEARCHRESULTPROPERTY_H
|
||||
#include <QMap>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
namespace UkuiSearch {
|
||||
namespace SearchProperty {
|
||||
|
||||
/**
|
||||
* @brief The SearchType enum 表示搜索插件种类
|
||||
*/
|
||||
enum class SearchType
|
||||
{
|
||||
File = 1u << 0,
|
||||
FileContent = 1u << 1,
|
||||
Application = 1u << 2,
|
||||
Setting = 1u << 3,
|
||||
Note = 1u << 4,
|
||||
Mail = 1u << 5,
|
||||
Custom = 1u << 6
|
||||
};
|
||||
/**
|
||||
* @brief The SearchResultProperty enum 表示搜索结果信息
|
||||
*/
|
||||
enum SearchResultProperty {
|
||||
Invalid = 0,
|
||||
//文件搜索
|
||||
FilePath, //文件路径
|
||||
FileName, //文件名
|
||||
FileIconName, //文件图标名称
|
||||
ModifiedTime, //文件修改时间
|
||||
//应用搜索
|
||||
ApplicationDesktopPath, //应用desktop文件路径
|
||||
ApplicationLocalName, //应用本地化名称
|
||||
ApplicationIconName, //应用图标名称(或路径)
|
||||
ApplicationDescription, //应用描述(针对软件商店上架应用)
|
||||
IsOnlineApplication, //是否是未安装应用
|
||||
ApplicationPkgName //应用包名
|
||||
};
|
||||
}
|
||||
typedef QVector<SearchProperty::SearchResultProperty> SearchResultProperties;
|
||||
typedef QMap<SearchProperty::SearchResultProperty, QVariant> SearchResultPropertyMap;
|
||||
}
|
||||
#endif // SEARCHRESULTPROPERTY_H
|
|
@ -12,8 +12,15 @@ AppSearchTask::AppSearchTask(QObject *parent)
|
|||
this->setParent(parent);
|
||||
qRegisterMetaType<size_t>("size_t");
|
||||
m_pool = new QThreadPool(this);
|
||||
AppInfoTable::self();
|
||||
m_pool->setMaxThreadCount(1);
|
||||
qDBusRegisterMetaType<QMap<QString, QString>>();
|
||||
qDBusRegisterMetaType<QList<QMap<QString, QString>>>();
|
||||
}
|
||||
|
||||
AppSearchTask::~AppSearchTask()
|
||||
{
|
||||
m_pool->clear();
|
||||
m_pool->waitForDone();
|
||||
}
|
||||
|
||||
const QString AppSearchTask::name()
|
||||
|
@ -33,14 +40,14 @@ QString AppSearchTask::getCustomSearchType()
|
|||
|
||||
void AppSearchTask::startSearch(std::shared_ptr<SearchController> searchController)
|
||||
{
|
||||
m_searchController = searchController;
|
||||
AppSearchWorker *appSearchWorker;
|
||||
appSearchWorker = new AppSearchWorker(this, searchController);
|
||||
appSearchWorker = new AppSearchWorker(this);
|
||||
m_pool->start(appSearchWorker);
|
||||
}
|
||||
|
||||
void AppSearchTask::stop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AppSearchTask::sendFinishSignal(size_t searchId)
|
||||
|
@ -49,11 +56,8 @@ void AppSearchTask::sendFinishSignal(size_t searchId)
|
|||
}
|
||||
|
||||
|
||||
AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask, std::shared_ptr<SearchController> searchController) :
|
||||
m_AppSearchTask(AppSarchTask), m_searchController(searchController)
|
||||
AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask): m_appSearchTask(AppSarchTask)
|
||||
{
|
||||
qDBusRegisterMetaType<QMap<QString, QString>>();
|
||||
qDBusRegisterMetaType<QList<QMap<QString, QString>>>();
|
||||
m_interFace = new QDBusInterface("com.kylin.softwarecenter.getsearchresults", "/com/kylin/softwarecenter/getsearchresults",
|
||||
"com.kylin.getsearchresults",
|
||||
QDBusConnection::sessionBus());
|
||||
|
@ -61,76 +65,83 @@ AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask, std::shared_ptr<Se
|
|||
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
|
||||
}
|
||||
m_interFace->setTimeout(1500);
|
||||
m_currentSearchId = m_searchController->getCurrentSearchId();
|
||||
m_currentSearchId = m_appSearchTask->m_searchController->getCurrentSearchId();
|
||||
}
|
||||
|
||||
void AppSearchWorker::run()
|
||||
{
|
||||
QStringList results;
|
||||
QStringList keyWords = m_searchController->getKeyword();
|
||||
ResultDataTypes dataType = m_searchController->getResultDataType(SearchType::Application);
|
||||
AppInfoTable::self()->searchInstallApp(keyWords, results);
|
||||
for (int i = 0; i < results.size() / 3; i++) {
|
||||
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
QVariantList info;
|
||||
if (dataType & UkuiSearch::ApplicationDesktopPath) {
|
||||
info << QVariant(results.at(i*3));
|
||||
}
|
||||
if (dataType & UkuiSearch::ApplicationLocalName) {
|
||||
info << QVariant(results.at(i*3 + 1));
|
||||
}
|
||||
if (dataType & UkuiSearch::ApplicationIconName) {
|
||||
info << QVariant(results.at(i*3 + 2));
|
||||
}
|
||||
if (dataType & UkuiSearch::ApplicationDescription) {//本地应用暂无简介
|
||||
info << QVariant(QString());
|
||||
}
|
||||
if (dataType & UkuiSearch::IsOnlineApplication) {
|
||||
info << QVariant(0);
|
||||
}
|
||||
ResultItem ri(m_currentSearchId, results.at(i*3), info);
|
||||
m_searchController->getDataQueue()->enqueue(ri);
|
||||
m_searchController->finishSearchIdCheck();
|
||||
ApplicationProperties applicationProperties;
|
||||
SearchResultProperties properties = m_appSearchTask->m_searchController->getResultProperties(SearchProperty::SearchType::Application);
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationDesktopPath)) {
|
||||
applicationProperties.append(ApplicationProperty::DesktopFilePath);
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationLocalName)) {
|
||||
applicationProperties.append(ApplicationProperty::LocalName);
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationIconName)) {
|
||||
applicationProperties.append(ApplicationProperty::Icon);
|
||||
}
|
||||
ApplicationInfoMap data = m_appSearchTask->m_appinfo.searchApp(applicationProperties, m_appSearchTask->m_searchController->getKeyword(), ApplicationPropertyMap{{ApplicationProperty::DontDisplay, 0}});
|
||||
for (const QString &desktop : data.keys()) {
|
||||
if (m_appSearchTask->m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
ResultItem item(desktop);
|
||||
item.setSearchId(m_currentSearchId);
|
||||
|
||||
ApplicationPropertyMap oneResult = data.value(desktop);
|
||||
if(oneResult.contains(ApplicationProperty::DesktopFilePath)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::ApplicationDesktopPath, oneResult.value(ApplicationProperty::DesktopFilePath).toString());
|
||||
}
|
||||
if(oneResult.contains(ApplicationProperty::LocalName)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::ApplicationLocalName, oneResult.value(ApplicationProperty::LocalName).toString());
|
||||
}
|
||||
if(oneResult.contains(ApplicationProperty::Icon)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::ApplicationIconName, oneResult.value(ApplicationProperty::Icon).toString());
|
||||
}
|
||||
m_appSearchTask->m_searchController->getDataQueue()->enqueue(item);
|
||||
m_appSearchTask->m_searchController->finishSearchIdCheck();
|
||||
} else {
|
||||
qDebug() << "Search id changed!";
|
||||
m_searchController->finishSearchIdCheck();
|
||||
m_appSearchTask->m_searchController->finishSearchIdCheck();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (m_searchController->isSearchOnlineApps()) {
|
||||
if (m_appSearchTask->m_searchController->isSearchOnlineApps()) {
|
||||
//online app search
|
||||
for (auto keyword : keyWords) {
|
||||
for (auto keyword : m_appSearchTask->m_searchController->getKeyword()) {
|
||||
QDBusReply<QList<QMap<QString, QString>>> reply = m_interFace->call("get_search_result", keyword); //阻塞,直到远程方法调用完成。
|
||||
if(reply.isValid()) {
|
||||
for(int i = 0; i < reply.value().size(); i++) {
|
||||
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
QVariantList info;
|
||||
if (dataType & UkuiSearch::ApplicationDesktopPath) {
|
||||
info << QVariant(reply.value().at(i).value("appname"));
|
||||
if (m_appSearchTask->m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
ResultItem item(m_currentSearchId);
|
||||
item.setItemKey(reply.value().at(i).value("appname"));
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationPkgName)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::ApplicationPkgName, reply.value().at(i).value("appname"));
|
||||
}
|
||||
if (dataType & UkuiSearch::ApplicationLocalName) {
|
||||
QLocale locale;
|
||||
if(locale.language() == QLocale::Chinese) {
|
||||
info << QVariant(reply.value().at(i).value("displayname_cn"));
|
||||
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationLocalName)) {
|
||||
QString localName;
|
||||
if(QLocale::system().language() == QLocale::Chinese) {
|
||||
localName = reply.value().at(i).value("displayname_cn");
|
||||
} else {
|
||||
info << QVariant(reply.value().at(i).value("appname"));
|
||||
localName = reply.value().at(i).value("appname");
|
||||
}
|
||||
item.setValue(SearchProperty::SearchResultProperty::ApplicationLocalName, localName);
|
||||
}
|
||||
if (dataType & UkuiSearch::ApplicationIconName) {
|
||||
info << QVariant(QIcon(reply.value().at(i).value("icon")));
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationIconName)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::ApplicationIconName, reply.value().at(i).value("icon"));
|
||||
}
|
||||
if (dataType & UkuiSearch::ApplicationDescription) {//在线应用有效
|
||||
info << QVariant(reply.value().at(i).value("discription"));
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationDescription)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::ApplicationDescription, reply.value().at(i).value("discription"));
|
||||
}
|
||||
if (dataType & UkuiSearch::IsOnlineApplication) {
|
||||
info << QVariant(1);
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::IsOnlineApplication)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::IsOnlineApplication, 1);
|
||||
}
|
||||
ResultItem ri(m_currentSearchId, reply.value().at(i).value("appname"), info);
|
||||
m_searchController->getDataQueue()->enqueue(ri);
|
||||
m_searchController->finishSearchIdCheck();
|
||||
m_appSearchTask->m_searchController->getDataQueue()->enqueue(item);
|
||||
m_appSearchTask->m_searchController->finishSearchIdCheck();
|
||||
} else {
|
||||
qDebug() << "Search id changed!";
|
||||
m_searchController->finishSearchIdCheck();
|
||||
m_appSearchTask->m_searchController->finishSearchIdCheck();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +152,7 @@ void AppSearchWorker::run()
|
|||
}
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(m_AppSearchTask, "searchFinished", Q_ARG(size_t, m_currentSearchId));
|
||||
QMetaObject::invokeMethod(m_appSearchTask, "searchFinished", Q_ARG(size_t, m_currentSearchId));
|
||||
}
|
||||
|
||||
AppSearchWorker::~AppSearchWorker()
|
||||
|
@ -153,7 +164,7 @@ AppSearchWorker::~AppSearchWorker()
|
|||
|
||||
void AppSearchWorker::sendErrorMsg(const QString &msg)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_AppSearchTask, "searchError",
|
||||
QMetaObject::invokeMethod(m_appSearchTask, "searchError",
|
||||
Q_ARG(size_t, m_currentSearchId),
|
||||
Q_ARG(QString, msg));
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#include "search-task-plugin-iface.h"
|
||||
#include "search-controller.h"
|
||||
#include "result-item.h"
|
||||
#include "app-info-table.h"
|
||||
#include "application-info.h"
|
||||
#include "search-result-property.h"
|
||||
|
||||
namespace UkuiSearch {
|
||||
class AppSearchTask : public SearchTaskPluginIface
|
||||
|
@ -18,6 +19,7 @@ class AppSearchTask : public SearchTaskPluginIface
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit AppSearchTask(QObject *parent);
|
||||
~AppSearchTask();
|
||||
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
|
||||
const QString name();
|
||||
const QString description();
|
||||
|
@ -25,20 +27,22 @@ public:
|
|||
void setEnable(bool enable) {}
|
||||
bool isEnable() { return true;}
|
||||
|
||||
SearchType getSearchType() {return SearchType::Application;}
|
||||
SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::Application;}
|
||||
QString getCustomSearchType();
|
||||
void startSearch(std::shared_ptr<SearchController> searchController);
|
||||
void stop();
|
||||
Q_INVOKABLE void sendFinishSignal(size_t searchId);
|
||||
|
||||
private:
|
||||
ApplicationInfo m_appinfo;
|
||||
std::shared_ptr<SearchController> m_searchController;
|
||||
QThreadPool *m_pool = nullptr;
|
||||
};
|
||||
|
||||
class AppSearchWorker : public QRunnable
|
||||
{
|
||||
public:
|
||||
explicit AppSearchWorker(AppSearchTask *AppSarchTask, std::shared_ptr<SearchController> searchController);
|
||||
explicit AppSearchWorker(AppSearchTask *AppSarchTask);
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
@ -48,8 +52,7 @@ private:
|
|||
void sendErrorMsg(const QString &msg);
|
||||
|
||||
private:
|
||||
AppSearchTask *m_AppSearchTask = nullptr;
|
||||
std::shared_ptr<SearchController> m_searchController;
|
||||
AppSearchTask *m_appSearchTask = nullptr;
|
||||
QDBusInterface *m_interFace = nullptr;
|
||||
size_t m_currentSearchId = 0;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
//Qt
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
#include <utility>
|
||||
|
||||
using namespace UkuiSearch;
|
||||
|
||||
|
@ -27,7 +26,8 @@ FileContentSearchTask::FileContentSearchTask(QObject *parent)
|
|||
|
||||
FileContentSearchTask::~FileContentSearchTask()
|
||||
{
|
||||
|
||||
m_pool->clear();
|
||||
m_pool->waitForDone();
|
||||
}
|
||||
|
||||
PluginInterface::PluginType FileContentSearchTask::pluginType()
|
||||
|
@ -65,9 +65,9 @@ QString FileContentSearchTask::getCustomSearchType()
|
|||
return tr("File Content");
|
||||
}
|
||||
|
||||
SearchType FileContentSearchTask::getSearchType()
|
||||
SearchProperty::SearchType FileContentSearchTask::getSearchType()
|
||||
{
|
||||
return SearchType::FileContent;
|
||||
return SearchProperty::SearchType::FileContent;
|
||||
}
|
||||
|
||||
void FileContentSearchTask::startSearch(std::shared_ptr<SearchController> searchController)
|
||||
|
@ -134,13 +134,28 @@ bool FileContentSearchWorker::execSearch()
|
|||
|
||||
FileContentSearchFilter filter(this);
|
||||
|
||||
Xapian::MSet result = enquire.get_mset(m_searchController->first(), m_searchController->maxResults(), 0, &filter);
|
||||
Xapian::MSet result = enquire.get_mset(0, m_searchController->maxResults(), 0, &filter);
|
||||
|
||||
for (auto it = result.begin(); it != result.end(); ++it) {
|
||||
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
QString path = QString::fromStdString(it.get_document().get_value(CONTENT_DATABASE_PATH_SLOT));
|
||||
|
||||
ResultItem resultItem(m_currentSearchId, path);
|
||||
SearchResultProperties properties = m_searchController->getResultProperties(SearchProperty::SearchType::File);
|
||||
ResultItem resultItem(m_currentSearchId);
|
||||
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FilePath)) {
|
||||
resultItem.setValue(SearchProperty::SearchResultProperty::FilePath, path);
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FileIconName)) {
|
||||
resultItem.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(path).name());
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FileName)) {
|
||||
resultItem.setValue(SearchProperty::SearchResultProperty::FileName, path.section("/", -1));
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ModifiedTime)) {
|
||||
resultItem.setValue(SearchProperty::SearchResultProperty::ModifiedTime,
|
||||
QDateTime::fromString(QString::fromStdString(it.get_document().get_value(3)), "yyyyMMddHHmmsszzz"));
|
||||
}
|
||||
m_searchController->getDataQueue()->enqueue(resultItem);
|
||||
m_searchController->finishSearchIdCheck();
|
||||
|
||||
|
@ -185,16 +200,16 @@ bool FileContentSearchFilter::operator()(const Xapian::Document &doc) const
|
|||
{
|
||||
//在此处对搜索结果进行过滤
|
||||
QString path = QString::fromStdString(doc.get_value(CONTENT_DATABASE_PATH_SLOT));
|
||||
bool isExists = QFileInfo::exists(path);
|
||||
bool inSearchDir = true;
|
||||
if(!QFileInfo::exists(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//如果不指定搜索目录,那么搜索整个数据库
|
||||
if (m_worker && !m_worker->m_validDirectories.empty()) {
|
||||
inSearchDir = std::any_of(m_worker->m_validDirectories.begin(), m_worker->m_validDirectories.end(), [=] (const QString& dir) {
|
||||
return path.startsWith(dir);
|
||||
});
|
||||
//TODO 黑名单
|
||||
for(const QString &dir : m_worker->m_validDirectories) {
|
||||
return FileUtils::isOrUnder(path, dir);
|
||||
}
|
||||
}
|
||||
|
||||
return isExists && inSearchDir;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
bool isEnable() override;
|
||||
|
||||
QString getCustomSearchType() override;
|
||||
SearchType getSearchType() override;
|
||||
SearchProperty::SearchType getSearchType() override;
|
||||
void startSearch(std::shared_ptr<SearchController> searchController) override;
|
||||
void stop() override;
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#include "file-search-task.h"
|
||||
#include "index-status-recorder.h"
|
||||
#include "dir-watcher.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QFile>
|
||||
#include <QQueue>
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
#include <gio/gio.h>
|
||||
#include "index-status-recorder.h"
|
||||
#include "dir-watcher.h"
|
||||
#include "common.h"
|
||||
#include "file-utils.h"
|
||||
|
||||
using namespace UkuiSearch;
|
||||
FileSearchTask::FileSearchTask(QObject *parent)
|
||||
|
@ -19,6 +20,12 @@ FileSearchTask::FileSearchTask(QObject *parent)
|
|||
m_pool->setMaxThreadCount(1);
|
||||
}
|
||||
|
||||
FileSearchTask::~FileSearchTask()
|
||||
{
|
||||
m_pool->clear();
|
||||
m_pool->waitForDone();
|
||||
}
|
||||
|
||||
const QString FileSearchTask::name()
|
||||
{
|
||||
return "File";
|
||||
|
@ -85,11 +92,23 @@ void FileSearchWorker::run()
|
|||
}
|
||||
|
||||
bool finished = true;
|
||||
bool indexed = !DirWatcher::getDirWatcher()->currentIndexableDir().isEmpty();
|
||||
qDebug() << DirWatcher::getDirWatcher()->currentIndexableDir();
|
||||
for(const QString &dir : DirWatcher::getDirWatcher()->currentIndexableDir()) {
|
||||
for(const QString &path : m_searchController->getSearchDir()) {
|
||||
if(!FileUtils::isOrUnder(path, dir)) {
|
||||
indexed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!indexed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//TODO 还需要判断是否为不能建立索引的目录
|
||||
if (IndexStatusRecorder::getInstance()->indexDatabaseEnable()) {
|
||||
if (IndexStatusRecorder::getInstance()->indexDatabaseEnable() && indexed) {
|
||||
qDebug() << "index ready";
|
||||
finished = searchWithIndex();
|
||||
|
||||
} else {
|
||||
if (m_validDirectories.empty()) {
|
||||
//TODO 使用全局的默认可搜索目录
|
||||
|
@ -145,13 +164,27 @@ bool FileSearchWorker::searchWithIndex()
|
|||
enquire.set_query(creatQueryForFileSearch());
|
||||
FileSearchFilter fileSearchFilter(this);
|
||||
|
||||
Xapian::MSet result = enquire.get_mset(m_searchController->first(), m_searchController->maxResults(), 0, &fileSearchFilter);
|
||||
Xapian::MSet result = enquire.get_mset(0, m_searchController->maxResults(), 0, &fileSearchFilter);
|
||||
|
||||
for (auto it = result.begin(); it != result.end(); ++it) {
|
||||
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
std::string data = it.get_document().get_data();
|
||||
|
||||
ResultItem resultItem(m_currentSearchId, QString::fromStdString(data));
|
||||
QString path = QString::fromStdString(it.get_document().get_data());
|
||||
SearchResultProperties properties = m_searchController->getResultProperties(SearchProperty::SearchType::File);
|
||||
ResultItem resultItem(m_currentSearchId);
|
||||
resultItem.setItemKey(path);
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FilePath)) {
|
||||
resultItem.setValue(SearchProperty::SearchResultProperty::FilePath, path);
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FileIconName)) {
|
||||
resultItem.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(path).name());
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FileName)) {
|
||||
resultItem.setValue(SearchProperty::SearchResultProperty::FileName, path.section("/", -1));
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ModifiedTime)) {
|
||||
resultItem.setValue(SearchProperty::SearchResultProperty::ModifiedTime,
|
||||
QDateTime::fromString(QString::fromStdString(it.get_document().get_value(2)), "yyyyMMddHHmmsszzz"));
|
||||
}
|
||||
m_searchController->getDataQueue()->enqueue(resultItem);
|
||||
m_searchController->finishSearchIdCheck();
|
||||
|
||||
|
@ -200,7 +233,6 @@ bool FileSearchWorker::directSearch()
|
|||
if (!dir.exists())
|
||||
continue;
|
||||
infoList = dir.entryInfoList();
|
||||
|
||||
for (const auto &fileInfo : infoList) {
|
||||
if (fileInfo.isDir() && !fileInfo.isSymLink()) {
|
||||
QString newPath = fileInfo.absoluteFilePath();
|
||||
|
@ -216,6 +248,9 @@ bool FileSearchWorker::directSearch()
|
|||
if (m_searchController->isRecurse()) {
|
||||
searchPathQueue.enqueue(newPath);
|
||||
}
|
||||
if (m_searchController->isSearchFileOnly()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
bool matched = false;
|
||||
|
@ -236,7 +271,21 @@ bool FileSearchWorker::directSearch()
|
|||
|
||||
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
if (matched) {
|
||||
ResultItem ri(m_currentSearchId, fileInfo.absoluteFilePath());
|
||||
ResultItem ri(m_currentSearchId);
|
||||
ri.setItemKey(fileInfo.absoluteFilePath());
|
||||
SearchResultProperties properties = m_searchController->getResultProperties(SearchProperty::SearchType::File);
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FilePath)) {
|
||||
ri.setValue(SearchProperty::SearchResultProperty::FilePath, fileInfo.absoluteFilePath());
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FileIconName)) {
|
||||
ri.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(fileInfo.absoluteFilePath()).name());
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::FileName)) {
|
||||
ri.setValue(SearchProperty::SearchResultProperty::FileName, fileInfo.fileName());
|
||||
}
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ModifiedTime)) {
|
||||
ri.setValue(SearchProperty::SearchResultProperty::ModifiedTime, fileInfo.lastModified());
|
||||
}
|
||||
m_searchController->getDataQueue()->enqueue(ri);
|
||||
--maxResults;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ class FileSearchTask : public SearchTaskPluginIface
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit FileSearchTask(QObject *parent);
|
||||
~FileSearchTask();
|
||||
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
|
||||
const QString name();
|
||||
const QString description();
|
||||
|
@ -23,7 +24,7 @@ public:
|
|||
void setEnable(bool enable) {}
|
||||
bool isEnable() { return true;}
|
||||
|
||||
SearchType getSearchType() {return SearchType::File;}
|
||||
SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::File;}
|
||||
QString getCustomSearchType();
|
||||
void startSearch(std::shared_ptr<SearchController> searchController);
|
||||
void stop();
|
||||
|
|
|
@ -1,226 +1,134 @@
|
|||
#include "ukui-search-task.h"
|
||||
#include "ukui-search-task-private.h"
|
||||
#include "search-task-plugin-manager.h"
|
||||
#include <QDebug>
|
||||
using namespace UkuiSearch;
|
||||
UkuiSearchTaskPrivate::UkuiSearchTaskPrivate(UkuiSearchTask *parent)
|
||||
: QObject(parent),
|
||||
q(parent)
|
||||
namespace UkuiSearch {
|
||||
|
||||
class UkuiSearchTaskPrivate
|
||||
{
|
||||
m_searchCotroller = std::make_shared<SearchController>();
|
||||
m_uuid = QUuid::createUuid();
|
||||
friend class UkuiSearchTask;
|
||||
private:
|
||||
std::shared_ptr<SearchController> m_searchCotroller = nullptr;
|
||||
size_t m_searchId = 0;
|
||||
QUuid m_uuid;
|
||||
};
|
||||
}
|
||||
|
||||
UkuiSearchTaskPrivate::~UkuiSearchTaskPrivate()
|
||||
UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate())
|
||||
{
|
||||
this->stop();
|
||||
SearchTaskPluginManager::getInstance()->destroyPlugins(m_uuid);
|
||||
d->m_searchCotroller = std::make_shared<SearchController>();
|
||||
d->m_uuid = QUuid::createUuid();
|
||||
}
|
||||
|
||||
DataQueue<ResultItem> *UkuiSearchTaskPrivate::init()
|
||||
UkuiSearchTask::~UkuiSearchTask()
|
||||
{
|
||||
return m_searchCotroller->initDataQueue();
|
||||
stop();
|
||||
SearchTaskPluginManager::getInstance()->destroyPlugins(d->m_uuid);
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::addSearchDir(const QString &path)
|
||||
DataQueue<ResultItem> *UkuiSearchTask::init()
|
||||
{
|
||||
m_searchCotroller->addSearchDir(path);
|
||||
return d->m_searchCotroller->initDataQueue();
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::setRecurse(bool recurse)
|
||||
void UkuiSearchTask::addSearchDir(const QString &path)
|
||||
{
|
||||
m_searchCotroller->setRecurse(recurse);
|
||||
d->m_searchCotroller->addSearchDir(path);
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::addKeyword(const QString &keyword)
|
||||
void UkuiSearchTask::setRecurse(bool recurse)
|
||||
{
|
||||
m_searchCotroller->addKeyword(keyword);
|
||||
d->m_searchCotroller->setRecurse(recurse);
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::addFileLabel(const QString &label)
|
||||
void UkuiSearchTask::addKeyword(const QString &keyword)
|
||||
{
|
||||
m_searchCotroller->addFileLabel(label);
|
||||
d->m_searchCotroller->addKeyword(keyword);
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::setOnlySearchFile(bool onlySearchFile)
|
||||
void UkuiSearchTask::addFileLabel(const QString &label)
|
||||
{
|
||||
m_searchCotroller->setOnlySearchFile(onlySearchFile);
|
||||
d->m_searchCotroller->addFileLabel(label);
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::setOnlySearchDir(bool onlySearchDir)
|
||||
void UkuiSearchTask::setOnlySearchFile(bool onlySearchFile)
|
||||
{
|
||||
m_searchCotroller->setOnlySearchDir(onlySearchDir);
|
||||
d->m_searchCotroller->setOnlySearchFile(onlySearchFile);
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::setSearchOnlineApps(bool searchOnlineApps)
|
||||
void UkuiSearchTask::setOnlySearchDir(bool onlySearchDir)
|
||||
{
|
||||
m_searchCotroller->setSearchOnlineApps(searchOnlineApps);
|
||||
d->m_searchCotroller->setOnlySearchDir(onlySearchDir);
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::initSearchPlugin(SearchType searchType, const QString& customSearchType)
|
||||
void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
|
||||
{
|
||||
SearchTaskPluginIface *plugin = SearchTaskPluginManager::getInstance()->initPlugins(m_uuid, searchType, customSearchType);
|
||||
d->m_searchCotroller->setSearchOnlineApps(searchOnlineApps);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, const QString &customSearchType)
|
||||
{
|
||||
SearchTaskPluginIface *plugin = SearchTaskPluginManager::getInstance()->initPlugins(d->m_uuid, searchType, customSearchType);
|
||||
if (plugin) {
|
||||
connect(plugin, &SearchTaskPluginIface::searchFinished,this, &UkuiSearchTaskPrivate::searchFinished);
|
||||
connect(plugin, &SearchTaskPluginIface::searchError,this, &UkuiSearchTaskPrivate::searchError);
|
||||
connect(plugin, &SearchTaskPluginIface::searchFinished,this, &UkuiSearchTask::searchFinished);
|
||||
connect(plugin, &SearchTaskPluginIface::searchError,this, &UkuiSearchTask::searchError);
|
||||
} else {
|
||||
qWarning() << "The plugin has been initialized or the plugin failed to load.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool UkuiSearchTaskPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||
bool UkuiSearchTask::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
||||
{
|
||||
return m_searchCotroller->setCustomResultDataType(customSearchType, dataType);
|
||||
return d->m_searchCotroller->setResultProperties(searchType, searchResultProperties);
|
||||
}
|
||||
|
||||
bool UkuiSearchTaskPrivate::setResultDataType(SearchType searchType, ResultDataTypes dataType)
|
||||
void UkuiSearchTask::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||
{
|
||||
return m_searchCotroller->setResultDataType(searchType, dataType);
|
||||
return d->m_searchCotroller->setCustomResultDataType(customSearchType, dataType);
|
||||
}
|
||||
|
||||
size_t UkuiSearchTaskPrivate::startSearch(SearchType searchtype, const QString& customSearchType)
|
||||
size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QString customSearchType)
|
||||
{
|
||||
m_searchId = m_searchCotroller->refreshSearchId();
|
||||
if(m_searchCotroller->getDataQueue() == nullptr) {
|
||||
d->m_searchId = d->m_searchCotroller->refreshSearchId();
|
||||
if(d->m_searchCotroller->getDataQueue() == nullptr) {
|
||||
qWarning() << "the date queue has not been initialized, you need run init first!";
|
||||
}
|
||||
|
||||
m_searchCotroller->refreshDataqueue();
|
||||
d->m_searchCotroller->refreshDataqueue();
|
||||
//plugin manager do async search here
|
||||
if (!SearchTaskPluginManager::getInstance()->startSearch(m_uuid, m_searchCotroller, searchtype, customSearchType)) {
|
||||
Q_EMIT searchError(m_searchCotroller->getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!"));
|
||||
if (!SearchTaskPluginManager::getInstance()->startSearch(d->m_uuid, d->m_searchCotroller, searchtype, customSearchType)) {
|
||||
Q_EMIT searchError(d->m_searchCotroller->getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!"));
|
||||
}
|
||||
|
||||
return m_searchId;
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::stop()
|
||||
{
|
||||
m_searchCotroller->stop();
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::clearKeyWords()
|
||||
{
|
||||
m_searchCotroller->clearKeyWords();
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::clearAllConditions()
|
||||
{
|
||||
m_searchCotroller->clearAllConditions();
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::clearSearchDir()
|
||||
{
|
||||
m_searchCotroller->clearSearchDir();
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::clearFileLabel()
|
||||
{
|
||||
m_searchCotroller->clearFileLabel();
|
||||
}
|
||||
|
||||
void UkuiSearchTaskPrivate::setPagination(unsigned int first, unsigned int maxResults)
|
||||
{
|
||||
m_searchCotroller->setPagination(first, maxResults);
|
||||
}
|
||||
|
||||
UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate(this))
|
||||
{
|
||||
connect(d, &UkuiSearchTaskPrivate::searchFinished, this, &UkuiSearchTask::searchFinished);
|
||||
connect(d, &UkuiSearchTaskPrivate::searchError, this, &UkuiSearchTask::searchError);
|
||||
}
|
||||
|
||||
UkuiSearchTask::~UkuiSearchTask()
|
||||
{
|
||||
}
|
||||
|
||||
DataQueue<ResultItem> *UkuiSearchTask::init()
|
||||
{
|
||||
return d->init();
|
||||
}
|
||||
|
||||
void UkuiSearchTask::addSearchDir(const QString &path)
|
||||
{
|
||||
d->addSearchDir(path);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::setRecurse(bool recurse)
|
||||
{
|
||||
d->setRecurse(recurse);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::addKeyword(const QString &keyword)
|
||||
{
|
||||
d->addKeyword(keyword);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::addFileLabel(const QString &label)
|
||||
{
|
||||
d->addFileLabel(label);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::setOnlySearchFile(bool onlySearchFile)
|
||||
{
|
||||
d->setOnlySearchFile(onlySearchFile);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::setOnlySearchDir(bool onlySearchDir)
|
||||
{
|
||||
d->setOnlySearchDir(onlySearchDir);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
|
||||
{
|
||||
d->setSearchOnlineApps(searchOnlineApps);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::initSearchPlugin(SearchType searchType)
|
||||
{
|
||||
d->initSearchPlugin(searchType);
|
||||
}
|
||||
|
||||
bool UkuiSearchTask::setResultDataType(SearchType searchType, ResultDataTypes dataType)
|
||||
{
|
||||
return d->setResultDataType(searchType, dataType);
|
||||
}
|
||||
|
||||
bool UkuiSearchTask::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||
{
|
||||
return d->setCustomResultDataType(customSearchType, dataType);
|
||||
}
|
||||
|
||||
size_t UkuiSearchTask::startSearch(SearchType searchtype, QString customSearchType)
|
||||
{
|
||||
return d->startSearch(searchtype, customSearchType);
|
||||
return d->m_searchId;
|
||||
}
|
||||
|
||||
void UkuiSearchTask::stop()
|
||||
{
|
||||
d->stop();
|
||||
d->m_searchCotroller->stop();
|
||||
}
|
||||
|
||||
void UkuiSearchTask::clearAllConditions()
|
||||
{
|
||||
d->clearAllConditions();
|
||||
d->m_searchCotroller->clearAllConditions();
|
||||
}
|
||||
|
||||
void UkuiSearchTask::clearKeyWords()
|
||||
{
|
||||
d->clearKeyWords();
|
||||
d->m_searchCotroller->clearKeyWords();
|
||||
}
|
||||
|
||||
void UkuiSearchTask::clearSearchDir()
|
||||
{
|
||||
d->clearSearchDir();
|
||||
d->m_searchCotroller->clearSearchDir();
|
||||
}
|
||||
|
||||
void UkuiSearchTask::clearFileLabel()
|
||||
{
|
||||
d->clearFileLabel();
|
||||
d->m_searchCotroller->clearFileLabel();
|
||||
}
|
||||
|
||||
void UkuiSearchTask::setPagination(unsigned int first, unsigned int maxResults)
|
||||
void UkuiSearchTask::setMaxResultNum(unsigned int maxResults)
|
||||
{
|
||||
d->setPagination(first, maxResults);
|
||||
d->m_searchCotroller->setMaxResultNum(maxResults);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "result-item.h"
|
||||
#include "data-queue.h"
|
||||
#include "common-defines.h"
|
||||
#include "search-result-property.h"
|
||||
namespace UkuiSearch {
|
||||
class UkuiSearchTaskPrivate;
|
||||
class UkuiSearchTask : public QObject
|
||||
|
@ -20,23 +20,28 @@ public:
|
|||
void setOnlySearchFile(bool onlySearchFile);
|
||||
void setOnlySearchDir(bool onlySearchDir);
|
||||
void setSearchOnlineApps(bool searchOnlineApps);
|
||||
void initSearchPlugin(SearchType searchType);
|
||||
/**
|
||||
* @brief initSearchPlugin 初始化搜索插件
|
||||
* @param searchType
|
||||
* @param customSearchType
|
||||
*/
|
||||
void initSearchPlugin(SearchProperty::SearchType searchType, const QString& customSearchType = QString());
|
||||
/**
|
||||
* @brief setResultDataType
|
||||
* @param searchType
|
||||
* @param dataType
|
||||
* @return
|
||||
*/
|
||||
bool setResultDataType(SearchType searchType, UkuiSearch::ResultDataTypes dataType);
|
||||
bool setCustomResultDataType(QString customSearchType, QStringList dataType);
|
||||
bool setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties);
|
||||
void setCustomResultDataType(QString customSearchType, QStringList dataType);
|
||||
|
||||
void clearAllConditions();
|
||||
void clearKeyWords();
|
||||
void clearSearchDir();
|
||||
void clearFileLabel();
|
||||
void setPagination(unsigned int first, unsigned int maxResults);
|
||||
void setMaxResultNum(unsigned int maxResults = 99999999);
|
||||
|
||||
size_t startSearch(SearchType searchtype, QString customSearchType = QString());
|
||||
size_t startSearch(SearchProperty::SearchType searchtype, QString customSearchType = QString());
|
||||
void stop();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
|
@ -30,4 +30,6 @@ void FileSystemWatcherTest::beginSignalTest()
|
|||
|
||||
connect(m_watcher, &FileSystemWatcher::closedWrite,
|
||||
[](const QString& fileUrl) { qDebug() << "ClosedWrite:" << fileUrl; });
|
||||
connect(m_watcher, &FileSystemWatcher::moveTo,
|
||||
[](const QString& fileUrl) { qDebug() << "moveTo:" << fileUrl; });
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item)
|
|||
{
|
||||
QMutexLocker locker(&s_mutex);
|
||||
for(auto it = item.constBegin(); it != item.constEnd(); it++) {
|
||||
PropertyMap propertyinfo = it.value();
|
||||
ApplicationPropertyMap propertyinfo = it.value();
|
||||
for (auto i = propertyinfo.constBegin(); i != propertyinfo.constEnd(); i++) {
|
||||
m_items2BUpdate[it.key()].insert(i.key(), i.value());
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ UkuiSearchAppDataService::UkuiSearchAppDataService(int &argc, char *argv[], cons
|
|||
if (!this->isRunning()) {
|
||||
qDebug() << "First running, I'm in app-db manager dbus rigister.";
|
||||
|
||||
qRegisterMetaType<PropertyMap>("PropertyMap");
|
||||
qDBusRegisterMetaType<PropertyMap>();
|
||||
qRegisterMetaType<ApplicationPropertyMap>("ApplicationPropertyMap");
|
||||
qDBusRegisterMetaType<ApplicationPropertyMap>();
|
||||
|
||||
qRegisterMetaType<ApplicationInfoMap>("ApplicationInfoMap");
|
||||
qDBusRegisterMetaType<ApplicationInfoMap>();
|
||||
|
|
Loading…
Reference in New Issue