更新搜索服务接口,完善应用搜索和文件搜索机制

This commit is contained in:
iaom 2023-03-15 16:39:38 +08:00
parent bf22f0e150
commit d354773177
36 changed files with 647 additions and 547 deletions

View File

@ -22,7 +22,7 @@ namespace UkuiSearch {
return argument; 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>()); argument.beginMap(/*qMetaTypeId<ApplicationProperty::Property>()*/QVariant::Int, qMetaTypeId<QDBusVariant>());
for (auto i = appPropertyInfo.constBegin(); i != appPropertyInfo.constEnd(); ++i) { for (auto i = appPropertyInfo.constBegin(); i != appPropertyInfo.constEnd(); ++i) {
@ -35,7 +35,7 @@ namespace UkuiSearch {
return argument; return argument;
} }
const QDBusArgument &operator >> (const QDBusArgument &argument, PropertyMap &appPropertyInfo) const QDBusArgument &operator >> (const QDBusArgument &argument, ApplicationPropertyMap &appPropertyInfo)
{ {
argument.beginMap(); argument.beginMap();
while (!argument.atEnd()) { while (!argument.atEnd()) {
@ -52,7 +52,7 @@ namespace UkuiSearch {
QDBusArgument &operator << (QDBusArgument &argument, const ApplicationInfoMap &appInfo) 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) { for (auto i = appInfo.constBegin(); i != appInfo.constEnd(); ++i) {
argument.beginMapEntry(); argument.beginMapEntry();
argument << i.key() << i.value(); argument << i.key() << i.value();
@ -67,7 +67,7 @@ namespace UkuiSearch {
argument.beginMap(); argument.beginMap();
while (!argument.atEnd()) { while (!argument.atEnd()) {
QString key; QString key;
PropertyMap value; ApplicationPropertyMap value;
argument.beginMapEntry(); argument.beginMapEntry();
argument >> key >> value; argument >> key >> value;
argument.endMapEntry(); argument.endMapEntry();

View File

@ -25,8 +25,8 @@ static AppInfoTable *global_intance = nullptr;
AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent), q(parent), m_database(new QSqlDatabase()) AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent), q(parent), m_database(new QSqlDatabase())
{ {
//dbus接收数据库信号 //dbus接收数据库信号
qRegisterMetaType<PropertyMap>("PropertyMap"); qRegisterMetaType<ApplicationPropertyMap>("ApplicationPropertyMap");
qDBusRegisterMetaType<PropertyMap>(); qDBusRegisterMetaType<ApplicationPropertyMap>();
qRegisterMetaType<ApplicationInfoMap>("ApplicationInfoMap"); qRegisterMetaType<ApplicationInfoMap>("ApplicationInfoMap");
qDBusRegisterMetaType<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; QString field;
for(const ApplicationProperty::Property &pro : properties) { for(const ApplicationProperty::Property &pro : properties) {
field.append(ApplicationPropertyHelper(pro).dataBaseField() + ","); field.append(ApplicationPropertyHelper(pro).dataBaseField() + ",");
} }
field.remove(field.length() - 1, 1); field.remove(field.length() - 1, 1);
if(field.isEmpty()) {
return true;
}
QSqlQuery query(*d->m_database); QSqlQuery query(*d->m_database);
query.setForwardOnly(true); query.setForwardOnly(true);
query.prepare(QString("SELECT %0 FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFile").arg(field)); 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; 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) { 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); QString sql = QString("SELECT %0 FROM APPINFO").arg(field);
QSqlQuery query(*d->m_database); QSqlQuery query(*d->m_database);
query.setForwardOnly(true); query.setForwardOnly(true);
@ -390,20 +399,26 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties)
return false; return false;
} }
while (query.next()) { while (query.next()) {
PropertyMap propertyMap; ApplicationPropertyMap propertyMap;
for(int i = 0; i< properties.size(); i++) { for(const ApplicationProperty::Property &pro : properties) {
propertyMap.insert(properties.at(i), query.value(i + 1)); 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; 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) { 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; QString condition;
@ -427,20 +442,26 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, Pro
return false; return false;
} }
while (query.next()) { while (query.next()) {
PropertyMap propertyMap; ApplicationPropertyMap propertyMap;
for(int i = 0; i< properties.size(); i++) { for(const ApplicationProperty::Property &pro : properties) {
propertyMap.insert(properties.at(i), query.value(i + 1)); 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; 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) { 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; QString condition;
@ -448,75 +469,22 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, con
condition.append(ApplicationPropertyHelper(prop).dataBaseField() + "=? AND "); condition.append(ApplicationPropertyHelper(prop).dataBaseField() + "=? AND ");
} }
QString cmd; QString keywordCondition;
if (keyword.size() < 2) { for(const QString& keyword : keywords) {
cmd = QString("SELECT %0 FROM APPINFO WHERE %1(LOCAL_NAME || NAME_EN || NAME_ZH || FIRST_LETTER_OF_PINYIN) LIKE ?") if(keyword.size() < 2) {
.arg(field) keywordCondition.append("(ifnull(LOCAL_NAME, '') like ? or ifnull(NAME_EN, '') like ? or ifnull(NAME_ZH, '') like ? or ifnull(FIRST_LETTER_OF_PINYIN, '') like ?) AND");
.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 ?";
} else { } 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); QSqlQuery query(*d->m_database);
query.setForwardOnly(true); query.setForwardOnly(true);
query.prepare(cmd); query.prepare(sql);
int count = 0; int count = 0;
for (const QVariant &conditionValue : restrictions) { for (const QVariant &conditionValue : restrictions) {
@ -524,21 +492,30 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties, con
count++; count++;
} }
for (int i = 0; i < keywords.size(); i++) { for(const QString &keyword : keywords) {
query.bindValue(count + i, "%" + keywords.at(i) + "%"); 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()) { if (!query.exec()) {
qWarning() << d->m_database->lastError() << query.lastError(); qWarning() << d->m_database->lastError() << query.lastError() << query.lastQuery() << query.boundValues();
return false; return false;
} }
while (query.next()) { while (query.next()) {
PropertyMap propertyMap; ApplicationPropertyMap propertyMap;
for(int i = 0; i< properties.size(); i++) { for(const ApplicationProperty::Property &pro : properties) {
propertyMap.insert(properties.at(i), query.value(i + 1)); 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; return true;
} }

View File

@ -20,11 +20,11 @@ public:
AppInfoTable(AppInfoTable &) = delete; AppInfoTable(AppInfoTable &) = delete;
AppInfoTable &operator =(const AppInfoTable &) = delete; AppInfoTable &operator =(const AppInfoTable &) = delete;
bool query(PropertyMap &propertyMap, const QString &desktopFile, Properties properties);
bool query(ApplicationInfoMap &infoMap, Properties properties); bool query(ApplicationPropertyMap &propertyMap, const QString &desktopFile, ApplicationProperties properties);
bool query(ApplicationInfoMap &infoMap, Properties properties, PropertyMap restrictions); bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties);
bool query(ApplicationInfoMap &infoMap, Properties properties, const QString &keyword, PropertyMap restrictions); bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties, ApplicationPropertyMap restrictions);
bool query(ApplicationInfoMap &infoMap, Properties properties, const QStringList &keywords, PropertyMap restrictions); bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions);
/** /**
* @brief AppInfoTable::setAppFavoritesState * @brief AppInfoTable::setAppFavoritesState

View File

@ -26,40 +26,41 @@ ApplicationInfo::~ApplicationInfo()
QVariant UkuiSearch::ApplicationInfo::getInfo(const QString &desktopFile, ApplicationProperty::Property property) QVariant UkuiSearch::ApplicationInfo::getInfo(const QString &desktopFile, ApplicationProperty::Property property)
{ {
PropertyMap map; ApplicationPropertyMap map;
AppInfoTable::self()->query(map, desktopFile, Properties{property}); AppInfoTable::self()->query(map, desktopFile, ApplicationProperties{property});
return map.value(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); AppInfoTable::self()->query(propertyMap, desktopFile, properties);
return propertyMap; return propertyMap;
} }
ApplicationInfoMap ApplicationInfo::getInfo(Properties properties) ApplicationInfoMap ApplicationInfo::getInfo(ApplicationProperties properties)
{ {
ApplicationInfoMap infoMap; ApplicationInfoMap infoMap;
AppInfoTable::self()->query(infoMap, properties); AppInfoTable::self()->query(infoMap, properties);
return infoMap; return infoMap;
} }
ApplicationInfoMap ApplicationInfo::getInfo(Properties properties, PropertyMap restrictions) ApplicationInfoMap ApplicationInfo::getInfo(ApplicationProperties properties, ApplicationPropertyMap restrictions)
{ {
ApplicationInfoMap infoMap; ApplicationInfoMap infoMap;
AppInfoTable::self()->query(infoMap, properties, restrictions); AppInfoTable::self()->query(infoMap, properties, restrictions);
return infoMap; return infoMap;
} }
ApplicationInfoMap ApplicationInfo::searchApp(Properties properties, const QString &keyword, PropertyMap restrictions)
ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties, const QString &keyword, ApplicationPropertyMap restrictions)
{ {
ApplicationInfoMap infoMap; ApplicationInfoMap infoMap;
AppInfoTable::self()->query(infoMap, properties, keyword, restrictions); AppInfoTable::self()->query(infoMap, properties, QStringList{keyword}, restrictions);
return infoMap; return infoMap;
} }
ApplicationInfoMap ApplicationInfo::searchApp(Properties properties, const QStringList &keywords, PropertyMap restrictions) ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions)
{ {
ApplicationInfoMap infoMap; ApplicationInfoMap infoMap;
AppInfoTable::self()->query(infoMap, properties, keywords, restrictions); AppInfoTable::self()->query(infoMap, properties, keywords, restrictions);

View File

@ -25,13 +25,13 @@ public:
* @param properties * @param properties
* @return * @return
*/ */
PropertyMap getInfo(const QString &desktopFile, Properties properties); ApplicationPropertyMap getInfo(const QString &desktopFile, ApplicationProperties properties);
/** /**
* @brief getInfo * @brief getInfo
* @param property * @param property
* @return * @return
*/ */
ApplicationInfoMap getInfo(Properties properties); ApplicationInfoMap getInfo(ApplicationProperties properties);
/** /**
* @brief ApplicationInfo::getInfo * @brief ApplicationInfo::getInfo
@ -40,7 +40,7 @@ public:
* @param properties: Each application's information should contain these properties * @param properties: Each application's information should contain these properties
* @return ApplicationInfoMap: the search result * @return ApplicationInfoMap: the search result
*/ */
ApplicationInfoMap getInfo(Properties properties, PropertyMap restrictions); ApplicationInfoMap getInfo(ApplicationProperties properties, ApplicationPropertyMap restrictions);
/** /**
* @brief ApplicationInfo::searchApp * @brief ApplicationInfo::searchApp
@ -48,8 +48,8 @@ public:
* @param installAppInfoRes: the search results of applications * @param installAppInfoRes: the search results of applications
* @return ApplicationInfoMap: the search result * @return ApplicationInfoMap: the search result
*/ */
ApplicationInfoMap searchApp(Properties properties, const QString &keyword, PropertyMap restrictions); ApplicationInfoMap searchApp(ApplicationProperties properties, const QString &keyword, ApplicationPropertyMap restrictions);
ApplicationInfoMap searchApp(Properties properties, const QStringList &keywords, PropertyMap restrictions); ApplicationInfoMap searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions);
/** /**
* @brief ApplicationInfo::setAppFavoritesState * @brief ApplicationInfo::setAppFavoritesState

View File

@ -36,9 +36,9 @@ enum Property {
DontDisplay //是否不需要显示设置了Nodisplay等字段 DontDisplay //是否不需要显示设置了Nodisplay等字段
}; };
} //namespace ApplicationProperty } //namespace ApplicationProperty
typedef QVector<ApplicationProperty::Property> Properties; typedef QVector<ApplicationProperty::Property> ApplicationProperties;
typedef QMap<ApplicationProperty::Property, QVariant> PropertyMap; typedef QMap<ApplicationProperty::Property, QVariant> ApplicationPropertyMap;
typedef QMap<QString, PropertyMap> ApplicationInfoMap; // desktopFile->PropertyMap typedef QMap<QString, ApplicationPropertyMap> ApplicationInfoMap; // desktopFile->ApplicationPropertyMap
} }
Q_DECLARE_METATYPE(UkuiSearch::ApplicationProperty::Property) Q_DECLARE_METATYPE(UkuiSearch::ApplicationProperty::Property)
#endif // APPLICATIONPROPERTY_H #endif // APPLICATIONPROPERTY_H

View File

@ -23,13 +23,14 @@ AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearch
m_timer->moveToThread(this); m_timer->moveToThread(this);
m_appSearchResults = m_appSearchTask->init(); m_appSearchResults = m_appSearchTask->init();
m_appSearchTask->initSearchPlugin(SearchType::Application); m_appSearchTask->initSearchPlugin(SearchProperty::SearchType::Application);
m_appSearchTask->setSearchOnlineApps(true); m_appSearchTask->setSearchOnlineApps(true);
m_appSearchTask->setResultDataType(SearchType::Application, UkuiSearch::ApplicationDesktopPath | m_appSearchTask->setResultProperties(SearchProperty::SearchType::Application,
UkuiSearch::ApplicationLocalName | SearchResultProperties{SearchProperty::SearchResultProperty::ApplicationDesktopPath,
UkuiSearch::ApplicationIconName | SearchProperty::SearchResultProperty::ApplicationLocalName,
UkuiSearch::ApplicationDescription | SearchProperty::SearchResultProperty::ApplicationIconName,
UkuiSearch::IsOnlineApplication); SearchProperty::SearchResultProperty::ApplicationDescription,
SearchProperty::SearchResultProperty::IsOnlineApplication});
} }
AppSearchPlugin::~AppSearchPlugin() AppSearchPlugin::~AppSearchPlugin()
@ -65,7 +66,7 @@ void AppSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIface
m_searchResult = searchResult; m_searchResult = searchResult;
m_appSearchTask->clearKeyWords(); m_appSearchTask->clearKeyWords();
m_appSearchTask->addKeyword(keyword); 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); // AppSearch *appsearch = new AppSearch(searchResult, m_appSearchResults, m_appSearchTask, keyword, uniqueSymbol);
// m_pool.start(appsearch); // m_pool.start(appsearch);
@ -163,7 +164,8 @@ void AppSearchPlugin::run()
{ {
while(!isInterruptionRequested()) { while(!isInterruptionRequested()) {
ResultItem oneResult = m_appSearchResults->tryDequeue(); 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()) { if(!m_timer->isActive()) {
m_timer->start(); m_timer->start();
} }
@ -171,14 +173,14 @@ void AppSearchPlugin::run()
} else { } else {
m_timer->stop(); m_timer->stop();
SearchPluginIface::ResultInfo ri; SearchPluginIface::ResultInfo ri;
ri.actionKey = oneResult.getExtral().at(0).toString(); ri.actionKey = data.value(SearchProperty::SearchResultProperty::ApplicationDesktopPath).toString();
ri.name = oneResult.getExtral().at(1).toString(); ri.name = data.value(SearchProperty::SearchResultProperty::ApplicationLocalName).toString();
ri.icon = XdgIcon::fromTheme(oneResult.getExtral().at(2).toString(), QIcon(":/res/icons/unknown.svg")); ri.icon = XdgIcon::fromTheme(data.value(SearchProperty::SearchResultProperty::ApplicationIconName).toString(), QIcon(":/res/icons/unknown.svg"));
SearchPluginIface::DescriptionInfo description; SearchPluginIface::DescriptionInfo description;
description.key = QString(tr("Application 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.description.append(description);
ri.type = oneResult.getExtral().at(4).toInt(); ri.type = data.value(SearchProperty::SearchResultProperty::IsOnlineApplication).toInt();
m_searchResult->enqueue(ri); m_searchResult->enqueue(ri);
} }

View File

@ -20,7 +20,10 @@ static const int OCR_MIN_SIZE = 200;
static const QByteArray UKUI_SEARCH_SCHEMAS = QByteArrayLiteral("org.ukui.search.settings"); static const QByteArray UKUI_SEARCH_SCHEMAS = QByteArrayLiteral("org.ukui.search.settings");
static const QString SEARCH_METHOD_KEY = QStringLiteral("fileIndexEnable"); static const QString SEARCH_METHOD_KEY = QStringLiteral("fileIndexEnable");
static const QString INDEX_DATABASE_VERSION = QStringLiteral("1.0.0"); 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");

View File

@ -57,7 +57,10 @@ bool fileContentIndexer::index()
m_document.addTerm("PARENTTERM" + FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep))); m_document.addTerm("PARENTTERM" + FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep)));
m_document.addValue(1, m_filePath); m_document.addValue(1, m_filePath);
m_document.addValue(2, suffix); 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; return true;
} }

View File

@ -84,6 +84,8 @@ void IndexScheduler::stop()
m_state = Stop; m_state = Stop;
qDebug() << "Index scheduler has been stopped."; qDebug() << "Index scheduler has been stopped.";
Q_EMIT stateChange(m_state); 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() void IndexScheduler::start()

View File

@ -39,7 +39,8 @@ public:
Initializing = 0, Initializing = 0,
Error = 1, Error = 1,
Ready = 2, Ready = 2,
Updating = 3 Updating = 3,
Off = 4
}; };
Q_ENUM(State) Q_ENUM(State)

View File

@ -109,7 +109,8 @@ unix {
appdata/application-property.h \ appdata/application-property.h \
appdata/application-property-helper.h \ appdata/application-property-helper.h \
searchinterface/ukui-search-task.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/* header.files += development-files/header-files/*

View File

@ -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

View File

@ -6,7 +6,7 @@
#include <QObject> #include <QObject>
#include <QtPlugin> #include <QtPlugin>
#include "plugin-iface.h" #include "plugin-iface.h"
#include "common-defines.h" #include "search-result-property.h"
#include "search-controller.h" #include "search-controller.h"
@ -16,7 +16,7 @@ class SearchTaskPluginIface : public QObject, public PluginInterface
Q_OBJECT Q_OBJECT
public: public:
virtual QString getCustomSearchType() = 0; virtual QString getCustomSearchType() = 0;
virtual SearchType getSearchType() = 0; virtual SearchProperty::SearchType getSearchType() = 0;
//Asynchronous,multithread. //Asynchronous,multithread.
virtual void startSearch(std::shared_ptr<SearchController> searchController) = 0; virtual void startSearch(std::shared_ptr<SearchController> searchController) = 0;
virtual void stop() = 0; virtual void stop() = 0;

View File

@ -16,16 +16,16 @@ SearchTaskPluginManager *SearchTaskPluginManager::getInstance()
return global_instance; return global_instance;
} }
void SearchTaskPluginManager::initPlugins(SearchType searchType) void SearchTaskPluginManager::initPlugins(SearchProperty::SearchType searchType)
{ {
switch (searchType) { switch (searchType) {
case SearchType::File: case SearchProperty::SearchType::File:
registerBuildinPlugin(new FileSearchTask(this)); registerBuildinPlugin(new FileSearchTask(this));
break; break;
case SearchType::FileContent: case SearchProperty::SearchType::FileContent:
registerBuildinPlugin(new FileContentSearchTask(this)); registerBuildinPlugin(new FileContentSearchTask(this));
break; break;
case SearchType::Application: case SearchProperty::SearchType::Application:
registerBuildinPlugin(new AppSearchTask(this)); registerBuildinPlugin(new AppSearchTask(this));
default: default:
break; 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); size_t type = static_cast<size_t>(searchType);
qDebug() << "search type" << type; 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)) { if (m_managedPlugins.contains(uuid)) {
ManagedPlugin* managedPlugin = m_managedPlugins.value(uuid); ManagedPlugin* managedPlugin = m_managedPlugins.value(uuid);
SearchTaskPluginIface *plugin = nullptr; SearchTaskPluginIface *plugin = nullptr;
if (searchType == SearchType::Custom) { if (searchType == SearchProperty::SearchType::Custom) {
plugin = managedPlugin->externalPlugin(customType); plugin = managedPlugin->externalPlugin(customType);
} else { } else {
@ -110,10 +110,10 @@ bool SearchTaskPluginManager::startSearch(const QUuid &uuid, std::shared_ptr<Sea
return false; return false;
} }
SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchType searchType, const QString& customType) SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchProperty::SearchType searchType, const QString& customType)
{ {
SearchTaskPluginIface *searchPlugin = nullptr; SearchTaskPluginIface *searchPlugin = nullptr;
if (searchType == SearchType::Custom) { if (searchType == SearchProperty::SearchType::Custom) {
if (m_loadedPluginPath.contains(customType)) { if (m_loadedPluginPath.contains(customType)) {
QPluginLoader pluginLoader(m_loadedPluginPath.value(customType)); QPluginLoader pluginLoader(m_loadedPluginPath.value(customType));
QObject *plugin = pluginLoader.instance(); QObject *plugin = pluginLoader.instance();
@ -124,13 +124,13 @@ SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchType searchType,
} else { } else {
switch (searchType) { switch (searchType) {
case SearchType::File: case SearchProperty::SearchType::File:
searchPlugin = new FileSearchTask(this); searchPlugin = new FileSearchTask(this);
break; break;
case SearchType::FileContent: case SearchProperty::SearchType::FileContent:
searchPlugin = new FileContentSearchTask(this); searchPlugin = new FileContentSearchTask(this);
break; break;
case SearchType::Application: case SearchProperty::SearchType::Application:
searchPlugin = new AppSearchTask(this); searchPlugin = new AppSearchTask(this);
break; break;
default: 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)) { if (!m_managedPlugins.contains(uuid)) {
m_managedPlugins.insert(uuid, new ManagedPlugin(nullptr)); m_managedPlugins.insert(uuid, new ManagedPlugin(nullptr));
@ -156,7 +156,7 @@ SearchTaskPluginIface *SearchTaskPluginManager::initPlugins(const QUuid& uuid, S
SearchTaskPluginIface *plugin = getPlugin(searchType, customType); SearchTaskPluginIface *plugin = getPlugin(searchType, customType);
bool succeed = false; bool succeed = false;
if (searchType == SearchType::Custom) { if (searchType == SearchProperty::SearchType::Custom) {
succeed = m_managedPlugins.value(uuid)->insertExternalPlugin(customType, plugin); succeed = m_managedPlugins.value(uuid)->insertExternalPlugin(customType, plugin);
} else { } 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) { if (plugin) {
auto type = static_cast<size_t>(searchType); auto type = static_cast<size_t>(searchType);
@ -213,7 +213,7 @@ bool ManagedPlugin::insertExternalPlugin(const QString &customType, SearchTaskPl
return false; return false;
} }
inline SearchTaskPluginIface *ManagedPlugin::internalPlugin(const SearchType &searchType) inline SearchTaskPluginIface *ManagedPlugin::internalPlugin(const SearchProperty::SearchType &searchType)
{ {
auto type = static_cast<size_t>(searchType); auto type = static_cast<size_t>(searchType);
if (m_internalPlugins.contains(type)) { if (m_internalPlugins.contains(type)) {

View File

@ -15,10 +15,10 @@ public:
explicit ManagedPlugin(QObject *parent) : QObject(parent) {} explicit ManagedPlugin(QObject *parent) : QObject(parent) {}
~ManagedPlugin() override; ~ManagedPlugin() override;
inline SearchTaskPluginIface *internalPlugin(const SearchType& searchType); inline SearchTaskPluginIface *internalPlugin(const SearchProperty::SearchType& searchType);
inline SearchTaskPluginIface *externalPlugin(const QString& customType); 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); bool insertExternalPlugin(const QString& customType, SearchTaskPluginIface* plugin);
private: private:
@ -31,16 +31,16 @@ class SearchTaskPluginManager : public QObject
Q_OBJECT Q_OBJECT
public: public:
static SearchTaskPluginManager *getInstance(); static SearchTaskPluginManager *getInstance();
void initPlugins(SearchType searchType); void initPlugins(SearchProperty::SearchType searchType);
SearchTaskPluginIface *initPlugins(const QUuid&, SearchType, const QString& customType = QString()); SearchTaskPluginIface *initPlugins(const QUuid&, SearchProperty::SearchType, const QString& customType = QString());
bool registerPlugin(SearchTaskPluginIface *plugin); bool registerPlugin(SearchTaskPluginIface *plugin);
bool registerBuildinPlugin(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); 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); 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); void registerPluginPath(const QString& customType, const QString& pluginPath);
Q_SIGNALS: Q_SIGNALS:

View File

@ -1,81 +1,69 @@
#include "result-item.h" #include "result-item.h"
#include "result-item-private.h"
using namespace UkuiSearch; 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) { d->m_searchId = searchId;
m_extral.append(info);
}
} }
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 size_t ResultItem::getSearchId() const
{ {
return d->getSearchId(); return d->m_searchId;
} }
QString ResultItem::getItemKey() const 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() ResultItem::~ResultItem()
@ -85,9 +73,6 @@ ResultItem::~ResultItem()
d = nullptr; 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());
} }

View File

@ -2,7 +2,7 @@
#define RESULTITEM_H #define RESULTITEM_H
#include <QString> #include <QString>
#include <QVariant> #include "search-result-property.h"
namespace UkuiSearch { namespace UkuiSearch {
class ResultItemPrivate; class ResultItemPrivate;
class ResultItem class ResultItem
@ -13,11 +13,15 @@ public:
ResultItem(const ResultItem &item); ResultItem(const ResultItem &item);
explicit ResultItem(const size_t searchId); explicit ResultItem(const size_t searchId);
explicit ResultItem(const QString itemKey); explicit ResultItem(const QString &itemKey);
explicit ResultItem(const size_t searchId, const QString itemKey, QVariantList extral = QVariantList()); 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; size_t getSearchId() const;
QString getItemKey() 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: private:
ResultItemPrivate *d; ResultItemPrivate *d;

View File

@ -4,6 +4,7 @@
#include <QMutex> #include <QMutex>
#include <QMap> #include <QMap>
#include "search-controller.h" #include "search-controller.h"
#include "search-result-property.h"
namespace UkuiSearch { namespace UkuiSearch {
class SearchControllerPrivate class SearchControllerPrivate
@ -26,7 +27,7 @@ public:
size_t getCurrentSearchId(); size_t getCurrentSearchId();
DataQueue<ResultItem>* getDataQueue(); DataQueue<ResultItem>* getDataQueue();
ResultDataTypes getResultDataType(SearchType searchType); SearchResultProperties getResultProperties(SearchProperty::SearchType searchType);
QStringList getCustomResultDataType(QString customSearchType); QStringList getCustomResultDataType(QString customSearchType);
bool beginSearchIdCheck(size_t searchId); bool beginSearchIdCheck(size_t searchId);
void finishSearchIdCheck(); void finishSearchIdCheck();
@ -44,16 +45,15 @@ public:
void clearSearchDir(); void clearSearchDir();
void clearFileLabel(); void clearFileLabel();
bool setResultDataType(SearchType searchType, ResultDataTypes dataType); bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
bool setCustomResultDataType(QString customSearchType, QStringList dataType); void setCustomResultDataType(QString customSearchType, QStringList dataType);
/** /**
* @brief * @brief
* @param first
* @param maxResults * @param maxResults
*/ */
void setPagination(unsigned int first, unsigned int maxResults); void setMaxResultNum(unsigned int maxResults);
unsigned int first() const;
unsigned int maxResults() const; unsigned int maxResults() const;
private: private:
@ -74,11 +74,9 @@ private:
bool m_onlySearchFile = false; bool m_onlySearchFile = false;
bool m_onlySearchDir = false; bool m_onlySearchDir = false;
bool m_searchOnlineApps = false; bool m_searchOnlineApps = false;
unsigned int m_first = 0;
unsigned int m_maxResults = 100; //默认取100条结果 unsigned int m_maxResults = 100; //默认取100条结果
QMap<SearchType, ResultDataTypes> m_searchType2ResultDataType; QMap<SearchProperty::SearchType, SearchResultProperties> m_searchType2ResultProperties;
QMap<QString, QStringList> m_customSearchType2ResultDataType; QMap<QString, QStringList> m_customSearchType2ResultDataType;
}; };
} }

View File

@ -96,9 +96,9 @@ DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
return m_sharedDataQueue.get(); 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) QStringList SearchControllerPrivate::getCustomResultDataType(QString customSearchType)
@ -209,31 +209,23 @@ void SearchControllerPrivate::clearFileLabel()
m_FileLabels.clear(); m_FileLabels.clear();
} }
bool SearchControllerPrivate::setResultDataType(SearchType searchType, ResultDataTypes dataType) bool SearchControllerPrivate::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
{ {
bool res(true); bool res(true);
m_searchType2ResultDataType[searchType] = dataType; m_searchType2ResultProperties[searchType] = searchResultProperties;
return res; return res;
} }
bool SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType) void SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
{ {
bool res(true);
m_customSearchType2ResultDataType[customSearchType] = dataType; 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; m_maxResults = maxResults;
} }
unsigned int SearchControllerPrivate::first() const
{
return m_first;
}
unsigned int SearchControllerPrivate::maxResults() const unsigned int SearchControllerPrivate::maxResults() const
{ {
return m_maxResults; return m_maxResults;
@ -291,9 +283,9 @@ DataQueue<ResultItem> *SearchController::getDataQueue()
return d->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) QStringList SearchController::getCustomResultDataType(QString customSearchType)
@ -401,14 +393,9 @@ void SearchController::clearFileLabel()
d->clearFileLabel(); d->clearFileLabel();
} }
void SearchController::setPagination(unsigned int first, unsigned int maxResults) void SearchController::setMaxResultNum(unsigned int maxResults)
{ {
d->setPagination(first, maxResults); d->setMaxResultNum(maxResults);
}
unsigned int SearchController::first() const
{
return d->first();
} }
unsigned int SearchController::maxResults() const unsigned int SearchController::maxResults() const
@ -416,12 +403,12 @@ unsigned int SearchController::maxResults() const
return d->maxResults(); 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); return d->setCustomResultDataType(customSearchType, dataType);
} }

