on xenial help sign in
don't call any methods that could overwrite dconf while we're loading it
commit423e8d4d679fbac152f098b108a1ee2e796a76e1 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 13 Oct 2014, 20:13 (12 years ago) parent3669634
4 files changed+22−3
plugins/Unity/Launcher/launchermodel.cpp+13−1 tests/plugins/Unity/Launcher/gsettings.cpp+5 tests/plugins/Unity/Launcher/gsettings.h+2 tests/plugins/Unity/Launcher/launchermodeltest.cpp+2−2
plugins/Unity/Launcher/launchermodel.cpp+13−1
@@ -171,6 +171,7 @@ void LauncherModel::requestRemove(const QString &appId)
171171 m_list.at(index)->setPinned(false);
172172 QModelIndex modelIndex = this->index(index);
173173 Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
174+ storeAppList();
174175 return;
175176 }
176177
@@ -350,6 +351,7 @@ void LauncherModel::countVisibleChanged(const QString &appId, int countVisible)
350351
351352void LauncherModel::refresh()
352353{
354+ qDebug() << "calling refresh";
353355 // First walk through all the existing items and see if we need to remove something
354356 QList<LauncherItem*> toBeRemoved;
355357 Q_FOREACH (LauncherItem* item, m_list) {
@@ -368,8 +370,18 @@ void LauncherModel::refresh()
368370 }
369371 }
370372
373+ // If running, just unpin, otherwise really remove
371374 Q_FOREACH (LauncherItem* item, toBeRemoved) {
372− requestRemove(item->appId());
375+ int index = m_list.indexOf(item);
376+ if (m_appManager->findApplication(item->appId())) {
377+ item->setPinned(false);
378+ QModelIndex modelIndex = this->index(index);
379+ Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
380+ } else {
381+ beginRemoveRows(QModelIndex(), index, index);
382+ m_list.takeAt(index)->deleteLater();
383+ endRemoveRows();
384+ }
373385 }
374386
375387 // This brings the Launcher into sync with the settings backend again. There's an issue though:
tests/plugins/Unity/Launcher/gsettings.cpp+5
@@ -35,5 +35,10 @@ QStringList GSettings::storedApplications() const
3535void GSettings::setStoredApplications(const QStringList &storedApplications)
3636{
3737 m_entries = storedApplications;
38+}
39+
40+void GSettings::simulateDConfChanged(const QStringList &storedApplications)
41+{
42+ setStoredApplications(storedApplications);
3843 Q_EMIT changed();
3944}
tests/plugins/Unity/Launcher/gsettings.h+2
@@ -34,6 +34,8 @@ public:
3434 QStringList storedApplications() const;
3535 void setStoredApplications(const QStringList &storedApplications);
3636
37+ void simulateDConfChanged(const QStringList &storedApplications);
38+
3739Q_SIGNALS:
3840 void changed();
3941
tests/plugins/Unity/Launcher/launchermodeltest.cpp+2−2
@@ -442,14 +442,14 @@ private Q_SLOTS:
442442 QCOMPARE(settings->storedApplications().count(), 2);
443443
444444 // Now remove 1 app through the backend, make sure one is still there
445− settings->setStoredApplications(QStringList() << "abs-icon");
445+ settings->simulateDConfChanged(QStringList() << "abs-icon");
446446 QCOMPARE(settings->storedApplications().count(), 1);
447447
448448 // Check if it disappeared from the frontend too
449449 QCOMPARE(launcherModel->rowCount(), 1);
450450
451451 // Add them back but in reverse order
452− settings->setStoredApplications(QStringList() << "no-icon" << "abs-icon");
452+ settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
453453 QCOMPARE(launcherModel->rowCount(), 2);
454454 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
455455 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));