on xenial help sign in
Use unity::glib::Cancellable.
commit105cfb00e651458a825cbf1770e45d99a58621d9 authorPawel Stolowski <pawel.stolowski@canonical.com> dateWed 25 Sep 2013, 17:52 (13 years ago) parentd7c7b88
4 files changed+8−49
plugins/Unity/preview.cpp+3−25 plugins/Unity/preview.h+2−2 plugins/Unity/scope.cpp+2−20 plugins/Unity/scope.h+1−2
plugins/Unity/preview.cpp+3−25
@@ -48,13 +48,6 @@ Preview::Preview(QObject *parent):
4848{
4949}
5050
51−Preview::~Preview()
52−{
53− if (m_actionCancellable) {
54− g_object_unref(m_actionCancellable);
55− }
56−}
57−
5851QString Preview::rendererName() const
5952{
6053 if (m_unityPreview) {
@@ -197,19 +190,8 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
197190{
198191 if (m_unityPreview) {
199192 auto unityHints = convertToHintsMap(hints);
200−
201− // cancel previous action
202− cancelAction();
203−
204− m_actionCancellable = g_cancellable_new();
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);
193+ m_actionCancellable.Renew();
194+ m_unityPreview->PerformAction(actionId.toStdString(), unityHints, nullptr, m_actionCancellable);
213195 } else {
214196 qWarning() << "Preview not set";
215197 }
@@ -217,9 +199,5 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
217199
218200void Preview::cancelAction()
219201{
220− if (m_actionCancellable) {
221− g_cancellable_cancel(m_actionCancellable);
222− g_object_unref(m_actionCancellable);
223− m_actionCancellable = nullptr;
224− }
202+ m_actionCancellable.Cancel();
225203}
plugins/Unity/preview.h+2−2
@@ -33,6 +33,7 @@
3333// local
3434#include "result.h"
3535#include "previewaction.h"
36+#include <UnityCore/GLibWrapper.h>
3637
3738class Q_DECL_EXPORT Preview : public QObject
3839{
@@ -51,7 +52,6 @@ class Q_DECL_EXPORT Preview : public QObject
5152
5253public:
5354 explicit Preview(QObject *parent = 0);
54− ~Preview();
5555 static Preview* newFromUnityPreview(unity::dash::Preview::Ptr unityPreview);
5656
5757 QString rendererName() const;
@@ -83,7 +83,7 @@ private:
8383 QList<QObject *> m_actions;
8484 QList<QObject *> m_infoHints;
8585 QVariantMap m_infoHintsHash;
86− GCancellable* m_actionCancellable;
86+ unity::glib::Cancellable m_actionCancellable;
8787};
8888
8989Q_DECLARE_METATYPE(Preview *)
plugins/Unity/scope.cpp+2−20
@@ -39,18 +39,10 @@
3939
4040Scope::Scope(QObject *parent) : QObject(parent)
4141 , m_formFactor("phone")
42− , m_previewCancellable(nullptr)
4342{
4443 m_categories.reset(new Categories(this));
4544}
4645
47−Scope::~Scope()
48−{
49− if (m_previewCancellable) {
50− g_object_unref(m_previewCancellable);
51− }
52−}
53−
5446QString Scope::id() const
5547{
5648 return QString::fromStdString(m_unityScope->id());
@@ -183,19 +175,13 @@ void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVaria
183175 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
184176{
185177 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();
189179 m_unityScope->Preview(res, nullptr, m_previewCancellable);
190180}
191181
192182void Scope::cancelActivation()
193183{
194− if (m_previewCancellable) {
195− g_cancellable_cancel(m_previewCancellable);
196− g_object_unref(m_previewCancellable);
197− m_previewCancellable = nullptr;
198− }
184+ m_previewCancellable.Cancel();
199185}
200186
201187void 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
226212
227213void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
228214{
229− if (m_previewCancellable) {
230− g_object_unref(m_previewCancellable);
231− m_previewCancellable = nullptr;
232− }
233215 auto prv = Preview::newFromUnityPreview(preview);
234216 // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
235217 // passing it by value is not possible.
plugins/Unity/scope.h+1−2
@@ -55,7 +55,6 @@ class Scope : public QObject
5555
5656public:
5757 explicit Scope(QObject *parent = 0);
58− ~Scope();
5958
6059 /* getters */
6160 QString id() const;
@@ -134,7 +133,7 @@ private:
134133 QString m_searchQuery;
135134 QString m_noResultsHint;
136135 QString m_formFactor;
137− GCancellable* m_previewCancellable;
136+ unity::glib::Cancellable m_previewCancellable;
138137};
139138
140139Q_DECLARE_METATYPE(Scope*)