精简代码;完善搜索服务插件生命周期管理;增加搜索搜索隐藏文件功能
This commit is contained in:
parent
0c2ef7bee2
commit
cbf833fa08
|
@ -34,7 +34,7 @@ class SearchTaskPluginIface : public QObject, public PluginInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
virtual void setController(const std::shared_ptr<SearchController> &searchController) = 0;
|
virtual void setController(const SearchController &searchController) = 0;
|
||||||
virtual QString getCustomSearchType() = 0;
|
virtual QString getCustomSearchType() = 0;
|
||||||
virtual SearchProperty::SearchType getSearchType() = 0;
|
virtual SearchProperty::SearchType getSearchType() = 0;
|
||||||
//Asynchronous,multithread.
|
//Asynchronous,multithread.
|
||||||
|
|
|
@ -76,13 +76,13 @@ SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchProperty::Search
|
||||||
} else {
|
} else {
|
||||||
switch (searchType) {
|
switch (searchType) {
|
||||||
case SearchProperty::SearchType::File:
|
case SearchProperty::SearchType::File:
|
||||||
searchPlugin = new FileSearchTask(this);
|
searchPlugin = new FileSearchTask();
|
||||||
break;
|
break;
|
||||||
case SearchProperty::SearchType::FileContent:
|
case SearchProperty::SearchType::FileContent:
|
||||||
searchPlugin = new FileContentSearchTask(this);
|
searchPlugin = new FileContentSearchTask();
|
||||||
break;
|
break;
|
||||||
case SearchProperty::SearchType::Application:
|
case SearchProperty::SearchType::Application:
|
||||||
searchPlugin = new AppSearchTask(this);
|
searchPlugin = new AppSearchTask();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -148,6 +148,8 @@ void SearchTaskPluginManager::destroyPlugins(const QUuid &uuid)
|
||||||
|
|
||||||
ManagedPlugin::~ManagedPlugin()
|
ManagedPlugin::~ManagedPlugin()
|
||||||
{
|
{
|
||||||
|
qDeleteAll(m_internalPlugins);
|
||||||
|
qDeleteAll(m_externalPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ManagedPlugin::insertInternalPlugin(const SearchProperty::SearchType &searchType, SearchTaskPluginIface *plugin)
|
bool ManagedPlugin::insertInternalPlugin(const SearchProperty::SearchType &searchType, SearchTaskPluginIface *plugin)
|
||||||
|
@ -163,7 +165,6 @@ bool ManagedPlugin::insertInternalPlugin(const SearchProperty::SearchType &searc
|
||||||
|
|
||||||
plugin->deleteLater();
|
plugin->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
#ifndef SEARCHCONTROLLERPRIVATE_H
|
|
||||||
#define SEARCHCONTROLLERPRIVATE_H
|
|
||||||
|
|
||||||
#include <QMutex>
|
|
||||||
#include <QMap>
|
|
||||||
#include "search-controller.h"
|
|
||||||
#include "search-result-property.h"
|
|
||||||
namespace UkuiSearch {
|
|
||||||
|
|
||||||
class SearchControllerPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit SearchControllerPrivate(SearchController *parent);
|
|
||||||
~SearchControllerPrivate();
|
|
||||||
size_t refreshSearchId();
|
|
||||||
DataQueue<ResultItem>* refreshDataqueue();
|
|
||||||
DataQueue<ResultItem>* initDataQueue();
|
|
||||||
|
|
||||||
void addSearchDir(const QString &path);
|
|
||||||
void setRecurse(bool recurse = true);
|
|
||||||
void addKeyword(const QString &keyword);
|
|
||||||
void setActiveKeywordSegmentation(bool active);
|
|
||||||
void addFileLabel(const QString &label);
|
|
||||||
void setOnlySearchFile(bool onlySearchFile);
|
|
||||||
void setOnlySearchDir(bool onlySearchDir);
|
|
||||||
void setSearchOnlineApps(bool searchOnlineApps);
|
|
||||||
|
|
||||||
size_t getCurrentSearchId();
|
|
||||||
DataQueue<ResultItem>* getDataQueue();
|
|
||||||
SearchResultProperties getResultProperties(SearchProperty::SearchType searchType);
|
|
||||||
QStringList getCustomResultDataType(QString customSearchType);
|
|
||||||
bool beginSearchIdCheck(size_t searchId);
|
|
||||||
void finishSearchIdCheck();
|
|
||||||
void stop();
|
|
||||||
QStringList getSearchDir();
|
|
||||||
bool isRecurse();
|
|
||||||
QStringList getKeyword();
|
|
||||||
bool isKeywordSegmentationActived();
|
|
||||||
QStringList getFileLabel();
|
|
||||||
bool isSearchFileOnly();
|
|
||||||
bool isSearchDirOnly();
|
|
||||||
bool isSearchOnlineApps();
|
|
||||||
void clearAllConditions();
|
|
||||||
void clearKeyWords();
|
|
||||||
void clearSearchDir();
|
|
||||||
void clearFileLabel();
|
|
||||||
|
|
||||||
bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
|
|
||||||
void setCustomResultDataType(QString customSearchType, QStringList dataType);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
* @param maxResults 每次搜索结果集的数量
|
|
||||||
*/
|
|
||||||
void setMaxResultNum(unsigned int maxResults);
|
|
||||||
void setInformNum(int num = 0);
|
|
||||||
|
|
||||||
unsigned int maxResults() const;
|
|
||||||
int informNum() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void copyData();
|
|
||||||
|
|
||||||
std::shared_ptr<DataQueue<ResultItem>> m_sharedDataQueue = nullptr;
|
|
||||||
size_t m_searchId = 0;
|
|
||||||
QMutex m_searchIdMutex;
|
|
||||||
SearchController *q = nullptr;
|
|
||||||
std::shared_ptr<SearchController> m_formerController = nullptr;
|
|
||||||
|
|
||||||
QStringList m_keywords;
|
|
||||||
QStringList m_searchDirs;
|
|
||||||
QStringList m_FileLabels;
|
|
||||||
bool m_recurse = true;
|
|
||||||
bool m_activeKeywordSegmentation = false;
|
|
||||||
bool m_onlySearchFile = false;
|
|
||||||
bool m_onlySearchDir = false;
|
|
||||||
bool m_searchOnlineApps = false;
|
|
||||||
unsigned int m_maxResults = 100; //默认取100条结果
|
|
||||||
int m_informNum = 0;
|
|
||||||
|
|
||||||
QMap<SearchProperty::SearchType, SearchResultProperties> m_searchType2ResultProperties;
|
|
||||||
QMap<QString, QStringList> m_customSearchType2ResultDataType;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // SEARCHCONTROLLERPRIVATE_H
|
|
|
@ -1,392 +1,230 @@
|
||||||
#include "search-controller.h"
|
#include "search-controller.h"
|
||||||
#include "search-controller-private.h"
|
#include <QMutex>
|
||||||
#include "ukui-search-task.h"
|
#include <QMap>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
using namespace UkuiSearch;
|
#include "search-result-property.h"
|
||||||
SearchControllerPrivate::SearchControllerPrivate(SearchController *parent)
|
#include "ukui-search-task.h"
|
||||||
: q(parent),
|
namespace UkuiSearch {
|
||||||
m_formerController(q->m_parent) //如果构造参数里包含父节点智能指针,则子节点带有一个智能指针指向父节点
|
|
||||||
{
|
|
||||||
copyData();
|
|
||||||
}
|
|
||||||
|
|
||||||
SearchControllerPrivate::~SearchControllerPrivate()
|
class SearchControllerPrivate
|
||||||
{
|
{
|
||||||
}
|
public:
|
||||||
|
void clearAllConditions();
|
||||||
|
|
||||||
size_t SearchControllerPrivate::refreshSearchId()
|
std::shared_ptr<DataQueue<ResultItem>> m_sharedDataQueue = nullptr;
|
||||||
{
|
size_t m_searchId = 0;
|
||||||
m_searchIdMutex.lock();
|
QMutex m_searchIdMutex;
|
||||||
m_searchId += 1;
|
QStringList m_keywords;
|
||||||
m_searchIdMutex.unlock();
|
QStringList m_searchDirs;
|
||||||
return m_searchId;
|
QStringList m_FileLabels;
|
||||||
}
|
bool m_recurse = true;
|
||||||
|
bool m_activeKeywordSegmentation = false;
|
||||||
DataQueue<ResultItem> *SearchControllerPrivate::refreshDataqueue()
|
bool m_onlySearchFile = false;
|
||||||
{
|
bool m_onlySearchDir = false;
|
||||||
if(!m_sharedDataQueue.get()) {
|
bool m_searchOnlineApps = false;
|
||||||
// m_dataQueue = new DataQueue<ResultItem>;
|
bool m_searchHiddenFiles = false;
|
||||||
m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
|
unsigned int m_maxResults = 100; //默认取100条结果
|
||||||
return m_sharedDataQueue.get();
|
int m_informNum = 0;
|
||||||
}
|
QMap<SearchProperty::SearchType, SearchResultProperties> m_searchType2ResultProperties;
|
||||||
m_sharedDataQueue.get()->clear();
|
QMap<QString, QStringList> m_customSearchType2ResultDataType;
|
||||||
return m_sharedDataQueue.get();
|
};
|
||||||
}
|
|
||||||
|
|
||||||
DataQueue<ResultItem> *SearchControllerPrivate::initDataQueue()
|
|
||||||
{
|
|
||||||
if(!m_sharedDataQueue.get()) {
|
|
||||||
m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
|
|
||||||
return m_sharedDataQueue.get();
|
|
||||||
}
|
|
||||||
return m_sharedDataQueue.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::addSearchDir(const QString &path)
|
|
||||||
{
|
|
||||||
m_searchDirs.append(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::setRecurse(bool recurse)
|
|
||||||
{
|
|
||||||
m_recurse = recurse;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::addKeyword(const QString &keyword)
|
|
||||||
{
|
|
||||||
m_keywords.append(keyword);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::setActiveKeywordSegmentation(bool active)
|
|
||||||
{
|
|
||||||
m_activeKeywordSegmentation = active;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::addFileLabel(const QString &label)
|
|
||||||
{
|
|
||||||
m_FileLabels.append(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::setOnlySearchFile(bool onlySearchFile)
|
|
||||||
{
|
|
||||||
m_onlySearchFile = onlySearchFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::setOnlySearchDir(bool onlySearchDir)
|
|
||||||
{
|
|
||||||
m_onlySearchDir = onlySearchDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::setSearchOnlineApps(bool searchOnlineApps)
|
|
||||||
{
|
|
||||||
m_searchOnlineApps = searchOnlineApps;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t SearchControllerPrivate::getCurrentSearchId()
|
|
||||||
{
|
|
||||||
m_searchIdMutex.lock();
|
|
||||||
size_t searchId = m_searchId;
|
|
||||||
m_searchIdMutex.unlock();
|
|
||||||
|
|
||||||
return searchId;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
|
|
||||||
{
|
|
||||||
return m_sharedDataQueue.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
SearchResultProperties SearchControllerPrivate::getResultProperties(SearchProperty::SearchType searchType)
|
|
||||||
{
|
|
||||||
return m_searchType2ResultProperties[searchType];
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList SearchControllerPrivate::getCustomResultDataType(QString customSearchType)
|
|
||||||
{
|
|
||||||
return m_customSearchType2ResultDataType[customSearchType];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SearchControllerPrivate::beginSearchIdCheck(size_t searchId)
|
|
||||||
{
|
|
||||||
if(q->m_parent) {
|
|
||||||
return q->m_parent->beginSearchIdCheck(searchId);
|
|
||||||
}
|
|
||||||
m_searchIdMutex.lock();
|
|
||||||
return m_searchId == searchId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::finishSearchIdCheck()
|
|
||||||
{
|
|
||||||
if(q->m_parent) {
|
|
||||||
return q->m_parent->finishSearchIdCheck();
|
|
||||||
}
|
|
||||||
m_searchIdMutex.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::stop()
|
|
||||||
{
|
|
||||||
m_searchIdMutex.lock();
|
|
||||||
m_searchId += 1;
|
|
||||||
m_searchIdMutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList SearchControllerPrivate::getSearchDir()
|
|
||||||
{
|
|
||||||
return m_searchDirs;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SearchControllerPrivate::isRecurse()
|
|
||||||
{
|
|
||||||
return m_recurse;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList SearchControllerPrivate::getKeyword()
|
|
||||||
{
|
|
||||||
return m_keywords;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SearchControllerPrivate::isKeywordSegmentationActived()
|
|
||||||
{
|
|
||||||
return m_activeKeywordSegmentation;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList SearchControllerPrivate::getFileLabel()
|
|
||||||
{
|
|
||||||
return m_FileLabels;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SearchControllerPrivate::isSearchFileOnly()
|
|
||||||
{
|
|
||||||
return m_onlySearchFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SearchControllerPrivate::isSearchDirOnly()
|
|
||||||
{
|
|
||||||
return m_onlySearchDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SearchControllerPrivate::isSearchOnlineApps()
|
|
||||||
{
|
|
||||||
return m_searchOnlineApps;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::copyData()
|
|
||||||
{
|
|
||||||
if(m_formerController.get()) {
|
|
||||||
m_searchId = m_formerController->d->m_searchId;
|
|
||||||
m_sharedDataQueue = m_formerController->d->m_sharedDataQueue;
|
|
||||||
m_keywords = m_formerController->d->m_keywords;
|
|
||||||
m_searchDirs = m_formerController->d->m_searchDirs;
|
|
||||||
m_FileLabels = m_formerController->d->m_FileLabels;
|
|
||||||
m_onlySearchFile = m_formerController->d->m_onlySearchFile;
|
|
||||||
m_onlySearchDir = m_formerController->d->m_onlySearchDir;
|
|
||||||
m_recurse = m_formerController->d->m_recurse;
|
|
||||||
m_activeKeywordSegmentation = m_formerController->d->m_activeKeywordSegmentation;
|
|
||||||
m_maxResults = m_formerController->d->m_maxResults;
|
|
||||||
m_informNum = m_formerController->d->m_informNum;
|
|
||||||
m_searchOnlineApps = m_formerController->d->m_searchOnlineApps;
|
|
||||||
m_searchType2ResultProperties = m_formerController->d->m_searchType2ResultProperties;
|
|
||||||
m_customSearchType2ResultDataType = m_formerController->d->m_customSearchType2ResultDataType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::clearAllConditions()
|
void SearchControllerPrivate::clearAllConditions()
|
||||||
{
|
|
||||||
clearKeyWords();
|
|
||||||
clearSearchDir();
|
|
||||||
clearFileLabel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::clearKeyWords()
|
|
||||||
{
|
{
|
||||||
m_keywords.clear();
|
m_keywords.clear();
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::clearSearchDir()
|
|
||||||
{
|
|
||||||
m_searchDirs.clear();
|
m_searchDirs.clear();
|
||||||
}
|
|
||||||
|
|
||||||
void SearchControllerPrivate::clearFileLabel()
|
|
||||||
{
|
|
||||||
m_FileLabels.clear();
|
m_FileLabels.clear();
|
||||||
|
m_recurse = true;
|
||||||
|
m_activeKeywordSegmentation = false;
|
||||||
|
m_onlySearchFile = false;
|
||||||
|
m_onlySearchDir = false;
|
||||||
|
m_searchOnlineApps = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchControllerPrivate::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
SearchController::SearchController(): d(new SearchControllerPrivate)
|
||||||
{
|
{
|
||||||
bool res(true);
|
|
||||||
m_searchType2ResultProperties[searchType] = searchResultProperties;
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
SearchController::SearchController(const SearchController &other):d(other.d)
|
||||||
{
|
{
|
||||||
m_customSearchType2ResultDataType[customSearchType] = dataType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchControllerPrivate::setMaxResultNum(unsigned int maxResults)
|
SearchController &SearchController::operator =(const SearchController &other)
|
||||||
{
|
{
|
||||||
m_maxResults = maxResults;
|
d = other.d;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
SearchController &SearchController::operator=(SearchController &&other) Q_DECL_NOEXCEPT
|
||||||
void SearchControllerPrivate::setInformNum(int num)
|
|
||||||
{
|
|
||||||
if(num >= 0) {
|
|
||||||
m_informNum = num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int SearchControllerPrivate::maxResults() const
|
|
||||||
{
|
|
||||||
return m_maxResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SearchControllerPrivate::informNum() const
|
|
||||||
{
|
|
||||||
return m_informNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
SearchController::SearchController(std::shared_ptr<SearchController> parent) : m_parent(parent), d(new SearchControllerPrivate(this))
|
|
||||||
{
|
{
|
||||||
|
d = other.d;
|
||||||
|
other.d.reset();
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchController::~SearchController()
|
SearchController::~SearchController()
|
||||||
{
|
{
|
||||||
if(d) {
|
d.reset();
|
||||||
delete d;
|
|
||||||
d = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DataQueue<ResultItem> *SearchController::refreshDataqueue()
|
DataQueue<ResultItem> *SearchController::refreshDataqueue()
|
||||||
{
|
{
|
||||||
return d->refreshDataqueue();
|
if(!d->m_sharedDataQueue.get()) {
|
||||||
|
// m_dataQueue = new DataQueue<ResultItem>;
|
||||||
|
d->m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
|
||||||
|
return d->m_sharedDataQueue.get();
|
||||||
|
}
|
||||||
|
d->m_sharedDataQueue.get()->clear();
|
||||||
|
return d->m_sharedDataQueue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SearchController::refreshSearchId()
|
size_t SearchController::refreshSearchId()
|
||||||
{
|
{
|
||||||
return d->refreshSearchId();
|
d->m_searchIdMutex.lock();
|
||||||
|
d->m_searchId += 1;
|
||||||
|
d->m_searchIdMutex.unlock();
|
||||||
|
return d->m_searchId;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataQueue<ResultItem> *SearchController::initDataQueue()
|
DataQueue<ResultItem> *SearchController::initDataQueue()
|
||||||
{
|
{
|
||||||
return d->initDataQueue();
|
if(!d->m_sharedDataQueue.get()) {
|
||||||
|
d->m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
|
||||||
|
return d->m_sharedDataQueue.get();
|
||||||
|
}
|
||||||
|
return d->m_sharedDataQueue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::addSearchDir(const QString &path)
|
void SearchController::addSearchDir(const QString &path)
|
||||||
{
|
{
|
||||||
return d->addSearchDir(path);
|
d->m_searchDirs.append(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::setRecurse(bool recurse)
|
void SearchController::setRecurse(bool recurse)
|
||||||
{
|
{
|
||||||
d->setRecurse(recurse);
|
d->m_recurse = recurse;;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::addKeyword(const QString &keyword)
|
void SearchController::addKeyword(const QString &keyword)
|
||||||
{
|
{
|
||||||
d->addKeyword(keyword);
|
d->m_keywords.append(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SearchController::getCurrentSearchId()
|
size_t SearchController::getCurrentSearchId()
|
||||||
{
|
{
|
||||||
return d->getCurrentSearchId();
|
d->m_searchIdMutex.lock();
|
||||||
|
size_t searchId = d->m_searchId;
|
||||||
|
d->m_searchIdMutex.unlock();
|
||||||
|
|
||||||
|
return searchId;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataQueue<ResultItem> *SearchController::getDataQueue()
|
DataQueue<ResultItem> *SearchController::getDataQueue()
|
||||||
{
|
{
|
||||||
return d->getDataQueue();
|
return d->m_sharedDataQueue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchResultProperties SearchController::getResultProperties(SearchProperty::SearchType searchType)
|
SearchResultProperties SearchController::getResultProperties(SearchProperty::SearchType searchType)
|
||||||
{
|
{
|
||||||
return d->getResultProperties(searchType);
|
return d->m_searchType2ResultProperties[searchType];;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SearchController::getCustomResultDataType(QString customSearchType)
|
QStringList SearchController::getCustomResultDataType(QString customSearchType)
|
||||||
{
|
{
|
||||||
return d->getCustomResultDataType(customSearchType);
|
return d->m_customSearchType2ResultDataType[customSearchType];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::setActiveKeywordSegmentation(bool active)
|
void SearchController::setActiveKeywordSegmentation(bool active)
|
||||||
{
|
{
|
||||||
d->setActiveKeywordSegmentation(active);
|
d->m_activeKeywordSegmentation = active;;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::addFileLabel(const QString &label)
|
void SearchController::addFileLabel(const QString &label)
|
||||||
{
|
{
|
||||||
d->addFileLabel(label);
|
d->m_FileLabels.append(label);;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::setOnlySearchFile(bool onlySearchFile)
|
void SearchController::setOnlySearchFile(bool onlySearchFile)
|
||||||
{
|
{
|
||||||
d->setOnlySearchFile(onlySearchFile);
|
d->m_onlySearchFile = onlySearchFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::setOnlySearchDir(bool onlySearchDir)
|
void SearchController::setOnlySearchDir(bool onlySearchDir)
|
||||||
{
|
{
|
||||||
d->setOnlySearchDir(onlySearchDir);
|
d->m_onlySearchDir = onlySearchDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::setSearchOnlineApps(bool searchOnlineApps)
|
void SearchController::setSearchOnlineApps(bool searchOnlineApps)
|
||||||
{
|
{
|
||||||
d->setSearchOnlineApps(searchOnlineApps);
|
d->m_searchOnlineApps = searchOnlineApps;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchController::setSearchHiddenFiles(bool searchHiddenFiles)
|
||||||
|
{
|
||||||
|
d->m_searchHiddenFiles = searchHiddenFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchController::beginSearchIdCheck(size_t searchId)
|
bool SearchController::beginSearchIdCheck(size_t searchId)
|
||||||
{
|
{
|
||||||
return d->beginSearchIdCheck(searchId);
|
d->m_searchIdMutex.lock();
|
||||||
|
return d->m_searchId == searchId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::finishSearchIdCheck()
|
void SearchController::finishSearchIdCheck()
|
||||||
{
|
{
|
||||||
d->finishSearchIdCheck();
|
d->m_searchIdMutex.unlock();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SearchController::getSearchDir()
|
QStringList SearchController::getSearchDir()
|
||||||
{
|
{
|
||||||
return d->getSearchDir();
|
return d->m_searchDirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchController::isRecurse()
|
bool SearchController::isRecurse()
|
||||||
{
|
{
|
||||||
return d->isRecurse();
|
return d->m_recurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SearchController::getKeyword()
|
QStringList SearchController::getKeyword()
|
||||||
{
|
{
|
||||||
return d->getKeyword();
|
return d->m_keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchController::isKeywordSegmentationActived()
|
bool SearchController::isKeywordSegmentationActived()
|
||||||
{
|
{
|
||||||
return d->isKeywordSegmentationActived();
|
return d->m_activeKeywordSegmentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SearchController::getFileLabel()
|
QStringList SearchController::getFileLabel()
|
||||||
{
|
{
|
||||||
return d->getFileLabel();
|
return d->m_FileLabels;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchController::isSearchFileOnly()
|
bool SearchController::isSearchFileOnly()
|
||||||
{
|
{
|
||||||
return d->isSearchFileOnly();
|
return d->m_onlySearchFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchController::isSearchDirOnly()
|
bool SearchController::isSearchDirOnly()
|
||||||
{
|
{
|
||||||
return d->isSearchDirOnly();
|
return d->m_onlySearchDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchController::isSearchOnlineApps()
|
bool SearchController::isSearchOnlineApps()
|
||||||
{
|
{
|
||||||
return d->isSearchOnlineApps();
|
return d->m_searchOnlineApps;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SearchController::searchHiddenFiles()
|
||||||
|
{
|
||||||
|
return d->m_searchHiddenFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::stop()
|
void SearchController::stop()
|
||||||
{
|
{
|
||||||
d->stop();
|
d->m_searchIdMutex.lock();
|
||||||
|
d->m_searchId += 1;
|
||||||
|
d->m_searchIdMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::clearAllConditions()
|
void SearchController::clearAllConditions()
|
||||||
|
@ -396,45 +234,49 @@ void SearchController::clearAllConditions()
|
||||||
|
|
||||||
void SearchController::clearKeyWords()
|
void SearchController::clearKeyWords()
|
||||||
{
|
{
|
||||||
d->clearKeyWords();
|
d->m_keywords.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::clearSearchDir()
|
void SearchController::clearSearchDir()
|
||||||
{
|
{
|
||||||
d->clearSearchDir();
|
d->m_searchDirs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::clearFileLabel()
|
void SearchController::clearFileLabel()
|
||||||
{
|
{
|
||||||
d->clearFileLabel();
|
d->m_FileLabels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::setMaxResultNum(unsigned int maxResults)
|
void SearchController::setMaxResultNum(unsigned int maxResults)
|
||||||
{
|
{
|
||||||
d->setMaxResultNum(maxResults);
|
d->m_maxResults = maxResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::setInformNum(int num)
|
void SearchController::setInformNum(int num)
|
||||||
{
|
{
|
||||||
d->setInformNum(num);
|
if(num >= 0) {
|
||||||
|
d->m_informNum = num;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int SearchController::maxResults() const
|
unsigned int SearchController::maxResults() const
|
||||||
{
|
{
|
||||||
return d->maxResults();
|
return d->m_maxResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SearchController::informNum() const
|
int SearchController::informNum() const
|
||||||
{
|
{
|
||||||
return d->informNum();
|
return d->m_informNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchController::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
bool SearchController::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
||||||
{
|
{
|
||||||
return d->setResultProperties(searchType, searchResultProperties);
|
d->m_searchType2ResultProperties[searchType] = searchResultProperties;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
void SearchController::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||||
{
|
{
|
||||||
return d->setCustomResultDataType(customSearchType, dataType);
|
d->m_customSearchType2ResultDataType[customSearchType] = dataType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,17 +15,17 @@ class SearchControllerPrivate;
|
||||||
*/
|
*/
|
||||||
class SearchController
|
class SearchController
|
||||||
{
|
{
|
||||||
friend class SearchControllerPrivate;
|
|
||||||
public:
|
public:
|
||||||
explicit SearchController(std::shared_ptr<SearchController> parent = nullptr);
|
SearchController();
|
||||||
SearchController(SearchController &) = delete;
|
SearchController(const SearchController &other);
|
||||||
SearchController &operator =(const SearchController &) = delete;
|
SearchController &operator=(const SearchController &other);
|
||||||
|
SearchController &operator=(SearchController &&other) Q_DECL_NOEXCEPT;
|
||||||
|
|
||||||
~SearchController();
|
~SearchController();
|
||||||
DataQueue<ResultItem>* refreshDataqueue();
|
DataQueue<ResultItem>* refreshDataqueue();
|
||||||
size_t refreshSearchId();
|
size_t refreshSearchId();
|
||||||
DataQueue<ResultItem>* initDataQueue();
|
DataQueue<ResultItem>* initDataQueue();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
void addSearchDir(const QString &path);
|
void addSearchDir(const QString &path);
|
||||||
void setRecurse(bool recurse = true);
|
void setRecurse(bool recurse = true);
|
||||||
void addKeyword(const QString &keyword);
|
void addKeyword(const QString &keyword);
|
||||||
|
@ -34,6 +34,7 @@ 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 setSearchHiddenFiles(bool searchHiddenFiles);
|
||||||
void setMaxResultNum(unsigned int maxResults);
|
void setMaxResultNum(unsigned int maxResults);
|
||||||
void setInformNum(int num = 0);
|
void setInformNum(int num = 0);
|
||||||
//以上方法插件请不要调用
|
//以上方法插件请不要调用
|
||||||
|
@ -54,6 +55,7 @@ public:
|
||||||
bool isSearchFileOnly();
|
bool isSearchFileOnly();
|
||||||
bool isSearchDirOnly();
|
bool isSearchDirOnly();
|
||||||
bool isSearchOnlineApps();
|
bool isSearchOnlineApps();
|
||||||
|
bool searchHiddenFiles();
|
||||||
void clearAllConditions();
|
void clearAllConditions();
|
||||||
void clearKeyWords();
|
void clearKeyWords();
|
||||||
void clearSearchDir();
|
void clearSearchDir();
|
||||||
|
@ -65,8 +67,7 @@ public:
|
||||||
bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
|
bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
|
||||||
void setCustomResultDataType(QString customSearchType, QStringList dataType);
|
void setCustomResultDataType(QString customSearchType, QStringList dataType);
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<SearchController> m_parent = nullptr;
|
std::shared_ptr<SearchControllerPrivate> d;
|
||||||
SearchControllerPrivate *d = nullptr;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ 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.h \
|
$$PWD/search-controller.h \
|
||||||
$$PWD/result-item.h \
|
$$PWD/result-item.h \
|
||||||
$$PWD/search-result-property-info.h \
|
$$PWD/search-result-property-info.h \
|
||||||
|
|
|
@ -42,7 +42,7 @@ AppSearchTask::~AppSearchTask()
|
||||||
m_pool->waitForDone();
|
m_pool->waitForDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
|
void AppSearchTask::setController(const SearchController &searchController)
|
||||||
{
|
{
|
||||||
m_searchController = searchController;
|
m_searchController = searchController;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ bool AppSearchTask::isSearching()
|
||||||
|
|
||||||
AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask): m_appSearchTask(AppSarchTask)
|
AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask): m_appSearchTask(AppSarchTask)
|
||||||
{
|
{
|
||||||
m_controller = new SearchController(m_appSearchTask->m_searchController);
|
m_controller = &m_appSearchTask->m_searchController;
|
||||||
m_currentSearchId = m_controller->getCurrentSearchId();
|
m_currentSearchId = m_controller->getCurrentSearchId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,14 +183,6 @@ 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()
|
|
||||||
{
|
|
||||||
if(m_controller) {
|
|
||||||
delete m_controller;
|
|
||||||
m_controller = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppSearchWorker::sendErrorMsg(const QString &msg)
|
void AppSearchWorker::sendErrorMsg(const QString &msg)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(m_appSearchTask, "searchError",
|
QMetaObject::invokeMethod(m_appSearchTask, "searchError",
|
||||||
|
|
|
@ -39,7 +39,7 @@ class AppSearchTask : public SearchTaskPluginIface
|
||||||
public:
|
public:
|
||||||
explicit AppSearchTask(QObject *parent = nullptr);
|
explicit AppSearchTask(QObject *parent = nullptr);
|
||||||
~AppSearchTask();
|
~AppSearchTask();
|
||||||
void setController(const std::shared_ptr<SearchController> &searchController);
|
void setController(const SearchController &searchController);
|
||||||
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
|
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
|
||||||
const QString name();
|
const QString name();
|
||||||
const QString description();
|
const QString description();
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ApplicationInfo m_appinfo;
|
ApplicationInfo m_appinfo;
|
||||||
std::shared_ptr<SearchController> m_searchController;
|
SearchController m_searchController;
|
||||||
QThreadPool *m_pool = nullptr;
|
QThreadPool *m_pool = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class AppSearchWorker : public QRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit AppSearchWorker(AppSearchTask *AppSarchTask);
|
explicit AppSearchWorker(AppSearchTask *AppSarchTask);
|
||||||
~AppSearchWorker();
|
|
||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ FileContentSearchTask::~FileContentSearchTask()
|
||||||
m_pool->waitForDone();
|
m_pool->waitForDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileContentSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
|
void FileContentSearchTask::setController(const SearchController &searchController)
|
||||||
{
|
{
|
||||||
m_searchController = searchController;
|
m_searchController = searchController;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ SearchProperty::SearchType FileContentSearchTask::getSearchType()
|
||||||
|
|
||||||
void FileContentSearchTask::startSearch()
|
void FileContentSearchTask::startSearch()
|
||||||
{
|
{
|
||||||
FileContentSearchWorker *worker = new FileContentSearchWorker(this, m_searchController);
|
FileContentSearchWorker *worker = new FileContentSearchWorker(this, &m_searchController);
|
||||||
m_pool->start(worker);
|
m_pool->start(worker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,21 +108,13 @@ bool FileContentSearchTask::isSearching()
|
||||||
return m_pool->activeThreadCount() > 0;
|
return m_pool->activeThreadCount() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileContentSearchWorker::FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, std::shared_ptr<SearchController> searchController)
|
FileContentSearchWorker::FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, SearchController *searchController)
|
||||||
{
|
{
|
||||||
m_fileContentSearchTask = fileContentSearchTask;
|
m_fileContentSearchTask = fileContentSearchTask;
|
||||||
m_searchController = new SearchController(searchController);
|
m_searchController = searchController;
|
||||||
m_currentSearchId = m_searchController->getCurrentSearchId();
|
m_currentSearchId = m_searchController->getCurrentSearchId();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileContentSearchWorker::~FileContentSearchWorker()
|
|
||||||
{
|
|
||||||
if(m_searchController) {
|
|
||||||
delete m_searchController;
|
|
||||||
m_searchController = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileContentSearchWorker::run()
|
void FileContentSearchWorker::run()
|
||||||
{
|
{
|
||||||
QStringList searchDirs = m_searchController->getSearchDir();
|
QStringList searchDirs = m_searchController->getSearchDir();
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
explicit FileContentSearchTask(QObject *parent = nullptr);
|
explicit FileContentSearchTask(QObject *parent = nullptr);
|
||||||
|
|
||||||
~FileContentSearchTask() override;
|
~FileContentSearchTask() override;
|
||||||
void setController(const std::shared_ptr<SearchController> &searchController) override;
|
void setController(const SearchController &searchController) override;
|
||||||
PluginType pluginType() override;
|
PluginType pluginType() override;
|
||||||
const QString name() override;
|
const QString name() override;
|
||||||
const QString description() override;
|
const QString description() override;
|
||||||
|
@ -51,12 +51,12 @@ public:
|
||||||
SearchProperty::SearchType getSearchType() override;
|
SearchProperty::SearchType getSearchType() override;
|
||||||
void startSearch() override;
|
void startSearch() override;
|
||||||
void stop() override;
|
void stop() override;
|
||||||
bool isSearching();
|
bool isSearching() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QThreadPool *m_pool = nullptr;
|
QThreadPool *m_pool = nullptr;
|
||||||
bool m_enable = true;
|
bool m_enable = true;
|
||||||
std::shared_ptr<SearchController> m_searchController;
|
SearchController m_searchController;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileContentSearchWorker : public QRunnable
|
class FileContentSearchWorker : public QRunnable
|
||||||
|
@ -64,9 +64,7 @@ class FileContentSearchWorker : public QRunnable
|
||||||
friend class FileContentSearchFilter;
|
friend class FileContentSearchFilter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, std::shared_ptr<SearchController> searchController);
|
explicit FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, SearchController *searchController);
|
||||||
~FileContentSearchWorker();
|
|
||||||
|
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -46,7 +46,7 @@ FileSearchTask::~FileSearchTask()
|
||||||
m_pool->waitForDone();
|
m_pool->waitForDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
|
void FileSearchTask::setController(const SearchController &searchController)
|
||||||
{
|
{
|
||||||
m_searchController = searchController;
|
m_searchController = searchController;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ QString FileSearchTask::getCustomSearchType()
|
||||||
void FileSearchTask::startSearch()
|
void FileSearchTask::startSearch()
|
||||||
{
|
{
|
||||||
FileSearchWorker *fileSearchWorker;
|
FileSearchWorker *fileSearchWorker;
|
||||||
fileSearchWorker = new FileSearchWorker(this, m_searchController);
|
fileSearchWorker = new FileSearchWorker(this, &m_searchController);
|
||||||
m_pool->start(fileSearchWorker);
|
m_pool->start(fileSearchWorker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,20 +83,12 @@ bool FileSearchTask::isSearching()
|
||||||
return m_pool->activeThreadCount() > 0;
|
return m_pool->activeThreadCount() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSearchWorker::FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController) : m_FileSearchTask(fileSarchTask)
|
FileSearchWorker::FileSearchWorker(FileSearchTask *fileSarchTask, SearchController *searchController) : m_FileSearchTask(fileSarchTask)
|
||||||
{
|
{
|
||||||
m_searchController = new SearchController(searchController);
|
m_searchController = searchController;
|
||||||
m_currentSearchId = m_searchController->getCurrentSearchId();
|
m_currentSearchId = m_searchController->getCurrentSearchId();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSearchWorker::~FileSearchWorker()
|
|
||||||
{
|
|
||||||
if(m_searchController) {
|
|
||||||
delete m_searchController;
|
|
||||||
m_searchController = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileSearchWorker::run()
|
void FileSearchWorker::run()
|
||||||
{
|
{
|
||||||
//1.检查是否为不可搜索目录
|
//1.检查是否为不可搜索目录
|
||||||
|
@ -128,7 +120,7 @@ void FileSearchWorker::run()
|
||||||
bool indexed = true;
|
bool indexed = true;
|
||||||
|
|
||||||
QStringList indexedDir = DirWatcher::getDirWatcher()->currentIndexableDir();
|
QStringList indexedDir = DirWatcher::getDirWatcher()->currentIndexableDir();
|
||||||
if(!indexedDir.isEmpty() && IndexStatusRecorder::getInstance()->indexDatabaseEnable()) {
|
if(!indexedDir.isEmpty() && IndexStatusRecorder::getInstance()->indexDatabaseEnable() && !m_searchController->searchHiddenFiles()) {
|
||||||
for(const QString &path : m_searchController->getSearchDir()) {
|
for(const QString &path : m_searchController->getSearchDir()) {
|
||||||
bool pathIndexed = false;
|
bool pathIndexed = false;
|
||||||
for(const QString &dir : indexedDir) {
|
for(const QString &dir : indexedDir) {
|
||||||
|
@ -266,13 +258,17 @@ bool FileSearchWorker::directSearch()
|
||||||
|
|
||||||
QDir dir;
|
QDir dir;
|
||||||
QFileInfoList infoList;
|
QFileInfoList infoList;
|
||||||
|
QDir::Filters filters;
|
||||||
if (m_searchController->isSearchDirOnly()) {
|
if (m_searchController->isSearchDirOnly()) {
|
||||||
dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
|
filters = QDir::Dirs | QDir::NoDotAndDotDot;
|
||||||
} else {
|
} else {
|
||||||
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
filters = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot;
|
||||||
dir.setSorting(QDir::DirsFirst);
|
dir.setSorting(QDir::DirsFirst);
|
||||||
}
|
}
|
||||||
|
if(m_searchController->searchHiddenFiles()) {
|
||||||
|
filters |= QDir::Hidden;
|
||||||
|
}
|
||||||
|
dir.setFilter(filters);
|
||||||
while (!searchPathQueue.empty()) {
|
while (!searchPathQueue.empty()) {
|
||||||
dir.setPath(searchPathQueue.dequeue());
|
dir.setPath(searchPathQueue.dequeue());
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
|
|
|
@ -34,10 +34,10 @@ class FileSearchTask : public SearchTaskPluginIface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit FileSearchTask(QObject *parent);
|
explicit FileSearchTask(QObject *parent = nullptr);
|
||||||
~FileSearchTask();
|
~FileSearchTask();
|
||||||
|
|
||||||
void setController(const std::shared_ptr<SearchController> &searchController);
|
void setController(const SearchController &searchController);
|
||||||
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
|
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
|
||||||
const QString name();
|
const QString name();
|
||||||
const QString description();
|
const QString description();
|
||||||
|
@ -53,7 +53,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QThreadPool *m_pool = nullptr;
|
QThreadPool *m_pool = nullptr;
|
||||||
std::shared_ptr<SearchController> m_searchController;
|
SearchController m_searchController;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileSearchWorker : public QRunnable
|
class FileSearchWorker : public QRunnable
|
||||||
|
@ -61,8 +61,7 @@ class FileSearchWorker : public QRunnable
|
||||||
friend class FileSearchFilter;
|
friend class FileSearchFilter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController);
|
explicit FileSearchWorker(FileSearchTask *fileSarchTask, SearchController *searchController);
|
||||||
~FileSearchWorker();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
|
|
|
@ -8,7 +8,7 @@ class UkuiSearchTaskPrivate
|
||||||
{
|
{
|
||||||
friend class UkuiSearchTask;
|
friend class UkuiSearchTask;
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<SearchController> m_searchCotroller = nullptr;
|
SearchController m_searchCotroller;
|
||||||
size_t m_searchId = 0;
|
size_t m_searchId = 0;
|
||||||
QUuid m_uuid;
|
QUuid m_uuid;
|
||||||
};
|
};
|
||||||
|
@ -16,7 +16,6 @@ private:
|
||||||
|
|
||||||
UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate())
|
UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate())
|
||||||
{
|
{
|
||||||
d->m_searchCotroller = std::make_shared<SearchController>();
|
|
||||||
d->m_uuid = QUuid::createUuid();
|
d->m_uuid = QUuid::createUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,42 +27,47 @@ UkuiSearchTask::~UkuiSearchTask()
|
||||||
|
|
||||||
DataQueue<ResultItem> *UkuiSearchTask::init()
|
DataQueue<ResultItem> *UkuiSearchTask::init()
|
||||||
{
|
{
|
||||||
return d->m_searchCotroller->initDataQueue();
|
return d->m_searchCotroller.initDataQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::addSearchDir(const QString &path)
|
void UkuiSearchTask::addSearchDir(const QString &path)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->addSearchDir(path);
|
d->m_searchCotroller.addSearchDir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::setRecurse(bool recurse)
|
void UkuiSearchTask::setRecurse(bool recurse)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->setRecurse(recurse);
|
d->m_searchCotroller.setRecurse(recurse);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::addKeyword(const QString &keyword)
|
void UkuiSearchTask::addKeyword(const QString &keyword)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->addKeyword(keyword);
|
d->m_searchCotroller.addKeyword(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::addFileLabel(const QString &label)
|
void UkuiSearchTask::addFileLabel(const QString &label)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->addFileLabel(label);
|
d->m_searchCotroller.addFileLabel(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::setOnlySearchFile(bool onlySearchFile)
|
void UkuiSearchTask::setOnlySearchFile(bool onlySearchFile)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->setOnlySearchFile(onlySearchFile);
|
d->m_searchCotroller.setOnlySearchFile(onlySearchFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::setOnlySearchDir(bool onlySearchDir)
|
void UkuiSearchTask::setOnlySearchDir(bool onlySearchDir)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->setOnlySearchDir(onlySearchDir);
|
d->m_searchCotroller.setOnlySearchDir(onlySearchDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
|
void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->setSearchOnlineApps(searchOnlineApps);
|
d->m_searchCotroller.setSearchOnlineApps(searchOnlineApps);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UkuiSearchTask::setSearchHiddenFiles(bool searchHiddenFiles)
|
||||||
|
{
|
||||||
|
d->m_searchCotroller.setSearchHiddenFiles(searchHiddenFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, const QString &customSearchType)
|
void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, const QString &customSearchType)
|
||||||
|
@ -81,25 +85,25 @@ void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, con
|
||||||
|
|
||||||
bool UkuiSearchTask::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
bool UkuiSearchTask::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
||||||
{
|
{
|
||||||
return d->m_searchCotroller->setResultProperties(searchType, searchResultProperties);
|
return d->m_searchCotroller.setResultProperties(searchType, searchResultProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
void UkuiSearchTask::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
||||||
{
|
{
|
||||||
return d->m_searchCotroller->setCustomResultDataType(customSearchType, dataType);
|
return d->m_searchCotroller.setCustomResultDataType(customSearchType, dataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QString customSearchType)
|
size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QString customSearchType)
|
||||||
{
|
{
|
||||||
d->m_searchId = d->m_searchCotroller->refreshSearchId();
|
d->m_searchId = d->m_searchCotroller.refreshSearchId();
|
||||||
if(d->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!";
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_searchCotroller->refreshDataqueue();
|
d->m_searchCotroller.refreshDataqueue();
|
||||||
//plugin manager do async search here
|
//plugin manager do async search here
|
||||||
if (!SearchTaskPluginManager::getInstance()->startSearch(d->m_uuid, searchtype, customSearchType)) {
|
if (!SearchTaskPluginManager::getInstance()->startSearch(d->m_uuid, searchtype, customSearchType)) {
|
||||||
Q_EMIT searchError(d->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 d->m_searchId;
|
return d->m_searchId;
|
||||||
|
@ -107,7 +111,7 @@ size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QStrin
|
||||||
|
|
||||||
void UkuiSearchTask::stop()
|
void UkuiSearchTask::stop()
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->stop();
|
d->m_searchCotroller.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UkuiSearchTask::isSearching(SearchProperty::SearchType searchtype, QString customSearchType)
|
bool UkuiSearchTask::isSearching(SearchProperty::SearchType searchtype, QString customSearchType)
|
||||||
|
@ -117,30 +121,30 @@ bool UkuiSearchTask::isSearching(SearchProperty::SearchType searchtype, QString
|
||||||
|
|
||||||
void UkuiSearchTask::clearAllConditions()
|
void UkuiSearchTask::clearAllConditions()
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->clearAllConditions();
|
d->m_searchCotroller.clearAllConditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::clearKeyWords()
|
void UkuiSearchTask::clearKeyWords()
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->clearKeyWords();
|
d->m_searchCotroller.clearKeyWords();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::clearSearchDir()
|
void UkuiSearchTask::clearSearchDir()
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->clearSearchDir();
|
d->m_searchCotroller.clearSearchDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::clearFileLabel()
|
void UkuiSearchTask::clearFileLabel()
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->clearFileLabel();
|
d->m_searchCotroller.clearFileLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::setMaxResultNum(unsigned int maxResults)
|
void UkuiSearchTask::setMaxResultNum(unsigned int maxResults)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->setMaxResultNum(maxResults);
|
d->m_searchCotroller.setMaxResultNum(maxResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::setInformNum(int num)
|
void UkuiSearchTask::setInformNum(int num)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller->setInformNum(num);
|
d->m_searchCotroller.setInformNum(num);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,12 @@ 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);
|
||||||
|
/**
|
||||||
|
* 是否搜索隐藏文件
|
||||||
|
* @brief setSearchHiddenFiles
|
||||||
|
* @param searchHiddenFiles
|
||||||
|
*/
|
||||||
|
void setSearchHiddenFiles(bool searchHiddenFiles);
|
||||||
/**
|
/**
|
||||||
* @brief initSearchPlugin 初始化搜索插件
|
* @brief initSearchPlugin 初始化搜索插件
|
||||||
* @param searchType
|
* @param searchType
|
||||||
|
|
Loading…
Reference in New Issue