Merge lp:~larryprice/ubuntu-app-launch/some-icon-paths-need-merged into lp:ubuntu-app-launch/16.10

Proposed by Larry Price
Status: Rejected
Rejected by: Ted Gould
Proposed branch: lp:~larryprice/ubuntu-app-launch/some-icon-paths-need-merged
Merge into: lp:ubuntu-app-launch/16.10
Diff against target: 104 lines (+75/-1)
2 files modified
libubuntu-app-launch/application-icon-finder.cpp (+59/-1)
tests/application-icon-finder.cpp (+16/-0)
To merge this branch: bzr merge lp:~larryprice/ubuntu-app-launch/some-icon-paths-need-merged
Reviewer Review Type Date Requested Status
Ted Gould (community) Needs Fixing
unity-api-1-bot continuous-integration Needs Fixing
Review via email: mp+298942@code.launchpad.net

Commit message

Some explicit icon paths need to be merged with the base path to find existing icon.

Description of the change

Some explicit icon paths need to be merged with the base path to find existing icon.

In particular, installing supertuxkart in libertine on a device with vivid+overlay will result in an icon path of "/usr/share/pixmaps/supertuxkart_128.png". IconFinder could not find this path because it did not exist on the system `/usr/share/pixmaps/`. The base search path for libertine apps includes `/usr/share` already, so a simple concatenation doesn't work. I've opted to iterate through the base path, figure out where the base path and icon name match, and merge the two together if a file exists at that location.

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:233
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/9/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/228/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/236
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/177
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/177
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/177
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/106
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/106/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/106
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/106/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/106
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/106/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/106/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/106/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/106
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/106/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/106
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/106/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/106
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/106/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/106
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/106/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/9/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

We've discussed this a bit on IRC and it seems a bit more complex than we originally thought. We don't want to match all the way down the path as we don't want an application to be able reference an icon outside of the Libertine container, or the Click package, etc. We do want it to be able do a full reference inside that container.

So to do this it is likely that we'll have to create another string to pass into the Desktop() object that is the contained path for references. This seems like it could have other uses in the future as well. That contained path can then be passed to the icon finder so that it doesn't over extend its search.

review: Needs Fixing

Unmerged revisions

233. By Larry Price

Reverse the merge lookup to be more performant

232. By Larry Price

Take care of more cases

231. By Larry Price

Attempt to prepend basePath to explicit icon names

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntu-app-launch/application-icon-finder.cpp'
2--- libubuntu-app-launch/application-icon-finder.cpp 2016-05-04 19:07:02 +0000
3+++ libubuntu-app-launch/application-icon-finder.cpp 2016-07-01 19:32:30 +0000
4@@ -45,6 +45,60 @@
5 constexpr auto ICON_TYPES = {".png", ".svg", ".xpm"};
6
7 static const std::regex iconSizeDirname = std::regex("^(\\d+)x\\1$");
8+
9+static std::string tryMergeFilePaths(const std::string& parent, const std::string& child)
10+{
11+ auto slashPos = parent.find_last_of('/');
12+ auto prevSlashPos = std::string::npos;
13+ while (slashPos != std::string::npos)
14+ {
15+ if (child.find(parent.substr(slashPos)) == std::string::npos && prevSlashPos != std::string::npos)
16+ {
17+ auto pathWithBase = g_build_filename(parent.substr(0, prevSlashPos).c_str(), child.c_str(), nullptr);
18+
19+ std::string strPathWithBase(pathWithBase);
20+ g_free(pathWithBase);
21+
22+ if (g_file_test(strPathWithBase.c_str(), G_FILE_TEST_EXISTS))
23+ {
24+ return strPathWithBase;
25+ }
26+ break;
27+ }
28+ prevSlashPos = slashPos;
29+ slashPos = parent.find_last_of('/', slashPos - 1);
30+ }
31+ return child;
32+}
33+
34+static std::string tryFindExplicitFile(const std::string& basePath, const std::string& iconName)
35+{
36+ if (g_file_test(iconName.c_str(), G_FILE_TEST_EXISTS))
37+ {
38+ return iconName;
39+ }
40+ else
41+ {
42+ auto pathWithBase = g_build_filename(basePath.c_str(), iconName.c_str(), nullptr);
43+
44+ std::string strPathWithBase(pathWithBase);
45+ g_free(pathWithBase);
46+
47+ if (g_file_test(strPathWithBase.c_str(), G_FILE_TEST_EXISTS))
48+ {
49+ return strPathWithBase;
50+ }
51+ else
52+ {
53+ auto mergedIconName = tryMergeFilePaths(basePath, iconName);
54+ if (mergedIconName != iconName)
55+ {
56+ return mergedIconName;
57+ }
58+ }
59+ }
60+ return "";
61+}
62 } // anonymous namespace
63
64 IconFinder::IconFinder(std::string basePath)
65@@ -58,7 +112,11 @@
66 {
67 if (iconName[0] == '/') // explicit icon path received
68 {
69- return Application::Info::IconPath::from_raw(iconName);
70+ auto explicitIconPath = tryFindExplicitFile(_basePath, iconName);
71+ if (!explicitIconPath.empty())
72+ {
73+ return Application::Info::IconPath::from_raw(explicitIconPath);
74+ }
75 }
76
77 /* Look in each directory slowly decreasing the size until we find
78
79=== modified file 'tests/application-icon-finder.cpp'
80--- tests/application-icon-finder.cpp 2016-05-04 19:07:02 +0000
81+++ tests/application-icon-finder.cpp 2016-07-01 19:32:30 +0000
82@@ -57,6 +57,22 @@
83 finder.find(basePath + "/icons/hicolor/scalable/apps/app.svg").value());
84 }
85
86+TEST(ApplicationIconFinder, ReturnsIconWithPrependedBasePath)
87+{
88+ auto basePath = std::string(CMAKE_SOURCE_DIR) + "/data/usr/share";
89+ IconFinder finder(basePath);
90+ EXPECT_EQ(basePath + "/icons/hicolor/scalable/apps/app.svg",
91+ finder.find("/icons/hicolor/scalable/apps/app.svg").value());
92+}
93+
94+TEST(ApplicationIconFinder, ReturnsIconWithMergedBasePathAndIconName)
95+{
96+ auto basePath = std::string(CMAKE_SOURCE_DIR) + "/data/usr/share";
97+ IconFinder finder(basePath);
98+ EXPECT_EQ(basePath + "/icons/hicolor/scalable/apps/app.svg",
99+ finder.find("/usr/share/icons/hicolor/scalable/apps/app.svg").value());
100+}
101+
102 TEST(ApplicationIconFinder, ReturnsIconFromPixmapAsFallback)
103 {
104 auto basePath = std::string(CMAKE_SOURCE_DIR) + "/data/usr/share";

Subscribers

People subscribed via source and target branches