2022-10-26 18:01:40 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022, 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-05-27 21:10:11 +08:00
|
|
|
#ifndef FILESEARCHPLUGIN_H
|
|
|
|
#define FILESEARCHPLUGIN_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QThreadPool>
|
2021-07-31 16:12:04 +08:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QFrame>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QAction>
|
2021-05-27 21:10:11 +08:00
|
|
|
|
|
|
|
#include "search-plugin-iface.h"
|
|
|
|
#include "common.h"
|
2021-07-31 16:12:04 +08:00
|
|
|
#include "action-label.h"
|
2021-12-09 13:57:19 +08:00
|
|
|
#include "separation-line.h"
|
2022-11-28 18:11:55 +08:00
|
|
|
#include "global-settings.h"
|
2023-09-01 17:30:21 +08:00
|
|
|
#include "icon-loader.h"
|
2022-11-28 18:11:55 +08:00
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
namespace UkuiSearch {
|
2021-05-27 21:10:11 +08:00
|
|
|
//internal plugin
|
|
|
|
class LIBSEARCH_EXPORT FileSearchPlugin : public QObject, public SearchPluginIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-12-15 13:43:42 +08:00
|
|
|
explicit FileSearchPlugin(QObject *parent = nullptr);
|
|
|
|
PluginType pluginType() override {return PluginType::SearchPlugin;}
|
|
|
|
const QString name() override;
|
|
|
|
const QString description() override;
|
|
|
|
const QIcon icon() override {return IconLoader::loadIconQt("folder");}
|
|
|
|
void setEnable(bool enable) override {m_enable = enable;}
|
|
|
|
bool isEnable() override {return m_enable;}
|
|
|
|
QString getPluginName() override;
|
|
|
|
|
|
|
|
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult) override;
|
|
|
|
void stopSearch() override;
|
|
|
|
QList<SearchPluginIface::Actioninfo> getActioninfo(int type) override;
|
|
|
|
void openAction(int actionkey, QString key, int type = 0) override;
|
2021-07-31 16:12:04 +08:00
|
|
|
// bool isPreviewEnable(QString key, int type);
|
|
|
|
// QWidget *previewPage(QString key, int type, QWidget *parent = nullptr);
|
2023-12-15 13:43:42 +08:00
|
|
|
QWidget *detailPage(const ResultInfo &ri) override;
|
2021-05-27 21:10:11 +08:00
|
|
|
|
|
|
|
private:
|
2021-07-31 16:12:04 +08:00
|
|
|
void initDetailPage();
|
|
|
|
QString m_currentActionKey;
|
|
|
|
QWidget *m_detailPage;
|
|
|
|
QVBoxLayout *m_detailLyt = nullptr;
|
|
|
|
QLabel *m_iconLabel = nullptr;
|
|
|
|
QFrame *m_nameFrame = nullptr;
|
|
|
|
QHBoxLayout *m_nameFrameLyt = nullptr;
|
|
|
|
QLabel *m_nameLabel = nullptr;
|
|
|
|
QLabel *m_pluginLabel = nullptr;
|
2021-12-09 13:57:19 +08:00
|
|
|
SeparationLine *m_line_1 = nullptr;
|
2021-07-31 16:12:04 +08:00
|
|
|
QFrame *m_pathFrame = nullptr;
|
|
|
|
QLabel *m_pathLabel1 = nullptr;
|
|
|
|
QLabel *m_pathLabel2 = nullptr;
|
|
|
|
QHBoxLayout *m_pathFrameLyt = nullptr;
|
|
|
|
QFrame *m_timeFrame = nullptr;
|
|
|
|
QLabel *m_timeLabel1 = nullptr;
|
|
|
|
QLabel *m_timeLabel2 = nullptr;
|
|
|
|
QHBoxLayout *m_timeFrameLyt = nullptr;
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
SeparationLine *m_line_2 = nullptr;
|
2021-07-31 16:12:04 +08:00
|
|
|
QFrame *m_actionFrame = nullptr;
|
|
|
|
QVBoxLayout *m_actionFrameLyt = nullptr;
|
|
|
|
ActionLabel *m_actionLabel1 = nullptr;
|
|
|
|
ActionLabel *m_actionLabel2 = nullptr;
|
|
|
|
ActionLabel *m_actionLabel3 = nullptr;
|
|
|
|
|
|
|
|
QVBoxLayout * m_actionLyt = nullptr;
|
|
|
|
|
2021-05-27 21:10:11 +08:00
|
|
|
bool m_enable = true;
|
|
|
|
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
|
|
|
QThreadPool m_pool;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LIBSEARCH_EXPORT DirSearchPlugin : public QObject, public SearchPluginIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-12-15 13:43:42 +08:00
|
|
|
explicit DirSearchPlugin(QObject *parent = nullptr);
|
|
|
|
PluginType pluginType() override {return PluginType::SearchPlugin;}
|
|
|
|
const QString name() override;
|
|
|
|
const QString description() override;
|
|
|
|
const QIcon icon() override {return IconLoader::loadIconQt("folder");}
|
|
|
|
void setEnable(bool enable) override {m_enable = enable;}
|
|
|
|
bool isEnable() override {return m_enable;}
|
|
|
|
QString getPluginName() override;
|
|
|
|
|
|
|
|
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult) override;
|
|
|
|
void stopSearch() override;
|
|
|
|
QList<SearchPluginIface::Actioninfo> getActioninfo(int type) override;
|
|
|
|
void openAction(int actionkey, QString key, int type = 0) override;
|
2021-07-31 16:12:04 +08:00
|
|
|
// bool isPreviewEnable(QString key, int type);
|
|
|
|
// QWidget *previewPage(QString key, int type, QWidget *parent = nullptr);
|
2023-12-15 13:43:42 +08:00
|
|
|
QWidget *detailPage(const ResultInfo &ri) override;
|
2021-05-27 21:10:11 +08:00
|
|
|
private:
|
2021-07-31 16:12:04 +08:00
|
|
|
void initDetailPage();
|
|
|
|
QWidget *m_detailPage = nullptr;
|
|
|
|
QString m_currentActionKey;
|
|
|
|
QVBoxLayout *m_detailLyt = nullptr;
|
|
|
|
QLabel *m_iconLabel = nullptr;
|
|
|
|
QFrame *m_nameFrame = nullptr;
|
|
|
|
QHBoxLayout *m_nameFrameLyt = nullptr;
|
|
|
|
QLabel *m_nameLabel = nullptr;
|
|
|
|
QLabel *m_pluginLabel = nullptr;
|
2021-12-09 13:57:19 +08:00
|
|
|
SeparationLine *m_line_1 = nullptr;
|
2021-07-31 16:12:04 +08:00
|
|
|
QFrame *m_pathFrame = nullptr;
|
|
|
|
QLabel *m_pathLabel1 = nullptr;
|
|
|
|
QLabel *m_pathLabel2 = nullptr;
|
|
|
|
QHBoxLayout *m_pathFrameLyt = nullptr;
|
|
|
|
QFrame *m_timeFrame = nullptr;
|
|
|
|
QLabel *m_timeLabel1 = nullptr;
|
|
|
|
QLabel *m_timeLabel2 = nullptr;
|
|
|
|
QHBoxLayout *m_timeFrameLyt = nullptr;
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
SeparationLine *m_line_2 = nullptr;
|
2021-07-31 16:12:04 +08:00
|
|
|
QFrame *m_actionFrame = nullptr;
|
|
|
|
QVBoxLayout *m_actionFrameLyt = nullptr;
|
|
|
|
ActionLabel *m_actionLabel1 = nullptr;
|
|
|
|
ActionLabel *m_actionLabel2 = nullptr;
|
|
|
|
ActionLabel *m_actionLabel3 = nullptr;
|
|
|
|
|
|
|
|
QVBoxLayout * m_actionLyt = nullptr;
|
|
|
|
|
2021-05-27 21:10:11 +08:00
|
|
|
bool m_enable = true;
|
|
|
|
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
|
|
|
QThreadPool m_pool;
|
|
|
|
};
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
class LIBSEARCH_EXPORT FileContentSearchPlugin : public QObject, public SearchPluginIface
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-12-15 13:43:42 +08:00
|
|
|
explicit FileContentSearchPlugin(QObject *parent = nullptr);
|
2023-11-01 10:56:16 +08:00
|
|
|
~FileContentSearchPlugin();
|
2023-12-15 13:43:42 +08:00
|
|
|
PluginType pluginType() override {return PluginType::SearchPlugin;}
|
|
|
|
const QString name() override;
|
|
|
|
const QString description() override;
|
|
|
|
const QIcon icon() override {return IconLoader::loadIconQt("folder");}
|
|
|
|
void setEnable(bool enable) override {m_enable = enable;}
|
|
|
|
bool isEnable() override {return m_enable;}
|
|
|
|
QString getPluginName() override;
|
|
|
|
|
|
|
|
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult) override;
|
|
|
|
void stopSearch() override;
|
|
|
|
QList<SearchPluginIface::Actioninfo> getActioninfo(int type) override;
|
|
|
|
void openAction(int actionkey, QString key, int type = 0) override;
|
2021-07-31 16:12:04 +08:00
|
|
|
// bool isPreviewEnable(QString key, int type);
|
|
|
|
// QWidget *previewPage(QString key, int type, QWidget *parent = nullptr);
|
2023-12-15 13:43:42 +08:00
|
|
|
QWidget *detailPage(const ResultInfo &ri) override;
|
2021-07-31 16:12:04 +08:00
|
|
|
QString getHtmlText(const QString & text, const QString & keyword);
|
2021-08-06 17:45:28 +08:00
|
|
|
QString wrapData(QLabel *p_label, const QString &text);
|
2021-05-27 21:10:11 +08:00
|
|
|
private:
|
2021-07-31 16:12:04 +08:00
|
|
|
void initDetailPage();
|
|
|
|
QWidget *m_detailPage = nullptr;
|
|
|
|
QString m_currentActionKey;
|
|
|
|
QVBoxLayout *m_detailLyt = nullptr;
|
|
|
|
QLabel *m_iconLabel = nullptr;
|
|
|
|
QFrame *m_nameFrame = nullptr;
|
|
|
|
QHBoxLayout *m_nameFrameLyt = nullptr;
|
|
|
|
QLabel *m_nameLabel = nullptr;
|
|
|
|
QLabel *m_pluginLabel = nullptr;
|
2021-12-09 13:57:19 +08:00
|
|
|
SeparationLine *m_line_1 = nullptr;
|
2021-07-31 16:12:04 +08:00
|
|
|
QLabel *m_snippetLabel = nullptr;
|
|
|
|
QFrame *m_pathFrame = nullptr;
|
|
|
|
QLabel *m_pathLabel1 = nullptr;
|
|
|
|
QLabel *m_pathLabel2 = nullptr;
|
|
|
|
QHBoxLayout *m_pathFrameLyt = nullptr;
|
|
|
|
QFrame *m_timeFrame = nullptr;
|
|
|
|
QLabel *m_timeLabel1 = nullptr;
|
|
|
|
QLabel *m_timeLabel2 = nullptr;
|
|
|
|
QHBoxLayout *m_timeFrameLyt = nullptr;
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
SeparationLine *m_line_2 = nullptr;
|
2021-07-31 16:12:04 +08:00
|
|
|
QFrame *m_actionFrame = nullptr;
|
|
|
|
QVBoxLayout *m_actionFrameLyt = nullptr;
|
|
|
|
ActionLabel *m_actionLabel1 = nullptr;
|
|
|
|
ActionLabel *m_actionLabel2 = nullptr;
|
|
|
|
ActionLabel *m_actionLabel3 = nullptr;
|
|
|
|
|
|
|
|
QVBoxLayout * m_actionLyt = nullptr;
|
|
|
|
QString m_keyWord;
|
2021-05-27 21:10:11 +08:00
|
|
|
bool m_enable = true;
|
|
|
|
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
|
|
|
QThreadPool m_pool;
|
2023-07-04 13:52:16 +08:00
|
|
|
QThreadPool m_thumbnailPool;
|
|
|
|
};
|
|
|
|
class ThumbnailCreator : public QObject, public QRunnable
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2024-01-23 15:02:35 +08:00
|
|
|
explicit ThumbnailCreator(const QString &url, const QSize &targetSize, qreal dpr, QObject *parent = nullptr);
|
2023-07-04 13:52:16 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void run() override;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void ready(QString url, const QImage &image);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_url;
|
2024-01-23 15:02:35 +08:00
|
|
|
QSize m_targetSize;
|
|
|
|
qreal m_dpr;
|
2021-05-27 21:10:11 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FILESEARCHPLUGIN_H
|