on xenial help sign in
Cancel previous preview request on new preview call.
commit36437554dd91df2987cac6e46d1c1432c4cdfa9e authorPawel Stolowski <pawel.stolowski@canonical.com> dateMon 23 Sep 2013, 18:36 (13 years ago) parent6fe2f9b
2 files changed+21−1
plugins/Unity/scope.cpp+19−1 plugins/Unity/scope.h+2
plugins/Unity/scope.cpp+19−1
@@ -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.
plugins/Unity/scope.h+2
@@ -55,6 +55,7 @@ class Scope : public QObject
5555
5656public:
5757 explicit Scope(QObject *parent = 0);
58+ ~Scope();
5859
5960 /* getters */
6061 QString id() const;
@@ -131,6 +132,7 @@ private:
131132 QString m_searchQuery;
132133 QString m_noResultsHint;
133134 QString m_formFactor;
135+ GCancellable* m_previewCancellable;
134136};
135137
136138Q_DECLARE_METATYPE(Scope*)