Merge lp:~mhr3/unity/pass-extra-hints-for-perform-action into lp:unity

Proposed by Michal Hruby
Status: Merged
Approved by: Paweł Stołowski
Approved revision: no longer in the source branch.
Merged at revision: 2661
Proposed branch: lp:~mhr3/unity/pass-extra-hints-for-perform-action
Merge into: lp:unity
Diff against target: 183 lines (+85/-12)
5 files modified
UnityCore/Lens.cpp (+37/-8)
UnityCore/Lens.h (+2/-1)
UnityCore/Preview.cpp (+2/-2)
UnityCore/Preview.h (+3/-1)
tests/test_lens.cpp (+41/-0)
To merge this branch: bzr merge lp:~mhr3/unity/pass-extra-hints-for-perform-action
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
Nick Dedekind (community) Approve
jenkins continuous-integration Pending
Review via email: mp+122547@code.launchpad.net

Commit message

Make sure we can pass extra hints when activating preview actions

Description of the change

Make sure we can pass extra hints when activating preview actions. This also adds compability with latest changes in libunity.

Added tests for the issue.

The related libunity branch is @ https://code.launchpad.net/~mhr3/libunity/add-hints-to-activate/+merge/122538

To post a comment you must log in.
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

LGTM

Only comment is that it would be better if you could use the Hints typedef in dash::Preview::PerformAction.

161 + void PerformAction(std::string const& id,
162 + std::map<std::string, glib::Variant> const& hints =
163 + std::map<std::string, glib::Variant>()) const;

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

> LGTM
>
> Only comment is that it would be better if you could use the Hints typedef in
> dash::Preview::PerformAction.
>

