on xenial help sign in
Cancel previous actions and previews on new activation / preview. Expose previewed data row in Preview object.
ad32a97Pawel Stolowski
debian/control+1−1
@@ -21,7 +21,7 @@ Build-Depends: cmake,
21 libqt5v8-5-private-dev,
21 libqt5v8-5-private-dev,
22 libsigc++-2.0-dev,
22 libsigc++-2.0-dev,
23 libunity-api-dev (>= 7.80.3),
23 libunity-api-dev (>= 7.80.3),
24− libunity-core-6.0-dev (<< 7.80),
24+ libunity-core-6.0-dev (>= 7.1.1),
25 libunity-dev (>= 7.0.12),
25 libunity-dev (>= 7.0.12),
26 libunity-mir-dev,
26 libunity-mir-dev,
27 libunity-scopes-json-def-phone,
27 libunity-scopes-json-def-phone,
plugins/Unity/CMakeLists.txt+1
@@ -43,6 +43,7 @@ set(QMLPLUGIN_SRC
43 preview.cpp
43 preview.cpp
44 previewaction.cpp
44 previewaction.cpp
45 previewinfohint.cpp
45 previewinfohint.cpp
46+ result.cpp
46 showallfilteroption.cpp
47 showallfilteroption.cpp
47 signalslist.cpp
48 signalslist.cpp
48 socialpreview.cpp
49 socialpreview.cpp
plugins/Unity/plugin.cpp+2
@@ -35,6 +35,7 @@
35#include "categoryresults.h"
35#include "categoryresults.h"
36#include "bottombarvisibilitycommunicatorshell.h"
36#include "bottombarvisibilitycommunicatorshell.h"
37#include "genericoptionsmodel.h"
37#include "genericoptionsmodel.h"
38+#include "result.h"
38
39
39// libqtdee
40// libqtdee
40#include "deelistmodel.h"
41#include "deelistmodel.h"
@@ -50,6 +51,7 @@ void UnityPlugin::registerTypes(const char *uri)
50 qmlRegisterUncreatableType<PreviewInfoHint>(uri, 0, 1, "PreviewInfoHint", "Can't create PreviewInfoHint object in QML.");
51 qmlRegisterUncreatableType<PreviewInfoHint>(uri, 0, 1, "PreviewInfoHint", "Can't create PreviewInfoHint object in QML.");
51 qmlRegisterUncreatableType<SocialPreviewComment>(uri, 0, 1, "SocialPreviewComment", "Can't create SocialPreviewComment object in QML.");
52 qmlRegisterUncreatableType<SocialPreviewComment>(uri, 0, 1, "SocialPreviewComment", "Can't create SocialPreviewComment object in QML.");
52 qmlRegisterUncreatableType<GenericOptionsModel>(uri, 0, 1, "GenericOptionsModel", "Can't create options model in QML.");
53 qmlRegisterUncreatableType<GenericOptionsModel>(uri, 0, 1, "GenericOptionsModel", "Can't create options model in QML.");
54+ qmlRegisterUncreatableType<Result>(uri, 0, 1, "Result", "Can't create result object in QML.");
53 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
55 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
54 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
56 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
55 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
57 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
plugins/Unity/preview.cpp+17−2
@@ -39,9 +39,12 @@
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),
47+ m_result(new Result(this))
45{
48{
46}
49}
47
50
@@ -123,6 +126,11 @@ QString Preview::imageSourceUri() const
123 return QString::null;
126 return QString::null;
124}
127}
125
128
129+QVariant Preview::result() const
130+{
131+ return QVariant::fromValue(m_result);
132+}
133+
126Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
134Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
127{
135{
128 Preview* preview = nullptr;
136 Preview* preview = nullptr;
@@ -151,6 +159,7 @@ Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
151void Preview::setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview)
159void Preview::setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview)
152{
160{
153 m_unityPreview = unityPreview;
161 m_unityPreview = unityPreview;
162+ m_result->setPreview(unityPreview);
154
163
155 qDeleteAll(m_infoHints);
164 qDeleteAll(m_infoHints);
156 m_infoHints.clear();
165 m_infoHints.clear();
@@ -181,8 +190,14 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
181{
190{
182 if (m_unityPreview) {
191 if (m_unityPreview) {
183 auto unityHints = convertToHintsMap(hints);
192 auto unityHints = convertToHintsMap(hints);
193+ m_actionCancellable.Renew();
184− m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
194+ m_unityPreview->PerformAction(actionId.toStdString(), unityHints, nullptr, m_actionCancellable);
185 } else {
195 } else {
186 qWarning() << "Preview not set";
196 qWarning() << "Preview not set";
187 }
197 }
188}
198}
199+
200+void Preview::cancelAction()
201+{
202+ m_actionCancellable.Cancel();
203+}
plugins/Unity/preview.h+7
@@ -31,7 +31,9 @@
31#include <UnityCore/Preview.h>
31#include <UnityCore/Preview.h>
32
32
33// local
33// local
34+#include "result.h"
34#include "previewaction.h"
35#include "previewaction.h"
36+#include <UnityCore/GLibWrapper.h>
35
37
36class Q_DECL_EXPORT Preview : public QObject
38class Q_DECL_EXPORT Preview : public QObject
37{
39{
@@ -46,6 +48,7 @@ class Q_DECL_EXPORT Preview : public QObject
46 Q_PROPERTY(QVariantMap infoMap READ infoHintsHash NOTIFY previewChanged)
48 Q_PROPERTY(QVariantMap infoMap READ infoHintsHash NOTIFY previewChanged)
47 Q_PROPERTY(QString image READ image NOTIFY previewChanged)
49 Q_PROPERTY(QString image READ image NOTIFY previewChanged)
48 Q_PROPERTY(QString imageSourceUri READ imageSourceUri NOTIFY previewChanged)
50 Q_PROPERTY(QString imageSourceUri READ imageSourceUri NOTIFY previewChanged)
51+ Q_PROPERTY(QVariant result READ result NOTIFY previewChanged)
49
52
50public:
53public:
51 explicit Preview(QObject *parent = 0);
54 explicit Preview(QObject *parent = 0);
@@ -60,8 +63,10 @@ public:
60 QVariantMap infoHintsHash() const;
63 QVariantMap infoHintsHash() const;
61 QString image() const;
64 QString image() const;
62 QString imageSourceUri() const;
65 QString imageSourceUri() const;
66+ QVariant result() const;
63
67
64 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();
65
70
66Q_SIGNALS:
71Q_SIGNALS:
67 void previewChanged();
72 void previewChanged();
@@ -70,6 +75,7 @@ protected:
70 virtual void setUnityPreview(unity::dash::Preview::Ptr unityPreview);
75 virtual void setUnityPreview(unity::dash::Preview::Ptr unityPreview);
71
76
72 unity::dash::Preview::Ptr m_unityPreview;
77 unity::dash::Preview::Ptr m_unityPreview;
78+ Result* m_result;
73
79
74private:
80private:
75 void setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview);
81 void setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview);
@@ -77,6 +83,7 @@ private:
77 QList<QObject *> m_actions;
83 QList<QObject *> m_actions;
78 QList<QObject *> m_infoHints;
84 QList<QObject *> m_infoHints;
79 QVariantMap m_infoHintsHash;
85 QVariantMap m_infoHintsHash;
86+ unity::glib::Cancellable m_actionCancellable;
80};
87};
81
88
82Q_DECLARE_METATYPE(Preview *)
89Q_DECLARE_METATYPE(Preview *)
plugins/Unity/result.cppnew file+82
@@ -0,0 +1,82 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+#include "result.h"
21+#include "variantutils.h"
22+
23+Result::Result(QObject *parent) :
24+ QObject(parent)
25+{
26+}
27+
28+Result::Result(unity::dash::Preview::Ptr preview, QObject *parent) :
29+ QObject(parent),
30+ m_preview(preview)
31+{
32+}
33+
34+void Result::setPreview(unity::dash::Preview::Ptr preview)
35+{
36+ m_preview = preview;
37+}
38+
39+QString Result::uri() const
40+{
41+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.uri) : QString::null;
42+}
43+
44+QString Result::iconHint() const
45+{
46+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.icon_hint) : QString::null;
47+}
48+
49+unsigned Result::categoryIndex() const
50+{
51+ return m_preview != nullptr ? m_preview->preview_result.category_index : 0;
52+}
53+
54+unsigned Result::resultType() const
55+{
56+ return m_preview != nullptr ? m_preview->preview_result.result_type : 0;
57+}
58+
59+QString Result::mimeType() const
60+{
61+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.mimetype) : QString::null;
62+}
63+
64+QString Result::title() const
65+{
66+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.name) : QString::null;
67+}
68+
69+QString Result::comment() const
70+{
71+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.comment) : QString::null;
72+}
73+
74+QString Result::dndUri() const
75+{
76+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.dnd_uri) : QString::null;
77+}
78+
79+QVariant Result::metadata() const
80+{
81+ return m_preview != nullptr ? convertToQVariantHash(m_preview->preview_result.hints) : QVariant();
82+}
plugins/Unity/result.hnew file+69
@@ -0,0 +1,69 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+#ifndef RESULT_H
21+#define RESULT_H
22+
23+// Qt
24+#include <QObject>
25+#include <QVariant>
26+
27+// libunity-core
28+#include <UnityCore/Preview.h>
29+
30+class Q_DECL_EXPORT Result : public QObject
31+{
32+ Q_OBJECT
33+
34+ Q_PROPERTY(QString uri READ uri CONSTANT)
35+ Q_PROPERTY(QString iconHint READ iconHint CONSTANT)
36+ Q_PROPERTY(unsigned categoryIndex READ categoryIndex CONSTANT)
37+ Q_PROPERTY(unsigned resultType READ resultType CONSTANT)
38+ Q_PROPERTY(QString mimeType READ mimeType CONSTANT)
39+ Q_PROPERTY(QString title READ title CONSTANT)
40+ Q_PROPERTY(QString comment READ comment CONSTANT)
41+ Q_PROPERTY(QString dndUri READ dndUri CONSTANT)
42+ Q_PROPERTY(QVariant metadata READ metadata CONSTANT)
43+
44+public:
45+ Result(QObject *parent = nullptr);
46+ Result(unity::dash::Preview::Ptr preview, QObject *parent = nullptr);
47+
48+ void setPreview(unity::dash::Preview::Ptr preview);
49+
50+ QString uri() const;
51+ QString iconHint() const;
52+ unsigned categoryIndex() const;
53+ unsigned resultType() const;
54+ QString mimeType() const;
55+ QString title() const;
56+ QString comment() const;
57+ QString dndUri() const;
58+ QVariant metadata() const;
59+
60+private:
61+ /* Keep reference to the original preview to access result attributes via it, rather than keeping copies of them;
62+ this will save us a bit on copying, especially as UI is mostly interested in just uri.
63+ */
64+ unity::dash::Preview::Ptr m_preview;
65+};
66+
67+Q_DECLARE_METATYPE(Result *)
68+
69+#endif
plugins/Unity/scope.cpp+8−1
@@ -175,14 +175,21 @@ void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVaria
175 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
175 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
176{
176{
177 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);
178+ m_previewCancellable.Renew();
179+
178 // canned queries don't have previews, must be activated
180 // canned queries don't have previews, must be activated
179 if (uri.toString().startsWith("x-unity-no-preview-scopes-query://")) {
181 if (uri.toString().startsWith("x-unity-no-preview-scopes-query://")) {
180 m_unityScope->Activate(res);
182 m_unityScope->Activate(res);
181 } else {
183 } else {
182− m_unityScope->Preview(res);
184+ m_unityScope->Preview(res, nullptr, m_previewCancellable);
183 }
185 }
184}
186}
185
187
188+void Scope::cancelActivation()
189+{
190+ m_previewCancellable.Cancel();
191+}
192+
186void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
193void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
187{
194{
188 // note: we will not get called on SHOW_PREVIEW, instead UnityCore will signal preview_ready.
195 // note: we will not get called on SHOW_PREVIEW, instead UnityCore will signal preview_ready.
plugins/Unity/scope.h+3
@@ -82,6 +82,8 @@ public:
82 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,
83 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
83 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
84 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+
85 void setUnityScope(const unity::dash::Scope::Ptr& scope);
87 void setUnityScope(const unity::dash::Scope::Ptr& scope);
86 unity::dash::Scope::Ptr unityScope() const;
88 unity::dash::Scope::Ptr unityScope() const;
87
89
@@ -131,6 +133,7 @@ private:
131 QString m_searchQuery;
133 QString m_searchQuery;
132 QString m_noResultsHint;
134 QString m_noResultsHint;
133 QString m_formFactor;
135 QString m_formFactor;
136+ unity::glib::Cancellable m_previewCancellable;
134};
137};
135
138
136Q_DECLARE_METATYPE(Scope*)
139Q_DECLARE_METATYPE(Scope*)
plugins/Unity/variantutils.cpp+9
@@ -40,3 +40,12 @@ unity::glib::HintsMap convertToHintsMap(const QVariant &var)
40 }
40 }
41 return unity::glib::HintsMap();
41 return unity::glib::HintsMap();
42}
42}
43+
44+QVariantHash convertToQVariantHash(const unity::glib::HintsMap& var)
45+{
46+ QVariantHash hash;
47+ for (auto hint: var) {
48+ hash.insert(QString::fromStdString(hint.first), DeeListModel::VariantForData(hint.second));
49+ }
50+ return hash;
51+}
plugins/Unity/variantutils.h+1
@@ -28,5 +28,6 @@
28
28
29unity::glib::HintsMap convertToHintsMap(const QHash<QString, QVariant> &val);
29unity::glib::HintsMap convertToHintsMap(const QHash<QString, QVariant> &val);
30unity::glib::HintsMap convertToHintsMap(const QVariant &var);
30unity::glib::HintsMap convertToHintsMap(const QVariant &var);
31+QVariantHash convertToQVariantHash(const unity::glib::HintsMap& var);
31
32
32#endif
33#endif
tests/plugins/Unity/previewbindingstest.cpp+27
@@ -19,6 +19,7 @@
19
19
20#include <UnityCore/Preview.h>
20#include <UnityCore/Preview.h>
21#include <UnityCore/GLibWrapper.h>
21#include <UnityCore/GLibWrapper.h>
22+#include <UnityCore/Variant.h>
22#include <unity-protocol.h>
23#include <unity-protocol.h>
23
24
24#include "genericpreview.h"
25#include "genericpreview.h"
@@ -48,7 +49,23 @@ void PreviewBindingsTest::testGenericPreview()
48 UNITY_PROTOCOL_LAYOUT_HINT_LEFT);
49 UNITY_PROTOCOL_LAYOUT_HINT_LEFT);
49 unity::glib::Object<GObject> genPrv(rawPreview);
50 unity::glib::Object<GObject> genPrv(rawPreview);
50
51
52+ // create local result
53+ unity::glib::HintsMap hints;
54+ hints["a"] = unity::glib::Variant(g_variant_new_string("b"));
55+ unity::dash::LocalResult localResult;
56+ localResult.uri = "http://foo";
57+ localResult.icon_hint = "xyz";
58+ localResult.category_index = 1;
59+ localResult.result_type = 2;
60+ localResult.mimetype = "abc";
61+ localResult.name = "baz";
62+ localResult.comment = "qwerty";
63+ localResult.dnd_uri = "zzz";
64+ localResult.hints = hints;
65+
51 auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
66 auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
67+ corePrv->preview_result = localResult;
68+
52 auto prv = Preview::newFromUnityPreview(corePrv);
69 auto prv = Preview::newFromUnityPreview(corePrv);
53
70
54 QCOMPARE(prv != nullptr, true);
71 QCOMPARE(prv != nullptr, true);
@@ -64,6 +81,16 @@ void PreviewBindingsTest::testGenericPreview()
64 QCOMPARE(act->displayName(), QString("Action1"));
81 QCOMPARE(act->displayName(), QString("Action1"));
65 QCOMPARE(act->iconHint(), QString("/foo.png"));
82 QCOMPARE(act->iconHint(), QString("/foo.png"));
66
83
84+ Result* res = prv->result().value<Result*>();
85+ QCOMPARE(res->uri(), QString("http://foo"));
86+ QCOMPARE(res->iconHint(), QString("xyz"));
87+ QCOMPARE(res->categoryIndex(), 1u);
88+ QCOMPARE(res->resultType(), 2u);
89+ QCOMPARE(res->mimeType(), QString("abc"));
90+ QCOMPARE(res->title(), QString("baz"));
91+ QCOMPARE(res->dndUri(), QString("zzz"));
92+ QCOMPARE(res->metadata().toHash()["a"].toString(), QString("b"));
93+
67 g_object_unref(icon);
94 g_object_unref(icon);
68 g_object_unref(iconFile);
95 g_object_unref(iconFile);
69}
96}