From 466a0bf75838e67e96b61f296de06205f2177030 Mon Sep 17 00:00:00 2001
From: Dirk Hohndel <dirk@hohndel.org>
Date: Sat, 20 Oct 2018 11:59:35 -0400
Subject: [PATCH] Mobile/filtering: update filter in separate thread

We can't use that while the model is shown, which is why this isn't hooked up.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
---
 mobile-widgets/qmlmanager.cpp | 13 +++++++++++++
 mobile-widgets/qmlmanager.h   |  1 +
 2 files changed, 14 insertions(+)

diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index c5603d434..009b1b4db 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -15,6 +15,8 @@
 #include <QDateTime>
 #include <QClipboard>
 #include <QFile>
+#include <QtConcurrent>
+#include <QFuture>
 
 #include <QBluetoothLocalDevice>
 
@@ -1844,6 +1846,17 @@ void QMLManager::showDownloadPage(QString deviceString)
 	emit pluggedInDeviceNameChanged();
 }
 
+void QMLManager::setFilter(const QString filterText)
+{
+	// show that we are doing something, then do something in another thread in order not to block the UI
+	QMetaObject::invokeMethod(qmlWindow, "showBusy");
+	QtConcurrent::run(QThreadPool::globalInstance(),
+			  [=]{
+				dlSortModel->setFilter(filterText);
+				QMetaObject::invokeMethod(qmlWindow, "hideBusy");
+			  });
+}
+
 #if defined(Q_OS_ANDROID)
 // implemented in core/android.cpp
 void checkPendingIntents();
diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h
index a8f67389c..98282425d 100644
--- a/mobile-widgets/qmlmanager.h
+++ b/mobile-widgets/qmlmanager.h
@@ -88,6 +88,7 @@ public:
 	Q_INVOKABLE int getDetectedProductIndex(const QString &currentVendorText);
 	Q_INVOKABLE int getConnectionIndex(const QString &deviceSubstr);
 	Q_INVOKABLE void setGitLocalOnly(const bool &value);
+	Q_INVOKABLE void setFilter(const QString filterText);
 
 	static QMLManager *instance();
 	Q_INVOKABLE void registerError(QString error);