on xenial help sign in
only hint if the change was triggered from the backend, add tests
36f2dcdMichael Zanetti
plugins/Unity/Launcher/launchermodel.cpp+10−1
@@ -344,6 +344,7 @@ void LauncherModel::countVisibleChanged(const QString &appId, int countVisible)
344 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
344 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
345 m_list.append(item);
345 m_list.append(item);
346 endInsertRows();
346 endInsertRows();
347+ Q_EMIT hintChanged();
347 }
348 }
348 }
349 }
349}
350}
@@ -372,6 +373,8 @@ void LauncherModel::refresh()
372 requestRemove(item->appId());
373 requestRemove(item->appId());
373 }
374 }
374
375
376+ bool changed = toBeRemoved.count() > 0;
377+
375 // This brings the Launcher into sync with the settings backend again. There's an issue though:
378 // This brings the Launcher into sync with the settings backend again. There's an issue though:
376 // If we can't find a .desktop file for an entry we need to skip it. That makes our settingsIndex
379 // If we can't find a .desktop file for an entry we need to skip it. That makes our settingsIndex
377 // go out of sync with the actual index of items. So let's also use an addedIndex which reflects
380 // 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()
406 beginInsertRows(QModelIndex(), addedIndex, addedIndex);
409 beginInsertRows(QModelIndex(), addedIndex, addedIndex);
407 m_list.insert(addedIndex, item);
410 m_list.insert(addedIndex, item);
408 endInsertRows();
411 endInsertRows();
412+ changed = true;
409 } else if (itemIndex != addedIndex) {
413 } 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.
411 // Move it to the addedIndex
415 // Move it to the addedIndex
412 beginMoveRows(QModelIndex(), itemIndex, itemIndex, QModelIndex(), addedIndex);
416 beginMoveRows(QModelIndex(), itemIndex, itemIndex, QModelIndex(), addedIndex);
413 m_list.move(itemIndex, addedIndex);
417 m_list.move(itemIndex, addedIndex);
414 endMoveRows();
418 endMoveRows();
419+ changed = true;
415 }
420 }
416
421
417 // Just like settingsIndex, this will increase with every item, except the ones we
422 // Just like settingsIndex, this will increase with every item, except the ones we
418 // skipped with the "continue" call above.
423 // skipped with the "continue" call above.
419 addedIndex++;
424 addedIndex++;
420 }
425 }
426+
427+ if (changed) {
428+ Q_EMIT hintChanged();
429+ }
421}
430}
422
431
423void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
432void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
qml/Launcher/Launcher.qml+2−4
@@ -79,7 +79,7 @@ Item {
79
79
80 Timer {
80 Timer {
81 id: teaseTimer
81 id: teaseTimer
82− interval: 200
82+ interval: mode == "teasing" ? 200 : 300
83 property string mode: "teasing"
83 property string mode: "teasing"
84 }
84 }
85
85
@@ -113,9 +113,7 @@ Item {
113
113
114 Connections {
114 Connections {
115 target: LauncherModel
115 target: LauncherModel
116− onRowsRemoved: hint();
116+ onHintChanged: hint();
117− onRowsInserted: hint();
118− onRowsMoved: hint();
119 }
117 }
120
118
121 SequentialAnimation {
119 SequentialAnimation {
tests/mocks/Unity/Launcher/MockLauncherModel.cpp+5
@@ -208,6 +208,11 @@ void MockLauncherModel::setApplicationManager(unity::shell::application::Applica
208 Q_UNUSED(applicationManager)
208 Q_UNUSED(applicationManager)
209}
209}
210
210
211+void MockLauncherModel::emitHintChanged()
212+{
213+ Q_EMIT hintChanged();
214+}
215+
211unity::shell::application::ApplicationManagerInterface *MockLauncherModel::applicationManager() const
216unity::shell::application::ApplicationManagerInterface *MockLauncherModel::applicationManager() const
212{
217{
213 return nullptr;
218 return nullptr;
tests/mocks/Unity/Launcher/MockLauncherModel.h+3
@@ -49,6 +49,9 @@ public:
49 unity::shell::application::ApplicationManagerInterface *applicationManager() const;
49 unity::shell::application::ApplicationManagerInterface *applicationManager() const;
50 void setApplicationManager(unity::shell::application::ApplicationManagerInterface *applicationManager);
50 void setApplicationManager(unity::shell::application::ApplicationManagerInterface *applicationManager);
51
51
52+ // For testing
53+ Q_INVOKABLE void emitHintChanged();
54+
52Q_SIGNALS:
55Q_SIGNALS:
53 void quickListTriggered(const QString &appId, int index);
56 void quickListTriggered(const QString &appId, int index);
54
57
tests/plugins/Unity/Launcher/gsettings.cpp+5
@@ -33,6 +33,11 @@ QStringList GSettings::storedApplications() const
33}
33}
34
34
35void GSettings::setStoredApplications(const QStringList &storedApplications)
35void GSettings::setStoredApplications(const QStringList &storedApplications)
36+{
37+ m_entries = storedApplications;
38+}
39+
40+void GSettings::simulateDconfChange(const QStringList &storedApplications)
36{
41{
37 m_entries = storedApplications;
42 m_entries = storedApplications;
38 Q_EMIT changed();
43 Q_EMIT changed();
tests/plugins/Unity/Launcher/gsettings.h+3
@@ -34,6 +34,9 @@ public:
34 QStringList storedApplications() const;
34 QStringList storedApplications() const;
35 void setStoredApplications(const QStringList &storedApplications);
35 void setStoredApplications(const QStringList &storedApplications);
36
36
37+ // Only for testing
38+ void simulateDconfChange(const QStringList &storedApplications);
39+
37Q_SIGNALS:
40Q_SIGNALS:
38 void changed();
41 void changed();
39
42
tests/plugins/Unity/Launcher/launchermodeltest.cpp+6−2
@@ -421,6 +421,7 @@ private Q_SLOTS:
421
421
422 void testSettings() {
422 void testSettings() {
423 GSettings *settings = launcherModel->m_settings;
423 GSettings *settings = launcherModel->m_settings;
424+ QSignalSpy spy(launcherModel, SIGNAL(hintChanged()));
424
425
425 // Nothing pinned at startup
426 // Nothing pinned at startup
426 QCOMPARE(settings->storedApplications().count(), 0);
427 QCOMPARE(settings->storedApplications().count(), 0);
@@ -428,6 +429,7 @@ private Q_SLOTS:
428 // pin both apps
429 // pin both apps
429 launcherModel->pin("abs-icon");
430 launcherModel->pin("abs-icon");
430 launcherModel->pin("no-icon");
431 launcherModel->pin("no-icon");
432+ QCOMPARE(spy.count(), 0);
431
433
432 // Now settings should have 2 apps
434 // Now settings should have 2 apps
433 QCOMPARE(settings->storedApplications().count(), 2);
435 QCOMPARE(settings->storedApplications().count(), 2);
@@ -440,17 +442,19 @@ private Q_SLOTS:
440 QCOMPARE(settings->storedApplications().count(), 2);
442 QCOMPARE(settings->storedApplications().count(), 2);
441
443
442 // 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
443− settings->setStoredApplications(QStringList() << "abs-icon");
445+ settings->simulateDconfChange(QStringList() << "abs-icon");
444 QCOMPARE(settings->storedApplications().count(), 1);
446 QCOMPARE(settings->storedApplications().count(), 1);
447+ QCOMPARE(spy.count(), 1);
445
448
446 // Check if it disappeared from the frontend too
449 // Check if it disappeared from the frontend too
447 QCOMPARE(launcherModel->rowCount(), 1);
450 QCOMPARE(launcherModel->rowCount(), 1);
448
451
449 // Add them back but in reverse order
452 // Add them back but in reverse order
450− settings->setStoredApplications(QStringList() << "no-icon" << "abs-icon");
453+ settings->simulateDconfChange(QStringList() << "no-icon" << "abs-icon");
451 QCOMPARE(launcherModel->rowCount(), 2);
454 QCOMPARE(launcherModel->rowCount(), 2);
452 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
455 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
453 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
456 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
457+ QCOMPARE(spy.count(), 2);
454 }
458 }
455};
459};
456
460
tests/qmltests/Launcher/tst_Launcher.qml+15
@@ -189,6 +189,21 @@ Item {
189 launcher.available = true;
189 launcher.available = true;
190 }
190 }
191
191
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+
192 function test_countEmblems() {
207 function test_countEmblems() {
193 revealer.dragLauncherIntoView();
208 revealer.dragLauncherIntoView();
194 var launcherListView = findChild(launcher, "launcherListView");
209 var launcherListView = findChild(launcher, "launcherListView");