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
|
|
|
|
{
|
2023-11-27 11:20:16 +08:00
|
|
|
Q_OBJECT
|
2022-04-25 11:16:25 +08:00
|
|
|
public:
|
|
|
|
explicit FileContentSearchTask(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
~FileContentSearchTask() override;
|
2023-07-06 15:27:23 +08:00
|
|
|
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;
|
2023-03-15 16:39:38 +08:00
|
|
|
SearchProperty::SearchType getSearchType() override;
|
2023-05-06 15:41:56 +08:00
|
|
|
void startSearch() override;
|
2022-04-25 11:16:25 +08:00
|
|
|
void stop() override;
|
2023-07-06 15:27:23 +08:00
|
|
|
bool isSearching() override;
|
2022-04-25 11:16:25 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
QThreadPool *m_pool = nullptr;
|
2022-06-13 13:38:47 +08:00
|
|
|
bool m_enable = true;
|
2023-07-06 15:27:23 +08:00
|
|
|
SearchController m_searchController;
|
2022-04-25 11:16:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileContentSearchWorker : public QRunnable
|
|
|
|
{
|
|
|
|
friend class FileContentSearchFilter;
|
|
|
|
|
|
|
|
public:
|
2023-07-06 15:27:23 +08:00
|
|
|
explicit FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, SearchController *searchController);
|
2022-04-25 11:16:25 +08:00
|
|
|
void run() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool execSearch();
|
|
|
|
inline Xapian::Query createQuery();
|
|
|
|
|
2022-04-26 10:43:02 +08:00
|
|
|
void sendErrorMsg(const QString &msg);
|
|
|
|
|
2022-04-25 11:16:25 +08:00
|
|
|
private:
|
|
|
|
FileContentSearchTask *m_fileContentSearchTask = nullptr;
|
2023-05-06 15:41:56 +08:00
|
|
|
SearchController *m_searchController = nullptr;
|
2022-04-25 11:16:25 +08:00
|
|
|
QStringList m_validDirectories;
|
|
|
|
size_t m_currentSearchId = 0;
|
2023-05-19 15:15:28 +08:00
|
|
|
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
|