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

96 lines
2.6 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>
*/
2022-04-25 11:16:25 +08:00
#ifndef UKUI_SEARCH_FILE_CONTENT_SEARCH_TASK_H
#define UKUI_SEARCH_FILE_CONTENT_SEARCH_TASK_H
//ukui-search
#include "search-task-plugin-iface.h"
//Qt
#include <QThreadPool>
#include <QRunnable>
//Xapian
#include <xapian.h>
namespace UkuiSearch {
class FileContentSearchTask : public SearchTaskPluginIface
{
public:
explicit FileContentSearchTask(QObject *parent = nullptr);
~FileContentSearchTask() override;
void setController(const SearchController &searchController) override;
2022-04-25 11:16:25 +08:00
PluginType pluginType() override;
const QString name() override;
const QString description() override;
const QIcon icon() override;
void setEnable(bool enable) override;
bool isEnable() override;
QString getCustomSearchType() override;
SearchProperty::SearchType getSearchType() override;
void startSearch() override;
2022-04-25 11:16:25 +08:00
void stop() override;
bool isSearching() override;
2022-04-25 11:16:25 +08:00
private:
QThreadPool *m_pool = nullptr;
bool m_enable = true;
SearchController m_searchController;
2022-04-25 11:16:25 +08:00
};
class FileContentSearchWorker : public QRunnable
{
friend class FileContentSearchFilter;
public:
explicit FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, SearchController *searchController);
2022-04-25 11:16:25 +08:00
void run() override;
private:
bool execSearch();
inline Xapian::Query createQuery();
void sendErrorMsg(const QString &msg);
2022-04-25 11:16:25 +08:00
private:
FileContentSearchTask *m_fileContentSearchTask = nullptr;
SearchController *m_searchController = nullptr;
2022-04-25 11:16:25 +08:00
QStringList m_validDirectories;
size_t m_currentSearchId = 0;
int m_resultNum = 0;
2022-04-25 11:16:25 +08:00
};
class FileContentSearchFilter : public Xapian::MatchDecider {
public:
explicit FileContentSearchFilter(FileContentSearchWorker*);
bool operator ()(const Xapian::Document &doc) const override;
private:
FileContentSearchWorker *m_worker;
};
}
#endif //UKUI_SEARCH_FILE_CONTENT_SEARCH_TASK_H