~unity-team/unity8/trunk

2659.5.43 by Michael Zanetti
fix issues from review
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
 */
16
2659.5.3 by Michael Zanetti
add missing files
17
#include <QDebug>
18
19
#include "ualwrapper.h"
20
21
#include <ubuntu-app-launch/registry.h>
22
using namespace ubuntu::app_launch;
23
24
UalWrapper::UalWrapper(QObject *parent):
25
    QObject(parent)
26
{
27
28
}
29
30
QStringList UalWrapper::installedApps()
31
{
32
    QStringList appIds;
2659.5.29 by Michael Zanetti
catch more exceptions
33
    try {
34
        for (const std::shared_ptr<Application> &app : Registry::installedApps()) {
2659.5.43 by Michael Zanetti
fix issues from review
35
            if (!app->appId().package.value().empty()) {
36
                appIds << QString::fromStdString(app->appId().package.value() + "_" + app->appId().appname.value());
2659.5.33 by Michael Zanetti
fix issues in ualwrapper
37
            } else {
38
                appIds << QString::fromStdString(app->appId().appname);
39
            }
2659.5.29 by Michael Zanetti
catch more exceptions
40
        }
2659.5.43 by Michael Zanetti
fix issues from review
41
    } catch (const std::runtime_error &e) {
2659.5.29 by Michael Zanetti
catch more exceptions
42
        qWarning() << "ubuntu-all-launch threw an exception listing apps:" << e.what();
2659.5.3 by Michael Zanetti
add missing files
43
    }
2659.5.29 by Michael Zanetti
catch more exceptions
44
2659.5.3 by Michael Zanetti
add missing files
45
    return appIds;
46
}
47
48
UalWrapper::AppInfo UalWrapper::getApplicationInfo(const QString &appId)
49
{
50
    AppInfo info;
51
2659.5.29 by Michael Zanetti
catch more exceptions
52
    try {
53
        AppID ualAppId = AppID::find(appId.toStdString());
54
        if (ualAppId.empty()) {
2659.5.33 by Michael Zanetti
fix issues in ualwrapper
55
            qWarning() << "Empty ualAppId result for" << appId;
2659.5.29 by Michael Zanetti
catch more exceptions
56
            return info;
57
        }
2659.5.3 by Michael Zanetti
add missing files
58
2659.5.29 by Michael Zanetti
catch more exceptions
59
        std::shared_ptr<Application> ualApp;
2659.5.3 by Michael Zanetti
add missing files
60
        ualApp = Application::create(ualAppId, Registry::getDefault());
2659.5.29 by Michael Zanetti
catch more exceptions
61
62
        info.name = QString::fromStdString(ualApp->info()->name());
63
        info.icon = QString::fromStdString(ualApp->info()->iconPath());
2659.5.34 by Michael Zanetti
add support for searching apps by keywords
64
        for (const std::string &keyword : ualApp->info()->keywords().value()) {
65
            info.keywords << QString::fromStdString(keyword);
66
        }
2659.5.33 by Michael Zanetti
fix issues in ualwrapper
67
        info.valid = true;
2659.5.43 by Michael Zanetti
fix issues from review
68
    } catch (const std::runtime_error &e) {
2659.5.29 by Michael Zanetti
catch more exceptions
69
        qWarning() << "ubuntu-app-launch threw an exception getting app info for appId:" << appId << ":" << e.what();
70
    }
71
2659.5.3 by Michael Zanetti
add missing files
72
    return info;
73
}