Merge lp:~ddieter/appcenter/appcenter-search-category into lp:~elementary-apps/appcenter/appcenter

Proposed by Dieter Debast
Status: Merged
Approved by: Danielle Foré
Approved revision: 315
Merged at revision: 316
Proposed branch: lp:~ddieter/appcenter/appcenter-search-category
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 318 lines (+109/-40)
6 files modified
src/Core/Client.vala (+3/-17)
src/MainWindow.vala (+93/-14)
src/Views/CategoryView.vala (+8/-4)
src/Views/InstalledView.vala (+1/-1)
src/Views/SearchView.vala (+3/-3)
src/Views/View.vala (+1/-1)
To merge this branch: bzr merge lp:~ddieter/appcenter/appcenter-search-category
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Artem Anufrij (community) cody style Approve
Review via email: mp+306512@code.launchpad.net

Commit message

When viewing the apps in a specific category, it is now possible to use the search bar and search apps only in that category

Description of the change

When viewing the apps in a specific category, it is now possible to use the search bar and search apps only in that category. Using the search bar in the main window, still performs a search in all of the apps.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

I can confirm that this works as expected! Nice work :)

One thing that I think I'd like, but I don't think is a blocker on this branch would be to leave the back button there so that if you search and it turns up empty you can click that button to kind of expand your search back to all categories

review: Approve (ux)
Revision history for this message
Danielle Foré (danrabbit) wrote :

Ah I just thought of another thing that would be kind of nice would be if the hint text changed to reflect the category. So "Search Audio" "Search Education" etc. Would help for clarity I think

311. By Dieter Debast

Change search bar placeholder depending on category

312. By Dieter Debast

Added a "Search All Apps" button

Revision history for this message
Dieter Debast (ddieter) wrote :

Thanks :)

I've made some changes. Is this what you had in mind?

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Code looks very good.

review: Approve (cody style)
Revision history for this message
Danielle Foré (danrabbit) wrote :

I left a small diff comment. For proper translations, you want to do "Search %s" not "search" + var.

Also, please don't add a new string "Search All Apps". "Search Apps" is sufficient and already has translations.

review: Needs Fixing
Revision history for this message
Danielle Foré (danrabbit) wrote :

Also, please revert changes to pot files. We'll update those in a separate commit.

Revision history for this message
Danielle Foré (danrabbit) wrote :

ah I see what you've done with "Search All Apps". I don't know about hiding the button until there are 0 results. This seems kind of limiting, especially if you see that there isn't the desired result when there are half a dozen left. Probably should keep the button the whole time.

313. By Dieter Debast

Always show "Search Apps" button

314. By Dieter Debast

Translation updates

315. By Dieter Debast

Improved Code

Revision history for this message
Dieter Debast (ddieter) wrote :

I've reverted the pot files, used the correct translation strings and the "Search Apps" button is now always shown when searching through categories

Revision history for this message
Danielle Foré (danrabbit) wrote :

