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

« back to all changes in this revision

Viewing changes to libubuntu-app-launch/application-info-desktop.cpp

Updating to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
    return retval;
128
128
}
129
129
 
 
130
template <typename T>
 
131
auto stringlistFromKeyfile(std::shared_ptr<GKeyFile> keyfile, const gchar* key, const std::string& exceptionText = {})
 
132
    -> T
 
133
{
 
134
    GError* error = nullptr;
 
135
    auto keyval = g_key_file_get_locale_string_list(keyfile.get(), DESKTOP_GROUP, key, nullptr, nullptr, &error);
 
136
 
 
137
    if (error != nullptr)
 
138
    {
 
139
        auto perror = std::shared_ptr<GError>(error, g_error_free);
 
140
        if (!exceptionText.empty())
 
141
        {
 
142
            throw std::runtime_error(exceptionText + perror.get()->message);
 
143
        }
 
144
 
 
145
        return T::from_raw({});
 
146
    }
 
147
 
 
148
    std::vector<std::string> results;
 
149
    for (auto i = 0; keyval[i] != nullptr; ++i)
 
150
    {
 
151
        if (strlen(keyval[i]) != 0)
 
152
        {
 
153
            results.emplace_back(keyval[i]);
 
154
        }
 
155
    }
 
156
    g_strfreev(keyval);
 
157
 
 
158
    return T::from_raw(results);
 
159
}
 
160
 
130
161
bool stringlistFromKeyfileContains(std::shared_ptr<GKeyFile> keyfile,
131
162
                                   const gchar* key,
132
163
                                   const std::string& match,
202
233
        }
203
234
        return fileFromKeyfile<Application::Info::IconPath>(keyfile, basePath, "Icon", "Missing icon for desktop file");
204
235
    }())
 
236
    , _defaultDepartment(
 
237
          stringFromKeyfile<Application::Info::DefaultDepartment>(keyfile, "X-Ubuntu-Default-Department-ID"))
 
238
    , _screenshotPath([keyfile, basePath]() {
 
239
        return fileFromKeyfile<Application::Info::IconPath>(keyfile, basePath, "X-Screenshot");
 
240
    }())
 
241
    , _keywords(stringlistFromKeyfile<Application::Info::Keywords>(keyfile, "Keywords"))
205
242
    , _splashInfo(
206
243
          {stringFromKeyfile<Application::Info::Splash::Title>(keyfile, "X-Ubuntu-Splash-Title"),
207
244
           fileFromKeyfile<Application::Info::Splash::Image>(keyfile, basePath, "X-Ubuntu-Splash-Image"),