~ci-train-bot/ubuntu-app-launch/ubuntu-app-launch-ubuntu-zesty-2577

« back to all changes in this revision

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

  • Committer: Bileto Bot
  • Author(s): Pete Woods
  • Date: 2017-03-21 03:28:14 UTC
  • mfrom: (249.8.2 trunk)
  • Revision ID: ci-train-bot@canonical.com-20170321032814-o6mie6u2ijpkly5u
Switch to reference counted memory management in all c++ code

- Depends on utilities from unity-api
- Add DBus and G signal management utilities
- Add gchar* and gchar** wrappers

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "application-impl-legacy.h"
21
21
#include "application-info-desktop.h"
22
22
#include "registry-impl.h"
 
23
#include "string-util.h"
23
24
 
24
25
#include <regex>
 
26
#include <unity/util/GlibMemory.h>
 
27
 
 
28
using namespace unity::util;
25
29
 
26
30
namespace ubuntu
27
31
{
89
93
    auto desktopName = name.value() + ".desktop";
90
94
    std::string desktopPath;
91
95
    auto keyfilecheck = [desktopName, &desktopPath](const std::string& dir) -> std::shared_ptr<GKeyFile> {
92
 
        auto fullname = g_build_filename(dir.c_str(), "applications", desktopName.c_str(), nullptr);
93
 
        if (!g_file_test(fullname, G_FILE_TEST_EXISTS))
 
96
        auto fullname = unique_gchar(g_build_filename(dir.c_str(), "applications", desktopName.c_str(), nullptr));
 
97
        if (!g_file_test(fullname.get(), G_FILE_TEST_EXISTS))
94
98
        {
95
 
            g_free(fullname);
96
99
            return {};
97
100
        }
98
 
        desktopPath = fullname;
 
101
        desktopPath = fullname.get();
99
102
 
100
 
        auto keyfile = std::shared_ptr<GKeyFile>(g_key_file_new(), clear_keyfile);
 
103
        auto keyfile = unique_glib(g_key_file_new());
101
104
 
102
105
        GError* error = nullptr;
103
 
        g_key_file_load_from_file(keyfile.get(), fullname, G_KEY_FILE_NONE, &error);
104
 
        g_free(fullname);
 
106
        g_key_file_load_from_file(keyfile.get(), fullname.get(), G_KEY_FILE_NONE, &error);
105
107
 
106
108
        if (error != nullptr)
107
109
        {
186
188
    /* Honor the 'Path' key if it is in the desktop file */
187
189
    if (g_key_file_has_key(_keyfile.get(), "Desktop Entry", "Path", nullptr))
188
190
    {
189
 
        gchar* path = g_key_file_get_string(_keyfile.get(), "Desktop Entry", "Path", nullptr);
190
 
        retval.emplace_back(std::make_pair("APP_DIR", path));
191
 
        g_free(path);
 
191
        auto path = unique_gchar(g_key_file_get_string(_keyfile.get(), "Desktop Entry", "Path", nullptr));
 
192
        retval.emplace_back(std::make_pair("APP_DIR", path.get()));
192
193
    }
193
194
 
194
195
    /* If they've asked for an Apparmor profile, let's use it! */
195
 
    gchar* apparmor = g_key_file_get_string(_keyfile.get(), "Desktop Entry", "X-Ubuntu-AppArmor-Profile", nullptr);
196
 
    if (apparmor != nullptr)
 
196
    auto apparmor =
 
197
        unique_gchar(g_key_file_get_string(_keyfile.get(), "Desktop Entry", "X-Ubuntu-AppArmor-Profile", nullptr));
 
198
    if (apparmor)
197
199
    {
198
 
        retval.emplace_back(std::make_pair("APP_EXEC_POLICY", apparmor));
199
 
        g_free(apparmor);
 
200
        retval.emplace_back(std::make_pair("APP_EXEC_POLICY", apparmor.get()));
200
201
 
201
202
        retval.splice(retval.end(), confinedEnv(_appname, "/usr/share"));
202
203
    }