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
|
|
|
#include "file-search-plugin.h"
|
2021-07-08 18:53:16 +08:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QHBoxLayout>
|
2021-09-23 10:31:13 +08:00
|
|
|
#include <QMessageBox>
|
2023-06-30 11:13:04 +08:00
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QMutexLocker>
|
2022-11-28 18:11:55 +08:00
|
|
|
#include "search-manager.h"
|
2023-05-31 17:59:20 +08:00
|
|
|
#include "file-indexer-config.h"
|
2023-06-30 11:13:04 +08:00
|
|
|
#include "libkydate.h"
|
2023-11-01 10:56:16 +08:00
|
|
|
#include "data-collecter.h"
|
2022-04-13 13:46:30 +08:00
|
|
|
|
|
|
|
#define OCR_ICONLABLE_WITH 352
|
2022-11-17 11:38:01 +08:00
|
|
|
#define OCR_ICONLABLE_HEIGHT 247
|
2021-12-14 14:43:35 +08:00
|
|
|
using namespace UkuiSearch;
|
2021-05-27 21:10:11 +08:00
|
|
|
|
2023-06-30 11:13:04 +08:00
|
|
|
static QMutex g_formatMutex;
|
|
|
|
static const QString DEFAULT_DATETIME_FORMAT = "yyyy/MM/dd hh:mm:ss";
|
|
|
|
|
|
|
|
class DateFormat : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
static DateFormat& getInstance() {
|
|
|
|
static DateFormat instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString format() {
|
|
|
|
QMutexLocker locker(&g_formatMutex);
|
|
|
|
if (m_dateFormat == DEFAULT_DATETIME_FORMAT) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
return m_dateFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void updateDateFormat(QString format) {
|
|
|
|
QMutexLocker locker(&g_formatMutex);
|
|
|
|
m_dateFormat = format + " hh:mm:ss";
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
explicit DateFormat(QObject *parent = nullptr) : QObject(parent)
|
|
|
|
{
|
|
|
|
char* shortFormat = kdk_system_get_shortformat();
|
|
|
|
m_dateFormat = shortFormat;
|
|
|
|
free(shortFormat);
|
|
|
|
if (m_dateFormat.isEmpty()) {
|
|
|
|
m_dateFormat = DEFAULT_DATETIME_FORMAT;
|
|
|
|
} else {
|
|
|
|
m_dateFormat += " hh:mm:ss";
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "connect sdk date signal" << QDBusConnection::sessionBus().connect("com.kylin.kysdk.DateServer",
|
|
|
|
"/com/kylin/kysdk/Date",
|
|
|
|
"com.kylin.kysdk.DateInterface",
|
|
|
|
"ShortDateSignal",
|
|
|
|
this, SLOT(updateDateFormat(QString)));
|
|
|
|
}
|
|
|
|
DateFormat(const DateFormat&) = delete;
|
|
|
|
DateFormat& operator = (const DateFormat&) = delete;
|
|
|
|
~DateFormat() = default;
|
|
|
|
|
|
|
|
QString m_dateFormat;
|
|
|
|
};
|
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
|
|
|
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
|
|
|
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
|
|
|
SearchPluginIface::Actioninfo CopyPath { 2, tr("Copy Path")};
|
|
|
|
m_actionInfo << open << Openpath << CopyPath;
|
2021-08-06 10:54:48 +08:00
|
|
|
m_pool.setMaxThreadCount(1);
|
2021-05-27 21:10:11 +08:00
|
|
|
m_pool.setExpiryTimeout(1000);
|
2021-07-31 16:12:04 +08:00
|
|
|
initDetailPage();
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString FileSearchPlugin::name()
|
|
|
|
{
|
2021-10-27 11:37:55 +08:00
|
|
|
return "File Search";
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString FileSearchPlugin::description()
|
|
|
|
{
|
|
|
|
return tr("File search.");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FileSearchPlugin::getPluginName()
|
|
|
|
{
|
|
|
|
return tr("File Search");
|
|
|
|
}
|
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
void UkuiSearch::FileSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
2021-08-25 18:00:53 +08:00
|
|
|
SearchManager::m_mutexFile.lock();
|
|
|
|
++SearchManager::uniqueSymbolFile;
|
|
|
|
SearchManager::m_mutexFile.unlock();
|
2021-05-27 21:10:11 +08:00
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
if(FileIndexerConfig::getInstance()->isFileIndexEnable()) {
|
2021-05-27 21:10:11 +08:00
|
|
|
FileSearch *filesearch;
|
2021-08-25 18:00:53 +08:00
|
|
|
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbolFile, keyword, FILE_SEARCH_VALUE, 1, 0, 5);
|
2021-05-27 21:10:11 +08:00
|
|
|
m_pool.start(filesearch);
|
2022-11-28 18:11:55 +08:00
|
|
|
} else{
|
|
|
|
DirectSearch *directSearch;
|
|
|
|
directSearch = new DirectSearch(keyword, searchResult, FILE_SEARCH_VALUE, SearchManager::uniqueSymbolFile);
|
|
|
|
m_pool.start(directSearch);
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 14:20:55 +08:00
|
|
|
void FileSearchPlugin::stopSearch()
|
|
|
|
{
|
|
|
|
SearchManager::m_mutexFile.lock();
|
|
|
|
++SearchManager::uniqueSymbolFile;
|
|
|
|
SearchManager::m_mutexFile.unlock();
|
|
|
|
}
|
|
|
|
|
2021-05-27 21:10:11 +08:00
|
|
|
QList<SearchPluginIface::Actioninfo> FileSearchPlugin::getActioninfo(int type)
|
|
|
|
{
|
2023-04-24 14:07:56 +08:00
|
|
|
Q_UNUSED(type)
|
2021-05-27 21:10:11 +08:00
|
|
|
return m_actionInfo;
|
|
|
|
}
|
|
|
|
|
2021-06-17 14:08:55 +08:00
|
|
|
void FileSearchPlugin::openAction(int actionkey, QString key, int type)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
2023-04-24 14:07:56 +08:00
|
|
|
Q_UNUSED(type)
|
2021-05-27 21:10:11 +08:00
|
|
|
//TODO add some return message here.
|
|
|
|
switch (actionkey) {
|
2023-11-01 10:56:16 +08:00
|
|
|
case 0:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileSearch"), QStringLiteral("openFile"));
|
2023-11-01 10:56:16 +08:00
|
|
|
if(FileUtils::openFile(key) == -1) {
|
|
|
|
QMessageBox msgBox(m_detailPage);
|
|
|
|
msgBox.setModal(true);
|
|
|
|
msgBox.addButton(tr("OK"), QMessageBox::YesRole);
|
|
|
|
msgBox.setIcon(QMessageBox::Information);
|
|
|
|
msgBox.setText(tr("Can not get a default application for opening %1.").arg(key));
|
|
|
|
msgBox.open();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileSearch"), QStringLiteral("openFileInDir"));
|
2023-11-01 10:56:16 +08:00
|
|
|
FileUtils::openFile(key, true);
|
|
|
|
break;
|
|
|
|
case 2:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileSearch"), QStringLiteral("copyPath"));
|
2023-11-01 10:56:16 +08:00
|
|
|
FileUtils::copyPath(key);
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
QWidget *FileSearchPlugin::detailPage(const ResultInfo &ri)
|
2021-07-08 18:53:16 +08:00
|
|
|
{
|
2021-07-31 16:12:04 +08:00
|
|
|
m_currentActionKey = ri.actionKey;
|
|
|
|
m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));
|
|
|
|
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
|
2021-08-10 17:50:50 +08:00
|
|
|
QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
|
2021-12-17 17:39:37 +08:00
|
|
|
m_nameLabel->setText(FileUtils::setAllTextBold(showname));
|
2022-02-16 17:12:48 +08:00
|
|
|
if(QString::compare(showname, ri.name)) {
|
2021-07-31 16:12:04 +08:00
|
|
|
m_nameLabel->setToolTip(ri.name);
|
2022-02-16 17:12:48 +08:00
|
|
|
} else {
|
|
|
|
m_nameLabel->setToolTip("");
|
|
|
|
}
|
2021-07-31 16:12:04 +08:00
|
|
|
m_pluginLabel->setText(tr("File"));
|
|
|
|
|
|
|
|
m_pathLabel2->setText(m_pathLabel2->fontMetrics().elidedText(m_currentActionKey, Qt::ElideRight, m_pathLabel2->width()));
|
|
|
|
m_pathLabel2->setToolTip(m_currentActionKey);
|
2023-06-30 11:13:04 +08:00
|
|
|
QString modTimeText = ri.description.at(1).value;
|
|
|
|
if (!DateFormat::getInstance().format().isEmpty()) {
|
|
|
|
QDateTime modTime = QDateTime::fromString(modTimeText, DEFAULT_DATETIME_FORMAT);
|
|
|
|
modTimeText = modTime.toString(DateFormat::getInstance().format());
|
|
|
|
}
|
|
|
|
m_timeLabel2->setText(modTimeText);
|
2021-07-31 16:12:04 +08:00
|
|
|
return m_detailPage;
|
2021-07-08 18:53:16 +08:00
|
|
|
}
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
void FileSearchPlugin::initDetailPage()
|
2021-07-08 18:53:16 +08:00
|
|
|
{
|
2021-07-31 16:12:04 +08:00
|
|
|
m_detailPage = new QWidget();
|
|
|
|
m_detailPage->setFixedWidth(360);
|
|
|
|
m_detailPage->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
m_detailLyt = new QVBoxLayout(m_detailPage);
|
|
|
|
m_detailLyt->setContentsMargins(8, 0, 16, 0);
|
|
|
|
m_iconLabel = new QLabel(m_detailPage);
|
|
|
|
m_iconLabel->setAlignment(Qt::AlignCenter);
|
|
|
|
m_iconLabel->setFixedHeight(128);
|
|
|
|
|
|
|
|
m_nameFrame = new QFrame(m_detailPage);
|
|
|
|
m_nameFrameLyt = new QHBoxLayout(m_nameFrame);
|
|
|
|
m_nameFrame->setLayout(m_nameFrameLyt);
|
|
|
|
m_nameFrameLyt->setContentsMargins(8, 0, 0, 0);
|
|
|
|
m_nameLabel = new QLabel(m_nameFrame);
|
|
|
|
m_nameLabel->setMaximumWidth(280);
|
|
|
|
m_pluginLabel = new QLabel(m_nameFrame);
|
|
|
|
m_pluginLabel->setEnabled(false);
|
|
|
|
m_nameFrameLyt->addWidget(m_nameLabel);
|
|
|
|
m_nameFrameLyt->addStretch();
|
|
|
|
m_nameFrameLyt->addWidget(m_pluginLabel);
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
m_line_1 = new SeparationLine(m_detailPage);
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_pathFrame = new QFrame(m_detailPage);
|
|
|
|
m_pathFrameLyt = new QHBoxLayout(m_pathFrame);
|
|
|
|
m_pathLabel1 = new QLabel(m_pathFrame);
|
|
|
|
m_pathLabel2 = new QLabel(m_pathFrame);
|
|
|
|
m_pathLabel1->setText(tr("Path"));
|
|
|
|
m_pathLabel2->setFixedWidth(240);
|
|
|
|
m_pathLabel2->setAlignment(Qt::AlignRight);
|
|
|
|
m_pathFrameLyt->addWidget(m_pathLabel1);
|
|
|
|
m_pathFrameLyt->addStretch();
|
|
|
|
m_pathFrameLyt->addWidget(m_pathLabel2);
|
|
|
|
|
|
|
|
m_timeFrame = new QFrame(m_detailPage);
|
|
|
|
m_timeFrameLyt = new QHBoxLayout(m_timeFrame);
|
|
|
|
m_timeLabel1 = new QLabel(m_timeFrame);
|
|
|
|
m_timeLabel2 = new QLabel(m_timeFrame);
|
|
|
|
m_timeLabel2->setAlignment(Qt::AlignRight);
|
|
|
|
m_timeLabel1->setText(tr("Last time modified"));
|
|
|
|
m_timeFrameLyt->addWidget(m_timeLabel1);
|
|
|
|
m_timeFrameLyt->addStretch();
|
|
|
|
m_timeFrameLyt->addWidget(m_timeLabel2);
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
m_line_2 = new SeparationLine(m_detailPage);
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_actionFrame = new QFrame(m_detailPage);
|
|
|
|
m_actionFrameLyt = new QVBoxLayout(m_actionFrame);
|
|
|
|
m_actionFrameLyt->setContentsMargins(8, 0, 0, 0);
|
|
|
|
m_actionLabel1 = new ActionLabel(tr("Open"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel2 = new ActionLabel(tr("Open path"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel3 = new ActionLabel(tr("Copy path"), m_currentActionKey, m_actionFrame);
|
|
|
|
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel1);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel2);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel3);
|
|
|
|
m_actionFrame->setLayout(m_actionFrameLyt);
|
|
|
|
|
|
|
|
m_detailLyt->addSpacing(50);
|
|
|
|
m_detailLyt->addWidget(m_iconLabel);
|
|
|
|
m_detailLyt->addWidget(m_nameFrame);
|
|
|
|
m_detailLyt->addWidget(m_line_1);
|
|
|
|
m_detailLyt->addWidget(m_pathFrame);
|
|
|
|
m_detailLyt->addWidget(m_timeFrame);
|
|
|
|
m_detailLyt->addWidget(m_line_2);
|
|
|
|
m_detailLyt->addWidget(m_actionFrame);
|
|
|
|
m_detailPage->setLayout(m_detailLyt);
|
|
|
|
m_detailLyt->addStretch();
|
|
|
|
|
|
|
|
connect(m_actionLabel1, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileSearch"), QStringLiteral("openFile"));
|
2021-09-23 10:31:13 +08:00
|
|
|
if(FileUtils::openFile(m_currentActionKey) == -1) {
|
|
|
|
QMessageBox msgBox(m_detailPage);
|
2023-04-24 17:36:37 +08:00
|
|
|
msgBox.setModal(true);
|
2023-07-04 17:59:32 +08:00
|
|
|
msgBox.addButton(tr("OK"), QMessageBox::YesRole);
|
2021-09-23 10:31:13 +08:00
|
|
|
msgBox.setIcon(QMessageBox::Information);
|
|
|
|
msgBox.setText(tr("Can not get a default application for opening %1.").arg(m_currentActionKey));
|
2023-04-24 17:36:37 +08:00
|
|
|
msgBox.open();
|
2021-09-23 10:31:13 +08:00
|
|
|
}
|
2021-07-31 16:12:04 +08:00
|
|
|
});
|
|
|
|
connect(m_actionLabel2, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileSearch"), QStringLiteral("openFileInDir"));
|
2021-07-31 16:12:04 +08:00
|
|
|
FileUtils::openFile(m_currentActionKey, true);
|
|
|
|
});
|
|
|
|
connect(m_actionLabel3, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileSearch"), QStringLiteral("copyPath"));
|
2021-07-31 16:12:04 +08:00
|
|
|
FileUtils::copyPath(m_currentActionKey);
|
|
|
|
});
|
2021-07-08 18:53:16 +08:00
|
|
|
}
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
//bool FileSearchPlugin::isPreviewEnable(QString key, int type)
|
|
|
|
//{
|
|
|
|
// return true;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//QWidget *FileSearchPlugin::previewPage(QString key, int type, QWidget *parent)
|
|
|
|
//{
|
|
|
|
// QWidget *previewPage = new QWidget(parent);
|
|
|
|
// QHBoxLayout * previewLyt = new QHBoxLayout(previewPage);
|
|
|
|
// previewLyt->setContentsMargins(0, 0, 0, 0);
|
|
|
|
// QLabel *label = new QLabel(previewPage);
|
|
|
|
// previewLyt->addWidget(label);
|
|
|
|
// label->setFixedHeight(120);
|
|
|
|
// previewPage->setFixedSize(120,120);
|
|
|
|
// previewLyt->setAlignment(Qt::AlignCenter);
|
|
|
|
// label->setPixmap(FileUtils::getFileIcon(QUrl::fromLocalFile(key).toString()).pixmap(120,120));
|
|
|
|
// return previewPage;
|
|
|
|
//}
|
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
DirSearchPlugin::DirSearchPlugin(QObject *parent) : QObject(parent)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
|
|
|
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
|
|
|
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
|
|
|
SearchPluginIface::Actioninfo CopyPath { 2, tr("Copy Path")};
|
|
|
|
m_actionInfo << open << Openpath << CopyPath;
|
2021-08-06 10:54:48 +08:00
|
|
|
m_pool.setMaxThreadCount(1);
|
2021-05-27 21:10:11 +08:00
|
|
|
m_pool.setExpiryTimeout(1000);
|
2021-07-31 16:12:04 +08:00
|
|
|
initDetailPage();
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString DirSearchPlugin::name()
|
|
|
|
{
|
2021-10-27 11:37:55 +08:00
|
|
|
return "Dir Search";
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString DirSearchPlugin::description()
|
|
|
|
{
|
|
|
|
return tr("Dir search.");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DirSearchPlugin::getPluginName()
|
|
|
|
{
|
|
|
|
return tr("Dir Search");
|
|
|
|
}
|
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
void UkuiSearch::DirSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
2021-08-25 18:00:53 +08:00
|
|
|
SearchManager::m_mutexDir.lock();
|
|
|
|
++SearchManager::uniqueSymbolDir;
|
|
|
|
SearchManager::m_mutexDir.unlock();
|
2021-05-27 21:10:11 +08:00
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
if(FileIndexerConfig::getInstance()->isFileIndexEnable()) {
|
2021-05-27 21:10:11 +08:00
|
|
|
FileSearch *filesearch;
|
2021-08-25 18:00:53 +08:00
|
|
|
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbolDir, keyword, DIR_SEARCH_VALUE, 1, 0, 5);
|
2021-05-27 21:10:11 +08:00
|
|
|
m_pool.start(filesearch);
|
2022-11-28 18:11:55 +08:00
|
|
|
} else {
|
|
|
|
DirectSearch *directSearch;
|
|
|
|
directSearch = new DirectSearch(keyword, searchResult, DIR_SEARCH_VALUE, SearchManager::uniqueSymbolDir);
|
|
|
|
m_pool.start(directSearch);
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 14:20:55 +08:00
|
|
|
void DirSearchPlugin::stopSearch()
|
|
|
|
{
|
|
|
|
SearchManager::m_mutexDir.lock();
|
|
|
|
++SearchManager::uniqueSymbolDir;
|
|
|
|
SearchManager::m_mutexDir.unlock();
|
|
|
|
}
|
|
|
|
|
2021-05-27 21:10:11 +08:00
|
|
|
QList<SearchPluginIface::Actioninfo> DirSearchPlugin::getActioninfo(int type)
|
|
|
|
{
|
2023-04-24 14:07:56 +08:00
|
|
|
Q_UNUSED(type)
|
2021-05-27 21:10:11 +08:00
|
|
|
return m_actionInfo;
|
|
|
|
}
|
|
|
|
|
2021-06-17 14:08:55 +08:00
|
|
|
void DirSearchPlugin::openAction(int actionkey, QString key, int type)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
2023-04-24 14:07:56 +08:00
|
|
|
Q_UNUSED(type)
|
2021-05-27 21:10:11 +08:00
|
|
|
//TODO add some return message here.
|
|
|
|
switch (actionkey) {
|
2023-11-01 10:56:16 +08:00
|
|
|
case 0:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("dirSearch"), QStringLiteral("openFile"));
|
2023-11-01 10:56:16 +08:00
|
|
|
FileUtils::openFile(key);
|
|
|
|
break;
|
|
|
|
case 1:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("dirSearch"), QStringLiteral("openFileInDir"));
|
2023-11-01 10:56:16 +08:00
|
|
|
FileUtils::openFile(key, true);
|
|
|
|
break;
|
|
|
|
case 2:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("dirSearch"), QStringLiteral("copyPath"));
|
2023-11-01 10:56:16 +08:00
|
|
|
FileUtils::copyPath(key);
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
QWidget *DirSearchPlugin::detailPage(const ResultInfo &ri)
|
2021-07-08 18:53:16 +08:00
|
|
|
{
|
2021-07-31 16:12:04 +08:00
|
|
|
m_currentActionKey = ri.actionKey;
|
|
|
|
m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));
|
|
|
|
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
|
2021-08-10 17:50:50 +08:00
|
|
|
QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
|
2021-12-17 17:39:37 +08:00
|
|
|
m_nameLabel->setText(FileUtils::setAllTextBold(showname));
|
2022-02-16 17:12:48 +08:00
|
|
|
if(QString::compare(showname, ri.name)) {
|
2021-07-31 16:12:04 +08:00
|
|
|
m_nameLabel->setToolTip(ri.name);
|
2022-02-16 17:12:48 +08:00
|
|
|
} else {
|
|
|
|
m_nameLabel->setToolTip("");
|
|
|
|
}
|
2022-05-23 15:48:16 +08:00
|
|
|
m_pluginLabel->setText(tr("Directory"));
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_pathLabel2->setText(m_pathLabel2->fontMetrics().elidedText(m_currentActionKey, Qt::ElideRight, m_pathLabel2->width()));
|
|
|
|
m_pathLabel2->setToolTip(m_currentActionKey);
|
2023-06-30 11:13:04 +08:00
|
|
|
QString modTimeText = ri.description.at(1).value;
|
|
|
|
if (!DateFormat::getInstance().format().isEmpty()) {
|
|
|
|
QDateTime modTime = QDateTime::fromString(modTimeText, DEFAULT_DATETIME_FORMAT);
|
|
|
|
modTimeText = modTime.toString(DateFormat::getInstance().format());
|
|
|
|
}
|
|
|
|
m_timeLabel2->setText(modTimeText);
|
2021-07-31 16:12:04 +08:00
|
|
|
return m_detailPage;
|
2021-07-08 18:53:16 +08:00
|
|
|
}
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
void DirSearchPlugin::initDetailPage()
|
2021-07-08 18:53:16 +08:00
|
|
|
{
|
2021-07-31 16:12:04 +08:00
|
|
|
m_detailPage = new QWidget();
|
|
|
|
m_detailPage->setFixedWidth(360);
|
|
|
|
m_detailPage->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
m_detailLyt = new QVBoxLayout(m_detailPage);
|
|
|
|
m_detailLyt->setContentsMargins(8, 0, 16, 0);
|
|
|
|
m_iconLabel = new QLabel(m_detailPage);
|
|
|
|
m_iconLabel->setAlignment(Qt::AlignCenter);
|
|
|
|
m_iconLabel->setFixedHeight(128);
|
|
|
|
|
|
|
|
m_nameFrame = new QFrame(m_detailPage);
|
|
|
|
m_nameFrameLyt = new QHBoxLayout(m_nameFrame);
|
|
|
|
m_nameFrame->setLayout(m_nameFrameLyt);
|
|
|
|
m_nameFrameLyt->setContentsMargins(8, 0, 0, 0);
|
|
|
|
m_nameLabel = new QLabel(m_nameFrame);
|
|
|
|
m_nameLabel->setMaximumWidth(280);
|
|
|
|
m_pluginLabel = new QLabel(m_nameFrame);
|
|
|
|
m_pluginLabel->setEnabled(false);
|
|
|
|
m_nameFrameLyt->addWidget(m_nameLabel);
|
|
|
|
m_nameFrameLyt->addStretch();
|
|
|
|
m_nameFrameLyt->addWidget(m_pluginLabel);
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
m_line_1 = new SeparationLine(m_detailPage);
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_pathFrame = new QFrame(m_detailPage);
|
|
|
|
m_pathFrameLyt = new QHBoxLayout(m_pathFrame);
|
|
|
|
m_pathLabel1 = new QLabel(m_pathFrame);
|
|
|
|
m_pathLabel2 = new QLabel(m_pathFrame);
|
|
|
|
m_pathLabel1->setText(tr("Path"));
|
|
|
|
m_pathLabel2->setFixedWidth(240);
|
|
|
|
m_pathLabel2->setAlignment(Qt::AlignRight);
|
|
|
|
m_pathFrameLyt->addWidget(m_pathLabel1);
|
|
|
|
m_pathFrameLyt->addStretch();
|
|
|
|
m_pathFrameLyt->addWidget(m_pathLabel2);
|
|
|
|
|
|
|
|
m_timeFrame = new QFrame(m_detailPage);
|
|
|
|
m_timeFrameLyt = new QHBoxLayout(m_timeFrame);
|
|
|
|
m_timeLabel1 = new QLabel(m_timeFrame);
|
|
|
|
m_timeLabel2 = new QLabel(m_timeFrame);
|
|
|
|
m_timeLabel2->setAlignment(Qt::AlignRight);
|
|
|
|
m_timeLabel1->setText(tr("Last time modified"));
|
|
|
|
m_timeFrameLyt->addWidget(m_timeLabel1);
|
|
|
|
m_timeFrameLyt->addStretch();
|
|
|
|
m_timeFrameLyt->addWidget(m_timeLabel2);
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
m_line_2 = new SeparationLine(m_detailPage);
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_actionFrame = new QFrame(m_detailPage);
|
|
|
|
m_actionFrameLyt = new QVBoxLayout(m_actionFrame);
|
|
|
|
m_actionFrameLyt->setContentsMargins(8, 0, 0, 0);
|
|
|
|
m_actionLabel1 = new ActionLabel(tr("Open"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel2 = new ActionLabel(tr("Open path"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel3 = new ActionLabel(tr("Copy path"), m_currentActionKey, m_actionFrame);
|
|
|
|
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel1);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel2);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel3);
|
|
|
|
m_actionFrame->setLayout(m_actionFrameLyt);
|
|
|
|
|
|
|
|
m_detailLyt->addSpacing(50);
|
|
|
|
m_detailLyt->addWidget(m_iconLabel);
|
|
|
|
m_detailLyt->addWidget(m_nameFrame);
|
|
|
|
m_detailLyt->addWidget(m_line_1);
|
|
|
|
m_detailLyt->addWidget(m_pathFrame);
|
|
|
|
m_detailLyt->addWidget(m_timeFrame);
|
|
|
|
m_detailLyt->addWidget(m_line_2);
|
|
|
|
m_detailLyt->addWidget(m_actionFrame);
|
|
|
|
m_detailPage->setLayout(m_detailLyt);
|
|
|
|
m_detailLyt->addStretch();
|
|
|
|
|
|
|
|
connect(m_actionLabel1, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("dirSearch"), QStringLiteral("openFile"));
|
2021-07-31 16:12:04 +08:00
|
|
|
FileUtils::openFile(m_currentActionKey);
|
|
|
|
});
|
|
|
|
connect(m_actionLabel2, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("dirSearch"), QStringLiteral("openFileInDir"));
|
2021-07-31 16:12:04 +08:00
|
|
|
FileUtils::openFile(m_currentActionKey, true);
|
|
|
|
});
|
|
|
|
connect(m_actionLabel3, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("dirSearch"), QStringLiteral("copyPath"));
|
2021-07-31 16:12:04 +08:00
|
|
|
FileUtils::copyPath(m_currentActionKey);
|
|
|
|
});
|
2021-07-08 18:53:16 +08:00
|
|
|
}
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
//bool DirSearchPlugin::isPreviewEnable(QString key, int type)
|
|
|
|
//{
|
|
|
|
// return false;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//QWidget *DirSearchPlugin::previewPage(QString key, int type, QWidget *parent)
|
|
|
|
//{
|
|
|
|
// return nullptr;
|
|
|
|
//}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
FileContentSearchPlugin::FileContentSearchPlugin(QObject *parent) : QObject(parent)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
|
|
|
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
|
|
|
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
|
|
|
SearchPluginIface::Actioninfo CopyPath { 2, tr("Copy Path")};
|
|
|
|
m_actionInfo << open << Openpath << CopyPath;
|
2021-08-06 10:54:48 +08:00
|
|
|
m_pool.setMaxThreadCount(1);
|
2023-07-04 13:52:16 +08:00
|
|
|
m_thumbnailPool.setMaxThreadCount(1);
|
2021-05-27 21:10:11 +08:00
|
|
|
m_pool.setExpiryTimeout(1000);
|
2021-07-31 16:12:04 +08:00
|
|
|
initDetailPage();
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
FileContentSearchPlugin::~FileContentSearchPlugin()
|
2023-07-04 13:52:16 +08:00
|
|
|
{
|
|
|
|
m_pool.clear();
|
|
|
|
m_thumbnailPool.clear();
|
|
|
|
m_thumbnailPool.waitForDone();
|
|
|
|
m_pool.waitForDone();
|
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
const QString FileContentSearchPlugin::name()
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
2021-10-27 11:37:55 +08:00
|
|
|
return "File Content Search";
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
const QString FileContentSearchPlugin::description()
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
|
|
|
return tr("File content search.");
|
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
QString FileContentSearchPlugin::getPluginName()
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
|
|
|
return tr("File content search");
|
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
void UkuiSearch::FileContentSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
2021-08-25 18:00:53 +08:00
|
|
|
SearchManager::m_mutexContent.lock();
|
|
|
|
++SearchManager::uniqueSymbolContent;
|
|
|
|
SearchManager::m_mutexContent.unlock();
|
2021-05-27 21:10:11 +08:00
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
m_keyWord = keyword;
|
2023-08-03 09:09:18 +08:00
|
|
|
if(FileIndexerConfig::getInstance()->isContentIndexEnable()) {
|
2021-05-27 21:10:11 +08:00
|
|
|
FileContentSearch *fileContentSearch;
|
2023-05-31 17:59:20 +08:00
|
|
|
fileContentSearch = new FileContentSearch(searchResult, SearchManager::uniqueSymbolContent, keyword, FileIndexerConfig::getInstance()->isFuzzySearchEnable(), 0, 5);
|
2021-05-27 21:10:11 +08:00
|
|
|
m_pool.start(fileContentSearch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
void FileContentSearchPlugin::stopSearch()
|
2022-02-12 14:20:55 +08:00
|
|
|
{
|
|
|
|
SearchManager::m_mutexContent.lock();
|
|
|
|
++SearchManager::uniqueSymbolContent;
|
|
|
|
SearchManager::m_mutexContent.unlock();
|
2023-07-04 13:52:16 +08:00
|
|
|
m_thumbnailPool.clear();
|
|
|
|
m_pool.clear();
|
2022-02-12 14:20:55 +08:00
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
QList<SearchPluginIface::Actioninfo> FileContentSearchPlugin::getActioninfo(int type)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
2023-04-24 14:07:56 +08:00
|
|
|
Q_UNUSED(type)
|
2021-05-27 21:10:11 +08:00
|
|
|
return m_actionInfo;
|
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
void FileContentSearchPlugin::openAction(int actionkey, QString key, int type)
|
2021-05-27 21:10:11 +08:00
|
|
|
{
|
2023-04-24 14:07:56 +08:00
|
|
|
Q_UNUSED(type)
|
2021-05-27 21:10:11 +08:00
|
|
|
//TODO add some return message here.
|
|
|
|
switch (actionkey) {
|
|
|
|
case 0:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileContentSearch"), QStringLiteral("openFile"));
|
2021-05-27 21:10:11 +08:00
|
|
|
FileUtils::openFile(key);
|
|
|
|
break;
|
|
|
|
case 1:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileContentSearch"), QStringLiteral("openFileInDir"));
|
2021-05-27 21:10:11 +08:00
|
|
|
FileUtils::openFile(key, true);
|
2023-04-23 16:27:45 +08:00
|
|
|
break;
|
2021-05-27 21:10:11 +08:00
|
|
|
case 2:
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileContentSearch"), QStringLiteral("copyPath"));
|
2021-05-27 21:10:11 +08:00
|
|
|
FileUtils::copyPath(key);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-07-08 18:53:16 +08:00
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
QWidget *FileContentSearchPlugin::detailPage(const ResultInfo &ri)
|
2021-07-08 18:53:16 +08:00
|
|
|
{
|
2023-09-13 15:16:50 +08:00
|
|
|
//因为需要更新时间格式所以每次调用detailpage需要先设置时间文本 20230916@bjj
|
|
|
|
QString modTimeText = ri.description.at(2).value;
|
|
|
|
if (!DateFormat::getInstance().format().isEmpty()) {
|
|
|
|
QDateTime modTime = QDateTime::fromString(modTimeText, DEFAULT_DATETIME_FORMAT);
|
|
|
|
modTimeText = modTime.toString(DateFormat::getInstance().format());
|
|
|
|
}
|
|
|
|
m_timeLabel2->setText(modTimeText);
|
|
|
|
|
2023-07-04 13:52:16 +08:00
|
|
|
if(ri.actionKey == m_currentActionKey) {
|
|
|
|
return m_detailPage;
|
|
|
|
}
|
2022-04-13 13:46:30 +08:00
|
|
|
if (1 == ri.type) {
|
2023-07-04 13:52:16 +08:00
|
|
|
auto creator = new ThumbnailCreator(ri.actionKey);
|
|
|
|
connect(creator, &ThumbnailCreator::ready, this, [&](QString uri, const QImage &image){
|
|
|
|
if(uri != m_currentActionKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPixmap pixmap = QPixmap::fromImage(image);
|
|
|
|
if(!pixmap.isNull()) {
|
|
|
|
m_iconLabel->setPixmap(pixmap.scaled(OCR_ICONLABLE_WITH, OCR_ICONLABLE_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
m_detailLyt->setContentsMargins(8, (OCR_ICONLABLE_HEIGHT-pixmap.height())/2 + 8, 16, 0);
|
|
|
|
} else {
|
|
|
|
m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));
|
|
|
|
}
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
m_thumbnailPool.start(creator);
|
2022-11-17 11:38:01 +08:00
|
|
|
|
2023-07-04 13:52:16 +08:00
|
|
|
m_iconLabel->setPixmap({});
|
|
|
|
m_detailLyt->setContentsMargins(8, 50, 16, 0);
|
2022-04-13 13:46:30 +08:00
|
|
|
m_pluginLabel->setText(tr("OCR"));
|
|
|
|
m_snippetLabel->hide();
|
|
|
|
} else {
|
|
|
|
m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));
|
|
|
|
m_pluginLabel->setText(tr("File"));
|
2023-07-18 16:18:58 +08:00
|
|
|
m_snippetLabel->setText(ri.description.at(0).value);
|
2022-04-13 13:46:30 +08:00
|
|
|
m_snippetLabel->show();
|
|
|
|
m_detailLyt->setContentsMargins(8, 50, 16, 0);
|
|
|
|
}
|
2021-07-31 16:12:04 +08:00
|
|
|
m_currentActionKey = ri.actionKey;
|
|
|
|
|
|
|
|
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
|
|
|
|
QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
|
2021-12-17 17:39:37 +08:00
|
|
|
m_nameLabel->setText(FileUtils::setAllTextBold(showname));
|
2022-02-16 17:12:48 +08:00
|
|
|
if(QString::compare(showname, ri.name)) {
|
2021-07-31 16:12:04 +08:00
|
|
|
m_nameLabel->setToolTip(ri.name);
|
2022-02-16 17:12:48 +08:00
|
|
|
} else {
|
|
|
|
m_nameLabel->setToolTip("");
|
|
|
|
}
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_pathLabel2->setText(m_pathLabel2->fontMetrics().elidedText(m_currentActionKey, Qt::ElideRight, m_pathLabel2->width()));
|
|
|
|
m_pathLabel2->setToolTip(m_currentActionKey);
|
|
|
|
return m_detailPage;
|
2021-07-08 18:53:16 +08:00
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
QString FileContentSearchPlugin::getHtmlText(const QString &text, const QString &keyword)
|
2021-07-08 18:53:16 +08:00
|
|
|
{
|
2021-07-31 16:12:04 +08:00
|
|
|
QString htmlString;
|
|
|
|
bool boldOpenned = false;
|
|
|
|
for(int i = 0; i < text.length(); i++) {
|
|
|
|
if((keyword.toUpper()).contains(QString(text.at(i)).toUpper())) {
|
|
|
|
if(! boldOpenned) {
|
|
|
|
boldOpenned = true;
|
|
|
|
htmlString.append(QString("<b><font size=\"4\">"));
|
|
|
|
}
|
|
|
|
htmlString.append(FileUtils::escapeHtml(QString(text.at(i))));
|
|
|
|
} else {
|
|
|
|
if(boldOpenned) {
|
|
|
|
boldOpenned = false;
|
|
|
|
htmlString.append(QString("</font></b>"));
|
|
|
|
}
|
|
|
|
htmlString.append(FileUtils::escapeHtml(QString(text.at(i))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
htmlString.replace("\n", "<br />");//替换换行符
|
2021-12-17 17:39:37 +08:00
|
|
|
return "<pre>" + htmlString + "</pre>";
|
2021-07-31 16:12:04 +08:00
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
QString FileContentSearchPlugin::wrapData(QLabel *p_label, const QString &text)
|
2021-08-06 17:45:28 +08:00
|
|
|
{
|
|
|
|
QString wrapText = text;
|
|
|
|
|
|
|
|
QFontMetrics fontMetrics = p_label->fontMetrics();
|
2023-04-24 14:07:56 +08:00
|
|
|
int textSize = fontMetrics.horizontalAdvance(wrapText);
|
2021-08-06 17:45:28 +08:00
|
|
|
if(textSize > LABEL_MAX_WIDTH){
|
|
|
|
int lastIndex = 0;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for(int i = lastIndex; i < wrapText.length(); i++) {
|
|
|
|
|
2023-04-24 14:07:56 +08:00
|
|
|
if(fontMetrics.horizontalAdvance(wrapText.mid(lastIndex, i - lastIndex)) == LABEL_MAX_WIDTH) {
|
2021-08-06 17:45:28 +08:00
|
|
|
lastIndex = i;
|
|
|
|
wrapText.insert(i, '\n');
|
|
|
|
count++;
|
2023-04-24 14:07:56 +08:00
|
|
|
} else if(fontMetrics.horizontalAdvance(wrapText.mid(lastIndex, i - lastIndex)) > LABEL_MAX_WIDTH) {
|
2021-08-06 17:45:28 +08:00
|
|
|
lastIndex = i;
|
|
|
|
wrapText.insert(i - 1, '\n');
|
|
|
|
count++;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count == 2){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_label->setText(wrapText);
|
|
|
|
return wrapText;
|
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
void FileContentSearchPlugin::initDetailPage()
|
2021-07-31 16:12:04 +08:00
|
|
|
{
|
|
|
|
m_detailPage = new QWidget();
|
|
|
|
m_detailPage->setFixedWidth(360);
|
|
|
|
m_detailPage->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
m_detailLyt = new QVBoxLayout(m_detailPage);
|
2022-04-13 13:46:30 +08:00
|
|
|
m_detailLyt->setContentsMargins(8, 50, 16, 0);
|
2021-07-31 16:12:04 +08:00
|
|
|
m_iconLabel = new QLabel(m_detailPage);
|
|
|
|
m_iconLabel->setAlignment(Qt::AlignCenter);
|
2022-04-13 13:46:30 +08:00
|
|
|
//m_iconLabel->setFixedHeight(128);
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_nameFrame = new QFrame(m_detailPage);
|
|
|
|
m_nameFrameLyt = new QHBoxLayout(m_nameFrame);
|
|
|
|
m_nameFrame->setLayout(m_nameFrameLyt);
|
|
|
|
m_nameFrameLyt->setContentsMargins(8, 0, 0, 0);
|
|
|
|
m_nameLabel = new QLabel(m_nameFrame);
|
|
|
|
m_nameLabel->setMaximumWidth(280);
|
|
|
|
m_pluginLabel = new QLabel(m_nameFrame);
|
|
|
|
m_pluginLabel->setEnabled(false);
|
|
|
|
m_nameFrameLyt->addWidget(m_nameLabel);
|
|
|
|
m_nameFrameLyt->addStretch();
|
|
|
|
m_nameFrameLyt->addWidget(m_pluginLabel);
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
m_line_1 = new SeparationLine(m_detailPage);
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_snippetLabel = new QLabel(m_detailPage);
|
2021-08-06 17:45:28 +08:00
|
|
|
// m_snippetLabel->setWordWrap(true);
|
2021-07-31 16:12:04 +08:00
|
|
|
m_snippetLabel->setContentsMargins(8, 0, 8, 0);
|
|
|
|
|
|
|
|
m_pathFrame = new QFrame(m_detailPage);
|
|
|
|
m_pathFrameLyt = new QHBoxLayout(m_pathFrame);
|
|
|
|
m_pathLabel1 = new QLabel(m_pathFrame);
|
|
|
|
m_pathLabel2 = new QLabel(m_pathFrame);
|
|
|
|
m_pathLabel1->setText(tr("Path"));
|
|
|
|
m_pathLabel2->setFixedWidth(240);
|
|
|
|
m_pathLabel2->setAlignment(Qt::AlignRight);
|
|
|
|
m_pathFrameLyt->addWidget(m_pathLabel1);
|
|
|
|
m_pathFrameLyt->addStretch();
|
|
|
|
m_pathFrameLyt->addWidget(m_pathLabel2);
|
|
|
|
|
|
|
|
m_timeFrame = new QFrame(m_detailPage);
|
|
|
|
m_timeFrameLyt = new QHBoxLayout(m_timeFrame);
|
|
|
|
m_timeLabel1 = new QLabel(m_timeFrame);
|
|
|
|
m_timeLabel2 = new QLabel(m_timeFrame);
|
|
|
|
m_timeLabel2->setAlignment(Qt::AlignRight);
|
|
|
|
m_timeLabel1->setText(tr("Last time modified"));
|
|
|
|
m_timeFrameLyt->addWidget(m_timeLabel1);
|
|
|
|
m_timeFrameLyt->addStretch();
|
|
|
|
m_timeFrameLyt->addWidget(m_timeLabel2);
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
m_line_2 = new SeparationLine(m_detailPage);
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_actionFrame = new QFrame(m_detailPage);
|
|
|
|
m_actionFrameLyt = new QVBoxLayout(m_actionFrame);
|
|
|
|
m_actionFrameLyt->setContentsMargins(8, 0, 0, 0);
|
|
|
|
m_actionLabel1 = new ActionLabel(tr("Open"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel2 = new ActionLabel(tr("Open path"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel3 = new ActionLabel(tr("Copy path"), m_currentActionKey, m_actionFrame);
|
|
|
|
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel1);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel2);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel3);
|
|
|
|
m_actionFrame->setLayout(m_actionFrameLyt);
|
|
|
|
|
2022-04-13 13:46:30 +08:00
|
|
|
// m_detailLyt->addSpacing(50);
|
2021-07-31 16:12:04 +08:00
|
|
|
m_detailLyt->addWidget(m_iconLabel);
|
|
|
|
m_detailLyt->addWidget(m_nameFrame);
|
|
|
|
m_detailLyt->addWidget(m_line_1);
|
|
|
|
m_detailLyt->addWidget(m_snippetLabel);
|
|
|
|
m_detailLyt->addWidget(m_pathFrame);
|
|
|
|
m_detailLyt->addWidget(m_timeFrame);
|
|
|
|
m_detailLyt->addWidget(m_line_2);
|
|
|
|
m_detailLyt->addWidget(m_actionFrame);
|
|
|
|
m_detailPage->setLayout(m_detailLyt);
|
|
|
|
m_detailLyt->addStretch();
|
|
|
|
|
|
|
|
connect(m_actionLabel1, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileContentSearch"), QStringLiteral("openFile"));
|
2021-07-31 16:12:04 +08:00
|
|
|
FileUtils::openFile(m_currentActionKey);
|
|
|
|
});
|
|
|
|
connect(m_actionLabel2, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileContentSearch"), QStringLiteral("openFileInDir"));
|
2021-07-31 16:12:04 +08:00
|
|
|
FileUtils::openFile(m_currentActionKey, true);
|
|
|
|
});
|
|
|
|
connect(m_actionLabel3, &ActionLabel::actionTriggered, [ & ](){
|
2023-11-16 10:47:41 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("fileContentSearch"), QStringLiteral("copyPath"));
|
2021-07-31 16:12:04 +08:00
|
|
|
FileUtils::copyPath(m_currentActionKey);
|
|
|
|
});
|
2021-07-08 18:53:16 +08:00
|
|
|
}
|
2021-07-31 16:12:04 +08:00
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
//bool FileContentSearchPlugin::isPreviewEnable(QString key, int type)
|
2021-07-31 16:12:04 +08:00
|
|
|
//{
|
|
|
|
// return false;
|
|
|
|
//}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
//QWidget *FileContentSearchPlugin::previewPage(QString key, int type, QWidget *parent)
|
2021-07-31 16:12:04 +08:00
|
|
|
//{
|
|
|
|
// return nullptr;
|
|
|
|
//}
|
2023-07-04 13:52:16 +08:00
|
|
|
|
|
|
|
ThumbnailCreator::ThumbnailCreator(QString url, QObject *parent): QObject(parent)
|
|
|
|
{
|
|
|
|
setAutoDelete(true);
|
|
|
|
m_url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailCreator::run()
|
|
|
|
{
|
|
|
|
Q_EMIT ready(m_url, QImage(m_url));
|
|
|
|
}
|
2023-06-30 11:13:04 +08:00
|
|
|
#include "file-search-plugin.moc"
|