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

112 lines
3.1 KiB
C
Raw Normal View History

2023-04-11 10:19:35 +08:00
/*
*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*/
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 = nullptr);
~FileSearchTask();
void setController(const SearchController &searchController);
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) {Q_UNUSED(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();
2021-12-28 15:56:41 +08:00
void stop();
bool isSearching();
2021-12-28 15:56:41 +08:00
private:
2022-01-11 16:20:40 +08:00
QThreadPool *m_pool = nullptr;
SearchController m_searchController;
2022-01-11 16:20:40 +08:00
};
class FileSearchWorker : public QRunnable
{
friend class FileSearchFilter;
2022-01-11 16:20:40 +08:00
public:
explicit FileSearchWorker(FileSearchTask *fileSarchTask, 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;
SearchController *m_searchController = nullptr;
size_t m_currentSearchId = 0;
int m_resultNum = 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