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; }; }