on xenial help sign in
Fix temp scopes opening temp scopes, correctly close previously opened temp scope with its preview Fixes: #1410337

Approved by: Albert Astals Cid

commitfb8bb42c8b3dc0e6e11bad6f9ea6bbc87ebfbe99 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateMon 16 Feb 2015, 13:13 (12 years ago) parentb85001f3ce1480
14 files changed+130−23
debian/control+2−2 qml/Dash/Dash.qml+6−8 qml/Dash/DashContent.qml+1−2 tests/mocks/Unity/CMakeLists.txt+1−1 tests/mocks/Unity/fake_previewmodel.cpp+15−1 tests/mocks/Unity/fake_previewmodel.h+7−1 tests/mocks/Unity/fake_previewstack.cpp+2−2 tests/mocks/Unity/fake_previewstack.h+3−1 tests/mocks/Unity/fake_previewwidgetmodel.cpp+1 tests/mocks/Unity/fake_scope.cpp+5−5 tests/mocks/Unity/fake_scopes.cpp+12 tests/mocks/Unity/fake_scopes.h+5 tests/mocks/Unity/fake_scopesoverview.cpp+1 tests/qmltests/Dash/tst_Dash.qml+69
debian/control+2−2
@@ -27,7 +27,7 @@ Build-Depends: cmake,
2727 libqmenumodel-dev (>= 0.2.9),
2828 libqt5xmlpatterns5-dev,
2929 libsystemsettings-dev,
30− libunity-api-dev (>= 7.95),
30+ libunity-api-dev (>= 7.96),
3131 libusermetricsoutput1-dev,
3232 libxcb1-dev,
3333 pkg-config,
@@ -126,7 +126,7 @@ Depends: qml-module-qtquick-layouts,
126126 unity-application-impl-4,
127127 unity-notifications-impl-3,
128128 unity-plugin-scopes | unity-scopes-impl,
129− unity-scopes-impl-4,
129+ unity-scopes-impl-6,
130130 unity8-fake-env | unity-application-impl,
131131 ${misc:Depends},
132132Breaks: unity8 (<< 7.86),
qml/Dash/Dash.qml+6−8
@@ -122,7 +122,6 @@ Showable {
122122 dash.setCurrentScope(scopeId, true, false);
123123 }
124124 onOpenScope: {
125− scopeItem.scopeThatOpenedScope = currentScope;
126125 scopeItem.scope = scope;
127126 x = -width;
128127 }
@@ -130,7 +129,7 @@ Showable {
130129 UbuntuNumberAnimation {
131130 onRunningChanged: {
132131 if (!running && dashContent.x == 0) {
133− scopeItem.scopeThatOpenedScope.closeScope(scopeItem.scope);
132+ scopes.closeScope(scopeItem.scope);
134133 scopeItem.scope = null;
135134 }
136135 }
@@ -187,7 +186,6 @@ Showable {
187186 onOpenScope: {
188187 bottomEdgeController.enableAnimation = true;
189188 bottomEdgeController.progress = 0;
190− scopeItem.scopeThatOpenedScope = scopesList.scope;
191189 scopeItem.scope = scope;
192190 dashContent.x = -dashContent.width;
193191 }
@@ -199,8 +197,7 @@ Showable {
199197 }
200198 }
201199
202− DashBackground
203− {
200+ DashBackground {
204201 anchors.fill: scopeItem
205202 visible: scopeItem.visible
206203 }
@@ -209,8 +206,6 @@ Showable {
209206 id: scopeItem
210207 objectName: "dashTempScopeItem"
211208
212− property var scopeThatOpenedScope: null
213−
214209 x: dashContent.x + width
215210 y: dashContent.y
216211 width: parent.width
@@ -229,7 +224,10 @@ Showable {
229224 dashContent.gotoScope(scopeId);
230225 }
231226 onOpenScope: {
232− dashContent.openScope(scope);
227+ scopeItem.closePreview();
228+ var oldScope = scopeItem.scope;
229+ scopeItem.scope = scope;
230+ scopes.closeScope(oldScope);
233231 }
234232 }
235233 }
qml/Dash/DashContent.qml+1−2
@@ -84,8 +84,7 @@ Item {
8484
8585 set_current_index = undefined;
8686
87− if (dashContentList.count > index)
88− {
87+ if (dashContentList.count > index) {
8988 dashContentList.currentIndex = index
9089
9190 if (reset) {
tests/mocks/Unity/CMakeLists.txt+1−1
@@ -6,7 +6,7 @@ add_subdirectory(Notifications)
66add_subdirectory(DashCommunicator)
77
88pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
9−pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=5)
9+pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=6)
1010
1111include_directories(
1212 ${CMAKE_CURRENT_BINARY_DIR}
tests/mocks/Unity/fake_previewmodel.cpp+15−1
@@ -22,18 +22,23 @@
2222#include "fake_previewmodel.h"
2323
2424// local
25+#include "fake_scope.h"
26+#include "fake_scopes.h"
2527#include "fake_previewwidgetmodel.h"
2628
2729// Qt
2830#include <QDebug>
2931
30−PreviewModel::PreviewModel(QObject* parent)
32+PreviewModel::PreviewModel(QObject* parent, Scope* scope)
3133 : unity::shell::scopes::PreviewModelInterface(parent)
3234 , m_loaded(true)
35+ , m_scope(scope)
3336{
3437 // we have one column by default
3538 PreviewWidgetModel* columnModel = new PreviewWidgetModel(this);
3639 m_previewWidgetModels.append(columnModel);
40+ connect(this, SIGNAL(triggered(QString const&, QString const&, QVariantMap const&)),
41+ this, SLOT(triggeredSlot(QString const&, QString const&, QVariantMap const&)));
3742}
3843
3944void PreviewModel::setWidgetColumnCount(int count)
@@ -80,3 +85,12 @@ void PreviewModel::setLoaded(bool loaded)
8085 Q_EMIT loadedChanged();
8186 }
8287}
88+
89+void PreviewModel::triggeredSlot(QString const&, QString const&, QVariantMap const&) {
90+ if (m_scope) {
91+ Scopes *scopes = dynamic_cast<Scopes*>(m_scope->parent());
92+ Scope* scope = scopes->getScopeFromAll("MockScope9");
93+ scopes->addTempScope(scope);
94+ Q_EMIT m_scope->openScope(scope);
95+ }
96+}
tests/mocks/Unity/fake_previewmodel.h+7−1
@@ -25,12 +25,14 @@
2525
2626class PreviewWidgetModel;
2727
28+class Scope;
29+
2830class PreviewModel : public unity::shell::scopes::PreviewModelInterface
2931{
3032 Q_OBJECT
3133
3234public:
33− explicit PreviewModel(QObject* parent = 0);
35+ explicit PreviewModel(QObject* parent = 0, Scope* scope = 0);
3436
3537 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
3638 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
@@ -42,9 +44,13 @@ public:
4244
4345 Q_INVOKABLE void setLoaded(bool); // Only available for testing
4446
47+private Q_SLOTS:
48+ void triggeredSlot(QString const&, QString const&, QVariantMap const&);
49+
4550private:
4651 QList<PreviewWidgetModel*> m_previewWidgetModels;
4752 bool m_loaded;
53+ Scope* m_scope;
4854};
4955
5056Q_DECLARE_METATYPE(PreviewModel*)
tests/mocks/Unity/fake_previewstack.cpp+2−2
@@ -21,10 +21,10 @@
2121#include "fake_previewmodel.h"
2222#include "fake_scope.h"
2323
24−PreviewStack::PreviewStack(QObject* parent)
24+PreviewStack::PreviewStack(QObject* parent, Scope *scope)
2525 : unity::shell::scopes::PreviewStackInterface(parent)
2626{
27− m_previews << new PreviewModel(this);
27+ m_previews << new PreviewModel(this, scope);
2828}
2929
3030PreviewStack::~PreviewStack()
tests/mocks/Unity/fake_previewstack.h+3−1
@@ -25,12 +25,14 @@
2525
2626class PreviewModel;
2727
28+class Scope;
29+
2830class PreviewStack : public unity::shell::scopes::PreviewStackInterface
2931{
3032 Q_OBJECT
3133
3234public:
33− explicit PreviewStack(QObject* parent = 0);
35+ explicit PreviewStack(QObject* parent = 0, Scope* scope = 0);
3436 virtual ~PreviewStack();
3537
3638 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
tests/mocks/Unity/fake_previewwidgetmodel.cpp+1
@@ -57,6 +57,7 @@ void PreviewWidgetModel::populateWidgets()
5757 QVariantMap attributes;
5858 QVariantMap buttonData;
5959 buttonData["label"] = "Button";
60+ buttonData["id"] = "open_click";
6061 QVariantList buttons;
6162 buttons << buttonData << buttonData << buttonData;
6263 attributes["actions"] = QVariant::fromValue(buttons);
tests/mocks/Unity/fake_scope.cpp+5−5
@@ -185,6 +185,7 @@ void Scope::activate(QVariant const& result)
185185 if (result.toString() == "Result.2.2") {
186186 Scopes *scopes = dynamic_cast<Scopes*>(parent());
187187 m_openScope = scopes->getScopeFromAll("MockScope9");
188+ scopes->addTempScope(m_openScope);
188189 Q_EMIT openScope(m_openScope);
189190 }
190191}
@@ -198,7 +199,7 @@ PreviewStack* Scope::preview(QVariant const& result)
198199 } else {
199200 // This probably leaks, do we don't care
200201 // it's a test after all
201− return new PreviewStack;
202+ return new PreviewStack(this, this);
202203 }
203204}
204205
@@ -208,11 +209,10 @@ void Scope::cancelActivation()
208209
209210void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
210211{
211− if (scope != m_openScope) {
212− qDebug() << scope << m_openScope;
213− qFatal("Scope::closeScope got wrong scope in closeScope");
212+ Scopes *scopes = dynamic_cast<Scopes*>(parent());
213+ if (scopes) {
214+ return scopes->closeScope(scope);
214215 }
215− m_openScope = nullptr;
216216}
217217
218218QString Scope::currentNavigationId() const
tests/mocks/Unity/fake_scopes.cpp+12
@@ -23,6 +23,7 @@
2323// TODO: Implement remaining pieces, like Categories (i.e. LensView now gives warnings)
2424
2525// Qt
26+#include <QDebug>
2627#include <QTimer>
2728
2829Scopes::Scopes(QObject *parent)
@@ -177,6 +178,17 @@ unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
177178 return m_scopesOverview;
178179}
179180
181+void Scopes::addTempScope(unity::shell::scopes::ScopeInterface* scope)
182+{
183+ m_tempScopes.insert(scope);
184+}
185+
186+void Scopes::closeScope(unity::shell::scopes::ScopeInterface* scope)
187+{
188+ Q_ASSERT(m_tempScopes.contains(scope));
189+ m_tempScopes.remove(scope);
190+}
191+
180192void Scopes::setFavorite(const QString& scopeId, bool favorite)
181193{
182194 if (favorite) {
tests/mocks/Unity/fake_scopes.h+5
@@ -26,6 +26,7 @@
2626
2727// Qt
2828#include <QList>
29+#include <QSet>
2930#include <QTimer>
3031
3132class ScopesOverview;
@@ -59,6 +60,9 @@ public:
5960 Q_INVOKABLE void setFavorite(const QString& scopeId, bool favorite) override;
6061 Q_INVOKABLE void moveFavoriteTo(const QString& scopeId, int index) override;
6162
63+ void addTempScope(unity::shell::scopes::ScopeInterface* scope);
64+ Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override;
65+
6266 // This is used as part of implementation of the other C++ code, not API
6367 QList<Scope*> favScopes() const;
6468 QList<Scope*> nonFavScopes() const;
@@ -70,6 +74,7 @@ private Q_SLOTS:
7074private:
7175 QList<Scope*> m_scopes; // the favorite ones
7276 QList<Scope*> m_allScopes;
77+ QSet<unity::shell::scopes::ScopeInterface*> m_tempScopes;
7378 ScopesOverview *m_scopesOverview;
7479 bool m_loaded;
7580 QTimer timer;
tests/mocks/Unity/fake_scopesoverview.cpp+1
@@ -48,6 +48,7 @@ Q_INVOKABLE void ScopesOverview::activate(QVariant const& result)
4848 Q_EMIT gotoScope(result.toString());
4949 } else {
5050 m_openScope = scopes->getScopeFromAll(result.toString());
51+ scopes->addTempScope(m_openScope);
5152 Q_EMIT openScope(m_openScope);
5253 }
5354}
tests/qmltests/Dash/tst_Dash.qml+69
@@ -428,5 +428,74 @@ Item {
428428 tryCompare(bottomEdgeController, "progress", 0);
429429 tryCompare(dashContentList, "currentIndex", 1)
430430 }
431+
432+ function test_close_temp_scope_preview_opening_scope() {
433+ // Show the manage dash
434+ touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
435+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
436+ tryCompare(bottomEdgeController, "progress", 1);
437+
438+ // Make sure stuff is loaded
439+ var nonfavScopesListCategory = findChild(dash, "scopesListCategoryother");
440+ var nonfavScopesListCategoryList = findChild(nonfavScopesListCategory, "scopesListCategoryInnerList");
441+ tryCompare(nonfavScopesListCategoryList, "currentIndex", 0);
442+
443+ // Click on a non favorite scope
444+ mouseClick(nonfavScopesListCategoryList.currentItem);
445+
446+ // Check the bottom edge (manage dash) is disabled from temp scope
447+ var overviewDragHandle = findChild(dash, "overviewDragHandle");
448+ compare(overviewDragHandle.enabled, false);
449+
450+ // Check temp scope is there
451+ var dashTempScopeItem = findChild(dash, "dashTempScopeItem");
452+ tryCompare(dashTempScopeItem, "x", 0);
453+ tryCompare(dashTempScopeItem, "visible", true);
454+
455+ // Check the manage dash is gone
456+ tryCompare(bottomEdgeController, "progress", 0);
457+
458+ // Open preview
459+ var categoryListView = findChild(dashTempScopeItem, "categoryListView");
460+ categoryListView.positionAtBeginning();
461+ tryCompareFunction(function() {
462+ var cardGrid = findChild(dashTempScopeItem, "dashCategory0");
463+ if (cardGrid != null) {
464+ var tile = findChild(cardGrid, "delegate0");
465+ return tile != null;
466+ }
467+ return false;
468+ },
469+ true);
470+ var tile = findChild(findChild(dashTempScopeItem, "dashCategory0"), "delegate0");
471+ waitForRendering(tile);
472+ mouseClick(tile);
473+ var subPageLoader = findChild(dashTempScopeItem, "subPageLoader");
474+ tryCompare(subPageLoader, "open", true);
475+ tryCompare(subPageLoader, "x", 0);
476+ tryCompare(findChild(dashTempScopeItem, "categoryListView"), "visible", false);
477+ var previewListRow0 = findChild(subPageLoader, "previewListRow0");
478+ touchFlick(previewListRow0, previewListRow0.width / 2, units.gu(20), previewListRow0.width / 2, units.gu(1));
479+ tryCompare(previewListRow0, "atYEnd", true);
480+ tryCompare(previewListRow0, "moving", false);
481+ var widget = findChild(subPageLoader, "widget-21");
482+ var initialWidgetHeight = widget.height;
483+ var openButton = findChild(widget, "buttonopen_click");
484+ mouseClick(openButton);
485+
486+ tryCompare(subPageLoader, "open", false);
487+ tryCompare(subPageLoader, "x", subPageLoader.width);
488+
489+ compare(dashTempScopeItem.scope.id, "MockScope9");
490+
491+ // Go back
492+ var dashTempScopeItemHeader = findChild(dashTempScopeItem, "scopePageHeader");
493+ var backButton = findChild(findChild(dashTempScopeItemHeader, "innerPageHeader"), "customBackButton");
494+ mouseClick(backButton);
495+
496+ // Check temp scope is gone
497+ tryCompare(dashTempScopeItem, "x", dash.width);
498+ tryCompare(dashTempScopeItem, "visible", false);
499+ }
431500 }
432501}