on xenial help sign in
don't call any methods that could overwrite dconf while we're loading it
423e8d4Michael Zanetti
plugins/Unity/Launcher/launchermodel.cpp+13−1
@@ -171,6 +171,7 @@ void LauncherModel::requestRemove(const QString &appId)
171 m_list.at(index)->setPinned(false);
171 m_list.at(index)->setPinned(false);
172 QModelIndex modelIndex = this->index(index);
172 QModelIndex modelIndex = this->index(index);
173 Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
173 Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
174+ storeAppList();
174 return;
175 return;
175 }
176 }
176
177
@@ -350,6 +351,7 @@ void LauncherModel::countVisibleChanged(const QString &appId, int countVisible)
350
351
351void LauncherModel::refresh()
352void LauncherModel::refresh()
352{
353{
354+ qDebug() << "calling refresh";
353 // First walk through all the existing items and see if we need to remove something
355 // First walk through all the existing items and see if we need to remove something
354 QList<LauncherItem*> toBeRemoved;
356 QList<LauncherItem*> toBeRemoved;
355 Q_FOREACH (LauncherItem* item, m_list) {
357 Q_FOREACH (LauncherItem* item, m_list) {
@@ -368,8 +370,18 @@ void LauncherModel::refresh()
368 }
370 }
369 }
371 }
370
372
373+ // If running, just unpin, otherwise really remove
371 Q_FOREACH (LauncherItem* item, toBeRemoved) {
374 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+ }
373 }
385 }
374
386
375 // This brings the Launcher into sync with the settings backend again. There's an issue though:
387 // 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
35void GSettings::setStoredApplications(const QStringList &storedApplications)
35void GSettings::setStoredApplications(const QStringList &storedApplications)
36{
36{
37 m_entries = storedApplications;
37 m_entries = storedApplications;
38+}
39+
40+void GSettings::simulateDConfChanged(const QStringList &storedApplications)
41+{
42+ setStoredApplications(storedApplications);
38 Q_EMIT changed();
43 Q_EMIT changed();
39}
44}
tests/plugins/Unity/Launcher/gsettings.h+2
@@ -34,6 +34,8 @@ public:
34 QStringList storedApplications() const;
34 QStringList storedApplications() const;
35 void setStoredApplications(const QStringList &storedApplications);
35 void setStoredApplications(const QStringList &storedApplications);
36
36
37+ void simulateDConfChanged(const QStringList &storedApplications);
38+
37Q_SIGNALS:
39Q_SIGNALS:
38 void changed();
40 void changed();
39
41
tests/plugins/Unity/Launcher/launchermodeltest.cpp+2−2
@@ -442,14 +442,14 @@ private Q_SLOTS:
442 QCOMPARE(settings->storedApplications().count(), 2);
442 QCOMPARE(settings->storedApplications().count(), 2);
443
443
444 // Now remove 1 app through the backend, make sure one is still there
444 // 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");
446 QCOMPARE(settings->storedApplications().count(), 1);
446 QCOMPARE(settings->storedApplications().count(), 1);
447
447
448 // Check if it disappeared from the frontend too
448 // Check if it disappeared from the frontend too
449 QCOMPARE(launcherModel->rowCount(), 1);
449 QCOMPARE(launcherModel->rowCount(), 1);
450
450
451 // Add them back but in reverse order
451 // Add them back but in reverse order
452− settings->setStoredApplications(QStringList() << "no-icon" << "abs-icon");
452+ settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
453 QCOMPARE(launcherModel->rowCount(), 2);
453 QCOMPARE(launcherModel->rowCount(), 2);
454 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
454 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
455 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
455 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));