on xenial help sign in
Cancel previous preview request on new preview call.
3643755Pawel Stolowski
plugins/Unity/scope.cpp+19−1
@@ -39,10 +39,18 @@
39
39
40Scope::Scope(QObject *parent) : QObject(parent)
40Scope::Scope(QObject *parent) : QObject(parent)
41 , m_formFactor("phone")
41 , m_formFactor("phone")
42+ , m_previewCancellable(nullptr)
42{
43{
43 m_categories.reset(new Categories(this));
44 m_categories.reset(new Categories(this));
44}
45}
45
46
47+Scope::~Scope()
48+{
49+ if (m_previewCancellable) {
50+ g_object_unref(m_previewCancellable);
51+ }
52+}
53+
46QString Scope::id() const
54QString Scope::id() const
47{
55{
48 return QString::fromStdString(m_unityScope->id());
56 return QString::fromStdString(m_unityScope->id());
@@ -175,7 +183,13 @@ void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVaria
175 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
183 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
176{
184{
177 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
185 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
186+
187+ if (m_previewCancellable) {
188+ g_cancellable_cancel(m_previewCancellable);
189+ g_object_unref(m_previewCancellable);
190+ }
191+ m_previewCancellable = g_cancellable_new();
178− m_unityScope->Preview(res);
192+ m_unityScope->Preview(res, nullptr, m_previewCancellable);
179}
193}
180
194
181void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
195void 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
206
220
207void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
221void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
208{
222{
223+ if (m_previewCancellable) {
224+ g_object_unref(m_previewCancellable);
225+ m_previewCancellable = nullptr;
226+ }
209 auto prv = Preview::newFromUnityPreview(preview);
227 auto prv = Preview::newFromUnityPreview(preview);
210 // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
228 // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
211 // passing it by value is not possible.
229 // passing it by value is not possible.
plugins/Unity/scope.h+2
@@ -55,6 +55,7 @@ class Scope : public QObject
55
55
56public:
56public:
57 explicit Scope(QObject *parent = 0);
57 explicit Scope(QObject *parent = 0);
58+ ~Scope();
58
59
59 /* getters */
60 /* getters */
60 QString id() const;
61 QString id() const;
@@ -131,6 +132,7 @@ private:
131 QString m_searchQuery;
132 QString m_searchQuery;
132 QString m_noResultsHint;
133 QString m_noResultsHint;
133 QString m_formFactor;
134 QString m_formFactor;
135+ GCancellable* m_previewCancellable;
134};
136};
135
137
136Q_DECLARE_METATYPE(Scope*)
138Q_DECLARE_METATYPE(Scope*)