Merge lp:~dobey/indicator-transfer/fix-dm-desktop into lp:indicator-transfer

Proposed by dobey on 2016-12-02
Status: Merged
Approved by: Pete Woods on 2016-12-05
Approved revision: 47
Merged at revision: 52
Proposed branch: lp:~dobey/indicator-transfer/fix-dm-desktop
Merge into: lp:indicator-transfer
Diff against target: 148 lines (+23/-67)
1 file modified
src/dm-plugin/dm-source.cpp (+23/-67)
To merge this branch: bzr merge lp:~dobey/indicator-transfer/fix-dm-desktop
Reviewer Review Type Date Requested Status
Pete Woods (community) 2016-12-02 Approve on 2016-12-05
unity-api-1-bot continuous-integration Approve on 2016-12-02
Review via email: mp+312375@code.launchpad.net

Commit message

Use UAL C++ API to get app info and launch apps.

Description of the change

This switches to using only the C++ API from UAL for getting the application info and launching apps, in the download-manager plug-in, rather than getting the .desktop file and trying to parse it directly.

This simplifies the code a fair bit, and relies on ubuntu-app-launch filling in the root path to the icon itself.

To post a comment you must log in.
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:47
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-transfer-ci/10/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1226/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1233
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1016
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1016/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1016/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1016
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1016/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1016/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1016
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1016/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1016/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-transfer-ci/10/rebuild

review: Needs Fixing (continuous-integration)
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:47
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-transfer-ci/13/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1230
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1237
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1020
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1020/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1020
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1020/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1020
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1020/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1020
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1020/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1020
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1020/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1020
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1020/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-transfer-ci/13/rebuild

review: Approve (continuous-integration)
Pete Woods (pete-woods) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dm-plugin/dm-source.cpp'
2--- src/dm-plugin/dm-source.cpp 2015-12-16 19:32:40 +0000
3+++ src/dm-plugin/dm-source.cpp 2016-12-02 16:47:47 +0000
4@@ -20,7 +20,7 @@
5 #include <transfer/dm-source.h>
6
7 #include <click.h>
8-#include <ubuntu-app-launch.h>
9+#include <ubuntu-app-launch/registry.h>
10
11 #include <glib/gstdio.h>
12 #include <json-glib/json-glib.h>
13@@ -28,6 +28,9 @@
14
15 #include <algorithm>
16 #include <iostream>
17+#include <memory>
18+
19+namespace ual = ubuntu::app_launch;
20
21 namespace unity {
22 namespace indicator {
23@@ -55,7 +58,8 @@
24 const std::string& ccad_path):
25 m_bus(G_DBUS_CONNECTION(g_object_ref(connection))),
26 m_cancellable(g_cancellable_new()),
27- m_ccad_path(ccad_path)
28+ m_ccad_path(ccad_path),
29+ m_registry(new ual::Registry())
30 {
31 id = next_unique_id();
32 time_started = time(nullptr);
33@@ -108,22 +112,21 @@
34 void open_app()
35 {
36 // destination app has priority over app_id
37- std::string app_id = download_app_id();
38+ auto app_id = ual::AppID::parse(download_app_id());
39
40 if (app_id.empty() && !m_package_name.empty()) {
41- app_id = std::string(ubuntu_app_launch_triplet_to_app_id(m_package_name.c_str(),
42- "first-listed-app",
43- "current-user-version"));
44+ app_id = ual::AppID::find(m_package_name);
45 }
46
47 if (app_id.empty())
48 {
49- g_warning("Fail to discovery app-id");
50+ g_warning("Failed to discover APP_ID");
51 }
52 else
53 {
54- g_debug("calling ubuntu_app_launch_start_application() for %s", app_id.c_str());
55- ubuntu_app_launch_start_application(app_id.c_str(), nullptr);
56+ g_debug("Launching '%s'", std::string(app_id).c_str());
57+ auto app = ual::Application::create(app_id, m_registry);
58+ app->launch();
59 }
60 }
61
62@@ -582,68 +585,20 @@
63
64 void update_app_info_from_package_name(const std::string &package_name)
65 {
66- std::string app_id = std::string(ubuntu_app_launch_triplet_to_app_id(package_name.c_str(),
67- "first-listed-app",
68- "current-user-version"));
69- if (!app_id.empty())
70- update_app_info_from_app_id(app_id);
71- else
72- g_warning("fail to retrive app-id from package: %s", package_name.c_str());
73+ auto app_id = ual::AppID::find(package_name);
74+ update_app_info_from_app_id(app_id);
75 }
76
77 void update_app_info_from_app_id(const std::string &app_id)
78 {
79- gchar *app_dir;
80- gchar *app_desktop_file;
81-
82- if (!ubuntu_app_launch_application_info(app_id.c_str(), &app_dir, &app_desktop_file))
83- {
84- g_warning("Fail to get app info: %s", app_id.c_str());
85- return;
86- }
87-
88- g_debug("App data: %s : %s", app_dir, app_desktop_file);
89- gchar *full_app_desktop_file = g_build_filename(app_dir, app_desktop_file, nullptr);
90- GKeyFile *app_info = g_key_file_new();
91- GError *error = nullptr;
92-
93- g_debug("Open desktop file: %s", full_app_desktop_file);
94- g_key_file_load_from_file(app_info, full_app_desktop_file, G_KEY_FILE_NONE, &error);
95- if (error)
96- {
97- g_warning("Fail to open desktop info: %s:%s", full_app_desktop_file, error->message);
98- g_free(full_app_desktop_file);
99- g_key_file_free(app_info);
100- g_error_free(error);
101- }
102- else
103- {
104- gchar *icon_name = g_key_file_get_string(app_info, "Desktop Entry", "Icon", &error);
105- if (error == nullptr)
106- {
107-
108- gchar *full_icon_name = g_build_filename(app_dir, icon_name, nullptr);
109- g_debug("App icon: %s", icon_name);
110- g_debug("App full icon name: %s", full_icon_name);
111- // check if it is full path icon or a themed one
112- if (g_file_test(full_icon_name, G_FILE_TEST_EXISTS))
113- set_icon(full_icon_name);
114- else
115- set_icon(icon_name);
116- g_free(full_icon_name);
117- }
118- else
119- {
120- g_warning("Fail to retrive icon:", error->message);
121- g_error_free(error);
122- }
123- g_free(icon_name);
124- }
125-
126- g_key_file_free(app_info);
127- g_free(full_app_desktop_file);
128- g_free(app_dir);
129- g_free(app_desktop_file);
130+ try {
131+ auto app = ual::Application::create(ual::AppID::parse(app_id), m_registry);
132+ auto info = app->info();
133+ std::string iconPath{info->iconPath()};
134+ set_icon(iconPath.c_str());
135+ } catch (const std::exception& e) {
136+ g_warning("Unable to get icon for '%s': %s", app_id.c_str(), e.what());
137+ }
138 }
139
140 /***
141@@ -691,6 +646,7 @@
142 std::string m_destination_app;
143 std::string m_package_name;
144 const std::string m_ccad_path;
145+ std::shared_ptr<ual::Registry> m_registry;
146 };
147
148 } // anonymous namespace

Subscribers

People subscribed via source and target branches