Merge branch '1213-ukss' into 'ukss-dev'
Add file search task plugin frame. See merge request kylin-desktop/ukui-search!242
This commit is contained in:
commit
4f5e12a57d
|
@ -20,6 +20,7 @@ Q_SIGNALS:
|
||||||
private:
|
private:
|
||||||
explicit SearchTaskPluginManager(QObject *parent = nullptr);
|
explicit SearchTaskPluginManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
//这里初衷是把内外部插件分开管理,内部插件可以增加枚举值,外部插件似乎只能用编写者自定义的字符串区分?
|
||||||
QHash<int, SearchTaskPluginIface*> m_buildinPlugin;
|
QHash<int, SearchTaskPluginIface*> m_buildinPlugin;
|
||||||
QHash<QString, SearchTaskPluginIface*> m_loadedPlugin;
|
QHash<QString, SearchTaskPluginIface*> m_loadedPlugin;
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,12 @@ namespace UkuiSearch {
|
||||||
class ResultItemPrivate
|
class ResultItemPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ResultItemPrivate(const QString &itemKey, ResultItem *parent);
|
explicit ResultItemPrivate(ResultItem *parent);
|
||||||
~ResultItemPrivate();
|
~ResultItemPrivate();
|
||||||
|
void setSearchId(size_t searchId);
|
||||||
|
void setItemKey(QString itemKey);
|
||||||
private:
|
private:
|
||||||
size_t searchId;
|
size_t m_searchId;
|
||||||
QString m_itemKey;
|
QString m_itemKey;
|
||||||
QString m_label;
|
QString m_label;
|
||||||
QVariant m_extral;
|
QVariant m_extral;
|
||||||
|
|
|
@ -1,18 +1,42 @@
|
||||||
#include "result-item.h"
|
#include "result-item.h"
|
||||||
#include "result-item-private.h"
|
#include "result-item-private.h"
|
||||||
using namespace UkuiSearch;
|
using namespace UkuiSearch;
|
||||||
ResultItemPrivate::ResultItemPrivate::ResultItemPrivate(const QString &itemKey, ResultItem *parent)
|
ResultItemPrivate::ResultItemPrivate::ResultItemPrivate(ResultItem *parent) : q(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultItemPrivate::~ResultItemPrivate()
|
ResultItemPrivate::~ResultItemPrivate()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
ResultItem::ResultItem(const QString &itemKey)
|
|
||||||
|
void ResultItemPrivate::setSearchId(size_t searchId)
|
||||||
{
|
{
|
||||||
d = new ResultItemPrivate(itemKey, this);
|
m_searchId = searchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResultItemPrivate::setItemKey(QString itemKey)
|
||||||
|
{
|
||||||
|
m_itemKey = itemKey;
|
||||||
|
}
|
||||||
|
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) : d(new ResultItemPrivate(this))
|
||||||
|
{
|
||||||
|
d->setSearchId(searchId);
|
||||||
|
d->setItemKey(itemKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultItem::~ResultItem()
|
ResultItem::~ResultItem()
|
||||||
|
|
|
@ -8,7 +8,10 @@ class ResultItemPrivate;
|
||||||
class ResultItem
|
class ResultItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ResultItem(const QString &itemKey);
|
explicit ResultItem();
|
||||||
|
explicit ResultItem(const size_t searchId);
|
||||||
|
explicit ResultItem(const QString itemKey);
|
||||||
|
explicit ResultItem(const size_t searchId, const QString itemKey);
|
||||||
~ResultItem();
|
~ResultItem();
|
||||||
private:
|
private:
|
||||||
ResultItemPrivate *d;
|
ResultItemPrivate *d;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define SEARCHCONTROLLERPRIVATE_H
|
#define SEARCHCONTROLLERPRIVATE_H
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QSharedPointer>
|
|
||||||
#include "search-controller.h"
|
#include "search-controller.h"
|
||||||
namespace UkuiSearch {
|
namespace UkuiSearch {
|
||||||
|
|
||||||
|
@ -20,6 +19,8 @@ public:
|
||||||
void addKeyword(QString &keyword);
|
void addKeyword(QString &keyword);
|
||||||
void setActiveKeywordSegmentation(bool active);
|
void setActiveKeywordSegmentation(bool active);
|
||||||
void addFileLabel(QString &label);
|
void addFileLabel(QString &label);
|
||||||
|
void setOnlySearchFile(bool onlySearchFile);
|
||||||
|
void setOnlySearchDir(bool onlySearchDir);
|
||||||
|
|
||||||
size_t getCurrentSearchId();
|
size_t getCurrentSearchId();
|
||||||
DataQueue<ResultItem>* getDataQueue();
|
DataQueue<ResultItem>* getDataQueue();
|
||||||
|
@ -31,19 +32,26 @@ public:
|
||||||
QStringList getKeyword();
|
QStringList getKeyword();
|
||||||
bool isKeywordSegmentationActived();
|
bool isKeywordSegmentationActived();
|
||||||
QStringList getFileLabel();
|
QStringList getFileLabel();
|
||||||
|
bool isSearchFileOnly();
|
||||||
|
bool isSearchDirOnly();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void copyData();
|
||||||
|
//TODO: 这里是否可以改为字节对齐的写法?
|
||||||
DataQueue<ResultItem>* m_dataQueue = nullptr ;
|
DataQueue<ResultItem>* m_dataQueue = nullptr ;
|
||||||
|
std::shared_ptr<DataQueue<ResultItem>> m_sharedDataueue = nullptr;
|
||||||
size_t m_searchId = 0;
|
size_t m_searchId = 0;
|
||||||
QMutex m_searchIdMutex;
|
QMutex m_searchIdMutex;
|
||||||
SearchController *q;
|
SearchController *q = nullptr;
|
||||||
QSharedPointer<SearchController> m_formerController;
|
std::shared_ptr<SearchController> m_formerController = nullptr;
|
||||||
|
|
||||||
QStringList m_keywords;
|
QStringList m_keywords;
|
||||||
QStringList m_searchDirs;
|
QStringList m_searchDirs;
|
||||||
QStringList m_FileLabels;
|
QStringList m_FileLabels;
|
||||||
bool m_recurse = true;
|
bool m_recurse = true;
|
||||||
bool m_activeKeywordSegmentation = false;
|
bool m_activeKeywordSegmentation = false;
|
||||||
|
bool m_onlySearchFile = false;
|
||||||
|
bool m_onlySearchDir = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,14 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
using namespace UkuiSearch;
|
using namespace UkuiSearch;
|
||||||
SearchControllerPrivate::SearchControllerPrivate(SearchController *parent)
|
SearchControllerPrivate::SearchControllerPrivate(SearchController *parent)
|
||||||
: q(parent)
|
: q(parent),
|
||||||
|
m_formerController(q->m_parent) //如果构造参数里包含父节点智能指针,则子节点带有一个智能指针指向父节点
|
||||||
{
|
{
|
||||||
if(q->m_parent) {
|
copyData();
|
||||||
m_formerController = QSharedPointer<SearchController>(q->m_parent);
|
|
||||||
m_searchId = q->m_parent->d->m_searchId;
|
|
||||||
m_dataQueue = q->m_parent->d->m_dataQueue;
|
|
||||||
m_keywords = q->m_parent->d->m_keywords;
|
|
||||||
m_searchDirs = q->m_parent->d->m_searchDirs;
|
|
||||||
m_FileLabels = q->m_parent->d->m_FileLabels;
|
|
||||||
m_recurse = q->m_parent->d->m_recurse;
|
|
||||||
m_activeKeywordSegmentation = q->m_parent->d->m_activeKeywordSegmentation;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchControllerPrivate::~SearchControllerPrivate()
|
SearchControllerPrivate::~SearchControllerPrivate()
|
||||||
{
|
{
|
||||||
m_formerController.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SearchControllerPrivate::refreshSearchId()
|
size_t SearchControllerPrivate::refreshSearchId()
|
||||||
|
@ -35,6 +26,7 @@ DataQueue<ResultItem> *SearchControllerPrivate::refreshDataqueue()
|
||||||
{
|
{
|
||||||
if(!m_dataQueue) {
|
if(!m_dataQueue) {
|
||||||
m_dataQueue = new DataQueue<ResultItem>;
|
m_dataQueue = new DataQueue<ResultItem>;
|
||||||
|
m_sharedDataueue = std::shared_ptr<DataQueue<ResultItem>>(m_dataQueue);
|
||||||
return m_dataQueue;
|
return m_dataQueue;
|
||||||
}
|
}
|
||||||
m_dataQueue->clear();
|
m_dataQueue->clear();
|
||||||
|
@ -45,6 +37,7 @@ DataQueue<ResultItem> *SearchControllerPrivate::initDataQueue()
|
||||||
{
|
{
|
||||||
if(!m_dataQueue) {
|
if(!m_dataQueue) {
|
||||||
m_dataQueue = new DataQueue<ResultItem>;
|
m_dataQueue = new DataQueue<ResultItem>;
|
||||||
|
m_sharedDataueue = std::shared_ptr<DataQueue<ResultItem>>(m_dataQueue);
|
||||||
return m_dataQueue;
|
return m_dataQueue;
|
||||||
}
|
}
|
||||||
return m_dataQueue;
|
return m_dataQueue;
|
||||||
|
@ -75,6 +68,16 @@ void SearchControllerPrivate::addFileLabel(QString &label)
|
||||||
m_FileLabels.append(label);
|
m_FileLabels.append(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchControllerPrivate::setOnlySearchFile(bool onlySearchFile)
|
||||||
|
{
|
||||||
|
m_onlySearchFile = onlySearchFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchControllerPrivate::setOnlySearchDir(bool onlySearchDir)
|
||||||
|
{
|
||||||
|
m_onlySearchDir = onlySearchDir;
|
||||||
|
}
|
||||||
|
|
||||||
size_t SearchControllerPrivate::getCurrentSearchId()
|
size_t SearchControllerPrivate::getCurrentSearchId()
|
||||||
{
|
{
|
||||||
return m_searchId;
|
return m_searchId;
|
||||||
|
@ -82,7 +85,7 @@ size_t SearchControllerPrivate::getCurrentSearchId()
|
||||||
|
|
||||||
DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
|
DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
|
||||||
{
|
{
|
||||||
return m_dataQueue;
|
return m_sharedDataueue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchControllerPrivate::beginSearchIdCheck(size_t searchId)
|
bool SearchControllerPrivate::beginSearchIdCheck(size_t searchId)
|
||||||
|
@ -112,30 +115,57 @@ void SearchControllerPrivate::stop()
|
||||||
|
|
||||||
QStringList SearchControllerPrivate::getSearchDir()
|
QStringList SearchControllerPrivate::getSearchDir()
|
||||||
{
|
{
|
||||||
|
return m_searchDirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchControllerPrivate::isRecurse()
|
bool SearchControllerPrivate::isRecurse()
|
||||||
{
|
{
|
||||||
|
return m_recurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SearchControllerPrivate::getKeyword()
|
QStringList SearchControllerPrivate::getKeyword()
|
||||||
{
|
{
|
||||||
|
return m_keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchControllerPrivate::isKeywordSegmentationActived()
|
bool SearchControllerPrivate::isKeywordSegmentationActived()
|
||||||
{
|
{
|
||||||
|
return m_activeKeywordSegmentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SearchControllerPrivate::getFileLabel()
|
QStringList SearchControllerPrivate::getFileLabel()
|
||||||
{
|
{
|
||||||
|
return m_FileLabels;
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchController::SearchController(SearchController *parent) : m_parent(parent), d(new SearchControllerPrivate(this))
|
bool SearchControllerPrivate::isSearchFileOnly()
|
||||||
|
{
|
||||||
|
return m_onlySearchFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SearchControllerPrivate::isSearchDirOnly()
|
||||||
|
{
|
||||||
|
return m_onlySearchDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchControllerPrivate::copyData()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(m_formerController.get()) {
|
||||||
|
m_searchId = m_formerController.get()->getCurrentSearchId();
|
||||||
|
//所有子节点都有一个指向根节点的队列的智能指针
|
||||||
|
m_sharedDataueue = m_formerController.get()->d->m_sharedDataueue;
|
||||||
|
m_keywords = m_formerController.get()->getKeyword();
|
||||||
|
m_searchDirs = m_formerController.get()->getSearchDir();
|
||||||
|
m_FileLabels = m_formerController.get()->getFileLabel();
|
||||||
|
m_onlySearchFile = m_formerController.get()->isSearchFileOnly();
|
||||||
|
m_onlySearchDir = m_formerController.get()->isSearchDirOnly();
|
||||||
|
m_recurse = m_formerController.get()->isRecurse();
|
||||||
|
m_activeKeywordSegmentation = m_formerController.get()->isKeywordSegmentationActived();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchController::SearchController(std::shared_ptr<SearchController> parent) : m_parent(parent), d(new SearchControllerPrivate(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +206,7 @@ void SearchController::addKeyword(QString &keyword)
|
||||||
|
|
||||||
size_t SearchController::getCurrentSearchId()
|
size_t SearchController::getCurrentSearchId()
|
||||||
{
|
{
|
||||||
d->getCurrentSearchId();
|
return d->getCurrentSearchId();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataQueue<ResultItem> *SearchController::getDataQueue()
|
DataQueue<ResultItem> *SearchController::getDataQueue()
|
||||||
|
@ -194,6 +224,16 @@ void SearchController::addFileLabel(QString &label)
|
||||||
d->addFileLabel(label);
|
d->addFileLabel(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchController::setOnlySearchFile(bool onlySearchFile)
|
||||||
|
{
|
||||||
|
d->setOnlySearchFile(onlySearchFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchController::setOnlySearchDir(bool onlySearchDir)
|
||||||
|
{
|
||||||
|
d->setOnlySearchDir(onlySearchDir);
|
||||||
|
}
|
||||||
|
|
||||||
bool SearchController::beginSearchIdCheck(size_t searchId)
|
bool SearchController::beginSearchIdCheck(size_t searchId)
|
||||||
{
|
{
|
||||||
return d->beginSearchIdCheck(searchId);
|
return d->beginSearchIdCheck(searchId);
|
||||||
|
@ -201,7 +241,42 @@ bool SearchController::beginSearchIdCheck(size_t searchId)
|
||||||
|
|
||||||
void SearchController::finishSearchIdCheck()
|
void SearchController::finishSearchIdCheck()
|
||||||
{
|
{
|
||||||
d->finishSearchIdCheck();
|
d->finishSearchIdCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList SearchController::getSearchDir()
|
||||||
|
{
|
||||||
|
return d->getSearchDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SearchController::isRecurse()
|
||||||
|
{
|
||||||
|
return d->isRecurse();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList SearchController::getKeyword()
|
||||||
|
{
|
||||||
|
return d->getKeyword();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SearchController::isKeywordSegmentationActived()
|
||||||
|
{
|
||||||
|
return d->isKeywordSegmentationActived();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList SearchController::getFileLabel()
|
||||||
|
{
|
||||||
|
return d->getFileLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SearchController::isSearchFileOnly()
|
||||||
|
{
|
||||||
|
return d->isSearchFileOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SearchController::isSearchDirOnly()
|
||||||
|
{
|
||||||
|
return d->isSearchDirOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::stop()
|
void SearchController::stop()
|
||||||
|
|
|
@ -2,17 +2,23 @@
|
||||||
#define SEARCHCONTROLLER_H
|
#define SEARCHCONTROLLER_H
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <memory>
|
||||||
#include "data-queue.h"
|
#include "data-queue.h"
|
||||||
//todo: url parser?
|
//todo: url parser?
|
||||||
namespace UkuiSearch {
|
namespace UkuiSearch {
|
||||||
class UkuiSearchTask;
|
class UkuiSearchTask;
|
||||||
class ResultItem;
|
class ResultItem;
|
||||||
class SearchControllerPrivate;
|
class SearchControllerPrivate;
|
||||||
|
/*
|
||||||
|
*搜索控制,用于传递搜索条件,搜索唯一ID,以及管理队列等。
|
||||||
|
*为树形结构,所有子节点含有智能指针指向父节点。
|
||||||
|
*只要有插件还在使用资源,其对应的子节点以及通向根节点上所有的实例就不会被释放,析构时,从下往上由智能指针自动析构
|
||||||
|
*/
|
||||||
class SearchController
|
class SearchController
|
||||||
{
|
{
|
||||||
friend class SearchControllerPrivate;
|
friend class SearchControllerPrivate;
|
||||||
public:
|
public:
|
||||||
explicit SearchController(SearchController *parent = nullptr);
|
explicit SearchController(std::shared_ptr<SearchController> parent = nullptr);
|
||||||
~SearchController();
|
~SearchController();
|
||||||
DataQueue<ResultItem>* refreshDataqueue();
|
DataQueue<ResultItem>* refreshDataqueue();
|
||||||
size_t refreshSearchId();
|
size_t refreshSearchId();
|
||||||
|
@ -24,6 +30,8 @@ public:
|
||||||
void addKeyword(QString &keyword);
|
void addKeyword(QString &keyword);
|
||||||
void setActiveKeywordSegmentation(bool active);
|
void setActiveKeywordSegmentation(bool active);
|
||||||
void addFileLabel(QString &label);
|
void addFileLabel(QString &label);
|
||||||
|
void setOnlySearchFile(bool onlySearchFile);
|
||||||
|
void setOnlySearchDir(bool onlySearchDir);
|
||||||
//以上方法插件请不要调用
|
//以上方法插件请不要调用
|
||||||
|
|
||||||
//以下方法插件可以调用
|
//以下方法插件可以调用
|
||||||
|
@ -37,9 +45,12 @@ public:
|
||||||
QStringList getKeyword();
|
QStringList getKeyword();
|
||||||
bool isKeywordSegmentationActived();
|
bool isKeywordSegmentationActived();
|
||||||
QStringList getFileLabel();
|
QStringList getFileLabel();
|
||||||
|
bool isSearchFileOnly();
|
||||||
|
bool isSearchDirOnly();
|
||||||
private:
|
private:
|
||||||
SearchControllerPrivate *d;
|
std::shared_ptr<SearchController> m_parent = nullptr;
|
||||||
SearchController *m_parent;
|
SearchControllerPrivate *d = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,26 +2,30 @@
|
||||||
using namespace UkuiSearch;
|
using namespace UkuiSearch;
|
||||||
FileSearchTask::FileSearchTask(SearchController searchController): m_searchControl(searchController)
|
FileSearchTask::FileSearchTask(SearchController searchController): m_searchControl(searchController)
|
||||||
{
|
{
|
||||||
|
m_pool = new QThreadPool(this);
|
||||||
|
m_pool->setMaxThreadCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString FileSearchTask::name()
|
const QString FileSearchTask::name()
|
||||||
{
|
{
|
||||||
|
return "File";
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString FileSearchTask::description()
|
const QString FileSearchTask::description()
|
||||||
{
|
{
|
||||||
|
return "File search.";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FileSearchTask::getCustomSearchType()
|
QString FileSearchTask::getCustomSearchType()
|
||||||
{
|
{
|
||||||
|
return "File";
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSearchTask::startSearch(SearchController searchController)
|
void FileSearchTask::startSearch(SearchController searchController)
|
||||||
{
|
{
|
||||||
|
FileSearchWorker *fileSearchWorker;
|
||||||
|
fileSearchWorker = new FileSearchWorker(this, searchController);
|
||||||
|
m_pool->start(fileSearchWorker);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSearchTask::stop()
|
void FileSearchTask::stop()
|
||||||
|
@ -29,6 +33,11 @@ void FileSearchTask::stop()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileSearchTask::sendFinishSignal(size_t searchId)
|
||||||
|
{
|
||||||
|
Q_EMIT searchFinished(searchId);
|
||||||
|
}
|
||||||
|
|
||||||
void FileSearchTask::run()
|
void FileSearchTask::run()
|
||||||
{
|
{
|
||||||
//file search, based on index or direct search?
|
//file search, based on index or direct search?
|
||||||
|
@ -41,3 +50,23 @@ void FileSearchTask::run()
|
||||||
m_searchControl.finishSearchIdCheck();
|
m_searchControl.finishSearchIdCheck();
|
||||||
//finish
|
//finish
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileSearchWorker::FileSearchWorker(FileSearchTask *fileSarchTask, SearchController searchController) : m_FileSearchTask(fileSarchTask), m_searchController(searchController)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileSearchWorker::run()
|
||||||
|
{
|
||||||
|
//TODO do search here
|
||||||
|
|
||||||
|
size_t searchId = m_searchController.getCurrentSearchId();
|
||||||
|
ResultItem ri(searchId);
|
||||||
|
if(m_searchController.beginSearchIdCheck(m_searchController.getCurrentSearchId())) {
|
||||||
|
m_searchController.getDataQueue()->enqueue(ri);
|
||||||
|
m_searchController.finishSearchIdCheck();
|
||||||
|
} else {
|
||||||
|
m_searchController.finishSearchIdCheck();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QMetaObject::invokeMethod(m_FileSearchTask, "searchFinished", Q_ARG(size_t, searchId));
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
#ifndef FILESEARCHTASK_H
|
#ifndef FILESEARCHTASK_H
|
||||||
#define FILESEARCHTASK_H
|
#define FILESEARCHTASK_H
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QThreadPool>
|
||||||
|
#include <QRunnable>
|
||||||
#include "search-task-plugin-iface.h"
|
#include "search-task-plugin-iface.h"
|
||||||
#include "search-controller.h"
|
#include "search-controller.h"
|
||||||
#include <QIcon>
|
#include "result-item.h"
|
||||||
namespace UkuiSearch {
|
namespace UkuiSearch {
|
||||||
|
/*
|
||||||
|
* 这里只写了大概框架,具体逻辑未实现,可以当成伪代码参考。
|
||||||
|
*/
|
||||||
class FileSearchTask : public SearchTaskPluginIface
|
class FileSearchTask : public SearchTaskPluginIface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -13,17 +20,30 @@ public:
|
||||||
const QString name();
|
const QString name();
|
||||||
const QString description();
|
const QString description();
|
||||||
const QIcon icon() {return QIcon::fromTheme("folder");}
|
const QIcon icon() {return QIcon::fromTheme("folder");}
|
||||||
void setEnable(bool enable) {}
|
void setEnable() {}
|
||||||
bool isEnable() {}
|
bool isEnable() { return true;}
|
||||||
|
|
||||||
SearchType getSearchType() {return SearchType::File;}
|
SearchType getSearchType() {return SearchType::File;}
|
||||||
QString getCustomSearchType();
|
QString getCustomSearchType();
|
||||||
void startSearch(SearchController searchController);
|
void startSearch(SearchController searchController);
|
||||||
void stop();
|
void stop();
|
||||||
|
Q_INVOKABLE void sendFinishSignal(size_t searchId);
|
||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
private:
|
private:
|
||||||
SearchController m_searchControl;
|
SearchController m_searchControl;
|
||||||
|
QThreadPool *m_pool = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileSearchWorker : public QRunnable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit FileSearchWorker(FileSearchTask *fileSarchTask, SearchController searchController);
|
||||||
|
protected:
|
||||||
|
void run();
|
||||||
|
private:
|
||||||
|
FileSearchTask *m_FileSearchTask;
|
||||||
|
SearchController m_searchController;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // FILESEARCHTASK_H
|
#endif // FILESEARCHTASK_H
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "ukui-search-task.h"
|
#include "ukui-search-task.h"
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QSharedPointer>
|
#include <memory>
|
||||||
|
|
||||||
#include "data-queue.h"
|
#include "data-queue.h"
|
||||||
#include "search-controller.h"
|
#include "search-controller.h"
|
||||||
|
@ -20,12 +20,14 @@ public:
|
||||||
void setRecurse(bool recurse = true);
|
void setRecurse(bool recurse = true);
|
||||||
void addKeyword(QString &keyword);
|
void addKeyword(QString &keyword);
|
||||||
void addFileLabel(QString &label);
|
void addFileLabel(QString &label);
|
||||||
|
void setOnlySearchFile(bool onlySearchFile);
|
||||||
|
void setOnlySearchDir(bool onlySearchDir);
|
||||||
void setSearchOnlineApps(bool searchOnlineApps);
|
void setSearchOnlineApps(bool searchOnlineApps);
|
||||||
size_t startSearch(SearchType searchtype, QString customSearchType = QString());
|
size_t startSearch(SearchType searchtype, QString customSearchType = QString());
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SearchController* m_searchCotroller;
|
std::shared_ptr<SearchController> m_searchCotroller = nullptr;
|
||||||
size_t m_searchId = 0;
|
size_t m_searchId = 0;
|
||||||
UkuiSearchTask* q = nullptr;
|
UkuiSearchTask* q = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ UkuiSearchTaskPrivate::UkuiSearchTaskPrivate(UkuiSearchTask *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
q(parent)
|
q(parent)
|
||||||
{
|
{
|
||||||
m_searchCotroller = new SearchController();
|
m_searchCotroller = std::shared_ptr<SearchController>(new SearchController());
|
||||||
}
|
}
|
||||||
|
|
||||||
UkuiSearchTaskPrivate::~UkuiSearchTaskPrivate()
|
UkuiSearchTaskPrivate::~UkuiSearchTaskPrivate()
|
||||||
|
@ -40,6 +40,16 @@ void UkuiSearchTaskPrivate::addFileLabel(QString &label)
|
||||||
m_searchCotroller->addFileLabel(label);
|
m_searchCotroller->addFileLabel(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UkuiSearchTaskPrivate::setOnlySearchFile(bool onlySearchFile)
|
||||||
|
{
|
||||||
|
m_searchCotroller->setOnlySearchFile(onlySearchFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UkuiSearchTaskPrivate::setOnlySearchDir(bool onlySearchDir)
|
||||||
|
{
|
||||||
|
m_searchCotroller->setOnlySearchDir(onlySearchDir);
|
||||||
|
}
|
||||||
|
|
||||||
void UkuiSearchTaskPrivate::setSearchOnlineApps(bool searchOnlineApps)
|
void UkuiSearchTaskPrivate::setSearchOnlineApps(bool searchOnlineApps)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -79,7 +89,7 @@ UkuiSearchTask::~UkuiSearchTask()
|
||||||
|
|
||||||
DataQueue<ResultItem> *UkuiSearchTask::init()
|
DataQueue<ResultItem> *UkuiSearchTask::init()
|
||||||
{
|
{
|
||||||
d->init();
|
return d->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::addSearchDir(QString &path)
|
void UkuiSearchTask::addSearchDir(QString &path)
|
||||||
|
@ -102,14 +112,24 @@ void UkuiSearchTask::addFileLabel(QString &label)
|
||||||
d->addFileLabel(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)
|
void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
|
||||||
{
|
{
|
||||||
d->setSearchOnlineApps(searchOnlineApps);
|
d->setSearchOnlineApps(searchOnlineApps);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t UkuiSearchTask::startSearch(SearchType searchtype, QString customSearchTYpe)
|
size_t UkuiSearchTask::startSearch(SearchType searchtype, QString customSearchType)
|
||||||
{
|
{
|
||||||
return d->startSearch(searchtype, customSearchTYpe);
|
return d->startSearch(searchtype, customSearchType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::stop()
|
void UkuiSearchTask::stop()
|
||||||
|
|
|
@ -17,8 +17,10 @@ public:
|
||||||
void setRecurse(bool recurse = true);
|
void setRecurse(bool recurse = true);
|
||||||
void addKeyword(QString &keyword);
|
void addKeyword(QString &keyword);
|
||||||
void addFileLabel(QString &label);
|
void addFileLabel(QString &label);
|
||||||
|
void setOnlySearchFile(bool onlySearchFile);
|
||||||
|
void setOnlySearchDir(bool onlySearchDir);
|
||||||
void setSearchOnlineApps(bool searchOnlineApps);
|
void setSearchOnlineApps(bool searchOnlineApps);
|
||||||
size_t startSearch(SearchType searchtype, QString customSearchTYpe = QString());
|
size_t startSearch(SearchType searchtype, QString customSearchType = QString());
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|
Loading…
Reference in New Issue