on xenial help sign in
Support for action cancellation. Added Q_INVOKABLE methods to cancel preview / action.
d7c7b88Pawel Stolowski
plugins/Unity/preview.cpp+31−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),
@@ -46,6 +48,13 @@ Preview::Preview(QObject *parent):
46{
48{
47}
49}
48
50
51+Preview::~Preview()
52+{
53+ if (m_actionCancellable) {
54+ g_object_unref(m_actionCancellable);
55+ }
56+}
57+
49QString Preview::rendererName() const
58QString Preview::rendererName() const
50{
59{
51 if (m_unityPreview) {
60 if (m_unityPreview) {
@@ -188,8 +197,29 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
188{
197{
189 if (m_unityPreview) {
198 if (m_unityPreview) {
190 auto unityHints = convertToHintsMap(hints);
199 auto unityHints = convertToHintsMap(hints);
200+
201+ // cancel previous action
202+ cancelAction();
203+
204+ m_actionCancellable = g_cancellable_new();
191− m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
205+ m_unityPreview->PerformAction(actionId.toStdString(),
206+ unityHints,
207+ [this](unity::dash::LocalResult const&, unity::dash::ScopeHandledType, unity::glib::Error const&) {
208+ if (m_actionCancellable) {
209+ g_object_unref(m_actionCancellable);
210+ m_actionCancellable = nullptr;
211+ }
212+ }, m_actionCancellable);
192 } else {
213 } else {
193 qWarning() << "Preview not set";
214 qWarning() << "Preview not set";
194 }
215 }
195}
216}
217+
218+void Preview::cancelAction()
219+{
220+ if (m_actionCancellable) {
221+ g_cancellable_cancel(m_actionCancellable);
222+ g_object_unref(m_actionCancellable);
223+ m_actionCancellable = nullptr;
224+ }
225+}
plugins/Unity/preview.h+3
@@ -51,6 +51,7 @@ class Q_DECL_EXPORT Preview : public QObject
51
51
52public:
52public:
53 explicit Preview(QObject *parent = 0);
53 explicit Preview(QObject *parent = 0);
54+ ~Preview();
54 static Preview* newFromUnityPreview(unity::dash::Preview::Ptr unityPreview);
55 static Preview* newFromUnityPreview(unity::dash::Preview::Ptr unityPreview);
55
56
56 QString rendererName() const;
57 QString rendererName() const;
@@ -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+ GCancellable* m_actionCancellable;
84};
87};
85
88
86Q_DECLARE_METATYPE(Preview *)
89Q_DECLARE_METATYPE(Preview *)
plugins/Unity/scope.cpp+8−2
@@ -184,12 +184,18 @@ void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVaria
184{
184{
185 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
186
187+ cancelActivation();
188+ m_previewCancellable = g_cancellable_new();
189+ m_unityScope->Preview(res, nullptr, m_previewCancellable);
190+}
191+
192+void Scope::cancelActivation()
193+{
187 if (m_previewCancellable) {
194 if (m_previewCancellable) {
188 g_cancellable_cancel(m_previewCancellable);
195 g_cancellable_cancel(m_previewCancellable);
189 g_object_unref(m_previewCancellable);
196 g_object_unref(m_previewCancellable);
197+ m_previewCancellable = nullptr;
190 }
198 }
191− m_previewCancellable = g_cancellable_new();
192− m_unityScope->Preview(res, nullptr, m_previewCancellable);
193}
199}
194
200
195void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
201void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
plugins/Unity/scope.h+2
@@ -83,6 +83,8 @@ public:
83 Q_INVOKABLE void preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
83 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,
84 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
85 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata);
85 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata);
86+ Q_INVOKABLE void cancelActivation();
87+
86 void setUnityScope(const unity::dash::Scope::Ptr& scope);
88 void setUnityScope(const unity::dash::Scope::Ptr& scope);
87 unity::dash::Scope::Ptr unityScope() const;
89 unity::dash::Scope::Ptr unityScope() const;
88
90