on xenial help sign in
only hint if the change was triggered from the backend, add tests
commit36f2dcde144a9de75e6970062677cf8c2e9f12d9 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 6 Oct 2014, 16:04 (12 years ago) parent73d98ae
8 files changed+49−7
plugins/Unity/Launcher/launchermodel.cpp+10−1 qml/Launcher/Launcher.qml+2−4 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+5 tests/mocks/Unity/Launcher/MockLauncherModel.h+3 tests/plugins/Unity/Launcher/gsettings.cpp+5 tests/plugins/Unity/Launcher/gsettings.h+3 tests/plugins/Unity/Launcher/launchermodeltest.cpp+6−2 tests/qmltests/Launcher/tst_Launcher.qml+15
plugins/Unity/Launcher/launchermodel.cpp+10−1
@@ -344,6 +344,7 @@ void LauncherModel::countVisibleChanged(const QString &appId, int countVisible)
344344 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
345345 m_list.append(item);
346346 endInsertRows();
347+ Q_EMIT hintChanged();
347348 }
348349 }
349350}
@@ -372,6 +373,8 @@ void LauncherModel::refresh()
372373 requestRemove(item->appId());
373374 }
374375
376+ bool changed = toBeRemoved.count() > 0;
377+
375378 // This brings the Launcher into sync with the settings backend again. There's an issue though:
376379 // If we can't find a .desktop file for an entry we need to skip it. That makes our settingsIndex
377380 // go out of sync with the actual index of items. So let's also use an addedIndex which reflects
@@ -406,18 +409,24 @@ void LauncherModel::refresh()
406409 beginInsertRows(QModelIndex(), addedIndex, addedIndex);
407410 m_list.insert(addedIndex, item);
408411 endInsertRows();
412+ changed = true;
409413 } else if (itemIndex != addedIndex) {
410− // The item is already there, but it is in a different place then in the settings.
414+ // The item is already there, but it is in a different place than in the settings.
411415 // Move it to the addedIndex
412416 beginMoveRows(QModelIndex(), itemIndex, itemIndex, QModelIndex(), addedIndex);
413417 m_list.move(itemIndex, addedIndex);
414418 endMoveRows();
419+ changed = true;
415420 }
416421
417422 // Just like settingsIndex, this will increase with every item, except the ones we
418423 // skipped with the "continue" call above.
419424 addedIndex++;
420425 }
426+
427+ if (changed) {
428+ Q_EMIT hintChanged();
429+ }
421430}
422431
423432void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
qml/Launcher/Launcher.qml+2−4
@@ -79,7 +79,7 @@ Item {
7979
8080 Timer {
8181 id: teaseTimer
82− interval: 200
82+ interval: mode == "teasing" ? 200 : 300
8383 property string mode: "teasing"
8484 }
8585
@@ -113,9 +113,7 @@ Item {
113113
114114 Connections {
115115 target: LauncherModel
116− onRowsRemoved: hint();
117− onRowsInserted: hint();
118− onRowsMoved: hint();
116+ onHintChanged: hint();
119117 }
120118
121119 SequentialAnimation {
tests/mocks/Unity/Launcher/MockLauncherModel.cpp+5
@@ -208,6 +208,11 @@ void MockLauncherModel::setApplicationManager(unity::shell::application::Applica
208208 Q_UNUSED(applicationManager)
209209}
210210
211+void MockLauncherModel::emitHintChanged()
212+{
213+ Q_EMIT hintChanged();
214+}
215+
211216unity::shell::application::ApplicationManagerInterface *MockLauncherModel::applicationManager() const
212217{
213218 return nullptr;
tests/mocks/Unity/Launcher/MockLauncherModel.h+3
@@ -49,6 +49,9 @@ public:
4949 unity::shell::application::ApplicationManagerInterface *applicationManager() const;
5050 void setApplicationManager(unity::shell::application::ApplicationManagerInterface *applicationManager);
5151
52+ // For testing
53+ Q_INVOKABLE void emitHintChanged();
54+
5255Q_SIGNALS:
5356 void quickListTriggered(const QString &appId, int index);
5457
tests/plugins/Unity/Launcher/gsettings.cpp+5
@@ -33,6 +33,11 @@ QStringList GSettings::storedApplications() const
3333}
3434
3535void GSettings::setStoredApplications(const QStringList &storedApplications)
36+{
37+ m_entries = storedApplications;
38+}
39+
40+void GSettings::simulateDconfChange(const QStringList &storedApplications)
3641{
3742 m_entries = storedApplications;
3843 Q_EMIT changed();
tests/plugins/Unity/Launcher/gsettings.h+3
@@ -34,6 +34,9 @@ public:
3434 QStringList storedApplications() const;
3535 void setStoredApplications(const QStringList &storedApplications);
3636
37+ // Only for testing
38+ void simulateDconfChange(const QStringList &storedApplications);
39+
3740Q_SIGNALS:
3841 void changed();
3942
tests/plugins/Unity/Launcher/launchermodeltest.cpp+6−2
@@ -421,6 +421,7 @@ private Q_SLOTS:
421421
422422 void testSettings() {
423423 GSettings *settings = launcherModel->m_settings;
424+ QSignalSpy spy(launcherModel, SIGNAL(hintChanged()));
424425
425426 // Nothing pinned at startup
426427 QCOMPARE(settings->storedApplications().count(), 0);
@@ -428,6 +429,7 @@ private Q_SLOTS:
428429 // pin both apps
429430 launcherModel->pin("abs-icon");
430431 launcherModel->pin("no-icon");
432+ QCOMPARE(spy.count(), 0);
431433
432434 // Now settings should have 2 apps
433435 QCOMPARE(settings->storedApplications().count(), 2);
@@ -440,17 +442,19 @@ private Q_SLOTS:
440442 QCOMPARE(settings->storedApplications().count(), 2);
441443
442444 // Now remove 1 app through the backend, make sure one is still there
443− settings->setStoredApplications(QStringList() << "abs-icon");
445+ settings->simulateDconfChange(QStringList() << "abs-icon");
444446 QCOMPARE(settings->storedApplications().count(), 1);
447+ QCOMPARE(spy.count(), 1);
445448
446449 // Check if it disappeared from the frontend too
447450 QCOMPARE(launcherModel->rowCount(), 1);
448451
449452 // Add them back but in reverse order
450− settings->setStoredApplications(QStringList() << "no-icon" << "abs-icon");
453+ settings->simulateDconfChange(QStringList() << "no-icon" << "abs-icon");
451454 QCOMPARE(launcherModel->rowCount(), 2);
452455 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
453456 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
457+ QCOMPARE(spy.count(), 2);
454458 }
455459};
456460
tests/qmltests/Launcher/tst_Launcher.qml+15
@@ -189,6 +189,21 @@ Item {
189189 launcher.available = true;
190190 }
191191
192+ function test_hintLauncherOnChange() {
193+ var launcherPanel = findChild(launcher, "launcherPanel")
194+ // Make sure we start hidden
195+ tryCompare(launcherPanel, "x", -launcher.panelWidth)
196+ // reset our measurement property
197+ launcher.maxPanelX = -launcher.panelWidth
198+ // change it
199+ LauncherModel.move(0, 1)
200+ LauncherModel.emitHintChanged();
201+
202+ // make sure it opened fully and hides again without delay
203+ tryCompare(launcher, "maxPanelX", 0)
204+ tryCompare(launcherPanel, "x", -launcher.panelWidth, 1000)
205+ }
206+
192207 function test_countEmblems() {
193208 revealer.dragLauncherIntoView();
194209 var launcherListView = findChild(launcher, "launcherListView");