@@ -25,6 +25,7 @@
25#include "asadapter.h"
25#include "asadapter.h"
27#include <unity/shell/application/ApplicationInfoInterface.h>
27#include <unity/shell/application/ApplicationInfoInterface.h>
28+#include <unity/shell/application/MirSurfaceListInterface.h>
29#include <QDesktopServices>
30#include <QDesktopServices>
30#include <QDebug>
31#include <QDebug>
@@ -88,6 +89,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
88 return item->alerting();
89 return item->alerting();
89 case RoleRunning:
90 case RoleRunning:
90 return item->running();
91 return item->running();
92+ case RoleSurfaceCount:
93+ return item->surfaceCount();
92 qWarning() << Q_FUNC_INFO << "missing role, implement me";
95 qWarning() << Q_FUNC_INFO << "missing role, implement me";
93 return QVariant();
96 return QVariant();
@@ -96,18 +99,6 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
96 return QVariant();
99 return QVariant();
99−void LauncherModel::setAlerting(const QString &appId, bool alerting) {
100− int index = findApplication(appId);
102− QModelIndex modelIndex = this->index(index);
103− LauncherItem *item = m_list.at(index);
104− if (!item->focused()) {
105− item->setAlerting(alerting);
106− Q_EMIT dataChanged(modelIndex, modelIndex, {RoleAlerting});
111unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) const
102unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) const
113 if (index < 0 || index >= m_list.count()) {
104 if (index < 0 || index >= m_list.count()) {
@@ -358,11 +349,13 @@ void LauncherModel::countChanged(const QString &appId, int count)
358 if (idx >= 0) {
349 if (idx >= 0) {
359 LauncherItem *item = m_list.at(idx);
350 LauncherItem *item = m_list.at(idx);
360 item->setCount(count);
351 item->setCount(count);
352+ QVector<int> changedRoles = {RoleCount};
361− if (item->countVisible()) {
353+ if (item->countVisible() && !item->alerting() && !item->focused()) {
354+ changedRoles << RoleAlerting;
362− setAlerting(item->appId(), true);
355+ item->setAlerting(true);
364 m_asAdapter->syncItems(m_list);
357 m_asAdapter->syncItems(m_list);
365− Q_EMIT dataChanged(index(idx), index(idx), {RoleCount});
358+ Q_EMIT dataChanged(index(idx), index(idx), changedRoles);
@@ -372,10 +365,12 @@ void LauncherModel::countVisibleChanged(const QString &appId, bool countVisible)
372 if (idx >= 0) {
365 if (idx >= 0) {
373 LauncherItem *item = m_list.at(idx);
366 LauncherItem *item = m_list.at(idx);
374 item->setCountVisible(countVisible);
367 item->setCountVisible(countVisible);
368+ QVector<int> changedRoles = {RoleCount};
375− if (countVisible) {
369+ if (countVisible && !item->alerting() && !item->focused()) {
370+ changedRoles << RoleAlerting;
376− setAlerting(item->appId(), true);
371+ item->setAlerting(true);
378− Q_EMIT dataChanged(index(idx), index(idx), {RoleCountVisible});
373+ Q_EMIT dataChanged(index(idx), index(idx), changedRoles);
380 // If countVisible goes to false, and the item is neither pinned nor recent we can drop it
375 // If countVisible goes to false, and the item is neither pinned nor recent we can drop it
381 if (!countVisible && !item->pinned() && !item->recent()) {
376 if (!countVisible && !item->pinned() && !item->recent()) {
@@ -498,8 +493,10 @@ void LauncherModel::alert(const QString &appId)
498 int idx = findApplication(appId);
493 int idx = findApplication(appId);
499 if (idx >= 0) {
494 if (idx >= 0) {
500 LauncherItem *item = m_list.at(idx);
495 LauncherItem *item = m_list.at(idx);
496+ if (!item->focused() && !item->alerting()) {
501− setAlerting(item->appId(), true);
497+ item->setAlerting(true);
502− Q_EMIT dataChanged(index(idx), index(idx), {RoleAlerting});
498+ Q_EMIT dataChanged(index(idx), index(idx), {RoleAlerting});
@@ -525,28 +522,50 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
525 item->setRecent(true);
522 item->setRecent(true);
526 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRecent});
523 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRecent});
525+ if (item->surfaceCount() != app->surfaceCount()) {
526+ item->setSurfaceCount(app->surfaceCount());
527+ Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleSurfaceCount});
528 item->setRunning(true);
530 item->setRunning(true);
530 LauncherItem *item = new LauncherItem(app->appId(), app->name(), app->icon().toString(), this);
532 LauncherItem *item = new LauncherItem(app->appId(), app->name(), app->icon().toString(), this);
531 item->setRecent(true);
533 item->setRecent(true);
532 item->setRunning(true);
534 item->setRunning(true);
533 item->setFocused(app->focused());
535 item->setFocused(app->focused());
534−
536+ item->setSurfaceCount(app->surfaceCount());
535 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
537 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
536 m_list.append(item);
538 m_list.append(item);
537 endInsertRows();
539 endInsertRows();
541+ connect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::applicationSurfaceCountChanged);
539 m_asAdapter->syncItems(m_list);
542 m_asAdapter->syncItems(m_list);
540 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRunning});
543 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRunning});
546+void LauncherModel::applicationSurfaceCountChanged(int count)
548+ ApplicationInfoInterface *app = static_cast<ApplicationInfoInterface*>(sender());
549+ int idx = findApplication(app->appId());
551+ qWarning() << "Received a surface count changed event from an app that's not in the Launcher model";
554+ LauncherItem *item = m_list.at(idx);
555+ if (item->surfaceCount() != count) {
556+ item->setSurfaceCount(count);
557+ Q_EMIT dataChanged(index(idx), index(idx), {RoleSurfaceCount});
543void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
561void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
545 Q_UNUSED(parent)
563 Q_UNUSED(parent)
565+ ApplicationInfoInterface *app = m_appManager->get(row);
547 int appIndex = -1;
566 int appIndex = -1;
548 for (int i = 0; i < m_list.count(); ++i) {
567 for (int i = 0; i < m_list.count(); ++i) {
549− if (m_list.at(i)->appId() == m_appManager->get(row)->appId()) {
568+ if (m_list.at(i)->appId() == app->appId()) {
550 appIndex = i;
569 appIndex = i;
@@ -557,17 +576,24 @@ void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
579+ disconnect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::applicationSurfaceCountChanged);
560 LauncherItem * item = m_list.at(appIndex);
581 LauncherItem * item = m_list.at(appIndex);
561− item->setRunning(false);
563 if (!item->pinned()) {
583 if (!item->pinned()) {
564 beginRemoveRows(QModelIndex(), appIndex, appIndex);
584 beginRemoveRows(QModelIndex(), appIndex, appIndex);
565 m_list.takeAt(appIndex)->deleteLater();
585 m_list.takeAt(appIndex)->deleteLater();
566 endRemoveRows();
586 endRemoveRows();
567 m_asAdapter->syncItems(m_list);
587 m_asAdapter->syncItems(m_list);
589+ QVector<int> changedRoles = {RoleRunning};
590+ item->setRunning(false);
591+ if (item->focused()) {
592+ changedRoles << RoleFocused;
593+ item->setFocused(false);
568− Q_EMIT dataChanged(index(appIndex), index(appIndex), {RolePinned});
595+ Q_EMIT dataChanged(index(appIndex), index(appIndex), changedRoles);
570− Q_EMIT dataChanged(index(appIndex), index(appIndex), {RoleRunning});
573void LauncherModel::focusedAppIdChanged()
599void LauncherModel::focusedAppIdChanged()
@@ -576,8 +602,14 @@ void LauncherModel::focusedAppIdChanged()
576 for (int i = 0; i < m_list.count(); ++i) {
602 for (int i = 0; i < m_list.count(); ++i) {
577 LauncherItem *item = m_list.at(i);
603 LauncherItem *item = m_list.at(i);
578 if (!item->focused() && item->appId() == appId) {
604 if (!item->focused() && item->appId() == appId) {
605+ QVector<int> changedRoles;
606+ changedRoles << RoleFocused;
579 item->setFocused(true);
607 item->setFocused(true);
580− Q_EMIT dataChanged(index(i), index(i), {RoleFocused});
608+ if (item->alerting()) {
609+ changedRoles << RoleAlerting;
610+ item->setAlerting(false);
612+ Q_EMIT dataChanged(index(i), index(i), changedRoles);
581 } else if (item->focused() && item->appId() != appId) {
613 } else if (item->focused() && item->appId() != appId) {
582 item->setFocused(false);
614 item->setFocused(false);
583 Q_EMIT dataChanged(index(i), index(i), {RoleFocused});
615 Q_EMIT dataChanged(index(i), index(i), {RoleFocused});