Merge lp:~stolowski/unity-scope-home/privacy-and-disabled-scopes into lp:unity-scope-home

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 81
Merged at revision: 76
Proposed branch: lp:~stolowski/unity-scope-home/privacy-and-disabled-scopes
Merge into: lp:unity-scope-home
Diff against target: 233 lines (+90/-11)
5 files modified
src/scope-manager.vala (+44/-0)
src/scope.vala (+35/-3)
src/smart-scopes-interface.vala (+1/-1)
src/smart-scopes-search.vala (+8/-5)
tests/unit/test-home-scope.vala (+2/-2)
To merge this branch: bzr merge lp:~stolowski/unity-scope-home/privacy-and-disabled-scopes
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+155045@code.launchpad.net

Commit message

Handle remote-content-search and disabled-scopes gsettings flags.

Description of the change

Handle remote-content-search and disabled-scopes gsettings flags.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

49 + public string[] disabled_scopes
50 + {
51 + get
52 + {
53 + return preferences.disabled_scopes;
54 + }
55 + }
56 +

Why the extra copy when there's the Set?

review: Needs Information
Revision history for this message
Michal Hruby (mhr3) wrote :

>
> Why the extra copy when there's the Set?

Solved on IRC.. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/scope-manager.vala'
2--- src/scope-manager.vala 2013-03-21 21:40:00 +0000
3+++ src/scope-manager.vala 2013-03-22 19:42:24 +0000
4@@ -24,23 +24,67 @@
5 private PreferencesManager preferences = PreferencesManager.get_default ();
6 private MasterScopesManager master_scopes_mgr = new MasterScopesManager ();
7 private Gee.Set<string> client_scopes = new Gee.HashSet<string> ();
8+ private Gee.Set<string> disabled_scopes_lut = new Gee.HashSet<string> ();
9
10 private Settings gp_settings;
11 private const string HOMELENS_DEFAULT_VIEW = "home-lens-default-view";
12+ private const string DISABLED_SCOPES_KEY = "disabled-scopes";
13+ private const string REMOTE_CONTENT_KEY = "remote-content-search";
14
15 public ScopeManager ()
16 {
17 gp_settings = new Settings ("com.canonical.Unity.Lenses");
18 gp_settings.bind (HOMELENS_DEFAULT_VIEW, this, "home_lens_default_view", SettingsBindFlags.DEFAULT); // bind get/set
19+
20+ update_disabled_scopes ();
21+
22+ preferences.notify[DISABLED_SCOPES_KEY].connect ((obj, pspec) =>
23+ {
24+ update_disabled_scopes ();
25+ });
26+
27+ update_remote_content_search ();
28+ preferences.notify[REMOTE_CONTENT_KEY].connect ((obj, pspec) =>
29+ {
30+ update_remote_content_search ();
31+ });
32+ }
33+
34+ private void update_remote_content_search ()
35+ {
36+ remote_content_search = (preferences.remote_content_search == Unity.PreferencesManager.RemoteContent.ALL);
37+ }
38+
39+ private void update_disabled_scopes ()
40+ {
41+ disabled_scopes_lut.clear ();
42+ foreach (var scope_id in preferences.disabled_scopes)
43+ {
44+ disabled_scopes_lut.add (scope_id);
45+ }
46 }
47
48 public string[] home_lens_default_view { get; set; default = new string[0]; }
49+ public string[] disabled_scopes
50+ {
51+ get
52+ {
53+ return preferences.disabled_scopes;
54+ }
55+ }
56+
57+ public bool remote_content_search { get; internal set; }
58
59 public void start_master_scopes ()
60 {
61 master_scopes_mgr.start ();
62 }
63
64+ public bool is_disabled (string scope_id)
65+ {
66+ return disabled_scopes_lut.contains (scope_id);
67+ }
68+
69 public bool is_client_scope (string scope_id)
70 {
71 if (client_scopes.size == 0)
72
73=== modified file 'src/scope.vala'
74--- src/scope.vala 2013-03-22 15:59:12 +0000
75+++ src/scope.vala 2013-03-22 19:42:24 +0000
76@@ -75,6 +75,11 @@
77 debug ("Exporting home scope");
78 export ();
79
80+ scope_mgr.notify["remote-content-search"].connect ((obj, pspec) =>
81+ {
82+ remote_content_search_changed ();
83+ });
84+
85 init_sss_client ();
86 }
87
88@@ -98,8 +103,32 @@
89 ml.run ();
90 }
91
92+ internal void remote_content_search_changed ()
93+ {
94+ debug ("remote-content-search flag changed");
95+
96+ if (!scope_mgr.remote_content_search)
97+ {
98+ if (smart_scopes_initialized)
99+ {
100+ debug ("Disabling Smart Scopes Server connectivity");
101+ smart_scopes_initialized = false;
102+ smart_scopes_ready = false;
103+ if (metrics_timer > 0)
104+ {
105+ GLib.Source.remove (metrics_timer);
106+ metrics_timer = 0;
107+ }
108+ sss_client = null;
109+ }
110+ } // don't do anything if it got enabled - this will be handled on next search ()
111+ }
112+
113 internal void init_sss_client ()
114 {
115+ if (scope_mgr.remote_content_search == false)
116+ return;
117+
118 if (!smart_scopes_initialized)
119 {
120 debug ("Initializing Smart Scopes client");
121@@ -342,6 +371,9 @@
122 internal override async ActivationResponse? activate (Unity.AggregatorActivation activation)
123 {
124 debug ("Activation request for scope %s, action_type=%u", activation.scope_id, activation.action_type);
125+
126+ if (!scope_mgr.remote_content_search)
127+ return null; //nothing to do
128
129 string? server_sid = channel_id_map.server_sid_for_channel (activation.channel_id);
130 string? session_id = channel_id_map.session_id_for_channel (activation.channel_id);
131@@ -463,7 +495,7 @@
132 }
133
134 // initiate Smart Scopes Search (if enabled and query not empty)
135- if (smart_scopes_ready == true)
136+ if (smart_scopes_ready)
137 {
138 if (empty_query)
139 {
140@@ -504,7 +536,7 @@
141 remote_scopes_to_query += scope_id;
142 }
143
144- sss_client.search.begin (scope_search.search_string, session_id, remote_scopes_to_query,
145+ sss_client.search.begin (scope_search.search_string, session_id, remote_scopes_to_query, scope_mgr.disabled_scopes,
146 (scope_id, row) =>
147 {
148 var pushed_model = push_data.lookup (scope_id);
149@@ -539,7 +571,7 @@
150 else
151 {
152 // may happen if remote-scopes haven't finished or returned an error
153- warning ("Smart scopes not ready and not enabled for this query");
154+ debug ("Smart scopes not ready or not enabled for this query");
155 }
156
157 // no filters set / no scopes to search, use always-search scopes
158
159=== modified file 'src/smart-scopes-interface.vala'
160--- src/smart-scopes-interface.vala 2013-03-21 22:10:04 +0000
161+++ src/smart-scopes-interface.vala 2013-03-22 19:42:24 +0000
162@@ -48,7 +48,7 @@
163 public interface SmartScopeClientInterface : Object
164 {
165 public abstract string create_session_id ();
166- public abstract async void search (string query, string session_id, string[] scopes, SmartScopeResult result_cb,
167+ public abstract async void search (string query, string session_id, string[] scopes, string[] disabled_scopes, SmartScopeResult result_cb,
168 SmartScopeCategories categories_cb, SmartScopeRecommendations recommend_cb, GLib.Cancellable? cancellable) throws Error;
169 public abstract async Preview? preview (string server_sid, string session_id, string result_id, ScopeResult result, GLib.Cancellable? cancellable) throws Error;
170 public abstract async RemoteScopeInfo[]? remote_scopes (GLib.Cancellable? cancellable) throws Error;
171
172=== modified file 'src/smart-scopes-search.vala'
173--- src/smart-scopes-search.vala 2013-03-22 13:41:11 +0000
174+++ src/smart-scopes-search.vala 2013-03-22 19:42:24 +0000
175@@ -241,10 +241,10 @@
176 return null;
177 }
178
179- public async void search (string query, string session_id, string[] scopes, SmartScopeResult result_cb,
180+ public async void search (string query, string session_id, string[] scopes, string[] disabled_scopes, SmartScopeResult result_cb,
181 SmartScopeCategories categories_cb, SmartScopeRecommendations recommend_cb, GLib.Cancellable? cancellable) throws Error
182 {
183- var uri = build_search_uri (query, session_id, scopes);
184+ var uri = build_search_uri (query, session_id, scopes, disabled_scopes);
185 debug ("Dispatching query '%s' to %s", query, uri);
186
187 if (search_requests.contains (session_id))
188@@ -340,7 +340,7 @@
189 metrics.add_found_event (session_id, server_sid, scope_results, timestamp);
190 }
191
192- internal string build_search_uri (string query, string session_id, string[] scopes = {})
193+ internal string build_search_uri (string query, string session_id, string[] scopes = {}, string[] disabled_scopes = {})
194 {
195 var sb = new StringBuilder (base_uri);
196 sb.append (SEARCH_URI);
197@@ -362,9 +362,12 @@
198 sb.append ("&added_scopes=");
199 sb.append (added_scopes);
200 }
201- if (info.removed_scopes.length > 0)
202+ if (info.removed_scopes.length > 0 || disabled_scopes.length > 0)
203 {
204- var removed_scopes = string.joinv (",", info.removed_scopes);
205+ var rscopes = info.removed_scopes;
206+ foreach (var id in disabled_scopes)
207+ rscopes += id;
208+ var removed_scopes = string.joinv (",", rscopes);
209 sb.append ("&removed_scopes=");
210 sb.append (removed_scopes);
211 }
212
213=== modified file 'tests/unit/test-home-scope.vala'
214--- tests/unit/test-home-scope.vala 2013-03-22 13:41:46 +0000
215+++ tests/unit/test-home-scope.vala 2013-03-22 19:42:24 +0000
216@@ -1024,7 +1024,7 @@
217
218 int num_results = 0;
219 int num_recommend = 0;
220- client.search.begin ("foo", session_id, {"scope3"}, (scope_id, row) =>
221+ client.search.begin ("foo", session_id, {"scope3"}, {}, (scope_id, row) =>
222 {
223 num_results++;
224 },
225@@ -1158,7 +1158,7 @@
226
227 var ml = new MainLoop ();
228
229- client.search.begin ("foo", session_id, {"scope3"}, (scope_id, row) =>
230+ client.search.begin ("foo", session_id, {"scope3"}, {}, (scope_id, row) =>
231 {
232 assert_not_reached ();
233 },

Subscribers

People subscribed via source and target branches

to all changes: