on xenial help sign in
fix issue with removing running app and storing pinned apps in config
commit51b408ef3a2a42cb19c4c408bae90be7204376af authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 16 Sep 2013, 19:53 (13 years ago) parentd1296e3
2 files changed+78−5
plugins/Unity/Launcher/launchermodel.cpp+12−3 tests/plugins/Unity/Launcher/launchermodeltest.cpp+66−2
plugins/Unity/Launcher/launchermodel.cpp+12−3
@@ -115,9 +115,11 @@ void LauncherModel::move(int oldIndex, int newIndex)
115115 m_list.move(oldIndex, newIndex);
116116 endMoveRows();
117117
118− storeAppList();
119−
120− pin(m_list.at(newIndex)->appId());
118+ if (!m_list.at(newIndex)->pinned()) {
119+ pin(m_list.at(newIndex)->appId());
120+ } else {
121+ storeAppList();
122+ }
121123}
122124
123125void LauncherModel::pin(const QString &appId, int index)
@@ -146,6 +148,8 @@ void LauncherModel::pin(const QString &appId, int index)
146148 m_list.insert(index, item);
147149 endInsertRows();
148150 }
151+
152+ storeAppList();
149153}
150154
151155void LauncherModel::requestRemove(const QString &appId)
@@ -155,6 +159,11 @@ void LauncherModel::requestRemove(const QString &appId)
155159 return;
156160 }
157161
162+ if (m_appManager->findApplication(appId)) {
163+ m_list.at(index)->setPinned(false);
164+ return;
165+ }
166+
158167 beginRemoveRows(QModelIndex(), index, index);
159168 m_list.takeAt(index)->deleteLater();
160169 endRemoveRows();
tests/plugins/Unity/Launcher/launchermodeltest.cpp+66−2
@@ -62,7 +62,14 @@ public:
6262 return QString();
6363 }
6464 unity::shell::application::ApplicationInfoInterface *get(int index) const { return m_list.at(index); }
65− unity::shell::application::ApplicationInfoInterface *findApplication(const QString &) const { return nullptr; }
65+ unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const {
66+ Q_FOREACH(MockApp* app, m_list) {
67+ if (app->appId() == appId) {
68+ return app;
69+ }
70+ }
71+ return nullptr;
72+ }
6673 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) { return nullptr; }
6774 bool stopApplication(const QString &) { return false; }
6875 bool focusApplication(const QString &appId) {
@@ -151,9 +158,59 @@ private Q_SLOTS:
151158 QCOMPARE(launcherModel->get(1)->pinned(), false);
152159 }
153160
161+ void testRemove_data() {
162+
163+ QTest::addColumn<bool>("pinned");
164+ QTest::addColumn<bool>("running");
165+
166+ // Needs to kepp the item as long as running and needs to remove it when app is closed
167+ QTest::newRow("non-pinned, running") << false << true;
168+
169+ // Needs to kepp the item as long as running and needs to remove it when app is closed
170+ QTest::newRow("pinned, running") << true << false;
171+
172+ // Needs to kepp the item as long as running and needs to remove it when app is closed
173+ QTest::newRow("pinned, non-running") << true << false;
174+ }
175+
154176 void testRemove() {
177+ QFETCH(bool, pinned);
178+ QFETCH(bool, running);
179+
180+ // In the beginning we always have to items
155181 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
156− launcherModel->requestRemove(launcherModel->get(0)->appId());
182+
183+ // pin one if required
184+ if (pinned) {
185+ launcherModel->pin(launcherModel->get(1)->appId());
186+ }
187+
188+ // stop it if required
189+ if (!running) {
190+ appManager->removeApplication(1);
191+ }
192+
193+ // Now remove one
194+ launcherModel->requestRemove(launcherModel->get(1)->appId());
195+
196+ if (running) {
197+ // bot apps are running, both apps must still be here
198+ QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
199+
200+ // Item must be unpinned now
201+ QCOMPARE(launcherModel->get(1)->pinned(), false);
202+
203+ } else if (pinned) {
204+ // Item 1 must go away, item 0 is here to stay
205+ QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
206+ }
207+
208+ // done our checks. now stop the app if was still running
209+ if (running) {
210+ appManager->removeApplication(1);
211+ }
212+
213+ // It needs to go away in any case now
157214 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
158215 }
159216
@@ -181,6 +238,13 @@ private Q_SLOTS:
181238
182239 // quicklist needs to transform to remove item. trigger it and check it item goes away
183240 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
241+ QCOMPARE(launcherModel->get(0)->pinned(), false);
242+
243+ // still needs to be here as the app is still here
244+ QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
245+ // close the app
246+ appManager->removeApplication(0);
247+ // Now it needs to go away
184248 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
185249 }
186250