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
=== modified file 'src/dm-plugin/dm-source.cpp'
--- src/dm-plugin/dm-source.cpp 2015-12-16 19:32:40 +0000
+++ src/dm-plugin/dm-source.cpp 2016-12-02 16:47:47 +0000
@@ -20,7 +20,7 @@
20#include <transfer/dm-source.h>20#include <transfer/dm-source.h>
2121
22#include <click.h>22#include <click.h>
23#include <ubuntu-app-launch.h>23#include <ubuntu-app-launch/registry.h>
2424
25#include <glib/gstdio.h>25#include <glib/gstdio.h>
26#include <json-glib/json-glib.h>26#include <json-glib/json-glib.h>
@@ -28,6 +28,9 @@
2828
29#include <algorithm>29#include <algorithm>
30#include <iostream>30#include <iostream>
31#include <memory>
32
33namespace ual = ubuntu::app_launch;
3134
32namespace unity {35namespace unity {
33namespace indicator {36namespace indicator {
@@ -55,7 +58,8 @@
55 const std::string& ccad_path):58 const std::string& ccad_path):
56 m_bus(G_DBUS_CONNECTION(g_object_ref(connection))),59 m_bus(G_DBUS_CONNECTION(g_object_ref(connection))),
57 m_cancellable(g_cancellable_new()),60 m_cancellable(g_cancellable_new()),
58 m_ccad_path(ccad_path)61 m_ccad_path(ccad_path),
62 m_registry(new ual::Registry())
59 {63 {
60 id = next_unique_id();64 id = next_unique_id();
61 time_started = time(nullptr);65 time_started = time(nullptr);
@@ -108,22 +112,21 @@
108 void open_app()112 void open_app()
109 {113 {
110 // destination app has priority over app_id114 // destination app has priority over app_id
111 std::string app_id = download_app_id();115 auto app_id = ual::AppID::parse(download_app_id());
112116
113 if (app_id.empty() && !m_package_name.empty()) {117 if (app_id.empty() && !m_package_name.empty()) {
114 app_id = std::string(ubuntu_app_launch_triplet_to_app_id(m_package_name.c_str(),118 app_id = ual::AppID::find(m_package_name);
115 "first-listed-app",
116 "current-user-version"));
117 }119 }
118120
119 if (app_id.empty())121 if (app_id.empty())
120 {122 {
121 g_warning("Fail to discovery app-id");123 g_warning("Failed to discover APP_ID");
122 }124 }
123 else125 else
124 {126 {
125 g_debug("calling ubuntu_app_launch_start_application() for %s", app_id.c_str());127 g_debug("Launching '%s'", std::string(app_id).c_str());
126 ubuntu_app_launch_start_application(app_id.c_str(), nullptr);128 auto app = ual::Application::create(app_id, m_registry);
129 app->launch();
127 }130 }
128 }131 }
129132
@@ -582,68 +585,20 @@
582585
583 void update_app_info_from_package_name(const std::string &package_name)586 void update_app_info_from_package_name(const std::string &package_name)
584 {587 {
585 std::string app_id = std::string(ubuntu_app_launch_triplet_to_app_id(package_name.c_str(),588 auto app_id = ual::AppID::find(package_name);
586 "first-listed-app",589 update_app_info_from_app_id(app_id);
587 "current-user-version"));
588 if (!app_id.empty())
589 update_app_info_from_app_id(app_id);
590 else
591 g_warning("fail to retrive app-id from package: %s", package_name.c_str());
592 }590 }
593591
594 void update_app_info_from_app_id(const std::string &app_id)592 void update_app_info_from_app_id(const std::string &app_id)
595 {593 {
596 gchar *app_dir;594 try {
597 gchar *app_desktop_file;595 auto app = ual::Application::create(ual::AppID::parse(app_id), m_registry);
598596 auto info = app->info();
599 if (!ubuntu_app_launch_application_info(app_id.c_str(), &app_dir, &app_desktop_file))597 std::string iconPath{info->iconPath()};
600 {598 set_icon(iconPath.c_str());
601 g_warning("Fail to get app info: %s", app_id.c_str());599 } catch (const std::exception& e) {
602 return;600 g_warning("Unable to get icon for '%s': %s", app_id.c_str(), e.what());
603 }601 }
604
605 g_debug("App data: %s : %s", app_dir, app_desktop_file);
606 gchar *full_app_desktop_file = g_build_filename(app_dir, app_desktop_file, nullptr);
607 GKeyFile *app_info = g_key_file_new();
608 GError *error = nullptr;
609
610 g_debug("Open desktop file: %s", full_app_desktop_file);
611 g_key_file_load_from_file(app_info, full_app_desktop_file, G_KEY_FILE_NONE, &error);
612 if (error)
613 {
614 g_warning("Fail to open desktop info: %s:%s", full_app_desktop_file, error->message);
615 g_free(full_app_desktop_file);
616 g_key_file_free(app_info);
617 g_error_free(error);
618 }
619 else
620 {
621 gchar *icon_name = g_key_file_get_string(app_info, "Desktop Entry", "Icon", &error);
622 if (error == nullptr)
623 {
624
625 gchar *full_icon_name = g_build_filename(app_dir, icon_name, nullptr);
626 g_debug("App icon: %s", icon_name);
627 g_debug("App full icon name: %s", full_icon_name);
628 // check if it is full path icon or a themed one
629 if (g_file_test(full_icon_name, G_FILE_TEST_EXISTS))
630 set_icon(full_icon_name);
631 else
632 set_icon(icon_name);
633 g_free(full_icon_name);
634 }
635 else
636 {
637 g_warning("Fail to retrive icon:", error->message);
638 g_error_free(error);
639 }
640 g_free(icon_name);
641 }
642
643 g_key_file_free(app_info);
644 g_free(full_app_desktop_file);
645 g_free(app_dir);
646 g_free(app_desktop_file);
647 }602 }
648603
649 /***604 /***
@@ -691,6 +646,7 @@
691 std::string m_destination_app;646 std::string m_destination_app;
692 std::string m_package_name;647 std::string m_package_name;
693 const std::string m_ccad_path;648 const std::string m_ccad_path;
649 std::shared_ptr<ual::Registry> m_registry;
694};650};
695651
696} // anonymous namespace652} // anonymous namespace

Subscribers

People subscribed via source and target branches