on xenial help sign in
[Launcher] fix bug where an item would disappear even though the app is running
53bcb44Michael Zanetti
plugins/Unity/Launcher/launchermodel.cpp+7−7
@@ -468,14 +468,14 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
468 return;
468 return;
469 }
469 }
470
470
471− bool found = false;
471+ int itemIndex = findApplication(app->appId());
472+ if (itemIndex != -1) {
472− Q_FOREACH(LauncherItem *item, m_list) {
473+ LauncherItem *item = m_list.at(itemIndex);
473− if (app->appId() == item->appId()) {
474+ if (!item->recent()) {
474− found = true;
475+ item->setRecent(true);
475− break;
476+ m_asAdapter->syncItems(m_list);
477+ Q_EMIT dataChanged(index(itemIndex), index(itemIndex), QVector<int>() << RoleRecent);
476 }
478 }
477− }
478− if (found) {
479 // Shall we paint some running/recent app highlight? If yes, do it here.
479 // Shall we paint some running/recent app highlight? If yes, do it here.
480 } else {
480 } else {
481 LauncherItem *item = new LauncherItem(app->appId(), app->name(), app->icon().toString(), this);
481 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:
400 QCOMPARE(launcherModel->get(index)->count(), 55);
400 QCOMPARE(launcherModel->get(index)->count(), 55);
401 }
401 }
402
402
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+
403 void testRefreshAfterDeletedDesktopFiles_data() {
460 void testRefreshAfterDeletedDesktopFiles_data() {
404 QTest::addColumn<bool>("deleted");
461 QTest::addColumn<bool>("deleted");
405 QTest::newRow("have .desktop files") << false;
462 QTest::newRow("have .desktop files") << false;