Merge lp:~larryprice/libertine-scope/update-app-preview into lp:libertine-scope

Proposed by Larry Price
Status: Merged
Approved by: Christopher Townsend
Approved revision: 43
Merged at revision: 32
Proposed branch: lp:~larryprice/libertine-scope/update-app-preview
Merge into: lp:libertine-scope
Diff against target: 413 lines (+277/-20)
11 files modified
libertine-scope/app_description.cpp (+57/-0)
libertine-scope/app_description.h (+41/-0)
libertine-scope/preview.cpp (+21/-14)
libertine-scope/query.cpp (+3/-1)
po/libertine-scope.pot (+1/-1)
tests/CMakeLists.txt (+9/-3)
tests/data/Full.desktop (+13/-0)
tests/data/NoComment.desktop (+7/-0)
tests/test_app_description.cpp (+61/-0)
tests/test_preview.cpp (+64/-0)
tests/test_scope.cpp (+0/-1)
To merge this branch: bzr merge lp:~larryprice/libertine-scope/update-app-preview
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
Christopher Townsend Approve
Review via email: mp+291747@code.launchpad.net

Commit message

Redesign preview pane with reasonably-sized image, title, and description to closer match the store preview.

Description of the change

Redesign preview pane with reasonably-sized image, title, and description to closer match the store preview.

To post a comment you must log in.
40. By Larry Price

use the unity ini file parser instead of rolling our own to parse the desktop file

41. By Larry Price

comparing list ptr to nullptr instead of NULL in preview test

42. By Larry Price

sticking constants into anonymous namespace

Revision history for this message
Christopher Townsend (townsend) wrote :

This looks great to me. I'll wait on Stephen to chime in before we top approve.

review: Approve
Revision history for this message
Stephen M. Webb (bregma) wrote :

Nice, but please back out the unrelated change to tests/scopefixture.h (see inline comment). There is a larger and unrelated change required here.

review: Needs Fixing
43. By Larry Price

Reverting change to scopefixture.h as it is related to a larger change

Revision history for this message
Christopher Townsend (townsend) wrote :

Top approving since Stephen's comment has been taken care of.

