Merge lp:~mhr3/libunity/remote-scope-sources into lp:libunity

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 113
Merged at revision: 112
Proposed branch: lp:~mhr3/libunity/remote-scope-sources
Merge into: lp:libunity
Diff against target: 232 lines (+137/-5)
5 files modified
src/unity-lens-filters.vala (+22/-1)
src/unity-scope-proxy-remote.vala (+1/-0)
src/unity-scope.vala (+1/-2)
test/vala/test-lens.vala (+71/-2)
test/vala/test-remote-scope.vala (+42/-0)
To merge this branch: bzr merge lp:~mhr3/libunity/remote-scope-sources
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+89417@code.launchpad.net

Description of the change

Fix sources filter when using remote scopes.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

68 - public OptionsFilter sources { get; internal set; }
69 + public OptionsFilter sources { get; private set; }

Technicaly this is an ABI break. Although only in internal ABI. If it's just a cleanup I suggest we leave it as is to not trigger the alarm bells of the packaging system.

$ nm -D src/.libs/libunity.so | grep set_sources
0001d931 T unity_lens_set_sources_display_name
000483ac T unity_scope_proxy_set_sources
$ nm -D /usr/lib/libunity.so | grep set_sources
00017140 T unity_lens_set_sources_display_name
00037c80 T unity_scope_proxy_set_sources
0002d350 T unity_scope_set_sources

review: Needs Fixing
113. By Michal Hruby

Revert ABI break

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

