on xenial help sign in
Let the scopes/scopes-plugin-shell take care of activates that are previews Fixes: #1428063

Approved by: Andrea Cimitan, Pawel Stolowski

commit12953f8ac4e640cba3cf22773d4fd937dd6e4113 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 11 Aug 2015, 14:45 (11 years ago) parent89ada3353f4e23
10 files changed+65−32
debian/changelog+6 debian/control+1−1 qml/Dash/GenericScopeView.qml+45−21 qml/Dash/PreviewListView.qml+2−1 qml/Dash/ScopesList.qml+1−1 tests/mocks/Unity/CMakeLists.txt+1−1 tests/mocks/Unity/fake_scope.cpp+5−3 tests/mocks/Unity/fake_scope.h+2−2 tests/mocks/Unity/fake_scopesoverview.cpp+1−1 tests/mocks/Unity/fake_scopesoverview.h+1−1
debian/changelog+6
@@ -1,3 +1,9 @@
1+unity8 (8.11-0ubuntu1) UNRELEASED; urgency=medium
2+
3+ * Increase version because of new scopes shell communication protocol
4+
5+ -- Albert Astals Cid <albert.astals@canonical.com> Tue, 04 Aug 2015 17:16:32 +0200
6+
17unity8 (8.10+15.10.20150804-0ubuntu1) wily; urgency=medium
28
39 [ Kevin Gunn ]
debian/control+1−1
@@ -128,7 +128,7 @@ Depends: qml-module-qtquick-layouts,
128128 unity-application-impl-6,
129129 unity-notifications-impl-3,
130130 unity-plugin-scopes | unity-scopes-impl,
131− unity-scopes-impl-6,
131+ unity-scopes-impl-7,
132132 unity8-fake-env | unity-application-impl,
133133 ${misc:Depends},
134134Breaks: unity8 (<< 7.86),
qml/Dash/GenericScopeView.qml+45−21
@@ -72,28 +72,39 @@ FocusScope {
7272 pageHeaderLoader.item.resetSearch()
7373 }
7474
75− function itemClicked(index, result, item, itemModel, resultsModel, limitedCategoryItemCount, categoryId) {
76− if (itemModel.uri.indexOf("scope://") === 0 || scope.id === "clickscope" || (scope.id === "videoaggregator" && categoryId === "myvideos-getstarted")) {
77− // TODO Technically it is possible that calling activate() will make the scope emit
78− // previewRequested so that we show a preview but there's no scope that does that yet
79− // so it's not implemented
80− scope.activate(result)
81− } else {
82− if (scope.preview(result)) {
83− openPreview(index, resultsModel, limitedCategoryItemCount);
84− }
85− }
75+ property var maybePreviewResult;
76+ property int maybePreviewIndex;
77+ property var maybePreviewResultsModel;
78+ property int maybePreviewLimitedCategoryItemCount;
79+ property string maybePreviewCategoryId;
80+
81+ function clearMaybePreviewData() {
82+ scopeView.maybePreviewResult = undefined;
83+ scopeView.maybePreviewIndex = -1;
84+ scopeView.maybePreviewResultsModel = undefined;
85+ scopeView.maybePreviewLimitedCategoryItemCount = -1;
86+ scopeView.maybePreviewCategoryId = "";
8687 }
8788
88− function itemPressedAndHeld(index, result, itemModel, resultsModel, limitedCategoryItemCount, categoryId) {
89− if (itemModel.uri.indexOf("scope://") !== 0 && !(scope.id === "videoaggregator" && categoryId === "myvideos-getstarted")) {
90− if (scope.preview(result)) {
91− openPreview(index, resultsModel, limitedCategoryItemCount);
92− }
89+ function itemClicked(index, result, itemModel, resultsModel, limitedCategoryItemCount, categoryId) {
90+ scopeView.maybePreviewResult = result;
91+ scopeView.maybePreviewIndex = index;
92+ scopeView.maybePreviewResultsModel = resultsModel;
93+ scopeView.maybePreviewLimitedCategoryItemCount = limitedCategoryItemCount;
94+ scopeView.maybePreviewCategoryId = categoryId;
95+
96+ scope.activate(result, categoryId);
97+ }
98+
99+ function itemPressedAndHeld(index, result, resultsModel, limitedCategoryItemCount, categoryId) {
100+ clearMaybePreviewData();
101+
102+ if (scope.preview(result, categoryId)) {
103+ openPreview(index, resultsModel, limitedCategoryItemCount, categoryId);
93104 }
94105 }
95106
96− function openPreview(index, resultsModel, limitedCategoryItemCount) {
107+ function openPreview(index, resultsModel, limitedCategoryItemCount, categoryId) {
97108 if (limitedCategoryItemCount > 0) {
98109 previewLimitModel.model = resultsModel;
99110 previewLimitModel.limit = limitedCategoryItemCount;
@@ -103,6 +114,7 @@ FocusScope {
103114 }
104115 subPageLoader.initialIndex = -1;
105116 subPageLoader.initialIndex = index;
117+ subPageLoader.categoryId = categoryId;
106118 subPageLoader.openSubPage("preview");
107119 }
108120
@@ -149,6 +161,16 @@ FocusScope {
149161 target: scopeView.scope
150162 onShowDash: subPageLoader.closeSubPage()
151163 onHideDash: subPageLoader.closeSubPage()
164+ onPreviewRequested: { // (QVariant const& result)
165+ if (result === scopeView.maybePreviewResult) {
166+ openPreview(scopeView.maybePreviewIndex,
167+ scopeView.maybePreviewResultsModel,
168+ scopeView.maybePreviewLimitedCategoryItemCount,
169+ scopeView.maybePreviewCategoryId);
170+
171+ clearMaybePreviewData();
172+ }
173+ }
152174 }
153175
154176 Connections {
@@ -357,12 +379,12 @@ FocusScope {
357379
358380 Connections {
359381 target: rendererLoader.item
360− onClicked: {
361− scopeView.itemClicked(index, result, item, itemModel, target.model, categoryItemCount(), baseItem.category);
382+ onClicked: { // (int index, var result, var item, var itemModel)
383+ scopeView.itemClicked(index, result, itemModel, target.model, categoryItemCount(), baseItem.category);
362384 }
363385
364− onPressAndHold: {
365− scopeView.itemPressedAndHeld(index, result, itemModel, target.model, categoryItemCount(), baseItem.category);
386+ onPressAndHold: { // (int index, var result, var itemModel)
387+ scopeView.itemPressedAndHeld(index, result, target.model, categoryItemCount(), baseItem.category);
366388 }
367389
368390 function categoryItemCount() {
@@ -736,6 +758,7 @@ FocusScope {
736758 property var scope: scopeView.scope
737759 property var scopeStyle: scopeView.scopeStyle
738760 property int initialIndex: -1
761+ property string categoryId
739762 property var model: null
740763
741764 readonly property bool processing: item && item.processing || false
@@ -767,6 +790,7 @@ FocusScope {
767790 item.open = Qt.binding(function() { return subPageLoader.open; } )
768791 item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex; } )
769792 item.model = Qt.binding(function() { return subPageLoader.model; } )
793+ item.categoryId = Qt.binding(function() { return subPageLoader.categoryId; } )
770794 }
771795 open = true;
772796 }
qml/Dash/PreviewListView.qml+2−1
@@ -26,6 +26,7 @@ Item {
2626 property int initialIndex: -1
2727 property var scope: null
2828 property var scopeStyle: null
29+ property string categoryId
2930
3031 property alias showSignatureLine: header.showSignatureLine
3132
@@ -99,7 +100,7 @@ Item {
99100 isCurrent: ListView.isCurrentItem
100101
101102 previewModel: {
102− var previewStack = root.scope.preview(result);
103+ var previewStack = root.scope.preview(result, root.categoryId);
103104 return previewStack.getPreviewModel(0);
104105 }
105106 scopeStyle: root.scopeStyle
qml/Dash/ScopesList.qml+1−1
@@ -124,7 +124,7 @@ Item {
124124 onRequestFavorite: root.requestFavorite(scopeId, favorite);
125125 onRequestEditMode: root.state = "edit";
126126 onRequestScopeMoveTo: root.requestFavoriteMoveTo(scopeId, index);
127− onRequestActivate: root.scope.activate(result);
127+ onRequestActivate: root.scope.activate(result, categoryId);
128128 onRequestRestore: root.requestRestore(scopeId);
129129 }
130130 }
tests/mocks/Unity/CMakeLists.txt+1−1
@@ -7,7 +7,7 @@ add_subdirectory(Notifications)
77add_subdirectory(DashCommunicator)
88
99pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
10−pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=6)
10+pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=7)
1111
1212include_directories(
1313 ${CMAKE_CURRENT_BINARY_DIR}
tests/mocks/Unity/fake_scope.cpp+5−3
@@ -181,18 +181,20 @@ void Scope::setNoResultsHint(const QString& str)
181181 }
182182}
183183
184−void Scope::activate(QVariant const& result)
184+void Scope::activate(QVariant const& result, QString const& categoryId)
185185{
186− qDebug() << "Called activate on scope" << m_id << "with result" << result;
186+ qDebug() << "Called activate on scope" << m_id << "with result" << result << "and category" << categoryId;
187187 if (result.toString() == "Result.2.2") {
188188 Scopes *scopes = dynamic_cast<Scopes*>(parent());
189189 m_openScope = scopes->getScopeFromAll("MockScope9");
190190 scopes->addTempScope(m_openScope);
191191 Q_EMIT openScope(m_openScope);
192+ } else {
193+ Q_EMIT previewRequested(result);
192194 }
193195}
194196
195−PreviewStack* Scope::preview(QVariant const& result)
197+PreviewStack* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
196198{
197199 Q_UNUSED(result);
198200
tests/mocks/Unity/fake_scope.h+2−2
@@ -60,8 +60,8 @@ public:
6060 Q_INVOKABLE void setName(const QString &name); // This is not invokable in the Interface, here for testing benefits
6161 Q_INVOKABLE void setSearchInProgress(const bool inProg); // This is not invokable in the Interface, here for testing benefits
6262
63− Q_INVOKABLE void activate(QVariant const& result) override;
64− Q_INVOKABLE PreviewStack* preview(QVariant const& result) override;
63+ Q_INVOKABLE void activate(QVariant const& result, QString const& categoryId) override;
64+ Q_INVOKABLE PreviewStack* preview(QVariant const& result, QString const& categoryId) override;
6565 Q_INVOKABLE void cancelActivation() override;
6666 Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override;
6767
tests/mocks/Unity/fake_scopesoverview.cpp+1−1
@@ -41,7 +41,7 @@ void ScopesOverview::setSearchQuery(const QString& search_query)
4141 Q_EMIT categoriesChanged();
4242}
4343
44−Q_INVOKABLE void ScopesOverview::activate(QVariant const& result)
44+Q_INVOKABLE void ScopesOverview::activate(QVariant const& result, QString const& /*categoryId*/)
4545{
4646 Scopes *scopes = dynamic_cast<Scopes*>(parent());
4747 if (scopes->getScope(result.toString())) {
tests/mocks/Unity/fake_scopesoverview.h+1−1
@@ -32,7 +32,7 @@ public:
3232 ScopesOverview(Scopes* parent = 0);
3333
3434 void setSearchQuery(const QString& search_query) override;
35− Q_INVOKABLE void activate(QVariant const& result) override;
35+ Q_INVOKABLE void activate(QVariant const& result, QString const& categoryId) override;
3636
3737 // This is implementation detail
3838 void setFavorite(Scope *scope, bool favorite);