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>
|
2022-03-25 09:40:56 +08:00
|
|
|
|
#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"
|
2022-03-25 09:40:56 +08:00
|
|
|
|
|
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:
|
2022-01-24 09:44:42 +08:00
|
|
|
|
explicit FileSearchTask(QObject *parent);
|
2023-03-15 16:39:38 +08:00
|
|
|
|
~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");}
|
2022-01-24 09:44:42 +08:00
|
|
|
|
void setEnable(bool enable) {}
|
2022-01-11 16:20:40 +08:00
|
|
|
|
bool isEnable() { return true;}
|
2021-12-28 15:56:41 +08:00
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
|
SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::File;}
|
2021-12-31 17:38:02 +08:00
|
|
|
|
QString getCustomSearchType();
|
2022-01-24 09:44:42 +08:00
|
|
|
|
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);
|
2022-01-24 09:44:42 +08:00
|
|
|
|
|
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
|
|
|
|
|
{
|
2022-03-25 09:40:56 +08:00
|
|
|
|
friend class FileSearchFilter;
|
|
|
|
|
|
2022-01-11 16:20:40 +08:00
|
|
|
|
public:
|
2022-01-24 09:44:42 +08:00
|
|
|
|
explicit FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController);
|
2022-03-25 09:40:56 +08:00
|
|
|
|
|
2022-01-11 16:20:40 +08:00
|
|
|
|
protected:
|
|
|
|
|
void run();
|
2022-03-25 09:40:56 +08:00
|
|
|
|
|
|
|
|
|
private:
|
2022-03-25 14:09:34 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief 通过索引进行搜索,如果搜索过程正常,返回true
|
|
|
|
|
* 如果搜索被打断,返回false.
|
|
|
|
|
* 搜索被打断是指用户使用同一个task发起多次搜索,导致searchId发生变化,那么上一次搜索即被打断。
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
bool searchWithIndex();
|
|
|
|
|
//同上
|
|
|
|
|
bool directSearch();
|
2022-03-25 09:40:56 +08:00
|
|
|
|
Xapian::Query creatQueryForFileSearch();
|
2022-04-26 10:43:02 +08:00
|
|
|
|
void sendErrorMsg(const QString &msg);
|
2022-03-25 09:40:56 +08:00
|
|
|
|
|
2022-01-11 16:20:40 +08:00
|
|
|
|
private:
|
|
|
|
|
FileSearchTask *m_FileSearchTask;
|
2022-01-24 09:44:42 +08:00
|
|
|
|
std::shared_ptr<SearchController> m_searchController;
|
2022-03-25 09:40:56 +08:00
|
|
|
|
|
|
|
|
|
size_t m_currentSearchId = 0;
|
|
|
|
|
QStringList m_validDirectories;
|
|
|
|
|
QStringList m_blackList;
|
2022-04-28 15:49:51 +08:00
|
|
|
|
QStringList m_labels;
|
2021-12-28 15:56:41 +08:00
|
|
|
|
};
|
2022-03-25 09:40:56 +08:00
|
|
|
|
|
|
|
|
|
class FileSearchFilter : public Xapian::MatchDecider {
|
|
|
|
|
public:
|
|
|
|
|
explicit FileSearchFilter(FileSearchWorker *parent);
|
|
|
|
|
bool operator ()(const Xapian::Document &doc) const;
|
|
|
|
|
|
2022-04-28 15:49:51 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief 检查path对应的文件是否包含labels中的标签
|
|
|
|
|
* @param path
|
|
|
|
|
* @param labels
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
static bool checkFileLabel(const QString &path, const QStringList &labels);
|
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
|
private:
|
2022-04-28 15:49:51 +08:00
|
|
|
|
FileSearchWorker *m_parent = nullptr;
|
2022-03-25 09:40:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
|
}
|
|
|
|
|
#endif // FILESEARCHTASK_H
|