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