on xenial help sign in
fix an issue with removing a running app from the launcher and always store pinning to the config.
acc304fMichael Zanetti
plugins/Unity/Launcher/launchermodel.cpp+12−3
@@ -115,9 +115,11 @@ void LauncherModel::move(int oldIndex, int newIndex)
115 m_list.move(oldIndex, newIndex);
115 m_list.move(oldIndex, newIndex);
116 endMoveRows();
116 endMoveRows();
117
117
118− storeAppList();
118+ if (!m_list.at(newIndex)->pinned()) {
119−
120− pin(m_list.at(newIndex)->appId());
119+ pin(m_list.at(newIndex)->appId());
120+ } else {
121+ storeAppList();
122+ }
121}
123}
122
124
123void LauncherModel::pin(const QString &appId, int index)
125void LauncherModel::pin(const QString &appId, int index)
@@ -146,6 +148,8 @@ void LauncherModel::pin(const QString &appId, int index)
146 m_list.insert(index, item);
148 m_list.insert(index, item);
147 endInsertRows();
149 endInsertRows();
148 }
150 }
151+
152+ storeAppList();
149}
153}
150
154
151void LauncherModel::requestRemove(const QString &appId)
155void LauncherModel::requestRemove(const QString &appId)
@@ -155,6 +159,11 @@ void LauncherModel::requestRemove(const QString &appId)
155 return;
159 return;
156 }
160 }
157
161
162+ if (m_appManager->findApplication(appId)) {
163+ m_list.at(index)->setPinned(false);
164+ return;
165+ }
166+
158 beginRemoveRows(QModelIndex(), index, index);
167 beginRemoveRows(QModelIndex(), index, index);
159 m_list.takeAt(index)->deleteLater();
168 m_list.takeAt(index)->deleteLater();
160 endRemoveRows();
169 endRemoveRows();
tests/plugins/Unity/Launcher/launchermodeltest.cpp+61−2
@@ -62,7 +62,14 @@ public:
62 return QString();
62 return QString();
63 }
63 }
64 unity::shell::application::ApplicationInfoInterface *get(int index) const { return m_list.at(index); }
64 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+ }
66 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) { return nullptr; }
73 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) { return nullptr; }
67 bool stopApplication(const QString &) { return false; }
74 bool stopApplication(const QString &) { return false; }
68 bool focusApplication(const QString &appId) {
75 bool focusApplication(const QString &appId) {
@@ -151,9 +158,54 @@ private Q_SLOTS:
151 QCOMPARE(launcherModel->get(1)->pinned(), false);
158 QCOMPARE(launcherModel->get(1)->pinned(), false);
152 }
159 }
153
160
161+ void testRemove_data() {
162+
163+ QTest::addColumn<bool>("pinned");
164+ QTest::addColumn<bool>("running");
165+
166+ QTest::newRow("non-pinned, running") << false << true;
167+ QTest::newRow("pinned, running") << true << false;
168+ QTest::newRow("pinned, non-running") << true << false;
169+ }
170+
154 void testRemove() {
171 void testRemove() {
172+ QFETCH(bool, pinned);
173+ QFETCH(bool, running);
174+
175+ // In the beginning we always have two items
155 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
176 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
177+
178+ // pin one if required
179+ if (pinned) {
180+ launcherModel->pin(launcherModel->get(1)->appId());
181+ }
182+
183+ // stop it if required
184+ if (!running) {
185+ appManager->removeApplication(1);
186+ }
187+
188+ // Now remove it
156− launcherModel->requestRemove(launcherModel->get(0)->appId());
189+ launcherModel->requestRemove(launcherModel->get(1)->appId());
190+
191+ if (running) {
192+ // both apps are running, both apps must still be here
193+ QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
194+
195+ // Item must be unpinned now
196+ QCOMPARE(launcherModel->get(1)->pinned(), false);
197+
198+ } else if (pinned) {
199+ // Item 1 must go away, item 0 is here to stay
200+ QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
201+ }
202+
203+ // done our checks. now stop the app if was still running
204+ if (running) {
205+ appManager->removeApplication(1);
206+ }
207+
208+ // It needs to go away in any case now
157 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
209 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
158 }
210 }
159
211
@@ -181,6 +233,13 @@ private Q_SLOTS:
181
233
182 // quicklist needs to transform to remove item. trigger it and check it item goes away
234 // quicklist needs to transform to remove item. trigger it and check it item goes away
183 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
235 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
236+ QCOMPARE(launcherModel->get(0)->pinned(), false);
237+
238+ // still needs to be here as the app is still here
239+ QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
240+ // close the app
241+ appManager->removeApplication(0);
242+ // Now it needs to go away
184 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
243 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
185 }
244 }
186
245