~ted/ubuntu-app-launch/libertine-service-name

« back to all changes in this revision

Viewing changes to libubuntu-app-launch/application-impl-libertine.cpp

  • Committer: Bileto Bot
  • Author(s): Ted Gould
  • Date: 2017-03-21 03:27:29 UTC
  • mfrom: (287.7.19 app-store)
  • Revision ID: ci-train-bot@canonical.com-20170321032729-wedntzv3ehbu6amm
Put all application specific static functions into a single AppStore object

Approved by: Charles Kerr

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
    return {};
144
144
}
145
145
 
146
 
/** Checks the AppID by making sure the version is "0.0" and then
147
 
    calling verifyAppname() to check the rest.
148
 
 
149
 
    \param appid AppID to check
150
 
    \param registry persistent connections to use
151
 
*/
152
 
bool Libertine::hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry)
153
 
{
154
 
    try
155
 
    {
156
 
        if (appid.version.value() != "0.0")
157
 
        {
158
 
            return false;
159
 
        }
160
 
 
161
 
        return verifyAppname(appid.package, appid.appname, registry);
162
 
    }
163
 
    catch (std::runtime_error& e)
164
 
    {
165
 
        return false;
166
 
    }
167
 
}
168
 
 
169
 
/** Verify a package name by getting the list of containers from
170
 
    liblibertine and ensuring it is in that list.
171
 
 
172
 
    \param package Container name
173
 
    \param registry persistent connections to use
174
 
*/
175
 
bool Libertine::verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry)
176
 
{
177
 
    auto containers = std::shared_ptr<gchar*>(libertine_list_containers(), g_strfreev);
178
 
 
179
 
    for (int i = 0; containers.get()[i] != nullptr; i++)
180
 
    {
181
 
        auto container = containers.get()[i];
182
 
        if (container == package.value())
183
 
        {
184
 
            return true;
185
 
        }
186
 
    }
187
 
 
188
 
    return false;
189
 
}
190
 
 
191
 
/** Gets the list of applications from the container using liblibertine
192
 
    and see if @appname is in that list.
193
 
 
194
 
    \param package Container name
195
 
    \param appname Application name to look for
196
 
    \param registry persistent connections to use
197
 
*/
198
 
bool Libertine::verifyAppname(const AppID::Package& package,
199
 
                              const AppID::AppName& appname,
200
 
                              const std::shared_ptr<Registry>& registry)
201
 
{
202
 
    auto apps = std::shared_ptr<gchar*>(libertine_list_apps_for_container(package.value().c_str()), g_strfreev);
203
 
 
204
 
    for (int i = 0; apps.get()[i] != nullptr; i++)
205
 
    {
206
 
        auto appid = AppID::parse(apps.get()[i]);
207
 
        if (appid.appname.value() == appname.value())
208
 
        {
209
 
            return true;
210
 
        }
211
 
    }
212
 
 
213
 
    return false;
214
 
}
215
 
 
216
 
/** We don't really have a way to implement this for Libertine, any
217
 
    search wouldn't really make sense. We just throw an error.
218
 
 
219
 
    \param package Container name
220
 
    \param card Application search paths
221
 
    \param registry persistent connections to use
222
 
*/
223
 
AppID::AppName Libertine::findAppname(const AppID::Package& package,
224
 
                                      AppID::ApplicationWildcard card,
225
 
                                      const std::shared_ptr<Registry>& registry)
226
 
{
227
 
    throw std::runtime_error("Legacy apps can't be discovered by package");
228
 
}
229
 
 
230
 
/** Function to return "0.0"
231
 
 
232
 
    \param package Container name (unused)
233
 
    \param appname Application name (unused)
234
 
    \param registry persistent connections to use (unused)
235
 
*/
236
 
AppID::Version Libertine::findVersion(const AppID::Package& package,
237
 
                                      const AppID::AppName& appname,
238
 
                                      const std::shared_ptr<Registry>& registry)
239
 
{
240
 
    return AppID::Version::from_raw("0.0");
241
 
}
242
 
 
243
 
std::list<std::shared_ptr<Application>> Libertine::list(const std::shared_ptr<Registry>& registry)
244
 
{
245
 
    std::list<std::shared_ptr<Application>> applist;
246
 
 
247
 
    auto containers = std::shared_ptr<gchar*>(libertine_list_containers(), g_strfreev);
248
 
 
249
 
    for (int i = 0; containers.get()[i] != nullptr; i++)
250
 
    {
251
 
        auto container = containers.get()[i];
252
 
        auto apps = std::shared_ptr<gchar*>(libertine_list_apps_for_container(container), g_strfreev);
253
 
 
254
 
        for (int j = 0; apps.get()[j] != nullptr; j++)
255
 
        {
256
 
            try
257
 
            {
258
 
                auto appid = AppID::parse(apps.get()[j]);
259
 
                auto sapp = std::make_shared<Libertine>(appid.package, appid.appname, registry);
260
 
                applist.emplace_back(sapp);
261
 
            }
262
 
            catch (std::runtime_error& e)
263
 
            {
264
 
                g_debug("Unable to create application for libertine appname '%s': %s", apps.get()[j], e.what());
265
 
            }
266
 
        }
267
 
    }
268
 
 
269
 
    return applist;
270
 
}
271
 
 
272
146
std::shared_ptr<Application::Info> Libertine::info()
273
147
{
274
148
    return appinfo_;
337
211
    return _registry->impl->jobs->existing(appId(), "application-legacy", instanceid, std::vector<Application::URL>{});
338
212
}
339
213
 
340
 
std::shared_ptr<info_watcher::Base> Libertine::createInfoWatcher(const std::shared_ptr<Registry>& reg)
341
 
{
342
 
    return {};
343
 
}
344
 
 
345
214
}  // namespace app_impls
346
215
}  // namespace app_launch
347
216
}  // namespace ubuntu