on xenial help sign in
Support cancellation for preview actions.
9a3ba83Pawel Stolowski
plugins/Unity/preview.cpp+9−1
@@ -39,6 +39,8 @@
39#include <UnityCore/MusicPreview.h>
39#include <UnityCore/MusicPreview.h>
40#include <UnityCore/SocialPreview.h>
40#include <UnityCore/SocialPreview.h>
41
41
42+#include <UnityCore/GLibWrapper.h>
43+
42Preview::Preview(QObject *parent):
44Preview::Preview(QObject *parent):
43 QObject(parent),
45 QObject(parent),
44 m_unityPreview(nullptr),
46 m_unityPreview(nullptr),
@@ -188,8 +190,14 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
188{
190{
189 if (m_unityPreview) {
191 if (m_unityPreview) {
190 auto unityHints = convertToHintsMap(hints);
192 auto unityHints = convertToHintsMap(hints);
193+ m_actionCancellable.Renew();
191− m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
194+ m_unityPreview->PerformAction(actionId.toStdString(), unityHints, nullptr, m_actionCancellable);
192 } else {
195 } else {
193 qWarning() << "Preview not set";
196 qWarning() << "Preview not set";
194 }
197 }
195}
198}
199+
200+void Preview::cancelAction()
201+{
202+ m_actionCancellable.Cancel();
203+}
plugins/Unity/preview.h+3
@@ -33,6 +33,7 @@
33// local
33// local
34#include "result.h"
34#include "result.h"
35#include "previewaction.h"
35#include "previewaction.h"
36+#include <UnityCore/GLibWrapper.h>
36
37
37class Q_DECL_EXPORT Preview : public QObject
38class Q_DECL_EXPORT Preview : public QObject
38{
39{
@@ -65,6 +66,7 @@ public:
65 QVariant result() const;
66 QVariant result() const;
66
67
67 Q_INVOKABLE void execute(const QString& actionId, const QHash<QString, QVariant>& hints);
68 Q_INVOKABLE void execute(const QString& actionId, const QHash<QString, QVariant>& hints);
69+ Q_INVOKABLE void cancelAction();
68
70
69Q_SIGNALS:
71Q_SIGNALS:
70 void previewChanged();
72 void previewChanged();
@@ -81,6 +83,7 @@ private:
81 QList<QObject *> m_actions;
83 QList<QObject *> m_actions;
82 QList<QObject *> m_infoHints;
84 QList<QObject *> m_infoHints;
83 QVariantMap m_infoHintsHash;
85 QVariantMap m_infoHintsHash;
86+ unity::glib::Cancellable m_actionCancellable;
84};
87};
85
88
86Q_DECLARE_METATYPE(Preview *)
89Q_DECLARE_METATYPE(Preview *)
plugins/Unity/scope.cpp+6−18
@@ -39,18 +39,10 @@
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)
43{
42{
44 m_categories.reset(new Categories(this));
43 m_categories.reset(new Categories(this));
45}
44}
46
45
47−Scope::~Scope()
48−{
49− if (m_previewCancellable) {
50− g_object_unref(m_previewCancellable);
51− }
52−}
53−
54QString Scope::id() const
46QString Scope::id() const
55{
47{
56 return QString::fromStdString(m_unityScope->id());
48 return QString::fromStdString(m_unityScope->id());
@@ -183,14 +175,14 @@ void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVaria
183 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
175 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
184{
176{
185 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
177 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
186−
187− if (m_previewCancellable) {
178+ m_previewCancellable.Renew();
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);
179 m_unityScope->Preview(res, nullptr, m_previewCancellable);
193}
180}
181+
182+void Scope::cancelActivation()
183+{
184+ m_previewCancellable.Cancel();
185+}
194
186
195void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
187void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
196{
188{
@@ -220,10 +212,6 @@ void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::Sco
220
212
221void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
213void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
222{
214{
223− if (m_previewCancellable) {
224− g_object_unref(m_previewCancellable);
225− m_previewCancellable = nullptr;
226− }
227 auto prv = Preview::newFromUnityPreview(preview);
215 auto prv = Preview::newFromUnityPreview(preview);
228 // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
216 // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
229 // passing it by value is not possible.
217 // passing it by value is not possible.
plugins/Unity/scope.h+3−2
@@ -55,7 +55,6 @@ class Scope : public QObject
55
55
56public:
56public:
57 explicit Scope(QObject *parent = 0);
57 explicit Scope(QObject *parent = 0);
58− ~Scope();
59
58
60 /* getters */
59 /* getters */
61 QString id() const;
60 QString id() const;
@@ -83,6 +82,8 @@ public:
83 Q_INVOKABLE void preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
82 Q_INVOKABLE void preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
84 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
83 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
85 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata);
84 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata);
85+ Q_INVOKABLE void cancelActivation();
86+
86 void setUnityScope(const unity::dash::Scope::Ptr& scope);
87 void setUnityScope(const unity::dash::Scope::Ptr& scope);
87 unity::dash::Scope::Ptr unityScope() const;
88 unity::dash::Scope::Ptr unityScope() const;
88
89
@@ -132,7 +133,7 @@ private:
132 QString m_searchQuery;
133 QString m_searchQuery;
133 QString m_noResultsHint;
134 QString m_noResultsHint;
134 QString m_formFactor;
135 QString m_formFactor;
135− GCancellable* m_previewCancellable;
136+ unity::glib::Cancellable m_previewCancellable;
136};
137};
137
138
138Q_DECLARE_METATYPE(Scope*)
139Q_DECLARE_METATYPE(Scope*)