on xenial help sign in
[Launcher] fix bug where an item would disappear even though the app is running

When an unpinned item is shown because of a count emblem notification, and during that time the application is started, the old code wouldn't update the app's "recent" state and so dropping it when the count emblem is cleared. Fixes: #1438172 Approved by: Albert Astals Cid

commit53bcb4439aeaeefeb13fcfb375ea7c2c1c306a1e authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 9 Apr 2015, 14:00 (12 years ago) parent2a50cbd9927cee
2 files changed+64−7
plugins/Unity/Launcher/launchermodel.cpp+7−7 tests/plugins/Unity/Launcher/launchermodeltest.cpp+57
plugins/Unity/Launcher/launchermodel.cpp+7−7
@@ -468,14 +468,14 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
468468 return;
469469 }
470470
471− bool found = false;
472− Q_FOREACH(LauncherItem *item, m_list) {
473− if (app->appId() == item->appId()) {
474− found = true;
475− break;
471+ int itemIndex = findApplication(app->appId());
472+ if (itemIndex != -1) {
473+ LauncherItem *item = m_list.at(itemIndex);
474+ if (!item->recent()) {
475+ item->setRecent(true);
476+ m_asAdapter->syncItems(m_list);
477+ Q_EMIT dataChanged(index(itemIndex), index(itemIndex), QVector<int>() << RoleRecent);
476478 }
477− }
478− if (found) {
479479 // Shall we paint some running/recent app highlight? If yes, do it here.
480480 } else {
481481 LauncherItem *item = new LauncherItem(app->appId(), app->name(), app->icon().toString(), this);
tests/plugins/Unity/Launcher/launchermodeltest.cpp+57
@@ -400,6 +400,63 @@ private Q_SLOTS:
400400 QCOMPARE(launcherModel->get(index)->count(), 55);
401401 }
402402
403+ void testCountEmblemAddsRemovesItem_data() {
404+ QTest::addColumn<bool>("isPinned");
405+ QTest::addColumn<bool>("isRunning");
406+ QTest::addColumn<bool>("startWhenVisible");
407+ QTest::newRow("not pinned, not running") << false << false << false;
408+ QTest::newRow("pinned, not running") << true << false << false;
409+ QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
410+ QTest::newRow("pinned, not running, starting from notification") << true << false << true;
411+ QTest::newRow("not pinned, running") << false << true << false;
412+ QTest::newRow("pinned, running") << true << true << false;
413+ }
414+
415+ void testCountEmblemAddsRemovesItem() {
416+ QFETCH(bool, isPinned);
417+ QFETCH(bool, isRunning);
418+ QFETCH(bool, startWhenVisible);
419+
420+ // Make sure item is here as expected after init() and that count is not visible
421+ int index = launcherModel->findApplication("abs-icon");
422+ QCOMPARE(index == -1, false);
423+ QCOMPARE(launcherModel->get(index)->countVisible(), false);
424+
425+ // Pin if we need to
426+ if (isPinned) {
427+ launcherModel->pin("abs-icon");
428+ }
429+ QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
430+
431+ // Stop it if we need to
432+ if (!isRunning) {
433+ appManager->stopApplication("abs-icon");
434+ }
435+ QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
436+
437+
438+ // set the count emblem to visible
439+ QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
440+ interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
441+ interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
442+
443+ // Make sure item is here and that count is visible
444+ index = launcherModel->findApplication("abs-icon");
445+ QCOMPARE(index == -1, false);
446+ QCOMPARE(launcherModel->get(index)->countVisible(), true);
447+
448+ if (!isRunning && startWhenVisible) {
449+ appManager->addApplication(new MockApp("abs-icon"));
450+ }
451+
452+ // Hide count emblem again
453+ interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
454+
455+ // Make sure item is shown/hidden as expected
456+ index = launcherModel->findApplication("abs-icon");
457+ QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
458+ }
459+
403460 void testRefreshAfterDeletedDesktopFiles_data() {
404461 QTest::addColumn<bool>("deleted");
405462 QTest::newRow("have .desktop files") << false;