View File

@ -4,7 +4,7 @@
#include <QStringList> #include <QStringList>
#include <memory> #include <memory>
#include "data-queue.h" #include "data-queue.h"
#include "common-defines.h" #include "search-result-property.h"
//todo: url parser? //todo: url parser?
namespace UkuiSearch { namespace UkuiSearch {
class UkuiSearchTask; class UkuiSearchTask;
@ -39,7 +39,7 @@ public:
//以下方法插件可以调用 //以下方法插件可以调用
size_t getCurrentSearchId(); size_t getCurrentSearchId();
DataQueue<ResultItem>* getDataQueue(); DataQueue<ResultItem>* getDataQueue();
ResultDataTypes getResultDataType(SearchType searchType); SearchResultProperties getResultProperties(SearchProperty::SearchType searchType);
QStringList getCustomResultDataType(QString customSearchType); QStringList getCustomResultDataType(QString customSearchType);
bool beginSearchIdCheck(size_t searchId); bool beginSearchIdCheck(size_t searchId);
void finishSearchIdCheck(); void finishSearchIdCheck();
@ -57,12 +57,12 @@ public:
void clearSearchDir(); void clearSearchDir();
void clearFileLabel(); void clearFileLabel();
void setPagination(unsigned int first, unsigned int maxResults); void setMaxResultNum(unsigned int maxResults);
unsigned int first() const; unsigned int first() const;
unsigned int maxResults() const; unsigned int maxResults() const;
bool setResultDataType(SearchType searchType, ResultDataTypes dataType); bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
bool setCustomResultDataType(QString customSearchType, QStringList dataType); void setCustomResultDataType(QString customSearchType, QStringList dataType);
private: private:
std::shared_ptr<SearchController> m_parent = nullptr; std::shared_ptr<SearchController> m_parent = nullptr;
SearchControllerPrivate *d = nullptr; SearchControllerPrivate *d = nullptr;

View File

@ -2,15 +2,18 @@ INCLUDEPATH += $$PWD
include(searchtasks/search-tasks.pri) include(searchtasks/search-tasks.pri)
HEADERS += \ HEADERS += \
$$PWD/result-item-private.h \ # $$PWD/result-item-private.h \
$$PWD/search-controller-private.h \ $$PWD/search-controller-private.h \
$$PWD/search-controller.h \ $$PWD/search-controller.h \
$$PWD/result-item.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 $$PWD/ukui-search-task.h
SOURCES += \ SOURCES += \
$$PWD/search-controller.cpp \ $$PWD/search-controller.cpp \
$$PWD/result-item.cpp \ $$PWD/result-item.cpp \
$$PWD/search-result-property-info.cpp \
$$PWD/ukui-search-task.cpp $$PWD/ukui-search-task.cpp

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -12,8 +12,15 @@ AppSearchTask::AppSearchTask(QObject *parent)
this->setParent(parent); this->setParent(parent);
qRegisterMetaType<size_t>("size_t"); qRegisterMetaType<size_t>("size_t");
m_pool = new QThreadPool(this); m_pool = new QThreadPool(this);
AppInfoTable::self();
m_pool->setMaxThreadCount(1); 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() const QString AppSearchTask::name()
@ -33,14 +40,14 @@ QString AppSearchTask::getCustomSearchType()
void AppSearchTask::startSearch(std::shared_ptr<SearchController> searchController) void AppSearchTask::startSearch(std::shared_ptr<SearchController> searchController)
{ {
m_searchController = searchController;
AppSearchWorker *appSearchWorker; AppSearchWorker *appSearchWorker;
appSearchWorker = new AppSearchWorker(this, searchController); appSearchWorker = new AppSearchWorker(this);
m_pool->start(appSearchWorker); m_pool->start(appSearchWorker);
} }
void AppSearchTask::stop() void AppSearchTask::stop()
{ {
} }
void AppSearchTask::sendFinishSignal(size_t searchId) 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) : AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask): m_appSearchTask(AppSarchTask)
m_AppSearchTask(AppSarchTask), m_searchController(searchController)
{ {
qDBusRegisterMetaType<QMap<QString, QString>>();
qDBusRegisterMetaType<QList<QMap<QString, QString>>>();
m_interFace = new QDBusInterface("com.kylin.softwarecenter.getsearchresults", "/com/kylin/softwarecenter/getsearchresults", m_interFace = new QDBusInterface("com.kylin.softwarecenter.getsearchresults", "/com/kylin/softwarecenter/getsearchresults",
"com.kylin.getsearchresults", "com.kylin.getsearchresults",
QDBusConnection::sessionBus()); QDBusConnection::sessionBus());
@ -61,76 +65,83 @@ AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask, std::shared_ptr<Se
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
} }
m_interFace->setTimeout(1500); m_interFace->setTimeout(1500);
m_currentSearchId = m_searchController->getCurrentSearchId(); m_currentSearchId = m_appSearchTask->m_searchController->getCurrentSearchId();
} }
void AppSearchWorker::run() void AppSearchWorker::run()
{ {
QStringList results; QStringList results;
QStringList keyWords = m_searchController->getKeyword(); ApplicationProperties applicationProperties;
ResultDataTypes dataType = m_searchController->getResultDataType(SearchType::Application); SearchResultProperties properties = m_appSearchTask->m_searchController->getResultProperties(SearchProperty::SearchType::Application);
AppInfoTable::self()->searchInstallApp(keyWords, results); if(properties.contains(SearchProperty::SearchResultProperty::ApplicationDesktopPath)) {
for (int i = 0; i < results.size() / 3; i++) { applicationProperties.append(ApplicationProperty::DesktopFilePath);
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) { }
QVariantList info; if(properties.contains(SearchProperty::SearchResultProperty::ApplicationLocalName)) {
if (dataType & UkuiSearch::ApplicationDesktopPath) { applicationProperties.append(ApplicationProperty::LocalName);
info << QVariant(results.at(i*3)); }
} if(properties.contains(SearchProperty::SearchResultProperty::ApplicationIconName)) {
if (dataType & UkuiSearch::ApplicationLocalName) { applicationProperties.append(ApplicationProperty::Icon);
info << QVariant(results.at(i*3 + 1)); }
} ApplicationInfoMap data = m_appSearchTask->m_appinfo.searchApp(applicationProperties, m_appSearchTask->m_searchController->getKeyword(), ApplicationPropertyMap{{ApplicationProperty::DontDisplay, 0}});
if (dataType & UkuiSearch::ApplicationIconName) { for (const QString &desktop : data.keys()) {
info << QVariant(results.at(i*3 + 2)); if (m_appSearchTask->m_searchController->beginSearchIdCheck(m_currentSearchId)) {
} ResultItem item(desktop);
if (dataType & UkuiSearch::ApplicationDescription) {//本地应用暂无简介 item.setSearchId(m_currentSearchId);
info << QVariant(QString());
} ApplicationPropertyMap oneResult = data.value(desktop);
if (dataType & UkuiSearch::IsOnlineApplication) { if(oneResult.contains(ApplicationProperty::DesktopFilePath)) {
info << QVariant(0); item.setValue(SearchProperty::SearchResultProperty::ApplicationDesktopPath, oneResult.value(ApplicationProperty::DesktopFilePath).toString());
} }
ResultItem ri(m_currentSearchId, results.at(i*3), info); if(oneResult.contains(ApplicationProperty::LocalName)) {
m_searchController->getDataQueue()->enqueue(ri); item.setValue(SearchProperty::SearchResultProperty::ApplicationLocalName, oneResult.value(ApplicationProperty::LocalName).toString());
m_searchController->finishSearchIdCheck(); }
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 { } else {
qDebug() << "Search id changed!"; qDebug() << "Search id changed!";
m_searchController->finishSearchIdCheck(); m_appSearchTask->m_searchController->finishSearchIdCheck();
return; return;
} }
} }
if (m_searchController->isSearchOnlineApps()) { if (m_appSearchTask->m_searchController->isSearchOnlineApps()) {
//online app search //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); //阻塞,直到远程方法调用完成。 QDBusReply<QList<QMap<QString, QString>>> reply = m_interFace->call("get_search_result", keyword); //阻塞,直到远程方法调用完成。
if(reply.isValid()) { if(reply.isValid()) {
for(int i = 0; i < reply.value().size(); i++) { for(int i = 0; i < reply.value().size(); i++) {
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) { if (m_appSearchTask->m_searchController->beginSearchIdCheck(m_currentSearchId)) {
QVariantList info; ResultItem item(m_currentSearchId);
if (dataType & UkuiSearch::ApplicationDesktopPath) { item.setItemKey(reply.value().at(i).value("appname"));
info << QVariant(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(properties.contains(SearchProperty::SearchResultProperty::ApplicationLocalName)) {
if(locale.language() == QLocale::Chinese) { QString localName;
info << QVariant(reply.value().at(i).value("displayname_cn")); if(QLocale::system().language() == QLocale::Chinese) {
localName = reply.value().at(i).value("displayname_cn");
} else { } 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) { if(properties.contains(SearchProperty::SearchResultProperty::ApplicationIconName)) {
info << QVariant(QIcon(reply.value().at(i).value("icon"))); item.setValue(SearchProperty::SearchResultProperty::ApplicationIconName, reply.value().at(i).value("icon"));
} }
if (dataType & UkuiSearch::ApplicationDescription) {//在线应用有效 if(properties.contains(SearchProperty::SearchResultProperty::ApplicationDescription)) {
info << QVariant(reply.value().at(i).value("discription")); item.setValue(SearchProperty::SearchResultProperty::ApplicationDescription, reply.value().at(i).value("discription"));
} }
if (dataType & UkuiSearch::IsOnlineApplication) { if(properties.contains(SearchProperty::SearchResultProperty::IsOnlineApplication)) {
info << QVariant(1); item.setValue(SearchProperty::SearchResultProperty::IsOnlineApplication, 1);
} }
ResultItem ri(m_currentSearchId, reply.value().at(i).value("appname"), info); m_appSearchTask->m_searchController->getDataQueue()->enqueue(item);
m_searchController->getDataQueue()->enqueue(ri); m_appSearchTask->m_searchController->finishSearchIdCheck();
m_searchController->finishSearchIdCheck();
} else { } else {
qDebug() << "Search id changed!"; qDebug() << "Search id changed!";
m_searchController->finishSearchIdCheck(); m_appSearchTask->m_searchController->finishSearchIdCheck();
return; 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() AppSearchWorker::~AppSearchWorker()
@ -153,7 +164,7 @@ AppSearchWorker::~AppSearchWorker()
void AppSearchWorker::sendErrorMsg(const QString &msg) void AppSearchWorker::sendErrorMsg(const QString &msg)
{ {
QMetaObject::invokeMethod(m_AppSearchTask, "searchError", QMetaObject::invokeMethod(m_appSearchTask, "searchError",
Q_ARG(size_t, m_currentSearchId), Q_ARG(size_t, m_currentSearchId),
Q_ARG(QString, msg)); Q_ARG(QString, msg));
} }

View File

@ -9,7 +9,8 @@
#include "search-task-plugin-iface.h" #include "search-task-plugin-iface.h"
#include "search-controller.h" #include "search-controller.h"
#include "result-item.h" #include "result-item.h"
#include "app-info-table.h" #include "application-info.h"
#include "search-result-property.h"
namespace UkuiSearch { namespace UkuiSearch {
class AppSearchTask : public SearchTaskPluginIface class AppSearchTask : public SearchTaskPluginIface
@ -18,6 +19,7 @@ class AppSearchTask : public SearchTaskPluginIface
Q_OBJECT Q_OBJECT
public: public:
explicit AppSearchTask(QObject *parent); explicit AppSearchTask(QObject *parent);
~AppSearchTask();
PluginType pluginType() {return PluginType::SearchTaskPlugin;} PluginType pluginType() {return PluginType::SearchTaskPlugin;}
const QString name(); const QString name();
const QString description(); const QString description();
@ -25,20 +27,22 @@ public:
void setEnable(bool enable) {} void setEnable(bool enable) {}
bool isEnable() { return true;} bool isEnable() { return true;}
SearchType getSearchType() {return SearchType::Application;} SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::Application;}
QString getCustomSearchType(); QString getCustomSearchType();
void startSearch(std::shared_ptr<SearchController> searchController); void startSearch(std::shared_ptr<SearchController> searchController);
void stop(); void stop();
Q_INVOKABLE void sendFinishSignal(size_t searchId); Q_INVOKABLE void sendFinishSignal(size_t searchId);
private: private:
ApplicationInfo m_appinfo;
std::shared_ptr<SearchController> m_searchController;
QThreadPool *m_pool = nullptr; QThreadPool *m_pool = nullptr;
}; };
class AppSearchWorker : public QRunnable class AppSearchWorker : public QRunnable
{ {
public: public:
explicit AppSearchWorker(AppSearchTask *AppSarchTask, std::shared_ptr<SearchController> searchController); explicit AppSearchWorker(AppSearchTask *AppSarchTask);
protected: protected:
void run(); void run();
@ -48,8 +52,7 @@ private:
void sendErrorMsg(const QString &msg); void sendErrorMsg(const QString &msg);
private: private:
AppSearchTask *m_AppSearchTask = nullptr; AppSearchTask *m_appSearchTask = nullptr;
std::shared_ptr<SearchController> m_searchController;
QDBusInterface *m_interFace = nullptr; QDBusInterface *m_interFace = nullptr;
size_t m_currentSearchId = 0; size_t m_currentSearchId = 0;
}; };

View File

@ -13,7 +13,6 @@
//Qt //Qt
#include <QIcon> #include <QIcon>
#include <QDebug> #include <QDebug>
#include <utility>
using namespace UkuiSearch; using namespace UkuiSearch;
@ -27,7 +26,8 @@ FileContentSearchTask::FileContentSearchTask(QObject *parent)
FileContentSearchTask::~FileContentSearchTask() FileContentSearchTask::~FileContentSearchTask()
{ {
m_pool->clear();
m_pool->waitForDone();
} }
PluginInterface::PluginType FileContentSearchTask::pluginType() PluginInterface::PluginType FileContentSearchTask::pluginType()
@ -65,9 +65,9 @@ QString FileContentSearchTask::getCustomSearchType()
return tr("File Content"); 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) void FileContentSearchTask::startSearch(std::shared_ptr<SearchController> searchController)
@ -134,13 +134,28 @@ bool FileContentSearchWorker::execSearch()
FileContentSearchFilter filter(this); 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) { for (auto it = result.begin(); it != result.end(); ++it) {
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) { if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
QString path = QString::fromStdString(it.get_document().get_value(CONTENT_DATABASE_PATH_SLOT)); 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->getDataQueue()->enqueue(resultItem);
m_searchController->finishSearchIdCheck(); 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)); QString path = QString::fromStdString(doc.get_value(CONTENT_DATABASE_PATH_SLOT));
bool isExists = QFileInfo::exists(path); if(!QFileInfo::exists(path)) {
bool inSearchDir = true; return false;
}
//如果不指定搜索目录,那么搜索整个数据库 //如果不指定搜索目录,那么搜索整个数据库
if (m_worker && !m_worker->m_validDirectories.empty()) { 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) { for(const QString &dir : m_worker->m_validDirectories) {
return path.startsWith(dir); return FileUtils::isOrUnder(path, dir);
}); }
//TODO 黑名单
} }
return isExists && inSearchDir; return true;
} }

View File

@ -32,7 +32,7 @@ public:
bool isEnable() override; bool isEnable() override;
QString getCustomSearchType() override; QString getCustomSearchType() override;
SearchType getSearchType() override; SearchProperty::SearchType getSearchType() override;
void startSearch(std::shared_ptr<SearchController> searchController) override; void startSearch(std::shared_ptr<SearchController> searchController) override;
void stop() override; void stop() override;

View File

@ -1,14 +1,15 @@
#include "file-search-task.h" #include "file-search-task.h"
#include "index-status-recorder.h"
#include "dir-watcher.h"
#include "common.h"
#include <QDir> #include <QDir>
#include <QUrl> #include <QUrl>
#include <QFile> #include <QFile>
#include <QQueue> #include <QQueue>
#include <QDebug> #include <QDebug>
#include <QDateTime>
#include <gio/gio.h> #include <gio/gio.h>
#include "index-status-recorder.h"
#include "dir-watcher.h"
#include "common.h"
#include "file-utils.h"
using namespace UkuiSearch; using namespace UkuiSearch;
FileSearchTask::FileSearchTask(QObject *parent) FileSearchTask::FileSearchTask(QObject *parent)
@ -19,6 +20,12 @@ FileSearchTask::FileSearchTask(QObject *parent)
m_pool->setMaxThreadCount(1); m_pool->setMaxThreadCount(1);
} }
FileSearchTask::~FileSearchTask()
{
m_pool->clear();
m_pool->waitForDone();
}
const QString FileSearchTask::name() const QString FileSearchTask::name()
{ {
return "File"; return "File";
@ -85,11 +92,23 @@ void FileSearchWorker::run()
} }
bool finished = true; 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 还需要判断是否为不能建立索引的目录 //TODO 还需要判断是否为不能建立索引的目录
if (IndexStatusRecorder::getInstance()->indexDatabaseEnable()) { if (IndexStatusRecorder::getInstance()->indexDatabaseEnable() && indexed) {
qDebug() << "index ready"; qDebug() << "index ready";
finished = searchWithIndex(); finished = searchWithIndex();
} else { } else {
if (m_validDirectories.empty()) { if (m_validDirectories.empty()) {
//TODO 使用全局的默认可搜索目录 //TODO 使用全局的默认可搜索目录
@ -145,13 +164,27 @@ bool FileSearchWorker::searchWithIndex()
enquire.set_query(creatQueryForFileSearch()); enquire.set_query(creatQueryForFileSearch());
FileSearchFilter fileSearchFilter(this); 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) { for (auto it = result.begin(); it != result.end(); ++it) {
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) { if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
std::string data = it.get_document().get_data(); QString path = QString::fromStdString(it.get_document().get_data());
SearchResultProperties properties = m_searchController->getResultProperties(SearchProperty::SearchType::File);
ResultItem resultItem(m_currentSearchId, QString::fromStdString(data)); 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->getDataQueue()->enqueue(resultItem);
m_searchController->finishSearchIdCheck(); m_searchController->finishSearchIdCheck();
@ -200,7 +233,6 @@ bool FileSearchWorker::directSearch()
if (!dir.exists()) if (!dir.exists())
continue; continue;
infoList = dir.entryInfoList(); infoList = dir.entryInfoList();
for (const auto &fileInfo : infoList) { for (const auto &fileInfo : infoList) {
if (fileInfo.isDir() && !fileInfo.isSymLink()) { if (fileInfo.isDir() && !fileInfo.isSymLink()) {
QString newPath = fileInfo.absoluteFilePath(); QString newPath = fileInfo.absoluteFilePath();
@ -216,6 +248,9 @@ bool FileSearchWorker::directSearch()
if (m_searchController->isRecurse()) { if (m_searchController->isRecurse()) {
searchPathQueue.enqueue(newPath); searchPathQueue.enqueue(newPath);
} }
if (m_searchController->isSearchFileOnly()) {
continue;
}
} }
bool matched = false; bool matched = false;
@ -236,7 +271,21 @@ bool FileSearchWorker::directSearch()
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) { if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
if (matched) { 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); m_searchController->getDataQueue()->enqueue(ri);
--maxResults; --maxResults;
} }

View File

@ -16,6 +16,7 @@ class FileSearchTask : public SearchTaskPluginIface
Q_OBJECT Q_OBJECT
public: public:
explicit FileSearchTask(QObject *parent); explicit FileSearchTask(QObject *parent);
~FileSearchTask();
PluginType pluginType() {return PluginType::SearchTaskPlugin;} PluginType pluginType() {return PluginType::SearchTaskPlugin;}
const QString name(); const QString name();
const QString description(); const QString description();
@ -23,7 +24,7 @@ public:
void setEnable(bool enable) {} void setEnable(bool enable) {}
bool isEnable() { return true;} bool isEnable() { return true;}
SearchType getSearchType() {return SearchType::File;} SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::File;}
QString getCustomSearchType(); QString getCustomSearchType();
void startSearch(std::shared_ptr<SearchController> searchController); void startSearch(std::shared_ptr<SearchController> searchController);
void stop(); void stop();

View File

@ -1,226 +1,134 @@
#include "ukui-search-task.h" #include "ukui-search-task.h"
#include "ukui-search-task-private.h"
#include "search-task-plugin-manager.h" #include "search-task-plugin-manager.h"
#include <QDebug> #include <QDebug>
using namespace UkuiSearch; using namespace UkuiSearch;
UkuiSearchTaskPrivate::UkuiSearchTaskPrivate(UkuiSearchTask *parent) namespace UkuiSearch {
: QObject(parent),
q(parent) class UkuiSearchTaskPrivate
{ {
m_searchCotroller = std::make_shared<SearchController>(); friend class UkuiSearchTask;
m_uuid = QUuid::createUuid(); 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(); d->m_searchCotroller = std::make_shared<SearchController>();
SearchTaskPluginManager::getInstance()->destroyPlugins(m_uuid); 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) { if (plugin) {
connect(plugin, &SearchTaskPluginIface::searchFinished,this, &UkuiSearchTaskPrivate::searchFinished); connect(plugin, &SearchTaskPluginIface::searchFinished,this, &UkuiSearchTask::searchFinished);
connect(plugin, &SearchTaskPluginIface::searchError,this, &UkuiSearchTaskPrivate::searchError); connect(plugin, &SearchTaskPluginIface::searchError,this, &UkuiSearchTask::searchError);
} else { } else {
qWarning() << "The plugin has been initialized or the plugin failed to load."; qWarning() << "The plugin has been initialized or the plugin failed to load.";
} }
} }
bool UkuiSearchTask::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
bool UkuiSearchTaskPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
{ {
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(); d->m_searchId = d->m_searchCotroller->refreshSearchId();
if(m_searchCotroller->getDataQueue() == nullptr) { if(d->m_searchCotroller->getDataQueue() == nullptr) {
qWarning() << "the date queue has not been initialized, you need run init first!"; 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 //plugin manager do async search here
if (!SearchTaskPluginManager::getInstance()->startSearch(m_uuid, m_searchCotroller, searchtype, customSearchType)) { if (!SearchTaskPluginManager::getInstance()->startSearch(d->m_uuid, d->m_searchCotroller, searchtype, customSearchType)) {
Q_EMIT searchError(m_searchCotroller->getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!")); Q_EMIT searchError(d->m_searchCotroller->getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!"));
} }
return m_searchId; return d->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);
} }
void UkuiSearchTask::stop() void UkuiSearchTask::stop()
{ {
d->stop(); d->m_searchCotroller->stop();
} }
void UkuiSearchTask::clearAllConditions() void UkuiSearchTask::clearAllConditions()
{ {
d->clearAllConditions(); d->m_searchCotroller->clearAllConditions();
} }
void UkuiSearchTask::clearKeyWords() void UkuiSearchTask::clearKeyWords()
{ {
d->clearKeyWords(); d->m_searchCotroller->clearKeyWords();
} }
void UkuiSearchTask::clearSearchDir() void UkuiSearchTask::clearSearchDir()
{ {
d->clearSearchDir(); d->m_searchCotroller->clearSearchDir();
} }
void UkuiSearchTask::clearFileLabel() 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);
} }

View File

@ -3,7 +3,7 @@
#include "result-item.h" #include "result-item.h"
#include "data-queue.h" #include "data-queue.h"
#include "common-defines.h" #include "search-result-property.h"
namespace UkuiSearch { namespace UkuiSearch {
class UkuiSearchTaskPrivate; class UkuiSearchTaskPrivate;
class UkuiSearchTask : public QObject class UkuiSearchTask : public QObject
@ -20,23 +20,28 @@ public:
void setOnlySearchFile(bool onlySearchFile); void setOnlySearchFile(bool onlySearchFile);
void setOnlySearchDir(bool onlySearchDir); void setOnlySearchDir(bool onlySearchDir);
void setSearchOnlineApps(bool searchOnlineApps); 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 * @brief setResultDataType
* @param searchType * @param searchType
* @param dataType * @param dataType
* @return * @return
*/ */
bool setResultDataType(SearchType searchType, UkuiSearch::ResultDataTypes dataType); bool setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties);
bool setCustomResultDataType(QString customSearchType, QStringList dataType); void setCustomResultDataType(QString customSearchType, QStringList dataType);
void clearAllConditions(); void clearAllConditions();
void clearKeyWords(); void clearKeyWords();
void clearSearchDir(); void clearSearchDir();
void clearFileLabel(); 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(); void stop();
Q_SIGNALS: Q_SIGNALS:

View File

@ -30,4 +30,6 @@ void FileSystemWatcherTest::beginSignalTest()
connect(m_watcher, &FileSystemWatcher::closedWrite, connect(m_watcher, &FileSystemWatcher::closedWrite,
[](const QString& fileUrl) { qDebug() << "ClosedWrite:" << fileUrl; }); [](const QString& fileUrl) { qDebug() << "ClosedWrite:" << fileUrl; });
connect(m_watcher, &FileSystemWatcher::moveTo,
[](const QString& fileUrl) { qDebug() << "moveTo:" << fileUrl; });
} }

View File

@ -18,7 +18,7 @@ void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item)
{ {
QMutexLocker locker(&s_mutex); QMutexLocker locker(&s_mutex);
for(auto it = item.constBegin(); it != item.constEnd(); it++) { 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++) { for (auto i = propertyinfo.constBegin(); i != propertyinfo.constEnd(); i++) {
m_items2BUpdate[it.key()].insert(i.key(), i.value()); m_items2BUpdate[it.key()].insert(i.key(), i.value());
} }

View File

@ -20,8 +20,8 @@ UkuiSearchAppDataService::UkuiSearchAppDataService(int &argc, char *argv[], cons
if (!this->isRunning()) { if (!this->isRunning()) {
qDebug() << "First running, I'm in app-db manager dbus rigister."; qDebug() << "First running, I'm in app-db manager dbus rigister.";
qRegisterMetaType<PropertyMap>("PropertyMap"); qRegisterMetaType<ApplicationPropertyMap>("ApplicationPropertyMap");
qDBusRegisterMetaType<PropertyMap>(); qDBusRegisterMetaType<ApplicationPropertyMap>();
qRegisterMetaType<ApplicationInfoMap>("ApplicationInfoMap"); qRegisterMetaType<ApplicationInfoMap>("ApplicationInfoMap");
qDBusRegisterMetaType<ApplicationInfoMap>(); qDBusRegisterMetaType<ApplicationInfoMap>();