Wanted to, but it's defined in Lens.h, which includes Previews, so there'd be a circular dependency... :(

Revision history for this message
Unity Merger (unity-merger) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

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

Looking good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/Lens.cpp'
2--- UnityCore/Lens.cpp 2012-08-31 14:36:57 +0000
3+++ UnityCore/Lens.cpp 2012-09-04 15:18:19 +0000
4@@ -89,7 +89,8 @@
5 void ActivationReply(GVariant* parameters);
6 void Preview(std::string const& uri);
7 void ActivatePreviewAction(std::string const& action_id,
8- std::string const& uri);
9+ std::string const& uri,
10+ Hints const& hints);
11 void SignalPreview(std::string const& preview_uri,
12 glib::Variant const& preview_update,
13 glib::DBusProxy::ReplyCallback reply_cb);
14@@ -499,6 +500,7 @@
15 &b),
16 sigc::mem_fun(this, &Lens::Impl::OnGlobalSearchFinished),
17 global_search_cancellable_);
18+
19 g_variant_builder_clear(&b);
20 }
21
22@@ -608,7 +610,8 @@
23 }
24
25 void Lens::Impl::ActivatePreviewAction(std::string const& action_id,
26- std::string const& uri)
27+ std::string const& uri,
28+ Hints const& hints)
29 {
30 LOG_DEBUG(logger) << "Activating action '" << action_id << "' on '" << id_ << "'";
31
32@@ -622,10 +625,35 @@
33 activation_uri += ":";
34 activation_uri += uri;
35
36- proxy_->Call("Activate",
37- g_variant_new("(su)", activation_uri.c_str(),
38- UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_ACTION),
39- sigc::mem_fun(this, &Lens::Impl::ActivationReply));
40+ if (hints.empty())
41+ {
42+ // FIXME: we should really be using the (sua{sv}) method all the time,
43+ // but we're past freezes and having to logout and back in is
44+ // too big of a deal after beta freeze
45+ proxy_->Call("Activate",
46+ g_variant_new("(su)", activation_uri.c_str(),
47+ UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_ACTION),
48+ sigc::mem_fun(this, &Lens::Impl::ActivationReply));
49+ }
50+ else
51+ {
52+ GVariantBuilder b;
53+ g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
54+
55+ for (auto it = hints.begin(); it != hints.end(); ++it)
56+ {
57+ GVariant* variant = it->second;
58+ g_variant_builder_add(&b, "{sv}", it->first.c_str(), variant);
59+ }
60+
61+ proxy_->Call("ActivateWithHints",
62+ g_variant_new("(sua{sv})", activation_uri.c_str(),
63+ UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_ACTION,
64+ &b),
65+ sigc::mem_fun(this, &Lens::Impl::ActivationReply));
66+
67+ g_variant_builder_clear(&b);
68+ }
69 }
70
71 void Lens::Impl::SignalPreview(std::string const& preview_uri,
72@@ -877,9 +905,10 @@
73 }
74
75 void Lens::ActivatePreviewAction(std::string const& action_id,
76- std::string const& uri)
77+ std::string const& uri,
78+ Hints const& hints)
79 {
80- pimpl->ActivatePreviewAction(action_id, uri);
81+ pimpl->ActivatePreviewAction(action_id, uri, hints);
82 }
83
84 void Lens::SignalPreview(std::string const& uri,
85
86=== modified file 'UnityCore/Lens.h'
87--- UnityCore/Lens.h 2012-08-30 16:14:40 +0000
88+++ UnityCore/Lens.h 2012-09-04 15:18:19 +0000
89@@ -86,7 +86,8 @@
90 virtual void Activate(std::string const& uri);
91 virtual void Preview(std::string const& uri);
92 virtual void ActivatePreviewAction(std::string const& action_id,
93- std::string const& uri);
94+ std::string const& uri,
95+ Hints const& hints);
96 virtual void SignalPreview(std::string const& uri,
97 glib::Variant const& preview_update,
98 glib::DBusProxy::ReplyCallback reply_cb = nullptr);
99
100=== modified file 'UnityCore/Preview.cpp'
101--- UnityCore/Preview.cpp 2012-08-20 10:53:00 +0000
102+++ UnityCore/Preview.cpp 2012-09-04 15:18:19 +0000
103@@ -262,11 +262,11 @@
104 }
105 }
106
107-void Preview::PerformAction(std::string const& id) const
108+void Preview::PerformAction(std::string const& id, Lens::Hints const& hints) const
109 {
110 if (pimpl->parent_lens_)
111 {
112- pimpl->parent_lens_->ActivatePreviewAction(id, preview_uri);
113+ pimpl->parent_lens_->ActivatePreviewAction(id, preview_uri, hints);
114 }
115 else
116 {
117
118=== modified file 'UnityCore/Preview.h'
119--- UnityCore/Preview.h 2012-08-20 10:25:17 +0000
120+++ UnityCore/Preview.h 2012-09-04 15:18:19 +0000
121@@ -112,7 +112,9 @@
122 ActionPtrList GetActions() const;
123 InfoHintPtrList GetInfoHints() const;
124
125- void PerformAction(std::string const& id) const;
126+ void PerformAction(std::string const& id,
127+ std::map<std::string, glib::Variant> const& hints =
128+ std::map<std::string, glib::Variant>()) const;
129 void EmitClosed() const;
130
131 protected:
132
133=== modified file 'tests/test_lens.cpp'
134--- tests/test_lens.cpp 2012-08-28 12:23:15 +0000
135+++ tests/test_lens.cpp 2012-09-04 15:18:19 +0000
136@@ -273,6 +273,47 @@
137 Utils::WaitUntil(action_executed);
138 }
139
140+TEST_F(TestLens, TestPreviewActionWithHints)
141+{
142+ std::string uri = PopulateAndGetFirstResultURI();
143+ bool previewed = false;
144+ Preview::Ptr preview;
145+
146+ auto preview_cb = [&previewed, &uri, &preview]
147+ (std::string const& uri_,
148+ Preview::Ptr const& preview_)
149+ {
150+ EXPECT_EQ(uri, uri_);
151+ EXPECT_EQ(preview_->renderer_name, "preview-movie");
152+
153+ preview = preview_;
154+ previewed = true;
155+ };
156+
157+ lens_->preview_ready.connect(preview_cb);
158+ lens_->Preview(uri);
159+
160+ Utils::WaitUntil(previewed);
161+
162+ bool action_executed = false;
163+ auto activated_cb = [&action_executed] (std::string const& uri,
164+ HandledType handled_type,
165+ Lens::Hints const& hints)
166+ {
167+ EXPECT_EQ(handled_type, HandledType::SHOW_DASH);
168+ action_executed = true;
169+ };
170+
171+ lens_->activated.connect(activated_cb);
172+ EXPECT_GT(preview->GetActions().size(), (unsigned)0);
173+ auto action = preview->GetActions()[0];
174+ auto hints = Lens::Hints();
175+ hints["passing-test-hint"] = g_variant_new_boolean(TRUE);
176+ preview->PerformAction(action->id, hints);
177+
178+ Utils::WaitUntil(action_executed);
179+}
180+
181 TEST_F(TestLens, TestEmitClosedSignal)
182 {
183 std::string uri = PopulateAndGetFirstResultURI();