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
1=== modified file 'lib/PlugsManager.vala'
2--- lib/PlugsManager.vala 2014-12-01 21:07:00 +0000
3+++ lib/PlugsManager.vala 2016-02-07 15:47:43 +0000
4@@ -102,4 +102,4 @@
5 public Gee.Collection<Switchboard.Plug> get_plugs () {
6 return plugs.read_only_view;
7 }
8-}
9\ No newline at end of file
10+}
11
12=== modified file 'src/CMakeLists.txt'
13--- src/CMakeLists.txt 2014-04-14 20:39:34 +0000
14+++ src/CMakeLists.txt 2016-02-07 15:47:43 +0000
15@@ -1,6 +1,7 @@
16 set(CLIENT_SOURCE
17 Switchboard.vala
18 CategoryView.vala
19+ PlugsSearch.vala
20 EmbeddedAlert.vala
21 NavigationButton.vala
22 )
23
24=== modified file 'src/CategoryView.vala'
25--- src/CategoryView.vala 2016-01-13 20:05:32 +0000
26+++ src/CategoryView.vala 2016-02-07 15:47:43 +0000
27@@ -42,16 +42,19 @@
28 public Gtk.IconView hardware_iconview;
29 public Gtk.IconView network_iconview;
30 public Gtk.IconView system_iconview;
31+ public Gee.ArrayList<SearchEntry?> plug_search_result;
32
33 private string? plug_to_open = null;
34+ private PlugsSearch plug_search;
35
36 public CategoryView (string? plug_to_open = null) {
37 this.plug_to_open = plug_to_open;
38-
39 setup_category (Switchboard.Plug.Category.PERSONAL, 0);
40 setup_category (Switchboard.Plug.Category.HARDWARE, 1);
41 setup_category (Switchboard.Plug.Category.NETWORK, 2);
42 setup_category (Switchboard.Plug.Category.SYSTEM, 3);
43+ plug_search = new PlugsSearch ();
44+ plug_search_result = new Gee.ArrayList<SearchEntry?> ();
45 }
46
47 private void setup_category (Switchboard.Plug.Category category, int i) {
48@@ -312,15 +315,25 @@
49 public void filter_plugs (string filter) {
50
51 var any_found = false;
52-
53- if (search_by_category (filter, Switchboard.Plug.Category.PERSONAL))
54- any_found = true;
55- if (search_by_category (filter, Switchboard.Plug.Category.HARDWARE))
56- any_found = true;
57- if (search_by_category (filter, Switchboard.Plug.Category.NETWORK))
58- any_found = true;
59- if (search_by_category (filter, Switchboard.Plug.Category.SYSTEM))
60- any_found = true;
61+ var model_filter = (Gtk.TreeModelFilter) personal_iconview.get_model ();
62+ if (search_by_category (filter, model_filter, personal_grid)) {
63+ any_found = true;
64+ }
65+
66+ model_filter = (Gtk.TreeModelFilter) hardware_iconview.get_model ();
67+ if (search_by_category (filter, model_filter, hardware_grid)) {
68+ any_found = true;
69+ }
70+
71+ model_filter = (Gtk.TreeModelFilter) network_iconview.get_model ();
72+ if (search_by_category (filter, model_filter, network_grid)) {
73+ any_found = true;
74+ }
75+
76+ model_filter = (Gtk.TreeModelFilter) system_iconview.get_model ();
77+ if (search_by_category (filter, model_filter, system_grid)) {
78+ any_found = true;
79+ }
80
81 unowned SwitchboardApp app = (SwitchboardApp) GLib.Application.get_default ();
82 if (!any_found) {
83@@ -330,43 +343,39 @@
84 }
85 }
86
87- private bool search_by_category (string filter, Plug.Category category) {
88-
89- Gtk.TreeModelFilter model_filter;
90- Gtk.Widget grid;
91-
92- switch (category) {
93- case Switchboard.Plug.Category.PERSONAL:
94- model_filter = (Gtk.TreeModelFilter)personal_iconview.get_model ();
95- grid = personal_grid;
96- break;
97- case Switchboard.Plug.Category.HARDWARE:
98- model_filter = (Gtk.TreeModelFilter)hardware_iconview.get_model ();
99- grid = hardware_grid;
100- break;
101- case Switchboard.Plug.Category.NETWORK:
102- model_filter = (Gtk.TreeModelFilter)network_iconview.get_model ();
103- grid = network_grid;
104- break;
105- case Switchboard.Plug.Category.SYSTEM:
106- model_filter = (Gtk.TreeModelFilter)system_iconview.get_model ();
107- grid = system_grid;
108- break;
109- default:
110- return false;
111+ private void deep_search (string filter) {
112+ if (plug_search.ready) {
113+ plug_search_result.clear ();
114+ foreach (var tmp in plug_search.search_entries) {
115+ if (tmp.ui_elements.down ().contains (filter.down ())) {
116+ plug_search_result.add (tmp);
117+ }
118+ }
119 }
120-
121+ }
122+
123+ private bool search_by_category (string filter, Gtk.TreeModelFilter model_filter, Gtk.Widget grid) {
124+
125+ deep_search (filter);
126 var store = model_filter.child_model as Gtk.ListStore;
127 int shown = 0;
128 store.foreach ((model, path, iter) => {
129 string title;
130
131 store.get (iter, Columns.TEXT, out title);
132+ bool show_element = false;
133+ foreach (var tmp in plug_search_result) {
134+ if (tmp.plug_name.down () in title.down ()) {
135+ store.set_value (iter, Columns.VISIBLE, true);
136+ shown++;
137+ show_element = true;
138+ }
139+ }
140
141 if (filter.down () in title.down ()) {
142 store.set_value (iter, Columns.VISIBLE, true);
143 shown++;
144- } else {
145+ } else if (!show_element) {
146 store.set_value (iter, Columns.VISIBLE, false);
147 }
148
149
150=== added file 'src/PlugsSearch.vala'
151--- src/PlugsSearch.vala 1970-01-01 00:00:00 +0000
152+++ src/PlugsSearch.vala 2016-02-07 15:47:43 +0000
153@@ -0,0 +1,64 @@
154+/*-
155+ * Copyright (c) 2015-2016 elementary LLC.
156+ *
157+ * This program is free software: you can redistribute it and/or modify
158+ * it under the terms of the GNU Lesser General Public License as published by
159+ * the Free Software Foundation, either version 2.1 of the License, or
160+ * (at your option) any later version.
161+ *
162+ * This program is distributed in the hope that it will be useful,
163+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
164+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
165+ * GNU Lesser General Public License for more details.
166+ *
167+ * You should have received a copy of the GNU Lesser General Public License
168+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
169+ *
170+ * Authored by: Kay van der Zander <kay20@hotmail.com>
171+ */
172+
173+namespace Switchboard {
174+
175+ public struct SearchEntry {
176+ string plug_name;
177+ string ui_elements;
178+ string open_window;
179+ }
180+
181+ public class PlugsSearch {
182+
183+ public Gee.ArrayList<SearchEntry?> search_entries;
184+ public bool ready {get; private set;}
185+
186+ public PlugsSearch () {
187+ ready = false;
188+ search_entries = new Gee.ArrayList<SearchEntry?>();
189+ cache_search_entries.begin((obj, res) => {
190+ cache_search_entries.end (res);
191+ ready = true;
192+ });
193+ }
194+
195+ // key ("%s → %s".printf (display_name, _("Network Time")))
196+ public async void cache_search_entries () {
197+ var plugsmanager = Switchboard.PlugsManager.get_default ();
198+
199+ foreach (var plug in plugsmanager.get_plugs ()) {
200+ var tmp_entries = yield plug.search ("");
201+
202+ foreach (var entry in tmp_entries.entries) {
203+ string [] tmp = entry.key.split(" → ");
204+ SearchEntry tmp_entry = SearchEntry ();
205+ tmp_entry.plug_name = tmp[0];
206+ string ui_elements_name = entry.key;
207+ tmp_entry.ui_elements = ui_elements_name;
208+ tmp_entry.open_window = entry.value;
209+ search_entries.add (tmp_entry);
210+ debug ("plugsSearch: add open window: %s ", tmp_entry.open_window);
211+ debug ("plugsSearch: add ui elements: %s ", tmp_entry.ui_elements);
212+ debug ("plugsSearch: add plug name: %s ", tmp_entry.plug_name);
213+ }
214+ }
215+ }
216+ }
217+}
218
219=== modified file 'src/Switchboard.vala'
220--- src/Switchboard.vala 2015-12-04 11:00:41 +0000
221+++ src/Switchboard.vala 2016-02-07 15:47:43 +0000
222@@ -182,6 +182,20 @@
223 loaded_plugs.add (plug.code_name);
224 }
225
226+ category_view.plug_search_result.foreach ((entry) => {
227+ if (plug.display_name == entry.plug_name) {
228+ if (entry.open_window == null) {
229+ plug.search_callback (""); // open default in the switch
230+ } else {
231+ plug.search_callback (entry.open_window);
232+ }
233+ debug ("open section:%s of plug: %s",entry.open_window, plug.display_name);
234+ return true;
235+ }
236+
237+ return false;
238+ });
239+
240 previous_plugs.add (plug);
241
242 // Launch plug's executable

Subscribers

People subscribed via source and target branches