Reverted, unfortunately "internal set;" marks the property as writeable, which is not desired.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Point taken. If you want to remove it take it up with Didier. It's unlikely to be an issue; we just need to make sure nobody panics ;-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-lens-filters.vala'
2--- src/unity-lens-filters.vala 2012-01-17 19:36:24 +0000
3+++ src/unity-lens-filters.vala 2012-01-23 13:23:30 +0000
4@@ -211,7 +211,7 @@
5
6 if (element != null)
7 {
8- var free_it = (owned) element.data;
9+ element.data = null;
10 options.delete_link (element);
11
12 this.changed ();
13@@ -245,6 +245,8 @@
14 VariantIter iter;
15 array.get("a(sssb)", out iter);
16
17+ string[] option_ids = {};
18+
19 for (var i = 0; i < iter.n_children(); i++)
20 {
21 string b_id;
22@@ -255,6 +257,25 @@
23 iter.next("(sssb)", out b_id, out b_name, out b_icon_hint, out b_active);
24
25 find_and_update_option(b_id, b_name, b_icon_hint, b_active);
26+ option_ids += b_id;
27+ }
28+
29+ if (options.length () != option_ids.length)
30+ {
31+ // something got removed, remove it from the List (and don't use
32+ // remove_option() cause it emits changed()
33+ unowned List<FilterOption> l = options;
34+ while (l != null)
35+ {
36+ unowned string id = l.data.id;
37+ unowned List<FilterOption> to_remove = l;
38+ l = l.next;
39+ if (!(id in option_ids))
40+ {
41+ to_remove.data = null;
42+ options.delete_link (to_remove);
43+ }
44+ }
45 }
46 }
47
48
49=== modified file 'src/unity-scope-proxy-remote.vala'
50--- src/unity-scope-proxy-remote.vala 2012-01-06 13:04:27 +0000
51+++ src/unity-scope-proxy-remote.vala 2012-01-23 13:23:30 +0000
52@@ -278,6 +278,7 @@
53
54 /* extract the sources */
55 sources.update (scope_info.sources);
56+ this.notify_property ("sources");
57
58 if (!synchronized)
59 {
60
61=== modified file 'src/unity-scope.vala'
62--- src/unity-scope.vala 2012-01-09 11:19:46 +0000
63+++ src/unity-scope.vala 2012-01-23 13:23:30 +0000
64@@ -63,8 +63,7 @@
65
66 public Scope (string dbus_path_)
67 {
68- Object (dbus_path: dbus_path_,
69- sources: new CheckOptionFilter ("sources", "Sources", null, true));
70+ Object (dbus_path: dbus_path_);
71 }
72
73 construct
74
75=== modified file 'test/vala/test-lens.vala'
76--- test/vala/test-lens.vala 2012-01-06 14:17:45 +0000
77+++ test/vala/test-lens.vala 2012-01-23 13:23:30 +0000
78@@ -463,23 +463,92 @@
79 bool got_search_changed = false;
80 local_scope.sources.add_option ("id1", "Source1", null);
81 local_scope.sources.add_option ("id2", "Source2", null);
82+
83 var ml = new MainLoop ();
84-
85 // wait a bit for the model to update
86- Timeout.add (500, () => { ml.quit (); return false; });
87+ Idle.add (() => { ml.quit (); return false; });
88+ ml.run ();
89+ ml = new MainLoop ();
90+
91+ ulong sig_id = local_scope.search_changed.connect ((lens_search) =>
92+ {
93+ assert (lens_search.search_string.has_prefix ("sources-test"));
94+ lens_search.finished ();
95+ });
96+ // do a search, so we can sync with the remote scope
97+ call_lens_search ("sources-test", () => { ml.quit (); });
98+ ml.run ();
99+ ml = new MainLoop ();
100+ // after this the sources *have* to be updated
101+ Idle.add (() => { ml.quit (); return false; });
102 ml.run ();
103
104 bool found1 = false;
105 bool found2 = false;
106+ bool remote1 = false;
107+ bool remote2 = false;
108 foreach (var filter_option in exported_lens.get_sources_internal ().options)
109 {
110 if (filter_option.id.has_suffix ("id1") && filter_option.id != "id1")
111 found1 = true;
112 else if (filter_option.id.has_suffix ("id2") && filter_option.id != "id2")
113 found2 = true;
114+ else if (filter_option.id.has_suffix ("id1-remote"))
115+ remote1 = true;
116+ else if (filter_option.id.has_suffix ("id2-remote"))
117+ remote2 = true;
118 }
119
120 assert (found1);
121 assert (found2);
122+ if (remote_scope_test)
123+ {
124+ assert (remote1);
125+ assert (remote2);
126+ }
127+
128+ // =============== PART 2 of the test =============== //
129+ // we'll now remove one source
130+ local_scope.sources.remove_option ("id1");
131+
132+ ml = new MainLoop ();
133+ // wait a bit for the model to update
134+ Idle.add (() => { ml.quit (); return false; });
135+ ml.run ();
136+ ml = new MainLoop ();
137+ // do another search to synchronize
138+ call_lens_search ("sources-test-2", () => { ml.quit (); });
139+ ml.run ();
140+ ml = new MainLoop ();
141+ // after this the sources *have* to be updated
142+ Idle.add (() => { ml.quit (); return false; });
143+ ml.run ();
144+
145+ found1 = false;
146+ found2 = false;
147+ remote1 = false;
148+ remote2 = false;
149+ foreach (var filter_option in exported_lens.get_sources_internal ().options)
150+ {
151+ if (filter_option.id.has_suffix ("id1") && filter_option.id != "id1")
152+ found1 = true;
153+ else if (filter_option.id.has_suffix ("id2") && filter_option.id != "id2")
154+ found2 = true;
155+ else if (filter_option.id.has_suffix ("id1-remote"))
156+ remote1 = true;
157+ else if (filter_option.id.has_suffix ("id2-remote"))
158+ remote2 = true;
159+ }
160+
161+ // make the the id1 sources are gone
162+ assert (found1 == false);
163+ assert (found2);
164+ if (remote_scope_test)
165+ {
166+ assert (remote1 == false);
167+ assert (remote2);
168+ }
169+
170+ SignalHandler.disconnect (local_scope, sig_id);
171 }
172 }
173
174=== modified file 'test/vala/test-remote-scope.vala'
175--- test/vala/test-remote-scope.vala 2011-12-08 14:57:22 +0000
176+++ test/vala/test-remote-scope.vala 2012-01-23 13:23:30 +0000
177@@ -31,6 +31,7 @@
178 Test.add_data_func ("/Integration/Scope/TwoSearches", test_scope_two_searches);
179 Test.add_data_func ("/Integration/Scope/ModelSync", test_scope_model_sync);
180 Test.add_data_func ("/Integration/Scope/ReplyHint", test_scope_reply_hint);
181+ Test.add_data_func ("/Integration/Scope/Sources", test_scope_sources);
182 Test.add_data_func ("/Integration/Scope/Finalize", test_scope_finalize);
183
184 Test.run ();
185@@ -228,6 +229,47 @@
186 bus.flush_sync ();
187 }
188
189+ public static void test_scope_sources ()
190+ {
191+ // we expect that the lens will call the search method
192+ assert (exported_scope != null);
193+
194+ var ml = new MainLoop ();
195+
196+ exported_scope.sources.add_option ("id1-remote", "Remote 1", null);
197+ exported_scope.sources.add_option ("id2-remote", "Remote 2", null);
198+
199+ bool remove_option = false;
200+ // we're using the search for synchronization
201+ ulong sig_id = exported_scope.search_changed.connect ((lens_search, search_type, cancellable) =>
202+ {
203+ assert (lens_search.search_string.has_prefix ("sources-test"));
204+ if (remove_option)
205+ {
206+ exported_scope.sources.remove_option ("id1-remote");
207+ }
208+ // wait a while to emit the finished signal (so the info_changed
209+ // is emitted)
210+ Idle.add (() => { lens_search.finished (); ml.quit (); return false; });
211+ });
212+
213+ Timeout.add (2000, () => { assert_not_reached (); });
214+ ml.run ();
215+
216+ // first part of the test passed, now let's try to remove a source
217+
218+ remove_option = true;
219+ // waiting for another search to finish
220+ ml = new MainLoop ();
221+ Timeout.add (2000, () => { assert_not_reached (); });
222+ ml.run ();
223+
224+ SignalHandler.disconnect (exported_scope, sig_id);
225+
226+ var bus = Bus.get_sync (BusType.SESSION);
227+ bus.flush_sync ();
228+ }
229+
230 public static void test_scope_finalize ()
231 {
232 // wait for the lens to vanish

Subscribers

People subscribed via source and target branches