Debian Codegraph @

liblomiri-app-launch/app-store-libertine.cpp

raw
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 <[email protected]>
18 */
19
20 #ifdef HAVE_LIBERTINE
21
22 #include "app-store-libertine.h"
23 #include "application-impl-libertine.h"
24 #include "string-util.h"
25
26 #include "libertine.h"
27
28 namespace lomiri
29 {
30 namespace app_launch
31 {
32 namespace app_store
33 {
34
35 Libertine::Libertine(const std::shared_ptr<Registry::Impl>& registry)
36 : Base(registry)
37 {
38 }
39
40 Libertine::~Libertine()
41 {
42 }
43
44 /** Checks the AppID by making sure the version is "0.0" and then
45 calling verifyAppname() to check the rest.
46
47 \param appid AppID to check
48 \param registry persistent connections to use
49 */
50 bool Libertine::hasAppId(const AppID& appid)
51 {
52 try
53 {
54 if (appid.version.value() != "0.0")
55 {
56 return false;
57 }
58
59 return verifyAppname(appid.package, appid.appname);
60 }
61 catch (std::runtime_error& e)
62 {
63 return false;
64 }
65 }
66
67 /** Verify a package name by getting the list of containers from
68 liblibertine and ensuring it is in that list.
69
70 \param package Container name
71 \param registry persistent connections to use
72 */
73 bool Libertine::verifyPackage(const AppID::Package& package)
74 {
75 auto containers = unique_gcharv(libertine_list_containers());
76
77 for (int i = 0; containers.get()[i] != nullptr; i++)
78 {
79 auto container = containers.get()[i];
80 if (container == package.value())
81 {
82 return true;
83 }
84 }
85
86 return false;
87 }
88
89 /** Gets the list of applications from the container using liblibertine
90 and see if @appname is in that list.
91
92 \param package Container name
93 \param appname Application name to look for
94 \param registry persistent connections to use
95 */
96 bool Libertine::verifyAppname(const AppID::Package& package, const AppID::AppName& appname)
97 {
98 auto apps = unique_gcharv(libertine_list_apps_for_container(package.value().c_str()));
99
100 for (int i = 0; apps.get()[i] != nullptr; i++)
101 {
102 auto appid = AppID::parse(apps.get()[i]);
103 if (appid.appname.value() == appname.value())
104 {
105 return true;
106 }
107 }
108
109 return false;
110 }
111
112 /** We don't really have a way to implement this for Libertine, any
113 search wouldn't really make sense. We just throw an error.
114
115 \param package Container name
116 \param card Application search paths
117 \param registry persistent connections to use
118 */
119 AppID::AppName Libertine::findAppname(const AppID::Package& package, AppID::ApplicationWildcard card)
120 {
121 throw std::runtime_error("Legacy apps can't be discovered by package");
122 }
123
124 /** Function to return "0.0"
125
126 \param package Container name (unused)
127 \param appname Application name (unused)
128 \param registry persistent connections to use (unused)
129 */
130 AppID::Version Libertine::findVersion(const AppID::Package& package, const AppID::AppName& appname)
131 {
132 return AppID::Version::from_raw("0.0");
133 }
134
135 std::list<std::shared_ptr<Application>> Libertine::list()
136 {
137 std::list<std::shared_ptr<Application>> applist;
138
139 auto reg = getReg();
140 auto containers = unique_gcharv(libertine_list_containers());
141
142 for (int i = 0; containers.get()[i] != nullptr; i++)
143 {
144 auto container = containers.get()[i];
145 auto apps = unique_gcharv(libertine_list_apps_for_container(container));
146
147 for (int j = 0; apps.get()[j] != nullptr; j++)
148 {
149 try
150 {
151 auto appid = AppID::parse(apps.get()[j]);
152 auto sapp = std::make_shared<app_impls::Libertine>(appid.package, appid.appname, reg);
153 applist.emplace_back(sapp);
154 }
155 catch (std::runtime_error& e)
156 {
157 g_debug("Unable to create application for libertine appname '%s': %s", apps.get()[j], e.what());
158 }
159 }
160 }
161
162 return applist;
163 }
164
165 std::shared_ptr<app_impls::Base> Libertine::create(const AppID& appid)
166 {
167 return std::make_shared<app_impls::Libertine>(appid.package, appid.appname, getReg());
168 }
169
170 } // namespace app_store
171 } // namespace app_launch
172 } // namespace lomiri
173
174 #endif // HAVE_LIBERTINE