Merge lp:~marcustomlinson/unity-scope-youtube/install_account_service into lp:unity-scope-youtube
- install_account_service
- Merge into 14.10
Proposed by
Marcus Tomlinson
Status: | Merged |
---|---|
Merged at revision: | 90 |
Proposed branch: | lp:~marcustomlinson/unity-scope-youtube/install_account_service |
Merge into: | lp:unity-scope-youtube |
Diff against target: |
699 lines (+114/-368) 17 files modified
CMakeLists.txt (+1/-1) click/CMakeLists.txt (+3/-0) click/apparmor.json (+1/-0) click/manifest.json.in (+6/-3) click/youtube.application (+10/-0) click/youtube.desktop (+6/-0) click/youtube.service (+23/-3) data/CMakeLists.txt (+0/-1) data/accounts/providers/youtube.provider (+0/-30) data/accounts/qml-plugins/youtube/Main.qml (+0/-35) debian/control (+2/-2) include/youtube/api/simple-oauth.h (+0/-88) include/youtube/scope/scope.h (+12/-7) src/CMakeLists.txt (+0/-1) src/youtube/api/simple-oauth.cpp (+0/-179) src/youtube/scope/query.cpp (+11/-5) src/youtube/scope/scope.cpp (+39/-13) |
To merge this branch: | bzr merge lp:~marcustomlinson/unity-scope-youtube/install_account_service |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Pete Woods | Pending | ||
Review via email: mp+234264@code.launchpad.net |
Commit message
Use new scopes:
Description of the change
To post a comment you must log in.
Revision history for this message
Pete Woods (pete-woods) wrote : | # |
Revision history for this message
Pete Woods (pete-woods) : | # |
Revision history for this message
Pete Woods (pete-woods) wrote : | # |
Another question is, do we need to explicitly compile and link against libaccounts/signon any more?
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2014-09-09 10:28:21 +0000 | |||
3 | +++ CMakeLists.txt 2014-09-11 08:39:29 +0000 | |||
4 | @@ -29,7 +29,7 @@ | |||
5 | 29 | gio-unix-2.0 | 29 | gio-unix-2.0 |
6 | 30 | libaccounts-glib | 30 | libaccounts-glib |
7 | 31 | libsignon-glib | 31 | libsignon-glib |
9 | 32 | libunity-scopes>=0.6.0 | 32 | libunity-scopes>=0.6.6 |
10 | 33 | jsoncpp | 33 | jsoncpp |
11 | 34 | net-cpp>=1.1.0 | 34 | net-cpp>=1.1.0 |
12 | 35 | process-cpp | 35 | process-cpp |
13 | 36 | 36 | ||
14 | === modified file 'click/CMakeLists.txt' | |||
15 | --- click/CMakeLists.txt 2014-09-09 10:28:21 +0000 | |||
16 | +++ click/CMakeLists.txt 2014-09-11 08:39:29 +0000 | |||
17 | @@ -9,6 +9,9 @@ | |||
18 | 9 | FILES | 9 | FILES |
19 | 10 | "${CMAKE_CURRENT_BINARY_DIR}/manifest.json" | 10 | "${CMAKE_CURRENT_BINARY_DIR}/manifest.json" |
20 | 11 | "apparmor.json" | 11 | "apparmor.json" |
21 | 12 | "youtube.application" | ||
22 | 13 | "youtube.service" | ||
23 | 14 | "youtube.desktop" | ||
24 | 12 | DESTINATION ${CMAKE_INSTALL_PREFIX} | 15 | DESTINATION ${CMAKE_INSTALL_PREFIX} |
25 | 13 | ) | 16 | ) |
26 | 14 | 17 | ||
27 | 15 | 18 | ||
28 | === modified file 'click/apparmor.json' | |||
29 | --- click/apparmor.json 2014-07-31 09:38:11 +0000 | |||
30 | +++ click/apparmor.json 2014-09-11 08:39:29 +0000 | |||
31 | @@ -1,6 +1,7 @@ | |||
32 | 1 | { | 1 | { |
33 | 2 | "template": "ubuntu-scope-network", | 2 | "template": "ubuntu-scope-network", |
34 | 3 | "policy_groups": [ | 3 | "policy_groups": [ |
35 | 4 | "accounts" | ||
36 | 4 | ], | 5 | ], |
37 | 5 | "policy_version": 1.2 | 6 | "policy_version": 1.2 |
38 | 6 | } | 7 | } |
39 | 7 | 8 | ||
40 | === modified file 'click/manifest.json.in' | |||
41 | --- click/manifest.json.in 2014-09-09 12:48:43 +0000 | |||
42 | +++ click/manifest.json.in 2014-09-11 08:39:29 +0000 | |||
43 | @@ -5,12 +5,15 @@ | |||
44 | 5 | "hooks": { | 5 | "hooks": { |
45 | 6 | "youtube": { | 6 | "youtube": { |
46 | 7 | "scope": "youtube", | 7 | "scope": "youtube", |
48 | 8 | "apparmor": "apparmor.json" | 8 | "apparmor": "apparmor.json", |
49 | 9 | "account-application": "youtube.application", | ||
50 | 10 | "account-service": "youtube.service", | ||
51 | 11 | "desktop": "youtube.desktop" | ||
52 | 9 | } | 12 | } |
53 | 10 | }, | 13 | }, |
55 | 11 | "icon": "icon", | 14 | "icon": "youtube/icon.png", |
56 | 12 | "maintainer": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>", | 15 | "maintainer": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>", |
57 | 13 | "name": "@SCOPE_NAME@", | 16 | "name": "@SCOPE_NAME@", |
58 | 14 | "title": "YouTube scope", | 17 | "title": "YouTube scope", |
60 | 15 | "version": "1.0.11" | 18 | "version": "1.0.12" |
61 | 16 | } | 19 | } |
62 | 17 | 20 | ||
63 | === added file 'click/youtube.application' | |||
64 | --- click/youtube.application 1970-01-01 00:00:00 +0000 | |||
65 | +++ click/youtube.application 2014-09-11 08:39:29 +0000 | |||
66 | @@ -0,0 +1,10 @@ | |||
67 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
68 | 2 | <application id="com.ubuntu.scopes.youtube_youtube"> | ||
69 | 3 | <description>YouTube</description> | ||
70 | 4 | <desktop-entry>com.ubuntu.scopes.youtube_youtube_1.0.12.desktop</desktop-entry> | ||
71 | 5 | <services> | ||
72 | 6 | <service id="com.ubuntu.scopes.youtube_youtube"> | ||
73 | 7 | <description>Watch your favorite YouTube videos</description> | ||
74 | 8 | </service> | ||
75 | 9 | </services> | ||
76 | 10 | </application> | ||
77 | 0 | 11 | ||
78 | === added file 'click/youtube.desktop' | |||
79 | --- click/youtube.desktop 1970-01-01 00:00:00 +0000 | |||
80 | +++ click/youtube.desktop 2014-09-11 08:39:29 +0000 | |||
81 | @@ -0,0 +1,6 @@ | |||
82 | 1 | [Desktop Entry] | ||
83 | 2 | Type=Application | ||
84 | 3 | Name=YouTube | ||
85 | 4 | Icon=youtube/icon.png | ||
86 | 5 | OnlyShowIn=OnlineAccountsSettingsPage | ||
87 | 6 | Exec= | ||
88 | 0 | 7 | ||
89 | === renamed file 'data/accounts/services/youtube.service' => 'click/youtube.service' | |||
90 | --- data/accounts/services/youtube.service 2014-08-11 10:35:09 +0000 | |||
91 | +++ click/youtube.service 2014-09-11 08:39:29 +0000 | |||
92 | @@ -1,8 +1,28 @@ | |||
93 | 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
95 | 2 | <service id="youtube"> | 2 | <service id="com.ubuntu.scopes.youtube_youtube"> |
96 | 3 | <type>sharing</type> | 3 | <type>sharing</type> |
97 | 4 | <icon>youtube</icon> | 4 | <icon>youtube</icon> |
100 | 5 | <name>Youtube</name> | 5 | <name>YouTube</name> |
101 | 6 | <provider>youtube</provider> | 6 | <provider>google</provider> |
102 | 7 | <translations>unity-scope-youtube</translations> | 7 | <translations>unity-scope-youtube</translations> |
103 | 8 | <template> | ||
104 | 9 | <group name="auth"> | ||
105 | 10 | <setting name="method">oauth2</setting> | ||
106 | 11 | <setting name="mechanism">web_server</setting> | ||
107 | 12 | <group name="oauth2"> | ||
108 | 13 | <group name="web_server"> | ||
109 | 14 | <setting name="Host">accounts.google.com</setting> | ||
110 | 15 | |||
111 | 16 | <setting name="AuthPath">o/oauth2/auth?access_type=offline</setting> | ||
112 | 17 | <setting name="TokenPath">o/oauth2/token</setting> | ||
113 | 18 | <setting name="RedirectUri">https://wiki.ubuntu.com/</setting> | ||
114 | 19 | <setting name="ResponseType">code</setting> | ||
115 | 20 | <setting type="as" name="Scope">['https://www.googleapis.com/auth/youtube.readonly']</setting> | ||
116 | 21 | <setting name="ClientId">368477111780-4tf0t65ol86nkvf6guksr8d1om0aebob.apps.googleusercontent.com</setting> | ||
117 | 22 | <setting name="ClientSecret">bNfrMJzYmesl2sm1XutVnlmv</setting> | ||
118 | 23 | <setting type="as" name="AllowedSchemes">['https','http']</setting> | ||
119 | 24 | </group> | ||
120 | 25 | </group> | ||
121 | 26 | </group> | ||
122 | 27 | </template> | ||
123 | 8 | </service> | 28 | </service> |
124 | 9 | 29 | ||
125 | === modified file 'data/CMakeLists.txt' | |||
126 | --- data/CMakeLists.txt 2014-07-22 10:12:43 +0000 | |||
127 | +++ data/CMakeLists.txt 2014-09-11 08:39:29 +0000 | |||
128 | @@ -18,4 +18,3 @@ | |||
129 | 18 | DESTINATION | 18 | DESTINATION |
130 | 19 | "${SCOPE_INSTALL_DIR}" | 19 | "${SCOPE_INSTALL_DIR}" |
131 | 20 | ) | 20 | ) |
132 | 21 | |||
133 | 22 | 21 | ||
134 | === removed directory 'data/accounts' | |||
135 | === removed directory 'data/accounts/providers' | |||
136 | === removed file 'data/accounts/providers/youtube.provider' | |||
137 | --- data/accounts/providers/youtube.provider 2014-08-11 10:35:09 +0000 | |||
138 | +++ data/accounts/providers/youtube.provider 1970-01-01 00:00:00 +0000 | |||
139 | @@ -1,30 +0,0 @@ | |||
140 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
141 | 2 | <provider id="youtube"> | ||
142 | 3 | <name>Youtube</name> | ||
143 | 4 | <description>Connect your Youtube account</description> | ||
144 | 5 | <icon>youtube</icon> | ||
145 | 6 | <translations>unity-scope-youtube</translations> | ||
146 | 7 | <domains>.*google\.com</domains> | ||
147 | 8 | <plugin>generic-oauth</plugin> | ||
148 | 9 | |||
149 | 10 | <template> | ||
150 | 11 | <group name="auth"> | ||
151 | 12 | <setting name="method">oauth2</setting> | ||
152 | 13 | <setting name="mechanism">web_server</setting> | ||
153 | 14 | <group name="oauth2"> | ||
154 | 15 | <group name="web_server"> | ||
155 | 16 | <setting name="Host">accounts.google.com</setting> | ||
156 | 17 | |||
157 | 18 | <setting name="AuthPath">o/oauth2/auth?access_type=offline</setting> | ||
158 | 19 | <setting name="TokenPath">o/oauth2/token</setting> | ||
159 | 20 | <setting name="RedirectUri">https://wiki.ubuntu.com/</setting> | ||
160 | 21 | <setting name="ResponseType">code</setting> | ||
161 | 22 | <setting type="as" name="Scope">['https://www.googleapis.com/auth/youtube.readonly']</setting> | ||
162 | 23 | <setting name="ClientId">368477111780-4tf0t65ol86nkvf6guksr8d1om0aebob.apps.googleusercontent.com</setting> | ||
163 | 24 | <setting name="ClientSecret">bNfrMJzYmesl2sm1XutVnlmv</setting> | ||
164 | 25 | <setting type="as" name="AllowedSchemes">['https','http']</setting> | ||
165 | 26 | </group> | ||
166 | 27 | </group> | ||
167 | 28 | </group> | ||
168 | 29 | </template> | ||
169 | 30 | </provider> | ||
170 | 31 | 0 | ||
171 | === removed directory 'data/accounts/qml-plugins' | |||
172 | === removed directory 'data/accounts/qml-plugins/youtube' | |||
173 | === removed file 'data/accounts/qml-plugins/youtube/Main.qml' | |||
174 | --- data/accounts/qml-plugins/youtube/Main.qml 2014-08-11 10:35:09 +0000 | |||
175 | +++ data/accounts/qml-plugins/youtube/Main.qml 1970-01-01 00:00:00 +0000 | |||
176 | @@ -1,35 +0,0 @@ | |||
177 | 1 | import Ubuntu.OnlineAccounts.Plugin 1.0 | ||
178 | 2 | |||
179 | 3 | OAuthMain { | ||
180 | 4 | |||
181 | 5 | // Override creationComponent so we can retreive that account's username | ||
182 | 6 | // This then appears in the accounts management page | ||
183 | 7 | creationComponent: OAuth { | ||
184 | 8 | function completeCreation(reply) { | ||
185 | 9 | console.log("Vimeo got reply: " + reply.AccessToken) | ||
186 | 10 | var http = new XMLHttpRequest() | ||
187 | 11 | var url = "https://api.vimeo.com/me"; | ||
188 | 12 | http.open("GET", url, true); | ||
189 | 13 | http.setRequestHeader("Authorization", "Bearer " + reply.AccessToken) | ||
190 | 14 | http.setRequestHeader("Accept", "application/vnd.vimeo.*+json; version=3.0") | ||
191 | 15 | http.setRequestHeader("User-Agent", "unity-scope-vimeo 0.1; (http: //developer.vimeo.com/api/docs)") | ||
192 | 16 | http.onreadystatechange = function() { | ||
193 | 17 | if (http.readyState === 4) { | ||
194 | 18 | if (http.status == 200) { | ||
195 | 19 | console.log("ok") | ||
196 | 20 | var response = JSON.parse(http.responseText) | ||
197 | 21 | console.log("got name: " + response.name) | ||
198 | 22 | account.updateDisplayName(response.name) | ||
199 | 23 | account.synced.connect(finished) | ||
200 | 24 | account.sync() | ||
201 | 25 | } else { | ||
202 | 26 | console.log("error: " + http.responseText) | ||
203 | 27 | cancel() | ||
204 | 28 | } | ||
205 | 29 | } | ||
206 | 30 | }; | ||
207 | 31 | |||
208 | 32 | http.send(null); | ||
209 | 33 | } | ||
210 | 34 | } | ||
211 | 35 | } | ||
212 | 36 | 0 | ||
213 | === removed directory 'data/accounts/services' | |||
214 | === modified file 'debian/control' | |||
215 | --- debian/control 2014-09-09 10:28:21 +0000 | |||
216 | +++ debian/control 2014-09-11 08:39:29 +0000 | |||
217 | @@ -2,7 +2,7 @@ | |||
218 | 2 | Section: x11 | 2 | Section: x11 |
219 | 3 | Priority: optional | 3 | Priority: optional |
220 | 4 | Build-Depends: cmake (>= 2.8.10), | 4 | Build-Depends: cmake (>= 2.8.10), |
222 | 5 | Build-Depends: cmake-extras (>= 0.2), | 5 | cmake-extras (>= 0.2), |
223 | 6 | debhelper (>= 9), | 6 | debhelper (>= 9), |
224 | 7 | dh-translations, | 7 | dh-translations, |
225 | 8 | g++-4.9, | 8 | g++-4.9, |
226 | @@ -16,7 +16,7 @@ | |||
227 | 16 | libnet-cpp-dev (>= 1.1.0), | 16 | libnet-cpp-dev (>= 1.1.0), |
228 | 17 | libprocess-cpp-dev, | 17 | libprocess-cpp-dev, |
229 | 18 | libsignon-glib-dev, | 18 | libsignon-glib-dev, |
231 | 19 | libunity-scopes-dev (>= 0.6.0), | 19 | libunity-scopes-dev (>= 0.6.6), |
232 | 20 | pkg-config, | 20 | pkg-config, |
233 | 21 | python-tornado, | 21 | python-tornado, |
234 | 22 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | 22 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
235 | 23 | 23 | ||
236 | === removed file 'include/youtube/api/simple-oauth.h' | |||
237 | --- include/youtube/api/simple-oauth.h 2014-06-27 13:08:32 +0000 | |||
238 | +++ include/youtube/api/simple-oauth.h 1970-01-01 00:00:00 +0000 | |||
239 | @@ -1,88 +0,0 @@ | |||
240 | 1 | /* | ||
241 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
242 | 3 | * | ||
243 | 4 | * This library is free software; you can redistribute it and/or modify it under | ||
244 | 5 | * the terms of version 3 of the GNU Lesser General Public License as published | ||
245 | 6 | * by the Free Software Foundation. | ||
246 | 7 | * | ||
247 | 8 | * This library is distributed in the hope that it will be useful, but WITHOUT | ||
248 | 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
249 | 10 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
250 | 11 | * details. | ||
251 | 12 | * | ||
252 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
253 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
254 | 15 | * | ||
255 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
256 | 17 | */ | ||
257 | 18 | |||
258 | 19 | #ifndef VIMEO_API_SIMPLEOAUTH_H_ | ||
259 | 20 | #define VIMEO_API_SIMPLEOAUTH_H_ | ||
260 | 21 | |||
261 | 22 | #include <map> | ||
262 | 23 | #include <memory> | ||
263 | 24 | #include <string> | ||
264 | 25 | |||
265 | 26 | #include <glib.h> | ||
266 | 27 | #include <libaccounts-glib/accounts-glib.h> | ||
267 | 28 | #include <libsignon-glib/signon-glib.h> | ||
268 | 29 | |||
269 | 30 | namespace youtube { | ||
270 | 31 | namespace api { | ||
271 | 32 | |||
272 | 33 | class SimpleOAuth { | ||
273 | 34 | public: | ||
274 | 35 | struct AuthData { | ||
275 | 36 | std::string client_id; | ||
276 | 37 | std::string client_secret; | ||
277 | 38 | std::string access_token; | ||
278 | 39 | }; | ||
279 | 40 | |||
280 | 41 | SimpleOAuth(const std::string &service_name); | ||
281 | 42 | |||
282 | 43 | virtual ~SimpleOAuth() = default; | ||
283 | 44 | |||
284 | 45 | virtual SimpleOAuth::AuthData auth_data() const; | ||
285 | 46 | |||
286 | 47 | protected: | ||
287 | 48 | void auth_login(const std::string &clientId, const std::string &clientSecret, | ||
288 | 49 | const std::string &accessToken); | ||
289 | 50 | |||
290 | 51 | static void login_cb(GObject *source, GAsyncResult *result, | ||
291 | 52 | void *user_data); | ||
292 | 53 | |||
293 | 54 | void login(SignonAuthSession *source, GAsyncResult *result); | ||
294 | 55 | |||
295 | 56 | void login_service(); | ||
296 | 57 | |||
297 | 58 | void logout_service(); | ||
298 | 59 | |||
299 | 60 | void lookup_account_service(); | ||
300 | 61 | |||
301 | 62 | static void account_enabled_cb(AgManager *manager, guint account_id, | ||
302 | 63 | void *user_data); | ||
303 | 64 | |||
304 | 65 | void account_enabled(AgManager *manager, guint account_id); | ||
305 | 66 | |||
306 | 67 | gboolean setup_context(); | ||
307 | 68 | |||
308 | 69 | static gboolean setup_context_cb(void *user_data); | ||
309 | 70 | |||
310 | 71 | std::string service_name_; | ||
311 | 72 | |||
312 | 73 | std::shared_ptr<GMainLoop> main_loop_; | ||
313 | 74 | std::shared_ptr<AgManager> manager_; | ||
314 | 75 | std::shared_ptr<AgAccountService> account_service_; | ||
315 | 76 | AgAuthData *ag_auth_data_; | ||
316 | 77 | std::shared_ptr<SignonAuthSession> session_; | ||
317 | 78 | |||
318 | 79 | std::shared_ptr<GVariant> auth_params_; | ||
319 | 80 | std::shared_ptr<GVariant> session_data_; | ||
320 | 81 | |||
321 | 82 | AuthData auth_data_; | ||
322 | 83 | }; | ||
323 | 84 | |||
324 | 85 | } | ||
325 | 86 | } | ||
326 | 87 | |||
327 | 88 | #endif // VIMEO_API_SIMPLEOAUTH_H_ | ||
328 | 89 | 0 | ||
329 | === modified file 'include/youtube/scope/scope.h' | |||
330 | --- include/youtube/scope/scope.h 2014-08-01 15:26:57 +0000 | |||
331 | +++ include/youtube/scope/scope.h 2014-09-11 08:39:29 +0000 | |||
332 | @@ -20,13 +20,12 @@ | |||
333 | 20 | #define YOUTUBE_SCOPE_SCOPE_H_ | 20 | #define YOUTUBE_SCOPE_SCOPE_H_ |
334 | 21 | 21 | ||
335 | 22 | #include <youtube/api/config.h> | 22 | #include <youtube/api/config.h> |
336 | 23 | #include <youtube/api/simple-oauth.h> | ||
337 | 24 | 23 | ||
338 | 24 | #include <unity/scopes/OnlineAccountClient.h> | ||
339 | 25 | #include <unity/scopes/PreviewQueryBase.h> | ||
340 | 26 | #include <unity/scopes/QueryBase.h> | ||
341 | 27 | #include <unity/scopes/ReplyProxyFwd.h> | ||
342 | 25 | #include <unity/scopes/ScopeBase.h> | 28 | #include <unity/scopes/ScopeBase.h> |
343 | 26 | #include <unity/scopes/QueryBase.h> | ||
344 | 27 | #include <unity/scopes/ReplyProxyFwd.h> | ||
345 | 28 | #include <unity/scopes/QueryBase.h> | ||
346 | 29 | #include <unity/scopes/PreviewQueryBase.h> | ||
347 | 30 | 29 | ||
348 | 31 | namespace youtube { | 30 | namespace youtube { |
349 | 32 | 31 | ||
350 | @@ -34,8 +33,12 @@ | |||
351 | 34 | 33 | ||
352 | 35 | class Scope: public unity::scopes::ScopeBase { | 34 | class Scope: public unity::scopes::ScopeBase { |
353 | 36 | public: | 35 | public: |
356 | 37 | void start(std::string const&) | 36 | Scope(); |
357 | 38 | override; | 37 | |
358 | 38 | void service_update(unity::scopes::OnlineAccountClient::ServiceStatus const& status); | ||
359 | 39 | void update_config(); | ||
360 | 40 | |||
361 | 41 | void start(std::string const&) override; | ||
362 | 39 | 42 | ||
363 | 40 | void stop() override; | 43 | void stop() override; |
364 | 41 | 44 | ||
365 | @@ -48,6 +51,8 @@ | |||
366 | 48 | 51 | ||
367 | 49 | protected: | 52 | protected: |
368 | 50 | youtube::api::Config::Ptr config_; | 53 | youtube::api::Config::Ptr config_; |
369 | 54 | std::mutex config_mutex_; | ||
370 | 55 | unity::scopes::OnlineAccountClient oa_client_; | ||
371 | 51 | }; | 56 | }; |
372 | 52 | 57 | ||
373 | 53 | } | 58 | } |
374 | 54 | 59 | ||
375 | === modified file 'src/CMakeLists.txt' | |||
376 | --- src/CMakeLists.txt 2014-08-19 11:09:19 +0000 | |||
377 | +++ src/CMakeLists.txt 2014-09-11 08:39:29 +0000 | |||
378 | @@ -23,7 +23,6 @@ | |||
379 | 23 | youtube/api/guide-category.cpp | 23 | youtube/api/guide-category.cpp |
380 | 24 | youtube/api/playlist.cpp | 24 | youtube/api/playlist.cpp |
381 | 25 | youtube/api/playlist-item.cpp | 25 | youtube/api/playlist-item.cpp |
382 | 26 | youtube/api/simple-oauth.cpp | ||
383 | 27 | youtube/api/search-list-response.cpp | 26 | youtube/api/search-list-response.cpp |
384 | 28 | youtube/api/video.cpp | 27 | youtube/api/video.cpp |
385 | 29 | youtube/scope/preview.cpp | 28 | youtube/scope/preview.cpp |
386 | 30 | 29 | ||
387 | === removed file 'src/youtube/api/simple-oauth.cpp' | |||
388 | --- src/youtube/api/simple-oauth.cpp 2014-06-27 13:08:32 +0000 | |||
389 | +++ src/youtube/api/simple-oauth.cpp 1970-01-01 00:00:00 +0000 | |||
390 | @@ -1,179 +0,0 @@ | |||
391 | 1 | /* | ||
392 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
393 | 3 | * | ||
394 | 4 | * This library is free software; you can redistribute it and/or modify it under | ||
395 | 5 | * the terms of version 3 of the GNU Lesser General Public License as published | ||
396 | 6 | * by the Free Software Foundation. | ||
397 | 7 | * | ||
398 | 8 | * This library is distributed in the hope that it will be useful, but WITHOUT | ||
399 | 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
400 | 10 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
401 | 11 | * details. | ||
402 | 12 | * | ||
403 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
404 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
405 | 15 | * | ||
406 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
407 | 17 | */ | ||
408 | 18 | |||
409 | 19 | #include <youtube/api/simple-oauth.h> | ||
410 | 20 | |||
411 | 21 | #include <iostream> | ||
412 | 22 | |||
413 | 23 | using namespace youtube::api; | ||
414 | 24 | using namespace std; | ||
415 | 25 | |||
416 | 26 | SimpleOAuth::SimpleOAuth(const std::string &service_name) : | ||
417 | 27 | service_name_(service_name) { | ||
418 | 28 | main_loop_.reset(g_main_loop_new(nullptr, true), g_main_loop_unref); | ||
419 | 29 | |||
420 | 30 | manager_.reset(ag_manager_new(), g_object_unref); | ||
421 | 31 | g_idle_add(setup_context_cb, this); | ||
422 | 32 | |||
423 | 33 | g_main_loop_run(main_loop_.get()); | ||
424 | 34 | } | ||
425 | 35 | |||
426 | 36 | SimpleOAuth::AuthData SimpleOAuth::auth_data() const { | ||
427 | 37 | return auth_data_; | ||
428 | 38 | } | ||
429 | 39 | |||
430 | 40 | void SimpleOAuth::auth_login(const string &clientId, const string &clientSecret, | ||
431 | 41 | const string &accessToken) { | ||
432 | 42 | auth_data_.client_id = clientId; | ||
433 | 43 | auth_data_.client_secret = clientSecret; | ||
434 | 44 | auth_data_.access_token = accessToken; | ||
435 | 45 | |||
436 | 46 | g_main_loop_quit(main_loop_.get()); | ||
437 | 47 | } | ||
438 | 48 | |||
439 | 49 | void SimpleOAuth::login_cb(GObject *source, GAsyncResult *result, | ||
440 | 50 | void *user_data) { | ||
441 | 51 | SignonAuthSession *session = (SignonAuthSession *) source; | ||
442 | 52 | SimpleOAuth *accounts = static_cast<SimpleOAuth*>(user_data); | ||
443 | 53 | accounts->login(session, result); | ||
444 | 54 | } | ||
445 | 55 | |||
446 | 56 | void SimpleOAuth::login(SignonAuthSession *session, GAsyncResult *result) { | ||
447 | 57 | GError *error = nullptr; | ||
448 | 58 | session_data_.reset( | ||
449 | 59 | signon_auth_session_process_finish(session, result, &error), | ||
450 | 60 | g_variant_unref); | ||
451 | 61 | |||
452 | 62 | session_.reset(); | ||
453 | 63 | |||
454 | 64 | if (error) { | ||
455 | 65 | cerr << "Authentication failed: " << error->message << endl; | ||
456 | 66 | g_error_free(error); | ||
457 | 67 | return; | ||
458 | 68 | } | ||
459 | 69 | |||
460 | 70 | char *tmp = nullptr; | ||
461 | 71 | string client_id; | ||
462 | 72 | string client_secret; | ||
463 | 73 | string access_token; | ||
464 | 74 | if (g_variant_lookup(auth_params_.get(), "ClientId", "&s", &tmp)) { | ||
465 | 75 | client_id = tmp; | ||
466 | 76 | } | ||
467 | 77 | if (g_variant_lookup(auth_params_.get(), "ClientSecret", "&s", &tmp)) { | ||
468 | 78 | client_secret = tmp; | ||
469 | 79 | } | ||
470 | 80 | if (g_variant_lookup(session_data_.get(), "AccessToken", "&s", &tmp)) { | ||
471 | 81 | access_token = tmp; | ||
472 | 82 | } | ||
473 | 83 | |||
474 | 84 | auth_login(client_id, client_secret, access_token); | ||
475 | 85 | } | ||
476 | 86 | |||
477 | 87 | void SimpleOAuth::login_service() { | ||
478 | 88 | ag_auth_data_ = ag_account_service_get_auth_data(account_service_.get()); | ||
479 | 89 | |||
480 | 90 | GError *error = NULL; | ||
481 | 91 | session_.reset( | ||
482 | 92 | signon_auth_session_new( | ||
483 | 93 | ag_auth_data_get_credentials_id(ag_auth_data_), | ||
484 | 94 | ag_auth_data_get_method(ag_auth_data_), &error), | ||
485 | 95 | g_object_unref); | ||
486 | 96 | if (error != NULL) { | ||
487 | 97 | cerr << "Could not set up auth session: " << error->message << endl; | ||
488 | 98 | g_error_free(error); | ||
489 | 99 | return; | ||
490 | 100 | } | ||
491 | 101 | |||
492 | 102 | GVariantBuilder builder; | ||
493 | 103 | g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); | ||
494 | 104 | g_variant_builder_add(&builder, "{sv}", | ||
495 | 105 | SIGNON_SESSION_DATA_UI_POLICY, | ||
496 | 106 | g_variant_new_int32(SIGNON_POLICY_NO_USER_INTERACTION)); | ||
497 | 107 | |||
498 | 108 | auth_params_.reset( | ||
499 | 109 | g_variant_ref_sink( | ||
500 | 110 | ag_auth_data_get_login_parameters(ag_auth_data_, | ||
501 | 111 | g_variant_builder_end(&builder))), g_variant_unref); | ||
502 | 112 | |||
503 | 113 | signon_auth_session_process_async(session_.get(), auth_params_.get(), | ||
504 | 114 | ag_auth_data_get_mechanism(ag_auth_data_), | ||
505 | 115 | NULL, /* cancellable */ | ||
506 | 116 | login_cb, this); | ||
507 | 117 | } | ||
508 | 118 | |||
509 | 119 | void SimpleOAuth::logout_service() { | ||
510 | 120 | session_data_.reset(); | ||
511 | 121 | auth_params_.reset(); | ||
512 | 122 | if (session_) { | ||
513 | 123 | signon_auth_session_cancel(session_.get()); | ||
514 | 124 | session_.reset(); | ||
515 | 125 | } | ||
516 | 126 | ag_auth_data_ = nullptr; | ||
517 | 127 | account_service_.reset(); | ||
518 | 128 | |||
519 | 129 | auth_login(string(), string(), string()); | ||
520 | 130 | } | ||
521 | 131 | |||
522 | 132 | void SimpleOAuth::lookup_account_service() { | ||
523 | 133 | GList *account_services = ag_manager_get_account_services( | ||
524 | 134 | manager_.get()); | ||
525 | 135 | GList *tmp; | ||
526 | 136 | for (tmp = account_services; tmp != nullptr; tmp = tmp->next) { | ||
527 | 137 | AgAccountService *acct_svc = AG_ACCOUNT_SERVICE(tmp->data); | ||
528 | 138 | AgService *service = ag_account_service_get_service(acct_svc); | ||
529 | 139 | if (service_name_ == ag_service_get_name(service)) { | ||
530 | 140 | account_service_.reset(AG_ACCOUNT_SERVICE(g_object_ref(acct_svc)), | ||
531 | 141 | g_object_unref); | ||
532 | 142 | break; | ||
533 | 143 | } | ||
534 | 144 | } | ||
535 | 145 | ag_manager_list_free(account_services); | ||
536 | 146 | |||
537 | 147 | if (account_service_) { | ||
538 | 148 | login_service(); | ||
539 | 149 | } else { | ||
540 | 150 | cerr << "Could not find account service" << endl; | ||
541 | 151 | g_main_loop_quit(main_loop_.get()); | ||
542 | 152 | } | ||
543 | 153 | } | ||
544 | 154 | |||
545 | 155 | void SimpleOAuth::account_enabled_cb(AgManager *manager, guint account_id, | ||
546 | 156 | void *user_data) { | ||
547 | 157 | SimpleOAuth *accounts = static_cast<SimpleOAuth*>(user_data); | ||
548 | 158 | accounts->account_enabled(manager, account_id); | ||
549 | 159 | } | ||
550 | 160 | |||
551 | 161 | void SimpleOAuth::account_enabled(AgManager *, guint) { | ||
552 | 162 | if (account_service_ | ||
553 | 163 | && !ag_account_service_get_enabled(account_service_.get())) { | ||
554 | 164 | logout_service(); | ||
555 | 165 | } | ||
556 | 166 | lookup_account_service(); | ||
557 | 167 | } | ||
558 | 168 | |||
559 | 169 | gboolean SimpleOAuth::setup_context_cb(void *user_data) { | ||
560 | 170 | SimpleOAuth *accounts = static_cast<SimpleOAuth*>(user_data); | ||
561 | 171 | return accounts->setup_context(); | ||
562 | 172 | } | ||
563 | 173 | |||
564 | 174 | gboolean SimpleOAuth::setup_context() { | ||
565 | 175 | lookup_account_service(); | ||
566 | 176 | g_signal_connect(manager_.get(), "enabled-event", | ||
567 | 177 | G_CALLBACK(account_enabled_cb), this); | ||
568 | 178 | return FALSE; | ||
569 | 179 | } | ||
570 | 180 | 0 | ||
571 | === modified file 'src/youtube/scope/query.cpp' | |||
572 | --- src/youtube/scope/query.cpp 2014-09-09 10:28:21 +0000 | |||
573 | +++ src/youtube/scope/query.cpp 2014-09-11 08:39:29 +0000 | |||
574 | @@ -28,6 +28,7 @@ | |||
575 | 28 | #include <unity/scopes/Annotation.h> | 28 | #include <unity/scopes/Annotation.h> |
576 | 29 | #include <unity/scopes/CategorisedResult.h> | 29 | #include <unity/scopes/CategorisedResult.h> |
577 | 30 | #include <unity/scopes/CategoryRenderer.h> | 30 | #include <unity/scopes/CategoryRenderer.h> |
578 | 31 | #include <unity/scopes/OnlineAccountClient.h> | ||
579 | 31 | #include <unity/scopes/QueryBase.h> | 32 | #include <unity/scopes/QueryBase.h> |
580 | 32 | #include <unity/scopes/SearchReply.h> | 33 | #include <unity/scopes/SearchReply.h> |
581 | 33 | #include <unity/scopes/SearchMetadata.h> | 34 | #include <unity/scopes/SearchMetadata.h> |
582 | @@ -295,7 +296,13 @@ | |||
583 | 295 | 296 | ||
584 | 296 | sc::CategorisedResult res(cat); | 297 | sc::CategorisedResult res(cat); |
585 | 297 | res.set_title(_("Log-in to YouTube")); | 298 | res.set_title(_("Log-in to YouTube")); |
587 | 298 | res.set_uri("settings:///system/online-accounts"); | 299 | |
588 | 300 | sc::OnlineAccountClient oa_client("com.ubuntu.scopes.youtube_youtube", "sharing", "google"); | ||
589 | 301 | oa_client.register_account_login_item(res, | ||
590 | 302 | query(), | ||
591 | 303 | sc::OnlineAccountClient::InvalidateResults, | ||
592 | 304 | sc::OnlineAccountClient::DoNothing); | ||
593 | 305 | |||
594 | 299 | reply->push(res); | 306 | reply->push(res); |
595 | 300 | } | 307 | } |
596 | 301 | 308 | ||
597 | @@ -668,10 +675,9 @@ | |||
598 | 668 | search(reply, query_string); | 675 | search(reply, query_string); |
599 | 669 | } | 676 | } |
600 | 670 | 677 | ||
605 | 671 | // FIXME Add this back when direct activation can be controlled | 678 | if (!client_->config()->authenticated) { |
606 | 672 | // if (!client_->config()->authenticated) { | 679 | add_login_nag(reply); |
607 | 673 | // add_login_nag(reply); | 680 | } |
604 | 674 | // } | ||
608 | 675 | } catch (domain_error &e) { | 681 | } catch (domain_error &e) { |
609 | 676 | cerr << "ERROR: " << e.what() << endl; | 682 | cerr << "ERROR: " << e.what() << endl; |
610 | 677 | } | 683 | } |
611 | 678 | 684 | ||
612 | === modified file 'src/youtube/scope/scope.cpp' | |||
613 | --- src/youtube/scope/scope.cpp 2014-09-09 10:56:09 +0000 | |||
614 | +++ src/youtube/scope/scope.cpp 2014-09-11 08:39:29 +0000 | |||
615 | @@ -30,32 +30,56 @@ | |||
616 | 30 | using namespace youtube::scope; | 30 | using namespace youtube::scope; |
617 | 31 | using namespace youtube::api; | 31 | using namespace youtube::api; |
618 | 32 | 32 | ||
624 | 33 | void Scope::start(string const&) { | 33 | Scope::Scope() |
625 | 34 | setlocale(LC_ALL, ""); | 34 | : oa_client_("com.ubuntu.scopes.youtube_youtube", |
626 | 35 | string translation_directory = ScopeBase::scope_directory() + "/../share/locale/"; | 35 | "sharing", |
627 | 36 | bindtextdomain(GETTEXT_PACKAGE, translation_directory.c_str()); | 36 | "google", |
628 | 37 | 37 | sc::OnlineAccountClient::CreateInternalMainLoop) | |
629 | 38 | { | ||
630 | 39 | oa_client_.set_service_update_callback(std::bind(&Scope::service_update, this, std::placeholders::_1)); | ||
631 | 40 | } | ||
632 | 41 | |||
633 | 42 | void Scope::service_update(sc::OnlineAccountClient::ServiceStatus const&) | ||
634 | 43 | { | ||
635 | 44 | update_config(); | ||
636 | 45 | } | ||
637 | 46 | |||
638 | 47 | void Scope::update_config() | ||
639 | 48 | { | ||
640 | 49 | std::lock_guard<std::mutex> lock(config_mutex_); | ||
641 | 38 | config_ = make_shared<Config>(); | 50 | config_ = make_shared<Config>(); |
642 | 39 | 51 | ||
643 | 40 | if (getenv("YOUTUBE_SCOPE_APIROOT")) { | 52 | if (getenv("YOUTUBE_SCOPE_APIROOT")) { |
644 | 41 | config_->apiroot = getenv("YOUTUBE_SCOPE_APIROOT"); | 53 | config_->apiroot = getenv("YOUTUBE_SCOPE_APIROOT"); |
645 | 42 | } | 54 | } |
646 | 43 | 55 | ||
647 | 44 | SimpleOAuth oauth("youtube"); | ||
648 | 45 | SimpleOAuth::AuthData auth_data; | ||
649 | 46 | if (getenv("YOUTUBE_SCOPE_IGNORE_ACCOUNTS") == nullptr) { | 56 | if (getenv("YOUTUBE_SCOPE_IGNORE_ACCOUNTS") == nullptr) { |
651 | 47 | auth_data = oauth.auth_data(); | 57 | auto statuses = oa_client_.get_service_statuses(); |
652 | 58 | for (auto const& status : statuses) | ||
653 | 59 | { | ||
654 | 60 | if (status.service_enabled) | ||
655 | 61 | { | ||
656 | 62 | config_->authenticated = true; | ||
657 | 63 | config_->access_token = status.access_token; | ||
658 | 64 | config_->client_id = status.client_id; | ||
659 | 65 | config_->client_secret = status.client_secret; | ||
660 | 66 | break; | ||
661 | 67 | } | ||
662 | 68 | } | ||
663 | 48 | } | 69 | } |
665 | 49 | if (auth_data.access_token.empty()) { | 70 | |
666 | 71 | if (!config_->authenticated) { | ||
667 | 50 | cerr << "YouTube scope is unauthenticated" << endl; | 72 | cerr << "YouTube scope is unauthenticated" << endl; |
668 | 51 | } else { | 73 | } else { |
669 | 52 | cerr << "YouTube scope is authenticated" << endl; | 74 | cerr << "YouTube scope is authenticated" << endl; |
670 | 53 | config_->authenticated = true; | ||
671 | 54 | } | 75 | } |
672 | 76 | } | ||
673 | 55 | 77 | ||
677 | 56 | config_->access_token = auth_data.access_token; | 78 | void Scope::start(string const&) { |
678 | 57 | config_->client_id = auth_data.client_id; | 79 | setlocale(LC_ALL, ""); |
679 | 58 | config_->client_secret = auth_data.client_secret; | 80 | string translation_directory = ScopeBase::scope_directory() + "/../share/locale/"; |
680 | 81 | bindtextdomain(GETTEXT_PACKAGE, translation_directory.c_str()); | ||
681 | 82 | update_config(); | ||
682 | 59 | } | 83 | } |
683 | 60 | 84 | ||
684 | 61 | void Scope::stop() { | 85 | void Scope::stop() { |
685 | @@ -63,12 +87,14 @@ | |||
686 | 63 | 87 | ||
687 | 64 | sc::SearchQueryBase::UPtr Scope::search(const sc::CannedQuery &query, | 88 | sc::SearchQueryBase::UPtr Scope::search(const sc::CannedQuery &query, |
688 | 65 | const sc::SearchMetadata &metadata) { | 89 | const sc::SearchMetadata &metadata) { |
689 | 90 | std::lock_guard<std::mutex> lock(config_mutex_); | ||
690 | 66 | auto client = make_shared<Client>(config_); | 91 | auto client = make_shared<Client>(config_); |
691 | 67 | return sc::SearchQueryBase::UPtr(new Query(query, metadata, client)); | 92 | return sc::SearchQueryBase::UPtr(new Query(query, metadata, client)); |
692 | 68 | } | 93 | } |
693 | 69 | 94 | ||
694 | 70 | sc::PreviewQueryBase::UPtr Scope::preview(sc::Result const& result, | 95 | sc::PreviewQueryBase::UPtr Scope::preview(sc::Result const& result, |
695 | 71 | sc::ActionMetadata const& metadata) { | 96 | sc::ActionMetadata const& metadata) { |
696 | 97 | std::lock_guard<std::mutex> lock(config_mutex_); | ||
697 | 72 | auto client = make_shared<Client>(config_); | 98 | auto client = make_shared<Client>(config_); |
698 | 73 | return sc::PreviewQueryBase::UPtr(new Preview(result, metadata, client)); | 99 | return sc::PreviewQueryBase::UPtr(new Preview(result, metadata, client)); |
699 | 74 | } | 100 | } |
At a high level, these changes look really good. There are a couple of variables I'd want to extract out of the .desktop and .application files, but overall this is a big +1