From 243a2874e73cf015f1bc73661f03cedc47c37407 Mon Sep 17 00:00:00 2001 From: iaom Date: Tue, 4 Jul 2023 13:52:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=86=85=E5=AE=B9=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8F=92=E4=BB=B6=E8=AF=A6=E6=83=85=E9=A1=B5=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=A4=A7=E5=9B=BE=E7=89=87=E6=97=B6=E9=98=BB=E5=A1=9E?= =?UTF-8?q?ui=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/appsearch/app-search-plugin.cpp | 2 +- libsearch/index/file-search-plugin.cpp | 50 +++++++++++++++++++---- libsearch/index/file-search-plugin.h | 17 ++++++++ 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index 55de443..8693926 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -296,7 +296,7 @@ bool AppSearchPlugin::launch(const QString &path) if(reply.isValid()) { res = reply; } else { - qWarning() << "SoftWareCenter dbus called failed!"; + qWarning() << "AppManager dbus called failed!"; res = false; } } diff --git a/libsearch/index/file-search-plugin.cpp b/libsearch/index/file-search-plugin.cpp index 1a6ed9f..639efa5 100644 --- a/libsearch/index/file-search-plugin.cpp +++ b/libsearch/index/file-search-plugin.cpp @@ -431,10 +431,19 @@ FileContengSearchPlugin::FileContengSearchPlugin(QObject *parent) : QObject(pare SearchPluginIface::Actioninfo CopyPath { 2, tr("Copy Path")}; m_actionInfo << open << Openpath << CopyPath; m_pool.setMaxThreadCount(1); + m_thumbnailPool.setMaxThreadCount(1); m_pool.setExpiryTimeout(1000); initDetailPage(); } +FileContengSearchPlugin::~FileContengSearchPlugin() +{ + m_pool.clear(); + m_thumbnailPool.clear(); + m_thumbnailPool.waitForDone(); + m_pool.waitForDone(); +} + const QString FileContengSearchPlugin::name() { return "File Content Search"; @@ -469,6 +478,8 @@ void FileContengSearchPlugin::stopSearch() SearchManager::m_mutexContent.lock(); ++SearchManager::uniqueSymbolContent; SearchManager::m_mutexContent.unlock(); + m_thumbnailPool.clear(); + m_pool.clear(); } QList FileContengSearchPlugin::getActioninfo(int type) @@ -497,17 +508,27 @@ void FileContengSearchPlugin::openAction(int actionkey, QString key, int type) QWidget *FileContengSearchPlugin::detailPage(const ResultInfo &ri) { + if(ri.actionKey == m_currentActionKey) { + return m_detailPage; + } if (1 == ri.type) { - QPixmap pixmap; - if(pixmap.load(ri.actionKey)) { - pixmap = 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 { - pixmap = ri.icon.pixmap(120, 120); - m_detailLyt->setContentsMargins(8, 50, 16, 0); - } + 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); - m_iconLabel->setPixmap(pixmap); + m_iconLabel->setPixmap({}); + m_detailLyt->setContentsMargins(8, 50, 16, 0); m_pluginLabel->setText(tr("OCR")); m_snippetLabel->hide(); } else { @@ -686,3 +707,14 @@ void FileContengSearchPlugin::initDetailPage() //{ // return nullptr; //} + +ThumbnailCreator::ThumbnailCreator(QString url, QObject *parent): QObject(parent) +{ + setAutoDelete(true); + m_url = url; +} + +void ThumbnailCreator::run() +{ + Q_EMIT ready(m_url, QImage(m_url)); +} diff --git a/libsearch/index/file-search-plugin.h b/libsearch/index/file-search-plugin.h index 12c8387..1e2f8a4 100644 --- a/libsearch/index/file-search-plugin.h +++ b/libsearch/index/file-search-plugin.h @@ -151,6 +151,7 @@ class LIBSEARCH_EXPORT FileContengSearchPlugin : public QObject, public SearchPl Q_OBJECT public: FileContengSearchPlugin(QObject *parent = nullptr); + ~FileContengSearchPlugin(); PluginType pluginType() {return PluginType::SearchPlugin;} const QString name(); const QString description(); @@ -201,6 +202,22 @@ private: bool m_enable = true; QList m_actionInfo; QThreadPool m_pool; + QThreadPool m_thumbnailPool; +}; +class ThumbnailCreator : public QObject, public QRunnable +{ + Q_OBJECT +public: + ThumbnailCreator(QString url, QObject *parent = nullptr); + +protected: + void run() override; + +Q_SIGNALS: + void ready(QString url, const QImage &image); + +private: + QString m_url; }; }