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
=== modified file 'src/scope-manager.vala'
--- src/scope-manager.vala 2013-03-21 21:40:00 +0000
+++ src/scope-manager.vala 2013-03-22 19:42:24 +0000
@@ -24,23 +24,67 @@
24 private PreferencesManager preferences = PreferencesManager.get_default ();24 private PreferencesManager preferences = PreferencesManager.get_default ();
25 private MasterScopesManager master_scopes_mgr = new MasterScopesManager ();25 private MasterScopesManager master_scopes_mgr = new MasterScopesManager ();
26 private Gee.Set<string> client_scopes = new Gee.HashSet<string> ();26 private Gee.Set<string> client_scopes = new Gee.HashSet<string> ();
27 private Gee.Set<string> disabled_scopes_lut = new Gee.HashSet<string> ();
2728
28 private Settings gp_settings;29 private Settings gp_settings;
29 private const string HOMELENS_DEFAULT_VIEW = "home-lens-default-view";30 private const string HOMELENS_DEFAULT_VIEW = "home-lens-default-view";
31 private const string DISABLED_SCOPES_KEY = "disabled-scopes";
32 private const string REMOTE_CONTENT_KEY = "remote-content-search";
3033
31 public ScopeManager ()34 public ScopeManager ()
32 {35 {
33 gp_settings = new Settings ("com.canonical.Unity.Lenses");36 gp_settings = new Settings ("com.canonical.Unity.Lenses");
34 gp_settings.bind (HOMELENS_DEFAULT_VIEW, this, "home_lens_default_view", SettingsBindFlags.DEFAULT); // bind get/set37 gp_settings.bind (HOMELENS_DEFAULT_VIEW, this, "home_lens_default_view", SettingsBindFlags.DEFAULT); // bind get/set
38
39 update_disabled_scopes ();
40
41 preferences.notify[DISABLED_SCOPES_KEY].connect ((obj, pspec) =>
42 {
43 update_disabled_scopes ();
44 });
45
46 update_remote_content_search ();
47 preferences.notify[REMOTE_CONTENT_KEY].connect ((obj, pspec) =>
48 {
49 update_remote_content_search ();
50 });
51 }
52
53 private void update_remote_content_search ()
54 {
55 remote_content_search = (preferences.remote_content_search == Unity.PreferencesManager.RemoteContent.ALL);
56 }
57
58 private void update_disabled_scopes ()
59 {
60 disabled_scopes_lut.clear ();
61 foreach (var scope_id in preferences.disabled_scopes)
62 {
63 disabled_scopes_lut.add (scope_id);
64 }
35 }65 }
3666
37 public string[] home_lens_default_view { get; set; default = new string[0]; }67 public string[] home_lens_default_view { get; set; default = new string[0]; }
68 public string[] disabled_scopes
69 {
70 get
71 {
72 return preferences.disabled_scopes;
73 }
74 }
75
76 public bool remote_content_search { get; internal set; }
3877
39 public void start_master_scopes ()78 public void start_master_scopes ()
40 {79 {
41 master_scopes_mgr.start ();80 master_scopes_mgr.start ();
42 }81 }
4382
83 public bool is_disabled (string scope_id)
84 {
85 return disabled_scopes_lut.contains (scope_id);
86 }
87
44 public bool is_client_scope (string scope_id)88 public bool is_client_scope (string scope_id)
45 {89 {
46 if (client_scopes.size == 0)90 if (client_scopes.size == 0)
4791
=== modified file 'src/scope.vala'
--- src/scope.vala 2013-03-22 15:59:12 +0000
+++ src/scope.vala 2013-03-22 19:42:24 +0000
@@ -75,6 +75,11 @@
75 debug ("Exporting home scope");75 debug ("Exporting home scope");
76 export ();76 export ();
7777
78 scope_mgr.notify["remote-content-search"].connect ((obj, pspec) =>
79 {
80 remote_content_search_changed ();
81 });
82
78 init_sss_client ();83 init_sss_client ();
79 }84 }
8085
@@ -98,8 +103,32 @@
98 ml.run ();103 ml.run ();
99 }104 }
100105
106 internal void remote_content_search_changed ()
107 {
108 debug ("remote-content-search flag changed");
109
110 if (!scope_mgr.remote_content_search)
111 {
112 if (smart_scopes_initialized)
113 {
114 debug ("Disabling Smart Scopes Server connectivity");
115 smart_scopes_initialized = false;
116 smart_scopes_ready = false;
117 if (metrics_timer > 0)
118 {
119 GLib.Source.remove (metrics_timer);
120 metrics_timer = 0;
121 }
122 sss_client = null;
123 }
124 } // don't do anything if it got enabled - this will be handled on next search ()
125 }
126
101 internal void init_sss_client ()127 internal void init_sss_client ()
102 {128 {
129 if (scope_mgr.remote_content_search == false)
130 return;
131
103 if (!smart_scopes_initialized)132 if (!smart_scopes_initialized)
104 {133 {
105 debug ("Initializing Smart Scopes client");134 debug ("Initializing Smart Scopes client");
@@ -342,6 +371,9 @@
342 internal override async ActivationResponse? activate (Unity.AggregatorActivation activation)371 internal override async ActivationResponse? activate (Unity.AggregatorActivation activation)
343 {372 {
344 debug ("Activation request for scope %s, action_type=%u", activation.scope_id, activation.action_type);373 debug ("Activation request for scope %s, action_type=%u", activation.scope_id, activation.action_type);
374
375 if (!scope_mgr.remote_content_search)
376 return null; //nothing to do
345 377
346 string? server_sid = channel_id_map.server_sid_for_channel (activation.channel_id);378 string? server_sid = channel_id_map.server_sid_for_channel (activation.channel_id);
347 string? session_id = channel_id_map.session_id_for_channel (activation.channel_id);379 string? session_id = channel_id_map.session_id_for_channel (activation.channel_id);
@@ -463,7 +495,7 @@
463 }495 }
464496
465 // initiate Smart Scopes Search (if enabled and query not empty)497 // initiate Smart Scopes Search (if enabled and query not empty)
466 if (smart_scopes_ready == true)498 if (smart_scopes_ready)
467 {499 {
468 if (empty_query)500 if (empty_query)
469 { 501 {
@@ -504,7 +536,7 @@
504 remote_scopes_to_query += scope_id;536 remote_scopes_to_query += scope_id;
505 }537 }
506538
507 sss_client.search.begin (scope_search.search_string, session_id, remote_scopes_to_query,539 sss_client.search.begin (scope_search.search_string, session_id, remote_scopes_to_query, scope_mgr.disabled_scopes,
508 (scope_id, row) =>540 (scope_id, row) =>
509 {541 {
510 var pushed_model = push_data.lookup (scope_id);542 var pushed_model = push_data.lookup (scope_id);
@@ -539,7 +571,7 @@
539 else571 else
540 {572 {
541 // may happen if remote-scopes haven't finished or returned an error573 // may happen if remote-scopes haven't finished or returned an error
542 warning ("Smart scopes not ready and not enabled for this query");574 debug ("Smart scopes not ready or not enabled for this query");
543 }575 }
544576
545 // no filters set / no scopes to search, use always-search scopes577 // no filters set / no scopes to search, use always-search scopes
546578
=== modified file 'src/smart-scopes-interface.vala'
--- src/smart-scopes-interface.vala 2013-03-21 22:10:04 +0000
+++ src/smart-scopes-interface.vala 2013-03-22 19:42:24 +0000
@@ -48,7 +48,7 @@
48 public interface SmartScopeClientInterface : Object48 public interface SmartScopeClientInterface : Object
49 {49 {
50 public abstract string create_session_id ();50 public abstract string create_session_id ();
51 public abstract async void search (string query, string session_id, string[] scopes, SmartScopeResult result_cb,51 public abstract async void search (string query, string session_id, string[] scopes, string[] disabled_scopes, SmartScopeResult result_cb,
52 SmartScopeCategories categories_cb, SmartScopeRecommendations recommend_cb, GLib.Cancellable? cancellable) throws Error;52 SmartScopeCategories categories_cb, SmartScopeRecommendations recommend_cb, GLib.Cancellable? cancellable) throws Error;
53 public abstract async Preview? preview (string server_sid, string session_id, string result_id, ScopeResult result, GLib.Cancellable? cancellable) throws Error;53 public abstract async Preview? preview (string server_sid, string session_id, string result_id, ScopeResult result, GLib.Cancellable? cancellable) throws Error;
54 public abstract async RemoteScopeInfo[]? remote_scopes (GLib.Cancellable? cancellable) throws Error;54 public abstract async RemoteScopeInfo[]? remote_scopes (GLib.Cancellable? cancellable) throws Error;
5555
=== modified file 'src/smart-scopes-search.vala'
--- src/smart-scopes-search.vala 2013-03-22 13:41:11 +0000
+++ src/smart-scopes-search.vala 2013-03-22 19:42:24 +0000
@@ -241,10 +241,10 @@
241 return null;241 return null;
242 }242 }
243243
244 public async void search (string query, string session_id, string[] scopes, SmartScopeResult result_cb,244 public async void search (string query, string session_id, string[] scopes, string[] disabled_scopes, SmartScopeResult result_cb,
245 SmartScopeCategories categories_cb, SmartScopeRecommendations recommend_cb, GLib.Cancellable? cancellable) throws Error245 SmartScopeCategories categories_cb, SmartScopeRecommendations recommend_cb, GLib.Cancellable? cancellable) throws Error
246 {246 {
247 var uri = build_search_uri (query, session_id, scopes);247 var uri = build_search_uri (query, session_id, scopes, disabled_scopes);
248 debug ("Dispatching query '%s' to %s", query, uri);248 debug ("Dispatching query '%s' to %s", query, uri);
249249
250 if (search_requests.contains (session_id))250 if (search_requests.contains (session_id))
@@ -340,7 +340,7 @@
340 metrics.add_found_event (session_id, server_sid, scope_results, timestamp);340 metrics.add_found_event (session_id, server_sid, scope_results, timestamp);
341 }341 }
342342
343 internal string build_search_uri (string query, string session_id, string[] scopes = {})343 internal string build_search_uri (string query, string session_id, string[] scopes = {}, string[] disabled_scopes = {})
344 {344 {
345 var sb = new StringBuilder (base_uri);345 var sb = new StringBuilder (base_uri);
346 sb.append (SEARCH_URI);346 sb.append (SEARCH_URI);
@@ -362,9 +362,12 @@
362 sb.append ("&added_scopes=");362 sb.append ("&added_scopes=");
363 sb.append (added_scopes);363 sb.append (added_scopes);
364 }364 }
365 if (info.removed_scopes.length > 0)365 if (info.removed_scopes.length > 0 || disabled_scopes.length > 0)
366 {366 {
367 var removed_scopes = string.joinv (",", info.removed_scopes);367 var rscopes = info.removed_scopes;
368 foreach (var id in disabled_scopes)
369 rscopes += id;
370 var removed_scopes = string.joinv (",", rscopes);
368 sb.append ("&removed_scopes=");371 sb.append ("&removed_scopes=");
369 sb.append (removed_scopes);372 sb.append (removed_scopes);
370 }373 }
371374
=== modified file 'tests/unit/test-home-scope.vala'
--- tests/unit/test-home-scope.vala 2013-03-22 13:41:46 +0000
+++ tests/unit/test-home-scope.vala 2013-03-22 19:42:24 +0000
@@ -1024,7 +1024,7 @@
10241024
1025 int num_results = 0;1025 int num_results = 0;
1026 int num_recommend = 0;1026 int num_recommend = 0;
1027 client.search.begin ("foo", session_id, {"scope3"}, (scope_id, row) => 1027 client.search.begin ("foo", session_id, {"scope3"}, {}, (scope_id, row) =>
1028 {1028 {
1029 num_results++;1029 num_results++;
1030 },1030 },
@@ -1158,7 +1158,7 @@
11581158
1159 var ml = new MainLoop ();1159 var ml = new MainLoop ();
11601160
1161 client.search.begin ("foo", session_id, {"scope3"}, (scope_id, row) => 1161 client.search.begin ("foo", session_id, {"scope3"}, {}, (scope_id, row) =>
1162 {1162 {
1163 assert_not_reached ();1163 assert_not_reached ();
1164 },1164 },

Subscribers

People subscribed via source and target branches

to all changes: