Merge lp:~stolowski/unity-scope-home/canned-queries-session-id into lp:unity-scope-home

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 167
Merged at revision: 165
Proposed branch: lp:~stolowski/unity-scope-home/canned-queries-session-id
Merge into: lp:unity-scope-home
Diff against target: 129 lines (+50/-19)
3 files modified
src/scope.vala (+4/-1)
src/search-query-state.vala (+34/-18)
tests/unit/test-home-scope.vala (+12/-0)
To merge this branch: bzr merge lp:~stolowski/unity-scope-home/canned-queries-session-id
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+186506@code.launchpad.net

Commit message

Reuse existing session_id for canned queries.

Description of the change

Added new CANNED_QUERY state to SearchQueryChange / SearchQueryState, so that we're able to reuse existing session_id for canned queries.
When a scopes-query:// item is activated, the activation handler sets a flag indicating that upcoming search query for current channel will be a canned query. Search request handler will then receive state == CANNED_QUERY when it calls query_state.search_query_changed.

To post a comment you must log in.
166. By Paweł Stołowski

Remove canned_query flag on remove().

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

What if the scope gets a query "foo", then a canned query is activated, but meanwhile the user changes something and instead of "keyword:foo" the scope gets "bar" as next query?

review: Needs Information
167. By Paweł Stołowski

Keep canned query string in the query state object rather than just bool, and only consider a query to be canned query if the search string matches current search request.

Revision history for this message
Paweł Stołowski (stolowski) wrote :

> What if the scope gets a query "foo", then a canned query is activated, but
> meanwhile the user changes something and instead of "keyword:foo" the scope
> gets "bar" as next query?

Good point, though rather unlikely. Anyway, update the code to deal with this.

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

Looks good now :)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/scope.vala'
--- src/scope.vala 2013-09-04 10:28:06 +0000
+++ src/scope.vala 2013-09-19 13:59:12 +0000
@@ -539,7 +539,10 @@
539 warning ("Invalid UTF8 received from the server");539 warning ("Invalid UTF8 received from the server");
540 }540 }
541541
542 return new ActivationResponse.with_search (escaped_query != null ? escaped_query : query, null, null);542 if (escaped_query != null)
543 query = escaped_query;
544 query_state.set_canned_query (activation.channel_id, query);
545 return new ActivationResponse.with_search (query, null, null);
543 }546 }
544547
545 if (!scope_mgr.remote_content_search || sss_client == null ||548 if (!scope_mgr.remote_content_search || sss_client == null ||
546549
=== modified file 'src/search-query-state.vala'
--- src/search-query-state.vala 2013-03-21 21:40:00 +0000
+++ src/search-query-state.vala 2013-09-19 13:59:12 +0000
@@ -23,6 +23,7 @@
23 {23 {
24 NOT_CHANGED,24 NOT_CHANGED,
25 NEW_QUERY,25 NEW_QUERY,
26 CANNED_QUERY,
26 APPENDS_TO_PREVIOUS_QUERY,27 APPENDS_TO_PREVIOUS_QUERY,
27 REMOVES_FROM_PREVIOUS_QUERY28 REMOVES_FROM_PREVIOUS_QUERY
28 }29 }
@@ -30,10 +31,12 @@
30 public class SearchQueryState31 public class SearchQueryState
31 {32 {
32 private HashTable<string, string> previous_query = new HashTable<string, string> (str_hash, str_equal);33 private HashTable<string, string> previous_query = new HashTable<string, string> (str_hash, str_equal);
34 private HashTable<string, string> canned_query = new HashTable<string, string> (str_hash, str_equal);
33 35
34 public void remove (string home_channel_id)36 public void remove (string home_channel_id)
35 {37 {
36 previous_query.remove (home_channel_id);38 previous_query.remove (home_channel_id);
39 canned_query.remove (home_channel_id);
37 }40 }
3841
39 public bool has_channel (string home_channel_id)42 public bool has_channel (string home_channel_id)
@@ -41,34 +44,47 @@
41 return previous_query.contains (home_channel_id);44 return previous_query.contains (home_channel_id);
42 }45 }
4346
47 public void set_canned_query (string channel_id, string search_string)
48 {
49 canned_query[channel_id] = search_string;
50 }
51
44 /**52 /**
45 * Compare search string with previous string for given home channel. Store new search string.53 * Compare search string with previous string for given home channel. Store new search string.
46 */54 */
47 public SearchQueryChange search_query_changed (string channel_id, string search_string)55 public SearchQueryChange search_query_changed (string channel_id, string search_string)
48 {56 {
49 var query = search_string.strip ();57 var query = search_string.strip ();
50
51 var changed = SearchQueryChange.NEW_QUERY;58 var changed = SearchQueryChange.NEW_QUERY;
52 if (previous_query.contains (channel_id))59
53 {60 if (canned_query.contains(channel_id) && canned_query[channel_id] == query)
54 var prev = previous_query[channel_id];61 {
55 if (query == "" && prev != "") // there was a query previously, but user removed all characters in new one62 changed = SearchQueryChange.CANNED_QUERY;
56 {63 }
57 changed = SearchQueryChange.NEW_QUERY;64 else
58 }65 {
59 else66 if (previous_query.contains (channel_id))
60 {67 {
61 if (prev == query)68 var prev = previous_query[channel_id];
62 changed = SearchQueryChange.NOT_CHANGED;69 if (query == "" && prev != "") // there was a query previously, but user removed all characters in new one
63 else if (prev == "")70 {
64 changed = SearchQueryChange.NEW_QUERY;71 changed = SearchQueryChange.NEW_QUERY;
65 else if (query.has_prefix (prev))72 }
66 changed = SearchQueryChange.APPENDS_TO_PREVIOUS_QUERY;73 else
67 else if (prev.has_prefix (query))74 {
68 changed = SearchQueryChange.REMOVES_FROM_PREVIOUS_QUERY;75 if (prev == query)
76 changed = SearchQueryChange.NOT_CHANGED;
77 else if (prev == "")
78 changed = SearchQueryChange.NEW_QUERY;
79 else if (query.has_prefix (prev))
80 changed = SearchQueryChange.APPENDS_TO_PREVIOUS_QUERY;
81 else if (prev.has_prefix (query))
82 changed = SearchQueryChange.REMOVES_FROM_PREVIOUS_QUERY;
83 }
69 }84 }
70 }85 }
7186
87 canned_query.remove (channel_id);
72 previous_query[channel_id] = query;88 previous_query[channel_id] = query;
7389
74 debug ("search_query_changed for channel %s: %s", channel_id, changed.to_string ());90 debug ("search_query_changed for channel %s: %s", channel_id, changed.to_string ());
7591
=== modified file 'tests/unit/test-home-scope.vala'
--- tests/unit/test-home-scope.vala 2013-09-04 10:28:06 +0000
+++ tests/unit/test-home-scope.vala 2013-09-19 13:59:12 +0000
@@ -230,6 +230,18 @@
230 assert (search_state.search_query_changed ("channel1", "te") == SearchQueryChange.REMOVES_FROM_PREVIOUS_QUERY);230 assert (search_state.search_query_changed ("channel1", "te") == SearchQueryChange.REMOVES_FROM_PREVIOUS_QUERY);
231 assert (search_state.search_query_changed ("channel1", "") == SearchQueryChange.NEW_QUERY);231 assert (search_state.search_query_changed ("channel1", "") == SearchQueryChange.NEW_QUERY);
232 assert (search_state.has_channel ("channel1") == true);232 assert (search_state.has_channel ("channel1") == true);
233
234 // simulate canned queries
235 assert (search_state.search_query_changed ("channel1", "ab") == SearchQueryChange.NEW_QUERY);
236 search_state.set_canned_query("channel1", "foo:lo");
237 assert (search_state.search_query_changed ("channel1", "foo:lo") == SearchQueryChange.CANNED_QUERY);
238 assert (search_state.search_query_changed ("channel1", "foo:lo") == SearchQueryChange.NOT_CHANGED);
239
240 // simulate canned queries, user types a query immediately after activation
241 assert (search_state.search_query_changed ("channel1", "me") == SearchQueryChange.NEW_QUERY);
242 search_state.set_canned_query("channel1", "foo:metallica");
243 assert (search_state.search_query_changed ("channel1", "iron maiden") == SearchQueryChange.NEW_QUERY);
244 assert (search_state.search_query_changed ("channel1", "foo:metallica") == SearchQueryChange.NEW_QUERY); //it's no longer considered canned query
233 }245 }
234 246
235 internal void test_category_manager_binary_search ()247 internal void test_category_manager_binary_search ()

Subscribers

People subscribed via source and target branches

to all changes: