~townsend/ubuntu-app-launch/remove-xmir-helpers

« back to all changes in this revision

Viewing changes to libubuntu-app-launch/app-store-libertine.cpp

  • Committer: Chris Townsend
  • Date: 2017-03-24 13:06:32 UTC
  • mfrom: (269.1.38 ubuntu-app-launch)
  • Revision ID: christopher.townsend@canonical.com-20170324130632-n52ashmczuy0vy4y
Merge lp:ubuntu-app-launch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2017 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 *     Ted Gould <ted.gould@canonical.com>
 
18
 */
 
19
 
 
20
#include "app-store-libertine.h"
 
21
#include "application-impl-libertine.h"
 
22
#include "string-util.h"
 
23
 
 
24
#include "libertine.h"
 
25
 
 
26
namespace ubuntu
 
27
{
 
28
namespace app_launch
 
29
{
 
30
namespace app_store
 
31
{
 
32
 
 
33
Libertine::Libertine()
 
34
{
 
35
}
 
36
 
 
37
Libertine::~Libertine()
 
38
{
 
39
}
 
40
 
 
41
/** Checks the AppID by making sure the version is "0.0" and then
 
42
    calling verifyAppname() to check the rest.
 
43
 
 
44
    \param appid AppID to check
 
45
    \param registry persistent connections to use
 
46
*/
 
47
bool Libertine::hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry)
 
48
{
 
49
    try
 
50
    {
 
51
        if (appid.version.value() != "0.0")
 
52
        {
 
53
            return false;
 
54
        }
 
55
 
 
56
        return verifyAppname(appid.package, appid.appname, registry);
 
57
    }
 
58
    catch (std::runtime_error& e)
 
59
    {
 
60
        return false;
 
61
    }
 
62
}
 
63
 
 
64
/** Verify a package name by getting the list of containers from
 
65
    liblibertine and ensuring it is in that list.
 
66
 
 
67
    \param package Container name
 
68
    \param registry persistent connections to use
 
69
*/
 
70
bool Libertine::verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry)
 
71
{
 
72
    auto containers = unique_gcharv(libertine_list_containers());
 
73
 
 
74
    for (int i = 0; containers.get()[i] != nullptr; i++)
 
75
    {
 
76
        auto container = containers.get()[i];
 
77
        if (container == package.value())
 
78
        {
 
79
            return true;
 
80
        }
 
81
    }
 
82
 
 
83
    return false;
 
84
}
 
85
 
 
86
/** Gets the list of applications from the container using liblibertine
 
87
    and see if @appname is in that list.
 
88
 
 
89
    \param package Container name
 
90
    \param appname Application name to look for
 
91
    \param registry persistent connections to use
 
92
*/
 
93
bool Libertine::verifyAppname(const AppID::Package& package,
 
94
                              const AppID::AppName& appname,
 
95
                              const std::shared_ptr<Registry>& registry)
 
96
{
 
97
    auto apps = unique_gcharv(libertine_list_apps_for_container(package.value().c_str()));
 
98
 
 
99
    for (int i = 0; apps.get()[i] != nullptr; i++)
 
100
    {
 
101
        auto appid = AppID::parse(apps.get()[i]);
 
102
        if (appid.appname.value() == appname.value())
 
103
        {
 
104
            return true;
 
105
        }
 
106
    }
 
107
 
 
108
    return false;
 
109
}
 
110
 
 
111
/** We don't really have a way to implement this for Libertine, any
 
112
    search wouldn't really make sense. We just throw an error.
 
113
 
 
114
    \param package Container name
 
115
    \param card Application search paths
 
116
    \param registry persistent connections to use
 
117
*/
 
118
AppID::AppName Libertine::findAppname(const AppID::Package& package,
 
119
                                      AppID::ApplicationWildcard card,
 
120
                                      const std::shared_ptr<Registry>& registry)
 
121
{
 
122
    throw std::runtime_error("Legacy apps can't be discovered by package");
 
123
}
 
124
 
 
125
/** Function to return "0.0"
 
126
 
 
127
    \param package Container name (unused)
 
128
    \param appname Application name (unused)
 
129
    \param registry persistent connections to use (unused)
 
130
*/
 
131
AppID::Version Libertine::findVersion(const AppID::Package& package,
 
132
                                      const AppID::AppName& appname,
 
133
                                      const std::shared_ptr<Registry>& registry)
 
134
{
 
135
    return AppID::Version::from_raw("0.0");
 
136
}
 
137
 
 
138
std::list<std::shared_ptr<Application>> Libertine::list(const std::shared_ptr<Registry>& registry)
 
139
{
 
140
    std::list<std::shared_ptr<Application>> applist;
 
141
 
 
142
    auto containers = unique_gcharv(libertine_list_containers());
 
143
 
 
144
    for (int i = 0; containers.get()[i] != nullptr; i++)
 
145
    {
 
146
        auto container = containers.get()[i];
 
147
        auto apps = unique_gcharv(libertine_list_apps_for_container(container));
 
148
 
 
149
        for (int j = 0; apps.get()[j] != nullptr; j++)
 
150
        {
 
151
            try
 
152
            {
 
153
                auto appid = AppID::parse(apps.get()[j]);
 
154
                auto sapp = std::make_shared<app_impls::Libertine>(appid.package, appid.appname, registry);
 
155
                applist.emplace_back(sapp);
 
156
            }
 
157
            catch (std::runtime_error& e)
 
158
            {
 
159
                g_debug("Unable to create application for libertine appname '%s': %s", apps.get()[j], e.what());
 
160
            }
 
161
        }
 
162
    }
 
163
 
 
164
    return applist;
 
165
}
 
166
 
 
167
std::shared_ptr<app_impls::Base> Libertine::create(const AppID& appid, const std::shared_ptr<Registry>& registry)
 
168
{
 
169
    return std::make_shared<app_impls::Libertine>(appid.package, appid.appname, registry);
 
170
}
 
171
 
 
172
}  // namespace app_store
 
173
}  // namespace app_launch
 
174
}  // namespace ubuntu