Skip to content
Snippets Groups Projects
Commit 2343f34b authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Sébastien Blin
Browse files

messaging: run previewengine on its own thread

Change-Id: Iff267600c0802fbadedb58174b5fe65bbd1a443f
parent 692ba0d5
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@
#include "previewengine.h"
#include <QRegularExpression>
#include <QThread>
const QRegularExpression PreviewEngine::newlineRe("\\r?\\n");
......@@ -25,10 +26,21 @@ PreviewEngine::PreviewEngine(ConnectivityMonitor* cm, QObject* parent)
: NetworkManager(cm, parent)
, htmlParser_(new HtmlParser(this))
{
// Run this object in a separate thread.
thread_ = new QThread();
moveToThread(thread_);
thread_->start();
// Connect on a queued connection to avoid blocking caller thread.
connect(this, &PreviewEngine::parseLink, this, &PreviewEngine::onParseLink, Qt::QueuedConnection);
}
PreviewEngine::~PreviewEngine()
{
thread_->quit();
thread_->wait();
}
QString
PreviewEngine::getTagContent(const QList<QString>& tags, const QString& value)
{
......
......@@ -27,7 +27,7 @@ class PreviewEngine final : public NetworkManager
Q_DISABLE_COPY(PreviewEngine)
public:
PreviewEngine(ConnectivityMonitor* cm, QObject* parent = nullptr);
~PreviewEngine() = default;
~PreviewEngine();
Q_SIGNALS:
void parseLink(const QString& messageId, const QString& link);
......@@ -45,4 +45,6 @@ private:
QString getImage(const QList<QString>& metaTags);
static const QRegularExpression newlineRe;
QThread* thread_;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment