2024-01-30 14:35:04 +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/>.
|
|
|
|
*
|
|
|
|
*/
|
2021-06-18 09:48:58 +08:00
|
|
|
#ifndef SETTINGSSEARCHPLUGIN_H
|
|
|
|
#define SETTINGSSEARCHPLUGIN_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-11-30 17:21:06 +08:00
|
|
|
#include <QDomDocument>
|
2022-11-29 20:07:53 +08:00
|
|
|
#include <QDBusInterface>
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
#include "action-label.h"
|
2021-12-09 13:57:19 +08:00
|
|
|
#include "separation-line.h"
|
2021-06-18 09:48:58 +08:00
|
|
|
#include "search-plugin-iface.h"
|
2023-09-01 17:30:21 +08:00
|
|
|
#include "icon-loader.h"
|
2021-06-18 09:48:58 +08:00
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
namespace UkuiSearch {
|
2021-06-18 09:48:58 +08:00
|
|
|
class LIBSEARCH_EXPORT SettingsSearchPlugin : public QObject, public SearchPluginIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2021-11-30 17:21:06 +08:00
|
|
|
friend class SettingsSearch;
|
|
|
|
friend class SettingsMatch;
|
2021-06-18 09:48:58 +08:00
|
|
|
public:
|
|
|
|
SettingsSearchPlugin(QObject *parent = nullptr);
|
|
|
|
PluginType pluginType() {return PluginType::SearchPlugin;}
|
|
|
|
const QString name();
|
|
|
|
const QString description();
|
2023-09-01 17:30:21 +08:00
|
|
|
const QIcon icon() {return IconLoader::loadIconQt("folder");}
|
2021-06-18 09:48:58 +08:00
|
|
|
void setEnable(bool enable) {m_enable = enable;}
|
|
|
|
bool isEnable() {return m_enable;}
|
|
|
|
QString getPluginName();
|
|
|
|
|
|
|
|
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
|
2022-02-12 14:20:55 +08:00
|
|
|
void stopSearch();
|
2021-06-18 09:48:58 +08:00
|
|
|
QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
|
|
|
|
void openAction(int actionkey, QString key, int type);
|
2021-07-31 16:12:04 +08:00
|
|
|
// bool isPreviewEnable(QString key, int type);
|
|
|
|
// QWidget *previewPage(QString key, int type, QWidget *parent);
|
|
|
|
QWidget *detailPage(const ResultInfo &ri);
|
2021-06-18 09:48:58 +08:00
|
|
|
|
|
|
|
private:
|
2021-07-31 16:12:04 +08:00
|
|
|
void initDetailPage();
|
2021-11-30 17:21:06 +08:00
|
|
|
bool m_enable = true;
|
|
|
|
QList<SettingsSearchPlugin::Actioninfo> m_actionInfo;
|
|
|
|
QThreadPool m_pool;
|
|
|
|
static size_t m_uniqueSymbolForSettings;
|
|
|
|
static QMutex m_mutex;
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
QString m_currentActionKey;
|
|
|
|
QWidget *m_detailPage = nullptr;
|
|
|
|
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_actionFrame = nullptr;
|
|
|
|
QVBoxLayout *m_actionFrameLyt = nullptr;
|
|
|
|
ActionLabel *m_actionLabel1 = nullptr;
|
|
|
|
QVBoxLayout * m_actionLyt = nullptr;
|
2021-11-30 17:21:06 +08:00
|
|
|
};
|
2021-07-31 16:12:04 +08:00
|
|
|
|
2021-11-30 17:21:06 +08:00
|
|
|
class SettingsSearch :public QObject, public QRunnable {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
SettingsSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, const QString& keyword, size_t uniqueSymbol);
|
|
|
|
~SettingsSearch() = default;
|
|
|
|
protected:
|
|
|
|
void run() override;
|
|
|
|
private:
|
|
|
|
QString m_keyword;
|
|
|
|
size_t m_uniqueSymbol;
|
|
|
|
DataQueue<SearchPluginIface::ResultInfo> *m_searchResult = nullptr;
|
|
|
|
};
|
2021-06-18 09:48:58 +08:00
|
|
|
|
2022-11-29 20:07:53 +08:00
|
|
|
class SettingsMatch :public QThread {
|
|
|
|
Q_OBJECT
|
2021-11-30 17:21:06 +08:00
|
|
|
public:
|
2022-11-29 20:07:53 +08:00
|
|
|
enum HandleType {
|
|
|
|
Add,
|
|
|
|
Delete
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(HandleTypes, HandleType)
|
|
|
|
|
2021-11-30 17:21:06 +08:00
|
|
|
static SettingsMatch *getInstance();
|
|
|
|
void startSearch(QString &keyword, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
|
2022-11-29 20:07:53 +08:00
|
|
|
public Q_SLOTS:
|
|
|
|
void addItem(QVariantMap replyMap);
|
|
|
|
void removeItem(QVariantMap replyMap);
|
2021-11-30 17:21:06 +08:00
|
|
|
protected:
|
|
|
|
void run() override;
|
|
|
|
private:
|
2022-11-29 20:07:53 +08:00
|
|
|
explicit SettingsMatch();
|
2021-11-30 17:21:06 +08:00
|
|
|
~SettingsMatch() = default;
|
2022-11-29 20:07:53 +08:00
|
|
|
|
|
|
|
//parsing dbus of ukcc
|
|
|
|
void initData();
|
|
|
|
void parsingArgsOfDbus(QVariantMap replyMap, HandleTypes type);
|
|
|
|
void handleData(const QVariantMap &itemInfo, HandleTypes type);
|
|
|
|
void add2DataMap(const QString &key, const QString &enName, const QString &localName);
|
|
|
|
|
|
|
|
//Parsing xml
|
2021-11-30 17:21:06 +08:00
|
|
|
void initDataOfXml();
|
|
|
|
bool matchCommonEnvironment(QDomNode childNode);
|
|
|
|
void matchNodes(QDomNode node);
|
2022-11-29 20:07:53 +08:00
|
|
|
|
|
|
|
//search
|
2023-10-08 16:48:24 +08:00
|
|
|
bool matchDataMap(QString &key, QString &keyword);
|
2021-11-30 17:21:06 +08:00
|
|
|
void createResultInfo(SearchPluginIface::ResultInfo &resultInfo, const QStringList &itemInfo, const QString &path);
|
2023-10-08 16:48:24 +08:00
|
|
|
bool enqueueResultInfo(SearchPluginIface::ResultInfo &resultInfo, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
|
2021-11-30 17:21:06 +08:00
|
|
|
QMap<QString, QMap<QString, QStringList>> m_searchMap;
|
|
|
|
QMap<QString, QStringList> m_dataMap;
|
2022-11-29 20:07:53 +08:00
|
|
|
QDBusInterface *m_interface = nullptr;
|
2021-06-18 09:48:58 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // SETTINGSSEARCHPLUGIN_H
|