Merge lp:~kay20/switchboard/plug_search into lp:~elementary-pantheon/switchboard/switchboard

Proposed by kay van der Zander
Status: Merged
Approved by: Corentin Noël
Approved revision: 578
Merged at revision: 599
Proposed branch: lp:~kay20/switchboard/plug_search
Merge into: lp:~elementary-pantheon/switchboard/switchboard
Diff against target: 242 lines (+125/-37)
5 files modified
lib/PlugsManager.vala (+1/-1)
src/CMakeLists.txt (+1/-0)
src/CategoryView.vala (+45/-36)
src/PlugsSearch.vala (+64/-0)
src/Switchboard.vala (+14/-0)
To merge this branch: bzr merge lp:~kay20/switchboard/plug_search
Reviewer Review Type Date Requested Status
kay van der Zander (community) Approve
Review via email: mp+282872@code.launchpad.net

Commit message

Implement deep search in the plugs and search callback.

Description of the change

this branch implements the deep plug search + the search callback to the plug to show the right ui element when opening.

this is tested with A11Y branch: https://code.launchpad.net/~kay20/switchboard-plug-a11y/plug-search

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

A few things and here we go

lp:~kay20/switchboard/plug_search updated
578. By kay van der Zander

implement search callback function

Revision history for this message
kay van der Zander (kay20) wrote :

