Merge lp:~jamesh/libunity/search-changed into lp:libunity

Proposed by James Henstridge
Status: Merged
Approved by: Michal Hruby
Approved revision: 267
Merged at revision: 262
Proposed branch: lp:~jamesh/libunity/search-changed
Merge into: lp:libunity
Diff against target: 132 lines (+64/-0)
4 files modified
debian/libunity9.symbols (+1/-0)
src/unity-scope-dbus-impl.vala (+27/-0)
src/unity-scope-interface.vala (+15/-0)
test/vala/test-scope.vala (+21/-0)
To merge this branch: bzr merge lp:~jamesh/libunity/search-changed
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+176142@code.launchpad.net

Commit message

Add an API to Unity.AbstractScope to let the scope indicate that its results have changed.

Description of the change

Add a Unity.AbstractScope.queue_search_changed(search_type) API to allow a scope to indicate that its results have changed.

This is implemented as a signal on AbstractScope, with ScopeDBusConnector connecting to that signal and running logic equivalent to what DeprecatedScope does.

To post a comment you must log in.
Revision history for this message
James Henstridge (jamesh) wrote :

And, yes I do need to hook up some tests.

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

46 + // FIXME: queue new search

Please remove this, the scope API is completely pull now, no push. So this isn't possible.

lp:~jamesh/libunity/search-changed updated
263. By James Henstridge

Rename to results_invalidated to match D-Bus API.

264. By James Henstridge

Add a test showing that the results_invalidated signal gets fired on the
remote side.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~jamesh/libunity/search-changed updated
265. By James Henstridge

Another renaming based on discussions with mhr3 on IRC.

266. By James Henstridge

Update symbols.

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

Looking good, just one simplification:

126 + uint tid = Timeout.add (500, () => { ml.quit (); return false; });
127 + ml.run ();

Could you please change this to assert(run_with_timeout(ml)) ?

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~jamesh/libunity/search-changed updated
267. By James Henstridge

Use run_with_timeout ().

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

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libunity9.symbols'
2--- debian/libunity9.symbols 2013-07-19 03:16:32 +0000
3+++ debian/libunity9.symbols 2013-07-22 11:26:23 +0000
4@@ -59,6 +59,7 @@
5 unity_abstract_scope_get_type@Base 7.0.0daily13.05.31ubuntu.unity.next
6 unity_abstract_scope_get_unique_name@Base 7.0.0daily13.05.31ubuntu.unity.next
7 unity_abstract_scope_normalize_search_query@Base 7.0.0daily13.05.31ubuntu.unity.next
8+ unity_abstract_scope_results_invalidated@Base 0replaceme
9 unity_activation_response_construct@Base 4.0.0
10 unity_activation_response_construct_with_preview@Base 5.90.0
11 unity_activation_response_get_goto_uri@Base 4.0.0
12
13=== modified file 'src/unity-scope-dbus-impl.vala'
14--- src/unity-scope-dbus-impl.vala 2013-07-17 15:18:49 +0000
15+++ src/unity-scope-dbus-impl.vala 2013-07-22 11:26:23 +0000
16@@ -53,6 +53,7 @@
17 private DBusConnection? _dbus_connection;
18 private Rand _rand;
19 private uint _timeout_source_id;
20+ private ulong _scope_results_invalidated_id;
21 private bool _query_happened;
22
23 public Dee.SerializableModel categories_model { get; set; }
24@@ -144,10 +145,18 @@
25 _dbus_connection = Bus.get_sync (BusType.SESSION);
26 _dbus_id = _dbus_connection.register_object (_dbus_name,
27 this as ScopeService);
28+
29+ _scope_results_invalidated_id = owner.results_invalidated_internal.connect(
30+ on_scope_results_invalidated);
31 }
32
33 public void unexport ()
34 {
35+ if (_scope_results_invalidated_id != 0)
36+ {
37+ owner.disconnect (_scope_results_invalidated_id);
38+ }
39+
40 if (_dbus_id != 0)
41 {
42 _dbus_connection.unregister_object (_dbus_id);
43@@ -284,6 +293,24 @@
44 if (found_iter) this.notify_property ("filters");
45 }
46
47+ private void on_scope_results_invalidated (SearchType search_type)
48+ {
49+ ChannelType channel_type = search_type == SearchType.DEFAULT ?
50+ ChannelType.DEFAULT : ChannelType.GLOBAL;
51+
52+ foreach (var channel in _channels.get_values ())
53+ {
54+ if (channel.channel_type == channel_type)
55+ {
56+ var search = channel.last_search;
57+ if (search != null) search.search_context.cancellable.cancel ();
58+ channel.last_search = null;
59+ // FIXME: queue new search
60+ }
61+ }
62+ this.results_invalidated (channel_type);
63+ }
64+
65 private SearchMetadata create_search_metadata (HashTable<string, Variant> hints)
66 {
67 var metadata_hints = new HashTable<string, Variant> (str_hash, str_equal);
68
69=== modified file 'src/unity-scope-interface.vala'
70--- src/unity-scope-interface.vala 2013-07-19 03:14:22 +0000
71+++ src/unity-scope-interface.vala 2013-07-22 11:26:23 +0000
72@@ -433,6 +433,21 @@
73 {
74 return search_query;
75 }
76+
77+ /**
78+ * Invalidate previously sent results.
79+ *
80+ * If a scope knows that results it has sent out previously are no
81+ * longer valid, it can call this function to notify any interested
82+ * parties that they may want to perform a new search.
83+ */
84+ public void results_invalidated (SearchType search_type)
85+ requires (search_type < SearchType.N_TYPES)
86+ {
87+ this.results_invalidated_internal (search_type);
88+ }
89+
90+ public signal void results_invalidated_internal (SearchType search_type);
91 }
92
93 } /* namespace Unity */
94
95=== modified file 'test/vala/test-scope.vala'
96--- test/vala/test-scope.vala 2013-07-19 03:14:22 +0000
97+++ test/vala/test-scope.vala 2013-07-22 11:26:23 +0000
98@@ -73,6 +73,8 @@
99 Fixture.create<ScopeTester> (ScopeTester.test_scope_filters));
100 Test.add_data_func ("/Unit/Scope/FormFactor",
101 Fixture.create<ScopeTester> (ScopeTester.test_scope_form_factor));
102+ Test.add_data_func ("/Unit/Scope/ResultsInvalidated",
103+ Fixture.create<ScopeTester> (ScopeTester.test_scope_results_invalidated));
104
105
106 Test.add_data_func ("/Unit/SimpleScope/Search",
107@@ -912,6 +914,25 @@
108 });
109 assert (form_factor == "phone");
110 }
111+
112+ public void test_scope_results_invalidated ()
113+ {
114+ var ml = new MainLoop ();
115+ bool got_signal = false;
116+ ChannelType channel_type = 0;
117+ proxy.results_invalidated.connect ((type) =>
118+ {
119+ got_signal = true;
120+ channel_type = type;
121+ ml.quit ();
122+ });
123+ scope.results_invalidated (Unity.SearchType.GLOBAL);
124+
125+ // Ensure that the test does not hang
126+ assert (run_with_timeout (ml));
127+ assert (got_signal = true);
128+ assert (channel_type == ChannelType.GLOBAL);
129+ }
130 }
131
132 class SimpleScopeTester: Object, Fixture

Subscribers

People subscribed via source and target branches