@@ -20,6 +20,7 @@
2020#include "dbusinterface.h"
2121#include "asadapter.h"
2222
23+#include <ubuntu-app-launch/appid.h>
2324#include <ubuntu-app-launch/application.h>
2425#include <ubuntu-app-launch/registry.h>
2526#include <unity/shell/application/ApplicationInfoInterface.h>
@@ -28,6 +29,8 @@
2829#include <QDesktopServices>
2930#include <QDebug>
3031
32+namespace ual = ubuntu::app_launch;
33+
3134using namespace unity::shell::application;
3235
3336LauncherModel::LauncherModel(QObject *parent):
@@ -36,7 +39,7 @@ LauncherModel::LauncherModel(QObject *parent):
3639 m_dbusIface(new DBusInterface(this)),
3740 m_asAdapter(new ASAdapter()),
3841 m_appManager(nullptr),
39− m_ualRegistry(std::make_shared<ubuntu::app_launch::Registry>())
42+ m_ualRegistry(std::make_shared<ual::Registry>())
4043{
4144 connect(m_dbusIface, &DBusInterface::countChanged, this, &LauncherModel::countChanged);
4245 connect(m_dbusIface, &DBusInterface::countVisibleChanged, this, &LauncherModel::countVisibleChanged);
@@ -157,15 +160,15 @@ void LauncherModel::pin(const QString &appId, int index)
157160 }
158161
159162 auto appInfo = getApplicationInfo(appId);
160− if (!appInfo) {
163+ if (!appInfo.valid) {
161164 qWarning() << "Can't pin application, appId not found:" << appId;
162165 return;
163166 }
164167
165168 beginInsertRows(QModelIndex(), index, index);
166169 LauncherItem *item = new LauncherItem(appId,
167− QString::fromStdString(appInfo->info()->name()),
168− QString::fromStdString(appInfo->info()->iconPath()),
170+ appInfo.name,
171+ appInfo.icon,
169172 this);
170173 item->setPinned(true);
171174 m_list.insert(index, item);
@@ -332,22 +335,30 @@ int LauncherModel::findApplication(const QString &appId)
332335 return -1;
333336}
334337
335−std::shared_ptr<ubuntu::app_launch::Application> LauncherModel::getApplicationInfo(const QString &appId)
338+LauncherModel::AppInfo LauncherModel::getApplicationInfo(const QString &appId)
336339{
337− auto ualAppId = ubuntu::app_launch::AppID::find(appId.toStdString());
340+ AppInfo info;
341+
342+ ual::AppID ualAppId = ual::AppID::find(appId.toStdString());
338343 if (ualAppId.empty()) {
339− return nullptr;
344+ return info;
340345 }
341346
347+ std::shared_ptr<ual::Application> ualApp;
342348 try
343349 {
344− return ubuntu::app_launch::Application::create(ualAppId, m_ualRegistry);
350+ ualApp = ual::Application::create(ualAppId, m_ualRegistry);
345351 }
346352 catch (std::runtime_error &e)
347353 {
348354 qWarning() << "Couldn't find application info for" << appId << "-" << e.what();
349− return nullptr;
355+ return info;
350356 }
357+
358+ info.valid = true;
359+ info.name = QString::fromStdString(ualApp->info()->name());
360+ info.icon = QString::fromStdString(ualApp->info()->iconPath());
361+ return info;
351362}
352363
353364void LauncherModel::progressChanged(const QString &appId, int progress)
@@ -398,10 +409,10 @@ void LauncherModel::countVisibleChanged(const QString &appId, bool countVisible)
398409 } else {
399410 // Need to create a new LauncherItem and show the highlight
400411 auto appInfo = getApplicationInfo(appId);
401− if (countVisible && appInfo) {
412+ if (countVisible && appInfo.valid) {
402413 LauncherItem *item = new LauncherItem(appId,
403− QString::fromStdString(appInfo->info()->name()),
404− QString::fromStdString(appInfo->info()->iconPath()),
414+ appInfo.name,
415+ appInfo.icon,
405416 this);
406417 item->setCountVisible(true);
407418 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
@@ -418,7 +429,7 @@ void LauncherModel::refresh()
418429 QList<LauncherItem*> toBeRemoved;
419430 Q_FOREACH (LauncherItem* item, m_list) {
420431 auto appInfo = getApplicationInfo(item->appId());
421− if (!appInfo) {
432+ if (!appInfo.valid) {
422433 // Application no longer available => drop it!
423434 toBeRemoved << item;
424435 } else if (!m_settings->storedApplications().contains(item->appId())) {
@@ -426,19 +437,19 @@ void LauncherModel::refresh()
426437 toBeRemoved << item;
427438 } else {
428439 int idx = m_list.indexOf(item);
429− item->setName(QString::fromStdString(appInfo->info()->name()));
440+ item->setName(appInfo.name);
430441 item->setPinned(item->pinned()); // update pinned text if needed
431442 item->setRunning(item->running());
432443 Q_EMIT dataChanged(index(idx), index(idx), {RoleName, RoleRunning});
433444
434445 const QString oldIcon = item->icon();
435− if (oldIcon == QString::fromStdString(appInfo->info()->iconPath())) { // same icon file, perhaps different contents, simulate changing the icon name to force reload
446+ if (oldIcon == appInfo.icon) { // same icon file, perhaps different contents, simulate changing the icon name to force reload
436447 item->setIcon(QString());
437448 Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
438449 }
439450
440451 // now set the icon for real
441− item->setIcon(QString::fromStdString(appInfo->info()->iconPath()));
452+ item->setIcon(appInfo.icon);
442453 Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
443454 }
444455 }
@@ -470,13 +481,13 @@ void LauncherModel::refresh()
470481 // Need to add it. Just add it into the addedIndex to keep same ordering as the list
471482 // in the settings.
472483 auto appInfo = getApplicationInfo(entry);
473− if (!appInfo) {
484+ if (!appInfo.valid) {
474485 continue;
475486 }
476487
477488 LauncherItem *item = new LauncherItem(entry,
478− QString::fromStdString(appInfo->info()->name()),
479− QString::fromStdString(appInfo->info()->iconPath()),
489+ appInfo.name,
490+ appInfo.icon,
480491 this);
481492 item->setPinned(true);
482493 beginInsertRows(QModelIndex(), addedIndex, addedIndex);