ukui-search/libsearch/searchinterface/searchtasks/file-search-task.h

89 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef FILESEARCHTASK_H
#define FILESEARCHTASK_H
#include <QIcon>
#include <QThreadPool>
#include <QRunnable>
#include <xapian.h>
#include "search-task-plugin-iface.h"
#include "search-controller.h"
#include "result-item.h"
namespace UkuiSearch {
class FileSearchTask : public SearchTaskPluginIface
{
Q_OBJECT
public:
explicit FileSearchTask(QObject *parent);
~FileSearchTask();
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
const QString name();
const QString description();
const QIcon icon() {return QIcon::fromTheme("folder");}
void setEnable(bool enable) {}
bool isEnable() { return true;}
SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::File;}
QString getCustomSearchType();
void startSearch(std::shared_ptr<SearchController> searchController);
void stop();
Q_INVOKABLE void sendFinishSignal(size_t searchId);
private:
QThreadPool *m_pool = nullptr;
};
class FileSearchWorker : public QRunnable
{
friend class FileSearchFilter;
public:
explicit FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController);
protected:
void run();
private:
/**
* @brief 通过索引进行搜索如果搜索过程正常返回true
* 如果搜索被打断返回false.
* 搜索被打断是指用户使用同一个task发起多次搜索导致searchId发生变化那么上一次搜索即被打断。
* @return
*/
bool searchWithIndex();
//同上
bool directSearch();
Xapian::Query creatQueryForFileSearch();
void sendErrorMsg(const QString &msg);
private:
FileSearchTask *m_FileSearchTask;
std::shared_ptr<SearchController> m_searchController;
size_t m_currentSearchId = 0;
QStringList m_validDirectories;
QStringList m_blackList;
QStringList m_labels;
};
class FileSearchFilter : public Xapian::MatchDecider {
public:
explicit FileSearchFilter(FileSearchWorker *parent);
bool operator ()(const Xapian::Document &doc) const;
/**
* @brief 检查path对应的文件是否包含labels中的标签
* @param path
* @param labels
* @return
*/
static bool checkFileLabel(const QString &path, const QStringList &labels);
private:
FileSearchWorker *m_parent = nullptr;
};
}
#endif // FILESEARCHTASK_H