@@ -21,6 +21,8 @@
2121#include "launcheritem.h"
2222#include "backend/launcherbackend.h"
2323
24+#include <QDebug>
25+
2426LauncherModel::LauncherModel(QObject *parent):
2527 LauncherModelInterface(parent),
2628 m_backend(new LauncherBackend(true, this))
@@ -74,6 +76,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
7476 return item->count();
7577 case RoleProgress:
7678 return item->progress();
79+ case RoleFocused:
80+ return item->focused();
7781 }
7882
7983 return QVariant();
@@ -193,18 +197,41 @@ void LauncherModel::setUser(const QString &username)
193197
194198void LauncherModel::applicationFocused(const QString &appId)
195199{
196− int index = findApplication(appId);
200+ // Unfocus all apps
201+ for(int i = 0; i < m_list.count(); ++i) {
202+ LauncherItem *item = m_list.at(i);
203+ if (item->focused()) {
204+ item->setFocused(false);
205+ Q_EMIT dataChanged(this->index(i), this->index(i), QVector<int>() << RoleFocused);
206+ }
207+ }
208+
209+ if (appId.isEmpty()) {
210+ return;
211+ }
212+
213+ // FIXME: drop this once we get real appIds from the AppManager
214+ QString helper = appId.split('/').last();
215+ if (helper.endsWith(".desktop")) {
216+ helper.chop(8);
217+ }
218+
219+ int index = findApplication(helper);
220+ qDebug() << "################## found focused app index" << index << helper;
197221
198222 if (index >= 0) {
199− // TODO: Mark application as focued
223+ m_list.at(index)->setFocused(true);
224+ qDebug() << "set focused to true on" << m_list.at(index)->name();
225+ Q_EMIT dataChanged(this->index(index), this->index(index), QVector<int>() << RoleFocused);
200226 } else {
201227 // Add app to recent apps
202− QString desktopFile = m_backend->desktopFile(appId);
203− QString appName = m_backend->displayName(appId);
204− QString icon = m_backend->icon(appId);
228+ QString desktopFile = m_backend->desktopFile(helper);
229+ QString appName = m_backend->displayName(helper);
230+ QString icon = m_backend->icon(helper);
205231
206− LauncherItem *item = new LauncherItem(appId, desktopFile, appName, icon);
232+ LauncherItem *item = new LauncherItem(helper, desktopFile, appName, icon);
207233 item->setRecent(true);
234+ item->setFocused(true);
208235 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
209236 m_list.append(item);
210237 endInsertRows();
@@ -243,6 +270,7 @@ int LauncherModel::findApplication(const QString &appId)
243270{
244271 for (int i = 0; i < m_list.count(); ++i) {
245272 LauncherItem *item = m_list.at(i);
273+ qDebug() << "checking app" << item->appId();
246274 if (item->appId() == appId) {
247275 return i;
248276 }