afaict this works as intended, minimal string changes and seems translatable. I like it :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Core/Client.vala'
2--- src/Core/Client.vala 2016-09-24 01:53:02 +0000
3+++ src/Core/Client.vala 2016-10-07 19:18:45 +0000
4@@ -271,11 +271,11 @@
5 return packages;
6 }
7
8- public Gee.Collection<AppCenterCore.Package> get_applications_for_category (AppStream.Category category) {
9+ public Gee.Collection<AppCenterCore.Package> search_applications (string? query, AppStream.Category? category) {
10 var apps = new Gee.TreeSet<AppCenterCore.Package> ();
11- string categories = get_string_from_categories (category);
12+ string categories = category == null ? null : get_string_from_categories (category);
13 try {
14- var comps = appstream_database.find_components (null, categories);
15+ var comps = appstream_database.find_components (query, categories);
16 comps.foreach ((comp) => {
17 apps.add (package_list.get (comp.get_pkgnames ()[0]));
18 });
19@@ -306,20 +306,6 @@
20 return categories;
21 }
22
23- public Gee.Collection<AppCenterCore.Package> search_applications (string query) {
24- var apps = new Gee.TreeSet<AppCenterCore.Package> ();
25- try {
26- var comps = appstream_database.find_components (query, null);
27- comps.foreach ((comp) => {
28- apps.add (package_list.get (comp.get_pkgnames ()[0]));
29- });
30- } catch (Error e) {
31- critical (e.message);
32- }
33-
34- return apps;
35- }
36-
37 public Pk.Package? get_app_package (string application, Pk.Bitfield additional_filters = 0) throws GLib.Error {
38 AppCenter.Task packages_task = request_task (false);
39 Pk.Package? package = null;
40
41=== modified file 'src/MainWindow.vala'
42--- src/MainWindow.vala 2016-09-07 18:38:31 +0000
43+++ src/MainWindow.vala 2016-10-07 19:18:45 +0000
44@@ -25,7 +25,10 @@
45 private Views.CategoryView category_view;
46 private Views.SearchView search_view;
47 private Gtk.Button return_button;
48+ private Gtk.Button search_all_button;
49+ private Gtk.Stack button_stack;
50 private ulong task_finished_connection = 0U;
51+ private Gee.Deque<string> return_button_history;
52
53 public static Views.InstalledView installed_view { get; private set; }
54
55@@ -78,6 +81,7 @@
56 });
57
58 return_button.clicked.connect (view_return);
59+ search_all_button.clicked.connect (search_all_apps);
60
61 installed_view.get_apps.begin ();
62
63@@ -94,6 +98,16 @@
64 return_button = new Gtk.Button ();
65 return_button.no_show_all = true;
66 return_button.get_style_context ().add_class ("back-button");
67+ return_button_history = new Gee.LinkedList<string> ();
68+
69+ search_all_button = new Gtk.Button.with_label (_("Search Apps"));
70+ search_all_button.no_show_all = true;
71+ search_all_button.get_style_context ().add_class ("back-button");
72+
73+ button_stack = new Gtk.Stack ();
74+ button_stack.add (return_button);
75+ button_stack.add (search_all_button);
76+ button_stack.set_visible_child (return_button);
77
78 view_mode = new Granite.Widgets.ModeButton ();
79 view_mode.append_text (_("Categories"));
80@@ -119,7 +133,7 @@
81 headerbar = new Gtk.HeaderBar ();
82 headerbar.show_close_button = true;
83 headerbar.set_custom_title (custom_title_stack);
84- headerbar.pack_start (return_button);
85+ headerbar.pack_start (button_stack);
86 headerbar.pack_end (search_entry);
87
88 set_titlebar (headerbar);
89@@ -178,6 +192,7 @@
90 unowned string research = search_entry.text;
91 if (research.length < 2) {
92 view_mode_revealer.reveal_child = true;
93+ custom_title_stack.set_visible_child (view_mode_revealer);
94 switch (view_mode.selected) {
95 case 0:
96 stack.visible_child = category_view;
97@@ -186,16 +201,42 @@
98 stack.visible_child = installed_view;
99 break;
100 }
101+ if (!return_button_history.is_empty) {
102+ return_button.no_show_all = false;
103+ return_button.show_all ();
104+ }
105+ button_stack.visible_child = return_button;
106+ search_all_button.no_show_all = true;
107+ search_all_button.hide ();
108 } else {
109- search_view.search.begin (research);
110- if (!return_button.visible) {
111- view_mode_revealer.reveal_child = false;
112- stack.visible_child = search_view;
113- }
114+ search_view.search.begin (research, category_view.currently_viewed_category, () => {
115+ if (category_view.currently_viewed_category != null) {
116+ button_stack.visible_child = search_all_button;
117+ search_all_button.no_show_all = false;
118+ search_all_button.show_all ();
119+ } else {
120+ button_stack.visible_child = return_button;
121+ search_all_button.no_show_all = true;
122+ search_all_button.hide ();
123+ }
124+ });
125+ view_mode_revealer.reveal_child = false;
126+ stack.visible_child = search_view;
127+ return_button.no_show_all = true;
128+ return_button.hide ();
129 }
130 }
131
132- private void view_opened (string return_name, string? custom_header = null) {
133+ private void view_opened (string return_name, bool allow_search, string? custom_header = null) {
134+ if (stack.visible_child == search_view && category_view.currently_viewed_category != null) {
135+ button_stack.visible_child = return_button;
136+ search_all_button.no_show_all = true;
137+ search_all_button.hide ();
138+ }
139+
140+ if (return_button_history.is_empty || return_button_history.peek_head () != return_name) {
141+ return_button_history.offer_head (return_name);
142+ }
143 return_button.label = return_name;
144 return_button.no_show_all = false;
145 return_button.show_all ();
146@@ -205,20 +246,58 @@
147 category_header.label = custom_header;
148 custom_title_stack.set_visible_child (category_header);
149 }
150- search_entry.sensitive = false;
151+
152+ search_entry.sensitive = allow_search;
153+ search_entry.grab_focus_without_selecting ();
154+ if (stack.visible_child == category_view && category_view.currently_viewed_category != null) {
155+ search_entry.placeholder_text = _("Search %s").printf (category_view.currently_viewed_category.get_name ());
156+ }
157 }
158
159 private void view_return () {
160- view_mode_revealer.reveal_child = true;
161- custom_title_stack.set_visible_child (view_mode_revealer);
162- category_header.label = "";
163-
164+ if (stack.visible_child != search_view) {
165+ view_mode_revealer.reveal_child = true;
166+ custom_title_stack.set_visible_child (view_mode_revealer);
167+ category_header.label = "";
168+ } else {
169+ if (category_view.currently_viewed_category != null) {
170+ button_stack.visible_child = search_all_button;
171+ search_all_button.no_show_all = false;
172+ search_all_button.show_all ();
173+ }
174+ }
175+
176+ if (stack.visible_child == category_view) {
177+ search_entry.placeholder_text = _("Search Apps");
178+ }
179 search_entry.sensitive = true;
180 search_entry.grab_focus_without_selecting ();
181- return_button.no_show_all = true;
182- return_button.hide ();
183+
184+ return_button_history.poll_head ();
185+ if (!return_button_history.is_empty && stack.visible_child == search_view) {
186+ return_button.label = return_button_history.peek_head ();
187+ return_button.no_show_all = true;
188+ return_button.hide ();
189+ } else {
190+ return_button.no_show_all = true;
191+ return_button.hide ();
192+ }
193
194 View view = (View) stack.visible_child;
195 view.return_clicked ();
196 }
197+
198+ private void search_all_apps () {
199+ category_header.label = "";
200+
201+ search_entry.placeholder_text = _("Search Apps");
202+ search_entry.grab_focus_without_selecting ();
203+
204+ return_button_history.poll_head ();
205+ return_button.no_show_all = true;
206+ return_button.hide ();
207+
208+ category_view.return_clicked ();
209+ trigger_search ();
210+ }
211 }
212
213=== modified file 'src/Views/CategoryView.vala'
214--- src/Views/CategoryView.vala 2016-09-07 18:38:31 +0000
215+++ src/Views/CategoryView.vala 2016-10-07 19:18:45 +0000
216@@ -25,6 +25,8 @@
217 private Gtk.ScrolledWindow category_scrolled;
218 private string current_category;
219
220+ public AppStream.Category currently_viewed_category;
221+
222 public CategoryView () {
223
224 }
225@@ -42,6 +44,7 @@
226 category_flow.child_activated.connect ((child) => {
227 var item = child as Widgets.CategoryItem;
228 if (item != null) {
229+ currently_viewed_category = item.app_category;
230 show_app_list_for_category (item.app_category);
231 }
232 });
233@@ -64,15 +67,16 @@
234 public override void return_clicked () {
235 if (current_category == null) {
236 set_visible_child (category_scrolled);
237+ currently_viewed_category = null;
238 } else {
239- subview_entered (_("Categories"), current_category);
240+ subview_entered (_("Categories"), true, current_category);
241 set_visible_child_name (current_category);
242 current_category = null;
243 }
244 }
245
246 private void show_app_list_for_category (AppStream.Category category) {
247- subview_entered (_("Categories"), category.name);
248+ subview_entered (_("Categories"), true, category.name);
249 var child = get_child_by_name (category.name);
250 if (child != null) {
251 set_visible_child (child);
252@@ -86,12 +90,12 @@
253
254 app_list_view.show_app.connect ((package) => {
255 current_category = category.name;
256- subview_entered (category.name, "");
257+ subview_entered (category.name, false, "");
258 show_package (package);
259 });
260
261 unowned Client client = Client.get_default ();
262- var apps = client.get_applications_for_category (category);
263+ var apps = client.search_applications (null, category);
264 foreach (var app in apps) {
265 app_list_view.add_package (app);
266 }
267
268=== modified file 'src/Views/InstalledView.vala'
269--- src/Views/InstalledView.vala 2016-09-17 19:28:03 +0000
270+++ src/Views/InstalledView.vala 2016-10-07 19:18:45 +0000
271@@ -42,7 +42,7 @@
272 app_list_view = new AppListUpdateView ();
273 add (app_list_view);
274 app_list_view.show_app.connect ((package) => {
275- subview_entered (C_("view", "Updates"));
276+ subview_entered (C_("view", "Updates"), false);
277 show_package (package);
278 });
279 }
280
281=== modified file 'src/Views/SearchView.vala'
282--- src/Views/SearchView.vala 2016-08-20 16:51:58 +0000
283+++ src/Views/SearchView.vala 2016-10-07 19:18:45 +0000
284@@ -33,7 +33,7 @@
285 add (app_list_view);
286 app_list_view.show_app.connect ((package) => {
287 /// TRANSLATORS: the name of the Search view
288- subview_entered (C_("view", "Search"));
289+ subview_entered (C_("view", "Search"), false);
290 show_package (package);
291 });
292 }
293@@ -42,10 +42,10 @@
294 set_visible_child (app_list_view);
295 }
296
297- public async void search (string search_term) {
298+ public async void search (string search_term, AppStream.Category? category) {
299 app_list_view.clear ();
300 unowned Client client = Client.get_default ();
301- var found_apps = client.search_applications (search_term);
302+ var found_apps = client.search_applications (search_term, category);
303
304 if (found_apps.size > 0) {
305 var apps_array = found_apps.to_array ();
306
307=== modified file 'src/Views/View.vala'
308--- src/Views/View.vala 2016-09-07 18:38:31 +0000
309+++ src/Views/View.vala 2016-10-07 19:18:45 +0000
310@@ -19,7 +19,7 @@
311 */
312
313 public abstract class AppCenter.View : Gtk.Stack {
314- public signal void subview_entered (string view_name, string? custom_title = null);
315+ public signal void subview_entered (string view_name, bool allow_search, string? custom_title = null);
316
317 construct {
318 get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);

Subscribers

People subscribed via source and target branches