Merge lp:~mhr3/libunity/add-hints-to-activate into lp:libunity

Proposed by Michal Hruby
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 175
Merged at revision: 172
Proposed branch: lp:~mhr3/libunity/add-hints-to-activate
Merge into: lp:libunity
Diff against target: 361 lines (+147/-23)
11 files modified
configure.ac (+1/-1)
protocol/protocol-lens-interface.vala (+6/-2)
protocol/protocol-scope-interface.vala (+1/-1)
src/unity-lens-private.vala (+10/-1)
src/unity-previews.vala (+7/-4)
src/unity-scope-private.vala (+20/-4)
src/unity-scope-proxy-local.vala (+3/-2)
src/unity-scope-proxy-remote.vala (+3/-2)
src/unity-scope-proxy.vala (+2/-1)
src/unity-scope.vala (+3/-2)
test/vala/test-lens.vala (+91/-3)
To merge this branch: bzr merge lp:~mhr3/libunity/add-hints-to-activate
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
Review via email: mp+122538@code.launchpad.net

Commit message

Add hints parameter to dbus Activate() method

Description of the change

Added hints to the dbus Activate() method, this allows us to pass arbitrary hints when activating a preview action.

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good!

review: Approve
175. By Michal Hruby

We're past freezes, make the wire protocol backwards-compatible

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2012-08-30 15:55:52 +0000
3+++ configure.ac 2012-09-04 11:43:20 +0000
4@@ -1,5 +1,5 @@
5 # When releasing also remember to update the soname as instructed below
6-AC_INIT(libunity, 5.97.3)
7+AC_INIT(libunity, 5.97.4)
8
9 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
10 AM_CONFIG_HEADER(config.h)
11
12=== modified file 'protocol/protocol-lens-interface.vala'
13--- protocol/protocol-lens-interface.vala 2012-08-28 13:41:29 +0000
14+++ protocol/protocol-lens-interface.vala 2012-09-04 11:43:20 +0000
15@@ -72,8 +72,12 @@
16 {
17 public async abstract void info_request () throws IOError;
18
19- public async abstract ActivationReplyRaw activate (string uri,
20- uint action_type) throws IOError;
21+ // FIXME: should have the hints param and activate_with_hints should go away
22+ public async abstract ActivationReplyRaw activate (
23+ string uri, uint action_type) throws IOError;
24+
25+ public async abstract ActivationReplyRaw activate_with_hints (
26+ string uri, uint action_type, HashTable<string, Variant> hints) throws IOError;
27
28 public async abstract HashTable<string, Variant> update_preview_property (string uri, HashTable<string, Variant> values) throws IOError;
29
30
31=== modified file 'protocol/protocol-scope-interface.vala'
32--- protocol/protocol-scope-interface.vala 2012-08-28 13:41:29 +0000
33+++ protocol/protocol-scope-interface.vala 2012-09-04 11:43:20 +0000
34@@ -62,7 +62,7 @@
35 public abstract async void info_request () throws IOError;
36
37 public abstract async ActivationReplyRaw activate (
38- string uri, uint action_type) throws IOError;
39+ string uri, uint action_type, HashTable<string, Variant> hints) throws IOError;
40
41 public abstract async HashTable<string, Variant> update_preview_property (
42 string uri, HashTable<string, Variant> values) throws IOError;
43
44=== modified file 'src/unity-lens-private.vala'
45--- src/unity-lens-private.vala 2012-08-30 15:55:52 +0000
46+++ src/unity-lens-private.vala 2012-09-04 11:43:20 +0000
47@@ -496,6 +496,15 @@
48 public async ActivationReplyRaw activate (string uri,
49 uint action_type) throws IOError
50 {
51+ var hints = new HashTable<string, Variant> (null, null);
52+ var reply = yield activate_with_hints (uri, action_type, hints);
53+ return reply;
54+ }
55+
56+ public async ActivationReplyRaw activate_with_hints (
57+ string uri, uint action_type,
58+ HashTable<string, Variant> hints) throws IOError
59+ {
60 string[] tokens;
61 ScopeProxy? scope = null;
62 string? scope_uri = null;
63@@ -520,7 +529,7 @@
64
65 if (scope is ScopeProxy)
66 {
67- raw = yield scope.activate (scope_uri, (ActionType) action_type);
68+ raw = yield scope.activate (scope_uri, (ActionType) action_type, hints);
69 raw.uri = "%s:%s".printf (uid_for_scope (scope), raw.uri);
70 }
71 else
72
73=== modified file 'src/unity-previews.vala'
74--- src/unity-previews.vala 2012-08-20 14:57:40 +0000
75+++ src/unity-previews.vala 2012-09-04 11:43:20 +0000
76@@ -82,7 +82,7 @@
77
78 _raw.add_action_with_hints (action.id, action.display_name,
79 action.icon_hint, action.layout_hint,
80- action.get_hints ());
81+ action.get_hints_internal ());
82 }
83
84 public void add_info (InfoHint info_hint)
85@@ -139,6 +139,10 @@
86 public string extra_text { get; set; }
87 public Icon? icon_hint { get; construct; }
88 public LayoutHint layout_hint { get; construct; }
89+ public HashTable<string, Variant>? hints { get { return hints_; } }
90+
91+ private HashTable<string, Variant> hints_ =
92+ new HashTable<string, Variant> (str_hash, str_equal);
93
94 public PreviewAction (string id, string display_name, Icon? icon_hint)
95 {
96@@ -163,14 +167,13 @@
97 tuple[1] = display_name;
98 tuple[2] = new Variant.string (icon_hint != null ? icon_hint.to_string () : "");
99 tuple[3] = (uint) layout_hint;
100- tuple[4] = get_hints ();
101+ tuple[4] = get_hints_internal ();
102
103 return new Variant.tuple (tuple);
104 }
105
106- internal HashTable<string, Variant> get_hints ()
107+ internal unowned HashTable<string, Variant> get_hints_internal ()
108 {
109- var hints = new HashTable<string, Variant> (str_hash, str_equal);
110 if (extra_text != null && extra_text[0] != '\0')
111 hints["extra-text"] = extra_text;
112
113
114=== modified file 'src/unity-scope-private.vala'
115--- src/unity-scope-private.vala 2012-08-30 15:55:52 +0000
116+++ src/unity-scope-private.vala 2012-09-04 11:43:20 +0000
117@@ -283,7 +283,8 @@
118 }
119
120 public async ActivationReplyRaw activate (string uri,
121- uint action_type) throws IOError
122+ uint action_type,
123+ HashTable<string, Variant> hints) throws IOError
124 {
125 var reply = ActivationReplyRaw ();
126 ActivationResponse? response = null;
127@@ -302,7 +303,7 @@
128 case ActionType.PREVIEW_ACTION:
129 string[] tokens = uri.split (":", 2);
130 stripped_uri = tokens[1];
131- response = activate_action (tokens[0], stripped_uri);
132+ response = activate_action (tokens[0], stripped_uri, hints);
133 break;
134 case ActionType.PREVIEW_BUILTIN_ACTION:
135 // TODO: implement
136@@ -321,7 +322,7 @@
137 var new_uri = response.goto_uri;
138 if (new_uri == null || new_uri[0] == '\0')
139 new_uri = stripped_uri ?? uri;
140- reply = yield activate (new_uri, ActionType.PREVIEW_RESULT);
141+ reply = yield activate (new_uri, ActionType.PREVIEW_RESULT, hints);
142 return reply;
143 }
144 }
145@@ -584,12 +585,27 @@
146 return response;
147 }
148
149- public ActivationResponse? activate_action (string action_id, string uri)
150+ public ActivationResponse? activate_action (string action_id, string uri,
151+ HashTable<string, Variant> hints)
152 {
153 ActivationResponse? response = null;
154 var action = _action_map[action_id];
155 if (action != null)
156+ {
157+ var action_hints = action.hints;
158+ action_hints.remove_all ();
159+ if (hints.size () > 0)
160+ {
161+ HashTableIter<string, Variant> iter = HashTableIter<string, Variant> (hints);
162+ unowned string key;
163+ unowned Variant value;
164+ while (iter.next (out key, out value))
165+ {
166+ action_hints[key] = value;
167+ }
168+ }
169 response = action.activated (uri);
170+ }
171 else
172 warning ("Cannot find PreviewAction with id: %s", action_id);
173
174
175=== modified file 'src/unity-scope-proxy-local.vala'
176--- src/unity-scope-proxy-local.vala 2012-08-30 15:55:52 +0000
177+++ src/unity-scope-proxy-local.vala 2012-09-04 11:43:20 +0000
178@@ -86,9 +86,10 @@
179 /*
180 * Implementation of the ScopeService interface
181 */
182- public async ActivationReplyRaw activate (string uri, ActionType action_type)
183+ public async ActivationReplyRaw activate (string uri, ActionType action_type,
184+ HashTable<string, Variant> hints)
185 {
186- var reply = yield scope.activate (uri, action_type);
187+ var reply = yield scope.activate (uri, action_type, hints);
188 return reply;
189 }
190
191
192=== modified file 'src/unity-scope-proxy-remote.vala'
193--- src/unity-scope-proxy-remote.vala 2012-08-30 15:55:52 +0000
194+++ src/unity-scope-proxy-remote.vala 2012-09-04 11:43:20 +0000
195@@ -188,12 +188,13 @@
196 /*
197 * Implementation of the ScopeService interface
198 */
199- public async ActivationReplyRaw activate (string uri, ActionType action_type)
200+ public async ActivationReplyRaw activate (string uri, ActionType action_type,
201+ HashTable<string, Variant> hints)
202 {
203 if (synchronized)
204 {
205 try {
206- var raw = yield _service.activate (uri, (uint) action_type);
207+ var raw = yield _service.activate (uri, (uint) action_type, hints);
208 return raw;
209 } catch (Error e) {
210 warning (@"Unable to search scope ($dbus_path): $(e.message)");
211
212=== modified file 'src/unity-scope-proxy.vala'
213--- src/unity-scope-proxy.vala 2012-08-30 15:55:52 +0000
214+++ src/unity-scope-proxy.vala 2012-09-04 11:43:20 +0000
215@@ -38,7 +38,8 @@
216 public abstract Dee.SerializableModel filters_model { get; set; }
217
218 public abstract async ActivationReplyRaw activate (string uri,
219- ActionType action_type);
220+ ActionType action_type,
221+ HashTable<string, Variant> hints);
222 public abstract async HashTable<string, Variant> update_preview_property (
223 string uri, HashTable<string, Variant> values) throws IOError;
224 public abstract async HashTable<string, Variant> search (
225
226=== modified file 'src/unity-scope.vala'
227--- src/unity-scope.vala 2012-08-30 15:55:52 +0000
228+++ src/unity-scope.vala 2012-09-04 11:43:20 +0000
229@@ -192,10 +192,11 @@
230 }
231
232 internal async Protocol.ActivationReplyRaw activate (string uri,
233- Protocol.ActionType action_type)
234+ Protocol.ActionType action_type,
235+ HashTable<string, Variant> hints)
236 {
237 try {
238- var reply = yield _pimpl.activate (uri, action_type);
239+ var reply = yield _pimpl.activate (uri, action_type, hints);
240 return reply;
241 } catch (Error e) {
242 warning (@"Unable to activate scope: $(e.message)");
243
244=== modified file 'test/vala/test-lens.vala'
245--- test/vala/test-lens.vala 2012-08-30 15:55:52 +0000
246+++ test/vala/test-lens.vala 2012-09-04 11:43:20 +0000
247@@ -58,6 +58,7 @@
248 Test.add_data_func ("/Unit/Lens/Preview/Async", test_lens_preview_async);
249 Test.add_data_func ("/Unit/Lens/Preview/Signal", test_lens_preview_signal);
250 Test.add_data_func ("/Unit/Lens/Preview/ClosedSignal", test_lens_preview_closed_signal);
251+ Test.add_data_func ("/Unit/Lens/Preview/ActionWithHints", test_lens_preview_action_with_hint);
252 Test.add_data_func ("/Unit/Lens/PrivateContentFlag", test_lens_private_content_flag);
253 Test.add_data_func ("/Unit/Lens/HomeLensDefaultName", test_lens_home_lens_default_name);
254
255@@ -209,9 +210,30 @@
256 private static void call_lens_activate (string uri, uint action_type,
257 Func<Variant?>? cb = null)
258 {
259- var parameters = new Variant ("(su)", uri, action_type);
260-
261- call_lens_method ("Activate", parameters, cb);
262+ call_lens_activate_with_hints (uri, action_type,
263+ new HashTable<string, Variant> (null, null),
264+ cb);
265+ }
266+
267+ private static void call_lens_activate_with_hints (
268+ string uri, uint action_type, HashTable<string, Variant> hints,
269+ Func<Variant?>? cb = null)
270+ {
271+ Variant parameters;
272+ // let's make sure we test both variants, since we have to support them
273+ if (hints.size () > 0)
274+ {
275+ Variant ht = hints;
276+ parameters = new Variant ("(su@a{sv})", uri, action_type, ht);
277+
278+ call_lens_method ("ActivateWithHints", parameters, cb);
279+ }
280+ else
281+ {
282+ parameters = new Variant ("(su)", uri, action_type);
283+
284+ call_lens_method ("Activate", parameters, cb);
285+ }
286 }
287
288 private static void call_lens_update_preview_property (string uri, HashTable<string, Variant> props,
289@@ -1068,6 +1090,72 @@
290 assert (got_closed_signal == 1);
291 }
292
293+ public static void test_lens_preview_action_with_hint ()
294+ {
295+ SignalWrapper[] signals = null;
296+ assert (local_scope != null);
297+
298+ var ml = new MainLoop ();
299+
300+ bool got_preview_uri_signal = false;
301+ bool got_activated_signal = false;
302+
303+ var preview = new Unity.GenericPreview ("title", "description", null);
304+ var action = new Unity.PreviewAction ("button1", "Do stuff!", null);
305+ preview.add_action (action);
306+
307+ signals += new SignalWrapper (action,
308+ action.activated.connect ((uri) =>
309+ {
310+ got_activated_signal = true;
311+ assert (action.hints["passing-extra-info"].get_boolean () == true);
312+ return null;
313+ }));
314+
315+ // this signal handler gets called when activate is called with PREVIEW_RESULT
316+ signals += new SignalWrapper (local_scope,
317+ local_scope.preview_uri.connect ((uri) =>
318+ {
319+ assert (uri == "scheme://local/");
320+ got_preview_uri_signal = true;
321+ return preview;
322+ }));
323+
324+ ml = new MainLoop ();
325+
326+ var lens_results_model =
327+ exported_lens.get_model_internal (0) as Dee.SharedModel;
328+ var iter = lens_results_model.get_first_iter ();
329+ var mangled_uri = lens_results_model.get_string (iter, 0);
330+
331+ Unity.Protocol.Preview? reconstructed = null;
332+ call_lens_activate (mangled_uri, Unity.Protocol.ActionType.PREVIEW_RESULT, (reply) =>
333+ {
334+ var v = reply.get_child_value (0);
335+ Unity.Protocol.ActivationReplyRaw reply_struct =
336+ (Unity.Protocol.ActivationReplyRaw) v;
337+ reconstructed = Unity.Protocol.Preview.parse (reply_struct.hints["preview"]);
338+ ml.quit ();
339+ });
340+ run_with_timeout (ml, 5000);
341+
342+ assert (reconstructed != null);
343+
344+ ml = new MainLoop ();
345+
346+ // activate the action, check that hints are passed to it
347+ var hints = new HashTable<string, Variant> (str_hash, str_equal);
348+ hints["passing-extra-info"] = new Variant.boolean (true);
349+ call_lens_activate_with_hints ("%s:%s".printf (action.id, mangled_uri), Unity.Protocol.ActionType.PREVIEW_ACTION, hints, (reply) =>
350+ {
351+ ml.quit ();
352+ });
353+
354+ run_with_timeout (ml, 5000);
355+
356+ assert (got_activated_signal);
357+ }
358+
359 public static void test_lens_private_content_flag ()
360 {
361 assert (local_scope != null);

Subscribers

People subscribed via source and target branches