on xenial help sign in
merge prereq
commitfab32a54f3c7704998e4497ab596393b50d450de authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 21 Oct 2014, 19:57 (12 years ago) parentba42b4f3a3879f
5 files changed+27−21
plugins/Unity/Launcher/launchermodel.cpp+20−17 plugins/Unity/Launcher/launchermodel.h+2 tests/plugins/Unity/Launcher/gsettings.cpp+2−1 tests/plugins/Unity/Launcher/gsettings.h+1−1 tests/plugins/Unity/Launcher/launchermodeltest.cpp+2−2
plugins/Unity/Launcher/launchermodel.cpp+20−17
@@ -162,22 +162,7 @@ void LauncherModel::pin(const QString &appId, int index)
162162
163163void LauncherModel::requestRemove(const QString &appId)
164164{
165− int index = findApplication(appId);
166− if (index < 0) {
167− return;
168− }
169−
170− if (m_appManager->findApplication(appId)) {
171− m_list.at(index)->setPinned(false);
172− QModelIndex modelIndex = this->index(index);
173− Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
174− return;
175− }
176−
177− beginRemoveRows(QModelIndex(), index, index);
178− m_list.takeAt(index)->deleteLater();
179− endRemoveRows();
180−
165+ unpin(appId);
181166 storeAppList();
182167}
183168
@@ -288,6 +273,24 @@ void LauncherModel::storeAppList()
288273 m_settings->setStoredApplications(appIds);
289274}
290275
276+void LauncherModel::unpin(const QString &appId)
277+{
278+ int index = findApplication(appId);
279+ if (index < 0) {
280+ return;
281+ }
282+
283+ if (m_appManager->findApplication(appId)) {
284+ m_list.at(index)->setPinned(false);
285+ QModelIndex modelIndex = this->index(index);
286+ Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
287+ } else {
288+ beginRemoveRows(QModelIndex(), index, index);
289+ m_list.takeAt(index)->deleteLater();
290+ endRemoveRows();
291+ }
292+}
293+
291294int LauncherModel::findApplication(const QString &appId)
292295{
293296 for (int i = 0; i < m_list.count(); ++i) {
@@ -370,7 +373,7 @@ void LauncherModel::refresh()
370373 }
371374
372375 Q_FOREACH (LauncherItem* item, toBeRemoved) {
373− requestRemove(item->appId());
376+ unpin(item->appId());
374377 }
375378
376379 bool changed = toBeRemoved.count() > 0;
plugins/Unity/Launcher/launchermodel.h+2
@@ -62,6 +62,8 @@ public Q_SLOTS:
6262private:
6363 void storeAppList();
6464
65+ void unpin(const QString &appId);
66+
6567private Q_SLOTS:
6668 void countChanged(const QString &appId, int count);
6769 void countVisibleChanged(const QString &appId, int count);
tests/plugins/Unity/Launcher/gsettings.cpp+2−1
@@ -37,8 +37,9 @@ void GSettings::setStoredApplications(const QStringList &storedApplications)
3737 m_entries = storedApplications;
3838}
3939
40−void GSettings::simulateDconfChange(const QStringList &storedApplications)
40+void GSettings::simulateDConfChanged(const QStringList &storedApplications)
4141{
4242 m_entries = storedApplications;
43+ setStoredApplications(storedApplications);
4344 Q_EMIT changed();
4445}
tests/plugins/Unity/Launcher/gsettings.h+1−1
@@ -35,7 +35,7 @@ public:
3535 void setStoredApplications(const QStringList &storedApplications);
3636
3737 // Only for testing
38− void simulateDconfChange(const QStringList &storedApplications);
38+ void simulateDConfChanged(const QStringList &storedApplications);
3939
4040Q_SIGNALS:
4141 void changed();
tests/plugins/Unity/Launcher/launchermodeltest.cpp+2−2
@@ -451,7 +451,7 @@ private Q_SLOTS:
451451 QCOMPARE(settings->storedApplications().count(), 2);
452452
453453 // Now remove 1 app through the backend, make sure one is still there
454− settings->simulateDconfChange(QStringList() << "abs-icon");
454+ settings->simulateDConfChanged(QStringList() << "abs-icon");
455455 QCOMPARE(settings->storedApplications().count(), 1);
456456 QCOMPARE(spy.count(), 1);
457457
@@ -459,7 +459,7 @@ private Q_SLOTS:
459459 QCOMPARE(launcherModel->rowCount(), 1);
460460
461461 // Add them back but in reverse order
462− settings->simulateDconfChange(QStringList() << "no-icon" << "abs-icon");
462+ settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
463463 QCOMPARE(launcherModel->rowCount(), 2);
464464 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
465465 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));