Revision history for this message
Stephen M. Webb (bregma) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'libertine-scope/app_description.cpp'
2--- libertine-scope/app_description.cpp 1970-01-01 00:00:00 +0000
3+++ libertine-scope/app_description.cpp 2016-04-15 12:42:14 +0000
4@@ -0,0 +1,57 @@
5+/*
6+ * Copyright 2016 Canonical Ltd.
7+ *
8+ * This program is free software: you can redistribute it and/or modify it under
9+ * the terms of the GNU General Public License, version 3, as published by the
10+ * Free Software Foundation.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ */
20+
21+#include "libertine-scope/app_description.h"
22+#include <unity/scopes/Variant.h>
23+#include <unity/util/IniParser.h>
24+#include <QFileInfo>
25+#include <QStringList>
26+
27+
28+namespace
29+{
30+static const std::string DESKTOP_FILE_GROUP("Desktop Entry");
31+static const std::string DESKTOP_FILE_KEY_COMMENT("Comment");
32+}
33+
34+
35+AppDescription::
36+AppDescription(const std::string& desktop_file, const std::string& locale)
37+ : desktop_file_(desktop_file), language_(locale)
38+{
39+}
40+
41+
42+AppDescription::
43+~AppDescription()
44+{
45+}
46+
47+
48+unity::scopes::Variant AppDescription::
49+description() const
50+{
51+ if (QFileInfo(QString::fromStdString(desktop_file_)).exists())
52+ {
53+ unity::util::IniParser parser(desktop_file_.c_str());
54+ if (parser.has_key(DESKTOP_FILE_GROUP, DESKTOP_FILE_KEY_COMMENT))
55+ {
56+ return unity::scopes::Variant(parser.get_locale_string(DESKTOP_FILE_GROUP, DESKTOP_FILE_KEY_COMMENT, language_));
57+ }
58+ }
59+
60+ return unity::scopes::Variant("");
61+}
62
63=== added file 'libertine-scope/app_description.h'
64--- libertine-scope/app_description.h 1970-01-01 00:00:00 +0000
65+++ libertine-scope/app_description.h 2016-04-15 12:42:14 +0000
66@@ -0,0 +1,41 @@
67+/*
68+ * Copyright 2016 Canonical Ltd.
69+ *
70+ * This program is free software: you can redistribute it and/or modify it under
71+ * the terms of the GNU General Public License, version 3, as published by the
72+ * Free Software Foundation.
73+ *
74+ * This program is distributed in the hope that it will be useful,
75+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
76+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77+ * GNU General Public License for more details.
78+ *
79+ * You should have received a copy of the GNU General Public License
80+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
81+ */
82+
83+#ifndef APP_DESCRIPTION_H
84+#define APP_DESCRIPTION_H
85+
86+#include <string>
87+
88+namespace unity {
89+ namespace scopes {
90+ class Variant;
91+ }
92+}
93+
94+class AppDescription
95+{
96+public:
97+ explicit
98+ AppDescription(const std::string& desktop_file, const std::string& locale);
99+ ~AppDescription();
100+ unity::scopes::Variant description() const;
101+
102+private:
103+ const std::string& desktop_file_;
104+ const std::string& language_;
105+};
106+
107+#endif
108
109=== modified file 'libertine-scope/preview.cpp'
110--- libertine-scope/preview.cpp 2016-01-19 21:10:09 +0000
111+++ libertine-scope/preview.cpp 2016-04-15 12:42:14 +0000
112@@ -13,16 +13,21 @@
113 * You should have received a copy of the GNU General Public License
114 * along with this program. If not, see <http://www.gnu.org/licenses/>.
115 */
116+
117 #include "libertine-scope/preview.h"
118+#include "libertine-scope/app_description.h"
119
120 #include <unity/scopes/PreviewReply.h>
121 #include <unity/scopes/Variant.h>
122 #include <unity/scopes/VariantBuilder.h>
123+#include <unity/scopes/ActionMetadata.h>
124+#include <unity/scopes/Result.h>
125
126+namespace usc = unity::scopes;
127
128 Preview::
129-Preview(unity::scopes::Result const& result,
130- unity::scopes::ActionMetadata const& metadata)
131+Preview(usc::Result const& result,
132+ usc::ActionMetadata const& metadata)
133 : PreviewQueryBase(result, metadata)
134 {
135 }
136@@ -41,22 +46,24 @@
137
138
139 void Preview::
140-run(unity::scopes::PreviewReplyProxy const& reply)
141+run(usc::PreviewReplyProxy const& reply)
142 {
143- reply->push("description", unity::scopes::Variant("A Description"));
144-
145- unity::scopes::PreviewWidget image_widget("myimage", "image");
146- image_widget.add_attribute_mapping("source", "art");
147-
148- unity::scopes::PreviewWidget buttons("buttons", "actions");
149- unity::scopes::VariantBuilder vb;
150+ usc::PreviewWidget header("hdr", "header");
151+ header.add_attribute_mapping("title", "title");
152+ header.add_attribute_mapping("mascot", "art");
153+
154+ usc::PreviewWidget buttons("buttons", "actions");
155+ usc::VariantBuilder vb;
156 vb.add_tuple({
157- {"id", unity::scopes::Variant("open")},
158- {"label", unity::scopes::Variant("Open")},
159+ {"id", usc::Variant("open")},
160+ {"label", usc::Variant("Open")},
161 });
162 buttons.add_attribute_value("actions", vb.end());
163
164- unity::scopes::PreviewWidgetList widgets{ image_widget, buttons };
165+ auto desktop_file_name = result()["desktop_file"].get_string();
166+ usc::PreviewWidget desc("desc", "text");
167+ desc.add_attribute_value("text", AppDescription(desktop_file_name, action_metadata().locale()).description());
168+
169+ usc::PreviewWidgetList widgets{ header, desc, buttons };
170 reply->push(widgets);
171 }
172-
173
174=== modified file 'libertine-scope/query.cpp'
175--- libertine-scope/query.cpp 2016-01-19 21:10:09 +0000
176+++ libertine-scope/query.cpp 2016-04-15 12:42:14 +0000
177@@ -96,12 +96,15 @@
178 for (auto const& app: container->app_launchers())
179 {
180 if (app.no_display())
181+ {
182 continue;
183+ }
184
185 usc::CategorisedResult result(category);
186 result.set_title(app.name());
187 result.set_art(app.icon());
188 result.set_uri(app_uri(*container, app));
189+ result["desktop_file"] = app.desktop_file();
190 if (!reply->push(result))
191 {
192 break;
193@@ -109,4 +112,3 @@
194 }
195 }
196 }
197-
198
199=== modified file 'po/libertine-scope.pot'
200--- po/libertine-scope.pot 2016-02-27 03:54:52 +0000
201+++ po/libertine-scope.pot 2016-04-15 12:42:14 +0000
202@@ -8,7 +8,7 @@
203 msgstr ""
204 "Project-Id-Version: PACKAGE VERSION\n"
205 "Report-Msgid-Bugs-To: \n"
206-"POT-Creation-Date: 2016-02-26 22:50-0500\n"
207+"POT-Creation-Date: 2016-04-14 13:30-0400\n"
208 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
209 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
210 "Language-Team: LANGUAGE <LL@li.org>\n"
211
212=== modified file 'tests/CMakeLists.txt'
213--- tests/CMakeLists.txt 2016-01-19 00:16:56 +0000
214+++ tests/CMakeLists.txt 2016-04-15 12:42:14 +0000
215@@ -6,7 +6,11 @@
216 add_executable(libertine_scope_tests
217 fake_container.cpp
218 fake_libertine.cpp
219+
220+ # tests
221 test_scope.cpp
222+ test_app_description.cpp
223+ test_preview.cpp
224 )
225
226 target_link_libraries(libertine_scope_tests
227@@ -16,6 +20,8 @@
228 gmock_main
229 )
230
231-add_test(test_scope
232- libertine_scope_tests
233-)
234+add_test(test_scope libertine_scope_tests)
235+add_test(test_app_description libertine_scope_tests)
236+add_test(test_preview libertine_scope_tests)
237+
238+execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/tests/data/ ${CMAKE_CURRENT_BINARY_DIR}/data)
239
240=== added directory 'tests/data'
241=== added file 'tests/data/Full.desktop'
242--- tests/data/Full.desktop 1970-01-01 00:00:00 +0000
243+++ tests/data/Full.desktop 2016-04-15 12:42:14 +0000
244@@ -0,0 +1,13 @@
245+[Desktop Entry]
246+Encoding=UTF-8
247+Name=Matchbox
248+Comment=This session logs you into Matchbox
249+Comment[da]=Surf på internettet
250+Comment[de]=Im Internet surfen
251+Comment[el]=Μπορείτε να περιηγηθείτε στο διαδίκτυο (Web)
252+Comment[es]=Navegue por la web
253+Comment[et]=Lehitse veebi
254+Exec=matchbox-session
255+Terminal=False
256+Icon=
257+Type=Application
258
259=== added file 'tests/data/NoComment.desktop'
260--- tests/data/NoComment.desktop 1970-01-01 00:00:00 +0000
261+++ tests/data/NoComment.desktop 2016-04-15 12:42:14 +0000
262@@ -0,0 +1,7 @@
263+[Desktop Entry]
264+Encoding=UTF-8
265+Name=Matchbox
266+Exec=matchbox-session
267+Terminal=False
268+Icon=
269+Type=Application
270
271=== added file 'tests/test_app_description.cpp'
272--- tests/test_app_description.cpp 1970-01-01 00:00:00 +0000
273+++ tests/test_app_description.cpp 2016-04-15 12:42:14 +0000
274@@ -0,0 +1,61 @@
275+/*
276+ * Copyright 2016 Canonical Ltd.
277+ *
278+ * This program is free software: you can redistribute it and/or modify it under
279+ * the terms of the GNU General Public License, version 3, as published by the
280+ * Free Software Foundation.
281+ *
282+ * This program is distributed in the hope that it will be useful,
283+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
284+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
285+ * GNU General Public License for more details.
286+ *
287+ * You should have received a copy of the GNU General Public License
288+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
289+ */
290+
291+#include "libertine-scope/app_description.h"
292+#include <unity/scopes/Variant.h>
293+#include <gtest/gtest.h>
294+#include <QDir>
295+
296+
297+TEST(TestAppDescription, returnsEmptyStringForEmptyNamedFile)
298+{
299+ AppDescription desc("", "");
300+ EXPECT_EQ("", desc.description().get_string());
301+}
302+
303+TEST(TestAppDescription, returnsEmptyStringForNonExistentDesktopFile)
304+{
305+ AppDescription desc("/non/existent/file", "");
306+ EXPECT_EQ("", desc.description().get_string());
307+}
308+
309+TEST(TestAppDescription, returnsEmptyStringForDesktopFileWithoutComment)
310+{
311+ auto data_path = QString("%1/data/NoComment.desktop").arg(QDir::currentPath()).toStdString();
312+ AppDescription desc(data_path, "");
313+ EXPECT_EQ("", desc.description().get_string());
314+}
315+
316+TEST(TestAppDescription, returnsTopLevelCommentWhenNoLocaleSpecified)
317+{
318+ auto data_path = QString("%1/data/Full.desktop").arg(QDir::currentPath()).toStdString();
319+ AppDescription desc(data_path, "");
320+ EXPECT_EQ("This session logs you into Matchbox", desc.description().get_string());
321+}
322+
323+TEST(TestAppDescription, returnsTopLevelCommentWhenLocaleNotAvailable)
324+{
325+ auto data_path = QString("%1/data/Full.desktop").arg(QDir::currentPath()).toStdString();
326+ AppDescription desc(data_path, "fr_FR");
327+ EXPECT_EQ("This session logs you into Matchbox", desc.description().get_string());
328+}
329+
330+TEST(TestAppDescription, returnsLocaleBasedComment)
331+{
332+ auto data_path = QString("%1/data/Full.desktop").arg(QDir::currentPath()).toStdString();
333+ AppDescription desc(data_path, "de_DE");
334+ EXPECT_EQ("Im Internet surfen", desc.description().get_string());
335+}
336
337=== added file 'tests/test_preview.cpp'
338--- tests/test_preview.cpp 1970-01-01 00:00:00 +0000
339+++ tests/test_preview.cpp 2016-04-15 12:42:14 +0000
340@@ -0,0 +1,64 @@
341+/*
342+ * Copyright 2016 Canonical Ltd.
343+ *
344+ * This program is free software: you can redistribute it and/or modify it under
345+ * the terms of the GNU General Public License, version 3, as published by the
346+ * Free Software Foundation.
347+ *
348+ * This program is distributed in the hope that it will be useful,
349+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
350+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
351+ * GNU General Public License for more details.
352+ *
353+ * You should have received a copy of the GNU General Public License
354+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
355+ */
356+
357+#include "libertine-scope/preview.h"
358+#include <unity/scopes/Variant.h>
359+#include <gtest/gtest.h>
360+#include <unity/scopes/ActionMetadata.h>
361+#include <unity/scopes/testing/Result.h>
362+#include <unity/scopes/testing/MockPreviewReply.h>
363+#include <unity/scopes/PreviewWidget.h>
364+#include <memory>
365+#include <QDir>
366+
367+
368+TEST(TestPreview, pushesWidgetsWithAppInformation)
369+{
370+ unity::scopes::testing::Result result;
371+ result["desktop_file"] = unity::scopes::Variant(QString("%1/data/Full.desktop").arg(QDir::currentPath()).toStdString());
372+ unity::scopes::ActionMetadata metadata("en_US", "phone");
373+
374+ std::unique_ptr<unity::scopes::PreviewWidgetList> list(new unity::scopes::PreviewWidgetList());
375+ testing::NiceMock<unity::scopes::testing::MockPreviewReply> reply;
376+ EXPECT_CALL(reply, push(testing::_)).WillOnce(testing::SaveArg<0>(list.get()));
377+ unity::scopes::PreviewReplyProxy proxy(&reply, [](unity::scopes::PreviewReply*) {});
378+
379+ Preview preview(result, metadata);
380+ preview.run(proxy);
381+
382+ ASSERT_NE(nullptr, list);
383+ ASSERT_EQ(3, list->size());
384+
385+ auto header = list->front();
386+ EXPECT_EQ("hdr", header.id());
387+ EXPECT_EQ("header", header.widget_type());
388+ EXPECT_EQ("title", header.attribute_mappings()["title"]);
389+ EXPECT_EQ("art", header.attribute_mappings()["mascot"]);
390+
391+ list->pop_front();
392+ auto desc = list->front();
393+ EXPECT_EQ("desc", desc.id());
394+ EXPECT_EQ("This session logs you into Matchbox", desc.attribute_values()["text"].get_string());
395+
396+ list->pop_front();
397+ auto buttons = list->front();
398+ EXPECT_EQ("buttons", buttons.id());
399+ EXPECT_EQ("actions", buttons.widget_type());
400+ auto buttons_actions = buttons.attribute_values()["actions"].get_array();
401+ ASSERT_EQ(1, buttons_actions.size());
402+ EXPECT_EQ("open", buttons_actions[0].get_dict()["id"].get_string());
403+ EXPECT_EQ("Open", buttons_actions[0].get_dict()["label"].get_string());
404+}
405
406=== modified file 'tests/test_scope.cpp'
407--- tests/test_scope.cpp 2016-01-19 00:16:56 +0000
408+++ tests/test_scope.cpp 2016-04-15 12:42:14 +0000
409@@ -54,4 +54,3 @@
410 SearchReplyProxy search_reply_proxy(&reply, [](unity::scopes::SearchReply*) {});
411 search_query->run(search_reply_proxy);
412 }
413-

Subscribers

People subscribed via source and target branches