on xenial help sign in
Reduce some of the namespacing and stdString conversions
0399ec1Michael Terry
plugins/Unity/Launcher/launchermodel.cpp+30−19
@@ -20,6 +20,7 @@
20#include "dbusinterface.h"
20#include "dbusinterface.h"
21#include "asadapter.h"
21#include "asadapter.h"
22
22
23+#include <ubuntu-app-launch/appid.h>
23#include <ubuntu-app-launch/application.h>
24#include <ubuntu-app-launch/application.h>
24#include <ubuntu-app-launch/registry.h>
25#include <ubuntu-app-launch/registry.h>
25#include <unity/shell/application/ApplicationInfoInterface.h>
26#include <unity/shell/application/ApplicationInfoInterface.h>
@@ -28,6 +29,8 @@
28#include <QDesktopServices>
29#include <QDesktopServices>
29#include <QDebug>
30#include <QDebug>
30
31
32+namespace ual = ubuntu::app_launch;
33+
31using namespace unity::shell::application;
34using namespace unity::shell::application;
32
35
33LauncherModel::LauncherModel(QObject *parent):
36LauncherModel::LauncherModel(QObject *parent):
@@ -36,7 +39,7 @@ LauncherModel::LauncherModel(QObject *parent):
36 m_dbusIface(new DBusInterface(this)),
39 m_dbusIface(new DBusInterface(this)),
37 m_asAdapter(new ASAdapter()),
40 m_asAdapter(new ASAdapter()),
38 m_appManager(nullptr),
41 m_appManager(nullptr),
39− m_ualRegistry(std::make_shared<ubuntu::app_launch::Registry>())
42+ m_ualRegistry(std::make_shared<ual::Registry>())
40{
43{
41 connect(m_dbusIface, &DBusInterface::countChanged, this, &LauncherModel::countChanged);
44 connect(m_dbusIface, &DBusInterface::countChanged, this, &LauncherModel::countChanged);
42 connect(m_dbusIface, &DBusInterface::countVisibleChanged, this, &LauncherModel::countVisibleChanged);
45 connect(m_dbusIface, &DBusInterface::countVisibleChanged, this, &LauncherModel::countVisibleChanged);
@@ -157,15 +160,15 @@ void LauncherModel::pin(const QString &appId, int index)
157 }
160 }
158
161
159 auto appInfo = getApplicationInfo(appId);
162 auto appInfo = getApplicationInfo(appId);
160− if (!appInfo) {
163+ if (!appInfo.valid) {
161 qWarning() << "Can't pin application, appId not found:" << appId;
164 qWarning() << "Can't pin application, appId not found:" << appId;
162 return;
165 return;
163 }
166 }
164
167
165 beginInsertRows(QModelIndex(), index, index);
168 beginInsertRows(QModelIndex(), index, index);
166 LauncherItem *item = new LauncherItem(appId,
169 LauncherItem *item = new LauncherItem(appId,
167− QString::fromStdString(appInfo->info()->name()),
170+ appInfo.name,
168− QString::fromStdString(appInfo->info()->iconPath()),
171+ appInfo.icon,
169 this);
172 this);
170 item->setPinned(true);
173 item->setPinned(true);
171 m_list.insert(index, item);
174 m_list.insert(index, item);
@@ -332,22 +335,30 @@ int LauncherModel::findApplication(const QString &appId)
332 return -1;
335 return -1;
333}
336}
334
337
335−std::shared_ptr<ubuntu::app_launch::Application> LauncherModel::getApplicationInfo(const QString &appId)
338+LauncherModel::AppInfo LauncherModel::getApplicationInfo(const QString &appId)
336{
339{
340+ AppInfo info;
341+
337− auto ualAppId = ubuntu::app_launch::AppID::find(appId.toStdString());
342+ ual::AppID ualAppId = ual::AppID::find(appId.toStdString());
338 if (ualAppId.empty()) {
343 if (ualAppId.empty()) {
339− return nullptr;
344+ return info;
340 }
345 }
341
346
347+ std::shared_ptr<ual::Application> ualApp;
342 try
348 try
343 {
349 {
344− return ubuntu::app_launch::Application::create(ualAppId, m_ualRegistry);
350+ ualApp = ual::Application::create(ualAppId, m_ualRegistry);
345 }
351 }
346 catch (std::runtime_error &e)
352 catch (std::runtime_error &e)
347 {
353 {
348 qWarning() << "Couldn't find application info for" << appId << "-" << e.what();
354 qWarning() << "Couldn't find application info for" << appId << "-" << e.what();
349− return nullptr;
355+ return info;
350 }
356 }
357+
358+ info.valid = true;
359+ info.name = QString::fromStdString(ualApp->info()->name());
360+ info.icon = QString::fromStdString(ualApp->info()->iconPath());
361+ return info;
351}
362}
352
363
353void LauncherModel::progressChanged(const QString &appId, int progress)
364void LauncherModel::progressChanged(const QString &appId, int progress)
@@ -398,10 +409,10 @@ void LauncherModel::countVisibleChanged(const QString &appId, bool countVisible)
398 } else {
409 } else {
399 // Need to create a new LauncherItem and show the highlight
410 // Need to create a new LauncherItem and show the highlight
400 auto appInfo = getApplicationInfo(appId);
411 auto appInfo = getApplicationInfo(appId);
401− if (countVisible && appInfo) {
412+ if (countVisible && appInfo.valid) {
402 LauncherItem *item = new LauncherItem(appId,
413 LauncherItem *item = new LauncherItem(appId,
403− QString::fromStdString(appInfo->info()->name()),
414+ appInfo.name,
404− QString::fromStdString(appInfo->info()->iconPath()),
415+ appInfo.icon,
405 this);
416 this);
406 item->setCountVisible(true);
417 item->setCountVisible(true);
407 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
418 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
@@ -418,7 +429,7 @@ void LauncherModel::refresh()
418 QList<LauncherItem*> toBeRemoved;
429 QList<LauncherItem*> toBeRemoved;
419 Q_FOREACH (LauncherItem* item, m_list) {
430 Q_FOREACH (LauncherItem* item, m_list) {
420 auto appInfo = getApplicationInfo(item->appId());
431 auto appInfo = getApplicationInfo(item->appId());
421− if (!appInfo) {
432+ if (!appInfo.valid) {
422 // Application no longer available => drop it!
433 // Application no longer available => drop it!
423 toBeRemoved << item;
434 toBeRemoved << item;
424 } else if (!m_settings->storedApplications().contains(item->appId())) {
435 } else if (!m_settings->storedApplications().contains(item->appId())) {
@@ -426,19 +437,19 @@ void LauncherModel::refresh()
426 toBeRemoved << item;
437 toBeRemoved << item;
427 } else {
438 } else {
428 int idx = m_list.indexOf(item);
439 int idx = m_list.indexOf(item);
429− item->setName(QString::fromStdString(appInfo->info()->name()));
440+ item->setName(appInfo.name);
430 item->setPinned(item->pinned()); // update pinned text if needed
441 item->setPinned(item->pinned()); // update pinned text if needed
431 item->setRunning(item->running());
442 item->setRunning(item->running());
432 Q_EMIT dataChanged(index(idx), index(idx), {RoleName, RoleRunning});
443 Q_EMIT dataChanged(index(idx), index(idx), {RoleName, RoleRunning});
433
444
434 const QString oldIcon = item->icon();
445 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
436 item->setIcon(QString());
447 item->setIcon(QString());
437 Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
448 Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
438 }
449 }
439
450
440 // now set the icon for real
451 // now set the icon for real
441− item->setIcon(QString::fromStdString(appInfo->info()->iconPath()));
452+ item->setIcon(appInfo.icon);
442 Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
453 Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
443 }
454 }
444 }
455 }
@@ -470,13 +481,13 @@ void LauncherModel::refresh()
470 // Need to add it. Just add it into the addedIndex to keep same ordering as the list
481 // Need to add it. Just add it into the addedIndex to keep same ordering as the list
471 // in the settings.
482 // in the settings.
472 auto appInfo = getApplicationInfo(entry);
483 auto appInfo = getApplicationInfo(entry);
473− if (!appInfo) {
484+ if (!appInfo.valid) {
474 continue;
485 continue;
475 }
486 }
476
487
477 LauncherItem *item = new LauncherItem(entry,
488 LauncherItem *item = new LauncherItem(entry,
478− QString::fromStdString(appInfo->info()->name()),
489+ appInfo.name,
479− QString::fromStdString(appInfo->info()->iconPath()),
490+ appInfo.icon,
480 this);
491 this);
481 item->setPinned(true);
492 item->setPinned(true);
482 beginInsertRows(QModelIndex(), addedIndex, addedIndex);
493 beginInsertRows(QModelIndex(), addedIndex, addedIndex);
plugins/Unity/Launcher/launchermodel.h+7−2
@@ -29,7 +29,6 @@ class ASAdapter;
29
29
30namespace ubuntu {
30namespace ubuntu {
31 namespace app_launch {
31 namespace app_launch {
32− class Application;
33 class Registry;
32 class Registry;
34 }
33 }
35}
34}
@@ -73,7 +72,13 @@ private:
73 void storeAppList();
72 void storeAppList();
74
73
75 void unpin(const QString &appId);
74 void unpin(const QString &appId);
75+
76+ struct AppInfo {
77+ bool valid = false;
78+ QString name;
79+ QString icon;
80+ };
76− std::shared_ptr<ubuntu::app_launch::Application> getApplicationInfo(const QString &appId);
81+ AppInfo getApplicationInfo(const QString &appId);
77
82
78private Q_SLOTS:
83private Q_SLOTS:
79 void countChanged(const QString &appId, int count);
84 void countChanged(const QString &appId, int count);