@@ -36,7 +36,7 @@ LauncherModel::LauncherModel(QObject *parent):
3636 m_settings(new GSettings(this)),
3737 m_dbusIface(new DBusInterface(this)),
3838 m_asAdapter(new ASAdapter()),
39− m_appManager(0)
39+ m_appManager(nullptr)
4040{
4141 connect(m_dbusIface, &DBusInterface::countChanged, this, &LauncherModel::countChanged);
4242 connect(m_dbusIface, &DBusInterface::countVisibleChanged, this, &LauncherModel::countVisibleChanged);
@@ -86,6 +86,11 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
8686 return item->focused();
8787 case RoleAlerting:
8888 return item->alerting();
89+ case RoleRunning:
90+ return item->running();
91+ default:
92+ qWarning() << Q_FUNC_INFO << "missing role, implement me";
93+ return QVariant();
8994 }
9095
9196 return QVariant();
@@ -150,7 +155,7 @@ void LauncherModel::pin(const QString &appId, int index)
150155 if (index == -1 || index == currentIndex) {
151156 m_list.at(currentIndex)->setPinned(true);
152157 QModelIndex modelIndex = this->index(currentIndex);
153− Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
158+ Q_EMIT dataChanged(modelIndex, modelIndex, {RolePinned});
154159 } else {
155160 move(currentIndex, index);
156161 // move() will store the list to the backend itself, so just exit at this point.
@@ -163,7 +168,7 @@ void LauncherModel::pin(const QString &appId, int index)
163168
164169 DesktopFileHandler desktopFile(appId);
165170 if (!desktopFile.isValid()) {
166− qWarning() << "Can't pin this application, there is no .destkop file available.";
171+ qWarning() << "Can't pin this application, there is no .desktop file available.";
167172 return;
168173 }
169174
@@ -188,7 +193,7 @@ void LauncherModel::requestRemove(const QString &appId)
188193
189194void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
190195{
191− int index = findApplication(appId);
196+ const int index = findApplication(appId);
192197 if (index < 0) {
193198 return;
194199 }
@@ -196,7 +201,7 @@ void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex
196201 LauncherItem *item = m_list.at(index);
197202 QuickListModel *model = qobject_cast<QuickListModel*>(item->quickList());
198203 if (model) {
199− QString actionId = model->get(actionIndex).actionId();
204+ const QString actionId = model->get(actionIndex).actionId();
200205
201206 // Check if this is one of the launcher actions we handle ourselves
202207 if (actionId == "pin_item") {
@@ -207,7 +212,10 @@ void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex
207212 }
208213 } else if (actionId == "launch_item") {
209214 QDesktopServices::openUrl(getUrlForAppId(appId));
210−
215+ } else if (actionId == "stop_item") { // Quit
216+ if (m_appManager) {
217+ m_appManager->stopApplication(appId);
218+ }
211219 // Nope, we don't know this action, let the backend forward it to the application
212220 } else {
213221 // TODO: forward quicklist action to app, possibly via m_dbusIface
@@ -305,7 +313,7 @@ void LauncherModel::storeAppList()
305313
306314void LauncherModel::unpin(const QString &appId)
307315{
308− int index = findApplication(appId);
316+ const int index = findApplication(appId);
309317 if (index < 0) {
310318 return;
311319 }
@@ -314,7 +322,7 @@ void LauncherModel::unpin(const QString &appId)
314322 if (m_list.at(index)->pinned()) {
315323 m_list.at(index)->setPinned(false);
316324 QModelIndex modelIndex = this->index(index);
317− Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
325+ Q_EMIT dataChanged(modelIndex, modelIndex, {RolePinned});
318326 }
319327 } else {
320328 beginRemoveRows(QModelIndex(), index, index);
@@ -336,25 +344,25 @@ int LauncherModel::findApplication(const QString &appId)
336344
337345void LauncherModel::progressChanged(const QString &appId, int progress)
338346{
339− int idx = findApplication(appId);
347+ const int idx = findApplication(appId);
340348 if (idx >= 0) {
341349 LauncherItem *item = m_list.at(idx);
342350 item->setProgress(progress);
343− Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleProgress);
351+ Q_EMIT dataChanged(index(idx), index(idx), {RoleProgress});
344352 }
345353}
346354
347355void LauncherModel::countChanged(const QString &appId, int count)
348356{
349− int idx = findApplication(appId);
357+ const int idx = findApplication(appId);
350358 if (idx >= 0) {
351359 LauncherItem *item = m_list.at(idx);
352360 item->setCount(count);
353361 if (item->countVisible()) {
354362 setAlerting(item->appId(), true);
355363 }
356− Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleCount);
357364 m_asAdapter->syncItems(m_list);
365+ Q_EMIT dataChanged(index(idx), index(idx), {RoleCount});
358366 }
359367}
360368
@@ -367,7 +375,7 @@ void LauncherModel::countVisibleChanged(const QString &appId, bool countVisible)
367375 if (countVisible) {
368376 setAlerting(item->appId(), true);
369377 }
370− Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleCountVisible);
378+ Q_EMIT dataChanged(index(idx), index(idx), {RoleCountVisible});
371379
372380 // If countVisible goes to false, and the item is neither pinned nor recent we can drop it
373381 if (!countVisible && !item->pinned() && !item->recent()) {
@@ -408,7 +416,8 @@ void LauncherModel::refresh()
408416 item->setName(desktopFile.displayName());
409417 item->setIcon(desktopFile.icon());
410418 item->setPinned(item->pinned()); // update pinned text if needed
411− Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleName << RoleIcon);
419+ item->setRunning(item->running());
420+ Q_EMIT dataChanged(index(idx), index(idx), {RoleName, RoleIcon, RoleRunning});
412421 }
413422 }
414423
@@ -426,7 +435,7 @@ void LauncherModel::refresh()
426435
427436 // Now walk through settings and see if we need to add something
428437 for (int settingsIndex = 0; settingsIndex < m_settings->storedApplications().count(); ++settingsIndex) {
429− QString entry = m_settings->storedApplications().at(settingsIndex);
438+ const QString entry = m_settings->storedApplications().at(settingsIndex);
430439 int itemIndex = -1;
431440 for (int i = 0; i < m_list.count(); ++i) {
432441 if (m_list.at(i)->appId() == entry) {
@@ -499,25 +508,27 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
499508 return;
500509 }
501510
502− int itemIndex = findApplication(app->appId());
511+ const int itemIndex = findApplication(app->appId());
503512 if (itemIndex != -1) {
504513 LauncherItem *item = m_list.at(itemIndex);
505514 if (!item->recent()) {
506515 item->setRecent(true);
507− m_asAdapter->syncItems(m_list);
508− Q_EMIT dataChanged(index(itemIndex), index(itemIndex), QVector<int>() << RoleRecent);
516+ Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRecent});
509517 }
510− // Shall we paint some running/recent app highlight? If yes, do it here.
518+ item->setRunning(true);
519+ // TODO Shall we paint some running/recent app highlight? If yes, do it here.
511520 } else {
512521 LauncherItem *item = new LauncherItem(app->appId(), app->name(), app->icon().toString(), this);
513522 item->setRecent(true);
523+ item->setRunning(true);
514524 item->setFocused(app->focused());
515525
516526 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
517527 m_list.append(item);
518528 endInsertRows();
519− m_asAdapter->syncItems(m_list);
520529 }
530+ m_asAdapter->syncItems(m_list);
531+ Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRunning});
521532}
522533
523534void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
@@ -532,25 +543,35 @@ void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
532543 }
533544 }
534545
535− if (appIndex > -1 && !m_list.at(appIndex)->pinned()) {
546+ if (appIndex < 0) {
547+ qWarning() << Q_FUNC_INFO << "appIndex not found";
548+ return;
549+ }
550+
551+ LauncherItem * item = m_list.at(appIndex);
552+ item->setRunning(false);
553+
554+ if (!item->pinned()) {
536555 beginRemoveRows(QModelIndex(), appIndex, appIndex);
537556 m_list.takeAt(appIndex)->deleteLater();
538557 endRemoveRows();
539558 m_asAdapter->syncItems(m_list);
559+ Q_EMIT dataChanged(index(appIndex), index(appIndex), {RolePinned});
540560 }
561+ Q_EMIT dataChanged(index(appIndex), index(appIndex), {RoleRunning});
541562}
542563
543564void LauncherModel::focusedAppIdChanged()
544565{
545− QString appId = m_appManager->focusedApplicationId();
566+ const QString appId = m_appManager->focusedApplicationId();
546567 for (int i = 0; i < m_list.count(); ++i) {
547568 LauncherItem *item = m_list.at(i);
548569 if (!item->focused() && item->appId() == appId) {
549570 item->setFocused(true);
550− Q_EMIT dataChanged(index(i), index(i), QVector<int>() << RoleFocused);
571+ Q_EMIT dataChanged(index(i), index(i), {RoleFocused});
551572 } else if (item->focused() && item->appId() != appId) {
552573 item->setFocused(false);
553− Q_EMIT dataChanged(index(i), index(i), QVector<int>() << RoleFocused);
574+ Q_EMIT dataChanged(index(i), index(i), {RoleFocused});
554575 }
555576 }
556577}