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

89 lines
2.3 KiB
C
Raw Normal View History

2021-12-28 15:56:41 +08:00
#ifndef FILESEARCHTASK_H
#define FILESEARCHTASK_H
2022-01-11 16:20:40 +08:00
#include <QIcon>
#include <QThreadPool>
#include <QRunnable>
#include <xapian.h>
2021-12-28 15:56:41 +08:00
#include "search-task-plugin-iface.h"
#include "search-controller.h"
2022-01-11 16:20:40 +08:00
#include "result-item.h"
2021-12-28 15:56:41 +08:00
namespace UkuiSearch {
2021-12-31 17:38:02 +08:00
class FileSearchTask : public SearchTaskPluginIface
2021-12-28 15:56:41 +08:00
{
Q_OBJECT
public:
explicit FileSearchTask(QObject *parent);
~FileSearchTask();
2021-12-28 15:56:41 +08:00
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
const QString name();
const QString description();
const QIcon icon() {return QIcon::fromTheme("folder");}
void setEnable(bool enable) {}
2022-01-11 16:20:40 +08:00
bool isEnable() { return true;}
2021-12-28 15:56:41 +08:00
SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::File;}
2021-12-31 17:38:02 +08:00
QString getCustomSearchType();
void startSearch(std::shared_ptr<SearchController> searchController);
2021-12-28 15:56:41 +08:00
void stop();
2022-01-11 16:20:40 +08:00
Q_INVOKABLE void sendFinishSignal(size_t searchId);
2021-12-28 15:56:41 +08:00
private:
2022-01-11 16:20:40 +08:00
QThreadPool *m_pool = nullptr;
};
class FileSearchWorker : public QRunnable
{
friend class FileSearchFilter;
2022-01-11 16:20:40 +08:00
public:
explicit FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController);
2022-01-11 16:20:40 +08:00
protected:
void run();
private:
/**
* @brief true
* false.
* 使task发起多次搜索searchId发生变化
* @return
*/
bool searchWithIndex();
//同上
bool directSearch();
Xapian::Query creatQueryForFileSearch();
void sendErrorMsg(const QString &msg);
2022-01-11 16:20:40 +08:00
private:
FileSearchTask *m_FileSearchTask;
std::shared_ptr<SearchController> m_searchController;
size_t m_currentSearchId = 0;
QStringList m_validDirectories;
QStringList m_blackList;
QStringList m_labels;
2021-12-28 15:56:41 +08:00
};
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;
};
2021-12-28 15:56:41 +08:00
}
#endif // FILESEARCHTASK_H