~ted/ubuntu-app-launch/snappy-backend-no-snap

« back to all changes in this revision

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

Updating to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
179
179
 
180
180
AppID::Version manifestVersion(const std::shared_ptr<JsonObject>& manifest)
181
181
{
182
 
    auto cstr = json_object_get_string_member(manifest.get(), "version");
183
 
 
184
 
    if (cstr == nullptr)
 
182
    const gchar* cstr = nullptr;
 
183
    if (!json_object_has_member(manifest.get(), "version") ||
 
184
        (cstr = json_object_get_string_member(manifest.get(), "version")) == nullptr)
 
185
    {
185
186
        throw std::runtime_error("Unable to find version number in manifest: " + Registry::Impl::printJson(manifest));
 
187
    }
186
188
 
187
 
    auto cppstr = AppID::Version::from_raw((const gchar*)cstr);
 
189
    auto cppstr = AppID::Version::from_raw(cstr);
188
190
    return cppstr;
189
191
}
190
192
 
191
193
std::list<AppID::AppName> manifestApps(const std::shared_ptr<JsonObject>& manifest)
192
194
{
193
 
    auto hooks = json_object_get_object_member(manifest.get(), "hooks");
194
 
    if (hooks == nullptr)
195
 
        throw std::runtime_error("Manifest for application does not have a 'hooks' field");
 
195
    JsonObject *hooks = nullptr;
 
196
    if (!json_object_has_member(manifest.get(), "hooks") ||
 
197
        (hooks = json_object_get_object_member(manifest.get(), "hooks")) == nullptr)
 
198
    {
 
199
        throw std::runtime_error("Manifest does not have a 'hooks' field");
 
200
    }
196
201
 
197
202
    auto gapps = json_object_get_members(hooks);
198
203
    if (gapps == nullptr)
226
231
        throw std::runtime_error("No manifest for package '" + package + "'");
227
232
    }
228
233
 
229
 
    auto hooks = json_object_get_object_member(manifest.get(), "hooks");
230
 
    if (hooks == nullptr)
 
234
    JsonObject *hooks = nullptr;
 
235
    if (!json_object_has_member(manifest.get(), "hooks") ||
 
236
        (hooks = json_object_get_object_member(manifest.get(), "hooks")) == nullptr)
 
237
    {
231
238
        throw std::runtime_error("Manifest for application '" + app + "' does not have a 'hooks' field: " +
232
239
                                 Registry::Impl::printJson(manifest));
 
240
    }
233
241
 
234
242
    auto gapps = json_object_get_members(hooks);
235
243
    if (gapps == nullptr)
236
244
        throw std::runtime_error("GLib JSON confusion, please talk to your library vendor");
237
245
 
238
 
    auto hooklist = json_object_get_object_member(hooks, app.c_str());
239
 
    if (hooklist == nullptr)
 
246
    JsonObject *hooklist = nullptr;
 
247
    if (!json_object_has_member(hooks, app.c_str()) ||
 
248
        (hooklist = json_object_get_object_member(hooks, app.c_str())) == nullptr)
 
249
    {
240
250
        throw std::runtime_error("Manifest for does not have an application '" + app + "': " +
241
251
                                 Registry::Impl::printJson(manifest));
 
252
    }
242
253
 
243
254
    auto desktoppath = json_object_get_string_member(hooklist, "desktop");
244
255
    if (desktoppath == nullptr)
277
288
                    {
278
289
                        AppID appid{pkg, appname, manifestVersion(manifest)};
279
290
                        auto app = std::make_shared<Click>(appid, manifest, registry);
280
 
                        applist.push_back(app);
 
291
                        applist.emplace_back(app);
281
292
                    }
282
293
                    catch (std::runtime_error& e)
283
294
                    {