@@ -39,10 +39,18 @@
3939
4040Scope::Scope(QObject *parent) : QObject(parent)
4141 , m_formFactor("phone")
42+ , m_previewCancellable(nullptr)
4243{
4344 m_categories.reset(new Categories(this));
4445}
4546
47+Scope::~Scope()
48+{
49+ if (m_previewCancellable) {
50+ g_object_unref(m_previewCancellable);
51+ }
52+}
53+
4654QString Scope::id() const
4755{
4856 return QString::fromStdString(m_unityScope->id());
@@ -175,7 +183,13 @@ void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVaria
175183 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
176184{
177185 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
178− m_unityScope->Preview(res);
186+
187+ if (m_previewCancellable) {
188+ g_cancellable_cancel(m_previewCancellable);
189+ g_object_unref(m_previewCancellable);
190+ }
191+ m_previewCancellable = g_cancellable_new();
192+ m_unityScope->Preview(res, nullptr, m_previewCancellable);
179193}
180194
181195void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
@@ -206,6 +220,10 @@ void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::Sco
206220
207221void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
208222{
223+ if (m_previewCancellable) {
224+ g_object_unref(m_previewCancellable);
225+ m_previewCancellable = nullptr;
226+ }
209227 auto prv = Preview::newFromUnityPreview(preview);
210228 // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
211229 // passing it by value is not possible.