on bionic help sign in
unity8/plugins/Unity/Launcher/ualwrapper.cpp
83 lines 2.9 kB history raw
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include <QDebug>
19#include "ualwrapper.h"
21#include <ubuntu-app-launch/registry.h>
22using namespace ubuntu::app_launch;
24UalWrapper::UalWrapper(QObject *parent):
25 QObject(parent)
27 Registry::appAdded().connect([this](const std::shared_ptr<Application>&app) {
28 Q_EMIT appAdded(QString::fromStdString(app->appId()));
29 });
30 Registry::appRemoved().connect([this](const AppID &appId) {
31 Q_EMIT appRemoved(QString::fromStdString(appId));
32 });
33 Registry::appInfoUpdated().connect([this](const std::shared_ptr<Application>&app){
34 Q_EMIT appInfoChanged(QString::fromStdString(app->appId()));
35 });
38QStringList UalWrapper::installedApps()
40 QStringList appIds;
41 try {
42 for (const std::shared_ptr<Application> &app : Registry::installedApps()) {
43 if (!app->appId().package.value().empty()) {
44 appIds << QString::fromStdString(app->appId().package.value() + "_" + app->appId().appname.value());
45 } else {
46 appIds << QString::fromStdString(app->appId().appname);
47 }
48 }
49 } catch (const std::runtime_error &e) {
50 qWarning() << "ubuntu-app-launch threw an exception listing apps:" << e.what();
51 }
53 return appIds;
56UalWrapper::AppInfo UalWrapper::getApplicationInfo(const QString &appId)
58 AppInfo info;
60 try {
61 AppID ualAppId = AppID::find(appId.toStdString());
62 if (ualAppId.empty()) {
63 qWarning() << "Empty ualAppId result for" << appId;
64 return info;
65 }
67 std::shared_ptr<Application> ualApp;
68 ualApp = Application::create(ualAppId, Registry::getDefault());
70 info.appId = appId;
71 info.name = QString::fromStdString(ualApp->info()->name());
72 info.icon = QString::fromStdString(ualApp->info()->iconPath());
73 for (const std::string &keyword : ualApp->info()->keywords().value()) {
74 info.keywords << QString::fromStdString(keyword);
75 }
76 info.popularity = ualApp->info()->popularity();
77 info.valid = true;
78 } catch (const std::runtime_error &e) {
79 qWarning() << "ubuntu-app-launch threw an exception getting app info for appId:" << appId << ":" << e.what();
80 }
82 return info;