Merge lp:~unity-team/unity/updated-activation-api into lp:unity

Proposed by Mikkel Kamstrup Erlandsen
Status: Merged
Merged at revision: 458
Proposed branch: lp:~unity-team/unity/updated-activation-api
Merge into: lp:unity
Diff against target: 204 lines (+102/-65)
2 files modified
unity-private/places/places-place.vala (+87/-3)
unity-private/places/places-view.vala (+15/-62)
To merge this branch: bzr merge lp:~unity-team/unity/updated-activation-api
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+33634@code.launchpad.net

Description of the change

Fix LP bug #612537 'Dash doesn't hide when clicking an app in the "Available" group'

This is done through a slight refactoring moving all the launching logic into Unity.Places.Place and simply having Unity.Places.View react to that. Before this the launching logic was a bit split between these two classes.

Note that this update is necessary to also reflect the new dbus wire format for com.canonical.Unity.Activation.Activate(uri)

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good, approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-private/places/places-place.vala'
2--- unity-private/places/places-place.vala 2010-08-23 22:53:18 +0000
3+++ unity-private/places/places-place.vala 2010-08-25 13:05:55 +0000
4@@ -211,19 +211,90 @@
5 online = true;
6 }
7
8- public bool activate (string uri)
9+ /* Dispatch an activation request to the place daemon,
10+ * if it has any registered handlers */
11+ public ActivationStatus activate (string uri, string mimetype)
12 {
13+ bool remote_activation = false;
14+
15+ if (uri_regex != null && uri_regex.match (uri))
16+ remote_activation = true;
17+ else if (mime_regex != null && mime_regex.match (mimetype))
18+ remote_activation = true;
19+
20+ if (!remote_activation)
21+ {
22+ activate_fallback.begin (uri);
23+ return ActivationStatus.ACTIVATED_FALLBACK;
24+ }
25+
26 if (activation_service == null)
27 {
28 activation_service = connection.get_object (dbus_name,
29 dbus_path,
30 "com.canonical.Unity.Activation");
31 }
32-
33- return activation_service.activate (uri);
34+
35+ // FIXME: This should be async
36+ uint32 result = activation_service.activate (uri);
37+
38+ switch (result)
39+ {
40+ case 0:
41+ activate_fallback.begin (uri);
42+ return ActivationStatus.ACTIVATED_FALLBACK;
43+ case 1:
44+ return ActivationStatus.ACTIVATED_SHOW_DASH;
45+ case 2:
46+ return ActivationStatus.ACTIVATED_HIDE_DASH;
47+ default:
48+ warning ("Illegal response from com.canonical.Unity.Activation.Activate: %u", result);
49+ return ActivationStatus.NOT_ACTIVATED;
50+ }
51 }
52
53 /* Private Methods */
54+ private async void activate_fallback (string uri)
55+ {
56+ if (uri.has_prefix ("application://"))
57+ {
58+ var id = uri.offset ("application://".length);
59+
60+ AppInfo info;
61+ try {
62+ var appinfos = AppInfoManager.get_instance ();
63+ info = yield appinfos.lookup_async (id);
64+ } catch (Error ee) {
65+ warning ("Unable to read .desktop file '%s': %s", uri, ee.message);
66+ return;
67+ }
68+
69+ if (info is AppInfo)
70+ {
71+ try {
72+ info.launch (null,null);
73+ } catch (Error e) {
74+ warning ("Unable to launch desktop file %s: %s\n",
75+ id,
76+ e.message);
77+ }
78+ }
79+ else
80+ {
81+ warning ("%s is an invalid DesktopAppInfo id\n", id);
82+ }
83+ return;
84+ }
85+
86+ try {
87+ Gtk.show_uri (Gdk.Screen.get_default (),
88+ uri,
89+ 0);
90+ } catch (GLib.Error eee) {
91+ warning ("Unable to launch: %s\n", eee.message);
92+ }
93+ }
94+
95 private void on_service_entry_added (dynamic DBus.Object dbus_object,
96 ValueArray info)
97 {
98@@ -325,5 +396,18 @@
99 show_entry);
100 }
101 }
102+
103+ /**
104+ * Return values for Unity.Places.Place.activate().
105+ * NOTE: These values do *not* coincide with the dbus wire
106+ * values fo com.canonical.Unity.Activation.Activate()
107+ */
108+ public enum ActivationStatus
109+ {
110+ NOT_ACTIVATED, /* Redrum! Something bad happened */
111+ ACTIVATED_FALLBACK, /* No remote activation, local fallback */
112+ ACTIVATED_SHOW_DASH, /* Remote activation. Keep showing the dash */
113+ ACTIVATED_HIDE_DASH /* Remote activation. Hide the dash */
114+ }
115 }
116
117
118=== modified file 'unity-private/places/places-view.vala'
119--- unity-private/places/places-view.vala 2010-08-23 17:01:29 +0000
120+++ unity-private/places/places-view.vala 2010-08-25 13:05:55 +0000
121@@ -173,68 +173,21 @@
122
123 private void on_result_activated (string uri, string mimetype)
124 {
125- bool check_with_service = false;
126-
127- if (active_entry.parent is Place)
128- {
129- if (active_entry.parent.uri_regex != null &&
130- active_entry.parent.uri_regex.match (uri))
131- check_with_service = true;
132-
133- if (active_entry.parent.mime_regex != null &&
134- active_entry.parent.mime_regex.match (mimetype))
135- check_with_service = true;
136- }
137-
138- if (check_with_service)
139- {
140- if (active_entry.parent.activate (uri))
141- return;
142- }
143- activate_normal.begin (uri);
144- }
145-
146- private async void activate_normal (string uri)
147- {
148- global_shell.hide_unity ();
149-
150- if (uri.has_prefix ("application://"))
151- {
152- var id = uri.offset ("application://".length);
153-
154- AppInfo info;
155- try {
156- var appinfos = AppInfoManager.get_instance ();
157- info = yield appinfos.lookup_async (id);
158- } catch (Error ee) {
159- warning ("Unable to read .desktop file '%s': %s", uri, ee.message);
160- return;
161- }
162-
163- if (info is AppInfo)
164- {
165- try {
166- info.launch (null,null);
167- } catch (Error e) {
168- warning ("Unable to launch desktop file %s: %s\n",
169- id,
170- e.message);
171- }
172- }
173- else
174- {
175- warning ("%s is an invalid DesktopAppInfo id\n", id);
176- }
177- return;
178- }
179-
180- try {
181- Gtk.show_uri (Gdk.Screen.get_default (),
182- uri,
183- 0);
184- } catch (GLib.Error eee) {
185- warning ("Unable to launch: %s\n", eee.message);
186- }
187+ ActivationStatus result = active_entry.parent.activate (uri, mimetype);
188+
189+ switch (result)
190+ {
191+ case ActivationStatus.ACTIVATED_SHOW_DASH:
192+ break;
193+ case ActivationStatus.NOT_ACTIVATED:
194+ case ActivationStatus.ACTIVATED_HIDE_DASH:
195+ case ActivationStatus.ACTIVATED_FALLBACK:
196+ global_shell.hide_unity ();
197+ break;
198+ default:
199+ warning ("Unexpected activation status: %u", result);
200+ break;
201+ }
202 }
203 }
204 }