on xenial help sign in
Use unity::glib::Cancellable.
105cfb0Pawel Stolowski
plugins/Unity/preview.cpp+3−25
@@ -48,13 +48,6 @@ Preview::Preview(QObject *parent):
48{
48{
49}
49}
50
50
51−Preview::~Preview()
52−{
53− if (m_actionCancellable) {
54− g_object_unref(m_actionCancellable);
55− }
56−}
57−
58QString Preview::rendererName() const
51QString Preview::rendererName() const
59{
52{
60 if (m_unityPreview) {
53 if (m_unityPreview) {
@@ -197,19 +190,8 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
197{
190{
198 if (m_unityPreview) {
191 if (m_unityPreview) {
199 auto unityHints = convertToHintsMap(hints);
192 auto unityHints = convertToHintsMap(hints);
200−
201− // cancel previous action
202− cancelAction();
203−
204− m_actionCancellable = g_cancellable_new();
193+ m_actionCancellable.Renew();
205− m_unityPreview->PerformAction(actionId.toStdString(),
194+ m_unityPreview->PerformAction(actionId.toStdString(), unityHints, nullptr, m_actionCancellable);
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);
213 } else {
195 } else {
214 qWarning() << "Preview not set";
196 qWarning() << "Preview not set";
215 }
197 }
@@ -217,9 +199,5 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
217
199
218void Preview::cancelAction()
200void Preview::cancelAction()
219{
201{
220− if (m_actionCancellable) {
202+ m_actionCancellable.Cancel();
221− g_cancellable_cancel(m_actionCancellable);
222− g_object_unref(m_actionCancellable);
223− m_actionCancellable = nullptr;
224− }
225}
203}
plugins/Unity/preview.h+2−2
@@ -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{
@@ -51,7 +52,6 @@ class Q_DECL_EXPORT Preview : public QObject
51
52
52public:
53public:
53 explicit Preview(QObject *parent = 0);
54 explicit Preview(QObject *parent = 0);
54− ~Preview();
55 static Preview* newFromUnityPreview(unity::dash::Preview::Ptr unityPreview);
55 static Preview* newFromUnityPreview(unity::dash::Preview::Ptr unityPreview);
56
56
57 QString rendererName() const;
57 QString rendererName() const;
@@ -83,7 +83,7 @@ private:
83 QList<QObject *> m_actions;
83 QList<QObject *> m_actions;
84 QList<QObject *> m_infoHints;
84 QList<QObject *> m_infoHints;
85 QVariantMap m_infoHintsHash;
85 QVariantMap m_infoHintsHash;
86− GCancellable* m_actionCancellable;
86+ unity::glib::Cancellable m_actionCancellable;
87};
87};
88
88
89Q_DECLARE_METATYPE(Preview *)
89Q_DECLARE_METATYPE(Preview *)
plugins/Unity/scope.cpp+2−20
@@ -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,19 +175,13 @@ 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− cancelActivation();
188− m_previewCancellable = g_cancellable_new();
178+ m_previewCancellable.Renew();
189 m_unityScope->Preview(res, nullptr, m_previewCancellable);
179 m_unityScope->Preview(res, nullptr, m_previewCancellable);
190}
180}
191
181
192void Scope::cancelActivation()
182void Scope::cancelActivation()
193{
183{
194− if (m_previewCancellable) {
184+ m_previewCancellable.Cancel();
195− g_cancellable_cancel(m_previewCancellable);
196− g_object_unref(m_previewCancellable);
197− m_previewCancellable = nullptr;
198− }
199}
185}
200
186
201void 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)
@@ -226,10 +212,6 @@ void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::Sco
226
212
227void 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)
228{
214{
229− if (m_previewCancellable) {
230− g_object_unref(m_previewCancellable);
231− m_previewCancellable = nullptr;
232− }
233 auto prv = Preview::newFromUnityPreview(preview);
215 auto prv = Preview::newFromUnityPreview(preview);
234 // 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.
235 // passing it by value is not possible.
217 // passing it by value is not possible.
plugins/Unity/scope.h+1−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;
@@ -134,7 +133,7 @@ private:
134 QString m_searchQuery;
133 QString m_searchQuery;
135 QString m_noResultsHint;
134 QString m_noResultsHint;
136 QString m_formFactor;
135 QString m_formFactor;
137− GCancellable* m_previewCancellable;
136+ unity::glib::Cancellable m_previewCancellable;
138};
137};
139
138
140Q_DECLARE_METATYPE(Scope*)
139Q_DECLARE_METATYPE(Scope*)