by Corentin Noël

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/PlugsManager.vala'
--- lib/PlugsManager.vala 2014-12-01 21:07:00 +0000
+++ lib/PlugsManager.vala 2016-02-07 15:47:43 +0000
@@ -102,4 +102,4 @@
102 public Gee.Collection<Switchboard.Plug> get_plugs () {102 public Gee.Collection<Switchboard.Plug> get_plugs () {
103 return plugs.read_only_view;103 return plugs.read_only_view;
104 }104 }
105}
106\ No newline at end of file105\ No newline at end of file
106}
107107
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-04-14 20:39:34 +0000
+++ src/CMakeLists.txt 2016-02-07 15:47:43 +0000
@@ -1,6 +1,7 @@
1set(CLIENT_SOURCE1set(CLIENT_SOURCE
2 Switchboard.vala2 Switchboard.vala
3 CategoryView.vala3 CategoryView.vala
4 PlugsSearch.vala
4 EmbeddedAlert.vala5 EmbeddedAlert.vala
5 NavigationButton.vala6 NavigationButton.vala
6)7)
78
=== modified file 'src/CategoryView.vala'
--- src/CategoryView.vala 2016-01-13 20:05:32 +0000
+++ src/CategoryView.vala 2016-02-07 15:47:43 +0000
@@ -42,16 +42,19 @@
42 public Gtk.IconView hardware_iconview;42 public Gtk.IconView hardware_iconview;
43 public Gtk.IconView network_iconview;43 public Gtk.IconView network_iconview;
44 public Gtk.IconView system_iconview;44 public Gtk.IconView system_iconview;
45 public Gee.ArrayList<SearchEntry?> plug_search_result;
4546
46 private string? plug_to_open = null;47 private string? plug_to_open = null;
48 private PlugsSearch plug_search;
4749
48 public CategoryView (string? plug_to_open = null) {50 public CategoryView (string? plug_to_open = null) {
49 this.plug_to_open = plug_to_open;51 this.plug_to_open = plug_to_open;
50
51 setup_category (Switchboard.Plug.Category.PERSONAL, 0);52 setup_category (Switchboard.Plug.Category.PERSONAL, 0);
52 setup_category (Switchboard.Plug.Category.HARDWARE, 1);53 setup_category (Switchboard.Plug.Category.HARDWARE, 1);
53 setup_category (Switchboard.Plug.Category.NETWORK, 2);54 setup_category (Switchboard.Plug.Category.NETWORK, 2);
54 setup_category (Switchboard.Plug.Category.SYSTEM, 3);55 setup_category (Switchboard.Plug.Category.SYSTEM, 3);
56 plug_search = new PlugsSearch ();
57 plug_search_result = new Gee.ArrayList<SearchEntry?> ();
55 }58 }
5659
57 private void setup_category (Switchboard.Plug.Category category, int i) {60 private void setup_category (Switchboard.Plug.Category category, int i) {
@@ -312,15 +315,25 @@
312 public void filter_plugs (string filter) {315 public void filter_plugs (string filter) {
313316
314 var any_found = false;317 var any_found = false;
315318 var model_filter = (Gtk.TreeModelFilter) personal_iconview.get_model ();
316 if (search_by_category (filter, Switchboard.Plug.Category.PERSONAL))319 if (search_by_category (filter, model_filter, personal_grid)) {
317 any_found = true;320 any_found = true;
318 if (search_by_category (filter, Switchboard.Plug.Category.HARDWARE))321 }
319 any_found = true;322
320 if (search_by_category (filter, Switchboard.Plug.Category.NETWORK))323 model_filter = (Gtk.TreeModelFilter) hardware_iconview.get_model ();
321 any_found = true;324 if (search_by_category (filter, model_filter, hardware_grid)) {
322 if (search_by_category (filter, Switchboard.Plug.Category.SYSTEM))325 any_found = true;
323 any_found = true;326 }
327
328 model_filter = (Gtk.TreeModelFilter) network_iconview.get_model ();
329 if (search_by_category (filter, model_filter, network_grid)) {
330 any_found = true;
331 }
332
333 model_filter = (Gtk.TreeModelFilter) system_iconview.get_model ();
334 if (search_by_category (filter, model_filter, system_grid)) {
335 any_found = true;
336 }
324337
325 unowned SwitchboardApp app = (SwitchboardApp) GLib.Application.get_default ();338 unowned SwitchboardApp app = (SwitchboardApp) GLib.Application.get_default ();
326 if (!any_found) {339 if (!any_found) {
@@ -330,43 +343,39 @@
330 }343 }
331 }344 }
332345
333 private bool search_by_category (string filter, Plug.Category category) {346 private void deep_search (string filter) {
334347 if (plug_search.ready) {
335 Gtk.TreeModelFilter model_filter;348 plug_search_result.clear ();
336 Gtk.Widget grid;349 foreach (var tmp in plug_search.search_entries) {
337350 if (tmp.ui_elements.down ().contains (filter.down ())) {
338 switch (category) {351 plug_search_result.add (tmp);
339 case Switchboard.Plug.Category.PERSONAL:352 }
340 model_filter = (Gtk.TreeModelFilter)personal_iconview.get_model ();353 }
341 grid = personal_grid;
342 break;
343 case Switchboard.Plug.Category.HARDWARE:
344 model_filter = (Gtk.TreeModelFilter)hardware_iconview.get_model ();
345 grid = hardware_grid;
346 break;
347 case Switchboard.Plug.Category.NETWORK:
348 model_filter = (Gtk.TreeModelFilter)network_iconview.get_model ();
349 grid = network_grid;
350 break;
351 case Switchboard.Plug.Category.SYSTEM:
352 model_filter = (Gtk.TreeModelFilter)system_iconview.get_model ();
353 grid = system_grid;
354 break;
355 default:
356 return false;
357 }354 }
358355 }
356
357 private bool search_by_category (string filter, Gtk.TreeModelFilter model_filter, Gtk.Widget grid) {
358
359 deep_search (filter);
359 var store = model_filter.child_model as Gtk.ListStore;360 var store = model_filter.child_model as Gtk.ListStore;
360 int shown = 0;361 int shown = 0;
361 store.foreach ((model, path, iter) => {362 store.foreach ((model, path, iter) => {
362 string title;363 string title;
363364
364 store.get (iter, Columns.TEXT, out title);365 store.get (iter, Columns.TEXT, out title);
366 bool show_element = false;
367 foreach (var tmp in plug_search_result) {
368 if (tmp.plug_name.down () in title.down ()) {
369 store.set_value (iter, Columns.VISIBLE, true);
370 shown++;
371 show_element = true;
372 }
373 }
365374
366 if (filter.down () in title.down ()) {375 if (filter.down () in title.down ()) {
367 store.set_value (iter, Columns.VISIBLE, true);376 store.set_value (iter, Columns.VISIBLE, true);
368 shown++;377 shown++;
369 } else {378 } else if (!show_element) {
370 store.set_value (iter, Columns.VISIBLE, false);379 store.set_value (iter, Columns.VISIBLE, false);
371 }380 }
372381
373382
=== added file 'src/PlugsSearch.vala'
--- src/PlugsSearch.vala 1970-01-01 00:00:00 +0000
+++ src/PlugsSearch.vala 2016-02-07 15:47:43 +0000
@@ -0,0 +1,64 @@
1/*-
2 * Copyright (c) 2015-2016 elementary LLC.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Kay van der Zander <kay20@hotmail.com>
18 */
19
20namespace Switchboard {
21
22 public struct SearchEntry {
23 string plug_name;
24 string ui_elements;
25 string open_window;
26 }
27
28 public class PlugsSearch {
29
30 public Gee.ArrayList<SearchEntry?> search_entries;
31 public bool ready {get; private set;}
32
33 public PlugsSearch () {
34 ready = false;
35 search_entries = new Gee.ArrayList<SearchEntry?>();
36 cache_search_entries.begin((obj, res) => {
37 cache_search_entries.end (res);
38 ready = true;
39 });
40 }
41
42 // key ("%s → %s".printf (display_name, _("Network Time")))
43 public async void cache_search_entries () {
44 var plugsmanager = Switchboard.PlugsManager.get_default ();
45
46 foreach (var plug in plugsmanager.get_plugs ()) {
47 var tmp_entries = yield plug.search ("");
48
49 foreach (var entry in tmp_entries.entries) {
50 string [] tmp = entry.key.split(" → ");
51 SearchEntry tmp_entry = SearchEntry ();
52 tmp_entry.plug_name = tmp[0];
53 string ui_elements_name = entry.key;
54 tmp_entry.ui_elements = ui_elements_name;
55 tmp_entry.open_window = entry.value;
56 search_entries.add (tmp_entry);
57 debug ("plugsSearch: add open window: %s ", tmp_entry.open_window);
58 debug ("plugsSearch: add ui elements: %s ", tmp_entry.ui_elements);
59 debug ("plugsSearch: add plug name: %s ", tmp_entry.plug_name);
60 }
61 }
62 }
63 }
64}
065
=== modified file 'src/Switchboard.vala'
--- src/Switchboard.vala 2015-12-04 11:00:41 +0000
+++ src/Switchboard.vala 2016-02-07 15:47:43 +0000
@@ -182,6 +182,20 @@
182 loaded_plugs.add (plug.code_name);182 loaded_plugs.add (plug.code_name);
183 }183 }
184184
185 category_view.plug_search_result.foreach ((entry) => {
186 if (plug.display_name == entry.plug_name) {
187 if (entry.open_window == null) {
188 plug.search_callback (""); // open default in the switch
189 } else {
190 plug.search_callback (entry.open_window);
191 }
192 debug ("open section:%s of plug: %s",entry.open_window, plug.display_name);
193 return true;
194 }
195
196 return false;
197 });
198
185 previous_plugs.add (plug);199 previous_plugs.add (plug);
186200
187 // Launch plug's executable201 // Launch plug's executable

Subscribers

People subscribed via source and target branches