~ted/ubuntu-app-launch/application-actions

« back to all changes in this revision

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

  • Committer: CI Train Bot
  • Author(s): Larry Price
  • Date: 2016-05-04 20:12:30 UTC
  • mfrom: (144.5.166 ual-finding-icons)
  • Revision ID: ci-train-bot@canonical.com-20160504201230-sd0l24oqgvztcfly
Update icon search for non-click applications to search the hicolor theme directory for appropriate icons. Fixes: #1576722
Approved by: Ted Gould

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
namespace app_impls
28
28
{
29
29
 
30
 
std::shared_ptr<GKeyFile> keyfileForApp(const AppID::AppName& name);
 
30
std::pair<std::string, std::shared_ptr<GKeyFile>> keyfileForApp(const AppID::AppName& name);
31
31
 
32
32
void clear_keyfile(GKeyFile* keyfile)
33
33
{
38
38
}
39
39
 
40
40
Legacy::Legacy(const AppID::AppName& appname,
 
41
               const std::string& basedir,
41
42
               const std::shared_ptr<GKeyFile>& keyfile,
42
43
               const std::shared_ptr<Registry>& registry)
43
44
    : Base(registry)
44
45
    , _appname(appname)
 
46
    , _basedir(basedir)
45
47
    , _keyfile(keyfile)
46
48
{
47
49
    if (!_keyfile)
49
51
}
50
52
 
51
53
Legacy::Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry)
52
 
    : Legacy(appname, keyfileForApp(appname), registry)
 
54
    : Base(registry)
 
55
    , _appname(appname)
53
56
{
 
57
    std::tie(_basedir, _keyfile) = keyfileForApp(appname);
 
58
 
 
59
    if (!_keyfile)
 
60
        throw std::runtime_error{"Unable to find keyfile for legacy application: " + appname.value()};
54
61
}
55
62
 
56
 
std::shared_ptr<GKeyFile> keyfileForApp(const AppID::AppName& name)
 
63
std::pair<std::string, std::shared_ptr<GKeyFile>> keyfileForApp(const AppID::AppName& name)
57
64
{
58
65
    std::string desktopName = name.value() + ".desktop";
59
 
    auto keyfilecheck = [desktopName](const gchar* dir) -> std::shared_ptr<GKeyFile> {
60
 
        auto fullname = g_build_filename(dir, "applications", desktopName.c_str(), nullptr);
 
66
    auto keyfilecheck = [desktopName](const std::string& dir) -> std::shared_ptr<GKeyFile> {
 
67
        auto fullname = g_build_filename(dir.c_str(), "applications", desktopName.c_str(), nullptr);
61
68
        if (!g_file_test(fullname, G_FILE_TEST_EXISTS))
62
69
        {
63
70
            g_free(fullname);
80
87
        return keyfile;
81
88
    };
82
89
 
83
 
    auto retval = keyfilecheck(g_get_user_data_dir());
 
90
    std::string basedir = g_get_user_data_dir();
 
91
    auto retval = keyfilecheck(basedir);
84
92
 
85
93
    auto systemDirs = g_get_system_data_dirs();
86
94
    for (auto i = 0; !retval && systemDirs[i] != nullptr; i++)
87
95
    {
88
 
        retval = keyfilecheck(systemDirs[i]);
 
96
        basedir = systemDirs[i];
 
97
        retval = keyfilecheck(basedir);
89
98
    }
90
99
 
91
 
    return retval;
 
100
    return std::make_pair(basedir, retval);
92
101
}
93
102
 
94
103
std::shared_ptr<Application::Info> Legacy::info()
95
104
{
96
 
    return std::make_shared<app_info::Desktop>(_keyfile, "/usr/share/icons/");
 
105
    return std::make_shared<app_info::Desktop>(_keyfile, _basedir, _registry, true);
97
106
}
98
107
 
99
108
std::list<std::shared_ptr<Application>> Legacy::list(const std::shared_ptr<Registry>& registry)