Merge lp:~dobey/unity-scope-click/ignored-setting into lp:unity-scope-click

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 421
Merged at revision: 424
Proposed branch: lp:~dobey/unity-scope-click/ignored-setting
Merge into: lp:unity-scope-click
Diff against target: 313 lines (+104/-15)
10 files modified
data/com.canonical.unity.clickscope.gschema.xml (+5/-0)
libclickscope/click/configuration.cpp (+7/-0)
libclickscope/click/configuration.h (+2/-0)
libclickscope/click/interface.cpp (+10/-2)
libclickscope/click/interface.h (+1/-0)
libclickscope/tests/test_configuration.cpp (+24/-0)
libclickscope/tests/test_interface.cpp (+23/-6)
scope/clickapps/apps-query.cpp (+2/-1)
scope/tests/CMakeLists.txt (+13/-1)
scope/tests/test_apps_query.cpp (+17/-5)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/ignored-setting
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Antti Kaijanmäki (community) Approve
Review via email: mp+286597@code.launchpad.net

Commit message

Add an "ignored-apps" gsettings key for a list of apps to ignore in results.
Generate a gsettings schema during build for the app scope tests.
Use the temporary schema and memory backend for app scope tests.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

see the inline comment.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/com.canonical.unity.clickscope.gschema.xml'
2--- data/com.canonical.unity.clickscope.gschema.xml 2014-07-04 13:10:05 +0000
3+++ data/com.canonical.unity.clickscope.gschema.xml 2016-03-03 19:38:54 +0000
4@@ -6,5 +6,10 @@
5 <summary>Applications to display in the top category of the Apps scope</summary>
6 <description>List of application IDs that will be displayed in the upper area of the Applications scope for quick access.</description>
7 </key>
8+ <key type="as" name="ignored-apps">
9+ <default>[]</default>
10+ <summary>Applications to hide from the Apps scope</summary>
11+ <description>List of application IDs that will be hidden from the Applications scope. Legacy applications must be the file name of the .desktop file (dialer-app.desktop), and clicks should use the package name (com.ubuntu.calendar).</description>
12+ </key>
13 </schema>
14 </schemalist>
15
16=== modified file 'libclickscope/click/configuration.cpp'
17--- libclickscope/click/configuration.cpp 2015-11-24 19:14:11 +0000
18+++ libclickscope/click/configuration.cpp 2016-03-03 19:38:54 +0000
19@@ -235,4 +235,11 @@
20 return apps;
21 }
22
23+const std::vector<std::string> Configuration::get_ignored_apps() const
24+{
25+ auto apps = get_dconf_strings(Configuration::COREAPPS_SCHEMA,
26+ Configuration::IGNORED_KEY);
27+ return apps;
28+}
29+
30 } // namespace click
31
32=== modified file 'libclickscope/click/configuration.h'
33--- libclickscope/click/configuration.h 2015-11-24 19:14:11 +0000
34+++ libclickscope/click/configuration.h 2016-03-03 19:38:54 +0000
35@@ -66,8 +66,10 @@
36
37 constexpr static const char* COREAPPS_SCHEMA {"com.canonical.Unity.ClickScope"};
38 constexpr static const char* COREAPPS_KEY {"coreApps"};
39+ constexpr static const char* IGNORED_KEY {"ignoredApps"};
40
41 virtual const std::vector<std::string> get_core_apps() const;
42+ virtual const std::vector<std::string> get_ignored_apps() const;
43 virtual ~Configuration() {}
44 protected:
45 virtual std::vector<std::string> list_folder(const std::string &folder, const std::string &pattern);
46
47=== modified file 'libclickscope/click/interface.cpp'
48--- libclickscope/click/interface.cpp 2016-01-04 20:56:17 +0000
49+++ libclickscope/click/interface.cpp 2016-03-03 19:38:54 +0000
50@@ -239,6 +239,7 @@
51 * Find all of the installed apps matching @search_query in a timeout.
52 */
53 std::vector<click::Application> Interface::find_installed_apps(const std::string& search_query,
54+ const std::vector<std::string>& ignored_apps,
55 const std::string& current_department,
56 const std::shared_ptr<click::DepartmentsDb>& depts_db)
57 {
58@@ -264,8 +265,7 @@
59 std::vector<Application> result;
60
61 bool include_desktop_results = show_desktop_apps();
62-
63- auto enumerator = [&result, this, search_query, current_department, packages_in_department, apply_department_filter, include_desktop_results, depts_db]
64+ auto enumerator = [&result, this, search_query, ignored_apps, current_department, packages_in_department, apply_department_filter, include_desktop_results, depts_db]
65 (const unity::util::IniParser& keyFile, const std::string& filename)
66 {
67 if (keyFile.has_group(DESKTOP_FILE_GROUP) == false) {
68@@ -280,6 +280,14 @@
69 || keyFile.has_key(DESKTOP_FILE_GROUP, DESKTOP_FILE_KEY_APP_ID)
70 || Interface::is_non_click_app(QString::fromStdString(filename))) {
71 auto app = load_app_from_desktop(keyFile, filename);
72+ auto app_id = app.name.empty() ? filename : app.name;
73+ if (!ignored_apps.empty() &&
74+ std::find(ignored_apps.begin(), ignored_apps.end(),
75+ app_id) != ignored_apps.end())
76+ {
77+ // The app is ignored. Get out of here.
78+ return;
79+ }
80
81 // app from click package has non-empty name; for non-click apps use desktop filename
82 const std::string department_key = app.name.empty() ? filename : app.name;
83
84=== modified file 'libclickscope/click/interface.h'
85--- libclickscope/click/interface.h 2014-07-18 11:18:27 +0000
86+++ libclickscope/click/interface.h 2016-03-03 19:38:54 +0000
87@@ -93,6 +93,7 @@
88 const std::string& filename);
89 static std::vector<Application> sort_apps(const std::vector<Application>& apps);
90 virtual std::vector<Application> find_installed_apps(const std::string& search_query,
91+ const std::vector<std::string>& ignored_apps = std::vector<std::string>{},
92 const std::string& current_department = "",
93 const std::shared_ptr<click::DepartmentsDb>& depts_db = nullptr);
94
95
96=== modified file 'libclickscope/tests/test_configuration.cpp'
97--- libclickscope/tests/test_configuration.cpp 2015-11-24 19:14:11 +0000
98+++ libclickscope/tests/test_configuration.cpp 2016-03-03 19:38:54 +0000
99@@ -75,6 +75,30 @@
100 ASSERT_EQ(found_apps, expected_apps);
101 }
102
103+TEST(Configuration, getIgnoredAppsEmpty)
104+{
105+ using namespace ::testing;
106+ FakeConfiguration c;
107+ auto expected_apps = std::vector<std::string>{};
108+ EXPECT_CALL(c, get_dconf_strings(Configuration::COREAPPS_SCHEMA,
109+ Configuration::IGNORED_KEY))
110+ .WillOnce(Return(expected_apps));
111+ auto ignored_apps = c.get_ignored_apps();
112+ ASSERT_EQ(expected_apps, ignored_apps);
113+}
114+
115+TEST(Configuration, getIgnoredAppsFound)
116+{
117+ using namespace ::testing;
118+ FakeConfiguration c;
119+ auto expected_apps = std::vector<std::string>{"package1", "package2"};
120+ EXPECT_CALL(c, get_dconf_strings(Configuration::COREAPPS_SCHEMA,
121+ Configuration::IGNORED_KEY))
122+ .WillOnce(Return(expected_apps));
123+ auto ignored_apps = c.get_ignored_apps();
124+ ASSERT_EQ(expected_apps, ignored_apps);
125+}
126+
127 TEST(Configuration, getAvailableFrameworksUsesRightFolder)
128 {
129 using namespace ::testing;
130
131=== modified file 'libclickscope/tests/test_interface.cpp'
132--- libclickscope/tests/test_interface.cpp 2016-01-04 20:56:17 +0000
133+++ libclickscope/tests/test_interface.cpp 2016-03-03 19:38:54 +0000
134@@ -1,5 +1,5 @@
135 /*
136- * Copyright (C) 2014 Canonical Ltd.
137+ * Copyright (C) 2014-2016 Canonical Ltd.
138 *
139 * This program is free software: you can redistribute it and/or modify it
140 * under the terms of the GNU General Public License version 3, as published
141@@ -128,6 +128,8 @@
142 MOCK_METHOD2(manifest_callback, void(Manifest, InterfaceError));
143 MOCK_METHOD2(manifests_callback, void(ManifestList, InterfaceError));
144 MOCK_METHOD2(installed_callback, void(PackageSet, InterfaceError));
145+
146+ std::vector<std::string> ignoredApps;
147 };
148
149 }
150@@ -190,10 +192,25 @@
151 EXPECT_TRUE(results.empty());
152 }
153
154+TEST_F(ClickInterfaceTest, testFindAppsInDirIgnoredApps)
155+{
156+ QSharedPointer<click::KeyFileLocator> keyFileLocator(
157+ new click::KeyFileLocator(
158+ testing::systemApplicationsDirectoryForTesting(),
159+ testing::userApplicationsDirectoryForTesting()));
160+
161+ click::Interface iface(keyFileLocator);
162+ ignoredApps.push_back("messaging-app.desktop");
163+ ignoredApps.push_back("com.ubuntu.calculator");
164+
165+ auto results = iface.find_installed_apps("", ignoredApps);
166+ EXPECT_EQ(20, results.size());
167+}
168+
169 //
170 // test that application with a default department id key in the desktop
171 // file is returned when department matches
172-TEST(ClickInterface, testFindAppsWithAppWithDefaultDepartmentId)
173+TEST_F(ClickInterfaceTest, testFindAppsWithAppWithDefaultDepartmentId)
174 {
175 QSharedPointer<click::KeyFileLocator> keyFileLocator(
176 new click::KeyFileLocator(
177@@ -203,13 +220,13 @@
178 click::Interface iface(keyFileLocator);
179
180 auto depts_db = std::make_shared<click::DepartmentsDb>(":memory:");
181- auto results = iface.find_installed_apps("", "accessories", depts_db);
182+ auto results = iface.find_installed_apps("", ignoredApps, "accessories", depts_db);
183
184 EXPECT_EQ(1u, results.size());
185 EXPECT_EQ("Contacts", results.begin()->title);
186 }
187
188-TEST(ClickInterface, testFindAppsWithAppWithDefaultDepartmentIdOverriden)
189+TEST_F(ClickInterfaceTest, testFindAppsWithAppWithDefaultDepartmentIdOverriden)
190 {
191 QSharedPointer<click::KeyFileLocator> keyFileLocator(
192 new click::KeyFileLocator(
193@@ -225,12 +242,12 @@
194 depts_db->store_department_mapping("utilities", "");
195 depts_db->store_department_mapping("accessories", "");
196
197- auto results = iface.find_installed_apps("", "utilies", depts_db);
198+ auto results = iface.find_installed_apps("", ignoredApps, "utilies", depts_db);
199 EXPECT_EQ(0, results.size());
200
201 // address book applicaton moved to utilities
202 depts_db->store_package_mapping("address-book-app.desktop", "utilities");
203- results = iface.find_installed_apps("", "utilities", depts_db);
204+ results = iface.find_installed_apps("", ignoredApps, "utilities", depts_db);
205
206 EXPECT_EQ(1u, results.size());
207 EXPECT_EQ("Contacts", results.begin()->title);
208
209=== modified file 'scope/clickapps/apps-query.cpp'
210--- scope/clickapps/apps-query.cpp 2016-01-06 18:08:33 +0000
211+++ scope/clickapps/apps-query.cpp 2016-03-03 19:38:54 +0000
212@@ -409,7 +409,8 @@
213
214 const bool show_top_apps = querystr.empty() && current_dept.empty();
215 ResultPusher pusher(searchReply, show_top_apps ? impl->configuration.get_core_apps() : std::vector<std::string>());
216- auto const localResults = clickInterfaceInstance().find_installed_apps(querystr, current_dept, impl->depts_db);
217+ auto const ignoredApps = impl->configuration.get_ignored_apps();
218+ auto const localResults = clickInterfaceInstance().find_installed_apps(querystr, ignoredApps, current_dept, impl->depts_db);
219
220 if (querystr.empty()) {
221 if (impl->depts_db)
222
223=== modified file 'scope/tests/CMakeLists.txt'
224--- scope/tests/CMakeLists.txt 2015-11-24 18:23:23 +0000
225+++ scope/tests/CMakeLists.txt 2016-03-03 19:38:54 +0000
226@@ -85,9 +85,21 @@
227
228 # ---
229
230+set(TEST_SCHEMA_DIR ${CMAKE_CURRENT_BINARY_DIR})
231+add_definitions(-DTEST_SCHEMA_DIR="${TEST_SCHEMA_DIR}")
232+execute_process (
233+ COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas
234+ OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE
235+ OUTPUT_STRIP_TRAILING_WHITESPACE
236+)
237+add_custom_target (gschemas.compiled
238+ COMMAND cp -f ${CMAKE_SOURCE_DIR}/data/*gschema.xml ${TEST_SCHEMA_DIR}
239+ COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${TEST_SCHEMA_DIR}
240+)
241+
242 add_custom_target (test-apps-scope
243 COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${APPS_SCOPE_TESTS_TARGET}
244- DEPENDS ${APPS_SCOPE_TESTS_TARGET}
245+ DEPENDS ${APPS_SCOPE_TESTS_TARGET} gschemas.compiled
246 )
247
248 add_custom_target(test-apps-scope-valgrind
249
250=== modified file 'scope/tests/test_apps_query.cpp'
251--- scope/tests/test_apps_query.cpp 2014-08-08 16:06:30 +0000
252+++ scope/tests/test_apps_query.cpp 2016-03-03 19:38:54 +0000
253@@ -61,7 +61,7 @@
254 {
255 public:
256 MockClickInterface() = default;
257- MOCK_METHOD3(find_installed_apps, std::vector<click::Application>(const std::string&, const std::string&, const std::shared_ptr<click::DepartmentsDb>&));
258+ MOCK_METHOD4(find_installed_apps, std::vector<click::Application>(const std::string&, const std::vector<std::string>&, const std::string&, const std::shared_ptr<click::DepartmentsDb>&));
259 };
260
261 class MockAppsQuery : public click::apps::Query
262@@ -192,6 +192,19 @@
263
264 class DepartmentsTest : public ::testing::Test {
265 protected:
266+ virtual void SetUp() override
267+ {
268+ ASSERT_EQ(setenv("GSETTINGS_SCHEMA_DIR", TEST_SCHEMA_DIR, 1), 0);
269+ ASSERT_EQ(setenv("GSETTINGS_BACKEND", "memory", 1), 0);
270+ std::cerr << "SCHEMA dir: " << TEST_SCHEMA_DIR << std::endl;
271+ }
272+
273+ virtual void TearDown() override
274+ {
275+ ASSERT_EQ(unsetenv("GSETTINGS_BACKEND"), 0);
276+ ASSERT_EQ(unsetenv("GSETTINGS_SCHEMA_DIR"), 0);
277+ }
278+
279 const std::vector<click::Application> installed_apps = {
280 {"app1", "App1", 0.0f, "icon", "url", "descr", "scrshot", "", "games-rpg"},
281 {"app2", "App2", 0.0f, "icon", "url", "descr", "scrshot", "", "video"}
282@@ -220,7 +233,7 @@
283 // no apps in 'books' department, thus excluded
284 std::list<std::string> expected_departments({{"", "games", "video"}});
285
286- EXPECT_CALL(*clickif, find_installed_apps(_, _, _)).WillOnce(Return(installed_apps));
287+ EXPECT_CALL(*clickif, find_installed_apps(_, _, _, _)).WillOnce(Return(installed_apps));
288 EXPECT_CALL(mock_reply, register_category("predefined", _, _, _)).WillOnce(Return(ptrCat));
289 EXPECT_CALL(mock_reply, register_category("local", StrNe(""), _, _)).WillOnce(Return(ptrCat));
290 EXPECT_CALL(mock_reply, register_category("store", _, _, _)).WillOnce(Return(ptrCat));
291@@ -269,7 +282,7 @@
292
293 std::list<std::string> expected_departments({"", "games"});
294
295- EXPECT_CALL(*clickif, find_installed_apps(_, _, _)).WillOnce(Return(installed_apps));
296+ EXPECT_CALL(*clickif, find_installed_apps(_, _, _, _)).WillOnce(Return(installed_apps));
297 EXPECT_CALL(mock_reply, register_category("local", StrEq(""), _, _)).WillOnce(Return(ptrCat));
298 EXPECT_CALL(mock_reply, register_category("store", _, _, _)).WillOnce(Return(ptrCat));
299 EXPECT_CALL(mock_reply, register_departments(MatchesDepartments(expected_departments)));
300@@ -301,7 +314,7 @@
301 scopes::testing::MockSearchReply mock_reply;
302 scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
303
304- EXPECT_CALL(*clickif, find_installed_apps(_, _, _)).WillOnce(Return(installed_apps));
305+ EXPECT_CALL(*clickif, find_installed_apps(_, _, _, _)).WillOnce(Return(installed_apps));
306 EXPECT_CALL(mock_reply, register_category("local", StrEq(""), _, _)).WillOnce(Return(ptrCat));
307 EXPECT_CALL(mock_reply, register_category("store", _, _, _)).WillOnce(Return(ptrCat));
308
309@@ -310,4 +323,3 @@
310 q.run(reply);
311 }
312 }
313-

Subscribers

People subscribed via source and target branches

to all changes: