2
* Copyright © 2017 Canonical Ltd.
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.
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.
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/>.
17
* Ted Gould <ted.gould@canonical.com>
20
#include "app-store-libertine.h"
21
#include "application-impl-libertine.h"
22
#include "string-util.h"
24
#include "libertine.h"
33
Libertine::Libertine()
37
Libertine::~Libertine()
41
/** Checks the AppID by making sure the version is "0.0" and then
42
calling verifyAppname() to check the rest.
44
\param appid AppID to check
45
\param registry persistent connections to use
47
bool Libertine::hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry)
51
if (appid.version.value() != "0.0")
56
return verifyAppname(appid.package, appid.appname, registry);
58
catch (std::runtime_error& e)
64
/** Verify a package name by getting the list of containers from
65
liblibertine and ensuring it is in that list.
67
\param package Container name
68
\param registry persistent connections to use
70
bool Libertine::verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry)
72
auto containers = unique_gcharv(libertine_list_containers());
74
for (int i = 0; containers.get()[i] != nullptr; i++)
76
auto container = containers.get()[i];
77
if (container == package.value())
86
/** Gets the list of applications from the container using liblibertine
87
and see if @appname is in that list.
89
\param package Container name
90
\param appname Application name to look for
91
\param registry persistent connections to use
93
bool Libertine::verifyAppname(const AppID::Package& package,
94
const AppID::AppName& appname,
95
const std::shared_ptr<Registry>& registry)
97
auto apps = unique_gcharv(libertine_list_apps_for_container(package.value().c_str()));
99
for (int i = 0; apps.get()[i] != nullptr; i++)
101
auto appid = AppID::parse(apps.get()[i]);
102
if (appid.appname.value() == appname.value())
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.
114
\param package Container name
115
\param card Application search paths
116
\param registry persistent connections to use
118
AppID::AppName Libertine::findAppname(const AppID::Package& package,
119
AppID::ApplicationWildcard card,
120
const std::shared_ptr<Registry>& registry)
122
throw std::runtime_error("Legacy apps can't be discovered by package");
125
/** Function to return "0.0"
127
\param package Container name (unused)
128
\param appname Application name (unused)
129
\param registry persistent connections to use (unused)
131
AppID::Version Libertine::findVersion(const AppID::Package& package,
132
const AppID::AppName& appname,
133
const std::shared_ptr<Registry>& registry)
135
return AppID::Version::from_raw("0.0");
138
std::list<std::shared_ptr<Application>> Libertine::list(const std::shared_ptr<Registry>& registry)
140
std::list<std::shared_ptr<Application>> applist;
142
auto containers = unique_gcharv(libertine_list_containers());
144
for (int i = 0; containers.get()[i] != nullptr; i++)
146
auto container = containers.get()[i];
147
auto apps = unique_gcharv(libertine_list_apps_for_container(container));
149
for (int j = 0; apps.get()[j] != nullptr; j++)
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);
157
catch (std::runtime_error& e)
159
g_debug("Unable to create application for libertine appname '%s': %s", apps.get()[j], e.what());
167
std::shared_ptr<app_impls::Base> Libertine::create(const AppID& appid, const std::shared_ptr<Registry>& registry)
169
return std::make_shared<app_impls::Libertine>(appid.package, appid.appname, registry);
172
} // namespace app_store
173
} // namespace app_launch
174
} // namespace ubuntu